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"
59 #include "c-family/c-upc.h"
60 #include "c-family/c-upc-gasp.h"
61 #include "c-family/c-upc-pts-ops.h"
70 /* Initialization routine for this file. */
75 /* The only initialization required is of the reserved word
81 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
82 the c_token structure. */
83 gcc_assert (RID_MAX
<= 255);
90 mask
|= D_ASM
| D_EXT
;
94 if (!c_dialect_objc ())
95 mask
|= D_OBJC
| D_CXX_OBJC
;
100 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
101 for (i
= 0; i
< num_c_common_reswords
; i
++)
103 /* If a keyword is disabled, do not enter it into the table
104 and so create a canonical spelling that isn't a keyword. */
105 if (c_common_reswords
[i
].disable
& mask
)
108 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
110 id
= get_identifier (c_common_reswords
[i
].word
);
111 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
112 C_IS_RESERVED_WORD (id
) = 1;
117 id
= get_identifier (c_common_reswords
[i
].word
);
118 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
119 C_IS_RESERVED_WORD (id
) = 1;
120 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
124 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
125 and the C parser. Unlike the C++ lexer, the parser structure
126 stores the lexer information instead of using a separate structure.
127 Identifiers are separated into ordinary identifiers, type names,
128 keywords and some other Objective-C types of identifiers, and some
129 look-ahead is maintained.
131 ??? It might be a good idea to lex the whole file up front (as for
132 C++). It would then be possible to share more of the C and C++
133 lexer code, if desired. */
135 /* The following local token type is used. */
138 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
140 /* More information about the type of a CPP_NAME token. */
141 typedef enum c_id_kind
{
142 /* An ordinary identifier. */
144 /* An identifier declared as a typedef name. */
146 /* An identifier declared as an Objective-C class name. */
148 /* An address space identifier. */
150 /* Not an identifier. */
154 /* A single C token after string literal concatenation and conversion
155 of preprocessing tokens to tokens. */
156 typedef struct GTY (()) c_token
{
157 /* The kind of token. */
158 ENUM_BITFIELD (cpp_ttype
) type
: 8;
159 /* If this token is a CPP_NAME, this value indicates whether also
160 declared as some kind of type. Otherwise, it is C_ID_NONE. */
161 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
162 /* If this token is a keyword, this value indicates which keyword.
163 Otherwise, this value is RID_MAX. */
164 ENUM_BITFIELD (rid
) keyword
: 8;
165 /* If this token is a CPP_PRAGMA, this indicates the pragma that
166 was seen. Otherwise it is PRAGMA_NONE. */
167 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
168 /* The location at which this token was found. */
170 /* The value associated with this token, if any. */
174 /* A parser structure recording information about the state and
175 context of parsing. Includes lexer information with up to two
176 tokens of look-ahead; more are not needed for C. */
177 typedef struct GTY(()) c_parser
{
178 /* The look-ahead tokens. */
179 c_token
* GTY((skip
)) tokens
;
180 /* Buffer for look-ahead tokens. */
181 c_token tokens_buf
[2];
182 /* How many look-ahead tokens are available (0, 1 or 2, or
183 more if parsing from pre-lexed tokens). */
184 unsigned int tokens_avail
;
185 /* True if a syntax error is being recovered from; false otherwise.
186 c_parser_error sets this flag. It should clear this flag when
187 enough tokens have been consumed to recover from the error. */
188 BOOL_BITFIELD error
: 1;
189 /* True if we're processing a pragma, and shouldn't automatically
190 consume CPP_PRAGMA_EOL. */
191 BOOL_BITFIELD in_pragma
: 1;
192 /* True if we're parsing the outermost block of an if statement. */
193 BOOL_BITFIELD in_if_block
: 1;
194 /* True if we want to lex an untranslated string. */
195 BOOL_BITFIELD lex_untranslated_string
: 1;
197 /* Objective-C specific parser/lexer information. */
199 /* True if we are in a context where the Objective-C "PQ" keywords
200 are considered keywords. */
201 BOOL_BITFIELD objc_pq_context
: 1;
202 /* True if we are parsing a (potential) Objective-C foreach
203 statement. This is set to true after we parsed 'for (' and while
204 we wait for 'in' or ';' to decide if it's a standard C for loop or an
205 Objective-C foreach loop. */
206 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
207 /* The following flag is needed to contextualize Objective-C lexical
208 analysis. In some cases (e.g., 'int NSObject;'), it is
209 undesirable to bind an identifier to an Objective-C class, even
210 if a class with that name exists. */
211 BOOL_BITFIELD objc_need_raw_identifier
: 1;
212 /* Nonzero if we're processing a __transaction statement. The value
213 is 1 | TM_STMT_ATTR_*. */
214 unsigned int in_transaction
: 4;
215 /* True if we are in a context where the Objective-C "Property attribute"
216 keywords are valid. */
217 BOOL_BITFIELD objc_property_attr_context
: 1;
219 /* Cilk Plus specific parser/lexer information. */
221 /* Buffer to hold all the tokens from parsing the vector attribute for the
222 SIMD-enabled functions (formerly known as elemental functions). */
223 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
227 /* The actual parser and external interface. ??? Does this need to be
228 garbage-collected? */
230 static GTY (()) c_parser
*the_parser
;
232 /* Read in and lex a single token, storing it in *TOKEN. */
235 c_lex_one_token (c_parser
*parser
, c_token
*token
)
237 timevar_push (TV_LEX
);
239 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
240 (parser
->lex_untranslated_string
241 ? C_LEX_STRING_NO_TRANSLATE
: 0));
242 token
->id_kind
= C_ID_NONE
;
243 token
->keyword
= RID_MAX
;
244 token
->pragma_kind
= PRAGMA_NONE
;
252 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
253 if (c_dialect_objc ())
254 parser
->objc_need_raw_identifier
= false;
256 if (C_IS_RESERVED_WORD (token
->value
))
258 enum rid rid_code
= C_RID_CODE (token
->value
);
260 if (rid_code
== RID_CXX_COMPAT_WARN
)
262 warning_at (token
->location
,
264 "identifier %qE conflicts with C++ keyword",
267 else if (rid_code
>= RID_FIRST_ADDR_SPACE
268 && rid_code
<= RID_LAST_ADDR_SPACE
)
270 token
->id_kind
= C_ID_ADDRSPACE
;
271 token
->keyword
= rid_code
;
274 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
276 /* We found an Objective-C "pq" keyword (in, out,
277 inout, bycopy, byref, oneway). They need special
278 care because the interpretation depends on the
280 if (parser
->objc_pq_context
)
282 token
->type
= CPP_KEYWORD
;
283 token
->keyword
= rid_code
;
286 else if (parser
->objc_could_be_foreach_context
287 && rid_code
== RID_IN
)
289 /* We are in Objective-C, inside a (potential)
290 foreach context (which means after having
291 parsed 'for (', but before having parsed ';'),
292 and we found 'in'. We consider it the keyword
293 which terminates the declaration at the
294 beginning of a foreach-statement. Note that
295 this means you can't use 'in' for anything else
296 in that context; in particular, in Objective-C
297 you can't use 'in' as the name of the running
298 variable in a C for loop. We could potentially
299 try to add code here to disambiguate, but it
300 seems a reasonable limitation. */
301 token
->type
= CPP_KEYWORD
;
302 token
->keyword
= rid_code
;
305 /* Else, "pq" keywords outside of the "pq" context are
306 not keywords, and we fall through to the code for
309 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
311 /* We found an Objective-C "property attribute"
312 keyword (getter, setter, readonly, etc). These are
313 only valid in the property context. */
314 if (parser
->objc_property_attr_context
)
316 token
->type
= CPP_KEYWORD
;
317 token
->keyword
= rid_code
;
320 /* Else they are not special keywords.
323 else if (c_dialect_objc ()
324 && (OBJC_IS_AT_KEYWORD (rid_code
)
325 || OBJC_IS_CXX_KEYWORD (rid_code
)))
327 /* We found one of the Objective-C "@" keywords (defs,
328 selector, synchronized, etc) or one of the
329 Objective-C "cxx" keywords (class, private,
330 protected, public, try, catch, throw) without a
331 preceding '@' sign. Do nothing and fall through to
332 the code for normal tokens (in C++ we would still
333 consider the CXX ones keywords, but not in C). */
338 token
->type
= CPP_KEYWORD
;
339 token
->keyword
= rid_code
;
344 decl
= lookup_name (token
->value
);
347 if (TREE_CODE (decl
) == TYPE_DECL
)
349 token
->id_kind
= C_ID_TYPENAME
;
353 else if (c_dialect_objc ())
355 tree objc_interface_decl
= objc_is_class_name (token
->value
);
356 /* Objective-C class names are in the same namespace as
357 variables and typedefs, and hence are shadowed by local
359 if (objc_interface_decl
360 && (!objc_force_identifier
|| global_bindings_p ()))
362 token
->value
= objc_interface_decl
;
363 token
->id_kind
= C_ID_CLASSNAME
;
367 token
->id_kind
= C_ID_ID
;
371 /* This only happens in Objective-C; it must be a keyword. */
372 token
->type
= CPP_KEYWORD
;
373 switch (C_RID_CODE (token
->value
))
375 /* Replace 'class' with '@class', 'private' with '@private',
376 etc. This prevents confusion with the C++ keyword
377 'class', and makes the tokens consistent with other
378 Objective-C 'AT' keywords. For example '@class' is
379 reported as RID_AT_CLASS which is consistent with
380 '@synchronized', which is reported as
383 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
384 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
385 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
386 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
387 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
388 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
389 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
390 default: token
->keyword
= C_RID_CODE (token
->value
);
395 case CPP_CLOSE_PAREN
:
397 /* These tokens may affect the interpretation of any identifiers
398 following, if doing Objective-C. */
399 if (c_dialect_objc ())
400 parser
->objc_need_raw_identifier
= false;
403 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
404 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
410 timevar_pop (TV_LEX
);
413 /* Return a pointer to the next token from PARSER, reading it in if
416 static inline c_token
*
417 c_parser_peek_token (c_parser
*parser
)
419 if (parser
->tokens_avail
== 0)
421 c_lex_one_token (parser
, &parser
->tokens
[0]);
422 parser
->tokens_avail
= 1;
424 return &parser
->tokens
[0];
427 /* Return true if the next token from PARSER has the indicated
431 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
433 return c_parser_peek_token (parser
)->type
== type
;
436 /* Return true if the next token from PARSER does not have the
440 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
442 return !c_parser_next_token_is (parser
, type
);
445 /* Return true if the next token from PARSER is the indicated
449 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
451 return c_parser_peek_token (parser
)->keyword
== keyword
;
454 /* Return a pointer to the next-but-one token from PARSER, reading it
455 in if necessary. The next token is already read in. */
458 c_parser_peek_2nd_token (c_parser
*parser
)
460 if (parser
->tokens_avail
>= 2)
461 return &parser
->tokens
[1];
462 gcc_assert (parser
->tokens_avail
== 1);
463 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
464 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
465 c_lex_one_token (parser
, &parser
->tokens
[1]);
466 parser
->tokens_avail
= 2;
467 return &parser
->tokens
[1];
470 /* Return true if TOKEN can start a type name,
473 c_token_starts_typename (c_token
*token
)
478 switch (token
->id_kind
)
487 gcc_assert (c_dialect_objc ());
493 switch (token
->keyword
)
533 if (c_dialect_objc ())
541 enum c_lookahead_kind
{
542 /* Always treat unknown identifiers as typenames. */
545 /* Could be parsing a nonabstract declarator. Only treat an identifier
546 as a typename if followed by another identifier or a star. */
547 cla_nonabstract_decl
,
549 /* Never treat identifiers as typenames. */
553 /* Return true if the next token from PARSER can start a type name,
554 false otherwise. LA specifies how to do lookahead in order to
555 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
558 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
560 c_token
*token
= c_parser_peek_token (parser
);
561 if (c_token_starts_typename (token
))
564 /* Try a bit harder to detect an unknown typename. */
565 if (la
!= cla_prefer_id
566 && token
->type
== CPP_NAME
567 && token
->id_kind
== C_ID_ID
569 /* Do not try too hard when we could have "object in array". */
570 && !parser
->objc_could_be_foreach_context
572 && (la
== cla_prefer_type
573 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
574 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
576 /* Only unknown identifiers. */
577 && !lookup_name (token
->value
))
583 /* Return true if TOKEN is a type qualifier, false otherwise. */
585 c_token_is_qualifier (c_token
*token
)
590 switch (token
->id_kind
)
598 switch (token
->keyword
)
621 /* Return true if the next token from PARSER is a type qualifier,
624 c_parser_next_token_is_qualifier (c_parser
*parser
)
626 c_token
*token
= c_parser_peek_token (parser
);
627 return c_token_is_qualifier (token
);
630 /* Return true if TOKEN can start declaration specifiers, false
633 c_token_starts_declspecs (c_token
*token
)
638 switch (token
->id_kind
)
647 gcc_assert (c_dialect_objc ());
653 switch (token
->keyword
)
702 if (c_dialect_objc ())
711 /* Return true if TOKEN can start declaration specifiers or a static
712 assertion, false otherwise. */
714 c_token_starts_declaration (c_token
*token
)
716 if (c_token_starts_declspecs (token
)
717 || token
->keyword
== RID_STATIC_ASSERT
)
723 /* Return true if the next token from PARSER can start declaration
724 specifiers, false otherwise. */
726 c_parser_next_token_starts_declspecs (c_parser
*parser
)
728 c_token
*token
= c_parser_peek_token (parser
);
730 /* In Objective-C, a classname normally starts a declspecs unless it
731 is immediately followed by a dot. In that case, it is the
732 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
733 setter/getter on the class. c_token_starts_declspecs() can't
734 differentiate between the two cases because it only checks the
735 current token, so we have a special check here. */
736 if (c_dialect_objc ()
737 && token
->type
== CPP_NAME
738 && token
->id_kind
== C_ID_CLASSNAME
739 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
742 return c_token_starts_declspecs (token
);
745 /* Return true if the next tokens from PARSER can start declaration
746 specifiers or a static assertion, false otherwise. */
748 c_parser_next_tokens_start_declaration (c_parser
*parser
)
750 c_token
*token
= c_parser_peek_token (parser
);
753 if (c_dialect_objc ()
754 && token
->type
== CPP_NAME
755 && token
->id_kind
== C_ID_CLASSNAME
756 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
759 /* Labels do not start declarations. */
760 if (token
->type
== CPP_NAME
761 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
764 if (c_token_starts_declaration (token
))
767 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
773 /* Consume the next token from PARSER. */
776 c_parser_consume_token (c_parser
*parser
)
778 gcc_assert (parser
->tokens_avail
>= 1);
779 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
780 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
781 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
782 if (parser
->tokens
!= &parser
->tokens_buf
[0])
784 else if (parser
->tokens_avail
== 2)
785 parser
->tokens
[0] = parser
->tokens
[1];
786 parser
->tokens_avail
--;
789 /* Expect the current token to be a #pragma. Consume it and remember
790 that we've begun parsing a pragma. */
793 c_parser_consume_pragma (c_parser
*parser
)
795 gcc_assert (!parser
->in_pragma
);
796 gcc_assert (parser
->tokens_avail
>= 1);
797 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
798 if (parser
->tokens
!= &parser
->tokens_buf
[0])
800 else if (parser
->tokens_avail
== 2)
801 parser
->tokens
[0] = parser
->tokens
[1];
802 parser
->tokens_avail
--;
803 parser
->in_pragma
= true;
806 /* Update the global input_location from TOKEN. */
808 c_parser_set_source_position_from_token (c_token
*token
)
810 if (token
->type
!= CPP_EOF
)
812 input_location
= token
->location
;
816 /* Issue a diagnostic of the form
817 FILE:LINE: MESSAGE before TOKEN
818 where TOKEN is the next token in the input stream of PARSER.
819 MESSAGE (specified by the caller) is usually of the form "expected
822 Do not issue a diagnostic if still recovering from an error.
824 ??? This is taken from the C++ parser, but building up messages in
825 this way is not i18n-friendly and some other approach should be
829 c_parser_error (c_parser
*parser
, const char *gmsgid
)
831 c_token
*token
= c_parser_peek_token (parser
);
834 parser
->error
= true;
837 /* This diagnostic makes more sense if it is tagged to the line of
838 the token we just peeked at. */
839 c_parser_set_source_position_from_token (token
);
840 c_parse_error (gmsgid
,
841 /* Because c_parse_error does not understand
842 CPP_KEYWORD, keywords are treated like
844 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
845 /* ??? The C parser does not save the cpp flags of a
846 token, we need to pass 0 here and we will not get
847 the source spelling of some tokens but rather the
848 canonical spelling. */
849 token
->value
, /*flags=*/0);
852 /* If the next token is of the indicated TYPE, consume it. Otherwise,
853 issue the error MSGID. If MSGID is NULL then a message has already
854 been produced and no message will be produced this time. Returns
855 true if found, false otherwise. */
858 c_parser_require (c_parser
*parser
,
862 if (c_parser_next_token_is (parser
, type
))
864 c_parser_consume_token (parser
);
869 c_parser_error (parser
, msgid
);
874 /* If the next token is the indicated keyword, consume it. Otherwise,
875 issue the error MSGID. Returns true if found, false otherwise. */
878 c_parser_require_keyword (c_parser
*parser
,
882 if (c_parser_next_token_is_keyword (parser
, keyword
))
884 c_parser_consume_token (parser
);
889 c_parser_error (parser
, msgid
);
894 /* Like c_parser_require, except that tokens will be skipped until the
895 desired token is found. An error message is still produced if the
896 next token is not as expected. If MSGID is NULL then a message has
897 already been produced and no message will be produced this
901 c_parser_skip_until_found (c_parser
*parser
,
905 unsigned nesting_depth
= 0;
907 if (c_parser_require (parser
, type
, msgid
))
910 /* Skip tokens until the desired token is found. */
913 /* Peek at the next token. */
914 c_token
*token
= c_parser_peek_token (parser
);
915 /* If we've reached the token we want, consume it and stop. */
916 if (token
->type
== type
&& !nesting_depth
)
918 c_parser_consume_token (parser
);
922 /* If we've run out of tokens, stop. */
923 if (token
->type
== CPP_EOF
)
925 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
927 if (token
->type
== CPP_OPEN_BRACE
928 || token
->type
== CPP_OPEN_PAREN
929 || token
->type
== CPP_OPEN_SQUARE
)
931 else if (token
->type
== CPP_CLOSE_BRACE
932 || token
->type
== CPP_CLOSE_PAREN
933 || token
->type
== CPP_CLOSE_SQUARE
)
935 if (nesting_depth
-- == 0)
938 /* Consume this token. */
939 c_parser_consume_token (parser
);
941 parser
->error
= false;
944 /* Skip tokens until the end of a parameter is found, but do not
945 consume the comma, semicolon or closing delimiter. */
948 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
950 unsigned nesting_depth
= 0;
954 c_token
*token
= c_parser_peek_token (parser
);
955 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
958 /* If we've run out of tokens, stop. */
959 if (token
->type
== CPP_EOF
)
961 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
963 if (token
->type
== CPP_OPEN_BRACE
964 || token
->type
== CPP_OPEN_PAREN
965 || token
->type
== CPP_OPEN_SQUARE
)
967 else if (token
->type
== CPP_CLOSE_BRACE
968 || token
->type
== CPP_CLOSE_PAREN
969 || token
->type
== CPP_CLOSE_SQUARE
)
971 if (nesting_depth
-- == 0)
974 /* Consume this token. */
975 c_parser_consume_token (parser
);
977 parser
->error
= false;
980 /* Expect to be at the end of the pragma directive and consume an
981 end of line marker. */
984 c_parser_skip_to_pragma_eol (c_parser
*parser
)
986 gcc_assert (parser
->in_pragma
);
987 parser
->in_pragma
= false;
989 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
992 c_token
*token
= c_parser_peek_token (parser
);
993 if (token
->type
== CPP_EOF
)
995 if (token
->type
== CPP_PRAGMA_EOL
)
997 c_parser_consume_token (parser
);
1000 c_parser_consume_token (parser
);
1003 parser
->error
= false;
1006 /* Skip tokens until we have consumed an entire block, or until we
1007 have consumed a non-nested ';'. */
1010 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1012 unsigned nesting_depth
= 0;
1013 bool save_error
= parser
->error
;
1019 /* Peek at the next token. */
1020 token
= c_parser_peek_token (parser
);
1022 switch (token
->type
)
1027 case CPP_PRAGMA_EOL
:
1028 if (parser
->in_pragma
)
1033 /* If the next token is a ';', we have reached the
1034 end of the statement. */
1037 /* Consume the ';'. */
1038 c_parser_consume_token (parser
);
1043 case CPP_CLOSE_BRACE
:
1044 /* If the next token is a non-nested '}', then we have
1045 reached the end of the current block. */
1046 if (nesting_depth
== 0 || --nesting_depth
== 0)
1048 c_parser_consume_token (parser
);
1053 case CPP_OPEN_BRACE
:
1054 /* If it the next token is a '{', then we are entering a new
1055 block. Consume the entire block. */
1060 /* If we see a pragma, consume the whole thing at once. We
1061 have some safeguards against consuming pragmas willy-nilly.
1062 Normally, we'd expect to be here with parser->error set,
1063 which disables these safeguards. But it's possible to get
1064 here for secondary error recovery, after parser->error has
1066 c_parser_consume_pragma (parser
);
1067 c_parser_skip_to_pragma_eol (parser
);
1068 parser
->error
= save_error
;
1075 c_parser_consume_token (parser
);
1079 parser
->error
= false;
1082 /* CPP's options (initialized by c-opts.c). */
1083 extern cpp_options
*cpp_opts
;
1085 /* Save the warning flags which are controlled by __extension__. */
1088 disable_extension_diagnostics (void)
1091 | (warn_pointer_arith
<< 1)
1092 | (warn_traditional
<< 2)
1094 | (warn_long_long
<< 4)
1095 | (warn_cxx_compat
<< 5)
1096 | (warn_overlength_strings
<< 6));
1097 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1098 warn_pointer_arith
= 0;
1099 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1101 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1102 warn_cxx_compat
= 0;
1103 warn_overlength_strings
= 0;
1107 /* Restore the warning flags which are controlled by __extension__.
1108 FLAGS is the return value from disable_extension_diagnostics. */
1111 restore_extension_diagnostics (int flags
)
1113 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1114 warn_pointer_arith
= (flags
>> 1) & 1;
1115 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1116 flag_iso
= (flags
>> 3) & 1;
1117 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1118 warn_cxx_compat
= (flags
>> 5) & 1;
1119 warn_overlength_strings
= (flags
>> 6) & 1;
1122 /* Possibly kinds of declarator to parse. */
1123 typedef enum c_dtr_syn
{
1124 /* A normal declarator with an identifier. */
1126 /* An abstract declarator (maybe empty). */
1128 /* A parameter declarator: may be either, but after a type name does
1129 not redeclare a typedef name as an identifier if it can
1130 alternatively be interpreted as a typedef name; see DR#009,
1131 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1132 following DR#249. For example, given a typedef T, "int T" and
1133 "int *T" are valid parameter declarations redeclaring T, while
1134 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1135 abstract declarators rather than involving redundant parentheses;
1136 the same applies with attributes inside the parentheses before
1141 /* The binary operation precedence levels, where 0 is a dummy lowest level
1142 used for the bottom of the stack. */
1143 enum c_parser_prec
{
1158 static void c_parser_external_declaration (c_parser
*);
1159 static void c_parser_asm_definition (c_parser
*);
1160 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1161 bool, bool, tree
*, vec
<c_token
>);
1162 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1163 static void c_parser_static_assert_declaration (c_parser
*);
1164 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1165 bool, bool, bool, enum c_lookahead_kind
);
1166 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1167 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1168 static tree
c_parser_struct_declaration (c_parser
*);
1169 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1170 static tree
c_parser_alignas_specifier (c_parser
*);
1171 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1173 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1175 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1177 struct c_declarator
*);
1178 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1179 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1181 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1182 static tree
c_parser_simple_asm_expr (c_parser
*);
1183 static tree
c_parser_attributes (c_parser
*);
1184 static struct c_type_name
*c_parser_type_name (c_parser
*);
1185 static struct c_expr
c_parser_initializer (c_parser
*);
1186 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1187 static void c_parser_initelt (c_parser
*, struct obstack
*);
1188 static void c_parser_initval (c_parser
*, struct c_expr
*,
1190 static tree
c_parser_compound_statement (c_parser
*);
1191 static void c_parser_compound_statement_nostart (c_parser
*);
1192 static void c_parser_label (c_parser
*);
1193 static void c_parser_statement (c_parser
*);
1194 static void c_parser_statement_after_labels (c_parser
*);
1195 static void c_parser_if_statement (c_parser
*);
1196 static void c_parser_switch_statement (c_parser
*);
1197 static void c_parser_while_statement (c_parser
*, bool);
1198 static void c_parser_do_statement (c_parser
*, bool);
1199 static void c_parser_for_statement (c_parser
*, bool);
1200 static tree
c_parser_asm_statement (c_parser
*);
1201 static tree
c_parser_asm_operands (c_parser
*);
1202 static tree
c_parser_asm_goto_operands (c_parser
*);
1203 static tree
c_parser_asm_clobbers (c_parser
*);
1204 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1206 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1207 struct c_expr
*, tree
);
1208 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1210 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1211 static struct c_expr
c_parser_unary_expression (c_parser
*);
1212 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1213 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1214 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1215 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1216 struct c_type_name
*,
1218 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1221 static tree
c_parser_transaction (c_parser
*, enum rid
);
1222 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1223 static tree
c_parser_transaction_cancel (c_parser
*);
1224 static struct c_expr
c_parser_expression (c_parser
*);
1225 static struct c_expr
c_parser_expression_conv (c_parser
*);
1226 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1227 vec
<tree
, va_gc
> **, location_t
*,
1228 tree
*, vec
<location_t
> *);
1229 static void c_parser_omp_construct (c_parser
*);
1230 static void c_parser_omp_threadprivate (c_parser
*);
1231 static void c_parser_omp_barrier (c_parser
*);
1232 static void c_parser_omp_flush (c_parser
*);
1233 static void c_parser_omp_taskwait (c_parser
*);
1234 static void c_parser_omp_taskyield (c_parser
*);
1235 static void c_parser_omp_cancel (c_parser
*);
1236 static void c_parser_omp_cancellation_point (c_parser
*);
1238 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1239 pragma_stmt
, pragma_compound
};
1240 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1241 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1242 static void c_parser_omp_end_declare_target (c_parser
*);
1243 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1245 /* These Objective-C parser functions are only ever called when
1246 compiling Objective-C. */
1247 static void c_parser_objc_class_definition (c_parser
*, tree
);
1248 static void c_parser_objc_class_instance_variables (c_parser
*);
1249 static void c_parser_objc_class_declaration (c_parser
*);
1250 static void c_parser_objc_alias_declaration (c_parser
*);
1251 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1252 static bool c_parser_objc_method_type (c_parser
*);
1253 static void c_parser_objc_method_definition (c_parser
*);
1254 static void c_parser_objc_methodprotolist (c_parser
*);
1255 static void c_parser_objc_methodproto (c_parser
*);
1256 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1257 static tree
c_parser_objc_type_name (c_parser
*);
1258 static tree
c_parser_objc_protocol_refs (c_parser
*);
1259 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1260 static void c_parser_objc_synchronized_statement (c_parser
*);
1261 static tree
c_parser_objc_selector (c_parser
*);
1262 static tree
c_parser_objc_selector_arg (c_parser
*);
1263 static tree
c_parser_objc_receiver (c_parser
*);
1264 static tree
c_parser_objc_message_args (c_parser
*);
1265 static tree
c_parser_objc_keywordexpr (c_parser
*);
1266 static void c_parser_objc_at_property_declaration (c_parser
*);
1267 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1268 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1269 static bool c_parser_objc_diagnose_bad_element_prefix
1270 (c_parser
*, struct c_declspecs
*);
1272 /* Cilk Plus supporting routines. */
1273 static void c_parser_cilk_simd (c_parser
*);
1274 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1275 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1276 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1278 /* These UPC parser functions are only ever called when
1280 static void c_parser_upc_forall_statement (c_parser
*);
1281 static void c_parser_upc_sync_statement (c_parser
*, int);
1282 static void c_parser_upc_shared_qual (source_location
,
1284 struct c_declspecs
*);
1286 /* Parse a translation unit (C90 6.7, C99 6.9).
1289 external-declarations
1291 external-declarations:
1292 external-declaration
1293 external-declarations external-declaration
1302 c_parser_translation_unit (c_parser
*parser
)
1304 if (c_parser_next_token_is (parser
, CPP_EOF
))
1306 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1307 "ISO C forbids an empty translation unit");
1311 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1312 mark_valid_location_for_stdc_pragma (false);
1316 c_parser_external_declaration (parser
);
1317 obstack_free (&parser_obstack
, obstack_position
);
1319 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1323 /* Parse an external declaration (C90 6.7, C99 6.9).
1325 external-declaration:
1331 external-declaration:
1334 __extension__ external-declaration
1338 external-declaration:
1339 objc-class-definition
1340 objc-class-declaration
1341 objc-alias-declaration
1342 objc-protocol-definition
1343 objc-method-definition
1348 c_parser_external_declaration (c_parser
*parser
)
1351 switch (c_parser_peek_token (parser
)->type
)
1354 switch (c_parser_peek_token (parser
)->keyword
)
1357 ext
= disable_extension_diagnostics ();
1358 c_parser_consume_token (parser
);
1359 c_parser_external_declaration (parser
);
1360 restore_extension_diagnostics (ext
);
1363 c_parser_asm_definition (parser
);
1365 case RID_AT_INTERFACE
:
1366 case RID_AT_IMPLEMENTATION
:
1367 gcc_assert (c_dialect_objc ());
1368 c_parser_objc_class_definition (parser
, NULL_TREE
);
1371 gcc_assert (c_dialect_objc ());
1372 c_parser_objc_class_declaration (parser
);
1375 gcc_assert (c_dialect_objc ());
1376 c_parser_objc_alias_declaration (parser
);
1378 case RID_AT_PROTOCOL
:
1379 gcc_assert (c_dialect_objc ());
1380 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1382 case RID_AT_PROPERTY
:
1383 gcc_assert (c_dialect_objc ());
1384 c_parser_objc_at_property_declaration (parser
);
1386 case RID_AT_SYNTHESIZE
:
1387 gcc_assert (c_dialect_objc ());
1388 c_parser_objc_at_synthesize_declaration (parser
);
1390 case RID_AT_DYNAMIC
:
1391 gcc_assert (c_dialect_objc ());
1392 c_parser_objc_at_dynamic_declaration (parser
);
1395 gcc_assert (c_dialect_objc ());
1396 c_parser_consume_token (parser
);
1397 objc_finish_implementation ();
1404 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1405 "ISO C does not allow extra %<;%> outside of a function");
1406 c_parser_consume_token (parser
);
1409 mark_valid_location_for_stdc_pragma (true);
1410 c_parser_pragma (parser
, pragma_external
);
1411 mark_valid_location_for_stdc_pragma (false);
1415 if (c_dialect_objc ())
1417 c_parser_objc_method_definition (parser
);
1420 /* Else fall through, and yield a syntax error trying to parse
1421 as a declaration or function definition. */
1424 /* A declaration or a function definition (or, in Objective-C,
1425 an @interface or @protocol with prefix attributes). We can
1426 only tell which after parsing the declaration specifiers, if
1427 any, and the first declarator. */
1428 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1434 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1436 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1437 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1438 accepted; otherwise (old-style parameter declarations) only other
1439 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1440 assertion is accepted; otherwise (old-style parameter declarations)
1441 it is not. If NESTED is true, we are inside a function or parsing
1442 old-style parameter declarations; any functions encountered are
1443 nested functions and declaration specifiers are required; otherwise
1444 we are at top level and functions are normal functions and
1445 declaration specifiers may be optional. If EMPTY_OK is true, empty
1446 declarations are OK (subject to all other constraints); otherwise
1447 (old-style parameter declarations) they are diagnosed. If
1448 START_ATTR_OK is true, the declaration specifiers may start with
1449 attributes; otherwise they may not.
1450 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1451 declaration when parsing an Objective-C foreach statement.
1454 declaration-specifiers init-declarator-list[opt] ;
1455 static_assert-declaration
1457 function-definition:
1458 declaration-specifiers[opt] declarator declaration-list[opt]
1463 declaration-list declaration
1465 init-declarator-list:
1467 init-declarator-list , init-declarator
1470 declarator simple-asm-expr[opt] attributes[opt]
1471 declarator simple-asm-expr[opt] attributes[opt] = initializer
1475 nested-function-definition:
1476 declaration-specifiers declarator declaration-list[opt]
1480 attributes objc-class-definition
1481 attributes objc-category-definition
1482 attributes objc-protocol-definition
1484 The simple-asm-expr and attributes are GNU extensions.
1486 This function does not handle __extension__; that is handled in its
1487 callers. ??? Following the old parser, __extension__ may start
1488 external declarations, declarations in functions and declarations
1489 at the start of "for" loops, but not old-style parameter
1492 C99 requires declaration specifiers in a function definition; the
1493 absence is diagnosed through the diagnosis of implicit int. In GNU
1494 C we also allow but diagnose declarations without declaration
1495 specifiers, but only at top level (elsewhere they conflict with
1498 In Objective-C, declarations of the looping variable in a foreach
1499 statement are exceptionally terminated by 'in' (for example, 'for
1500 (NSObject *object in array) { ... }').
1505 threadprivate-directive */
1508 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1509 bool static_assert_ok
, bool empty_ok
,
1510 bool nested
, bool start_attr_ok
,
1511 tree
*objc_foreach_object_declaration
,
1512 vec
<c_token
> omp_declare_simd_clauses
)
1514 struct c_declspecs
*specs
;
1516 tree all_prefix_attrs
;
1517 bool diagnosed_no_specs
= false;
1518 location_t here
= c_parser_peek_token (parser
)->location
;
1520 if (static_assert_ok
1521 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1523 c_parser_static_assert_declaration (parser
);
1526 specs
= build_null_declspecs ();
1528 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1529 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1530 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1531 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1532 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1533 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1535 error_at (here
, "unknown type name %qE",
1536 c_parser_peek_token (parser
)->value
);
1538 /* Parse declspecs normally to get a correct pointer type, but avoid
1539 a further "fails to be a type name" error. Refuse nested functions
1540 since it is not how the user likely wants us to recover. */
1541 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1542 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1543 c_parser_peek_token (parser
)->value
= error_mark_node
;
1547 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1548 true, true, cla_nonabstract_decl
);
1551 c_parser_skip_to_end_of_block_or_statement (parser
);
1554 if (nested
&& !specs
->declspecs_seen_p
)
1556 c_parser_error (parser
, "expected declaration specifiers");
1557 c_parser_skip_to_end_of_block_or_statement (parser
);
1560 finish_declspecs (specs
);
1561 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1562 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1565 error_at (here
, "%<__auto_type%> in empty declaration");
1570 shadow_tag_warned (specs
, 1);
1571 pedwarn (here
, 0, "empty declaration");
1573 c_parser_consume_token (parser
);
1577 /* Provide better error recovery. Note that a type name here is usually
1578 better diagnosed as a redeclaration. */
1580 && specs
->typespec_kind
== ctsk_tagdef
1581 && c_parser_next_token_starts_declspecs (parser
)
1582 && !c_parser_next_token_is (parser
, CPP_NAME
))
1584 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1585 parser
->error
= false;
1586 shadow_tag_warned (specs
, 1);
1589 else if (c_dialect_objc () && !auto_type_p
)
1591 /* Prefix attributes are an error on method decls. */
1592 switch (c_parser_peek_token (parser
)->type
)
1596 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1600 warning_at (c_parser_peek_token (parser
)->location
,
1602 "prefix attributes are ignored for methods");
1603 specs
->attrs
= NULL_TREE
;
1606 c_parser_objc_method_definition (parser
);
1608 c_parser_objc_methodproto (parser
);
1614 /* This is where we parse 'attributes @interface ...',
1615 'attributes @implementation ...', 'attributes @protocol ...'
1616 (where attributes could be, for example, __attribute__
1619 switch (c_parser_peek_token (parser
)->keyword
)
1621 case RID_AT_INTERFACE
:
1623 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1625 c_parser_objc_class_definition (parser
, specs
->attrs
);
1629 case RID_AT_IMPLEMENTATION
:
1631 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1635 warning_at (c_parser_peek_token (parser
)->location
,
1637 "prefix attributes are ignored for implementations");
1638 specs
->attrs
= NULL_TREE
;
1640 c_parser_objc_class_definition (parser
, NULL_TREE
);
1644 case RID_AT_PROTOCOL
:
1646 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1648 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1655 case RID_AT_PROPERTY
:
1658 c_parser_error (parser
, "unexpected attribute");
1659 specs
->attrs
= NULL
;
1667 pending_xref_error ();
1668 prefix_attrs
= specs
->attrs
;
1669 all_prefix_attrs
= prefix_attrs
;
1670 specs
->attrs
= NULL_TREE
;
1673 struct c_declarator
*declarator
;
1677 /* Declaring either one or more declarators (in which case we
1678 should diagnose if there were no declaration specifiers) or a
1679 function definition (in which case the diagnostic for
1680 implicit int suffices). */
1681 declarator
= c_parser_declarator (parser
,
1682 specs
->typespec_kind
!= ctsk_none
,
1683 C_DTR_NORMAL
, &dummy
);
1684 if (declarator
== NULL
)
1686 if (omp_declare_simd_clauses
.exists ()
1687 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1688 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1689 omp_declare_simd_clauses
);
1690 c_parser_skip_to_end_of_block_or_statement (parser
);
1693 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1696 "%<__auto_type%> requires a plain identifier"
1698 c_parser_skip_to_end_of_block_or_statement (parser
);
1701 if (c_parser_next_token_is (parser
, CPP_EQ
)
1702 || c_parser_next_token_is (parser
, CPP_COMMA
)
1703 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1704 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1705 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1706 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1708 tree asm_name
= NULL_TREE
;
1709 tree postfix_attrs
= NULL_TREE
;
1710 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1712 diagnosed_no_specs
= true;
1713 pedwarn (here
, 0, "data definition has no type or storage class");
1715 /* Having seen a data definition, there cannot now be a
1716 function definition. */
1718 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1719 asm_name
= c_parser_simple_asm_expr (parser
);
1720 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1721 postfix_attrs
= c_parser_attributes (parser
);
1722 if (c_parser_next_token_is (parser
, CPP_EQ
))
1726 location_t init_loc
;
1727 c_parser_consume_token (parser
);
1730 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1731 init_loc
= c_parser_peek_token (parser
)->location
;
1732 init
= c_parser_expr_no_commas (parser
, NULL
);
1733 if (TREE_CODE (init
.value
) == COMPONENT_REF
1734 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1736 "%<__auto_type%> used with a bit-field"
1738 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1739 tree init_type
= TREE_TYPE (init
.value
);
1740 /* As with typeof, remove _Atomic and const
1741 qualifiers from atomic types. */
1742 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1744 = c_build_qualified_type (init_type
,
1745 (TYPE_QUALS (init_type
)
1746 & ~(TYPE_QUAL_ATOMIC
1747 | TYPE_QUAL_CONST
)));
1748 bool vm_type
= variably_modified_type_p (init_type
,
1751 init
.value
= c_save_expr (init
.value
);
1753 specs
->typespec_kind
= ctsk_typeof
;
1754 specs
->locations
[cdw_typedef
] = init_loc
;
1755 specs
->typedef_p
= true;
1756 specs
->type
= init_type
;
1759 bool maybe_const
= true;
1760 tree type_expr
= c_fully_fold (init
.value
, false,
1762 specs
->expr_const_operands
&= maybe_const
;
1764 specs
->expr
= build2 (COMPOUND_EXPR
,
1765 TREE_TYPE (type_expr
),
1766 specs
->expr
, type_expr
);
1768 specs
->expr
= type_expr
;
1770 d
= start_decl (declarator
, specs
, true,
1771 chainon (postfix_attrs
, all_prefix_attrs
));
1773 d
= error_mark_node
;
1774 if (omp_declare_simd_clauses
.exists ()
1775 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1776 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1777 omp_declare_simd_clauses
);
1781 /* The declaration of the variable is in effect while
1782 its initializer is parsed. */
1783 d
= start_decl (declarator
, specs
, true,
1784 chainon (postfix_attrs
, all_prefix_attrs
));
1786 d
= error_mark_node
;
1787 if (omp_declare_simd_clauses
.exists ()
1788 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1789 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1790 omp_declare_simd_clauses
);
1791 start_init (d
, asm_name
, global_bindings_p ());
1792 init_loc
= c_parser_peek_token (parser
)->location
;
1793 init
= c_parser_initializer (parser
);
1796 if (d
!= error_mark_node
)
1798 maybe_warn_string_init (TREE_TYPE (d
), init
);
1799 finish_decl (d
, init_loc
, init
.value
,
1800 init
.original_type
, asm_name
);
1808 "%<__auto_type%> requires an initialized "
1809 "data declaration");
1810 c_parser_skip_to_end_of_block_or_statement (parser
);
1813 tree d
= start_decl (declarator
, specs
, false,
1814 chainon (postfix_attrs
,
1816 if (omp_declare_simd_clauses
.exists ()
1817 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1819 tree parms
= NULL_TREE
;
1820 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1822 struct c_declarator
*ce
= declarator
;
1824 if (ce
->kind
== cdk_function
)
1826 parms
= ce
->u
.arg_info
->parms
;
1830 ce
= ce
->declarator
;
1833 temp_store_parm_decls (d
, parms
);
1834 c_finish_omp_declare_simd (parser
, d
, parms
,
1835 omp_declare_simd_clauses
);
1837 temp_pop_parm_decls ();
1840 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1841 NULL_TREE
, asm_name
);
1843 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1846 *objc_foreach_object_declaration
= d
;
1848 *objc_foreach_object_declaration
= error_mark_node
;
1851 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1856 "%<__auto_type%> may only be used with"
1857 " a single declarator");
1858 c_parser_skip_to_end_of_block_or_statement (parser
);
1861 c_parser_consume_token (parser
);
1862 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1863 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1866 all_prefix_attrs
= prefix_attrs
;
1869 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1871 c_parser_consume_token (parser
);
1874 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1876 /* This can only happen in Objective-C: we found the
1877 'in' that terminates the declaration inside an
1878 Objective-C foreach statement. Do not consume the
1879 token, so that the caller can use it to determine
1880 that this indeed is a foreach context. */
1885 c_parser_error (parser
, "expected %<,%> or %<;%>");
1886 c_parser_skip_to_end_of_block_or_statement (parser
);
1890 else if (auto_type_p
)
1893 "%<__auto_type%> requires an initialized data declaration");
1894 c_parser_skip_to_end_of_block_or_statement (parser
);
1899 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1900 "%<asm%> or %<__attribute__%>");
1901 c_parser_skip_to_end_of_block_or_statement (parser
);
1904 /* Function definition (nested or otherwise). */
1907 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1908 c_push_function_context ();
1910 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1912 /* This can appear in many cases looking nothing like a
1913 function definition, so we don't give a more specific
1914 error suggesting there was one. */
1915 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1916 "or %<__attribute__%>");
1918 c_pop_function_context ();
1922 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1923 tv
= TV_PARSE_INLINE
;
1928 /* Parse old-style parameter declarations. ??? Attributes are
1929 not allowed to start declaration specifiers here because of a
1930 syntax conflict between a function declaration with attribute
1931 suffix and a function definition with an attribute prefix on
1932 first old-style parameter declaration. Following the old
1933 parser, they are not accepted on subsequent old-style
1934 parameter declarations either. However, there is no
1935 ambiguity after the first declaration, nor indeed on the
1936 first as long as we don't allow postfix attributes after a
1937 declarator with a nonempty identifier list in a definition;
1938 and postfix attributes have never been accepted here in
1939 function definitions either. */
1940 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1941 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1942 c_parser_declaration_or_fndef (parser
, false, false, false,
1943 true, false, NULL
, vNULL
);
1944 store_parm_decls ();
1945 if (omp_declare_simd_clauses
.exists ()
1946 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1947 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1948 omp_declare_simd_clauses
);
1949 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1950 = c_parser_peek_token (parser
)->location
;
1951 fnbody
= c_parser_compound_statement (parser
);
1952 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1953 fnbody
= expand_array_notation_exprs (fnbody
);
1956 tree decl
= current_function_decl
;
1957 /* Mark nested functions as needing static-chain initially.
1958 lower_nested_functions will recompute it but the
1959 DECL_STATIC_CHAIN flag is also used before that happens,
1960 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1961 DECL_STATIC_CHAIN (decl
) = 1;
1964 c_pop_function_context ();
1965 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1978 /* Parse an asm-definition (asm() outside a function body). This is a
1986 c_parser_asm_definition (c_parser
*parser
)
1988 tree asm_str
= c_parser_simple_asm_expr (parser
);
1990 add_asm_node (asm_str
);
1991 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1994 /* Parse a static assertion (C11 6.7.10).
1996 static_assert-declaration:
1997 static_assert-declaration-no-semi ;
2001 c_parser_static_assert_declaration (c_parser
*parser
)
2003 c_parser_static_assert_declaration_no_semi (parser
);
2005 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2006 c_parser_skip_to_end_of_block_or_statement (parser
);
2009 /* Parse a static assertion (C11 6.7.10), without the trailing
2012 static_assert-declaration-no-semi:
2013 _Static_assert ( constant-expression , string-literal )
2017 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2019 location_t assert_loc
, value_loc
;
2023 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2024 assert_loc
= c_parser_peek_token (parser
)->location
;
2028 pedwarn (assert_loc
, OPT_Wpedantic
,
2029 "ISO C99 does not support %<_Static_assert%>");
2031 pedwarn (assert_loc
, OPT_Wpedantic
,
2032 "ISO C90 does not support %<_Static_assert%>");
2034 c_parser_consume_token (parser
);
2035 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2037 value_loc
= c_parser_peek_token (parser
)->location
;
2038 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2039 parser
->lex_untranslated_string
= true;
2040 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2042 parser
->lex_untranslated_string
= false;
2045 switch (c_parser_peek_token (parser
)->type
)
2051 case CPP_UTF8STRING
:
2052 string
= c_parser_peek_token (parser
)->value
;
2053 c_parser_consume_token (parser
);
2054 parser
->lex_untranslated_string
= false;
2057 c_parser_error (parser
, "expected string literal");
2058 parser
->lex_untranslated_string
= false;
2061 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2063 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2065 error_at (value_loc
, "expression in static assertion is not an integer");
2068 if (TREE_CODE (value
) != INTEGER_CST
)
2070 value
= c_fully_fold (value
, false, NULL
);
2071 if (TREE_CODE (value
) == INTEGER_CST
)
2072 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2073 "is not an integer constant expression");
2075 if (TREE_CODE (value
) != INTEGER_CST
)
2077 error_at (value_loc
, "expression in static assertion is not constant");
2080 constant_expression_warning (value
);
2081 if (integer_zerop (value
))
2082 error_at (assert_loc
, "static assertion failed: %E", string
);
2085 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2086 6.7), adding them to SPECS (which may already include some).
2087 Storage class specifiers are accepted iff SCSPEC_OK; type
2088 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2089 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2090 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2092 declaration-specifiers:
2093 storage-class-specifier declaration-specifiers[opt]
2094 type-specifier declaration-specifiers[opt]
2095 type-qualifier declaration-specifiers[opt]
2096 function-specifier declaration-specifiers[opt]
2097 alignment-specifier declaration-specifiers[opt]
2099 Function specifiers (inline) are from C99, and are currently
2100 handled as storage class specifiers, as is __thread. Alignment
2101 specifiers are from C11.
2103 C90 6.5.1, C99 6.7.1:
2104 storage-class-specifier:
2112 (_Thread_local is new in C11.)
2119 (_Noreturn is new in C11.)
2121 C90 6.5.2, C99 6.7.2:
2134 [_Imaginary removed in C99 TC2]
2135 struct-or-union-specifier
2138 atomic-type-specifier
2140 (_Bool and _Complex are new in C99.)
2141 (atomic-type-specifier is new in C11.)
2143 C90 6.5.3, C99 6.7.3:
2149 address-space-qualifier
2152 (restrict is new in C99.)
2153 (_Atomic is new in C11.)
2157 declaration-specifiers:
2158 attributes declaration-specifiers[opt]
2164 identifier recognized by the target
2166 storage-class-specifier:
2180 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2181 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2183 atomic-type-specifier
2184 _Atomic ( type-name )
2189 class-name objc-protocol-refs[opt]
2190 typedef-name objc-protocol-refs
2195 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2196 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2197 bool alignspec_ok
, bool auto_type_ok
,
2198 enum c_lookahead_kind la
)
2200 bool attrs_ok
= start_attr_ok
;
2201 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2204 gcc_assert (la
== cla_prefer_id
);
2206 while (c_parser_next_token_is (parser
, CPP_NAME
)
2207 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2208 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2210 struct c_typespec t
;
2213 location_t loc
= c_parser_peek_token (parser
)->location
;
2215 /* If we cannot accept a type, exit if the next token must start
2216 one. Also, if we already have seen a tagged definition,
2217 a typename would be an error anyway and likely the user
2218 has simply forgotten a semicolon, so we exit. */
2219 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2220 && c_parser_next_tokens_start_typename (parser
, la
)
2221 && !c_parser_next_token_is_qualifier (parser
))
2224 if (c_parser_next_token_is (parser
, CPP_NAME
))
2226 c_token
*name_token
= c_parser_peek_token (parser
);
2227 tree value
= name_token
->value
;
2228 c_id_kind kind
= name_token
->id_kind
;
2230 if (kind
== C_ID_ADDRSPACE
)
2233 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2234 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2235 c_parser_consume_token (parser
);
2240 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2242 /* If we cannot accept a type, and the next token must start one,
2243 exit. Do the same if we already have seen a tagged definition,
2244 since it would be an error anyway and likely the user has simply
2245 forgotten a semicolon. */
2246 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2249 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2250 a C_ID_CLASSNAME. */
2251 c_parser_consume_token (parser
);
2254 if (kind
== C_ID_ID
)
2256 error_at (loc
, "unknown type name %qE", value
);
2257 t
.kind
= ctsk_typedef
;
2258 t
.spec
= error_mark_node
;
2260 else if (kind
== C_ID_TYPENAME
2261 && (!c_dialect_objc ()
2262 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2264 t
.kind
= ctsk_typedef
;
2265 /* For a typedef name, record the meaning, not the name.
2266 In case of 'foo foo, bar;'. */
2267 t
.spec
= lookup_name (value
);
2271 tree proto
= NULL_TREE
;
2272 gcc_assert (c_dialect_objc ());
2274 if (c_parser_next_token_is (parser
, CPP_LESS
))
2275 proto
= c_parser_objc_protocol_refs (parser
);
2276 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2279 t
.expr_const_operands
= true;
2280 declspecs_add_type (name_token
->location
, specs
, t
);
2283 if (c_parser_next_token_is (parser
, CPP_LESS
))
2285 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2286 nisse@lysator.liu.se. */
2288 gcc_assert (c_dialect_objc ());
2289 if (!typespec_ok
|| seen_type
)
2291 proto
= c_parser_objc_protocol_refs (parser
);
2293 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2295 t
.expr_const_operands
= true;
2296 declspecs_add_type (loc
, specs
, t
);
2299 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2300 switch (c_parser_peek_token (parser
)->keyword
)
2313 /* TODO: Distinguish between function specifiers (inline, noreturn)
2314 and storage class specifiers, either here or in
2315 declspecs_add_scspec. */
2316 declspecs_add_scspec (loc
, specs
,
2317 c_parser_peek_token (parser
)->value
);
2318 c_parser_consume_token (parser
);
2346 if (c_dialect_objc ())
2347 parser
->objc_need_raw_identifier
= true;
2348 t
.kind
= ctsk_resword
;
2349 t
.spec
= c_parser_peek_token (parser
)->value
;
2351 t
.expr_const_operands
= true;
2352 declspecs_add_type (loc
, specs
, t
);
2353 c_parser_consume_token (parser
);
2360 t
= c_parser_enum_specifier (parser
);
2361 declspecs_add_type (loc
, specs
, t
);
2369 t
= c_parser_struct_or_union_specifier (parser
);
2370 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2371 declspecs_add_type (loc
, specs
, t
);
2374 /* ??? The old parser rejected typeof after other type
2375 specifiers, but is a syntax error the best way of
2377 if (!typespec_ok
|| seen_type
)
2381 t
= c_parser_typeof_specifier (parser
);
2382 declspecs_add_type (loc
, specs
, t
);
2385 /* C parser handling of Objective-C constructs needs
2386 checking for correct lvalue-to-rvalue conversions, and
2387 the code in build_modify_expr handling various
2388 Objective-C cases, and that in build_unary_op handling
2389 Objective-C cases for increment / decrement, also needs
2390 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2391 and objc_types_are_equivalent may also need updates. */
2392 if (c_dialect_objc ())
2393 sorry ("%<_Atomic%> in Objective-C");
2394 /* C parser handling of OpenMP constructs needs checking for
2395 correct lvalue-to-rvalue conversions. */
2397 sorry ("%<_Atomic%> with OpenMP");
2401 pedwarn (loc
, OPT_Wpedantic
,
2402 "ISO C99 does not support the %<_Atomic%> qualifier");
2404 pedwarn (loc
, OPT_Wpedantic
,
2405 "ISO C90 does not support the %<_Atomic%> qualifier");
2409 value
= c_parser_peek_token (parser
)->value
;
2410 c_parser_consume_token (parser
);
2411 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2413 /* _Atomic ( type-name ). */
2415 c_parser_consume_token (parser
);
2416 struct c_type_name
*type
= c_parser_type_name (parser
);
2417 t
.kind
= ctsk_typeof
;
2418 t
.spec
= error_mark_node
;
2420 t
.expr_const_operands
= true;
2422 t
.spec
= groktypename (type
, &t
.expr
,
2423 &t
.expr_const_operands
);
2424 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2426 if (t
.spec
!= error_mark_node
)
2428 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2429 error_at (loc
, "%<_Atomic%>-qualified array type");
2430 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2431 error_at (loc
, "%<_Atomic%>-qualified function type");
2432 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2433 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2435 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2437 declspecs_add_type (loc
, specs
, t
);
2440 declspecs_add_qual (loc
, specs
, value
);
2446 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2447 c_parser_consume_token (parser
);
2449 /* UPC qualifiers */
2452 c_parser_upc_shared_qual (loc
, parser
, specs
);
2457 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2458 c_parser_consume_token (parser
);
2463 attrs
= c_parser_attributes (parser
);
2464 declspecs_add_attrs (loc
, specs
, attrs
);
2469 align
= c_parser_alignas_specifier (parser
);
2470 declspecs_add_alignas (loc
, specs
, align
);
2479 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2482 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2483 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2484 enum attributes[opt] identifier
2486 The form with trailing comma is new in C99. The forms with
2487 attributes are GNU extensions. In GNU C, we accept any expression
2488 without commas in the syntax (assignment expressions, not just
2489 conditional expressions); assignment expressions will be diagnosed
2494 enumerator-list , enumerator
2497 enumeration-constant
2498 enumeration-constant = constant-expression
2501 static struct c_typespec
2502 c_parser_enum_specifier (c_parser
*parser
)
2504 struct c_typespec ret
;
2506 tree ident
= NULL_TREE
;
2507 location_t enum_loc
;
2508 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2509 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2510 enum_loc
= c_parser_peek_token (parser
)->location
;
2511 c_parser_consume_token (parser
);
2512 attrs
= c_parser_attributes (parser
);
2513 enum_loc
= c_parser_peek_token (parser
)->location
;
2514 /* Set the location in case we create a decl now. */
2515 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2516 if (c_parser_next_token_is (parser
, CPP_NAME
))
2518 ident
= c_parser_peek_token (parser
)->value
;
2519 ident_loc
= c_parser_peek_token (parser
)->location
;
2520 enum_loc
= ident_loc
;
2521 c_parser_consume_token (parser
);
2523 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2525 /* Parse an enum definition. */
2526 struct c_enum_contents the_enum
;
2529 /* We chain the enumerators in reverse order, then put them in
2530 forward order at the end. */
2532 timevar_push (TV_PARSE_ENUM
);
2533 type
= start_enum (enum_loc
, &the_enum
, ident
);
2535 c_parser_consume_token (parser
);
2543 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2544 location_t decl_loc
, value_loc
;
2545 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2547 c_parser_error (parser
, "expected identifier");
2548 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2549 values
= error_mark_node
;
2552 token
= c_parser_peek_token (parser
);
2553 enum_id
= token
->value
;
2554 /* Set the location in case we create a decl now. */
2555 c_parser_set_source_position_from_token (token
);
2556 decl_loc
= value_loc
= token
->location
;
2557 c_parser_consume_token (parser
);
2558 if (c_parser_next_token_is (parser
, CPP_EQ
))
2560 c_parser_consume_token (parser
);
2561 value_loc
= c_parser_peek_token (parser
)->location
;
2562 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2565 enum_value
= NULL_TREE
;
2566 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2567 &the_enum
, enum_id
, enum_value
);
2568 TREE_CHAIN (enum_decl
) = values
;
2571 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2573 comma_loc
= c_parser_peek_token (parser
)->location
;
2575 c_parser_consume_token (parser
);
2577 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2579 if (seen_comma
&& !flag_isoc99
)
2580 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2581 c_parser_consume_token (parser
);
2586 c_parser_error (parser
, "expected %<,%> or %<}%>");
2587 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2588 values
= error_mark_node
;
2592 postfix_attrs
= c_parser_attributes (parser
);
2593 ret
.spec
= finish_enum (type
, nreverse (values
),
2594 chainon (attrs
, postfix_attrs
));
2595 ret
.kind
= ctsk_tagdef
;
2596 ret
.expr
= NULL_TREE
;
2597 ret
.expr_const_operands
= true;
2598 timevar_pop (TV_PARSE_ENUM
);
2603 c_parser_error (parser
, "expected %<{%>");
2604 ret
.spec
= error_mark_node
;
2605 ret
.kind
= ctsk_tagref
;
2606 ret
.expr
= NULL_TREE
;
2607 ret
.expr_const_operands
= true;
2610 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2611 /* In ISO C, enumerated types can be referred to only if already
2613 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2616 pedwarn (enum_loc
, OPT_Wpedantic
,
2617 "ISO C forbids forward references to %<enum%> types");
2622 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2624 struct-or-union-specifier:
2625 struct-or-union attributes[opt] identifier[opt]
2626 { struct-contents } attributes[opt]
2627 struct-or-union attributes[opt] identifier
2630 struct-declaration-list
2632 struct-declaration-list:
2633 struct-declaration ;
2634 struct-declaration-list struct-declaration ;
2641 struct-declaration-list struct-declaration
2643 struct-declaration-list:
2644 struct-declaration-list ;
2647 (Note that in the syntax here, unlike that in ISO C, the semicolons
2648 are included here rather than in struct-declaration, in order to
2649 describe the syntax with extra semicolons and missing semicolon at
2654 struct-declaration-list:
2655 @defs ( class-name )
2657 (Note this does not include a trailing semicolon, but can be
2658 followed by further declarations, and gets a pedwarn-if-pedantic
2659 when followed by a semicolon.) */
2661 static struct c_typespec
2662 c_parser_struct_or_union_specifier (c_parser
*parser
)
2664 struct c_typespec ret
;
2666 tree ident
= NULL_TREE
;
2667 location_t struct_loc
;
2668 location_t ident_loc
= UNKNOWN_LOCATION
;
2669 enum tree_code code
;
2670 switch (c_parser_peek_token (parser
)->keyword
)
2681 struct_loc
= c_parser_peek_token (parser
)->location
;
2682 c_parser_consume_token (parser
);
2683 attrs
= c_parser_attributes (parser
);
2685 /* Set the location in case we create a decl now. */
2686 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2688 if (c_parser_next_token_is (parser
, CPP_NAME
))
2690 ident
= c_parser_peek_token (parser
)->value
;
2691 ident_loc
= c_parser_peek_token (parser
)->location
;
2692 struct_loc
= ident_loc
;
2693 c_parser_consume_token (parser
);
2695 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2697 /* Parse a struct or union definition. Start the scope of the
2698 tag before parsing components. */
2699 struct c_struct_parse_info
*struct_info
;
2700 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2702 /* We chain the components in reverse order, then put them in
2703 forward order at the end. Each struct-declaration may
2704 declare multiple components (comma-separated), so we must use
2705 chainon to join them, although when parsing each
2706 struct-declaration we can use TREE_CHAIN directly.
2708 The theory behind all this is that there will be more
2709 semicolon separated fields than comma separated fields, and
2710 so we'll be minimizing the number of node traversals required
2713 timevar_push (TV_PARSE_STRUCT
);
2714 contents
= NULL_TREE
;
2715 c_parser_consume_token (parser
);
2716 /* Handle the Objective-C @defs construct,
2717 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2718 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2721 gcc_assert (c_dialect_objc ());
2722 c_parser_consume_token (parser
);
2723 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2725 if (c_parser_next_token_is (parser
, CPP_NAME
)
2726 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2728 name
= c_parser_peek_token (parser
)->value
;
2729 c_parser_consume_token (parser
);
2733 c_parser_error (parser
, "expected class name");
2734 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2737 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2739 contents
= nreverse (objc_get_class_ivars (name
));
2742 /* Parse the struct-declarations and semicolons. Problems with
2743 semicolons are diagnosed here; empty structures are diagnosed
2748 /* Parse any stray semicolon. */
2749 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2751 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2752 "extra semicolon in struct or union specified");
2753 c_parser_consume_token (parser
);
2756 /* Stop if at the end of the struct or union contents. */
2757 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2759 c_parser_consume_token (parser
);
2762 /* Accept #pragmas at struct scope. */
2763 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2765 c_parser_pragma (parser
, pragma_struct
);
2768 /* Parse some comma-separated declarations, but not the
2769 trailing semicolon if any. */
2770 decls
= c_parser_struct_declaration (parser
);
2771 contents
= chainon (decls
, contents
);
2772 /* If no semicolon follows, either we have a parse error or
2773 are at the end of the struct or union and should
2775 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2776 c_parser_consume_token (parser
);
2779 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2780 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2781 "no semicolon at end of struct or union");
2782 else if (parser
->error
2783 || !c_parser_next_token_starts_declspecs (parser
))
2785 c_parser_error (parser
, "expected %<;%>");
2786 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2790 /* If we come here, we have already emitted an error
2791 for an expected `;', identifier or `(', and we also
2792 recovered already. Go on with the next field. */
2795 postfix_attrs
= c_parser_attributes (parser
);
2796 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2797 chainon (attrs
, postfix_attrs
), struct_info
);
2798 ret
.kind
= ctsk_tagdef
;
2799 ret
.expr
= NULL_TREE
;
2800 ret
.expr_const_operands
= true;
2801 timevar_pop (TV_PARSE_STRUCT
);
2806 c_parser_error (parser
, "expected %<{%>");
2807 ret
.spec
= error_mark_node
;
2808 ret
.kind
= ctsk_tagref
;
2809 ret
.expr
= NULL_TREE
;
2810 ret
.expr_const_operands
= true;
2813 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2817 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2818 the trailing semicolon.
2821 specifier-qualifier-list struct-declarator-list
2822 static_assert-declaration-no-semi
2824 specifier-qualifier-list:
2825 type-specifier specifier-qualifier-list[opt]
2826 type-qualifier specifier-qualifier-list[opt]
2827 attributes specifier-qualifier-list[opt]
2829 struct-declarator-list:
2831 struct-declarator-list , attributes[opt] struct-declarator
2834 declarator attributes[opt]
2835 declarator[opt] : constant-expression attributes[opt]
2840 __extension__ struct-declaration
2841 specifier-qualifier-list
2843 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2844 of attributes where shown is a GNU extension. In GNU C, we accept
2845 any expression without commas in the syntax (assignment
2846 expressions, not just conditional expressions); assignment
2847 expressions will be diagnosed as non-constant. */
2850 c_parser_struct_declaration (c_parser
*parser
)
2852 struct c_declspecs
*specs
;
2854 tree all_prefix_attrs
;
2856 location_t decl_loc
;
2857 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2861 ext
= disable_extension_diagnostics ();
2862 c_parser_consume_token (parser
);
2863 decl
= c_parser_struct_declaration (parser
);
2864 restore_extension_diagnostics (ext
);
2867 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2869 c_parser_static_assert_declaration_no_semi (parser
);
2872 specs
= build_null_declspecs ();
2873 decl_loc
= c_parser_peek_token (parser
)->location
;
2874 /* Strictly by the standard, we shouldn't allow _Alignas here,
2875 but it appears to have been intended to allow it there, so
2876 we're keeping it as it is until WG14 reaches a conclusion
2878 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2879 c_parser_declspecs (parser
, specs
, false, true, true,
2880 true, false, cla_nonabstract_decl
);
2883 if (!specs
->declspecs_seen_p
)
2885 c_parser_error (parser
, "expected specifier-qualifier-list");
2888 finish_declspecs (specs
);
2889 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2890 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2893 if (specs
->typespec_kind
== ctsk_none
)
2895 pedwarn (decl_loc
, OPT_Wpedantic
,
2896 "ISO C forbids member declarations with no members");
2897 shadow_tag_warned (specs
, pedantic
);
2902 /* Support for unnamed structs or unions as members of
2903 structs or unions (which is [a] useful and [b] supports
2907 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2908 build_id_declarator (NULL_TREE
), specs
,
2911 decl_attributes (&ret
, attrs
, 0);
2916 /* Provide better error recovery. Note that a type name here is valid,
2917 and will be treated as a field name. */
2918 if (specs
->typespec_kind
== ctsk_tagdef
2919 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2920 && c_parser_next_token_starts_declspecs (parser
)
2921 && !c_parser_next_token_is (parser
, CPP_NAME
))
2923 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2924 parser
->error
= false;
2928 pending_xref_error ();
2929 prefix_attrs
= specs
->attrs
;
2930 all_prefix_attrs
= prefix_attrs
;
2931 specs
->attrs
= NULL_TREE
;
2935 /* Declaring one or more declarators or un-named bit-fields. */
2936 struct c_declarator
*declarator
;
2938 if (c_parser_next_token_is (parser
, CPP_COLON
))
2939 declarator
= build_id_declarator (NULL_TREE
);
2941 declarator
= c_parser_declarator (parser
,
2942 specs
->typespec_kind
!= ctsk_none
,
2943 C_DTR_NORMAL
, &dummy
);
2944 if (declarator
== NULL
)
2946 c_parser_skip_to_end_of_block_or_statement (parser
);
2949 if (c_parser_next_token_is (parser
, CPP_COLON
)
2950 || c_parser_next_token_is (parser
, CPP_COMMA
)
2951 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2952 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2953 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2955 tree postfix_attrs
= NULL_TREE
;
2956 tree width
= NULL_TREE
;
2958 if (c_parser_next_token_is (parser
, CPP_COLON
))
2960 c_parser_consume_token (parser
);
2961 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2963 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2964 postfix_attrs
= c_parser_attributes (parser
);
2965 d
= grokfield (c_parser_peek_token (parser
)->location
,
2966 declarator
, specs
, width
, &all_prefix_attrs
);
2967 decl_attributes (&d
, chainon (postfix_attrs
,
2968 all_prefix_attrs
), 0);
2969 DECL_CHAIN (d
) = decls
;
2971 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2972 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2975 all_prefix_attrs
= prefix_attrs
;
2976 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2977 c_parser_consume_token (parser
);
2978 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2979 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2981 /* Semicolon consumed in caller. */
2986 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2992 c_parser_error (parser
,
2993 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2994 "%<__attribute__%>");
3001 /* Parse a typeof specifier (a GNU extension).
3004 typeof ( expression )
3005 typeof ( type-name )
3008 static struct c_typespec
3009 c_parser_typeof_specifier (c_parser
*parser
)
3011 struct c_typespec ret
;
3012 ret
.kind
= ctsk_typeof
;
3013 ret
.spec
= error_mark_node
;
3014 ret
.expr
= NULL_TREE
;
3015 ret
.expr_const_operands
= true;
3016 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3017 c_parser_consume_token (parser
);
3018 c_inhibit_evaluation_warnings
++;
3020 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3022 c_inhibit_evaluation_warnings
--;
3026 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3028 struct c_type_name
*type
= c_parser_type_name (parser
);
3029 c_inhibit_evaluation_warnings
--;
3033 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3034 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3040 location_t here
= c_parser_peek_token (parser
)->location
;
3041 struct c_expr expr
= c_parser_expression (parser
);
3042 c_inhibit_evaluation_warnings
--;
3044 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3045 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3046 error_at (here
, "%<typeof%> applied to a bit-field");
3047 mark_exp_read (expr
.value
);
3048 ret
.spec
= TREE_TYPE (expr
.value
);
3049 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3050 /* This is returned with the type so that when the type is
3051 evaluated, this can be evaluated. */
3053 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3054 pop_maybe_used (was_vm
);
3055 /* For use in macros such as those in <stdatomic.h>, remove
3056 _Atomic and const qualifiers from atomic types. (Possibly
3057 all qualifiers should be removed; const can be an issue for
3058 more macros using typeof than just the <stdatomic.h>
3060 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3061 ret
.spec
= c_build_qualified_type (ret
.spec
,
3062 (TYPE_QUALS (ret
.spec
)
3063 & ~(TYPE_QUAL_ATOMIC
3064 | TYPE_QUAL_CONST
)));
3066 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3070 /* Parse an alignment-specifier.
3074 alignment-specifier:
3075 _Alignas ( type-name )
3076 _Alignas ( constant-expression )
3080 c_parser_alignas_specifier (c_parser
* parser
)
3082 tree ret
= error_mark_node
;
3083 location_t loc
= c_parser_peek_token (parser
)->location
;
3084 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3085 c_parser_consume_token (parser
);
3089 pedwarn (loc
, OPT_Wpedantic
,
3090 "ISO C99 does not support %<_Alignas%>");
3092 pedwarn (loc
, OPT_Wpedantic
,
3093 "ISO C90 does not support %<_Alignas%>");
3095 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3097 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3099 struct c_type_name
*type
= c_parser_type_name (parser
);
3101 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3105 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3106 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3110 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3111 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3112 be redeclared; otherwise it may not. KIND indicates which kind of
3113 declarator is wanted. Returns a valid declarator except in the
3114 case of a syntax error in which case NULL is returned. *SEEN_ID is
3115 set to true if an identifier being declared is seen; this is used
3116 to diagnose bad forms of abstract array declarators and to
3117 determine whether an identifier list is syntactically permitted.
3120 pointer[opt] direct-declarator
3124 ( attributes[opt] declarator )
3125 direct-declarator array-declarator
3126 direct-declarator ( parameter-type-list )
3127 direct-declarator ( identifier-list[opt] )
3130 * type-qualifier-list[opt]
3131 * type-qualifier-list[opt] pointer
3133 type-qualifier-list:
3136 type-qualifier-list type-qualifier
3137 type-qualifier-list attributes
3140 [ type-qualifier-list[opt] assignment-expression[opt] ]
3141 [ static type-qualifier-list[opt] assignment-expression ]
3142 [ type-qualifier-list static assignment-expression ]
3143 [ type-qualifier-list[opt] * ]
3145 parameter-type-list:
3147 parameter-list , ...
3150 parameter-declaration
3151 parameter-list , parameter-declaration
3153 parameter-declaration:
3154 declaration-specifiers declarator attributes[opt]
3155 declaration-specifiers abstract-declarator[opt] attributes[opt]
3159 identifier-list , identifier
3161 abstract-declarator:
3163 pointer[opt] direct-abstract-declarator
3165 direct-abstract-declarator:
3166 ( attributes[opt] abstract-declarator )
3167 direct-abstract-declarator[opt] array-declarator
3168 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3173 direct-declarator ( parameter-forward-declarations
3174 parameter-type-list[opt] )
3176 direct-abstract-declarator:
3177 direct-abstract-declarator[opt] ( parameter-forward-declarations
3178 parameter-type-list[opt] )
3180 parameter-forward-declarations:
3182 parameter-forward-declarations parameter-list ;
3184 The uses of attributes shown above are GNU extensions.
3186 Some forms of array declarator are not included in C99 in the
3187 syntax for abstract declarators; these are disallowed elsewhere.
3188 This may be a defect (DR#289).
3190 This function also accepts an omitted abstract declarator as being
3191 an abstract declarator, although not part of the formal syntax. */
3193 static struct c_declarator
*
3194 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3197 /* Parse any initial pointer part. */
3198 if (c_parser_next_token_is (parser
, CPP_MULT
))
3200 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3201 struct c_declarator
*inner
;
3202 c_parser_consume_token (parser
);
3203 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3204 false, false, cla_prefer_id
);
3205 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3209 return make_pointer_declarator (quals_attrs
, inner
);
3211 /* Now we have a direct declarator, direct abstract declarator or
3212 nothing (which counts as a direct abstract declarator here). */
3213 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3216 /* Parse a direct declarator or direct abstract declarator; arguments
3217 as c_parser_declarator. */
3219 static struct c_declarator
*
3220 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3223 /* The direct declarator must start with an identifier (possibly
3224 omitted) or a parenthesized declarator (possibly abstract). In
3225 an ordinary declarator, initial parentheses must start a
3226 parenthesized declarator. In an abstract declarator or parameter
3227 declarator, they could start a parenthesized declarator or a
3228 parameter list. To tell which, the open parenthesis and any
3229 following attributes must be read. If a declaration specifier
3230 follows, then it is a parameter list; if the specifier is a
3231 typedef name, there might be an ambiguity about redeclaring it,
3232 which is resolved in the direction of treating it as a typedef
3233 name. If a close parenthesis follows, it is also an empty
3234 parameter list, as the syntax does not permit empty abstract
3235 declarators. Otherwise, it is a parenthesized declarator (in
3236 which case the analysis may be repeated inside it, recursively).
3238 ??? There is an ambiguity in a parameter declaration "int
3239 (__attribute__((foo)) x)", where x is not a typedef name: it
3240 could be an abstract declarator for a function, or declare x with
3241 parentheses. The proper resolution of this ambiguity needs
3242 documenting. At present we follow an accident of the old
3243 parser's implementation, whereby the first parameter must have
3244 some declaration specifiers other than just attributes. Thus as
3245 a parameter declaration it is treated as a parenthesized
3246 parameter named x, and as an abstract declarator it is
3249 ??? Also following the old parser, attributes inside an empty
3250 parameter list are ignored, making it a list not yielding a
3251 prototype, rather than giving an error or making it have one
3252 parameter with implicit type int.
3254 ??? Also following the old parser, typedef names may be
3255 redeclared in declarators, but not Objective-C class names. */
3257 if (kind
!= C_DTR_ABSTRACT
3258 && c_parser_next_token_is (parser
, CPP_NAME
)
3260 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3261 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3262 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3264 struct c_declarator
*inner
3265 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3267 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3268 c_parser_consume_token (parser
);
3269 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3272 if (kind
!= C_DTR_NORMAL
3273 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3275 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3276 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3279 /* Either we are at the end of an abstract declarator, or we have
3282 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3285 struct c_declarator
*inner
;
3286 c_parser_consume_token (parser
);
3287 attrs
= c_parser_attributes (parser
);
3288 if (kind
!= C_DTR_NORMAL
3289 && (c_parser_next_token_starts_declspecs (parser
)
3290 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3292 struct c_arg_info
*args
3293 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3300 = build_function_declarator (args
,
3301 build_id_declarator (NULL_TREE
));
3302 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3306 /* A parenthesized declarator. */
3307 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3308 if (inner
!= NULL
&& attrs
!= NULL
)
3309 inner
= build_attrs_declarator (attrs
, inner
);
3310 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3312 c_parser_consume_token (parser
);
3316 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3320 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3327 if (kind
== C_DTR_NORMAL
)
3329 c_parser_error (parser
, "expected identifier or %<(%>");
3333 return build_id_declarator (NULL_TREE
);
3337 /* Parse part of a direct declarator or direct abstract declarator,
3338 given that some (in INNER) has already been parsed; ID_PRESENT is
3339 true if an identifier is present, false for an abstract
3342 static struct c_declarator
*
3343 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3344 struct c_declarator
*inner
)
3346 /* Parse a sequence of array declarators and parameter lists. */
3347 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3349 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3350 struct c_declarator
*declarator
;
3351 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3354 struct c_expr dimen
;
3355 dimen
.value
= NULL_TREE
;
3356 dimen
.original_code
= ERROR_MARK
;
3357 dimen
.original_type
= NULL_TREE
;
3358 c_parser_consume_token (parser
);
3359 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3360 false, false, cla_prefer_id
);
3361 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3363 c_parser_consume_token (parser
);
3364 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3365 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3366 false, false, cla_prefer_id
);
3367 if (!quals_attrs
->declspecs_seen_p
)
3369 /* If "static" is present, there must be an array dimension.
3370 Otherwise, there may be a dimension, "*", or no
3375 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3379 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3381 dimen
.value
= NULL_TREE
;
3384 else if (flag_cilkplus
3385 && c_parser_next_token_is (parser
, CPP_COLON
))
3387 dimen
.value
= error_mark_node
;
3389 error_at (c_parser_peek_token (parser
)->location
,
3390 "array notations cannot be used in declaration");
3391 c_parser_consume_token (parser
);
3393 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3395 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3397 dimen
.value
= NULL_TREE
;
3399 c_parser_consume_token (parser
);
3404 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3410 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3413 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3414 c_parser_consume_token (parser
);
3415 else if (flag_cilkplus
3416 && c_parser_next_token_is (parser
, CPP_COLON
))
3418 error_at (c_parser_peek_token (parser
)->location
,
3419 "array notations cannot be used in declaration");
3420 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3425 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3430 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3431 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3432 static_seen
, star_seen
);
3433 if (declarator
== NULL
)
3435 inner
= set_array_declarator_inner (declarator
, inner
);
3436 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3438 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3441 struct c_arg_info
*args
;
3442 c_parser_consume_token (parser
);
3443 attrs
= c_parser_attributes (parser
);
3444 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3449 inner
= build_function_declarator (args
, inner
);
3450 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3456 /* Parse a parameter list or identifier list, including the closing
3457 parenthesis but not the opening one. ATTRS are the attributes at
3458 the start of the list. ID_LIST_OK is true if an identifier list is
3459 acceptable; such a list must not have attributes at the start. */
3461 static struct c_arg_info
*
3462 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3465 declare_parm_level ();
3466 /* If the list starts with an identifier, it is an identifier list.
3467 Otherwise, it is either a prototype list or an empty list. */
3470 && c_parser_next_token_is (parser
, CPP_NAME
)
3471 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3473 /* Look ahead to detect typos in type names. */
3474 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3475 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3476 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3477 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3479 tree list
= NULL_TREE
, *nextp
= &list
;
3480 while (c_parser_next_token_is (parser
, CPP_NAME
)
3481 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3483 *nextp
= build_tree_list (NULL_TREE
,
3484 c_parser_peek_token (parser
)->value
);
3485 nextp
= & TREE_CHAIN (*nextp
);
3486 c_parser_consume_token (parser
);
3487 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3489 c_parser_consume_token (parser
);
3490 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3492 c_parser_error (parser
, "expected identifier");
3496 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3498 struct c_arg_info
*ret
= build_arg_info ();
3500 c_parser_consume_token (parser
);
3506 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3514 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3521 /* Parse a parameter list (possibly empty), including the closing
3522 parenthesis but not the opening one. ATTRS are the attributes at
3523 the start of the list. EXPR is NULL or an expression that needs to
3524 be evaluated for the side effects of array size expressions in the
3527 static struct c_arg_info
*
3528 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3530 bool bad_parm
= false;
3532 /* ??? Following the old parser, forward parameter declarations may
3533 use abstract declarators, and if no real parameter declarations
3534 follow the forward declarations then this is not diagnosed. Also
3535 note as above that attributes are ignored as the only contents of
3536 the parentheses, or as the only contents after forward
3538 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3540 struct c_arg_info
*ret
= build_arg_info ();
3541 c_parser_consume_token (parser
);
3544 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3546 struct c_arg_info
*ret
= build_arg_info ();
3548 if (flag_allow_parameterless_variadic_functions
)
3550 /* F (...) is allowed. */
3551 ret
->types
= NULL_TREE
;
3555 /* Suppress -Wold-style-definition for this case. */
3556 ret
->types
= error_mark_node
;
3557 error_at (c_parser_peek_token (parser
)->location
,
3558 "ISO C requires a named argument before %<...%>");
3560 c_parser_consume_token (parser
);
3561 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3563 c_parser_consume_token (parser
);
3568 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3573 /* Nonempty list of parameters, either terminated with semicolon
3574 (forward declarations; recurse) or with close parenthesis (normal
3575 function) or with ", ... )" (variadic function). */
3578 /* Parse a parameter. */
3579 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3584 push_parm_decl (parm
, &expr
);
3585 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3588 c_parser_consume_token (parser
);
3589 mark_forward_parm_decls ();
3590 new_attrs
= c_parser_attributes (parser
);
3591 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3593 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3595 c_parser_consume_token (parser
);
3599 return get_parm_info (false, expr
);
3601 if (!c_parser_require (parser
, CPP_COMMA
,
3602 "expected %<;%>, %<,%> or %<)%>"))
3604 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3607 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3609 c_parser_consume_token (parser
);
3610 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3612 c_parser_consume_token (parser
);
3616 return get_parm_info (true, expr
);
3620 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3628 /* Parse a parameter declaration. ATTRS are the attributes at the
3629 start of the declaration if it is the first parameter. */
3631 static struct c_parm
*
3632 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3634 struct c_declspecs
*specs
;
3635 struct c_declarator
*declarator
;
3637 tree postfix_attrs
= NULL_TREE
;
3640 /* Accept #pragmas between parameter declarations. */
3641 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3642 c_parser_pragma (parser
, pragma_param
);
3644 if (!c_parser_next_token_starts_declspecs (parser
))
3646 c_token
*token
= c_parser_peek_token (parser
);
3649 c_parser_set_source_position_from_token (token
);
3650 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3652 error_at (token
->location
, "unknown type name %qE", token
->value
);
3653 parser
->error
= true;
3655 /* ??? In some Objective-C cases '...' isn't applicable so there
3656 should be a different message. */
3658 c_parser_error (parser
,
3659 "expected declaration specifiers or %<...%>");
3660 c_parser_skip_to_end_of_parameter (parser
);
3663 specs
= build_null_declspecs ();
3666 declspecs_add_attrs (input_location
, specs
, attrs
);
3669 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3670 cla_nonabstract_decl
);
3671 finish_declspecs (specs
);
3672 pending_xref_error ();
3673 prefix_attrs
= specs
->attrs
;
3674 specs
->attrs
= NULL_TREE
;
3675 declarator
= c_parser_declarator (parser
,
3676 specs
->typespec_kind
!= ctsk_none
,
3677 C_DTR_PARM
, &dummy
);
3678 if (declarator
== NULL
)
3680 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3683 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3684 postfix_attrs
= c_parser_attributes (parser
);
3685 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3689 /* Parse a string literal in an asm expression. It should not be
3690 translated, and wide string literals are an error although
3691 permitted by the syntax. This is a GNU extension.
3696 ??? At present, following the old parser, the caller needs to have
3697 set lex_untranslated_string to 1. It would be better to follow the
3698 C++ parser rather than using this kludge. */
3701 c_parser_asm_string_literal (c_parser
*parser
)
3704 int save_flag
= warn_overlength_strings
;
3705 warn_overlength_strings
= 0;
3706 if (c_parser_next_token_is (parser
, CPP_STRING
))
3708 str
= c_parser_peek_token (parser
)->value
;
3709 c_parser_consume_token (parser
);
3711 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3713 error_at (c_parser_peek_token (parser
)->location
,
3714 "wide string literal in %<asm%>");
3715 str
= build_string (1, "");
3716 c_parser_consume_token (parser
);
3720 c_parser_error (parser
, "expected string literal");
3723 warn_overlength_strings
= save_flag
;
3727 /* Parse a simple asm expression. This is used in restricted
3728 contexts, where a full expression with inputs and outputs does not
3729 make sense. This is a GNU extension.
3732 asm ( asm-string-literal )
3736 c_parser_simple_asm_expr (c_parser
*parser
)
3739 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3740 /* ??? Follow the C++ parser rather than using the
3741 lex_untranslated_string kludge. */
3742 parser
->lex_untranslated_string
= true;
3743 c_parser_consume_token (parser
);
3744 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3746 parser
->lex_untranslated_string
= false;
3749 str
= c_parser_asm_string_literal (parser
);
3750 parser
->lex_untranslated_string
= false;
3751 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3753 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3760 c_parser_attribute_any_word (c_parser
*parser
)
3762 tree attr_name
= NULL_TREE
;
3764 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3766 /* ??? See comment above about what keywords are accepted here. */
3768 switch (c_parser_peek_token (parser
)->keyword
)
3799 case RID_TRANSACTION_ATOMIC
:
3800 case RID_TRANSACTION_CANCEL
:
3812 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3813 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3815 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3816 attr_name
= c_parser_peek_token (parser
)->value
;
3821 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3822 "__vector" or "__vector__." */
3825 is_cilkplus_vector_p (tree name
)
3827 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3832 #define CILK_SIMD_FN_CLAUSE_MASK \
3833 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3834 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3835 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3836 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3837 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3839 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3840 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3841 pushed into the token list.
3844 vector (<vector attributes>). */
3847 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3849 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3851 int paren_scope
= 0;
3852 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3853 /* Consume the "vector" token. */
3854 c_parser_consume_token (parser
);
3856 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3858 c_parser_consume_token (parser
);
3861 while (paren_scope
> 0)
3863 c_token
*token
= c_parser_peek_token (parser
);
3864 if (token
->type
== CPP_OPEN_PAREN
)
3866 else if (token
->type
== CPP_CLOSE_PAREN
)
3868 /* Do not push the last ')' since we are not pushing the '('. */
3869 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3870 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3871 c_parser_consume_token (parser
);
3874 /* Since we are converting an attribute to a pragma, we need to end the
3875 attribute with PRAGMA_EOL. */
3877 memset (&eol_token
, 0, sizeof (eol_token
));
3878 eol_token
.type
= CPP_PRAGMA_EOL
;
3879 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3882 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3885 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3887 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3889 /* c_parser_attributes is called in several places, so if these EOF
3890 tokens are already inserted, then don't do them again. */
3891 if (last_token
.type
== CPP_EOF
)
3894 /* Two CPP_EOF token are added as a safety net since the normal C
3895 front-end has two token look-ahead. */
3897 eof_token
.type
= CPP_EOF
;
3898 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3899 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3902 /* Parse (possibly empty) attributes. This is a GNU extension.
3906 attributes attribute
3909 __attribute__ ( ( attribute-list ) )
3913 attribute_list , attrib
3918 any-word ( identifier )
3919 any-word ( identifier , nonempty-expr-list )
3920 any-word ( expr-list )
3922 where the "identifier" must not be declared as a type, and
3923 "any-word" may be any identifier (including one declared as a
3924 type), a reserved word storage class specifier, type specifier or
3925 type qualifier. ??? This still leaves out most reserved keywords
3926 (following the old parser), shouldn't we include them, and why not
3927 allow identifiers declared as types to start the arguments? */
3930 c_parser_attributes (c_parser
*parser
)
3932 tree attrs
= NULL_TREE
;
3933 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3935 /* ??? Follow the C++ parser rather than using the
3936 lex_untranslated_string kludge. */
3937 parser
->lex_untranslated_string
= true;
3938 c_parser_consume_token (parser
);
3939 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3941 parser
->lex_untranslated_string
= false;
3944 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3946 parser
->lex_untranslated_string
= false;
3947 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3950 /* Parse the attribute list. */
3951 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3952 || c_parser_next_token_is (parser
, CPP_NAME
)
3953 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3955 tree attr
, attr_name
, attr_args
;
3956 vec
<tree
, va_gc
> *expr_list
;
3957 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3959 c_parser_consume_token (parser
);
3963 attr_name
= c_parser_attribute_any_word (parser
);
3964 if (attr_name
== NULL
)
3966 if (is_cilkplus_vector_p (attr_name
))
3968 c_token
*v_token
= c_parser_peek_token (parser
);
3969 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3972 c_parser_consume_token (parser
);
3973 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3975 attr
= build_tree_list (attr_name
, NULL_TREE
);
3976 attrs
= chainon (attrs
, attr
);
3979 c_parser_consume_token (parser
);
3980 /* Parse the attribute contents. If they start with an
3981 identifier which is followed by a comma or close
3982 parenthesis, then the arguments start with that
3983 identifier; otherwise they are an expression list.
3984 In objective-c the identifier may be a classname. */
3985 if (c_parser_next_token_is (parser
, CPP_NAME
)
3986 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3987 || (c_dialect_objc ()
3988 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3989 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3990 || (c_parser_peek_2nd_token (parser
)->type
3991 == CPP_CLOSE_PAREN
)))
3993 tree arg1
= c_parser_peek_token (parser
)->value
;
3994 c_parser_consume_token (parser
);
3995 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3996 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4000 c_parser_consume_token (parser
);
4001 expr_list
= c_parser_expr_list (parser
, false, true,
4002 NULL
, NULL
, NULL
, NULL
);
4003 tree_list
= build_tree_list_vec (expr_list
);
4004 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4005 release_tree_vector (expr_list
);
4010 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4011 attr_args
= NULL_TREE
;
4014 expr_list
= c_parser_expr_list (parser
, false, true,
4015 NULL
, NULL
, NULL
, NULL
);
4016 attr_args
= build_tree_list_vec (expr_list
);
4017 release_tree_vector (expr_list
);
4020 attr
= build_tree_list (attr_name
, attr_args
);
4021 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4022 c_parser_consume_token (parser
);
4025 parser
->lex_untranslated_string
= false;
4026 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4030 attrs
= chainon (attrs
, attr
);
4032 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4033 c_parser_consume_token (parser
);
4036 parser
->lex_untranslated_string
= false;
4037 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4041 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4042 c_parser_consume_token (parser
);
4045 parser
->lex_untranslated_string
= false;
4046 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4050 parser
->lex_untranslated_string
= false;
4053 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4054 c_finish_cilk_simd_fn_tokens (parser
);
4058 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4061 specifier-qualifier-list abstract-declarator[opt]
4064 static struct c_type_name
*
4065 c_parser_type_name (c_parser
*parser
)
4067 struct c_declspecs
*specs
= build_null_declspecs ();
4068 struct c_declarator
*declarator
;
4069 struct c_type_name
*ret
;
4071 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4073 if (!specs
->declspecs_seen_p
)
4075 c_parser_error (parser
, "expected specifier-qualifier-list");
4078 if (specs
->type
!= error_mark_node
)
4080 pending_xref_error ();
4081 finish_declspecs (specs
);
4083 declarator
= c_parser_declarator (parser
,
4084 specs
->typespec_kind
!= ctsk_none
,
4085 C_DTR_ABSTRACT
, &dummy
);
4086 if (declarator
== NULL
)
4088 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4090 ret
->declarator
= declarator
;
4094 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4097 assignment-expression
4098 { initializer-list }
4099 { initializer-list , }
4102 designation[opt] initializer
4103 initializer-list , designation[opt] initializer
4110 designator-list designator
4117 [ constant-expression ]
4129 [ constant-expression ... constant-expression ]
4131 Any expression without commas is accepted in the syntax for the
4132 constant-expressions, with non-constant expressions rejected later.
4134 This function is only used for top-level initializers; for nested
4135 ones, see c_parser_initval. */
4137 static struct c_expr
4138 c_parser_initializer (c_parser
*parser
)
4140 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4141 return c_parser_braced_init (parser
, NULL_TREE
, false);
4145 location_t loc
= c_parser_peek_token (parser
)->location
;
4146 ret
= c_parser_expr_no_commas (parser
, NULL
);
4147 if (TREE_CODE (ret
.value
) != STRING_CST
4148 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4149 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4154 /* Parse a braced initializer list. TYPE is the type specified for a
4155 compound literal, and NULL_TREE for other initializers and for
4156 nested braced lists. NESTED_P is true for nested braced lists,
4157 false for the list of a compound literal or the list that is the
4158 top-level initializer in a declaration. */
4160 static struct c_expr
4161 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4164 struct obstack braced_init_obstack
;
4165 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4166 gcc_obstack_init (&braced_init_obstack
);
4167 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4168 c_parser_consume_token (parser
);
4170 push_init_level (0, &braced_init_obstack
);
4172 really_start_incremental_init (type
);
4173 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4175 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4179 /* Parse a non-empty initializer list, possibly with a trailing
4183 c_parser_initelt (parser
, &braced_init_obstack
);
4186 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4187 c_parser_consume_token (parser
);
4190 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4194 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4196 ret
.value
= error_mark_node
;
4197 ret
.original_code
= ERROR_MARK
;
4198 ret
.original_type
= NULL
;
4199 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4200 pop_init_level (0, &braced_init_obstack
);
4201 obstack_free (&braced_init_obstack
, NULL
);
4204 c_parser_consume_token (parser
);
4205 ret
= pop_init_level (0, &braced_init_obstack
);
4206 obstack_free (&braced_init_obstack
, NULL
);
4210 /* Parse a nested initializer, including designators. */
4213 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4215 /* Parse any designator or designator list. A single array
4216 designator may have the subsequent "=" omitted in GNU C, but a
4217 longer list or a structure member designator may not. */
4218 if (c_parser_next_token_is (parser
, CPP_NAME
)
4219 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4221 /* Old-style structure member designator. */
4222 set_init_label (c_parser_peek_token (parser
)->value
,
4223 braced_init_obstack
);
4224 /* Use the colon as the error location. */
4225 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4226 "obsolete use of designated initializer with %<:%>");
4227 c_parser_consume_token (parser
);
4228 c_parser_consume_token (parser
);
4232 /* des_seen is 0 if there have been no designators, 1 if there
4233 has been a single array designator and 2 otherwise. */
4235 /* Location of a designator. */
4236 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4237 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4238 || c_parser_next_token_is (parser
, CPP_DOT
))
4240 int des_prev
= des_seen
;
4242 des_loc
= c_parser_peek_token (parser
)->location
;
4245 if (c_parser_next_token_is (parser
, CPP_DOT
))
4248 c_parser_consume_token (parser
);
4249 if (c_parser_next_token_is (parser
, CPP_NAME
))
4251 set_init_label (c_parser_peek_token (parser
)->value
,
4252 braced_init_obstack
);
4253 c_parser_consume_token (parser
);
4258 init
.value
= error_mark_node
;
4259 init
.original_code
= ERROR_MARK
;
4260 init
.original_type
= NULL
;
4261 c_parser_error (parser
, "expected identifier");
4262 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4263 process_init_element (init
, false, braced_init_obstack
);
4270 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4271 /* ??? Following the old parser, [ objc-receiver
4272 objc-message-args ] is accepted as an initializer,
4273 being distinguished from a designator by what follows
4274 the first assignment expression inside the square
4275 brackets, but after a first array designator a
4276 subsequent square bracket is for Objective-C taken to
4277 start an expression, using the obsolete form of
4278 designated initializer without '=', rather than
4279 possibly being a second level of designation: in LALR
4280 terms, the '[' is shifted rather than reducing
4281 designator to designator-list. */
4282 if (des_prev
== 1 && c_dialect_objc ())
4284 des_seen
= des_prev
;
4287 if (des_prev
== 0 && c_dialect_objc ())
4289 /* This might be an array designator or an
4290 Objective-C message expression. If the former,
4291 continue parsing here; if the latter, parse the
4292 remainder of the initializer given the starting
4293 primary-expression. ??? It might make sense to
4294 distinguish when des_prev == 1 as well; see
4295 previous comment. */
4297 struct c_expr mexpr
;
4298 c_parser_consume_token (parser
);
4299 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4300 && ((c_parser_peek_token (parser
)->id_kind
4302 || (c_parser_peek_token (parser
)->id_kind
4303 == C_ID_CLASSNAME
)))
4305 /* Type name receiver. */
4306 tree id
= c_parser_peek_token (parser
)->value
;
4307 c_parser_consume_token (parser
);
4308 rec
= objc_get_class_reference (id
);
4309 goto parse_message_args
;
4311 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4312 mark_exp_read (first
);
4313 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4314 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4315 goto array_desig_after_first
;
4316 /* Expression receiver. So far only one part
4317 without commas has been parsed; there might be
4318 more of the expression. */
4320 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4323 location_t comma_loc
, exp_loc
;
4324 comma_loc
= c_parser_peek_token (parser
)->location
;
4325 c_parser_consume_token (parser
);
4326 exp_loc
= c_parser_peek_token (parser
)->location
;
4327 next
= c_parser_expr_no_commas (parser
, NULL
);
4328 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4330 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4333 /* Now parse the objc-message-args. */
4334 args
= c_parser_objc_message_args (parser
);
4335 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4338 = objc_build_message_expr (rec
, args
);
4339 mexpr
.original_code
= ERROR_MARK
;
4340 mexpr
.original_type
= NULL
;
4341 /* Now parse and process the remainder of the
4342 initializer, starting with this message
4343 expression as a primary-expression. */
4344 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4347 c_parser_consume_token (parser
);
4348 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4349 mark_exp_read (first
);
4350 array_desig_after_first
:
4351 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4353 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4354 c_parser_consume_token (parser
);
4355 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4356 mark_exp_read (second
);
4360 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4362 c_parser_consume_token (parser
);
4363 set_init_index (first
, second
, braced_init_obstack
);
4365 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4366 "ISO C forbids specifying range of elements to initialize");
4369 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4375 if (c_parser_next_token_is (parser
, CPP_EQ
))
4378 pedwarn (des_loc
, OPT_Wpedantic
,
4379 "ISO C90 forbids specifying subobject to initialize");
4380 c_parser_consume_token (parser
);
4385 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4386 "obsolete use of designated initializer without %<=%>");
4390 init
.value
= error_mark_node
;
4391 init
.original_code
= ERROR_MARK
;
4392 init
.original_type
= NULL
;
4393 c_parser_error (parser
, "expected %<=%>");
4394 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4395 process_init_element (init
, false, braced_init_obstack
);
4401 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4404 /* Parse a nested initializer; as c_parser_initializer but parses
4405 initializers within braced lists, after any designators have been
4406 applied. If AFTER is not NULL then it is an Objective-C message
4407 expression which is the primary-expression starting the
4411 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4412 struct obstack
* braced_init_obstack
)
4415 gcc_assert (!after
|| c_dialect_objc ());
4416 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4417 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4420 location_t loc
= c_parser_peek_token (parser
)->location
;
4421 init
= c_parser_expr_no_commas (parser
, after
);
4422 if (init
.value
!= NULL_TREE
4423 && TREE_CODE (init
.value
) != STRING_CST
4424 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4425 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4427 process_init_element (init
, false, braced_init_obstack
);
4430 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4434 { block-item-list[opt] }
4435 { label-declarations block-item-list }
4439 block-item-list block-item
4451 { label-declarations block-item-list }
4454 __extension__ nested-declaration
4455 nested-function-definition
4459 label-declarations label-declaration
4462 __label__ identifier-list ;
4464 Allowing the mixing of declarations and code is new in C99. The
4465 GNU syntax also permits (not shown above) labels at the end of
4466 compound statements, which yield an error. We don't allow labels
4467 on declarations; this might seem like a natural extension, but
4468 there would be a conflict between attributes on the label and
4469 prefix attributes on the declaration. ??? The syntax follows the
4470 old parser in requiring something after label declarations.
4471 Although they are erroneous if the labels declared aren't defined,
4472 is it useful for the syntax to be this way?
4485 cancellation-point-directive */
4488 c_parser_compound_statement (c_parser
*parser
)
4491 location_t brace_loc
;
4492 brace_loc
= c_parser_peek_token (parser
)->location
;
4493 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4495 /* Ensure a scope is entered and left anyway to avoid confusion
4496 if we have just prepared to enter a function body. */
4497 stmt
= c_begin_compound_stmt (true);
4498 c_end_compound_stmt (brace_loc
, stmt
, true);
4499 return error_mark_node
;
4501 stmt
= c_begin_compound_stmt (true);
4502 c_parser_compound_statement_nostart (parser
);
4504 /* If the compound stmt contains array notations, then we expand them. */
4505 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4506 stmt
= expand_array_notation_exprs (stmt
);
4507 return c_end_compound_stmt (brace_loc
, stmt
, true);
4510 /* Parse a compound statement except for the opening brace. This is
4511 used for parsing both compound statements and statement expressions
4512 (which follow different paths to handling the opening). */
4515 c_parser_compound_statement_nostart (c_parser
*parser
)
4517 bool last_stmt
= false;
4518 bool last_label
= false;
4519 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4520 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4521 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4523 c_parser_consume_token (parser
);
4526 mark_valid_location_for_stdc_pragma (true);
4527 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4529 /* Read zero or more forward-declarations for labels that nested
4530 functions can jump to. */
4531 mark_valid_location_for_stdc_pragma (false);
4532 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4534 label_loc
= c_parser_peek_token (parser
)->location
;
4535 c_parser_consume_token (parser
);
4536 /* Any identifiers, including those declared as type names,
4541 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4543 c_parser_error (parser
, "expected identifier");
4547 = declare_label (c_parser_peek_token (parser
)->value
);
4548 C_DECLARED_LABEL_FLAG (label
) = 1;
4549 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4550 c_parser_consume_token (parser
);
4551 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4552 c_parser_consume_token (parser
);
4556 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4558 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4560 /* We must now have at least one statement, label or declaration. */
4561 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4563 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4564 c_parser_error (parser
, "expected declaration or statement");
4565 c_parser_consume_token (parser
);
4568 /* Process all #pragma's just after the opening brace. This
4569 handles #pragma upc, which can only appear just after
4570 the opening brace, when it appears within a function body. */
4571 push_upc_consistency_mode ();
4572 permit_pragma_upc ();
4573 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4575 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4576 if (c_parser_pragma (parser
, pragma_compound
))
4577 last_label
= false, last_stmt
= true;
4578 parser
->error
= false;
4581 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4583 location_t loc
= c_parser_peek_token (parser
)->location
;
4584 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4585 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4586 || (c_parser_next_token_is (parser
, CPP_NAME
)
4587 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4589 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4590 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4592 label_loc
= c_parser_peek_token (parser
)->location
;
4595 mark_valid_location_for_stdc_pragma (false);
4596 c_parser_label (parser
);
4598 else if (!last_label
4599 && c_parser_next_tokens_start_declaration (parser
))
4602 mark_valid_location_for_stdc_pragma (false);
4603 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4607 (pedantic
&& !flag_isoc99
)
4609 : OPT_Wdeclaration_after_statement
,
4610 "ISO C90 forbids mixed declarations and code");
4613 else if (!last_label
4614 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4616 /* __extension__ can start a declaration, but is also an
4617 unary operator that can start an expression. Consume all
4618 but the last of a possible series of __extension__ to
4620 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4621 && (c_parser_peek_2nd_token (parser
)->keyword
4623 c_parser_consume_token (parser
);
4624 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4627 ext
= disable_extension_diagnostics ();
4628 c_parser_consume_token (parser
);
4630 mark_valid_location_for_stdc_pragma (false);
4631 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4633 /* Following the old parser, __extension__ does not
4634 disable this diagnostic. */
4635 restore_extension_diagnostics (ext
);
4637 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4639 : OPT_Wdeclaration_after_statement
,
4640 "ISO C90 forbids mixed declarations and code");
4646 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4648 /* External pragmas, and some omp pragmas, are not associated
4649 with regular c code, and so are not to be considered statements
4650 syntactically. This ensures that the user doesn't put them
4651 places that would turn into syntax errors if the directive
4653 if (c_parser_pragma (parser
, pragma_compound
))
4654 last_label
= false, last_stmt
= true;
4656 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4658 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4659 c_parser_error (parser
, "expected declaration or statement");
4662 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4664 if (parser
->in_if_block
)
4666 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4667 error_at (loc
, """expected %<}%> before %<else%>");
4672 error_at (loc
, "%<else%> without a previous %<if%>");
4673 c_parser_consume_token (parser
);
4682 mark_valid_location_for_stdc_pragma (false);
4683 c_parser_statement_after_labels (parser
);
4686 parser
->error
= false;
4689 error_at (label_loc
, "label at end of compound statement");
4690 c_parser_consume_token (parser
);
4691 pop_upc_consistency_mode ();
4692 /* Restore the value we started with. */
4693 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4696 /* Parse a label (C90 6.6.1, C99 6.8.1).
4699 identifier : attributes[opt]
4700 case constant-expression :
4706 case constant-expression ... constant-expression :
4708 The use of attributes on labels is a GNU extension. The syntax in
4709 GNU C accepts any expressions without commas, non-constant
4710 expressions being rejected later. */
4713 c_parser_label (c_parser
*parser
)
4715 location_t loc1
= c_parser_peek_token (parser
)->location
;
4716 tree label
= NULL_TREE
;
4717 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4720 c_parser_consume_token (parser
);
4721 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4722 if (c_parser_next_token_is (parser
, CPP_COLON
))
4724 c_parser_consume_token (parser
);
4725 label
= do_case (loc1
, exp1
, NULL_TREE
);
4727 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4729 c_parser_consume_token (parser
);
4730 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4731 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4732 label
= do_case (loc1
, exp1
, exp2
);
4735 c_parser_error (parser
, "expected %<:%> or %<...%>");
4737 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4739 c_parser_consume_token (parser
);
4740 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4741 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4745 tree name
= c_parser_peek_token (parser
)->value
;
4748 location_t loc2
= c_parser_peek_token (parser
)->location
;
4749 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4750 c_parser_consume_token (parser
);
4751 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4752 c_parser_consume_token (parser
);
4753 attrs
= c_parser_attributes (parser
);
4754 tlab
= define_label (loc2
, name
);
4757 decl_attributes (&tlab
, attrs
, 0);
4758 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4763 if (c_parser_next_tokens_start_declaration (parser
))
4765 error_at (c_parser_peek_token (parser
)->location
,
4766 "a label can only be part of a statement and "
4767 "a declaration is not a statement");
4768 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4769 /*static_assert_ok*/ true,
4770 /*empty_ok*/ true, /*nested*/ true,
4771 /*start_attr_ok*/ true, NULL
,
4777 /* Parse a statement (C90 6.6, C99 6.8).
4782 expression-statement
4790 expression-statement:
4793 selection-statement:
4797 iteration-statement:
4806 return expression[opt] ;
4819 objc-throw-statement
4820 objc-try-catch-statement
4821 objc-synchronized-statement
4823 objc-throw-statement:
4839 parallel-for-construct
4840 parallel-for-simd-construct
4841 parallel-sections-construct
4848 parallel-directive structured-block
4851 for-directive iteration-statement
4854 simd-directive iteration-statements
4857 for-simd-directive iteration-statements
4860 sections-directive section-scope
4863 single-directive structured-block
4865 parallel-for-construct:
4866 parallel-for-directive iteration-statement
4868 parallel-for-simd-construct:
4869 parallel-for-simd-directive iteration-statement
4871 parallel-sections-construct:
4872 parallel-sections-directive section-scope
4875 master-directive structured-block
4878 critical-directive structured-block
4881 atomic-directive expression-statement
4884 ordered-directive structured-block
4886 Transactional Memory:
4889 transaction-statement
4890 transaction-cancel-statement
4894 c_parser_statement (c_parser
*parser
)
4896 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4897 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4898 || (c_parser_next_token_is (parser
, CPP_NAME
)
4899 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4900 c_parser_label (parser
);
4901 c_parser_statement_after_labels (parser
);
4904 /* Parse a statement, other than a labeled statement. */
4907 c_parser_statement_after_labels (c_parser
*parser
)
4909 location_t loc
= c_parser_peek_token (parser
)->location
;
4910 tree stmt
= NULL_TREE
;
4911 bool in_if_block
= parser
->in_if_block
;
4912 parser
->in_if_block
= false;
4913 switch (c_parser_peek_token (parser
)->type
)
4915 case CPP_OPEN_BRACE
:
4916 add_stmt (c_parser_compound_statement (parser
));
4919 switch (c_parser_peek_token (parser
)->keyword
)
4922 c_parser_if_statement (parser
);
4925 c_parser_switch_statement (parser
);
4928 c_parser_while_statement (parser
, false);
4931 c_parser_do_statement (parser
, false);
4934 c_parser_for_statement (parser
, false);
4937 c_parser_consume_token (parser
);
4938 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4940 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4942 add_stmt (build_cilk_sync ());
4945 c_parser_consume_token (parser
);
4946 if (c_parser_next_token_is (parser
, CPP_NAME
))
4948 stmt
= c_finish_goto_label (loc
,
4949 c_parser_peek_token (parser
)->value
);
4950 c_parser_consume_token (parser
);
4952 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4956 c_parser_consume_token (parser
);
4957 val
= c_parser_expression (parser
);
4958 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4959 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4962 c_parser_error (parser
, "expected identifier or %<*%>");
4963 goto expect_semicolon
;
4965 c_parser_consume_token (parser
);
4966 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4967 goto expect_semicolon
;
4969 c_parser_consume_token (parser
);
4970 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4971 goto expect_semicolon
;
4973 c_parser_consume_token (parser
);
4974 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4976 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4977 c_parser_consume_token (parser
);
4981 struct c_expr expr
= c_parser_expression_conv (parser
);
4982 mark_exp_read (expr
.value
);
4983 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4984 goto expect_semicolon
;
4988 stmt
= c_parser_asm_statement (parser
);
4990 case RID_TRANSACTION_ATOMIC
:
4991 case RID_TRANSACTION_RELAXED
:
4992 stmt
= c_parser_transaction (parser
,
4993 c_parser_peek_token (parser
)->keyword
);
4995 case RID_TRANSACTION_CANCEL
:
4996 stmt
= c_parser_transaction_cancel (parser
);
4997 goto expect_semicolon
;
4999 gcc_assert (c_dialect_objc ());
5000 c_parser_consume_token (parser
);
5001 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5003 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5004 c_parser_consume_token (parser
);
5008 struct c_expr expr
= c_parser_expression (parser
);
5009 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5010 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5011 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5012 goto expect_semicolon
;
5016 gcc_assert (c_dialect_objc ());
5017 c_parser_objc_try_catch_finally_statement (parser
);
5019 case RID_AT_SYNCHRONIZED
:
5020 gcc_assert (c_dialect_objc ());
5021 c_parser_objc_synchronized_statement (parser
);
5023 case RID_UPC_FORALL
:
5024 gcc_assert (flag_upc
);
5025 c_parser_upc_forall_statement (parser
);
5027 case RID_UPC_NOTIFY
:
5028 gcc_assert (flag_upc
);
5029 c_parser_upc_sync_statement (parser
, UPC_SYNC_NOTIFY_OP
);
5030 goto expect_semicolon
;
5032 gcc_assert (flag_upc
);
5033 c_parser_upc_sync_statement (parser
, UPC_SYNC_WAIT_OP
);
5034 goto expect_semicolon
;
5035 case RID_UPC_BARRIER
:
5036 gcc_assert (flag_upc
);
5037 c_parser_upc_sync_statement (parser
, UPC_SYNC_BARRIER_OP
);
5038 goto expect_semicolon
;
5044 c_parser_consume_token (parser
);
5046 case CPP_CLOSE_PAREN
:
5047 case CPP_CLOSE_SQUARE
:
5048 /* Avoid infinite loop in error recovery:
5049 c_parser_skip_until_found stops at a closing nesting
5050 delimiter without consuming it, but here we need to consume
5051 it to proceed further. */
5052 c_parser_error (parser
, "expected statement");
5053 c_parser_consume_token (parser
);
5056 c_parser_pragma (parser
, pragma_stmt
);
5060 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5062 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5065 /* Two cases cannot and do not have line numbers associated: If stmt
5066 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5067 cannot hold line numbers. But that's OK because the statement
5068 will either be changed to a MODIFY_EXPR during gimplification of
5069 the statement expr, or discarded. If stmt was compound, but
5070 without new variables, we will have skipped the creation of a
5071 BIND and will have a bare STATEMENT_LIST. But that's OK because
5072 (recursively) all of the component statements should already have
5073 line numbers assigned. ??? Can we discard no-op statements
5075 if (CAN_HAVE_LOCATION_P (stmt
)
5076 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5077 SET_EXPR_LOCATION (stmt
, loc
);
5079 parser
->in_if_block
= in_if_block
;
5082 /* Parse the condition from an if, do, while or for statements. */
5085 c_parser_condition (c_parser
*parser
)
5087 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
5089 cond
= c_parser_expression_conv (parser
).value
;
5090 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5091 cond
= c_fully_fold (cond
, false, NULL
);
5092 if (warn_sequence_point
)
5093 verify_sequence_points (cond
);
5097 /* Parse a parenthesized condition from an if, do or while statement.
5103 c_parser_paren_condition (c_parser
*parser
)
5106 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5107 return error_mark_node
;
5108 cond
= c_parser_condition (parser
);
5109 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5113 /* Parse a statement which is a block in C99. */
5116 c_parser_c99_block_statement (c_parser
*parser
)
5118 tree block
= c_begin_compound_stmt (flag_isoc99
);
5119 location_t loc
= c_parser_peek_token (parser
)->location
;
5120 c_parser_statement (parser
);
5121 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5124 /* Parse the body of an if statement. This is just parsing a
5125 statement but (a) it is a block in C99, (b) we track whether the
5126 body is an if statement for the sake of -Wparentheses warnings, (c)
5127 we handle an empty body specially for the sake of -Wempty-body
5128 warnings, and (d) we call parser_compound_statement directly
5129 because c_parser_statement_after_labels resets
5130 parser->in_if_block. */
5133 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5135 tree block
= c_begin_compound_stmt (flag_isoc99
);
5136 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5137 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5138 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5139 || (c_parser_next_token_is (parser
, CPP_NAME
)
5140 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5141 c_parser_label (parser
);
5142 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5143 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5145 location_t loc
= c_parser_peek_token (parser
)->location
;
5146 add_stmt (build_empty_stmt (loc
));
5147 c_parser_consume_token (parser
);
5148 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5149 warning_at (loc
, OPT_Wempty_body
,
5150 "suggest braces around empty body in an %<if%> statement");
5152 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5153 add_stmt (c_parser_compound_statement (parser
));
5155 c_parser_statement_after_labels (parser
);
5156 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5159 /* Parse the else body of an if statement. This is just parsing a
5160 statement but (a) it is a block in C99, (b) we handle an empty body
5161 specially for the sake of -Wempty-body warnings. */
5164 c_parser_else_body (c_parser
*parser
)
5166 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5167 tree block
= c_begin_compound_stmt (flag_isoc99
);
5168 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5169 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5170 || (c_parser_next_token_is (parser
, CPP_NAME
)
5171 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5172 c_parser_label (parser
);
5173 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5175 location_t loc
= c_parser_peek_token (parser
)->location
;
5178 "suggest braces around empty body in an %<else%> statement");
5179 add_stmt (build_empty_stmt (loc
));
5180 c_parser_consume_token (parser
);
5183 c_parser_statement_after_labels (parser
);
5184 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5187 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5190 if ( expression ) statement
5191 if ( expression ) statement else statement
5195 c_parser_if_statement (c_parser
*parser
)
5200 bool first_if
= false;
5201 tree first_body
, second_body
;
5205 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5206 c_parser_consume_token (parser
);
5207 block
= c_begin_compound_stmt (flag_isoc99
);
5208 loc
= c_parser_peek_token (parser
)->location
;
5209 cond
= c_parser_paren_condition (parser
);
5210 in_if_block
= parser
->in_if_block
;
5211 parser
->in_if_block
= true;
5212 first_body
= c_parser_if_body (parser
, &first_if
);
5213 parser
->in_if_block
= in_if_block
;
5214 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5216 c_parser_consume_token (parser
);
5217 second_body
= c_parser_else_body (parser
);
5220 second_body
= NULL_TREE
;
5221 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5222 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5224 /* If the if statement contains array notations, then we expand them. */
5225 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5226 if_stmt
= fix_conditional_array_notations (if_stmt
);
5230 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5233 switch (expression) statement
5237 c_parser_switch_statement (c_parser
*parser
)
5240 tree block
, expr
, body
, save_break
;
5241 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5242 location_t switch_cond_loc
;
5243 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5244 c_parser_consume_token (parser
);
5245 block
= c_begin_compound_stmt (flag_isoc99
);
5246 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5248 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5249 ce
= c_parser_expression (parser
);
5250 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5252 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5254 error_at (switch_cond_loc
,
5255 "array notations cannot be used as a condition for switch "
5257 expr
= error_mark_node
;
5259 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5263 switch_cond_loc
= UNKNOWN_LOCATION
;
5264 expr
= error_mark_node
;
5266 c_start_case (switch_loc
, switch_cond_loc
, expr
);
5267 save_break
= c_break_label
;
5268 c_break_label
= NULL_TREE
;
5269 body
= c_parser_c99_block_statement (parser
);
5270 c_finish_case (body
);
5273 location_t here
= c_parser_peek_token (parser
)->location
;
5274 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5275 SET_EXPR_LOCATION (t
, here
);
5278 c_break_label
= save_break
;
5279 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5282 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5285 while (expression) statement
5289 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5291 tree block
, cond
, body
, save_break
, save_cont
;
5293 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5294 c_parser_consume_token (parser
);
5295 block
= c_begin_compound_stmt (flag_isoc99
);
5296 loc
= c_parser_peek_token (parser
)->location
;
5297 cond
= c_parser_paren_condition (parser
);
5298 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5300 error_at (loc
, "array notations cannot be used as a condition for while "
5302 cond
= error_mark_node
;
5305 if (ivdep
&& cond
!= error_mark_node
)
5306 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5307 build_int_cst (integer_type_node
,
5308 annot_expr_ivdep_kind
));
5309 save_break
= c_break_label
;
5310 c_break_label
= NULL_TREE
;
5311 save_cont
= c_cont_label
;
5312 c_cont_label
= NULL_TREE
;
5313 body
= c_parser_c99_block_statement (parser
);
5314 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5315 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5316 c_break_label
= save_break
;
5317 c_cont_label
= save_cont
;
5320 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5323 do statement while ( expression ) ;
5327 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5329 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5331 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5332 c_parser_consume_token (parser
);
5333 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5334 warning_at (c_parser_peek_token (parser
)->location
,
5336 "suggest braces around empty body in %<do%> statement");
5337 block
= c_begin_compound_stmt (flag_isoc99
);
5338 loc
= c_parser_peek_token (parser
)->location
;
5339 save_break
= c_break_label
;
5340 c_break_label
= NULL_TREE
;
5341 save_cont
= c_cont_label
;
5342 c_cont_label
= NULL_TREE
;
5343 body
= c_parser_c99_block_statement (parser
);
5344 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5345 new_break
= c_break_label
;
5346 c_break_label
= save_break
;
5347 new_cont
= c_cont_label
;
5348 c_cont_label
= save_cont
;
5349 cond
= c_parser_paren_condition (parser
);
5350 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5352 error_at (loc
, "array notations cannot be used as a condition for a "
5353 "do-while statement");
5354 cond
= error_mark_node
;
5356 if (ivdep
&& cond
!= error_mark_node
)
5357 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5358 build_int_cst (integer_type_node
,
5359 annot_expr_ivdep_kind
));
5360 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5361 c_parser_skip_to_end_of_block_or_statement (parser
);
5362 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5363 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5366 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5369 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5370 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5372 The form with a declaration is new in C99.
5374 ??? In accordance with the old parser, the declaration may be a
5375 nested function, which is then rejected in check_for_loop_decls,
5376 but does it make any sense for this to be included in the grammar?
5377 Note in particular that the nested function does not include a
5378 trailing ';', whereas the "declaration" production includes one.
5379 Also, can we reject bad declarations earlier and cheaper than
5380 check_for_loop_decls?
5382 In Objective-C, there are two additional variants:
5385 for ( expression in expresssion ) statement
5386 for ( declaration in expression ) statement
5388 This is inconsistent with C, because the second variant is allowed
5389 even if c99 is not enabled.
5391 The rest of the comment documents these Objective-C foreach-statement.
5393 Here is the canonical example of the first variant:
5394 for (object in array) { do something with object }
5395 we call the first expression ("object") the "object_expression" and
5396 the second expression ("array") the "collection_expression".
5397 object_expression must be an lvalue of type "id" (a generic Objective-C
5398 object) because the loop works by assigning to object_expression the
5399 various objects from the collection_expression. collection_expression
5400 must evaluate to something of type "id" which responds to the method
5401 countByEnumeratingWithState:objects:count:.
5403 The canonical example of the second variant is:
5404 for (id object in array) { do something with object }
5405 which is completely equivalent to
5408 for (object in array) { do something with object }
5410 Note that initizializing 'object' in some way (eg, "for ((object =
5411 xxx) in array) { do something with object }") is possibly
5412 technically valid, but completely pointless as 'object' will be
5413 assigned to something else as soon as the loop starts. We should
5414 most likely reject it (TODO).
5416 The beginning of the Objective-C foreach-statement looks exactly
5417 like the beginning of the for-statement, and we can tell it is a
5418 foreach-statement only because the initial declaration or
5419 expression is terminated by 'in' instead of ';'.
5423 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5425 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5426 /* The following are only used when parsing an ObjC foreach statement. */
5427 tree object_expression
;
5428 /* Silence the bogus uninitialized warning. */
5429 tree collection_expression
= NULL
;
5430 location_t loc
= c_parser_peek_token (parser
)->location
;
5431 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5432 bool is_foreach_statement
= false;
5433 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5434 c_parser_consume_token (parser
);
5435 /* Open a compound statement in Objective-C as well, just in case this is
5436 as foreach expression. */
5437 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5438 cond
= error_mark_node
;
5439 incr
= error_mark_node
;
5440 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5442 /* Parse the initialization declaration or expression. */
5443 object_expression
= error_mark_node
;
5444 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5445 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5447 parser
->objc_could_be_foreach_context
= false;
5448 c_parser_consume_token (parser
);
5449 c_finish_expr_stmt (loc
, NULL_TREE
);
5451 else if (c_parser_next_tokens_start_declaration (parser
))
5453 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5454 &object_expression
, vNULL
);
5455 parser
->objc_could_be_foreach_context
= false;
5457 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5459 c_parser_consume_token (parser
);
5460 is_foreach_statement
= true;
5461 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5462 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5465 check_for_loop_decls (for_loc
, flag_isoc99
);
5467 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5469 /* __extension__ can start a declaration, but is also an
5470 unary operator that can start an expression. Consume all
5471 but the last of a possible series of __extension__ to
5473 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5474 && (c_parser_peek_2nd_token (parser
)->keyword
5476 c_parser_consume_token (parser
);
5477 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5480 ext
= disable_extension_diagnostics ();
5481 c_parser_consume_token (parser
);
5482 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5483 true, &object_expression
, vNULL
);
5484 parser
->objc_could_be_foreach_context
= false;
5486 restore_extension_diagnostics (ext
);
5487 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5489 c_parser_consume_token (parser
);
5490 is_foreach_statement
= true;
5491 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5492 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5495 check_for_loop_decls (for_loc
, flag_isoc99
);
5505 tree init_expression
;
5506 ce
= c_parser_expression (parser
);
5507 init_expression
= ce
.value
;
5508 parser
->objc_could_be_foreach_context
= false;
5509 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5511 c_parser_consume_token (parser
);
5512 is_foreach_statement
= true;
5513 if (! lvalue_p (init_expression
))
5514 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5515 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5519 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5520 init_expression
= ce
.value
;
5521 c_finish_expr_stmt (loc
, init_expression
);
5522 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5526 /* Parse the loop condition. In the case of a foreach
5527 statement, there is no loop condition. */
5528 gcc_assert (!parser
->objc_could_be_foreach_context
);
5529 if (!is_foreach_statement
)
5531 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5535 c_parser_error (parser
, "missing loop condition in loop with "
5536 "%<GCC ivdep%> pragma");
5537 cond
= error_mark_node
;
5541 c_parser_consume_token (parser
);
5547 cond
= c_parser_condition (parser
);
5548 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5550 error_at (loc
, "array notations cannot be used in a "
5551 "condition for a for-loop");
5552 cond
= error_mark_node
;
5554 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5557 if (ivdep
&& cond
!= error_mark_node
)
5558 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5559 build_int_cst (integer_type_node
,
5560 annot_expr_ivdep_kind
));
5562 /* Parse the increment expression (the third expression in a
5563 for-statement). In the case of a foreach-statement, this is
5564 the expression that follows the 'in'. */
5565 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5567 if (is_foreach_statement
)
5569 c_parser_error (parser
, "missing collection in fast enumeration");
5570 collection_expression
= error_mark_node
;
5573 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5577 if (is_foreach_statement
)
5578 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5582 struct c_expr ce
= c_parser_expression (parser
);
5583 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5584 incr
= c_process_expr_stmt (loc
, ce
.value
);
5587 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5589 save_break
= c_break_label
;
5590 c_break_label
= NULL_TREE
;
5591 save_cont
= c_cont_label
;
5592 c_cont_label
= NULL_TREE
;
5593 body
= c_parser_c99_block_statement (parser
);
5594 if (is_foreach_statement
)
5595 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5597 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5598 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5599 c_break_label
= save_break
;
5600 c_cont_label
= save_cont
;
5603 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5604 statement with inputs, outputs, clobbers, and volatile tag
5608 asm type-qualifier[opt] ( asm-argument ) ;
5609 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5613 asm-string-literal : asm-operands[opt]
5614 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5615 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5618 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5621 Qualifiers other than volatile are accepted in the syntax but
5625 c_parser_asm_statement (c_parser
*parser
)
5627 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5628 bool simple
, is_goto
;
5629 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5630 int section
, nsections
;
5632 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5633 c_parser_consume_token (parser
);
5634 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5636 quals
= c_parser_peek_token (parser
)->value
;
5637 c_parser_consume_token (parser
);
5639 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5640 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5642 warning_at (c_parser_peek_token (parser
)->location
,
5644 "%E qualifier ignored on asm",
5645 c_parser_peek_token (parser
)->value
);
5647 c_parser_consume_token (parser
);
5653 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5655 c_parser_consume_token (parser
);
5659 /* ??? Follow the C++ parser rather than using the
5660 lex_untranslated_string kludge. */
5661 parser
->lex_untranslated_string
= true;
5664 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5667 str
= c_parser_asm_string_literal (parser
);
5668 if (str
== NULL_TREE
)
5669 goto error_close_paren
;
5672 outputs
= NULL_TREE
;
5674 clobbers
= NULL_TREE
;
5677 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5680 /* Parse each colon-delimited section of operands. */
5681 nsections
= 3 + is_goto
;
5682 for (section
= 0; section
< nsections
; ++section
)
5684 if (!c_parser_require (parser
, CPP_COLON
,
5687 : "expected %<:%> or %<)%>"))
5688 goto error_close_paren
;
5690 /* Once past any colon, we're no longer a simple asm. */
5693 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5694 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5699 /* For asm goto, we don't allow output operands, but reserve
5700 the slot for a future extension that does allow them. */
5702 outputs
= c_parser_asm_operands (parser
);
5705 inputs
= c_parser_asm_operands (parser
);
5708 clobbers
= c_parser_asm_clobbers (parser
);
5711 labels
= c_parser_asm_goto_operands (parser
);
5717 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5722 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5724 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5728 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5729 c_parser_skip_to_end_of_block_or_statement (parser
);
5731 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5732 clobbers
, labels
, simple
));
5735 parser
->lex_untranslated_string
= false;
5739 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5743 /* Parse asm operands, a GNU extension.
5747 asm-operands , asm-operand
5750 asm-string-literal ( expression )
5751 [ identifier ] asm-string-literal ( expression )
5755 c_parser_asm_operands (c_parser
*parser
)
5757 tree list
= NULL_TREE
;
5762 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5764 c_parser_consume_token (parser
);
5765 if (c_parser_next_token_is (parser
, CPP_NAME
))
5767 tree id
= c_parser_peek_token (parser
)->value
;
5768 c_parser_consume_token (parser
);
5769 name
= build_string (IDENTIFIER_LENGTH (id
),
5770 IDENTIFIER_POINTER (id
));
5774 c_parser_error (parser
, "expected identifier");
5775 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5778 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5783 str
= c_parser_asm_string_literal (parser
);
5784 if (str
== NULL_TREE
)
5786 parser
->lex_untranslated_string
= false;
5787 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5789 parser
->lex_untranslated_string
= true;
5792 expr
= c_parser_expression (parser
);
5793 mark_exp_read (expr
.value
);
5794 parser
->lex_untranslated_string
= true;
5795 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5797 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5800 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5802 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5803 c_parser_consume_token (parser
);
5810 /* Parse asm clobbers, a GNU extension.
5814 asm-clobbers , asm-string-literal
5818 c_parser_asm_clobbers (c_parser
*parser
)
5820 tree list
= NULL_TREE
;
5823 tree str
= c_parser_asm_string_literal (parser
);
5825 list
= tree_cons (NULL_TREE
, str
, list
);
5828 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5829 c_parser_consume_token (parser
);
5836 /* Parse asm goto labels, a GNU extension.
5840 asm-goto-operands , identifier
5844 c_parser_asm_goto_operands (c_parser
*parser
)
5846 tree list
= NULL_TREE
;
5851 if (c_parser_next_token_is (parser
, CPP_NAME
))
5853 c_token
*tok
= c_parser_peek_token (parser
);
5855 label
= lookup_label_for_goto (tok
->location
, name
);
5856 c_parser_consume_token (parser
);
5857 TREE_USED (label
) = 1;
5861 c_parser_error (parser
, "expected identifier");
5865 name
= build_string (IDENTIFIER_LENGTH (name
),
5866 IDENTIFIER_POINTER (name
));
5867 list
= tree_cons (name
, label
, list
);
5868 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5869 c_parser_consume_token (parser
);
5871 return nreverse (list
);
5875 /* Parse an expression other than a compound expression; that is, an
5876 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5877 NULL then it is an Objective-C message expression which is the
5878 primary-expression starting the expression as an initializer.
5880 assignment-expression:
5881 conditional-expression
5882 unary-expression assignment-operator assignment-expression
5884 assignment-operator: one of
5885 = *= /= %= += -= <<= >>= &= ^= |=
5887 In GNU C we accept any conditional expression on the LHS and
5888 diagnose the invalid lvalue rather than producing a syntax
5891 static struct c_expr
5892 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5893 tree omp_atomic_lhs
)
5895 struct c_expr lhs
, rhs
, ret
;
5896 enum tree_code code
;
5897 location_t op_location
, exp_location
;
5898 gcc_assert (!after
|| c_dialect_objc ());
5899 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5900 op_location
= c_parser_peek_token (parser
)->location
;
5901 switch (c_parser_peek_token (parser
)->type
)
5910 code
= TRUNC_DIV_EXPR
;
5913 code
= TRUNC_MOD_EXPR
;
5928 code
= BIT_AND_EXPR
;
5931 code
= BIT_XOR_EXPR
;
5934 code
= BIT_IOR_EXPR
;
5939 c_parser_consume_token (parser
);
5940 exp_location
= c_parser_peek_token (parser
)->location
;
5941 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5942 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5944 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5945 code
, exp_location
, rhs
.value
,
5947 if (code
== NOP_EXPR
)
5948 ret
.original_code
= MODIFY_EXPR
;
5951 TREE_NO_WARNING (ret
.value
) = 1;
5952 ret
.original_code
= ERROR_MARK
;
5954 ret
.original_type
= NULL
;
5958 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5959 is not NULL then it is an Objective-C message expression which is
5960 the primary-expression starting the expression as an initializer.
5962 conditional-expression:
5963 logical-OR-expression
5964 logical-OR-expression ? expression : conditional-expression
5968 conditional-expression:
5969 logical-OR-expression ? : conditional-expression
5972 static struct c_expr
5973 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5974 tree omp_atomic_lhs
)
5976 struct c_expr cond
, exp1
, exp2
, ret
;
5977 location_t cond_loc
, colon_loc
, middle_loc
;
5979 gcc_assert (!after
|| c_dialect_objc ());
5981 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5983 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5985 cond_loc
= c_parser_peek_token (parser
)->location
;
5986 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5987 c_parser_consume_token (parser
);
5988 if (c_parser_next_token_is (parser
, CPP_COLON
))
5990 tree eptype
= NULL_TREE
;
5992 middle_loc
= c_parser_peek_token (parser
)->location
;
5993 pedwarn (middle_loc
, OPT_Wpedantic
,
5994 "ISO C forbids omitting the middle term of a ?: expression");
5995 warn_for_omitted_condop (middle_loc
, cond
.value
);
5996 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5998 eptype
= TREE_TYPE (cond
.value
);
5999 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6001 /* Make sure first operand is calculated only once. */
6002 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6004 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6005 exp1
.original_type
= NULL
;
6006 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6007 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6012 = c_objc_common_truthvalue_conversion
6013 (cond_loc
, default_conversion (cond
.value
));
6014 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6015 exp1
= c_parser_expression_conv (parser
);
6016 mark_exp_read (exp1
.value
);
6017 c_inhibit_evaluation_warnings
+=
6018 ((cond
.value
== truthvalue_true_node
)
6019 - (cond
.value
== truthvalue_false_node
));
6022 colon_loc
= c_parser_peek_token (parser
)->location
;
6023 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6025 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6026 ret
.value
= error_mark_node
;
6027 ret
.original_code
= ERROR_MARK
;
6028 ret
.original_type
= NULL
;
6032 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6033 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6034 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6036 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6037 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6038 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6039 exp1
.value
, exp1
.original_type
,
6040 exp2
.value
, exp2
.original_type
);
6041 ret
.original_code
= ERROR_MARK
;
6042 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6043 ret
.original_type
= NULL
;
6048 /* If both sides are enum type, the default conversion will have
6049 made the type of the result be an integer type. We want to
6050 remember the enum types we started with. */
6051 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6052 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6053 ret
.original_type
= ((t1
!= error_mark_node
6054 && t2
!= error_mark_node
6055 && (TYPE_MAIN_VARIANT (t1
)
6056 == TYPE_MAIN_VARIANT (t2
)))
6063 /* Parse a binary expression; that is, a logical-OR-expression (C90
6064 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6065 an Objective-C message expression which is the primary-expression
6066 starting the expression as an initializer.
6068 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6069 when it should be the unfolded lhs. In a valid OpenMP source,
6070 one of the operands of the toplevel binary expression must be equal
6071 to it. In that case, just return a build2 created binary operation
6072 rather than result of parser_build_binary_op.
6074 multiplicative-expression:
6076 multiplicative-expression * cast-expression
6077 multiplicative-expression / cast-expression
6078 multiplicative-expression % cast-expression
6080 additive-expression:
6081 multiplicative-expression
6082 additive-expression + multiplicative-expression
6083 additive-expression - multiplicative-expression
6087 shift-expression << additive-expression
6088 shift-expression >> additive-expression
6090 relational-expression:
6092 relational-expression < shift-expression
6093 relational-expression > shift-expression
6094 relational-expression <= shift-expression
6095 relational-expression >= shift-expression
6097 equality-expression:
6098 relational-expression
6099 equality-expression == relational-expression
6100 equality-expression != relational-expression
6104 AND-expression & equality-expression
6106 exclusive-OR-expression:
6108 exclusive-OR-expression ^ AND-expression
6110 inclusive-OR-expression:
6111 exclusive-OR-expression
6112 inclusive-OR-expression | exclusive-OR-expression
6114 logical-AND-expression:
6115 inclusive-OR-expression
6116 logical-AND-expression && inclusive-OR-expression
6118 logical-OR-expression:
6119 logical-AND-expression
6120 logical-OR-expression || logical-AND-expression
6123 static struct c_expr
6124 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6125 tree omp_atomic_lhs
)
6127 /* A binary expression is parsed using operator-precedence parsing,
6128 with the operands being cast expressions. All the binary
6129 operators are left-associative. Thus a binary expression is of
6132 E0 op1 E1 op2 E2 ...
6134 which we represent on a stack. On the stack, the precedence
6135 levels are strictly increasing. When a new operator is
6136 encountered of higher precedence than that at the top of the
6137 stack, it is pushed; its LHS is the top expression, and its RHS
6138 is everything parsed until it is popped. When a new operator is
6139 encountered with precedence less than or equal to that at the top
6140 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6141 by the result of the operation until the operator at the top of
6142 the stack has lower precedence than the new operator or there is
6143 only one element on the stack; then the top expression is the LHS
6144 of the new operator. In the case of logical AND and OR
6145 expressions, we also need to adjust c_inhibit_evaluation_warnings
6146 as appropriate when the operators are pushed and popped. */
6149 /* The expression at this stack level. */
6151 /* The precedence of the operator on its left, PREC_NONE at the
6152 bottom of the stack. */
6153 enum c_parser_prec prec
;
6154 /* The operation on its left. */
6156 /* The source location of this operation. */
6160 /* Location of the binary operator. */
6161 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6164 switch (stack[sp].op) \
6166 case TRUTH_ANDIF_EXPR: \
6167 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6168 == truthvalue_false_node); \
6170 case TRUTH_ORIF_EXPR: \
6171 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6172 == truthvalue_true_node); \
6177 stack[sp - 1].expr \
6178 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6179 stack[sp - 1].expr, true, true); \
6181 = convert_lvalue_to_rvalue (stack[sp].loc, \
6182 stack[sp].expr, true, true); \
6183 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6184 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6185 && ((1 << stack[sp].prec) \
6186 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6187 | PREC_ADD | PREC_MULT))) \
6188 && stack[sp].op != TRUNC_MOD_EXPR \
6189 && stack[0].expr.value != error_mark_node \
6190 && stack[1].expr.value != error_mark_node \
6191 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6192 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6193 stack[0].expr.value \
6194 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6195 stack[0].expr.value, stack[1].expr.value); \
6197 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6199 stack[sp - 1].expr, \
6203 gcc_assert (!after
|| c_dialect_objc ());
6204 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6205 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6206 stack
[0].prec
= PREC_NONE
;
6210 enum c_parser_prec oprec
;
6211 enum tree_code ocode
;
6214 switch (c_parser_peek_token (parser
)->type
)
6222 ocode
= TRUNC_DIV_EXPR
;
6226 ocode
= TRUNC_MOD_EXPR
;
6238 ocode
= LSHIFT_EXPR
;
6242 ocode
= RSHIFT_EXPR
;
6256 case CPP_GREATER_EQ
:
6269 oprec
= PREC_BITAND
;
6270 ocode
= BIT_AND_EXPR
;
6273 oprec
= PREC_BITXOR
;
6274 ocode
= BIT_XOR_EXPR
;
6278 ocode
= BIT_IOR_EXPR
;
6281 oprec
= PREC_LOGAND
;
6282 ocode
= TRUTH_ANDIF_EXPR
;
6286 ocode
= TRUTH_ORIF_EXPR
;
6289 /* Not a binary operator, so end of the binary
6293 binary_loc
= c_parser_peek_token (parser
)->location
;
6294 while (oprec
<= stack
[sp
].prec
)
6296 c_parser_consume_token (parser
);
6299 case TRUTH_ANDIF_EXPR
:
6301 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6302 stack
[sp
].expr
, true, true);
6303 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6304 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6305 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6306 == truthvalue_false_node
);
6308 case TRUTH_ORIF_EXPR
:
6310 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6311 stack
[sp
].expr
, true, true);
6312 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6313 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6314 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6315 == truthvalue_true_node
);
6321 stack
[sp
].loc
= binary_loc
;
6322 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6323 stack
[sp
].prec
= oprec
;
6324 stack
[sp
].op
= ocode
;
6325 stack
[sp
].loc
= binary_loc
;
6330 return stack
[0].expr
;
6334 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6335 NULL then it is an Objective-C message expression which is the
6336 primary-expression starting the expression as an initializer.
6340 ( type-name ) unary-expression
6343 static struct c_expr
6344 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6346 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6347 gcc_assert (!after
|| c_dialect_objc ());
6349 return c_parser_postfix_expression_after_primary (parser
,
6351 /* If the expression begins with a parenthesized type name, it may
6352 be either a cast or a compound literal; we need to see whether
6353 the next character is '{' to tell the difference. If not, it is
6354 an unary expression. Full detection of unknown typenames here
6355 would require a 3-token lookahead. */
6356 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6357 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6359 struct c_type_name
*type_name
;
6362 c_parser_consume_token (parser
);
6363 type_name
= c_parser_type_name (parser
);
6364 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6365 if (type_name
== NULL
)
6367 ret
.value
= error_mark_node
;
6368 ret
.original_code
= ERROR_MARK
;
6369 ret
.original_type
= NULL
;
6373 /* Save casted types in the function's used types hash table. */
6374 used_types_insert (type_name
->specs
->type
);
6376 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6377 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6380 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6381 expr
= c_parser_cast_expression (parser
, NULL
);
6382 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6384 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6385 ret
.original_code
= ERROR_MARK
;
6386 ret
.original_type
= NULL
;
6390 return c_parser_unary_expression (parser
);
6393 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6399 unary-operator cast-expression
6400 sizeof unary-expression
6401 sizeof ( type-name )
6403 unary-operator: one of
6409 __alignof__ unary-expression
6410 __alignof__ ( type-name )
6413 (C11 permits _Alignof with type names only.)
6415 unary-operator: one of
6416 __extension__ __real__ __imag__
6418 Transactional Memory:
6421 transaction-expression
6423 In addition, the GNU syntax treats ++ and -- as unary operators, so
6424 they may be applied to cast expressions with errors for non-lvalues
6427 static struct c_expr
6428 c_parser_unary_expression (c_parser
*parser
)
6431 struct c_expr ret
, op
;
6432 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6434 ret
.original_code
= ERROR_MARK
;
6435 ret
.original_type
= NULL
;
6436 switch (c_parser_peek_token (parser
)->type
)
6439 c_parser_consume_token (parser
);
6440 exp_loc
= c_parser_peek_token (parser
)->location
;
6441 op
= c_parser_cast_expression (parser
, NULL
);
6443 /* If there is array notations in op, we expand them. */
6444 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6445 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6448 op
= default_function_array_read_conversion (exp_loc
, op
);
6449 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6451 case CPP_MINUS_MINUS
:
6452 c_parser_consume_token (parser
);
6453 exp_loc
= c_parser_peek_token (parser
)->location
;
6454 op
= c_parser_cast_expression (parser
, NULL
);
6456 /* If there is array notations in op, we expand them. */
6457 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6458 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6461 op
= default_function_array_read_conversion (exp_loc
, op
);
6462 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6465 c_parser_consume_token (parser
);
6466 op
= c_parser_cast_expression (parser
, NULL
);
6467 mark_exp_read (op
.value
);
6468 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6470 c_parser_consume_token (parser
);
6471 exp_loc
= c_parser_peek_token (parser
)->location
;
6472 op
= c_parser_cast_expression (parser
, NULL
);
6473 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6474 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6477 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6480 "traditional C rejects the unary plus operator");
6481 c_parser_consume_token (parser
);
6482 exp_loc
= c_parser_peek_token (parser
)->location
;
6483 op
= c_parser_cast_expression (parser
, NULL
);
6484 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6485 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6487 c_parser_consume_token (parser
);
6488 exp_loc
= c_parser_peek_token (parser
)->location
;
6489 op
= c_parser_cast_expression (parser
, NULL
);
6490 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6491 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6493 c_parser_consume_token (parser
);
6494 exp_loc
= c_parser_peek_token (parser
)->location
;
6495 op
= c_parser_cast_expression (parser
, NULL
);
6496 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6497 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6499 c_parser_consume_token (parser
);
6500 exp_loc
= c_parser_peek_token (parser
)->location
;
6501 op
= c_parser_cast_expression (parser
, NULL
);
6502 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6503 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6505 /* Refer to the address of a label as a pointer. */
6506 c_parser_consume_token (parser
);
6507 if (c_parser_next_token_is (parser
, CPP_NAME
))
6509 ret
.value
= finish_label_address_expr
6510 (c_parser_peek_token (parser
)->value
, op_loc
);
6511 c_parser_consume_token (parser
);
6515 c_parser_error (parser
, "expected identifier");
6516 ret
.value
= error_mark_node
;
6520 switch (c_parser_peek_token (parser
)->keyword
)
6523 return c_parser_sizeof_expression (parser
);
6524 case RID_UPC_BLOCKSIZEOF
:
6525 case RID_UPC_ELEMSIZEOF
:
6526 case RID_UPC_LOCALSIZEOF
:
6527 gcc_assert (flag_upc
);
6528 return c_parser_sizeof_expression (parser
);
6530 return c_parser_alignof_expression (parser
);
6532 c_parser_consume_token (parser
);
6533 ext
= disable_extension_diagnostics ();
6534 ret
= c_parser_cast_expression (parser
, NULL
);
6535 restore_extension_diagnostics (ext
);
6538 c_parser_consume_token (parser
);
6539 exp_loc
= c_parser_peek_token (parser
)->location
;
6540 op
= c_parser_cast_expression (parser
, NULL
);
6541 op
= default_function_array_conversion (exp_loc
, op
);
6542 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6544 c_parser_consume_token (parser
);
6545 exp_loc
= c_parser_peek_token (parser
)->location
;
6546 op
= c_parser_cast_expression (parser
, NULL
);
6547 op
= default_function_array_conversion (exp_loc
, op
);
6548 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6549 case RID_TRANSACTION_ATOMIC
:
6550 case RID_TRANSACTION_RELAXED
:
6551 return c_parser_transaction_expression (parser
,
6552 c_parser_peek_token (parser
)->keyword
);
6554 return c_parser_postfix_expression (parser
);
6557 return c_parser_postfix_expression (parser
);
6561 /* Return the result of upc_blocksizeof applied to EXPR. */
6565 upc_blocksizeof_expr (location_t loc
, struct c_expr expr
)
6568 ret
.original_code
= ERROR_MARK
;
6569 ret
.original_type
= NULL_TREE
;
6570 if (expr
.value
== error_mark_node
)
6572 ret
.value
= error_mark_node
;
6573 pop_maybe_used (false);
6577 ret
.value
= upc_blocksizeof (loc
, TREE_TYPE (expr
.value
));
6578 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6583 /* Return the result of upc_blocksizeof applied to T, a structure
6584 for the type name passed to sizeof (rather than the type itself). */
6588 upc_blocksizeof_type (location_t loc
, struct c_type_name
*t
)
6592 ret
.original_code
= ERROR_MARK
;
6593 ret
.original_type
= NULL_TREE
;
6594 type
= groktypename (t
, NULL
, NULL
);
6595 if (type
== error_mark_node
)
6597 ret
.value
= error_mark_node
;
6598 pop_maybe_used (false);
6602 ret
.value
= upc_blocksizeof (loc
, type
);
6603 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6608 /* Return the result of upc_elemsizeof applied to EXPR. */
6612 upc_elemsizeof_expr (location_t loc
, struct c_expr expr
)
6615 ret
.original_code
= ERROR_MARK
;
6616 ret
.original_type
= NULL_TREE
;
6617 if (expr
.value
== error_mark_node
)
6619 ret
.value
= error_mark_node
;
6620 pop_maybe_used (false);
6624 ret
.value
= upc_elemsizeof (loc
, TREE_TYPE (expr
.value
));
6625 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6630 /* Return the result of upc_elemsizeof applied to T, a structure
6631 for the type name passed to sizeof (rather than the type itself). */
6635 upc_elemsizeof_type (location_t loc
, struct c_type_name
*t
)
6639 ret
.original_code
= ERROR_MARK
;
6640 ret
.original_type
= NULL_TREE
;
6641 type
= groktypename (t
, NULL
, NULL
);
6642 if (type
== error_mark_node
)
6644 ret
.value
= error_mark_node
;
6645 pop_maybe_used (false);
6649 ret
.value
= upc_elemsizeof (loc
, type
);
6650 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6655 /* Return the result of upc_localsizeof applied to EXPR. */
6659 upc_localsizeof_expr (location_t loc
, struct c_expr expr
)
6662 ret
.original_code
= ERROR_MARK
;
6663 ret
.original_type
= NULL_TREE
;
6664 if (expr
.value
== error_mark_node
)
6666 ret
.value
= error_mark_node
;
6667 pop_maybe_used (false);
6671 ret
.value
= upc_localsizeof (loc
, TREE_TYPE (expr
.value
));
6672 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6677 /* Return the result of upc_localsizeof applied to T, a structure
6678 for the type name passed to sizeof (rather than the type itself). */
6682 upc_localsizeof_type (location_t loc
, struct c_type_name
*t
)
6686 ret
.original_code
= ERROR_MARK
;
6687 ret
.original_type
= NULL_TREE
;
6688 type
= groktypename (t
, NULL
, NULL
);
6689 if (type
== error_mark_node
)
6691 ret
.value
= error_mark_node
;
6692 pop_maybe_used (false);
6696 ret
.value
= upc_localsizeof (loc
, type
);
6697 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6702 /* Parse a sizeof expression. */
6704 static struct c_expr
6705 c_parser_sizeof_expression (c_parser
*parser
)
6708 location_t expr_loc
;
6709 enum rid keyword
= c_parser_peek_token (parser
)->keyword
;
6710 c_parser_consume_token (parser
);
6711 c_inhibit_evaluation_warnings
++;
6713 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6714 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6716 /* Either sizeof ( type-name ) or sizeof unary-expression
6717 starting with a compound literal. */
6718 struct c_type_name
*type_name
;
6719 c_parser_consume_token (parser
);
6720 expr_loc
= c_parser_peek_token (parser
)->location
;
6721 type_name
= c_parser_type_name (parser
);
6722 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6723 if (type_name
== NULL
)
6726 c_inhibit_evaluation_warnings
--;
6728 ret
.value
= error_mark_node
;
6729 ret
.original_code
= ERROR_MARK
;
6730 ret
.original_type
= NULL
;
6733 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6735 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6740 /* sizeof ( type-name ). */
6741 c_inhibit_evaluation_warnings
--;
6743 /* Handle upc_*_sizeof (type) operations. */
6746 case RID_UPC_BLOCKSIZEOF
:
6747 return upc_blocksizeof_type (expr_loc
, type_name
);
6748 case RID_UPC_ELEMSIZEOF
:
6749 return upc_elemsizeof_type (expr_loc
, type_name
);
6750 case RID_UPC_LOCALSIZEOF
:
6751 return upc_localsizeof_type (expr_loc
, type_name
);
6754 return c_expr_sizeof_type (expr_loc
, type_name
);
6758 expr_loc
= c_parser_peek_token (parser
)->location
;
6759 expr
= c_parser_unary_expression (parser
);
6761 c_inhibit_evaluation_warnings
--;
6763 mark_exp_read (expr
.value
);
6764 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6765 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6766 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6767 /* Handle upc_*_sizeof (expr) operations. */
6770 case RID_UPC_BLOCKSIZEOF
:
6771 return upc_blocksizeof_expr (expr_loc
, expr
);
6772 case RID_UPC_ELEMSIZEOF
:
6773 return upc_elemsizeof_expr (expr_loc
, expr
);
6774 case RID_UPC_LOCALSIZEOF
:
6775 return upc_localsizeof_expr (expr_loc
, expr
);
6777 return c_expr_sizeof_expr (expr_loc
, expr
);
6780 return c_expr_sizeof_expr (expr_loc
, expr
);
6784 /* Parse an alignof expression. */
6786 static struct c_expr
6787 c_parser_alignof_expression (c_parser
*parser
)
6790 location_t loc
= c_parser_peek_token (parser
)->location
;
6791 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6792 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6793 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6795 /* A diagnostic is not required for the use of this identifier in
6796 the implementation namespace; only diagnose it for the C11
6797 spelling because of existing code using the other spellings. */
6798 if (!flag_isoc11
&& is_c11_alignof
)
6801 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6804 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6807 c_parser_consume_token (parser
);
6808 c_inhibit_evaluation_warnings
++;
6810 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6811 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6813 /* Either __alignof__ ( type-name ) or __alignof__
6814 unary-expression starting with a compound literal. */
6816 struct c_type_name
*type_name
;
6818 c_parser_consume_token (parser
);
6819 loc
= c_parser_peek_token (parser
)->location
;
6820 type_name
= c_parser_type_name (parser
);
6821 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6822 if (type_name
== NULL
)
6825 c_inhibit_evaluation_warnings
--;
6827 ret
.value
= error_mark_node
;
6828 ret
.original_code
= ERROR_MARK
;
6829 ret
.original_type
= NULL
;
6832 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6834 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6839 /* alignof ( type-name ). */
6840 c_inhibit_evaluation_warnings
--;
6842 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6844 false, is_c11_alignof
, 1);
6845 ret
.original_code
= ERROR_MARK
;
6846 ret
.original_type
= NULL
;
6852 expr
= c_parser_unary_expression (parser
);
6854 mark_exp_read (expr
.value
);
6855 c_inhibit_evaluation_warnings
--;
6857 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6859 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6860 ret
.original_code
= ERROR_MARK
;
6861 ret
.original_type
= NULL
;
6866 /* Helper function to read arguments of builtins which are interfaces
6867 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6868 others. The name of the builtin is passed using BNAME parameter.
6869 Function returns true if there were no errors while parsing and
6870 stores the arguments in CEXPR_LIST. */
6872 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6873 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6876 location_t loc
= c_parser_peek_token (parser
)->location
;
6877 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6879 bool saved_force_folding_builtin_constant_p
;
6881 *ret_cexpr_list
= NULL
;
6882 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6884 error_at (loc
, "cannot take address of %qs", bname
);
6888 c_parser_consume_token (parser
);
6890 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6892 c_parser_consume_token (parser
);
6896 saved_force_folding_builtin_constant_p
6897 = force_folding_builtin_constant_p
;
6898 force_folding_builtin_constant_p
|= choose_expr_p
;
6899 expr
= c_parser_expr_no_commas (parser
, NULL
);
6900 force_folding_builtin_constant_p
6901 = saved_force_folding_builtin_constant_p
;
6902 vec_alloc (cexpr_list
, 1);
6903 vec_safe_push (cexpr_list
, expr
);
6904 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6906 c_parser_consume_token (parser
);
6907 expr
= c_parser_expr_no_commas (parser
, NULL
);
6908 vec_safe_push (cexpr_list
, expr
);
6911 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6914 *ret_cexpr_list
= cexpr_list
;
6918 /* This represents a single generic-association. */
6920 struct c_generic_association
6922 /* The location of the starting token of the type. */
6923 location_t type_location
;
6924 /* The association's type, or NULL_TREE for 'default'. */
6926 /* The association's expression. */
6927 struct c_expr expression
;
6930 /* Parse a generic-selection. (C11 6.5.1.1).
6933 _Generic ( assignment-expression , generic-assoc-list )
6937 generic-assoc-list , generic-association
6939 generic-association:
6940 type-name : assignment-expression
6941 default : assignment-expression
6944 static struct c_expr
6945 c_parser_generic_selection (c_parser
*parser
)
6947 vec
<c_generic_association
> associations
= vNULL
;
6948 struct c_expr selector
, error_expr
;
6950 struct c_generic_association matched_assoc
;
6951 bool match_found
= false;
6952 location_t generic_loc
, selector_loc
;
6954 error_expr
.original_code
= ERROR_MARK
;
6955 error_expr
.original_type
= NULL
;
6956 error_expr
.value
= error_mark_node
;
6957 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6958 matched_assoc
.type
= NULL_TREE
;
6959 matched_assoc
.expression
= error_expr
;
6961 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6962 generic_loc
= c_parser_peek_token (parser
)->location
;
6963 c_parser_consume_token (parser
);
6967 pedwarn (generic_loc
, OPT_Wpedantic
,
6968 "ISO C99 does not support %<_Generic%>");
6970 pedwarn (generic_loc
, OPT_Wpedantic
,
6971 "ISO C90 does not support %<_Generic%>");
6974 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6977 c_inhibit_evaluation_warnings
++;
6978 selector_loc
= c_parser_peek_token (parser
)->location
;
6979 selector
= c_parser_expr_no_commas (parser
, NULL
);
6980 selector
= default_function_array_conversion (selector_loc
, selector
);
6981 c_inhibit_evaluation_warnings
--;
6983 if (selector
.value
== error_mark_node
)
6985 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6988 selector_type
= TREE_TYPE (selector
.value
);
6989 /* In ISO C terms, rvalues (including the controlling expression of
6990 _Generic) do not have qualified types. */
6991 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6992 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6993 /* In ISO C terms, _Noreturn is not part of the type of expressions
6994 such as &abort, but in GCC it is represented internally as a type
6996 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6997 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6999 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7001 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7003 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7009 struct c_generic_association assoc
, *iter
;
7011 c_token
*token
= c_parser_peek_token (parser
);
7013 assoc
.type_location
= token
->location
;
7014 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7016 c_parser_consume_token (parser
);
7017 assoc
.type
= NULL_TREE
;
7021 struct c_type_name
*type_name
;
7023 type_name
= c_parser_type_name (parser
);
7024 if (type_name
== NULL
)
7026 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7029 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7030 if (assoc
.type
== error_mark_node
)
7032 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7036 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7037 error_at (assoc
.type_location
,
7038 "%<_Generic%> association has function type");
7039 else if (!COMPLETE_TYPE_P (assoc
.type
))
7040 error_at (assoc
.type_location
,
7041 "%<_Generic%> association has incomplete type");
7043 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7044 error_at (assoc
.type_location
,
7045 "%<_Generic%> association has "
7046 "variable length type");
7049 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7051 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7055 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7056 if (assoc
.expression
.value
== error_mark_node
)
7058 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7062 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7064 if (assoc
.type
== NULL_TREE
)
7066 if (iter
->type
== NULL_TREE
)
7068 error_at (assoc
.type_location
,
7069 "duplicate %<default%> case in %<_Generic%>");
7070 inform (iter
->type_location
, "original %<default%> is here");
7073 else if (iter
->type
!= NULL_TREE
)
7075 if (comptypes (assoc
.type
, iter
->type
))
7077 error_at (assoc
.type_location
,
7078 "%<_Generic%> specifies two compatible types");
7079 inform (iter
->type_location
, "compatible type is here");
7084 if (assoc
.type
== NULL_TREE
)
7088 matched_assoc
= assoc
;
7092 else if (comptypes (assoc
.type
, selector_type
))
7094 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7096 matched_assoc
= assoc
;
7101 error_at (assoc
.type_location
,
7102 "%<_Generic> selector matches multiple associations");
7103 inform (matched_assoc
.type_location
,
7104 "other match is here");
7108 associations
.safe_push (assoc
);
7110 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7112 c_parser_consume_token (parser
);
7115 associations
.release ();
7117 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7119 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7125 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7126 "compatible with any association",
7131 return matched_assoc
.expression
;
7134 associations
.release ();
7138 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7142 postfix-expression [ expression ]
7143 postfix-expression ( argument-expression-list[opt] )
7144 postfix-expression . identifier
7145 postfix-expression -> identifier
7146 postfix-expression ++
7147 postfix-expression --
7148 ( type-name ) { initializer-list }
7149 ( type-name ) { initializer-list , }
7151 argument-expression-list:
7153 argument-expression-list , argument-expression
7166 (treated as a keyword in GNU C)
7169 ( compound-statement )
7170 __builtin_va_arg ( assignment-expression , type-name )
7171 __builtin_offsetof ( type-name , offsetof-member-designator )
7172 __builtin_choose_expr ( assignment-expression ,
7173 assignment-expression ,
7174 assignment-expression )
7175 __builtin_types_compatible_p ( type-name , type-name )
7176 __builtin_complex ( assignment-expression , assignment-expression )
7177 __builtin_shuffle ( assignment-expression , assignment-expression )
7178 __builtin_shuffle ( assignment-expression ,
7179 assignment-expression ,
7180 assignment-expression, )
7182 offsetof-member-designator:
7184 offsetof-member-designator . identifier
7185 offsetof-member-designator [ expression ]
7190 [ objc-receiver objc-message-args ]
7191 @selector ( objc-selector-arg )
7192 @protocol ( identifier )
7193 @encode ( type-name )
7195 Classname . identifier
7198 static struct c_expr
7199 c_parser_postfix_expression (c_parser
*parser
)
7201 struct c_expr expr
, e1
;
7202 struct c_type_name
*t1
, *t2
;
7203 location_t loc
= c_parser_peek_token (parser
)->location
;;
7204 expr
.original_code
= ERROR_MARK
;
7205 expr
.original_type
= NULL
;
7206 switch (c_parser_peek_token (parser
)->type
)
7209 expr
.value
= c_parser_peek_token (parser
)->value
;
7210 loc
= c_parser_peek_token (parser
)->location
;
7211 c_parser_consume_token (parser
);
7212 if (TREE_CODE (expr
.value
) == FIXED_CST
7213 && !targetm
.fixed_point_supported_p ())
7215 error_at (loc
, "fixed-point types not supported for this target");
7216 expr
.value
= error_mark_node
;
7223 expr
.value
= c_parser_peek_token (parser
)->value
;
7224 c_parser_consume_token (parser
);
7230 case CPP_UTF8STRING
:
7231 expr
.value
= c_parser_peek_token (parser
)->value
;
7232 expr
.original_code
= STRING_CST
;
7233 c_parser_consume_token (parser
);
7235 case CPP_OBJC_STRING
:
7236 gcc_assert (c_dialect_objc ());
7238 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7239 c_parser_consume_token (parser
);
7242 switch (c_parser_peek_token (parser
)->id_kind
)
7246 tree id
= c_parser_peek_token (parser
)->value
;
7247 c_parser_consume_token (parser
);
7248 expr
.value
= build_external_ref (loc
, id
,
7249 (c_parser_peek_token (parser
)->type
7251 &expr
.original_type
);
7254 case C_ID_CLASSNAME
:
7256 /* Here we parse the Objective-C 2.0 Class.name dot
7258 tree class_name
= c_parser_peek_token (parser
)->value
;
7260 c_parser_consume_token (parser
);
7261 gcc_assert (c_dialect_objc ());
7262 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7264 expr
.value
= error_mark_node
;
7267 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7269 c_parser_error (parser
, "expected identifier");
7270 expr
.value
= error_mark_node
;
7273 component
= c_parser_peek_token (parser
)->value
;
7274 c_parser_consume_token (parser
);
7275 expr
.value
= objc_build_class_component_ref (class_name
,
7280 c_parser_error (parser
, "expected expression");
7281 expr
.value
= error_mark_node
;
7285 case CPP_OPEN_PAREN
:
7286 /* A parenthesized expression, statement expression or compound
7288 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7290 /* A statement expression. */
7292 location_t brace_loc
;
7293 c_parser_consume_token (parser
);
7294 brace_loc
= c_parser_peek_token (parser
)->location
;
7295 c_parser_consume_token (parser
);
7296 if (!building_stmt_list_p ())
7298 error_at (loc
, "braced-group within expression allowed "
7299 "only inside a function");
7300 parser
->error
= true;
7301 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7302 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7303 expr
.value
= error_mark_node
;
7306 stmt
= c_begin_stmt_expr ();
7307 c_parser_compound_statement_nostart (parser
);
7308 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7310 pedwarn (loc
, OPT_Wpedantic
,
7311 "ISO C forbids braced-groups within expressions");
7312 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7313 mark_exp_read (expr
.value
);
7315 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7317 /* A compound literal. ??? Can we actually get here rather
7318 than going directly to
7319 c_parser_postfix_expression_after_paren_type from
7322 struct c_type_name
*type_name
;
7323 c_parser_consume_token (parser
);
7324 loc
= c_parser_peek_token (parser
)->location
;
7325 type_name
= c_parser_type_name (parser
);
7326 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7328 if (type_name
== NULL
)
7330 expr
.value
= error_mark_node
;
7333 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7339 /* A parenthesized expression. */
7340 c_parser_consume_token (parser
);
7341 expr
= c_parser_expression (parser
);
7342 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7343 TREE_NO_WARNING (expr
.value
) = 1;
7344 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7345 expr
.original_code
= ERROR_MARK
;
7346 /* Don't change EXPR.ORIGINAL_TYPE. */
7347 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7352 switch (c_parser_peek_token (parser
)->keyword
)
7354 case RID_FUNCTION_NAME
:
7355 case RID_PRETTY_FUNCTION_NAME
:
7356 case RID_C99_FUNCTION_NAME
:
7357 expr
.value
= fname_decl (loc
,
7358 c_parser_peek_token (parser
)->keyword
,
7359 c_parser_peek_token (parser
)->value
);
7360 c_parser_consume_token (parser
);
7363 c_parser_consume_token (parser
);
7364 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7366 expr
.value
= error_mark_node
;
7369 e1
= c_parser_expr_no_commas (parser
, NULL
);
7370 mark_exp_read (e1
.value
);
7371 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7372 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7374 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7375 expr
.value
= error_mark_node
;
7378 loc
= c_parser_peek_token (parser
)->location
;
7379 t1
= c_parser_type_name (parser
);
7380 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7384 expr
.value
= error_mark_node
;
7388 tree type_expr
= NULL_TREE
;
7389 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7390 groktypename (t1
, &type_expr
, NULL
));
7393 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7394 TREE_TYPE (expr
.value
), type_expr
,
7396 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7401 c_parser_consume_token (parser
);
7402 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7404 expr
.value
= error_mark_node
;
7407 t1
= c_parser_type_name (parser
);
7409 parser
->error
= true;
7410 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7411 gcc_assert (parser
->error
);
7414 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7415 expr
.value
= error_mark_node
;
7420 tree type
= groktypename (t1
, NULL
, NULL
);
7422 if (type
== error_mark_node
)
7423 offsetof_ref
= error_mark_node
;
7426 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7427 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7429 /* Parse the second argument to __builtin_offsetof. We
7430 must have one identifier, and beyond that we want to
7431 accept sub structure and sub array references. */
7432 if (c_parser_next_token_is (parser
, CPP_NAME
))
7434 offsetof_ref
= build_component_ref
7435 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7436 c_parser_consume_token (parser
);
7437 while (c_parser_next_token_is (parser
, CPP_DOT
)
7438 || c_parser_next_token_is (parser
,
7440 || c_parser_next_token_is (parser
,
7443 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7445 loc
= c_parser_peek_token (parser
)->location
;
7446 offsetof_ref
= build_array_ref (loc
,
7451 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7454 c_parser_consume_token (parser
);
7455 if (c_parser_next_token_is_not (parser
,
7458 c_parser_error (parser
, "expected identifier");
7461 offsetof_ref
= build_component_ref
7463 c_parser_peek_token (parser
)->value
);
7464 c_parser_consume_token (parser
);
7470 loc
= c_parser_peek_token (parser
)->location
;
7471 c_parser_consume_token (parser
);
7472 ce
= c_parser_expression (parser
);
7473 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7475 idx
= c_fully_fold (idx
, false, NULL
);
7476 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7478 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7483 c_parser_error (parser
, "expected identifier");
7484 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7486 expr
.value
= fold_offsetof (offsetof_ref
);
7489 case RID_CHOOSE_EXPR
:
7491 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7492 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7495 c_parser_consume_token (parser
);
7496 if (!c_parser_get_builtin_args (parser
,
7497 "__builtin_choose_expr",
7500 expr
.value
= error_mark_node
;
7504 if (vec_safe_length (cexpr_list
) != 3)
7506 error_at (loc
, "wrong number of arguments to "
7507 "%<__builtin_choose_expr%>");
7508 expr
.value
= error_mark_node
;
7512 e1_p
= &(*cexpr_list
)[0];
7513 e2_p
= &(*cexpr_list
)[1];
7514 e3_p
= &(*cexpr_list
)[2];
7517 mark_exp_read (e2_p
->value
);
7518 mark_exp_read (e3_p
->value
);
7519 if (TREE_CODE (c
) != INTEGER_CST
7520 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7522 "first argument to %<__builtin_choose_expr%> not"
7524 constant_expression_warning (c
);
7525 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7528 case RID_TYPES_COMPATIBLE_P
:
7529 c_parser_consume_token (parser
);
7530 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7532 expr
.value
= error_mark_node
;
7535 t1
= c_parser_type_name (parser
);
7538 expr
.value
= error_mark_node
;
7541 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7543 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7544 expr
.value
= error_mark_node
;
7547 t2
= c_parser_type_name (parser
);
7550 expr
.value
= error_mark_node
;
7553 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7557 e1
= groktypename (t1
, NULL
, NULL
);
7558 e2
= groktypename (t2
, NULL
, NULL
);
7559 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7561 expr
.value
= error_mark_node
;
7565 e1
= TYPE_MAIN_VARIANT (e1
);
7566 e2
= TYPE_MAIN_VARIANT (e2
);
7569 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7572 case RID_BUILTIN_COMPLEX
:
7574 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7575 c_expr_t
*e1_p
, *e2_p
;
7577 c_parser_consume_token (parser
);
7578 if (!c_parser_get_builtin_args (parser
,
7579 "__builtin_complex",
7580 &cexpr_list
, false))
7582 expr
.value
= error_mark_node
;
7586 if (vec_safe_length (cexpr_list
) != 2)
7588 error_at (loc
, "wrong number of arguments to "
7589 "%<__builtin_complex%>");
7590 expr
.value
= error_mark_node
;
7594 e1_p
= &(*cexpr_list
)[0];
7595 e2_p
= &(*cexpr_list
)[1];
7597 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7598 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7599 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7600 TREE_OPERAND (e1_p
->value
, 0));
7601 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7602 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7603 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7604 TREE_OPERAND (e2_p
->value
, 0));
7605 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7606 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7607 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7608 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7610 error_at (loc
, "%<__builtin_complex%> operand "
7611 "not of real binary floating-point type");
7612 expr
.value
= error_mark_node
;
7615 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7616 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7619 "%<__builtin_complex%> operands of different types");
7620 expr
.value
= error_mark_node
;
7624 pedwarn (loc
, OPT_Wpedantic
,
7625 "ISO C90 does not support complex types");
7626 expr
.value
= build2 (COMPLEX_EXPR
,
7629 (TREE_TYPE (e1_p
->value
))),
7630 e1_p
->value
, e2_p
->value
);
7633 case RID_BUILTIN_SHUFFLE
:
7635 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7639 c_parser_consume_token (parser
);
7640 if (!c_parser_get_builtin_args (parser
,
7641 "__builtin_shuffle",
7642 &cexpr_list
, false))
7644 expr
.value
= error_mark_node
;
7648 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7649 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7651 if (vec_safe_length (cexpr_list
) == 2)
7653 c_build_vec_perm_expr
7654 (loc
, (*cexpr_list
)[0].value
,
7655 NULL_TREE
, (*cexpr_list
)[1].value
);
7657 else if (vec_safe_length (cexpr_list
) == 3)
7659 c_build_vec_perm_expr
7660 (loc
, (*cexpr_list
)[0].value
,
7661 (*cexpr_list
)[1].value
,
7662 (*cexpr_list
)[2].value
);
7665 error_at (loc
, "wrong number of arguments to "
7666 "%<__builtin_shuffle%>");
7667 expr
.value
= error_mark_node
;
7671 case RID_AT_SELECTOR
:
7672 gcc_assert (c_dialect_objc ());
7673 c_parser_consume_token (parser
);
7674 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7676 expr
.value
= error_mark_node
;
7680 tree sel
= c_parser_objc_selector_arg (parser
);
7681 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7683 expr
.value
= objc_build_selector_expr (loc
, sel
);
7686 case RID_AT_PROTOCOL
:
7687 gcc_assert (c_dialect_objc ());
7688 c_parser_consume_token (parser
);
7689 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7691 expr
.value
= error_mark_node
;
7694 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7696 c_parser_error (parser
, "expected identifier");
7697 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7698 expr
.value
= error_mark_node
;
7702 tree id
= c_parser_peek_token (parser
)->value
;
7703 c_parser_consume_token (parser
);
7704 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7706 expr
.value
= objc_build_protocol_expr (id
);
7710 /* Extension to support C-structures in the archiver. */
7711 gcc_assert (c_dialect_objc ());
7712 c_parser_consume_token (parser
);
7713 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7715 expr
.value
= error_mark_node
;
7718 t1
= c_parser_type_name (parser
);
7721 expr
.value
= error_mark_node
;
7722 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7725 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7728 tree type
= groktypename (t1
, NULL
, NULL
);
7729 expr
.value
= objc_build_encode_expr (type
);
7733 expr
= c_parser_generic_selection (parser
);
7735 case RID_CILK_SPAWN
:
7736 c_parser_consume_token (parser
);
7739 error_at (loc
, "-fcilkplus must be enabled to use "
7741 expr
= c_parser_postfix_expression (parser
);
7742 expr
.value
= error_mark_node
;
7744 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7746 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7747 "are not permitted");
7748 /* Now flush out all the _Cilk_spawns. */
7749 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7750 c_parser_consume_token (parser
);
7751 expr
= c_parser_postfix_expression (parser
);
7755 expr
= c_parser_postfix_expression (parser
);
7756 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7760 c_parser_error (parser
, "expected expression");
7761 expr
.value
= error_mark_node
;
7765 case CPP_OPEN_SQUARE
:
7766 if (c_dialect_objc ())
7768 tree receiver
, args
;
7769 c_parser_consume_token (parser
);
7770 receiver
= c_parser_objc_receiver (parser
);
7771 args
= c_parser_objc_message_args (parser
);
7772 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7774 expr
.value
= objc_build_message_expr (receiver
, args
);
7777 /* Else fall through to report error. */
7779 c_parser_error (parser
, "expected expression");
7780 expr
.value
= error_mark_node
;
7783 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7786 /* Parse a postfix expression after a parenthesized type name: the
7787 brace-enclosed initializer of a compound literal, possibly followed
7788 by some postfix operators. This is separate because it is not
7789 possible to tell until after the type name whether a cast
7790 expression has a cast or a compound literal, or whether the operand
7791 of sizeof is a parenthesized type name or starts with a compound
7792 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7793 location of the first token after the parentheses around the type
7796 static struct c_expr
7797 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7798 struct c_type_name
*type_name
,
7799 location_t type_loc
)
7805 location_t start_loc
;
7806 tree type_expr
= NULL_TREE
;
7807 bool type_expr_const
= true;
7808 check_compound_literal_type (type_loc
, type_name
);
7809 start_init (NULL_TREE
, NULL
, 0);
7810 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7811 start_loc
= c_parser_peek_token (parser
)->location
;
7812 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7814 error_at (type_loc
, "compound literal has variable size");
7815 type
= error_mark_node
;
7817 init
= c_parser_braced_init (parser
, type
, false);
7819 maybe_warn_string_init (type
, init
);
7821 if (type
!= error_mark_node
7822 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7823 && current_function_decl
)
7825 error ("compound literal qualified by address-space qualifier");
7826 type
= error_mark_node
;
7830 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7831 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7832 ? CONSTRUCTOR_NON_CONST (init
.value
)
7833 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7834 non_const
|= !type_expr_const
;
7835 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7836 expr
.original_code
= ERROR_MARK
;
7837 expr
.original_type
= NULL
;
7840 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7842 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7843 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7847 gcc_assert (!non_const
);
7848 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7849 type_expr
, expr
.value
);
7852 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7855 /* Callback function for sizeof_pointer_memaccess_warning to compare
7859 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7861 return comptypes (type1
, type2
) == 1;
7864 /* Parse a postfix expression after the initial primary or compound
7865 literal; that is, parse a series of postfix operators.
7867 EXPR_LOC is the location of the primary expression. */
7869 static struct c_expr
7870 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7871 location_t expr_loc
,
7874 struct c_expr orig_expr
;
7876 location_t sizeof_arg_loc
[3];
7879 vec
<tree
, va_gc
> *exprlist
;
7880 vec
<tree
, va_gc
> *origtypes
= NULL
;
7881 vec
<location_t
> arg_loc
= vNULL
;
7885 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7886 switch (c_parser_peek_token (parser
)->type
)
7888 case CPP_OPEN_SQUARE
:
7889 /* Array reference. */
7890 c_parser_consume_token (parser
);
7892 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7893 /* If we are here, then we have something like this:
7896 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7900 idx
= c_parser_expression (parser
).value
;
7901 /* Here we have 3 options:
7902 1. Array [EXPR] -- Normal Array call.
7903 2. Array [EXPR : EXPR] -- Array notation without stride.
7904 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7906 For 1, we just handle it just like a normal array expression.
7907 For 2 and 3 we handle it like we handle array notations. The
7908 idx value we have above becomes the initial/start index.
7911 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7912 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7916 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7918 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7921 expr
.original_code
= ERROR_MARK
;
7922 expr
.original_type
= NULL
;
7924 case CPP_OPEN_PAREN
:
7925 /* Function call. */
7926 c_parser_consume_token (parser
);
7927 for (i
= 0; i
< 3; i
++)
7929 sizeof_arg
[i
] = NULL_TREE
;
7930 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7932 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7935 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7936 sizeof_arg_loc
, sizeof_arg
,
7938 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7941 mark_exp_read (expr
.value
);
7942 if (warn_sizeof_pointer_memaccess
)
7943 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7944 expr
.value
, exprlist
,
7946 sizeof_ptr_memacc_comptypes
);
7948 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7949 exprlist
, origtypes
);
7950 expr
.original_code
= ERROR_MARK
;
7951 if (TREE_CODE (expr
.value
) == INTEGER_CST
7952 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7953 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7954 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7955 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7956 expr
.original_type
= NULL
;
7959 release_tree_vector (exprlist
);
7960 release_tree_vector (origtypes
);
7965 /* Structure element reference. */
7966 c_parser_consume_token (parser
);
7967 expr
= default_function_array_conversion (expr_loc
, expr
);
7968 if (c_parser_next_token_is (parser
, CPP_NAME
))
7969 ident
= c_parser_peek_token (parser
)->value
;
7972 c_parser_error (parser
, "expected identifier");
7973 expr
.value
= error_mark_node
;
7974 expr
.original_code
= ERROR_MARK
;
7975 expr
.original_type
= NULL
;
7978 c_parser_consume_token (parser
);
7979 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7980 expr
.original_code
= ERROR_MARK
;
7981 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7982 expr
.original_type
= NULL
;
7985 /* Remember the original type of a bitfield. */
7986 tree field
= TREE_OPERAND (expr
.value
, 1);
7987 if (TREE_CODE (field
) != FIELD_DECL
)
7988 expr
.original_type
= NULL
;
7990 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7994 /* Structure element reference. */
7995 c_parser_consume_token (parser
);
7996 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7997 if (c_parser_next_token_is (parser
, CPP_NAME
))
7998 ident
= c_parser_peek_token (parser
)->value
;
8001 c_parser_error (parser
, "expected identifier");
8002 expr
.value
= error_mark_node
;
8003 expr
.original_code
= ERROR_MARK
;
8004 expr
.original_type
= NULL
;
8007 c_parser_consume_token (parser
);
8008 expr
.value
= build_component_ref (op_loc
,
8009 build_indirect_ref (op_loc
,
8013 expr
.original_code
= ERROR_MARK
;
8014 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8015 expr
.original_type
= NULL
;
8018 /* Remember the original type of a bitfield. */
8019 tree field
= TREE_OPERAND (expr
.value
, 1);
8020 if (TREE_CODE (field
) != FIELD_DECL
)
8021 expr
.original_type
= NULL
;
8023 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8027 /* Postincrement. */
8028 c_parser_consume_token (parser
);
8029 /* If the expressions have array notations, we expand them. */
8031 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8032 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8035 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8036 expr
.value
= build_unary_op (op_loc
,
8037 POSTINCREMENT_EXPR
, expr
.value
, 0);
8039 expr
.original_code
= ERROR_MARK
;
8040 expr
.original_type
= NULL
;
8042 case CPP_MINUS_MINUS
:
8043 /* Postdecrement. */
8044 c_parser_consume_token (parser
);
8045 /* If the expressions have array notations, we expand them. */
8047 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8048 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8051 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8052 expr
.value
= build_unary_op (op_loc
,
8053 POSTDECREMENT_EXPR
, expr
.value
, 0);
8055 expr
.original_code
= ERROR_MARK
;
8056 expr
.original_type
= NULL
;
8064 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8067 assignment-expression
8068 expression , assignment-expression
8071 static struct c_expr
8072 c_parser_expression (c_parser
*parser
)
8074 location_t tloc
= c_parser_peek_token (parser
)->location
;
8076 expr
= c_parser_expr_no_commas (parser
, NULL
);
8077 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8078 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8079 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8083 location_t loc
= c_parser_peek_token (parser
)->location
;
8084 location_t expr_loc
;
8085 c_parser_consume_token (parser
);
8086 expr_loc
= c_parser_peek_token (parser
)->location
;
8087 lhsval
= expr
.value
;
8088 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8089 lhsval
= TREE_OPERAND (lhsval
, 1);
8090 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8091 mark_exp_read (lhsval
);
8092 next
= c_parser_expr_no_commas (parser
, NULL
);
8093 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8094 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8095 expr
.original_code
= COMPOUND_EXPR
;
8096 expr
.original_type
= next
.original_type
;
8101 /* Parse an expression and convert functions or arrays to pointers and
8102 lvalues to rvalues. */
8104 static struct c_expr
8105 c_parser_expression_conv (c_parser
*parser
)
8108 location_t loc
= c_parser_peek_token (parser
)->location
;
8109 expr
= c_parser_expression (parser
);
8110 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8114 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8115 functions and arrays to pointers and lvalues to rvalues. If
8116 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8117 locations of function arguments into this vector.
8120 assignment-expression
8121 nonempty-expr-list , assignment-expression
8124 static vec
<tree
, va_gc
> *
8125 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8126 vec
<tree
, va_gc
> **p_orig_types
,
8127 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8128 vec
<location_t
> *locations
)
8130 vec
<tree
, va_gc
> *ret
;
8131 vec
<tree
, va_gc
> *orig_types
;
8133 location_t loc
= c_parser_peek_token (parser
)->location
;
8134 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8135 unsigned int idx
= 0;
8137 ret
= make_tree_vector ();
8138 if (p_orig_types
== NULL
)
8141 orig_types
= make_tree_vector ();
8143 if (sizeof_arg
!= NULL
8144 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8145 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8146 expr
= c_parser_expr_no_commas (parser
, NULL
);
8148 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8150 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8151 ret
->quick_push (expr
.value
);
8153 orig_types
->quick_push (expr
.original_type
);
8155 locations
->safe_push (loc
);
8156 if (sizeof_arg
!= NULL
8157 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8158 && expr
.original_code
== SIZEOF_EXPR
)
8160 sizeof_arg
[0] = c_last_sizeof_arg
;
8161 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8163 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8165 c_parser_consume_token (parser
);
8166 loc
= c_parser_peek_token (parser
)->location
;
8167 if (sizeof_arg
!= NULL
8168 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8169 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8171 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8172 expr
= c_parser_expr_no_commas (parser
, NULL
);
8174 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8176 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8177 vec_safe_push (ret
, expr
.value
);
8179 vec_safe_push (orig_types
, expr
.original_type
);
8181 locations
->safe_push (loc
);
8183 && sizeof_arg
!= NULL
8184 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8185 && expr
.original_code
== SIZEOF_EXPR
)
8187 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8188 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8192 *p_orig_types
= orig_types
;
8196 /* Parse Objective-C-specific constructs. */
8198 /* Parse an objc-class-definition.
8200 objc-class-definition:
8201 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8202 objc-class-instance-variables[opt] objc-methodprotolist @end
8203 @implementation identifier objc-superclass[opt]
8204 objc-class-instance-variables[opt]
8205 @interface identifier ( identifier ) objc-protocol-refs[opt]
8206 objc-methodprotolist @end
8207 @interface identifier ( ) objc-protocol-refs[opt]
8208 objc-methodprotolist @end
8209 @implementation identifier ( identifier )
8214 "@interface identifier (" must start "@interface identifier (
8215 identifier ) ...": objc-methodprotolist in the first production may
8216 not start with a parenthesized identifier as a declarator of a data
8217 definition with no declaration specifiers if the objc-superclass,
8218 objc-protocol-refs and objc-class-instance-variables are omitted. */
8221 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8226 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8228 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8233 c_parser_consume_token (parser
);
8234 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8236 c_parser_error (parser
, "expected identifier");
8239 id1
= c_parser_peek_token (parser
)->value
;
8240 c_parser_consume_token (parser
);
8241 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8243 /* We have a category or class extension. */
8245 tree proto
= NULL_TREE
;
8246 c_parser_consume_token (parser
);
8247 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8249 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8251 /* We have a class extension. */
8256 c_parser_error (parser
, "expected identifier or %<)%>");
8257 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8263 id2
= c_parser_peek_token (parser
)->value
;
8264 c_parser_consume_token (parser
);
8266 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8269 objc_start_category_implementation (id1
, id2
);
8272 if (c_parser_next_token_is (parser
, CPP_LESS
))
8273 proto
= c_parser_objc_protocol_refs (parser
);
8274 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8275 c_parser_objc_methodprotolist (parser
);
8276 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8277 objc_finish_interface ();
8280 if (c_parser_next_token_is (parser
, CPP_COLON
))
8282 c_parser_consume_token (parser
);
8283 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8285 c_parser_error (parser
, "expected identifier");
8288 superclass
= c_parser_peek_token (parser
)->value
;
8289 c_parser_consume_token (parser
);
8292 superclass
= NULL_TREE
;
8295 tree proto
= NULL_TREE
;
8296 if (c_parser_next_token_is (parser
, CPP_LESS
))
8297 proto
= c_parser_objc_protocol_refs (parser
);
8298 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8301 objc_start_class_implementation (id1
, superclass
);
8302 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8303 c_parser_objc_class_instance_variables (parser
);
8306 objc_continue_interface ();
8307 c_parser_objc_methodprotolist (parser
);
8308 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8309 objc_finish_interface ();
8313 objc_continue_implementation ();
8318 /* Parse objc-class-instance-variables.
8320 objc-class-instance-variables:
8321 { objc-instance-variable-decl-list[opt] }
8323 objc-instance-variable-decl-list:
8324 objc-visibility-spec
8325 objc-instance-variable-decl ;
8327 objc-instance-variable-decl-list objc-visibility-spec
8328 objc-instance-variable-decl-list objc-instance-variable-decl ;
8329 objc-instance-variable-decl-list ;
8331 objc-visibility-spec:
8336 objc-instance-variable-decl:
8341 c_parser_objc_class_instance_variables (c_parser
*parser
)
8343 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8344 c_parser_consume_token (parser
);
8345 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8348 /* Parse any stray semicolon. */
8349 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8351 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8353 c_parser_consume_token (parser
);
8356 /* Stop if at the end of the instance variables. */
8357 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8359 c_parser_consume_token (parser
);
8362 /* Parse any objc-visibility-spec. */
8363 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8365 c_parser_consume_token (parser
);
8366 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8369 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8371 c_parser_consume_token (parser
);
8372 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8375 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8377 c_parser_consume_token (parser
);
8378 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8381 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8383 c_parser_consume_token (parser
);
8384 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8387 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8389 c_parser_pragma (parser
, pragma_external
);
8393 /* Parse some comma-separated declarations. */
8394 decls
= c_parser_struct_declaration (parser
);
8397 /* There is a syntax error. We want to skip the offending
8398 tokens up to the next ';' (included) or '}'
8401 /* First, skip manually a ')' or ']'. This is because they
8402 reduce the nesting level, so c_parser_skip_until_found()
8403 wouldn't be able to skip past them. */
8404 c_token
*token
= c_parser_peek_token (parser
);
8405 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8406 c_parser_consume_token (parser
);
8408 /* Then, do the standard skipping. */
8409 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8411 /* We hopefully recovered. Start normal parsing again. */
8412 parser
->error
= false;
8417 /* Comma-separated instance variables are chained together
8418 in reverse order; add them one by one. */
8419 tree ivar
= nreverse (decls
);
8420 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8421 objc_add_instance_variable (copy_node (ivar
));
8423 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8427 /* Parse an objc-class-declaration.
8429 objc-class-declaration:
8430 @class identifier-list ;
8434 c_parser_objc_class_declaration (c_parser
*parser
)
8436 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8437 c_parser_consume_token (parser
);
8438 /* Any identifiers, including those declared as type names, are OK
8443 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8445 c_parser_error (parser
, "expected identifier");
8446 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8447 parser
->error
= false;
8450 id
= c_parser_peek_token (parser
)->value
;
8451 objc_declare_class (id
);
8452 c_parser_consume_token (parser
);
8453 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8454 c_parser_consume_token (parser
);
8458 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8461 /* Parse an objc-alias-declaration.
8463 objc-alias-declaration:
8464 @compatibility_alias identifier identifier ;
8468 c_parser_objc_alias_declaration (c_parser
*parser
)
8471 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8472 c_parser_consume_token (parser
);
8473 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8475 c_parser_error (parser
, "expected identifier");
8476 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8479 id1
= c_parser_peek_token (parser
)->value
;
8480 c_parser_consume_token (parser
);
8481 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8483 c_parser_error (parser
, "expected identifier");
8484 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8487 id2
= c_parser_peek_token (parser
)->value
;
8488 c_parser_consume_token (parser
);
8489 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8490 objc_declare_alias (id1
, id2
);
8493 /* Parse an objc-protocol-definition.
8495 objc-protocol-definition:
8496 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8497 @protocol identifier-list ;
8499 "@protocol identifier ;" should be resolved as "@protocol
8500 identifier-list ;": objc-methodprotolist may not start with a
8501 semicolon in the first alternative if objc-protocol-refs are
8505 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8507 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8509 c_parser_consume_token (parser
);
8510 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8512 c_parser_error (parser
, "expected identifier");
8515 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8516 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8518 /* Any identifiers, including those declared as type names, are
8523 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8525 c_parser_error (parser
, "expected identifier");
8528 id
= c_parser_peek_token (parser
)->value
;
8529 objc_declare_protocol (id
, attributes
);
8530 c_parser_consume_token (parser
);
8531 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8532 c_parser_consume_token (parser
);
8536 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8540 tree id
= c_parser_peek_token (parser
)->value
;
8541 tree proto
= NULL_TREE
;
8542 c_parser_consume_token (parser
);
8543 if (c_parser_next_token_is (parser
, CPP_LESS
))
8544 proto
= c_parser_objc_protocol_refs (parser
);
8545 parser
->objc_pq_context
= true;
8546 objc_start_protocol (id
, proto
, attributes
);
8547 c_parser_objc_methodprotolist (parser
);
8548 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8549 parser
->objc_pq_context
= false;
8550 objc_finish_interface ();
8554 /* Parse an objc-method-type.
8560 Return true if it is a class method (+) and false if it is
8561 an instance method (-).
8564 c_parser_objc_method_type (c_parser
*parser
)
8566 switch (c_parser_peek_token (parser
)->type
)
8569 c_parser_consume_token (parser
);
8572 c_parser_consume_token (parser
);
8579 /* Parse an objc-method-definition.
8581 objc-method-definition:
8582 objc-method-type objc-method-decl ;[opt] compound-statement
8586 c_parser_objc_method_definition (c_parser
*parser
)
8588 bool is_class_method
= c_parser_objc_method_type (parser
);
8589 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8590 parser
->objc_pq_context
= true;
8591 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8593 if (decl
== error_mark_node
)
8594 return; /* Bail here. */
8596 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8598 c_parser_consume_token (parser
);
8599 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8600 "extra semicolon in method definition specified");
8603 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8605 c_parser_error (parser
, "expected %<{%>");
8609 parser
->objc_pq_context
= false;
8610 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8612 add_stmt (c_parser_compound_statement (parser
));
8613 objc_finish_method_definition (current_function_decl
);
8617 /* This code is executed when we find a method definition
8618 outside of an @implementation context (or invalid for other
8619 reasons). Parse the method (to keep going) but do not emit
8622 c_parser_compound_statement (parser
);
8626 /* Parse an objc-methodprotolist.
8628 objc-methodprotolist:
8630 objc-methodprotolist objc-methodproto
8631 objc-methodprotolist declaration
8632 objc-methodprotolist ;
8636 The declaration is a data definition, which may be missing
8637 declaration specifiers under the same rules and diagnostics as
8638 other data definitions outside functions, and the stray semicolon
8639 is diagnosed the same way as a stray semicolon outside a
8643 c_parser_objc_methodprotolist (c_parser
*parser
)
8647 /* The list is terminated by @end. */
8648 switch (c_parser_peek_token (parser
)->type
)
8651 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8652 "ISO C does not allow extra %<;%> outside of a function");
8653 c_parser_consume_token (parser
);
8657 c_parser_objc_methodproto (parser
);
8660 c_parser_pragma (parser
, pragma_external
);
8665 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8667 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8668 c_parser_objc_at_property_declaration (parser
);
8669 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8671 objc_set_method_opt (true);
8672 c_parser_consume_token (parser
);
8674 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8676 objc_set_method_opt (false);
8677 c_parser_consume_token (parser
);
8680 c_parser_declaration_or_fndef (parser
, false, false, true,
8681 false, true, NULL
, vNULL
);
8687 /* Parse an objc-methodproto.
8690 objc-method-type objc-method-decl ;
8694 c_parser_objc_methodproto (c_parser
*parser
)
8696 bool is_class_method
= c_parser_objc_method_type (parser
);
8697 tree decl
, attributes
= NULL_TREE
;
8699 /* Remember protocol qualifiers in prototypes. */
8700 parser
->objc_pq_context
= true;
8701 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8703 /* Forget protocol qualifiers now. */
8704 parser
->objc_pq_context
= false;
8706 /* Do not allow the presence of attributes to hide an erroneous
8707 method implementation in the interface section. */
8708 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8710 c_parser_error (parser
, "expected %<;%>");
8714 if (decl
!= error_mark_node
)
8715 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8717 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8720 /* If we are at a position that method attributes may be present, check that
8721 there are not any parsed already (a syntax error) and then collect any
8722 specified at the current location. Finally, if new attributes were present,
8723 check that the next token is legal ( ';' for decls and '{' for defs). */
8726 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8731 c_parser_error (parser
,
8732 "method attributes must be specified at the end only");
8733 *attributes
= NULL_TREE
;
8737 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8738 *attributes
= c_parser_attributes (parser
);
8740 /* If there were no attributes here, just report any earlier error. */
8741 if (*attributes
== NULL_TREE
|| bad
)
8744 /* If the attributes are followed by a ; or {, then just report any earlier
8746 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8747 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8750 /* We've got attributes, but not at the end. */
8751 c_parser_error (parser
,
8752 "expected %<;%> or %<{%> after method attribute definition");
8756 /* Parse an objc-method-decl.
8759 ( objc-type-name ) objc-selector
8761 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8762 objc-keyword-selector objc-optparmlist
8765 objc-keyword-selector:
8767 objc-keyword-selector objc-keyword-decl
8770 objc-selector : ( objc-type-name ) identifier
8771 objc-selector : identifier
8772 : ( objc-type-name ) identifier
8776 objc-optparms objc-optellipsis
8780 objc-opt-parms , parameter-declaration
8788 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8789 tree
*attributes
, tree
*expr
)
8791 tree type
= NULL_TREE
;
8793 tree parms
= NULL_TREE
;
8794 bool ellipsis
= false;
8795 bool attr_err
= false;
8797 *attributes
= NULL_TREE
;
8798 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8800 c_parser_consume_token (parser
);
8801 type
= c_parser_objc_type_name (parser
);
8802 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8804 sel
= c_parser_objc_selector (parser
);
8805 /* If there is no selector, or a colon follows, we have an
8806 objc-keyword-selector. If there is a selector, and a colon does
8807 not follow, that selector ends the objc-method-decl. */
8808 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8811 tree list
= NULL_TREE
;
8814 tree atype
= NULL_TREE
, id
, keyworddecl
;
8815 tree param_attr
= NULL_TREE
;
8816 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8818 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8820 c_parser_consume_token (parser
);
8821 atype
= c_parser_objc_type_name (parser
);
8822 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8825 /* New ObjC allows attributes on method parameters. */
8826 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8827 param_attr
= c_parser_attributes (parser
);
8828 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8830 c_parser_error (parser
, "expected identifier");
8831 return error_mark_node
;
8833 id
= c_parser_peek_token (parser
)->value
;
8834 c_parser_consume_token (parser
);
8835 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8836 list
= chainon (list
, keyworddecl
);
8837 tsel
= c_parser_objc_selector (parser
);
8838 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8842 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8844 /* Parse the optional parameter list. Optional Objective-C
8845 method parameters follow the C syntax, and may include '...'
8846 to denote a variable number of arguments. */
8847 parms
= make_node (TREE_LIST
);
8848 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8850 struct c_parm
*parm
;
8851 c_parser_consume_token (parser
);
8852 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8855 c_parser_consume_token (parser
);
8856 attr_err
|= c_parser_objc_maybe_method_attributes
8857 (parser
, attributes
) ;
8860 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8863 parms
= chainon (parms
,
8864 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8869 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8873 c_parser_error (parser
, "objective-c method declaration is expected");
8874 return error_mark_node
;
8878 return error_mark_node
;
8880 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8883 /* Parse an objc-type-name.
8886 objc-type-qualifiers[opt] type-name
8887 objc-type-qualifiers[opt]
8889 objc-type-qualifiers:
8891 objc-type-qualifiers objc-type-qualifier
8893 objc-type-qualifier: one of
8894 in out inout bycopy byref oneway
8898 c_parser_objc_type_name (c_parser
*parser
)
8900 tree quals
= NULL_TREE
;
8901 struct c_type_name
*type_name
= NULL
;
8902 tree type
= NULL_TREE
;
8905 c_token
*token
= c_parser_peek_token (parser
);
8906 if (token
->type
== CPP_KEYWORD
8907 && (token
->keyword
== RID_IN
8908 || token
->keyword
== RID_OUT
8909 || token
->keyword
== RID_INOUT
8910 || token
->keyword
== RID_BYCOPY
8911 || token
->keyword
== RID_BYREF
8912 || token
->keyword
== RID_ONEWAY
))
8914 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8915 c_parser_consume_token (parser
);
8920 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8921 type_name
= c_parser_type_name (parser
);
8923 type
= groktypename (type_name
, NULL
, NULL
);
8925 /* If the type is unknown, and error has already been produced and
8926 we need to recover from the error. In that case, use NULL_TREE
8927 for the type, as if no type had been specified; this will use the
8928 default type ('id') which is good for error recovery. */
8929 if (type
== error_mark_node
)
8932 return build_tree_list (quals
, type
);
8935 /* Parse objc-protocol-refs.
8942 c_parser_objc_protocol_refs (c_parser
*parser
)
8944 tree list
= NULL_TREE
;
8945 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8946 c_parser_consume_token (parser
);
8947 /* Any identifiers, including those declared as type names, are OK
8952 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8954 c_parser_error (parser
, "expected identifier");
8957 id
= c_parser_peek_token (parser
)->value
;
8958 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8959 c_parser_consume_token (parser
);
8960 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8961 c_parser_consume_token (parser
);
8965 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8969 /* Parse an objc-try-catch-finally-statement.
8971 objc-try-catch-finally-statement:
8972 @try compound-statement objc-catch-list[opt]
8973 @try compound-statement objc-catch-list[opt] @finally compound-statement
8976 @catch ( objc-catch-parameter-declaration ) compound-statement
8977 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8979 objc-catch-parameter-declaration:
8980 parameter-declaration
8983 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8985 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8986 for C++. Keep them in sync. */
8989 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8991 location_t location
;
8994 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8995 c_parser_consume_token (parser
);
8996 location
= c_parser_peek_token (parser
)->location
;
8997 objc_maybe_warn_exceptions (location
);
8998 stmt
= c_parser_compound_statement (parser
);
8999 objc_begin_try_stmt (location
, stmt
);
9001 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9003 struct c_parm
*parm
;
9004 tree parameter_declaration
= error_mark_node
;
9005 bool seen_open_paren
= false;
9007 c_parser_consume_token (parser
);
9008 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9009 seen_open_paren
= true;
9010 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9012 /* We have "@catch (...)" (where the '...' are literally
9013 what is in the code). Skip the '...'.
9014 parameter_declaration is set to NULL_TREE, and
9015 objc_being_catch_clauses() knows that that means
9017 c_parser_consume_token (parser
);
9018 parameter_declaration
= NULL_TREE
;
9022 /* We have "@catch (NSException *exception)" or something
9023 like that. Parse the parameter declaration. */
9024 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9026 parameter_declaration
= error_mark_node
;
9028 parameter_declaration
= grokparm (parm
, NULL
);
9030 if (seen_open_paren
)
9031 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9034 /* If there was no open parenthesis, we are recovering from
9035 an error, and we are trying to figure out what mistake
9036 the user has made. */
9038 /* If there is an immediate closing parenthesis, the user
9039 probably forgot the opening one (ie, they typed "@catch
9040 NSException *e)". Parse the closing parenthesis and keep
9042 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9043 c_parser_consume_token (parser
);
9045 /* If these is no immediate closing parenthesis, the user
9046 probably doesn't know that parenthesis are required at
9047 all (ie, they typed "@catch NSException *e"). So, just
9048 forget about the closing parenthesis and keep going. */
9050 objc_begin_catch_clause (parameter_declaration
);
9051 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9052 c_parser_compound_statement_nostart (parser
);
9053 objc_finish_catch_clause ();
9055 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9057 c_parser_consume_token (parser
);
9058 location
= c_parser_peek_token (parser
)->location
;
9059 stmt
= c_parser_compound_statement (parser
);
9060 objc_build_finally_clause (location
, stmt
);
9062 objc_finish_try_stmt ();
9065 /* Parse an objc-synchronized-statement.
9067 objc-synchronized-statement:
9068 @synchronized ( expression ) compound-statement
9072 c_parser_objc_synchronized_statement (c_parser
*parser
)
9076 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9077 c_parser_consume_token (parser
);
9078 loc
= c_parser_peek_token (parser
)->location
;
9079 objc_maybe_warn_exceptions (loc
);
9080 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9082 struct c_expr ce
= c_parser_expression (parser
);
9083 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9085 expr
= c_fully_fold (expr
, false, NULL
);
9086 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9089 expr
= error_mark_node
;
9090 stmt
= c_parser_compound_statement (parser
);
9091 objc_build_synchronized (loc
, expr
, stmt
);
9094 /* Parse an objc-selector; return NULL_TREE without an error if the
9095 next token is not an objc-selector.
9100 enum struct union if else while do for switch case default
9101 break continue return goto asm sizeof typeof __alignof
9102 unsigned long const short volatile signed restrict _Complex
9103 in out inout bycopy byref oneway int char float double void _Bool
9106 ??? Why this selection of keywords but not, for example, storage
9107 class specifiers? */
9110 c_parser_objc_selector (c_parser
*parser
)
9112 c_token
*token
= c_parser_peek_token (parser
);
9113 tree value
= token
->value
;
9114 if (token
->type
== CPP_NAME
)
9116 c_parser_consume_token (parser
);
9119 if (token
->type
!= CPP_KEYWORD
)
9121 switch (token
->keyword
)
9165 c_parser_consume_token (parser
);
9172 /* Parse an objc-selector-arg.
9176 objc-keywordname-list
9178 objc-keywordname-list:
9180 objc-keywordname-list objc-keywordname
9188 c_parser_objc_selector_arg (c_parser
*parser
)
9190 tree sel
= c_parser_objc_selector (parser
);
9191 tree list
= NULL_TREE
;
9192 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9196 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9198 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9199 sel
= c_parser_objc_selector (parser
);
9200 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9206 /* Parse an objc-receiver.
9215 c_parser_objc_receiver (c_parser
*parser
)
9217 location_t loc
= c_parser_peek_token (parser
)->location
;
9219 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9220 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9221 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9223 tree id
= c_parser_peek_token (parser
)->value
;
9224 c_parser_consume_token (parser
);
9225 return objc_get_class_reference (id
);
9227 struct c_expr ce
= c_parser_expression (parser
);
9228 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9229 return c_fully_fold (ce
.value
, false, NULL
);
9232 /* Parse objc-message-args.
9236 objc-keywordarg-list
9238 objc-keywordarg-list:
9240 objc-keywordarg-list objc-keywordarg
9243 objc-selector : objc-keywordexpr
9248 c_parser_objc_message_args (c_parser
*parser
)
9250 tree sel
= c_parser_objc_selector (parser
);
9251 tree list
= NULL_TREE
;
9252 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9257 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9258 return error_mark_node
;
9259 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9260 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9261 sel
= c_parser_objc_selector (parser
);
9262 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9268 /* Parse an objc-keywordexpr.
9275 c_parser_objc_keywordexpr (c_parser
*parser
)
9278 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9279 NULL
, NULL
, NULL
, NULL
);
9280 if (vec_safe_length (expr_list
) == 1)
9282 /* Just return the expression, remove a level of
9284 ret
= (*expr_list
)[0];
9288 /* We have a comma expression, we will collapse later. */
9289 ret
= build_tree_list_vec (expr_list
);
9291 release_tree_vector (expr_list
);
9295 /* A check, needed in several places, that ObjC interface, implementation or
9296 method definitions are not prefixed by incorrect items. */
9298 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9299 struct c_declspecs
*specs
)
9301 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9302 || specs
->typespec_kind
!= ctsk_none
)
9304 c_parser_error (parser
,
9305 "no type or storage class may be specified here,");
9306 c_parser_skip_to_end_of_block_or_statement (parser
);
9312 /* Parse an Objective-C @property declaration. The syntax is:
9314 objc-property-declaration:
9315 '@property' objc-property-attributes[opt] struct-declaration ;
9317 objc-property-attributes:
9318 '(' objc-property-attribute-list ')'
9320 objc-property-attribute-list:
9321 objc-property-attribute
9322 objc-property-attribute-list, objc-property-attribute
9324 objc-property-attribute
9325 'getter' = identifier
9326 'setter' = identifier
9335 @property NSString *name;
9336 @property (readonly) id object;
9337 @property (retain, nonatomic, getter=getTheName) id name;
9338 @property int a, b, c;
9340 PS: This function is identical to cp_parser_objc_at_propery_declaration
9341 for C++. Keep them in sync. */
9343 c_parser_objc_at_property_declaration (c_parser
*parser
)
9345 /* The following variables hold the attributes of the properties as
9346 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9347 seen. When we see an attribute, we set them to 'true' (if they
9348 are boolean properties) or to the identifier (if they have an
9349 argument, ie, for getter and setter). Note that here we only
9350 parse the list of attributes, check the syntax and accumulate the
9351 attributes that we find. objc_add_property_declaration() will
9352 then process the information. */
9353 bool property_assign
= false;
9354 bool property_copy
= false;
9355 tree property_getter_ident
= NULL_TREE
;
9356 bool property_nonatomic
= false;
9357 bool property_readonly
= false;
9358 bool property_readwrite
= false;
9359 bool property_retain
= false;
9360 tree property_setter_ident
= NULL_TREE
;
9362 /* 'properties' is the list of properties that we read. Usually a
9363 single one, but maybe more (eg, in "@property int a, b, c;" there
9368 loc
= c_parser_peek_token (parser
)->location
;
9369 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9371 c_parser_consume_token (parser
); /* Eat '@property'. */
9373 /* Parse the optional attribute list... */
9374 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9377 c_parser_consume_token (parser
);
9379 /* Property attribute keywords are valid now. */
9380 parser
->objc_property_attr_context
= true;
9384 bool syntax_error
= false;
9385 c_token
*token
= c_parser_peek_token (parser
);
9388 if (token
->type
!= CPP_KEYWORD
)
9390 if (token
->type
== CPP_CLOSE_PAREN
)
9391 c_parser_error (parser
, "expected identifier");
9394 c_parser_consume_token (parser
);
9395 c_parser_error (parser
, "unknown property attribute");
9399 keyword
= token
->keyword
;
9400 c_parser_consume_token (parser
);
9403 case RID_ASSIGN
: property_assign
= true; break;
9404 case RID_COPY
: property_copy
= true; break;
9405 case RID_NONATOMIC
: property_nonatomic
= true; break;
9406 case RID_READONLY
: property_readonly
= true; break;
9407 case RID_READWRITE
: property_readwrite
= true; break;
9408 case RID_RETAIN
: property_retain
= true; break;
9412 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9414 if (keyword
== RID_GETTER
)
9415 c_parser_error (parser
,
9416 "missing %<=%> (after %<getter%> attribute)");
9418 c_parser_error (parser
,
9419 "missing %<=%> (after %<setter%> attribute)");
9420 syntax_error
= true;
9423 c_parser_consume_token (parser
); /* eat the = */
9424 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9426 c_parser_error (parser
, "expected identifier");
9427 syntax_error
= true;
9430 if (keyword
== RID_SETTER
)
9432 if (property_setter_ident
!= NULL_TREE
)
9433 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9435 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9436 c_parser_consume_token (parser
);
9437 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9438 c_parser_error (parser
, "setter name must terminate with %<:%>");
9440 c_parser_consume_token (parser
);
9444 if (property_getter_ident
!= NULL_TREE
)
9445 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9447 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9448 c_parser_consume_token (parser
);
9452 c_parser_error (parser
, "unknown property attribute");
9453 syntax_error
= true;
9460 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9461 c_parser_consume_token (parser
);
9465 parser
->objc_property_attr_context
= false;
9466 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9468 /* ... and the property declaration(s). */
9469 properties
= c_parser_struct_declaration (parser
);
9471 if (properties
== error_mark_node
)
9473 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9474 parser
->error
= false;
9478 if (properties
== NULL_TREE
)
9479 c_parser_error (parser
, "expected identifier");
9482 /* Comma-separated properties are chained together in
9483 reverse order; add them one by one. */
9484 properties
= nreverse (properties
);
9486 for (; properties
; properties
= TREE_CHAIN (properties
))
9487 objc_add_property_declaration (loc
, copy_node (properties
),
9488 property_readonly
, property_readwrite
,
9489 property_assign
, property_retain
,
9490 property_copy
, property_nonatomic
,
9491 property_getter_ident
, property_setter_ident
);
9494 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9495 parser
->error
= false;
9498 /* Parse an Objective-C @synthesize declaration. The syntax is:
9500 objc-synthesize-declaration:
9501 @synthesize objc-synthesize-identifier-list ;
9503 objc-synthesize-identifier-list:
9504 objc-synthesize-identifier
9505 objc-synthesize-identifier-list, objc-synthesize-identifier
9507 objc-synthesize-identifier
9509 identifier = identifier
9512 @synthesize MyProperty;
9513 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9515 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9516 for C++. Keep them in sync.
9519 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9521 tree list
= NULL_TREE
;
9523 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9524 loc
= c_parser_peek_token (parser
)->location
;
9526 c_parser_consume_token (parser
);
9529 tree property
, ivar
;
9530 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9532 c_parser_error (parser
, "expected identifier");
9533 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9534 /* Once we find the semicolon, we can resume normal parsing.
9535 We have to reset parser->error manually because
9536 c_parser_skip_until_found() won't reset it for us if the
9537 next token is precisely a semicolon. */
9538 parser
->error
= false;
9541 property
= c_parser_peek_token (parser
)->value
;
9542 c_parser_consume_token (parser
);
9543 if (c_parser_next_token_is (parser
, CPP_EQ
))
9545 c_parser_consume_token (parser
);
9546 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9548 c_parser_error (parser
, "expected identifier");
9549 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9550 parser
->error
= false;
9553 ivar
= c_parser_peek_token (parser
)->value
;
9554 c_parser_consume_token (parser
);
9558 list
= chainon (list
, build_tree_list (ivar
, property
));
9559 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9560 c_parser_consume_token (parser
);
9564 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9565 objc_add_synthesize_declaration (loc
, list
);
9568 /* Parse an Objective-C @dynamic declaration. The syntax is:
9570 objc-dynamic-declaration:
9571 @dynamic identifier-list ;
9574 @dynamic MyProperty;
9575 @dynamic MyProperty, AnotherProperty;
9577 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9578 for C++. Keep them in sync.
9581 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9583 tree list
= NULL_TREE
;
9585 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9586 loc
= c_parser_peek_token (parser
)->location
;
9588 c_parser_consume_token (parser
);
9592 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9594 c_parser_error (parser
, "expected identifier");
9595 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9596 parser
->error
= false;
9599 property
= c_parser_peek_token (parser
)->value
;
9600 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9601 c_parser_consume_token (parser
);
9602 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9603 c_parser_consume_token (parser
);
9607 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9608 objc_add_dynamic_declaration (loc
, list
);
9611 /* Parse UPC shared qualifier
9613 shared-type-qualifier: shared layout-qualifier-opt
9614 layout-qualifier: [ constant-expression-opt ] | [ * ]
9618 c_parser_upc_shared_qual (source_location loc
,
9620 struct c_declspecs
*specs
)
9622 tree array_qual
, arg1
;
9624 /* consume "shared" part */
9625 c_parser_consume_token (parser
);
9627 /* check for shared array layout specifier */
9628 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9630 declspecs_add_qual (loc
, specs
, ridpointers
[RID_SHARED
]);
9633 c_parser_consume_token (parser
);
9634 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9636 /* [] layout specifier */
9637 arg1
= size_zero_node
;
9639 else if (c_parser_next_token_is (parser
, CPP_MULT
))
9641 /* [*] layout specifier */
9642 arg1
= build1 (INDIRECT_REF
, NULL_TREE
, NULL_TREE
);
9643 c_parser_consume_token (parser
);
9647 /* [ expression ] layout specifier */
9648 arg1
= c_parser_expression (parser
).value
;
9650 array_qual
= build4 (ARRAY_REF
, NULL_TREE
, NULL_TREE
,
9651 arg1
, NULL_TREE
, NULL_TREE
);
9652 declspecs_add_qual (loc
, specs
, array_qual
);
9654 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9656 c_parser_error (parser
, "expected ]");
9658 c_parser_consume_token (parser
);
9661 /* Implement UPC's upc_forall 'affinity' test.
9662 If the type of AFFINITY is a UPC pointer-to-shared type,
9664 upc_threadof (AFFINITY) == MYTHREAD
9665 If AFFINITY is an integer expression, then
9667 (AFFINITY % THREADS) == MYTHREAD */
9670 upc_affinity_test (location_t loc
, tree affinity
)
9675 gcc_assert (affinity
!= NULL_TREE
);
9677 if (TREE_CODE (TREE_TYPE (affinity
)) == POINTER_TYPE
9678 && upc_shared_type_p (TREE_TYPE (TREE_TYPE (affinity
))))
9680 /* We have a pointer to a UPC shared object and the affinity is
9681 determined by the thread component of the address. */
9682 const tree pts_rep
= build1 (VIEW_CONVERT_EXPR
, upc_pts_rep_type_node
,
9683 save_expr (affinity
));
9684 affinity
= (*upc_pts
.threadof
) (loc
, pts_rep
);
9686 else if (TREE_CODE (TREE_TYPE (affinity
)) == INTEGER_TYPE
)
9688 tree n_threads
= upc_num_threads ();
9690 build_binary_op (loc
, FLOOR_MOD_EXPR
, affinity
, n_threads
, 0);
9695 ("UPC affinity expression is neither an integer nor the address of "
9697 return error_mark_node
;
9700 /* Generate an external reference to the "MYTHREAD" identifier. */
9702 mythread
= lookup_name (get_identifier ("MYTHREAD"));
9703 gcc_assert (mythread
!= NULL_TREE
);
9704 assemble_external (mythread
);
9705 TREE_USED (mythread
) = 1;
9707 /* AFFINITY now contains an integer value that can be compared to MY_THREAD.
9708 Create an expression that tests if AFFINITY is equal to MYTHREAD. */
9710 if (!c_types_compatible_p (TREE_TYPE (affinity
), TREE_TYPE (mythread
)))
9711 affinity
= convert (TREE_TYPE (mythread
), affinity
);
9712 affinity_test
= c_objc_common_truthvalue_conversion (loc
,
9713 build_binary_op (loc
, EQ_EXPR
,
9714 affinity
, mythread
, 1));
9715 /* Remove any MAYBE_CONST_EXPR's. */
9717 affinity_test
= c_fully_fold (affinity_test
, false, NULL
);
9719 return affinity_test
;
9722 /* Parse a UPC upc_forall statement
9724 upc_forall-statement:
9725 upc_forall ( expression[opt] ; expression[opt] ;
9726 expression[opt] ; affinity[opt] ) statement
9727 affinity: experssion | continue */
9730 c_parser_upc_forall_statement (c_parser
*parser
)
9732 tree block
, cond
, incr
, save_break
, save_cont
, body
;
9734 location_t loc
= c_parser_peek_token (parser
)->location
;
9735 location_t affinity_loc
= UNKNOWN_LOCATION
;
9736 const int profile_upc_forall
= flag_upc_instrument
&& get_upc_pupc_mode();
9737 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_FORALL
));
9738 c_parser_consume_token (parser
);
9739 block
= c_begin_compound_stmt (flag_isoc99
);
9740 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9742 /* Parse the initialization declaration or expression. */
9743 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9745 c_parser_consume_token (parser
);
9746 c_finish_expr_stmt (loc
, NULL_TREE
);
9748 else if (c_parser_next_token_starts_declspecs (parser
))
9750 c_parser_declaration_or_fndef (parser
, true, true, true,
9751 true, true, NULL
, vNULL
);
9752 check_for_loop_decls (loc
, true);
9754 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
9756 /* __extension__ can start a declaration, but is also an
9757 unary operator that can start an expression. Consume all
9758 but the last of a possible series of __extension__ to
9760 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
9761 && (c_parser_peek_2nd_token (parser
)->keyword
9763 c_parser_consume_token (parser
);
9764 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
9767 ext
= disable_extension_diagnostics ();
9768 c_parser_consume_token (parser
);
9769 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
9771 restore_extension_diagnostics (ext
);
9772 check_for_loop_decls (loc
, true);
9780 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
9781 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9783 /* Parse the loop condition. */
9784 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9786 c_parser_consume_token (parser
);
9791 cond
= c_parser_condition (parser
);
9792 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9794 /* Parse the increment expression. */
9795 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9796 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
9798 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
9799 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9800 /* Parse the UPC affinity expression. */
9801 affinity_loc
= c_parser_peek_token (parser
)->location
;
9802 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9804 affinity
= NULL_TREE
;
9806 else if (c_parser_peek_token (parser
)->type
== CPP_KEYWORD
9807 && c_parser_peek_token (parser
)->keyword
== RID_CONTINUE
)
9809 affinity
= NULL_TREE
;
9810 c_parser_consume_token (parser
);
9814 affinity
= c_parser_expression_conv (parser
).value
;
9815 affinity
= c_fully_fold (affinity
, false, NULL
);
9817 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9819 affinity
= upc_affinity_test (affinity_loc
, affinity
);
9823 cond
= error_mark_node
;
9824 incr
= error_mark_node
;
9825 affinity
= error_mark_node
;
9827 save_break
= c_break_label
;
9828 c_break_label
= NULL_TREE
;
9829 save_cont
= c_cont_label
;
9830 c_cont_label
= NULL_TREE
;
9831 body
= c_parser_c99_block_statement (parser
);
9832 if (profile_upc_forall
)
9834 const tree gasp_start
= upc_instrument_forall (loc
, 1 /* start */);
9835 add_stmt (gasp_start
);
9837 loc
= c_parser_peek_token (parser
)->location
;
9838 if (affinity
!= NULL_TREE
&& affinity
!= error_mark_node
)
9840 tree upc_forall_depth
= upc_rts_forall_depth_var ();
9841 tree inc_depth
, depth_gt_one
;
9842 inc_depth
= build_unary_op (loc
, PREINCREMENT_EXPR
, upc_forall_depth
, 0);
9843 c_finish_expr_stmt (loc
, inc_depth
);
9844 depth_gt_one
= build_binary_op (affinity_loc
,
9845 GT_EXPR
, upc_forall_depth
, integer_one_node
, 0);
9846 depth_gt_one
= c_objc_common_truthvalue_conversion (affinity_loc
, depth_gt_one
);
9847 depth_gt_one
= c_fully_fold (depth_gt_one
, false, NULL
);
9848 affinity
= build_binary_op (affinity_loc
, TRUTH_OR_EXPR
,
9849 depth_gt_one
, affinity
, 0);
9850 body
= build3 (COND_EXPR
, void_type_node
, affinity
,
9852 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
9853 c_finish_expr_stmt (loc
,
9854 build_unary_op (loc
, PREDECREMENT_EXPR
, upc_forall_depth
, 0));
9857 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
9858 if (profile_upc_forall
)
9860 const tree gasp_end
= upc_instrument_forall (loc
, 0 /* start */);
9861 add_stmt (gasp_end
);
9863 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
9864 c_break_label
= save_break
;
9865 c_cont_label
= save_cont
;
9868 /* For the given kind of UPC synchronization statement given
9869 by SYNC_KIND (UPC_SYNC_NOTIFY_OP, UPC_SYNC_WAIT_OP,
9870 or UPC_SYNC_BARRIER_OP), build a UPC_SYNC_STMT tree node,
9871 and add it to the current statement list. The value of
9872 SYNC_EXPR will be non-null if an expression is present
9873 in the UPC statement being compiled.
9875 If SYNC_EXPR is supplied, it must be assignment compatible
9879 upc_build_sync_stmt (location_t loc
, tree sync_kind
, tree sync_expr
)
9881 if (sync_expr
!= NULL_TREE
)
9883 mark_exp_read (sync_expr
);
9884 sync_expr
= c_cvt_expr_for_assign (loc
, integer_type_node
, sync_expr
);
9885 if (sync_expr
== error_mark_node
)
9887 inform (loc
, "UPC synchronization statement expressions "
9888 "must be assignment compatible with type `int'");
9889 sync_expr
= NULL_TREE
;
9892 return add_stmt (build_stmt (loc
, UPC_SYNC_STMT
, sync_kind
, sync_expr
));
9895 /* Parse an upc-sync-statement.
9897 upc_barrier, upc_wait, upc_notify
9901 c_parser_upc_sync_statement (c_parser
*parser
, int sync_kind
)
9904 tree expr
= NULL_TREE
;
9906 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_BARRIER
) ||
9907 c_parser_next_token_is_keyword (parser
, RID_UPC_NOTIFY
) ||
9908 c_parser_next_token_is_keyword (parser
, RID_UPC_WAIT
));
9909 loc
= c_parser_peek_token (parser
)->location
;
9910 c_parser_consume_token (parser
);
9911 if (c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
9913 loc
= c_parser_peek_token (parser
)->location
;
9914 expr
= c_parser_expression (parser
).value
;
9915 if (expr
== error_mark_node
)
9918 stmt
= size_int (sync_kind
);
9919 (void) upc_build_sync_stmt (loc
, stmt
, expr
);
9923 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9924 should be considered, statements. ALLOW_STMT is true if we're within
9925 the context of a function and such pragmas are to be allowed. Returns
9926 true if we actually parsed such a pragma. */
9929 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9933 id
= c_parser_peek_token (parser
)->pragma_kind
;
9934 gcc_assert (id
!= PRAGMA_NONE
);
9938 case PRAGMA_OMP_BARRIER
:
9939 if (context
!= pragma_compound
)
9941 if (context
== pragma_stmt
)
9942 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9943 "used in compound statements");
9946 c_parser_omp_barrier (parser
);
9949 case PRAGMA_OMP_FLUSH
:
9950 if (context
!= pragma_compound
)
9952 if (context
== pragma_stmt
)
9953 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9954 "used in compound statements");
9957 c_parser_omp_flush (parser
);
9960 case PRAGMA_OMP_TASKWAIT
:
9961 if (context
!= pragma_compound
)
9963 if (context
== pragma_stmt
)
9964 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9965 "used in compound statements");
9968 c_parser_omp_taskwait (parser
);
9971 case PRAGMA_OMP_TASKYIELD
:
9972 if (context
!= pragma_compound
)
9974 if (context
== pragma_stmt
)
9975 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9976 "used in compound statements");
9979 c_parser_omp_taskyield (parser
);
9982 case PRAGMA_OMP_CANCEL
:
9983 if (context
!= pragma_compound
)
9985 if (context
== pragma_stmt
)
9986 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9987 "used in compound statements");
9990 c_parser_omp_cancel (parser
);
9993 case PRAGMA_OMP_CANCELLATION_POINT
:
9994 if (context
!= pragma_compound
)
9996 if (context
== pragma_stmt
)
9997 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9998 "only be used in compound statements");
10001 c_parser_omp_cancellation_point (parser
);
10004 case PRAGMA_OMP_THREADPRIVATE
:
10005 c_parser_omp_threadprivate (parser
);
10008 case PRAGMA_OMP_TARGET
:
10009 return c_parser_omp_target (parser
, context
);
10011 case PRAGMA_OMP_END_DECLARE_TARGET
:
10012 c_parser_omp_end_declare_target (parser
);
10015 case PRAGMA_OMP_SECTION
:
10016 error_at (c_parser_peek_token (parser
)->location
,
10017 "%<#pragma omp section%> may only be used in "
10018 "%<#pragma omp sections%> construct");
10019 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10022 case PRAGMA_OMP_DECLARE_REDUCTION
:
10023 c_parser_omp_declare (parser
, context
);
10026 c_parser_consume_pragma (parser
);
10027 c_parser_skip_to_pragma_eol (parser
);
10028 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10029 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10030 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10032 c_parser_error (parser
, "for, while or do statement expected");
10035 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10036 c_parser_for_statement (parser
, true);
10037 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10038 c_parser_while_statement (parser
, true);
10040 c_parser_do_statement (parser
, true);
10043 case PRAGMA_GCC_PCH_PREPROCESS
:
10044 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10045 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10048 case PRAGMA_CILK_SIMD
:
10049 if (!c_parser_cilk_verify_simd (parser
, context
))
10051 c_parser_consume_pragma (parser
);
10052 c_parser_cilk_simd (parser
);
10056 if (id
< PRAGMA_FIRST_EXTERNAL
)
10058 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10061 c_parser_error (parser
, "expected declaration specifiers");
10062 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10065 c_parser_omp_construct (parser
);
10071 c_parser_consume_pragma (parser
);
10072 c_invoke_pragma_handler (id
);
10074 /* Skip to EOL, but suppress any error message. Those will have been
10075 generated by the handler routine through calling error, as opposed
10076 to calling c_parser_error. */
10077 parser
->error
= true;
10078 c_parser_skip_to_pragma_eol (parser
);
10083 /* The interface the pragma parsers have to the lexer. */
10086 pragma_lex (tree
*value
)
10088 c_token
*tok
= c_parser_peek_token (the_parser
);
10089 enum cpp_ttype ret
= tok
->type
;
10091 *value
= tok
->value
;
10092 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
10096 if (ret
== CPP_KEYWORD
)
10098 c_parser_consume_token (the_parser
);
10105 c_parser_pragma_pch_preprocess (c_parser
*parser
)
10109 c_parser_consume_pragma (parser
);
10110 if (c_parser_next_token_is (parser
, CPP_STRING
))
10112 name
= c_parser_peek_token (parser
)->value
;
10113 c_parser_consume_token (parser
);
10116 c_parser_error (parser
, "expected string literal");
10117 c_parser_skip_to_pragma_eol (parser
);
10120 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
10123 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
10125 /* Returns name of the next clause.
10126 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10127 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10128 returned and the token is consumed. */
10130 static pragma_omp_clause
10131 c_parser_omp_clause_name (c_parser
*parser
)
10133 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
10135 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
10136 result
= PRAGMA_OMP_CLAUSE_IF
;
10137 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
10138 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
10139 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10140 result
= PRAGMA_OMP_CLAUSE_FOR
;
10141 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10143 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10148 if (!strcmp ("aligned", p
))
10149 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
10152 if (!strcmp ("collapse", p
))
10153 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
10154 else if (!strcmp ("copyin", p
))
10155 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
10156 else if (!strcmp ("copyprivate", p
))
10157 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
10160 if (!strcmp ("depend", p
))
10161 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
10162 else if (!strcmp ("device", p
))
10163 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
10164 else if (!strcmp ("dist_schedule", p
))
10165 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
10168 if (!strcmp ("final", p
))
10169 result
= PRAGMA_OMP_CLAUSE_FINAL
;
10170 else if (!strcmp ("firstprivate", p
))
10171 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
10172 else if (!strcmp ("from", p
))
10173 result
= PRAGMA_OMP_CLAUSE_FROM
;
10176 if (!strcmp ("inbranch", p
))
10177 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10180 if (!strcmp ("lastprivate", p
))
10181 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10182 else if (!strcmp ("linear", p
))
10183 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10186 if (!strcmp ("map", p
))
10187 result
= PRAGMA_OMP_CLAUSE_MAP
;
10188 else if (!strcmp ("mergeable", p
))
10189 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10190 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10191 result
= PRAGMA_CILK_CLAUSE_MASK
;
10194 if (!strcmp ("notinbranch", p
))
10195 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10196 else if (!strcmp ("nowait", p
))
10197 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10198 else if (!strcmp ("num_teams", p
))
10199 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10200 else if (!strcmp ("num_threads", p
))
10201 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10202 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10203 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10206 if (!strcmp ("ordered", p
))
10207 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10210 if (!strcmp ("parallel", p
))
10211 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10212 else if (!strcmp ("private", p
))
10213 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10214 else if (!strcmp ("proc_bind", p
))
10215 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10218 if (!strcmp ("reduction", p
))
10219 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10222 if (!strcmp ("safelen", p
))
10223 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10224 else if (!strcmp ("schedule", p
))
10225 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10226 else if (!strcmp ("sections", p
))
10227 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10228 else if (!strcmp ("shared", p
))
10229 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10230 else if (!strcmp ("simdlen", p
))
10231 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10234 if (!strcmp ("taskgroup", p
))
10235 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10236 else if (!strcmp ("thread_limit", p
))
10237 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10238 else if (!strcmp ("to", p
))
10239 result
= PRAGMA_OMP_CLAUSE_TO
;
10242 if (!strcmp ("uniform", p
))
10243 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10244 else if (!strcmp ("untied", p
))
10245 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10248 if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10249 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10254 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10255 c_parser_consume_token (parser
);
10260 /* Validate that a clause of the given type does not already exist. */
10263 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10268 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10269 if (OMP_CLAUSE_CODE (c
) == code
)
10271 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10272 error_at (loc
, "too many %qs clauses", name
);
10280 variable-list , identifier
10282 If KIND is nonzero, create the appropriate node and install the
10283 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10284 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10286 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10287 return the list created. */
10290 c_parser_omp_variable_list (c_parser
*parser
,
10291 location_t clause_loc
,
10292 enum omp_clause_code kind
, tree list
)
10294 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10295 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10296 c_parser_error (parser
, "expected identifier");
10298 while (c_parser_next_token_is (parser
, CPP_NAME
)
10299 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10301 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10303 if (t
== NULL_TREE
)
10305 undeclared_variable (c_parser_peek_token (parser
)->location
,
10306 c_parser_peek_token (parser
)->value
);
10307 t
= error_mark_node
;
10310 c_parser_consume_token (parser
);
10312 if (t
== error_mark_node
)
10314 else if (kind
!= 0)
10318 case OMP_CLAUSE_MAP
:
10319 case OMP_CLAUSE_FROM
:
10320 case OMP_CLAUSE_TO
:
10321 case OMP_CLAUSE_DEPEND
:
10322 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10324 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10326 c_parser_consume_token (parser
);
10327 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10328 low_bound
= c_parser_expression (parser
).value
;
10329 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10330 length
= integer_one_node
;
10333 /* Look for `:'. */
10334 if (!c_parser_require (parser
, CPP_COLON
,
10337 t
= error_mark_node
;
10340 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10341 length
= c_parser_expression (parser
).value
;
10343 /* Look for the closing `]'. */
10344 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10347 t
= error_mark_node
;
10350 t
= tree_cons (low_bound
, length
, t
);
10357 if (t
!= error_mark_node
)
10359 tree u
= build_omp_clause (clause_loc
, kind
);
10360 OMP_CLAUSE_DECL (u
) = t
;
10361 OMP_CLAUSE_CHAIN (u
) = list
;
10366 list
= tree_cons (t
, NULL_TREE
, list
);
10368 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10371 c_parser_consume_token (parser
);
10377 /* Similarly, but expect leading and trailing parenthesis. This is a very
10378 common case for omp clauses. */
10381 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10384 /* The clauses location. */
10385 location_t loc
= c_parser_peek_token (parser
)->location
;
10387 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10389 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10396 collapse ( constant-expression ) */
10399 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10401 tree c
, num
= error_mark_node
;
10405 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10407 loc
= c_parser_peek_token (parser
)->location
;
10408 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10410 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10411 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10413 if (num
== error_mark_node
)
10415 mark_exp_read (num
);
10416 num
= c_fully_fold (num
, false, NULL
);
10417 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10418 || !tree_fits_shwi_p (num
)
10419 || (n
= tree_to_shwi (num
)) <= 0
10423 "collapse argument needs positive constant integer expression");
10426 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10427 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10428 OMP_CLAUSE_CHAIN (c
) = list
;
10433 copyin ( variable-list ) */
10436 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10438 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10442 copyprivate ( variable-list ) */
10445 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10447 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10451 default ( shared | none ) */
10454 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10456 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10457 location_t loc
= c_parser_peek_token (parser
)->location
;
10460 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10462 if (c_parser_next_token_is (parser
, CPP_NAME
))
10464 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10469 if (strcmp ("none", p
) != 0)
10471 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10475 if (strcmp ("shared", p
) != 0)
10477 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10484 c_parser_consume_token (parser
);
10489 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10491 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10493 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10496 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10497 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10498 OMP_CLAUSE_CHAIN (c
) = list
;
10499 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10505 firstprivate ( variable-list ) */
10508 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10510 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10514 final ( expression ) */
10517 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10519 location_t loc
= c_parser_peek_token (parser
)->location
;
10520 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10522 tree t
= c_parser_paren_condition (parser
);
10525 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10527 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10528 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10529 OMP_CLAUSE_CHAIN (c
) = list
;
10533 c_parser_error (parser
, "expected %<(%>");
10539 if ( expression ) */
10542 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10544 location_t loc
= c_parser_peek_token (parser
)->location
;
10545 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10547 tree t
= c_parser_paren_condition (parser
);
10550 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10552 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10553 OMP_CLAUSE_IF_EXPR (c
) = t
;
10554 OMP_CLAUSE_CHAIN (c
) = list
;
10558 c_parser_error (parser
, "expected %<(%>");
10564 lastprivate ( variable-list ) */
10567 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10569 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10576 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10580 /* FIXME: Should we allow duplicates? */
10581 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10583 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10584 OMP_CLAUSE_MERGEABLE
);
10585 OMP_CLAUSE_CHAIN (c
) = list
;
10594 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10597 location_t loc
= c_parser_peek_token (parser
)->location
;
10599 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10601 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10602 OMP_CLAUSE_CHAIN (c
) = list
;
10607 num_threads ( expression ) */
10610 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10612 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10613 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10615 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10616 tree c
, t
= c_parser_expression (parser
).value
;
10618 t
= c_fully_fold (t
, false, NULL
);
10620 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10622 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10624 c_parser_error (parser
, "expected integer expression");
10628 /* Attempt to statically determine when the number isn't positive. */
10629 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10630 build_int_cst (TREE_TYPE (t
), 0));
10631 if (CAN_HAVE_LOCATION_P (c
))
10632 SET_EXPR_LOCATION (c
, expr_loc
);
10633 if (c
== boolean_true_node
)
10635 warning_at (expr_loc
, 0,
10636 "%<num_threads%> value must be positive");
10637 t
= integer_one_node
;
10640 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10642 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10643 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10644 OMP_CLAUSE_CHAIN (c
) = list
;
10655 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10659 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10661 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10662 OMP_CLAUSE_ORDERED
);
10663 OMP_CLAUSE_CHAIN (c
) = list
;
10669 private ( variable-list ) */
10672 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10674 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10678 reduction ( reduction-operator : variable-list )
10680 reduction-operator:
10681 One of: + * - & ^ | && ||
10685 reduction-operator:
10686 One of: + * - & ^ | && || max min
10690 reduction-operator:
10691 One of: + * - & ^ | && ||
10695 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10697 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10698 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10700 enum tree_code code
= ERROR_MARK
;
10701 tree reduc_id
= NULL_TREE
;
10703 switch (c_parser_peek_token (parser
)->type
)
10715 code
= BIT_AND_EXPR
;
10718 code
= BIT_XOR_EXPR
;
10721 code
= BIT_IOR_EXPR
;
10724 code
= TRUTH_ANDIF_EXPR
;
10727 code
= TRUTH_ORIF_EXPR
;
10732 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10733 if (strcmp (p
, "min") == 0)
10738 if (strcmp (p
, "max") == 0)
10743 reduc_id
= c_parser_peek_token (parser
)->value
;
10747 c_parser_error (parser
,
10748 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10749 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10750 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10753 c_parser_consume_token (parser
);
10754 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10755 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10759 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10760 OMP_CLAUSE_REDUCTION
, list
);
10761 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10763 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10764 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10765 if (code
== ERROR_MARK
10766 || !(INTEGRAL_TYPE_P (type
)
10767 || TREE_CODE (type
) == REAL_TYPE
10768 || TREE_CODE (type
) == COMPLEX_TYPE
))
10769 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10770 = c_omp_reduction_lookup (reduc_id
,
10771 TYPE_MAIN_VARIANT (type
));
10776 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10782 schedule ( schedule-kind )
10783 schedule ( schedule-kind , expression )
10786 static | dynamic | guided | runtime | auto
10790 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10793 location_t loc
= c_parser_peek_token (parser
)->location
;
10795 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10798 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10800 if (c_parser_next_token_is (parser
, CPP_NAME
))
10802 tree kind
= c_parser_peek_token (parser
)->value
;
10803 const char *p
= IDENTIFIER_POINTER (kind
);
10808 if (strcmp ("dynamic", p
) != 0)
10810 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10814 if (strcmp ("guided", p
) != 0)
10816 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10820 if (strcmp ("runtime", p
) != 0)
10822 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10829 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10830 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10831 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10832 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10836 c_parser_consume_token (parser
);
10837 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10840 c_parser_consume_token (parser
);
10842 here
= c_parser_peek_token (parser
)->location
;
10843 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10845 t
= c_fully_fold (t
, false, NULL
);
10847 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10848 error_at (here
, "schedule %<runtime%> does not take "
10849 "a %<chunk_size%> parameter");
10850 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10852 "schedule %<auto%> does not take "
10853 "a %<chunk_size%> parameter");
10854 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10855 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10857 c_parser_error (parser
, "expected integer expression");
10859 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10863 "expected %<,%> or %<)%>");
10865 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10866 OMP_CLAUSE_CHAIN (c
) = list
;
10870 c_parser_error (parser
, "invalid schedule kind");
10871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10876 shared ( variable-list ) */
10879 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10881 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10888 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10892 /* FIXME: Should we allow duplicates? */
10893 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10895 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10896 OMP_CLAUSE_UNTIED
);
10897 OMP_CLAUSE_CHAIN (c
) = list
;
10907 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10908 enum omp_clause_code code
, tree list
)
10910 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10912 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10913 OMP_CLAUSE_CHAIN (c
) = list
;
10925 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10926 enum omp_clause_code code
, tree list
)
10928 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10929 OMP_CLAUSE_CHAIN (c
) = list
;
10935 num_teams ( expression ) */
10938 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10940 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10941 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10943 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10944 tree c
, t
= c_parser_expression (parser
).value
;
10946 t
= c_fully_fold (t
, false, NULL
);
10948 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10950 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10952 c_parser_error (parser
, "expected integer expression");
10956 /* Attempt to statically determine when the number isn't positive. */
10957 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10958 build_int_cst (TREE_TYPE (t
), 0));
10959 if (CAN_HAVE_LOCATION_P (c
))
10960 SET_EXPR_LOCATION (c
, expr_loc
);
10961 if (c
== boolean_true_node
)
10963 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10964 t
= integer_one_node
;
10967 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10969 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10970 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10971 OMP_CLAUSE_CHAIN (c
) = list
;
10979 thread_limit ( expression ) */
10982 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10984 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10985 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10987 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10988 tree c
, t
= c_parser_expression (parser
).value
;
10990 t
= c_fully_fold (t
, false, NULL
);
10992 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10994 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10996 c_parser_error (parser
, "expected integer expression");
11000 /* Attempt to statically determine when the number isn't positive. */
11001 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11002 build_int_cst (TREE_TYPE (t
), 0));
11003 if (CAN_HAVE_LOCATION_P (c
))
11004 SET_EXPR_LOCATION (c
, expr_loc
);
11005 if (c
== boolean_true_node
)
11007 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
11008 t
= integer_one_node
;
11011 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
11014 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
11015 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
11016 OMP_CLAUSE_CHAIN (c
) = list
;
11024 aligned ( variable-list )
11025 aligned ( variable-list : constant-expression ) */
11028 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
11030 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11033 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11036 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11037 OMP_CLAUSE_ALIGNED
, list
);
11039 if (c_parser_next_token_is (parser
, CPP_COLON
))
11041 c_parser_consume_token (parser
);
11042 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
11043 mark_exp_read (alignment
);
11044 alignment
= c_fully_fold (alignment
, false, NULL
);
11045 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
11046 && TREE_CODE (alignment
) != INTEGER_CST
11047 && tree_int_cst_sgn (alignment
) != 1)
11049 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
11050 "be positive constant integer expression");
11051 alignment
= NULL_TREE
;
11054 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11055 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
11058 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11063 linear ( variable-list )
11064 linear ( variable-list : expression ) */
11067 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
11069 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11072 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11075 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11076 OMP_CLAUSE_LINEAR
, list
);
11078 if (c_parser_next_token_is (parser
, CPP_COLON
))
11080 c_parser_consume_token (parser
);
11081 step
= c_parser_expression (parser
).value
;
11082 mark_exp_read (step
);
11083 step
= c_fully_fold (step
, false, NULL
);
11084 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
11086 sorry ("using parameters for %<linear%> step is not supported yet");
11087 step
= integer_one_node
;
11089 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
11091 error_at (clause_loc
, "%<linear%> clause step expression must "
11093 step
= integer_one_node
;
11098 step
= integer_one_node
;
11100 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11102 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11105 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11110 safelen ( constant-expression ) */
11113 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
11115 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11118 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11121 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11123 t
= c_fully_fold (t
, false, NULL
);
11124 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11125 && TREE_CODE (t
) != INTEGER_CST
11126 && tree_int_cst_sgn (t
) != 1)
11128 error_at (clause_loc
, "%<safelen%> clause expression must "
11129 "be positive constant integer expression");
11133 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11134 if (t
== NULL_TREE
|| t
== error_mark_node
)
11137 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
11139 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
11140 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
11141 OMP_CLAUSE_CHAIN (c
) = list
;
11146 simdlen ( constant-expression ) */
11149 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
11151 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11154 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11157 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11159 t
= c_fully_fold (t
, false, NULL
);
11160 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
11161 && TREE_CODE (t
) != INTEGER_CST
11162 && tree_int_cst_sgn (t
) != 1)
11164 error_at (clause_loc
, "%<simdlen%> clause expression must "
11165 "be positive constant integer expression");
11169 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11170 if (t
== NULL_TREE
|| t
== error_mark_node
)
11173 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
11175 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
11176 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
11177 OMP_CLAUSE_CHAIN (c
) = list
;
11182 depend ( depend-kind: variable-list )
11185 in | out | inout */
11188 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
11190 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11191 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
11194 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11197 if (c_parser_next_token_is (parser
, CPP_NAME
))
11199 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11200 if (strcmp ("in", p
) == 0)
11201 kind
= OMP_CLAUSE_DEPEND_IN
;
11202 else if (strcmp ("inout", p
) == 0)
11203 kind
= OMP_CLAUSE_DEPEND_INOUT
;
11204 else if (strcmp ("out", p
) == 0)
11205 kind
= OMP_CLAUSE_DEPEND_OUT
;
11212 c_parser_consume_token (parser
);
11213 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11216 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
11217 OMP_CLAUSE_DEPEND
, list
);
11219 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11220 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
11222 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11226 c_parser_error (parser
, "invalid depend kind");
11228 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11233 map ( map-kind: variable-list )
11234 map ( variable-list )
11237 alloc | to | from | tofrom */
11240 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
11242 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11243 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
11246 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11249 if (c_parser_next_token_is (parser
, CPP_NAME
)
11250 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11252 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11253 if (strcmp ("alloc", p
) == 0)
11254 kind
= OMP_CLAUSE_MAP_ALLOC
;
11255 else if (strcmp ("to", p
) == 0)
11256 kind
= OMP_CLAUSE_MAP_TO
;
11257 else if (strcmp ("from", p
) == 0)
11258 kind
= OMP_CLAUSE_MAP_FROM
;
11259 else if (strcmp ("tofrom", p
) == 0)
11260 kind
= OMP_CLAUSE_MAP_TOFROM
;
11263 c_parser_error (parser
, "invalid map kind");
11264 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11268 c_parser_consume_token (parser
);
11269 c_parser_consume_token (parser
);
11272 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
11274 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11275 OMP_CLAUSE_MAP_KIND (c
) = kind
;
11277 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11282 device ( expression ) */
11285 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
11287 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11288 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11290 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11292 t
= c_fully_fold (t
, false, NULL
);
11294 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11296 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11298 c_parser_error (parser
, "expected integer expression");
11302 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
11304 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
11305 OMP_CLAUSE_DEVICE_ID (c
) = t
;
11306 OMP_CLAUSE_CHAIN (c
) = list
;
11314 dist_schedule ( static )
11315 dist_schedule ( static , expression ) */
11318 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
11320 tree c
, t
= NULL_TREE
;
11321 location_t loc
= c_parser_peek_token (parser
)->location
;
11323 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11326 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11328 c_parser_error (parser
, "invalid dist_schedule kind");
11329 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11334 c_parser_consume_token (parser
);
11335 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11337 c_parser_consume_token (parser
);
11339 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
11341 t
= c_fully_fold (t
, false, NULL
);
11342 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11345 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11346 "expected %<,%> or %<)%>");
11348 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
11349 if (t
== error_mark_node
)
11352 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
11353 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
11354 OMP_CLAUSE_CHAIN (c
) = list
;
11359 proc_bind ( proc-bind-kind )
11362 master | close | spread */
11365 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
11367 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11368 enum omp_clause_proc_bind_kind kind
;
11371 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11374 if (c_parser_next_token_is (parser
, CPP_NAME
))
11376 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11377 if (strcmp ("master", p
) == 0)
11378 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
11379 else if (strcmp ("close", p
) == 0)
11380 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
11381 else if (strcmp ("spread", p
) == 0)
11382 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
11389 c_parser_consume_token (parser
);
11390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11391 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
11392 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
11393 OMP_CLAUSE_CHAIN (c
) = list
;
11397 c_parser_error (parser
, "invalid proc_bind kind");
11398 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11403 to ( variable-list ) */
11406 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
11408 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
11412 from ( variable-list ) */
11415 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
11417 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
11421 uniform ( variable-list ) */
11424 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
11426 /* The clauses location. */
11427 location_t loc
= c_parser_peek_token (parser
)->location
;
11429 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11431 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
11433 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11438 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11439 is a bitmask in MASK. Return the list of clauses found; the result
11440 of clause default goes in *pdefault. */
11443 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11444 const char *where
, bool finish_p
= true)
11446 tree clauses
= NULL
;
11447 bool first
= true, cilk_simd_fn
= false;
11449 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11452 pragma_omp_clause c_kind
;
11453 const char *c_name
;
11454 tree prev
= clauses
;
11456 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11457 c_parser_consume_token (parser
);
11459 here
= c_parser_peek_token (parser
)->location
;
11460 c_kind
= c_parser_omp_clause_name (parser
);
11464 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11465 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11466 c_name
= "collapse";
11468 case PRAGMA_OMP_CLAUSE_COPYIN
:
11469 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11472 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11473 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11474 c_name
= "copyprivate";
11476 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11477 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11478 c_name
= "default";
11480 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11481 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11482 c_name
= "firstprivate";
11484 case PRAGMA_OMP_CLAUSE_FINAL
:
11485 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11488 case PRAGMA_OMP_CLAUSE_IF
:
11489 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11492 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11493 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11494 c_name
= "lastprivate";
11496 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11497 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11498 c_name
= "mergeable";
11500 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11501 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11504 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11505 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11506 c_name
= "num_threads";
11508 case PRAGMA_OMP_CLAUSE_ORDERED
:
11509 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11510 c_name
= "ordered";
11512 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11513 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11514 c_name
= "private";
11516 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11517 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11518 c_name
= "reduction";
11520 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11521 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11522 c_name
= "schedule";
11524 case PRAGMA_OMP_CLAUSE_SHARED
:
11525 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11528 case PRAGMA_OMP_CLAUSE_UNTIED
:
11529 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11532 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11533 case PRAGMA_CILK_CLAUSE_MASK
:
11534 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11536 c_name
= "inbranch";
11538 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11539 case PRAGMA_CILK_CLAUSE_NOMASK
:
11540 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11542 c_name
= "notinbranch";
11544 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11546 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11548 c_name
= "parallel";
11552 error_at (here
, "%qs must be the first clause of %qs",
11557 case PRAGMA_OMP_CLAUSE_FOR
:
11559 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11563 goto clause_not_first
;
11565 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11567 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11569 c_name
= "sections";
11571 goto clause_not_first
;
11573 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11575 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11577 c_name
= "taskgroup";
11579 goto clause_not_first
;
11581 case PRAGMA_OMP_CLAUSE_TO
:
11582 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11585 case PRAGMA_OMP_CLAUSE_FROM
:
11586 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11589 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11590 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11591 c_name
= "uniform";
11593 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11594 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11595 c_name
= "num_teams";
11597 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11598 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11599 c_name
= "thread_limit";
11601 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11602 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11603 c_name
= "aligned";
11605 case PRAGMA_OMP_CLAUSE_LINEAR
:
11606 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11607 cilk_simd_fn
= true;
11608 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11611 case PRAGMA_OMP_CLAUSE_DEPEND
:
11612 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11615 case PRAGMA_OMP_CLAUSE_MAP
:
11616 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11619 case PRAGMA_OMP_CLAUSE_DEVICE
:
11620 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11623 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11624 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11625 c_name
= "dist_schedule";
11627 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11628 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11629 c_name
= "proc_bind";
11631 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11632 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11633 c_name
= "safelen";
11635 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11636 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11637 c_name
= "simdlen";
11639 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11640 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11641 c_name
= "simdlen";
11644 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11650 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11652 /* Remove the invalid clause(s) from the list to avoid
11653 confusing the rest of the compiler. */
11655 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11660 c_parser_skip_to_pragma_eol (parser
);
11663 return c_finish_omp_clauses (clauses
);
11672 In practice, we're also interested in adding the statement to an
11673 outer node. So it is convenient if we work around the fact that
11674 c_parser_statement calls add_stmt. */
11677 c_parser_omp_structured_block (c_parser
*parser
)
11679 tree stmt
= push_stmt_list ();
11680 c_parser_statement (parser
);
11681 return pop_stmt_list (stmt
);
11685 # pragma omp atomic new-line
11689 x binop= expr | x++ | ++x | x-- | --x
11691 +, *, -, /, &, ^, |, <<, >>
11693 where x is an lvalue expression with scalar type.
11696 # pragma omp atomic new-line
11699 # pragma omp atomic read new-line
11702 # pragma omp atomic write new-line
11705 # pragma omp atomic update new-line
11708 # pragma omp atomic capture new-line
11711 # pragma omp atomic capture new-line
11719 expression-stmt | x = x binop expr
11721 v = expression-stmt
11723 { v = x; update-stmt; } | { update-stmt; v = x; }
11727 expression-stmt | x = x binop expr | x = expr binop x
11731 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11733 where x and v are lvalue expressions with scalar type.
11735 LOC is the location of the #pragma token. */
11738 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11740 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11741 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11742 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11743 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11744 struct c_expr expr
;
11746 bool structured_block
= false;
11747 bool swapped
= false;
11748 bool seq_cst
= false;
11750 if (c_parser_next_token_is (parser
, CPP_NAME
))
11752 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11754 if (!strcmp (p
, "read"))
11755 code
= OMP_ATOMIC_READ
;
11756 else if (!strcmp (p
, "write"))
11758 else if (!strcmp (p
, "update"))
11760 else if (!strcmp (p
, "capture"))
11761 code
= OMP_ATOMIC_CAPTURE_NEW
;
11765 c_parser_consume_token (parser
);
11767 if (c_parser_next_token_is (parser
, CPP_NAME
))
11769 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11770 if (!strcmp (p
, "seq_cst"))
11773 c_parser_consume_token (parser
);
11776 c_parser_skip_to_pragma_eol (parser
);
11780 case OMP_ATOMIC_READ
:
11781 case NOP_EXPR
: /* atomic write */
11782 v
= c_parser_unary_expression (parser
).value
;
11783 v
= c_fully_fold (v
, false, NULL
);
11784 if (v
== error_mark_node
)
11786 loc
= c_parser_peek_token (parser
)->location
;
11787 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11789 if (code
== NOP_EXPR
)
11790 lhs
= c_parser_expression (parser
).value
;
11792 lhs
= c_parser_unary_expression (parser
).value
;
11793 lhs
= c_fully_fold (lhs
, false, NULL
);
11794 if (lhs
== error_mark_node
)
11796 if (code
== NOP_EXPR
)
11798 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11806 case OMP_ATOMIC_CAPTURE_NEW
:
11807 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11809 c_parser_consume_token (parser
);
11810 structured_block
= true;
11814 v
= c_parser_unary_expression (parser
).value
;
11815 v
= c_fully_fold (v
, false, NULL
);
11816 if (v
== error_mark_node
)
11818 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11826 /* For structured_block case we don't know yet whether
11827 old or new x should be captured. */
11829 eloc
= c_parser_peek_token (parser
)->location
;
11830 expr
= c_parser_unary_expression (parser
);
11832 expr
= default_function_array_conversion (eloc
, expr
);
11833 unfolded_lhs
= expr
.value
;
11834 lhs
= c_fully_fold (lhs
, false, NULL
);
11836 switch (TREE_CODE (lhs
))
11840 c_parser_skip_to_end_of_block_or_statement (parser
);
11841 if (structured_block
)
11843 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11844 c_parser_consume_token (parser
);
11845 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11847 c_parser_skip_to_end_of_block_or_statement (parser
);
11848 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11849 c_parser_consume_token (parser
);
11854 case POSTINCREMENT_EXPR
:
11855 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11856 code
= OMP_ATOMIC_CAPTURE_OLD
;
11858 case PREINCREMENT_EXPR
:
11859 lhs
= TREE_OPERAND (lhs
, 0);
11860 unfolded_lhs
= NULL_TREE
;
11861 opcode
= PLUS_EXPR
;
11862 rhs
= integer_one_node
;
11865 case POSTDECREMENT_EXPR
:
11866 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11867 code
= OMP_ATOMIC_CAPTURE_OLD
;
11869 case PREDECREMENT_EXPR
:
11870 lhs
= TREE_OPERAND (lhs
, 0);
11871 unfolded_lhs
= NULL_TREE
;
11872 opcode
= MINUS_EXPR
;
11873 rhs
= integer_one_node
;
11876 case COMPOUND_EXPR
:
11877 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11878 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11879 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11880 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11881 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11882 (TREE_OPERAND (lhs
, 1), 0), 0)))
11884 /* Undo effects of boolean_increment for post {in,de}crement. */
11885 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11888 if (TREE_CODE (lhs
) == MODIFY_EXPR
11889 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11891 /* Undo effects of boolean_increment. */
11892 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11894 /* This is pre or post increment. */
11895 rhs
= TREE_OPERAND (lhs
, 1);
11896 lhs
= TREE_OPERAND (lhs
, 0);
11897 unfolded_lhs
= NULL_TREE
;
11899 if (code
== OMP_ATOMIC_CAPTURE_NEW
11900 && !structured_block
11901 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11902 code
= OMP_ATOMIC_CAPTURE_OLD
;
11905 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11906 && TREE_OPERAND (lhs
, 0)
11907 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11909 /* This is pre or post decrement. */
11910 rhs
= TREE_OPERAND (lhs
, 1);
11911 lhs
= TREE_OPERAND (lhs
, 0);
11912 unfolded_lhs
= NULL_TREE
;
11914 if (code
== OMP_ATOMIC_CAPTURE_NEW
11915 && !structured_block
11916 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11917 code
= OMP_ATOMIC_CAPTURE_OLD
;
11923 switch (c_parser_peek_token (parser
)->type
)
11926 opcode
= MULT_EXPR
;
11929 opcode
= TRUNC_DIV_EXPR
;
11932 opcode
= PLUS_EXPR
;
11935 opcode
= MINUS_EXPR
;
11937 case CPP_LSHIFT_EQ
:
11938 opcode
= LSHIFT_EXPR
;
11940 case CPP_RSHIFT_EQ
:
11941 opcode
= RSHIFT_EXPR
;
11944 opcode
= BIT_AND_EXPR
;
11947 opcode
= BIT_IOR_EXPR
;
11950 opcode
= BIT_XOR_EXPR
;
11953 c_parser_consume_token (parser
);
11954 eloc
= c_parser_peek_token (parser
)->location
;
11955 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11957 switch (TREE_CODE (rhs1
))
11960 case TRUNC_DIV_EXPR
:
11968 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11970 opcode
= TREE_CODE (rhs1
);
11971 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11972 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11975 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11977 opcode
= TREE_CODE (rhs1
);
11978 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11979 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11980 swapped
= !commutative_tree_code (opcode
);
11989 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11991 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11993 code
= OMP_ATOMIC_CAPTURE_OLD
;
11996 expr
= default_function_array_read_conversion (eloc
, expr
);
11997 unfolded_lhs1
= expr
.value
;
11998 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
12000 c_parser_consume_token (parser
);
12003 if (structured_block
)
12006 expr
= default_function_array_read_conversion (eloc
, expr
);
12007 rhs
= c_fully_fold (expr
.value
, false, NULL
);
12012 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
12015 c_parser_error (parser
,
12016 "invalid operator for %<#pragma omp atomic%>");
12020 /* Arrange to pass the location of the assignment operator to
12021 c_finish_omp_atomic. */
12022 loc
= c_parser_peek_token (parser
)->location
;
12023 c_parser_consume_token (parser
);
12024 eloc
= c_parser_peek_token (parser
)->location
;
12025 expr
= c_parser_expression (parser
);
12026 expr
= default_function_array_read_conversion (eloc
, expr
);
12028 rhs
= c_fully_fold (rhs
, false, NULL
);
12032 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
12034 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
12036 v
= c_parser_unary_expression (parser
).value
;
12037 v
= c_fully_fold (v
, false, NULL
);
12038 if (v
== error_mark_node
)
12040 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12042 eloc
= c_parser_peek_token (parser
)->location
;
12043 expr
= c_parser_unary_expression (parser
);
12045 expr
= default_function_array_read_conversion (eloc
, expr
);
12046 unfolded_lhs1
= expr
.value
;
12047 lhs1
= c_fully_fold (lhs1
, false, NULL
);
12048 if (lhs1
== error_mark_node
)
12051 if (structured_block
)
12053 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12054 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
12057 if (unfolded_lhs
&& unfolded_lhs1
12058 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
12060 error ("%<#pragma omp atomic capture%> uses two different "
12061 "expressions for memory");
12062 stmt
= error_mark_node
;
12065 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
12067 if (stmt
!= error_mark_node
)
12070 if (!structured_block
)
12071 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12076 # pragma omp barrier new-line
12080 c_parser_omp_barrier (c_parser
*parser
)
12082 location_t loc
= c_parser_peek_token (parser
)->location
;
12083 c_parser_consume_pragma (parser
);
12084 c_parser_skip_to_pragma_eol (parser
);
12086 c_finish_omp_barrier (loc
);
12090 # pragma omp critical [(name)] new-line
12093 LOC is the location of the #pragma itself. */
12096 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
12098 tree stmt
, name
= NULL
;
12100 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12102 c_parser_consume_token (parser
);
12103 if (c_parser_next_token_is (parser
, CPP_NAME
))
12105 name
= c_parser_peek_token (parser
)->value
;
12106 c_parser_consume_token (parser
);
12107 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12110 c_parser_error (parser
, "expected identifier");
12112 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12113 c_parser_error (parser
, "expected %<(%> or end of line");
12114 c_parser_skip_to_pragma_eol (parser
);
12116 stmt
= c_parser_omp_structured_block (parser
);
12117 return c_finish_omp_critical (loc
, stmt
, name
);
12121 # pragma omp flush flush-vars[opt] new-line
12124 ( variable-list ) */
12127 c_parser_omp_flush (c_parser
*parser
)
12129 location_t loc
= c_parser_peek_token (parser
)->location
;
12130 c_parser_consume_pragma (parser
);
12131 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12132 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12133 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12134 c_parser_error (parser
, "expected %<(%> or end of line");
12135 c_parser_skip_to_pragma_eol (parser
);
12137 c_finish_omp_flush (loc
);
12140 /* Parse the restricted form of the for statement allowed by OpenMP.
12141 The real trick here is to determine the loop control variable early
12142 so that we can push a new decl if necessary to make it private.
12143 LOC is the location of the OMP in "#pragma omp". */
12146 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
12147 tree clauses
, tree
*cclauses
)
12149 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
12150 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
12151 bool fail
= false, open_brace_parsed
= false;
12152 int i
, collapse
= 1, nbraces
= 0;
12153 location_t for_loc
;
12154 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
12156 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
12157 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
12158 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
12160 gcc_assert (collapse
>= 1);
12162 declv
= make_tree_vec (collapse
);
12163 initv
= make_tree_vec (collapse
);
12164 condv
= make_tree_vec (collapse
);
12165 incrv
= make_tree_vec (collapse
);
12167 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
12169 c_parser_error (parser
, "for statement expected");
12172 for_loc
= c_parser_peek_token (parser
)->location
;
12173 c_parser_consume_token (parser
);
12175 for (i
= 0; i
< collapse
; i
++)
12177 int bracecount
= 0;
12179 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12182 /* Parse the initialization declaration or expression. */
12183 if (c_parser_next_tokens_start_declaration (parser
))
12186 vec_safe_push (for_block
, c_begin_compound_stmt (true));
12187 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12189 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
12192 if (DECL_INITIAL (decl
) == error_mark_node
)
12193 decl
= error_mark_node
;
12196 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12197 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
12199 struct c_expr decl_exp
;
12200 struct c_expr init_exp
;
12201 location_t init_loc
;
12203 decl_exp
= c_parser_postfix_expression (parser
);
12204 decl
= decl_exp
.value
;
12206 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
12208 init_loc
= c_parser_peek_token (parser
)->location
;
12209 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
12210 init_exp
= default_function_array_read_conversion (init_loc
,
12212 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
12213 NOP_EXPR
, init_loc
, init_exp
.value
,
12214 init_exp
.original_type
);
12215 init
= c_process_expr_stmt (init_loc
, init
);
12217 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12222 c_parser_error (parser
,
12223 "expected iteration declaration or initialization");
12224 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12230 /* Parse the loop condition. */
12232 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
12234 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
12235 struct c_expr cond_expr
12236 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
12238 cond
= cond_expr
.value
;
12239 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
12240 cond
= c_fully_fold (cond
, false, NULL
);
12241 switch (cond_expr
.original_code
)
12249 if (code
== CILK_SIMD
)
12253 /* Can't be cond = error_mark_node, because we want to preserve
12254 the location until c_finish_omp_for. */
12255 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
12258 protected_set_expr_location (cond
, cond_loc
);
12260 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
12262 /* Parse the increment expression. */
12264 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
12266 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
12268 incr
= c_process_expr_stmt (incr_loc
,
12269 c_parser_expression (parser
).value
);
12271 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12273 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
12277 TREE_VEC_ELT (declv
, i
) = decl
;
12278 TREE_VEC_ELT (initv
, i
) = init
;
12279 TREE_VEC_ELT (condv
, i
) = cond
;
12280 TREE_VEC_ELT (incrv
, i
) = incr
;
12284 if (i
== collapse
- 1)
12287 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
12288 in between the collapsed for loops to be still considered perfectly
12289 nested. Hopefully the final version clarifies this.
12290 For now handle (multiple) {'s and empty statements. */
12293 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12295 c_parser_consume_token (parser
);
12298 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
12300 c_parser_consume_token (parser
);
12303 else if (bracecount
12304 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12305 c_parser_consume_token (parser
);
12308 c_parser_error (parser
, "not enough perfectly nested loops");
12311 open_brace_parsed
= true;
12321 nbraces
+= bracecount
;
12324 save_break
= c_break_label
;
12325 if (code
== CILK_SIMD
)
12326 c_break_label
= build_int_cst (size_type_node
, 2);
12328 c_break_label
= size_one_node
;
12329 save_cont
= c_cont_label
;
12330 c_cont_label
= NULL_TREE
;
12331 body
= push_stmt_list ();
12333 if (open_brace_parsed
)
12335 location_t here
= c_parser_peek_token (parser
)->location
;
12336 stmt
= c_begin_compound_stmt (true);
12337 c_parser_compound_statement_nostart (parser
);
12338 add_stmt (c_end_compound_stmt (here
, stmt
, true));
12341 add_stmt (c_parser_c99_block_statement (parser
));
12344 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
12345 SET_EXPR_LOCATION (t
, loc
);
12349 body
= pop_stmt_list (body
);
12350 c_break_label
= save_break
;
12351 c_cont_label
= save_cont
;
12355 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12357 c_parser_consume_token (parser
);
12360 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
12361 c_parser_consume_token (parser
);
12364 c_parser_error (parser
, "collapsed loops not perfectly nested");
12367 location_t here
= c_parser_peek_token (parser
)->location
;
12368 stmt
= c_begin_compound_stmt (true);
12370 c_parser_compound_statement_nostart (parser
);
12371 body
= c_end_compound_stmt (here
, stmt
, true);
12378 /* Only bother calling c_finish_omp_for if we haven't already generated
12379 an error from the initialization parsing. */
12382 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
12383 incrv
, body
, NULL
);
12386 if (cclauses
!= NULL
12387 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
12390 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
12391 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
12392 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
12393 c
= &OMP_CLAUSE_CHAIN (*c
);
12396 for (i
= 0; i
< collapse
; i
++)
12397 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
12400 c
= &OMP_CLAUSE_CHAIN (*c
);
12401 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
12404 "iteration variable %qD should not be firstprivate",
12405 OMP_CLAUSE_DECL (*c
));
12406 *c
= OMP_CLAUSE_CHAIN (*c
);
12410 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
12411 change it to shared (decl) in
12412 OMP_PARALLEL_CLAUSES. */
12413 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
12414 OMP_CLAUSE_LASTPRIVATE
);
12415 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
12416 OMP_CLAUSE_CHAIN (l
) = clauses
;
12418 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
12422 OMP_FOR_CLAUSES (stmt
) = clauses
;
12427 while (!for_block
->is_empty ())
12429 /* FIXME diagnostics: LOC below should be the actual location of
12430 this particular for block. We need to build a list of
12431 locations to go along with FOR_BLOCK. */
12432 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
12435 release_tree_vector (for_block
);
12439 /* Helper function for OpenMP parsing, split clauses and call
12440 finish_omp_clauses on each of the set of clauses afterwards. */
12443 omp_split_clauses (location_t loc
, enum tree_code code
,
12444 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
12447 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
12448 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
12450 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
12454 #pragma omp simd simd-clause[optseq] new-line
12457 LOC is the location of the #pragma token.
12460 #define OMP_SIMD_CLAUSE_MASK \
12461 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
12462 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12463 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12464 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12465 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12466 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12467 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12470 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
12471 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12473 tree block
, clauses
, ret
;
12475 strcat (p_name
, " simd");
12476 mask
|= OMP_SIMD_CLAUSE_MASK
;
12477 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
12479 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12482 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
12483 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
12486 block
= c_begin_compound_stmt (true);
12487 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
12488 block
= c_end_compound_stmt (loc
, block
, true);
12495 #pragma omp for for-clause[optseq] new-line
12499 #pragma omp for simd for-simd-clause[optseq] new-line
12502 LOC is the location of the #pragma token.
12505 #define OMP_FOR_CLAUSE_MASK \
12506 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12507 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12508 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12509 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12510 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12511 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12512 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12513 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12516 c_parser_omp_for (location_t loc
, c_parser
*parser
,
12517 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12519 tree block
, clauses
, ret
;
12521 strcat (p_name
, " for");
12522 mask
|= OMP_FOR_CLAUSE_MASK
;
12524 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12526 if (c_parser_next_token_is (parser
, CPP_NAME
))
12528 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12530 if (strcmp (p
, "simd") == 0)
12532 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12533 if (cclauses
== NULL
)
12534 cclauses
= cclauses_buf
;
12536 c_parser_consume_token (parser
);
12537 if (!flag_openmp
) /* flag_openmp_simd */
12538 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12539 block
= c_begin_compound_stmt (true);
12540 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12541 block
= c_end_compound_stmt (loc
, block
, true);
12542 if (ret
== NULL_TREE
)
12544 ret
= make_node (OMP_FOR
);
12545 TREE_TYPE (ret
) = void_type_node
;
12546 OMP_FOR_BODY (ret
) = block
;
12547 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12548 SET_EXPR_LOCATION (ret
, loc
);
12553 if (!flag_openmp
) /* flag_openmp_simd */
12555 c_parser_skip_to_pragma_eol (parser
);
12559 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12562 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12563 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12566 block
= c_begin_compound_stmt (true);
12567 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12568 block
= c_end_compound_stmt (loc
, block
, true);
12575 # pragma omp master new-line
12578 LOC is the location of the #pragma token.
12582 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12584 c_parser_skip_to_pragma_eol (parser
);
12585 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12589 # pragma omp ordered new-line
12592 LOC is the location of the #pragma itself.
12596 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12598 c_parser_skip_to_pragma_eol (parser
);
12599 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12605 { section-sequence }
12608 section-directive[opt] structured-block
12609 section-sequence section-directive structured-block
12611 SECTIONS_LOC is the location of the #pragma omp sections. */
12614 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12616 tree stmt
, substmt
;
12617 bool error_suppress
= false;
12620 loc
= c_parser_peek_token (parser
)->location
;
12621 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12623 /* Avoid skipping until the end of the block. */
12624 parser
->error
= false;
12628 stmt
= push_stmt_list ();
12630 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12632 substmt
= c_parser_omp_structured_block (parser
);
12633 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12634 SET_EXPR_LOCATION (substmt
, loc
);
12635 add_stmt (substmt
);
12640 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12642 if (c_parser_next_token_is (parser
, CPP_EOF
))
12645 loc
= c_parser_peek_token (parser
)->location
;
12646 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12648 c_parser_consume_pragma (parser
);
12649 c_parser_skip_to_pragma_eol (parser
);
12650 error_suppress
= false;
12652 else if (!error_suppress
)
12654 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12655 error_suppress
= true;
12658 substmt
= c_parser_omp_structured_block (parser
);
12659 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12660 SET_EXPR_LOCATION (substmt
, loc
);
12661 add_stmt (substmt
);
12663 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12664 "expected %<#pragma omp section%> or %<}%>");
12666 substmt
= pop_stmt_list (stmt
);
12668 stmt
= make_node (OMP_SECTIONS
);
12669 SET_EXPR_LOCATION (stmt
, sections_loc
);
12670 TREE_TYPE (stmt
) = void_type_node
;
12671 OMP_SECTIONS_BODY (stmt
) = substmt
;
12673 return add_stmt (stmt
);
12677 # pragma omp sections sections-clause[optseq] newline
12680 LOC is the location of the #pragma token.
12683 #define OMP_SECTIONS_CLAUSE_MASK \
12684 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12685 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12686 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12687 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12688 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12691 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12692 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12694 tree block
, clauses
, ret
;
12696 strcat (p_name
, " sections");
12697 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12699 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12701 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12704 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12705 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12708 block
= c_begin_compound_stmt (true);
12709 ret
= c_parser_omp_sections_scope (loc
, parser
);
12711 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12712 block
= c_end_compound_stmt (loc
, block
, true);
12719 # pragma omp parallel parallel-clause[optseq] new-line
12721 # pragma omp parallel for parallel-for-clause[optseq] new-line
12723 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12727 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12730 LOC is the location of the #pragma token.
12733 #define OMP_PARALLEL_CLAUSE_MASK \
12734 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12741 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12745 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12746 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12748 tree stmt
, clauses
, block
;
12750 strcat (p_name
, " parallel");
12751 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12753 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12755 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12756 if (cclauses
== NULL
)
12757 cclauses
= cclauses_buf
;
12759 c_parser_consume_token (parser
);
12760 if (!flag_openmp
) /* flag_openmp_simd */
12761 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12762 block
= c_begin_omp_parallel ();
12763 c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12765 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12767 OMP_PARALLEL_COMBINED (stmt
) = 1;
12772 error_at (loc
, "expected %<for%> after %qs", p_name
);
12773 c_parser_skip_to_pragma_eol (parser
);
12776 else if (!flag_openmp
) /* flag_openmp_simd */
12778 c_parser_skip_to_pragma_eol (parser
);
12781 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12783 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12784 if (strcmp (p
, "sections") == 0)
12786 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12787 if (cclauses
== NULL
)
12788 cclauses
= cclauses_buf
;
12790 c_parser_consume_token (parser
);
12791 block
= c_begin_omp_parallel ();
12792 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12793 stmt
= c_finish_omp_parallel (loc
,
12794 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12796 OMP_PARALLEL_COMBINED (stmt
) = 1;
12801 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12803 block
= c_begin_omp_parallel ();
12804 c_parser_statement (parser
);
12805 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12811 # pragma omp single single-clause[optseq] new-line
12814 LOC is the location of the #pragma.
12817 #define OMP_SINGLE_CLAUSE_MASK \
12818 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12819 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12820 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12821 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12824 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12826 tree stmt
= make_node (OMP_SINGLE
);
12827 SET_EXPR_LOCATION (stmt
, loc
);
12828 TREE_TYPE (stmt
) = void_type_node
;
12830 OMP_SINGLE_CLAUSES (stmt
)
12831 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12832 "#pragma omp single");
12833 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12835 return add_stmt (stmt
);
12839 # pragma omp task task-clause[optseq] new-line
12841 LOC is the location of the #pragma.
12844 #define OMP_TASK_CLAUSE_MASK \
12845 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12846 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12847 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12848 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12849 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12850 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12851 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12852 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12853 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12856 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12858 tree clauses
, block
;
12860 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12861 "#pragma omp task");
12863 block
= c_begin_omp_task ();
12864 c_parser_statement (parser
);
12865 return c_finish_omp_task (loc
, clauses
, block
);
12869 # pragma omp taskwait new-line
12873 c_parser_omp_taskwait (c_parser
*parser
)
12875 location_t loc
= c_parser_peek_token (parser
)->location
;
12876 c_parser_consume_pragma (parser
);
12877 c_parser_skip_to_pragma_eol (parser
);
12879 c_finish_omp_taskwait (loc
);
12883 # pragma omp taskyield new-line
12887 c_parser_omp_taskyield (c_parser
*parser
)
12889 location_t loc
= c_parser_peek_token (parser
)->location
;
12890 c_parser_consume_pragma (parser
);
12891 c_parser_skip_to_pragma_eol (parser
);
12893 c_finish_omp_taskyield (loc
);
12897 # pragma omp taskgroup new-line
12901 c_parser_omp_taskgroup (c_parser
*parser
)
12903 location_t loc
= c_parser_peek_token (parser
)->location
;
12904 c_parser_skip_to_pragma_eol (parser
);
12905 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12909 # pragma omp cancel cancel-clause[optseq] new-line
12911 LOC is the location of the #pragma.
12914 #define OMP_CANCEL_CLAUSE_MASK \
12915 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12916 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12917 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12918 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12919 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12922 c_parser_omp_cancel (c_parser
*parser
)
12924 location_t loc
= c_parser_peek_token (parser
)->location
;
12926 c_parser_consume_pragma (parser
);
12927 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12928 "#pragma omp cancel");
12930 c_finish_omp_cancel (loc
, clauses
);
12934 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12936 LOC is the location of the #pragma.
12939 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12940 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12942 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12946 c_parser_omp_cancellation_point (c_parser
*parser
)
12948 location_t loc
= c_parser_peek_token (parser
)->location
;
12950 bool point_seen
= false;
12952 c_parser_consume_pragma (parser
);
12953 if (c_parser_next_token_is (parser
, CPP_NAME
))
12955 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12956 if (strcmp (p
, "point") == 0)
12958 c_parser_consume_token (parser
);
12964 c_parser_error (parser
, "expected %<point%>");
12965 c_parser_skip_to_pragma_eol (parser
);
12970 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12971 "#pragma omp cancellation point");
12973 c_finish_omp_cancellation_point (loc
, clauses
);
12977 #pragma omp distribute distribute-clause[optseq] new-line
12980 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12981 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12982 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12983 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12984 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12987 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12988 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12990 tree clauses
, block
, ret
;
12992 strcat (p_name
, " distribute");
12993 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12995 if (c_parser_next_token_is (parser
, CPP_NAME
))
12997 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12999 bool parallel
= false;
13001 if (strcmp (p
, "simd") == 0)
13004 parallel
= strcmp (p
, "parallel") == 0;
13005 if (parallel
|| simd
)
13007 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13008 if (cclauses
== NULL
)
13009 cclauses
= cclauses_buf
;
13010 c_parser_consume_token (parser
);
13011 if (!flag_openmp
) /* flag_openmp_simd */
13014 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13016 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
13019 block
= c_begin_compound_stmt (true);
13021 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
13023 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
13024 block
= c_end_compound_stmt (loc
, block
, true);
13027 ret
= make_node (OMP_DISTRIBUTE
);
13028 TREE_TYPE (ret
) = void_type_node
;
13029 OMP_FOR_BODY (ret
) = block
;
13030 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13031 SET_EXPR_LOCATION (ret
, loc
);
13036 if (!flag_openmp
) /* flag_openmp_simd */
13038 c_parser_skip_to_pragma_eol (parser
);
13042 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13045 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
13046 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
13049 block
= c_begin_compound_stmt (true);
13050 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
13051 block
= c_end_compound_stmt (loc
, block
, true);
13058 # pragma omp teams teams-clause[optseq] new-line
13059 structured-block */
13061 #define OMP_TEAMS_CLAUSE_MASK \
13062 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
13063 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
13064 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
13065 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
13066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
13067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
13068 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
13071 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
13072 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
13074 tree clauses
, block
, ret
;
13076 strcat (p_name
, " teams");
13077 mask
|= OMP_TEAMS_CLAUSE_MASK
;
13079 if (c_parser_next_token_is (parser
, CPP_NAME
))
13081 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13082 if (strcmp (p
, "distribute") == 0)
13084 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
13085 if (cclauses
== NULL
)
13086 cclauses
= cclauses_buf
;
13088 c_parser_consume_token (parser
);
13089 if (!flag_openmp
) /* flag_openmp_simd */
13090 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13091 block
= c_begin_compound_stmt (true);
13092 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
13093 block
= c_end_compound_stmt (loc
, block
, true);
13096 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13097 ret
= make_node (OMP_TEAMS
);
13098 TREE_TYPE (ret
) = void_type_node
;
13099 OMP_TEAMS_CLAUSES (ret
) = clauses
;
13100 OMP_TEAMS_BODY (ret
) = block
;
13101 return add_stmt (ret
);
13104 if (!flag_openmp
) /* flag_openmp_simd */
13106 c_parser_skip_to_pragma_eol (parser
);
13110 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
13113 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
13114 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
13117 tree stmt
= make_node (OMP_TEAMS
);
13118 TREE_TYPE (stmt
) = void_type_node
;
13119 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
13120 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
13122 return add_stmt (stmt
);
13126 # pragma omp target data target-data-clause[optseq] new-line
13127 structured-block */
13129 #define OMP_TARGET_DATA_CLAUSE_MASK \
13130 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13131 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13132 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13135 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
13137 tree stmt
= make_node (OMP_TARGET_DATA
);
13138 TREE_TYPE (stmt
) = void_type_node
;
13140 OMP_TARGET_DATA_CLAUSES (stmt
)
13141 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
13142 "#pragma omp target data");
13143 keep_next_level ();
13144 tree block
= c_begin_compound_stmt (true);
13145 add_stmt (c_parser_omp_structured_block (parser
));
13146 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13148 SET_EXPR_LOCATION (stmt
, loc
);
13149 return add_stmt (stmt
);
13153 # pragma omp target update target-update-clause[optseq] new-line */
13155 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
13156 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
13157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
13158 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13159 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13162 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
13163 enum pragma_context context
)
13165 if (context
== pragma_stmt
)
13168 "%<#pragma omp target update%> may only be "
13169 "used in compound statements");
13170 c_parser_skip_to_pragma_eol (parser
);
13175 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
13176 "#pragma omp target update");
13177 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
13178 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
13181 "%<#pragma omp target update must contain at least one "
13182 "%<from%> or %<to%> clauses");
13186 tree stmt
= make_node (OMP_TARGET_UPDATE
);
13187 TREE_TYPE (stmt
) = void_type_node
;
13188 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
13189 SET_EXPR_LOCATION (stmt
, loc
);
13195 # pragma omp target target-clause[optseq] new-line
13196 structured-block */
13198 #define OMP_TARGET_CLAUSE_MASK \
13199 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
13200 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
13201 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
13204 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
13206 location_t loc
= c_parser_peek_token (parser
)->location
;
13207 c_parser_consume_pragma (parser
);
13209 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
13211 c_parser_error (parser
, "expected declaration specifiers");
13212 c_parser_skip_to_pragma_eol (parser
);
13216 if (c_parser_next_token_is (parser
, CPP_NAME
))
13218 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13220 if (strcmp (p
, "teams") == 0)
13222 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
13223 char p_name
[sizeof ("#pragma omp target teams distribute "
13224 "parallel for simd")];
13226 c_parser_consume_token (parser
);
13227 strcpy (p_name
, "#pragma omp target");
13228 if (!flag_openmp
) /* flag_openmp_simd */
13229 return c_parser_omp_teams (loc
, parser
, p_name
,
13230 OMP_TARGET_CLAUSE_MASK
, cclauses
);
13231 keep_next_level ();
13232 tree block
= c_begin_compound_stmt (true);
13233 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
13234 OMP_TARGET_CLAUSE_MASK
, cclauses
);
13235 block
= c_end_compound_stmt (loc
, block
, true);
13238 tree stmt
= make_node (OMP_TARGET
);
13239 TREE_TYPE (stmt
) = void_type_node
;
13240 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
13241 OMP_TARGET_BODY (stmt
) = block
;
13245 else if (!flag_openmp
) /* flag_openmp_simd */
13247 c_parser_skip_to_pragma_eol (parser
);
13250 else if (strcmp (p
, "data") == 0)
13252 c_parser_consume_token (parser
);
13253 c_parser_omp_target_data (loc
, parser
);
13256 else if (strcmp (p
, "update") == 0)
13258 c_parser_consume_token (parser
);
13259 return c_parser_omp_target_update (loc
, parser
, context
);
13263 tree stmt
= make_node (OMP_TARGET
);
13264 TREE_TYPE (stmt
) = void_type_node
;
13266 OMP_TARGET_CLAUSES (stmt
)
13267 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
13268 "#pragma omp target");
13269 keep_next_level ();
13270 tree block
= c_begin_compound_stmt (true);
13271 add_stmt (c_parser_omp_structured_block (parser
));
13272 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
13274 SET_EXPR_LOCATION (stmt
, loc
);
13280 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
13282 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
13283 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
13284 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
13285 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
13286 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
13287 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
13288 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
13291 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
13293 vec
<c_token
> clauses
= vNULL
;
13294 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13296 c_token
*token
= c_parser_peek_token (parser
);
13297 if (token
->type
== CPP_EOF
)
13299 c_parser_skip_to_pragma_eol (parser
);
13300 clauses
.release ();
13303 clauses
.safe_push (*token
);
13304 c_parser_consume_token (parser
);
13306 clauses
.safe_push (*c_parser_peek_token (parser
));
13307 c_parser_skip_to_pragma_eol (parser
);
13309 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
13311 if (c_parser_peek_token (parser
)->pragma_kind
13312 != PRAGMA_OMP_DECLARE_REDUCTION
13313 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
13314 || strcmp (IDENTIFIER_POINTER
13315 (c_parser_peek_2nd_token (parser
)->value
),
13318 c_parser_error (parser
,
13319 "%<#pragma omp declare simd%> must be followed by "
13320 "function declaration or definition or another "
13321 "%<#pragma omp declare simd%>");
13322 clauses
.release ();
13325 c_parser_consume_pragma (parser
);
13326 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13328 c_token
*token
= c_parser_peek_token (parser
);
13329 if (token
->type
== CPP_EOF
)
13331 c_parser_skip_to_pragma_eol (parser
);
13332 clauses
.release ();
13335 clauses
.safe_push (*token
);
13336 c_parser_consume_token (parser
);
13338 clauses
.safe_push (*c_parser_peek_token (parser
));
13339 c_parser_skip_to_pragma_eol (parser
);
13342 /* Make sure nothing tries to read past the end of the tokens. */
13344 memset (&eof_token
, 0, sizeof (eof_token
));
13345 eof_token
.type
= CPP_EOF
;
13346 clauses
.safe_push (eof_token
);
13347 clauses
.safe_push (eof_token
);
13351 case pragma_external
:
13352 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13353 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
13355 int ext
= disable_extension_diagnostics ();
13357 c_parser_consume_token (parser
);
13358 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13359 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
13360 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13362 restore_extension_diagnostics (ext
);
13365 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13368 case pragma_struct
:
13370 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13371 "function declaration or definition");
13373 case pragma_compound
:
13375 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13376 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
13378 int ext
= disable_extension_diagnostics ();
13380 c_parser_consume_token (parser
);
13381 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13382 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
13383 if (c_parser_next_tokens_start_declaration (parser
))
13385 c_parser_declaration_or_fndef (parser
, true, true, true, true,
13386 true, NULL
, clauses
);
13387 restore_extension_diagnostics (ext
);
13390 restore_extension_diagnostics (ext
);
13392 else if (c_parser_next_tokens_start_declaration (parser
))
13394 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
13398 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13399 "function declaration or definition");
13402 gcc_unreachable ();
13404 clauses
.release ();
13407 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
13408 and put that into "omp declare simd" attribute. */
13411 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
13412 vec
<c_token
> clauses
)
13415 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13417 error ("%<#pragma omp declare simd%> cannot be used in the same "
13418 "function marked as a Cilk Plus SIMD-enabled function");
13419 vec_free (parser
->cilk_simd_fn_tokens
);
13423 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
13424 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
13425 has already processed the tokens. */
13426 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
13428 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
13430 error ("%<#pragma omp declare simd%> not immediately followed by "
13431 "a function declaration or definition");
13432 clauses
[0].type
= CPP_EOF
;
13435 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
13437 error_at (DECL_SOURCE_LOCATION (fndecl
),
13438 "%<#pragma omp declare simd%> not immediately followed by "
13439 "a single function declaration or definition");
13440 clauses
[0].type
= CPP_EOF
;
13444 if (parms
== NULL_TREE
)
13445 parms
= DECL_ARGUMENTS (fndecl
);
13447 unsigned int tokens_avail
= parser
->tokens_avail
;
13448 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13449 bool is_cilkplus_cilk_simd_fn
= false;
13451 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13453 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
13454 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
13455 is_cilkplus_cilk_simd_fn
= true;
13459 parser
->tokens
= clauses
.address ();
13460 parser
->tokens_avail
= clauses
.length ();
13463 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
13464 while (parser
->tokens_avail
> 3)
13466 c_token
*token
= c_parser_peek_token (parser
);
13467 if (!is_cilkplus_cilk_simd_fn
)
13468 gcc_assert (token
->type
== CPP_NAME
13469 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
13471 gcc_assert (token
->type
== CPP_NAME
13472 && is_cilkplus_vector_p (token
->value
));
13473 c_parser_consume_token (parser
);
13474 parser
->in_pragma
= true;
13476 tree c
= NULL_TREE
;
13477 if (is_cilkplus_cilk_simd_fn
)
13478 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
13479 "SIMD-enabled functions attribute");
13481 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
13482 "#pragma omp declare simd");
13483 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
13484 if (c
!= NULL_TREE
)
13485 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
13486 if (is_cilkplus_cilk_simd_fn
)
13488 tree k
= build_tree_list (get_identifier ("cilk simd function"),
13490 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
13491 DECL_ATTRIBUTES (fndecl
) = k
;
13493 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
13494 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
13495 DECL_ATTRIBUTES (fndecl
) = c
;
13498 parser
->tokens
= &parser
->tokens_buf
[0];
13499 parser
->tokens_avail
= tokens_avail
;
13500 if (clauses
.exists ())
13501 clauses
[0].type
= CPP_PRAGMA
;
13503 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13504 vec_free (parser
->cilk_simd_fn_tokens
);
13509 # pragma omp declare target new-line
13510 declarations and definitions
13511 # pragma omp end declare target new-line */
13514 c_parser_omp_declare_target (c_parser
*parser
)
13516 c_parser_skip_to_pragma_eol (parser
);
13517 current_omp_declare_target_attribute
++;
13521 c_parser_omp_end_declare_target (c_parser
*parser
)
13523 location_t loc
= c_parser_peek_token (parser
)->location
;
13524 c_parser_consume_pragma (parser
);
13525 if (c_parser_next_token_is (parser
, CPP_NAME
)
13526 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13529 c_parser_consume_token (parser
);
13530 if (c_parser_next_token_is (parser
, CPP_NAME
)
13531 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13533 c_parser_consume_token (parser
);
13536 c_parser_error (parser
, "expected %<target%>");
13537 c_parser_skip_to_pragma_eol (parser
);
13543 c_parser_error (parser
, "expected %<declare%>");
13544 c_parser_skip_to_pragma_eol (parser
);
13547 c_parser_skip_to_pragma_eol (parser
);
13548 if (!current_omp_declare_target_attribute
)
13549 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13550 "%<#pragma omp declare target%>");
13552 current_omp_declare_target_attribute
--;
13557 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13558 initializer-clause[opt] new-line
13560 initializer-clause:
13561 initializer (omp_priv = initializer)
13562 initializer (function-name (argument-list)) */
13565 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13567 unsigned int tokens_avail
= 0, i
;
13568 vec
<tree
> types
= vNULL
;
13569 vec
<c_token
> clauses
= vNULL
;
13570 enum tree_code reduc_code
= ERROR_MARK
;
13571 tree reduc_id
= NULL_TREE
;
13573 location_t rloc
= c_parser_peek_token (parser
)->location
;
13575 if (context
== pragma_struct
|| context
== pragma_param
)
13577 error ("%<#pragma omp declare reduction%> not at file or block scope");
13581 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13584 switch (c_parser_peek_token (parser
)->type
)
13587 reduc_code
= PLUS_EXPR
;
13590 reduc_code
= MULT_EXPR
;
13593 reduc_code
= MINUS_EXPR
;
13596 reduc_code
= BIT_AND_EXPR
;
13599 reduc_code
= BIT_XOR_EXPR
;
13602 reduc_code
= BIT_IOR_EXPR
;
13605 reduc_code
= TRUTH_ANDIF_EXPR
;
13608 reduc_code
= TRUTH_ORIF_EXPR
;
13612 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13613 if (strcmp (p
, "min") == 0)
13615 reduc_code
= MIN_EXPR
;
13618 if (strcmp (p
, "max") == 0)
13620 reduc_code
= MAX_EXPR
;
13623 reduc_id
= c_parser_peek_token (parser
)->value
;
13626 c_parser_error (parser
,
13627 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13628 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13632 tree orig_reduc_id
, reduc_decl
;
13633 orig_reduc_id
= reduc_id
;
13634 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13635 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13636 c_parser_consume_token (parser
);
13638 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13643 location_t loc
= c_parser_peek_token (parser
)->location
;
13644 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13647 type
= groktypename (ctype
, NULL
, NULL
);
13648 if (type
== error_mark_node
)
13650 else if ((INTEGRAL_TYPE_P (type
)
13651 || TREE_CODE (type
) == REAL_TYPE
13652 || TREE_CODE (type
) == COMPLEX_TYPE
)
13653 && orig_reduc_id
== NULL_TREE
)
13654 error_at (loc
, "predeclared arithmetic type in "
13655 "%<#pragma omp declare reduction%>");
13656 else if (TREE_CODE (type
) == FUNCTION_TYPE
13657 || TREE_CODE (type
) == ARRAY_TYPE
)
13658 error_at (loc
, "function or array type in "
13659 "%<#pragma omp declare reduction%>");
13660 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13661 error_at (loc
, "const, volatile or restrict qualified type in "
13662 "%<#pragma omp declare reduction%>");
13666 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13667 if (comptypes (TREE_PURPOSE (t
), type
))
13669 error_at (loc
, "redeclaration of %qs "
13670 "%<#pragma omp declare reduction%> for "
13672 IDENTIFIER_POINTER (reduc_id
)
13673 + sizeof ("omp declare reduction ") - 1,
13676 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13678 error_at (ploc
, "previous %<#pragma omp declare "
13682 if (t
== NULL_TREE
)
13683 types
.safe_push (type
);
13685 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13686 c_parser_consume_token (parser
);
13694 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13695 || types
.is_empty ())
13698 clauses
.release ();
13702 c_token
*token
= c_parser_peek_token (parser
);
13703 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13705 c_parser_consume_token (parser
);
13707 c_parser_skip_to_pragma_eol (parser
);
13711 if (types
.length () > 1)
13713 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13715 c_token
*token
= c_parser_peek_token (parser
);
13716 if (token
->type
== CPP_EOF
)
13718 clauses
.safe_push (*token
);
13719 c_parser_consume_token (parser
);
13721 clauses
.safe_push (*c_parser_peek_token (parser
));
13722 c_parser_skip_to_pragma_eol (parser
);
13724 /* Make sure nothing tries to read past the end of the tokens. */
13726 memset (&eof_token
, 0, sizeof (eof_token
));
13727 eof_token
.type
= CPP_EOF
;
13728 clauses
.safe_push (eof_token
);
13729 clauses
.safe_push (eof_token
);
13732 int errs
= errorcount
;
13733 FOR_EACH_VEC_ELT (types
, i
, type
)
13735 tokens_avail
= parser
->tokens_avail
;
13736 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13737 if (!clauses
.is_empty ())
13739 parser
->tokens
= clauses
.address ();
13740 parser
->tokens_avail
= clauses
.length ();
13741 parser
->in_pragma
= true;
13744 bool nested
= current_function_decl
!= NULL_TREE
;
13746 c_push_function_context ();
13747 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13748 reduc_id
, default_function_type
);
13749 current_function_decl
= fndecl
;
13750 allocate_struct_function (fndecl
, true);
13752 tree stmt
= push_stmt_list ();
13753 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13754 warn about these. */
13755 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13756 get_identifier ("omp_out"), type
);
13757 DECL_ARTIFICIAL (omp_out
) = 1;
13758 DECL_CONTEXT (omp_out
) = fndecl
;
13759 pushdecl (omp_out
);
13760 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13761 get_identifier ("omp_in"), type
);
13762 DECL_ARTIFICIAL (omp_in
) = 1;
13763 DECL_CONTEXT (omp_in
) = fndecl
;
13765 struct c_expr combiner
= c_parser_expression (parser
);
13766 struct c_expr initializer
;
13767 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13769 initializer
.value
= error_mark_node
;
13770 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13772 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13773 && strcmp (IDENTIFIER_POINTER
13774 (c_parser_peek_token (parser
)->value
),
13775 "initializer") == 0)
13777 c_parser_consume_token (parser
);
13780 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13781 get_identifier ("omp_priv"), type
);
13782 DECL_ARTIFICIAL (omp_priv
) = 1;
13783 DECL_INITIAL (omp_priv
) = error_mark_node
;
13784 DECL_CONTEXT (omp_priv
) = fndecl
;
13785 pushdecl (omp_priv
);
13786 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13787 get_identifier ("omp_orig"), type
);
13788 DECL_ARTIFICIAL (omp_orig
) = 1;
13789 DECL_CONTEXT (omp_orig
) = fndecl
;
13790 pushdecl (omp_orig
);
13791 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13793 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13795 c_parser_error (parser
, "expected %<omp_priv%> or "
13799 else if (strcmp (IDENTIFIER_POINTER
13800 (c_parser_peek_token (parser
)->value
),
13803 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13804 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13806 c_parser_error (parser
, "expected function-name %<(%>");
13810 initializer
= c_parser_postfix_expression (parser
);
13811 if (initializer
.value
13812 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13815 tree c
= initializer
.value
;
13816 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13817 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13818 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13820 if (j
== call_expr_nargs (c
))
13821 error ("one of the initializer call arguments should be "
13827 c_parser_consume_token (parser
);
13828 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13832 tree st
= push_stmt_list ();
13833 start_init (omp_priv
, NULL_TREE
, 0);
13834 location_t loc
= c_parser_peek_token (parser
)->location
;
13835 struct c_expr init
= c_parser_initializer (parser
);
13837 finish_decl (omp_priv
, loc
, init
.value
,
13838 init
.original_type
, NULL_TREE
);
13839 pop_stmt_list (st
);
13843 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13849 c_parser_skip_to_pragma_eol (parser
);
13851 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13852 DECL_INITIAL (reduc_decl
));
13853 DECL_INITIAL (reduc_decl
) = t
;
13854 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13855 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13856 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13857 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13858 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13859 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13862 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13863 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13864 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13865 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13866 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13867 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13868 walk_tree (&DECL_INITIAL (omp_priv
),
13869 c_check_omp_declare_reduction_r
,
13870 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13874 pop_stmt_list (stmt
);
13876 if (cfun
->language
!= NULL
)
13878 ggc_free (cfun
->language
);
13879 cfun
->language
= NULL
;
13882 current_function_decl
= NULL_TREE
;
13884 c_pop_function_context ();
13886 if (!clauses
.is_empty ())
13888 parser
->tokens
= &parser
->tokens_buf
[0];
13889 parser
->tokens_avail
= tokens_avail
;
13893 if (errs
!= errorcount
)
13897 clauses
.release ();
13903 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13904 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13905 initializer-clause[opt] new-line
13906 #pragma omp declare target new-line */
13909 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13911 c_parser_consume_pragma (parser
);
13912 if (c_parser_next_token_is (parser
, CPP_NAME
))
13914 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13915 if (strcmp (p
, "simd") == 0)
13917 /* c_parser_consume_token (parser); done in
13918 c_parser_omp_declare_simd. */
13919 c_parser_omp_declare_simd (parser
, context
);
13922 if (strcmp (p
, "reduction") == 0)
13924 c_parser_consume_token (parser
);
13925 c_parser_omp_declare_reduction (parser
, context
);
13928 if (!flag_openmp
) /* flag_openmp_simd */
13930 c_parser_skip_to_pragma_eol (parser
);
13933 if (strcmp (p
, "target") == 0)
13935 c_parser_consume_token (parser
);
13936 c_parser_omp_declare_target (parser
);
13941 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13943 c_parser_skip_to_pragma_eol (parser
);
13946 /* Main entry point to parsing most OpenMP pragmas. */
13949 c_parser_omp_construct (c_parser
*parser
)
13951 enum pragma_kind p_kind
;
13954 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13955 omp_clause_mask
mask (0);
13957 loc
= c_parser_peek_token (parser
)->location
;
13958 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13959 c_parser_consume_pragma (parser
);
13963 case PRAGMA_OMP_ATOMIC
:
13964 c_parser_omp_atomic (loc
, parser
);
13966 case PRAGMA_OMP_CRITICAL
:
13967 stmt
= c_parser_omp_critical (loc
, parser
);
13969 case PRAGMA_OMP_DISTRIBUTE
:
13970 strcpy (p_name
, "#pragma omp");
13971 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13973 case PRAGMA_OMP_FOR
:
13974 strcpy (p_name
, "#pragma omp");
13975 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13977 case PRAGMA_OMP_MASTER
:
13978 stmt
= c_parser_omp_master (loc
, parser
);
13980 case PRAGMA_OMP_ORDERED
:
13981 stmt
= c_parser_omp_ordered (loc
, parser
);
13983 case PRAGMA_OMP_PARALLEL
:
13984 strcpy (p_name
, "#pragma omp");
13985 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13987 case PRAGMA_OMP_SECTIONS
:
13988 strcpy (p_name
, "#pragma omp");
13989 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13991 case PRAGMA_OMP_SIMD
:
13992 strcpy (p_name
, "#pragma omp");
13993 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13995 case PRAGMA_OMP_SINGLE
:
13996 stmt
= c_parser_omp_single (loc
, parser
);
13998 case PRAGMA_OMP_TASK
:
13999 stmt
= c_parser_omp_task (loc
, parser
);
14001 case PRAGMA_OMP_TASKGROUP
:
14002 stmt
= c_parser_omp_taskgroup (parser
);
14004 case PRAGMA_OMP_TEAMS
:
14005 strcpy (p_name
, "#pragma omp");
14006 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
14009 gcc_unreachable ();
14013 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
14018 # pragma omp threadprivate (variable-list) */
14021 c_parser_omp_threadprivate (c_parser
*parser
)
14026 c_parser_consume_pragma (parser
);
14027 loc
= c_parser_peek_token (parser
)->location
;
14028 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14030 /* Mark every variable in VARS to be assigned thread local storage. */
14031 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
14033 tree v
= TREE_PURPOSE (t
);
14035 /* FIXME diagnostics: Ideally we should keep individual
14036 locations for all the variables in the var list to make the
14037 following errors more precise. Perhaps
14038 c_parser_omp_var_list_parens() should construct a list of
14039 locations to go along with the var list. */
14041 /* If V had already been marked threadprivate, it doesn't matter
14042 whether it had been used prior to this point. */
14043 if (TREE_CODE (v
) != VAR_DECL
)
14044 error_at (loc
, "%qD is not a variable", v
);
14045 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
14046 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
14047 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
14048 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
14049 else if (TREE_TYPE (v
) == error_mark_node
)
14051 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
14052 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
14055 if (! DECL_THREAD_LOCAL_P (v
))
14057 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
14058 /* If rtl has been already set for this var, call
14059 make_decl_rtl once again, so that encode_section_info
14060 has a chance to look at the new decl flags. */
14061 if (DECL_RTL_SET_P (v
))
14064 C_DECL_THREADPRIVATE_P (v
) = 1;
14068 c_parser_skip_to_pragma_eol (parser
);
14071 /* Cilk Plus <#pragma simd> parsing routines. */
14073 /* Helper function for c_parser_pragma. Perform some sanity checking
14074 for <#pragma simd> constructs. Returns FALSE if there was a
14078 c_parser_cilk_verify_simd (c_parser
*parser
,
14079 enum pragma_context context
)
14081 if (!flag_cilkplus
)
14083 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
14084 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14087 if (context
== pragma_external
)
14089 c_parser_error (parser
,"pragma simd must be inside a function");
14090 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
14097 This function is shared by SIMD-enabled functions and #pragma simd.
14098 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
14099 CLAUSES is unused. The main purpose of this function is to parse a
14100 vectorlength attribute or clause and check for parse errors.
14101 When IS_SIMD_FN is true then the function is merely caching the tokens
14102 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
14103 cache is cleared since there is no reason to continue.
14105 vectorlength ( constant-expression ) */
14108 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
14112 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
14114 /* The vectorlength clause behaves exactly like OpenMP's safelen
14115 clause. Represent it in OpenMP terms. */
14116 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
14118 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14121 location_t loc
= c_parser_peek_token (parser
)->location
;
14122 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14123 expr
= c_fully_fold (expr
, false, NULL
);
14125 /* If expr is an error_mark_node then the above function would have
14126 emitted an error. No reason to do it twice. */
14127 if (expr
== error_mark_node
)
14129 else if (!TREE_TYPE (expr
)
14130 || !TREE_CONSTANT (expr
)
14131 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
14133 error_at (loc
, "vectorlength must be an integer constant");
14134 else if (exact_log2 (TREE_INT_CST_LOW (expr
)) == -1)
14135 error_at (loc
, "vectorlength must be a power of 2");
14140 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
14141 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
14142 OMP_CLAUSE_CHAIN (u
) = clauses
;
14147 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
14148 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
14149 OMP_CLAUSE_CHAIN (u
) = clauses
;
14154 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14160 linear ( simd-linear-variable-list )
14162 simd-linear-variable-list:
14163 simd-linear-variable
14164 simd-linear-variable-list , simd-linear-variable
14166 simd-linear-variable:
14168 id-expression : simd-linear-step
14171 conditional-expression */
14174 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
14176 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14179 location_t loc
= c_parser_peek_token (parser
)->location
;
14181 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
14182 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
14183 c_parser_error (parser
, "expected identifier");
14185 while (c_parser_next_token_is (parser
, CPP_NAME
)
14186 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
14188 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
14192 undeclared_variable (c_parser_peek_token (parser
)->location
,
14193 c_parser_peek_token (parser
)->value
);
14194 c_parser_consume_token (parser
);
14196 else if (var
== error_mark_node
)
14197 c_parser_consume_token (parser
);
14200 tree step
= integer_one_node
;
14202 /* Parse the linear step if present. */
14203 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
14205 c_parser_consume_token (parser
);
14206 c_parser_consume_token (parser
);
14208 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
14209 expr
= c_fully_fold (expr
, false, NULL
);
14211 if (TREE_TYPE (expr
)
14212 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
14213 && (TREE_CONSTANT (expr
)
14217 c_parser_error (parser
,
14218 "step size must be an integer constant "
14219 "expression or an integer variable");
14222 c_parser_consume_token (parser
);
14224 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
14225 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
14226 OMP_CLAUSE_DECL (u
) = var
;
14227 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
14228 OMP_CLAUSE_CHAIN (u
) = clauses
;
14232 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
14235 c_parser_consume_token (parser
);
14238 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14243 /* Returns the name of the next clause. If the clause is not
14244 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
14245 not consumed. Otherwise, the appropriate pragma_simd_clause is
14246 returned and the token is consumed. */
14248 static pragma_omp_clause
14249 c_parser_cilk_clause_name (c_parser
*parser
)
14251 pragma_omp_clause result
;
14252 c_token
*token
= c_parser_peek_token (parser
);
14254 if (!token
->value
|| token
->type
!= CPP_NAME
)
14255 return PRAGMA_CILK_CLAUSE_NONE
;
14257 const char *p
= IDENTIFIER_POINTER (token
->value
);
14259 if (!strcmp (p
, "vectorlength"))
14260 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
14261 else if (!strcmp (p
, "linear"))
14262 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
14263 else if (!strcmp (p
, "private"))
14264 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
14265 else if (!strcmp (p
, "firstprivate"))
14266 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
14267 else if (!strcmp (p
, "lastprivate"))
14268 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
14269 else if (!strcmp (p
, "reduction"))
14270 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
14272 return PRAGMA_CILK_CLAUSE_NONE
;
14274 c_parser_consume_token (parser
);
14278 /* Parse all #<pragma simd> clauses. Return the list of clauses
14282 c_parser_cilk_all_clauses (c_parser
*parser
)
14284 tree clauses
= NULL
;
14286 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14288 pragma_omp_clause c_kind
;
14290 c_kind
= c_parser_cilk_clause_name (parser
);
14294 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
14295 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
14297 case PRAGMA_CILK_CLAUSE_LINEAR
:
14298 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
14300 case PRAGMA_CILK_CLAUSE_PRIVATE
:
14301 /* Use the OpenMP counterpart. */
14302 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14304 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
14305 /* Use the OpenMP counterpart. */
14306 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14308 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
14309 /* Use the OpenMP counterpart. */
14310 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14312 case PRAGMA_CILK_CLAUSE_REDUCTION
:
14313 /* Use the OpenMP counterpart. */
14314 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14317 c_parser_error (parser
, "expected %<#pragma simd%> clause");
14323 c_parser_skip_to_pragma_eol (parser
);
14324 return c_finish_cilk_clauses (clauses
);
14327 /* Main entry point for parsing Cilk Plus <#pragma simd> for
14331 c_parser_cilk_simd (c_parser
*parser
)
14333 tree clauses
= c_parser_cilk_all_clauses (parser
);
14334 tree block
= c_begin_compound_stmt (true);
14335 location_t loc
= c_parser_peek_token (parser
)->location
;
14336 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
14337 block
= c_end_compound_stmt (loc
, block
, true);
14341 /* Parse a transaction attribute (GCC Extension).
14343 transaction-attribute:
14347 The transactional memory language description is written for C++,
14348 and uses the C++0x attribute syntax. For compatibility, allow the
14349 bracket style for transactions in C as well. */
14352 c_parser_transaction_attributes (c_parser
*parser
)
14354 tree attr_name
, attr
= NULL
;
14356 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
14357 return c_parser_attributes (parser
);
14359 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
14361 c_parser_consume_token (parser
);
14362 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
14365 attr_name
= c_parser_attribute_any_word (parser
);
14368 c_parser_consume_token (parser
);
14369 attr
= build_tree_list (attr_name
, NULL_TREE
);
14372 c_parser_error (parser
, "expected identifier");
14374 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14376 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14380 /* Parse a __transaction_atomic or __transaction_relaxed statement
14383 transaction-statement:
14384 __transaction_atomic transaction-attribute[opt] compound-statement
14385 __transaction_relaxed compound-statement
14387 Note that the only valid attribute is: "outer".
14391 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
14393 unsigned int old_in
= parser
->in_transaction
;
14394 unsigned int this_in
= 1, new_in
;
14395 location_t loc
= c_parser_peek_token (parser
)->location
;
14398 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
14399 || keyword
== RID_TRANSACTION_RELAXED
)
14400 && c_parser_next_token_is_keyword (parser
, keyword
));
14401 c_parser_consume_token (parser
);
14403 if (keyword
== RID_TRANSACTION_RELAXED
)
14404 this_in
|= TM_STMT_ATTR_RELAXED
;
14407 attrs
= c_parser_transaction_attributes (parser
);
14409 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
14412 /* Keep track if we're in the lexical scope of an outer transaction. */
14413 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
14415 parser
->in_transaction
= new_in
;
14416 stmt
= c_parser_compound_statement (parser
);
14417 parser
->in_transaction
= old_in
;
14420 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
14422 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
14423 "%<__transaction_atomic%> without transactional memory support enabled"
14424 : "%<__transaction_relaxed %> "
14425 "without transactional memory support enabled"));
14430 /* Parse a __transaction_atomic or __transaction_relaxed expression
14433 transaction-expression:
14434 __transaction_atomic ( expression )
14435 __transaction_relaxed ( expression )
14438 static struct c_expr
14439 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
14442 unsigned int old_in
= parser
->in_transaction
;
14443 unsigned int this_in
= 1;
14444 location_t loc
= c_parser_peek_token (parser
)->location
;
14447 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
14448 || keyword
== RID_TRANSACTION_RELAXED
)
14449 && c_parser_next_token_is_keyword (parser
, keyword
));
14450 c_parser_consume_token (parser
);
14452 if (keyword
== RID_TRANSACTION_RELAXED
)
14453 this_in
|= TM_STMT_ATTR_RELAXED
;
14456 attrs
= c_parser_transaction_attributes (parser
);
14458 this_in
|= parse_tm_stmt_attr (attrs
, 0);
14461 parser
->in_transaction
= this_in
;
14462 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14464 tree expr
= c_parser_expression (parser
).value
;
14465 ret
.original_type
= TREE_TYPE (expr
);
14466 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
14467 if (this_in
& TM_STMT_ATTR_RELAXED
)
14468 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
14469 SET_EXPR_LOCATION (ret
.value
, loc
);
14470 ret
.original_code
= TRANSACTION_EXPR
;
14471 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14473 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
14480 ret
.value
= error_mark_node
;
14481 ret
.original_code
= ERROR_MARK
;
14482 ret
.original_type
= NULL
;
14484 parser
->in_transaction
= old_in
;
14487 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
14488 "%<__transaction_atomic%> without transactional memory support enabled"
14489 : "%<__transaction_relaxed %> "
14490 "without transactional memory support enabled"));
14495 /* Parse a __transaction_cancel statement (GCC Extension).
14497 transaction-cancel-statement:
14498 __transaction_cancel transaction-attribute[opt] ;
14500 Note that the only valid attribute is "outer".
14504 c_parser_transaction_cancel (c_parser
*parser
)
14506 location_t loc
= c_parser_peek_token (parser
)->location
;
14508 bool is_outer
= false;
14510 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
14511 c_parser_consume_token (parser
);
14513 attrs
= c_parser_transaction_attributes (parser
);
14515 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
14519 error_at (loc
, "%<__transaction_cancel%> without "
14520 "transactional memory support enabled");
14523 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
14525 error_at (loc
, "%<__transaction_cancel%> within a "
14526 "%<__transaction_relaxed%>");
14531 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
14532 && !is_tm_may_cancel_outer (current_function_decl
))
14534 error_at (loc
, "outer %<__transaction_cancel%> not "
14535 "within outer %<__transaction_atomic%>");
14536 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
14540 else if (parser
->in_transaction
== 0)
14542 error_at (loc
, "%<__transaction_cancel%> not within "
14543 "%<__transaction_atomic%>");
14547 return add_stmt (build_tm_abort_call (loc
, is_outer
));
14550 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
14553 /* Parse a single source file. */
14556 c_parse_file (void)
14558 /* Use local storage to begin. If the first token is a pragma, parse it.
14559 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14560 which will cause garbage collection. */
14563 memset (&tparser
, 0, sizeof tparser
);
14564 tparser
.tokens
= &tparser
.tokens_buf
[0];
14565 the_parser
= &tparser
;
14567 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
14568 c_parser_pragma_pch_preprocess (&tparser
);
14570 the_parser
= ggc_alloc_c_parser ();
14571 *the_parser
= tparser
;
14572 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
14573 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
14575 /* Initialize EH, if we've been told to do so. */
14576 if (flag_exceptions
)
14577 using_eh_for_cleanups ();
14579 c_parser_translation_unit (the_parser
);
14583 /* This function parses Cilk Plus array notation. The starting index is
14584 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14585 return value of this function is a tree_node called VALUE_TREE of type
14586 ARRAY_NOTATION_REF. */
14589 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
14592 c_token
*token
= NULL
;
14593 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
14594 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
14595 tree array_type_domain
= NULL_TREE
;
14597 if (array_value
== error_mark_node
)
14599 /* No need to continue. If either of these 2 were true, then an error
14600 must be emitted already. Thus, no need to emit them twice. */
14601 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14602 return error_mark_node
;
14605 array_type
= TREE_TYPE (array_value
);
14606 gcc_assert (array_type
);
14607 type
= TREE_TYPE (array_type
);
14608 token
= c_parser_peek_token (parser
);
14610 if (token
->type
== CPP_EOF
)
14612 c_parser_error (parser
, "expected %<:%> or numeral");
14615 else if (token
->type
== CPP_COLON
)
14617 if (!initial_index
)
14619 /* If we are here, then we have a case like this A[:]. */
14620 c_parser_consume_token (parser
);
14621 if (TREE_CODE (array_type
) == POINTER_TYPE
)
14623 error_at (loc
, "start-index and length fields necessary for "
14624 "using array notations in pointers");
14625 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14626 return error_mark_node
;
14628 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14630 error_at (loc
, "array notations cannot be used with function "
14632 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14633 return error_mark_node
;
14635 array_type_domain
= TYPE_DOMAIN (array_type
);
14637 if (!array_type_domain
)
14639 error_at (loc
, "start-index and length fields necessary for "
14640 "using array notations in dimensionless arrays");
14641 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14642 return error_mark_node
;
14645 start_index
= TYPE_MINVAL (array_type_domain
);
14646 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
14648 if (!TYPE_MAXVAL (array_type_domain
)
14649 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
14651 error_at (loc
, "start-index and length fields necessary for "
14652 "using array notations in variable-length arrays");
14653 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14654 return error_mark_node
;
14656 end_index
= TYPE_MAXVAL (array_type_domain
);
14657 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
14658 end_index
, integer_one_node
);
14659 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
14660 stride
= build_int_cst (integer_type_node
, 1);
14661 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
14663 else if (initial_index
!= error_mark_node
)
14665 /* If we are here, then there should be 2 possibilities:
14666 1. Array [EXPR : EXPR]
14667 2. Array [EXPR : EXPR : EXPR]
14669 start_index
= initial_index
;
14671 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14673 error_at (loc
, "array notations cannot be used with function "
14675 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14676 return error_mark_node
;
14678 c_parser_consume_token (parser
); /* consume the ':' */
14679 struct c_expr ce
= c_parser_expression (parser
);
14680 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14681 end_index
= ce
.value
;
14682 if (!end_index
|| end_index
== error_mark_node
)
14684 c_parser_skip_to_end_of_block_or_statement (parser
);
14685 return error_mark_node
;
14687 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
14689 c_parser_consume_token (parser
);
14690 ce
= c_parser_expression (parser
);
14691 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14693 if (!stride
|| stride
== error_mark_node
)
14695 c_parser_skip_to_end_of_block_or_statement (parser
);
14696 return error_mark_node
;
14701 c_parser_error (parser
, "expected array notation expression");
14704 c_parser_error (parser
, "expected array notation expression");
14706 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14708 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
14709 end_index
, stride
, type
);
14710 if (value_tree
!= error_mark_node
)
14711 SET_EXPR_LOCATION (value_tree
, loc
);
14715 #include "gt-c-c-parser.h"