1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
43 #include "stringpool.h"
45 #include "stor-layout.h"
47 #include "trans-mem.h"
48 #include "langhooks.h"
52 #include "c-family/c-pragma.h"
57 #include "c-family/c-common.h"
58 #include "c-family/c-objc.h"
67 /* Initialization routine for this file. */
72 /* The only initialization required is of the reserved word
78 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
79 the c_token structure. */
80 gcc_assert (RID_MAX
<= 255);
87 mask
|= D_ASM
| D_EXT
;
91 if (!c_dialect_objc ())
92 mask
|= D_OBJC
| D_CXX_OBJC
;
94 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
95 for (i
= 0; i
< num_c_common_reswords
; i
++)
97 /* If a keyword is disabled, do not enter it into the table
98 and so create a canonical spelling that isn't a keyword. */
99 if (c_common_reswords
[i
].disable
& mask
)
102 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
104 id
= get_identifier (c_common_reswords
[i
].word
);
105 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
106 C_IS_RESERVED_WORD (id
) = 1;
111 id
= get_identifier (c_common_reswords
[i
].word
);
112 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
113 C_IS_RESERVED_WORD (id
) = 1;
114 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
118 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
119 and the C parser. Unlike the C++ lexer, the parser structure
120 stores the lexer information instead of using a separate structure.
121 Identifiers are separated into ordinary identifiers, type names,
122 keywords and some other Objective-C types of identifiers, and some
123 look-ahead is maintained.
125 ??? It might be a good idea to lex the whole file up front (as for
126 C++). It would then be possible to share more of the C and C++
127 lexer code, if desired. */
129 /* The following local token type is used. */
132 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
134 /* More information about the type of a CPP_NAME token. */
135 typedef enum c_id_kind
{
136 /* An ordinary identifier. */
138 /* An identifier declared as a typedef name. */
140 /* An identifier declared as an Objective-C class name. */
142 /* An address space identifier. */
144 /* Not an identifier. */
148 /* A single C token after string literal concatenation and conversion
149 of preprocessing tokens to tokens. */
150 typedef struct GTY (()) c_token
{
151 /* The kind of token. */
152 ENUM_BITFIELD (cpp_ttype
) type
: 8;
153 /* If this token is a CPP_NAME, this value indicates whether also
154 declared as some kind of type. Otherwise, it is C_ID_NONE. */
155 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
156 /* If this token is a keyword, this value indicates which keyword.
157 Otherwise, this value is RID_MAX. */
158 ENUM_BITFIELD (rid
) keyword
: 8;
159 /* If this token is a CPP_PRAGMA, this indicates the pragma that
160 was seen. Otherwise it is PRAGMA_NONE. */
161 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
162 /* The location at which this token was found. */
164 /* The value associated with this token, if any. */
168 /* A parser structure recording information about the state and
169 context of parsing. Includes lexer information with up to two
170 tokens of look-ahead; more are not needed for C. */
171 typedef struct GTY(()) c_parser
{
172 /* The look-ahead tokens. */
173 c_token
* GTY((skip
)) tokens
;
174 /* Buffer for look-ahead tokens. */
175 c_token tokens_buf
[2];
176 /* How many look-ahead tokens are available (0, 1 or 2, or
177 more if parsing from pre-lexed tokens). */
178 unsigned int tokens_avail
;
179 /* True if a syntax error is being recovered from; false otherwise.
180 c_parser_error sets this flag. It should clear this flag when
181 enough tokens have been consumed to recover from the error. */
182 BOOL_BITFIELD error
: 1;
183 /* True if we're processing a pragma, and shouldn't automatically
184 consume CPP_PRAGMA_EOL. */
185 BOOL_BITFIELD in_pragma
: 1;
186 /* True if we're parsing the outermost block of an if statement. */
187 BOOL_BITFIELD in_if_block
: 1;
188 /* True if we want to lex an untranslated string. */
189 BOOL_BITFIELD lex_untranslated_string
: 1;
191 /* Objective-C specific parser/lexer information. */
193 /* True if we are in a context where the Objective-C "PQ" keywords
194 are considered keywords. */
195 BOOL_BITFIELD objc_pq_context
: 1;
196 /* True if we are parsing a (potential) Objective-C foreach
197 statement. This is set to true after we parsed 'for (' and while
198 we wait for 'in' or ';' to decide if it's a standard C for loop or an
199 Objective-C foreach loop. */
200 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
201 /* The following flag is needed to contextualize Objective-C lexical
202 analysis. In some cases (e.g., 'int NSObject;'), it is
203 undesirable to bind an identifier to an Objective-C class, even
204 if a class with that name exists. */
205 BOOL_BITFIELD objc_need_raw_identifier
: 1;
206 /* Nonzero if we're processing a __transaction statement. The value
207 is 1 | TM_STMT_ATTR_*. */
208 unsigned int in_transaction
: 4;
209 /* True if we are in a context where the Objective-C "Property attribute"
210 keywords are valid. */
211 BOOL_BITFIELD objc_property_attr_context
: 1;
213 /* Cilk Plus specific parser/lexer information. */
215 /* Buffer to hold all the tokens from parsing the vector attribute for the
216 SIMD-enabled functions (formerly known as elemental functions). */
217 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
221 /* The actual parser and external interface. ??? Does this need to be
222 garbage-collected? */
224 static GTY (()) c_parser
*the_parser
;
226 /* Read in and lex a single token, storing it in *TOKEN. */
229 c_lex_one_token (c_parser
*parser
, c_token
*token
)
231 timevar_push (TV_LEX
);
233 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
234 (parser
->lex_untranslated_string
235 ? C_LEX_STRING_NO_TRANSLATE
: 0));
236 token
->id_kind
= C_ID_NONE
;
237 token
->keyword
= RID_MAX
;
238 token
->pragma_kind
= PRAGMA_NONE
;
246 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
247 if (c_dialect_objc ())
248 parser
->objc_need_raw_identifier
= false;
250 if (C_IS_RESERVED_WORD (token
->value
))
252 enum rid rid_code
= C_RID_CODE (token
->value
);
254 if (rid_code
== RID_CXX_COMPAT_WARN
)
256 warning_at (token
->location
,
258 "identifier %qE conflicts with C++ keyword",
261 else if (rid_code
>= RID_FIRST_ADDR_SPACE
262 && rid_code
<= RID_LAST_ADDR_SPACE
)
264 token
->id_kind
= C_ID_ADDRSPACE
;
265 token
->keyword
= rid_code
;
268 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
270 /* We found an Objective-C "pq" keyword (in, out,
271 inout, bycopy, byref, oneway). They need special
272 care because the interpretation depends on the
274 if (parser
->objc_pq_context
)
276 token
->type
= CPP_KEYWORD
;
277 token
->keyword
= rid_code
;
280 else if (parser
->objc_could_be_foreach_context
281 && rid_code
== RID_IN
)
283 /* We are in Objective-C, inside a (potential)
284 foreach context (which means after having
285 parsed 'for (', but before having parsed ';'),
286 and we found 'in'. We consider it the keyword
287 which terminates the declaration at the
288 beginning of a foreach-statement. Note that
289 this means you can't use 'in' for anything else
290 in that context; in particular, in Objective-C
291 you can't use 'in' as the name of the running
292 variable in a C for loop. We could potentially
293 try to add code here to disambiguate, but it
294 seems a reasonable limitation. */
295 token
->type
= CPP_KEYWORD
;
296 token
->keyword
= rid_code
;
299 /* Else, "pq" keywords outside of the "pq" context are
300 not keywords, and we fall through to the code for
303 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
305 /* We found an Objective-C "property attribute"
306 keyword (getter, setter, readonly, etc). These are
307 only valid in the property context. */
308 if (parser
->objc_property_attr_context
)
310 token
->type
= CPP_KEYWORD
;
311 token
->keyword
= rid_code
;
314 /* Else they are not special keywords.
317 else if (c_dialect_objc ()
318 && (OBJC_IS_AT_KEYWORD (rid_code
)
319 || OBJC_IS_CXX_KEYWORD (rid_code
)))
321 /* We found one of the Objective-C "@" keywords (defs,
322 selector, synchronized, etc) or one of the
323 Objective-C "cxx" keywords (class, private,
324 protected, public, try, catch, throw) without a
325 preceding '@' sign. Do nothing and fall through to
326 the code for normal tokens (in C++ we would still
327 consider the CXX ones keywords, but not in C). */
332 token
->type
= CPP_KEYWORD
;
333 token
->keyword
= rid_code
;
338 decl
= lookup_name (token
->value
);
341 if (TREE_CODE (decl
) == TYPE_DECL
)
343 token
->id_kind
= C_ID_TYPENAME
;
347 else if (c_dialect_objc ())
349 tree objc_interface_decl
= objc_is_class_name (token
->value
);
350 /* Objective-C class names are in the same namespace as
351 variables and typedefs, and hence are shadowed by local
353 if (objc_interface_decl
354 && (!objc_force_identifier
|| global_bindings_p ()))
356 token
->value
= objc_interface_decl
;
357 token
->id_kind
= C_ID_CLASSNAME
;
361 token
->id_kind
= C_ID_ID
;
365 /* This only happens in Objective-C; it must be a keyword. */
366 token
->type
= CPP_KEYWORD
;
367 switch (C_RID_CODE (token
->value
))
369 /* Replace 'class' with '@class', 'private' with '@private',
370 etc. This prevents confusion with the C++ keyword
371 'class', and makes the tokens consistent with other
372 Objective-C 'AT' keywords. For example '@class' is
373 reported as RID_AT_CLASS which is consistent with
374 '@synchronized', which is reported as
377 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
378 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
379 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
380 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
381 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
382 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
383 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
384 default: token
->keyword
= C_RID_CODE (token
->value
);
389 case CPP_CLOSE_PAREN
:
391 /* These tokens may affect the interpretation of any identifiers
392 following, if doing Objective-C. */
393 if (c_dialect_objc ())
394 parser
->objc_need_raw_identifier
= false;
397 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
398 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
404 timevar_pop (TV_LEX
);
407 /* Return a pointer to the next token from PARSER, reading it in if
410 static inline c_token
*
411 c_parser_peek_token (c_parser
*parser
)
413 if (parser
->tokens_avail
== 0)
415 c_lex_one_token (parser
, &parser
->tokens
[0]);
416 parser
->tokens_avail
= 1;
418 return &parser
->tokens
[0];
421 /* Return true if the next token from PARSER has the indicated
425 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
427 return c_parser_peek_token (parser
)->type
== type
;
430 /* Return true if the next token from PARSER does not have the
434 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
436 return !c_parser_next_token_is (parser
, type
);
439 /* Return true if the next token from PARSER is the indicated
443 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
445 return c_parser_peek_token (parser
)->keyword
== keyword
;
448 /* Return a pointer to the next-but-one token from PARSER, reading it
449 in if necessary. The next token is already read in. */
452 c_parser_peek_2nd_token (c_parser
*parser
)
454 if (parser
->tokens_avail
>= 2)
455 return &parser
->tokens
[1];
456 gcc_assert (parser
->tokens_avail
== 1);
457 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
458 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
459 c_lex_one_token (parser
, &parser
->tokens
[1]);
460 parser
->tokens_avail
= 2;
461 return &parser
->tokens
[1];
464 /* Return true if TOKEN can start a type name,
467 c_token_starts_typename (c_token
*token
)
472 switch (token
->id_kind
)
481 gcc_assert (c_dialect_objc ());
487 switch (token
->keyword
)
522 if (c_dialect_objc ())
530 enum c_lookahead_kind
{
531 /* Always treat unknown identifiers as typenames. */
534 /* Could be parsing a nonabstract declarator. Only treat an identifier
535 as a typename if followed by another identifier or a star. */
536 cla_nonabstract_decl
,
538 /* Never treat identifiers as typenames. */
542 /* Return true if the next token from PARSER can start a type name,
543 false otherwise. LA specifies how to do lookahead in order to
544 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
547 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
549 c_token
*token
= c_parser_peek_token (parser
);
550 if (c_token_starts_typename (token
))
553 /* Try a bit harder to detect an unknown typename. */
554 if (la
!= cla_prefer_id
555 && token
->type
== CPP_NAME
556 && token
->id_kind
== C_ID_ID
558 /* Do not try too hard when we could have "object in array". */
559 && !parser
->objc_could_be_foreach_context
561 && (la
== cla_prefer_type
562 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
563 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
565 /* Only unknown identifiers. */
566 && !lookup_name (token
->value
))
572 /* Return true if TOKEN is a type qualifier, false otherwise. */
574 c_token_is_qualifier (c_token
*token
)
579 switch (token
->id_kind
)
587 switch (token
->keyword
)
605 /* Return true if the next token from PARSER is a type qualifier,
608 c_parser_next_token_is_qualifier (c_parser
*parser
)
610 c_token
*token
= c_parser_peek_token (parser
);
611 return c_token_is_qualifier (token
);
614 /* Return true if TOKEN can start declaration specifiers, false
617 c_token_starts_declspecs (c_token
*token
)
622 switch (token
->id_kind
)
631 gcc_assert (c_dialect_objc ());
637 switch (token
->keyword
)
681 if (c_dialect_objc ())
690 /* Return true if TOKEN can start declaration specifiers or a static
691 assertion, false otherwise. */
693 c_token_starts_declaration (c_token
*token
)
695 if (c_token_starts_declspecs (token
)
696 || token
->keyword
== RID_STATIC_ASSERT
)
702 /* Return true if the next token from PARSER can start declaration
703 specifiers, false otherwise. */
705 c_parser_next_token_starts_declspecs (c_parser
*parser
)
707 c_token
*token
= c_parser_peek_token (parser
);
709 /* In Objective-C, a classname normally starts a declspecs unless it
710 is immediately followed by a dot. In that case, it is the
711 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
712 setter/getter on the class. c_token_starts_declspecs() can't
713 differentiate between the two cases because it only checks the
714 current token, so we have a special check here. */
715 if (c_dialect_objc ()
716 && token
->type
== CPP_NAME
717 && token
->id_kind
== C_ID_CLASSNAME
718 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
721 return c_token_starts_declspecs (token
);
724 /* Return true if the next tokens from PARSER can start declaration
725 specifiers or a static assertion, false otherwise. */
727 c_parser_next_tokens_start_declaration (c_parser
*parser
)
729 c_token
*token
= c_parser_peek_token (parser
);
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 /* Labels do not start declarations. */
739 if (token
->type
== CPP_NAME
740 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
743 if (c_token_starts_declaration (token
))
746 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
752 /* Consume the next token from PARSER. */
755 c_parser_consume_token (c_parser
*parser
)
757 gcc_assert (parser
->tokens_avail
>= 1);
758 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
759 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
760 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
761 if (parser
->tokens
!= &parser
->tokens_buf
[0])
763 else if (parser
->tokens_avail
== 2)
764 parser
->tokens
[0] = parser
->tokens
[1];
765 parser
->tokens_avail
--;
768 /* Expect the current token to be a #pragma. Consume it and remember
769 that we've begun parsing a pragma. */
772 c_parser_consume_pragma (c_parser
*parser
)
774 gcc_assert (!parser
->in_pragma
);
775 gcc_assert (parser
->tokens_avail
>= 1);
776 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
777 if (parser
->tokens
!= &parser
->tokens_buf
[0])
779 else if (parser
->tokens_avail
== 2)
780 parser
->tokens
[0] = parser
->tokens
[1];
781 parser
->tokens_avail
--;
782 parser
->in_pragma
= true;
785 /* Update the global input_location from TOKEN. */
787 c_parser_set_source_position_from_token (c_token
*token
)
789 if (token
->type
!= CPP_EOF
)
791 input_location
= token
->location
;
795 /* Issue a diagnostic of the form
796 FILE:LINE: MESSAGE before TOKEN
797 where TOKEN is the next token in the input stream of PARSER.
798 MESSAGE (specified by the caller) is usually of the form "expected
801 Do not issue a diagnostic if still recovering from an error.
803 ??? This is taken from the C++ parser, but building up messages in
804 this way is not i18n-friendly and some other approach should be
808 c_parser_error (c_parser
*parser
, const char *gmsgid
)
810 c_token
*token
= c_parser_peek_token (parser
);
813 parser
->error
= true;
816 /* This diagnostic makes more sense if it is tagged to the line of
817 the token we just peeked at. */
818 c_parser_set_source_position_from_token (token
);
819 c_parse_error (gmsgid
,
820 /* Because c_parse_error does not understand
821 CPP_KEYWORD, keywords are treated like
823 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
824 /* ??? The C parser does not save the cpp flags of a
825 token, we need to pass 0 here and we will not get
826 the source spelling of some tokens but rather the
827 canonical spelling. */
828 token
->value
, /*flags=*/0);
831 /* If the next token is of the indicated TYPE, consume it. Otherwise,
832 issue the error MSGID. If MSGID is NULL then a message has already
833 been produced and no message will be produced this time. Returns
834 true if found, false otherwise. */
837 c_parser_require (c_parser
*parser
,
841 if (c_parser_next_token_is (parser
, type
))
843 c_parser_consume_token (parser
);
848 c_parser_error (parser
, msgid
);
853 /* If the next token is the indicated keyword, consume it. Otherwise,
854 issue the error MSGID. Returns true if found, false otherwise. */
857 c_parser_require_keyword (c_parser
*parser
,
861 if (c_parser_next_token_is_keyword (parser
, keyword
))
863 c_parser_consume_token (parser
);
868 c_parser_error (parser
, msgid
);
873 /* Like c_parser_require, except that tokens will be skipped until the
874 desired token is found. An error message is still produced if the
875 next token is not as expected. If MSGID is NULL then a message has
876 already been produced and no message will be produced this
880 c_parser_skip_until_found (c_parser
*parser
,
884 unsigned nesting_depth
= 0;
886 if (c_parser_require (parser
, type
, msgid
))
889 /* Skip tokens until the desired token is found. */
892 /* Peek at the next token. */
893 c_token
*token
= c_parser_peek_token (parser
);
894 /* If we've reached the token we want, consume it and stop. */
895 if (token
->type
== type
&& !nesting_depth
)
897 c_parser_consume_token (parser
);
901 /* If we've run out of tokens, stop. */
902 if (token
->type
== CPP_EOF
)
904 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
906 if (token
->type
== CPP_OPEN_BRACE
907 || token
->type
== CPP_OPEN_PAREN
908 || token
->type
== CPP_OPEN_SQUARE
)
910 else if (token
->type
== CPP_CLOSE_BRACE
911 || token
->type
== CPP_CLOSE_PAREN
912 || token
->type
== CPP_CLOSE_SQUARE
)
914 if (nesting_depth
-- == 0)
917 /* Consume this token. */
918 c_parser_consume_token (parser
);
920 parser
->error
= false;
923 /* Skip tokens until the end of a parameter is found, but do not
924 consume the comma, semicolon or closing delimiter. */
927 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
929 unsigned nesting_depth
= 0;
933 c_token
*token
= c_parser_peek_token (parser
);
934 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
937 /* If we've run out of tokens, stop. */
938 if (token
->type
== CPP_EOF
)
940 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
942 if (token
->type
== CPP_OPEN_BRACE
943 || token
->type
== CPP_OPEN_PAREN
944 || token
->type
== CPP_OPEN_SQUARE
)
946 else if (token
->type
== CPP_CLOSE_BRACE
947 || token
->type
== CPP_CLOSE_PAREN
948 || token
->type
== CPP_CLOSE_SQUARE
)
950 if (nesting_depth
-- == 0)
953 /* Consume this token. */
954 c_parser_consume_token (parser
);
956 parser
->error
= false;
959 /* Expect to be at the end of the pragma directive and consume an
960 end of line marker. */
963 c_parser_skip_to_pragma_eol (c_parser
*parser
)
965 gcc_assert (parser
->in_pragma
);
966 parser
->in_pragma
= false;
968 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
971 c_token
*token
= c_parser_peek_token (parser
);
972 if (token
->type
== CPP_EOF
)
974 if (token
->type
== CPP_PRAGMA_EOL
)
976 c_parser_consume_token (parser
);
979 c_parser_consume_token (parser
);
982 parser
->error
= false;
985 /* Skip tokens until we have consumed an entire block, or until we
986 have consumed a non-nested ';'. */
989 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
991 unsigned nesting_depth
= 0;
992 bool save_error
= parser
->error
;
998 /* Peek at the next token. */
999 token
= c_parser_peek_token (parser
);
1001 switch (token
->type
)
1006 case CPP_PRAGMA_EOL
:
1007 if (parser
->in_pragma
)
1012 /* If the next token is a ';', we have reached the
1013 end of the statement. */
1016 /* Consume the ';'. */
1017 c_parser_consume_token (parser
);
1022 case CPP_CLOSE_BRACE
:
1023 /* If the next token is a non-nested '}', then we have
1024 reached the end of the current block. */
1025 if (nesting_depth
== 0 || --nesting_depth
== 0)
1027 c_parser_consume_token (parser
);
1032 case CPP_OPEN_BRACE
:
1033 /* If it the next token is a '{', then we are entering a new
1034 block. Consume the entire block. */
1039 /* If we see a pragma, consume the whole thing at once. We
1040 have some safeguards against consuming pragmas willy-nilly.
1041 Normally, we'd expect to be here with parser->error set,
1042 which disables these safeguards. But it's possible to get
1043 here for secondary error recovery, after parser->error has
1045 c_parser_consume_pragma (parser
);
1046 c_parser_skip_to_pragma_eol (parser
);
1047 parser
->error
= save_error
;
1054 c_parser_consume_token (parser
);
1058 parser
->error
= false;
1061 /* CPP's options (initialized by c-opts.c). */
1062 extern cpp_options
*cpp_opts
;
1064 /* Save the warning flags which are controlled by __extension__. */
1067 disable_extension_diagnostics (void)
1070 | (warn_pointer_arith
<< 1)
1071 | (warn_traditional
<< 2)
1073 | (warn_long_long
<< 4)
1074 | (warn_cxx_compat
<< 5)
1075 | (warn_overlength_strings
<< 6)
1076 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1077 play tricks to properly restore it. */
1078 | ((warn_c90_c99_compat
== 1) << 7)
1079 | ((warn_c90_c99_compat
== -1) << 8)
1080 /* Similarly for warn_c99_c11_compat. */
1081 | ((warn_c99_c11_compat
== 1) << 9)
1082 | ((warn_c99_c11_compat
== -1) << 10)
1084 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1085 warn_pointer_arith
= 0;
1086 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1088 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1089 warn_cxx_compat
= 0;
1090 warn_overlength_strings
= 0;
1091 warn_c90_c99_compat
= 0;
1092 warn_c99_c11_compat
= 0;
1096 /* Restore the warning flags which are controlled by __extension__.
1097 FLAGS is the return value from disable_extension_diagnostics. */
1100 restore_extension_diagnostics (int flags
)
1102 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1103 warn_pointer_arith
= (flags
>> 1) & 1;
1104 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1105 flag_iso
= (flags
>> 3) & 1;
1106 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1107 warn_cxx_compat
= (flags
>> 5) & 1;
1108 warn_overlength_strings
= (flags
>> 6) & 1;
1109 /* See above for why is this needed. */
1110 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1111 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1114 /* Possibly kinds of declarator to parse. */
1115 typedef enum c_dtr_syn
{
1116 /* A normal declarator with an identifier. */
1118 /* An abstract declarator (maybe empty). */
1120 /* A parameter declarator: may be either, but after a type name does
1121 not redeclare a typedef name as an identifier if it can
1122 alternatively be interpreted as a typedef name; see DR#009,
1123 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1124 following DR#249. For example, given a typedef T, "int T" and
1125 "int *T" are valid parameter declarations redeclaring T, while
1126 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1127 abstract declarators rather than involving redundant parentheses;
1128 the same applies with attributes inside the parentheses before
1133 /* The binary operation precedence levels, where 0 is a dummy lowest level
1134 used for the bottom of the stack. */
1135 enum c_parser_prec
{
1150 static void c_parser_external_declaration (c_parser
*);
1151 static void c_parser_asm_definition (c_parser
*);
1152 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1153 bool, bool, tree
*, vec
<c_token
>);
1154 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1155 static void c_parser_static_assert_declaration (c_parser
*);
1156 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1157 bool, bool, bool, enum c_lookahead_kind
);
1158 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1159 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1160 static tree
c_parser_struct_declaration (c_parser
*);
1161 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1162 static tree
c_parser_alignas_specifier (c_parser
*);
1163 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1165 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1167 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1169 struct c_declarator
*);
1170 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1171 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1173 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1174 static tree
c_parser_simple_asm_expr (c_parser
*);
1175 static tree
c_parser_attributes (c_parser
*);
1176 static struct c_type_name
*c_parser_type_name (c_parser
*);
1177 static struct c_expr
c_parser_initializer (c_parser
*);
1178 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1179 static void c_parser_initelt (c_parser
*, struct obstack
*);
1180 static void c_parser_initval (c_parser
*, struct c_expr
*,
1182 static tree
c_parser_compound_statement (c_parser
*);
1183 static void c_parser_compound_statement_nostart (c_parser
*);
1184 static void c_parser_label (c_parser
*);
1185 static void c_parser_statement (c_parser
*);
1186 static void c_parser_statement_after_labels (c_parser
*);
1187 static void c_parser_if_statement (c_parser
*);
1188 static void c_parser_switch_statement (c_parser
*);
1189 static void c_parser_while_statement (c_parser
*, bool);
1190 static void c_parser_do_statement (c_parser
*, bool);
1191 static void c_parser_for_statement (c_parser
*, bool);
1192 static tree
c_parser_asm_statement (c_parser
*);
1193 static tree
c_parser_asm_operands (c_parser
*);
1194 static tree
c_parser_asm_goto_operands (c_parser
*);
1195 static tree
c_parser_asm_clobbers (c_parser
*);
1196 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1198 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1199 struct c_expr
*, tree
);
1200 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1202 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1203 static struct c_expr
c_parser_unary_expression (c_parser
*);
1204 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1205 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1206 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1207 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1208 struct c_type_name
*,
1210 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1213 static tree
c_parser_transaction (c_parser
*, enum rid
);
1214 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1215 static tree
c_parser_transaction_cancel (c_parser
*);
1216 static struct c_expr
c_parser_expression (c_parser
*);
1217 static struct c_expr
c_parser_expression_conv (c_parser
*);
1218 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1219 vec
<tree
, va_gc
> **, location_t
*,
1220 tree
*, vec
<location_t
> *,
1221 unsigned int * = NULL
);
1222 static void c_parser_omp_construct (c_parser
*);
1223 static void c_parser_omp_threadprivate (c_parser
*);
1224 static void c_parser_omp_barrier (c_parser
*);
1225 static void c_parser_omp_flush (c_parser
*);
1226 static void c_parser_omp_taskwait (c_parser
*);
1227 static void c_parser_omp_taskyield (c_parser
*);
1228 static void c_parser_omp_cancel (c_parser
*);
1229 static void c_parser_omp_cancellation_point (c_parser
*);
1231 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1232 pragma_stmt
, pragma_compound
};
1233 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1234 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1235 static void c_parser_omp_end_declare_target (c_parser
*);
1236 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1238 /* These Objective-C parser functions are only ever called when
1239 compiling Objective-C. */
1240 static void c_parser_objc_class_definition (c_parser
*, tree
);
1241 static void c_parser_objc_class_instance_variables (c_parser
*);
1242 static void c_parser_objc_class_declaration (c_parser
*);
1243 static void c_parser_objc_alias_declaration (c_parser
*);
1244 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1245 static bool c_parser_objc_method_type (c_parser
*);
1246 static void c_parser_objc_method_definition (c_parser
*);
1247 static void c_parser_objc_methodprotolist (c_parser
*);
1248 static void c_parser_objc_methodproto (c_parser
*);
1249 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1250 static tree
c_parser_objc_type_name (c_parser
*);
1251 static tree
c_parser_objc_protocol_refs (c_parser
*);
1252 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1253 static void c_parser_objc_synchronized_statement (c_parser
*);
1254 static tree
c_parser_objc_selector (c_parser
*);
1255 static tree
c_parser_objc_selector_arg (c_parser
*);
1256 static tree
c_parser_objc_receiver (c_parser
*);
1257 static tree
c_parser_objc_message_args (c_parser
*);
1258 static tree
c_parser_objc_keywordexpr (c_parser
*);
1259 static void c_parser_objc_at_property_declaration (c_parser
*);
1260 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1261 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1262 static bool c_parser_objc_diagnose_bad_element_prefix
1263 (c_parser
*, struct c_declspecs
*);
1265 /* Cilk Plus supporting routines. */
1266 static void c_parser_cilk_simd (c_parser
*);
1267 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1268 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1269 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1271 /* Parse a translation unit (C90 6.7, C99 6.9).
1274 external-declarations
1276 external-declarations:
1277 external-declaration
1278 external-declarations external-declaration
1287 c_parser_translation_unit (c_parser
*parser
)
1289 if (c_parser_next_token_is (parser
, CPP_EOF
))
1291 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1292 "ISO C forbids an empty translation unit");
1296 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1297 mark_valid_location_for_stdc_pragma (false);
1301 c_parser_external_declaration (parser
);
1302 obstack_free (&parser_obstack
, obstack_position
);
1304 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1308 /* Parse an external declaration (C90 6.7, C99 6.9).
1310 external-declaration:
1316 external-declaration:
1319 __extension__ external-declaration
1323 external-declaration:
1324 objc-class-definition
1325 objc-class-declaration
1326 objc-alias-declaration
1327 objc-protocol-definition
1328 objc-method-definition
1333 c_parser_external_declaration (c_parser
*parser
)
1336 switch (c_parser_peek_token (parser
)->type
)
1339 switch (c_parser_peek_token (parser
)->keyword
)
1342 ext
= disable_extension_diagnostics ();
1343 c_parser_consume_token (parser
);
1344 c_parser_external_declaration (parser
);
1345 restore_extension_diagnostics (ext
);
1348 c_parser_asm_definition (parser
);
1350 case RID_AT_INTERFACE
:
1351 case RID_AT_IMPLEMENTATION
:
1352 gcc_assert (c_dialect_objc ());
1353 c_parser_objc_class_definition (parser
, NULL_TREE
);
1356 gcc_assert (c_dialect_objc ());
1357 c_parser_objc_class_declaration (parser
);
1360 gcc_assert (c_dialect_objc ());
1361 c_parser_objc_alias_declaration (parser
);
1363 case RID_AT_PROTOCOL
:
1364 gcc_assert (c_dialect_objc ());
1365 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1367 case RID_AT_PROPERTY
:
1368 gcc_assert (c_dialect_objc ());
1369 c_parser_objc_at_property_declaration (parser
);
1371 case RID_AT_SYNTHESIZE
:
1372 gcc_assert (c_dialect_objc ());
1373 c_parser_objc_at_synthesize_declaration (parser
);
1375 case RID_AT_DYNAMIC
:
1376 gcc_assert (c_dialect_objc ());
1377 c_parser_objc_at_dynamic_declaration (parser
);
1380 gcc_assert (c_dialect_objc ());
1381 c_parser_consume_token (parser
);
1382 objc_finish_implementation ();
1389 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1390 "ISO C does not allow extra %<;%> outside of a function");
1391 c_parser_consume_token (parser
);
1394 mark_valid_location_for_stdc_pragma (true);
1395 c_parser_pragma (parser
, pragma_external
);
1396 mark_valid_location_for_stdc_pragma (false);
1400 if (c_dialect_objc ())
1402 c_parser_objc_method_definition (parser
);
1405 /* Else fall through, and yield a syntax error trying to parse
1406 as a declaration or function definition. */
1409 /* A declaration or a function definition (or, in Objective-C,
1410 an @interface or @protocol with prefix attributes). We can
1411 only tell which after parsing the declaration specifiers, if
1412 any, and the first declarator. */
1413 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1419 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1421 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1422 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1423 accepted; otherwise (old-style parameter declarations) only other
1424 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1425 assertion is accepted; otherwise (old-style parameter declarations)
1426 it is not. If NESTED is true, we are inside a function or parsing
1427 old-style parameter declarations; any functions encountered are
1428 nested functions and declaration specifiers are required; otherwise
1429 we are at top level and functions are normal functions and
1430 declaration specifiers may be optional. If EMPTY_OK is true, empty
1431 declarations are OK (subject to all other constraints); otherwise
1432 (old-style parameter declarations) they are diagnosed. If
1433 START_ATTR_OK is true, the declaration specifiers may start with
1434 attributes; otherwise they may not.
1435 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1436 declaration when parsing an Objective-C foreach statement.
1439 declaration-specifiers init-declarator-list[opt] ;
1440 static_assert-declaration
1442 function-definition:
1443 declaration-specifiers[opt] declarator declaration-list[opt]
1448 declaration-list declaration
1450 init-declarator-list:
1452 init-declarator-list , init-declarator
1455 declarator simple-asm-expr[opt] attributes[opt]
1456 declarator simple-asm-expr[opt] attributes[opt] = initializer
1460 nested-function-definition:
1461 declaration-specifiers declarator declaration-list[opt]
1465 attributes objc-class-definition
1466 attributes objc-category-definition
1467 attributes objc-protocol-definition
1469 The simple-asm-expr and attributes are GNU extensions.
1471 This function does not handle __extension__; that is handled in its
1472 callers. ??? Following the old parser, __extension__ may start
1473 external declarations, declarations in functions and declarations
1474 at the start of "for" loops, but not old-style parameter
1477 C99 requires declaration specifiers in a function definition; the
1478 absence is diagnosed through the diagnosis of implicit int. In GNU
1479 C we also allow but diagnose declarations without declaration
1480 specifiers, but only at top level (elsewhere they conflict with
1483 In Objective-C, declarations of the looping variable in a foreach
1484 statement are exceptionally terminated by 'in' (for example, 'for
1485 (NSObject *object in array) { ... }').
1490 threadprivate-directive */
1493 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1494 bool static_assert_ok
, bool empty_ok
,
1495 bool nested
, bool start_attr_ok
,
1496 tree
*objc_foreach_object_declaration
,
1497 vec
<c_token
> omp_declare_simd_clauses
)
1499 struct c_declspecs
*specs
;
1501 tree all_prefix_attrs
;
1502 bool diagnosed_no_specs
= false;
1503 location_t here
= c_parser_peek_token (parser
)->location
;
1505 if (static_assert_ok
1506 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1508 c_parser_static_assert_declaration (parser
);
1511 specs
= build_null_declspecs ();
1513 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1514 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1515 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1516 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1517 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1518 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1520 error_at (here
, "unknown type name %qE",
1521 c_parser_peek_token (parser
)->value
);
1523 /* Parse declspecs normally to get a correct pointer type, but avoid
1524 a further "fails to be a type name" error. Refuse nested functions
1525 since it is not how the user likely wants us to recover. */
1526 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1527 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1528 c_parser_peek_token (parser
)->value
= error_mark_node
;
1532 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1533 true, true, cla_nonabstract_decl
);
1536 c_parser_skip_to_end_of_block_or_statement (parser
);
1539 if (nested
&& !specs
->declspecs_seen_p
)
1541 c_parser_error (parser
, "expected declaration specifiers");
1542 c_parser_skip_to_end_of_block_or_statement (parser
);
1545 finish_declspecs (specs
);
1546 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1547 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1550 error_at (here
, "%<__auto_type%> in empty declaration");
1555 shadow_tag_warned (specs
, 1);
1556 pedwarn (here
, 0, "empty declaration");
1558 c_parser_consume_token (parser
);
1562 /* Provide better error recovery. Note that a type name here is usually
1563 better diagnosed as a redeclaration. */
1565 && specs
->typespec_kind
== ctsk_tagdef
1566 && c_parser_next_token_starts_declspecs (parser
)
1567 && !c_parser_next_token_is (parser
, CPP_NAME
))
1569 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1570 parser
->error
= false;
1571 shadow_tag_warned (specs
, 1);
1574 else if (c_dialect_objc () && !auto_type_p
)
1576 /* Prefix attributes are an error on method decls. */
1577 switch (c_parser_peek_token (parser
)->type
)
1581 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1585 warning_at (c_parser_peek_token (parser
)->location
,
1587 "prefix attributes are ignored for methods");
1588 specs
->attrs
= NULL_TREE
;
1591 c_parser_objc_method_definition (parser
);
1593 c_parser_objc_methodproto (parser
);
1599 /* This is where we parse 'attributes @interface ...',
1600 'attributes @implementation ...', 'attributes @protocol ...'
1601 (where attributes could be, for example, __attribute__
1604 switch (c_parser_peek_token (parser
)->keyword
)
1606 case RID_AT_INTERFACE
:
1608 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1610 c_parser_objc_class_definition (parser
, specs
->attrs
);
1614 case RID_AT_IMPLEMENTATION
:
1616 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1620 warning_at (c_parser_peek_token (parser
)->location
,
1622 "prefix attributes are ignored for implementations");
1623 specs
->attrs
= NULL_TREE
;
1625 c_parser_objc_class_definition (parser
, NULL_TREE
);
1629 case RID_AT_PROTOCOL
:
1631 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1633 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1640 case RID_AT_PROPERTY
:
1643 c_parser_error (parser
, "unexpected attribute");
1644 specs
->attrs
= NULL
;
1652 pending_xref_error ();
1653 prefix_attrs
= specs
->attrs
;
1654 all_prefix_attrs
= prefix_attrs
;
1655 specs
->attrs
= NULL_TREE
;
1658 struct c_declarator
*declarator
;
1662 /* Declaring either one or more declarators (in which case we
1663 should diagnose if there were no declaration specifiers) or a
1664 function definition (in which case the diagnostic for
1665 implicit int suffices). */
1666 declarator
= c_parser_declarator (parser
,
1667 specs
->typespec_kind
!= ctsk_none
,
1668 C_DTR_NORMAL
, &dummy
);
1669 if (declarator
== NULL
)
1671 if (omp_declare_simd_clauses
.exists ()
1672 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1673 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1674 omp_declare_simd_clauses
);
1675 c_parser_skip_to_end_of_block_or_statement (parser
);
1678 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1681 "%<__auto_type%> requires a plain identifier"
1683 c_parser_skip_to_end_of_block_or_statement (parser
);
1686 if (c_parser_next_token_is (parser
, CPP_EQ
)
1687 || c_parser_next_token_is (parser
, CPP_COMMA
)
1688 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1689 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1690 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1691 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1693 tree asm_name
= NULL_TREE
;
1694 tree postfix_attrs
= NULL_TREE
;
1695 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1697 diagnosed_no_specs
= true;
1698 pedwarn (here
, 0, "data definition has no type or storage class");
1700 /* Having seen a data definition, there cannot now be a
1701 function definition. */
1703 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1704 asm_name
= c_parser_simple_asm_expr (parser
);
1705 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1707 postfix_attrs
= c_parser_attributes (parser
);
1708 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1710 /* This means there is an attribute specifier after
1711 the declarator in a function definition. Provide
1712 some more information for the user. */
1713 error_at (here
, "attributes should be specified before the "
1714 "declarator in a function definition");
1715 c_parser_skip_to_end_of_block_or_statement (parser
);
1719 if (c_parser_next_token_is (parser
, CPP_EQ
))
1723 location_t init_loc
;
1724 c_parser_consume_token (parser
);
1727 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1728 init_loc
= c_parser_peek_token (parser
)->location
;
1729 init
= c_parser_expr_no_commas (parser
, NULL
);
1730 if (TREE_CODE (init
.value
) == COMPONENT_REF
1731 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1733 "%<__auto_type%> used with a bit-field"
1735 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1736 tree init_type
= TREE_TYPE (init
.value
);
1737 /* As with typeof, remove all qualifiers from atomic types. */
1738 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1740 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1741 bool vm_type
= variably_modified_type_p (init_type
,
1744 init
.value
= c_save_expr (init
.value
);
1746 specs
->typespec_kind
= ctsk_typeof
;
1747 specs
->locations
[cdw_typedef
] = init_loc
;
1748 specs
->typedef_p
= true;
1749 specs
->type
= init_type
;
1752 bool maybe_const
= true;
1753 tree type_expr
= c_fully_fold (init
.value
, false,
1755 specs
->expr_const_operands
&= maybe_const
;
1757 specs
->expr
= build2 (COMPOUND_EXPR
,
1758 TREE_TYPE (type_expr
),
1759 specs
->expr
, type_expr
);
1761 specs
->expr
= type_expr
;
1763 d
= start_decl (declarator
, specs
, true,
1764 chainon (postfix_attrs
, all_prefix_attrs
));
1766 d
= error_mark_node
;
1767 if (omp_declare_simd_clauses
.exists ()
1768 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1769 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1770 omp_declare_simd_clauses
);
1774 /* The declaration of the variable is in effect while
1775 its initializer is parsed. */
1776 d
= start_decl (declarator
, specs
, true,
1777 chainon (postfix_attrs
, all_prefix_attrs
));
1779 d
= error_mark_node
;
1780 if (omp_declare_simd_clauses
.exists ()
1781 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1782 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1783 omp_declare_simd_clauses
);
1784 start_init (d
, asm_name
, global_bindings_p ());
1785 init_loc
= c_parser_peek_token (parser
)->location
;
1786 init
= c_parser_initializer (parser
);
1789 if (d
!= error_mark_node
)
1791 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1792 finish_decl (d
, init_loc
, init
.value
,
1793 init
.original_type
, asm_name
);
1801 "%<__auto_type%> requires an initialized "
1802 "data declaration");
1803 c_parser_skip_to_end_of_block_or_statement (parser
);
1806 tree d
= start_decl (declarator
, specs
, false,
1807 chainon (postfix_attrs
,
1809 if (omp_declare_simd_clauses
.exists ()
1810 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1812 tree parms
= NULL_TREE
;
1813 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1815 struct c_declarator
*ce
= declarator
;
1817 if (ce
->kind
== cdk_function
)
1819 parms
= ce
->u
.arg_info
->parms
;
1823 ce
= ce
->declarator
;
1826 temp_store_parm_decls (d
, parms
);
1827 c_finish_omp_declare_simd (parser
, d
, parms
,
1828 omp_declare_simd_clauses
);
1830 temp_pop_parm_decls ();
1833 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1834 NULL_TREE
, asm_name
);
1836 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1839 *objc_foreach_object_declaration
= d
;
1841 *objc_foreach_object_declaration
= error_mark_node
;
1844 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1849 "%<__auto_type%> may only be used with"
1850 " a single declarator");
1851 c_parser_skip_to_end_of_block_or_statement (parser
);
1854 c_parser_consume_token (parser
);
1855 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1856 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1859 all_prefix_attrs
= prefix_attrs
;
1862 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1864 c_parser_consume_token (parser
);
1867 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1869 /* This can only happen in Objective-C: we found the
1870 'in' that terminates the declaration inside an
1871 Objective-C foreach statement. Do not consume the
1872 token, so that the caller can use it to determine
1873 that this indeed is a foreach context. */
1878 c_parser_error (parser
, "expected %<,%> or %<;%>");
1879 c_parser_skip_to_end_of_block_or_statement (parser
);
1883 else if (auto_type_p
)
1886 "%<__auto_type%> requires an initialized data declaration");
1887 c_parser_skip_to_end_of_block_or_statement (parser
);
1892 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1893 "%<asm%> or %<__attribute__%>");
1894 c_parser_skip_to_end_of_block_or_statement (parser
);
1897 /* Function definition (nested or otherwise). */
1900 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1901 c_push_function_context ();
1903 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1905 /* This can appear in many cases looking nothing like a
1906 function definition, so we don't give a more specific
1907 error suggesting there was one. */
1908 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1909 "or %<__attribute__%>");
1911 c_pop_function_context ();
1915 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1916 tv
= TV_PARSE_INLINE
;
1921 /* Parse old-style parameter declarations. ??? Attributes are
1922 not allowed to start declaration specifiers here because of a
1923 syntax conflict between a function declaration with attribute
1924 suffix and a function definition with an attribute prefix on
1925 first old-style parameter declaration. Following the old
1926 parser, they are not accepted on subsequent old-style
1927 parameter declarations either. However, there is no
1928 ambiguity after the first declaration, nor indeed on the
1929 first as long as we don't allow postfix attributes after a
1930 declarator with a nonempty identifier list in a definition;
1931 and postfix attributes have never been accepted here in
1932 function definitions either. */
1933 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1934 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1935 c_parser_declaration_or_fndef (parser
, false, false, false,
1936 true, false, NULL
, vNULL
);
1937 store_parm_decls ();
1938 if (omp_declare_simd_clauses
.exists ()
1939 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1940 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1941 omp_declare_simd_clauses
);
1942 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1943 = c_parser_peek_token (parser
)->location
;
1944 fnbody
= c_parser_compound_statement (parser
);
1945 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1946 fnbody
= expand_array_notation_exprs (fnbody
);
1949 tree decl
= current_function_decl
;
1950 /* Mark nested functions as needing static-chain initially.
1951 lower_nested_functions will recompute it but the
1952 DECL_STATIC_CHAIN flag is also used before that happens,
1953 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1954 DECL_STATIC_CHAIN (decl
) = 1;
1957 c_pop_function_context ();
1958 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1971 /* Parse an asm-definition (asm() outside a function body). This is a
1979 c_parser_asm_definition (c_parser
*parser
)
1981 tree asm_str
= c_parser_simple_asm_expr (parser
);
1983 symtab
->finalize_toplevel_asm (asm_str
);
1984 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1987 /* Parse a static assertion (C11 6.7.10).
1989 static_assert-declaration:
1990 static_assert-declaration-no-semi ;
1994 c_parser_static_assert_declaration (c_parser
*parser
)
1996 c_parser_static_assert_declaration_no_semi (parser
);
1998 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1999 c_parser_skip_to_end_of_block_or_statement (parser
);
2002 /* Parse a static assertion (C11 6.7.10), without the trailing
2005 static_assert-declaration-no-semi:
2006 _Static_assert ( constant-expression , string-literal )
2010 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2012 location_t assert_loc
, value_loc
;
2016 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2017 assert_loc
= c_parser_peek_token (parser
)->location
;
2019 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2020 "ISO C99 does not support %<_Static_assert%>");
2022 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2023 "ISO C90 does not support %<_Static_assert%>");
2024 c_parser_consume_token (parser
);
2025 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2027 value_loc
= c_parser_peek_token (parser
)->location
;
2028 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2029 parser
->lex_untranslated_string
= true;
2030 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2032 parser
->lex_untranslated_string
= false;
2035 switch (c_parser_peek_token (parser
)->type
)
2041 case CPP_UTF8STRING
:
2042 string
= c_parser_peek_token (parser
)->value
;
2043 c_parser_consume_token (parser
);
2044 parser
->lex_untranslated_string
= false;
2047 c_parser_error (parser
, "expected string literal");
2048 parser
->lex_untranslated_string
= false;
2051 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2053 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2055 error_at (value_loc
, "expression in static assertion is not an integer");
2058 if (TREE_CODE (value
) != INTEGER_CST
)
2060 value
= c_fully_fold (value
, false, NULL
);
2061 if (TREE_CODE (value
) == INTEGER_CST
)
2062 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2063 "is not an integer constant expression");
2065 if (TREE_CODE (value
) != INTEGER_CST
)
2067 error_at (value_loc
, "expression in static assertion is not constant");
2070 constant_expression_warning (value
);
2071 if (integer_zerop (value
))
2072 error_at (assert_loc
, "static assertion failed: %E", string
);
2075 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2076 6.7), adding them to SPECS (which may already include some).
2077 Storage class specifiers are accepted iff SCSPEC_OK; type
2078 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2079 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2080 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2082 declaration-specifiers:
2083 storage-class-specifier declaration-specifiers[opt]
2084 type-specifier declaration-specifiers[opt]
2085 type-qualifier declaration-specifiers[opt]
2086 function-specifier declaration-specifiers[opt]
2087 alignment-specifier declaration-specifiers[opt]
2089 Function specifiers (inline) are from C99, and are currently
2090 handled as storage class specifiers, as is __thread. Alignment
2091 specifiers are from C11.
2093 C90 6.5.1, C99 6.7.1:
2094 storage-class-specifier:
2102 (_Thread_local is new in C11.)
2109 (_Noreturn is new in C11.)
2111 C90 6.5.2, C99 6.7.2:
2124 [_Imaginary removed in C99 TC2]
2125 struct-or-union-specifier
2128 atomic-type-specifier
2130 (_Bool and _Complex are new in C99.)
2131 (atomic-type-specifier is new in C11.)
2133 C90 6.5.3, C99 6.7.3:
2139 address-space-qualifier
2142 (restrict is new in C99.)
2143 (_Atomic is new in C11.)
2147 declaration-specifiers:
2148 attributes declaration-specifiers[opt]
2154 identifier recognized by the target
2156 storage-class-specifier:
2170 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2171 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2173 atomic-type-specifier
2174 _Atomic ( type-name )
2179 class-name objc-protocol-refs[opt]
2180 typedef-name objc-protocol-refs
2185 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2186 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2187 bool alignspec_ok
, bool auto_type_ok
,
2188 enum c_lookahead_kind la
)
2190 bool attrs_ok
= start_attr_ok
;
2191 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2194 gcc_assert (la
== cla_prefer_id
);
2196 while (c_parser_next_token_is (parser
, CPP_NAME
)
2197 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2198 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2200 struct c_typespec t
;
2203 location_t loc
= c_parser_peek_token (parser
)->location
;
2205 /* If we cannot accept a type, exit if the next token must start
2206 one. Also, if we already have seen a tagged definition,
2207 a typename would be an error anyway and likely the user
2208 has simply forgotten a semicolon, so we exit. */
2209 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2210 && c_parser_next_tokens_start_typename (parser
, la
)
2211 && !c_parser_next_token_is_qualifier (parser
))
2214 if (c_parser_next_token_is (parser
, CPP_NAME
))
2216 c_token
*name_token
= c_parser_peek_token (parser
);
2217 tree value
= name_token
->value
;
2218 c_id_kind kind
= name_token
->id_kind
;
2220 if (kind
== C_ID_ADDRSPACE
)
2223 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2224 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2225 c_parser_consume_token (parser
);
2230 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2232 /* If we cannot accept a type, and the next token must start one,
2233 exit. Do the same if we already have seen a tagged definition,
2234 since it would be an error anyway and likely the user has simply
2235 forgotten a semicolon. */
2236 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2239 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2240 a C_ID_CLASSNAME. */
2241 c_parser_consume_token (parser
);
2244 if (kind
== C_ID_ID
)
2246 error_at (loc
, "unknown type name %qE", value
);
2247 t
.kind
= ctsk_typedef
;
2248 t
.spec
= error_mark_node
;
2250 else if (kind
== C_ID_TYPENAME
2251 && (!c_dialect_objc ()
2252 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2254 t
.kind
= ctsk_typedef
;
2255 /* For a typedef name, record the meaning, not the name.
2256 In case of 'foo foo, bar;'. */
2257 t
.spec
= lookup_name (value
);
2261 tree proto
= NULL_TREE
;
2262 gcc_assert (c_dialect_objc ());
2264 if (c_parser_next_token_is (parser
, CPP_LESS
))
2265 proto
= c_parser_objc_protocol_refs (parser
);
2266 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2269 t
.expr_const_operands
= true;
2270 declspecs_add_type (name_token
->location
, specs
, t
);
2273 if (c_parser_next_token_is (parser
, CPP_LESS
))
2275 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2276 nisse@lysator.liu.se. */
2278 gcc_assert (c_dialect_objc ());
2279 if (!typespec_ok
|| seen_type
)
2281 proto
= c_parser_objc_protocol_refs (parser
);
2283 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2285 t
.expr_const_operands
= true;
2286 declspecs_add_type (loc
, specs
, t
);
2289 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2290 switch (c_parser_peek_token (parser
)->keyword
)
2303 /* TODO: Distinguish between function specifiers (inline, noreturn)
2304 and storage class specifiers, either here or in
2305 declspecs_add_scspec. */
2306 declspecs_add_scspec (loc
, specs
,
2307 c_parser_peek_token (parser
)->value
);
2308 c_parser_consume_token (parser
);
2336 if (c_dialect_objc ())
2337 parser
->objc_need_raw_identifier
= true;
2338 t
.kind
= ctsk_resword
;
2339 t
.spec
= c_parser_peek_token (parser
)->value
;
2341 t
.expr_const_operands
= true;
2342 declspecs_add_type (loc
, specs
, t
);
2343 c_parser_consume_token (parser
);
2350 t
= c_parser_enum_specifier (parser
);
2351 declspecs_add_type (loc
, specs
, t
);
2359 t
= c_parser_struct_or_union_specifier (parser
);
2360 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2361 declspecs_add_type (loc
, specs
, t
);
2364 /* ??? The old parser rejected typeof after other type
2365 specifiers, but is a syntax error the best way of
2367 if (!typespec_ok
|| seen_type
)
2371 t
= c_parser_typeof_specifier (parser
);
2372 declspecs_add_type (loc
, specs
, t
);
2375 /* C parser handling of Objective-C constructs needs
2376 checking for correct lvalue-to-rvalue conversions, and
2377 the code in build_modify_expr handling various
2378 Objective-C cases, and that in build_unary_op handling
2379 Objective-C cases for increment / decrement, also needs
2380 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2381 and objc_types_are_equivalent may also need updates. */
2382 if (c_dialect_objc ())
2383 sorry ("%<_Atomic%> in Objective-C");
2384 /* C parser handling of OpenMP constructs needs checking for
2385 correct lvalue-to-rvalue conversions. */
2387 sorry ("%<_Atomic%> with OpenMP");
2389 pedwarn_c99 (loc
, OPT_Wpedantic
,
2390 "ISO C99 does not support the %<_Atomic%> qualifier");
2392 pedwarn_c99 (loc
, OPT_Wpedantic
,
2393 "ISO C90 does not support the %<_Atomic%> qualifier");
2396 value
= c_parser_peek_token (parser
)->value
;
2397 c_parser_consume_token (parser
);
2398 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2400 /* _Atomic ( type-name ). */
2402 c_parser_consume_token (parser
);
2403 struct c_type_name
*type
= c_parser_type_name (parser
);
2404 t
.kind
= ctsk_typeof
;
2405 t
.spec
= error_mark_node
;
2407 t
.expr_const_operands
= true;
2409 t
.spec
= groktypename (type
, &t
.expr
,
2410 &t
.expr_const_operands
);
2411 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2413 if (t
.spec
!= error_mark_node
)
2415 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2416 error_at (loc
, "%<_Atomic%>-qualified array type");
2417 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2418 error_at (loc
, "%<_Atomic%>-qualified function type");
2419 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2420 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2422 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2424 declspecs_add_type (loc
, specs
, t
);
2427 declspecs_add_qual (loc
, specs
, value
);
2433 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2434 c_parser_consume_token (parser
);
2439 attrs
= c_parser_attributes (parser
);
2440 declspecs_add_attrs (loc
, specs
, attrs
);
2445 align
= c_parser_alignas_specifier (parser
);
2446 declspecs_add_alignas (loc
, specs
, align
);
2455 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2458 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2459 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2460 enum attributes[opt] identifier
2462 The form with trailing comma is new in C99. The forms with
2463 attributes are GNU extensions. In GNU C, we accept any expression
2464 without commas in the syntax (assignment expressions, not just
2465 conditional expressions); assignment expressions will be diagnosed
2470 enumerator-list , enumerator
2473 enumeration-constant
2474 enumeration-constant = constant-expression
2477 static struct c_typespec
2478 c_parser_enum_specifier (c_parser
*parser
)
2480 struct c_typespec ret
;
2482 tree ident
= NULL_TREE
;
2483 location_t enum_loc
;
2484 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2485 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2486 enum_loc
= c_parser_peek_token (parser
)->location
;
2487 c_parser_consume_token (parser
);
2488 attrs
= c_parser_attributes (parser
);
2489 enum_loc
= c_parser_peek_token (parser
)->location
;
2490 /* Set the location in case we create a decl now. */
2491 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2492 if (c_parser_next_token_is (parser
, CPP_NAME
))
2494 ident
= c_parser_peek_token (parser
)->value
;
2495 ident_loc
= c_parser_peek_token (parser
)->location
;
2496 enum_loc
= ident_loc
;
2497 c_parser_consume_token (parser
);
2499 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2501 /* Parse an enum definition. */
2502 struct c_enum_contents the_enum
;
2505 /* We chain the enumerators in reverse order, then put them in
2506 forward order at the end. */
2508 timevar_push (TV_PARSE_ENUM
);
2509 type
= start_enum (enum_loc
, &the_enum
, ident
);
2511 c_parser_consume_token (parser
);
2519 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2520 location_t decl_loc
, value_loc
;
2521 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2523 c_parser_error (parser
, "expected identifier");
2524 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2525 values
= error_mark_node
;
2528 token
= c_parser_peek_token (parser
);
2529 enum_id
= token
->value
;
2530 /* Set the location in case we create a decl now. */
2531 c_parser_set_source_position_from_token (token
);
2532 decl_loc
= value_loc
= token
->location
;
2533 c_parser_consume_token (parser
);
2534 if (c_parser_next_token_is (parser
, CPP_EQ
))
2536 c_parser_consume_token (parser
);
2537 value_loc
= c_parser_peek_token (parser
)->location
;
2538 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2541 enum_value
= NULL_TREE
;
2542 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2543 &the_enum
, enum_id
, enum_value
);
2544 TREE_CHAIN (enum_decl
) = values
;
2547 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2549 comma_loc
= c_parser_peek_token (parser
)->location
;
2551 c_parser_consume_token (parser
);
2553 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2556 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2557 "comma at end of enumerator list");
2558 c_parser_consume_token (parser
);
2563 c_parser_error (parser
, "expected %<,%> or %<}%>");
2564 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2565 values
= error_mark_node
;
2569 postfix_attrs
= c_parser_attributes (parser
);
2570 ret
.spec
= finish_enum (type
, nreverse (values
),
2571 chainon (attrs
, postfix_attrs
));
2572 ret
.kind
= ctsk_tagdef
;
2573 ret
.expr
= NULL_TREE
;
2574 ret
.expr_const_operands
= true;
2575 timevar_pop (TV_PARSE_ENUM
);
2580 c_parser_error (parser
, "expected %<{%>");
2581 ret
.spec
= error_mark_node
;
2582 ret
.kind
= ctsk_tagref
;
2583 ret
.expr
= NULL_TREE
;
2584 ret
.expr_const_operands
= true;
2587 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2588 /* In ISO C, enumerated types can be referred to only if already
2590 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2593 pedwarn (enum_loc
, OPT_Wpedantic
,
2594 "ISO C forbids forward references to %<enum%> types");
2599 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2601 struct-or-union-specifier:
2602 struct-or-union attributes[opt] identifier[opt]
2603 { struct-contents } attributes[opt]
2604 struct-or-union attributes[opt] identifier
2607 struct-declaration-list
2609 struct-declaration-list:
2610 struct-declaration ;
2611 struct-declaration-list struct-declaration ;
2618 struct-declaration-list struct-declaration
2620 struct-declaration-list:
2621 struct-declaration-list ;
2624 (Note that in the syntax here, unlike that in ISO C, the semicolons
2625 are included here rather than in struct-declaration, in order to
2626 describe the syntax with extra semicolons and missing semicolon at
2631 struct-declaration-list:
2632 @defs ( class-name )
2634 (Note this does not include a trailing semicolon, but can be
2635 followed by further declarations, and gets a pedwarn-if-pedantic
2636 when followed by a semicolon.) */
2638 static struct c_typespec
2639 c_parser_struct_or_union_specifier (c_parser
*parser
)
2641 struct c_typespec ret
;
2643 tree ident
= NULL_TREE
;
2644 location_t struct_loc
;
2645 location_t ident_loc
= UNKNOWN_LOCATION
;
2646 enum tree_code code
;
2647 switch (c_parser_peek_token (parser
)->keyword
)
2658 struct_loc
= c_parser_peek_token (parser
)->location
;
2659 c_parser_consume_token (parser
);
2660 attrs
= c_parser_attributes (parser
);
2662 /* Set the location in case we create a decl now. */
2663 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2665 if (c_parser_next_token_is (parser
, CPP_NAME
))
2667 ident
= c_parser_peek_token (parser
)->value
;
2668 ident_loc
= c_parser_peek_token (parser
)->location
;
2669 struct_loc
= ident_loc
;
2670 c_parser_consume_token (parser
);
2672 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2674 /* Parse a struct or union definition. Start the scope of the
2675 tag before parsing components. */
2676 struct c_struct_parse_info
*struct_info
;
2677 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2679 /* We chain the components in reverse order, then put them in
2680 forward order at the end. Each struct-declaration may
2681 declare multiple components (comma-separated), so we must use
2682 chainon to join them, although when parsing each
2683 struct-declaration we can use TREE_CHAIN directly.
2685 The theory behind all this is that there will be more
2686 semicolon separated fields than comma separated fields, and
2687 so we'll be minimizing the number of node traversals required
2690 timevar_push (TV_PARSE_STRUCT
);
2691 contents
= NULL_TREE
;
2692 c_parser_consume_token (parser
);
2693 /* Handle the Objective-C @defs construct,
2694 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2695 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2698 gcc_assert (c_dialect_objc ());
2699 c_parser_consume_token (parser
);
2700 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2702 if (c_parser_next_token_is (parser
, CPP_NAME
)
2703 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2705 name
= c_parser_peek_token (parser
)->value
;
2706 c_parser_consume_token (parser
);
2710 c_parser_error (parser
, "expected class name");
2711 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2714 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2716 contents
= nreverse (objc_get_class_ivars (name
));
2719 /* Parse the struct-declarations and semicolons. Problems with
2720 semicolons are diagnosed here; empty structures are diagnosed
2725 /* Parse any stray semicolon. */
2726 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2728 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2729 "extra semicolon in struct or union specified");
2730 c_parser_consume_token (parser
);
2733 /* Stop if at the end of the struct or union contents. */
2734 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2736 c_parser_consume_token (parser
);
2739 /* Accept #pragmas at struct scope. */
2740 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2742 c_parser_pragma (parser
, pragma_struct
);
2745 /* Parse some comma-separated declarations, but not the
2746 trailing semicolon if any. */
2747 decls
= c_parser_struct_declaration (parser
);
2748 contents
= chainon (decls
, contents
);
2749 /* If no semicolon follows, either we have a parse error or
2750 are at the end of the struct or union and should
2752 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2753 c_parser_consume_token (parser
);
2756 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2757 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2758 "no semicolon at end of struct or union");
2759 else if (parser
->error
2760 || !c_parser_next_token_starts_declspecs (parser
))
2762 c_parser_error (parser
, "expected %<;%>");
2763 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2767 /* If we come here, we have already emitted an error
2768 for an expected `;', identifier or `(', and we also
2769 recovered already. Go on with the next field. */
2772 postfix_attrs
= c_parser_attributes (parser
);
2773 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2774 chainon (attrs
, postfix_attrs
), struct_info
);
2775 ret
.kind
= ctsk_tagdef
;
2776 ret
.expr
= NULL_TREE
;
2777 ret
.expr_const_operands
= true;
2778 timevar_pop (TV_PARSE_STRUCT
);
2783 c_parser_error (parser
, "expected %<{%>");
2784 ret
.spec
= error_mark_node
;
2785 ret
.kind
= ctsk_tagref
;
2786 ret
.expr
= NULL_TREE
;
2787 ret
.expr_const_operands
= true;
2790 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2794 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2795 the trailing semicolon.
2798 specifier-qualifier-list struct-declarator-list
2799 static_assert-declaration-no-semi
2801 specifier-qualifier-list:
2802 type-specifier specifier-qualifier-list[opt]
2803 type-qualifier specifier-qualifier-list[opt]
2804 attributes specifier-qualifier-list[opt]
2806 struct-declarator-list:
2808 struct-declarator-list , attributes[opt] struct-declarator
2811 declarator attributes[opt]
2812 declarator[opt] : constant-expression attributes[opt]
2817 __extension__ struct-declaration
2818 specifier-qualifier-list
2820 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2821 of attributes where shown is a GNU extension. In GNU C, we accept
2822 any expression without commas in the syntax (assignment
2823 expressions, not just conditional expressions); assignment
2824 expressions will be diagnosed as non-constant. */
2827 c_parser_struct_declaration (c_parser
*parser
)
2829 struct c_declspecs
*specs
;
2831 tree all_prefix_attrs
;
2833 location_t decl_loc
;
2834 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2838 ext
= disable_extension_diagnostics ();
2839 c_parser_consume_token (parser
);
2840 decl
= c_parser_struct_declaration (parser
);
2841 restore_extension_diagnostics (ext
);
2844 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2846 c_parser_static_assert_declaration_no_semi (parser
);
2849 specs
= build_null_declspecs ();
2850 decl_loc
= c_parser_peek_token (parser
)->location
;
2851 /* Strictly by the standard, we shouldn't allow _Alignas here,
2852 but it appears to have been intended to allow it there, so
2853 we're keeping it as it is until WG14 reaches a conclusion
2855 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2856 c_parser_declspecs (parser
, specs
, false, true, true,
2857 true, false, cla_nonabstract_decl
);
2860 if (!specs
->declspecs_seen_p
)
2862 c_parser_error (parser
, "expected specifier-qualifier-list");
2865 finish_declspecs (specs
);
2866 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2867 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2870 if (specs
->typespec_kind
== ctsk_none
)
2872 pedwarn (decl_loc
, OPT_Wpedantic
,
2873 "ISO C forbids member declarations with no members");
2874 shadow_tag_warned (specs
, pedantic
);
2879 /* Support for unnamed structs or unions as members of
2880 structs or unions (which is [a] useful and [b] supports
2884 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2885 build_id_declarator (NULL_TREE
), specs
,
2888 decl_attributes (&ret
, attrs
, 0);
2893 /* Provide better error recovery. Note that a type name here is valid,
2894 and will be treated as a field name. */
2895 if (specs
->typespec_kind
== ctsk_tagdef
2896 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2897 && c_parser_next_token_starts_declspecs (parser
)
2898 && !c_parser_next_token_is (parser
, CPP_NAME
))
2900 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2901 parser
->error
= false;
2905 pending_xref_error ();
2906 prefix_attrs
= specs
->attrs
;
2907 all_prefix_attrs
= prefix_attrs
;
2908 specs
->attrs
= NULL_TREE
;
2912 /* Declaring one or more declarators or un-named bit-fields. */
2913 struct c_declarator
*declarator
;
2915 if (c_parser_next_token_is (parser
, CPP_COLON
))
2916 declarator
= build_id_declarator (NULL_TREE
);
2918 declarator
= c_parser_declarator (parser
,
2919 specs
->typespec_kind
!= ctsk_none
,
2920 C_DTR_NORMAL
, &dummy
);
2921 if (declarator
== NULL
)
2923 c_parser_skip_to_end_of_block_or_statement (parser
);
2926 if (c_parser_next_token_is (parser
, CPP_COLON
)
2927 || c_parser_next_token_is (parser
, CPP_COMMA
)
2928 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2929 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2930 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2932 tree postfix_attrs
= NULL_TREE
;
2933 tree width
= NULL_TREE
;
2935 if (c_parser_next_token_is (parser
, CPP_COLON
))
2937 c_parser_consume_token (parser
);
2938 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2940 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2941 postfix_attrs
= c_parser_attributes (parser
);
2942 d
= grokfield (c_parser_peek_token (parser
)->location
,
2943 declarator
, specs
, width
, &all_prefix_attrs
);
2944 decl_attributes (&d
, chainon (postfix_attrs
,
2945 all_prefix_attrs
), 0);
2946 DECL_CHAIN (d
) = decls
;
2948 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2949 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2952 all_prefix_attrs
= prefix_attrs
;
2953 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2954 c_parser_consume_token (parser
);
2955 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2956 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2958 /* Semicolon consumed in caller. */
2963 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2969 c_parser_error (parser
,
2970 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2971 "%<__attribute__%>");
2978 /* Parse a typeof specifier (a GNU extension).
2981 typeof ( expression )
2982 typeof ( type-name )
2985 static struct c_typespec
2986 c_parser_typeof_specifier (c_parser
*parser
)
2988 struct c_typespec ret
;
2989 ret
.kind
= ctsk_typeof
;
2990 ret
.spec
= error_mark_node
;
2991 ret
.expr
= NULL_TREE
;
2992 ret
.expr_const_operands
= true;
2993 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2994 c_parser_consume_token (parser
);
2995 c_inhibit_evaluation_warnings
++;
2997 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2999 c_inhibit_evaluation_warnings
--;
3003 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3005 struct c_type_name
*type
= c_parser_type_name (parser
);
3006 c_inhibit_evaluation_warnings
--;
3010 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3011 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3017 location_t here
= c_parser_peek_token (parser
)->location
;
3018 struct c_expr expr
= c_parser_expression (parser
);
3019 c_inhibit_evaluation_warnings
--;
3021 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3022 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3023 error_at (here
, "%<typeof%> applied to a bit-field");
3024 mark_exp_read (expr
.value
);
3025 ret
.spec
= TREE_TYPE (expr
.value
);
3026 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3027 /* This is returned with the type so that when the type is
3028 evaluated, this can be evaluated. */
3030 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3031 pop_maybe_used (was_vm
);
3032 /* For use in macros such as those in <stdatomic.h>, remove all
3033 qualifiers from atomic types. (const can be an issue for more macros
3034 using typeof than just the <stdatomic.h> ones.) */
3035 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3036 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3038 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3042 /* Parse an alignment-specifier.
3046 alignment-specifier:
3047 _Alignas ( type-name )
3048 _Alignas ( constant-expression )
3052 c_parser_alignas_specifier (c_parser
* parser
)
3054 tree ret
= error_mark_node
;
3055 location_t loc
= c_parser_peek_token (parser
)->location
;
3056 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3057 c_parser_consume_token (parser
);
3059 pedwarn_c99 (loc
, OPT_Wpedantic
,
3060 "ISO C99 does not support %<_Alignas%>");
3062 pedwarn_c99 (loc
, OPT_Wpedantic
,
3063 "ISO C90 does not support %<_Alignas%>");
3064 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3066 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3068 struct c_type_name
*type
= c_parser_type_name (parser
);
3070 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3074 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3075 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3079 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3080 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3081 be redeclared; otherwise it may not. KIND indicates which kind of
3082 declarator is wanted. Returns a valid declarator except in the
3083 case of a syntax error in which case NULL is returned. *SEEN_ID is
3084 set to true if an identifier being declared is seen; this is used
3085 to diagnose bad forms of abstract array declarators and to
3086 determine whether an identifier list is syntactically permitted.
3089 pointer[opt] direct-declarator
3093 ( attributes[opt] declarator )
3094 direct-declarator array-declarator
3095 direct-declarator ( parameter-type-list )
3096 direct-declarator ( identifier-list[opt] )
3099 * type-qualifier-list[opt]
3100 * type-qualifier-list[opt] pointer
3102 type-qualifier-list:
3105 type-qualifier-list type-qualifier
3106 type-qualifier-list attributes
3109 [ type-qualifier-list[opt] assignment-expression[opt] ]
3110 [ static type-qualifier-list[opt] assignment-expression ]
3111 [ type-qualifier-list static assignment-expression ]
3112 [ type-qualifier-list[opt] * ]
3114 parameter-type-list:
3116 parameter-list , ...
3119 parameter-declaration
3120 parameter-list , parameter-declaration
3122 parameter-declaration:
3123 declaration-specifiers declarator attributes[opt]
3124 declaration-specifiers abstract-declarator[opt] attributes[opt]
3128 identifier-list , identifier
3130 abstract-declarator:
3132 pointer[opt] direct-abstract-declarator
3134 direct-abstract-declarator:
3135 ( attributes[opt] abstract-declarator )
3136 direct-abstract-declarator[opt] array-declarator
3137 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3142 direct-declarator ( parameter-forward-declarations
3143 parameter-type-list[opt] )
3145 direct-abstract-declarator:
3146 direct-abstract-declarator[opt] ( parameter-forward-declarations
3147 parameter-type-list[opt] )
3149 parameter-forward-declarations:
3151 parameter-forward-declarations parameter-list ;
3153 The uses of attributes shown above are GNU extensions.
3155 Some forms of array declarator are not included in C99 in the
3156 syntax for abstract declarators; these are disallowed elsewhere.
3157 This may be a defect (DR#289).
3159 This function also accepts an omitted abstract declarator as being
3160 an abstract declarator, although not part of the formal syntax. */
3162 static struct c_declarator
*
3163 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3166 /* Parse any initial pointer part. */
3167 if (c_parser_next_token_is (parser
, CPP_MULT
))
3169 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3170 struct c_declarator
*inner
;
3171 c_parser_consume_token (parser
);
3172 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3173 false, false, cla_prefer_id
);
3174 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3178 return make_pointer_declarator (quals_attrs
, inner
);
3180 /* Now we have a direct declarator, direct abstract declarator or
3181 nothing (which counts as a direct abstract declarator here). */
3182 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3185 /* Parse a direct declarator or direct abstract declarator; arguments
3186 as c_parser_declarator. */
3188 static struct c_declarator
*
3189 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3192 /* The direct declarator must start with an identifier (possibly
3193 omitted) or a parenthesized declarator (possibly abstract). In
3194 an ordinary declarator, initial parentheses must start a
3195 parenthesized declarator. In an abstract declarator or parameter
3196 declarator, they could start a parenthesized declarator or a
3197 parameter list. To tell which, the open parenthesis and any
3198 following attributes must be read. If a declaration specifier
3199 follows, then it is a parameter list; if the specifier is a
3200 typedef name, there might be an ambiguity about redeclaring it,
3201 which is resolved in the direction of treating it as a typedef
3202 name. If a close parenthesis follows, it is also an empty
3203 parameter list, as the syntax does not permit empty abstract
3204 declarators. Otherwise, it is a parenthesized declarator (in
3205 which case the analysis may be repeated inside it, recursively).
3207 ??? There is an ambiguity in a parameter declaration "int
3208 (__attribute__((foo)) x)", where x is not a typedef name: it
3209 could be an abstract declarator for a function, or declare x with
3210 parentheses. The proper resolution of this ambiguity needs
3211 documenting. At present we follow an accident of the old
3212 parser's implementation, whereby the first parameter must have
3213 some declaration specifiers other than just attributes. Thus as
3214 a parameter declaration it is treated as a parenthesized
3215 parameter named x, and as an abstract declarator it is
3218 ??? Also following the old parser, attributes inside an empty
3219 parameter list are ignored, making it a list not yielding a
3220 prototype, rather than giving an error or making it have one
3221 parameter with implicit type int.
3223 ??? Also following the old parser, typedef names may be
3224 redeclared in declarators, but not Objective-C class names. */
3226 if (kind
!= C_DTR_ABSTRACT
3227 && c_parser_next_token_is (parser
, CPP_NAME
)
3229 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3230 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3231 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3233 struct c_declarator
*inner
3234 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3236 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3237 c_parser_consume_token (parser
);
3238 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3241 if (kind
!= C_DTR_NORMAL
3242 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3244 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3245 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3248 /* Either we are at the end of an abstract declarator, or we have
3251 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3254 struct c_declarator
*inner
;
3255 c_parser_consume_token (parser
);
3256 attrs
= c_parser_attributes (parser
);
3257 if (kind
!= C_DTR_NORMAL
3258 && (c_parser_next_token_starts_declspecs (parser
)
3259 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3261 struct c_arg_info
*args
3262 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3269 = build_function_declarator (args
,
3270 build_id_declarator (NULL_TREE
));
3271 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3275 /* A parenthesized declarator. */
3276 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3277 if (inner
!= NULL
&& attrs
!= NULL
)
3278 inner
= build_attrs_declarator (attrs
, inner
);
3279 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3281 c_parser_consume_token (parser
);
3285 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3289 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3296 if (kind
== C_DTR_NORMAL
)
3298 c_parser_error (parser
, "expected identifier or %<(%>");
3302 return build_id_declarator (NULL_TREE
);
3306 /* Parse part of a direct declarator or direct abstract declarator,
3307 given that some (in INNER) has already been parsed; ID_PRESENT is
3308 true if an identifier is present, false for an abstract
3311 static struct c_declarator
*
3312 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3313 struct c_declarator
*inner
)
3315 /* Parse a sequence of array declarators and parameter lists. */
3316 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3318 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3319 struct c_declarator
*declarator
;
3320 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3323 struct c_expr dimen
;
3324 dimen
.value
= NULL_TREE
;
3325 dimen
.original_code
= ERROR_MARK
;
3326 dimen
.original_type
= NULL_TREE
;
3327 c_parser_consume_token (parser
);
3328 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3329 false, false, cla_prefer_id
);
3330 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3332 c_parser_consume_token (parser
);
3333 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3334 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3335 false, false, cla_prefer_id
);
3336 if (!quals_attrs
->declspecs_seen_p
)
3338 /* If "static" is present, there must be an array dimension.
3339 Otherwise, there may be a dimension, "*", or no
3344 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3348 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3350 dimen
.value
= NULL_TREE
;
3353 else if (flag_cilkplus
3354 && c_parser_next_token_is (parser
, CPP_COLON
))
3356 dimen
.value
= error_mark_node
;
3358 error_at (c_parser_peek_token (parser
)->location
,
3359 "array notations cannot be used in declaration");
3360 c_parser_consume_token (parser
);
3362 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3364 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3366 dimen
.value
= NULL_TREE
;
3368 c_parser_consume_token (parser
);
3373 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3379 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3382 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3383 c_parser_consume_token (parser
);
3384 else if (flag_cilkplus
3385 && c_parser_next_token_is (parser
, CPP_COLON
))
3387 error_at (c_parser_peek_token (parser
)->location
,
3388 "array notations cannot be used in declaration");
3389 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3394 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3399 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3400 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3401 static_seen
, star_seen
);
3402 if (declarator
== NULL
)
3404 inner
= set_array_declarator_inner (declarator
, inner
);
3405 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3407 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3410 struct c_arg_info
*args
;
3411 c_parser_consume_token (parser
);
3412 attrs
= c_parser_attributes (parser
);
3413 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3418 inner
= build_function_declarator (args
, inner
);
3419 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3425 /* Parse a parameter list or identifier list, including the closing
3426 parenthesis but not the opening one. ATTRS are the attributes at
3427 the start of the list. ID_LIST_OK is true if an identifier list is
3428 acceptable; such a list must not have attributes at the start. */
3430 static struct c_arg_info
*
3431 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3434 declare_parm_level ();
3435 /* If the list starts with an identifier, it is an identifier list.
3436 Otherwise, it is either a prototype list or an empty list. */
3439 && c_parser_next_token_is (parser
, CPP_NAME
)
3440 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3442 /* Look ahead to detect typos in type names. */
3443 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3444 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3445 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3446 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3448 tree list
= NULL_TREE
, *nextp
= &list
;
3449 while (c_parser_next_token_is (parser
, CPP_NAME
)
3450 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3452 *nextp
= build_tree_list (NULL_TREE
,
3453 c_parser_peek_token (parser
)->value
);
3454 nextp
= & TREE_CHAIN (*nextp
);
3455 c_parser_consume_token (parser
);
3456 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3458 c_parser_consume_token (parser
);
3459 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3461 c_parser_error (parser
, "expected identifier");
3465 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3467 struct c_arg_info
*ret
= build_arg_info ();
3469 c_parser_consume_token (parser
);
3475 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3483 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3490 /* Parse a parameter list (possibly empty), including the closing
3491 parenthesis but not the opening one. ATTRS are the attributes at
3492 the start of the list. EXPR is NULL or an expression that needs to
3493 be evaluated for the side effects of array size expressions in the
3496 static struct c_arg_info
*
3497 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3499 bool bad_parm
= false;
3501 /* ??? Following the old parser, forward parameter declarations may
3502 use abstract declarators, and if no real parameter declarations
3503 follow the forward declarations then this is not diagnosed. Also
3504 note as above that attributes are ignored as the only contents of
3505 the parentheses, or as the only contents after forward
3507 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3509 struct c_arg_info
*ret
= build_arg_info ();
3510 c_parser_consume_token (parser
);
3513 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3515 struct c_arg_info
*ret
= build_arg_info ();
3517 if (flag_allow_parameterless_variadic_functions
)
3519 /* F (...) is allowed. */
3520 ret
->types
= NULL_TREE
;
3524 /* Suppress -Wold-style-definition for this case. */
3525 ret
->types
= error_mark_node
;
3526 error_at (c_parser_peek_token (parser
)->location
,
3527 "ISO C requires a named argument before %<...%>");
3529 c_parser_consume_token (parser
);
3530 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3532 c_parser_consume_token (parser
);
3537 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3542 /* Nonempty list of parameters, either terminated with semicolon
3543 (forward declarations; recurse) or with close parenthesis (normal
3544 function) or with ", ... )" (variadic function). */
3547 /* Parse a parameter. */
3548 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3553 push_parm_decl (parm
, &expr
);
3554 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3557 c_parser_consume_token (parser
);
3558 mark_forward_parm_decls ();
3559 new_attrs
= c_parser_attributes (parser
);
3560 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3562 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3564 c_parser_consume_token (parser
);
3568 return get_parm_info (false, expr
);
3570 if (!c_parser_require (parser
, CPP_COMMA
,
3571 "expected %<;%>, %<,%> or %<)%>"))
3573 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3576 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3578 c_parser_consume_token (parser
);
3579 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3581 c_parser_consume_token (parser
);
3585 return get_parm_info (true, expr
);
3589 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3597 /* Parse a parameter declaration. ATTRS are the attributes at the
3598 start of the declaration if it is the first parameter. */
3600 static struct c_parm
*
3601 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3603 struct c_declspecs
*specs
;
3604 struct c_declarator
*declarator
;
3606 tree postfix_attrs
= NULL_TREE
;
3609 /* Accept #pragmas between parameter declarations. */
3610 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3611 c_parser_pragma (parser
, pragma_param
);
3613 if (!c_parser_next_token_starts_declspecs (parser
))
3615 c_token
*token
= c_parser_peek_token (parser
);
3618 c_parser_set_source_position_from_token (token
);
3619 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3621 error_at (token
->location
, "unknown type name %qE", token
->value
);
3622 parser
->error
= true;
3624 /* ??? In some Objective-C cases '...' isn't applicable so there
3625 should be a different message. */
3627 c_parser_error (parser
,
3628 "expected declaration specifiers or %<...%>");
3629 c_parser_skip_to_end_of_parameter (parser
);
3632 specs
= build_null_declspecs ();
3635 declspecs_add_attrs (input_location
, specs
, attrs
);
3638 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3639 cla_nonabstract_decl
);
3640 finish_declspecs (specs
);
3641 pending_xref_error ();
3642 prefix_attrs
= specs
->attrs
;
3643 specs
->attrs
= NULL_TREE
;
3644 declarator
= c_parser_declarator (parser
,
3645 specs
->typespec_kind
!= ctsk_none
,
3646 C_DTR_PARM
, &dummy
);
3647 if (declarator
== NULL
)
3649 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3652 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3653 postfix_attrs
= c_parser_attributes (parser
);
3654 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3658 /* Parse a string literal in an asm expression. It should not be
3659 translated, and wide string literals are an error although
3660 permitted by the syntax. This is a GNU extension.
3665 ??? At present, following the old parser, the caller needs to have
3666 set lex_untranslated_string to 1. It would be better to follow the
3667 C++ parser rather than using this kludge. */
3670 c_parser_asm_string_literal (c_parser
*parser
)
3673 int save_flag
= warn_overlength_strings
;
3674 warn_overlength_strings
= 0;
3675 if (c_parser_next_token_is (parser
, CPP_STRING
))
3677 str
= c_parser_peek_token (parser
)->value
;
3678 c_parser_consume_token (parser
);
3680 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3682 error_at (c_parser_peek_token (parser
)->location
,
3683 "wide string literal in %<asm%>");
3684 str
= build_string (1, "");
3685 c_parser_consume_token (parser
);
3689 c_parser_error (parser
, "expected string literal");
3692 warn_overlength_strings
= save_flag
;
3696 /* Parse a simple asm expression. This is used in restricted
3697 contexts, where a full expression with inputs and outputs does not
3698 make sense. This is a GNU extension.
3701 asm ( asm-string-literal )
3705 c_parser_simple_asm_expr (c_parser
*parser
)
3708 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3709 /* ??? Follow the C++ parser rather than using the
3710 lex_untranslated_string kludge. */
3711 parser
->lex_untranslated_string
= true;
3712 c_parser_consume_token (parser
);
3713 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3715 parser
->lex_untranslated_string
= false;
3718 str
= c_parser_asm_string_literal (parser
);
3719 parser
->lex_untranslated_string
= false;
3720 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3722 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3729 c_parser_attribute_any_word (c_parser
*parser
)
3731 tree attr_name
= NULL_TREE
;
3733 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3735 /* ??? See comment above about what keywords are accepted here. */
3737 switch (c_parser_peek_token (parser
)->keyword
)
3768 case RID_TRANSACTION_ATOMIC
:
3769 case RID_TRANSACTION_CANCEL
:
3781 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3782 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3784 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3785 attr_name
= c_parser_peek_token (parser
)->value
;
3790 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3791 "__vector" or "__vector__." */
3794 is_cilkplus_vector_p (tree name
)
3796 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3801 #define CILK_SIMD_FN_CLAUSE_MASK \
3802 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3803 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3804 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3805 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3806 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3808 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3809 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3810 pushed into the token list.
3813 vector (<vector attributes>). */
3816 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3818 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3820 int paren_scope
= 0;
3821 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3822 /* Consume the "vector" token. */
3823 c_parser_consume_token (parser
);
3825 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3827 c_parser_consume_token (parser
);
3830 while (paren_scope
> 0)
3832 c_token
*token
= c_parser_peek_token (parser
);
3833 if (token
->type
== CPP_OPEN_PAREN
)
3835 else if (token
->type
== CPP_CLOSE_PAREN
)
3837 /* Do not push the last ')' since we are not pushing the '('. */
3838 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3839 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3840 c_parser_consume_token (parser
);
3843 /* Since we are converting an attribute to a pragma, we need to end the
3844 attribute with PRAGMA_EOL. */
3846 memset (&eol_token
, 0, sizeof (eol_token
));
3847 eol_token
.type
= CPP_PRAGMA_EOL
;
3848 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3851 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3854 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3856 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3858 /* c_parser_attributes is called in several places, so if these EOF
3859 tokens are already inserted, then don't do them again. */
3860 if (last_token
.type
== CPP_EOF
)
3863 /* Two CPP_EOF token are added as a safety net since the normal C
3864 front-end has two token look-ahead. */
3866 eof_token
.type
= CPP_EOF
;
3867 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3868 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3871 /* Parse (possibly empty) attributes. This is a GNU extension.
3875 attributes attribute
3878 __attribute__ ( ( attribute-list ) )
3882 attribute_list , attrib
3887 any-word ( identifier )
3888 any-word ( identifier , nonempty-expr-list )
3889 any-word ( expr-list )
3891 where the "identifier" must not be declared as a type, and
3892 "any-word" may be any identifier (including one declared as a
3893 type), a reserved word storage class specifier, type specifier or
3894 type qualifier. ??? This still leaves out most reserved keywords
3895 (following the old parser), shouldn't we include them, and why not
3896 allow identifiers declared as types to start the arguments? */
3899 c_parser_attributes (c_parser
*parser
)
3901 tree attrs
= NULL_TREE
;
3902 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3904 /* ??? Follow the C++ parser rather than using the
3905 lex_untranslated_string kludge. */
3906 parser
->lex_untranslated_string
= true;
3907 c_parser_consume_token (parser
);
3908 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3910 parser
->lex_untranslated_string
= false;
3913 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3915 parser
->lex_untranslated_string
= false;
3916 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3919 /* Parse the attribute list. */
3920 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3921 || c_parser_next_token_is (parser
, CPP_NAME
)
3922 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3924 tree attr
, attr_name
, attr_args
;
3925 vec
<tree
, va_gc
> *expr_list
;
3926 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3928 c_parser_consume_token (parser
);
3932 attr_name
= c_parser_attribute_any_word (parser
);
3933 if (attr_name
== NULL
)
3935 if (is_cilkplus_vector_p (attr_name
))
3937 c_token
*v_token
= c_parser_peek_token (parser
);
3938 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3941 c_parser_consume_token (parser
);
3942 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3944 attr
= build_tree_list (attr_name
, NULL_TREE
);
3945 attrs
= chainon (attrs
, attr
);
3948 c_parser_consume_token (parser
);
3949 /* Parse the attribute contents. If they start with an
3950 identifier which is followed by a comma or close
3951 parenthesis, then the arguments start with that
3952 identifier; otherwise they are an expression list.
3953 In objective-c the identifier may be a classname. */
3954 if (c_parser_next_token_is (parser
, CPP_NAME
)
3955 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3956 || (c_dialect_objc ()
3957 && c_parser_peek_token (parser
)->id_kind
3959 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3960 || (c_parser_peek_2nd_token (parser
)->type
3961 == CPP_CLOSE_PAREN
))
3962 && (attribute_takes_identifier_p (attr_name
)
3963 || (c_dialect_objc ()
3964 && c_parser_peek_token (parser
)->id_kind
3965 == C_ID_CLASSNAME
)))
3967 tree arg1
= c_parser_peek_token (parser
)->value
;
3968 c_parser_consume_token (parser
);
3969 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3970 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3974 c_parser_consume_token (parser
);
3975 expr_list
= c_parser_expr_list (parser
, false, true,
3976 NULL
, NULL
, NULL
, NULL
);
3977 tree_list
= build_tree_list_vec (expr_list
);
3978 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3979 release_tree_vector (expr_list
);
3984 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3985 attr_args
= NULL_TREE
;
3988 expr_list
= c_parser_expr_list (parser
, false, true,
3989 NULL
, NULL
, NULL
, NULL
);
3990 attr_args
= build_tree_list_vec (expr_list
);
3991 release_tree_vector (expr_list
);
3994 attr
= build_tree_list (attr_name
, attr_args
);
3995 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3996 c_parser_consume_token (parser
);
3999 parser
->lex_untranslated_string
= false;
4000 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4004 attrs
= chainon (attrs
, attr
);
4006 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4007 c_parser_consume_token (parser
);
4010 parser
->lex_untranslated_string
= false;
4011 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4015 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4016 c_parser_consume_token (parser
);
4019 parser
->lex_untranslated_string
= false;
4020 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4024 parser
->lex_untranslated_string
= false;
4027 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4028 c_finish_cilk_simd_fn_tokens (parser
);
4032 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4035 specifier-qualifier-list abstract-declarator[opt]
4038 static struct c_type_name
*
4039 c_parser_type_name (c_parser
*parser
)
4041 struct c_declspecs
*specs
= build_null_declspecs ();
4042 struct c_declarator
*declarator
;
4043 struct c_type_name
*ret
;
4045 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4047 if (!specs
->declspecs_seen_p
)
4049 c_parser_error (parser
, "expected specifier-qualifier-list");
4052 if (specs
->type
!= error_mark_node
)
4054 pending_xref_error ();
4055 finish_declspecs (specs
);
4057 declarator
= c_parser_declarator (parser
,
4058 specs
->typespec_kind
!= ctsk_none
,
4059 C_DTR_ABSTRACT
, &dummy
);
4060 if (declarator
== NULL
)
4062 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4064 ret
->declarator
= declarator
;
4068 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4071 assignment-expression
4072 { initializer-list }
4073 { initializer-list , }
4076 designation[opt] initializer
4077 initializer-list , designation[opt] initializer
4084 designator-list designator
4091 [ constant-expression ]
4103 [ constant-expression ... constant-expression ]
4105 Any expression without commas is accepted in the syntax for the
4106 constant-expressions, with non-constant expressions rejected later.
4108 This function is only used for top-level initializers; for nested
4109 ones, see c_parser_initval. */
4111 static struct c_expr
4112 c_parser_initializer (c_parser
*parser
)
4114 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4115 return c_parser_braced_init (parser
, NULL_TREE
, false);
4119 location_t loc
= c_parser_peek_token (parser
)->location
;
4120 ret
= c_parser_expr_no_commas (parser
, NULL
);
4121 if (TREE_CODE (ret
.value
) != STRING_CST
4122 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4123 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4128 /* Parse a braced initializer list. TYPE is the type specified for a
4129 compound literal, and NULL_TREE for other initializers and for
4130 nested braced lists. NESTED_P is true for nested braced lists,
4131 false for the list of a compound literal or the list that is the
4132 top-level initializer in a declaration. */
4134 static struct c_expr
4135 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4138 struct obstack braced_init_obstack
;
4139 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4140 gcc_obstack_init (&braced_init_obstack
);
4141 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4142 c_parser_consume_token (parser
);
4144 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4146 really_start_incremental_init (type
);
4147 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4149 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4153 /* Parse a non-empty initializer list, possibly with a trailing
4157 c_parser_initelt (parser
, &braced_init_obstack
);
4160 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4161 c_parser_consume_token (parser
);
4164 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4168 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4170 ret
.value
= error_mark_node
;
4171 ret
.original_code
= ERROR_MARK
;
4172 ret
.original_type
= NULL
;
4173 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4174 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4175 obstack_free (&braced_init_obstack
, NULL
);
4178 c_parser_consume_token (parser
);
4179 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4180 obstack_free (&braced_init_obstack
, NULL
);
4184 /* Parse a nested initializer, including designators. */
4187 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4189 /* Parse any designator or designator list. A single array
4190 designator may have the subsequent "=" omitted in GNU C, but a
4191 longer list or a structure member designator may not. */
4192 if (c_parser_next_token_is (parser
, CPP_NAME
)
4193 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4195 /* Old-style structure member designator. */
4196 set_init_label (c_parser_peek_token (parser
)->location
,
4197 c_parser_peek_token (parser
)->value
,
4198 braced_init_obstack
);
4199 /* Use the colon as the error location. */
4200 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4201 "obsolete use of designated initializer with %<:%>");
4202 c_parser_consume_token (parser
);
4203 c_parser_consume_token (parser
);
4207 /* des_seen is 0 if there have been no designators, 1 if there
4208 has been a single array designator and 2 otherwise. */
4210 /* Location of a designator. */
4211 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4212 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4213 || c_parser_next_token_is (parser
, CPP_DOT
))
4215 int des_prev
= des_seen
;
4217 des_loc
= c_parser_peek_token (parser
)->location
;
4220 if (c_parser_next_token_is (parser
, CPP_DOT
))
4223 c_parser_consume_token (parser
);
4224 if (c_parser_next_token_is (parser
, CPP_NAME
))
4226 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4227 braced_init_obstack
);
4228 c_parser_consume_token (parser
);
4233 init
.value
= error_mark_node
;
4234 init
.original_code
= ERROR_MARK
;
4235 init
.original_type
= NULL
;
4236 c_parser_error (parser
, "expected identifier");
4237 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4238 process_init_element (input_location
, init
, false,
4239 braced_init_obstack
);
4246 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4247 location_t array_index_loc
= UNKNOWN_LOCATION
;
4248 /* ??? Following the old parser, [ objc-receiver
4249 objc-message-args ] is accepted as an initializer,
4250 being distinguished from a designator by what follows
4251 the first assignment expression inside the square
4252 brackets, but after a first array designator a
4253 subsequent square bracket is for Objective-C taken to
4254 start an expression, using the obsolete form of
4255 designated initializer without '=', rather than
4256 possibly being a second level of designation: in LALR
4257 terms, the '[' is shifted rather than reducing
4258 designator to designator-list. */
4259 if (des_prev
== 1 && c_dialect_objc ())
4261 des_seen
= des_prev
;
4264 if (des_prev
== 0 && c_dialect_objc ())
4266 /* This might be an array designator or an
4267 Objective-C message expression. If the former,
4268 continue parsing here; if the latter, parse the
4269 remainder of the initializer given the starting
4270 primary-expression. ??? It might make sense to
4271 distinguish when des_prev == 1 as well; see
4272 previous comment. */
4274 struct c_expr mexpr
;
4275 c_parser_consume_token (parser
);
4276 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4277 && ((c_parser_peek_token (parser
)->id_kind
4279 || (c_parser_peek_token (parser
)->id_kind
4280 == C_ID_CLASSNAME
)))
4282 /* Type name receiver. */
4283 tree id
= c_parser_peek_token (parser
)->value
;
4284 c_parser_consume_token (parser
);
4285 rec
= objc_get_class_reference (id
);
4286 goto parse_message_args
;
4288 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4289 mark_exp_read (first
);
4290 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4291 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4292 goto array_desig_after_first
;
4293 /* Expression receiver. So far only one part
4294 without commas has been parsed; there might be
4295 more of the expression. */
4297 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4300 location_t comma_loc
, exp_loc
;
4301 comma_loc
= c_parser_peek_token (parser
)->location
;
4302 c_parser_consume_token (parser
);
4303 exp_loc
= c_parser_peek_token (parser
)->location
;
4304 next
= c_parser_expr_no_commas (parser
, NULL
);
4305 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4307 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4310 /* Now parse the objc-message-args. */
4311 args
= c_parser_objc_message_args (parser
);
4312 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4315 = objc_build_message_expr (rec
, args
);
4316 mexpr
.original_code
= ERROR_MARK
;
4317 mexpr
.original_type
= NULL
;
4318 /* Now parse and process the remainder of the
4319 initializer, starting with this message
4320 expression as a primary-expression. */
4321 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4324 c_parser_consume_token (parser
);
4325 array_index_loc
= c_parser_peek_token (parser
)->location
;
4326 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4327 mark_exp_read (first
);
4328 array_desig_after_first
:
4329 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4331 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4332 c_parser_consume_token (parser
);
4333 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4334 mark_exp_read (second
);
4338 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4340 c_parser_consume_token (parser
);
4341 set_init_index (array_index_loc
, first
, second
,
4342 braced_init_obstack
);
4344 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4345 "ISO C forbids specifying range of elements to initialize");
4348 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4354 if (c_parser_next_token_is (parser
, CPP_EQ
))
4356 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4357 "ISO C90 forbids specifying subobject "
4359 c_parser_consume_token (parser
);
4364 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4365 "obsolete use of designated initializer without %<=%>");
4369 init
.value
= error_mark_node
;
4370 init
.original_code
= ERROR_MARK
;
4371 init
.original_type
= NULL
;
4372 c_parser_error (parser
, "expected %<=%>");
4373 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4374 process_init_element (input_location
, init
, false,
4375 braced_init_obstack
);
4381 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4384 /* Parse a nested initializer; as c_parser_initializer but parses
4385 initializers within braced lists, after any designators have been
4386 applied. If AFTER is not NULL then it is an Objective-C message
4387 expression which is the primary-expression starting the
4391 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4392 struct obstack
* braced_init_obstack
)
4395 gcc_assert (!after
|| c_dialect_objc ());
4396 location_t loc
= c_parser_peek_token (parser
)->location
;
4398 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4399 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4402 init
= c_parser_expr_no_commas (parser
, after
);
4403 if (init
.value
!= NULL_TREE
4404 && TREE_CODE (init
.value
) != STRING_CST
4405 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4406 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4408 process_init_element (loc
, init
, false, braced_init_obstack
);
4411 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4415 { block-item-list[opt] }
4416 { label-declarations block-item-list }
4420 block-item-list block-item
4432 { label-declarations block-item-list }
4435 __extension__ nested-declaration
4436 nested-function-definition
4440 label-declarations label-declaration
4443 __label__ identifier-list ;
4445 Allowing the mixing of declarations and code is new in C99. The
4446 GNU syntax also permits (not shown above) labels at the end of
4447 compound statements, which yield an error. We don't allow labels
4448 on declarations; this might seem like a natural extension, but
4449 there would be a conflict between attributes on the label and
4450 prefix attributes on the declaration. ??? The syntax follows the
4451 old parser in requiring something after label declarations.
4452 Although they are erroneous if the labels declared aren't defined,
4453 is it useful for the syntax to be this way?
4466 cancellation-point-directive */
4469 c_parser_compound_statement (c_parser
*parser
)
4472 location_t brace_loc
;
4473 brace_loc
= c_parser_peek_token (parser
)->location
;
4474 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4476 /* Ensure a scope is entered and left anyway to avoid confusion
4477 if we have just prepared to enter a function body. */
4478 stmt
= c_begin_compound_stmt (true);
4479 c_end_compound_stmt (brace_loc
, stmt
, true);
4480 return error_mark_node
;
4482 stmt
= c_begin_compound_stmt (true);
4483 c_parser_compound_statement_nostart (parser
);
4485 /* If the compound stmt contains array notations, then we expand them. */
4486 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4487 stmt
= expand_array_notation_exprs (stmt
);
4488 return c_end_compound_stmt (brace_loc
, stmt
, true);
4491 /* Parse a compound statement except for the opening brace. This is
4492 used for parsing both compound statements and statement expressions
4493 (which follow different paths to handling the opening). */
4496 c_parser_compound_statement_nostart (c_parser
*parser
)
4498 bool last_stmt
= false;
4499 bool last_label
= false;
4500 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4501 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4502 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4504 c_parser_consume_token (parser
);
4507 mark_valid_location_for_stdc_pragma (true);
4508 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4510 /* Read zero or more forward-declarations for labels that nested
4511 functions can jump to. */
4512 mark_valid_location_for_stdc_pragma (false);
4513 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4515 label_loc
= c_parser_peek_token (parser
)->location
;
4516 c_parser_consume_token (parser
);
4517 /* Any identifiers, including those declared as type names,
4522 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4524 c_parser_error (parser
, "expected identifier");
4528 = declare_label (c_parser_peek_token (parser
)->value
);
4529 C_DECLARED_LABEL_FLAG (label
) = 1;
4530 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4531 c_parser_consume_token (parser
);
4532 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4533 c_parser_consume_token (parser
);
4537 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4539 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4541 /* We must now have at least one statement, label or declaration. */
4542 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4544 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4545 c_parser_error (parser
, "expected declaration or statement");
4546 c_parser_consume_token (parser
);
4549 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4551 location_t loc
= c_parser_peek_token (parser
)->location
;
4552 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4553 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4554 || (c_parser_next_token_is (parser
, CPP_NAME
)
4555 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4557 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4558 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4560 label_loc
= c_parser_peek_token (parser
)->location
;
4563 mark_valid_location_for_stdc_pragma (false);
4564 c_parser_label (parser
);
4566 else if (!last_label
4567 && c_parser_next_tokens_start_declaration (parser
))
4570 mark_valid_location_for_stdc_pragma (false);
4571 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4574 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4575 "ISO C90 forbids mixed declarations and code");
4578 else if (!last_label
4579 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4581 /* __extension__ can start a declaration, but is also an
4582 unary operator that can start an expression. Consume all
4583 but the last of a possible series of __extension__ to
4585 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4586 && (c_parser_peek_2nd_token (parser
)->keyword
4588 c_parser_consume_token (parser
);
4589 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4592 ext
= disable_extension_diagnostics ();
4593 c_parser_consume_token (parser
);
4595 mark_valid_location_for_stdc_pragma (false);
4596 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4598 /* Following the old parser, __extension__ does not
4599 disable this diagnostic. */
4600 restore_extension_diagnostics (ext
);
4602 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4603 "ISO C90 forbids mixed declarations and code");
4609 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4611 /* External pragmas, and some omp pragmas, are not associated
4612 with regular c code, and so are not to be considered statements
4613 syntactically. This ensures that the user doesn't put them
4614 places that would turn into syntax errors if the directive
4616 if (c_parser_pragma (parser
, pragma_compound
))
4617 last_label
= false, last_stmt
= true;
4619 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4621 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4622 c_parser_error (parser
, "expected declaration or statement");
4625 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4627 if (parser
->in_if_block
)
4629 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4630 error_at (loc
, """expected %<}%> before %<else%>");
4635 error_at (loc
, "%<else%> without a previous %<if%>");
4636 c_parser_consume_token (parser
);
4645 mark_valid_location_for_stdc_pragma (false);
4646 c_parser_statement_after_labels (parser
);
4649 parser
->error
= false;
4652 error_at (label_loc
, "label at end of compound statement");
4653 c_parser_consume_token (parser
);
4654 /* Restore the value we started with. */
4655 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4658 /* Parse a label (C90 6.6.1, C99 6.8.1).
4661 identifier : attributes[opt]
4662 case constant-expression :
4668 case constant-expression ... constant-expression :
4670 The use of attributes on labels is a GNU extension. The syntax in
4671 GNU C accepts any expressions without commas, non-constant
4672 expressions being rejected later. */
4675 c_parser_label (c_parser
*parser
)
4677 location_t loc1
= c_parser_peek_token (parser
)->location
;
4678 tree label
= NULL_TREE
;
4679 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4682 c_parser_consume_token (parser
);
4683 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4684 if (c_parser_next_token_is (parser
, CPP_COLON
))
4686 c_parser_consume_token (parser
);
4687 label
= do_case (loc1
, exp1
, NULL_TREE
);
4689 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4691 c_parser_consume_token (parser
);
4692 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4693 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4694 label
= do_case (loc1
, exp1
, exp2
);
4697 c_parser_error (parser
, "expected %<:%> or %<...%>");
4699 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4701 c_parser_consume_token (parser
);
4702 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4703 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4707 tree name
= c_parser_peek_token (parser
)->value
;
4710 location_t loc2
= c_parser_peek_token (parser
)->location
;
4711 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4712 c_parser_consume_token (parser
);
4713 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4714 c_parser_consume_token (parser
);
4715 attrs
= c_parser_attributes (parser
);
4716 tlab
= define_label (loc2
, name
);
4719 decl_attributes (&tlab
, attrs
, 0);
4720 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4725 if (c_parser_next_tokens_start_declaration (parser
))
4727 error_at (c_parser_peek_token (parser
)->location
,
4728 "a label can only be part of a statement and "
4729 "a declaration is not a statement");
4730 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4731 /*static_assert_ok*/ true,
4732 /*empty_ok*/ true, /*nested*/ true,
4733 /*start_attr_ok*/ true, NULL
,
4739 /* Parse a statement (C90 6.6, C99 6.8).
4744 expression-statement
4752 expression-statement:
4755 selection-statement:
4759 iteration-statement:
4768 return expression[opt] ;
4781 objc-throw-statement
4782 objc-try-catch-statement
4783 objc-synchronized-statement
4785 objc-throw-statement:
4801 parallel-for-construct
4802 parallel-for-simd-construct
4803 parallel-sections-construct
4810 parallel-directive structured-block
4813 for-directive iteration-statement
4816 simd-directive iteration-statements
4819 for-simd-directive iteration-statements
4822 sections-directive section-scope
4825 single-directive structured-block
4827 parallel-for-construct:
4828 parallel-for-directive iteration-statement
4830 parallel-for-simd-construct:
4831 parallel-for-simd-directive iteration-statement
4833 parallel-sections-construct:
4834 parallel-sections-directive section-scope
4837 master-directive structured-block
4840 critical-directive structured-block
4843 atomic-directive expression-statement
4846 ordered-directive structured-block
4848 Transactional Memory:
4851 transaction-statement
4852 transaction-cancel-statement
4856 c_parser_statement (c_parser
*parser
)
4858 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4859 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4860 || (c_parser_next_token_is (parser
, CPP_NAME
)
4861 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4862 c_parser_label (parser
);
4863 c_parser_statement_after_labels (parser
);
4866 /* Parse a statement, other than a labeled statement. */
4869 c_parser_statement_after_labels (c_parser
*parser
)
4871 location_t loc
= c_parser_peek_token (parser
)->location
;
4872 tree stmt
= NULL_TREE
;
4873 bool in_if_block
= parser
->in_if_block
;
4874 parser
->in_if_block
= false;
4875 switch (c_parser_peek_token (parser
)->type
)
4877 case CPP_OPEN_BRACE
:
4878 add_stmt (c_parser_compound_statement (parser
));
4881 switch (c_parser_peek_token (parser
)->keyword
)
4884 c_parser_if_statement (parser
);
4887 c_parser_switch_statement (parser
);
4890 c_parser_while_statement (parser
, false);
4893 c_parser_do_statement (parser
, false);
4896 c_parser_for_statement (parser
, false);
4899 c_parser_consume_token (parser
);
4900 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4902 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4904 add_stmt (build_cilk_sync ());
4907 c_parser_consume_token (parser
);
4908 if (c_parser_next_token_is (parser
, CPP_NAME
))
4910 stmt
= c_finish_goto_label (loc
,
4911 c_parser_peek_token (parser
)->value
);
4912 c_parser_consume_token (parser
);
4914 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4918 c_parser_consume_token (parser
);
4919 val
= c_parser_expression (parser
);
4920 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4921 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4924 c_parser_error (parser
, "expected identifier or %<*%>");
4925 goto expect_semicolon
;
4927 c_parser_consume_token (parser
);
4928 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4929 goto expect_semicolon
;
4931 c_parser_consume_token (parser
);
4932 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4933 goto expect_semicolon
;
4935 c_parser_consume_token (parser
);
4936 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4938 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4939 c_parser_consume_token (parser
);
4943 location_t xloc
= c_parser_peek_token (parser
)->location
;
4944 struct c_expr expr
= c_parser_expression_conv (parser
);
4945 mark_exp_read (expr
.value
);
4946 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
4947 goto expect_semicolon
;
4951 stmt
= c_parser_asm_statement (parser
);
4953 case RID_TRANSACTION_ATOMIC
:
4954 case RID_TRANSACTION_RELAXED
:
4955 stmt
= c_parser_transaction (parser
,
4956 c_parser_peek_token (parser
)->keyword
);
4958 case RID_TRANSACTION_CANCEL
:
4959 stmt
= c_parser_transaction_cancel (parser
);
4960 goto expect_semicolon
;
4962 gcc_assert (c_dialect_objc ());
4963 c_parser_consume_token (parser
);
4964 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4966 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4967 c_parser_consume_token (parser
);
4971 struct c_expr expr
= c_parser_expression (parser
);
4972 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
4973 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4974 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
4975 goto expect_semicolon
;
4979 gcc_assert (c_dialect_objc ());
4980 c_parser_objc_try_catch_finally_statement (parser
);
4982 case RID_AT_SYNCHRONIZED
:
4983 gcc_assert (c_dialect_objc ());
4984 c_parser_objc_synchronized_statement (parser
);
4991 c_parser_consume_token (parser
);
4993 case CPP_CLOSE_PAREN
:
4994 case CPP_CLOSE_SQUARE
:
4995 /* Avoid infinite loop in error recovery:
4996 c_parser_skip_until_found stops at a closing nesting
4997 delimiter without consuming it, but here we need to consume
4998 it to proceed further. */
4999 c_parser_error (parser
, "expected statement");
5000 c_parser_consume_token (parser
);
5003 c_parser_pragma (parser
, pragma_stmt
);
5007 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5009 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5012 /* Two cases cannot and do not have line numbers associated: If stmt
5013 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5014 cannot hold line numbers. But that's OK because the statement
5015 will either be changed to a MODIFY_EXPR during gimplification of
5016 the statement expr, or discarded. If stmt was compound, but
5017 without new variables, we will have skipped the creation of a
5018 BIND and will have a bare STATEMENT_LIST. But that's OK because
5019 (recursively) all of the component statements should already have
5020 line numbers assigned. ??? Can we discard no-op statements
5022 if (CAN_HAVE_LOCATION_P (stmt
)
5023 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5024 SET_EXPR_LOCATION (stmt
, loc
);
5026 parser
->in_if_block
= in_if_block
;
5029 /* Parse the condition from an if, do, while or for statements. */
5032 c_parser_condition (c_parser
*parser
)
5034 location_t loc
= c_parser_peek_token (parser
)->location
;
5036 cond
= c_parser_expression_conv (parser
).value
;
5037 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5038 cond
= c_fully_fold (cond
, false, NULL
);
5039 if (warn_sequence_point
)
5040 verify_sequence_points (cond
);
5044 /* Parse a parenthesized condition from an if, do or while statement.
5050 c_parser_paren_condition (c_parser
*parser
)
5053 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5054 return error_mark_node
;
5055 cond
= c_parser_condition (parser
);
5056 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5060 /* Parse a statement which is a block in C99. */
5063 c_parser_c99_block_statement (c_parser
*parser
)
5065 tree block
= c_begin_compound_stmt (flag_isoc99
);
5066 location_t loc
= c_parser_peek_token (parser
)->location
;
5067 c_parser_statement (parser
);
5068 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5071 /* Parse the body of an if statement. This is just parsing a
5072 statement but (a) it is a block in C99, (b) we track whether the
5073 body is an if statement for the sake of -Wparentheses warnings, (c)
5074 we handle an empty body specially for the sake of -Wempty-body
5075 warnings, and (d) we call parser_compound_statement directly
5076 because c_parser_statement_after_labels resets
5077 parser->in_if_block. */
5080 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5082 tree block
= c_begin_compound_stmt (flag_isoc99
);
5083 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5084 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5085 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5086 || (c_parser_next_token_is (parser
, CPP_NAME
)
5087 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5088 c_parser_label (parser
);
5089 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5090 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5092 location_t loc
= c_parser_peek_token (parser
)->location
;
5093 add_stmt (build_empty_stmt (loc
));
5094 c_parser_consume_token (parser
);
5095 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5096 warning_at (loc
, OPT_Wempty_body
,
5097 "suggest braces around empty body in an %<if%> statement");
5099 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5100 add_stmt (c_parser_compound_statement (parser
));
5102 c_parser_statement_after_labels (parser
);
5103 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5106 /* Parse the else body of an if statement. This is just parsing a
5107 statement but (a) it is a block in C99, (b) we handle an empty body
5108 specially for the sake of -Wempty-body warnings. */
5111 c_parser_else_body (c_parser
*parser
)
5113 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5114 tree block
= c_begin_compound_stmt (flag_isoc99
);
5115 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5116 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5117 || (c_parser_next_token_is (parser
, CPP_NAME
)
5118 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5119 c_parser_label (parser
);
5120 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5122 location_t loc
= c_parser_peek_token (parser
)->location
;
5125 "suggest braces around empty body in an %<else%> statement");
5126 add_stmt (build_empty_stmt (loc
));
5127 c_parser_consume_token (parser
);
5130 c_parser_statement_after_labels (parser
);
5131 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5134 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5137 if ( expression ) statement
5138 if ( expression ) statement else statement
5142 c_parser_if_statement (c_parser
*parser
)
5147 bool first_if
= false;
5148 tree first_body
, second_body
;
5152 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5153 c_parser_consume_token (parser
);
5154 block
= c_begin_compound_stmt (flag_isoc99
);
5155 loc
= c_parser_peek_token (parser
)->location
;
5156 cond
= c_parser_paren_condition (parser
);
5157 in_if_block
= parser
->in_if_block
;
5158 parser
->in_if_block
= true;
5159 first_body
= c_parser_if_body (parser
, &first_if
);
5160 parser
->in_if_block
= in_if_block
;
5161 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5163 c_parser_consume_token (parser
);
5164 second_body
= c_parser_else_body (parser
);
5167 second_body
= NULL_TREE
;
5168 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5169 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5171 /* If the if statement contains array notations, then we expand them. */
5172 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5173 if_stmt
= fix_conditional_array_notations (if_stmt
);
5177 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5180 switch (expression) statement
5184 c_parser_switch_statement (c_parser
*parser
)
5187 tree block
, expr
, body
, save_break
;
5188 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5189 location_t switch_cond_loc
;
5190 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5191 c_parser_consume_token (parser
);
5192 block
= c_begin_compound_stmt (flag_isoc99
);
5193 bool explicit_cast_p
= false;
5194 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5196 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5197 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5198 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5199 explicit_cast_p
= true;
5200 ce
= c_parser_expression (parser
);
5201 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5203 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5205 error_at (switch_cond_loc
,
5206 "array notations cannot be used as a condition for switch "
5208 expr
= error_mark_node
;
5210 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5214 switch_cond_loc
= UNKNOWN_LOCATION
;
5215 expr
= error_mark_node
;
5217 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5218 save_break
= c_break_label
;
5219 c_break_label
= NULL_TREE
;
5220 body
= c_parser_c99_block_statement (parser
);
5221 c_finish_case (body
);
5224 location_t here
= c_parser_peek_token (parser
)->location
;
5225 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5226 SET_EXPR_LOCATION (t
, here
);
5229 c_break_label
= save_break
;
5230 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5233 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5236 while (expression) statement
5240 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5242 tree block
, cond
, body
, save_break
, save_cont
;
5244 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5245 c_parser_consume_token (parser
);
5246 block
= c_begin_compound_stmt (flag_isoc99
);
5247 loc
= c_parser_peek_token (parser
)->location
;
5248 cond
= c_parser_paren_condition (parser
);
5249 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5251 error_at (loc
, "array notations cannot be used as a condition for while "
5253 cond
= error_mark_node
;
5256 if (ivdep
&& cond
!= error_mark_node
)
5257 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5258 build_int_cst (integer_type_node
,
5259 annot_expr_ivdep_kind
));
5260 save_break
= c_break_label
;
5261 c_break_label
= NULL_TREE
;
5262 save_cont
= c_cont_label
;
5263 c_cont_label
= NULL_TREE
;
5264 body
= c_parser_c99_block_statement (parser
);
5265 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5266 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5267 c_break_label
= save_break
;
5268 c_cont_label
= save_cont
;
5271 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5274 do statement while ( expression ) ;
5278 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5280 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5282 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5283 c_parser_consume_token (parser
);
5284 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5285 warning_at (c_parser_peek_token (parser
)->location
,
5287 "suggest braces around empty body in %<do%> statement");
5288 block
= c_begin_compound_stmt (flag_isoc99
);
5289 loc
= c_parser_peek_token (parser
)->location
;
5290 save_break
= c_break_label
;
5291 c_break_label
= NULL_TREE
;
5292 save_cont
= c_cont_label
;
5293 c_cont_label
= NULL_TREE
;
5294 body
= c_parser_c99_block_statement (parser
);
5295 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5296 new_break
= c_break_label
;
5297 c_break_label
= save_break
;
5298 new_cont
= c_cont_label
;
5299 c_cont_label
= save_cont
;
5300 cond
= c_parser_paren_condition (parser
);
5301 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5303 error_at (loc
, "array notations cannot be used as a condition for a "
5304 "do-while statement");
5305 cond
= error_mark_node
;
5307 if (ivdep
&& cond
!= error_mark_node
)
5308 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5309 build_int_cst (integer_type_node
,
5310 annot_expr_ivdep_kind
));
5311 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5312 c_parser_skip_to_end_of_block_or_statement (parser
);
5313 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5314 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5317 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5320 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5321 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5323 The form with a declaration is new in C99.
5325 ??? In accordance with the old parser, the declaration may be a
5326 nested function, which is then rejected in check_for_loop_decls,
5327 but does it make any sense for this to be included in the grammar?
5328 Note in particular that the nested function does not include a
5329 trailing ';', whereas the "declaration" production includes one.
5330 Also, can we reject bad declarations earlier and cheaper than
5331 check_for_loop_decls?
5333 In Objective-C, there are two additional variants:
5336 for ( expression in expresssion ) statement
5337 for ( declaration in expression ) statement
5339 This is inconsistent with C, because the second variant is allowed
5340 even if c99 is not enabled.
5342 The rest of the comment documents these Objective-C foreach-statement.
5344 Here is the canonical example of the first variant:
5345 for (object in array) { do something with object }
5346 we call the first expression ("object") the "object_expression" and
5347 the second expression ("array") the "collection_expression".
5348 object_expression must be an lvalue of type "id" (a generic Objective-C
5349 object) because the loop works by assigning to object_expression the
5350 various objects from the collection_expression. collection_expression
5351 must evaluate to something of type "id" which responds to the method
5352 countByEnumeratingWithState:objects:count:.
5354 The canonical example of the second variant is:
5355 for (id object in array) { do something with object }
5356 which is completely equivalent to
5359 for (object in array) { do something with object }
5361 Note that initizializing 'object' in some way (eg, "for ((object =
5362 xxx) in array) { do something with object }") is possibly
5363 technically valid, but completely pointless as 'object' will be
5364 assigned to something else as soon as the loop starts. We should
5365 most likely reject it (TODO).
5367 The beginning of the Objective-C foreach-statement looks exactly
5368 like the beginning of the for-statement, and we can tell it is a
5369 foreach-statement only because the initial declaration or
5370 expression is terminated by 'in' instead of ';'.
5374 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5376 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5377 /* The following are only used when parsing an ObjC foreach statement. */
5378 tree object_expression
;
5379 /* Silence the bogus uninitialized warning. */
5380 tree collection_expression
= NULL
;
5381 location_t loc
= c_parser_peek_token (parser
)->location
;
5382 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5383 bool is_foreach_statement
= false;
5384 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5385 c_parser_consume_token (parser
);
5386 /* Open a compound statement in Objective-C as well, just in case this is
5387 as foreach expression. */
5388 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5389 cond
= error_mark_node
;
5390 incr
= error_mark_node
;
5391 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5393 /* Parse the initialization declaration or expression. */
5394 object_expression
= error_mark_node
;
5395 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5396 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5398 parser
->objc_could_be_foreach_context
= false;
5399 c_parser_consume_token (parser
);
5400 c_finish_expr_stmt (loc
, NULL_TREE
);
5402 else if (c_parser_next_tokens_start_declaration (parser
))
5404 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5405 &object_expression
, vNULL
);
5406 parser
->objc_could_be_foreach_context
= false;
5408 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5410 c_parser_consume_token (parser
);
5411 is_foreach_statement
= true;
5412 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5413 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5416 check_for_loop_decls (for_loc
, flag_isoc99
);
5418 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5420 /* __extension__ can start a declaration, but is also an
5421 unary operator that can start an expression. Consume all
5422 but the last of a possible series of __extension__ to
5424 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5425 && (c_parser_peek_2nd_token (parser
)->keyword
5427 c_parser_consume_token (parser
);
5428 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5431 ext
= disable_extension_diagnostics ();
5432 c_parser_consume_token (parser
);
5433 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5434 true, &object_expression
, vNULL
);
5435 parser
->objc_could_be_foreach_context
= false;
5437 restore_extension_diagnostics (ext
);
5438 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5440 c_parser_consume_token (parser
);
5441 is_foreach_statement
= true;
5442 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5443 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5446 check_for_loop_decls (for_loc
, flag_isoc99
);
5456 tree init_expression
;
5457 ce
= c_parser_expression (parser
);
5458 init_expression
= ce
.value
;
5459 parser
->objc_could_be_foreach_context
= false;
5460 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5462 c_parser_consume_token (parser
);
5463 is_foreach_statement
= true;
5464 if (! lvalue_p (init_expression
))
5465 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5466 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5470 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5471 init_expression
= ce
.value
;
5472 c_finish_expr_stmt (loc
, init_expression
);
5473 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5477 /* Parse the loop condition. In the case of a foreach
5478 statement, there is no loop condition. */
5479 gcc_assert (!parser
->objc_could_be_foreach_context
);
5480 if (!is_foreach_statement
)
5482 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5486 c_parser_error (parser
, "missing loop condition in loop with "
5487 "%<GCC ivdep%> pragma");
5488 cond
= error_mark_node
;
5492 c_parser_consume_token (parser
);
5498 cond
= c_parser_condition (parser
);
5499 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5501 error_at (loc
, "array notations cannot be used in a "
5502 "condition for a for-loop");
5503 cond
= error_mark_node
;
5505 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5508 if (ivdep
&& cond
!= error_mark_node
)
5509 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5510 build_int_cst (integer_type_node
,
5511 annot_expr_ivdep_kind
));
5513 /* Parse the increment expression (the third expression in a
5514 for-statement). In the case of a foreach-statement, this is
5515 the expression that follows the 'in'. */
5516 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5518 if (is_foreach_statement
)
5520 c_parser_error (parser
, "missing collection in fast enumeration");
5521 collection_expression
= error_mark_node
;
5524 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5528 if (is_foreach_statement
)
5529 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5533 struct c_expr ce
= c_parser_expression (parser
);
5534 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5535 incr
= c_process_expr_stmt (loc
, ce
.value
);
5538 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5540 save_break
= c_break_label
;
5541 c_break_label
= NULL_TREE
;
5542 save_cont
= c_cont_label
;
5543 c_cont_label
= NULL_TREE
;
5544 body
= c_parser_c99_block_statement (parser
);
5545 if (is_foreach_statement
)
5546 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5548 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5549 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5550 c_break_label
= save_break
;
5551 c_cont_label
= save_cont
;
5554 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5555 statement with inputs, outputs, clobbers, and volatile tag
5559 asm type-qualifier[opt] ( asm-argument ) ;
5560 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5564 asm-string-literal : asm-operands[opt]
5565 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5566 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5569 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5572 Qualifiers other than volatile are accepted in the syntax but
5576 c_parser_asm_statement (c_parser
*parser
)
5578 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5579 bool simple
, is_goto
;
5580 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5581 int section
, nsections
;
5583 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5584 c_parser_consume_token (parser
);
5585 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5587 quals
= c_parser_peek_token (parser
)->value
;
5588 c_parser_consume_token (parser
);
5590 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5591 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5593 warning_at (c_parser_peek_token (parser
)->location
,
5595 "%E qualifier ignored on asm",
5596 c_parser_peek_token (parser
)->value
);
5598 c_parser_consume_token (parser
);
5604 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5606 c_parser_consume_token (parser
);
5610 /* ??? Follow the C++ parser rather than using the
5611 lex_untranslated_string kludge. */
5612 parser
->lex_untranslated_string
= true;
5615 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5618 str
= c_parser_asm_string_literal (parser
);
5619 if (str
== NULL_TREE
)
5620 goto error_close_paren
;
5623 outputs
= NULL_TREE
;
5625 clobbers
= NULL_TREE
;
5628 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5631 /* Parse each colon-delimited section of operands. */
5632 nsections
= 3 + is_goto
;
5633 for (section
= 0; section
< nsections
; ++section
)
5635 if (!c_parser_require (parser
, CPP_COLON
,
5638 : "expected %<:%> or %<)%>"))
5639 goto error_close_paren
;
5641 /* Once past any colon, we're no longer a simple asm. */
5644 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5645 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5650 /* For asm goto, we don't allow output operands, but reserve
5651 the slot for a future extension that does allow them. */
5653 outputs
= c_parser_asm_operands (parser
);
5656 inputs
= c_parser_asm_operands (parser
);
5659 clobbers
= c_parser_asm_clobbers (parser
);
5662 labels
= c_parser_asm_goto_operands (parser
);
5668 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5673 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5675 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5679 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5680 c_parser_skip_to_end_of_block_or_statement (parser
);
5682 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5683 clobbers
, labels
, simple
));
5686 parser
->lex_untranslated_string
= false;
5690 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5694 /* Parse asm operands, a GNU extension.
5698 asm-operands , asm-operand
5701 asm-string-literal ( expression )
5702 [ identifier ] asm-string-literal ( expression )
5706 c_parser_asm_operands (c_parser
*parser
)
5708 tree list
= NULL_TREE
;
5713 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5715 c_parser_consume_token (parser
);
5716 if (c_parser_next_token_is (parser
, CPP_NAME
))
5718 tree id
= c_parser_peek_token (parser
)->value
;
5719 c_parser_consume_token (parser
);
5720 name
= build_string (IDENTIFIER_LENGTH (id
),
5721 IDENTIFIER_POINTER (id
));
5725 c_parser_error (parser
, "expected identifier");
5726 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5729 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5734 str
= c_parser_asm_string_literal (parser
);
5735 if (str
== NULL_TREE
)
5737 parser
->lex_untranslated_string
= false;
5738 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5740 parser
->lex_untranslated_string
= true;
5743 expr
= c_parser_expression (parser
);
5744 mark_exp_read (expr
.value
);
5745 parser
->lex_untranslated_string
= true;
5746 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5748 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5751 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5753 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5754 c_parser_consume_token (parser
);
5761 /* Parse asm clobbers, a GNU extension.
5765 asm-clobbers , asm-string-literal
5769 c_parser_asm_clobbers (c_parser
*parser
)
5771 tree list
= NULL_TREE
;
5774 tree str
= c_parser_asm_string_literal (parser
);
5776 list
= tree_cons (NULL_TREE
, str
, list
);
5779 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5780 c_parser_consume_token (parser
);
5787 /* Parse asm goto labels, a GNU extension.
5791 asm-goto-operands , identifier
5795 c_parser_asm_goto_operands (c_parser
*parser
)
5797 tree list
= NULL_TREE
;
5802 if (c_parser_next_token_is (parser
, CPP_NAME
))
5804 c_token
*tok
= c_parser_peek_token (parser
);
5806 label
= lookup_label_for_goto (tok
->location
, name
);
5807 c_parser_consume_token (parser
);
5808 TREE_USED (label
) = 1;
5812 c_parser_error (parser
, "expected identifier");
5816 name
= build_string (IDENTIFIER_LENGTH (name
),
5817 IDENTIFIER_POINTER (name
));
5818 list
= tree_cons (name
, label
, list
);
5819 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5820 c_parser_consume_token (parser
);
5822 return nreverse (list
);
5826 /* Parse an expression other than a compound expression; that is, an
5827 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5828 NULL then it is an Objective-C message expression which is the
5829 primary-expression starting the expression as an initializer.
5831 assignment-expression:
5832 conditional-expression
5833 unary-expression assignment-operator assignment-expression
5835 assignment-operator: one of
5836 = *= /= %= += -= <<= >>= &= ^= |=
5838 In GNU C we accept any conditional expression on the LHS and
5839 diagnose the invalid lvalue rather than producing a syntax
5842 static struct c_expr
5843 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5844 tree omp_atomic_lhs
)
5846 struct c_expr lhs
, rhs
, ret
;
5847 enum tree_code code
;
5848 location_t op_location
, exp_location
;
5849 gcc_assert (!after
|| c_dialect_objc ());
5850 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5851 op_location
= c_parser_peek_token (parser
)->location
;
5852 switch (c_parser_peek_token (parser
)->type
)
5861 code
= TRUNC_DIV_EXPR
;
5864 code
= TRUNC_MOD_EXPR
;
5879 code
= BIT_AND_EXPR
;
5882 code
= BIT_XOR_EXPR
;
5885 code
= BIT_IOR_EXPR
;
5890 c_parser_consume_token (parser
);
5891 exp_location
= c_parser_peek_token (parser
)->location
;
5892 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5893 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5895 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5896 code
, exp_location
, rhs
.value
,
5898 if (code
== NOP_EXPR
)
5899 ret
.original_code
= MODIFY_EXPR
;
5902 TREE_NO_WARNING (ret
.value
) = 1;
5903 ret
.original_code
= ERROR_MARK
;
5905 ret
.original_type
= NULL
;
5909 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5910 is not NULL then it is an Objective-C message expression which is
5911 the primary-expression starting the expression as an initializer.
5913 conditional-expression:
5914 logical-OR-expression
5915 logical-OR-expression ? expression : conditional-expression
5919 conditional-expression:
5920 logical-OR-expression ? : conditional-expression
5923 static struct c_expr
5924 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5925 tree omp_atomic_lhs
)
5927 struct c_expr cond
, exp1
, exp2
, ret
;
5928 location_t cond_loc
, colon_loc
, middle_loc
;
5930 gcc_assert (!after
|| c_dialect_objc ());
5932 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5934 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5936 cond_loc
= c_parser_peek_token (parser
)->location
;
5937 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5938 c_parser_consume_token (parser
);
5939 if (c_parser_next_token_is (parser
, CPP_COLON
))
5941 tree eptype
= NULL_TREE
;
5943 middle_loc
= c_parser_peek_token (parser
)->location
;
5944 pedwarn (middle_loc
, OPT_Wpedantic
,
5945 "ISO C forbids omitting the middle term of a ?: expression");
5946 warn_for_omitted_condop (middle_loc
, cond
.value
);
5947 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5949 eptype
= TREE_TYPE (cond
.value
);
5950 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5952 /* Make sure first operand is calculated only once. */
5953 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5955 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5956 exp1
.original_type
= NULL
;
5957 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5958 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5963 = c_objc_common_truthvalue_conversion
5964 (cond_loc
, default_conversion (cond
.value
));
5965 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5966 exp1
= c_parser_expression_conv (parser
);
5967 mark_exp_read (exp1
.value
);
5968 c_inhibit_evaluation_warnings
+=
5969 ((cond
.value
== truthvalue_true_node
)
5970 - (cond
.value
== truthvalue_false_node
));
5973 colon_loc
= c_parser_peek_token (parser
)->location
;
5974 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5976 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5977 ret
.value
= error_mark_node
;
5978 ret
.original_code
= ERROR_MARK
;
5979 ret
.original_type
= NULL
;
5983 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5984 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5985 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
5987 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5988 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5989 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5990 exp1
.value
, exp1
.original_type
,
5991 exp2
.value
, exp2
.original_type
);
5992 ret
.original_code
= ERROR_MARK
;
5993 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5994 ret
.original_type
= NULL
;
5999 /* If both sides are enum type, the default conversion will have
6000 made the type of the result be an integer type. We want to
6001 remember the enum types we started with. */
6002 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6003 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6004 ret
.original_type
= ((t1
!= error_mark_node
6005 && t2
!= error_mark_node
6006 && (TYPE_MAIN_VARIANT (t1
)
6007 == TYPE_MAIN_VARIANT (t2
)))
6014 /* Parse a binary expression; that is, a logical-OR-expression (C90
6015 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6016 an Objective-C message expression which is the primary-expression
6017 starting the expression as an initializer.
6019 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6020 when it should be the unfolded lhs. In a valid OpenMP source,
6021 one of the operands of the toplevel binary expression must be equal
6022 to it. In that case, just return a build2 created binary operation
6023 rather than result of parser_build_binary_op.
6025 multiplicative-expression:
6027 multiplicative-expression * cast-expression
6028 multiplicative-expression / cast-expression
6029 multiplicative-expression % cast-expression
6031 additive-expression:
6032 multiplicative-expression
6033 additive-expression + multiplicative-expression
6034 additive-expression - multiplicative-expression
6038 shift-expression << additive-expression
6039 shift-expression >> additive-expression
6041 relational-expression:
6043 relational-expression < shift-expression
6044 relational-expression > shift-expression
6045 relational-expression <= shift-expression
6046 relational-expression >= shift-expression
6048 equality-expression:
6049 relational-expression
6050 equality-expression == relational-expression
6051 equality-expression != relational-expression
6055 AND-expression & equality-expression
6057 exclusive-OR-expression:
6059 exclusive-OR-expression ^ AND-expression
6061 inclusive-OR-expression:
6062 exclusive-OR-expression
6063 inclusive-OR-expression | exclusive-OR-expression
6065 logical-AND-expression:
6066 inclusive-OR-expression
6067 logical-AND-expression && inclusive-OR-expression
6069 logical-OR-expression:
6070 logical-AND-expression
6071 logical-OR-expression || logical-AND-expression
6074 static struct c_expr
6075 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6076 tree omp_atomic_lhs
)
6078 /* A binary expression is parsed using operator-precedence parsing,
6079 with the operands being cast expressions. All the binary
6080 operators are left-associative. Thus a binary expression is of
6083 E0 op1 E1 op2 E2 ...
6085 which we represent on a stack. On the stack, the precedence
6086 levels are strictly increasing. When a new operator is
6087 encountered of higher precedence than that at the top of the
6088 stack, it is pushed; its LHS is the top expression, and its RHS
6089 is everything parsed until it is popped. When a new operator is
6090 encountered with precedence less than or equal to that at the top
6091 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6092 by the result of the operation until the operator at the top of
6093 the stack has lower precedence than the new operator or there is
6094 only one element on the stack; then the top expression is the LHS
6095 of the new operator. In the case of logical AND and OR
6096 expressions, we also need to adjust c_inhibit_evaluation_warnings
6097 as appropriate when the operators are pushed and popped. */
6100 /* The expression at this stack level. */
6102 /* The precedence of the operator on its left, PREC_NONE at the
6103 bottom of the stack. */
6104 enum c_parser_prec prec
;
6105 /* The operation on its left. */
6107 /* The source location of this operation. */
6111 /* Location of the binary operator. */
6112 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6115 switch (stack[sp].op) \
6117 case TRUTH_ANDIF_EXPR: \
6118 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6119 == truthvalue_false_node); \
6121 case TRUTH_ORIF_EXPR: \
6122 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6123 == truthvalue_true_node); \
6128 stack[sp - 1].expr \
6129 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6130 stack[sp - 1].expr, true, true); \
6132 = convert_lvalue_to_rvalue (stack[sp].loc, \
6133 stack[sp].expr, true, true); \
6134 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6135 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6136 && ((1 << stack[sp].prec) \
6137 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6138 | PREC_ADD | PREC_MULT))) \
6139 && stack[sp].op != TRUNC_MOD_EXPR \
6140 && stack[0].expr.value != error_mark_node \
6141 && stack[1].expr.value != error_mark_node \
6142 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6143 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6144 stack[0].expr.value \
6145 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6146 stack[0].expr.value, stack[1].expr.value); \
6148 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6150 stack[sp - 1].expr, \
6154 gcc_assert (!after
|| c_dialect_objc ());
6155 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6156 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6157 stack
[0].prec
= PREC_NONE
;
6161 enum c_parser_prec oprec
;
6162 enum tree_code ocode
;
6165 switch (c_parser_peek_token (parser
)->type
)
6173 ocode
= TRUNC_DIV_EXPR
;
6177 ocode
= TRUNC_MOD_EXPR
;
6189 ocode
= LSHIFT_EXPR
;
6193 ocode
= RSHIFT_EXPR
;
6207 case CPP_GREATER_EQ
:
6220 oprec
= PREC_BITAND
;
6221 ocode
= BIT_AND_EXPR
;
6224 oprec
= PREC_BITXOR
;
6225 ocode
= BIT_XOR_EXPR
;
6229 ocode
= BIT_IOR_EXPR
;
6232 oprec
= PREC_LOGAND
;
6233 ocode
= TRUTH_ANDIF_EXPR
;
6237 ocode
= TRUTH_ORIF_EXPR
;
6240 /* Not a binary operator, so end of the binary
6244 binary_loc
= c_parser_peek_token (parser
)->location
;
6245 while (oprec
<= stack
[sp
].prec
)
6247 c_parser_consume_token (parser
);
6250 case TRUTH_ANDIF_EXPR
:
6252 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6253 stack
[sp
].expr
, true, true);
6254 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6255 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6256 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6257 == truthvalue_false_node
);
6259 case TRUTH_ORIF_EXPR
:
6261 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6262 stack
[sp
].expr
, true, true);
6263 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6264 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6265 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6266 == truthvalue_true_node
);
6272 stack
[sp
].loc
= binary_loc
;
6273 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6274 stack
[sp
].prec
= oprec
;
6275 stack
[sp
].op
= ocode
;
6276 stack
[sp
].loc
= binary_loc
;
6281 return stack
[0].expr
;
6285 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6286 NULL then it is an Objective-C message expression which is the
6287 primary-expression starting the expression as an initializer.
6291 ( type-name ) unary-expression
6294 static struct c_expr
6295 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6297 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6298 gcc_assert (!after
|| c_dialect_objc ());
6300 return c_parser_postfix_expression_after_primary (parser
,
6302 /* If the expression begins with a parenthesized type name, it may
6303 be either a cast or a compound literal; we need to see whether
6304 the next character is '{' to tell the difference. If not, it is
6305 an unary expression. Full detection of unknown typenames here
6306 would require a 3-token lookahead. */
6307 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6308 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6310 struct c_type_name
*type_name
;
6313 c_parser_consume_token (parser
);
6314 type_name
= c_parser_type_name (parser
);
6315 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6316 if (type_name
== NULL
)
6318 ret
.value
= error_mark_node
;
6319 ret
.original_code
= ERROR_MARK
;
6320 ret
.original_type
= NULL
;
6324 /* Save casted types in the function's used types hash table. */
6325 used_types_insert (type_name
->specs
->type
);
6327 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6328 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6331 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6332 expr
= c_parser_cast_expression (parser
, NULL
);
6333 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6335 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6336 ret
.original_code
= ERROR_MARK
;
6337 ret
.original_type
= NULL
;
6341 return c_parser_unary_expression (parser
);
6344 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6350 unary-operator cast-expression
6351 sizeof unary-expression
6352 sizeof ( type-name )
6354 unary-operator: one of
6360 __alignof__ unary-expression
6361 __alignof__ ( type-name )
6364 (C11 permits _Alignof with type names only.)
6366 unary-operator: one of
6367 __extension__ __real__ __imag__
6369 Transactional Memory:
6372 transaction-expression
6374 In addition, the GNU syntax treats ++ and -- as unary operators, so
6375 they may be applied to cast expressions with errors for non-lvalues
6378 static struct c_expr
6379 c_parser_unary_expression (c_parser
*parser
)
6382 struct c_expr ret
, op
;
6383 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6385 ret
.original_code
= ERROR_MARK
;
6386 ret
.original_type
= NULL
;
6387 switch (c_parser_peek_token (parser
)->type
)
6390 c_parser_consume_token (parser
);
6391 exp_loc
= c_parser_peek_token (parser
)->location
;
6392 op
= c_parser_cast_expression (parser
, NULL
);
6394 /* If there is array notations in op, we expand them. */
6395 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6396 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6399 op
= default_function_array_read_conversion (exp_loc
, op
);
6400 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6402 case CPP_MINUS_MINUS
:
6403 c_parser_consume_token (parser
);
6404 exp_loc
= c_parser_peek_token (parser
)->location
;
6405 op
= c_parser_cast_expression (parser
, NULL
);
6407 /* If there is array notations in op, we expand them. */
6408 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6409 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6412 op
= default_function_array_read_conversion (exp_loc
, op
);
6413 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6416 c_parser_consume_token (parser
);
6417 op
= c_parser_cast_expression (parser
, NULL
);
6418 mark_exp_read (op
.value
);
6419 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6421 c_parser_consume_token (parser
);
6422 exp_loc
= c_parser_peek_token (parser
)->location
;
6423 op
= c_parser_cast_expression (parser
, NULL
);
6424 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6425 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6428 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6431 "traditional C rejects the unary plus operator");
6432 c_parser_consume_token (parser
);
6433 exp_loc
= c_parser_peek_token (parser
)->location
;
6434 op
= c_parser_cast_expression (parser
, NULL
);
6435 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6436 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6438 c_parser_consume_token (parser
);
6439 exp_loc
= c_parser_peek_token (parser
)->location
;
6440 op
= c_parser_cast_expression (parser
, NULL
);
6441 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6442 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6444 c_parser_consume_token (parser
);
6445 exp_loc
= c_parser_peek_token (parser
)->location
;
6446 op
= c_parser_cast_expression (parser
, NULL
);
6447 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6448 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6450 c_parser_consume_token (parser
);
6451 exp_loc
= c_parser_peek_token (parser
)->location
;
6452 op
= c_parser_cast_expression (parser
, NULL
);
6453 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6454 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6456 /* Refer to the address of a label as a pointer. */
6457 c_parser_consume_token (parser
);
6458 if (c_parser_next_token_is (parser
, CPP_NAME
))
6460 ret
.value
= finish_label_address_expr
6461 (c_parser_peek_token (parser
)->value
, op_loc
);
6462 c_parser_consume_token (parser
);
6466 c_parser_error (parser
, "expected identifier");
6467 ret
.value
= error_mark_node
;
6471 switch (c_parser_peek_token (parser
)->keyword
)
6474 return c_parser_sizeof_expression (parser
);
6476 return c_parser_alignof_expression (parser
);
6478 c_parser_consume_token (parser
);
6479 ext
= disable_extension_diagnostics ();
6480 ret
= c_parser_cast_expression (parser
, NULL
);
6481 restore_extension_diagnostics (ext
);
6484 c_parser_consume_token (parser
);
6485 exp_loc
= c_parser_peek_token (parser
)->location
;
6486 op
= c_parser_cast_expression (parser
, NULL
);
6487 op
= default_function_array_conversion (exp_loc
, op
);
6488 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6490 c_parser_consume_token (parser
);
6491 exp_loc
= c_parser_peek_token (parser
)->location
;
6492 op
= c_parser_cast_expression (parser
, NULL
);
6493 op
= default_function_array_conversion (exp_loc
, op
);
6494 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6495 case RID_TRANSACTION_ATOMIC
:
6496 case RID_TRANSACTION_RELAXED
:
6497 return c_parser_transaction_expression (parser
,
6498 c_parser_peek_token (parser
)->keyword
);
6500 return c_parser_postfix_expression (parser
);
6503 return c_parser_postfix_expression (parser
);
6507 /* Parse a sizeof expression. */
6509 static struct c_expr
6510 c_parser_sizeof_expression (c_parser
*parser
)
6513 location_t expr_loc
;
6514 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6515 c_parser_consume_token (parser
);
6516 c_inhibit_evaluation_warnings
++;
6518 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6519 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6521 /* Either sizeof ( type-name ) or sizeof unary-expression
6522 starting with a compound literal. */
6523 struct c_type_name
*type_name
;
6524 c_parser_consume_token (parser
);
6525 expr_loc
= c_parser_peek_token (parser
)->location
;
6526 type_name
= c_parser_type_name (parser
);
6527 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6528 if (type_name
== NULL
)
6531 c_inhibit_evaluation_warnings
--;
6533 ret
.value
= error_mark_node
;
6534 ret
.original_code
= ERROR_MARK
;
6535 ret
.original_type
= NULL
;
6538 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6540 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6545 /* sizeof ( type-name ). */
6546 c_inhibit_evaluation_warnings
--;
6548 return c_expr_sizeof_type (expr_loc
, type_name
);
6552 expr_loc
= c_parser_peek_token (parser
)->location
;
6553 expr
= c_parser_unary_expression (parser
);
6555 c_inhibit_evaluation_warnings
--;
6557 mark_exp_read (expr
.value
);
6558 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6559 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6560 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6561 return c_expr_sizeof_expr (expr_loc
, expr
);
6565 /* Parse an alignof expression. */
6567 static struct c_expr
6568 c_parser_alignof_expression (c_parser
*parser
)
6571 location_t loc
= c_parser_peek_token (parser
)->location
;
6572 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6573 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6574 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6576 /* A diagnostic is not required for the use of this identifier in
6577 the implementation namespace; only diagnose it for the C11
6578 spelling because of existing code using the other spellings. */
6582 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6585 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6588 c_parser_consume_token (parser
);
6589 c_inhibit_evaluation_warnings
++;
6591 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6592 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6594 /* Either __alignof__ ( type-name ) or __alignof__
6595 unary-expression starting with a compound literal. */
6597 struct c_type_name
*type_name
;
6599 c_parser_consume_token (parser
);
6600 loc
= c_parser_peek_token (parser
)->location
;
6601 type_name
= c_parser_type_name (parser
);
6602 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6603 if (type_name
== NULL
)
6606 c_inhibit_evaluation_warnings
--;
6608 ret
.value
= error_mark_node
;
6609 ret
.original_code
= ERROR_MARK
;
6610 ret
.original_type
= NULL
;
6613 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6615 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6620 /* alignof ( type-name ). */
6621 c_inhibit_evaluation_warnings
--;
6623 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6625 false, is_c11_alignof
, 1);
6626 ret
.original_code
= ERROR_MARK
;
6627 ret
.original_type
= NULL
;
6633 expr
= c_parser_unary_expression (parser
);
6635 mark_exp_read (expr
.value
);
6636 c_inhibit_evaluation_warnings
--;
6638 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6640 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6641 ret
.original_code
= ERROR_MARK
;
6642 ret
.original_type
= NULL
;
6647 /* Helper function to read arguments of builtins which are interfaces
6648 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6649 others. The name of the builtin is passed using BNAME parameter.
6650 Function returns true if there were no errors while parsing and
6651 stores the arguments in CEXPR_LIST. */
6653 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6654 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6657 location_t loc
= c_parser_peek_token (parser
)->location
;
6658 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6660 bool saved_force_folding_builtin_constant_p
;
6662 *ret_cexpr_list
= NULL
;
6663 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6665 error_at (loc
, "cannot take address of %qs", bname
);
6669 c_parser_consume_token (parser
);
6671 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6673 c_parser_consume_token (parser
);
6677 saved_force_folding_builtin_constant_p
6678 = force_folding_builtin_constant_p
;
6679 force_folding_builtin_constant_p
|= choose_expr_p
;
6680 expr
= c_parser_expr_no_commas (parser
, NULL
);
6681 force_folding_builtin_constant_p
6682 = saved_force_folding_builtin_constant_p
;
6683 vec_alloc (cexpr_list
, 1);
6684 vec_safe_push (cexpr_list
, expr
);
6685 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6687 c_parser_consume_token (parser
);
6688 expr
= c_parser_expr_no_commas (parser
, NULL
);
6689 vec_safe_push (cexpr_list
, expr
);
6692 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6695 *ret_cexpr_list
= cexpr_list
;
6699 /* This represents a single generic-association. */
6701 struct c_generic_association
6703 /* The location of the starting token of the type. */
6704 location_t type_location
;
6705 /* The association's type, or NULL_TREE for 'default'. */
6707 /* The association's expression. */
6708 struct c_expr expression
;
6711 /* Parse a generic-selection. (C11 6.5.1.1).
6714 _Generic ( assignment-expression , generic-assoc-list )
6718 generic-assoc-list , generic-association
6720 generic-association:
6721 type-name : assignment-expression
6722 default : assignment-expression
6725 static struct c_expr
6726 c_parser_generic_selection (c_parser
*parser
)
6728 vec
<c_generic_association
> associations
= vNULL
;
6729 struct c_expr selector
, error_expr
;
6731 struct c_generic_association matched_assoc
;
6732 bool match_found
= false;
6733 location_t generic_loc
, selector_loc
;
6735 error_expr
.original_code
= ERROR_MARK
;
6736 error_expr
.original_type
= NULL
;
6737 error_expr
.value
= error_mark_node
;
6738 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6739 matched_assoc
.type
= NULL_TREE
;
6740 matched_assoc
.expression
= error_expr
;
6742 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6743 generic_loc
= c_parser_peek_token (parser
)->location
;
6744 c_parser_consume_token (parser
);
6746 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6747 "ISO C99 does not support %<_Generic%>");
6749 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6750 "ISO C90 does not support %<_Generic%>");
6752 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6755 c_inhibit_evaluation_warnings
++;
6756 selector_loc
= c_parser_peek_token (parser
)->location
;
6757 selector
= c_parser_expr_no_commas (parser
, NULL
);
6758 selector
= default_function_array_conversion (selector_loc
, selector
);
6759 c_inhibit_evaluation_warnings
--;
6761 if (selector
.value
== error_mark_node
)
6763 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6766 selector_type
= TREE_TYPE (selector
.value
);
6767 /* In ISO C terms, rvalues (including the controlling expression of
6768 _Generic) do not have qualified types. */
6769 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6770 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6771 /* In ISO C terms, _Noreturn is not part of the type of expressions
6772 such as &abort, but in GCC it is represented internally as a type
6774 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6775 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6777 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6779 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6781 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6787 struct c_generic_association assoc
, *iter
;
6789 c_token
*token
= c_parser_peek_token (parser
);
6791 assoc
.type_location
= token
->location
;
6792 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6794 c_parser_consume_token (parser
);
6795 assoc
.type
= NULL_TREE
;
6799 struct c_type_name
*type_name
;
6801 type_name
= c_parser_type_name (parser
);
6802 if (type_name
== NULL
)
6804 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6807 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6808 if (assoc
.type
== error_mark_node
)
6810 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6814 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6815 error_at (assoc
.type_location
,
6816 "%<_Generic%> association has function type");
6817 else if (!COMPLETE_TYPE_P (assoc
.type
))
6818 error_at (assoc
.type_location
,
6819 "%<_Generic%> association has incomplete type");
6821 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6822 error_at (assoc
.type_location
,
6823 "%<_Generic%> association has "
6824 "variable length type");
6827 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6829 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6833 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6834 if (assoc
.expression
.value
== error_mark_node
)
6836 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6840 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6842 if (assoc
.type
== NULL_TREE
)
6844 if (iter
->type
== NULL_TREE
)
6846 error_at (assoc
.type_location
,
6847 "duplicate %<default%> case in %<_Generic%>");
6848 inform (iter
->type_location
, "original %<default%> is here");
6851 else if (iter
->type
!= NULL_TREE
)
6853 if (comptypes (assoc
.type
, iter
->type
))
6855 error_at (assoc
.type_location
,
6856 "%<_Generic%> specifies two compatible types");
6857 inform (iter
->type_location
, "compatible type is here");
6862 if (assoc
.type
== NULL_TREE
)
6866 matched_assoc
= assoc
;
6870 else if (comptypes (assoc
.type
, selector_type
))
6872 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6874 matched_assoc
= assoc
;
6879 error_at (assoc
.type_location
,
6880 "%<_Generic> selector matches multiple associations");
6881 inform (matched_assoc
.type_location
,
6882 "other match is here");
6886 associations
.safe_push (assoc
);
6888 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6890 c_parser_consume_token (parser
);
6893 associations
.release ();
6895 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6903 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6904 "compatible with any association",
6909 return matched_assoc
.expression
;
6912 associations
.release ();
6916 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6920 postfix-expression [ expression ]
6921 postfix-expression ( argument-expression-list[opt] )
6922 postfix-expression . identifier
6923 postfix-expression -> identifier
6924 postfix-expression ++
6925 postfix-expression --
6926 ( type-name ) { initializer-list }
6927 ( type-name ) { initializer-list , }
6929 argument-expression-list:
6931 argument-expression-list , argument-expression
6944 (treated as a keyword in GNU C)
6947 ( compound-statement )
6948 __builtin_va_arg ( assignment-expression , type-name )
6949 __builtin_offsetof ( type-name , offsetof-member-designator )
6950 __builtin_choose_expr ( assignment-expression ,
6951 assignment-expression ,
6952 assignment-expression )
6953 __builtin_types_compatible_p ( type-name , type-name )
6954 __builtin_complex ( assignment-expression , assignment-expression )
6955 __builtin_shuffle ( assignment-expression , assignment-expression )
6956 __builtin_shuffle ( assignment-expression ,
6957 assignment-expression ,
6958 assignment-expression, )
6960 offsetof-member-designator:
6962 offsetof-member-designator . identifier
6963 offsetof-member-designator [ expression ]
6968 [ objc-receiver objc-message-args ]
6969 @selector ( objc-selector-arg )
6970 @protocol ( identifier )
6971 @encode ( type-name )
6973 Classname . identifier
6976 static struct c_expr
6977 c_parser_postfix_expression (c_parser
*parser
)
6979 struct c_expr expr
, e1
;
6980 struct c_type_name
*t1
, *t2
;
6981 location_t loc
= c_parser_peek_token (parser
)->location
;;
6982 expr
.original_code
= ERROR_MARK
;
6983 expr
.original_type
= NULL
;
6984 switch (c_parser_peek_token (parser
)->type
)
6987 expr
.value
= c_parser_peek_token (parser
)->value
;
6988 loc
= c_parser_peek_token (parser
)->location
;
6989 c_parser_consume_token (parser
);
6990 if (TREE_CODE (expr
.value
) == FIXED_CST
6991 && !targetm
.fixed_point_supported_p ())
6993 error_at (loc
, "fixed-point types not supported for this target");
6994 expr
.value
= error_mark_node
;
7001 expr
.value
= c_parser_peek_token (parser
)->value
;
7002 c_parser_consume_token (parser
);
7008 case CPP_UTF8STRING
:
7009 expr
.value
= c_parser_peek_token (parser
)->value
;
7010 expr
.original_code
= STRING_CST
;
7011 c_parser_consume_token (parser
);
7013 case CPP_OBJC_STRING
:
7014 gcc_assert (c_dialect_objc ());
7016 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7017 c_parser_consume_token (parser
);
7020 switch (c_parser_peek_token (parser
)->id_kind
)
7024 tree id
= c_parser_peek_token (parser
)->value
;
7025 c_parser_consume_token (parser
);
7026 expr
.value
= build_external_ref (loc
, id
,
7027 (c_parser_peek_token (parser
)->type
7029 &expr
.original_type
);
7032 case C_ID_CLASSNAME
:
7034 /* Here we parse the Objective-C 2.0 Class.name dot
7036 tree class_name
= c_parser_peek_token (parser
)->value
;
7038 c_parser_consume_token (parser
);
7039 gcc_assert (c_dialect_objc ());
7040 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7042 expr
.value
= error_mark_node
;
7045 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7047 c_parser_error (parser
, "expected identifier");
7048 expr
.value
= error_mark_node
;
7051 component
= c_parser_peek_token (parser
)->value
;
7052 c_parser_consume_token (parser
);
7053 expr
.value
= objc_build_class_component_ref (class_name
,
7058 c_parser_error (parser
, "expected expression");
7059 expr
.value
= error_mark_node
;
7063 case CPP_OPEN_PAREN
:
7064 /* A parenthesized expression, statement expression or compound
7066 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7068 /* A statement expression. */
7070 location_t brace_loc
;
7071 c_parser_consume_token (parser
);
7072 brace_loc
= c_parser_peek_token (parser
)->location
;
7073 c_parser_consume_token (parser
);
7074 if (!building_stmt_list_p ())
7076 error_at (loc
, "braced-group within expression allowed "
7077 "only inside a function");
7078 parser
->error
= true;
7079 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7080 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7081 expr
.value
= error_mark_node
;
7084 stmt
= c_begin_stmt_expr ();
7085 c_parser_compound_statement_nostart (parser
);
7086 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7088 pedwarn (loc
, OPT_Wpedantic
,
7089 "ISO C forbids braced-groups within expressions");
7090 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7091 mark_exp_read (expr
.value
);
7093 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7095 /* A compound literal. ??? Can we actually get here rather
7096 than going directly to
7097 c_parser_postfix_expression_after_paren_type from
7100 struct c_type_name
*type_name
;
7101 c_parser_consume_token (parser
);
7102 loc
= c_parser_peek_token (parser
)->location
;
7103 type_name
= c_parser_type_name (parser
);
7104 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7106 if (type_name
== NULL
)
7108 expr
.value
= error_mark_node
;
7111 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7117 /* A parenthesized expression. */
7118 c_parser_consume_token (parser
);
7119 expr
= c_parser_expression (parser
);
7120 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7121 TREE_NO_WARNING (expr
.value
) = 1;
7122 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7123 expr
.original_code
= ERROR_MARK
;
7124 /* Don't change EXPR.ORIGINAL_TYPE. */
7125 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7130 switch (c_parser_peek_token (parser
)->keyword
)
7132 case RID_FUNCTION_NAME
:
7133 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7134 "%<__FUNCTION__%> predefined identifier");
7135 expr
.value
= fname_decl (loc
,
7136 c_parser_peek_token (parser
)->keyword
,
7137 c_parser_peek_token (parser
)->value
);
7138 c_parser_consume_token (parser
);
7140 case RID_PRETTY_FUNCTION_NAME
:
7141 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7142 "%<__PRETTY_FUNCTION__%> predefined identifier");
7143 expr
.value
= fname_decl (loc
,
7144 c_parser_peek_token (parser
)->keyword
,
7145 c_parser_peek_token (parser
)->value
);
7146 c_parser_consume_token (parser
);
7148 case RID_C99_FUNCTION_NAME
:
7149 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7150 "%<__func__%> predefined identifier");
7151 expr
.value
= fname_decl (loc
,
7152 c_parser_peek_token (parser
)->keyword
,
7153 c_parser_peek_token (parser
)->value
);
7154 c_parser_consume_token (parser
);
7157 c_parser_consume_token (parser
);
7158 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7160 expr
.value
= error_mark_node
;
7163 e1
= c_parser_expr_no_commas (parser
, NULL
);
7164 mark_exp_read (e1
.value
);
7165 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7166 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7168 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7169 expr
.value
= error_mark_node
;
7172 loc
= c_parser_peek_token (parser
)->location
;
7173 t1
= c_parser_type_name (parser
);
7174 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7178 expr
.value
= error_mark_node
;
7182 tree type_expr
= NULL_TREE
;
7183 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7184 groktypename (t1
, &type_expr
, NULL
));
7187 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7188 TREE_TYPE (expr
.value
), type_expr
,
7190 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7195 c_parser_consume_token (parser
);
7196 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7198 expr
.value
= error_mark_node
;
7201 t1
= c_parser_type_name (parser
);
7203 parser
->error
= true;
7204 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7205 gcc_assert (parser
->error
);
7208 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7209 expr
.value
= error_mark_node
;
7214 tree type
= groktypename (t1
, NULL
, NULL
);
7216 if (type
== error_mark_node
)
7217 offsetof_ref
= error_mark_node
;
7220 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7221 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7223 /* Parse the second argument to __builtin_offsetof. We
7224 must have one identifier, and beyond that we want to
7225 accept sub structure and sub array references. */
7226 if (c_parser_next_token_is (parser
, CPP_NAME
))
7228 offsetof_ref
= build_component_ref
7229 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7230 c_parser_consume_token (parser
);
7231 while (c_parser_next_token_is (parser
, CPP_DOT
)
7232 || c_parser_next_token_is (parser
,
7234 || c_parser_next_token_is (parser
,
7237 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7239 loc
= c_parser_peek_token (parser
)->location
;
7240 offsetof_ref
= build_array_ref (loc
,
7245 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7248 c_parser_consume_token (parser
);
7249 if (c_parser_next_token_is_not (parser
,
7252 c_parser_error (parser
, "expected identifier");
7255 offsetof_ref
= build_component_ref
7257 c_parser_peek_token (parser
)->value
);
7258 c_parser_consume_token (parser
);
7264 loc
= c_parser_peek_token (parser
)->location
;
7265 c_parser_consume_token (parser
);
7266 ce
= c_parser_expression (parser
);
7267 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7269 idx
= c_fully_fold (idx
, false, NULL
);
7270 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7272 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7277 c_parser_error (parser
, "expected identifier");
7278 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7280 expr
.value
= fold_offsetof (offsetof_ref
);
7283 case RID_CHOOSE_EXPR
:
7285 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7286 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7289 c_parser_consume_token (parser
);
7290 if (!c_parser_get_builtin_args (parser
,
7291 "__builtin_choose_expr",
7294 expr
.value
= error_mark_node
;
7298 if (vec_safe_length (cexpr_list
) != 3)
7300 error_at (loc
, "wrong number of arguments to "
7301 "%<__builtin_choose_expr%>");
7302 expr
.value
= error_mark_node
;
7306 e1_p
= &(*cexpr_list
)[0];
7307 e2_p
= &(*cexpr_list
)[1];
7308 e3_p
= &(*cexpr_list
)[2];
7311 mark_exp_read (e2_p
->value
);
7312 mark_exp_read (e3_p
->value
);
7313 if (TREE_CODE (c
) != INTEGER_CST
7314 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7316 "first argument to %<__builtin_choose_expr%> not"
7318 constant_expression_warning (c
);
7319 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7322 case RID_TYPES_COMPATIBLE_P
:
7323 c_parser_consume_token (parser
);
7324 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7326 expr
.value
= error_mark_node
;
7329 t1
= c_parser_type_name (parser
);
7332 expr
.value
= error_mark_node
;
7335 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7337 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7338 expr
.value
= error_mark_node
;
7341 t2
= c_parser_type_name (parser
);
7344 expr
.value
= error_mark_node
;
7347 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7351 e1
= groktypename (t1
, NULL
, NULL
);
7352 e2
= groktypename (t2
, NULL
, NULL
);
7353 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7355 expr
.value
= error_mark_node
;
7359 e1
= TYPE_MAIN_VARIANT (e1
);
7360 e2
= TYPE_MAIN_VARIANT (e2
);
7363 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7366 case RID_BUILTIN_COMPLEX
:
7368 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7369 c_expr_t
*e1_p
, *e2_p
;
7371 c_parser_consume_token (parser
);
7372 if (!c_parser_get_builtin_args (parser
,
7373 "__builtin_complex",
7374 &cexpr_list
, false))
7376 expr
.value
= error_mark_node
;
7380 if (vec_safe_length (cexpr_list
) != 2)
7382 error_at (loc
, "wrong number of arguments to "
7383 "%<__builtin_complex%>");
7384 expr
.value
= error_mark_node
;
7388 e1_p
= &(*cexpr_list
)[0];
7389 e2_p
= &(*cexpr_list
)[1];
7391 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7392 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7393 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7394 TREE_OPERAND (e1_p
->value
, 0));
7395 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7396 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7397 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7398 TREE_OPERAND (e2_p
->value
, 0));
7399 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7400 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7401 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7402 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7404 error_at (loc
, "%<__builtin_complex%> operand "
7405 "not of real binary floating-point type");
7406 expr
.value
= error_mark_node
;
7409 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7410 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7413 "%<__builtin_complex%> operands of different types");
7414 expr
.value
= error_mark_node
;
7417 pedwarn_c90 (loc
, OPT_Wpedantic
,
7418 "ISO C90 does not support complex types");
7419 expr
.value
= build2 (COMPLEX_EXPR
,
7422 (TREE_TYPE (e1_p
->value
))),
7423 e1_p
->value
, e2_p
->value
);
7426 case RID_BUILTIN_SHUFFLE
:
7428 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7432 c_parser_consume_token (parser
);
7433 if (!c_parser_get_builtin_args (parser
,
7434 "__builtin_shuffle",
7435 &cexpr_list
, false))
7437 expr
.value
= error_mark_node
;
7441 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7442 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7444 if (vec_safe_length (cexpr_list
) == 2)
7446 c_build_vec_perm_expr
7447 (loc
, (*cexpr_list
)[0].value
,
7448 NULL_TREE
, (*cexpr_list
)[1].value
);
7450 else if (vec_safe_length (cexpr_list
) == 3)
7452 c_build_vec_perm_expr
7453 (loc
, (*cexpr_list
)[0].value
,
7454 (*cexpr_list
)[1].value
,
7455 (*cexpr_list
)[2].value
);
7458 error_at (loc
, "wrong number of arguments to "
7459 "%<__builtin_shuffle%>");
7460 expr
.value
= error_mark_node
;
7464 case RID_AT_SELECTOR
:
7465 gcc_assert (c_dialect_objc ());
7466 c_parser_consume_token (parser
);
7467 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7469 expr
.value
= error_mark_node
;
7473 tree sel
= c_parser_objc_selector_arg (parser
);
7474 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7476 expr
.value
= objc_build_selector_expr (loc
, sel
);
7479 case RID_AT_PROTOCOL
:
7480 gcc_assert (c_dialect_objc ());
7481 c_parser_consume_token (parser
);
7482 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7484 expr
.value
= error_mark_node
;
7487 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7489 c_parser_error (parser
, "expected identifier");
7490 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7491 expr
.value
= error_mark_node
;
7495 tree id
= c_parser_peek_token (parser
)->value
;
7496 c_parser_consume_token (parser
);
7497 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7499 expr
.value
= objc_build_protocol_expr (id
);
7503 /* Extension to support C-structures in the archiver. */
7504 gcc_assert (c_dialect_objc ());
7505 c_parser_consume_token (parser
);
7506 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7508 expr
.value
= error_mark_node
;
7511 t1
= c_parser_type_name (parser
);
7514 expr
.value
= error_mark_node
;
7515 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7518 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7521 tree type
= groktypename (t1
, NULL
, NULL
);
7522 expr
.value
= objc_build_encode_expr (type
);
7526 expr
= c_parser_generic_selection (parser
);
7528 case RID_CILK_SPAWN
:
7529 c_parser_consume_token (parser
);
7532 error_at (loc
, "-fcilkplus must be enabled to use "
7534 expr
= c_parser_postfix_expression (parser
);
7535 expr
.value
= error_mark_node
;
7537 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7539 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7540 "are not permitted");
7541 /* Now flush out all the _Cilk_spawns. */
7542 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7543 c_parser_consume_token (parser
);
7544 expr
= c_parser_postfix_expression (parser
);
7548 expr
= c_parser_postfix_expression (parser
);
7549 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7553 c_parser_error (parser
, "expected expression");
7554 expr
.value
= error_mark_node
;
7558 case CPP_OPEN_SQUARE
:
7559 if (c_dialect_objc ())
7561 tree receiver
, args
;
7562 c_parser_consume_token (parser
);
7563 receiver
= c_parser_objc_receiver (parser
);
7564 args
= c_parser_objc_message_args (parser
);
7565 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7567 expr
.value
= objc_build_message_expr (receiver
, args
);
7570 /* Else fall through to report error. */
7572 c_parser_error (parser
, "expected expression");
7573 expr
.value
= error_mark_node
;
7576 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7579 /* Parse a postfix expression after a parenthesized type name: the
7580 brace-enclosed initializer of a compound literal, possibly followed
7581 by some postfix operators. This is separate because it is not
7582 possible to tell until after the type name whether a cast
7583 expression has a cast or a compound literal, or whether the operand
7584 of sizeof is a parenthesized type name or starts with a compound
7585 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7586 location of the first token after the parentheses around the type
7589 static struct c_expr
7590 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7591 struct c_type_name
*type_name
,
7592 location_t type_loc
)
7598 location_t start_loc
;
7599 tree type_expr
= NULL_TREE
;
7600 bool type_expr_const
= true;
7601 check_compound_literal_type (type_loc
, type_name
);
7602 start_init (NULL_TREE
, NULL
, 0);
7603 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7604 start_loc
= c_parser_peek_token (parser
)->location
;
7605 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7607 error_at (type_loc
, "compound literal has variable size");
7608 type
= error_mark_node
;
7610 init
= c_parser_braced_init (parser
, type
, false);
7612 maybe_warn_string_init (type_loc
, type
, init
);
7614 if (type
!= error_mark_node
7615 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7616 && current_function_decl
)
7618 error ("compound literal qualified by address-space qualifier");
7619 type
= error_mark_node
;
7622 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7623 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7624 ? CONSTRUCTOR_NON_CONST (init
.value
)
7625 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7626 non_const
|= !type_expr_const
;
7627 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7628 expr
.original_code
= ERROR_MARK
;
7629 expr
.original_type
= NULL
;
7632 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7634 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7635 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7639 gcc_assert (!non_const
);
7640 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7641 type_expr
, expr
.value
);
7644 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7647 /* Callback function for sizeof_pointer_memaccess_warning to compare
7651 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7653 return comptypes (type1
, type2
) == 1;
7656 /* Parse a postfix expression after the initial primary or compound
7657 literal; that is, parse a series of postfix operators.
7659 EXPR_LOC is the location of the primary expression. */
7661 static struct c_expr
7662 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7663 location_t expr_loc
,
7666 struct c_expr orig_expr
;
7668 location_t sizeof_arg_loc
[3];
7670 unsigned int literal_zero_mask
;
7672 vec
<tree
, va_gc
> *exprlist
;
7673 vec
<tree
, va_gc
> *origtypes
= NULL
;
7674 vec
<location_t
> arg_loc
= vNULL
;
7678 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7679 switch (c_parser_peek_token (parser
)->type
)
7681 case CPP_OPEN_SQUARE
:
7682 /* Array reference. */
7683 c_parser_consume_token (parser
);
7685 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7686 /* If we are here, then we have something like this:
7689 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7693 idx
= c_parser_expression (parser
).value
;
7694 /* Here we have 3 options:
7695 1. Array [EXPR] -- Normal Array call.
7696 2. Array [EXPR : EXPR] -- Array notation without stride.
7697 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7699 For 1, we just handle it just like a normal array expression.
7700 For 2 and 3 we handle it like we handle array notations. The
7701 idx value we have above becomes the initial/start index.
7704 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7705 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7709 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7711 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7714 expr
.original_code
= ERROR_MARK
;
7715 expr
.original_type
= NULL
;
7717 case CPP_OPEN_PAREN
:
7718 /* Function call. */
7719 c_parser_consume_token (parser
);
7720 for (i
= 0; i
< 3; i
++)
7722 sizeof_arg
[i
] = NULL_TREE
;
7723 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7725 literal_zero_mask
= 0;
7726 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7729 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7730 sizeof_arg_loc
, sizeof_arg
,
7731 &arg_loc
, &literal_zero_mask
);
7732 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7735 mark_exp_read (expr
.value
);
7736 if (warn_sizeof_pointer_memaccess
)
7737 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7738 expr
.value
, exprlist
,
7740 sizeof_ptr_memacc_comptypes
);
7741 if (warn_memset_transposed_args
7742 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7743 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7744 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7745 && vec_safe_length (exprlist
) == 3
7746 && integer_zerop ((*exprlist
)[2])
7747 && (literal_zero_mask
& (1 << 2)) != 0
7748 && (!integer_zerop ((*exprlist
)[1])
7749 || (literal_zero_mask
& (1 << 1)) == 0))
7750 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7751 "%<memset%> used with constant zero length parameter; "
7752 "this could be due to transposed parameters");
7755 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7756 exprlist
, origtypes
);
7757 expr
.original_code
= ERROR_MARK
;
7758 if (TREE_CODE (expr
.value
) == INTEGER_CST
7759 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7760 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7761 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7762 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7763 expr
.original_type
= NULL
;
7766 release_tree_vector (exprlist
);
7767 release_tree_vector (origtypes
);
7772 /* Structure element reference. */
7773 c_parser_consume_token (parser
);
7774 expr
= default_function_array_conversion (expr_loc
, expr
);
7775 if (c_parser_next_token_is (parser
, CPP_NAME
))
7776 ident
= c_parser_peek_token (parser
)->value
;
7779 c_parser_error (parser
, "expected identifier");
7780 expr
.value
= error_mark_node
;
7781 expr
.original_code
= ERROR_MARK
;
7782 expr
.original_type
= NULL
;
7785 c_parser_consume_token (parser
);
7786 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7787 expr
.original_code
= ERROR_MARK
;
7788 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7789 expr
.original_type
= NULL
;
7792 /* Remember the original type of a bitfield. */
7793 tree field
= TREE_OPERAND (expr
.value
, 1);
7794 if (TREE_CODE (field
) != FIELD_DECL
)
7795 expr
.original_type
= NULL
;
7797 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7801 /* Structure element reference. */
7802 c_parser_consume_token (parser
);
7803 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7804 if (c_parser_next_token_is (parser
, CPP_NAME
))
7805 ident
= c_parser_peek_token (parser
)->value
;
7808 c_parser_error (parser
, "expected identifier");
7809 expr
.value
= error_mark_node
;
7810 expr
.original_code
= ERROR_MARK
;
7811 expr
.original_type
= NULL
;
7814 c_parser_consume_token (parser
);
7815 expr
.value
= build_component_ref (op_loc
,
7816 build_indirect_ref (op_loc
,
7820 expr
.original_code
= ERROR_MARK
;
7821 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7822 expr
.original_type
= NULL
;
7825 /* Remember the original type of a bitfield. */
7826 tree field
= TREE_OPERAND (expr
.value
, 1);
7827 if (TREE_CODE (field
) != FIELD_DECL
)
7828 expr
.original_type
= NULL
;
7830 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7834 /* Postincrement. */
7835 c_parser_consume_token (parser
);
7836 /* If the expressions have array notations, we expand them. */
7838 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7839 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7842 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7843 expr
.value
= build_unary_op (op_loc
,
7844 POSTINCREMENT_EXPR
, expr
.value
, 0);
7846 expr
.original_code
= ERROR_MARK
;
7847 expr
.original_type
= NULL
;
7849 case CPP_MINUS_MINUS
:
7850 /* Postdecrement. */
7851 c_parser_consume_token (parser
);
7852 /* If the expressions have array notations, we expand them. */
7854 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7855 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7858 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7859 expr
.value
= build_unary_op (op_loc
,
7860 POSTDECREMENT_EXPR
, expr
.value
, 0);
7862 expr
.original_code
= ERROR_MARK
;
7863 expr
.original_type
= NULL
;
7871 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7874 assignment-expression
7875 expression , assignment-expression
7878 static struct c_expr
7879 c_parser_expression (c_parser
*parser
)
7881 location_t tloc
= c_parser_peek_token (parser
)->location
;
7883 expr
= c_parser_expr_no_commas (parser
, NULL
);
7884 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7885 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7886 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7890 location_t loc
= c_parser_peek_token (parser
)->location
;
7891 location_t expr_loc
;
7892 c_parser_consume_token (parser
);
7893 expr_loc
= c_parser_peek_token (parser
)->location
;
7894 lhsval
= expr
.value
;
7895 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7896 lhsval
= TREE_OPERAND (lhsval
, 1);
7897 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7898 mark_exp_read (lhsval
);
7899 next
= c_parser_expr_no_commas (parser
, NULL
);
7900 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7901 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7902 expr
.original_code
= COMPOUND_EXPR
;
7903 expr
.original_type
= next
.original_type
;
7908 /* Parse an expression and convert functions or arrays to pointers and
7909 lvalues to rvalues. */
7911 static struct c_expr
7912 c_parser_expression_conv (c_parser
*parser
)
7915 location_t loc
= c_parser_peek_token (parser
)->location
;
7916 expr
= c_parser_expression (parser
);
7917 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7921 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
7922 argument is a literal zero alone and if so, set it in literal_zero_mask. */
7925 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
7928 if (idx
>= HOST_BITS_PER_INT
)
7931 c_token
*tok
= c_parser_peek_token (parser
);
7939 /* If a parameter is literal zero alone, remember it
7940 for -Wmemset-transposed-args warning. */
7941 if (integer_zerop (tok
->value
)
7942 && !TREE_OVERFLOW (tok
->value
)
7943 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7944 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
7945 *literal_zero_mask
|= 1U << idx
;
7951 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7952 functions and arrays to pointers and lvalues to rvalues. If
7953 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7954 locations of function arguments into this vector.
7957 assignment-expression
7958 nonempty-expr-list , assignment-expression
7961 static vec
<tree
, va_gc
> *
7962 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7963 vec
<tree
, va_gc
> **p_orig_types
,
7964 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
7965 vec
<location_t
> *locations
,
7966 unsigned int *literal_zero_mask
)
7968 vec
<tree
, va_gc
> *ret
;
7969 vec
<tree
, va_gc
> *orig_types
;
7971 location_t loc
= c_parser_peek_token (parser
)->location
;
7972 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7973 unsigned int idx
= 0;
7975 ret
= make_tree_vector ();
7976 if (p_orig_types
== NULL
)
7979 orig_types
= make_tree_vector ();
7981 if (sizeof_arg
!= NULL
7982 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7983 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7984 if (literal_zero_mask
)
7985 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
7986 expr
= c_parser_expr_no_commas (parser
, NULL
);
7988 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7990 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7991 ret
->quick_push (expr
.value
);
7993 orig_types
->quick_push (expr
.original_type
);
7995 locations
->safe_push (loc
);
7996 if (sizeof_arg
!= NULL
7997 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7998 && expr
.original_code
== SIZEOF_EXPR
)
8000 sizeof_arg
[0] = c_last_sizeof_arg
;
8001 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8003 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8005 c_parser_consume_token (parser
);
8006 loc
= c_parser_peek_token (parser
)->location
;
8007 if (sizeof_arg
!= NULL
8008 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8009 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8011 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8012 if (literal_zero_mask
)
8013 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8014 expr
= c_parser_expr_no_commas (parser
, NULL
);
8016 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8018 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8019 vec_safe_push (ret
, expr
.value
);
8021 vec_safe_push (orig_types
, expr
.original_type
);
8023 locations
->safe_push (loc
);
8025 && sizeof_arg
!= NULL
8026 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8027 && expr
.original_code
== SIZEOF_EXPR
)
8029 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8030 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8034 *p_orig_types
= orig_types
;
8038 /* Parse Objective-C-specific constructs. */
8040 /* Parse an objc-class-definition.
8042 objc-class-definition:
8043 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8044 objc-class-instance-variables[opt] objc-methodprotolist @end
8045 @implementation identifier objc-superclass[opt]
8046 objc-class-instance-variables[opt]
8047 @interface identifier ( identifier ) objc-protocol-refs[opt]
8048 objc-methodprotolist @end
8049 @interface identifier ( ) objc-protocol-refs[opt]
8050 objc-methodprotolist @end
8051 @implementation identifier ( identifier )
8056 "@interface identifier (" must start "@interface identifier (
8057 identifier ) ...": objc-methodprotolist in the first production may
8058 not start with a parenthesized identifier as a declarator of a data
8059 definition with no declaration specifiers if the objc-superclass,
8060 objc-protocol-refs and objc-class-instance-variables are omitted. */
8063 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8068 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8070 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8075 c_parser_consume_token (parser
);
8076 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8078 c_parser_error (parser
, "expected identifier");
8081 id1
= c_parser_peek_token (parser
)->value
;
8082 c_parser_consume_token (parser
);
8083 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8085 /* We have a category or class extension. */
8087 tree proto
= NULL_TREE
;
8088 c_parser_consume_token (parser
);
8089 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8091 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8093 /* We have a class extension. */
8098 c_parser_error (parser
, "expected identifier or %<)%>");
8099 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8105 id2
= c_parser_peek_token (parser
)->value
;
8106 c_parser_consume_token (parser
);
8108 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8111 objc_start_category_implementation (id1
, id2
);
8114 if (c_parser_next_token_is (parser
, CPP_LESS
))
8115 proto
= c_parser_objc_protocol_refs (parser
);
8116 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8117 c_parser_objc_methodprotolist (parser
);
8118 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8119 objc_finish_interface ();
8122 if (c_parser_next_token_is (parser
, CPP_COLON
))
8124 c_parser_consume_token (parser
);
8125 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8127 c_parser_error (parser
, "expected identifier");
8130 superclass
= c_parser_peek_token (parser
)->value
;
8131 c_parser_consume_token (parser
);
8134 superclass
= NULL_TREE
;
8137 tree proto
= NULL_TREE
;
8138 if (c_parser_next_token_is (parser
, CPP_LESS
))
8139 proto
= c_parser_objc_protocol_refs (parser
);
8140 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8143 objc_start_class_implementation (id1
, superclass
);
8144 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8145 c_parser_objc_class_instance_variables (parser
);
8148 objc_continue_interface ();
8149 c_parser_objc_methodprotolist (parser
);
8150 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8151 objc_finish_interface ();
8155 objc_continue_implementation ();
8160 /* Parse objc-class-instance-variables.
8162 objc-class-instance-variables:
8163 { objc-instance-variable-decl-list[opt] }
8165 objc-instance-variable-decl-list:
8166 objc-visibility-spec
8167 objc-instance-variable-decl ;
8169 objc-instance-variable-decl-list objc-visibility-spec
8170 objc-instance-variable-decl-list objc-instance-variable-decl ;
8171 objc-instance-variable-decl-list ;
8173 objc-visibility-spec:
8178 objc-instance-variable-decl:
8183 c_parser_objc_class_instance_variables (c_parser
*parser
)
8185 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8186 c_parser_consume_token (parser
);
8187 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8190 /* Parse any stray semicolon. */
8191 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8193 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8195 c_parser_consume_token (parser
);
8198 /* Stop if at the end of the instance variables. */
8199 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8201 c_parser_consume_token (parser
);
8204 /* Parse any objc-visibility-spec. */
8205 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8207 c_parser_consume_token (parser
);
8208 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8211 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8213 c_parser_consume_token (parser
);
8214 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8217 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8219 c_parser_consume_token (parser
);
8220 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8223 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8225 c_parser_consume_token (parser
);
8226 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8229 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8231 c_parser_pragma (parser
, pragma_external
);
8235 /* Parse some comma-separated declarations. */
8236 decls
= c_parser_struct_declaration (parser
);
8239 /* There is a syntax error. We want to skip the offending
8240 tokens up to the next ';' (included) or '}'
8243 /* First, skip manually a ')' or ']'. This is because they
8244 reduce the nesting level, so c_parser_skip_until_found()
8245 wouldn't be able to skip past them. */
8246 c_token
*token
= c_parser_peek_token (parser
);
8247 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8248 c_parser_consume_token (parser
);
8250 /* Then, do the standard skipping. */
8251 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8253 /* We hopefully recovered. Start normal parsing again. */
8254 parser
->error
= false;
8259 /* Comma-separated instance variables are chained together
8260 in reverse order; add them one by one. */
8261 tree ivar
= nreverse (decls
);
8262 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8263 objc_add_instance_variable (copy_node (ivar
));
8265 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8269 /* Parse an objc-class-declaration.
8271 objc-class-declaration:
8272 @class identifier-list ;
8276 c_parser_objc_class_declaration (c_parser
*parser
)
8278 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8279 c_parser_consume_token (parser
);
8280 /* Any identifiers, including those declared as type names, are OK
8285 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8287 c_parser_error (parser
, "expected identifier");
8288 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8289 parser
->error
= false;
8292 id
= c_parser_peek_token (parser
)->value
;
8293 objc_declare_class (id
);
8294 c_parser_consume_token (parser
);
8295 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8296 c_parser_consume_token (parser
);
8300 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8303 /* Parse an objc-alias-declaration.
8305 objc-alias-declaration:
8306 @compatibility_alias identifier identifier ;
8310 c_parser_objc_alias_declaration (c_parser
*parser
)
8313 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8314 c_parser_consume_token (parser
);
8315 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8317 c_parser_error (parser
, "expected identifier");
8318 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8321 id1
= c_parser_peek_token (parser
)->value
;
8322 c_parser_consume_token (parser
);
8323 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8325 c_parser_error (parser
, "expected identifier");
8326 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8329 id2
= c_parser_peek_token (parser
)->value
;
8330 c_parser_consume_token (parser
);
8331 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8332 objc_declare_alias (id1
, id2
);
8335 /* Parse an objc-protocol-definition.
8337 objc-protocol-definition:
8338 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8339 @protocol identifier-list ;
8341 "@protocol identifier ;" should be resolved as "@protocol
8342 identifier-list ;": objc-methodprotolist may not start with a
8343 semicolon in the first alternative if objc-protocol-refs are
8347 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8349 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8351 c_parser_consume_token (parser
);
8352 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8354 c_parser_error (parser
, "expected identifier");
8357 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8358 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8360 /* Any identifiers, including those declared as type names, are
8365 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8367 c_parser_error (parser
, "expected identifier");
8370 id
= c_parser_peek_token (parser
)->value
;
8371 objc_declare_protocol (id
, attributes
);
8372 c_parser_consume_token (parser
);
8373 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8374 c_parser_consume_token (parser
);
8378 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8382 tree id
= c_parser_peek_token (parser
)->value
;
8383 tree proto
= NULL_TREE
;
8384 c_parser_consume_token (parser
);
8385 if (c_parser_next_token_is (parser
, CPP_LESS
))
8386 proto
= c_parser_objc_protocol_refs (parser
);
8387 parser
->objc_pq_context
= true;
8388 objc_start_protocol (id
, proto
, attributes
);
8389 c_parser_objc_methodprotolist (parser
);
8390 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8391 parser
->objc_pq_context
= false;
8392 objc_finish_interface ();
8396 /* Parse an objc-method-type.
8402 Return true if it is a class method (+) and false if it is
8403 an instance method (-).
8406 c_parser_objc_method_type (c_parser
*parser
)
8408 switch (c_parser_peek_token (parser
)->type
)
8411 c_parser_consume_token (parser
);
8414 c_parser_consume_token (parser
);
8421 /* Parse an objc-method-definition.
8423 objc-method-definition:
8424 objc-method-type objc-method-decl ;[opt] compound-statement
8428 c_parser_objc_method_definition (c_parser
*parser
)
8430 bool is_class_method
= c_parser_objc_method_type (parser
);
8431 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8432 parser
->objc_pq_context
= true;
8433 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8435 if (decl
== error_mark_node
)
8436 return; /* Bail here. */
8438 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8440 c_parser_consume_token (parser
);
8441 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8442 "extra semicolon in method definition specified");
8445 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8447 c_parser_error (parser
, "expected %<{%>");
8451 parser
->objc_pq_context
= false;
8452 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8454 add_stmt (c_parser_compound_statement (parser
));
8455 objc_finish_method_definition (current_function_decl
);
8459 /* This code is executed when we find a method definition
8460 outside of an @implementation context (or invalid for other
8461 reasons). Parse the method (to keep going) but do not emit
8464 c_parser_compound_statement (parser
);
8468 /* Parse an objc-methodprotolist.
8470 objc-methodprotolist:
8472 objc-methodprotolist objc-methodproto
8473 objc-methodprotolist declaration
8474 objc-methodprotolist ;
8478 The declaration is a data definition, which may be missing
8479 declaration specifiers under the same rules and diagnostics as
8480 other data definitions outside functions, and the stray semicolon
8481 is diagnosed the same way as a stray semicolon outside a
8485 c_parser_objc_methodprotolist (c_parser
*parser
)
8489 /* The list is terminated by @end. */
8490 switch (c_parser_peek_token (parser
)->type
)
8493 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8494 "ISO C does not allow extra %<;%> outside of a function");
8495 c_parser_consume_token (parser
);
8499 c_parser_objc_methodproto (parser
);
8502 c_parser_pragma (parser
, pragma_external
);
8507 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8509 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8510 c_parser_objc_at_property_declaration (parser
);
8511 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8513 objc_set_method_opt (true);
8514 c_parser_consume_token (parser
);
8516 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8518 objc_set_method_opt (false);
8519 c_parser_consume_token (parser
);
8522 c_parser_declaration_or_fndef (parser
, false, false, true,
8523 false, true, NULL
, vNULL
);
8529 /* Parse an objc-methodproto.
8532 objc-method-type objc-method-decl ;
8536 c_parser_objc_methodproto (c_parser
*parser
)
8538 bool is_class_method
= c_parser_objc_method_type (parser
);
8539 tree decl
, attributes
= NULL_TREE
;
8541 /* Remember protocol qualifiers in prototypes. */
8542 parser
->objc_pq_context
= true;
8543 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8545 /* Forget protocol qualifiers now. */
8546 parser
->objc_pq_context
= false;
8548 /* Do not allow the presence of attributes to hide an erroneous
8549 method implementation in the interface section. */
8550 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8552 c_parser_error (parser
, "expected %<;%>");
8556 if (decl
!= error_mark_node
)
8557 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8559 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8562 /* If we are at a position that method attributes may be present, check that
8563 there are not any parsed already (a syntax error) and then collect any
8564 specified at the current location. Finally, if new attributes were present,
8565 check that the next token is legal ( ';' for decls and '{' for defs). */
8568 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8573 c_parser_error (parser
,
8574 "method attributes must be specified at the end only");
8575 *attributes
= NULL_TREE
;
8579 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8580 *attributes
= c_parser_attributes (parser
);
8582 /* If there were no attributes here, just report any earlier error. */
8583 if (*attributes
== NULL_TREE
|| bad
)
8586 /* If the attributes are followed by a ; or {, then just report any earlier
8588 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8589 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8592 /* We've got attributes, but not at the end. */
8593 c_parser_error (parser
,
8594 "expected %<;%> or %<{%> after method attribute definition");
8598 /* Parse an objc-method-decl.
8601 ( objc-type-name ) objc-selector
8603 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8604 objc-keyword-selector objc-optparmlist
8607 objc-keyword-selector:
8609 objc-keyword-selector objc-keyword-decl
8612 objc-selector : ( objc-type-name ) identifier
8613 objc-selector : identifier
8614 : ( objc-type-name ) identifier
8618 objc-optparms objc-optellipsis
8622 objc-opt-parms , parameter-declaration
8630 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8631 tree
*attributes
, tree
*expr
)
8633 tree type
= NULL_TREE
;
8635 tree parms
= NULL_TREE
;
8636 bool ellipsis
= false;
8637 bool attr_err
= false;
8639 *attributes
= NULL_TREE
;
8640 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8642 c_parser_consume_token (parser
);
8643 type
= c_parser_objc_type_name (parser
);
8644 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8646 sel
= c_parser_objc_selector (parser
);
8647 /* If there is no selector, or a colon follows, we have an
8648 objc-keyword-selector. If there is a selector, and a colon does
8649 not follow, that selector ends the objc-method-decl. */
8650 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8653 tree list
= NULL_TREE
;
8656 tree atype
= NULL_TREE
, id
, keyworddecl
;
8657 tree param_attr
= NULL_TREE
;
8658 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8660 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8662 c_parser_consume_token (parser
);
8663 atype
= c_parser_objc_type_name (parser
);
8664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8667 /* New ObjC allows attributes on method parameters. */
8668 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8669 param_attr
= c_parser_attributes (parser
);
8670 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8672 c_parser_error (parser
, "expected identifier");
8673 return error_mark_node
;
8675 id
= c_parser_peek_token (parser
)->value
;
8676 c_parser_consume_token (parser
);
8677 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8678 list
= chainon (list
, keyworddecl
);
8679 tsel
= c_parser_objc_selector (parser
);
8680 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8684 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8686 /* Parse the optional parameter list. Optional Objective-C
8687 method parameters follow the C syntax, and may include '...'
8688 to denote a variable number of arguments. */
8689 parms
= make_node (TREE_LIST
);
8690 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8692 struct c_parm
*parm
;
8693 c_parser_consume_token (parser
);
8694 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8697 c_parser_consume_token (parser
);
8698 attr_err
|= c_parser_objc_maybe_method_attributes
8699 (parser
, attributes
) ;
8702 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8705 parms
= chainon (parms
,
8706 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8711 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8715 c_parser_error (parser
, "objective-c method declaration is expected");
8716 return error_mark_node
;
8720 return error_mark_node
;
8722 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8725 /* Parse an objc-type-name.
8728 objc-type-qualifiers[opt] type-name
8729 objc-type-qualifiers[opt]
8731 objc-type-qualifiers:
8733 objc-type-qualifiers objc-type-qualifier
8735 objc-type-qualifier: one of
8736 in out inout bycopy byref oneway
8740 c_parser_objc_type_name (c_parser
*parser
)
8742 tree quals
= NULL_TREE
;
8743 struct c_type_name
*type_name
= NULL
;
8744 tree type
= NULL_TREE
;
8747 c_token
*token
= c_parser_peek_token (parser
);
8748 if (token
->type
== CPP_KEYWORD
8749 && (token
->keyword
== RID_IN
8750 || token
->keyword
== RID_OUT
8751 || token
->keyword
== RID_INOUT
8752 || token
->keyword
== RID_BYCOPY
8753 || token
->keyword
== RID_BYREF
8754 || token
->keyword
== RID_ONEWAY
))
8756 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8757 c_parser_consume_token (parser
);
8762 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8763 type_name
= c_parser_type_name (parser
);
8765 type
= groktypename (type_name
, NULL
, NULL
);
8767 /* If the type is unknown, and error has already been produced and
8768 we need to recover from the error. In that case, use NULL_TREE
8769 for the type, as if no type had been specified; this will use the
8770 default type ('id') which is good for error recovery. */
8771 if (type
== error_mark_node
)
8774 return build_tree_list (quals
, type
);
8777 /* Parse objc-protocol-refs.
8784 c_parser_objc_protocol_refs (c_parser
*parser
)
8786 tree list
= NULL_TREE
;
8787 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8788 c_parser_consume_token (parser
);
8789 /* Any identifiers, including those declared as type names, are OK
8794 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8796 c_parser_error (parser
, "expected identifier");
8799 id
= c_parser_peek_token (parser
)->value
;
8800 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8801 c_parser_consume_token (parser
);
8802 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8803 c_parser_consume_token (parser
);
8807 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8811 /* Parse an objc-try-catch-finally-statement.
8813 objc-try-catch-finally-statement:
8814 @try compound-statement objc-catch-list[opt]
8815 @try compound-statement objc-catch-list[opt] @finally compound-statement
8818 @catch ( objc-catch-parameter-declaration ) compound-statement
8819 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8821 objc-catch-parameter-declaration:
8822 parameter-declaration
8825 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8827 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8828 for C++. Keep them in sync. */
8831 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8833 location_t location
;
8836 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8837 c_parser_consume_token (parser
);
8838 location
= c_parser_peek_token (parser
)->location
;
8839 objc_maybe_warn_exceptions (location
);
8840 stmt
= c_parser_compound_statement (parser
);
8841 objc_begin_try_stmt (location
, stmt
);
8843 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8845 struct c_parm
*parm
;
8846 tree parameter_declaration
= error_mark_node
;
8847 bool seen_open_paren
= false;
8849 c_parser_consume_token (parser
);
8850 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8851 seen_open_paren
= true;
8852 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8854 /* We have "@catch (...)" (where the '...' are literally
8855 what is in the code). Skip the '...'.
8856 parameter_declaration is set to NULL_TREE, and
8857 objc_being_catch_clauses() knows that that means
8859 c_parser_consume_token (parser
);
8860 parameter_declaration
= NULL_TREE
;
8864 /* We have "@catch (NSException *exception)" or something
8865 like that. Parse the parameter declaration. */
8866 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8868 parameter_declaration
= error_mark_node
;
8870 parameter_declaration
= grokparm (parm
, NULL
);
8872 if (seen_open_paren
)
8873 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8876 /* If there was no open parenthesis, we are recovering from
8877 an error, and we are trying to figure out what mistake
8878 the user has made. */
8880 /* If there is an immediate closing parenthesis, the user
8881 probably forgot the opening one (ie, they typed "@catch
8882 NSException *e)". Parse the closing parenthesis and keep
8884 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8885 c_parser_consume_token (parser
);
8887 /* If these is no immediate closing parenthesis, the user
8888 probably doesn't know that parenthesis are required at
8889 all (ie, they typed "@catch NSException *e"). So, just
8890 forget about the closing parenthesis and keep going. */
8892 objc_begin_catch_clause (parameter_declaration
);
8893 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8894 c_parser_compound_statement_nostart (parser
);
8895 objc_finish_catch_clause ();
8897 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8899 c_parser_consume_token (parser
);
8900 location
= c_parser_peek_token (parser
)->location
;
8901 stmt
= c_parser_compound_statement (parser
);
8902 objc_build_finally_clause (location
, stmt
);
8904 objc_finish_try_stmt ();
8907 /* Parse an objc-synchronized-statement.
8909 objc-synchronized-statement:
8910 @synchronized ( expression ) compound-statement
8914 c_parser_objc_synchronized_statement (c_parser
*parser
)
8918 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8919 c_parser_consume_token (parser
);
8920 loc
= c_parser_peek_token (parser
)->location
;
8921 objc_maybe_warn_exceptions (loc
);
8922 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8924 struct c_expr ce
= c_parser_expression (parser
);
8925 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8927 expr
= c_fully_fold (expr
, false, NULL
);
8928 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8931 expr
= error_mark_node
;
8932 stmt
= c_parser_compound_statement (parser
);
8933 objc_build_synchronized (loc
, expr
, stmt
);
8936 /* Parse an objc-selector; return NULL_TREE without an error if the
8937 next token is not an objc-selector.
8942 enum struct union if else while do for switch case default
8943 break continue return goto asm sizeof typeof __alignof
8944 unsigned long const short volatile signed restrict _Complex
8945 in out inout bycopy byref oneway int char float double void _Bool
8948 ??? Why this selection of keywords but not, for example, storage
8949 class specifiers? */
8952 c_parser_objc_selector (c_parser
*parser
)
8954 c_token
*token
= c_parser_peek_token (parser
);
8955 tree value
= token
->value
;
8956 if (token
->type
== CPP_NAME
)
8958 c_parser_consume_token (parser
);
8961 if (token
->type
!= CPP_KEYWORD
)
8963 switch (token
->keyword
)
9007 c_parser_consume_token (parser
);
9014 /* Parse an objc-selector-arg.
9018 objc-keywordname-list
9020 objc-keywordname-list:
9022 objc-keywordname-list objc-keywordname
9030 c_parser_objc_selector_arg (c_parser
*parser
)
9032 tree sel
= c_parser_objc_selector (parser
);
9033 tree list
= NULL_TREE
;
9034 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9038 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9040 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9041 sel
= c_parser_objc_selector (parser
);
9042 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9048 /* Parse an objc-receiver.
9057 c_parser_objc_receiver (c_parser
*parser
)
9059 location_t loc
= c_parser_peek_token (parser
)->location
;
9061 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9062 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9063 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9065 tree id
= c_parser_peek_token (parser
)->value
;
9066 c_parser_consume_token (parser
);
9067 return objc_get_class_reference (id
);
9069 struct c_expr ce
= c_parser_expression (parser
);
9070 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9071 return c_fully_fold (ce
.value
, false, NULL
);
9074 /* Parse objc-message-args.
9078 objc-keywordarg-list
9080 objc-keywordarg-list:
9082 objc-keywordarg-list objc-keywordarg
9085 objc-selector : objc-keywordexpr
9090 c_parser_objc_message_args (c_parser
*parser
)
9092 tree sel
= c_parser_objc_selector (parser
);
9093 tree list
= NULL_TREE
;
9094 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9099 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9100 return error_mark_node
;
9101 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9102 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9103 sel
= c_parser_objc_selector (parser
);
9104 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9110 /* Parse an objc-keywordexpr.
9117 c_parser_objc_keywordexpr (c_parser
*parser
)
9120 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9121 NULL
, NULL
, NULL
, NULL
);
9122 if (vec_safe_length (expr_list
) == 1)
9124 /* Just return the expression, remove a level of
9126 ret
= (*expr_list
)[0];
9130 /* We have a comma expression, we will collapse later. */
9131 ret
= build_tree_list_vec (expr_list
);
9133 release_tree_vector (expr_list
);
9137 /* A check, needed in several places, that ObjC interface, implementation or
9138 method definitions are not prefixed by incorrect items. */
9140 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9141 struct c_declspecs
*specs
)
9143 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9144 || specs
->typespec_kind
!= ctsk_none
)
9146 c_parser_error (parser
,
9147 "no type or storage class may be specified here,");
9148 c_parser_skip_to_end_of_block_or_statement (parser
);
9154 /* Parse an Objective-C @property declaration. The syntax is:
9156 objc-property-declaration:
9157 '@property' objc-property-attributes[opt] struct-declaration ;
9159 objc-property-attributes:
9160 '(' objc-property-attribute-list ')'
9162 objc-property-attribute-list:
9163 objc-property-attribute
9164 objc-property-attribute-list, objc-property-attribute
9166 objc-property-attribute
9167 'getter' = identifier
9168 'setter' = identifier
9177 @property NSString *name;
9178 @property (readonly) id object;
9179 @property (retain, nonatomic, getter=getTheName) id name;
9180 @property int a, b, c;
9182 PS: This function is identical to cp_parser_objc_at_propery_declaration
9183 for C++. Keep them in sync. */
9185 c_parser_objc_at_property_declaration (c_parser
*parser
)
9187 /* The following variables hold the attributes of the properties as
9188 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9189 seen. When we see an attribute, we set them to 'true' (if they
9190 are boolean properties) or to the identifier (if they have an
9191 argument, ie, for getter and setter). Note that here we only
9192 parse the list of attributes, check the syntax and accumulate the
9193 attributes that we find. objc_add_property_declaration() will
9194 then process the information. */
9195 bool property_assign
= false;
9196 bool property_copy
= false;
9197 tree property_getter_ident
= NULL_TREE
;
9198 bool property_nonatomic
= false;
9199 bool property_readonly
= false;
9200 bool property_readwrite
= false;
9201 bool property_retain
= false;
9202 tree property_setter_ident
= NULL_TREE
;
9204 /* 'properties' is the list of properties that we read. Usually a
9205 single one, but maybe more (eg, in "@property int a, b, c;" there
9210 loc
= c_parser_peek_token (parser
)->location
;
9211 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9213 c_parser_consume_token (parser
); /* Eat '@property'. */
9215 /* Parse the optional attribute list... */
9216 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9219 c_parser_consume_token (parser
);
9221 /* Property attribute keywords are valid now. */
9222 parser
->objc_property_attr_context
= true;
9226 bool syntax_error
= false;
9227 c_token
*token
= c_parser_peek_token (parser
);
9230 if (token
->type
!= CPP_KEYWORD
)
9232 if (token
->type
== CPP_CLOSE_PAREN
)
9233 c_parser_error (parser
, "expected identifier");
9236 c_parser_consume_token (parser
);
9237 c_parser_error (parser
, "unknown property attribute");
9241 keyword
= token
->keyword
;
9242 c_parser_consume_token (parser
);
9245 case RID_ASSIGN
: property_assign
= true; break;
9246 case RID_COPY
: property_copy
= true; break;
9247 case RID_NONATOMIC
: property_nonatomic
= true; break;
9248 case RID_READONLY
: property_readonly
= true; break;
9249 case RID_READWRITE
: property_readwrite
= true; break;
9250 case RID_RETAIN
: property_retain
= true; break;
9254 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9256 if (keyword
== RID_GETTER
)
9257 c_parser_error (parser
,
9258 "missing %<=%> (after %<getter%> attribute)");
9260 c_parser_error (parser
,
9261 "missing %<=%> (after %<setter%> attribute)");
9262 syntax_error
= true;
9265 c_parser_consume_token (parser
); /* eat the = */
9266 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9268 c_parser_error (parser
, "expected identifier");
9269 syntax_error
= true;
9272 if (keyword
== RID_SETTER
)
9274 if (property_setter_ident
!= NULL_TREE
)
9275 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9277 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9278 c_parser_consume_token (parser
);
9279 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9280 c_parser_error (parser
, "setter name must terminate with %<:%>");
9282 c_parser_consume_token (parser
);
9286 if (property_getter_ident
!= NULL_TREE
)
9287 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9289 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9290 c_parser_consume_token (parser
);
9294 c_parser_error (parser
, "unknown property attribute");
9295 syntax_error
= true;
9302 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9303 c_parser_consume_token (parser
);
9307 parser
->objc_property_attr_context
= false;
9308 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9310 /* ... and the property declaration(s). */
9311 properties
= c_parser_struct_declaration (parser
);
9313 if (properties
== error_mark_node
)
9315 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9316 parser
->error
= false;
9320 if (properties
== NULL_TREE
)
9321 c_parser_error (parser
, "expected identifier");
9324 /* Comma-separated properties are chained together in
9325 reverse order; add them one by one. */
9326 properties
= nreverse (properties
);
9328 for (; properties
; properties
= TREE_CHAIN (properties
))
9329 objc_add_property_declaration (loc
, copy_node (properties
),
9330 property_readonly
, property_readwrite
,
9331 property_assign
, property_retain
,
9332 property_copy
, property_nonatomic
,
9333 property_getter_ident
, property_setter_ident
);
9336 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9337 parser
->error
= false;
9340 /* Parse an Objective-C @synthesize declaration. The syntax is:
9342 objc-synthesize-declaration:
9343 @synthesize objc-synthesize-identifier-list ;
9345 objc-synthesize-identifier-list:
9346 objc-synthesize-identifier
9347 objc-synthesize-identifier-list, objc-synthesize-identifier
9349 objc-synthesize-identifier
9351 identifier = identifier
9354 @synthesize MyProperty;
9355 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9357 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9358 for C++. Keep them in sync.
9361 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9363 tree list
= NULL_TREE
;
9365 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9366 loc
= c_parser_peek_token (parser
)->location
;
9368 c_parser_consume_token (parser
);
9371 tree property
, ivar
;
9372 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9374 c_parser_error (parser
, "expected identifier");
9375 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9376 /* Once we find the semicolon, we can resume normal parsing.
9377 We have to reset parser->error manually because
9378 c_parser_skip_until_found() won't reset it for us if the
9379 next token is precisely a semicolon. */
9380 parser
->error
= false;
9383 property
= c_parser_peek_token (parser
)->value
;
9384 c_parser_consume_token (parser
);
9385 if (c_parser_next_token_is (parser
, CPP_EQ
))
9387 c_parser_consume_token (parser
);
9388 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9390 c_parser_error (parser
, "expected identifier");
9391 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9392 parser
->error
= false;
9395 ivar
= c_parser_peek_token (parser
)->value
;
9396 c_parser_consume_token (parser
);
9400 list
= chainon (list
, build_tree_list (ivar
, property
));
9401 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9402 c_parser_consume_token (parser
);
9406 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9407 objc_add_synthesize_declaration (loc
, list
);
9410 /* Parse an Objective-C @dynamic declaration. The syntax is:
9412 objc-dynamic-declaration:
9413 @dynamic identifier-list ;
9416 @dynamic MyProperty;
9417 @dynamic MyProperty, AnotherProperty;
9419 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9420 for C++. Keep them in sync.
9423 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9425 tree list
= NULL_TREE
;
9427 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9428 loc
= c_parser_peek_token (parser
)->location
;
9430 c_parser_consume_token (parser
);
9434 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9436 c_parser_error (parser
, "expected identifier");
9437 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9438 parser
->error
= false;
9441 property
= c_parser_peek_token (parser
)->value
;
9442 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9443 c_parser_consume_token (parser
);
9444 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9445 c_parser_consume_token (parser
);
9449 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9450 objc_add_dynamic_declaration (loc
, list
);
9454 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9455 should be considered, statements. ALLOW_STMT is true if we're within
9456 the context of a function and such pragmas are to be allowed. Returns
9457 true if we actually parsed such a pragma. */
9460 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9464 id
= c_parser_peek_token (parser
)->pragma_kind
;
9465 gcc_assert (id
!= PRAGMA_NONE
);
9469 case PRAGMA_OMP_BARRIER
:
9470 if (context
!= pragma_compound
)
9472 if (context
== pragma_stmt
)
9473 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9474 "used in compound statements");
9477 c_parser_omp_barrier (parser
);
9480 case PRAGMA_OMP_FLUSH
:
9481 if (context
!= pragma_compound
)
9483 if (context
== pragma_stmt
)
9484 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9485 "used in compound statements");
9488 c_parser_omp_flush (parser
);
9491 case PRAGMA_OMP_TASKWAIT
:
9492 if (context
!= pragma_compound
)
9494 if (context
== pragma_stmt
)
9495 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9496 "used in compound statements");
9499 c_parser_omp_taskwait (parser
);
9502 case PRAGMA_OMP_TASKYIELD
:
9503 if (context
!= pragma_compound
)
9505 if (context
== pragma_stmt
)
9506 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9507 "used in compound statements");
9510 c_parser_omp_taskyield (parser
);
9513 case PRAGMA_OMP_CANCEL
:
9514 if (context
!= pragma_compound
)
9516 if (context
== pragma_stmt
)
9517 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9518 "used in compound statements");
9521 c_parser_omp_cancel (parser
);
9524 case PRAGMA_OMP_CANCELLATION_POINT
:
9525 if (context
!= pragma_compound
)
9527 if (context
== pragma_stmt
)
9528 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9529 "only be used in compound statements");
9532 c_parser_omp_cancellation_point (parser
);
9535 case PRAGMA_OMP_THREADPRIVATE
:
9536 c_parser_omp_threadprivate (parser
);
9539 case PRAGMA_OMP_TARGET
:
9540 return c_parser_omp_target (parser
, context
);
9542 case PRAGMA_OMP_END_DECLARE_TARGET
:
9543 c_parser_omp_end_declare_target (parser
);
9546 case PRAGMA_OMP_SECTION
:
9547 error_at (c_parser_peek_token (parser
)->location
,
9548 "%<#pragma omp section%> may only be used in "
9549 "%<#pragma omp sections%> construct");
9550 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9553 case PRAGMA_OMP_DECLARE_REDUCTION
:
9554 c_parser_omp_declare (parser
, context
);
9557 c_parser_consume_pragma (parser
);
9558 c_parser_skip_to_pragma_eol (parser
);
9559 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9560 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9561 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9563 c_parser_error (parser
, "for, while or do statement expected");
9566 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9567 c_parser_for_statement (parser
, true);
9568 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9569 c_parser_while_statement (parser
, true);
9571 c_parser_do_statement (parser
, true);
9574 case PRAGMA_GCC_PCH_PREPROCESS
:
9575 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9576 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9579 case PRAGMA_CILK_SIMD
:
9580 if (!c_parser_cilk_verify_simd (parser
, context
))
9582 c_parser_consume_pragma (parser
);
9583 c_parser_cilk_simd (parser
);
9587 if (id
< PRAGMA_FIRST_EXTERNAL
)
9589 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9592 c_parser_error (parser
, "expected declaration specifiers");
9593 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9596 c_parser_omp_construct (parser
);
9602 c_parser_consume_pragma (parser
);
9603 c_invoke_pragma_handler (id
);
9605 /* Skip to EOL, but suppress any error message. Those will have been
9606 generated by the handler routine through calling error, as opposed
9607 to calling c_parser_error. */
9608 parser
->error
= true;
9609 c_parser_skip_to_pragma_eol (parser
);
9614 /* The interface the pragma parsers have to the lexer. */
9617 pragma_lex (tree
*value
)
9619 c_token
*tok
= c_parser_peek_token (the_parser
);
9620 enum cpp_ttype ret
= tok
->type
;
9622 *value
= tok
->value
;
9623 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9627 if (ret
== CPP_KEYWORD
)
9629 c_parser_consume_token (the_parser
);
9636 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9640 c_parser_consume_pragma (parser
);
9641 if (c_parser_next_token_is (parser
, CPP_STRING
))
9643 name
= c_parser_peek_token (parser
)->value
;
9644 c_parser_consume_token (parser
);
9647 c_parser_error (parser
, "expected string literal");
9648 c_parser_skip_to_pragma_eol (parser
);
9651 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9654 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9656 /* Returns name of the next clause.
9657 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9658 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9659 returned and the token is consumed. */
9661 static pragma_omp_clause
9662 c_parser_omp_clause_name (c_parser
*parser
)
9664 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9666 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9667 result
= PRAGMA_OMP_CLAUSE_IF
;
9668 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9669 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9670 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9671 result
= PRAGMA_OMP_CLAUSE_FOR
;
9672 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9674 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9679 if (!strcmp ("aligned", p
))
9680 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9683 if (!strcmp ("collapse", p
))
9684 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9685 else if (!strcmp ("copyin", p
))
9686 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9687 else if (!strcmp ("copyprivate", p
))
9688 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9691 if (!strcmp ("depend", p
))
9692 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9693 else if (!strcmp ("device", p
))
9694 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9695 else if (!strcmp ("dist_schedule", p
))
9696 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9699 if (!strcmp ("final", p
))
9700 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9701 else if (!strcmp ("firstprivate", p
))
9702 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9703 else if (!strcmp ("from", p
))
9704 result
= PRAGMA_OMP_CLAUSE_FROM
;
9707 if (!strcmp ("inbranch", p
))
9708 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9711 if (!strcmp ("lastprivate", p
))
9712 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9713 else if (!strcmp ("linear", p
))
9714 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9717 if (!strcmp ("map", p
))
9718 result
= PRAGMA_OMP_CLAUSE_MAP
;
9719 else if (!strcmp ("mergeable", p
))
9720 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9721 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9722 result
= PRAGMA_CILK_CLAUSE_MASK
;
9725 if (!strcmp ("notinbranch", p
))
9726 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9727 else if (!strcmp ("nowait", p
))
9728 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9729 else if (!strcmp ("num_teams", p
))
9730 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9731 else if (!strcmp ("num_threads", p
))
9732 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9733 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9734 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9737 if (!strcmp ("ordered", p
))
9738 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9741 if (!strcmp ("parallel", p
))
9742 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9743 else if (!strcmp ("private", p
))
9744 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9745 else if (!strcmp ("proc_bind", p
))
9746 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9749 if (!strcmp ("reduction", p
))
9750 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9753 if (!strcmp ("safelen", p
))
9754 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9755 else if (!strcmp ("schedule", p
))
9756 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9757 else if (!strcmp ("sections", p
))
9758 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9759 else if (!strcmp ("shared", p
))
9760 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9761 else if (!strcmp ("simdlen", p
))
9762 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9765 if (!strcmp ("taskgroup", p
))
9766 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9767 else if (!strcmp ("thread_limit", p
))
9768 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9769 else if (!strcmp ("to", p
))
9770 result
= PRAGMA_OMP_CLAUSE_TO
;
9773 if (!strcmp ("uniform", p
))
9774 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9775 else if (!strcmp ("untied", p
))
9776 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9779 if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9780 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9785 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9786 c_parser_consume_token (parser
);
9791 /* Validate that a clause of the given type does not already exist. */
9794 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9799 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9800 if (OMP_CLAUSE_CODE (c
) == code
)
9802 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9803 error_at (loc
, "too many %qs clauses", name
);
9811 variable-list , identifier
9813 If KIND is nonzero, create the appropriate node and install the
9814 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9815 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9817 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9818 return the list created. */
9821 c_parser_omp_variable_list (c_parser
*parser
,
9822 location_t clause_loc
,
9823 enum omp_clause_code kind
, tree list
)
9825 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9826 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9827 c_parser_error (parser
, "expected identifier");
9829 while (c_parser_next_token_is (parser
, CPP_NAME
)
9830 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9832 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9836 undeclared_variable (c_parser_peek_token (parser
)->location
,
9837 c_parser_peek_token (parser
)->value
);
9838 t
= error_mark_node
;
9841 c_parser_consume_token (parser
);
9843 if (t
== error_mark_node
)
9849 case OMP_CLAUSE_MAP
:
9850 case OMP_CLAUSE_FROM
:
9852 case OMP_CLAUSE_DEPEND
:
9853 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9855 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9857 c_parser_consume_token (parser
);
9858 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9859 low_bound
= c_parser_expression (parser
).value
;
9860 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9861 length
= integer_one_node
;
9865 if (!c_parser_require (parser
, CPP_COLON
,
9868 t
= error_mark_node
;
9871 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9872 length
= c_parser_expression (parser
).value
;
9874 /* Look for the closing `]'. */
9875 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9878 t
= error_mark_node
;
9881 t
= tree_cons (low_bound
, length
, t
);
9888 if (t
!= error_mark_node
)
9890 tree u
= build_omp_clause (clause_loc
, kind
);
9891 OMP_CLAUSE_DECL (u
) = t
;
9892 OMP_CLAUSE_CHAIN (u
) = list
;
9897 list
= tree_cons (t
, NULL_TREE
, list
);
9899 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9902 c_parser_consume_token (parser
);
9908 /* Similarly, but expect leading and trailing parenthesis. This is a very
9909 common case for omp clauses. */
9912 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9915 /* The clauses location. */
9916 location_t loc
= c_parser_peek_token (parser
)->location
;
9918 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9920 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9921 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9927 collapse ( constant-expression ) */
9930 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9932 tree c
, num
= error_mark_node
;
9936 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9938 loc
= c_parser_peek_token (parser
)->location
;
9939 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9941 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9944 if (num
== error_mark_node
)
9946 mark_exp_read (num
);
9947 num
= c_fully_fold (num
, false, NULL
);
9948 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9949 || !tree_fits_shwi_p (num
)
9950 || (n
= tree_to_shwi (num
)) <= 0
9954 "collapse argument needs positive constant integer expression");
9957 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9958 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9959 OMP_CLAUSE_CHAIN (c
) = list
;
9964 copyin ( variable-list ) */
9967 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9969 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9973 copyprivate ( variable-list ) */
9976 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9978 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9982 default ( shared | none ) */
9985 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9987 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9988 location_t loc
= c_parser_peek_token (parser
)->location
;
9991 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9993 if (c_parser_next_token_is (parser
, CPP_NAME
))
9995 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10000 if (strcmp ("none", p
) != 0)
10002 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10006 if (strcmp ("shared", p
) != 0)
10008 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10015 c_parser_consume_token (parser
);
10020 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10022 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10024 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10027 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10028 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10029 OMP_CLAUSE_CHAIN (c
) = list
;
10030 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10036 firstprivate ( variable-list ) */
10039 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10041 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10045 final ( expression ) */
10048 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10050 location_t loc
= c_parser_peek_token (parser
)->location
;
10051 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10053 tree t
= c_parser_paren_condition (parser
);
10056 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10058 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10059 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10060 OMP_CLAUSE_CHAIN (c
) = list
;
10064 c_parser_error (parser
, "expected %<(%>");
10070 if ( expression ) */
10073 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10075 location_t loc
= c_parser_peek_token (parser
)->location
;
10076 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10078 tree t
= c_parser_paren_condition (parser
);
10081 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10083 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10084 OMP_CLAUSE_IF_EXPR (c
) = t
;
10085 OMP_CLAUSE_CHAIN (c
) = list
;
10089 c_parser_error (parser
, "expected %<(%>");
10095 lastprivate ( variable-list ) */
10098 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10100 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10107 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10111 /* FIXME: Should we allow duplicates? */
10112 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10114 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10115 OMP_CLAUSE_MERGEABLE
);
10116 OMP_CLAUSE_CHAIN (c
) = list
;
10125 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10128 location_t loc
= c_parser_peek_token (parser
)->location
;
10130 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10132 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10133 OMP_CLAUSE_CHAIN (c
) = list
;
10138 num_threads ( expression ) */
10141 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10143 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10144 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10146 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10147 tree c
, t
= c_parser_expression (parser
).value
;
10149 t
= c_fully_fold (t
, false, NULL
);
10151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10153 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10155 c_parser_error (parser
, "expected integer expression");
10159 /* Attempt to statically determine when the number isn't positive. */
10160 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10161 build_int_cst (TREE_TYPE (t
), 0));
10162 if (CAN_HAVE_LOCATION_P (c
))
10163 SET_EXPR_LOCATION (c
, expr_loc
);
10164 if (c
== boolean_true_node
)
10166 warning_at (expr_loc
, 0,
10167 "%<num_threads%> value must be positive");
10168 t
= integer_one_node
;
10171 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10173 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10174 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10175 OMP_CLAUSE_CHAIN (c
) = list
;
10186 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10190 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10192 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10193 OMP_CLAUSE_ORDERED
);
10194 OMP_CLAUSE_CHAIN (c
) = list
;
10200 private ( variable-list ) */
10203 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10205 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10209 reduction ( reduction-operator : variable-list )
10211 reduction-operator:
10212 One of: + * - & ^ | && ||
10216 reduction-operator:
10217 One of: + * - & ^ | && || max min
10221 reduction-operator:
10222 One of: + * - & ^ | && ||
10226 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10228 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10229 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10231 enum tree_code code
= ERROR_MARK
;
10232 tree reduc_id
= NULL_TREE
;
10234 switch (c_parser_peek_token (parser
)->type
)
10246 code
= BIT_AND_EXPR
;
10249 code
= BIT_XOR_EXPR
;
10252 code
= BIT_IOR_EXPR
;
10255 code
= TRUTH_ANDIF_EXPR
;
10258 code
= TRUTH_ORIF_EXPR
;
10263 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10264 if (strcmp (p
, "min") == 0)
10269 if (strcmp (p
, "max") == 0)
10274 reduc_id
= c_parser_peek_token (parser
)->value
;
10278 c_parser_error (parser
,
10279 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10280 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10281 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10284 c_parser_consume_token (parser
);
10285 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10286 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10290 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10291 OMP_CLAUSE_REDUCTION
, list
);
10292 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10294 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10295 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10296 if (code
== ERROR_MARK
10297 || !(INTEGRAL_TYPE_P (type
)
10298 || TREE_CODE (type
) == REAL_TYPE
10299 || TREE_CODE (type
) == COMPLEX_TYPE
))
10300 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10301 = c_omp_reduction_lookup (reduc_id
,
10302 TYPE_MAIN_VARIANT (type
));
10307 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10313 schedule ( schedule-kind )
10314 schedule ( schedule-kind , expression )
10317 static | dynamic | guided | runtime | auto
10321 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10324 location_t loc
= c_parser_peek_token (parser
)->location
;
10326 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10329 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10331 if (c_parser_next_token_is (parser
, CPP_NAME
))
10333 tree kind
= c_parser_peek_token (parser
)->value
;
10334 const char *p
= IDENTIFIER_POINTER (kind
);
10339 if (strcmp ("dynamic", p
) != 0)
10341 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10345 if (strcmp ("guided", p
) != 0)
10347 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10351 if (strcmp ("runtime", p
) != 0)
10353 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10360 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10361 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10362 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10363 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10367 c_parser_consume_token (parser
);
10368 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10371 c_parser_consume_token (parser
);
10373 here
= c_parser_peek_token (parser
)->location
;
10374 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10376 t
= c_fully_fold (t
, false, NULL
);
10378 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10379 error_at (here
, "schedule %<runtime%> does not take "
10380 "a %<chunk_size%> parameter");
10381 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10383 "schedule %<auto%> does not take "
10384 "a %<chunk_size%> parameter");
10385 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10386 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10388 c_parser_error (parser
, "expected integer expression");
10390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10393 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10394 "expected %<,%> or %<)%>");
10396 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10397 OMP_CLAUSE_CHAIN (c
) = list
;
10401 c_parser_error (parser
, "invalid schedule kind");
10402 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10407 shared ( variable-list ) */
10410 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10412 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10419 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10423 /* FIXME: Should we allow duplicates? */
10424 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10426 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10427 OMP_CLAUSE_UNTIED
);
10428 OMP_CLAUSE_CHAIN (c
) = list
;
10438 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10439 enum omp_clause_code code
, tree list
)
10441 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10443 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10444 OMP_CLAUSE_CHAIN (c
) = list
;
10456 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10457 enum omp_clause_code code
, tree list
)
10459 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10460 OMP_CLAUSE_CHAIN (c
) = list
;
10466 num_teams ( expression ) */
10469 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10471 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10472 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10474 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10475 tree c
, t
= c_parser_expression (parser
).value
;
10477 t
= c_fully_fold (t
, false, NULL
);
10479 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10481 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10483 c_parser_error (parser
, "expected integer expression");
10487 /* Attempt to statically determine when the number isn't positive. */
10488 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10489 build_int_cst (TREE_TYPE (t
), 0));
10490 if (CAN_HAVE_LOCATION_P (c
))
10491 SET_EXPR_LOCATION (c
, expr_loc
);
10492 if (c
== boolean_true_node
)
10494 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10495 t
= integer_one_node
;
10498 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10500 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10501 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10502 OMP_CLAUSE_CHAIN (c
) = list
;
10510 thread_limit ( expression ) */
10513 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10515 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
10516 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10518 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10519 tree c
, t
= c_parser_expression (parser
).value
;
10521 t
= c_fully_fold (t
, false, NULL
);
10523 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10525 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10527 c_parser_error (parser
, "expected integer expression");
10531 /* Attempt to statically determine when the number isn't positive. */
10532 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10533 build_int_cst (TREE_TYPE (t
), 0));
10534 if (CAN_HAVE_LOCATION_P (c
))
10535 SET_EXPR_LOCATION (c
, expr_loc
);
10536 if (c
== boolean_true_node
)
10538 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10539 t
= integer_one_node
;
10542 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10545 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10546 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10547 OMP_CLAUSE_CHAIN (c
) = list
;
10555 aligned ( variable-list )
10556 aligned ( variable-list : constant-expression ) */
10559 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10561 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10564 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10567 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10568 OMP_CLAUSE_ALIGNED
, list
);
10570 if (c_parser_next_token_is (parser
, CPP_COLON
))
10572 c_parser_consume_token (parser
);
10573 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10574 mark_exp_read (alignment
);
10575 alignment
= c_fully_fold (alignment
, false, NULL
);
10576 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10577 && TREE_CODE (alignment
) != INTEGER_CST
10578 && tree_int_cst_sgn (alignment
) != 1)
10580 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10581 "be positive constant integer expression");
10582 alignment
= NULL_TREE
;
10585 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10586 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10589 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10594 linear ( variable-list )
10595 linear ( variable-list : expression ) */
10598 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
10600 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10603 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10606 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10607 OMP_CLAUSE_LINEAR
, list
);
10609 if (c_parser_next_token_is (parser
, CPP_COLON
))
10611 c_parser_consume_token (parser
);
10612 step
= c_parser_expression (parser
).value
;
10613 mark_exp_read (step
);
10614 step
= c_fully_fold (step
, false, NULL
);
10615 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
10617 sorry ("using parameters for %<linear%> step is not supported yet");
10618 step
= integer_one_node
;
10620 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10622 error_at (clause_loc
, "%<linear%> clause step expression must "
10624 step
= integer_one_node
;
10629 step
= integer_one_node
;
10631 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10633 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10636 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10641 safelen ( constant-expression ) */
10644 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10646 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10649 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10652 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10654 t
= c_fully_fold (t
, false, NULL
);
10655 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10656 && TREE_CODE (t
) != INTEGER_CST
10657 && tree_int_cst_sgn (t
) != 1)
10659 error_at (clause_loc
, "%<safelen%> clause expression must "
10660 "be positive constant integer expression");
10664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10665 if (t
== NULL_TREE
|| t
== error_mark_node
)
10668 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10670 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10671 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10672 OMP_CLAUSE_CHAIN (c
) = list
;
10677 simdlen ( constant-expression ) */
10680 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10682 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10685 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10688 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10690 t
= c_fully_fold (t
, false, NULL
);
10691 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10692 && TREE_CODE (t
) != INTEGER_CST
10693 && tree_int_cst_sgn (t
) != 1)
10695 error_at (clause_loc
, "%<simdlen%> clause expression must "
10696 "be positive constant integer expression");
10700 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10701 if (t
== NULL_TREE
|| t
== error_mark_node
)
10704 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10706 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10707 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10708 OMP_CLAUSE_CHAIN (c
) = list
;
10713 depend ( depend-kind: variable-list )
10716 in | out | inout */
10719 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10721 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10722 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10725 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10728 if (c_parser_next_token_is (parser
, CPP_NAME
))
10730 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10731 if (strcmp ("in", p
) == 0)
10732 kind
= OMP_CLAUSE_DEPEND_IN
;
10733 else if (strcmp ("inout", p
) == 0)
10734 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10735 else if (strcmp ("out", p
) == 0)
10736 kind
= OMP_CLAUSE_DEPEND_OUT
;
10743 c_parser_consume_token (parser
);
10744 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10747 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10748 OMP_CLAUSE_DEPEND
, list
);
10750 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10751 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10753 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10757 c_parser_error (parser
, "invalid depend kind");
10759 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10764 map ( map-kind: variable-list )
10765 map ( variable-list )
10768 alloc | to | from | tofrom */
10771 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10773 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10774 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10777 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10780 if (c_parser_next_token_is (parser
, CPP_NAME
)
10781 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10783 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10784 if (strcmp ("alloc", p
) == 0)
10785 kind
= OMP_CLAUSE_MAP_ALLOC
;
10786 else if (strcmp ("to", p
) == 0)
10787 kind
= OMP_CLAUSE_MAP_TO
;
10788 else if (strcmp ("from", p
) == 0)
10789 kind
= OMP_CLAUSE_MAP_FROM
;
10790 else if (strcmp ("tofrom", p
) == 0)
10791 kind
= OMP_CLAUSE_MAP_TOFROM
;
10794 c_parser_error (parser
, "invalid map kind");
10795 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10799 c_parser_consume_token (parser
);
10800 c_parser_consume_token (parser
);
10803 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10805 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10806 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10808 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10813 device ( expression ) */
10816 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10818 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10819 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10821 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10823 t
= c_fully_fold (t
, false, NULL
);
10825 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10827 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10829 c_parser_error (parser
, "expected integer expression");
10833 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10835 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10836 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10837 OMP_CLAUSE_CHAIN (c
) = list
;
10845 dist_schedule ( static )
10846 dist_schedule ( static , expression ) */
10849 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10851 tree c
, t
= NULL_TREE
;
10852 location_t loc
= c_parser_peek_token (parser
)->location
;
10854 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10857 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10859 c_parser_error (parser
, "invalid dist_schedule kind");
10860 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10865 c_parser_consume_token (parser
);
10866 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10868 c_parser_consume_token (parser
);
10870 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10872 t
= c_fully_fold (t
, false, NULL
);
10873 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10876 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10877 "expected %<,%> or %<)%>");
10879 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10880 if (t
== error_mark_node
)
10883 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10884 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10885 OMP_CLAUSE_CHAIN (c
) = list
;
10890 proc_bind ( proc-bind-kind )
10893 master | close | spread */
10896 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10898 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10899 enum omp_clause_proc_bind_kind kind
;
10902 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10905 if (c_parser_next_token_is (parser
, CPP_NAME
))
10907 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10908 if (strcmp ("master", p
) == 0)
10909 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10910 else if (strcmp ("close", p
) == 0)
10911 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10912 else if (strcmp ("spread", p
) == 0)
10913 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10920 c_parser_consume_token (parser
);
10921 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10922 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10923 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10924 OMP_CLAUSE_CHAIN (c
) = list
;
10928 c_parser_error (parser
, "invalid proc_bind kind");
10929 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10934 to ( variable-list ) */
10937 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10939 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10943 from ( variable-list ) */
10946 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10948 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10952 uniform ( variable-list ) */
10955 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10957 /* The clauses location. */
10958 location_t loc
= c_parser_peek_token (parser
)->location
;
10960 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10962 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10964 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10969 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10970 is a bitmask in MASK. Return the list of clauses found; the result
10971 of clause default goes in *pdefault. */
10974 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10975 const char *where
, bool finish_p
= true)
10977 tree clauses
= NULL
;
10978 bool first
= true, cilk_simd_fn
= false;
10980 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10983 pragma_omp_clause c_kind
;
10984 const char *c_name
;
10985 tree prev
= clauses
;
10987 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10988 c_parser_consume_token (parser
);
10990 here
= c_parser_peek_token (parser
)->location
;
10991 c_kind
= c_parser_omp_clause_name (parser
);
10995 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10996 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10997 c_name
= "collapse";
10999 case PRAGMA_OMP_CLAUSE_COPYIN
:
11000 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11003 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11004 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11005 c_name
= "copyprivate";
11007 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11008 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11009 c_name
= "default";
11011 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11012 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11013 c_name
= "firstprivate";
11015 case PRAGMA_OMP_CLAUSE_FINAL
:
11016 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11019 case PRAGMA_OMP_CLAUSE_IF
:
11020 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11023 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11024 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11025 c_name
= "lastprivate";
11027 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11028 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11029 c_name
= "mergeable";
11031 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11032 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11035 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11036 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11037 c_name
= "num_threads";
11039 case PRAGMA_OMP_CLAUSE_ORDERED
:
11040 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11041 c_name
= "ordered";
11043 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11044 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11045 c_name
= "private";
11047 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11048 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11049 c_name
= "reduction";
11051 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11052 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11053 c_name
= "schedule";
11055 case PRAGMA_OMP_CLAUSE_SHARED
:
11056 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11059 case PRAGMA_OMP_CLAUSE_UNTIED
:
11060 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11063 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11064 case PRAGMA_CILK_CLAUSE_MASK
:
11065 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11067 c_name
= "inbranch";
11069 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11070 case PRAGMA_CILK_CLAUSE_NOMASK
:
11071 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11073 c_name
= "notinbranch";
11075 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11077 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11079 c_name
= "parallel";
11083 error_at (here
, "%qs must be the first clause of %qs",
11088 case PRAGMA_OMP_CLAUSE_FOR
:
11090 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11094 goto clause_not_first
;
11096 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11098 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11100 c_name
= "sections";
11102 goto clause_not_first
;
11104 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11106 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11108 c_name
= "taskgroup";
11110 goto clause_not_first
;
11112 case PRAGMA_OMP_CLAUSE_TO
:
11113 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11116 case PRAGMA_OMP_CLAUSE_FROM
:
11117 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11120 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11121 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11122 c_name
= "uniform";
11124 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11125 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11126 c_name
= "num_teams";
11128 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11129 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11130 c_name
= "thread_limit";
11132 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11133 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11134 c_name
= "aligned";
11136 case PRAGMA_OMP_CLAUSE_LINEAR
:
11137 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11138 cilk_simd_fn
= true;
11139 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11142 case PRAGMA_OMP_CLAUSE_DEPEND
:
11143 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11146 case PRAGMA_OMP_CLAUSE_MAP
:
11147 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11150 case PRAGMA_OMP_CLAUSE_DEVICE
:
11151 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11154 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11155 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11156 c_name
= "dist_schedule";
11158 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11159 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11160 c_name
= "proc_bind";
11162 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11163 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11164 c_name
= "safelen";
11166 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11167 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11168 c_name
= "simdlen";
11170 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11171 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11172 c_name
= "simdlen";
11175 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11181 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11183 /* Remove the invalid clause(s) from the list to avoid
11184 confusing the rest of the compiler. */
11186 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11191 c_parser_skip_to_pragma_eol (parser
);
11194 return c_finish_omp_clauses (clauses
);
11203 In practice, we're also interested in adding the statement to an
11204 outer node. So it is convenient if we work around the fact that
11205 c_parser_statement calls add_stmt. */
11208 c_parser_omp_structured_block (c_parser
*parser
)
11210 tree stmt
= push_stmt_list ();
11211 c_parser_statement (parser
);
11212 return pop_stmt_list (stmt
);
11216 # pragma omp atomic new-line
11220 x binop= expr | x++ | ++x | x-- | --x
11222 +, *, -, /, &, ^, |, <<, >>
11224 where x is an lvalue expression with scalar type.
11227 # pragma omp atomic new-line
11230 # pragma omp atomic read new-line
11233 # pragma omp atomic write new-line
11236 # pragma omp atomic update new-line
11239 # pragma omp atomic capture new-line
11242 # pragma omp atomic capture new-line
11250 expression-stmt | x = x binop expr
11252 v = expression-stmt
11254 { v = x; update-stmt; } | { update-stmt; v = x; }
11258 expression-stmt | x = x binop expr | x = expr binop x
11262 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11264 where x and v are lvalue expressions with scalar type.
11266 LOC is the location of the #pragma token. */
11269 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11271 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11272 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11273 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11274 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11275 struct c_expr expr
;
11277 bool structured_block
= false;
11278 bool swapped
= false;
11279 bool seq_cst
= false;
11281 if (c_parser_next_token_is (parser
, CPP_NAME
))
11283 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11284 if (!strcmp (p
, "seq_cst"))
11287 c_parser_consume_token (parser
);
11288 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11289 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11290 c_parser_consume_token (parser
);
11293 if (c_parser_next_token_is (parser
, CPP_NAME
))
11295 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11297 if (!strcmp (p
, "read"))
11298 code
= OMP_ATOMIC_READ
;
11299 else if (!strcmp (p
, "write"))
11301 else if (!strcmp (p
, "update"))
11303 else if (!strcmp (p
, "capture"))
11304 code
= OMP_ATOMIC_CAPTURE_NEW
;
11308 c_parser_consume_token (parser
);
11312 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11313 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11314 c_parser_consume_token (parser
);
11316 if (c_parser_next_token_is (parser
, CPP_NAME
))
11319 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11320 if (!strcmp (p
, "seq_cst"))
11323 c_parser_consume_token (parser
);
11327 c_parser_skip_to_pragma_eol (parser
);
11331 case OMP_ATOMIC_READ
:
11332 case NOP_EXPR
: /* atomic write */
11333 v
= c_parser_unary_expression (parser
).value
;
11334 v
= c_fully_fold (v
, false, NULL
);
11335 if (v
== error_mark_node
)
11337 loc
= c_parser_peek_token (parser
)->location
;
11338 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11340 if (code
== NOP_EXPR
)
11341 lhs
= c_parser_expression (parser
).value
;
11343 lhs
= c_parser_unary_expression (parser
).value
;
11344 lhs
= c_fully_fold (lhs
, false, NULL
);
11345 if (lhs
== error_mark_node
)
11347 if (code
== NOP_EXPR
)
11349 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11357 case OMP_ATOMIC_CAPTURE_NEW
:
11358 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11360 c_parser_consume_token (parser
);
11361 structured_block
= true;
11365 v
= c_parser_unary_expression (parser
).value
;
11366 v
= c_fully_fold (v
, false, NULL
);
11367 if (v
== error_mark_node
)
11369 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11377 /* For structured_block case we don't know yet whether
11378 old or new x should be captured. */
11380 eloc
= c_parser_peek_token (parser
)->location
;
11381 expr
= c_parser_unary_expression (parser
);
11383 expr
= default_function_array_conversion (eloc
, expr
);
11384 unfolded_lhs
= expr
.value
;
11385 lhs
= c_fully_fold (lhs
, false, NULL
);
11387 switch (TREE_CODE (lhs
))
11391 c_parser_skip_to_end_of_block_or_statement (parser
);
11392 if (structured_block
)
11394 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11395 c_parser_consume_token (parser
);
11396 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11398 c_parser_skip_to_end_of_block_or_statement (parser
);
11399 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11400 c_parser_consume_token (parser
);
11405 case POSTINCREMENT_EXPR
:
11406 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11407 code
= OMP_ATOMIC_CAPTURE_OLD
;
11409 case PREINCREMENT_EXPR
:
11410 lhs
= TREE_OPERAND (lhs
, 0);
11411 unfolded_lhs
= NULL_TREE
;
11412 opcode
= PLUS_EXPR
;
11413 rhs
= integer_one_node
;
11416 case POSTDECREMENT_EXPR
:
11417 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11418 code
= OMP_ATOMIC_CAPTURE_OLD
;
11420 case PREDECREMENT_EXPR
:
11421 lhs
= TREE_OPERAND (lhs
, 0);
11422 unfolded_lhs
= NULL_TREE
;
11423 opcode
= MINUS_EXPR
;
11424 rhs
= integer_one_node
;
11427 case COMPOUND_EXPR
:
11428 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11429 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11430 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11431 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11432 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11433 (TREE_OPERAND (lhs
, 1), 0), 0)))
11435 /* Undo effects of boolean_increment for post {in,de}crement. */
11436 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11439 if (TREE_CODE (lhs
) == MODIFY_EXPR
11440 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11442 /* Undo effects of boolean_increment. */
11443 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11445 /* This is pre or post increment. */
11446 rhs
= TREE_OPERAND (lhs
, 1);
11447 lhs
= TREE_OPERAND (lhs
, 0);
11448 unfolded_lhs
= NULL_TREE
;
11450 if (code
== OMP_ATOMIC_CAPTURE_NEW
11451 && !structured_block
11452 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11453 code
= OMP_ATOMIC_CAPTURE_OLD
;
11456 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11457 && TREE_OPERAND (lhs
, 0)
11458 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11460 /* This is pre or post decrement. */
11461 rhs
= TREE_OPERAND (lhs
, 1);
11462 lhs
= TREE_OPERAND (lhs
, 0);
11463 unfolded_lhs
= NULL_TREE
;
11465 if (code
== OMP_ATOMIC_CAPTURE_NEW
11466 && !structured_block
11467 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11468 code
= OMP_ATOMIC_CAPTURE_OLD
;
11474 switch (c_parser_peek_token (parser
)->type
)
11477 opcode
= MULT_EXPR
;
11480 opcode
= TRUNC_DIV_EXPR
;
11483 opcode
= PLUS_EXPR
;
11486 opcode
= MINUS_EXPR
;
11488 case CPP_LSHIFT_EQ
:
11489 opcode
= LSHIFT_EXPR
;
11491 case CPP_RSHIFT_EQ
:
11492 opcode
= RSHIFT_EXPR
;
11495 opcode
= BIT_AND_EXPR
;
11498 opcode
= BIT_IOR_EXPR
;
11501 opcode
= BIT_XOR_EXPR
;
11504 c_parser_consume_token (parser
);
11505 eloc
= c_parser_peek_token (parser
)->location
;
11506 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11508 switch (TREE_CODE (rhs1
))
11511 case TRUNC_DIV_EXPR
:
11519 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11521 opcode
= TREE_CODE (rhs1
);
11522 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11523 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11526 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11528 opcode
= TREE_CODE (rhs1
);
11529 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11530 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11531 swapped
= !commutative_tree_code (opcode
);
11540 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11542 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11544 code
= OMP_ATOMIC_CAPTURE_OLD
;
11547 expr
= default_function_array_read_conversion (eloc
, expr
);
11548 unfolded_lhs1
= expr
.value
;
11549 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11551 c_parser_consume_token (parser
);
11554 if (structured_block
)
11557 expr
= default_function_array_read_conversion (eloc
, expr
);
11558 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11563 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11566 c_parser_error (parser
,
11567 "invalid operator for %<#pragma omp atomic%>");
11571 /* Arrange to pass the location of the assignment operator to
11572 c_finish_omp_atomic. */
11573 loc
= c_parser_peek_token (parser
)->location
;
11574 c_parser_consume_token (parser
);
11575 eloc
= c_parser_peek_token (parser
)->location
;
11576 expr
= c_parser_expression (parser
);
11577 expr
= default_function_array_read_conversion (eloc
, expr
);
11579 rhs
= c_fully_fold (rhs
, false, NULL
);
11583 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11585 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11587 v
= c_parser_unary_expression (parser
).value
;
11588 v
= c_fully_fold (v
, false, NULL
);
11589 if (v
== error_mark_node
)
11591 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11593 eloc
= c_parser_peek_token (parser
)->location
;
11594 expr
= c_parser_unary_expression (parser
);
11596 expr
= default_function_array_read_conversion (eloc
, expr
);
11597 unfolded_lhs1
= expr
.value
;
11598 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11599 if (lhs1
== error_mark_node
)
11602 if (structured_block
)
11604 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11605 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11608 if (unfolded_lhs
&& unfolded_lhs1
11609 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11611 error ("%<#pragma omp atomic capture%> uses two different "
11612 "expressions for memory");
11613 stmt
= error_mark_node
;
11616 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11618 if (stmt
!= error_mark_node
)
11621 if (!structured_block
)
11622 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11627 # pragma omp barrier new-line
11631 c_parser_omp_barrier (c_parser
*parser
)
11633 location_t loc
= c_parser_peek_token (parser
)->location
;
11634 c_parser_consume_pragma (parser
);
11635 c_parser_skip_to_pragma_eol (parser
);
11637 c_finish_omp_barrier (loc
);
11641 # pragma omp critical [(name)] new-line
11644 LOC is the location of the #pragma itself. */
11647 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11649 tree stmt
, name
= NULL
;
11651 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11653 c_parser_consume_token (parser
);
11654 if (c_parser_next_token_is (parser
, CPP_NAME
))
11656 name
= c_parser_peek_token (parser
)->value
;
11657 c_parser_consume_token (parser
);
11658 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11661 c_parser_error (parser
, "expected identifier");
11663 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11664 c_parser_error (parser
, "expected %<(%> or end of line");
11665 c_parser_skip_to_pragma_eol (parser
);
11667 stmt
= c_parser_omp_structured_block (parser
);
11668 return c_finish_omp_critical (loc
, stmt
, name
);
11672 # pragma omp flush flush-vars[opt] new-line
11675 ( variable-list ) */
11678 c_parser_omp_flush (c_parser
*parser
)
11680 location_t loc
= c_parser_peek_token (parser
)->location
;
11681 c_parser_consume_pragma (parser
);
11682 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11683 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11684 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11685 c_parser_error (parser
, "expected %<(%> or end of line");
11686 c_parser_skip_to_pragma_eol (parser
);
11688 c_finish_omp_flush (loc
);
11691 /* Parse the restricted form of the for statement allowed by OpenMP.
11692 The real trick here is to determine the loop control variable early
11693 so that we can push a new decl if necessary to make it private.
11694 LOC is the location of the OMP in "#pragma omp". */
11697 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11698 tree clauses
, tree
*cclauses
)
11700 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11701 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11702 bool fail
= false, open_brace_parsed
= false;
11703 int i
, collapse
= 1, nbraces
= 0;
11704 location_t for_loc
;
11705 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11707 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11708 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11709 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
11711 gcc_assert (collapse
>= 1);
11713 declv
= make_tree_vec (collapse
);
11714 initv
= make_tree_vec (collapse
);
11715 condv
= make_tree_vec (collapse
);
11716 incrv
= make_tree_vec (collapse
);
11718 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11720 c_parser_error (parser
, "for statement expected");
11723 for_loc
= c_parser_peek_token (parser
)->location
;
11724 c_parser_consume_token (parser
);
11726 for (i
= 0; i
< collapse
; i
++)
11728 int bracecount
= 0;
11730 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11733 /* Parse the initialization declaration or expression. */
11734 if (c_parser_next_tokens_start_declaration (parser
))
11737 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11738 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11740 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11743 if (DECL_INITIAL (decl
) == error_mark_node
)
11744 decl
= error_mark_node
;
11747 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11748 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11750 struct c_expr decl_exp
;
11751 struct c_expr init_exp
;
11752 location_t init_loc
;
11754 decl_exp
= c_parser_postfix_expression (parser
);
11755 decl
= decl_exp
.value
;
11757 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11759 init_loc
= c_parser_peek_token (parser
)->location
;
11760 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11761 init_exp
= default_function_array_read_conversion (init_loc
,
11763 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11764 NOP_EXPR
, init_loc
, init_exp
.value
,
11765 init_exp
.original_type
);
11766 init
= c_process_expr_stmt (init_loc
, init
);
11768 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11773 c_parser_error (parser
,
11774 "expected iteration declaration or initialization");
11775 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11781 /* Parse the loop condition. */
11783 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11785 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11786 struct c_expr cond_expr
11787 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11789 cond
= cond_expr
.value
;
11790 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11791 cond
= c_fully_fold (cond
, false, NULL
);
11792 switch (cond_expr
.original_code
)
11800 if (code
== CILK_SIMD
)
11804 /* Can't be cond = error_mark_node, because we want to preserve
11805 the location until c_finish_omp_for. */
11806 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11809 protected_set_expr_location (cond
, cond_loc
);
11811 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11813 /* Parse the increment expression. */
11815 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11817 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11819 incr
= c_process_expr_stmt (incr_loc
,
11820 c_parser_expression (parser
).value
);
11822 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11824 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11828 TREE_VEC_ELT (declv
, i
) = decl
;
11829 TREE_VEC_ELT (initv
, i
) = init
;
11830 TREE_VEC_ELT (condv
, i
) = cond
;
11831 TREE_VEC_ELT (incrv
, i
) = incr
;
11835 if (i
== collapse
- 1)
11838 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11839 in between the collapsed for loops to be still considered perfectly
11840 nested. Hopefully the final version clarifies this.
11841 For now handle (multiple) {'s and empty statements. */
11844 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11846 c_parser_consume_token (parser
);
11849 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11851 c_parser_consume_token (parser
);
11854 else if (bracecount
11855 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11856 c_parser_consume_token (parser
);
11859 c_parser_error (parser
, "not enough perfectly nested loops");
11862 open_brace_parsed
= true;
11872 nbraces
+= bracecount
;
11875 save_break
= c_break_label
;
11876 if (code
== CILK_SIMD
)
11877 c_break_label
= build_int_cst (size_type_node
, 2);
11879 c_break_label
= size_one_node
;
11880 save_cont
= c_cont_label
;
11881 c_cont_label
= NULL_TREE
;
11882 body
= push_stmt_list ();
11884 if (open_brace_parsed
)
11886 location_t here
= c_parser_peek_token (parser
)->location
;
11887 stmt
= c_begin_compound_stmt (true);
11888 c_parser_compound_statement_nostart (parser
);
11889 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11892 add_stmt (c_parser_c99_block_statement (parser
));
11895 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11896 SET_EXPR_LOCATION (t
, loc
);
11900 body
= pop_stmt_list (body
);
11901 c_break_label
= save_break
;
11902 c_cont_label
= save_cont
;
11906 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11908 c_parser_consume_token (parser
);
11911 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11912 c_parser_consume_token (parser
);
11915 c_parser_error (parser
, "collapsed loops not perfectly nested");
11918 location_t here
= c_parser_peek_token (parser
)->location
;
11919 stmt
= c_begin_compound_stmt (true);
11921 c_parser_compound_statement_nostart (parser
);
11922 body
= c_end_compound_stmt (here
, stmt
, true);
11929 /* Only bother calling c_finish_omp_for if we haven't already generated
11930 an error from the initialization parsing. */
11933 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11934 incrv
, body
, NULL
);
11937 if (cclauses
!= NULL
11938 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11941 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11942 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11943 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11944 c
= &OMP_CLAUSE_CHAIN (*c
);
11947 for (i
= 0; i
< collapse
; i
++)
11948 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11951 c
= &OMP_CLAUSE_CHAIN (*c
);
11952 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11955 "iteration variable %qD should not be firstprivate",
11956 OMP_CLAUSE_DECL (*c
));
11957 *c
= OMP_CLAUSE_CHAIN (*c
);
11961 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11962 change it to shared (decl) in
11963 OMP_PARALLEL_CLAUSES. */
11964 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11965 OMP_CLAUSE_LASTPRIVATE
);
11966 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11967 if (code
== OMP_SIMD
)
11969 OMP_CLAUSE_CHAIN (l
)
11970 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11971 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
11975 OMP_CLAUSE_CHAIN (l
) = clauses
;
11978 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11982 OMP_FOR_CLAUSES (stmt
) = clauses
;
11987 while (!for_block
->is_empty ())
11989 /* FIXME diagnostics: LOC below should be the actual location of
11990 this particular for block. We need to build a list of
11991 locations to go along with FOR_BLOCK. */
11992 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11995 release_tree_vector (for_block
);
11999 /* Helper function for OpenMP parsing, split clauses and call
12000 finish_omp_clauses on each of the set of clauses afterwards. */
12003 omp_split_clauses (location_t loc
, enum tree_code code
,
12004 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
12007 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
12008 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
12010 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
12014 #pragma omp simd simd-clause[optseq] new-line
12017 LOC is the location of the #pragma token.
12020 #define OMP_SIMD_CLAUSE_MASK \
12021 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
12022 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12023 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12024 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12025 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12026 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12027 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12030 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
12031 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12033 tree block
, clauses
, ret
;
12035 strcat (p_name
, " simd");
12036 mask
|= OMP_SIMD_CLAUSE_MASK
;
12037 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
12039 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12042 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
12043 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
12046 block
= c_begin_compound_stmt (true);
12047 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
12048 block
= c_end_compound_stmt (loc
, block
, true);
12055 #pragma omp for for-clause[optseq] new-line
12059 #pragma omp for simd for-simd-clause[optseq] new-line
12062 LOC is the location of the #pragma token.
12065 #define OMP_FOR_CLAUSE_MASK \
12066 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12068 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12069 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12070 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12076 c_parser_omp_for (location_t loc
, c_parser
*parser
,
12077 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12079 tree block
, clauses
, ret
;
12081 strcat (p_name
, " for");
12082 mask
|= OMP_FOR_CLAUSE_MASK
;
12084 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12086 if (c_parser_next_token_is (parser
, CPP_NAME
))
12088 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12090 if (strcmp (p
, "simd") == 0)
12092 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12093 if (cclauses
== NULL
)
12094 cclauses
= cclauses_buf
;
12096 c_parser_consume_token (parser
);
12097 if (!flag_openmp
) /* flag_openmp_simd */
12098 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12099 block
= c_begin_compound_stmt (true);
12100 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12101 block
= c_end_compound_stmt (loc
, block
, true);
12102 if (ret
== NULL_TREE
)
12104 ret
= make_node (OMP_FOR
);
12105 TREE_TYPE (ret
) = void_type_node
;
12106 OMP_FOR_BODY (ret
) = block
;
12107 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12108 SET_EXPR_LOCATION (ret
, loc
);
12113 if (!flag_openmp
) /* flag_openmp_simd */
12115 c_parser_skip_to_pragma_eol (parser
);
12119 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12122 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12123 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12126 block
= c_begin_compound_stmt (true);
12127 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12128 block
= c_end_compound_stmt (loc
, block
, true);
12135 # pragma omp master new-line
12138 LOC is the location of the #pragma token.
12142 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12144 c_parser_skip_to_pragma_eol (parser
);
12145 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12149 # pragma omp ordered new-line
12152 LOC is the location of the #pragma itself.
12156 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12158 c_parser_skip_to_pragma_eol (parser
);
12159 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12165 { section-sequence }
12168 section-directive[opt] structured-block
12169 section-sequence section-directive structured-block
12171 SECTIONS_LOC is the location of the #pragma omp sections. */
12174 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12176 tree stmt
, substmt
;
12177 bool error_suppress
= false;
12180 loc
= c_parser_peek_token (parser
)->location
;
12181 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12183 /* Avoid skipping until the end of the block. */
12184 parser
->error
= false;
12188 stmt
= push_stmt_list ();
12190 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12192 substmt
= c_parser_omp_structured_block (parser
);
12193 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12194 SET_EXPR_LOCATION (substmt
, loc
);
12195 add_stmt (substmt
);
12200 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12202 if (c_parser_next_token_is (parser
, CPP_EOF
))
12205 loc
= c_parser_peek_token (parser
)->location
;
12206 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12208 c_parser_consume_pragma (parser
);
12209 c_parser_skip_to_pragma_eol (parser
);
12210 error_suppress
= false;
12212 else if (!error_suppress
)
12214 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12215 error_suppress
= true;
12218 substmt
= c_parser_omp_structured_block (parser
);
12219 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12220 SET_EXPR_LOCATION (substmt
, loc
);
12221 add_stmt (substmt
);
12223 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12224 "expected %<#pragma omp section%> or %<}%>");
12226 substmt
= pop_stmt_list (stmt
);
12228 stmt
= make_node (OMP_SECTIONS
);
12229 SET_EXPR_LOCATION (stmt
, sections_loc
);
12230 TREE_TYPE (stmt
) = void_type_node
;
12231 OMP_SECTIONS_BODY (stmt
) = substmt
;
12233 return add_stmt (stmt
);
12237 # pragma omp sections sections-clause[optseq] newline
12240 LOC is the location of the #pragma token.
12243 #define OMP_SECTIONS_CLAUSE_MASK \
12244 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12245 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12246 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12247 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12248 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12251 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12252 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12254 tree block
, clauses
, ret
;
12256 strcat (p_name
, " sections");
12257 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12259 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12261 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12264 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12265 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12268 block
= c_begin_compound_stmt (true);
12269 ret
= c_parser_omp_sections_scope (loc
, parser
);
12271 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12272 block
= c_end_compound_stmt (loc
, block
, true);
12279 # pragma omp parallel parallel-clause[optseq] new-line
12281 # pragma omp parallel for parallel-for-clause[optseq] new-line
12283 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12287 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12290 LOC is the location of the #pragma token.
12293 #define OMP_PARALLEL_CLAUSE_MASK \
12294 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12295 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12296 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12297 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12298 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12299 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12301 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12305 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12306 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12308 tree stmt
, clauses
, block
;
12310 strcat (p_name
, " parallel");
12311 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12313 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12315 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12316 if (cclauses
== NULL
)
12317 cclauses
= cclauses_buf
;
12319 c_parser_consume_token (parser
);
12320 if (!flag_openmp
) /* flag_openmp_simd */
12321 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12322 block
= c_begin_omp_parallel ();
12323 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12325 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12327 if (ret
== NULL_TREE
)
12329 OMP_PARALLEL_COMBINED (stmt
) = 1;
12334 error_at (loc
, "expected %<for%> after %qs", p_name
);
12335 c_parser_skip_to_pragma_eol (parser
);
12338 else if (!flag_openmp
) /* flag_openmp_simd */
12340 c_parser_skip_to_pragma_eol (parser
);
12343 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12345 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12346 if (strcmp (p
, "sections") == 0)
12348 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12349 if (cclauses
== NULL
)
12350 cclauses
= cclauses_buf
;
12352 c_parser_consume_token (parser
);
12353 block
= c_begin_omp_parallel ();
12354 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12355 stmt
= c_finish_omp_parallel (loc
,
12356 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12358 OMP_PARALLEL_COMBINED (stmt
) = 1;
12363 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12365 block
= c_begin_omp_parallel ();
12366 c_parser_statement (parser
);
12367 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12373 # pragma omp single single-clause[optseq] new-line
12376 LOC is the location of the #pragma.
12379 #define OMP_SINGLE_CLAUSE_MASK \
12380 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12381 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12382 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12383 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12386 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12388 tree stmt
= make_node (OMP_SINGLE
);
12389 SET_EXPR_LOCATION (stmt
, loc
);
12390 TREE_TYPE (stmt
) = void_type_node
;
12392 OMP_SINGLE_CLAUSES (stmt
)
12393 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12394 "#pragma omp single");
12395 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12397 return add_stmt (stmt
);
12401 # pragma omp task task-clause[optseq] new-line
12403 LOC is the location of the #pragma.
12406 #define OMP_TASK_CLAUSE_MASK \
12407 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12408 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12409 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12410 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12411 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12412 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12413 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12414 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12415 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12418 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12420 tree clauses
, block
;
12422 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12423 "#pragma omp task");
12425 block
= c_begin_omp_task ();
12426 c_parser_statement (parser
);
12427 return c_finish_omp_task (loc
, clauses
, block
);
12431 # pragma omp taskwait new-line
12435 c_parser_omp_taskwait (c_parser
*parser
)
12437 location_t loc
= c_parser_peek_token (parser
)->location
;
12438 c_parser_consume_pragma (parser
);
12439 c_parser_skip_to_pragma_eol (parser
);
12441 c_finish_omp_taskwait (loc
);
12445 # pragma omp taskyield new-line
12449 c_parser_omp_taskyield (c_parser
*parser
)
12451 location_t loc
= c_parser_peek_token (parser
)->location
;
12452 c_parser_consume_pragma (parser
);
12453 c_parser_skip_to_pragma_eol (parser
);
12455 c_finish_omp_taskyield (loc
);
12459 # pragma omp taskgroup new-line
12463 c_parser_omp_taskgroup (c_parser
*parser
)
12465 location_t loc
= c_parser_peek_token (parser
)->location
;
12466 c_parser_skip_to_pragma_eol (parser
);
12467 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12471 # pragma omp cancel cancel-clause[optseq] new-line
12473 LOC is the location of the #pragma.
12476 #define OMP_CANCEL_CLAUSE_MASK \
12477 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12478 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12479 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12480 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12481 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12484 c_parser_omp_cancel (c_parser
*parser
)
12486 location_t loc
= c_parser_peek_token (parser
)->location
;
12488 c_parser_consume_pragma (parser
);
12489 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12490 "#pragma omp cancel");
12492 c_finish_omp_cancel (loc
, clauses
);
12496 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12498 LOC is the location of the #pragma.
12501 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12502 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12503 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12504 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12505 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12508 c_parser_omp_cancellation_point (c_parser
*parser
)
12510 location_t loc
= c_parser_peek_token (parser
)->location
;
12512 bool point_seen
= false;
12514 c_parser_consume_pragma (parser
);
12515 if (c_parser_next_token_is (parser
, CPP_NAME
))
12517 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12518 if (strcmp (p
, "point") == 0)
12520 c_parser_consume_token (parser
);
12526 c_parser_error (parser
, "expected %<point%>");
12527 c_parser_skip_to_pragma_eol (parser
);
12532 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12533 "#pragma omp cancellation point");
12535 c_finish_omp_cancellation_point (loc
, clauses
);
12539 #pragma omp distribute distribute-clause[optseq] new-line
12542 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12543 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12545 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12546 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12549 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12550 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12552 tree clauses
, block
, ret
;
12554 strcat (p_name
, " distribute");
12555 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12557 if (c_parser_next_token_is (parser
, CPP_NAME
))
12559 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12561 bool parallel
= false;
12563 if (strcmp (p
, "simd") == 0)
12566 parallel
= strcmp (p
, "parallel") == 0;
12567 if (parallel
|| simd
)
12569 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12570 if (cclauses
== NULL
)
12571 cclauses
= cclauses_buf
;
12572 c_parser_consume_token (parser
);
12573 if (!flag_openmp
) /* flag_openmp_simd */
12576 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12578 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12581 block
= c_begin_compound_stmt (true);
12583 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12585 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12586 block
= c_end_compound_stmt (loc
, block
, true);
12589 ret
= make_node (OMP_DISTRIBUTE
);
12590 TREE_TYPE (ret
) = void_type_node
;
12591 OMP_FOR_BODY (ret
) = block
;
12592 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12593 SET_EXPR_LOCATION (ret
, loc
);
12598 if (!flag_openmp
) /* flag_openmp_simd */
12600 c_parser_skip_to_pragma_eol (parser
);
12604 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12607 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12608 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12611 block
= c_begin_compound_stmt (true);
12612 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12613 block
= c_end_compound_stmt (loc
, block
, true);
12620 # pragma omp teams teams-clause[optseq] new-line
12621 structured-block */
12623 #define OMP_TEAMS_CLAUSE_MASK \
12624 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12625 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12626 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12627 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12628 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12629 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12630 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12633 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12634 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12636 tree clauses
, block
, ret
;
12638 strcat (p_name
, " teams");
12639 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12641 if (c_parser_next_token_is (parser
, CPP_NAME
))
12643 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12644 if (strcmp (p
, "distribute") == 0)
12646 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12647 if (cclauses
== NULL
)
12648 cclauses
= cclauses_buf
;
12650 c_parser_consume_token (parser
);
12651 if (!flag_openmp
) /* flag_openmp_simd */
12652 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12653 block
= c_begin_compound_stmt (true);
12654 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12655 block
= c_end_compound_stmt (loc
, block
, true);
12658 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12659 ret
= make_node (OMP_TEAMS
);
12660 TREE_TYPE (ret
) = void_type_node
;
12661 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12662 OMP_TEAMS_BODY (ret
) = block
;
12663 return add_stmt (ret
);
12666 if (!flag_openmp
) /* flag_openmp_simd */
12668 c_parser_skip_to_pragma_eol (parser
);
12672 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12675 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12676 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12679 tree stmt
= make_node (OMP_TEAMS
);
12680 TREE_TYPE (stmt
) = void_type_node
;
12681 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12682 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12684 return add_stmt (stmt
);
12688 # pragma omp target data target-data-clause[optseq] new-line
12689 structured-block */
12691 #define OMP_TARGET_DATA_CLAUSE_MASK \
12692 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12693 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12694 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12697 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12699 tree stmt
= make_node (OMP_TARGET_DATA
);
12700 TREE_TYPE (stmt
) = void_type_node
;
12702 OMP_TARGET_DATA_CLAUSES (stmt
)
12703 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12704 "#pragma omp target data");
12705 keep_next_level ();
12706 tree block
= c_begin_compound_stmt (true);
12707 add_stmt (c_parser_omp_structured_block (parser
));
12708 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12710 SET_EXPR_LOCATION (stmt
, loc
);
12711 return add_stmt (stmt
);
12715 # pragma omp target update target-update-clause[optseq] new-line */
12717 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12718 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12719 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12720 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12721 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12724 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12725 enum pragma_context context
)
12727 if (context
== pragma_stmt
)
12730 "%<#pragma omp target update%> may only be "
12731 "used in compound statements");
12732 c_parser_skip_to_pragma_eol (parser
);
12737 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12738 "#pragma omp target update");
12739 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12740 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12743 "%<#pragma omp target update must contain at least one "
12744 "%<from%> or %<to%> clauses");
12748 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12749 TREE_TYPE (stmt
) = void_type_node
;
12750 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12751 SET_EXPR_LOCATION (stmt
, loc
);
12757 # pragma omp target target-clause[optseq] new-line
12758 structured-block */
12760 #define OMP_TARGET_CLAUSE_MASK \
12761 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12762 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12766 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12768 location_t loc
= c_parser_peek_token (parser
)->location
;
12769 c_parser_consume_pragma (parser
);
12771 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12773 c_parser_error (parser
, "expected declaration specifiers");
12774 c_parser_skip_to_pragma_eol (parser
);
12778 if (c_parser_next_token_is (parser
, CPP_NAME
))
12780 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12782 if (strcmp (p
, "teams") == 0)
12784 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12785 char p_name
[sizeof ("#pragma omp target teams distribute "
12786 "parallel for simd")];
12788 c_parser_consume_token (parser
);
12789 strcpy (p_name
, "#pragma omp target");
12790 if (!flag_openmp
) /* flag_openmp_simd */
12792 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
12793 OMP_TARGET_CLAUSE_MASK
,
12795 return stmt
!= NULL_TREE
;
12797 keep_next_level ();
12798 tree block
= c_begin_compound_stmt (true);
12799 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12800 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12801 block
= c_end_compound_stmt (loc
, block
, true);
12802 if (ret
== NULL_TREE
)
12804 tree stmt
= make_node (OMP_TARGET
);
12805 TREE_TYPE (stmt
) = void_type_node
;
12806 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12807 OMP_TARGET_BODY (stmt
) = block
;
12811 else if (!flag_openmp
) /* flag_openmp_simd */
12813 c_parser_skip_to_pragma_eol (parser
);
12816 else if (strcmp (p
, "data") == 0)
12818 c_parser_consume_token (parser
);
12819 c_parser_omp_target_data (loc
, parser
);
12822 else if (strcmp (p
, "update") == 0)
12824 c_parser_consume_token (parser
);
12825 return c_parser_omp_target_update (loc
, parser
, context
);
12829 tree stmt
= make_node (OMP_TARGET
);
12830 TREE_TYPE (stmt
) = void_type_node
;
12832 OMP_TARGET_CLAUSES (stmt
)
12833 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12834 "#pragma omp target");
12835 keep_next_level ();
12836 tree block
= c_begin_compound_stmt (true);
12837 add_stmt (c_parser_omp_structured_block (parser
));
12838 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12840 SET_EXPR_LOCATION (stmt
, loc
);
12846 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12848 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12849 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12850 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12851 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12852 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12853 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12854 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12857 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12859 vec
<c_token
> clauses
= vNULL
;
12860 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12862 c_token
*token
= c_parser_peek_token (parser
);
12863 if (token
->type
== CPP_EOF
)
12865 c_parser_skip_to_pragma_eol (parser
);
12866 clauses
.release ();
12869 clauses
.safe_push (*token
);
12870 c_parser_consume_token (parser
);
12872 clauses
.safe_push (*c_parser_peek_token (parser
));
12873 c_parser_skip_to_pragma_eol (parser
);
12875 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12877 if (c_parser_peek_token (parser
)->pragma_kind
12878 != PRAGMA_OMP_DECLARE_REDUCTION
12879 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12880 || strcmp (IDENTIFIER_POINTER
12881 (c_parser_peek_2nd_token (parser
)->value
),
12884 c_parser_error (parser
,
12885 "%<#pragma omp declare simd%> must be followed by "
12886 "function declaration or definition or another "
12887 "%<#pragma omp declare simd%>");
12888 clauses
.release ();
12891 c_parser_consume_pragma (parser
);
12892 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12894 c_token
*token
= c_parser_peek_token (parser
);
12895 if (token
->type
== CPP_EOF
)
12897 c_parser_skip_to_pragma_eol (parser
);
12898 clauses
.release ();
12901 clauses
.safe_push (*token
);
12902 c_parser_consume_token (parser
);
12904 clauses
.safe_push (*c_parser_peek_token (parser
));
12905 c_parser_skip_to_pragma_eol (parser
);
12908 /* Make sure nothing tries to read past the end of the tokens. */
12910 memset (&eof_token
, 0, sizeof (eof_token
));
12911 eof_token
.type
= CPP_EOF
;
12912 clauses
.safe_push (eof_token
);
12913 clauses
.safe_push (eof_token
);
12917 case pragma_external
:
12918 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12919 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12921 int ext
= disable_extension_diagnostics ();
12923 c_parser_consume_token (parser
);
12924 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12925 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12926 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12928 restore_extension_diagnostics (ext
);
12931 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12934 case pragma_struct
:
12936 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12937 "function declaration or definition");
12939 case pragma_compound
:
12941 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12942 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12944 int ext
= disable_extension_diagnostics ();
12946 c_parser_consume_token (parser
);
12947 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12948 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12949 if (c_parser_next_tokens_start_declaration (parser
))
12951 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12952 true, NULL
, clauses
);
12953 restore_extension_diagnostics (ext
);
12956 restore_extension_diagnostics (ext
);
12958 else if (c_parser_next_tokens_start_declaration (parser
))
12960 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12964 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12965 "function declaration or definition");
12968 gcc_unreachable ();
12970 clauses
.release ();
12973 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12974 and put that into "omp declare simd" attribute. */
12977 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12978 vec
<c_token
> clauses
)
12981 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12983 error ("%<#pragma omp declare simd%> cannot be used in the same "
12984 "function marked as a Cilk Plus SIMD-enabled function");
12985 vec_free (parser
->cilk_simd_fn_tokens
);
12989 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12990 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12991 has already processed the tokens. */
12992 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
12994 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12996 error ("%<#pragma omp declare simd%> not immediately followed by "
12997 "a function declaration or definition");
12998 clauses
[0].type
= CPP_EOF
;
13001 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
13003 error_at (DECL_SOURCE_LOCATION (fndecl
),
13004 "%<#pragma omp declare simd%> not immediately followed by "
13005 "a single function declaration or definition");
13006 clauses
[0].type
= CPP_EOF
;
13010 if (parms
== NULL_TREE
)
13011 parms
= DECL_ARGUMENTS (fndecl
);
13013 unsigned int tokens_avail
= parser
->tokens_avail
;
13014 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13015 bool is_cilkplus_cilk_simd_fn
= false;
13017 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13019 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
13020 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
13021 is_cilkplus_cilk_simd_fn
= true;
13025 parser
->tokens
= clauses
.address ();
13026 parser
->tokens_avail
= clauses
.length ();
13029 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
13030 while (parser
->tokens_avail
> 3)
13032 c_token
*token
= c_parser_peek_token (parser
);
13033 if (!is_cilkplus_cilk_simd_fn
)
13034 gcc_assert (token
->type
== CPP_NAME
13035 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
13037 gcc_assert (token
->type
== CPP_NAME
13038 && is_cilkplus_vector_p (token
->value
));
13039 c_parser_consume_token (parser
);
13040 parser
->in_pragma
= true;
13042 tree c
= NULL_TREE
;
13043 if (is_cilkplus_cilk_simd_fn
)
13044 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
13045 "SIMD-enabled functions attribute");
13047 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
13048 "#pragma omp declare simd");
13049 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
13050 if (c
!= NULL_TREE
)
13051 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
13052 if (is_cilkplus_cilk_simd_fn
)
13054 tree k
= build_tree_list (get_identifier ("cilk simd function"),
13056 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
13057 DECL_ATTRIBUTES (fndecl
) = k
;
13059 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
13060 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
13061 DECL_ATTRIBUTES (fndecl
) = c
;
13064 parser
->tokens
= &parser
->tokens_buf
[0];
13065 parser
->tokens_avail
= tokens_avail
;
13066 if (clauses
.exists ())
13067 clauses
[0].type
= CPP_PRAGMA
;
13069 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13070 vec_free (parser
->cilk_simd_fn_tokens
);
13075 # pragma omp declare target new-line
13076 declarations and definitions
13077 # pragma omp end declare target new-line */
13080 c_parser_omp_declare_target (c_parser
*parser
)
13082 c_parser_skip_to_pragma_eol (parser
);
13083 current_omp_declare_target_attribute
++;
13087 c_parser_omp_end_declare_target (c_parser
*parser
)
13089 location_t loc
= c_parser_peek_token (parser
)->location
;
13090 c_parser_consume_pragma (parser
);
13091 if (c_parser_next_token_is (parser
, CPP_NAME
)
13092 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13095 c_parser_consume_token (parser
);
13096 if (c_parser_next_token_is (parser
, CPP_NAME
)
13097 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13099 c_parser_consume_token (parser
);
13102 c_parser_error (parser
, "expected %<target%>");
13103 c_parser_skip_to_pragma_eol (parser
);
13109 c_parser_error (parser
, "expected %<declare%>");
13110 c_parser_skip_to_pragma_eol (parser
);
13113 c_parser_skip_to_pragma_eol (parser
);
13114 if (!current_omp_declare_target_attribute
)
13115 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13116 "%<#pragma omp declare target%>");
13118 current_omp_declare_target_attribute
--;
13123 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13124 initializer-clause[opt] new-line
13126 initializer-clause:
13127 initializer (omp_priv = initializer)
13128 initializer (function-name (argument-list)) */
13131 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13133 unsigned int tokens_avail
= 0, i
;
13134 vec
<tree
> types
= vNULL
;
13135 vec
<c_token
> clauses
= vNULL
;
13136 enum tree_code reduc_code
= ERROR_MARK
;
13137 tree reduc_id
= NULL_TREE
;
13139 location_t rloc
= c_parser_peek_token (parser
)->location
;
13141 if (context
== pragma_struct
|| context
== pragma_param
)
13143 error ("%<#pragma omp declare reduction%> not at file or block scope");
13147 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13150 switch (c_parser_peek_token (parser
)->type
)
13153 reduc_code
= PLUS_EXPR
;
13156 reduc_code
= MULT_EXPR
;
13159 reduc_code
= MINUS_EXPR
;
13162 reduc_code
= BIT_AND_EXPR
;
13165 reduc_code
= BIT_XOR_EXPR
;
13168 reduc_code
= BIT_IOR_EXPR
;
13171 reduc_code
= TRUTH_ANDIF_EXPR
;
13174 reduc_code
= TRUTH_ORIF_EXPR
;
13178 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13179 if (strcmp (p
, "min") == 0)
13181 reduc_code
= MIN_EXPR
;
13184 if (strcmp (p
, "max") == 0)
13186 reduc_code
= MAX_EXPR
;
13189 reduc_id
= c_parser_peek_token (parser
)->value
;
13192 c_parser_error (parser
,
13193 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13194 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13198 tree orig_reduc_id
, reduc_decl
;
13199 orig_reduc_id
= reduc_id
;
13200 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13201 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13202 c_parser_consume_token (parser
);
13204 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13209 location_t loc
= c_parser_peek_token (parser
)->location
;
13210 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13213 type
= groktypename (ctype
, NULL
, NULL
);
13214 if (type
== error_mark_node
)
13216 else if ((INTEGRAL_TYPE_P (type
)
13217 || TREE_CODE (type
) == REAL_TYPE
13218 || TREE_CODE (type
) == COMPLEX_TYPE
)
13219 && orig_reduc_id
== NULL_TREE
)
13220 error_at (loc
, "predeclared arithmetic type in "
13221 "%<#pragma omp declare reduction%>");
13222 else if (TREE_CODE (type
) == FUNCTION_TYPE
13223 || TREE_CODE (type
) == ARRAY_TYPE
)
13224 error_at (loc
, "function or array type in "
13225 "%<#pragma omp declare reduction%>");
13226 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13227 error_at (loc
, "const, volatile or restrict qualified type in "
13228 "%<#pragma omp declare reduction%>");
13232 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13233 if (comptypes (TREE_PURPOSE (t
), type
))
13235 error_at (loc
, "redeclaration of %qs "
13236 "%<#pragma omp declare reduction%> for "
13238 IDENTIFIER_POINTER (reduc_id
)
13239 + sizeof ("omp declare reduction ") - 1,
13242 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13244 error_at (ploc
, "previous %<#pragma omp declare "
13248 if (t
== NULL_TREE
)
13249 types
.safe_push (type
);
13251 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13252 c_parser_consume_token (parser
);
13260 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13261 || types
.is_empty ())
13264 clauses
.release ();
13268 c_token
*token
= c_parser_peek_token (parser
);
13269 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13271 c_parser_consume_token (parser
);
13273 c_parser_skip_to_pragma_eol (parser
);
13277 if (types
.length () > 1)
13279 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13281 c_token
*token
= c_parser_peek_token (parser
);
13282 if (token
->type
== CPP_EOF
)
13284 clauses
.safe_push (*token
);
13285 c_parser_consume_token (parser
);
13287 clauses
.safe_push (*c_parser_peek_token (parser
));
13288 c_parser_skip_to_pragma_eol (parser
);
13290 /* Make sure nothing tries to read past the end of the tokens. */
13292 memset (&eof_token
, 0, sizeof (eof_token
));
13293 eof_token
.type
= CPP_EOF
;
13294 clauses
.safe_push (eof_token
);
13295 clauses
.safe_push (eof_token
);
13298 int errs
= errorcount
;
13299 FOR_EACH_VEC_ELT (types
, i
, type
)
13301 tokens_avail
= parser
->tokens_avail
;
13302 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13303 if (!clauses
.is_empty ())
13305 parser
->tokens
= clauses
.address ();
13306 parser
->tokens_avail
= clauses
.length ();
13307 parser
->in_pragma
= true;
13310 bool nested
= current_function_decl
!= NULL_TREE
;
13312 c_push_function_context ();
13313 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13314 reduc_id
, default_function_type
);
13315 current_function_decl
= fndecl
;
13316 allocate_struct_function (fndecl
, true);
13318 tree stmt
= push_stmt_list ();
13319 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13320 warn about these. */
13321 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13322 get_identifier ("omp_out"), type
);
13323 DECL_ARTIFICIAL (omp_out
) = 1;
13324 DECL_CONTEXT (omp_out
) = fndecl
;
13325 pushdecl (omp_out
);
13326 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13327 get_identifier ("omp_in"), type
);
13328 DECL_ARTIFICIAL (omp_in
) = 1;
13329 DECL_CONTEXT (omp_in
) = fndecl
;
13331 struct c_expr combiner
= c_parser_expression (parser
);
13332 struct c_expr initializer
;
13333 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13335 initializer
.value
= error_mark_node
;
13336 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13338 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13339 && strcmp (IDENTIFIER_POINTER
13340 (c_parser_peek_token (parser
)->value
),
13341 "initializer") == 0)
13343 c_parser_consume_token (parser
);
13346 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13347 get_identifier ("omp_priv"), type
);
13348 DECL_ARTIFICIAL (omp_priv
) = 1;
13349 DECL_INITIAL (omp_priv
) = error_mark_node
;
13350 DECL_CONTEXT (omp_priv
) = fndecl
;
13351 pushdecl (omp_priv
);
13352 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13353 get_identifier ("omp_orig"), type
);
13354 DECL_ARTIFICIAL (omp_orig
) = 1;
13355 DECL_CONTEXT (omp_orig
) = fndecl
;
13356 pushdecl (omp_orig
);
13357 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13359 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13361 c_parser_error (parser
, "expected %<omp_priv%> or "
13365 else if (strcmp (IDENTIFIER_POINTER
13366 (c_parser_peek_token (parser
)->value
),
13369 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13370 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13372 c_parser_error (parser
, "expected function-name %<(%>");
13376 initializer
= c_parser_postfix_expression (parser
);
13377 if (initializer
.value
13378 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13381 tree c
= initializer
.value
;
13382 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13383 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13384 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13386 if (j
== call_expr_nargs (c
))
13387 error ("one of the initializer call arguments should be "
13393 c_parser_consume_token (parser
);
13394 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13398 tree st
= push_stmt_list ();
13399 start_init (omp_priv
, NULL_TREE
, 0);
13400 location_t loc
= c_parser_peek_token (parser
)->location
;
13401 struct c_expr init
= c_parser_initializer (parser
);
13403 finish_decl (omp_priv
, loc
, init
.value
,
13404 init
.original_type
, NULL_TREE
);
13405 pop_stmt_list (st
);
13409 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13415 c_parser_skip_to_pragma_eol (parser
);
13417 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13418 DECL_INITIAL (reduc_decl
));
13419 DECL_INITIAL (reduc_decl
) = t
;
13420 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13421 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13422 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13423 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13424 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13425 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13428 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13429 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13430 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13431 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13432 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13433 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13434 walk_tree (&DECL_INITIAL (omp_priv
),
13435 c_check_omp_declare_reduction_r
,
13436 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13440 pop_stmt_list (stmt
);
13442 if (cfun
->language
!= NULL
)
13444 ggc_free (cfun
->language
);
13445 cfun
->language
= NULL
;
13448 current_function_decl
= NULL_TREE
;
13450 c_pop_function_context ();
13452 if (!clauses
.is_empty ())
13454 parser
->tokens
= &parser
->tokens_buf
[0];
13455 parser
->tokens_avail
= tokens_avail
;
13459 if (errs
!= errorcount
)
13463 clauses
.release ();
13469 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13470 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13471 initializer-clause[opt] new-line
13472 #pragma omp declare target new-line */
13475 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13477 c_parser_consume_pragma (parser
);
13478 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
, "simd") == 0)
13483 /* c_parser_consume_token (parser); done in
13484 c_parser_omp_declare_simd. */
13485 c_parser_omp_declare_simd (parser
, context
);
13488 if (strcmp (p
, "reduction") == 0)
13490 c_parser_consume_token (parser
);
13491 c_parser_omp_declare_reduction (parser
, context
);
13494 if (!flag_openmp
) /* flag_openmp_simd */
13496 c_parser_skip_to_pragma_eol (parser
);
13499 if (strcmp (p
, "target") == 0)
13501 c_parser_consume_token (parser
);
13502 c_parser_omp_declare_target (parser
);
13507 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13509 c_parser_skip_to_pragma_eol (parser
);
13512 /* Main entry point to parsing most OpenMP pragmas. */
13515 c_parser_omp_construct (c_parser
*parser
)
13517 enum pragma_kind p_kind
;
13520 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13521 omp_clause_mask
mask (0);
13523 loc
= c_parser_peek_token (parser
)->location
;
13524 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13525 c_parser_consume_pragma (parser
);
13529 case PRAGMA_OMP_ATOMIC
:
13530 c_parser_omp_atomic (loc
, parser
);
13532 case PRAGMA_OMP_CRITICAL
:
13533 stmt
= c_parser_omp_critical (loc
, parser
);
13535 case PRAGMA_OMP_DISTRIBUTE
:
13536 strcpy (p_name
, "#pragma omp");
13537 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13539 case PRAGMA_OMP_FOR
:
13540 strcpy (p_name
, "#pragma omp");
13541 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13543 case PRAGMA_OMP_MASTER
:
13544 stmt
= c_parser_omp_master (loc
, parser
);
13546 case PRAGMA_OMP_ORDERED
:
13547 stmt
= c_parser_omp_ordered (loc
, parser
);
13549 case PRAGMA_OMP_PARALLEL
:
13550 strcpy (p_name
, "#pragma omp");
13551 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13553 case PRAGMA_OMP_SECTIONS
:
13554 strcpy (p_name
, "#pragma omp");
13555 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13557 case PRAGMA_OMP_SIMD
:
13558 strcpy (p_name
, "#pragma omp");
13559 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13561 case PRAGMA_OMP_SINGLE
:
13562 stmt
= c_parser_omp_single (loc
, parser
);
13564 case PRAGMA_OMP_TASK
:
13565 stmt
= c_parser_omp_task (loc
, parser
);
13567 case PRAGMA_OMP_TASKGROUP
:
13568 stmt
= c_parser_omp_taskgroup (parser
);
13570 case PRAGMA_OMP_TEAMS
:
13571 strcpy (p_name
, "#pragma omp");
13572 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13575 gcc_unreachable ();
13579 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13584 # pragma omp threadprivate (variable-list) */
13587 c_parser_omp_threadprivate (c_parser
*parser
)
13592 c_parser_consume_pragma (parser
);
13593 loc
= c_parser_peek_token (parser
)->location
;
13594 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13596 /* Mark every variable in VARS to be assigned thread local storage. */
13597 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13599 tree v
= TREE_PURPOSE (t
);
13601 /* FIXME diagnostics: Ideally we should keep individual
13602 locations for all the variables in the var list to make the
13603 following errors more precise. Perhaps
13604 c_parser_omp_var_list_parens() should construct a list of
13605 locations to go along with the var list. */
13607 /* If V had already been marked threadprivate, it doesn't matter
13608 whether it had been used prior to this point. */
13609 if (TREE_CODE (v
) != VAR_DECL
)
13610 error_at (loc
, "%qD is not a variable", v
);
13611 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13612 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13613 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13614 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13615 else if (TREE_TYPE (v
) == error_mark_node
)
13617 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13618 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13621 if (! DECL_THREAD_LOCAL_P (v
))
13623 set_decl_tls_model (v
, decl_default_tls_model (v
));
13624 /* If rtl has been already set for this var, call
13625 make_decl_rtl once again, so that encode_section_info
13626 has a chance to look at the new decl flags. */
13627 if (DECL_RTL_SET_P (v
))
13630 C_DECL_THREADPRIVATE_P (v
) = 1;
13634 c_parser_skip_to_pragma_eol (parser
);
13637 /* Cilk Plus <#pragma simd> parsing routines. */
13639 /* Helper function for c_parser_pragma. Perform some sanity checking
13640 for <#pragma simd> constructs. Returns FALSE if there was a
13644 c_parser_cilk_verify_simd (c_parser
*parser
,
13645 enum pragma_context context
)
13647 if (!flag_cilkplus
)
13649 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13650 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13653 if (context
== pragma_external
)
13655 c_parser_error (parser
,"pragma simd must be inside a function");
13656 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13663 This function is shared by SIMD-enabled functions and #pragma simd.
13664 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
13665 CLAUSES is unused. The main purpose of this function is to parse a
13666 vectorlength attribute or clause and check for parse errors.
13667 When IS_SIMD_FN is true then the function is merely caching the tokens
13668 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
13669 cache is cleared since there is no reason to continue.
13671 vectorlength ( constant-expression ) */
13674 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
13678 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
13680 /* The vectorlength clause behaves exactly like OpenMP's safelen
13681 clause. Represent it in OpenMP terms. */
13682 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13684 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13687 location_t loc
= c_parser_peek_token (parser
)->location
;
13688 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13689 expr
= c_fully_fold (expr
, false, NULL
);
13691 /* If expr is an error_mark_node then the above function would have
13692 emitted an error. No reason to do it twice. */
13693 if (expr
== error_mark_node
)
13695 else if (!TREE_TYPE (expr
)
13696 || !TREE_CONSTANT (expr
)
13697 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13699 error_at (loc
, "vectorlength must be an integer constant");
13700 else if (wi::exact_log2 (expr
) == -1)
13701 error_at (loc
, "vectorlength must be a power of 2");
13706 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
13707 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
13708 OMP_CLAUSE_CHAIN (u
) = clauses
;
13713 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13714 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13715 OMP_CLAUSE_CHAIN (u
) = clauses
;
13720 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13726 linear ( simd-linear-variable-list )
13728 simd-linear-variable-list:
13729 simd-linear-variable
13730 simd-linear-variable-list , simd-linear-variable
13732 simd-linear-variable:
13734 id-expression : simd-linear-step
13737 conditional-expression */
13740 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13742 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13745 location_t loc
= c_parser_peek_token (parser
)->location
;
13747 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13748 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13749 c_parser_error (parser
, "expected identifier");
13751 while (c_parser_next_token_is (parser
, CPP_NAME
)
13752 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13754 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13758 undeclared_variable (c_parser_peek_token (parser
)->location
,
13759 c_parser_peek_token (parser
)->value
);
13760 c_parser_consume_token (parser
);
13762 else if (var
== error_mark_node
)
13763 c_parser_consume_token (parser
);
13766 tree step
= integer_one_node
;
13768 /* Parse the linear step if present. */
13769 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13771 c_parser_consume_token (parser
);
13772 c_parser_consume_token (parser
);
13774 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13775 expr
= c_fully_fold (expr
, false, NULL
);
13777 if (TREE_TYPE (expr
)
13778 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13779 && (TREE_CONSTANT (expr
)
13783 c_parser_error (parser
,
13784 "step size must be an integer constant "
13785 "expression or an integer variable");
13788 c_parser_consume_token (parser
);
13790 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13791 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13792 OMP_CLAUSE_DECL (u
) = var
;
13793 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13794 OMP_CLAUSE_CHAIN (u
) = clauses
;
13798 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13801 c_parser_consume_token (parser
);
13804 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13809 /* Returns the name of the next clause. If the clause is not
13810 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13811 not consumed. Otherwise, the appropriate pragma_simd_clause is
13812 returned and the token is consumed. */
13814 static pragma_omp_clause
13815 c_parser_cilk_clause_name (c_parser
*parser
)
13817 pragma_omp_clause result
;
13818 c_token
*token
= c_parser_peek_token (parser
);
13820 if (!token
->value
|| token
->type
!= CPP_NAME
)
13821 return PRAGMA_CILK_CLAUSE_NONE
;
13823 const char *p
= IDENTIFIER_POINTER (token
->value
);
13825 if (!strcmp (p
, "vectorlength"))
13826 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13827 else if (!strcmp (p
, "linear"))
13828 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13829 else if (!strcmp (p
, "private"))
13830 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13831 else if (!strcmp (p
, "firstprivate"))
13832 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13833 else if (!strcmp (p
, "lastprivate"))
13834 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13835 else if (!strcmp (p
, "reduction"))
13836 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13838 return PRAGMA_CILK_CLAUSE_NONE
;
13840 c_parser_consume_token (parser
);
13844 /* Parse all #<pragma simd> clauses. Return the list of clauses
13848 c_parser_cilk_all_clauses (c_parser
*parser
)
13850 tree clauses
= NULL
;
13852 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13854 pragma_omp_clause c_kind
;
13856 c_kind
= c_parser_cilk_clause_name (parser
);
13860 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13861 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
13863 case PRAGMA_CILK_CLAUSE_LINEAR
:
13864 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13866 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13867 /* Use the OpenMP counterpart. */
13868 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13870 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13871 /* Use the OpenMP counterpart. */
13872 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13874 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13875 /* Use the OpenMP counterpart. */
13876 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13878 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13879 /* Use the OpenMP counterpart. */
13880 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13883 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13889 c_parser_skip_to_pragma_eol (parser
);
13890 return c_finish_cilk_clauses (clauses
);
13893 /* Main entry point for parsing Cilk Plus <#pragma simd> for
13897 c_parser_cilk_simd (c_parser
*parser
)
13899 tree clauses
= c_parser_cilk_all_clauses (parser
);
13900 tree block
= c_begin_compound_stmt (true);
13901 location_t loc
= c_parser_peek_token (parser
)->location
;
13902 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
13903 block
= c_end_compound_stmt (loc
, block
, true);
13907 /* Parse a transaction attribute (GCC Extension).
13909 transaction-attribute:
13913 The transactional memory language description is written for C++,
13914 and uses the C++0x attribute syntax. For compatibility, allow the
13915 bracket style for transactions in C as well. */
13918 c_parser_transaction_attributes (c_parser
*parser
)
13920 tree attr_name
, attr
= NULL
;
13922 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13923 return c_parser_attributes (parser
);
13925 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13927 c_parser_consume_token (parser
);
13928 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13931 attr_name
= c_parser_attribute_any_word (parser
);
13934 c_parser_consume_token (parser
);
13935 attr
= build_tree_list (attr_name
, NULL_TREE
);
13938 c_parser_error (parser
, "expected identifier");
13940 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13942 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13946 /* Parse a __transaction_atomic or __transaction_relaxed statement
13949 transaction-statement:
13950 __transaction_atomic transaction-attribute[opt] compound-statement
13951 __transaction_relaxed compound-statement
13953 Note that the only valid attribute is: "outer".
13957 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13959 unsigned int old_in
= parser
->in_transaction
;
13960 unsigned int this_in
= 1, new_in
;
13961 location_t loc
= c_parser_peek_token (parser
)->location
;
13964 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13965 || keyword
== RID_TRANSACTION_RELAXED
)
13966 && c_parser_next_token_is_keyword (parser
, keyword
));
13967 c_parser_consume_token (parser
);
13969 if (keyword
== RID_TRANSACTION_RELAXED
)
13970 this_in
|= TM_STMT_ATTR_RELAXED
;
13973 attrs
= c_parser_transaction_attributes (parser
);
13975 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13978 /* Keep track if we're in the lexical scope of an outer transaction. */
13979 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13981 parser
->in_transaction
= new_in
;
13982 stmt
= c_parser_compound_statement (parser
);
13983 parser
->in_transaction
= old_in
;
13986 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13988 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13989 "%<__transaction_atomic%> without transactional memory support enabled"
13990 : "%<__transaction_relaxed %> "
13991 "without transactional memory support enabled"));
13996 /* Parse a __transaction_atomic or __transaction_relaxed expression
13999 transaction-expression:
14000 __transaction_atomic ( expression )
14001 __transaction_relaxed ( expression )
14004 static struct c_expr
14005 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
14008 unsigned int old_in
= parser
->in_transaction
;
14009 unsigned int this_in
= 1;
14010 location_t loc
= c_parser_peek_token (parser
)->location
;
14013 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
14014 || keyword
== RID_TRANSACTION_RELAXED
)
14015 && c_parser_next_token_is_keyword (parser
, keyword
));
14016 c_parser_consume_token (parser
);
14018 if (keyword
== RID_TRANSACTION_RELAXED
)
14019 this_in
|= TM_STMT_ATTR_RELAXED
;
14022 attrs
= c_parser_transaction_attributes (parser
);
14024 this_in
|= parse_tm_stmt_attr (attrs
, 0);
14027 parser
->in_transaction
= this_in
;
14028 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14030 tree expr
= c_parser_expression (parser
).value
;
14031 ret
.original_type
= TREE_TYPE (expr
);
14032 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
14033 if (this_in
& TM_STMT_ATTR_RELAXED
)
14034 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
14035 SET_EXPR_LOCATION (ret
.value
, loc
);
14036 ret
.original_code
= TRANSACTION_EXPR
;
14037 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14039 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
14046 ret
.value
= error_mark_node
;
14047 ret
.original_code
= ERROR_MARK
;
14048 ret
.original_type
= NULL
;
14050 parser
->in_transaction
= old_in
;
14053 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
14054 "%<__transaction_atomic%> without transactional memory support enabled"
14055 : "%<__transaction_relaxed %> "
14056 "without transactional memory support enabled"));
14061 /* Parse a __transaction_cancel statement (GCC Extension).
14063 transaction-cancel-statement:
14064 __transaction_cancel transaction-attribute[opt] ;
14066 Note that the only valid attribute is "outer".
14070 c_parser_transaction_cancel (c_parser
*parser
)
14072 location_t loc
= c_parser_peek_token (parser
)->location
;
14074 bool is_outer
= false;
14076 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
14077 c_parser_consume_token (parser
);
14079 attrs
= c_parser_transaction_attributes (parser
);
14081 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
14085 error_at (loc
, "%<__transaction_cancel%> without "
14086 "transactional memory support enabled");
14089 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
14091 error_at (loc
, "%<__transaction_cancel%> within a "
14092 "%<__transaction_relaxed%>");
14097 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
14098 && !is_tm_may_cancel_outer (current_function_decl
))
14100 error_at (loc
, "outer %<__transaction_cancel%> not "
14101 "within outer %<__transaction_atomic%>");
14102 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
14106 else if (parser
->in_transaction
== 0)
14108 error_at (loc
, "%<__transaction_cancel%> not within "
14109 "%<__transaction_atomic%>");
14113 return add_stmt (build_tm_abort_call (loc
, is_outer
));
14116 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
14119 /* Parse a single source file. */
14122 c_parse_file (void)
14124 /* Use local storage to begin. If the first token is a pragma, parse it.
14125 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14126 which will cause garbage collection. */
14129 memset (&tparser
, 0, sizeof tparser
);
14130 tparser
.tokens
= &tparser
.tokens_buf
[0];
14131 the_parser
= &tparser
;
14133 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
14134 c_parser_pragma_pch_preprocess (&tparser
);
14136 the_parser
= ggc_alloc
<c_parser
> ();
14137 *the_parser
= tparser
;
14138 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
14139 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
14141 /* Initialize EH, if we've been told to do so. */
14142 if (flag_exceptions
)
14143 using_eh_for_cleanups ();
14145 c_parser_translation_unit (the_parser
);
14149 /* This function parses Cilk Plus array notation. The starting index is
14150 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14151 return value of this function is a tree_node called VALUE_TREE of type
14152 ARRAY_NOTATION_REF. */
14155 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
14158 c_token
*token
= NULL
;
14159 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
14160 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
14161 tree array_type_domain
= NULL_TREE
;
14163 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
14165 /* No need to continue. If either of these 2 were true, then an error
14166 must be emitted already. Thus, no need to emit them twice. */
14167 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14168 return error_mark_node
;
14171 array_type
= TREE_TYPE (array_value
);
14172 gcc_assert (array_type
);
14173 if (TREE_CODE (array_type
) != ARRAY_TYPE
14174 && TREE_CODE (array_type
) != POINTER_TYPE
)
14176 error_at (loc
, "base of array section must be pointer or array type");
14177 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14178 return error_mark_node
;
14180 type
= TREE_TYPE (array_type
);
14181 token
= c_parser_peek_token (parser
);
14183 if (token
->type
== CPP_EOF
)
14185 c_parser_error (parser
, "expected %<:%> or numeral");
14188 else if (token
->type
== CPP_COLON
)
14190 if (!initial_index
)
14192 /* If we are here, then we have a case like this A[:]. */
14193 c_parser_consume_token (parser
);
14194 if (TREE_CODE (array_type
) == POINTER_TYPE
)
14196 error_at (loc
, "start-index and length fields necessary for "
14197 "using array notations in pointers");
14198 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14199 return error_mark_node
;
14201 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14203 error_at (loc
, "array notations cannot be used with function "
14205 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14206 return error_mark_node
;
14208 array_type_domain
= TYPE_DOMAIN (array_type
);
14210 if (!array_type_domain
)
14212 error_at (loc
, "start-index and length fields necessary for "
14213 "using array notations in dimensionless arrays");
14214 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14215 return error_mark_node
;
14218 start_index
= TYPE_MINVAL (array_type_domain
);
14219 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
14221 if (!TYPE_MAXVAL (array_type_domain
)
14222 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
14224 error_at (loc
, "start-index and length fields necessary for "
14225 "using array notations in variable-length arrays");
14226 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14227 return error_mark_node
;
14229 end_index
= TYPE_MAXVAL (array_type_domain
);
14230 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
14231 end_index
, integer_one_node
);
14232 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
14233 stride
= build_int_cst (integer_type_node
, 1);
14234 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
14236 else if (initial_index
!= error_mark_node
)
14238 /* If we are here, then there should be 2 possibilities:
14239 1. Array [EXPR : EXPR]
14240 2. Array [EXPR : EXPR : EXPR]
14242 start_index
= initial_index
;
14244 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14246 error_at (loc
, "array notations cannot be used with function "
14248 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14249 return error_mark_node
;
14251 c_parser_consume_token (parser
); /* consume the ':' */
14252 struct c_expr ce
= c_parser_expression (parser
);
14253 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14254 end_index
= ce
.value
;
14255 if (!end_index
|| end_index
== error_mark_node
)
14257 c_parser_skip_to_end_of_block_or_statement (parser
);
14258 return error_mark_node
;
14260 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
14262 c_parser_consume_token (parser
);
14263 ce
= c_parser_expression (parser
);
14264 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14266 if (!stride
|| stride
== error_mark_node
)
14268 c_parser_skip_to_end_of_block_or_statement (parser
);
14269 return error_mark_node
;
14274 c_parser_error (parser
, "expected array notation expression");
14277 c_parser_error (parser
, "expected array notation expression");
14279 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14281 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
14282 end_index
, stride
, type
);
14283 if (value_tree
!= error_mark_node
)
14284 SET_EXPR_LOCATION (value_tree
, loc
);
14288 #include "gt-c-c-parser.h"