1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
46 #include "fold-const.h"
47 #include "stringpool.h"
49 #include "stor-layout.h"
51 #include "trans-mem.h"
52 #include "langhooks.h"
55 #include "c-family/c-pragma.h"
59 #include "c-family/c-common.h"
60 #include "c-family/c-objc.h"
62 #include "plugin-api.h"
63 #include "hard-reg-set.h"
70 #include "gomp-constants.h"
73 /* Initialization routine for this file. */
78 /* The only initialization required is of the reserved word
84 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
85 the c_token structure. */
86 gcc_assert (RID_MAX
<= 255);
93 mask
|= D_ASM
| D_EXT
;
97 if (!c_dialect_objc ())
98 mask
|= D_OBJC
| D_CXX_OBJC
;
100 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
101 for (i
= 0; i
< num_c_common_reswords
; i
++)
103 /* If a keyword is disabled, do not enter it into the table
104 and so create a canonical spelling that isn't a keyword. */
105 if (c_common_reswords
[i
].disable
& mask
)
108 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
110 id
= get_identifier (c_common_reswords
[i
].word
);
111 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
112 C_IS_RESERVED_WORD (id
) = 1;
117 id
= get_identifier (c_common_reswords
[i
].word
);
118 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
119 C_IS_RESERVED_WORD (id
) = 1;
120 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
123 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
125 /* We always create the symbols but they aren't always supported. */
127 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
128 id
= get_identifier (name
);
129 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
130 C_IS_RESERVED_WORD (id
) = 1;
134 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
135 and the C parser. Unlike the C++ lexer, the parser structure
136 stores the lexer information instead of using a separate structure.
137 Identifiers are separated into ordinary identifiers, type names,
138 keywords and some other Objective-C types of identifiers, and some
139 look-ahead is maintained.
141 ??? It might be a good idea to lex the whole file up front (as for
142 C++). It would then be possible to share more of the C and C++
143 lexer code, if desired. */
145 /* More information about the type of a CPP_NAME token. */
146 typedef enum c_id_kind
{
147 /* An ordinary identifier. */
149 /* An identifier declared as a typedef name. */
151 /* An identifier declared as an Objective-C class name. */
153 /* An address space identifier. */
155 /* Not an identifier. */
159 /* A single C token after string literal concatenation and conversion
160 of preprocessing tokens to tokens. */
161 typedef struct GTY (()) c_token
{
162 /* The kind of token. */
163 ENUM_BITFIELD (cpp_ttype
) type
: 8;
164 /* If this token is a CPP_NAME, this value indicates whether also
165 declared as some kind of type. Otherwise, it is C_ID_NONE. */
166 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
167 /* If this token is a keyword, this value indicates which keyword.
168 Otherwise, this value is RID_MAX. */
169 ENUM_BITFIELD (rid
) keyword
: 8;
170 /* If this token is a CPP_PRAGMA, this indicates the pragma that
171 was seen. Otherwise it is PRAGMA_NONE. */
172 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
173 /* The location at which this token was found. */
175 /* The value associated with this token, if any. */
179 /* A parser structure recording information about the state and
180 context of parsing. Includes lexer information with up to two
181 tokens of look-ahead; more are not needed for C. */
182 typedef struct GTY(()) c_parser
{
183 /* The look-ahead tokens. */
184 c_token
* GTY((skip
)) tokens
;
185 /* Buffer for look-ahead tokens. */
186 c_token tokens_buf
[2];
187 /* How many look-ahead tokens are available (0, 1 or 2, or
188 more if parsing from pre-lexed tokens). */
189 unsigned int tokens_avail
;
190 /* True if a syntax error is being recovered from; false otherwise.
191 c_parser_error sets this flag. It should clear this flag when
192 enough tokens have been consumed to recover from the error. */
193 BOOL_BITFIELD error
: 1;
194 /* True if we're processing a pragma, and shouldn't automatically
195 consume CPP_PRAGMA_EOL. */
196 BOOL_BITFIELD in_pragma
: 1;
197 /* True if we're parsing the outermost block of an if statement. */
198 BOOL_BITFIELD in_if_block
: 1;
199 /* True if we want to lex an untranslated string. */
200 BOOL_BITFIELD lex_untranslated_string
: 1;
202 /* Objective-C specific parser/lexer information. */
204 /* True if we are in a context where the Objective-C "PQ" keywords
205 are considered keywords. */
206 BOOL_BITFIELD objc_pq_context
: 1;
207 /* True if we are parsing a (potential) Objective-C foreach
208 statement. This is set to true after we parsed 'for (' and while
209 we wait for 'in' or ';' to decide if it's a standard C for loop or an
210 Objective-C foreach loop. */
211 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
212 /* The following flag is needed to contextualize Objective-C lexical
213 analysis. In some cases (e.g., 'int NSObject;'), it is
214 undesirable to bind an identifier to an Objective-C class, even
215 if a class with that name exists. */
216 BOOL_BITFIELD objc_need_raw_identifier
: 1;
217 /* Nonzero if we're processing a __transaction statement. The value
218 is 1 | TM_STMT_ATTR_*. */
219 unsigned int in_transaction
: 4;
220 /* True if we are in a context where the Objective-C "Property attribute"
221 keywords are valid. */
222 BOOL_BITFIELD objc_property_attr_context
: 1;
224 /* Cilk Plus specific parser/lexer information. */
226 /* Buffer to hold all the tokens from parsing the vector attribute for the
227 SIMD-enabled functions (formerly known as elemental functions). */
228 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
232 /* The actual parser and external interface. ??? Does this need to be
233 garbage-collected? */
235 static GTY (()) c_parser
*the_parser
;
237 /* Read in and lex a single token, storing it in *TOKEN. */
240 c_lex_one_token (c_parser
*parser
, c_token
*token
)
242 timevar_push (TV_LEX
);
244 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
245 (parser
->lex_untranslated_string
246 ? C_LEX_STRING_NO_TRANSLATE
: 0));
247 token
->id_kind
= C_ID_NONE
;
248 token
->keyword
= RID_MAX
;
249 token
->pragma_kind
= PRAGMA_NONE
;
257 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
258 if (c_dialect_objc ())
259 parser
->objc_need_raw_identifier
= false;
261 if (C_IS_RESERVED_WORD (token
->value
))
263 enum rid rid_code
= C_RID_CODE (token
->value
);
265 if (rid_code
== RID_CXX_COMPAT_WARN
)
267 warning_at (token
->location
,
269 "identifier %qE conflicts with C++ keyword",
272 else if (rid_code
>= RID_FIRST_ADDR_SPACE
273 && rid_code
<= RID_LAST_ADDR_SPACE
)
275 token
->id_kind
= C_ID_ADDRSPACE
;
276 token
->keyword
= rid_code
;
279 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
281 /* We found an Objective-C "pq" keyword (in, out,
282 inout, bycopy, byref, oneway). They need special
283 care because the interpretation depends on the
285 if (parser
->objc_pq_context
)
287 token
->type
= CPP_KEYWORD
;
288 token
->keyword
= rid_code
;
291 else if (parser
->objc_could_be_foreach_context
292 && rid_code
== RID_IN
)
294 /* We are in Objective-C, inside a (potential)
295 foreach context (which means after having
296 parsed 'for (', but before having parsed ';'),
297 and we found 'in'. We consider it the keyword
298 which terminates the declaration at the
299 beginning of a foreach-statement. Note that
300 this means you can't use 'in' for anything else
301 in that context; in particular, in Objective-C
302 you can't use 'in' as the name of the running
303 variable in a C for loop. We could potentially
304 try to add code here to disambiguate, but it
305 seems a reasonable limitation. */
306 token
->type
= CPP_KEYWORD
;
307 token
->keyword
= rid_code
;
310 /* Else, "pq" keywords outside of the "pq" context are
311 not keywords, and we fall through to the code for
314 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
316 /* We found an Objective-C "property attribute"
317 keyword (getter, setter, readonly, etc). These are
318 only valid in the property context. */
319 if (parser
->objc_property_attr_context
)
321 token
->type
= CPP_KEYWORD
;
322 token
->keyword
= rid_code
;
325 /* Else they are not special keywords.
328 else if (c_dialect_objc ()
329 && (OBJC_IS_AT_KEYWORD (rid_code
)
330 || OBJC_IS_CXX_KEYWORD (rid_code
)))
332 /* We found one of the Objective-C "@" keywords (defs,
333 selector, synchronized, etc) or one of the
334 Objective-C "cxx" keywords (class, private,
335 protected, public, try, catch, throw) without a
336 preceding '@' sign. Do nothing and fall through to
337 the code for normal tokens (in C++ we would still
338 consider the CXX ones keywords, but not in C). */
343 token
->type
= CPP_KEYWORD
;
344 token
->keyword
= rid_code
;
349 decl
= lookup_name (token
->value
);
352 if (TREE_CODE (decl
) == TYPE_DECL
)
354 token
->id_kind
= C_ID_TYPENAME
;
358 else if (c_dialect_objc ())
360 tree objc_interface_decl
= objc_is_class_name (token
->value
);
361 /* Objective-C class names are in the same namespace as
362 variables and typedefs, and hence are shadowed by local
364 if (objc_interface_decl
365 && (!objc_force_identifier
|| global_bindings_p ()))
367 token
->value
= objc_interface_decl
;
368 token
->id_kind
= C_ID_CLASSNAME
;
372 token
->id_kind
= C_ID_ID
;
376 /* This only happens in Objective-C; it must be a keyword. */
377 token
->type
= CPP_KEYWORD
;
378 switch (C_RID_CODE (token
->value
))
380 /* Replace 'class' with '@class', 'private' with '@private',
381 etc. This prevents confusion with the C++ keyword
382 'class', and makes the tokens consistent with other
383 Objective-C 'AT' keywords. For example '@class' is
384 reported as RID_AT_CLASS which is consistent with
385 '@synchronized', which is reported as
388 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
389 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
390 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
391 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
392 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
393 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
394 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
395 default: token
->keyword
= C_RID_CODE (token
->value
);
400 case CPP_CLOSE_PAREN
:
402 /* These tokens may affect the interpretation of any identifiers
403 following, if doing Objective-C. */
404 if (c_dialect_objc ())
405 parser
->objc_need_raw_identifier
= false;
408 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
409 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
415 timevar_pop (TV_LEX
);
418 /* Return a pointer to the next token from PARSER, reading it in if
421 static inline c_token
*
422 c_parser_peek_token (c_parser
*parser
)
424 if (parser
->tokens_avail
== 0)
426 c_lex_one_token (parser
, &parser
->tokens
[0]);
427 parser
->tokens_avail
= 1;
429 return &parser
->tokens
[0];
432 /* Return true if the next token from PARSER has the indicated
436 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
438 return c_parser_peek_token (parser
)->type
== type
;
441 /* Return true if the next token from PARSER does not have the
445 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
447 return !c_parser_next_token_is (parser
, type
);
450 /* Return true if the next token from PARSER is the indicated
454 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
456 return c_parser_peek_token (parser
)->keyword
== keyword
;
459 /* Return a pointer to the next-but-one token from PARSER, reading it
460 in if necessary. The next token is already read in. */
463 c_parser_peek_2nd_token (c_parser
*parser
)
465 if (parser
->tokens_avail
>= 2)
466 return &parser
->tokens
[1];
467 gcc_assert (parser
->tokens_avail
== 1);
468 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
469 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
470 c_lex_one_token (parser
, &parser
->tokens
[1]);
471 parser
->tokens_avail
= 2;
472 return &parser
->tokens
[1];
475 /* Return true if TOKEN can start a type name,
478 c_token_starts_typename (c_token
*token
)
483 switch (token
->id_kind
)
492 gcc_assert (c_dialect_objc ());
498 switch (token
->keyword
)
529 if (token
->keyword
>= RID_FIRST_INT_N
530 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
531 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
536 if (c_dialect_objc ())
544 enum c_lookahead_kind
{
545 /* Always treat unknown identifiers as typenames. */
548 /* Could be parsing a nonabstract declarator. Only treat an identifier
549 as a typename if followed by another identifier or a star. */
550 cla_nonabstract_decl
,
552 /* Never treat identifiers as typenames. */
556 /* Return true if the next token from PARSER can start a type name,
557 false otherwise. LA specifies how to do lookahead in order to
558 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
561 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
563 c_token
*token
= c_parser_peek_token (parser
);
564 if (c_token_starts_typename (token
))
567 /* Try a bit harder to detect an unknown typename. */
568 if (la
!= cla_prefer_id
569 && token
->type
== CPP_NAME
570 && token
->id_kind
== C_ID_ID
572 /* Do not try too hard when we could have "object in array". */
573 && !parser
->objc_could_be_foreach_context
575 && (la
== cla_prefer_type
576 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
577 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
579 /* Only unknown identifiers. */
580 && !lookup_name (token
->value
))
586 /* Return true if TOKEN is a type qualifier, false otherwise. */
588 c_token_is_qualifier (c_token
*token
)
593 switch (token
->id_kind
)
601 switch (token
->keyword
)
619 /* Return true if the next token from PARSER is a type qualifier,
622 c_parser_next_token_is_qualifier (c_parser
*parser
)
624 c_token
*token
= c_parser_peek_token (parser
);
625 return c_token_is_qualifier (token
);
628 /* Return true if TOKEN can start declaration specifiers, false
631 c_token_starts_declspecs (c_token
*token
)
636 switch (token
->id_kind
)
645 gcc_assert (c_dialect_objc ());
651 switch (token
->keyword
)
691 if (token
->keyword
>= RID_FIRST_INT_N
692 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
693 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
698 if (c_dialect_objc ())
707 /* Return true if TOKEN can start declaration specifiers or a static
708 assertion, false otherwise. */
710 c_token_starts_declaration (c_token
*token
)
712 if (c_token_starts_declspecs (token
)
713 || token
->keyword
== RID_STATIC_ASSERT
)
719 /* Return true if the next token from PARSER can start declaration
720 specifiers, false otherwise. */
722 c_parser_next_token_starts_declspecs (c_parser
*parser
)
724 c_token
*token
= c_parser_peek_token (parser
);
726 /* In Objective-C, a classname normally starts a declspecs unless it
727 is immediately followed by a dot. In that case, it is the
728 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
729 setter/getter on the class. c_token_starts_declspecs() can't
730 differentiate between the two cases because it only checks the
731 current token, so we have a special check here. */
732 if (c_dialect_objc ()
733 && token
->type
== CPP_NAME
734 && token
->id_kind
== C_ID_CLASSNAME
735 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
738 return c_token_starts_declspecs (token
);
741 /* Return true if the next tokens from PARSER can start declaration
742 specifiers or a static assertion, false otherwise. */
744 c_parser_next_tokens_start_declaration (c_parser
*parser
)
746 c_token
*token
= c_parser_peek_token (parser
);
749 if (c_dialect_objc ()
750 && token
->type
== CPP_NAME
751 && token
->id_kind
== C_ID_CLASSNAME
752 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
755 /* Labels do not start declarations. */
756 if (token
->type
== CPP_NAME
757 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
760 if (c_token_starts_declaration (token
))
763 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
769 /* Consume the next token from PARSER. */
772 c_parser_consume_token (c_parser
*parser
)
774 gcc_assert (parser
->tokens_avail
>= 1);
775 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
776 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
777 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
778 if (parser
->tokens
!= &parser
->tokens_buf
[0])
780 else if (parser
->tokens_avail
== 2)
781 parser
->tokens
[0] = parser
->tokens
[1];
782 parser
->tokens_avail
--;
785 /* Expect the current token to be a #pragma. Consume it and remember
786 that we've begun parsing a pragma. */
789 c_parser_consume_pragma (c_parser
*parser
)
791 gcc_assert (!parser
->in_pragma
);
792 gcc_assert (parser
->tokens_avail
>= 1);
793 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
794 if (parser
->tokens
!= &parser
->tokens_buf
[0])
796 else if (parser
->tokens_avail
== 2)
797 parser
->tokens
[0] = parser
->tokens
[1];
798 parser
->tokens_avail
--;
799 parser
->in_pragma
= true;
802 /* Update the global input_location from TOKEN. */
804 c_parser_set_source_position_from_token (c_token
*token
)
806 if (token
->type
!= CPP_EOF
)
808 input_location
= token
->location
;
812 /* Issue a diagnostic of the form
813 FILE:LINE: MESSAGE before TOKEN
814 where TOKEN is the next token in the input stream of PARSER.
815 MESSAGE (specified by the caller) is usually of the form "expected
818 Do not issue a diagnostic if still recovering from an error.
820 ??? This is taken from the C++ parser, but building up messages in
821 this way is not i18n-friendly and some other approach should be
825 c_parser_error (c_parser
*parser
, const char *gmsgid
)
827 c_token
*token
= c_parser_peek_token (parser
);
830 parser
->error
= true;
833 /* This diagnostic makes more sense if it is tagged to the line of
834 the token we just peeked at. */
835 c_parser_set_source_position_from_token (token
);
836 c_parse_error (gmsgid
,
837 /* Because c_parse_error does not understand
838 CPP_KEYWORD, keywords are treated like
840 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
841 /* ??? The C parser does not save the cpp flags of a
842 token, we need to pass 0 here and we will not get
843 the source spelling of some tokens but rather the
844 canonical spelling. */
845 token
->value
, /*flags=*/0);
848 /* If the next token is of the indicated TYPE, consume it. Otherwise,
849 issue the error MSGID. If MSGID is NULL then a message has already
850 been produced and no message will be produced this time. Returns
851 true if found, false otherwise. */
854 c_parser_require (c_parser
*parser
,
858 if (c_parser_next_token_is (parser
, type
))
860 c_parser_consume_token (parser
);
865 c_parser_error (parser
, msgid
);
870 /* If the next token is the indicated keyword, consume it. Otherwise,
871 issue the error MSGID. Returns true if found, false otherwise. */
874 c_parser_require_keyword (c_parser
*parser
,
878 if (c_parser_next_token_is_keyword (parser
, keyword
))
880 c_parser_consume_token (parser
);
885 c_parser_error (parser
, msgid
);
890 /* Like c_parser_require, except that tokens will be skipped until the
891 desired token is found. An error message is still produced if the
892 next token is not as expected. If MSGID is NULL then a message has
893 already been produced and no message will be produced this
897 c_parser_skip_until_found (c_parser
*parser
,
901 unsigned nesting_depth
= 0;
903 if (c_parser_require (parser
, type
, msgid
))
906 /* Skip tokens until the desired token is found. */
909 /* Peek at the next token. */
910 c_token
*token
= c_parser_peek_token (parser
);
911 /* If we've reached the token we want, consume it and stop. */
912 if (token
->type
== type
&& !nesting_depth
)
914 c_parser_consume_token (parser
);
918 /* If we've run out of tokens, stop. */
919 if (token
->type
== CPP_EOF
)
921 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
923 if (token
->type
== CPP_OPEN_BRACE
924 || token
->type
== CPP_OPEN_PAREN
925 || token
->type
== CPP_OPEN_SQUARE
)
927 else if (token
->type
== CPP_CLOSE_BRACE
928 || token
->type
== CPP_CLOSE_PAREN
929 || token
->type
== CPP_CLOSE_SQUARE
)
931 if (nesting_depth
-- == 0)
934 /* Consume this token. */
935 c_parser_consume_token (parser
);
937 parser
->error
= false;
940 /* Skip tokens until the end of a parameter is found, but do not
941 consume the comma, semicolon or closing delimiter. */
944 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
946 unsigned nesting_depth
= 0;
950 c_token
*token
= c_parser_peek_token (parser
);
951 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
954 /* If we've run out of tokens, stop. */
955 if (token
->type
== CPP_EOF
)
957 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
959 if (token
->type
== CPP_OPEN_BRACE
960 || token
->type
== CPP_OPEN_PAREN
961 || token
->type
== CPP_OPEN_SQUARE
)
963 else if (token
->type
== CPP_CLOSE_BRACE
964 || token
->type
== CPP_CLOSE_PAREN
965 || token
->type
== CPP_CLOSE_SQUARE
)
967 if (nesting_depth
-- == 0)
970 /* Consume this token. */
971 c_parser_consume_token (parser
);
973 parser
->error
= false;
976 /* Expect to be at the end of the pragma directive and consume an
977 end of line marker. */
980 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
982 gcc_assert (parser
->in_pragma
);
983 parser
->in_pragma
= false;
985 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
986 c_parser_error (parser
, "expected end of line");
988 cpp_ttype token_type
;
991 c_token
*token
= c_parser_peek_token (parser
);
992 token_type
= token
->type
;
993 if (token_type
== CPP_EOF
)
995 c_parser_consume_token (parser
);
997 while (token_type
!= CPP_PRAGMA_EOL
);
999 parser
->error
= false;
1002 /* Skip tokens until we have consumed an entire block, or until we
1003 have consumed a non-nested ';'. */
1006 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1008 unsigned nesting_depth
= 0;
1009 bool save_error
= parser
->error
;
1015 /* Peek at the next token. */
1016 token
= c_parser_peek_token (parser
);
1018 switch (token
->type
)
1023 case CPP_PRAGMA_EOL
:
1024 if (parser
->in_pragma
)
1029 /* If the next token is a ';', we have reached the
1030 end of the statement. */
1033 /* Consume the ';'. */
1034 c_parser_consume_token (parser
);
1039 case CPP_CLOSE_BRACE
:
1040 /* If the next token is a non-nested '}', then we have
1041 reached the end of the current block. */
1042 if (nesting_depth
== 0 || --nesting_depth
== 0)
1044 c_parser_consume_token (parser
);
1049 case CPP_OPEN_BRACE
:
1050 /* If it the next token is a '{', then we are entering a new
1051 block. Consume the entire block. */
1056 /* If we see a pragma, consume the whole thing at once. We
1057 have some safeguards against consuming pragmas willy-nilly.
1058 Normally, we'd expect to be here with parser->error set,
1059 which disables these safeguards. But it's possible to get
1060 here for secondary error recovery, after parser->error has
1062 c_parser_consume_pragma (parser
);
1063 c_parser_skip_to_pragma_eol (parser
);
1064 parser
->error
= save_error
;
1071 c_parser_consume_token (parser
);
1075 parser
->error
= false;
1078 /* CPP's options (initialized by c-opts.c). */
1079 extern cpp_options
*cpp_opts
;
1081 /* Save the warning flags which are controlled by __extension__. */
1084 disable_extension_diagnostics (void)
1087 | (warn_pointer_arith
<< 1)
1088 | (warn_traditional
<< 2)
1090 | (warn_long_long
<< 4)
1091 | (warn_cxx_compat
<< 5)
1092 | (warn_overlength_strings
<< 6)
1093 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1094 play tricks to properly restore it. */
1095 | ((warn_c90_c99_compat
== 1) << 7)
1096 | ((warn_c90_c99_compat
== -1) << 8)
1097 /* Similarly for warn_c99_c11_compat. */
1098 | ((warn_c99_c11_compat
== 1) << 9)
1099 | ((warn_c99_c11_compat
== -1) << 10)
1101 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1102 warn_pointer_arith
= 0;
1103 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1105 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1106 warn_cxx_compat
= 0;
1107 warn_overlength_strings
= 0;
1108 warn_c90_c99_compat
= 0;
1109 warn_c99_c11_compat
= 0;
1113 /* Restore the warning flags which are controlled by __extension__.
1114 FLAGS is the return value from disable_extension_diagnostics. */
1117 restore_extension_diagnostics (int flags
)
1119 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1120 warn_pointer_arith
= (flags
>> 1) & 1;
1121 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1122 flag_iso
= (flags
>> 3) & 1;
1123 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1124 warn_cxx_compat
= (flags
>> 5) & 1;
1125 warn_overlength_strings
= (flags
>> 6) & 1;
1126 /* See above for why is this needed. */
1127 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1128 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1131 /* Possibly kinds of declarator to parse. */
1132 typedef enum c_dtr_syn
{
1133 /* A normal declarator with an identifier. */
1135 /* An abstract declarator (maybe empty). */
1137 /* A parameter declarator: may be either, but after a type name does
1138 not redeclare a typedef name as an identifier if it can
1139 alternatively be interpreted as a typedef name; see DR#009,
1140 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1141 following DR#249. For example, given a typedef T, "int T" and
1142 "int *T" are valid parameter declarations redeclaring T, while
1143 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1144 abstract declarators rather than involving redundant parentheses;
1145 the same applies with attributes inside the parentheses before
1150 /* The binary operation precedence levels, where 0 is a dummy lowest level
1151 used for the bottom of the stack. */
1152 enum c_parser_prec
{
1167 static void c_parser_external_declaration (c_parser
*);
1168 static void c_parser_asm_definition (c_parser
*);
1169 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1170 bool, bool, tree
*, vec
<c_token
>);
1171 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1172 static void c_parser_static_assert_declaration (c_parser
*);
1173 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1174 bool, bool, bool, enum c_lookahead_kind
);
1175 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1176 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1177 static tree
c_parser_struct_declaration (c_parser
*);
1178 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1179 static tree
c_parser_alignas_specifier (c_parser
*);
1180 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1182 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1184 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1186 struct c_declarator
*);
1187 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1188 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1190 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1191 static tree
c_parser_simple_asm_expr (c_parser
*);
1192 static tree
c_parser_attributes (c_parser
*);
1193 static struct c_type_name
*c_parser_type_name (c_parser
*);
1194 static struct c_expr
c_parser_initializer (c_parser
*);
1195 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1196 static void c_parser_initelt (c_parser
*, struct obstack
*);
1197 static void c_parser_initval (c_parser
*, struct c_expr
*,
1199 static tree
c_parser_compound_statement (c_parser
*);
1200 static void c_parser_compound_statement_nostart (c_parser
*);
1201 static void c_parser_label (c_parser
*);
1202 static void c_parser_statement (c_parser
*);
1203 static void c_parser_statement_after_labels (c_parser
*);
1204 static void c_parser_if_statement (c_parser
*);
1205 static void c_parser_switch_statement (c_parser
*);
1206 static void c_parser_while_statement (c_parser
*, bool);
1207 static void c_parser_do_statement (c_parser
*, bool);
1208 static void c_parser_for_statement (c_parser
*, bool);
1209 static tree
c_parser_asm_statement (c_parser
*);
1210 static tree
c_parser_asm_operands (c_parser
*);
1211 static tree
c_parser_asm_goto_operands (c_parser
*);
1212 static tree
c_parser_asm_clobbers (c_parser
*);
1213 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1215 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1216 struct c_expr
*, tree
);
1217 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1219 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1220 static struct c_expr
c_parser_unary_expression (c_parser
*);
1221 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1222 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1223 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1224 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1225 struct c_type_name
*,
1227 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1230 static tree
c_parser_transaction (c_parser
*, enum rid
);
1231 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1232 static tree
c_parser_transaction_cancel (c_parser
*);
1233 static struct c_expr
c_parser_expression (c_parser
*);
1234 static struct c_expr
c_parser_expression_conv (c_parser
*);
1235 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1236 vec
<tree
, va_gc
> **, location_t
*,
1237 tree
*, vec
<location_t
> *,
1238 unsigned int * = NULL
);
1239 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1240 static void c_parser_oacc_update (c_parser
*);
1241 static tree
c_parser_oacc_loop (location_t
, c_parser
*, char *);
1242 static void c_parser_omp_construct (c_parser
*);
1243 static void c_parser_omp_threadprivate (c_parser
*);
1244 static void c_parser_omp_barrier (c_parser
*);
1245 static void c_parser_omp_flush (c_parser
*);
1246 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1248 static void c_parser_omp_taskwait (c_parser
*);
1249 static void c_parser_omp_taskyield (c_parser
*);
1250 static void c_parser_omp_cancel (c_parser
*);
1251 static void c_parser_omp_cancellation_point (c_parser
*);
1253 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1254 pragma_stmt
, pragma_compound
};
1255 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1256 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1257 static void c_parser_omp_end_declare_target (c_parser
*);
1258 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1260 /* These Objective-C parser functions are only ever called when
1261 compiling Objective-C. */
1262 static void c_parser_objc_class_definition (c_parser
*, tree
);
1263 static void c_parser_objc_class_instance_variables (c_parser
*);
1264 static void c_parser_objc_class_declaration (c_parser
*);
1265 static void c_parser_objc_alias_declaration (c_parser
*);
1266 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1267 static bool c_parser_objc_method_type (c_parser
*);
1268 static void c_parser_objc_method_definition (c_parser
*);
1269 static void c_parser_objc_methodprotolist (c_parser
*);
1270 static void c_parser_objc_methodproto (c_parser
*);
1271 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1272 static tree
c_parser_objc_type_name (c_parser
*);
1273 static tree
c_parser_objc_protocol_refs (c_parser
*);
1274 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1275 static void c_parser_objc_synchronized_statement (c_parser
*);
1276 static tree
c_parser_objc_selector (c_parser
*);
1277 static tree
c_parser_objc_selector_arg (c_parser
*);
1278 static tree
c_parser_objc_receiver (c_parser
*);
1279 static tree
c_parser_objc_message_args (c_parser
*);
1280 static tree
c_parser_objc_keywordexpr (c_parser
*);
1281 static void c_parser_objc_at_property_declaration (c_parser
*);
1282 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1283 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1284 static bool c_parser_objc_diagnose_bad_element_prefix
1285 (c_parser
*, struct c_declspecs
*);
1287 /* Cilk Plus supporting routines. */
1288 static void c_parser_cilk_simd (c_parser
*);
1289 static void c_parser_cilk_for (c_parser
*, tree
);
1290 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1291 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1292 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1293 static void c_parser_cilk_grainsize (c_parser
*);
1295 /* Parse a translation unit (C90 6.7, C99 6.9).
1298 external-declarations
1300 external-declarations:
1301 external-declaration
1302 external-declarations external-declaration
1311 c_parser_translation_unit (c_parser
*parser
)
1313 if (c_parser_next_token_is (parser
, CPP_EOF
))
1315 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1316 "ISO C forbids an empty translation unit");
1320 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1321 mark_valid_location_for_stdc_pragma (false);
1325 c_parser_external_declaration (parser
);
1326 obstack_free (&parser_obstack
, obstack_position
);
1328 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1332 /* Parse an external declaration (C90 6.7, C99 6.9).
1334 external-declaration:
1340 external-declaration:
1343 __extension__ external-declaration
1347 external-declaration:
1348 objc-class-definition
1349 objc-class-declaration
1350 objc-alias-declaration
1351 objc-protocol-definition
1352 objc-method-definition
1357 c_parser_external_declaration (c_parser
*parser
)
1360 switch (c_parser_peek_token (parser
)->type
)
1363 switch (c_parser_peek_token (parser
)->keyword
)
1366 ext
= disable_extension_diagnostics ();
1367 c_parser_consume_token (parser
);
1368 c_parser_external_declaration (parser
);
1369 restore_extension_diagnostics (ext
);
1372 c_parser_asm_definition (parser
);
1374 case RID_AT_INTERFACE
:
1375 case RID_AT_IMPLEMENTATION
:
1376 gcc_assert (c_dialect_objc ());
1377 c_parser_objc_class_definition (parser
, NULL_TREE
);
1380 gcc_assert (c_dialect_objc ());
1381 c_parser_objc_class_declaration (parser
);
1384 gcc_assert (c_dialect_objc ());
1385 c_parser_objc_alias_declaration (parser
);
1387 case RID_AT_PROTOCOL
:
1388 gcc_assert (c_dialect_objc ());
1389 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1391 case RID_AT_PROPERTY
:
1392 gcc_assert (c_dialect_objc ());
1393 c_parser_objc_at_property_declaration (parser
);
1395 case RID_AT_SYNTHESIZE
:
1396 gcc_assert (c_dialect_objc ());
1397 c_parser_objc_at_synthesize_declaration (parser
);
1399 case RID_AT_DYNAMIC
:
1400 gcc_assert (c_dialect_objc ());
1401 c_parser_objc_at_dynamic_declaration (parser
);
1404 gcc_assert (c_dialect_objc ());
1405 c_parser_consume_token (parser
);
1406 objc_finish_implementation ();
1413 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1414 "ISO C does not allow extra %<;%> outside of a function");
1415 c_parser_consume_token (parser
);
1418 mark_valid_location_for_stdc_pragma (true);
1419 c_parser_pragma (parser
, pragma_external
);
1420 mark_valid_location_for_stdc_pragma (false);
1424 if (c_dialect_objc ())
1426 c_parser_objc_method_definition (parser
);
1429 /* Else fall through, and yield a syntax error trying to parse
1430 as a declaration or function definition. */
1433 /* A declaration or a function definition (or, in Objective-C,
1434 an @interface or @protocol with prefix attributes). We can
1435 only tell which after parsing the declaration specifiers, if
1436 any, and the first declarator. */
1437 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1443 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1445 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1446 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1447 accepted; otherwise (old-style parameter declarations) only other
1448 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1449 assertion is accepted; otherwise (old-style parameter declarations)
1450 it is not. If NESTED is true, we are inside a function or parsing
1451 old-style parameter declarations; any functions encountered are
1452 nested functions and declaration specifiers are required; otherwise
1453 we are at top level and functions are normal functions and
1454 declaration specifiers may be optional. If EMPTY_OK is true, empty
1455 declarations are OK (subject to all other constraints); otherwise
1456 (old-style parameter declarations) they are diagnosed. If
1457 START_ATTR_OK is true, the declaration specifiers may start with
1458 attributes; otherwise they may not.
1459 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1460 declaration when parsing an Objective-C foreach statement.
1463 declaration-specifiers init-declarator-list[opt] ;
1464 static_assert-declaration
1466 function-definition:
1467 declaration-specifiers[opt] declarator declaration-list[opt]
1472 declaration-list declaration
1474 init-declarator-list:
1476 init-declarator-list , init-declarator
1479 declarator simple-asm-expr[opt] attributes[opt]
1480 declarator simple-asm-expr[opt] attributes[opt] = initializer
1484 nested-function-definition:
1485 declaration-specifiers declarator declaration-list[opt]
1489 attributes objc-class-definition
1490 attributes objc-category-definition
1491 attributes objc-protocol-definition
1493 The simple-asm-expr and attributes are GNU extensions.
1495 This function does not handle __extension__; that is handled in its
1496 callers. ??? Following the old parser, __extension__ may start
1497 external declarations, declarations in functions and declarations
1498 at the start of "for" loops, but not old-style parameter
1501 C99 requires declaration specifiers in a function definition; the
1502 absence is diagnosed through the diagnosis of implicit int. In GNU
1503 C we also allow but diagnose declarations without declaration
1504 specifiers, but only at top level (elsewhere they conflict with
1507 In Objective-C, declarations of the looping variable in a foreach
1508 statement are exceptionally terminated by 'in' (for example, 'for
1509 (NSObject *object in array) { ... }').
1514 threadprivate-directive */
1517 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1518 bool static_assert_ok
, bool empty_ok
,
1519 bool nested
, bool start_attr_ok
,
1520 tree
*objc_foreach_object_declaration
,
1521 vec
<c_token
> omp_declare_simd_clauses
)
1523 struct c_declspecs
*specs
;
1525 tree all_prefix_attrs
;
1526 bool diagnosed_no_specs
= false;
1527 location_t here
= c_parser_peek_token (parser
)->location
;
1529 if (static_assert_ok
1530 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1532 c_parser_static_assert_declaration (parser
);
1535 specs
= build_null_declspecs ();
1537 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1538 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1539 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1540 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1541 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1542 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1544 error_at (here
, "unknown type name %qE",
1545 c_parser_peek_token (parser
)->value
);
1547 /* Parse declspecs normally to get a correct pointer type, but avoid
1548 a further "fails to be a type name" error. Refuse nested functions
1549 since it is not how the user likely wants us to recover. */
1550 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1551 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1552 c_parser_peek_token (parser
)->value
= error_mark_node
;
1556 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1557 true, true, cla_nonabstract_decl
);
1560 c_parser_skip_to_end_of_block_or_statement (parser
);
1563 if (nested
&& !specs
->declspecs_seen_p
)
1565 c_parser_error (parser
, "expected declaration specifiers");
1566 c_parser_skip_to_end_of_block_or_statement (parser
);
1569 finish_declspecs (specs
);
1570 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1571 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1574 error_at (here
, "%<__auto_type%> in empty declaration");
1579 shadow_tag_warned (specs
, 1);
1580 pedwarn (here
, 0, "empty declaration");
1582 c_parser_consume_token (parser
);
1586 /* Provide better error recovery. Note that a type name here is usually
1587 better diagnosed as a redeclaration. */
1589 && specs
->typespec_kind
== ctsk_tagdef
1590 && c_parser_next_token_starts_declspecs (parser
)
1591 && !c_parser_next_token_is (parser
, CPP_NAME
))
1593 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1594 parser
->error
= false;
1595 shadow_tag_warned (specs
, 1);
1598 else if (c_dialect_objc () && !auto_type_p
)
1600 /* Prefix attributes are an error on method decls. */
1601 switch (c_parser_peek_token (parser
)->type
)
1605 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1609 warning_at (c_parser_peek_token (parser
)->location
,
1611 "prefix attributes are ignored for methods");
1612 specs
->attrs
= NULL_TREE
;
1615 c_parser_objc_method_definition (parser
);
1617 c_parser_objc_methodproto (parser
);
1623 /* This is where we parse 'attributes @interface ...',
1624 'attributes @implementation ...', 'attributes @protocol ...'
1625 (where attributes could be, for example, __attribute__
1628 switch (c_parser_peek_token (parser
)->keyword
)
1630 case RID_AT_INTERFACE
:
1632 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1634 c_parser_objc_class_definition (parser
, specs
->attrs
);
1638 case RID_AT_IMPLEMENTATION
:
1640 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1644 warning_at (c_parser_peek_token (parser
)->location
,
1646 "prefix attributes are ignored for implementations");
1647 specs
->attrs
= NULL_TREE
;
1649 c_parser_objc_class_definition (parser
, NULL_TREE
);
1653 case RID_AT_PROTOCOL
:
1655 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1657 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1664 case RID_AT_PROPERTY
:
1667 c_parser_error (parser
, "unexpected attribute");
1668 specs
->attrs
= NULL
;
1676 pending_xref_error ();
1677 prefix_attrs
= specs
->attrs
;
1678 all_prefix_attrs
= prefix_attrs
;
1679 specs
->attrs
= NULL_TREE
;
1682 struct c_declarator
*declarator
;
1686 /* Declaring either one or more declarators (in which case we
1687 should diagnose if there were no declaration specifiers) or a
1688 function definition (in which case the diagnostic for
1689 implicit int suffices). */
1690 declarator
= c_parser_declarator (parser
,
1691 specs
->typespec_kind
!= ctsk_none
,
1692 C_DTR_NORMAL
, &dummy
);
1693 if (declarator
== NULL
)
1695 if (omp_declare_simd_clauses
.exists ()
1696 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1697 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1698 omp_declare_simd_clauses
);
1699 c_parser_skip_to_end_of_block_or_statement (parser
);
1702 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1705 "%<__auto_type%> requires a plain identifier"
1707 c_parser_skip_to_end_of_block_or_statement (parser
);
1710 if (c_parser_next_token_is (parser
, CPP_EQ
)
1711 || c_parser_next_token_is (parser
, CPP_COMMA
)
1712 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1713 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1714 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1715 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1717 tree asm_name
= NULL_TREE
;
1718 tree postfix_attrs
= NULL_TREE
;
1719 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1721 diagnosed_no_specs
= true;
1722 pedwarn (here
, 0, "data definition has no type or storage class");
1724 /* Having seen a data definition, there cannot now be a
1725 function definition. */
1727 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1728 asm_name
= c_parser_simple_asm_expr (parser
);
1729 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1731 postfix_attrs
= c_parser_attributes (parser
);
1732 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1734 /* This means there is an attribute specifier after
1735 the declarator in a function definition. Provide
1736 some more information for the user. */
1737 error_at (here
, "attributes should be specified before the "
1738 "declarator in a function definition");
1739 c_parser_skip_to_end_of_block_or_statement (parser
);
1743 if (c_parser_next_token_is (parser
, CPP_EQ
))
1747 location_t init_loc
;
1748 c_parser_consume_token (parser
);
1751 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1752 init_loc
= c_parser_peek_token (parser
)->location
;
1753 init
= c_parser_expr_no_commas (parser
, NULL
);
1754 if (TREE_CODE (init
.value
) == COMPONENT_REF
1755 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1757 "%<__auto_type%> used with a bit-field"
1759 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1760 tree init_type
= TREE_TYPE (init
.value
);
1761 /* As with typeof, remove all qualifiers from atomic types. */
1762 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1764 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1765 bool vm_type
= variably_modified_type_p (init_type
,
1768 init
.value
= c_save_expr (init
.value
);
1770 specs
->typespec_kind
= ctsk_typeof
;
1771 specs
->locations
[cdw_typedef
] = init_loc
;
1772 specs
->typedef_p
= true;
1773 specs
->type
= init_type
;
1776 bool maybe_const
= true;
1777 tree type_expr
= c_fully_fold (init
.value
, false,
1779 specs
->expr_const_operands
&= maybe_const
;
1781 specs
->expr
= build2 (COMPOUND_EXPR
,
1782 TREE_TYPE (type_expr
),
1783 specs
->expr
, type_expr
);
1785 specs
->expr
= type_expr
;
1787 d
= start_decl (declarator
, specs
, true,
1788 chainon (postfix_attrs
, all_prefix_attrs
));
1790 d
= error_mark_node
;
1791 if (omp_declare_simd_clauses
.exists ()
1792 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1793 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1794 omp_declare_simd_clauses
);
1798 /* The declaration of the variable is in effect while
1799 its initializer is parsed. */
1800 d
= start_decl (declarator
, specs
, true,
1801 chainon (postfix_attrs
, all_prefix_attrs
));
1803 d
= error_mark_node
;
1804 if (omp_declare_simd_clauses
.exists ()
1805 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1806 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1807 omp_declare_simd_clauses
);
1808 start_init (d
, asm_name
, global_bindings_p ());
1809 init_loc
= c_parser_peek_token (parser
)->location
;
1810 init
= c_parser_initializer (parser
);
1813 if (d
!= error_mark_node
)
1815 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1816 finish_decl (d
, init_loc
, init
.value
,
1817 init
.original_type
, asm_name
);
1825 "%<__auto_type%> requires an initialized "
1826 "data declaration");
1827 c_parser_skip_to_end_of_block_or_statement (parser
);
1830 tree d
= start_decl (declarator
, specs
, false,
1831 chainon (postfix_attrs
,
1833 if (omp_declare_simd_clauses
.exists ()
1834 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1836 tree parms
= NULL_TREE
;
1837 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1839 struct c_declarator
*ce
= declarator
;
1841 if (ce
->kind
== cdk_function
)
1843 parms
= ce
->u
.arg_info
->parms
;
1847 ce
= ce
->declarator
;
1850 temp_store_parm_decls (d
, parms
);
1851 c_finish_omp_declare_simd (parser
, d
, parms
,
1852 omp_declare_simd_clauses
);
1854 temp_pop_parm_decls ();
1857 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1858 NULL_TREE
, asm_name
);
1860 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1863 *objc_foreach_object_declaration
= d
;
1865 *objc_foreach_object_declaration
= error_mark_node
;
1868 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1873 "%<__auto_type%> may only be used with"
1874 " a single declarator");
1875 c_parser_skip_to_end_of_block_or_statement (parser
);
1878 c_parser_consume_token (parser
);
1879 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1880 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1883 all_prefix_attrs
= prefix_attrs
;
1886 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1888 c_parser_consume_token (parser
);
1891 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1893 /* This can only happen in Objective-C: we found the
1894 'in' that terminates the declaration inside an
1895 Objective-C foreach statement. Do not consume the
1896 token, so that the caller can use it to determine
1897 that this indeed is a foreach context. */
1902 c_parser_error (parser
, "expected %<,%> or %<;%>");
1903 c_parser_skip_to_end_of_block_or_statement (parser
);
1907 else if (auto_type_p
)
1910 "%<__auto_type%> requires an initialized data declaration");
1911 c_parser_skip_to_end_of_block_or_statement (parser
);
1916 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1917 "%<asm%> or %<__attribute__%>");
1918 c_parser_skip_to_end_of_block_or_statement (parser
);
1921 /* Function definition (nested or otherwise). */
1924 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1925 c_push_function_context ();
1927 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1929 /* This can appear in many cases looking nothing like a
1930 function definition, so we don't give a more specific
1931 error suggesting there was one. */
1932 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1933 "or %<__attribute__%>");
1935 c_pop_function_context ();
1939 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1940 tv
= TV_PARSE_INLINE
;
1945 /* Parse old-style parameter declarations. ??? Attributes are
1946 not allowed to start declaration specifiers here because of a
1947 syntax conflict between a function declaration with attribute
1948 suffix and a function definition with an attribute prefix on
1949 first old-style parameter declaration. Following the old
1950 parser, they are not accepted on subsequent old-style
1951 parameter declarations either. However, there is no
1952 ambiguity after the first declaration, nor indeed on the
1953 first as long as we don't allow postfix attributes after a
1954 declarator with a nonempty identifier list in a definition;
1955 and postfix attributes have never been accepted here in
1956 function definitions either. */
1957 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1958 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1959 c_parser_declaration_or_fndef (parser
, false, false, false,
1960 true, false, NULL
, vNULL
);
1961 store_parm_decls ();
1962 if (omp_declare_simd_clauses
.exists ()
1963 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1964 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1965 omp_declare_simd_clauses
);
1966 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1967 = c_parser_peek_token (parser
)->location
;
1968 fnbody
= c_parser_compound_statement (parser
);
1969 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1970 fnbody
= expand_array_notation_exprs (fnbody
);
1973 tree decl
= current_function_decl
;
1974 /* Mark nested functions as needing static-chain initially.
1975 lower_nested_functions will recompute it but the
1976 DECL_STATIC_CHAIN flag is also used before that happens,
1977 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1978 DECL_STATIC_CHAIN (decl
) = 1;
1981 c_pop_function_context ();
1982 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1995 /* Parse an asm-definition (asm() outside a function body). This is a
2003 c_parser_asm_definition (c_parser
*parser
)
2005 tree asm_str
= c_parser_simple_asm_expr (parser
);
2007 symtab
->finalize_toplevel_asm (asm_str
);
2008 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2011 /* Parse a static assertion (C11 6.7.10).
2013 static_assert-declaration:
2014 static_assert-declaration-no-semi ;
2018 c_parser_static_assert_declaration (c_parser
*parser
)
2020 c_parser_static_assert_declaration_no_semi (parser
);
2022 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2023 c_parser_skip_to_end_of_block_or_statement (parser
);
2026 /* Parse a static assertion (C11 6.7.10), without the trailing
2029 static_assert-declaration-no-semi:
2030 _Static_assert ( constant-expression , string-literal )
2034 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2036 location_t assert_loc
, value_loc
;
2040 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2041 assert_loc
= c_parser_peek_token (parser
)->location
;
2043 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2044 "ISO C99 does not support %<_Static_assert%>");
2046 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2047 "ISO C90 does not support %<_Static_assert%>");
2048 c_parser_consume_token (parser
);
2049 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2051 value_loc
= c_parser_peek_token (parser
)->location
;
2052 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2053 parser
->lex_untranslated_string
= true;
2054 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2056 parser
->lex_untranslated_string
= false;
2059 switch (c_parser_peek_token (parser
)->type
)
2065 case CPP_UTF8STRING
:
2066 string
= c_parser_peek_token (parser
)->value
;
2067 c_parser_consume_token (parser
);
2068 parser
->lex_untranslated_string
= false;
2071 c_parser_error (parser
, "expected string literal");
2072 parser
->lex_untranslated_string
= false;
2075 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2077 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2079 error_at (value_loc
, "expression in static assertion is not an integer");
2082 if (TREE_CODE (value
) != INTEGER_CST
)
2084 value
= c_fully_fold (value
, false, NULL
);
2085 /* Strip no-op conversions. */
2086 STRIP_TYPE_NOPS (value
);
2087 if (TREE_CODE (value
) == INTEGER_CST
)
2088 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2089 "is not an integer constant expression");
2091 if (TREE_CODE (value
) != INTEGER_CST
)
2093 error_at (value_loc
, "expression in static assertion is not constant");
2096 constant_expression_warning (value
);
2097 if (integer_zerop (value
))
2098 error_at (assert_loc
, "static assertion failed: %E", string
);
2101 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2102 6.7), adding them to SPECS (which may already include some).
2103 Storage class specifiers are accepted iff SCSPEC_OK; type
2104 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2105 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2106 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2108 declaration-specifiers:
2109 storage-class-specifier declaration-specifiers[opt]
2110 type-specifier declaration-specifiers[opt]
2111 type-qualifier declaration-specifiers[opt]
2112 function-specifier declaration-specifiers[opt]
2113 alignment-specifier declaration-specifiers[opt]
2115 Function specifiers (inline) are from C99, and are currently
2116 handled as storage class specifiers, as is __thread. Alignment
2117 specifiers are from C11.
2119 C90 6.5.1, C99 6.7.1:
2120 storage-class-specifier:
2128 (_Thread_local is new in C11.)
2135 (_Noreturn is new in C11.)
2137 C90 6.5.2, C99 6.7.2:
2150 [_Imaginary removed in C99 TC2]
2151 struct-or-union-specifier
2154 atomic-type-specifier
2156 (_Bool and _Complex are new in C99.)
2157 (atomic-type-specifier is new in C11.)
2159 C90 6.5.3, C99 6.7.3:
2165 address-space-qualifier
2168 (restrict is new in C99.)
2169 (_Atomic is new in C11.)
2173 declaration-specifiers:
2174 attributes declaration-specifiers[opt]
2180 identifier recognized by the target
2182 storage-class-specifier:
2196 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2197 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2199 atomic-type-specifier
2200 _Atomic ( type-name )
2205 class-name objc-protocol-refs[opt]
2206 typedef-name objc-protocol-refs
2211 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2212 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2213 bool alignspec_ok
, bool auto_type_ok
,
2214 enum c_lookahead_kind la
)
2216 bool attrs_ok
= start_attr_ok
;
2217 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2220 gcc_assert (la
== cla_prefer_id
);
2222 while (c_parser_next_token_is (parser
, CPP_NAME
)
2223 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2224 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2226 struct c_typespec t
;
2229 location_t loc
= c_parser_peek_token (parser
)->location
;
2231 /* If we cannot accept a type, exit if the next token must start
2232 one. Also, if we already have seen a tagged definition,
2233 a typename would be an error anyway and likely the user
2234 has simply forgotten a semicolon, so we exit. */
2235 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2236 && c_parser_next_tokens_start_typename (parser
, la
)
2237 && !c_parser_next_token_is_qualifier (parser
))
2240 if (c_parser_next_token_is (parser
, CPP_NAME
))
2242 c_token
*name_token
= c_parser_peek_token (parser
);
2243 tree value
= name_token
->value
;
2244 c_id_kind kind
= name_token
->id_kind
;
2246 if (kind
== C_ID_ADDRSPACE
)
2249 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2250 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2251 c_parser_consume_token (parser
);
2256 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2258 /* If we cannot accept a type, and the next token must start one,
2259 exit. Do the same if we already have seen a tagged definition,
2260 since it would be an error anyway and likely the user has simply
2261 forgotten a semicolon. */
2262 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2265 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2266 a C_ID_CLASSNAME. */
2267 c_parser_consume_token (parser
);
2270 if (kind
== C_ID_ID
)
2272 error_at (loc
, "unknown type name %qE", value
);
2273 t
.kind
= ctsk_typedef
;
2274 t
.spec
= error_mark_node
;
2276 else if (kind
== C_ID_TYPENAME
2277 && (!c_dialect_objc ()
2278 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2280 t
.kind
= ctsk_typedef
;
2281 /* For a typedef name, record the meaning, not the name.
2282 In case of 'foo foo, bar;'. */
2283 t
.spec
= lookup_name (value
);
2287 tree proto
= NULL_TREE
;
2288 gcc_assert (c_dialect_objc ());
2290 if (c_parser_next_token_is (parser
, CPP_LESS
))
2291 proto
= c_parser_objc_protocol_refs (parser
);
2292 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2295 t
.expr_const_operands
= true;
2296 declspecs_add_type (name_token
->location
, specs
, t
);
2299 if (c_parser_next_token_is (parser
, CPP_LESS
))
2301 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2302 nisse@lysator.liu.se. */
2304 gcc_assert (c_dialect_objc ());
2305 if (!typespec_ok
|| seen_type
)
2307 proto
= c_parser_objc_protocol_refs (parser
);
2309 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2311 t
.expr_const_operands
= true;
2312 declspecs_add_type (loc
, specs
, t
);
2315 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2316 switch (c_parser_peek_token (parser
)->keyword
)
2329 /* TODO: Distinguish between function specifiers (inline, noreturn)
2330 and storage class specifiers, either here or in
2331 declspecs_add_scspec. */
2332 declspecs_add_scspec (loc
, specs
,
2333 c_parser_peek_token (parser
)->value
);
2334 c_parser_consume_token (parser
);
2365 if (c_dialect_objc ())
2366 parser
->objc_need_raw_identifier
= true;
2367 t
.kind
= ctsk_resword
;
2368 t
.spec
= c_parser_peek_token (parser
)->value
;
2370 t
.expr_const_operands
= true;
2371 declspecs_add_type (loc
, specs
, t
);
2372 c_parser_consume_token (parser
);
2379 t
= c_parser_enum_specifier (parser
);
2380 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2381 declspecs_add_type (loc
, specs
, t
);
2389 t
= c_parser_struct_or_union_specifier (parser
);
2390 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2391 declspecs_add_type (loc
, specs
, t
);
2394 /* ??? The old parser rejected typeof after other type
2395 specifiers, but is a syntax error the best way of
2397 if (!typespec_ok
|| seen_type
)
2401 t
= c_parser_typeof_specifier (parser
);
2402 declspecs_add_type (loc
, specs
, t
);
2405 /* C parser handling of Objective-C constructs needs
2406 checking for correct lvalue-to-rvalue conversions, and
2407 the code in build_modify_expr handling various
2408 Objective-C cases, and that in build_unary_op handling
2409 Objective-C cases for increment / decrement, also needs
2410 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2411 and objc_types_are_equivalent may also need updates. */
2412 if (c_dialect_objc ())
2413 sorry ("%<_Atomic%> in Objective-C");
2414 /* C parser handling of OpenMP constructs needs checking for
2415 correct lvalue-to-rvalue conversions. */
2417 sorry ("%<_Atomic%> with OpenMP");
2419 pedwarn_c99 (loc
, OPT_Wpedantic
,
2420 "ISO C99 does not support the %<_Atomic%> qualifier");
2422 pedwarn_c99 (loc
, OPT_Wpedantic
,
2423 "ISO C90 does not support the %<_Atomic%> qualifier");
2426 value
= c_parser_peek_token (parser
)->value
;
2427 c_parser_consume_token (parser
);
2428 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2430 /* _Atomic ( type-name ). */
2432 c_parser_consume_token (parser
);
2433 struct c_type_name
*type
= c_parser_type_name (parser
);
2434 t
.kind
= ctsk_typeof
;
2435 t
.spec
= error_mark_node
;
2437 t
.expr_const_operands
= true;
2439 t
.spec
= groktypename (type
, &t
.expr
,
2440 &t
.expr_const_operands
);
2441 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2443 if (t
.spec
!= error_mark_node
)
2445 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2446 error_at (loc
, "%<_Atomic%>-qualified array type");
2447 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2448 error_at (loc
, "%<_Atomic%>-qualified function type");
2449 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2450 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2452 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2454 declspecs_add_type (loc
, specs
, t
);
2457 declspecs_add_qual (loc
, specs
, value
);
2463 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2464 c_parser_consume_token (parser
);
2469 attrs
= c_parser_attributes (parser
);
2470 declspecs_add_attrs (loc
, specs
, attrs
);
2475 align
= c_parser_alignas_specifier (parser
);
2476 declspecs_add_alignas (loc
, specs
, align
);
2485 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2488 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2489 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2490 enum attributes[opt] identifier
2492 The form with trailing comma is new in C99. The forms with
2493 attributes are GNU extensions. In GNU C, we accept any expression
2494 without commas in the syntax (assignment expressions, not just
2495 conditional expressions); assignment expressions will be diagnosed
2500 enumerator-list , enumerator
2503 enumeration-constant
2504 enumeration-constant = constant-expression
2509 enumeration-constant attributes[opt]
2510 enumeration-constant attributes[opt] = constant-expression
2514 static struct c_typespec
2515 c_parser_enum_specifier (c_parser
*parser
)
2517 struct c_typespec ret
;
2519 tree ident
= NULL_TREE
;
2520 location_t enum_loc
;
2521 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2522 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2523 enum_loc
= c_parser_peek_token (parser
)->location
;
2524 c_parser_consume_token (parser
);
2525 attrs
= c_parser_attributes (parser
);
2526 enum_loc
= c_parser_peek_token (parser
)->location
;
2527 /* Set the location in case we create a decl now. */
2528 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2529 if (c_parser_next_token_is (parser
, CPP_NAME
))
2531 ident
= c_parser_peek_token (parser
)->value
;
2532 ident_loc
= c_parser_peek_token (parser
)->location
;
2533 enum_loc
= ident_loc
;
2534 c_parser_consume_token (parser
);
2536 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2538 /* Parse an enum definition. */
2539 struct c_enum_contents the_enum
;
2542 /* We chain the enumerators in reverse order, then put them in
2543 forward order at the end. */
2545 timevar_push (TV_PARSE_ENUM
);
2546 type
= start_enum (enum_loc
, &the_enum
, ident
);
2548 c_parser_consume_token (parser
);
2556 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2557 location_t decl_loc
, value_loc
;
2558 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2560 c_parser_error (parser
, "expected identifier");
2561 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2562 values
= error_mark_node
;
2565 token
= c_parser_peek_token (parser
);
2566 enum_id
= token
->value
;
2567 /* Set the location in case we create a decl now. */
2568 c_parser_set_source_position_from_token (token
);
2569 decl_loc
= value_loc
= token
->location
;
2570 c_parser_consume_token (parser
);
2571 /* Parse any specified attributes. */
2572 tree enum_attrs
= c_parser_attributes (parser
);
2573 if (c_parser_next_token_is (parser
, CPP_EQ
))
2575 c_parser_consume_token (parser
);
2576 value_loc
= c_parser_peek_token (parser
)->location
;
2577 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2580 enum_value
= NULL_TREE
;
2581 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2582 &the_enum
, enum_id
, enum_value
);
2584 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2585 TREE_CHAIN (enum_decl
) = values
;
2588 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2590 comma_loc
= c_parser_peek_token (parser
)->location
;
2592 c_parser_consume_token (parser
);
2594 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2597 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2598 "comma at end of enumerator list");
2599 c_parser_consume_token (parser
);
2604 c_parser_error (parser
, "expected %<,%> or %<}%>");
2605 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2606 values
= error_mark_node
;
2610 postfix_attrs
= c_parser_attributes (parser
);
2611 ret
.spec
= finish_enum (type
, nreverse (values
),
2612 chainon (attrs
, postfix_attrs
));
2613 ret
.kind
= ctsk_tagdef
;
2614 ret
.expr
= NULL_TREE
;
2615 ret
.expr_const_operands
= true;
2616 timevar_pop (TV_PARSE_ENUM
);
2621 c_parser_error (parser
, "expected %<{%>");
2622 ret
.spec
= error_mark_node
;
2623 ret
.kind
= ctsk_tagref
;
2624 ret
.expr
= NULL_TREE
;
2625 ret
.expr_const_operands
= true;
2628 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2629 /* In ISO C, enumerated types can be referred to only if already
2631 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2634 pedwarn (enum_loc
, OPT_Wpedantic
,
2635 "ISO C forbids forward references to %<enum%> types");
2640 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2642 struct-or-union-specifier:
2643 struct-or-union attributes[opt] identifier[opt]
2644 { struct-contents } attributes[opt]
2645 struct-or-union attributes[opt] identifier
2648 struct-declaration-list
2650 struct-declaration-list:
2651 struct-declaration ;
2652 struct-declaration-list struct-declaration ;
2659 struct-declaration-list struct-declaration
2661 struct-declaration-list:
2662 struct-declaration-list ;
2665 (Note that in the syntax here, unlike that in ISO C, the semicolons
2666 are included here rather than in struct-declaration, in order to
2667 describe the syntax with extra semicolons and missing semicolon at
2672 struct-declaration-list:
2673 @defs ( class-name )
2675 (Note this does not include a trailing semicolon, but can be
2676 followed by further declarations, and gets a pedwarn-if-pedantic
2677 when followed by a semicolon.) */
2679 static struct c_typespec
2680 c_parser_struct_or_union_specifier (c_parser
*parser
)
2682 struct c_typespec ret
;
2684 tree ident
= NULL_TREE
;
2685 location_t struct_loc
;
2686 location_t ident_loc
= UNKNOWN_LOCATION
;
2687 enum tree_code code
;
2688 switch (c_parser_peek_token (parser
)->keyword
)
2699 struct_loc
= c_parser_peek_token (parser
)->location
;
2700 c_parser_consume_token (parser
);
2701 attrs
= c_parser_attributes (parser
);
2703 /* Set the location in case we create a decl now. */
2704 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2706 if (c_parser_next_token_is (parser
, CPP_NAME
))
2708 ident
= c_parser_peek_token (parser
)->value
;
2709 ident_loc
= c_parser_peek_token (parser
)->location
;
2710 struct_loc
= ident_loc
;
2711 c_parser_consume_token (parser
);
2713 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2715 /* Parse a struct or union definition. Start the scope of the
2716 tag before parsing components. */
2717 struct c_struct_parse_info
*struct_info
;
2718 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2720 /* We chain the components in reverse order, then put them in
2721 forward order at the end. Each struct-declaration may
2722 declare multiple components (comma-separated), so we must use
2723 chainon to join them, although when parsing each
2724 struct-declaration we can use TREE_CHAIN directly.
2726 The theory behind all this is that there will be more
2727 semicolon separated fields than comma separated fields, and
2728 so we'll be minimizing the number of node traversals required
2731 timevar_push (TV_PARSE_STRUCT
);
2732 contents
= NULL_TREE
;
2733 c_parser_consume_token (parser
);
2734 /* Handle the Objective-C @defs construct,
2735 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2736 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2739 gcc_assert (c_dialect_objc ());
2740 c_parser_consume_token (parser
);
2741 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2743 if (c_parser_next_token_is (parser
, CPP_NAME
)
2744 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2746 name
= c_parser_peek_token (parser
)->value
;
2747 c_parser_consume_token (parser
);
2751 c_parser_error (parser
, "expected class name");
2752 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2755 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2757 contents
= nreverse (objc_get_class_ivars (name
));
2760 /* Parse the struct-declarations and semicolons. Problems with
2761 semicolons are diagnosed here; empty structures are diagnosed
2766 /* Parse any stray semicolon. */
2767 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2769 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2770 "extra semicolon in struct or union specified");
2771 c_parser_consume_token (parser
);
2774 /* Stop if at the end of the struct or union contents. */
2775 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2777 c_parser_consume_token (parser
);
2780 /* Accept #pragmas at struct scope. */
2781 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2783 c_parser_pragma (parser
, pragma_struct
);
2786 /* Parse some comma-separated declarations, but not the
2787 trailing semicolon if any. */
2788 decls
= c_parser_struct_declaration (parser
);
2789 contents
= chainon (decls
, contents
);
2790 /* If no semicolon follows, either we have a parse error or
2791 are at the end of the struct or union and should
2793 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2794 c_parser_consume_token (parser
);
2797 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2798 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2799 "no semicolon at end of struct or union");
2800 else if (parser
->error
2801 || !c_parser_next_token_starts_declspecs (parser
))
2803 c_parser_error (parser
, "expected %<;%>");
2804 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2808 /* If we come here, we have already emitted an error
2809 for an expected `;', identifier or `(', and we also
2810 recovered already. Go on with the next field. */
2813 postfix_attrs
= c_parser_attributes (parser
);
2814 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2815 chainon (attrs
, postfix_attrs
), struct_info
);
2816 ret
.kind
= ctsk_tagdef
;
2817 ret
.expr
= NULL_TREE
;
2818 ret
.expr_const_operands
= true;
2819 timevar_pop (TV_PARSE_STRUCT
);
2824 c_parser_error (parser
, "expected %<{%>");
2825 ret
.spec
= error_mark_node
;
2826 ret
.kind
= ctsk_tagref
;
2827 ret
.expr
= NULL_TREE
;
2828 ret
.expr_const_operands
= true;
2831 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2835 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2836 the trailing semicolon.
2839 specifier-qualifier-list struct-declarator-list
2840 static_assert-declaration-no-semi
2842 specifier-qualifier-list:
2843 type-specifier specifier-qualifier-list[opt]
2844 type-qualifier specifier-qualifier-list[opt]
2845 attributes specifier-qualifier-list[opt]
2847 struct-declarator-list:
2849 struct-declarator-list , attributes[opt] struct-declarator
2852 declarator attributes[opt]
2853 declarator[opt] : constant-expression attributes[opt]
2858 __extension__ struct-declaration
2859 specifier-qualifier-list
2861 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2862 of attributes where shown is a GNU extension. In GNU C, we accept
2863 any expression without commas in the syntax (assignment
2864 expressions, not just conditional expressions); assignment
2865 expressions will be diagnosed as non-constant. */
2868 c_parser_struct_declaration (c_parser
*parser
)
2870 struct c_declspecs
*specs
;
2872 tree all_prefix_attrs
;
2874 location_t decl_loc
;
2875 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2879 ext
= disable_extension_diagnostics ();
2880 c_parser_consume_token (parser
);
2881 decl
= c_parser_struct_declaration (parser
);
2882 restore_extension_diagnostics (ext
);
2885 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2887 c_parser_static_assert_declaration_no_semi (parser
);
2890 specs
= build_null_declspecs ();
2891 decl_loc
= c_parser_peek_token (parser
)->location
;
2892 /* Strictly by the standard, we shouldn't allow _Alignas here,
2893 but it appears to have been intended to allow it there, so
2894 we're keeping it as it is until WG14 reaches a conclusion
2896 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2897 c_parser_declspecs (parser
, specs
, false, true, true,
2898 true, false, cla_nonabstract_decl
);
2901 if (!specs
->declspecs_seen_p
)
2903 c_parser_error (parser
, "expected specifier-qualifier-list");
2906 finish_declspecs (specs
);
2907 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2908 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2911 if (specs
->typespec_kind
== ctsk_none
)
2913 pedwarn (decl_loc
, OPT_Wpedantic
,
2914 "ISO C forbids member declarations with no members");
2915 shadow_tag_warned (specs
, pedantic
);
2920 /* Support for unnamed structs or unions as members of
2921 structs or unions (which is [a] useful and [b] supports
2925 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2926 build_id_declarator (NULL_TREE
), specs
,
2929 decl_attributes (&ret
, attrs
, 0);
2934 /* Provide better error recovery. Note that a type name here is valid,
2935 and will be treated as a field name. */
2936 if (specs
->typespec_kind
== ctsk_tagdef
2937 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2938 && c_parser_next_token_starts_declspecs (parser
)
2939 && !c_parser_next_token_is (parser
, CPP_NAME
))
2941 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2942 parser
->error
= false;
2946 pending_xref_error ();
2947 prefix_attrs
= specs
->attrs
;
2948 all_prefix_attrs
= prefix_attrs
;
2949 specs
->attrs
= NULL_TREE
;
2953 /* Declaring one or more declarators or un-named bit-fields. */
2954 struct c_declarator
*declarator
;
2956 if (c_parser_next_token_is (parser
, CPP_COLON
))
2957 declarator
= build_id_declarator (NULL_TREE
);
2959 declarator
= c_parser_declarator (parser
,
2960 specs
->typespec_kind
!= ctsk_none
,
2961 C_DTR_NORMAL
, &dummy
);
2962 if (declarator
== NULL
)
2964 c_parser_skip_to_end_of_block_or_statement (parser
);
2967 if (c_parser_next_token_is (parser
, CPP_COLON
)
2968 || c_parser_next_token_is (parser
, CPP_COMMA
)
2969 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2970 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2971 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2973 tree postfix_attrs
= NULL_TREE
;
2974 tree width
= NULL_TREE
;
2976 if (c_parser_next_token_is (parser
, CPP_COLON
))
2978 c_parser_consume_token (parser
);
2979 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2981 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2982 postfix_attrs
= c_parser_attributes (parser
);
2983 d
= grokfield (c_parser_peek_token (parser
)->location
,
2984 declarator
, specs
, width
, &all_prefix_attrs
);
2985 decl_attributes (&d
, chainon (postfix_attrs
,
2986 all_prefix_attrs
), 0);
2987 DECL_CHAIN (d
) = decls
;
2989 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2990 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2993 all_prefix_attrs
= prefix_attrs
;
2994 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2995 c_parser_consume_token (parser
);
2996 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2997 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2999 /* Semicolon consumed in caller. */
3004 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3010 c_parser_error (parser
,
3011 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3012 "%<__attribute__%>");
3019 /* Parse a typeof specifier (a GNU extension).
3022 typeof ( expression )
3023 typeof ( type-name )
3026 static struct c_typespec
3027 c_parser_typeof_specifier (c_parser
*parser
)
3029 struct c_typespec ret
;
3030 ret
.kind
= ctsk_typeof
;
3031 ret
.spec
= error_mark_node
;
3032 ret
.expr
= NULL_TREE
;
3033 ret
.expr_const_operands
= true;
3034 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3035 c_parser_consume_token (parser
);
3036 c_inhibit_evaluation_warnings
++;
3038 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3040 c_inhibit_evaluation_warnings
--;
3044 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3046 struct c_type_name
*type
= c_parser_type_name (parser
);
3047 c_inhibit_evaluation_warnings
--;
3051 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3052 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3058 location_t here
= c_parser_peek_token (parser
)->location
;
3059 struct c_expr expr
= c_parser_expression (parser
);
3060 c_inhibit_evaluation_warnings
--;
3062 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3063 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3064 error_at (here
, "%<typeof%> applied to a bit-field");
3065 mark_exp_read (expr
.value
);
3066 ret
.spec
= TREE_TYPE (expr
.value
);
3067 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3068 /* This is returned with the type so that when the type is
3069 evaluated, this can be evaluated. */
3071 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3072 pop_maybe_used (was_vm
);
3073 /* For use in macros such as those in <stdatomic.h>, remove all
3074 qualifiers from atomic types. (const can be an issue for more macros
3075 using typeof than just the <stdatomic.h> ones.) */
3076 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3077 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3079 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3083 /* Parse an alignment-specifier.
3087 alignment-specifier:
3088 _Alignas ( type-name )
3089 _Alignas ( constant-expression )
3093 c_parser_alignas_specifier (c_parser
* parser
)
3095 tree ret
= error_mark_node
;
3096 location_t loc
= c_parser_peek_token (parser
)->location
;
3097 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3098 c_parser_consume_token (parser
);
3100 pedwarn_c99 (loc
, OPT_Wpedantic
,
3101 "ISO C99 does not support %<_Alignas%>");
3103 pedwarn_c99 (loc
, OPT_Wpedantic
,
3104 "ISO C90 does not support %<_Alignas%>");
3105 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3107 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3109 struct c_type_name
*type
= c_parser_type_name (parser
);
3111 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3115 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3116 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3120 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3121 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3122 be redeclared; otherwise it may not. KIND indicates which kind of
3123 declarator is wanted. Returns a valid declarator except in the
3124 case of a syntax error in which case NULL is returned. *SEEN_ID is
3125 set to true if an identifier being declared is seen; this is used
3126 to diagnose bad forms of abstract array declarators and to
3127 determine whether an identifier list is syntactically permitted.
3130 pointer[opt] direct-declarator
3134 ( attributes[opt] declarator )
3135 direct-declarator array-declarator
3136 direct-declarator ( parameter-type-list )
3137 direct-declarator ( identifier-list[opt] )
3140 * type-qualifier-list[opt]
3141 * type-qualifier-list[opt] pointer
3143 type-qualifier-list:
3146 type-qualifier-list type-qualifier
3147 type-qualifier-list attributes
3150 [ type-qualifier-list[opt] assignment-expression[opt] ]
3151 [ static type-qualifier-list[opt] assignment-expression ]
3152 [ type-qualifier-list static assignment-expression ]
3153 [ type-qualifier-list[opt] * ]
3155 parameter-type-list:
3157 parameter-list , ...
3160 parameter-declaration
3161 parameter-list , parameter-declaration
3163 parameter-declaration:
3164 declaration-specifiers declarator attributes[opt]
3165 declaration-specifiers abstract-declarator[opt] attributes[opt]
3169 identifier-list , identifier
3171 abstract-declarator:
3173 pointer[opt] direct-abstract-declarator
3175 direct-abstract-declarator:
3176 ( attributes[opt] abstract-declarator )
3177 direct-abstract-declarator[opt] array-declarator
3178 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3183 direct-declarator ( parameter-forward-declarations
3184 parameter-type-list[opt] )
3186 direct-abstract-declarator:
3187 direct-abstract-declarator[opt] ( parameter-forward-declarations
3188 parameter-type-list[opt] )
3190 parameter-forward-declarations:
3192 parameter-forward-declarations parameter-list ;
3194 The uses of attributes shown above are GNU extensions.
3196 Some forms of array declarator are not included in C99 in the
3197 syntax for abstract declarators; these are disallowed elsewhere.
3198 This may be a defect (DR#289).
3200 This function also accepts an omitted abstract declarator as being
3201 an abstract declarator, although not part of the formal syntax. */
3203 static struct c_declarator
*
3204 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3207 /* Parse any initial pointer part. */
3208 if (c_parser_next_token_is (parser
, CPP_MULT
))
3210 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3211 struct c_declarator
*inner
;
3212 c_parser_consume_token (parser
);
3213 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3214 false, false, cla_prefer_id
);
3215 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3219 return make_pointer_declarator (quals_attrs
, inner
);
3221 /* Now we have a direct declarator, direct abstract declarator or
3222 nothing (which counts as a direct abstract declarator here). */
3223 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3226 /* Parse a direct declarator or direct abstract declarator; arguments
3227 as c_parser_declarator. */
3229 static struct c_declarator
*
3230 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3233 /* The direct declarator must start with an identifier (possibly
3234 omitted) or a parenthesized declarator (possibly abstract). In
3235 an ordinary declarator, initial parentheses must start a
3236 parenthesized declarator. In an abstract declarator or parameter
3237 declarator, they could start a parenthesized declarator or a
3238 parameter list. To tell which, the open parenthesis and any
3239 following attributes must be read. If a declaration specifier
3240 follows, then it is a parameter list; if the specifier is a
3241 typedef name, there might be an ambiguity about redeclaring it,
3242 which is resolved in the direction of treating it as a typedef
3243 name. If a close parenthesis follows, it is also an empty
3244 parameter list, as the syntax does not permit empty abstract
3245 declarators. Otherwise, it is a parenthesized declarator (in
3246 which case the analysis may be repeated inside it, recursively).
3248 ??? There is an ambiguity in a parameter declaration "int
3249 (__attribute__((foo)) x)", where x is not a typedef name: it
3250 could be an abstract declarator for a function, or declare x with
3251 parentheses. The proper resolution of this ambiguity needs
3252 documenting. At present we follow an accident of the old
3253 parser's implementation, whereby the first parameter must have
3254 some declaration specifiers other than just attributes. Thus as
3255 a parameter declaration it is treated as a parenthesized
3256 parameter named x, and as an abstract declarator it is
3259 ??? Also following the old parser, attributes inside an empty
3260 parameter list are ignored, making it a list not yielding a
3261 prototype, rather than giving an error or making it have one
3262 parameter with implicit type int.
3264 ??? Also following the old parser, typedef names may be
3265 redeclared in declarators, but not Objective-C class names. */
3267 if (kind
!= C_DTR_ABSTRACT
3268 && c_parser_next_token_is (parser
, CPP_NAME
)
3270 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3271 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3272 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3274 struct c_declarator
*inner
3275 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3277 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3278 c_parser_consume_token (parser
);
3279 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3282 if (kind
!= C_DTR_NORMAL
3283 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3285 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3286 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3289 /* Either we are at the end of an abstract declarator, or we have
3292 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3295 struct c_declarator
*inner
;
3296 c_parser_consume_token (parser
);
3297 attrs
= c_parser_attributes (parser
);
3298 if (kind
!= C_DTR_NORMAL
3299 && (c_parser_next_token_starts_declspecs (parser
)
3300 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3302 struct c_arg_info
*args
3303 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3310 = build_function_declarator (args
,
3311 build_id_declarator (NULL_TREE
));
3312 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3316 /* A parenthesized declarator. */
3317 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3318 if (inner
!= NULL
&& attrs
!= NULL
)
3319 inner
= build_attrs_declarator (attrs
, inner
);
3320 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3322 c_parser_consume_token (parser
);
3326 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3330 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3337 if (kind
== C_DTR_NORMAL
)
3339 c_parser_error (parser
, "expected identifier or %<(%>");
3343 return build_id_declarator (NULL_TREE
);
3347 /* Parse part of a direct declarator or direct abstract declarator,
3348 given that some (in INNER) has already been parsed; ID_PRESENT is
3349 true if an identifier is present, false for an abstract
3352 static struct c_declarator
*
3353 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3354 struct c_declarator
*inner
)
3356 /* Parse a sequence of array declarators and parameter lists. */
3357 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3359 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3360 struct c_declarator
*declarator
;
3361 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3364 struct c_expr dimen
;
3365 dimen
.value
= NULL_TREE
;
3366 dimen
.original_code
= ERROR_MARK
;
3367 dimen
.original_type
= NULL_TREE
;
3368 c_parser_consume_token (parser
);
3369 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3370 false, false, cla_prefer_id
);
3371 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3373 c_parser_consume_token (parser
);
3374 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3375 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3376 false, false, cla_prefer_id
);
3377 if (!quals_attrs
->declspecs_seen_p
)
3379 /* If "static" is present, there must be an array dimension.
3380 Otherwise, there may be a dimension, "*", or no
3385 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3389 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3391 dimen
.value
= NULL_TREE
;
3394 else if (flag_cilkplus
3395 && c_parser_next_token_is (parser
, CPP_COLON
))
3397 dimen
.value
= error_mark_node
;
3399 error_at (c_parser_peek_token (parser
)->location
,
3400 "array notations cannot be used in declaration");
3401 c_parser_consume_token (parser
);
3403 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3405 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3407 dimen
.value
= NULL_TREE
;
3409 c_parser_consume_token (parser
);
3414 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3420 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3423 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3424 c_parser_consume_token (parser
);
3425 else if (flag_cilkplus
3426 && c_parser_next_token_is (parser
, CPP_COLON
))
3428 error_at (c_parser_peek_token (parser
)->location
,
3429 "array notations cannot be used in declaration");
3430 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3435 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3440 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3441 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3442 static_seen
, star_seen
);
3443 if (declarator
== NULL
)
3445 inner
= set_array_declarator_inner (declarator
, inner
);
3446 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3448 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3451 struct c_arg_info
*args
;
3452 c_parser_consume_token (parser
);
3453 attrs
= c_parser_attributes (parser
);
3454 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3459 inner
= build_function_declarator (args
, inner
);
3460 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3466 /* Parse a parameter list or identifier list, including the closing
3467 parenthesis but not the opening one. ATTRS are the attributes at
3468 the start of the list. ID_LIST_OK is true if an identifier list is
3469 acceptable; such a list must not have attributes at the start. */
3471 static struct c_arg_info
*
3472 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3475 declare_parm_level ();
3476 /* If the list starts with an identifier, it is an identifier list.
3477 Otherwise, it is either a prototype list or an empty list. */
3480 && c_parser_next_token_is (parser
, CPP_NAME
)
3481 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3483 /* Look ahead to detect typos in type names. */
3484 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3485 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3486 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3487 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3489 tree list
= NULL_TREE
, *nextp
= &list
;
3490 while (c_parser_next_token_is (parser
, CPP_NAME
)
3491 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3493 *nextp
= build_tree_list (NULL_TREE
,
3494 c_parser_peek_token (parser
)->value
);
3495 nextp
= & TREE_CHAIN (*nextp
);
3496 c_parser_consume_token (parser
);
3497 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3499 c_parser_consume_token (parser
);
3500 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3502 c_parser_error (parser
, "expected identifier");
3506 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3508 struct c_arg_info
*ret
= build_arg_info ();
3510 c_parser_consume_token (parser
);
3516 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3524 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3531 /* Parse a parameter list (possibly empty), including the closing
3532 parenthesis but not the opening one. ATTRS are the attributes at
3533 the start of the list. EXPR is NULL or an expression that needs to
3534 be evaluated for the side effects of array size expressions in the
3537 static struct c_arg_info
*
3538 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3540 bool bad_parm
= false;
3542 /* ??? Following the old parser, forward parameter declarations may
3543 use abstract declarators, and if no real parameter declarations
3544 follow the forward declarations then this is not diagnosed. Also
3545 note as above that attributes are ignored as the only contents of
3546 the parentheses, or as the only contents after forward
3548 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3550 struct c_arg_info
*ret
= build_arg_info ();
3551 c_parser_consume_token (parser
);
3554 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3556 struct c_arg_info
*ret
= build_arg_info ();
3558 if (flag_allow_parameterless_variadic_functions
)
3560 /* F (...) is allowed. */
3561 ret
->types
= NULL_TREE
;
3565 /* Suppress -Wold-style-definition for this case. */
3566 ret
->types
= error_mark_node
;
3567 error_at (c_parser_peek_token (parser
)->location
,
3568 "ISO C requires a named argument before %<...%>");
3570 c_parser_consume_token (parser
);
3571 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3573 c_parser_consume_token (parser
);
3578 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3583 /* Nonempty list of parameters, either terminated with semicolon
3584 (forward declarations; recurse) or with close parenthesis (normal
3585 function) or with ", ... )" (variadic function). */
3588 /* Parse a parameter. */
3589 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3594 push_parm_decl (parm
, &expr
);
3595 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3598 c_parser_consume_token (parser
);
3599 mark_forward_parm_decls ();
3600 new_attrs
= c_parser_attributes (parser
);
3601 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3603 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3605 c_parser_consume_token (parser
);
3609 return get_parm_info (false, expr
);
3611 if (!c_parser_require (parser
, CPP_COMMA
,
3612 "expected %<;%>, %<,%> or %<)%>"))
3614 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3617 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3619 c_parser_consume_token (parser
);
3620 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3622 c_parser_consume_token (parser
);
3626 return get_parm_info (true, expr
);
3630 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3638 /* Parse a parameter declaration. ATTRS are the attributes at the
3639 start of the declaration if it is the first parameter. */
3641 static struct c_parm
*
3642 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3644 struct c_declspecs
*specs
;
3645 struct c_declarator
*declarator
;
3647 tree postfix_attrs
= NULL_TREE
;
3650 /* Accept #pragmas between parameter declarations. */
3651 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3652 c_parser_pragma (parser
, pragma_param
);
3654 if (!c_parser_next_token_starts_declspecs (parser
))
3656 c_token
*token
= c_parser_peek_token (parser
);
3659 c_parser_set_source_position_from_token (token
);
3660 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3662 error_at (token
->location
, "unknown type name %qE", token
->value
);
3663 parser
->error
= true;
3665 /* ??? In some Objective-C cases '...' isn't applicable so there
3666 should be a different message. */
3668 c_parser_error (parser
,
3669 "expected declaration specifiers or %<...%>");
3670 c_parser_skip_to_end_of_parameter (parser
);
3673 specs
= build_null_declspecs ();
3676 declspecs_add_attrs (input_location
, specs
, attrs
);
3679 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3680 cla_nonabstract_decl
);
3681 finish_declspecs (specs
);
3682 pending_xref_error ();
3683 prefix_attrs
= specs
->attrs
;
3684 specs
->attrs
= NULL_TREE
;
3685 declarator
= c_parser_declarator (parser
,
3686 specs
->typespec_kind
!= ctsk_none
,
3687 C_DTR_PARM
, &dummy
);
3688 if (declarator
== NULL
)
3690 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3693 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3694 postfix_attrs
= c_parser_attributes (parser
);
3695 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3699 /* Parse a string literal in an asm expression. It should not be
3700 translated, and wide string literals are an error although
3701 permitted by the syntax. This is a GNU extension.
3706 ??? At present, following the old parser, the caller needs to have
3707 set lex_untranslated_string to 1. It would be better to follow the
3708 C++ parser rather than using this kludge. */
3711 c_parser_asm_string_literal (c_parser
*parser
)
3714 int save_flag
= warn_overlength_strings
;
3715 warn_overlength_strings
= 0;
3716 if (c_parser_next_token_is (parser
, CPP_STRING
))
3718 str
= c_parser_peek_token (parser
)->value
;
3719 c_parser_consume_token (parser
);
3721 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3723 error_at (c_parser_peek_token (parser
)->location
,
3724 "wide string literal in %<asm%>");
3725 str
= build_string (1, "");
3726 c_parser_consume_token (parser
);
3730 c_parser_error (parser
, "expected string literal");
3733 warn_overlength_strings
= save_flag
;
3737 /* Parse a simple asm expression. This is used in restricted
3738 contexts, where a full expression with inputs and outputs does not
3739 make sense. This is a GNU extension.
3742 asm ( asm-string-literal )
3746 c_parser_simple_asm_expr (c_parser
*parser
)
3749 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3750 /* ??? Follow the C++ parser rather than using the
3751 lex_untranslated_string kludge. */
3752 parser
->lex_untranslated_string
= true;
3753 c_parser_consume_token (parser
);
3754 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3756 parser
->lex_untranslated_string
= false;
3759 str
= c_parser_asm_string_literal (parser
);
3760 parser
->lex_untranslated_string
= false;
3761 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3763 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3770 c_parser_attribute_any_word (c_parser
*parser
)
3772 tree attr_name
= NULL_TREE
;
3774 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3776 /* ??? See comment above about what keywords are accepted here. */
3778 switch (c_parser_peek_token (parser
)->keyword
)
3808 case RID_TRANSACTION_ATOMIC
:
3809 case RID_TRANSACTION_CANCEL
:
3825 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3826 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3828 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3829 attr_name
= c_parser_peek_token (parser
)->value
;
3834 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3835 "__vector" or "__vector__." */
3838 is_cilkplus_vector_p (tree name
)
3840 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3845 #define CILK_SIMD_FN_CLAUSE_MASK \
3846 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3847 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3848 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3849 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3850 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3852 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3853 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3854 pushed into the token list.
3857 vector (<vector attributes>). */
3860 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3862 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3864 int paren_scope
= 0;
3865 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3866 /* Consume the "vector" token. */
3867 c_parser_consume_token (parser
);
3869 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3871 c_parser_consume_token (parser
);
3874 while (paren_scope
> 0)
3876 c_token
*token
= c_parser_peek_token (parser
);
3877 if (token
->type
== CPP_OPEN_PAREN
)
3879 else if (token
->type
== CPP_CLOSE_PAREN
)
3881 /* Do not push the last ')' since we are not pushing the '('. */
3882 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3883 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3884 c_parser_consume_token (parser
);
3887 /* Since we are converting an attribute to a pragma, we need to end the
3888 attribute with PRAGMA_EOL. */
3890 memset (&eol_token
, 0, sizeof (eol_token
));
3891 eol_token
.type
= CPP_PRAGMA_EOL
;
3892 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3895 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3898 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3900 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3902 /* c_parser_attributes is called in several places, so if these EOF
3903 tokens are already inserted, then don't do them again. */
3904 if (last_token
.type
== CPP_EOF
)
3907 /* Two CPP_EOF token are added as a safety net since the normal C
3908 front-end has two token look-ahead. */
3910 eof_token
.type
= CPP_EOF
;
3911 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3912 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3915 /* Parse (possibly empty) attributes. This is a GNU extension.
3919 attributes attribute
3922 __attribute__ ( ( attribute-list ) )
3926 attribute_list , attrib
3931 any-word ( identifier )
3932 any-word ( identifier , nonempty-expr-list )
3933 any-word ( expr-list )
3935 where the "identifier" must not be declared as a type, and
3936 "any-word" may be any identifier (including one declared as a
3937 type), a reserved word storage class specifier, type specifier or
3938 type qualifier. ??? This still leaves out most reserved keywords
3939 (following the old parser), shouldn't we include them, and why not
3940 allow identifiers declared as types to start the arguments? */
3943 c_parser_attributes (c_parser
*parser
)
3945 tree attrs
= NULL_TREE
;
3946 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3948 /* ??? Follow the C++ parser rather than using the
3949 lex_untranslated_string kludge. */
3950 parser
->lex_untranslated_string
= true;
3951 c_parser_consume_token (parser
);
3952 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3954 parser
->lex_untranslated_string
= false;
3957 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3959 parser
->lex_untranslated_string
= false;
3960 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3963 /* Parse the attribute list. */
3964 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3965 || c_parser_next_token_is (parser
, CPP_NAME
)
3966 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3968 tree attr
, attr_name
, attr_args
;
3969 vec
<tree
, va_gc
> *expr_list
;
3970 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3972 c_parser_consume_token (parser
);
3976 attr_name
= c_parser_attribute_any_word (parser
);
3977 if (attr_name
== NULL
)
3979 if (is_cilkplus_vector_p (attr_name
))
3981 c_token
*v_token
= c_parser_peek_token (parser
);
3982 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3985 c_parser_consume_token (parser
);
3986 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3988 attr
= build_tree_list (attr_name
, NULL_TREE
);
3989 attrs
= chainon (attrs
, attr
);
3992 c_parser_consume_token (parser
);
3993 /* Parse the attribute contents. If they start with an
3994 identifier which is followed by a comma or close
3995 parenthesis, then the arguments start with that
3996 identifier; otherwise they are an expression list.
3997 In objective-c the identifier may be a classname. */
3998 if (c_parser_next_token_is (parser
, CPP_NAME
)
3999 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4000 || (c_dialect_objc ()
4001 && c_parser_peek_token (parser
)->id_kind
4003 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4004 || (c_parser_peek_2nd_token (parser
)->type
4005 == CPP_CLOSE_PAREN
))
4006 && (attribute_takes_identifier_p (attr_name
)
4007 || (c_dialect_objc ()
4008 && c_parser_peek_token (parser
)->id_kind
4009 == C_ID_CLASSNAME
)))
4011 tree arg1
= c_parser_peek_token (parser
)->value
;
4012 c_parser_consume_token (parser
);
4013 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4014 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4018 c_parser_consume_token (parser
);
4019 expr_list
= c_parser_expr_list (parser
, false, true,
4020 NULL
, NULL
, NULL
, NULL
);
4021 tree_list
= build_tree_list_vec (expr_list
);
4022 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4023 release_tree_vector (expr_list
);
4028 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4029 attr_args
= NULL_TREE
;
4032 expr_list
= c_parser_expr_list (parser
, false, true,
4033 NULL
, NULL
, NULL
, NULL
);
4034 attr_args
= build_tree_list_vec (expr_list
);
4035 release_tree_vector (expr_list
);
4038 attr
= build_tree_list (attr_name
, attr_args
);
4039 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4040 c_parser_consume_token (parser
);
4043 parser
->lex_untranslated_string
= false;
4044 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4048 attrs
= chainon (attrs
, attr
);
4050 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4051 c_parser_consume_token (parser
);
4054 parser
->lex_untranslated_string
= false;
4055 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4059 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4060 c_parser_consume_token (parser
);
4063 parser
->lex_untranslated_string
= false;
4064 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4068 parser
->lex_untranslated_string
= false;
4071 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4072 c_finish_cilk_simd_fn_tokens (parser
);
4076 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4079 specifier-qualifier-list abstract-declarator[opt]
4082 static struct c_type_name
*
4083 c_parser_type_name (c_parser
*parser
)
4085 struct c_declspecs
*specs
= build_null_declspecs ();
4086 struct c_declarator
*declarator
;
4087 struct c_type_name
*ret
;
4089 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4091 if (!specs
->declspecs_seen_p
)
4093 c_parser_error (parser
, "expected specifier-qualifier-list");
4096 if (specs
->type
!= error_mark_node
)
4098 pending_xref_error ();
4099 finish_declspecs (specs
);
4101 declarator
= c_parser_declarator (parser
,
4102 specs
->typespec_kind
!= ctsk_none
,
4103 C_DTR_ABSTRACT
, &dummy
);
4104 if (declarator
== NULL
)
4106 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4108 ret
->declarator
= declarator
;
4112 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4115 assignment-expression
4116 { initializer-list }
4117 { initializer-list , }
4120 designation[opt] initializer
4121 initializer-list , designation[opt] initializer
4128 designator-list designator
4135 [ constant-expression ]
4147 [ constant-expression ... constant-expression ]
4149 Any expression without commas is accepted in the syntax for the
4150 constant-expressions, with non-constant expressions rejected later.
4152 This function is only used for top-level initializers; for nested
4153 ones, see c_parser_initval. */
4155 static struct c_expr
4156 c_parser_initializer (c_parser
*parser
)
4158 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4159 return c_parser_braced_init (parser
, NULL_TREE
, false);
4163 location_t loc
= c_parser_peek_token (parser
)->location
;
4164 ret
= c_parser_expr_no_commas (parser
, NULL
);
4165 if (TREE_CODE (ret
.value
) != STRING_CST
4166 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4167 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4172 /* Parse a braced initializer list. TYPE is the type specified for a
4173 compound literal, and NULL_TREE for other initializers and for
4174 nested braced lists. NESTED_P is true for nested braced lists,
4175 false for the list of a compound literal or the list that is the
4176 top-level initializer in a declaration. */
4178 static struct c_expr
4179 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4182 struct obstack braced_init_obstack
;
4183 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4184 gcc_obstack_init (&braced_init_obstack
);
4185 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4186 c_parser_consume_token (parser
);
4188 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4190 really_start_incremental_init (type
);
4191 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4193 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4197 /* Parse a non-empty initializer list, possibly with a trailing
4201 c_parser_initelt (parser
, &braced_init_obstack
);
4204 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4205 c_parser_consume_token (parser
);
4208 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4212 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4214 ret
.value
= error_mark_node
;
4215 ret
.original_code
= ERROR_MARK
;
4216 ret
.original_type
= NULL
;
4217 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4218 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4219 obstack_free (&braced_init_obstack
, NULL
);
4222 c_parser_consume_token (parser
);
4223 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4224 obstack_free (&braced_init_obstack
, NULL
);
4228 /* Parse a nested initializer, including designators. */
4231 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4233 /* Parse any designator or designator list. A single array
4234 designator may have the subsequent "=" omitted in GNU C, but a
4235 longer list or a structure member designator may not. */
4236 if (c_parser_next_token_is (parser
, CPP_NAME
)
4237 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4239 /* Old-style structure member designator. */
4240 set_init_label (c_parser_peek_token (parser
)->location
,
4241 c_parser_peek_token (parser
)->value
,
4242 braced_init_obstack
);
4243 /* Use the colon as the error location. */
4244 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4245 "obsolete use of designated initializer with %<:%>");
4246 c_parser_consume_token (parser
);
4247 c_parser_consume_token (parser
);
4251 /* des_seen is 0 if there have been no designators, 1 if there
4252 has been a single array designator and 2 otherwise. */
4254 /* Location of a designator. */
4255 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4256 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4257 || c_parser_next_token_is (parser
, CPP_DOT
))
4259 int des_prev
= des_seen
;
4261 des_loc
= c_parser_peek_token (parser
)->location
;
4264 if (c_parser_next_token_is (parser
, CPP_DOT
))
4267 c_parser_consume_token (parser
);
4268 if (c_parser_next_token_is (parser
, CPP_NAME
))
4270 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4271 braced_init_obstack
);
4272 c_parser_consume_token (parser
);
4277 init
.value
= error_mark_node
;
4278 init
.original_code
= ERROR_MARK
;
4279 init
.original_type
= NULL
;
4280 c_parser_error (parser
, "expected identifier");
4281 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4282 process_init_element (input_location
, init
, false,
4283 braced_init_obstack
);
4290 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4291 location_t array_index_loc
= UNKNOWN_LOCATION
;
4292 /* ??? Following the old parser, [ objc-receiver
4293 objc-message-args ] is accepted as an initializer,
4294 being distinguished from a designator by what follows
4295 the first assignment expression inside the square
4296 brackets, but after a first array designator a
4297 subsequent square bracket is for Objective-C taken to
4298 start an expression, using the obsolete form of
4299 designated initializer without '=', rather than
4300 possibly being a second level of designation: in LALR
4301 terms, the '[' is shifted rather than reducing
4302 designator to designator-list. */
4303 if (des_prev
== 1 && c_dialect_objc ())
4305 des_seen
= des_prev
;
4308 if (des_prev
== 0 && c_dialect_objc ())
4310 /* This might be an array designator or an
4311 Objective-C message expression. If the former,
4312 continue parsing here; if the latter, parse the
4313 remainder of the initializer given the starting
4314 primary-expression. ??? It might make sense to
4315 distinguish when des_prev == 1 as well; see
4316 previous comment. */
4318 struct c_expr mexpr
;
4319 c_parser_consume_token (parser
);
4320 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4321 && ((c_parser_peek_token (parser
)->id_kind
4323 || (c_parser_peek_token (parser
)->id_kind
4324 == C_ID_CLASSNAME
)))
4326 /* Type name receiver. */
4327 tree id
= c_parser_peek_token (parser
)->value
;
4328 c_parser_consume_token (parser
);
4329 rec
= objc_get_class_reference (id
);
4330 goto parse_message_args
;
4332 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4333 mark_exp_read (first
);
4334 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4335 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4336 goto array_desig_after_first
;
4337 /* Expression receiver. So far only one part
4338 without commas has been parsed; there might be
4339 more of the expression. */
4341 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4344 location_t comma_loc
, exp_loc
;
4345 comma_loc
= c_parser_peek_token (parser
)->location
;
4346 c_parser_consume_token (parser
);
4347 exp_loc
= c_parser_peek_token (parser
)->location
;
4348 next
= c_parser_expr_no_commas (parser
, NULL
);
4349 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4351 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4354 /* Now parse the objc-message-args. */
4355 args
= c_parser_objc_message_args (parser
);
4356 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4359 = objc_build_message_expr (rec
, args
);
4360 mexpr
.original_code
= ERROR_MARK
;
4361 mexpr
.original_type
= NULL
;
4362 /* Now parse and process the remainder of the
4363 initializer, starting with this message
4364 expression as a primary-expression. */
4365 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4368 c_parser_consume_token (parser
);
4369 array_index_loc
= c_parser_peek_token (parser
)->location
;
4370 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4371 mark_exp_read (first
);
4372 array_desig_after_first
:
4373 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4375 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4376 c_parser_consume_token (parser
);
4377 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4378 mark_exp_read (second
);
4382 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4384 c_parser_consume_token (parser
);
4385 set_init_index (array_index_loc
, first
, second
,
4386 braced_init_obstack
);
4388 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4389 "ISO C forbids specifying range of elements to initialize");
4392 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4398 if (c_parser_next_token_is (parser
, CPP_EQ
))
4400 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4401 "ISO C90 forbids specifying subobject "
4403 c_parser_consume_token (parser
);
4408 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4409 "obsolete use of designated initializer without %<=%>");
4413 init
.value
= error_mark_node
;
4414 init
.original_code
= ERROR_MARK
;
4415 init
.original_type
= NULL
;
4416 c_parser_error (parser
, "expected %<=%>");
4417 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4418 process_init_element (input_location
, init
, false,
4419 braced_init_obstack
);
4425 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4428 /* Parse a nested initializer; as c_parser_initializer but parses
4429 initializers within braced lists, after any designators have been
4430 applied. If AFTER is not NULL then it is an Objective-C message
4431 expression which is the primary-expression starting the
4435 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4436 struct obstack
* braced_init_obstack
)
4439 gcc_assert (!after
|| c_dialect_objc ());
4440 location_t loc
= c_parser_peek_token (parser
)->location
;
4442 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4443 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4446 init
= c_parser_expr_no_commas (parser
, after
);
4447 if (init
.value
!= NULL_TREE
4448 && TREE_CODE (init
.value
) != STRING_CST
4449 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4450 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4452 process_init_element (loc
, init
, false, braced_init_obstack
);
4455 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4459 { block-item-list[opt] }
4460 { label-declarations block-item-list }
4464 block-item-list block-item
4476 { label-declarations block-item-list }
4479 __extension__ nested-declaration
4480 nested-function-definition
4484 label-declarations label-declaration
4487 __label__ identifier-list ;
4489 Allowing the mixing of declarations and code is new in C99. The
4490 GNU syntax also permits (not shown above) labels at the end of
4491 compound statements, which yield an error. We don't allow labels
4492 on declarations; this might seem like a natural extension, but
4493 there would be a conflict between attributes on the label and
4494 prefix attributes on the declaration. ??? The syntax follows the
4495 old parser in requiring something after label declarations.
4496 Although they are erroneous if the labels declared aren't defined,
4497 is it useful for the syntax to be this way?
4518 cancellation-point-directive */
4521 c_parser_compound_statement (c_parser
*parser
)
4524 location_t brace_loc
;
4525 brace_loc
= c_parser_peek_token (parser
)->location
;
4526 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4528 /* Ensure a scope is entered and left anyway to avoid confusion
4529 if we have just prepared to enter a function body. */
4530 stmt
= c_begin_compound_stmt (true);
4531 c_end_compound_stmt (brace_loc
, stmt
, true);
4532 return error_mark_node
;
4534 stmt
= c_begin_compound_stmt (true);
4535 c_parser_compound_statement_nostart (parser
);
4537 /* If the compound stmt contains array notations, then we expand them. */
4538 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4539 stmt
= expand_array_notation_exprs (stmt
);
4540 return c_end_compound_stmt (brace_loc
, stmt
, true);
4543 /* Parse a compound statement except for the opening brace. This is
4544 used for parsing both compound statements and statement expressions
4545 (which follow different paths to handling the opening). */
4548 c_parser_compound_statement_nostart (c_parser
*parser
)
4550 bool last_stmt
= false;
4551 bool last_label
= false;
4552 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4553 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4554 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4556 c_parser_consume_token (parser
);
4559 mark_valid_location_for_stdc_pragma (true);
4560 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4562 /* Read zero or more forward-declarations for labels that nested
4563 functions can jump to. */
4564 mark_valid_location_for_stdc_pragma (false);
4565 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4567 label_loc
= c_parser_peek_token (parser
)->location
;
4568 c_parser_consume_token (parser
);
4569 /* Any identifiers, including those declared as type names,
4574 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4576 c_parser_error (parser
, "expected identifier");
4580 = declare_label (c_parser_peek_token (parser
)->value
);
4581 C_DECLARED_LABEL_FLAG (label
) = 1;
4582 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4583 c_parser_consume_token (parser
);
4584 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4585 c_parser_consume_token (parser
);
4589 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4591 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4593 /* We must now have at least one statement, label or declaration. */
4594 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4596 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4597 c_parser_error (parser
, "expected declaration or statement");
4598 c_parser_consume_token (parser
);
4601 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4603 location_t loc
= c_parser_peek_token (parser
)->location
;
4604 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4605 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4606 || (c_parser_next_token_is (parser
, CPP_NAME
)
4607 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4609 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4610 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4612 label_loc
= c_parser_peek_token (parser
)->location
;
4615 mark_valid_location_for_stdc_pragma (false);
4616 c_parser_label (parser
);
4618 else if (!last_label
4619 && c_parser_next_tokens_start_declaration (parser
))
4622 mark_valid_location_for_stdc_pragma (false);
4623 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4626 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4627 "ISO C90 forbids mixed declarations and code");
4630 else if (!last_label
4631 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4633 /* __extension__ can start a declaration, but is also an
4634 unary operator that can start an expression. Consume all
4635 but the last of a possible series of __extension__ to
4637 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4638 && (c_parser_peek_2nd_token (parser
)->keyword
4640 c_parser_consume_token (parser
);
4641 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4644 ext
= disable_extension_diagnostics ();
4645 c_parser_consume_token (parser
);
4647 mark_valid_location_for_stdc_pragma (false);
4648 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4650 /* Following the old parser, __extension__ does not
4651 disable this diagnostic. */
4652 restore_extension_diagnostics (ext
);
4654 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4655 "ISO C90 forbids mixed declarations and code");
4661 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4663 /* External pragmas, and some omp pragmas, are not associated
4664 with regular c code, and so are not to be considered statements
4665 syntactically. This ensures that the user doesn't put them
4666 places that would turn into syntax errors if the directive
4668 if (c_parser_pragma (parser
, pragma_compound
))
4669 last_label
= false, last_stmt
= true;
4671 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4673 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4674 c_parser_error (parser
, "expected declaration or statement");
4677 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4679 if (parser
->in_if_block
)
4681 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4682 error_at (loc
, """expected %<}%> before %<else%>");
4687 error_at (loc
, "%<else%> without a previous %<if%>");
4688 c_parser_consume_token (parser
);
4697 mark_valid_location_for_stdc_pragma (false);
4698 c_parser_statement_after_labels (parser
);
4701 parser
->error
= false;
4704 error_at (label_loc
, "label at end of compound statement");
4705 c_parser_consume_token (parser
);
4706 /* Restore the value we started with. */
4707 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4710 /* Parse all consecutive labels. */
4713 c_parser_all_labels (c_parser
*parser
)
4715 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4716 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4717 || (c_parser_next_token_is (parser
, CPP_NAME
)
4718 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4719 c_parser_label (parser
);
4722 /* Parse a label (C90 6.6.1, C99 6.8.1).
4725 identifier : attributes[opt]
4726 case constant-expression :
4732 case constant-expression ... constant-expression :
4734 The use of attributes on labels is a GNU extension. The syntax in
4735 GNU C accepts any expressions without commas, non-constant
4736 expressions being rejected later. */
4739 c_parser_label (c_parser
*parser
)
4741 location_t loc1
= c_parser_peek_token (parser
)->location
;
4742 tree label
= NULL_TREE
;
4743 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4746 c_parser_consume_token (parser
);
4747 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4748 if (c_parser_next_token_is (parser
, CPP_COLON
))
4750 c_parser_consume_token (parser
);
4751 label
= do_case (loc1
, exp1
, NULL_TREE
);
4753 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4755 c_parser_consume_token (parser
);
4756 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4757 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4758 label
= do_case (loc1
, exp1
, exp2
);
4761 c_parser_error (parser
, "expected %<:%> or %<...%>");
4763 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4765 c_parser_consume_token (parser
);
4766 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4767 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4771 tree name
= c_parser_peek_token (parser
)->value
;
4774 location_t loc2
= c_parser_peek_token (parser
)->location
;
4775 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4776 c_parser_consume_token (parser
);
4777 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4778 c_parser_consume_token (parser
);
4779 attrs
= c_parser_attributes (parser
);
4780 tlab
= define_label (loc2
, name
);
4783 decl_attributes (&tlab
, attrs
, 0);
4784 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4789 if (c_parser_next_tokens_start_declaration (parser
))
4791 error_at (c_parser_peek_token (parser
)->location
,
4792 "a label can only be part of a statement and "
4793 "a declaration is not a statement");
4794 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4795 /*static_assert_ok*/ true,
4796 /*empty_ok*/ true, /*nested*/ true,
4797 /*start_attr_ok*/ true, NULL
,
4803 /* Parse a statement (C90 6.6, C99 6.8).
4808 expression-statement
4816 expression-statement:
4819 selection-statement:
4823 iteration-statement:
4832 return expression[opt] ;
4845 objc-throw-statement
4846 objc-try-catch-statement
4847 objc-synchronized-statement
4849 objc-throw-statement:
4865 parallel-directive structured-block
4868 kernels-directive structured-block
4871 data-directive structured-block
4874 loop-directive structured-block
4888 parallel-for-construct
4889 parallel-for-simd-construct
4890 parallel-sections-construct
4897 parallel-directive structured-block
4900 for-directive iteration-statement
4903 simd-directive iteration-statements
4906 for-simd-directive iteration-statements
4909 sections-directive section-scope
4912 single-directive structured-block
4914 parallel-for-construct:
4915 parallel-for-directive iteration-statement
4917 parallel-for-simd-construct:
4918 parallel-for-simd-directive iteration-statement
4920 parallel-sections-construct:
4921 parallel-sections-directive section-scope
4924 master-directive structured-block
4927 critical-directive structured-block
4930 atomic-directive expression-statement
4933 ordered-directive structured-block
4935 Transactional Memory:
4938 transaction-statement
4939 transaction-cancel-statement
4943 c_parser_statement (c_parser
*parser
)
4945 c_parser_all_labels (parser
);
4946 c_parser_statement_after_labels (parser
);
4949 /* Parse a statement, other than a labeled statement. */
4952 c_parser_statement_after_labels (c_parser
*parser
)
4954 location_t loc
= c_parser_peek_token (parser
)->location
;
4955 tree stmt
= NULL_TREE
;
4956 bool in_if_block
= parser
->in_if_block
;
4957 parser
->in_if_block
= false;
4958 switch (c_parser_peek_token (parser
)->type
)
4960 case CPP_OPEN_BRACE
:
4961 add_stmt (c_parser_compound_statement (parser
));
4964 switch (c_parser_peek_token (parser
)->keyword
)
4967 c_parser_if_statement (parser
);
4970 c_parser_switch_statement (parser
);
4973 c_parser_while_statement (parser
, false);
4976 c_parser_do_statement (parser
, false);
4979 c_parser_for_statement (parser
, false);
4984 error_at (c_parser_peek_token (parser
)->location
,
4985 "-fcilkplus must be enabled to use %<_Cilk_for%>");
4986 c_parser_skip_to_end_of_block_or_statement (parser
);
4989 c_parser_cilk_for (parser
, integer_zero_node
);
4992 c_parser_consume_token (parser
);
4993 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4995 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4997 add_stmt (build_cilk_sync ());
5000 c_parser_consume_token (parser
);
5001 if (c_parser_next_token_is (parser
, CPP_NAME
))
5003 stmt
= c_finish_goto_label (loc
,
5004 c_parser_peek_token (parser
)->value
);
5005 c_parser_consume_token (parser
);
5007 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5011 c_parser_consume_token (parser
);
5012 val
= c_parser_expression (parser
);
5013 if (check_no_cilk (val
.value
,
5014 "Cilk array notation cannot be used as a computed goto expression",
5015 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5017 val
.value
= error_mark_node
;
5018 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5019 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5022 c_parser_error (parser
, "expected identifier or %<*%>");
5023 goto expect_semicolon
;
5025 c_parser_consume_token (parser
);
5026 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5027 goto expect_semicolon
;
5029 c_parser_consume_token (parser
);
5030 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5031 goto expect_semicolon
;
5033 c_parser_consume_token (parser
);
5034 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5036 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5037 c_parser_consume_token (parser
);
5041 location_t xloc
= c_parser_peek_token (parser
)->location
;
5042 struct c_expr expr
= c_parser_expression_conv (parser
);
5043 mark_exp_read (expr
.value
);
5044 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
5045 goto expect_semicolon
;
5049 stmt
= c_parser_asm_statement (parser
);
5051 case RID_TRANSACTION_ATOMIC
:
5052 case RID_TRANSACTION_RELAXED
:
5053 stmt
= c_parser_transaction (parser
,
5054 c_parser_peek_token (parser
)->keyword
);
5056 case RID_TRANSACTION_CANCEL
:
5057 stmt
= c_parser_transaction_cancel (parser
);
5058 goto expect_semicolon
;
5060 gcc_assert (c_dialect_objc ());
5061 c_parser_consume_token (parser
);
5062 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5064 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5065 c_parser_consume_token (parser
);
5069 struct c_expr expr
= c_parser_expression (parser
);
5070 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5071 if (check_no_cilk (expr
.value
,
5072 "Cilk array notation cannot be used for a throw expression",
5073 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5074 expr
.value
= error_mark_node
;
5077 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5078 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5080 goto expect_semicolon
;
5084 gcc_assert (c_dialect_objc ());
5085 c_parser_objc_try_catch_finally_statement (parser
);
5087 case RID_AT_SYNCHRONIZED
:
5088 gcc_assert (c_dialect_objc ());
5089 c_parser_objc_synchronized_statement (parser
);
5096 c_parser_consume_token (parser
);
5098 case CPP_CLOSE_PAREN
:
5099 case CPP_CLOSE_SQUARE
:
5100 /* Avoid infinite loop in error recovery:
5101 c_parser_skip_until_found stops at a closing nesting
5102 delimiter without consuming it, but here we need to consume
5103 it to proceed further. */
5104 c_parser_error (parser
, "expected statement");
5105 c_parser_consume_token (parser
);
5108 c_parser_pragma (parser
, pragma_stmt
);
5112 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5114 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5117 /* Two cases cannot and do not have line numbers associated: If stmt
5118 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5119 cannot hold line numbers. But that's OK because the statement
5120 will either be changed to a MODIFY_EXPR during gimplification of
5121 the statement expr, or discarded. If stmt was compound, but
5122 without new variables, we will have skipped the creation of a
5123 BIND and will have a bare STATEMENT_LIST. But that's OK because
5124 (recursively) all of the component statements should already have
5125 line numbers assigned. ??? Can we discard no-op statements
5127 if (CAN_HAVE_LOCATION_P (stmt
)
5128 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5129 SET_EXPR_LOCATION (stmt
, loc
);
5131 parser
->in_if_block
= in_if_block
;
5134 /* Parse the condition from an if, do, while or for statements. */
5137 c_parser_condition (c_parser
*parser
)
5139 location_t loc
= c_parser_peek_token (parser
)->location
;
5141 cond
= c_parser_expression_conv (parser
).value
;
5142 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5143 cond
= c_fully_fold (cond
, false, NULL
);
5144 if (warn_sequence_point
)
5145 verify_sequence_points (cond
);
5149 /* Parse a parenthesized condition from an if, do or while statement.
5155 c_parser_paren_condition (c_parser
*parser
)
5158 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5159 return error_mark_node
;
5160 cond
= c_parser_condition (parser
);
5161 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5165 /* Parse a statement which is a block in C99. */
5168 c_parser_c99_block_statement (c_parser
*parser
)
5170 tree block
= c_begin_compound_stmt (flag_isoc99
);
5171 location_t loc
= c_parser_peek_token (parser
)->location
;
5172 c_parser_statement (parser
);
5173 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5176 /* Parse the body of an if statement. This is just parsing a
5177 statement but (a) it is a block in C99, (b) we track whether the
5178 body is an if statement for the sake of -Wparentheses warnings, (c)
5179 we handle an empty body specially for the sake of -Wempty-body
5180 warnings, and (d) we call parser_compound_statement directly
5181 because c_parser_statement_after_labels resets
5182 parser->in_if_block. */
5185 c_parser_if_body (c_parser
*parser
, bool *if_p
, location_t if_loc
)
5187 tree block
= c_begin_compound_stmt (flag_isoc99
);
5188 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5189 c_parser_all_labels (parser
);
5190 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5191 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5193 location_t loc
= c_parser_peek_token (parser
)->location
;
5194 add_stmt (build_empty_stmt (loc
));
5195 c_parser_consume_token (parser
);
5196 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5197 warning_at (loc
, OPT_Wempty_body
,
5198 "suggest braces around empty body in an %<if%> statement");
5200 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5201 add_stmt (c_parser_compound_statement (parser
));
5204 c_parser_statement_after_labels (parser
);
5205 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5206 warn_for_misleading_indentation (if_loc
, body_loc
,
5207 c_parser_peek_token (parser
)->location
,
5208 c_parser_peek_token (parser
)->type
,
5212 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5215 /* Parse the else body of an if statement. This is just parsing a
5216 statement but (a) it is a block in C99, (b) we handle an empty body
5217 specially for the sake of -Wempty-body warnings. */
5220 c_parser_else_body (c_parser
*parser
, location_t else_loc
)
5222 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5223 tree block
= c_begin_compound_stmt (flag_isoc99
);
5224 c_parser_all_labels (parser
);
5225 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5227 location_t loc
= c_parser_peek_token (parser
)->location
;
5230 "suggest braces around empty body in an %<else%> statement");
5231 add_stmt (build_empty_stmt (loc
));
5232 c_parser_consume_token (parser
);
5236 c_parser_statement_after_labels (parser
);
5237 warn_for_misleading_indentation (else_loc
, body_loc
,
5238 c_parser_peek_token (parser
)->location
,
5239 c_parser_peek_token (parser
)->type
,
5242 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5245 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5248 if ( expression ) statement
5249 if ( expression ) statement else statement
5253 c_parser_if_statement (c_parser
*parser
)
5258 bool first_if
= false;
5259 tree first_body
, second_body
;
5263 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5264 location_t if_loc
= c_parser_peek_token (parser
)->location
;
5265 c_parser_consume_token (parser
);
5266 block
= c_begin_compound_stmt (flag_isoc99
);
5267 loc
= c_parser_peek_token (parser
)->location
;
5268 cond
= c_parser_paren_condition (parser
);
5269 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5271 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5272 cond
= error_mark_node
;
5274 in_if_block
= parser
->in_if_block
;
5275 parser
->in_if_block
= true;
5276 first_body
= c_parser_if_body (parser
, &first_if
, if_loc
);
5277 parser
->in_if_block
= in_if_block
;
5278 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5280 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5281 c_parser_consume_token (parser
);
5282 second_body
= c_parser_else_body (parser
, else_loc
);
5285 second_body
= NULL_TREE
;
5286 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5287 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5289 /* If the if statement contains array notations, then we expand them. */
5290 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5291 if_stmt
= fix_conditional_array_notations (if_stmt
);
5295 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5298 switch (expression) statement
5302 c_parser_switch_statement (c_parser
*parser
)
5305 tree block
, expr
, body
, save_break
;
5306 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5307 location_t switch_cond_loc
;
5308 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5309 c_parser_consume_token (parser
);
5310 block
= c_begin_compound_stmt (flag_isoc99
);
5311 bool explicit_cast_p
= false;
5312 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5314 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5315 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5316 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5317 explicit_cast_p
= true;
5318 ce
= c_parser_expression (parser
);
5319 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5321 /* ??? expr has no valid location? */
5322 if (check_no_cilk (expr
,
5323 "Cilk array notation cannot be used as a condition for switch statement",
5324 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5326 expr
= error_mark_node
;
5327 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5331 switch_cond_loc
= UNKNOWN_LOCATION
;
5332 expr
= error_mark_node
;
5334 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5335 save_break
= c_break_label
;
5336 c_break_label
= NULL_TREE
;
5337 body
= c_parser_c99_block_statement (parser
);
5338 c_finish_case (body
, ce
.original_type
);
5341 location_t here
= c_parser_peek_token (parser
)->location
;
5342 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5343 SET_EXPR_LOCATION (t
, here
);
5346 c_break_label
= save_break
;
5347 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5350 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5353 while (expression) statement
5357 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5359 tree block
, cond
, body
, save_break
, save_cont
;
5361 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5362 location_t while_loc
= c_parser_peek_token (parser
)->location
;
5363 c_parser_consume_token (parser
);
5364 block
= c_begin_compound_stmt (flag_isoc99
);
5365 loc
= c_parser_peek_token (parser
)->location
;
5366 cond
= c_parser_paren_condition (parser
);
5367 if (check_no_cilk (cond
,
5368 "Cilk array notation cannot be used as a condition for while statement",
5369 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5370 cond
= error_mark_node
;
5371 if (ivdep
&& cond
!= error_mark_node
)
5372 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5373 build_int_cst (integer_type_node
,
5374 annot_expr_ivdep_kind
));
5375 save_break
= c_break_label
;
5376 c_break_label
= NULL_TREE
;
5377 save_cont
= c_cont_label
;
5378 c_cont_label
= NULL_TREE
;
5380 location_t body_loc
= UNKNOWN_LOCATION
;
5381 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_BRACE
)
5382 body_loc
= c_parser_peek_token (parser
)->location
;
5383 body
= c_parser_c99_block_statement (parser
);
5384 warn_for_misleading_indentation (while_loc
, body_loc
,
5385 c_parser_peek_token (parser
)->location
,
5386 c_parser_peek_token (parser
)->type
,
5389 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5390 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5391 c_break_label
= save_break
;
5392 c_cont_label
= save_cont
;
5395 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5398 do statement while ( expression ) ;
5402 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5404 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5406 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5407 c_parser_consume_token (parser
);
5408 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5409 warning_at (c_parser_peek_token (parser
)->location
,
5411 "suggest braces around empty body in %<do%> statement");
5412 block
= c_begin_compound_stmt (flag_isoc99
);
5413 loc
= c_parser_peek_token (parser
)->location
;
5414 save_break
= c_break_label
;
5415 c_break_label
= NULL_TREE
;
5416 save_cont
= c_cont_label
;
5417 c_cont_label
= NULL_TREE
;
5418 body
= c_parser_c99_block_statement (parser
);
5419 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5420 new_break
= c_break_label
;
5421 c_break_label
= save_break
;
5422 new_cont
= c_cont_label
;
5423 c_cont_label
= save_cont
;
5424 cond
= c_parser_paren_condition (parser
);
5425 if (check_no_cilk (cond
,
5426 "Cilk array notation cannot be used as a condition for a do-while statement",
5427 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5428 cond
= error_mark_node
;
5429 if (ivdep
&& cond
!= error_mark_node
)
5430 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5431 build_int_cst (integer_type_node
,
5432 annot_expr_ivdep_kind
));
5433 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5434 c_parser_skip_to_end_of_block_or_statement (parser
);
5435 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5436 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5439 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5442 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5443 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5445 The form with a declaration is new in C99.
5447 ??? In accordance with the old parser, the declaration may be a
5448 nested function, which is then rejected in check_for_loop_decls,
5449 but does it make any sense for this to be included in the grammar?
5450 Note in particular that the nested function does not include a
5451 trailing ';', whereas the "declaration" production includes one.
5452 Also, can we reject bad declarations earlier and cheaper than
5453 check_for_loop_decls?
5455 In Objective-C, there are two additional variants:
5458 for ( expression in expresssion ) statement
5459 for ( declaration in expression ) statement
5461 This is inconsistent with C, because the second variant is allowed
5462 even if c99 is not enabled.
5464 The rest of the comment documents these Objective-C foreach-statement.
5466 Here is the canonical example of the first variant:
5467 for (object in array) { do something with object }
5468 we call the first expression ("object") the "object_expression" and
5469 the second expression ("array") the "collection_expression".
5470 object_expression must be an lvalue of type "id" (a generic Objective-C
5471 object) because the loop works by assigning to object_expression the
5472 various objects from the collection_expression. collection_expression
5473 must evaluate to something of type "id" which responds to the method
5474 countByEnumeratingWithState:objects:count:.
5476 The canonical example of the second variant is:
5477 for (id object in array) { do something with object }
5478 which is completely equivalent to
5481 for (object in array) { do something with object }
5483 Note that initizializing 'object' in some way (eg, "for ((object =
5484 xxx) in array) { do something with object }") is possibly
5485 technically valid, but completely pointless as 'object' will be
5486 assigned to something else as soon as the loop starts. We should
5487 most likely reject it (TODO).
5489 The beginning of the Objective-C foreach-statement looks exactly
5490 like the beginning of the for-statement, and we can tell it is a
5491 foreach-statement only because the initial declaration or
5492 expression is terminated by 'in' instead of ';'.
5496 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5498 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5499 /* The following are only used when parsing an ObjC foreach statement. */
5500 tree object_expression
;
5501 /* Silence the bogus uninitialized warning. */
5502 tree collection_expression
= NULL
;
5503 location_t loc
= c_parser_peek_token (parser
)->location
;
5504 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5505 bool is_foreach_statement
= false;
5506 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5507 c_parser_consume_token (parser
);
5508 /* Open a compound statement in Objective-C as well, just in case this is
5509 as foreach expression. */
5510 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5511 cond
= error_mark_node
;
5512 incr
= error_mark_node
;
5513 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5515 /* Parse the initialization declaration or expression. */
5516 object_expression
= error_mark_node
;
5517 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5518 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5520 parser
->objc_could_be_foreach_context
= false;
5521 c_parser_consume_token (parser
);
5522 c_finish_expr_stmt (loc
, NULL_TREE
);
5524 else if (c_parser_next_tokens_start_declaration (parser
))
5526 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5527 &object_expression
, vNULL
);
5528 parser
->objc_could_be_foreach_context
= false;
5530 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5532 c_parser_consume_token (parser
);
5533 is_foreach_statement
= true;
5534 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5535 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5538 check_for_loop_decls (for_loc
, flag_isoc99
);
5540 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5542 /* __extension__ can start a declaration, but is also an
5543 unary operator that can start an expression. Consume all
5544 but the last of a possible series of __extension__ to
5546 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5547 && (c_parser_peek_2nd_token (parser
)->keyword
5549 c_parser_consume_token (parser
);
5550 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5553 ext
= disable_extension_diagnostics ();
5554 c_parser_consume_token (parser
);
5555 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5556 true, &object_expression
, vNULL
);
5557 parser
->objc_could_be_foreach_context
= false;
5559 restore_extension_diagnostics (ext
);
5560 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5562 c_parser_consume_token (parser
);
5563 is_foreach_statement
= true;
5564 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5565 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5568 check_for_loop_decls (for_loc
, flag_isoc99
);
5578 tree init_expression
;
5579 ce
= c_parser_expression (parser
);
5580 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5581 level statement", but it works just fine, so allow it. */
5582 init_expression
= ce
.value
;
5583 parser
->objc_could_be_foreach_context
= false;
5584 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5586 c_parser_consume_token (parser
);
5587 is_foreach_statement
= true;
5588 if (! lvalue_p (init_expression
))
5589 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5590 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5594 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5595 init_expression
= ce
.value
;
5596 c_finish_expr_stmt (loc
, init_expression
);
5597 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5601 /* Parse the loop condition. In the case of a foreach
5602 statement, there is no loop condition. */
5603 gcc_assert (!parser
->objc_could_be_foreach_context
);
5604 if (!is_foreach_statement
)
5606 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5610 c_parser_error (parser
, "missing loop condition in loop with "
5611 "%<GCC ivdep%> pragma");
5612 cond
= error_mark_node
;
5616 c_parser_consume_token (parser
);
5622 cond
= c_parser_condition (parser
);
5623 if (check_no_cilk (cond
,
5624 "Cilk array notation cannot be used in a condition for a for-loop",
5625 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5626 cond
= error_mark_node
;
5627 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5630 if (ivdep
&& cond
!= error_mark_node
)
5631 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5632 build_int_cst (integer_type_node
,
5633 annot_expr_ivdep_kind
));
5635 /* Parse the increment expression (the third expression in a
5636 for-statement). In the case of a foreach-statement, this is
5637 the expression that follows the 'in'. */
5638 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5640 if (is_foreach_statement
)
5642 c_parser_error (parser
, "missing collection in fast enumeration");
5643 collection_expression
= error_mark_node
;
5646 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5650 if (is_foreach_statement
)
5651 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5655 struct c_expr ce
= c_parser_expression (parser
);
5656 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5657 incr
= c_process_expr_stmt (loc
, ce
.value
);
5660 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5662 save_break
= c_break_label
;
5663 c_break_label
= NULL_TREE
;
5664 save_cont
= c_cont_label
;
5665 c_cont_label
= NULL_TREE
;
5667 location_t body_loc
= UNKNOWN_LOCATION
;
5668 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_BRACE
)
5669 body_loc
= c_parser_peek_token (parser
)->location
;
5670 body
= c_parser_c99_block_statement (parser
);
5671 warn_for_misleading_indentation (for_loc
, body_loc
,
5672 c_parser_peek_token (parser
)->location
,
5673 c_parser_peek_token (parser
)->type
,
5676 if (is_foreach_statement
)
5677 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5679 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5680 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5681 c_break_label
= save_break
;
5682 c_cont_label
= save_cont
;
5685 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5686 statement with inputs, outputs, clobbers, and volatile tag
5690 asm type-qualifier[opt] ( asm-argument ) ;
5691 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5695 asm-string-literal : asm-operands[opt]
5696 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5697 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5700 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5703 Qualifiers other than volatile are accepted in the syntax but
5707 c_parser_asm_statement (c_parser
*parser
)
5709 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5710 bool simple
, is_goto
;
5711 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5712 int section
, nsections
;
5714 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5715 c_parser_consume_token (parser
);
5716 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5718 quals
= c_parser_peek_token (parser
)->value
;
5719 c_parser_consume_token (parser
);
5721 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5722 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5724 warning_at (c_parser_peek_token (parser
)->location
,
5726 "%E qualifier ignored on asm",
5727 c_parser_peek_token (parser
)->value
);
5729 c_parser_consume_token (parser
);
5735 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5737 c_parser_consume_token (parser
);
5741 /* ??? Follow the C++ parser rather than using the
5742 lex_untranslated_string kludge. */
5743 parser
->lex_untranslated_string
= true;
5746 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5749 str
= c_parser_asm_string_literal (parser
);
5750 if (str
== NULL_TREE
)
5751 goto error_close_paren
;
5754 outputs
= NULL_TREE
;
5756 clobbers
= NULL_TREE
;
5759 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5762 /* Parse each colon-delimited section of operands. */
5763 nsections
= 3 + is_goto
;
5764 for (section
= 0; section
< nsections
; ++section
)
5766 if (!c_parser_require (parser
, CPP_COLON
,
5769 : "expected %<:%> or %<)%>"))
5770 goto error_close_paren
;
5772 /* Once past any colon, we're no longer a simple asm. */
5775 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5776 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5781 /* For asm goto, we don't allow output operands, but reserve
5782 the slot for a future extension that does allow them. */
5784 outputs
= c_parser_asm_operands (parser
);
5787 inputs
= c_parser_asm_operands (parser
);
5790 clobbers
= c_parser_asm_clobbers (parser
);
5793 labels
= c_parser_asm_goto_operands (parser
);
5799 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5804 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5806 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5810 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5811 c_parser_skip_to_end_of_block_or_statement (parser
);
5813 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5814 clobbers
, labels
, simple
));
5817 parser
->lex_untranslated_string
= false;
5821 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5825 /* Parse asm operands, a GNU extension.
5829 asm-operands , asm-operand
5832 asm-string-literal ( expression )
5833 [ identifier ] asm-string-literal ( expression )
5837 c_parser_asm_operands (c_parser
*parser
)
5839 tree list
= NULL_TREE
;
5844 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5846 c_parser_consume_token (parser
);
5847 if (c_parser_next_token_is (parser
, CPP_NAME
))
5849 tree id
= c_parser_peek_token (parser
)->value
;
5850 c_parser_consume_token (parser
);
5851 name
= build_string (IDENTIFIER_LENGTH (id
),
5852 IDENTIFIER_POINTER (id
));
5856 c_parser_error (parser
, "expected identifier");
5857 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5860 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5865 str
= c_parser_asm_string_literal (parser
);
5866 if (str
== NULL_TREE
)
5868 parser
->lex_untranslated_string
= false;
5869 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5871 parser
->lex_untranslated_string
= true;
5874 expr
= c_parser_expression (parser
);
5875 mark_exp_read (expr
.value
);
5876 parser
->lex_untranslated_string
= true;
5877 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5879 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5882 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5884 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5885 c_parser_consume_token (parser
);
5892 /* Parse asm clobbers, a GNU extension.
5896 asm-clobbers , asm-string-literal
5900 c_parser_asm_clobbers (c_parser
*parser
)
5902 tree list
= NULL_TREE
;
5905 tree str
= c_parser_asm_string_literal (parser
);
5907 list
= tree_cons (NULL_TREE
, str
, list
);
5910 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5911 c_parser_consume_token (parser
);
5918 /* Parse asm goto labels, a GNU extension.
5922 asm-goto-operands , identifier
5926 c_parser_asm_goto_operands (c_parser
*parser
)
5928 tree list
= NULL_TREE
;
5933 if (c_parser_next_token_is (parser
, CPP_NAME
))
5935 c_token
*tok
= c_parser_peek_token (parser
);
5937 label
= lookup_label_for_goto (tok
->location
, name
);
5938 c_parser_consume_token (parser
);
5939 TREE_USED (label
) = 1;
5943 c_parser_error (parser
, "expected identifier");
5947 name
= build_string (IDENTIFIER_LENGTH (name
),
5948 IDENTIFIER_POINTER (name
));
5949 list
= tree_cons (name
, label
, list
);
5950 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5951 c_parser_consume_token (parser
);
5953 return nreverse (list
);
5957 /* Parse an expression other than a compound expression; that is, an
5958 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5959 NULL then it is an Objective-C message expression which is the
5960 primary-expression starting the expression as an initializer.
5962 assignment-expression:
5963 conditional-expression
5964 unary-expression assignment-operator assignment-expression
5966 assignment-operator: one of
5967 = *= /= %= += -= <<= >>= &= ^= |=
5969 In GNU C we accept any conditional expression on the LHS and
5970 diagnose the invalid lvalue rather than producing a syntax
5973 static struct c_expr
5974 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5975 tree omp_atomic_lhs
)
5977 struct c_expr lhs
, rhs
, ret
;
5978 enum tree_code code
;
5979 location_t op_location
, exp_location
;
5980 gcc_assert (!after
|| c_dialect_objc ());
5981 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5982 op_location
= c_parser_peek_token (parser
)->location
;
5983 switch (c_parser_peek_token (parser
)->type
)
5992 code
= TRUNC_DIV_EXPR
;
5995 code
= TRUNC_MOD_EXPR
;
6010 code
= BIT_AND_EXPR
;
6013 code
= BIT_XOR_EXPR
;
6016 code
= BIT_IOR_EXPR
;
6021 c_parser_consume_token (parser
);
6022 exp_location
= c_parser_peek_token (parser
)->location
;
6023 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6024 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6026 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6027 code
, exp_location
, rhs
.value
,
6029 if (code
== NOP_EXPR
)
6030 ret
.original_code
= MODIFY_EXPR
;
6033 TREE_NO_WARNING (ret
.value
) = 1;
6034 ret
.original_code
= ERROR_MARK
;
6036 ret
.original_type
= NULL
;
6040 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6041 is not NULL then it is an Objective-C message expression which is
6042 the primary-expression starting the expression as an initializer.
6044 conditional-expression:
6045 logical-OR-expression
6046 logical-OR-expression ? expression : conditional-expression
6050 conditional-expression:
6051 logical-OR-expression ? : conditional-expression
6054 static struct c_expr
6055 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6056 tree omp_atomic_lhs
)
6058 struct c_expr cond
, exp1
, exp2
, ret
;
6059 location_t cond_loc
, colon_loc
, middle_loc
;
6061 gcc_assert (!after
|| c_dialect_objc ());
6063 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6065 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6067 cond_loc
= c_parser_peek_token (parser
)->location
;
6068 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6069 c_parser_consume_token (parser
);
6070 if (c_parser_next_token_is (parser
, CPP_COLON
))
6072 tree eptype
= NULL_TREE
;
6074 middle_loc
= c_parser_peek_token (parser
)->location
;
6075 pedwarn (middle_loc
, OPT_Wpedantic
,
6076 "ISO C forbids omitting the middle term of a ?: expression");
6077 warn_for_omitted_condop (middle_loc
, cond
.value
);
6078 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6080 eptype
= TREE_TYPE (cond
.value
);
6081 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6083 /* Make sure first operand is calculated only once. */
6084 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6086 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6087 exp1
.original_type
= NULL
;
6088 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6089 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6094 = c_objc_common_truthvalue_conversion
6095 (cond_loc
, default_conversion (cond
.value
));
6096 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6097 exp1
= c_parser_expression_conv (parser
);
6098 mark_exp_read (exp1
.value
);
6099 c_inhibit_evaluation_warnings
+=
6100 ((cond
.value
== truthvalue_true_node
)
6101 - (cond
.value
== truthvalue_false_node
));
6104 colon_loc
= c_parser_peek_token (parser
)->location
;
6105 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6107 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6108 ret
.value
= error_mark_node
;
6109 ret
.original_code
= ERROR_MARK
;
6110 ret
.original_type
= NULL
;
6114 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6115 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6116 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6118 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6119 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6120 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6121 exp1
.value
, exp1
.original_type
,
6122 exp2
.value
, exp2
.original_type
);
6123 ret
.original_code
= ERROR_MARK
;
6124 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6125 ret
.original_type
= NULL
;
6130 /* If both sides are enum type, the default conversion will have
6131 made the type of the result be an integer type. We want to
6132 remember the enum types we started with. */
6133 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6134 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6135 ret
.original_type
= ((t1
!= error_mark_node
6136 && t2
!= error_mark_node
6137 && (TYPE_MAIN_VARIANT (t1
)
6138 == TYPE_MAIN_VARIANT (t2
)))
6145 /* Parse a binary expression; that is, a logical-OR-expression (C90
6146 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6147 an Objective-C message expression which is the primary-expression
6148 starting the expression as an initializer.
6150 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6151 when it should be the unfolded lhs. In a valid OpenMP source,
6152 one of the operands of the toplevel binary expression must be equal
6153 to it. In that case, just return a build2 created binary operation
6154 rather than result of parser_build_binary_op.
6156 multiplicative-expression:
6158 multiplicative-expression * cast-expression
6159 multiplicative-expression / cast-expression
6160 multiplicative-expression % cast-expression
6162 additive-expression:
6163 multiplicative-expression
6164 additive-expression + multiplicative-expression
6165 additive-expression - multiplicative-expression
6169 shift-expression << additive-expression
6170 shift-expression >> additive-expression
6172 relational-expression:
6174 relational-expression < shift-expression
6175 relational-expression > shift-expression
6176 relational-expression <= shift-expression
6177 relational-expression >= shift-expression
6179 equality-expression:
6180 relational-expression
6181 equality-expression == relational-expression
6182 equality-expression != relational-expression
6186 AND-expression & equality-expression
6188 exclusive-OR-expression:
6190 exclusive-OR-expression ^ AND-expression
6192 inclusive-OR-expression:
6193 exclusive-OR-expression
6194 inclusive-OR-expression | exclusive-OR-expression
6196 logical-AND-expression:
6197 inclusive-OR-expression
6198 logical-AND-expression && inclusive-OR-expression
6200 logical-OR-expression:
6201 logical-AND-expression
6202 logical-OR-expression || logical-AND-expression
6205 static struct c_expr
6206 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6207 tree omp_atomic_lhs
)
6209 /* A binary expression is parsed using operator-precedence parsing,
6210 with the operands being cast expressions. All the binary
6211 operators are left-associative. Thus a binary expression is of
6214 E0 op1 E1 op2 E2 ...
6216 which we represent on a stack. On the stack, the precedence
6217 levels are strictly increasing. When a new operator is
6218 encountered of higher precedence than that at the top of the
6219 stack, it is pushed; its LHS is the top expression, and its RHS
6220 is everything parsed until it is popped. When a new operator is
6221 encountered with precedence less than or equal to that at the top
6222 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6223 by the result of the operation until the operator at the top of
6224 the stack has lower precedence than the new operator or there is
6225 only one element on the stack; then the top expression is the LHS
6226 of the new operator. In the case of logical AND and OR
6227 expressions, we also need to adjust c_inhibit_evaluation_warnings
6228 as appropriate when the operators are pushed and popped. */
6231 /* The expression at this stack level. */
6233 /* The precedence of the operator on its left, PREC_NONE at the
6234 bottom of the stack. */
6235 enum c_parser_prec prec
;
6236 /* The operation on its left. */
6238 /* The source location of this operation. */
6242 /* Location of the binary operator. */
6243 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6246 switch (stack[sp].op) \
6248 case TRUTH_ANDIF_EXPR: \
6249 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6250 == truthvalue_false_node); \
6252 case TRUTH_ORIF_EXPR: \
6253 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6254 == truthvalue_true_node); \
6259 stack[sp - 1].expr \
6260 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6261 stack[sp - 1].expr, true, true); \
6263 = convert_lvalue_to_rvalue (stack[sp].loc, \
6264 stack[sp].expr, true, true); \
6265 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6266 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6267 && ((1 << stack[sp].prec) \
6268 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6269 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6270 && stack[sp].op != TRUNC_MOD_EXPR \
6271 && stack[0].expr.value != error_mark_node \
6272 && stack[1].expr.value != error_mark_node \
6273 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6274 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6275 stack[0].expr.value \
6276 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6277 stack[0].expr.value, stack[1].expr.value); \
6279 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6281 stack[sp - 1].expr, \
6285 gcc_assert (!after
|| c_dialect_objc ());
6286 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6287 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6288 stack
[0].prec
= PREC_NONE
;
6292 enum c_parser_prec oprec
;
6293 enum tree_code ocode
;
6296 switch (c_parser_peek_token (parser
)->type
)
6304 ocode
= TRUNC_DIV_EXPR
;
6308 ocode
= TRUNC_MOD_EXPR
;
6320 ocode
= LSHIFT_EXPR
;
6324 ocode
= RSHIFT_EXPR
;
6338 case CPP_GREATER_EQ
:
6351 oprec
= PREC_BITAND
;
6352 ocode
= BIT_AND_EXPR
;
6355 oprec
= PREC_BITXOR
;
6356 ocode
= BIT_XOR_EXPR
;
6360 ocode
= BIT_IOR_EXPR
;
6363 oprec
= PREC_LOGAND
;
6364 ocode
= TRUTH_ANDIF_EXPR
;
6368 ocode
= TRUTH_ORIF_EXPR
;
6371 /* Not a binary operator, so end of the binary
6375 binary_loc
= c_parser_peek_token (parser
)->location
;
6376 while (oprec
<= stack
[sp
].prec
)
6378 c_parser_consume_token (parser
);
6381 case TRUTH_ANDIF_EXPR
:
6383 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6384 stack
[sp
].expr
, true, true);
6385 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6386 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6387 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6388 == truthvalue_false_node
);
6390 case TRUTH_ORIF_EXPR
:
6392 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6393 stack
[sp
].expr
, true, true);
6394 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6395 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6396 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6397 == truthvalue_true_node
);
6403 stack
[sp
].loc
= binary_loc
;
6404 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6405 stack
[sp
].prec
= oprec
;
6406 stack
[sp
].op
= ocode
;
6411 return stack
[0].expr
;
6415 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6416 NULL then it is an Objective-C message expression which is the
6417 primary-expression starting the expression as an initializer.
6421 ( type-name ) unary-expression
6424 static struct c_expr
6425 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6427 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6428 gcc_assert (!after
|| c_dialect_objc ());
6430 return c_parser_postfix_expression_after_primary (parser
,
6432 /* If the expression begins with a parenthesized type name, it may
6433 be either a cast or a compound literal; we need to see whether
6434 the next character is '{' to tell the difference. If not, it is
6435 an unary expression. Full detection of unknown typenames here
6436 would require a 3-token lookahead. */
6437 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6438 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6440 struct c_type_name
*type_name
;
6443 c_parser_consume_token (parser
);
6444 type_name
= c_parser_type_name (parser
);
6445 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6446 if (type_name
== NULL
)
6448 ret
.value
= error_mark_node
;
6449 ret
.original_code
= ERROR_MARK
;
6450 ret
.original_type
= NULL
;
6454 /* Save casted types in the function's used types hash table. */
6455 used_types_insert (type_name
->specs
->type
);
6457 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6458 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6461 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6462 expr
= c_parser_cast_expression (parser
, NULL
);
6463 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6465 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6466 ret
.original_code
= ERROR_MARK
;
6467 ret
.original_type
= NULL
;
6471 return c_parser_unary_expression (parser
);
6474 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6480 unary-operator cast-expression
6481 sizeof unary-expression
6482 sizeof ( type-name )
6484 unary-operator: one of
6490 __alignof__ unary-expression
6491 __alignof__ ( type-name )
6494 (C11 permits _Alignof with type names only.)
6496 unary-operator: one of
6497 __extension__ __real__ __imag__
6499 Transactional Memory:
6502 transaction-expression
6504 In addition, the GNU syntax treats ++ and -- as unary operators, so
6505 they may be applied to cast expressions with errors for non-lvalues
6508 static struct c_expr
6509 c_parser_unary_expression (c_parser
*parser
)
6512 struct c_expr ret
, op
;
6513 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6515 ret
.original_code
= ERROR_MARK
;
6516 ret
.original_type
= NULL
;
6517 switch (c_parser_peek_token (parser
)->type
)
6520 c_parser_consume_token (parser
);
6521 exp_loc
= c_parser_peek_token (parser
)->location
;
6522 op
= c_parser_cast_expression (parser
, NULL
);
6524 /* If there is array notations in op, we expand them. */
6525 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6526 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6529 op
= default_function_array_read_conversion (exp_loc
, op
);
6530 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6532 case CPP_MINUS_MINUS
:
6533 c_parser_consume_token (parser
);
6534 exp_loc
= c_parser_peek_token (parser
)->location
;
6535 op
= c_parser_cast_expression (parser
, NULL
);
6537 /* If there is array notations in op, we expand them. */
6538 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6539 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6542 op
= default_function_array_read_conversion (exp_loc
, op
);
6543 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6546 c_parser_consume_token (parser
);
6547 op
= c_parser_cast_expression (parser
, NULL
);
6548 mark_exp_read (op
.value
);
6549 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6551 c_parser_consume_token (parser
);
6552 exp_loc
= c_parser_peek_token (parser
)->location
;
6553 op
= c_parser_cast_expression (parser
, NULL
);
6554 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6555 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6558 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6561 "traditional C rejects the unary plus operator");
6562 c_parser_consume_token (parser
);
6563 exp_loc
= c_parser_peek_token (parser
)->location
;
6564 op
= c_parser_cast_expression (parser
, NULL
);
6565 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6566 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6568 c_parser_consume_token (parser
);
6569 exp_loc
= c_parser_peek_token (parser
)->location
;
6570 op
= c_parser_cast_expression (parser
, NULL
);
6571 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6572 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6574 c_parser_consume_token (parser
);
6575 exp_loc
= c_parser_peek_token (parser
)->location
;
6576 op
= c_parser_cast_expression (parser
, NULL
);
6577 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6578 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6580 c_parser_consume_token (parser
);
6581 exp_loc
= c_parser_peek_token (parser
)->location
;
6582 op
= c_parser_cast_expression (parser
, NULL
);
6583 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6584 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6586 /* Refer to the address of a label as a pointer. */
6587 c_parser_consume_token (parser
);
6588 if (c_parser_next_token_is (parser
, CPP_NAME
))
6590 ret
.value
= finish_label_address_expr
6591 (c_parser_peek_token (parser
)->value
, op_loc
);
6592 c_parser_consume_token (parser
);
6596 c_parser_error (parser
, "expected identifier");
6597 ret
.value
= error_mark_node
;
6601 switch (c_parser_peek_token (parser
)->keyword
)
6604 return c_parser_sizeof_expression (parser
);
6606 return c_parser_alignof_expression (parser
);
6608 c_parser_consume_token (parser
);
6609 ext
= disable_extension_diagnostics ();
6610 ret
= c_parser_cast_expression (parser
, NULL
);
6611 restore_extension_diagnostics (ext
);
6614 c_parser_consume_token (parser
);
6615 exp_loc
= c_parser_peek_token (parser
)->location
;
6616 op
= c_parser_cast_expression (parser
, NULL
);
6617 op
= default_function_array_conversion (exp_loc
, op
);
6618 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6620 c_parser_consume_token (parser
);
6621 exp_loc
= c_parser_peek_token (parser
)->location
;
6622 op
= c_parser_cast_expression (parser
, NULL
);
6623 op
= default_function_array_conversion (exp_loc
, op
);
6624 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6625 case RID_TRANSACTION_ATOMIC
:
6626 case RID_TRANSACTION_RELAXED
:
6627 return c_parser_transaction_expression (parser
,
6628 c_parser_peek_token (parser
)->keyword
);
6630 return c_parser_postfix_expression (parser
);
6633 return c_parser_postfix_expression (parser
);
6637 /* Parse a sizeof expression. */
6639 static struct c_expr
6640 c_parser_sizeof_expression (c_parser
*parser
)
6643 location_t expr_loc
;
6644 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6645 c_parser_consume_token (parser
);
6646 c_inhibit_evaluation_warnings
++;
6648 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6649 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6651 /* Either sizeof ( type-name ) or sizeof unary-expression
6652 starting with a compound literal. */
6653 struct c_type_name
*type_name
;
6654 c_parser_consume_token (parser
);
6655 expr_loc
= c_parser_peek_token (parser
)->location
;
6656 type_name
= c_parser_type_name (parser
);
6657 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6658 if (type_name
== NULL
)
6661 c_inhibit_evaluation_warnings
--;
6663 ret
.value
= error_mark_node
;
6664 ret
.original_code
= ERROR_MARK
;
6665 ret
.original_type
= NULL
;
6668 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6670 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6675 /* sizeof ( type-name ). */
6676 c_inhibit_evaluation_warnings
--;
6678 return c_expr_sizeof_type (expr_loc
, type_name
);
6682 expr_loc
= c_parser_peek_token (parser
)->location
;
6683 expr
= c_parser_unary_expression (parser
);
6685 c_inhibit_evaluation_warnings
--;
6687 mark_exp_read (expr
.value
);
6688 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6689 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6690 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6691 return c_expr_sizeof_expr (expr_loc
, expr
);
6695 /* Parse an alignof expression. */
6697 static struct c_expr
6698 c_parser_alignof_expression (c_parser
*parser
)
6701 location_t loc
= c_parser_peek_token (parser
)->location
;
6702 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6703 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6704 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6706 /* A diagnostic is not required for the use of this identifier in
6707 the implementation namespace; only diagnose it for the C11
6708 spelling because of existing code using the other spellings. */
6712 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6715 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6718 c_parser_consume_token (parser
);
6719 c_inhibit_evaluation_warnings
++;
6721 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6722 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6724 /* Either __alignof__ ( type-name ) or __alignof__
6725 unary-expression starting with a compound literal. */
6727 struct c_type_name
*type_name
;
6729 c_parser_consume_token (parser
);
6730 loc
= c_parser_peek_token (parser
)->location
;
6731 type_name
= c_parser_type_name (parser
);
6732 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6733 if (type_name
== NULL
)
6736 c_inhibit_evaluation_warnings
--;
6738 ret
.value
= error_mark_node
;
6739 ret
.original_code
= ERROR_MARK
;
6740 ret
.original_type
= NULL
;
6743 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6745 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6750 /* alignof ( type-name ). */
6751 c_inhibit_evaluation_warnings
--;
6753 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6755 false, is_c11_alignof
, 1);
6756 ret
.original_code
= ERROR_MARK
;
6757 ret
.original_type
= NULL
;
6763 expr
= c_parser_unary_expression (parser
);
6765 mark_exp_read (expr
.value
);
6766 c_inhibit_evaluation_warnings
--;
6768 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6770 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6771 ret
.original_code
= ERROR_MARK
;
6772 ret
.original_type
= NULL
;
6777 /* Helper function to read arguments of builtins which are interfaces
6778 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6779 others. The name of the builtin is passed using BNAME parameter.
6780 Function returns true if there were no errors while parsing and
6781 stores the arguments in CEXPR_LIST. */
6783 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6784 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6787 location_t loc
= c_parser_peek_token (parser
)->location
;
6788 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6790 bool saved_force_folding_builtin_constant_p
;
6792 *ret_cexpr_list
= NULL
;
6793 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6795 error_at (loc
, "cannot take address of %qs", bname
);
6799 c_parser_consume_token (parser
);
6801 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6803 c_parser_consume_token (parser
);
6807 saved_force_folding_builtin_constant_p
6808 = force_folding_builtin_constant_p
;
6809 force_folding_builtin_constant_p
|= choose_expr_p
;
6810 expr
= c_parser_expr_no_commas (parser
, NULL
);
6811 force_folding_builtin_constant_p
6812 = saved_force_folding_builtin_constant_p
;
6813 vec_alloc (cexpr_list
, 1);
6814 vec_safe_push (cexpr_list
, expr
);
6815 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6817 c_parser_consume_token (parser
);
6818 expr
= c_parser_expr_no_commas (parser
, NULL
);
6819 vec_safe_push (cexpr_list
, expr
);
6822 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6825 *ret_cexpr_list
= cexpr_list
;
6829 /* This represents a single generic-association. */
6831 struct c_generic_association
6833 /* The location of the starting token of the type. */
6834 location_t type_location
;
6835 /* The association's type, or NULL_TREE for 'default'. */
6837 /* The association's expression. */
6838 struct c_expr expression
;
6841 /* Parse a generic-selection. (C11 6.5.1.1).
6844 _Generic ( assignment-expression , generic-assoc-list )
6848 generic-assoc-list , generic-association
6850 generic-association:
6851 type-name : assignment-expression
6852 default : assignment-expression
6855 static struct c_expr
6856 c_parser_generic_selection (c_parser
*parser
)
6858 vec
<c_generic_association
> associations
= vNULL
;
6859 struct c_expr selector
, error_expr
;
6861 struct c_generic_association matched_assoc
;
6862 bool match_found
= false;
6863 location_t generic_loc
, selector_loc
;
6865 error_expr
.original_code
= ERROR_MARK
;
6866 error_expr
.original_type
= NULL
;
6867 error_expr
.value
= error_mark_node
;
6868 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6869 matched_assoc
.type
= NULL_TREE
;
6870 matched_assoc
.expression
= error_expr
;
6872 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6873 generic_loc
= c_parser_peek_token (parser
)->location
;
6874 c_parser_consume_token (parser
);
6876 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6877 "ISO C99 does not support %<_Generic%>");
6879 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6880 "ISO C90 does not support %<_Generic%>");
6882 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6885 c_inhibit_evaluation_warnings
++;
6886 selector_loc
= c_parser_peek_token (parser
)->location
;
6887 selector
= c_parser_expr_no_commas (parser
, NULL
);
6888 selector
= default_function_array_conversion (selector_loc
, selector
);
6889 c_inhibit_evaluation_warnings
--;
6891 if (selector
.value
== error_mark_node
)
6893 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6896 selector_type
= TREE_TYPE (selector
.value
);
6897 /* In ISO C terms, rvalues (including the controlling expression of
6898 _Generic) do not have qualified types. */
6899 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6900 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6901 /* In ISO C terms, _Noreturn is not part of the type of expressions
6902 such as &abort, but in GCC it is represented internally as a type
6904 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6905 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6907 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6909 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6911 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6917 struct c_generic_association assoc
, *iter
;
6919 c_token
*token
= c_parser_peek_token (parser
);
6921 assoc
.type_location
= token
->location
;
6922 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6924 c_parser_consume_token (parser
);
6925 assoc
.type
= NULL_TREE
;
6929 struct c_type_name
*type_name
;
6931 type_name
= c_parser_type_name (parser
);
6932 if (type_name
== NULL
)
6934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6937 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6938 if (assoc
.type
== error_mark_node
)
6940 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6944 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6945 error_at (assoc
.type_location
,
6946 "%<_Generic%> association has function type");
6947 else if (!COMPLETE_TYPE_P (assoc
.type
))
6948 error_at (assoc
.type_location
,
6949 "%<_Generic%> association has incomplete type");
6951 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6952 error_at (assoc
.type_location
,
6953 "%<_Generic%> association has "
6954 "variable length type");
6957 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6959 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6963 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6964 if (assoc
.expression
.value
== error_mark_node
)
6966 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6970 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6972 if (assoc
.type
== NULL_TREE
)
6974 if (iter
->type
== NULL_TREE
)
6976 error_at (assoc
.type_location
,
6977 "duplicate %<default%> case in %<_Generic%>");
6978 inform (iter
->type_location
, "original %<default%> is here");
6981 else if (iter
->type
!= NULL_TREE
)
6983 if (comptypes (assoc
.type
, iter
->type
))
6985 error_at (assoc
.type_location
,
6986 "%<_Generic%> specifies two compatible types");
6987 inform (iter
->type_location
, "compatible type is here");
6992 if (assoc
.type
== NULL_TREE
)
6996 matched_assoc
= assoc
;
7000 else if (comptypes (assoc
.type
, selector_type
))
7002 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7004 matched_assoc
= assoc
;
7009 error_at (assoc
.type_location
,
7010 "%<_Generic> selector matches multiple associations");
7011 inform (matched_assoc
.type_location
,
7012 "other match is here");
7016 associations
.safe_push (assoc
);
7018 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7020 c_parser_consume_token (parser
);
7023 associations
.release ();
7025 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7027 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7033 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7034 "compatible with any association",
7039 return matched_assoc
.expression
;
7042 associations
.release ();
7046 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7050 postfix-expression [ expression ]
7051 postfix-expression ( argument-expression-list[opt] )
7052 postfix-expression . identifier
7053 postfix-expression -> identifier
7054 postfix-expression ++
7055 postfix-expression --
7056 ( type-name ) { initializer-list }
7057 ( type-name ) { initializer-list , }
7059 argument-expression-list:
7061 argument-expression-list , argument-expression
7074 (treated as a keyword in GNU C)
7077 ( compound-statement )
7078 __builtin_va_arg ( assignment-expression , type-name )
7079 __builtin_offsetof ( type-name , offsetof-member-designator )
7080 __builtin_choose_expr ( assignment-expression ,
7081 assignment-expression ,
7082 assignment-expression )
7083 __builtin_types_compatible_p ( type-name , type-name )
7084 __builtin_complex ( assignment-expression , assignment-expression )
7085 __builtin_shuffle ( assignment-expression , assignment-expression )
7086 __builtin_shuffle ( assignment-expression ,
7087 assignment-expression ,
7088 assignment-expression, )
7090 offsetof-member-designator:
7092 offsetof-member-designator . identifier
7093 offsetof-member-designator [ expression ]
7098 [ objc-receiver objc-message-args ]
7099 @selector ( objc-selector-arg )
7100 @protocol ( identifier )
7101 @encode ( type-name )
7103 Classname . identifier
7106 static struct c_expr
7107 c_parser_postfix_expression (c_parser
*parser
)
7109 struct c_expr expr
, e1
;
7110 struct c_type_name
*t1
, *t2
;
7111 location_t loc
= c_parser_peek_token (parser
)->location
;;
7112 expr
.original_code
= ERROR_MARK
;
7113 expr
.original_type
= NULL
;
7114 switch (c_parser_peek_token (parser
)->type
)
7117 expr
.value
= c_parser_peek_token (parser
)->value
;
7118 loc
= c_parser_peek_token (parser
)->location
;
7119 c_parser_consume_token (parser
);
7120 if (TREE_CODE (expr
.value
) == FIXED_CST
7121 && !targetm
.fixed_point_supported_p ())
7123 error_at (loc
, "fixed-point types not supported for this target");
7124 expr
.value
= error_mark_node
;
7131 expr
.value
= c_parser_peek_token (parser
)->value
;
7132 c_parser_consume_token (parser
);
7138 case CPP_UTF8STRING
:
7139 expr
.value
= c_parser_peek_token (parser
)->value
;
7140 expr
.original_code
= STRING_CST
;
7141 c_parser_consume_token (parser
);
7143 case CPP_OBJC_STRING
:
7144 gcc_assert (c_dialect_objc ());
7146 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7147 c_parser_consume_token (parser
);
7150 switch (c_parser_peek_token (parser
)->id_kind
)
7154 tree id
= c_parser_peek_token (parser
)->value
;
7155 c_parser_consume_token (parser
);
7156 expr
.value
= build_external_ref (loc
, id
,
7157 (c_parser_peek_token (parser
)->type
7159 &expr
.original_type
);
7162 case C_ID_CLASSNAME
:
7164 /* Here we parse the Objective-C 2.0 Class.name dot
7166 tree class_name
= c_parser_peek_token (parser
)->value
;
7168 c_parser_consume_token (parser
);
7169 gcc_assert (c_dialect_objc ());
7170 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7172 expr
.value
= error_mark_node
;
7175 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7177 c_parser_error (parser
, "expected identifier");
7178 expr
.value
= error_mark_node
;
7181 component
= c_parser_peek_token (parser
)->value
;
7182 c_parser_consume_token (parser
);
7183 expr
.value
= objc_build_class_component_ref (class_name
,
7188 c_parser_error (parser
, "expected expression");
7189 expr
.value
= error_mark_node
;
7193 case CPP_OPEN_PAREN
:
7194 /* A parenthesized expression, statement expression or compound
7196 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7198 /* A statement expression. */
7200 location_t brace_loc
;
7201 c_parser_consume_token (parser
);
7202 brace_loc
= c_parser_peek_token (parser
)->location
;
7203 c_parser_consume_token (parser
);
7204 if (!building_stmt_list_p ())
7206 error_at (loc
, "braced-group within expression allowed "
7207 "only inside a function");
7208 parser
->error
= true;
7209 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7210 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7211 expr
.value
= error_mark_node
;
7214 stmt
= c_begin_stmt_expr ();
7215 c_parser_compound_statement_nostart (parser
);
7216 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7218 pedwarn (loc
, OPT_Wpedantic
,
7219 "ISO C forbids braced-groups within expressions");
7220 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7221 mark_exp_read (expr
.value
);
7223 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7225 /* A compound literal. ??? Can we actually get here rather
7226 than going directly to
7227 c_parser_postfix_expression_after_paren_type from
7230 struct c_type_name
*type_name
;
7231 c_parser_consume_token (parser
);
7232 loc
= c_parser_peek_token (parser
)->location
;
7233 type_name
= c_parser_type_name (parser
);
7234 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7236 if (type_name
== NULL
)
7238 expr
.value
= error_mark_node
;
7241 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7247 /* A parenthesized expression. */
7248 c_parser_consume_token (parser
);
7249 expr
= c_parser_expression (parser
);
7250 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7251 TREE_NO_WARNING (expr
.value
) = 1;
7252 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7253 expr
.original_code
= ERROR_MARK
;
7254 /* Don't change EXPR.ORIGINAL_TYPE. */
7255 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7260 switch (c_parser_peek_token (parser
)->keyword
)
7262 case RID_FUNCTION_NAME
:
7263 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7264 "%<__FUNCTION__%> predefined identifier");
7265 expr
.value
= fname_decl (loc
,
7266 c_parser_peek_token (parser
)->keyword
,
7267 c_parser_peek_token (parser
)->value
);
7268 c_parser_consume_token (parser
);
7270 case RID_PRETTY_FUNCTION_NAME
:
7271 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7272 "%<__PRETTY_FUNCTION__%> predefined identifier");
7273 expr
.value
= fname_decl (loc
,
7274 c_parser_peek_token (parser
)->keyword
,
7275 c_parser_peek_token (parser
)->value
);
7276 c_parser_consume_token (parser
);
7278 case RID_C99_FUNCTION_NAME
:
7279 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7280 "%<__func__%> predefined identifier");
7281 expr
.value
= fname_decl (loc
,
7282 c_parser_peek_token (parser
)->keyword
,
7283 c_parser_peek_token (parser
)->value
);
7284 c_parser_consume_token (parser
);
7287 c_parser_consume_token (parser
);
7288 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7290 expr
.value
= error_mark_node
;
7293 e1
= c_parser_expr_no_commas (parser
, NULL
);
7294 mark_exp_read (e1
.value
);
7295 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7296 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7298 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7299 expr
.value
= error_mark_node
;
7302 loc
= c_parser_peek_token (parser
)->location
;
7303 t1
= c_parser_type_name (parser
);
7304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7308 expr
.value
= error_mark_node
;
7312 tree type_expr
= NULL_TREE
;
7313 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7314 groktypename (t1
, &type_expr
, NULL
));
7317 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7318 TREE_TYPE (expr
.value
), type_expr
,
7320 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7325 c_parser_consume_token (parser
);
7326 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7328 expr
.value
= error_mark_node
;
7331 t1
= c_parser_type_name (parser
);
7333 parser
->error
= true;
7334 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7335 gcc_assert (parser
->error
);
7338 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7339 expr
.value
= error_mark_node
;
7344 tree type
= groktypename (t1
, NULL
, NULL
);
7346 if (type
== error_mark_node
)
7347 offsetof_ref
= error_mark_node
;
7350 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7351 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7353 /* Parse the second argument to __builtin_offsetof. We
7354 must have one identifier, and beyond that we want to
7355 accept sub structure and sub array references. */
7356 if (c_parser_next_token_is (parser
, CPP_NAME
))
7358 offsetof_ref
= build_component_ref
7359 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7360 c_parser_consume_token (parser
);
7361 while (c_parser_next_token_is (parser
, CPP_DOT
)
7362 || c_parser_next_token_is (parser
,
7364 || c_parser_next_token_is (parser
,
7367 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7369 loc
= c_parser_peek_token (parser
)->location
;
7370 offsetof_ref
= build_array_ref (loc
,
7375 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7378 c_parser_consume_token (parser
);
7379 if (c_parser_next_token_is_not (parser
,
7382 c_parser_error (parser
, "expected identifier");
7385 offsetof_ref
= build_component_ref
7387 c_parser_peek_token (parser
)->value
);
7388 c_parser_consume_token (parser
);
7394 loc
= c_parser_peek_token (parser
)->location
;
7395 c_parser_consume_token (parser
);
7396 ce
= c_parser_expression (parser
);
7397 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7399 idx
= c_fully_fold (idx
, false, NULL
);
7400 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7402 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7407 c_parser_error (parser
, "expected identifier");
7408 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7410 expr
.value
= fold_offsetof (offsetof_ref
);
7413 case RID_CHOOSE_EXPR
:
7415 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7416 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7419 c_parser_consume_token (parser
);
7420 if (!c_parser_get_builtin_args (parser
,
7421 "__builtin_choose_expr",
7424 expr
.value
= error_mark_node
;
7428 if (vec_safe_length (cexpr_list
) != 3)
7430 error_at (loc
, "wrong number of arguments to "
7431 "%<__builtin_choose_expr%>");
7432 expr
.value
= error_mark_node
;
7436 e1_p
= &(*cexpr_list
)[0];
7437 e2_p
= &(*cexpr_list
)[1];
7438 e3_p
= &(*cexpr_list
)[2];
7441 mark_exp_read (e2_p
->value
);
7442 mark_exp_read (e3_p
->value
);
7443 if (TREE_CODE (c
) != INTEGER_CST
7444 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7446 "first argument to %<__builtin_choose_expr%> not"
7448 constant_expression_warning (c
);
7449 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7452 case RID_TYPES_COMPATIBLE_P
:
7453 c_parser_consume_token (parser
);
7454 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7456 expr
.value
= error_mark_node
;
7459 t1
= c_parser_type_name (parser
);
7462 expr
.value
= error_mark_node
;
7465 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7467 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7468 expr
.value
= error_mark_node
;
7471 t2
= c_parser_type_name (parser
);
7474 expr
.value
= error_mark_node
;
7477 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7481 e1
= groktypename (t1
, NULL
, NULL
);
7482 e2
= groktypename (t2
, NULL
, NULL
);
7483 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7485 expr
.value
= error_mark_node
;
7489 e1
= TYPE_MAIN_VARIANT (e1
);
7490 e2
= TYPE_MAIN_VARIANT (e2
);
7493 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7496 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7498 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7502 c_parser_consume_token (parser
);
7503 if (!c_parser_get_builtin_args (parser
,
7504 "__builtin_call_with_static_chain",
7505 &cexpr_list
, false))
7507 expr
.value
= error_mark_node
;
7510 if (vec_safe_length (cexpr_list
) != 2)
7512 error_at (loc
, "wrong number of arguments to "
7513 "%<__builtin_call_with_static_chain%>");
7514 expr
.value
= error_mark_node
;
7518 expr
= (*cexpr_list
)[0];
7519 e2_p
= &(*cexpr_list
)[1];
7520 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7521 chain_value
= e2_p
->value
;
7522 mark_exp_read (chain_value
);
7524 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7525 error_at (loc
, "first argument to "
7526 "%<__builtin_call_with_static_chain%> "
7527 "must be a call expression");
7528 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7529 error_at (loc
, "second argument to "
7530 "%<__builtin_call_with_static_chain%> "
7531 "must be a pointer type");
7533 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7536 case RID_BUILTIN_COMPLEX
:
7538 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7539 c_expr_t
*e1_p
, *e2_p
;
7541 c_parser_consume_token (parser
);
7542 if (!c_parser_get_builtin_args (parser
,
7543 "__builtin_complex",
7544 &cexpr_list
, false))
7546 expr
.value
= error_mark_node
;
7550 if (vec_safe_length (cexpr_list
) != 2)
7552 error_at (loc
, "wrong number of arguments to "
7553 "%<__builtin_complex%>");
7554 expr
.value
= error_mark_node
;
7558 e1_p
= &(*cexpr_list
)[0];
7559 e2_p
= &(*cexpr_list
)[1];
7561 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7562 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7563 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7564 TREE_OPERAND (e1_p
->value
, 0));
7565 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7566 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7567 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7568 TREE_OPERAND (e2_p
->value
, 0));
7569 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7570 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7571 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7572 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7574 error_at (loc
, "%<__builtin_complex%> operand "
7575 "not of real binary floating-point type");
7576 expr
.value
= error_mark_node
;
7579 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7580 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7583 "%<__builtin_complex%> operands of different types");
7584 expr
.value
= error_mark_node
;
7587 pedwarn_c90 (loc
, OPT_Wpedantic
,
7588 "ISO C90 does not support complex types");
7589 expr
.value
= build2 (COMPLEX_EXPR
,
7592 (TREE_TYPE (e1_p
->value
))),
7593 e1_p
->value
, e2_p
->value
);
7596 case RID_BUILTIN_SHUFFLE
:
7598 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7602 c_parser_consume_token (parser
);
7603 if (!c_parser_get_builtin_args (parser
,
7604 "__builtin_shuffle",
7605 &cexpr_list
, false))
7607 expr
.value
= error_mark_node
;
7611 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7612 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7614 if (vec_safe_length (cexpr_list
) == 2)
7616 c_build_vec_perm_expr
7617 (loc
, (*cexpr_list
)[0].value
,
7618 NULL_TREE
, (*cexpr_list
)[1].value
);
7620 else if (vec_safe_length (cexpr_list
) == 3)
7622 c_build_vec_perm_expr
7623 (loc
, (*cexpr_list
)[0].value
,
7624 (*cexpr_list
)[1].value
,
7625 (*cexpr_list
)[2].value
);
7628 error_at (loc
, "wrong number of arguments to "
7629 "%<__builtin_shuffle%>");
7630 expr
.value
= error_mark_node
;
7634 case RID_AT_SELECTOR
:
7635 gcc_assert (c_dialect_objc ());
7636 c_parser_consume_token (parser
);
7637 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7639 expr
.value
= error_mark_node
;
7643 tree sel
= c_parser_objc_selector_arg (parser
);
7644 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7646 expr
.value
= objc_build_selector_expr (loc
, sel
);
7649 case RID_AT_PROTOCOL
:
7650 gcc_assert (c_dialect_objc ());
7651 c_parser_consume_token (parser
);
7652 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7654 expr
.value
= error_mark_node
;
7657 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7659 c_parser_error (parser
, "expected identifier");
7660 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7661 expr
.value
= error_mark_node
;
7665 tree id
= c_parser_peek_token (parser
)->value
;
7666 c_parser_consume_token (parser
);
7667 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7669 expr
.value
= objc_build_protocol_expr (id
);
7673 /* Extension to support C-structures in the archiver. */
7674 gcc_assert (c_dialect_objc ());
7675 c_parser_consume_token (parser
);
7676 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7678 expr
.value
= error_mark_node
;
7681 t1
= c_parser_type_name (parser
);
7684 expr
.value
= error_mark_node
;
7685 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7688 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7691 tree type
= groktypename (t1
, NULL
, NULL
);
7692 expr
.value
= objc_build_encode_expr (type
);
7696 expr
= c_parser_generic_selection (parser
);
7698 case RID_CILK_SPAWN
:
7699 c_parser_consume_token (parser
);
7702 error_at (loc
, "-fcilkplus must be enabled to use "
7704 expr
= c_parser_postfix_expression (parser
);
7705 expr
.value
= error_mark_node
;
7707 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7709 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7710 "are not permitted");
7711 /* Now flush out all the _Cilk_spawns. */
7712 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7713 c_parser_consume_token (parser
);
7714 expr
= c_parser_postfix_expression (parser
);
7718 expr
= c_parser_postfix_expression (parser
);
7719 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7723 c_parser_error (parser
, "expected expression");
7724 expr
.value
= error_mark_node
;
7728 case CPP_OPEN_SQUARE
:
7729 if (c_dialect_objc ())
7731 tree receiver
, args
;
7732 c_parser_consume_token (parser
);
7733 receiver
= c_parser_objc_receiver (parser
);
7734 args
= c_parser_objc_message_args (parser
);
7735 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7737 expr
.value
= objc_build_message_expr (receiver
, args
);
7740 /* Else fall through to report error. */
7742 c_parser_error (parser
, "expected expression");
7743 expr
.value
= error_mark_node
;
7746 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7749 /* Parse a postfix expression after a parenthesized type name: the
7750 brace-enclosed initializer of a compound literal, possibly followed
7751 by some postfix operators. This is separate because it is not
7752 possible to tell until after the type name whether a cast
7753 expression has a cast or a compound literal, or whether the operand
7754 of sizeof is a parenthesized type name or starts with a compound
7755 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7756 location of the first token after the parentheses around the type
7759 static struct c_expr
7760 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7761 struct c_type_name
*type_name
,
7762 location_t type_loc
)
7768 location_t start_loc
;
7769 tree type_expr
= NULL_TREE
;
7770 bool type_expr_const
= true;
7771 check_compound_literal_type (type_loc
, type_name
);
7772 start_init (NULL_TREE
, NULL
, 0);
7773 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7774 start_loc
= c_parser_peek_token (parser
)->location
;
7775 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7777 error_at (type_loc
, "compound literal has variable size");
7778 type
= error_mark_node
;
7780 init
= c_parser_braced_init (parser
, type
, false);
7782 maybe_warn_string_init (type_loc
, type
, init
);
7784 if (type
!= error_mark_node
7785 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7786 && current_function_decl
)
7788 error ("compound literal qualified by address-space qualifier");
7789 type
= error_mark_node
;
7792 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7793 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7794 ? CONSTRUCTOR_NON_CONST (init
.value
)
7795 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7796 non_const
|= !type_expr_const
;
7797 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7798 expr
.original_code
= ERROR_MARK
;
7799 expr
.original_type
= NULL
;
7802 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7804 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7805 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7809 gcc_assert (!non_const
);
7810 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7811 type_expr
, expr
.value
);
7814 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7817 /* Callback function for sizeof_pointer_memaccess_warning to compare
7821 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7823 return comptypes (type1
, type2
) == 1;
7826 /* Parse a postfix expression after the initial primary or compound
7827 literal; that is, parse a series of postfix operators.
7829 EXPR_LOC is the location of the primary expression. */
7831 static struct c_expr
7832 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7833 location_t expr_loc
,
7836 struct c_expr orig_expr
;
7838 location_t sizeof_arg_loc
[3];
7840 unsigned int literal_zero_mask
;
7842 vec
<tree
, va_gc
> *exprlist
;
7843 vec
<tree
, va_gc
> *origtypes
= NULL
;
7844 vec
<location_t
> arg_loc
= vNULL
;
7848 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7849 switch (c_parser_peek_token (parser
)->type
)
7851 case CPP_OPEN_SQUARE
:
7852 /* Array reference. */
7853 c_parser_consume_token (parser
);
7855 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7856 /* If we are here, then we have something like this:
7859 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7863 idx
= c_parser_expression (parser
).value
;
7864 /* Here we have 3 options:
7865 1. Array [EXPR] -- Normal Array call.
7866 2. Array [EXPR : EXPR] -- Array notation without stride.
7867 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7869 For 1, we just handle it just like a normal array expression.
7870 For 2 and 3 we handle it like we handle array notations. The
7871 idx value we have above becomes the initial/start index.
7874 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7875 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7879 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7881 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7884 expr
.original_code
= ERROR_MARK
;
7885 expr
.original_type
= NULL
;
7887 case CPP_OPEN_PAREN
:
7888 /* Function call. */
7889 c_parser_consume_token (parser
);
7890 for (i
= 0; i
< 3; i
++)
7892 sizeof_arg
[i
] = NULL_TREE
;
7893 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7895 literal_zero_mask
= 0;
7896 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7899 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7900 sizeof_arg_loc
, sizeof_arg
,
7901 &arg_loc
, &literal_zero_mask
);
7902 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7905 mark_exp_read (expr
.value
);
7906 if (warn_sizeof_pointer_memaccess
)
7907 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7908 expr
.value
, exprlist
,
7910 sizeof_ptr_memacc_comptypes
);
7911 if (warn_memset_transposed_args
7912 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7913 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7914 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7915 && vec_safe_length (exprlist
) == 3
7916 && integer_zerop ((*exprlist
)[2])
7917 && (literal_zero_mask
& (1 << 2)) != 0
7918 && (!integer_zerop ((*exprlist
)[1])
7919 || (literal_zero_mask
& (1 << 1)) == 0))
7920 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7921 "%<memset%> used with constant zero length parameter; "
7922 "this could be due to transposed parameters");
7925 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7926 exprlist
, origtypes
);
7927 expr
.original_code
= ERROR_MARK
;
7928 if (TREE_CODE (expr
.value
) == INTEGER_CST
7929 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7930 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7931 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7932 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7933 expr
.original_type
= NULL
;
7936 release_tree_vector (exprlist
);
7937 release_tree_vector (origtypes
);
7942 /* Structure element reference. */
7943 c_parser_consume_token (parser
);
7944 expr
= default_function_array_conversion (expr_loc
, expr
);
7945 if (c_parser_next_token_is (parser
, CPP_NAME
))
7946 ident
= c_parser_peek_token (parser
)->value
;
7949 c_parser_error (parser
, "expected identifier");
7950 expr
.value
= error_mark_node
;
7951 expr
.original_code
= ERROR_MARK
;
7952 expr
.original_type
= NULL
;
7955 c_parser_consume_token (parser
);
7956 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7957 expr
.original_code
= ERROR_MARK
;
7958 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7959 expr
.original_type
= NULL
;
7962 /* Remember the original type of a bitfield. */
7963 tree field
= TREE_OPERAND (expr
.value
, 1);
7964 if (TREE_CODE (field
) != FIELD_DECL
)
7965 expr
.original_type
= NULL
;
7967 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7971 /* Structure element reference. */
7972 c_parser_consume_token (parser
);
7973 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7974 if (c_parser_next_token_is (parser
, CPP_NAME
))
7975 ident
= c_parser_peek_token (parser
)->value
;
7978 c_parser_error (parser
, "expected identifier");
7979 expr
.value
= error_mark_node
;
7980 expr
.original_code
= ERROR_MARK
;
7981 expr
.original_type
= NULL
;
7984 c_parser_consume_token (parser
);
7985 expr
.value
= build_component_ref (op_loc
,
7986 build_indirect_ref (op_loc
,
7990 expr
.original_code
= ERROR_MARK
;
7991 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7992 expr
.original_type
= NULL
;
7995 /* Remember the original type of a bitfield. */
7996 tree field
= TREE_OPERAND (expr
.value
, 1);
7997 if (TREE_CODE (field
) != FIELD_DECL
)
7998 expr
.original_type
= NULL
;
8000 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8004 /* Postincrement. */
8005 c_parser_consume_token (parser
);
8006 /* If the expressions have array notations, we expand them. */
8008 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8009 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8012 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8013 expr
.value
= build_unary_op (op_loc
,
8014 POSTINCREMENT_EXPR
, expr
.value
, 0);
8016 expr
.original_code
= ERROR_MARK
;
8017 expr
.original_type
= NULL
;
8019 case CPP_MINUS_MINUS
:
8020 /* Postdecrement. */
8021 c_parser_consume_token (parser
);
8022 /* If the expressions have array notations, we expand them. */
8024 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8025 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8028 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8029 expr
.value
= build_unary_op (op_loc
,
8030 POSTDECREMENT_EXPR
, expr
.value
, 0);
8032 expr
.original_code
= ERROR_MARK
;
8033 expr
.original_type
= NULL
;
8041 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8044 assignment-expression
8045 expression , assignment-expression
8048 static struct c_expr
8049 c_parser_expression (c_parser
*parser
)
8051 location_t tloc
= c_parser_peek_token (parser
)->location
;
8053 expr
= c_parser_expr_no_commas (parser
, NULL
);
8054 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8055 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8056 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8060 location_t loc
= c_parser_peek_token (parser
)->location
;
8061 location_t expr_loc
;
8062 c_parser_consume_token (parser
);
8063 expr_loc
= c_parser_peek_token (parser
)->location
;
8064 lhsval
= expr
.value
;
8065 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8066 lhsval
= TREE_OPERAND (lhsval
, 1);
8067 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8068 mark_exp_read (lhsval
);
8069 next
= c_parser_expr_no_commas (parser
, NULL
);
8070 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8071 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8072 expr
.original_code
= COMPOUND_EXPR
;
8073 expr
.original_type
= next
.original_type
;
8078 /* Parse an expression and convert functions or arrays to pointers and
8079 lvalues to rvalues. */
8081 static struct c_expr
8082 c_parser_expression_conv (c_parser
*parser
)
8085 location_t loc
= c_parser_peek_token (parser
)->location
;
8086 expr
= c_parser_expression (parser
);
8087 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8091 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8092 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8095 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8098 if (idx
>= HOST_BITS_PER_INT
)
8101 c_token
*tok
= c_parser_peek_token (parser
);
8109 /* If a parameter is literal zero alone, remember it
8110 for -Wmemset-transposed-args warning. */
8111 if (integer_zerop (tok
->value
)
8112 && !TREE_OVERFLOW (tok
->value
)
8113 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8114 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8115 *literal_zero_mask
|= 1U << idx
;
8121 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8122 functions and arrays to pointers and lvalues to rvalues. If
8123 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8124 locations of function arguments into this vector.
8127 assignment-expression
8128 nonempty-expr-list , assignment-expression
8131 static vec
<tree
, va_gc
> *
8132 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8133 vec
<tree
, va_gc
> **p_orig_types
,
8134 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8135 vec
<location_t
> *locations
,
8136 unsigned int *literal_zero_mask
)
8138 vec
<tree
, va_gc
> *ret
;
8139 vec
<tree
, va_gc
> *orig_types
;
8141 location_t loc
= c_parser_peek_token (parser
)->location
;
8142 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8143 unsigned int idx
= 0;
8145 ret
= make_tree_vector ();
8146 if (p_orig_types
== NULL
)
8149 orig_types
= make_tree_vector ();
8151 if (sizeof_arg
!= NULL
8152 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8153 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8154 if (literal_zero_mask
)
8155 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8156 expr
= c_parser_expr_no_commas (parser
, NULL
);
8158 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8160 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8161 ret
->quick_push (expr
.value
);
8163 orig_types
->quick_push (expr
.original_type
);
8165 locations
->safe_push (loc
);
8166 if (sizeof_arg
!= NULL
8167 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8168 && expr
.original_code
== SIZEOF_EXPR
)
8170 sizeof_arg
[0] = c_last_sizeof_arg
;
8171 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8173 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8175 c_parser_consume_token (parser
);
8176 loc
= c_parser_peek_token (parser
)->location
;
8177 if (sizeof_arg
!= NULL
8178 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8179 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8181 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8182 if (literal_zero_mask
)
8183 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8184 expr
= c_parser_expr_no_commas (parser
, NULL
);
8186 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8188 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8189 vec_safe_push (ret
, expr
.value
);
8191 vec_safe_push (orig_types
, expr
.original_type
);
8193 locations
->safe_push (loc
);
8195 && sizeof_arg
!= NULL
8196 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8197 && expr
.original_code
== SIZEOF_EXPR
)
8199 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8200 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8204 *p_orig_types
= orig_types
;
8208 /* Parse Objective-C-specific constructs. */
8210 /* Parse an objc-class-definition.
8212 objc-class-definition:
8213 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8214 objc-class-instance-variables[opt] objc-methodprotolist @end
8215 @implementation identifier objc-superclass[opt]
8216 objc-class-instance-variables[opt]
8217 @interface identifier ( identifier ) objc-protocol-refs[opt]
8218 objc-methodprotolist @end
8219 @interface identifier ( ) objc-protocol-refs[opt]
8220 objc-methodprotolist @end
8221 @implementation identifier ( identifier )
8226 "@interface identifier (" must start "@interface identifier (
8227 identifier ) ...": objc-methodprotolist in the first production may
8228 not start with a parenthesized identifier as a declarator of a data
8229 definition with no declaration specifiers if the objc-superclass,
8230 objc-protocol-refs and objc-class-instance-variables are omitted. */
8233 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8238 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8240 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8245 c_parser_consume_token (parser
);
8246 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8248 c_parser_error (parser
, "expected identifier");
8251 id1
= c_parser_peek_token (parser
)->value
;
8252 c_parser_consume_token (parser
);
8253 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8255 /* We have a category or class extension. */
8257 tree proto
= NULL_TREE
;
8258 c_parser_consume_token (parser
);
8259 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8261 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8263 /* We have a class extension. */
8268 c_parser_error (parser
, "expected identifier or %<)%>");
8269 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8275 id2
= c_parser_peek_token (parser
)->value
;
8276 c_parser_consume_token (parser
);
8278 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8281 objc_start_category_implementation (id1
, id2
);
8284 if (c_parser_next_token_is (parser
, CPP_LESS
))
8285 proto
= c_parser_objc_protocol_refs (parser
);
8286 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8287 c_parser_objc_methodprotolist (parser
);
8288 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8289 objc_finish_interface ();
8292 if (c_parser_next_token_is (parser
, CPP_COLON
))
8294 c_parser_consume_token (parser
);
8295 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8297 c_parser_error (parser
, "expected identifier");
8300 superclass
= c_parser_peek_token (parser
)->value
;
8301 c_parser_consume_token (parser
);
8304 superclass
= NULL_TREE
;
8307 tree proto
= NULL_TREE
;
8308 if (c_parser_next_token_is (parser
, CPP_LESS
))
8309 proto
= c_parser_objc_protocol_refs (parser
);
8310 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8313 objc_start_class_implementation (id1
, superclass
);
8314 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8315 c_parser_objc_class_instance_variables (parser
);
8318 objc_continue_interface ();
8319 c_parser_objc_methodprotolist (parser
);
8320 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8321 objc_finish_interface ();
8325 objc_continue_implementation ();
8330 /* Parse objc-class-instance-variables.
8332 objc-class-instance-variables:
8333 { objc-instance-variable-decl-list[opt] }
8335 objc-instance-variable-decl-list:
8336 objc-visibility-spec
8337 objc-instance-variable-decl ;
8339 objc-instance-variable-decl-list objc-visibility-spec
8340 objc-instance-variable-decl-list objc-instance-variable-decl ;
8341 objc-instance-variable-decl-list ;
8343 objc-visibility-spec:
8348 objc-instance-variable-decl:
8353 c_parser_objc_class_instance_variables (c_parser
*parser
)
8355 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8356 c_parser_consume_token (parser
);
8357 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8360 /* Parse any stray semicolon. */
8361 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8363 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8365 c_parser_consume_token (parser
);
8368 /* Stop if at the end of the instance variables. */
8369 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8371 c_parser_consume_token (parser
);
8374 /* Parse any objc-visibility-spec. */
8375 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8377 c_parser_consume_token (parser
);
8378 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8381 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8383 c_parser_consume_token (parser
);
8384 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8387 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8389 c_parser_consume_token (parser
);
8390 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8393 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8395 c_parser_consume_token (parser
);
8396 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8399 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8401 c_parser_pragma (parser
, pragma_external
);
8405 /* Parse some comma-separated declarations. */
8406 decls
= c_parser_struct_declaration (parser
);
8409 /* There is a syntax error. We want to skip the offending
8410 tokens up to the next ';' (included) or '}'
8413 /* First, skip manually a ')' or ']'. This is because they
8414 reduce the nesting level, so c_parser_skip_until_found()
8415 wouldn't be able to skip past them. */
8416 c_token
*token
= c_parser_peek_token (parser
);
8417 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8418 c_parser_consume_token (parser
);
8420 /* Then, do the standard skipping. */
8421 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8423 /* We hopefully recovered. Start normal parsing again. */
8424 parser
->error
= false;
8429 /* Comma-separated instance variables are chained together
8430 in reverse order; add them one by one. */
8431 tree ivar
= nreverse (decls
);
8432 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8433 objc_add_instance_variable (copy_node (ivar
));
8435 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8439 /* Parse an objc-class-declaration.
8441 objc-class-declaration:
8442 @class identifier-list ;
8446 c_parser_objc_class_declaration (c_parser
*parser
)
8448 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8449 c_parser_consume_token (parser
);
8450 /* Any identifiers, including those declared as type names, are OK
8455 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8457 c_parser_error (parser
, "expected identifier");
8458 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8459 parser
->error
= false;
8462 id
= c_parser_peek_token (parser
)->value
;
8463 objc_declare_class (id
);
8464 c_parser_consume_token (parser
);
8465 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8466 c_parser_consume_token (parser
);
8470 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8473 /* Parse an objc-alias-declaration.
8475 objc-alias-declaration:
8476 @compatibility_alias identifier identifier ;
8480 c_parser_objc_alias_declaration (c_parser
*parser
)
8483 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8484 c_parser_consume_token (parser
);
8485 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8487 c_parser_error (parser
, "expected identifier");
8488 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8491 id1
= c_parser_peek_token (parser
)->value
;
8492 c_parser_consume_token (parser
);
8493 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8495 c_parser_error (parser
, "expected identifier");
8496 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8499 id2
= c_parser_peek_token (parser
)->value
;
8500 c_parser_consume_token (parser
);
8501 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8502 objc_declare_alias (id1
, id2
);
8505 /* Parse an objc-protocol-definition.
8507 objc-protocol-definition:
8508 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8509 @protocol identifier-list ;
8511 "@protocol identifier ;" should be resolved as "@protocol
8512 identifier-list ;": objc-methodprotolist may not start with a
8513 semicolon in the first alternative if objc-protocol-refs are
8517 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8519 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8521 c_parser_consume_token (parser
);
8522 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8524 c_parser_error (parser
, "expected identifier");
8527 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8528 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8530 /* Any identifiers, including those declared as type names, are
8535 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8537 c_parser_error (parser
, "expected identifier");
8540 id
= c_parser_peek_token (parser
)->value
;
8541 objc_declare_protocol (id
, attributes
);
8542 c_parser_consume_token (parser
);
8543 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8544 c_parser_consume_token (parser
);
8548 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8552 tree id
= c_parser_peek_token (parser
)->value
;
8553 tree proto
= NULL_TREE
;
8554 c_parser_consume_token (parser
);
8555 if (c_parser_next_token_is (parser
, CPP_LESS
))
8556 proto
= c_parser_objc_protocol_refs (parser
);
8557 parser
->objc_pq_context
= true;
8558 objc_start_protocol (id
, proto
, attributes
);
8559 c_parser_objc_methodprotolist (parser
);
8560 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8561 parser
->objc_pq_context
= false;
8562 objc_finish_interface ();
8566 /* Parse an objc-method-type.
8572 Return true if it is a class method (+) and false if it is
8573 an instance method (-).
8576 c_parser_objc_method_type (c_parser
*parser
)
8578 switch (c_parser_peek_token (parser
)->type
)
8581 c_parser_consume_token (parser
);
8584 c_parser_consume_token (parser
);
8591 /* Parse an objc-method-definition.
8593 objc-method-definition:
8594 objc-method-type objc-method-decl ;[opt] compound-statement
8598 c_parser_objc_method_definition (c_parser
*parser
)
8600 bool is_class_method
= c_parser_objc_method_type (parser
);
8601 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8602 parser
->objc_pq_context
= true;
8603 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8605 if (decl
== error_mark_node
)
8606 return; /* Bail here. */
8608 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8610 c_parser_consume_token (parser
);
8611 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8612 "extra semicolon in method definition specified");
8615 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8617 c_parser_error (parser
, "expected %<{%>");
8621 parser
->objc_pq_context
= false;
8622 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8624 add_stmt (c_parser_compound_statement (parser
));
8625 objc_finish_method_definition (current_function_decl
);
8629 /* This code is executed when we find a method definition
8630 outside of an @implementation context (or invalid for other
8631 reasons). Parse the method (to keep going) but do not emit
8634 c_parser_compound_statement (parser
);
8638 /* Parse an objc-methodprotolist.
8640 objc-methodprotolist:
8642 objc-methodprotolist objc-methodproto
8643 objc-methodprotolist declaration
8644 objc-methodprotolist ;
8648 The declaration is a data definition, which may be missing
8649 declaration specifiers under the same rules and diagnostics as
8650 other data definitions outside functions, and the stray semicolon
8651 is diagnosed the same way as a stray semicolon outside a
8655 c_parser_objc_methodprotolist (c_parser
*parser
)
8659 /* The list is terminated by @end. */
8660 switch (c_parser_peek_token (parser
)->type
)
8663 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8664 "ISO C does not allow extra %<;%> outside of a function");
8665 c_parser_consume_token (parser
);
8669 c_parser_objc_methodproto (parser
);
8672 c_parser_pragma (parser
, pragma_external
);
8677 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8679 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8680 c_parser_objc_at_property_declaration (parser
);
8681 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8683 objc_set_method_opt (true);
8684 c_parser_consume_token (parser
);
8686 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8688 objc_set_method_opt (false);
8689 c_parser_consume_token (parser
);
8692 c_parser_declaration_or_fndef (parser
, false, false, true,
8693 false, true, NULL
, vNULL
);
8699 /* Parse an objc-methodproto.
8702 objc-method-type objc-method-decl ;
8706 c_parser_objc_methodproto (c_parser
*parser
)
8708 bool is_class_method
= c_parser_objc_method_type (parser
);
8709 tree decl
, attributes
= NULL_TREE
;
8711 /* Remember protocol qualifiers in prototypes. */
8712 parser
->objc_pq_context
= true;
8713 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8715 /* Forget protocol qualifiers now. */
8716 parser
->objc_pq_context
= false;
8718 /* Do not allow the presence of attributes to hide an erroneous
8719 method implementation in the interface section. */
8720 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8722 c_parser_error (parser
, "expected %<;%>");
8726 if (decl
!= error_mark_node
)
8727 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8729 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8732 /* If we are at a position that method attributes may be present, check that
8733 there are not any parsed already (a syntax error) and then collect any
8734 specified at the current location. Finally, if new attributes were present,
8735 check that the next token is legal ( ';' for decls and '{' for defs). */
8738 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8743 c_parser_error (parser
,
8744 "method attributes must be specified at the end only");
8745 *attributes
= NULL_TREE
;
8749 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8750 *attributes
= c_parser_attributes (parser
);
8752 /* If there were no attributes here, just report any earlier error. */
8753 if (*attributes
== NULL_TREE
|| bad
)
8756 /* If the attributes are followed by a ; or {, then just report any earlier
8758 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8759 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8762 /* We've got attributes, but not at the end. */
8763 c_parser_error (parser
,
8764 "expected %<;%> or %<{%> after method attribute definition");
8768 /* Parse an objc-method-decl.
8771 ( objc-type-name ) objc-selector
8773 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8774 objc-keyword-selector objc-optparmlist
8777 objc-keyword-selector:
8779 objc-keyword-selector objc-keyword-decl
8782 objc-selector : ( objc-type-name ) identifier
8783 objc-selector : identifier
8784 : ( objc-type-name ) identifier
8788 objc-optparms objc-optellipsis
8792 objc-opt-parms , parameter-declaration
8800 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8801 tree
*attributes
, tree
*expr
)
8803 tree type
= NULL_TREE
;
8805 tree parms
= NULL_TREE
;
8806 bool ellipsis
= false;
8807 bool attr_err
= false;
8809 *attributes
= NULL_TREE
;
8810 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8812 c_parser_consume_token (parser
);
8813 type
= c_parser_objc_type_name (parser
);
8814 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8816 sel
= c_parser_objc_selector (parser
);
8817 /* If there is no selector, or a colon follows, we have an
8818 objc-keyword-selector. If there is a selector, and a colon does
8819 not follow, that selector ends the objc-method-decl. */
8820 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8823 tree list
= NULL_TREE
;
8826 tree atype
= NULL_TREE
, id
, keyworddecl
;
8827 tree param_attr
= NULL_TREE
;
8828 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8830 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8832 c_parser_consume_token (parser
);
8833 atype
= c_parser_objc_type_name (parser
);
8834 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8837 /* New ObjC allows attributes on method parameters. */
8838 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8839 param_attr
= c_parser_attributes (parser
);
8840 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8842 c_parser_error (parser
, "expected identifier");
8843 return error_mark_node
;
8845 id
= c_parser_peek_token (parser
)->value
;
8846 c_parser_consume_token (parser
);
8847 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8848 list
= chainon (list
, keyworddecl
);
8849 tsel
= c_parser_objc_selector (parser
);
8850 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8854 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8856 /* Parse the optional parameter list. Optional Objective-C
8857 method parameters follow the C syntax, and may include '...'
8858 to denote a variable number of arguments. */
8859 parms
= make_node (TREE_LIST
);
8860 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8862 struct c_parm
*parm
;
8863 c_parser_consume_token (parser
);
8864 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8867 c_parser_consume_token (parser
);
8868 attr_err
|= c_parser_objc_maybe_method_attributes
8869 (parser
, attributes
) ;
8872 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8875 parms
= chainon (parms
,
8876 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8881 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8885 c_parser_error (parser
, "objective-c method declaration is expected");
8886 return error_mark_node
;
8890 return error_mark_node
;
8892 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8895 /* Parse an objc-type-name.
8898 objc-type-qualifiers[opt] type-name
8899 objc-type-qualifiers[opt]
8901 objc-type-qualifiers:
8903 objc-type-qualifiers objc-type-qualifier
8905 objc-type-qualifier: one of
8906 in out inout bycopy byref oneway
8910 c_parser_objc_type_name (c_parser
*parser
)
8912 tree quals
= NULL_TREE
;
8913 struct c_type_name
*type_name
= NULL
;
8914 tree type
= NULL_TREE
;
8917 c_token
*token
= c_parser_peek_token (parser
);
8918 if (token
->type
== CPP_KEYWORD
8919 && (token
->keyword
== RID_IN
8920 || token
->keyword
== RID_OUT
8921 || token
->keyword
== RID_INOUT
8922 || token
->keyword
== RID_BYCOPY
8923 || token
->keyword
== RID_BYREF
8924 || token
->keyword
== RID_ONEWAY
))
8926 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8927 c_parser_consume_token (parser
);
8932 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8933 type_name
= c_parser_type_name (parser
);
8935 type
= groktypename (type_name
, NULL
, NULL
);
8937 /* If the type is unknown, and error has already been produced and
8938 we need to recover from the error. In that case, use NULL_TREE
8939 for the type, as if no type had been specified; this will use the
8940 default type ('id') which is good for error recovery. */
8941 if (type
== error_mark_node
)
8944 return build_tree_list (quals
, type
);
8947 /* Parse objc-protocol-refs.
8954 c_parser_objc_protocol_refs (c_parser
*parser
)
8956 tree list
= NULL_TREE
;
8957 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8958 c_parser_consume_token (parser
);
8959 /* Any identifiers, including those declared as type names, are OK
8964 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8966 c_parser_error (parser
, "expected identifier");
8969 id
= c_parser_peek_token (parser
)->value
;
8970 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8971 c_parser_consume_token (parser
);
8972 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8973 c_parser_consume_token (parser
);
8977 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8981 /* Parse an objc-try-catch-finally-statement.
8983 objc-try-catch-finally-statement:
8984 @try compound-statement objc-catch-list[opt]
8985 @try compound-statement objc-catch-list[opt] @finally compound-statement
8988 @catch ( objc-catch-parameter-declaration ) compound-statement
8989 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8991 objc-catch-parameter-declaration:
8992 parameter-declaration
8995 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8997 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8998 for C++. Keep them in sync. */
9001 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9003 location_t location
;
9006 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9007 c_parser_consume_token (parser
);
9008 location
= c_parser_peek_token (parser
)->location
;
9009 objc_maybe_warn_exceptions (location
);
9010 stmt
= c_parser_compound_statement (parser
);
9011 objc_begin_try_stmt (location
, stmt
);
9013 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9015 struct c_parm
*parm
;
9016 tree parameter_declaration
= error_mark_node
;
9017 bool seen_open_paren
= false;
9019 c_parser_consume_token (parser
);
9020 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9021 seen_open_paren
= true;
9022 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9024 /* We have "@catch (...)" (where the '...' are literally
9025 what is in the code). Skip the '...'.
9026 parameter_declaration is set to NULL_TREE, and
9027 objc_being_catch_clauses() knows that that means
9029 c_parser_consume_token (parser
);
9030 parameter_declaration
= NULL_TREE
;
9034 /* We have "@catch (NSException *exception)" or something
9035 like that. Parse the parameter declaration. */
9036 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9038 parameter_declaration
= error_mark_node
;
9040 parameter_declaration
= grokparm (parm
, NULL
);
9042 if (seen_open_paren
)
9043 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9046 /* If there was no open parenthesis, we are recovering from
9047 an error, and we are trying to figure out what mistake
9048 the user has made. */
9050 /* If there is an immediate closing parenthesis, the user
9051 probably forgot the opening one (ie, they typed "@catch
9052 NSException *e)". Parse the closing parenthesis and keep
9054 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9055 c_parser_consume_token (parser
);
9057 /* If these is no immediate closing parenthesis, the user
9058 probably doesn't know that parenthesis are required at
9059 all (ie, they typed "@catch NSException *e"). So, just
9060 forget about the closing parenthesis and keep going. */
9062 objc_begin_catch_clause (parameter_declaration
);
9063 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9064 c_parser_compound_statement_nostart (parser
);
9065 objc_finish_catch_clause ();
9067 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9069 c_parser_consume_token (parser
);
9070 location
= c_parser_peek_token (parser
)->location
;
9071 stmt
= c_parser_compound_statement (parser
);
9072 objc_build_finally_clause (location
, stmt
);
9074 objc_finish_try_stmt ();
9077 /* Parse an objc-synchronized-statement.
9079 objc-synchronized-statement:
9080 @synchronized ( expression ) compound-statement
9084 c_parser_objc_synchronized_statement (c_parser
*parser
)
9088 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9089 c_parser_consume_token (parser
);
9090 loc
= c_parser_peek_token (parser
)->location
;
9091 objc_maybe_warn_exceptions (loc
);
9092 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9094 struct c_expr ce
= c_parser_expression (parser
);
9095 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9097 expr
= c_fully_fold (expr
, false, NULL
);
9098 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9101 expr
= error_mark_node
;
9102 stmt
= c_parser_compound_statement (parser
);
9103 objc_build_synchronized (loc
, expr
, stmt
);
9106 /* Parse an objc-selector; return NULL_TREE without an error if the
9107 next token is not an objc-selector.
9112 enum struct union if else while do for switch case default
9113 break continue return goto asm sizeof typeof __alignof
9114 unsigned long const short volatile signed restrict _Complex
9115 in out inout bycopy byref oneway int char float double void _Bool
9118 ??? Why this selection of keywords but not, for example, storage
9119 class specifiers? */
9122 c_parser_objc_selector (c_parser
*parser
)
9124 c_token
*token
= c_parser_peek_token (parser
);
9125 tree value
= token
->value
;
9126 if (token
->type
== CPP_NAME
)
9128 c_parser_consume_token (parser
);
9131 if (token
->type
!= CPP_KEYWORD
)
9133 switch (token
->keyword
)
9180 c_parser_consume_token (parser
);
9187 /* Parse an objc-selector-arg.
9191 objc-keywordname-list
9193 objc-keywordname-list:
9195 objc-keywordname-list objc-keywordname
9203 c_parser_objc_selector_arg (c_parser
*parser
)
9205 tree sel
= c_parser_objc_selector (parser
);
9206 tree list
= NULL_TREE
;
9207 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9211 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9213 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9214 sel
= c_parser_objc_selector (parser
);
9215 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9221 /* Parse an objc-receiver.
9230 c_parser_objc_receiver (c_parser
*parser
)
9232 location_t loc
= c_parser_peek_token (parser
)->location
;
9234 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9235 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9236 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9238 tree id
= c_parser_peek_token (parser
)->value
;
9239 c_parser_consume_token (parser
);
9240 return objc_get_class_reference (id
);
9242 struct c_expr ce
= c_parser_expression (parser
);
9243 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9244 return c_fully_fold (ce
.value
, false, NULL
);
9247 /* Parse objc-message-args.
9251 objc-keywordarg-list
9253 objc-keywordarg-list:
9255 objc-keywordarg-list objc-keywordarg
9258 objc-selector : objc-keywordexpr
9263 c_parser_objc_message_args (c_parser
*parser
)
9265 tree sel
= c_parser_objc_selector (parser
);
9266 tree list
= NULL_TREE
;
9267 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9272 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9273 return error_mark_node
;
9274 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9275 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9276 sel
= c_parser_objc_selector (parser
);
9277 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9283 /* Parse an objc-keywordexpr.
9290 c_parser_objc_keywordexpr (c_parser
*parser
)
9293 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9294 NULL
, NULL
, NULL
, NULL
);
9295 if (vec_safe_length (expr_list
) == 1)
9297 /* Just return the expression, remove a level of
9299 ret
= (*expr_list
)[0];
9303 /* We have a comma expression, we will collapse later. */
9304 ret
= build_tree_list_vec (expr_list
);
9306 release_tree_vector (expr_list
);
9310 /* A check, needed in several places, that ObjC interface, implementation or
9311 method definitions are not prefixed by incorrect items. */
9313 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9314 struct c_declspecs
*specs
)
9316 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9317 || specs
->typespec_kind
!= ctsk_none
)
9319 c_parser_error (parser
,
9320 "no type or storage class may be specified here,");
9321 c_parser_skip_to_end_of_block_or_statement (parser
);
9327 /* Parse an Objective-C @property declaration. The syntax is:
9329 objc-property-declaration:
9330 '@property' objc-property-attributes[opt] struct-declaration ;
9332 objc-property-attributes:
9333 '(' objc-property-attribute-list ')'
9335 objc-property-attribute-list:
9336 objc-property-attribute
9337 objc-property-attribute-list, objc-property-attribute
9339 objc-property-attribute
9340 'getter' = identifier
9341 'setter' = identifier
9350 @property NSString *name;
9351 @property (readonly) id object;
9352 @property (retain, nonatomic, getter=getTheName) id name;
9353 @property int a, b, c;
9355 PS: This function is identical to cp_parser_objc_at_propery_declaration
9356 for C++. Keep them in sync. */
9358 c_parser_objc_at_property_declaration (c_parser
*parser
)
9360 /* The following variables hold the attributes of the properties as
9361 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9362 seen. When we see an attribute, we set them to 'true' (if they
9363 are boolean properties) or to the identifier (if they have an
9364 argument, ie, for getter and setter). Note that here we only
9365 parse the list of attributes, check the syntax and accumulate the
9366 attributes that we find. objc_add_property_declaration() will
9367 then process the information. */
9368 bool property_assign
= false;
9369 bool property_copy
= false;
9370 tree property_getter_ident
= NULL_TREE
;
9371 bool property_nonatomic
= false;
9372 bool property_readonly
= false;
9373 bool property_readwrite
= false;
9374 bool property_retain
= false;
9375 tree property_setter_ident
= NULL_TREE
;
9377 /* 'properties' is the list of properties that we read. Usually a
9378 single one, but maybe more (eg, in "@property int a, b, c;" there
9383 loc
= c_parser_peek_token (parser
)->location
;
9384 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9386 c_parser_consume_token (parser
); /* Eat '@property'. */
9388 /* Parse the optional attribute list... */
9389 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9392 c_parser_consume_token (parser
);
9394 /* Property attribute keywords are valid now. */
9395 parser
->objc_property_attr_context
= true;
9399 bool syntax_error
= false;
9400 c_token
*token
= c_parser_peek_token (parser
);
9403 if (token
->type
!= CPP_KEYWORD
)
9405 if (token
->type
== CPP_CLOSE_PAREN
)
9406 c_parser_error (parser
, "expected identifier");
9409 c_parser_consume_token (parser
);
9410 c_parser_error (parser
, "unknown property attribute");
9414 keyword
= token
->keyword
;
9415 c_parser_consume_token (parser
);
9418 case RID_ASSIGN
: property_assign
= true; break;
9419 case RID_COPY
: property_copy
= true; break;
9420 case RID_NONATOMIC
: property_nonatomic
= true; break;
9421 case RID_READONLY
: property_readonly
= true; break;
9422 case RID_READWRITE
: property_readwrite
= true; break;
9423 case RID_RETAIN
: property_retain
= true; break;
9427 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9429 if (keyword
== RID_GETTER
)
9430 c_parser_error (parser
,
9431 "missing %<=%> (after %<getter%> attribute)");
9433 c_parser_error (parser
,
9434 "missing %<=%> (after %<setter%> attribute)");
9435 syntax_error
= true;
9438 c_parser_consume_token (parser
); /* eat the = */
9439 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9441 c_parser_error (parser
, "expected identifier");
9442 syntax_error
= true;
9445 if (keyword
== RID_SETTER
)
9447 if (property_setter_ident
!= NULL_TREE
)
9448 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9450 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9451 c_parser_consume_token (parser
);
9452 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9453 c_parser_error (parser
, "setter name must terminate with %<:%>");
9455 c_parser_consume_token (parser
);
9459 if (property_getter_ident
!= NULL_TREE
)
9460 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9462 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9463 c_parser_consume_token (parser
);
9467 c_parser_error (parser
, "unknown property attribute");
9468 syntax_error
= true;
9475 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9476 c_parser_consume_token (parser
);
9480 parser
->objc_property_attr_context
= false;
9481 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9483 /* ... and the property declaration(s). */
9484 properties
= c_parser_struct_declaration (parser
);
9486 if (properties
== error_mark_node
)
9488 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9489 parser
->error
= false;
9493 if (properties
== NULL_TREE
)
9494 c_parser_error (parser
, "expected identifier");
9497 /* Comma-separated properties are chained together in
9498 reverse order; add them one by one. */
9499 properties
= nreverse (properties
);
9501 for (; properties
; properties
= TREE_CHAIN (properties
))
9502 objc_add_property_declaration (loc
, copy_node (properties
),
9503 property_readonly
, property_readwrite
,
9504 property_assign
, property_retain
,
9505 property_copy
, property_nonatomic
,
9506 property_getter_ident
, property_setter_ident
);
9509 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9510 parser
->error
= false;
9513 /* Parse an Objective-C @synthesize declaration. The syntax is:
9515 objc-synthesize-declaration:
9516 @synthesize objc-synthesize-identifier-list ;
9518 objc-synthesize-identifier-list:
9519 objc-synthesize-identifier
9520 objc-synthesize-identifier-list, objc-synthesize-identifier
9522 objc-synthesize-identifier
9524 identifier = identifier
9527 @synthesize MyProperty;
9528 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9530 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9531 for C++. Keep them in sync.
9534 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9536 tree list
= NULL_TREE
;
9538 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9539 loc
= c_parser_peek_token (parser
)->location
;
9541 c_parser_consume_token (parser
);
9544 tree property
, ivar
;
9545 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9547 c_parser_error (parser
, "expected identifier");
9548 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9549 /* Once we find the semicolon, we can resume normal parsing.
9550 We have to reset parser->error manually because
9551 c_parser_skip_until_found() won't reset it for us if the
9552 next token is precisely a semicolon. */
9553 parser
->error
= false;
9556 property
= c_parser_peek_token (parser
)->value
;
9557 c_parser_consume_token (parser
);
9558 if (c_parser_next_token_is (parser
, CPP_EQ
))
9560 c_parser_consume_token (parser
);
9561 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9563 c_parser_error (parser
, "expected identifier");
9564 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9565 parser
->error
= false;
9568 ivar
= c_parser_peek_token (parser
)->value
;
9569 c_parser_consume_token (parser
);
9573 list
= chainon (list
, build_tree_list (ivar
, property
));
9574 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9575 c_parser_consume_token (parser
);
9579 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9580 objc_add_synthesize_declaration (loc
, list
);
9583 /* Parse an Objective-C @dynamic declaration. The syntax is:
9585 objc-dynamic-declaration:
9586 @dynamic identifier-list ;
9589 @dynamic MyProperty;
9590 @dynamic MyProperty, AnotherProperty;
9592 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9593 for C++. Keep them in sync.
9596 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9598 tree list
= NULL_TREE
;
9600 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9601 loc
= c_parser_peek_token (parser
)->location
;
9603 c_parser_consume_token (parser
);
9607 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9609 c_parser_error (parser
, "expected identifier");
9610 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9611 parser
->error
= false;
9614 property
= c_parser_peek_token (parser
)->value
;
9615 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9616 c_parser_consume_token (parser
);
9617 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9618 c_parser_consume_token (parser
);
9622 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9623 objc_add_dynamic_declaration (loc
, list
);
9627 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9628 should be considered, statements. ALLOW_STMT is true if we're within
9629 the context of a function and such pragmas are to be allowed. Returns
9630 true if we actually parsed such a pragma. */
9633 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9637 id
= c_parser_peek_token (parser
)->pragma_kind
;
9638 gcc_assert (id
!= PRAGMA_NONE
);
9642 case PRAGMA_OACC_ENTER_DATA
:
9643 c_parser_oacc_enter_exit_data (parser
, true);
9646 case PRAGMA_OACC_EXIT_DATA
:
9647 c_parser_oacc_enter_exit_data (parser
, false);
9650 case PRAGMA_OACC_UPDATE
:
9651 if (context
!= pragma_compound
)
9653 if (context
== pragma_stmt
)
9654 c_parser_error (parser
, "%<#pragma acc update%> may only be "
9655 "used in compound statements");
9658 c_parser_oacc_update (parser
);
9661 case PRAGMA_OMP_BARRIER
:
9662 if (context
!= pragma_compound
)
9664 if (context
== pragma_stmt
)
9665 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9666 "used in compound statements");
9669 c_parser_omp_barrier (parser
);
9672 case PRAGMA_OMP_FLUSH
:
9673 if (context
!= pragma_compound
)
9675 if (context
== pragma_stmt
)
9676 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9677 "used in compound statements");
9680 c_parser_omp_flush (parser
);
9683 case PRAGMA_OMP_TASKWAIT
:
9684 if (context
!= pragma_compound
)
9686 if (context
== pragma_stmt
)
9687 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9688 "used in compound statements");
9691 c_parser_omp_taskwait (parser
);
9694 case PRAGMA_OMP_TASKYIELD
:
9695 if (context
!= pragma_compound
)
9697 if (context
== pragma_stmt
)
9698 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9699 "used in compound statements");
9702 c_parser_omp_taskyield (parser
);
9705 case PRAGMA_OMP_CANCEL
:
9706 if (context
!= pragma_compound
)
9708 if (context
== pragma_stmt
)
9709 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9710 "used in compound statements");
9713 c_parser_omp_cancel (parser
);
9716 case PRAGMA_OMP_CANCELLATION_POINT
:
9717 if (context
!= pragma_compound
)
9719 if (context
== pragma_stmt
)
9720 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9721 "only be used in compound statements");
9724 c_parser_omp_cancellation_point (parser
);
9727 case PRAGMA_OMP_THREADPRIVATE
:
9728 c_parser_omp_threadprivate (parser
);
9731 case PRAGMA_OMP_TARGET
:
9732 return c_parser_omp_target (parser
, context
);
9734 case PRAGMA_OMP_END_DECLARE_TARGET
:
9735 c_parser_omp_end_declare_target (parser
);
9738 case PRAGMA_OMP_SECTION
:
9739 error_at (c_parser_peek_token (parser
)->location
,
9740 "%<#pragma omp section%> may only be used in "
9741 "%<#pragma omp sections%> construct");
9742 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9745 case PRAGMA_OMP_DECLARE_REDUCTION
:
9746 c_parser_omp_declare (parser
, context
);
9749 c_parser_consume_pragma (parser
);
9750 c_parser_skip_to_pragma_eol (parser
);
9751 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9752 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9753 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9755 c_parser_error (parser
, "for, while or do statement expected");
9758 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9759 c_parser_for_statement (parser
, true);
9760 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9761 c_parser_while_statement (parser
, true);
9763 c_parser_do_statement (parser
, true);
9766 case PRAGMA_GCC_PCH_PREPROCESS
:
9767 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9768 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9771 case PRAGMA_CILK_SIMD
:
9772 if (!c_parser_cilk_verify_simd (parser
, context
))
9774 c_parser_consume_pragma (parser
);
9775 c_parser_cilk_simd (parser
);
9777 case PRAGMA_CILK_GRAINSIZE
:
9780 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9782 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9785 if (context
== pragma_external
)
9787 error_at (c_parser_peek_token (parser
)->location
,
9788 "%<#pragma grainsize%> must be inside a function");
9789 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9792 c_parser_cilk_grainsize (parser
);
9796 if (id
< PRAGMA_FIRST_EXTERNAL
)
9798 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9801 c_parser_error (parser
, "expected declaration specifiers");
9802 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9805 c_parser_omp_construct (parser
);
9811 c_parser_consume_pragma (parser
);
9812 c_invoke_pragma_handler (id
);
9814 /* Skip to EOL, but suppress any error message. Those will have been
9815 generated by the handler routine through calling error, as opposed
9816 to calling c_parser_error. */
9817 parser
->error
= true;
9818 c_parser_skip_to_pragma_eol (parser
);
9823 /* The interface the pragma parsers have to the lexer. */
9826 pragma_lex (tree
*value
)
9828 c_token
*tok
= c_parser_peek_token (the_parser
);
9829 enum cpp_ttype ret
= tok
->type
;
9831 *value
= tok
->value
;
9832 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9836 if (ret
== CPP_KEYWORD
)
9838 c_parser_consume_token (the_parser
);
9845 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9849 c_parser_consume_pragma (parser
);
9850 if (c_parser_next_token_is (parser
, CPP_STRING
))
9852 name
= c_parser_peek_token (parser
)->value
;
9853 c_parser_consume_token (parser
);
9856 c_parser_error (parser
, "expected string literal");
9857 c_parser_skip_to_pragma_eol (parser
);
9860 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9863 /* OpenACC and OpenMP parsing routines. */
9865 /* Returns name of the next clause.
9866 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9867 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9868 returned and the token is consumed. */
9870 static pragma_omp_clause
9871 c_parser_omp_clause_name (c_parser
*parser
)
9873 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9875 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9876 result
= PRAGMA_OACC_CLAUSE_AUTO
;
9877 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9878 result
= PRAGMA_OMP_CLAUSE_IF
;
9879 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9880 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9881 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9882 result
= PRAGMA_OMP_CLAUSE_FOR
;
9883 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9885 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9890 if (!strcmp ("aligned", p
))
9891 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9892 else if (!strcmp ("async", p
))
9893 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
9896 if (!strcmp ("collapse", p
))
9897 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9898 else if (!strcmp ("copy", p
))
9899 result
= PRAGMA_OACC_CLAUSE_COPY
;
9900 else if (!strcmp ("copyin", p
))
9901 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9902 else if (!strcmp ("copyout", p
))
9903 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
9904 else if (!strcmp ("copyprivate", p
))
9905 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9906 else if (!strcmp ("create", p
))
9907 result
= PRAGMA_OACC_CLAUSE_CREATE
;
9910 if (!strcmp ("delete", p
))
9911 result
= PRAGMA_OACC_CLAUSE_DELETE
;
9912 else if (!strcmp ("depend", p
))
9913 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9914 else if (!strcmp ("device", p
))
9915 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9916 else if (!strcmp ("deviceptr", p
))
9917 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
9918 else if (!strcmp ("dist_schedule", p
))
9919 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9922 if (!strcmp ("final", p
))
9923 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9924 else if (!strcmp ("firstprivate", p
))
9925 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9926 else if (!strcmp ("from", p
))
9927 result
= PRAGMA_OMP_CLAUSE_FROM
;
9930 if (!strcmp ("gang", p
))
9931 result
= PRAGMA_OACC_CLAUSE_GANG
;
9934 if (!strcmp ("host", p
))
9935 result
= PRAGMA_OACC_CLAUSE_HOST
;
9938 if (!strcmp ("inbranch", p
))
9939 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9942 if (!strcmp ("lastprivate", p
))
9943 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9944 else if (!strcmp ("linear", p
))
9945 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9948 if (!strcmp ("map", p
))
9949 result
= PRAGMA_OMP_CLAUSE_MAP
;
9950 else if (!strcmp ("mergeable", p
))
9951 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9952 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9953 result
= PRAGMA_CILK_CLAUSE_MASK
;
9956 if (!strcmp ("notinbranch", p
))
9957 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9958 else if (!strcmp ("nowait", p
))
9959 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9960 else if (!strcmp ("num_gangs", p
))
9961 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
9962 else if (!strcmp ("num_teams", p
))
9963 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9964 else if (!strcmp ("num_threads", p
))
9965 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9966 else if (!strcmp ("num_workers", p
))
9967 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
9968 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9969 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9972 if (!strcmp ("ordered", p
))
9973 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9976 if (!strcmp ("parallel", p
))
9977 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9978 else if (!strcmp ("present", p
))
9979 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
9980 else if (!strcmp ("present_or_copy", p
)
9981 || !strcmp ("pcopy", p
))
9982 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
9983 else if (!strcmp ("present_or_copyin", p
)
9984 || !strcmp ("pcopyin", p
))
9985 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
9986 else if (!strcmp ("present_or_copyout", p
)
9987 || !strcmp ("pcopyout", p
))
9988 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
9989 else if (!strcmp ("present_or_create", p
)
9990 || !strcmp ("pcreate", p
))
9991 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
9992 else if (!strcmp ("private", p
))
9993 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9994 else if (!strcmp ("proc_bind", p
))
9995 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9998 if (!strcmp ("reduction", p
))
9999 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10002 if (!strcmp ("safelen", p
))
10003 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10004 else if (!strcmp ("schedule", p
))
10005 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10006 else if (!strcmp ("sections", p
))
10007 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10008 else if (!strcmp ("seq", p
))
10009 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10010 else if (!strcmp ("shared", p
))
10011 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10012 else if (!strcmp ("simdlen", p
))
10013 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10014 else if (!strcmp ("self", p
))
10015 result
= PRAGMA_OACC_CLAUSE_SELF
;
10018 if (!strcmp ("taskgroup", p
))
10019 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10020 else if (!strcmp ("thread_limit", p
))
10021 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10022 else if (!strcmp ("to", p
))
10023 result
= PRAGMA_OMP_CLAUSE_TO
;
10026 if (!strcmp ("uniform", p
))
10027 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10028 else if (!strcmp ("untied", p
))
10029 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10032 if (!strcmp ("vector", p
))
10033 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10034 else if (!strcmp ("vector_length", p
))
10035 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10036 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10037 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10040 if (!strcmp ("wait", p
))
10041 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10042 else if (!strcmp ("worker", p
))
10043 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10048 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10049 c_parser_consume_token (parser
);
10054 /* Validate that a clause of the given type does not already exist. */
10057 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10062 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10063 if (OMP_CLAUSE_CODE (c
) == code
)
10065 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10066 error_at (loc
, "too many %qs clauses", name
);
10072 Parse wait clause or wait directive parameters. */
10075 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10077 vec
<tree
, va_gc
> *args
;
10080 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10083 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10085 if (args
->length () == 0)
10087 c_parser_error (parser
, "expected integer expression before ')'");
10088 release_tree_vector (args
);
10092 args_tree
= build_tree_list_vec (args
);
10094 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10096 tree targ
= TREE_VALUE (t
);
10098 if (targ
!= error_mark_node
)
10100 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10102 c_parser_error (parser
, "expression must be integral");
10103 targ
= error_mark_node
;
10107 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10109 OMP_CLAUSE_DECL (c
) = targ
;
10110 OMP_CLAUSE_CHAIN (c
) = list
;
10116 release_tree_vector (args
);
10117 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10121 /* OpenACC 2.0, OpenMP 2.5:
10124 variable-list , identifier
10126 If KIND is nonzero, create the appropriate node and install the
10127 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10128 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10130 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10131 return the list created. */
10134 c_parser_omp_variable_list (c_parser
*parser
,
10135 location_t clause_loc
,
10136 enum omp_clause_code kind
, tree list
)
10138 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10139 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10140 c_parser_error (parser
, "expected identifier");
10142 while (c_parser_next_token_is (parser
, CPP_NAME
)
10143 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10145 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10147 if (t
== NULL_TREE
)
10149 undeclared_variable (c_parser_peek_token (parser
)->location
,
10150 c_parser_peek_token (parser
)->value
);
10151 t
= error_mark_node
;
10154 c_parser_consume_token (parser
);
10156 if (t
== error_mark_node
)
10158 else if (kind
!= 0)
10162 case OMP_CLAUSE__CACHE_
:
10163 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10165 c_parser_error (parser
, "expected %<[%>");
10166 t
= error_mark_node
;
10169 /* FALL THROUGH. */
10170 case OMP_CLAUSE_MAP
:
10171 case OMP_CLAUSE_FROM
:
10172 case OMP_CLAUSE_TO
:
10173 case OMP_CLAUSE_DEPEND
:
10174 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10176 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10178 c_parser_consume_token (parser
);
10179 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10181 low_bound
= c_parser_expression (parser
).value
;
10182 mark_exp_read (low_bound
);
10184 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10185 length
= integer_one_node
;
10188 /* Look for `:'. */
10189 if (!c_parser_require (parser
, CPP_COLON
,
10192 t
= error_mark_node
;
10195 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10197 length
= c_parser_expression (parser
).value
;
10198 mark_exp_read (length
);
10201 /* Look for the closing `]'. */
10202 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10205 t
= error_mark_node
;
10209 if (kind
== OMP_CLAUSE__CACHE_
)
10211 if (TREE_CODE (low_bound
) != INTEGER_CST
10212 && !TREE_READONLY (low_bound
))
10214 error_at (clause_loc
,
10215 "%qD is not a constant", low_bound
);
10216 t
= error_mark_node
;
10219 if (TREE_CODE (length
) != INTEGER_CST
10220 && !TREE_READONLY (length
))
10222 error_at (clause_loc
,
10223 "%qD is not a constant", length
);
10224 t
= error_mark_node
;
10228 t
= tree_cons (low_bound
, length
, t
);
10235 if (t
!= error_mark_node
)
10237 tree u
= build_omp_clause (clause_loc
, kind
);
10238 OMP_CLAUSE_DECL (u
) = t
;
10239 OMP_CLAUSE_CHAIN (u
) = list
;
10244 list
= tree_cons (t
, NULL_TREE
, list
);
10246 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10249 c_parser_consume_token (parser
);
10255 /* Similarly, but expect leading and trailing parenthesis. This is a very
10256 common case for OpenACC and OpenMP clauses. */
10259 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10262 /* The clauses location. */
10263 location_t loc
= c_parser_peek_token (parser
)->location
;
10265 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10267 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10268 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10274 copy ( variable-list )
10275 copyin ( variable-list )
10276 copyout ( variable-list )
10277 create ( variable-list )
10278 delete ( variable-list )
10279 present ( variable-list )
10280 present_or_copy ( variable-list )
10281 pcopy ( variable-list )
10282 present_or_copyin ( variable-list )
10283 pcopyin ( variable-list )
10284 present_or_copyout ( variable-list )
10285 pcopyout ( variable-list )
10286 present_or_create ( variable-list )
10287 pcreate ( variable-list ) */
10290 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10293 enum gomp_map_kind kind
;
10296 case PRAGMA_OACC_CLAUSE_COPY
:
10297 kind
= GOMP_MAP_FORCE_TOFROM
;
10299 case PRAGMA_OACC_CLAUSE_COPYIN
:
10300 kind
= GOMP_MAP_FORCE_TO
;
10302 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10303 kind
= GOMP_MAP_FORCE_FROM
;
10305 case PRAGMA_OACC_CLAUSE_CREATE
:
10306 kind
= GOMP_MAP_FORCE_ALLOC
;
10308 case PRAGMA_OACC_CLAUSE_DELETE
:
10309 kind
= GOMP_MAP_FORCE_DEALLOC
;
10311 case PRAGMA_OACC_CLAUSE_DEVICE
:
10312 kind
= GOMP_MAP_FORCE_TO
;
10314 case PRAGMA_OACC_CLAUSE_HOST
:
10315 case PRAGMA_OACC_CLAUSE_SELF
:
10316 kind
= GOMP_MAP_FORCE_FROM
;
10318 case PRAGMA_OACC_CLAUSE_PRESENT
:
10319 kind
= GOMP_MAP_FORCE_PRESENT
;
10321 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10322 kind
= GOMP_MAP_TOFROM
;
10324 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10325 kind
= GOMP_MAP_TO
;
10327 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10328 kind
= GOMP_MAP_FROM
;
10330 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10331 kind
= GOMP_MAP_ALLOC
;
10334 gcc_unreachable ();
10337 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10339 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10340 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10346 deviceptr ( variable-list ) */
10349 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10351 location_t loc
= c_parser_peek_token (parser
)->location
;
10354 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10355 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10356 variable-list must only allow for pointer variables. */
10357 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10358 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10360 tree v
= TREE_PURPOSE (t
);
10362 /* FIXME diagnostics: Ideally we should keep individual
10363 locations for all the variables in the var list to make the
10364 following errors more precise. Perhaps
10365 c_parser_omp_var_list_parens() should construct a list of
10366 locations to go along with the var list. */
10368 if (TREE_CODE (v
) != VAR_DECL
)
10369 error_at (loc
, "%qD is not a variable", v
);
10370 else if (TREE_TYPE (v
) == error_mark_node
)
10372 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10373 error_at (loc
, "%qD is not a pointer variable", v
);
10375 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10376 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10377 OMP_CLAUSE_DECL (u
) = v
;
10378 OMP_CLAUSE_CHAIN (u
) = list
;
10385 /* OpenACC 2.0, OpenMP 3.0:
10386 collapse ( constant-expression ) */
10389 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10391 tree c
, num
= error_mark_node
;
10395 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10397 loc
= c_parser_peek_token (parser
)->location
;
10398 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10400 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10401 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10403 if (num
== error_mark_node
)
10405 mark_exp_read (num
);
10406 num
= c_fully_fold (num
, false, NULL
);
10407 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10408 || !tree_fits_shwi_p (num
)
10409 || (n
= tree_to_shwi (num
)) <= 0
10413 "collapse argument needs positive constant integer expression");
10416 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10417 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10418 OMP_CLAUSE_CHAIN (c
) = list
;
10423 copyin ( variable-list ) */
10426 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10428 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10432 copyprivate ( variable-list ) */
10435 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10437 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10441 default ( shared | none ) */
10444 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10446 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10447 location_t loc
= c_parser_peek_token (parser
)->location
;
10450 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10452 if (c_parser_next_token_is (parser
, CPP_NAME
))
10454 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10459 if (strcmp ("none", p
) != 0)
10461 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10465 if (strcmp ("shared", p
) != 0)
10467 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10474 c_parser_consume_token (parser
);
10479 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10481 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10483 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10486 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10487 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10488 OMP_CLAUSE_CHAIN (c
) = list
;
10489 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10495 firstprivate ( variable-list ) */
10498 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10500 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10504 final ( expression ) */
10507 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10509 location_t loc
= c_parser_peek_token (parser
)->location
;
10510 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10512 tree t
= c_parser_paren_condition (parser
);
10515 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10517 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10518 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10519 OMP_CLAUSE_CHAIN (c
) = list
;
10523 c_parser_error (parser
, "expected %<(%>");
10528 /* OpenACC, OpenMP 2.5:
10529 if ( expression ) */
10532 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10534 location_t loc
= c_parser_peek_token (parser
)->location
;
10535 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10537 tree t
= c_parser_paren_condition (parser
);
10540 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10542 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10543 OMP_CLAUSE_IF_EXPR (c
) = t
;
10544 OMP_CLAUSE_CHAIN (c
) = list
;
10548 c_parser_error (parser
, "expected %<(%>");
10554 lastprivate ( variable-list ) */
10557 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10559 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10566 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10570 /* FIXME: Should we allow duplicates? */
10571 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10573 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10574 OMP_CLAUSE_MERGEABLE
);
10575 OMP_CLAUSE_CHAIN (c
) = list
;
10584 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10587 location_t loc
= c_parser_peek_token (parser
)->location
;
10589 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10591 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10592 OMP_CLAUSE_CHAIN (c
) = list
;
10597 num_gangs ( expression ) */
10600 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
10602 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
10603 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10605 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10606 tree c
, t
= c_parser_expression (parser
).value
;
10608 t
= c_fully_fold (t
, false, NULL
);
10610 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10612 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10614 c_parser_error (parser
, "expected integer expression");
10618 /* Attempt to statically determine when the number isn't positive. */
10619 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10620 build_int_cst (TREE_TYPE (t
), 0));
10621 if (CAN_HAVE_LOCATION_P (c
))
10622 SET_EXPR_LOCATION (c
, expr_loc
);
10623 if (c
== boolean_true_node
)
10625 warning_at (expr_loc
, 0,
10626 "%<num_gangs%> value must be positive");
10627 t
= integer_one_node
;
10630 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
10632 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
10633 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
10634 OMP_CLAUSE_CHAIN (c
) = list
;
10642 num_threads ( expression ) */
10645 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10647 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10648 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10650 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10651 tree c
, t
= c_parser_expression (parser
).value
;
10653 t
= c_fully_fold (t
, false, NULL
);
10655 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10657 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10659 c_parser_error (parser
, "expected integer expression");
10663 /* Attempt to statically determine when the number isn't positive. */
10664 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10665 build_int_cst (TREE_TYPE (t
), 0));
10666 if (CAN_HAVE_LOCATION_P (c
))
10667 SET_EXPR_LOCATION (c
, expr_loc
);
10668 if (c
== boolean_true_node
)
10670 warning_at (expr_loc
, 0,
10671 "%<num_threads%> value must be positive");
10672 t
= integer_one_node
;
10675 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10677 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10678 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10679 OMP_CLAUSE_CHAIN (c
) = list
;
10687 num_workers ( expression ) */
10690 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
10692 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
10693 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10695 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10696 tree c
, t
= c_parser_expression (parser
).value
;
10698 t
= c_fully_fold (t
, false, NULL
);
10700 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10702 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10704 c_parser_error (parser
, "expected integer expression");
10708 /* Attempt to statically determine when the number isn't positive. */
10709 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10710 build_int_cst (TREE_TYPE (t
), 0));
10711 if (CAN_HAVE_LOCATION_P (c
))
10712 SET_EXPR_LOCATION (c
, expr_loc
);
10713 if (c
== boolean_true_node
)
10715 warning_at (expr_loc
, 0,
10716 "%<num_workers%> value must be positive");
10717 t
= integer_one_node
;
10720 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
10722 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
10723 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
10724 OMP_CLAUSE_CHAIN (c
) = list
;
10732 async [( int-expr )] */
10735 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
10738 location_t loc
= c_parser_peek_token (parser
)->location
;
10740 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
10742 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10744 c_parser_consume_token (parser
);
10746 t
= c_parser_expression (parser
).value
;
10747 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10748 c_parser_error (parser
, "expected integer expression");
10749 else if (t
== error_mark_node
10750 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10754 t
= c_fully_fold (t
, false, NULL
);
10756 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
10758 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
10759 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
10760 OMP_CLAUSE_CHAIN (c
) = list
;
10767 wait ( int-expr-list ) */
10770 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
10772 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10774 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
10775 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
10784 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10788 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10790 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10791 OMP_CLAUSE_ORDERED
);
10792 OMP_CLAUSE_CHAIN (c
) = list
;
10798 private ( variable-list ) */
10801 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10803 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10807 reduction ( reduction-operator : variable-list )
10809 reduction-operator:
10810 One of: + * - & ^ | && ||
10814 reduction-operator:
10815 One of: + * - & ^ | && || max min
10819 reduction-operator:
10820 One of: + * - & ^ | && ||
10824 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10826 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10827 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10829 enum tree_code code
= ERROR_MARK
;
10830 tree reduc_id
= NULL_TREE
;
10832 switch (c_parser_peek_token (parser
)->type
)
10844 code
= BIT_AND_EXPR
;
10847 code
= BIT_XOR_EXPR
;
10850 code
= BIT_IOR_EXPR
;
10853 code
= TRUTH_ANDIF_EXPR
;
10856 code
= TRUTH_ORIF_EXPR
;
10861 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10862 if (strcmp (p
, "min") == 0)
10867 if (strcmp (p
, "max") == 0)
10872 reduc_id
= c_parser_peek_token (parser
)->value
;
10876 c_parser_error (parser
,
10877 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10878 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10879 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10882 c_parser_consume_token (parser
);
10883 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10884 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10888 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10889 OMP_CLAUSE_REDUCTION
, list
);
10890 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10892 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10893 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10894 if (code
== ERROR_MARK
10895 || !(INTEGRAL_TYPE_P (type
)
10896 || TREE_CODE (type
) == REAL_TYPE
10897 || TREE_CODE (type
) == COMPLEX_TYPE
))
10898 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10899 = c_omp_reduction_lookup (reduc_id
,
10900 TYPE_MAIN_VARIANT (type
));
10905 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10911 schedule ( schedule-kind )
10912 schedule ( schedule-kind , expression )
10915 static | dynamic | guided | runtime | auto
10919 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10922 location_t loc
= c_parser_peek_token (parser
)->location
;
10924 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10927 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10929 if (c_parser_next_token_is (parser
, CPP_NAME
))
10931 tree kind
= c_parser_peek_token (parser
)->value
;
10932 const char *p
= IDENTIFIER_POINTER (kind
);
10937 if (strcmp ("dynamic", p
) != 0)
10939 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10943 if (strcmp ("guided", p
) != 0)
10945 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10949 if (strcmp ("runtime", p
) != 0)
10951 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10958 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10959 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10960 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10961 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10965 c_parser_consume_token (parser
);
10966 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10969 c_parser_consume_token (parser
);
10971 here
= c_parser_peek_token (parser
)->location
;
10972 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10974 t
= c_fully_fold (t
, false, NULL
);
10976 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10977 error_at (here
, "schedule %<runtime%> does not take "
10978 "a %<chunk_size%> parameter");
10979 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10981 "schedule %<auto%> does not take "
10982 "a %<chunk_size%> parameter");
10983 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10984 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10986 c_parser_error (parser
, "expected integer expression");
10988 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10991 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10992 "expected %<,%> or %<)%>");
10994 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10995 OMP_CLAUSE_CHAIN (c
) = list
;
10999 c_parser_error (parser
, "invalid schedule kind");
11000 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11005 shared ( variable-list ) */
11008 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
11010 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
11017 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11021 /* FIXME: Should we allow duplicates? */
11022 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
11024 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11025 OMP_CLAUSE_UNTIED
);
11026 OMP_CLAUSE_CHAIN (c
) = list
;
11032 vector_length ( expression ) */
11035 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
11037 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
11038 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11040 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11041 tree c
, t
= c_parser_expression (parser
).value
;
11043 t
= c_fully_fold (t
, false, NULL
);
11045 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11047 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11049 c_parser_error (parser
, "expected integer expression");
11053 /* Attempt to statically determine when the number isn't positive. */
11054 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11055 build_int_cst (TREE_TYPE (t
), 0));
11056 if (CAN_HAVE_LOCATION_P (c
))
11057 SET_EXPR_LOCATION (c
, expr_loc
);
11058 if (c
== boolean_true_node
)
11060 warning_at (expr_loc
, 0,
11061 "%<vector_length%> value must be positive");
11062 t
= integer_one_node
;
11065 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
11067 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
11068 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
11069 OMP_CLAUSE_CHAIN (c
) = list
;
11081 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
11082 enum omp_clause_code code
, tree list
)
11084 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11086 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11087 OMP_CLAUSE_CHAIN (c
) = list
;
11099 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
11100 enum omp_clause_code code
, tree list
)
11102 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11103 OMP_CLAUSE_CHAIN (c
) = list
;
11109 num_teams ( expression ) */
11112 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
11114 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
11115 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11117 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11118 tree c
, t
= c_parser_expression (parser
).value
;
11120 t
= c_fully_fold (t
, false, NULL
);
11122 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11124 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11126 c_parser_error (parser
, "expected integer expression");
11130 /* Attempt to statically determine when the number isn't positive. */
11131 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11132 build_int_cst (TREE_TYPE (t
), 0));
11133 if (CAN_HAVE_LOCATION_P (c
))
11134 SET_EXPR_LOCATION (c
, expr_loc
);
11135 if (c
== boolean_true_node
)
11137 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
11138 t
= integer_one_node
;
11141 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
11143 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
11144 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
11145 OMP_CLAUSE_CHAIN (c
) = list
;
11153 thread_limit ( expression ) */
11156 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
11158 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
11159 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11161 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11162 tree c
, t
= c_parser_expression (parser
).value
;
11164 t
= c_fully_fold (t
, false, NULL
);
11166 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11168 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11170 c_parser_error (parser
, "expected integer expression");
11174 /* Attempt to statically determine when the number isn't positive. */
11175 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11176 build_int_cst (TREE_TYPE (t
), 0));
11177 if (CAN_HAVE_LOCATION_P (c
))
11178 SET_EXPR_LOCATION (c
, expr_loc
);
11179 if (c
== boolean_true_node
)
11181 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
11182 t
= integer_one_node
;
11185 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
11188 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11189 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
11190 OMP_CLAUSE_CHAIN (c
) = list
;
11198 aligned ( variable-list )
11199 aligned ( variable-list : constant-expression ) */
11202 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
11204 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11207 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11210 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11211 OMP_CLAUSE_ALIGNED
, list
);
11213 if (c_parser_next_token_is (parser
, CPP_COLON
))
11215 c_parser_consume_token (parser
);
11216 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
11217 mark_exp_read (alignment
);
11218 alignment
= c_fully_fold (alignment
, false, NULL
);
11219 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
11220 && TREE_CODE (alignment
) != INTEGER_CST
11221 && tree_int_cst_sgn (alignment
) != 1)
11223 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
11224 "be positive constant integer expression");
11225 alignment
= NULL_TREE
;
11228 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11229 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
11232 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11237 linear ( variable-list )
11238 linear ( variable-list : expression ) */
11241 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
11243 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11246 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11249 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11250 OMP_CLAUSE_LINEAR
, list
);
11252 if (c_parser_next_token_is (parser
, CPP_COLON
))
11254 c_parser_consume_token (parser
);
11255 step
= c_parser_expression (parser
).value
;
11256 mark_exp_read (step
);
11257 step
= c_fully_fold (step
, false, NULL
);
11258 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
11260 sorry ("using parameters for %<linear%> step is not supported yet");
11261 step
= integer_one_node
;
11263 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
11265 error_at (clause_loc
, "%<linear%> clause step expression must "
11267 step
= integer_one_node
;
11272 step
= integer_one_node
;
11274 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11276 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11279 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11284 safelen ( constant-expression ) */
11287 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
11289 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11292 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11295 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11297 t
= c_fully_fold (t
, false, NULL
);
11298 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11299 && TREE_CODE (t
) != INTEGER_CST
11300 && tree_int_cst_sgn (t
) != 1)
11302 error_at (clause_loc
, "%<safelen%> clause expression must "
11303 "be positive constant integer expression");
11307 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11308 if (t
== NULL_TREE
|| t
== error_mark_node
)
11311 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
11313 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
11314 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
11315 OMP_CLAUSE_CHAIN (c
) = list
;
11320 simdlen ( constant-expression ) */
11323 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
11325 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11328 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11331 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11333 t
= c_fully_fold (t
, false, NULL
);
11334 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11335 && TREE_CODE (t
) != INTEGER_CST
11336 && tree_int_cst_sgn (t
) != 1)
11338 error_at (clause_loc
, "%<simdlen%> clause expression must "
11339 "be positive constant integer expression");
11343 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11344 if (t
== NULL_TREE
|| t
== error_mark_node
)
11347 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
11349 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
11350 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
11351 OMP_CLAUSE_CHAIN (c
) = list
;
11356 depend ( depend-kind: variable-list )
11359 in | out | inout */
11362 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
11364 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11365 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
11368 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11371 if (c_parser_next_token_is (parser
, CPP_NAME
))
11373 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11374 if (strcmp ("in", p
) == 0)
11375 kind
= OMP_CLAUSE_DEPEND_IN
;
11376 else if (strcmp ("inout", p
) == 0)
11377 kind
= OMP_CLAUSE_DEPEND_INOUT
;
11378 else if (strcmp ("out", p
) == 0)
11379 kind
= OMP_CLAUSE_DEPEND_OUT
;
11386 c_parser_consume_token (parser
);
11387 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11390 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11391 OMP_CLAUSE_DEPEND
, list
);
11393 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11394 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
11396 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11400 c_parser_error (parser
, "invalid depend kind");
11402 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11407 map ( map-kind: variable-list )
11408 map ( variable-list )
11411 alloc | to | from | tofrom */
11414 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
11416 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11417 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
11420 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11423 if (c_parser_next_token_is (parser
, CPP_NAME
)
11424 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11426 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11427 if (strcmp ("alloc", p
) == 0)
11428 kind
= GOMP_MAP_ALLOC
;
11429 else if (strcmp ("to", p
) == 0)
11430 kind
= GOMP_MAP_TO
;
11431 else if (strcmp ("from", p
) == 0)
11432 kind
= GOMP_MAP_FROM
;
11433 else if (strcmp ("tofrom", p
) == 0)
11434 kind
= GOMP_MAP_TOFROM
;
11437 c_parser_error (parser
, "invalid map kind");
11438 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11442 c_parser_consume_token (parser
);
11443 c_parser_consume_token (parser
);
11446 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
11448 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11449 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11451 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11456 device ( expression ) */
11459 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
11461 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11462 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11464 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11466 t
= c_fully_fold (t
, false, NULL
);
11468 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11470 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11472 c_parser_error (parser
, "expected integer expression");
11476 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
11478 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
11479 OMP_CLAUSE_DEVICE_ID (c
) = t
;
11480 OMP_CLAUSE_CHAIN (c
) = list
;
11488 dist_schedule ( static )
11489 dist_schedule ( static , expression ) */
11492 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
11494 tree c
, t
= NULL_TREE
;
11495 location_t loc
= c_parser_peek_token (parser
)->location
;
11497 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11500 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11502 c_parser_error (parser
, "invalid dist_schedule kind");
11503 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11508 c_parser_consume_token (parser
);
11509 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11511 c_parser_consume_token (parser
);
11513 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11515 t
= c_fully_fold (t
, false, NULL
);
11516 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11519 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11520 "expected %<,%> or %<)%>");
11522 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11523 if (t
== error_mark_node
)
11526 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
11527 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
11528 OMP_CLAUSE_CHAIN (c
) = list
;
11533 proc_bind ( proc-bind-kind )
11536 master | close | spread */
11539 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
11541 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11542 enum omp_clause_proc_bind_kind kind
;
11545 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11548 if (c_parser_next_token_is (parser
, CPP_NAME
))
11550 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11551 if (strcmp ("master", p
) == 0)
11552 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
11553 else if (strcmp ("close", p
) == 0)
11554 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
11555 else if (strcmp ("spread", p
) == 0)
11556 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
11563 c_parser_consume_token (parser
);
11564 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11565 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
11566 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
11567 OMP_CLAUSE_CHAIN (c
) = list
;
11571 c_parser_error (parser
, "invalid proc_bind kind");
11572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11577 to ( variable-list ) */
11580 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
11582 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
11586 from ( variable-list ) */
11589 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
11591 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
11595 uniform ( variable-list ) */
11598 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
11600 /* The clauses location. */
11601 location_t loc
= c_parser_peek_token (parser
)->location
;
11603 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11605 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
11607 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11612 /* Parse all OpenACC clauses. The set clauses allowed by the directive
11613 is a bitmask in MASK. Return the list of clauses found. */
11616 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11617 const char *where
, bool finish_p
= true)
11619 tree clauses
= NULL
;
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_OACC_CLAUSE_ASYNC
:
11638 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
11641 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
11642 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11643 c_name
= "collapse";
11645 case PRAGMA_OACC_CLAUSE_COPY
:
11646 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11649 case PRAGMA_OACC_CLAUSE_COPYIN
:
11650 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11653 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11654 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11655 c_name
= "copyout";
11657 case PRAGMA_OACC_CLAUSE_CREATE
:
11658 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11661 case PRAGMA_OACC_CLAUSE_DELETE
:
11662 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11665 case PRAGMA_OACC_CLAUSE_DEVICE
:
11666 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11669 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
11670 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
11671 c_name
= "deviceptr";
11673 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
11674 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11675 c_name
= "firstprivate";
11677 case PRAGMA_OACC_CLAUSE_HOST
:
11678 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11681 case PRAGMA_OACC_CLAUSE_IF
:
11682 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11685 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
11686 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
11687 c_name
= "num_gangs";
11689 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
11690 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
11691 c_name
= "num_workers";
11693 case PRAGMA_OACC_CLAUSE_PRESENT
:
11694 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11695 c_name
= "present";
11697 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
11698 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11699 c_name
= "present_or_copy";
11701 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
11702 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11703 c_name
= "present_or_copyin";
11705 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
11706 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11707 c_name
= "present_or_copyout";
11709 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
11710 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11711 c_name
= "present_or_create";
11713 case PRAGMA_OACC_CLAUSE_PRIVATE
:
11714 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11715 c_name
= "private";
11717 case PRAGMA_OACC_CLAUSE_REDUCTION
:
11718 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11719 c_name
= "reduction";
11721 case PRAGMA_OACC_CLAUSE_SELF
:
11722 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
11725 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
11726 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
11727 c_name
= "vector_length";
11729 case PRAGMA_OACC_CLAUSE_WAIT
:
11730 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
11734 c_parser_error (parser
, "expected %<#pragma acc%> clause");
11740 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11742 /* Remove the invalid clause(s) from the list to avoid
11743 confusing the rest of the compiler. */
11745 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11750 c_parser_skip_to_pragma_eol (parser
);
11753 return c_finish_omp_clauses (clauses
);
11758 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11759 is a bitmask in MASK. Return the list of clauses found. */
11762 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11763 const char *where
, bool finish_p
= true)
11765 tree clauses
= NULL
;
11766 bool first
= true, cilk_simd_fn
= false;
11768 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11771 pragma_omp_clause c_kind
;
11772 const char *c_name
;
11773 tree prev
= clauses
;
11775 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11776 c_parser_consume_token (parser
);
11778 here
= c_parser_peek_token (parser
)->location
;
11779 c_kind
= c_parser_omp_clause_name (parser
);
11783 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11784 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11785 c_name
= "collapse";
11787 case PRAGMA_OMP_CLAUSE_COPYIN
:
11788 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11791 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11792 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11793 c_name
= "copyprivate";
11795 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11796 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11797 c_name
= "default";
11799 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11800 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11801 c_name
= "firstprivate";
11803 case PRAGMA_OMP_CLAUSE_FINAL
:
11804 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11807 case PRAGMA_OMP_CLAUSE_IF
:
11808 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11811 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11812 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11813 c_name
= "lastprivate";
11815 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11816 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11817 c_name
= "mergeable";
11819 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11820 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11823 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11824 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11825 c_name
= "num_threads";
11827 case PRAGMA_OMP_CLAUSE_ORDERED
:
11828 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11829 c_name
= "ordered";
11831 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11832 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11833 c_name
= "private";
11835 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11836 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11837 c_name
= "reduction";
11839 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11840 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11841 c_name
= "schedule";
11843 case PRAGMA_OMP_CLAUSE_SHARED
:
11844 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11847 case PRAGMA_OMP_CLAUSE_UNTIED
:
11848 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11851 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11852 case PRAGMA_CILK_CLAUSE_MASK
:
11853 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11855 c_name
= "inbranch";
11857 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11858 case PRAGMA_CILK_CLAUSE_NOMASK
:
11859 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11861 c_name
= "notinbranch";
11863 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11865 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11867 c_name
= "parallel";
11871 error_at (here
, "%qs must be the first clause of %qs",
11876 case PRAGMA_OMP_CLAUSE_FOR
:
11878 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11882 goto clause_not_first
;
11884 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11886 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11888 c_name
= "sections";
11890 goto clause_not_first
;
11892 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11894 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11896 c_name
= "taskgroup";
11898 goto clause_not_first
;
11900 case PRAGMA_OMP_CLAUSE_TO
:
11901 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11904 case PRAGMA_OMP_CLAUSE_FROM
:
11905 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11908 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11909 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11910 c_name
= "uniform";
11912 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11913 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11914 c_name
= "num_teams";
11916 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11917 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11918 c_name
= "thread_limit";
11920 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11921 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11922 c_name
= "aligned";
11924 case PRAGMA_OMP_CLAUSE_LINEAR
:
11925 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11926 cilk_simd_fn
= true;
11927 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11930 case PRAGMA_OMP_CLAUSE_DEPEND
:
11931 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11934 case PRAGMA_OMP_CLAUSE_MAP
:
11935 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11938 case PRAGMA_OMP_CLAUSE_DEVICE
:
11939 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11942 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11943 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11944 c_name
= "dist_schedule";
11946 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11947 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11948 c_name
= "proc_bind";
11950 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11951 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11952 c_name
= "safelen";
11954 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11955 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11956 c_name
= "simdlen";
11958 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11959 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11960 c_name
= "simdlen";
11963 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11969 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11971 /* Remove the invalid clause(s) from the list to avoid
11972 confusing the rest of the compiler. */
11974 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11979 c_parser_skip_to_pragma_eol (parser
);
11982 return c_finish_omp_clauses (clauses
);
11987 /* OpenACC 2.0, OpenMP 2.5:
11991 In practice, we're also interested in adding the statement to an
11992 outer node. So it is convenient if we work around the fact that
11993 c_parser_statement calls add_stmt. */
11996 c_parser_omp_structured_block (c_parser
*parser
)
11998 tree stmt
= push_stmt_list ();
11999 c_parser_statement (parser
);
12000 return pop_stmt_list (stmt
);
12004 # pragma acc cache (variable-list) new-line
12006 LOC is the location of the #pragma token.
12010 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
12012 tree stmt
, clauses
;
12014 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
12015 clauses
= c_finish_omp_clauses (clauses
);
12017 c_parser_skip_to_pragma_eol (parser
);
12019 stmt
= make_node (OACC_CACHE
);
12020 TREE_TYPE (stmt
) = void_type_node
;
12021 OACC_CACHE_CLAUSES (stmt
) = clauses
;
12022 SET_EXPR_LOCATION (stmt
, loc
);
12029 # pragma acc data oacc-data-clause[optseq] new-line
12032 LOC is the location of the #pragma token.
12035 #define OACC_DATA_CLAUSE_MASK \
12036 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12037 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12038 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12039 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12040 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12041 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12042 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12043 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
12049 c_parser_oacc_data (location_t loc
, c_parser
*parser
)
12051 tree stmt
, clauses
, block
;
12053 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
12054 "#pragma acc data");
12056 block
= c_begin_omp_parallel ();
12057 add_stmt (c_parser_omp_structured_block (parser
));
12059 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
12065 # pragma acc kernels oacc-kernels-clause[optseq] new-line
12068 LOC is the location of the #pragma token.
12071 #define OACC_KERNELS_CLAUSE_MASK \
12072 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12075 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12076 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12077 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12078 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12079 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12080 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12081 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12082 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12083 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12084 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12087 c_parser_oacc_kernels (location_t loc
, c_parser
*parser
, char *p_name
)
12089 tree stmt
, clauses
= NULL_TREE
, block
;
12091 strcat (p_name
, " kernels");
12093 if (c_parser_next_token_is (parser
, CPP_NAME
))
12095 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12096 if (strcmp (p
, "loop") == 0)
12098 c_parser_consume_token (parser
);
12099 block
= c_begin_omp_parallel ();
12100 c_parser_oacc_loop (loc
, parser
, p_name
);
12101 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12102 OACC_KERNELS_COMBINED (stmt
) = 1;
12107 clauses
= c_parser_oacc_all_clauses (parser
, OACC_KERNELS_CLAUSE_MASK
,
12110 block
= c_begin_omp_parallel ();
12111 add_stmt (c_parser_omp_structured_block (parser
));
12113 stmt
= c_finish_oacc_kernels (loc
, clauses
, block
);
12119 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
12123 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
12126 LOC is the location of the #pragma token.
12129 #define OACC_ENTER_DATA_CLAUSE_MASK \
12130 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12131 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12132 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12133 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12134 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12135 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12136 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12138 #define OACC_EXIT_DATA_CLAUSE_MASK \
12139 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12140 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12141 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12142 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
12143 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12146 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
12148 location_t loc
= c_parser_peek_token (parser
)->location
;
12149 tree clauses
, stmt
;
12151 c_parser_consume_pragma (parser
);
12153 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12155 c_parser_error (parser
, enter
12156 ? "expected %<data%> in %<#pragma acc enter data%>"
12157 : "expected %<data%> in %<#pragma acc exit data%>");
12158 c_parser_skip_to_pragma_eol (parser
);
12162 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12163 if (strcmp (p
, "data") != 0)
12165 c_parser_error (parser
, "invalid pragma");
12166 c_parser_skip_to_pragma_eol (parser
);
12170 c_parser_consume_token (parser
);
12173 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
12174 "#pragma acc enter data");
12176 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
12177 "#pragma acc exit data");
12179 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12181 error_at (loc
, enter
12182 ? "%<#pragma acc enter data%> has no data movement clause"
12183 : "%<#pragma acc exit data%> has no data movement clause");
12187 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
12188 TREE_TYPE (stmt
) = void_type_node
;
12189 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
12190 SET_EXPR_LOCATION (stmt
, loc
);
12197 # pragma acc loop oacc-loop-clause[optseq] new-line
12200 LOC is the location of the #pragma token.
12203 #define OACC_LOOP_CLAUSE_MASK \
12204 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
12205 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) )
12208 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
)
12210 tree stmt
, clauses
, block
;
12212 strcat (p_name
, " loop");
12214 clauses
= c_parser_oacc_all_clauses (parser
, OACC_LOOP_CLAUSE_MASK
, p_name
);
12216 block
= c_begin_compound_stmt (true);
12217 stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
);
12218 block
= c_end_compound_stmt (loc
, block
, true);
12225 # pragma acc parallel oacc-parallel-clause[optseq] new-line
12228 LOC is the location of the #pragma token.
12231 #define OACC_PARALLEL_CLAUSE_MASK \
12232 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12233 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
12234 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
12235 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
12236 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
12237 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
12238 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12239 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
12240 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
12241 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
12242 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
12243 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
12244 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
12245 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
12246 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
12247 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
12248 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12251 c_parser_oacc_parallel (location_t loc
, c_parser
*parser
, char *p_name
)
12253 tree stmt
, clauses
= NULL_TREE
, block
;
12255 strcat (p_name
, " parallel");
12257 if (c_parser_next_token_is (parser
, CPP_NAME
))
12259 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12260 if (strcmp (p
, "loop") == 0)
12262 c_parser_consume_token (parser
);
12263 block
= c_begin_omp_parallel ();
12264 c_parser_oacc_loop (loc
, parser
, p_name
);
12265 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12266 OACC_PARALLEL_COMBINED (stmt
) = 1;
12271 clauses
= c_parser_oacc_all_clauses (parser
, OACC_PARALLEL_CLAUSE_MASK
,
12274 block
= c_begin_omp_parallel ();
12275 add_stmt (c_parser_omp_structured_block (parser
));
12277 stmt
= c_finish_oacc_parallel (loc
, clauses
, block
);
12283 # pragma acc update oacc-update-clause[optseq] new-line
12286 #define OACC_UPDATE_CLAUSE_MASK \
12287 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
12288 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
12289 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
12290 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
12291 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
12292 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
12295 c_parser_oacc_update (c_parser
*parser
)
12297 location_t loc
= c_parser_peek_token (parser
)->location
;
12299 c_parser_consume_pragma (parser
);
12301 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
12302 "#pragma acc update");
12303 if (find_omp_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
12306 "%<#pragma acc update%> must contain at least one "
12307 "%<device%> or %<host/self%> clause");
12314 tree stmt
= make_node (OACC_UPDATE
);
12315 TREE_TYPE (stmt
) = void_type_node
;
12316 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
12317 SET_EXPR_LOCATION (stmt
, loc
);
12322 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
12324 LOC is the location of the #pragma token.
12327 #define OACC_WAIT_CLAUSE_MASK \
12328 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
12331 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
12333 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
12335 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12336 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
12338 strcpy (p_name
, " wait");
12339 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
12340 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
12346 # pragma omp atomic new-line
12350 x binop= expr | x++ | ++x | x-- | --x
12352 +, *, -, /, &, ^, |, <<, >>
12354 where x is an lvalue expression with scalar type.
12357 # pragma omp atomic new-line
12360 # pragma omp atomic read new-line
12363 # pragma omp atomic write new-line
12366 # pragma omp atomic update new-line
12369 # pragma omp atomic capture new-line
12372 # pragma omp atomic capture new-line
12380 expression-stmt | x = x binop expr
12382 v = expression-stmt
12384 { v = x; update-stmt; } | { update-stmt; v = x; }
12388 expression-stmt | x = x binop expr | x = expr binop x
12392 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
12394 where x and v are lvalue expressions with scalar type.
12396 LOC is the location of the #pragma token. */
12399 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
12401 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
12402 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
12403 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
12404 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
12405 struct c_expr expr
;
12407 bool structured_block
= false;
12408 bool swapped
= false;
12409 bool seq_cst
= false;
12411 if (c_parser_next_token_is (parser
, CPP_NAME
))
12413 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12414 if (!strcmp (p
, "seq_cst"))
12417 c_parser_consume_token (parser
);
12418 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12419 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12420 c_parser_consume_token (parser
);
12423 if (c_parser_next_token_is (parser
, CPP_NAME
))
12425 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12427 if (!strcmp (p
, "read"))
12428 code
= OMP_ATOMIC_READ
;
12429 else if (!strcmp (p
, "write"))
12431 else if (!strcmp (p
, "update"))
12433 else if (!strcmp (p
, "capture"))
12434 code
= OMP_ATOMIC_CAPTURE_NEW
;
12438 c_parser_consume_token (parser
);
12442 if (c_parser_next_token_is (parser
, CPP_COMMA
)
12443 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12444 c_parser_consume_token (parser
);
12446 if (c_parser_next_token_is (parser
, CPP_NAME
))
12449 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12450 if (!strcmp (p
, "seq_cst"))
12453 c_parser_consume_token (parser
);
12457 c_parser_skip_to_pragma_eol (parser
);
12461 case OMP_ATOMIC_READ
:
12462 case NOP_EXPR
: /* atomic write */
12463 v
= c_parser_unary_expression (parser
).value
;
12464 v
= c_fully_fold (v
, false, NULL
);
12465 if (v
== error_mark_node
)
12467 loc
= c_parser_peek_token (parser
)->location
;
12468 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12470 if (code
== NOP_EXPR
)
12471 lhs
= c_parser_expression (parser
).value
;
12473 lhs
= c_parser_unary_expression (parser
).value
;
12474 lhs
= c_fully_fold (lhs
, false, NULL
);
12475 if (lhs
== error_mark_node
)
12477 if (code
== NOP_EXPR
)
12479 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
12487 case OMP_ATOMIC_CAPTURE_NEW
:
12488 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12490 c_parser_consume_token (parser
);
12491 structured_block
= true;
12495 v
= c_parser_unary_expression (parser
).value
;
12496 v
= c_fully_fold (v
, false, NULL
);
12497 if (v
== error_mark_node
)
12499 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12507 /* For structured_block case we don't know yet whether
12508 old or new x should be captured. */
12510 eloc
= c_parser_peek_token (parser
)->location
;
12511 expr
= c_parser_unary_expression (parser
);
12513 expr
= default_function_array_conversion (eloc
, expr
);
12514 unfolded_lhs
= expr
.value
;
12515 lhs
= c_fully_fold (lhs
, false, NULL
);
12517 switch (TREE_CODE (lhs
))
12521 c_parser_skip_to_end_of_block_or_statement (parser
);
12522 if (structured_block
)
12524 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12525 c_parser_consume_token (parser
);
12526 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
12528 c_parser_skip_to_end_of_block_or_statement (parser
);
12529 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12530 c_parser_consume_token (parser
);
12535 case POSTINCREMENT_EXPR
:
12536 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12537 code
= OMP_ATOMIC_CAPTURE_OLD
;
12539 case PREINCREMENT_EXPR
:
12540 lhs
= TREE_OPERAND (lhs
, 0);
12541 unfolded_lhs
= NULL_TREE
;
12542 opcode
= PLUS_EXPR
;
12543 rhs
= integer_one_node
;
12546 case POSTDECREMENT_EXPR
:
12547 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
12548 code
= OMP_ATOMIC_CAPTURE_OLD
;
12550 case PREDECREMENT_EXPR
:
12551 lhs
= TREE_OPERAND (lhs
, 0);
12552 unfolded_lhs
= NULL_TREE
;
12553 opcode
= MINUS_EXPR
;
12554 rhs
= integer_one_node
;
12557 case COMPOUND_EXPR
:
12558 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
12559 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
12560 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
12561 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
12562 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
12563 (TREE_OPERAND (lhs
, 1), 0), 0)))
12565 /* Undo effects of boolean_increment for post {in,de}crement. */
12566 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
12569 if (TREE_CODE (lhs
) == MODIFY_EXPR
12570 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
12572 /* Undo effects of boolean_increment. */
12573 if (integer_onep (TREE_OPERAND (lhs
, 1)))
12575 /* This is pre or post increment. */
12576 rhs
= TREE_OPERAND (lhs
, 1);
12577 lhs
= TREE_OPERAND (lhs
, 0);
12578 unfolded_lhs
= NULL_TREE
;
12580 if (code
== OMP_ATOMIC_CAPTURE_NEW
12581 && !structured_block
12582 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12583 code
= OMP_ATOMIC_CAPTURE_OLD
;
12586 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
12587 && TREE_OPERAND (lhs
, 0)
12588 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
12590 /* This is pre or post decrement. */
12591 rhs
= TREE_OPERAND (lhs
, 1);
12592 lhs
= TREE_OPERAND (lhs
, 0);
12593 unfolded_lhs
= NULL_TREE
;
12595 if (code
== OMP_ATOMIC_CAPTURE_NEW
12596 && !structured_block
12597 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
12598 code
= OMP_ATOMIC_CAPTURE_OLD
;
12604 switch (c_parser_peek_token (parser
)->type
)
12607 opcode
= MULT_EXPR
;
12610 opcode
= TRUNC_DIV_EXPR
;
12613 opcode
= PLUS_EXPR
;
12616 opcode
= MINUS_EXPR
;
12618 case CPP_LSHIFT_EQ
:
12619 opcode
= LSHIFT_EXPR
;
12621 case CPP_RSHIFT_EQ
:
12622 opcode
= RSHIFT_EXPR
;
12625 opcode
= BIT_AND_EXPR
;
12628 opcode
= BIT_IOR_EXPR
;
12631 opcode
= BIT_XOR_EXPR
;
12634 c_parser_consume_token (parser
);
12635 eloc
= c_parser_peek_token (parser
)->location
;
12636 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
12638 switch (TREE_CODE (rhs1
))
12641 case TRUNC_DIV_EXPR
:
12650 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
12652 opcode
= TREE_CODE (rhs1
);
12653 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12654 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12657 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
12659 opcode
= TREE_CODE (rhs1
);
12660 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
12661 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
12662 swapped
= !commutative_tree_code (opcode
);
12671 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
12673 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12675 code
= OMP_ATOMIC_CAPTURE_OLD
;
12678 expr
= default_function_array_read_conversion (eloc
, expr
);
12679 unfolded_lhs1
= expr
.value
;
12680 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
12682 c_parser_consume_token (parser
);
12685 if (structured_block
)
12688 expr
= default_function_array_read_conversion (eloc
, expr
);
12689 rhs
= c_fully_fold (expr
.value
, false, NULL
);
12694 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
12697 c_parser_error (parser
,
12698 "invalid operator for %<#pragma omp atomic%>");
12702 /* Arrange to pass the location of the assignment operator to
12703 c_finish_omp_atomic. */
12704 loc
= c_parser_peek_token (parser
)->location
;
12705 c_parser_consume_token (parser
);
12706 eloc
= c_parser_peek_token (parser
)->location
;
12707 expr
= c_parser_expression (parser
);
12708 expr
= default_function_array_read_conversion (eloc
, expr
);
12710 rhs
= c_fully_fold (rhs
, false, NULL
);
12714 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12716 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
12718 v
= c_parser_unary_expression (parser
).value
;
12719 v
= c_fully_fold (v
, false, NULL
);
12720 if (v
== error_mark_node
)
12722 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12724 eloc
= c_parser_peek_token (parser
)->location
;
12725 expr
= c_parser_unary_expression (parser
);
12727 expr
= default_function_array_read_conversion (eloc
, expr
);
12728 unfolded_lhs1
= expr
.value
;
12729 lhs1
= c_fully_fold (lhs1
, false, NULL
);
12730 if (lhs1
== error_mark_node
)
12733 if (structured_block
)
12735 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12736 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
12739 if (unfolded_lhs
&& unfolded_lhs1
12740 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
12742 error ("%<#pragma omp atomic capture%> uses two different "
12743 "expressions for memory");
12744 stmt
= error_mark_node
;
12747 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
12749 if (stmt
!= error_mark_node
)
12752 if (!structured_block
)
12753 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12758 # pragma omp barrier new-line
12762 c_parser_omp_barrier (c_parser
*parser
)
12764 location_t loc
= c_parser_peek_token (parser
)->location
;
12765 c_parser_consume_pragma (parser
);
12766 c_parser_skip_to_pragma_eol (parser
);
12768 c_finish_omp_barrier (loc
);
12772 # pragma omp critical [(name)] new-line
12775 LOC is the location of the #pragma itself. */
12778 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
12780 tree stmt
, name
= NULL
;
12782 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12784 c_parser_consume_token (parser
);
12785 if (c_parser_next_token_is (parser
, CPP_NAME
))
12787 name
= c_parser_peek_token (parser
)->value
;
12788 c_parser_consume_token (parser
);
12789 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12792 c_parser_error (parser
, "expected identifier");
12794 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12795 c_parser_error (parser
, "expected %<(%> or end of line");
12796 c_parser_skip_to_pragma_eol (parser
);
12798 stmt
= c_parser_omp_structured_block (parser
);
12799 return c_finish_omp_critical (loc
, stmt
, name
);
12803 # pragma omp flush flush-vars[opt] new-line
12806 ( variable-list ) */
12809 c_parser_omp_flush (c_parser
*parser
)
12811 location_t loc
= c_parser_peek_token (parser
)->location
;
12812 c_parser_consume_pragma (parser
);
12813 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12814 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12815 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12816 c_parser_error (parser
, "expected %<(%> or end of line");
12817 c_parser_skip_to_pragma_eol (parser
);
12819 c_finish_omp_flush (loc
);
12822 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
12823 The real trick here is to determine the loop control variable early
12824 so that we can push a new decl if necessary to make it private.
12825 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
12829 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
12830 tree clauses
, tree
*cclauses
)
12832 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
12833 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
12834 bool fail
= false, open_brace_parsed
= false;
12835 int i
, collapse
= 1, nbraces
= 0;
12836 location_t for_loc
;
12837 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
12839 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
12840 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
12841 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
12843 gcc_assert (collapse
>= 1);
12845 declv
= make_tree_vec (collapse
);
12846 initv
= make_tree_vec (collapse
);
12847 condv
= make_tree_vec (collapse
);
12848 incrv
= make_tree_vec (collapse
);
12850 if (code
!= CILK_FOR
12851 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
12853 c_parser_error (parser
, "for statement expected");
12856 if (code
== CILK_FOR
12857 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
12859 c_parser_error (parser
, "_Cilk_for statement expected");
12862 for_loc
= c_parser_peek_token (parser
)->location
;
12863 c_parser_consume_token (parser
);
12865 for (i
= 0; i
< collapse
; i
++)
12867 int bracecount
= 0;
12869 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12872 /* Parse the initialization declaration or expression. */
12873 if (c_parser_next_tokens_start_declaration (parser
))
12876 vec_safe_push (for_block
, c_begin_compound_stmt (true));
12877 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12879 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
12882 if (DECL_INITIAL (decl
) == error_mark_node
)
12883 decl
= error_mark_node
;
12886 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12887 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
12889 struct c_expr decl_exp
;
12890 struct c_expr init_exp
;
12891 location_t init_loc
;
12893 decl_exp
= c_parser_postfix_expression (parser
);
12894 decl
= decl_exp
.value
;
12896 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
12898 init_loc
= c_parser_peek_token (parser
)->location
;
12899 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
12900 init_exp
= default_function_array_read_conversion (init_loc
,
12902 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
12903 NOP_EXPR
, init_loc
, init_exp
.value
,
12904 init_exp
.original_type
);
12905 init
= c_process_expr_stmt (init_loc
, init
);
12907 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12912 c_parser_error (parser
,
12913 "expected iteration declaration or initialization");
12914 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12920 /* Parse the loop condition. */
12922 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
12924 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
12925 struct c_expr cond_expr
12926 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
12928 cond
= cond_expr
.value
;
12929 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
12930 cond
= c_fully_fold (cond
, false, NULL
);
12931 switch (cond_expr
.original_code
)
12939 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
12943 /* Can't be cond = error_mark_node, because we want to preserve
12944 the location until c_finish_omp_for. */
12945 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
12948 protected_set_expr_location (cond
, cond_loc
);
12950 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12952 /* Parse the increment expression. */
12954 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
12956 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
12958 incr
= c_process_expr_stmt (incr_loc
,
12959 c_parser_expression (parser
).value
);
12961 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12963 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
12967 TREE_VEC_ELT (declv
, i
) = decl
;
12968 TREE_VEC_ELT (initv
, i
) = init
;
12969 TREE_VEC_ELT (condv
, i
) = cond
;
12970 TREE_VEC_ELT (incrv
, i
) = incr
;
12974 if (i
== collapse
- 1)
12977 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12978 in between the collapsed for loops to be still considered perfectly
12979 nested. Hopefully the final version clarifies this.
12980 For now handle (multiple) {'s and empty statements. */
12983 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12985 c_parser_consume_token (parser
);
12988 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12990 c_parser_consume_token (parser
);
12993 else if (bracecount
12994 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12995 c_parser_consume_token (parser
);
12998 c_parser_error (parser
, "not enough perfectly nested loops");
13001 open_brace_parsed
= true;
13011 nbraces
+= bracecount
;
13014 save_break
= c_break_label
;
13015 if (code
== CILK_SIMD
)
13016 c_break_label
= build_int_cst (size_type_node
, 2);
13018 c_break_label
= size_one_node
;
13019 save_cont
= c_cont_label
;
13020 c_cont_label
= NULL_TREE
;
13021 body
= push_stmt_list ();
13023 if (open_brace_parsed
)
13025 location_t here
= c_parser_peek_token (parser
)->location
;
13026 stmt
= c_begin_compound_stmt (true);
13027 c_parser_compound_statement_nostart (parser
);
13028 add_stmt (c_end_compound_stmt (here
, stmt
, true));
13031 add_stmt (c_parser_c99_block_statement (parser
));
13034 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
13035 SET_EXPR_LOCATION (t
, loc
);
13039 body
= pop_stmt_list (body
);
13040 c_break_label
= save_break
;
13041 c_cont_label
= save_cont
;
13045 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13047 c_parser_consume_token (parser
);
13050 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
13051 c_parser_consume_token (parser
);
13054 c_parser_error (parser
, "collapsed loops not perfectly nested");
13057 location_t here
= c_parser_peek_token (parser
)->location
;
13058 stmt
= c_begin_compound_stmt (true);
13060 c_parser_compound_statement_nostart (parser
);
13061 body
= c_end_compound_stmt (here
, stmt
, true);
13068 /* Only bother calling c_finish_omp_for if we haven't already generated
13069 an error from the initialization parsing. */
13072 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
13073 incrv
, body
, NULL
);
13076 if (cclauses
!= NULL
13077 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
13080 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
13081 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
13082 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
13083 c
= &OMP_CLAUSE_CHAIN (*c
);
13086 for (i
= 0; i
< collapse
; i
++)
13087 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
13090 c
= &OMP_CLAUSE_CHAIN (*c
);
13091 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
13094 "iteration variable %qD should not be firstprivate",
13095 OMP_CLAUSE_DECL (*c
));
13096 *c
= OMP_CLAUSE_CHAIN (*c
);
13100 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
13102 *c
= OMP_CLAUSE_CHAIN (*c
);
13103 if (code
== OMP_SIMD
)
13105 OMP_CLAUSE_CHAIN (l
)
13106 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13107 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
13111 OMP_CLAUSE_CHAIN (l
) = clauses
;
13117 OMP_FOR_CLAUSES (stmt
) = clauses
;
13122 while (!for_block
->is_empty ())
13124 /* FIXME diagnostics: LOC below should be the actual location of
13125 this particular for block. We need to build a list of
13126 locations to go along with FOR_BLOCK. */
13127 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
13130 release_tree_vector (for_block
);
13134 /* Helper function for OpenMP parsing, split clauses and call
13135 finish_omp_clauses on each of the set of clauses afterwards. */
13138 omp_split_clauses (location_t loc
, enum tree_code code
,
13139 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
13142 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
13143 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
13145 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
13149 #pragma omp simd simd-clause[optseq] new-line
13152 LOC is the location of the #pragma token.
13155 #define OMP_SIMD_CLAUSE_MASK \
13156 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
13157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13158 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13159 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13160 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13161 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13162 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13165 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
13166 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13168 tree block
, clauses
, ret
;
13170 strcat (p_name
, " simd");
13171 mask
|= OMP_SIMD_CLAUSE_MASK
;
13172 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
13174 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13177 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
13178 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
13181 block
= c_begin_compound_stmt (true);
13182 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
13183 block
= c_end_compound_stmt (loc
, block
, true);
13190 #pragma omp for for-clause[optseq] new-line
13194 #pragma omp for simd for-simd-clause[optseq] new-line
13197 LOC is the location of the #pragma token.
13200 #define OMP_FOR_CLAUSE_MASK \
13201 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13202 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13203 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13204 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13205 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
13206 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
13207 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
13208 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13211 c_parser_omp_for (location_t loc
, c_parser
*parser
,
13212 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13214 tree block
, clauses
, ret
;
13216 strcat (p_name
, " for");
13217 mask
|= OMP_FOR_CLAUSE_MASK
;
13219 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13221 if (c_parser_next_token_is (parser
, CPP_NAME
))
13223 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13225 if (strcmp (p
, "simd") == 0)
13227 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13228 if (cclauses
== NULL
)
13229 cclauses
= cclauses_buf
;
13231 c_parser_consume_token (parser
);
13232 if (!flag_openmp
) /* flag_openmp_simd */
13233 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13234 block
= c_begin_compound_stmt (true);
13235 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13236 block
= c_end_compound_stmt (loc
, block
, true);
13237 if (ret
== NULL_TREE
)
13239 ret
= make_node (OMP_FOR
);
13240 TREE_TYPE (ret
) = void_type_node
;
13241 OMP_FOR_BODY (ret
) = block
;
13242 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13243 SET_EXPR_LOCATION (ret
, loc
);
13248 if (!flag_openmp
) /* flag_openmp_simd */
13250 c_parser_skip_to_pragma_eol (parser
, false);
13254 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13257 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
13258 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
13261 block
= c_begin_compound_stmt (true);
13262 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
13263 block
= c_end_compound_stmt (loc
, block
, true);
13270 # pragma omp master new-line
13273 LOC is the location of the #pragma token.
13277 c_parser_omp_master (location_t loc
, c_parser
*parser
)
13279 c_parser_skip_to_pragma_eol (parser
);
13280 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
13284 # pragma omp ordered new-line
13287 LOC is the location of the #pragma itself.
13291 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
13293 c_parser_skip_to_pragma_eol (parser
);
13294 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
13300 { section-sequence }
13303 section-directive[opt] structured-block
13304 section-sequence section-directive structured-block
13306 SECTIONS_LOC is the location of the #pragma omp sections. */
13309 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
13311 tree stmt
, substmt
;
13312 bool error_suppress
= false;
13315 loc
= c_parser_peek_token (parser
)->location
;
13316 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
13318 /* Avoid skipping until the end of the block. */
13319 parser
->error
= false;
13323 stmt
= push_stmt_list ();
13325 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
13327 substmt
= c_parser_omp_structured_block (parser
);
13328 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13329 SET_EXPR_LOCATION (substmt
, loc
);
13330 add_stmt (substmt
);
13335 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
13337 if (c_parser_next_token_is (parser
, CPP_EOF
))
13340 loc
= c_parser_peek_token (parser
)->location
;
13341 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
13343 c_parser_consume_pragma (parser
);
13344 c_parser_skip_to_pragma_eol (parser
);
13345 error_suppress
= false;
13347 else if (!error_suppress
)
13349 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
13350 error_suppress
= true;
13353 substmt
= c_parser_omp_structured_block (parser
);
13354 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
13355 SET_EXPR_LOCATION (substmt
, loc
);
13356 add_stmt (substmt
);
13358 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
13359 "expected %<#pragma omp section%> or %<}%>");
13361 substmt
= pop_stmt_list (stmt
);
13363 stmt
= make_node (OMP_SECTIONS
);
13364 SET_EXPR_LOCATION (stmt
, sections_loc
);
13365 TREE_TYPE (stmt
) = void_type_node
;
13366 OMP_SECTIONS_BODY (stmt
) = substmt
;
13368 return add_stmt (stmt
);
13372 # pragma omp sections sections-clause[optseq] newline
13375 LOC is the location of the #pragma token.
13378 #define OMP_SECTIONS_CLAUSE_MASK \
13379 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13380 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13381 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
13382 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13383 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13386 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
13387 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13389 tree block
, clauses
, ret
;
13391 strcat (p_name
, " sections");
13392 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
13394 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
13396 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13399 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
13400 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
13403 block
= c_begin_compound_stmt (true);
13404 ret
= c_parser_omp_sections_scope (loc
, parser
);
13406 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
13407 block
= c_end_compound_stmt (loc
, block
, true);
13414 # pragma omp parallel parallel-clause[optseq] new-line
13416 # pragma omp parallel for parallel-for-clause[optseq] new-line
13418 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
13422 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
13425 LOC is the location of the #pragma token.
13428 #define OMP_PARALLEL_CLAUSE_MASK \
13429 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13430 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13431 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13432 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13433 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13434 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
13435 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13436 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
13437 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
13440 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
13441 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13443 tree stmt
, clauses
, block
;
13445 strcat (p_name
, " parallel");
13446 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
13448 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
13450 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13451 if (cclauses
== NULL
)
13452 cclauses
= cclauses_buf
;
13454 c_parser_consume_token (parser
);
13455 if (!flag_openmp
) /* flag_openmp_simd */
13456 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13457 block
= c_begin_omp_parallel ();
13458 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
13460 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13462 if (ret
== NULL_TREE
)
13464 OMP_PARALLEL_COMBINED (stmt
) = 1;
13469 error_at (loc
, "expected %<for%> after %qs", p_name
);
13470 c_parser_skip_to_pragma_eol (parser
);
13473 else if (!flag_openmp
) /* flag_openmp_simd */
13475 c_parser_skip_to_pragma_eol (parser
, false);
13478 else if (c_parser_next_token_is (parser
, CPP_NAME
))
13480 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13481 if (strcmp (p
, "sections") == 0)
13483 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13484 if (cclauses
== NULL
)
13485 cclauses
= cclauses_buf
;
13487 c_parser_consume_token (parser
);
13488 block
= c_begin_omp_parallel ();
13489 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
13490 stmt
= c_finish_omp_parallel (loc
,
13491 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
13493 OMP_PARALLEL_COMBINED (stmt
) = 1;
13498 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13500 block
= c_begin_omp_parallel ();
13501 c_parser_statement (parser
);
13502 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
13508 # pragma omp single single-clause[optseq] new-line
13511 LOC is the location of the #pragma.
13514 #define OMP_SINGLE_CLAUSE_MASK \
13515 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
13518 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
13521 c_parser_omp_single (location_t loc
, c_parser
*parser
)
13523 tree stmt
= make_node (OMP_SINGLE
);
13524 SET_EXPR_LOCATION (stmt
, loc
);
13525 TREE_TYPE (stmt
) = void_type_node
;
13527 OMP_SINGLE_CLAUSES (stmt
)
13528 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
13529 "#pragma omp single");
13530 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13532 return add_stmt (stmt
);
13536 # pragma omp task task-clause[optseq] new-line
13538 LOC is the location of the #pragma.
13541 #define OMP_TASK_CLAUSE_MASK \
13542 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
13543 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
13544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
13545 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13546 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13547 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13548 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
13549 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
13550 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
13553 c_parser_omp_task (location_t loc
, c_parser
*parser
)
13555 tree clauses
, block
;
13557 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
13558 "#pragma omp task");
13560 block
= c_begin_omp_task ();
13561 c_parser_statement (parser
);
13562 return c_finish_omp_task (loc
, clauses
, block
);
13566 # pragma omp taskwait new-line
13570 c_parser_omp_taskwait (c_parser
*parser
)
13572 location_t loc
= c_parser_peek_token (parser
)->location
;
13573 c_parser_consume_pragma (parser
);
13574 c_parser_skip_to_pragma_eol (parser
);
13576 c_finish_omp_taskwait (loc
);
13580 # pragma omp taskyield new-line
13584 c_parser_omp_taskyield (c_parser
*parser
)
13586 location_t loc
= c_parser_peek_token (parser
)->location
;
13587 c_parser_consume_pragma (parser
);
13588 c_parser_skip_to_pragma_eol (parser
);
13590 c_finish_omp_taskyield (loc
);
13594 # pragma omp taskgroup new-line
13598 c_parser_omp_taskgroup (c_parser
*parser
)
13600 location_t loc
= c_parser_peek_token (parser
)->location
;
13601 c_parser_skip_to_pragma_eol (parser
);
13602 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
13606 # pragma omp cancel cancel-clause[optseq] new-line
13608 LOC is the location of the #pragma.
13611 #define OMP_CANCEL_CLAUSE_MASK \
13612 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
13616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13619 c_parser_omp_cancel (c_parser
*parser
)
13621 location_t loc
= c_parser_peek_token (parser
)->location
;
13623 c_parser_consume_pragma (parser
);
13624 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
13625 "#pragma omp cancel");
13627 c_finish_omp_cancel (loc
, clauses
);
13631 # pragma omp cancellation point cancelpt-clause[optseq] new-line
13633 LOC is the location of the #pragma.
13636 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
13637 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
13638 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
13639 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
13640 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
13643 c_parser_omp_cancellation_point (c_parser
*parser
)
13645 location_t loc
= c_parser_peek_token (parser
)->location
;
13647 bool point_seen
= false;
13649 c_parser_consume_pragma (parser
);
13650 if (c_parser_next_token_is (parser
, CPP_NAME
))
13652 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13653 if (strcmp (p
, "point") == 0)
13655 c_parser_consume_token (parser
);
13661 c_parser_error (parser
, "expected %<point%>");
13662 c_parser_skip_to_pragma_eol (parser
);
13667 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
13668 "#pragma omp cancellation point");
13670 c_finish_omp_cancellation_point (loc
, clauses
);
13674 #pragma omp distribute distribute-clause[optseq] new-line
13677 #define OMP_DISTRIBUTE_CLAUSE_MASK \
13678 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13679 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13680 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
13681 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
13684 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
13685 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13687 tree clauses
, block
, ret
;
13689 strcat (p_name
, " distribute");
13690 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
13692 if (c_parser_next_token_is (parser
, CPP_NAME
))
13694 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13696 bool parallel
= false;
13698 if (strcmp (p
, "simd") == 0)
13701 parallel
= strcmp (p
, "parallel") == 0;
13702 if (parallel
|| simd
)
13704 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13705 if (cclauses
== NULL
)
13706 cclauses
= cclauses_buf
;
13707 c_parser_consume_token (parser
);
13708 if (!flag_openmp
) /* flag_openmp_simd */
13711 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13713 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
13716 block
= c_begin_compound_stmt (true);
13718 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13720 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
13721 block
= c_end_compound_stmt (loc
, block
, true);
13724 ret
= make_node (OMP_DISTRIBUTE
);
13725 TREE_TYPE (ret
) = void_type_node
;
13726 OMP_FOR_BODY (ret
) = block
;
13727 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13728 SET_EXPR_LOCATION (ret
, loc
);
13733 if (!flag_openmp
) /* flag_openmp_simd */
13735 c_parser_skip_to_pragma_eol (parser
, false);
13739 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13742 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
13743 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13746 block
= c_begin_compound_stmt (true);
13747 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
13748 block
= c_end_compound_stmt (loc
, block
, true);
13755 # pragma omp teams teams-clause[optseq] new-line
13756 structured-block */
13758 #define OMP_TEAMS_CLAUSE_MASK \
13759 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13762 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13764 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13765 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13768 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
13769 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13771 tree clauses
, block
, ret
;
13773 strcat (p_name
, " teams");
13774 mask
|= OMP_TEAMS_CLAUSE_MASK
;
13776 if (c_parser_next_token_is (parser
, CPP_NAME
))
13778 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13779 if (strcmp (p
, "distribute") == 0)
13781 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13782 if (cclauses
== NULL
)
13783 cclauses
= cclauses_buf
;
13785 c_parser_consume_token (parser
);
13786 if (!flag_openmp
) /* flag_openmp_simd */
13787 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13788 block
= c_begin_compound_stmt (true);
13789 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13790 block
= c_end_compound_stmt (loc
, block
, true);
13793 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13794 ret
= make_node (OMP_TEAMS
);
13795 TREE_TYPE (ret
) = void_type_node
;
13796 OMP_TEAMS_CLAUSES (ret
) = clauses
;
13797 OMP_TEAMS_BODY (ret
) = block
;
13798 OMP_TEAMS_COMBINED (ret
) = 1;
13799 return add_stmt (ret
);
13802 if (!flag_openmp
) /* flag_openmp_simd */
13804 c_parser_skip_to_pragma_eol (parser
, false);
13808 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13811 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
13812 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13815 tree stmt
= make_node (OMP_TEAMS
);
13816 TREE_TYPE (stmt
) = void_type_node
;
13817 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
13818 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13820 return add_stmt (stmt
);
13824 # pragma omp target data target-data-clause[optseq] new-line
13825 structured-block */
13827 #define OMP_TARGET_DATA_CLAUSE_MASK \
13828 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13829 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13830 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13833 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
13835 tree stmt
= make_node (OMP_TARGET_DATA
);
13836 TREE_TYPE (stmt
) = void_type_node
;
13838 OMP_TARGET_DATA_CLAUSES (stmt
)
13839 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
13840 "#pragma omp target data");
13841 keep_next_level ();
13842 tree block
= c_begin_compound_stmt (true);
13843 add_stmt (c_parser_omp_structured_block (parser
));
13844 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13846 SET_EXPR_LOCATION (stmt
, loc
);
13847 return add_stmt (stmt
);
13851 # pragma omp target update target-update-clause[optseq] new-line */
13853 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13854 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13855 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13856 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13857 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13860 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
13861 enum pragma_context context
)
13863 if (context
== pragma_stmt
)
13866 "%<#pragma omp target update%> may only be "
13867 "used in compound statements");
13868 c_parser_skip_to_pragma_eol (parser
);
13873 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
13874 "#pragma omp target update");
13875 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
13876 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
13879 "%<#pragma omp target update%> must contain at least one "
13880 "%<from%> or %<to%> clauses");
13884 tree stmt
= make_node (OMP_TARGET_UPDATE
);
13885 TREE_TYPE (stmt
) = void_type_node
;
13886 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
13887 SET_EXPR_LOCATION (stmt
, loc
);
13893 # pragma omp target target-clause[optseq] new-line
13894 structured-block */
13896 #define OMP_TARGET_CLAUSE_MASK \
13897 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13898 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13899 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13902 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
13904 location_t loc
= c_parser_peek_token (parser
)->location
;
13905 c_parser_consume_pragma (parser
);
13907 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
13909 c_parser_error (parser
, "expected declaration specifiers");
13910 c_parser_skip_to_pragma_eol (parser
);
13914 if (c_parser_next_token_is (parser
, CPP_NAME
))
13916 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13918 if (strcmp (p
, "teams") == 0)
13920 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
13921 char p_name
[sizeof ("#pragma omp target teams distribute "
13922 "parallel for simd")];
13924 c_parser_consume_token (parser
);
13925 strcpy (p_name
, "#pragma omp target");
13926 if (!flag_openmp
) /* flag_openmp_simd */
13928 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
13929 OMP_TARGET_CLAUSE_MASK
,
13931 return stmt
!= NULL_TREE
;
13933 keep_next_level ();
13934 tree block
= c_begin_compound_stmt (true);
13935 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
13936 OMP_TARGET_CLAUSE_MASK
, cclauses
);
13937 block
= c_end_compound_stmt (loc
, block
, true);
13938 if (ret
== NULL_TREE
)
13940 tree stmt
= make_node (OMP_TARGET
);
13941 TREE_TYPE (stmt
) = void_type_node
;
13942 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
13943 OMP_TARGET_BODY (stmt
) = block
;
13947 else if (!flag_openmp
) /* flag_openmp_simd */
13949 c_parser_skip_to_pragma_eol (parser
, false);
13952 else if (strcmp (p
, "data") == 0)
13954 c_parser_consume_token (parser
);
13955 c_parser_omp_target_data (loc
, parser
);
13958 else if (strcmp (p
, "update") == 0)
13960 c_parser_consume_token (parser
);
13961 return c_parser_omp_target_update (loc
, parser
, context
);
13965 tree stmt
= make_node (OMP_TARGET
);
13966 TREE_TYPE (stmt
) = void_type_node
;
13968 OMP_TARGET_CLAUSES (stmt
)
13969 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
13970 "#pragma omp target");
13971 keep_next_level ();
13972 tree block
= c_begin_compound_stmt (true);
13973 add_stmt (c_parser_omp_structured_block (parser
));
13974 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13976 SET_EXPR_LOCATION (stmt
, loc
);
13982 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
13984 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
13985 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
13986 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13987 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13988 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
13989 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
13990 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
13993 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
13995 vec
<c_token
> clauses
= vNULL
;
13996 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13998 c_token
*token
= c_parser_peek_token (parser
);
13999 if (token
->type
== CPP_EOF
)
14001 c_parser_skip_to_pragma_eol (parser
);
14002 clauses
.release ();
14005 clauses
.safe_push (*token
);
14006 c_parser_consume_token (parser
);
14008 clauses
.safe_push (*c_parser_peek_token (parser
));
14009 c_parser_skip_to_pragma_eol (parser
);
14011 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
14013 if (c_parser_peek_token (parser
)->pragma_kind
14014 != PRAGMA_OMP_DECLARE_REDUCTION
14015 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
14016 || strcmp (IDENTIFIER_POINTER
14017 (c_parser_peek_2nd_token (parser
)->value
),
14020 c_parser_error (parser
,
14021 "%<#pragma omp declare simd%> must be followed by "
14022 "function declaration or definition or another "
14023 "%<#pragma omp declare simd%>");
14024 clauses
.release ();
14027 c_parser_consume_pragma (parser
);
14028 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14030 c_token
*token
= c_parser_peek_token (parser
);
14031 if (token
->type
== CPP_EOF
)
14033 c_parser_skip_to_pragma_eol (parser
);
14034 clauses
.release ();
14037 clauses
.safe_push (*token
);
14038 c_parser_consume_token (parser
);
14040 clauses
.safe_push (*c_parser_peek_token (parser
));
14041 c_parser_skip_to_pragma_eol (parser
);
14044 /* Make sure nothing tries to read past the end of the tokens. */
14046 memset (&eof_token
, 0, sizeof (eof_token
));
14047 eof_token
.type
= CPP_EOF
;
14048 clauses
.safe_push (eof_token
);
14049 clauses
.safe_push (eof_token
);
14053 case pragma_external
:
14054 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14055 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14057 int ext
= disable_extension_diagnostics ();
14059 c_parser_consume_token (parser
);
14060 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14061 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14062 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14064 restore_extension_diagnostics (ext
);
14067 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14070 case pragma_struct
:
14072 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14073 "function declaration or definition");
14075 case pragma_compound
:
14077 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14078 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14080 int ext
= disable_extension_diagnostics ();
14082 c_parser_consume_token (parser
);
14083 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14084 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14085 if (c_parser_next_tokens_start_declaration (parser
))
14087 c_parser_declaration_or_fndef (parser
, true, true, true, true,
14088 true, NULL
, clauses
);
14089 restore_extension_diagnostics (ext
);
14092 restore_extension_diagnostics (ext
);
14094 else if (c_parser_next_tokens_start_declaration (parser
))
14096 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14100 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
14101 "function declaration or definition");
14104 gcc_unreachable ();
14106 clauses
.release ();
14109 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
14110 and put that into "omp declare simd" attribute. */
14113 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
14114 vec
<c_token
> clauses
)
14117 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14119 error ("%<#pragma omp declare simd%> cannot be used in the same "
14120 "function marked as a Cilk Plus SIMD-enabled function");
14121 vec_free (parser
->cilk_simd_fn_tokens
);
14125 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
14126 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
14127 has already processed the tokens. */
14128 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
14130 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14132 error ("%<#pragma omp declare simd%> not immediately followed by "
14133 "a function declaration or definition");
14134 clauses
[0].type
= CPP_EOF
;
14137 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
14139 error_at (DECL_SOURCE_LOCATION (fndecl
),
14140 "%<#pragma omp declare simd%> not immediately followed by "
14141 "a single function declaration or definition");
14142 clauses
[0].type
= CPP_EOF
;
14146 if (parms
== NULL_TREE
)
14147 parms
= DECL_ARGUMENTS (fndecl
);
14149 unsigned int tokens_avail
= parser
->tokens_avail
;
14150 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14151 bool is_cilkplus_cilk_simd_fn
= false;
14153 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14155 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
14156 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
14157 is_cilkplus_cilk_simd_fn
= true;
14161 parser
->tokens
= clauses
.address ();
14162 parser
->tokens_avail
= clauses
.length ();
14165 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
14166 while (parser
->tokens_avail
> 3)
14168 c_token
*token
= c_parser_peek_token (parser
);
14169 if (!is_cilkplus_cilk_simd_fn
)
14170 gcc_assert (token
->type
== CPP_NAME
14171 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
14173 gcc_assert (token
->type
== CPP_NAME
14174 && is_cilkplus_vector_p (token
->value
));
14175 c_parser_consume_token (parser
);
14176 parser
->in_pragma
= true;
14178 tree c
= NULL_TREE
;
14179 if (is_cilkplus_cilk_simd_fn
)
14180 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
14181 "SIMD-enabled functions attribute");
14183 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
14184 "#pragma omp declare simd");
14185 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
14186 if (c
!= NULL_TREE
)
14187 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
14188 if (is_cilkplus_cilk_simd_fn
)
14190 tree k
= build_tree_list (get_identifier ("cilk simd function"),
14192 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
14193 DECL_ATTRIBUTES (fndecl
) = k
;
14195 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
14196 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
14197 DECL_ATTRIBUTES (fndecl
) = c
;
14200 parser
->tokens
= &parser
->tokens_buf
[0];
14201 parser
->tokens_avail
= tokens_avail
;
14202 if (clauses
.exists ())
14203 clauses
[0].type
= CPP_PRAGMA
;
14205 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
14206 vec_free (parser
->cilk_simd_fn_tokens
);
14211 # pragma omp declare target new-line
14212 declarations and definitions
14213 # pragma omp end declare target new-line */
14216 c_parser_omp_declare_target (c_parser
*parser
)
14218 c_parser_skip_to_pragma_eol (parser
);
14219 current_omp_declare_target_attribute
++;
14223 c_parser_omp_end_declare_target (c_parser
*parser
)
14225 location_t loc
= c_parser_peek_token (parser
)->location
;
14226 c_parser_consume_pragma (parser
);
14227 if (c_parser_next_token_is (parser
, CPP_NAME
)
14228 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14231 c_parser_consume_token (parser
);
14232 if (c_parser_next_token_is (parser
, CPP_NAME
)
14233 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
14235 c_parser_consume_token (parser
);
14238 c_parser_error (parser
, "expected %<target%>");
14239 c_parser_skip_to_pragma_eol (parser
);
14245 c_parser_error (parser
, "expected %<declare%>");
14246 c_parser_skip_to_pragma_eol (parser
);
14249 c_parser_skip_to_pragma_eol (parser
);
14250 if (!current_omp_declare_target_attribute
)
14251 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
14252 "%<#pragma omp declare target%>");
14254 current_omp_declare_target_attribute
--;
14259 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14260 initializer-clause[opt] new-line
14262 initializer-clause:
14263 initializer (omp_priv = initializer)
14264 initializer (function-name (argument-list)) */
14267 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
14269 unsigned int tokens_avail
= 0, i
;
14270 vec
<tree
> types
= vNULL
;
14271 vec
<c_token
> clauses
= vNULL
;
14272 enum tree_code reduc_code
= ERROR_MARK
;
14273 tree reduc_id
= NULL_TREE
;
14275 location_t rloc
= c_parser_peek_token (parser
)->location
;
14277 if (context
== pragma_struct
|| context
== pragma_param
)
14279 error ("%<#pragma omp declare reduction%> not at file or block scope");
14283 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14286 switch (c_parser_peek_token (parser
)->type
)
14289 reduc_code
= PLUS_EXPR
;
14292 reduc_code
= MULT_EXPR
;
14295 reduc_code
= MINUS_EXPR
;
14298 reduc_code
= BIT_AND_EXPR
;
14301 reduc_code
= BIT_XOR_EXPR
;
14304 reduc_code
= BIT_IOR_EXPR
;
14307 reduc_code
= TRUTH_ANDIF_EXPR
;
14310 reduc_code
= TRUTH_ORIF_EXPR
;
14314 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14315 if (strcmp (p
, "min") == 0)
14317 reduc_code
= MIN_EXPR
;
14320 if (strcmp (p
, "max") == 0)
14322 reduc_code
= MAX_EXPR
;
14325 reduc_id
= c_parser_peek_token (parser
)->value
;
14328 c_parser_error (parser
,
14329 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
14330 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
14334 tree orig_reduc_id
, reduc_decl
;
14335 orig_reduc_id
= reduc_id
;
14336 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
14337 reduc_decl
= c_omp_reduction_decl (reduc_id
);
14338 c_parser_consume_token (parser
);
14340 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
14345 location_t loc
= c_parser_peek_token (parser
)->location
;
14346 struct c_type_name
*ctype
= c_parser_type_name (parser
);
14349 type
= groktypename (ctype
, NULL
, NULL
);
14350 if (type
== error_mark_node
)
14352 else if ((INTEGRAL_TYPE_P (type
)
14353 || TREE_CODE (type
) == REAL_TYPE
14354 || TREE_CODE (type
) == COMPLEX_TYPE
)
14355 && orig_reduc_id
== NULL_TREE
)
14356 error_at (loc
, "predeclared arithmetic type in "
14357 "%<#pragma omp declare reduction%>");
14358 else if (TREE_CODE (type
) == FUNCTION_TYPE
14359 || TREE_CODE (type
) == ARRAY_TYPE
)
14360 error_at (loc
, "function or array type in "
14361 "%<#pragma omp declare reduction%>");
14362 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
14363 error_at (loc
, "const, volatile or restrict qualified type in "
14364 "%<#pragma omp declare reduction%>");
14368 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
14369 if (comptypes (TREE_PURPOSE (t
), type
))
14371 error_at (loc
, "redeclaration of %qs "
14372 "%<#pragma omp declare reduction%> for "
14374 IDENTIFIER_POINTER (reduc_id
)
14375 + sizeof ("omp declare reduction ") - 1,
14378 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
14380 error_at (ploc
, "previous %<#pragma omp declare "
14384 if (t
== NULL_TREE
)
14385 types
.safe_push (type
);
14387 if (c_parser_next_token_is (parser
, CPP_COMMA
))
14388 c_parser_consume_token (parser
);
14396 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
14397 || types
.is_empty ())
14400 clauses
.release ();
14404 c_token
*token
= c_parser_peek_token (parser
);
14405 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
14407 c_parser_consume_token (parser
);
14409 c_parser_skip_to_pragma_eol (parser
);
14413 if (types
.length () > 1)
14415 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14417 c_token
*token
= c_parser_peek_token (parser
);
14418 if (token
->type
== CPP_EOF
)
14420 clauses
.safe_push (*token
);
14421 c_parser_consume_token (parser
);
14423 clauses
.safe_push (*c_parser_peek_token (parser
));
14424 c_parser_skip_to_pragma_eol (parser
);
14426 /* Make sure nothing tries to read past the end of the tokens. */
14428 memset (&eof_token
, 0, sizeof (eof_token
));
14429 eof_token
.type
= CPP_EOF
;
14430 clauses
.safe_push (eof_token
);
14431 clauses
.safe_push (eof_token
);
14434 int errs
= errorcount
;
14435 FOR_EACH_VEC_ELT (types
, i
, type
)
14437 tokens_avail
= parser
->tokens_avail
;
14438 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
14439 if (!clauses
.is_empty ())
14441 parser
->tokens
= clauses
.address ();
14442 parser
->tokens_avail
= clauses
.length ();
14443 parser
->in_pragma
= true;
14446 bool nested
= current_function_decl
!= NULL_TREE
;
14448 c_push_function_context ();
14449 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
14450 reduc_id
, default_function_type
);
14451 current_function_decl
= fndecl
;
14452 allocate_struct_function (fndecl
, true);
14454 tree stmt
= push_stmt_list ();
14455 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
14456 warn about these. */
14457 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14458 get_identifier ("omp_out"), type
);
14459 DECL_ARTIFICIAL (omp_out
) = 1;
14460 DECL_CONTEXT (omp_out
) = fndecl
;
14461 pushdecl (omp_out
);
14462 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14463 get_identifier ("omp_in"), type
);
14464 DECL_ARTIFICIAL (omp_in
) = 1;
14465 DECL_CONTEXT (omp_in
) = fndecl
;
14467 struct c_expr combiner
= c_parser_expression (parser
);
14468 struct c_expr initializer
;
14469 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
14471 initializer
.value
= error_mark_node
;
14472 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14474 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14475 && strcmp (IDENTIFIER_POINTER
14476 (c_parser_peek_token (parser
)->value
),
14477 "initializer") == 0)
14479 c_parser_consume_token (parser
);
14482 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14483 get_identifier ("omp_priv"), type
);
14484 DECL_ARTIFICIAL (omp_priv
) = 1;
14485 DECL_INITIAL (omp_priv
) = error_mark_node
;
14486 DECL_CONTEXT (omp_priv
) = fndecl
;
14487 pushdecl (omp_priv
);
14488 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
14489 get_identifier ("omp_orig"), type
);
14490 DECL_ARTIFICIAL (omp_orig
) = 1;
14491 DECL_CONTEXT (omp_orig
) = fndecl
;
14492 pushdecl (omp_orig
);
14493 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14495 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
14497 c_parser_error (parser
, "expected %<omp_priv%> or "
14501 else if (strcmp (IDENTIFIER_POINTER
14502 (c_parser_peek_token (parser
)->value
),
14505 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
14506 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14508 c_parser_error (parser
, "expected function-name %<(%>");
14512 initializer
= c_parser_postfix_expression (parser
);
14513 if (initializer
.value
14514 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
14517 tree c
= initializer
.value
;
14518 for (j
= 0; j
< call_expr_nargs (c
); j
++)
14519 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
14520 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
14522 if (j
== call_expr_nargs (c
))
14523 error ("one of the initializer call arguments should be "
14529 c_parser_consume_token (parser
);
14530 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14534 tree st
= push_stmt_list ();
14535 start_init (omp_priv
, NULL_TREE
, 0);
14536 location_t loc
= c_parser_peek_token (parser
)->location
;
14537 struct c_expr init
= c_parser_initializer (parser
);
14539 finish_decl (omp_priv
, loc
, init
.value
,
14540 init
.original_type
, NULL_TREE
);
14541 pop_stmt_list (st
);
14545 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14551 c_parser_skip_to_pragma_eol (parser
);
14553 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
14554 DECL_INITIAL (reduc_decl
));
14555 DECL_INITIAL (reduc_decl
) = t
;
14556 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
14557 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
14558 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
14559 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
14560 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
14561 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
14564 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
14565 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
14566 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
14567 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
14568 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
14569 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14570 walk_tree (&DECL_INITIAL (omp_priv
),
14571 c_check_omp_declare_reduction_r
,
14572 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
14576 pop_stmt_list (stmt
);
14578 if (cfun
->language
!= NULL
)
14580 ggc_free (cfun
->language
);
14581 cfun
->language
= NULL
;
14584 current_function_decl
= NULL_TREE
;
14586 c_pop_function_context ();
14588 if (!clauses
.is_empty ())
14590 parser
->tokens
= &parser
->tokens_buf
[0];
14591 parser
->tokens_avail
= tokens_avail
;
14595 if (errs
!= errorcount
)
14599 clauses
.release ();
14605 #pragma omp declare simd declare-simd-clauses[optseq] new-line
14606 #pragma omp declare reduction (reduction-id : typename-list : expression) \
14607 initializer-clause[opt] new-line
14608 #pragma omp declare target new-line */
14611 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
14613 c_parser_consume_pragma (parser
);
14614 if (c_parser_next_token_is (parser
, CPP_NAME
))
14616 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14617 if (strcmp (p
, "simd") == 0)
14619 /* c_parser_consume_token (parser); done in
14620 c_parser_omp_declare_simd. */
14621 c_parser_omp_declare_simd (parser
, context
);
14624 if (strcmp (p
, "reduction") == 0)
14626 c_parser_consume_token (parser
);
14627 c_parser_omp_declare_reduction (parser
, context
);
14630 if (!flag_openmp
) /* flag_openmp_simd */
14632 c_parser_skip_to_pragma_eol (parser
, false);
14635 if (strcmp (p
, "target") == 0)
14637 c_parser_consume_token (parser
);
14638 c_parser_omp_declare_target (parser
);
14643 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
14645 c_parser_skip_to_pragma_eol (parser
);
14648 /* Main entry point to parsing most OpenMP pragmas. */
14651 c_parser_omp_construct (c_parser
*parser
)
14653 enum pragma_kind p_kind
;
14656 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
14657 omp_clause_mask
mask (0);
14659 loc
= c_parser_peek_token (parser
)->location
;
14660 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
14661 c_parser_consume_pragma (parser
);
14665 case PRAGMA_OACC_CACHE
:
14666 strcpy (p_name
, "#pragma acc");
14667 stmt
= c_parser_oacc_cache (loc
, parser
);
14669 case PRAGMA_OACC_DATA
:
14670 stmt
= c_parser_oacc_data (loc
, parser
);
14672 case PRAGMA_OACC_KERNELS
:
14673 strcpy (p_name
, "#pragma acc");
14674 stmt
= c_parser_oacc_kernels (loc
, parser
, p_name
);
14676 case PRAGMA_OACC_LOOP
:
14677 strcpy (p_name
, "#pragma acc");
14678 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
);
14680 case PRAGMA_OACC_PARALLEL
:
14681 strcpy (p_name
, "#pragma acc");
14682 stmt
= c_parser_oacc_parallel (loc
, parser
, p_name
);
14684 case PRAGMA_OACC_WAIT
:
14685 strcpy (p_name
, "#pragma wait");
14686 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
14688 case PRAGMA_OMP_ATOMIC
:
14689 c_parser_omp_atomic (loc
, parser
);
14691 case PRAGMA_OMP_CRITICAL
:
14692 stmt
= c_parser_omp_critical (loc
, parser
);
14694 case PRAGMA_OMP_DISTRIBUTE
:
14695 strcpy (p_name
, "#pragma omp");
14696 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
14698 case PRAGMA_OMP_FOR
:
14699 strcpy (p_name
, "#pragma omp");
14700 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
14702 case PRAGMA_OMP_MASTER
:
14703 stmt
= c_parser_omp_master (loc
, parser
);
14705 case PRAGMA_OMP_ORDERED
:
14706 stmt
= c_parser_omp_ordered (loc
, parser
);
14708 case PRAGMA_OMP_PARALLEL
:
14709 strcpy (p_name
, "#pragma omp");
14710 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
14712 case PRAGMA_OMP_SECTIONS
:
14713 strcpy (p_name
, "#pragma omp");
14714 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
14716 case PRAGMA_OMP_SIMD
:
14717 strcpy (p_name
, "#pragma omp");
14718 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
14720 case PRAGMA_OMP_SINGLE
:
14721 stmt
= c_parser_omp_single (loc
, parser
);
14723 case PRAGMA_OMP_TASK
:
14724 stmt
= c_parser_omp_task (loc
, parser
);
14726 case PRAGMA_OMP_TASKGROUP
:
14727 stmt
= c_parser_omp_taskgroup (parser
);
14729 case PRAGMA_OMP_TEAMS
:
14730 strcpy (p_name
, "#pragma omp");
14731 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
14734 gcc_unreachable ();
14738 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
14743 # pragma omp threadprivate (variable-list) */
14746 c_parser_omp_threadprivate (c_parser
*parser
)
14751 c_parser_consume_pragma (parser
);
14752 loc
= c_parser_peek_token (parser
)->location
;
14753 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14755 /* Mark every variable in VARS to be assigned thread local storage. */
14756 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
14758 tree v
= TREE_PURPOSE (t
);
14760 /* FIXME diagnostics: Ideally we should keep individual
14761 locations for all the variables in the var list to make the
14762 following errors more precise. Perhaps
14763 c_parser_omp_var_list_parens() should construct a list of
14764 locations to go along with the var list. */
14766 /* If V had already been marked threadprivate, it doesn't matter
14767 whether it had been used prior to this point. */
14768 if (TREE_CODE (v
) != VAR_DECL
)
14769 error_at (loc
, "%qD is not a variable", v
);
14770 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
14771 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
14772 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
14773 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
14774 else if (TREE_TYPE (v
) == error_mark_node
)
14776 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
14777 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
14780 if (! DECL_THREAD_LOCAL_P (v
))
14782 set_decl_tls_model (v
, decl_default_tls_model (v
));
14783 /* If rtl has been already set for this var, call
14784 make_decl_rtl once again, so that encode_section_info
14785 has a chance to look at the new decl flags. */
14786 if (DECL_RTL_SET_P (v
))
14789 C_DECL_THREADPRIVATE_P (v
) = 1;
14793 c_parser_skip_to_pragma_eol (parser
);
14796 /* Cilk Plus <#pragma simd> parsing routines. */
14798 /* Helper function for c_parser_pragma. Perform some sanity checking
14799 for <#pragma simd> constructs. Returns FALSE if there was a
14803 c_parser_cilk_verify_simd (c_parser
*parser
,
14804 enum pragma_context context
)
14806 if (!flag_cilkplus
)
14808 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14809 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14812 if (context
== pragma_external
)
14814 c_parser_error (parser
,"pragma simd must be inside a function");
14815 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14822 This function is shared by SIMD-enabled functions and #pragma simd.
14823 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14824 CLAUSES is unused. The main purpose of this function is to parse a
14825 vectorlength attribute or clause and check for parse errors.
14826 When IS_SIMD_FN is true then the function is merely caching the tokens
14827 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14828 cache is cleared since there is no reason to continue.
14830 vectorlength ( constant-expression ) */
14833 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
14837 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
14839 /* The vectorlength clause behaves exactly like OpenMP's safelen
14840 clause. Represent it in OpenMP terms. */
14841 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
14843 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14846 location_t loc
= c_parser_peek_token (parser
)->location
;
14847 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14848 expr
= c_fully_fold (expr
, false, NULL
);
14850 /* If expr is an error_mark_node then the above function would have
14851 emitted an error. No reason to do it twice. */
14852 if (expr
== error_mark_node
)
14854 else if (!TREE_TYPE (expr
)
14855 || !TREE_CONSTANT (expr
)
14856 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
14858 error_at (loc
, "vectorlength must be an integer constant");
14859 else if (wi::exact_log2 (expr
) == -1)
14860 error_at (loc
, "vectorlength must be a power of 2");
14865 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
14866 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
14867 OMP_CLAUSE_CHAIN (u
) = clauses
;
14872 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
14873 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
14874 OMP_CLAUSE_CHAIN (u
) = clauses
;
14879 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14885 linear ( simd-linear-variable-list )
14887 simd-linear-variable-list:
14888 simd-linear-variable
14889 simd-linear-variable-list , simd-linear-variable
14891 simd-linear-variable:
14893 id-expression : simd-linear-step
14896 conditional-expression */
14899 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
14901 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14904 location_t loc
= c_parser_peek_token (parser
)->location
;
14906 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14907 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14908 c_parser_error (parser
, "expected identifier");
14910 while (c_parser_next_token_is (parser
, CPP_NAME
)
14911 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14913 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
14917 undeclared_variable (c_parser_peek_token (parser
)->location
,
14918 c_parser_peek_token (parser
)->value
);
14919 c_parser_consume_token (parser
);
14921 else if (var
== error_mark_node
)
14922 c_parser_consume_token (parser
);
14925 tree step
= integer_one_node
;
14927 /* Parse the linear step if present. */
14928 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14930 c_parser_consume_token (parser
);
14931 c_parser_consume_token (parser
);
14933 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14934 expr
= c_fully_fold (expr
, false, NULL
);
14936 if (TREE_TYPE (expr
)
14937 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
14938 && (TREE_CONSTANT (expr
)
14942 c_parser_error (parser
,
14943 "step size must be an integer constant "
14944 "expression or an integer variable");
14947 c_parser_consume_token (parser
);
14949 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
14950 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
14951 OMP_CLAUSE_DECL (u
) = var
;
14952 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
14953 OMP_CLAUSE_CHAIN (u
) = clauses
;
14957 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
14960 c_parser_consume_token (parser
);
14963 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14968 /* Returns the name of the next clause. If the clause is not
14969 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14970 not consumed. Otherwise, the appropriate pragma_simd_clause is
14971 returned and the token is consumed. */
14973 static pragma_omp_clause
14974 c_parser_cilk_clause_name (c_parser
*parser
)
14976 pragma_omp_clause result
;
14977 c_token
*token
= c_parser_peek_token (parser
);
14979 if (!token
->value
|| token
->type
!= CPP_NAME
)
14980 return PRAGMA_CILK_CLAUSE_NONE
;
14982 const char *p
= IDENTIFIER_POINTER (token
->value
);
14984 if (!strcmp (p
, "vectorlength"))
14985 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
14986 else if (!strcmp (p
, "linear"))
14987 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
14988 else if (!strcmp (p
, "private"))
14989 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
14990 else if (!strcmp (p
, "firstprivate"))
14991 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
14992 else if (!strcmp (p
, "lastprivate"))
14993 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
14994 else if (!strcmp (p
, "reduction"))
14995 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
14997 return PRAGMA_CILK_CLAUSE_NONE
;
14999 c_parser_consume_token (parser
);
15003 /* Parse all #<pragma simd> clauses. Return the list of clauses
15007 c_parser_cilk_all_clauses (c_parser
*parser
)
15009 tree clauses
= NULL
;
15011 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15013 pragma_omp_clause c_kind
;
15015 c_kind
= c_parser_cilk_clause_name (parser
);
15019 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
15020 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
15022 case PRAGMA_CILK_CLAUSE_LINEAR
:
15023 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
15025 case PRAGMA_CILK_CLAUSE_PRIVATE
:
15026 /* Use the OpenMP counterpart. */
15027 clauses
= c_parser_omp_clause_private (parser
, clauses
);
15029 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
15030 /* Use the OpenMP counterpart. */
15031 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
15033 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
15034 /* Use the OpenMP counterpart. */
15035 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
15037 case PRAGMA_CILK_CLAUSE_REDUCTION
:
15038 /* Use the OpenMP counterpart. */
15039 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
15042 c_parser_error (parser
, "expected %<#pragma simd%> clause");
15048 c_parser_skip_to_pragma_eol (parser
);
15049 return c_finish_cilk_clauses (clauses
);
15052 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
15053 Here is the correct syntax of this pragma:
15054 #pragma cilk grainsize = <EXP>
15058 c_parser_cilk_grainsize (c_parser
*parser
)
15060 extern tree
convert_to_integer (tree
, tree
);
15062 /* consume the 'grainsize' keyword. */
15063 c_parser_consume_pragma (parser
);
15065 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
15067 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
15068 if (g_expr
.value
== error_mark_node
)
15070 c_parser_skip_to_pragma_eol (parser
);
15073 tree grain
= convert_to_integer (long_integer_type_node
,
15074 c_fully_fold (g_expr
.value
, false,
15076 c_parser_skip_to_pragma_eol (parser
);
15077 c_token
*token
= c_parser_peek_token (parser
);
15078 if (token
&& token
->type
== CPP_KEYWORD
15079 && token
->keyword
== RID_CILK_FOR
)
15081 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
15082 grain
= integer_zero_node
;
15083 c_parser_cilk_for (parser
, grain
);
15086 warning (0, "%<#pragma cilk grainsize%> is not followed by "
15090 c_parser_skip_to_pragma_eol (parser
);
15093 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
15096 c_parser_cilk_simd (c_parser
*parser
)
15098 tree clauses
= c_parser_cilk_all_clauses (parser
);
15099 tree block
= c_begin_compound_stmt (true);
15100 location_t loc
= c_parser_peek_token (parser
)->location
;
15101 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
15102 block
= c_end_compound_stmt (loc
, block
, true);
15106 /* Create an artificial decl with TYPE and emit initialization of it with
15110 c_get_temp_regvar (tree type
, tree init
)
15112 location_t loc
= EXPR_LOCATION (init
);
15113 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
15114 DECL_ARTIFICIAL (decl
) = 1;
15115 DECL_IGNORED_P (decl
) = 1;
15117 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
15122 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
15123 GRAIN is the grain value passed in through pragma or 0. */
15126 c_parser_cilk_for (c_parser
*parser
, tree grain
)
15128 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
15129 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
15130 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
15131 clauses
= c_finish_omp_clauses (clauses
);
15133 tree block
= c_begin_compound_stmt (true);
15134 tree sb
= push_stmt_list ();
15135 location_t loc
= c_parser_peek_token (parser
)->location
;
15136 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
15137 sb
= pop_stmt_list (sb
);
15141 tree omp_par
= make_node (OMP_PARALLEL
);
15142 TREE_TYPE (omp_par
) = void_type_node
;
15143 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
15144 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
15145 TREE_SIDE_EFFECTS (bind
) = 1;
15146 BIND_EXPR_BODY (bind
) = sb
;
15147 OMP_PARALLEL_BODY (omp_par
) = bind
;
15148 if (OMP_FOR_PRE_BODY (omp_for
))
15150 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
15151 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
15153 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
15154 tree decl
= TREE_OPERAND (init
, 0);
15155 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
15156 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
15157 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
15158 if (TREE_CODE (t
) != INTEGER_CST
)
15160 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15161 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15162 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
15163 OMP_CLAUSE_CHAIN (c
) = clauses
;
15166 if (TREE_CODE (incr
) == MODIFY_EXPR
)
15168 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15169 if (TREE_CODE (t
) != INTEGER_CST
)
15171 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
15172 = c_get_temp_regvar (TREE_TYPE (t
), t
);
15173 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15174 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
15175 OMP_CLAUSE_CHAIN (c
) = clauses
;
15179 t
= TREE_OPERAND (init
, 1);
15180 if (TREE_CODE (t
) != INTEGER_CST
)
15182 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
15183 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
15184 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
15185 OMP_CLAUSE_CHAIN (c
) = clauses
;
15188 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
15189 OMP_CLAUSE_DECL (c
) = decl
;
15190 OMP_CLAUSE_CHAIN (c
) = clauses
;
15192 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
15193 OMP_CLAUSE_OPERAND (c
, 0)
15194 = cilk_for_number_of_iterations (omp_for
);
15195 OMP_CLAUSE_CHAIN (c
) = clauses
;
15196 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
);
15197 add_stmt (omp_par
);
15200 block
= c_end_compound_stmt (loc
, block
, true);
15205 /* Parse a transaction attribute (GCC Extension).
15207 transaction-attribute:
15211 The transactional memory language description is written for C++,
15212 and uses the C++0x attribute syntax. For compatibility, allow the
15213 bracket style for transactions in C as well. */
15216 c_parser_transaction_attributes (c_parser
*parser
)
15218 tree attr_name
, attr
= NULL
;
15220 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
15221 return c_parser_attributes (parser
);
15223 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
15225 c_parser_consume_token (parser
);
15226 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
15229 attr_name
= c_parser_attribute_any_word (parser
);
15232 c_parser_consume_token (parser
);
15233 attr
= build_tree_list (attr_name
, NULL_TREE
);
15236 c_parser_error (parser
, "expected identifier");
15238 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15240 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15244 /* Parse a __transaction_atomic or __transaction_relaxed statement
15247 transaction-statement:
15248 __transaction_atomic transaction-attribute[opt] compound-statement
15249 __transaction_relaxed compound-statement
15251 Note that the only valid attribute is: "outer".
15255 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
15257 unsigned int old_in
= parser
->in_transaction
;
15258 unsigned int this_in
= 1, new_in
;
15259 location_t loc
= c_parser_peek_token (parser
)->location
;
15262 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15263 || keyword
== RID_TRANSACTION_RELAXED
)
15264 && c_parser_next_token_is_keyword (parser
, keyword
));
15265 c_parser_consume_token (parser
);
15267 if (keyword
== RID_TRANSACTION_RELAXED
)
15268 this_in
|= TM_STMT_ATTR_RELAXED
;
15271 attrs
= c_parser_transaction_attributes (parser
);
15273 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
15276 /* Keep track if we're in the lexical scope of an outer transaction. */
15277 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
15279 parser
->in_transaction
= new_in
;
15280 stmt
= c_parser_compound_statement (parser
);
15281 parser
->in_transaction
= old_in
;
15284 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
15286 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15287 "%<__transaction_atomic%> without transactional memory support enabled"
15288 : "%<__transaction_relaxed %> "
15289 "without transactional memory support enabled"));
15294 /* Parse a __transaction_atomic or __transaction_relaxed expression
15297 transaction-expression:
15298 __transaction_atomic ( expression )
15299 __transaction_relaxed ( expression )
15302 static struct c_expr
15303 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
15306 unsigned int old_in
= parser
->in_transaction
;
15307 unsigned int this_in
= 1;
15308 location_t loc
= c_parser_peek_token (parser
)->location
;
15311 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
15312 || keyword
== RID_TRANSACTION_RELAXED
)
15313 && c_parser_next_token_is_keyword (parser
, keyword
));
15314 c_parser_consume_token (parser
);
15316 if (keyword
== RID_TRANSACTION_RELAXED
)
15317 this_in
|= TM_STMT_ATTR_RELAXED
;
15320 attrs
= c_parser_transaction_attributes (parser
);
15322 this_in
|= parse_tm_stmt_attr (attrs
, 0);
15325 parser
->in_transaction
= this_in
;
15326 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
15328 tree expr
= c_parser_expression (parser
).value
;
15329 ret
.original_type
= TREE_TYPE (expr
);
15330 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
15331 if (this_in
& TM_STMT_ATTR_RELAXED
)
15332 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
15333 SET_EXPR_LOCATION (ret
.value
, loc
);
15334 ret
.original_code
= TRANSACTION_EXPR
;
15335 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
15337 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
15344 ret
.value
= error_mark_node
;
15345 ret
.original_code
= ERROR_MARK
;
15346 ret
.original_type
= NULL
;
15348 parser
->in_transaction
= old_in
;
15351 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
15352 "%<__transaction_atomic%> without transactional memory support enabled"
15353 : "%<__transaction_relaxed %> "
15354 "without transactional memory support enabled"));
15359 /* Parse a __transaction_cancel statement (GCC Extension).
15361 transaction-cancel-statement:
15362 __transaction_cancel transaction-attribute[opt] ;
15364 Note that the only valid attribute is "outer".
15368 c_parser_transaction_cancel (c_parser
*parser
)
15370 location_t loc
= c_parser_peek_token (parser
)->location
;
15372 bool is_outer
= false;
15374 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
15375 c_parser_consume_token (parser
);
15377 attrs
= c_parser_transaction_attributes (parser
);
15379 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
15383 error_at (loc
, "%<__transaction_cancel%> without "
15384 "transactional memory support enabled");
15387 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
15389 error_at (loc
, "%<__transaction_cancel%> within a "
15390 "%<__transaction_relaxed%>");
15395 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
15396 && !is_tm_may_cancel_outer (current_function_decl
))
15398 error_at (loc
, "outer %<__transaction_cancel%> not "
15399 "within outer %<__transaction_atomic%>");
15400 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
15404 else if (parser
->in_transaction
== 0)
15406 error_at (loc
, "%<__transaction_cancel%> not within "
15407 "%<__transaction_atomic%>");
15411 return add_stmt (build_tm_abort_call (loc
, is_outer
));
15414 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
15417 /* Parse a single source file. */
15420 c_parse_file (void)
15422 /* Use local storage to begin. If the first token is a pragma, parse it.
15423 If it is #pragma GCC pch_preprocess, then this will load a PCH file
15424 which will cause garbage collection. */
15427 memset (&tparser
, 0, sizeof tparser
);
15428 tparser
.tokens
= &tparser
.tokens_buf
[0];
15429 the_parser
= &tparser
;
15431 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
15432 c_parser_pragma_pch_preprocess (&tparser
);
15434 the_parser
= ggc_alloc
<c_parser
> ();
15435 *the_parser
= tparser
;
15436 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
15437 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
15439 /* Initialize EH, if we've been told to do so. */
15440 if (flag_exceptions
)
15441 using_eh_for_cleanups ();
15443 c_parser_translation_unit (the_parser
);
15447 /* This function parses Cilk Plus array notation. The starting index is
15448 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
15449 return value of this function is a tree_node called VALUE_TREE of type
15450 ARRAY_NOTATION_REF. */
15453 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
15456 c_token
*token
= NULL
;
15457 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
15458 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
15459 tree array_type_domain
= NULL_TREE
;
15461 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
15463 /* No need to continue. If either of these 2 were true, then an error
15464 must be emitted already. Thus, no need to emit them twice. */
15465 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15466 return error_mark_node
;
15469 array_type
= TREE_TYPE (array_value
);
15470 gcc_assert (array_type
);
15471 if (TREE_CODE (array_type
) != ARRAY_TYPE
15472 && TREE_CODE (array_type
) != POINTER_TYPE
)
15474 error_at (loc
, "base of array section must be pointer or array type");
15475 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15476 return error_mark_node
;
15478 type
= TREE_TYPE (array_type
);
15479 token
= c_parser_peek_token (parser
);
15481 if (token
->type
== CPP_EOF
)
15483 c_parser_error (parser
, "expected %<:%> or numeral");
15486 else if (token
->type
== CPP_COLON
)
15488 if (!initial_index
)
15490 /* If we are here, then we have a case like this A[:]. */
15491 c_parser_consume_token (parser
);
15492 if (TREE_CODE (array_type
) == POINTER_TYPE
)
15494 error_at (loc
, "start-index and length fields necessary for "
15495 "using array notations in pointers");
15496 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15497 return error_mark_node
;
15499 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15501 error_at (loc
, "array notations cannot be used with function "
15503 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15504 return error_mark_node
;
15506 array_type_domain
= TYPE_DOMAIN (array_type
);
15508 if (!array_type_domain
)
15510 error_at (loc
, "start-index and length fields necessary for "
15511 "using array notations in dimensionless arrays");
15512 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15513 return error_mark_node
;
15516 start_index
= TYPE_MINVAL (array_type_domain
);
15517 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
15519 if (!TYPE_MAXVAL (array_type_domain
)
15520 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
15522 error_at (loc
, "start-index and length fields necessary for "
15523 "using array notations in variable-length arrays");
15524 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15525 return error_mark_node
;
15527 end_index
= TYPE_MAXVAL (array_type_domain
);
15528 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
15529 end_index
, integer_one_node
);
15530 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
15531 stride
= build_int_cst (integer_type_node
, 1);
15532 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
15534 else if (initial_index
!= error_mark_node
)
15536 /* If we are here, then there should be 2 possibilities:
15537 1. Array [EXPR : EXPR]
15538 2. Array [EXPR : EXPR : EXPR]
15540 start_index
= initial_index
;
15542 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
15544 error_at (loc
, "array notations cannot be used with function "
15546 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
15547 return error_mark_node
;
15549 c_parser_consume_token (parser
); /* consume the ':' */
15550 struct c_expr ce
= c_parser_expression (parser
);
15551 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15552 end_index
= ce
.value
;
15553 if (!end_index
|| end_index
== error_mark_node
)
15555 c_parser_skip_to_end_of_block_or_statement (parser
);
15556 return error_mark_node
;
15558 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
15560 c_parser_consume_token (parser
);
15561 ce
= c_parser_expression (parser
);
15562 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
15564 if (!stride
|| stride
== error_mark_node
)
15566 c_parser_skip_to_end_of_block_or_statement (parser
);
15567 return error_mark_node
;
15572 c_parser_error (parser
, "expected array notation expression");
15575 c_parser_error (parser
, "expected array notation expression");
15577 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
15579 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
15580 end_index
, stride
, type
);
15581 if (value_tree
!= error_mark_node
)
15582 SET_EXPR_LOCATION (value_tree
, loc
);
15586 #include "gt-c-c-parser.h"