1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
43 #include "stringpool.h"
45 #include "stor-layout.h"
47 #include "trans-mem.h"
48 #include "langhooks.h"
52 #include "c-family/c-pragma.h"
57 #include "c-family/c-common.h"
58 #include "c-family/c-objc.h"
63 #include "plugin-api.h"
67 #include "hard-reg-set.h"
76 /* Initialization routine for this file. */
81 /* The only initialization required is of the reserved word
87 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
88 the c_token structure. */
89 gcc_assert (RID_MAX
<= 255);
96 mask
|= D_ASM
| D_EXT
;
100 if (!c_dialect_objc ())
101 mask
|= D_OBJC
| D_CXX_OBJC
;
103 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
104 for (i
= 0; i
< num_c_common_reswords
; i
++)
106 /* If a keyword is disabled, do not enter it into the table
107 and so create a canonical spelling that isn't a keyword. */
108 if (c_common_reswords
[i
].disable
& mask
)
111 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
113 id
= get_identifier (c_common_reswords
[i
].word
);
114 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
115 C_IS_RESERVED_WORD (id
) = 1;
120 id
= get_identifier (c_common_reswords
[i
].word
);
121 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
122 C_IS_RESERVED_WORD (id
) = 1;
123 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
126 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
128 /* We always create the symbols but they aren't always supported. */
130 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
131 id
= get_identifier (xstrdup (name
));
132 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
133 C_IS_RESERVED_WORD (id
) = 1;
137 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
138 and the C parser. Unlike the C++ lexer, the parser structure
139 stores the lexer information instead of using a separate structure.
140 Identifiers are separated into ordinary identifiers, type names,
141 keywords and some other Objective-C types of identifiers, and some
142 look-ahead is maintained.
144 ??? It might be a good idea to lex the whole file up front (as for
145 C++). It would then be possible to share more of the C and C++
146 lexer code, if desired. */
148 /* More information about the type of a CPP_NAME token. */
149 typedef enum c_id_kind
{
150 /* An ordinary identifier. */
152 /* An identifier declared as a typedef name. */
154 /* An identifier declared as an Objective-C class name. */
156 /* An address space identifier. */
158 /* Not an identifier. */
162 /* A single C token after string literal concatenation and conversion
163 of preprocessing tokens to tokens. */
164 typedef struct GTY (()) c_token
{
165 /* The kind of token. */
166 ENUM_BITFIELD (cpp_ttype
) type
: 8;
167 /* If this token is a CPP_NAME, this value indicates whether also
168 declared as some kind of type. Otherwise, it is C_ID_NONE. */
169 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
170 /* If this token is a keyword, this value indicates which keyword.
171 Otherwise, this value is RID_MAX. */
172 ENUM_BITFIELD (rid
) keyword
: 8;
173 /* If this token is a CPP_PRAGMA, this indicates the pragma that
174 was seen. Otherwise it is PRAGMA_NONE. */
175 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
176 /* The location at which this token was found. */
178 /* The value associated with this token, if any. */
182 /* A parser structure recording information about the state and
183 context of parsing. Includes lexer information with up to two
184 tokens of look-ahead; more are not needed for C. */
185 typedef struct GTY(()) c_parser
{
186 /* The look-ahead tokens. */
187 c_token
* GTY((skip
)) tokens
;
188 /* Buffer for look-ahead tokens. */
189 c_token tokens_buf
[2];
190 /* How many look-ahead tokens are available (0, 1 or 2, or
191 more if parsing from pre-lexed tokens). */
192 unsigned int tokens_avail
;
193 /* True if a syntax error is being recovered from; false otherwise.
194 c_parser_error sets this flag. It should clear this flag when
195 enough tokens have been consumed to recover from the error. */
196 BOOL_BITFIELD error
: 1;
197 /* True if we're processing a pragma, and shouldn't automatically
198 consume CPP_PRAGMA_EOL. */
199 BOOL_BITFIELD in_pragma
: 1;
200 /* True if we're parsing the outermost block of an if statement. */
201 BOOL_BITFIELD in_if_block
: 1;
202 /* True if we want to lex an untranslated string. */
203 BOOL_BITFIELD lex_untranslated_string
: 1;
205 /* Objective-C specific parser/lexer information. */
207 /* True if we are in a context where the Objective-C "PQ" keywords
208 are considered keywords. */
209 BOOL_BITFIELD objc_pq_context
: 1;
210 /* True if we are parsing a (potential) Objective-C foreach
211 statement. This is set to true after we parsed 'for (' and while
212 we wait for 'in' or ';' to decide if it's a standard C for loop or an
213 Objective-C foreach loop. */
214 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
215 /* The following flag is needed to contextualize Objective-C lexical
216 analysis. In some cases (e.g., 'int NSObject;'), it is
217 undesirable to bind an identifier to an Objective-C class, even
218 if a class with that name exists. */
219 BOOL_BITFIELD objc_need_raw_identifier
: 1;
220 /* Nonzero if we're processing a __transaction statement. The value
221 is 1 | TM_STMT_ATTR_*. */
222 unsigned int in_transaction
: 4;
223 /* True if we are in a context where the Objective-C "Property attribute"
224 keywords are valid. */
225 BOOL_BITFIELD objc_property_attr_context
: 1;
227 /* Cilk Plus specific parser/lexer information. */
229 /* Buffer to hold all the tokens from parsing the vector attribute for the
230 SIMD-enabled functions (formerly known as elemental functions). */
231 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
235 /* The actual parser and external interface. ??? Does this need to be
236 garbage-collected? */
238 static GTY (()) c_parser
*the_parser
;
240 /* Read in and lex a single token, storing it in *TOKEN. */
243 c_lex_one_token (c_parser
*parser
, c_token
*token
)
245 timevar_push (TV_LEX
);
247 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
248 (parser
->lex_untranslated_string
249 ? C_LEX_STRING_NO_TRANSLATE
: 0));
250 token
->id_kind
= C_ID_NONE
;
251 token
->keyword
= RID_MAX
;
252 token
->pragma_kind
= PRAGMA_NONE
;
260 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
261 if (c_dialect_objc ())
262 parser
->objc_need_raw_identifier
= false;
264 if (C_IS_RESERVED_WORD (token
->value
))
266 enum rid rid_code
= C_RID_CODE (token
->value
);
268 if (rid_code
== RID_CXX_COMPAT_WARN
)
270 warning_at (token
->location
,
272 "identifier %qE conflicts with C++ keyword",
275 else if (rid_code
>= RID_FIRST_ADDR_SPACE
276 && rid_code
<= RID_LAST_ADDR_SPACE
)
278 token
->id_kind
= C_ID_ADDRSPACE
;
279 token
->keyword
= rid_code
;
282 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
284 /* We found an Objective-C "pq" keyword (in, out,
285 inout, bycopy, byref, oneway). They need special
286 care because the interpretation depends on the
288 if (parser
->objc_pq_context
)
290 token
->type
= CPP_KEYWORD
;
291 token
->keyword
= rid_code
;
294 else if (parser
->objc_could_be_foreach_context
295 && rid_code
== RID_IN
)
297 /* We are in Objective-C, inside a (potential)
298 foreach context (which means after having
299 parsed 'for (', but before having parsed ';'),
300 and we found 'in'. We consider it the keyword
301 which terminates the declaration at the
302 beginning of a foreach-statement. Note that
303 this means you can't use 'in' for anything else
304 in that context; in particular, in Objective-C
305 you can't use 'in' as the name of the running
306 variable in a C for loop. We could potentially
307 try to add code here to disambiguate, but it
308 seems a reasonable limitation. */
309 token
->type
= CPP_KEYWORD
;
310 token
->keyword
= rid_code
;
313 /* Else, "pq" keywords outside of the "pq" context are
314 not keywords, and we fall through to the code for
317 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
319 /* We found an Objective-C "property attribute"
320 keyword (getter, setter, readonly, etc). These are
321 only valid in the property context. */
322 if (parser
->objc_property_attr_context
)
324 token
->type
= CPP_KEYWORD
;
325 token
->keyword
= rid_code
;
328 /* Else they are not special keywords.
331 else if (c_dialect_objc ()
332 && (OBJC_IS_AT_KEYWORD (rid_code
)
333 || OBJC_IS_CXX_KEYWORD (rid_code
)))
335 /* We found one of the Objective-C "@" keywords (defs,
336 selector, synchronized, etc) or one of the
337 Objective-C "cxx" keywords (class, private,
338 protected, public, try, catch, throw) without a
339 preceding '@' sign. Do nothing and fall through to
340 the code for normal tokens (in C++ we would still
341 consider the CXX ones keywords, but not in C). */
346 token
->type
= CPP_KEYWORD
;
347 token
->keyword
= rid_code
;
352 decl
= lookup_name (token
->value
);
355 if (TREE_CODE (decl
) == TYPE_DECL
)
357 token
->id_kind
= C_ID_TYPENAME
;
361 else if (c_dialect_objc ())
363 tree objc_interface_decl
= objc_is_class_name (token
->value
);
364 /* Objective-C class names are in the same namespace as
365 variables and typedefs, and hence are shadowed by local
367 if (objc_interface_decl
368 && (!objc_force_identifier
|| global_bindings_p ()))
370 token
->value
= objc_interface_decl
;
371 token
->id_kind
= C_ID_CLASSNAME
;
375 token
->id_kind
= C_ID_ID
;
379 /* This only happens in Objective-C; it must be a keyword. */
380 token
->type
= CPP_KEYWORD
;
381 switch (C_RID_CODE (token
->value
))
383 /* Replace 'class' with '@class', 'private' with '@private',
384 etc. This prevents confusion with the C++ keyword
385 'class', and makes the tokens consistent with other
386 Objective-C 'AT' keywords. For example '@class' is
387 reported as RID_AT_CLASS which is consistent with
388 '@synchronized', which is reported as
391 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
392 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
393 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
394 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
395 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
396 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
397 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
398 default: token
->keyword
= C_RID_CODE (token
->value
);
403 case CPP_CLOSE_PAREN
:
405 /* These tokens may affect the interpretation of any identifiers
406 following, if doing Objective-C. */
407 if (c_dialect_objc ())
408 parser
->objc_need_raw_identifier
= false;
411 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
412 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
418 timevar_pop (TV_LEX
);
421 /* Return a pointer to the next token from PARSER, reading it in if
424 static inline c_token
*
425 c_parser_peek_token (c_parser
*parser
)
427 if (parser
->tokens_avail
== 0)
429 c_lex_one_token (parser
, &parser
->tokens
[0]);
430 parser
->tokens_avail
= 1;
432 return &parser
->tokens
[0];
435 /* Return true if the next token from PARSER has the indicated
439 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
441 return c_parser_peek_token (parser
)->type
== type
;
444 /* Return true if the next token from PARSER does not have the
448 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
450 return !c_parser_next_token_is (parser
, type
);
453 /* Return true if the next token from PARSER is the indicated
457 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
459 return c_parser_peek_token (parser
)->keyword
== keyword
;
462 /* Return a pointer to the next-but-one token from PARSER, reading it
463 in if necessary. The next token is already read in. */
466 c_parser_peek_2nd_token (c_parser
*parser
)
468 if (parser
->tokens_avail
>= 2)
469 return &parser
->tokens
[1];
470 gcc_assert (parser
->tokens_avail
== 1);
471 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
472 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
473 c_lex_one_token (parser
, &parser
->tokens
[1]);
474 parser
->tokens_avail
= 2;
475 return &parser
->tokens
[1];
478 /* Return true if TOKEN can start a type name,
481 c_token_starts_typename (c_token
*token
)
486 switch (token
->id_kind
)
495 gcc_assert (c_dialect_objc ());
501 switch (token
->keyword
)
532 if (token
->keyword
>= RID_FIRST_INT_N
533 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
534 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
539 if (c_dialect_objc ())
547 enum c_lookahead_kind
{
548 /* Always treat unknown identifiers as typenames. */
551 /* Could be parsing a nonabstract declarator. Only treat an identifier
552 as a typename if followed by another identifier or a star. */
553 cla_nonabstract_decl
,
555 /* Never treat identifiers as typenames. */
559 /* Return true if the next token from PARSER can start a type name,
560 false otherwise. LA specifies how to do lookahead in order to
561 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
564 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
566 c_token
*token
= c_parser_peek_token (parser
);
567 if (c_token_starts_typename (token
))
570 /* Try a bit harder to detect an unknown typename. */
571 if (la
!= cla_prefer_id
572 && token
->type
== CPP_NAME
573 && token
->id_kind
== C_ID_ID
575 /* Do not try too hard when we could have "object in array". */
576 && !parser
->objc_could_be_foreach_context
578 && (la
== cla_prefer_type
579 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
580 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
582 /* Only unknown identifiers. */
583 && !lookup_name (token
->value
))
589 /* Return true if TOKEN is a type qualifier, false otherwise. */
591 c_token_is_qualifier (c_token
*token
)
596 switch (token
->id_kind
)
604 switch (token
->keyword
)
622 /* Return true if the next token from PARSER is a type qualifier,
625 c_parser_next_token_is_qualifier (c_parser
*parser
)
627 c_token
*token
= c_parser_peek_token (parser
);
628 return c_token_is_qualifier (token
);
631 /* Return true if TOKEN can start declaration specifiers, false
634 c_token_starts_declspecs (c_token
*token
)
639 switch (token
->id_kind
)
648 gcc_assert (c_dialect_objc ());
654 switch (token
->keyword
)
694 if (token
->keyword
>= RID_FIRST_INT_N
695 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
696 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
701 if (c_dialect_objc ())
710 /* Return true if TOKEN can start declaration specifiers or a static
711 assertion, false otherwise. */
713 c_token_starts_declaration (c_token
*token
)
715 if (c_token_starts_declspecs (token
)
716 || token
->keyword
== RID_STATIC_ASSERT
)
722 /* Return true if the next token from PARSER can start declaration
723 specifiers, false otherwise. */
725 c_parser_next_token_starts_declspecs (c_parser
*parser
)
727 c_token
*token
= c_parser_peek_token (parser
);
729 /* In Objective-C, a classname normally starts a declspecs unless it
730 is immediately followed by a dot. In that case, it is the
731 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
732 setter/getter on the class. c_token_starts_declspecs() can't
733 differentiate between the two cases because it only checks the
734 current token, so we have a special check here. */
735 if (c_dialect_objc ()
736 && token
->type
== CPP_NAME
737 && token
->id_kind
== C_ID_CLASSNAME
738 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
741 return c_token_starts_declspecs (token
);
744 /* Return true if the next tokens from PARSER can start declaration
745 specifiers or a static assertion, false otherwise. */
747 c_parser_next_tokens_start_declaration (c_parser
*parser
)
749 c_token
*token
= c_parser_peek_token (parser
);
752 if (c_dialect_objc ()
753 && token
->type
== CPP_NAME
754 && token
->id_kind
== C_ID_CLASSNAME
755 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
758 /* Labels do not start declarations. */
759 if (token
->type
== CPP_NAME
760 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
763 if (c_token_starts_declaration (token
))
766 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
772 /* Consume the next token from PARSER. */
775 c_parser_consume_token (c_parser
*parser
)
777 gcc_assert (parser
->tokens_avail
>= 1);
778 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
779 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
780 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
781 if (parser
->tokens
!= &parser
->tokens_buf
[0])
783 else if (parser
->tokens_avail
== 2)
784 parser
->tokens
[0] = parser
->tokens
[1];
785 parser
->tokens_avail
--;
788 /* Expect the current token to be a #pragma. Consume it and remember
789 that we've begun parsing a pragma. */
792 c_parser_consume_pragma (c_parser
*parser
)
794 gcc_assert (!parser
->in_pragma
);
795 gcc_assert (parser
->tokens_avail
>= 1);
796 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
797 if (parser
->tokens
!= &parser
->tokens_buf
[0])
799 else if (parser
->tokens_avail
== 2)
800 parser
->tokens
[0] = parser
->tokens
[1];
801 parser
->tokens_avail
--;
802 parser
->in_pragma
= true;
805 /* Update the global input_location from TOKEN. */
807 c_parser_set_source_position_from_token (c_token
*token
)
809 if (token
->type
!= CPP_EOF
)
811 input_location
= token
->location
;
815 /* Issue a diagnostic of the form
816 FILE:LINE: MESSAGE before TOKEN
817 where TOKEN is the next token in the input stream of PARSER.
818 MESSAGE (specified by the caller) is usually of the form "expected
821 Do not issue a diagnostic if still recovering from an error.
823 ??? This is taken from the C++ parser, but building up messages in
824 this way is not i18n-friendly and some other approach should be
828 c_parser_error (c_parser
*parser
, const char *gmsgid
)
830 c_token
*token
= c_parser_peek_token (parser
);
833 parser
->error
= true;
836 /* This diagnostic makes more sense if it is tagged to the line of
837 the token we just peeked at. */
838 c_parser_set_source_position_from_token (token
);
839 c_parse_error (gmsgid
,
840 /* Because c_parse_error does not understand
841 CPP_KEYWORD, keywords are treated like
843 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
844 /* ??? The C parser does not save the cpp flags of a
845 token, we need to pass 0 here and we will not get
846 the source spelling of some tokens but rather the
847 canonical spelling. */
848 token
->value
, /*flags=*/0);
851 /* If the next token is of the indicated TYPE, consume it. Otherwise,
852 issue the error MSGID. If MSGID is NULL then a message has already
853 been produced and no message will be produced this time. Returns
854 true if found, false otherwise. */
857 c_parser_require (c_parser
*parser
,
861 if (c_parser_next_token_is (parser
, type
))
863 c_parser_consume_token (parser
);
868 c_parser_error (parser
, msgid
);
873 /* If the next token is the indicated keyword, consume it. Otherwise,
874 issue the error MSGID. Returns true if found, false otherwise. */
877 c_parser_require_keyword (c_parser
*parser
,
881 if (c_parser_next_token_is_keyword (parser
, keyword
))
883 c_parser_consume_token (parser
);
888 c_parser_error (parser
, msgid
);
893 /* Like c_parser_require, except that tokens will be skipped until the
894 desired token is found. An error message is still produced if the
895 next token is not as expected. If MSGID is NULL then a message has
896 already been produced and no message will be produced this
900 c_parser_skip_until_found (c_parser
*parser
,
904 unsigned nesting_depth
= 0;
906 if (c_parser_require (parser
, type
, msgid
))
909 /* Skip tokens until the desired token is found. */
912 /* Peek at the next token. */
913 c_token
*token
= c_parser_peek_token (parser
);
914 /* If we've reached the token we want, consume it and stop. */
915 if (token
->type
== type
&& !nesting_depth
)
917 c_parser_consume_token (parser
);
921 /* If we've run out of tokens, stop. */
922 if (token
->type
== CPP_EOF
)
924 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
926 if (token
->type
== CPP_OPEN_BRACE
927 || token
->type
== CPP_OPEN_PAREN
928 || token
->type
== CPP_OPEN_SQUARE
)
930 else if (token
->type
== CPP_CLOSE_BRACE
931 || token
->type
== CPP_CLOSE_PAREN
932 || token
->type
== CPP_CLOSE_SQUARE
)
934 if (nesting_depth
-- == 0)
937 /* Consume this token. */
938 c_parser_consume_token (parser
);
940 parser
->error
= false;
943 /* Skip tokens until the end of a parameter is found, but do not
944 consume the comma, semicolon or closing delimiter. */
947 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
949 unsigned nesting_depth
= 0;
953 c_token
*token
= c_parser_peek_token (parser
);
954 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
957 /* If we've run out of tokens, stop. */
958 if (token
->type
== CPP_EOF
)
960 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
962 if (token
->type
== CPP_OPEN_BRACE
963 || token
->type
== CPP_OPEN_PAREN
964 || token
->type
== CPP_OPEN_SQUARE
)
966 else if (token
->type
== CPP_CLOSE_BRACE
967 || token
->type
== CPP_CLOSE_PAREN
968 || token
->type
== CPP_CLOSE_SQUARE
)
970 if (nesting_depth
-- == 0)
973 /* Consume this token. */
974 c_parser_consume_token (parser
);
976 parser
->error
= false;
979 /* Expect to be at the end of the pragma directive and consume an
980 end of line marker. */
983 c_parser_skip_to_pragma_eol (c_parser
*parser
)
985 gcc_assert (parser
->in_pragma
);
986 parser
->in_pragma
= false;
988 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
991 c_token
*token
= c_parser_peek_token (parser
);
992 if (token
->type
== CPP_EOF
)
994 if (token
->type
== CPP_PRAGMA_EOL
)
996 c_parser_consume_token (parser
);
999 c_parser_consume_token (parser
);
1002 parser
->error
= false;
1005 /* Skip tokens until we have consumed an entire block, or until we
1006 have consumed a non-nested ';'. */
1009 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1011 unsigned nesting_depth
= 0;
1012 bool save_error
= parser
->error
;
1018 /* Peek at the next token. */
1019 token
= c_parser_peek_token (parser
);
1021 switch (token
->type
)
1026 case CPP_PRAGMA_EOL
:
1027 if (parser
->in_pragma
)
1032 /* If the next token is a ';', we have reached the
1033 end of the statement. */
1036 /* Consume the ';'. */
1037 c_parser_consume_token (parser
);
1042 case CPP_CLOSE_BRACE
:
1043 /* If the next token is a non-nested '}', then we have
1044 reached the end of the current block. */
1045 if (nesting_depth
== 0 || --nesting_depth
== 0)
1047 c_parser_consume_token (parser
);
1052 case CPP_OPEN_BRACE
:
1053 /* If it the next token is a '{', then we are entering a new
1054 block. Consume the entire block. */
1059 /* If we see a pragma, consume the whole thing at once. We
1060 have some safeguards against consuming pragmas willy-nilly.
1061 Normally, we'd expect to be here with parser->error set,
1062 which disables these safeguards. But it's possible to get
1063 here for secondary error recovery, after parser->error has
1065 c_parser_consume_pragma (parser
);
1066 c_parser_skip_to_pragma_eol (parser
);
1067 parser
->error
= save_error
;
1074 c_parser_consume_token (parser
);
1078 parser
->error
= false;
1081 /* CPP's options (initialized by c-opts.c). */
1082 extern cpp_options
*cpp_opts
;
1084 /* Save the warning flags which are controlled by __extension__. */
1087 disable_extension_diagnostics (void)
1090 | (warn_pointer_arith
<< 1)
1091 | (warn_traditional
<< 2)
1093 | (warn_long_long
<< 4)
1094 | (warn_cxx_compat
<< 5)
1095 | (warn_overlength_strings
<< 6)
1096 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1097 play tricks to properly restore it. */
1098 | ((warn_c90_c99_compat
== 1) << 7)
1099 | ((warn_c90_c99_compat
== -1) << 8)
1100 /* Similarly for warn_c99_c11_compat. */
1101 | ((warn_c99_c11_compat
== 1) << 9)
1102 | ((warn_c99_c11_compat
== -1) << 10)
1104 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1105 warn_pointer_arith
= 0;
1106 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1108 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1109 warn_cxx_compat
= 0;
1110 warn_overlength_strings
= 0;
1111 warn_c90_c99_compat
= 0;
1112 warn_c99_c11_compat
= 0;
1116 /* Restore the warning flags which are controlled by __extension__.
1117 FLAGS is the return value from disable_extension_diagnostics. */
1120 restore_extension_diagnostics (int flags
)
1122 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1123 warn_pointer_arith
= (flags
>> 1) & 1;
1124 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1125 flag_iso
= (flags
>> 3) & 1;
1126 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1127 warn_cxx_compat
= (flags
>> 5) & 1;
1128 warn_overlength_strings
= (flags
>> 6) & 1;
1129 /* See above for why is this needed. */
1130 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1131 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1134 /* Possibly kinds of declarator to parse. */
1135 typedef enum c_dtr_syn
{
1136 /* A normal declarator with an identifier. */
1138 /* An abstract declarator (maybe empty). */
1140 /* A parameter declarator: may be either, but after a type name does
1141 not redeclare a typedef name as an identifier if it can
1142 alternatively be interpreted as a typedef name; see DR#009,
1143 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1144 following DR#249. For example, given a typedef T, "int T" and
1145 "int *T" are valid parameter declarations redeclaring T, while
1146 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1147 abstract declarators rather than involving redundant parentheses;
1148 the same applies with attributes inside the parentheses before
1153 /* The binary operation precedence levels, where 0 is a dummy lowest level
1154 used for the bottom of the stack. */
1155 enum c_parser_prec
{
1170 static void c_parser_external_declaration (c_parser
*);
1171 static void c_parser_asm_definition (c_parser
*);
1172 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1173 bool, bool, tree
*, vec
<c_token
>);
1174 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1175 static void c_parser_static_assert_declaration (c_parser
*);
1176 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1177 bool, bool, bool, enum c_lookahead_kind
);
1178 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1179 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1180 static tree
c_parser_struct_declaration (c_parser
*);
1181 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1182 static tree
c_parser_alignas_specifier (c_parser
*);
1183 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1185 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1187 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1189 struct c_declarator
*);
1190 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1191 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1193 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1194 static tree
c_parser_simple_asm_expr (c_parser
*);
1195 static tree
c_parser_attributes (c_parser
*);
1196 static struct c_type_name
*c_parser_type_name (c_parser
*);
1197 static struct c_expr
c_parser_initializer (c_parser
*);
1198 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1199 static void c_parser_initelt (c_parser
*, struct obstack
*);
1200 static void c_parser_initval (c_parser
*, struct c_expr
*,
1202 static tree
c_parser_compound_statement (c_parser
*);
1203 static void c_parser_compound_statement_nostart (c_parser
*);
1204 static void c_parser_label (c_parser
*);
1205 static void c_parser_statement (c_parser
*);
1206 static void c_parser_statement_after_labels (c_parser
*);
1207 static void c_parser_if_statement (c_parser
*);
1208 static void c_parser_switch_statement (c_parser
*);
1209 static void c_parser_while_statement (c_parser
*, bool);
1210 static void c_parser_do_statement (c_parser
*, bool);
1211 static void c_parser_for_statement (c_parser
*, bool);
1212 static tree
c_parser_asm_statement (c_parser
*);
1213 static tree
c_parser_asm_operands (c_parser
*);
1214 static tree
c_parser_asm_goto_operands (c_parser
*);
1215 static tree
c_parser_asm_clobbers (c_parser
*);
1216 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1218 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1219 struct c_expr
*, tree
);
1220 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1222 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1223 static struct c_expr
c_parser_unary_expression (c_parser
*);
1224 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1225 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1226 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1227 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1228 struct c_type_name
*,
1230 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1233 static tree
c_parser_transaction (c_parser
*, enum rid
);
1234 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1235 static tree
c_parser_transaction_cancel (c_parser
*);
1236 static struct c_expr
c_parser_expression (c_parser
*);
1237 static struct c_expr
c_parser_expression_conv (c_parser
*);
1238 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1239 vec
<tree
, va_gc
> **, location_t
*,
1240 tree
*, vec
<location_t
> *,
1241 unsigned int * = NULL
);
1242 static tree
c_parser_oacc_loop (location_t
, c_parser
*, char *);
1243 static void c_parser_omp_construct (c_parser
*);
1244 static void c_parser_omp_threadprivate (c_parser
*);
1245 static void c_parser_oacc_update (c_parser
*);
1246 static void c_parser_omp_barrier (c_parser
*);
1247 static void c_parser_omp_flush (c_parser
*);
1248 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1250 static void c_parser_omp_taskwait (c_parser
*);
1251 static void c_parser_omp_taskyield (c_parser
*);
1252 static void c_parser_omp_cancel (c_parser
*);
1253 static void c_parser_omp_cancellation_point (c_parser
*);
1255 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1256 pragma_stmt
, pragma_compound
};
1257 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1258 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1259 static void c_parser_omp_end_declare_target (c_parser
*);
1260 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1262 /* These Objective-C parser functions are only ever called when
1263 compiling Objective-C. */
1264 static void c_parser_objc_class_definition (c_parser
*, tree
);
1265 static void c_parser_objc_class_instance_variables (c_parser
*);
1266 static void c_parser_objc_class_declaration (c_parser
*);
1267 static void c_parser_objc_alias_declaration (c_parser
*);
1268 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1269 static bool c_parser_objc_method_type (c_parser
*);
1270 static void c_parser_objc_method_definition (c_parser
*);
1271 static void c_parser_objc_methodprotolist (c_parser
*);
1272 static void c_parser_objc_methodproto (c_parser
*);
1273 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1274 static tree
c_parser_objc_type_name (c_parser
*);
1275 static tree
c_parser_objc_protocol_refs (c_parser
*);
1276 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1277 static void c_parser_objc_synchronized_statement (c_parser
*);
1278 static tree
c_parser_objc_selector (c_parser
*);
1279 static tree
c_parser_objc_selector_arg (c_parser
*);
1280 static tree
c_parser_objc_receiver (c_parser
*);
1281 static tree
c_parser_objc_message_args (c_parser
*);
1282 static tree
c_parser_objc_keywordexpr (c_parser
*);
1283 static void c_parser_objc_at_property_declaration (c_parser
*);
1284 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1285 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1286 static bool c_parser_objc_diagnose_bad_element_prefix
1287 (c_parser
*, struct c_declspecs
*);
1289 /* Cilk Plus supporting routines. */
1290 static void c_parser_cilk_simd (c_parser
*);
1291 static void c_parser_cilk_for (c_parser
*, tree
);
1292 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1293 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1294 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1295 static void c_parser_cilk_grainsize (c_parser
*);
1297 /* Parse a translation unit (C90 6.7, C99 6.9).
1300 external-declarations
1302 external-declarations:
1303 external-declaration
1304 external-declarations external-declaration
1313 c_parser_translation_unit (c_parser
*parser
)
1315 if (c_parser_next_token_is (parser
, CPP_EOF
))
1317 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1318 "ISO C forbids an empty translation unit");
1322 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1323 mark_valid_location_for_stdc_pragma (false);
1327 c_parser_external_declaration (parser
);
1328 obstack_free (&parser_obstack
, obstack_position
);
1330 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1334 /* Parse an external declaration (C90 6.7, C99 6.9).
1336 external-declaration:
1342 external-declaration:
1345 __extension__ external-declaration
1349 external-declaration:
1350 objc-class-definition
1351 objc-class-declaration
1352 objc-alias-declaration
1353 objc-protocol-definition
1354 objc-method-definition
1359 c_parser_external_declaration (c_parser
*parser
)
1362 switch (c_parser_peek_token (parser
)->type
)
1365 switch (c_parser_peek_token (parser
)->keyword
)
1368 ext
= disable_extension_diagnostics ();
1369 c_parser_consume_token (parser
);
1370 c_parser_external_declaration (parser
);
1371 restore_extension_diagnostics (ext
);
1374 c_parser_asm_definition (parser
);
1376 case RID_AT_INTERFACE
:
1377 case RID_AT_IMPLEMENTATION
:
1378 gcc_assert (c_dialect_objc ());
1379 c_parser_objc_class_definition (parser
, NULL_TREE
);
1382 gcc_assert (c_dialect_objc ());
1383 c_parser_objc_class_declaration (parser
);
1386 gcc_assert (c_dialect_objc ());
1387 c_parser_objc_alias_declaration (parser
);
1389 case RID_AT_PROTOCOL
:
1390 gcc_assert (c_dialect_objc ());
1391 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1393 case RID_AT_PROPERTY
:
1394 gcc_assert (c_dialect_objc ());
1395 c_parser_objc_at_property_declaration (parser
);
1397 case RID_AT_SYNTHESIZE
:
1398 gcc_assert (c_dialect_objc ());
1399 c_parser_objc_at_synthesize_declaration (parser
);
1401 case RID_AT_DYNAMIC
:
1402 gcc_assert (c_dialect_objc ());
1403 c_parser_objc_at_dynamic_declaration (parser
);
1406 gcc_assert (c_dialect_objc ());
1407 c_parser_consume_token (parser
);
1408 objc_finish_implementation ();
1415 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1416 "ISO C does not allow extra %<;%> outside of a function");
1417 c_parser_consume_token (parser
);
1420 mark_valid_location_for_stdc_pragma (true);
1421 c_parser_pragma (parser
, pragma_external
);
1422 mark_valid_location_for_stdc_pragma (false);
1426 if (c_dialect_objc ())
1428 c_parser_objc_method_definition (parser
);
1431 /* Else fall through, and yield a syntax error trying to parse
1432 as a declaration or function definition. */
1435 /* A declaration or a function definition (or, in Objective-C,
1436 an @interface or @protocol with prefix attributes). We can
1437 only tell which after parsing the declaration specifiers, if
1438 any, and the first declarator. */
1439 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1445 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1447 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1448 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1449 accepted; otherwise (old-style parameter declarations) only other
1450 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1451 assertion is accepted; otherwise (old-style parameter declarations)
1452 it is not. If NESTED is true, we are inside a function or parsing
1453 old-style parameter declarations; any functions encountered are
1454 nested functions and declaration specifiers are required; otherwise
1455 we are at top level and functions are normal functions and
1456 declaration specifiers may be optional. If EMPTY_OK is true, empty
1457 declarations are OK (subject to all other constraints); otherwise
1458 (old-style parameter declarations) they are diagnosed. If
1459 START_ATTR_OK is true, the declaration specifiers may start with
1460 attributes; otherwise they may not.
1461 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1462 declaration when parsing an Objective-C foreach statement.
1465 declaration-specifiers init-declarator-list[opt] ;
1466 static_assert-declaration
1468 function-definition:
1469 declaration-specifiers[opt] declarator declaration-list[opt]
1474 declaration-list declaration
1476 init-declarator-list:
1478 init-declarator-list , init-declarator
1481 declarator simple-asm-expr[opt] attributes[opt]
1482 declarator simple-asm-expr[opt] attributes[opt] = initializer
1486 nested-function-definition:
1487 declaration-specifiers declarator declaration-list[opt]
1491 attributes objc-class-definition
1492 attributes objc-category-definition
1493 attributes objc-protocol-definition
1495 The simple-asm-expr and attributes are GNU extensions.
1497 This function does not handle __extension__; that is handled in its
1498 callers. ??? Following the old parser, __extension__ may start
1499 external declarations, declarations in functions and declarations
1500 at the start of "for" loops, but not old-style parameter
1503 C99 requires declaration specifiers in a function definition; the
1504 absence is diagnosed through the diagnosis of implicit int. In GNU
1505 C we also allow but diagnose declarations without declaration
1506 specifiers, but only at top level (elsewhere they conflict with
1509 In Objective-C, declarations of the looping variable in a foreach
1510 statement are exceptionally terminated by 'in' (for example, 'for
1511 (NSObject *object in array) { ... }').
1516 threadprivate-directive */
1519 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1520 bool static_assert_ok
, bool empty_ok
,
1521 bool nested
, bool start_attr_ok
,
1522 tree
*objc_foreach_object_declaration
,
1523 vec
<c_token
> omp_declare_simd_clauses
)
1525 struct c_declspecs
*specs
;
1527 tree all_prefix_attrs
;
1528 bool diagnosed_no_specs
= false;
1529 location_t here
= c_parser_peek_token (parser
)->location
;
1531 if (static_assert_ok
1532 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1534 c_parser_static_assert_declaration (parser
);
1537 specs
= build_null_declspecs ();
1539 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1540 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1541 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1542 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1543 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1544 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1546 error_at (here
, "unknown type name %qE",
1547 c_parser_peek_token (parser
)->value
);
1549 /* Parse declspecs normally to get a correct pointer type, but avoid
1550 a further "fails to be a type name" error. Refuse nested functions
1551 since it is not how the user likely wants us to recover. */
1552 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1553 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1554 c_parser_peek_token (parser
)->value
= error_mark_node
;
1558 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1559 true, true, cla_nonabstract_decl
);
1562 c_parser_skip_to_end_of_block_or_statement (parser
);
1565 if (nested
&& !specs
->declspecs_seen_p
)
1567 c_parser_error (parser
, "expected declaration specifiers");
1568 c_parser_skip_to_end_of_block_or_statement (parser
);
1571 finish_declspecs (specs
);
1572 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1573 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1576 error_at (here
, "%<__auto_type%> in empty declaration");
1581 shadow_tag_warned (specs
, 1);
1582 pedwarn (here
, 0, "empty declaration");
1584 c_parser_consume_token (parser
);
1588 /* Provide better error recovery. Note that a type name here is usually
1589 better diagnosed as a redeclaration. */
1591 && specs
->typespec_kind
== ctsk_tagdef
1592 && c_parser_next_token_starts_declspecs (parser
)
1593 && !c_parser_next_token_is (parser
, CPP_NAME
))
1595 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1596 parser
->error
= false;
1597 shadow_tag_warned (specs
, 1);
1600 else if (c_dialect_objc () && !auto_type_p
)
1602 /* Prefix attributes are an error on method decls. */
1603 switch (c_parser_peek_token (parser
)->type
)
1607 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1611 warning_at (c_parser_peek_token (parser
)->location
,
1613 "prefix attributes are ignored for methods");
1614 specs
->attrs
= NULL_TREE
;
1617 c_parser_objc_method_definition (parser
);
1619 c_parser_objc_methodproto (parser
);
1625 /* This is where we parse 'attributes @interface ...',
1626 'attributes @implementation ...', 'attributes @protocol ...'
1627 (where attributes could be, for example, __attribute__
1630 switch (c_parser_peek_token (parser
)->keyword
)
1632 case RID_AT_INTERFACE
:
1634 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1636 c_parser_objc_class_definition (parser
, specs
->attrs
);
1640 case RID_AT_IMPLEMENTATION
:
1642 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1646 warning_at (c_parser_peek_token (parser
)->location
,
1648 "prefix attributes are ignored for implementations");
1649 specs
->attrs
= NULL_TREE
;
1651 c_parser_objc_class_definition (parser
, NULL_TREE
);
1655 case RID_AT_PROTOCOL
:
1657 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1659 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1666 case RID_AT_PROPERTY
:
1669 c_parser_error (parser
, "unexpected attribute");
1670 specs
->attrs
= NULL
;
1678 pending_xref_error ();
1679 prefix_attrs
= specs
->attrs
;
1680 all_prefix_attrs
= prefix_attrs
;
1681 specs
->attrs
= NULL_TREE
;
1684 struct c_declarator
*declarator
;
1688 /* Declaring either one or more declarators (in which case we
1689 should diagnose if there were no declaration specifiers) or a
1690 function definition (in which case the diagnostic for
1691 implicit int suffices). */
1692 declarator
= c_parser_declarator (parser
,
1693 specs
->typespec_kind
!= ctsk_none
,
1694 C_DTR_NORMAL
, &dummy
);
1695 if (declarator
== NULL
)
1697 if (omp_declare_simd_clauses
.exists ()
1698 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1699 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1700 omp_declare_simd_clauses
);
1701 c_parser_skip_to_end_of_block_or_statement (parser
);
1704 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1707 "%<__auto_type%> requires a plain identifier"
1709 c_parser_skip_to_end_of_block_or_statement (parser
);
1712 if (c_parser_next_token_is (parser
, CPP_EQ
)
1713 || c_parser_next_token_is (parser
, CPP_COMMA
)
1714 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1715 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1716 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1717 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1719 tree asm_name
= NULL_TREE
;
1720 tree postfix_attrs
= NULL_TREE
;
1721 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1723 diagnosed_no_specs
= true;
1724 pedwarn (here
, 0, "data definition has no type or storage class");
1726 /* Having seen a data definition, there cannot now be a
1727 function definition. */
1729 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1730 asm_name
= c_parser_simple_asm_expr (parser
);
1731 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1733 postfix_attrs
= c_parser_attributes (parser
);
1734 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1736 /* This means there is an attribute specifier after
1737 the declarator in a function definition. Provide
1738 some more information for the user. */
1739 error_at (here
, "attributes should be specified before the "
1740 "declarator in a function definition");
1741 c_parser_skip_to_end_of_block_or_statement (parser
);
1745 if (c_parser_next_token_is (parser
, CPP_EQ
))
1749 location_t init_loc
;
1750 c_parser_consume_token (parser
);
1753 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1754 init_loc
= c_parser_peek_token (parser
)->location
;
1755 init
= c_parser_expr_no_commas (parser
, NULL
);
1756 if (TREE_CODE (init
.value
) == COMPONENT_REF
1757 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1759 "%<__auto_type%> used with a bit-field"
1761 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1762 tree init_type
= TREE_TYPE (init
.value
);
1763 /* As with typeof, remove all qualifiers from atomic types. */
1764 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1766 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1767 bool vm_type
= variably_modified_type_p (init_type
,
1770 init
.value
= c_save_expr (init
.value
);
1772 specs
->typespec_kind
= ctsk_typeof
;
1773 specs
->locations
[cdw_typedef
] = init_loc
;
1774 specs
->typedef_p
= true;
1775 specs
->type
= init_type
;
1778 bool maybe_const
= true;
1779 tree type_expr
= c_fully_fold (init
.value
, false,
1781 specs
->expr_const_operands
&= maybe_const
;
1783 specs
->expr
= build2 (COMPOUND_EXPR
,
1784 TREE_TYPE (type_expr
),
1785 specs
->expr
, type_expr
);
1787 specs
->expr
= type_expr
;
1789 d
= start_decl (declarator
, specs
, true,
1790 chainon (postfix_attrs
, all_prefix_attrs
));
1792 d
= error_mark_node
;
1793 if (omp_declare_simd_clauses
.exists ()
1794 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1795 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1796 omp_declare_simd_clauses
);
1800 /* The declaration of the variable is in effect while
1801 its initializer is parsed. */
1802 d
= start_decl (declarator
, specs
, true,
1803 chainon (postfix_attrs
, all_prefix_attrs
));
1805 d
= error_mark_node
;
1806 if (omp_declare_simd_clauses
.exists ()
1807 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1808 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1809 omp_declare_simd_clauses
);
1810 start_init (d
, asm_name
, global_bindings_p ());
1811 init_loc
= c_parser_peek_token (parser
)->location
;
1812 init
= c_parser_initializer (parser
);
1815 if (d
!= error_mark_node
)
1817 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1818 finish_decl (d
, init_loc
, init
.value
,
1819 init
.original_type
, asm_name
);
1827 "%<__auto_type%> requires an initialized "
1828 "data declaration");
1829 c_parser_skip_to_end_of_block_or_statement (parser
);
1832 tree d
= start_decl (declarator
, specs
, false,
1833 chainon (postfix_attrs
,
1835 if (omp_declare_simd_clauses
.exists ()
1836 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1838 tree parms
= NULL_TREE
;
1839 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1841 struct c_declarator
*ce
= declarator
;
1843 if (ce
->kind
== cdk_function
)
1845 parms
= ce
->u
.arg_info
->parms
;
1849 ce
= ce
->declarator
;
1852 temp_store_parm_decls (d
, parms
);
1853 c_finish_omp_declare_simd (parser
, d
, parms
,
1854 omp_declare_simd_clauses
);
1856 temp_pop_parm_decls ();
1859 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1860 NULL_TREE
, asm_name
);
1862 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1865 *objc_foreach_object_declaration
= d
;
1867 *objc_foreach_object_declaration
= error_mark_node
;
1870 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1875 "%<__auto_type%> may only be used with"
1876 " a single declarator");
1877 c_parser_skip_to_end_of_block_or_statement (parser
);
1880 c_parser_consume_token (parser
);
1881 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1882 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1885 all_prefix_attrs
= prefix_attrs
;
1888 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1890 c_parser_consume_token (parser
);
1893 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1895 /* This can only happen in Objective-C: we found the
1896 'in' that terminates the declaration inside an
1897 Objective-C foreach statement. Do not consume the
1898 token, so that the caller can use it to determine
1899 that this indeed is a foreach context. */
1904 c_parser_error (parser
, "expected %<,%> or %<;%>");
1905 c_parser_skip_to_end_of_block_or_statement (parser
);
1909 else if (auto_type_p
)
1912 "%<__auto_type%> requires an initialized data declaration");
1913 c_parser_skip_to_end_of_block_or_statement (parser
);
1918 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1919 "%<asm%> or %<__attribute__%>");
1920 c_parser_skip_to_end_of_block_or_statement (parser
);
1923 /* Function definition (nested or otherwise). */
1926 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1927 c_push_function_context ();
1929 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1931 /* This can appear in many cases looking nothing like a
1932 function definition, so we don't give a more specific
1933 error suggesting there was one. */
1934 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1935 "or %<__attribute__%>");
1937 c_pop_function_context ();
1941 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1942 tv
= TV_PARSE_INLINE
;
1947 /* Parse old-style parameter declarations. ??? Attributes are
1948 not allowed to start declaration specifiers here because of a
1949 syntax conflict between a function declaration with attribute
1950 suffix and a function definition with an attribute prefix on
1951 first old-style parameter declaration. Following the old
1952 parser, they are not accepted on subsequent old-style
1953 parameter declarations either. However, there is no
1954 ambiguity after the first declaration, nor indeed on the
1955 first as long as we don't allow postfix attributes after a
1956 declarator with a nonempty identifier list in a definition;
1957 and postfix attributes have never been accepted here in
1958 function definitions either. */
1959 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1960 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1961 c_parser_declaration_or_fndef (parser
, false, false, false,
1962 true, false, NULL
, vNULL
);
1963 store_parm_decls ();
1964 if (omp_declare_simd_clauses
.exists ()
1965 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1966 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1967 omp_declare_simd_clauses
);
1968 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1969 = c_parser_peek_token (parser
)->location
;
1970 fnbody
= c_parser_compound_statement (parser
);
1971 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1972 fnbody
= expand_array_notation_exprs (fnbody
);
1975 tree decl
= current_function_decl
;
1976 /* Mark nested functions as needing static-chain initially.
1977 lower_nested_functions will recompute it but the
1978 DECL_STATIC_CHAIN flag is also used before that happens,
1979 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1980 DECL_STATIC_CHAIN (decl
) = 1;
1983 c_pop_function_context ();
1984 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1997 /* Parse an asm-definition (asm() outside a function body). This is a
2005 c_parser_asm_definition (c_parser
*parser
)
2007 tree asm_str
= c_parser_simple_asm_expr (parser
);
2009 symtab
->finalize_toplevel_asm (asm_str
);
2010 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2013 /* Parse a static assertion (C11 6.7.10).
2015 static_assert-declaration:
2016 static_assert-declaration-no-semi ;
2020 c_parser_static_assert_declaration (c_parser
*parser
)
2022 c_parser_static_assert_declaration_no_semi (parser
);
2024 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2025 c_parser_skip_to_end_of_block_or_statement (parser
);
2028 /* Parse a static assertion (C11 6.7.10), without the trailing
2031 static_assert-declaration-no-semi:
2032 _Static_assert ( constant-expression , string-literal )
2036 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2038 location_t assert_loc
, value_loc
;
2042 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2043 assert_loc
= c_parser_peek_token (parser
)->location
;
2045 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2046 "ISO C99 does not support %<_Static_assert%>");
2048 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2049 "ISO C90 does not support %<_Static_assert%>");
2050 c_parser_consume_token (parser
);
2051 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2053 value_loc
= c_parser_peek_token (parser
)->location
;
2054 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2055 parser
->lex_untranslated_string
= true;
2056 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2058 parser
->lex_untranslated_string
= false;
2061 switch (c_parser_peek_token (parser
)->type
)
2067 case CPP_UTF8STRING
:
2068 string
= c_parser_peek_token (parser
)->value
;
2069 c_parser_consume_token (parser
);
2070 parser
->lex_untranslated_string
= false;
2073 c_parser_error (parser
, "expected string literal");
2074 parser
->lex_untranslated_string
= false;
2077 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2079 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2081 error_at (value_loc
, "expression in static assertion is not an integer");
2084 if (TREE_CODE (value
) != INTEGER_CST
)
2086 value
= c_fully_fold (value
, false, NULL
);
2087 /* Strip no-op conversions. */
2088 STRIP_TYPE_NOPS (value
);
2089 if (TREE_CODE (value
) == INTEGER_CST
)
2090 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2091 "is not an integer constant expression");
2093 if (TREE_CODE (value
) != INTEGER_CST
)
2095 error_at (value_loc
, "expression in static assertion is not constant");
2098 constant_expression_warning (value
);
2099 if (integer_zerop (value
))
2100 error_at (assert_loc
, "static assertion failed: %E", string
);
2103 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2104 6.7), adding them to SPECS (which may already include some).
2105 Storage class specifiers are accepted iff SCSPEC_OK; type
2106 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2107 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2108 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2110 declaration-specifiers:
2111 storage-class-specifier declaration-specifiers[opt]
2112 type-specifier declaration-specifiers[opt]
2113 type-qualifier declaration-specifiers[opt]
2114 function-specifier declaration-specifiers[opt]
2115 alignment-specifier declaration-specifiers[opt]
2117 Function specifiers (inline) are from C99, and are currently
2118 handled as storage class specifiers, as is __thread. Alignment
2119 specifiers are from C11.
2121 C90 6.5.1, C99 6.7.1:
2122 storage-class-specifier:
2130 (_Thread_local is new in C11.)
2137 (_Noreturn is new in C11.)
2139 C90 6.5.2, C99 6.7.2:
2152 [_Imaginary removed in C99 TC2]
2153 struct-or-union-specifier
2156 atomic-type-specifier
2158 (_Bool and _Complex are new in C99.)
2159 (atomic-type-specifier is new in C11.)
2161 C90 6.5.3, C99 6.7.3:
2167 address-space-qualifier
2170 (restrict is new in C99.)
2171 (_Atomic is new in C11.)
2175 declaration-specifiers:
2176 attributes declaration-specifiers[opt]
2182 identifier recognized by the target
2184 storage-class-specifier:
2198 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2199 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2201 atomic-type-specifier
2202 _Atomic ( type-name )
2207 class-name objc-protocol-refs[opt]
2208 typedef-name objc-protocol-refs
2213 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2214 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2215 bool alignspec_ok
, bool auto_type_ok
,
2216 enum c_lookahead_kind la
)
2218 bool attrs_ok
= start_attr_ok
;
2219 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2222 gcc_assert (la
== cla_prefer_id
);
2224 while (c_parser_next_token_is (parser
, CPP_NAME
)
2225 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2226 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2228 struct c_typespec t
;
2231 location_t loc
= c_parser_peek_token (parser
)->location
;
2233 /* If we cannot accept a type, exit if the next token must start
2234 one. Also, if we already have seen a tagged definition,
2235 a typename would be an error anyway and likely the user
2236 has simply forgotten a semicolon, so we exit. */
2237 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2238 && c_parser_next_tokens_start_typename (parser
, la
)
2239 && !c_parser_next_token_is_qualifier (parser
))
2242 if (c_parser_next_token_is (parser
, CPP_NAME
))
2244 c_token
*name_token
= c_parser_peek_token (parser
);
2245 tree value
= name_token
->value
;
2246 c_id_kind kind
= name_token
->id_kind
;
2248 if (kind
== C_ID_ADDRSPACE
)
2251 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2252 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2253 c_parser_consume_token (parser
);
2258 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2260 /* If we cannot accept a type, and the next token must start one,
2261 exit. Do the same if we already have seen a tagged definition,
2262 since it would be an error anyway and likely the user has simply
2263 forgotten a semicolon. */
2264 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2267 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2268 a C_ID_CLASSNAME. */
2269 c_parser_consume_token (parser
);
2272 if (kind
== C_ID_ID
)
2274 error_at (loc
, "unknown type name %qE", value
);
2275 t
.kind
= ctsk_typedef
;
2276 t
.spec
= error_mark_node
;
2278 else if (kind
== C_ID_TYPENAME
2279 && (!c_dialect_objc ()
2280 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2282 t
.kind
= ctsk_typedef
;
2283 /* For a typedef name, record the meaning, not the name.
2284 In case of 'foo foo, bar;'. */
2285 t
.spec
= lookup_name (value
);
2289 tree proto
= NULL_TREE
;
2290 gcc_assert (c_dialect_objc ());
2292 if (c_parser_next_token_is (parser
, CPP_LESS
))
2293 proto
= c_parser_objc_protocol_refs (parser
);
2294 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2297 t
.expr_const_operands
= true;
2298 declspecs_add_type (name_token
->location
, specs
, t
);
2301 if (c_parser_next_token_is (parser
, CPP_LESS
))
2303 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2304 nisse@lysator.liu.se. */
2306 gcc_assert (c_dialect_objc ());
2307 if (!typespec_ok
|| seen_type
)
2309 proto
= c_parser_objc_protocol_refs (parser
);
2311 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2313 t
.expr_const_operands
= true;
2314 declspecs_add_type (loc
, specs
, t
);
2317 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2318 switch (c_parser_peek_token (parser
)->keyword
)
2331 /* TODO: Distinguish between function specifiers (inline, noreturn)
2332 and storage class specifiers, either here or in
2333 declspecs_add_scspec. */
2334 declspecs_add_scspec (loc
, specs
,
2335 c_parser_peek_token (parser
)->value
);
2336 c_parser_consume_token (parser
);
2367 if (c_dialect_objc ())
2368 parser
->objc_need_raw_identifier
= true;
2369 t
.kind
= ctsk_resword
;
2370 t
.spec
= c_parser_peek_token (parser
)->value
;
2372 t
.expr_const_operands
= true;
2373 declspecs_add_type (loc
, specs
, t
);
2374 c_parser_consume_token (parser
);
2381 t
= c_parser_enum_specifier (parser
);
2382 declspecs_add_type (loc
, specs
, t
);
2390 t
= c_parser_struct_or_union_specifier (parser
);
2391 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2392 declspecs_add_type (loc
, specs
, t
);
2395 /* ??? The old parser rejected typeof after other type
2396 specifiers, but is a syntax error the best way of
2398 if (!typespec_ok
|| seen_type
)
2402 t
= c_parser_typeof_specifier (parser
);
2403 declspecs_add_type (loc
, specs
, t
);
2406 /* C parser handling of Objective-C constructs needs
2407 checking for correct lvalue-to-rvalue conversions, and
2408 the code in build_modify_expr handling various
2409 Objective-C cases, and that in build_unary_op handling
2410 Objective-C cases for increment / decrement, also needs
2411 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2412 and objc_types_are_equivalent may also need updates. */
2413 if (c_dialect_objc ())
2414 sorry ("%<_Atomic%> in Objective-C");
2415 /* C parser handling of OpenMP constructs needs checking for
2416 correct lvalue-to-rvalue conversions. */
2418 sorry ("%<_Atomic%> with OpenMP");
2420 pedwarn_c99 (loc
, OPT_Wpedantic
,
2421 "ISO C99 does not support the %<_Atomic%> qualifier");
2423 pedwarn_c99 (loc
, OPT_Wpedantic
,
2424 "ISO C90 does not support the %<_Atomic%> qualifier");
2427 value
= c_parser_peek_token (parser
)->value
;
2428 c_parser_consume_token (parser
);
2429 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2431 /* _Atomic ( type-name ). */
2433 c_parser_consume_token (parser
);
2434 struct c_type_name
*type
= c_parser_type_name (parser
);
2435 t
.kind
= ctsk_typeof
;
2436 t
.spec
= error_mark_node
;
2438 t
.expr_const_operands
= true;
2440 t
.spec
= groktypename (type
, &t
.expr
,
2441 &t
.expr_const_operands
);
2442 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2444 if (t
.spec
!= error_mark_node
)
2446 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2447 error_at (loc
, "%<_Atomic%>-qualified array type");
2448 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2449 error_at (loc
, "%<_Atomic%>-qualified function type");
2450 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2451 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2453 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2455 declspecs_add_type (loc
, specs
, t
);
2458 declspecs_add_qual (loc
, specs
, value
);
2464 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2465 c_parser_consume_token (parser
);
2470 attrs
= c_parser_attributes (parser
);
2471 declspecs_add_attrs (loc
, specs
, attrs
);
2476 align
= c_parser_alignas_specifier (parser
);
2477 declspecs_add_alignas (loc
, specs
, align
);
2486 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2489 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2490 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2491 enum attributes[opt] identifier
2493 The form with trailing comma is new in C99. The forms with
2494 attributes are GNU extensions. In GNU C, we accept any expression
2495 without commas in the syntax (assignment expressions, not just
2496 conditional expressions); assignment expressions will be diagnosed
2501 enumerator-list , enumerator
2504 enumeration-constant
2505 enumeration-constant = constant-expression
2508 static struct c_typespec
2509 c_parser_enum_specifier (c_parser
*parser
)
2511 struct c_typespec ret
;
2513 tree ident
= NULL_TREE
;
2514 location_t enum_loc
;
2515 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2516 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2517 enum_loc
= c_parser_peek_token (parser
)->location
;
2518 c_parser_consume_token (parser
);
2519 attrs
= c_parser_attributes (parser
);
2520 enum_loc
= c_parser_peek_token (parser
)->location
;
2521 /* Set the location in case we create a decl now. */
2522 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2523 if (c_parser_next_token_is (parser
, CPP_NAME
))
2525 ident
= c_parser_peek_token (parser
)->value
;
2526 ident_loc
= c_parser_peek_token (parser
)->location
;
2527 enum_loc
= ident_loc
;
2528 c_parser_consume_token (parser
);
2530 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2532 /* Parse an enum definition. */
2533 struct c_enum_contents the_enum
;
2536 /* We chain the enumerators in reverse order, then put them in
2537 forward order at the end. */
2539 timevar_push (TV_PARSE_ENUM
);
2540 type
= start_enum (enum_loc
, &the_enum
, ident
);
2542 c_parser_consume_token (parser
);
2550 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2551 location_t decl_loc
, value_loc
;
2552 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2554 c_parser_error (parser
, "expected identifier");
2555 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2556 values
= error_mark_node
;
2559 token
= c_parser_peek_token (parser
);
2560 enum_id
= token
->value
;
2561 /* Set the location in case we create a decl now. */
2562 c_parser_set_source_position_from_token (token
);
2563 decl_loc
= value_loc
= token
->location
;
2564 c_parser_consume_token (parser
);
2565 if (c_parser_next_token_is (parser
, CPP_EQ
))
2567 c_parser_consume_token (parser
);
2568 value_loc
= c_parser_peek_token (parser
)->location
;
2569 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2572 enum_value
= NULL_TREE
;
2573 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2574 &the_enum
, enum_id
, enum_value
);
2575 TREE_CHAIN (enum_decl
) = values
;
2578 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2580 comma_loc
= c_parser_peek_token (parser
)->location
;
2582 c_parser_consume_token (parser
);
2584 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2587 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2588 "comma at end of enumerator list");
2589 c_parser_consume_token (parser
);
2594 c_parser_error (parser
, "expected %<,%> or %<}%>");
2595 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2596 values
= error_mark_node
;
2600 postfix_attrs
= c_parser_attributes (parser
);
2601 ret
.spec
= finish_enum (type
, nreverse (values
),
2602 chainon (attrs
, postfix_attrs
));
2603 ret
.kind
= ctsk_tagdef
;
2604 ret
.expr
= NULL_TREE
;
2605 ret
.expr_const_operands
= true;
2606 timevar_pop (TV_PARSE_ENUM
);
2611 c_parser_error (parser
, "expected %<{%>");
2612 ret
.spec
= error_mark_node
;
2613 ret
.kind
= ctsk_tagref
;
2614 ret
.expr
= NULL_TREE
;
2615 ret
.expr_const_operands
= true;
2618 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2619 /* In ISO C, enumerated types can be referred to only if already
2621 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2624 pedwarn (enum_loc
, OPT_Wpedantic
,
2625 "ISO C forbids forward references to %<enum%> types");
2630 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2632 struct-or-union-specifier:
2633 struct-or-union attributes[opt] identifier[opt]
2634 { struct-contents } attributes[opt]
2635 struct-or-union attributes[opt] identifier
2638 struct-declaration-list
2640 struct-declaration-list:
2641 struct-declaration ;
2642 struct-declaration-list struct-declaration ;
2649 struct-declaration-list struct-declaration
2651 struct-declaration-list:
2652 struct-declaration-list ;
2655 (Note that in the syntax here, unlike that in ISO C, the semicolons
2656 are included here rather than in struct-declaration, in order to
2657 describe the syntax with extra semicolons and missing semicolon at
2662 struct-declaration-list:
2663 @defs ( class-name )
2665 (Note this does not include a trailing semicolon, but can be
2666 followed by further declarations, and gets a pedwarn-if-pedantic
2667 when followed by a semicolon.) */
2669 static struct c_typespec
2670 c_parser_struct_or_union_specifier (c_parser
*parser
)
2672 struct c_typespec ret
;
2674 tree ident
= NULL_TREE
;
2675 location_t struct_loc
;
2676 location_t ident_loc
= UNKNOWN_LOCATION
;
2677 enum tree_code code
;
2678 switch (c_parser_peek_token (parser
)->keyword
)
2689 struct_loc
= c_parser_peek_token (parser
)->location
;
2690 c_parser_consume_token (parser
);
2691 attrs
= c_parser_attributes (parser
);
2693 /* Set the location in case we create a decl now. */
2694 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2696 if (c_parser_next_token_is (parser
, CPP_NAME
))
2698 ident
= c_parser_peek_token (parser
)->value
;
2699 ident_loc
= c_parser_peek_token (parser
)->location
;
2700 struct_loc
= ident_loc
;
2701 c_parser_consume_token (parser
);
2703 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2705 /* Parse a struct or union definition. Start the scope of the
2706 tag before parsing components. */
2707 struct c_struct_parse_info
*struct_info
;
2708 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2710 /* We chain the components in reverse order, then put them in
2711 forward order at the end. Each struct-declaration may
2712 declare multiple components (comma-separated), so we must use
2713 chainon to join them, although when parsing each
2714 struct-declaration we can use TREE_CHAIN directly.
2716 The theory behind all this is that there will be more
2717 semicolon separated fields than comma separated fields, and
2718 so we'll be minimizing the number of node traversals required
2721 timevar_push (TV_PARSE_STRUCT
);
2722 contents
= NULL_TREE
;
2723 c_parser_consume_token (parser
);
2724 /* Handle the Objective-C @defs construct,
2725 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2726 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2729 gcc_assert (c_dialect_objc ());
2730 c_parser_consume_token (parser
);
2731 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2733 if (c_parser_next_token_is (parser
, CPP_NAME
)
2734 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2736 name
= c_parser_peek_token (parser
)->value
;
2737 c_parser_consume_token (parser
);
2741 c_parser_error (parser
, "expected class name");
2742 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2745 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2747 contents
= nreverse (objc_get_class_ivars (name
));
2750 /* Parse the struct-declarations and semicolons. Problems with
2751 semicolons are diagnosed here; empty structures are diagnosed
2756 /* Parse any stray semicolon. */
2757 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2759 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2760 "extra semicolon in struct or union specified");
2761 c_parser_consume_token (parser
);
2764 /* Stop if at the end of the struct or union contents. */
2765 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2767 c_parser_consume_token (parser
);
2770 /* Accept #pragmas at struct scope. */
2771 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2773 c_parser_pragma (parser
, pragma_struct
);
2776 /* Parse some comma-separated declarations, but not the
2777 trailing semicolon if any. */
2778 decls
= c_parser_struct_declaration (parser
);
2779 contents
= chainon (decls
, contents
);
2780 /* If no semicolon follows, either we have a parse error or
2781 are at the end of the struct or union and should
2783 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2784 c_parser_consume_token (parser
);
2787 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2788 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2789 "no semicolon at end of struct or union");
2790 else if (parser
->error
2791 || !c_parser_next_token_starts_declspecs (parser
))
2793 c_parser_error (parser
, "expected %<;%>");
2794 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2798 /* If we come here, we have already emitted an error
2799 for an expected `;', identifier or `(', and we also
2800 recovered already. Go on with the next field. */
2803 postfix_attrs
= c_parser_attributes (parser
);
2804 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2805 chainon (attrs
, postfix_attrs
), struct_info
);
2806 ret
.kind
= ctsk_tagdef
;
2807 ret
.expr
= NULL_TREE
;
2808 ret
.expr_const_operands
= true;
2809 timevar_pop (TV_PARSE_STRUCT
);
2814 c_parser_error (parser
, "expected %<{%>");
2815 ret
.spec
= error_mark_node
;
2816 ret
.kind
= ctsk_tagref
;
2817 ret
.expr
= NULL_TREE
;
2818 ret
.expr_const_operands
= true;
2821 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2825 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2826 the trailing semicolon.
2829 specifier-qualifier-list struct-declarator-list
2830 static_assert-declaration-no-semi
2832 specifier-qualifier-list:
2833 type-specifier specifier-qualifier-list[opt]
2834 type-qualifier specifier-qualifier-list[opt]
2835 attributes specifier-qualifier-list[opt]
2837 struct-declarator-list:
2839 struct-declarator-list , attributes[opt] struct-declarator
2842 declarator attributes[opt]
2843 declarator[opt] : constant-expression attributes[opt]
2848 __extension__ struct-declaration
2849 specifier-qualifier-list
2851 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2852 of attributes where shown is a GNU extension. In GNU C, we accept
2853 any expression without commas in the syntax (assignment
2854 expressions, not just conditional expressions); assignment
2855 expressions will be diagnosed as non-constant. */
2858 c_parser_struct_declaration (c_parser
*parser
)
2860 struct c_declspecs
*specs
;
2862 tree all_prefix_attrs
;
2864 location_t decl_loc
;
2865 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2869 ext
= disable_extension_diagnostics ();
2870 c_parser_consume_token (parser
);
2871 decl
= c_parser_struct_declaration (parser
);
2872 restore_extension_diagnostics (ext
);
2875 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2877 c_parser_static_assert_declaration_no_semi (parser
);
2880 specs
= build_null_declspecs ();
2881 decl_loc
= c_parser_peek_token (parser
)->location
;
2882 /* Strictly by the standard, we shouldn't allow _Alignas here,
2883 but it appears to have been intended to allow it there, so
2884 we're keeping it as it is until WG14 reaches a conclusion
2886 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2887 c_parser_declspecs (parser
, specs
, false, true, true,
2888 true, false, cla_nonabstract_decl
);
2891 if (!specs
->declspecs_seen_p
)
2893 c_parser_error (parser
, "expected specifier-qualifier-list");
2896 finish_declspecs (specs
);
2897 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2898 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2901 if (specs
->typespec_kind
== ctsk_none
)
2903 pedwarn (decl_loc
, OPT_Wpedantic
,
2904 "ISO C forbids member declarations with no members");
2905 shadow_tag_warned (specs
, pedantic
);
2910 /* Support for unnamed structs or unions as members of
2911 structs or unions (which is [a] useful and [b] supports
2915 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2916 build_id_declarator (NULL_TREE
), specs
,
2919 decl_attributes (&ret
, attrs
, 0);
2924 /* Provide better error recovery. Note that a type name here is valid,
2925 and will be treated as a field name. */
2926 if (specs
->typespec_kind
== ctsk_tagdef
2927 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2928 && c_parser_next_token_starts_declspecs (parser
)
2929 && !c_parser_next_token_is (parser
, CPP_NAME
))
2931 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2932 parser
->error
= false;
2936 pending_xref_error ();
2937 prefix_attrs
= specs
->attrs
;
2938 all_prefix_attrs
= prefix_attrs
;
2939 specs
->attrs
= NULL_TREE
;
2943 /* Declaring one or more declarators or un-named bit-fields. */
2944 struct c_declarator
*declarator
;
2946 if (c_parser_next_token_is (parser
, CPP_COLON
))
2947 declarator
= build_id_declarator (NULL_TREE
);
2949 declarator
= c_parser_declarator (parser
,
2950 specs
->typespec_kind
!= ctsk_none
,
2951 C_DTR_NORMAL
, &dummy
);
2952 if (declarator
== NULL
)
2954 c_parser_skip_to_end_of_block_or_statement (parser
);
2957 if (c_parser_next_token_is (parser
, CPP_COLON
)
2958 || c_parser_next_token_is (parser
, CPP_COMMA
)
2959 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2960 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2961 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2963 tree postfix_attrs
= NULL_TREE
;
2964 tree width
= NULL_TREE
;
2966 if (c_parser_next_token_is (parser
, CPP_COLON
))
2968 c_parser_consume_token (parser
);
2969 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2971 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2972 postfix_attrs
= c_parser_attributes (parser
);
2973 d
= grokfield (c_parser_peek_token (parser
)->location
,
2974 declarator
, specs
, width
, &all_prefix_attrs
);
2975 decl_attributes (&d
, chainon (postfix_attrs
,
2976 all_prefix_attrs
), 0);
2977 DECL_CHAIN (d
) = decls
;
2979 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2980 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2983 all_prefix_attrs
= prefix_attrs
;
2984 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2985 c_parser_consume_token (parser
);
2986 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2987 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2989 /* Semicolon consumed in caller. */
2994 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3000 c_parser_error (parser
,
3001 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3002 "%<__attribute__%>");
3009 /* Parse a typeof specifier (a GNU extension).
3012 typeof ( expression )
3013 typeof ( type-name )
3016 static struct c_typespec
3017 c_parser_typeof_specifier (c_parser
*parser
)
3019 struct c_typespec ret
;
3020 ret
.kind
= ctsk_typeof
;
3021 ret
.spec
= error_mark_node
;
3022 ret
.expr
= NULL_TREE
;
3023 ret
.expr_const_operands
= true;
3024 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3025 c_parser_consume_token (parser
);
3026 c_inhibit_evaluation_warnings
++;
3028 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3030 c_inhibit_evaluation_warnings
--;
3034 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3036 struct c_type_name
*type
= c_parser_type_name (parser
);
3037 c_inhibit_evaluation_warnings
--;
3041 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3042 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3048 location_t here
= c_parser_peek_token (parser
)->location
;
3049 struct c_expr expr
= c_parser_expression (parser
);
3050 c_inhibit_evaluation_warnings
--;
3052 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3053 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3054 error_at (here
, "%<typeof%> applied to a bit-field");
3055 mark_exp_read (expr
.value
);
3056 ret
.spec
= TREE_TYPE (expr
.value
);
3057 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3058 /* This is returned with the type so that when the type is
3059 evaluated, this can be evaluated. */
3061 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3062 pop_maybe_used (was_vm
);
3063 /* For use in macros such as those in <stdatomic.h>, remove all
3064 qualifiers from atomic types. (const can be an issue for more macros
3065 using typeof than just the <stdatomic.h> ones.) */
3066 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3067 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3069 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3073 /* Parse an alignment-specifier.
3077 alignment-specifier:
3078 _Alignas ( type-name )
3079 _Alignas ( constant-expression )
3083 c_parser_alignas_specifier (c_parser
* parser
)
3085 tree ret
= error_mark_node
;
3086 location_t loc
= c_parser_peek_token (parser
)->location
;
3087 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3088 c_parser_consume_token (parser
);
3090 pedwarn_c99 (loc
, OPT_Wpedantic
,
3091 "ISO C99 does not support %<_Alignas%>");
3093 pedwarn_c99 (loc
, OPT_Wpedantic
,
3094 "ISO C90 does not support %<_Alignas%>");
3095 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3097 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3099 struct c_type_name
*type
= c_parser_type_name (parser
);
3101 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3105 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3106 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3110 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3111 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3112 be redeclared; otherwise it may not. KIND indicates which kind of
3113 declarator is wanted. Returns a valid declarator except in the
3114 case of a syntax error in which case NULL is returned. *SEEN_ID is
3115 set to true if an identifier being declared is seen; this is used
3116 to diagnose bad forms of abstract array declarators and to
3117 determine whether an identifier list is syntactically permitted.
3120 pointer[opt] direct-declarator
3124 ( attributes[opt] declarator )
3125 direct-declarator array-declarator
3126 direct-declarator ( parameter-type-list )
3127 direct-declarator ( identifier-list[opt] )
3130 * type-qualifier-list[opt]
3131 * type-qualifier-list[opt] pointer
3133 type-qualifier-list:
3136 type-qualifier-list type-qualifier
3137 type-qualifier-list attributes
3140 [ type-qualifier-list[opt] assignment-expression[opt] ]
3141 [ static type-qualifier-list[opt] assignment-expression ]
3142 [ type-qualifier-list static assignment-expression ]
3143 [ type-qualifier-list[opt] * ]
3145 parameter-type-list:
3147 parameter-list , ...
3150 parameter-declaration
3151 parameter-list , parameter-declaration
3153 parameter-declaration:
3154 declaration-specifiers declarator attributes[opt]
3155 declaration-specifiers abstract-declarator[opt] attributes[opt]
3159 identifier-list , identifier
3161 abstract-declarator:
3163 pointer[opt] direct-abstract-declarator
3165 direct-abstract-declarator:
3166 ( attributes[opt] abstract-declarator )
3167 direct-abstract-declarator[opt] array-declarator
3168 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3173 direct-declarator ( parameter-forward-declarations
3174 parameter-type-list[opt] )
3176 direct-abstract-declarator:
3177 direct-abstract-declarator[opt] ( parameter-forward-declarations
3178 parameter-type-list[opt] )
3180 parameter-forward-declarations:
3182 parameter-forward-declarations parameter-list ;
3184 The uses of attributes shown above are GNU extensions.
3186 Some forms of array declarator are not included in C99 in the
3187 syntax for abstract declarators; these are disallowed elsewhere.
3188 This may be a defect (DR#289).
3190 This function also accepts an omitted abstract declarator as being
3191 an abstract declarator, although not part of the formal syntax. */
3193 static struct c_declarator
*
3194 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3197 /* Parse any initial pointer part. */
3198 if (c_parser_next_token_is (parser
, CPP_MULT
))
3200 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3201 struct c_declarator
*inner
;
3202 c_parser_consume_token (parser
);
3203 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3204 false, false, cla_prefer_id
);
3205 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3209 return make_pointer_declarator (quals_attrs
, inner
);
3211 /* Now we have a direct declarator, direct abstract declarator or
3212 nothing (which counts as a direct abstract declarator here). */
3213 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3216 /* Parse a direct declarator or direct abstract declarator; arguments
3217 as c_parser_declarator. */
3219 static struct c_declarator
*
3220 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3223 /* The direct declarator must start with an identifier (possibly
3224 omitted) or a parenthesized declarator (possibly abstract). In
3225 an ordinary declarator, initial parentheses must start a
3226 parenthesized declarator. In an abstract declarator or parameter
3227 declarator, they could start a parenthesized declarator or a
3228 parameter list. To tell which, the open parenthesis and any
3229 following attributes must be read. If a declaration specifier
3230 follows, then it is a parameter list; if the specifier is a
3231 typedef name, there might be an ambiguity about redeclaring it,
3232 which is resolved in the direction of treating it as a typedef
3233 name. If a close parenthesis follows, it is also an empty
3234 parameter list, as the syntax does not permit empty abstract
3235 declarators. Otherwise, it is a parenthesized declarator (in
3236 which case the analysis may be repeated inside it, recursively).
3238 ??? There is an ambiguity in a parameter declaration "int
3239 (__attribute__((foo)) x)", where x is not a typedef name: it
3240 could be an abstract declarator for a function, or declare x with
3241 parentheses. The proper resolution of this ambiguity needs
3242 documenting. At present we follow an accident of the old
3243 parser's implementation, whereby the first parameter must have
3244 some declaration specifiers other than just attributes. Thus as
3245 a parameter declaration it is treated as a parenthesized
3246 parameter named x, and as an abstract declarator it is
3249 ??? Also following the old parser, attributes inside an empty
3250 parameter list are ignored, making it a list not yielding a
3251 prototype, rather than giving an error or making it have one
3252 parameter with implicit type int.
3254 ??? Also following the old parser, typedef names may be
3255 redeclared in declarators, but not Objective-C class names. */
3257 if (kind
!= C_DTR_ABSTRACT
3258 && c_parser_next_token_is (parser
, CPP_NAME
)
3260 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3261 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3262 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3264 struct c_declarator
*inner
3265 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3267 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3268 c_parser_consume_token (parser
);
3269 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3272 if (kind
!= C_DTR_NORMAL
3273 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3275 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3276 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3279 /* Either we are at the end of an abstract declarator, or we have
3282 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3285 struct c_declarator
*inner
;
3286 c_parser_consume_token (parser
);
3287 attrs
= c_parser_attributes (parser
);
3288 if (kind
!= C_DTR_NORMAL
3289 && (c_parser_next_token_starts_declspecs (parser
)
3290 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3292 struct c_arg_info
*args
3293 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3300 = build_function_declarator (args
,
3301 build_id_declarator (NULL_TREE
));
3302 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3306 /* A parenthesized declarator. */
3307 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3308 if (inner
!= NULL
&& attrs
!= NULL
)
3309 inner
= build_attrs_declarator (attrs
, inner
);
3310 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3312 c_parser_consume_token (parser
);
3316 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3320 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3327 if (kind
== C_DTR_NORMAL
)
3329 c_parser_error (parser
, "expected identifier or %<(%>");
3333 return build_id_declarator (NULL_TREE
);
3337 /* Parse part of a direct declarator or direct abstract declarator,
3338 given that some (in INNER) has already been parsed; ID_PRESENT is
3339 true if an identifier is present, false for an abstract
3342 static struct c_declarator
*
3343 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3344 struct c_declarator
*inner
)
3346 /* Parse a sequence of array declarators and parameter lists. */
3347 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3349 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3350 struct c_declarator
*declarator
;
3351 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3354 struct c_expr dimen
;
3355 dimen
.value
= NULL_TREE
;
3356 dimen
.original_code
= ERROR_MARK
;
3357 dimen
.original_type
= NULL_TREE
;
3358 c_parser_consume_token (parser
);
3359 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3360 false, false, cla_prefer_id
);
3361 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3363 c_parser_consume_token (parser
);
3364 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3365 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3366 false, false, cla_prefer_id
);
3367 if (!quals_attrs
->declspecs_seen_p
)
3369 /* If "static" is present, there must be an array dimension.
3370 Otherwise, there may be a dimension, "*", or no
3375 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3379 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3381 dimen
.value
= NULL_TREE
;
3384 else if (flag_cilkplus
3385 && c_parser_next_token_is (parser
, CPP_COLON
))
3387 dimen
.value
= error_mark_node
;
3389 error_at (c_parser_peek_token (parser
)->location
,
3390 "array notations cannot be used in declaration");
3391 c_parser_consume_token (parser
);
3393 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3395 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3397 dimen
.value
= NULL_TREE
;
3399 c_parser_consume_token (parser
);
3404 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3410 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3413 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3414 c_parser_consume_token (parser
);
3415 else if (flag_cilkplus
3416 && c_parser_next_token_is (parser
, CPP_COLON
))
3418 error_at (c_parser_peek_token (parser
)->location
,
3419 "array notations cannot be used in declaration");
3420 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3425 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3430 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3431 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3432 static_seen
, star_seen
);
3433 if (declarator
== NULL
)
3435 inner
= set_array_declarator_inner (declarator
, inner
);
3436 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3438 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3441 struct c_arg_info
*args
;
3442 c_parser_consume_token (parser
);
3443 attrs
= c_parser_attributes (parser
);
3444 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3449 inner
= build_function_declarator (args
, inner
);
3450 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3456 /* Parse a parameter list or identifier list, including the closing
3457 parenthesis but not the opening one. ATTRS are the attributes at
3458 the start of the list. ID_LIST_OK is true if an identifier list is
3459 acceptable; such a list must not have attributes at the start. */
3461 static struct c_arg_info
*
3462 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3465 declare_parm_level ();
3466 /* If the list starts with an identifier, it is an identifier list.
3467 Otherwise, it is either a prototype list or an empty list. */
3470 && c_parser_next_token_is (parser
, CPP_NAME
)
3471 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3473 /* Look ahead to detect typos in type names. */
3474 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3475 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3476 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3477 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3479 tree list
= NULL_TREE
, *nextp
= &list
;
3480 while (c_parser_next_token_is (parser
, CPP_NAME
)
3481 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3483 *nextp
= build_tree_list (NULL_TREE
,
3484 c_parser_peek_token (parser
)->value
);
3485 nextp
= & TREE_CHAIN (*nextp
);
3486 c_parser_consume_token (parser
);
3487 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3489 c_parser_consume_token (parser
);
3490 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3492 c_parser_error (parser
, "expected identifier");
3496 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3498 struct c_arg_info
*ret
= build_arg_info ();
3500 c_parser_consume_token (parser
);
3506 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3514 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3521 /* Parse a parameter list (possibly empty), including the closing
3522 parenthesis but not the opening one. ATTRS are the attributes at
3523 the start of the list. EXPR is NULL or an expression that needs to
3524 be evaluated for the side effects of array size expressions in the
3527 static struct c_arg_info
*
3528 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3530 bool bad_parm
= false;
3532 /* ??? Following the old parser, forward parameter declarations may
3533 use abstract declarators, and if no real parameter declarations
3534 follow the forward declarations then this is not diagnosed. Also
3535 note as above that attributes are ignored as the only contents of
3536 the parentheses, or as the only contents after forward
3538 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3540 struct c_arg_info
*ret
= build_arg_info ();
3541 c_parser_consume_token (parser
);
3544 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3546 struct c_arg_info
*ret
= build_arg_info ();
3548 if (flag_allow_parameterless_variadic_functions
)
3550 /* F (...) is allowed. */
3551 ret
->types
= NULL_TREE
;
3555 /* Suppress -Wold-style-definition for this case. */
3556 ret
->types
= error_mark_node
;
3557 error_at (c_parser_peek_token (parser
)->location
,
3558 "ISO C requires a named argument before %<...%>");
3560 c_parser_consume_token (parser
);
3561 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3563 c_parser_consume_token (parser
);
3568 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3573 /* Nonempty list of parameters, either terminated with semicolon
3574 (forward declarations; recurse) or with close parenthesis (normal
3575 function) or with ", ... )" (variadic function). */
3578 /* Parse a parameter. */
3579 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3584 push_parm_decl (parm
, &expr
);
3585 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3588 c_parser_consume_token (parser
);
3589 mark_forward_parm_decls ();
3590 new_attrs
= c_parser_attributes (parser
);
3591 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3593 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3595 c_parser_consume_token (parser
);
3599 return get_parm_info (false, expr
);
3601 if (!c_parser_require (parser
, CPP_COMMA
,
3602 "expected %<;%>, %<,%> or %<)%>"))
3604 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3607 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3609 c_parser_consume_token (parser
);
3610 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3612 c_parser_consume_token (parser
);
3616 return get_parm_info (true, expr
);
3620 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3628 /* Parse a parameter declaration. ATTRS are the attributes at the
3629 start of the declaration if it is the first parameter. */
3631 static struct c_parm
*
3632 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3634 struct c_declspecs
*specs
;
3635 struct c_declarator
*declarator
;
3637 tree postfix_attrs
= NULL_TREE
;
3640 /* Accept #pragmas between parameter declarations. */
3641 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3642 c_parser_pragma (parser
, pragma_param
);
3644 if (!c_parser_next_token_starts_declspecs (parser
))
3646 c_token
*token
= c_parser_peek_token (parser
);
3649 c_parser_set_source_position_from_token (token
);
3650 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3652 error_at (token
->location
, "unknown type name %qE", token
->value
);
3653 parser
->error
= true;
3655 /* ??? In some Objective-C cases '...' isn't applicable so there
3656 should be a different message. */
3658 c_parser_error (parser
,
3659 "expected declaration specifiers or %<...%>");
3660 c_parser_skip_to_end_of_parameter (parser
);
3663 specs
= build_null_declspecs ();
3666 declspecs_add_attrs (input_location
, specs
, attrs
);
3669 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3670 cla_nonabstract_decl
);
3671 finish_declspecs (specs
);
3672 pending_xref_error ();
3673 prefix_attrs
= specs
->attrs
;
3674 specs
->attrs
= NULL_TREE
;
3675 declarator
= c_parser_declarator (parser
,
3676 specs
->typespec_kind
!= ctsk_none
,
3677 C_DTR_PARM
, &dummy
);
3678 if (declarator
== NULL
)
3680 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3683 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3684 postfix_attrs
= c_parser_attributes (parser
);
3685 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3689 /* Parse a string literal in an asm expression. It should not be
3690 translated, and wide string literals are an error although
3691 permitted by the syntax. This is a GNU extension.
3696 ??? At present, following the old parser, the caller needs to have
3697 set lex_untranslated_string to 1. It would be better to follow the
3698 C++ parser rather than using this kludge. */
3701 c_parser_asm_string_literal (c_parser
*parser
)
3704 int save_flag
= warn_overlength_strings
;
3705 warn_overlength_strings
= 0;
3706 if (c_parser_next_token_is (parser
, CPP_STRING
))
3708 str
= c_parser_peek_token (parser
)->value
;
3709 c_parser_consume_token (parser
);
3711 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3713 error_at (c_parser_peek_token (parser
)->location
,
3714 "wide string literal in %<asm%>");
3715 str
= build_string (1, "");
3716 c_parser_consume_token (parser
);
3720 c_parser_error (parser
, "expected string literal");
3723 warn_overlength_strings
= save_flag
;
3727 /* Parse a simple asm expression. This is used in restricted
3728 contexts, where a full expression with inputs and outputs does not
3729 make sense. This is a GNU extension.
3732 asm ( asm-string-literal )
3736 c_parser_simple_asm_expr (c_parser
*parser
)
3739 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3740 /* ??? Follow the C++ parser rather than using the
3741 lex_untranslated_string kludge. */
3742 parser
->lex_untranslated_string
= true;
3743 c_parser_consume_token (parser
);
3744 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3746 parser
->lex_untranslated_string
= false;
3749 str
= c_parser_asm_string_literal (parser
);
3750 parser
->lex_untranslated_string
= false;
3751 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3753 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3760 c_parser_attribute_any_word (c_parser
*parser
)
3762 tree attr_name
= NULL_TREE
;
3764 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3766 /* ??? See comment above about what keywords are accepted here. */
3768 switch (c_parser_peek_token (parser
)->keyword
)
3798 case RID_TRANSACTION_ATOMIC
:
3799 case RID_TRANSACTION_CANCEL
:
3815 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3816 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3818 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3819 attr_name
= c_parser_peek_token (parser
)->value
;
3824 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3825 "__vector" or "__vector__." */
3828 is_cilkplus_vector_p (tree name
)
3830 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3835 #define CILK_SIMD_FN_CLAUSE_MASK \
3836 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3837 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3838 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3839 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3840 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3842 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3843 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3844 pushed into the token list.
3847 vector (<vector attributes>). */
3850 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3852 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3854 int paren_scope
= 0;
3855 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3856 /* Consume the "vector" token. */
3857 c_parser_consume_token (parser
);
3859 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3861 c_parser_consume_token (parser
);
3864 while (paren_scope
> 0)
3866 c_token
*token
= c_parser_peek_token (parser
);
3867 if (token
->type
== CPP_OPEN_PAREN
)
3869 else if (token
->type
== CPP_CLOSE_PAREN
)
3871 /* Do not push the last ')' since we are not pushing the '('. */
3872 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3873 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3874 c_parser_consume_token (parser
);
3877 /* Since we are converting an attribute to a pragma, we need to end the
3878 attribute with PRAGMA_EOL. */
3880 memset (&eol_token
, 0, sizeof (eol_token
));
3881 eol_token
.type
= CPP_PRAGMA_EOL
;
3882 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3885 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3888 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3890 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3892 /* c_parser_attributes is called in several places, so if these EOF
3893 tokens are already inserted, then don't do them again. */
3894 if (last_token
.type
== CPP_EOF
)
3897 /* Two CPP_EOF token are added as a safety net since the normal C
3898 front-end has two token look-ahead. */
3900 eof_token
.type
= CPP_EOF
;
3901 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3902 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3905 /* Parse (possibly empty) attributes. This is a GNU extension.
3909 attributes attribute
3912 __attribute__ ( ( attribute-list ) )
3916 attribute_list , attrib
3921 any-word ( identifier )
3922 any-word ( identifier , nonempty-expr-list )
3923 any-word ( expr-list )
3925 where the "identifier" must not be declared as a type, and
3926 "any-word" may be any identifier (including one declared as a
3927 type), a reserved word storage class specifier, type specifier or
3928 type qualifier. ??? This still leaves out most reserved keywords
3929 (following the old parser), shouldn't we include them, and why not
3930 allow identifiers declared as types to start the arguments? */
3933 c_parser_attributes (c_parser
*parser
)
3935 tree attrs
= NULL_TREE
;
3936 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3938 /* ??? Follow the C++ parser rather than using the
3939 lex_untranslated_string kludge. */
3940 parser
->lex_untranslated_string
= true;
3941 c_parser_consume_token (parser
);
3942 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3944 parser
->lex_untranslated_string
= false;
3947 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3949 parser
->lex_untranslated_string
= false;
3950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3953 /* Parse the attribute list. */
3954 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3955 || c_parser_next_token_is (parser
, CPP_NAME
)
3956 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3958 tree attr
, attr_name
, attr_args
;
3959 vec
<tree
, va_gc
> *expr_list
;
3960 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3962 c_parser_consume_token (parser
);
3966 attr_name
= c_parser_attribute_any_word (parser
);
3967 if (attr_name
== NULL
)
3969 if (is_cilkplus_vector_p (attr_name
))
3971 c_token
*v_token
= c_parser_peek_token (parser
);
3972 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3975 c_parser_consume_token (parser
);
3976 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3978 attr
= build_tree_list (attr_name
, NULL_TREE
);
3979 attrs
= chainon (attrs
, attr
);
3982 c_parser_consume_token (parser
);
3983 /* Parse the attribute contents. If they start with an
3984 identifier which is followed by a comma or close
3985 parenthesis, then the arguments start with that
3986 identifier; otherwise they are an expression list.
3987 In objective-c the identifier may be a classname. */
3988 if (c_parser_next_token_is (parser
, CPP_NAME
)
3989 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3990 || (c_dialect_objc ()
3991 && c_parser_peek_token (parser
)->id_kind
3993 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3994 || (c_parser_peek_2nd_token (parser
)->type
3995 == CPP_CLOSE_PAREN
))
3996 && (attribute_takes_identifier_p (attr_name
)
3997 || (c_dialect_objc ()
3998 && c_parser_peek_token (parser
)->id_kind
3999 == C_ID_CLASSNAME
)))
4001 tree arg1
= c_parser_peek_token (parser
)->value
;
4002 c_parser_consume_token (parser
);
4003 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4004 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4008 c_parser_consume_token (parser
);
4009 expr_list
= c_parser_expr_list (parser
, false, true,
4010 NULL
, NULL
, NULL
, NULL
);
4011 tree_list
= build_tree_list_vec (expr_list
);
4012 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4013 release_tree_vector (expr_list
);
4018 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4019 attr_args
= NULL_TREE
;
4022 expr_list
= c_parser_expr_list (parser
, false, true,
4023 NULL
, NULL
, NULL
, NULL
);
4024 attr_args
= build_tree_list_vec (expr_list
);
4025 release_tree_vector (expr_list
);
4028 attr
= build_tree_list (attr_name
, attr_args
);
4029 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4030 c_parser_consume_token (parser
);
4033 parser
->lex_untranslated_string
= false;
4034 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4038 attrs
= chainon (attrs
, attr
);
4040 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4041 c_parser_consume_token (parser
);
4044 parser
->lex_untranslated_string
= false;
4045 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4049 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4050 c_parser_consume_token (parser
);
4053 parser
->lex_untranslated_string
= false;
4054 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4058 parser
->lex_untranslated_string
= false;
4061 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4062 c_finish_cilk_simd_fn_tokens (parser
);
4066 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4069 specifier-qualifier-list abstract-declarator[opt]
4072 static struct c_type_name
*
4073 c_parser_type_name (c_parser
*parser
)
4075 struct c_declspecs
*specs
= build_null_declspecs ();
4076 struct c_declarator
*declarator
;
4077 struct c_type_name
*ret
;
4079 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4081 if (!specs
->declspecs_seen_p
)
4083 c_parser_error (parser
, "expected specifier-qualifier-list");
4086 if (specs
->type
!= error_mark_node
)
4088 pending_xref_error ();
4089 finish_declspecs (specs
);
4091 declarator
= c_parser_declarator (parser
,
4092 specs
->typespec_kind
!= ctsk_none
,
4093 C_DTR_ABSTRACT
, &dummy
);
4094 if (declarator
== NULL
)
4096 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4098 ret
->declarator
= declarator
;
4102 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4105 assignment-expression
4106 { initializer-list }
4107 { initializer-list , }
4110 designation[opt] initializer
4111 initializer-list , designation[opt] initializer
4118 designator-list designator
4125 [ constant-expression ]
4137 [ constant-expression ... constant-expression ]
4139 Any expression without commas is accepted in the syntax for the
4140 constant-expressions, with non-constant expressions rejected later.
4142 This function is only used for top-level initializers; for nested
4143 ones, see c_parser_initval. */
4145 static struct c_expr
4146 c_parser_initializer (c_parser
*parser
)
4148 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4149 return c_parser_braced_init (parser
, NULL_TREE
, false);
4153 location_t loc
= c_parser_peek_token (parser
)->location
;
4154 ret
= c_parser_expr_no_commas (parser
, NULL
);
4155 if (TREE_CODE (ret
.value
) != STRING_CST
4156 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4157 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4162 /* Parse a braced initializer list. TYPE is the type specified for a
4163 compound literal, and NULL_TREE for other initializers and for
4164 nested braced lists. NESTED_P is true for nested braced lists,
4165 false for the list of a compound literal or the list that is the
4166 top-level initializer in a declaration. */
4168 static struct c_expr
4169 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4172 struct obstack braced_init_obstack
;
4173 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4174 gcc_obstack_init (&braced_init_obstack
);
4175 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4176 c_parser_consume_token (parser
);
4178 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4180 really_start_incremental_init (type
);
4181 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4183 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4187 /* Parse a non-empty initializer list, possibly with a trailing
4191 c_parser_initelt (parser
, &braced_init_obstack
);
4194 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4195 c_parser_consume_token (parser
);
4198 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4202 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4204 ret
.value
= error_mark_node
;
4205 ret
.original_code
= ERROR_MARK
;
4206 ret
.original_type
= NULL
;
4207 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4208 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4209 obstack_free (&braced_init_obstack
, NULL
);
4212 c_parser_consume_token (parser
);
4213 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4214 obstack_free (&braced_init_obstack
, NULL
);
4218 /* Parse a nested initializer, including designators. */
4221 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4223 /* Parse any designator or designator list. A single array
4224 designator may have the subsequent "=" omitted in GNU C, but a
4225 longer list or a structure member designator may not. */
4226 if (c_parser_next_token_is (parser
, CPP_NAME
)
4227 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4229 /* Old-style structure member designator. */
4230 set_init_label (c_parser_peek_token (parser
)->location
,
4231 c_parser_peek_token (parser
)->value
,
4232 braced_init_obstack
);
4233 /* Use the colon as the error location. */
4234 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4235 "obsolete use of designated initializer with %<:%>");
4236 c_parser_consume_token (parser
);
4237 c_parser_consume_token (parser
);
4241 /* des_seen is 0 if there have been no designators, 1 if there
4242 has been a single array designator and 2 otherwise. */
4244 /* Location of a designator. */
4245 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4246 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4247 || c_parser_next_token_is (parser
, CPP_DOT
))
4249 int des_prev
= des_seen
;
4251 des_loc
= c_parser_peek_token (parser
)->location
;
4254 if (c_parser_next_token_is (parser
, CPP_DOT
))
4257 c_parser_consume_token (parser
);
4258 if (c_parser_next_token_is (parser
, CPP_NAME
))
4260 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4261 braced_init_obstack
);
4262 c_parser_consume_token (parser
);
4267 init
.value
= error_mark_node
;
4268 init
.original_code
= ERROR_MARK
;
4269 init
.original_type
= NULL
;
4270 c_parser_error (parser
, "expected identifier");
4271 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4272 process_init_element (input_location
, init
, false,
4273 braced_init_obstack
);
4280 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4281 location_t array_index_loc
= UNKNOWN_LOCATION
;
4282 /* ??? Following the old parser, [ objc-receiver
4283 objc-message-args ] is accepted as an initializer,
4284 being distinguished from a designator by what follows
4285 the first assignment expression inside the square
4286 brackets, but after a first array designator a
4287 subsequent square bracket is for Objective-C taken to
4288 start an expression, using the obsolete form of
4289 designated initializer without '=', rather than
4290 possibly being a second level of designation: in LALR
4291 terms, the '[' is shifted rather than reducing
4292 designator to designator-list. */
4293 if (des_prev
== 1 && c_dialect_objc ())
4295 des_seen
= des_prev
;
4298 if (des_prev
== 0 && c_dialect_objc ())
4300 /* This might be an array designator or an
4301 Objective-C message expression. If the former,
4302 continue parsing here; if the latter, parse the
4303 remainder of the initializer given the starting
4304 primary-expression. ??? It might make sense to
4305 distinguish when des_prev == 1 as well; see
4306 previous comment. */
4308 struct c_expr mexpr
;
4309 c_parser_consume_token (parser
);
4310 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4311 && ((c_parser_peek_token (parser
)->id_kind
4313 || (c_parser_peek_token (parser
)->id_kind
4314 == C_ID_CLASSNAME
)))
4316 /* Type name receiver. */
4317 tree id
= c_parser_peek_token (parser
)->value
;
4318 c_parser_consume_token (parser
);
4319 rec
= objc_get_class_reference (id
);
4320 goto parse_message_args
;
4322 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4323 mark_exp_read (first
);
4324 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4325 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4326 goto array_desig_after_first
;
4327 /* Expression receiver. So far only one part
4328 without commas has been parsed; there might be
4329 more of the expression. */
4331 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4334 location_t comma_loc
, exp_loc
;
4335 comma_loc
= c_parser_peek_token (parser
)->location
;
4336 c_parser_consume_token (parser
);
4337 exp_loc
= c_parser_peek_token (parser
)->location
;
4338 next
= c_parser_expr_no_commas (parser
, NULL
);
4339 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4341 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4344 /* Now parse the objc-message-args. */
4345 args
= c_parser_objc_message_args (parser
);
4346 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4349 = objc_build_message_expr (rec
, args
);
4350 mexpr
.original_code
= ERROR_MARK
;
4351 mexpr
.original_type
= NULL
;
4352 /* Now parse and process the remainder of the
4353 initializer, starting with this message
4354 expression as a primary-expression. */
4355 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4358 c_parser_consume_token (parser
);
4359 array_index_loc
= c_parser_peek_token (parser
)->location
;
4360 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4361 mark_exp_read (first
);
4362 array_desig_after_first
:
4363 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4365 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4366 c_parser_consume_token (parser
);
4367 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4368 mark_exp_read (second
);
4372 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4374 c_parser_consume_token (parser
);
4375 set_init_index (array_index_loc
, first
, second
,
4376 braced_init_obstack
);
4378 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4379 "ISO C forbids specifying range of elements to initialize");
4382 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4388 if (c_parser_next_token_is (parser
, CPP_EQ
))
4390 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4391 "ISO C90 forbids specifying subobject "
4393 c_parser_consume_token (parser
);
4398 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4399 "obsolete use of designated initializer without %<=%>");
4403 init
.value
= error_mark_node
;
4404 init
.original_code
= ERROR_MARK
;
4405 init
.original_type
= NULL
;
4406 c_parser_error (parser
, "expected %<=%>");
4407 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4408 process_init_element (input_location
, init
, false,
4409 braced_init_obstack
);
4415 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4418 /* Parse a nested initializer; as c_parser_initializer but parses
4419 initializers within braced lists, after any designators have been
4420 applied. If AFTER is not NULL then it is an Objective-C message
4421 expression which is the primary-expression starting the
4425 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4426 struct obstack
* braced_init_obstack
)
4429 gcc_assert (!after
|| c_dialect_objc ());
4430 location_t loc
= c_parser_peek_token (parser
)->location
;
4432 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4433 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4436 init
= c_parser_expr_no_commas (parser
, after
);
4437 if (init
.value
!= NULL_TREE
4438 && TREE_CODE (init
.value
) != STRING_CST
4439 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4440 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4442 process_init_element (loc
, init
, false, braced_init_obstack
);
4445 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4449 { block-item-list[opt] }
4450 { label-declarations block-item-list }
4454 block-item-list block-item
4466 { label-declarations block-item-list }
4469 __extension__ nested-declaration
4470 nested-function-definition
4474 label-declarations label-declaration
4477 __label__ identifier-list ;
4479 Allowing the mixing of declarations and code is new in C99. The
4480 GNU syntax also permits (not shown above) labels at the end of
4481 compound statements, which yield an error. We don't allow labels
4482 on declarations; this might seem like a natural extension, but
4483 there would be a conflict between attributes on the label and
4484 prefix attributes on the declaration. ??? The syntax follows the
4485 old parser in requiring something after label declarations.
4486 Although they are erroneous if the labels declared aren't defined,
4487 is it useful for the syntax to be this way?
4508 cancellation-point-directive */
4511 c_parser_compound_statement (c_parser
*parser
)
4514 location_t brace_loc
;
4515 brace_loc
= c_parser_peek_token (parser
)->location
;
4516 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4518 /* Ensure a scope is entered and left anyway to avoid confusion
4519 if we have just prepared to enter a function body. */
4520 stmt
= c_begin_compound_stmt (true);
4521 c_end_compound_stmt (brace_loc
, stmt
, true);
4522 return error_mark_node
;
4524 stmt
= c_begin_compound_stmt (true);
4525 c_parser_compound_statement_nostart (parser
);
4527 /* If the compound stmt contains array notations, then we expand them. */
4528 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4529 stmt
= expand_array_notation_exprs (stmt
);
4530 return c_end_compound_stmt (brace_loc
, stmt
, true);
4533 /* Parse a compound statement except for the opening brace. This is
4534 used for parsing both compound statements and statement expressions
4535 (which follow different paths to handling the opening). */
4538 c_parser_compound_statement_nostart (c_parser
*parser
)
4540 bool last_stmt
= false;
4541 bool last_label
= false;
4542 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4543 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4544 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4546 c_parser_consume_token (parser
);
4549 mark_valid_location_for_stdc_pragma (true);
4550 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4552 /* Read zero or more forward-declarations for labels that nested
4553 functions can jump to. */
4554 mark_valid_location_for_stdc_pragma (false);
4555 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4557 label_loc
= c_parser_peek_token (parser
)->location
;
4558 c_parser_consume_token (parser
);
4559 /* Any identifiers, including those declared as type names,
4564 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4566 c_parser_error (parser
, "expected identifier");
4570 = declare_label (c_parser_peek_token (parser
)->value
);
4571 C_DECLARED_LABEL_FLAG (label
) = 1;
4572 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4573 c_parser_consume_token (parser
);
4574 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4575 c_parser_consume_token (parser
);
4579 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4581 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4583 /* We must now have at least one statement, label or declaration. */
4584 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4586 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4587 c_parser_error (parser
, "expected declaration or statement");
4588 c_parser_consume_token (parser
);
4591 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4593 location_t loc
= c_parser_peek_token (parser
)->location
;
4594 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4595 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4596 || (c_parser_next_token_is (parser
, CPP_NAME
)
4597 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4599 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4600 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4602 label_loc
= c_parser_peek_token (parser
)->location
;
4605 mark_valid_location_for_stdc_pragma (false);
4606 c_parser_label (parser
);
4608 else if (!last_label
4609 && c_parser_next_tokens_start_declaration (parser
))
4612 mark_valid_location_for_stdc_pragma (false);
4613 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4616 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4617 "ISO C90 forbids mixed declarations and code");
4620 else if (!last_label
4621 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4623 /* __extension__ can start a declaration, but is also an
4624 unary operator that can start an expression. Consume all
4625 but the last of a possible series of __extension__ to
4627 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4628 && (c_parser_peek_2nd_token (parser
)->keyword
4630 c_parser_consume_token (parser
);
4631 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4634 ext
= disable_extension_diagnostics ();
4635 c_parser_consume_token (parser
);
4637 mark_valid_location_for_stdc_pragma (false);
4638 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4640 /* Following the old parser, __extension__ does not
4641 disable this diagnostic. */
4642 restore_extension_diagnostics (ext
);
4644 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4645 "ISO C90 forbids mixed declarations and code");
4651 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4653 /* External pragmas, and some omp pragmas, are not associated
4654 with regular c code, and so are not to be considered statements
4655 syntactically. This ensures that the user doesn't put them
4656 places that would turn into syntax errors if the directive
4658 if (c_parser_pragma (parser
, pragma_compound
))
4659 last_label
= false, last_stmt
= true;
4661 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4663 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4664 c_parser_error (parser
, "expected declaration or statement");
4667 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4669 if (parser
->in_if_block
)
4671 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4672 error_at (loc
, """expected %<}%> before %<else%>");
4677 error_at (loc
, "%<else%> without a previous %<if%>");
4678 c_parser_consume_token (parser
);
4687 mark_valid_location_for_stdc_pragma (false);
4688 c_parser_statement_after_labels (parser
);
4691 parser
->error
= false;
4694 error_at (label_loc
, "label at end of compound statement");
4695 c_parser_consume_token (parser
);
4696 /* Restore the value we started with. */
4697 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4700 /* Parse all consecutive labels. */
4703 c_parser_all_labels (c_parser
*parser
)
4705 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4706 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4707 || (c_parser_next_token_is (parser
, CPP_NAME
)
4708 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4709 c_parser_label (parser
);
4712 /* Parse a label (C90 6.6.1, C99 6.8.1).
4715 identifier : attributes[opt]
4716 case constant-expression :
4722 case constant-expression ... constant-expression :
4724 The use of attributes on labels is a GNU extension. The syntax in
4725 GNU C accepts any expressions without commas, non-constant
4726 expressions being rejected later. */
4729 c_parser_label (c_parser
*parser
)
4731 location_t loc1
= c_parser_peek_token (parser
)->location
;
4732 tree label
= NULL_TREE
;
4733 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4736 c_parser_consume_token (parser
);
4737 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4738 if (c_parser_next_token_is (parser
, CPP_COLON
))
4740 c_parser_consume_token (parser
);
4741 label
= do_case (loc1
, exp1
, NULL_TREE
);
4743 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4745 c_parser_consume_token (parser
);
4746 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4747 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4748 label
= do_case (loc1
, exp1
, exp2
);
4751 c_parser_error (parser
, "expected %<:%> or %<...%>");
4753 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4755 c_parser_consume_token (parser
);
4756 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4757 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4761 tree name
= c_parser_peek_token (parser
)->value
;
4764 location_t loc2
= c_parser_peek_token (parser
)->location
;
4765 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4766 c_parser_consume_token (parser
);
4767 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4768 c_parser_consume_token (parser
);
4769 attrs
= c_parser_attributes (parser
);
4770 tlab
= define_label (loc2
, name
);
4773 decl_attributes (&tlab
, attrs
, 0);
4774 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4779 if (c_parser_next_tokens_start_declaration (parser
))
4781 error_at (c_parser_peek_token (parser
)->location
,
4782 "a label can only be part of a statement and "
4783 "a declaration is not a statement");
4784 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4785 /*static_assert_ok*/ true,
4786 /*empty_ok*/ true, /*nested*/ true,
4787 /*start_attr_ok*/ true, NULL
,
4793 /* Parse a statement (C90 6.6, C99 6.8).
4798 expression-statement
4806 expression-statement:
4809 selection-statement:
4813 iteration-statement:
4822 return expression[opt] ;
4835 objc-throw-statement
4836 objc-try-catch-statement
4837 objc-synchronized-statement
4839 objc-throw-statement:
4855 parallel-directive structured-block
4858 kernels-directive structured-block
4861 data-directive structured-block
4864 loop-directive structured-block
4878 parallel-for-construct
4879 parallel-for-simd-construct
4880 parallel-sections-construct
4887 parallel-directive structured-block
4890 for-directive iteration-statement
4893 simd-directive iteration-statements
4896 for-simd-directive iteration-statements
4899 sections-directive section-scope
4902 single-directive structured-block
4904 parallel-for-construct:
4905 parallel-for-directive iteration-statement
4907 parallel-for-simd-construct:
4908 parallel-for-simd-directive iteration-statement
4910 parallel-sections-construct:
4911 parallel-sections-directive section-scope
4914 master-directive structured-block
4917 critical-directive structured-block
4920 atomic-directive expression-statement
4923 ordered-directive structured-block
4925 Transactional Memory:
4928 transaction-statement
4929 transaction-cancel-statement
4933 c_parser_statement (c_parser
*parser
)
4935 c_parser_all_labels (parser
);
4936 c_parser_statement_after_labels (parser
);
4939 /* Parse a statement, other than a labeled statement. */
4942 c_parser_statement_after_labels (c_parser
*parser
)
4944 location_t loc
= c_parser_peek_token (parser
)->location
;
4945 tree stmt
= NULL_TREE
;
4946 bool in_if_block
= parser
->in_if_block
;
4947 parser
->in_if_block
= false;
4948 switch (c_parser_peek_token (parser
)->type
)
4950 case CPP_OPEN_BRACE
:
4951 add_stmt (c_parser_compound_statement (parser
));
4954 switch (c_parser_peek_token (parser
)->keyword
)
4957 c_parser_if_statement (parser
);
4960 c_parser_switch_statement (parser
);
4963 c_parser_while_statement (parser
, false);
4966 c_parser_do_statement (parser
, false);
4969 c_parser_for_statement (parser
, false);
4974 error_at (c_parser_peek_token (parser
)->location
,
4975 "-fcilkplus must be enabled to use %<_Cilk_for%>");
4976 c_parser_skip_to_end_of_block_or_statement (parser
);
4979 c_parser_cilk_for (parser
, integer_zero_node
);
4982 c_parser_consume_token (parser
);
4983 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4985 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4987 add_stmt (build_cilk_sync ());
4990 c_parser_consume_token (parser
);
4991 if (c_parser_next_token_is (parser
, CPP_NAME
))
4993 stmt
= c_finish_goto_label (loc
,
4994 c_parser_peek_token (parser
)->value
);
4995 c_parser_consume_token (parser
);
4997 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5001 c_parser_consume_token (parser
);
5002 val
= c_parser_expression (parser
);
5003 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5004 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5007 c_parser_error (parser
, "expected identifier or %<*%>");
5008 goto expect_semicolon
;
5010 c_parser_consume_token (parser
);
5011 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5012 goto expect_semicolon
;
5014 c_parser_consume_token (parser
);
5015 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5016 goto expect_semicolon
;
5018 c_parser_consume_token (parser
);
5019 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5021 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5022 c_parser_consume_token (parser
);
5026 location_t xloc
= c_parser_peek_token (parser
)->location
;
5027 struct c_expr expr
= c_parser_expression_conv (parser
);
5028 mark_exp_read (expr
.value
);
5029 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
5030 goto expect_semicolon
;
5034 stmt
= c_parser_asm_statement (parser
);
5036 case RID_TRANSACTION_ATOMIC
:
5037 case RID_TRANSACTION_RELAXED
:
5038 stmt
= c_parser_transaction (parser
,
5039 c_parser_peek_token (parser
)->keyword
);
5041 case RID_TRANSACTION_CANCEL
:
5042 stmt
= c_parser_transaction_cancel (parser
);
5043 goto expect_semicolon
;
5045 gcc_assert (c_dialect_objc ());
5046 c_parser_consume_token (parser
);
5047 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5049 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5050 c_parser_consume_token (parser
);
5054 struct c_expr expr
= c_parser_expression (parser
);
5055 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5056 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5057 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5058 goto expect_semicolon
;
5062 gcc_assert (c_dialect_objc ());
5063 c_parser_objc_try_catch_finally_statement (parser
);
5065 case RID_AT_SYNCHRONIZED
:
5066 gcc_assert (c_dialect_objc ());
5067 c_parser_objc_synchronized_statement (parser
);
5074 c_parser_consume_token (parser
);
5076 case CPP_CLOSE_PAREN
:
5077 case CPP_CLOSE_SQUARE
:
5078 /* Avoid infinite loop in error recovery:
5079 c_parser_skip_until_found stops at a closing nesting
5080 delimiter without consuming it, but here we need to consume
5081 it to proceed further. */
5082 c_parser_error (parser
, "expected statement");
5083 c_parser_consume_token (parser
);
5086 c_parser_pragma (parser
, pragma_stmt
);
5090 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5092 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5095 /* Two cases cannot and do not have line numbers associated: If stmt
5096 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5097 cannot hold line numbers. But that's OK because the statement
5098 will either be changed to a MODIFY_EXPR during gimplification of
5099 the statement expr, or discarded. If stmt was compound, but
5100 without new variables, we will have skipped the creation of a
5101 BIND and will have a bare STATEMENT_LIST. But that's OK because
5102 (recursively) all of the component statements should already have
5103 line numbers assigned. ??? Can we discard no-op statements
5105 if (CAN_HAVE_LOCATION_P (stmt
)
5106 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5107 SET_EXPR_LOCATION (stmt
, loc
);
5109 parser
->in_if_block
= in_if_block
;
5112 /* Parse the condition from an if, do, while or for statements. */
5115 c_parser_condition (c_parser
*parser
)
5117 location_t loc
= c_parser_peek_token (parser
)->location
;
5119 cond
= c_parser_expression_conv (parser
).value
;
5120 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5121 cond
= c_fully_fold (cond
, false, NULL
);
5122 if (warn_sequence_point
)
5123 verify_sequence_points (cond
);
5127 /* Parse a parenthesized condition from an if, do or while statement.
5133 c_parser_paren_condition (c_parser
*parser
)
5136 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5137 return error_mark_node
;
5138 cond
= c_parser_condition (parser
);
5139 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5143 /* Parse a statement which is a block in C99. */
5146 c_parser_c99_block_statement (c_parser
*parser
)
5148 tree block
= c_begin_compound_stmt (flag_isoc99
);
5149 location_t loc
= c_parser_peek_token (parser
)->location
;
5150 c_parser_statement (parser
);
5151 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5154 /* Parse the body of an if statement. This is just parsing a
5155 statement but (a) it is a block in C99, (b) we track whether the
5156 body is an if statement for the sake of -Wparentheses warnings, (c)
5157 we handle an empty body specially for the sake of -Wempty-body
5158 warnings, and (d) we call parser_compound_statement directly
5159 because c_parser_statement_after_labels resets
5160 parser->in_if_block. */
5163 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5165 tree block
= c_begin_compound_stmt (flag_isoc99
);
5166 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5167 c_parser_all_labels (parser
);
5168 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5169 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5171 location_t loc
= c_parser_peek_token (parser
)->location
;
5172 add_stmt (build_empty_stmt (loc
));
5173 c_parser_consume_token (parser
);
5174 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5175 warning_at (loc
, OPT_Wempty_body
,
5176 "suggest braces around empty body in an %<if%> statement");
5178 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5179 add_stmt (c_parser_compound_statement (parser
));
5181 c_parser_statement_after_labels (parser
);
5182 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5185 /* Parse the else body of an if statement. This is just parsing a
5186 statement but (a) it is a block in C99, (b) we handle an empty body
5187 specially for the sake of -Wempty-body warnings. */
5190 c_parser_else_body (c_parser
*parser
)
5192 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5193 tree block
= c_begin_compound_stmt (flag_isoc99
);
5194 c_parser_all_labels (parser
);
5195 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5197 location_t loc
= c_parser_peek_token (parser
)->location
;
5200 "suggest braces around empty body in an %<else%> statement");
5201 add_stmt (build_empty_stmt (loc
));
5202 c_parser_consume_token (parser
);
5205 c_parser_statement_after_labels (parser
);
5206 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5209 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5212 if ( expression ) statement
5213 if ( expression ) statement else statement
5217 c_parser_if_statement (c_parser
*parser
)
5222 bool first_if
= false;
5223 tree first_body
, second_body
;
5227 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5228 c_parser_consume_token (parser
);
5229 block
= c_begin_compound_stmt (flag_isoc99
);
5230 loc
= c_parser_peek_token (parser
)->location
;
5231 cond
= c_parser_paren_condition (parser
);
5232 in_if_block
= parser
->in_if_block
;
5233 parser
->in_if_block
= true;
5234 first_body
= c_parser_if_body (parser
, &first_if
);
5235 parser
->in_if_block
= in_if_block
;
5236 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5238 c_parser_consume_token (parser
);
5239 second_body
= c_parser_else_body (parser
);
5242 second_body
= NULL_TREE
;
5243 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5244 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5246 /* If the if statement contains array notations, then we expand them. */
5247 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5248 if_stmt
= fix_conditional_array_notations (if_stmt
);
5252 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5255 switch (expression) statement
5259 c_parser_switch_statement (c_parser
*parser
)
5262 tree block
, expr
, body
, save_break
;
5263 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5264 location_t switch_cond_loc
;
5265 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5266 c_parser_consume_token (parser
);
5267 block
= c_begin_compound_stmt (flag_isoc99
);
5268 bool explicit_cast_p
= false;
5269 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5271 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5272 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5273 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5274 explicit_cast_p
= true;
5275 ce
= c_parser_expression (parser
);
5276 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5278 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5280 error_at (switch_cond_loc
,
5281 "array notations cannot be used as a condition for switch "
5283 expr
= error_mark_node
;
5285 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5289 switch_cond_loc
= UNKNOWN_LOCATION
;
5290 expr
= error_mark_node
;
5292 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5293 save_break
= c_break_label
;
5294 c_break_label
= NULL_TREE
;
5295 body
= c_parser_c99_block_statement (parser
);
5296 c_finish_case (body
, ce
.original_type
);
5299 location_t here
= c_parser_peek_token (parser
)->location
;
5300 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5301 SET_EXPR_LOCATION (t
, here
);
5304 c_break_label
= save_break
;
5305 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5308 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5311 while (expression) statement
5315 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5317 tree block
, cond
, body
, save_break
, save_cont
;
5319 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5320 c_parser_consume_token (parser
);
5321 block
= c_begin_compound_stmt (flag_isoc99
);
5322 loc
= c_parser_peek_token (parser
)->location
;
5323 cond
= c_parser_paren_condition (parser
);
5324 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5326 error_at (loc
, "array notations cannot be used as a condition for while "
5328 cond
= error_mark_node
;
5331 if (ivdep
&& cond
!= error_mark_node
)
5332 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5333 build_int_cst (integer_type_node
,
5334 annot_expr_ivdep_kind
));
5335 save_break
= c_break_label
;
5336 c_break_label
= NULL_TREE
;
5337 save_cont
= c_cont_label
;
5338 c_cont_label
= NULL_TREE
;
5339 body
= c_parser_c99_block_statement (parser
);
5340 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5341 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5342 c_break_label
= save_break
;
5343 c_cont_label
= save_cont
;
5346 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5349 do statement while ( expression ) ;
5353 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5355 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5357 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5358 c_parser_consume_token (parser
);
5359 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5360 warning_at (c_parser_peek_token (parser
)->location
,
5362 "suggest braces around empty body in %<do%> statement");
5363 block
= c_begin_compound_stmt (flag_isoc99
);
5364 loc
= c_parser_peek_token (parser
)->location
;
5365 save_break
= c_break_label
;
5366 c_break_label
= NULL_TREE
;
5367 save_cont
= c_cont_label
;
5368 c_cont_label
= NULL_TREE
;
5369 body
= c_parser_c99_block_statement (parser
);
5370 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5371 new_break
= c_break_label
;
5372 c_break_label
= save_break
;
5373 new_cont
= c_cont_label
;
5374 c_cont_label
= save_cont
;
5375 cond
= c_parser_paren_condition (parser
);
5376 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5378 error_at (loc
, "array notations cannot be used as a condition for a "
5379 "do-while statement");
5380 cond
= error_mark_node
;
5382 if (ivdep
&& cond
!= error_mark_node
)
5383 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5384 build_int_cst (integer_type_node
,
5385 annot_expr_ivdep_kind
));
5386 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5387 c_parser_skip_to_end_of_block_or_statement (parser
);
5388 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5389 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5392 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5395 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5396 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5398 The form with a declaration is new in C99.
5400 ??? In accordance with the old parser, the declaration may be a
5401 nested function, which is then rejected in check_for_loop_decls,
5402 but does it make any sense for this to be included in the grammar?
5403 Note in particular that the nested function does not include a
5404 trailing ';', whereas the "declaration" production includes one.
5405 Also, can we reject bad declarations earlier and cheaper than
5406 check_for_loop_decls?
5408 In Objective-C, there are two additional variants:
5411 for ( expression in expresssion ) statement
5412 for ( declaration in expression ) statement
5414 This is inconsistent with C, because the second variant is allowed
5415 even if c99 is not enabled.
5417 The rest of the comment documents these Objective-C foreach-statement.
5419 Here is the canonical example of the first variant:
5420 for (object in array) { do something with object }
5421 we call the first expression ("object") the "object_expression" and
5422 the second expression ("array") the "collection_expression".
5423 object_expression must be an lvalue of type "id" (a generic Objective-C
5424 object) because the loop works by assigning to object_expression the
5425 various objects from the collection_expression. collection_expression
5426 must evaluate to something of type "id" which responds to the method
5427 countByEnumeratingWithState:objects:count:.
5429 The canonical example of the second variant is:
5430 for (id object in array) { do something with object }
5431 which is completely equivalent to
5434 for (object in array) { do something with object }
5436 Note that initizializing 'object' in some way (eg, "for ((object =
5437 xxx) in array) { do something with object }") is possibly
5438 technically valid, but completely pointless as 'object' will be
5439 assigned to something else as soon as the loop starts. We should
5440 most likely reject it (TODO).
5442 The beginning of the Objective-C foreach-statement looks exactly
5443 like the beginning of the for-statement, and we can tell it is a
5444 foreach-statement only because the initial declaration or
5445 expression is terminated by 'in' instead of ';'.
5449 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5451 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5452 /* The following are only used when parsing an ObjC foreach statement. */
5453 tree object_expression
;
5454 /* Silence the bogus uninitialized warning. */
5455 tree collection_expression
= NULL
;
5456 location_t loc
= c_parser_peek_token (parser
)->location
;
5457 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5458 bool is_foreach_statement
= false;
5459 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5460 c_parser_consume_token (parser
);
5461 /* Open a compound statement in Objective-C as well, just in case this is
5462 as foreach expression. */
5463 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5464 cond
= error_mark_node
;
5465 incr
= error_mark_node
;
5466 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5468 /* Parse the initialization declaration or expression. */
5469 object_expression
= error_mark_node
;
5470 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5471 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5473 parser
->objc_could_be_foreach_context
= false;
5474 c_parser_consume_token (parser
);
5475 c_finish_expr_stmt (loc
, NULL_TREE
);
5477 else if (c_parser_next_tokens_start_declaration (parser
))
5479 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5480 &object_expression
, vNULL
);
5481 parser
->objc_could_be_foreach_context
= false;
5483 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5485 c_parser_consume_token (parser
);
5486 is_foreach_statement
= true;
5487 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5488 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5491 check_for_loop_decls (for_loc
, flag_isoc99
);
5493 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5495 /* __extension__ can start a declaration, but is also an
5496 unary operator that can start an expression. Consume all
5497 but the last of a possible series of __extension__ to
5499 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5500 && (c_parser_peek_2nd_token (parser
)->keyword
5502 c_parser_consume_token (parser
);
5503 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5506 ext
= disable_extension_diagnostics ();
5507 c_parser_consume_token (parser
);
5508 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5509 true, &object_expression
, vNULL
);
5510 parser
->objc_could_be_foreach_context
= false;
5512 restore_extension_diagnostics (ext
);
5513 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5515 c_parser_consume_token (parser
);
5516 is_foreach_statement
= true;
5517 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5518 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5521 check_for_loop_decls (for_loc
, flag_isoc99
);
5531 tree init_expression
;
5532 ce
= c_parser_expression (parser
);
5533 init_expression
= ce
.value
;
5534 parser
->objc_could_be_foreach_context
= false;
5535 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5537 c_parser_consume_token (parser
);
5538 is_foreach_statement
= true;
5539 if (! lvalue_p (init_expression
))
5540 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5541 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5545 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5546 init_expression
= ce
.value
;
5547 c_finish_expr_stmt (loc
, init_expression
);
5548 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5552 /* Parse the loop condition. In the case of a foreach
5553 statement, there is no loop condition. */
5554 gcc_assert (!parser
->objc_could_be_foreach_context
);
5555 if (!is_foreach_statement
)
5557 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5561 c_parser_error (parser
, "missing loop condition in loop with "
5562 "%<GCC ivdep%> pragma");
5563 cond
= error_mark_node
;
5567 c_parser_consume_token (parser
);
5573 cond
= c_parser_condition (parser
);
5574 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5576 error_at (loc
, "array notations cannot be used in a "
5577 "condition for a for-loop");
5578 cond
= error_mark_node
;
5580 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5583 if (ivdep
&& cond
!= error_mark_node
)
5584 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5585 build_int_cst (integer_type_node
,
5586 annot_expr_ivdep_kind
));
5588 /* Parse the increment expression (the third expression in a
5589 for-statement). In the case of a foreach-statement, this is
5590 the expression that follows the 'in'. */
5591 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5593 if (is_foreach_statement
)
5595 c_parser_error (parser
, "missing collection in fast enumeration");
5596 collection_expression
= error_mark_node
;
5599 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5603 if (is_foreach_statement
)
5604 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5608 struct c_expr ce
= c_parser_expression (parser
);
5609 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5610 incr
= c_process_expr_stmt (loc
, ce
.value
);
5613 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5615 save_break
= c_break_label
;
5616 c_break_label
= NULL_TREE
;
5617 save_cont
= c_cont_label
;
5618 c_cont_label
= NULL_TREE
;
5619 body
= c_parser_c99_block_statement (parser
);
5620 if (is_foreach_statement
)
5621 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5623 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5624 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5625 c_break_label
= save_break
;
5626 c_cont_label
= save_cont
;
5629 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5630 statement with inputs, outputs, clobbers, and volatile tag
5634 asm type-qualifier[opt] ( asm-argument ) ;
5635 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5639 asm-string-literal : asm-operands[opt]
5640 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5641 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5644 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5647 Qualifiers other than volatile are accepted in the syntax but
5651 c_parser_asm_statement (c_parser
*parser
)
5653 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5654 bool simple
, is_goto
;
5655 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5656 int section
, nsections
;
5658 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5659 c_parser_consume_token (parser
);
5660 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5662 quals
= c_parser_peek_token (parser
)->value
;
5663 c_parser_consume_token (parser
);
5665 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5666 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5668 warning_at (c_parser_peek_token (parser
)->location
,
5670 "%E qualifier ignored on asm",
5671 c_parser_peek_token (parser
)->value
);
5673 c_parser_consume_token (parser
);
5679 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5681 c_parser_consume_token (parser
);
5685 /* ??? Follow the C++ parser rather than using the
5686 lex_untranslated_string kludge. */
5687 parser
->lex_untranslated_string
= true;
5690 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5693 str
= c_parser_asm_string_literal (parser
);
5694 if (str
== NULL_TREE
)
5695 goto error_close_paren
;
5698 outputs
= NULL_TREE
;
5700 clobbers
= NULL_TREE
;
5703 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5706 /* Parse each colon-delimited section of operands. */
5707 nsections
= 3 + is_goto
;
5708 for (section
= 0; section
< nsections
; ++section
)
5710 if (!c_parser_require (parser
, CPP_COLON
,
5713 : "expected %<:%> or %<)%>"))
5714 goto error_close_paren
;
5716 /* Once past any colon, we're no longer a simple asm. */
5719 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5720 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5725 /* For asm goto, we don't allow output operands, but reserve
5726 the slot for a future extension that does allow them. */
5728 outputs
= c_parser_asm_operands (parser
);
5731 inputs
= c_parser_asm_operands (parser
);
5734 clobbers
= c_parser_asm_clobbers (parser
);
5737 labels
= c_parser_asm_goto_operands (parser
);
5743 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5748 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5750 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5754 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5755 c_parser_skip_to_end_of_block_or_statement (parser
);
5757 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5758 clobbers
, labels
, simple
));
5761 parser
->lex_untranslated_string
= false;
5765 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5769 /* Parse asm operands, a GNU extension.
5773 asm-operands , asm-operand
5776 asm-string-literal ( expression )
5777 [ identifier ] asm-string-literal ( expression )
5781 c_parser_asm_operands (c_parser
*parser
)
5783 tree list
= NULL_TREE
;
5788 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5790 c_parser_consume_token (parser
);
5791 if (c_parser_next_token_is (parser
, CPP_NAME
))
5793 tree id
= c_parser_peek_token (parser
)->value
;
5794 c_parser_consume_token (parser
);
5795 name
= build_string (IDENTIFIER_LENGTH (id
),
5796 IDENTIFIER_POINTER (id
));
5800 c_parser_error (parser
, "expected identifier");
5801 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5804 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5809 str
= c_parser_asm_string_literal (parser
);
5810 if (str
== NULL_TREE
)
5812 parser
->lex_untranslated_string
= false;
5813 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5815 parser
->lex_untranslated_string
= true;
5818 expr
= c_parser_expression (parser
);
5819 mark_exp_read (expr
.value
);
5820 parser
->lex_untranslated_string
= true;
5821 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5823 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5826 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5828 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5829 c_parser_consume_token (parser
);
5836 /* Parse asm clobbers, a GNU extension.
5840 asm-clobbers , asm-string-literal
5844 c_parser_asm_clobbers (c_parser
*parser
)
5846 tree list
= NULL_TREE
;
5849 tree str
= c_parser_asm_string_literal (parser
);
5851 list
= tree_cons (NULL_TREE
, str
, list
);
5854 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5855 c_parser_consume_token (parser
);
5862 /* Parse asm goto labels, a GNU extension.
5866 asm-goto-operands , identifier
5870 c_parser_asm_goto_operands (c_parser
*parser
)
5872 tree list
= NULL_TREE
;
5877 if (c_parser_next_token_is (parser
, CPP_NAME
))
5879 c_token
*tok
= c_parser_peek_token (parser
);
5881 label
= lookup_label_for_goto (tok
->location
, name
);
5882 c_parser_consume_token (parser
);
5883 TREE_USED (label
) = 1;
5887 c_parser_error (parser
, "expected identifier");
5891 name
= build_string (IDENTIFIER_LENGTH (name
),
5892 IDENTIFIER_POINTER (name
));
5893 list
= tree_cons (name
, label
, list
);
5894 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5895 c_parser_consume_token (parser
);
5897 return nreverse (list
);
5901 /* Parse an expression other than a compound expression; that is, an
5902 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5903 NULL then it is an Objective-C message expression which is the
5904 primary-expression starting the expression as an initializer.
5906 assignment-expression:
5907 conditional-expression
5908 unary-expression assignment-operator assignment-expression
5910 assignment-operator: one of
5911 = *= /= %= += -= <<= >>= &= ^= |=
5913 In GNU C we accept any conditional expression on the LHS and
5914 diagnose the invalid lvalue rather than producing a syntax
5917 static struct c_expr
5918 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5919 tree omp_atomic_lhs
)
5921 struct c_expr lhs
, rhs
, ret
;
5922 enum tree_code code
;
5923 location_t op_location
, exp_location
;
5924 gcc_assert (!after
|| c_dialect_objc ());
5925 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5926 op_location
= c_parser_peek_token (parser
)->location
;
5927 switch (c_parser_peek_token (parser
)->type
)
5936 code
= TRUNC_DIV_EXPR
;
5939 code
= TRUNC_MOD_EXPR
;
5954 code
= BIT_AND_EXPR
;
5957 code
= BIT_XOR_EXPR
;
5960 code
= BIT_IOR_EXPR
;
5965 c_parser_consume_token (parser
);
5966 exp_location
= c_parser_peek_token (parser
)->location
;
5967 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5968 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5970 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5971 code
, exp_location
, rhs
.value
,
5973 if (code
== NOP_EXPR
)
5974 ret
.original_code
= MODIFY_EXPR
;
5977 TREE_NO_WARNING (ret
.value
) = 1;
5978 ret
.original_code
= ERROR_MARK
;
5980 ret
.original_type
= NULL
;
5984 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5985 is not NULL then it is an Objective-C message expression which is
5986 the primary-expression starting the expression as an initializer.
5988 conditional-expression:
5989 logical-OR-expression
5990 logical-OR-expression ? expression : conditional-expression
5994 conditional-expression:
5995 logical-OR-expression ? : conditional-expression
5998 static struct c_expr
5999 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6000 tree omp_atomic_lhs
)
6002 struct c_expr cond
, exp1
, exp2
, ret
;
6003 location_t cond_loc
, colon_loc
, middle_loc
;
6005 gcc_assert (!after
|| c_dialect_objc ());
6007 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6009 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6011 cond_loc
= c_parser_peek_token (parser
)->location
;
6012 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6013 c_parser_consume_token (parser
);
6014 if (c_parser_next_token_is (parser
, CPP_COLON
))
6016 tree eptype
= NULL_TREE
;
6018 middle_loc
= c_parser_peek_token (parser
)->location
;
6019 pedwarn (middle_loc
, OPT_Wpedantic
,
6020 "ISO C forbids omitting the middle term of a ?: expression");
6021 warn_for_omitted_condop (middle_loc
, cond
.value
);
6022 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6024 eptype
= TREE_TYPE (cond
.value
);
6025 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6027 /* Make sure first operand is calculated only once. */
6028 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6030 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6031 exp1
.original_type
= NULL
;
6032 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6033 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6038 = c_objc_common_truthvalue_conversion
6039 (cond_loc
, default_conversion (cond
.value
));
6040 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6041 exp1
= c_parser_expression_conv (parser
);
6042 mark_exp_read (exp1
.value
);
6043 c_inhibit_evaluation_warnings
+=
6044 ((cond
.value
== truthvalue_true_node
)
6045 - (cond
.value
== truthvalue_false_node
));
6048 colon_loc
= c_parser_peek_token (parser
)->location
;
6049 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6051 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6052 ret
.value
= error_mark_node
;
6053 ret
.original_code
= ERROR_MARK
;
6054 ret
.original_type
= NULL
;
6058 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6059 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6060 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6062 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6063 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6064 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6065 exp1
.value
, exp1
.original_type
,
6066 exp2
.value
, exp2
.original_type
);
6067 ret
.original_code
= ERROR_MARK
;
6068 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6069 ret
.original_type
= NULL
;
6074 /* If both sides are enum type, the default conversion will have
6075 made the type of the result be an integer type. We want to
6076 remember the enum types we started with. */
6077 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6078 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6079 ret
.original_type
= ((t1
!= error_mark_node
6080 && t2
!= error_mark_node
6081 && (TYPE_MAIN_VARIANT (t1
)
6082 == TYPE_MAIN_VARIANT (t2
)))
6089 /* Parse a binary expression; that is, a logical-OR-expression (C90
6090 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6091 an Objective-C message expression which is the primary-expression
6092 starting the expression as an initializer.
6094 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6095 when it should be the unfolded lhs. In a valid OpenMP source,
6096 one of the operands of the toplevel binary expression must be equal
6097 to it. In that case, just return a build2 created binary operation
6098 rather than result of parser_build_binary_op.
6100 multiplicative-expression:
6102 multiplicative-expression * cast-expression
6103 multiplicative-expression / cast-expression
6104 multiplicative-expression % cast-expression
6106 additive-expression:
6107 multiplicative-expression
6108 additive-expression + multiplicative-expression
6109 additive-expression - multiplicative-expression
6113 shift-expression << additive-expression
6114 shift-expression >> additive-expression
6116 relational-expression:
6118 relational-expression < shift-expression
6119 relational-expression > shift-expression
6120 relational-expression <= shift-expression
6121 relational-expression >= shift-expression
6123 equality-expression:
6124 relational-expression
6125 equality-expression == relational-expression
6126 equality-expression != relational-expression
6130 AND-expression & equality-expression
6132 exclusive-OR-expression:
6134 exclusive-OR-expression ^ AND-expression
6136 inclusive-OR-expression:
6137 exclusive-OR-expression
6138 inclusive-OR-expression | exclusive-OR-expression
6140 logical-AND-expression:
6141 inclusive-OR-expression
6142 logical-AND-expression && inclusive-OR-expression
6144 logical-OR-expression:
6145 logical-AND-expression
6146 logical-OR-expression || logical-AND-expression
6149 static struct c_expr
6150 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6151 tree omp_atomic_lhs
)
6153 /* A binary expression is parsed using operator-precedence parsing,
6154 with the operands being cast expressions. All the binary
6155 operators are left-associative. Thus a binary expression is of
6158 E0 op1 E1 op2 E2 ...
6160 which we represent on a stack. On the stack, the precedence
6161 levels are strictly increasing. When a new operator is
6162 encountered of higher precedence than that at the top of the
6163 stack, it is pushed; its LHS is the top expression, and its RHS
6164 is everything parsed until it is popped. When a new operator is
6165 encountered with precedence less than or equal to that at the top
6166 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6167 by the result of the operation until the operator at the top of
6168 the stack has lower precedence than the new operator or there is
6169 only one element on the stack; then the top expression is the LHS
6170 of the new operator. In the case of logical AND and OR
6171 expressions, we also need to adjust c_inhibit_evaluation_warnings
6172 as appropriate when the operators are pushed and popped. */
6175 /* The expression at this stack level. */
6177 /* The precedence of the operator on its left, PREC_NONE at the
6178 bottom of the stack. */
6179 enum c_parser_prec prec
;
6180 /* The operation on its left. */
6182 /* The source location of this operation. */
6186 /* Location of the binary operator. */
6187 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6190 switch (stack[sp].op) \
6192 case TRUTH_ANDIF_EXPR: \
6193 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6194 == truthvalue_false_node); \
6196 case TRUTH_ORIF_EXPR: \
6197 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6198 == truthvalue_true_node); \
6203 stack[sp - 1].expr \
6204 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6205 stack[sp - 1].expr, true, true); \
6207 = convert_lvalue_to_rvalue (stack[sp].loc, \
6208 stack[sp].expr, true, true); \
6209 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6210 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6211 && ((1 << stack[sp].prec) \
6212 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6213 | PREC_ADD | PREC_MULT))) \
6214 && stack[sp].op != TRUNC_MOD_EXPR \
6215 && stack[0].expr.value != error_mark_node \
6216 && stack[1].expr.value != error_mark_node \
6217 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6218 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6219 stack[0].expr.value \
6220 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6221 stack[0].expr.value, stack[1].expr.value); \
6223 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6225 stack[sp - 1].expr, \
6229 gcc_assert (!after
|| c_dialect_objc ());
6230 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6231 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6232 stack
[0].prec
= PREC_NONE
;
6236 enum c_parser_prec oprec
;
6237 enum tree_code ocode
;
6240 switch (c_parser_peek_token (parser
)->type
)
6248 ocode
= TRUNC_DIV_EXPR
;
6252 ocode
= TRUNC_MOD_EXPR
;
6264 ocode
= LSHIFT_EXPR
;
6268 ocode
= RSHIFT_EXPR
;
6282 case CPP_GREATER_EQ
:
6295 oprec
= PREC_BITAND
;
6296 ocode
= BIT_AND_EXPR
;
6299 oprec
= PREC_BITXOR
;
6300 ocode
= BIT_XOR_EXPR
;
6304 ocode
= BIT_IOR_EXPR
;
6307 oprec
= PREC_LOGAND
;
6308 ocode
= TRUTH_ANDIF_EXPR
;
6312 ocode
= TRUTH_ORIF_EXPR
;
6315 /* Not a binary operator, so end of the binary
6319 binary_loc
= c_parser_peek_token (parser
)->location
;
6320 while (oprec
<= stack
[sp
].prec
)
6322 c_parser_consume_token (parser
);
6325 case TRUTH_ANDIF_EXPR
:
6327 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6328 stack
[sp
].expr
, true, true);
6329 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6330 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6331 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6332 == truthvalue_false_node
);
6334 case TRUTH_ORIF_EXPR
:
6336 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6337 stack
[sp
].expr
, true, true);
6338 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6339 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6340 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6341 == truthvalue_true_node
);
6347 stack
[sp
].loc
= binary_loc
;
6348 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6349 stack
[sp
].prec
= oprec
;
6350 stack
[sp
].op
= ocode
;
6351 stack
[sp
].loc
= binary_loc
;
6356 return stack
[0].expr
;
6360 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6361 NULL then it is an Objective-C message expression which is the
6362 primary-expression starting the expression as an initializer.
6366 ( type-name ) unary-expression
6369 static struct c_expr
6370 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6372 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6373 gcc_assert (!after
|| c_dialect_objc ());
6375 return c_parser_postfix_expression_after_primary (parser
,
6377 /* If the expression begins with a parenthesized type name, it may
6378 be either a cast or a compound literal; we need to see whether
6379 the next character is '{' to tell the difference. If not, it is
6380 an unary expression. Full detection of unknown typenames here
6381 would require a 3-token lookahead. */
6382 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6383 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6385 struct c_type_name
*type_name
;
6388 c_parser_consume_token (parser
);
6389 type_name
= c_parser_type_name (parser
);
6390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6391 if (type_name
== NULL
)
6393 ret
.value
= error_mark_node
;
6394 ret
.original_code
= ERROR_MARK
;
6395 ret
.original_type
= NULL
;
6399 /* Save casted types in the function's used types hash table. */
6400 used_types_insert (type_name
->specs
->type
);
6402 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6403 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6406 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6407 expr
= c_parser_cast_expression (parser
, NULL
);
6408 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6410 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6411 ret
.original_code
= ERROR_MARK
;
6412 ret
.original_type
= NULL
;
6416 return c_parser_unary_expression (parser
);
6419 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6425 unary-operator cast-expression
6426 sizeof unary-expression
6427 sizeof ( type-name )
6429 unary-operator: one of
6435 __alignof__ unary-expression
6436 __alignof__ ( type-name )
6439 (C11 permits _Alignof with type names only.)
6441 unary-operator: one of
6442 __extension__ __real__ __imag__
6444 Transactional Memory:
6447 transaction-expression
6449 In addition, the GNU syntax treats ++ and -- as unary operators, so
6450 they may be applied to cast expressions with errors for non-lvalues
6453 static struct c_expr
6454 c_parser_unary_expression (c_parser
*parser
)
6457 struct c_expr ret
, op
;
6458 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6460 ret
.original_code
= ERROR_MARK
;
6461 ret
.original_type
= NULL
;
6462 switch (c_parser_peek_token (parser
)->type
)
6465 c_parser_consume_token (parser
);
6466 exp_loc
= c_parser_peek_token (parser
)->location
;
6467 op
= c_parser_cast_expression (parser
, NULL
);
6469 /* If there is array notations in op, we expand them. */
6470 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6471 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6474 op
= default_function_array_read_conversion (exp_loc
, op
);
6475 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6477 case CPP_MINUS_MINUS
:
6478 c_parser_consume_token (parser
);
6479 exp_loc
= c_parser_peek_token (parser
)->location
;
6480 op
= c_parser_cast_expression (parser
, NULL
);
6482 /* If there is array notations in op, we expand them. */
6483 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6484 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6487 op
= default_function_array_read_conversion (exp_loc
, op
);
6488 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6491 c_parser_consume_token (parser
);
6492 op
= c_parser_cast_expression (parser
, NULL
);
6493 mark_exp_read (op
.value
);
6494 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6496 c_parser_consume_token (parser
);
6497 exp_loc
= c_parser_peek_token (parser
)->location
;
6498 op
= c_parser_cast_expression (parser
, NULL
);
6499 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6500 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6503 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6506 "traditional C rejects the unary plus operator");
6507 c_parser_consume_token (parser
);
6508 exp_loc
= c_parser_peek_token (parser
)->location
;
6509 op
= c_parser_cast_expression (parser
, NULL
);
6510 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6511 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6513 c_parser_consume_token (parser
);
6514 exp_loc
= c_parser_peek_token (parser
)->location
;
6515 op
= c_parser_cast_expression (parser
, NULL
);
6516 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6517 return parser_build_unary_op (op_loc
, NEGATE_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 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6525 c_parser_consume_token (parser
);
6526 exp_loc
= c_parser_peek_token (parser
)->location
;
6527 op
= c_parser_cast_expression (parser
, NULL
);
6528 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6529 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6531 /* Refer to the address of a label as a pointer. */
6532 c_parser_consume_token (parser
);
6533 if (c_parser_next_token_is (parser
, CPP_NAME
))
6535 ret
.value
= finish_label_address_expr
6536 (c_parser_peek_token (parser
)->value
, op_loc
);
6537 c_parser_consume_token (parser
);
6541 c_parser_error (parser
, "expected identifier");
6542 ret
.value
= error_mark_node
;
6546 switch (c_parser_peek_token (parser
)->keyword
)
6549 return c_parser_sizeof_expression (parser
);
6551 return c_parser_alignof_expression (parser
);
6553 c_parser_consume_token (parser
);
6554 ext
= disable_extension_diagnostics ();
6555 ret
= c_parser_cast_expression (parser
, NULL
);
6556 restore_extension_diagnostics (ext
);
6559 c_parser_consume_token (parser
);
6560 exp_loc
= c_parser_peek_token (parser
)->location
;
6561 op
= c_parser_cast_expression (parser
, NULL
);
6562 op
= default_function_array_conversion (exp_loc
, op
);
6563 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6565 c_parser_consume_token (parser
);
6566 exp_loc
= c_parser_peek_token (parser
)->location
;
6567 op
= c_parser_cast_expression (parser
, NULL
);
6568 op
= default_function_array_conversion (exp_loc
, op
);
6569 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6570 case RID_TRANSACTION_ATOMIC
:
6571 case RID_TRANSACTION_RELAXED
:
6572 return c_parser_transaction_expression (parser
,
6573 c_parser_peek_token (parser
)->keyword
);
6575 return c_parser_postfix_expression (parser
);
6578 return c_parser_postfix_expression (parser
);
6582 /* Parse a sizeof expression. */
6584 static struct c_expr
6585 c_parser_sizeof_expression (c_parser
*parser
)
6588 location_t expr_loc
;
6589 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6590 c_parser_consume_token (parser
);
6591 c_inhibit_evaluation_warnings
++;
6593 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6594 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6596 /* Either sizeof ( type-name ) or sizeof unary-expression
6597 starting with a compound literal. */
6598 struct c_type_name
*type_name
;
6599 c_parser_consume_token (parser
);
6600 expr_loc
= c_parser_peek_token (parser
)->location
;
6601 type_name
= c_parser_type_name (parser
);
6602 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6603 if (type_name
== NULL
)
6606 c_inhibit_evaluation_warnings
--;
6608 ret
.value
= error_mark_node
;
6609 ret
.original_code
= ERROR_MARK
;
6610 ret
.original_type
= NULL
;
6613 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6615 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6620 /* sizeof ( type-name ). */
6621 c_inhibit_evaluation_warnings
--;
6623 return c_expr_sizeof_type (expr_loc
, type_name
);
6627 expr_loc
= c_parser_peek_token (parser
)->location
;
6628 expr
= c_parser_unary_expression (parser
);
6630 c_inhibit_evaluation_warnings
--;
6632 mark_exp_read (expr
.value
);
6633 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6634 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6635 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6636 return c_expr_sizeof_expr (expr_loc
, expr
);
6640 /* Parse an alignof expression. */
6642 static struct c_expr
6643 c_parser_alignof_expression (c_parser
*parser
)
6646 location_t loc
= c_parser_peek_token (parser
)->location
;
6647 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6648 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6649 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6651 /* A diagnostic is not required for the use of this identifier in
6652 the implementation namespace; only diagnose it for the C11
6653 spelling because of existing code using the other spellings. */
6657 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6660 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6663 c_parser_consume_token (parser
);
6664 c_inhibit_evaluation_warnings
++;
6666 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6667 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6669 /* Either __alignof__ ( type-name ) or __alignof__
6670 unary-expression starting with a compound literal. */
6672 struct c_type_name
*type_name
;
6674 c_parser_consume_token (parser
);
6675 loc
= c_parser_peek_token (parser
)->location
;
6676 type_name
= c_parser_type_name (parser
);
6677 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6678 if (type_name
== NULL
)
6681 c_inhibit_evaluation_warnings
--;
6683 ret
.value
= error_mark_node
;
6684 ret
.original_code
= ERROR_MARK
;
6685 ret
.original_type
= NULL
;
6688 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6690 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6695 /* alignof ( type-name ). */
6696 c_inhibit_evaluation_warnings
--;
6698 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6700 false, is_c11_alignof
, 1);
6701 ret
.original_code
= ERROR_MARK
;
6702 ret
.original_type
= NULL
;
6708 expr
= c_parser_unary_expression (parser
);
6710 mark_exp_read (expr
.value
);
6711 c_inhibit_evaluation_warnings
--;
6713 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6715 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6716 ret
.original_code
= ERROR_MARK
;
6717 ret
.original_type
= NULL
;
6722 /* Helper function to read arguments of builtins which are interfaces
6723 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6724 others. The name of the builtin is passed using BNAME parameter.
6725 Function returns true if there were no errors while parsing and
6726 stores the arguments in CEXPR_LIST. */
6728 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6729 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6732 location_t loc
= c_parser_peek_token (parser
)->location
;
6733 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6735 bool saved_force_folding_builtin_constant_p
;
6737 *ret_cexpr_list
= NULL
;
6738 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6740 error_at (loc
, "cannot take address of %qs", bname
);
6744 c_parser_consume_token (parser
);
6746 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6748 c_parser_consume_token (parser
);
6752 saved_force_folding_builtin_constant_p
6753 = force_folding_builtin_constant_p
;
6754 force_folding_builtin_constant_p
|= choose_expr_p
;
6755 expr
= c_parser_expr_no_commas (parser
, NULL
);
6756 force_folding_builtin_constant_p
6757 = saved_force_folding_builtin_constant_p
;
6758 vec_alloc (cexpr_list
, 1);
6759 vec_safe_push (cexpr_list
, expr
);
6760 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6762 c_parser_consume_token (parser
);
6763 expr
= c_parser_expr_no_commas (parser
, NULL
);
6764 vec_safe_push (cexpr_list
, expr
);
6767 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6770 *ret_cexpr_list
= cexpr_list
;
6774 /* This represents a single generic-association. */
6776 struct c_generic_association
6778 /* The location of the starting token of the type. */
6779 location_t type_location
;
6780 /* The association's type, or NULL_TREE for 'default'. */
6782 /* The association's expression. */
6783 struct c_expr expression
;
6786 /* Parse a generic-selection. (C11 6.5.1.1).
6789 _Generic ( assignment-expression , generic-assoc-list )
6793 generic-assoc-list , generic-association
6795 generic-association:
6796 type-name : assignment-expression
6797 default : assignment-expression
6800 static struct c_expr
6801 c_parser_generic_selection (c_parser
*parser
)
6803 vec
<c_generic_association
> associations
= vNULL
;
6804 struct c_expr selector
, error_expr
;
6806 struct c_generic_association matched_assoc
;
6807 bool match_found
= false;
6808 location_t generic_loc
, selector_loc
;
6810 error_expr
.original_code
= ERROR_MARK
;
6811 error_expr
.original_type
= NULL
;
6812 error_expr
.value
= error_mark_node
;
6813 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6814 matched_assoc
.type
= NULL_TREE
;
6815 matched_assoc
.expression
= error_expr
;
6817 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6818 generic_loc
= c_parser_peek_token (parser
)->location
;
6819 c_parser_consume_token (parser
);
6821 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6822 "ISO C99 does not support %<_Generic%>");
6824 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6825 "ISO C90 does not support %<_Generic%>");
6827 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6830 c_inhibit_evaluation_warnings
++;
6831 selector_loc
= c_parser_peek_token (parser
)->location
;
6832 selector
= c_parser_expr_no_commas (parser
, NULL
);
6833 selector
= default_function_array_conversion (selector_loc
, selector
);
6834 c_inhibit_evaluation_warnings
--;
6836 if (selector
.value
== error_mark_node
)
6838 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6841 selector_type
= TREE_TYPE (selector
.value
);
6842 /* In ISO C terms, rvalues (including the controlling expression of
6843 _Generic) do not have qualified types. */
6844 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6845 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6846 /* In ISO C terms, _Noreturn is not part of the type of expressions
6847 such as &abort, but in GCC it is represented internally as a type
6849 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6850 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6852 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6854 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6856 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6862 struct c_generic_association assoc
, *iter
;
6864 c_token
*token
= c_parser_peek_token (parser
);
6866 assoc
.type_location
= token
->location
;
6867 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6869 c_parser_consume_token (parser
);
6870 assoc
.type
= NULL_TREE
;
6874 struct c_type_name
*type_name
;
6876 type_name
= c_parser_type_name (parser
);
6877 if (type_name
== NULL
)
6879 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6882 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6883 if (assoc
.type
== error_mark_node
)
6885 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6889 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6890 error_at (assoc
.type_location
,
6891 "%<_Generic%> association has function type");
6892 else if (!COMPLETE_TYPE_P (assoc
.type
))
6893 error_at (assoc
.type_location
,
6894 "%<_Generic%> association has incomplete type");
6896 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6897 error_at (assoc
.type_location
,
6898 "%<_Generic%> association has "
6899 "variable length type");
6902 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6904 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6908 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6909 if (assoc
.expression
.value
== error_mark_node
)
6911 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6915 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6917 if (assoc
.type
== NULL_TREE
)
6919 if (iter
->type
== NULL_TREE
)
6921 error_at (assoc
.type_location
,
6922 "duplicate %<default%> case in %<_Generic%>");
6923 inform (iter
->type_location
, "original %<default%> is here");
6926 else if (iter
->type
!= NULL_TREE
)
6928 if (comptypes (assoc
.type
, iter
->type
))
6930 error_at (assoc
.type_location
,
6931 "%<_Generic%> specifies two compatible types");
6932 inform (iter
->type_location
, "compatible type is here");
6937 if (assoc
.type
== NULL_TREE
)
6941 matched_assoc
= assoc
;
6945 else if (comptypes (assoc
.type
, selector_type
))
6947 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6949 matched_assoc
= assoc
;
6954 error_at (assoc
.type_location
,
6955 "%<_Generic> selector matches multiple associations");
6956 inform (matched_assoc
.type_location
,
6957 "other match is here");
6961 associations
.safe_push (assoc
);
6963 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6965 c_parser_consume_token (parser
);
6968 associations
.release ();
6970 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6972 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6978 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6979 "compatible with any association",
6984 return matched_assoc
.expression
;
6987 associations
.release ();
6991 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6995 postfix-expression [ expression ]
6996 postfix-expression ( argument-expression-list[opt] )
6997 postfix-expression . identifier
6998 postfix-expression -> identifier
6999 postfix-expression ++
7000 postfix-expression --
7001 ( type-name ) { initializer-list }
7002 ( type-name ) { initializer-list , }
7004 argument-expression-list:
7006 argument-expression-list , argument-expression
7019 (treated as a keyword in GNU C)
7022 ( compound-statement )
7023 __builtin_va_arg ( assignment-expression , type-name )
7024 __builtin_offsetof ( type-name , offsetof-member-designator )
7025 __builtin_choose_expr ( assignment-expression ,
7026 assignment-expression ,
7027 assignment-expression )
7028 __builtin_types_compatible_p ( type-name , type-name )
7029 __builtin_complex ( assignment-expression , assignment-expression )
7030 __builtin_shuffle ( assignment-expression , assignment-expression )
7031 __builtin_shuffle ( assignment-expression ,
7032 assignment-expression ,
7033 assignment-expression, )
7035 offsetof-member-designator:
7037 offsetof-member-designator . identifier
7038 offsetof-member-designator [ expression ]
7043 [ objc-receiver objc-message-args ]
7044 @selector ( objc-selector-arg )
7045 @protocol ( identifier )
7046 @encode ( type-name )
7048 Classname . identifier
7051 static struct c_expr
7052 c_parser_postfix_expression (c_parser
*parser
)
7054 struct c_expr expr
, e1
;
7055 struct c_type_name
*t1
, *t2
;
7056 location_t loc
= c_parser_peek_token (parser
)->location
;;
7057 expr
.original_code
= ERROR_MARK
;
7058 expr
.original_type
= NULL
;
7059 switch (c_parser_peek_token (parser
)->type
)
7062 expr
.value
= c_parser_peek_token (parser
)->value
;
7063 loc
= c_parser_peek_token (parser
)->location
;
7064 c_parser_consume_token (parser
);
7065 if (TREE_CODE (expr
.value
) == FIXED_CST
7066 && !targetm
.fixed_point_supported_p ())
7068 error_at (loc
, "fixed-point types not supported for this target");
7069 expr
.value
= error_mark_node
;
7076 expr
.value
= c_parser_peek_token (parser
)->value
;
7077 c_parser_consume_token (parser
);
7083 case CPP_UTF8STRING
:
7084 expr
.value
= c_parser_peek_token (parser
)->value
;
7085 expr
.original_code
= STRING_CST
;
7086 c_parser_consume_token (parser
);
7088 case CPP_OBJC_STRING
:
7089 gcc_assert (c_dialect_objc ());
7091 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7092 c_parser_consume_token (parser
);
7095 switch (c_parser_peek_token (parser
)->id_kind
)
7099 tree id
= c_parser_peek_token (parser
)->value
;
7100 c_parser_consume_token (parser
);
7101 expr
.value
= build_external_ref (loc
, id
,
7102 (c_parser_peek_token (parser
)->type
7104 &expr
.original_type
);
7107 case C_ID_CLASSNAME
:
7109 /* Here we parse the Objective-C 2.0 Class.name dot
7111 tree class_name
= c_parser_peek_token (parser
)->value
;
7113 c_parser_consume_token (parser
);
7114 gcc_assert (c_dialect_objc ());
7115 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7117 expr
.value
= error_mark_node
;
7120 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7122 c_parser_error (parser
, "expected identifier");
7123 expr
.value
= error_mark_node
;
7126 component
= c_parser_peek_token (parser
)->value
;
7127 c_parser_consume_token (parser
);
7128 expr
.value
= objc_build_class_component_ref (class_name
,
7133 c_parser_error (parser
, "expected expression");
7134 expr
.value
= error_mark_node
;
7138 case CPP_OPEN_PAREN
:
7139 /* A parenthesized expression, statement expression or compound
7141 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7143 /* A statement expression. */
7145 location_t brace_loc
;
7146 c_parser_consume_token (parser
);
7147 brace_loc
= c_parser_peek_token (parser
)->location
;
7148 c_parser_consume_token (parser
);
7149 if (!building_stmt_list_p ())
7151 error_at (loc
, "braced-group within expression allowed "
7152 "only inside a function");
7153 parser
->error
= true;
7154 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7155 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7156 expr
.value
= error_mark_node
;
7159 stmt
= c_begin_stmt_expr ();
7160 c_parser_compound_statement_nostart (parser
);
7161 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7163 pedwarn (loc
, OPT_Wpedantic
,
7164 "ISO C forbids braced-groups within expressions");
7165 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7166 mark_exp_read (expr
.value
);
7168 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7170 /* A compound literal. ??? Can we actually get here rather
7171 than going directly to
7172 c_parser_postfix_expression_after_paren_type from
7175 struct c_type_name
*type_name
;
7176 c_parser_consume_token (parser
);
7177 loc
= c_parser_peek_token (parser
)->location
;
7178 type_name
= c_parser_type_name (parser
);
7179 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7181 if (type_name
== NULL
)
7183 expr
.value
= error_mark_node
;
7186 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7192 /* A parenthesized expression. */
7193 c_parser_consume_token (parser
);
7194 expr
= c_parser_expression (parser
);
7195 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7196 TREE_NO_WARNING (expr
.value
) = 1;
7197 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7198 expr
.original_code
= ERROR_MARK
;
7199 /* Don't change EXPR.ORIGINAL_TYPE. */
7200 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7205 switch (c_parser_peek_token (parser
)->keyword
)
7207 case RID_FUNCTION_NAME
:
7208 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7209 "%<__FUNCTION__%> predefined identifier");
7210 expr
.value
= fname_decl (loc
,
7211 c_parser_peek_token (parser
)->keyword
,
7212 c_parser_peek_token (parser
)->value
);
7213 c_parser_consume_token (parser
);
7215 case RID_PRETTY_FUNCTION_NAME
:
7216 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7217 "%<__PRETTY_FUNCTION__%> predefined identifier");
7218 expr
.value
= fname_decl (loc
,
7219 c_parser_peek_token (parser
)->keyword
,
7220 c_parser_peek_token (parser
)->value
);
7221 c_parser_consume_token (parser
);
7223 case RID_C99_FUNCTION_NAME
:
7224 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7225 "%<__func__%> predefined identifier");
7226 expr
.value
= fname_decl (loc
,
7227 c_parser_peek_token (parser
)->keyword
,
7228 c_parser_peek_token (parser
)->value
);
7229 c_parser_consume_token (parser
);
7232 c_parser_consume_token (parser
);
7233 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7235 expr
.value
= error_mark_node
;
7238 e1
= c_parser_expr_no_commas (parser
, NULL
);
7239 mark_exp_read (e1
.value
);
7240 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7241 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7243 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7244 expr
.value
= error_mark_node
;
7247 loc
= c_parser_peek_token (parser
)->location
;
7248 t1
= c_parser_type_name (parser
);
7249 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7253 expr
.value
= error_mark_node
;
7257 tree type_expr
= NULL_TREE
;
7258 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7259 groktypename (t1
, &type_expr
, NULL
));
7262 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7263 TREE_TYPE (expr
.value
), type_expr
,
7265 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7270 c_parser_consume_token (parser
);
7271 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7273 expr
.value
= error_mark_node
;
7276 t1
= c_parser_type_name (parser
);
7278 parser
->error
= true;
7279 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7280 gcc_assert (parser
->error
);
7283 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7284 expr
.value
= error_mark_node
;
7289 tree type
= groktypename (t1
, NULL
, NULL
);
7291 if (type
== error_mark_node
)
7292 offsetof_ref
= error_mark_node
;
7295 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7296 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7298 /* Parse the second argument to __builtin_offsetof. We
7299 must have one identifier, and beyond that we want to
7300 accept sub structure and sub array references. */
7301 if (c_parser_next_token_is (parser
, CPP_NAME
))
7303 offsetof_ref
= build_component_ref
7304 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7305 c_parser_consume_token (parser
);
7306 while (c_parser_next_token_is (parser
, CPP_DOT
)
7307 || c_parser_next_token_is (parser
,
7309 || c_parser_next_token_is (parser
,
7312 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7314 loc
= c_parser_peek_token (parser
)->location
;
7315 offsetof_ref
= build_array_ref (loc
,
7320 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7323 c_parser_consume_token (parser
);
7324 if (c_parser_next_token_is_not (parser
,
7327 c_parser_error (parser
, "expected identifier");
7330 offsetof_ref
= build_component_ref
7332 c_parser_peek_token (parser
)->value
);
7333 c_parser_consume_token (parser
);
7339 loc
= c_parser_peek_token (parser
)->location
;
7340 c_parser_consume_token (parser
);
7341 ce
= c_parser_expression (parser
);
7342 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7344 idx
= c_fully_fold (idx
, false, NULL
);
7345 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7347 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7352 c_parser_error (parser
, "expected identifier");
7353 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7355 expr
.value
= fold_offsetof (offsetof_ref
);
7358 case RID_CHOOSE_EXPR
:
7360 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7361 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7364 c_parser_consume_token (parser
);
7365 if (!c_parser_get_builtin_args (parser
,
7366 "__builtin_choose_expr",
7369 expr
.value
= error_mark_node
;
7373 if (vec_safe_length (cexpr_list
) != 3)
7375 error_at (loc
, "wrong number of arguments to "
7376 "%<__builtin_choose_expr%>");
7377 expr
.value
= error_mark_node
;
7381 e1_p
= &(*cexpr_list
)[0];
7382 e2_p
= &(*cexpr_list
)[1];
7383 e3_p
= &(*cexpr_list
)[2];
7386 mark_exp_read (e2_p
->value
);
7387 mark_exp_read (e3_p
->value
);
7388 if (TREE_CODE (c
) != INTEGER_CST
7389 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7391 "first argument to %<__builtin_choose_expr%> not"
7393 constant_expression_warning (c
);
7394 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7397 case RID_TYPES_COMPATIBLE_P
:
7398 c_parser_consume_token (parser
);
7399 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7401 expr
.value
= error_mark_node
;
7404 t1
= c_parser_type_name (parser
);
7407 expr
.value
= error_mark_node
;
7410 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7412 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7413 expr
.value
= error_mark_node
;
7416 t2
= c_parser_type_name (parser
);
7419 expr
.value
= error_mark_node
;
7422 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7426 e1
= groktypename (t1
, NULL
, NULL
);
7427 e2
= groktypename (t2
, NULL
, NULL
);
7428 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7430 expr
.value
= error_mark_node
;
7434 e1
= TYPE_MAIN_VARIANT (e1
);
7435 e2
= TYPE_MAIN_VARIANT (e2
);
7438 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7441 case RID_BUILTIN_COMPLEX
:
7443 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7444 c_expr_t
*e1_p
, *e2_p
;
7446 c_parser_consume_token (parser
);
7447 if (!c_parser_get_builtin_args (parser
,
7448 "__builtin_complex",
7449 &cexpr_list
, false))
7451 expr
.value
= error_mark_node
;
7455 if (vec_safe_length (cexpr_list
) != 2)
7457 error_at (loc
, "wrong number of arguments to "
7458 "%<__builtin_complex%>");
7459 expr
.value
= error_mark_node
;
7463 e1_p
= &(*cexpr_list
)[0];
7464 e2_p
= &(*cexpr_list
)[1];
7466 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7467 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7468 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7469 TREE_OPERAND (e1_p
->value
, 0));
7470 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7471 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7472 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7473 TREE_OPERAND (e2_p
->value
, 0));
7474 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7475 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7476 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7477 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7479 error_at (loc
, "%<__builtin_complex%> operand "
7480 "not of real binary floating-point type");
7481 expr
.value
= error_mark_node
;
7484 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7485 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7488 "%<__builtin_complex%> operands of different types");
7489 expr
.value
= error_mark_node
;
7492 pedwarn_c90 (loc
, OPT_Wpedantic
,
7493 "ISO C90 does not support complex types");
7494 expr
.value
= build2 (COMPLEX_EXPR
,
7497 (TREE_TYPE (e1_p
->value
))),
7498 e1_p
->value
, e2_p
->value
);
7501 case RID_BUILTIN_SHUFFLE
:
7503 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7507 c_parser_consume_token (parser
);
7508 if (!c_parser_get_builtin_args (parser
,
7509 "__builtin_shuffle",
7510 &cexpr_list
, false))
7512 expr
.value
= error_mark_node
;
7516 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7517 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7519 if (vec_safe_length (cexpr_list
) == 2)
7521 c_build_vec_perm_expr
7522 (loc
, (*cexpr_list
)[0].value
,
7523 NULL_TREE
, (*cexpr_list
)[1].value
);
7525 else if (vec_safe_length (cexpr_list
) == 3)
7527 c_build_vec_perm_expr
7528 (loc
, (*cexpr_list
)[0].value
,
7529 (*cexpr_list
)[1].value
,
7530 (*cexpr_list
)[2].value
);
7533 error_at (loc
, "wrong number of arguments to "
7534 "%<__builtin_shuffle%>");
7535 expr
.value
= error_mark_node
;
7539 case RID_AT_SELECTOR
:
7540 gcc_assert (c_dialect_objc ());
7541 c_parser_consume_token (parser
);
7542 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7544 expr
.value
= error_mark_node
;
7548 tree sel
= c_parser_objc_selector_arg (parser
);
7549 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7551 expr
.value
= objc_build_selector_expr (loc
, sel
);
7554 case RID_AT_PROTOCOL
:
7555 gcc_assert (c_dialect_objc ());
7556 c_parser_consume_token (parser
);
7557 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7559 expr
.value
= error_mark_node
;
7562 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7564 c_parser_error (parser
, "expected identifier");
7565 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7566 expr
.value
= error_mark_node
;
7570 tree id
= c_parser_peek_token (parser
)->value
;
7571 c_parser_consume_token (parser
);
7572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7574 expr
.value
= objc_build_protocol_expr (id
);
7578 /* Extension to support C-structures in the archiver. */
7579 gcc_assert (c_dialect_objc ());
7580 c_parser_consume_token (parser
);
7581 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7583 expr
.value
= error_mark_node
;
7586 t1
= c_parser_type_name (parser
);
7589 expr
.value
= error_mark_node
;
7590 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7593 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7596 tree type
= groktypename (t1
, NULL
, NULL
);
7597 expr
.value
= objc_build_encode_expr (type
);
7601 expr
= c_parser_generic_selection (parser
);
7603 case RID_CILK_SPAWN
:
7604 c_parser_consume_token (parser
);
7607 error_at (loc
, "-fcilkplus must be enabled to use "
7609 expr
= c_parser_postfix_expression (parser
);
7610 expr
.value
= error_mark_node
;
7612 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7614 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7615 "are not permitted");
7616 /* Now flush out all the _Cilk_spawns. */
7617 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7618 c_parser_consume_token (parser
);
7619 expr
= c_parser_postfix_expression (parser
);
7623 expr
= c_parser_postfix_expression (parser
);
7624 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7628 c_parser_error (parser
, "expected expression");
7629 expr
.value
= error_mark_node
;
7633 case CPP_OPEN_SQUARE
:
7634 if (c_dialect_objc ())
7636 tree receiver
, args
;
7637 c_parser_consume_token (parser
);
7638 receiver
= c_parser_objc_receiver (parser
);
7639 args
= c_parser_objc_message_args (parser
);
7640 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7642 expr
.value
= objc_build_message_expr (receiver
, args
);
7645 /* Else fall through to report error. */
7647 c_parser_error (parser
, "expected expression");
7648 expr
.value
= error_mark_node
;
7651 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7654 /* Parse a postfix expression after a parenthesized type name: the
7655 brace-enclosed initializer of a compound literal, possibly followed
7656 by some postfix operators. This is separate because it is not
7657 possible to tell until after the type name whether a cast
7658 expression has a cast or a compound literal, or whether the operand
7659 of sizeof is a parenthesized type name or starts with a compound
7660 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7661 location of the first token after the parentheses around the type
7664 static struct c_expr
7665 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7666 struct c_type_name
*type_name
,
7667 location_t type_loc
)
7673 location_t start_loc
;
7674 tree type_expr
= NULL_TREE
;
7675 bool type_expr_const
= true;
7676 check_compound_literal_type (type_loc
, type_name
);
7677 start_init (NULL_TREE
, NULL
, 0);
7678 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7679 start_loc
= c_parser_peek_token (parser
)->location
;
7680 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7682 error_at (type_loc
, "compound literal has variable size");
7683 type
= error_mark_node
;
7685 init
= c_parser_braced_init (parser
, type
, false);
7687 maybe_warn_string_init (type_loc
, type
, init
);
7689 if (type
!= error_mark_node
7690 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7691 && current_function_decl
)
7693 error ("compound literal qualified by address-space qualifier");
7694 type
= error_mark_node
;
7697 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7698 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7699 ? CONSTRUCTOR_NON_CONST (init
.value
)
7700 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7701 non_const
|= !type_expr_const
;
7702 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7703 expr
.original_code
= ERROR_MARK
;
7704 expr
.original_type
= NULL
;
7707 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7709 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7710 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7714 gcc_assert (!non_const
);
7715 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7716 type_expr
, expr
.value
);
7719 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7722 /* Callback function for sizeof_pointer_memaccess_warning to compare
7726 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7728 return comptypes (type1
, type2
) == 1;
7731 /* Parse a postfix expression after the initial primary or compound
7732 literal; that is, parse a series of postfix operators.
7734 EXPR_LOC is the location of the primary expression. */
7736 static struct c_expr
7737 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7738 location_t expr_loc
,
7741 struct c_expr orig_expr
;
7743 location_t sizeof_arg_loc
[3];
7745 unsigned int literal_zero_mask
;
7747 vec
<tree
, va_gc
> *exprlist
;
7748 vec
<tree
, va_gc
> *origtypes
= NULL
;
7749 vec
<location_t
> arg_loc
= vNULL
;
7753 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7754 switch (c_parser_peek_token (parser
)->type
)
7756 case CPP_OPEN_SQUARE
:
7757 /* Array reference. */
7758 c_parser_consume_token (parser
);
7760 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7761 /* If we are here, then we have something like this:
7764 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7768 idx
= c_parser_expression (parser
).value
;
7769 /* Here we have 3 options:
7770 1. Array [EXPR] -- Normal Array call.
7771 2. Array [EXPR : EXPR] -- Array notation without stride.
7772 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7774 For 1, we just handle it just like a normal array expression.
7775 For 2 and 3 we handle it like we handle array notations. The
7776 idx value we have above becomes the initial/start index.
7779 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7780 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7784 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7786 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7789 expr
.original_code
= ERROR_MARK
;
7790 expr
.original_type
= NULL
;
7792 case CPP_OPEN_PAREN
:
7793 /* Function call. */
7794 c_parser_consume_token (parser
);
7795 for (i
= 0; i
< 3; i
++)
7797 sizeof_arg
[i
] = NULL_TREE
;
7798 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7800 literal_zero_mask
= 0;
7801 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7804 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7805 sizeof_arg_loc
, sizeof_arg
,
7806 &arg_loc
, &literal_zero_mask
);
7807 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7810 mark_exp_read (expr
.value
);
7811 if (warn_sizeof_pointer_memaccess
)
7812 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7813 expr
.value
, exprlist
,
7815 sizeof_ptr_memacc_comptypes
);
7816 if (warn_memset_transposed_args
7817 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7818 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7819 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7820 && vec_safe_length (exprlist
) == 3
7821 && integer_zerop ((*exprlist
)[2])
7822 && (literal_zero_mask
& (1 << 2)) != 0
7823 && (!integer_zerop ((*exprlist
)[1])
7824 || (literal_zero_mask
& (1 << 1)) == 0))
7825 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7826 "%<memset%> used with constant zero length parameter; "
7827 "this could be due to transposed parameters");
7830 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7831 exprlist
, origtypes
);
7832 expr
.original_code
= ERROR_MARK
;
7833 if (TREE_CODE (expr
.value
) == INTEGER_CST
7834 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7835 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7836 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7837 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7838 expr
.original_type
= NULL
;
7841 release_tree_vector (exprlist
);
7842 release_tree_vector (origtypes
);
7847 /* Structure element reference. */
7848 c_parser_consume_token (parser
);
7849 expr
= default_function_array_conversion (expr_loc
, expr
);
7850 if (c_parser_next_token_is (parser
, CPP_NAME
))
7851 ident
= c_parser_peek_token (parser
)->value
;
7854 c_parser_error (parser
, "expected identifier");
7855 expr
.value
= error_mark_node
;
7856 expr
.original_code
= ERROR_MARK
;
7857 expr
.original_type
= NULL
;
7860 c_parser_consume_token (parser
);
7861 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7862 expr
.original_code
= ERROR_MARK
;
7863 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7864 expr
.original_type
= NULL
;
7867 /* Remember the original type of a bitfield. */
7868 tree field
= TREE_OPERAND (expr
.value
, 1);
7869 if (TREE_CODE (field
) != FIELD_DECL
)
7870 expr
.original_type
= NULL
;
7872 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7876 /* Structure element reference. */
7877 c_parser_consume_token (parser
);
7878 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7879 if (c_parser_next_token_is (parser
, CPP_NAME
))
7880 ident
= c_parser_peek_token (parser
)->value
;
7883 c_parser_error (parser
, "expected identifier");
7884 expr
.value
= error_mark_node
;
7885 expr
.original_code
= ERROR_MARK
;
7886 expr
.original_type
= NULL
;
7889 c_parser_consume_token (parser
);
7890 expr
.value
= build_component_ref (op_loc
,
7891 build_indirect_ref (op_loc
,
7895 expr
.original_code
= ERROR_MARK
;
7896 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7897 expr
.original_type
= NULL
;
7900 /* Remember the original type of a bitfield. */
7901 tree field
= TREE_OPERAND (expr
.value
, 1);
7902 if (TREE_CODE (field
) != FIELD_DECL
)
7903 expr
.original_type
= NULL
;
7905 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7909 /* Postincrement. */
7910 c_parser_consume_token (parser
);
7911 /* If the expressions have array notations, we expand them. */
7913 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7914 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7917 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7918 expr
.value
= build_unary_op (op_loc
,
7919 POSTINCREMENT_EXPR
, expr
.value
, 0);
7921 expr
.original_code
= ERROR_MARK
;
7922 expr
.original_type
= NULL
;
7924 case CPP_MINUS_MINUS
:
7925 /* Postdecrement. */
7926 c_parser_consume_token (parser
);
7927 /* If the expressions have array notations, we expand them. */
7929 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7930 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7933 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7934 expr
.value
= build_unary_op (op_loc
,
7935 POSTDECREMENT_EXPR
, expr
.value
, 0);
7937 expr
.original_code
= ERROR_MARK
;
7938 expr
.original_type
= NULL
;
7946 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7949 assignment-expression
7950 expression , assignment-expression
7953 static struct c_expr
7954 c_parser_expression (c_parser
*parser
)
7956 location_t tloc
= c_parser_peek_token (parser
)->location
;
7958 expr
= c_parser_expr_no_commas (parser
, NULL
);
7959 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7960 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7961 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7965 location_t loc
= c_parser_peek_token (parser
)->location
;
7966 location_t expr_loc
;
7967 c_parser_consume_token (parser
);
7968 expr_loc
= c_parser_peek_token (parser
)->location
;
7969 lhsval
= expr
.value
;
7970 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7971 lhsval
= TREE_OPERAND (lhsval
, 1);
7972 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7973 mark_exp_read (lhsval
);
7974 next
= c_parser_expr_no_commas (parser
, NULL
);
7975 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7976 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7977 expr
.original_code
= COMPOUND_EXPR
;
7978 expr
.original_type
= next
.original_type
;
7983 /* Parse an expression and convert functions or arrays to pointers and
7984 lvalues to rvalues. */
7986 static struct c_expr
7987 c_parser_expression_conv (c_parser
*parser
)
7990 location_t loc
= c_parser_peek_token (parser
)->location
;
7991 expr
= c_parser_expression (parser
);
7992 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7996 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
7997 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8000 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8003 if (idx
>= HOST_BITS_PER_INT
)
8006 c_token
*tok
= c_parser_peek_token (parser
);
8014 /* If a parameter is literal zero alone, remember it
8015 for -Wmemset-transposed-args warning. */
8016 if (integer_zerop (tok
->value
)
8017 && !TREE_OVERFLOW (tok
->value
)
8018 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8019 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8020 *literal_zero_mask
|= 1U << idx
;
8026 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8027 functions and arrays to pointers and lvalues to rvalues. If
8028 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8029 locations of function arguments into this vector.
8032 assignment-expression
8033 nonempty-expr-list , assignment-expression
8036 static vec
<tree
, va_gc
> *
8037 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8038 vec
<tree
, va_gc
> **p_orig_types
,
8039 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8040 vec
<location_t
> *locations
,
8041 unsigned int *literal_zero_mask
)
8043 vec
<tree
, va_gc
> *ret
;
8044 vec
<tree
, va_gc
> *orig_types
;
8046 location_t loc
= c_parser_peek_token (parser
)->location
;
8047 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8048 unsigned int idx
= 0;
8050 ret
= make_tree_vector ();
8051 if (p_orig_types
== NULL
)
8054 orig_types
= make_tree_vector ();
8056 if (sizeof_arg
!= NULL
8057 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8058 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8059 if (literal_zero_mask
)
8060 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8061 expr
= c_parser_expr_no_commas (parser
, NULL
);
8063 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8065 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8066 ret
->quick_push (expr
.value
);
8068 orig_types
->quick_push (expr
.original_type
);
8070 locations
->safe_push (loc
);
8071 if (sizeof_arg
!= NULL
8072 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8073 && expr
.original_code
== SIZEOF_EXPR
)
8075 sizeof_arg
[0] = c_last_sizeof_arg
;
8076 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8078 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8080 c_parser_consume_token (parser
);
8081 loc
= c_parser_peek_token (parser
)->location
;
8082 if (sizeof_arg
!= NULL
8083 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8084 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8086 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8087 if (literal_zero_mask
)
8088 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8089 expr
= c_parser_expr_no_commas (parser
, NULL
);
8091 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8093 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8094 vec_safe_push (ret
, expr
.value
);
8096 vec_safe_push (orig_types
, expr
.original_type
);
8098 locations
->safe_push (loc
);
8100 && sizeof_arg
!= NULL
8101 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8102 && expr
.original_code
== SIZEOF_EXPR
)
8104 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8105 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8109 *p_orig_types
= orig_types
;
8113 /* Parse Objective-C-specific constructs. */
8115 /* Parse an objc-class-definition.
8117 objc-class-definition:
8118 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8119 objc-class-instance-variables[opt] objc-methodprotolist @end
8120 @implementation identifier objc-superclass[opt]
8121 objc-class-instance-variables[opt]
8122 @interface identifier ( identifier ) objc-protocol-refs[opt]
8123 objc-methodprotolist @end
8124 @interface identifier ( ) objc-protocol-refs[opt]
8125 objc-methodprotolist @end
8126 @implementation identifier ( identifier )
8131 "@interface identifier (" must start "@interface identifier (
8132 identifier ) ...": objc-methodprotolist in the first production may
8133 not start with a parenthesized identifier as a declarator of a data
8134 definition with no declaration specifiers if the objc-superclass,
8135 objc-protocol-refs and objc-class-instance-variables are omitted. */
8138 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8143 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8145 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8150 c_parser_consume_token (parser
);
8151 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8153 c_parser_error (parser
, "expected identifier");
8156 id1
= c_parser_peek_token (parser
)->value
;
8157 c_parser_consume_token (parser
);
8158 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8160 /* We have a category or class extension. */
8162 tree proto
= NULL_TREE
;
8163 c_parser_consume_token (parser
);
8164 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8166 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8168 /* We have a class extension. */
8173 c_parser_error (parser
, "expected identifier or %<)%>");
8174 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8180 id2
= c_parser_peek_token (parser
)->value
;
8181 c_parser_consume_token (parser
);
8183 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8186 objc_start_category_implementation (id1
, id2
);
8189 if (c_parser_next_token_is (parser
, CPP_LESS
))
8190 proto
= c_parser_objc_protocol_refs (parser
);
8191 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8192 c_parser_objc_methodprotolist (parser
);
8193 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8194 objc_finish_interface ();
8197 if (c_parser_next_token_is (parser
, CPP_COLON
))
8199 c_parser_consume_token (parser
);
8200 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8202 c_parser_error (parser
, "expected identifier");
8205 superclass
= c_parser_peek_token (parser
)->value
;
8206 c_parser_consume_token (parser
);
8209 superclass
= NULL_TREE
;
8212 tree proto
= NULL_TREE
;
8213 if (c_parser_next_token_is (parser
, CPP_LESS
))
8214 proto
= c_parser_objc_protocol_refs (parser
);
8215 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8218 objc_start_class_implementation (id1
, superclass
);
8219 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8220 c_parser_objc_class_instance_variables (parser
);
8223 objc_continue_interface ();
8224 c_parser_objc_methodprotolist (parser
);
8225 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8226 objc_finish_interface ();
8230 objc_continue_implementation ();
8235 /* Parse objc-class-instance-variables.
8237 objc-class-instance-variables:
8238 { objc-instance-variable-decl-list[opt] }
8240 objc-instance-variable-decl-list:
8241 objc-visibility-spec
8242 objc-instance-variable-decl ;
8244 objc-instance-variable-decl-list objc-visibility-spec
8245 objc-instance-variable-decl-list objc-instance-variable-decl ;
8246 objc-instance-variable-decl-list ;
8248 objc-visibility-spec:
8253 objc-instance-variable-decl:
8258 c_parser_objc_class_instance_variables (c_parser
*parser
)
8260 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8261 c_parser_consume_token (parser
);
8262 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8265 /* Parse any stray semicolon. */
8266 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8268 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8270 c_parser_consume_token (parser
);
8273 /* Stop if at the end of the instance variables. */
8274 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8276 c_parser_consume_token (parser
);
8279 /* Parse any objc-visibility-spec. */
8280 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8282 c_parser_consume_token (parser
);
8283 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8286 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8288 c_parser_consume_token (parser
);
8289 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8292 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8294 c_parser_consume_token (parser
);
8295 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8298 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8300 c_parser_consume_token (parser
);
8301 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8304 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8306 c_parser_pragma (parser
, pragma_external
);
8310 /* Parse some comma-separated declarations. */
8311 decls
= c_parser_struct_declaration (parser
);
8314 /* There is a syntax error. We want to skip the offending
8315 tokens up to the next ';' (included) or '}'
8318 /* First, skip manually a ')' or ']'. This is because they
8319 reduce the nesting level, so c_parser_skip_until_found()
8320 wouldn't be able to skip past them. */
8321 c_token
*token
= c_parser_peek_token (parser
);
8322 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8323 c_parser_consume_token (parser
);
8325 /* Then, do the standard skipping. */
8326 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8328 /* We hopefully recovered. Start normal parsing again. */
8329 parser
->error
= false;
8334 /* Comma-separated instance variables are chained together
8335 in reverse order; add them one by one. */
8336 tree ivar
= nreverse (decls
);
8337 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8338 objc_add_instance_variable (copy_node (ivar
));
8340 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8344 /* Parse an objc-class-declaration.
8346 objc-class-declaration:
8347 @class identifier-list ;
8351 c_parser_objc_class_declaration (c_parser
*parser
)
8353 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8354 c_parser_consume_token (parser
);
8355 /* Any identifiers, including those declared as type names, are OK
8360 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8362 c_parser_error (parser
, "expected identifier");
8363 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8364 parser
->error
= false;
8367 id
= c_parser_peek_token (parser
)->value
;
8368 objc_declare_class (id
);
8369 c_parser_consume_token (parser
);
8370 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8371 c_parser_consume_token (parser
);
8375 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8378 /* Parse an objc-alias-declaration.
8380 objc-alias-declaration:
8381 @compatibility_alias identifier identifier ;
8385 c_parser_objc_alias_declaration (c_parser
*parser
)
8388 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8389 c_parser_consume_token (parser
);
8390 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8392 c_parser_error (parser
, "expected identifier");
8393 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8396 id1
= c_parser_peek_token (parser
)->value
;
8397 c_parser_consume_token (parser
);
8398 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8400 c_parser_error (parser
, "expected identifier");
8401 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8404 id2
= c_parser_peek_token (parser
)->value
;
8405 c_parser_consume_token (parser
);
8406 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8407 objc_declare_alias (id1
, id2
);
8410 /* Parse an objc-protocol-definition.
8412 objc-protocol-definition:
8413 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8414 @protocol identifier-list ;
8416 "@protocol identifier ;" should be resolved as "@protocol
8417 identifier-list ;": objc-methodprotolist may not start with a
8418 semicolon in the first alternative if objc-protocol-refs are
8422 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8424 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8426 c_parser_consume_token (parser
);
8427 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8429 c_parser_error (parser
, "expected identifier");
8432 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8433 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8435 /* Any identifiers, including those declared as type names, are
8440 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8442 c_parser_error (parser
, "expected identifier");
8445 id
= c_parser_peek_token (parser
)->value
;
8446 objc_declare_protocol (id
, attributes
);
8447 c_parser_consume_token (parser
);
8448 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8449 c_parser_consume_token (parser
);
8453 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8457 tree id
= c_parser_peek_token (parser
)->value
;
8458 tree proto
= NULL_TREE
;
8459 c_parser_consume_token (parser
);
8460 if (c_parser_next_token_is (parser
, CPP_LESS
))
8461 proto
= c_parser_objc_protocol_refs (parser
);
8462 parser
->objc_pq_context
= true;
8463 objc_start_protocol (id
, proto
, attributes
);
8464 c_parser_objc_methodprotolist (parser
);
8465 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8466 parser
->objc_pq_context
= false;
8467 objc_finish_interface ();
8471 /* Parse an objc-method-type.
8477 Return true if it is a class method (+) and false if it is
8478 an instance method (-).
8481 c_parser_objc_method_type (c_parser
*parser
)
8483 switch (c_parser_peek_token (parser
)->type
)
8486 c_parser_consume_token (parser
);
8489 c_parser_consume_token (parser
);
8496 /* Parse an objc-method-definition.
8498 objc-method-definition:
8499 objc-method-type objc-method-decl ;[opt] compound-statement
8503 c_parser_objc_method_definition (c_parser
*parser
)
8505 bool is_class_method
= c_parser_objc_method_type (parser
);
8506 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8507 parser
->objc_pq_context
= true;
8508 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8510 if (decl
== error_mark_node
)
8511 return; /* Bail here. */
8513 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8515 c_parser_consume_token (parser
);
8516 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8517 "extra semicolon in method definition specified");
8520 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8522 c_parser_error (parser
, "expected %<{%>");
8526 parser
->objc_pq_context
= false;
8527 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8529 add_stmt (c_parser_compound_statement (parser
));
8530 objc_finish_method_definition (current_function_decl
);
8534 /* This code is executed when we find a method definition
8535 outside of an @implementation context (or invalid for other
8536 reasons). Parse the method (to keep going) but do not emit
8539 c_parser_compound_statement (parser
);
8543 /* Parse an objc-methodprotolist.
8545 objc-methodprotolist:
8547 objc-methodprotolist objc-methodproto
8548 objc-methodprotolist declaration
8549 objc-methodprotolist ;
8553 The declaration is a data definition, which may be missing
8554 declaration specifiers under the same rules and diagnostics as
8555 other data definitions outside functions, and the stray semicolon
8556 is diagnosed the same way as a stray semicolon outside a
8560 c_parser_objc_methodprotolist (c_parser
*parser
)
8564 /* The list is terminated by @end. */
8565 switch (c_parser_peek_token (parser
)->type
)
8568 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8569 "ISO C does not allow extra %<;%> outside of a function");
8570 c_parser_consume_token (parser
);
8574 c_parser_objc_methodproto (parser
);
8577 c_parser_pragma (parser
, pragma_external
);
8582 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8584 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8585 c_parser_objc_at_property_declaration (parser
);
8586 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8588 objc_set_method_opt (true);
8589 c_parser_consume_token (parser
);
8591 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8593 objc_set_method_opt (false);
8594 c_parser_consume_token (parser
);
8597 c_parser_declaration_or_fndef (parser
, false, false, true,
8598 false, true, NULL
, vNULL
);
8604 /* Parse an objc-methodproto.
8607 objc-method-type objc-method-decl ;
8611 c_parser_objc_methodproto (c_parser
*parser
)
8613 bool is_class_method
= c_parser_objc_method_type (parser
);
8614 tree decl
, attributes
= NULL_TREE
;
8616 /* Remember protocol qualifiers in prototypes. */
8617 parser
->objc_pq_context
= true;
8618 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8620 /* Forget protocol qualifiers now. */
8621 parser
->objc_pq_context
= false;
8623 /* Do not allow the presence of attributes to hide an erroneous
8624 method implementation in the interface section. */
8625 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8627 c_parser_error (parser
, "expected %<;%>");
8631 if (decl
!= error_mark_node
)
8632 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8634 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8637 /* If we are at a position that method attributes may be present, check that
8638 there are not any parsed already (a syntax error) and then collect any
8639 specified at the current location. Finally, if new attributes were present,
8640 check that the next token is legal ( ';' for decls and '{' for defs). */
8643 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8648 c_parser_error (parser
,
8649 "method attributes must be specified at the end only");
8650 *attributes
= NULL_TREE
;
8654 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8655 *attributes
= c_parser_attributes (parser
);
8657 /* If there were no attributes here, just report any earlier error. */
8658 if (*attributes
== NULL_TREE
|| bad
)
8661 /* If the attributes are followed by a ; or {, then just report any earlier
8663 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8664 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8667 /* We've got attributes, but not at the end. */
8668 c_parser_error (parser
,
8669 "expected %<;%> or %<{%> after method attribute definition");
8673 /* Parse an objc-method-decl.
8676 ( objc-type-name ) objc-selector
8678 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8679 objc-keyword-selector objc-optparmlist
8682 objc-keyword-selector:
8684 objc-keyword-selector objc-keyword-decl
8687 objc-selector : ( objc-type-name ) identifier
8688 objc-selector : identifier
8689 : ( objc-type-name ) identifier
8693 objc-optparms objc-optellipsis
8697 objc-opt-parms , parameter-declaration
8705 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8706 tree
*attributes
, tree
*expr
)
8708 tree type
= NULL_TREE
;
8710 tree parms
= NULL_TREE
;
8711 bool ellipsis
= false;
8712 bool attr_err
= false;
8714 *attributes
= NULL_TREE
;
8715 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8717 c_parser_consume_token (parser
);
8718 type
= c_parser_objc_type_name (parser
);
8719 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8721 sel
= c_parser_objc_selector (parser
);
8722 /* If there is no selector, or a colon follows, we have an
8723 objc-keyword-selector. If there is a selector, and a colon does
8724 not follow, that selector ends the objc-method-decl. */
8725 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8728 tree list
= NULL_TREE
;
8731 tree atype
= NULL_TREE
, id
, keyworddecl
;
8732 tree param_attr
= NULL_TREE
;
8733 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8735 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8737 c_parser_consume_token (parser
);
8738 atype
= c_parser_objc_type_name (parser
);
8739 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8742 /* New ObjC allows attributes on method parameters. */
8743 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8744 param_attr
= c_parser_attributes (parser
);
8745 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8747 c_parser_error (parser
, "expected identifier");
8748 return error_mark_node
;
8750 id
= c_parser_peek_token (parser
)->value
;
8751 c_parser_consume_token (parser
);
8752 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8753 list
= chainon (list
, keyworddecl
);
8754 tsel
= c_parser_objc_selector (parser
);
8755 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8759 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8761 /* Parse the optional parameter list. Optional Objective-C
8762 method parameters follow the C syntax, and may include '...'
8763 to denote a variable number of arguments. */
8764 parms
= make_node (TREE_LIST
);
8765 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8767 struct c_parm
*parm
;
8768 c_parser_consume_token (parser
);
8769 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8772 c_parser_consume_token (parser
);
8773 attr_err
|= c_parser_objc_maybe_method_attributes
8774 (parser
, attributes
) ;
8777 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8780 parms
= chainon (parms
,
8781 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8786 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8790 c_parser_error (parser
, "objective-c method declaration is expected");
8791 return error_mark_node
;
8795 return error_mark_node
;
8797 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8800 /* Parse an objc-type-name.
8803 objc-type-qualifiers[opt] type-name
8804 objc-type-qualifiers[opt]
8806 objc-type-qualifiers:
8808 objc-type-qualifiers objc-type-qualifier
8810 objc-type-qualifier: one of
8811 in out inout bycopy byref oneway
8815 c_parser_objc_type_name (c_parser
*parser
)
8817 tree quals
= NULL_TREE
;
8818 struct c_type_name
*type_name
= NULL
;
8819 tree type
= NULL_TREE
;
8822 c_token
*token
= c_parser_peek_token (parser
);
8823 if (token
->type
== CPP_KEYWORD
8824 && (token
->keyword
== RID_IN
8825 || token
->keyword
== RID_OUT
8826 || token
->keyword
== RID_INOUT
8827 || token
->keyword
== RID_BYCOPY
8828 || token
->keyword
== RID_BYREF
8829 || token
->keyword
== RID_ONEWAY
))
8831 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8832 c_parser_consume_token (parser
);
8837 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8838 type_name
= c_parser_type_name (parser
);
8840 type
= groktypename (type_name
, NULL
, NULL
);
8842 /* If the type is unknown, and error has already been produced and
8843 we need to recover from the error. In that case, use NULL_TREE
8844 for the type, as if no type had been specified; this will use the
8845 default type ('id') which is good for error recovery. */
8846 if (type
== error_mark_node
)
8849 return build_tree_list (quals
, type
);
8852 /* Parse objc-protocol-refs.
8859 c_parser_objc_protocol_refs (c_parser
*parser
)
8861 tree list
= NULL_TREE
;
8862 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8863 c_parser_consume_token (parser
);
8864 /* Any identifiers, including those declared as type names, are OK
8869 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8871 c_parser_error (parser
, "expected identifier");
8874 id
= c_parser_peek_token (parser
)->value
;
8875 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8876 c_parser_consume_token (parser
);
8877 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8878 c_parser_consume_token (parser
);
8882 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8886 /* Parse an objc-try-catch-finally-statement.
8888 objc-try-catch-finally-statement:
8889 @try compound-statement objc-catch-list[opt]
8890 @try compound-statement objc-catch-list[opt] @finally compound-statement
8893 @catch ( objc-catch-parameter-declaration ) compound-statement
8894 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8896 objc-catch-parameter-declaration:
8897 parameter-declaration
8900 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8902 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8903 for C++. Keep them in sync. */
8906 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8908 location_t location
;
8911 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8912 c_parser_consume_token (parser
);
8913 location
= c_parser_peek_token (parser
)->location
;
8914 objc_maybe_warn_exceptions (location
);
8915 stmt
= c_parser_compound_statement (parser
);
8916 objc_begin_try_stmt (location
, stmt
);
8918 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8920 struct c_parm
*parm
;
8921 tree parameter_declaration
= error_mark_node
;
8922 bool seen_open_paren
= false;
8924 c_parser_consume_token (parser
);
8925 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8926 seen_open_paren
= true;
8927 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8929 /* We have "@catch (...)" (where the '...' are literally
8930 what is in the code). Skip the '...'.
8931 parameter_declaration is set to NULL_TREE, and
8932 objc_being_catch_clauses() knows that that means
8934 c_parser_consume_token (parser
);
8935 parameter_declaration
= NULL_TREE
;
8939 /* We have "@catch (NSException *exception)" or something
8940 like that. Parse the parameter declaration. */
8941 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8943 parameter_declaration
= error_mark_node
;
8945 parameter_declaration
= grokparm (parm
, NULL
);
8947 if (seen_open_paren
)
8948 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8951 /* If there was no open parenthesis, we are recovering from
8952 an error, and we are trying to figure out what mistake
8953 the user has made. */
8955 /* If there is an immediate closing parenthesis, the user
8956 probably forgot the opening one (ie, they typed "@catch
8957 NSException *e)". Parse the closing parenthesis and keep
8959 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8960 c_parser_consume_token (parser
);
8962 /* If these is no immediate closing parenthesis, the user
8963 probably doesn't know that parenthesis are required at
8964 all (ie, they typed "@catch NSException *e"). So, just
8965 forget about the closing parenthesis and keep going. */
8967 objc_begin_catch_clause (parameter_declaration
);
8968 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8969 c_parser_compound_statement_nostart (parser
);
8970 objc_finish_catch_clause ();
8972 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8974 c_parser_consume_token (parser
);
8975 location
= c_parser_peek_token (parser
)->location
;
8976 stmt
= c_parser_compound_statement (parser
);
8977 objc_build_finally_clause (location
, stmt
);
8979 objc_finish_try_stmt ();
8982 /* Parse an objc-synchronized-statement.
8984 objc-synchronized-statement:
8985 @synchronized ( expression ) compound-statement
8989 c_parser_objc_synchronized_statement (c_parser
*parser
)
8993 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8994 c_parser_consume_token (parser
);
8995 loc
= c_parser_peek_token (parser
)->location
;
8996 objc_maybe_warn_exceptions (loc
);
8997 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8999 struct c_expr ce
= c_parser_expression (parser
);
9000 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9002 expr
= c_fully_fold (expr
, false, NULL
);
9003 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9006 expr
= error_mark_node
;
9007 stmt
= c_parser_compound_statement (parser
);
9008 objc_build_synchronized (loc
, expr
, stmt
);
9011 /* Parse an objc-selector; return NULL_TREE without an error if the
9012 next token is not an objc-selector.
9017 enum struct union if else while do for switch case default
9018 break continue return goto asm sizeof typeof __alignof
9019 unsigned long const short volatile signed restrict _Complex
9020 in out inout bycopy byref oneway int char float double void _Bool
9023 ??? Why this selection of keywords but not, for example, storage
9024 class specifiers? */
9027 c_parser_objc_selector (c_parser
*parser
)
9029 c_token
*token
= c_parser_peek_token (parser
);
9030 tree value
= token
->value
;
9031 if (token
->type
== CPP_NAME
)
9033 c_parser_consume_token (parser
);
9036 if (token
->type
!= CPP_KEYWORD
)
9038 switch (token
->keyword
)
9085 c_parser_consume_token (parser
);
9092 /* Parse an objc-selector-arg.
9096 objc-keywordname-list
9098 objc-keywordname-list:
9100 objc-keywordname-list objc-keywordname
9108 c_parser_objc_selector_arg (c_parser
*parser
)
9110 tree sel
= c_parser_objc_selector (parser
);
9111 tree list
= NULL_TREE
;
9112 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9116 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9118 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9119 sel
= c_parser_objc_selector (parser
);
9120 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9126 /* Parse an objc-receiver.
9135 c_parser_objc_receiver (c_parser
*parser
)
9137 location_t loc
= c_parser_peek_token (parser
)->location
;
9139 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9140 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9141 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9143 tree id
= c_parser_peek_token (parser
)->value
;
9144 c_parser_consume_token (parser
);
9145 return objc_get_class_reference (id
);
9147 struct c_expr ce
= c_parser_expression (parser
);
9148 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9149 return c_fully_fold (ce
.value
, false, NULL
);
9152 /* Parse objc-message-args.
9156 objc-keywordarg-list
9158 objc-keywordarg-list:
9160 objc-keywordarg-list objc-keywordarg
9163 objc-selector : objc-keywordexpr
9168 c_parser_objc_message_args (c_parser
*parser
)
9170 tree sel
= c_parser_objc_selector (parser
);
9171 tree list
= NULL_TREE
;
9172 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9177 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9178 return error_mark_node
;
9179 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9180 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9181 sel
= c_parser_objc_selector (parser
);
9182 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9188 /* Parse an objc-keywordexpr.
9195 c_parser_objc_keywordexpr (c_parser
*parser
)
9198 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9199 NULL
, NULL
, NULL
, NULL
);
9200 if (vec_safe_length (expr_list
) == 1)
9202 /* Just return the expression, remove a level of
9204 ret
= (*expr_list
)[0];
9208 /* We have a comma expression, we will collapse later. */
9209 ret
= build_tree_list_vec (expr_list
);
9211 release_tree_vector (expr_list
);
9215 /* A check, needed in several places, that ObjC interface, implementation or
9216 method definitions are not prefixed by incorrect items. */
9218 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9219 struct c_declspecs
*specs
)
9221 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9222 || specs
->typespec_kind
!= ctsk_none
)
9224 c_parser_error (parser
,
9225 "no type or storage class may be specified here,");
9226 c_parser_skip_to_end_of_block_or_statement (parser
);
9232 /* Parse an Objective-C @property declaration. The syntax is:
9234 objc-property-declaration:
9235 '@property' objc-property-attributes[opt] struct-declaration ;
9237 objc-property-attributes:
9238 '(' objc-property-attribute-list ')'
9240 objc-property-attribute-list:
9241 objc-property-attribute
9242 objc-property-attribute-list, objc-property-attribute
9244 objc-property-attribute
9245 'getter' = identifier
9246 'setter' = identifier
9255 @property NSString *name;
9256 @property (readonly) id object;
9257 @property (retain, nonatomic, getter=getTheName) id name;
9258 @property int a, b, c;
9260 PS: This function is identical to cp_parser_objc_at_propery_declaration
9261 for C++. Keep them in sync. */
9263 c_parser_objc_at_property_declaration (c_parser
*parser
)
9265 /* The following variables hold the attributes of the properties as
9266 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9267 seen. When we see an attribute, we set them to 'true' (if they
9268 are boolean properties) or to the identifier (if they have an
9269 argument, ie, for getter and setter). Note that here we only
9270 parse the list of attributes, check the syntax and accumulate the
9271 attributes that we find. objc_add_property_declaration() will
9272 then process the information. */
9273 bool property_assign
= false;
9274 bool property_copy
= false;
9275 tree property_getter_ident
= NULL_TREE
;
9276 bool property_nonatomic
= false;
9277 bool property_readonly
= false;
9278 bool property_readwrite
= false;
9279 bool property_retain
= false;
9280 tree property_setter_ident
= NULL_TREE
;
9282 /* 'properties' is the list of properties that we read. Usually a
9283 single one, but maybe more (eg, in "@property int a, b, c;" there
9288 loc
= c_parser_peek_token (parser
)->location
;
9289 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9291 c_parser_consume_token (parser
); /* Eat '@property'. */
9293 /* Parse the optional attribute list... */
9294 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9297 c_parser_consume_token (parser
);
9299 /* Property attribute keywords are valid now. */
9300 parser
->objc_property_attr_context
= true;
9304 bool syntax_error
= false;
9305 c_token
*token
= c_parser_peek_token (parser
);
9308 if (token
->type
!= CPP_KEYWORD
)
9310 if (token
->type
== CPP_CLOSE_PAREN
)
9311 c_parser_error (parser
, "expected identifier");
9314 c_parser_consume_token (parser
);
9315 c_parser_error (parser
, "unknown property attribute");
9319 keyword
= token
->keyword
;
9320 c_parser_consume_token (parser
);
9323 case RID_ASSIGN
: property_assign
= true; break;
9324 case RID_COPY
: property_copy
= true; break;
9325 case RID_NONATOMIC
: property_nonatomic
= true; break;
9326 case RID_READONLY
: property_readonly
= true; break;
9327 case RID_READWRITE
: property_readwrite
= true; break;
9328 case RID_RETAIN
: property_retain
= true; break;
9332 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9334 if (keyword
== RID_GETTER
)
9335 c_parser_error (parser
,
9336 "missing %<=%> (after %<getter%> attribute)");
9338 c_parser_error (parser
,
9339 "missing %<=%> (after %<setter%> attribute)");
9340 syntax_error
= true;
9343 c_parser_consume_token (parser
); /* eat the = */
9344 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9346 c_parser_error (parser
, "expected identifier");
9347 syntax_error
= true;
9350 if (keyword
== RID_SETTER
)
9352 if (property_setter_ident
!= NULL_TREE
)
9353 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9355 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9356 c_parser_consume_token (parser
);
9357 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9358 c_parser_error (parser
, "setter name must terminate with %<:%>");
9360 c_parser_consume_token (parser
);
9364 if (property_getter_ident
!= NULL_TREE
)
9365 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9367 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9368 c_parser_consume_token (parser
);
9372 c_parser_error (parser
, "unknown property attribute");
9373 syntax_error
= true;
9380 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9381 c_parser_consume_token (parser
);
9385 parser
->objc_property_attr_context
= false;
9386 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9388 /* ... and the property declaration(s). */
9389 properties
= c_parser_struct_declaration (parser
);
9391 if (properties
== error_mark_node
)
9393 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9394 parser
->error
= false;
9398 if (properties
== NULL_TREE
)
9399 c_parser_error (parser
, "expected identifier");
9402 /* Comma-separated properties are chained together in
9403 reverse order; add them one by one. */
9404 properties
= nreverse (properties
);
9406 for (; properties
; properties
= TREE_CHAIN (properties
))
9407 objc_add_property_declaration (loc
, copy_node (properties
),
9408 property_readonly
, property_readwrite
,
9409 property_assign
, property_retain
,
9410 property_copy
, property_nonatomic
,
9411 property_getter_ident
, property_setter_ident
);
9414 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9415 parser
->error
= false;
9418 /* Parse an Objective-C @synthesize declaration. The syntax is:
9420 objc-synthesize-declaration:
9421 @synthesize objc-synthesize-identifier-list ;
9423 objc-synthesize-identifier-list:
9424 objc-synthesize-identifier
9425 objc-synthesize-identifier-list, objc-synthesize-identifier
9427 objc-synthesize-identifier
9429 identifier = identifier
9432 @synthesize MyProperty;
9433 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9435 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9436 for C++. Keep them in sync.
9439 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9441 tree list
= NULL_TREE
;
9443 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9444 loc
= c_parser_peek_token (parser
)->location
;
9446 c_parser_consume_token (parser
);
9449 tree property
, ivar
;
9450 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9452 c_parser_error (parser
, "expected identifier");
9453 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9454 /* Once we find the semicolon, we can resume normal parsing.
9455 We have to reset parser->error manually because
9456 c_parser_skip_until_found() won't reset it for us if the
9457 next token is precisely a semicolon. */
9458 parser
->error
= false;
9461 property
= c_parser_peek_token (parser
)->value
;
9462 c_parser_consume_token (parser
);
9463 if (c_parser_next_token_is (parser
, CPP_EQ
))
9465 c_parser_consume_token (parser
);
9466 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9468 c_parser_error (parser
, "expected identifier");
9469 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9470 parser
->error
= false;
9473 ivar
= c_parser_peek_token (parser
)->value
;
9474 c_parser_consume_token (parser
);
9478 list
= chainon (list
, build_tree_list (ivar
, property
));
9479 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9480 c_parser_consume_token (parser
);
9484 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9485 objc_add_synthesize_declaration (loc
, list
);
9488 /* Parse an Objective-C @dynamic declaration. The syntax is:
9490 objc-dynamic-declaration:
9491 @dynamic identifier-list ;
9494 @dynamic MyProperty;
9495 @dynamic MyProperty, AnotherProperty;
9497 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9498 for C++. Keep them in sync.
9501 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9503 tree list
= NULL_TREE
;
9505 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9506 loc
= c_parser_peek_token (parser
)->location
;
9508 c_parser_consume_token (parser
);
9512 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9514 c_parser_error (parser
, "expected identifier");
9515 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9516 parser
->error
= false;
9519 property
= c_parser_peek_token (parser
)->value
;
9520 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9521 c_parser_consume_token (parser
);
9522 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9523 c_parser_consume_token (parser
);
9527 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9528 objc_add_dynamic_declaration (loc
, list
);
9532 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9533 should be considered, statements. ALLOW_STMT is true if we're within
9534 the context of a function and such pragmas are to be allowed. Returns
9535 true if we actually parsed such a pragma. */
9538 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9542 id
= c_parser_peek_token (parser
)->pragma_kind
;
9543 gcc_assert (id
!= PRAGMA_NONE
);
9547 case PRAGMA_OACC_UPDATE
:
9548 if (context
!= pragma_compound
)
9550 if (context
== pragma_stmt
)
9551 c_parser_error (parser
, "%<#pragma acc update%> may only be "
9552 "used in compound statements");
9555 c_parser_oacc_update (parser
);
9558 case PRAGMA_OMP_BARRIER
:
9559 if (context
!= pragma_compound
)
9561 if (context
== pragma_stmt
)
9562 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9563 "used in compound statements");
9566 c_parser_omp_barrier (parser
);
9569 case PRAGMA_OMP_FLUSH
:
9570 if (context
!= pragma_compound
)
9572 if (context
== pragma_stmt
)
9573 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9574 "used in compound statements");
9577 c_parser_omp_flush (parser
);
9580 case PRAGMA_OMP_TASKWAIT
:
9581 if (context
!= pragma_compound
)
9583 if (context
== pragma_stmt
)
9584 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9585 "used in compound statements");
9588 c_parser_omp_taskwait (parser
);
9591 case PRAGMA_OMP_TASKYIELD
:
9592 if (context
!= pragma_compound
)
9594 if (context
== pragma_stmt
)
9595 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9596 "used in compound statements");
9599 c_parser_omp_taskyield (parser
);
9602 case PRAGMA_OMP_CANCEL
:
9603 if (context
!= pragma_compound
)
9605 if (context
== pragma_stmt
)
9606 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9607 "used in compound statements");
9610 c_parser_omp_cancel (parser
);
9613 case PRAGMA_OMP_CANCELLATION_POINT
:
9614 if (context
!= pragma_compound
)
9616 if (context
== pragma_stmt
)
9617 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9618 "only be used in compound statements");
9621 c_parser_omp_cancellation_point (parser
);
9624 case PRAGMA_OMP_THREADPRIVATE
:
9625 c_parser_omp_threadprivate (parser
);
9628 case PRAGMA_OMP_TARGET
:
9629 return c_parser_omp_target (parser
, context
);
9631 case PRAGMA_OMP_END_DECLARE_TARGET
:
9632 c_parser_omp_end_declare_target (parser
);
9635 case PRAGMA_OMP_SECTION
:
9636 error_at (c_parser_peek_token (parser
)->location
,
9637 "%<#pragma omp section%> may only be used in "
9638 "%<#pragma omp sections%> construct");
9639 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9642 case PRAGMA_OMP_DECLARE_REDUCTION
:
9643 c_parser_omp_declare (parser
, context
);
9646 c_parser_consume_pragma (parser
);
9647 c_parser_skip_to_pragma_eol (parser
);
9648 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9649 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9650 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9652 c_parser_error (parser
, "for, while or do statement expected");
9655 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9656 c_parser_for_statement (parser
, true);
9657 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9658 c_parser_while_statement (parser
, true);
9660 c_parser_do_statement (parser
, true);
9663 case PRAGMA_GCC_PCH_PREPROCESS
:
9664 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9665 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9668 case PRAGMA_CILK_SIMD
:
9669 if (!c_parser_cilk_verify_simd (parser
, context
))
9671 c_parser_consume_pragma (parser
);
9672 c_parser_cilk_simd (parser
);
9674 case PRAGMA_CILK_GRAINSIZE
:
9677 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9679 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9682 if (context
== pragma_external
)
9684 error_at (c_parser_peek_token (parser
)->location
,
9685 "%<#pragma grainsize%> must be inside a function");
9686 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9689 c_parser_cilk_grainsize (parser
);
9693 if (id
< PRAGMA_FIRST_EXTERNAL
)
9695 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9698 c_parser_error (parser
, "expected declaration specifiers");
9699 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9702 c_parser_omp_construct (parser
);
9708 c_parser_consume_pragma (parser
);
9709 c_invoke_pragma_handler (id
);
9711 /* Skip to EOL, but suppress any error message. Those will have been
9712 generated by the handler routine through calling error, as opposed
9713 to calling c_parser_error. */
9714 parser
->error
= true;
9715 c_parser_skip_to_pragma_eol (parser
);
9720 /* The interface the pragma parsers have to the lexer. */
9723 pragma_lex (tree
*value
)
9725 c_token
*tok
= c_parser_peek_token (the_parser
);
9726 enum cpp_ttype ret
= tok
->type
;
9728 *value
= tok
->value
;
9729 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9733 if (ret
== CPP_KEYWORD
)
9735 c_parser_consume_token (the_parser
);
9742 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9746 c_parser_consume_pragma (parser
);
9747 if (c_parser_next_token_is (parser
, CPP_STRING
))
9749 name
= c_parser_peek_token (parser
)->value
;
9750 c_parser_consume_token (parser
);
9753 c_parser_error (parser
, "expected string literal");
9754 c_parser_skip_to_pragma_eol (parser
);
9757 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9760 /* OpenACC and OpenMP parsing routines. */
9762 /* Returns name of the next clause.
9763 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9764 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9765 returned and the token is consumed. */
9767 static pragma_omp_clause
9768 c_parser_omp_clause_name (c_parser
*parser
)
9770 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9772 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9773 result
= PRAGMA_OMP_CLAUSE_IF
;
9774 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9775 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9776 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9777 result
= PRAGMA_OMP_CLAUSE_FOR
;
9778 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9780 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9785 if (!strcmp ("aligned", p
))
9786 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9787 else if (!strcmp ("async", p
))
9788 result
= PRAGMA_OMP_CLAUSE_ASYNC
;
9791 if (!strcmp ("collapse", p
))
9792 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9793 else if (!strcmp ("copy", p
))
9794 result
= PRAGMA_OMP_CLAUSE_COPY
;
9795 else if (!strcmp ("copyin", p
))
9796 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9797 else if (!strcmp ("copyout", p
))
9798 result
= PRAGMA_OMP_CLAUSE_COPYOUT
;
9799 else if (!strcmp ("copyprivate", p
))
9800 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9801 else if (!strcmp ("create", p
))
9802 result
= PRAGMA_OMP_CLAUSE_CREATE
;
9805 if (!strcmp ("delete", p
))
9806 result
= PRAGMA_OMP_CLAUSE_DELETE
;
9807 else if (!strcmp ("depend", p
))
9808 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9809 else if (!strcmp ("device", p
))
9810 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9811 else if (!strcmp ("deviceptr", p
))
9812 result
= PRAGMA_OMP_CLAUSE_DEVICEPTR
;
9813 else if (!strcmp ("dist_schedule", p
))
9814 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9817 if (!strcmp ("final", p
))
9818 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9819 else if (!strcmp ("firstprivate", p
))
9820 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9821 else if (!strcmp ("from", p
))
9822 result
= PRAGMA_OMP_CLAUSE_FROM
;
9825 if (!strcmp ("host", p
))
9826 result
= PRAGMA_OMP_CLAUSE_SELF
;
9829 if (!strcmp ("inbranch", p
))
9830 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9833 if (!strcmp ("lastprivate", p
))
9834 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9835 else if (!strcmp ("linear", p
))
9836 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9839 if (!strcmp ("map", p
))
9840 result
= PRAGMA_OMP_CLAUSE_MAP
;
9841 else if (!strcmp ("mergeable", p
))
9842 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9843 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9844 result
= PRAGMA_CILK_CLAUSE_MASK
;
9847 if (!strcmp ("notinbranch", p
))
9848 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9849 else if (!strcmp ("nowait", p
))
9850 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9851 else if (!strcmp ("num_gangs", p
))
9852 result
= PRAGMA_OMP_CLAUSE_NUM_GANGS
;
9853 else if (!strcmp ("num_teams", p
))
9854 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9855 else if (!strcmp ("num_threads", p
))
9856 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9857 else if (!strcmp ("num_workers", p
))
9858 result
= PRAGMA_OMP_CLAUSE_NUM_WORKERS
;
9859 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9860 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9863 if (!strcmp ("ordered", p
))
9864 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9867 if (!strcmp ("parallel", p
))
9868 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9869 else if (!strcmp ("present", p
))
9870 result
= PRAGMA_OMP_CLAUSE_PRESENT
;
9871 else if (!strcmp ("present_or_copy", p
)
9872 || !strcmp ("pcopy", p
))
9873 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
;
9874 else if (!strcmp ("present_or_copyin", p
)
9875 || !strcmp ("pcopyin", p
))
9876 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
;
9877 else if (!strcmp ("present_or_copyout", p
)
9878 || !strcmp ("pcopyout", p
))
9879 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
;
9880 else if (!strcmp ("present_or_create", p
)
9881 || !strcmp ("pcreate", p
))
9882 result
= PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
;
9883 else if (!strcmp ("private", p
))
9884 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9885 else if (!strcmp ("proc_bind", p
))
9886 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9889 if (!strcmp ("reduction", p
))
9890 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9893 if (!strcmp ("safelen", p
))
9894 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9895 else if (!strcmp ("schedule", p
))
9896 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9897 else if (!strcmp ("sections", p
))
9898 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9899 else if (!strcmp ("shared", p
))
9900 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9901 else if (!strcmp ("simdlen", p
))
9902 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9903 else if (!strcmp ("self", p
))
9904 result
= PRAGMA_OMP_CLAUSE_SELF
;
9907 if (!strcmp ("taskgroup", p
))
9908 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9909 else if (!strcmp ("thread_limit", p
))
9910 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9911 else if (!strcmp ("to", p
))
9912 result
= PRAGMA_OMP_CLAUSE_TO
;
9915 if (!strcmp ("uniform", p
))
9916 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9917 else if (!strcmp ("untied", p
))
9918 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9921 if (!strcmp ("vector_length", p
))
9922 result
= PRAGMA_OMP_CLAUSE_VECTOR_LENGTH
;
9923 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9924 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9927 if (!strcmp ("wait", p
))
9928 result
= PRAGMA_OMP_CLAUSE_WAIT
;
9933 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9934 c_parser_consume_token (parser
);
9939 /* Validate that a clause of the given type does not already exist. */
9942 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9947 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9948 if (OMP_CLAUSE_CODE (c
) == code
)
9950 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9951 error_at (loc
, "too many %qs clauses", name
);
9957 Parse wait clause or wait directive parameters. */
9960 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
9962 vec
<tree
, va_gc
> *args
;
9965 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9968 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
9970 if (args
->length () == 0)
9972 c_parser_error (parser
, "expected integer expression before ')'");
9973 release_tree_vector (args
);
9977 args_tree
= build_tree_list_vec (args
);
9979 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
9981 tree targ
= TREE_VALUE (t
);
9983 if (targ
!= error_mark_node
)
9985 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
9987 c_parser_error (parser
, "expression must be integral");
9988 targ
= error_mark_node
;
9992 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
9994 OMP_CLAUSE_DECL (c
) = targ
;
9995 OMP_CLAUSE_CHAIN (c
) = list
;
10001 release_tree_vector (args
);
10002 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10006 /* OpenACC 2.0, OpenMP 2.5:
10009 variable-list , identifier
10011 If KIND is nonzero, create the appropriate node and install the
10012 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10013 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10015 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10016 return the list created. */
10019 c_parser_omp_variable_list (c_parser
*parser
,
10020 location_t clause_loc
,
10021 enum omp_clause_code kind
, tree list
)
10023 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10024 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10025 c_parser_error (parser
, "expected identifier");
10027 while (c_parser_next_token_is (parser
, CPP_NAME
)
10028 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10030 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10032 if (t
== NULL_TREE
)
10034 undeclared_variable (c_parser_peek_token (parser
)->location
,
10035 c_parser_peek_token (parser
)->value
);
10036 t
= error_mark_node
;
10039 c_parser_consume_token (parser
);
10041 if (t
== error_mark_node
)
10043 else if (kind
!= 0)
10047 case OMP_CLAUSE_MAP
:
10048 case OMP_CLAUSE_FROM
:
10049 case OMP_CLAUSE_TO
:
10050 case OMP_CLAUSE_DEPEND
:
10051 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10053 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10055 c_parser_consume_token (parser
);
10056 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10058 low_bound
= c_parser_expression (parser
).value
;
10059 mark_exp_read (low_bound
);
10061 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10062 length
= integer_one_node
;
10065 /* Look for `:'. */
10066 if (!c_parser_require (parser
, CPP_COLON
,
10069 t
= error_mark_node
;
10072 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10074 length
= c_parser_expression (parser
).value
;
10075 mark_exp_read (length
);
10078 /* Look for the closing `]'. */
10079 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10082 t
= error_mark_node
;
10085 t
= tree_cons (low_bound
, length
, t
);
10092 if (t
!= error_mark_node
)
10094 tree u
= build_omp_clause (clause_loc
, kind
);
10095 OMP_CLAUSE_DECL (u
) = t
;
10096 OMP_CLAUSE_CHAIN (u
) = list
;
10101 list
= tree_cons (t
, NULL_TREE
, list
);
10103 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10106 c_parser_consume_token (parser
);
10112 /* Similarly, but expect leading and trailing parenthesis. This is a very
10113 common case for OpenACC and OpenMP clauses. */
10116 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10119 /* The clauses location. */
10120 location_t loc
= c_parser_peek_token (parser
)->location
;
10122 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10124 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10125 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10131 copy ( variable-list )
10132 copyin ( variable-list )
10133 copyout ( variable-list )
10134 create ( variable-list )
10135 delete ( variable-list )
10136 present ( variable-list )
10137 present_or_copy ( variable-list )
10138 pcopy ( variable-list )
10139 present_or_copyin ( variable-list )
10140 pcopyin ( variable-list )
10141 present_or_copyout ( variable-list )
10142 pcopyout ( variable-list )
10143 present_or_create ( variable-list )
10144 pcreate ( variable-list ) */
10147 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10150 enum omp_clause_map_kind kind
;
10154 gcc_unreachable ();
10155 case PRAGMA_OMP_CLAUSE_COPY
:
10156 kind
= OMP_CLAUSE_MAP_FORCE_TOFROM
;
10158 case PRAGMA_OMP_CLAUSE_COPYIN
:
10159 kind
= OMP_CLAUSE_MAP_FORCE_TO
;
10161 case PRAGMA_OMP_CLAUSE_COPYOUT
:
10162 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
10164 case PRAGMA_OMP_CLAUSE_CREATE
:
10165 kind
= OMP_CLAUSE_MAP_FORCE_ALLOC
;
10167 case PRAGMA_OMP_CLAUSE_DELETE
:
10168 kind
= OMP_CLAUSE_MAP_FORCE_DEALLOC
;
10170 case PRAGMA_OMP_CLAUSE_DEVICE
:
10171 kind
= OMP_CLAUSE_MAP_FORCE_TO
;
10173 case PRAGMA_OMP_CLAUSE_HOST
:
10174 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
10176 case PRAGMA_OMP_CLAUSE_PRESENT
:
10177 kind
= OMP_CLAUSE_MAP_FORCE_PRESENT
;
10179 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
:
10180 kind
= OMP_CLAUSE_MAP_TOFROM
;
10182 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
:
10183 kind
= OMP_CLAUSE_MAP_TO
;
10185 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
:
10186 kind
= OMP_CLAUSE_MAP_FROM
;
10188 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
:
10189 kind
= OMP_CLAUSE_MAP_ALLOC
;
10191 case PRAGMA_OMP_CLAUSE_SELF
:
10192 kind
= OMP_CLAUSE_MAP_FORCE_FROM
;
10196 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10198 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10199 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10205 deviceptr ( variable-list ) */
10208 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10210 location_t loc
= c_parser_peek_token (parser
)->location
;
10213 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10214 c_parser_oacc_data_clause), as for PRAGMA_OMP_CLAUSE_DEVICEPTR,
10215 variable-list must only allow for pointer variables. */
10216 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10217 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10219 tree v
= TREE_PURPOSE (t
);
10221 /* FIXME diagnostics: Ideally we should keep individual
10222 locations for all the variables in the var list to make the
10223 following errors more precise. Perhaps
10224 c_parser_omp_var_list_parens() should construct a list of
10225 locations to go along with the var list. */
10227 if (TREE_CODE (v
) != VAR_DECL
)
10228 error_at (loc
, "%qD is not a variable", v
);
10229 else if (TREE_TYPE (v
) == error_mark_node
)
10231 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10232 error_at (loc
, "%qD is not a pointer variable", v
);
10234 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10235 OMP_CLAUSE_MAP_KIND (u
) = OMP_CLAUSE_MAP_FORCE_DEVICEPTR
;
10236 OMP_CLAUSE_DECL (u
) = v
;
10237 OMP_CLAUSE_CHAIN (u
) = list
;
10244 /* OpenACC 2.0, OpenMP 3.0:
10245 collapse ( constant-expression ) */
10248 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10250 tree c
, num
= error_mark_node
;
10254 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10256 loc
= c_parser_peek_token (parser
)->location
;
10257 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10259 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10260 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10262 if (num
== error_mark_node
)
10264 mark_exp_read (num
);
10265 num
= c_fully_fold (num
, false, NULL
);
10266 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10267 || !tree_fits_shwi_p (num
)
10268 || (n
= tree_to_shwi (num
)) <= 0
10272 "collapse argument needs positive constant integer expression");
10275 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10276 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10277 OMP_CLAUSE_CHAIN (c
) = list
;
10282 copyin ( variable-list ) */
10285 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10287 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10291 copyprivate ( variable-list ) */
10294 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10296 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10300 default ( shared | none ) */
10303 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10305 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10306 location_t loc
= c_parser_peek_token (parser
)->location
;
10309 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10311 if (c_parser_next_token_is (parser
, CPP_NAME
))
10313 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10318 if (strcmp ("none", p
) != 0)
10320 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10324 if (strcmp ("shared", p
) != 0)
10326 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10333 c_parser_consume_token (parser
);
10338 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10340 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10342 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10345 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10346 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10347 OMP_CLAUSE_CHAIN (c
) = list
;
10348 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10354 firstprivate ( variable-list ) */
10357 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10359 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10363 final ( expression ) */
10366 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10368 location_t loc
= c_parser_peek_token (parser
)->location
;
10369 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10371 tree t
= c_parser_paren_condition (parser
);
10374 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10376 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10377 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10378 OMP_CLAUSE_CHAIN (c
) = list
;
10382 c_parser_error (parser
, "expected %<(%>");
10387 /* OpenACC, OpenMP 2.5:
10388 if ( expression ) */
10391 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10393 location_t loc
= c_parser_peek_token (parser
)->location
;
10394 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10396 tree t
= c_parser_paren_condition (parser
);
10399 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10401 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10402 OMP_CLAUSE_IF_EXPR (c
) = t
;
10403 OMP_CLAUSE_CHAIN (c
) = list
;
10407 c_parser_error (parser
, "expected %<(%>");
10413 lastprivate ( variable-list ) */
10416 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10418 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10425 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10429 /* FIXME: Should we allow duplicates? */
10430 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10432 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10433 OMP_CLAUSE_MERGEABLE
);
10434 OMP_CLAUSE_CHAIN (c
) = list
;
10443 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10446 location_t loc
= c_parser_peek_token (parser
)->location
;
10448 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10450 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10451 OMP_CLAUSE_CHAIN (c
) = list
;
10456 num_gangs ( expression ) */
10459 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
10461 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
10462 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10464 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10465 tree c
, t
= c_parser_expression (parser
).value
;
10467 t
= c_fully_fold (t
, false, NULL
);
10469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10471 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10473 c_parser_error (parser
, "expected integer expression");
10477 /* Attempt to statically determine when the number isn't positive. */
10478 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10479 build_int_cst (TREE_TYPE (t
), 0));
10480 if (CAN_HAVE_LOCATION_P (c
))
10481 SET_EXPR_LOCATION (c
, expr_loc
);
10482 if (c
== boolean_true_node
)
10484 warning_at (expr_loc
, 0,
10485 "%<num_gangs%> value must be positive");
10486 t
= integer_one_node
;
10489 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
10491 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
10492 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
10493 OMP_CLAUSE_CHAIN (c
) = list
;
10501 num_threads ( expression ) */
10504 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10506 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10507 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10509 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10510 tree c
, t
= c_parser_expression (parser
).value
;
10512 t
= c_fully_fold (t
, false, NULL
);
10514 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10516 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10518 c_parser_error (parser
, "expected integer expression");
10522 /* Attempt to statically determine when the number isn't positive. */
10523 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10524 build_int_cst (TREE_TYPE (t
), 0));
10525 if (CAN_HAVE_LOCATION_P (c
))
10526 SET_EXPR_LOCATION (c
, expr_loc
);
10527 if (c
== boolean_true_node
)
10529 warning_at (expr_loc
, 0,
10530 "%<num_threads%> value must be positive");
10531 t
= integer_one_node
;
10534 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10536 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10537 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10538 OMP_CLAUSE_CHAIN (c
) = list
;
10546 num_workers ( expression ) */
10549 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
10551 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
10552 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10554 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10555 tree c
, t
= c_parser_expression (parser
).value
;
10557 t
= c_fully_fold (t
, false, NULL
);
10559 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10561 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10563 c_parser_error (parser
, "expected integer expression");
10567 /* Attempt to statically determine when the number isn't positive. */
10568 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10569 build_int_cst (TREE_TYPE (t
), 0));
10570 if (CAN_HAVE_LOCATION_P (c
))
10571 SET_EXPR_LOCATION (c
, expr_loc
);
10572 if (c
== boolean_true_node
)
10574 warning_at (expr_loc
, 0,
10575 "%<num_workers%> value must be positive");
10576 t
= integer_one_node
;
10579 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
10581 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
10582 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
10583 OMP_CLAUSE_CHAIN (c
) = list
;
10591 async [( int-expr )] */
10594 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
10597 location_t loc
= c_parser_peek_token (parser
)->location
;
10599 /* TODO XXX: FIX -1 (acc_async_noval). */
10600 t
= build_int_cst (integer_type_node
, -1);
10602 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10604 c_parser_consume_token (parser
);
10606 t
= c_parser_expression (parser
).value
;
10607 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10608 c_parser_error (parser
, "expected integer expression");
10609 else if (t
== error_mark_node
10610 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10615 t
= c_fully_fold (t
, false, NULL
);
10618 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
10620 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
10621 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
10622 OMP_CLAUSE_CHAIN (c
) = list
;
10629 wait ( int-expr-list ) */
10632 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
10634 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10636 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10637 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
10646 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10650 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10652 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10653 OMP_CLAUSE_ORDERED
);
10654 OMP_CLAUSE_CHAIN (c
) = list
;
10660 private ( variable-list ) */
10663 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10665 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10669 reduction ( reduction-operator : variable-list )
10671 reduction-operator:
10672 One of: + * - & ^ | && ||
10676 reduction-operator:
10677 One of: + * - & ^ | && || max min
10681 reduction-operator:
10682 One of: + * - & ^ | && ||
10686 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10688 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10689 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10691 enum tree_code code
= ERROR_MARK
;
10692 tree reduc_id
= NULL_TREE
;
10694 switch (c_parser_peek_token (parser
)->type
)
10706 code
= BIT_AND_EXPR
;
10709 code
= BIT_XOR_EXPR
;
10712 code
= BIT_IOR_EXPR
;
10715 code
= TRUTH_ANDIF_EXPR
;
10718 code
= TRUTH_ORIF_EXPR
;
10723 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10724 if (strcmp (p
, "min") == 0)
10729 if (strcmp (p
, "max") == 0)
10734 reduc_id
= c_parser_peek_token (parser
)->value
;
10738 c_parser_error (parser
,
10739 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10740 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10741 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10744 c_parser_consume_token (parser
);
10745 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10746 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10750 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10751 OMP_CLAUSE_REDUCTION
, list
);
10752 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10754 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10755 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10756 if (code
== ERROR_MARK
10757 || !(INTEGRAL_TYPE_P (type
)
10758 || TREE_CODE (type
) == REAL_TYPE
10759 || TREE_CODE (type
) == COMPLEX_TYPE
))
10760 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10761 = c_omp_reduction_lookup (reduc_id
,
10762 TYPE_MAIN_VARIANT (type
));
10767 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10773 schedule ( schedule-kind )
10774 schedule ( schedule-kind , expression )
10777 static | dynamic | guided | runtime | auto
10781 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10784 location_t loc
= c_parser_peek_token (parser
)->location
;
10786 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10789 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10791 if (c_parser_next_token_is (parser
, CPP_NAME
))
10793 tree kind
= c_parser_peek_token (parser
)->value
;
10794 const char *p
= IDENTIFIER_POINTER (kind
);
10799 if (strcmp ("dynamic", p
) != 0)
10801 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10805 if (strcmp ("guided", p
) != 0)
10807 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10811 if (strcmp ("runtime", p
) != 0)
10813 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10820 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10821 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10822 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10823 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10827 c_parser_consume_token (parser
);
10828 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10831 c_parser_consume_token (parser
);
10833 here
= c_parser_peek_token (parser
)->location
;
10834 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10836 t
= c_fully_fold (t
, false, NULL
);
10838 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10839 error_at (here
, "schedule %<runtime%> does not take "
10840 "a %<chunk_size%> parameter");
10841 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10843 "schedule %<auto%> does not take "
10844 "a %<chunk_size%> parameter");
10845 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10846 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10848 c_parser_error (parser
, "expected integer expression");
10850 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10853 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10854 "expected %<,%> or %<)%>");
10856 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10857 OMP_CLAUSE_CHAIN (c
) = list
;
10861 c_parser_error (parser
, "invalid schedule kind");
10862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10867 shared ( variable-list ) */
10870 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10872 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10879 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10883 /* FIXME: Should we allow duplicates? */
10884 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10886 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10887 OMP_CLAUSE_UNTIED
);
10888 OMP_CLAUSE_CHAIN (c
) = list
;
10894 vector_length ( expression ) */
10897 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
10899 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
10900 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10902 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10903 tree c
, t
= c_parser_expression (parser
).value
;
10905 t
= c_fully_fold (t
, false, NULL
);
10907 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10909 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10911 c_parser_error (parser
, "expected integer expression");
10915 /* Attempt to statically determine when the number isn't positive. */
10916 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10917 build_int_cst (TREE_TYPE (t
), 0));
10918 if (CAN_HAVE_LOCATION_P (c
))
10919 SET_EXPR_LOCATION (c
, expr_loc
);
10920 if (c
== boolean_true_node
)
10922 warning_at (expr_loc
, 0,
10923 "%<vector_length%> value must be positive");
10924 t
= integer_one_node
;
10927 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
10929 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
10930 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
10931 OMP_CLAUSE_CHAIN (c
) = list
;
10943 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10944 enum omp_clause_code code
, tree list
)
10946 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10948 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10949 OMP_CLAUSE_CHAIN (c
) = list
;
10961 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10962 enum omp_clause_code code
, tree list
)
10964 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10965 OMP_CLAUSE_CHAIN (c
) = list
;
10971 num_teams ( expression ) */
10974 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10976 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10977 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10979 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10980 tree c
, t
= c_parser_expression (parser
).value
;
10982 t
= c_fully_fold (t
, false, NULL
);
10984 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10986 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10988 c_parser_error (parser
, "expected integer expression");
10992 /* Attempt to statically determine when the number isn't positive. */
10993 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10994 build_int_cst (TREE_TYPE (t
), 0));
10995 if (CAN_HAVE_LOCATION_P (c
))
10996 SET_EXPR_LOCATION (c
, expr_loc
);
10997 if (c
== boolean_true_node
)
10999 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
11000 t
= integer_one_node
;
11003 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
11005 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
11006 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
11007 OMP_CLAUSE_CHAIN (c
) = list
;
11015 thread_limit ( expression ) */
11018 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
11020 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
11021 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11023 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11024 tree c
, t
= c_parser_expression (parser
).value
;
11026 t
= c_fully_fold (t
, false, NULL
);
11028 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11030 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11032 c_parser_error (parser
, "expected integer expression");
11036 /* Attempt to statically determine when the number isn't positive. */
11037 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11038 build_int_cst (TREE_TYPE (t
), 0));
11039 if (CAN_HAVE_LOCATION_P (c
))
11040 SET_EXPR_LOCATION (c
, expr_loc
);
11041 if (c
== boolean_true_node
)
11043 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
11044 t
= integer_one_node
;
11047 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
11050 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11051 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
11052 OMP_CLAUSE_CHAIN (c
) = list
;
11060 aligned ( variable-list )
11061 aligned ( variable-list : constant-expression ) */
11064 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
11066 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11069 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11072 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11073 OMP_CLAUSE_ALIGNED
, list
);
11075 if (c_parser_next_token_is (parser
, CPP_COLON
))
11077 c_parser_consume_token (parser
);
11078 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
11079 mark_exp_read (alignment
);
11080 alignment
= c_fully_fold (alignment
, false, NULL
);
11081 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
11082 && TREE_CODE (alignment
) != INTEGER_CST
11083 && tree_int_cst_sgn (alignment
) != 1)
11085 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
11086 "be positive constant integer expression");
11087 alignment
= NULL_TREE
;
11090 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11091 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
11094 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11099 linear ( variable-list )
11100 linear ( variable-list : expression ) */
11103 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
11105 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11108 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11111 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11112 OMP_CLAUSE_LINEAR
, list
);
11114 if (c_parser_next_token_is (parser
, CPP_COLON
))
11116 c_parser_consume_token (parser
);
11117 step
= c_parser_expression (parser
).value
;
11118 mark_exp_read (step
);
11119 step
= c_fully_fold (step
, false, NULL
);
11120 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
11122 sorry ("using parameters for %<linear%> step is not supported yet");
11123 step
= integer_one_node
;
11125 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
11127 error_at (clause_loc
, "%<linear%> clause step expression must "
11129 step
= integer_one_node
;
11134 step
= integer_one_node
;
11136 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11138 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11141 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11146 safelen ( constant-expression ) */
11149 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
11151 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11154 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11157 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11159 t
= c_fully_fold (t
, false, NULL
);
11160 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11161 && TREE_CODE (t
) != INTEGER_CST
11162 && tree_int_cst_sgn (t
) != 1)
11164 error_at (clause_loc
, "%<safelen%> clause expression must "
11165 "be positive constant integer expression");
11169 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11170 if (t
== NULL_TREE
|| t
== error_mark_node
)
11173 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
11175 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
11176 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
11177 OMP_CLAUSE_CHAIN (c
) = list
;
11182 simdlen ( constant-expression ) */
11185 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
11187 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11190 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11193 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11195 t
= c_fully_fold (t
, false, NULL
);
11196 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11197 && TREE_CODE (t
) != INTEGER_CST
11198 && tree_int_cst_sgn (t
) != 1)
11200 error_at (clause_loc
, "%<simdlen%> clause expression must "
11201 "be positive constant integer expression");
11205 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11206 if (t
== NULL_TREE
|| t
== error_mark_node
)
11209 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
11211 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
11212 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
11213 OMP_CLAUSE_CHAIN (c
) = list
;
11218 depend ( depend-kind: variable-list )
11221 in | out | inout */
11224 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
11226 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11227 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
11230 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11233 if (c_parser_next_token_is (parser
, CPP_NAME
))
11235 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11236 if (strcmp ("in", p
) == 0)
11237 kind
= OMP_CLAUSE_DEPEND_IN
;
11238 else if (strcmp ("inout", p
) == 0)
11239 kind
= OMP_CLAUSE_DEPEND_INOUT
;
11240 else if (strcmp ("out", p
) == 0)
11241 kind
= OMP_CLAUSE_DEPEND_OUT
;
11248 c_parser_consume_token (parser
);
11249 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11252 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11253 OMP_CLAUSE_DEPEND
, list
);
11255 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11256 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
11258 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11262 c_parser_error (parser
, "invalid depend kind");
11264 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11269 map ( map-kind: variable-list )
11270 map ( variable-list )
11273 alloc | to | from | tofrom */
11276 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
11278 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11279 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
11282 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11285 if (c_parser_next_token_is (parser
, CPP_NAME
)
11286 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11288 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11289 if (strcmp ("alloc", p
) == 0)
11290 kind
= OMP_CLAUSE_MAP_ALLOC
;
11291 else if (strcmp ("to", p
) == 0)
11292 kind
= OMP_CLAUSE_MAP_TO
;
11293 else if (strcmp ("from", p
) == 0)
11294 kind
= OMP_CLAUSE_MAP_FROM
;
11295 else if (strcmp ("tofrom", p
) == 0)
11296 kind
= OMP_CLAUSE_MAP_TOFROM
;
11299 c_parser_error (parser
, "invalid map kind");
11300 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11304 c_parser_consume_token (parser
);
11305 c_parser_consume_token (parser
);
11308 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
11310 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11311 OMP_CLAUSE_MAP_KIND (c
) = kind
;
11313 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11318 device ( expression ) */
11321 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
11323 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11324 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11326 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11328 t
= c_fully_fold (t
, false, NULL
);
11330 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11332 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11334 c_parser_error (parser
, "expected integer expression");
11338 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
11340 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
11341 OMP_CLAUSE_DEVICE_ID (c
) = t
;
11342 OMP_CLAUSE_CHAIN (c
) = list
;
11350 dist_schedule ( static )
11351 dist_schedule ( static , expression ) */
11354 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
11356 tree c
, t
= NULL_TREE
;
11357 location_t loc
= c_parser_peek_token (parser
)->location
;
11359 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11362 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11364 c_parser_error (parser
, "invalid dist_schedule kind");
11365 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11370 c_parser_consume_token (parser
);
11371 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11373 c_parser_consume_token (parser
);
11375 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11377 t
= c_fully_fold (t
, false, NULL
);
11378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11381 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11382 "expected %<,%> or %<)%>");
11384 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11385 if (t
== error_mark_node
)
11388 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
11389 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
11390 OMP_CLAUSE_CHAIN (c
) = list
;
11395 proc_bind ( proc-bind-kind )
11398 master | close | spread */
11401 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
11403 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11404 enum omp_clause_proc_bind_kind kind
;
11407 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11410 if (c_parser_next_token_is (parser
, CPP_NAME
))
11412 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11413 if (strcmp ("master", p
) == 0)
11414 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
11415 else if (strcmp ("close", p
) == 0)
11416 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
11417 else if (strcmp ("spread", p
) == 0)
11418 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
11425 c_parser_consume_token (parser
);
11426 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11427 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
11428 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
11429 OMP_CLAUSE_CHAIN (c
) = list
;
11433 c_parser_error (parser
, "invalid proc_bind kind");
11434 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11439 to ( variable-list ) */
11442 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
11444 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
11448 from ( variable-list ) */
11451 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
11453 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
11457 uniform ( variable-list ) */
11460 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
11462 /* The clauses location. */
11463 location_t loc
= c_parser_peek_token (parser
)->location
;
11465 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11467 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
11469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11474 /* Parse all OpenACC clauses. The set clauses allowed by the directive
11475 is a bitmask in MASK. Return the list of clauses found. */
11478 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11479 const char *where
, bool finish_p
= true)
11481 tree clauses
= NULL
;
11484 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11487 pragma_omp_clause c_kind
;
11488 const char *c_name
;
11489 tree prev
= clauses
;
11491 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11492 c_parser_consume_token (parser
);
11494 here
= c_parser_peek_token (parser
)->location
;
11495 c_kind
= c_parser_omp_clause_name (parser
);
11499 case PRAGMA_OMP_CLAUSE_ASYNC
:
11500 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
11503 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11504 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11505 c_name
= "collapse";
11507 case PRAGMA_OMP_CLAUSE_COPY
:
11508 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11511 case PRAGMA_OMP_CLAUSE_COPYIN
:
11512 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11515 case PRAGMA_OMP_CLAUSE_COPYOUT
:
11516 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11517 c_name
= "copyout";
11519 case PRAGMA_OMP_CLAUSE_CREATE
:
11520 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11523 case PRAGMA_OMP_CLAUSE_DELETE
:
11524 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11527 case PRAGMA_OMP_CLAUSE_DEVICE
:
11528 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11531 case PRAGMA_OMP_CLAUSE_DEVICEPTR
:
11532 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
11533 c_name
= "deviceptr";
11535 case PRAGMA_OMP_CLAUSE_HOST
:
11536 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11539 case PRAGMA_OMP_CLAUSE_IF
:
11540 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11543 case PRAGMA_OMP_CLAUSE_NUM_GANGS
:
11544 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
11545 c_name
= "num_gangs";
11547 case PRAGMA_OMP_CLAUSE_NUM_WORKERS
:
11548 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
11549 c_name
= "num_workers";
11551 case PRAGMA_OMP_CLAUSE_PRESENT
:
11552 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11553 c_name
= "present";
11555 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY
:
11556 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11557 c_name
= "present_or_copy";
11559 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN
:
11560 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11561 c_name
= "present_or_copyin";
11563 case PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT
:
11564 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11565 c_name
= "present_or_copyout";
11567 case PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE
:
11568 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11569 c_name
= "present_or_create";
11571 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11572 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11573 c_name
= "reduction";
11575 case PRAGMA_OMP_CLAUSE_SELF
:
11576 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11579 case PRAGMA_OMP_CLAUSE_VECTOR_LENGTH
:
11580 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
11581 c_name
= "vector_length";
11583 case PRAGMA_OMP_CLAUSE_WAIT
:
11584 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
11588 c_parser_error (parser
, "expected clause");
11594 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11596 /* Remove the invalid clause(s) from the list to avoid
11597 confusing the rest of the compiler. */
11599 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11604 c_parser_skip_to_pragma_eol (parser
);
11607 return c_finish_omp_clauses (clauses
);
11612 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11613 is a bitmask in MASK. Return the list of clauses found. */
11616 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11617 const char *where
, bool finish_p
= true)
11619 tree clauses
= NULL
;
11620 bool first
= true, cilk_simd_fn
= false;
11622 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11625 pragma_omp_clause c_kind
;
11626 const char *c_name
;
11627 tree prev
= clauses
;
11629 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11630 c_parser_consume_token (parser
);
11632 here
= c_parser_peek_token (parser
)->location
;
11633 c_kind
= c_parser_omp_clause_name (parser
);
11637 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11638 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11639 c_name
= "collapse";
11641 case PRAGMA_OMP_CLAUSE_COPYIN
:
11642 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11645 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11646 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11647 c_name
= "copyprivate";
11649 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11650 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11651 c_name
= "default";
11653 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11654 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11655 c_name
= "firstprivate";
11657 case PRAGMA_OMP_CLAUSE_FINAL
:
11658 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11661 case PRAGMA_OMP_CLAUSE_IF
:
11662 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11665 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11666 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11667 c_name
= "lastprivate";
11669 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11670 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11671 c_name
= "mergeable";
11673 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11674 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11677 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11678 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11679 c_name
= "num_threads";
11681 case PRAGMA_OMP_CLAUSE_ORDERED
:
11682 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11683 c_name
= "ordered";
11685 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11686 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11687 c_name
= "private";
11689 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11690 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11691 c_name
= "reduction";
11693 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11694 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11695 c_name
= "schedule";
11697 case PRAGMA_OMP_CLAUSE_SHARED
:
11698 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11701 case PRAGMA_OMP_CLAUSE_UNTIED
:
11702 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11705 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11706 case PRAGMA_CILK_CLAUSE_MASK
:
11707 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11709 c_name
= "inbranch";
11711 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11712 case PRAGMA_CILK_CLAUSE_NOMASK
:
11713 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11715 c_name
= "notinbranch";
11717 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11719 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11721 c_name
= "parallel";
11725 error_at (here
, "%qs must be the first clause of %qs",
11730 case PRAGMA_OMP_CLAUSE_FOR
:
11732 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11736 goto clause_not_first
;
11738 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11740 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11742 c_name
= "sections";
11744 goto clause_not_first
;
11746 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11748 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11750 c_name
= "taskgroup";
11752 goto clause_not_first
;
11754 case PRAGMA_OMP_CLAUSE_TO
:
11755 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11758 case PRAGMA_OMP_CLAUSE_FROM
:
11759 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11762 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11763 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11764 c_name
= "uniform";
11766 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11767 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11768 c_name
= "num_teams";
11770 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11771 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11772 c_name
= "thread_limit";
11774 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11775 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11776 c_name
= "aligned";
11778 case PRAGMA_OMP_CLAUSE_LINEAR
:
11779 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11780 cilk_simd_fn
= true;
11781 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11784 case PRAGMA_OMP_CLAUSE_DEPEND
:
11785 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11788 case PRAGMA_OMP_CLAUSE_MAP
:
11789 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11792 case PRAGMA_OMP_CLAUSE_DEVICE
:
11793 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11796 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11797 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11798 c_name
= "dist_schedule";
11800 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11801 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11802 c_name
= "proc_bind";
11804 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11805 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11806 c_name
= "safelen";
11808 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11809 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11810 c_name
= "simdlen";
11812 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11813 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11814 c_name
= "simdlen";
11817 c_parser_error (parser
, "expected clause");
11823 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11825 /* Remove the invalid clause(s) from the list to avoid
11826 confusing the rest of the compiler. */
11828 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11833 c_parser_skip_to_pragma_eol (parser
);
11836 return c_finish_omp_clauses (clauses
);
11841 /* OpenACC 2.0, OpenMP 2.5:
11845 In practice, we're also interested in adding the statement to an
11846 outer node. So it is convenient if we work around the fact that
11847 c_parser_statement calls add_stmt. */
11850 c_parser_omp_structured_block (c_parser
*parser
)
11852 tree stmt
= push_stmt_list ();
11853 c_parser_statement (parser
);
11854 return pop_stmt_list (stmt
);
11858 # pragma acc data oacc-data-clause[optseq] new-line
11861 LOC is the location of the #pragma token.
11864 #define OACC_DATA_CLAUSE_MASK \
11865 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11866 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11867 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11868 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11869 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11870 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11871 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11872 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11873 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11874 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11875 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) )
11878 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
11880 tree stmt
, clauses
, block
;
11882 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
11883 "#pragma acc data");
11885 block
= c_begin_omp_parallel ();
11886 add_stmt (c_parser_omp_structured_block (parser
));
11888 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
11894 # pragma acc kernels oacc-kernels-clause[optseq] new-line
11897 LOC is the location of the #pragma token.
11900 #define OACC_KERNELS_CLAUSE_MASK \
11901 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
11902 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11903 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11904 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11905 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11906 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11907 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11911 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11912 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) \
11913 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
11916 c_parser_oacc_kernels (location_t loc
, c_parser
*parser
, char *p_name
)
11918 tree stmt
, clauses
= NULL_TREE
, block
;
11920 strcat (p_name
, " kernels");
11922 if (c_parser_next_token_is (parser
, CPP_NAME
))
11924 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11925 if (strcmp (p
, "loop") == 0)
11927 c_parser_consume_token (parser
);
11928 block
= c_begin_omp_parallel ();
11929 c_parser_oacc_loop (loc
, parser
, p_name
);
11930 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
11931 OACC_KERNELS_COMBINED (stmt
) = 1;
11936 clauses
= c_parser_oacc_all_clauses (parser
, OACC_KERNELS_CLAUSE_MASK
,
11939 block
= c_begin_omp_parallel ();
11940 add_stmt (c_parser_omp_structured_block (parser
));
11942 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
11948 # pragma acc loop oacc-loop-clause[optseq] new-line
11951 LOC is the location of the #pragma token.
11954 #define OACC_LOOP_CLAUSE_MASK \
11955 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11956 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) )
11959 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
)
11961 tree stmt
, clauses
, block
;
11963 strcat (p_name
, " loop");
11965 clauses
= c_parser_oacc_all_clauses (parser
, OACC_LOOP_CLAUSE_MASK
, p_name
);
11967 block
= c_begin_compound_stmt (true);
11968 stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
11969 block
= c_end_compound_stmt (loc
, block
, true);
11976 # pragma acc parallel oacc-parallel-clause[optseq] new-line
11979 LOC is the location of the #pragma token.
11982 #define OACC_PARALLEL_CLAUSE_MASK \
11983 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
11984 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPY) \
11985 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11986 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYOUT) \
11987 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_CREATE) \
11988 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICEPTR) \
11989 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11990 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_GANGS) \
11991 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_WORKERS) \
11992 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT) \
11993 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPY) \
11994 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYIN) \
11995 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_COPYOUT) \
11996 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRESENT_OR_CREATE) \
11997 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11998 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_VECTOR_LENGTH) \
11999 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
12002 c_parser_oacc_parallel (location_t loc
, c_parser
*parser
, char *p_name
)
12004 tree stmt
, clauses
= NULL_TREE
, block
;
12006 strcat (p_name
, " parallel");
12008 if (c_parser_next_token_is (parser
, CPP_NAME
))
12010 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12011 if (strcmp (p
, "loop") == 0)
12013 c_parser_consume_token (parser
);
12014 block
= c_begin_omp_parallel ();
12015 c_parser_oacc_loop (loc
, parser
, p_name
);
12016 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12017 OACC_PARALLEL_COMBINED (stmt
) = 1;
12022 clauses
= c_parser_oacc_all_clauses (parser
, OACC_PARALLEL_CLAUSE_MASK
,
12025 block
= c_begin_omp_parallel ();
12026 add_stmt (c_parser_omp_structured_block (parser
));
12028 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12034 # pragma acc update oacc-update-clause[optseq] new-line
12037 #define OACC_UPDATE_CLAUSE_MASK \
12038 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) \
12039 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12040 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HOST) \
12041 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12042 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SELF) \
12043 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_WAIT) )
12046 c_parser_oacc_update (c_parser
*parser
)
12048 location_t loc
= c_parser_peek_token (parser
)->location
;
12050 c_parser_consume_pragma (parser
);
12052 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
12053 "#pragma acc update");
12054 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12057 "%<#pragma acc update%> must contain at least one "
12058 "%<device%> or %<host/self%> clause");
12065 tree stmt
= make_node (OACC_UPDATE
);
12066 TREE_TYPE (stmt
) = void_type_node
;
12067 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
12068 SET_EXPR_LOCATION (stmt
, loc
);
12073 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12075 LOC is the location of the #pragma token.
12078 #define OACC_WAIT_CLAUSE_MASK \
12079 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ASYNC) )
12082 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
12084 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
12086 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12087 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
12089 strcpy (p_name
, " wait");
12090 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
12091 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
12097 # pragma omp atomic new-line
12101 x binop= expr | x++ | ++x | x-- | --x
12103 +, *, -, /, &, ^, |, <<, >>
12105 where x is an lvalue expression with scalar type.
12108 # pragma omp atomic new-line
12111 # pragma omp atomic read new-line
12114 # pragma omp atomic write new-line
12117 # pragma omp atomic update new-line
12120 # pragma omp atomic capture new-line
12123 # pragma omp atomic capture new-line
12131 expression-stmt | x = x binop expr
12133 v = expression-stmt
12135 { v = x; update-stmt; } | { update-stmt; v = x; }
12139 expression-stmt | x = x binop expr | x = expr binop x
12143 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12145 where x and v are lvalue expressions with scalar type.
12147 LOC is the location of the #pragma token. */
12150 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
12152 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
12153 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
12154 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
12155 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
12156 struct c_expr expr
;
12158 bool structured_block
= false;
12159 bool swapped
= false;
12160 bool seq_cst
= false;
12162 if (c_parser_next_token_is (parser
, CPP_NAME
))
12164 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12165 if (!strcmp (p
, "seq_cst"))
12168 c_parser_consume_token (parser
);
12169 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12170 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12171 c_parser_consume_token (parser
);
12174 if (c_parser_next_token_is (parser
, CPP_NAME
))
12176 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12178 if (!strcmp (p
, "read"))
12179 code
= OMP_ATOMIC_READ
;
12180 else if (!strcmp (p
, "write"))
12182 else if (!strcmp (p
, "update"))
12184 else if (!strcmp (p
, "capture"))
12185 code
= OMP_ATOMIC_CAPTURE_NEW
;
12189 c_parser_consume_token (parser
);
12193 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12194 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12195 c_parser_consume_token (parser
);
12197 if (c_parser_next_token_is (parser
, CPP_NAME
))
12200 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12201 if (!strcmp (p
, "seq_cst"))
12204 c_parser_consume_token (parser
);
12208 c_parser_skip_to_pragma_eol (parser
);
12212 case OMP_ATOMIC_READ
:
12213 case NOP_EXPR
: /* atomic write */
12214 v
= c_parser_unary_expression (parser
).value
;
12215 v
= c_fully_fold (v
, false, NULL
);
12216 if (v
== error_mark_node
)
12218 loc
= c_parser_peek_token (parser
)->location
;
12219 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12221 if (code
== NOP_EXPR
)
12222 lhs
= c_parser_expression (parser
).value
;
12224 lhs
= c_parser_unary_expression (parser
).value
;
12225 lhs
= c_fully_fold (lhs
, false, NULL
);
12226 if (lhs
== error_mark_node
)
12228 if (code
== NOP_EXPR
)
12230 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
12238 case OMP_ATOMIC_CAPTURE_NEW
:
12239 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12241 c_parser_consume_token (parser
);
12242 structured_block
= true;
12246 v
= c_parser_unary_expression (parser
).value
;
12247 v
= c_fully_fold (v
, false, NULL
);
12248 if (v
== error_mark_node
)
12250 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12258 /* For structured_block case we don't know yet whether
12259 old or new x should be captured. */
12261 eloc
= c_parser_peek_token (parser
)->location
;
12262 expr
= c_parser_unary_expression (parser
);
12264 expr
= default_function_array_conversion (eloc
, expr
);
12265 unfolded_lhs
= expr
.value
;
12266 lhs
= c_fully_fold (lhs
, false, NULL
);
12268 switch (TREE_CODE (lhs
))
12272 c_parser_skip_to_end_of_block_or_statement (parser
);
12273 if (structured_block
)
12275 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12276 c_parser_consume_token (parser
);
12277 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
12279 c_parser_skip_to_end_of_block_or_statement (parser
);
12280 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12281 c_parser_consume_token (parser
);
12286 case POSTINCREMENT_EXPR
:
12287 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12288 code
= OMP_ATOMIC_CAPTURE_OLD
;
12290 case PREINCREMENT_EXPR
:
12291 lhs
= TREE_OPERAND (lhs
, 0);
12292 unfolded_lhs
= NULL_TREE
;
12293 opcode
= PLUS_EXPR
;
12294 rhs
= integer_one_node
;
12297 case POSTDECREMENT_EXPR
:
12298 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12299 code
= OMP_ATOMIC_CAPTURE_OLD
;
12301 case PREDECREMENT_EXPR
:
12302 lhs
= TREE_OPERAND (lhs
, 0);
12303 unfolded_lhs
= NULL_TREE
;
12304 opcode
= MINUS_EXPR
;
12305 rhs
= integer_one_node
;
12308 case COMPOUND_EXPR
:
12309 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
12310 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
12311 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
12312 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
12313 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12314 (TREE_OPERAND (lhs
, 1), 0), 0)))
12316 /* Undo effects of boolean_increment for post {in,de}crement. */
12317 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
12320 if (TREE_CODE (lhs
) == MODIFY_EXPR
12321 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
12323 /* Undo effects of boolean_increment. */
12324 if (integer_onep (TREE_OPERAND (lhs
, 1)))
12326 /* This is pre or post increment. */
12327 rhs
= TREE_OPERAND (lhs
, 1);
12328 lhs
= TREE_OPERAND (lhs
, 0);
12329 unfolded_lhs
= NULL_TREE
;
12331 if (code
== OMP_ATOMIC_CAPTURE_NEW
12332 && !structured_block
12333 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12334 code
= OMP_ATOMIC_CAPTURE_OLD
;
12337 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
12338 && TREE_OPERAND (lhs
, 0)
12339 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
12341 /* This is pre or post decrement. */
12342 rhs
= TREE_OPERAND (lhs
, 1);
12343 lhs
= TREE_OPERAND (lhs
, 0);
12344 unfolded_lhs
= NULL_TREE
;
12346 if (code
== OMP_ATOMIC_CAPTURE_NEW
12347 && !structured_block
12348 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12349 code
= OMP_ATOMIC_CAPTURE_OLD
;
12355 switch (c_parser_peek_token (parser
)->type
)
12358 opcode
= MULT_EXPR
;
12361 opcode
= TRUNC_DIV_EXPR
;
12364 opcode
= PLUS_EXPR
;
12367 opcode
= MINUS_EXPR
;
12369 case CPP_LSHIFT_EQ
:
12370 opcode
= LSHIFT_EXPR
;
12372 case CPP_RSHIFT_EQ
:
12373 opcode
= RSHIFT_EXPR
;
12376 opcode
= BIT_AND_EXPR
;
12379 opcode
= BIT_IOR_EXPR
;
12382 opcode
= BIT_XOR_EXPR
;
12385 c_parser_consume_token (parser
);
12386 eloc
= c_parser_peek_token (parser
)->location
;
12387 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
12389 switch (TREE_CODE (rhs1
))
12392 case TRUNC_DIV_EXPR
:
12400 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
12402 opcode
= TREE_CODE (rhs1
);
12403 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12404 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12407 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
12409 opcode
= TREE_CODE (rhs1
);
12410 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12411 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12412 swapped
= !commutative_tree_code (opcode
);
12421 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
12423 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12425 code
= OMP_ATOMIC_CAPTURE_OLD
;
12428 expr
= default_function_array_read_conversion (eloc
, expr
);
12429 unfolded_lhs1
= expr
.value
;
12430 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
12432 c_parser_consume_token (parser
);
12435 if (structured_block
)
12438 expr
= default_function_array_read_conversion (eloc
, expr
);
12439 rhs
= c_fully_fold (expr
.value
, false, NULL
);
12444 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
12447 c_parser_error (parser
,
12448 "invalid operator for %<#pragma omp atomic%>");
12452 /* Arrange to pass the location of the assignment operator to
12453 c_finish_omp_atomic. */
12454 loc
= c_parser_peek_token (parser
)->location
;
12455 c_parser_consume_token (parser
);
12456 eloc
= c_parser_peek_token (parser
)->location
;
12457 expr
= c_parser_expression (parser
);
12458 expr
= default_function_array_read_conversion (eloc
, expr
);
12460 rhs
= c_fully_fold (rhs
, false, NULL
);
12464 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12466 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
12468 v
= c_parser_unary_expression (parser
).value
;
12469 v
= c_fully_fold (v
, false, NULL
);
12470 if (v
== error_mark_node
)
12472 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12474 eloc
= c_parser_peek_token (parser
)->location
;
12475 expr
= c_parser_unary_expression (parser
);
12477 expr
= default_function_array_read_conversion (eloc
, expr
);
12478 unfolded_lhs1
= expr
.value
;
12479 lhs1
= c_fully_fold (lhs1
, false, NULL
);
12480 if (lhs1
== error_mark_node
)
12483 if (structured_block
)
12485 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12486 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
12489 if (unfolded_lhs
&& unfolded_lhs1
12490 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
12492 error ("%<#pragma omp atomic capture%> uses two different "
12493 "expressions for memory");
12494 stmt
= error_mark_node
;
12497 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
12499 if (stmt
!= error_mark_node
)
12502 if (!structured_block
)
12503 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12508 # pragma omp barrier new-line
12512 c_parser_omp_barrier (c_parser
*parser
)
12514 location_t loc
= c_parser_peek_token (parser
)->location
;
12515 c_parser_consume_pragma (parser
);
12516 c_parser_skip_to_pragma_eol (parser
);
12518 c_finish_omp_barrier (loc
);
12522 # pragma omp critical [(name)] new-line
12525 LOC is the location of the #pragma itself. */
12528 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
12530 tree stmt
, name
= NULL
;
12532 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12534 c_parser_consume_token (parser
);
12535 if (c_parser_next_token_is (parser
, CPP_NAME
))
12537 name
= c_parser_peek_token (parser
)->value
;
12538 c_parser_consume_token (parser
);
12539 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12542 c_parser_error (parser
, "expected identifier");
12544 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12545 c_parser_error (parser
, "expected %<(%> or end of line");
12546 c_parser_skip_to_pragma_eol (parser
);
12548 stmt
= c_parser_omp_structured_block (parser
);
12549 return c_finish_omp_critical (loc
, stmt
, name
);
12553 # pragma omp flush flush-vars[opt] new-line
12556 ( variable-list ) */
12559 c_parser_omp_flush (c_parser
*parser
)
12561 location_t loc
= c_parser_peek_token (parser
)->location
;
12562 c_parser_consume_pragma (parser
);
12563 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12564 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12565 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12566 c_parser_error (parser
, "expected %<(%> or end of line");
12567 c_parser_skip_to_pragma_eol (parser
);
12569 c_finish_omp_flush (loc
);
12572 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12573 The real trick here is to determine the loop control variable early
12574 so that we can push a new decl if necessary to make it private.
12575 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12579 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
12580 tree clauses
, tree
*cclauses
)
12582 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
12583 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
12584 bool fail
= false, open_brace_parsed
= false;
12585 int i
, collapse
= 1, nbraces
= 0;
12586 location_t for_loc
;
12587 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
12589 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
12590 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
12591 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
12593 gcc_assert (collapse
>= 1);
12595 declv
= make_tree_vec (collapse
);
12596 initv
= make_tree_vec (collapse
);
12597 condv
= make_tree_vec (collapse
);
12598 incrv
= make_tree_vec (collapse
);
12600 if (code
!= CILK_FOR
12601 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
12603 c_parser_error (parser
, "for statement expected");
12606 if (code
== CILK_FOR
12607 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
12609 c_parser_error (parser
, "_Cilk_for statement expected");
12612 for_loc
= c_parser_peek_token (parser
)->location
;
12613 c_parser_consume_token (parser
);
12615 for (i
= 0; i
< collapse
; i
++)
12617 int bracecount
= 0;
12619 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12622 /* Parse the initialization declaration or expression. */
12623 if (c_parser_next_tokens_start_declaration (parser
))
12626 vec_safe_push (for_block
, c_begin_compound_stmt (true));
12627 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12629 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
12632 if (DECL_INITIAL (decl
) == error_mark_node
)
12633 decl
= error_mark_node
;
12636 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12637 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
12639 struct c_expr decl_exp
;
12640 struct c_expr init_exp
;
12641 location_t init_loc
;
12643 decl_exp
= c_parser_postfix_expression (parser
);
12644 decl
= decl_exp
.value
;
12646 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
12648 init_loc
= c_parser_peek_token (parser
)->location
;
12649 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
12650 init_exp
= default_function_array_read_conversion (init_loc
,
12652 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
12653 NOP_EXPR
, init_loc
, init_exp
.value
,
12654 init_exp
.original_type
);
12655 init
= c_process_expr_stmt (init_loc
, init
);
12657 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12662 c_parser_error (parser
,
12663 "expected iteration declaration or initialization");
12664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12670 /* Parse the loop condition. */
12672 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
12674 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
12675 struct c_expr cond_expr
12676 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
12678 cond
= cond_expr
.value
;
12679 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
12680 cond
= c_fully_fold (cond
, false, NULL
);
12681 switch (cond_expr
.original_code
)
12689 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
12693 /* Can't be cond = error_mark_node, because we want to preserve
12694 the location until c_finish_omp_for. */
12695 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
12698 protected_set_expr_location (cond
, cond_loc
);
12700 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12702 /* Parse the increment expression. */
12704 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
12706 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
12708 incr
= c_process_expr_stmt (incr_loc
,
12709 c_parser_expression (parser
).value
);
12711 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12713 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
12717 TREE_VEC_ELT (declv
, i
) = decl
;
12718 TREE_VEC_ELT (initv
, i
) = init
;
12719 TREE_VEC_ELT (condv
, i
) = cond
;
12720 TREE_VEC_ELT (incrv
, i
) = incr
;
12724 if (i
== collapse
- 1)
12727 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12728 in between the collapsed for loops to be still considered perfectly
12729 nested. Hopefully the final version clarifies this.
12730 For now handle (multiple) {'s and empty statements. */
12733 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12735 c_parser_consume_token (parser
);
12738 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12740 c_parser_consume_token (parser
);
12743 else if (bracecount
12744 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12745 c_parser_consume_token (parser
);
12748 c_parser_error (parser
, "not enough perfectly nested loops");
12751 open_brace_parsed
= true;
12761 nbraces
+= bracecount
;
12764 save_break
= c_break_label
;
12765 if (code
== CILK_SIMD
)
12766 c_break_label
= build_int_cst (size_type_node
, 2);
12768 c_break_label
= size_one_node
;
12769 save_cont
= c_cont_label
;
12770 c_cont_label
= NULL_TREE
;
12771 body
= push_stmt_list ();
12773 if (open_brace_parsed
)
12775 location_t here
= c_parser_peek_token (parser
)->location
;
12776 stmt
= c_begin_compound_stmt (true);
12777 c_parser_compound_statement_nostart (parser
);
12778 add_stmt (c_end_compound_stmt (here
, stmt
, true));
12781 add_stmt (c_parser_c99_block_statement (parser
));
12784 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
12785 SET_EXPR_LOCATION (t
, loc
);
12789 body
= pop_stmt_list (body
);
12790 c_break_label
= save_break
;
12791 c_cont_label
= save_cont
;
12795 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12797 c_parser_consume_token (parser
);
12800 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12801 c_parser_consume_token (parser
);
12804 c_parser_error (parser
, "collapsed loops not perfectly nested");
12807 location_t here
= c_parser_peek_token (parser
)->location
;
12808 stmt
= c_begin_compound_stmt (true);
12810 c_parser_compound_statement_nostart (parser
);
12811 body
= c_end_compound_stmt (here
, stmt
, true);
12818 /* Only bother calling c_finish_omp_for if we haven't already generated
12819 an error from the initialization parsing. */
12822 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
12823 incrv
, body
, NULL
);
12826 if (cclauses
!= NULL
12827 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
12829 gcc_assert (code
!= OACC_LOOP
);
12831 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
12832 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
12833 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
12834 c
= &OMP_CLAUSE_CHAIN (*c
);
12837 for (i
= 0; i
< collapse
; i
++)
12838 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
12841 c
= &OMP_CLAUSE_CHAIN (*c
);
12842 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
12845 "iteration variable %qD should not be firstprivate",
12846 OMP_CLAUSE_DECL (*c
));
12847 *c
= OMP_CLAUSE_CHAIN (*c
);
12851 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
12852 change it to shared (decl) in
12853 OMP_PARALLEL_CLAUSES. */
12854 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
12855 OMP_CLAUSE_LASTPRIVATE
);
12856 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
12857 if (code
== OMP_SIMD
)
12859 OMP_CLAUSE_CHAIN (l
)
12860 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12861 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
12865 OMP_CLAUSE_CHAIN (l
) = clauses
;
12868 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
12872 OMP_FOR_CLAUSES (stmt
) = clauses
;
12877 while (!for_block
->is_empty ())
12879 /* FIXME diagnostics: LOC below should be the actual location of
12880 this particular for block. We need to build a list of
12881 locations to go along with FOR_BLOCK. */
12882 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
12885 release_tree_vector (for_block
);
12889 /* Helper function for OpenMP parsing, split clauses and call
12890 finish_omp_clauses on each of the set of clauses afterwards. */
12893 omp_split_clauses (location_t loc
, enum tree_code code
,
12894 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
12897 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
12898 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
12900 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
12904 #pragma omp simd simd-clause[optseq] new-line
12907 LOC is the location of the #pragma token.
12910 #define OMP_SIMD_CLAUSE_MASK \
12911 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
12912 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12913 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12914 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12915 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12916 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12917 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12920 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
12921 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12923 tree block
, clauses
, ret
;
12925 strcat (p_name
, " simd");
12926 mask
|= OMP_SIMD_CLAUSE_MASK
;
12927 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
12929 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12932 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
12933 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
12936 block
= c_begin_compound_stmt (true);
12937 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
12938 block
= c_end_compound_stmt (loc
, block
, true);
12945 #pragma omp for for-clause[optseq] new-line
12949 #pragma omp for simd for-simd-clause[optseq] new-line
12952 LOC is the location of the #pragma token.
12955 #define OMP_FOR_CLAUSE_MASK \
12956 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12957 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12958 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12959 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12960 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12961 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12962 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12963 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12966 c_parser_omp_for (location_t loc
, c_parser
*parser
,
12967 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12969 tree block
, clauses
, ret
;
12971 strcat (p_name
, " for");
12972 mask
|= OMP_FOR_CLAUSE_MASK
;
12974 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12976 if (c_parser_next_token_is (parser
, CPP_NAME
))
12978 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12980 if (strcmp (p
, "simd") == 0)
12982 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12983 if (cclauses
== NULL
)
12984 cclauses
= cclauses_buf
;
12986 c_parser_consume_token (parser
);
12987 if (!flag_openmp
) /* flag_openmp_simd */
12988 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12989 block
= c_begin_compound_stmt (true);
12990 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12991 block
= c_end_compound_stmt (loc
, block
, true);
12992 if (ret
== NULL_TREE
)
12994 ret
= make_node (OMP_FOR
);
12995 TREE_TYPE (ret
) = void_type_node
;
12996 OMP_FOR_BODY (ret
) = block
;
12997 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12998 SET_EXPR_LOCATION (ret
, loc
);
13003 if (!flag_openmp
) /* flag_openmp_simd */
13005 c_parser_skip_to_pragma_eol (parser
);
13009 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13012 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
13013 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13016 block
= c_begin_compound_stmt (true);
13017 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
13018 block
= c_end_compound_stmt (loc
, block
, true);
13025 # pragma omp master new-line
13028 LOC is the location of the #pragma token.
13032 c_parser_omp_master (location_t loc
, c_parser
*parser
)
13034 c_parser_skip_to_pragma_eol (parser
);
13035 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
13039 # pragma omp ordered new-line
13042 LOC is the location of the #pragma itself.
13046 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
13048 c_parser_skip_to_pragma_eol (parser
);
13049 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
13055 { section-sequence }
13058 section-directive[opt] structured-block
13059 section-sequence section-directive structured-block
13061 SECTIONS_LOC is the location of the #pragma omp sections. */
13064 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
13066 tree stmt
, substmt
;
13067 bool error_suppress
= false;
13070 loc
= c_parser_peek_token (parser
)->location
;
13071 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
13073 /* Avoid skipping until the end of the block. */
13074 parser
->error
= false;
13078 stmt
= push_stmt_list ();
13080 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
13082 substmt
= c_parser_omp_structured_block (parser
);
13083 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13084 SET_EXPR_LOCATION (substmt
, loc
);
13085 add_stmt (substmt
);
13090 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13092 if (c_parser_next_token_is (parser
, CPP_EOF
))
13095 loc
= c_parser_peek_token (parser
)->location
;
13096 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
13098 c_parser_consume_pragma (parser
);
13099 c_parser_skip_to_pragma_eol (parser
);
13100 error_suppress
= false;
13102 else if (!error_suppress
)
13104 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
13105 error_suppress
= true;
13108 substmt
= c_parser_omp_structured_block (parser
);
13109 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13110 SET_EXPR_LOCATION (substmt
, loc
);
13111 add_stmt (substmt
);
13113 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
13114 "expected %<#pragma omp section%> or %<}%>");
13116 substmt
= pop_stmt_list (stmt
);
13118 stmt
= make_node (OMP_SECTIONS
);
13119 SET_EXPR_LOCATION (stmt
, sections_loc
);
13120 TREE_TYPE (stmt
) = void_type_node
;
13121 OMP_SECTIONS_BODY (stmt
) = substmt
;
13123 return add_stmt (stmt
);
13127 # pragma omp sections sections-clause[optseq] newline
13130 LOC is the location of the #pragma token.
13133 #define OMP_SECTIONS_CLAUSE_MASK \
13134 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13135 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13136 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13137 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13138 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13141 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
13142 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13144 tree block
, clauses
, ret
;
13146 strcat (p_name
, " sections");
13147 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
13149 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13151 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13154 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
13155 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
13158 block
= c_begin_compound_stmt (true);
13159 ret
= c_parser_omp_sections_scope (loc
, parser
);
13161 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
13162 block
= c_end_compound_stmt (loc
, block
, true);
13169 # pragma omp parallel parallel-clause[optseq] new-line
13171 # pragma omp parallel for parallel-for-clause[optseq] new-line
13173 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13177 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13180 LOC is the location of the #pragma token.
13183 #define OMP_PARALLEL_CLAUSE_MASK \
13184 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13185 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13186 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13187 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13188 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13189 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
13190 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13191 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
13192 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13195 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
13196 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13198 tree stmt
, clauses
, block
;
13200 strcat (p_name
, " parallel");
13201 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
13203 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
13205 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13206 if (cclauses
== NULL
)
13207 cclauses
= cclauses_buf
;
13209 c_parser_consume_token (parser
);
13210 if (!flag_openmp
) /* flag_openmp_simd */
13211 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13212 block
= c_begin_omp_parallel ();
13213 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13215 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13217 if (ret
== NULL_TREE
)
13219 OMP_PARALLEL_COMBINED (stmt
) = 1;
13224 error_at (loc
, "expected %<for%> after %qs", p_name
);
13225 c_parser_skip_to_pragma_eol (parser
);
13228 else if (!flag_openmp
) /* flag_openmp_simd */
13230 c_parser_skip_to_pragma_eol (parser
);
13233 else if (c_parser_next_token_is (parser
, CPP_NAME
))
13235 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13236 if (strcmp (p
, "sections") == 0)
13238 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13239 if (cclauses
== NULL
)
13240 cclauses
= cclauses_buf
;
13242 c_parser_consume_token (parser
);
13243 block
= c_begin_omp_parallel ();
13244 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
13245 stmt
= c_finish_omp_parallel (loc
,
13246 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13248 OMP_PARALLEL_COMBINED (stmt
) = 1;
13253 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13255 block
= c_begin_omp_parallel ();
13256 c_parser_statement (parser
);
13257 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
13263 # pragma omp single single-clause[optseq] new-line
13266 LOC is the location of the #pragma.
13269 #define OMP_SINGLE_CLAUSE_MASK \
13270 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13272 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
13273 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13276 c_parser_omp_single (location_t loc
, c_parser
*parser
)
13278 tree stmt
= make_node (OMP_SINGLE
);
13279 SET_EXPR_LOCATION (stmt
, loc
);
13280 TREE_TYPE (stmt
) = void_type_node
;
13282 OMP_SINGLE_CLAUSES (stmt
)
13283 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
13284 "#pragma omp single");
13285 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13287 return add_stmt (stmt
);
13291 # pragma omp task task-clause[optseq] new-line
13293 LOC is the location of the #pragma.
13296 #define OMP_TASK_CLAUSE_MASK \
13297 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13298 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
13299 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13301 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13303 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
13304 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
13305 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13308 c_parser_omp_task (location_t loc
, c_parser
*parser
)
13310 tree clauses
, block
;
13312 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
13313 "#pragma omp task");
13315 block
= c_begin_omp_task ();
13316 c_parser_statement (parser
);
13317 return c_finish_omp_task (loc
, clauses
, block
);
13321 # pragma omp taskwait new-line
13325 c_parser_omp_taskwait (c_parser
*parser
)
13327 location_t loc
= c_parser_peek_token (parser
)->location
;
13328 c_parser_consume_pragma (parser
);
13329 c_parser_skip_to_pragma_eol (parser
);
13331 c_finish_omp_taskwait (loc
);
13335 # pragma omp taskyield new-line
13339 c_parser_omp_taskyield (c_parser
*parser
)
13341 location_t loc
= c_parser_peek_token (parser
)->location
;
13342 c_parser_consume_pragma (parser
);
13343 c_parser_skip_to_pragma_eol (parser
);
13345 c_finish_omp_taskyield (loc
);
13349 # pragma omp taskgroup new-line
13353 c_parser_omp_taskgroup (c_parser
*parser
)
13355 location_t loc
= c_parser_peek_token (parser
)->location
;
13356 c_parser_skip_to_pragma_eol (parser
);
13357 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
13361 # pragma omp cancel cancel-clause[optseq] new-line
13363 LOC is the location of the #pragma.
13366 #define OMP_CANCEL_CLAUSE_MASK \
13367 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13368 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13369 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13370 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
13371 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13374 c_parser_omp_cancel (c_parser
*parser
)
13376 location_t loc
= c_parser_peek_token (parser
)->location
;
13378 c_parser_consume_pragma (parser
);
13379 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
13380 "#pragma omp cancel");
13382 c_finish_omp_cancel (loc
, clauses
);
13386 # pragma omp cancellation point cancelpt-clause[optseq] new-line
13388 LOC is the location of the #pragma.
13391 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
13392 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13393 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13394 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13395 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13398 c_parser_omp_cancellation_point (c_parser
*parser
)
13400 location_t loc
= c_parser_peek_token (parser
)->location
;
13402 bool point_seen
= false;
13404 c_parser_consume_pragma (parser
);
13405 if (c_parser_next_token_is (parser
, CPP_NAME
))
13407 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13408 if (strcmp (p
, "point") == 0)
13410 c_parser_consume_token (parser
);
13416 c_parser_error (parser
, "expected %<point%>");
13417 c_parser_skip_to_pragma_eol (parser
);
13422 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
13423 "#pragma omp cancellation point");
13425 c_finish_omp_cancellation_point (loc
, clauses
);
13429 #pragma omp distribute distribute-clause[optseq] new-line
13432 #define OMP_DISTRIBUTE_CLAUSE_MASK \
13433 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13434 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13435 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13436 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13439 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
13440 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13442 tree clauses
, block
, ret
;
13444 strcat (p_name
, " distribute");
13445 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
13447 if (c_parser_next_token_is (parser
, CPP_NAME
))
13449 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13451 bool parallel
= false;
13453 if (strcmp (p
, "simd") == 0)
13456 parallel
= strcmp (p
, "parallel") == 0;
13457 if (parallel
|| simd
)
13459 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13460 if (cclauses
== NULL
)
13461 cclauses
= cclauses_buf
;
13462 c_parser_consume_token (parser
);
13463 if (!flag_openmp
) /* flag_openmp_simd */
13466 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13468 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
13471 block
= c_begin_compound_stmt (true);
13473 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13475 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
13476 block
= c_end_compound_stmt (loc
, block
, true);
13479 ret
= make_node (OMP_DISTRIBUTE
);
13480 TREE_TYPE (ret
) = void_type_node
;
13481 OMP_FOR_BODY (ret
) = block
;
13482 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13483 SET_EXPR_LOCATION (ret
, loc
);
13488 if (!flag_openmp
) /* flag_openmp_simd */
13490 c_parser_skip_to_pragma_eol (parser
);
13494 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13497 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
13498 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13501 block
= c_begin_compound_stmt (true);
13502 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
13503 block
= c_end_compound_stmt (loc
, block
, true);
13510 # pragma omp teams teams-clause[optseq] new-line
13511 structured-block */
13513 #define OMP_TEAMS_CLAUSE_MASK \
13514 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13515 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13518 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13519 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13520 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13523 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
13524 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13526 tree clauses
, block
, ret
;
13528 strcat (p_name
, " teams");
13529 mask
|= OMP_TEAMS_CLAUSE_MASK
;
13531 if (c_parser_next_token_is (parser
, CPP_NAME
))
13533 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13534 if (strcmp (p
, "distribute") == 0)
13536 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13537 if (cclauses
== NULL
)
13538 cclauses
= cclauses_buf
;
13540 c_parser_consume_token (parser
);
13541 if (!flag_openmp
) /* flag_openmp_simd */
13542 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13543 block
= c_begin_compound_stmt (true);
13544 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13545 block
= c_end_compound_stmt (loc
, block
, true);
13548 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13549 ret
= make_node (OMP_TEAMS
);
13550 TREE_TYPE (ret
) = void_type_node
;
13551 OMP_TEAMS_CLAUSES (ret
) = clauses
;
13552 OMP_TEAMS_BODY (ret
) = block
;
13553 return add_stmt (ret
);
13556 if (!flag_openmp
) /* flag_openmp_simd */
13558 c_parser_skip_to_pragma_eol (parser
);
13562 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13565 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
13566 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13569 tree stmt
= make_node (OMP_TEAMS
);
13570 TREE_TYPE (stmt
) = void_type_node
;
13571 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
13572 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13574 return add_stmt (stmt
);
13578 # pragma omp target data target-data-clause[optseq] new-line
13579 structured-block */
13581 #define OMP_TARGET_DATA_CLAUSE_MASK \
13582 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13587 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
13589 tree stmt
= make_node (OMP_TARGET_DATA
);
13590 TREE_TYPE (stmt
) = void_type_node
;
13592 OMP_TARGET_DATA_CLAUSES (stmt
)
13593 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
13594 "#pragma omp target data");
13595 keep_next_level ();
13596 tree block
= c_begin_compound_stmt (true);
13597 add_stmt (c_parser_omp_structured_block (parser
));
13598 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13600 SET_EXPR_LOCATION (stmt
, loc
);
13601 return add_stmt (stmt
);
13605 # pragma omp target update target-update-clause[optseq] new-line */
13607 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13608 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13609 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13610 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13611 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13614 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
13615 enum pragma_context context
)
13617 if (context
== pragma_stmt
)
13620 "%<#pragma omp target update%> may only be "
13621 "used in compound statements");
13622 c_parser_skip_to_pragma_eol (parser
);
13627 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
13628 "#pragma omp target update");
13629 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
13630 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
13633 "%<#pragma omp target update must contain at least one "
13634 "%<from%> or %<to%> clauses");
13638 tree stmt
= make_node (OMP_TARGET_UPDATE
);
13639 TREE_TYPE (stmt
) = void_type_node
;
13640 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
13641 SET_EXPR_LOCATION (stmt
, loc
);
13647 # pragma omp target target-clause[optseq] new-line
13648 structured-block */
13650 #define OMP_TARGET_CLAUSE_MASK \
13651 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13652 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13653 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13656 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
13658 location_t loc
= c_parser_peek_token (parser
)->location
;
13659 c_parser_consume_pragma (parser
);
13661 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
13663 c_parser_error (parser
, "expected declaration specifiers");
13664 c_parser_skip_to_pragma_eol (parser
);
13668 if (c_parser_next_token_is (parser
, CPP_NAME
))
13670 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13672 if (strcmp (p
, "teams") == 0)
13674 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
13675 char p_name
[sizeof ("#pragma omp target teams distribute "
13676 "parallel for simd")];
13678 c_parser_consume_token (parser
);
13679 strcpy (p_name
, "#pragma omp target");
13680 if (!flag_openmp
) /* flag_openmp_simd */
13682 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
13683 OMP_TARGET_CLAUSE_MASK
,
13685 return stmt
!= NULL_TREE
;
13687 keep_next_level ();
13688 tree block
= c_begin_compound_stmt (true);
13689 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
13690 OMP_TARGET_CLAUSE_MASK
, cclauses
);
13691 block
= c_end_compound_stmt (loc
, block
, true);
13692 if (ret
== NULL_TREE
)
13694 tree stmt
= make_node (OMP_TARGET
);
13695 TREE_TYPE (stmt
) = void_type_node
;
13696 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
13697 OMP_TARGET_BODY (stmt
) = block
;
13701 else if (!flag_openmp
) /* flag_openmp_simd */
13703 c_parser_skip_to_pragma_eol (parser
);
13706 else if (strcmp (p
, "data") == 0)
13708 c_parser_consume_token (parser
);
13709 c_parser_omp_target_data (loc
, parser
);
13712 else if (strcmp (p
, "update") == 0)
13714 c_parser_consume_token (parser
);
13715 return c_parser_omp_target_update (loc
, parser
, context
);
13719 tree stmt
= make_node (OMP_TARGET
);
13720 TREE_TYPE (stmt
) = void_type_node
;
13722 OMP_TARGET_CLAUSES (stmt
)
13723 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
13724 "#pragma omp target");
13725 keep_next_level ();
13726 tree block
= c_begin_compound_stmt (true);
13727 add_stmt (c_parser_omp_structured_block (parser
));
13728 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13730 SET_EXPR_LOCATION (stmt
, loc
);
13736 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
13738 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
13739 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
13740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13741 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
13743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
13744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
13747 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
13749 vec
<c_token
> clauses
= vNULL
;
13750 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13752 c_token
*token
= c_parser_peek_token (parser
);
13753 if (token
->type
== CPP_EOF
)
13755 c_parser_skip_to_pragma_eol (parser
);
13756 clauses
.release ();
13759 clauses
.safe_push (*token
);
13760 c_parser_consume_token (parser
);
13762 clauses
.safe_push (*c_parser_peek_token (parser
));
13763 c_parser_skip_to_pragma_eol (parser
);
13765 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
13767 if (c_parser_peek_token (parser
)->pragma_kind
13768 != PRAGMA_OMP_DECLARE_REDUCTION
13769 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
13770 || strcmp (IDENTIFIER_POINTER
13771 (c_parser_peek_2nd_token (parser
)->value
),
13774 c_parser_error (parser
,
13775 "%<#pragma omp declare simd%> must be followed by "
13776 "function declaration or definition or another "
13777 "%<#pragma omp declare simd%>");
13778 clauses
.release ();
13781 c_parser_consume_pragma (parser
);
13782 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13784 c_token
*token
= c_parser_peek_token (parser
);
13785 if (token
->type
== CPP_EOF
)
13787 c_parser_skip_to_pragma_eol (parser
);
13788 clauses
.release ();
13791 clauses
.safe_push (*token
);
13792 c_parser_consume_token (parser
);
13794 clauses
.safe_push (*c_parser_peek_token (parser
));
13795 c_parser_skip_to_pragma_eol (parser
);
13798 /* Make sure nothing tries to read past the end of the tokens. */
13800 memset (&eof_token
, 0, sizeof (eof_token
));
13801 eof_token
.type
= CPP_EOF
;
13802 clauses
.safe_push (eof_token
);
13803 clauses
.safe_push (eof_token
);
13807 case pragma_external
:
13808 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13809 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
13811 int ext
= disable_extension_diagnostics ();
13813 c_parser_consume_token (parser
);
13814 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13815 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
13816 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13818 restore_extension_diagnostics (ext
);
13821 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13824 case pragma_struct
:
13826 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13827 "function declaration or definition");
13829 case pragma_compound
:
13831 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13832 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
13834 int ext
= disable_extension_diagnostics ();
13836 c_parser_consume_token (parser
);
13837 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13838 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
13839 if (c_parser_next_tokens_start_declaration (parser
))
13841 c_parser_declaration_or_fndef (parser
, true, true, true, true,
13842 true, NULL
, clauses
);
13843 restore_extension_diagnostics (ext
);
13846 restore_extension_diagnostics (ext
);
13848 else if (c_parser_next_tokens_start_declaration (parser
))
13850 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
13854 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13855 "function declaration or definition");
13858 gcc_unreachable ();
13860 clauses
.release ();
13863 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
13864 and put that into "omp declare simd" attribute. */
13867 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
13868 vec
<c_token
> clauses
)
13871 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13873 error ("%<#pragma omp declare simd%> cannot be used in the same "
13874 "function marked as a Cilk Plus SIMD-enabled function");
13875 vec_free (parser
->cilk_simd_fn_tokens
);
13879 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
13880 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
13881 has already processed the tokens. */
13882 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
13884 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
13886 error ("%<#pragma omp declare simd%> not immediately followed by "
13887 "a function declaration or definition");
13888 clauses
[0].type
= CPP_EOF
;
13891 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
13893 error_at (DECL_SOURCE_LOCATION (fndecl
),
13894 "%<#pragma omp declare simd%> not immediately followed by "
13895 "a single function declaration or definition");
13896 clauses
[0].type
= CPP_EOF
;
13900 if (parms
== NULL_TREE
)
13901 parms
= DECL_ARGUMENTS (fndecl
);
13903 unsigned int tokens_avail
= parser
->tokens_avail
;
13904 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13905 bool is_cilkplus_cilk_simd_fn
= false;
13907 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13909 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
13910 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
13911 is_cilkplus_cilk_simd_fn
= true;
13915 parser
->tokens
= clauses
.address ();
13916 parser
->tokens_avail
= clauses
.length ();
13919 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
13920 while (parser
->tokens_avail
> 3)
13922 c_token
*token
= c_parser_peek_token (parser
);
13923 if (!is_cilkplus_cilk_simd_fn
)
13924 gcc_assert (token
->type
== CPP_NAME
13925 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
13927 gcc_assert (token
->type
== CPP_NAME
13928 && is_cilkplus_vector_p (token
->value
));
13929 c_parser_consume_token (parser
);
13930 parser
->in_pragma
= true;
13932 tree c
= NULL_TREE
;
13933 if (is_cilkplus_cilk_simd_fn
)
13934 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
13935 "SIMD-enabled functions attribute");
13937 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
13938 "#pragma omp declare simd");
13939 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
13940 if (c
!= NULL_TREE
)
13941 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
13942 if (is_cilkplus_cilk_simd_fn
)
13944 tree k
= build_tree_list (get_identifier ("cilk simd function"),
13946 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
13947 DECL_ATTRIBUTES (fndecl
) = k
;
13949 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
13950 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
13951 DECL_ATTRIBUTES (fndecl
) = c
;
13954 parser
->tokens
= &parser
->tokens_buf
[0];
13955 parser
->tokens_avail
= tokens_avail
;
13956 if (clauses
.exists ())
13957 clauses
[0].type
= CPP_PRAGMA
;
13959 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13960 vec_free (parser
->cilk_simd_fn_tokens
);
13965 # pragma omp declare target new-line
13966 declarations and definitions
13967 # pragma omp end declare target new-line */
13970 c_parser_omp_declare_target (c_parser
*parser
)
13972 c_parser_skip_to_pragma_eol (parser
);
13973 current_omp_declare_target_attribute
++;
13977 c_parser_omp_end_declare_target (c_parser
*parser
)
13979 location_t loc
= c_parser_peek_token (parser
)->location
;
13980 c_parser_consume_pragma (parser
);
13981 if (c_parser_next_token_is (parser
, CPP_NAME
)
13982 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13985 c_parser_consume_token (parser
);
13986 if (c_parser_next_token_is (parser
, CPP_NAME
)
13987 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13989 c_parser_consume_token (parser
);
13992 c_parser_error (parser
, "expected %<target%>");
13993 c_parser_skip_to_pragma_eol (parser
);
13999 c_parser_error (parser
, "expected %<declare%>");
14000 c_parser_skip_to_pragma_eol (parser
);
14003 c_parser_skip_to_pragma_eol (parser
);
14004 if (!current_omp_declare_target_attribute
)
14005 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
14006 "%<#pragma omp declare target%>");
14008 current_omp_declare_target_attribute
--;
14013 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14014 initializer-clause[opt] new-line
14016 initializer-clause:
14017 initializer (omp_priv = initializer)
14018 initializer (function-name (argument-list)) */
14021 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
14023 unsigned int tokens_avail
= 0, i
;
14024 vec
<tree
> types
= vNULL
;
14025 vec
<c_token
> clauses
= vNULL
;
14026 enum tree_code reduc_code
= ERROR_MARK
;
14027 tree reduc_id
= NULL_TREE
;
14029 location_t rloc
= c_parser_peek_token (parser
)->location
;
14031 if (context
== pragma_struct
|| context
== pragma_param
)
14033 error ("%<#pragma omp declare reduction%> not at file or block scope");
14037 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14040 switch (c_parser_peek_token (parser
)->type
)
14043 reduc_code
= PLUS_EXPR
;
14046 reduc_code
= MULT_EXPR
;
14049 reduc_code
= MINUS_EXPR
;
14052 reduc_code
= BIT_AND_EXPR
;
14055 reduc_code
= BIT_XOR_EXPR
;
14058 reduc_code
= BIT_IOR_EXPR
;
14061 reduc_code
= TRUTH_ANDIF_EXPR
;
14064 reduc_code
= TRUTH_ORIF_EXPR
;
14068 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14069 if (strcmp (p
, "min") == 0)
14071 reduc_code
= MIN_EXPR
;
14074 if (strcmp (p
, "max") == 0)
14076 reduc_code
= MAX_EXPR
;
14079 reduc_id
= c_parser_peek_token (parser
)->value
;
14082 c_parser_error (parser
,
14083 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14084 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14088 tree orig_reduc_id
, reduc_decl
;
14089 orig_reduc_id
= reduc_id
;
14090 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
14091 reduc_decl
= c_omp_reduction_decl (reduc_id
);
14092 c_parser_consume_token (parser
);
14094 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14099 location_t loc
= c_parser_peek_token (parser
)->location
;
14100 struct c_type_name
*ctype
= c_parser_type_name (parser
);
14103 type
= groktypename (ctype
, NULL
, NULL
);
14104 if (type
== error_mark_node
)
14106 else if ((INTEGRAL_TYPE_P (type
)
14107 || TREE_CODE (type
) == REAL_TYPE
14108 || TREE_CODE (type
) == COMPLEX_TYPE
)
14109 && orig_reduc_id
== NULL_TREE
)
14110 error_at (loc
, "predeclared arithmetic type in "
14111 "%<#pragma omp declare reduction%>");
14112 else if (TREE_CODE (type
) == FUNCTION_TYPE
14113 || TREE_CODE (type
) == ARRAY_TYPE
)
14114 error_at (loc
, "function or array type in "
14115 "%<#pragma omp declare reduction%>");
14116 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
14117 error_at (loc
, "const, volatile or restrict qualified type in "
14118 "%<#pragma omp declare reduction%>");
14122 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
14123 if (comptypes (TREE_PURPOSE (t
), type
))
14125 error_at (loc
, "redeclaration of %qs "
14126 "%<#pragma omp declare reduction%> for "
14128 IDENTIFIER_POINTER (reduc_id
)
14129 + sizeof ("omp declare reduction ") - 1,
14132 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
14134 error_at (ploc
, "previous %<#pragma omp declare "
14138 if (t
== NULL_TREE
)
14139 types
.safe_push (type
);
14141 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14142 c_parser_consume_token (parser
);
14150 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
14151 || types
.is_empty ())
14154 clauses
.release ();
14158 c_token
*token
= c_parser_peek_token (parser
);
14159 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
14161 c_parser_consume_token (parser
);
14163 c_parser_skip_to_pragma_eol (parser
);
14167 if (types
.length () > 1)
14169 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14171 c_token
*token
= c_parser_peek_token (parser
);
14172 if (token
->type
== CPP_EOF
)
14174 clauses
.safe_push (*token
);
14175 c_parser_consume_token (parser
);
14177 clauses
.safe_push (*c_parser_peek_token (parser
));
14178 c_parser_skip_to_pragma_eol (parser
);
14180 /* Make sure nothing tries to read past the end of the tokens. */
14182 memset (&eof_token
, 0, sizeof (eof_token
));
14183 eof_token
.type
= CPP_EOF
;
14184 clauses
.safe_push (eof_token
);
14185 clauses
.safe_push (eof_token
);
14188 int errs
= errorcount
;
14189 FOR_EACH_VEC_ELT (types
, i
, type
)
14191 tokens_avail
= parser
->tokens_avail
;
14192 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14193 if (!clauses
.is_empty ())
14195 parser
->tokens
= clauses
.address ();
14196 parser
->tokens_avail
= clauses
.length ();
14197 parser
->in_pragma
= true;
14200 bool nested
= current_function_decl
!= NULL_TREE
;
14202 c_push_function_context ();
14203 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
14204 reduc_id
, default_function_type
);
14205 current_function_decl
= fndecl
;
14206 allocate_struct_function (fndecl
, true);
14208 tree stmt
= push_stmt_list ();
14209 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14210 warn about these. */
14211 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14212 get_identifier ("omp_out"), type
);
14213 DECL_ARTIFICIAL (omp_out
) = 1;
14214 DECL_CONTEXT (omp_out
) = fndecl
;
14215 pushdecl (omp_out
);
14216 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14217 get_identifier ("omp_in"), type
);
14218 DECL_ARTIFICIAL (omp_in
) = 1;
14219 DECL_CONTEXT (omp_in
) = fndecl
;
14221 struct c_expr combiner
= c_parser_expression (parser
);
14222 struct c_expr initializer
;
14223 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
14225 initializer
.value
= error_mark_node
;
14226 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14228 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14229 && strcmp (IDENTIFIER_POINTER
14230 (c_parser_peek_token (parser
)->value
),
14231 "initializer") == 0)
14233 c_parser_consume_token (parser
);
14236 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14237 get_identifier ("omp_priv"), type
);
14238 DECL_ARTIFICIAL (omp_priv
) = 1;
14239 DECL_INITIAL (omp_priv
) = error_mark_node
;
14240 DECL_CONTEXT (omp_priv
) = fndecl
;
14241 pushdecl (omp_priv
);
14242 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14243 get_identifier ("omp_orig"), type
);
14244 DECL_ARTIFICIAL (omp_orig
) = 1;
14245 DECL_CONTEXT (omp_orig
) = fndecl
;
14246 pushdecl (omp_orig
);
14247 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14249 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
14251 c_parser_error (parser
, "expected %<omp_priv%> or "
14255 else if (strcmp (IDENTIFIER_POINTER
14256 (c_parser_peek_token (parser
)->value
),
14259 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
14260 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14262 c_parser_error (parser
, "expected function-name %<(%>");
14266 initializer
= c_parser_postfix_expression (parser
);
14267 if (initializer
.value
14268 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
14271 tree c
= initializer
.value
;
14272 for (j
= 0; j
< call_expr_nargs (c
); j
++)
14273 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
14274 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
14276 if (j
== call_expr_nargs (c
))
14277 error ("one of the initializer call arguments should be "
14283 c_parser_consume_token (parser
);
14284 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14288 tree st
= push_stmt_list ();
14289 start_init (omp_priv
, NULL_TREE
, 0);
14290 location_t loc
= c_parser_peek_token (parser
)->location
;
14291 struct c_expr init
= c_parser_initializer (parser
);
14293 finish_decl (omp_priv
, loc
, init
.value
,
14294 init
.original_type
, NULL_TREE
);
14295 pop_stmt_list (st
);
14299 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14305 c_parser_skip_to_pragma_eol (parser
);
14307 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
14308 DECL_INITIAL (reduc_decl
));
14309 DECL_INITIAL (reduc_decl
) = t
;
14310 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
14311 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
14312 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
14313 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
14314 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
14315 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
14318 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
14319 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
14320 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
14321 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
14322 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
14323 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14324 walk_tree (&DECL_INITIAL (omp_priv
),
14325 c_check_omp_declare_reduction_r
,
14326 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14330 pop_stmt_list (stmt
);
14332 if (cfun
->language
!= NULL
)
14334 ggc_free (cfun
->language
);
14335 cfun
->language
= NULL
;
14338 current_function_decl
= NULL_TREE
;
14340 c_pop_function_context ();
14342 if (!clauses
.is_empty ())
14344 parser
->tokens
= &parser
->tokens_buf
[0];
14345 parser
->tokens_avail
= tokens_avail
;
14349 if (errs
!= errorcount
)
14353 clauses
.release ();
14359 #pragma omp declare simd declare-simd-clauses[optseq] new-line
14360 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14361 initializer-clause[opt] new-line
14362 #pragma omp declare target new-line */
14365 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
14367 c_parser_consume_pragma (parser
);
14368 if (c_parser_next_token_is (parser
, CPP_NAME
))
14370 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14371 if (strcmp (p
, "simd") == 0)
14373 /* c_parser_consume_token (parser); done in
14374 c_parser_omp_declare_simd. */
14375 c_parser_omp_declare_simd (parser
, context
);
14378 if (strcmp (p
, "reduction") == 0)
14380 c_parser_consume_token (parser
);
14381 c_parser_omp_declare_reduction (parser
, context
);
14384 if (!flag_openmp
) /* flag_openmp_simd */
14386 c_parser_skip_to_pragma_eol (parser
);
14389 if (strcmp (p
, "target") == 0)
14391 c_parser_consume_token (parser
);
14392 c_parser_omp_declare_target (parser
);
14397 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
14399 c_parser_skip_to_pragma_eol (parser
);
14402 /* Main entry point to parsing most OpenMP pragmas. */
14405 c_parser_omp_construct (c_parser
*parser
)
14407 enum pragma_kind p_kind
;
14410 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
14411 omp_clause_mask
mask (0);
14413 loc
= c_parser_peek_token (parser
)->location
;
14414 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
14415 c_parser_consume_pragma (parser
);
14419 case PRAGMA_OACC_DATA
:
14420 stmt
= c_parser_oacc_data (loc
, parser
);
14422 case PRAGMA_OACC_KERNELS
:
14423 strcpy (p_name
, "#pragma acc");
14424 stmt
= c_parser_oacc_kernels (loc
, parser
, p_name
);
14426 case PRAGMA_OACC_LOOP
:
14427 strcpy (p_name
, "#pragma acc");
14428 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
);
14430 case PRAGMA_OACC_PARALLEL
:
14431 strcpy (p_name
, "#pragma acc");
14432 stmt
= c_parser_oacc_parallel (loc
, parser
, p_name
);
14434 case PRAGMA_OACC_WAIT
:
14435 strcpy (p_name
, "#pragma wait");
14436 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
14438 case PRAGMA_OMP_ATOMIC
:
14439 c_parser_omp_atomic (loc
, parser
);
14441 case PRAGMA_OMP_CRITICAL
:
14442 stmt
= c_parser_omp_critical (loc
, parser
);
14444 case PRAGMA_OMP_DISTRIBUTE
:
14445 strcpy (p_name
, "#pragma omp");
14446 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
14448 case PRAGMA_OMP_FOR
:
14449 strcpy (p_name
, "#pragma omp");
14450 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
14452 case PRAGMA_OMP_MASTER
:
14453 stmt
= c_parser_omp_master (loc
, parser
);
14455 case PRAGMA_OMP_ORDERED
:
14456 stmt
= c_parser_omp_ordered (loc
, parser
);
14458 case PRAGMA_OMP_PARALLEL
:
14459 strcpy (p_name
, "#pragma omp");
14460 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
14462 case PRAGMA_OMP_SECTIONS
:
14463 strcpy (p_name
, "#pragma omp");
14464 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
14466 case PRAGMA_OMP_SIMD
:
14467 strcpy (p_name
, "#pragma omp");
14468 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
14470 case PRAGMA_OMP_SINGLE
:
14471 stmt
= c_parser_omp_single (loc
, parser
);
14473 case PRAGMA_OMP_TASK
:
14474 stmt
= c_parser_omp_task (loc
, parser
);
14476 case PRAGMA_OMP_TASKGROUP
:
14477 stmt
= c_parser_omp_taskgroup (parser
);
14479 case PRAGMA_OMP_TEAMS
:
14480 strcpy (p_name
, "#pragma omp");
14481 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
14484 gcc_unreachable ();
14488 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
14493 # pragma omp threadprivate (variable-list) */
14496 c_parser_omp_threadprivate (c_parser
*parser
)
14501 c_parser_consume_pragma (parser
);
14502 loc
= c_parser_peek_token (parser
)->location
;
14503 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14505 /* Mark every variable in VARS to be assigned thread local storage. */
14506 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
14508 tree v
= TREE_PURPOSE (t
);
14510 /* FIXME diagnostics: Ideally we should keep individual
14511 locations for all the variables in the var list to make the
14512 following errors more precise. Perhaps
14513 c_parser_omp_var_list_parens() should construct a list of
14514 locations to go along with the var list. */
14516 /* If V had already been marked threadprivate, it doesn't matter
14517 whether it had been used prior to this point. */
14518 if (TREE_CODE (v
) != VAR_DECL
)
14519 error_at (loc
, "%qD is not a variable", v
);
14520 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
14521 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
14522 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
14523 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
14524 else if (TREE_TYPE (v
) == error_mark_node
)
14526 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
14527 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
14530 if (! DECL_THREAD_LOCAL_P (v
))
14532 set_decl_tls_model (v
, decl_default_tls_model (v
));
14533 /* If rtl has been already set for this var, call
14534 make_decl_rtl once again, so that encode_section_info
14535 has a chance to look at the new decl flags. */
14536 if (DECL_RTL_SET_P (v
))
14539 C_DECL_THREADPRIVATE_P (v
) = 1;
14543 c_parser_skip_to_pragma_eol (parser
);
14546 /* Cilk Plus <#pragma simd> parsing routines. */
14548 /* Helper function for c_parser_pragma. Perform some sanity checking
14549 for <#pragma simd> constructs. Returns FALSE if there was a
14553 c_parser_cilk_verify_simd (c_parser
*parser
,
14554 enum pragma_context context
)
14556 if (!flag_cilkplus
)
14558 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14559 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14562 if (context
== pragma_external
)
14564 c_parser_error (parser
,"pragma simd must be inside a function");
14565 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14572 This function is shared by SIMD-enabled functions and #pragma simd.
14573 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14574 CLAUSES is unused. The main purpose of this function is to parse a
14575 vectorlength attribute or clause and check for parse errors.
14576 When IS_SIMD_FN is true then the function is merely caching the tokens
14577 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14578 cache is cleared since there is no reason to continue.
14580 vectorlength ( constant-expression ) */
14583 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
14587 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
14589 /* The vectorlength clause behaves exactly like OpenMP's safelen
14590 clause. Represent it in OpenMP terms. */
14591 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
14593 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14596 location_t loc
= c_parser_peek_token (parser
)->location
;
14597 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14598 expr
= c_fully_fold (expr
, false, NULL
);
14600 /* If expr is an error_mark_node then the above function would have
14601 emitted an error. No reason to do it twice. */
14602 if (expr
== error_mark_node
)
14604 else if (!TREE_TYPE (expr
)
14605 || !TREE_CONSTANT (expr
)
14606 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
14608 error_at (loc
, "vectorlength must be an integer constant");
14609 else if (wi::exact_log2 (expr
) == -1)
14610 error_at (loc
, "vectorlength must be a power of 2");
14615 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
14616 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
14617 OMP_CLAUSE_CHAIN (u
) = clauses
;
14622 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
14623 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
14624 OMP_CLAUSE_CHAIN (u
) = clauses
;
14629 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14635 linear ( simd-linear-variable-list )
14637 simd-linear-variable-list:
14638 simd-linear-variable
14639 simd-linear-variable-list , simd-linear-variable
14641 simd-linear-variable:
14643 id-expression : simd-linear-step
14646 conditional-expression */
14649 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
14651 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14654 location_t loc
= c_parser_peek_token (parser
)->location
;
14656 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14657 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14658 c_parser_error (parser
, "expected identifier");
14660 while (c_parser_next_token_is (parser
, CPP_NAME
)
14661 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14663 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
14667 undeclared_variable (c_parser_peek_token (parser
)->location
,
14668 c_parser_peek_token (parser
)->value
);
14669 c_parser_consume_token (parser
);
14671 else if (var
== error_mark_node
)
14672 c_parser_consume_token (parser
);
14675 tree step
= integer_one_node
;
14677 /* Parse the linear step if present. */
14678 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14680 c_parser_consume_token (parser
);
14681 c_parser_consume_token (parser
);
14683 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14684 expr
= c_fully_fold (expr
, false, NULL
);
14686 if (TREE_TYPE (expr
)
14687 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
14688 && (TREE_CONSTANT (expr
)
14692 c_parser_error (parser
,
14693 "step size must be an integer constant "
14694 "expression or an integer variable");
14697 c_parser_consume_token (parser
);
14699 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
14700 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
14701 OMP_CLAUSE_DECL (u
) = var
;
14702 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
14703 OMP_CLAUSE_CHAIN (u
) = clauses
;
14707 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
14710 c_parser_consume_token (parser
);
14713 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14718 /* Returns the name of the next clause. If the clause is not
14719 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14720 not consumed. Otherwise, the appropriate pragma_simd_clause is
14721 returned and the token is consumed. */
14723 static pragma_omp_clause
14724 c_parser_cilk_clause_name (c_parser
*parser
)
14726 pragma_omp_clause result
;
14727 c_token
*token
= c_parser_peek_token (parser
);
14729 if (!token
->value
|| token
->type
!= CPP_NAME
)
14730 return PRAGMA_CILK_CLAUSE_NONE
;
14732 const char *p
= IDENTIFIER_POINTER (token
->value
);
14734 if (!strcmp (p
, "vectorlength"))
14735 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
14736 else if (!strcmp (p
, "linear"))
14737 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
14738 else if (!strcmp (p
, "private"))
14739 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
14740 else if (!strcmp (p
, "firstprivate"))
14741 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
14742 else if (!strcmp (p
, "lastprivate"))
14743 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
14744 else if (!strcmp (p
, "reduction"))
14745 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
14747 return PRAGMA_CILK_CLAUSE_NONE
;
14749 c_parser_consume_token (parser
);
14753 /* Parse all #<pragma simd> clauses. Return the list of clauses
14757 c_parser_cilk_all_clauses (c_parser
*parser
)
14759 tree clauses
= NULL
;
14761 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14763 pragma_omp_clause c_kind
;
14765 c_kind
= c_parser_cilk_clause_name (parser
);
14769 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
14770 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
14772 case PRAGMA_CILK_CLAUSE_LINEAR
:
14773 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
14775 case PRAGMA_CILK_CLAUSE_PRIVATE
:
14776 /* Use the OpenMP counterpart. */
14777 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14779 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
14780 /* Use the OpenMP counterpart. */
14781 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14783 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
14784 /* Use the OpenMP counterpart. */
14785 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14787 case PRAGMA_CILK_CLAUSE_REDUCTION
:
14788 /* Use the OpenMP counterpart. */
14789 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14792 c_parser_error (parser
, "expected %<#pragma simd%> clause");
14798 c_parser_skip_to_pragma_eol (parser
);
14799 return c_finish_cilk_clauses (clauses
);
14802 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
14803 Here is the correct syntax of this pragma:
14804 #pragma cilk grainsize = <EXP>
14808 c_parser_cilk_grainsize (c_parser
*parser
)
14810 extern tree
convert_to_integer (tree
, tree
);
14812 /* consume the 'grainsize' keyword. */
14813 c_parser_consume_pragma (parser
);
14815 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
14817 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
14818 if (g_expr
.value
== error_mark_node
)
14820 c_parser_skip_to_pragma_eol (parser
);
14823 tree grain
= convert_to_integer (long_integer_type_node
,
14824 c_fully_fold (g_expr
.value
, false,
14826 c_parser_skip_to_pragma_eol (parser
);
14827 c_token
*token
= c_parser_peek_token (parser
);
14828 if (token
&& token
->type
== CPP_KEYWORD
14829 && token
->keyword
== RID_CILK_FOR
)
14831 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
14832 grain
= integer_zero_node
;
14833 c_parser_cilk_for (parser
, grain
);
14836 warning (0, "%<#pragma cilk grainsize%> is not followed by "
14840 c_parser_skip_to_pragma_eol (parser
);
14843 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
14846 c_parser_cilk_simd (c_parser
*parser
)
14848 tree clauses
= c_parser_cilk_all_clauses (parser
);
14849 tree block
= c_begin_compound_stmt (true);
14850 location_t loc
= c_parser_peek_token (parser
)->location
;
14851 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
14852 block
= c_end_compound_stmt (loc
, block
, true);
14856 /* Create an artificial decl with TYPE and emit initialization of it with
14860 c_get_temp_regvar (tree type
, tree init
)
14862 location_t loc
= EXPR_LOCATION (init
);
14863 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
14864 DECL_ARTIFICIAL (decl
) = 1;
14865 DECL_IGNORED_P (decl
) = 1;
14867 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
14872 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
14873 GRAIN is the grain value passed in through pragma or 0. */
14876 c_parser_cilk_for (c_parser
*parser
, tree grain
)
14878 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
14879 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
14880 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
14881 clauses
= c_finish_omp_clauses (clauses
);
14883 tree block
= c_begin_compound_stmt (true);
14884 tree sb
= push_stmt_list ();
14885 location_t loc
= c_parser_peek_token (parser
)->location
;
14886 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
14887 sb
= pop_stmt_list (sb
);
14891 tree omp_par
= make_node (OMP_PARALLEL
);
14892 TREE_TYPE (omp_par
) = void_type_node
;
14893 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
14894 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
14895 TREE_SIDE_EFFECTS (bind
) = 1;
14896 BIND_EXPR_BODY (bind
) = sb
;
14897 OMP_PARALLEL_BODY (omp_par
) = bind
;
14898 if (OMP_FOR_PRE_BODY (omp_for
))
14900 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
14901 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
14903 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
14904 tree decl
= TREE_OPERAND (init
, 0);
14905 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
14906 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
14907 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
14908 if (TREE_CODE (t
) != INTEGER_CST
)
14910 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
14911 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
14912 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
14913 OMP_CLAUSE_CHAIN (c
) = clauses
;
14916 if (TREE_CODE (incr
) == MODIFY_EXPR
)
14918 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
14919 if (TREE_CODE (t
) != INTEGER_CST
)
14921 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
14922 = c_get_temp_regvar (TREE_TYPE (t
), t
);
14923 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
14924 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
14925 OMP_CLAUSE_CHAIN (c
) = clauses
;
14929 t
= TREE_OPERAND (init
, 1);
14930 if (TREE_CODE (t
) != INTEGER_CST
)
14932 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
14933 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
14934 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
14935 OMP_CLAUSE_CHAIN (c
) = clauses
;
14938 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
14939 OMP_CLAUSE_DECL (c
) = decl
;
14940 OMP_CLAUSE_CHAIN (c
) = clauses
;
14942 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
14943 OMP_CLAUSE_OPERAND (c
, 0)
14944 = cilk_for_number_of_iterations (omp_for
);
14945 OMP_CLAUSE_CHAIN (c
) = clauses
;
14946 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
);
14947 add_stmt (omp_par
);
14950 block
= c_end_compound_stmt (loc
, block
, true);
14955 /* Parse a transaction attribute (GCC Extension).
14957 transaction-attribute:
14961 The transactional memory language description is written for C++,
14962 and uses the C++0x attribute syntax. For compatibility, allow the
14963 bracket style for transactions in C as well. */
14966 c_parser_transaction_attributes (c_parser
*parser
)
14968 tree attr_name
, attr
= NULL
;
14970 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
14971 return c_parser_attributes (parser
);
14973 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
14975 c_parser_consume_token (parser
);
14976 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
14979 attr_name
= c_parser_attribute_any_word (parser
);
14982 c_parser_consume_token (parser
);
14983 attr
= build_tree_list (attr_name
, NULL_TREE
);
14986 c_parser_error (parser
, "expected identifier");
14988 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14990 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14994 /* Parse a __transaction_atomic or __transaction_relaxed statement
14997 transaction-statement:
14998 __transaction_atomic transaction-attribute[opt] compound-statement
14999 __transaction_relaxed compound-statement
15001 Note that the only valid attribute is: "outer".
15005 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
15007 unsigned int old_in
= parser
->in_transaction
;
15008 unsigned int this_in
= 1, new_in
;
15009 location_t loc
= c_parser_peek_token (parser
)->location
;
15012 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15013 || keyword
== RID_TRANSACTION_RELAXED
)
15014 && c_parser_next_token_is_keyword (parser
, keyword
));
15015 c_parser_consume_token (parser
);
15017 if (keyword
== RID_TRANSACTION_RELAXED
)
15018 this_in
|= TM_STMT_ATTR_RELAXED
;
15021 attrs
= c_parser_transaction_attributes (parser
);
15023 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
15026 /* Keep track if we're in the lexical scope of an outer transaction. */
15027 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
15029 parser
->in_transaction
= new_in
;
15030 stmt
= c_parser_compound_statement (parser
);
15031 parser
->in_transaction
= old_in
;
15034 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
15036 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15037 "%<__transaction_atomic%> without transactional memory support enabled"
15038 : "%<__transaction_relaxed %> "
15039 "without transactional memory support enabled"));
15044 /* Parse a __transaction_atomic or __transaction_relaxed expression
15047 transaction-expression:
15048 __transaction_atomic ( expression )
15049 __transaction_relaxed ( expression )
15052 static struct c_expr
15053 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
15056 unsigned int old_in
= parser
->in_transaction
;
15057 unsigned int this_in
= 1;
15058 location_t loc
= c_parser_peek_token (parser
)->location
;
15061 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15062 || keyword
== RID_TRANSACTION_RELAXED
)
15063 && c_parser_next_token_is_keyword (parser
, keyword
));
15064 c_parser_consume_token (parser
);
15066 if (keyword
== RID_TRANSACTION_RELAXED
)
15067 this_in
|= TM_STMT_ATTR_RELAXED
;
15070 attrs
= c_parser_transaction_attributes (parser
);
15072 this_in
|= parse_tm_stmt_attr (attrs
, 0);
15075 parser
->in_transaction
= this_in
;
15076 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15078 tree expr
= c_parser_expression (parser
).value
;
15079 ret
.original_type
= TREE_TYPE (expr
);
15080 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
15081 if (this_in
& TM_STMT_ATTR_RELAXED
)
15082 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
15083 SET_EXPR_LOCATION (ret
.value
, loc
);
15084 ret
.original_code
= TRANSACTION_EXPR
;
15085 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15087 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
15094 ret
.value
= error_mark_node
;
15095 ret
.original_code
= ERROR_MARK
;
15096 ret
.original_type
= NULL
;
15098 parser
->in_transaction
= old_in
;
15101 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15102 "%<__transaction_atomic%> without transactional memory support enabled"
15103 : "%<__transaction_relaxed %> "
15104 "without transactional memory support enabled"));
15109 /* Parse a __transaction_cancel statement (GCC Extension).
15111 transaction-cancel-statement:
15112 __transaction_cancel transaction-attribute[opt] ;
15114 Note that the only valid attribute is "outer".
15118 c_parser_transaction_cancel (c_parser
*parser
)
15120 location_t loc
= c_parser_peek_token (parser
)->location
;
15122 bool is_outer
= false;
15124 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
15125 c_parser_consume_token (parser
);
15127 attrs
= c_parser_transaction_attributes (parser
);
15129 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
15133 error_at (loc
, "%<__transaction_cancel%> without "
15134 "transactional memory support enabled");
15137 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
15139 error_at (loc
, "%<__transaction_cancel%> within a "
15140 "%<__transaction_relaxed%>");
15145 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
15146 && !is_tm_may_cancel_outer (current_function_decl
))
15148 error_at (loc
, "outer %<__transaction_cancel%> not "
15149 "within outer %<__transaction_atomic%>");
15150 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
15154 else if (parser
->in_transaction
== 0)
15156 error_at (loc
, "%<__transaction_cancel%> not within "
15157 "%<__transaction_atomic%>");
15161 return add_stmt (build_tm_abort_call (loc
, is_outer
));
15164 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
15167 /* Parse a single source file. */
15170 c_parse_file (void)
15172 /* Use local storage to begin. If the first token is a pragma, parse it.
15173 If it is #pragma GCC pch_preprocess, then this will load a PCH file
15174 which will cause garbage collection. */
15177 memset (&tparser
, 0, sizeof tparser
);
15178 tparser
.tokens
= &tparser
.tokens_buf
[0];
15179 the_parser
= &tparser
;
15181 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
15182 c_parser_pragma_pch_preprocess (&tparser
);
15184 the_parser
= ggc_alloc
<c_parser
> ();
15185 *the_parser
= tparser
;
15186 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
15187 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
15189 /* Initialize EH, if we've been told to do so. */
15190 if (flag_exceptions
)
15191 using_eh_for_cleanups ();
15193 c_parser_translation_unit (the_parser
);
15197 /* This function parses Cilk Plus array notation. The starting index is
15198 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
15199 return value of this function is a tree_node called VALUE_TREE of type
15200 ARRAY_NOTATION_REF. */
15203 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
15206 c_token
*token
= NULL
;
15207 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
15208 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
15209 tree array_type_domain
= NULL_TREE
;
15211 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
15213 /* No need to continue. If either of these 2 were true, then an error
15214 must be emitted already. Thus, no need to emit them twice. */
15215 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15216 return error_mark_node
;
15219 array_type
= TREE_TYPE (array_value
);
15220 gcc_assert (array_type
);
15221 if (TREE_CODE (array_type
) != ARRAY_TYPE
15222 && TREE_CODE (array_type
) != POINTER_TYPE
)
15224 error_at (loc
, "base of array section must be pointer or array type");
15225 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15226 return error_mark_node
;
15228 type
= TREE_TYPE (array_type
);
15229 token
= c_parser_peek_token (parser
);
15231 if (token
->type
== CPP_EOF
)
15233 c_parser_error (parser
, "expected %<:%> or numeral");
15236 else if (token
->type
== CPP_COLON
)
15238 if (!initial_index
)
15240 /* If we are here, then we have a case like this A[:]. */
15241 c_parser_consume_token (parser
);
15242 if (TREE_CODE (array_type
) == POINTER_TYPE
)
15244 error_at (loc
, "start-index and length fields necessary for "
15245 "using array notations in pointers");
15246 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15247 return error_mark_node
;
15249 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15251 error_at (loc
, "array notations cannot be used with function "
15253 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15254 return error_mark_node
;
15256 array_type_domain
= TYPE_DOMAIN (array_type
);
15258 if (!array_type_domain
)
15260 error_at (loc
, "start-index and length fields necessary for "
15261 "using array notations in dimensionless arrays");
15262 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15263 return error_mark_node
;
15266 start_index
= TYPE_MINVAL (array_type_domain
);
15267 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
15269 if (!TYPE_MAXVAL (array_type_domain
)
15270 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
15272 error_at (loc
, "start-index and length fields necessary for "
15273 "using array notations in variable-length arrays");
15274 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15275 return error_mark_node
;
15277 end_index
= TYPE_MAXVAL (array_type_domain
);
15278 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
15279 end_index
, integer_one_node
);
15280 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
15281 stride
= build_int_cst (integer_type_node
, 1);
15282 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
15284 else if (initial_index
!= error_mark_node
)
15286 /* If we are here, then there should be 2 possibilities:
15287 1. Array [EXPR : EXPR]
15288 2. Array [EXPR : EXPR : EXPR]
15290 start_index
= initial_index
;
15292 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15294 error_at (loc
, "array notations cannot be used with function "
15296 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15297 return error_mark_node
;
15299 c_parser_consume_token (parser
); /* consume the ':' */
15300 struct c_expr ce
= c_parser_expression (parser
);
15301 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15302 end_index
= ce
.value
;
15303 if (!end_index
|| end_index
== error_mark_node
)
15305 c_parser_skip_to_end_of_block_or_statement (parser
);
15306 return error_mark_node
;
15308 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
15310 c_parser_consume_token (parser
);
15311 ce
= c_parser_expression (parser
);
15312 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15314 if (!stride
|| stride
== error_mark_node
)
15316 c_parser_skip_to_end_of_block_or_statement (parser
);
15317 return error_mark_node
;
15322 c_parser_error (parser
, "expected array notation expression");
15325 c_parser_error (parser
, "expected array notation expression");
15327 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15329 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
15330 end_index
, stride
, type
);
15331 if (value_tree
!= error_mark_node
)
15332 SET_EXPR_LOCATION (value_tree
, loc
);
15336 #include "gt-c-c-parser.h"