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 unsigned int * = NULL
);
1209 static void c_parser_omp_construct (c_parser
*);
1210 static void c_parser_omp_threadprivate (c_parser
*);
1211 static void c_parser_omp_barrier (c_parser
*);
1212 static void c_parser_omp_flush (c_parser
*);
1213 static void c_parser_omp_taskwait (c_parser
*);
1214 static void c_parser_omp_taskyield (c_parser
*);
1215 static void c_parser_omp_cancel (c_parser
*);
1216 static void c_parser_omp_cancellation_point (c_parser
*);
1218 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1219 pragma_stmt
, pragma_compound
};
1220 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1221 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1222 static void c_parser_omp_end_declare_target (c_parser
*);
1223 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1225 /* These Objective-C parser functions are only ever called when
1226 compiling Objective-C. */
1227 static void c_parser_objc_class_definition (c_parser
*, tree
);
1228 static void c_parser_objc_class_instance_variables (c_parser
*);
1229 static void c_parser_objc_class_declaration (c_parser
*);
1230 static void c_parser_objc_alias_declaration (c_parser
*);
1231 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1232 static bool c_parser_objc_method_type (c_parser
*);
1233 static void c_parser_objc_method_definition (c_parser
*);
1234 static void c_parser_objc_methodprotolist (c_parser
*);
1235 static void c_parser_objc_methodproto (c_parser
*);
1236 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1237 static tree
c_parser_objc_type_name (c_parser
*);
1238 static tree
c_parser_objc_protocol_refs (c_parser
*);
1239 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1240 static void c_parser_objc_synchronized_statement (c_parser
*);
1241 static tree
c_parser_objc_selector (c_parser
*);
1242 static tree
c_parser_objc_selector_arg (c_parser
*);
1243 static tree
c_parser_objc_receiver (c_parser
*);
1244 static tree
c_parser_objc_message_args (c_parser
*);
1245 static tree
c_parser_objc_keywordexpr (c_parser
*);
1246 static void c_parser_objc_at_property_declaration (c_parser
*);
1247 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1248 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1249 static bool c_parser_objc_diagnose_bad_element_prefix
1250 (c_parser
*, struct c_declspecs
*);
1252 /* Cilk Plus supporting routines. */
1253 static void c_parser_cilk_simd (c_parser
*);
1254 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1255 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1256 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1258 /* Parse a translation unit (C90 6.7, C99 6.9).
1261 external-declarations
1263 external-declarations:
1264 external-declaration
1265 external-declarations external-declaration
1274 c_parser_translation_unit (c_parser
*parser
)
1276 if (c_parser_next_token_is (parser
, CPP_EOF
))
1278 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1279 "ISO C forbids an empty translation unit");
1283 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1284 mark_valid_location_for_stdc_pragma (false);
1288 c_parser_external_declaration (parser
);
1289 obstack_free (&parser_obstack
, obstack_position
);
1291 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1295 /* Parse an external declaration (C90 6.7, C99 6.9).
1297 external-declaration:
1303 external-declaration:
1306 __extension__ external-declaration
1310 external-declaration:
1311 objc-class-definition
1312 objc-class-declaration
1313 objc-alias-declaration
1314 objc-protocol-definition
1315 objc-method-definition
1320 c_parser_external_declaration (c_parser
*parser
)
1323 switch (c_parser_peek_token (parser
)->type
)
1326 switch (c_parser_peek_token (parser
)->keyword
)
1329 ext
= disable_extension_diagnostics ();
1330 c_parser_consume_token (parser
);
1331 c_parser_external_declaration (parser
);
1332 restore_extension_diagnostics (ext
);
1335 c_parser_asm_definition (parser
);
1337 case RID_AT_INTERFACE
:
1338 case RID_AT_IMPLEMENTATION
:
1339 gcc_assert (c_dialect_objc ());
1340 c_parser_objc_class_definition (parser
, NULL_TREE
);
1343 gcc_assert (c_dialect_objc ());
1344 c_parser_objc_class_declaration (parser
);
1347 gcc_assert (c_dialect_objc ());
1348 c_parser_objc_alias_declaration (parser
);
1350 case RID_AT_PROTOCOL
:
1351 gcc_assert (c_dialect_objc ());
1352 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1354 case RID_AT_PROPERTY
:
1355 gcc_assert (c_dialect_objc ());
1356 c_parser_objc_at_property_declaration (parser
);
1358 case RID_AT_SYNTHESIZE
:
1359 gcc_assert (c_dialect_objc ());
1360 c_parser_objc_at_synthesize_declaration (parser
);
1362 case RID_AT_DYNAMIC
:
1363 gcc_assert (c_dialect_objc ());
1364 c_parser_objc_at_dynamic_declaration (parser
);
1367 gcc_assert (c_dialect_objc ());
1368 c_parser_consume_token (parser
);
1369 objc_finish_implementation ();
1376 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1377 "ISO C does not allow extra %<;%> outside of a function");
1378 c_parser_consume_token (parser
);
1381 mark_valid_location_for_stdc_pragma (true);
1382 c_parser_pragma (parser
, pragma_external
);
1383 mark_valid_location_for_stdc_pragma (false);
1387 if (c_dialect_objc ())
1389 c_parser_objc_method_definition (parser
);
1392 /* Else fall through, and yield a syntax error trying to parse
1393 as a declaration or function definition. */
1396 /* A declaration or a function definition (or, in Objective-C,
1397 an @interface or @protocol with prefix attributes). We can
1398 only tell which after parsing the declaration specifiers, if
1399 any, and the first declarator. */
1400 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1406 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1408 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1409 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1410 accepted; otherwise (old-style parameter declarations) only other
1411 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1412 assertion is accepted; otherwise (old-style parameter declarations)
1413 it is not. If NESTED is true, we are inside a function or parsing
1414 old-style parameter declarations; any functions encountered are
1415 nested functions and declaration specifiers are required; otherwise
1416 we are at top level and functions are normal functions and
1417 declaration specifiers may be optional. If EMPTY_OK is true, empty
1418 declarations are OK (subject to all other constraints); otherwise
1419 (old-style parameter declarations) they are diagnosed. If
1420 START_ATTR_OK is true, the declaration specifiers may start with
1421 attributes; otherwise they may not.
1422 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1423 declaration when parsing an Objective-C foreach statement.
1426 declaration-specifiers init-declarator-list[opt] ;
1427 static_assert-declaration
1429 function-definition:
1430 declaration-specifiers[opt] declarator declaration-list[opt]
1435 declaration-list declaration
1437 init-declarator-list:
1439 init-declarator-list , init-declarator
1442 declarator simple-asm-expr[opt] attributes[opt]
1443 declarator simple-asm-expr[opt] attributes[opt] = initializer
1447 nested-function-definition:
1448 declaration-specifiers declarator declaration-list[opt]
1452 attributes objc-class-definition
1453 attributes objc-category-definition
1454 attributes objc-protocol-definition
1456 The simple-asm-expr and attributes are GNU extensions.
1458 This function does not handle __extension__; that is handled in its
1459 callers. ??? Following the old parser, __extension__ may start
1460 external declarations, declarations in functions and declarations
1461 at the start of "for" loops, but not old-style parameter
1464 C99 requires declaration specifiers in a function definition; the
1465 absence is diagnosed through the diagnosis of implicit int. In GNU
1466 C we also allow but diagnose declarations without declaration
1467 specifiers, but only at top level (elsewhere they conflict with
1470 In Objective-C, declarations of the looping variable in a foreach
1471 statement are exceptionally terminated by 'in' (for example, 'for
1472 (NSObject *object in array) { ... }').
1477 threadprivate-directive */
1480 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1481 bool static_assert_ok
, bool empty_ok
,
1482 bool nested
, bool start_attr_ok
,
1483 tree
*objc_foreach_object_declaration
,
1484 vec
<c_token
> omp_declare_simd_clauses
)
1486 struct c_declspecs
*specs
;
1488 tree all_prefix_attrs
;
1489 bool diagnosed_no_specs
= false;
1490 location_t here
= c_parser_peek_token (parser
)->location
;
1492 if (static_assert_ok
1493 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1495 c_parser_static_assert_declaration (parser
);
1498 specs
= build_null_declspecs ();
1500 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1501 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1502 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1503 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1504 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1505 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1507 error_at (here
, "unknown type name %qE",
1508 c_parser_peek_token (parser
)->value
);
1510 /* Parse declspecs normally to get a correct pointer type, but avoid
1511 a further "fails to be a type name" error. Refuse nested functions
1512 since it is not how the user likely wants us to recover. */
1513 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1514 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1515 c_parser_peek_token (parser
)->value
= error_mark_node
;
1519 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1520 true, true, cla_nonabstract_decl
);
1523 c_parser_skip_to_end_of_block_or_statement (parser
);
1526 if (nested
&& !specs
->declspecs_seen_p
)
1528 c_parser_error (parser
, "expected declaration specifiers");
1529 c_parser_skip_to_end_of_block_or_statement (parser
);
1532 finish_declspecs (specs
);
1533 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1534 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1537 error_at (here
, "%<__auto_type%> in empty declaration");
1542 shadow_tag_warned (specs
, 1);
1543 pedwarn (here
, 0, "empty declaration");
1545 c_parser_consume_token (parser
);
1549 /* Provide better error recovery. Note that a type name here is usually
1550 better diagnosed as a redeclaration. */
1552 && specs
->typespec_kind
== ctsk_tagdef
1553 && c_parser_next_token_starts_declspecs (parser
)
1554 && !c_parser_next_token_is (parser
, CPP_NAME
))
1556 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1557 parser
->error
= false;
1558 shadow_tag_warned (specs
, 1);
1561 else if (c_dialect_objc () && !auto_type_p
)
1563 /* Prefix attributes are an error on method decls. */
1564 switch (c_parser_peek_token (parser
)->type
)
1568 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1572 warning_at (c_parser_peek_token (parser
)->location
,
1574 "prefix attributes are ignored for methods");
1575 specs
->attrs
= NULL_TREE
;
1578 c_parser_objc_method_definition (parser
);
1580 c_parser_objc_methodproto (parser
);
1586 /* This is where we parse 'attributes @interface ...',
1587 'attributes @implementation ...', 'attributes @protocol ...'
1588 (where attributes could be, for example, __attribute__
1591 switch (c_parser_peek_token (parser
)->keyword
)
1593 case RID_AT_INTERFACE
:
1595 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1597 c_parser_objc_class_definition (parser
, specs
->attrs
);
1601 case RID_AT_IMPLEMENTATION
:
1603 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1607 warning_at (c_parser_peek_token (parser
)->location
,
1609 "prefix attributes are ignored for implementations");
1610 specs
->attrs
= NULL_TREE
;
1612 c_parser_objc_class_definition (parser
, NULL_TREE
);
1616 case RID_AT_PROTOCOL
:
1618 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1620 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1627 case RID_AT_PROPERTY
:
1630 c_parser_error (parser
, "unexpected attribute");
1631 specs
->attrs
= NULL
;
1639 pending_xref_error ();
1640 prefix_attrs
= specs
->attrs
;
1641 all_prefix_attrs
= prefix_attrs
;
1642 specs
->attrs
= NULL_TREE
;
1645 struct c_declarator
*declarator
;
1649 /* Declaring either one or more declarators (in which case we
1650 should diagnose if there were no declaration specifiers) or a
1651 function definition (in which case the diagnostic for
1652 implicit int suffices). */
1653 declarator
= c_parser_declarator (parser
,
1654 specs
->typespec_kind
!= ctsk_none
,
1655 C_DTR_NORMAL
, &dummy
);
1656 if (declarator
== NULL
)
1658 if (omp_declare_simd_clauses
.exists ()
1659 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1660 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1661 omp_declare_simd_clauses
);
1662 c_parser_skip_to_end_of_block_or_statement (parser
);
1665 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1668 "%<__auto_type%> requires a plain identifier"
1670 c_parser_skip_to_end_of_block_or_statement (parser
);
1673 if (c_parser_next_token_is (parser
, CPP_EQ
)
1674 || c_parser_next_token_is (parser
, CPP_COMMA
)
1675 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1676 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1677 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1678 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1680 tree asm_name
= NULL_TREE
;
1681 tree postfix_attrs
= NULL_TREE
;
1682 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1684 diagnosed_no_specs
= true;
1685 pedwarn (here
, 0, "data definition has no type or storage class");
1687 /* Having seen a data definition, there cannot now be a
1688 function definition. */
1690 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1691 asm_name
= c_parser_simple_asm_expr (parser
);
1692 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1694 postfix_attrs
= c_parser_attributes (parser
);
1695 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1697 /* This means there is an attribute specifier after
1698 the declarator in a function definition. Provide
1699 some more information for the user. */
1700 error_at (here
, "attributes should be specified before the "
1701 "declarator in a function definition");
1702 c_parser_skip_to_end_of_block_or_statement (parser
);
1706 if (c_parser_next_token_is (parser
, CPP_EQ
))
1710 location_t init_loc
;
1711 c_parser_consume_token (parser
);
1714 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1715 init_loc
= c_parser_peek_token (parser
)->location
;
1716 init
= c_parser_expr_no_commas (parser
, NULL
);
1717 if (TREE_CODE (init
.value
) == COMPONENT_REF
1718 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1720 "%<__auto_type%> used with a bit-field"
1722 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1723 tree init_type
= TREE_TYPE (init
.value
);
1724 /* As with typeof, remove all qualifiers from atomic types. */
1725 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1727 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1728 bool vm_type
= variably_modified_type_p (init_type
,
1731 init
.value
= c_save_expr (init
.value
);
1733 specs
->typespec_kind
= ctsk_typeof
;
1734 specs
->locations
[cdw_typedef
] = init_loc
;
1735 specs
->typedef_p
= true;
1736 specs
->type
= init_type
;
1739 bool maybe_const
= true;
1740 tree type_expr
= c_fully_fold (init
.value
, false,
1742 specs
->expr_const_operands
&= maybe_const
;
1744 specs
->expr
= build2 (COMPOUND_EXPR
,
1745 TREE_TYPE (type_expr
),
1746 specs
->expr
, type_expr
);
1748 specs
->expr
= type_expr
;
1750 d
= start_decl (declarator
, specs
, true,
1751 chainon (postfix_attrs
, all_prefix_attrs
));
1753 d
= error_mark_node
;
1754 if (omp_declare_simd_clauses
.exists ()
1755 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1756 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1757 omp_declare_simd_clauses
);
1761 /* The declaration of the variable is in effect while
1762 its initializer is parsed. */
1763 d
= start_decl (declarator
, specs
, true,
1764 chainon (postfix_attrs
, all_prefix_attrs
));
1766 d
= error_mark_node
;
1767 if (omp_declare_simd_clauses
.exists ()
1768 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1769 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1770 omp_declare_simd_clauses
);
1771 start_init (d
, asm_name
, global_bindings_p ());
1772 init_loc
= c_parser_peek_token (parser
)->location
;
1773 init
= c_parser_initializer (parser
);
1776 if (d
!= error_mark_node
)
1778 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1779 finish_decl (d
, init_loc
, init
.value
,
1780 init
.original_type
, asm_name
);
1788 "%<__auto_type%> requires an initialized "
1789 "data declaration");
1790 c_parser_skip_to_end_of_block_or_statement (parser
);
1793 tree d
= start_decl (declarator
, specs
, false,
1794 chainon (postfix_attrs
,
1796 if (omp_declare_simd_clauses
.exists ()
1797 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1799 tree parms
= NULL_TREE
;
1800 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1802 struct c_declarator
*ce
= declarator
;
1804 if (ce
->kind
== cdk_function
)
1806 parms
= ce
->u
.arg_info
->parms
;
1810 ce
= ce
->declarator
;
1813 temp_store_parm_decls (d
, parms
);
1814 c_finish_omp_declare_simd (parser
, d
, parms
,
1815 omp_declare_simd_clauses
);
1817 temp_pop_parm_decls ();
1820 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1821 NULL_TREE
, asm_name
);
1823 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1826 *objc_foreach_object_declaration
= d
;
1828 *objc_foreach_object_declaration
= error_mark_node
;
1831 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1836 "%<__auto_type%> may only be used with"
1837 " a single declarator");
1838 c_parser_skip_to_end_of_block_or_statement (parser
);
1841 c_parser_consume_token (parser
);
1842 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1843 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1846 all_prefix_attrs
= prefix_attrs
;
1849 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1851 c_parser_consume_token (parser
);
1854 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1856 /* This can only happen in Objective-C: we found the
1857 'in' that terminates the declaration inside an
1858 Objective-C foreach statement. Do not consume the
1859 token, so that the caller can use it to determine
1860 that this indeed is a foreach context. */
1865 c_parser_error (parser
, "expected %<,%> or %<;%>");
1866 c_parser_skip_to_end_of_block_or_statement (parser
);
1870 else if (auto_type_p
)
1873 "%<__auto_type%> requires an initialized data declaration");
1874 c_parser_skip_to_end_of_block_or_statement (parser
);
1879 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1880 "%<asm%> or %<__attribute__%>");
1881 c_parser_skip_to_end_of_block_or_statement (parser
);
1884 /* Function definition (nested or otherwise). */
1887 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1888 c_push_function_context ();
1890 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1892 /* This can appear in many cases looking nothing like a
1893 function definition, so we don't give a more specific
1894 error suggesting there was one. */
1895 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1896 "or %<__attribute__%>");
1898 c_pop_function_context ();
1902 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1903 tv
= TV_PARSE_INLINE
;
1908 /* Parse old-style parameter declarations. ??? Attributes are
1909 not allowed to start declaration specifiers here because of a
1910 syntax conflict between a function declaration with attribute
1911 suffix and a function definition with an attribute prefix on
1912 first old-style parameter declaration. Following the old
1913 parser, they are not accepted on subsequent old-style
1914 parameter declarations either. However, there is no
1915 ambiguity after the first declaration, nor indeed on the
1916 first as long as we don't allow postfix attributes after a
1917 declarator with a nonempty identifier list in a definition;
1918 and postfix attributes have never been accepted here in
1919 function definitions either. */
1920 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1921 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1922 c_parser_declaration_or_fndef (parser
, false, false, false,
1923 true, false, NULL
, vNULL
);
1924 store_parm_decls ();
1925 if (omp_declare_simd_clauses
.exists ()
1926 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1927 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1928 omp_declare_simd_clauses
);
1929 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1930 = c_parser_peek_token (parser
)->location
;
1931 fnbody
= c_parser_compound_statement (parser
);
1932 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1933 fnbody
= expand_array_notation_exprs (fnbody
);
1936 tree decl
= current_function_decl
;
1937 /* Mark nested functions as needing static-chain initially.
1938 lower_nested_functions will recompute it but the
1939 DECL_STATIC_CHAIN flag is also used before that happens,
1940 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1941 DECL_STATIC_CHAIN (decl
) = 1;
1944 c_pop_function_context ();
1945 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1958 /* Parse an asm-definition (asm() outside a function body). This is a
1966 c_parser_asm_definition (c_parser
*parser
)
1968 tree asm_str
= c_parser_simple_asm_expr (parser
);
1970 add_asm_node (asm_str
);
1971 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1974 /* Parse a static assertion (C11 6.7.10).
1976 static_assert-declaration:
1977 static_assert-declaration-no-semi ;
1981 c_parser_static_assert_declaration (c_parser
*parser
)
1983 c_parser_static_assert_declaration_no_semi (parser
);
1985 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1986 c_parser_skip_to_end_of_block_or_statement (parser
);
1989 /* Parse a static assertion (C11 6.7.10), without the trailing
1992 static_assert-declaration-no-semi:
1993 _Static_assert ( constant-expression , string-literal )
1997 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1999 location_t assert_loc
, value_loc
;
2003 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2004 assert_loc
= c_parser_peek_token (parser
)->location
;
2008 pedwarn (assert_loc
, OPT_Wpedantic
,
2009 "ISO C99 does not support %<_Static_assert%>");
2011 pedwarn (assert_loc
, OPT_Wpedantic
,
2012 "ISO C90 does not support %<_Static_assert%>");
2014 c_parser_consume_token (parser
);
2015 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2017 value_loc
= c_parser_peek_token (parser
)->location
;
2018 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2019 parser
->lex_untranslated_string
= true;
2020 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2022 parser
->lex_untranslated_string
= false;
2025 switch (c_parser_peek_token (parser
)->type
)
2031 case CPP_UTF8STRING
:
2032 string
= c_parser_peek_token (parser
)->value
;
2033 c_parser_consume_token (parser
);
2034 parser
->lex_untranslated_string
= false;
2037 c_parser_error (parser
, "expected string literal");
2038 parser
->lex_untranslated_string
= false;
2041 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2043 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2045 error_at (value_loc
, "expression in static assertion is not an integer");
2048 if (TREE_CODE (value
) != INTEGER_CST
)
2050 value
= c_fully_fold (value
, false, NULL
);
2051 if (TREE_CODE (value
) == INTEGER_CST
)
2052 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2053 "is not an integer constant expression");
2055 if (TREE_CODE (value
) != INTEGER_CST
)
2057 error_at (value_loc
, "expression in static assertion is not constant");
2060 constant_expression_warning (value
);
2061 if (integer_zerop (value
))
2062 error_at (assert_loc
, "static assertion failed: %E", string
);
2065 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2066 6.7), adding them to SPECS (which may already include some).
2067 Storage class specifiers are accepted iff SCSPEC_OK; type
2068 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2069 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2070 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2072 declaration-specifiers:
2073 storage-class-specifier declaration-specifiers[opt]
2074 type-specifier declaration-specifiers[opt]
2075 type-qualifier declaration-specifiers[opt]
2076 function-specifier declaration-specifiers[opt]
2077 alignment-specifier declaration-specifiers[opt]
2079 Function specifiers (inline) are from C99, and are currently
2080 handled as storage class specifiers, as is __thread. Alignment
2081 specifiers are from C11.
2083 C90 6.5.1, C99 6.7.1:
2084 storage-class-specifier:
2092 (_Thread_local is new in C11.)
2099 (_Noreturn is new in C11.)
2101 C90 6.5.2, C99 6.7.2:
2114 [_Imaginary removed in C99 TC2]
2115 struct-or-union-specifier
2118 atomic-type-specifier
2120 (_Bool and _Complex are new in C99.)
2121 (atomic-type-specifier is new in C11.)
2123 C90 6.5.3, C99 6.7.3:
2129 address-space-qualifier
2132 (restrict is new in C99.)
2133 (_Atomic is new in C11.)
2137 declaration-specifiers:
2138 attributes declaration-specifiers[opt]
2144 identifier recognized by the target
2146 storage-class-specifier:
2160 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2161 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2163 atomic-type-specifier
2164 _Atomic ( type-name )
2169 class-name objc-protocol-refs[opt]
2170 typedef-name objc-protocol-refs
2175 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2176 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2177 bool alignspec_ok
, bool auto_type_ok
,
2178 enum c_lookahead_kind la
)
2180 bool attrs_ok
= start_attr_ok
;
2181 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2184 gcc_assert (la
== cla_prefer_id
);
2186 while (c_parser_next_token_is (parser
, CPP_NAME
)
2187 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2188 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2190 struct c_typespec t
;
2193 location_t loc
= c_parser_peek_token (parser
)->location
;
2195 /* If we cannot accept a type, exit if the next token must start
2196 one. Also, if we already have seen a tagged definition,
2197 a typename would be an error anyway and likely the user
2198 has simply forgotten a semicolon, so we exit. */
2199 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2200 && c_parser_next_tokens_start_typename (parser
, la
)
2201 && !c_parser_next_token_is_qualifier (parser
))
2204 if (c_parser_next_token_is (parser
, CPP_NAME
))
2206 c_token
*name_token
= c_parser_peek_token (parser
);
2207 tree value
= name_token
->value
;
2208 c_id_kind kind
= name_token
->id_kind
;
2210 if (kind
== C_ID_ADDRSPACE
)
2213 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2214 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2215 c_parser_consume_token (parser
);
2220 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2222 /* If we cannot accept a type, and the next token must start one,
2223 exit. Do the same if we already have seen a tagged definition,
2224 since it would be an error anyway and likely the user has simply
2225 forgotten a semicolon. */
2226 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2229 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2230 a C_ID_CLASSNAME. */
2231 c_parser_consume_token (parser
);
2234 if (kind
== C_ID_ID
)
2236 error_at (loc
, "unknown type name %qE", value
);
2237 t
.kind
= ctsk_typedef
;
2238 t
.spec
= error_mark_node
;
2240 else if (kind
== C_ID_TYPENAME
2241 && (!c_dialect_objc ()
2242 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2244 t
.kind
= ctsk_typedef
;
2245 /* For a typedef name, record the meaning, not the name.
2246 In case of 'foo foo, bar;'. */
2247 t
.spec
= lookup_name (value
);
2251 tree proto
= NULL_TREE
;
2252 gcc_assert (c_dialect_objc ());
2254 if (c_parser_next_token_is (parser
, CPP_LESS
))
2255 proto
= c_parser_objc_protocol_refs (parser
);
2256 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2259 t
.expr_const_operands
= true;
2260 declspecs_add_type (name_token
->location
, specs
, t
);
2263 if (c_parser_next_token_is (parser
, CPP_LESS
))
2265 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2266 nisse@lysator.liu.se. */
2268 gcc_assert (c_dialect_objc ());
2269 if (!typespec_ok
|| seen_type
)
2271 proto
= c_parser_objc_protocol_refs (parser
);
2273 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2275 t
.expr_const_operands
= true;
2276 declspecs_add_type (loc
, specs
, t
);
2279 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2280 switch (c_parser_peek_token (parser
)->keyword
)
2293 /* TODO: Distinguish between function specifiers (inline, noreturn)
2294 and storage class specifiers, either here or in
2295 declspecs_add_scspec. */
2296 declspecs_add_scspec (loc
, specs
,
2297 c_parser_peek_token (parser
)->value
);
2298 c_parser_consume_token (parser
);
2326 if (c_dialect_objc ())
2327 parser
->objc_need_raw_identifier
= true;
2328 t
.kind
= ctsk_resword
;
2329 t
.spec
= c_parser_peek_token (parser
)->value
;
2331 t
.expr_const_operands
= true;
2332 declspecs_add_type (loc
, specs
, t
);
2333 c_parser_consume_token (parser
);
2340 t
= c_parser_enum_specifier (parser
);
2341 declspecs_add_type (loc
, specs
, t
);
2349 t
= c_parser_struct_or_union_specifier (parser
);
2350 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2351 declspecs_add_type (loc
, specs
, t
);
2354 /* ??? The old parser rejected typeof after other type
2355 specifiers, but is a syntax error the best way of
2357 if (!typespec_ok
|| seen_type
)
2361 t
= c_parser_typeof_specifier (parser
);
2362 declspecs_add_type (loc
, specs
, t
);
2365 /* C parser handling of Objective-C constructs needs
2366 checking for correct lvalue-to-rvalue conversions, and
2367 the code in build_modify_expr handling various
2368 Objective-C cases, and that in build_unary_op handling
2369 Objective-C cases for increment / decrement, also needs
2370 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2371 and objc_types_are_equivalent may also need updates. */
2372 if (c_dialect_objc ())
2373 sorry ("%<_Atomic%> in Objective-C");
2374 /* C parser handling of OpenMP constructs needs checking for
2375 correct lvalue-to-rvalue conversions. */
2377 sorry ("%<_Atomic%> with OpenMP");
2381 pedwarn (loc
, OPT_Wpedantic
,
2382 "ISO C99 does not support the %<_Atomic%> qualifier");
2384 pedwarn (loc
, OPT_Wpedantic
,
2385 "ISO C90 does not support the %<_Atomic%> qualifier");
2389 value
= c_parser_peek_token (parser
)->value
;
2390 c_parser_consume_token (parser
);
2391 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2393 /* _Atomic ( type-name ). */
2395 c_parser_consume_token (parser
);
2396 struct c_type_name
*type
= c_parser_type_name (parser
);
2397 t
.kind
= ctsk_typeof
;
2398 t
.spec
= error_mark_node
;
2400 t
.expr_const_operands
= true;
2402 t
.spec
= groktypename (type
, &t
.expr
,
2403 &t
.expr_const_operands
);
2404 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2406 if (t
.spec
!= error_mark_node
)
2408 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2409 error_at (loc
, "%<_Atomic%>-qualified array type");
2410 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2411 error_at (loc
, "%<_Atomic%>-qualified function type");
2412 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2413 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2415 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2417 declspecs_add_type (loc
, specs
, t
);
2420 declspecs_add_qual (loc
, specs
, value
);
2426 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2427 c_parser_consume_token (parser
);
2432 attrs
= c_parser_attributes (parser
);
2433 declspecs_add_attrs (loc
, specs
, attrs
);
2438 align
= c_parser_alignas_specifier (parser
);
2439 declspecs_add_alignas (loc
, specs
, align
);
2448 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2451 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2452 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2453 enum attributes[opt] identifier
2455 The form with trailing comma is new in C99. The forms with
2456 attributes are GNU extensions. In GNU C, we accept any expression
2457 without commas in the syntax (assignment expressions, not just
2458 conditional expressions); assignment expressions will be diagnosed
2463 enumerator-list , enumerator
2466 enumeration-constant
2467 enumeration-constant = constant-expression
2470 static struct c_typespec
2471 c_parser_enum_specifier (c_parser
*parser
)
2473 struct c_typespec ret
;
2475 tree ident
= NULL_TREE
;
2476 location_t enum_loc
;
2477 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2478 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2479 enum_loc
= c_parser_peek_token (parser
)->location
;
2480 c_parser_consume_token (parser
);
2481 attrs
= c_parser_attributes (parser
);
2482 enum_loc
= c_parser_peek_token (parser
)->location
;
2483 /* Set the location in case we create a decl now. */
2484 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2485 if (c_parser_next_token_is (parser
, CPP_NAME
))
2487 ident
= c_parser_peek_token (parser
)->value
;
2488 ident_loc
= c_parser_peek_token (parser
)->location
;
2489 enum_loc
= ident_loc
;
2490 c_parser_consume_token (parser
);
2492 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2494 /* Parse an enum definition. */
2495 struct c_enum_contents the_enum
;
2498 /* We chain the enumerators in reverse order, then put them in
2499 forward order at the end. */
2501 timevar_push (TV_PARSE_ENUM
);
2502 type
= start_enum (enum_loc
, &the_enum
, ident
);
2504 c_parser_consume_token (parser
);
2512 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2513 location_t decl_loc
, value_loc
;
2514 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2516 c_parser_error (parser
, "expected identifier");
2517 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2518 values
= error_mark_node
;
2521 token
= c_parser_peek_token (parser
);
2522 enum_id
= token
->value
;
2523 /* Set the location in case we create a decl now. */
2524 c_parser_set_source_position_from_token (token
);
2525 decl_loc
= value_loc
= token
->location
;
2526 c_parser_consume_token (parser
);
2527 if (c_parser_next_token_is (parser
, CPP_EQ
))
2529 c_parser_consume_token (parser
);
2530 value_loc
= c_parser_peek_token (parser
)->location
;
2531 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2534 enum_value
= NULL_TREE
;
2535 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2536 &the_enum
, enum_id
, enum_value
);
2537 TREE_CHAIN (enum_decl
) = values
;
2540 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2542 comma_loc
= c_parser_peek_token (parser
)->location
;
2544 c_parser_consume_token (parser
);
2546 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2548 if (seen_comma
&& !flag_isoc99
)
2549 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2550 c_parser_consume_token (parser
);
2555 c_parser_error (parser
, "expected %<,%> or %<}%>");
2556 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2557 values
= error_mark_node
;
2561 postfix_attrs
= c_parser_attributes (parser
);
2562 ret
.spec
= finish_enum (type
, nreverse (values
),
2563 chainon (attrs
, postfix_attrs
));
2564 ret
.kind
= ctsk_tagdef
;
2565 ret
.expr
= NULL_TREE
;
2566 ret
.expr_const_operands
= true;
2567 timevar_pop (TV_PARSE_ENUM
);
2572 c_parser_error (parser
, "expected %<{%>");
2573 ret
.spec
= error_mark_node
;
2574 ret
.kind
= ctsk_tagref
;
2575 ret
.expr
= NULL_TREE
;
2576 ret
.expr_const_operands
= true;
2579 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2580 /* In ISO C, enumerated types can be referred to only if already
2582 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2585 pedwarn (enum_loc
, OPT_Wpedantic
,
2586 "ISO C forbids forward references to %<enum%> types");
2591 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2593 struct-or-union-specifier:
2594 struct-or-union attributes[opt] identifier[opt]
2595 { struct-contents } attributes[opt]
2596 struct-or-union attributes[opt] identifier
2599 struct-declaration-list
2601 struct-declaration-list:
2602 struct-declaration ;
2603 struct-declaration-list struct-declaration ;
2610 struct-declaration-list struct-declaration
2612 struct-declaration-list:
2613 struct-declaration-list ;
2616 (Note that in the syntax here, unlike that in ISO C, the semicolons
2617 are included here rather than in struct-declaration, in order to
2618 describe the syntax with extra semicolons and missing semicolon at
2623 struct-declaration-list:
2624 @defs ( class-name )
2626 (Note this does not include a trailing semicolon, but can be
2627 followed by further declarations, and gets a pedwarn-if-pedantic
2628 when followed by a semicolon.) */
2630 static struct c_typespec
2631 c_parser_struct_or_union_specifier (c_parser
*parser
)
2633 struct c_typespec ret
;
2635 tree ident
= NULL_TREE
;
2636 location_t struct_loc
;
2637 location_t ident_loc
= UNKNOWN_LOCATION
;
2638 enum tree_code code
;
2639 switch (c_parser_peek_token (parser
)->keyword
)
2650 struct_loc
= c_parser_peek_token (parser
)->location
;
2651 c_parser_consume_token (parser
);
2652 attrs
= c_parser_attributes (parser
);
2654 /* Set the location in case we create a decl now. */
2655 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2657 if (c_parser_next_token_is (parser
, CPP_NAME
))
2659 ident
= c_parser_peek_token (parser
)->value
;
2660 ident_loc
= c_parser_peek_token (parser
)->location
;
2661 struct_loc
= ident_loc
;
2662 c_parser_consume_token (parser
);
2664 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2666 /* Parse a struct or union definition. Start the scope of the
2667 tag before parsing components. */
2668 struct c_struct_parse_info
*struct_info
;
2669 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2671 /* We chain the components in reverse order, then put them in
2672 forward order at the end. Each struct-declaration may
2673 declare multiple components (comma-separated), so we must use
2674 chainon to join them, although when parsing each
2675 struct-declaration we can use TREE_CHAIN directly.
2677 The theory behind all this is that there will be more
2678 semicolon separated fields than comma separated fields, and
2679 so we'll be minimizing the number of node traversals required
2682 timevar_push (TV_PARSE_STRUCT
);
2683 contents
= NULL_TREE
;
2684 c_parser_consume_token (parser
);
2685 /* Handle the Objective-C @defs construct,
2686 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2687 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2690 gcc_assert (c_dialect_objc ());
2691 c_parser_consume_token (parser
);
2692 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2694 if (c_parser_next_token_is (parser
, CPP_NAME
)
2695 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2697 name
= c_parser_peek_token (parser
)->value
;
2698 c_parser_consume_token (parser
);
2702 c_parser_error (parser
, "expected class name");
2703 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2706 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2708 contents
= nreverse (objc_get_class_ivars (name
));
2711 /* Parse the struct-declarations and semicolons. Problems with
2712 semicolons are diagnosed here; empty structures are diagnosed
2717 /* Parse any stray semicolon. */
2718 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2720 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2721 "extra semicolon in struct or union specified");
2722 c_parser_consume_token (parser
);
2725 /* Stop if at the end of the struct or union contents. */
2726 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2728 c_parser_consume_token (parser
);
2731 /* Accept #pragmas at struct scope. */
2732 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2734 c_parser_pragma (parser
, pragma_struct
);
2737 /* Parse some comma-separated declarations, but not the
2738 trailing semicolon if any. */
2739 decls
= c_parser_struct_declaration (parser
);
2740 contents
= chainon (decls
, contents
);
2741 /* If no semicolon follows, either we have a parse error or
2742 are at the end of the struct or union and should
2744 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2745 c_parser_consume_token (parser
);
2748 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2749 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2750 "no semicolon at end of struct or union");
2751 else if (parser
->error
2752 || !c_parser_next_token_starts_declspecs (parser
))
2754 c_parser_error (parser
, "expected %<;%>");
2755 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2759 /* If we come here, we have already emitted an error
2760 for an expected `;', identifier or `(', and we also
2761 recovered already. Go on with the next field. */
2764 postfix_attrs
= c_parser_attributes (parser
);
2765 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2766 chainon (attrs
, postfix_attrs
), struct_info
);
2767 ret
.kind
= ctsk_tagdef
;
2768 ret
.expr
= NULL_TREE
;
2769 ret
.expr_const_operands
= true;
2770 timevar_pop (TV_PARSE_STRUCT
);
2775 c_parser_error (parser
, "expected %<{%>");
2776 ret
.spec
= error_mark_node
;
2777 ret
.kind
= ctsk_tagref
;
2778 ret
.expr
= NULL_TREE
;
2779 ret
.expr_const_operands
= true;
2782 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2786 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2787 the trailing semicolon.
2790 specifier-qualifier-list struct-declarator-list
2791 static_assert-declaration-no-semi
2793 specifier-qualifier-list:
2794 type-specifier specifier-qualifier-list[opt]
2795 type-qualifier specifier-qualifier-list[opt]
2796 attributes specifier-qualifier-list[opt]
2798 struct-declarator-list:
2800 struct-declarator-list , attributes[opt] struct-declarator
2803 declarator attributes[opt]
2804 declarator[opt] : constant-expression attributes[opt]
2809 __extension__ struct-declaration
2810 specifier-qualifier-list
2812 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2813 of attributes where shown is a GNU extension. In GNU C, we accept
2814 any expression without commas in the syntax (assignment
2815 expressions, not just conditional expressions); assignment
2816 expressions will be diagnosed as non-constant. */
2819 c_parser_struct_declaration (c_parser
*parser
)
2821 struct c_declspecs
*specs
;
2823 tree all_prefix_attrs
;
2825 location_t decl_loc
;
2826 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2830 ext
= disable_extension_diagnostics ();
2831 c_parser_consume_token (parser
);
2832 decl
= c_parser_struct_declaration (parser
);
2833 restore_extension_diagnostics (ext
);
2836 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2838 c_parser_static_assert_declaration_no_semi (parser
);
2841 specs
= build_null_declspecs ();
2842 decl_loc
= c_parser_peek_token (parser
)->location
;
2843 /* Strictly by the standard, we shouldn't allow _Alignas here,
2844 but it appears to have been intended to allow it there, so
2845 we're keeping it as it is until WG14 reaches a conclusion
2847 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2848 c_parser_declspecs (parser
, specs
, false, true, true,
2849 true, false, cla_nonabstract_decl
);
2852 if (!specs
->declspecs_seen_p
)
2854 c_parser_error (parser
, "expected specifier-qualifier-list");
2857 finish_declspecs (specs
);
2858 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2859 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2862 if (specs
->typespec_kind
== ctsk_none
)
2864 pedwarn (decl_loc
, OPT_Wpedantic
,
2865 "ISO C forbids member declarations with no members");
2866 shadow_tag_warned (specs
, pedantic
);
2871 /* Support for unnamed structs or unions as members of
2872 structs or unions (which is [a] useful and [b] supports
2876 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2877 build_id_declarator (NULL_TREE
), specs
,
2880 decl_attributes (&ret
, attrs
, 0);
2885 /* Provide better error recovery. Note that a type name here is valid,
2886 and will be treated as a field name. */
2887 if (specs
->typespec_kind
== ctsk_tagdef
2888 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2889 && c_parser_next_token_starts_declspecs (parser
)
2890 && !c_parser_next_token_is (parser
, CPP_NAME
))
2892 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2893 parser
->error
= false;
2897 pending_xref_error ();
2898 prefix_attrs
= specs
->attrs
;
2899 all_prefix_attrs
= prefix_attrs
;
2900 specs
->attrs
= NULL_TREE
;
2904 /* Declaring one or more declarators or un-named bit-fields. */
2905 struct c_declarator
*declarator
;
2907 if (c_parser_next_token_is (parser
, CPP_COLON
))
2908 declarator
= build_id_declarator (NULL_TREE
);
2910 declarator
= c_parser_declarator (parser
,
2911 specs
->typespec_kind
!= ctsk_none
,
2912 C_DTR_NORMAL
, &dummy
);
2913 if (declarator
== NULL
)
2915 c_parser_skip_to_end_of_block_or_statement (parser
);
2918 if (c_parser_next_token_is (parser
, CPP_COLON
)
2919 || c_parser_next_token_is (parser
, CPP_COMMA
)
2920 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2921 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2922 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2924 tree postfix_attrs
= NULL_TREE
;
2925 tree width
= NULL_TREE
;
2927 if (c_parser_next_token_is (parser
, CPP_COLON
))
2929 c_parser_consume_token (parser
);
2930 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2932 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2933 postfix_attrs
= c_parser_attributes (parser
);
2934 d
= grokfield (c_parser_peek_token (parser
)->location
,
2935 declarator
, specs
, width
, &all_prefix_attrs
);
2936 decl_attributes (&d
, chainon (postfix_attrs
,
2937 all_prefix_attrs
), 0);
2938 DECL_CHAIN (d
) = decls
;
2940 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2941 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2944 all_prefix_attrs
= prefix_attrs
;
2945 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2946 c_parser_consume_token (parser
);
2947 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2948 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2950 /* Semicolon consumed in caller. */
2955 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2961 c_parser_error (parser
,
2962 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2963 "%<__attribute__%>");
2970 /* Parse a typeof specifier (a GNU extension).
2973 typeof ( expression )
2974 typeof ( type-name )
2977 static struct c_typespec
2978 c_parser_typeof_specifier (c_parser
*parser
)
2980 struct c_typespec ret
;
2981 ret
.kind
= ctsk_typeof
;
2982 ret
.spec
= error_mark_node
;
2983 ret
.expr
= NULL_TREE
;
2984 ret
.expr_const_operands
= true;
2985 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2986 c_parser_consume_token (parser
);
2987 c_inhibit_evaluation_warnings
++;
2989 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2991 c_inhibit_evaluation_warnings
--;
2995 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2997 struct c_type_name
*type
= c_parser_type_name (parser
);
2998 c_inhibit_evaluation_warnings
--;
3002 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3003 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3009 location_t here
= c_parser_peek_token (parser
)->location
;
3010 struct c_expr expr
= c_parser_expression (parser
);
3011 c_inhibit_evaluation_warnings
--;
3013 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3014 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3015 error_at (here
, "%<typeof%> applied to a bit-field");
3016 mark_exp_read (expr
.value
);
3017 ret
.spec
= TREE_TYPE (expr
.value
);
3018 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3019 /* This is returned with the type so that when the type is
3020 evaluated, this can be evaluated. */
3022 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3023 pop_maybe_used (was_vm
);
3024 /* For use in macros such as those in <stdatomic.h>, remove all
3025 qualifiers from atomic types. (const can be an issue for more macros
3026 using typeof than just the <stdatomic.h> ones.) */
3027 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3028 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3030 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3034 /* Parse an alignment-specifier.
3038 alignment-specifier:
3039 _Alignas ( type-name )
3040 _Alignas ( constant-expression )
3044 c_parser_alignas_specifier (c_parser
* parser
)
3046 tree ret
= error_mark_node
;
3047 location_t loc
= c_parser_peek_token (parser
)->location
;
3048 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3049 c_parser_consume_token (parser
);
3053 pedwarn (loc
, OPT_Wpedantic
,
3054 "ISO C99 does not support %<_Alignas%>");
3056 pedwarn (loc
, OPT_Wpedantic
,
3057 "ISO C90 does not support %<_Alignas%>");
3059 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3061 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3063 struct c_type_name
*type
= c_parser_type_name (parser
);
3065 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3069 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3070 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3074 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3075 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3076 be redeclared; otherwise it may not. KIND indicates which kind of
3077 declarator is wanted. Returns a valid declarator except in the
3078 case of a syntax error in which case NULL is returned. *SEEN_ID is
3079 set to true if an identifier being declared is seen; this is used
3080 to diagnose bad forms of abstract array declarators and to
3081 determine whether an identifier list is syntactically permitted.
3084 pointer[opt] direct-declarator
3088 ( attributes[opt] declarator )
3089 direct-declarator array-declarator
3090 direct-declarator ( parameter-type-list )
3091 direct-declarator ( identifier-list[opt] )
3094 * type-qualifier-list[opt]
3095 * type-qualifier-list[opt] pointer
3097 type-qualifier-list:
3100 type-qualifier-list type-qualifier
3101 type-qualifier-list attributes
3104 [ type-qualifier-list[opt] assignment-expression[opt] ]
3105 [ static type-qualifier-list[opt] assignment-expression ]
3106 [ type-qualifier-list static assignment-expression ]
3107 [ type-qualifier-list[opt] * ]
3109 parameter-type-list:
3111 parameter-list , ...
3114 parameter-declaration
3115 parameter-list , parameter-declaration
3117 parameter-declaration:
3118 declaration-specifiers declarator attributes[opt]
3119 declaration-specifiers abstract-declarator[opt] attributes[opt]
3123 identifier-list , identifier
3125 abstract-declarator:
3127 pointer[opt] direct-abstract-declarator
3129 direct-abstract-declarator:
3130 ( attributes[opt] abstract-declarator )
3131 direct-abstract-declarator[opt] array-declarator
3132 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3137 direct-declarator ( parameter-forward-declarations
3138 parameter-type-list[opt] )
3140 direct-abstract-declarator:
3141 direct-abstract-declarator[opt] ( parameter-forward-declarations
3142 parameter-type-list[opt] )
3144 parameter-forward-declarations:
3146 parameter-forward-declarations parameter-list ;
3148 The uses of attributes shown above are GNU extensions.
3150 Some forms of array declarator are not included in C99 in the
3151 syntax for abstract declarators; these are disallowed elsewhere.
3152 This may be a defect (DR#289).
3154 This function also accepts an omitted abstract declarator as being
3155 an abstract declarator, although not part of the formal syntax. */
3157 static struct c_declarator
*
3158 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3161 /* Parse any initial pointer part. */
3162 if (c_parser_next_token_is (parser
, CPP_MULT
))
3164 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3165 struct c_declarator
*inner
;
3166 c_parser_consume_token (parser
);
3167 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3168 false, false, cla_prefer_id
);
3169 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3173 return make_pointer_declarator (quals_attrs
, inner
);
3175 /* Now we have a direct declarator, direct abstract declarator or
3176 nothing (which counts as a direct abstract declarator here). */
3177 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3180 /* Parse a direct declarator or direct abstract declarator; arguments
3181 as c_parser_declarator. */
3183 static struct c_declarator
*
3184 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3187 /* The direct declarator must start with an identifier (possibly
3188 omitted) or a parenthesized declarator (possibly abstract). In
3189 an ordinary declarator, initial parentheses must start a
3190 parenthesized declarator. In an abstract declarator or parameter
3191 declarator, they could start a parenthesized declarator or a
3192 parameter list. To tell which, the open parenthesis and any
3193 following attributes must be read. If a declaration specifier
3194 follows, then it is a parameter list; if the specifier is a
3195 typedef name, there might be an ambiguity about redeclaring it,
3196 which is resolved in the direction of treating it as a typedef
3197 name. If a close parenthesis follows, it is also an empty
3198 parameter list, as the syntax does not permit empty abstract
3199 declarators. Otherwise, it is a parenthesized declarator (in
3200 which case the analysis may be repeated inside it, recursively).
3202 ??? There is an ambiguity in a parameter declaration "int
3203 (__attribute__((foo)) x)", where x is not a typedef name: it
3204 could be an abstract declarator for a function, or declare x with
3205 parentheses. The proper resolution of this ambiguity needs
3206 documenting. At present we follow an accident of the old
3207 parser's implementation, whereby the first parameter must have
3208 some declaration specifiers other than just attributes. Thus as
3209 a parameter declaration it is treated as a parenthesized
3210 parameter named x, and as an abstract declarator it is
3213 ??? Also following the old parser, attributes inside an empty
3214 parameter list are ignored, making it a list not yielding a
3215 prototype, rather than giving an error or making it have one
3216 parameter with implicit type int.
3218 ??? Also following the old parser, typedef names may be
3219 redeclared in declarators, but not Objective-C class names. */
3221 if (kind
!= C_DTR_ABSTRACT
3222 && c_parser_next_token_is (parser
, CPP_NAME
)
3224 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3225 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3226 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3228 struct c_declarator
*inner
3229 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3231 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3232 c_parser_consume_token (parser
);
3233 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3236 if (kind
!= C_DTR_NORMAL
3237 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3239 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3240 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3243 /* Either we are at the end of an abstract declarator, or we have
3246 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3249 struct c_declarator
*inner
;
3250 c_parser_consume_token (parser
);
3251 attrs
= c_parser_attributes (parser
);
3252 if (kind
!= C_DTR_NORMAL
3253 && (c_parser_next_token_starts_declspecs (parser
)
3254 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3256 struct c_arg_info
*args
3257 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3264 = build_function_declarator (args
,
3265 build_id_declarator (NULL_TREE
));
3266 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3270 /* A parenthesized declarator. */
3271 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3272 if (inner
!= NULL
&& attrs
!= NULL
)
3273 inner
= build_attrs_declarator (attrs
, inner
);
3274 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3276 c_parser_consume_token (parser
);
3280 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3284 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3291 if (kind
== C_DTR_NORMAL
)
3293 c_parser_error (parser
, "expected identifier or %<(%>");
3297 return build_id_declarator (NULL_TREE
);
3301 /* Parse part of a direct declarator or direct abstract declarator,
3302 given that some (in INNER) has already been parsed; ID_PRESENT is
3303 true if an identifier is present, false for an abstract
3306 static struct c_declarator
*
3307 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3308 struct c_declarator
*inner
)
3310 /* Parse a sequence of array declarators and parameter lists. */
3311 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3313 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3314 struct c_declarator
*declarator
;
3315 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3318 struct c_expr dimen
;
3319 dimen
.value
= NULL_TREE
;
3320 dimen
.original_code
= ERROR_MARK
;
3321 dimen
.original_type
= NULL_TREE
;
3322 c_parser_consume_token (parser
);
3323 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3324 false, false, cla_prefer_id
);
3325 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3327 c_parser_consume_token (parser
);
3328 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3329 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3330 false, false, cla_prefer_id
);
3331 if (!quals_attrs
->declspecs_seen_p
)
3333 /* If "static" is present, there must be an array dimension.
3334 Otherwise, there may be a dimension, "*", or no
3339 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3343 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3345 dimen
.value
= NULL_TREE
;
3348 else if (flag_cilkplus
3349 && c_parser_next_token_is (parser
, CPP_COLON
))
3351 dimen
.value
= error_mark_node
;
3353 error_at (c_parser_peek_token (parser
)->location
,
3354 "array notations cannot be used in declaration");
3355 c_parser_consume_token (parser
);
3357 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3359 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3361 dimen
.value
= NULL_TREE
;
3363 c_parser_consume_token (parser
);
3368 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3374 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3377 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3378 c_parser_consume_token (parser
);
3379 else if (flag_cilkplus
3380 && c_parser_next_token_is (parser
, CPP_COLON
))
3382 error_at (c_parser_peek_token (parser
)->location
,
3383 "array notations cannot be used in declaration");
3384 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3389 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3394 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3395 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3396 static_seen
, star_seen
);
3397 if (declarator
== NULL
)
3399 inner
= set_array_declarator_inner (declarator
, inner
);
3400 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3402 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3405 struct c_arg_info
*args
;
3406 c_parser_consume_token (parser
);
3407 attrs
= c_parser_attributes (parser
);
3408 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3413 inner
= build_function_declarator (args
, inner
);
3414 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3420 /* Parse a parameter list or identifier list, including the closing
3421 parenthesis but not the opening one. ATTRS are the attributes at
3422 the start of the list. ID_LIST_OK is true if an identifier list is
3423 acceptable; such a list must not have attributes at the start. */
3425 static struct c_arg_info
*
3426 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3429 declare_parm_level ();
3430 /* If the list starts with an identifier, it is an identifier list.
3431 Otherwise, it is either a prototype list or an empty list. */
3434 && c_parser_next_token_is (parser
, CPP_NAME
)
3435 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3437 /* Look ahead to detect typos in type names. */
3438 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3439 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3440 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3441 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3443 tree list
= NULL_TREE
, *nextp
= &list
;
3444 while (c_parser_next_token_is (parser
, CPP_NAME
)
3445 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3447 *nextp
= build_tree_list (NULL_TREE
,
3448 c_parser_peek_token (parser
)->value
);
3449 nextp
= & TREE_CHAIN (*nextp
);
3450 c_parser_consume_token (parser
);
3451 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3453 c_parser_consume_token (parser
);
3454 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3456 c_parser_error (parser
, "expected identifier");
3460 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3462 struct c_arg_info
*ret
= build_arg_info ();
3464 c_parser_consume_token (parser
);
3470 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3478 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3485 /* Parse a parameter list (possibly empty), including the closing
3486 parenthesis but not the opening one. ATTRS are the attributes at
3487 the start of the list. EXPR is NULL or an expression that needs to
3488 be evaluated for the side effects of array size expressions in the
3491 static struct c_arg_info
*
3492 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3494 bool bad_parm
= false;
3496 /* ??? Following the old parser, forward parameter declarations may
3497 use abstract declarators, and if no real parameter declarations
3498 follow the forward declarations then this is not diagnosed. Also
3499 note as above that attributes are ignored as the only contents of
3500 the parentheses, or as the only contents after forward
3502 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3504 struct c_arg_info
*ret
= build_arg_info ();
3505 c_parser_consume_token (parser
);
3508 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3510 struct c_arg_info
*ret
= build_arg_info ();
3512 if (flag_allow_parameterless_variadic_functions
)
3514 /* F (...) is allowed. */
3515 ret
->types
= NULL_TREE
;
3519 /* Suppress -Wold-style-definition for this case. */
3520 ret
->types
= error_mark_node
;
3521 error_at (c_parser_peek_token (parser
)->location
,
3522 "ISO C requires a named argument before %<...%>");
3524 c_parser_consume_token (parser
);
3525 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3527 c_parser_consume_token (parser
);
3532 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3537 /* Nonempty list of parameters, either terminated with semicolon
3538 (forward declarations; recurse) or with close parenthesis (normal
3539 function) or with ", ... )" (variadic function). */
3542 /* Parse a parameter. */
3543 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3548 push_parm_decl (parm
, &expr
);
3549 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3552 c_parser_consume_token (parser
);
3553 mark_forward_parm_decls ();
3554 new_attrs
= c_parser_attributes (parser
);
3555 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3557 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3559 c_parser_consume_token (parser
);
3563 return get_parm_info (false, expr
);
3565 if (!c_parser_require (parser
, CPP_COMMA
,
3566 "expected %<;%>, %<,%> or %<)%>"))
3568 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3571 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3573 c_parser_consume_token (parser
);
3574 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3576 c_parser_consume_token (parser
);
3580 return get_parm_info (true, expr
);
3584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3592 /* Parse a parameter declaration. ATTRS are the attributes at the
3593 start of the declaration if it is the first parameter. */
3595 static struct c_parm
*
3596 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3598 struct c_declspecs
*specs
;
3599 struct c_declarator
*declarator
;
3601 tree postfix_attrs
= NULL_TREE
;
3604 /* Accept #pragmas between parameter declarations. */
3605 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3606 c_parser_pragma (parser
, pragma_param
);
3608 if (!c_parser_next_token_starts_declspecs (parser
))
3610 c_token
*token
= c_parser_peek_token (parser
);
3613 c_parser_set_source_position_from_token (token
);
3614 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3616 error_at (token
->location
, "unknown type name %qE", token
->value
);
3617 parser
->error
= true;
3619 /* ??? In some Objective-C cases '...' isn't applicable so there
3620 should be a different message. */
3622 c_parser_error (parser
,
3623 "expected declaration specifiers or %<...%>");
3624 c_parser_skip_to_end_of_parameter (parser
);
3627 specs
= build_null_declspecs ();
3630 declspecs_add_attrs (input_location
, specs
, attrs
);
3633 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3634 cla_nonabstract_decl
);
3635 finish_declspecs (specs
);
3636 pending_xref_error ();
3637 prefix_attrs
= specs
->attrs
;
3638 specs
->attrs
= NULL_TREE
;
3639 declarator
= c_parser_declarator (parser
,
3640 specs
->typespec_kind
!= ctsk_none
,
3641 C_DTR_PARM
, &dummy
);
3642 if (declarator
== NULL
)
3644 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3647 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3648 postfix_attrs
= c_parser_attributes (parser
);
3649 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3653 /* Parse a string literal in an asm expression. It should not be
3654 translated, and wide string literals are an error although
3655 permitted by the syntax. This is a GNU extension.
3660 ??? At present, following the old parser, the caller needs to have
3661 set lex_untranslated_string to 1. It would be better to follow the
3662 C++ parser rather than using this kludge. */
3665 c_parser_asm_string_literal (c_parser
*parser
)
3668 int save_flag
= warn_overlength_strings
;
3669 warn_overlength_strings
= 0;
3670 if (c_parser_next_token_is (parser
, CPP_STRING
))
3672 str
= c_parser_peek_token (parser
)->value
;
3673 c_parser_consume_token (parser
);
3675 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3677 error_at (c_parser_peek_token (parser
)->location
,
3678 "wide string literal in %<asm%>");
3679 str
= build_string (1, "");
3680 c_parser_consume_token (parser
);
3684 c_parser_error (parser
, "expected string literal");
3687 warn_overlength_strings
= save_flag
;
3691 /* Parse a simple asm expression. This is used in restricted
3692 contexts, where a full expression with inputs and outputs does not
3693 make sense. This is a GNU extension.
3696 asm ( asm-string-literal )
3700 c_parser_simple_asm_expr (c_parser
*parser
)
3703 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3704 /* ??? Follow the C++ parser rather than using the
3705 lex_untranslated_string kludge. */
3706 parser
->lex_untranslated_string
= true;
3707 c_parser_consume_token (parser
);
3708 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3710 parser
->lex_untranslated_string
= false;
3713 str
= c_parser_asm_string_literal (parser
);
3714 parser
->lex_untranslated_string
= false;
3715 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3717 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3724 c_parser_attribute_any_word (c_parser
*parser
)
3726 tree attr_name
= NULL_TREE
;
3728 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3730 /* ??? See comment above about what keywords are accepted here. */
3732 switch (c_parser_peek_token (parser
)->keyword
)
3763 case RID_TRANSACTION_ATOMIC
:
3764 case RID_TRANSACTION_CANCEL
:
3776 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3777 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3779 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3780 attr_name
= c_parser_peek_token (parser
)->value
;
3785 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3786 "__vector" or "__vector__." */
3789 is_cilkplus_vector_p (tree name
)
3791 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3796 #define CILK_SIMD_FN_CLAUSE_MASK \
3797 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3798 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3799 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3800 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3801 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3803 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3804 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3805 pushed into the token list.
3808 vector (<vector attributes>). */
3811 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3813 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3815 int paren_scope
= 0;
3816 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3817 /* Consume the "vector" token. */
3818 c_parser_consume_token (parser
);
3820 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3822 c_parser_consume_token (parser
);
3825 while (paren_scope
> 0)
3827 c_token
*token
= c_parser_peek_token (parser
);
3828 if (token
->type
== CPP_OPEN_PAREN
)
3830 else if (token
->type
== CPP_CLOSE_PAREN
)
3832 /* Do not push the last ')' since we are not pushing the '('. */
3833 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3834 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3835 c_parser_consume_token (parser
);
3838 /* Since we are converting an attribute to a pragma, we need to end the
3839 attribute with PRAGMA_EOL. */
3841 memset (&eol_token
, 0, sizeof (eol_token
));
3842 eol_token
.type
= CPP_PRAGMA_EOL
;
3843 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3846 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3849 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3851 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3853 /* c_parser_attributes is called in several places, so if these EOF
3854 tokens are already inserted, then don't do them again. */
3855 if (last_token
.type
== CPP_EOF
)
3858 /* Two CPP_EOF token are added as a safety net since the normal C
3859 front-end has two token look-ahead. */
3861 eof_token
.type
= CPP_EOF
;
3862 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3863 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3866 /* Parse (possibly empty) attributes. This is a GNU extension.
3870 attributes attribute
3873 __attribute__ ( ( attribute-list ) )
3877 attribute_list , attrib
3882 any-word ( identifier )
3883 any-word ( identifier , nonempty-expr-list )
3884 any-word ( expr-list )
3886 where the "identifier" must not be declared as a type, and
3887 "any-word" may be any identifier (including one declared as a
3888 type), a reserved word storage class specifier, type specifier or
3889 type qualifier. ??? This still leaves out most reserved keywords
3890 (following the old parser), shouldn't we include them, and why not
3891 allow identifiers declared as types to start the arguments? */
3894 c_parser_attributes (c_parser
*parser
)
3896 tree attrs
= NULL_TREE
;
3897 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3899 /* ??? Follow the C++ parser rather than using the
3900 lex_untranslated_string kludge. */
3901 parser
->lex_untranslated_string
= true;
3902 c_parser_consume_token (parser
);
3903 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3905 parser
->lex_untranslated_string
= false;
3908 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3910 parser
->lex_untranslated_string
= false;
3911 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3914 /* Parse the attribute list. */
3915 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3916 || c_parser_next_token_is (parser
, CPP_NAME
)
3917 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3919 tree attr
, attr_name
, attr_args
;
3920 vec
<tree
, va_gc
> *expr_list
;
3921 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3923 c_parser_consume_token (parser
);
3927 attr_name
= c_parser_attribute_any_word (parser
);
3928 if (attr_name
== NULL
)
3930 if (is_cilkplus_vector_p (attr_name
))
3932 c_token
*v_token
= c_parser_peek_token (parser
);
3933 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3936 c_parser_consume_token (parser
);
3937 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3939 attr
= build_tree_list (attr_name
, NULL_TREE
);
3940 attrs
= chainon (attrs
, attr
);
3943 c_parser_consume_token (parser
);
3944 /* Parse the attribute contents. If they start with an
3945 identifier which is followed by a comma or close
3946 parenthesis, then the arguments start with that
3947 identifier; otherwise they are an expression list.
3948 In objective-c the identifier may be a classname. */
3949 if (c_parser_next_token_is (parser
, CPP_NAME
)
3950 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3951 || (c_dialect_objc ()
3952 && c_parser_peek_token (parser
)->id_kind
3954 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3955 || (c_parser_peek_2nd_token (parser
)->type
3956 == CPP_CLOSE_PAREN
))
3957 && (attribute_takes_identifier_p (attr_name
)
3958 || (c_dialect_objc ()
3959 && c_parser_peek_token (parser
)->id_kind
3960 == C_ID_CLASSNAME
)))
3962 tree arg1
= c_parser_peek_token (parser
)->value
;
3963 c_parser_consume_token (parser
);
3964 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3965 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3969 c_parser_consume_token (parser
);
3970 expr_list
= c_parser_expr_list (parser
, false, true,
3971 NULL
, NULL
, NULL
, NULL
);
3972 tree_list
= build_tree_list_vec (expr_list
);
3973 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3974 release_tree_vector (expr_list
);
3979 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3980 attr_args
= NULL_TREE
;
3983 expr_list
= c_parser_expr_list (parser
, false, true,
3984 NULL
, NULL
, NULL
, NULL
);
3985 attr_args
= build_tree_list_vec (expr_list
);
3986 release_tree_vector (expr_list
);
3989 attr
= build_tree_list (attr_name
, attr_args
);
3990 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3991 c_parser_consume_token (parser
);
3994 parser
->lex_untranslated_string
= false;
3995 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3999 attrs
= chainon (attrs
, attr
);
4001 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4002 c_parser_consume_token (parser
);
4005 parser
->lex_untranslated_string
= false;
4006 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4010 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4011 c_parser_consume_token (parser
);
4014 parser
->lex_untranslated_string
= false;
4015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4019 parser
->lex_untranslated_string
= false;
4022 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4023 c_finish_cilk_simd_fn_tokens (parser
);
4027 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4030 specifier-qualifier-list abstract-declarator[opt]
4033 static struct c_type_name
*
4034 c_parser_type_name (c_parser
*parser
)
4036 struct c_declspecs
*specs
= build_null_declspecs ();
4037 struct c_declarator
*declarator
;
4038 struct c_type_name
*ret
;
4040 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4042 if (!specs
->declspecs_seen_p
)
4044 c_parser_error (parser
, "expected specifier-qualifier-list");
4047 if (specs
->type
!= error_mark_node
)
4049 pending_xref_error ();
4050 finish_declspecs (specs
);
4052 declarator
= c_parser_declarator (parser
,
4053 specs
->typespec_kind
!= ctsk_none
,
4054 C_DTR_ABSTRACT
, &dummy
);
4055 if (declarator
== NULL
)
4057 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4059 ret
->declarator
= declarator
;
4063 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4066 assignment-expression
4067 { initializer-list }
4068 { initializer-list , }
4071 designation[opt] initializer
4072 initializer-list , designation[opt] initializer
4079 designator-list designator
4086 [ constant-expression ]
4098 [ constant-expression ... constant-expression ]
4100 Any expression without commas is accepted in the syntax for the
4101 constant-expressions, with non-constant expressions rejected later.
4103 This function is only used for top-level initializers; for nested
4104 ones, see c_parser_initval. */
4106 static struct c_expr
4107 c_parser_initializer (c_parser
*parser
)
4109 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4110 return c_parser_braced_init (parser
, NULL_TREE
, false);
4114 location_t loc
= c_parser_peek_token (parser
)->location
;
4115 ret
= c_parser_expr_no_commas (parser
, NULL
);
4116 if (TREE_CODE (ret
.value
) != STRING_CST
4117 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4118 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4123 /* Parse a braced initializer list. TYPE is the type specified for a
4124 compound literal, and NULL_TREE for other initializers and for
4125 nested braced lists. NESTED_P is true for nested braced lists,
4126 false for the list of a compound literal or the list that is the
4127 top-level initializer in a declaration. */
4129 static struct c_expr
4130 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4133 struct obstack braced_init_obstack
;
4134 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4135 gcc_obstack_init (&braced_init_obstack
);
4136 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4137 c_parser_consume_token (parser
);
4139 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4141 really_start_incremental_init (type
);
4142 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4144 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4148 /* Parse a non-empty initializer list, possibly with a trailing
4152 c_parser_initelt (parser
, &braced_init_obstack
);
4155 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4156 c_parser_consume_token (parser
);
4159 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4163 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4165 ret
.value
= error_mark_node
;
4166 ret
.original_code
= ERROR_MARK
;
4167 ret
.original_type
= NULL
;
4168 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4169 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4170 obstack_free (&braced_init_obstack
, NULL
);
4173 c_parser_consume_token (parser
);
4174 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4175 obstack_free (&braced_init_obstack
, NULL
);
4179 /* Parse a nested initializer, including designators. */
4182 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4184 /* Parse any designator or designator list. A single array
4185 designator may have the subsequent "=" omitted in GNU C, but a
4186 longer list or a structure member designator may not. */
4187 if (c_parser_next_token_is (parser
, CPP_NAME
)
4188 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4190 /* Old-style structure member designator. */
4191 set_init_label (c_parser_peek_token (parser
)->location
,
4192 c_parser_peek_token (parser
)->value
,
4193 braced_init_obstack
);
4194 /* Use the colon as the error location. */
4195 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4196 "obsolete use of designated initializer with %<:%>");
4197 c_parser_consume_token (parser
);
4198 c_parser_consume_token (parser
);
4202 /* des_seen is 0 if there have been no designators, 1 if there
4203 has been a single array designator and 2 otherwise. */
4205 /* Location of a designator. */
4206 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4207 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4208 || c_parser_next_token_is (parser
, CPP_DOT
))
4210 int des_prev
= des_seen
;
4212 des_loc
= c_parser_peek_token (parser
)->location
;
4215 if (c_parser_next_token_is (parser
, CPP_DOT
))
4218 c_parser_consume_token (parser
);
4219 if (c_parser_next_token_is (parser
, CPP_NAME
))
4221 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4222 braced_init_obstack
);
4223 c_parser_consume_token (parser
);
4228 init
.value
= error_mark_node
;
4229 init
.original_code
= ERROR_MARK
;
4230 init
.original_type
= NULL
;
4231 c_parser_error (parser
, "expected identifier");
4232 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4233 process_init_element (input_location
, init
, false,
4234 braced_init_obstack
);
4241 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4242 location_t array_index_loc
= UNKNOWN_LOCATION
;
4243 /* ??? Following the old parser, [ objc-receiver
4244 objc-message-args ] is accepted as an initializer,
4245 being distinguished from a designator by what follows
4246 the first assignment expression inside the square
4247 brackets, but after a first array designator a
4248 subsequent square bracket is for Objective-C taken to
4249 start an expression, using the obsolete form of
4250 designated initializer without '=', rather than
4251 possibly being a second level of designation: in LALR
4252 terms, the '[' is shifted rather than reducing
4253 designator to designator-list. */
4254 if (des_prev
== 1 && c_dialect_objc ())
4256 des_seen
= des_prev
;
4259 if (des_prev
== 0 && c_dialect_objc ())
4261 /* This might be an array designator or an
4262 Objective-C message expression. If the former,
4263 continue parsing here; if the latter, parse the
4264 remainder of the initializer given the starting
4265 primary-expression. ??? It might make sense to
4266 distinguish when des_prev == 1 as well; see
4267 previous comment. */
4269 struct c_expr mexpr
;
4270 c_parser_consume_token (parser
);
4271 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4272 && ((c_parser_peek_token (parser
)->id_kind
4274 || (c_parser_peek_token (parser
)->id_kind
4275 == C_ID_CLASSNAME
)))
4277 /* Type name receiver. */
4278 tree id
= c_parser_peek_token (parser
)->value
;
4279 c_parser_consume_token (parser
);
4280 rec
= objc_get_class_reference (id
);
4281 goto parse_message_args
;
4283 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4284 mark_exp_read (first
);
4285 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4286 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4287 goto array_desig_after_first
;
4288 /* Expression receiver. So far only one part
4289 without commas has been parsed; there might be
4290 more of the expression. */
4292 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4295 location_t comma_loc
, exp_loc
;
4296 comma_loc
= c_parser_peek_token (parser
)->location
;
4297 c_parser_consume_token (parser
);
4298 exp_loc
= c_parser_peek_token (parser
)->location
;
4299 next
= c_parser_expr_no_commas (parser
, NULL
);
4300 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4302 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4305 /* Now parse the objc-message-args. */
4306 args
= c_parser_objc_message_args (parser
);
4307 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4310 = objc_build_message_expr (rec
, args
);
4311 mexpr
.original_code
= ERROR_MARK
;
4312 mexpr
.original_type
= NULL
;
4313 /* Now parse and process the remainder of the
4314 initializer, starting with this message
4315 expression as a primary-expression. */
4316 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4319 c_parser_consume_token (parser
);
4320 array_index_loc
= c_parser_peek_token (parser
)->location
;
4321 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4322 mark_exp_read (first
);
4323 array_desig_after_first
:
4324 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4326 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4327 c_parser_consume_token (parser
);
4328 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4329 mark_exp_read (second
);
4333 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4335 c_parser_consume_token (parser
);
4336 set_init_index (array_index_loc
, first
, second
,
4337 braced_init_obstack
);
4339 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4340 "ISO C forbids specifying range of elements to initialize");
4343 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4349 if (c_parser_next_token_is (parser
, CPP_EQ
))
4352 pedwarn (des_loc
, OPT_Wpedantic
,
4353 "ISO C90 forbids specifying subobject to initialize");
4354 c_parser_consume_token (parser
);
4359 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4360 "obsolete use of designated initializer without %<=%>");
4364 init
.value
= error_mark_node
;
4365 init
.original_code
= ERROR_MARK
;
4366 init
.original_type
= NULL
;
4367 c_parser_error (parser
, "expected %<=%>");
4368 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4369 process_init_element (input_location
, init
, false,
4370 braced_init_obstack
);
4376 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4379 /* Parse a nested initializer; as c_parser_initializer but parses
4380 initializers within braced lists, after any designators have been
4381 applied. If AFTER is not NULL then it is an Objective-C message
4382 expression which is the primary-expression starting the
4386 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4387 struct obstack
* braced_init_obstack
)
4390 gcc_assert (!after
|| c_dialect_objc ());
4391 location_t loc
= c_parser_peek_token (parser
)->location
;
4393 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4394 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4397 init
= c_parser_expr_no_commas (parser
, after
);
4398 if (init
.value
!= NULL_TREE
4399 && TREE_CODE (init
.value
) != STRING_CST
4400 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4401 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4403 process_init_element (loc
, init
, false, braced_init_obstack
);
4406 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4410 { block-item-list[opt] }
4411 { label-declarations block-item-list }
4415 block-item-list block-item
4427 { label-declarations block-item-list }
4430 __extension__ nested-declaration
4431 nested-function-definition
4435 label-declarations label-declaration
4438 __label__ identifier-list ;
4440 Allowing the mixing of declarations and code is new in C99. The
4441 GNU syntax also permits (not shown above) labels at the end of
4442 compound statements, which yield an error. We don't allow labels
4443 on declarations; this might seem like a natural extension, but
4444 there would be a conflict between attributes on the label and
4445 prefix attributes on the declaration. ??? The syntax follows the
4446 old parser in requiring something after label declarations.
4447 Although they are erroneous if the labels declared aren't defined,
4448 is it useful for the syntax to be this way?
4461 cancellation-point-directive */
4464 c_parser_compound_statement (c_parser
*parser
)
4467 location_t brace_loc
;
4468 brace_loc
= c_parser_peek_token (parser
)->location
;
4469 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4471 /* Ensure a scope is entered and left anyway to avoid confusion
4472 if we have just prepared to enter a function body. */
4473 stmt
= c_begin_compound_stmt (true);
4474 c_end_compound_stmt (brace_loc
, stmt
, true);
4475 return error_mark_node
;
4477 stmt
= c_begin_compound_stmt (true);
4478 c_parser_compound_statement_nostart (parser
);
4480 /* If the compound stmt contains array notations, then we expand them. */
4481 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4482 stmt
= expand_array_notation_exprs (stmt
);
4483 return c_end_compound_stmt (brace_loc
, stmt
, true);
4486 /* Parse a compound statement except for the opening brace. This is
4487 used for parsing both compound statements and statement expressions
4488 (which follow different paths to handling the opening). */
4491 c_parser_compound_statement_nostart (c_parser
*parser
)
4493 bool last_stmt
= false;
4494 bool last_label
= false;
4495 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4496 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4497 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4499 c_parser_consume_token (parser
);
4502 mark_valid_location_for_stdc_pragma (true);
4503 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4505 /* Read zero or more forward-declarations for labels that nested
4506 functions can jump to. */
4507 mark_valid_location_for_stdc_pragma (false);
4508 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4510 label_loc
= c_parser_peek_token (parser
)->location
;
4511 c_parser_consume_token (parser
);
4512 /* Any identifiers, including those declared as type names,
4517 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4519 c_parser_error (parser
, "expected identifier");
4523 = declare_label (c_parser_peek_token (parser
)->value
);
4524 C_DECLARED_LABEL_FLAG (label
) = 1;
4525 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4526 c_parser_consume_token (parser
);
4527 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4528 c_parser_consume_token (parser
);
4532 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4534 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4536 /* We must now have at least one statement, label or declaration. */
4537 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4539 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4540 c_parser_error (parser
, "expected declaration or statement");
4541 c_parser_consume_token (parser
);
4544 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4546 location_t loc
= c_parser_peek_token (parser
)->location
;
4547 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4548 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4549 || (c_parser_next_token_is (parser
, CPP_NAME
)
4550 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4552 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4553 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4555 label_loc
= c_parser_peek_token (parser
)->location
;
4558 mark_valid_location_for_stdc_pragma (false);
4559 c_parser_label (parser
);
4561 else if (!last_label
4562 && c_parser_next_tokens_start_declaration (parser
))
4565 mark_valid_location_for_stdc_pragma (false);
4566 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4570 (pedantic
&& !flag_isoc99
)
4572 : OPT_Wdeclaration_after_statement
,
4573 "ISO C90 forbids mixed declarations and code");
4576 else if (!last_label
4577 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4579 /* __extension__ can start a declaration, but is also an
4580 unary operator that can start an expression. Consume all
4581 but the last of a possible series of __extension__ to
4583 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4584 && (c_parser_peek_2nd_token (parser
)->keyword
4586 c_parser_consume_token (parser
);
4587 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4590 ext
= disable_extension_diagnostics ();
4591 c_parser_consume_token (parser
);
4593 mark_valid_location_for_stdc_pragma (false);
4594 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4596 /* Following the old parser, __extension__ does not
4597 disable this diagnostic. */
4598 restore_extension_diagnostics (ext
);
4600 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4602 : OPT_Wdeclaration_after_statement
,
4603 "ISO C90 forbids mixed declarations and code");
4609 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4611 /* External pragmas, and some omp pragmas, are not associated
4612 with regular c code, and so are not to be considered statements
4613 syntactically. This ensures that the user doesn't put them
4614 places that would turn into syntax errors if the directive
4616 if (c_parser_pragma (parser
, pragma_compound
))
4617 last_label
= false, last_stmt
= true;
4619 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4621 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4622 c_parser_error (parser
, "expected declaration or statement");
4625 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4627 if (parser
->in_if_block
)
4629 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4630 error_at (loc
, """expected %<}%> before %<else%>");
4635 error_at (loc
, "%<else%> without a previous %<if%>");
4636 c_parser_consume_token (parser
);
4645 mark_valid_location_for_stdc_pragma (false);
4646 c_parser_statement_after_labels (parser
);
4649 parser
->error
= false;
4652 error_at (label_loc
, "label at end of compound statement");
4653 c_parser_consume_token (parser
);
4654 /* Restore the value we started with. */
4655 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4658 /* Parse a label (C90 6.6.1, C99 6.8.1).
4661 identifier : attributes[opt]
4662 case constant-expression :
4668 case constant-expression ... constant-expression :
4670 The use of attributes on labels is a GNU extension. The syntax in
4671 GNU C accepts any expressions without commas, non-constant
4672 expressions being rejected later. */
4675 c_parser_label (c_parser
*parser
)
4677 location_t loc1
= c_parser_peek_token (parser
)->location
;
4678 tree label
= NULL_TREE
;
4679 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4682 c_parser_consume_token (parser
);
4683 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4684 if (c_parser_next_token_is (parser
, CPP_COLON
))
4686 c_parser_consume_token (parser
);
4687 label
= do_case (loc1
, exp1
, NULL_TREE
);
4689 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4691 c_parser_consume_token (parser
);
4692 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4693 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4694 label
= do_case (loc1
, exp1
, exp2
);
4697 c_parser_error (parser
, "expected %<:%> or %<...%>");
4699 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4701 c_parser_consume_token (parser
);
4702 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4703 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4707 tree name
= c_parser_peek_token (parser
)->value
;
4710 location_t loc2
= c_parser_peek_token (parser
)->location
;
4711 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4712 c_parser_consume_token (parser
);
4713 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4714 c_parser_consume_token (parser
);
4715 attrs
= c_parser_attributes (parser
);
4716 tlab
= define_label (loc2
, name
);
4719 decl_attributes (&tlab
, attrs
, 0);
4720 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4725 if (c_parser_next_tokens_start_declaration (parser
))
4727 error_at (c_parser_peek_token (parser
)->location
,
4728 "a label can only be part of a statement and "
4729 "a declaration is not a statement");
4730 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4731 /*static_assert_ok*/ true,
4732 /*empty_ok*/ true, /*nested*/ true,
4733 /*start_attr_ok*/ true, NULL
,
4739 /* Parse a statement (C90 6.6, C99 6.8).
4744 expression-statement
4752 expression-statement:
4755 selection-statement:
4759 iteration-statement:
4768 return expression[opt] ;
4781 objc-throw-statement
4782 objc-try-catch-statement
4783 objc-synchronized-statement
4785 objc-throw-statement:
4801 parallel-for-construct
4802 parallel-for-simd-construct
4803 parallel-sections-construct
4810 parallel-directive structured-block
4813 for-directive iteration-statement
4816 simd-directive iteration-statements
4819 for-simd-directive iteration-statements
4822 sections-directive section-scope
4825 single-directive structured-block
4827 parallel-for-construct:
4828 parallel-for-directive iteration-statement
4830 parallel-for-simd-construct:
4831 parallel-for-simd-directive iteration-statement
4833 parallel-sections-construct:
4834 parallel-sections-directive section-scope
4837 master-directive structured-block
4840 critical-directive structured-block
4843 atomic-directive expression-statement
4846 ordered-directive structured-block
4848 Transactional Memory:
4851 transaction-statement
4852 transaction-cancel-statement
4856 c_parser_statement (c_parser
*parser
)
4858 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4859 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4860 || (c_parser_next_token_is (parser
, CPP_NAME
)
4861 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4862 c_parser_label (parser
);
4863 c_parser_statement_after_labels (parser
);
4866 /* Parse a statement, other than a labeled statement. */
4869 c_parser_statement_after_labels (c_parser
*parser
)
4871 location_t loc
= c_parser_peek_token (parser
)->location
;
4872 tree stmt
= NULL_TREE
;
4873 bool in_if_block
= parser
->in_if_block
;
4874 parser
->in_if_block
= false;
4875 switch (c_parser_peek_token (parser
)->type
)
4877 case CPP_OPEN_BRACE
:
4878 add_stmt (c_parser_compound_statement (parser
));
4881 switch (c_parser_peek_token (parser
)->keyword
)
4884 c_parser_if_statement (parser
);
4887 c_parser_switch_statement (parser
);
4890 c_parser_while_statement (parser
, false);
4893 c_parser_do_statement (parser
, false);
4896 c_parser_for_statement (parser
, false);
4899 c_parser_consume_token (parser
);
4900 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4902 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4904 add_stmt (build_cilk_sync ());
4907 c_parser_consume_token (parser
);
4908 if (c_parser_next_token_is (parser
, CPP_NAME
))
4910 stmt
= c_finish_goto_label (loc
,
4911 c_parser_peek_token (parser
)->value
);
4912 c_parser_consume_token (parser
);
4914 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4918 c_parser_consume_token (parser
);
4919 val
= c_parser_expression (parser
);
4920 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4921 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4924 c_parser_error (parser
, "expected identifier or %<*%>");
4925 goto expect_semicolon
;
4927 c_parser_consume_token (parser
);
4928 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4929 goto expect_semicolon
;
4931 c_parser_consume_token (parser
);
4932 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4933 goto expect_semicolon
;
4935 c_parser_consume_token (parser
);
4936 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4938 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4939 c_parser_consume_token (parser
);
4943 location_t xloc
= c_parser_peek_token (parser
)->location
;
4944 struct c_expr expr
= c_parser_expression_conv (parser
);
4945 mark_exp_read (expr
.value
);
4946 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
4947 goto expect_semicolon
;
4951 stmt
= c_parser_asm_statement (parser
);
4953 case RID_TRANSACTION_ATOMIC
:
4954 case RID_TRANSACTION_RELAXED
:
4955 stmt
= c_parser_transaction (parser
,
4956 c_parser_peek_token (parser
)->keyword
);
4958 case RID_TRANSACTION_CANCEL
:
4959 stmt
= c_parser_transaction_cancel (parser
);
4960 goto expect_semicolon
;
4962 gcc_assert (c_dialect_objc ());
4963 c_parser_consume_token (parser
);
4964 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4966 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4967 c_parser_consume_token (parser
);
4971 struct c_expr expr
= c_parser_expression (parser
);
4972 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
4973 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4974 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
4975 goto expect_semicolon
;
4979 gcc_assert (c_dialect_objc ());
4980 c_parser_objc_try_catch_finally_statement (parser
);
4982 case RID_AT_SYNCHRONIZED
:
4983 gcc_assert (c_dialect_objc ());
4984 c_parser_objc_synchronized_statement (parser
);
4991 c_parser_consume_token (parser
);
4993 case CPP_CLOSE_PAREN
:
4994 case CPP_CLOSE_SQUARE
:
4995 /* Avoid infinite loop in error recovery:
4996 c_parser_skip_until_found stops at a closing nesting
4997 delimiter without consuming it, but here we need to consume
4998 it to proceed further. */
4999 c_parser_error (parser
, "expected statement");
5000 c_parser_consume_token (parser
);
5003 c_parser_pragma (parser
, pragma_stmt
);
5007 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5009 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5012 /* Two cases cannot and do not have line numbers associated: If stmt
5013 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5014 cannot hold line numbers. But that's OK because the statement
5015 will either be changed to a MODIFY_EXPR during gimplification of
5016 the statement expr, or discarded. If stmt was compound, but
5017 without new variables, we will have skipped the creation of a
5018 BIND and will have a bare STATEMENT_LIST. But that's OK because
5019 (recursively) all of the component statements should already have
5020 line numbers assigned. ??? Can we discard no-op statements
5022 if (CAN_HAVE_LOCATION_P (stmt
)
5023 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5024 SET_EXPR_LOCATION (stmt
, loc
);
5026 parser
->in_if_block
= in_if_block
;
5029 /* Parse the condition from an if, do, while or for statements. */
5032 c_parser_condition (c_parser
*parser
)
5034 location_t loc
= c_parser_peek_token (parser
)->location
;
5036 cond
= c_parser_expression_conv (parser
).value
;
5037 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5038 cond
= c_fully_fold (cond
, false, NULL
);
5039 if (warn_sequence_point
)
5040 verify_sequence_points (cond
);
5044 /* Parse a parenthesized condition from an if, do or while statement.
5050 c_parser_paren_condition (c_parser
*parser
)
5053 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5054 return error_mark_node
;
5055 cond
= c_parser_condition (parser
);
5056 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5060 /* Parse a statement which is a block in C99. */
5063 c_parser_c99_block_statement (c_parser
*parser
)
5065 tree block
= c_begin_compound_stmt (flag_isoc99
);
5066 location_t loc
= c_parser_peek_token (parser
)->location
;
5067 c_parser_statement (parser
);
5068 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5071 /* Parse the body of an if statement. This is just parsing a
5072 statement but (a) it is a block in C99, (b) we track whether the
5073 body is an if statement for the sake of -Wparentheses warnings, (c)
5074 we handle an empty body specially for the sake of -Wempty-body
5075 warnings, and (d) we call parser_compound_statement directly
5076 because c_parser_statement_after_labels resets
5077 parser->in_if_block. */
5080 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5082 tree block
= c_begin_compound_stmt (flag_isoc99
);
5083 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5084 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5085 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5086 || (c_parser_next_token_is (parser
, CPP_NAME
)
5087 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5088 c_parser_label (parser
);
5089 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5090 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5092 location_t loc
= c_parser_peek_token (parser
)->location
;
5093 add_stmt (build_empty_stmt (loc
));
5094 c_parser_consume_token (parser
);
5095 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5096 warning_at (loc
, OPT_Wempty_body
,
5097 "suggest braces around empty body in an %<if%> statement");
5099 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5100 add_stmt (c_parser_compound_statement (parser
));
5102 c_parser_statement_after_labels (parser
);
5103 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5106 /* Parse the else body of an if statement. This is just parsing a
5107 statement but (a) it is a block in C99, (b) we handle an empty body
5108 specially for the sake of -Wempty-body warnings. */
5111 c_parser_else_body (c_parser
*parser
)
5113 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5114 tree block
= c_begin_compound_stmt (flag_isoc99
);
5115 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5116 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5117 || (c_parser_next_token_is (parser
, CPP_NAME
)
5118 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5119 c_parser_label (parser
);
5120 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5122 location_t loc
= c_parser_peek_token (parser
)->location
;
5125 "suggest braces around empty body in an %<else%> statement");
5126 add_stmt (build_empty_stmt (loc
));
5127 c_parser_consume_token (parser
);
5130 c_parser_statement_after_labels (parser
);
5131 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5134 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5137 if ( expression ) statement
5138 if ( expression ) statement else statement
5142 c_parser_if_statement (c_parser
*parser
)
5147 bool first_if
= false;
5148 tree first_body
, second_body
;
5152 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5153 c_parser_consume_token (parser
);
5154 block
= c_begin_compound_stmt (flag_isoc99
);
5155 loc
= c_parser_peek_token (parser
)->location
;
5156 cond
= c_parser_paren_condition (parser
);
5157 in_if_block
= parser
->in_if_block
;
5158 parser
->in_if_block
= true;
5159 first_body
= c_parser_if_body (parser
, &first_if
);
5160 parser
->in_if_block
= in_if_block
;
5161 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5163 c_parser_consume_token (parser
);
5164 second_body
= c_parser_else_body (parser
);
5167 second_body
= NULL_TREE
;
5168 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5169 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5171 /* If the if statement contains array notations, then we expand them. */
5172 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5173 if_stmt
= fix_conditional_array_notations (if_stmt
);
5177 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5180 switch (expression) statement
5184 c_parser_switch_statement (c_parser
*parser
)
5187 tree block
, expr
, body
, save_break
;
5188 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5189 location_t switch_cond_loc
;
5190 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5191 c_parser_consume_token (parser
);
5192 block
= c_begin_compound_stmt (flag_isoc99
);
5193 bool explicit_cast_p
= false;
5194 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5196 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5197 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5198 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5199 explicit_cast_p
= true;
5200 ce
= c_parser_expression (parser
);
5201 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5203 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5205 error_at (switch_cond_loc
,
5206 "array notations cannot be used as a condition for switch "
5208 expr
= error_mark_node
;
5210 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5214 switch_cond_loc
= UNKNOWN_LOCATION
;
5215 expr
= error_mark_node
;
5217 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5218 save_break
= c_break_label
;
5219 c_break_label
= NULL_TREE
;
5220 body
= c_parser_c99_block_statement (parser
);
5221 c_finish_case (body
);
5224 location_t here
= c_parser_peek_token (parser
)->location
;
5225 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5226 SET_EXPR_LOCATION (t
, here
);
5229 c_break_label
= save_break
;
5230 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5233 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5236 while (expression) statement
5240 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5242 tree block
, cond
, body
, save_break
, save_cont
;
5244 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5245 c_parser_consume_token (parser
);
5246 block
= c_begin_compound_stmt (flag_isoc99
);
5247 loc
= c_parser_peek_token (parser
)->location
;
5248 cond
= c_parser_paren_condition (parser
);
5249 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5251 error_at (loc
, "array notations cannot be used as a condition for while "
5253 cond
= error_mark_node
;
5256 if (ivdep
&& cond
!= error_mark_node
)
5257 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5258 build_int_cst (integer_type_node
,
5259 annot_expr_ivdep_kind
));
5260 save_break
= c_break_label
;
5261 c_break_label
= NULL_TREE
;
5262 save_cont
= c_cont_label
;
5263 c_cont_label
= NULL_TREE
;
5264 body
= c_parser_c99_block_statement (parser
);
5265 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5266 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5267 c_break_label
= save_break
;
5268 c_cont_label
= save_cont
;
5271 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5274 do statement while ( expression ) ;
5278 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5280 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5282 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5283 c_parser_consume_token (parser
);
5284 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5285 warning_at (c_parser_peek_token (parser
)->location
,
5287 "suggest braces around empty body in %<do%> statement");
5288 block
= c_begin_compound_stmt (flag_isoc99
);
5289 loc
= c_parser_peek_token (parser
)->location
;
5290 save_break
= c_break_label
;
5291 c_break_label
= NULL_TREE
;
5292 save_cont
= c_cont_label
;
5293 c_cont_label
= NULL_TREE
;
5294 body
= c_parser_c99_block_statement (parser
);
5295 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5296 new_break
= c_break_label
;
5297 c_break_label
= save_break
;
5298 new_cont
= c_cont_label
;
5299 c_cont_label
= save_cont
;
5300 cond
= c_parser_paren_condition (parser
);
5301 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5303 error_at (loc
, "array notations cannot be used as a condition for a "
5304 "do-while statement");
5305 cond
= error_mark_node
;
5307 if (ivdep
&& cond
!= error_mark_node
)
5308 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5309 build_int_cst (integer_type_node
,
5310 annot_expr_ivdep_kind
));
5311 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5312 c_parser_skip_to_end_of_block_or_statement (parser
);
5313 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5314 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5317 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5320 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5321 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5323 The form with a declaration is new in C99.
5325 ??? In accordance with the old parser, the declaration may be a
5326 nested function, which is then rejected in check_for_loop_decls,
5327 but does it make any sense for this to be included in the grammar?
5328 Note in particular that the nested function does not include a
5329 trailing ';', whereas the "declaration" production includes one.
5330 Also, can we reject bad declarations earlier and cheaper than
5331 check_for_loop_decls?
5333 In Objective-C, there are two additional variants:
5336 for ( expression in expresssion ) statement
5337 for ( declaration in expression ) statement
5339 This is inconsistent with C, because the second variant is allowed
5340 even if c99 is not enabled.
5342 The rest of the comment documents these Objective-C foreach-statement.
5344 Here is the canonical example of the first variant:
5345 for (object in array) { do something with object }
5346 we call the first expression ("object") the "object_expression" and
5347 the second expression ("array") the "collection_expression".
5348 object_expression must be an lvalue of type "id" (a generic Objective-C
5349 object) because the loop works by assigning to object_expression the
5350 various objects from the collection_expression. collection_expression
5351 must evaluate to something of type "id" which responds to the method
5352 countByEnumeratingWithState:objects:count:.
5354 The canonical example of the second variant is:
5355 for (id object in array) { do something with object }
5356 which is completely equivalent to
5359 for (object in array) { do something with object }
5361 Note that initizializing 'object' in some way (eg, "for ((object =
5362 xxx) in array) { do something with object }") is possibly
5363 technically valid, but completely pointless as 'object' will be
5364 assigned to something else as soon as the loop starts. We should
5365 most likely reject it (TODO).
5367 The beginning of the Objective-C foreach-statement looks exactly
5368 like the beginning of the for-statement, and we can tell it is a
5369 foreach-statement only because the initial declaration or
5370 expression is terminated by 'in' instead of ';'.
5374 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5376 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5377 /* The following are only used when parsing an ObjC foreach statement. */
5378 tree object_expression
;
5379 /* Silence the bogus uninitialized warning. */
5380 tree collection_expression
= NULL
;
5381 location_t loc
= c_parser_peek_token (parser
)->location
;
5382 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5383 bool is_foreach_statement
= false;
5384 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5385 c_parser_consume_token (parser
);
5386 /* Open a compound statement in Objective-C as well, just in case this is
5387 as foreach expression. */
5388 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5389 cond
= error_mark_node
;
5390 incr
= error_mark_node
;
5391 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5393 /* Parse the initialization declaration or expression. */
5394 object_expression
= error_mark_node
;
5395 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5396 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5398 parser
->objc_could_be_foreach_context
= false;
5399 c_parser_consume_token (parser
);
5400 c_finish_expr_stmt (loc
, NULL_TREE
);
5402 else if (c_parser_next_tokens_start_declaration (parser
))
5404 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5405 &object_expression
, vNULL
);
5406 parser
->objc_could_be_foreach_context
= false;
5408 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5410 c_parser_consume_token (parser
);
5411 is_foreach_statement
= true;
5412 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5413 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5416 check_for_loop_decls (for_loc
, flag_isoc99
);
5418 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5420 /* __extension__ can start a declaration, but is also an
5421 unary operator that can start an expression. Consume all
5422 but the last of a possible series of __extension__ to
5424 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5425 && (c_parser_peek_2nd_token (parser
)->keyword
5427 c_parser_consume_token (parser
);
5428 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5431 ext
= disable_extension_diagnostics ();
5432 c_parser_consume_token (parser
);
5433 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5434 true, &object_expression
, vNULL
);
5435 parser
->objc_could_be_foreach_context
= false;
5437 restore_extension_diagnostics (ext
);
5438 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5440 c_parser_consume_token (parser
);
5441 is_foreach_statement
= true;
5442 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5443 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5446 check_for_loop_decls (for_loc
, flag_isoc99
);
5456 tree init_expression
;
5457 ce
= c_parser_expression (parser
);
5458 init_expression
= ce
.value
;
5459 parser
->objc_could_be_foreach_context
= false;
5460 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5462 c_parser_consume_token (parser
);
5463 is_foreach_statement
= true;
5464 if (! lvalue_p (init_expression
))
5465 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5466 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5470 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5471 init_expression
= ce
.value
;
5472 c_finish_expr_stmt (loc
, init_expression
);
5473 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5477 /* Parse the loop condition. In the case of a foreach
5478 statement, there is no loop condition. */
5479 gcc_assert (!parser
->objc_could_be_foreach_context
);
5480 if (!is_foreach_statement
)
5482 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5486 c_parser_error (parser
, "missing loop condition in loop with "
5487 "%<GCC ivdep%> pragma");
5488 cond
= error_mark_node
;
5492 c_parser_consume_token (parser
);
5498 cond
= c_parser_condition (parser
);
5499 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5501 error_at (loc
, "array notations cannot be used in a "
5502 "condition for a for-loop");
5503 cond
= error_mark_node
;
5505 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5508 if (ivdep
&& cond
!= error_mark_node
)
5509 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5510 build_int_cst (integer_type_node
,
5511 annot_expr_ivdep_kind
));
5513 /* Parse the increment expression (the third expression in a
5514 for-statement). In the case of a foreach-statement, this is
5515 the expression that follows the 'in'. */
5516 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5518 if (is_foreach_statement
)
5520 c_parser_error (parser
, "missing collection in fast enumeration");
5521 collection_expression
= error_mark_node
;
5524 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5528 if (is_foreach_statement
)
5529 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5533 struct c_expr ce
= c_parser_expression (parser
);
5534 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5535 incr
= c_process_expr_stmt (loc
, ce
.value
);
5538 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5540 save_break
= c_break_label
;
5541 c_break_label
= NULL_TREE
;
5542 save_cont
= c_cont_label
;
5543 c_cont_label
= NULL_TREE
;
5544 body
= c_parser_c99_block_statement (parser
);
5545 if (is_foreach_statement
)
5546 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5548 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5549 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5550 c_break_label
= save_break
;
5551 c_cont_label
= save_cont
;
5554 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5555 statement with inputs, outputs, clobbers, and volatile tag
5559 asm type-qualifier[opt] ( asm-argument ) ;
5560 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5564 asm-string-literal : asm-operands[opt]
5565 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5566 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5569 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5572 Qualifiers other than volatile are accepted in the syntax but
5576 c_parser_asm_statement (c_parser
*parser
)
5578 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5579 bool simple
, is_goto
;
5580 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5581 int section
, nsections
;
5583 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5584 c_parser_consume_token (parser
);
5585 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5587 quals
= c_parser_peek_token (parser
)->value
;
5588 c_parser_consume_token (parser
);
5590 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5591 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5593 warning_at (c_parser_peek_token (parser
)->location
,
5595 "%E qualifier ignored on asm",
5596 c_parser_peek_token (parser
)->value
);
5598 c_parser_consume_token (parser
);
5604 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5606 c_parser_consume_token (parser
);
5610 /* ??? Follow the C++ parser rather than using the
5611 lex_untranslated_string kludge. */
5612 parser
->lex_untranslated_string
= true;
5615 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5618 str
= c_parser_asm_string_literal (parser
);
5619 if (str
== NULL_TREE
)
5620 goto error_close_paren
;
5623 outputs
= NULL_TREE
;
5625 clobbers
= NULL_TREE
;
5628 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5631 /* Parse each colon-delimited section of operands. */
5632 nsections
= 3 + is_goto
;
5633 for (section
= 0; section
< nsections
; ++section
)
5635 if (!c_parser_require (parser
, CPP_COLON
,
5638 : "expected %<:%> or %<)%>"))
5639 goto error_close_paren
;
5641 /* Once past any colon, we're no longer a simple asm. */
5644 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5645 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5650 /* For asm goto, we don't allow output operands, but reserve
5651 the slot for a future extension that does allow them. */
5653 outputs
= c_parser_asm_operands (parser
);
5656 inputs
= c_parser_asm_operands (parser
);
5659 clobbers
= c_parser_asm_clobbers (parser
);
5662 labels
= c_parser_asm_goto_operands (parser
);
5668 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5673 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5675 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5679 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5680 c_parser_skip_to_end_of_block_or_statement (parser
);
5682 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5683 clobbers
, labels
, simple
));
5686 parser
->lex_untranslated_string
= false;
5690 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5694 /* Parse asm operands, a GNU extension.
5698 asm-operands , asm-operand
5701 asm-string-literal ( expression )
5702 [ identifier ] asm-string-literal ( expression )
5706 c_parser_asm_operands (c_parser
*parser
)
5708 tree list
= NULL_TREE
;
5713 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5715 c_parser_consume_token (parser
);
5716 if (c_parser_next_token_is (parser
, CPP_NAME
))
5718 tree id
= c_parser_peek_token (parser
)->value
;
5719 c_parser_consume_token (parser
);
5720 name
= build_string (IDENTIFIER_LENGTH (id
),
5721 IDENTIFIER_POINTER (id
));
5725 c_parser_error (parser
, "expected identifier");
5726 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5729 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5734 str
= c_parser_asm_string_literal (parser
);
5735 if (str
== NULL_TREE
)
5737 parser
->lex_untranslated_string
= false;
5738 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5740 parser
->lex_untranslated_string
= true;
5743 expr
= c_parser_expression (parser
);
5744 mark_exp_read (expr
.value
);
5745 parser
->lex_untranslated_string
= true;
5746 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5748 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5751 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5753 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5754 c_parser_consume_token (parser
);
5761 /* Parse asm clobbers, a GNU extension.
5765 asm-clobbers , asm-string-literal
5769 c_parser_asm_clobbers (c_parser
*parser
)
5771 tree list
= NULL_TREE
;
5774 tree str
= c_parser_asm_string_literal (parser
);
5776 list
= tree_cons (NULL_TREE
, str
, list
);
5779 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5780 c_parser_consume_token (parser
);
5787 /* Parse asm goto labels, a GNU extension.
5791 asm-goto-operands , identifier
5795 c_parser_asm_goto_operands (c_parser
*parser
)
5797 tree list
= NULL_TREE
;
5802 if (c_parser_next_token_is (parser
, CPP_NAME
))
5804 c_token
*tok
= c_parser_peek_token (parser
);
5806 label
= lookup_label_for_goto (tok
->location
, name
);
5807 c_parser_consume_token (parser
);
5808 TREE_USED (label
) = 1;
5812 c_parser_error (parser
, "expected identifier");
5816 name
= build_string (IDENTIFIER_LENGTH (name
),
5817 IDENTIFIER_POINTER (name
));
5818 list
= tree_cons (name
, label
, list
);
5819 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5820 c_parser_consume_token (parser
);
5822 return nreverse (list
);
5826 /* Parse an expression other than a compound expression; that is, an
5827 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5828 NULL then it is an Objective-C message expression which is the
5829 primary-expression starting the expression as an initializer.
5831 assignment-expression:
5832 conditional-expression
5833 unary-expression assignment-operator assignment-expression
5835 assignment-operator: one of
5836 = *= /= %= += -= <<= >>= &= ^= |=
5838 In GNU C we accept any conditional expression on the LHS and
5839 diagnose the invalid lvalue rather than producing a syntax
5842 static struct c_expr
5843 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5844 tree omp_atomic_lhs
)
5846 struct c_expr lhs
, rhs
, ret
;
5847 enum tree_code code
;
5848 location_t op_location
, exp_location
;
5849 gcc_assert (!after
|| c_dialect_objc ());
5850 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5851 op_location
= c_parser_peek_token (parser
)->location
;
5852 switch (c_parser_peek_token (parser
)->type
)
5861 code
= TRUNC_DIV_EXPR
;
5864 code
= TRUNC_MOD_EXPR
;
5879 code
= BIT_AND_EXPR
;
5882 code
= BIT_XOR_EXPR
;
5885 code
= BIT_IOR_EXPR
;
5890 c_parser_consume_token (parser
);
5891 exp_location
= c_parser_peek_token (parser
)->location
;
5892 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5893 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5895 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5896 code
, exp_location
, rhs
.value
,
5898 if (code
== NOP_EXPR
)
5899 ret
.original_code
= MODIFY_EXPR
;
5902 TREE_NO_WARNING (ret
.value
) = 1;
5903 ret
.original_code
= ERROR_MARK
;
5905 ret
.original_type
= NULL
;
5909 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5910 is not NULL then it is an Objective-C message expression which is
5911 the primary-expression starting the expression as an initializer.
5913 conditional-expression:
5914 logical-OR-expression
5915 logical-OR-expression ? expression : conditional-expression
5919 conditional-expression:
5920 logical-OR-expression ? : conditional-expression
5923 static struct c_expr
5924 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5925 tree omp_atomic_lhs
)
5927 struct c_expr cond
, exp1
, exp2
, ret
;
5928 location_t cond_loc
, colon_loc
, middle_loc
;
5930 gcc_assert (!after
|| c_dialect_objc ());
5932 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5934 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5936 cond_loc
= c_parser_peek_token (parser
)->location
;
5937 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5938 c_parser_consume_token (parser
);
5939 if (c_parser_next_token_is (parser
, CPP_COLON
))
5941 tree eptype
= NULL_TREE
;
5943 middle_loc
= c_parser_peek_token (parser
)->location
;
5944 pedwarn (middle_loc
, OPT_Wpedantic
,
5945 "ISO C forbids omitting the middle term of a ?: expression");
5946 warn_for_omitted_condop (middle_loc
, cond
.value
);
5947 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5949 eptype
= TREE_TYPE (cond
.value
);
5950 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5952 /* Make sure first operand is calculated only once. */
5953 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5955 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5956 exp1
.original_type
= NULL
;
5957 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5958 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5963 = c_objc_common_truthvalue_conversion
5964 (cond_loc
, default_conversion (cond
.value
));
5965 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5966 exp1
= c_parser_expression_conv (parser
);
5967 mark_exp_read (exp1
.value
);
5968 c_inhibit_evaluation_warnings
+=
5969 ((cond
.value
== truthvalue_true_node
)
5970 - (cond
.value
== truthvalue_false_node
));
5973 colon_loc
= c_parser_peek_token (parser
)->location
;
5974 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5976 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5977 ret
.value
= error_mark_node
;
5978 ret
.original_code
= ERROR_MARK
;
5979 ret
.original_type
= NULL
;
5983 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5984 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5985 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
5987 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5988 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5989 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5990 exp1
.value
, exp1
.original_type
,
5991 exp2
.value
, exp2
.original_type
);
5992 ret
.original_code
= ERROR_MARK
;
5993 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5994 ret
.original_type
= NULL
;
5999 /* If both sides are enum type, the default conversion will have
6000 made the type of the result be an integer type. We want to
6001 remember the enum types we started with. */
6002 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6003 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6004 ret
.original_type
= ((t1
!= error_mark_node
6005 && t2
!= error_mark_node
6006 && (TYPE_MAIN_VARIANT (t1
)
6007 == TYPE_MAIN_VARIANT (t2
)))
6014 /* Parse a binary expression; that is, a logical-OR-expression (C90
6015 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6016 an Objective-C message expression which is the primary-expression
6017 starting the expression as an initializer.
6019 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6020 when it should be the unfolded lhs. In a valid OpenMP source,
6021 one of the operands of the toplevel binary expression must be equal
6022 to it. In that case, just return a build2 created binary operation
6023 rather than result of parser_build_binary_op.
6025 multiplicative-expression:
6027 multiplicative-expression * cast-expression
6028 multiplicative-expression / cast-expression
6029 multiplicative-expression % cast-expression
6031 additive-expression:
6032 multiplicative-expression
6033 additive-expression + multiplicative-expression
6034 additive-expression - multiplicative-expression
6038 shift-expression << additive-expression
6039 shift-expression >> additive-expression
6041 relational-expression:
6043 relational-expression < shift-expression
6044 relational-expression > shift-expression
6045 relational-expression <= shift-expression
6046 relational-expression >= shift-expression
6048 equality-expression:
6049 relational-expression
6050 equality-expression == relational-expression
6051 equality-expression != relational-expression
6055 AND-expression & equality-expression
6057 exclusive-OR-expression:
6059 exclusive-OR-expression ^ AND-expression
6061 inclusive-OR-expression:
6062 exclusive-OR-expression
6063 inclusive-OR-expression | exclusive-OR-expression
6065 logical-AND-expression:
6066 inclusive-OR-expression
6067 logical-AND-expression && inclusive-OR-expression
6069 logical-OR-expression:
6070 logical-AND-expression
6071 logical-OR-expression || logical-AND-expression
6074 static struct c_expr
6075 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6076 tree omp_atomic_lhs
)
6078 /* A binary expression is parsed using operator-precedence parsing,
6079 with the operands being cast expressions. All the binary
6080 operators are left-associative. Thus a binary expression is of
6083 E0 op1 E1 op2 E2 ...
6085 which we represent on a stack. On the stack, the precedence
6086 levels are strictly increasing. When a new operator is
6087 encountered of higher precedence than that at the top of the
6088 stack, it is pushed; its LHS is the top expression, and its RHS
6089 is everything parsed until it is popped. When a new operator is
6090 encountered with precedence less than or equal to that at the top
6091 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6092 by the result of the operation until the operator at the top of
6093 the stack has lower precedence than the new operator or there is
6094 only one element on the stack; then the top expression is the LHS
6095 of the new operator. In the case of logical AND and OR
6096 expressions, we also need to adjust c_inhibit_evaluation_warnings
6097 as appropriate when the operators are pushed and popped. */
6100 /* The expression at this stack level. */
6102 /* The precedence of the operator on its left, PREC_NONE at the
6103 bottom of the stack. */
6104 enum c_parser_prec prec
;
6105 /* The operation on its left. */
6107 /* The source location of this operation. */
6111 /* Location of the binary operator. */
6112 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6115 switch (stack[sp].op) \
6117 case TRUTH_ANDIF_EXPR: \
6118 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6119 == truthvalue_false_node); \
6121 case TRUTH_ORIF_EXPR: \
6122 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6123 == truthvalue_true_node); \
6128 stack[sp - 1].expr \
6129 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6130 stack[sp - 1].expr, true, true); \
6132 = convert_lvalue_to_rvalue (stack[sp].loc, \
6133 stack[sp].expr, true, true); \
6134 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6135 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6136 && ((1 << stack[sp].prec) \
6137 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6138 | PREC_ADD | PREC_MULT))) \
6139 && stack[sp].op != TRUNC_MOD_EXPR \
6140 && stack[0].expr.value != error_mark_node \
6141 && stack[1].expr.value != error_mark_node \
6142 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6143 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6144 stack[0].expr.value \
6145 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6146 stack[0].expr.value, stack[1].expr.value); \
6148 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6150 stack[sp - 1].expr, \
6154 gcc_assert (!after
|| c_dialect_objc ());
6155 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6156 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6157 stack
[0].prec
= PREC_NONE
;
6161 enum c_parser_prec oprec
;
6162 enum tree_code ocode
;
6165 switch (c_parser_peek_token (parser
)->type
)
6173 ocode
= TRUNC_DIV_EXPR
;
6177 ocode
= TRUNC_MOD_EXPR
;
6189 ocode
= LSHIFT_EXPR
;
6193 ocode
= RSHIFT_EXPR
;
6207 case CPP_GREATER_EQ
:
6220 oprec
= PREC_BITAND
;
6221 ocode
= BIT_AND_EXPR
;
6224 oprec
= PREC_BITXOR
;
6225 ocode
= BIT_XOR_EXPR
;
6229 ocode
= BIT_IOR_EXPR
;
6232 oprec
= PREC_LOGAND
;
6233 ocode
= TRUTH_ANDIF_EXPR
;
6237 ocode
= TRUTH_ORIF_EXPR
;
6240 /* Not a binary operator, so end of the binary
6244 binary_loc
= c_parser_peek_token (parser
)->location
;
6245 while (oprec
<= stack
[sp
].prec
)
6247 c_parser_consume_token (parser
);
6250 case TRUTH_ANDIF_EXPR
:
6252 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6253 stack
[sp
].expr
, true, true);
6254 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6255 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6256 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6257 == truthvalue_false_node
);
6259 case TRUTH_ORIF_EXPR
:
6261 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6262 stack
[sp
].expr
, true, true);
6263 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6264 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6265 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6266 == truthvalue_true_node
);
6272 stack
[sp
].loc
= binary_loc
;
6273 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6274 stack
[sp
].prec
= oprec
;
6275 stack
[sp
].op
= ocode
;
6276 stack
[sp
].loc
= binary_loc
;
6281 return stack
[0].expr
;
6285 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6286 NULL then it is an Objective-C message expression which is the
6287 primary-expression starting the expression as an initializer.
6291 ( type-name ) unary-expression
6294 static struct c_expr
6295 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6297 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6298 gcc_assert (!after
|| c_dialect_objc ());
6300 return c_parser_postfix_expression_after_primary (parser
,
6302 /* If the expression begins with a parenthesized type name, it may
6303 be either a cast or a compound literal; we need to see whether
6304 the next character is '{' to tell the difference. If not, it is
6305 an unary expression. Full detection of unknown typenames here
6306 would require a 3-token lookahead. */
6307 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6308 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6310 struct c_type_name
*type_name
;
6313 c_parser_consume_token (parser
);
6314 type_name
= c_parser_type_name (parser
);
6315 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6316 if (type_name
== NULL
)
6318 ret
.value
= error_mark_node
;
6319 ret
.original_code
= ERROR_MARK
;
6320 ret
.original_type
= NULL
;
6324 /* Save casted types in the function's used types hash table. */
6325 used_types_insert (type_name
->specs
->type
);
6327 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6328 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6331 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6332 expr
= c_parser_cast_expression (parser
, NULL
);
6333 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6335 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6336 ret
.original_code
= ERROR_MARK
;
6337 ret
.original_type
= NULL
;
6341 return c_parser_unary_expression (parser
);
6344 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6350 unary-operator cast-expression
6351 sizeof unary-expression
6352 sizeof ( type-name )
6354 unary-operator: one of
6360 __alignof__ unary-expression
6361 __alignof__ ( type-name )
6364 (C11 permits _Alignof with type names only.)
6366 unary-operator: one of
6367 __extension__ __real__ __imag__
6369 Transactional Memory:
6372 transaction-expression
6374 In addition, the GNU syntax treats ++ and -- as unary operators, so
6375 they may be applied to cast expressions with errors for non-lvalues
6378 static struct c_expr
6379 c_parser_unary_expression (c_parser
*parser
)
6382 struct c_expr ret
, op
;
6383 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6385 ret
.original_code
= ERROR_MARK
;
6386 ret
.original_type
= NULL
;
6387 switch (c_parser_peek_token (parser
)->type
)
6390 c_parser_consume_token (parser
);
6391 exp_loc
= c_parser_peek_token (parser
)->location
;
6392 op
= c_parser_cast_expression (parser
, NULL
);
6394 /* If there is array notations in op, we expand them. */
6395 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6396 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6399 op
= default_function_array_read_conversion (exp_loc
, op
);
6400 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6402 case CPP_MINUS_MINUS
:
6403 c_parser_consume_token (parser
);
6404 exp_loc
= c_parser_peek_token (parser
)->location
;
6405 op
= c_parser_cast_expression (parser
, NULL
);
6407 /* If there is array notations in op, we expand them. */
6408 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6409 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6412 op
= default_function_array_read_conversion (exp_loc
, op
);
6413 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6416 c_parser_consume_token (parser
);
6417 op
= c_parser_cast_expression (parser
, NULL
);
6418 mark_exp_read (op
.value
);
6419 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6421 c_parser_consume_token (parser
);
6422 exp_loc
= c_parser_peek_token (parser
)->location
;
6423 op
= c_parser_cast_expression (parser
, NULL
);
6424 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6425 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6428 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6431 "traditional C rejects the unary plus operator");
6432 c_parser_consume_token (parser
);
6433 exp_loc
= c_parser_peek_token (parser
)->location
;
6434 op
= c_parser_cast_expression (parser
, NULL
);
6435 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6436 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6438 c_parser_consume_token (parser
);
6439 exp_loc
= c_parser_peek_token (parser
)->location
;
6440 op
= c_parser_cast_expression (parser
, NULL
);
6441 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6442 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6444 c_parser_consume_token (parser
);
6445 exp_loc
= c_parser_peek_token (parser
)->location
;
6446 op
= c_parser_cast_expression (parser
, NULL
);
6447 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6448 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6450 c_parser_consume_token (parser
);
6451 exp_loc
= c_parser_peek_token (parser
)->location
;
6452 op
= c_parser_cast_expression (parser
, NULL
);
6453 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6454 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6456 /* Refer to the address of a label as a pointer. */
6457 c_parser_consume_token (parser
);
6458 if (c_parser_next_token_is (parser
, CPP_NAME
))
6460 ret
.value
= finish_label_address_expr
6461 (c_parser_peek_token (parser
)->value
, op_loc
);
6462 c_parser_consume_token (parser
);
6466 c_parser_error (parser
, "expected identifier");
6467 ret
.value
= error_mark_node
;
6471 switch (c_parser_peek_token (parser
)->keyword
)
6474 return c_parser_sizeof_expression (parser
);
6476 return c_parser_alignof_expression (parser
);
6478 c_parser_consume_token (parser
);
6479 ext
= disable_extension_diagnostics ();
6480 ret
= c_parser_cast_expression (parser
, NULL
);
6481 restore_extension_diagnostics (ext
);
6484 c_parser_consume_token (parser
);
6485 exp_loc
= c_parser_peek_token (parser
)->location
;
6486 op
= c_parser_cast_expression (parser
, NULL
);
6487 op
= default_function_array_conversion (exp_loc
, op
);
6488 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6490 c_parser_consume_token (parser
);
6491 exp_loc
= c_parser_peek_token (parser
)->location
;
6492 op
= c_parser_cast_expression (parser
, NULL
);
6493 op
= default_function_array_conversion (exp_loc
, op
);
6494 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6495 case RID_TRANSACTION_ATOMIC
:
6496 case RID_TRANSACTION_RELAXED
:
6497 return c_parser_transaction_expression (parser
,
6498 c_parser_peek_token (parser
)->keyword
);
6500 return c_parser_postfix_expression (parser
);
6503 return c_parser_postfix_expression (parser
);
6507 /* Parse a sizeof expression. */
6509 static struct c_expr
6510 c_parser_sizeof_expression (c_parser
*parser
)
6513 location_t expr_loc
;
6514 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6515 c_parser_consume_token (parser
);
6516 c_inhibit_evaluation_warnings
++;
6518 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6519 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6521 /* Either sizeof ( type-name ) or sizeof unary-expression
6522 starting with a compound literal. */
6523 struct c_type_name
*type_name
;
6524 c_parser_consume_token (parser
);
6525 expr_loc
= c_parser_peek_token (parser
)->location
;
6526 type_name
= c_parser_type_name (parser
);
6527 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6528 if (type_name
== NULL
)
6531 c_inhibit_evaluation_warnings
--;
6533 ret
.value
= error_mark_node
;
6534 ret
.original_code
= ERROR_MARK
;
6535 ret
.original_type
= NULL
;
6538 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6540 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6545 /* sizeof ( type-name ). */
6546 c_inhibit_evaluation_warnings
--;
6548 return c_expr_sizeof_type (expr_loc
, type_name
);
6552 expr_loc
= c_parser_peek_token (parser
)->location
;
6553 expr
= c_parser_unary_expression (parser
);
6555 c_inhibit_evaluation_warnings
--;
6557 mark_exp_read (expr
.value
);
6558 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6559 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6560 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6561 return c_expr_sizeof_expr (expr_loc
, expr
);
6565 /* Parse an alignof expression. */
6567 static struct c_expr
6568 c_parser_alignof_expression (c_parser
*parser
)
6571 location_t loc
= c_parser_peek_token (parser
)->location
;
6572 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6573 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6574 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6576 /* A diagnostic is not required for the use of this identifier in
6577 the implementation namespace; only diagnose it for the C11
6578 spelling because of existing code using the other spellings. */
6579 if (!flag_isoc11
&& is_c11_alignof
)
6582 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6585 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6588 c_parser_consume_token (parser
);
6589 c_inhibit_evaluation_warnings
++;
6591 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6592 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6594 /* Either __alignof__ ( type-name ) or __alignof__
6595 unary-expression starting with a compound literal. */
6597 struct c_type_name
*type_name
;
6599 c_parser_consume_token (parser
);
6600 loc
= c_parser_peek_token (parser
)->location
;
6601 type_name
= c_parser_type_name (parser
);
6602 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6603 if (type_name
== NULL
)
6606 c_inhibit_evaluation_warnings
--;
6608 ret
.value
= error_mark_node
;
6609 ret
.original_code
= ERROR_MARK
;
6610 ret
.original_type
= NULL
;
6613 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6615 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6620 /* alignof ( type-name ). */
6621 c_inhibit_evaluation_warnings
--;
6623 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6625 false, is_c11_alignof
, 1);
6626 ret
.original_code
= ERROR_MARK
;
6627 ret
.original_type
= NULL
;
6633 expr
= c_parser_unary_expression (parser
);
6635 mark_exp_read (expr
.value
);
6636 c_inhibit_evaluation_warnings
--;
6638 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6640 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6641 ret
.original_code
= ERROR_MARK
;
6642 ret
.original_type
= NULL
;
6647 /* Helper function to read arguments of builtins which are interfaces
6648 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6649 others. The name of the builtin is passed using BNAME parameter.
6650 Function returns true if there were no errors while parsing and
6651 stores the arguments in CEXPR_LIST. */
6653 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6654 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6657 location_t loc
= c_parser_peek_token (parser
)->location
;
6658 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6660 bool saved_force_folding_builtin_constant_p
;
6662 *ret_cexpr_list
= NULL
;
6663 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6665 error_at (loc
, "cannot take address of %qs", bname
);
6669 c_parser_consume_token (parser
);
6671 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6673 c_parser_consume_token (parser
);
6677 saved_force_folding_builtin_constant_p
6678 = force_folding_builtin_constant_p
;
6679 force_folding_builtin_constant_p
|= choose_expr_p
;
6680 expr
= c_parser_expr_no_commas (parser
, NULL
);
6681 force_folding_builtin_constant_p
6682 = saved_force_folding_builtin_constant_p
;
6683 vec_alloc (cexpr_list
, 1);
6684 vec_safe_push (cexpr_list
, expr
);
6685 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6687 c_parser_consume_token (parser
);
6688 expr
= c_parser_expr_no_commas (parser
, NULL
);
6689 vec_safe_push (cexpr_list
, expr
);
6692 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6695 *ret_cexpr_list
= cexpr_list
;
6699 /* This represents a single generic-association. */
6701 struct c_generic_association
6703 /* The location of the starting token of the type. */
6704 location_t type_location
;
6705 /* The association's type, or NULL_TREE for 'default'. */
6707 /* The association's expression. */
6708 struct c_expr expression
;
6711 /* Parse a generic-selection. (C11 6.5.1.1).
6714 _Generic ( assignment-expression , generic-assoc-list )
6718 generic-assoc-list , generic-association
6720 generic-association:
6721 type-name : assignment-expression
6722 default : assignment-expression
6725 static struct c_expr
6726 c_parser_generic_selection (c_parser
*parser
)
6728 vec
<c_generic_association
> associations
= vNULL
;
6729 struct c_expr selector
, error_expr
;
6731 struct c_generic_association matched_assoc
;
6732 bool match_found
= false;
6733 location_t generic_loc
, selector_loc
;
6735 error_expr
.original_code
= ERROR_MARK
;
6736 error_expr
.original_type
= NULL
;
6737 error_expr
.value
= error_mark_node
;
6738 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6739 matched_assoc
.type
= NULL_TREE
;
6740 matched_assoc
.expression
= error_expr
;
6742 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6743 generic_loc
= c_parser_peek_token (parser
)->location
;
6744 c_parser_consume_token (parser
);
6748 pedwarn (generic_loc
, OPT_Wpedantic
,
6749 "ISO C99 does not support %<_Generic%>");
6751 pedwarn (generic_loc
, OPT_Wpedantic
,
6752 "ISO C90 does not support %<_Generic%>");
6755 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6758 c_inhibit_evaluation_warnings
++;
6759 selector_loc
= c_parser_peek_token (parser
)->location
;
6760 selector
= c_parser_expr_no_commas (parser
, NULL
);
6761 selector
= default_function_array_conversion (selector_loc
, selector
);
6762 c_inhibit_evaluation_warnings
--;
6764 if (selector
.value
== error_mark_node
)
6766 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6769 selector_type
= TREE_TYPE (selector
.value
);
6770 /* In ISO C terms, rvalues (including the controlling expression of
6771 _Generic) do not have qualified types. */
6772 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6773 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6774 /* In ISO C terms, _Noreturn is not part of the type of expressions
6775 such as &abort, but in GCC it is represented internally as a type
6777 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6778 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6780 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6782 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6784 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6790 struct c_generic_association assoc
, *iter
;
6792 c_token
*token
= c_parser_peek_token (parser
);
6794 assoc
.type_location
= token
->location
;
6795 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6797 c_parser_consume_token (parser
);
6798 assoc
.type
= NULL_TREE
;
6802 struct c_type_name
*type_name
;
6804 type_name
= c_parser_type_name (parser
);
6805 if (type_name
== NULL
)
6807 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6810 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6811 if (assoc
.type
== error_mark_node
)
6813 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6817 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6818 error_at (assoc
.type_location
,
6819 "%<_Generic%> association has function type");
6820 else if (!COMPLETE_TYPE_P (assoc
.type
))
6821 error_at (assoc
.type_location
,
6822 "%<_Generic%> association has incomplete type");
6824 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6825 error_at (assoc
.type_location
,
6826 "%<_Generic%> association has "
6827 "variable length type");
6830 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6832 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6836 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6837 if (assoc
.expression
.value
== error_mark_node
)
6839 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6843 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6845 if (assoc
.type
== NULL_TREE
)
6847 if (iter
->type
== NULL_TREE
)
6849 error_at (assoc
.type_location
,
6850 "duplicate %<default%> case in %<_Generic%>");
6851 inform (iter
->type_location
, "original %<default%> is here");
6854 else if (iter
->type
!= NULL_TREE
)
6856 if (comptypes (assoc
.type
, iter
->type
))
6858 error_at (assoc
.type_location
,
6859 "%<_Generic%> specifies two compatible types");
6860 inform (iter
->type_location
, "compatible type is here");
6865 if (assoc
.type
== NULL_TREE
)
6869 matched_assoc
= assoc
;
6873 else if (comptypes (assoc
.type
, selector_type
))
6875 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6877 matched_assoc
= assoc
;
6882 error_at (assoc
.type_location
,
6883 "%<_Generic> selector matches multiple associations");
6884 inform (matched_assoc
.type_location
,
6885 "other match is here");
6889 associations
.safe_push (assoc
);
6891 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6893 c_parser_consume_token (parser
);
6896 associations
.release ();
6898 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6900 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6906 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6907 "compatible with any association",
6912 return matched_assoc
.expression
;
6915 associations
.release ();
6919 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6923 postfix-expression [ expression ]
6924 postfix-expression ( argument-expression-list[opt] )
6925 postfix-expression . identifier
6926 postfix-expression -> identifier
6927 postfix-expression ++
6928 postfix-expression --
6929 ( type-name ) { initializer-list }
6930 ( type-name ) { initializer-list , }
6932 argument-expression-list:
6934 argument-expression-list , argument-expression
6947 (treated as a keyword in GNU C)
6950 ( compound-statement )
6951 __builtin_va_arg ( assignment-expression , type-name )
6952 __builtin_offsetof ( type-name , offsetof-member-designator )
6953 __builtin_choose_expr ( assignment-expression ,
6954 assignment-expression ,
6955 assignment-expression )
6956 __builtin_types_compatible_p ( type-name , type-name )
6957 __builtin_complex ( assignment-expression , assignment-expression )
6958 __builtin_shuffle ( assignment-expression , assignment-expression )
6959 __builtin_shuffle ( assignment-expression ,
6960 assignment-expression ,
6961 assignment-expression, )
6963 offsetof-member-designator:
6965 offsetof-member-designator . identifier
6966 offsetof-member-designator [ expression ]
6971 [ objc-receiver objc-message-args ]
6972 @selector ( objc-selector-arg )
6973 @protocol ( identifier )
6974 @encode ( type-name )
6976 Classname . identifier
6979 static struct c_expr
6980 c_parser_postfix_expression (c_parser
*parser
)
6982 struct c_expr expr
, e1
;
6983 struct c_type_name
*t1
, *t2
;
6984 location_t loc
= c_parser_peek_token (parser
)->location
;;
6985 expr
.original_code
= ERROR_MARK
;
6986 expr
.original_type
= NULL
;
6987 switch (c_parser_peek_token (parser
)->type
)
6990 expr
.value
= c_parser_peek_token (parser
)->value
;
6991 loc
= c_parser_peek_token (parser
)->location
;
6992 c_parser_consume_token (parser
);
6993 if (TREE_CODE (expr
.value
) == FIXED_CST
6994 && !targetm
.fixed_point_supported_p ())
6996 error_at (loc
, "fixed-point types not supported for this target");
6997 expr
.value
= error_mark_node
;
7004 expr
.value
= c_parser_peek_token (parser
)->value
;
7005 c_parser_consume_token (parser
);
7011 case CPP_UTF8STRING
:
7012 expr
.value
= c_parser_peek_token (parser
)->value
;
7013 expr
.original_code
= STRING_CST
;
7014 c_parser_consume_token (parser
);
7016 case CPP_OBJC_STRING
:
7017 gcc_assert (c_dialect_objc ());
7019 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7020 c_parser_consume_token (parser
);
7023 switch (c_parser_peek_token (parser
)->id_kind
)
7027 tree id
= c_parser_peek_token (parser
)->value
;
7028 c_parser_consume_token (parser
);
7029 expr
.value
= build_external_ref (loc
, id
,
7030 (c_parser_peek_token (parser
)->type
7032 &expr
.original_type
);
7035 case C_ID_CLASSNAME
:
7037 /* Here we parse the Objective-C 2.0 Class.name dot
7039 tree class_name
= c_parser_peek_token (parser
)->value
;
7041 c_parser_consume_token (parser
);
7042 gcc_assert (c_dialect_objc ());
7043 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7045 expr
.value
= error_mark_node
;
7048 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7050 c_parser_error (parser
, "expected identifier");
7051 expr
.value
= error_mark_node
;
7054 component
= c_parser_peek_token (parser
)->value
;
7055 c_parser_consume_token (parser
);
7056 expr
.value
= objc_build_class_component_ref (class_name
,
7061 c_parser_error (parser
, "expected expression");
7062 expr
.value
= error_mark_node
;
7066 case CPP_OPEN_PAREN
:
7067 /* A parenthesized expression, statement expression or compound
7069 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7071 /* A statement expression. */
7073 location_t brace_loc
;
7074 c_parser_consume_token (parser
);
7075 brace_loc
= c_parser_peek_token (parser
)->location
;
7076 c_parser_consume_token (parser
);
7077 if (!building_stmt_list_p ())
7079 error_at (loc
, "braced-group within expression allowed "
7080 "only inside a function");
7081 parser
->error
= true;
7082 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7083 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7084 expr
.value
= error_mark_node
;
7087 stmt
= c_begin_stmt_expr ();
7088 c_parser_compound_statement_nostart (parser
);
7089 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7091 pedwarn (loc
, OPT_Wpedantic
,
7092 "ISO C forbids braced-groups within expressions");
7093 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7094 mark_exp_read (expr
.value
);
7096 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7098 /* A compound literal. ??? Can we actually get here rather
7099 than going directly to
7100 c_parser_postfix_expression_after_paren_type from
7103 struct c_type_name
*type_name
;
7104 c_parser_consume_token (parser
);
7105 loc
= c_parser_peek_token (parser
)->location
;
7106 type_name
= c_parser_type_name (parser
);
7107 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7109 if (type_name
== NULL
)
7111 expr
.value
= error_mark_node
;
7114 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7120 /* A parenthesized expression. */
7121 c_parser_consume_token (parser
);
7122 expr
= c_parser_expression (parser
);
7123 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7124 TREE_NO_WARNING (expr
.value
) = 1;
7125 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7126 expr
.original_code
= ERROR_MARK
;
7127 /* Don't change EXPR.ORIGINAL_TYPE. */
7128 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7133 switch (c_parser_peek_token (parser
)->keyword
)
7135 case RID_FUNCTION_NAME
:
7136 case RID_PRETTY_FUNCTION_NAME
:
7137 case RID_C99_FUNCTION_NAME
:
7138 expr
.value
= fname_decl (loc
,
7139 c_parser_peek_token (parser
)->keyword
,
7140 c_parser_peek_token (parser
)->value
);
7141 c_parser_consume_token (parser
);
7144 c_parser_consume_token (parser
);
7145 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7147 expr
.value
= error_mark_node
;
7150 e1
= c_parser_expr_no_commas (parser
, NULL
);
7151 mark_exp_read (e1
.value
);
7152 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7153 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7155 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7156 expr
.value
= error_mark_node
;
7159 loc
= c_parser_peek_token (parser
)->location
;
7160 t1
= c_parser_type_name (parser
);
7161 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7165 expr
.value
= error_mark_node
;
7169 tree type_expr
= NULL_TREE
;
7170 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7171 groktypename (t1
, &type_expr
, NULL
));
7174 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7175 TREE_TYPE (expr
.value
), type_expr
,
7177 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7182 c_parser_consume_token (parser
);
7183 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7185 expr
.value
= error_mark_node
;
7188 t1
= c_parser_type_name (parser
);
7190 parser
->error
= true;
7191 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7192 gcc_assert (parser
->error
);
7195 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7196 expr
.value
= error_mark_node
;
7201 tree type
= groktypename (t1
, NULL
, NULL
);
7203 if (type
== error_mark_node
)
7204 offsetof_ref
= error_mark_node
;
7207 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7208 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7210 /* Parse the second argument to __builtin_offsetof. We
7211 must have one identifier, and beyond that we want to
7212 accept sub structure and sub array references. */
7213 if (c_parser_next_token_is (parser
, CPP_NAME
))
7215 offsetof_ref
= build_component_ref
7216 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7217 c_parser_consume_token (parser
);
7218 while (c_parser_next_token_is (parser
, CPP_DOT
)
7219 || c_parser_next_token_is (parser
,
7221 || c_parser_next_token_is (parser
,
7224 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7226 loc
= c_parser_peek_token (parser
)->location
;
7227 offsetof_ref
= build_array_ref (loc
,
7232 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7235 c_parser_consume_token (parser
);
7236 if (c_parser_next_token_is_not (parser
,
7239 c_parser_error (parser
, "expected identifier");
7242 offsetof_ref
= build_component_ref
7244 c_parser_peek_token (parser
)->value
);
7245 c_parser_consume_token (parser
);
7251 loc
= c_parser_peek_token (parser
)->location
;
7252 c_parser_consume_token (parser
);
7253 ce
= c_parser_expression (parser
);
7254 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7256 idx
= c_fully_fold (idx
, false, NULL
);
7257 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7259 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7264 c_parser_error (parser
, "expected identifier");
7265 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7267 expr
.value
= fold_offsetof (offsetof_ref
);
7270 case RID_CHOOSE_EXPR
:
7272 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7273 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7276 c_parser_consume_token (parser
);
7277 if (!c_parser_get_builtin_args (parser
,
7278 "__builtin_choose_expr",
7281 expr
.value
= error_mark_node
;
7285 if (vec_safe_length (cexpr_list
) != 3)
7287 error_at (loc
, "wrong number of arguments to "
7288 "%<__builtin_choose_expr%>");
7289 expr
.value
= error_mark_node
;
7293 e1_p
= &(*cexpr_list
)[0];
7294 e2_p
= &(*cexpr_list
)[1];
7295 e3_p
= &(*cexpr_list
)[2];
7298 mark_exp_read (e2_p
->value
);
7299 mark_exp_read (e3_p
->value
);
7300 if (TREE_CODE (c
) != INTEGER_CST
7301 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7303 "first argument to %<__builtin_choose_expr%> not"
7305 constant_expression_warning (c
);
7306 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7309 case RID_TYPES_COMPATIBLE_P
:
7310 c_parser_consume_token (parser
);
7311 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7313 expr
.value
= error_mark_node
;
7316 t1
= c_parser_type_name (parser
);
7319 expr
.value
= error_mark_node
;
7322 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7324 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7325 expr
.value
= error_mark_node
;
7328 t2
= c_parser_type_name (parser
);
7331 expr
.value
= error_mark_node
;
7334 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7338 e1
= groktypename (t1
, NULL
, NULL
);
7339 e2
= groktypename (t2
, NULL
, NULL
);
7340 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7342 expr
.value
= error_mark_node
;
7346 e1
= TYPE_MAIN_VARIANT (e1
);
7347 e2
= TYPE_MAIN_VARIANT (e2
);
7350 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7353 case RID_BUILTIN_COMPLEX
:
7355 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7356 c_expr_t
*e1_p
, *e2_p
;
7358 c_parser_consume_token (parser
);
7359 if (!c_parser_get_builtin_args (parser
,
7360 "__builtin_complex",
7361 &cexpr_list
, false))
7363 expr
.value
= error_mark_node
;
7367 if (vec_safe_length (cexpr_list
) != 2)
7369 error_at (loc
, "wrong number of arguments to "
7370 "%<__builtin_complex%>");
7371 expr
.value
= error_mark_node
;
7375 e1_p
= &(*cexpr_list
)[0];
7376 e2_p
= &(*cexpr_list
)[1];
7378 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7379 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7380 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7381 TREE_OPERAND (e1_p
->value
, 0));
7382 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7383 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7384 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7385 TREE_OPERAND (e2_p
->value
, 0));
7386 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7387 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7388 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7389 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7391 error_at (loc
, "%<__builtin_complex%> operand "
7392 "not of real binary floating-point type");
7393 expr
.value
= error_mark_node
;
7396 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7397 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7400 "%<__builtin_complex%> operands of different types");
7401 expr
.value
= error_mark_node
;
7405 pedwarn (loc
, OPT_Wpedantic
,
7406 "ISO C90 does not support complex types");
7407 expr
.value
= build2 (COMPLEX_EXPR
,
7410 (TREE_TYPE (e1_p
->value
))),
7411 e1_p
->value
, e2_p
->value
);
7414 case RID_BUILTIN_SHUFFLE
:
7416 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7420 c_parser_consume_token (parser
);
7421 if (!c_parser_get_builtin_args (parser
,
7422 "__builtin_shuffle",
7423 &cexpr_list
, false))
7425 expr
.value
= error_mark_node
;
7429 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7430 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7432 if (vec_safe_length (cexpr_list
) == 2)
7434 c_build_vec_perm_expr
7435 (loc
, (*cexpr_list
)[0].value
,
7436 NULL_TREE
, (*cexpr_list
)[1].value
);
7438 else if (vec_safe_length (cexpr_list
) == 3)
7440 c_build_vec_perm_expr
7441 (loc
, (*cexpr_list
)[0].value
,
7442 (*cexpr_list
)[1].value
,
7443 (*cexpr_list
)[2].value
);
7446 error_at (loc
, "wrong number of arguments to "
7447 "%<__builtin_shuffle%>");
7448 expr
.value
= error_mark_node
;
7452 case RID_AT_SELECTOR
:
7453 gcc_assert (c_dialect_objc ());
7454 c_parser_consume_token (parser
);
7455 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7457 expr
.value
= error_mark_node
;
7461 tree sel
= c_parser_objc_selector_arg (parser
);
7462 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7464 expr
.value
= objc_build_selector_expr (loc
, sel
);
7467 case RID_AT_PROTOCOL
:
7468 gcc_assert (c_dialect_objc ());
7469 c_parser_consume_token (parser
);
7470 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7472 expr
.value
= error_mark_node
;
7475 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7477 c_parser_error (parser
, "expected identifier");
7478 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7479 expr
.value
= error_mark_node
;
7483 tree id
= c_parser_peek_token (parser
)->value
;
7484 c_parser_consume_token (parser
);
7485 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7487 expr
.value
= objc_build_protocol_expr (id
);
7491 /* Extension to support C-structures in the archiver. */
7492 gcc_assert (c_dialect_objc ());
7493 c_parser_consume_token (parser
);
7494 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7496 expr
.value
= error_mark_node
;
7499 t1
= c_parser_type_name (parser
);
7502 expr
.value
= error_mark_node
;
7503 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7506 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7509 tree type
= groktypename (t1
, NULL
, NULL
);
7510 expr
.value
= objc_build_encode_expr (type
);
7514 expr
= c_parser_generic_selection (parser
);
7516 case RID_CILK_SPAWN
:
7517 c_parser_consume_token (parser
);
7520 error_at (loc
, "-fcilkplus must be enabled to use "
7522 expr
= c_parser_postfix_expression (parser
);
7523 expr
.value
= error_mark_node
;
7525 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7527 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7528 "are not permitted");
7529 /* Now flush out all the _Cilk_spawns. */
7530 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7531 c_parser_consume_token (parser
);
7532 expr
= c_parser_postfix_expression (parser
);
7536 expr
= c_parser_postfix_expression (parser
);
7537 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7541 c_parser_error (parser
, "expected expression");
7542 expr
.value
= error_mark_node
;
7546 case CPP_OPEN_SQUARE
:
7547 if (c_dialect_objc ())
7549 tree receiver
, args
;
7550 c_parser_consume_token (parser
);
7551 receiver
= c_parser_objc_receiver (parser
);
7552 args
= c_parser_objc_message_args (parser
);
7553 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7555 expr
.value
= objc_build_message_expr (receiver
, args
);
7558 /* Else fall through to report error. */
7560 c_parser_error (parser
, "expected expression");
7561 expr
.value
= error_mark_node
;
7564 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7567 /* Parse a postfix expression after a parenthesized type name: the
7568 brace-enclosed initializer of a compound literal, possibly followed
7569 by some postfix operators. This is separate because it is not
7570 possible to tell until after the type name whether a cast
7571 expression has a cast or a compound literal, or whether the operand
7572 of sizeof is a parenthesized type name or starts with a compound
7573 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7574 location of the first token after the parentheses around the type
7577 static struct c_expr
7578 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7579 struct c_type_name
*type_name
,
7580 location_t type_loc
)
7586 location_t start_loc
;
7587 tree type_expr
= NULL_TREE
;
7588 bool type_expr_const
= true;
7589 check_compound_literal_type (type_loc
, type_name
);
7590 start_init (NULL_TREE
, NULL
, 0);
7591 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7592 start_loc
= c_parser_peek_token (parser
)->location
;
7593 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7595 error_at (type_loc
, "compound literal has variable size");
7596 type
= error_mark_node
;
7598 init
= c_parser_braced_init (parser
, type
, false);
7600 maybe_warn_string_init (type_loc
, type
, init
);
7602 if (type
!= error_mark_node
7603 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7604 && current_function_decl
)
7606 error ("compound literal qualified by address-space qualifier");
7607 type
= error_mark_node
;
7611 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7612 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7613 ? CONSTRUCTOR_NON_CONST (init
.value
)
7614 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7615 non_const
|= !type_expr_const
;
7616 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7617 expr
.original_code
= ERROR_MARK
;
7618 expr
.original_type
= NULL
;
7621 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7623 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7624 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7628 gcc_assert (!non_const
);
7629 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7630 type_expr
, expr
.value
);
7633 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7636 /* Callback function for sizeof_pointer_memaccess_warning to compare
7640 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7642 return comptypes (type1
, type2
) == 1;
7645 /* Parse a postfix expression after the initial primary or compound
7646 literal; that is, parse a series of postfix operators.
7648 EXPR_LOC is the location of the primary expression. */
7650 static struct c_expr
7651 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7652 location_t expr_loc
,
7655 struct c_expr orig_expr
;
7657 location_t sizeof_arg_loc
[3];
7659 unsigned int literal_zero_mask
;
7661 vec
<tree
, va_gc
> *exprlist
;
7662 vec
<tree
, va_gc
> *origtypes
= NULL
;
7663 vec
<location_t
> arg_loc
= vNULL
;
7667 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7668 switch (c_parser_peek_token (parser
)->type
)
7670 case CPP_OPEN_SQUARE
:
7671 /* Array reference. */
7672 c_parser_consume_token (parser
);
7674 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7675 /* If we are here, then we have something like this:
7678 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7682 idx
= c_parser_expression (parser
).value
;
7683 /* Here we have 3 options:
7684 1. Array [EXPR] -- Normal Array call.
7685 2. Array [EXPR : EXPR] -- Array notation without stride.
7686 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7688 For 1, we just handle it just like a normal array expression.
7689 For 2 and 3 we handle it like we handle array notations. The
7690 idx value we have above becomes the initial/start index.
7693 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7694 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7698 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7700 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7703 expr
.original_code
= ERROR_MARK
;
7704 expr
.original_type
= NULL
;
7706 case CPP_OPEN_PAREN
:
7707 /* Function call. */
7708 c_parser_consume_token (parser
);
7709 for (i
= 0; i
< 3; i
++)
7711 sizeof_arg
[i
] = NULL_TREE
;
7712 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7714 literal_zero_mask
= 0;
7715 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7718 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7719 sizeof_arg_loc
, sizeof_arg
,
7720 &arg_loc
, &literal_zero_mask
);
7721 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7724 mark_exp_read (expr
.value
);
7725 if (warn_sizeof_pointer_memaccess
)
7726 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7727 expr
.value
, exprlist
,
7729 sizeof_ptr_memacc_comptypes
);
7730 if (warn_memset_transposed_args
7731 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7732 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7733 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7734 && vec_safe_length (exprlist
) == 3
7735 && integer_zerop ((*exprlist
)[2])
7736 && (literal_zero_mask
& (1 << 2)) != 0
7737 && (!integer_zerop ((*exprlist
)[1])
7738 || (literal_zero_mask
& (1 << 1)) == 0))
7739 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7740 "%<memset%> used with constant zero length parameter; "
7741 "this could be due to transposed parameters");
7744 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7745 exprlist
, origtypes
);
7746 expr
.original_code
= ERROR_MARK
;
7747 if (TREE_CODE (expr
.value
) == INTEGER_CST
7748 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7749 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7750 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7751 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7752 expr
.original_type
= NULL
;
7755 release_tree_vector (exprlist
);
7756 release_tree_vector (origtypes
);
7761 /* Structure element reference. */
7762 c_parser_consume_token (parser
);
7763 expr
= default_function_array_conversion (expr_loc
, expr
);
7764 if (c_parser_next_token_is (parser
, CPP_NAME
))
7765 ident
= c_parser_peek_token (parser
)->value
;
7768 c_parser_error (parser
, "expected identifier");
7769 expr
.value
= error_mark_node
;
7770 expr
.original_code
= ERROR_MARK
;
7771 expr
.original_type
= NULL
;
7774 c_parser_consume_token (parser
);
7775 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7776 expr
.original_code
= ERROR_MARK
;
7777 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7778 expr
.original_type
= NULL
;
7781 /* Remember the original type of a bitfield. */
7782 tree field
= TREE_OPERAND (expr
.value
, 1);
7783 if (TREE_CODE (field
) != FIELD_DECL
)
7784 expr
.original_type
= NULL
;
7786 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7790 /* Structure element reference. */
7791 c_parser_consume_token (parser
);
7792 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7793 if (c_parser_next_token_is (parser
, CPP_NAME
))
7794 ident
= c_parser_peek_token (parser
)->value
;
7797 c_parser_error (parser
, "expected identifier");
7798 expr
.value
= error_mark_node
;
7799 expr
.original_code
= ERROR_MARK
;
7800 expr
.original_type
= NULL
;
7803 c_parser_consume_token (parser
);
7804 expr
.value
= build_component_ref (op_loc
,
7805 build_indirect_ref (op_loc
,
7809 expr
.original_code
= ERROR_MARK
;
7810 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7811 expr
.original_type
= NULL
;
7814 /* Remember the original type of a bitfield. */
7815 tree field
= TREE_OPERAND (expr
.value
, 1);
7816 if (TREE_CODE (field
) != FIELD_DECL
)
7817 expr
.original_type
= NULL
;
7819 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7823 /* Postincrement. */
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
, POSTINCREMENT_EXPR
, expr
);
7831 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7832 expr
.value
= build_unary_op (op_loc
,
7833 POSTINCREMENT_EXPR
, expr
.value
, 0);
7835 expr
.original_code
= ERROR_MARK
;
7836 expr
.original_type
= NULL
;
7838 case CPP_MINUS_MINUS
:
7839 /* Postdecrement. */
7840 c_parser_consume_token (parser
);
7841 /* If the expressions have array notations, we expand them. */
7843 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7844 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7847 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7848 expr
.value
= build_unary_op (op_loc
,
7849 POSTDECREMENT_EXPR
, expr
.value
, 0);
7851 expr
.original_code
= ERROR_MARK
;
7852 expr
.original_type
= NULL
;
7860 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7863 assignment-expression
7864 expression , assignment-expression
7867 static struct c_expr
7868 c_parser_expression (c_parser
*parser
)
7870 location_t tloc
= c_parser_peek_token (parser
)->location
;
7872 expr
= c_parser_expr_no_commas (parser
, NULL
);
7873 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7874 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7875 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7879 location_t loc
= c_parser_peek_token (parser
)->location
;
7880 location_t expr_loc
;
7881 c_parser_consume_token (parser
);
7882 expr_loc
= c_parser_peek_token (parser
)->location
;
7883 lhsval
= expr
.value
;
7884 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7885 lhsval
= TREE_OPERAND (lhsval
, 1);
7886 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7887 mark_exp_read (lhsval
);
7888 next
= c_parser_expr_no_commas (parser
, NULL
);
7889 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7890 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7891 expr
.original_code
= COMPOUND_EXPR
;
7892 expr
.original_type
= next
.original_type
;
7897 /* Parse an expression and convert functions or arrays to pointers and
7898 lvalues to rvalues. */
7900 static struct c_expr
7901 c_parser_expression_conv (c_parser
*parser
)
7904 location_t loc
= c_parser_peek_token (parser
)->location
;
7905 expr
= c_parser_expression (parser
);
7906 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7910 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
7911 argument is a literal zero alone and if so, set it in literal_zero_mask. */
7914 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
7917 if (idx
>= HOST_BITS_PER_INT
)
7920 c_token
*tok
= c_parser_peek_token (parser
);
7928 /* If a parameter is literal zero alone, remember it
7929 for -Wmemset-transposed-args warning. */
7930 if (integer_zerop (tok
->value
)
7931 && !TREE_OVERFLOW (tok
->value
)
7932 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7933 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
7934 *literal_zero_mask
|= 1U << idx
;
7940 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7941 functions and arrays to pointers and lvalues to rvalues. If
7942 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7943 locations of function arguments into this vector.
7946 assignment-expression
7947 nonempty-expr-list , assignment-expression
7950 static vec
<tree
, va_gc
> *
7951 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7952 vec
<tree
, va_gc
> **p_orig_types
,
7953 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
7954 vec
<location_t
> *locations
,
7955 unsigned int *literal_zero_mask
)
7957 vec
<tree
, va_gc
> *ret
;
7958 vec
<tree
, va_gc
> *orig_types
;
7960 location_t loc
= c_parser_peek_token (parser
)->location
;
7961 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7962 unsigned int idx
= 0;
7964 ret
= make_tree_vector ();
7965 if (p_orig_types
== NULL
)
7968 orig_types
= make_tree_vector ();
7970 if (sizeof_arg
!= NULL
7971 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7972 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7973 if (literal_zero_mask
)
7974 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
7975 expr
= c_parser_expr_no_commas (parser
, NULL
);
7977 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7979 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7980 ret
->quick_push (expr
.value
);
7982 orig_types
->quick_push (expr
.original_type
);
7984 locations
->safe_push (loc
);
7985 if (sizeof_arg
!= NULL
7986 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7987 && expr
.original_code
== SIZEOF_EXPR
)
7989 sizeof_arg
[0] = c_last_sizeof_arg
;
7990 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7992 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7994 c_parser_consume_token (parser
);
7995 loc
= c_parser_peek_token (parser
)->location
;
7996 if (sizeof_arg
!= NULL
7997 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7998 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8000 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8001 if (literal_zero_mask
)
8002 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8003 expr
= c_parser_expr_no_commas (parser
, NULL
);
8005 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8007 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8008 vec_safe_push (ret
, expr
.value
);
8010 vec_safe_push (orig_types
, expr
.original_type
);
8012 locations
->safe_push (loc
);
8014 && sizeof_arg
!= NULL
8015 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8016 && expr
.original_code
== SIZEOF_EXPR
)
8018 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8019 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8023 *p_orig_types
= orig_types
;
8027 /* Parse Objective-C-specific constructs. */
8029 /* Parse an objc-class-definition.
8031 objc-class-definition:
8032 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8033 objc-class-instance-variables[opt] objc-methodprotolist @end
8034 @implementation identifier objc-superclass[opt]
8035 objc-class-instance-variables[opt]
8036 @interface identifier ( identifier ) objc-protocol-refs[opt]
8037 objc-methodprotolist @end
8038 @interface identifier ( ) objc-protocol-refs[opt]
8039 objc-methodprotolist @end
8040 @implementation identifier ( identifier )
8045 "@interface identifier (" must start "@interface identifier (
8046 identifier ) ...": objc-methodprotolist in the first production may
8047 not start with a parenthesized identifier as a declarator of a data
8048 definition with no declaration specifiers if the objc-superclass,
8049 objc-protocol-refs and objc-class-instance-variables are omitted. */
8052 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8057 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8059 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8064 c_parser_consume_token (parser
);
8065 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8067 c_parser_error (parser
, "expected identifier");
8070 id1
= c_parser_peek_token (parser
)->value
;
8071 c_parser_consume_token (parser
);
8072 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8074 /* We have a category or class extension. */
8076 tree proto
= NULL_TREE
;
8077 c_parser_consume_token (parser
);
8078 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8080 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8082 /* We have a class extension. */
8087 c_parser_error (parser
, "expected identifier or %<)%>");
8088 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8094 id2
= c_parser_peek_token (parser
)->value
;
8095 c_parser_consume_token (parser
);
8097 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8100 objc_start_category_implementation (id1
, id2
);
8103 if (c_parser_next_token_is (parser
, CPP_LESS
))
8104 proto
= c_parser_objc_protocol_refs (parser
);
8105 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8106 c_parser_objc_methodprotolist (parser
);
8107 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8108 objc_finish_interface ();
8111 if (c_parser_next_token_is (parser
, CPP_COLON
))
8113 c_parser_consume_token (parser
);
8114 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8116 c_parser_error (parser
, "expected identifier");
8119 superclass
= c_parser_peek_token (parser
)->value
;
8120 c_parser_consume_token (parser
);
8123 superclass
= NULL_TREE
;
8126 tree proto
= NULL_TREE
;
8127 if (c_parser_next_token_is (parser
, CPP_LESS
))
8128 proto
= c_parser_objc_protocol_refs (parser
);
8129 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8132 objc_start_class_implementation (id1
, superclass
);
8133 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8134 c_parser_objc_class_instance_variables (parser
);
8137 objc_continue_interface ();
8138 c_parser_objc_methodprotolist (parser
);
8139 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8140 objc_finish_interface ();
8144 objc_continue_implementation ();
8149 /* Parse objc-class-instance-variables.
8151 objc-class-instance-variables:
8152 { objc-instance-variable-decl-list[opt] }
8154 objc-instance-variable-decl-list:
8155 objc-visibility-spec
8156 objc-instance-variable-decl ;
8158 objc-instance-variable-decl-list objc-visibility-spec
8159 objc-instance-variable-decl-list objc-instance-variable-decl ;
8160 objc-instance-variable-decl-list ;
8162 objc-visibility-spec:
8167 objc-instance-variable-decl:
8172 c_parser_objc_class_instance_variables (c_parser
*parser
)
8174 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8175 c_parser_consume_token (parser
);
8176 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8179 /* Parse any stray semicolon. */
8180 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8182 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8184 c_parser_consume_token (parser
);
8187 /* Stop if at the end of the instance variables. */
8188 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8190 c_parser_consume_token (parser
);
8193 /* Parse any objc-visibility-spec. */
8194 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8196 c_parser_consume_token (parser
);
8197 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8200 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8202 c_parser_consume_token (parser
);
8203 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8206 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8208 c_parser_consume_token (parser
);
8209 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8212 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8214 c_parser_consume_token (parser
);
8215 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8218 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8220 c_parser_pragma (parser
, pragma_external
);
8224 /* Parse some comma-separated declarations. */
8225 decls
= c_parser_struct_declaration (parser
);
8228 /* There is a syntax error. We want to skip the offending
8229 tokens up to the next ';' (included) or '}'
8232 /* First, skip manually a ')' or ']'. This is because they
8233 reduce the nesting level, so c_parser_skip_until_found()
8234 wouldn't be able to skip past them. */
8235 c_token
*token
= c_parser_peek_token (parser
);
8236 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8237 c_parser_consume_token (parser
);
8239 /* Then, do the standard skipping. */
8240 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8242 /* We hopefully recovered. Start normal parsing again. */
8243 parser
->error
= false;
8248 /* Comma-separated instance variables are chained together
8249 in reverse order; add them one by one. */
8250 tree ivar
= nreverse (decls
);
8251 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8252 objc_add_instance_variable (copy_node (ivar
));
8254 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8258 /* Parse an objc-class-declaration.
8260 objc-class-declaration:
8261 @class identifier-list ;
8265 c_parser_objc_class_declaration (c_parser
*parser
)
8267 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8268 c_parser_consume_token (parser
);
8269 /* Any identifiers, including those declared as type names, are OK
8274 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8276 c_parser_error (parser
, "expected identifier");
8277 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8278 parser
->error
= false;
8281 id
= c_parser_peek_token (parser
)->value
;
8282 objc_declare_class (id
);
8283 c_parser_consume_token (parser
);
8284 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8285 c_parser_consume_token (parser
);
8289 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8292 /* Parse an objc-alias-declaration.
8294 objc-alias-declaration:
8295 @compatibility_alias identifier identifier ;
8299 c_parser_objc_alias_declaration (c_parser
*parser
)
8302 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8303 c_parser_consume_token (parser
);
8304 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8306 c_parser_error (parser
, "expected identifier");
8307 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8310 id1
= c_parser_peek_token (parser
)->value
;
8311 c_parser_consume_token (parser
);
8312 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8314 c_parser_error (parser
, "expected identifier");
8315 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8318 id2
= c_parser_peek_token (parser
)->value
;
8319 c_parser_consume_token (parser
);
8320 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8321 objc_declare_alias (id1
, id2
);
8324 /* Parse an objc-protocol-definition.
8326 objc-protocol-definition:
8327 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8328 @protocol identifier-list ;
8330 "@protocol identifier ;" should be resolved as "@protocol
8331 identifier-list ;": objc-methodprotolist may not start with a
8332 semicolon in the first alternative if objc-protocol-refs are
8336 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8338 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8340 c_parser_consume_token (parser
);
8341 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8343 c_parser_error (parser
, "expected identifier");
8346 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8347 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8349 /* Any identifiers, including those declared as type names, are
8354 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8356 c_parser_error (parser
, "expected identifier");
8359 id
= c_parser_peek_token (parser
)->value
;
8360 objc_declare_protocol (id
, attributes
);
8361 c_parser_consume_token (parser
);
8362 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8363 c_parser_consume_token (parser
);
8367 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8371 tree id
= c_parser_peek_token (parser
)->value
;
8372 tree proto
= NULL_TREE
;
8373 c_parser_consume_token (parser
);
8374 if (c_parser_next_token_is (parser
, CPP_LESS
))
8375 proto
= c_parser_objc_protocol_refs (parser
);
8376 parser
->objc_pq_context
= true;
8377 objc_start_protocol (id
, proto
, attributes
);
8378 c_parser_objc_methodprotolist (parser
);
8379 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8380 parser
->objc_pq_context
= false;
8381 objc_finish_interface ();
8385 /* Parse an objc-method-type.
8391 Return true if it is a class method (+) and false if it is
8392 an instance method (-).
8395 c_parser_objc_method_type (c_parser
*parser
)
8397 switch (c_parser_peek_token (parser
)->type
)
8400 c_parser_consume_token (parser
);
8403 c_parser_consume_token (parser
);
8410 /* Parse an objc-method-definition.
8412 objc-method-definition:
8413 objc-method-type objc-method-decl ;[opt] compound-statement
8417 c_parser_objc_method_definition (c_parser
*parser
)
8419 bool is_class_method
= c_parser_objc_method_type (parser
);
8420 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8421 parser
->objc_pq_context
= true;
8422 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8424 if (decl
== error_mark_node
)
8425 return; /* Bail here. */
8427 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8429 c_parser_consume_token (parser
);
8430 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8431 "extra semicolon in method definition specified");
8434 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8436 c_parser_error (parser
, "expected %<{%>");
8440 parser
->objc_pq_context
= false;
8441 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8443 add_stmt (c_parser_compound_statement (parser
));
8444 objc_finish_method_definition (current_function_decl
);
8448 /* This code is executed when we find a method definition
8449 outside of an @implementation context (or invalid for other
8450 reasons). Parse the method (to keep going) but do not emit
8453 c_parser_compound_statement (parser
);
8457 /* Parse an objc-methodprotolist.
8459 objc-methodprotolist:
8461 objc-methodprotolist objc-methodproto
8462 objc-methodprotolist declaration
8463 objc-methodprotolist ;
8467 The declaration is a data definition, which may be missing
8468 declaration specifiers under the same rules and diagnostics as
8469 other data definitions outside functions, and the stray semicolon
8470 is diagnosed the same way as a stray semicolon outside a
8474 c_parser_objc_methodprotolist (c_parser
*parser
)
8478 /* The list is terminated by @end. */
8479 switch (c_parser_peek_token (parser
)->type
)
8482 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8483 "ISO C does not allow extra %<;%> outside of a function");
8484 c_parser_consume_token (parser
);
8488 c_parser_objc_methodproto (parser
);
8491 c_parser_pragma (parser
, pragma_external
);
8496 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8498 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8499 c_parser_objc_at_property_declaration (parser
);
8500 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8502 objc_set_method_opt (true);
8503 c_parser_consume_token (parser
);
8505 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8507 objc_set_method_opt (false);
8508 c_parser_consume_token (parser
);
8511 c_parser_declaration_or_fndef (parser
, false, false, true,
8512 false, true, NULL
, vNULL
);
8518 /* Parse an objc-methodproto.
8521 objc-method-type objc-method-decl ;
8525 c_parser_objc_methodproto (c_parser
*parser
)
8527 bool is_class_method
= c_parser_objc_method_type (parser
);
8528 tree decl
, attributes
= NULL_TREE
;
8530 /* Remember protocol qualifiers in prototypes. */
8531 parser
->objc_pq_context
= true;
8532 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8534 /* Forget protocol qualifiers now. */
8535 parser
->objc_pq_context
= false;
8537 /* Do not allow the presence of attributes to hide an erroneous
8538 method implementation in the interface section. */
8539 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8541 c_parser_error (parser
, "expected %<;%>");
8545 if (decl
!= error_mark_node
)
8546 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8548 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8551 /* If we are at a position that method attributes may be present, check that
8552 there are not any parsed already (a syntax error) and then collect any
8553 specified at the current location. Finally, if new attributes were present,
8554 check that the next token is legal ( ';' for decls and '{' for defs). */
8557 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8562 c_parser_error (parser
,
8563 "method attributes must be specified at the end only");
8564 *attributes
= NULL_TREE
;
8568 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8569 *attributes
= c_parser_attributes (parser
);
8571 /* If there were no attributes here, just report any earlier error. */
8572 if (*attributes
== NULL_TREE
|| bad
)
8575 /* If the attributes are followed by a ; or {, then just report any earlier
8577 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8578 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8581 /* We've got attributes, but not at the end. */
8582 c_parser_error (parser
,
8583 "expected %<;%> or %<{%> after method attribute definition");
8587 /* Parse an objc-method-decl.
8590 ( objc-type-name ) objc-selector
8592 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8593 objc-keyword-selector objc-optparmlist
8596 objc-keyword-selector:
8598 objc-keyword-selector objc-keyword-decl
8601 objc-selector : ( objc-type-name ) identifier
8602 objc-selector : identifier
8603 : ( objc-type-name ) identifier
8607 objc-optparms objc-optellipsis
8611 objc-opt-parms , parameter-declaration
8619 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8620 tree
*attributes
, tree
*expr
)
8622 tree type
= NULL_TREE
;
8624 tree parms
= NULL_TREE
;
8625 bool ellipsis
= false;
8626 bool attr_err
= false;
8628 *attributes
= NULL_TREE
;
8629 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8631 c_parser_consume_token (parser
);
8632 type
= c_parser_objc_type_name (parser
);
8633 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8635 sel
= c_parser_objc_selector (parser
);
8636 /* If there is no selector, or a colon follows, we have an
8637 objc-keyword-selector. If there is a selector, and a colon does
8638 not follow, that selector ends the objc-method-decl. */
8639 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8642 tree list
= NULL_TREE
;
8645 tree atype
= NULL_TREE
, id
, keyworddecl
;
8646 tree param_attr
= NULL_TREE
;
8647 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8649 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8651 c_parser_consume_token (parser
);
8652 atype
= c_parser_objc_type_name (parser
);
8653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8656 /* New ObjC allows attributes on method parameters. */
8657 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8658 param_attr
= c_parser_attributes (parser
);
8659 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8661 c_parser_error (parser
, "expected identifier");
8662 return error_mark_node
;
8664 id
= c_parser_peek_token (parser
)->value
;
8665 c_parser_consume_token (parser
);
8666 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8667 list
= chainon (list
, keyworddecl
);
8668 tsel
= c_parser_objc_selector (parser
);
8669 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8673 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8675 /* Parse the optional parameter list. Optional Objective-C
8676 method parameters follow the C syntax, and may include '...'
8677 to denote a variable number of arguments. */
8678 parms
= make_node (TREE_LIST
);
8679 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8681 struct c_parm
*parm
;
8682 c_parser_consume_token (parser
);
8683 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8686 c_parser_consume_token (parser
);
8687 attr_err
|= c_parser_objc_maybe_method_attributes
8688 (parser
, attributes
) ;
8691 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8694 parms
= chainon (parms
,
8695 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8700 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8704 c_parser_error (parser
, "objective-c method declaration is expected");
8705 return error_mark_node
;
8709 return error_mark_node
;
8711 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8714 /* Parse an objc-type-name.
8717 objc-type-qualifiers[opt] type-name
8718 objc-type-qualifiers[opt]
8720 objc-type-qualifiers:
8722 objc-type-qualifiers objc-type-qualifier
8724 objc-type-qualifier: one of
8725 in out inout bycopy byref oneway
8729 c_parser_objc_type_name (c_parser
*parser
)
8731 tree quals
= NULL_TREE
;
8732 struct c_type_name
*type_name
= NULL
;
8733 tree type
= NULL_TREE
;
8736 c_token
*token
= c_parser_peek_token (parser
);
8737 if (token
->type
== CPP_KEYWORD
8738 && (token
->keyword
== RID_IN
8739 || token
->keyword
== RID_OUT
8740 || token
->keyword
== RID_INOUT
8741 || token
->keyword
== RID_BYCOPY
8742 || token
->keyword
== RID_BYREF
8743 || token
->keyword
== RID_ONEWAY
))
8745 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8746 c_parser_consume_token (parser
);
8751 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8752 type_name
= c_parser_type_name (parser
);
8754 type
= groktypename (type_name
, NULL
, NULL
);
8756 /* If the type is unknown, and error has already been produced and
8757 we need to recover from the error. In that case, use NULL_TREE
8758 for the type, as if no type had been specified; this will use the
8759 default type ('id') which is good for error recovery. */
8760 if (type
== error_mark_node
)
8763 return build_tree_list (quals
, type
);
8766 /* Parse objc-protocol-refs.
8773 c_parser_objc_protocol_refs (c_parser
*parser
)
8775 tree list
= NULL_TREE
;
8776 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8777 c_parser_consume_token (parser
);
8778 /* Any identifiers, including those declared as type names, are OK
8783 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8785 c_parser_error (parser
, "expected identifier");
8788 id
= c_parser_peek_token (parser
)->value
;
8789 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8790 c_parser_consume_token (parser
);
8791 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8792 c_parser_consume_token (parser
);
8796 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8800 /* Parse an objc-try-catch-finally-statement.
8802 objc-try-catch-finally-statement:
8803 @try compound-statement objc-catch-list[opt]
8804 @try compound-statement objc-catch-list[opt] @finally compound-statement
8807 @catch ( objc-catch-parameter-declaration ) compound-statement
8808 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8810 objc-catch-parameter-declaration:
8811 parameter-declaration
8814 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8816 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8817 for C++. Keep them in sync. */
8820 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8822 location_t location
;
8825 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8826 c_parser_consume_token (parser
);
8827 location
= c_parser_peek_token (parser
)->location
;
8828 objc_maybe_warn_exceptions (location
);
8829 stmt
= c_parser_compound_statement (parser
);
8830 objc_begin_try_stmt (location
, stmt
);
8832 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8834 struct c_parm
*parm
;
8835 tree parameter_declaration
= error_mark_node
;
8836 bool seen_open_paren
= false;
8838 c_parser_consume_token (parser
);
8839 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8840 seen_open_paren
= true;
8841 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8843 /* We have "@catch (...)" (where the '...' are literally
8844 what is in the code). Skip the '...'.
8845 parameter_declaration is set to NULL_TREE, and
8846 objc_being_catch_clauses() knows that that means
8848 c_parser_consume_token (parser
);
8849 parameter_declaration
= NULL_TREE
;
8853 /* We have "@catch (NSException *exception)" or something
8854 like that. Parse the parameter declaration. */
8855 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8857 parameter_declaration
= error_mark_node
;
8859 parameter_declaration
= grokparm (parm
, NULL
);
8861 if (seen_open_paren
)
8862 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8865 /* If there was no open parenthesis, we are recovering from
8866 an error, and we are trying to figure out what mistake
8867 the user has made. */
8869 /* If there is an immediate closing parenthesis, the user
8870 probably forgot the opening one (ie, they typed "@catch
8871 NSException *e)". Parse the closing parenthesis and keep
8873 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8874 c_parser_consume_token (parser
);
8876 /* If these is no immediate closing parenthesis, the user
8877 probably doesn't know that parenthesis are required at
8878 all (ie, they typed "@catch NSException *e"). So, just
8879 forget about the closing parenthesis and keep going. */
8881 objc_begin_catch_clause (parameter_declaration
);
8882 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8883 c_parser_compound_statement_nostart (parser
);
8884 objc_finish_catch_clause ();
8886 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8888 c_parser_consume_token (parser
);
8889 location
= c_parser_peek_token (parser
)->location
;
8890 stmt
= c_parser_compound_statement (parser
);
8891 objc_build_finally_clause (location
, stmt
);
8893 objc_finish_try_stmt ();
8896 /* Parse an objc-synchronized-statement.
8898 objc-synchronized-statement:
8899 @synchronized ( expression ) compound-statement
8903 c_parser_objc_synchronized_statement (c_parser
*parser
)
8907 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8908 c_parser_consume_token (parser
);
8909 loc
= c_parser_peek_token (parser
)->location
;
8910 objc_maybe_warn_exceptions (loc
);
8911 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8913 struct c_expr ce
= c_parser_expression (parser
);
8914 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8916 expr
= c_fully_fold (expr
, false, NULL
);
8917 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8920 expr
= error_mark_node
;
8921 stmt
= c_parser_compound_statement (parser
);
8922 objc_build_synchronized (loc
, expr
, stmt
);
8925 /* Parse an objc-selector; return NULL_TREE without an error if the
8926 next token is not an objc-selector.
8931 enum struct union if else while do for switch case default
8932 break continue return goto asm sizeof typeof __alignof
8933 unsigned long const short volatile signed restrict _Complex
8934 in out inout bycopy byref oneway int char float double void _Bool
8937 ??? Why this selection of keywords but not, for example, storage
8938 class specifiers? */
8941 c_parser_objc_selector (c_parser
*parser
)
8943 c_token
*token
= c_parser_peek_token (parser
);
8944 tree value
= token
->value
;
8945 if (token
->type
== CPP_NAME
)
8947 c_parser_consume_token (parser
);
8950 if (token
->type
!= CPP_KEYWORD
)
8952 switch (token
->keyword
)
8996 c_parser_consume_token (parser
);
9003 /* Parse an objc-selector-arg.
9007 objc-keywordname-list
9009 objc-keywordname-list:
9011 objc-keywordname-list objc-keywordname
9019 c_parser_objc_selector_arg (c_parser
*parser
)
9021 tree sel
= c_parser_objc_selector (parser
);
9022 tree list
= NULL_TREE
;
9023 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9027 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9029 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9030 sel
= c_parser_objc_selector (parser
);
9031 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9037 /* Parse an objc-receiver.
9046 c_parser_objc_receiver (c_parser
*parser
)
9048 location_t loc
= c_parser_peek_token (parser
)->location
;
9050 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9051 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9052 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9054 tree id
= c_parser_peek_token (parser
)->value
;
9055 c_parser_consume_token (parser
);
9056 return objc_get_class_reference (id
);
9058 struct c_expr ce
= c_parser_expression (parser
);
9059 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9060 return c_fully_fold (ce
.value
, false, NULL
);
9063 /* Parse objc-message-args.
9067 objc-keywordarg-list
9069 objc-keywordarg-list:
9071 objc-keywordarg-list objc-keywordarg
9074 objc-selector : objc-keywordexpr
9079 c_parser_objc_message_args (c_parser
*parser
)
9081 tree sel
= c_parser_objc_selector (parser
);
9082 tree list
= NULL_TREE
;
9083 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9088 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9089 return error_mark_node
;
9090 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9091 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9092 sel
= c_parser_objc_selector (parser
);
9093 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9099 /* Parse an objc-keywordexpr.
9106 c_parser_objc_keywordexpr (c_parser
*parser
)
9109 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9110 NULL
, NULL
, NULL
, NULL
);
9111 if (vec_safe_length (expr_list
) == 1)
9113 /* Just return the expression, remove a level of
9115 ret
= (*expr_list
)[0];
9119 /* We have a comma expression, we will collapse later. */
9120 ret
= build_tree_list_vec (expr_list
);
9122 release_tree_vector (expr_list
);
9126 /* A check, needed in several places, that ObjC interface, implementation or
9127 method definitions are not prefixed by incorrect items. */
9129 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9130 struct c_declspecs
*specs
)
9132 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9133 || specs
->typespec_kind
!= ctsk_none
)
9135 c_parser_error (parser
,
9136 "no type or storage class may be specified here,");
9137 c_parser_skip_to_end_of_block_or_statement (parser
);
9143 /* Parse an Objective-C @property declaration. The syntax is:
9145 objc-property-declaration:
9146 '@property' objc-property-attributes[opt] struct-declaration ;
9148 objc-property-attributes:
9149 '(' objc-property-attribute-list ')'
9151 objc-property-attribute-list:
9152 objc-property-attribute
9153 objc-property-attribute-list, objc-property-attribute
9155 objc-property-attribute
9156 'getter' = identifier
9157 'setter' = identifier
9166 @property NSString *name;
9167 @property (readonly) id object;
9168 @property (retain, nonatomic, getter=getTheName) id name;
9169 @property int a, b, c;
9171 PS: This function is identical to cp_parser_objc_at_propery_declaration
9172 for C++. Keep them in sync. */
9174 c_parser_objc_at_property_declaration (c_parser
*parser
)
9176 /* The following variables hold the attributes of the properties as
9177 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9178 seen. When we see an attribute, we set them to 'true' (if they
9179 are boolean properties) or to the identifier (if they have an
9180 argument, ie, for getter and setter). Note that here we only
9181 parse the list of attributes, check the syntax and accumulate the
9182 attributes that we find. objc_add_property_declaration() will
9183 then process the information. */
9184 bool property_assign
= false;
9185 bool property_copy
= false;
9186 tree property_getter_ident
= NULL_TREE
;
9187 bool property_nonatomic
= false;
9188 bool property_readonly
= false;
9189 bool property_readwrite
= false;
9190 bool property_retain
= false;
9191 tree property_setter_ident
= NULL_TREE
;
9193 /* 'properties' is the list of properties that we read. Usually a
9194 single one, but maybe more (eg, in "@property int a, b, c;" there
9199 loc
= c_parser_peek_token (parser
)->location
;
9200 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9202 c_parser_consume_token (parser
); /* Eat '@property'. */
9204 /* Parse the optional attribute list... */
9205 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9208 c_parser_consume_token (parser
);
9210 /* Property attribute keywords are valid now. */
9211 parser
->objc_property_attr_context
= true;
9215 bool syntax_error
= false;
9216 c_token
*token
= c_parser_peek_token (parser
);
9219 if (token
->type
!= CPP_KEYWORD
)
9221 if (token
->type
== CPP_CLOSE_PAREN
)
9222 c_parser_error (parser
, "expected identifier");
9225 c_parser_consume_token (parser
);
9226 c_parser_error (parser
, "unknown property attribute");
9230 keyword
= token
->keyword
;
9231 c_parser_consume_token (parser
);
9234 case RID_ASSIGN
: property_assign
= true; break;
9235 case RID_COPY
: property_copy
= true; break;
9236 case RID_NONATOMIC
: property_nonatomic
= true; break;
9237 case RID_READONLY
: property_readonly
= true; break;
9238 case RID_READWRITE
: property_readwrite
= true; break;
9239 case RID_RETAIN
: property_retain
= true; break;
9243 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9245 if (keyword
== RID_GETTER
)
9246 c_parser_error (parser
,
9247 "missing %<=%> (after %<getter%> attribute)");
9249 c_parser_error (parser
,
9250 "missing %<=%> (after %<setter%> attribute)");
9251 syntax_error
= true;
9254 c_parser_consume_token (parser
); /* eat the = */
9255 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9257 c_parser_error (parser
, "expected identifier");
9258 syntax_error
= true;
9261 if (keyword
== RID_SETTER
)
9263 if (property_setter_ident
!= NULL_TREE
)
9264 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9266 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9267 c_parser_consume_token (parser
);
9268 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9269 c_parser_error (parser
, "setter name must terminate with %<:%>");
9271 c_parser_consume_token (parser
);
9275 if (property_getter_ident
!= NULL_TREE
)
9276 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9278 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9279 c_parser_consume_token (parser
);
9283 c_parser_error (parser
, "unknown property attribute");
9284 syntax_error
= true;
9291 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9292 c_parser_consume_token (parser
);
9296 parser
->objc_property_attr_context
= false;
9297 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9299 /* ... and the property declaration(s). */
9300 properties
= c_parser_struct_declaration (parser
);
9302 if (properties
== error_mark_node
)
9304 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9305 parser
->error
= false;
9309 if (properties
== NULL_TREE
)
9310 c_parser_error (parser
, "expected identifier");
9313 /* Comma-separated properties are chained together in
9314 reverse order; add them one by one. */
9315 properties
= nreverse (properties
);
9317 for (; properties
; properties
= TREE_CHAIN (properties
))
9318 objc_add_property_declaration (loc
, copy_node (properties
),
9319 property_readonly
, property_readwrite
,
9320 property_assign
, property_retain
,
9321 property_copy
, property_nonatomic
,
9322 property_getter_ident
, property_setter_ident
);
9325 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9326 parser
->error
= false;
9329 /* Parse an Objective-C @synthesize declaration. The syntax is:
9331 objc-synthesize-declaration:
9332 @synthesize objc-synthesize-identifier-list ;
9334 objc-synthesize-identifier-list:
9335 objc-synthesize-identifier
9336 objc-synthesize-identifier-list, objc-synthesize-identifier
9338 objc-synthesize-identifier
9340 identifier = identifier
9343 @synthesize MyProperty;
9344 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9346 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9347 for C++. Keep them in sync.
9350 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9352 tree list
= NULL_TREE
;
9354 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9355 loc
= c_parser_peek_token (parser
)->location
;
9357 c_parser_consume_token (parser
);
9360 tree property
, ivar
;
9361 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9363 c_parser_error (parser
, "expected identifier");
9364 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9365 /* Once we find the semicolon, we can resume normal parsing.
9366 We have to reset parser->error manually because
9367 c_parser_skip_until_found() won't reset it for us if the
9368 next token is precisely a semicolon. */
9369 parser
->error
= false;
9372 property
= c_parser_peek_token (parser
)->value
;
9373 c_parser_consume_token (parser
);
9374 if (c_parser_next_token_is (parser
, CPP_EQ
))
9376 c_parser_consume_token (parser
);
9377 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9379 c_parser_error (parser
, "expected identifier");
9380 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9381 parser
->error
= false;
9384 ivar
= c_parser_peek_token (parser
)->value
;
9385 c_parser_consume_token (parser
);
9389 list
= chainon (list
, build_tree_list (ivar
, property
));
9390 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9391 c_parser_consume_token (parser
);
9395 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9396 objc_add_synthesize_declaration (loc
, list
);
9399 /* Parse an Objective-C @dynamic declaration. The syntax is:
9401 objc-dynamic-declaration:
9402 @dynamic identifier-list ;
9405 @dynamic MyProperty;
9406 @dynamic MyProperty, AnotherProperty;
9408 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9409 for C++. Keep them in sync.
9412 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9414 tree list
= NULL_TREE
;
9416 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9417 loc
= c_parser_peek_token (parser
)->location
;
9419 c_parser_consume_token (parser
);
9423 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9425 c_parser_error (parser
, "expected identifier");
9426 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9427 parser
->error
= false;
9430 property
= c_parser_peek_token (parser
)->value
;
9431 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9432 c_parser_consume_token (parser
);
9433 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9434 c_parser_consume_token (parser
);
9438 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9439 objc_add_dynamic_declaration (loc
, list
);
9443 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9444 should be considered, statements. ALLOW_STMT is true if we're within
9445 the context of a function and such pragmas are to be allowed. Returns
9446 true if we actually parsed such a pragma. */
9449 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9453 id
= c_parser_peek_token (parser
)->pragma_kind
;
9454 gcc_assert (id
!= PRAGMA_NONE
);
9458 case PRAGMA_OMP_BARRIER
:
9459 if (context
!= pragma_compound
)
9461 if (context
== pragma_stmt
)
9462 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9463 "used in compound statements");
9466 c_parser_omp_barrier (parser
);
9469 case PRAGMA_OMP_FLUSH
:
9470 if (context
!= pragma_compound
)
9472 if (context
== pragma_stmt
)
9473 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9474 "used in compound statements");
9477 c_parser_omp_flush (parser
);
9480 case PRAGMA_OMP_TASKWAIT
:
9481 if (context
!= pragma_compound
)
9483 if (context
== pragma_stmt
)
9484 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9485 "used in compound statements");
9488 c_parser_omp_taskwait (parser
);
9491 case PRAGMA_OMP_TASKYIELD
:
9492 if (context
!= pragma_compound
)
9494 if (context
== pragma_stmt
)
9495 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9496 "used in compound statements");
9499 c_parser_omp_taskyield (parser
);
9502 case PRAGMA_OMP_CANCEL
:
9503 if (context
!= pragma_compound
)
9505 if (context
== pragma_stmt
)
9506 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9507 "used in compound statements");
9510 c_parser_omp_cancel (parser
);
9513 case PRAGMA_OMP_CANCELLATION_POINT
:
9514 if (context
!= pragma_compound
)
9516 if (context
== pragma_stmt
)
9517 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9518 "only be used in compound statements");
9521 c_parser_omp_cancellation_point (parser
);
9524 case PRAGMA_OMP_THREADPRIVATE
:
9525 c_parser_omp_threadprivate (parser
);
9528 case PRAGMA_OMP_TARGET
:
9529 return c_parser_omp_target (parser
, context
);
9531 case PRAGMA_OMP_END_DECLARE_TARGET
:
9532 c_parser_omp_end_declare_target (parser
);
9535 case PRAGMA_OMP_SECTION
:
9536 error_at (c_parser_peek_token (parser
)->location
,
9537 "%<#pragma omp section%> may only be used in "
9538 "%<#pragma omp sections%> construct");
9539 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9542 case PRAGMA_OMP_DECLARE_REDUCTION
:
9543 c_parser_omp_declare (parser
, context
);
9546 c_parser_consume_pragma (parser
);
9547 c_parser_skip_to_pragma_eol (parser
);
9548 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9549 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9550 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9552 c_parser_error (parser
, "for, while or do statement expected");
9555 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9556 c_parser_for_statement (parser
, true);
9557 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9558 c_parser_while_statement (parser
, true);
9560 c_parser_do_statement (parser
, true);
9563 case PRAGMA_GCC_PCH_PREPROCESS
:
9564 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9565 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9568 case PRAGMA_CILK_SIMD
:
9569 if (!c_parser_cilk_verify_simd (parser
, context
))
9571 c_parser_consume_pragma (parser
);
9572 c_parser_cilk_simd (parser
);
9576 if (id
< PRAGMA_FIRST_EXTERNAL
)
9578 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9581 c_parser_error (parser
, "expected declaration specifiers");
9582 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9585 c_parser_omp_construct (parser
);
9591 c_parser_consume_pragma (parser
);
9592 c_invoke_pragma_handler (id
);
9594 /* Skip to EOL, but suppress any error message. Those will have been
9595 generated by the handler routine through calling error, as opposed
9596 to calling c_parser_error. */
9597 parser
->error
= true;
9598 c_parser_skip_to_pragma_eol (parser
);
9603 /* The interface the pragma parsers have to the lexer. */
9606 pragma_lex (tree
*value
)
9608 c_token
*tok
= c_parser_peek_token (the_parser
);
9609 enum cpp_ttype ret
= tok
->type
;
9611 *value
= tok
->value
;
9612 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9616 if (ret
== CPP_KEYWORD
)
9618 c_parser_consume_token (the_parser
);
9625 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9629 c_parser_consume_pragma (parser
);
9630 if (c_parser_next_token_is (parser
, CPP_STRING
))
9632 name
= c_parser_peek_token (parser
)->value
;
9633 c_parser_consume_token (parser
);
9636 c_parser_error (parser
, "expected string literal");
9637 c_parser_skip_to_pragma_eol (parser
);
9640 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9643 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9645 /* Returns name of the next clause.
9646 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9647 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9648 returned and the token is consumed. */
9650 static pragma_omp_clause
9651 c_parser_omp_clause_name (c_parser
*parser
)
9653 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9655 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9656 result
= PRAGMA_OMP_CLAUSE_IF
;
9657 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9658 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9659 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9660 result
= PRAGMA_OMP_CLAUSE_FOR
;
9661 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9663 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9668 if (!strcmp ("aligned", p
))
9669 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9672 if (!strcmp ("collapse", p
))
9673 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9674 else if (!strcmp ("copyin", p
))
9675 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9676 else if (!strcmp ("copyprivate", p
))
9677 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9680 if (!strcmp ("depend", p
))
9681 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9682 else if (!strcmp ("device", p
))
9683 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9684 else if (!strcmp ("dist_schedule", p
))
9685 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9688 if (!strcmp ("final", p
))
9689 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9690 else if (!strcmp ("firstprivate", p
))
9691 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9692 else if (!strcmp ("from", p
))
9693 result
= PRAGMA_OMP_CLAUSE_FROM
;
9696 if (!strcmp ("inbranch", p
))
9697 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9700 if (!strcmp ("lastprivate", p
))
9701 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9702 else if (!strcmp ("linear", p
))
9703 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9706 if (!strcmp ("map", p
))
9707 result
= PRAGMA_OMP_CLAUSE_MAP
;
9708 else if (!strcmp ("mergeable", p
))
9709 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9710 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9711 result
= PRAGMA_CILK_CLAUSE_MASK
;
9714 if (!strcmp ("notinbranch", p
))
9715 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9716 else if (!strcmp ("nowait", p
))
9717 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9718 else if (!strcmp ("num_teams", p
))
9719 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9720 else if (!strcmp ("num_threads", p
))
9721 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9722 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9723 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9726 if (!strcmp ("ordered", p
))
9727 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9730 if (!strcmp ("parallel", p
))
9731 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9732 else if (!strcmp ("private", p
))
9733 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9734 else if (!strcmp ("proc_bind", p
))
9735 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9738 if (!strcmp ("reduction", p
))
9739 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9742 if (!strcmp ("safelen", p
))
9743 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9744 else if (!strcmp ("schedule", p
))
9745 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9746 else if (!strcmp ("sections", p
))
9747 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9748 else if (!strcmp ("shared", p
))
9749 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9750 else if (!strcmp ("simdlen", p
))
9751 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9754 if (!strcmp ("taskgroup", p
))
9755 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9756 else if (!strcmp ("thread_limit", p
))
9757 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9758 else if (!strcmp ("to", p
))
9759 result
= PRAGMA_OMP_CLAUSE_TO
;
9762 if (!strcmp ("uniform", p
))
9763 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9764 else if (!strcmp ("untied", p
))
9765 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9768 if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9769 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9774 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9775 c_parser_consume_token (parser
);
9780 /* Validate that a clause of the given type does not already exist. */
9783 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9788 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9789 if (OMP_CLAUSE_CODE (c
) == code
)
9791 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9792 error_at (loc
, "too many %qs clauses", name
);
9800 variable-list , identifier
9802 If KIND is nonzero, create the appropriate node and install the
9803 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9804 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9806 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9807 return the list created. */
9810 c_parser_omp_variable_list (c_parser
*parser
,
9811 location_t clause_loc
,
9812 enum omp_clause_code kind
, tree list
)
9814 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9815 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9816 c_parser_error (parser
, "expected identifier");
9818 while (c_parser_next_token_is (parser
, CPP_NAME
)
9819 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9821 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9825 undeclared_variable (c_parser_peek_token (parser
)->location
,
9826 c_parser_peek_token (parser
)->value
);
9827 t
= error_mark_node
;
9830 c_parser_consume_token (parser
);
9832 if (t
== error_mark_node
)
9838 case OMP_CLAUSE_MAP
:
9839 case OMP_CLAUSE_FROM
:
9841 case OMP_CLAUSE_DEPEND
:
9842 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9844 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9846 c_parser_consume_token (parser
);
9847 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9848 low_bound
= c_parser_expression (parser
).value
;
9849 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9850 length
= integer_one_node
;
9854 if (!c_parser_require (parser
, CPP_COLON
,
9857 t
= error_mark_node
;
9860 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9861 length
= c_parser_expression (parser
).value
;
9863 /* Look for the closing `]'. */
9864 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9867 t
= error_mark_node
;
9870 t
= tree_cons (low_bound
, length
, t
);
9877 if (t
!= error_mark_node
)
9879 tree u
= build_omp_clause (clause_loc
, kind
);
9880 OMP_CLAUSE_DECL (u
) = t
;
9881 OMP_CLAUSE_CHAIN (u
) = list
;
9886 list
= tree_cons (t
, NULL_TREE
, list
);
9888 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9891 c_parser_consume_token (parser
);
9897 /* Similarly, but expect leading and trailing parenthesis. This is a very
9898 common case for omp clauses. */
9901 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9904 /* The clauses location. */
9905 location_t loc
= c_parser_peek_token (parser
)->location
;
9907 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9909 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9910 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9916 collapse ( constant-expression ) */
9919 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9921 tree c
, num
= error_mark_node
;
9925 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9927 loc
= c_parser_peek_token (parser
)->location
;
9928 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9930 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9931 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9933 if (num
== error_mark_node
)
9935 mark_exp_read (num
);
9936 num
= c_fully_fold (num
, false, NULL
);
9937 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9938 || !tree_fits_shwi_p (num
)
9939 || (n
= tree_to_shwi (num
)) <= 0
9943 "collapse argument needs positive constant integer expression");
9946 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9947 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9948 OMP_CLAUSE_CHAIN (c
) = list
;
9953 copyin ( variable-list ) */
9956 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9958 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9962 copyprivate ( variable-list ) */
9965 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9967 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9971 default ( shared | none ) */
9974 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9976 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9977 location_t loc
= c_parser_peek_token (parser
)->location
;
9980 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9982 if (c_parser_next_token_is (parser
, CPP_NAME
))
9984 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9989 if (strcmp ("none", p
) != 0)
9991 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9995 if (strcmp ("shared", p
) != 0)
9997 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10004 c_parser_consume_token (parser
);
10009 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10011 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10013 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10016 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10017 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10018 OMP_CLAUSE_CHAIN (c
) = list
;
10019 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10025 firstprivate ( variable-list ) */
10028 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10030 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10034 final ( expression ) */
10037 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10039 location_t loc
= c_parser_peek_token (parser
)->location
;
10040 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10042 tree t
= c_parser_paren_condition (parser
);
10045 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10047 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10048 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10049 OMP_CLAUSE_CHAIN (c
) = list
;
10053 c_parser_error (parser
, "expected %<(%>");
10059 if ( expression ) */
10062 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10064 location_t loc
= c_parser_peek_token (parser
)->location
;
10065 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10067 tree t
= c_parser_paren_condition (parser
);
10070 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10072 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10073 OMP_CLAUSE_IF_EXPR (c
) = t
;
10074 OMP_CLAUSE_CHAIN (c
) = list
;
10078 c_parser_error (parser
, "expected %<(%>");
10084 lastprivate ( variable-list ) */
10087 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10089 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10096 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10100 /* FIXME: Should we allow duplicates? */
10101 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10103 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10104 OMP_CLAUSE_MERGEABLE
);
10105 OMP_CLAUSE_CHAIN (c
) = list
;
10114 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10117 location_t loc
= c_parser_peek_token (parser
)->location
;
10119 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10121 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10122 OMP_CLAUSE_CHAIN (c
) = list
;
10127 num_threads ( expression ) */
10130 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10132 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10133 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10135 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10136 tree c
, t
= c_parser_expression (parser
).value
;
10138 t
= c_fully_fold (t
, false, NULL
);
10140 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10142 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10144 c_parser_error (parser
, "expected integer expression");
10148 /* Attempt to statically determine when the number isn't positive. */
10149 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10150 build_int_cst (TREE_TYPE (t
), 0));
10151 if (CAN_HAVE_LOCATION_P (c
))
10152 SET_EXPR_LOCATION (c
, expr_loc
);
10153 if (c
== boolean_true_node
)
10155 warning_at (expr_loc
, 0,
10156 "%<num_threads%> value must be positive");
10157 t
= integer_one_node
;
10160 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10162 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10163 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10164 OMP_CLAUSE_CHAIN (c
) = list
;
10175 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10179 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10181 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10182 OMP_CLAUSE_ORDERED
);
10183 OMP_CLAUSE_CHAIN (c
) = list
;
10189 private ( variable-list ) */
10192 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10194 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10198 reduction ( reduction-operator : variable-list )
10200 reduction-operator:
10201 One of: + * - & ^ | && ||
10205 reduction-operator:
10206 One of: + * - & ^ | && || max min
10210 reduction-operator:
10211 One of: + * - & ^ | && ||
10215 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10217 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10218 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10220 enum tree_code code
= ERROR_MARK
;
10221 tree reduc_id
= NULL_TREE
;
10223 switch (c_parser_peek_token (parser
)->type
)
10235 code
= BIT_AND_EXPR
;
10238 code
= BIT_XOR_EXPR
;
10241 code
= BIT_IOR_EXPR
;
10244 code
= TRUTH_ANDIF_EXPR
;
10247 code
= TRUTH_ORIF_EXPR
;
10252 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10253 if (strcmp (p
, "min") == 0)
10258 if (strcmp (p
, "max") == 0)
10263 reduc_id
= c_parser_peek_token (parser
)->value
;
10267 c_parser_error (parser
,
10268 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10269 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10270 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10273 c_parser_consume_token (parser
);
10274 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10275 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10279 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10280 OMP_CLAUSE_REDUCTION
, list
);
10281 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10283 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10284 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10285 if (code
== ERROR_MARK
10286 || !(INTEGRAL_TYPE_P (type
)
10287 || TREE_CODE (type
) == REAL_TYPE
10288 || TREE_CODE (type
) == COMPLEX_TYPE
))
10289 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10290 = c_omp_reduction_lookup (reduc_id
,
10291 TYPE_MAIN_VARIANT (type
));
10296 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10302 schedule ( schedule-kind )
10303 schedule ( schedule-kind , expression )
10306 static | dynamic | guided | runtime | auto
10310 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10313 location_t loc
= c_parser_peek_token (parser
)->location
;
10315 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10318 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10320 if (c_parser_next_token_is (parser
, CPP_NAME
))
10322 tree kind
= c_parser_peek_token (parser
)->value
;
10323 const char *p
= IDENTIFIER_POINTER (kind
);
10328 if (strcmp ("dynamic", p
) != 0)
10330 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10334 if (strcmp ("guided", p
) != 0)
10336 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10340 if (strcmp ("runtime", p
) != 0)
10342 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10349 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10350 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10351 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10352 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10356 c_parser_consume_token (parser
);
10357 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10360 c_parser_consume_token (parser
);
10362 here
= c_parser_peek_token (parser
)->location
;
10363 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10365 t
= c_fully_fold (t
, false, NULL
);
10367 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10368 error_at (here
, "schedule %<runtime%> does not take "
10369 "a %<chunk_size%> parameter");
10370 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10372 "schedule %<auto%> does not take "
10373 "a %<chunk_size%> parameter");
10374 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10375 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10377 c_parser_error (parser
, "expected integer expression");
10379 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10382 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10383 "expected %<,%> or %<)%>");
10385 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10386 OMP_CLAUSE_CHAIN (c
) = list
;
10390 c_parser_error (parser
, "invalid schedule kind");
10391 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10396 shared ( variable-list ) */
10399 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10401 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10408 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10412 /* FIXME: Should we allow duplicates? */
10413 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10415 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10416 OMP_CLAUSE_UNTIED
);
10417 OMP_CLAUSE_CHAIN (c
) = list
;
10427 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10428 enum omp_clause_code code
, tree list
)
10430 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10432 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10433 OMP_CLAUSE_CHAIN (c
) = list
;
10445 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10446 enum omp_clause_code code
, tree list
)
10448 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10449 OMP_CLAUSE_CHAIN (c
) = list
;
10455 num_teams ( expression ) */
10458 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10460 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10461 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10463 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10464 tree c
, t
= c_parser_expression (parser
).value
;
10466 t
= c_fully_fold (t
, false, NULL
);
10468 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10470 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10472 c_parser_error (parser
, "expected integer expression");
10476 /* Attempt to statically determine when the number isn't positive. */
10477 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10478 build_int_cst (TREE_TYPE (t
), 0));
10479 if (CAN_HAVE_LOCATION_P (c
))
10480 SET_EXPR_LOCATION (c
, expr_loc
);
10481 if (c
== boolean_true_node
)
10483 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10484 t
= integer_one_node
;
10487 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10489 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10490 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10491 OMP_CLAUSE_CHAIN (c
) = list
;
10499 thread_limit ( expression ) */
10502 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10504 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
10505 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10507 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10508 tree c
, t
= c_parser_expression (parser
).value
;
10510 t
= c_fully_fold (t
, false, NULL
);
10512 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10514 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10516 c_parser_error (parser
, "expected integer expression");
10520 /* Attempt to statically determine when the number isn't positive. */
10521 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10522 build_int_cst (TREE_TYPE (t
), 0));
10523 if (CAN_HAVE_LOCATION_P (c
))
10524 SET_EXPR_LOCATION (c
, expr_loc
);
10525 if (c
== boolean_true_node
)
10527 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10528 t
= integer_one_node
;
10531 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10534 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10535 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10536 OMP_CLAUSE_CHAIN (c
) = list
;
10544 aligned ( variable-list )
10545 aligned ( variable-list : constant-expression ) */
10548 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10550 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10553 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10556 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10557 OMP_CLAUSE_ALIGNED
, list
);
10559 if (c_parser_next_token_is (parser
, CPP_COLON
))
10561 c_parser_consume_token (parser
);
10562 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10563 mark_exp_read (alignment
);
10564 alignment
= c_fully_fold (alignment
, false, NULL
);
10565 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10566 && TREE_CODE (alignment
) != INTEGER_CST
10567 && tree_int_cst_sgn (alignment
) != 1)
10569 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10570 "be positive constant integer expression");
10571 alignment
= NULL_TREE
;
10574 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10575 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10578 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10583 linear ( variable-list )
10584 linear ( variable-list : expression ) */
10587 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
10589 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10592 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10595 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10596 OMP_CLAUSE_LINEAR
, list
);
10598 if (c_parser_next_token_is (parser
, CPP_COLON
))
10600 c_parser_consume_token (parser
);
10601 step
= c_parser_expression (parser
).value
;
10602 mark_exp_read (step
);
10603 step
= c_fully_fold (step
, false, NULL
);
10604 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
10606 sorry ("using parameters for %<linear%> step is not supported yet");
10607 step
= integer_one_node
;
10609 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10611 error_at (clause_loc
, "%<linear%> clause step expression must "
10613 step
= integer_one_node
;
10618 step
= integer_one_node
;
10620 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10622 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10630 safelen ( constant-expression ) */
10633 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10635 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10638 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10641 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10643 t
= c_fully_fold (t
, false, NULL
);
10644 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10645 && TREE_CODE (t
) != INTEGER_CST
10646 && tree_int_cst_sgn (t
) != 1)
10648 error_at (clause_loc
, "%<safelen%> clause expression must "
10649 "be positive constant integer expression");
10653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10654 if (t
== NULL_TREE
|| t
== error_mark_node
)
10657 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10659 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10660 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10661 OMP_CLAUSE_CHAIN (c
) = list
;
10666 simdlen ( constant-expression ) */
10669 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10671 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10674 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10677 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10679 t
= c_fully_fold (t
, false, NULL
);
10680 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10681 && TREE_CODE (t
) != INTEGER_CST
10682 && tree_int_cst_sgn (t
) != 1)
10684 error_at (clause_loc
, "%<simdlen%> clause expression must "
10685 "be positive constant integer expression");
10689 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10690 if (t
== NULL_TREE
|| t
== error_mark_node
)
10693 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10695 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10696 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10697 OMP_CLAUSE_CHAIN (c
) = list
;
10702 depend ( depend-kind: variable-list )
10705 in | out | inout */
10708 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10710 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10711 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10714 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10717 if (c_parser_next_token_is (parser
, CPP_NAME
))
10719 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10720 if (strcmp ("in", p
) == 0)
10721 kind
= OMP_CLAUSE_DEPEND_IN
;
10722 else if (strcmp ("inout", p
) == 0)
10723 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10724 else if (strcmp ("out", p
) == 0)
10725 kind
= OMP_CLAUSE_DEPEND_OUT
;
10732 c_parser_consume_token (parser
);
10733 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10736 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10737 OMP_CLAUSE_DEPEND
, list
);
10739 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10740 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10742 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10746 c_parser_error (parser
, "invalid depend kind");
10748 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10753 map ( map-kind: variable-list )
10754 map ( variable-list )
10757 alloc | to | from | tofrom */
10760 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10762 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10763 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10766 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10769 if (c_parser_next_token_is (parser
, CPP_NAME
)
10770 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10772 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10773 if (strcmp ("alloc", p
) == 0)
10774 kind
= OMP_CLAUSE_MAP_ALLOC
;
10775 else if (strcmp ("to", p
) == 0)
10776 kind
= OMP_CLAUSE_MAP_TO
;
10777 else if (strcmp ("from", p
) == 0)
10778 kind
= OMP_CLAUSE_MAP_FROM
;
10779 else if (strcmp ("tofrom", p
) == 0)
10780 kind
= OMP_CLAUSE_MAP_TOFROM
;
10783 c_parser_error (parser
, "invalid map kind");
10784 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10788 c_parser_consume_token (parser
);
10789 c_parser_consume_token (parser
);
10792 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10794 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10795 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10797 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10802 device ( expression ) */
10805 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10807 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10808 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10810 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10812 t
= c_fully_fold (t
, false, NULL
);
10814 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10816 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10818 c_parser_error (parser
, "expected integer expression");
10822 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10824 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10825 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10826 OMP_CLAUSE_CHAIN (c
) = list
;
10834 dist_schedule ( static )
10835 dist_schedule ( static , expression ) */
10838 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10840 tree c
, t
= NULL_TREE
;
10841 location_t loc
= c_parser_peek_token (parser
)->location
;
10843 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10846 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10848 c_parser_error (parser
, "invalid dist_schedule kind");
10849 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10854 c_parser_consume_token (parser
);
10855 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10857 c_parser_consume_token (parser
);
10859 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10861 t
= c_fully_fold (t
, false, NULL
);
10862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10865 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10866 "expected %<,%> or %<)%>");
10868 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10869 if (t
== error_mark_node
)
10872 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10873 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10874 OMP_CLAUSE_CHAIN (c
) = list
;
10879 proc_bind ( proc-bind-kind )
10882 master | close | spread */
10885 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10887 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10888 enum omp_clause_proc_bind_kind kind
;
10891 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10894 if (c_parser_next_token_is (parser
, CPP_NAME
))
10896 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10897 if (strcmp ("master", p
) == 0)
10898 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10899 else if (strcmp ("close", p
) == 0)
10900 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10901 else if (strcmp ("spread", p
) == 0)
10902 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10909 c_parser_consume_token (parser
);
10910 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10911 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10912 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10913 OMP_CLAUSE_CHAIN (c
) = list
;
10917 c_parser_error (parser
, "invalid proc_bind kind");
10918 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10923 to ( variable-list ) */
10926 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10928 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10932 from ( variable-list ) */
10935 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10937 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10941 uniform ( variable-list ) */
10944 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10946 /* The clauses location. */
10947 location_t loc
= c_parser_peek_token (parser
)->location
;
10949 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10951 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10953 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10958 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10959 is a bitmask in MASK. Return the list of clauses found; the result
10960 of clause default goes in *pdefault. */
10963 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10964 const char *where
, bool finish_p
= true)
10966 tree clauses
= NULL
;
10967 bool first
= true, cilk_simd_fn
= false;
10969 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10972 pragma_omp_clause c_kind
;
10973 const char *c_name
;
10974 tree prev
= clauses
;
10976 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10977 c_parser_consume_token (parser
);
10979 here
= c_parser_peek_token (parser
)->location
;
10980 c_kind
= c_parser_omp_clause_name (parser
);
10984 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10985 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10986 c_name
= "collapse";
10988 case PRAGMA_OMP_CLAUSE_COPYIN
:
10989 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10992 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10993 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10994 c_name
= "copyprivate";
10996 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10997 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10998 c_name
= "default";
11000 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11001 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11002 c_name
= "firstprivate";
11004 case PRAGMA_OMP_CLAUSE_FINAL
:
11005 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11008 case PRAGMA_OMP_CLAUSE_IF
:
11009 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11012 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11013 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11014 c_name
= "lastprivate";
11016 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11017 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11018 c_name
= "mergeable";
11020 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11021 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11024 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11025 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11026 c_name
= "num_threads";
11028 case PRAGMA_OMP_CLAUSE_ORDERED
:
11029 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11030 c_name
= "ordered";
11032 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11033 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11034 c_name
= "private";
11036 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11037 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11038 c_name
= "reduction";
11040 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11041 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11042 c_name
= "schedule";
11044 case PRAGMA_OMP_CLAUSE_SHARED
:
11045 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11048 case PRAGMA_OMP_CLAUSE_UNTIED
:
11049 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11052 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11053 case PRAGMA_CILK_CLAUSE_MASK
:
11054 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11056 c_name
= "inbranch";
11058 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11059 case PRAGMA_CILK_CLAUSE_NOMASK
:
11060 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11062 c_name
= "notinbranch";
11064 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11066 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11068 c_name
= "parallel";
11072 error_at (here
, "%qs must be the first clause of %qs",
11077 case PRAGMA_OMP_CLAUSE_FOR
:
11079 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11083 goto clause_not_first
;
11085 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11087 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11089 c_name
= "sections";
11091 goto clause_not_first
;
11093 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11095 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11097 c_name
= "taskgroup";
11099 goto clause_not_first
;
11101 case PRAGMA_OMP_CLAUSE_TO
:
11102 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11105 case PRAGMA_OMP_CLAUSE_FROM
:
11106 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11109 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11110 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11111 c_name
= "uniform";
11113 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11114 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11115 c_name
= "num_teams";
11117 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11118 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11119 c_name
= "thread_limit";
11121 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11122 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11123 c_name
= "aligned";
11125 case PRAGMA_OMP_CLAUSE_LINEAR
:
11126 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11127 cilk_simd_fn
= true;
11128 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11131 case PRAGMA_OMP_CLAUSE_DEPEND
:
11132 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11135 case PRAGMA_OMP_CLAUSE_MAP
:
11136 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11139 case PRAGMA_OMP_CLAUSE_DEVICE
:
11140 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11143 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11144 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11145 c_name
= "dist_schedule";
11147 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11148 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11149 c_name
= "proc_bind";
11151 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11152 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11153 c_name
= "safelen";
11155 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11156 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11157 c_name
= "simdlen";
11159 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11160 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11161 c_name
= "simdlen";
11164 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11170 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11172 /* Remove the invalid clause(s) from the list to avoid
11173 confusing the rest of the compiler. */
11175 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11180 c_parser_skip_to_pragma_eol (parser
);
11183 return c_finish_omp_clauses (clauses
);
11192 In practice, we're also interested in adding the statement to an
11193 outer node. So it is convenient if we work around the fact that
11194 c_parser_statement calls add_stmt. */
11197 c_parser_omp_structured_block (c_parser
*parser
)
11199 tree stmt
= push_stmt_list ();
11200 c_parser_statement (parser
);
11201 return pop_stmt_list (stmt
);
11205 # pragma omp atomic new-line
11209 x binop= expr | x++ | ++x | x-- | --x
11211 +, *, -, /, &, ^, |, <<, >>
11213 where x is an lvalue expression with scalar type.
11216 # pragma omp atomic new-line
11219 # pragma omp atomic read new-line
11222 # pragma omp atomic write new-line
11225 # pragma omp atomic update new-line
11228 # pragma omp atomic capture new-line
11231 # pragma omp atomic capture new-line
11239 expression-stmt | x = x binop expr
11241 v = expression-stmt
11243 { v = x; update-stmt; } | { update-stmt; v = x; }
11247 expression-stmt | x = x binop expr | x = expr binop x
11251 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11253 where x and v are lvalue expressions with scalar type.
11255 LOC is the location of the #pragma token. */
11258 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11260 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11261 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11262 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11263 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11264 struct c_expr expr
;
11266 bool structured_block
= false;
11267 bool swapped
= false;
11268 bool seq_cst
= false;
11270 if (c_parser_next_token_is (parser
, CPP_NAME
))
11272 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11273 if (!strcmp (p
, "seq_cst"))
11276 c_parser_consume_token (parser
);
11277 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11278 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11279 c_parser_consume_token (parser
);
11282 if (c_parser_next_token_is (parser
, CPP_NAME
))
11284 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11286 if (!strcmp (p
, "read"))
11287 code
= OMP_ATOMIC_READ
;
11288 else if (!strcmp (p
, "write"))
11290 else if (!strcmp (p
, "update"))
11292 else if (!strcmp (p
, "capture"))
11293 code
= OMP_ATOMIC_CAPTURE_NEW
;
11297 c_parser_consume_token (parser
);
11301 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11302 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11303 c_parser_consume_token (parser
);
11305 if (c_parser_next_token_is (parser
, CPP_NAME
))
11308 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11309 if (!strcmp (p
, "seq_cst"))
11312 c_parser_consume_token (parser
);
11316 c_parser_skip_to_pragma_eol (parser
);
11320 case OMP_ATOMIC_READ
:
11321 case NOP_EXPR
: /* atomic write */
11322 v
= c_parser_unary_expression (parser
).value
;
11323 v
= c_fully_fold (v
, false, NULL
);
11324 if (v
== error_mark_node
)
11326 loc
= c_parser_peek_token (parser
)->location
;
11327 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11329 if (code
== NOP_EXPR
)
11330 lhs
= c_parser_expression (parser
).value
;
11332 lhs
= c_parser_unary_expression (parser
).value
;
11333 lhs
= c_fully_fold (lhs
, false, NULL
);
11334 if (lhs
== error_mark_node
)
11336 if (code
== NOP_EXPR
)
11338 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11346 case OMP_ATOMIC_CAPTURE_NEW
:
11347 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11349 c_parser_consume_token (parser
);
11350 structured_block
= true;
11354 v
= c_parser_unary_expression (parser
).value
;
11355 v
= c_fully_fold (v
, false, NULL
);
11356 if (v
== error_mark_node
)
11358 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11366 /* For structured_block case we don't know yet whether
11367 old or new x should be captured. */
11369 eloc
= c_parser_peek_token (parser
)->location
;
11370 expr
= c_parser_unary_expression (parser
);
11372 expr
= default_function_array_conversion (eloc
, expr
);
11373 unfolded_lhs
= expr
.value
;
11374 lhs
= c_fully_fold (lhs
, false, NULL
);
11376 switch (TREE_CODE (lhs
))
11380 c_parser_skip_to_end_of_block_or_statement (parser
);
11381 if (structured_block
)
11383 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11384 c_parser_consume_token (parser
);
11385 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11387 c_parser_skip_to_end_of_block_or_statement (parser
);
11388 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11389 c_parser_consume_token (parser
);
11394 case POSTINCREMENT_EXPR
:
11395 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11396 code
= OMP_ATOMIC_CAPTURE_OLD
;
11398 case PREINCREMENT_EXPR
:
11399 lhs
= TREE_OPERAND (lhs
, 0);
11400 unfolded_lhs
= NULL_TREE
;
11401 opcode
= PLUS_EXPR
;
11402 rhs
= integer_one_node
;
11405 case POSTDECREMENT_EXPR
:
11406 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11407 code
= OMP_ATOMIC_CAPTURE_OLD
;
11409 case PREDECREMENT_EXPR
:
11410 lhs
= TREE_OPERAND (lhs
, 0);
11411 unfolded_lhs
= NULL_TREE
;
11412 opcode
= MINUS_EXPR
;
11413 rhs
= integer_one_node
;
11416 case COMPOUND_EXPR
:
11417 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11418 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11419 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11420 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11421 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11422 (TREE_OPERAND (lhs
, 1), 0), 0)))
11424 /* Undo effects of boolean_increment for post {in,de}crement. */
11425 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11428 if (TREE_CODE (lhs
) == MODIFY_EXPR
11429 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11431 /* Undo effects of boolean_increment. */
11432 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11434 /* This is pre or post increment. */
11435 rhs
= TREE_OPERAND (lhs
, 1);
11436 lhs
= TREE_OPERAND (lhs
, 0);
11437 unfolded_lhs
= NULL_TREE
;
11439 if (code
== OMP_ATOMIC_CAPTURE_NEW
11440 && !structured_block
11441 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11442 code
= OMP_ATOMIC_CAPTURE_OLD
;
11445 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11446 && TREE_OPERAND (lhs
, 0)
11447 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11449 /* This is pre or post decrement. */
11450 rhs
= TREE_OPERAND (lhs
, 1);
11451 lhs
= TREE_OPERAND (lhs
, 0);
11452 unfolded_lhs
= NULL_TREE
;
11454 if (code
== OMP_ATOMIC_CAPTURE_NEW
11455 && !structured_block
11456 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11457 code
= OMP_ATOMIC_CAPTURE_OLD
;
11463 switch (c_parser_peek_token (parser
)->type
)
11466 opcode
= MULT_EXPR
;
11469 opcode
= TRUNC_DIV_EXPR
;
11472 opcode
= PLUS_EXPR
;
11475 opcode
= MINUS_EXPR
;
11477 case CPP_LSHIFT_EQ
:
11478 opcode
= LSHIFT_EXPR
;
11480 case CPP_RSHIFT_EQ
:
11481 opcode
= RSHIFT_EXPR
;
11484 opcode
= BIT_AND_EXPR
;
11487 opcode
= BIT_IOR_EXPR
;
11490 opcode
= BIT_XOR_EXPR
;
11493 c_parser_consume_token (parser
);
11494 eloc
= c_parser_peek_token (parser
)->location
;
11495 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11497 switch (TREE_CODE (rhs1
))
11500 case TRUNC_DIV_EXPR
:
11508 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11510 opcode
= TREE_CODE (rhs1
);
11511 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11512 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11515 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11517 opcode
= TREE_CODE (rhs1
);
11518 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11519 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11520 swapped
= !commutative_tree_code (opcode
);
11529 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11531 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11533 code
= OMP_ATOMIC_CAPTURE_OLD
;
11536 expr
= default_function_array_read_conversion (eloc
, expr
);
11537 unfolded_lhs1
= expr
.value
;
11538 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11540 c_parser_consume_token (parser
);
11543 if (structured_block
)
11546 expr
= default_function_array_read_conversion (eloc
, expr
);
11547 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11552 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11555 c_parser_error (parser
,
11556 "invalid operator for %<#pragma omp atomic%>");
11560 /* Arrange to pass the location of the assignment operator to
11561 c_finish_omp_atomic. */
11562 loc
= c_parser_peek_token (parser
)->location
;
11563 c_parser_consume_token (parser
);
11564 eloc
= c_parser_peek_token (parser
)->location
;
11565 expr
= c_parser_expression (parser
);
11566 expr
= default_function_array_read_conversion (eloc
, expr
);
11568 rhs
= c_fully_fold (rhs
, false, NULL
);
11572 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11574 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11576 v
= c_parser_unary_expression (parser
).value
;
11577 v
= c_fully_fold (v
, false, NULL
);
11578 if (v
== error_mark_node
)
11580 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11582 eloc
= c_parser_peek_token (parser
)->location
;
11583 expr
= c_parser_unary_expression (parser
);
11585 expr
= default_function_array_read_conversion (eloc
, expr
);
11586 unfolded_lhs1
= expr
.value
;
11587 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11588 if (lhs1
== error_mark_node
)
11591 if (structured_block
)
11593 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11594 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11597 if (unfolded_lhs
&& unfolded_lhs1
11598 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11600 error ("%<#pragma omp atomic capture%> uses two different "
11601 "expressions for memory");
11602 stmt
= error_mark_node
;
11605 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11607 if (stmt
!= error_mark_node
)
11610 if (!structured_block
)
11611 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11616 # pragma omp barrier new-line
11620 c_parser_omp_barrier (c_parser
*parser
)
11622 location_t loc
= c_parser_peek_token (parser
)->location
;
11623 c_parser_consume_pragma (parser
);
11624 c_parser_skip_to_pragma_eol (parser
);
11626 c_finish_omp_barrier (loc
);
11630 # pragma omp critical [(name)] new-line
11633 LOC is the location of the #pragma itself. */
11636 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11638 tree stmt
, name
= NULL
;
11640 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11642 c_parser_consume_token (parser
);
11643 if (c_parser_next_token_is (parser
, CPP_NAME
))
11645 name
= c_parser_peek_token (parser
)->value
;
11646 c_parser_consume_token (parser
);
11647 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11650 c_parser_error (parser
, "expected identifier");
11652 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11653 c_parser_error (parser
, "expected %<(%> or end of line");
11654 c_parser_skip_to_pragma_eol (parser
);
11656 stmt
= c_parser_omp_structured_block (parser
);
11657 return c_finish_omp_critical (loc
, stmt
, name
);
11661 # pragma omp flush flush-vars[opt] new-line
11664 ( variable-list ) */
11667 c_parser_omp_flush (c_parser
*parser
)
11669 location_t loc
= c_parser_peek_token (parser
)->location
;
11670 c_parser_consume_pragma (parser
);
11671 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11672 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11673 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11674 c_parser_error (parser
, "expected %<(%> or end of line");
11675 c_parser_skip_to_pragma_eol (parser
);
11677 c_finish_omp_flush (loc
);
11680 /* Parse the restricted form of the for statement allowed by OpenMP.
11681 The real trick here is to determine the loop control variable early
11682 so that we can push a new decl if necessary to make it private.
11683 LOC is the location of the OMP in "#pragma omp". */
11686 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11687 tree clauses
, tree
*cclauses
)
11689 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11690 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11691 bool fail
= false, open_brace_parsed
= false;
11692 int i
, collapse
= 1, nbraces
= 0;
11693 location_t for_loc
;
11694 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11696 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11697 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11698 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
11700 gcc_assert (collapse
>= 1);
11702 declv
= make_tree_vec (collapse
);
11703 initv
= make_tree_vec (collapse
);
11704 condv
= make_tree_vec (collapse
);
11705 incrv
= make_tree_vec (collapse
);
11707 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11709 c_parser_error (parser
, "for statement expected");
11712 for_loc
= c_parser_peek_token (parser
)->location
;
11713 c_parser_consume_token (parser
);
11715 for (i
= 0; i
< collapse
; i
++)
11717 int bracecount
= 0;
11719 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11722 /* Parse the initialization declaration or expression. */
11723 if (c_parser_next_tokens_start_declaration (parser
))
11726 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11727 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11729 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11732 if (DECL_INITIAL (decl
) == error_mark_node
)
11733 decl
= error_mark_node
;
11736 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11737 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11739 struct c_expr decl_exp
;
11740 struct c_expr init_exp
;
11741 location_t init_loc
;
11743 decl_exp
= c_parser_postfix_expression (parser
);
11744 decl
= decl_exp
.value
;
11746 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11748 init_loc
= c_parser_peek_token (parser
)->location
;
11749 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11750 init_exp
= default_function_array_read_conversion (init_loc
,
11752 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11753 NOP_EXPR
, init_loc
, init_exp
.value
,
11754 init_exp
.original_type
);
11755 init
= c_process_expr_stmt (init_loc
, init
);
11757 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11762 c_parser_error (parser
,
11763 "expected iteration declaration or initialization");
11764 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11770 /* Parse the loop condition. */
11772 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11774 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11775 struct c_expr cond_expr
11776 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11778 cond
= cond_expr
.value
;
11779 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11780 cond
= c_fully_fold (cond
, false, NULL
);
11781 switch (cond_expr
.original_code
)
11789 if (code
== CILK_SIMD
)
11793 /* Can't be cond = error_mark_node, because we want to preserve
11794 the location until c_finish_omp_for. */
11795 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11798 protected_set_expr_location (cond
, cond_loc
);
11800 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11802 /* Parse the increment expression. */
11804 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11806 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11808 incr
= c_process_expr_stmt (incr_loc
,
11809 c_parser_expression (parser
).value
);
11811 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11813 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11817 TREE_VEC_ELT (declv
, i
) = decl
;
11818 TREE_VEC_ELT (initv
, i
) = init
;
11819 TREE_VEC_ELT (condv
, i
) = cond
;
11820 TREE_VEC_ELT (incrv
, i
) = incr
;
11824 if (i
== collapse
- 1)
11827 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11828 in between the collapsed for loops to be still considered perfectly
11829 nested. Hopefully the final version clarifies this.
11830 For now handle (multiple) {'s and empty statements. */
11833 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11835 c_parser_consume_token (parser
);
11838 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11840 c_parser_consume_token (parser
);
11843 else if (bracecount
11844 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11845 c_parser_consume_token (parser
);
11848 c_parser_error (parser
, "not enough perfectly nested loops");
11851 open_brace_parsed
= true;
11861 nbraces
+= bracecount
;
11864 save_break
= c_break_label
;
11865 if (code
== CILK_SIMD
)
11866 c_break_label
= build_int_cst (size_type_node
, 2);
11868 c_break_label
= size_one_node
;
11869 save_cont
= c_cont_label
;
11870 c_cont_label
= NULL_TREE
;
11871 body
= push_stmt_list ();
11873 if (open_brace_parsed
)
11875 location_t here
= c_parser_peek_token (parser
)->location
;
11876 stmt
= c_begin_compound_stmt (true);
11877 c_parser_compound_statement_nostart (parser
);
11878 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11881 add_stmt (c_parser_c99_block_statement (parser
));
11884 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11885 SET_EXPR_LOCATION (t
, loc
);
11889 body
= pop_stmt_list (body
);
11890 c_break_label
= save_break
;
11891 c_cont_label
= save_cont
;
11895 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11897 c_parser_consume_token (parser
);
11900 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11901 c_parser_consume_token (parser
);
11904 c_parser_error (parser
, "collapsed loops not perfectly nested");
11907 location_t here
= c_parser_peek_token (parser
)->location
;
11908 stmt
= c_begin_compound_stmt (true);
11910 c_parser_compound_statement_nostart (parser
);
11911 body
= c_end_compound_stmt (here
, stmt
, true);
11918 /* Only bother calling c_finish_omp_for if we haven't already generated
11919 an error from the initialization parsing. */
11922 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11923 incrv
, body
, NULL
);
11926 if (cclauses
!= NULL
11927 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11930 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11931 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11932 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11933 c
= &OMP_CLAUSE_CHAIN (*c
);
11936 for (i
= 0; i
< collapse
; i
++)
11937 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11940 c
= &OMP_CLAUSE_CHAIN (*c
);
11941 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11944 "iteration variable %qD should not be firstprivate",
11945 OMP_CLAUSE_DECL (*c
));
11946 *c
= OMP_CLAUSE_CHAIN (*c
);
11950 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11951 change it to shared (decl) in
11952 OMP_PARALLEL_CLAUSES. */
11953 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11954 OMP_CLAUSE_LASTPRIVATE
);
11955 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11956 if (code
== OMP_SIMD
)
11958 OMP_CLAUSE_CHAIN (l
)
11959 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11960 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
11964 OMP_CLAUSE_CHAIN (l
) = clauses
;
11967 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11971 OMP_FOR_CLAUSES (stmt
) = clauses
;
11976 while (!for_block
->is_empty ())
11978 /* FIXME diagnostics: LOC below should be the actual location of
11979 this particular for block. We need to build a list of
11980 locations to go along with FOR_BLOCK. */
11981 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11984 release_tree_vector (for_block
);
11988 /* Helper function for OpenMP parsing, split clauses and call
11989 finish_omp_clauses on each of the set of clauses afterwards. */
11992 omp_split_clauses (location_t loc
, enum tree_code code
,
11993 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11996 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11997 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11999 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
12003 #pragma omp simd simd-clause[optseq] new-line
12006 LOC is the location of the #pragma token.
12009 #define OMP_SIMD_CLAUSE_MASK \
12010 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
12011 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12012 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12013 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12014 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12015 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12016 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12019 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
12020 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12022 tree block
, clauses
, ret
;
12024 strcat (p_name
, " simd");
12025 mask
|= OMP_SIMD_CLAUSE_MASK
;
12026 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
12028 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12031 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
12032 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
12035 block
= c_begin_compound_stmt (true);
12036 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
12037 block
= c_end_compound_stmt (loc
, block
, true);
12044 #pragma omp for for-clause[optseq] new-line
12048 #pragma omp for simd for-simd-clause[optseq] new-line
12051 LOC is the location of the #pragma token.
12054 #define OMP_FOR_CLAUSE_MASK \
12055 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12056 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12057 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12058 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12059 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12060 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12061 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12062 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12065 c_parser_omp_for (location_t loc
, c_parser
*parser
,
12066 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12068 tree block
, clauses
, ret
;
12070 strcat (p_name
, " for");
12071 mask
|= OMP_FOR_CLAUSE_MASK
;
12073 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12075 if (c_parser_next_token_is (parser
, CPP_NAME
))
12077 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12079 if (strcmp (p
, "simd") == 0)
12081 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12082 if (cclauses
== NULL
)
12083 cclauses
= cclauses_buf
;
12085 c_parser_consume_token (parser
);
12086 if (!flag_openmp
) /* flag_openmp_simd */
12087 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12088 block
= c_begin_compound_stmt (true);
12089 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12090 block
= c_end_compound_stmt (loc
, block
, true);
12091 if (ret
== NULL_TREE
)
12093 ret
= make_node (OMP_FOR
);
12094 TREE_TYPE (ret
) = void_type_node
;
12095 OMP_FOR_BODY (ret
) = block
;
12096 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12097 SET_EXPR_LOCATION (ret
, loc
);
12102 if (!flag_openmp
) /* flag_openmp_simd */
12104 c_parser_skip_to_pragma_eol (parser
);
12108 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12111 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12112 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12115 block
= c_begin_compound_stmt (true);
12116 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12117 block
= c_end_compound_stmt (loc
, block
, true);
12124 # pragma omp master new-line
12127 LOC is the location of the #pragma token.
12131 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12133 c_parser_skip_to_pragma_eol (parser
);
12134 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12138 # pragma omp ordered new-line
12141 LOC is the location of the #pragma itself.
12145 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12147 c_parser_skip_to_pragma_eol (parser
);
12148 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12154 { section-sequence }
12157 section-directive[opt] structured-block
12158 section-sequence section-directive structured-block
12160 SECTIONS_LOC is the location of the #pragma omp sections. */
12163 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12165 tree stmt
, substmt
;
12166 bool error_suppress
= false;
12169 loc
= c_parser_peek_token (parser
)->location
;
12170 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12172 /* Avoid skipping until the end of the block. */
12173 parser
->error
= false;
12177 stmt
= push_stmt_list ();
12179 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12181 substmt
= c_parser_omp_structured_block (parser
);
12182 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12183 SET_EXPR_LOCATION (substmt
, loc
);
12184 add_stmt (substmt
);
12189 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12191 if (c_parser_next_token_is (parser
, CPP_EOF
))
12194 loc
= c_parser_peek_token (parser
)->location
;
12195 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12197 c_parser_consume_pragma (parser
);
12198 c_parser_skip_to_pragma_eol (parser
);
12199 error_suppress
= false;
12201 else if (!error_suppress
)
12203 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12204 error_suppress
= true;
12207 substmt
= c_parser_omp_structured_block (parser
);
12208 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12209 SET_EXPR_LOCATION (substmt
, loc
);
12210 add_stmt (substmt
);
12212 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12213 "expected %<#pragma omp section%> or %<}%>");
12215 substmt
= pop_stmt_list (stmt
);
12217 stmt
= make_node (OMP_SECTIONS
);
12218 SET_EXPR_LOCATION (stmt
, sections_loc
);
12219 TREE_TYPE (stmt
) = void_type_node
;
12220 OMP_SECTIONS_BODY (stmt
) = substmt
;
12222 return add_stmt (stmt
);
12226 # pragma omp sections sections-clause[optseq] newline
12229 LOC is the location of the #pragma token.
12232 #define OMP_SECTIONS_CLAUSE_MASK \
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_LASTPRIVATE) \
12236 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12237 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12240 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12241 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12243 tree block
, clauses
, ret
;
12245 strcat (p_name
, " sections");
12246 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12248 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12250 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12253 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12254 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12257 block
= c_begin_compound_stmt (true);
12258 ret
= c_parser_omp_sections_scope (loc
, parser
);
12260 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12261 block
= c_end_compound_stmt (loc
, block
, true);
12268 # pragma omp parallel parallel-clause[optseq] new-line
12270 # pragma omp parallel for parallel-for-clause[optseq] new-line
12272 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12276 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12279 LOC is the location of the #pragma token.
12282 #define OMP_PARALLEL_CLAUSE_MASK \
12283 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12284 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12285 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12286 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12287 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12288 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12289 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12290 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12291 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12294 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12295 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12297 tree stmt
, clauses
, block
;
12299 strcat (p_name
, " parallel");
12300 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12302 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12304 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12305 if (cclauses
== NULL
)
12306 cclauses
= cclauses_buf
;
12308 c_parser_consume_token (parser
);
12309 if (!flag_openmp
) /* flag_openmp_simd */
12310 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12311 block
= c_begin_omp_parallel ();
12312 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12314 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12316 if (ret
== NULL_TREE
)
12318 OMP_PARALLEL_COMBINED (stmt
) = 1;
12323 error_at (loc
, "expected %<for%> after %qs", p_name
);
12324 c_parser_skip_to_pragma_eol (parser
);
12327 else if (!flag_openmp
) /* flag_openmp_simd */
12329 c_parser_skip_to_pragma_eol (parser
);
12332 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12334 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12335 if (strcmp (p
, "sections") == 0)
12337 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12338 if (cclauses
== NULL
)
12339 cclauses
= cclauses_buf
;
12341 c_parser_consume_token (parser
);
12342 block
= c_begin_omp_parallel ();
12343 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12344 stmt
= c_finish_omp_parallel (loc
,
12345 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12347 OMP_PARALLEL_COMBINED (stmt
) = 1;
12352 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12354 block
= c_begin_omp_parallel ();
12355 c_parser_statement (parser
);
12356 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12362 # pragma omp single single-clause[optseq] new-line
12365 LOC is the location of the #pragma.
12368 #define OMP_SINGLE_CLAUSE_MASK \
12369 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12370 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12371 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12372 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12375 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12377 tree stmt
= make_node (OMP_SINGLE
);
12378 SET_EXPR_LOCATION (stmt
, loc
);
12379 TREE_TYPE (stmt
) = void_type_node
;
12381 OMP_SINGLE_CLAUSES (stmt
)
12382 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12383 "#pragma omp single");
12384 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12386 return add_stmt (stmt
);
12390 # pragma omp task task-clause[optseq] new-line
12392 LOC is the location of the #pragma.
12395 #define OMP_TASK_CLAUSE_MASK \
12396 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12397 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12398 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12399 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12400 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12401 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12402 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12403 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12404 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12407 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12409 tree clauses
, block
;
12411 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12412 "#pragma omp task");
12414 block
= c_begin_omp_task ();
12415 c_parser_statement (parser
);
12416 return c_finish_omp_task (loc
, clauses
, block
);
12420 # pragma omp taskwait new-line
12424 c_parser_omp_taskwait (c_parser
*parser
)
12426 location_t loc
= c_parser_peek_token (parser
)->location
;
12427 c_parser_consume_pragma (parser
);
12428 c_parser_skip_to_pragma_eol (parser
);
12430 c_finish_omp_taskwait (loc
);
12434 # pragma omp taskyield new-line
12438 c_parser_omp_taskyield (c_parser
*parser
)
12440 location_t loc
= c_parser_peek_token (parser
)->location
;
12441 c_parser_consume_pragma (parser
);
12442 c_parser_skip_to_pragma_eol (parser
);
12444 c_finish_omp_taskyield (loc
);
12448 # pragma omp taskgroup new-line
12452 c_parser_omp_taskgroup (c_parser
*parser
)
12454 location_t loc
= c_parser_peek_token (parser
)->location
;
12455 c_parser_skip_to_pragma_eol (parser
);
12456 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12460 # pragma omp cancel cancel-clause[optseq] new-line
12462 LOC is the location of the #pragma.
12465 #define OMP_CANCEL_CLAUSE_MASK \
12466 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12467 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12468 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12469 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12470 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12473 c_parser_omp_cancel (c_parser
*parser
)
12475 location_t loc
= c_parser_peek_token (parser
)->location
;
12477 c_parser_consume_pragma (parser
);
12478 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12479 "#pragma omp cancel");
12481 c_finish_omp_cancel (loc
, clauses
);
12485 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12487 LOC is the location of the #pragma.
12490 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12491 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12492 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12493 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12494 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12497 c_parser_omp_cancellation_point (c_parser
*parser
)
12499 location_t loc
= c_parser_peek_token (parser
)->location
;
12501 bool point_seen
= false;
12503 c_parser_consume_pragma (parser
);
12504 if (c_parser_next_token_is (parser
, CPP_NAME
))
12506 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12507 if (strcmp (p
, "point") == 0)
12509 c_parser_consume_token (parser
);
12515 c_parser_error (parser
, "expected %<point%>");
12516 c_parser_skip_to_pragma_eol (parser
);
12521 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12522 "#pragma omp cancellation point");
12524 c_finish_omp_cancellation_point (loc
, clauses
);
12528 #pragma omp distribute distribute-clause[optseq] new-line
12531 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12532 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12533 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12534 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12535 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12538 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12539 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12541 tree clauses
, block
, ret
;
12543 strcat (p_name
, " distribute");
12544 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12546 if (c_parser_next_token_is (parser
, CPP_NAME
))
12548 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12550 bool parallel
= false;
12552 if (strcmp (p
, "simd") == 0)
12555 parallel
= strcmp (p
, "parallel") == 0;
12556 if (parallel
|| simd
)
12558 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12559 if (cclauses
== NULL
)
12560 cclauses
= cclauses_buf
;
12561 c_parser_consume_token (parser
);
12562 if (!flag_openmp
) /* flag_openmp_simd */
12565 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12567 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12570 block
= c_begin_compound_stmt (true);
12572 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12574 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12575 block
= c_end_compound_stmt (loc
, block
, true);
12578 ret
= make_node (OMP_DISTRIBUTE
);
12579 TREE_TYPE (ret
) = void_type_node
;
12580 OMP_FOR_BODY (ret
) = block
;
12581 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12582 SET_EXPR_LOCATION (ret
, loc
);
12587 if (!flag_openmp
) /* flag_openmp_simd */
12589 c_parser_skip_to_pragma_eol (parser
);
12593 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12596 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12597 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12600 block
= c_begin_compound_stmt (true);
12601 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12602 block
= c_end_compound_stmt (loc
, block
, true);
12609 # pragma omp teams teams-clause[optseq] new-line
12610 structured-block */
12612 #define OMP_TEAMS_CLAUSE_MASK \
12613 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12622 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12623 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12625 tree clauses
, block
, ret
;
12627 strcat (p_name
, " teams");
12628 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12630 if (c_parser_next_token_is (parser
, CPP_NAME
))
12632 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12633 if (strcmp (p
, "distribute") == 0)
12635 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12636 if (cclauses
== NULL
)
12637 cclauses
= cclauses_buf
;
12639 c_parser_consume_token (parser
);
12640 if (!flag_openmp
) /* flag_openmp_simd */
12641 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12642 block
= c_begin_compound_stmt (true);
12643 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12644 block
= c_end_compound_stmt (loc
, block
, true);
12647 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12648 ret
= make_node (OMP_TEAMS
);
12649 TREE_TYPE (ret
) = void_type_node
;
12650 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12651 OMP_TEAMS_BODY (ret
) = block
;
12652 return add_stmt (ret
);
12655 if (!flag_openmp
) /* flag_openmp_simd */
12657 c_parser_skip_to_pragma_eol (parser
);
12661 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12664 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12665 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12668 tree stmt
= make_node (OMP_TEAMS
);
12669 TREE_TYPE (stmt
) = void_type_node
;
12670 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12671 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12673 return add_stmt (stmt
);
12677 # pragma omp target data target-data-clause[optseq] new-line
12678 structured-block */
12680 #define OMP_TARGET_DATA_CLAUSE_MASK \
12681 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12682 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12683 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12686 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12688 tree stmt
= make_node (OMP_TARGET_DATA
);
12689 TREE_TYPE (stmt
) = void_type_node
;
12691 OMP_TARGET_DATA_CLAUSES (stmt
)
12692 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12693 "#pragma omp target data");
12694 keep_next_level ();
12695 tree block
= c_begin_compound_stmt (true);
12696 add_stmt (c_parser_omp_structured_block (parser
));
12697 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12699 SET_EXPR_LOCATION (stmt
, loc
);
12700 return add_stmt (stmt
);
12704 # pragma omp target update target-update-clause[optseq] new-line */
12706 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12707 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12708 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12709 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12710 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12713 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12714 enum pragma_context context
)
12716 if (context
== pragma_stmt
)
12719 "%<#pragma omp target update%> may only be "
12720 "used in compound statements");
12721 c_parser_skip_to_pragma_eol (parser
);
12726 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12727 "#pragma omp target update");
12728 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12729 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12732 "%<#pragma omp target update must contain at least one "
12733 "%<from%> or %<to%> clauses");
12737 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12738 TREE_TYPE (stmt
) = void_type_node
;
12739 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12740 SET_EXPR_LOCATION (stmt
, loc
);
12746 # pragma omp target target-clause[optseq] new-line
12747 structured-block */
12749 #define OMP_TARGET_CLAUSE_MASK \
12750 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12751 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12752 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12755 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12757 location_t loc
= c_parser_peek_token (parser
)->location
;
12758 c_parser_consume_pragma (parser
);
12760 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12762 c_parser_error (parser
, "expected declaration specifiers");
12763 c_parser_skip_to_pragma_eol (parser
);
12767 if (c_parser_next_token_is (parser
, CPP_NAME
))
12769 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12771 if (strcmp (p
, "teams") == 0)
12773 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12774 char p_name
[sizeof ("#pragma omp target teams distribute "
12775 "parallel for simd")];
12777 c_parser_consume_token (parser
);
12778 strcpy (p_name
, "#pragma omp target");
12779 if (!flag_openmp
) /* flag_openmp_simd */
12781 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
12782 OMP_TARGET_CLAUSE_MASK
,
12784 return stmt
!= NULL_TREE
;
12786 keep_next_level ();
12787 tree block
= c_begin_compound_stmt (true);
12788 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12789 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12790 block
= c_end_compound_stmt (loc
, block
, true);
12791 if (ret
== NULL_TREE
)
12793 tree stmt
= make_node (OMP_TARGET
);
12794 TREE_TYPE (stmt
) = void_type_node
;
12795 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12796 OMP_TARGET_BODY (stmt
) = block
;
12800 else if (!flag_openmp
) /* flag_openmp_simd */
12802 c_parser_skip_to_pragma_eol (parser
);
12805 else if (strcmp (p
, "data") == 0)
12807 c_parser_consume_token (parser
);
12808 c_parser_omp_target_data (loc
, parser
);
12811 else if (strcmp (p
, "update") == 0)
12813 c_parser_consume_token (parser
);
12814 return c_parser_omp_target_update (loc
, parser
, context
);
12818 tree stmt
= make_node (OMP_TARGET
);
12819 TREE_TYPE (stmt
) = void_type_node
;
12821 OMP_TARGET_CLAUSES (stmt
)
12822 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12823 "#pragma omp target");
12824 keep_next_level ();
12825 tree block
= c_begin_compound_stmt (true);
12826 add_stmt (c_parser_omp_structured_block (parser
));
12827 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12829 SET_EXPR_LOCATION (stmt
, loc
);
12835 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12837 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12838 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12841 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12842 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12843 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12846 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12848 vec
<c_token
> clauses
= vNULL
;
12849 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12851 c_token
*token
= c_parser_peek_token (parser
);
12852 if (token
->type
== CPP_EOF
)
12854 c_parser_skip_to_pragma_eol (parser
);
12855 clauses
.release ();
12858 clauses
.safe_push (*token
);
12859 c_parser_consume_token (parser
);
12861 clauses
.safe_push (*c_parser_peek_token (parser
));
12862 c_parser_skip_to_pragma_eol (parser
);
12864 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12866 if (c_parser_peek_token (parser
)->pragma_kind
12867 != PRAGMA_OMP_DECLARE_REDUCTION
12868 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12869 || strcmp (IDENTIFIER_POINTER
12870 (c_parser_peek_2nd_token (parser
)->value
),
12873 c_parser_error (parser
,
12874 "%<#pragma omp declare simd%> must be followed by "
12875 "function declaration or definition or another "
12876 "%<#pragma omp declare simd%>");
12877 clauses
.release ();
12880 c_parser_consume_pragma (parser
);
12881 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12883 c_token
*token
= c_parser_peek_token (parser
);
12884 if (token
->type
== CPP_EOF
)
12886 c_parser_skip_to_pragma_eol (parser
);
12887 clauses
.release ();
12890 clauses
.safe_push (*token
);
12891 c_parser_consume_token (parser
);
12893 clauses
.safe_push (*c_parser_peek_token (parser
));
12894 c_parser_skip_to_pragma_eol (parser
);
12897 /* Make sure nothing tries to read past the end of the tokens. */
12899 memset (&eof_token
, 0, sizeof (eof_token
));
12900 eof_token
.type
= CPP_EOF
;
12901 clauses
.safe_push (eof_token
);
12902 clauses
.safe_push (eof_token
);
12906 case pragma_external
:
12907 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12908 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12910 int ext
= disable_extension_diagnostics ();
12912 c_parser_consume_token (parser
);
12913 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12914 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12915 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12917 restore_extension_diagnostics (ext
);
12920 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12923 case pragma_struct
:
12925 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12926 "function declaration or definition");
12928 case pragma_compound
:
12930 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12931 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12933 int ext
= disable_extension_diagnostics ();
12935 c_parser_consume_token (parser
);
12936 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12937 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12938 if (c_parser_next_tokens_start_declaration (parser
))
12940 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12941 true, NULL
, clauses
);
12942 restore_extension_diagnostics (ext
);
12945 restore_extension_diagnostics (ext
);
12947 else if (c_parser_next_tokens_start_declaration (parser
))
12949 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12953 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12954 "function declaration or definition");
12957 gcc_unreachable ();
12959 clauses
.release ();
12962 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12963 and put that into "omp declare simd" attribute. */
12966 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12967 vec
<c_token
> clauses
)
12970 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12972 error ("%<#pragma omp declare simd%> cannot be used in the same "
12973 "function marked as a Cilk Plus SIMD-enabled function");
12974 vec_free (parser
->cilk_simd_fn_tokens
);
12978 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12979 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12980 has already processed the tokens. */
12981 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
12983 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12985 error ("%<#pragma omp declare simd%> not immediately followed by "
12986 "a function declaration or definition");
12987 clauses
[0].type
= CPP_EOF
;
12990 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
12992 error_at (DECL_SOURCE_LOCATION (fndecl
),
12993 "%<#pragma omp declare simd%> not immediately followed by "
12994 "a single function declaration or definition");
12995 clauses
[0].type
= CPP_EOF
;
12999 if (parms
== NULL_TREE
)
13000 parms
= DECL_ARGUMENTS (fndecl
);
13002 unsigned int tokens_avail
= parser
->tokens_avail
;
13003 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13004 bool is_cilkplus_cilk_simd_fn
= false;
13006 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13008 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
13009 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
13010 is_cilkplus_cilk_simd_fn
= true;
13014 parser
->tokens
= clauses
.address ();
13015 parser
->tokens_avail
= clauses
.length ();
13018 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
13019 while (parser
->tokens_avail
> 3)
13021 c_token
*token
= c_parser_peek_token (parser
);
13022 if (!is_cilkplus_cilk_simd_fn
)
13023 gcc_assert (token
->type
== CPP_NAME
13024 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
13026 gcc_assert (token
->type
== CPP_NAME
13027 && is_cilkplus_vector_p (token
->value
));
13028 c_parser_consume_token (parser
);
13029 parser
->in_pragma
= true;
13031 tree c
= NULL_TREE
;
13032 if (is_cilkplus_cilk_simd_fn
)
13033 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
13034 "SIMD-enabled functions attribute");
13036 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
13037 "#pragma omp declare simd");
13038 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
13039 if (c
!= NULL_TREE
)
13040 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
13041 if (is_cilkplus_cilk_simd_fn
)
13043 tree k
= build_tree_list (get_identifier ("cilk simd function"),
13045 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
13046 DECL_ATTRIBUTES (fndecl
) = k
;
13048 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
13049 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
13050 DECL_ATTRIBUTES (fndecl
) = c
;
13053 parser
->tokens
= &parser
->tokens_buf
[0];
13054 parser
->tokens_avail
= tokens_avail
;
13055 if (clauses
.exists ())
13056 clauses
[0].type
= CPP_PRAGMA
;
13058 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13059 vec_free (parser
->cilk_simd_fn_tokens
);
13064 # pragma omp declare target new-line
13065 declarations and definitions
13066 # pragma omp end declare target new-line */
13069 c_parser_omp_declare_target (c_parser
*parser
)
13071 c_parser_skip_to_pragma_eol (parser
);
13072 current_omp_declare_target_attribute
++;
13076 c_parser_omp_end_declare_target (c_parser
*parser
)
13078 location_t loc
= c_parser_peek_token (parser
)->location
;
13079 c_parser_consume_pragma (parser
);
13080 if (c_parser_next_token_is (parser
, CPP_NAME
)
13081 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13084 c_parser_consume_token (parser
);
13085 if (c_parser_next_token_is (parser
, CPP_NAME
)
13086 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13088 c_parser_consume_token (parser
);
13091 c_parser_error (parser
, "expected %<target%>");
13092 c_parser_skip_to_pragma_eol (parser
);
13098 c_parser_error (parser
, "expected %<declare%>");
13099 c_parser_skip_to_pragma_eol (parser
);
13102 c_parser_skip_to_pragma_eol (parser
);
13103 if (!current_omp_declare_target_attribute
)
13104 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13105 "%<#pragma omp declare target%>");
13107 current_omp_declare_target_attribute
--;
13112 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13113 initializer-clause[opt] new-line
13115 initializer-clause:
13116 initializer (omp_priv = initializer)
13117 initializer (function-name (argument-list)) */
13120 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13122 unsigned int tokens_avail
= 0, i
;
13123 vec
<tree
> types
= vNULL
;
13124 vec
<c_token
> clauses
= vNULL
;
13125 enum tree_code reduc_code
= ERROR_MARK
;
13126 tree reduc_id
= NULL_TREE
;
13128 location_t rloc
= c_parser_peek_token (parser
)->location
;
13130 if (context
== pragma_struct
|| context
== pragma_param
)
13132 error ("%<#pragma omp declare reduction%> not at file or block scope");
13136 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13139 switch (c_parser_peek_token (parser
)->type
)
13142 reduc_code
= PLUS_EXPR
;
13145 reduc_code
= MULT_EXPR
;
13148 reduc_code
= MINUS_EXPR
;
13151 reduc_code
= BIT_AND_EXPR
;
13154 reduc_code
= BIT_XOR_EXPR
;
13157 reduc_code
= BIT_IOR_EXPR
;
13160 reduc_code
= TRUTH_ANDIF_EXPR
;
13163 reduc_code
= TRUTH_ORIF_EXPR
;
13167 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13168 if (strcmp (p
, "min") == 0)
13170 reduc_code
= MIN_EXPR
;
13173 if (strcmp (p
, "max") == 0)
13175 reduc_code
= MAX_EXPR
;
13178 reduc_id
= c_parser_peek_token (parser
)->value
;
13181 c_parser_error (parser
,
13182 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13183 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13187 tree orig_reduc_id
, reduc_decl
;
13188 orig_reduc_id
= reduc_id
;
13189 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13190 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13191 c_parser_consume_token (parser
);
13193 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13198 location_t loc
= c_parser_peek_token (parser
)->location
;
13199 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13202 type
= groktypename (ctype
, NULL
, NULL
);
13203 if (type
== error_mark_node
)
13205 else if ((INTEGRAL_TYPE_P (type
)
13206 || TREE_CODE (type
) == REAL_TYPE
13207 || TREE_CODE (type
) == COMPLEX_TYPE
)
13208 && orig_reduc_id
== NULL_TREE
)
13209 error_at (loc
, "predeclared arithmetic type in "
13210 "%<#pragma omp declare reduction%>");
13211 else if (TREE_CODE (type
) == FUNCTION_TYPE
13212 || TREE_CODE (type
) == ARRAY_TYPE
)
13213 error_at (loc
, "function or array type in "
13214 "%<#pragma omp declare reduction%>");
13215 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13216 error_at (loc
, "const, volatile or restrict qualified type in "
13217 "%<#pragma omp declare reduction%>");
13221 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13222 if (comptypes (TREE_PURPOSE (t
), type
))
13224 error_at (loc
, "redeclaration of %qs "
13225 "%<#pragma omp declare reduction%> for "
13227 IDENTIFIER_POINTER (reduc_id
)
13228 + sizeof ("omp declare reduction ") - 1,
13231 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13233 error_at (ploc
, "previous %<#pragma omp declare "
13237 if (t
== NULL_TREE
)
13238 types
.safe_push (type
);
13240 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13241 c_parser_consume_token (parser
);
13249 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13250 || types
.is_empty ())
13253 clauses
.release ();
13257 c_token
*token
= c_parser_peek_token (parser
);
13258 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13260 c_parser_consume_token (parser
);
13262 c_parser_skip_to_pragma_eol (parser
);
13266 if (types
.length () > 1)
13268 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13270 c_token
*token
= c_parser_peek_token (parser
);
13271 if (token
->type
== CPP_EOF
)
13273 clauses
.safe_push (*token
);
13274 c_parser_consume_token (parser
);
13276 clauses
.safe_push (*c_parser_peek_token (parser
));
13277 c_parser_skip_to_pragma_eol (parser
);
13279 /* Make sure nothing tries to read past the end of the tokens. */
13281 memset (&eof_token
, 0, sizeof (eof_token
));
13282 eof_token
.type
= CPP_EOF
;
13283 clauses
.safe_push (eof_token
);
13284 clauses
.safe_push (eof_token
);
13287 int errs
= errorcount
;
13288 FOR_EACH_VEC_ELT (types
, i
, type
)
13290 tokens_avail
= parser
->tokens_avail
;
13291 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13292 if (!clauses
.is_empty ())
13294 parser
->tokens
= clauses
.address ();
13295 parser
->tokens_avail
= clauses
.length ();
13296 parser
->in_pragma
= true;
13299 bool nested
= current_function_decl
!= NULL_TREE
;
13301 c_push_function_context ();
13302 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13303 reduc_id
, default_function_type
);
13304 current_function_decl
= fndecl
;
13305 allocate_struct_function (fndecl
, true);
13307 tree stmt
= push_stmt_list ();
13308 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13309 warn about these. */
13310 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13311 get_identifier ("omp_out"), type
);
13312 DECL_ARTIFICIAL (omp_out
) = 1;
13313 DECL_CONTEXT (omp_out
) = fndecl
;
13314 pushdecl (omp_out
);
13315 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13316 get_identifier ("omp_in"), type
);
13317 DECL_ARTIFICIAL (omp_in
) = 1;
13318 DECL_CONTEXT (omp_in
) = fndecl
;
13320 struct c_expr combiner
= c_parser_expression (parser
);
13321 struct c_expr initializer
;
13322 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13324 initializer
.value
= error_mark_node
;
13325 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13327 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13328 && strcmp (IDENTIFIER_POINTER
13329 (c_parser_peek_token (parser
)->value
),
13330 "initializer") == 0)
13332 c_parser_consume_token (parser
);
13335 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13336 get_identifier ("omp_priv"), type
);
13337 DECL_ARTIFICIAL (omp_priv
) = 1;
13338 DECL_INITIAL (omp_priv
) = error_mark_node
;
13339 DECL_CONTEXT (omp_priv
) = fndecl
;
13340 pushdecl (omp_priv
);
13341 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13342 get_identifier ("omp_orig"), type
);
13343 DECL_ARTIFICIAL (omp_orig
) = 1;
13344 DECL_CONTEXT (omp_orig
) = fndecl
;
13345 pushdecl (omp_orig
);
13346 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13348 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13350 c_parser_error (parser
, "expected %<omp_priv%> or "
13354 else if (strcmp (IDENTIFIER_POINTER
13355 (c_parser_peek_token (parser
)->value
),
13358 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13359 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13361 c_parser_error (parser
, "expected function-name %<(%>");
13365 initializer
= c_parser_postfix_expression (parser
);
13366 if (initializer
.value
13367 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13370 tree c
= initializer
.value
;
13371 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13372 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13373 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13375 if (j
== call_expr_nargs (c
))
13376 error ("one of the initializer call arguments should be "
13382 c_parser_consume_token (parser
);
13383 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13387 tree st
= push_stmt_list ();
13388 start_init (omp_priv
, NULL_TREE
, 0);
13389 location_t loc
= c_parser_peek_token (parser
)->location
;
13390 struct c_expr init
= c_parser_initializer (parser
);
13392 finish_decl (omp_priv
, loc
, init
.value
,
13393 init
.original_type
, NULL_TREE
);
13394 pop_stmt_list (st
);
13398 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13404 c_parser_skip_to_pragma_eol (parser
);
13406 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13407 DECL_INITIAL (reduc_decl
));
13408 DECL_INITIAL (reduc_decl
) = t
;
13409 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13410 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13411 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13412 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13413 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13414 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13417 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13418 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13419 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13420 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13421 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13422 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13423 walk_tree (&DECL_INITIAL (omp_priv
),
13424 c_check_omp_declare_reduction_r
,
13425 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13429 pop_stmt_list (stmt
);
13431 if (cfun
->language
!= NULL
)
13433 ggc_free (cfun
->language
);
13434 cfun
->language
= NULL
;
13437 current_function_decl
= NULL_TREE
;
13439 c_pop_function_context ();
13441 if (!clauses
.is_empty ())
13443 parser
->tokens
= &parser
->tokens_buf
[0];
13444 parser
->tokens_avail
= tokens_avail
;
13448 if (errs
!= errorcount
)
13452 clauses
.release ();
13458 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13459 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13460 initializer-clause[opt] new-line
13461 #pragma omp declare target new-line */
13464 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13466 c_parser_consume_pragma (parser
);
13467 if (c_parser_next_token_is (parser
, CPP_NAME
))
13469 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13470 if (strcmp (p
, "simd") == 0)
13472 /* c_parser_consume_token (parser); done in
13473 c_parser_omp_declare_simd. */
13474 c_parser_omp_declare_simd (parser
, context
);
13477 if (strcmp (p
, "reduction") == 0)
13479 c_parser_consume_token (parser
);
13480 c_parser_omp_declare_reduction (parser
, context
);
13483 if (!flag_openmp
) /* flag_openmp_simd */
13485 c_parser_skip_to_pragma_eol (parser
);
13488 if (strcmp (p
, "target") == 0)
13490 c_parser_consume_token (parser
);
13491 c_parser_omp_declare_target (parser
);
13496 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13498 c_parser_skip_to_pragma_eol (parser
);
13501 /* Main entry point to parsing most OpenMP pragmas. */
13504 c_parser_omp_construct (c_parser
*parser
)
13506 enum pragma_kind p_kind
;
13509 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13510 omp_clause_mask
mask (0);
13512 loc
= c_parser_peek_token (parser
)->location
;
13513 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13514 c_parser_consume_pragma (parser
);
13518 case PRAGMA_OMP_ATOMIC
:
13519 c_parser_omp_atomic (loc
, parser
);
13521 case PRAGMA_OMP_CRITICAL
:
13522 stmt
= c_parser_omp_critical (loc
, parser
);
13524 case PRAGMA_OMP_DISTRIBUTE
:
13525 strcpy (p_name
, "#pragma omp");
13526 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13528 case PRAGMA_OMP_FOR
:
13529 strcpy (p_name
, "#pragma omp");
13530 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13532 case PRAGMA_OMP_MASTER
:
13533 stmt
= c_parser_omp_master (loc
, parser
);
13535 case PRAGMA_OMP_ORDERED
:
13536 stmt
= c_parser_omp_ordered (loc
, parser
);
13538 case PRAGMA_OMP_PARALLEL
:
13539 strcpy (p_name
, "#pragma omp");
13540 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13542 case PRAGMA_OMP_SECTIONS
:
13543 strcpy (p_name
, "#pragma omp");
13544 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13546 case PRAGMA_OMP_SIMD
:
13547 strcpy (p_name
, "#pragma omp");
13548 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13550 case PRAGMA_OMP_SINGLE
:
13551 stmt
= c_parser_omp_single (loc
, parser
);
13553 case PRAGMA_OMP_TASK
:
13554 stmt
= c_parser_omp_task (loc
, parser
);
13556 case PRAGMA_OMP_TASKGROUP
:
13557 stmt
= c_parser_omp_taskgroup (parser
);
13559 case PRAGMA_OMP_TEAMS
:
13560 strcpy (p_name
, "#pragma omp");
13561 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13564 gcc_unreachable ();
13568 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13573 # pragma omp threadprivate (variable-list) */
13576 c_parser_omp_threadprivate (c_parser
*parser
)
13581 c_parser_consume_pragma (parser
);
13582 loc
= c_parser_peek_token (parser
)->location
;
13583 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13585 /* Mark every variable in VARS to be assigned thread local storage. */
13586 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13588 tree v
= TREE_PURPOSE (t
);
13590 /* FIXME diagnostics: Ideally we should keep individual
13591 locations for all the variables in the var list to make the
13592 following errors more precise. Perhaps
13593 c_parser_omp_var_list_parens() should construct a list of
13594 locations to go along with the var list. */
13596 /* If V had already been marked threadprivate, it doesn't matter
13597 whether it had been used prior to this point. */
13598 if (TREE_CODE (v
) != VAR_DECL
)
13599 error_at (loc
, "%qD is not a variable", v
);
13600 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13601 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13602 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13603 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13604 else if (TREE_TYPE (v
) == error_mark_node
)
13606 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13607 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13610 if (! DECL_THREAD_LOCAL_P (v
))
13612 set_decl_tls_model (v
, decl_default_tls_model (v
));
13613 /* If rtl has been already set for this var, call
13614 make_decl_rtl once again, so that encode_section_info
13615 has a chance to look at the new decl flags. */
13616 if (DECL_RTL_SET_P (v
))
13619 C_DECL_THREADPRIVATE_P (v
) = 1;
13623 c_parser_skip_to_pragma_eol (parser
);
13626 /* Cilk Plus <#pragma simd> parsing routines. */
13628 /* Helper function for c_parser_pragma. Perform some sanity checking
13629 for <#pragma simd> constructs. Returns FALSE if there was a
13633 c_parser_cilk_verify_simd (c_parser
*parser
,
13634 enum pragma_context context
)
13636 if (!flag_cilkplus
)
13638 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13639 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13642 if (context
== pragma_external
)
13644 c_parser_error (parser
,"pragma simd must be inside a function");
13645 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13652 This function is shared by SIMD-enabled functions and #pragma simd.
13653 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
13654 CLAUSES is unused. The main purpose of this function is to parse a
13655 vectorlength attribute or clause and check for parse errors.
13656 When IS_SIMD_FN is true then the function is merely caching the tokens
13657 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
13658 cache is cleared since there is no reason to continue.
13660 vectorlength ( constant-expression ) */
13663 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
13667 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
13669 /* The vectorlength clause behaves exactly like OpenMP's safelen
13670 clause. Represent it in OpenMP terms. */
13671 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13673 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13676 location_t loc
= c_parser_peek_token (parser
)->location
;
13677 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13678 expr
= c_fully_fold (expr
, false, NULL
);
13680 /* If expr is an error_mark_node then the above function would have
13681 emitted an error. No reason to do it twice. */
13682 if (expr
== error_mark_node
)
13684 else if (!TREE_TYPE (expr
)
13685 || !TREE_CONSTANT (expr
)
13686 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13688 error_at (loc
, "vectorlength must be an integer constant");
13689 else if (wi::exact_log2 (expr
) == -1)
13690 error_at (loc
, "vectorlength must be a power of 2");
13695 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
13696 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
13697 OMP_CLAUSE_CHAIN (u
) = clauses
;
13702 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13703 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13704 OMP_CLAUSE_CHAIN (u
) = clauses
;
13709 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13715 linear ( simd-linear-variable-list )
13717 simd-linear-variable-list:
13718 simd-linear-variable
13719 simd-linear-variable-list , simd-linear-variable
13721 simd-linear-variable:
13723 id-expression : simd-linear-step
13726 conditional-expression */
13729 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13731 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13734 location_t loc
= c_parser_peek_token (parser
)->location
;
13736 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13737 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13738 c_parser_error (parser
, "expected identifier");
13740 while (c_parser_next_token_is (parser
, CPP_NAME
)
13741 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13743 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13747 undeclared_variable (c_parser_peek_token (parser
)->location
,
13748 c_parser_peek_token (parser
)->value
);
13749 c_parser_consume_token (parser
);
13751 else if (var
== error_mark_node
)
13752 c_parser_consume_token (parser
);
13755 tree step
= integer_one_node
;
13757 /* Parse the linear step if present. */
13758 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13760 c_parser_consume_token (parser
);
13761 c_parser_consume_token (parser
);
13763 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13764 expr
= c_fully_fold (expr
, false, NULL
);
13766 if (TREE_TYPE (expr
)
13767 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13768 && (TREE_CONSTANT (expr
)
13772 c_parser_error (parser
,
13773 "step size must be an integer constant "
13774 "expression or an integer variable");
13777 c_parser_consume_token (parser
);
13779 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13780 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13781 OMP_CLAUSE_DECL (u
) = var
;
13782 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13783 OMP_CLAUSE_CHAIN (u
) = clauses
;
13787 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13790 c_parser_consume_token (parser
);
13793 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13798 /* Returns the name of the next clause. If the clause is not
13799 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13800 not consumed. Otherwise, the appropriate pragma_simd_clause is
13801 returned and the token is consumed. */
13803 static pragma_omp_clause
13804 c_parser_cilk_clause_name (c_parser
*parser
)
13806 pragma_omp_clause result
;
13807 c_token
*token
= c_parser_peek_token (parser
);
13809 if (!token
->value
|| token
->type
!= CPP_NAME
)
13810 return PRAGMA_CILK_CLAUSE_NONE
;
13812 const char *p
= IDENTIFIER_POINTER (token
->value
);
13814 if (!strcmp (p
, "vectorlength"))
13815 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13816 else if (!strcmp (p
, "linear"))
13817 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13818 else if (!strcmp (p
, "private"))
13819 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13820 else if (!strcmp (p
, "firstprivate"))
13821 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13822 else if (!strcmp (p
, "lastprivate"))
13823 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13824 else if (!strcmp (p
, "reduction"))
13825 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13827 return PRAGMA_CILK_CLAUSE_NONE
;
13829 c_parser_consume_token (parser
);
13833 /* Parse all #<pragma simd> clauses. Return the list of clauses
13837 c_parser_cilk_all_clauses (c_parser
*parser
)
13839 tree clauses
= NULL
;
13841 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13843 pragma_omp_clause c_kind
;
13845 c_kind
= c_parser_cilk_clause_name (parser
);
13849 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13850 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
13852 case PRAGMA_CILK_CLAUSE_LINEAR
:
13853 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13855 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13856 /* Use the OpenMP counterpart. */
13857 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13859 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13860 /* Use the OpenMP counterpart. */
13861 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13863 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13864 /* Use the OpenMP counterpart. */
13865 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13867 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13868 /* Use the OpenMP counterpart. */
13869 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13872 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13878 c_parser_skip_to_pragma_eol (parser
);
13879 return c_finish_cilk_clauses (clauses
);
13882 /* Main entry point for parsing Cilk Plus <#pragma simd> for
13886 c_parser_cilk_simd (c_parser
*parser
)
13888 tree clauses
= c_parser_cilk_all_clauses (parser
);
13889 tree block
= c_begin_compound_stmt (true);
13890 location_t loc
= c_parser_peek_token (parser
)->location
;
13891 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
13892 block
= c_end_compound_stmt (loc
, block
, true);
13896 /* Parse a transaction attribute (GCC Extension).
13898 transaction-attribute:
13902 The transactional memory language description is written for C++,
13903 and uses the C++0x attribute syntax. For compatibility, allow the
13904 bracket style for transactions in C as well. */
13907 c_parser_transaction_attributes (c_parser
*parser
)
13909 tree attr_name
, attr
= NULL
;
13911 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13912 return c_parser_attributes (parser
);
13914 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13916 c_parser_consume_token (parser
);
13917 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13920 attr_name
= c_parser_attribute_any_word (parser
);
13923 c_parser_consume_token (parser
);
13924 attr
= build_tree_list (attr_name
, NULL_TREE
);
13927 c_parser_error (parser
, "expected identifier");
13929 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13931 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13935 /* Parse a __transaction_atomic or __transaction_relaxed statement
13938 transaction-statement:
13939 __transaction_atomic transaction-attribute[opt] compound-statement
13940 __transaction_relaxed compound-statement
13942 Note that the only valid attribute is: "outer".
13946 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13948 unsigned int old_in
= parser
->in_transaction
;
13949 unsigned int this_in
= 1, new_in
;
13950 location_t loc
= c_parser_peek_token (parser
)->location
;
13953 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13954 || keyword
== RID_TRANSACTION_RELAXED
)
13955 && c_parser_next_token_is_keyword (parser
, keyword
));
13956 c_parser_consume_token (parser
);
13958 if (keyword
== RID_TRANSACTION_RELAXED
)
13959 this_in
|= TM_STMT_ATTR_RELAXED
;
13962 attrs
= c_parser_transaction_attributes (parser
);
13964 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13967 /* Keep track if we're in the lexical scope of an outer transaction. */
13968 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13970 parser
->in_transaction
= new_in
;
13971 stmt
= c_parser_compound_statement (parser
);
13972 parser
->in_transaction
= old_in
;
13975 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13977 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13978 "%<__transaction_atomic%> without transactional memory support enabled"
13979 : "%<__transaction_relaxed %> "
13980 "without transactional memory support enabled"));
13985 /* Parse a __transaction_atomic or __transaction_relaxed expression
13988 transaction-expression:
13989 __transaction_atomic ( expression )
13990 __transaction_relaxed ( expression )
13993 static struct c_expr
13994 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13997 unsigned int old_in
= parser
->in_transaction
;
13998 unsigned int this_in
= 1;
13999 location_t loc
= c_parser_peek_token (parser
)->location
;
14002 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
14003 || keyword
== RID_TRANSACTION_RELAXED
)
14004 && c_parser_next_token_is_keyword (parser
, keyword
));
14005 c_parser_consume_token (parser
);
14007 if (keyword
== RID_TRANSACTION_RELAXED
)
14008 this_in
|= TM_STMT_ATTR_RELAXED
;
14011 attrs
= c_parser_transaction_attributes (parser
);
14013 this_in
|= parse_tm_stmt_attr (attrs
, 0);
14016 parser
->in_transaction
= this_in
;
14017 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14019 tree expr
= c_parser_expression (parser
).value
;
14020 ret
.original_type
= TREE_TYPE (expr
);
14021 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
14022 if (this_in
& TM_STMT_ATTR_RELAXED
)
14023 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
14024 SET_EXPR_LOCATION (ret
.value
, loc
);
14025 ret
.original_code
= TRANSACTION_EXPR
;
14026 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14028 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
14035 ret
.value
= error_mark_node
;
14036 ret
.original_code
= ERROR_MARK
;
14037 ret
.original_type
= NULL
;
14039 parser
->in_transaction
= old_in
;
14042 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
14043 "%<__transaction_atomic%> without transactional memory support enabled"
14044 : "%<__transaction_relaxed %> "
14045 "without transactional memory support enabled"));
14050 /* Parse a __transaction_cancel statement (GCC Extension).
14052 transaction-cancel-statement:
14053 __transaction_cancel transaction-attribute[opt] ;
14055 Note that the only valid attribute is "outer".
14059 c_parser_transaction_cancel (c_parser
*parser
)
14061 location_t loc
= c_parser_peek_token (parser
)->location
;
14063 bool is_outer
= false;
14065 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
14066 c_parser_consume_token (parser
);
14068 attrs
= c_parser_transaction_attributes (parser
);
14070 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
14074 error_at (loc
, "%<__transaction_cancel%> without "
14075 "transactional memory support enabled");
14078 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
14080 error_at (loc
, "%<__transaction_cancel%> within a "
14081 "%<__transaction_relaxed%>");
14086 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
14087 && !is_tm_may_cancel_outer (current_function_decl
))
14089 error_at (loc
, "outer %<__transaction_cancel%> not "
14090 "within outer %<__transaction_atomic%>");
14091 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
14095 else if (parser
->in_transaction
== 0)
14097 error_at (loc
, "%<__transaction_cancel%> not within "
14098 "%<__transaction_atomic%>");
14102 return add_stmt (build_tm_abort_call (loc
, is_outer
));
14105 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
14108 /* Parse a single source file. */
14111 c_parse_file (void)
14113 /* Use local storage to begin. If the first token is a pragma, parse it.
14114 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14115 which will cause garbage collection. */
14118 memset (&tparser
, 0, sizeof tparser
);
14119 tparser
.tokens
= &tparser
.tokens_buf
[0];
14120 the_parser
= &tparser
;
14122 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
14123 c_parser_pragma_pch_preprocess (&tparser
);
14125 the_parser
= ggc_alloc
<c_parser
> ();
14126 *the_parser
= tparser
;
14127 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
14128 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
14130 /* Initialize EH, if we've been told to do so. */
14131 if (flag_exceptions
)
14132 using_eh_for_cleanups ();
14134 c_parser_translation_unit (the_parser
);
14138 /* This function parses Cilk Plus array notation. The starting index is
14139 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14140 return value of this function is a tree_node called VALUE_TREE of type
14141 ARRAY_NOTATION_REF. */
14144 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
14147 c_token
*token
= NULL
;
14148 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
14149 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
14150 tree array_type_domain
= NULL_TREE
;
14152 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
14154 /* No need to continue. If either of these 2 were true, then an error
14155 must be emitted already. Thus, no need to emit them twice. */
14156 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14157 return error_mark_node
;
14160 array_type
= TREE_TYPE (array_value
);
14161 gcc_assert (array_type
);
14162 type
= TREE_TYPE (array_type
);
14163 token
= c_parser_peek_token (parser
);
14165 if (token
->type
== CPP_EOF
)
14167 c_parser_error (parser
, "expected %<:%> or numeral");
14170 else if (token
->type
== CPP_COLON
)
14172 if (!initial_index
)
14174 /* If we are here, then we have a case like this A[:]. */
14175 c_parser_consume_token (parser
);
14176 if (TREE_CODE (array_type
) == POINTER_TYPE
)
14178 error_at (loc
, "start-index and length fields necessary for "
14179 "using array notations in pointers");
14180 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14181 return error_mark_node
;
14183 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14185 error_at (loc
, "array notations cannot be used with function "
14187 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14188 return error_mark_node
;
14190 array_type_domain
= TYPE_DOMAIN (array_type
);
14192 if (!array_type_domain
)
14194 error_at (loc
, "start-index and length fields necessary for "
14195 "using array notations in dimensionless arrays");
14196 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14197 return error_mark_node
;
14200 start_index
= TYPE_MINVAL (array_type_domain
);
14201 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
14203 if (!TYPE_MAXVAL (array_type_domain
)
14204 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
14206 error_at (loc
, "start-index and length fields necessary for "
14207 "using array notations in variable-length arrays");
14208 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14209 return error_mark_node
;
14211 end_index
= TYPE_MAXVAL (array_type_domain
);
14212 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
14213 end_index
, integer_one_node
);
14214 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
14215 stride
= build_int_cst (integer_type_node
, 1);
14216 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
14218 else if (initial_index
!= error_mark_node
)
14220 /* If we are here, then there should be 2 possibilities:
14221 1. Array [EXPR : EXPR]
14222 2. Array [EXPR : EXPR : EXPR]
14224 start_index
= initial_index
;
14226 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14228 error_at (loc
, "array notations cannot be used with function "
14230 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14231 return error_mark_node
;
14233 c_parser_consume_token (parser
); /* consume the ':' */
14234 struct c_expr ce
= c_parser_expression (parser
);
14235 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14236 end_index
= ce
.value
;
14237 if (!end_index
|| end_index
== error_mark_node
)
14239 c_parser_skip_to_end_of_block_or_statement (parser
);
14240 return error_mark_node
;
14242 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
14244 c_parser_consume_token (parser
);
14245 ce
= c_parser_expression (parser
);
14246 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14248 if (!stride
|| stride
== error_mark_node
)
14250 c_parser_skip_to_end_of_block_or_statement (parser
);
14251 return error_mark_node
;
14256 c_parser_error (parser
, "expected array notation expression");
14259 c_parser_error (parser
, "expected array notation expression");
14261 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14263 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
14264 end_index
, stride
, type
);
14265 if (value_tree
!= error_mark_node
)
14266 SET_EXPR_LOCATION (value_tree
, loc
);
14270 #include "gt-c-c-parser.h"