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 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1077 warn_pointer_arith
= 0;
1078 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1080 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1081 warn_cxx_compat
= 0;
1082 warn_overlength_strings
= 0;
1086 /* Restore the warning flags which are controlled by __extension__.
1087 FLAGS is the return value from disable_extension_diagnostics. */
1090 restore_extension_diagnostics (int flags
)
1092 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1093 warn_pointer_arith
= (flags
>> 1) & 1;
1094 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1095 flag_iso
= (flags
>> 3) & 1;
1096 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1097 warn_cxx_compat
= (flags
>> 5) & 1;
1098 warn_overlength_strings
= (flags
>> 6) & 1;
1101 /* Possibly kinds of declarator to parse. */
1102 typedef enum c_dtr_syn
{
1103 /* A normal declarator with an identifier. */
1105 /* An abstract declarator (maybe empty). */
1107 /* A parameter declarator: may be either, but after a type name does
1108 not redeclare a typedef name as an identifier if it can
1109 alternatively be interpreted as a typedef name; see DR#009,
1110 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1111 following DR#249. For example, given a typedef T, "int T" and
1112 "int *T" are valid parameter declarations redeclaring T, while
1113 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1114 abstract declarators rather than involving redundant parentheses;
1115 the same applies with attributes inside the parentheses before
1120 /* The binary operation precedence levels, where 0 is a dummy lowest level
1121 used for the bottom of the stack. */
1122 enum c_parser_prec
{
1137 static void c_parser_external_declaration (c_parser
*);
1138 static void c_parser_asm_definition (c_parser
*);
1139 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1140 bool, bool, tree
*, vec
<c_token
>);
1141 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1142 static void c_parser_static_assert_declaration (c_parser
*);
1143 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1144 bool, bool, bool, enum c_lookahead_kind
);
1145 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1146 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1147 static tree
c_parser_struct_declaration (c_parser
*);
1148 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1149 static tree
c_parser_alignas_specifier (c_parser
*);
1150 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1152 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1154 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1156 struct c_declarator
*);
1157 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1158 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1160 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1161 static tree
c_parser_simple_asm_expr (c_parser
*);
1162 static tree
c_parser_attributes (c_parser
*);
1163 static struct c_type_name
*c_parser_type_name (c_parser
*);
1164 static struct c_expr
c_parser_initializer (c_parser
*);
1165 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1166 static void c_parser_initelt (c_parser
*, struct obstack
*);
1167 static void c_parser_initval (c_parser
*, struct c_expr
*,
1169 static tree
c_parser_compound_statement (c_parser
*);
1170 static void c_parser_compound_statement_nostart (c_parser
*);
1171 static void c_parser_label (c_parser
*);
1172 static void c_parser_statement (c_parser
*);
1173 static void c_parser_statement_after_labels (c_parser
*);
1174 static void c_parser_if_statement (c_parser
*);
1175 static void c_parser_switch_statement (c_parser
*);
1176 static void c_parser_while_statement (c_parser
*, bool);
1177 static void c_parser_do_statement (c_parser
*, bool);
1178 static void c_parser_for_statement (c_parser
*, bool);
1179 static tree
c_parser_asm_statement (c_parser
*);
1180 static tree
c_parser_asm_operands (c_parser
*);
1181 static tree
c_parser_asm_goto_operands (c_parser
*);
1182 static tree
c_parser_asm_clobbers (c_parser
*);
1183 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1185 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1186 struct c_expr
*, tree
);
1187 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1189 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1190 static struct c_expr
c_parser_unary_expression (c_parser
*);
1191 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1192 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1193 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1194 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1195 struct c_type_name
*,
1197 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1200 static tree
c_parser_transaction (c_parser
*, enum rid
);
1201 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1202 static tree
c_parser_transaction_cancel (c_parser
*);
1203 static struct c_expr
c_parser_expression (c_parser
*);
1204 static struct c_expr
c_parser_expression_conv (c_parser
*);
1205 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1206 vec
<tree
, va_gc
> **, location_t
*,
1207 tree
*, vec
<location_t
> *);
1208 static void c_parser_omp_construct (c_parser
*);
1209 static void c_parser_omp_threadprivate (c_parser
*);
1210 static void c_parser_omp_barrier (c_parser
*);
1211 static void c_parser_omp_flush (c_parser
*);
1212 static void c_parser_omp_taskwait (c_parser
*);
1213 static void c_parser_omp_taskyield (c_parser
*);
1214 static void c_parser_omp_cancel (c_parser
*);
1215 static void c_parser_omp_cancellation_point (c_parser
*);
1217 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1218 pragma_stmt
, pragma_compound
};
1219 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1220 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1221 static void c_parser_omp_end_declare_target (c_parser
*);
1222 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1224 /* These Objective-C parser functions are only ever called when
1225 compiling Objective-C. */
1226 static void c_parser_objc_class_definition (c_parser
*, tree
);
1227 static void c_parser_objc_class_instance_variables (c_parser
*);
1228 static void c_parser_objc_class_declaration (c_parser
*);
1229 static void c_parser_objc_alias_declaration (c_parser
*);
1230 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1231 static bool c_parser_objc_method_type (c_parser
*);
1232 static void c_parser_objc_method_definition (c_parser
*);
1233 static void c_parser_objc_methodprotolist (c_parser
*);
1234 static void c_parser_objc_methodproto (c_parser
*);
1235 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1236 static tree
c_parser_objc_type_name (c_parser
*);
1237 static tree
c_parser_objc_protocol_refs (c_parser
*);
1238 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1239 static void c_parser_objc_synchronized_statement (c_parser
*);
1240 static tree
c_parser_objc_selector (c_parser
*);
1241 static tree
c_parser_objc_selector_arg (c_parser
*);
1242 static tree
c_parser_objc_receiver (c_parser
*);
1243 static tree
c_parser_objc_message_args (c_parser
*);
1244 static tree
c_parser_objc_keywordexpr (c_parser
*);
1245 static void c_parser_objc_at_property_declaration (c_parser
*);
1246 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1247 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1248 static bool c_parser_objc_diagnose_bad_element_prefix
1249 (c_parser
*, struct c_declspecs
*);
1251 /* Cilk Plus supporting routines. */
1252 static void c_parser_cilk_simd (c_parser
*);
1253 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1254 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1255 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1257 /* Parse a translation unit (C90 6.7, C99 6.9).
1260 external-declarations
1262 external-declarations:
1263 external-declaration
1264 external-declarations external-declaration
1273 c_parser_translation_unit (c_parser
*parser
)
1275 if (c_parser_next_token_is (parser
, CPP_EOF
))
1277 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1278 "ISO C forbids an empty translation unit");
1282 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1283 mark_valid_location_for_stdc_pragma (false);
1287 c_parser_external_declaration (parser
);
1288 obstack_free (&parser_obstack
, obstack_position
);
1290 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1294 /* Parse an external declaration (C90 6.7, C99 6.9).
1296 external-declaration:
1302 external-declaration:
1305 __extension__ external-declaration
1309 external-declaration:
1310 objc-class-definition
1311 objc-class-declaration
1312 objc-alias-declaration
1313 objc-protocol-definition
1314 objc-method-definition
1319 c_parser_external_declaration (c_parser
*parser
)
1322 switch (c_parser_peek_token (parser
)->type
)
1325 switch (c_parser_peek_token (parser
)->keyword
)
1328 ext
= disable_extension_diagnostics ();
1329 c_parser_consume_token (parser
);
1330 c_parser_external_declaration (parser
);
1331 restore_extension_diagnostics (ext
);
1334 c_parser_asm_definition (parser
);
1336 case RID_AT_INTERFACE
:
1337 case RID_AT_IMPLEMENTATION
:
1338 gcc_assert (c_dialect_objc ());
1339 c_parser_objc_class_definition (parser
, NULL_TREE
);
1342 gcc_assert (c_dialect_objc ());
1343 c_parser_objc_class_declaration (parser
);
1346 gcc_assert (c_dialect_objc ());
1347 c_parser_objc_alias_declaration (parser
);
1349 case RID_AT_PROTOCOL
:
1350 gcc_assert (c_dialect_objc ());
1351 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1353 case RID_AT_PROPERTY
:
1354 gcc_assert (c_dialect_objc ());
1355 c_parser_objc_at_property_declaration (parser
);
1357 case RID_AT_SYNTHESIZE
:
1358 gcc_assert (c_dialect_objc ());
1359 c_parser_objc_at_synthesize_declaration (parser
);
1361 case RID_AT_DYNAMIC
:
1362 gcc_assert (c_dialect_objc ());
1363 c_parser_objc_at_dynamic_declaration (parser
);
1366 gcc_assert (c_dialect_objc ());
1367 c_parser_consume_token (parser
);
1368 objc_finish_implementation ();
1375 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1376 "ISO C does not allow extra %<;%> outside of a function");
1377 c_parser_consume_token (parser
);
1380 mark_valid_location_for_stdc_pragma (true);
1381 c_parser_pragma (parser
, pragma_external
);
1382 mark_valid_location_for_stdc_pragma (false);
1386 if (c_dialect_objc ())
1388 c_parser_objc_method_definition (parser
);
1391 /* Else fall through, and yield a syntax error trying to parse
1392 as a declaration or function definition. */
1395 /* A declaration or a function definition (or, in Objective-C,
1396 an @interface or @protocol with prefix attributes). We can
1397 only tell which after parsing the declaration specifiers, if
1398 any, and the first declarator. */
1399 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1405 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1407 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1408 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1409 accepted; otherwise (old-style parameter declarations) only other
1410 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1411 assertion is accepted; otherwise (old-style parameter declarations)
1412 it is not. If NESTED is true, we are inside a function or parsing
1413 old-style parameter declarations; any functions encountered are
1414 nested functions and declaration specifiers are required; otherwise
1415 we are at top level and functions are normal functions and
1416 declaration specifiers may be optional. If EMPTY_OK is true, empty
1417 declarations are OK (subject to all other constraints); otherwise
1418 (old-style parameter declarations) they are diagnosed. If
1419 START_ATTR_OK is true, the declaration specifiers may start with
1420 attributes; otherwise they may not.
1421 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1422 declaration when parsing an Objective-C foreach statement.
1425 declaration-specifiers init-declarator-list[opt] ;
1426 static_assert-declaration
1428 function-definition:
1429 declaration-specifiers[opt] declarator declaration-list[opt]
1434 declaration-list declaration
1436 init-declarator-list:
1438 init-declarator-list , init-declarator
1441 declarator simple-asm-expr[opt] attributes[opt]
1442 declarator simple-asm-expr[opt] attributes[opt] = initializer
1446 nested-function-definition:
1447 declaration-specifiers declarator declaration-list[opt]
1451 attributes objc-class-definition
1452 attributes objc-category-definition
1453 attributes objc-protocol-definition
1455 The simple-asm-expr and attributes are GNU extensions.
1457 This function does not handle __extension__; that is handled in its
1458 callers. ??? Following the old parser, __extension__ may start
1459 external declarations, declarations in functions and declarations
1460 at the start of "for" loops, but not old-style parameter
1463 C99 requires declaration specifiers in a function definition; the
1464 absence is diagnosed through the diagnosis of implicit int. In GNU
1465 C we also allow but diagnose declarations without declaration
1466 specifiers, but only at top level (elsewhere they conflict with
1469 In Objective-C, declarations of the looping variable in a foreach
1470 statement are exceptionally terminated by 'in' (for example, 'for
1471 (NSObject *object in array) { ... }').
1476 threadprivate-directive */
1479 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1480 bool static_assert_ok
, bool empty_ok
,
1481 bool nested
, bool start_attr_ok
,
1482 tree
*objc_foreach_object_declaration
,
1483 vec
<c_token
> omp_declare_simd_clauses
)
1485 struct c_declspecs
*specs
;
1487 tree all_prefix_attrs
;
1488 bool diagnosed_no_specs
= false;
1489 location_t here
= c_parser_peek_token (parser
)->location
;
1491 if (static_assert_ok
1492 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1494 c_parser_static_assert_declaration (parser
);
1497 specs
= build_null_declspecs ();
1499 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1500 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1501 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1502 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1503 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1504 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1506 error_at (here
, "unknown type name %qE",
1507 c_parser_peek_token (parser
)->value
);
1509 /* Parse declspecs normally to get a correct pointer type, but avoid
1510 a further "fails to be a type name" error. Refuse nested functions
1511 since it is not how the user likely wants us to recover. */
1512 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1513 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1514 c_parser_peek_token (parser
)->value
= error_mark_node
;
1518 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1519 true, true, cla_nonabstract_decl
);
1522 c_parser_skip_to_end_of_block_or_statement (parser
);
1525 if (nested
&& !specs
->declspecs_seen_p
)
1527 c_parser_error (parser
, "expected declaration specifiers");
1528 c_parser_skip_to_end_of_block_or_statement (parser
);
1531 finish_declspecs (specs
);
1532 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1533 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1536 error_at (here
, "%<__auto_type%> in empty declaration");
1541 shadow_tag_warned (specs
, 1);
1542 pedwarn (here
, 0, "empty declaration");
1544 c_parser_consume_token (parser
);
1548 /* Provide better error recovery. Note that a type name here is usually
1549 better diagnosed as a redeclaration. */
1551 && specs
->typespec_kind
== ctsk_tagdef
1552 && c_parser_next_token_starts_declspecs (parser
)
1553 && !c_parser_next_token_is (parser
, CPP_NAME
))
1555 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1556 parser
->error
= false;
1557 shadow_tag_warned (specs
, 1);
1560 else if (c_dialect_objc () && !auto_type_p
)
1562 /* Prefix attributes are an error on method decls. */
1563 switch (c_parser_peek_token (parser
)->type
)
1567 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1571 warning_at (c_parser_peek_token (parser
)->location
,
1573 "prefix attributes are ignored for methods");
1574 specs
->attrs
= NULL_TREE
;
1577 c_parser_objc_method_definition (parser
);
1579 c_parser_objc_methodproto (parser
);
1585 /* This is where we parse 'attributes @interface ...',
1586 'attributes @implementation ...', 'attributes @protocol ...'
1587 (where attributes could be, for example, __attribute__
1590 switch (c_parser_peek_token (parser
)->keyword
)
1592 case RID_AT_INTERFACE
:
1594 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1596 c_parser_objc_class_definition (parser
, specs
->attrs
);
1600 case RID_AT_IMPLEMENTATION
:
1602 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1606 warning_at (c_parser_peek_token (parser
)->location
,
1608 "prefix attributes are ignored for implementations");
1609 specs
->attrs
= NULL_TREE
;
1611 c_parser_objc_class_definition (parser
, NULL_TREE
);
1615 case RID_AT_PROTOCOL
:
1617 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1619 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1626 case RID_AT_PROPERTY
:
1629 c_parser_error (parser
, "unexpected attribute");
1630 specs
->attrs
= NULL
;
1638 pending_xref_error ();
1639 prefix_attrs
= specs
->attrs
;
1640 all_prefix_attrs
= prefix_attrs
;
1641 specs
->attrs
= NULL_TREE
;
1644 struct c_declarator
*declarator
;
1648 /* Declaring either one or more declarators (in which case we
1649 should diagnose if there were no declaration specifiers) or a
1650 function definition (in which case the diagnostic for
1651 implicit int suffices). */
1652 declarator
= c_parser_declarator (parser
,
1653 specs
->typespec_kind
!= ctsk_none
,
1654 C_DTR_NORMAL
, &dummy
);
1655 if (declarator
== NULL
)
1657 if (omp_declare_simd_clauses
.exists ()
1658 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1659 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1660 omp_declare_simd_clauses
);
1661 c_parser_skip_to_end_of_block_or_statement (parser
);
1664 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1667 "%<__auto_type%> requires a plain identifier"
1669 c_parser_skip_to_end_of_block_or_statement (parser
);
1672 if (c_parser_next_token_is (parser
, CPP_EQ
)
1673 || c_parser_next_token_is (parser
, CPP_COMMA
)
1674 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1675 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1676 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1677 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1679 tree asm_name
= NULL_TREE
;
1680 tree postfix_attrs
= NULL_TREE
;
1681 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1683 diagnosed_no_specs
= true;
1684 pedwarn (here
, 0, "data definition has no type or storage class");
1686 /* Having seen a data definition, there cannot now be a
1687 function definition. */
1689 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1690 asm_name
= c_parser_simple_asm_expr (parser
);
1691 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1693 postfix_attrs
= c_parser_attributes (parser
);
1694 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1696 /* This means there is an attribute specifier after
1697 the declarator in a function definition. Provide
1698 some more information for the user. */
1699 error_at (here
, "attributes should be specified before the "
1700 "declarator in a function definition");
1701 c_parser_skip_to_end_of_block_or_statement (parser
);
1705 if (c_parser_next_token_is (parser
, CPP_EQ
))
1709 location_t init_loc
;
1710 c_parser_consume_token (parser
);
1713 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1714 init_loc
= c_parser_peek_token (parser
)->location
;
1715 init
= c_parser_expr_no_commas (parser
, NULL
);
1716 if (TREE_CODE (init
.value
) == COMPONENT_REF
1717 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1719 "%<__auto_type%> used with a bit-field"
1721 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1722 tree init_type
= TREE_TYPE (init
.value
);
1723 /* As with typeof, remove all qualifiers from atomic types. */
1724 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1726 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1727 bool vm_type
= variably_modified_type_p (init_type
,
1730 init
.value
= c_save_expr (init
.value
);
1732 specs
->typespec_kind
= ctsk_typeof
;
1733 specs
->locations
[cdw_typedef
] = init_loc
;
1734 specs
->typedef_p
= true;
1735 specs
->type
= init_type
;
1738 bool maybe_const
= true;
1739 tree type_expr
= c_fully_fold (init
.value
, false,
1741 specs
->expr_const_operands
&= maybe_const
;
1743 specs
->expr
= build2 (COMPOUND_EXPR
,
1744 TREE_TYPE (type_expr
),
1745 specs
->expr
, type_expr
);
1747 specs
->expr
= type_expr
;
1749 d
= start_decl (declarator
, specs
, true,
1750 chainon (postfix_attrs
, all_prefix_attrs
));
1752 d
= error_mark_node
;
1753 if (omp_declare_simd_clauses
.exists ()
1754 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1755 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1756 omp_declare_simd_clauses
);
1760 /* The declaration of the variable is in effect while
1761 its initializer is parsed. */
1762 d
= start_decl (declarator
, specs
, true,
1763 chainon (postfix_attrs
, all_prefix_attrs
));
1765 d
= error_mark_node
;
1766 if (omp_declare_simd_clauses
.exists ()
1767 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1768 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1769 omp_declare_simd_clauses
);
1770 start_init (d
, asm_name
, global_bindings_p ());
1771 init_loc
= c_parser_peek_token (parser
)->location
;
1772 init
= c_parser_initializer (parser
);
1775 if (d
!= error_mark_node
)
1777 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1778 finish_decl (d
, init_loc
, init
.value
,
1779 init
.original_type
, asm_name
);
1787 "%<__auto_type%> requires an initialized "
1788 "data declaration");
1789 c_parser_skip_to_end_of_block_or_statement (parser
);
1792 tree d
= start_decl (declarator
, specs
, false,
1793 chainon (postfix_attrs
,
1795 if (omp_declare_simd_clauses
.exists ()
1796 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1798 tree parms
= NULL_TREE
;
1799 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1801 struct c_declarator
*ce
= declarator
;
1803 if (ce
->kind
== cdk_function
)
1805 parms
= ce
->u
.arg_info
->parms
;
1809 ce
= ce
->declarator
;
1812 temp_store_parm_decls (d
, parms
);
1813 c_finish_omp_declare_simd (parser
, d
, parms
,
1814 omp_declare_simd_clauses
);
1816 temp_pop_parm_decls ();
1819 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1820 NULL_TREE
, asm_name
);
1822 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1825 *objc_foreach_object_declaration
= d
;
1827 *objc_foreach_object_declaration
= error_mark_node
;
1830 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1835 "%<__auto_type%> may only be used with"
1836 " a single declarator");
1837 c_parser_skip_to_end_of_block_or_statement (parser
);
1840 c_parser_consume_token (parser
);
1841 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1842 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1845 all_prefix_attrs
= prefix_attrs
;
1848 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1850 c_parser_consume_token (parser
);
1853 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1855 /* This can only happen in Objective-C: we found the
1856 'in' that terminates the declaration inside an
1857 Objective-C foreach statement. Do not consume the
1858 token, so that the caller can use it to determine
1859 that this indeed is a foreach context. */
1864 c_parser_error (parser
, "expected %<,%> or %<;%>");
1865 c_parser_skip_to_end_of_block_or_statement (parser
);
1869 else if (auto_type_p
)
1872 "%<__auto_type%> requires an initialized data declaration");
1873 c_parser_skip_to_end_of_block_or_statement (parser
);
1878 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1879 "%<asm%> or %<__attribute__%>");
1880 c_parser_skip_to_end_of_block_or_statement (parser
);
1883 /* Function definition (nested or otherwise). */
1886 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1887 c_push_function_context ();
1889 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1891 /* This can appear in many cases looking nothing like a
1892 function definition, so we don't give a more specific
1893 error suggesting there was one. */
1894 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1895 "or %<__attribute__%>");
1897 c_pop_function_context ();
1901 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1902 tv
= TV_PARSE_INLINE
;
1907 /* Parse old-style parameter declarations. ??? Attributes are
1908 not allowed to start declaration specifiers here because of a
1909 syntax conflict between a function declaration with attribute
1910 suffix and a function definition with an attribute prefix on
1911 first old-style parameter declaration. Following the old
1912 parser, they are not accepted on subsequent old-style
1913 parameter declarations either. However, there is no
1914 ambiguity after the first declaration, nor indeed on the
1915 first as long as we don't allow postfix attributes after a
1916 declarator with a nonempty identifier list in a definition;
1917 and postfix attributes have never been accepted here in
1918 function definitions either. */
1919 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1920 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1921 c_parser_declaration_or_fndef (parser
, false, false, false,
1922 true, false, NULL
, vNULL
);
1923 store_parm_decls ();
1924 if (omp_declare_simd_clauses
.exists ()
1925 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1926 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1927 omp_declare_simd_clauses
);
1928 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1929 = c_parser_peek_token (parser
)->location
;
1930 fnbody
= c_parser_compound_statement (parser
);
1931 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1932 fnbody
= expand_array_notation_exprs (fnbody
);
1935 tree decl
= current_function_decl
;
1936 /* Mark nested functions as needing static-chain initially.
1937 lower_nested_functions will recompute it but the
1938 DECL_STATIC_CHAIN flag is also used before that happens,
1939 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1940 DECL_STATIC_CHAIN (decl
) = 1;
1943 c_pop_function_context ();
1944 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1957 /* Parse an asm-definition (asm() outside a function body). This is a
1965 c_parser_asm_definition (c_parser
*parser
)
1967 tree asm_str
= c_parser_simple_asm_expr (parser
);
1969 add_asm_node (asm_str
);
1970 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1973 /* Parse a static assertion (C11 6.7.10).
1975 static_assert-declaration:
1976 static_assert-declaration-no-semi ;
1980 c_parser_static_assert_declaration (c_parser
*parser
)
1982 c_parser_static_assert_declaration_no_semi (parser
);
1984 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1985 c_parser_skip_to_end_of_block_or_statement (parser
);
1988 /* Parse a static assertion (C11 6.7.10), without the trailing
1991 static_assert-declaration-no-semi:
1992 _Static_assert ( constant-expression , string-literal )
1996 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1998 location_t assert_loc
, value_loc
;
2002 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2003 assert_loc
= c_parser_peek_token (parser
)->location
;
2007 pedwarn (assert_loc
, OPT_Wpedantic
,
2008 "ISO C99 does not support %<_Static_assert%>");
2010 pedwarn (assert_loc
, OPT_Wpedantic
,
2011 "ISO C90 does not support %<_Static_assert%>");
2013 c_parser_consume_token (parser
);
2014 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2016 value_loc
= c_parser_peek_token (parser
)->location
;
2017 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2018 parser
->lex_untranslated_string
= true;
2019 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2021 parser
->lex_untranslated_string
= false;
2024 switch (c_parser_peek_token (parser
)->type
)
2030 case CPP_UTF8STRING
:
2031 string
= c_parser_peek_token (parser
)->value
;
2032 c_parser_consume_token (parser
);
2033 parser
->lex_untranslated_string
= false;
2036 c_parser_error (parser
, "expected string literal");
2037 parser
->lex_untranslated_string
= false;
2040 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2042 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2044 error_at (value_loc
, "expression in static assertion is not an integer");
2047 if (TREE_CODE (value
) != INTEGER_CST
)
2049 value
= c_fully_fold (value
, false, NULL
);
2050 if (TREE_CODE (value
) == INTEGER_CST
)
2051 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2052 "is not an integer constant expression");
2054 if (TREE_CODE (value
) != INTEGER_CST
)
2056 error_at (value_loc
, "expression in static assertion is not constant");
2059 constant_expression_warning (value
);
2060 if (integer_zerop (value
))
2061 error_at (assert_loc
, "static assertion failed: %E", string
);
2064 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2065 6.7), adding them to SPECS (which may already include some).
2066 Storage class specifiers are accepted iff SCSPEC_OK; type
2067 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2068 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2069 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2071 declaration-specifiers:
2072 storage-class-specifier declaration-specifiers[opt]
2073 type-specifier declaration-specifiers[opt]
2074 type-qualifier declaration-specifiers[opt]
2075 function-specifier declaration-specifiers[opt]
2076 alignment-specifier declaration-specifiers[opt]
2078 Function specifiers (inline) are from C99, and are currently
2079 handled as storage class specifiers, as is __thread. Alignment
2080 specifiers are from C11.
2082 C90 6.5.1, C99 6.7.1:
2083 storage-class-specifier:
2091 (_Thread_local is new in C11.)
2098 (_Noreturn is new in C11.)
2100 C90 6.5.2, C99 6.7.2:
2113 [_Imaginary removed in C99 TC2]
2114 struct-or-union-specifier
2117 atomic-type-specifier
2119 (_Bool and _Complex are new in C99.)
2120 (atomic-type-specifier is new in C11.)
2122 C90 6.5.3, C99 6.7.3:
2128 address-space-qualifier
2131 (restrict is new in C99.)
2132 (_Atomic is new in C11.)
2136 declaration-specifiers:
2137 attributes declaration-specifiers[opt]
2143 identifier recognized by the target
2145 storage-class-specifier:
2159 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2160 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2162 atomic-type-specifier
2163 _Atomic ( type-name )
2168 class-name objc-protocol-refs[opt]
2169 typedef-name objc-protocol-refs
2174 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2175 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2176 bool alignspec_ok
, bool auto_type_ok
,
2177 enum c_lookahead_kind la
)
2179 bool attrs_ok
= start_attr_ok
;
2180 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2183 gcc_assert (la
== cla_prefer_id
);
2185 while (c_parser_next_token_is (parser
, CPP_NAME
)
2186 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2187 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2189 struct c_typespec t
;
2192 location_t loc
= c_parser_peek_token (parser
)->location
;
2194 /* If we cannot accept a type, exit if the next token must start
2195 one. Also, if we already have seen a tagged definition,
2196 a typename would be an error anyway and likely the user
2197 has simply forgotten a semicolon, so we exit. */
2198 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2199 && c_parser_next_tokens_start_typename (parser
, la
)
2200 && !c_parser_next_token_is_qualifier (parser
))
2203 if (c_parser_next_token_is (parser
, CPP_NAME
))
2205 c_token
*name_token
= c_parser_peek_token (parser
);
2206 tree value
= name_token
->value
;
2207 c_id_kind kind
= name_token
->id_kind
;
2209 if (kind
== C_ID_ADDRSPACE
)
2212 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2213 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2214 c_parser_consume_token (parser
);
2219 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2221 /* If we cannot accept a type, and the next token must start one,
2222 exit. Do the same if we already have seen a tagged definition,
2223 since it would be an error anyway and likely the user has simply
2224 forgotten a semicolon. */
2225 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2228 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2229 a C_ID_CLASSNAME. */
2230 c_parser_consume_token (parser
);
2233 if (kind
== C_ID_ID
)
2235 error_at (loc
, "unknown type name %qE", value
);
2236 t
.kind
= ctsk_typedef
;
2237 t
.spec
= error_mark_node
;
2239 else if (kind
== C_ID_TYPENAME
2240 && (!c_dialect_objc ()
2241 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2243 t
.kind
= ctsk_typedef
;
2244 /* For a typedef name, record the meaning, not the name.
2245 In case of 'foo foo, bar;'. */
2246 t
.spec
= lookup_name (value
);
2250 tree proto
= NULL_TREE
;
2251 gcc_assert (c_dialect_objc ());
2253 if (c_parser_next_token_is (parser
, CPP_LESS
))
2254 proto
= c_parser_objc_protocol_refs (parser
);
2255 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2258 t
.expr_const_operands
= true;
2259 declspecs_add_type (name_token
->location
, specs
, t
);
2262 if (c_parser_next_token_is (parser
, CPP_LESS
))
2264 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2265 nisse@lysator.liu.se. */
2267 gcc_assert (c_dialect_objc ());
2268 if (!typespec_ok
|| seen_type
)
2270 proto
= c_parser_objc_protocol_refs (parser
);
2272 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2274 t
.expr_const_operands
= true;
2275 declspecs_add_type (loc
, specs
, t
);
2278 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2279 switch (c_parser_peek_token (parser
)->keyword
)
2292 /* TODO: Distinguish between function specifiers (inline, noreturn)
2293 and storage class specifiers, either here or in
2294 declspecs_add_scspec. */
2295 declspecs_add_scspec (loc
, specs
,
2296 c_parser_peek_token (parser
)->value
);
2297 c_parser_consume_token (parser
);
2325 if (c_dialect_objc ())
2326 parser
->objc_need_raw_identifier
= true;
2327 t
.kind
= ctsk_resword
;
2328 t
.spec
= c_parser_peek_token (parser
)->value
;
2330 t
.expr_const_operands
= true;
2331 declspecs_add_type (loc
, specs
, t
);
2332 c_parser_consume_token (parser
);
2339 t
= c_parser_enum_specifier (parser
);
2340 declspecs_add_type (loc
, specs
, t
);
2348 t
= c_parser_struct_or_union_specifier (parser
);
2349 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2350 declspecs_add_type (loc
, specs
, t
);
2353 /* ??? The old parser rejected typeof after other type
2354 specifiers, but is a syntax error the best way of
2356 if (!typespec_ok
|| seen_type
)
2360 t
= c_parser_typeof_specifier (parser
);
2361 declspecs_add_type (loc
, specs
, t
);
2364 /* C parser handling of Objective-C constructs needs
2365 checking for correct lvalue-to-rvalue conversions, and
2366 the code in build_modify_expr handling various
2367 Objective-C cases, and that in build_unary_op handling
2368 Objective-C cases for increment / decrement, also needs
2369 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2370 and objc_types_are_equivalent may also need updates. */
2371 if (c_dialect_objc ())
2372 sorry ("%<_Atomic%> in Objective-C");
2373 /* C parser handling of OpenMP constructs needs checking for
2374 correct lvalue-to-rvalue conversions. */
2376 sorry ("%<_Atomic%> with OpenMP");
2380 pedwarn (loc
, OPT_Wpedantic
,
2381 "ISO C99 does not support the %<_Atomic%> qualifier");
2383 pedwarn (loc
, OPT_Wpedantic
,
2384 "ISO C90 does not support the %<_Atomic%> qualifier");
2388 value
= c_parser_peek_token (parser
)->value
;
2389 c_parser_consume_token (parser
);
2390 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2392 /* _Atomic ( type-name ). */
2394 c_parser_consume_token (parser
);
2395 struct c_type_name
*type
= c_parser_type_name (parser
);
2396 t
.kind
= ctsk_typeof
;
2397 t
.spec
= error_mark_node
;
2399 t
.expr_const_operands
= true;
2401 t
.spec
= groktypename (type
, &t
.expr
,
2402 &t
.expr_const_operands
);
2403 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2405 if (t
.spec
!= error_mark_node
)
2407 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2408 error_at (loc
, "%<_Atomic%>-qualified array type");
2409 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2410 error_at (loc
, "%<_Atomic%>-qualified function type");
2411 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2412 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2414 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2416 declspecs_add_type (loc
, specs
, t
);
2419 declspecs_add_qual (loc
, specs
, value
);
2425 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2426 c_parser_consume_token (parser
);
2431 attrs
= c_parser_attributes (parser
);
2432 declspecs_add_attrs (loc
, specs
, attrs
);
2437 align
= c_parser_alignas_specifier (parser
);
2438 declspecs_add_alignas (loc
, specs
, align
);
2447 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2450 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2451 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2452 enum attributes[opt] identifier
2454 The form with trailing comma is new in C99. The forms with
2455 attributes are GNU extensions. In GNU C, we accept any expression
2456 without commas in the syntax (assignment expressions, not just
2457 conditional expressions); assignment expressions will be diagnosed
2462 enumerator-list , enumerator
2465 enumeration-constant
2466 enumeration-constant = constant-expression
2469 static struct c_typespec
2470 c_parser_enum_specifier (c_parser
*parser
)
2472 struct c_typespec ret
;
2474 tree ident
= NULL_TREE
;
2475 location_t enum_loc
;
2476 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2477 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2478 enum_loc
= c_parser_peek_token (parser
)->location
;
2479 c_parser_consume_token (parser
);
2480 attrs
= c_parser_attributes (parser
);
2481 enum_loc
= c_parser_peek_token (parser
)->location
;
2482 /* Set the location in case we create a decl now. */
2483 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2484 if (c_parser_next_token_is (parser
, CPP_NAME
))
2486 ident
= c_parser_peek_token (parser
)->value
;
2487 ident_loc
= c_parser_peek_token (parser
)->location
;
2488 enum_loc
= ident_loc
;
2489 c_parser_consume_token (parser
);
2491 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2493 /* Parse an enum definition. */
2494 struct c_enum_contents the_enum
;
2497 /* We chain the enumerators in reverse order, then put them in
2498 forward order at the end. */
2500 timevar_push (TV_PARSE_ENUM
);
2501 type
= start_enum (enum_loc
, &the_enum
, ident
);
2503 c_parser_consume_token (parser
);
2511 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2512 location_t decl_loc
, value_loc
;
2513 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2515 c_parser_error (parser
, "expected identifier");
2516 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2517 values
= error_mark_node
;
2520 token
= c_parser_peek_token (parser
);
2521 enum_id
= token
->value
;
2522 /* Set the location in case we create a decl now. */
2523 c_parser_set_source_position_from_token (token
);
2524 decl_loc
= value_loc
= token
->location
;
2525 c_parser_consume_token (parser
);
2526 if (c_parser_next_token_is (parser
, CPP_EQ
))
2528 c_parser_consume_token (parser
);
2529 value_loc
= c_parser_peek_token (parser
)->location
;
2530 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2533 enum_value
= NULL_TREE
;
2534 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2535 &the_enum
, enum_id
, enum_value
);
2536 TREE_CHAIN (enum_decl
) = values
;
2539 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2541 comma_loc
= c_parser_peek_token (parser
)->location
;
2543 c_parser_consume_token (parser
);
2545 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2547 if (seen_comma
&& !flag_isoc99
)
2548 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2549 c_parser_consume_token (parser
);
2554 c_parser_error (parser
, "expected %<,%> or %<}%>");
2555 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2556 values
= error_mark_node
;
2560 postfix_attrs
= c_parser_attributes (parser
);
2561 ret
.spec
= finish_enum (type
, nreverse (values
),
2562 chainon (attrs
, postfix_attrs
));
2563 ret
.kind
= ctsk_tagdef
;
2564 ret
.expr
= NULL_TREE
;
2565 ret
.expr_const_operands
= true;
2566 timevar_pop (TV_PARSE_ENUM
);
2571 c_parser_error (parser
, "expected %<{%>");
2572 ret
.spec
= error_mark_node
;
2573 ret
.kind
= ctsk_tagref
;
2574 ret
.expr
= NULL_TREE
;
2575 ret
.expr_const_operands
= true;
2578 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2579 /* In ISO C, enumerated types can be referred to only if already
2581 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2584 pedwarn (enum_loc
, OPT_Wpedantic
,
2585 "ISO C forbids forward references to %<enum%> types");
2590 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2592 struct-or-union-specifier:
2593 struct-or-union attributes[opt] identifier[opt]
2594 { struct-contents } attributes[opt]
2595 struct-or-union attributes[opt] identifier
2598 struct-declaration-list
2600 struct-declaration-list:
2601 struct-declaration ;
2602 struct-declaration-list struct-declaration ;
2609 struct-declaration-list struct-declaration
2611 struct-declaration-list:
2612 struct-declaration-list ;
2615 (Note that in the syntax here, unlike that in ISO C, the semicolons
2616 are included here rather than in struct-declaration, in order to
2617 describe the syntax with extra semicolons and missing semicolon at
2622 struct-declaration-list:
2623 @defs ( class-name )
2625 (Note this does not include a trailing semicolon, but can be
2626 followed by further declarations, and gets a pedwarn-if-pedantic
2627 when followed by a semicolon.) */
2629 static struct c_typespec
2630 c_parser_struct_or_union_specifier (c_parser
*parser
)
2632 struct c_typespec ret
;
2634 tree ident
= NULL_TREE
;
2635 location_t struct_loc
;
2636 location_t ident_loc
= UNKNOWN_LOCATION
;
2637 enum tree_code code
;
2638 switch (c_parser_peek_token (parser
)->keyword
)
2649 struct_loc
= c_parser_peek_token (parser
)->location
;
2650 c_parser_consume_token (parser
);
2651 attrs
= c_parser_attributes (parser
);
2653 /* Set the location in case we create a decl now. */
2654 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2656 if (c_parser_next_token_is (parser
, CPP_NAME
))
2658 ident
= c_parser_peek_token (parser
)->value
;
2659 ident_loc
= c_parser_peek_token (parser
)->location
;
2660 struct_loc
= ident_loc
;
2661 c_parser_consume_token (parser
);
2663 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2665 /* Parse a struct or union definition. Start the scope of the
2666 tag before parsing components. */
2667 struct c_struct_parse_info
*struct_info
;
2668 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2670 /* We chain the components in reverse order, then put them in
2671 forward order at the end. Each struct-declaration may
2672 declare multiple components (comma-separated), so we must use
2673 chainon to join them, although when parsing each
2674 struct-declaration we can use TREE_CHAIN directly.
2676 The theory behind all this is that there will be more
2677 semicolon separated fields than comma separated fields, and
2678 so we'll be minimizing the number of node traversals required
2681 timevar_push (TV_PARSE_STRUCT
);
2682 contents
= NULL_TREE
;
2683 c_parser_consume_token (parser
);
2684 /* Handle the Objective-C @defs construct,
2685 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2686 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2689 gcc_assert (c_dialect_objc ());
2690 c_parser_consume_token (parser
);
2691 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2693 if (c_parser_next_token_is (parser
, CPP_NAME
)
2694 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2696 name
= c_parser_peek_token (parser
)->value
;
2697 c_parser_consume_token (parser
);
2701 c_parser_error (parser
, "expected class name");
2702 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2705 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2707 contents
= nreverse (objc_get_class_ivars (name
));
2710 /* Parse the struct-declarations and semicolons. Problems with
2711 semicolons are diagnosed here; empty structures are diagnosed
2716 /* Parse any stray semicolon. */
2717 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2719 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2720 "extra semicolon in struct or union specified");
2721 c_parser_consume_token (parser
);
2724 /* Stop if at the end of the struct or union contents. */
2725 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2727 c_parser_consume_token (parser
);
2730 /* Accept #pragmas at struct scope. */
2731 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2733 c_parser_pragma (parser
, pragma_struct
);
2736 /* Parse some comma-separated declarations, but not the
2737 trailing semicolon if any. */
2738 decls
= c_parser_struct_declaration (parser
);
2739 contents
= chainon (decls
, contents
);
2740 /* If no semicolon follows, either we have a parse error or
2741 are at the end of the struct or union and should
2743 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2744 c_parser_consume_token (parser
);
2747 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2748 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2749 "no semicolon at end of struct or union");
2750 else if (parser
->error
2751 || !c_parser_next_token_starts_declspecs (parser
))
2753 c_parser_error (parser
, "expected %<;%>");
2754 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2758 /* If we come here, we have already emitted an error
2759 for an expected `;', identifier or `(', and we also
2760 recovered already. Go on with the next field. */
2763 postfix_attrs
= c_parser_attributes (parser
);
2764 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2765 chainon (attrs
, postfix_attrs
), struct_info
);
2766 ret
.kind
= ctsk_tagdef
;
2767 ret
.expr
= NULL_TREE
;
2768 ret
.expr_const_operands
= true;
2769 timevar_pop (TV_PARSE_STRUCT
);
2774 c_parser_error (parser
, "expected %<{%>");
2775 ret
.spec
= error_mark_node
;
2776 ret
.kind
= ctsk_tagref
;
2777 ret
.expr
= NULL_TREE
;
2778 ret
.expr_const_operands
= true;
2781 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2785 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2786 the trailing semicolon.
2789 specifier-qualifier-list struct-declarator-list
2790 static_assert-declaration-no-semi
2792 specifier-qualifier-list:
2793 type-specifier specifier-qualifier-list[opt]
2794 type-qualifier specifier-qualifier-list[opt]
2795 attributes specifier-qualifier-list[opt]
2797 struct-declarator-list:
2799 struct-declarator-list , attributes[opt] struct-declarator
2802 declarator attributes[opt]
2803 declarator[opt] : constant-expression attributes[opt]
2808 __extension__ struct-declaration
2809 specifier-qualifier-list
2811 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2812 of attributes where shown is a GNU extension. In GNU C, we accept
2813 any expression without commas in the syntax (assignment
2814 expressions, not just conditional expressions); assignment
2815 expressions will be diagnosed as non-constant. */
2818 c_parser_struct_declaration (c_parser
*parser
)
2820 struct c_declspecs
*specs
;
2822 tree all_prefix_attrs
;
2824 location_t decl_loc
;
2825 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2829 ext
= disable_extension_diagnostics ();
2830 c_parser_consume_token (parser
);
2831 decl
= c_parser_struct_declaration (parser
);
2832 restore_extension_diagnostics (ext
);
2835 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2837 c_parser_static_assert_declaration_no_semi (parser
);
2840 specs
= build_null_declspecs ();
2841 decl_loc
= c_parser_peek_token (parser
)->location
;
2842 /* Strictly by the standard, we shouldn't allow _Alignas here,
2843 but it appears to have been intended to allow it there, so
2844 we're keeping it as it is until WG14 reaches a conclusion
2846 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2847 c_parser_declspecs (parser
, specs
, false, true, true,
2848 true, false, cla_nonabstract_decl
);
2851 if (!specs
->declspecs_seen_p
)
2853 c_parser_error (parser
, "expected specifier-qualifier-list");
2856 finish_declspecs (specs
);
2857 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2858 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2861 if (specs
->typespec_kind
== ctsk_none
)
2863 pedwarn (decl_loc
, OPT_Wpedantic
,
2864 "ISO C forbids member declarations with no members");
2865 shadow_tag_warned (specs
, pedantic
);
2870 /* Support for unnamed structs or unions as members of
2871 structs or unions (which is [a] useful and [b] supports
2875 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2876 build_id_declarator (NULL_TREE
), specs
,
2879 decl_attributes (&ret
, attrs
, 0);
2884 /* Provide better error recovery. Note that a type name here is valid,
2885 and will be treated as a field name. */
2886 if (specs
->typespec_kind
== ctsk_tagdef
2887 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2888 && c_parser_next_token_starts_declspecs (parser
)
2889 && !c_parser_next_token_is (parser
, CPP_NAME
))
2891 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2892 parser
->error
= false;
2896 pending_xref_error ();
2897 prefix_attrs
= specs
->attrs
;
2898 all_prefix_attrs
= prefix_attrs
;
2899 specs
->attrs
= NULL_TREE
;
2903 /* Declaring one or more declarators or un-named bit-fields. */
2904 struct c_declarator
*declarator
;
2906 if (c_parser_next_token_is (parser
, CPP_COLON
))
2907 declarator
= build_id_declarator (NULL_TREE
);
2909 declarator
= c_parser_declarator (parser
,
2910 specs
->typespec_kind
!= ctsk_none
,
2911 C_DTR_NORMAL
, &dummy
);
2912 if (declarator
== NULL
)
2914 c_parser_skip_to_end_of_block_or_statement (parser
);
2917 if (c_parser_next_token_is (parser
, CPP_COLON
)
2918 || c_parser_next_token_is (parser
, CPP_COMMA
)
2919 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2920 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2921 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2923 tree postfix_attrs
= NULL_TREE
;
2924 tree width
= NULL_TREE
;
2926 if (c_parser_next_token_is (parser
, CPP_COLON
))
2928 c_parser_consume_token (parser
);
2929 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2931 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2932 postfix_attrs
= c_parser_attributes (parser
);
2933 d
= grokfield (c_parser_peek_token (parser
)->location
,
2934 declarator
, specs
, width
, &all_prefix_attrs
);
2935 decl_attributes (&d
, chainon (postfix_attrs
,
2936 all_prefix_attrs
), 0);
2937 DECL_CHAIN (d
) = decls
;
2939 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2940 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2943 all_prefix_attrs
= prefix_attrs
;
2944 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2945 c_parser_consume_token (parser
);
2946 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2947 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2949 /* Semicolon consumed in caller. */
2954 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2960 c_parser_error (parser
,
2961 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2962 "%<__attribute__%>");
2969 /* Parse a typeof specifier (a GNU extension).
2972 typeof ( expression )
2973 typeof ( type-name )
2976 static struct c_typespec
2977 c_parser_typeof_specifier (c_parser
*parser
)
2979 struct c_typespec ret
;
2980 ret
.kind
= ctsk_typeof
;
2981 ret
.spec
= error_mark_node
;
2982 ret
.expr
= NULL_TREE
;
2983 ret
.expr_const_operands
= true;
2984 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2985 c_parser_consume_token (parser
);
2986 c_inhibit_evaluation_warnings
++;
2988 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2990 c_inhibit_evaluation_warnings
--;
2994 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2996 struct c_type_name
*type
= c_parser_type_name (parser
);
2997 c_inhibit_evaluation_warnings
--;
3001 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3002 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3008 location_t here
= c_parser_peek_token (parser
)->location
;
3009 struct c_expr expr
= c_parser_expression (parser
);
3010 c_inhibit_evaluation_warnings
--;
3012 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3013 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3014 error_at (here
, "%<typeof%> applied to a bit-field");
3015 mark_exp_read (expr
.value
);
3016 ret
.spec
= TREE_TYPE (expr
.value
);
3017 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3018 /* This is returned with the type so that when the type is
3019 evaluated, this can be evaluated. */
3021 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3022 pop_maybe_used (was_vm
);
3023 /* For use in macros such as those in <stdatomic.h>, remove all
3024 qualifiers from atomic types. (const can be an issue for more macros
3025 using typeof than just the <stdatomic.h> ones.) */
3026 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3027 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3033 /* Parse an alignment-specifier.
3037 alignment-specifier:
3038 _Alignas ( type-name )
3039 _Alignas ( constant-expression )
3043 c_parser_alignas_specifier (c_parser
* parser
)
3045 tree ret
= error_mark_node
;
3046 location_t loc
= c_parser_peek_token (parser
)->location
;
3047 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3048 c_parser_consume_token (parser
);
3052 pedwarn (loc
, OPT_Wpedantic
,
3053 "ISO C99 does not support %<_Alignas%>");
3055 pedwarn (loc
, OPT_Wpedantic
,
3056 "ISO C90 does not support %<_Alignas%>");
3058 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3060 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3062 struct c_type_name
*type
= c_parser_type_name (parser
);
3064 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3068 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3069 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3073 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3074 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3075 be redeclared; otherwise it may not. KIND indicates which kind of
3076 declarator is wanted. Returns a valid declarator except in the
3077 case of a syntax error in which case NULL is returned. *SEEN_ID is
3078 set to true if an identifier being declared is seen; this is used
3079 to diagnose bad forms of abstract array declarators and to
3080 determine whether an identifier list is syntactically permitted.
3083 pointer[opt] direct-declarator
3087 ( attributes[opt] declarator )
3088 direct-declarator array-declarator
3089 direct-declarator ( parameter-type-list )
3090 direct-declarator ( identifier-list[opt] )
3093 * type-qualifier-list[opt]
3094 * type-qualifier-list[opt] pointer
3096 type-qualifier-list:
3099 type-qualifier-list type-qualifier
3100 type-qualifier-list attributes
3103 [ type-qualifier-list[opt] assignment-expression[opt] ]
3104 [ static type-qualifier-list[opt] assignment-expression ]
3105 [ type-qualifier-list static assignment-expression ]
3106 [ type-qualifier-list[opt] * ]
3108 parameter-type-list:
3110 parameter-list , ...
3113 parameter-declaration
3114 parameter-list , parameter-declaration
3116 parameter-declaration:
3117 declaration-specifiers declarator attributes[opt]
3118 declaration-specifiers abstract-declarator[opt] attributes[opt]
3122 identifier-list , identifier
3124 abstract-declarator:
3126 pointer[opt] direct-abstract-declarator
3128 direct-abstract-declarator:
3129 ( attributes[opt] abstract-declarator )
3130 direct-abstract-declarator[opt] array-declarator
3131 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3136 direct-declarator ( parameter-forward-declarations
3137 parameter-type-list[opt] )
3139 direct-abstract-declarator:
3140 direct-abstract-declarator[opt] ( parameter-forward-declarations
3141 parameter-type-list[opt] )
3143 parameter-forward-declarations:
3145 parameter-forward-declarations parameter-list ;
3147 The uses of attributes shown above are GNU extensions.
3149 Some forms of array declarator are not included in C99 in the
3150 syntax for abstract declarators; these are disallowed elsewhere.
3151 This may be a defect (DR#289).
3153 This function also accepts an omitted abstract declarator as being
3154 an abstract declarator, although not part of the formal syntax. */
3156 static struct c_declarator
*
3157 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3160 /* Parse any initial pointer part. */
3161 if (c_parser_next_token_is (parser
, CPP_MULT
))
3163 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3164 struct c_declarator
*inner
;
3165 c_parser_consume_token (parser
);
3166 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3167 false, false, cla_prefer_id
);
3168 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3172 return make_pointer_declarator (quals_attrs
, inner
);
3174 /* Now we have a direct declarator, direct abstract declarator or
3175 nothing (which counts as a direct abstract declarator here). */
3176 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3179 /* Parse a direct declarator or direct abstract declarator; arguments
3180 as c_parser_declarator. */
3182 static struct c_declarator
*
3183 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3186 /* The direct declarator must start with an identifier (possibly
3187 omitted) or a parenthesized declarator (possibly abstract). In
3188 an ordinary declarator, initial parentheses must start a
3189 parenthesized declarator. In an abstract declarator or parameter
3190 declarator, they could start a parenthesized declarator or a
3191 parameter list. To tell which, the open parenthesis and any
3192 following attributes must be read. If a declaration specifier
3193 follows, then it is a parameter list; if the specifier is a
3194 typedef name, there might be an ambiguity about redeclaring it,
3195 which is resolved in the direction of treating it as a typedef
3196 name. If a close parenthesis follows, it is also an empty
3197 parameter list, as the syntax does not permit empty abstract
3198 declarators. Otherwise, it is a parenthesized declarator (in
3199 which case the analysis may be repeated inside it, recursively).
3201 ??? There is an ambiguity in a parameter declaration "int
3202 (__attribute__((foo)) x)", where x is not a typedef name: it
3203 could be an abstract declarator for a function, or declare x with
3204 parentheses. The proper resolution of this ambiguity needs
3205 documenting. At present we follow an accident of the old
3206 parser's implementation, whereby the first parameter must have
3207 some declaration specifiers other than just attributes. Thus as
3208 a parameter declaration it is treated as a parenthesized
3209 parameter named x, and as an abstract declarator it is
3212 ??? Also following the old parser, attributes inside an empty
3213 parameter list are ignored, making it a list not yielding a
3214 prototype, rather than giving an error or making it have one
3215 parameter with implicit type int.
3217 ??? Also following the old parser, typedef names may be
3218 redeclared in declarators, but not Objective-C class names. */
3220 if (kind
!= C_DTR_ABSTRACT
3221 && c_parser_next_token_is (parser
, CPP_NAME
)
3223 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3224 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3225 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3227 struct c_declarator
*inner
3228 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3230 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3231 c_parser_consume_token (parser
);
3232 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3235 if (kind
!= C_DTR_NORMAL
3236 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3238 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3239 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3242 /* Either we are at the end of an abstract declarator, or we have
3245 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3248 struct c_declarator
*inner
;
3249 c_parser_consume_token (parser
);
3250 attrs
= c_parser_attributes (parser
);
3251 if (kind
!= C_DTR_NORMAL
3252 && (c_parser_next_token_starts_declspecs (parser
)
3253 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3255 struct c_arg_info
*args
3256 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3263 = build_function_declarator (args
,
3264 build_id_declarator (NULL_TREE
));
3265 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3269 /* A parenthesized declarator. */
3270 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3271 if (inner
!= NULL
&& attrs
!= NULL
)
3272 inner
= build_attrs_declarator (attrs
, inner
);
3273 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3275 c_parser_consume_token (parser
);
3279 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3283 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3290 if (kind
== C_DTR_NORMAL
)
3292 c_parser_error (parser
, "expected identifier or %<(%>");
3296 return build_id_declarator (NULL_TREE
);
3300 /* Parse part of a direct declarator or direct abstract declarator,
3301 given that some (in INNER) has already been parsed; ID_PRESENT is
3302 true if an identifier is present, false for an abstract
3305 static struct c_declarator
*
3306 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3307 struct c_declarator
*inner
)
3309 /* Parse a sequence of array declarators and parameter lists. */
3310 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3312 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3313 struct c_declarator
*declarator
;
3314 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3317 struct c_expr dimen
;
3318 dimen
.value
= NULL_TREE
;
3319 dimen
.original_code
= ERROR_MARK
;
3320 dimen
.original_type
= NULL_TREE
;
3321 c_parser_consume_token (parser
);
3322 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3323 false, false, cla_prefer_id
);
3324 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3326 c_parser_consume_token (parser
);
3327 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3328 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3329 false, false, cla_prefer_id
);
3330 if (!quals_attrs
->declspecs_seen_p
)
3332 /* If "static" is present, there must be an array dimension.
3333 Otherwise, there may be a dimension, "*", or no
3338 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3342 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3344 dimen
.value
= NULL_TREE
;
3347 else if (flag_cilkplus
3348 && c_parser_next_token_is (parser
, CPP_COLON
))
3350 dimen
.value
= error_mark_node
;
3352 error_at (c_parser_peek_token (parser
)->location
,
3353 "array notations cannot be used in declaration");
3354 c_parser_consume_token (parser
);
3356 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3358 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3360 dimen
.value
= NULL_TREE
;
3362 c_parser_consume_token (parser
);
3367 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3373 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3376 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3377 c_parser_consume_token (parser
);
3378 else if (flag_cilkplus
3379 && c_parser_next_token_is (parser
, CPP_COLON
))
3381 error_at (c_parser_peek_token (parser
)->location
,
3382 "array notations cannot be used in declaration");
3383 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3388 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3393 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3394 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3395 static_seen
, star_seen
);
3396 if (declarator
== NULL
)
3398 inner
= set_array_declarator_inner (declarator
, inner
);
3399 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3401 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3404 struct c_arg_info
*args
;
3405 c_parser_consume_token (parser
);
3406 attrs
= c_parser_attributes (parser
);
3407 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3412 inner
= build_function_declarator (args
, inner
);
3413 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3419 /* Parse a parameter list or identifier list, including the closing
3420 parenthesis but not the opening one. ATTRS are the attributes at
3421 the start of the list. ID_LIST_OK is true if an identifier list is
3422 acceptable; such a list must not have attributes at the start. */
3424 static struct c_arg_info
*
3425 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3428 declare_parm_level ();
3429 /* If the list starts with an identifier, it is an identifier list.
3430 Otherwise, it is either a prototype list or an empty list. */
3433 && c_parser_next_token_is (parser
, CPP_NAME
)
3434 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3436 /* Look ahead to detect typos in type names. */
3437 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3438 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3439 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3440 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3442 tree list
= NULL_TREE
, *nextp
= &list
;
3443 while (c_parser_next_token_is (parser
, CPP_NAME
)
3444 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3446 *nextp
= build_tree_list (NULL_TREE
,
3447 c_parser_peek_token (parser
)->value
);
3448 nextp
= & TREE_CHAIN (*nextp
);
3449 c_parser_consume_token (parser
);
3450 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3452 c_parser_consume_token (parser
);
3453 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3455 c_parser_error (parser
, "expected identifier");
3459 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3461 struct c_arg_info
*ret
= build_arg_info ();
3463 c_parser_consume_token (parser
);
3469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3477 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3484 /* Parse a parameter list (possibly empty), including the closing
3485 parenthesis but not the opening one. ATTRS are the attributes at
3486 the start of the list. EXPR is NULL or an expression that needs to
3487 be evaluated for the side effects of array size expressions in the
3490 static struct c_arg_info
*
3491 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3493 bool bad_parm
= false;
3495 /* ??? Following the old parser, forward parameter declarations may
3496 use abstract declarators, and if no real parameter declarations
3497 follow the forward declarations then this is not diagnosed. Also
3498 note as above that attributes are ignored as the only contents of
3499 the parentheses, or as the only contents after forward
3501 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3503 struct c_arg_info
*ret
= build_arg_info ();
3504 c_parser_consume_token (parser
);
3507 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3509 struct c_arg_info
*ret
= build_arg_info ();
3511 if (flag_allow_parameterless_variadic_functions
)
3513 /* F (...) is allowed. */
3514 ret
->types
= NULL_TREE
;
3518 /* Suppress -Wold-style-definition for this case. */
3519 ret
->types
= error_mark_node
;
3520 error_at (c_parser_peek_token (parser
)->location
,
3521 "ISO C requires a named argument before %<...%>");
3523 c_parser_consume_token (parser
);
3524 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3526 c_parser_consume_token (parser
);
3531 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3536 /* Nonempty list of parameters, either terminated with semicolon
3537 (forward declarations; recurse) or with close parenthesis (normal
3538 function) or with ", ... )" (variadic function). */
3541 /* Parse a parameter. */
3542 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3547 push_parm_decl (parm
, &expr
);
3548 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3551 c_parser_consume_token (parser
);
3552 mark_forward_parm_decls ();
3553 new_attrs
= c_parser_attributes (parser
);
3554 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3556 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3558 c_parser_consume_token (parser
);
3562 return get_parm_info (false, expr
);
3564 if (!c_parser_require (parser
, CPP_COMMA
,
3565 "expected %<;%>, %<,%> or %<)%>"))
3567 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3570 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3572 c_parser_consume_token (parser
);
3573 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3575 c_parser_consume_token (parser
);
3579 return get_parm_info (true, expr
);
3583 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3591 /* Parse a parameter declaration. ATTRS are the attributes at the
3592 start of the declaration if it is the first parameter. */
3594 static struct c_parm
*
3595 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3597 struct c_declspecs
*specs
;
3598 struct c_declarator
*declarator
;
3600 tree postfix_attrs
= NULL_TREE
;
3603 /* Accept #pragmas between parameter declarations. */
3604 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3605 c_parser_pragma (parser
, pragma_param
);
3607 if (!c_parser_next_token_starts_declspecs (parser
))
3609 c_token
*token
= c_parser_peek_token (parser
);
3612 c_parser_set_source_position_from_token (token
);
3613 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3615 error_at (token
->location
, "unknown type name %qE", token
->value
);
3616 parser
->error
= true;
3618 /* ??? In some Objective-C cases '...' isn't applicable so there
3619 should be a different message. */
3621 c_parser_error (parser
,
3622 "expected declaration specifiers or %<...%>");
3623 c_parser_skip_to_end_of_parameter (parser
);
3626 specs
= build_null_declspecs ();
3629 declspecs_add_attrs (input_location
, specs
, attrs
);
3632 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3633 cla_nonabstract_decl
);
3634 finish_declspecs (specs
);
3635 pending_xref_error ();
3636 prefix_attrs
= specs
->attrs
;
3637 specs
->attrs
= NULL_TREE
;
3638 declarator
= c_parser_declarator (parser
,
3639 specs
->typespec_kind
!= ctsk_none
,
3640 C_DTR_PARM
, &dummy
);
3641 if (declarator
== NULL
)
3643 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3646 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3647 postfix_attrs
= c_parser_attributes (parser
);
3648 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3652 /* Parse a string literal in an asm expression. It should not be
3653 translated, and wide string literals are an error although
3654 permitted by the syntax. This is a GNU extension.
3659 ??? At present, following the old parser, the caller needs to have
3660 set lex_untranslated_string to 1. It would be better to follow the
3661 C++ parser rather than using this kludge. */
3664 c_parser_asm_string_literal (c_parser
*parser
)
3667 int save_flag
= warn_overlength_strings
;
3668 warn_overlength_strings
= 0;
3669 if (c_parser_next_token_is (parser
, CPP_STRING
))
3671 str
= c_parser_peek_token (parser
)->value
;
3672 c_parser_consume_token (parser
);
3674 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3676 error_at (c_parser_peek_token (parser
)->location
,
3677 "wide string literal in %<asm%>");
3678 str
= build_string (1, "");
3679 c_parser_consume_token (parser
);
3683 c_parser_error (parser
, "expected string literal");
3686 warn_overlength_strings
= save_flag
;
3690 /* Parse a simple asm expression. This is used in restricted
3691 contexts, where a full expression with inputs and outputs does not
3692 make sense. This is a GNU extension.
3695 asm ( asm-string-literal )
3699 c_parser_simple_asm_expr (c_parser
*parser
)
3702 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3703 /* ??? Follow the C++ parser rather than using the
3704 lex_untranslated_string kludge. */
3705 parser
->lex_untranslated_string
= true;
3706 c_parser_consume_token (parser
);
3707 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3709 parser
->lex_untranslated_string
= false;
3712 str
= c_parser_asm_string_literal (parser
);
3713 parser
->lex_untranslated_string
= false;
3714 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3716 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3723 c_parser_attribute_any_word (c_parser
*parser
)
3725 tree attr_name
= NULL_TREE
;
3727 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3729 /* ??? See comment above about what keywords are accepted here. */
3731 switch (c_parser_peek_token (parser
)->keyword
)
3762 case RID_TRANSACTION_ATOMIC
:
3763 case RID_TRANSACTION_CANCEL
:
3775 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3776 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3778 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3779 attr_name
= c_parser_peek_token (parser
)->value
;
3784 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3785 "__vector" or "__vector__." */
3788 is_cilkplus_vector_p (tree name
)
3790 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3795 #define CILK_SIMD_FN_CLAUSE_MASK \
3796 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3797 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3798 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3799 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3800 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3802 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3803 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3804 pushed into the token list.
3807 vector (<vector attributes>). */
3810 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3812 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3814 int paren_scope
= 0;
3815 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3816 /* Consume the "vector" token. */
3817 c_parser_consume_token (parser
);
3819 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3821 c_parser_consume_token (parser
);
3824 while (paren_scope
> 0)
3826 c_token
*token
= c_parser_peek_token (parser
);
3827 if (token
->type
== CPP_OPEN_PAREN
)
3829 else if (token
->type
== CPP_CLOSE_PAREN
)
3831 /* Do not push the last ')' since we are not pushing the '('. */
3832 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3833 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3834 c_parser_consume_token (parser
);
3837 /* Since we are converting an attribute to a pragma, we need to end the
3838 attribute with PRAGMA_EOL. */
3840 memset (&eol_token
, 0, sizeof (eol_token
));
3841 eol_token
.type
= CPP_PRAGMA_EOL
;
3842 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3845 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3848 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3850 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3852 /* c_parser_attributes is called in several places, so if these EOF
3853 tokens are already inserted, then don't do them again. */
3854 if (last_token
.type
== CPP_EOF
)
3857 /* Two CPP_EOF token are added as a safety net since the normal C
3858 front-end has two token look-ahead. */
3860 eof_token
.type
= CPP_EOF
;
3861 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3862 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3865 /* Parse (possibly empty) attributes. This is a GNU extension.
3869 attributes attribute
3872 __attribute__ ( ( attribute-list ) )
3876 attribute_list , attrib
3881 any-word ( identifier )
3882 any-word ( identifier , nonempty-expr-list )
3883 any-word ( expr-list )
3885 where the "identifier" must not be declared as a type, and
3886 "any-word" may be any identifier (including one declared as a
3887 type), a reserved word storage class specifier, type specifier or
3888 type qualifier. ??? This still leaves out most reserved keywords
3889 (following the old parser), shouldn't we include them, and why not
3890 allow identifiers declared as types to start the arguments? */
3893 c_parser_attributes (c_parser
*parser
)
3895 tree attrs
= NULL_TREE
;
3896 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3898 /* ??? Follow the C++ parser rather than using the
3899 lex_untranslated_string kludge. */
3900 parser
->lex_untranslated_string
= true;
3901 c_parser_consume_token (parser
);
3902 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3904 parser
->lex_untranslated_string
= false;
3907 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3909 parser
->lex_untranslated_string
= false;
3910 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3913 /* Parse the attribute list. */
3914 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3915 || c_parser_next_token_is (parser
, CPP_NAME
)
3916 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3918 tree attr
, attr_name
, attr_args
;
3919 vec
<tree
, va_gc
> *expr_list
;
3920 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3922 c_parser_consume_token (parser
);
3926 attr_name
= c_parser_attribute_any_word (parser
);
3927 if (attr_name
== NULL
)
3929 if (is_cilkplus_vector_p (attr_name
))
3931 c_token
*v_token
= c_parser_peek_token (parser
);
3932 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3935 c_parser_consume_token (parser
);
3936 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3938 attr
= build_tree_list (attr_name
, NULL_TREE
);
3939 attrs
= chainon (attrs
, attr
);
3942 c_parser_consume_token (parser
);
3943 /* Parse the attribute contents. If they start with an
3944 identifier which is followed by a comma or close
3945 parenthesis, then the arguments start with that
3946 identifier; otherwise they are an expression list.
3947 In objective-c the identifier may be a classname. */
3948 if (c_parser_next_token_is (parser
, CPP_NAME
)
3949 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3950 || (c_dialect_objc ()
3951 && c_parser_peek_token (parser
)->id_kind
3953 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3954 || (c_parser_peek_2nd_token (parser
)->type
3955 == CPP_CLOSE_PAREN
))
3956 && (attribute_takes_identifier_p (attr_name
)
3957 || (c_dialect_objc ()
3958 && c_parser_peek_token (parser
)->id_kind
3959 == C_ID_CLASSNAME
)))
3961 tree arg1
= c_parser_peek_token (parser
)->value
;
3962 c_parser_consume_token (parser
);
3963 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3964 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3968 c_parser_consume_token (parser
);
3969 expr_list
= c_parser_expr_list (parser
, false, true,
3970 NULL
, NULL
, NULL
, NULL
);
3971 tree_list
= build_tree_list_vec (expr_list
);
3972 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3973 release_tree_vector (expr_list
);
3978 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3979 attr_args
= NULL_TREE
;
3982 expr_list
= c_parser_expr_list (parser
, false, true,
3983 NULL
, NULL
, NULL
, NULL
);
3984 attr_args
= build_tree_list_vec (expr_list
);
3985 release_tree_vector (expr_list
);
3988 attr
= build_tree_list (attr_name
, attr_args
);
3989 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3990 c_parser_consume_token (parser
);
3993 parser
->lex_untranslated_string
= false;
3994 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3998 attrs
= chainon (attrs
, attr
);
4000 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4001 c_parser_consume_token (parser
);
4004 parser
->lex_untranslated_string
= false;
4005 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4009 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4010 c_parser_consume_token (parser
);
4013 parser
->lex_untranslated_string
= false;
4014 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4018 parser
->lex_untranslated_string
= false;
4021 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4022 c_finish_cilk_simd_fn_tokens (parser
);
4026 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4029 specifier-qualifier-list abstract-declarator[opt]
4032 static struct c_type_name
*
4033 c_parser_type_name (c_parser
*parser
)
4035 struct c_declspecs
*specs
= build_null_declspecs ();
4036 struct c_declarator
*declarator
;
4037 struct c_type_name
*ret
;
4039 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4041 if (!specs
->declspecs_seen_p
)
4043 c_parser_error (parser
, "expected specifier-qualifier-list");
4046 if (specs
->type
!= error_mark_node
)
4048 pending_xref_error ();
4049 finish_declspecs (specs
);
4051 declarator
= c_parser_declarator (parser
,
4052 specs
->typespec_kind
!= ctsk_none
,
4053 C_DTR_ABSTRACT
, &dummy
);
4054 if (declarator
== NULL
)
4056 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4058 ret
->declarator
= declarator
;
4062 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4065 assignment-expression
4066 { initializer-list }
4067 { initializer-list , }
4070 designation[opt] initializer
4071 initializer-list , designation[opt] initializer
4078 designator-list designator
4085 [ constant-expression ]
4097 [ constant-expression ... constant-expression ]
4099 Any expression without commas is accepted in the syntax for the
4100 constant-expressions, with non-constant expressions rejected later.
4102 This function is only used for top-level initializers; for nested
4103 ones, see c_parser_initval. */
4105 static struct c_expr
4106 c_parser_initializer (c_parser
*parser
)
4108 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4109 return c_parser_braced_init (parser
, NULL_TREE
, false);
4113 location_t loc
= c_parser_peek_token (parser
)->location
;
4114 ret
= c_parser_expr_no_commas (parser
, NULL
);
4115 if (TREE_CODE (ret
.value
) != STRING_CST
4116 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4117 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4122 /* Parse a braced initializer list. TYPE is the type specified for a
4123 compound literal, and NULL_TREE for other initializers and for
4124 nested braced lists. NESTED_P is true for nested braced lists,
4125 false for the list of a compound literal or the list that is the
4126 top-level initializer in a declaration. */
4128 static struct c_expr
4129 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4132 struct obstack braced_init_obstack
;
4133 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4134 gcc_obstack_init (&braced_init_obstack
);
4135 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4136 c_parser_consume_token (parser
);
4138 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4140 really_start_incremental_init (type
);
4141 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4143 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4147 /* Parse a non-empty initializer list, possibly with a trailing
4151 c_parser_initelt (parser
, &braced_init_obstack
);
4154 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4155 c_parser_consume_token (parser
);
4158 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4162 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4164 ret
.value
= error_mark_node
;
4165 ret
.original_code
= ERROR_MARK
;
4166 ret
.original_type
= NULL
;
4167 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4168 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4169 obstack_free (&braced_init_obstack
, NULL
);
4172 c_parser_consume_token (parser
);
4173 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4174 obstack_free (&braced_init_obstack
, NULL
);
4178 /* Parse a nested initializer, including designators. */
4181 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4183 /* Parse any designator or designator list. A single array
4184 designator may have the subsequent "=" omitted in GNU C, but a
4185 longer list or a structure member designator may not. */
4186 if (c_parser_next_token_is (parser
, CPP_NAME
)
4187 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4189 /* Old-style structure member designator. */
4190 set_init_label (c_parser_peek_token (parser
)->location
,
4191 c_parser_peek_token (parser
)->value
,
4192 braced_init_obstack
);
4193 /* Use the colon as the error location. */
4194 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4195 "obsolete use of designated initializer with %<:%>");
4196 c_parser_consume_token (parser
);
4197 c_parser_consume_token (parser
);
4201 /* des_seen is 0 if there have been no designators, 1 if there
4202 has been a single array designator and 2 otherwise. */
4204 /* Location of a designator. */
4205 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4206 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4207 || c_parser_next_token_is (parser
, CPP_DOT
))
4209 int des_prev
= des_seen
;
4211 des_loc
= c_parser_peek_token (parser
)->location
;
4214 if (c_parser_next_token_is (parser
, CPP_DOT
))
4217 c_parser_consume_token (parser
);
4218 if (c_parser_next_token_is (parser
, CPP_NAME
))
4220 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4221 braced_init_obstack
);
4222 c_parser_consume_token (parser
);
4227 init
.value
= error_mark_node
;
4228 init
.original_code
= ERROR_MARK
;
4229 init
.original_type
= NULL
;
4230 c_parser_error (parser
, "expected identifier");
4231 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4232 process_init_element (input_location
, init
, false,
4233 braced_init_obstack
);
4240 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4241 location_t array_index_loc
= UNKNOWN_LOCATION
;
4242 /* ??? Following the old parser, [ objc-receiver
4243 objc-message-args ] is accepted as an initializer,
4244 being distinguished from a designator by what follows
4245 the first assignment expression inside the square
4246 brackets, but after a first array designator a
4247 subsequent square bracket is for Objective-C taken to
4248 start an expression, using the obsolete form of
4249 designated initializer without '=', rather than
4250 possibly being a second level of designation: in LALR
4251 terms, the '[' is shifted rather than reducing
4252 designator to designator-list. */
4253 if (des_prev
== 1 && c_dialect_objc ())
4255 des_seen
= des_prev
;
4258 if (des_prev
== 0 && c_dialect_objc ())
4260 /* This might be an array designator or an
4261 Objective-C message expression. If the former,
4262 continue parsing here; if the latter, parse the
4263 remainder of the initializer given the starting
4264 primary-expression. ??? It might make sense to
4265 distinguish when des_prev == 1 as well; see
4266 previous comment. */
4268 struct c_expr mexpr
;
4269 c_parser_consume_token (parser
);
4270 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4271 && ((c_parser_peek_token (parser
)->id_kind
4273 || (c_parser_peek_token (parser
)->id_kind
4274 == C_ID_CLASSNAME
)))
4276 /* Type name receiver. */
4277 tree id
= c_parser_peek_token (parser
)->value
;
4278 c_parser_consume_token (parser
);
4279 rec
= objc_get_class_reference (id
);
4280 goto parse_message_args
;
4282 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4283 mark_exp_read (first
);
4284 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4285 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4286 goto array_desig_after_first
;
4287 /* Expression receiver. So far only one part
4288 without commas has been parsed; there might be
4289 more of the expression. */
4291 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4294 location_t comma_loc
, exp_loc
;
4295 comma_loc
= c_parser_peek_token (parser
)->location
;
4296 c_parser_consume_token (parser
);
4297 exp_loc
= c_parser_peek_token (parser
)->location
;
4298 next
= c_parser_expr_no_commas (parser
, NULL
);
4299 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4301 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4304 /* Now parse the objc-message-args. */
4305 args
= c_parser_objc_message_args (parser
);
4306 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4309 = objc_build_message_expr (rec
, args
);
4310 mexpr
.original_code
= ERROR_MARK
;
4311 mexpr
.original_type
= NULL
;
4312 /* Now parse and process the remainder of the
4313 initializer, starting with this message
4314 expression as a primary-expression. */
4315 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4318 c_parser_consume_token (parser
);
4319 array_index_loc
= c_parser_peek_token (parser
)->location
;
4320 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4321 mark_exp_read (first
);
4322 array_desig_after_first
:
4323 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4325 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4326 c_parser_consume_token (parser
);
4327 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4328 mark_exp_read (second
);
4332 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4334 c_parser_consume_token (parser
);
4335 set_init_index (array_index_loc
, first
, second
,
4336 braced_init_obstack
);
4338 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4339 "ISO C forbids specifying range of elements to initialize");
4342 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4348 if (c_parser_next_token_is (parser
, CPP_EQ
))
4351 pedwarn (des_loc
, OPT_Wpedantic
,
4352 "ISO C90 forbids specifying subobject to initialize");
4353 c_parser_consume_token (parser
);
4358 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4359 "obsolete use of designated initializer without %<=%>");
4363 init
.value
= error_mark_node
;
4364 init
.original_code
= ERROR_MARK
;
4365 init
.original_type
= NULL
;
4366 c_parser_error (parser
, "expected %<=%>");
4367 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4368 process_init_element (input_location
, init
, false,
4369 braced_init_obstack
);
4375 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4378 /* Parse a nested initializer; as c_parser_initializer but parses
4379 initializers within braced lists, after any designators have been
4380 applied. If AFTER is not NULL then it is an Objective-C message
4381 expression which is the primary-expression starting the
4385 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4386 struct obstack
* braced_init_obstack
)
4389 gcc_assert (!after
|| c_dialect_objc ());
4390 location_t loc
= c_parser_peek_token (parser
)->location
;
4392 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4393 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4396 init
= c_parser_expr_no_commas (parser
, after
);
4397 if (init
.value
!= NULL_TREE
4398 && TREE_CODE (init
.value
) != STRING_CST
4399 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4400 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4402 process_init_element (loc
, init
, false, braced_init_obstack
);
4405 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4409 { block-item-list[opt] }
4410 { label-declarations block-item-list }
4414 block-item-list block-item
4426 { label-declarations block-item-list }
4429 __extension__ nested-declaration
4430 nested-function-definition
4434 label-declarations label-declaration
4437 __label__ identifier-list ;
4439 Allowing the mixing of declarations and code is new in C99. The
4440 GNU syntax also permits (not shown above) labels at the end of
4441 compound statements, which yield an error. We don't allow labels
4442 on declarations; this might seem like a natural extension, but
4443 there would be a conflict between attributes on the label and
4444 prefix attributes on the declaration. ??? The syntax follows the
4445 old parser in requiring something after label declarations.
4446 Although they are erroneous if the labels declared aren't defined,
4447 is it useful for the syntax to be this way?
4460 cancellation-point-directive */
4463 c_parser_compound_statement (c_parser
*parser
)
4466 location_t brace_loc
;
4467 brace_loc
= c_parser_peek_token (parser
)->location
;
4468 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4470 /* Ensure a scope is entered and left anyway to avoid confusion
4471 if we have just prepared to enter a function body. */
4472 stmt
= c_begin_compound_stmt (true);
4473 c_end_compound_stmt (brace_loc
, stmt
, true);
4474 return error_mark_node
;
4476 stmt
= c_begin_compound_stmt (true);
4477 c_parser_compound_statement_nostart (parser
);
4479 /* If the compound stmt contains array notations, then we expand them. */
4480 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4481 stmt
= expand_array_notation_exprs (stmt
);
4482 return c_end_compound_stmt (brace_loc
, stmt
, true);
4485 /* Parse a compound statement except for the opening brace. This is
4486 used for parsing both compound statements and statement expressions
4487 (which follow different paths to handling the opening). */
4490 c_parser_compound_statement_nostart (c_parser
*parser
)
4492 bool last_stmt
= false;
4493 bool last_label
= false;
4494 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4495 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4496 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4498 c_parser_consume_token (parser
);
4501 mark_valid_location_for_stdc_pragma (true);
4502 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4504 /* Read zero or more forward-declarations for labels that nested
4505 functions can jump to. */
4506 mark_valid_location_for_stdc_pragma (false);
4507 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4509 label_loc
= c_parser_peek_token (parser
)->location
;
4510 c_parser_consume_token (parser
);
4511 /* Any identifiers, including those declared as type names,
4516 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4518 c_parser_error (parser
, "expected identifier");
4522 = declare_label (c_parser_peek_token (parser
)->value
);
4523 C_DECLARED_LABEL_FLAG (label
) = 1;
4524 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4525 c_parser_consume_token (parser
);
4526 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4527 c_parser_consume_token (parser
);
4531 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4533 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4535 /* We must now have at least one statement, label or declaration. */
4536 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4538 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4539 c_parser_error (parser
, "expected declaration or statement");
4540 c_parser_consume_token (parser
);
4543 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4545 location_t loc
= c_parser_peek_token (parser
)->location
;
4546 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4547 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4548 || (c_parser_next_token_is (parser
, CPP_NAME
)
4549 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4551 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4552 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4554 label_loc
= c_parser_peek_token (parser
)->location
;
4557 mark_valid_location_for_stdc_pragma (false);
4558 c_parser_label (parser
);
4560 else if (!last_label
4561 && c_parser_next_tokens_start_declaration (parser
))
4564 mark_valid_location_for_stdc_pragma (false);
4565 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4569 (pedantic
&& !flag_isoc99
)
4571 : OPT_Wdeclaration_after_statement
,
4572 "ISO C90 forbids mixed declarations and code");
4575 else if (!last_label
4576 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4578 /* __extension__ can start a declaration, but is also an
4579 unary operator that can start an expression. Consume all
4580 but the last of a possible series of __extension__ to
4582 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4583 && (c_parser_peek_2nd_token (parser
)->keyword
4585 c_parser_consume_token (parser
);
4586 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4589 ext
= disable_extension_diagnostics ();
4590 c_parser_consume_token (parser
);
4592 mark_valid_location_for_stdc_pragma (false);
4593 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4595 /* Following the old parser, __extension__ does not
4596 disable this diagnostic. */
4597 restore_extension_diagnostics (ext
);
4599 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4601 : OPT_Wdeclaration_after_statement
,
4602 "ISO C90 forbids mixed declarations and code");
4608 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4610 /* External pragmas, and some omp pragmas, are not associated
4611 with regular c code, and so are not to be considered statements
4612 syntactically. This ensures that the user doesn't put them
4613 places that would turn into syntax errors if the directive
4615 if (c_parser_pragma (parser
, pragma_compound
))
4616 last_label
= false, last_stmt
= true;
4618 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4620 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4621 c_parser_error (parser
, "expected declaration or statement");
4624 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4626 if (parser
->in_if_block
)
4628 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4629 error_at (loc
, """expected %<}%> before %<else%>");
4634 error_at (loc
, "%<else%> without a previous %<if%>");
4635 c_parser_consume_token (parser
);
4644 mark_valid_location_for_stdc_pragma (false);
4645 c_parser_statement_after_labels (parser
);
4648 parser
->error
= false;
4651 error_at (label_loc
, "label at end of compound statement");
4652 c_parser_consume_token (parser
);
4653 /* Restore the value we started with. */
4654 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4657 /* Parse a label (C90 6.6.1, C99 6.8.1).
4660 identifier : attributes[opt]
4661 case constant-expression :
4667 case constant-expression ... constant-expression :
4669 The use of attributes on labels is a GNU extension. The syntax in
4670 GNU C accepts any expressions without commas, non-constant
4671 expressions being rejected later. */
4674 c_parser_label (c_parser
*parser
)
4676 location_t loc1
= c_parser_peek_token (parser
)->location
;
4677 tree label
= NULL_TREE
;
4678 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4681 c_parser_consume_token (parser
);
4682 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4683 if (c_parser_next_token_is (parser
, CPP_COLON
))
4685 c_parser_consume_token (parser
);
4686 label
= do_case (loc1
, exp1
, NULL_TREE
);
4688 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4690 c_parser_consume_token (parser
);
4691 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4692 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4693 label
= do_case (loc1
, exp1
, exp2
);
4696 c_parser_error (parser
, "expected %<:%> or %<...%>");
4698 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4700 c_parser_consume_token (parser
);
4701 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4702 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4706 tree name
= c_parser_peek_token (parser
)->value
;
4709 location_t loc2
= c_parser_peek_token (parser
)->location
;
4710 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4711 c_parser_consume_token (parser
);
4712 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4713 c_parser_consume_token (parser
);
4714 attrs
= c_parser_attributes (parser
);
4715 tlab
= define_label (loc2
, name
);
4718 decl_attributes (&tlab
, attrs
, 0);
4719 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4724 if (c_parser_next_tokens_start_declaration (parser
))
4726 error_at (c_parser_peek_token (parser
)->location
,
4727 "a label can only be part of a statement and "
4728 "a declaration is not a statement");
4729 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4730 /*static_assert_ok*/ true,
4731 /*empty_ok*/ true, /*nested*/ true,
4732 /*start_attr_ok*/ true, NULL
,
4738 /* Parse a statement (C90 6.6, C99 6.8).
4743 expression-statement
4751 expression-statement:
4754 selection-statement:
4758 iteration-statement:
4767 return expression[opt] ;
4780 objc-throw-statement
4781 objc-try-catch-statement
4782 objc-synchronized-statement
4784 objc-throw-statement:
4800 parallel-for-construct
4801 parallel-for-simd-construct
4802 parallel-sections-construct
4809 parallel-directive structured-block
4812 for-directive iteration-statement
4815 simd-directive iteration-statements
4818 for-simd-directive iteration-statements
4821 sections-directive section-scope
4824 single-directive structured-block
4826 parallel-for-construct:
4827 parallel-for-directive iteration-statement
4829 parallel-for-simd-construct:
4830 parallel-for-simd-directive iteration-statement
4832 parallel-sections-construct:
4833 parallel-sections-directive section-scope
4836 master-directive structured-block
4839 critical-directive structured-block
4842 atomic-directive expression-statement
4845 ordered-directive structured-block
4847 Transactional Memory:
4850 transaction-statement
4851 transaction-cancel-statement
4855 c_parser_statement (c_parser
*parser
)
4857 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4858 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4859 || (c_parser_next_token_is (parser
, CPP_NAME
)
4860 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4861 c_parser_label (parser
);
4862 c_parser_statement_after_labels (parser
);
4865 /* Parse a statement, other than a labeled statement. */
4868 c_parser_statement_after_labels (c_parser
*parser
)
4870 location_t loc
= c_parser_peek_token (parser
)->location
;
4871 tree stmt
= NULL_TREE
;
4872 bool in_if_block
= parser
->in_if_block
;
4873 parser
->in_if_block
= false;
4874 switch (c_parser_peek_token (parser
)->type
)
4876 case CPP_OPEN_BRACE
:
4877 add_stmt (c_parser_compound_statement (parser
));
4880 switch (c_parser_peek_token (parser
)->keyword
)
4883 c_parser_if_statement (parser
);
4886 c_parser_switch_statement (parser
);
4889 c_parser_while_statement (parser
, false);
4892 c_parser_do_statement (parser
, false);
4895 c_parser_for_statement (parser
, false);
4898 c_parser_consume_token (parser
);
4899 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4901 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4903 add_stmt (build_cilk_sync ());
4906 c_parser_consume_token (parser
);
4907 if (c_parser_next_token_is (parser
, CPP_NAME
))
4909 stmt
= c_finish_goto_label (loc
,
4910 c_parser_peek_token (parser
)->value
);
4911 c_parser_consume_token (parser
);
4913 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4917 c_parser_consume_token (parser
);
4918 val
= c_parser_expression (parser
);
4919 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4920 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4923 c_parser_error (parser
, "expected identifier or %<*%>");
4924 goto expect_semicolon
;
4926 c_parser_consume_token (parser
);
4927 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4928 goto expect_semicolon
;
4930 c_parser_consume_token (parser
);
4931 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4932 goto expect_semicolon
;
4934 c_parser_consume_token (parser
);
4935 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4937 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4938 c_parser_consume_token (parser
);
4942 location_t xloc
= c_parser_peek_token (parser
)->location
;
4943 struct c_expr expr
= c_parser_expression_conv (parser
);
4944 mark_exp_read (expr
.value
);
4945 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
4946 goto expect_semicolon
;
4950 stmt
= c_parser_asm_statement (parser
);
4952 case RID_TRANSACTION_ATOMIC
:
4953 case RID_TRANSACTION_RELAXED
:
4954 stmt
= c_parser_transaction (parser
,
4955 c_parser_peek_token (parser
)->keyword
);
4957 case RID_TRANSACTION_CANCEL
:
4958 stmt
= c_parser_transaction_cancel (parser
);
4959 goto expect_semicolon
;
4961 gcc_assert (c_dialect_objc ());
4962 c_parser_consume_token (parser
);
4963 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4965 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4966 c_parser_consume_token (parser
);
4970 struct c_expr expr
= c_parser_expression (parser
);
4971 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
4972 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4973 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
4974 goto expect_semicolon
;
4978 gcc_assert (c_dialect_objc ());
4979 c_parser_objc_try_catch_finally_statement (parser
);
4981 case RID_AT_SYNCHRONIZED
:
4982 gcc_assert (c_dialect_objc ());
4983 c_parser_objc_synchronized_statement (parser
);
4990 c_parser_consume_token (parser
);
4992 case CPP_CLOSE_PAREN
:
4993 case CPP_CLOSE_SQUARE
:
4994 /* Avoid infinite loop in error recovery:
4995 c_parser_skip_until_found stops at a closing nesting
4996 delimiter without consuming it, but here we need to consume
4997 it to proceed further. */
4998 c_parser_error (parser
, "expected statement");
4999 c_parser_consume_token (parser
);
5002 c_parser_pragma (parser
, pragma_stmt
);
5006 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5008 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5011 /* Two cases cannot and do not have line numbers associated: If stmt
5012 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5013 cannot hold line numbers. But that's OK because the statement
5014 will either be changed to a MODIFY_EXPR during gimplification of
5015 the statement expr, or discarded. If stmt was compound, but
5016 without new variables, we will have skipped the creation of a
5017 BIND and will have a bare STATEMENT_LIST. But that's OK because
5018 (recursively) all of the component statements should already have
5019 line numbers assigned. ??? Can we discard no-op statements
5021 if (CAN_HAVE_LOCATION_P (stmt
)
5022 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5023 SET_EXPR_LOCATION (stmt
, loc
);
5025 parser
->in_if_block
= in_if_block
;
5028 /* Parse the condition from an if, do, while or for statements. */
5031 c_parser_condition (c_parser
*parser
)
5033 location_t loc
= c_parser_peek_token (parser
)->location
;
5035 cond
= c_parser_expression_conv (parser
).value
;
5036 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5037 cond
= c_fully_fold (cond
, false, NULL
);
5038 if (warn_sequence_point
)
5039 verify_sequence_points (cond
);
5043 /* Parse a parenthesized condition from an if, do or while statement.
5049 c_parser_paren_condition (c_parser
*parser
)
5052 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5053 return error_mark_node
;
5054 cond
= c_parser_condition (parser
);
5055 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5059 /* Parse a statement which is a block in C99. */
5062 c_parser_c99_block_statement (c_parser
*parser
)
5064 tree block
= c_begin_compound_stmt (flag_isoc99
);
5065 location_t loc
= c_parser_peek_token (parser
)->location
;
5066 c_parser_statement (parser
);
5067 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5070 /* Parse the body of an if statement. This is just parsing a
5071 statement but (a) it is a block in C99, (b) we track whether the
5072 body is an if statement for the sake of -Wparentheses warnings, (c)
5073 we handle an empty body specially for the sake of -Wempty-body
5074 warnings, and (d) we call parser_compound_statement directly
5075 because c_parser_statement_after_labels resets
5076 parser->in_if_block. */
5079 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5081 tree block
= c_begin_compound_stmt (flag_isoc99
);
5082 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5083 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5084 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5085 || (c_parser_next_token_is (parser
, CPP_NAME
)
5086 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5087 c_parser_label (parser
);
5088 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5089 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5091 location_t loc
= c_parser_peek_token (parser
)->location
;
5092 add_stmt (build_empty_stmt (loc
));
5093 c_parser_consume_token (parser
);
5094 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5095 warning_at (loc
, OPT_Wempty_body
,
5096 "suggest braces around empty body in an %<if%> statement");
5098 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5099 add_stmt (c_parser_compound_statement (parser
));
5101 c_parser_statement_after_labels (parser
);
5102 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5105 /* Parse the else body of an if statement. This is just parsing a
5106 statement but (a) it is a block in C99, (b) we handle an empty body
5107 specially for the sake of -Wempty-body warnings. */
5110 c_parser_else_body (c_parser
*parser
)
5112 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5113 tree block
= c_begin_compound_stmt (flag_isoc99
);
5114 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5115 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5116 || (c_parser_next_token_is (parser
, CPP_NAME
)
5117 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5118 c_parser_label (parser
);
5119 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5121 location_t loc
= c_parser_peek_token (parser
)->location
;
5124 "suggest braces around empty body in an %<else%> statement");
5125 add_stmt (build_empty_stmt (loc
));
5126 c_parser_consume_token (parser
);
5129 c_parser_statement_after_labels (parser
);
5130 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5133 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5136 if ( expression ) statement
5137 if ( expression ) statement else statement
5141 c_parser_if_statement (c_parser
*parser
)
5146 bool first_if
= false;
5147 tree first_body
, second_body
;
5151 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5152 c_parser_consume_token (parser
);
5153 block
= c_begin_compound_stmt (flag_isoc99
);
5154 loc
= c_parser_peek_token (parser
)->location
;
5155 cond
= c_parser_paren_condition (parser
);
5156 in_if_block
= parser
->in_if_block
;
5157 parser
->in_if_block
= true;
5158 first_body
= c_parser_if_body (parser
, &first_if
);
5159 parser
->in_if_block
= in_if_block
;
5160 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5162 c_parser_consume_token (parser
);
5163 second_body
= c_parser_else_body (parser
);
5166 second_body
= NULL_TREE
;
5167 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5168 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5170 /* If the if statement contains array notations, then we expand them. */
5171 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5172 if_stmt
= fix_conditional_array_notations (if_stmt
);
5176 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5179 switch (expression) statement
5183 c_parser_switch_statement (c_parser
*parser
)
5186 tree block
, expr
, body
, save_break
;
5187 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5188 location_t switch_cond_loc
;
5189 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5190 c_parser_consume_token (parser
);
5191 block
= c_begin_compound_stmt (flag_isoc99
);
5192 bool explicit_cast_p
= false;
5193 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5195 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5196 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5197 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5198 explicit_cast_p
= true;
5199 ce
= c_parser_expression (parser
);
5200 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5202 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5204 error_at (switch_cond_loc
,
5205 "array notations cannot be used as a condition for switch "
5207 expr
= error_mark_node
;
5209 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5213 switch_cond_loc
= UNKNOWN_LOCATION
;
5214 expr
= error_mark_node
;
5216 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5217 save_break
= c_break_label
;
5218 c_break_label
= NULL_TREE
;
5219 body
= c_parser_c99_block_statement (parser
);
5220 c_finish_case (body
);
5223 location_t here
= c_parser_peek_token (parser
)->location
;
5224 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5225 SET_EXPR_LOCATION (t
, here
);
5228 c_break_label
= save_break
;
5229 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5232 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5235 while (expression) statement
5239 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5241 tree block
, cond
, body
, save_break
, save_cont
;
5243 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5244 c_parser_consume_token (parser
);
5245 block
= c_begin_compound_stmt (flag_isoc99
);
5246 loc
= c_parser_peek_token (parser
)->location
;
5247 cond
= c_parser_paren_condition (parser
);
5248 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5250 error_at (loc
, "array notations cannot be used as a condition for while "
5252 cond
= error_mark_node
;
5255 if (ivdep
&& cond
!= error_mark_node
)
5256 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5257 build_int_cst (integer_type_node
,
5258 annot_expr_ivdep_kind
));
5259 save_break
= c_break_label
;
5260 c_break_label
= NULL_TREE
;
5261 save_cont
= c_cont_label
;
5262 c_cont_label
= NULL_TREE
;
5263 body
= c_parser_c99_block_statement (parser
);
5264 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5265 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5266 c_break_label
= save_break
;
5267 c_cont_label
= save_cont
;
5270 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5273 do statement while ( expression ) ;
5277 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5279 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5281 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5282 c_parser_consume_token (parser
);
5283 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5284 warning_at (c_parser_peek_token (parser
)->location
,
5286 "suggest braces around empty body in %<do%> statement");
5287 block
= c_begin_compound_stmt (flag_isoc99
);
5288 loc
= c_parser_peek_token (parser
)->location
;
5289 save_break
= c_break_label
;
5290 c_break_label
= NULL_TREE
;
5291 save_cont
= c_cont_label
;
5292 c_cont_label
= NULL_TREE
;
5293 body
= c_parser_c99_block_statement (parser
);
5294 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5295 new_break
= c_break_label
;
5296 c_break_label
= save_break
;
5297 new_cont
= c_cont_label
;
5298 c_cont_label
= save_cont
;
5299 cond
= c_parser_paren_condition (parser
);
5300 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5302 error_at (loc
, "array notations cannot be used as a condition for a "
5303 "do-while statement");
5304 cond
= error_mark_node
;
5306 if (ivdep
&& cond
!= error_mark_node
)
5307 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5308 build_int_cst (integer_type_node
,
5309 annot_expr_ivdep_kind
));
5310 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5311 c_parser_skip_to_end_of_block_or_statement (parser
);
5312 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5313 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5316 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5319 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5320 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5322 The form with a declaration is new in C99.
5324 ??? In accordance with the old parser, the declaration may be a
5325 nested function, which is then rejected in check_for_loop_decls,
5326 but does it make any sense for this to be included in the grammar?
5327 Note in particular that the nested function does not include a
5328 trailing ';', whereas the "declaration" production includes one.
5329 Also, can we reject bad declarations earlier and cheaper than
5330 check_for_loop_decls?
5332 In Objective-C, there are two additional variants:
5335 for ( expression in expresssion ) statement
5336 for ( declaration in expression ) statement
5338 This is inconsistent with C, because the second variant is allowed
5339 even if c99 is not enabled.
5341 The rest of the comment documents these Objective-C foreach-statement.
5343 Here is the canonical example of the first variant:
5344 for (object in array) { do something with object }
5345 we call the first expression ("object") the "object_expression" and
5346 the second expression ("array") the "collection_expression".
5347 object_expression must be an lvalue of type "id" (a generic Objective-C
5348 object) because the loop works by assigning to object_expression the
5349 various objects from the collection_expression. collection_expression
5350 must evaluate to something of type "id" which responds to the method
5351 countByEnumeratingWithState:objects:count:.
5353 The canonical example of the second variant is:
5354 for (id object in array) { do something with object }
5355 which is completely equivalent to
5358 for (object in array) { do something with object }
5360 Note that initizializing 'object' in some way (eg, "for ((object =
5361 xxx) in array) { do something with object }") is possibly
5362 technically valid, but completely pointless as 'object' will be
5363 assigned to something else as soon as the loop starts. We should
5364 most likely reject it (TODO).
5366 The beginning of the Objective-C foreach-statement looks exactly
5367 like the beginning of the for-statement, and we can tell it is a
5368 foreach-statement only because the initial declaration or
5369 expression is terminated by 'in' instead of ';'.
5373 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5375 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5376 /* The following are only used when parsing an ObjC foreach statement. */
5377 tree object_expression
;
5378 /* Silence the bogus uninitialized warning. */
5379 tree collection_expression
= NULL
;
5380 location_t loc
= c_parser_peek_token (parser
)->location
;
5381 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5382 bool is_foreach_statement
= false;
5383 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5384 c_parser_consume_token (parser
);
5385 /* Open a compound statement in Objective-C as well, just in case this is
5386 as foreach expression. */
5387 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5388 cond
= error_mark_node
;
5389 incr
= error_mark_node
;
5390 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5392 /* Parse the initialization declaration or expression. */
5393 object_expression
= error_mark_node
;
5394 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5395 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5397 parser
->objc_could_be_foreach_context
= false;
5398 c_parser_consume_token (parser
);
5399 c_finish_expr_stmt (loc
, NULL_TREE
);
5401 else if (c_parser_next_tokens_start_declaration (parser
))
5403 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5404 &object_expression
, vNULL
);
5405 parser
->objc_could_be_foreach_context
= false;
5407 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5409 c_parser_consume_token (parser
);
5410 is_foreach_statement
= true;
5411 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5412 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5415 check_for_loop_decls (for_loc
, flag_isoc99
);
5417 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5419 /* __extension__ can start a declaration, but is also an
5420 unary operator that can start an expression. Consume all
5421 but the last of a possible series of __extension__ to
5423 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5424 && (c_parser_peek_2nd_token (parser
)->keyword
5426 c_parser_consume_token (parser
);
5427 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5430 ext
= disable_extension_diagnostics ();
5431 c_parser_consume_token (parser
);
5432 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5433 true, &object_expression
, vNULL
);
5434 parser
->objc_could_be_foreach_context
= false;
5436 restore_extension_diagnostics (ext
);
5437 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5439 c_parser_consume_token (parser
);
5440 is_foreach_statement
= true;
5441 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5442 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5445 check_for_loop_decls (for_loc
, flag_isoc99
);
5455 tree init_expression
;
5456 ce
= c_parser_expression (parser
);
5457 init_expression
= ce
.value
;
5458 parser
->objc_could_be_foreach_context
= false;
5459 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5461 c_parser_consume_token (parser
);
5462 is_foreach_statement
= true;
5463 if (! lvalue_p (init_expression
))
5464 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5465 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5469 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5470 init_expression
= ce
.value
;
5471 c_finish_expr_stmt (loc
, init_expression
);
5472 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5476 /* Parse the loop condition. In the case of a foreach
5477 statement, there is no loop condition. */
5478 gcc_assert (!parser
->objc_could_be_foreach_context
);
5479 if (!is_foreach_statement
)
5481 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5485 c_parser_error (parser
, "missing loop condition in loop with "
5486 "%<GCC ivdep%> pragma");
5487 cond
= error_mark_node
;
5491 c_parser_consume_token (parser
);
5497 cond
= c_parser_condition (parser
);
5498 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5500 error_at (loc
, "array notations cannot be used in a "
5501 "condition for a for-loop");
5502 cond
= error_mark_node
;
5504 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5507 if (ivdep
&& cond
!= error_mark_node
)
5508 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5509 build_int_cst (integer_type_node
,
5510 annot_expr_ivdep_kind
));
5512 /* Parse the increment expression (the third expression in a
5513 for-statement). In the case of a foreach-statement, this is
5514 the expression that follows the 'in'. */
5515 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5517 if (is_foreach_statement
)
5519 c_parser_error (parser
, "missing collection in fast enumeration");
5520 collection_expression
= error_mark_node
;
5523 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5527 if (is_foreach_statement
)
5528 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5532 struct c_expr ce
= c_parser_expression (parser
);
5533 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5534 incr
= c_process_expr_stmt (loc
, ce
.value
);
5537 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5539 save_break
= c_break_label
;
5540 c_break_label
= NULL_TREE
;
5541 save_cont
= c_cont_label
;
5542 c_cont_label
= NULL_TREE
;
5543 body
= c_parser_c99_block_statement (parser
);
5544 if (is_foreach_statement
)
5545 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5547 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5548 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5549 c_break_label
= save_break
;
5550 c_cont_label
= save_cont
;
5553 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5554 statement with inputs, outputs, clobbers, and volatile tag
5558 asm type-qualifier[opt] ( asm-argument ) ;
5559 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5563 asm-string-literal : asm-operands[opt]
5564 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5565 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5568 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5571 Qualifiers other than volatile are accepted in the syntax but
5575 c_parser_asm_statement (c_parser
*parser
)
5577 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5578 bool simple
, is_goto
;
5579 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5580 int section
, nsections
;
5582 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5583 c_parser_consume_token (parser
);
5584 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5586 quals
= c_parser_peek_token (parser
)->value
;
5587 c_parser_consume_token (parser
);
5589 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5590 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5592 warning_at (c_parser_peek_token (parser
)->location
,
5594 "%E qualifier ignored on asm",
5595 c_parser_peek_token (parser
)->value
);
5597 c_parser_consume_token (parser
);
5603 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5605 c_parser_consume_token (parser
);
5609 /* ??? Follow the C++ parser rather than using the
5610 lex_untranslated_string kludge. */
5611 parser
->lex_untranslated_string
= true;
5614 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5617 str
= c_parser_asm_string_literal (parser
);
5618 if (str
== NULL_TREE
)
5619 goto error_close_paren
;
5622 outputs
= NULL_TREE
;
5624 clobbers
= NULL_TREE
;
5627 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5630 /* Parse each colon-delimited section of operands. */
5631 nsections
= 3 + is_goto
;
5632 for (section
= 0; section
< nsections
; ++section
)
5634 if (!c_parser_require (parser
, CPP_COLON
,
5637 : "expected %<:%> or %<)%>"))
5638 goto error_close_paren
;
5640 /* Once past any colon, we're no longer a simple asm. */
5643 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5644 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5649 /* For asm goto, we don't allow output operands, but reserve
5650 the slot for a future extension that does allow them. */
5652 outputs
= c_parser_asm_operands (parser
);
5655 inputs
= c_parser_asm_operands (parser
);
5658 clobbers
= c_parser_asm_clobbers (parser
);
5661 labels
= c_parser_asm_goto_operands (parser
);
5667 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5672 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5674 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5678 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5679 c_parser_skip_to_end_of_block_or_statement (parser
);
5681 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5682 clobbers
, labels
, simple
));
5685 parser
->lex_untranslated_string
= false;
5689 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5693 /* Parse asm operands, a GNU extension.
5697 asm-operands , asm-operand
5700 asm-string-literal ( expression )
5701 [ identifier ] asm-string-literal ( expression )
5705 c_parser_asm_operands (c_parser
*parser
)
5707 tree list
= NULL_TREE
;
5712 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5714 c_parser_consume_token (parser
);
5715 if (c_parser_next_token_is (parser
, CPP_NAME
))
5717 tree id
= c_parser_peek_token (parser
)->value
;
5718 c_parser_consume_token (parser
);
5719 name
= build_string (IDENTIFIER_LENGTH (id
),
5720 IDENTIFIER_POINTER (id
));
5724 c_parser_error (parser
, "expected identifier");
5725 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5728 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5733 str
= c_parser_asm_string_literal (parser
);
5734 if (str
== NULL_TREE
)
5736 parser
->lex_untranslated_string
= false;
5737 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5739 parser
->lex_untranslated_string
= true;
5742 expr
= c_parser_expression (parser
);
5743 mark_exp_read (expr
.value
);
5744 parser
->lex_untranslated_string
= true;
5745 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5747 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5750 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5752 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5753 c_parser_consume_token (parser
);
5760 /* Parse asm clobbers, a GNU extension.
5764 asm-clobbers , asm-string-literal
5768 c_parser_asm_clobbers (c_parser
*parser
)
5770 tree list
= NULL_TREE
;
5773 tree str
= c_parser_asm_string_literal (parser
);
5775 list
= tree_cons (NULL_TREE
, str
, list
);
5778 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5779 c_parser_consume_token (parser
);
5786 /* Parse asm goto labels, a GNU extension.
5790 asm-goto-operands , identifier
5794 c_parser_asm_goto_operands (c_parser
*parser
)
5796 tree list
= NULL_TREE
;
5801 if (c_parser_next_token_is (parser
, CPP_NAME
))
5803 c_token
*tok
= c_parser_peek_token (parser
);
5805 label
= lookup_label_for_goto (tok
->location
, name
);
5806 c_parser_consume_token (parser
);
5807 TREE_USED (label
) = 1;
5811 c_parser_error (parser
, "expected identifier");
5815 name
= build_string (IDENTIFIER_LENGTH (name
),
5816 IDENTIFIER_POINTER (name
));
5817 list
= tree_cons (name
, label
, list
);
5818 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5819 c_parser_consume_token (parser
);
5821 return nreverse (list
);
5825 /* Parse an expression other than a compound expression; that is, an
5826 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5827 NULL then it is an Objective-C message expression which is the
5828 primary-expression starting the expression as an initializer.
5830 assignment-expression:
5831 conditional-expression
5832 unary-expression assignment-operator assignment-expression
5834 assignment-operator: one of
5835 = *= /= %= += -= <<= >>= &= ^= |=
5837 In GNU C we accept any conditional expression on the LHS and
5838 diagnose the invalid lvalue rather than producing a syntax
5841 static struct c_expr
5842 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5843 tree omp_atomic_lhs
)
5845 struct c_expr lhs
, rhs
, ret
;
5846 enum tree_code code
;
5847 location_t op_location
, exp_location
;
5848 gcc_assert (!after
|| c_dialect_objc ());
5849 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5850 op_location
= c_parser_peek_token (parser
)->location
;
5851 switch (c_parser_peek_token (parser
)->type
)
5860 code
= TRUNC_DIV_EXPR
;
5863 code
= TRUNC_MOD_EXPR
;
5878 code
= BIT_AND_EXPR
;
5881 code
= BIT_XOR_EXPR
;
5884 code
= BIT_IOR_EXPR
;
5889 c_parser_consume_token (parser
);
5890 exp_location
= c_parser_peek_token (parser
)->location
;
5891 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5892 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5894 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5895 code
, exp_location
, rhs
.value
,
5897 if (code
== NOP_EXPR
)
5898 ret
.original_code
= MODIFY_EXPR
;
5901 TREE_NO_WARNING (ret
.value
) = 1;
5902 ret
.original_code
= ERROR_MARK
;
5904 ret
.original_type
= NULL
;
5908 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5909 is not NULL then it is an Objective-C message expression which is
5910 the primary-expression starting the expression as an initializer.
5912 conditional-expression:
5913 logical-OR-expression
5914 logical-OR-expression ? expression : conditional-expression
5918 conditional-expression:
5919 logical-OR-expression ? : conditional-expression
5922 static struct c_expr
5923 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5924 tree omp_atomic_lhs
)
5926 struct c_expr cond
, exp1
, exp2
, ret
;
5927 location_t cond_loc
, colon_loc
, middle_loc
;
5929 gcc_assert (!after
|| c_dialect_objc ());
5931 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5933 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5935 cond_loc
= c_parser_peek_token (parser
)->location
;
5936 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5937 c_parser_consume_token (parser
);
5938 if (c_parser_next_token_is (parser
, CPP_COLON
))
5940 tree eptype
= NULL_TREE
;
5942 middle_loc
= c_parser_peek_token (parser
)->location
;
5943 pedwarn (middle_loc
, OPT_Wpedantic
,
5944 "ISO C forbids omitting the middle term of a ?: expression");
5945 warn_for_omitted_condop (middle_loc
, cond
.value
);
5946 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5948 eptype
= TREE_TYPE (cond
.value
);
5949 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5951 /* Make sure first operand is calculated only once. */
5952 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5954 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5955 exp1
.original_type
= NULL
;
5956 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5957 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5962 = c_objc_common_truthvalue_conversion
5963 (cond_loc
, default_conversion (cond
.value
));
5964 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5965 exp1
= c_parser_expression_conv (parser
);
5966 mark_exp_read (exp1
.value
);
5967 c_inhibit_evaluation_warnings
+=
5968 ((cond
.value
== truthvalue_true_node
)
5969 - (cond
.value
== truthvalue_false_node
));
5972 colon_loc
= c_parser_peek_token (parser
)->location
;
5973 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5975 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5976 ret
.value
= error_mark_node
;
5977 ret
.original_code
= ERROR_MARK
;
5978 ret
.original_type
= NULL
;
5982 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5983 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5984 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
5986 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5987 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5988 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5989 exp1
.value
, exp1
.original_type
,
5990 exp2
.value
, exp2
.original_type
);
5991 ret
.original_code
= ERROR_MARK
;
5992 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5993 ret
.original_type
= NULL
;
5998 /* If both sides are enum type, the default conversion will have
5999 made the type of the result be an integer type. We want to
6000 remember the enum types we started with. */
6001 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6002 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6003 ret
.original_type
= ((t1
!= error_mark_node
6004 && t2
!= error_mark_node
6005 && (TYPE_MAIN_VARIANT (t1
)
6006 == TYPE_MAIN_VARIANT (t2
)))
6013 /* Parse a binary expression; that is, a logical-OR-expression (C90
6014 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6015 an Objective-C message expression which is the primary-expression
6016 starting the expression as an initializer.
6018 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6019 when it should be the unfolded lhs. In a valid OpenMP source,
6020 one of the operands of the toplevel binary expression must be equal
6021 to it. In that case, just return a build2 created binary operation
6022 rather than result of parser_build_binary_op.
6024 multiplicative-expression:
6026 multiplicative-expression * cast-expression
6027 multiplicative-expression / cast-expression
6028 multiplicative-expression % cast-expression
6030 additive-expression:
6031 multiplicative-expression
6032 additive-expression + multiplicative-expression
6033 additive-expression - multiplicative-expression
6037 shift-expression << additive-expression
6038 shift-expression >> additive-expression
6040 relational-expression:
6042 relational-expression < shift-expression
6043 relational-expression > shift-expression
6044 relational-expression <= shift-expression
6045 relational-expression >= shift-expression
6047 equality-expression:
6048 relational-expression
6049 equality-expression == relational-expression
6050 equality-expression != relational-expression
6054 AND-expression & equality-expression
6056 exclusive-OR-expression:
6058 exclusive-OR-expression ^ AND-expression
6060 inclusive-OR-expression:
6061 exclusive-OR-expression
6062 inclusive-OR-expression | exclusive-OR-expression
6064 logical-AND-expression:
6065 inclusive-OR-expression
6066 logical-AND-expression && inclusive-OR-expression
6068 logical-OR-expression:
6069 logical-AND-expression
6070 logical-OR-expression || logical-AND-expression
6073 static struct c_expr
6074 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6075 tree omp_atomic_lhs
)
6077 /* A binary expression is parsed using operator-precedence parsing,
6078 with the operands being cast expressions. All the binary
6079 operators are left-associative. Thus a binary expression is of
6082 E0 op1 E1 op2 E2 ...
6084 which we represent on a stack. On the stack, the precedence
6085 levels are strictly increasing. When a new operator is
6086 encountered of higher precedence than that at the top of the
6087 stack, it is pushed; its LHS is the top expression, and its RHS
6088 is everything parsed until it is popped. When a new operator is
6089 encountered with precedence less than or equal to that at the top
6090 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6091 by the result of the operation until the operator at the top of
6092 the stack has lower precedence than the new operator or there is
6093 only one element on the stack; then the top expression is the LHS
6094 of the new operator. In the case of logical AND and OR
6095 expressions, we also need to adjust c_inhibit_evaluation_warnings
6096 as appropriate when the operators are pushed and popped. */
6099 /* The expression at this stack level. */
6101 /* The precedence of the operator on its left, PREC_NONE at the
6102 bottom of the stack. */
6103 enum c_parser_prec prec
;
6104 /* The operation on its left. */
6106 /* The source location of this operation. */
6110 /* Location of the binary operator. */
6111 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6114 switch (stack[sp].op) \
6116 case TRUTH_ANDIF_EXPR: \
6117 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6118 == truthvalue_false_node); \
6120 case TRUTH_ORIF_EXPR: \
6121 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6122 == truthvalue_true_node); \
6127 stack[sp - 1].expr \
6128 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6129 stack[sp - 1].expr, true, true); \
6131 = convert_lvalue_to_rvalue (stack[sp].loc, \
6132 stack[sp].expr, true, true); \
6133 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6134 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6135 && ((1 << stack[sp].prec) \
6136 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6137 | PREC_ADD | PREC_MULT))) \
6138 && stack[sp].op != TRUNC_MOD_EXPR \
6139 && stack[0].expr.value != error_mark_node \
6140 && stack[1].expr.value != error_mark_node \
6141 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6142 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6143 stack[0].expr.value \
6144 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6145 stack[0].expr.value, stack[1].expr.value); \
6147 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6149 stack[sp - 1].expr, \
6153 gcc_assert (!after
|| c_dialect_objc ());
6154 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6155 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6156 stack
[0].prec
= PREC_NONE
;
6160 enum c_parser_prec oprec
;
6161 enum tree_code ocode
;
6164 switch (c_parser_peek_token (parser
)->type
)
6172 ocode
= TRUNC_DIV_EXPR
;
6176 ocode
= TRUNC_MOD_EXPR
;
6188 ocode
= LSHIFT_EXPR
;
6192 ocode
= RSHIFT_EXPR
;
6206 case CPP_GREATER_EQ
:
6219 oprec
= PREC_BITAND
;
6220 ocode
= BIT_AND_EXPR
;
6223 oprec
= PREC_BITXOR
;
6224 ocode
= BIT_XOR_EXPR
;
6228 ocode
= BIT_IOR_EXPR
;
6231 oprec
= PREC_LOGAND
;
6232 ocode
= TRUTH_ANDIF_EXPR
;
6236 ocode
= TRUTH_ORIF_EXPR
;
6239 /* Not a binary operator, so end of the binary
6243 binary_loc
= c_parser_peek_token (parser
)->location
;
6244 while (oprec
<= stack
[sp
].prec
)
6246 c_parser_consume_token (parser
);
6249 case TRUTH_ANDIF_EXPR
:
6251 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6252 stack
[sp
].expr
, true, true);
6253 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6254 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6255 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6256 == truthvalue_false_node
);
6258 case TRUTH_ORIF_EXPR
:
6260 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6261 stack
[sp
].expr
, true, true);
6262 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6263 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6264 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6265 == truthvalue_true_node
);
6271 stack
[sp
].loc
= binary_loc
;
6272 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6273 stack
[sp
].prec
= oprec
;
6274 stack
[sp
].op
= ocode
;
6275 stack
[sp
].loc
= binary_loc
;
6280 return stack
[0].expr
;
6284 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6285 NULL then it is an Objective-C message expression which is the
6286 primary-expression starting the expression as an initializer.
6290 ( type-name ) unary-expression
6293 static struct c_expr
6294 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6296 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6297 gcc_assert (!after
|| c_dialect_objc ());
6299 return c_parser_postfix_expression_after_primary (parser
,
6301 /* If the expression begins with a parenthesized type name, it may
6302 be either a cast or a compound literal; we need to see whether
6303 the next character is '{' to tell the difference. If not, it is
6304 an unary expression. Full detection of unknown typenames here
6305 would require a 3-token lookahead. */
6306 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6307 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6309 struct c_type_name
*type_name
;
6312 c_parser_consume_token (parser
);
6313 type_name
= c_parser_type_name (parser
);
6314 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6315 if (type_name
== NULL
)
6317 ret
.value
= error_mark_node
;
6318 ret
.original_code
= ERROR_MARK
;
6319 ret
.original_type
= NULL
;
6323 /* Save casted types in the function's used types hash table. */
6324 used_types_insert (type_name
->specs
->type
);
6326 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6327 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6330 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6331 expr
= c_parser_cast_expression (parser
, NULL
);
6332 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6334 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6335 ret
.original_code
= ERROR_MARK
;
6336 ret
.original_type
= NULL
;
6340 return c_parser_unary_expression (parser
);
6343 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6349 unary-operator cast-expression
6350 sizeof unary-expression
6351 sizeof ( type-name )
6353 unary-operator: one of
6359 __alignof__ unary-expression
6360 __alignof__ ( type-name )
6363 (C11 permits _Alignof with type names only.)
6365 unary-operator: one of
6366 __extension__ __real__ __imag__
6368 Transactional Memory:
6371 transaction-expression
6373 In addition, the GNU syntax treats ++ and -- as unary operators, so
6374 they may be applied to cast expressions with errors for non-lvalues
6377 static struct c_expr
6378 c_parser_unary_expression (c_parser
*parser
)
6381 struct c_expr ret
, op
;
6382 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6384 ret
.original_code
= ERROR_MARK
;
6385 ret
.original_type
= NULL
;
6386 switch (c_parser_peek_token (parser
)->type
)
6389 c_parser_consume_token (parser
);
6390 exp_loc
= c_parser_peek_token (parser
)->location
;
6391 op
= c_parser_cast_expression (parser
, NULL
);
6393 /* If there is array notations in op, we expand them. */
6394 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6395 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6398 op
= default_function_array_read_conversion (exp_loc
, op
);
6399 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6401 case CPP_MINUS_MINUS
:
6402 c_parser_consume_token (parser
);
6403 exp_loc
= c_parser_peek_token (parser
)->location
;
6404 op
= c_parser_cast_expression (parser
, NULL
);
6406 /* If there is array notations in op, we expand them. */
6407 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6408 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6411 op
= default_function_array_read_conversion (exp_loc
, op
);
6412 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6415 c_parser_consume_token (parser
);
6416 op
= c_parser_cast_expression (parser
, NULL
);
6417 mark_exp_read (op
.value
);
6418 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6420 c_parser_consume_token (parser
);
6421 exp_loc
= c_parser_peek_token (parser
)->location
;
6422 op
= c_parser_cast_expression (parser
, NULL
);
6423 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6424 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6427 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6430 "traditional C rejects the unary plus operator");
6431 c_parser_consume_token (parser
);
6432 exp_loc
= c_parser_peek_token (parser
)->location
;
6433 op
= c_parser_cast_expression (parser
, NULL
);
6434 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6435 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6437 c_parser_consume_token (parser
);
6438 exp_loc
= c_parser_peek_token (parser
)->location
;
6439 op
= c_parser_cast_expression (parser
, NULL
);
6440 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6441 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6443 c_parser_consume_token (parser
);
6444 exp_loc
= c_parser_peek_token (parser
)->location
;
6445 op
= c_parser_cast_expression (parser
, NULL
);
6446 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6447 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6449 c_parser_consume_token (parser
);
6450 exp_loc
= c_parser_peek_token (parser
)->location
;
6451 op
= c_parser_cast_expression (parser
, NULL
);
6452 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6453 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6455 /* Refer to the address of a label as a pointer. */
6456 c_parser_consume_token (parser
);
6457 if (c_parser_next_token_is (parser
, CPP_NAME
))
6459 ret
.value
= finish_label_address_expr
6460 (c_parser_peek_token (parser
)->value
, op_loc
);
6461 c_parser_consume_token (parser
);
6465 c_parser_error (parser
, "expected identifier");
6466 ret
.value
= error_mark_node
;
6470 switch (c_parser_peek_token (parser
)->keyword
)
6473 return c_parser_sizeof_expression (parser
);
6475 return c_parser_alignof_expression (parser
);
6477 c_parser_consume_token (parser
);
6478 ext
= disable_extension_diagnostics ();
6479 ret
= c_parser_cast_expression (parser
, NULL
);
6480 restore_extension_diagnostics (ext
);
6483 c_parser_consume_token (parser
);
6484 exp_loc
= c_parser_peek_token (parser
)->location
;
6485 op
= c_parser_cast_expression (parser
, NULL
);
6486 op
= default_function_array_conversion (exp_loc
, op
);
6487 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6489 c_parser_consume_token (parser
);
6490 exp_loc
= c_parser_peek_token (parser
)->location
;
6491 op
= c_parser_cast_expression (parser
, NULL
);
6492 op
= default_function_array_conversion (exp_loc
, op
);
6493 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6494 case RID_TRANSACTION_ATOMIC
:
6495 case RID_TRANSACTION_RELAXED
:
6496 return c_parser_transaction_expression (parser
,
6497 c_parser_peek_token (parser
)->keyword
);
6499 return c_parser_postfix_expression (parser
);
6502 return c_parser_postfix_expression (parser
);
6506 /* Parse a sizeof expression. */
6508 static struct c_expr
6509 c_parser_sizeof_expression (c_parser
*parser
)
6512 location_t expr_loc
;
6513 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6514 c_parser_consume_token (parser
);
6515 c_inhibit_evaluation_warnings
++;
6517 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6518 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6520 /* Either sizeof ( type-name ) or sizeof unary-expression
6521 starting with a compound literal. */
6522 struct c_type_name
*type_name
;
6523 c_parser_consume_token (parser
);
6524 expr_loc
= c_parser_peek_token (parser
)->location
;
6525 type_name
= c_parser_type_name (parser
);
6526 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6527 if (type_name
== NULL
)
6530 c_inhibit_evaluation_warnings
--;
6532 ret
.value
= error_mark_node
;
6533 ret
.original_code
= ERROR_MARK
;
6534 ret
.original_type
= NULL
;
6537 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6539 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6544 /* sizeof ( type-name ). */
6545 c_inhibit_evaluation_warnings
--;
6547 return c_expr_sizeof_type (expr_loc
, type_name
);
6551 expr_loc
= c_parser_peek_token (parser
)->location
;
6552 expr
= c_parser_unary_expression (parser
);
6554 c_inhibit_evaluation_warnings
--;
6556 mark_exp_read (expr
.value
);
6557 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6558 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6559 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6560 return c_expr_sizeof_expr (expr_loc
, expr
);
6564 /* Parse an alignof expression. */
6566 static struct c_expr
6567 c_parser_alignof_expression (c_parser
*parser
)
6570 location_t loc
= c_parser_peek_token (parser
)->location
;
6571 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6572 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6573 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6575 /* A diagnostic is not required for the use of this identifier in
6576 the implementation namespace; only diagnose it for the C11
6577 spelling because of existing code using the other spellings. */
6578 if (!flag_isoc11
&& is_c11_alignof
)
6581 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6584 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6587 c_parser_consume_token (parser
);
6588 c_inhibit_evaluation_warnings
++;
6590 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6591 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6593 /* Either __alignof__ ( type-name ) or __alignof__
6594 unary-expression starting with a compound literal. */
6596 struct c_type_name
*type_name
;
6598 c_parser_consume_token (parser
);
6599 loc
= c_parser_peek_token (parser
)->location
;
6600 type_name
= c_parser_type_name (parser
);
6601 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6602 if (type_name
== NULL
)
6605 c_inhibit_evaluation_warnings
--;
6607 ret
.value
= error_mark_node
;
6608 ret
.original_code
= ERROR_MARK
;
6609 ret
.original_type
= NULL
;
6612 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6614 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6619 /* alignof ( type-name ). */
6620 c_inhibit_evaluation_warnings
--;
6622 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6624 false, is_c11_alignof
, 1);
6625 ret
.original_code
= ERROR_MARK
;
6626 ret
.original_type
= NULL
;
6632 expr
= c_parser_unary_expression (parser
);
6634 mark_exp_read (expr
.value
);
6635 c_inhibit_evaluation_warnings
--;
6637 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6639 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6640 ret
.original_code
= ERROR_MARK
;
6641 ret
.original_type
= NULL
;
6646 /* Helper function to read arguments of builtins which are interfaces
6647 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6648 others. The name of the builtin is passed using BNAME parameter.
6649 Function returns true if there were no errors while parsing and
6650 stores the arguments in CEXPR_LIST. */
6652 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6653 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6656 location_t loc
= c_parser_peek_token (parser
)->location
;
6657 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6659 bool saved_force_folding_builtin_constant_p
;
6661 *ret_cexpr_list
= NULL
;
6662 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6664 error_at (loc
, "cannot take address of %qs", bname
);
6668 c_parser_consume_token (parser
);
6670 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6672 c_parser_consume_token (parser
);
6676 saved_force_folding_builtin_constant_p
6677 = force_folding_builtin_constant_p
;
6678 force_folding_builtin_constant_p
|= choose_expr_p
;
6679 expr
= c_parser_expr_no_commas (parser
, NULL
);
6680 force_folding_builtin_constant_p
6681 = saved_force_folding_builtin_constant_p
;
6682 vec_alloc (cexpr_list
, 1);
6683 vec_safe_push (cexpr_list
, expr
);
6684 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6686 c_parser_consume_token (parser
);
6687 expr
= c_parser_expr_no_commas (parser
, NULL
);
6688 vec_safe_push (cexpr_list
, expr
);
6691 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6694 *ret_cexpr_list
= cexpr_list
;
6698 /* This represents a single generic-association. */
6700 struct c_generic_association
6702 /* The location of the starting token of the type. */
6703 location_t type_location
;
6704 /* The association's type, or NULL_TREE for 'default'. */
6706 /* The association's expression. */
6707 struct c_expr expression
;
6710 /* Parse a generic-selection. (C11 6.5.1.1).
6713 _Generic ( assignment-expression , generic-assoc-list )
6717 generic-assoc-list , generic-association
6719 generic-association:
6720 type-name : assignment-expression
6721 default : assignment-expression
6724 static struct c_expr
6725 c_parser_generic_selection (c_parser
*parser
)
6727 vec
<c_generic_association
> associations
= vNULL
;
6728 struct c_expr selector
, error_expr
;
6730 struct c_generic_association matched_assoc
;
6731 bool match_found
= false;
6732 location_t generic_loc
, selector_loc
;
6734 error_expr
.original_code
= ERROR_MARK
;
6735 error_expr
.original_type
= NULL
;
6736 error_expr
.value
= error_mark_node
;
6737 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6738 matched_assoc
.type
= NULL_TREE
;
6739 matched_assoc
.expression
= error_expr
;
6741 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6742 generic_loc
= c_parser_peek_token (parser
)->location
;
6743 c_parser_consume_token (parser
);
6747 pedwarn (generic_loc
, OPT_Wpedantic
,
6748 "ISO C99 does not support %<_Generic%>");
6750 pedwarn (generic_loc
, OPT_Wpedantic
,
6751 "ISO C90 does not support %<_Generic%>");
6754 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6757 c_inhibit_evaluation_warnings
++;
6758 selector_loc
= c_parser_peek_token (parser
)->location
;
6759 selector
= c_parser_expr_no_commas (parser
, NULL
);
6760 selector
= default_function_array_conversion (selector_loc
, selector
);
6761 c_inhibit_evaluation_warnings
--;
6763 if (selector
.value
== error_mark_node
)
6765 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6768 selector_type
= TREE_TYPE (selector
.value
);
6769 /* In ISO C terms, rvalues (including the controlling expression of
6770 _Generic) do not have qualified types. */
6771 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6772 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6773 /* In ISO C terms, _Noreturn is not part of the type of expressions
6774 such as &abort, but in GCC it is represented internally as a type
6776 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6777 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6779 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6781 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6783 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6789 struct c_generic_association assoc
, *iter
;
6791 c_token
*token
= c_parser_peek_token (parser
);
6793 assoc
.type_location
= token
->location
;
6794 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6796 c_parser_consume_token (parser
);
6797 assoc
.type
= NULL_TREE
;
6801 struct c_type_name
*type_name
;
6803 type_name
= c_parser_type_name (parser
);
6804 if (type_name
== NULL
)
6806 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6809 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6810 if (assoc
.type
== error_mark_node
)
6812 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6816 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6817 error_at (assoc
.type_location
,
6818 "%<_Generic%> association has function type");
6819 else if (!COMPLETE_TYPE_P (assoc
.type
))
6820 error_at (assoc
.type_location
,
6821 "%<_Generic%> association has incomplete type");
6823 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6824 error_at (assoc
.type_location
,
6825 "%<_Generic%> association has "
6826 "variable length type");
6829 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6831 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6835 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6836 if (assoc
.expression
.value
== error_mark_node
)
6838 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6842 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6844 if (assoc
.type
== NULL_TREE
)
6846 if (iter
->type
== NULL_TREE
)
6848 error_at (assoc
.type_location
,
6849 "duplicate %<default%> case in %<_Generic%>");
6850 inform (iter
->type_location
, "original %<default%> is here");
6853 else if (iter
->type
!= NULL_TREE
)
6855 if (comptypes (assoc
.type
, iter
->type
))
6857 error_at (assoc
.type_location
,
6858 "%<_Generic%> specifies two compatible types");
6859 inform (iter
->type_location
, "compatible type is here");
6864 if (assoc
.type
== NULL_TREE
)
6868 matched_assoc
= assoc
;
6872 else if (comptypes (assoc
.type
, selector_type
))
6874 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6876 matched_assoc
= assoc
;
6881 error_at (assoc
.type_location
,
6882 "%<_Generic> selector matches multiple associations");
6883 inform (matched_assoc
.type_location
,
6884 "other match is here");
6888 associations
.safe_push (assoc
);
6890 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6892 c_parser_consume_token (parser
);
6895 associations
.release ();
6897 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6899 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6905 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6906 "compatible with any association",
6911 return matched_assoc
.expression
;
6914 associations
.release ();
6918 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6922 postfix-expression [ expression ]
6923 postfix-expression ( argument-expression-list[opt] )
6924 postfix-expression . identifier
6925 postfix-expression -> identifier
6926 postfix-expression ++
6927 postfix-expression --
6928 ( type-name ) { initializer-list }
6929 ( type-name ) { initializer-list , }
6931 argument-expression-list:
6933 argument-expression-list , argument-expression
6946 (treated as a keyword in GNU C)
6949 ( compound-statement )
6950 __builtin_va_arg ( assignment-expression , type-name )
6951 __builtin_offsetof ( type-name , offsetof-member-designator )
6952 __builtin_choose_expr ( assignment-expression ,
6953 assignment-expression ,
6954 assignment-expression )
6955 __builtin_types_compatible_p ( type-name , type-name )
6956 __builtin_complex ( assignment-expression , assignment-expression )
6957 __builtin_shuffle ( assignment-expression , assignment-expression )
6958 __builtin_shuffle ( assignment-expression ,
6959 assignment-expression ,
6960 assignment-expression, )
6962 offsetof-member-designator:
6964 offsetof-member-designator . identifier
6965 offsetof-member-designator [ expression ]
6970 [ objc-receiver objc-message-args ]
6971 @selector ( objc-selector-arg )
6972 @protocol ( identifier )
6973 @encode ( type-name )
6975 Classname . identifier
6978 static struct c_expr
6979 c_parser_postfix_expression (c_parser
*parser
)
6981 struct c_expr expr
, e1
;
6982 struct c_type_name
*t1
, *t2
;
6983 location_t loc
= c_parser_peek_token (parser
)->location
;;
6984 expr
.original_code
= ERROR_MARK
;
6985 expr
.original_type
= NULL
;
6986 switch (c_parser_peek_token (parser
)->type
)
6989 expr
.value
= c_parser_peek_token (parser
)->value
;
6990 loc
= c_parser_peek_token (parser
)->location
;
6991 c_parser_consume_token (parser
);
6992 if (TREE_CODE (expr
.value
) == FIXED_CST
6993 && !targetm
.fixed_point_supported_p ())
6995 error_at (loc
, "fixed-point types not supported for this target");
6996 expr
.value
= error_mark_node
;
7003 expr
.value
= c_parser_peek_token (parser
)->value
;
7004 c_parser_consume_token (parser
);
7010 case CPP_UTF8STRING
:
7011 expr
.value
= c_parser_peek_token (parser
)->value
;
7012 expr
.original_code
= STRING_CST
;
7013 c_parser_consume_token (parser
);
7015 case CPP_OBJC_STRING
:
7016 gcc_assert (c_dialect_objc ());
7018 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7019 c_parser_consume_token (parser
);
7022 switch (c_parser_peek_token (parser
)->id_kind
)
7026 tree id
= c_parser_peek_token (parser
)->value
;
7027 c_parser_consume_token (parser
);
7028 expr
.value
= build_external_ref (loc
, id
,
7029 (c_parser_peek_token (parser
)->type
7031 &expr
.original_type
);
7034 case C_ID_CLASSNAME
:
7036 /* Here we parse the Objective-C 2.0 Class.name dot
7038 tree class_name
= c_parser_peek_token (parser
)->value
;
7040 c_parser_consume_token (parser
);
7041 gcc_assert (c_dialect_objc ());
7042 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7044 expr
.value
= error_mark_node
;
7047 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7049 c_parser_error (parser
, "expected identifier");
7050 expr
.value
= error_mark_node
;
7053 component
= c_parser_peek_token (parser
)->value
;
7054 c_parser_consume_token (parser
);
7055 expr
.value
= objc_build_class_component_ref (class_name
,
7060 c_parser_error (parser
, "expected expression");
7061 expr
.value
= error_mark_node
;
7065 case CPP_OPEN_PAREN
:
7066 /* A parenthesized expression, statement expression or compound
7068 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7070 /* A statement expression. */
7072 location_t brace_loc
;
7073 c_parser_consume_token (parser
);
7074 brace_loc
= c_parser_peek_token (parser
)->location
;
7075 c_parser_consume_token (parser
);
7076 if (!building_stmt_list_p ())
7078 error_at (loc
, "braced-group within expression allowed "
7079 "only inside a function");
7080 parser
->error
= true;
7081 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7082 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7083 expr
.value
= error_mark_node
;
7086 stmt
= c_begin_stmt_expr ();
7087 c_parser_compound_statement_nostart (parser
);
7088 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7090 pedwarn (loc
, OPT_Wpedantic
,
7091 "ISO C forbids braced-groups within expressions");
7092 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7093 mark_exp_read (expr
.value
);
7095 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7097 /* A compound literal. ??? Can we actually get here rather
7098 than going directly to
7099 c_parser_postfix_expression_after_paren_type from
7102 struct c_type_name
*type_name
;
7103 c_parser_consume_token (parser
);
7104 loc
= c_parser_peek_token (parser
)->location
;
7105 type_name
= c_parser_type_name (parser
);
7106 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7108 if (type_name
== NULL
)
7110 expr
.value
= error_mark_node
;
7113 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7119 /* A parenthesized expression. */
7120 c_parser_consume_token (parser
);
7121 expr
= c_parser_expression (parser
);
7122 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7123 TREE_NO_WARNING (expr
.value
) = 1;
7124 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7125 expr
.original_code
= ERROR_MARK
;
7126 /* Don't change EXPR.ORIGINAL_TYPE. */
7127 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7132 switch (c_parser_peek_token (parser
)->keyword
)
7134 case RID_FUNCTION_NAME
:
7135 case RID_PRETTY_FUNCTION_NAME
:
7136 case RID_C99_FUNCTION_NAME
:
7137 expr
.value
= fname_decl (loc
,
7138 c_parser_peek_token (parser
)->keyword
,
7139 c_parser_peek_token (parser
)->value
);
7140 c_parser_consume_token (parser
);
7143 c_parser_consume_token (parser
);
7144 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7146 expr
.value
= error_mark_node
;
7149 e1
= c_parser_expr_no_commas (parser
, NULL
);
7150 mark_exp_read (e1
.value
);
7151 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7152 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7154 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7155 expr
.value
= error_mark_node
;
7158 loc
= c_parser_peek_token (parser
)->location
;
7159 t1
= c_parser_type_name (parser
);
7160 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7164 expr
.value
= error_mark_node
;
7168 tree type_expr
= NULL_TREE
;
7169 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7170 groktypename (t1
, &type_expr
, NULL
));
7173 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7174 TREE_TYPE (expr
.value
), type_expr
,
7176 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7181 c_parser_consume_token (parser
);
7182 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7184 expr
.value
= error_mark_node
;
7187 t1
= c_parser_type_name (parser
);
7189 parser
->error
= true;
7190 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7191 gcc_assert (parser
->error
);
7194 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7195 expr
.value
= error_mark_node
;
7200 tree type
= groktypename (t1
, NULL
, NULL
);
7202 if (type
== error_mark_node
)
7203 offsetof_ref
= error_mark_node
;
7206 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7207 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7209 /* Parse the second argument to __builtin_offsetof. We
7210 must have one identifier, and beyond that we want to
7211 accept sub structure and sub array references. */
7212 if (c_parser_next_token_is (parser
, CPP_NAME
))
7214 offsetof_ref
= build_component_ref
7215 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7216 c_parser_consume_token (parser
);
7217 while (c_parser_next_token_is (parser
, CPP_DOT
)
7218 || c_parser_next_token_is (parser
,
7220 || c_parser_next_token_is (parser
,
7223 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7225 loc
= c_parser_peek_token (parser
)->location
;
7226 offsetof_ref
= build_array_ref (loc
,
7231 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7234 c_parser_consume_token (parser
);
7235 if (c_parser_next_token_is_not (parser
,
7238 c_parser_error (parser
, "expected identifier");
7241 offsetof_ref
= build_component_ref
7243 c_parser_peek_token (parser
)->value
);
7244 c_parser_consume_token (parser
);
7250 loc
= c_parser_peek_token (parser
)->location
;
7251 c_parser_consume_token (parser
);
7252 ce
= c_parser_expression (parser
);
7253 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7255 idx
= c_fully_fold (idx
, false, NULL
);
7256 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7258 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7263 c_parser_error (parser
, "expected identifier");
7264 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7266 expr
.value
= fold_offsetof (offsetof_ref
);
7269 case RID_CHOOSE_EXPR
:
7271 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7272 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7275 c_parser_consume_token (parser
);
7276 if (!c_parser_get_builtin_args (parser
,
7277 "__builtin_choose_expr",
7280 expr
.value
= error_mark_node
;
7284 if (vec_safe_length (cexpr_list
) != 3)
7286 error_at (loc
, "wrong number of arguments to "
7287 "%<__builtin_choose_expr%>");
7288 expr
.value
= error_mark_node
;
7292 e1_p
= &(*cexpr_list
)[0];
7293 e2_p
= &(*cexpr_list
)[1];
7294 e3_p
= &(*cexpr_list
)[2];
7297 mark_exp_read (e2_p
->value
);
7298 mark_exp_read (e3_p
->value
);
7299 if (TREE_CODE (c
) != INTEGER_CST
7300 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7302 "first argument to %<__builtin_choose_expr%> not"
7304 constant_expression_warning (c
);
7305 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7308 case RID_TYPES_COMPATIBLE_P
:
7309 c_parser_consume_token (parser
);
7310 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7312 expr
.value
= error_mark_node
;
7315 t1
= c_parser_type_name (parser
);
7318 expr
.value
= error_mark_node
;
7321 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7323 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7324 expr
.value
= error_mark_node
;
7327 t2
= c_parser_type_name (parser
);
7330 expr
.value
= error_mark_node
;
7333 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7337 e1
= groktypename (t1
, NULL
, NULL
);
7338 e2
= groktypename (t2
, NULL
, NULL
);
7339 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7341 expr
.value
= error_mark_node
;
7345 e1
= TYPE_MAIN_VARIANT (e1
);
7346 e2
= TYPE_MAIN_VARIANT (e2
);
7349 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7352 case RID_BUILTIN_COMPLEX
:
7354 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7355 c_expr_t
*e1_p
, *e2_p
;
7357 c_parser_consume_token (parser
);
7358 if (!c_parser_get_builtin_args (parser
,
7359 "__builtin_complex",
7360 &cexpr_list
, false))
7362 expr
.value
= error_mark_node
;
7366 if (vec_safe_length (cexpr_list
) != 2)
7368 error_at (loc
, "wrong number of arguments to "
7369 "%<__builtin_complex%>");
7370 expr
.value
= error_mark_node
;
7374 e1_p
= &(*cexpr_list
)[0];
7375 e2_p
= &(*cexpr_list
)[1];
7377 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7378 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7379 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7380 TREE_OPERAND (e1_p
->value
, 0));
7381 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7382 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7383 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7384 TREE_OPERAND (e2_p
->value
, 0));
7385 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7386 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7387 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7388 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7390 error_at (loc
, "%<__builtin_complex%> operand "
7391 "not of real binary floating-point type");
7392 expr
.value
= error_mark_node
;
7395 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7396 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7399 "%<__builtin_complex%> operands of different types");
7400 expr
.value
= error_mark_node
;
7404 pedwarn (loc
, OPT_Wpedantic
,
7405 "ISO C90 does not support complex types");
7406 expr
.value
= build2 (COMPLEX_EXPR
,
7409 (TREE_TYPE (e1_p
->value
))),
7410 e1_p
->value
, e2_p
->value
);
7413 case RID_BUILTIN_SHUFFLE
:
7415 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7419 c_parser_consume_token (parser
);
7420 if (!c_parser_get_builtin_args (parser
,
7421 "__builtin_shuffle",
7422 &cexpr_list
, false))
7424 expr
.value
= error_mark_node
;
7428 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7429 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7431 if (vec_safe_length (cexpr_list
) == 2)
7433 c_build_vec_perm_expr
7434 (loc
, (*cexpr_list
)[0].value
,
7435 NULL_TREE
, (*cexpr_list
)[1].value
);
7437 else if (vec_safe_length (cexpr_list
) == 3)
7439 c_build_vec_perm_expr
7440 (loc
, (*cexpr_list
)[0].value
,
7441 (*cexpr_list
)[1].value
,
7442 (*cexpr_list
)[2].value
);
7445 error_at (loc
, "wrong number of arguments to "
7446 "%<__builtin_shuffle%>");
7447 expr
.value
= error_mark_node
;
7451 case RID_AT_SELECTOR
:
7452 gcc_assert (c_dialect_objc ());
7453 c_parser_consume_token (parser
);
7454 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7456 expr
.value
= error_mark_node
;
7460 tree sel
= c_parser_objc_selector_arg (parser
);
7461 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7463 expr
.value
= objc_build_selector_expr (loc
, sel
);
7466 case RID_AT_PROTOCOL
:
7467 gcc_assert (c_dialect_objc ());
7468 c_parser_consume_token (parser
);
7469 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7471 expr
.value
= error_mark_node
;
7474 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7476 c_parser_error (parser
, "expected identifier");
7477 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7478 expr
.value
= error_mark_node
;
7482 tree id
= c_parser_peek_token (parser
)->value
;
7483 c_parser_consume_token (parser
);
7484 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7486 expr
.value
= objc_build_protocol_expr (id
);
7490 /* Extension to support C-structures in the archiver. */
7491 gcc_assert (c_dialect_objc ());
7492 c_parser_consume_token (parser
);
7493 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7495 expr
.value
= error_mark_node
;
7498 t1
= c_parser_type_name (parser
);
7501 expr
.value
= error_mark_node
;
7502 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7505 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7508 tree type
= groktypename (t1
, NULL
, NULL
);
7509 expr
.value
= objc_build_encode_expr (type
);
7513 expr
= c_parser_generic_selection (parser
);
7515 case RID_CILK_SPAWN
:
7516 c_parser_consume_token (parser
);
7519 error_at (loc
, "-fcilkplus must be enabled to use "
7521 expr
= c_parser_postfix_expression (parser
);
7522 expr
.value
= error_mark_node
;
7524 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7526 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7527 "are not permitted");
7528 /* Now flush out all the _Cilk_spawns. */
7529 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7530 c_parser_consume_token (parser
);
7531 expr
= c_parser_postfix_expression (parser
);
7535 expr
= c_parser_postfix_expression (parser
);
7536 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7540 c_parser_error (parser
, "expected expression");
7541 expr
.value
= error_mark_node
;
7545 case CPP_OPEN_SQUARE
:
7546 if (c_dialect_objc ())
7548 tree receiver
, args
;
7549 c_parser_consume_token (parser
);
7550 receiver
= c_parser_objc_receiver (parser
);
7551 args
= c_parser_objc_message_args (parser
);
7552 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7554 expr
.value
= objc_build_message_expr (receiver
, args
);
7557 /* Else fall through to report error. */
7559 c_parser_error (parser
, "expected expression");
7560 expr
.value
= error_mark_node
;
7563 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7566 /* Parse a postfix expression after a parenthesized type name: the
7567 brace-enclosed initializer of a compound literal, possibly followed
7568 by some postfix operators. This is separate because it is not
7569 possible to tell until after the type name whether a cast
7570 expression has a cast or a compound literal, or whether the operand
7571 of sizeof is a parenthesized type name or starts with a compound
7572 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7573 location of the first token after the parentheses around the type
7576 static struct c_expr
7577 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7578 struct c_type_name
*type_name
,
7579 location_t type_loc
)
7585 location_t start_loc
;
7586 tree type_expr
= NULL_TREE
;
7587 bool type_expr_const
= true;
7588 check_compound_literal_type (type_loc
, type_name
);
7589 start_init (NULL_TREE
, NULL
, 0);
7590 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7591 start_loc
= c_parser_peek_token (parser
)->location
;
7592 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7594 error_at (type_loc
, "compound literal has variable size");
7595 type
= error_mark_node
;
7597 init
= c_parser_braced_init (parser
, type
, false);
7599 maybe_warn_string_init (type_loc
, type
, init
);
7601 if (type
!= error_mark_node
7602 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7603 && current_function_decl
)
7605 error ("compound literal qualified by address-space qualifier");
7606 type
= error_mark_node
;
7610 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7611 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7612 ? CONSTRUCTOR_NON_CONST (init
.value
)
7613 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7614 non_const
|= !type_expr_const
;
7615 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7616 expr
.original_code
= ERROR_MARK
;
7617 expr
.original_type
= NULL
;
7620 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7622 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7623 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7627 gcc_assert (!non_const
);
7628 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7629 type_expr
, expr
.value
);
7632 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7635 /* Callback function for sizeof_pointer_memaccess_warning to compare
7639 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7641 return comptypes (type1
, type2
) == 1;
7644 /* Parse a postfix expression after the initial primary or compound
7645 literal; that is, parse a series of postfix operators.
7647 EXPR_LOC is the location of the primary expression. */
7649 static struct c_expr
7650 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7651 location_t expr_loc
,
7654 struct c_expr orig_expr
;
7656 location_t sizeof_arg_loc
[3];
7659 vec
<tree
, va_gc
> *exprlist
;
7660 vec
<tree
, va_gc
> *origtypes
= NULL
;
7661 vec
<location_t
> arg_loc
= vNULL
;
7665 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7666 switch (c_parser_peek_token (parser
)->type
)
7668 case CPP_OPEN_SQUARE
:
7669 /* Array reference. */
7670 c_parser_consume_token (parser
);
7672 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7673 /* If we are here, then we have something like this:
7676 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7680 idx
= c_parser_expression (parser
).value
;
7681 /* Here we have 3 options:
7682 1. Array [EXPR] -- Normal Array call.
7683 2. Array [EXPR : EXPR] -- Array notation without stride.
7684 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7686 For 1, we just handle it just like a normal array expression.
7687 For 2 and 3 we handle it like we handle array notations. The
7688 idx value we have above becomes the initial/start index.
7691 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7692 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7696 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7698 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7701 expr
.original_code
= ERROR_MARK
;
7702 expr
.original_type
= NULL
;
7704 case CPP_OPEN_PAREN
:
7705 /* Function call. */
7706 c_parser_consume_token (parser
);
7707 for (i
= 0; i
< 3; i
++)
7709 sizeof_arg
[i
] = NULL_TREE
;
7710 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7712 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7715 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7716 sizeof_arg_loc
, sizeof_arg
,
7718 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7721 mark_exp_read (expr
.value
);
7722 if (warn_sizeof_pointer_memaccess
)
7723 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7724 expr
.value
, exprlist
,
7726 sizeof_ptr_memacc_comptypes
);
7728 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7729 exprlist
, origtypes
);
7730 expr
.original_code
= ERROR_MARK
;
7731 if (TREE_CODE (expr
.value
) == INTEGER_CST
7732 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7733 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7734 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7735 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7736 expr
.original_type
= NULL
;
7739 release_tree_vector (exprlist
);
7740 release_tree_vector (origtypes
);
7745 /* Structure element reference. */
7746 c_parser_consume_token (parser
);
7747 expr
= default_function_array_conversion (expr_loc
, expr
);
7748 if (c_parser_next_token_is (parser
, CPP_NAME
))
7749 ident
= c_parser_peek_token (parser
)->value
;
7752 c_parser_error (parser
, "expected identifier");
7753 expr
.value
= error_mark_node
;
7754 expr
.original_code
= ERROR_MARK
;
7755 expr
.original_type
= NULL
;
7758 c_parser_consume_token (parser
);
7759 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7760 expr
.original_code
= ERROR_MARK
;
7761 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7762 expr
.original_type
= NULL
;
7765 /* Remember the original type of a bitfield. */
7766 tree field
= TREE_OPERAND (expr
.value
, 1);
7767 if (TREE_CODE (field
) != FIELD_DECL
)
7768 expr
.original_type
= NULL
;
7770 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7774 /* Structure element reference. */
7775 c_parser_consume_token (parser
);
7776 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7777 if (c_parser_next_token_is (parser
, CPP_NAME
))
7778 ident
= c_parser_peek_token (parser
)->value
;
7781 c_parser_error (parser
, "expected identifier");
7782 expr
.value
= error_mark_node
;
7783 expr
.original_code
= ERROR_MARK
;
7784 expr
.original_type
= NULL
;
7787 c_parser_consume_token (parser
);
7788 expr
.value
= build_component_ref (op_loc
,
7789 build_indirect_ref (op_loc
,
7793 expr
.original_code
= ERROR_MARK
;
7794 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7795 expr
.original_type
= NULL
;
7798 /* Remember the original type of a bitfield. */
7799 tree field
= TREE_OPERAND (expr
.value
, 1);
7800 if (TREE_CODE (field
) != FIELD_DECL
)
7801 expr
.original_type
= NULL
;
7803 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7807 /* Postincrement. */
7808 c_parser_consume_token (parser
);
7809 /* If the expressions have array notations, we expand them. */
7811 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7812 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7815 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7816 expr
.value
= build_unary_op (op_loc
,
7817 POSTINCREMENT_EXPR
, expr
.value
, 0);
7819 expr
.original_code
= ERROR_MARK
;
7820 expr
.original_type
= NULL
;
7822 case CPP_MINUS_MINUS
:
7823 /* Postdecrement. */
7824 c_parser_consume_token (parser
);
7825 /* If the expressions have array notations, we expand them. */
7827 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7828 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7831 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7832 expr
.value
= build_unary_op (op_loc
,
7833 POSTDECREMENT_EXPR
, expr
.value
, 0);
7835 expr
.original_code
= ERROR_MARK
;
7836 expr
.original_type
= NULL
;
7844 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7847 assignment-expression
7848 expression , assignment-expression
7851 static struct c_expr
7852 c_parser_expression (c_parser
*parser
)
7854 location_t tloc
= c_parser_peek_token (parser
)->location
;
7856 expr
= c_parser_expr_no_commas (parser
, NULL
);
7857 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7858 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7859 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7863 location_t loc
= c_parser_peek_token (parser
)->location
;
7864 location_t expr_loc
;
7865 c_parser_consume_token (parser
);
7866 expr_loc
= c_parser_peek_token (parser
)->location
;
7867 lhsval
= expr
.value
;
7868 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7869 lhsval
= TREE_OPERAND (lhsval
, 1);
7870 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7871 mark_exp_read (lhsval
);
7872 next
= c_parser_expr_no_commas (parser
, NULL
);
7873 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7874 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7875 expr
.original_code
= COMPOUND_EXPR
;
7876 expr
.original_type
= next
.original_type
;
7881 /* Parse an expression and convert functions or arrays to pointers and
7882 lvalues to rvalues. */
7884 static struct c_expr
7885 c_parser_expression_conv (c_parser
*parser
)
7888 location_t loc
= c_parser_peek_token (parser
)->location
;
7889 expr
= c_parser_expression (parser
);
7890 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7894 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7895 functions and arrays to pointers and lvalues to rvalues. If
7896 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7897 locations of function arguments into this vector.
7900 assignment-expression
7901 nonempty-expr-list , assignment-expression
7904 static vec
<tree
, va_gc
> *
7905 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7906 vec
<tree
, va_gc
> **p_orig_types
,
7907 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
7908 vec
<location_t
> *locations
)
7910 vec
<tree
, va_gc
> *ret
;
7911 vec
<tree
, va_gc
> *orig_types
;
7913 location_t loc
= c_parser_peek_token (parser
)->location
;
7914 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7915 unsigned int idx
= 0;
7917 ret
= make_tree_vector ();
7918 if (p_orig_types
== NULL
)
7921 orig_types
= make_tree_vector ();
7923 if (sizeof_arg
!= NULL
7924 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7925 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7926 expr
= c_parser_expr_no_commas (parser
, NULL
);
7928 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7930 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7931 ret
->quick_push (expr
.value
);
7933 orig_types
->quick_push (expr
.original_type
);
7935 locations
->safe_push (loc
);
7936 if (sizeof_arg
!= NULL
7937 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7938 && expr
.original_code
== SIZEOF_EXPR
)
7940 sizeof_arg
[0] = c_last_sizeof_arg
;
7941 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7943 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7945 c_parser_consume_token (parser
);
7946 loc
= c_parser_peek_token (parser
)->location
;
7947 if (sizeof_arg
!= NULL
7948 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7949 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7951 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7952 expr
= c_parser_expr_no_commas (parser
, NULL
);
7954 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7956 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7957 vec_safe_push (ret
, expr
.value
);
7959 vec_safe_push (orig_types
, expr
.original_type
);
7961 locations
->safe_push (loc
);
7963 && sizeof_arg
!= NULL
7964 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7965 && expr
.original_code
== SIZEOF_EXPR
)
7967 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7968 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7972 *p_orig_types
= orig_types
;
7976 /* Parse Objective-C-specific constructs. */
7978 /* Parse an objc-class-definition.
7980 objc-class-definition:
7981 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7982 objc-class-instance-variables[opt] objc-methodprotolist @end
7983 @implementation identifier objc-superclass[opt]
7984 objc-class-instance-variables[opt]
7985 @interface identifier ( identifier ) objc-protocol-refs[opt]
7986 objc-methodprotolist @end
7987 @interface identifier ( ) objc-protocol-refs[opt]
7988 objc-methodprotolist @end
7989 @implementation identifier ( identifier )
7994 "@interface identifier (" must start "@interface identifier (
7995 identifier ) ...": objc-methodprotolist in the first production may
7996 not start with a parenthesized identifier as a declarator of a data
7997 definition with no declaration specifiers if the objc-superclass,
7998 objc-protocol-refs and objc-class-instance-variables are omitted. */
8001 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8006 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8008 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8013 c_parser_consume_token (parser
);
8014 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8016 c_parser_error (parser
, "expected identifier");
8019 id1
= c_parser_peek_token (parser
)->value
;
8020 c_parser_consume_token (parser
);
8021 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8023 /* We have a category or class extension. */
8025 tree proto
= NULL_TREE
;
8026 c_parser_consume_token (parser
);
8027 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8029 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8031 /* We have a class extension. */
8036 c_parser_error (parser
, "expected identifier or %<)%>");
8037 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8043 id2
= c_parser_peek_token (parser
)->value
;
8044 c_parser_consume_token (parser
);
8046 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8049 objc_start_category_implementation (id1
, id2
);
8052 if (c_parser_next_token_is (parser
, CPP_LESS
))
8053 proto
= c_parser_objc_protocol_refs (parser
);
8054 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8055 c_parser_objc_methodprotolist (parser
);
8056 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8057 objc_finish_interface ();
8060 if (c_parser_next_token_is (parser
, CPP_COLON
))
8062 c_parser_consume_token (parser
);
8063 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8065 c_parser_error (parser
, "expected identifier");
8068 superclass
= c_parser_peek_token (parser
)->value
;
8069 c_parser_consume_token (parser
);
8072 superclass
= NULL_TREE
;
8075 tree proto
= NULL_TREE
;
8076 if (c_parser_next_token_is (parser
, CPP_LESS
))
8077 proto
= c_parser_objc_protocol_refs (parser
);
8078 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8081 objc_start_class_implementation (id1
, superclass
);
8082 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8083 c_parser_objc_class_instance_variables (parser
);
8086 objc_continue_interface ();
8087 c_parser_objc_methodprotolist (parser
);
8088 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8089 objc_finish_interface ();
8093 objc_continue_implementation ();
8098 /* Parse objc-class-instance-variables.
8100 objc-class-instance-variables:
8101 { objc-instance-variable-decl-list[opt] }
8103 objc-instance-variable-decl-list:
8104 objc-visibility-spec
8105 objc-instance-variable-decl ;
8107 objc-instance-variable-decl-list objc-visibility-spec
8108 objc-instance-variable-decl-list objc-instance-variable-decl ;
8109 objc-instance-variable-decl-list ;
8111 objc-visibility-spec:
8116 objc-instance-variable-decl:
8121 c_parser_objc_class_instance_variables (c_parser
*parser
)
8123 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8124 c_parser_consume_token (parser
);
8125 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8128 /* Parse any stray semicolon. */
8129 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8131 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8133 c_parser_consume_token (parser
);
8136 /* Stop if at the end of the instance variables. */
8137 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8139 c_parser_consume_token (parser
);
8142 /* Parse any objc-visibility-spec. */
8143 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8145 c_parser_consume_token (parser
);
8146 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8149 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8151 c_parser_consume_token (parser
);
8152 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8155 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8157 c_parser_consume_token (parser
);
8158 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8161 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8163 c_parser_consume_token (parser
);
8164 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8167 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8169 c_parser_pragma (parser
, pragma_external
);
8173 /* Parse some comma-separated declarations. */
8174 decls
= c_parser_struct_declaration (parser
);
8177 /* There is a syntax error. We want to skip the offending
8178 tokens up to the next ';' (included) or '}'
8181 /* First, skip manually a ')' or ']'. This is because they
8182 reduce the nesting level, so c_parser_skip_until_found()
8183 wouldn't be able to skip past them. */
8184 c_token
*token
= c_parser_peek_token (parser
);
8185 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8186 c_parser_consume_token (parser
);
8188 /* Then, do the standard skipping. */
8189 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8191 /* We hopefully recovered. Start normal parsing again. */
8192 parser
->error
= false;
8197 /* Comma-separated instance variables are chained together
8198 in reverse order; add them one by one. */
8199 tree ivar
= nreverse (decls
);
8200 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8201 objc_add_instance_variable (copy_node (ivar
));
8203 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8207 /* Parse an objc-class-declaration.
8209 objc-class-declaration:
8210 @class identifier-list ;
8214 c_parser_objc_class_declaration (c_parser
*parser
)
8216 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8217 c_parser_consume_token (parser
);
8218 /* Any identifiers, including those declared as type names, are OK
8223 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8225 c_parser_error (parser
, "expected identifier");
8226 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8227 parser
->error
= false;
8230 id
= c_parser_peek_token (parser
)->value
;
8231 objc_declare_class (id
);
8232 c_parser_consume_token (parser
);
8233 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8234 c_parser_consume_token (parser
);
8238 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8241 /* Parse an objc-alias-declaration.
8243 objc-alias-declaration:
8244 @compatibility_alias identifier identifier ;
8248 c_parser_objc_alias_declaration (c_parser
*parser
)
8251 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8252 c_parser_consume_token (parser
);
8253 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8255 c_parser_error (parser
, "expected identifier");
8256 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8259 id1
= c_parser_peek_token (parser
)->value
;
8260 c_parser_consume_token (parser
);
8261 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8263 c_parser_error (parser
, "expected identifier");
8264 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8267 id2
= c_parser_peek_token (parser
)->value
;
8268 c_parser_consume_token (parser
);
8269 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8270 objc_declare_alias (id1
, id2
);
8273 /* Parse an objc-protocol-definition.
8275 objc-protocol-definition:
8276 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8277 @protocol identifier-list ;
8279 "@protocol identifier ;" should be resolved as "@protocol
8280 identifier-list ;": objc-methodprotolist may not start with a
8281 semicolon in the first alternative if objc-protocol-refs are
8285 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8287 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8289 c_parser_consume_token (parser
);
8290 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8292 c_parser_error (parser
, "expected identifier");
8295 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8296 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8298 /* Any identifiers, including those declared as type names, are
8303 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8305 c_parser_error (parser
, "expected identifier");
8308 id
= c_parser_peek_token (parser
)->value
;
8309 objc_declare_protocol (id
, attributes
);
8310 c_parser_consume_token (parser
);
8311 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8312 c_parser_consume_token (parser
);
8316 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8320 tree id
= c_parser_peek_token (parser
)->value
;
8321 tree proto
= NULL_TREE
;
8322 c_parser_consume_token (parser
);
8323 if (c_parser_next_token_is (parser
, CPP_LESS
))
8324 proto
= c_parser_objc_protocol_refs (parser
);
8325 parser
->objc_pq_context
= true;
8326 objc_start_protocol (id
, proto
, attributes
);
8327 c_parser_objc_methodprotolist (parser
);
8328 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8329 parser
->objc_pq_context
= false;
8330 objc_finish_interface ();
8334 /* Parse an objc-method-type.
8340 Return true if it is a class method (+) and false if it is
8341 an instance method (-).
8344 c_parser_objc_method_type (c_parser
*parser
)
8346 switch (c_parser_peek_token (parser
)->type
)
8349 c_parser_consume_token (parser
);
8352 c_parser_consume_token (parser
);
8359 /* Parse an objc-method-definition.
8361 objc-method-definition:
8362 objc-method-type objc-method-decl ;[opt] compound-statement
8366 c_parser_objc_method_definition (c_parser
*parser
)
8368 bool is_class_method
= c_parser_objc_method_type (parser
);
8369 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8370 parser
->objc_pq_context
= true;
8371 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8373 if (decl
== error_mark_node
)
8374 return; /* Bail here. */
8376 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8378 c_parser_consume_token (parser
);
8379 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8380 "extra semicolon in method definition specified");
8383 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8385 c_parser_error (parser
, "expected %<{%>");
8389 parser
->objc_pq_context
= false;
8390 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8392 add_stmt (c_parser_compound_statement (parser
));
8393 objc_finish_method_definition (current_function_decl
);
8397 /* This code is executed when we find a method definition
8398 outside of an @implementation context (or invalid for other
8399 reasons). Parse the method (to keep going) but do not emit
8402 c_parser_compound_statement (parser
);
8406 /* Parse an objc-methodprotolist.
8408 objc-methodprotolist:
8410 objc-methodprotolist objc-methodproto
8411 objc-methodprotolist declaration
8412 objc-methodprotolist ;
8416 The declaration is a data definition, which may be missing
8417 declaration specifiers under the same rules and diagnostics as
8418 other data definitions outside functions, and the stray semicolon
8419 is diagnosed the same way as a stray semicolon outside a
8423 c_parser_objc_methodprotolist (c_parser
*parser
)
8427 /* The list is terminated by @end. */
8428 switch (c_parser_peek_token (parser
)->type
)
8431 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8432 "ISO C does not allow extra %<;%> outside of a function");
8433 c_parser_consume_token (parser
);
8437 c_parser_objc_methodproto (parser
);
8440 c_parser_pragma (parser
, pragma_external
);
8445 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8447 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8448 c_parser_objc_at_property_declaration (parser
);
8449 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8451 objc_set_method_opt (true);
8452 c_parser_consume_token (parser
);
8454 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8456 objc_set_method_opt (false);
8457 c_parser_consume_token (parser
);
8460 c_parser_declaration_or_fndef (parser
, false, false, true,
8461 false, true, NULL
, vNULL
);
8467 /* Parse an objc-methodproto.
8470 objc-method-type objc-method-decl ;
8474 c_parser_objc_methodproto (c_parser
*parser
)
8476 bool is_class_method
= c_parser_objc_method_type (parser
);
8477 tree decl
, attributes
= NULL_TREE
;
8479 /* Remember protocol qualifiers in prototypes. */
8480 parser
->objc_pq_context
= true;
8481 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8483 /* Forget protocol qualifiers now. */
8484 parser
->objc_pq_context
= false;
8486 /* Do not allow the presence of attributes to hide an erroneous
8487 method implementation in the interface section. */
8488 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8490 c_parser_error (parser
, "expected %<;%>");
8494 if (decl
!= error_mark_node
)
8495 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8497 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8500 /* If we are at a position that method attributes may be present, check that
8501 there are not any parsed already (a syntax error) and then collect any
8502 specified at the current location. Finally, if new attributes were present,
8503 check that the next token is legal ( ';' for decls and '{' for defs). */
8506 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8511 c_parser_error (parser
,
8512 "method attributes must be specified at the end only");
8513 *attributes
= NULL_TREE
;
8517 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8518 *attributes
= c_parser_attributes (parser
);
8520 /* If there were no attributes here, just report any earlier error. */
8521 if (*attributes
== NULL_TREE
|| bad
)
8524 /* If the attributes are followed by a ; or {, then just report any earlier
8526 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8527 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8530 /* We've got attributes, but not at the end. */
8531 c_parser_error (parser
,
8532 "expected %<;%> or %<{%> after method attribute definition");
8536 /* Parse an objc-method-decl.
8539 ( objc-type-name ) objc-selector
8541 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8542 objc-keyword-selector objc-optparmlist
8545 objc-keyword-selector:
8547 objc-keyword-selector objc-keyword-decl
8550 objc-selector : ( objc-type-name ) identifier
8551 objc-selector : identifier
8552 : ( objc-type-name ) identifier
8556 objc-optparms objc-optellipsis
8560 objc-opt-parms , parameter-declaration
8568 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8569 tree
*attributes
, tree
*expr
)
8571 tree type
= NULL_TREE
;
8573 tree parms
= NULL_TREE
;
8574 bool ellipsis
= false;
8575 bool attr_err
= false;
8577 *attributes
= NULL_TREE
;
8578 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8580 c_parser_consume_token (parser
);
8581 type
= c_parser_objc_type_name (parser
);
8582 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8584 sel
= c_parser_objc_selector (parser
);
8585 /* If there is no selector, or a colon follows, we have an
8586 objc-keyword-selector. If there is a selector, and a colon does
8587 not follow, that selector ends the objc-method-decl. */
8588 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8591 tree list
= NULL_TREE
;
8594 tree atype
= NULL_TREE
, id
, keyworddecl
;
8595 tree param_attr
= NULL_TREE
;
8596 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8598 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8600 c_parser_consume_token (parser
);
8601 atype
= c_parser_objc_type_name (parser
);
8602 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8605 /* New ObjC allows attributes on method parameters. */
8606 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8607 param_attr
= c_parser_attributes (parser
);
8608 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8610 c_parser_error (parser
, "expected identifier");
8611 return error_mark_node
;
8613 id
= c_parser_peek_token (parser
)->value
;
8614 c_parser_consume_token (parser
);
8615 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8616 list
= chainon (list
, keyworddecl
);
8617 tsel
= c_parser_objc_selector (parser
);
8618 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8622 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8624 /* Parse the optional parameter list. Optional Objective-C
8625 method parameters follow the C syntax, and may include '...'
8626 to denote a variable number of arguments. */
8627 parms
= make_node (TREE_LIST
);
8628 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8630 struct c_parm
*parm
;
8631 c_parser_consume_token (parser
);
8632 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8635 c_parser_consume_token (parser
);
8636 attr_err
|= c_parser_objc_maybe_method_attributes
8637 (parser
, attributes
) ;
8640 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8643 parms
= chainon (parms
,
8644 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8649 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8653 c_parser_error (parser
, "objective-c method declaration is expected");
8654 return error_mark_node
;
8658 return error_mark_node
;
8660 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8663 /* Parse an objc-type-name.
8666 objc-type-qualifiers[opt] type-name
8667 objc-type-qualifiers[opt]
8669 objc-type-qualifiers:
8671 objc-type-qualifiers objc-type-qualifier
8673 objc-type-qualifier: one of
8674 in out inout bycopy byref oneway
8678 c_parser_objc_type_name (c_parser
*parser
)
8680 tree quals
= NULL_TREE
;
8681 struct c_type_name
*type_name
= NULL
;
8682 tree type
= NULL_TREE
;
8685 c_token
*token
= c_parser_peek_token (parser
);
8686 if (token
->type
== CPP_KEYWORD
8687 && (token
->keyword
== RID_IN
8688 || token
->keyword
== RID_OUT
8689 || token
->keyword
== RID_INOUT
8690 || token
->keyword
== RID_BYCOPY
8691 || token
->keyword
== RID_BYREF
8692 || token
->keyword
== RID_ONEWAY
))
8694 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8695 c_parser_consume_token (parser
);
8700 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8701 type_name
= c_parser_type_name (parser
);
8703 type
= groktypename (type_name
, NULL
, NULL
);
8705 /* If the type is unknown, and error has already been produced and
8706 we need to recover from the error. In that case, use NULL_TREE
8707 for the type, as if no type had been specified; this will use the
8708 default type ('id') which is good for error recovery. */
8709 if (type
== error_mark_node
)
8712 return build_tree_list (quals
, type
);
8715 /* Parse objc-protocol-refs.
8722 c_parser_objc_protocol_refs (c_parser
*parser
)
8724 tree list
= NULL_TREE
;
8725 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8726 c_parser_consume_token (parser
);
8727 /* Any identifiers, including those declared as type names, are OK
8732 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8734 c_parser_error (parser
, "expected identifier");
8737 id
= c_parser_peek_token (parser
)->value
;
8738 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8739 c_parser_consume_token (parser
);
8740 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8741 c_parser_consume_token (parser
);
8745 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8749 /* Parse an objc-try-catch-finally-statement.
8751 objc-try-catch-finally-statement:
8752 @try compound-statement objc-catch-list[opt]
8753 @try compound-statement objc-catch-list[opt] @finally compound-statement
8756 @catch ( objc-catch-parameter-declaration ) compound-statement
8757 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8759 objc-catch-parameter-declaration:
8760 parameter-declaration
8763 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8765 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8766 for C++. Keep them in sync. */
8769 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8771 location_t location
;
8774 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8775 c_parser_consume_token (parser
);
8776 location
= c_parser_peek_token (parser
)->location
;
8777 objc_maybe_warn_exceptions (location
);
8778 stmt
= c_parser_compound_statement (parser
);
8779 objc_begin_try_stmt (location
, stmt
);
8781 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8783 struct c_parm
*parm
;
8784 tree parameter_declaration
= error_mark_node
;
8785 bool seen_open_paren
= false;
8787 c_parser_consume_token (parser
);
8788 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8789 seen_open_paren
= true;
8790 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8792 /* We have "@catch (...)" (where the '...' are literally
8793 what is in the code). Skip the '...'.
8794 parameter_declaration is set to NULL_TREE, and
8795 objc_being_catch_clauses() knows that that means
8797 c_parser_consume_token (parser
);
8798 parameter_declaration
= NULL_TREE
;
8802 /* We have "@catch (NSException *exception)" or something
8803 like that. Parse the parameter declaration. */
8804 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8806 parameter_declaration
= error_mark_node
;
8808 parameter_declaration
= grokparm (parm
, NULL
);
8810 if (seen_open_paren
)
8811 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8814 /* If there was no open parenthesis, we are recovering from
8815 an error, and we are trying to figure out what mistake
8816 the user has made. */
8818 /* If there is an immediate closing parenthesis, the user
8819 probably forgot the opening one (ie, they typed "@catch
8820 NSException *e)". Parse the closing parenthesis and keep
8822 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8823 c_parser_consume_token (parser
);
8825 /* If these is no immediate closing parenthesis, the user
8826 probably doesn't know that parenthesis are required at
8827 all (ie, they typed "@catch NSException *e"). So, just
8828 forget about the closing parenthesis and keep going. */
8830 objc_begin_catch_clause (parameter_declaration
);
8831 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8832 c_parser_compound_statement_nostart (parser
);
8833 objc_finish_catch_clause ();
8835 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8837 c_parser_consume_token (parser
);
8838 location
= c_parser_peek_token (parser
)->location
;
8839 stmt
= c_parser_compound_statement (parser
);
8840 objc_build_finally_clause (location
, stmt
);
8842 objc_finish_try_stmt ();
8845 /* Parse an objc-synchronized-statement.
8847 objc-synchronized-statement:
8848 @synchronized ( expression ) compound-statement
8852 c_parser_objc_synchronized_statement (c_parser
*parser
)
8856 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8857 c_parser_consume_token (parser
);
8858 loc
= c_parser_peek_token (parser
)->location
;
8859 objc_maybe_warn_exceptions (loc
);
8860 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8862 struct c_expr ce
= c_parser_expression (parser
);
8863 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8865 expr
= c_fully_fold (expr
, false, NULL
);
8866 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8869 expr
= error_mark_node
;
8870 stmt
= c_parser_compound_statement (parser
);
8871 objc_build_synchronized (loc
, expr
, stmt
);
8874 /* Parse an objc-selector; return NULL_TREE without an error if the
8875 next token is not an objc-selector.
8880 enum struct union if else while do for switch case default
8881 break continue return goto asm sizeof typeof __alignof
8882 unsigned long const short volatile signed restrict _Complex
8883 in out inout bycopy byref oneway int char float double void _Bool
8886 ??? Why this selection of keywords but not, for example, storage
8887 class specifiers? */
8890 c_parser_objc_selector (c_parser
*parser
)
8892 c_token
*token
= c_parser_peek_token (parser
);
8893 tree value
= token
->value
;
8894 if (token
->type
== CPP_NAME
)
8896 c_parser_consume_token (parser
);
8899 if (token
->type
!= CPP_KEYWORD
)
8901 switch (token
->keyword
)
8945 c_parser_consume_token (parser
);
8952 /* Parse an objc-selector-arg.
8956 objc-keywordname-list
8958 objc-keywordname-list:
8960 objc-keywordname-list objc-keywordname
8968 c_parser_objc_selector_arg (c_parser
*parser
)
8970 tree sel
= c_parser_objc_selector (parser
);
8971 tree list
= NULL_TREE
;
8972 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8976 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8978 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8979 sel
= c_parser_objc_selector (parser
);
8980 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8986 /* Parse an objc-receiver.
8995 c_parser_objc_receiver (c_parser
*parser
)
8997 location_t loc
= c_parser_peek_token (parser
)->location
;
8999 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9000 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9001 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9003 tree id
= c_parser_peek_token (parser
)->value
;
9004 c_parser_consume_token (parser
);
9005 return objc_get_class_reference (id
);
9007 struct c_expr ce
= c_parser_expression (parser
);
9008 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9009 return c_fully_fold (ce
.value
, false, NULL
);
9012 /* Parse objc-message-args.
9016 objc-keywordarg-list
9018 objc-keywordarg-list:
9020 objc-keywordarg-list objc-keywordarg
9023 objc-selector : objc-keywordexpr
9028 c_parser_objc_message_args (c_parser
*parser
)
9030 tree sel
= c_parser_objc_selector (parser
);
9031 tree list
= NULL_TREE
;
9032 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9037 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9038 return error_mark_node
;
9039 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9040 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9041 sel
= c_parser_objc_selector (parser
);
9042 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9048 /* Parse an objc-keywordexpr.
9055 c_parser_objc_keywordexpr (c_parser
*parser
)
9058 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9059 NULL
, NULL
, NULL
, NULL
);
9060 if (vec_safe_length (expr_list
) == 1)
9062 /* Just return the expression, remove a level of
9064 ret
= (*expr_list
)[0];
9068 /* We have a comma expression, we will collapse later. */
9069 ret
= build_tree_list_vec (expr_list
);
9071 release_tree_vector (expr_list
);
9075 /* A check, needed in several places, that ObjC interface, implementation or
9076 method definitions are not prefixed by incorrect items. */
9078 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9079 struct c_declspecs
*specs
)
9081 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9082 || specs
->typespec_kind
!= ctsk_none
)
9084 c_parser_error (parser
,
9085 "no type or storage class may be specified here,");
9086 c_parser_skip_to_end_of_block_or_statement (parser
);
9092 /* Parse an Objective-C @property declaration. The syntax is:
9094 objc-property-declaration:
9095 '@property' objc-property-attributes[opt] struct-declaration ;
9097 objc-property-attributes:
9098 '(' objc-property-attribute-list ')'
9100 objc-property-attribute-list:
9101 objc-property-attribute
9102 objc-property-attribute-list, objc-property-attribute
9104 objc-property-attribute
9105 'getter' = identifier
9106 'setter' = identifier
9115 @property NSString *name;
9116 @property (readonly) id object;
9117 @property (retain, nonatomic, getter=getTheName) id name;
9118 @property int a, b, c;
9120 PS: This function is identical to cp_parser_objc_at_propery_declaration
9121 for C++. Keep them in sync. */
9123 c_parser_objc_at_property_declaration (c_parser
*parser
)
9125 /* The following variables hold the attributes of the properties as
9126 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9127 seen. When we see an attribute, we set them to 'true' (if they
9128 are boolean properties) or to the identifier (if they have an
9129 argument, ie, for getter and setter). Note that here we only
9130 parse the list of attributes, check the syntax and accumulate the
9131 attributes that we find. objc_add_property_declaration() will
9132 then process the information. */
9133 bool property_assign
= false;
9134 bool property_copy
= false;
9135 tree property_getter_ident
= NULL_TREE
;
9136 bool property_nonatomic
= false;
9137 bool property_readonly
= false;
9138 bool property_readwrite
= false;
9139 bool property_retain
= false;
9140 tree property_setter_ident
= NULL_TREE
;
9142 /* 'properties' is the list of properties that we read. Usually a
9143 single one, but maybe more (eg, in "@property int a, b, c;" there
9148 loc
= c_parser_peek_token (parser
)->location
;
9149 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9151 c_parser_consume_token (parser
); /* Eat '@property'. */
9153 /* Parse the optional attribute list... */
9154 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9157 c_parser_consume_token (parser
);
9159 /* Property attribute keywords are valid now. */
9160 parser
->objc_property_attr_context
= true;
9164 bool syntax_error
= false;
9165 c_token
*token
= c_parser_peek_token (parser
);
9168 if (token
->type
!= CPP_KEYWORD
)
9170 if (token
->type
== CPP_CLOSE_PAREN
)
9171 c_parser_error (parser
, "expected identifier");
9174 c_parser_consume_token (parser
);
9175 c_parser_error (parser
, "unknown property attribute");
9179 keyword
= token
->keyword
;
9180 c_parser_consume_token (parser
);
9183 case RID_ASSIGN
: property_assign
= true; break;
9184 case RID_COPY
: property_copy
= true; break;
9185 case RID_NONATOMIC
: property_nonatomic
= true; break;
9186 case RID_READONLY
: property_readonly
= true; break;
9187 case RID_READWRITE
: property_readwrite
= true; break;
9188 case RID_RETAIN
: property_retain
= true; break;
9192 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9194 if (keyword
== RID_GETTER
)
9195 c_parser_error (parser
,
9196 "missing %<=%> (after %<getter%> attribute)");
9198 c_parser_error (parser
,
9199 "missing %<=%> (after %<setter%> attribute)");
9200 syntax_error
= true;
9203 c_parser_consume_token (parser
); /* eat the = */
9204 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9206 c_parser_error (parser
, "expected identifier");
9207 syntax_error
= true;
9210 if (keyword
== RID_SETTER
)
9212 if (property_setter_ident
!= NULL_TREE
)
9213 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9215 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9216 c_parser_consume_token (parser
);
9217 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9218 c_parser_error (parser
, "setter name must terminate with %<:%>");
9220 c_parser_consume_token (parser
);
9224 if (property_getter_ident
!= NULL_TREE
)
9225 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9227 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9228 c_parser_consume_token (parser
);
9232 c_parser_error (parser
, "unknown property attribute");
9233 syntax_error
= true;
9240 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9241 c_parser_consume_token (parser
);
9245 parser
->objc_property_attr_context
= false;
9246 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9248 /* ... and the property declaration(s). */
9249 properties
= c_parser_struct_declaration (parser
);
9251 if (properties
== error_mark_node
)
9253 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9254 parser
->error
= false;
9258 if (properties
== NULL_TREE
)
9259 c_parser_error (parser
, "expected identifier");
9262 /* Comma-separated properties are chained together in
9263 reverse order; add them one by one. */
9264 properties
= nreverse (properties
);
9266 for (; properties
; properties
= TREE_CHAIN (properties
))
9267 objc_add_property_declaration (loc
, copy_node (properties
),
9268 property_readonly
, property_readwrite
,
9269 property_assign
, property_retain
,
9270 property_copy
, property_nonatomic
,
9271 property_getter_ident
, property_setter_ident
);
9274 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9275 parser
->error
= false;
9278 /* Parse an Objective-C @synthesize declaration. The syntax is:
9280 objc-synthesize-declaration:
9281 @synthesize objc-synthesize-identifier-list ;
9283 objc-synthesize-identifier-list:
9284 objc-synthesize-identifier
9285 objc-synthesize-identifier-list, objc-synthesize-identifier
9287 objc-synthesize-identifier
9289 identifier = identifier
9292 @synthesize MyProperty;
9293 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9295 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9296 for C++. Keep them in sync.
9299 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9301 tree list
= NULL_TREE
;
9303 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9304 loc
= c_parser_peek_token (parser
)->location
;
9306 c_parser_consume_token (parser
);
9309 tree property
, ivar
;
9310 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9312 c_parser_error (parser
, "expected identifier");
9313 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9314 /* Once we find the semicolon, we can resume normal parsing.
9315 We have to reset parser->error manually because
9316 c_parser_skip_until_found() won't reset it for us if the
9317 next token is precisely a semicolon. */
9318 parser
->error
= false;
9321 property
= c_parser_peek_token (parser
)->value
;
9322 c_parser_consume_token (parser
);
9323 if (c_parser_next_token_is (parser
, CPP_EQ
))
9325 c_parser_consume_token (parser
);
9326 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9328 c_parser_error (parser
, "expected identifier");
9329 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9330 parser
->error
= false;
9333 ivar
= c_parser_peek_token (parser
)->value
;
9334 c_parser_consume_token (parser
);
9338 list
= chainon (list
, build_tree_list (ivar
, property
));
9339 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9340 c_parser_consume_token (parser
);
9344 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9345 objc_add_synthesize_declaration (loc
, list
);
9348 /* Parse an Objective-C @dynamic declaration. The syntax is:
9350 objc-dynamic-declaration:
9351 @dynamic identifier-list ;
9354 @dynamic MyProperty;
9355 @dynamic MyProperty, AnotherProperty;
9357 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9358 for C++. Keep them in sync.
9361 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9363 tree list
= NULL_TREE
;
9365 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9366 loc
= c_parser_peek_token (parser
)->location
;
9368 c_parser_consume_token (parser
);
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 parser
->error
= false;
9379 property
= c_parser_peek_token (parser
)->value
;
9380 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9381 c_parser_consume_token (parser
);
9382 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9383 c_parser_consume_token (parser
);
9387 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9388 objc_add_dynamic_declaration (loc
, list
);
9392 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9393 should be considered, statements. ALLOW_STMT is true if we're within
9394 the context of a function and such pragmas are to be allowed. Returns
9395 true if we actually parsed such a pragma. */
9398 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9402 id
= c_parser_peek_token (parser
)->pragma_kind
;
9403 gcc_assert (id
!= PRAGMA_NONE
);
9407 case PRAGMA_OMP_BARRIER
:
9408 if (context
!= pragma_compound
)
9410 if (context
== pragma_stmt
)
9411 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9412 "used in compound statements");
9415 c_parser_omp_barrier (parser
);
9418 case PRAGMA_OMP_FLUSH
:
9419 if (context
!= pragma_compound
)
9421 if (context
== pragma_stmt
)
9422 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9423 "used in compound statements");
9426 c_parser_omp_flush (parser
);
9429 case PRAGMA_OMP_TASKWAIT
:
9430 if (context
!= pragma_compound
)
9432 if (context
== pragma_stmt
)
9433 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9434 "used in compound statements");
9437 c_parser_omp_taskwait (parser
);
9440 case PRAGMA_OMP_TASKYIELD
:
9441 if (context
!= pragma_compound
)
9443 if (context
== pragma_stmt
)
9444 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9445 "used in compound statements");
9448 c_parser_omp_taskyield (parser
);
9451 case PRAGMA_OMP_CANCEL
:
9452 if (context
!= pragma_compound
)
9454 if (context
== pragma_stmt
)
9455 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9456 "used in compound statements");
9459 c_parser_omp_cancel (parser
);
9462 case PRAGMA_OMP_CANCELLATION_POINT
:
9463 if (context
!= pragma_compound
)
9465 if (context
== pragma_stmt
)
9466 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9467 "only be used in compound statements");
9470 c_parser_omp_cancellation_point (parser
);
9473 case PRAGMA_OMP_THREADPRIVATE
:
9474 c_parser_omp_threadprivate (parser
);
9477 case PRAGMA_OMP_TARGET
:
9478 return c_parser_omp_target (parser
, context
);
9480 case PRAGMA_OMP_END_DECLARE_TARGET
:
9481 c_parser_omp_end_declare_target (parser
);
9484 case PRAGMA_OMP_SECTION
:
9485 error_at (c_parser_peek_token (parser
)->location
,
9486 "%<#pragma omp section%> may only be used in "
9487 "%<#pragma omp sections%> construct");
9488 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9491 case PRAGMA_OMP_DECLARE_REDUCTION
:
9492 c_parser_omp_declare (parser
, context
);
9495 c_parser_consume_pragma (parser
);
9496 c_parser_skip_to_pragma_eol (parser
);
9497 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9498 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9499 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9501 c_parser_error (parser
, "for, while or do statement expected");
9504 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9505 c_parser_for_statement (parser
, true);
9506 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9507 c_parser_while_statement (parser
, true);
9509 c_parser_do_statement (parser
, true);
9512 case PRAGMA_GCC_PCH_PREPROCESS
:
9513 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9514 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9517 case PRAGMA_CILK_SIMD
:
9518 if (!c_parser_cilk_verify_simd (parser
, context
))
9520 c_parser_consume_pragma (parser
);
9521 c_parser_cilk_simd (parser
);
9525 if (id
< PRAGMA_FIRST_EXTERNAL
)
9527 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9530 c_parser_error (parser
, "expected declaration specifiers");
9531 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9534 c_parser_omp_construct (parser
);
9540 c_parser_consume_pragma (parser
);
9541 c_invoke_pragma_handler (id
);
9543 /* Skip to EOL, but suppress any error message. Those will have been
9544 generated by the handler routine through calling error, as opposed
9545 to calling c_parser_error. */
9546 parser
->error
= true;
9547 c_parser_skip_to_pragma_eol (parser
);
9552 /* The interface the pragma parsers have to the lexer. */
9555 pragma_lex (tree
*value
)
9557 c_token
*tok
= c_parser_peek_token (the_parser
);
9558 enum cpp_ttype ret
= tok
->type
;
9560 *value
= tok
->value
;
9561 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9565 if (ret
== CPP_KEYWORD
)
9567 c_parser_consume_token (the_parser
);
9574 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9578 c_parser_consume_pragma (parser
);
9579 if (c_parser_next_token_is (parser
, CPP_STRING
))
9581 name
= c_parser_peek_token (parser
)->value
;
9582 c_parser_consume_token (parser
);
9585 c_parser_error (parser
, "expected string literal");
9586 c_parser_skip_to_pragma_eol (parser
);
9589 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9592 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9594 /* Returns name of the next clause.
9595 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9596 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9597 returned and the token is consumed. */
9599 static pragma_omp_clause
9600 c_parser_omp_clause_name (c_parser
*parser
)
9602 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9604 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9605 result
= PRAGMA_OMP_CLAUSE_IF
;
9606 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9607 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9608 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9609 result
= PRAGMA_OMP_CLAUSE_FOR
;
9610 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9612 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9617 if (!strcmp ("aligned", p
))
9618 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9621 if (!strcmp ("collapse", p
))
9622 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9623 else if (!strcmp ("copyin", p
))
9624 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9625 else if (!strcmp ("copyprivate", p
))
9626 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9629 if (!strcmp ("depend", p
))
9630 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9631 else if (!strcmp ("device", p
))
9632 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9633 else if (!strcmp ("dist_schedule", p
))
9634 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9637 if (!strcmp ("final", p
))
9638 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9639 else if (!strcmp ("firstprivate", p
))
9640 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9641 else if (!strcmp ("from", p
))
9642 result
= PRAGMA_OMP_CLAUSE_FROM
;
9645 if (!strcmp ("inbranch", p
))
9646 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9649 if (!strcmp ("lastprivate", p
))
9650 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9651 else if (!strcmp ("linear", p
))
9652 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9655 if (!strcmp ("map", p
))
9656 result
= PRAGMA_OMP_CLAUSE_MAP
;
9657 else if (!strcmp ("mergeable", p
))
9658 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9659 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9660 result
= PRAGMA_CILK_CLAUSE_MASK
;
9663 if (!strcmp ("notinbranch", p
))
9664 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9665 else if (!strcmp ("nowait", p
))
9666 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9667 else if (!strcmp ("num_teams", p
))
9668 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9669 else if (!strcmp ("num_threads", p
))
9670 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9671 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9672 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9675 if (!strcmp ("ordered", p
))
9676 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9679 if (!strcmp ("parallel", p
))
9680 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9681 else if (!strcmp ("private", p
))
9682 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9683 else if (!strcmp ("proc_bind", p
))
9684 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9687 if (!strcmp ("reduction", p
))
9688 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9691 if (!strcmp ("safelen", p
))
9692 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9693 else if (!strcmp ("schedule", p
))
9694 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9695 else if (!strcmp ("sections", p
))
9696 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9697 else if (!strcmp ("shared", p
))
9698 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9699 else if (!strcmp ("simdlen", p
))
9700 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9703 if (!strcmp ("taskgroup", p
))
9704 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9705 else if (!strcmp ("thread_limit", p
))
9706 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9707 else if (!strcmp ("to", p
))
9708 result
= PRAGMA_OMP_CLAUSE_TO
;
9711 if (!strcmp ("uniform", p
))
9712 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9713 else if (!strcmp ("untied", p
))
9714 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9717 if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9718 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9723 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9724 c_parser_consume_token (parser
);
9729 /* Validate that a clause of the given type does not already exist. */
9732 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9737 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9738 if (OMP_CLAUSE_CODE (c
) == code
)
9740 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9741 error_at (loc
, "too many %qs clauses", name
);
9749 variable-list , identifier
9751 If KIND is nonzero, create the appropriate node and install the
9752 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9753 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9755 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9756 return the list created. */
9759 c_parser_omp_variable_list (c_parser
*parser
,
9760 location_t clause_loc
,
9761 enum omp_clause_code kind
, tree list
)
9763 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9764 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9765 c_parser_error (parser
, "expected identifier");
9767 while (c_parser_next_token_is (parser
, CPP_NAME
)
9768 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9770 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9774 undeclared_variable (c_parser_peek_token (parser
)->location
,
9775 c_parser_peek_token (parser
)->value
);
9776 t
= error_mark_node
;
9779 c_parser_consume_token (parser
);
9781 if (t
== error_mark_node
)
9787 case OMP_CLAUSE_MAP
:
9788 case OMP_CLAUSE_FROM
:
9790 case OMP_CLAUSE_DEPEND
:
9791 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9793 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9795 c_parser_consume_token (parser
);
9796 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9797 low_bound
= c_parser_expression (parser
).value
;
9798 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9799 length
= integer_one_node
;
9803 if (!c_parser_require (parser
, CPP_COLON
,
9806 t
= error_mark_node
;
9809 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9810 length
= c_parser_expression (parser
).value
;
9812 /* Look for the closing `]'. */
9813 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9816 t
= error_mark_node
;
9819 t
= tree_cons (low_bound
, length
, t
);
9826 if (t
!= error_mark_node
)
9828 tree u
= build_omp_clause (clause_loc
, kind
);
9829 OMP_CLAUSE_DECL (u
) = t
;
9830 OMP_CLAUSE_CHAIN (u
) = list
;
9835 list
= tree_cons (t
, NULL_TREE
, list
);
9837 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9840 c_parser_consume_token (parser
);
9846 /* Similarly, but expect leading and trailing parenthesis. This is a very
9847 common case for omp clauses. */
9850 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9853 /* The clauses location. */
9854 location_t loc
= c_parser_peek_token (parser
)->location
;
9856 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9858 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9859 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9865 collapse ( constant-expression ) */
9868 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9870 tree c
, num
= error_mark_node
;
9874 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9876 loc
= c_parser_peek_token (parser
)->location
;
9877 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9879 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9880 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9882 if (num
== error_mark_node
)
9884 mark_exp_read (num
);
9885 num
= c_fully_fold (num
, false, NULL
);
9886 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9887 || !tree_fits_shwi_p (num
)
9888 || (n
= tree_to_shwi (num
)) <= 0
9892 "collapse argument needs positive constant integer expression");
9895 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9896 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9897 OMP_CLAUSE_CHAIN (c
) = list
;
9902 copyin ( variable-list ) */
9905 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9907 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9911 copyprivate ( variable-list ) */
9914 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9916 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9920 default ( shared | none ) */
9923 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9925 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9926 location_t loc
= c_parser_peek_token (parser
)->location
;
9929 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9931 if (c_parser_next_token_is (parser
, CPP_NAME
))
9933 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9938 if (strcmp ("none", p
) != 0)
9940 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9944 if (strcmp ("shared", p
) != 0)
9946 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9953 c_parser_consume_token (parser
);
9958 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9960 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9962 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9965 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9966 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9967 OMP_CLAUSE_CHAIN (c
) = list
;
9968 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9974 firstprivate ( variable-list ) */
9977 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9979 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9983 final ( expression ) */
9986 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9988 location_t loc
= c_parser_peek_token (parser
)->location
;
9989 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9991 tree t
= c_parser_paren_condition (parser
);
9994 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9996 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9997 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9998 OMP_CLAUSE_CHAIN (c
) = list
;
10002 c_parser_error (parser
, "expected %<(%>");
10008 if ( expression ) */
10011 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10013 location_t loc
= c_parser_peek_token (parser
)->location
;
10014 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10016 tree t
= c_parser_paren_condition (parser
);
10019 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10021 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10022 OMP_CLAUSE_IF_EXPR (c
) = t
;
10023 OMP_CLAUSE_CHAIN (c
) = list
;
10027 c_parser_error (parser
, "expected %<(%>");
10033 lastprivate ( variable-list ) */
10036 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10038 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10045 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10049 /* FIXME: Should we allow duplicates? */
10050 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10052 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10053 OMP_CLAUSE_MERGEABLE
);
10054 OMP_CLAUSE_CHAIN (c
) = list
;
10063 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10066 location_t loc
= c_parser_peek_token (parser
)->location
;
10068 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10070 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10071 OMP_CLAUSE_CHAIN (c
) = list
;
10076 num_threads ( expression ) */
10079 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10081 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10082 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10084 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10085 tree c
, t
= c_parser_expression (parser
).value
;
10087 t
= c_fully_fold (t
, false, NULL
);
10089 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10091 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10093 c_parser_error (parser
, "expected integer expression");
10097 /* Attempt to statically determine when the number isn't positive. */
10098 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10099 build_int_cst (TREE_TYPE (t
), 0));
10100 if (CAN_HAVE_LOCATION_P (c
))
10101 SET_EXPR_LOCATION (c
, expr_loc
);
10102 if (c
== boolean_true_node
)
10104 warning_at (expr_loc
, 0,
10105 "%<num_threads%> value must be positive");
10106 t
= integer_one_node
;
10109 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10111 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10112 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10113 OMP_CLAUSE_CHAIN (c
) = list
;
10124 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10128 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10130 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10131 OMP_CLAUSE_ORDERED
);
10132 OMP_CLAUSE_CHAIN (c
) = list
;
10138 private ( variable-list ) */
10141 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10143 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10147 reduction ( reduction-operator : variable-list )
10149 reduction-operator:
10150 One of: + * - & ^ | && ||
10154 reduction-operator:
10155 One of: + * - & ^ | && || max min
10159 reduction-operator:
10160 One of: + * - & ^ | && ||
10164 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10166 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10167 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10169 enum tree_code code
= ERROR_MARK
;
10170 tree reduc_id
= NULL_TREE
;
10172 switch (c_parser_peek_token (parser
)->type
)
10184 code
= BIT_AND_EXPR
;
10187 code
= BIT_XOR_EXPR
;
10190 code
= BIT_IOR_EXPR
;
10193 code
= TRUTH_ANDIF_EXPR
;
10196 code
= TRUTH_ORIF_EXPR
;
10201 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10202 if (strcmp (p
, "min") == 0)
10207 if (strcmp (p
, "max") == 0)
10212 reduc_id
= c_parser_peek_token (parser
)->value
;
10216 c_parser_error (parser
,
10217 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10218 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10219 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10222 c_parser_consume_token (parser
);
10223 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10224 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10228 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10229 OMP_CLAUSE_REDUCTION
, list
);
10230 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10232 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10233 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10234 if (code
== ERROR_MARK
10235 || !(INTEGRAL_TYPE_P (type
)
10236 || TREE_CODE (type
) == REAL_TYPE
10237 || TREE_CODE (type
) == COMPLEX_TYPE
))
10238 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10239 = c_omp_reduction_lookup (reduc_id
,
10240 TYPE_MAIN_VARIANT (type
));
10245 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10251 schedule ( schedule-kind )
10252 schedule ( schedule-kind , expression )
10255 static | dynamic | guided | runtime | auto
10259 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10262 location_t loc
= c_parser_peek_token (parser
)->location
;
10264 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10267 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10269 if (c_parser_next_token_is (parser
, CPP_NAME
))
10271 tree kind
= c_parser_peek_token (parser
)->value
;
10272 const char *p
= IDENTIFIER_POINTER (kind
);
10277 if (strcmp ("dynamic", p
) != 0)
10279 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10283 if (strcmp ("guided", p
) != 0)
10285 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10289 if (strcmp ("runtime", p
) != 0)
10291 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10298 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10299 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10300 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10301 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10305 c_parser_consume_token (parser
);
10306 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10309 c_parser_consume_token (parser
);
10311 here
= c_parser_peek_token (parser
)->location
;
10312 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10314 t
= c_fully_fold (t
, false, NULL
);
10316 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10317 error_at (here
, "schedule %<runtime%> does not take "
10318 "a %<chunk_size%> parameter");
10319 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10321 "schedule %<auto%> does not take "
10322 "a %<chunk_size%> parameter");
10323 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10324 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10326 c_parser_error (parser
, "expected integer expression");
10328 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10331 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10332 "expected %<,%> or %<)%>");
10334 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10335 OMP_CLAUSE_CHAIN (c
) = list
;
10339 c_parser_error (parser
, "invalid schedule kind");
10340 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10345 shared ( variable-list ) */
10348 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10350 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10357 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10361 /* FIXME: Should we allow duplicates? */
10362 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10364 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10365 OMP_CLAUSE_UNTIED
);
10366 OMP_CLAUSE_CHAIN (c
) = list
;
10376 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10377 enum omp_clause_code code
, tree list
)
10379 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10381 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10382 OMP_CLAUSE_CHAIN (c
) = list
;
10394 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10395 enum omp_clause_code code
, tree list
)
10397 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10398 OMP_CLAUSE_CHAIN (c
) = list
;
10404 num_teams ( expression ) */
10407 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10409 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10410 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10412 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10413 tree c
, t
= c_parser_expression (parser
).value
;
10415 t
= c_fully_fold (t
, false, NULL
);
10417 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10419 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10421 c_parser_error (parser
, "expected integer expression");
10425 /* Attempt to statically determine when the number isn't positive. */
10426 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10427 build_int_cst (TREE_TYPE (t
), 0));
10428 if (CAN_HAVE_LOCATION_P (c
))
10429 SET_EXPR_LOCATION (c
, expr_loc
);
10430 if (c
== boolean_true_node
)
10432 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10433 t
= integer_one_node
;
10436 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10438 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10439 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10440 OMP_CLAUSE_CHAIN (c
) = list
;
10448 thread_limit ( expression ) */
10451 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10453 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
10454 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10456 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10457 tree c
, t
= c_parser_expression (parser
).value
;
10459 t
= c_fully_fold (t
, false, NULL
);
10461 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10463 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10465 c_parser_error (parser
, "expected integer expression");
10469 /* Attempt to statically determine when the number isn't positive. */
10470 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10471 build_int_cst (TREE_TYPE (t
), 0));
10472 if (CAN_HAVE_LOCATION_P (c
))
10473 SET_EXPR_LOCATION (c
, expr_loc
);
10474 if (c
== boolean_true_node
)
10476 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10477 t
= integer_one_node
;
10480 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10483 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10484 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10485 OMP_CLAUSE_CHAIN (c
) = list
;
10493 aligned ( variable-list )
10494 aligned ( variable-list : constant-expression ) */
10497 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10499 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10502 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10505 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10506 OMP_CLAUSE_ALIGNED
, list
);
10508 if (c_parser_next_token_is (parser
, CPP_COLON
))
10510 c_parser_consume_token (parser
);
10511 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10512 mark_exp_read (alignment
);
10513 alignment
= c_fully_fold (alignment
, false, NULL
);
10514 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10515 && TREE_CODE (alignment
) != INTEGER_CST
10516 && tree_int_cst_sgn (alignment
) != 1)
10518 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10519 "be positive constant integer expression");
10520 alignment
= NULL_TREE
;
10523 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10524 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10527 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10532 linear ( variable-list )
10533 linear ( variable-list : expression ) */
10536 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
10538 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10541 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10544 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10545 OMP_CLAUSE_LINEAR
, list
);
10547 if (c_parser_next_token_is (parser
, CPP_COLON
))
10549 c_parser_consume_token (parser
);
10550 step
= c_parser_expression (parser
).value
;
10551 mark_exp_read (step
);
10552 step
= c_fully_fold (step
, false, NULL
);
10553 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
10555 sorry ("using parameters for %<linear%> step is not supported yet");
10556 step
= integer_one_node
;
10558 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10560 error_at (clause_loc
, "%<linear%> clause step expression must "
10562 step
= integer_one_node
;
10567 step
= integer_one_node
;
10569 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10571 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10574 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10579 safelen ( constant-expression ) */
10582 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10584 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10587 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10590 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10592 t
= c_fully_fold (t
, false, NULL
);
10593 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10594 && TREE_CODE (t
) != INTEGER_CST
10595 && tree_int_cst_sgn (t
) != 1)
10597 error_at (clause_loc
, "%<safelen%> clause expression must "
10598 "be positive constant integer expression");
10602 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10603 if (t
== NULL_TREE
|| t
== error_mark_node
)
10606 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10608 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10609 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10610 OMP_CLAUSE_CHAIN (c
) = list
;
10615 simdlen ( constant-expression ) */
10618 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10620 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10623 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10626 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10628 t
= c_fully_fold (t
, false, NULL
);
10629 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10630 && TREE_CODE (t
) != INTEGER_CST
10631 && tree_int_cst_sgn (t
) != 1)
10633 error_at (clause_loc
, "%<simdlen%> clause expression must "
10634 "be positive constant integer expression");
10638 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10639 if (t
== NULL_TREE
|| t
== error_mark_node
)
10642 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10644 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10645 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10646 OMP_CLAUSE_CHAIN (c
) = list
;
10651 depend ( depend-kind: variable-list )
10654 in | out | inout */
10657 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10659 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10660 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10663 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10666 if (c_parser_next_token_is (parser
, CPP_NAME
))
10668 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10669 if (strcmp ("in", p
) == 0)
10670 kind
= OMP_CLAUSE_DEPEND_IN
;
10671 else if (strcmp ("inout", p
) == 0)
10672 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10673 else if (strcmp ("out", p
) == 0)
10674 kind
= OMP_CLAUSE_DEPEND_OUT
;
10681 c_parser_consume_token (parser
);
10682 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10685 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10686 OMP_CLAUSE_DEPEND
, list
);
10688 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10689 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10691 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10695 c_parser_error (parser
, "invalid depend kind");
10697 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10702 map ( map-kind: variable-list )
10703 map ( variable-list )
10706 alloc | to | from | tofrom */
10709 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10711 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10712 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10715 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10718 if (c_parser_next_token_is (parser
, CPP_NAME
)
10719 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10721 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10722 if (strcmp ("alloc", p
) == 0)
10723 kind
= OMP_CLAUSE_MAP_ALLOC
;
10724 else if (strcmp ("to", p
) == 0)
10725 kind
= OMP_CLAUSE_MAP_TO
;
10726 else if (strcmp ("from", p
) == 0)
10727 kind
= OMP_CLAUSE_MAP_FROM
;
10728 else if (strcmp ("tofrom", p
) == 0)
10729 kind
= OMP_CLAUSE_MAP_TOFROM
;
10732 c_parser_error (parser
, "invalid map kind");
10733 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10737 c_parser_consume_token (parser
);
10738 c_parser_consume_token (parser
);
10741 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10743 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10744 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10746 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10751 device ( expression ) */
10754 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10756 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10757 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10759 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10761 t
= c_fully_fold (t
, false, NULL
);
10763 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10765 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10767 c_parser_error (parser
, "expected integer expression");
10771 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10773 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10774 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10775 OMP_CLAUSE_CHAIN (c
) = list
;
10783 dist_schedule ( static )
10784 dist_schedule ( static , expression ) */
10787 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10789 tree c
, t
= NULL_TREE
;
10790 location_t loc
= c_parser_peek_token (parser
)->location
;
10792 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10795 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10797 c_parser_error (parser
, "invalid dist_schedule kind");
10798 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10803 c_parser_consume_token (parser
);
10804 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10806 c_parser_consume_token (parser
);
10808 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10810 t
= c_fully_fold (t
, false, NULL
);
10811 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10814 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10815 "expected %<,%> or %<)%>");
10817 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10818 if (t
== error_mark_node
)
10821 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10822 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10823 OMP_CLAUSE_CHAIN (c
) = list
;
10828 proc_bind ( proc-bind-kind )
10831 master | close | spread */
10834 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10836 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10837 enum omp_clause_proc_bind_kind kind
;
10840 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10843 if (c_parser_next_token_is (parser
, CPP_NAME
))
10845 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10846 if (strcmp ("master", p
) == 0)
10847 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10848 else if (strcmp ("close", p
) == 0)
10849 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10850 else if (strcmp ("spread", p
) == 0)
10851 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10858 c_parser_consume_token (parser
);
10859 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10860 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10861 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10862 OMP_CLAUSE_CHAIN (c
) = list
;
10866 c_parser_error (parser
, "invalid proc_bind kind");
10867 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10872 to ( variable-list ) */
10875 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10877 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10881 from ( variable-list ) */
10884 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10886 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10890 uniform ( variable-list ) */
10893 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10895 /* The clauses location. */
10896 location_t loc
= c_parser_peek_token (parser
)->location
;
10898 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10900 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10902 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10907 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10908 is a bitmask in MASK. Return the list of clauses found; the result
10909 of clause default goes in *pdefault. */
10912 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10913 const char *where
, bool finish_p
= true)
10915 tree clauses
= NULL
;
10916 bool first
= true, cilk_simd_fn
= false;
10918 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10921 pragma_omp_clause c_kind
;
10922 const char *c_name
;
10923 tree prev
= clauses
;
10925 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10926 c_parser_consume_token (parser
);
10928 here
= c_parser_peek_token (parser
)->location
;
10929 c_kind
= c_parser_omp_clause_name (parser
);
10933 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10934 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10935 c_name
= "collapse";
10937 case PRAGMA_OMP_CLAUSE_COPYIN
:
10938 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10941 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10942 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10943 c_name
= "copyprivate";
10945 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10946 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10947 c_name
= "default";
10949 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
10950 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
10951 c_name
= "firstprivate";
10953 case PRAGMA_OMP_CLAUSE_FINAL
:
10954 clauses
= c_parser_omp_clause_final (parser
, clauses
);
10957 case PRAGMA_OMP_CLAUSE_IF
:
10958 clauses
= c_parser_omp_clause_if (parser
, clauses
);
10961 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
10962 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
10963 c_name
= "lastprivate";
10965 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
10966 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
10967 c_name
= "mergeable";
10969 case PRAGMA_OMP_CLAUSE_NOWAIT
:
10970 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
10973 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
10974 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
10975 c_name
= "num_threads";
10977 case PRAGMA_OMP_CLAUSE_ORDERED
:
10978 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
10979 c_name
= "ordered";
10981 case PRAGMA_OMP_CLAUSE_PRIVATE
:
10982 clauses
= c_parser_omp_clause_private (parser
, clauses
);
10983 c_name
= "private";
10985 case PRAGMA_OMP_CLAUSE_REDUCTION
:
10986 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
10987 c_name
= "reduction";
10989 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10990 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10991 c_name
= "schedule";
10993 case PRAGMA_OMP_CLAUSE_SHARED
:
10994 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10997 case PRAGMA_OMP_CLAUSE_UNTIED
:
10998 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11001 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11002 case PRAGMA_CILK_CLAUSE_MASK
:
11003 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11005 c_name
= "inbranch";
11007 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11008 case PRAGMA_CILK_CLAUSE_NOMASK
:
11009 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11011 c_name
= "notinbranch";
11013 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11015 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11017 c_name
= "parallel";
11021 error_at (here
, "%qs must be the first clause of %qs",
11026 case PRAGMA_OMP_CLAUSE_FOR
:
11028 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11032 goto clause_not_first
;
11034 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11036 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11038 c_name
= "sections";
11040 goto clause_not_first
;
11042 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11044 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11046 c_name
= "taskgroup";
11048 goto clause_not_first
;
11050 case PRAGMA_OMP_CLAUSE_TO
:
11051 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11054 case PRAGMA_OMP_CLAUSE_FROM
:
11055 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11058 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11059 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11060 c_name
= "uniform";
11062 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11063 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11064 c_name
= "num_teams";
11066 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11067 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11068 c_name
= "thread_limit";
11070 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11071 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11072 c_name
= "aligned";
11074 case PRAGMA_OMP_CLAUSE_LINEAR
:
11075 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11076 cilk_simd_fn
= true;
11077 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11080 case PRAGMA_OMP_CLAUSE_DEPEND
:
11081 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11084 case PRAGMA_OMP_CLAUSE_MAP
:
11085 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11088 case PRAGMA_OMP_CLAUSE_DEVICE
:
11089 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11092 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11093 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11094 c_name
= "dist_schedule";
11096 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11097 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11098 c_name
= "proc_bind";
11100 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11101 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11102 c_name
= "safelen";
11104 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11105 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11106 c_name
= "simdlen";
11108 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11109 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11110 c_name
= "simdlen";
11113 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11119 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11121 /* Remove the invalid clause(s) from the list to avoid
11122 confusing the rest of the compiler. */
11124 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11129 c_parser_skip_to_pragma_eol (parser
);
11132 return c_finish_omp_clauses (clauses
);
11141 In practice, we're also interested in adding the statement to an
11142 outer node. So it is convenient if we work around the fact that
11143 c_parser_statement calls add_stmt. */
11146 c_parser_omp_structured_block (c_parser
*parser
)
11148 tree stmt
= push_stmt_list ();
11149 c_parser_statement (parser
);
11150 return pop_stmt_list (stmt
);
11154 # pragma omp atomic new-line
11158 x binop= expr | x++ | ++x | x-- | --x
11160 +, *, -, /, &, ^, |, <<, >>
11162 where x is an lvalue expression with scalar type.
11165 # pragma omp atomic new-line
11168 # pragma omp atomic read new-line
11171 # pragma omp atomic write new-line
11174 # pragma omp atomic update new-line
11177 # pragma omp atomic capture new-line
11180 # pragma omp atomic capture new-line
11188 expression-stmt | x = x binop expr
11190 v = expression-stmt
11192 { v = x; update-stmt; } | { update-stmt; v = x; }
11196 expression-stmt | x = x binop expr | x = expr binop x
11200 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11202 where x and v are lvalue expressions with scalar type.
11204 LOC is the location of the #pragma token. */
11207 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11209 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11210 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11211 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11212 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11213 struct c_expr expr
;
11215 bool structured_block
= false;
11216 bool swapped
= false;
11217 bool seq_cst
= false;
11219 if (c_parser_next_token_is (parser
, CPP_NAME
))
11221 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11222 if (!strcmp (p
, "seq_cst"))
11225 c_parser_consume_token (parser
);
11226 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11227 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11228 c_parser_consume_token (parser
);
11231 if (c_parser_next_token_is (parser
, CPP_NAME
))
11233 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11235 if (!strcmp (p
, "read"))
11236 code
= OMP_ATOMIC_READ
;
11237 else if (!strcmp (p
, "write"))
11239 else if (!strcmp (p
, "update"))
11241 else if (!strcmp (p
, "capture"))
11242 code
= OMP_ATOMIC_CAPTURE_NEW
;
11246 c_parser_consume_token (parser
);
11250 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11251 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11252 c_parser_consume_token (parser
);
11254 if (c_parser_next_token_is (parser
, CPP_NAME
))
11257 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11258 if (!strcmp (p
, "seq_cst"))
11261 c_parser_consume_token (parser
);
11265 c_parser_skip_to_pragma_eol (parser
);
11269 case OMP_ATOMIC_READ
:
11270 case NOP_EXPR
: /* atomic write */
11271 v
= c_parser_unary_expression (parser
).value
;
11272 v
= c_fully_fold (v
, false, NULL
);
11273 if (v
== error_mark_node
)
11275 loc
= c_parser_peek_token (parser
)->location
;
11276 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11278 if (code
== NOP_EXPR
)
11279 lhs
= c_parser_expression (parser
).value
;
11281 lhs
= c_parser_unary_expression (parser
).value
;
11282 lhs
= c_fully_fold (lhs
, false, NULL
);
11283 if (lhs
== error_mark_node
)
11285 if (code
== NOP_EXPR
)
11287 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11295 case OMP_ATOMIC_CAPTURE_NEW
:
11296 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11298 c_parser_consume_token (parser
);
11299 structured_block
= true;
11303 v
= c_parser_unary_expression (parser
).value
;
11304 v
= c_fully_fold (v
, false, NULL
);
11305 if (v
== error_mark_node
)
11307 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11315 /* For structured_block case we don't know yet whether
11316 old or new x should be captured. */
11318 eloc
= c_parser_peek_token (parser
)->location
;
11319 expr
= c_parser_unary_expression (parser
);
11321 expr
= default_function_array_conversion (eloc
, expr
);
11322 unfolded_lhs
= expr
.value
;
11323 lhs
= c_fully_fold (lhs
, false, NULL
);
11325 switch (TREE_CODE (lhs
))
11329 c_parser_skip_to_end_of_block_or_statement (parser
);
11330 if (structured_block
)
11332 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11333 c_parser_consume_token (parser
);
11334 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11336 c_parser_skip_to_end_of_block_or_statement (parser
);
11337 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11338 c_parser_consume_token (parser
);
11343 case POSTINCREMENT_EXPR
:
11344 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11345 code
= OMP_ATOMIC_CAPTURE_OLD
;
11347 case PREINCREMENT_EXPR
:
11348 lhs
= TREE_OPERAND (lhs
, 0);
11349 unfolded_lhs
= NULL_TREE
;
11350 opcode
= PLUS_EXPR
;
11351 rhs
= integer_one_node
;
11354 case POSTDECREMENT_EXPR
:
11355 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11356 code
= OMP_ATOMIC_CAPTURE_OLD
;
11358 case PREDECREMENT_EXPR
:
11359 lhs
= TREE_OPERAND (lhs
, 0);
11360 unfolded_lhs
= NULL_TREE
;
11361 opcode
= MINUS_EXPR
;
11362 rhs
= integer_one_node
;
11365 case COMPOUND_EXPR
:
11366 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11367 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11368 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11369 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11370 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11371 (TREE_OPERAND (lhs
, 1), 0), 0)))
11373 /* Undo effects of boolean_increment for post {in,de}crement. */
11374 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11377 if (TREE_CODE (lhs
) == MODIFY_EXPR
11378 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11380 /* Undo effects of boolean_increment. */
11381 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11383 /* This is pre or post increment. */
11384 rhs
= TREE_OPERAND (lhs
, 1);
11385 lhs
= TREE_OPERAND (lhs
, 0);
11386 unfolded_lhs
= NULL_TREE
;
11388 if (code
== OMP_ATOMIC_CAPTURE_NEW
11389 && !structured_block
11390 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11391 code
= OMP_ATOMIC_CAPTURE_OLD
;
11394 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11395 && TREE_OPERAND (lhs
, 0)
11396 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11398 /* This is pre or post decrement. */
11399 rhs
= TREE_OPERAND (lhs
, 1);
11400 lhs
= TREE_OPERAND (lhs
, 0);
11401 unfolded_lhs
= NULL_TREE
;
11403 if (code
== OMP_ATOMIC_CAPTURE_NEW
11404 && !structured_block
11405 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11406 code
= OMP_ATOMIC_CAPTURE_OLD
;
11412 switch (c_parser_peek_token (parser
)->type
)
11415 opcode
= MULT_EXPR
;
11418 opcode
= TRUNC_DIV_EXPR
;
11421 opcode
= PLUS_EXPR
;
11424 opcode
= MINUS_EXPR
;
11426 case CPP_LSHIFT_EQ
:
11427 opcode
= LSHIFT_EXPR
;
11429 case CPP_RSHIFT_EQ
:
11430 opcode
= RSHIFT_EXPR
;
11433 opcode
= BIT_AND_EXPR
;
11436 opcode
= BIT_IOR_EXPR
;
11439 opcode
= BIT_XOR_EXPR
;
11442 c_parser_consume_token (parser
);
11443 eloc
= c_parser_peek_token (parser
)->location
;
11444 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11446 switch (TREE_CODE (rhs1
))
11449 case TRUNC_DIV_EXPR
:
11457 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11459 opcode
= TREE_CODE (rhs1
);
11460 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11461 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11464 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11466 opcode
= TREE_CODE (rhs1
);
11467 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11468 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11469 swapped
= !commutative_tree_code (opcode
);
11478 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11480 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11482 code
= OMP_ATOMIC_CAPTURE_OLD
;
11485 expr
= default_function_array_read_conversion (eloc
, expr
);
11486 unfolded_lhs1
= expr
.value
;
11487 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11489 c_parser_consume_token (parser
);
11492 if (structured_block
)
11495 expr
= default_function_array_read_conversion (eloc
, expr
);
11496 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11501 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11504 c_parser_error (parser
,
11505 "invalid operator for %<#pragma omp atomic%>");
11509 /* Arrange to pass the location of the assignment operator to
11510 c_finish_omp_atomic. */
11511 loc
= c_parser_peek_token (parser
)->location
;
11512 c_parser_consume_token (parser
);
11513 eloc
= c_parser_peek_token (parser
)->location
;
11514 expr
= c_parser_expression (parser
);
11515 expr
= default_function_array_read_conversion (eloc
, expr
);
11517 rhs
= c_fully_fold (rhs
, false, NULL
);
11521 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11523 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11525 v
= c_parser_unary_expression (parser
).value
;
11526 v
= c_fully_fold (v
, false, NULL
);
11527 if (v
== error_mark_node
)
11529 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11531 eloc
= c_parser_peek_token (parser
)->location
;
11532 expr
= c_parser_unary_expression (parser
);
11534 expr
= default_function_array_read_conversion (eloc
, expr
);
11535 unfolded_lhs1
= expr
.value
;
11536 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11537 if (lhs1
== error_mark_node
)
11540 if (structured_block
)
11542 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11543 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11546 if (unfolded_lhs
&& unfolded_lhs1
11547 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11549 error ("%<#pragma omp atomic capture%> uses two different "
11550 "expressions for memory");
11551 stmt
= error_mark_node
;
11554 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11556 if (stmt
!= error_mark_node
)
11559 if (!structured_block
)
11560 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11565 # pragma omp barrier new-line
11569 c_parser_omp_barrier (c_parser
*parser
)
11571 location_t loc
= c_parser_peek_token (parser
)->location
;
11572 c_parser_consume_pragma (parser
);
11573 c_parser_skip_to_pragma_eol (parser
);
11575 c_finish_omp_barrier (loc
);
11579 # pragma omp critical [(name)] new-line
11582 LOC is the location of the #pragma itself. */
11585 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11587 tree stmt
, name
= NULL
;
11589 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11591 c_parser_consume_token (parser
);
11592 if (c_parser_next_token_is (parser
, CPP_NAME
))
11594 name
= c_parser_peek_token (parser
)->value
;
11595 c_parser_consume_token (parser
);
11596 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11599 c_parser_error (parser
, "expected identifier");
11601 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11602 c_parser_error (parser
, "expected %<(%> or end of line");
11603 c_parser_skip_to_pragma_eol (parser
);
11605 stmt
= c_parser_omp_structured_block (parser
);
11606 return c_finish_omp_critical (loc
, stmt
, name
);
11610 # pragma omp flush flush-vars[opt] new-line
11613 ( variable-list ) */
11616 c_parser_omp_flush (c_parser
*parser
)
11618 location_t loc
= c_parser_peek_token (parser
)->location
;
11619 c_parser_consume_pragma (parser
);
11620 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11621 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11622 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11623 c_parser_error (parser
, "expected %<(%> or end of line");
11624 c_parser_skip_to_pragma_eol (parser
);
11626 c_finish_omp_flush (loc
);
11629 /* Parse the restricted form of the for statement allowed by OpenMP.
11630 The real trick here is to determine the loop control variable early
11631 so that we can push a new decl if necessary to make it private.
11632 LOC is the location of the OMP in "#pragma omp". */
11635 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11636 tree clauses
, tree
*cclauses
)
11638 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11639 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11640 bool fail
= false, open_brace_parsed
= false;
11641 int i
, collapse
= 1, nbraces
= 0;
11642 location_t for_loc
;
11643 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11645 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11646 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11647 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
11649 gcc_assert (collapse
>= 1);
11651 declv
= make_tree_vec (collapse
);
11652 initv
= make_tree_vec (collapse
);
11653 condv
= make_tree_vec (collapse
);
11654 incrv
= make_tree_vec (collapse
);
11656 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11658 c_parser_error (parser
, "for statement expected");
11661 for_loc
= c_parser_peek_token (parser
)->location
;
11662 c_parser_consume_token (parser
);
11664 for (i
= 0; i
< collapse
; i
++)
11666 int bracecount
= 0;
11668 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11671 /* Parse the initialization declaration or expression. */
11672 if (c_parser_next_tokens_start_declaration (parser
))
11675 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11676 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11678 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11681 if (DECL_INITIAL (decl
) == error_mark_node
)
11682 decl
= error_mark_node
;
11685 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11686 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11688 struct c_expr decl_exp
;
11689 struct c_expr init_exp
;
11690 location_t init_loc
;
11692 decl_exp
= c_parser_postfix_expression (parser
);
11693 decl
= decl_exp
.value
;
11695 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11697 init_loc
= c_parser_peek_token (parser
)->location
;
11698 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11699 init_exp
= default_function_array_read_conversion (init_loc
,
11701 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11702 NOP_EXPR
, init_loc
, init_exp
.value
,
11703 init_exp
.original_type
);
11704 init
= c_process_expr_stmt (init_loc
, init
);
11706 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11711 c_parser_error (parser
,
11712 "expected iteration declaration or initialization");
11713 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11719 /* Parse the loop condition. */
11721 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11723 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11724 struct c_expr cond_expr
11725 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11727 cond
= cond_expr
.value
;
11728 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11729 cond
= c_fully_fold (cond
, false, NULL
);
11730 switch (cond_expr
.original_code
)
11738 if (code
== CILK_SIMD
)
11742 /* Can't be cond = error_mark_node, because we want to preserve
11743 the location until c_finish_omp_for. */
11744 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11747 protected_set_expr_location (cond
, cond_loc
);
11749 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11751 /* Parse the increment expression. */
11753 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11755 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11757 incr
= c_process_expr_stmt (incr_loc
,
11758 c_parser_expression (parser
).value
);
11760 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11762 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11766 TREE_VEC_ELT (declv
, i
) = decl
;
11767 TREE_VEC_ELT (initv
, i
) = init
;
11768 TREE_VEC_ELT (condv
, i
) = cond
;
11769 TREE_VEC_ELT (incrv
, i
) = incr
;
11773 if (i
== collapse
- 1)
11776 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11777 in between the collapsed for loops to be still considered perfectly
11778 nested. Hopefully the final version clarifies this.
11779 For now handle (multiple) {'s and empty statements. */
11782 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11784 c_parser_consume_token (parser
);
11787 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11789 c_parser_consume_token (parser
);
11792 else if (bracecount
11793 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11794 c_parser_consume_token (parser
);
11797 c_parser_error (parser
, "not enough perfectly nested loops");
11800 open_brace_parsed
= true;
11810 nbraces
+= bracecount
;
11813 save_break
= c_break_label
;
11814 if (code
== CILK_SIMD
)
11815 c_break_label
= build_int_cst (size_type_node
, 2);
11817 c_break_label
= size_one_node
;
11818 save_cont
= c_cont_label
;
11819 c_cont_label
= NULL_TREE
;
11820 body
= push_stmt_list ();
11822 if (open_brace_parsed
)
11824 location_t here
= c_parser_peek_token (parser
)->location
;
11825 stmt
= c_begin_compound_stmt (true);
11826 c_parser_compound_statement_nostart (parser
);
11827 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11830 add_stmt (c_parser_c99_block_statement (parser
));
11833 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11834 SET_EXPR_LOCATION (t
, loc
);
11838 body
= pop_stmt_list (body
);
11839 c_break_label
= save_break
;
11840 c_cont_label
= save_cont
;
11844 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11846 c_parser_consume_token (parser
);
11849 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11850 c_parser_consume_token (parser
);
11853 c_parser_error (parser
, "collapsed loops not perfectly nested");
11856 location_t here
= c_parser_peek_token (parser
)->location
;
11857 stmt
= c_begin_compound_stmt (true);
11859 c_parser_compound_statement_nostart (parser
);
11860 body
= c_end_compound_stmt (here
, stmt
, true);
11867 /* Only bother calling c_finish_omp_for if we haven't already generated
11868 an error from the initialization parsing. */
11871 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11872 incrv
, body
, NULL
);
11875 if (cclauses
!= NULL
11876 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11879 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11880 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11881 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11882 c
= &OMP_CLAUSE_CHAIN (*c
);
11885 for (i
= 0; i
< collapse
; i
++)
11886 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11889 c
= &OMP_CLAUSE_CHAIN (*c
);
11890 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11893 "iteration variable %qD should not be firstprivate",
11894 OMP_CLAUSE_DECL (*c
));
11895 *c
= OMP_CLAUSE_CHAIN (*c
);
11899 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11900 change it to shared (decl) in
11901 OMP_PARALLEL_CLAUSES. */
11902 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11903 OMP_CLAUSE_LASTPRIVATE
);
11904 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11905 if (code
== OMP_SIMD
)
11907 OMP_CLAUSE_CHAIN (l
)
11908 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11909 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
11913 OMP_CLAUSE_CHAIN (l
) = clauses
;
11916 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11920 OMP_FOR_CLAUSES (stmt
) = clauses
;
11925 while (!for_block
->is_empty ())
11927 /* FIXME diagnostics: LOC below should be the actual location of
11928 this particular for block. We need to build a list of
11929 locations to go along with FOR_BLOCK. */
11930 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11933 release_tree_vector (for_block
);
11937 /* Helper function for OpenMP parsing, split clauses and call
11938 finish_omp_clauses on each of the set of clauses afterwards. */
11941 omp_split_clauses (location_t loc
, enum tree_code code
,
11942 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11945 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11946 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11948 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11952 #pragma omp simd simd-clause[optseq] new-line
11955 LOC is the location of the #pragma token.
11958 #define OMP_SIMD_CLAUSE_MASK \
11959 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
11960 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
11961 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
11962 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11963 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11964 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11965 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
11968 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
11969 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11971 tree block
, clauses
, ret
;
11973 strcat (p_name
, " simd");
11974 mask
|= OMP_SIMD_CLAUSE_MASK
;
11975 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
11977 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11980 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
11981 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
11984 block
= c_begin_compound_stmt (true);
11985 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
11986 block
= c_end_compound_stmt (loc
, block
, true);
11993 #pragma omp for for-clause[optseq] new-line
11997 #pragma omp for simd for-simd-clause[optseq] new-line
12000 LOC is the location of the #pragma token.
12003 #define OMP_FOR_CLAUSE_MASK \
12004 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12005 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12009 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12010 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12011 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12014 c_parser_omp_for (location_t loc
, c_parser
*parser
,
12015 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12017 tree block
, clauses
, ret
;
12019 strcat (p_name
, " for");
12020 mask
|= OMP_FOR_CLAUSE_MASK
;
12022 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12024 if (c_parser_next_token_is (parser
, CPP_NAME
))
12026 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12028 if (strcmp (p
, "simd") == 0)
12030 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12031 if (cclauses
== NULL
)
12032 cclauses
= cclauses_buf
;
12034 c_parser_consume_token (parser
);
12035 if (!flag_openmp
) /* flag_openmp_simd */
12036 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12037 block
= c_begin_compound_stmt (true);
12038 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12039 block
= c_end_compound_stmt (loc
, block
, true);
12040 if (ret
== NULL_TREE
)
12042 ret
= make_node (OMP_FOR
);
12043 TREE_TYPE (ret
) = void_type_node
;
12044 OMP_FOR_BODY (ret
) = block
;
12045 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12046 SET_EXPR_LOCATION (ret
, loc
);
12051 if (!flag_openmp
) /* flag_openmp_simd */
12053 c_parser_skip_to_pragma_eol (parser
);
12057 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12060 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12061 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12064 block
= c_begin_compound_stmt (true);
12065 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12066 block
= c_end_compound_stmt (loc
, block
, true);
12073 # pragma omp master new-line
12076 LOC is the location of the #pragma token.
12080 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12082 c_parser_skip_to_pragma_eol (parser
);
12083 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12087 # pragma omp ordered new-line
12090 LOC is the location of the #pragma itself.
12094 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12096 c_parser_skip_to_pragma_eol (parser
);
12097 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12103 { section-sequence }
12106 section-directive[opt] structured-block
12107 section-sequence section-directive structured-block
12109 SECTIONS_LOC is the location of the #pragma omp sections. */
12112 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12114 tree stmt
, substmt
;
12115 bool error_suppress
= false;
12118 loc
= c_parser_peek_token (parser
)->location
;
12119 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12121 /* Avoid skipping until the end of the block. */
12122 parser
->error
= false;
12126 stmt
= push_stmt_list ();
12128 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12130 substmt
= c_parser_omp_structured_block (parser
);
12131 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12132 SET_EXPR_LOCATION (substmt
, loc
);
12133 add_stmt (substmt
);
12138 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12140 if (c_parser_next_token_is (parser
, CPP_EOF
))
12143 loc
= c_parser_peek_token (parser
)->location
;
12144 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12146 c_parser_consume_pragma (parser
);
12147 c_parser_skip_to_pragma_eol (parser
);
12148 error_suppress
= false;
12150 else if (!error_suppress
)
12152 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12153 error_suppress
= true;
12156 substmt
= c_parser_omp_structured_block (parser
);
12157 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12158 SET_EXPR_LOCATION (substmt
, loc
);
12159 add_stmt (substmt
);
12161 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12162 "expected %<#pragma omp section%> or %<}%>");
12164 substmt
= pop_stmt_list (stmt
);
12166 stmt
= make_node (OMP_SECTIONS
);
12167 SET_EXPR_LOCATION (stmt
, sections_loc
);
12168 TREE_TYPE (stmt
) = void_type_node
;
12169 OMP_SECTIONS_BODY (stmt
) = substmt
;
12171 return add_stmt (stmt
);
12175 # pragma omp sections sections-clause[optseq] newline
12178 LOC is the location of the #pragma token.
12181 #define OMP_SECTIONS_CLAUSE_MASK \
12182 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12183 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12184 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12185 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12186 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12189 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12190 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12192 tree block
, clauses
, ret
;
12194 strcat (p_name
, " sections");
12195 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12197 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12199 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12202 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12203 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12206 block
= c_begin_compound_stmt (true);
12207 ret
= c_parser_omp_sections_scope (loc
, parser
);
12209 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12210 block
= c_end_compound_stmt (loc
, block
, true);
12217 # pragma omp parallel parallel-clause[optseq] new-line
12219 # pragma omp parallel for parallel-for-clause[optseq] new-line
12221 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12225 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12228 LOC is the location of the #pragma token.
12231 #define OMP_PARALLEL_CLAUSE_MASK \
12232 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12233 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12234 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12235 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12236 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12237 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12238 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12239 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12240 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12243 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12244 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12246 tree stmt
, clauses
, block
;
12248 strcat (p_name
, " parallel");
12249 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12251 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12253 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12254 if (cclauses
== NULL
)
12255 cclauses
= cclauses_buf
;
12257 c_parser_consume_token (parser
);
12258 if (!flag_openmp
) /* flag_openmp_simd */
12259 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12260 block
= c_begin_omp_parallel ();
12261 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12263 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12265 if (ret
== NULL_TREE
)
12267 OMP_PARALLEL_COMBINED (stmt
) = 1;
12272 error_at (loc
, "expected %<for%> after %qs", p_name
);
12273 c_parser_skip_to_pragma_eol (parser
);
12276 else if (!flag_openmp
) /* flag_openmp_simd */
12278 c_parser_skip_to_pragma_eol (parser
);
12281 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12283 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12284 if (strcmp (p
, "sections") == 0)
12286 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12287 if (cclauses
== NULL
)
12288 cclauses
= cclauses_buf
;
12290 c_parser_consume_token (parser
);
12291 block
= c_begin_omp_parallel ();
12292 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12293 stmt
= c_finish_omp_parallel (loc
,
12294 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12296 OMP_PARALLEL_COMBINED (stmt
) = 1;
12301 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12303 block
= c_begin_omp_parallel ();
12304 c_parser_statement (parser
);
12305 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12311 # pragma omp single single-clause[optseq] new-line
12314 LOC is the location of the #pragma.
12317 #define OMP_SINGLE_CLAUSE_MASK \
12318 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12324 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12326 tree stmt
= make_node (OMP_SINGLE
);
12327 SET_EXPR_LOCATION (stmt
, loc
);
12328 TREE_TYPE (stmt
) = void_type_node
;
12330 OMP_SINGLE_CLAUSES (stmt
)
12331 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12332 "#pragma omp single");
12333 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12335 return add_stmt (stmt
);
12339 # pragma omp task task-clause[optseq] new-line
12341 LOC is the location of the #pragma.
12344 #define OMP_TASK_CLAUSE_MASK \
12345 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12346 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12347 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12348 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12349 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12350 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12351 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12352 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12353 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12356 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12358 tree clauses
, block
;
12360 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12361 "#pragma omp task");
12363 block
= c_begin_omp_task ();
12364 c_parser_statement (parser
);
12365 return c_finish_omp_task (loc
, clauses
, block
);
12369 # pragma omp taskwait new-line
12373 c_parser_omp_taskwait (c_parser
*parser
)
12375 location_t loc
= c_parser_peek_token (parser
)->location
;
12376 c_parser_consume_pragma (parser
);
12377 c_parser_skip_to_pragma_eol (parser
);
12379 c_finish_omp_taskwait (loc
);
12383 # pragma omp taskyield new-line
12387 c_parser_omp_taskyield (c_parser
*parser
)
12389 location_t loc
= c_parser_peek_token (parser
)->location
;
12390 c_parser_consume_pragma (parser
);
12391 c_parser_skip_to_pragma_eol (parser
);
12393 c_finish_omp_taskyield (loc
);
12397 # pragma omp taskgroup new-line
12401 c_parser_omp_taskgroup (c_parser
*parser
)
12403 location_t loc
= c_parser_peek_token (parser
)->location
;
12404 c_parser_skip_to_pragma_eol (parser
);
12405 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12409 # pragma omp cancel cancel-clause[optseq] new-line
12411 LOC is the location of the #pragma.
12414 #define OMP_CANCEL_CLAUSE_MASK \
12415 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12416 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12417 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12418 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12419 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12422 c_parser_omp_cancel (c_parser
*parser
)
12424 location_t loc
= c_parser_peek_token (parser
)->location
;
12426 c_parser_consume_pragma (parser
);
12427 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12428 "#pragma omp cancel");
12430 c_finish_omp_cancel (loc
, clauses
);
12434 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12436 LOC is the location of the #pragma.
12439 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12440 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12441 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12442 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12443 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12446 c_parser_omp_cancellation_point (c_parser
*parser
)
12448 location_t loc
= c_parser_peek_token (parser
)->location
;
12450 bool point_seen
= false;
12452 c_parser_consume_pragma (parser
);
12453 if (c_parser_next_token_is (parser
, CPP_NAME
))
12455 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12456 if (strcmp (p
, "point") == 0)
12458 c_parser_consume_token (parser
);
12464 c_parser_error (parser
, "expected %<point%>");
12465 c_parser_skip_to_pragma_eol (parser
);
12470 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12471 "#pragma omp cancellation point");
12473 c_finish_omp_cancellation_point (loc
, clauses
);
12477 #pragma omp distribute distribute-clause[optseq] new-line
12480 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12481 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12482 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12483 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12484 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12487 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12488 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12490 tree clauses
, block
, ret
;
12492 strcat (p_name
, " distribute");
12493 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12495 if (c_parser_next_token_is (parser
, CPP_NAME
))
12497 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12499 bool parallel
= false;
12501 if (strcmp (p
, "simd") == 0)
12504 parallel
= strcmp (p
, "parallel") == 0;
12505 if (parallel
|| simd
)
12507 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12508 if (cclauses
== NULL
)
12509 cclauses
= cclauses_buf
;
12510 c_parser_consume_token (parser
);
12511 if (!flag_openmp
) /* flag_openmp_simd */
12514 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12516 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12519 block
= c_begin_compound_stmt (true);
12521 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12523 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12524 block
= c_end_compound_stmt (loc
, block
, true);
12527 ret
= make_node (OMP_DISTRIBUTE
);
12528 TREE_TYPE (ret
) = void_type_node
;
12529 OMP_FOR_BODY (ret
) = block
;
12530 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12531 SET_EXPR_LOCATION (ret
, loc
);
12536 if (!flag_openmp
) /* flag_openmp_simd */
12538 c_parser_skip_to_pragma_eol (parser
);
12542 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12545 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12546 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12549 block
= c_begin_compound_stmt (true);
12550 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12551 block
= c_end_compound_stmt (loc
, block
, true);
12558 # pragma omp teams teams-clause[optseq] new-line
12559 structured-block */
12561 #define OMP_TEAMS_CLAUSE_MASK \
12562 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12564 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12565 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12566 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12568 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12571 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12572 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12574 tree clauses
, block
, ret
;
12576 strcat (p_name
, " teams");
12577 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12579 if (c_parser_next_token_is (parser
, CPP_NAME
))
12581 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12582 if (strcmp (p
, "distribute") == 0)
12584 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12585 if (cclauses
== NULL
)
12586 cclauses
= cclauses_buf
;
12588 c_parser_consume_token (parser
);
12589 if (!flag_openmp
) /* flag_openmp_simd */
12590 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12591 block
= c_begin_compound_stmt (true);
12592 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12593 block
= c_end_compound_stmt (loc
, block
, true);
12596 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12597 ret
= make_node (OMP_TEAMS
);
12598 TREE_TYPE (ret
) = void_type_node
;
12599 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12600 OMP_TEAMS_BODY (ret
) = block
;
12601 return add_stmt (ret
);
12604 if (!flag_openmp
) /* flag_openmp_simd */
12606 c_parser_skip_to_pragma_eol (parser
);
12610 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12613 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12614 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12617 tree stmt
= make_node (OMP_TEAMS
);
12618 TREE_TYPE (stmt
) = void_type_node
;
12619 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12620 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12622 return add_stmt (stmt
);
12626 # pragma omp target data target-data-clause[optseq] new-line
12627 structured-block */
12629 #define OMP_TARGET_DATA_CLAUSE_MASK \
12630 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12631 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12632 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12635 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12637 tree stmt
= make_node (OMP_TARGET_DATA
);
12638 TREE_TYPE (stmt
) = void_type_node
;
12640 OMP_TARGET_DATA_CLAUSES (stmt
)
12641 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12642 "#pragma omp target data");
12643 keep_next_level ();
12644 tree block
= c_begin_compound_stmt (true);
12645 add_stmt (c_parser_omp_structured_block (parser
));
12646 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12648 SET_EXPR_LOCATION (stmt
, loc
);
12649 return add_stmt (stmt
);
12653 # pragma omp target update target-update-clause[optseq] new-line */
12655 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12656 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12657 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12658 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12659 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12662 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12663 enum pragma_context context
)
12665 if (context
== pragma_stmt
)
12668 "%<#pragma omp target update%> may only be "
12669 "used in compound statements");
12670 c_parser_skip_to_pragma_eol (parser
);
12675 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12676 "#pragma omp target update");
12677 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12678 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12681 "%<#pragma omp target update must contain at least one "
12682 "%<from%> or %<to%> clauses");
12686 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12687 TREE_TYPE (stmt
) = void_type_node
;
12688 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12689 SET_EXPR_LOCATION (stmt
, loc
);
12695 # pragma omp target target-clause[optseq] new-line
12696 structured-block */
12698 #define OMP_TARGET_CLAUSE_MASK \
12699 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12700 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12701 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12704 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12706 location_t loc
= c_parser_peek_token (parser
)->location
;
12707 c_parser_consume_pragma (parser
);
12709 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12711 c_parser_error (parser
, "expected declaration specifiers");
12712 c_parser_skip_to_pragma_eol (parser
);
12716 if (c_parser_next_token_is (parser
, CPP_NAME
))
12718 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12720 if (strcmp (p
, "teams") == 0)
12722 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12723 char p_name
[sizeof ("#pragma omp target teams distribute "
12724 "parallel for simd")];
12726 c_parser_consume_token (parser
);
12727 strcpy (p_name
, "#pragma omp target");
12728 if (!flag_openmp
) /* flag_openmp_simd */
12730 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
12731 OMP_TARGET_CLAUSE_MASK
,
12733 return stmt
!= NULL_TREE
;
12735 keep_next_level ();
12736 tree block
= c_begin_compound_stmt (true);
12737 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12738 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12739 block
= c_end_compound_stmt (loc
, block
, true);
12740 if (ret
== NULL_TREE
)
12742 tree stmt
= make_node (OMP_TARGET
);
12743 TREE_TYPE (stmt
) = void_type_node
;
12744 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12745 OMP_TARGET_BODY (stmt
) = block
;
12749 else if (!flag_openmp
) /* flag_openmp_simd */
12751 c_parser_skip_to_pragma_eol (parser
);
12754 else if (strcmp (p
, "data") == 0)
12756 c_parser_consume_token (parser
);
12757 c_parser_omp_target_data (loc
, parser
);
12760 else if (strcmp (p
, "update") == 0)
12762 c_parser_consume_token (parser
);
12763 return c_parser_omp_target_update (loc
, parser
, context
);
12767 tree stmt
= make_node (OMP_TARGET
);
12768 TREE_TYPE (stmt
) = void_type_node
;
12770 OMP_TARGET_CLAUSES (stmt
)
12771 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12772 "#pragma omp target");
12773 keep_next_level ();
12774 tree block
= c_begin_compound_stmt (true);
12775 add_stmt (c_parser_omp_structured_block (parser
));
12776 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12778 SET_EXPR_LOCATION (stmt
, loc
);
12784 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12786 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12787 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12788 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12789 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12790 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12791 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12792 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12795 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12797 vec
<c_token
> clauses
= vNULL
;
12798 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12800 c_token
*token
= c_parser_peek_token (parser
);
12801 if (token
->type
== CPP_EOF
)
12803 c_parser_skip_to_pragma_eol (parser
);
12804 clauses
.release ();
12807 clauses
.safe_push (*token
);
12808 c_parser_consume_token (parser
);
12810 clauses
.safe_push (*c_parser_peek_token (parser
));
12811 c_parser_skip_to_pragma_eol (parser
);
12813 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12815 if (c_parser_peek_token (parser
)->pragma_kind
12816 != PRAGMA_OMP_DECLARE_REDUCTION
12817 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12818 || strcmp (IDENTIFIER_POINTER
12819 (c_parser_peek_2nd_token (parser
)->value
),
12822 c_parser_error (parser
,
12823 "%<#pragma omp declare simd%> must be followed by "
12824 "function declaration or definition or another "
12825 "%<#pragma omp declare simd%>");
12826 clauses
.release ();
12829 c_parser_consume_pragma (parser
);
12830 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12832 c_token
*token
= c_parser_peek_token (parser
);
12833 if (token
->type
== CPP_EOF
)
12835 c_parser_skip_to_pragma_eol (parser
);
12836 clauses
.release ();
12839 clauses
.safe_push (*token
);
12840 c_parser_consume_token (parser
);
12842 clauses
.safe_push (*c_parser_peek_token (parser
));
12843 c_parser_skip_to_pragma_eol (parser
);
12846 /* Make sure nothing tries to read past the end of the tokens. */
12848 memset (&eof_token
, 0, sizeof (eof_token
));
12849 eof_token
.type
= CPP_EOF
;
12850 clauses
.safe_push (eof_token
);
12851 clauses
.safe_push (eof_token
);
12855 case pragma_external
:
12856 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12857 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12859 int ext
= disable_extension_diagnostics ();
12861 c_parser_consume_token (parser
);
12862 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12863 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12864 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12866 restore_extension_diagnostics (ext
);
12869 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12872 case pragma_struct
:
12874 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12875 "function declaration or definition");
12877 case pragma_compound
:
12879 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12880 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12882 int ext
= disable_extension_diagnostics ();
12884 c_parser_consume_token (parser
);
12885 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12886 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12887 if (c_parser_next_tokens_start_declaration (parser
))
12889 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12890 true, NULL
, clauses
);
12891 restore_extension_diagnostics (ext
);
12894 restore_extension_diagnostics (ext
);
12896 else if (c_parser_next_tokens_start_declaration (parser
))
12898 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12902 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12903 "function declaration or definition");
12906 gcc_unreachable ();
12908 clauses
.release ();
12911 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12912 and put that into "omp declare simd" attribute. */
12915 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12916 vec
<c_token
> clauses
)
12919 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12921 error ("%<#pragma omp declare simd%> cannot be used in the same "
12922 "function marked as a Cilk Plus SIMD-enabled function");
12923 vec_free (parser
->cilk_simd_fn_tokens
);
12927 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12928 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12929 has already processed the tokens. */
12930 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
12932 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12934 error ("%<#pragma omp declare simd%> not immediately followed by "
12935 "a function declaration or definition");
12936 clauses
[0].type
= CPP_EOF
;
12939 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
12941 error_at (DECL_SOURCE_LOCATION (fndecl
),
12942 "%<#pragma omp declare simd%> not immediately followed by "
12943 "a single function declaration or definition");
12944 clauses
[0].type
= CPP_EOF
;
12948 if (parms
== NULL_TREE
)
12949 parms
= DECL_ARGUMENTS (fndecl
);
12951 unsigned int tokens_avail
= parser
->tokens_avail
;
12952 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12953 bool is_cilkplus_cilk_simd_fn
= false;
12955 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12957 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
12958 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
12959 is_cilkplus_cilk_simd_fn
= true;
12963 parser
->tokens
= clauses
.address ();
12964 parser
->tokens_avail
= clauses
.length ();
12967 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12968 while (parser
->tokens_avail
> 3)
12970 c_token
*token
= c_parser_peek_token (parser
);
12971 if (!is_cilkplus_cilk_simd_fn
)
12972 gcc_assert (token
->type
== CPP_NAME
12973 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12975 gcc_assert (token
->type
== CPP_NAME
12976 && is_cilkplus_vector_p (token
->value
));
12977 c_parser_consume_token (parser
);
12978 parser
->in_pragma
= true;
12980 tree c
= NULL_TREE
;
12981 if (is_cilkplus_cilk_simd_fn
)
12982 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
12983 "SIMD-enabled functions attribute");
12985 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12986 "#pragma omp declare simd");
12987 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12988 if (c
!= NULL_TREE
)
12989 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12990 if (is_cilkplus_cilk_simd_fn
)
12992 tree k
= build_tree_list (get_identifier ("cilk simd function"),
12994 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
12995 DECL_ATTRIBUTES (fndecl
) = k
;
12997 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12998 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12999 DECL_ATTRIBUTES (fndecl
) = c
;
13002 parser
->tokens
= &parser
->tokens_buf
[0];
13003 parser
->tokens_avail
= tokens_avail
;
13004 if (clauses
.exists ())
13005 clauses
[0].type
= CPP_PRAGMA
;
13007 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13008 vec_free (parser
->cilk_simd_fn_tokens
);
13013 # pragma omp declare target new-line
13014 declarations and definitions
13015 # pragma omp end declare target new-line */
13018 c_parser_omp_declare_target (c_parser
*parser
)
13020 c_parser_skip_to_pragma_eol (parser
);
13021 current_omp_declare_target_attribute
++;
13025 c_parser_omp_end_declare_target (c_parser
*parser
)
13027 location_t loc
= c_parser_peek_token (parser
)->location
;
13028 c_parser_consume_pragma (parser
);
13029 if (c_parser_next_token_is (parser
, CPP_NAME
)
13030 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13033 c_parser_consume_token (parser
);
13034 if (c_parser_next_token_is (parser
, CPP_NAME
)
13035 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13037 c_parser_consume_token (parser
);
13040 c_parser_error (parser
, "expected %<target%>");
13041 c_parser_skip_to_pragma_eol (parser
);
13047 c_parser_error (parser
, "expected %<declare%>");
13048 c_parser_skip_to_pragma_eol (parser
);
13051 c_parser_skip_to_pragma_eol (parser
);
13052 if (!current_omp_declare_target_attribute
)
13053 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13054 "%<#pragma omp declare target%>");
13056 current_omp_declare_target_attribute
--;
13061 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13062 initializer-clause[opt] new-line
13064 initializer-clause:
13065 initializer (omp_priv = initializer)
13066 initializer (function-name (argument-list)) */
13069 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13071 unsigned int tokens_avail
= 0, i
;
13072 vec
<tree
> types
= vNULL
;
13073 vec
<c_token
> clauses
= vNULL
;
13074 enum tree_code reduc_code
= ERROR_MARK
;
13075 tree reduc_id
= NULL_TREE
;
13077 location_t rloc
= c_parser_peek_token (parser
)->location
;
13079 if (context
== pragma_struct
|| context
== pragma_param
)
13081 error ("%<#pragma omp declare reduction%> not at file or block scope");
13085 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13088 switch (c_parser_peek_token (parser
)->type
)
13091 reduc_code
= PLUS_EXPR
;
13094 reduc_code
= MULT_EXPR
;
13097 reduc_code
= MINUS_EXPR
;
13100 reduc_code
= BIT_AND_EXPR
;
13103 reduc_code
= BIT_XOR_EXPR
;
13106 reduc_code
= BIT_IOR_EXPR
;
13109 reduc_code
= TRUTH_ANDIF_EXPR
;
13112 reduc_code
= TRUTH_ORIF_EXPR
;
13116 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13117 if (strcmp (p
, "min") == 0)
13119 reduc_code
= MIN_EXPR
;
13122 if (strcmp (p
, "max") == 0)
13124 reduc_code
= MAX_EXPR
;
13127 reduc_id
= c_parser_peek_token (parser
)->value
;
13130 c_parser_error (parser
,
13131 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13132 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13136 tree orig_reduc_id
, reduc_decl
;
13137 orig_reduc_id
= reduc_id
;
13138 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13139 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13140 c_parser_consume_token (parser
);
13142 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13147 location_t loc
= c_parser_peek_token (parser
)->location
;
13148 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13151 type
= groktypename (ctype
, NULL
, NULL
);
13152 if (type
== error_mark_node
)
13154 else if ((INTEGRAL_TYPE_P (type
)
13155 || TREE_CODE (type
) == REAL_TYPE
13156 || TREE_CODE (type
) == COMPLEX_TYPE
)
13157 && orig_reduc_id
== NULL_TREE
)
13158 error_at (loc
, "predeclared arithmetic type in "
13159 "%<#pragma omp declare reduction%>");
13160 else if (TREE_CODE (type
) == FUNCTION_TYPE
13161 || TREE_CODE (type
) == ARRAY_TYPE
)
13162 error_at (loc
, "function or array type in "
13163 "%<#pragma omp declare reduction%>");
13164 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13165 error_at (loc
, "const, volatile or restrict qualified type in "
13166 "%<#pragma omp declare reduction%>");
13170 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13171 if (comptypes (TREE_PURPOSE (t
), type
))
13173 error_at (loc
, "redeclaration of %qs "
13174 "%<#pragma omp declare reduction%> for "
13176 IDENTIFIER_POINTER (reduc_id
)
13177 + sizeof ("omp declare reduction ") - 1,
13180 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13182 error_at (ploc
, "previous %<#pragma omp declare "
13186 if (t
== NULL_TREE
)
13187 types
.safe_push (type
);
13189 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13190 c_parser_consume_token (parser
);
13198 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13199 || types
.is_empty ())
13202 clauses
.release ();
13206 c_token
*token
= c_parser_peek_token (parser
);
13207 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13209 c_parser_consume_token (parser
);
13211 c_parser_skip_to_pragma_eol (parser
);
13215 if (types
.length () > 1)
13217 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13219 c_token
*token
= c_parser_peek_token (parser
);
13220 if (token
->type
== CPP_EOF
)
13222 clauses
.safe_push (*token
);
13223 c_parser_consume_token (parser
);
13225 clauses
.safe_push (*c_parser_peek_token (parser
));
13226 c_parser_skip_to_pragma_eol (parser
);
13228 /* Make sure nothing tries to read past the end of the tokens. */
13230 memset (&eof_token
, 0, sizeof (eof_token
));
13231 eof_token
.type
= CPP_EOF
;
13232 clauses
.safe_push (eof_token
);
13233 clauses
.safe_push (eof_token
);
13236 int errs
= errorcount
;
13237 FOR_EACH_VEC_ELT (types
, i
, type
)
13239 tokens_avail
= parser
->tokens_avail
;
13240 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13241 if (!clauses
.is_empty ())
13243 parser
->tokens
= clauses
.address ();
13244 parser
->tokens_avail
= clauses
.length ();
13245 parser
->in_pragma
= true;
13248 bool nested
= current_function_decl
!= NULL_TREE
;
13250 c_push_function_context ();
13251 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13252 reduc_id
, default_function_type
);
13253 current_function_decl
= fndecl
;
13254 allocate_struct_function (fndecl
, true);
13256 tree stmt
= push_stmt_list ();
13257 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13258 warn about these. */
13259 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13260 get_identifier ("omp_out"), type
);
13261 DECL_ARTIFICIAL (omp_out
) = 1;
13262 DECL_CONTEXT (omp_out
) = fndecl
;
13263 pushdecl (omp_out
);
13264 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13265 get_identifier ("omp_in"), type
);
13266 DECL_ARTIFICIAL (omp_in
) = 1;
13267 DECL_CONTEXT (omp_in
) = fndecl
;
13269 struct c_expr combiner
= c_parser_expression (parser
);
13270 struct c_expr initializer
;
13271 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13273 initializer
.value
= error_mark_node
;
13274 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13276 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13277 && strcmp (IDENTIFIER_POINTER
13278 (c_parser_peek_token (parser
)->value
),
13279 "initializer") == 0)
13281 c_parser_consume_token (parser
);
13284 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13285 get_identifier ("omp_priv"), type
);
13286 DECL_ARTIFICIAL (omp_priv
) = 1;
13287 DECL_INITIAL (omp_priv
) = error_mark_node
;
13288 DECL_CONTEXT (omp_priv
) = fndecl
;
13289 pushdecl (omp_priv
);
13290 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13291 get_identifier ("omp_orig"), type
);
13292 DECL_ARTIFICIAL (omp_orig
) = 1;
13293 DECL_CONTEXT (omp_orig
) = fndecl
;
13294 pushdecl (omp_orig
);
13295 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13297 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13299 c_parser_error (parser
, "expected %<omp_priv%> or "
13303 else if (strcmp (IDENTIFIER_POINTER
13304 (c_parser_peek_token (parser
)->value
),
13307 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13308 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13310 c_parser_error (parser
, "expected function-name %<(%>");
13314 initializer
= c_parser_postfix_expression (parser
);
13315 if (initializer
.value
13316 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13319 tree c
= initializer
.value
;
13320 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13321 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13322 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13324 if (j
== call_expr_nargs (c
))
13325 error ("one of the initializer call arguments should be "
13331 c_parser_consume_token (parser
);
13332 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13336 tree st
= push_stmt_list ();
13337 start_init (omp_priv
, NULL_TREE
, 0);
13338 location_t loc
= c_parser_peek_token (parser
)->location
;
13339 struct c_expr init
= c_parser_initializer (parser
);
13341 finish_decl (omp_priv
, loc
, init
.value
,
13342 init
.original_type
, NULL_TREE
);
13343 pop_stmt_list (st
);
13347 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13353 c_parser_skip_to_pragma_eol (parser
);
13355 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13356 DECL_INITIAL (reduc_decl
));
13357 DECL_INITIAL (reduc_decl
) = t
;
13358 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13359 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13360 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13361 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13362 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13363 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13366 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13367 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13368 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13369 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13370 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13371 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13372 walk_tree (&DECL_INITIAL (omp_priv
),
13373 c_check_omp_declare_reduction_r
,
13374 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13378 pop_stmt_list (stmt
);
13380 if (cfun
->language
!= NULL
)
13382 ggc_free (cfun
->language
);
13383 cfun
->language
= NULL
;
13386 current_function_decl
= NULL_TREE
;
13388 c_pop_function_context ();
13390 if (!clauses
.is_empty ())
13392 parser
->tokens
= &parser
->tokens_buf
[0];
13393 parser
->tokens_avail
= tokens_avail
;
13397 if (errs
!= errorcount
)
13401 clauses
.release ();
13407 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13408 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13409 initializer-clause[opt] new-line
13410 #pragma omp declare target new-line */
13413 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13415 c_parser_consume_pragma (parser
);
13416 if (c_parser_next_token_is (parser
, CPP_NAME
))
13418 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13419 if (strcmp (p
, "simd") == 0)
13421 /* c_parser_consume_token (parser); done in
13422 c_parser_omp_declare_simd. */
13423 c_parser_omp_declare_simd (parser
, context
);
13426 if (strcmp (p
, "reduction") == 0)
13428 c_parser_consume_token (parser
);
13429 c_parser_omp_declare_reduction (parser
, context
);
13432 if (!flag_openmp
) /* flag_openmp_simd */
13434 c_parser_skip_to_pragma_eol (parser
);
13437 if (strcmp (p
, "target") == 0)
13439 c_parser_consume_token (parser
);
13440 c_parser_omp_declare_target (parser
);
13445 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13447 c_parser_skip_to_pragma_eol (parser
);
13450 /* Main entry point to parsing most OpenMP pragmas. */
13453 c_parser_omp_construct (c_parser
*parser
)
13455 enum pragma_kind p_kind
;
13458 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13459 omp_clause_mask
mask (0);
13461 loc
= c_parser_peek_token (parser
)->location
;
13462 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13463 c_parser_consume_pragma (parser
);
13467 case PRAGMA_OMP_ATOMIC
:
13468 c_parser_omp_atomic (loc
, parser
);
13470 case PRAGMA_OMP_CRITICAL
:
13471 stmt
= c_parser_omp_critical (loc
, parser
);
13473 case PRAGMA_OMP_DISTRIBUTE
:
13474 strcpy (p_name
, "#pragma omp");
13475 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13477 case PRAGMA_OMP_FOR
:
13478 strcpy (p_name
, "#pragma omp");
13479 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13481 case PRAGMA_OMP_MASTER
:
13482 stmt
= c_parser_omp_master (loc
, parser
);
13484 case PRAGMA_OMP_ORDERED
:
13485 stmt
= c_parser_omp_ordered (loc
, parser
);
13487 case PRAGMA_OMP_PARALLEL
:
13488 strcpy (p_name
, "#pragma omp");
13489 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13491 case PRAGMA_OMP_SECTIONS
:
13492 strcpy (p_name
, "#pragma omp");
13493 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13495 case PRAGMA_OMP_SIMD
:
13496 strcpy (p_name
, "#pragma omp");
13497 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13499 case PRAGMA_OMP_SINGLE
:
13500 stmt
= c_parser_omp_single (loc
, parser
);
13502 case PRAGMA_OMP_TASK
:
13503 stmt
= c_parser_omp_task (loc
, parser
);
13505 case PRAGMA_OMP_TASKGROUP
:
13506 stmt
= c_parser_omp_taskgroup (parser
);
13508 case PRAGMA_OMP_TEAMS
:
13509 strcpy (p_name
, "#pragma omp");
13510 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13513 gcc_unreachable ();
13517 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13522 # pragma omp threadprivate (variable-list) */
13525 c_parser_omp_threadprivate (c_parser
*parser
)
13530 c_parser_consume_pragma (parser
);
13531 loc
= c_parser_peek_token (parser
)->location
;
13532 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13534 /* Mark every variable in VARS to be assigned thread local storage. */
13535 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13537 tree v
= TREE_PURPOSE (t
);
13539 /* FIXME diagnostics: Ideally we should keep individual
13540 locations for all the variables in the var list to make the
13541 following errors more precise. Perhaps
13542 c_parser_omp_var_list_parens() should construct a list of
13543 locations to go along with the var list. */
13545 /* If V had already been marked threadprivate, it doesn't matter
13546 whether it had been used prior to this point. */
13547 if (TREE_CODE (v
) != VAR_DECL
)
13548 error_at (loc
, "%qD is not a variable", v
);
13549 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13550 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13551 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13552 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13553 else if (TREE_TYPE (v
) == error_mark_node
)
13555 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13556 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13559 if (! DECL_THREAD_LOCAL_P (v
))
13561 set_decl_tls_model (v
, decl_default_tls_model (v
));
13562 /* If rtl has been already set for this var, call
13563 make_decl_rtl once again, so that encode_section_info
13564 has a chance to look at the new decl flags. */
13565 if (DECL_RTL_SET_P (v
))
13568 C_DECL_THREADPRIVATE_P (v
) = 1;
13572 c_parser_skip_to_pragma_eol (parser
);
13575 /* Cilk Plus <#pragma simd> parsing routines. */
13577 /* Helper function for c_parser_pragma. Perform some sanity checking
13578 for <#pragma simd> constructs. Returns FALSE if there was a
13582 c_parser_cilk_verify_simd (c_parser
*parser
,
13583 enum pragma_context context
)
13585 if (!flag_cilkplus
)
13587 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13588 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13591 if (context
== pragma_external
)
13593 c_parser_error (parser
,"pragma simd must be inside a function");
13594 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13601 This function is shared by SIMD-enabled functions and #pragma simd.
13602 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
13603 CLAUSES is unused. The main purpose of this function is to parse a
13604 vectorlength attribute or clause and check for parse errors.
13605 When IS_SIMD_FN is true then the function is merely caching the tokens
13606 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
13607 cache is cleared since there is no reason to continue.
13609 vectorlength ( constant-expression ) */
13612 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
13616 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
13618 /* The vectorlength clause behaves exactly like OpenMP's safelen
13619 clause. Represent it in OpenMP terms. */
13620 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13622 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13625 location_t loc
= c_parser_peek_token (parser
)->location
;
13626 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13627 expr
= c_fully_fold (expr
, false, NULL
);
13629 /* If expr is an error_mark_node then the above function would have
13630 emitted an error. No reason to do it twice. */
13631 if (expr
== error_mark_node
)
13633 else if (!TREE_TYPE (expr
)
13634 || !TREE_CONSTANT (expr
)
13635 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13637 error_at (loc
, "vectorlength must be an integer constant");
13638 else if (wi::exact_log2 (expr
) == -1)
13639 error_at (loc
, "vectorlength must be a power of 2");
13644 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
13645 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
13646 OMP_CLAUSE_CHAIN (u
) = clauses
;
13651 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13652 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13653 OMP_CLAUSE_CHAIN (u
) = clauses
;
13658 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13664 linear ( simd-linear-variable-list )
13666 simd-linear-variable-list:
13667 simd-linear-variable
13668 simd-linear-variable-list , simd-linear-variable
13670 simd-linear-variable:
13672 id-expression : simd-linear-step
13675 conditional-expression */
13678 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13680 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13683 location_t loc
= c_parser_peek_token (parser
)->location
;
13685 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13686 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13687 c_parser_error (parser
, "expected identifier");
13689 while (c_parser_next_token_is (parser
, CPP_NAME
)
13690 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13692 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13696 undeclared_variable (c_parser_peek_token (parser
)->location
,
13697 c_parser_peek_token (parser
)->value
);
13698 c_parser_consume_token (parser
);
13700 else if (var
== error_mark_node
)
13701 c_parser_consume_token (parser
);
13704 tree step
= integer_one_node
;
13706 /* Parse the linear step if present. */
13707 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13709 c_parser_consume_token (parser
);
13710 c_parser_consume_token (parser
);
13712 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13713 expr
= c_fully_fold (expr
, false, NULL
);
13715 if (TREE_TYPE (expr
)
13716 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13717 && (TREE_CONSTANT (expr
)
13721 c_parser_error (parser
,
13722 "step size must be an integer constant "
13723 "expression or an integer variable");
13726 c_parser_consume_token (parser
);
13728 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13729 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13730 OMP_CLAUSE_DECL (u
) = var
;
13731 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13732 OMP_CLAUSE_CHAIN (u
) = clauses
;
13736 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13739 c_parser_consume_token (parser
);
13742 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13747 /* Returns the name of the next clause. If the clause is not
13748 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13749 not consumed. Otherwise, the appropriate pragma_simd_clause is
13750 returned and the token is consumed. */
13752 static pragma_omp_clause
13753 c_parser_cilk_clause_name (c_parser
*parser
)
13755 pragma_omp_clause result
;
13756 c_token
*token
= c_parser_peek_token (parser
);
13758 if (!token
->value
|| token
->type
!= CPP_NAME
)
13759 return PRAGMA_CILK_CLAUSE_NONE
;
13761 const char *p
= IDENTIFIER_POINTER (token
->value
);
13763 if (!strcmp (p
, "vectorlength"))
13764 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13765 else if (!strcmp (p
, "linear"))
13766 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13767 else if (!strcmp (p
, "private"))
13768 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13769 else if (!strcmp (p
, "firstprivate"))
13770 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13771 else if (!strcmp (p
, "lastprivate"))
13772 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13773 else if (!strcmp (p
, "reduction"))
13774 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13776 return PRAGMA_CILK_CLAUSE_NONE
;
13778 c_parser_consume_token (parser
);
13782 /* Parse all #<pragma simd> clauses. Return the list of clauses
13786 c_parser_cilk_all_clauses (c_parser
*parser
)
13788 tree clauses
= NULL
;
13790 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13792 pragma_omp_clause c_kind
;
13794 c_kind
= c_parser_cilk_clause_name (parser
);
13798 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13799 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
13801 case PRAGMA_CILK_CLAUSE_LINEAR
:
13802 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13804 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13805 /* Use the OpenMP counterpart. */
13806 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13808 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13809 /* Use the OpenMP counterpart. */
13810 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13812 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13813 /* Use the OpenMP counterpart. */
13814 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13816 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13817 /* Use the OpenMP counterpart. */
13818 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13821 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13827 c_parser_skip_to_pragma_eol (parser
);
13828 return c_finish_cilk_clauses (clauses
);
13831 /* Main entry point for parsing Cilk Plus <#pragma simd> for
13835 c_parser_cilk_simd (c_parser
*parser
)
13837 tree clauses
= c_parser_cilk_all_clauses (parser
);
13838 tree block
= c_begin_compound_stmt (true);
13839 location_t loc
= c_parser_peek_token (parser
)->location
;
13840 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
13841 block
= c_end_compound_stmt (loc
, block
, true);
13845 /* Parse a transaction attribute (GCC Extension).
13847 transaction-attribute:
13851 The transactional memory language description is written for C++,
13852 and uses the C++0x attribute syntax. For compatibility, allow the
13853 bracket style for transactions in C as well. */
13856 c_parser_transaction_attributes (c_parser
*parser
)
13858 tree attr_name
, attr
= NULL
;
13860 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13861 return c_parser_attributes (parser
);
13863 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13865 c_parser_consume_token (parser
);
13866 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13869 attr_name
= c_parser_attribute_any_word (parser
);
13872 c_parser_consume_token (parser
);
13873 attr
= build_tree_list (attr_name
, NULL_TREE
);
13876 c_parser_error (parser
, "expected identifier");
13878 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13880 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13884 /* Parse a __transaction_atomic or __transaction_relaxed statement
13887 transaction-statement:
13888 __transaction_atomic transaction-attribute[opt] compound-statement
13889 __transaction_relaxed compound-statement
13891 Note that the only valid attribute is: "outer".
13895 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13897 unsigned int old_in
= parser
->in_transaction
;
13898 unsigned int this_in
= 1, new_in
;
13899 location_t loc
= c_parser_peek_token (parser
)->location
;
13902 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13903 || keyword
== RID_TRANSACTION_RELAXED
)
13904 && c_parser_next_token_is_keyword (parser
, keyword
));
13905 c_parser_consume_token (parser
);
13907 if (keyword
== RID_TRANSACTION_RELAXED
)
13908 this_in
|= TM_STMT_ATTR_RELAXED
;
13911 attrs
= c_parser_transaction_attributes (parser
);
13913 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13916 /* Keep track if we're in the lexical scope of an outer transaction. */
13917 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13919 parser
->in_transaction
= new_in
;
13920 stmt
= c_parser_compound_statement (parser
);
13921 parser
->in_transaction
= old_in
;
13924 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13926 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13927 "%<__transaction_atomic%> without transactional memory support enabled"
13928 : "%<__transaction_relaxed %> "
13929 "without transactional memory support enabled"));
13934 /* Parse a __transaction_atomic or __transaction_relaxed expression
13937 transaction-expression:
13938 __transaction_atomic ( expression )
13939 __transaction_relaxed ( expression )
13942 static struct c_expr
13943 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13946 unsigned int old_in
= parser
->in_transaction
;
13947 unsigned int this_in
= 1;
13948 location_t loc
= c_parser_peek_token (parser
)->location
;
13951 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13952 || keyword
== RID_TRANSACTION_RELAXED
)
13953 && c_parser_next_token_is_keyword (parser
, keyword
));
13954 c_parser_consume_token (parser
);
13956 if (keyword
== RID_TRANSACTION_RELAXED
)
13957 this_in
|= TM_STMT_ATTR_RELAXED
;
13960 attrs
= c_parser_transaction_attributes (parser
);
13962 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13965 parser
->in_transaction
= this_in
;
13966 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13968 tree expr
= c_parser_expression (parser
).value
;
13969 ret
.original_type
= TREE_TYPE (expr
);
13970 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13971 if (this_in
& TM_STMT_ATTR_RELAXED
)
13972 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13973 SET_EXPR_LOCATION (ret
.value
, loc
);
13974 ret
.original_code
= TRANSACTION_EXPR
;
13975 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13977 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13984 ret
.value
= error_mark_node
;
13985 ret
.original_code
= ERROR_MARK
;
13986 ret
.original_type
= NULL
;
13988 parser
->in_transaction
= old_in
;
13991 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13992 "%<__transaction_atomic%> without transactional memory support enabled"
13993 : "%<__transaction_relaxed %> "
13994 "without transactional memory support enabled"));
13999 /* Parse a __transaction_cancel statement (GCC Extension).
14001 transaction-cancel-statement:
14002 __transaction_cancel transaction-attribute[opt] ;
14004 Note that the only valid attribute is "outer".
14008 c_parser_transaction_cancel (c_parser
*parser
)
14010 location_t loc
= c_parser_peek_token (parser
)->location
;
14012 bool is_outer
= false;
14014 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
14015 c_parser_consume_token (parser
);
14017 attrs
= c_parser_transaction_attributes (parser
);
14019 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
14023 error_at (loc
, "%<__transaction_cancel%> without "
14024 "transactional memory support enabled");
14027 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
14029 error_at (loc
, "%<__transaction_cancel%> within a "
14030 "%<__transaction_relaxed%>");
14035 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
14036 && !is_tm_may_cancel_outer (current_function_decl
))
14038 error_at (loc
, "outer %<__transaction_cancel%> not "
14039 "within outer %<__transaction_atomic%>");
14040 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
14044 else if (parser
->in_transaction
== 0)
14046 error_at (loc
, "%<__transaction_cancel%> not within "
14047 "%<__transaction_atomic%>");
14051 return add_stmt (build_tm_abort_call (loc
, is_outer
));
14054 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
14057 /* Parse a single source file. */
14060 c_parse_file (void)
14062 /* Use local storage to begin. If the first token is a pragma, parse it.
14063 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14064 which will cause garbage collection. */
14067 memset (&tparser
, 0, sizeof tparser
);
14068 tparser
.tokens
= &tparser
.tokens_buf
[0];
14069 the_parser
= &tparser
;
14071 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
14072 c_parser_pragma_pch_preprocess (&tparser
);
14074 the_parser
= ggc_alloc
<c_parser
> ();
14075 *the_parser
= tparser
;
14076 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
14077 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
14079 /* Initialize EH, if we've been told to do so. */
14080 if (flag_exceptions
)
14081 using_eh_for_cleanups ();
14083 c_parser_translation_unit (the_parser
);
14087 /* This function parses Cilk Plus array notation. The starting index is
14088 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14089 return value of this function is a tree_node called VALUE_TREE of type
14090 ARRAY_NOTATION_REF. */
14093 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
14096 c_token
*token
= NULL
;
14097 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
14098 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
14099 tree array_type_domain
= NULL_TREE
;
14101 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
14103 /* No need to continue. If either of these 2 were true, then an error
14104 must be emitted already. Thus, no need to emit them twice. */
14105 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14106 return error_mark_node
;
14109 array_type
= TREE_TYPE (array_value
);
14110 gcc_assert (array_type
);
14111 type
= TREE_TYPE (array_type
);
14112 token
= c_parser_peek_token (parser
);
14114 if (token
->type
== CPP_EOF
)
14116 c_parser_error (parser
, "expected %<:%> or numeral");
14119 else if (token
->type
== CPP_COLON
)
14121 if (!initial_index
)
14123 /* If we are here, then we have a case like this A[:]. */
14124 c_parser_consume_token (parser
);
14125 if (TREE_CODE (array_type
) == POINTER_TYPE
)
14127 error_at (loc
, "start-index and length fields necessary for "
14128 "using array notations in pointers");
14129 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14130 return error_mark_node
;
14132 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14134 error_at (loc
, "array notations cannot be used with function "
14136 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14137 return error_mark_node
;
14139 array_type_domain
= TYPE_DOMAIN (array_type
);
14141 if (!array_type_domain
)
14143 error_at (loc
, "start-index and length fields necessary for "
14144 "using array notations in dimensionless arrays");
14145 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14146 return error_mark_node
;
14149 start_index
= TYPE_MINVAL (array_type_domain
);
14150 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
14152 if (!TYPE_MAXVAL (array_type_domain
)
14153 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
14155 error_at (loc
, "start-index and length fields necessary for "
14156 "using array notations in variable-length arrays");
14157 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14158 return error_mark_node
;
14160 end_index
= TYPE_MAXVAL (array_type_domain
);
14161 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
14162 end_index
, integer_one_node
);
14163 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
14164 stride
= build_int_cst (integer_type_node
, 1);
14165 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
14167 else if (initial_index
!= error_mark_node
)
14169 /* If we are here, then there should be 2 possibilities:
14170 1. Array [EXPR : EXPR]
14171 2. Array [EXPR : EXPR : EXPR]
14173 start_index
= initial_index
;
14175 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14177 error_at (loc
, "array notations cannot be used with function "
14179 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14180 return error_mark_node
;
14182 c_parser_consume_token (parser
); /* consume the ':' */
14183 struct c_expr ce
= c_parser_expression (parser
);
14184 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14185 end_index
= ce
.value
;
14186 if (!end_index
|| end_index
== error_mark_node
)
14188 c_parser_skip_to_end_of_block_or_statement (parser
);
14189 return error_mark_node
;
14191 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
14193 c_parser_consume_token (parser
);
14194 ce
= c_parser_expression (parser
);
14195 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14197 if (!stride
|| stride
== error_mark_node
)
14199 c_parser_skip_to_end_of_block_or_statement (parser
);
14200 return error_mark_node
;
14205 c_parser_error (parser
, "expected array notation expression");
14208 c_parser_error (parser
, "expected array notation expression");
14210 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14212 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
14213 end_index
, stride
, type
);
14214 if (value_tree
!= error_mark_node
)
14215 SET_EXPR_LOCATION (value_tree
, loc
);
14219 #include "gt-c-c-parser.h"