1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2015 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. */
47 #include "double-int.h"
52 #include "fold-const.h"
53 #include "stringpool.h"
55 #include "stor-layout.h"
57 #include "trans-mem.h"
58 #include "langhooks.h"
62 #include "c-family/c-pragma.h"
67 #include "c-family/c-common.h"
68 #include "c-family/c-objc.h"
73 #include "plugin-api.h"
77 #include "hard-reg-set.h"
84 #include "gomp-constants.h"
87 /* Initialization routine for this file. */
92 /* The only initialization required is of the reserved word
98 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
99 the c_token structure. */
100 gcc_assert (RID_MAX
<= 255);
107 mask
|= D_ASM
| D_EXT
;
111 if (!c_dialect_objc ())
112 mask
|= D_OBJC
| D_CXX_OBJC
;
114 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
115 for (i
= 0; i
< num_c_common_reswords
; i
++)
117 /* If a keyword is disabled, do not enter it into the table
118 and so create a canonical spelling that isn't a keyword. */
119 if (c_common_reswords
[i
].disable
& mask
)
122 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
124 id
= get_identifier (c_common_reswords
[i
].word
);
125 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
126 C_IS_RESERVED_WORD (id
) = 1;
131 id
= get_identifier (c_common_reswords
[i
].word
);
132 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
133 C_IS_RESERVED_WORD (id
) = 1;
134 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
137 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
139 /* We always create the symbols but they aren't always supported. */
141 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
142 id
= get_identifier (name
);
143 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
144 C_IS_RESERVED_WORD (id
) = 1;
148 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
149 and the C parser. Unlike the C++ lexer, the parser structure
150 stores the lexer information instead of using a separate structure.
151 Identifiers are separated into ordinary identifiers, type names,
152 keywords and some other Objective-C types of identifiers, and some
153 look-ahead is maintained.
155 ??? It might be a good idea to lex the whole file up front (as for
156 C++). It would then be possible to share more of the C and C++
157 lexer code, if desired. */
159 /* More information about the type of a CPP_NAME token. */
160 typedef enum c_id_kind
{
161 /* An ordinary identifier. */
163 /* An identifier declared as a typedef name. */
165 /* An identifier declared as an Objective-C class name. */
167 /* An address space identifier. */
169 /* Not an identifier. */
173 /* A single C token after string literal concatenation and conversion
174 of preprocessing tokens to tokens. */
175 typedef struct GTY (()) c_token
{
176 /* The kind of token. */
177 ENUM_BITFIELD (cpp_ttype
) type
: 8;
178 /* If this token is a CPP_NAME, this value indicates whether also
179 declared as some kind of type. Otherwise, it is C_ID_NONE. */
180 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
181 /* If this token is a keyword, this value indicates which keyword.
182 Otherwise, this value is RID_MAX. */
183 ENUM_BITFIELD (rid
) keyword
: 8;
184 /* If this token is a CPP_PRAGMA, this indicates the pragma that
185 was seen. Otherwise it is PRAGMA_NONE. */
186 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
187 /* The location at which this token was found. */
189 /* The value associated with this token, if any. */
193 /* A parser structure recording information about the state and
194 context of parsing. Includes lexer information with up to two
195 tokens of look-ahead; more are not needed for C. */
196 typedef struct GTY(()) c_parser
{
197 /* The look-ahead tokens. */
198 c_token
* GTY((skip
)) tokens
;
199 /* Buffer for look-ahead tokens. */
200 c_token tokens_buf
[2];
201 /* How many look-ahead tokens are available (0, 1 or 2, or
202 more if parsing from pre-lexed tokens). */
203 unsigned int tokens_avail
;
204 /* True if a syntax error is being recovered from; false otherwise.
205 c_parser_error sets this flag. It should clear this flag when
206 enough tokens have been consumed to recover from the error. */
207 BOOL_BITFIELD error
: 1;
208 /* True if we're processing a pragma, and shouldn't automatically
209 consume CPP_PRAGMA_EOL. */
210 BOOL_BITFIELD in_pragma
: 1;
211 /* True if we're parsing the outermost block of an if statement. */
212 BOOL_BITFIELD in_if_block
: 1;
213 /* True if we want to lex an untranslated string. */
214 BOOL_BITFIELD lex_untranslated_string
: 1;
216 /* Objective-C specific parser/lexer information. */
218 /* True if we are in a context where the Objective-C "PQ" keywords
219 are considered keywords. */
220 BOOL_BITFIELD objc_pq_context
: 1;
221 /* True if we are parsing a (potential) Objective-C foreach
222 statement. This is set to true after we parsed 'for (' and while
223 we wait for 'in' or ';' to decide if it's a standard C for loop or an
224 Objective-C foreach loop. */
225 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
226 /* The following flag is needed to contextualize Objective-C lexical
227 analysis. In some cases (e.g., 'int NSObject;'), it is
228 undesirable to bind an identifier to an Objective-C class, even
229 if a class with that name exists. */
230 BOOL_BITFIELD objc_need_raw_identifier
: 1;
231 /* Nonzero if we're processing a __transaction statement. The value
232 is 1 | TM_STMT_ATTR_*. */
233 unsigned int in_transaction
: 4;
234 /* True if we are in a context where the Objective-C "Property attribute"
235 keywords are valid. */
236 BOOL_BITFIELD objc_property_attr_context
: 1;
238 /* Cilk Plus specific parser/lexer information. */
240 /* Buffer to hold all the tokens from parsing the vector attribute for the
241 SIMD-enabled functions (formerly known as elemental functions). */
242 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
246 /* The actual parser and external interface. ??? Does this need to be
247 garbage-collected? */
249 static GTY (()) c_parser
*the_parser
;
251 /* Read in and lex a single token, storing it in *TOKEN. */
254 c_lex_one_token (c_parser
*parser
, c_token
*token
)
256 timevar_push (TV_LEX
);
258 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
259 (parser
->lex_untranslated_string
260 ? C_LEX_STRING_NO_TRANSLATE
: 0));
261 token
->id_kind
= C_ID_NONE
;
262 token
->keyword
= RID_MAX
;
263 token
->pragma_kind
= PRAGMA_NONE
;
271 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
272 if (c_dialect_objc ())
273 parser
->objc_need_raw_identifier
= false;
275 if (C_IS_RESERVED_WORD (token
->value
))
277 enum rid rid_code
= C_RID_CODE (token
->value
);
279 if (rid_code
== RID_CXX_COMPAT_WARN
)
281 warning_at (token
->location
,
283 "identifier %qE conflicts with C++ keyword",
286 else if (rid_code
>= RID_FIRST_ADDR_SPACE
287 && rid_code
<= RID_LAST_ADDR_SPACE
)
289 token
->id_kind
= C_ID_ADDRSPACE
;
290 token
->keyword
= rid_code
;
293 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
295 /* We found an Objective-C "pq" keyword (in, out,
296 inout, bycopy, byref, oneway). They need special
297 care because the interpretation depends on the
299 if (parser
->objc_pq_context
)
301 token
->type
= CPP_KEYWORD
;
302 token
->keyword
= rid_code
;
305 else if (parser
->objc_could_be_foreach_context
306 && rid_code
== RID_IN
)
308 /* We are in Objective-C, inside a (potential)
309 foreach context (which means after having
310 parsed 'for (', but before having parsed ';'),
311 and we found 'in'. We consider it the keyword
312 which terminates the declaration at the
313 beginning of a foreach-statement. Note that
314 this means you can't use 'in' for anything else
315 in that context; in particular, in Objective-C
316 you can't use 'in' as the name of the running
317 variable in a C for loop. We could potentially
318 try to add code here to disambiguate, but it
319 seems a reasonable limitation. */
320 token
->type
= CPP_KEYWORD
;
321 token
->keyword
= rid_code
;
324 /* Else, "pq" keywords outside of the "pq" context are
325 not keywords, and we fall through to the code for
328 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
330 /* We found an Objective-C "property attribute"
331 keyword (getter, setter, readonly, etc). These are
332 only valid in the property context. */
333 if (parser
->objc_property_attr_context
)
335 token
->type
= CPP_KEYWORD
;
336 token
->keyword
= rid_code
;
339 /* Else they are not special keywords.
342 else if (c_dialect_objc ()
343 && (OBJC_IS_AT_KEYWORD (rid_code
)
344 || OBJC_IS_CXX_KEYWORD (rid_code
)))
346 /* We found one of the Objective-C "@" keywords (defs,
347 selector, synchronized, etc) or one of the
348 Objective-C "cxx" keywords (class, private,
349 protected, public, try, catch, throw) without a
350 preceding '@' sign. Do nothing and fall through to
351 the code for normal tokens (in C++ we would still
352 consider the CXX ones keywords, but not in C). */
357 token
->type
= CPP_KEYWORD
;
358 token
->keyword
= rid_code
;
363 decl
= lookup_name (token
->value
);
366 if (TREE_CODE (decl
) == TYPE_DECL
)
368 token
->id_kind
= C_ID_TYPENAME
;
372 else if (c_dialect_objc ())
374 tree objc_interface_decl
= objc_is_class_name (token
->value
);
375 /* Objective-C class names are in the same namespace as
376 variables and typedefs, and hence are shadowed by local
378 if (objc_interface_decl
379 && (!objc_force_identifier
|| global_bindings_p ()))
381 token
->value
= objc_interface_decl
;
382 token
->id_kind
= C_ID_CLASSNAME
;
386 token
->id_kind
= C_ID_ID
;
390 /* This only happens in Objective-C; it must be a keyword. */
391 token
->type
= CPP_KEYWORD
;
392 switch (C_RID_CODE (token
->value
))
394 /* Replace 'class' with '@class', 'private' with '@private',
395 etc. This prevents confusion with the C++ keyword
396 'class', and makes the tokens consistent with other
397 Objective-C 'AT' keywords. For example '@class' is
398 reported as RID_AT_CLASS which is consistent with
399 '@synchronized', which is reported as
402 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
403 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
404 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
405 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
406 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
407 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
408 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
409 default: token
->keyword
= C_RID_CODE (token
->value
);
414 case CPP_CLOSE_PAREN
:
416 /* These tokens may affect the interpretation of any identifiers
417 following, if doing Objective-C. */
418 if (c_dialect_objc ())
419 parser
->objc_need_raw_identifier
= false;
422 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
423 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
429 timevar_pop (TV_LEX
);
432 /* Return a pointer to the next token from PARSER, reading it in if
435 static inline c_token
*
436 c_parser_peek_token (c_parser
*parser
)
438 if (parser
->tokens_avail
== 0)
440 c_lex_one_token (parser
, &parser
->tokens
[0]);
441 parser
->tokens_avail
= 1;
443 return &parser
->tokens
[0];
446 /* Return true if the next token from PARSER has the indicated
450 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
452 return c_parser_peek_token (parser
)->type
== type
;
455 /* Return true if the next token from PARSER does not have the
459 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
461 return !c_parser_next_token_is (parser
, type
);
464 /* Return true if the next token from PARSER is the indicated
468 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
470 return c_parser_peek_token (parser
)->keyword
== keyword
;
473 /* Return a pointer to the next-but-one token from PARSER, reading it
474 in if necessary. The next token is already read in. */
477 c_parser_peek_2nd_token (c_parser
*parser
)
479 if (parser
->tokens_avail
>= 2)
480 return &parser
->tokens
[1];
481 gcc_assert (parser
->tokens_avail
== 1);
482 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
483 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
484 c_lex_one_token (parser
, &parser
->tokens
[1]);
485 parser
->tokens_avail
= 2;
486 return &parser
->tokens
[1];
489 /* Return true if TOKEN can start a type name,
492 c_token_starts_typename (c_token
*token
)
497 switch (token
->id_kind
)
506 gcc_assert (c_dialect_objc ());
512 switch (token
->keyword
)
543 if (token
->keyword
>= RID_FIRST_INT_N
544 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
545 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
550 if (c_dialect_objc ())
558 enum c_lookahead_kind
{
559 /* Always treat unknown identifiers as typenames. */
562 /* Could be parsing a nonabstract declarator. Only treat an identifier
563 as a typename if followed by another identifier or a star. */
564 cla_nonabstract_decl
,
566 /* Never treat identifiers as typenames. */
570 /* Return true if the next token from PARSER can start a type name,
571 false otherwise. LA specifies how to do lookahead in order to
572 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
575 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
577 c_token
*token
= c_parser_peek_token (parser
);
578 if (c_token_starts_typename (token
))
581 /* Try a bit harder to detect an unknown typename. */
582 if (la
!= cla_prefer_id
583 && token
->type
== CPP_NAME
584 && token
->id_kind
== C_ID_ID
586 /* Do not try too hard when we could have "object in array". */
587 && !parser
->objc_could_be_foreach_context
589 && (la
== cla_prefer_type
590 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
591 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
593 /* Only unknown identifiers. */
594 && !lookup_name (token
->value
))
600 /* Return true if TOKEN is a type qualifier, false otherwise. */
602 c_token_is_qualifier (c_token
*token
)
607 switch (token
->id_kind
)
615 switch (token
->keyword
)
633 /* Return true if the next token from PARSER is a type qualifier,
636 c_parser_next_token_is_qualifier (c_parser
*parser
)
638 c_token
*token
= c_parser_peek_token (parser
);
639 return c_token_is_qualifier (token
);
642 /* Return true if TOKEN can start declaration specifiers, false
645 c_token_starts_declspecs (c_token
*token
)
650 switch (token
->id_kind
)
659 gcc_assert (c_dialect_objc ());
665 switch (token
->keyword
)
705 if (token
->keyword
>= RID_FIRST_INT_N
706 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
707 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
712 if (c_dialect_objc ())
721 /* Return true if TOKEN can start declaration specifiers or a static
722 assertion, false otherwise. */
724 c_token_starts_declaration (c_token
*token
)
726 if (c_token_starts_declspecs (token
)
727 || token
->keyword
== RID_STATIC_ASSERT
)
733 /* Return true if the next token from PARSER can start declaration
734 specifiers, false otherwise. */
736 c_parser_next_token_starts_declspecs (c_parser
*parser
)
738 c_token
*token
= c_parser_peek_token (parser
);
740 /* In Objective-C, a classname normally starts a declspecs unless it
741 is immediately followed by a dot. In that case, it is the
742 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
743 setter/getter on the class. c_token_starts_declspecs() can't
744 differentiate between the two cases because it only checks the
745 current token, so we have a special check here. */
746 if (c_dialect_objc ()
747 && token
->type
== CPP_NAME
748 && token
->id_kind
== C_ID_CLASSNAME
749 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
752 return c_token_starts_declspecs (token
);
755 /* Return true if the next tokens from PARSER can start declaration
756 specifiers or a static assertion, false otherwise. */
758 c_parser_next_tokens_start_declaration (c_parser
*parser
)
760 c_token
*token
= c_parser_peek_token (parser
);
763 if (c_dialect_objc ()
764 && token
->type
== CPP_NAME
765 && token
->id_kind
== C_ID_CLASSNAME
766 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
769 /* Labels do not start declarations. */
770 if (token
->type
== CPP_NAME
771 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
774 if (c_token_starts_declaration (token
))
777 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
783 /* Consume the next token from PARSER. */
786 c_parser_consume_token (c_parser
*parser
)
788 gcc_assert (parser
->tokens_avail
>= 1);
789 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
790 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
791 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
792 if (parser
->tokens
!= &parser
->tokens_buf
[0])
794 else if (parser
->tokens_avail
== 2)
795 parser
->tokens
[0] = parser
->tokens
[1];
796 parser
->tokens_avail
--;
799 /* Expect the current token to be a #pragma. Consume it and remember
800 that we've begun parsing a pragma. */
803 c_parser_consume_pragma (c_parser
*parser
)
805 gcc_assert (!parser
->in_pragma
);
806 gcc_assert (parser
->tokens_avail
>= 1);
807 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
808 if (parser
->tokens
!= &parser
->tokens_buf
[0])
810 else if (parser
->tokens_avail
== 2)
811 parser
->tokens
[0] = parser
->tokens
[1];
812 parser
->tokens_avail
--;
813 parser
->in_pragma
= true;
816 /* Update the global input_location from TOKEN. */
818 c_parser_set_source_position_from_token (c_token
*token
)
820 if (token
->type
!= CPP_EOF
)
822 input_location
= token
->location
;
826 /* Issue a diagnostic of the form
827 FILE:LINE: MESSAGE before TOKEN
828 where TOKEN is the next token in the input stream of PARSER.
829 MESSAGE (specified by the caller) is usually of the form "expected
832 Do not issue a diagnostic if still recovering from an error.
834 ??? This is taken from the C++ parser, but building up messages in
835 this way is not i18n-friendly and some other approach should be
839 c_parser_error (c_parser
*parser
, const char *gmsgid
)
841 c_token
*token
= c_parser_peek_token (parser
);
844 parser
->error
= true;
847 /* This diagnostic makes more sense if it is tagged to the line of
848 the token we just peeked at. */
849 c_parser_set_source_position_from_token (token
);
850 c_parse_error (gmsgid
,
851 /* Because c_parse_error does not understand
852 CPP_KEYWORD, keywords are treated like
854 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
855 /* ??? The C parser does not save the cpp flags of a
856 token, we need to pass 0 here and we will not get
857 the source spelling of some tokens but rather the
858 canonical spelling. */
859 token
->value
, /*flags=*/0);
862 /* If the next token is of the indicated TYPE, consume it. Otherwise,
863 issue the error MSGID. If MSGID is NULL then a message has already
864 been produced and no message will be produced this time. Returns
865 true if found, false otherwise. */
868 c_parser_require (c_parser
*parser
,
872 if (c_parser_next_token_is (parser
, type
))
874 c_parser_consume_token (parser
);
879 c_parser_error (parser
, msgid
);
884 /* If the next token is the indicated keyword, consume it. Otherwise,
885 issue the error MSGID. Returns true if found, false otherwise. */
888 c_parser_require_keyword (c_parser
*parser
,
892 if (c_parser_next_token_is_keyword (parser
, keyword
))
894 c_parser_consume_token (parser
);
899 c_parser_error (parser
, msgid
);
904 /* Like c_parser_require, except that tokens will be skipped until the
905 desired token is found. An error message is still produced if the
906 next token is not as expected. If MSGID is NULL then a message has
907 already been produced and no message will be produced this
911 c_parser_skip_until_found (c_parser
*parser
,
915 unsigned nesting_depth
= 0;
917 if (c_parser_require (parser
, type
, msgid
))
920 /* Skip tokens until the desired token is found. */
923 /* Peek at the next token. */
924 c_token
*token
= c_parser_peek_token (parser
);
925 /* If we've reached the token we want, consume it and stop. */
926 if (token
->type
== type
&& !nesting_depth
)
928 c_parser_consume_token (parser
);
932 /* If we've run out of tokens, stop. */
933 if (token
->type
== CPP_EOF
)
935 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
937 if (token
->type
== CPP_OPEN_BRACE
938 || token
->type
== CPP_OPEN_PAREN
939 || token
->type
== CPP_OPEN_SQUARE
)
941 else if (token
->type
== CPP_CLOSE_BRACE
942 || token
->type
== CPP_CLOSE_PAREN
943 || token
->type
== CPP_CLOSE_SQUARE
)
945 if (nesting_depth
-- == 0)
948 /* Consume this token. */
949 c_parser_consume_token (parser
);
951 parser
->error
= false;
954 /* Skip tokens until the end of a parameter is found, but do not
955 consume the comma, semicolon or closing delimiter. */
958 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
960 unsigned nesting_depth
= 0;
964 c_token
*token
= c_parser_peek_token (parser
);
965 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
968 /* If we've run out of tokens, stop. */
969 if (token
->type
== CPP_EOF
)
971 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
973 if (token
->type
== CPP_OPEN_BRACE
974 || token
->type
== CPP_OPEN_PAREN
975 || token
->type
== CPP_OPEN_SQUARE
)
977 else if (token
->type
== CPP_CLOSE_BRACE
978 || token
->type
== CPP_CLOSE_PAREN
979 || token
->type
== CPP_CLOSE_SQUARE
)
981 if (nesting_depth
-- == 0)
984 /* Consume this token. */
985 c_parser_consume_token (parser
);
987 parser
->error
= false;
990 /* Expect to be at the end of the pragma directive and consume an
991 end of line marker. */
994 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
996 gcc_assert (parser
->in_pragma
);
997 parser
->in_pragma
= false;
999 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1000 c_parser_error (parser
, "expected end of line");
1002 cpp_ttype token_type
;
1005 c_token
*token
= c_parser_peek_token (parser
);
1006 token_type
= token
->type
;
1007 if (token_type
== CPP_EOF
)
1009 c_parser_consume_token (parser
);
1011 while (token_type
!= CPP_PRAGMA_EOL
);
1013 parser
->error
= false;
1016 /* Skip tokens until we have consumed an entire block, or until we
1017 have consumed a non-nested ';'. */
1020 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1022 unsigned nesting_depth
= 0;
1023 bool save_error
= parser
->error
;
1029 /* Peek at the next token. */
1030 token
= c_parser_peek_token (parser
);
1032 switch (token
->type
)
1037 case CPP_PRAGMA_EOL
:
1038 if (parser
->in_pragma
)
1043 /* If the next token is a ';', we have reached the
1044 end of the statement. */
1047 /* Consume the ';'. */
1048 c_parser_consume_token (parser
);
1053 case CPP_CLOSE_BRACE
:
1054 /* If the next token is a non-nested '}', then we have
1055 reached the end of the current block. */
1056 if (nesting_depth
== 0 || --nesting_depth
== 0)
1058 c_parser_consume_token (parser
);
1063 case CPP_OPEN_BRACE
:
1064 /* If it the next token is a '{', then we are entering a new
1065 block. Consume the entire block. */
1070 /* If we see a pragma, consume the whole thing at once. We
1071 have some safeguards against consuming pragmas willy-nilly.
1072 Normally, we'd expect to be here with parser->error set,
1073 which disables these safeguards. But it's possible to get
1074 here for secondary error recovery, after parser->error has
1076 c_parser_consume_pragma (parser
);
1077 c_parser_skip_to_pragma_eol (parser
);
1078 parser
->error
= save_error
;
1085 c_parser_consume_token (parser
);
1089 parser
->error
= false;
1092 /* CPP's options (initialized by c-opts.c). */
1093 extern cpp_options
*cpp_opts
;
1095 /* Save the warning flags which are controlled by __extension__. */
1098 disable_extension_diagnostics (void)
1101 | (warn_pointer_arith
<< 1)
1102 | (warn_traditional
<< 2)
1104 | (warn_long_long
<< 4)
1105 | (warn_cxx_compat
<< 5)
1106 | (warn_overlength_strings
<< 6)
1107 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1108 play tricks to properly restore it. */
1109 | ((warn_c90_c99_compat
== 1) << 7)
1110 | ((warn_c90_c99_compat
== -1) << 8)
1111 /* Similarly for warn_c99_c11_compat. */
1112 | ((warn_c99_c11_compat
== 1) << 9)
1113 | ((warn_c99_c11_compat
== -1) << 10)
1115 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1116 warn_pointer_arith
= 0;
1117 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1119 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1120 warn_cxx_compat
= 0;
1121 warn_overlength_strings
= 0;
1122 warn_c90_c99_compat
= 0;
1123 warn_c99_c11_compat
= 0;
1127 /* Restore the warning flags which are controlled by __extension__.
1128 FLAGS is the return value from disable_extension_diagnostics. */
1131 restore_extension_diagnostics (int flags
)
1133 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1134 warn_pointer_arith
= (flags
>> 1) & 1;
1135 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1136 flag_iso
= (flags
>> 3) & 1;
1137 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1138 warn_cxx_compat
= (flags
>> 5) & 1;
1139 warn_overlength_strings
= (flags
>> 6) & 1;
1140 /* See above for why is this needed. */
1141 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1142 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1145 /* Possibly kinds of declarator to parse. */
1146 typedef enum c_dtr_syn
{
1147 /* A normal declarator with an identifier. */
1149 /* An abstract declarator (maybe empty). */
1151 /* A parameter declarator: may be either, but after a type name does
1152 not redeclare a typedef name as an identifier if it can
1153 alternatively be interpreted as a typedef name; see DR#009,
1154 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1155 following DR#249. For example, given a typedef T, "int T" and
1156 "int *T" are valid parameter declarations redeclaring T, while
1157 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1158 abstract declarators rather than involving redundant parentheses;
1159 the same applies with attributes inside the parentheses before
1164 /* The binary operation precedence levels, where 0 is a dummy lowest level
1165 used for the bottom of the stack. */
1166 enum c_parser_prec
{
1181 static void c_parser_external_declaration (c_parser
*);
1182 static void c_parser_asm_definition (c_parser
*);
1183 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1184 bool, bool, tree
*, vec
<c_token
>);
1185 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1186 static void c_parser_static_assert_declaration (c_parser
*);
1187 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1188 bool, bool, bool, enum c_lookahead_kind
);
1189 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1190 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1191 static tree
c_parser_struct_declaration (c_parser
*);
1192 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1193 static tree
c_parser_alignas_specifier (c_parser
*);
1194 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1196 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1198 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1200 struct c_declarator
*);
1201 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1202 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1204 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1205 static tree
c_parser_simple_asm_expr (c_parser
*);
1206 static tree
c_parser_attributes (c_parser
*);
1207 static struct c_type_name
*c_parser_type_name (c_parser
*);
1208 static struct c_expr
c_parser_initializer (c_parser
*);
1209 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1210 static void c_parser_initelt (c_parser
*, struct obstack
*);
1211 static void c_parser_initval (c_parser
*, struct c_expr
*,
1213 static tree
c_parser_compound_statement (c_parser
*);
1214 static void c_parser_compound_statement_nostart (c_parser
*);
1215 static void c_parser_label (c_parser
*);
1216 static void c_parser_statement (c_parser
*);
1217 static void c_parser_statement_after_labels (c_parser
*);
1218 static void c_parser_if_statement (c_parser
*);
1219 static void c_parser_switch_statement (c_parser
*);
1220 static void c_parser_while_statement (c_parser
*, bool);
1221 static void c_parser_do_statement (c_parser
*, bool);
1222 static void c_parser_for_statement (c_parser
*, bool);
1223 static tree
c_parser_asm_statement (c_parser
*);
1224 static tree
c_parser_asm_operands (c_parser
*);
1225 static tree
c_parser_asm_goto_operands (c_parser
*);
1226 static tree
c_parser_asm_clobbers (c_parser
*);
1227 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1229 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1230 struct c_expr
*, tree
);
1231 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1233 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1234 static struct c_expr
c_parser_unary_expression (c_parser
*);
1235 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1236 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1237 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1238 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1239 struct c_type_name
*,
1241 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1244 static tree
c_parser_transaction (c_parser
*, enum rid
);
1245 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1246 static tree
c_parser_transaction_cancel (c_parser
*);
1247 static struct c_expr
c_parser_expression (c_parser
*);
1248 static struct c_expr
c_parser_expression_conv (c_parser
*);
1249 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1250 vec
<tree
, va_gc
> **, location_t
*,
1251 tree
*, vec
<location_t
> *,
1252 unsigned int * = NULL
);
1253 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1254 static void c_parser_oacc_update (c_parser
*);
1255 static tree
c_parser_oacc_loop (location_t
, c_parser
*, char *);
1256 static void c_parser_omp_construct (c_parser
*);
1257 static void c_parser_omp_threadprivate (c_parser
*);
1258 static void c_parser_omp_barrier (c_parser
*);
1259 static void c_parser_omp_flush (c_parser
*);
1260 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1262 static void c_parser_omp_taskwait (c_parser
*);
1263 static void c_parser_omp_taskyield (c_parser
*);
1264 static void c_parser_omp_cancel (c_parser
*);
1265 static void c_parser_omp_cancellation_point (c_parser
*);
1267 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1268 pragma_stmt
, pragma_compound
};
1269 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1270 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1271 static void c_parser_omp_end_declare_target (c_parser
*);
1272 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1274 /* These Objective-C parser functions are only ever called when
1275 compiling Objective-C. */
1276 static void c_parser_objc_class_definition (c_parser
*, tree
);
1277 static void c_parser_objc_class_instance_variables (c_parser
*);
1278 static void c_parser_objc_class_declaration (c_parser
*);
1279 static void c_parser_objc_alias_declaration (c_parser
*);
1280 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1281 static bool c_parser_objc_method_type (c_parser
*);
1282 static void c_parser_objc_method_definition (c_parser
*);
1283 static void c_parser_objc_methodprotolist (c_parser
*);
1284 static void c_parser_objc_methodproto (c_parser
*);
1285 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1286 static tree
c_parser_objc_type_name (c_parser
*);
1287 static tree
c_parser_objc_protocol_refs (c_parser
*);
1288 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1289 static void c_parser_objc_synchronized_statement (c_parser
*);
1290 static tree
c_parser_objc_selector (c_parser
*);
1291 static tree
c_parser_objc_selector_arg (c_parser
*);
1292 static tree
c_parser_objc_receiver (c_parser
*);
1293 static tree
c_parser_objc_message_args (c_parser
*);
1294 static tree
c_parser_objc_keywordexpr (c_parser
*);
1295 static void c_parser_objc_at_property_declaration (c_parser
*);
1296 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1297 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1298 static bool c_parser_objc_diagnose_bad_element_prefix
1299 (c_parser
*, struct c_declspecs
*);
1301 /* Cilk Plus supporting routines. */
1302 static void c_parser_cilk_simd (c_parser
*);
1303 static void c_parser_cilk_for (c_parser
*, tree
);
1304 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1305 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1306 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1307 static void c_parser_cilk_grainsize (c_parser
*);
1309 /* Parse a translation unit (C90 6.7, C99 6.9).
1312 external-declarations
1314 external-declarations:
1315 external-declaration
1316 external-declarations external-declaration
1325 c_parser_translation_unit (c_parser
*parser
)
1327 if (c_parser_next_token_is (parser
, CPP_EOF
))
1329 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1330 "ISO C forbids an empty translation unit");
1334 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1335 mark_valid_location_for_stdc_pragma (false);
1339 c_parser_external_declaration (parser
);
1340 obstack_free (&parser_obstack
, obstack_position
);
1342 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1346 /* Parse an external declaration (C90 6.7, C99 6.9).
1348 external-declaration:
1354 external-declaration:
1357 __extension__ external-declaration
1361 external-declaration:
1362 objc-class-definition
1363 objc-class-declaration
1364 objc-alias-declaration
1365 objc-protocol-definition
1366 objc-method-definition
1371 c_parser_external_declaration (c_parser
*parser
)
1374 switch (c_parser_peek_token (parser
)->type
)
1377 switch (c_parser_peek_token (parser
)->keyword
)
1380 ext
= disable_extension_diagnostics ();
1381 c_parser_consume_token (parser
);
1382 c_parser_external_declaration (parser
);
1383 restore_extension_diagnostics (ext
);
1386 c_parser_asm_definition (parser
);
1388 case RID_AT_INTERFACE
:
1389 case RID_AT_IMPLEMENTATION
:
1390 gcc_assert (c_dialect_objc ());
1391 c_parser_objc_class_definition (parser
, NULL_TREE
);
1394 gcc_assert (c_dialect_objc ());
1395 c_parser_objc_class_declaration (parser
);
1398 gcc_assert (c_dialect_objc ());
1399 c_parser_objc_alias_declaration (parser
);
1401 case RID_AT_PROTOCOL
:
1402 gcc_assert (c_dialect_objc ());
1403 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1405 case RID_AT_PROPERTY
:
1406 gcc_assert (c_dialect_objc ());
1407 c_parser_objc_at_property_declaration (parser
);
1409 case RID_AT_SYNTHESIZE
:
1410 gcc_assert (c_dialect_objc ());
1411 c_parser_objc_at_synthesize_declaration (parser
);
1413 case RID_AT_DYNAMIC
:
1414 gcc_assert (c_dialect_objc ());
1415 c_parser_objc_at_dynamic_declaration (parser
);
1418 gcc_assert (c_dialect_objc ());
1419 c_parser_consume_token (parser
);
1420 objc_finish_implementation ();
1427 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1428 "ISO C does not allow extra %<;%> outside of a function");
1429 c_parser_consume_token (parser
);
1432 mark_valid_location_for_stdc_pragma (true);
1433 c_parser_pragma (parser
, pragma_external
);
1434 mark_valid_location_for_stdc_pragma (false);
1438 if (c_dialect_objc ())
1440 c_parser_objc_method_definition (parser
);
1443 /* Else fall through, and yield a syntax error trying to parse
1444 as a declaration or function definition. */
1447 /* A declaration or a function definition (or, in Objective-C,
1448 an @interface or @protocol with prefix attributes). We can
1449 only tell which after parsing the declaration specifiers, if
1450 any, and the first declarator. */
1451 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1457 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1459 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1460 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1461 accepted; otherwise (old-style parameter declarations) only other
1462 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1463 assertion is accepted; otherwise (old-style parameter declarations)
1464 it is not. If NESTED is true, we are inside a function or parsing
1465 old-style parameter declarations; any functions encountered are
1466 nested functions and declaration specifiers are required; otherwise
1467 we are at top level and functions are normal functions and
1468 declaration specifiers may be optional. If EMPTY_OK is true, empty
1469 declarations are OK (subject to all other constraints); otherwise
1470 (old-style parameter declarations) they are diagnosed. If
1471 START_ATTR_OK is true, the declaration specifiers may start with
1472 attributes; otherwise they may not.
1473 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1474 declaration when parsing an Objective-C foreach statement.
1477 declaration-specifiers init-declarator-list[opt] ;
1478 static_assert-declaration
1480 function-definition:
1481 declaration-specifiers[opt] declarator declaration-list[opt]
1486 declaration-list declaration
1488 init-declarator-list:
1490 init-declarator-list , init-declarator
1493 declarator simple-asm-expr[opt] attributes[opt]
1494 declarator simple-asm-expr[opt] attributes[opt] = initializer
1498 nested-function-definition:
1499 declaration-specifiers declarator declaration-list[opt]
1503 attributes objc-class-definition
1504 attributes objc-category-definition
1505 attributes objc-protocol-definition
1507 The simple-asm-expr and attributes are GNU extensions.
1509 This function does not handle __extension__; that is handled in its
1510 callers. ??? Following the old parser, __extension__ may start
1511 external declarations, declarations in functions and declarations
1512 at the start of "for" loops, but not old-style parameter
1515 C99 requires declaration specifiers in a function definition; the
1516 absence is diagnosed through the diagnosis of implicit int. In GNU
1517 C we also allow but diagnose declarations without declaration
1518 specifiers, but only at top level (elsewhere they conflict with
1521 In Objective-C, declarations of the looping variable in a foreach
1522 statement are exceptionally terminated by 'in' (for example, 'for
1523 (NSObject *object in array) { ... }').
1528 threadprivate-directive */
1531 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1532 bool static_assert_ok
, bool empty_ok
,
1533 bool nested
, bool start_attr_ok
,
1534 tree
*objc_foreach_object_declaration
,
1535 vec
<c_token
> omp_declare_simd_clauses
)
1537 struct c_declspecs
*specs
;
1539 tree all_prefix_attrs
;
1540 bool diagnosed_no_specs
= false;
1541 location_t here
= c_parser_peek_token (parser
)->location
;
1543 if (static_assert_ok
1544 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1546 c_parser_static_assert_declaration (parser
);
1549 specs
= build_null_declspecs ();
1551 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1552 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1553 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1554 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1555 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1556 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1558 error_at (here
, "unknown type name %qE",
1559 c_parser_peek_token (parser
)->value
);
1561 /* Parse declspecs normally to get a correct pointer type, but avoid
1562 a further "fails to be a type name" error. Refuse nested functions
1563 since it is not how the user likely wants us to recover. */
1564 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1565 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1566 c_parser_peek_token (parser
)->value
= error_mark_node
;
1570 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1571 true, true, cla_nonabstract_decl
);
1574 c_parser_skip_to_end_of_block_or_statement (parser
);
1577 if (nested
&& !specs
->declspecs_seen_p
)
1579 c_parser_error (parser
, "expected declaration specifiers");
1580 c_parser_skip_to_end_of_block_or_statement (parser
);
1583 finish_declspecs (specs
);
1584 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1585 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1588 error_at (here
, "%<__auto_type%> in empty declaration");
1593 shadow_tag_warned (specs
, 1);
1594 pedwarn (here
, 0, "empty declaration");
1596 c_parser_consume_token (parser
);
1600 /* Provide better error recovery. Note that a type name here is usually
1601 better diagnosed as a redeclaration. */
1603 && specs
->typespec_kind
== ctsk_tagdef
1604 && c_parser_next_token_starts_declspecs (parser
)
1605 && !c_parser_next_token_is (parser
, CPP_NAME
))
1607 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1608 parser
->error
= false;
1609 shadow_tag_warned (specs
, 1);
1612 else if (c_dialect_objc () && !auto_type_p
)
1614 /* Prefix attributes are an error on method decls. */
1615 switch (c_parser_peek_token (parser
)->type
)
1619 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1623 warning_at (c_parser_peek_token (parser
)->location
,
1625 "prefix attributes are ignored for methods");
1626 specs
->attrs
= NULL_TREE
;
1629 c_parser_objc_method_definition (parser
);
1631 c_parser_objc_methodproto (parser
);
1637 /* This is where we parse 'attributes @interface ...',
1638 'attributes @implementation ...', 'attributes @protocol ...'
1639 (where attributes could be, for example, __attribute__
1642 switch (c_parser_peek_token (parser
)->keyword
)
1644 case RID_AT_INTERFACE
:
1646 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1648 c_parser_objc_class_definition (parser
, specs
->attrs
);
1652 case RID_AT_IMPLEMENTATION
:
1654 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1658 warning_at (c_parser_peek_token (parser
)->location
,
1660 "prefix attributes are ignored for implementations");
1661 specs
->attrs
= NULL_TREE
;
1663 c_parser_objc_class_definition (parser
, NULL_TREE
);
1667 case RID_AT_PROTOCOL
:
1669 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1671 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1678 case RID_AT_PROPERTY
:
1681 c_parser_error (parser
, "unexpected attribute");
1682 specs
->attrs
= NULL
;
1690 pending_xref_error ();
1691 prefix_attrs
= specs
->attrs
;
1692 all_prefix_attrs
= prefix_attrs
;
1693 specs
->attrs
= NULL_TREE
;
1696 struct c_declarator
*declarator
;
1700 /* Declaring either one or more declarators (in which case we
1701 should diagnose if there were no declaration specifiers) or a
1702 function definition (in which case the diagnostic for
1703 implicit int suffices). */
1704 declarator
= c_parser_declarator (parser
,
1705 specs
->typespec_kind
!= ctsk_none
,
1706 C_DTR_NORMAL
, &dummy
);
1707 if (declarator
== NULL
)
1709 if (omp_declare_simd_clauses
.exists ()
1710 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1711 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1712 omp_declare_simd_clauses
);
1713 c_parser_skip_to_end_of_block_or_statement (parser
);
1716 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1719 "%<__auto_type%> requires a plain identifier"
1721 c_parser_skip_to_end_of_block_or_statement (parser
);
1724 if (c_parser_next_token_is (parser
, CPP_EQ
)
1725 || c_parser_next_token_is (parser
, CPP_COMMA
)
1726 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1727 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1728 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1729 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1731 tree asm_name
= NULL_TREE
;
1732 tree postfix_attrs
= NULL_TREE
;
1733 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1735 diagnosed_no_specs
= true;
1736 pedwarn (here
, 0, "data definition has no type or storage class");
1738 /* Having seen a data definition, there cannot now be a
1739 function definition. */
1741 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1742 asm_name
= c_parser_simple_asm_expr (parser
);
1743 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1745 postfix_attrs
= c_parser_attributes (parser
);
1746 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1748 /* This means there is an attribute specifier after
1749 the declarator in a function definition. Provide
1750 some more information for the user. */
1751 error_at (here
, "attributes should be specified before the "
1752 "declarator in a function definition");
1753 c_parser_skip_to_end_of_block_or_statement (parser
);
1757 if (c_parser_next_token_is (parser
, CPP_EQ
))
1761 location_t init_loc
;
1762 c_parser_consume_token (parser
);
1765 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1766 init_loc
= c_parser_peek_token (parser
)->location
;
1767 init
= c_parser_expr_no_commas (parser
, NULL
);
1768 if (TREE_CODE (init
.value
) == COMPONENT_REF
1769 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1771 "%<__auto_type%> used with a bit-field"
1773 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1774 tree init_type
= TREE_TYPE (init
.value
);
1775 /* As with typeof, remove all qualifiers from atomic types. */
1776 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1778 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1779 bool vm_type
= variably_modified_type_p (init_type
,
1782 init
.value
= c_save_expr (init
.value
);
1784 specs
->typespec_kind
= ctsk_typeof
;
1785 specs
->locations
[cdw_typedef
] = init_loc
;
1786 specs
->typedef_p
= true;
1787 specs
->type
= init_type
;
1790 bool maybe_const
= true;
1791 tree type_expr
= c_fully_fold (init
.value
, false,
1793 specs
->expr_const_operands
&= maybe_const
;
1795 specs
->expr
= build2 (COMPOUND_EXPR
,
1796 TREE_TYPE (type_expr
),
1797 specs
->expr
, type_expr
);
1799 specs
->expr
= type_expr
;
1801 d
= start_decl (declarator
, specs
, true,
1802 chainon (postfix_attrs
, all_prefix_attrs
));
1804 d
= error_mark_node
;
1805 if (omp_declare_simd_clauses
.exists ()
1806 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1807 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1808 omp_declare_simd_clauses
);
1812 /* The declaration of the variable is in effect while
1813 its initializer is parsed. */
1814 d
= start_decl (declarator
, specs
, true,
1815 chainon (postfix_attrs
, all_prefix_attrs
));
1817 d
= error_mark_node
;
1818 if (omp_declare_simd_clauses
.exists ()
1819 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1820 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1821 omp_declare_simd_clauses
);
1822 start_init (d
, asm_name
, global_bindings_p ());
1823 init_loc
= c_parser_peek_token (parser
)->location
;
1824 init
= c_parser_initializer (parser
);
1827 if (d
!= error_mark_node
)
1829 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1830 finish_decl (d
, init_loc
, init
.value
,
1831 init
.original_type
, asm_name
);
1839 "%<__auto_type%> requires an initialized "
1840 "data declaration");
1841 c_parser_skip_to_end_of_block_or_statement (parser
);
1844 tree d
= start_decl (declarator
, specs
, false,
1845 chainon (postfix_attrs
,
1847 if (omp_declare_simd_clauses
.exists ()
1848 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1850 tree parms
= NULL_TREE
;
1851 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1853 struct c_declarator
*ce
= declarator
;
1855 if (ce
->kind
== cdk_function
)
1857 parms
= ce
->u
.arg_info
->parms
;
1861 ce
= ce
->declarator
;
1864 temp_store_parm_decls (d
, parms
);
1865 c_finish_omp_declare_simd (parser
, d
, parms
,
1866 omp_declare_simd_clauses
);
1868 temp_pop_parm_decls ();
1871 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1872 NULL_TREE
, asm_name
);
1874 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1877 *objc_foreach_object_declaration
= d
;
1879 *objc_foreach_object_declaration
= error_mark_node
;
1882 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1887 "%<__auto_type%> may only be used with"
1888 " a single declarator");
1889 c_parser_skip_to_end_of_block_or_statement (parser
);
1892 c_parser_consume_token (parser
);
1893 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1894 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1897 all_prefix_attrs
= prefix_attrs
;
1900 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1902 c_parser_consume_token (parser
);
1905 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1907 /* This can only happen in Objective-C: we found the
1908 'in' that terminates the declaration inside an
1909 Objective-C foreach statement. Do not consume the
1910 token, so that the caller can use it to determine
1911 that this indeed is a foreach context. */
1916 c_parser_error (parser
, "expected %<,%> or %<;%>");
1917 c_parser_skip_to_end_of_block_or_statement (parser
);
1921 else if (auto_type_p
)
1924 "%<__auto_type%> requires an initialized data declaration");
1925 c_parser_skip_to_end_of_block_or_statement (parser
);
1930 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1931 "%<asm%> or %<__attribute__%>");
1932 c_parser_skip_to_end_of_block_or_statement (parser
);
1935 /* Function definition (nested or otherwise). */
1938 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1939 c_push_function_context ();
1941 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1943 /* This can appear in many cases looking nothing like a
1944 function definition, so we don't give a more specific
1945 error suggesting there was one. */
1946 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1947 "or %<__attribute__%>");
1949 c_pop_function_context ();
1953 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1954 tv
= TV_PARSE_INLINE
;
1959 /* Parse old-style parameter declarations. ??? Attributes are
1960 not allowed to start declaration specifiers here because of a
1961 syntax conflict between a function declaration with attribute
1962 suffix and a function definition with an attribute prefix on
1963 first old-style parameter declaration. Following the old
1964 parser, they are not accepted on subsequent old-style
1965 parameter declarations either. However, there is no
1966 ambiguity after the first declaration, nor indeed on the
1967 first as long as we don't allow postfix attributes after a
1968 declarator with a nonempty identifier list in a definition;
1969 and postfix attributes have never been accepted here in
1970 function definitions either. */
1971 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1972 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1973 c_parser_declaration_or_fndef (parser
, false, false, false,
1974 true, false, NULL
, vNULL
);
1975 store_parm_decls ();
1976 if (omp_declare_simd_clauses
.exists ()
1977 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1978 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1979 omp_declare_simd_clauses
);
1980 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1981 = c_parser_peek_token (parser
)->location
;
1982 fnbody
= c_parser_compound_statement (parser
);
1983 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1984 fnbody
= expand_array_notation_exprs (fnbody
);
1987 tree decl
= current_function_decl
;
1988 /* Mark nested functions as needing static-chain initially.
1989 lower_nested_functions will recompute it but the
1990 DECL_STATIC_CHAIN flag is also used before that happens,
1991 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1992 DECL_STATIC_CHAIN (decl
) = 1;
1995 c_pop_function_context ();
1996 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2009 /* Parse an asm-definition (asm() outside a function body). This is a
2017 c_parser_asm_definition (c_parser
*parser
)
2019 tree asm_str
= c_parser_simple_asm_expr (parser
);
2021 symtab
->finalize_toplevel_asm (asm_str
);
2022 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2025 /* Parse a static assertion (C11 6.7.10).
2027 static_assert-declaration:
2028 static_assert-declaration-no-semi ;
2032 c_parser_static_assert_declaration (c_parser
*parser
)
2034 c_parser_static_assert_declaration_no_semi (parser
);
2036 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2037 c_parser_skip_to_end_of_block_or_statement (parser
);
2040 /* Parse a static assertion (C11 6.7.10), without the trailing
2043 static_assert-declaration-no-semi:
2044 _Static_assert ( constant-expression , string-literal )
2048 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2050 location_t assert_loc
, value_loc
;
2054 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2055 assert_loc
= c_parser_peek_token (parser
)->location
;
2057 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2058 "ISO C99 does not support %<_Static_assert%>");
2060 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2061 "ISO C90 does not support %<_Static_assert%>");
2062 c_parser_consume_token (parser
);
2063 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2065 value_loc
= c_parser_peek_token (parser
)->location
;
2066 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2067 parser
->lex_untranslated_string
= true;
2068 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2070 parser
->lex_untranslated_string
= false;
2073 switch (c_parser_peek_token (parser
)->type
)
2079 case CPP_UTF8STRING
:
2080 string
= c_parser_peek_token (parser
)->value
;
2081 c_parser_consume_token (parser
);
2082 parser
->lex_untranslated_string
= false;
2085 c_parser_error (parser
, "expected string literal");
2086 parser
->lex_untranslated_string
= false;
2089 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2091 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2093 error_at (value_loc
, "expression in static assertion is not an integer");
2096 if (TREE_CODE (value
) != INTEGER_CST
)
2098 value
= c_fully_fold (value
, false, NULL
);
2099 /* Strip no-op conversions. */
2100 STRIP_TYPE_NOPS (value
);
2101 if (TREE_CODE (value
) == INTEGER_CST
)
2102 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2103 "is not an integer constant expression");
2105 if (TREE_CODE (value
) != INTEGER_CST
)
2107 error_at (value_loc
, "expression in static assertion is not constant");
2110 constant_expression_warning (value
);
2111 if (integer_zerop (value
))
2112 error_at (assert_loc
, "static assertion failed: %E", string
);
2115 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2116 6.7), adding them to SPECS (which may already include some).
2117 Storage class specifiers are accepted iff SCSPEC_OK; type
2118 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2119 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2120 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2122 declaration-specifiers:
2123 storage-class-specifier declaration-specifiers[opt]
2124 type-specifier declaration-specifiers[opt]
2125 type-qualifier declaration-specifiers[opt]
2126 function-specifier declaration-specifiers[opt]
2127 alignment-specifier declaration-specifiers[opt]
2129 Function specifiers (inline) are from C99, and are currently
2130 handled as storage class specifiers, as is __thread. Alignment
2131 specifiers are from C11.
2133 C90 6.5.1, C99 6.7.1:
2134 storage-class-specifier:
2142 (_Thread_local is new in C11.)
2149 (_Noreturn is new in C11.)
2151 C90 6.5.2, C99 6.7.2:
2164 [_Imaginary removed in C99 TC2]
2165 struct-or-union-specifier
2168 atomic-type-specifier
2170 (_Bool and _Complex are new in C99.)
2171 (atomic-type-specifier is new in C11.)
2173 C90 6.5.3, C99 6.7.3:
2179 address-space-qualifier
2182 (restrict is new in C99.)
2183 (_Atomic is new in C11.)
2187 declaration-specifiers:
2188 attributes declaration-specifiers[opt]
2194 identifier recognized by the target
2196 storage-class-specifier:
2210 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2211 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2213 atomic-type-specifier
2214 _Atomic ( type-name )
2219 class-name objc-protocol-refs[opt]
2220 typedef-name objc-protocol-refs
2225 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2226 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2227 bool alignspec_ok
, bool auto_type_ok
,
2228 enum c_lookahead_kind la
)
2230 bool attrs_ok
= start_attr_ok
;
2231 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2234 gcc_assert (la
== cla_prefer_id
);
2236 while (c_parser_next_token_is (parser
, CPP_NAME
)
2237 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2238 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2240 struct c_typespec t
;
2243 location_t loc
= c_parser_peek_token (parser
)->location
;
2245 /* If we cannot accept a type, exit if the next token must start
2246 one. Also, if we already have seen a tagged definition,
2247 a typename would be an error anyway and likely the user
2248 has simply forgotten a semicolon, so we exit. */
2249 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2250 && c_parser_next_tokens_start_typename (parser
, la
)
2251 && !c_parser_next_token_is_qualifier (parser
))
2254 if (c_parser_next_token_is (parser
, CPP_NAME
))
2256 c_token
*name_token
= c_parser_peek_token (parser
);
2257 tree value
= name_token
->value
;
2258 c_id_kind kind
= name_token
->id_kind
;
2260 if (kind
== C_ID_ADDRSPACE
)
2263 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2264 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2265 c_parser_consume_token (parser
);
2270 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2272 /* If we cannot accept a type, and the next token must start one,
2273 exit. Do the same if we already have seen a tagged definition,
2274 since it would be an error anyway and likely the user has simply
2275 forgotten a semicolon. */
2276 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2279 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2280 a C_ID_CLASSNAME. */
2281 c_parser_consume_token (parser
);
2284 if (kind
== C_ID_ID
)
2286 error_at (loc
, "unknown type name %qE", value
);
2287 t
.kind
= ctsk_typedef
;
2288 t
.spec
= error_mark_node
;
2290 else if (kind
== C_ID_TYPENAME
2291 && (!c_dialect_objc ()
2292 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2294 t
.kind
= ctsk_typedef
;
2295 /* For a typedef name, record the meaning, not the name.
2296 In case of 'foo foo, bar;'. */
2297 t
.spec
= lookup_name (value
);
2301 tree proto
= NULL_TREE
;
2302 gcc_assert (c_dialect_objc ());
2304 if (c_parser_next_token_is (parser
, CPP_LESS
))
2305 proto
= c_parser_objc_protocol_refs (parser
);
2306 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2309 t
.expr_const_operands
= true;
2310 declspecs_add_type (name_token
->location
, specs
, t
);
2313 if (c_parser_next_token_is (parser
, CPP_LESS
))
2315 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2316 nisse@lysator.liu.se. */
2318 gcc_assert (c_dialect_objc ());
2319 if (!typespec_ok
|| seen_type
)
2321 proto
= c_parser_objc_protocol_refs (parser
);
2323 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2325 t
.expr_const_operands
= true;
2326 declspecs_add_type (loc
, specs
, t
);
2329 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2330 switch (c_parser_peek_token (parser
)->keyword
)
2343 /* TODO: Distinguish between function specifiers (inline, noreturn)
2344 and storage class specifiers, either here or in
2345 declspecs_add_scspec. */
2346 declspecs_add_scspec (loc
, specs
,
2347 c_parser_peek_token (parser
)->value
);
2348 c_parser_consume_token (parser
);
2379 if (c_dialect_objc ())
2380 parser
->objc_need_raw_identifier
= true;
2381 t
.kind
= ctsk_resword
;
2382 t
.spec
= c_parser_peek_token (parser
)->value
;
2384 t
.expr_const_operands
= true;
2385 declspecs_add_type (loc
, specs
, t
);
2386 c_parser_consume_token (parser
);
2393 t
= c_parser_enum_specifier (parser
);
2394 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2395 declspecs_add_type (loc
, specs
, t
);
2403 t
= c_parser_struct_or_union_specifier (parser
);
2404 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2405 declspecs_add_type (loc
, specs
, t
);
2408 /* ??? The old parser rejected typeof after other type
2409 specifiers, but is a syntax error the best way of
2411 if (!typespec_ok
|| seen_type
)
2415 t
= c_parser_typeof_specifier (parser
);
2416 declspecs_add_type (loc
, specs
, t
);
2419 /* C parser handling of Objective-C constructs needs
2420 checking for correct lvalue-to-rvalue conversions, and
2421 the code in build_modify_expr handling various
2422 Objective-C cases, and that in build_unary_op handling
2423 Objective-C cases for increment / decrement, also needs
2424 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2425 and objc_types_are_equivalent may also need updates. */
2426 if (c_dialect_objc ())
2427 sorry ("%<_Atomic%> in Objective-C");
2428 /* C parser handling of OpenMP constructs needs checking for
2429 correct lvalue-to-rvalue conversions. */
2431 sorry ("%<_Atomic%> with OpenMP");
2433 pedwarn_c99 (loc
, OPT_Wpedantic
,
2434 "ISO C99 does not support the %<_Atomic%> qualifier");
2436 pedwarn_c99 (loc
, OPT_Wpedantic
,
2437 "ISO C90 does not support the %<_Atomic%> qualifier");
2440 value
= c_parser_peek_token (parser
)->value
;
2441 c_parser_consume_token (parser
);
2442 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2444 /* _Atomic ( type-name ). */
2446 c_parser_consume_token (parser
);
2447 struct c_type_name
*type
= c_parser_type_name (parser
);
2448 t
.kind
= ctsk_typeof
;
2449 t
.spec
= error_mark_node
;
2451 t
.expr_const_operands
= true;
2453 t
.spec
= groktypename (type
, &t
.expr
,
2454 &t
.expr_const_operands
);
2455 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2457 if (t
.spec
!= error_mark_node
)
2459 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2460 error_at (loc
, "%<_Atomic%>-qualified array type");
2461 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2462 error_at (loc
, "%<_Atomic%>-qualified function type");
2463 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2464 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2466 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2468 declspecs_add_type (loc
, specs
, t
);
2471 declspecs_add_qual (loc
, specs
, value
);
2477 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2478 c_parser_consume_token (parser
);
2483 attrs
= c_parser_attributes (parser
);
2484 declspecs_add_attrs (loc
, specs
, attrs
);
2489 align
= c_parser_alignas_specifier (parser
);
2490 declspecs_add_alignas (loc
, specs
, align
);
2499 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2502 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2503 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2504 enum attributes[opt] identifier
2506 The form with trailing comma is new in C99. The forms with
2507 attributes are GNU extensions. In GNU C, we accept any expression
2508 without commas in the syntax (assignment expressions, not just
2509 conditional expressions); assignment expressions will be diagnosed
2514 enumerator-list , enumerator
2517 enumeration-constant
2518 enumeration-constant = constant-expression
2521 static struct c_typespec
2522 c_parser_enum_specifier (c_parser
*parser
)
2524 struct c_typespec ret
;
2526 tree ident
= NULL_TREE
;
2527 location_t enum_loc
;
2528 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2529 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2530 enum_loc
= c_parser_peek_token (parser
)->location
;
2531 c_parser_consume_token (parser
);
2532 attrs
= c_parser_attributes (parser
);
2533 enum_loc
= c_parser_peek_token (parser
)->location
;
2534 /* Set the location in case we create a decl now. */
2535 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2536 if (c_parser_next_token_is (parser
, CPP_NAME
))
2538 ident
= c_parser_peek_token (parser
)->value
;
2539 ident_loc
= c_parser_peek_token (parser
)->location
;
2540 enum_loc
= ident_loc
;
2541 c_parser_consume_token (parser
);
2543 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2545 /* Parse an enum definition. */
2546 struct c_enum_contents the_enum
;
2549 /* We chain the enumerators in reverse order, then put them in
2550 forward order at the end. */
2552 timevar_push (TV_PARSE_ENUM
);
2553 type
= start_enum (enum_loc
, &the_enum
, ident
);
2555 c_parser_consume_token (parser
);
2563 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2564 location_t decl_loc
, value_loc
;
2565 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2567 c_parser_error (parser
, "expected identifier");
2568 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2569 values
= error_mark_node
;
2572 token
= c_parser_peek_token (parser
);
2573 enum_id
= token
->value
;
2574 /* Set the location in case we create a decl now. */
2575 c_parser_set_source_position_from_token (token
);
2576 decl_loc
= value_loc
= token
->location
;
2577 c_parser_consume_token (parser
);
2578 if (c_parser_next_token_is (parser
, CPP_EQ
))
2580 c_parser_consume_token (parser
);
2581 value_loc
= c_parser_peek_token (parser
)->location
;
2582 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2585 enum_value
= NULL_TREE
;
2586 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2587 &the_enum
, enum_id
, enum_value
);
2588 TREE_CHAIN (enum_decl
) = values
;
2591 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2593 comma_loc
= c_parser_peek_token (parser
)->location
;
2595 c_parser_consume_token (parser
);
2597 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2600 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2601 "comma at end of enumerator list");
2602 c_parser_consume_token (parser
);
2607 c_parser_error (parser
, "expected %<,%> or %<}%>");
2608 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2609 values
= error_mark_node
;
2613 postfix_attrs
= c_parser_attributes (parser
);
2614 ret
.spec
= finish_enum (type
, nreverse (values
),
2615 chainon (attrs
, postfix_attrs
));
2616 ret
.kind
= ctsk_tagdef
;
2617 ret
.expr
= NULL_TREE
;
2618 ret
.expr_const_operands
= true;
2619 timevar_pop (TV_PARSE_ENUM
);
2624 c_parser_error (parser
, "expected %<{%>");
2625 ret
.spec
= error_mark_node
;
2626 ret
.kind
= ctsk_tagref
;
2627 ret
.expr
= NULL_TREE
;
2628 ret
.expr_const_operands
= true;
2631 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2632 /* In ISO C, enumerated types can be referred to only if already
2634 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2637 pedwarn (enum_loc
, OPT_Wpedantic
,
2638 "ISO C forbids forward references to %<enum%> types");
2643 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2645 struct-or-union-specifier:
2646 struct-or-union attributes[opt] identifier[opt]
2647 { struct-contents } attributes[opt]
2648 struct-or-union attributes[opt] identifier
2651 struct-declaration-list
2653 struct-declaration-list:
2654 struct-declaration ;
2655 struct-declaration-list struct-declaration ;
2662 struct-declaration-list struct-declaration
2664 struct-declaration-list:
2665 struct-declaration-list ;
2668 (Note that in the syntax here, unlike that in ISO C, the semicolons
2669 are included here rather than in struct-declaration, in order to
2670 describe the syntax with extra semicolons and missing semicolon at
2675 struct-declaration-list:
2676 @defs ( class-name )
2678 (Note this does not include a trailing semicolon, but can be
2679 followed by further declarations, and gets a pedwarn-if-pedantic
2680 when followed by a semicolon.) */
2682 static struct c_typespec
2683 c_parser_struct_or_union_specifier (c_parser
*parser
)
2685 struct c_typespec ret
;
2687 tree ident
= NULL_TREE
;
2688 location_t struct_loc
;
2689 location_t ident_loc
= UNKNOWN_LOCATION
;
2690 enum tree_code code
;
2691 switch (c_parser_peek_token (parser
)->keyword
)
2702 struct_loc
= c_parser_peek_token (parser
)->location
;
2703 c_parser_consume_token (parser
);
2704 attrs
= c_parser_attributes (parser
);
2706 /* Set the location in case we create a decl now. */
2707 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2709 if (c_parser_next_token_is (parser
, CPP_NAME
))
2711 ident
= c_parser_peek_token (parser
)->value
;
2712 ident_loc
= c_parser_peek_token (parser
)->location
;
2713 struct_loc
= ident_loc
;
2714 c_parser_consume_token (parser
);
2716 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2718 /* Parse a struct or union definition. Start the scope of the
2719 tag before parsing components. */
2720 struct c_struct_parse_info
*struct_info
;
2721 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2723 /* We chain the components in reverse order, then put them in
2724 forward order at the end. Each struct-declaration may
2725 declare multiple components (comma-separated), so we must use
2726 chainon to join them, although when parsing each
2727 struct-declaration we can use TREE_CHAIN directly.
2729 The theory behind all this is that there will be more
2730 semicolon separated fields than comma separated fields, and
2731 so we'll be minimizing the number of node traversals required
2734 timevar_push (TV_PARSE_STRUCT
);
2735 contents
= NULL_TREE
;
2736 c_parser_consume_token (parser
);
2737 /* Handle the Objective-C @defs construct,
2738 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2739 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2742 gcc_assert (c_dialect_objc ());
2743 c_parser_consume_token (parser
);
2744 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2746 if (c_parser_next_token_is (parser
, CPP_NAME
)
2747 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2749 name
= c_parser_peek_token (parser
)->value
;
2750 c_parser_consume_token (parser
);
2754 c_parser_error (parser
, "expected class name");
2755 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2758 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2760 contents
= nreverse (objc_get_class_ivars (name
));
2763 /* Parse the struct-declarations and semicolons. Problems with
2764 semicolons are diagnosed here; empty structures are diagnosed
2769 /* Parse any stray semicolon. */
2770 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2772 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2773 "extra semicolon in struct or union specified");
2774 c_parser_consume_token (parser
);
2777 /* Stop if at the end of the struct or union contents. */
2778 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2780 c_parser_consume_token (parser
);
2783 /* Accept #pragmas at struct scope. */
2784 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2786 c_parser_pragma (parser
, pragma_struct
);
2789 /* Parse some comma-separated declarations, but not the
2790 trailing semicolon if any. */
2791 decls
= c_parser_struct_declaration (parser
);
2792 contents
= chainon (decls
, contents
);
2793 /* If no semicolon follows, either we have a parse error or
2794 are at the end of the struct or union and should
2796 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2797 c_parser_consume_token (parser
);
2800 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2801 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2802 "no semicolon at end of struct or union");
2803 else if (parser
->error
2804 || !c_parser_next_token_starts_declspecs (parser
))
2806 c_parser_error (parser
, "expected %<;%>");
2807 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2811 /* If we come here, we have already emitted an error
2812 for an expected `;', identifier or `(', and we also
2813 recovered already. Go on with the next field. */
2816 postfix_attrs
= c_parser_attributes (parser
);
2817 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2818 chainon (attrs
, postfix_attrs
), struct_info
);
2819 ret
.kind
= ctsk_tagdef
;
2820 ret
.expr
= NULL_TREE
;
2821 ret
.expr_const_operands
= true;
2822 timevar_pop (TV_PARSE_STRUCT
);
2827 c_parser_error (parser
, "expected %<{%>");
2828 ret
.spec
= error_mark_node
;
2829 ret
.kind
= ctsk_tagref
;
2830 ret
.expr
= NULL_TREE
;
2831 ret
.expr_const_operands
= true;
2834 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2838 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2839 the trailing semicolon.
2842 specifier-qualifier-list struct-declarator-list
2843 static_assert-declaration-no-semi
2845 specifier-qualifier-list:
2846 type-specifier specifier-qualifier-list[opt]
2847 type-qualifier specifier-qualifier-list[opt]
2848 attributes specifier-qualifier-list[opt]
2850 struct-declarator-list:
2852 struct-declarator-list , attributes[opt] struct-declarator
2855 declarator attributes[opt]
2856 declarator[opt] : constant-expression attributes[opt]
2861 __extension__ struct-declaration
2862 specifier-qualifier-list
2864 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2865 of attributes where shown is a GNU extension. In GNU C, we accept
2866 any expression without commas in the syntax (assignment
2867 expressions, not just conditional expressions); assignment
2868 expressions will be diagnosed as non-constant. */
2871 c_parser_struct_declaration (c_parser
*parser
)
2873 struct c_declspecs
*specs
;
2875 tree all_prefix_attrs
;
2877 location_t decl_loc
;
2878 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2882 ext
= disable_extension_diagnostics ();
2883 c_parser_consume_token (parser
);
2884 decl
= c_parser_struct_declaration (parser
);
2885 restore_extension_diagnostics (ext
);
2888 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2890 c_parser_static_assert_declaration_no_semi (parser
);
2893 specs
= build_null_declspecs ();
2894 decl_loc
= c_parser_peek_token (parser
)->location
;
2895 /* Strictly by the standard, we shouldn't allow _Alignas here,
2896 but it appears to have been intended to allow it there, so
2897 we're keeping it as it is until WG14 reaches a conclusion
2899 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2900 c_parser_declspecs (parser
, specs
, false, true, true,
2901 true, false, cla_nonabstract_decl
);
2904 if (!specs
->declspecs_seen_p
)
2906 c_parser_error (parser
, "expected specifier-qualifier-list");
2909 finish_declspecs (specs
);
2910 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2911 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2914 if (specs
->typespec_kind
== ctsk_none
)
2916 pedwarn (decl_loc
, OPT_Wpedantic
,
2917 "ISO C forbids member declarations with no members");
2918 shadow_tag_warned (specs
, pedantic
);
2923 /* Support for unnamed structs or unions as members of
2924 structs or unions (which is [a] useful and [b] supports
2928 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2929 build_id_declarator (NULL_TREE
), specs
,
2932 decl_attributes (&ret
, attrs
, 0);
2937 /* Provide better error recovery. Note that a type name here is valid,
2938 and will be treated as a field name. */
2939 if (specs
->typespec_kind
== ctsk_tagdef
2940 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2941 && c_parser_next_token_starts_declspecs (parser
)
2942 && !c_parser_next_token_is (parser
, CPP_NAME
))
2944 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2945 parser
->error
= false;
2949 pending_xref_error ();
2950 prefix_attrs
= specs
->attrs
;
2951 all_prefix_attrs
= prefix_attrs
;
2952 specs
->attrs
= NULL_TREE
;
2956 /* Declaring one or more declarators or un-named bit-fields. */
2957 struct c_declarator
*declarator
;
2959 if (c_parser_next_token_is (parser
, CPP_COLON
))
2960 declarator
= build_id_declarator (NULL_TREE
);
2962 declarator
= c_parser_declarator (parser
,
2963 specs
->typespec_kind
!= ctsk_none
,
2964 C_DTR_NORMAL
, &dummy
);
2965 if (declarator
== NULL
)
2967 c_parser_skip_to_end_of_block_or_statement (parser
);
2970 if (c_parser_next_token_is (parser
, CPP_COLON
)
2971 || c_parser_next_token_is (parser
, CPP_COMMA
)
2972 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2973 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2974 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2976 tree postfix_attrs
= NULL_TREE
;
2977 tree width
= NULL_TREE
;
2979 if (c_parser_next_token_is (parser
, CPP_COLON
))
2981 c_parser_consume_token (parser
);
2982 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2984 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2985 postfix_attrs
= c_parser_attributes (parser
);
2986 d
= grokfield (c_parser_peek_token (parser
)->location
,
2987 declarator
, specs
, width
, &all_prefix_attrs
);
2988 decl_attributes (&d
, chainon (postfix_attrs
,
2989 all_prefix_attrs
), 0);
2990 DECL_CHAIN (d
) = decls
;
2992 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2993 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2996 all_prefix_attrs
= prefix_attrs
;
2997 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2998 c_parser_consume_token (parser
);
2999 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3000 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3002 /* Semicolon consumed in caller. */
3007 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3013 c_parser_error (parser
,
3014 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3015 "%<__attribute__%>");
3022 /* Parse a typeof specifier (a GNU extension).
3025 typeof ( expression )
3026 typeof ( type-name )
3029 static struct c_typespec
3030 c_parser_typeof_specifier (c_parser
*parser
)
3032 struct c_typespec ret
;
3033 ret
.kind
= ctsk_typeof
;
3034 ret
.spec
= error_mark_node
;
3035 ret
.expr
= NULL_TREE
;
3036 ret
.expr_const_operands
= true;
3037 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3038 c_parser_consume_token (parser
);
3039 c_inhibit_evaluation_warnings
++;
3041 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3043 c_inhibit_evaluation_warnings
--;
3047 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3049 struct c_type_name
*type
= c_parser_type_name (parser
);
3050 c_inhibit_evaluation_warnings
--;
3054 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3055 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3061 location_t here
= c_parser_peek_token (parser
)->location
;
3062 struct c_expr expr
= c_parser_expression (parser
);
3063 c_inhibit_evaluation_warnings
--;
3065 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3066 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3067 error_at (here
, "%<typeof%> applied to a bit-field");
3068 mark_exp_read (expr
.value
);
3069 ret
.spec
= TREE_TYPE (expr
.value
);
3070 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3071 /* This is returned with the type so that when the type is
3072 evaluated, this can be evaluated. */
3074 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3075 pop_maybe_used (was_vm
);
3076 /* For use in macros such as those in <stdatomic.h>, remove all
3077 qualifiers from atomic types. (const can be an issue for more macros
3078 using typeof than just the <stdatomic.h> ones.) */
3079 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3080 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3082 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3086 /* Parse an alignment-specifier.
3090 alignment-specifier:
3091 _Alignas ( type-name )
3092 _Alignas ( constant-expression )
3096 c_parser_alignas_specifier (c_parser
* parser
)
3098 tree ret
= error_mark_node
;
3099 location_t loc
= c_parser_peek_token (parser
)->location
;
3100 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3101 c_parser_consume_token (parser
);
3103 pedwarn_c99 (loc
, OPT_Wpedantic
,
3104 "ISO C99 does not support %<_Alignas%>");
3106 pedwarn_c99 (loc
, OPT_Wpedantic
,
3107 "ISO C90 does not support %<_Alignas%>");
3108 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3110 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3112 struct c_type_name
*type
= c_parser_type_name (parser
);
3114 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3118 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3119 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3123 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3124 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3125 be redeclared; otherwise it may not. KIND indicates which kind of
3126 declarator is wanted. Returns a valid declarator except in the
3127 case of a syntax error in which case NULL is returned. *SEEN_ID is
3128 set to true if an identifier being declared is seen; this is used
3129 to diagnose bad forms of abstract array declarators and to
3130 determine whether an identifier list is syntactically permitted.
3133 pointer[opt] direct-declarator
3137 ( attributes[opt] declarator )
3138 direct-declarator array-declarator
3139 direct-declarator ( parameter-type-list )
3140 direct-declarator ( identifier-list[opt] )
3143 * type-qualifier-list[opt]
3144 * type-qualifier-list[opt] pointer
3146 type-qualifier-list:
3149 type-qualifier-list type-qualifier
3150 type-qualifier-list attributes
3153 [ type-qualifier-list[opt] assignment-expression[opt] ]
3154 [ static type-qualifier-list[opt] assignment-expression ]
3155 [ type-qualifier-list static assignment-expression ]
3156 [ type-qualifier-list[opt] * ]
3158 parameter-type-list:
3160 parameter-list , ...
3163 parameter-declaration
3164 parameter-list , parameter-declaration
3166 parameter-declaration:
3167 declaration-specifiers declarator attributes[opt]
3168 declaration-specifiers abstract-declarator[opt] attributes[opt]
3172 identifier-list , identifier
3174 abstract-declarator:
3176 pointer[opt] direct-abstract-declarator
3178 direct-abstract-declarator:
3179 ( attributes[opt] abstract-declarator )
3180 direct-abstract-declarator[opt] array-declarator
3181 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3186 direct-declarator ( parameter-forward-declarations
3187 parameter-type-list[opt] )
3189 direct-abstract-declarator:
3190 direct-abstract-declarator[opt] ( parameter-forward-declarations
3191 parameter-type-list[opt] )
3193 parameter-forward-declarations:
3195 parameter-forward-declarations parameter-list ;
3197 The uses of attributes shown above are GNU extensions.
3199 Some forms of array declarator are not included in C99 in the
3200 syntax for abstract declarators; these are disallowed elsewhere.
3201 This may be a defect (DR#289).
3203 This function also accepts an omitted abstract declarator as being
3204 an abstract declarator, although not part of the formal syntax. */
3206 static struct c_declarator
*
3207 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3210 /* Parse any initial pointer part. */
3211 if (c_parser_next_token_is (parser
, CPP_MULT
))
3213 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3214 struct c_declarator
*inner
;
3215 c_parser_consume_token (parser
);
3216 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3217 false, false, cla_prefer_id
);
3218 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3222 return make_pointer_declarator (quals_attrs
, inner
);
3224 /* Now we have a direct declarator, direct abstract declarator or
3225 nothing (which counts as a direct abstract declarator here). */
3226 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3229 /* Parse a direct declarator or direct abstract declarator; arguments
3230 as c_parser_declarator. */
3232 static struct c_declarator
*
3233 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3236 /* The direct declarator must start with an identifier (possibly
3237 omitted) or a parenthesized declarator (possibly abstract). In
3238 an ordinary declarator, initial parentheses must start a
3239 parenthesized declarator. In an abstract declarator or parameter
3240 declarator, they could start a parenthesized declarator or a
3241 parameter list. To tell which, the open parenthesis and any
3242 following attributes must be read. If a declaration specifier
3243 follows, then it is a parameter list; if the specifier is a
3244 typedef name, there might be an ambiguity about redeclaring it,
3245 which is resolved in the direction of treating it as a typedef
3246 name. If a close parenthesis follows, it is also an empty
3247 parameter list, as the syntax does not permit empty abstract
3248 declarators. Otherwise, it is a parenthesized declarator (in
3249 which case the analysis may be repeated inside it, recursively).
3251 ??? There is an ambiguity in a parameter declaration "int
3252 (__attribute__((foo)) x)", where x is not a typedef name: it
3253 could be an abstract declarator for a function, or declare x with
3254 parentheses. The proper resolution of this ambiguity needs
3255 documenting. At present we follow an accident of the old
3256 parser's implementation, whereby the first parameter must have
3257 some declaration specifiers other than just attributes. Thus as
3258 a parameter declaration it is treated as a parenthesized
3259 parameter named x, and as an abstract declarator it is
3262 ??? Also following the old parser, attributes inside an empty
3263 parameter list are ignored, making it a list not yielding a
3264 prototype, rather than giving an error or making it have one
3265 parameter with implicit type int.
3267 ??? Also following the old parser, typedef names may be
3268 redeclared in declarators, but not Objective-C class names. */
3270 if (kind
!= C_DTR_ABSTRACT
3271 && c_parser_next_token_is (parser
, CPP_NAME
)
3273 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3274 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3275 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3277 struct c_declarator
*inner
3278 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3280 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3281 c_parser_consume_token (parser
);
3282 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3285 if (kind
!= C_DTR_NORMAL
3286 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3288 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3289 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3292 /* Either we are at the end of an abstract declarator, or we have
3295 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3298 struct c_declarator
*inner
;
3299 c_parser_consume_token (parser
);
3300 attrs
= c_parser_attributes (parser
);
3301 if (kind
!= C_DTR_NORMAL
3302 && (c_parser_next_token_starts_declspecs (parser
)
3303 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3305 struct c_arg_info
*args
3306 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3313 = build_function_declarator (args
,
3314 build_id_declarator (NULL_TREE
));
3315 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3319 /* A parenthesized declarator. */
3320 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3321 if (inner
!= NULL
&& attrs
!= NULL
)
3322 inner
= build_attrs_declarator (attrs
, inner
);
3323 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3325 c_parser_consume_token (parser
);
3329 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3333 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3340 if (kind
== C_DTR_NORMAL
)
3342 c_parser_error (parser
, "expected identifier or %<(%>");
3346 return build_id_declarator (NULL_TREE
);
3350 /* Parse part of a direct declarator or direct abstract declarator,
3351 given that some (in INNER) has already been parsed; ID_PRESENT is
3352 true if an identifier is present, false for an abstract
3355 static struct c_declarator
*
3356 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3357 struct c_declarator
*inner
)
3359 /* Parse a sequence of array declarators and parameter lists. */
3360 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3362 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3363 struct c_declarator
*declarator
;
3364 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3367 struct c_expr dimen
;
3368 dimen
.value
= NULL_TREE
;
3369 dimen
.original_code
= ERROR_MARK
;
3370 dimen
.original_type
= NULL_TREE
;
3371 c_parser_consume_token (parser
);
3372 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3373 false, false, cla_prefer_id
);
3374 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3376 c_parser_consume_token (parser
);
3377 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3378 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3379 false, false, cla_prefer_id
);
3380 if (!quals_attrs
->declspecs_seen_p
)
3382 /* If "static" is present, there must be an array dimension.
3383 Otherwise, there may be a dimension, "*", or no
3388 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3392 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3394 dimen
.value
= NULL_TREE
;
3397 else if (flag_cilkplus
3398 && c_parser_next_token_is (parser
, CPP_COLON
))
3400 dimen
.value
= error_mark_node
;
3402 error_at (c_parser_peek_token (parser
)->location
,
3403 "array notations cannot be used in declaration");
3404 c_parser_consume_token (parser
);
3406 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3408 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3410 dimen
.value
= NULL_TREE
;
3412 c_parser_consume_token (parser
);
3417 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3423 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3426 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3427 c_parser_consume_token (parser
);
3428 else if (flag_cilkplus
3429 && c_parser_next_token_is (parser
, CPP_COLON
))
3431 error_at (c_parser_peek_token (parser
)->location
,
3432 "array notations cannot be used in declaration");
3433 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3438 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3443 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3444 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3445 static_seen
, star_seen
);
3446 if (declarator
== NULL
)
3448 inner
= set_array_declarator_inner (declarator
, inner
);
3449 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3451 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3454 struct c_arg_info
*args
;
3455 c_parser_consume_token (parser
);
3456 attrs
= c_parser_attributes (parser
);
3457 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3462 inner
= build_function_declarator (args
, inner
);
3463 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3469 /* Parse a parameter list or identifier list, including the closing
3470 parenthesis but not the opening one. ATTRS are the attributes at
3471 the start of the list. ID_LIST_OK is true if an identifier list is
3472 acceptable; such a list must not have attributes at the start. */
3474 static struct c_arg_info
*
3475 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3478 declare_parm_level ();
3479 /* If the list starts with an identifier, it is an identifier list.
3480 Otherwise, it is either a prototype list or an empty list. */
3483 && c_parser_next_token_is (parser
, CPP_NAME
)
3484 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3486 /* Look ahead to detect typos in type names. */
3487 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3488 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3489 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3490 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3492 tree list
= NULL_TREE
, *nextp
= &list
;
3493 while (c_parser_next_token_is (parser
, CPP_NAME
)
3494 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3496 *nextp
= build_tree_list (NULL_TREE
,
3497 c_parser_peek_token (parser
)->value
);
3498 nextp
= & TREE_CHAIN (*nextp
);
3499 c_parser_consume_token (parser
);
3500 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3502 c_parser_consume_token (parser
);
3503 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3505 c_parser_error (parser
, "expected identifier");
3509 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3511 struct c_arg_info
*ret
= build_arg_info ();
3513 c_parser_consume_token (parser
);
3519 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3527 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3534 /* Parse a parameter list (possibly empty), including the closing
3535 parenthesis but not the opening one. ATTRS are the attributes at
3536 the start of the list. EXPR is NULL or an expression that needs to
3537 be evaluated for the side effects of array size expressions in the
3540 static struct c_arg_info
*
3541 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3543 bool bad_parm
= false;
3545 /* ??? Following the old parser, forward parameter declarations may
3546 use abstract declarators, and if no real parameter declarations
3547 follow the forward declarations then this is not diagnosed. Also
3548 note as above that attributes are ignored as the only contents of
3549 the parentheses, or as the only contents after forward
3551 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3553 struct c_arg_info
*ret
= build_arg_info ();
3554 c_parser_consume_token (parser
);
3557 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3559 struct c_arg_info
*ret
= build_arg_info ();
3561 if (flag_allow_parameterless_variadic_functions
)
3563 /* F (...) is allowed. */
3564 ret
->types
= NULL_TREE
;
3568 /* Suppress -Wold-style-definition for this case. */
3569 ret
->types
= error_mark_node
;
3570 error_at (c_parser_peek_token (parser
)->location
,
3571 "ISO C requires a named argument before %<...%>");
3573 c_parser_consume_token (parser
);
3574 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3576 c_parser_consume_token (parser
);
3581 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3586 /* Nonempty list of parameters, either terminated with semicolon
3587 (forward declarations; recurse) or with close parenthesis (normal
3588 function) or with ", ... )" (variadic function). */
3591 /* Parse a parameter. */
3592 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3597 push_parm_decl (parm
, &expr
);
3598 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3601 c_parser_consume_token (parser
);
3602 mark_forward_parm_decls ();
3603 new_attrs
= c_parser_attributes (parser
);
3604 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3606 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3608 c_parser_consume_token (parser
);
3612 return get_parm_info (false, expr
);
3614 if (!c_parser_require (parser
, CPP_COMMA
,
3615 "expected %<;%>, %<,%> or %<)%>"))
3617 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3620 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3622 c_parser_consume_token (parser
);
3623 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3625 c_parser_consume_token (parser
);
3629 return get_parm_info (true, expr
);
3633 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3641 /* Parse a parameter declaration. ATTRS are the attributes at the
3642 start of the declaration if it is the first parameter. */
3644 static struct c_parm
*
3645 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3647 struct c_declspecs
*specs
;
3648 struct c_declarator
*declarator
;
3650 tree postfix_attrs
= NULL_TREE
;
3653 /* Accept #pragmas between parameter declarations. */
3654 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3655 c_parser_pragma (parser
, pragma_param
);
3657 if (!c_parser_next_token_starts_declspecs (parser
))
3659 c_token
*token
= c_parser_peek_token (parser
);
3662 c_parser_set_source_position_from_token (token
);
3663 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3665 error_at (token
->location
, "unknown type name %qE", token
->value
);
3666 parser
->error
= true;
3668 /* ??? In some Objective-C cases '...' isn't applicable so there
3669 should be a different message. */
3671 c_parser_error (parser
,
3672 "expected declaration specifiers or %<...%>");
3673 c_parser_skip_to_end_of_parameter (parser
);
3676 specs
= build_null_declspecs ();
3679 declspecs_add_attrs (input_location
, specs
, attrs
);
3682 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3683 cla_nonabstract_decl
);
3684 finish_declspecs (specs
);
3685 pending_xref_error ();
3686 prefix_attrs
= specs
->attrs
;
3687 specs
->attrs
= NULL_TREE
;
3688 declarator
= c_parser_declarator (parser
,
3689 specs
->typespec_kind
!= ctsk_none
,
3690 C_DTR_PARM
, &dummy
);
3691 if (declarator
== NULL
)
3693 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3696 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3697 postfix_attrs
= c_parser_attributes (parser
);
3698 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3702 /* Parse a string literal in an asm expression. It should not be
3703 translated, and wide string literals are an error although
3704 permitted by the syntax. This is a GNU extension.
3709 ??? At present, following the old parser, the caller needs to have
3710 set lex_untranslated_string to 1. It would be better to follow the
3711 C++ parser rather than using this kludge. */
3714 c_parser_asm_string_literal (c_parser
*parser
)
3717 int save_flag
= warn_overlength_strings
;
3718 warn_overlength_strings
= 0;
3719 if (c_parser_next_token_is (parser
, CPP_STRING
))
3721 str
= c_parser_peek_token (parser
)->value
;
3722 c_parser_consume_token (parser
);
3724 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3726 error_at (c_parser_peek_token (parser
)->location
,
3727 "wide string literal in %<asm%>");
3728 str
= build_string (1, "");
3729 c_parser_consume_token (parser
);
3733 c_parser_error (parser
, "expected string literal");
3736 warn_overlength_strings
= save_flag
;
3740 /* Parse a simple asm expression. This is used in restricted
3741 contexts, where a full expression with inputs and outputs does not
3742 make sense. This is a GNU extension.
3745 asm ( asm-string-literal )
3749 c_parser_simple_asm_expr (c_parser
*parser
)
3752 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3753 /* ??? Follow the C++ parser rather than using the
3754 lex_untranslated_string kludge. */
3755 parser
->lex_untranslated_string
= true;
3756 c_parser_consume_token (parser
);
3757 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3759 parser
->lex_untranslated_string
= false;
3762 str
= c_parser_asm_string_literal (parser
);
3763 parser
->lex_untranslated_string
= false;
3764 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3766 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3773 c_parser_attribute_any_word (c_parser
*parser
)
3775 tree attr_name
= NULL_TREE
;
3777 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3779 /* ??? See comment above about what keywords are accepted here. */
3781 switch (c_parser_peek_token (parser
)->keyword
)
3811 case RID_TRANSACTION_ATOMIC
:
3812 case RID_TRANSACTION_CANCEL
:
3828 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3829 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3831 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3832 attr_name
= c_parser_peek_token (parser
)->value
;
3837 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3838 "__vector" or "__vector__." */
3841 is_cilkplus_vector_p (tree name
)
3843 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3848 #define CILK_SIMD_FN_CLAUSE_MASK \
3849 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3850 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3851 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3852 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3853 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3855 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3856 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3857 pushed into the token list.
3860 vector (<vector attributes>). */
3863 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3865 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3867 int paren_scope
= 0;
3868 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3869 /* Consume the "vector" token. */
3870 c_parser_consume_token (parser
);
3872 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3874 c_parser_consume_token (parser
);
3877 while (paren_scope
> 0)
3879 c_token
*token
= c_parser_peek_token (parser
);
3880 if (token
->type
== CPP_OPEN_PAREN
)
3882 else if (token
->type
== CPP_CLOSE_PAREN
)
3884 /* Do not push the last ')' since we are not pushing the '('. */
3885 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3886 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3887 c_parser_consume_token (parser
);
3890 /* Since we are converting an attribute to a pragma, we need to end the
3891 attribute with PRAGMA_EOL. */
3893 memset (&eol_token
, 0, sizeof (eol_token
));
3894 eol_token
.type
= CPP_PRAGMA_EOL
;
3895 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3898 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3901 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3903 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3905 /* c_parser_attributes is called in several places, so if these EOF
3906 tokens are already inserted, then don't do them again. */
3907 if (last_token
.type
== CPP_EOF
)
3910 /* Two CPP_EOF token are added as a safety net since the normal C
3911 front-end has two token look-ahead. */
3913 eof_token
.type
= CPP_EOF
;
3914 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3915 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3918 /* Parse (possibly empty) attributes. This is a GNU extension.
3922 attributes attribute
3925 __attribute__ ( ( attribute-list ) )
3929 attribute_list , attrib
3934 any-word ( identifier )
3935 any-word ( identifier , nonempty-expr-list )
3936 any-word ( expr-list )
3938 where the "identifier" must not be declared as a type, and
3939 "any-word" may be any identifier (including one declared as a
3940 type), a reserved word storage class specifier, type specifier or
3941 type qualifier. ??? This still leaves out most reserved keywords
3942 (following the old parser), shouldn't we include them, and why not
3943 allow identifiers declared as types to start the arguments? */
3946 c_parser_attributes (c_parser
*parser
)
3948 tree attrs
= NULL_TREE
;
3949 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3951 /* ??? Follow the C++ parser rather than using the
3952 lex_untranslated_string kludge. */
3953 parser
->lex_untranslated_string
= true;
3954 c_parser_consume_token (parser
);
3955 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3957 parser
->lex_untranslated_string
= false;
3960 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3962 parser
->lex_untranslated_string
= false;
3963 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3966 /* Parse the attribute list. */
3967 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3968 || c_parser_next_token_is (parser
, CPP_NAME
)
3969 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3971 tree attr
, attr_name
, attr_args
;
3972 vec
<tree
, va_gc
> *expr_list
;
3973 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3975 c_parser_consume_token (parser
);
3979 attr_name
= c_parser_attribute_any_word (parser
);
3980 if (attr_name
== NULL
)
3982 if (is_cilkplus_vector_p (attr_name
))
3984 c_token
*v_token
= c_parser_peek_token (parser
);
3985 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3988 c_parser_consume_token (parser
);
3989 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3991 attr
= build_tree_list (attr_name
, NULL_TREE
);
3992 attrs
= chainon (attrs
, attr
);
3995 c_parser_consume_token (parser
);
3996 /* Parse the attribute contents. If they start with an
3997 identifier which is followed by a comma or close
3998 parenthesis, then the arguments start with that
3999 identifier; otherwise they are an expression list.
4000 In objective-c the identifier may be a classname. */
4001 if (c_parser_next_token_is (parser
, CPP_NAME
)
4002 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4003 || (c_dialect_objc ()
4004 && c_parser_peek_token (parser
)->id_kind
4006 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4007 || (c_parser_peek_2nd_token (parser
)->type
4008 == CPP_CLOSE_PAREN
))
4009 && (attribute_takes_identifier_p (attr_name
)
4010 || (c_dialect_objc ()
4011 && c_parser_peek_token (parser
)->id_kind
4012 == C_ID_CLASSNAME
)))
4014 tree arg1
= c_parser_peek_token (parser
)->value
;
4015 c_parser_consume_token (parser
);
4016 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4017 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4021 c_parser_consume_token (parser
);
4022 expr_list
= c_parser_expr_list (parser
, false, true,
4023 NULL
, NULL
, NULL
, NULL
);
4024 tree_list
= build_tree_list_vec (expr_list
);
4025 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4026 release_tree_vector (expr_list
);
4031 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4032 attr_args
= NULL_TREE
;
4035 expr_list
= c_parser_expr_list (parser
, false, true,
4036 NULL
, NULL
, NULL
, NULL
);
4037 attr_args
= build_tree_list_vec (expr_list
);
4038 release_tree_vector (expr_list
);
4041 attr
= build_tree_list (attr_name
, attr_args
);
4042 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4043 c_parser_consume_token (parser
);
4046 parser
->lex_untranslated_string
= false;
4047 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4051 attrs
= chainon (attrs
, attr
);
4053 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4054 c_parser_consume_token (parser
);
4057 parser
->lex_untranslated_string
= false;
4058 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4062 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4063 c_parser_consume_token (parser
);
4066 parser
->lex_untranslated_string
= false;
4067 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4071 parser
->lex_untranslated_string
= false;
4074 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4075 c_finish_cilk_simd_fn_tokens (parser
);
4079 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4082 specifier-qualifier-list abstract-declarator[opt]
4085 static struct c_type_name
*
4086 c_parser_type_name (c_parser
*parser
)
4088 struct c_declspecs
*specs
= build_null_declspecs ();
4089 struct c_declarator
*declarator
;
4090 struct c_type_name
*ret
;
4092 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4094 if (!specs
->declspecs_seen_p
)
4096 c_parser_error (parser
, "expected specifier-qualifier-list");
4099 if (specs
->type
!= error_mark_node
)
4101 pending_xref_error ();
4102 finish_declspecs (specs
);
4104 declarator
= c_parser_declarator (parser
,
4105 specs
->typespec_kind
!= ctsk_none
,
4106 C_DTR_ABSTRACT
, &dummy
);
4107 if (declarator
== NULL
)
4109 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4111 ret
->declarator
= declarator
;
4115 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4118 assignment-expression
4119 { initializer-list }
4120 { initializer-list , }
4123 designation[opt] initializer
4124 initializer-list , designation[opt] initializer
4131 designator-list designator
4138 [ constant-expression ]
4150 [ constant-expression ... constant-expression ]
4152 Any expression without commas is accepted in the syntax for the
4153 constant-expressions, with non-constant expressions rejected later.
4155 This function is only used for top-level initializers; for nested
4156 ones, see c_parser_initval. */
4158 static struct c_expr
4159 c_parser_initializer (c_parser
*parser
)
4161 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4162 return c_parser_braced_init (parser
, NULL_TREE
, false);
4166 location_t loc
= c_parser_peek_token (parser
)->location
;
4167 ret
= c_parser_expr_no_commas (parser
, NULL
);
4168 if (TREE_CODE (ret
.value
) != STRING_CST
4169 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4170 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4175 /* Parse a braced initializer list. TYPE is the type specified for a
4176 compound literal, and NULL_TREE for other initializers and for
4177 nested braced lists. NESTED_P is true for nested braced lists,
4178 false for the list of a compound literal or the list that is the
4179 top-level initializer in a declaration. */
4181 static struct c_expr
4182 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4185 struct obstack braced_init_obstack
;
4186 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4187 gcc_obstack_init (&braced_init_obstack
);
4188 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4189 c_parser_consume_token (parser
);
4191 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4193 really_start_incremental_init (type
);
4194 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4196 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4200 /* Parse a non-empty initializer list, possibly with a trailing
4204 c_parser_initelt (parser
, &braced_init_obstack
);
4207 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4208 c_parser_consume_token (parser
);
4211 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4215 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4217 ret
.value
= error_mark_node
;
4218 ret
.original_code
= ERROR_MARK
;
4219 ret
.original_type
= NULL
;
4220 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4221 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4222 obstack_free (&braced_init_obstack
, NULL
);
4225 c_parser_consume_token (parser
);
4226 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4227 obstack_free (&braced_init_obstack
, NULL
);
4231 /* Parse a nested initializer, including designators. */
4234 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4236 /* Parse any designator or designator list. A single array
4237 designator may have the subsequent "=" omitted in GNU C, but a
4238 longer list or a structure member designator may not. */
4239 if (c_parser_next_token_is (parser
, CPP_NAME
)
4240 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4242 /* Old-style structure member designator. */
4243 set_init_label (c_parser_peek_token (parser
)->location
,
4244 c_parser_peek_token (parser
)->value
,
4245 braced_init_obstack
);
4246 /* Use the colon as the error location. */
4247 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4248 "obsolete use of designated initializer with %<:%>");
4249 c_parser_consume_token (parser
);
4250 c_parser_consume_token (parser
);
4254 /* des_seen is 0 if there have been no designators, 1 if there
4255 has been a single array designator and 2 otherwise. */
4257 /* Location of a designator. */
4258 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4259 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4260 || c_parser_next_token_is (parser
, CPP_DOT
))
4262 int des_prev
= des_seen
;
4264 des_loc
= c_parser_peek_token (parser
)->location
;
4267 if (c_parser_next_token_is (parser
, CPP_DOT
))
4270 c_parser_consume_token (parser
);
4271 if (c_parser_next_token_is (parser
, CPP_NAME
))
4273 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4274 braced_init_obstack
);
4275 c_parser_consume_token (parser
);
4280 init
.value
= error_mark_node
;
4281 init
.original_code
= ERROR_MARK
;
4282 init
.original_type
= NULL
;
4283 c_parser_error (parser
, "expected identifier");
4284 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4285 process_init_element (input_location
, init
, false,
4286 braced_init_obstack
);
4293 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4294 location_t array_index_loc
= UNKNOWN_LOCATION
;
4295 /* ??? Following the old parser, [ objc-receiver
4296 objc-message-args ] is accepted as an initializer,
4297 being distinguished from a designator by what follows
4298 the first assignment expression inside the square
4299 brackets, but after a first array designator a
4300 subsequent square bracket is for Objective-C taken to
4301 start an expression, using the obsolete form of
4302 designated initializer without '=', rather than
4303 possibly being a second level of designation: in LALR
4304 terms, the '[' is shifted rather than reducing
4305 designator to designator-list. */
4306 if (des_prev
== 1 && c_dialect_objc ())
4308 des_seen
= des_prev
;
4311 if (des_prev
== 0 && c_dialect_objc ())
4313 /* This might be an array designator or an
4314 Objective-C message expression. If the former,
4315 continue parsing here; if the latter, parse the
4316 remainder of the initializer given the starting
4317 primary-expression. ??? It might make sense to
4318 distinguish when des_prev == 1 as well; see
4319 previous comment. */
4321 struct c_expr mexpr
;
4322 c_parser_consume_token (parser
);
4323 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4324 && ((c_parser_peek_token (parser
)->id_kind
4326 || (c_parser_peek_token (parser
)->id_kind
4327 == C_ID_CLASSNAME
)))
4329 /* Type name receiver. */
4330 tree id
= c_parser_peek_token (parser
)->value
;
4331 c_parser_consume_token (parser
);
4332 rec
= objc_get_class_reference (id
);
4333 goto parse_message_args
;
4335 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4336 mark_exp_read (first
);
4337 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4338 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4339 goto array_desig_after_first
;
4340 /* Expression receiver. So far only one part
4341 without commas has been parsed; there might be
4342 more of the expression. */
4344 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4347 location_t comma_loc
, exp_loc
;
4348 comma_loc
= c_parser_peek_token (parser
)->location
;
4349 c_parser_consume_token (parser
);
4350 exp_loc
= c_parser_peek_token (parser
)->location
;
4351 next
= c_parser_expr_no_commas (parser
, NULL
);
4352 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4354 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4357 /* Now parse the objc-message-args. */
4358 args
= c_parser_objc_message_args (parser
);
4359 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4362 = objc_build_message_expr (rec
, args
);
4363 mexpr
.original_code
= ERROR_MARK
;
4364 mexpr
.original_type
= NULL
;
4365 /* Now parse and process the remainder of the
4366 initializer, starting with this message
4367 expression as a primary-expression. */
4368 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4371 c_parser_consume_token (parser
);
4372 array_index_loc
= c_parser_peek_token (parser
)->location
;
4373 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4374 mark_exp_read (first
);
4375 array_desig_after_first
:
4376 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4378 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4379 c_parser_consume_token (parser
);
4380 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4381 mark_exp_read (second
);
4385 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4387 c_parser_consume_token (parser
);
4388 set_init_index (array_index_loc
, first
, second
,
4389 braced_init_obstack
);
4391 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4392 "ISO C forbids specifying range of elements to initialize");
4395 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4401 if (c_parser_next_token_is (parser
, CPP_EQ
))
4403 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4404 "ISO C90 forbids specifying subobject "
4406 c_parser_consume_token (parser
);
4411 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4412 "obsolete use of designated initializer without %<=%>");
4416 init
.value
= error_mark_node
;
4417 init
.original_code
= ERROR_MARK
;
4418 init
.original_type
= NULL
;
4419 c_parser_error (parser
, "expected %<=%>");
4420 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4421 process_init_element (input_location
, init
, false,
4422 braced_init_obstack
);
4428 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4431 /* Parse a nested initializer; as c_parser_initializer but parses
4432 initializers within braced lists, after any designators have been
4433 applied. If AFTER is not NULL then it is an Objective-C message
4434 expression which is the primary-expression starting the
4438 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4439 struct obstack
* braced_init_obstack
)
4442 gcc_assert (!after
|| c_dialect_objc ());
4443 location_t loc
= c_parser_peek_token (parser
)->location
;
4445 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4446 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4449 init
= c_parser_expr_no_commas (parser
, after
);
4450 if (init
.value
!= NULL_TREE
4451 && TREE_CODE (init
.value
) != STRING_CST
4452 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4453 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4455 process_init_element (loc
, init
, false, braced_init_obstack
);
4458 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4462 { block-item-list[opt] }
4463 { label-declarations block-item-list }
4467 block-item-list block-item
4479 { label-declarations block-item-list }
4482 __extension__ nested-declaration
4483 nested-function-definition
4487 label-declarations label-declaration
4490 __label__ identifier-list ;
4492 Allowing the mixing of declarations and code is new in C99. The
4493 GNU syntax also permits (not shown above) labels at the end of
4494 compound statements, which yield an error. We don't allow labels
4495 on declarations; this might seem like a natural extension, but
4496 there would be a conflict between attributes on the label and
4497 prefix attributes on the declaration. ??? The syntax follows the
4498 old parser in requiring something after label declarations.
4499 Although they are erroneous if the labels declared aren't defined,
4500 is it useful for the syntax to be this way?
4521 cancellation-point-directive */
4524 c_parser_compound_statement (c_parser
*parser
)
4527 location_t brace_loc
;
4528 brace_loc
= c_parser_peek_token (parser
)->location
;
4529 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4531 /* Ensure a scope is entered and left anyway to avoid confusion
4532 if we have just prepared to enter a function body. */
4533 stmt
= c_begin_compound_stmt (true);
4534 c_end_compound_stmt (brace_loc
, stmt
, true);
4535 return error_mark_node
;
4537 stmt
= c_begin_compound_stmt (true);
4538 c_parser_compound_statement_nostart (parser
);
4540 /* If the compound stmt contains array notations, then we expand them. */
4541 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4542 stmt
= expand_array_notation_exprs (stmt
);
4543 return c_end_compound_stmt (brace_loc
, stmt
, true);
4546 /* Parse a compound statement except for the opening brace. This is
4547 used for parsing both compound statements and statement expressions
4548 (which follow different paths to handling the opening). */
4551 c_parser_compound_statement_nostart (c_parser
*parser
)
4553 bool last_stmt
= false;
4554 bool last_label
= false;
4555 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4556 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4557 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4559 c_parser_consume_token (parser
);
4562 mark_valid_location_for_stdc_pragma (true);
4563 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4565 /* Read zero or more forward-declarations for labels that nested
4566 functions can jump to. */
4567 mark_valid_location_for_stdc_pragma (false);
4568 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4570 label_loc
= c_parser_peek_token (parser
)->location
;
4571 c_parser_consume_token (parser
);
4572 /* Any identifiers, including those declared as type names,
4577 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4579 c_parser_error (parser
, "expected identifier");
4583 = declare_label (c_parser_peek_token (parser
)->value
);
4584 C_DECLARED_LABEL_FLAG (label
) = 1;
4585 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4586 c_parser_consume_token (parser
);
4587 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4588 c_parser_consume_token (parser
);
4592 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4594 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4596 /* We must now have at least one statement, label or declaration. */
4597 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4599 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4600 c_parser_error (parser
, "expected declaration or statement");
4601 c_parser_consume_token (parser
);
4604 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4606 location_t loc
= c_parser_peek_token (parser
)->location
;
4607 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4608 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4609 || (c_parser_next_token_is (parser
, CPP_NAME
)
4610 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4612 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4613 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4615 label_loc
= c_parser_peek_token (parser
)->location
;
4618 mark_valid_location_for_stdc_pragma (false);
4619 c_parser_label (parser
);
4621 else if (!last_label
4622 && c_parser_next_tokens_start_declaration (parser
))
4625 mark_valid_location_for_stdc_pragma (false);
4626 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4629 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4630 "ISO C90 forbids mixed declarations and code");
4633 else if (!last_label
4634 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4636 /* __extension__ can start a declaration, but is also an
4637 unary operator that can start an expression. Consume all
4638 but the last of a possible series of __extension__ to
4640 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4641 && (c_parser_peek_2nd_token (parser
)->keyword
4643 c_parser_consume_token (parser
);
4644 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4647 ext
= disable_extension_diagnostics ();
4648 c_parser_consume_token (parser
);
4650 mark_valid_location_for_stdc_pragma (false);
4651 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4653 /* Following the old parser, __extension__ does not
4654 disable this diagnostic. */
4655 restore_extension_diagnostics (ext
);
4657 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4658 "ISO C90 forbids mixed declarations and code");
4664 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4666 /* External pragmas, and some omp pragmas, are not associated
4667 with regular c code, and so are not to be considered statements
4668 syntactically. This ensures that the user doesn't put them
4669 places that would turn into syntax errors if the directive
4671 if (c_parser_pragma (parser
, pragma_compound
))
4672 last_label
= false, last_stmt
= true;
4674 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4676 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4677 c_parser_error (parser
, "expected declaration or statement");
4680 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4682 if (parser
->in_if_block
)
4684 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4685 error_at (loc
, """expected %<}%> before %<else%>");
4690 error_at (loc
, "%<else%> without a previous %<if%>");
4691 c_parser_consume_token (parser
);
4700 mark_valid_location_for_stdc_pragma (false);
4701 c_parser_statement_after_labels (parser
);
4704 parser
->error
= false;
4707 error_at (label_loc
, "label at end of compound statement");
4708 c_parser_consume_token (parser
);
4709 /* Restore the value we started with. */
4710 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4713 /* Parse all consecutive labels. */
4716 c_parser_all_labels (c_parser
*parser
)
4718 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4719 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4720 || (c_parser_next_token_is (parser
, CPP_NAME
)
4721 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4722 c_parser_label (parser
);
4725 /* Parse a label (C90 6.6.1, C99 6.8.1).
4728 identifier : attributes[opt]
4729 case constant-expression :
4735 case constant-expression ... constant-expression :
4737 The use of attributes on labels is a GNU extension. The syntax in
4738 GNU C accepts any expressions without commas, non-constant
4739 expressions being rejected later. */
4742 c_parser_label (c_parser
*parser
)
4744 location_t loc1
= c_parser_peek_token (parser
)->location
;
4745 tree label
= NULL_TREE
;
4746 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4749 c_parser_consume_token (parser
);
4750 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4751 if (c_parser_next_token_is (parser
, CPP_COLON
))
4753 c_parser_consume_token (parser
);
4754 label
= do_case (loc1
, exp1
, NULL_TREE
);
4756 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4758 c_parser_consume_token (parser
);
4759 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4760 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4761 label
= do_case (loc1
, exp1
, exp2
);
4764 c_parser_error (parser
, "expected %<:%> or %<...%>");
4766 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4768 c_parser_consume_token (parser
);
4769 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4770 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4774 tree name
= c_parser_peek_token (parser
)->value
;
4777 location_t loc2
= c_parser_peek_token (parser
)->location
;
4778 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4779 c_parser_consume_token (parser
);
4780 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4781 c_parser_consume_token (parser
);
4782 attrs
= c_parser_attributes (parser
);
4783 tlab
= define_label (loc2
, name
);
4786 decl_attributes (&tlab
, attrs
, 0);
4787 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4792 if (c_parser_next_tokens_start_declaration (parser
))
4794 error_at (c_parser_peek_token (parser
)->location
,
4795 "a label can only be part of a statement and "
4796 "a declaration is not a statement");
4797 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4798 /*static_assert_ok*/ true,
4799 /*empty_ok*/ true, /*nested*/ true,
4800 /*start_attr_ok*/ true, NULL
,
4806 /* Parse a statement (C90 6.6, C99 6.8).
4811 expression-statement
4819 expression-statement:
4822 selection-statement:
4826 iteration-statement:
4835 return expression[opt] ;
4848 objc-throw-statement
4849 objc-try-catch-statement
4850 objc-synchronized-statement
4852 objc-throw-statement:
4868 parallel-directive structured-block
4871 kernels-directive structured-block
4874 data-directive structured-block
4877 loop-directive structured-block
4891 parallel-for-construct
4892 parallel-for-simd-construct
4893 parallel-sections-construct
4900 parallel-directive structured-block
4903 for-directive iteration-statement
4906 simd-directive iteration-statements
4909 for-simd-directive iteration-statements
4912 sections-directive section-scope
4915 single-directive structured-block
4917 parallel-for-construct:
4918 parallel-for-directive iteration-statement
4920 parallel-for-simd-construct:
4921 parallel-for-simd-directive iteration-statement
4923 parallel-sections-construct:
4924 parallel-sections-directive section-scope
4927 master-directive structured-block
4930 critical-directive structured-block
4933 atomic-directive expression-statement
4936 ordered-directive structured-block
4938 Transactional Memory:
4941 transaction-statement
4942 transaction-cancel-statement
4946 c_parser_statement (c_parser
*parser
)
4948 c_parser_all_labels (parser
);
4949 c_parser_statement_after_labels (parser
);
4952 /* Parse a statement, other than a labeled statement. */
4955 c_parser_statement_after_labels (c_parser
*parser
)
4957 location_t loc
= c_parser_peek_token (parser
)->location
;
4958 tree stmt
= NULL_TREE
;
4959 bool in_if_block
= parser
->in_if_block
;
4960 parser
->in_if_block
= false;
4961 switch (c_parser_peek_token (parser
)->type
)
4963 case CPP_OPEN_BRACE
:
4964 add_stmt (c_parser_compound_statement (parser
));
4967 switch (c_parser_peek_token (parser
)->keyword
)
4970 c_parser_if_statement (parser
);
4973 c_parser_switch_statement (parser
);
4976 c_parser_while_statement (parser
, false);
4979 c_parser_do_statement (parser
, false);
4982 c_parser_for_statement (parser
, false);
4987 error_at (c_parser_peek_token (parser
)->location
,
4988 "-fcilkplus must be enabled to use %<_Cilk_for%>");
4989 c_parser_skip_to_end_of_block_or_statement (parser
);
4992 c_parser_cilk_for (parser
, integer_zero_node
);
4995 c_parser_consume_token (parser
);
4996 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4998 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5000 add_stmt (build_cilk_sync ());
5003 c_parser_consume_token (parser
);
5004 if (c_parser_next_token_is (parser
, CPP_NAME
))
5006 stmt
= c_finish_goto_label (loc
,
5007 c_parser_peek_token (parser
)->value
);
5008 c_parser_consume_token (parser
);
5010 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5014 c_parser_consume_token (parser
);
5015 val
= c_parser_expression (parser
);
5016 if (check_no_cilk (val
.value
,
5017 "Cilk array notation cannot be used as a computed goto expression",
5018 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5020 val
.value
= error_mark_node
;
5021 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5022 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5025 c_parser_error (parser
, "expected identifier or %<*%>");
5026 goto expect_semicolon
;
5028 c_parser_consume_token (parser
);
5029 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5030 goto expect_semicolon
;
5032 c_parser_consume_token (parser
);
5033 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5034 goto expect_semicolon
;
5036 c_parser_consume_token (parser
);
5037 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5039 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5040 c_parser_consume_token (parser
);
5044 location_t xloc
= c_parser_peek_token (parser
)->location
;
5045 struct c_expr expr
= c_parser_expression_conv (parser
);
5046 mark_exp_read (expr
.value
);
5047 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
5048 goto expect_semicolon
;
5052 stmt
= c_parser_asm_statement (parser
);
5054 case RID_TRANSACTION_ATOMIC
:
5055 case RID_TRANSACTION_RELAXED
:
5056 stmt
= c_parser_transaction (parser
,
5057 c_parser_peek_token (parser
)->keyword
);
5059 case RID_TRANSACTION_CANCEL
:
5060 stmt
= c_parser_transaction_cancel (parser
);
5061 goto expect_semicolon
;
5063 gcc_assert (c_dialect_objc ());
5064 c_parser_consume_token (parser
);
5065 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5067 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5068 c_parser_consume_token (parser
);
5072 struct c_expr expr
= c_parser_expression (parser
);
5073 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5074 if (check_no_cilk (expr
.value
,
5075 "Cilk array notation cannot be used for a throw expression",
5076 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5077 expr
.value
= error_mark_node
;
5080 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5081 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5083 goto expect_semicolon
;
5087 gcc_assert (c_dialect_objc ());
5088 c_parser_objc_try_catch_finally_statement (parser
);
5090 case RID_AT_SYNCHRONIZED
:
5091 gcc_assert (c_dialect_objc ());
5092 c_parser_objc_synchronized_statement (parser
);
5099 c_parser_consume_token (parser
);
5101 case CPP_CLOSE_PAREN
:
5102 case CPP_CLOSE_SQUARE
:
5103 /* Avoid infinite loop in error recovery:
5104 c_parser_skip_until_found stops at a closing nesting
5105 delimiter without consuming it, but here we need to consume
5106 it to proceed further. */
5107 c_parser_error (parser
, "expected statement");
5108 c_parser_consume_token (parser
);
5111 c_parser_pragma (parser
, pragma_stmt
);
5115 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5117 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5120 /* Two cases cannot and do not have line numbers associated: If stmt
5121 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5122 cannot hold line numbers. But that's OK because the statement
5123 will either be changed to a MODIFY_EXPR during gimplification of
5124 the statement expr, or discarded. If stmt was compound, but
5125 without new variables, we will have skipped the creation of a
5126 BIND and will have a bare STATEMENT_LIST. But that's OK because
5127 (recursively) all of the component statements should already have
5128 line numbers assigned. ??? Can we discard no-op statements
5130 if (CAN_HAVE_LOCATION_P (stmt
)
5131 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5132 SET_EXPR_LOCATION (stmt
, loc
);
5134 parser
->in_if_block
= in_if_block
;
5137 /* Parse the condition from an if, do, while or for statements. */
5140 c_parser_condition (c_parser
*parser
)
5142 location_t loc
= c_parser_peek_token (parser
)->location
;
5144 cond
= c_parser_expression_conv (parser
).value
;
5145 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5146 cond
= c_fully_fold (cond
, false, NULL
);
5147 if (warn_sequence_point
)
5148 verify_sequence_points (cond
);
5152 /* Parse a parenthesized condition from an if, do or while statement.
5158 c_parser_paren_condition (c_parser
*parser
)
5161 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5162 return error_mark_node
;
5163 cond
= c_parser_condition (parser
);
5164 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5168 /* Parse a statement which is a block in C99. */
5171 c_parser_c99_block_statement (c_parser
*parser
)
5173 tree block
= c_begin_compound_stmt (flag_isoc99
);
5174 location_t loc
= c_parser_peek_token (parser
)->location
;
5175 c_parser_statement (parser
);
5176 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5179 /* Parse the body of an if statement. This is just parsing a
5180 statement but (a) it is a block in C99, (b) we track whether the
5181 body is an if statement for the sake of -Wparentheses warnings, (c)
5182 we handle an empty body specially for the sake of -Wempty-body
5183 warnings, and (d) we call parser_compound_statement directly
5184 because c_parser_statement_after_labels resets
5185 parser->in_if_block. */
5188 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5190 tree block
= c_begin_compound_stmt (flag_isoc99
);
5191 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5192 c_parser_all_labels (parser
);
5193 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5194 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5196 location_t loc
= c_parser_peek_token (parser
)->location
;
5197 add_stmt (build_empty_stmt (loc
));
5198 c_parser_consume_token (parser
);
5199 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5200 warning_at (loc
, OPT_Wempty_body
,
5201 "suggest braces around empty body in an %<if%> statement");
5203 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5204 add_stmt (c_parser_compound_statement (parser
));
5206 c_parser_statement_after_labels (parser
);
5207 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5210 /* Parse the else body of an if statement. This is just parsing a
5211 statement but (a) it is a block in C99, (b) we handle an empty body
5212 specially for the sake of -Wempty-body warnings. */
5215 c_parser_else_body (c_parser
*parser
)
5217 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5218 tree block
= c_begin_compound_stmt (flag_isoc99
);
5219 c_parser_all_labels (parser
);
5220 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5222 location_t loc
= c_parser_peek_token (parser
)->location
;
5225 "suggest braces around empty body in an %<else%> statement");
5226 add_stmt (build_empty_stmt (loc
));
5227 c_parser_consume_token (parser
);
5230 c_parser_statement_after_labels (parser
);
5231 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5234 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5237 if ( expression ) statement
5238 if ( expression ) statement else statement
5242 c_parser_if_statement (c_parser
*parser
)
5247 bool first_if
= false;
5248 tree first_body
, second_body
;
5252 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5253 c_parser_consume_token (parser
);
5254 block
= c_begin_compound_stmt (flag_isoc99
);
5255 loc
= c_parser_peek_token (parser
)->location
;
5256 cond
= c_parser_paren_condition (parser
);
5257 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5259 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5260 cond
= error_mark_node
;
5262 in_if_block
= parser
->in_if_block
;
5263 parser
->in_if_block
= true;
5264 first_body
= c_parser_if_body (parser
, &first_if
);
5265 parser
->in_if_block
= in_if_block
;
5266 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5268 c_parser_consume_token (parser
);
5269 second_body
= c_parser_else_body (parser
);
5272 second_body
= NULL_TREE
;
5273 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5274 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5276 /* If the if statement contains array notations, then we expand them. */
5277 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5278 if_stmt
= fix_conditional_array_notations (if_stmt
);
5282 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5285 switch (expression) statement
5289 c_parser_switch_statement (c_parser
*parser
)
5292 tree block
, expr
, body
, save_break
;
5293 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5294 location_t switch_cond_loc
;
5295 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5296 c_parser_consume_token (parser
);
5297 block
= c_begin_compound_stmt (flag_isoc99
);
5298 bool explicit_cast_p
= false;
5299 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5301 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5302 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5303 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5304 explicit_cast_p
= true;
5305 ce
= c_parser_expression (parser
);
5306 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5308 /* ??? expr has no valid location? */
5309 if (check_no_cilk (expr
,
5310 "Cilk array notation cannot be used as a condition for switch statement",
5311 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5313 expr
= error_mark_node
;
5314 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5318 switch_cond_loc
= UNKNOWN_LOCATION
;
5319 expr
= error_mark_node
;
5321 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5322 save_break
= c_break_label
;
5323 c_break_label
= NULL_TREE
;
5324 body
= c_parser_c99_block_statement (parser
);
5325 c_finish_case (body
, ce
.original_type
);
5328 location_t here
= c_parser_peek_token (parser
)->location
;
5329 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5330 SET_EXPR_LOCATION (t
, here
);
5333 c_break_label
= save_break
;
5334 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5337 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5340 while (expression) statement
5344 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5346 tree block
, cond
, body
, save_break
, save_cont
;
5348 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5349 c_parser_consume_token (parser
);
5350 block
= c_begin_compound_stmt (flag_isoc99
);
5351 loc
= c_parser_peek_token (parser
)->location
;
5352 cond
= c_parser_paren_condition (parser
);
5353 if (check_no_cilk (cond
,
5354 "Cilk array notation cannot be used as a condition for while statement",
5355 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5356 cond
= error_mark_node
;
5357 if (ivdep
&& cond
!= error_mark_node
)
5358 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5359 build_int_cst (integer_type_node
,
5360 annot_expr_ivdep_kind
));
5361 save_break
= c_break_label
;
5362 c_break_label
= NULL_TREE
;
5363 save_cont
= c_cont_label
;
5364 c_cont_label
= NULL_TREE
;
5365 body
= c_parser_c99_block_statement (parser
);
5366 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5367 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5368 c_break_label
= save_break
;
5369 c_cont_label
= save_cont
;
5372 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5375 do statement while ( expression ) ;
5379 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5381 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5383 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5384 c_parser_consume_token (parser
);
5385 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5386 warning_at (c_parser_peek_token (parser
)->location
,
5388 "suggest braces around empty body in %<do%> statement");
5389 block
= c_begin_compound_stmt (flag_isoc99
);
5390 loc
= c_parser_peek_token (parser
)->location
;
5391 save_break
= c_break_label
;
5392 c_break_label
= NULL_TREE
;
5393 save_cont
= c_cont_label
;
5394 c_cont_label
= NULL_TREE
;
5395 body
= c_parser_c99_block_statement (parser
);
5396 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5397 new_break
= c_break_label
;
5398 c_break_label
= save_break
;
5399 new_cont
= c_cont_label
;
5400 c_cont_label
= save_cont
;
5401 cond
= c_parser_paren_condition (parser
);
5402 if (check_no_cilk (cond
,
5403 "Cilk array notation cannot be used as a condition for a do-while statement",
5404 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5405 cond
= error_mark_node
;
5406 if (ivdep
&& cond
!= error_mark_node
)
5407 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5408 build_int_cst (integer_type_node
,
5409 annot_expr_ivdep_kind
));
5410 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5411 c_parser_skip_to_end_of_block_or_statement (parser
);
5412 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5413 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5416 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5419 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5420 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5422 The form with a declaration is new in C99.
5424 ??? In accordance with the old parser, the declaration may be a
5425 nested function, which is then rejected in check_for_loop_decls,
5426 but does it make any sense for this to be included in the grammar?
5427 Note in particular that the nested function does not include a
5428 trailing ';', whereas the "declaration" production includes one.
5429 Also, can we reject bad declarations earlier and cheaper than
5430 check_for_loop_decls?
5432 In Objective-C, there are two additional variants:
5435 for ( expression in expresssion ) statement
5436 for ( declaration in expression ) statement
5438 This is inconsistent with C, because the second variant is allowed
5439 even if c99 is not enabled.
5441 The rest of the comment documents these Objective-C foreach-statement.
5443 Here is the canonical example of the first variant:
5444 for (object in array) { do something with object }
5445 we call the first expression ("object") the "object_expression" and
5446 the second expression ("array") the "collection_expression".
5447 object_expression must be an lvalue of type "id" (a generic Objective-C
5448 object) because the loop works by assigning to object_expression the
5449 various objects from the collection_expression. collection_expression
5450 must evaluate to something of type "id" which responds to the method
5451 countByEnumeratingWithState:objects:count:.
5453 The canonical example of the second variant is:
5454 for (id object in array) { do something with object }
5455 which is completely equivalent to
5458 for (object in array) { do something with object }
5460 Note that initizializing 'object' in some way (eg, "for ((object =
5461 xxx) in array) { do something with object }") is possibly
5462 technically valid, but completely pointless as 'object' will be
5463 assigned to something else as soon as the loop starts. We should
5464 most likely reject it (TODO).
5466 The beginning of the Objective-C foreach-statement looks exactly
5467 like the beginning of the for-statement, and we can tell it is a
5468 foreach-statement only because the initial declaration or
5469 expression is terminated by 'in' instead of ';'.
5473 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5475 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5476 /* The following are only used when parsing an ObjC foreach statement. */
5477 tree object_expression
;
5478 /* Silence the bogus uninitialized warning. */
5479 tree collection_expression
= NULL
;
5480 location_t loc
= c_parser_peek_token (parser
)->location
;
5481 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5482 bool is_foreach_statement
= false;
5483 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5484 c_parser_consume_token (parser
);
5485 /* Open a compound statement in Objective-C as well, just in case this is
5486 as foreach expression. */
5487 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5488 cond
= error_mark_node
;
5489 incr
= error_mark_node
;
5490 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5492 /* Parse the initialization declaration or expression. */
5493 object_expression
= error_mark_node
;
5494 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5495 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5497 parser
->objc_could_be_foreach_context
= false;
5498 c_parser_consume_token (parser
);
5499 c_finish_expr_stmt (loc
, NULL_TREE
);
5501 else if (c_parser_next_tokens_start_declaration (parser
))
5503 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5504 &object_expression
, vNULL
);
5505 parser
->objc_could_be_foreach_context
= false;
5507 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5509 c_parser_consume_token (parser
);
5510 is_foreach_statement
= true;
5511 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5512 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5515 check_for_loop_decls (for_loc
, flag_isoc99
);
5517 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5519 /* __extension__ can start a declaration, but is also an
5520 unary operator that can start an expression. Consume all
5521 but the last of a possible series of __extension__ to
5523 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5524 && (c_parser_peek_2nd_token (parser
)->keyword
5526 c_parser_consume_token (parser
);
5527 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5530 ext
= disable_extension_diagnostics ();
5531 c_parser_consume_token (parser
);
5532 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5533 true, &object_expression
, vNULL
);
5534 parser
->objc_could_be_foreach_context
= false;
5536 restore_extension_diagnostics (ext
);
5537 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5539 c_parser_consume_token (parser
);
5540 is_foreach_statement
= true;
5541 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5542 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5545 check_for_loop_decls (for_loc
, flag_isoc99
);
5555 tree init_expression
;
5556 ce
= c_parser_expression (parser
);
5557 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5558 level statement", but it works just fine, so allow it. */
5559 init_expression
= ce
.value
;
5560 parser
->objc_could_be_foreach_context
= false;
5561 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5563 c_parser_consume_token (parser
);
5564 is_foreach_statement
= true;
5565 if (! lvalue_p (init_expression
))
5566 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5567 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5571 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5572 init_expression
= ce
.value
;
5573 c_finish_expr_stmt (loc
, init_expression
);
5574 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5578 /* Parse the loop condition. In the case of a foreach
5579 statement, there is no loop condition. */
5580 gcc_assert (!parser
->objc_could_be_foreach_context
);
5581 if (!is_foreach_statement
)
5583 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5587 c_parser_error (parser
, "missing loop condition in loop with "
5588 "%<GCC ivdep%> pragma");
5589 cond
= error_mark_node
;
5593 c_parser_consume_token (parser
);
5599 cond
= c_parser_condition (parser
);
5600 if (check_no_cilk (cond
,
5601 "Cilk array notation cannot be used in a condition for a for-loop",
5602 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5603 cond
= error_mark_node
;
5604 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5607 if (ivdep
&& cond
!= error_mark_node
)
5608 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5609 build_int_cst (integer_type_node
,
5610 annot_expr_ivdep_kind
));
5612 /* Parse the increment expression (the third expression in a
5613 for-statement). In the case of a foreach-statement, this is
5614 the expression that follows the 'in'. */
5615 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5617 if (is_foreach_statement
)
5619 c_parser_error (parser
, "missing collection in fast enumeration");
5620 collection_expression
= error_mark_node
;
5623 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5627 if (is_foreach_statement
)
5628 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5632 struct c_expr ce
= c_parser_expression (parser
);
5633 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5634 incr
= c_process_expr_stmt (loc
, ce
.value
);
5637 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5639 save_break
= c_break_label
;
5640 c_break_label
= NULL_TREE
;
5641 save_cont
= c_cont_label
;
5642 c_cont_label
= NULL_TREE
;
5643 body
= c_parser_c99_block_statement (parser
);
5644 if (is_foreach_statement
)
5645 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5647 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5648 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5649 c_break_label
= save_break
;
5650 c_cont_label
= save_cont
;
5653 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5654 statement with inputs, outputs, clobbers, and volatile tag
5658 asm type-qualifier[opt] ( asm-argument ) ;
5659 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5663 asm-string-literal : asm-operands[opt]
5664 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5665 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5668 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5671 Qualifiers other than volatile are accepted in the syntax but
5675 c_parser_asm_statement (c_parser
*parser
)
5677 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5678 bool simple
, is_goto
;
5679 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5680 int section
, nsections
;
5682 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5683 c_parser_consume_token (parser
);
5684 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5686 quals
= c_parser_peek_token (parser
)->value
;
5687 c_parser_consume_token (parser
);
5689 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5690 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5692 warning_at (c_parser_peek_token (parser
)->location
,
5694 "%E qualifier ignored on asm",
5695 c_parser_peek_token (parser
)->value
);
5697 c_parser_consume_token (parser
);
5703 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5705 c_parser_consume_token (parser
);
5709 /* ??? Follow the C++ parser rather than using the
5710 lex_untranslated_string kludge. */
5711 parser
->lex_untranslated_string
= true;
5714 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5717 str
= c_parser_asm_string_literal (parser
);
5718 if (str
== NULL_TREE
)
5719 goto error_close_paren
;
5722 outputs
= NULL_TREE
;
5724 clobbers
= NULL_TREE
;
5727 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5730 /* Parse each colon-delimited section of operands. */
5731 nsections
= 3 + is_goto
;
5732 for (section
= 0; section
< nsections
; ++section
)
5734 if (!c_parser_require (parser
, CPP_COLON
,
5737 : "expected %<:%> or %<)%>"))
5738 goto error_close_paren
;
5740 /* Once past any colon, we're no longer a simple asm. */
5743 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5744 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5749 /* For asm goto, we don't allow output operands, but reserve
5750 the slot for a future extension that does allow them. */
5752 outputs
= c_parser_asm_operands (parser
);
5755 inputs
= c_parser_asm_operands (parser
);
5758 clobbers
= c_parser_asm_clobbers (parser
);
5761 labels
= c_parser_asm_goto_operands (parser
);
5767 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5772 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5774 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5778 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5779 c_parser_skip_to_end_of_block_or_statement (parser
);
5781 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5782 clobbers
, labels
, simple
));
5785 parser
->lex_untranslated_string
= false;
5789 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5793 /* Parse asm operands, a GNU extension.
5797 asm-operands , asm-operand
5800 asm-string-literal ( expression )
5801 [ identifier ] asm-string-literal ( expression )
5805 c_parser_asm_operands (c_parser
*parser
)
5807 tree list
= NULL_TREE
;
5812 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5814 c_parser_consume_token (parser
);
5815 if (c_parser_next_token_is (parser
, CPP_NAME
))
5817 tree id
= c_parser_peek_token (parser
)->value
;
5818 c_parser_consume_token (parser
);
5819 name
= build_string (IDENTIFIER_LENGTH (id
),
5820 IDENTIFIER_POINTER (id
));
5824 c_parser_error (parser
, "expected identifier");
5825 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5828 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5833 str
= c_parser_asm_string_literal (parser
);
5834 if (str
== NULL_TREE
)
5836 parser
->lex_untranslated_string
= false;
5837 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5839 parser
->lex_untranslated_string
= true;
5842 expr
= c_parser_expression (parser
);
5843 mark_exp_read (expr
.value
);
5844 parser
->lex_untranslated_string
= true;
5845 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5847 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5850 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5852 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5853 c_parser_consume_token (parser
);
5860 /* Parse asm clobbers, a GNU extension.
5864 asm-clobbers , asm-string-literal
5868 c_parser_asm_clobbers (c_parser
*parser
)
5870 tree list
= NULL_TREE
;
5873 tree str
= c_parser_asm_string_literal (parser
);
5875 list
= tree_cons (NULL_TREE
, str
, list
);
5878 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5879 c_parser_consume_token (parser
);
5886 /* Parse asm goto labels, a GNU extension.
5890 asm-goto-operands , identifier
5894 c_parser_asm_goto_operands (c_parser
*parser
)
5896 tree list
= NULL_TREE
;
5901 if (c_parser_next_token_is (parser
, CPP_NAME
))
5903 c_token
*tok
= c_parser_peek_token (parser
);
5905 label
= lookup_label_for_goto (tok
->location
, name
);
5906 c_parser_consume_token (parser
);
5907 TREE_USED (label
) = 1;
5911 c_parser_error (parser
, "expected identifier");
5915 name
= build_string (IDENTIFIER_LENGTH (name
),
5916 IDENTIFIER_POINTER (name
));
5917 list
= tree_cons (name
, label
, list
);
5918 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5919 c_parser_consume_token (parser
);
5921 return nreverse (list
);
5925 /* Parse an expression other than a compound expression; that is, an
5926 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5927 NULL then it is an Objective-C message expression which is the
5928 primary-expression starting the expression as an initializer.
5930 assignment-expression:
5931 conditional-expression
5932 unary-expression assignment-operator assignment-expression
5934 assignment-operator: one of
5935 = *= /= %= += -= <<= >>= &= ^= |=
5937 In GNU C we accept any conditional expression on the LHS and
5938 diagnose the invalid lvalue rather than producing a syntax
5941 static struct c_expr
5942 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5943 tree omp_atomic_lhs
)
5945 struct c_expr lhs
, rhs
, ret
;
5946 enum tree_code code
;
5947 location_t op_location
, exp_location
;
5948 gcc_assert (!after
|| c_dialect_objc ());
5949 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5950 op_location
= c_parser_peek_token (parser
)->location
;
5951 switch (c_parser_peek_token (parser
)->type
)
5960 code
= TRUNC_DIV_EXPR
;
5963 code
= TRUNC_MOD_EXPR
;
5978 code
= BIT_AND_EXPR
;
5981 code
= BIT_XOR_EXPR
;
5984 code
= BIT_IOR_EXPR
;
5989 c_parser_consume_token (parser
);
5990 exp_location
= c_parser_peek_token (parser
)->location
;
5991 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5992 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5994 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5995 code
, exp_location
, rhs
.value
,
5997 if (code
== NOP_EXPR
)
5998 ret
.original_code
= MODIFY_EXPR
;
6001 TREE_NO_WARNING (ret
.value
) = 1;
6002 ret
.original_code
= ERROR_MARK
;
6004 ret
.original_type
= NULL
;
6008 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6009 is not NULL then it is an Objective-C message expression which is
6010 the primary-expression starting the expression as an initializer.
6012 conditional-expression:
6013 logical-OR-expression
6014 logical-OR-expression ? expression : conditional-expression
6018 conditional-expression:
6019 logical-OR-expression ? : conditional-expression
6022 static struct c_expr
6023 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6024 tree omp_atomic_lhs
)
6026 struct c_expr cond
, exp1
, exp2
, ret
;
6027 location_t cond_loc
, colon_loc
, middle_loc
;
6029 gcc_assert (!after
|| c_dialect_objc ());
6031 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6033 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6035 cond_loc
= c_parser_peek_token (parser
)->location
;
6036 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6037 c_parser_consume_token (parser
);
6038 if (c_parser_next_token_is (parser
, CPP_COLON
))
6040 tree eptype
= NULL_TREE
;
6042 middle_loc
= c_parser_peek_token (parser
)->location
;
6043 pedwarn (middle_loc
, OPT_Wpedantic
,
6044 "ISO C forbids omitting the middle term of a ?: expression");
6045 warn_for_omitted_condop (middle_loc
, cond
.value
);
6046 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6048 eptype
= TREE_TYPE (cond
.value
);
6049 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6051 /* Make sure first operand is calculated only once. */
6052 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6054 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6055 exp1
.original_type
= NULL
;
6056 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6057 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6062 = c_objc_common_truthvalue_conversion
6063 (cond_loc
, default_conversion (cond
.value
));
6064 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6065 exp1
= c_parser_expression_conv (parser
);
6066 mark_exp_read (exp1
.value
);
6067 c_inhibit_evaluation_warnings
+=
6068 ((cond
.value
== truthvalue_true_node
)
6069 - (cond
.value
== truthvalue_false_node
));
6072 colon_loc
= c_parser_peek_token (parser
)->location
;
6073 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6075 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6076 ret
.value
= error_mark_node
;
6077 ret
.original_code
= ERROR_MARK
;
6078 ret
.original_type
= NULL
;
6082 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6083 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6084 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6086 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6087 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6088 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6089 exp1
.value
, exp1
.original_type
,
6090 exp2
.value
, exp2
.original_type
);
6091 ret
.original_code
= ERROR_MARK
;
6092 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6093 ret
.original_type
= NULL
;
6098 /* If both sides are enum type, the default conversion will have
6099 made the type of the result be an integer type. We want to
6100 remember the enum types we started with. */
6101 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6102 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6103 ret
.original_type
= ((t1
!= error_mark_node
6104 && t2
!= error_mark_node
6105 && (TYPE_MAIN_VARIANT (t1
)
6106 == TYPE_MAIN_VARIANT (t2
)))
6113 /* Parse a binary expression; that is, a logical-OR-expression (C90
6114 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6115 an Objective-C message expression which is the primary-expression
6116 starting the expression as an initializer.
6118 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6119 when it should be the unfolded lhs. In a valid OpenMP source,
6120 one of the operands of the toplevel binary expression must be equal
6121 to it. In that case, just return a build2 created binary operation
6122 rather than result of parser_build_binary_op.
6124 multiplicative-expression:
6126 multiplicative-expression * cast-expression
6127 multiplicative-expression / cast-expression
6128 multiplicative-expression % cast-expression
6130 additive-expression:
6131 multiplicative-expression
6132 additive-expression + multiplicative-expression
6133 additive-expression - multiplicative-expression
6137 shift-expression << additive-expression
6138 shift-expression >> additive-expression
6140 relational-expression:
6142 relational-expression < shift-expression
6143 relational-expression > shift-expression
6144 relational-expression <= shift-expression
6145 relational-expression >= shift-expression
6147 equality-expression:
6148 relational-expression
6149 equality-expression == relational-expression
6150 equality-expression != relational-expression
6154 AND-expression & equality-expression
6156 exclusive-OR-expression:
6158 exclusive-OR-expression ^ AND-expression
6160 inclusive-OR-expression:
6161 exclusive-OR-expression
6162 inclusive-OR-expression | exclusive-OR-expression
6164 logical-AND-expression:
6165 inclusive-OR-expression
6166 logical-AND-expression && inclusive-OR-expression
6168 logical-OR-expression:
6169 logical-AND-expression
6170 logical-OR-expression || logical-AND-expression
6173 static struct c_expr
6174 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6175 tree omp_atomic_lhs
)
6177 /* A binary expression is parsed using operator-precedence parsing,
6178 with the operands being cast expressions. All the binary
6179 operators are left-associative. Thus a binary expression is of
6182 E0 op1 E1 op2 E2 ...
6184 which we represent on a stack. On the stack, the precedence
6185 levels are strictly increasing. When a new operator is
6186 encountered of higher precedence than that at the top of the
6187 stack, it is pushed; its LHS is the top expression, and its RHS
6188 is everything parsed until it is popped. When a new operator is
6189 encountered with precedence less than or equal to that at the top
6190 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6191 by the result of the operation until the operator at the top of
6192 the stack has lower precedence than the new operator or there is
6193 only one element on the stack; then the top expression is the LHS
6194 of the new operator. In the case of logical AND and OR
6195 expressions, we also need to adjust c_inhibit_evaluation_warnings
6196 as appropriate when the operators are pushed and popped. */
6199 /* The expression at this stack level. */
6201 /* The precedence of the operator on its left, PREC_NONE at the
6202 bottom of the stack. */
6203 enum c_parser_prec prec
;
6204 /* The operation on its left. */
6206 /* The source location of this operation. */
6210 /* Location of the binary operator. */
6211 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6214 switch (stack[sp].op) \
6216 case TRUTH_ANDIF_EXPR: \
6217 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6218 == truthvalue_false_node); \
6220 case TRUTH_ORIF_EXPR: \
6221 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6222 == truthvalue_true_node); \
6227 stack[sp - 1].expr \
6228 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6229 stack[sp - 1].expr, true, true); \
6231 = convert_lvalue_to_rvalue (stack[sp].loc, \
6232 stack[sp].expr, true, true); \
6233 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6234 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6235 && ((1 << stack[sp].prec) \
6236 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6237 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6238 && stack[sp].op != TRUNC_MOD_EXPR \
6239 && stack[0].expr.value != error_mark_node \
6240 && stack[1].expr.value != error_mark_node \
6241 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6242 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6243 stack[0].expr.value \
6244 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6245 stack[0].expr.value, stack[1].expr.value); \
6247 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6249 stack[sp - 1].expr, \
6253 gcc_assert (!after
|| c_dialect_objc ());
6254 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6255 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6256 stack
[0].prec
= PREC_NONE
;
6260 enum c_parser_prec oprec
;
6261 enum tree_code ocode
;
6264 switch (c_parser_peek_token (parser
)->type
)
6272 ocode
= TRUNC_DIV_EXPR
;
6276 ocode
= TRUNC_MOD_EXPR
;
6288 ocode
= LSHIFT_EXPR
;
6292 ocode
= RSHIFT_EXPR
;
6306 case CPP_GREATER_EQ
:
6319 oprec
= PREC_BITAND
;
6320 ocode
= BIT_AND_EXPR
;
6323 oprec
= PREC_BITXOR
;
6324 ocode
= BIT_XOR_EXPR
;
6328 ocode
= BIT_IOR_EXPR
;
6331 oprec
= PREC_LOGAND
;
6332 ocode
= TRUTH_ANDIF_EXPR
;
6336 ocode
= TRUTH_ORIF_EXPR
;
6339 /* Not a binary operator, so end of the binary
6343 binary_loc
= c_parser_peek_token (parser
)->location
;
6344 while (oprec
<= stack
[sp
].prec
)
6346 c_parser_consume_token (parser
);
6349 case TRUTH_ANDIF_EXPR
:
6351 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6352 stack
[sp
].expr
, true, true);
6353 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6354 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6355 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6356 == truthvalue_false_node
);
6358 case TRUTH_ORIF_EXPR
:
6360 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6361 stack
[sp
].expr
, true, true);
6362 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6363 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6364 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6365 == truthvalue_true_node
);
6371 stack
[sp
].loc
= binary_loc
;
6372 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6373 stack
[sp
].prec
= oprec
;
6374 stack
[sp
].op
= ocode
;
6379 return stack
[0].expr
;
6383 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6384 NULL then it is an Objective-C message expression which is the
6385 primary-expression starting the expression as an initializer.
6389 ( type-name ) unary-expression
6392 static struct c_expr
6393 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6395 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6396 gcc_assert (!after
|| c_dialect_objc ());
6398 return c_parser_postfix_expression_after_primary (parser
,
6400 /* If the expression begins with a parenthesized type name, it may
6401 be either a cast or a compound literal; we need to see whether
6402 the next character is '{' to tell the difference. If not, it is
6403 an unary expression. Full detection of unknown typenames here
6404 would require a 3-token lookahead. */
6405 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6406 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6408 struct c_type_name
*type_name
;
6411 c_parser_consume_token (parser
);
6412 type_name
= c_parser_type_name (parser
);
6413 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6414 if (type_name
== NULL
)
6416 ret
.value
= error_mark_node
;
6417 ret
.original_code
= ERROR_MARK
;
6418 ret
.original_type
= NULL
;
6422 /* Save casted types in the function's used types hash table. */
6423 used_types_insert (type_name
->specs
->type
);
6425 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6426 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6429 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6430 expr
= c_parser_cast_expression (parser
, NULL
);
6431 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6433 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6434 ret
.original_code
= ERROR_MARK
;
6435 ret
.original_type
= NULL
;
6439 return c_parser_unary_expression (parser
);
6442 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6448 unary-operator cast-expression
6449 sizeof unary-expression
6450 sizeof ( type-name )
6452 unary-operator: one of
6458 __alignof__ unary-expression
6459 __alignof__ ( type-name )
6462 (C11 permits _Alignof with type names only.)
6464 unary-operator: one of
6465 __extension__ __real__ __imag__
6467 Transactional Memory:
6470 transaction-expression
6472 In addition, the GNU syntax treats ++ and -- as unary operators, so
6473 they may be applied to cast expressions with errors for non-lvalues
6476 static struct c_expr
6477 c_parser_unary_expression (c_parser
*parser
)
6480 struct c_expr ret
, op
;
6481 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6483 ret
.original_code
= ERROR_MARK
;
6484 ret
.original_type
= NULL
;
6485 switch (c_parser_peek_token (parser
)->type
)
6488 c_parser_consume_token (parser
);
6489 exp_loc
= c_parser_peek_token (parser
)->location
;
6490 op
= c_parser_cast_expression (parser
, NULL
);
6492 /* If there is array notations in op, we expand them. */
6493 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6494 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6497 op
= default_function_array_read_conversion (exp_loc
, op
);
6498 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6500 case CPP_MINUS_MINUS
:
6501 c_parser_consume_token (parser
);
6502 exp_loc
= c_parser_peek_token (parser
)->location
;
6503 op
= c_parser_cast_expression (parser
, NULL
);
6505 /* If there is array notations in op, we expand them. */
6506 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6507 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6510 op
= default_function_array_read_conversion (exp_loc
, op
);
6511 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6514 c_parser_consume_token (parser
);
6515 op
= c_parser_cast_expression (parser
, NULL
);
6516 mark_exp_read (op
.value
);
6517 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6519 c_parser_consume_token (parser
);
6520 exp_loc
= c_parser_peek_token (parser
)->location
;
6521 op
= c_parser_cast_expression (parser
, NULL
);
6522 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6523 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6526 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6529 "traditional C rejects the unary plus operator");
6530 c_parser_consume_token (parser
);
6531 exp_loc
= c_parser_peek_token (parser
)->location
;
6532 op
= c_parser_cast_expression (parser
, NULL
);
6533 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6534 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6536 c_parser_consume_token (parser
);
6537 exp_loc
= c_parser_peek_token (parser
)->location
;
6538 op
= c_parser_cast_expression (parser
, NULL
);
6539 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6540 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6542 c_parser_consume_token (parser
);
6543 exp_loc
= c_parser_peek_token (parser
)->location
;
6544 op
= c_parser_cast_expression (parser
, NULL
);
6545 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6546 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6548 c_parser_consume_token (parser
);
6549 exp_loc
= c_parser_peek_token (parser
)->location
;
6550 op
= c_parser_cast_expression (parser
, NULL
);
6551 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6552 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6554 /* Refer to the address of a label as a pointer. */
6555 c_parser_consume_token (parser
);
6556 if (c_parser_next_token_is (parser
, CPP_NAME
))
6558 ret
.value
= finish_label_address_expr
6559 (c_parser_peek_token (parser
)->value
, op_loc
);
6560 c_parser_consume_token (parser
);
6564 c_parser_error (parser
, "expected identifier");
6565 ret
.value
= error_mark_node
;
6569 switch (c_parser_peek_token (parser
)->keyword
)
6572 return c_parser_sizeof_expression (parser
);
6574 return c_parser_alignof_expression (parser
);
6576 c_parser_consume_token (parser
);
6577 ext
= disable_extension_diagnostics ();
6578 ret
= c_parser_cast_expression (parser
, NULL
);
6579 restore_extension_diagnostics (ext
);
6582 c_parser_consume_token (parser
);
6583 exp_loc
= c_parser_peek_token (parser
)->location
;
6584 op
= c_parser_cast_expression (parser
, NULL
);
6585 op
= default_function_array_conversion (exp_loc
, op
);
6586 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6588 c_parser_consume_token (parser
);
6589 exp_loc
= c_parser_peek_token (parser
)->location
;
6590 op
= c_parser_cast_expression (parser
, NULL
);
6591 op
= default_function_array_conversion (exp_loc
, op
);
6592 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6593 case RID_TRANSACTION_ATOMIC
:
6594 case RID_TRANSACTION_RELAXED
:
6595 return c_parser_transaction_expression (parser
,
6596 c_parser_peek_token (parser
)->keyword
);
6598 return c_parser_postfix_expression (parser
);
6601 return c_parser_postfix_expression (parser
);
6605 /* Parse a sizeof expression. */
6607 static struct c_expr
6608 c_parser_sizeof_expression (c_parser
*parser
)
6611 location_t expr_loc
;
6612 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6613 c_parser_consume_token (parser
);
6614 c_inhibit_evaluation_warnings
++;
6616 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6617 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6619 /* Either sizeof ( type-name ) or sizeof unary-expression
6620 starting with a compound literal. */
6621 struct c_type_name
*type_name
;
6622 c_parser_consume_token (parser
);
6623 expr_loc
= c_parser_peek_token (parser
)->location
;
6624 type_name
= c_parser_type_name (parser
);
6625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6626 if (type_name
== NULL
)
6629 c_inhibit_evaluation_warnings
--;
6631 ret
.value
= error_mark_node
;
6632 ret
.original_code
= ERROR_MARK
;
6633 ret
.original_type
= NULL
;
6636 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6638 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6643 /* sizeof ( type-name ). */
6644 c_inhibit_evaluation_warnings
--;
6646 return c_expr_sizeof_type (expr_loc
, type_name
);
6650 expr_loc
= c_parser_peek_token (parser
)->location
;
6651 expr
= c_parser_unary_expression (parser
);
6653 c_inhibit_evaluation_warnings
--;
6655 mark_exp_read (expr
.value
);
6656 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6657 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6658 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6659 return c_expr_sizeof_expr (expr_loc
, expr
);
6663 /* Parse an alignof expression. */
6665 static struct c_expr
6666 c_parser_alignof_expression (c_parser
*parser
)
6669 location_t loc
= c_parser_peek_token (parser
)->location
;
6670 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6671 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6672 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6674 /* A diagnostic is not required for the use of this identifier in
6675 the implementation namespace; only diagnose it for the C11
6676 spelling because of existing code using the other spellings. */
6680 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6683 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6686 c_parser_consume_token (parser
);
6687 c_inhibit_evaluation_warnings
++;
6689 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6690 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6692 /* Either __alignof__ ( type-name ) or __alignof__
6693 unary-expression starting with a compound literal. */
6695 struct c_type_name
*type_name
;
6697 c_parser_consume_token (parser
);
6698 loc
= c_parser_peek_token (parser
)->location
;
6699 type_name
= c_parser_type_name (parser
);
6700 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6701 if (type_name
== NULL
)
6704 c_inhibit_evaluation_warnings
--;
6706 ret
.value
= error_mark_node
;
6707 ret
.original_code
= ERROR_MARK
;
6708 ret
.original_type
= NULL
;
6711 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6713 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6718 /* alignof ( type-name ). */
6719 c_inhibit_evaluation_warnings
--;
6721 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6723 false, is_c11_alignof
, 1);
6724 ret
.original_code
= ERROR_MARK
;
6725 ret
.original_type
= NULL
;
6731 expr
= c_parser_unary_expression (parser
);
6733 mark_exp_read (expr
.value
);
6734 c_inhibit_evaluation_warnings
--;
6736 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6738 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6739 ret
.original_code
= ERROR_MARK
;
6740 ret
.original_type
= NULL
;
6745 /* Helper function to read arguments of builtins which are interfaces
6746 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6747 others. The name of the builtin is passed using BNAME parameter.
6748 Function returns true if there were no errors while parsing and
6749 stores the arguments in CEXPR_LIST. */
6751 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6752 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6755 location_t loc
= c_parser_peek_token (parser
)->location
;
6756 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6758 bool saved_force_folding_builtin_constant_p
;
6760 *ret_cexpr_list
= NULL
;
6761 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6763 error_at (loc
, "cannot take address of %qs", bname
);
6767 c_parser_consume_token (parser
);
6769 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6771 c_parser_consume_token (parser
);
6775 saved_force_folding_builtin_constant_p
6776 = force_folding_builtin_constant_p
;
6777 force_folding_builtin_constant_p
|= choose_expr_p
;
6778 expr
= c_parser_expr_no_commas (parser
, NULL
);
6779 force_folding_builtin_constant_p
6780 = saved_force_folding_builtin_constant_p
;
6781 vec_alloc (cexpr_list
, 1);
6782 vec_safe_push (cexpr_list
, expr
);
6783 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6785 c_parser_consume_token (parser
);
6786 expr
= c_parser_expr_no_commas (parser
, NULL
);
6787 vec_safe_push (cexpr_list
, expr
);
6790 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6793 *ret_cexpr_list
= cexpr_list
;
6797 /* This represents a single generic-association. */
6799 struct c_generic_association
6801 /* The location of the starting token of the type. */
6802 location_t type_location
;
6803 /* The association's type, or NULL_TREE for 'default'. */
6805 /* The association's expression. */
6806 struct c_expr expression
;
6809 /* Parse a generic-selection. (C11 6.5.1.1).
6812 _Generic ( assignment-expression , generic-assoc-list )
6816 generic-assoc-list , generic-association
6818 generic-association:
6819 type-name : assignment-expression
6820 default : assignment-expression
6823 static struct c_expr
6824 c_parser_generic_selection (c_parser
*parser
)
6826 vec
<c_generic_association
> associations
= vNULL
;
6827 struct c_expr selector
, error_expr
;
6829 struct c_generic_association matched_assoc
;
6830 bool match_found
= false;
6831 location_t generic_loc
, selector_loc
;
6833 error_expr
.original_code
= ERROR_MARK
;
6834 error_expr
.original_type
= NULL
;
6835 error_expr
.value
= error_mark_node
;
6836 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6837 matched_assoc
.type
= NULL_TREE
;
6838 matched_assoc
.expression
= error_expr
;
6840 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6841 generic_loc
= c_parser_peek_token (parser
)->location
;
6842 c_parser_consume_token (parser
);
6844 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6845 "ISO C99 does not support %<_Generic%>");
6847 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6848 "ISO C90 does not support %<_Generic%>");
6850 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6853 c_inhibit_evaluation_warnings
++;
6854 selector_loc
= c_parser_peek_token (parser
)->location
;
6855 selector
= c_parser_expr_no_commas (parser
, NULL
);
6856 selector
= default_function_array_conversion (selector_loc
, selector
);
6857 c_inhibit_evaluation_warnings
--;
6859 if (selector
.value
== error_mark_node
)
6861 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6864 selector_type
= TREE_TYPE (selector
.value
);
6865 /* In ISO C terms, rvalues (including the controlling expression of
6866 _Generic) do not have qualified types. */
6867 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6868 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6869 /* In ISO C terms, _Noreturn is not part of the type of expressions
6870 such as &abort, but in GCC it is represented internally as a type
6872 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6873 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6875 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6877 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6879 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6885 struct c_generic_association assoc
, *iter
;
6887 c_token
*token
= c_parser_peek_token (parser
);
6889 assoc
.type_location
= token
->location
;
6890 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6892 c_parser_consume_token (parser
);
6893 assoc
.type
= NULL_TREE
;
6897 struct c_type_name
*type_name
;
6899 type_name
= c_parser_type_name (parser
);
6900 if (type_name
== NULL
)
6902 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6905 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6906 if (assoc
.type
== error_mark_node
)
6908 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6912 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6913 error_at (assoc
.type_location
,
6914 "%<_Generic%> association has function type");
6915 else if (!COMPLETE_TYPE_P (assoc
.type
))
6916 error_at (assoc
.type_location
,
6917 "%<_Generic%> association has incomplete type");
6919 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6920 error_at (assoc
.type_location
,
6921 "%<_Generic%> association has "
6922 "variable length type");
6925 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6927 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6931 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6932 if (assoc
.expression
.value
== error_mark_node
)
6934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6938 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6940 if (assoc
.type
== NULL_TREE
)
6942 if (iter
->type
== NULL_TREE
)
6944 error_at (assoc
.type_location
,
6945 "duplicate %<default%> case in %<_Generic%>");
6946 inform (iter
->type_location
, "original %<default%> is here");
6949 else if (iter
->type
!= NULL_TREE
)
6951 if (comptypes (assoc
.type
, iter
->type
))
6953 error_at (assoc
.type_location
,
6954 "%<_Generic%> specifies two compatible types");
6955 inform (iter
->type_location
, "compatible type is here");
6960 if (assoc
.type
== NULL_TREE
)
6964 matched_assoc
= assoc
;
6968 else if (comptypes (assoc
.type
, selector_type
))
6970 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6972 matched_assoc
= assoc
;
6977 error_at (assoc
.type_location
,
6978 "%<_Generic> selector matches multiple associations");
6979 inform (matched_assoc
.type_location
,
6980 "other match is here");
6984 associations
.safe_push (assoc
);
6986 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6988 c_parser_consume_token (parser
);
6991 associations
.release ();
6993 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6995 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7001 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7002 "compatible with any association",
7007 return matched_assoc
.expression
;
7010 associations
.release ();
7014 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7018 postfix-expression [ expression ]
7019 postfix-expression ( argument-expression-list[opt] )
7020 postfix-expression . identifier
7021 postfix-expression -> identifier
7022 postfix-expression ++
7023 postfix-expression --
7024 ( type-name ) { initializer-list }
7025 ( type-name ) { initializer-list , }
7027 argument-expression-list:
7029 argument-expression-list , argument-expression
7042 (treated as a keyword in GNU C)
7045 ( compound-statement )
7046 __builtin_va_arg ( assignment-expression , type-name )
7047 __builtin_offsetof ( type-name , offsetof-member-designator )
7048 __builtin_choose_expr ( assignment-expression ,
7049 assignment-expression ,
7050 assignment-expression )
7051 __builtin_types_compatible_p ( type-name , type-name )
7052 __builtin_complex ( assignment-expression , assignment-expression )
7053 __builtin_shuffle ( assignment-expression , assignment-expression )
7054 __builtin_shuffle ( assignment-expression ,
7055 assignment-expression ,
7056 assignment-expression, )
7058 offsetof-member-designator:
7060 offsetof-member-designator . identifier
7061 offsetof-member-designator [ expression ]
7066 [ objc-receiver objc-message-args ]
7067 @selector ( objc-selector-arg )
7068 @protocol ( identifier )
7069 @encode ( type-name )
7071 Classname . identifier
7074 static struct c_expr
7075 c_parser_postfix_expression (c_parser
*parser
)
7077 struct c_expr expr
, e1
;
7078 struct c_type_name
*t1
, *t2
;
7079 location_t loc
= c_parser_peek_token (parser
)->location
;;
7080 expr
.original_code
= ERROR_MARK
;
7081 expr
.original_type
= NULL
;
7082 switch (c_parser_peek_token (parser
)->type
)
7085 expr
.value
= c_parser_peek_token (parser
)->value
;
7086 loc
= c_parser_peek_token (parser
)->location
;
7087 c_parser_consume_token (parser
);
7088 if (TREE_CODE (expr
.value
) == FIXED_CST
7089 && !targetm
.fixed_point_supported_p ())
7091 error_at (loc
, "fixed-point types not supported for this target");
7092 expr
.value
= error_mark_node
;
7099 expr
.value
= c_parser_peek_token (parser
)->value
;
7100 c_parser_consume_token (parser
);
7106 case CPP_UTF8STRING
:
7107 expr
.value
= c_parser_peek_token (parser
)->value
;
7108 expr
.original_code
= STRING_CST
;
7109 c_parser_consume_token (parser
);
7111 case CPP_OBJC_STRING
:
7112 gcc_assert (c_dialect_objc ());
7114 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7115 c_parser_consume_token (parser
);
7118 switch (c_parser_peek_token (parser
)->id_kind
)
7122 tree id
= c_parser_peek_token (parser
)->value
;
7123 c_parser_consume_token (parser
);
7124 expr
.value
= build_external_ref (loc
, id
,
7125 (c_parser_peek_token (parser
)->type
7127 &expr
.original_type
);
7130 case C_ID_CLASSNAME
:
7132 /* Here we parse the Objective-C 2.0 Class.name dot
7134 tree class_name
= c_parser_peek_token (parser
)->value
;
7136 c_parser_consume_token (parser
);
7137 gcc_assert (c_dialect_objc ());
7138 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7140 expr
.value
= error_mark_node
;
7143 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7145 c_parser_error (parser
, "expected identifier");
7146 expr
.value
= error_mark_node
;
7149 component
= c_parser_peek_token (parser
)->value
;
7150 c_parser_consume_token (parser
);
7151 expr
.value
= objc_build_class_component_ref (class_name
,
7156 c_parser_error (parser
, "expected expression");
7157 expr
.value
= error_mark_node
;
7161 case CPP_OPEN_PAREN
:
7162 /* A parenthesized expression, statement expression or compound
7164 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7166 /* A statement expression. */
7168 location_t brace_loc
;
7169 c_parser_consume_token (parser
);
7170 brace_loc
= c_parser_peek_token (parser
)->location
;
7171 c_parser_consume_token (parser
);
7172 if (!building_stmt_list_p ())
7174 error_at (loc
, "braced-group within expression allowed "
7175 "only inside a function");
7176 parser
->error
= true;
7177 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7178 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7179 expr
.value
= error_mark_node
;
7182 stmt
= c_begin_stmt_expr ();
7183 c_parser_compound_statement_nostart (parser
);
7184 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7186 pedwarn (loc
, OPT_Wpedantic
,
7187 "ISO C forbids braced-groups within expressions");
7188 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7189 mark_exp_read (expr
.value
);
7191 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7193 /* A compound literal. ??? Can we actually get here rather
7194 than going directly to
7195 c_parser_postfix_expression_after_paren_type from
7198 struct c_type_name
*type_name
;
7199 c_parser_consume_token (parser
);
7200 loc
= c_parser_peek_token (parser
)->location
;
7201 type_name
= c_parser_type_name (parser
);
7202 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7204 if (type_name
== NULL
)
7206 expr
.value
= error_mark_node
;
7209 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7215 /* A parenthesized expression. */
7216 c_parser_consume_token (parser
);
7217 expr
= c_parser_expression (parser
);
7218 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7219 TREE_NO_WARNING (expr
.value
) = 1;
7220 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7221 expr
.original_code
= ERROR_MARK
;
7222 /* Don't change EXPR.ORIGINAL_TYPE. */
7223 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7228 switch (c_parser_peek_token (parser
)->keyword
)
7230 case RID_FUNCTION_NAME
:
7231 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7232 "%<__FUNCTION__%> predefined identifier");
7233 expr
.value
= fname_decl (loc
,
7234 c_parser_peek_token (parser
)->keyword
,
7235 c_parser_peek_token (parser
)->value
);
7236 c_parser_consume_token (parser
);
7238 case RID_PRETTY_FUNCTION_NAME
:
7239 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7240 "%<__PRETTY_FUNCTION__%> predefined identifier");
7241 expr
.value
= fname_decl (loc
,
7242 c_parser_peek_token (parser
)->keyword
,
7243 c_parser_peek_token (parser
)->value
);
7244 c_parser_consume_token (parser
);
7246 case RID_C99_FUNCTION_NAME
:
7247 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7248 "%<__func__%> predefined identifier");
7249 expr
.value
= fname_decl (loc
,
7250 c_parser_peek_token (parser
)->keyword
,
7251 c_parser_peek_token (parser
)->value
);
7252 c_parser_consume_token (parser
);
7255 c_parser_consume_token (parser
);
7256 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7258 expr
.value
= error_mark_node
;
7261 e1
= c_parser_expr_no_commas (parser
, NULL
);
7262 mark_exp_read (e1
.value
);
7263 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7264 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7266 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7267 expr
.value
= error_mark_node
;
7270 loc
= c_parser_peek_token (parser
)->location
;
7271 t1
= c_parser_type_name (parser
);
7272 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7276 expr
.value
= error_mark_node
;
7280 tree type_expr
= NULL_TREE
;
7281 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7282 groktypename (t1
, &type_expr
, NULL
));
7285 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7286 TREE_TYPE (expr
.value
), type_expr
,
7288 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7293 c_parser_consume_token (parser
);
7294 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7296 expr
.value
= error_mark_node
;
7299 t1
= c_parser_type_name (parser
);
7301 parser
->error
= true;
7302 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7303 gcc_assert (parser
->error
);
7306 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7307 expr
.value
= error_mark_node
;
7312 tree type
= groktypename (t1
, NULL
, NULL
);
7314 if (type
== error_mark_node
)
7315 offsetof_ref
= error_mark_node
;
7318 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7319 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7321 /* Parse the second argument to __builtin_offsetof. We
7322 must have one identifier, and beyond that we want to
7323 accept sub structure and sub array references. */
7324 if (c_parser_next_token_is (parser
, CPP_NAME
))
7326 offsetof_ref
= build_component_ref
7327 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7328 c_parser_consume_token (parser
);
7329 while (c_parser_next_token_is (parser
, CPP_DOT
)
7330 || c_parser_next_token_is (parser
,
7332 || c_parser_next_token_is (parser
,
7335 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7337 loc
= c_parser_peek_token (parser
)->location
;
7338 offsetof_ref
= build_array_ref (loc
,
7343 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7346 c_parser_consume_token (parser
);
7347 if (c_parser_next_token_is_not (parser
,
7350 c_parser_error (parser
, "expected identifier");
7353 offsetof_ref
= build_component_ref
7355 c_parser_peek_token (parser
)->value
);
7356 c_parser_consume_token (parser
);
7362 loc
= c_parser_peek_token (parser
)->location
;
7363 c_parser_consume_token (parser
);
7364 ce
= c_parser_expression (parser
);
7365 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7367 idx
= c_fully_fold (idx
, false, NULL
);
7368 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7370 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7375 c_parser_error (parser
, "expected identifier");
7376 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7378 expr
.value
= fold_offsetof (offsetof_ref
);
7381 case RID_CHOOSE_EXPR
:
7383 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7384 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7387 c_parser_consume_token (parser
);
7388 if (!c_parser_get_builtin_args (parser
,
7389 "__builtin_choose_expr",
7392 expr
.value
= error_mark_node
;
7396 if (vec_safe_length (cexpr_list
) != 3)
7398 error_at (loc
, "wrong number of arguments to "
7399 "%<__builtin_choose_expr%>");
7400 expr
.value
= error_mark_node
;
7404 e1_p
= &(*cexpr_list
)[0];
7405 e2_p
= &(*cexpr_list
)[1];
7406 e3_p
= &(*cexpr_list
)[2];
7409 mark_exp_read (e2_p
->value
);
7410 mark_exp_read (e3_p
->value
);
7411 if (TREE_CODE (c
) != INTEGER_CST
7412 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7414 "first argument to %<__builtin_choose_expr%> not"
7416 constant_expression_warning (c
);
7417 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7420 case RID_TYPES_COMPATIBLE_P
:
7421 c_parser_consume_token (parser
);
7422 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7424 expr
.value
= error_mark_node
;
7427 t1
= c_parser_type_name (parser
);
7430 expr
.value
= error_mark_node
;
7433 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7435 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7436 expr
.value
= error_mark_node
;
7439 t2
= c_parser_type_name (parser
);
7442 expr
.value
= error_mark_node
;
7445 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7449 e1
= groktypename (t1
, NULL
, NULL
);
7450 e2
= groktypename (t2
, NULL
, NULL
);
7451 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7453 expr
.value
= error_mark_node
;
7457 e1
= TYPE_MAIN_VARIANT (e1
);
7458 e2
= TYPE_MAIN_VARIANT (e2
);
7461 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7464 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7466 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7470 c_parser_consume_token (parser
);
7471 if (!c_parser_get_builtin_args (parser
,
7472 "__builtin_call_with_static_chain",
7473 &cexpr_list
, false))
7475 expr
.value
= error_mark_node
;
7478 if (vec_safe_length (cexpr_list
) != 2)
7480 error_at (loc
, "wrong number of arguments to "
7481 "%<__builtin_call_with_static_chain%>");
7482 expr
.value
= error_mark_node
;
7486 expr
= (*cexpr_list
)[0];
7487 e2_p
= &(*cexpr_list
)[1];
7488 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7489 chain_value
= e2_p
->value
;
7490 mark_exp_read (chain_value
);
7492 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7493 error_at (loc
, "first argument to "
7494 "%<__builtin_call_with_static_chain%> "
7495 "must be a call expression");
7496 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7497 error_at (loc
, "second argument to "
7498 "%<__builtin_call_with_static_chain%> "
7499 "must be a pointer type");
7501 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7504 case RID_BUILTIN_COMPLEX
:
7506 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7507 c_expr_t
*e1_p
, *e2_p
;
7509 c_parser_consume_token (parser
);
7510 if (!c_parser_get_builtin_args (parser
,
7511 "__builtin_complex",
7512 &cexpr_list
, false))
7514 expr
.value
= error_mark_node
;
7518 if (vec_safe_length (cexpr_list
) != 2)
7520 error_at (loc
, "wrong number of arguments to "
7521 "%<__builtin_complex%>");
7522 expr
.value
= error_mark_node
;
7526 e1_p
= &(*cexpr_list
)[0];
7527 e2_p
= &(*cexpr_list
)[1];
7529 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7530 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7531 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7532 TREE_OPERAND (e1_p
->value
, 0));
7533 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7534 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7535 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7536 TREE_OPERAND (e2_p
->value
, 0));
7537 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7538 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7539 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7540 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7542 error_at (loc
, "%<__builtin_complex%> operand "
7543 "not of real binary floating-point type");
7544 expr
.value
= error_mark_node
;
7547 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7548 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7551 "%<__builtin_complex%> operands of different types");
7552 expr
.value
= error_mark_node
;
7555 pedwarn_c90 (loc
, OPT_Wpedantic
,
7556 "ISO C90 does not support complex types");
7557 expr
.value
= build2 (COMPLEX_EXPR
,
7560 (TREE_TYPE (e1_p
->value
))),
7561 e1_p
->value
, e2_p
->value
);
7564 case RID_BUILTIN_SHUFFLE
:
7566 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7570 c_parser_consume_token (parser
);
7571 if (!c_parser_get_builtin_args (parser
,
7572 "__builtin_shuffle",
7573 &cexpr_list
, false))
7575 expr
.value
= error_mark_node
;
7579 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7580 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7582 if (vec_safe_length (cexpr_list
) == 2)
7584 c_build_vec_perm_expr
7585 (loc
, (*cexpr_list
)[0].value
,
7586 NULL_TREE
, (*cexpr_list
)[1].value
);
7588 else if (vec_safe_length (cexpr_list
) == 3)
7590 c_build_vec_perm_expr
7591 (loc
, (*cexpr_list
)[0].value
,
7592 (*cexpr_list
)[1].value
,
7593 (*cexpr_list
)[2].value
);
7596 error_at (loc
, "wrong number of arguments to "
7597 "%<__builtin_shuffle%>");
7598 expr
.value
= error_mark_node
;
7602 case RID_AT_SELECTOR
:
7603 gcc_assert (c_dialect_objc ());
7604 c_parser_consume_token (parser
);
7605 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7607 expr
.value
= error_mark_node
;
7611 tree sel
= c_parser_objc_selector_arg (parser
);
7612 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7614 expr
.value
= objc_build_selector_expr (loc
, sel
);
7617 case RID_AT_PROTOCOL
:
7618 gcc_assert (c_dialect_objc ());
7619 c_parser_consume_token (parser
);
7620 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7622 expr
.value
= error_mark_node
;
7625 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7627 c_parser_error (parser
, "expected identifier");
7628 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7629 expr
.value
= error_mark_node
;
7633 tree id
= c_parser_peek_token (parser
)->value
;
7634 c_parser_consume_token (parser
);
7635 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7637 expr
.value
= objc_build_protocol_expr (id
);
7641 /* Extension to support C-structures in the archiver. */
7642 gcc_assert (c_dialect_objc ());
7643 c_parser_consume_token (parser
);
7644 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7646 expr
.value
= error_mark_node
;
7649 t1
= c_parser_type_name (parser
);
7652 expr
.value
= error_mark_node
;
7653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7656 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7659 tree type
= groktypename (t1
, NULL
, NULL
);
7660 expr
.value
= objc_build_encode_expr (type
);
7664 expr
= c_parser_generic_selection (parser
);
7666 case RID_CILK_SPAWN
:
7667 c_parser_consume_token (parser
);
7670 error_at (loc
, "-fcilkplus must be enabled to use "
7672 expr
= c_parser_postfix_expression (parser
);
7673 expr
.value
= error_mark_node
;
7675 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7677 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7678 "are not permitted");
7679 /* Now flush out all the _Cilk_spawns. */
7680 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7681 c_parser_consume_token (parser
);
7682 expr
= c_parser_postfix_expression (parser
);
7686 expr
= c_parser_postfix_expression (parser
);
7687 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7691 c_parser_error (parser
, "expected expression");
7692 expr
.value
= error_mark_node
;
7696 case CPP_OPEN_SQUARE
:
7697 if (c_dialect_objc ())
7699 tree receiver
, args
;
7700 c_parser_consume_token (parser
);
7701 receiver
= c_parser_objc_receiver (parser
);
7702 args
= c_parser_objc_message_args (parser
);
7703 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7705 expr
.value
= objc_build_message_expr (receiver
, args
);
7708 /* Else fall through to report error. */
7710 c_parser_error (parser
, "expected expression");
7711 expr
.value
= error_mark_node
;
7714 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7717 /* Parse a postfix expression after a parenthesized type name: the
7718 brace-enclosed initializer of a compound literal, possibly followed
7719 by some postfix operators. This is separate because it is not
7720 possible to tell until after the type name whether a cast
7721 expression has a cast or a compound literal, or whether the operand
7722 of sizeof is a parenthesized type name or starts with a compound
7723 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7724 location of the first token after the parentheses around the type
7727 static struct c_expr
7728 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7729 struct c_type_name
*type_name
,
7730 location_t type_loc
)
7736 location_t start_loc
;
7737 tree type_expr
= NULL_TREE
;
7738 bool type_expr_const
= true;
7739 check_compound_literal_type (type_loc
, type_name
);
7740 start_init (NULL_TREE
, NULL
, 0);
7741 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7742 start_loc
= c_parser_peek_token (parser
)->location
;
7743 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7745 error_at (type_loc
, "compound literal has variable size");
7746 type
= error_mark_node
;
7748 init
= c_parser_braced_init (parser
, type
, false);
7750 maybe_warn_string_init (type_loc
, type
, init
);
7752 if (type
!= error_mark_node
7753 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7754 && current_function_decl
)
7756 error ("compound literal qualified by address-space qualifier");
7757 type
= error_mark_node
;
7760 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7761 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7762 ? CONSTRUCTOR_NON_CONST (init
.value
)
7763 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7764 non_const
|= !type_expr_const
;
7765 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7766 expr
.original_code
= ERROR_MARK
;
7767 expr
.original_type
= NULL
;
7770 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7772 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7773 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7777 gcc_assert (!non_const
);
7778 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7779 type_expr
, expr
.value
);
7782 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7785 /* Callback function for sizeof_pointer_memaccess_warning to compare
7789 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7791 return comptypes (type1
, type2
) == 1;
7794 /* Parse a postfix expression after the initial primary or compound
7795 literal; that is, parse a series of postfix operators.
7797 EXPR_LOC is the location of the primary expression. */
7799 static struct c_expr
7800 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7801 location_t expr_loc
,
7804 struct c_expr orig_expr
;
7806 location_t sizeof_arg_loc
[3];
7808 unsigned int literal_zero_mask
;
7810 vec
<tree
, va_gc
> *exprlist
;
7811 vec
<tree
, va_gc
> *origtypes
= NULL
;
7812 vec
<location_t
> arg_loc
= vNULL
;
7816 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7817 switch (c_parser_peek_token (parser
)->type
)
7819 case CPP_OPEN_SQUARE
:
7820 /* Array reference. */
7821 c_parser_consume_token (parser
);
7823 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7824 /* If we are here, then we have something like this:
7827 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7831 idx
= c_parser_expression (parser
).value
;
7832 /* Here we have 3 options:
7833 1. Array [EXPR] -- Normal Array call.
7834 2. Array [EXPR : EXPR] -- Array notation without stride.
7835 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7837 For 1, we just handle it just like a normal array expression.
7838 For 2 and 3 we handle it like we handle array notations. The
7839 idx value we have above becomes the initial/start index.
7842 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7843 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7847 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7849 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7852 expr
.original_code
= ERROR_MARK
;
7853 expr
.original_type
= NULL
;
7855 case CPP_OPEN_PAREN
:
7856 /* Function call. */
7857 c_parser_consume_token (parser
);
7858 for (i
= 0; i
< 3; i
++)
7860 sizeof_arg
[i
] = NULL_TREE
;
7861 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7863 literal_zero_mask
= 0;
7864 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7867 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7868 sizeof_arg_loc
, sizeof_arg
,
7869 &arg_loc
, &literal_zero_mask
);
7870 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7873 mark_exp_read (expr
.value
);
7874 if (warn_sizeof_pointer_memaccess
)
7875 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7876 expr
.value
, exprlist
,
7878 sizeof_ptr_memacc_comptypes
);
7879 if (warn_memset_transposed_args
7880 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7881 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7882 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7883 && vec_safe_length (exprlist
) == 3
7884 && integer_zerop ((*exprlist
)[2])
7885 && (literal_zero_mask
& (1 << 2)) != 0
7886 && (!integer_zerop ((*exprlist
)[1])
7887 || (literal_zero_mask
& (1 << 1)) == 0))
7888 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7889 "%<memset%> used with constant zero length parameter; "
7890 "this could be due to transposed parameters");
7893 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7894 exprlist
, origtypes
);
7895 expr
.original_code
= ERROR_MARK
;
7896 if (TREE_CODE (expr
.value
) == INTEGER_CST
7897 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7898 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7899 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7900 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7901 expr
.original_type
= NULL
;
7904 release_tree_vector (exprlist
);
7905 release_tree_vector (origtypes
);
7910 /* Structure element reference. */
7911 c_parser_consume_token (parser
);
7912 expr
= default_function_array_conversion (expr_loc
, expr
);
7913 if (c_parser_next_token_is (parser
, CPP_NAME
))
7914 ident
= c_parser_peek_token (parser
)->value
;
7917 c_parser_error (parser
, "expected identifier");
7918 expr
.value
= error_mark_node
;
7919 expr
.original_code
= ERROR_MARK
;
7920 expr
.original_type
= NULL
;
7923 c_parser_consume_token (parser
);
7924 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7925 expr
.original_code
= ERROR_MARK
;
7926 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7927 expr
.original_type
= NULL
;
7930 /* Remember the original type of a bitfield. */
7931 tree field
= TREE_OPERAND (expr
.value
, 1);
7932 if (TREE_CODE (field
) != FIELD_DECL
)
7933 expr
.original_type
= NULL
;
7935 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7939 /* Structure element reference. */
7940 c_parser_consume_token (parser
);
7941 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7942 if (c_parser_next_token_is (parser
, CPP_NAME
))
7943 ident
= c_parser_peek_token (parser
)->value
;
7946 c_parser_error (parser
, "expected identifier");
7947 expr
.value
= error_mark_node
;
7948 expr
.original_code
= ERROR_MARK
;
7949 expr
.original_type
= NULL
;
7952 c_parser_consume_token (parser
);
7953 expr
.value
= build_component_ref (op_loc
,
7954 build_indirect_ref (op_loc
,
7958 expr
.original_code
= ERROR_MARK
;
7959 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7960 expr
.original_type
= NULL
;
7963 /* Remember the original type of a bitfield. */
7964 tree field
= TREE_OPERAND (expr
.value
, 1);
7965 if (TREE_CODE (field
) != FIELD_DECL
)
7966 expr
.original_type
= NULL
;
7968 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7972 /* Postincrement. */
7973 c_parser_consume_token (parser
);
7974 /* If the expressions have array notations, we expand them. */
7976 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7977 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7980 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7981 expr
.value
= build_unary_op (op_loc
,
7982 POSTINCREMENT_EXPR
, expr
.value
, 0);
7984 expr
.original_code
= ERROR_MARK
;
7985 expr
.original_type
= NULL
;
7987 case CPP_MINUS_MINUS
:
7988 /* Postdecrement. */
7989 c_parser_consume_token (parser
);
7990 /* If the expressions have array notations, we expand them. */
7992 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7993 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7996 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7997 expr
.value
= build_unary_op (op_loc
,
7998 POSTDECREMENT_EXPR
, expr
.value
, 0);
8000 expr
.original_code
= ERROR_MARK
;
8001 expr
.original_type
= NULL
;
8009 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8012 assignment-expression
8013 expression , assignment-expression
8016 static struct c_expr
8017 c_parser_expression (c_parser
*parser
)
8019 location_t tloc
= c_parser_peek_token (parser
)->location
;
8021 expr
= c_parser_expr_no_commas (parser
, NULL
);
8022 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8023 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8024 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8028 location_t loc
= c_parser_peek_token (parser
)->location
;
8029 location_t expr_loc
;
8030 c_parser_consume_token (parser
);
8031 expr_loc
= c_parser_peek_token (parser
)->location
;
8032 lhsval
= expr
.value
;
8033 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8034 lhsval
= TREE_OPERAND (lhsval
, 1);
8035 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8036 mark_exp_read (lhsval
);
8037 next
= c_parser_expr_no_commas (parser
, NULL
);
8038 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8039 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8040 expr
.original_code
= COMPOUND_EXPR
;
8041 expr
.original_type
= next
.original_type
;
8046 /* Parse an expression and convert functions or arrays to pointers and
8047 lvalues to rvalues. */
8049 static struct c_expr
8050 c_parser_expression_conv (c_parser
*parser
)
8053 location_t loc
= c_parser_peek_token (parser
)->location
;
8054 expr
= c_parser_expression (parser
);
8055 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8059 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8060 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8063 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8066 if (idx
>= HOST_BITS_PER_INT
)
8069 c_token
*tok
= c_parser_peek_token (parser
);
8077 /* If a parameter is literal zero alone, remember it
8078 for -Wmemset-transposed-args warning. */
8079 if (integer_zerop (tok
->value
)
8080 && !TREE_OVERFLOW (tok
->value
)
8081 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8082 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8083 *literal_zero_mask
|= 1U << idx
;
8089 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8090 functions and arrays to pointers and lvalues to rvalues. If
8091 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8092 locations of function arguments into this vector.
8095 assignment-expression
8096 nonempty-expr-list , assignment-expression
8099 static vec
<tree
, va_gc
> *
8100 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8101 vec
<tree
, va_gc
> **p_orig_types
,
8102 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8103 vec
<location_t
> *locations
,
8104 unsigned int *literal_zero_mask
)
8106 vec
<tree
, va_gc
> *ret
;
8107 vec
<tree
, va_gc
> *orig_types
;
8109 location_t loc
= c_parser_peek_token (parser
)->location
;
8110 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8111 unsigned int idx
= 0;
8113 ret
= make_tree_vector ();
8114 if (p_orig_types
== NULL
)
8117 orig_types
= make_tree_vector ();
8119 if (sizeof_arg
!= NULL
8120 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8121 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8122 if (literal_zero_mask
)
8123 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8124 expr
= c_parser_expr_no_commas (parser
, NULL
);
8126 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8128 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8129 ret
->quick_push (expr
.value
);
8131 orig_types
->quick_push (expr
.original_type
);
8133 locations
->safe_push (loc
);
8134 if (sizeof_arg
!= NULL
8135 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8136 && expr
.original_code
== SIZEOF_EXPR
)
8138 sizeof_arg
[0] = c_last_sizeof_arg
;
8139 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8141 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8143 c_parser_consume_token (parser
);
8144 loc
= c_parser_peek_token (parser
)->location
;
8145 if (sizeof_arg
!= NULL
8146 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8147 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8149 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8150 if (literal_zero_mask
)
8151 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8152 expr
= c_parser_expr_no_commas (parser
, NULL
);
8154 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8156 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8157 vec_safe_push (ret
, expr
.value
);
8159 vec_safe_push (orig_types
, expr
.original_type
);
8161 locations
->safe_push (loc
);
8163 && sizeof_arg
!= NULL
8164 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8165 && expr
.original_code
== SIZEOF_EXPR
)
8167 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8168 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8172 *p_orig_types
= orig_types
;
8176 /* Parse Objective-C-specific constructs. */
8178 /* Parse an objc-class-definition.
8180 objc-class-definition:
8181 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8182 objc-class-instance-variables[opt] objc-methodprotolist @end
8183 @implementation identifier objc-superclass[opt]
8184 objc-class-instance-variables[opt]
8185 @interface identifier ( identifier ) objc-protocol-refs[opt]
8186 objc-methodprotolist @end
8187 @interface identifier ( ) objc-protocol-refs[opt]
8188 objc-methodprotolist @end
8189 @implementation identifier ( identifier )
8194 "@interface identifier (" must start "@interface identifier (
8195 identifier ) ...": objc-methodprotolist in the first production may
8196 not start with a parenthesized identifier as a declarator of a data
8197 definition with no declaration specifiers if the objc-superclass,
8198 objc-protocol-refs and objc-class-instance-variables are omitted. */
8201 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8206 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8208 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8213 c_parser_consume_token (parser
);
8214 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8216 c_parser_error (parser
, "expected identifier");
8219 id1
= c_parser_peek_token (parser
)->value
;
8220 c_parser_consume_token (parser
);
8221 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8223 /* We have a category or class extension. */
8225 tree proto
= NULL_TREE
;
8226 c_parser_consume_token (parser
);
8227 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8229 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8231 /* We have a class extension. */
8236 c_parser_error (parser
, "expected identifier or %<)%>");
8237 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8243 id2
= c_parser_peek_token (parser
)->value
;
8244 c_parser_consume_token (parser
);
8246 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8249 objc_start_category_implementation (id1
, id2
);
8252 if (c_parser_next_token_is (parser
, CPP_LESS
))
8253 proto
= c_parser_objc_protocol_refs (parser
);
8254 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8255 c_parser_objc_methodprotolist (parser
);
8256 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8257 objc_finish_interface ();
8260 if (c_parser_next_token_is (parser
, CPP_COLON
))
8262 c_parser_consume_token (parser
);
8263 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8265 c_parser_error (parser
, "expected identifier");
8268 superclass
= c_parser_peek_token (parser
)->value
;
8269 c_parser_consume_token (parser
);
8272 superclass
= NULL_TREE
;
8275 tree proto
= NULL_TREE
;
8276 if (c_parser_next_token_is (parser
, CPP_LESS
))
8277 proto
= c_parser_objc_protocol_refs (parser
);
8278 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8281 objc_start_class_implementation (id1
, superclass
);
8282 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8283 c_parser_objc_class_instance_variables (parser
);
8286 objc_continue_interface ();
8287 c_parser_objc_methodprotolist (parser
);
8288 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8289 objc_finish_interface ();
8293 objc_continue_implementation ();
8298 /* Parse objc-class-instance-variables.
8300 objc-class-instance-variables:
8301 { objc-instance-variable-decl-list[opt] }
8303 objc-instance-variable-decl-list:
8304 objc-visibility-spec
8305 objc-instance-variable-decl ;
8307 objc-instance-variable-decl-list objc-visibility-spec
8308 objc-instance-variable-decl-list objc-instance-variable-decl ;
8309 objc-instance-variable-decl-list ;
8311 objc-visibility-spec:
8316 objc-instance-variable-decl:
8321 c_parser_objc_class_instance_variables (c_parser
*parser
)
8323 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8324 c_parser_consume_token (parser
);
8325 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8328 /* Parse any stray semicolon. */
8329 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8331 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8333 c_parser_consume_token (parser
);
8336 /* Stop if at the end of the instance variables. */
8337 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8339 c_parser_consume_token (parser
);
8342 /* Parse any objc-visibility-spec. */
8343 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8345 c_parser_consume_token (parser
);
8346 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8349 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8351 c_parser_consume_token (parser
);
8352 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8355 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8357 c_parser_consume_token (parser
);
8358 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8361 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8363 c_parser_consume_token (parser
);
8364 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8367 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8369 c_parser_pragma (parser
, pragma_external
);
8373 /* Parse some comma-separated declarations. */
8374 decls
= c_parser_struct_declaration (parser
);
8377 /* There is a syntax error. We want to skip the offending
8378 tokens up to the next ';' (included) or '}'
8381 /* First, skip manually a ')' or ']'. This is because they
8382 reduce the nesting level, so c_parser_skip_until_found()
8383 wouldn't be able to skip past them. */
8384 c_token
*token
= c_parser_peek_token (parser
);
8385 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8386 c_parser_consume_token (parser
);
8388 /* Then, do the standard skipping. */
8389 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8391 /* We hopefully recovered. Start normal parsing again. */
8392 parser
->error
= false;
8397 /* Comma-separated instance variables are chained together
8398 in reverse order; add them one by one. */
8399 tree ivar
= nreverse (decls
);
8400 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8401 objc_add_instance_variable (copy_node (ivar
));
8403 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8407 /* Parse an objc-class-declaration.
8409 objc-class-declaration:
8410 @class identifier-list ;
8414 c_parser_objc_class_declaration (c_parser
*parser
)
8416 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8417 c_parser_consume_token (parser
);
8418 /* Any identifiers, including those declared as type names, are OK
8423 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8425 c_parser_error (parser
, "expected identifier");
8426 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8427 parser
->error
= false;
8430 id
= c_parser_peek_token (parser
)->value
;
8431 objc_declare_class (id
);
8432 c_parser_consume_token (parser
);
8433 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8434 c_parser_consume_token (parser
);
8438 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8441 /* Parse an objc-alias-declaration.
8443 objc-alias-declaration:
8444 @compatibility_alias identifier identifier ;
8448 c_parser_objc_alias_declaration (c_parser
*parser
)
8451 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8452 c_parser_consume_token (parser
);
8453 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8455 c_parser_error (parser
, "expected identifier");
8456 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8459 id1
= c_parser_peek_token (parser
)->value
;
8460 c_parser_consume_token (parser
);
8461 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8463 c_parser_error (parser
, "expected identifier");
8464 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8467 id2
= c_parser_peek_token (parser
)->value
;
8468 c_parser_consume_token (parser
);
8469 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8470 objc_declare_alias (id1
, id2
);
8473 /* Parse an objc-protocol-definition.
8475 objc-protocol-definition:
8476 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8477 @protocol identifier-list ;
8479 "@protocol identifier ;" should be resolved as "@protocol
8480 identifier-list ;": objc-methodprotolist may not start with a
8481 semicolon in the first alternative if objc-protocol-refs are
8485 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8487 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8489 c_parser_consume_token (parser
);
8490 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8492 c_parser_error (parser
, "expected identifier");
8495 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8496 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8498 /* Any identifiers, including those declared as type names, are
8503 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8505 c_parser_error (parser
, "expected identifier");
8508 id
= c_parser_peek_token (parser
)->value
;
8509 objc_declare_protocol (id
, attributes
);
8510 c_parser_consume_token (parser
);
8511 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8512 c_parser_consume_token (parser
);
8516 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8520 tree id
= c_parser_peek_token (parser
)->value
;
8521 tree proto
= NULL_TREE
;
8522 c_parser_consume_token (parser
);
8523 if (c_parser_next_token_is (parser
, CPP_LESS
))
8524 proto
= c_parser_objc_protocol_refs (parser
);
8525 parser
->objc_pq_context
= true;
8526 objc_start_protocol (id
, proto
, attributes
);
8527 c_parser_objc_methodprotolist (parser
);
8528 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8529 parser
->objc_pq_context
= false;
8530 objc_finish_interface ();
8534 /* Parse an objc-method-type.
8540 Return true if it is a class method (+) and false if it is
8541 an instance method (-).
8544 c_parser_objc_method_type (c_parser
*parser
)
8546 switch (c_parser_peek_token (parser
)->type
)
8549 c_parser_consume_token (parser
);
8552 c_parser_consume_token (parser
);
8559 /* Parse an objc-method-definition.
8561 objc-method-definition:
8562 objc-method-type objc-method-decl ;[opt] compound-statement
8566 c_parser_objc_method_definition (c_parser
*parser
)
8568 bool is_class_method
= c_parser_objc_method_type (parser
);
8569 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8570 parser
->objc_pq_context
= true;
8571 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8573 if (decl
== error_mark_node
)
8574 return; /* Bail here. */
8576 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8578 c_parser_consume_token (parser
);
8579 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8580 "extra semicolon in method definition specified");
8583 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8585 c_parser_error (parser
, "expected %<{%>");
8589 parser
->objc_pq_context
= false;
8590 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8592 add_stmt (c_parser_compound_statement (parser
));
8593 objc_finish_method_definition (current_function_decl
);
8597 /* This code is executed when we find a method definition
8598 outside of an @implementation context (or invalid for other
8599 reasons). Parse the method (to keep going) but do not emit
8602 c_parser_compound_statement (parser
);
8606 /* Parse an objc-methodprotolist.
8608 objc-methodprotolist:
8610 objc-methodprotolist objc-methodproto
8611 objc-methodprotolist declaration
8612 objc-methodprotolist ;
8616 The declaration is a data definition, which may be missing
8617 declaration specifiers under the same rules and diagnostics as
8618 other data definitions outside functions, and the stray semicolon
8619 is diagnosed the same way as a stray semicolon outside a
8623 c_parser_objc_methodprotolist (c_parser
*parser
)
8627 /* The list is terminated by @end. */
8628 switch (c_parser_peek_token (parser
)->type
)
8631 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8632 "ISO C does not allow extra %<;%> outside of a function");
8633 c_parser_consume_token (parser
);
8637 c_parser_objc_methodproto (parser
);
8640 c_parser_pragma (parser
, pragma_external
);
8645 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8647 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8648 c_parser_objc_at_property_declaration (parser
);
8649 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8651 objc_set_method_opt (true);
8652 c_parser_consume_token (parser
);
8654 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8656 objc_set_method_opt (false);
8657 c_parser_consume_token (parser
);
8660 c_parser_declaration_or_fndef (parser
, false, false, true,
8661 false, true, NULL
, vNULL
);
8667 /* Parse an objc-methodproto.
8670 objc-method-type objc-method-decl ;
8674 c_parser_objc_methodproto (c_parser
*parser
)
8676 bool is_class_method
= c_parser_objc_method_type (parser
);
8677 tree decl
, attributes
= NULL_TREE
;
8679 /* Remember protocol qualifiers in prototypes. */
8680 parser
->objc_pq_context
= true;
8681 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8683 /* Forget protocol qualifiers now. */
8684 parser
->objc_pq_context
= false;
8686 /* Do not allow the presence of attributes to hide an erroneous
8687 method implementation in the interface section. */
8688 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8690 c_parser_error (parser
, "expected %<;%>");
8694 if (decl
!= error_mark_node
)
8695 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8697 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8700 /* If we are at a position that method attributes may be present, check that
8701 there are not any parsed already (a syntax error) and then collect any
8702 specified at the current location. Finally, if new attributes were present,
8703 check that the next token is legal ( ';' for decls and '{' for defs). */
8706 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8711 c_parser_error (parser
,
8712 "method attributes must be specified at the end only");
8713 *attributes
= NULL_TREE
;
8717 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8718 *attributes
= c_parser_attributes (parser
);
8720 /* If there were no attributes here, just report any earlier error. */
8721 if (*attributes
== NULL_TREE
|| bad
)
8724 /* If the attributes are followed by a ; or {, then just report any earlier
8726 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8727 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8730 /* We've got attributes, but not at the end. */
8731 c_parser_error (parser
,
8732 "expected %<;%> or %<{%> after method attribute definition");
8736 /* Parse an objc-method-decl.
8739 ( objc-type-name ) objc-selector
8741 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8742 objc-keyword-selector objc-optparmlist
8745 objc-keyword-selector:
8747 objc-keyword-selector objc-keyword-decl
8750 objc-selector : ( objc-type-name ) identifier
8751 objc-selector : identifier
8752 : ( objc-type-name ) identifier
8756 objc-optparms objc-optellipsis
8760 objc-opt-parms , parameter-declaration
8768 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8769 tree
*attributes
, tree
*expr
)
8771 tree type
= NULL_TREE
;
8773 tree parms
= NULL_TREE
;
8774 bool ellipsis
= false;
8775 bool attr_err
= false;
8777 *attributes
= NULL_TREE
;
8778 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8780 c_parser_consume_token (parser
);
8781 type
= c_parser_objc_type_name (parser
);
8782 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8784 sel
= c_parser_objc_selector (parser
);
8785 /* If there is no selector, or a colon follows, we have an
8786 objc-keyword-selector. If there is a selector, and a colon does
8787 not follow, that selector ends the objc-method-decl. */
8788 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8791 tree list
= NULL_TREE
;
8794 tree atype
= NULL_TREE
, id
, keyworddecl
;
8795 tree param_attr
= NULL_TREE
;
8796 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8798 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8800 c_parser_consume_token (parser
);
8801 atype
= c_parser_objc_type_name (parser
);
8802 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8805 /* New ObjC allows attributes on method parameters. */
8806 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8807 param_attr
= c_parser_attributes (parser
);
8808 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8810 c_parser_error (parser
, "expected identifier");
8811 return error_mark_node
;
8813 id
= c_parser_peek_token (parser
)->value
;
8814 c_parser_consume_token (parser
);
8815 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8816 list
= chainon (list
, keyworddecl
);
8817 tsel
= c_parser_objc_selector (parser
);
8818 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8822 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8824 /* Parse the optional parameter list. Optional Objective-C
8825 method parameters follow the C syntax, and may include '...'
8826 to denote a variable number of arguments. */
8827 parms
= make_node (TREE_LIST
);
8828 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8830 struct c_parm
*parm
;
8831 c_parser_consume_token (parser
);
8832 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8835 c_parser_consume_token (parser
);
8836 attr_err
|= c_parser_objc_maybe_method_attributes
8837 (parser
, attributes
) ;
8840 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8843 parms
= chainon (parms
,
8844 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8849 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8853 c_parser_error (parser
, "objective-c method declaration is expected");
8854 return error_mark_node
;
8858 return error_mark_node
;
8860 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8863 /* Parse an objc-type-name.
8866 objc-type-qualifiers[opt] type-name
8867 objc-type-qualifiers[opt]
8869 objc-type-qualifiers:
8871 objc-type-qualifiers objc-type-qualifier
8873 objc-type-qualifier: one of
8874 in out inout bycopy byref oneway
8878 c_parser_objc_type_name (c_parser
*parser
)
8880 tree quals
= NULL_TREE
;
8881 struct c_type_name
*type_name
= NULL
;
8882 tree type
= NULL_TREE
;
8885 c_token
*token
= c_parser_peek_token (parser
);
8886 if (token
->type
== CPP_KEYWORD
8887 && (token
->keyword
== RID_IN
8888 || token
->keyword
== RID_OUT
8889 || token
->keyword
== RID_INOUT
8890 || token
->keyword
== RID_BYCOPY
8891 || token
->keyword
== RID_BYREF
8892 || token
->keyword
== RID_ONEWAY
))
8894 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8895 c_parser_consume_token (parser
);
8900 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8901 type_name
= c_parser_type_name (parser
);
8903 type
= groktypename (type_name
, NULL
, NULL
);
8905 /* If the type is unknown, and error has already been produced and
8906 we need to recover from the error. In that case, use NULL_TREE
8907 for the type, as if no type had been specified; this will use the
8908 default type ('id') which is good for error recovery. */
8909 if (type
== error_mark_node
)
8912 return build_tree_list (quals
, type
);
8915 /* Parse objc-protocol-refs.
8922 c_parser_objc_protocol_refs (c_parser
*parser
)
8924 tree list
= NULL_TREE
;
8925 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8926 c_parser_consume_token (parser
);
8927 /* Any identifiers, including those declared as type names, are OK
8932 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8934 c_parser_error (parser
, "expected identifier");
8937 id
= c_parser_peek_token (parser
)->value
;
8938 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8939 c_parser_consume_token (parser
);
8940 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8941 c_parser_consume_token (parser
);
8945 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8949 /* Parse an objc-try-catch-finally-statement.
8951 objc-try-catch-finally-statement:
8952 @try compound-statement objc-catch-list[opt]
8953 @try compound-statement objc-catch-list[opt] @finally compound-statement
8956 @catch ( objc-catch-parameter-declaration ) compound-statement
8957 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8959 objc-catch-parameter-declaration:
8960 parameter-declaration
8963 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8965 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8966 for C++. Keep them in sync. */
8969 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8971 location_t location
;
8974 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8975 c_parser_consume_token (parser
);
8976 location
= c_parser_peek_token (parser
)->location
;
8977 objc_maybe_warn_exceptions (location
);
8978 stmt
= c_parser_compound_statement (parser
);
8979 objc_begin_try_stmt (location
, stmt
);
8981 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8983 struct c_parm
*parm
;
8984 tree parameter_declaration
= error_mark_node
;
8985 bool seen_open_paren
= false;
8987 c_parser_consume_token (parser
);
8988 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8989 seen_open_paren
= true;
8990 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8992 /* We have "@catch (...)" (where the '...' are literally
8993 what is in the code). Skip the '...'.
8994 parameter_declaration is set to NULL_TREE, and
8995 objc_being_catch_clauses() knows that that means
8997 c_parser_consume_token (parser
);
8998 parameter_declaration
= NULL_TREE
;
9002 /* We have "@catch (NSException *exception)" or something
9003 like that. Parse the parameter declaration. */
9004 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9006 parameter_declaration
= error_mark_node
;
9008 parameter_declaration
= grokparm (parm
, NULL
);
9010 if (seen_open_paren
)
9011 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9014 /* If there was no open parenthesis, we are recovering from
9015 an error, and we are trying to figure out what mistake
9016 the user has made. */
9018 /* If there is an immediate closing parenthesis, the user
9019 probably forgot the opening one (ie, they typed "@catch
9020 NSException *e)". Parse the closing parenthesis and keep
9022 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9023 c_parser_consume_token (parser
);
9025 /* If these is no immediate closing parenthesis, the user
9026 probably doesn't know that parenthesis are required at
9027 all (ie, they typed "@catch NSException *e"). So, just
9028 forget about the closing parenthesis and keep going. */
9030 objc_begin_catch_clause (parameter_declaration
);
9031 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9032 c_parser_compound_statement_nostart (parser
);
9033 objc_finish_catch_clause ();
9035 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9037 c_parser_consume_token (parser
);
9038 location
= c_parser_peek_token (parser
)->location
;
9039 stmt
= c_parser_compound_statement (parser
);
9040 objc_build_finally_clause (location
, stmt
);
9042 objc_finish_try_stmt ();
9045 /* Parse an objc-synchronized-statement.
9047 objc-synchronized-statement:
9048 @synchronized ( expression ) compound-statement
9052 c_parser_objc_synchronized_statement (c_parser
*parser
)
9056 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9057 c_parser_consume_token (parser
);
9058 loc
= c_parser_peek_token (parser
)->location
;
9059 objc_maybe_warn_exceptions (loc
);
9060 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9062 struct c_expr ce
= c_parser_expression (parser
);
9063 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9065 expr
= c_fully_fold (expr
, false, NULL
);
9066 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9069 expr
= error_mark_node
;
9070 stmt
= c_parser_compound_statement (parser
);
9071 objc_build_synchronized (loc
, expr
, stmt
);
9074 /* Parse an objc-selector; return NULL_TREE without an error if the
9075 next token is not an objc-selector.
9080 enum struct union if else while do for switch case default
9081 break continue return goto asm sizeof typeof __alignof
9082 unsigned long const short volatile signed restrict _Complex
9083 in out inout bycopy byref oneway int char float double void _Bool
9086 ??? Why this selection of keywords but not, for example, storage
9087 class specifiers? */
9090 c_parser_objc_selector (c_parser
*parser
)
9092 c_token
*token
= c_parser_peek_token (parser
);
9093 tree value
= token
->value
;
9094 if (token
->type
== CPP_NAME
)
9096 c_parser_consume_token (parser
);
9099 if (token
->type
!= CPP_KEYWORD
)
9101 switch (token
->keyword
)
9148 c_parser_consume_token (parser
);
9155 /* Parse an objc-selector-arg.
9159 objc-keywordname-list
9161 objc-keywordname-list:
9163 objc-keywordname-list objc-keywordname
9171 c_parser_objc_selector_arg (c_parser
*parser
)
9173 tree sel
= c_parser_objc_selector (parser
);
9174 tree list
= NULL_TREE
;
9175 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9179 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9181 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9182 sel
= c_parser_objc_selector (parser
);
9183 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9189 /* Parse an objc-receiver.
9198 c_parser_objc_receiver (c_parser
*parser
)
9200 location_t loc
= c_parser_peek_token (parser
)->location
;
9202 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9203 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9204 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9206 tree id
= c_parser_peek_token (parser
)->value
;
9207 c_parser_consume_token (parser
);
9208 return objc_get_class_reference (id
);
9210 struct c_expr ce
= c_parser_expression (parser
);
9211 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9212 return c_fully_fold (ce
.value
, false, NULL
);
9215 /* Parse objc-message-args.
9219 objc-keywordarg-list
9221 objc-keywordarg-list:
9223 objc-keywordarg-list objc-keywordarg
9226 objc-selector : objc-keywordexpr
9231 c_parser_objc_message_args (c_parser
*parser
)
9233 tree sel
= c_parser_objc_selector (parser
);
9234 tree list
= NULL_TREE
;
9235 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9240 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9241 return error_mark_node
;
9242 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9243 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9244 sel
= c_parser_objc_selector (parser
);
9245 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9251 /* Parse an objc-keywordexpr.
9258 c_parser_objc_keywordexpr (c_parser
*parser
)
9261 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9262 NULL
, NULL
, NULL
, NULL
);
9263 if (vec_safe_length (expr_list
) == 1)
9265 /* Just return the expression, remove a level of
9267 ret
= (*expr_list
)[0];
9271 /* We have a comma expression, we will collapse later. */
9272 ret
= build_tree_list_vec (expr_list
);
9274 release_tree_vector (expr_list
);
9278 /* A check, needed in several places, that ObjC interface, implementation or
9279 method definitions are not prefixed by incorrect items. */
9281 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9282 struct c_declspecs
*specs
)
9284 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9285 || specs
->typespec_kind
!= ctsk_none
)
9287 c_parser_error (parser
,
9288 "no type or storage class may be specified here,");
9289 c_parser_skip_to_end_of_block_or_statement (parser
);
9295 /* Parse an Objective-C @property declaration. The syntax is:
9297 objc-property-declaration:
9298 '@property' objc-property-attributes[opt] struct-declaration ;
9300 objc-property-attributes:
9301 '(' objc-property-attribute-list ')'
9303 objc-property-attribute-list:
9304 objc-property-attribute
9305 objc-property-attribute-list, objc-property-attribute
9307 objc-property-attribute
9308 'getter' = identifier
9309 'setter' = identifier
9318 @property NSString *name;
9319 @property (readonly) id object;
9320 @property (retain, nonatomic, getter=getTheName) id name;
9321 @property int a, b, c;
9323 PS: This function is identical to cp_parser_objc_at_propery_declaration
9324 for C++. Keep them in sync. */
9326 c_parser_objc_at_property_declaration (c_parser
*parser
)
9328 /* The following variables hold the attributes of the properties as
9329 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9330 seen. When we see an attribute, we set them to 'true' (if they
9331 are boolean properties) or to the identifier (if they have an
9332 argument, ie, for getter and setter). Note that here we only
9333 parse the list of attributes, check the syntax and accumulate the
9334 attributes that we find. objc_add_property_declaration() will
9335 then process the information. */
9336 bool property_assign
= false;
9337 bool property_copy
= false;
9338 tree property_getter_ident
= NULL_TREE
;
9339 bool property_nonatomic
= false;
9340 bool property_readonly
= false;
9341 bool property_readwrite
= false;
9342 bool property_retain
= false;
9343 tree property_setter_ident
= NULL_TREE
;
9345 /* 'properties' is the list of properties that we read. Usually a
9346 single one, but maybe more (eg, in "@property int a, b, c;" there
9351 loc
= c_parser_peek_token (parser
)->location
;
9352 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9354 c_parser_consume_token (parser
); /* Eat '@property'. */
9356 /* Parse the optional attribute list... */
9357 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9360 c_parser_consume_token (parser
);
9362 /* Property attribute keywords are valid now. */
9363 parser
->objc_property_attr_context
= true;
9367 bool syntax_error
= false;
9368 c_token
*token
= c_parser_peek_token (parser
);
9371 if (token
->type
!= CPP_KEYWORD
)
9373 if (token
->type
== CPP_CLOSE_PAREN
)
9374 c_parser_error (parser
, "expected identifier");
9377 c_parser_consume_token (parser
);
9378 c_parser_error (parser
, "unknown property attribute");
9382 keyword
= token
->keyword
;
9383 c_parser_consume_token (parser
);
9386 case RID_ASSIGN
: property_assign
= true; break;
9387 case RID_COPY
: property_copy
= true; break;
9388 case RID_NONATOMIC
: property_nonatomic
= true; break;
9389 case RID_READONLY
: property_readonly
= true; break;
9390 case RID_READWRITE
: property_readwrite
= true; break;
9391 case RID_RETAIN
: property_retain
= true; break;
9395 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9397 if (keyword
== RID_GETTER
)
9398 c_parser_error (parser
,
9399 "missing %<=%> (after %<getter%> attribute)");
9401 c_parser_error (parser
,
9402 "missing %<=%> (after %<setter%> attribute)");
9403 syntax_error
= true;
9406 c_parser_consume_token (parser
); /* eat the = */
9407 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9409 c_parser_error (parser
, "expected identifier");
9410 syntax_error
= true;
9413 if (keyword
== RID_SETTER
)
9415 if (property_setter_ident
!= NULL_TREE
)
9416 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9418 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9419 c_parser_consume_token (parser
);
9420 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9421 c_parser_error (parser
, "setter name must terminate with %<:%>");
9423 c_parser_consume_token (parser
);
9427 if (property_getter_ident
!= NULL_TREE
)
9428 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9430 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9431 c_parser_consume_token (parser
);
9435 c_parser_error (parser
, "unknown property attribute");
9436 syntax_error
= true;
9443 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9444 c_parser_consume_token (parser
);
9448 parser
->objc_property_attr_context
= false;
9449 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9451 /* ... and the property declaration(s). */
9452 properties
= c_parser_struct_declaration (parser
);
9454 if (properties
== error_mark_node
)
9456 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9457 parser
->error
= false;
9461 if (properties
== NULL_TREE
)
9462 c_parser_error (parser
, "expected identifier");
9465 /* Comma-separated properties are chained together in
9466 reverse order; add them one by one. */
9467 properties
= nreverse (properties
);
9469 for (; properties
; properties
= TREE_CHAIN (properties
))
9470 objc_add_property_declaration (loc
, copy_node (properties
),
9471 property_readonly
, property_readwrite
,
9472 property_assign
, property_retain
,
9473 property_copy
, property_nonatomic
,
9474 property_getter_ident
, property_setter_ident
);
9477 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9478 parser
->error
= false;
9481 /* Parse an Objective-C @synthesize declaration. The syntax is:
9483 objc-synthesize-declaration:
9484 @synthesize objc-synthesize-identifier-list ;
9486 objc-synthesize-identifier-list:
9487 objc-synthesize-identifier
9488 objc-synthesize-identifier-list, objc-synthesize-identifier
9490 objc-synthesize-identifier
9492 identifier = identifier
9495 @synthesize MyProperty;
9496 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9498 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9499 for C++. Keep them in sync.
9502 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9504 tree list
= NULL_TREE
;
9506 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9507 loc
= c_parser_peek_token (parser
)->location
;
9509 c_parser_consume_token (parser
);
9512 tree property
, ivar
;
9513 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9515 c_parser_error (parser
, "expected identifier");
9516 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9517 /* Once we find the semicolon, we can resume normal parsing.
9518 We have to reset parser->error manually because
9519 c_parser_skip_until_found() won't reset it for us if the
9520 next token is precisely a semicolon. */
9521 parser
->error
= false;
9524 property
= c_parser_peek_token (parser
)->value
;
9525 c_parser_consume_token (parser
);
9526 if (c_parser_next_token_is (parser
, CPP_EQ
))
9528 c_parser_consume_token (parser
);
9529 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9531 c_parser_error (parser
, "expected identifier");
9532 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9533 parser
->error
= false;
9536 ivar
= c_parser_peek_token (parser
)->value
;
9537 c_parser_consume_token (parser
);
9541 list
= chainon (list
, build_tree_list (ivar
, property
));
9542 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9543 c_parser_consume_token (parser
);
9547 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9548 objc_add_synthesize_declaration (loc
, list
);
9551 /* Parse an Objective-C @dynamic declaration. The syntax is:
9553 objc-dynamic-declaration:
9554 @dynamic identifier-list ;
9557 @dynamic MyProperty;
9558 @dynamic MyProperty, AnotherProperty;
9560 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9561 for C++. Keep them in sync.
9564 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9566 tree list
= NULL_TREE
;
9568 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9569 loc
= c_parser_peek_token (parser
)->location
;
9571 c_parser_consume_token (parser
);
9575 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9577 c_parser_error (parser
, "expected identifier");
9578 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9579 parser
->error
= false;
9582 property
= c_parser_peek_token (parser
)->value
;
9583 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9584 c_parser_consume_token (parser
);
9585 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9586 c_parser_consume_token (parser
);
9590 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9591 objc_add_dynamic_declaration (loc
, list
);
9595 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9596 should be considered, statements. ALLOW_STMT is true if we're within
9597 the context of a function and such pragmas are to be allowed. Returns
9598 true if we actually parsed such a pragma. */
9601 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9605 id
= c_parser_peek_token (parser
)->pragma_kind
;
9606 gcc_assert (id
!= PRAGMA_NONE
);
9610 case PRAGMA_OACC_ENTER_DATA
:
9611 c_parser_oacc_enter_exit_data (parser
, true);
9614 case PRAGMA_OACC_EXIT_DATA
:
9615 c_parser_oacc_enter_exit_data (parser
, false);
9618 case PRAGMA_OACC_UPDATE
:
9619 if (context
!= pragma_compound
)
9621 if (context
== pragma_stmt
)
9622 c_parser_error (parser
, "%<#pragma acc update%> may only be "
9623 "used in compound statements");
9626 c_parser_oacc_update (parser
);
9629 case PRAGMA_OMP_BARRIER
:
9630 if (context
!= pragma_compound
)
9632 if (context
== pragma_stmt
)
9633 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9634 "used in compound statements");
9637 c_parser_omp_barrier (parser
);
9640 case PRAGMA_OMP_FLUSH
:
9641 if (context
!= pragma_compound
)
9643 if (context
== pragma_stmt
)
9644 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9645 "used in compound statements");
9648 c_parser_omp_flush (parser
);
9651 case PRAGMA_OMP_TASKWAIT
:
9652 if (context
!= pragma_compound
)
9654 if (context
== pragma_stmt
)
9655 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9656 "used in compound statements");
9659 c_parser_omp_taskwait (parser
);
9662 case PRAGMA_OMP_TASKYIELD
:
9663 if (context
!= pragma_compound
)
9665 if (context
== pragma_stmt
)
9666 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9667 "used in compound statements");
9670 c_parser_omp_taskyield (parser
);
9673 case PRAGMA_OMP_CANCEL
:
9674 if (context
!= pragma_compound
)
9676 if (context
== pragma_stmt
)
9677 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9678 "used in compound statements");
9681 c_parser_omp_cancel (parser
);
9684 case PRAGMA_OMP_CANCELLATION_POINT
:
9685 if (context
!= pragma_compound
)
9687 if (context
== pragma_stmt
)
9688 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9689 "only be used in compound statements");
9692 c_parser_omp_cancellation_point (parser
);
9695 case PRAGMA_OMP_THREADPRIVATE
:
9696 c_parser_omp_threadprivate (parser
);
9699 case PRAGMA_OMP_TARGET
:
9700 return c_parser_omp_target (parser
, context
);
9702 case PRAGMA_OMP_END_DECLARE_TARGET
:
9703 c_parser_omp_end_declare_target (parser
);
9706 case PRAGMA_OMP_SECTION
:
9707 error_at (c_parser_peek_token (parser
)->location
,
9708 "%<#pragma omp section%> may only be used in "
9709 "%<#pragma omp sections%> construct");
9710 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9713 case PRAGMA_OMP_DECLARE_REDUCTION
:
9714 c_parser_omp_declare (parser
, context
);
9717 c_parser_consume_pragma (parser
);
9718 c_parser_skip_to_pragma_eol (parser
);
9719 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9720 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9721 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9723 c_parser_error (parser
, "for, while or do statement expected");
9726 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9727 c_parser_for_statement (parser
, true);
9728 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9729 c_parser_while_statement (parser
, true);
9731 c_parser_do_statement (parser
, true);
9734 case PRAGMA_GCC_PCH_PREPROCESS
:
9735 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9736 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9739 case PRAGMA_CILK_SIMD
:
9740 if (!c_parser_cilk_verify_simd (parser
, context
))
9742 c_parser_consume_pragma (parser
);
9743 c_parser_cilk_simd (parser
);
9745 case PRAGMA_CILK_GRAINSIZE
:
9748 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9750 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9753 if (context
== pragma_external
)
9755 error_at (c_parser_peek_token (parser
)->location
,
9756 "%<#pragma grainsize%> must be inside a function");
9757 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9760 c_parser_cilk_grainsize (parser
);
9764 if (id
< PRAGMA_FIRST_EXTERNAL
)
9766 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9769 c_parser_error (parser
, "expected declaration specifiers");
9770 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9773 c_parser_omp_construct (parser
);
9779 c_parser_consume_pragma (parser
);
9780 c_invoke_pragma_handler (id
);
9782 /* Skip to EOL, but suppress any error message. Those will have been
9783 generated by the handler routine through calling error, as opposed
9784 to calling c_parser_error. */
9785 parser
->error
= true;
9786 c_parser_skip_to_pragma_eol (parser
);
9791 /* The interface the pragma parsers have to the lexer. */
9794 pragma_lex (tree
*value
)
9796 c_token
*tok
= c_parser_peek_token (the_parser
);
9797 enum cpp_ttype ret
= tok
->type
;
9799 *value
= tok
->value
;
9800 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9804 if (ret
== CPP_KEYWORD
)
9806 c_parser_consume_token (the_parser
);
9813 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9817 c_parser_consume_pragma (parser
);
9818 if (c_parser_next_token_is (parser
, CPP_STRING
))
9820 name
= c_parser_peek_token (parser
)->value
;
9821 c_parser_consume_token (parser
);
9824 c_parser_error (parser
, "expected string literal");
9825 c_parser_skip_to_pragma_eol (parser
);
9828 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9831 /* OpenACC and OpenMP parsing routines. */
9833 /* Returns name of the next clause.
9834 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9835 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9836 returned and the token is consumed. */
9838 static pragma_omp_clause
9839 c_parser_omp_clause_name (c_parser
*parser
)
9841 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9843 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9844 result
= PRAGMA_OACC_CLAUSE_AUTO
;
9845 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9846 result
= PRAGMA_OMP_CLAUSE_IF
;
9847 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9848 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9849 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9850 result
= PRAGMA_OMP_CLAUSE_FOR
;
9851 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9853 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9858 if (!strcmp ("aligned", p
))
9859 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9860 else if (!strcmp ("async", p
))
9861 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
9864 if (!strcmp ("collapse", p
))
9865 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9866 else if (!strcmp ("copy", p
))
9867 result
= PRAGMA_OACC_CLAUSE_COPY
;
9868 else if (!strcmp ("copyin", p
))
9869 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9870 else if (!strcmp ("copyout", p
))
9871 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
9872 else if (!strcmp ("copyprivate", p
))
9873 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9874 else if (!strcmp ("create", p
))
9875 result
= PRAGMA_OACC_CLAUSE_CREATE
;
9878 if (!strcmp ("delete", p
))
9879 result
= PRAGMA_OACC_CLAUSE_DELETE
;
9880 else if (!strcmp ("depend", p
))
9881 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9882 else if (!strcmp ("device", p
))
9883 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9884 else if (!strcmp ("deviceptr", p
))
9885 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
9886 else if (!strcmp ("dist_schedule", p
))
9887 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9890 if (!strcmp ("final", p
))
9891 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9892 else if (!strcmp ("firstprivate", p
))
9893 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9894 else if (!strcmp ("from", p
))
9895 result
= PRAGMA_OMP_CLAUSE_FROM
;
9898 if (!strcmp ("gang", p
))
9899 result
= PRAGMA_OACC_CLAUSE_GANG
;
9902 if (!strcmp ("host", p
))
9903 result
= PRAGMA_OACC_CLAUSE_HOST
;
9906 if (!strcmp ("inbranch", p
))
9907 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9910 if (!strcmp ("lastprivate", p
))
9911 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9912 else if (!strcmp ("linear", p
))
9913 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9916 if (!strcmp ("map", p
))
9917 result
= PRAGMA_OMP_CLAUSE_MAP
;
9918 else if (!strcmp ("mergeable", p
))
9919 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9920 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9921 result
= PRAGMA_CILK_CLAUSE_MASK
;
9924 if (!strcmp ("notinbranch", p
))
9925 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9926 else if (!strcmp ("nowait", p
))
9927 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9928 else if (!strcmp ("num_gangs", p
))
9929 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
9930 else if (!strcmp ("num_teams", p
))
9931 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9932 else if (!strcmp ("num_threads", p
))
9933 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9934 else if (!strcmp ("num_workers", p
))
9935 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
9936 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9937 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9940 if (!strcmp ("ordered", p
))
9941 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9944 if (!strcmp ("parallel", p
))
9945 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9946 else if (!strcmp ("present", p
))
9947 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
9948 else if (!strcmp ("present_or_copy", p
)
9949 || !strcmp ("pcopy", p
))
9950 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
9951 else if (!strcmp ("present_or_copyin", p
)
9952 || !strcmp ("pcopyin", p
))
9953 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
9954 else if (!strcmp ("present_or_copyout", p
)
9955 || !strcmp ("pcopyout", p
))
9956 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
9957 else if (!strcmp ("present_or_create", p
)
9958 || !strcmp ("pcreate", p
))
9959 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
9960 else if (!strcmp ("private", p
))
9961 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9962 else if (!strcmp ("proc_bind", p
))
9963 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9966 if (!strcmp ("reduction", p
))
9967 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9970 if (!strcmp ("safelen", p
))
9971 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9972 else if (!strcmp ("schedule", p
))
9973 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9974 else if (!strcmp ("sections", p
))
9975 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9976 else if (!strcmp ("seq", p
))
9977 result
= PRAGMA_OACC_CLAUSE_SEQ
;
9978 else if (!strcmp ("shared", p
))
9979 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9980 else if (!strcmp ("simdlen", p
))
9981 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9982 else if (!strcmp ("self", p
))
9983 result
= PRAGMA_OACC_CLAUSE_SELF
;
9986 if (!strcmp ("taskgroup", p
))
9987 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9988 else if (!strcmp ("thread_limit", p
))
9989 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9990 else if (!strcmp ("to", p
))
9991 result
= PRAGMA_OMP_CLAUSE_TO
;
9994 if (!strcmp ("uniform", p
))
9995 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9996 else if (!strcmp ("untied", p
))
9997 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10000 if (!strcmp ("vector", p
))
10001 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10002 else if (!strcmp ("vector_length", p
))
10003 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10004 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10005 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10008 if (!strcmp ("wait", p
))
10009 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10010 else if (!strcmp ("worker", p
))
10011 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10016 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10017 c_parser_consume_token (parser
);
10022 /* Validate that a clause of the given type does not already exist. */
10025 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10030 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10031 if (OMP_CLAUSE_CODE (c
) == code
)
10033 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10034 error_at (loc
, "too many %qs clauses", name
);
10040 Parse wait clause or wait directive parameters. */
10043 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10045 vec
<tree
, va_gc
> *args
;
10048 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10051 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10053 if (args
->length () == 0)
10055 c_parser_error (parser
, "expected integer expression before ')'");
10056 release_tree_vector (args
);
10060 args_tree
= build_tree_list_vec (args
);
10062 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10064 tree targ
= TREE_VALUE (t
);
10066 if (targ
!= error_mark_node
)
10068 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10070 c_parser_error (parser
, "expression must be integral");
10071 targ
= error_mark_node
;
10075 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10077 OMP_CLAUSE_DECL (c
) = targ
;
10078 OMP_CLAUSE_CHAIN (c
) = list
;
10084 release_tree_vector (args
);
10085 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10089 /* OpenACC 2.0, OpenMP 2.5:
10092 variable-list , identifier
10094 If KIND is nonzero, create the appropriate node and install the
10095 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10096 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10098 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10099 return the list created. */
10102 c_parser_omp_variable_list (c_parser
*parser
,
10103 location_t clause_loc
,
10104 enum omp_clause_code kind
, tree list
)
10106 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10107 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10108 c_parser_error (parser
, "expected identifier");
10110 while (c_parser_next_token_is (parser
, CPP_NAME
)
10111 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10113 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10115 if (t
== NULL_TREE
)
10117 undeclared_variable (c_parser_peek_token (parser
)->location
,
10118 c_parser_peek_token (parser
)->value
);
10119 t
= error_mark_node
;
10122 c_parser_consume_token (parser
);
10124 if (t
== error_mark_node
)
10126 else if (kind
!= 0)
10130 case OMP_CLAUSE__CACHE_
:
10131 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10133 c_parser_error (parser
, "expected %<[%>");
10134 t
= error_mark_node
;
10137 /* FALL THROUGH. */
10138 case OMP_CLAUSE_MAP
:
10139 case OMP_CLAUSE_FROM
:
10140 case OMP_CLAUSE_TO
:
10141 case OMP_CLAUSE_DEPEND
:
10142 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10144 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10146 c_parser_consume_token (parser
);
10147 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10149 low_bound
= c_parser_expression (parser
).value
;
10150 mark_exp_read (low_bound
);
10152 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10153 length
= integer_one_node
;
10156 /* Look for `:'. */
10157 if (!c_parser_require (parser
, CPP_COLON
,
10160 t
= error_mark_node
;
10163 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10165 length
= c_parser_expression (parser
).value
;
10166 mark_exp_read (length
);
10169 /* Look for the closing `]'. */
10170 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10173 t
= error_mark_node
;
10177 if (kind
== OMP_CLAUSE__CACHE_
)
10179 if (TREE_CODE (low_bound
) != INTEGER_CST
10180 && !TREE_READONLY (low_bound
))
10182 error_at (clause_loc
,
10183 "%qD is not a constant", low_bound
);
10184 t
= error_mark_node
;
10187 if (TREE_CODE (length
) != INTEGER_CST
10188 && !TREE_READONLY (length
))
10190 error_at (clause_loc
,
10191 "%qD is not a constant", length
);
10192 t
= error_mark_node
;
10196 t
= tree_cons (low_bound
, length
, t
);
10203 if (t
!= error_mark_node
)
10205 tree u
= build_omp_clause (clause_loc
, kind
);
10206 OMP_CLAUSE_DECL (u
) = t
;
10207 OMP_CLAUSE_CHAIN (u
) = list
;
10212 list
= tree_cons (t
, NULL_TREE
, list
);
10214 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10217 c_parser_consume_token (parser
);
10223 /* Similarly, but expect leading and trailing parenthesis. This is a very
10224 common case for OpenACC and OpenMP clauses. */
10227 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10230 /* The clauses location. */
10231 location_t loc
= c_parser_peek_token (parser
)->location
;
10233 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10235 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10236 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10242 copy ( variable-list )
10243 copyin ( variable-list )
10244 copyout ( variable-list )
10245 create ( variable-list )
10246 delete ( variable-list )
10247 present ( variable-list )
10248 present_or_copy ( variable-list )
10249 pcopy ( variable-list )
10250 present_or_copyin ( variable-list )
10251 pcopyin ( variable-list )
10252 present_or_copyout ( variable-list )
10253 pcopyout ( variable-list )
10254 present_or_create ( variable-list )
10255 pcreate ( variable-list ) */
10258 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10261 enum gomp_map_kind kind
;
10264 case PRAGMA_OACC_CLAUSE_COPY
:
10265 kind
= GOMP_MAP_FORCE_TOFROM
;
10267 case PRAGMA_OACC_CLAUSE_COPYIN
:
10268 kind
= GOMP_MAP_FORCE_TO
;
10270 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10271 kind
= GOMP_MAP_FORCE_FROM
;
10273 case PRAGMA_OACC_CLAUSE_CREATE
:
10274 kind
= GOMP_MAP_FORCE_ALLOC
;
10276 case PRAGMA_OACC_CLAUSE_DELETE
:
10277 kind
= GOMP_MAP_FORCE_DEALLOC
;
10279 case PRAGMA_OACC_CLAUSE_DEVICE
:
10280 kind
= GOMP_MAP_FORCE_TO
;
10282 case PRAGMA_OACC_CLAUSE_HOST
:
10283 case PRAGMA_OACC_CLAUSE_SELF
:
10284 kind
= GOMP_MAP_FORCE_FROM
;
10286 case PRAGMA_OACC_CLAUSE_PRESENT
:
10287 kind
= GOMP_MAP_FORCE_PRESENT
;
10289 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10290 kind
= GOMP_MAP_TOFROM
;
10292 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10293 kind
= GOMP_MAP_TO
;
10295 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10296 kind
= GOMP_MAP_FROM
;
10298 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10299 kind
= GOMP_MAP_ALLOC
;
10302 gcc_unreachable ();
10305 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10307 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10308 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10314 deviceptr ( variable-list ) */
10317 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10319 location_t loc
= c_parser_peek_token (parser
)->location
;
10322 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10323 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10324 variable-list must only allow for pointer variables. */
10325 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10326 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10328 tree v
= TREE_PURPOSE (t
);
10330 /* FIXME diagnostics: Ideally we should keep individual
10331 locations for all the variables in the var list to make the
10332 following errors more precise. Perhaps
10333 c_parser_omp_var_list_parens() should construct a list of
10334 locations to go along with the var list. */
10336 if (TREE_CODE (v
) != VAR_DECL
)
10337 error_at (loc
, "%qD is not a variable", v
);
10338 else if (TREE_TYPE (v
) == error_mark_node
)
10340 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10341 error_at (loc
, "%qD is not a pointer variable", v
);
10343 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10344 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10345 OMP_CLAUSE_DECL (u
) = v
;
10346 OMP_CLAUSE_CHAIN (u
) = list
;
10353 /* OpenACC 2.0, OpenMP 3.0:
10354 collapse ( constant-expression ) */
10357 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10359 tree c
, num
= error_mark_node
;
10363 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10365 loc
= c_parser_peek_token (parser
)->location
;
10366 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10368 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10369 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10371 if (num
== error_mark_node
)
10373 mark_exp_read (num
);
10374 num
= c_fully_fold (num
, false, NULL
);
10375 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10376 || !tree_fits_shwi_p (num
)
10377 || (n
= tree_to_shwi (num
)) <= 0
10381 "collapse argument needs positive constant integer expression");
10384 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10385 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10386 OMP_CLAUSE_CHAIN (c
) = list
;
10391 copyin ( variable-list ) */
10394 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10396 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10400 copyprivate ( variable-list ) */
10403 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10405 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10409 default ( shared | none ) */
10412 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10414 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10415 location_t loc
= c_parser_peek_token (parser
)->location
;
10418 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10420 if (c_parser_next_token_is (parser
, CPP_NAME
))
10422 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10427 if (strcmp ("none", p
) != 0)
10429 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10433 if (strcmp ("shared", p
) != 0)
10435 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10442 c_parser_consume_token (parser
);
10447 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10449 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10451 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10454 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10455 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10456 OMP_CLAUSE_CHAIN (c
) = list
;
10457 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10463 firstprivate ( variable-list ) */
10466 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10468 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10472 final ( expression ) */
10475 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10477 location_t loc
= c_parser_peek_token (parser
)->location
;
10478 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10480 tree t
= c_parser_paren_condition (parser
);
10483 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10485 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10486 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10487 OMP_CLAUSE_CHAIN (c
) = list
;
10491 c_parser_error (parser
, "expected %<(%>");
10496 /* OpenACC, OpenMP 2.5:
10497 if ( expression ) */
10500 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10502 location_t loc
= c_parser_peek_token (parser
)->location
;
10503 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10505 tree t
= c_parser_paren_condition (parser
);
10508 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10510 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10511 OMP_CLAUSE_IF_EXPR (c
) = t
;
10512 OMP_CLAUSE_CHAIN (c
) = list
;
10516 c_parser_error (parser
, "expected %<(%>");
10522 lastprivate ( variable-list ) */
10525 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10527 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10534 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10538 /* FIXME: Should we allow duplicates? */
10539 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10541 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10542 OMP_CLAUSE_MERGEABLE
);
10543 OMP_CLAUSE_CHAIN (c
) = list
;
10552 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10555 location_t loc
= c_parser_peek_token (parser
)->location
;
10557 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10559 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10560 OMP_CLAUSE_CHAIN (c
) = list
;
10565 num_gangs ( expression ) */
10568 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
10570 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
10571 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10573 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10574 tree c
, t
= c_parser_expression (parser
).value
;
10576 t
= c_fully_fold (t
, false, NULL
);
10578 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10580 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10582 c_parser_error (parser
, "expected integer expression");
10586 /* Attempt to statically determine when the number isn't positive. */
10587 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10588 build_int_cst (TREE_TYPE (t
), 0));
10589 if (CAN_HAVE_LOCATION_P (c
))
10590 SET_EXPR_LOCATION (c
, expr_loc
);
10591 if (c
== boolean_true_node
)
10593 warning_at (expr_loc
, 0,
10594 "%<num_gangs%> value must be positive");
10595 t
= integer_one_node
;
10598 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
10600 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
10601 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
10602 OMP_CLAUSE_CHAIN (c
) = list
;
10610 num_threads ( expression ) */
10613 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10615 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10616 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10618 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10619 tree c
, t
= c_parser_expression (parser
).value
;
10621 t
= c_fully_fold (t
, false, NULL
);
10623 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10625 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10627 c_parser_error (parser
, "expected integer expression");
10631 /* Attempt to statically determine when the number isn't positive. */
10632 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10633 build_int_cst (TREE_TYPE (t
), 0));
10634 if (CAN_HAVE_LOCATION_P (c
))
10635 SET_EXPR_LOCATION (c
, expr_loc
);
10636 if (c
== boolean_true_node
)
10638 warning_at (expr_loc
, 0,
10639 "%<num_threads%> value must be positive");
10640 t
= integer_one_node
;
10643 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10645 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10646 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10647 OMP_CLAUSE_CHAIN (c
) = list
;
10655 num_workers ( expression ) */
10658 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
10660 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
10661 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10663 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10664 tree c
, t
= c_parser_expression (parser
).value
;
10666 t
= c_fully_fold (t
, false, NULL
);
10668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10670 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10672 c_parser_error (parser
, "expected integer expression");
10676 /* Attempt to statically determine when the number isn't positive. */
10677 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10678 build_int_cst (TREE_TYPE (t
), 0));
10679 if (CAN_HAVE_LOCATION_P (c
))
10680 SET_EXPR_LOCATION (c
, expr_loc
);
10681 if (c
== boolean_true_node
)
10683 warning_at (expr_loc
, 0,
10684 "%<num_workers%> value must be positive");
10685 t
= integer_one_node
;
10688 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
10690 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
10691 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
10692 OMP_CLAUSE_CHAIN (c
) = list
;
10700 async [( int-expr )] */
10703 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
10706 location_t loc
= c_parser_peek_token (parser
)->location
;
10708 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
10710 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10712 c_parser_consume_token (parser
);
10714 t
= c_parser_expression (parser
).value
;
10715 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10716 c_parser_error (parser
, "expected integer expression");
10717 else if (t
== error_mark_node
10718 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10722 t
= c_fully_fold (t
, false, NULL
);
10724 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
10726 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
10727 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
10728 OMP_CLAUSE_CHAIN (c
) = list
;
10735 wait ( int-expr-list ) */
10738 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
10740 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10742 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10743 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
10752 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10756 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10758 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10759 OMP_CLAUSE_ORDERED
);
10760 OMP_CLAUSE_CHAIN (c
) = list
;
10766 private ( variable-list ) */
10769 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10771 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10775 reduction ( reduction-operator : variable-list )
10777 reduction-operator:
10778 One of: + * - & ^ | && ||
10782 reduction-operator:
10783 One of: + * - & ^ | && || max min
10787 reduction-operator:
10788 One of: + * - & ^ | && ||
10792 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10794 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10795 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10797 enum tree_code code
= ERROR_MARK
;
10798 tree reduc_id
= NULL_TREE
;
10800 switch (c_parser_peek_token (parser
)->type
)
10812 code
= BIT_AND_EXPR
;
10815 code
= BIT_XOR_EXPR
;
10818 code
= BIT_IOR_EXPR
;
10821 code
= TRUTH_ANDIF_EXPR
;
10824 code
= TRUTH_ORIF_EXPR
;
10829 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10830 if (strcmp (p
, "min") == 0)
10835 if (strcmp (p
, "max") == 0)
10840 reduc_id
= c_parser_peek_token (parser
)->value
;
10844 c_parser_error (parser
,
10845 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10846 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10847 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10850 c_parser_consume_token (parser
);
10851 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10852 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10856 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10857 OMP_CLAUSE_REDUCTION
, list
);
10858 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10860 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10861 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10862 if (code
== ERROR_MARK
10863 || !(INTEGRAL_TYPE_P (type
)
10864 || TREE_CODE (type
) == REAL_TYPE
10865 || TREE_CODE (type
) == COMPLEX_TYPE
))
10866 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10867 = c_omp_reduction_lookup (reduc_id
,
10868 TYPE_MAIN_VARIANT (type
));
10873 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10879 schedule ( schedule-kind )
10880 schedule ( schedule-kind , expression )
10883 static | dynamic | guided | runtime | auto
10887 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10890 location_t loc
= c_parser_peek_token (parser
)->location
;
10892 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10895 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10897 if (c_parser_next_token_is (parser
, CPP_NAME
))
10899 tree kind
= c_parser_peek_token (parser
)->value
;
10900 const char *p
= IDENTIFIER_POINTER (kind
);
10905 if (strcmp ("dynamic", p
) != 0)
10907 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10911 if (strcmp ("guided", p
) != 0)
10913 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10917 if (strcmp ("runtime", p
) != 0)
10919 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10926 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10927 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10928 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10929 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10933 c_parser_consume_token (parser
);
10934 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10937 c_parser_consume_token (parser
);
10939 here
= c_parser_peek_token (parser
)->location
;
10940 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10942 t
= c_fully_fold (t
, false, NULL
);
10944 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10945 error_at (here
, "schedule %<runtime%> does not take "
10946 "a %<chunk_size%> parameter");
10947 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10949 "schedule %<auto%> does not take "
10950 "a %<chunk_size%> parameter");
10951 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10952 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10954 c_parser_error (parser
, "expected integer expression");
10956 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10959 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10960 "expected %<,%> or %<)%>");
10962 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10963 OMP_CLAUSE_CHAIN (c
) = list
;
10967 c_parser_error (parser
, "invalid schedule kind");
10968 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10973 shared ( variable-list ) */
10976 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10978 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10985 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10989 /* FIXME: Should we allow duplicates? */
10990 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10992 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10993 OMP_CLAUSE_UNTIED
);
10994 OMP_CLAUSE_CHAIN (c
) = list
;
11000 vector_length ( expression ) */
11003 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
11005 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
11006 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11008 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11009 tree c
, t
= c_parser_expression (parser
).value
;
11011 t
= c_fully_fold (t
, false, NULL
);
11013 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11015 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11017 c_parser_error (parser
, "expected integer expression");
11021 /* Attempt to statically determine when the number isn't positive. */
11022 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11023 build_int_cst (TREE_TYPE (t
), 0));
11024 if (CAN_HAVE_LOCATION_P (c
))
11025 SET_EXPR_LOCATION (c
, expr_loc
);
11026 if (c
== boolean_true_node
)
11028 warning_at (expr_loc
, 0,
11029 "%<vector_length%> value must be positive");
11030 t
= integer_one_node
;
11033 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
11035 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
11036 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
11037 OMP_CLAUSE_CHAIN (c
) = list
;
11049 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
11050 enum omp_clause_code code
, tree list
)
11052 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11054 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11055 OMP_CLAUSE_CHAIN (c
) = list
;
11067 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
11068 enum omp_clause_code code
, tree list
)
11070 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11071 OMP_CLAUSE_CHAIN (c
) = list
;
11077 num_teams ( expression ) */
11080 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
11082 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
11083 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11085 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11086 tree c
, t
= c_parser_expression (parser
).value
;
11088 t
= c_fully_fold (t
, false, NULL
);
11090 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11092 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11094 c_parser_error (parser
, "expected integer expression");
11098 /* Attempt to statically determine when the number isn't positive. */
11099 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11100 build_int_cst (TREE_TYPE (t
), 0));
11101 if (CAN_HAVE_LOCATION_P (c
))
11102 SET_EXPR_LOCATION (c
, expr_loc
);
11103 if (c
== boolean_true_node
)
11105 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
11106 t
= integer_one_node
;
11109 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
11111 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
11112 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
11113 OMP_CLAUSE_CHAIN (c
) = list
;
11121 thread_limit ( expression ) */
11124 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
11126 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
11127 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11129 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11130 tree c
, t
= c_parser_expression (parser
).value
;
11132 t
= c_fully_fold (t
, false, NULL
);
11134 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11136 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11138 c_parser_error (parser
, "expected integer expression");
11142 /* Attempt to statically determine when the number isn't positive. */
11143 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11144 build_int_cst (TREE_TYPE (t
), 0));
11145 if (CAN_HAVE_LOCATION_P (c
))
11146 SET_EXPR_LOCATION (c
, expr_loc
);
11147 if (c
== boolean_true_node
)
11149 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
11150 t
= integer_one_node
;
11153 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
11156 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11157 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
11158 OMP_CLAUSE_CHAIN (c
) = list
;
11166 aligned ( variable-list )
11167 aligned ( variable-list : constant-expression ) */
11170 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
11172 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11175 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11178 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11179 OMP_CLAUSE_ALIGNED
, list
);
11181 if (c_parser_next_token_is (parser
, CPP_COLON
))
11183 c_parser_consume_token (parser
);
11184 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
11185 mark_exp_read (alignment
);
11186 alignment
= c_fully_fold (alignment
, false, NULL
);
11187 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
11188 && TREE_CODE (alignment
) != INTEGER_CST
11189 && tree_int_cst_sgn (alignment
) != 1)
11191 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
11192 "be positive constant integer expression");
11193 alignment
= NULL_TREE
;
11196 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11197 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
11200 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11205 linear ( variable-list )
11206 linear ( variable-list : expression ) */
11209 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
11211 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11214 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11217 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11218 OMP_CLAUSE_LINEAR
, list
);
11220 if (c_parser_next_token_is (parser
, CPP_COLON
))
11222 c_parser_consume_token (parser
);
11223 step
= c_parser_expression (parser
).value
;
11224 mark_exp_read (step
);
11225 step
= c_fully_fold (step
, false, NULL
);
11226 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
11228 sorry ("using parameters for %<linear%> step is not supported yet");
11229 step
= integer_one_node
;
11231 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
11233 error_at (clause_loc
, "%<linear%> clause step expression must "
11235 step
= integer_one_node
;
11240 step
= integer_one_node
;
11242 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11244 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11247 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11252 safelen ( constant-expression ) */
11255 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
11257 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11260 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11263 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11265 t
= c_fully_fold (t
, false, NULL
);
11266 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11267 && TREE_CODE (t
) != INTEGER_CST
11268 && tree_int_cst_sgn (t
) != 1)
11270 error_at (clause_loc
, "%<safelen%> clause expression must "
11271 "be positive constant integer expression");
11275 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11276 if (t
== NULL_TREE
|| t
== error_mark_node
)
11279 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
11281 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
11282 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
11283 OMP_CLAUSE_CHAIN (c
) = list
;
11288 simdlen ( constant-expression ) */
11291 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
11293 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11296 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11299 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11301 t
= c_fully_fold (t
, false, NULL
);
11302 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11303 && TREE_CODE (t
) != INTEGER_CST
11304 && tree_int_cst_sgn (t
) != 1)
11306 error_at (clause_loc
, "%<simdlen%> clause expression must "
11307 "be positive constant integer expression");
11311 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11312 if (t
== NULL_TREE
|| t
== error_mark_node
)
11315 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
11317 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
11318 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
11319 OMP_CLAUSE_CHAIN (c
) = list
;
11324 depend ( depend-kind: variable-list )
11327 in | out | inout */
11330 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
11332 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11333 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
11336 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11339 if (c_parser_next_token_is (parser
, CPP_NAME
))
11341 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11342 if (strcmp ("in", p
) == 0)
11343 kind
= OMP_CLAUSE_DEPEND_IN
;
11344 else if (strcmp ("inout", p
) == 0)
11345 kind
= OMP_CLAUSE_DEPEND_INOUT
;
11346 else if (strcmp ("out", p
) == 0)
11347 kind
= OMP_CLAUSE_DEPEND_OUT
;
11354 c_parser_consume_token (parser
);
11355 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11358 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11359 OMP_CLAUSE_DEPEND
, list
);
11361 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11362 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
11364 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11368 c_parser_error (parser
, "invalid depend kind");
11370 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11375 map ( map-kind: variable-list )
11376 map ( variable-list )
11379 alloc | to | from | tofrom */
11382 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
11384 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11385 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
11388 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11391 if (c_parser_next_token_is (parser
, CPP_NAME
)
11392 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11394 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11395 if (strcmp ("alloc", p
) == 0)
11396 kind
= GOMP_MAP_ALLOC
;
11397 else if (strcmp ("to", p
) == 0)
11398 kind
= GOMP_MAP_TO
;
11399 else if (strcmp ("from", p
) == 0)
11400 kind
= GOMP_MAP_FROM
;
11401 else if (strcmp ("tofrom", p
) == 0)
11402 kind
= GOMP_MAP_TOFROM
;
11405 c_parser_error (parser
, "invalid map kind");
11406 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11410 c_parser_consume_token (parser
);
11411 c_parser_consume_token (parser
);
11414 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
11416 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11417 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11419 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11424 device ( expression ) */
11427 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
11429 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11430 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11432 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11434 t
= c_fully_fold (t
, false, NULL
);
11436 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11438 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11440 c_parser_error (parser
, "expected integer expression");
11444 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
11446 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
11447 OMP_CLAUSE_DEVICE_ID (c
) = t
;
11448 OMP_CLAUSE_CHAIN (c
) = list
;
11456 dist_schedule ( static )
11457 dist_schedule ( static , expression ) */
11460 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
11462 tree c
, t
= NULL_TREE
;
11463 location_t loc
= c_parser_peek_token (parser
)->location
;
11465 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11468 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11470 c_parser_error (parser
, "invalid dist_schedule kind");
11471 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11476 c_parser_consume_token (parser
);
11477 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11479 c_parser_consume_token (parser
);
11481 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11483 t
= c_fully_fold (t
, false, NULL
);
11484 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11487 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11488 "expected %<,%> or %<)%>");
11490 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11491 if (t
== error_mark_node
)
11494 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
11495 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
11496 OMP_CLAUSE_CHAIN (c
) = list
;
11501 proc_bind ( proc-bind-kind )
11504 master | close | spread */
11507 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
11509 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11510 enum omp_clause_proc_bind_kind kind
;
11513 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11516 if (c_parser_next_token_is (parser
, CPP_NAME
))
11518 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11519 if (strcmp ("master", p
) == 0)
11520 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
11521 else if (strcmp ("close", p
) == 0)
11522 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
11523 else if (strcmp ("spread", p
) == 0)
11524 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
11531 c_parser_consume_token (parser
);
11532 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11533 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
11534 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
11535 OMP_CLAUSE_CHAIN (c
) = list
;
11539 c_parser_error (parser
, "invalid proc_bind kind");
11540 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11545 to ( variable-list ) */
11548 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
11550 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
11554 from ( variable-list ) */
11557 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
11559 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
11563 uniform ( variable-list ) */
11566 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
11568 /* The clauses location. */
11569 location_t loc
= c_parser_peek_token (parser
)->location
;
11571 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11573 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
11575 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11580 /* Parse all OpenACC clauses. The set clauses allowed by the directive
11581 is a bitmask in MASK. Return the list of clauses found. */
11584 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11585 const char *where
, bool finish_p
= true)
11587 tree clauses
= NULL
;
11590 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11593 pragma_omp_clause c_kind
;
11594 const char *c_name
;
11595 tree prev
= clauses
;
11597 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11598 c_parser_consume_token (parser
);
11600 here
= c_parser_peek_token (parser
)->location
;
11601 c_kind
= c_parser_omp_clause_name (parser
);
11605 case PRAGMA_OACC_CLAUSE_ASYNC
:
11606 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
11609 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
11610 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11611 c_name
= "collapse";
11613 case PRAGMA_OACC_CLAUSE_COPY
:
11614 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11617 case PRAGMA_OACC_CLAUSE_COPYIN
:
11618 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11621 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11622 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11623 c_name
= "copyout";
11625 case PRAGMA_OACC_CLAUSE_CREATE
:
11626 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11629 case PRAGMA_OACC_CLAUSE_DELETE
:
11630 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11633 case PRAGMA_OACC_CLAUSE_DEVICE
:
11634 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11637 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
11638 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
11639 c_name
= "deviceptr";
11641 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
11642 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11643 c_name
= "firstprivate";
11645 case PRAGMA_OACC_CLAUSE_HOST
:
11646 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11649 case PRAGMA_OACC_CLAUSE_IF
:
11650 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11653 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
11654 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
11655 c_name
= "num_gangs";
11657 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
11658 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
11659 c_name
= "num_workers";
11661 case PRAGMA_OACC_CLAUSE_PRESENT
:
11662 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11663 c_name
= "present";
11665 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
11666 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11667 c_name
= "present_or_copy";
11669 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
11670 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11671 c_name
= "present_or_copyin";
11673 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
11674 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11675 c_name
= "present_or_copyout";
11677 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
11678 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11679 c_name
= "present_or_create";
11681 case PRAGMA_OACC_CLAUSE_PRIVATE
:
11682 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11683 c_name
= "private";
11685 case PRAGMA_OACC_CLAUSE_REDUCTION
:
11686 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11687 c_name
= "reduction";
11689 case PRAGMA_OACC_CLAUSE_SELF
:
11690 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11693 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
11694 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
11695 c_name
= "vector_length";
11697 case PRAGMA_OACC_CLAUSE_WAIT
:
11698 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
11702 c_parser_error (parser
, "expected %<#pragma acc%> clause");
11708 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11710 /* Remove the invalid clause(s) from the list to avoid
11711 confusing the rest of the compiler. */
11713 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11718 c_parser_skip_to_pragma_eol (parser
);
11721 return c_finish_omp_clauses (clauses
);
11726 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11727 is a bitmask in MASK. Return the list of clauses found. */
11730 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11731 const char *where
, bool finish_p
= true)
11733 tree clauses
= NULL
;
11734 bool first
= true, cilk_simd_fn
= false;
11736 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11739 pragma_omp_clause c_kind
;
11740 const char *c_name
;
11741 tree prev
= clauses
;
11743 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11744 c_parser_consume_token (parser
);
11746 here
= c_parser_peek_token (parser
)->location
;
11747 c_kind
= c_parser_omp_clause_name (parser
);
11751 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11752 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11753 c_name
= "collapse";
11755 case PRAGMA_OMP_CLAUSE_COPYIN
:
11756 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11759 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11760 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11761 c_name
= "copyprivate";
11763 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11764 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11765 c_name
= "default";
11767 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11768 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11769 c_name
= "firstprivate";
11771 case PRAGMA_OMP_CLAUSE_FINAL
:
11772 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11775 case PRAGMA_OMP_CLAUSE_IF
:
11776 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11779 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11780 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11781 c_name
= "lastprivate";
11783 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11784 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11785 c_name
= "mergeable";
11787 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11788 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11791 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11792 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11793 c_name
= "num_threads";
11795 case PRAGMA_OMP_CLAUSE_ORDERED
:
11796 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11797 c_name
= "ordered";
11799 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11800 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11801 c_name
= "private";
11803 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11804 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11805 c_name
= "reduction";
11807 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11808 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11809 c_name
= "schedule";
11811 case PRAGMA_OMP_CLAUSE_SHARED
:
11812 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11815 case PRAGMA_OMP_CLAUSE_UNTIED
:
11816 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11819 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11820 case PRAGMA_CILK_CLAUSE_MASK
:
11821 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11823 c_name
= "inbranch";
11825 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11826 case PRAGMA_CILK_CLAUSE_NOMASK
:
11827 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11829 c_name
= "notinbranch";
11831 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11833 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11835 c_name
= "parallel";
11839 error_at (here
, "%qs must be the first clause of %qs",
11844 case PRAGMA_OMP_CLAUSE_FOR
:
11846 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11850 goto clause_not_first
;
11852 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11854 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11856 c_name
= "sections";
11858 goto clause_not_first
;
11860 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11862 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11864 c_name
= "taskgroup";
11866 goto clause_not_first
;
11868 case PRAGMA_OMP_CLAUSE_TO
:
11869 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11872 case PRAGMA_OMP_CLAUSE_FROM
:
11873 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11876 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11877 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11878 c_name
= "uniform";
11880 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11881 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11882 c_name
= "num_teams";
11884 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11885 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11886 c_name
= "thread_limit";
11888 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11889 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11890 c_name
= "aligned";
11892 case PRAGMA_OMP_CLAUSE_LINEAR
:
11893 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11894 cilk_simd_fn
= true;
11895 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11898 case PRAGMA_OMP_CLAUSE_DEPEND
:
11899 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11902 case PRAGMA_OMP_CLAUSE_MAP
:
11903 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11906 case PRAGMA_OMP_CLAUSE_DEVICE
:
11907 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11910 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11911 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11912 c_name
= "dist_schedule";
11914 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11915 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11916 c_name
= "proc_bind";
11918 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11919 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11920 c_name
= "safelen";
11922 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11923 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11924 c_name
= "simdlen";
11926 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11927 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11928 c_name
= "simdlen";
11931 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11937 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11939 /* Remove the invalid clause(s) from the list to avoid
11940 confusing the rest of the compiler. */
11942 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11947 c_parser_skip_to_pragma_eol (parser
);
11950 return c_finish_omp_clauses (clauses
);
11955 /* OpenACC 2.0, OpenMP 2.5:
11959 In practice, we're also interested in adding the statement to an
11960 outer node. So it is convenient if we work around the fact that
11961 c_parser_statement calls add_stmt. */
11964 c_parser_omp_structured_block (c_parser
*parser
)
11966 tree stmt
= push_stmt_list ();
11967 c_parser_statement (parser
);
11968 return pop_stmt_list (stmt
);
11972 # pragma acc cache (variable-list) new-line
11974 LOC is the location of the #pragma token.
11978 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
11980 tree stmt
, clauses
;
11982 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
11983 clauses
= c_finish_omp_clauses (clauses
);
11985 c_parser_skip_to_pragma_eol (parser
);
11987 stmt
= make_node (OACC_CACHE
);
11988 TREE_TYPE (stmt
) = void_type_node
;
11989 OACC_CACHE_CLAUSES (stmt
) = clauses
;
11990 SET_EXPR_LOCATION (stmt
, loc
);
11997 # pragma acc data oacc-data-clause[optseq] new-line
12000 LOC is the location of the #pragma token.
12003 #define OACC_DATA_CLAUSE_MASK \
12004 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12009 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12010 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12011 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12012 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12013 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12014 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
12017 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
12019 tree stmt
, clauses
, block
;
12021 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
12022 "#pragma acc data");
12024 block
= c_begin_omp_parallel ();
12025 add_stmt (c_parser_omp_structured_block (parser
));
12027 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
12033 # pragma acc kernels oacc-kernels-clause[optseq] new-line
12036 LOC is the location of the #pragma token.
12039 #define OACC_KERNELS_CLAUSE_MASK \
12040 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12041 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12042 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12043 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12047 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12049 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12050 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12051 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12052 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12055 c_parser_oacc_kernels (location_t loc
, c_parser
*parser
, char *p_name
)
12057 tree stmt
, clauses
= NULL_TREE
, block
;
12059 strcat (p_name
, " kernels");
12061 if (c_parser_next_token_is (parser
, CPP_NAME
))
12063 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12064 if (strcmp (p
, "loop") == 0)
12066 c_parser_consume_token (parser
);
12067 block
= c_begin_omp_parallel ();
12068 c_parser_oacc_loop (loc
, parser
, p_name
);
12069 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12070 OACC_KERNELS_COMBINED (stmt
) = 1;
12075 clauses
= c_parser_oacc_all_clauses (parser
, OACC_KERNELS_CLAUSE_MASK
,
12078 block
= c_begin_omp_parallel ();
12079 add_stmt (c_parser_omp_structured_block (parser
));
12081 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12087 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
12091 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
12094 LOC is the location of the #pragma token.
12097 #define OACC_ENTER_DATA_CLAUSE_MASK \
12098 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12099 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12101 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12102 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12103 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12104 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12106 #define OACC_EXIT_DATA_CLAUSE_MASK \
12107 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12108 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12109 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12110 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
12111 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12114 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
12116 location_t loc
= c_parser_peek_token (parser
)->location
;
12117 tree clauses
, stmt
;
12119 c_parser_consume_pragma (parser
);
12121 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12123 c_parser_error (parser
, enter
12124 ? "expected %<data%> in %<#pragma acc enter data%>"
12125 : "expected %<data%> in %<#pragma acc exit data%>");
12126 c_parser_skip_to_pragma_eol (parser
);
12130 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12131 if (strcmp (p
, "data") != 0)
12133 c_parser_error (parser
, "invalid pragma");
12134 c_parser_skip_to_pragma_eol (parser
);
12138 c_parser_consume_token (parser
);
12141 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
12142 "#pragma acc enter data");
12144 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
12145 "#pragma acc exit data");
12147 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12149 error_at (loc
, enter
12150 ? "%<#pragma acc enter data%> has no data movement clause"
12151 : "%<#pragma acc exit data%> has no data movement clause");
12155 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
12156 TREE_TYPE (stmt
) = void_type_node
;
12158 OACC_ENTER_DATA_CLAUSES (stmt
) = clauses
;
12160 OACC_EXIT_DATA_CLAUSES (stmt
) = clauses
;
12161 SET_EXPR_LOCATION (stmt
, loc
);
12168 # pragma acc loop oacc-loop-clause[optseq] new-line
12171 LOC is the location of the #pragma token.
12174 #define OACC_LOOP_CLAUSE_MASK \
12175 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
12176 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) )
12179 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
)
12181 tree stmt
, clauses
, block
;
12183 strcat (p_name
, " loop");
12185 clauses
= c_parser_oacc_all_clauses (parser
, OACC_LOOP_CLAUSE_MASK
, p_name
);
12187 block
= c_begin_compound_stmt (true);
12188 stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
12189 block
= c_end_compound_stmt (loc
, block
, true);
12196 # pragma acc parallel oacc-parallel-clause[optseq] new-line
12199 LOC is the location of the #pragma token.
12202 #define OACC_PARALLEL_CLAUSE_MASK \
12203 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12204 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12205 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12206 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12207 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12208 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12209 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12210 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
12211 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
12212 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12213 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12214 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12215 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12216 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12217 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
12218 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
12219 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12222 c_parser_oacc_parallel (location_t loc
, c_parser
*parser
, char *p_name
)
12224 tree stmt
, clauses
= NULL_TREE
, block
;
12226 strcat (p_name
, " parallel");
12228 if (c_parser_next_token_is (parser
, CPP_NAME
))
12230 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12231 if (strcmp (p
, "loop") == 0)
12233 c_parser_consume_token (parser
);
12234 block
= c_begin_omp_parallel ();
12235 c_parser_oacc_loop (loc
, parser
, p_name
);
12236 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12237 OACC_PARALLEL_COMBINED (stmt
) = 1;
12242 clauses
= c_parser_oacc_all_clauses (parser
, OACC_PARALLEL_CLAUSE_MASK
,
12245 block
= c_begin_omp_parallel ();
12246 add_stmt (c_parser_omp_structured_block (parser
));
12248 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12254 # pragma acc update oacc-update-clause[optseq] new-line
12257 #define OACC_UPDATE_CLAUSE_MASK \
12258 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12259 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
12260 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
12261 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12262 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
12263 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12266 c_parser_oacc_update (c_parser
*parser
)
12268 location_t loc
= c_parser_peek_token (parser
)->location
;
12270 c_parser_consume_pragma (parser
);
12272 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
12273 "#pragma acc update");
12274 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12277 "%<#pragma acc update%> must contain at least one "
12278 "%<device%> or %<host/self%> clause");
12285 tree stmt
= make_node (OACC_UPDATE
);
12286 TREE_TYPE (stmt
) = void_type_node
;
12287 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
12288 SET_EXPR_LOCATION (stmt
, loc
);
12293 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12295 LOC is the location of the #pragma token.
12298 #define OACC_WAIT_CLAUSE_MASK \
12299 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
12302 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
12304 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
12306 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12307 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
12309 strcpy (p_name
, " wait");
12310 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
12311 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
12317 # pragma omp atomic new-line
12321 x binop= expr | x++ | ++x | x-- | --x
12323 +, *, -, /, &, ^, |, <<, >>
12325 where x is an lvalue expression with scalar type.
12328 # pragma omp atomic new-line
12331 # pragma omp atomic read new-line
12334 # pragma omp atomic write new-line
12337 # pragma omp atomic update new-line
12340 # pragma omp atomic capture new-line
12343 # pragma omp atomic capture new-line
12351 expression-stmt | x = x binop expr
12353 v = expression-stmt
12355 { v = x; update-stmt; } | { update-stmt; v = x; }
12359 expression-stmt | x = x binop expr | x = expr binop x
12363 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12365 where x and v are lvalue expressions with scalar type.
12367 LOC is the location of the #pragma token. */
12370 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
12372 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
12373 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
12374 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
12375 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
12376 struct c_expr expr
;
12378 bool structured_block
= false;
12379 bool swapped
= false;
12380 bool seq_cst
= false;
12382 if (c_parser_next_token_is (parser
, CPP_NAME
))
12384 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12385 if (!strcmp (p
, "seq_cst"))
12388 c_parser_consume_token (parser
);
12389 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12390 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12391 c_parser_consume_token (parser
);
12394 if (c_parser_next_token_is (parser
, CPP_NAME
))
12396 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12398 if (!strcmp (p
, "read"))
12399 code
= OMP_ATOMIC_READ
;
12400 else if (!strcmp (p
, "write"))
12402 else if (!strcmp (p
, "update"))
12404 else if (!strcmp (p
, "capture"))
12405 code
= OMP_ATOMIC_CAPTURE_NEW
;
12409 c_parser_consume_token (parser
);
12413 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12414 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12415 c_parser_consume_token (parser
);
12417 if (c_parser_next_token_is (parser
, CPP_NAME
))
12420 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12421 if (!strcmp (p
, "seq_cst"))
12424 c_parser_consume_token (parser
);
12428 c_parser_skip_to_pragma_eol (parser
);
12432 case OMP_ATOMIC_READ
:
12433 case NOP_EXPR
: /* atomic write */
12434 v
= c_parser_unary_expression (parser
).value
;
12435 v
= c_fully_fold (v
, false, NULL
);
12436 if (v
== error_mark_node
)
12438 loc
= c_parser_peek_token (parser
)->location
;
12439 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12441 if (code
== NOP_EXPR
)
12442 lhs
= c_parser_expression (parser
).value
;
12444 lhs
= c_parser_unary_expression (parser
).value
;
12445 lhs
= c_fully_fold (lhs
, false, NULL
);
12446 if (lhs
== error_mark_node
)
12448 if (code
== NOP_EXPR
)
12450 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
12458 case OMP_ATOMIC_CAPTURE_NEW
:
12459 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12461 c_parser_consume_token (parser
);
12462 structured_block
= true;
12466 v
= c_parser_unary_expression (parser
).value
;
12467 v
= c_fully_fold (v
, false, NULL
);
12468 if (v
== error_mark_node
)
12470 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12478 /* For structured_block case we don't know yet whether
12479 old or new x should be captured. */
12481 eloc
= c_parser_peek_token (parser
)->location
;
12482 expr
= c_parser_unary_expression (parser
);
12484 expr
= default_function_array_conversion (eloc
, expr
);
12485 unfolded_lhs
= expr
.value
;
12486 lhs
= c_fully_fold (lhs
, false, NULL
);
12488 switch (TREE_CODE (lhs
))
12492 c_parser_skip_to_end_of_block_or_statement (parser
);
12493 if (structured_block
)
12495 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12496 c_parser_consume_token (parser
);
12497 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
12499 c_parser_skip_to_end_of_block_or_statement (parser
);
12500 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12501 c_parser_consume_token (parser
);
12506 case POSTINCREMENT_EXPR
:
12507 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12508 code
= OMP_ATOMIC_CAPTURE_OLD
;
12510 case PREINCREMENT_EXPR
:
12511 lhs
= TREE_OPERAND (lhs
, 0);
12512 unfolded_lhs
= NULL_TREE
;
12513 opcode
= PLUS_EXPR
;
12514 rhs
= integer_one_node
;
12517 case POSTDECREMENT_EXPR
:
12518 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12519 code
= OMP_ATOMIC_CAPTURE_OLD
;
12521 case PREDECREMENT_EXPR
:
12522 lhs
= TREE_OPERAND (lhs
, 0);
12523 unfolded_lhs
= NULL_TREE
;
12524 opcode
= MINUS_EXPR
;
12525 rhs
= integer_one_node
;
12528 case COMPOUND_EXPR
:
12529 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
12530 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
12531 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
12532 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
12533 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12534 (TREE_OPERAND (lhs
, 1), 0), 0)))
12536 /* Undo effects of boolean_increment for post {in,de}crement. */
12537 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
12540 if (TREE_CODE (lhs
) == MODIFY_EXPR
12541 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
12543 /* Undo effects of boolean_increment. */
12544 if (integer_onep (TREE_OPERAND (lhs
, 1)))
12546 /* This is pre or post increment. */
12547 rhs
= TREE_OPERAND (lhs
, 1);
12548 lhs
= TREE_OPERAND (lhs
, 0);
12549 unfolded_lhs
= NULL_TREE
;
12551 if (code
== OMP_ATOMIC_CAPTURE_NEW
12552 && !structured_block
12553 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12554 code
= OMP_ATOMIC_CAPTURE_OLD
;
12557 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
12558 && TREE_OPERAND (lhs
, 0)
12559 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
12561 /* This is pre or post decrement. */
12562 rhs
= TREE_OPERAND (lhs
, 1);
12563 lhs
= TREE_OPERAND (lhs
, 0);
12564 unfolded_lhs
= NULL_TREE
;
12566 if (code
== OMP_ATOMIC_CAPTURE_NEW
12567 && !structured_block
12568 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12569 code
= OMP_ATOMIC_CAPTURE_OLD
;
12575 switch (c_parser_peek_token (parser
)->type
)
12578 opcode
= MULT_EXPR
;
12581 opcode
= TRUNC_DIV_EXPR
;
12584 opcode
= PLUS_EXPR
;
12587 opcode
= MINUS_EXPR
;
12589 case CPP_LSHIFT_EQ
:
12590 opcode
= LSHIFT_EXPR
;
12592 case CPP_RSHIFT_EQ
:
12593 opcode
= RSHIFT_EXPR
;
12596 opcode
= BIT_AND_EXPR
;
12599 opcode
= BIT_IOR_EXPR
;
12602 opcode
= BIT_XOR_EXPR
;
12605 c_parser_consume_token (parser
);
12606 eloc
= c_parser_peek_token (parser
)->location
;
12607 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
12609 switch (TREE_CODE (rhs1
))
12612 case TRUNC_DIV_EXPR
:
12621 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
12623 opcode
= TREE_CODE (rhs1
);
12624 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12625 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12628 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
12630 opcode
= TREE_CODE (rhs1
);
12631 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12632 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12633 swapped
= !commutative_tree_code (opcode
);
12642 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
12644 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12646 code
= OMP_ATOMIC_CAPTURE_OLD
;
12649 expr
= default_function_array_read_conversion (eloc
, expr
);
12650 unfolded_lhs1
= expr
.value
;
12651 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
12653 c_parser_consume_token (parser
);
12656 if (structured_block
)
12659 expr
= default_function_array_read_conversion (eloc
, expr
);
12660 rhs
= c_fully_fold (expr
.value
, false, NULL
);
12665 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
12668 c_parser_error (parser
,
12669 "invalid operator for %<#pragma omp atomic%>");
12673 /* Arrange to pass the location of the assignment operator to
12674 c_finish_omp_atomic. */
12675 loc
= c_parser_peek_token (parser
)->location
;
12676 c_parser_consume_token (parser
);
12677 eloc
= c_parser_peek_token (parser
)->location
;
12678 expr
= c_parser_expression (parser
);
12679 expr
= default_function_array_read_conversion (eloc
, expr
);
12681 rhs
= c_fully_fold (rhs
, false, NULL
);
12685 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12687 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
12689 v
= c_parser_unary_expression (parser
).value
;
12690 v
= c_fully_fold (v
, false, NULL
);
12691 if (v
== error_mark_node
)
12693 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12695 eloc
= c_parser_peek_token (parser
)->location
;
12696 expr
= c_parser_unary_expression (parser
);
12698 expr
= default_function_array_read_conversion (eloc
, expr
);
12699 unfolded_lhs1
= expr
.value
;
12700 lhs1
= c_fully_fold (lhs1
, false, NULL
);
12701 if (lhs1
== error_mark_node
)
12704 if (structured_block
)
12706 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12707 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
12710 if (unfolded_lhs
&& unfolded_lhs1
12711 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
12713 error ("%<#pragma omp atomic capture%> uses two different "
12714 "expressions for memory");
12715 stmt
= error_mark_node
;
12718 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
12720 if (stmt
!= error_mark_node
)
12723 if (!structured_block
)
12724 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12729 # pragma omp barrier new-line
12733 c_parser_omp_barrier (c_parser
*parser
)
12735 location_t loc
= c_parser_peek_token (parser
)->location
;
12736 c_parser_consume_pragma (parser
);
12737 c_parser_skip_to_pragma_eol (parser
);
12739 c_finish_omp_barrier (loc
);
12743 # pragma omp critical [(name)] new-line
12746 LOC is the location of the #pragma itself. */
12749 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
12751 tree stmt
, name
= NULL
;
12753 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12755 c_parser_consume_token (parser
);
12756 if (c_parser_next_token_is (parser
, CPP_NAME
))
12758 name
= c_parser_peek_token (parser
)->value
;
12759 c_parser_consume_token (parser
);
12760 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12763 c_parser_error (parser
, "expected identifier");
12765 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12766 c_parser_error (parser
, "expected %<(%> or end of line");
12767 c_parser_skip_to_pragma_eol (parser
);
12769 stmt
= c_parser_omp_structured_block (parser
);
12770 return c_finish_omp_critical (loc
, stmt
, name
);
12774 # pragma omp flush flush-vars[opt] new-line
12777 ( variable-list ) */
12780 c_parser_omp_flush (c_parser
*parser
)
12782 location_t loc
= c_parser_peek_token (parser
)->location
;
12783 c_parser_consume_pragma (parser
);
12784 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12785 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12786 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12787 c_parser_error (parser
, "expected %<(%> or end of line");
12788 c_parser_skip_to_pragma_eol (parser
);
12790 c_finish_omp_flush (loc
);
12793 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12794 The real trick here is to determine the loop control variable early
12795 so that we can push a new decl if necessary to make it private.
12796 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12800 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
12801 tree clauses
, tree
*cclauses
)
12803 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
12804 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
12805 bool fail
= false, open_brace_parsed
= false;
12806 int i
, collapse
= 1, nbraces
= 0;
12807 location_t for_loc
;
12808 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
12810 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
12811 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
12812 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
12814 gcc_assert (collapse
>= 1);
12816 declv
= make_tree_vec (collapse
);
12817 initv
= make_tree_vec (collapse
);
12818 condv
= make_tree_vec (collapse
);
12819 incrv
= make_tree_vec (collapse
);
12821 if (code
!= CILK_FOR
12822 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
12824 c_parser_error (parser
, "for statement expected");
12827 if (code
== CILK_FOR
12828 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
12830 c_parser_error (parser
, "_Cilk_for statement expected");
12833 for_loc
= c_parser_peek_token (parser
)->location
;
12834 c_parser_consume_token (parser
);
12836 for (i
= 0; i
< collapse
; i
++)
12838 int bracecount
= 0;
12840 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12843 /* Parse the initialization declaration or expression. */
12844 if (c_parser_next_tokens_start_declaration (parser
))
12847 vec_safe_push (for_block
, c_begin_compound_stmt (true));
12848 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12850 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
12853 if (DECL_INITIAL (decl
) == error_mark_node
)
12854 decl
= error_mark_node
;
12857 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12858 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
12860 struct c_expr decl_exp
;
12861 struct c_expr init_exp
;
12862 location_t init_loc
;
12864 decl_exp
= c_parser_postfix_expression (parser
);
12865 decl
= decl_exp
.value
;
12867 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
12869 init_loc
= c_parser_peek_token (parser
)->location
;
12870 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
12871 init_exp
= default_function_array_read_conversion (init_loc
,
12873 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
12874 NOP_EXPR
, init_loc
, init_exp
.value
,
12875 init_exp
.original_type
);
12876 init
= c_process_expr_stmt (init_loc
, init
);
12878 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12883 c_parser_error (parser
,
12884 "expected iteration declaration or initialization");
12885 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12891 /* Parse the loop condition. */
12893 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
12895 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
12896 struct c_expr cond_expr
12897 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
12899 cond
= cond_expr
.value
;
12900 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
12901 cond
= c_fully_fold (cond
, false, NULL
);
12902 switch (cond_expr
.original_code
)
12910 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
12914 /* Can't be cond = error_mark_node, because we want to preserve
12915 the location until c_finish_omp_for. */
12916 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
12919 protected_set_expr_location (cond
, cond_loc
);
12921 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12923 /* Parse the increment expression. */
12925 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
12927 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
12929 incr
= c_process_expr_stmt (incr_loc
,
12930 c_parser_expression (parser
).value
);
12932 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12934 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
12938 TREE_VEC_ELT (declv
, i
) = decl
;
12939 TREE_VEC_ELT (initv
, i
) = init
;
12940 TREE_VEC_ELT (condv
, i
) = cond
;
12941 TREE_VEC_ELT (incrv
, i
) = incr
;
12945 if (i
== collapse
- 1)
12948 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12949 in between the collapsed for loops to be still considered perfectly
12950 nested. Hopefully the final version clarifies this.
12951 For now handle (multiple) {'s and empty statements. */
12954 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12956 c_parser_consume_token (parser
);
12959 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12961 c_parser_consume_token (parser
);
12964 else if (bracecount
12965 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12966 c_parser_consume_token (parser
);
12969 c_parser_error (parser
, "not enough perfectly nested loops");
12972 open_brace_parsed
= true;
12982 nbraces
+= bracecount
;
12985 save_break
= c_break_label
;
12986 if (code
== CILK_SIMD
)
12987 c_break_label
= build_int_cst (size_type_node
, 2);
12989 c_break_label
= size_one_node
;
12990 save_cont
= c_cont_label
;
12991 c_cont_label
= NULL_TREE
;
12992 body
= push_stmt_list ();
12994 if (open_brace_parsed
)
12996 location_t here
= c_parser_peek_token (parser
)->location
;
12997 stmt
= c_begin_compound_stmt (true);
12998 c_parser_compound_statement_nostart (parser
);
12999 add_stmt (c_end_compound_stmt (here
, stmt
, true));
13002 add_stmt (c_parser_c99_block_statement (parser
));
13005 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
13006 SET_EXPR_LOCATION (t
, loc
);
13010 body
= pop_stmt_list (body
);
13011 c_break_label
= save_break
;
13012 c_cont_label
= save_cont
;
13016 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13018 c_parser_consume_token (parser
);
13021 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
13022 c_parser_consume_token (parser
);
13025 c_parser_error (parser
, "collapsed loops not perfectly nested");
13028 location_t here
= c_parser_peek_token (parser
)->location
;
13029 stmt
= c_begin_compound_stmt (true);
13031 c_parser_compound_statement_nostart (parser
);
13032 body
= c_end_compound_stmt (here
, stmt
, true);
13039 /* Only bother calling c_finish_omp_for if we haven't already generated
13040 an error from the initialization parsing. */
13043 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
13044 incrv
, body
, NULL
);
13047 if (cclauses
!= NULL
13048 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
13051 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
13052 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
13053 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
13054 c
= &OMP_CLAUSE_CHAIN (*c
);
13057 for (i
= 0; i
< collapse
; i
++)
13058 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
13061 c
= &OMP_CLAUSE_CHAIN (*c
);
13062 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
13065 "iteration variable %qD should not be firstprivate",
13066 OMP_CLAUSE_DECL (*c
));
13067 *c
= OMP_CLAUSE_CHAIN (*c
);
13071 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
13072 change it to shared (decl) in
13073 OMP_PARALLEL_CLAUSES. */
13074 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
13075 OMP_CLAUSE_LASTPRIVATE
);
13076 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
13077 if (code
== OMP_SIMD
)
13079 OMP_CLAUSE_CHAIN (l
)
13080 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13081 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
13085 OMP_CLAUSE_CHAIN (l
) = clauses
;
13088 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
13092 OMP_FOR_CLAUSES (stmt
) = clauses
;
13097 while (!for_block
->is_empty ())
13099 /* FIXME diagnostics: LOC below should be the actual location of
13100 this particular for block. We need to build a list of
13101 locations to go along with FOR_BLOCK. */
13102 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
13105 release_tree_vector (for_block
);
13109 /* Helper function for OpenMP parsing, split clauses and call
13110 finish_omp_clauses on each of the set of clauses afterwards. */
13113 omp_split_clauses (location_t loc
, enum tree_code code
,
13114 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
13117 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
13118 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
13120 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
13124 #pragma omp simd simd-clause[optseq] new-line
13127 LOC is the location of the #pragma token.
13130 #define OMP_SIMD_CLAUSE_MASK \
13131 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
13132 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13133 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13134 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13135 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13136 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13137 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13140 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
13141 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13143 tree block
, clauses
, ret
;
13145 strcat (p_name
, " simd");
13146 mask
|= OMP_SIMD_CLAUSE_MASK
;
13147 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
13149 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13152 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
13153 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
13156 block
= c_begin_compound_stmt (true);
13157 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
13158 block
= c_end_compound_stmt (loc
, block
, true);
13165 #pragma omp for for-clause[optseq] new-line
13169 #pragma omp for simd for-simd-clause[optseq] new-line
13172 LOC is the location of the #pragma token.
13175 #define OMP_FOR_CLAUSE_MASK \
13176 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13177 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13178 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13179 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13180 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
13181 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
13182 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
13183 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13186 c_parser_omp_for (location_t loc
, c_parser
*parser
,
13187 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13189 tree block
, clauses
, ret
;
13191 strcat (p_name
, " for");
13192 mask
|= OMP_FOR_CLAUSE_MASK
;
13194 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13196 if (c_parser_next_token_is (parser
, CPP_NAME
))
13198 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13200 if (strcmp (p
, "simd") == 0)
13202 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13203 if (cclauses
== NULL
)
13204 cclauses
= cclauses_buf
;
13206 c_parser_consume_token (parser
);
13207 if (!flag_openmp
) /* flag_openmp_simd */
13208 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13209 block
= c_begin_compound_stmt (true);
13210 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13211 block
= c_end_compound_stmt (loc
, block
, true);
13212 if (ret
== NULL_TREE
)
13214 ret
= make_node (OMP_FOR
);
13215 TREE_TYPE (ret
) = void_type_node
;
13216 OMP_FOR_BODY (ret
) = block
;
13217 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13218 SET_EXPR_LOCATION (ret
, loc
);
13223 if (!flag_openmp
) /* flag_openmp_simd */
13225 c_parser_skip_to_pragma_eol (parser
, false);
13229 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13232 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
13233 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13236 block
= c_begin_compound_stmt (true);
13237 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
13238 block
= c_end_compound_stmt (loc
, block
, true);
13245 # pragma omp master new-line
13248 LOC is the location of the #pragma token.
13252 c_parser_omp_master (location_t loc
, c_parser
*parser
)
13254 c_parser_skip_to_pragma_eol (parser
);
13255 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
13259 # pragma omp ordered new-line
13262 LOC is the location of the #pragma itself.
13266 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
13268 c_parser_skip_to_pragma_eol (parser
);
13269 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
13275 { section-sequence }
13278 section-directive[opt] structured-block
13279 section-sequence section-directive structured-block
13281 SECTIONS_LOC is the location of the #pragma omp sections. */
13284 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
13286 tree stmt
, substmt
;
13287 bool error_suppress
= false;
13290 loc
= c_parser_peek_token (parser
)->location
;
13291 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
13293 /* Avoid skipping until the end of the block. */
13294 parser
->error
= false;
13298 stmt
= push_stmt_list ();
13300 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
13302 substmt
= c_parser_omp_structured_block (parser
);
13303 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13304 SET_EXPR_LOCATION (substmt
, loc
);
13305 add_stmt (substmt
);
13310 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13312 if (c_parser_next_token_is (parser
, CPP_EOF
))
13315 loc
= c_parser_peek_token (parser
)->location
;
13316 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
13318 c_parser_consume_pragma (parser
);
13319 c_parser_skip_to_pragma_eol (parser
);
13320 error_suppress
= false;
13322 else if (!error_suppress
)
13324 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
13325 error_suppress
= true;
13328 substmt
= c_parser_omp_structured_block (parser
);
13329 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13330 SET_EXPR_LOCATION (substmt
, loc
);
13331 add_stmt (substmt
);
13333 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
13334 "expected %<#pragma omp section%> or %<}%>");
13336 substmt
= pop_stmt_list (stmt
);
13338 stmt
= make_node (OMP_SECTIONS
);
13339 SET_EXPR_LOCATION (stmt
, sections_loc
);
13340 TREE_TYPE (stmt
) = void_type_node
;
13341 OMP_SECTIONS_BODY (stmt
) = substmt
;
13343 return add_stmt (stmt
);
13347 # pragma omp sections sections-clause[optseq] newline
13350 LOC is the location of the #pragma token.
13353 #define OMP_SECTIONS_CLAUSE_MASK \
13354 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13355 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13356 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13357 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13358 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13361 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
13362 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13364 tree block
, clauses
, ret
;
13366 strcat (p_name
, " sections");
13367 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
13369 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13371 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13374 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
13375 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
13378 block
= c_begin_compound_stmt (true);
13379 ret
= c_parser_omp_sections_scope (loc
, parser
);
13381 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
13382 block
= c_end_compound_stmt (loc
, block
, true);
13389 # pragma omp parallel parallel-clause[optseq] new-line
13391 # pragma omp parallel for parallel-for-clause[optseq] new-line
13393 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13397 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13400 LOC is the location of the #pragma token.
13403 #define OMP_PARALLEL_CLAUSE_MASK \
13404 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13405 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13406 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13407 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13408 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13409 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
13410 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13411 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
13412 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13415 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
13416 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13418 tree stmt
, clauses
, block
;
13420 strcat (p_name
, " parallel");
13421 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
13423 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
13425 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13426 if (cclauses
== NULL
)
13427 cclauses
= cclauses_buf
;
13429 c_parser_consume_token (parser
);
13430 if (!flag_openmp
) /* flag_openmp_simd */
13431 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13432 block
= c_begin_omp_parallel ();
13433 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13435 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13437 if (ret
== NULL_TREE
)
13439 OMP_PARALLEL_COMBINED (stmt
) = 1;
13444 error_at (loc
, "expected %<for%> after %qs", p_name
);
13445 c_parser_skip_to_pragma_eol (parser
);
13448 else if (!flag_openmp
) /* flag_openmp_simd */
13450 c_parser_skip_to_pragma_eol (parser
, false);
13453 else if (c_parser_next_token_is (parser
, CPP_NAME
))
13455 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13456 if (strcmp (p
, "sections") == 0)
13458 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13459 if (cclauses
== NULL
)
13460 cclauses
= cclauses_buf
;
13462 c_parser_consume_token (parser
);
13463 block
= c_begin_omp_parallel ();
13464 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
13465 stmt
= c_finish_omp_parallel (loc
,
13466 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13468 OMP_PARALLEL_COMBINED (stmt
) = 1;
13473 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13475 block
= c_begin_omp_parallel ();
13476 c_parser_statement (parser
);
13477 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
13483 # pragma omp single single-clause[optseq] new-line
13486 LOC is the location of the #pragma.
13489 #define OMP_SINGLE_CLAUSE_MASK \
13490 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13491 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13492 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
13493 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13496 c_parser_omp_single (location_t loc
, c_parser
*parser
)
13498 tree stmt
= make_node (OMP_SINGLE
);
13499 SET_EXPR_LOCATION (stmt
, loc
);
13500 TREE_TYPE (stmt
) = void_type_node
;
13502 OMP_SINGLE_CLAUSES (stmt
)
13503 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
13504 "#pragma omp single");
13505 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13507 return add_stmt (stmt
);
13511 # pragma omp task task-clause[optseq] new-line
13513 LOC is the location of the #pragma.
13516 #define OMP_TASK_CLAUSE_MASK \
13517 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13518 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
13519 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13520 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13521 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13522 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13523 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
13524 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
13525 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13528 c_parser_omp_task (location_t loc
, c_parser
*parser
)
13530 tree clauses
, block
;
13532 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
13533 "#pragma omp task");
13535 block
= c_begin_omp_task ();
13536 c_parser_statement (parser
);
13537 return c_finish_omp_task (loc
, clauses
, block
);
13541 # pragma omp taskwait new-line
13545 c_parser_omp_taskwait (c_parser
*parser
)
13547 location_t loc
= c_parser_peek_token (parser
)->location
;
13548 c_parser_consume_pragma (parser
);
13549 c_parser_skip_to_pragma_eol (parser
);
13551 c_finish_omp_taskwait (loc
);
13555 # pragma omp taskyield new-line
13559 c_parser_omp_taskyield (c_parser
*parser
)
13561 location_t loc
= c_parser_peek_token (parser
)->location
;
13562 c_parser_consume_pragma (parser
);
13563 c_parser_skip_to_pragma_eol (parser
);
13565 c_finish_omp_taskyield (loc
);
13569 # pragma omp taskgroup new-line
13573 c_parser_omp_taskgroup (c_parser
*parser
)
13575 location_t loc
= c_parser_peek_token (parser
)->location
;
13576 c_parser_skip_to_pragma_eol (parser
);
13577 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
13581 # pragma omp cancel cancel-clause[optseq] new-line
13583 LOC is the location of the #pragma.
13586 #define OMP_CANCEL_CLAUSE_MASK \
13587 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13588 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13589 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13590 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
13591 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13594 c_parser_omp_cancel (c_parser
*parser
)
13596 location_t loc
= c_parser_peek_token (parser
)->location
;
13598 c_parser_consume_pragma (parser
);
13599 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
13600 "#pragma omp cancel");
13602 c_finish_omp_cancel (loc
, clauses
);
13606 # pragma omp cancellation point cancelpt-clause[optseq] new-line
13608 LOC is the location of the #pragma.
13611 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
13612 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13618 c_parser_omp_cancellation_point (c_parser
*parser
)
13620 location_t loc
= c_parser_peek_token (parser
)->location
;
13622 bool point_seen
= false;
13624 c_parser_consume_pragma (parser
);
13625 if (c_parser_next_token_is (parser
, CPP_NAME
))
13627 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13628 if (strcmp (p
, "point") == 0)
13630 c_parser_consume_token (parser
);
13636 c_parser_error (parser
, "expected %<point%>");
13637 c_parser_skip_to_pragma_eol (parser
);
13642 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
13643 "#pragma omp cancellation point");
13645 c_finish_omp_cancellation_point (loc
, clauses
);
13649 #pragma omp distribute distribute-clause[optseq] new-line
13652 #define OMP_DISTRIBUTE_CLAUSE_MASK \
13653 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13654 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13655 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13656 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13659 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
13660 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13662 tree clauses
, block
, ret
;
13664 strcat (p_name
, " distribute");
13665 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
13667 if (c_parser_next_token_is (parser
, CPP_NAME
))
13669 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13671 bool parallel
= false;
13673 if (strcmp (p
, "simd") == 0)
13676 parallel
= strcmp (p
, "parallel") == 0;
13677 if (parallel
|| simd
)
13679 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13680 if (cclauses
== NULL
)
13681 cclauses
= cclauses_buf
;
13682 c_parser_consume_token (parser
);
13683 if (!flag_openmp
) /* flag_openmp_simd */
13686 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13688 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
13691 block
= c_begin_compound_stmt (true);
13693 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13695 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
13696 block
= c_end_compound_stmt (loc
, block
, true);
13699 ret
= make_node (OMP_DISTRIBUTE
);
13700 TREE_TYPE (ret
) = void_type_node
;
13701 OMP_FOR_BODY (ret
) = block
;
13702 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13703 SET_EXPR_LOCATION (ret
, loc
);
13708 if (!flag_openmp
) /* flag_openmp_simd */
13710 c_parser_skip_to_pragma_eol (parser
, false);
13714 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13717 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
13718 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13721 block
= c_begin_compound_stmt (true);
13722 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
13723 block
= c_end_compound_stmt (loc
, block
, true);
13730 # pragma omp teams teams-clause[optseq] new-line
13731 structured-block */
13733 #define OMP_TEAMS_CLAUSE_MASK \
13734 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13743 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
13744 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13746 tree clauses
, block
, ret
;
13748 strcat (p_name
, " teams");
13749 mask
|= OMP_TEAMS_CLAUSE_MASK
;
13751 if (c_parser_next_token_is (parser
, CPP_NAME
))
13753 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13754 if (strcmp (p
, "distribute") == 0)
13756 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13757 if (cclauses
== NULL
)
13758 cclauses
= cclauses_buf
;
13760 c_parser_consume_token (parser
);
13761 if (!flag_openmp
) /* flag_openmp_simd */
13762 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13763 block
= c_begin_compound_stmt (true);
13764 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13765 block
= c_end_compound_stmt (loc
, block
, true);
13768 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13769 ret
= make_node (OMP_TEAMS
);
13770 TREE_TYPE (ret
) = void_type_node
;
13771 OMP_TEAMS_CLAUSES (ret
) = clauses
;
13772 OMP_TEAMS_BODY (ret
) = block
;
13773 return add_stmt (ret
);
13776 if (!flag_openmp
) /* flag_openmp_simd */
13778 c_parser_skip_to_pragma_eol (parser
, false);
13782 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13785 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
13786 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13789 tree stmt
= make_node (OMP_TEAMS
);
13790 TREE_TYPE (stmt
) = void_type_node
;
13791 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
13792 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13794 return add_stmt (stmt
);
13798 # pragma omp target data target-data-clause[optseq] new-line
13799 structured-block */
13801 #define OMP_TARGET_DATA_CLAUSE_MASK \
13802 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13804 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13807 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
13809 tree stmt
= make_node (OMP_TARGET_DATA
);
13810 TREE_TYPE (stmt
) = void_type_node
;
13812 OMP_TARGET_DATA_CLAUSES (stmt
)
13813 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
13814 "#pragma omp target data");
13815 keep_next_level ();
13816 tree block
= c_begin_compound_stmt (true);
13817 add_stmt (c_parser_omp_structured_block (parser
));
13818 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13820 SET_EXPR_LOCATION (stmt
, loc
);
13821 return add_stmt (stmt
);
13825 # pragma omp target update target-update-clause[optseq] new-line */
13827 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13828 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13829 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13830 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13831 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13834 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
13835 enum pragma_context context
)
13837 if (context
== pragma_stmt
)
13840 "%<#pragma omp target update%> may only be "
13841 "used in compound statements");
13842 c_parser_skip_to_pragma_eol (parser
);
13847 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
13848 "#pragma omp target update");
13849 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
13850 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
13853 "%<#pragma omp target update%> must contain at least one "
13854 "%<from%> or %<to%> clauses");
13858 tree stmt
= make_node (OMP_TARGET_UPDATE
);
13859 TREE_TYPE (stmt
) = void_type_node
;
13860 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
13861 SET_EXPR_LOCATION (stmt
, loc
);
13867 # pragma omp target target-clause[optseq] new-line
13868 structured-block */
13870 #define OMP_TARGET_CLAUSE_MASK \
13871 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13872 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13873 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13876 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
13878 location_t loc
= c_parser_peek_token (parser
)->location
;
13879 c_parser_consume_pragma (parser
);
13881 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
13883 c_parser_error (parser
, "expected declaration specifiers");
13884 c_parser_skip_to_pragma_eol (parser
);
13888 if (c_parser_next_token_is (parser
, CPP_NAME
))
13890 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13892 if (strcmp (p
, "teams") == 0)
13894 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
13895 char p_name
[sizeof ("#pragma omp target teams distribute "
13896 "parallel for simd")];
13898 c_parser_consume_token (parser
);
13899 strcpy (p_name
, "#pragma omp target");
13900 if (!flag_openmp
) /* flag_openmp_simd */
13902 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
13903 OMP_TARGET_CLAUSE_MASK
,
13905 return stmt
!= NULL_TREE
;
13907 keep_next_level ();
13908 tree block
= c_begin_compound_stmt (true);
13909 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
13910 OMP_TARGET_CLAUSE_MASK
, cclauses
);
13911 block
= c_end_compound_stmt (loc
, block
, true);
13912 if (ret
== NULL_TREE
)
13914 tree stmt
= make_node (OMP_TARGET
);
13915 TREE_TYPE (stmt
) = void_type_node
;
13916 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
13917 OMP_TARGET_BODY (stmt
) = block
;
13921 else if (!flag_openmp
) /* flag_openmp_simd */
13923 c_parser_skip_to_pragma_eol (parser
, false);
13926 else if (strcmp (p
, "data") == 0)
13928 c_parser_consume_token (parser
);
13929 c_parser_omp_target_data (loc
, parser
);
13932 else if (strcmp (p
, "update") == 0)
13934 c_parser_consume_token (parser
);
13935 return c_parser_omp_target_update (loc
, parser
, context
);
13939 tree stmt
= make_node (OMP_TARGET
);
13940 TREE_TYPE (stmt
) = void_type_node
;
13942 OMP_TARGET_CLAUSES (stmt
)
13943 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
13944 "#pragma omp target");
13945 keep_next_level ();
13946 tree block
= c_begin_compound_stmt (true);
13947 add_stmt (c_parser_omp_structured_block (parser
));
13948 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13950 SET_EXPR_LOCATION (stmt
, loc
);
13956 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
13958 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
13959 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
13960 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13961 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13962 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
13963 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
13964 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
13967 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
13969 vec
<c_token
> clauses
= vNULL
;
13970 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13972 c_token
*token
= c_parser_peek_token (parser
);
13973 if (token
->type
== CPP_EOF
)
13975 c_parser_skip_to_pragma_eol (parser
);
13976 clauses
.release ();
13979 clauses
.safe_push (*token
);
13980 c_parser_consume_token (parser
);
13982 clauses
.safe_push (*c_parser_peek_token (parser
));
13983 c_parser_skip_to_pragma_eol (parser
);
13985 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
13987 if (c_parser_peek_token (parser
)->pragma_kind
13988 != PRAGMA_OMP_DECLARE_REDUCTION
13989 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
13990 || strcmp (IDENTIFIER_POINTER
13991 (c_parser_peek_2nd_token (parser
)->value
),
13994 c_parser_error (parser
,
13995 "%<#pragma omp declare simd%> must be followed by "
13996 "function declaration or definition or another "
13997 "%<#pragma omp declare simd%>");
13998 clauses
.release ();
14001 c_parser_consume_pragma (parser
);
14002 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14004 c_token
*token
= c_parser_peek_token (parser
);
14005 if (token
->type
== CPP_EOF
)
14007 c_parser_skip_to_pragma_eol (parser
);
14008 clauses
.release ();
14011 clauses
.safe_push (*token
);
14012 c_parser_consume_token (parser
);
14014 clauses
.safe_push (*c_parser_peek_token (parser
));
14015 c_parser_skip_to_pragma_eol (parser
);
14018 /* Make sure nothing tries to read past the end of the tokens. */
14020 memset (&eof_token
, 0, sizeof (eof_token
));
14021 eof_token
.type
= CPP_EOF
;
14022 clauses
.safe_push (eof_token
);
14023 clauses
.safe_push (eof_token
);
14027 case pragma_external
:
14028 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14029 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14031 int ext
= disable_extension_diagnostics ();
14033 c_parser_consume_token (parser
);
14034 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14035 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14036 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14038 restore_extension_diagnostics (ext
);
14041 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14044 case pragma_struct
:
14046 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14047 "function declaration or definition");
14049 case pragma_compound
:
14051 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14052 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14054 int ext
= disable_extension_diagnostics ();
14056 c_parser_consume_token (parser
);
14057 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14058 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14059 if (c_parser_next_tokens_start_declaration (parser
))
14061 c_parser_declaration_or_fndef (parser
, true, true, true, true,
14062 true, NULL
, clauses
);
14063 restore_extension_diagnostics (ext
);
14066 restore_extension_diagnostics (ext
);
14068 else if (c_parser_next_tokens_start_declaration (parser
))
14070 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14074 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14075 "function declaration or definition");
14078 gcc_unreachable ();
14080 clauses
.release ();
14083 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
14084 and put that into "omp declare simd" attribute. */
14087 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
14088 vec
<c_token
> clauses
)
14091 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14093 error ("%<#pragma omp declare simd%> cannot be used in the same "
14094 "function marked as a Cilk Plus SIMD-enabled function");
14095 vec_free (parser
->cilk_simd_fn_tokens
);
14099 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
14100 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
14101 has already processed the tokens. */
14102 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
14104 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14106 error ("%<#pragma omp declare simd%> not immediately followed by "
14107 "a function declaration or definition");
14108 clauses
[0].type
= CPP_EOF
;
14111 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
14113 error_at (DECL_SOURCE_LOCATION (fndecl
),
14114 "%<#pragma omp declare simd%> not immediately followed by "
14115 "a single function declaration or definition");
14116 clauses
[0].type
= CPP_EOF
;
14120 if (parms
== NULL_TREE
)
14121 parms
= DECL_ARGUMENTS (fndecl
);
14123 unsigned int tokens_avail
= parser
->tokens_avail
;
14124 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14125 bool is_cilkplus_cilk_simd_fn
= false;
14127 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14129 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
14130 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
14131 is_cilkplus_cilk_simd_fn
= true;
14135 parser
->tokens
= clauses
.address ();
14136 parser
->tokens_avail
= clauses
.length ();
14139 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
14140 while (parser
->tokens_avail
> 3)
14142 c_token
*token
= c_parser_peek_token (parser
);
14143 if (!is_cilkplus_cilk_simd_fn
)
14144 gcc_assert (token
->type
== CPP_NAME
14145 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
14147 gcc_assert (token
->type
== CPP_NAME
14148 && is_cilkplus_vector_p (token
->value
));
14149 c_parser_consume_token (parser
);
14150 parser
->in_pragma
= true;
14152 tree c
= NULL_TREE
;
14153 if (is_cilkplus_cilk_simd_fn
)
14154 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
14155 "SIMD-enabled functions attribute");
14157 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
14158 "#pragma omp declare simd");
14159 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
14160 if (c
!= NULL_TREE
)
14161 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
14162 if (is_cilkplus_cilk_simd_fn
)
14164 tree k
= build_tree_list (get_identifier ("cilk simd function"),
14166 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
14167 DECL_ATTRIBUTES (fndecl
) = k
;
14169 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
14170 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
14171 DECL_ATTRIBUTES (fndecl
) = c
;
14174 parser
->tokens
= &parser
->tokens_buf
[0];
14175 parser
->tokens_avail
= tokens_avail
;
14176 if (clauses
.exists ())
14177 clauses
[0].type
= CPP_PRAGMA
;
14179 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14180 vec_free (parser
->cilk_simd_fn_tokens
);
14185 # pragma omp declare target new-line
14186 declarations and definitions
14187 # pragma omp end declare target new-line */
14190 c_parser_omp_declare_target (c_parser
*parser
)
14192 c_parser_skip_to_pragma_eol (parser
);
14193 current_omp_declare_target_attribute
++;
14197 c_parser_omp_end_declare_target (c_parser
*parser
)
14199 location_t loc
= c_parser_peek_token (parser
)->location
;
14200 c_parser_consume_pragma (parser
);
14201 if (c_parser_next_token_is (parser
, CPP_NAME
)
14202 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14205 c_parser_consume_token (parser
);
14206 if (c_parser_next_token_is (parser
, CPP_NAME
)
14207 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14209 c_parser_consume_token (parser
);
14212 c_parser_error (parser
, "expected %<target%>");
14213 c_parser_skip_to_pragma_eol (parser
);
14219 c_parser_error (parser
, "expected %<declare%>");
14220 c_parser_skip_to_pragma_eol (parser
);
14223 c_parser_skip_to_pragma_eol (parser
);
14224 if (!current_omp_declare_target_attribute
)
14225 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
14226 "%<#pragma omp declare target%>");
14228 current_omp_declare_target_attribute
--;
14233 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14234 initializer-clause[opt] new-line
14236 initializer-clause:
14237 initializer (omp_priv = initializer)
14238 initializer (function-name (argument-list)) */
14241 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
14243 unsigned int tokens_avail
= 0, i
;
14244 vec
<tree
> types
= vNULL
;
14245 vec
<c_token
> clauses
= vNULL
;
14246 enum tree_code reduc_code
= ERROR_MARK
;
14247 tree reduc_id
= NULL_TREE
;
14249 location_t rloc
= c_parser_peek_token (parser
)->location
;
14251 if (context
== pragma_struct
|| context
== pragma_param
)
14253 error ("%<#pragma omp declare reduction%> not at file or block scope");
14257 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14260 switch (c_parser_peek_token (parser
)->type
)
14263 reduc_code
= PLUS_EXPR
;
14266 reduc_code
= MULT_EXPR
;
14269 reduc_code
= MINUS_EXPR
;
14272 reduc_code
= BIT_AND_EXPR
;
14275 reduc_code
= BIT_XOR_EXPR
;
14278 reduc_code
= BIT_IOR_EXPR
;
14281 reduc_code
= TRUTH_ANDIF_EXPR
;
14284 reduc_code
= TRUTH_ORIF_EXPR
;
14288 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14289 if (strcmp (p
, "min") == 0)
14291 reduc_code
= MIN_EXPR
;
14294 if (strcmp (p
, "max") == 0)
14296 reduc_code
= MAX_EXPR
;
14299 reduc_id
= c_parser_peek_token (parser
)->value
;
14302 c_parser_error (parser
,
14303 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14304 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14308 tree orig_reduc_id
, reduc_decl
;
14309 orig_reduc_id
= reduc_id
;
14310 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
14311 reduc_decl
= c_omp_reduction_decl (reduc_id
);
14312 c_parser_consume_token (parser
);
14314 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14319 location_t loc
= c_parser_peek_token (parser
)->location
;
14320 struct c_type_name
*ctype
= c_parser_type_name (parser
);
14323 type
= groktypename (ctype
, NULL
, NULL
);
14324 if (type
== error_mark_node
)
14326 else if ((INTEGRAL_TYPE_P (type
)
14327 || TREE_CODE (type
) == REAL_TYPE
14328 || TREE_CODE (type
) == COMPLEX_TYPE
)
14329 && orig_reduc_id
== NULL_TREE
)
14330 error_at (loc
, "predeclared arithmetic type in "
14331 "%<#pragma omp declare reduction%>");
14332 else if (TREE_CODE (type
) == FUNCTION_TYPE
14333 || TREE_CODE (type
) == ARRAY_TYPE
)
14334 error_at (loc
, "function or array type in "
14335 "%<#pragma omp declare reduction%>");
14336 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
14337 error_at (loc
, "const, volatile or restrict qualified type in "
14338 "%<#pragma omp declare reduction%>");
14342 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
14343 if (comptypes (TREE_PURPOSE (t
), type
))
14345 error_at (loc
, "redeclaration of %qs "
14346 "%<#pragma omp declare reduction%> for "
14348 IDENTIFIER_POINTER (reduc_id
)
14349 + sizeof ("omp declare reduction ") - 1,
14352 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
14354 error_at (ploc
, "previous %<#pragma omp declare "
14358 if (t
== NULL_TREE
)
14359 types
.safe_push (type
);
14361 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14362 c_parser_consume_token (parser
);
14370 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
14371 || types
.is_empty ())
14374 clauses
.release ();
14378 c_token
*token
= c_parser_peek_token (parser
);
14379 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
14381 c_parser_consume_token (parser
);
14383 c_parser_skip_to_pragma_eol (parser
);
14387 if (types
.length () > 1)
14389 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14391 c_token
*token
= c_parser_peek_token (parser
);
14392 if (token
->type
== CPP_EOF
)
14394 clauses
.safe_push (*token
);
14395 c_parser_consume_token (parser
);
14397 clauses
.safe_push (*c_parser_peek_token (parser
));
14398 c_parser_skip_to_pragma_eol (parser
);
14400 /* Make sure nothing tries to read past the end of the tokens. */
14402 memset (&eof_token
, 0, sizeof (eof_token
));
14403 eof_token
.type
= CPP_EOF
;
14404 clauses
.safe_push (eof_token
);
14405 clauses
.safe_push (eof_token
);
14408 int errs
= errorcount
;
14409 FOR_EACH_VEC_ELT (types
, i
, type
)
14411 tokens_avail
= parser
->tokens_avail
;
14412 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14413 if (!clauses
.is_empty ())
14415 parser
->tokens
= clauses
.address ();
14416 parser
->tokens_avail
= clauses
.length ();
14417 parser
->in_pragma
= true;
14420 bool nested
= current_function_decl
!= NULL_TREE
;
14422 c_push_function_context ();
14423 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
14424 reduc_id
, default_function_type
);
14425 current_function_decl
= fndecl
;
14426 allocate_struct_function (fndecl
, true);
14428 tree stmt
= push_stmt_list ();
14429 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14430 warn about these. */
14431 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14432 get_identifier ("omp_out"), type
);
14433 DECL_ARTIFICIAL (omp_out
) = 1;
14434 DECL_CONTEXT (omp_out
) = fndecl
;
14435 pushdecl (omp_out
);
14436 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14437 get_identifier ("omp_in"), type
);
14438 DECL_ARTIFICIAL (omp_in
) = 1;
14439 DECL_CONTEXT (omp_in
) = fndecl
;
14441 struct c_expr combiner
= c_parser_expression (parser
);
14442 struct c_expr initializer
;
14443 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
14445 initializer
.value
= error_mark_node
;
14446 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14448 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14449 && strcmp (IDENTIFIER_POINTER
14450 (c_parser_peek_token (parser
)->value
),
14451 "initializer") == 0)
14453 c_parser_consume_token (parser
);
14456 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14457 get_identifier ("omp_priv"), type
);
14458 DECL_ARTIFICIAL (omp_priv
) = 1;
14459 DECL_INITIAL (omp_priv
) = error_mark_node
;
14460 DECL_CONTEXT (omp_priv
) = fndecl
;
14461 pushdecl (omp_priv
);
14462 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14463 get_identifier ("omp_orig"), type
);
14464 DECL_ARTIFICIAL (omp_orig
) = 1;
14465 DECL_CONTEXT (omp_orig
) = fndecl
;
14466 pushdecl (omp_orig
);
14467 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14469 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
14471 c_parser_error (parser
, "expected %<omp_priv%> or "
14475 else if (strcmp (IDENTIFIER_POINTER
14476 (c_parser_peek_token (parser
)->value
),
14479 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
14480 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14482 c_parser_error (parser
, "expected function-name %<(%>");
14486 initializer
= c_parser_postfix_expression (parser
);
14487 if (initializer
.value
14488 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
14491 tree c
= initializer
.value
;
14492 for (j
= 0; j
< call_expr_nargs (c
); j
++)
14493 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
14494 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
14496 if (j
== call_expr_nargs (c
))
14497 error ("one of the initializer call arguments should be "
14503 c_parser_consume_token (parser
);
14504 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14508 tree st
= push_stmt_list ();
14509 start_init (omp_priv
, NULL_TREE
, 0);
14510 location_t loc
= c_parser_peek_token (parser
)->location
;
14511 struct c_expr init
= c_parser_initializer (parser
);
14513 finish_decl (omp_priv
, loc
, init
.value
,
14514 init
.original_type
, NULL_TREE
);
14515 pop_stmt_list (st
);
14519 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14525 c_parser_skip_to_pragma_eol (parser
);
14527 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
14528 DECL_INITIAL (reduc_decl
));
14529 DECL_INITIAL (reduc_decl
) = t
;
14530 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
14531 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
14532 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
14533 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
14534 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
14535 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
14538 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
14539 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
14540 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
14541 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
14542 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
14543 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14544 walk_tree (&DECL_INITIAL (omp_priv
),
14545 c_check_omp_declare_reduction_r
,
14546 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14550 pop_stmt_list (stmt
);
14552 if (cfun
->language
!= NULL
)
14554 ggc_free (cfun
->language
);
14555 cfun
->language
= NULL
;
14558 current_function_decl
= NULL_TREE
;
14560 c_pop_function_context ();
14562 if (!clauses
.is_empty ())
14564 parser
->tokens
= &parser
->tokens_buf
[0];
14565 parser
->tokens_avail
= tokens_avail
;
14569 if (errs
!= errorcount
)
14573 clauses
.release ();
14579 #pragma omp declare simd declare-simd-clauses[optseq] new-line
14580 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14581 initializer-clause[opt] new-line
14582 #pragma omp declare target new-line */
14585 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
14587 c_parser_consume_pragma (parser
);
14588 if (c_parser_next_token_is (parser
, CPP_NAME
))
14590 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14591 if (strcmp (p
, "simd") == 0)
14593 /* c_parser_consume_token (parser); done in
14594 c_parser_omp_declare_simd. */
14595 c_parser_omp_declare_simd (parser
, context
);
14598 if (strcmp (p
, "reduction") == 0)
14600 c_parser_consume_token (parser
);
14601 c_parser_omp_declare_reduction (parser
, context
);
14604 if (!flag_openmp
) /* flag_openmp_simd */
14606 c_parser_skip_to_pragma_eol (parser
, false);
14609 if (strcmp (p
, "target") == 0)
14611 c_parser_consume_token (parser
);
14612 c_parser_omp_declare_target (parser
);
14617 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
14619 c_parser_skip_to_pragma_eol (parser
);
14622 /* Main entry point to parsing most OpenMP pragmas. */
14625 c_parser_omp_construct (c_parser
*parser
)
14627 enum pragma_kind p_kind
;
14630 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
14631 omp_clause_mask
mask (0);
14633 loc
= c_parser_peek_token (parser
)->location
;
14634 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
14635 c_parser_consume_pragma (parser
);
14639 case PRAGMA_OACC_CACHE
:
14640 strcpy (p_name
, "#pragma acc");
14641 stmt
= c_parser_oacc_cache (loc
, parser
);
14643 case PRAGMA_OACC_DATA
:
14644 stmt
= c_parser_oacc_data (loc
, parser
);
14646 case PRAGMA_OACC_KERNELS
:
14647 strcpy (p_name
, "#pragma acc");
14648 stmt
= c_parser_oacc_kernels (loc
, parser
, p_name
);
14650 case PRAGMA_OACC_LOOP
:
14651 strcpy (p_name
, "#pragma acc");
14652 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
);
14654 case PRAGMA_OACC_PARALLEL
:
14655 strcpy (p_name
, "#pragma acc");
14656 stmt
= c_parser_oacc_parallel (loc
, parser
, p_name
);
14658 case PRAGMA_OACC_WAIT
:
14659 strcpy (p_name
, "#pragma wait");
14660 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
14662 case PRAGMA_OMP_ATOMIC
:
14663 c_parser_omp_atomic (loc
, parser
);
14665 case PRAGMA_OMP_CRITICAL
:
14666 stmt
= c_parser_omp_critical (loc
, parser
);
14668 case PRAGMA_OMP_DISTRIBUTE
:
14669 strcpy (p_name
, "#pragma omp");
14670 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
14672 case PRAGMA_OMP_FOR
:
14673 strcpy (p_name
, "#pragma omp");
14674 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
14676 case PRAGMA_OMP_MASTER
:
14677 stmt
= c_parser_omp_master (loc
, parser
);
14679 case PRAGMA_OMP_ORDERED
:
14680 stmt
= c_parser_omp_ordered (loc
, parser
);
14682 case PRAGMA_OMP_PARALLEL
:
14683 strcpy (p_name
, "#pragma omp");
14684 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
14686 case PRAGMA_OMP_SECTIONS
:
14687 strcpy (p_name
, "#pragma omp");
14688 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
14690 case PRAGMA_OMP_SIMD
:
14691 strcpy (p_name
, "#pragma omp");
14692 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
14694 case PRAGMA_OMP_SINGLE
:
14695 stmt
= c_parser_omp_single (loc
, parser
);
14697 case PRAGMA_OMP_TASK
:
14698 stmt
= c_parser_omp_task (loc
, parser
);
14700 case PRAGMA_OMP_TASKGROUP
:
14701 stmt
= c_parser_omp_taskgroup (parser
);
14703 case PRAGMA_OMP_TEAMS
:
14704 strcpy (p_name
, "#pragma omp");
14705 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
14708 gcc_unreachable ();
14712 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
14717 # pragma omp threadprivate (variable-list) */
14720 c_parser_omp_threadprivate (c_parser
*parser
)
14725 c_parser_consume_pragma (parser
);
14726 loc
= c_parser_peek_token (parser
)->location
;
14727 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14729 /* Mark every variable in VARS to be assigned thread local storage. */
14730 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
14732 tree v
= TREE_PURPOSE (t
);
14734 /* FIXME diagnostics: Ideally we should keep individual
14735 locations for all the variables in the var list to make the
14736 following errors more precise. Perhaps
14737 c_parser_omp_var_list_parens() should construct a list of
14738 locations to go along with the var list. */
14740 /* If V had already been marked threadprivate, it doesn't matter
14741 whether it had been used prior to this point. */
14742 if (TREE_CODE (v
) != VAR_DECL
)
14743 error_at (loc
, "%qD is not a variable", v
);
14744 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
14745 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
14746 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
14747 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
14748 else if (TREE_TYPE (v
) == error_mark_node
)
14750 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
14751 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
14754 if (! DECL_THREAD_LOCAL_P (v
))
14756 set_decl_tls_model (v
, decl_default_tls_model (v
));
14757 /* If rtl has been already set for this var, call
14758 make_decl_rtl once again, so that encode_section_info
14759 has a chance to look at the new decl flags. */
14760 if (DECL_RTL_SET_P (v
))
14763 C_DECL_THREADPRIVATE_P (v
) = 1;
14767 c_parser_skip_to_pragma_eol (parser
);
14770 /* Cilk Plus <#pragma simd> parsing routines. */
14772 /* Helper function for c_parser_pragma. Perform some sanity checking
14773 for <#pragma simd> constructs. Returns FALSE if there was a
14777 c_parser_cilk_verify_simd (c_parser
*parser
,
14778 enum pragma_context context
)
14780 if (!flag_cilkplus
)
14782 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14783 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14786 if (context
== pragma_external
)
14788 c_parser_error (parser
,"pragma simd must be inside a function");
14789 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14796 This function is shared by SIMD-enabled functions and #pragma simd.
14797 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14798 CLAUSES is unused. The main purpose of this function is to parse a
14799 vectorlength attribute or clause and check for parse errors.
14800 When IS_SIMD_FN is true then the function is merely caching the tokens
14801 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14802 cache is cleared since there is no reason to continue.
14804 vectorlength ( constant-expression ) */
14807 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
14811 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
14813 /* The vectorlength clause behaves exactly like OpenMP's safelen
14814 clause. Represent it in OpenMP terms. */
14815 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
14817 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14820 location_t loc
= c_parser_peek_token (parser
)->location
;
14821 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14822 expr
= c_fully_fold (expr
, false, NULL
);
14824 /* If expr is an error_mark_node then the above function would have
14825 emitted an error. No reason to do it twice. */
14826 if (expr
== error_mark_node
)
14828 else if (!TREE_TYPE (expr
)
14829 || !TREE_CONSTANT (expr
)
14830 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
14832 error_at (loc
, "vectorlength must be an integer constant");
14833 else if (wi::exact_log2 (expr
) == -1)
14834 error_at (loc
, "vectorlength must be a power of 2");
14839 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
14840 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
14841 OMP_CLAUSE_CHAIN (u
) = clauses
;
14846 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
14847 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
14848 OMP_CLAUSE_CHAIN (u
) = clauses
;
14853 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14859 linear ( simd-linear-variable-list )
14861 simd-linear-variable-list:
14862 simd-linear-variable
14863 simd-linear-variable-list , simd-linear-variable
14865 simd-linear-variable:
14867 id-expression : simd-linear-step
14870 conditional-expression */
14873 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
14875 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14878 location_t loc
= c_parser_peek_token (parser
)->location
;
14880 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14881 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14882 c_parser_error (parser
, "expected identifier");
14884 while (c_parser_next_token_is (parser
, CPP_NAME
)
14885 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14887 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
14891 undeclared_variable (c_parser_peek_token (parser
)->location
,
14892 c_parser_peek_token (parser
)->value
);
14893 c_parser_consume_token (parser
);
14895 else if (var
== error_mark_node
)
14896 c_parser_consume_token (parser
);
14899 tree step
= integer_one_node
;
14901 /* Parse the linear step if present. */
14902 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14904 c_parser_consume_token (parser
);
14905 c_parser_consume_token (parser
);
14907 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14908 expr
= c_fully_fold (expr
, false, NULL
);
14910 if (TREE_TYPE (expr
)
14911 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
14912 && (TREE_CONSTANT (expr
)
14916 c_parser_error (parser
,
14917 "step size must be an integer constant "
14918 "expression or an integer variable");
14921 c_parser_consume_token (parser
);
14923 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
14924 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
14925 OMP_CLAUSE_DECL (u
) = var
;
14926 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
14927 OMP_CLAUSE_CHAIN (u
) = clauses
;
14931 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
14934 c_parser_consume_token (parser
);
14937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14942 /* Returns the name of the next clause. If the clause is not
14943 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14944 not consumed. Otherwise, the appropriate pragma_simd_clause is
14945 returned and the token is consumed. */
14947 static pragma_omp_clause
14948 c_parser_cilk_clause_name (c_parser
*parser
)
14950 pragma_omp_clause result
;
14951 c_token
*token
= c_parser_peek_token (parser
);
14953 if (!token
->value
|| token
->type
!= CPP_NAME
)
14954 return PRAGMA_CILK_CLAUSE_NONE
;
14956 const char *p
= IDENTIFIER_POINTER (token
->value
);
14958 if (!strcmp (p
, "vectorlength"))
14959 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
14960 else if (!strcmp (p
, "linear"))
14961 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
14962 else if (!strcmp (p
, "private"))
14963 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
14964 else if (!strcmp (p
, "firstprivate"))
14965 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
14966 else if (!strcmp (p
, "lastprivate"))
14967 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
14968 else if (!strcmp (p
, "reduction"))
14969 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
14971 return PRAGMA_CILK_CLAUSE_NONE
;
14973 c_parser_consume_token (parser
);
14977 /* Parse all #<pragma simd> clauses. Return the list of clauses
14981 c_parser_cilk_all_clauses (c_parser
*parser
)
14983 tree clauses
= NULL
;
14985 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14987 pragma_omp_clause c_kind
;
14989 c_kind
= c_parser_cilk_clause_name (parser
);
14993 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
14994 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
14996 case PRAGMA_CILK_CLAUSE_LINEAR
:
14997 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
14999 case PRAGMA_CILK_CLAUSE_PRIVATE
:
15000 /* Use the OpenMP counterpart. */
15001 clauses
= c_parser_omp_clause_private (parser
, clauses
);
15003 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
15004 /* Use the OpenMP counterpart. */
15005 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
15007 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
15008 /* Use the OpenMP counterpart. */
15009 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
15011 case PRAGMA_CILK_CLAUSE_REDUCTION
:
15012 /* Use the OpenMP counterpart. */
15013 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
15016 c_parser_error (parser
, "expected %<#pragma simd%> clause");
15022 c_parser_skip_to_pragma_eol (parser
);
15023 return c_finish_cilk_clauses (clauses
);
15026 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
15027 Here is the correct syntax of this pragma:
15028 #pragma cilk grainsize = <EXP>
15032 c_parser_cilk_grainsize (c_parser
*parser
)
15034 extern tree
convert_to_integer (tree
, tree
);
15036 /* consume the 'grainsize' keyword. */
15037 c_parser_consume_pragma (parser
);
15039 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
15041 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
15042 if (g_expr
.value
== error_mark_node
)
15044 c_parser_skip_to_pragma_eol (parser
);
15047 tree grain
= convert_to_integer (long_integer_type_node
,
15048 c_fully_fold (g_expr
.value
, false,
15050 c_parser_skip_to_pragma_eol (parser
);
15051 c_token
*token
= c_parser_peek_token (parser
);
15052 if (token
&& token
->type
== CPP_KEYWORD
15053 && token
->keyword
== RID_CILK_FOR
)
15055 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
15056 grain
= integer_zero_node
;
15057 c_parser_cilk_for (parser
, grain
);
15060 warning (0, "%<#pragma cilk grainsize%> is not followed by "
15064 c_parser_skip_to_pragma_eol (parser
);
15067 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
15070 c_parser_cilk_simd (c_parser
*parser
)
15072 tree clauses
= c_parser_cilk_all_clauses (parser
);
15073 tree block
= c_begin_compound_stmt (true);
15074 location_t loc
= c_parser_peek_token (parser
)->location
;
15075 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
15076 block
= c_end_compound_stmt (loc
, block
, true);
15080 /* Create an artificial decl with TYPE and emit initialization of it with
15084 c_get_temp_regvar (tree type
, tree init
)
15086 location_t loc
= EXPR_LOCATION (init
);
15087 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
15088 DECL_ARTIFICIAL (decl
) = 1;
15089 DECL_IGNORED_P (decl
) = 1;
15091 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
15096 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
15097 GRAIN is the grain value passed in through pragma or 0. */
15100 c_parser_cilk_for (c_parser
*parser
, tree grain
)
15102 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
15103 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
15104 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
15105 clauses
= c_finish_omp_clauses (clauses
);
15107 tree block
= c_begin_compound_stmt (true);
15108 tree sb
= push_stmt_list ();
15109 location_t loc
= c_parser_peek_token (parser
)->location
;
15110 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
15111 sb
= pop_stmt_list (sb
);
15115 tree omp_par
= make_node (OMP_PARALLEL
);
15116 TREE_TYPE (omp_par
) = void_type_node
;
15117 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
15118 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
15119 TREE_SIDE_EFFECTS (bind
) = 1;
15120 BIND_EXPR_BODY (bind
) = sb
;
15121 OMP_PARALLEL_BODY (omp_par
) = bind
;
15122 if (OMP_FOR_PRE_BODY (omp_for
))
15124 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
15125 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
15127 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
15128 tree decl
= TREE_OPERAND (init
, 0);
15129 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
15130 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
15131 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
15132 if (TREE_CODE (t
) != INTEGER_CST
)
15134 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15135 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15136 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
15137 OMP_CLAUSE_CHAIN (c
) = clauses
;
15140 if (TREE_CODE (incr
) == MODIFY_EXPR
)
15142 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15143 if (TREE_CODE (t
) != INTEGER_CST
)
15145 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
15146 = c_get_temp_regvar (TREE_TYPE (t
), t
);
15147 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15148 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15149 OMP_CLAUSE_CHAIN (c
) = clauses
;
15153 t
= TREE_OPERAND (init
, 1);
15154 if (TREE_CODE (t
) != INTEGER_CST
)
15156 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15157 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15158 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
15159 OMP_CLAUSE_CHAIN (c
) = clauses
;
15162 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
15163 OMP_CLAUSE_DECL (c
) = decl
;
15164 OMP_CLAUSE_CHAIN (c
) = clauses
;
15166 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
15167 OMP_CLAUSE_OPERAND (c
, 0)
15168 = cilk_for_number_of_iterations (omp_for
);
15169 OMP_CLAUSE_CHAIN (c
) = clauses
;
15170 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
);
15171 add_stmt (omp_par
);
15174 block
= c_end_compound_stmt (loc
, block
, true);
15179 /* Parse a transaction attribute (GCC Extension).
15181 transaction-attribute:
15185 The transactional memory language description is written for C++,
15186 and uses the C++0x attribute syntax. For compatibility, allow the
15187 bracket style for transactions in C as well. */
15190 c_parser_transaction_attributes (c_parser
*parser
)
15192 tree attr_name
, attr
= NULL
;
15194 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
15195 return c_parser_attributes (parser
);
15197 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
15199 c_parser_consume_token (parser
);
15200 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
15203 attr_name
= c_parser_attribute_any_word (parser
);
15206 c_parser_consume_token (parser
);
15207 attr
= build_tree_list (attr_name
, NULL_TREE
);
15210 c_parser_error (parser
, "expected identifier");
15212 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15214 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15218 /* Parse a __transaction_atomic or __transaction_relaxed statement
15221 transaction-statement:
15222 __transaction_atomic transaction-attribute[opt] compound-statement
15223 __transaction_relaxed compound-statement
15225 Note that the only valid attribute is: "outer".
15229 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
15231 unsigned int old_in
= parser
->in_transaction
;
15232 unsigned int this_in
= 1, new_in
;
15233 location_t loc
= c_parser_peek_token (parser
)->location
;
15236 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15237 || keyword
== RID_TRANSACTION_RELAXED
)
15238 && c_parser_next_token_is_keyword (parser
, keyword
));
15239 c_parser_consume_token (parser
);
15241 if (keyword
== RID_TRANSACTION_RELAXED
)
15242 this_in
|= TM_STMT_ATTR_RELAXED
;
15245 attrs
= c_parser_transaction_attributes (parser
);
15247 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
15250 /* Keep track if we're in the lexical scope of an outer transaction. */
15251 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
15253 parser
->in_transaction
= new_in
;
15254 stmt
= c_parser_compound_statement (parser
);
15255 parser
->in_transaction
= old_in
;
15258 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
15260 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15261 "%<__transaction_atomic%> without transactional memory support enabled"
15262 : "%<__transaction_relaxed %> "
15263 "without transactional memory support enabled"));
15268 /* Parse a __transaction_atomic or __transaction_relaxed expression
15271 transaction-expression:
15272 __transaction_atomic ( expression )
15273 __transaction_relaxed ( expression )
15276 static struct c_expr
15277 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
15280 unsigned int old_in
= parser
->in_transaction
;
15281 unsigned int this_in
= 1;
15282 location_t loc
= c_parser_peek_token (parser
)->location
;
15285 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15286 || keyword
== RID_TRANSACTION_RELAXED
)
15287 && c_parser_next_token_is_keyword (parser
, keyword
));
15288 c_parser_consume_token (parser
);
15290 if (keyword
== RID_TRANSACTION_RELAXED
)
15291 this_in
|= TM_STMT_ATTR_RELAXED
;
15294 attrs
= c_parser_transaction_attributes (parser
);
15296 this_in
|= parse_tm_stmt_attr (attrs
, 0);
15299 parser
->in_transaction
= this_in
;
15300 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15302 tree expr
= c_parser_expression (parser
).value
;
15303 ret
.original_type
= TREE_TYPE (expr
);
15304 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
15305 if (this_in
& TM_STMT_ATTR_RELAXED
)
15306 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
15307 SET_EXPR_LOCATION (ret
.value
, loc
);
15308 ret
.original_code
= TRANSACTION_EXPR
;
15309 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15311 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
15318 ret
.value
= error_mark_node
;
15319 ret
.original_code
= ERROR_MARK
;
15320 ret
.original_type
= NULL
;
15322 parser
->in_transaction
= old_in
;
15325 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15326 "%<__transaction_atomic%> without transactional memory support enabled"
15327 : "%<__transaction_relaxed %> "
15328 "without transactional memory support enabled"));
15333 /* Parse a __transaction_cancel statement (GCC Extension).
15335 transaction-cancel-statement:
15336 __transaction_cancel transaction-attribute[opt] ;
15338 Note that the only valid attribute is "outer".
15342 c_parser_transaction_cancel (c_parser
*parser
)
15344 location_t loc
= c_parser_peek_token (parser
)->location
;
15346 bool is_outer
= false;
15348 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
15349 c_parser_consume_token (parser
);
15351 attrs
= c_parser_transaction_attributes (parser
);
15353 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
15357 error_at (loc
, "%<__transaction_cancel%> without "
15358 "transactional memory support enabled");
15361 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
15363 error_at (loc
, "%<__transaction_cancel%> within a "
15364 "%<__transaction_relaxed%>");
15369 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
15370 && !is_tm_may_cancel_outer (current_function_decl
))
15372 error_at (loc
, "outer %<__transaction_cancel%> not "
15373 "within outer %<__transaction_atomic%>");
15374 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
15378 else if (parser
->in_transaction
== 0)
15380 error_at (loc
, "%<__transaction_cancel%> not within "
15381 "%<__transaction_atomic%>");
15385 return add_stmt (build_tm_abort_call (loc
, is_outer
));
15388 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
15391 /* Parse a single source file. */
15394 c_parse_file (void)
15396 /* Use local storage to begin. If the first token is a pragma, parse it.
15397 If it is #pragma GCC pch_preprocess, then this will load a PCH file
15398 which will cause garbage collection. */
15401 memset (&tparser
, 0, sizeof tparser
);
15402 tparser
.tokens
= &tparser
.tokens_buf
[0];
15403 the_parser
= &tparser
;
15405 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
15406 c_parser_pragma_pch_preprocess (&tparser
);
15408 the_parser
= ggc_alloc
<c_parser
> ();
15409 *the_parser
= tparser
;
15410 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
15411 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
15413 /* Initialize EH, if we've been told to do so. */
15414 if (flag_exceptions
)
15415 using_eh_for_cleanups ();
15417 c_parser_translation_unit (the_parser
);
15421 /* This function parses Cilk Plus array notation. The starting index is
15422 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
15423 return value of this function is a tree_node called VALUE_TREE of type
15424 ARRAY_NOTATION_REF. */
15427 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
15430 c_token
*token
= NULL
;
15431 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
15432 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
15433 tree array_type_domain
= NULL_TREE
;
15435 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
15437 /* No need to continue. If either of these 2 were true, then an error
15438 must be emitted already. Thus, no need to emit them twice. */
15439 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15440 return error_mark_node
;
15443 array_type
= TREE_TYPE (array_value
);
15444 gcc_assert (array_type
);
15445 if (TREE_CODE (array_type
) != ARRAY_TYPE
15446 && TREE_CODE (array_type
) != POINTER_TYPE
)
15448 error_at (loc
, "base of array section must be pointer or array type");
15449 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15450 return error_mark_node
;
15452 type
= TREE_TYPE (array_type
);
15453 token
= c_parser_peek_token (parser
);
15455 if (token
->type
== CPP_EOF
)
15457 c_parser_error (parser
, "expected %<:%> or numeral");
15460 else if (token
->type
== CPP_COLON
)
15462 if (!initial_index
)
15464 /* If we are here, then we have a case like this A[:]. */
15465 c_parser_consume_token (parser
);
15466 if (TREE_CODE (array_type
) == POINTER_TYPE
)
15468 error_at (loc
, "start-index and length fields necessary for "
15469 "using array notations in pointers");
15470 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15471 return error_mark_node
;
15473 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15475 error_at (loc
, "array notations cannot be used with function "
15477 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15478 return error_mark_node
;
15480 array_type_domain
= TYPE_DOMAIN (array_type
);
15482 if (!array_type_domain
)
15484 error_at (loc
, "start-index and length fields necessary for "
15485 "using array notations in dimensionless arrays");
15486 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15487 return error_mark_node
;
15490 start_index
= TYPE_MINVAL (array_type_domain
);
15491 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
15493 if (!TYPE_MAXVAL (array_type_domain
)
15494 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
15496 error_at (loc
, "start-index and length fields necessary for "
15497 "using array notations in variable-length arrays");
15498 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15499 return error_mark_node
;
15501 end_index
= TYPE_MAXVAL (array_type_domain
);
15502 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
15503 end_index
, integer_one_node
);
15504 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
15505 stride
= build_int_cst (integer_type_node
, 1);
15506 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
15508 else if (initial_index
!= error_mark_node
)
15510 /* If we are here, then there should be 2 possibilities:
15511 1. Array [EXPR : EXPR]
15512 2. Array [EXPR : EXPR : EXPR]
15514 start_index
= initial_index
;
15516 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15518 error_at (loc
, "array notations cannot be used with function "
15520 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15521 return error_mark_node
;
15523 c_parser_consume_token (parser
); /* consume the ':' */
15524 struct c_expr ce
= c_parser_expression (parser
);
15525 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15526 end_index
= ce
.value
;
15527 if (!end_index
|| end_index
== error_mark_node
)
15529 c_parser_skip_to_end_of_block_or_statement (parser
);
15530 return error_mark_node
;
15532 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
15534 c_parser_consume_token (parser
);
15535 ce
= c_parser_expression (parser
);
15536 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15538 if (!stride
|| stride
== error_mark_node
)
15540 c_parser_skip_to_end_of_block_or_statement (parser
);
15541 return error_mark_node
;
15546 c_parser_error (parser
, "expected array notation expression");
15549 c_parser_error (parser
, "expected array notation expression");
15551 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15553 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
15554 end_index
, stride
, type
);
15555 if (value_tree
!= error_mark_node
)
15556 SET_EXPR_LOCATION (value_tree
, loc
);
15560 #include "gt-c-c-parser.h"