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"
63 #include "plugin-api.h"
67 #include "hard-reg-set.h"
76 /* Initialization routine for this file. */
81 /* The only initialization required is of the reserved word
87 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
88 the c_token structure. */
89 gcc_assert (RID_MAX
<= 255);
96 mask
|= D_ASM
| D_EXT
;
100 if (!c_dialect_objc ())
101 mask
|= D_OBJC
| D_CXX_OBJC
;
103 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
104 for (i
= 0; i
< num_c_common_reswords
; i
++)
106 /* If a keyword is disabled, do not enter it into the table
107 and so create a canonical spelling that isn't a keyword. */
108 if (c_common_reswords
[i
].disable
& mask
)
111 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
113 id
= get_identifier (c_common_reswords
[i
].word
);
114 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
115 C_IS_RESERVED_WORD (id
) = 1;
120 id
= get_identifier (c_common_reswords
[i
].word
);
121 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
122 C_IS_RESERVED_WORD (id
) = 1;
123 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
126 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
128 /* We always create the symbols but they aren't always supported. */
130 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
131 id
= get_identifier (xstrdup (name
));
132 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
133 C_IS_RESERVED_WORD (id
) = 1;
137 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
138 and the C parser. Unlike the C++ lexer, the parser structure
139 stores the lexer information instead of using a separate structure.
140 Identifiers are separated into ordinary identifiers, type names,
141 keywords and some other Objective-C types of identifiers, and some
142 look-ahead is maintained.
144 ??? It might be a good idea to lex the whole file up front (as for
145 C++). It would then be possible to share more of the C and C++
146 lexer code, if desired. */
148 /* More information about the type of a CPP_NAME token. */
149 typedef enum c_id_kind
{
150 /* An ordinary identifier. */
152 /* An identifier declared as a typedef name. */
154 /* An identifier declared as an Objective-C class name. */
156 /* An address space identifier. */
158 /* Not an identifier. */
162 /* A single C token after string literal concatenation and conversion
163 of preprocessing tokens to tokens. */
164 typedef struct GTY (()) c_token
{
165 /* The kind of token. */
166 ENUM_BITFIELD (cpp_ttype
) type
: 8;
167 /* If this token is a CPP_NAME, this value indicates whether also
168 declared as some kind of type. Otherwise, it is C_ID_NONE. */
169 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
170 /* If this token is a keyword, this value indicates which keyword.
171 Otherwise, this value is RID_MAX. */
172 ENUM_BITFIELD (rid
) keyword
: 8;
173 /* If this token is a CPP_PRAGMA, this indicates the pragma that
174 was seen. Otherwise it is PRAGMA_NONE. */
175 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
176 /* The location at which this token was found. */
178 /* The value associated with this token, if any. */
182 /* A parser structure recording information about the state and
183 context of parsing. Includes lexer information with up to two
184 tokens of look-ahead; more are not needed for C. */
185 typedef struct GTY(()) c_parser
{
186 /* The look-ahead tokens. */
187 c_token
* GTY((skip
)) tokens
;
188 /* Buffer for look-ahead tokens. */
189 c_token tokens_buf
[2];
190 /* How many look-ahead tokens are available (0, 1 or 2, or
191 more if parsing from pre-lexed tokens). */
192 unsigned int tokens_avail
;
193 /* True if a syntax error is being recovered from; false otherwise.
194 c_parser_error sets this flag. It should clear this flag when
195 enough tokens have been consumed to recover from the error. */
196 BOOL_BITFIELD error
: 1;
197 /* True if we're processing a pragma, and shouldn't automatically
198 consume CPP_PRAGMA_EOL. */
199 BOOL_BITFIELD in_pragma
: 1;
200 /* True if we're parsing the outermost block of an if statement. */
201 BOOL_BITFIELD in_if_block
: 1;
202 /* True if we want to lex an untranslated string. */
203 BOOL_BITFIELD lex_untranslated_string
: 1;
205 /* Objective-C specific parser/lexer information. */
207 /* True if we are in a context where the Objective-C "PQ" keywords
208 are considered keywords. */
209 BOOL_BITFIELD objc_pq_context
: 1;
210 /* True if we are parsing a (potential) Objective-C foreach
211 statement. This is set to true after we parsed 'for (' and while
212 we wait for 'in' or ';' to decide if it's a standard C for loop or an
213 Objective-C foreach loop. */
214 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
215 /* The following flag is needed to contextualize Objective-C lexical
216 analysis. In some cases (e.g., 'int NSObject;'), it is
217 undesirable to bind an identifier to an Objective-C class, even
218 if a class with that name exists. */
219 BOOL_BITFIELD objc_need_raw_identifier
: 1;
220 /* Nonzero if we're processing a __transaction statement. The value
221 is 1 | TM_STMT_ATTR_*. */
222 unsigned int in_transaction
: 4;
223 /* True if we are in a context where the Objective-C "Property attribute"
224 keywords are valid. */
225 BOOL_BITFIELD objc_property_attr_context
: 1;
227 /* Cilk Plus specific parser/lexer information. */
229 /* Buffer to hold all the tokens from parsing the vector attribute for the
230 SIMD-enabled functions (formerly known as elemental functions). */
231 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
235 /* The actual parser and external interface. ??? Does this need to be
236 garbage-collected? */
238 static GTY (()) c_parser
*the_parser
;
240 /* Read in and lex a single token, storing it in *TOKEN. */
243 c_lex_one_token (c_parser
*parser
, c_token
*token
)
245 timevar_push (TV_LEX
);
247 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
248 (parser
->lex_untranslated_string
249 ? C_LEX_STRING_NO_TRANSLATE
: 0));
250 token
->id_kind
= C_ID_NONE
;
251 token
->keyword
= RID_MAX
;
252 token
->pragma_kind
= PRAGMA_NONE
;
260 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
261 if (c_dialect_objc ())
262 parser
->objc_need_raw_identifier
= false;
264 if (C_IS_RESERVED_WORD (token
->value
))
266 enum rid rid_code
= C_RID_CODE (token
->value
);
268 if (rid_code
== RID_CXX_COMPAT_WARN
)
270 warning_at (token
->location
,
272 "identifier %qE conflicts with C++ keyword",
275 else if (rid_code
>= RID_FIRST_ADDR_SPACE
276 && rid_code
<= RID_LAST_ADDR_SPACE
)
278 token
->id_kind
= C_ID_ADDRSPACE
;
279 token
->keyword
= rid_code
;
282 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
284 /* We found an Objective-C "pq" keyword (in, out,
285 inout, bycopy, byref, oneway). They need special
286 care because the interpretation depends on the
288 if (parser
->objc_pq_context
)
290 token
->type
= CPP_KEYWORD
;
291 token
->keyword
= rid_code
;
294 else if (parser
->objc_could_be_foreach_context
295 && rid_code
== RID_IN
)
297 /* We are in Objective-C, inside a (potential)
298 foreach context (which means after having
299 parsed 'for (', but before having parsed ';'),
300 and we found 'in'. We consider it the keyword
301 which terminates the declaration at the
302 beginning of a foreach-statement. Note that
303 this means you can't use 'in' for anything else
304 in that context; in particular, in Objective-C
305 you can't use 'in' as the name of the running
306 variable in a C for loop. We could potentially
307 try to add code here to disambiguate, but it
308 seems a reasonable limitation. */
309 token
->type
= CPP_KEYWORD
;
310 token
->keyword
= rid_code
;
313 /* Else, "pq" keywords outside of the "pq" context are
314 not keywords, and we fall through to the code for
317 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
319 /* We found an Objective-C "property attribute"
320 keyword (getter, setter, readonly, etc). These are
321 only valid in the property context. */
322 if (parser
->objc_property_attr_context
)
324 token
->type
= CPP_KEYWORD
;
325 token
->keyword
= rid_code
;
328 /* Else they are not special keywords.
331 else if (c_dialect_objc ()
332 && (OBJC_IS_AT_KEYWORD (rid_code
)
333 || OBJC_IS_CXX_KEYWORD (rid_code
)))
335 /* We found one of the Objective-C "@" keywords (defs,
336 selector, synchronized, etc) or one of the
337 Objective-C "cxx" keywords (class, private,
338 protected, public, try, catch, throw) without a
339 preceding '@' sign. Do nothing and fall through to
340 the code for normal tokens (in C++ we would still
341 consider the CXX ones keywords, but not in C). */
346 token
->type
= CPP_KEYWORD
;
347 token
->keyword
= rid_code
;
352 decl
= lookup_name (token
->value
);
355 if (TREE_CODE (decl
) == TYPE_DECL
)
357 token
->id_kind
= C_ID_TYPENAME
;
361 else if (c_dialect_objc ())
363 tree objc_interface_decl
= objc_is_class_name (token
->value
);
364 /* Objective-C class names are in the same namespace as
365 variables and typedefs, and hence are shadowed by local
367 if (objc_interface_decl
368 && (!objc_force_identifier
|| global_bindings_p ()))
370 token
->value
= objc_interface_decl
;
371 token
->id_kind
= C_ID_CLASSNAME
;
375 token
->id_kind
= C_ID_ID
;
379 /* This only happens in Objective-C; it must be a keyword. */
380 token
->type
= CPP_KEYWORD
;
381 switch (C_RID_CODE (token
->value
))
383 /* Replace 'class' with '@class', 'private' with '@private',
384 etc. This prevents confusion with the C++ keyword
385 'class', and makes the tokens consistent with other
386 Objective-C 'AT' keywords. For example '@class' is
387 reported as RID_AT_CLASS which is consistent with
388 '@synchronized', which is reported as
391 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
392 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
393 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
394 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
395 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
396 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
397 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
398 default: token
->keyword
= C_RID_CODE (token
->value
);
403 case CPP_CLOSE_PAREN
:
405 /* These tokens may affect the interpretation of any identifiers
406 following, if doing Objective-C. */
407 if (c_dialect_objc ())
408 parser
->objc_need_raw_identifier
= false;
411 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
412 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
418 timevar_pop (TV_LEX
);
421 /* Return a pointer to the next token from PARSER, reading it in if
424 static inline c_token
*
425 c_parser_peek_token (c_parser
*parser
)
427 if (parser
->tokens_avail
== 0)
429 c_lex_one_token (parser
, &parser
->tokens
[0]);
430 parser
->tokens_avail
= 1;
432 return &parser
->tokens
[0];
435 /* Return true if the next token from PARSER has the indicated
439 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
441 return c_parser_peek_token (parser
)->type
== type
;
444 /* Return true if the next token from PARSER does not have the
448 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
450 return !c_parser_next_token_is (parser
, type
);
453 /* Return true if the next token from PARSER is the indicated
457 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
459 return c_parser_peek_token (parser
)->keyword
== keyword
;
462 /* Return a pointer to the next-but-one token from PARSER, reading it
463 in if necessary. The next token is already read in. */
466 c_parser_peek_2nd_token (c_parser
*parser
)
468 if (parser
->tokens_avail
>= 2)
469 return &parser
->tokens
[1];
470 gcc_assert (parser
->tokens_avail
== 1);
471 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
472 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
473 c_lex_one_token (parser
, &parser
->tokens
[1]);
474 parser
->tokens_avail
= 2;
475 return &parser
->tokens
[1];
478 /* Return true if TOKEN can start a type name,
481 c_token_starts_typename (c_token
*token
)
486 switch (token
->id_kind
)
495 gcc_assert (c_dialect_objc ());
501 switch (token
->keyword
)
532 if (token
->keyword
>= RID_FIRST_INT_N
533 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
534 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
539 if (c_dialect_objc ())
547 enum c_lookahead_kind
{
548 /* Always treat unknown identifiers as typenames. */
551 /* Could be parsing a nonabstract declarator. Only treat an identifier
552 as a typename if followed by another identifier or a star. */
553 cla_nonabstract_decl
,
555 /* Never treat identifiers as typenames. */
559 /* Return true if the next token from PARSER can start a type name,
560 false otherwise. LA specifies how to do lookahead in order to
561 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
564 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
566 c_token
*token
= c_parser_peek_token (parser
);
567 if (c_token_starts_typename (token
))
570 /* Try a bit harder to detect an unknown typename. */
571 if (la
!= cla_prefer_id
572 && token
->type
== CPP_NAME
573 && token
->id_kind
== C_ID_ID
575 /* Do not try too hard when we could have "object in array". */
576 && !parser
->objc_could_be_foreach_context
578 && (la
== cla_prefer_type
579 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
580 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
582 /* Only unknown identifiers. */
583 && !lookup_name (token
->value
))
589 /* Return true if TOKEN is a type qualifier, false otherwise. */
591 c_token_is_qualifier (c_token
*token
)
596 switch (token
->id_kind
)
604 switch (token
->keyword
)
622 /* Return true if the next token from PARSER is a type qualifier,
625 c_parser_next_token_is_qualifier (c_parser
*parser
)
627 c_token
*token
= c_parser_peek_token (parser
);
628 return c_token_is_qualifier (token
);
631 /* Return true if TOKEN can start declaration specifiers, false
634 c_token_starts_declspecs (c_token
*token
)
639 switch (token
->id_kind
)
648 gcc_assert (c_dialect_objc ());
654 switch (token
->keyword
)
694 if (token
->keyword
>= RID_FIRST_INT_N
695 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
696 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
701 if (c_dialect_objc ())
710 /* Return true if TOKEN can start declaration specifiers or a static
711 assertion, false otherwise. */
713 c_token_starts_declaration (c_token
*token
)
715 if (c_token_starts_declspecs (token
)
716 || token
->keyword
== RID_STATIC_ASSERT
)
722 /* Return true if the next token from PARSER can start declaration
723 specifiers, false otherwise. */
725 c_parser_next_token_starts_declspecs (c_parser
*parser
)
727 c_token
*token
= c_parser_peek_token (parser
);
729 /* In Objective-C, a classname normally starts a declspecs unless it
730 is immediately followed by a dot. In that case, it is the
731 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
732 setter/getter on the class. c_token_starts_declspecs() can't
733 differentiate between the two cases because it only checks the
734 current token, so we have a special check here. */
735 if (c_dialect_objc ()
736 && token
->type
== CPP_NAME
737 && token
->id_kind
== C_ID_CLASSNAME
738 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
741 return c_token_starts_declspecs (token
);
744 /* Return true if the next tokens from PARSER can start declaration
745 specifiers or a static assertion, false otherwise. */
747 c_parser_next_tokens_start_declaration (c_parser
*parser
)
749 c_token
*token
= c_parser_peek_token (parser
);
752 if (c_dialect_objc ()
753 && token
->type
== CPP_NAME
754 && token
->id_kind
== C_ID_CLASSNAME
755 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
758 /* Labels do not start declarations. */
759 if (token
->type
== CPP_NAME
760 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
763 if (c_token_starts_declaration (token
))
766 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
772 /* Consume the next token from PARSER. */
775 c_parser_consume_token (c_parser
*parser
)
777 gcc_assert (parser
->tokens_avail
>= 1);
778 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
779 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
780 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
781 if (parser
->tokens
!= &parser
->tokens_buf
[0])
783 else if (parser
->tokens_avail
== 2)
784 parser
->tokens
[0] = parser
->tokens
[1];
785 parser
->tokens_avail
--;
788 /* Expect the current token to be a #pragma. Consume it and remember
789 that we've begun parsing a pragma. */
792 c_parser_consume_pragma (c_parser
*parser
)
794 gcc_assert (!parser
->in_pragma
);
795 gcc_assert (parser
->tokens_avail
>= 1);
796 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
797 if (parser
->tokens
!= &parser
->tokens_buf
[0])
799 else if (parser
->tokens_avail
== 2)
800 parser
->tokens
[0] = parser
->tokens
[1];
801 parser
->tokens_avail
--;
802 parser
->in_pragma
= true;
805 /* Update the global input_location from TOKEN. */
807 c_parser_set_source_position_from_token (c_token
*token
)
809 if (token
->type
!= CPP_EOF
)
811 input_location
= token
->location
;
815 /* Issue a diagnostic of the form
816 FILE:LINE: MESSAGE before TOKEN
817 where TOKEN is the next token in the input stream of PARSER.
818 MESSAGE (specified by the caller) is usually of the form "expected
821 Do not issue a diagnostic if still recovering from an error.
823 ??? This is taken from the C++ parser, but building up messages in
824 this way is not i18n-friendly and some other approach should be
828 c_parser_error (c_parser
*parser
, const char *gmsgid
)
830 c_token
*token
= c_parser_peek_token (parser
);
833 parser
->error
= true;
836 /* This diagnostic makes more sense if it is tagged to the line of
837 the token we just peeked at. */
838 c_parser_set_source_position_from_token (token
);
839 c_parse_error (gmsgid
,
840 /* Because c_parse_error does not understand
841 CPP_KEYWORD, keywords are treated like
843 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
844 /* ??? The C parser does not save the cpp flags of a
845 token, we need to pass 0 here and we will not get
846 the source spelling of some tokens but rather the
847 canonical spelling. */
848 token
->value
, /*flags=*/0);
851 /* If the next token is of the indicated TYPE, consume it. Otherwise,
852 issue the error MSGID. If MSGID is NULL then a message has already
853 been produced and no message will be produced this time. Returns
854 true if found, false otherwise. */
857 c_parser_require (c_parser
*parser
,
861 if (c_parser_next_token_is (parser
, type
))
863 c_parser_consume_token (parser
);
868 c_parser_error (parser
, msgid
);
873 /* If the next token is the indicated keyword, consume it. Otherwise,
874 issue the error MSGID. Returns true if found, false otherwise. */
877 c_parser_require_keyword (c_parser
*parser
,
881 if (c_parser_next_token_is_keyword (parser
, keyword
))
883 c_parser_consume_token (parser
);
888 c_parser_error (parser
, msgid
);
893 /* Like c_parser_require, except that tokens will be skipped until the
894 desired token is found. An error message is still produced if the
895 next token is not as expected. If MSGID is NULL then a message has
896 already been produced and no message will be produced this
900 c_parser_skip_until_found (c_parser
*parser
,
904 unsigned nesting_depth
= 0;
906 if (c_parser_require (parser
, type
, msgid
))
909 /* Skip tokens until the desired token is found. */
912 /* Peek at the next token. */
913 c_token
*token
= c_parser_peek_token (parser
);
914 /* If we've reached the token we want, consume it and stop. */
915 if (token
->type
== type
&& !nesting_depth
)
917 c_parser_consume_token (parser
);
921 /* If we've run out of tokens, stop. */
922 if (token
->type
== CPP_EOF
)
924 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
926 if (token
->type
== CPP_OPEN_BRACE
927 || token
->type
== CPP_OPEN_PAREN
928 || token
->type
== CPP_OPEN_SQUARE
)
930 else if (token
->type
== CPP_CLOSE_BRACE
931 || token
->type
== CPP_CLOSE_PAREN
932 || token
->type
== CPP_CLOSE_SQUARE
)
934 if (nesting_depth
-- == 0)
937 /* Consume this token. */
938 c_parser_consume_token (parser
);
940 parser
->error
= false;
943 /* Skip tokens until the end of a parameter is found, but do not
944 consume the comma, semicolon or closing delimiter. */
947 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
949 unsigned nesting_depth
= 0;
953 c_token
*token
= c_parser_peek_token (parser
);
954 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
957 /* If we've run out of tokens, stop. */
958 if (token
->type
== CPP_EOF
)
960 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
962 if (token
->type
== CPP_OPEN_BRACE
963 || token
->type
== CPP_OPEN_PAREN
964 || token
->type
== CPP_OPEN_SQUARE
)
966 else if (token
->type
== CPP_CLOSE_BRACE
967 || token
->type
== CPP_CLOSE_PAREN
968 || token
->type
== CPP_CLOSE_SQUARE
)
970 if (nesting_depth
-- == 0)
973 /* Consume this token. */
974 c_parser_consume_token (parser
);
976 parser
->error
= false;
979 /* Expect to be at the end of the pragma directive and consume an
980 end of line marker. */
983 c_parser_skip_to_pragma_eol (c_parser
*parser
)
985 gcc_assert (parser
->in_pragma
);
986 parser
->in_pragma
= false;
988 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
991 c_token
*token
= c_parser_peek_token (parser
);
992 if (token
->type
== CPP_EOF
)
994 if (token
->type
== CPP_PRAGMA_EOL
)
996 c_parser_consume_token (parser
);
999 c_parser_consume_token (parser
);
1002 parser
->error
= false;
1005 /* Skip tokens until we have consumed an entire block, or until we
1006 have consumed a non-nested ';'. */
1009 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1011 unsigned nesting_depth
= 0;
1012 bool save_error
= parser
->error
;
1018 /* Peek at the next token. */
1019 token
= c_parser_peek_token (parser
);
1021 switch (token
->type
)
1026 case CPP_PRAGMA_EOL
:
1027 if (parser
->in_pragma
)
1032 /* If the next token is a ';', we have reached the
1033 end of the statement. */
1036 /* Consume the ';'. */
1037 c_parser_consume_token (parser
);
1042 case CPP_CLOSE_BRACE
:
1043 /* If the next token is a non-nested '}', then we have
1044 reached the end of the current block. */
1045 if (nesting_depth
== 0 || --nesting_depth
== 0)
1047 c_parser_consume_token (parser
);
1052 case CPP_OPEN_BRACE
:
1053 /* If it the next token is a '{', then we are entering a new
1054 block. Consume the entire block. */
1059 /* If we see a pragma, consume the whole thing at once. We
1060 have some safeguards against consuming pragmas willy-nilly.
1061 Normally, we'd expect to be here with parser->error set,
1062 which disables these safeguards. But it's possible to get
1063 here for secondary error recovery, after parser->error has
1065 c_parser_consume_pragma (parser
);
1066 c_parser_skip_to_pragma_eol (parser
);
1067 parser
->error
= save_error
;
1074 c_parser_consume_token (parser
);
1078 parser
->error
= false;
1081 /* CPP's options (initialized by c-opts.c). */
1082 extern cpp_options
*cpp_opts
;
1084 /* Save the warning flags which are controlled by __extension__. */
1087 disable_extension_diagnostics (void)
1090 | (warn_pointer_arith
<< 1)
1091 | (warn_traditional
<< 2)
1093 | (warn_long_long
<< 4)
1094 | (warn_cxx_compat
<< 5)
1095 | (warn_overlength_strings
<< 6)
1096 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1097 play tricks to properly restore it. */
1098 | ((warn_c90_c99_compat
== 1) << 7)
1099 | ((warn_c90_c99_compat
== -1) << 8)
1100 /* Similarly for warn_c99_c11_compat. */
1101 | ((warn_c99_c11_compat
== 1) << 9)
1102 | ((warn_c99_c11_compat
== -1) << 10)
1104 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1105 warn_pointer_arith
= 0;
1106 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1108 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1109 warn_cxx_compat
= 0;
1110 warn_overlength_strings
= 0;
1111 warn_c90_c99_compat
= 0;
1112 warn_c99_c11_compat
= 0;
1116 /* Restore the warning flags which are controlled by __extension__.
1117 FLAGS is the return value from disable_extension_diagnostics. */
1120 restore_extension_diagnostics (int flags
)
1122 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1123 warn_pointer_arith
= (flags
>> 1) & 1;
1124 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1125 flag_iso
= (flags
>> 3) & 1;
1126 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1127 warn_cxx_compat
= (flags
>> 5) & 1;
1128 warn_overlength_strings
= (flags
>> 6) & 1;
1129 /* See above for why is this needed. */
1130 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1131 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1134 /* Possibly kinds of declarator to parse. */
1135 typedef enum c_dtr_syn
{
1136 /* A normal declarator with an identifier. */
1138 /* An abstract declarator (maybe empty). */
1140 /* A parameter declarator: may be either, but after a type name does
1141 not redeclare a typedef name as an identifier if it can
1142 alternatively be interpreted as a typedef name; see DR#009,
1143 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1144 following DR#249. For example, given a typedef T, "int T" and
1145 "int *T" are valid parameter declarations redeclaring T, while
1146 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1147 abstract declarators rather than involving redundant parentheses;
1148 the same applies with attributes inside the parentheses before
1153 /* The binary operation precedence levels, where 0 is a dummy lowest level
1154 used for the bottom of the stack. */
1155 enum c_parser_prec
{
1170 static void c_parser_external_declaration (c_parser
*);
1171 static void c_parser_asm_definition (c_parser
*);
1172 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1173 bool, bool, tree
*, vec
<c_token
>);
1174 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1175 static void c_parser_static_assert_declaration (c_parser
*);
1176 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1177 bool, bool, bool, enum c_lookahead_kind
);
1178 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1179 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1180 static tree
c_parser_struct_declaration (c_parser
*);
1181 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1182 static tree
c_parser_alignas_specifier (c_parser
*);
1183 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1185 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1187 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1189 struct c_declarator
*);
1190 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1191 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1193 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1194 static tree
c_parser_simple_asm_expr (c_parser
*);
1195 static tree
c_parser_attributes (c_parser
*);
1196 static struct c_type_name
*c_parser_type_name (c_parser
*);
1197 static struct c_expr
c_parser_initializer (c_parser
*);
1198 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1199 static void c_parser_initelt (c_parser
*, struct obstack
*);
1200 static void c_parser_initval (c_parser
*, struct c_expr
*,
1202 static tree
c_parser_compound_statement (c_parser
*);
1203 static void c_parser_compound_statement_nostart (c_parser
*);
1204 static void c_parser_label (c_parser
*);
1205 static void c_parser_statement (c_parser
*);
1206 static void c_parser_statement_after_labels (c_parser
*);
1207 static void c_parser_if_statement (c_parser
*);
1208 static void c_parser_switch_statement (c_parser
*);
1209 static void c_parser_while_statement (c_parser
*, bool);
1210 static void c_parser_do_statement (c_parser
*, bool);
1211 static void c_parser_for_statement (c_parser
*, bool);
1212 static tree
c_parser_asm_statement (c_parser
*);
1213 static tree
c_parser_asm_operands (c_parser
*);
1214 static tree
c_parser_asm_goto_operands (c_parser
*);
1215 static tree
c_parser_asm_clobbers (c_parser
*);
1216 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1218 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1219 struct c_expr
*, tree
);
1220 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1222 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1223 static struct c_expr
c_parser_unary_expression (c_parser
*);
1224 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1225 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1226 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1227 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1228 struct c_type_name
*,
1230 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1233 static tree
c_parser_transaction (c_parser
*, enum rid
);
1234 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1235 static tree
c_parser_transaction_cancel (c_parser
*);
1236 static struct c_expr
c_parser_expression (c_parser
*);
1237 static struct c_expr
c_parser_expression_conv (c_parser
*);
1238 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1239 vec
<tree
, va_gc
> **, location_t
*,
1240 tree
*, vec
<location_t
> *,
1241 unsigned int * = NULL
);
1242 static void c_parser_omp_construct (c_parser
*);
1243 static void c_parser_omp_threadprivate (c_parser
*);
1244 static void c_parser_omp_barrier (c_parser
*);
1245 static void c_parser_omp_flush (c_parser
*);
1246 static void c_parser_omp_taskwait (c_parser
*);
1247 static void c_parser_omp_taskyield (c_parser
*);
1248 static void c_parser_omp_cancel (c_parser
*);
1249 static void c_parser_omp_cancellation_point (c_parser
*);
1251 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1252 pragma_stmt
, pragma_compound
};
1253 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1254 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1255 static void c_parser_omp_end_declare_target (c_parser
*);
1256 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1258 /* These Objective-C parser functions are only ever called when
1259 compiling Objective-C. */
1260 static void c_parser_objc_class_definition (c_parser
*, tree
);
1261 static void c_parser_objc_class_instance_variables (c_parser
*);
1262 static void c_parser_objc_class_declaration (c_parser
*);
1263 static void c_parser_objc_alias_declaration (c_parser
*);
1264 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1265 static bool c_parser_objc_method_type (c_parser
*);
1266 static void c_parser_objc_method_definition (c_parser
*);
1267 static void c_parser_objc_methodprotolist (c_parser
*);
1268 static void c_parser_objc_methodproto (c_parser
*);
1269 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1270 static tree
c_parser_objc_type_name (c_parser
*);
1271 static tree
c_parser_objc_protocol_refs (c_parser
*);
1272 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1273 static void c_parser_objc_synchronized_statement (c_parser
*);
1274 static tree
c_parser_objc_selector (c_parser
*);
1275 static tree
c_parser_objc_selector_arg (c_parser
*);
1276 static tree
c_parser_objc_receiver (c_parser
*);
1277 static tree
c_parser_objc_message_args (c_parser
*);
1278 static tree
c_parser_objc_keywordexpr (c_parser
*);
1279 static void c_parser_objc_at_property_declaration (c_parser
*);
1280 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1281 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1282 static bool c_parser_objc_diagnose_bad_element_prefix
1283 (c_parser
*, struct c_declspecs
*);
1285 /* Cilk Plus supporting routines. */
1286 static void c_parser_cilk_simd (c_parser
*);
1287 static void c_parser_cilk_for (c_parser
*, tree
);
1288 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1289 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1290 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1291 static void c_parser_cilk_grainsize (c_parser
*);
1293 /* Parse a translation unit (C90 6.7, C99 6.9).
1296 external-declarations
1298 external-declarations:
1299 external-declaration
1300 external-declarations external-declaration
1309 c_parser_translation_unit (c_parser
*parser
)
1311 if (c_parser_next_token_is (parser
, CPP_EOF
))
1313 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1314 "ISO C forbids an empty translation unit");
1318 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1319 mark_valid_location_for_stdc_pragma (false);
1323 c_parser_external_declaration (parser
);
1324 obstack_free (&parser_obstack
, obstack_position
);
1326 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1330 /* Parse an external declaration (C90 6.7, C99 6.9).
1332 external-declaration:
1338 external-declaration:
1341 __extension__ external-declaration
1345 external-declaration:
1346 objc-class-definition
1347 objc-class-declaration
1348 objc-alias-declaration
1349 objc-protocol-definition
1350 objc-method-definition
1355 c_parser_external_declaration (c_parser
*parser
)
1358 switch (c_parser_peek_token (parser
)->type
)
1361 switch (c_parser_peek_token (parser
)->keyword
)
1364 ext
= disable_extension_diagnostics ();
1365 c_parser_consume_token (parser
);
1366 c_parser_external_declaration (parser
);
1367 restore_extension_diagnostics (ext
);
1370 c_parser_asm_definition (parser
);
1372 case RID_AT_INTERFACE
:
1373 case RID_AT_IMPLEMENTATION
:
1374 gcc_assert (c_dialect_objc ());
1375 c_parser_objc_class_definition (parser
, NULL_TREE
);
1378 gcc_assert (c_dialect_objc ());
1379 c_parser_objc_class_declaration (parser
);
1382 gcc_assert (c_dialect_objc ());
1383 c_parser_objc_alias_declaration (parser
);
1385 case RID_AT_PROTOCOL
:
1386 gcc_assert (c_dialect_objc ());
1387 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1389 case RID_AT_PROPERTY
:
1390 gcc_assert (c_dialect_objc ());
1391 c_parser_objc_at_property_declaration (parser
);
1393 case RID_AT_SYNTHESIZE
:
1394 gcc_assert (c_dialect_objc ());
1395 c_parser_objc_at_synthesize_declaration (parser
);
1397 case RID_AT_DYNAMIC
:
1398 gcc_assert (c_dialect_objc ());
1399 c_parser_objc_at_dynamic_declaration (parser
);
1402 gcc_assert (c_dialect_objc ());
1403 c_parser_consume_token (parser
);
1404 objc_finish_implementation ();
1411 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1412 "ISO C does not allow extra %<;%> outside of a function");
1413 c_parser_consume_token (parser
);
1416 mark_valid_location_for_stdc_pragma (true);
1417 c_parser_pragma (parser
, pragma_external
);
1418 mark_valid_location_for_stdc_pragma (false);
1422 if (c_dialect_objc ())
1424 c_parser_objc_method_definition (parser
);
1427 /* Else fall through, and yield a syntax error trying to parse
1428 as a declaration or function definition. */
1431 /* A declaration or a function definition (or, in Objective-C,
1432 an @interface or @protocol with prefix attributes). We can
1433 only tell which after parsing the declaration specifiers, if
1434 any, and the first declarator. */
1435 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1441 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1443 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1444 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1445 accepted; otherwise (old-style parameter declarations) only other
1446 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1447 assertion is accepted; otherwise (old-style parameter declarations)
1448 it is not. If NESTED is true, we are inside a function or parsing
1449 old-style parameter declarations; any functions encountered are
1450 nested functions and declaration specifiers are required; otherwise
1451 we are at top level and functions are normal functions and
1452 declaration specifiers may be optional. If EMPTY_OK is true, empty
1453 declarations are OK (subject to all other constraints); otherwise
1454 (old-style parameter declarations) they are diagnosed. If
1455 START_ATTR_OK is true, the declaration specifiers may start with
1456 attributes; otherwise they may not.
1457 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1458 declaration when parsing an Objective-C foreach statement.
1461 declaration-specifiers init-declarator-list[opt] ;
1462 static_assert-declaration
1464 function-definition:
1465 declaration-specifiers[opt] declarator declaration-list[opt]
1470 declaration-list declaration
1472 init-declarator-list:
1474 init-declarator-list , init-declarator
1477 declarator simple-asm-expr[opt] attributes[opt]
1478 declarator simple-asm-expr[opt] attributes[opt] = initializer
1482 nested-function-definition:
1483 declaration-specifiers declarator declaration-list[opt]
1487 attributes objc-class-definition
1488 attributes objc-category-definition
1489 attributes objc-protocol-definition
1491 The simple-asm-expr and attributes are GNU extensions.
1493 This function does not handle __extension__; that is handled in its
1494 callers. ??? Following the old parser, __extension__ may start
1495 external declarations, declarations in functions and declarations
1496 at the start of "for" loops, but not old-style parameter
1499 C99 requires declaration specifiers in a function definition; the
1500 absence is diagnosed through the diagnosis of implicit int. In GNU
1501 C we also allow but diagnose declarations without declaration
1502 specifiers, but only at top level (elsewhere they conflict with
1505 In Objective-C, declarations of the looping variable in a foreach
1506 statement are exceptionally terminated by 'in' (for example, 'for
1507 (NSObject *object in array) { ... }').
1512 threadprivate-directive */
1515 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1516 bool static_assert_ok
, bool empty_ok
,
1517 bool nested
, bool start_attr_ok
,
1518 tree
*objc_foreach_object_declaration
,
1519 vec
<c_token
> omp_declare_simd_clauses
)
1521 struct c_declspecs
*specs
;
1523 tree all_prefix_attrs
;
1524 bool diagnosed_no_specs
= false;
1525 location_t here
= c_parser_peek_token (parser
)->location
;
1527 if (static_assert_ok
1528 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1530 c_parser_static_assert_declaration (parser
);
1533 specs
= build_null_declspecs ();
1535 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1536 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1537 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1538 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1539 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1540 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1542 error_at (here
, "unknown type name %qE",
1543 c_parser_peek_token (parser
)->value
);
1545 /* Parse declspecs normally to get a correct pointer type, but avoid
1546 a further "fails to be a type name" error. Refuse nested functions
1547 since it is not how the user likely wants us to recover. */
1548 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1549 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1550 c_parser_peek_token (parser
)->value
= error_mark_node
;
1554 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1555 true, true, cla_nonabstract_decl
);
1558 c_parser_skip_to_end_of_block_or_statement (parser
);
1561 if (nested
&& !specs
->declspecs_seen_p
)
1563 c_parser_error (parser
, "expected declaration specifiers");
1564 c_parser_skip_to_end_of_block_or_statement (parser
);
1567 finish_declspecs (specs
);
1568 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1569 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1572 error_at (here
, "%<__auto_type%> in empty declaration");
1577 shadow_tag_warned (specs
, 1);
1578 pedwarn (here
, 0, "empty declaration");
1580 c_parser_consume_token (parser
);
1584 /* Provide better error recovery. Note that a type name here is usually
1585 better diagnosed as a redeclaration. */
1587 && specs
->typespec_kind
== ctsk_tagdef
1588 && c_parser_next_token_starts_declspecs (parser
)
1589 && !c_parser_next_token_is (parser
, CPP_NAME
))
1591 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1592 parser
->error
= false;
1593 shadow_tag_warned (specs
, 1);
1596 else if (c_dialect_objc () && !auto_type_p
)
1598 /* Prefix attributes are an error on method decls. */
1599 switch (c_parser_peek_token (parser
)->type
)
1603 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1607 warning_at (c_parser_peek_token (parser
)->location
,
1609 "prefix attributes are ignored for methods");
1610 specs
->attrs
= NULL_TREE
;
1613 c_parser_objc_method_definition (parser
);
1615 c_parser_objc_methodproto (parser
);
1621 /* This is where we parse 'attributes @interface ...',
1622 'attributes @implementation ...', 'attributes @protocol ...'
1623 (where attributes could be, for example, __attribute__
1626 switch (c_parser_peek_token (parser
)->keyword
)
1628 case RID_AT_INTERFACE
:
1630 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1632 c_parser_objc_class_definition (parser
, specs
->attrs
);
1636 case RID_AT_IMPLEMENTATION
:
1638 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1642 warning_at (c_parser_peek_token (parser
)->location
,
1644 "prefix attributes are ignored for implementations");
1645 specs
->attrs
= NULL_TREE
;
1647 c_parser_objc_class_definition (parser
, NULL_TREE
);
1651 case RID_AT_PROTOCOL
:
1653 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1655 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1662 case RID_AT_PROPERTY
:
1665 c_parser_error (parser
, "unexpected attribute");
1666 specs
->attrs
= NULL
;
1674 pending_xref_error ();
1675 prefix_attrs
= specs
->attrs
;
1676 all_prefix_attrs
= prefix_attrs
;
1677 specs
->attrs
= NULL_TREE
;
1680 struct c_declarator
*declarator
;
1684 /* Declaring either one or more declarators (in which case we
1685 should diagnose if there were no declaration specifiers) or a
1686 function definition (in which case the diagnostic for
1687 implicit int suffices). */
1688 declarator
= c_parser_declarator (parser
,
1689 specs
->typespec_kind
!= ctsk_none
,
1690 C_DTR_NORMAL
, &dummy
);
1691 if (declarator
== NULL
)
1693 if (omp_declare_simd_clauses
.exists ()
1694 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1695 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1696 omp_declare_simd_clauses
);
1697 c_parser_skip_to_end_of_block_or_statement (parser
);
1700 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1703 "%<__auto_type%> requires a plain identifier"
1705 c_parser_skip_to_end_of_block_or_statement (parser
);
1708 if (c_parser_next_token_is (parser
, CPP_EQ
)
1709 || c_parser_next_token_is (parser
, CPP_COMMA
)
1710 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1711 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1712 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1713 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1715 tree asm_name
= NULL_TREE
;
1716 tree postfix_attrs
= NULL_TREE
;
1717 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1719 diagnosed_no_specs
= true;
1720 pedwarn (here
, 0, "data definition has no type or storage class");
1722 /* Having seen a data definition, there cannot now be a
1723 function definition. */
1725 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1726 asm_name
= c_parser_simple_asm_expr (parser
);
1727 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1729 postfix_attrs
= c_parser_attributes (parser
);
1730 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1732 /* This means there is an attribute specifier after
1733 the declarator in a function definition. Provide
1734 some more information for the user. */
1735 error_at (here
, "attributes should be specified before the "
1736 "declarator in a function definition");
1737 c_parser_skip_to_end_of_block_or_statement (parser
);
1741 if (c_parser_next_token_is (parser
, CPP_EQ
))
1745 location_t init_loc
;
1746 c_parser_consume_token (parser
);
1749 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1750 init_loc
= c_parser_peek_token (parser
)->location
;
1751 init
= c_parser_expr_no_commas (parser
, NULL
);
1752 if (TREE_CODE (init
.value
) == COMPONENT_REF
1753 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1755 "%<__auto_type%> used with a bit-field"
1757 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1758 tree init_type
= TREE_TYPE (init
.value
);
1759 /* As with typeof, remove all qualifiers from atomic types. */
1760 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1762 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1763 bool vm_type
= variably_modified_type_p (init_type
,
1766 init
.value
= c_save_expr (init
.value
);
1768 specs
->typespec_kind
= ctsk_typeof
;
1769 specs
->locations
[cdw_typedef
] = init_loc
;
1770 specs
->typedef_p
= true;
1771 specs
->type
= init_type
;
1774 bool maybe_const
= true;
1775 tree type_expr
= c_fully_fold (init
.value
, false,
1777 specs
->expr_const_operands
&= maybe_const
;
1779 specs
->expr
= build2 (COMPOUND_EXPR
,
1780 TREE_TYPE (type_expr
),
1781 specs
->expr
, type_expr
);
1783 specs
->expr
= type_expr
;
1785 d
= start_decl (declarator
, specs
, true,
1786 chainon (postfix_attrs
, all_prefix_attrs
));
1788 d
= error_mark_node
;
1789 if (omp_declare_simd_clauses
.exists ()
1790 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1791 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1792 omp_declare_simd_clauses
);
1796 /* The declaration of the variable is in effect while
1797 its initializer is parsed. */
1798 d
= start_decl (declarator
, specs
, true,
1799 chainon (postfix_attrs
, all_prefix_attrs
));
1801 d
= error_mark_node
;
1802 if (omp_declare_simd_clauses
.exists ()
1803 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1804 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1805 omp_declare_simd_clauses
);
1806 start_init (d
, asm_name
, global_bindings_p ());
1807 init_loc
= c_parser_peek_token (parser
)->location
;
1808 init
= c_parser_initializer (parser
);
1811 if (d
!= error_mark_node
)
1813 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1814 finish_decl (d
, init_loc
, init
.value
,
1815 init
.original_type
, asm_name
);
1823 "%<__auto_type%> requires an initialized "
1824 "data declaration");
1825 c_parser_skip_to_end_of_block_or_statement (parser
);
1828 tree d
= start_decl (declarator
, specs
, false,
1829 chainon (postfix_attrs
,
1831 if (omp_declare_simd_clauses
.exists ()
1832 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1834 tree parms
= NULL_TREE
;
1835 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1837 struct c_declarator
*ce
= declarator
;
1839 if (ce
->kind
== cdk_function
)
1841 parms
= ce
->u
.arg_info
->parms
;
1845 ce
= ce
->declarator
;
1848 temp_store_parm_decls (d
, parms
);
1849 c_finish_omp_declare_simd (parser
, d
, parms
,
1850 omp_declare_simd_clauses
);
1852 temp_pop_parm_decls ();
1855 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1856 NULL_TREE
, asm_name
);
1858 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1861 *objc_foreach_object_declaration
= d
;
1863 *objc_foreach_object_declaration
= error_mark_node
;
1866 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1871 "%<__auto_type%> may only be used with"
1872 " a single declarator");
1873 c_parser_skip_to_end_of_block_or_statement (parser
);
1876 c_parser_consume_token (parser
);
1877 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1878 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1881 all_prefix_attrs
= prefix_attrs
;
1884 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1886 c_parser_consume_token (parser
);
1889 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1891 /* This can only happen in Objective-C: we found the
1892 'in' that terminates the declaration inside an
1893 Objective-C foreach statement. Do not consume the
1894 token, so that the caller can use it to determine
1895 that this indeed is a foreach context. */
1900 c_parser_error (parser
, "expected %<,%> or %<;%>");
1901 c_parser_skip_to_end_of_block_or_statement (parser
);
1905 else if (auto_type_p
)
1908 "%<__auto_type%> requires an initialized data declaration");
1909 c_parser_skip_to_end_of_block_or_statement (parser
);
1914 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1915 "%<asm%> or %<__attribute__%>");
1916 c_parser_skip_to_end_of_block_or_statement (parser
);
1919 /* Function definition (nested or otherwise). */
1922 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1923 c_push_function_context ();
1925 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1927 /* This can appear in many cases looking nothing like a
1928 function definition, so we don't give a more specific
1929 error suggesting there was one. */
1930 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1931 "or %<__attribute__%>");
1933 c_pop_function_context ();
1937 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1938 tv
= TV_PARSE_INLINE
;
1943 /* Parse old-style parameter declarations. ??? Attributes are
1944 not allowed to start declaration specifiers here because of a
1945 syntax conflict between a function declaration with attribute
1946 suffix and a function definition with an attribute prefix on
1947 first old-style parameter declaration. Following the old
1948 parser, they are not accepted on subsequent old-style
1949 parameter declarations either. However, there is no
1950 ambiguity after the first declaration, nor indeed on the
1951 first as long as we don't allow postfix attributes after a
1952 declarator with a nonempty identifier list in a definition;
1953 and postfix attributes have never been accepted here in
1954 function definitions either. */
1955 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1956 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1957 c_parser_declaration_or_fndef (parser
, false, false, false,
1958 true, false, NULL
, vNULL
);
1959 store_parm_decls ();
1960 if (omp_declare_simd_clauses
.exists ()
1961 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1962 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1963 omp_declare_simd_clauses
);
1964 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1965 = c_parser_peek_token (parser
)->location
;
1966 fnbody
= c_parser_compound_statement (parser
);
1967 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1968 fnbody
= expand_array_notation_exprs (fnbody
);
1971 tree decl
= current_function_decl
;
1972 /* Mark nested functions as needing static-chain initially.
1973 lower_nested_functions will recompute it but the
1974 DECL_STATIC_CHAIN flag is also used before that happens,
1975 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1976 DECL_STATIC_CHAIN (decl
) = 1;
1979 c_pop_function_context ();
1980 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1993 /* Parse an asm-definition (asm() outside a function body). This is a
2001 c_parser_asm_definition (c_parser
*parser
)
2003 tree asm_str
= c_parser_simple_asm_expr (parser
);
2005 symtab
->finalize_toplevel_asm (asm_str
);
2006 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2009 /* Parse a static assertion (C11 6.7.10).
2011 static_assert-declaration:
2012 static_assert-declaration-no-semi ;
2016 c_parser_static_assert_declaration (c_parser
*parser
)
2018 c_parser_static_assert_declaration_no_semi (parser
);
2020 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2021 c_parser_skip_to_end_of_block_or_statement (parser
);
2024 /* Parse a static assertion (C11 6.7.10), without the trailing
2027 static_assert-declaration-no-semi:
2028 _Static_assert ( constant-expression , string-literal )
2032 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2034 location_t assert_loc
, value_loc
;
2038 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2039 assert_loc
= c_parser_peek_token (parser
)->location
;
2041 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2042 "ISO C99 does not support %<_Static_assert%>");
2044 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2045 "ISO C90 does not support %<_Static_assert%>");
2046 c_parser_consume_token (parser
);
2047 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2049 value_loc
= c_parser_peek_token (parser
)->location
;
2050 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2051 parser
->lex_untranslated_string
= true;
2052 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2054 parser
->lex_untranslated_string
= false;
2057 switch (c_parser_peek_token (parser
)->type
)
2063 case CPP_UTF8STRING
:
2064 string
= c_parser_peek_token (parser
)->value
;
2065 c_parser_consume_token (parser
);
2066 parser
->lex_untranslated_string
= false;
2069 c_parser_error (parser
, "expected string literal");
2070 parser
->lex_untranslated_string
= false;
2073 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2075 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2077 error_at (value_loc
, "expression in static assertion is not an integer");
2080 if (TREE_CODE (value
) != INTEGER_CST
)
2082 value
= c_fully_fold (value
, false, NULL
);
2083 /* Strip no-op conversions. */
2084 STRIP_TYPE_NOPS (value
);
2085 if (TREE_CODE (value
) == INTEGER_CST
)
2086 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2087 "is not an integer constant expression");
2089 if (TREE_CODE (value
) != INTEGER_CST
)
2091 error_at (value_loc
, "expression in static assertion is not constant");
2094 constant_expression_warning (value
);
2095 if (integer_zerop (value
))
2096 error_at (assert_loc
, "static assertion failed: %E", string
);
2099 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2100 6.7), adding them to SPECS (which may already include some).
2101 Storage class specifiers are accepted iff SCSPEC_OK; type
2102 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2103 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2104 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2106 declaration-specifiers:
2107 storage-class-specifier declaration-specifiers[opt]
2108 type-specifier declaration-specifiers[opt]
2109 type-qualifier declaration-specifiers[opt]
2110 function-specifier declaration-specifiers[opt]
2111 alignment-specifier declaration-specifiers[opt]
2113 Function specifiers (inline) are from C99, and are currently
2114 handled as storage class specifiers, as is __thread. Alignment
2115 specifiers are from C11.
2117 C90 6.5.1, C99 6.7.1:
2118 storage-class-specifier:
2126 (_Thread_local is new in C11.)
2133 (_Noreturn is new in C11.)
2135 C90 6.5.2, C99 6.7.2:
2148 [_Imaginary removed in C99 TC2]
2149 struct-or-union-specifier
2152 atomic-type-specifier
2154 (_Bool and _Complex are new in C99.)
2155 (atomic-type-specifier is new in C11.)
2157 C90 6.5.3, C99 6.7.3:
2163 address-space-qualifier
2166 (restrict is new in C99.)
2167 (_Atomic is new in C11.)
2171 declaration-specifiers:
2172 attributes declaration-specifiers[opt]
2178 identifier recognized by the target
2180 storage-class-specifier:
2194 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2195 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2197 atomic-type-specifier
2198 _Atomic ( type-name )
2203 class-name objc-protocol-refs[opt]
2204 typedef-name objc-protocol-refs
2209 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2210 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2211 bool alignspec_ok
, bool auto_type_ok
,
2212 enum c_lookahead_kind la
)
2214 bool attrs_ok
= start_attr_ok
;
2215 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2218 gcc_assert (la
== cla_prefer_id
);
2220 while (c_parser_next_token_is (parser
, CPP_NAME
)
2221 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2222 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2224 struct c_typespec t
;
2227 location_t loc
= c_parser_peek_token (parser
)->location
;
2229 /* If we cannot accept a type, exit if the next token must start
2230 one. Also, if we already have seen a tagged definition,
2231 a typename would be an error anyway and likely the user
2232 has simply forgotten a semicolon, so we exit. */
2233 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2234 && c_parser_next_tokens_start_typename (parser
, la
)
2235 && !c_parser_next_token_is_qualifier (parser
))
2238 if (c_parser_next_token_is (parser
, CPP_NAME
))
2240 c_token
*name_token
= c_parser_peek_token (parser
);
2241 tree value
= name_token
->value
;
2242 c_id_kind kind
= name_token
->id_kind
;
2244 if (kind
== C_ID_ADDRSPACE
)
2247 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2248 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2249 c_parser_consume_token (parser
);
2254 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2256 /* If we cannot accept a type, and the next token must start one,
2257 exit. Do the same if we already have seen a tagged definition,
2258 since it would be an error anyway and likely the user has simply
2259 forgotten a semicolon. */
2260 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2263 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2264 a C_ID_CLASSNAME. */
2265 c_parser_consume_token (parser
);
2268 if (kind
== C_ID_ID
)
2270 error_at (loc
, "unknown type name %qE", value
);
2271 t
.kind
= ctsk_typedef
;
2272 t
.spec
= error_mark_node
;
2274 else if (kind
== C_ID_TYPENAME
2275 && (!c_dialect_objc ()
2276 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2278 t
.kind
= ctsk_typedef
;
2279 /* For a typedef name, record the meaning, not the name.
2280 In case of 'foo foo, bar;'. */
2281 t
.spec
= lookup_name (value
);
2285 tree proto
= NULL_TREE
;
2286 gcc_assert (c_dialect_objc ());
2288 if (c_parser_next_token_is (parser
, CPP_LESS
))
2289 proto
= c_parser_objc_protocol_refs (parser
);
2290 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2293 t
.expr_const_operands
= true;
2294 declspecs_add_type (name_token
->location
, specs
, t
);
2297 if (c_parser_next_token_is (parser
, CPP_LESS
))
2299 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2300 nisse@lysator.liu.se. */
2302 gcc_assert (c_dialect_objc ());
2303 if (!typespec_ok
|| seen_type
)
2305 proto
= c_parser_objc_protocol_refs (parser
);
2307 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2309 t
.expr_const_operands
= true;
2310 declspecs_add_type (loc
, specs
, t
);
2313 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2314 switch (c_parser_peek_token (parser
)->keyword
)
2327 /* TODO: Distinguish between function specifiers (inline, noreturn)
2328 and storage class specifiers, either here or in
2329 declspecs_add_scspec. */
2330 declspecs_add_scspec (loc
, specs
,
2331 c_parser_peek_token (parser
)->value
);
2332 c_parser_consume_token (parser
);
2363 if (c_dialect_objc ())
2364 parser
->objc_need_raw_identifier
= true;
2365 t
.kind
= ctsk_resword
;
2366 t
.spec
= c_parser_peek_token (parser
)->value
;
2368 t
.expr_const_operands
= true;
2369 declspecs_add_type (loc
, specs
, t
);
2370 c_parser_consume_token (parser
);
2377 t
= c_parser_enum_specifier (parser
);
2378 declspecs_add_type (loc
, specs
, t
);
2386 t
= c_parser_struct_or_union_specifier (parser
);
2387 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2388 declspecs_add_type (loc
, specs
, t
);
2391 /* ??? The old parser rejected typeof after other type
2392 specifiers, but is a syntax error the best way of
2394 if (!typespec_ok
|| seen_type
)
2398 t
= c_parser_typeof_specifier (parser
);
2399 declspecs_add_type (loc
, specs
, t
);
2402 /* C parser handling of Objective-C constructs needs
2403 checking for correct lvalue-to-rvalue conversions, and
2404 the code in build_modify_expr handling various
2405 Objective-C cases, and that in build_unary_op handling
2406 Objective-C cases for increment / decrement, also needs
2407 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2408 and objc_types_are_equivalent may also need updates. */
2409 if (c_dialect_objc ())
2410 sorry ("%<_Atomic%> in Objective-C");
2411 /* C parser handling of OpenMP constructs needs checking for
2412 correct lvalue-to-rvalue conversions. */
2414 sorry ("%<_Atomic%> with OpenMP");
2416 pedwarn_c99 (loc
, OPT_Wpedantic
,
2417 "ISO C99 does not support the %<_Atomic%> qualifier");
2419 pedwarn_c99 (loc
, OPT_Wpedantic
,
2420 "ISO C90 does not support the %<_Atomic%> qualifier");
2423 value
= c_parser_peek_token (parser
)->value
;
2424 c_parser_consume_token (parser
);
2425 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2427 /* _Atomic ( type-name ). */
2429 c_parser_consume_token (parser
);
2430 struct c_type_name
*type
= c_parser_type_name (parser
);
2431 t
.kind
= ctsk_typeof
;
2432 t
.spec
= error_mark_node
;
2434 t
.expr_const_operands
= true;
2436 t
.spec
= groktypename (type
, &t
.expr
,
2437 &t
.expr_const_operands
);
2438 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2440 if (t
.spec
!= error_mark_node
)
2442 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2443 error_at (loc
, "%<_Atomic%>-qualified array type");
2444 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2445 error_at (loc
, "%<_Atomic%>-qualified function type");
2446 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2447 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2449 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2451 declspecs_add_type (loc
, specs
, t
);
2454 declspecs_add_qual (loc
, specs
, value
);
2460 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2461 c_parser_consume_token (parser
);
2466 attrs
= c_parser_attributes (parser
);
2467 declspecs_add_attrs (loc
, specs
, attrs
);
2472 align
= c_parser_alignas_specifier (parser
);
2473 declspecs_add_alignas (loc
, specs
, align
);
2482 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2485 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2486 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2487 enum attributes[opt] identifier
2489 The form with trailing comma is new in C99. The forms with
2490 attributes are GNU extensions. In GNU C, we accept any expression
2491 without commas in the syntax (assignment expressions, not just
2492 conditional expressions); assignment expressions will be diagnosed
2497 enumerator-list , enumerator
2500 enumeration-constant
2501 enumeration-constant = constant-expression
2504 static struct c_typespec
2505 c_parser_enum_specifier (c_parser
*parser
)
2507 struct c_typespec ret
;
2509 tree ident
= NULL_TREE
;
2510 location_t enum_loc
;
2511 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2512 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2513 enum_loc
= c_parser_peek_token (parser
)->location
;
2514 c_parser_consume_token (parser
);
2515 attrs
= c_parser_attributes (parser
);
2516 enum_loc
= c_parser_peek_token (parser
)->location
;
2517 /* Set the location in case we create a decl now. */
2518 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2519 if (c_parser_next_token_is (parser
, CPP_NAME
))
2521 ident
= c_parser_peek_token (parser
)->value
;
2522 ident_loc
= c_parser_peek_token (parser
)->location
;
2523 enum_loc
= ident_loc
;
2524 c_parser_consume_token (parser
);
2526 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2528 /* Parse an enum definition. */
2529 struct c_enum_contents the_enum
;
2532 /* We chain the enumerators in reverse order, then put them in
2533 forward order at the end. */
2535 timevar_push (TV_PARSE_ENUM
);
2536 type
= start_enum (enum_loc
, &the_enum
, ident
);
2538 c_parser_consume_token (parser
);
2546 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2547 location_t decl_loc
, value_loc
;
2548 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2550 c_parser_error (parser
, "expected identifier");
2551 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2552 values
= error_mark_node
;
2555 token
= c_parser_peek_token (parser
);
2556 enum_id
= token
->value
;
2557 /* Set the location in case we create a decl now. */
2558 c_parser_set_source_position_from_token (token
);
2559 decl_loc
= value_loc
= token
->location
;
2560 c_parser_consume_token (parser
);
2561 if (c_parser_next_token_is (parser
, CPP_EQ
))
2563 c_parser_consume_token (parser
);
2564 value_loc
= c_parser_peek_token (parser
)->location
;
2565 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2568 enum_value
= NULL_TREE
;
2569 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2570 &the_enum
, enum_id
, enum_value
);
2571 TREE_CHAIN (enum_decl
) = values
;
2574 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2576 comma_loc
= c_parser_peek_token (parser
)->location
;
2578 c_parser_consume_token (parser
);
2580 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2583 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2584 "comma at end of enumerator list");
2585 c_parser_consume_token (parser
);
2590 c_parser_error (parser
, "expected %<,%> or %<}%>");
2591 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2592 values
= error_mark_node
;
2596 postfix_attrs
= c_parser_attributes (parser
);
2597 ret
.spec
= finish_enum (type
, nreverse (values
),
2598 chainon (attrs
, postfix_attrs
));
2599 ret
.kind
= ctsk_tagdef
;
2600 ret
.expr
= NULL_TREE
;
2601 ret
.expr_const_operands
= true;
2602 timevar_pop (TV_PARSE_ENUM
);
2607 c_parser_error (parser
, "expected %<{%>");
2608 ret
.spec
= error_mark_node
;
2609 ret
.kind
= ctsk_tagref
;
2610 ret
.expr
= NULL_TREE
;
2611 ret
.expr_const_operands
= true;
2614 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2615 /* In ISO C, enumerated types can be referred to only if already
2617 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2620 pedwarn (enum_loc
, OPT_Wpedantic
,
2621 "ISO C forbids forward references to %<enum%> types");
2626 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2628 struct-or-union-specifier:
2629 struct-or-union attributes[opt] identifier[opt]
2630 { struct-contents } attributes[opt]
2631 struct-or-union attributes[opt] identifier
2634 struct-declaration-list
2636 struct-declaration-list:
2637 struct-declaration ;
2638 struct-declaration-list struct-declaration ;
2645 struct-declaration-list struct-declaration
2647 struct-declaration-list:
2648 struct-declaration-list ;
2651 (Note that in the syntax here, unlike that in ISO C, the semicolons
2652 are included here rather than in struct-declaration, in order to
2653 describe the syntax with extra semicolons and missing semicolon at
2658 struct-declaration-list:
2659 @defs ( class-name )
2661 (Note this does not include a trailing semicolon, but can be
2662 followed by further declarations, and gets a pedwarn-if-pedantic
2663 when followed by a semicolon.) */
2665 static struct c_typespec
2666 c_parser_struct_or_union_specifier (c_parser
*parser
)
2668 struct c_typespec ret
;
2670 tree ident
= NULL_TREE
;
2671 location_t struct_loc
;
2672 location_t ident_loc
= UNKNOWN_LOCATION
;
2673 enum tree_code code
;
2674 switch (c_parser_peek_token (parser
)->keyword
)
2685 struct_loc
= c_parser_peek_token (parser
)->location
;
2686 c_parser_consume_token (parser
);
2687 attrs
= c_parser_attributes (parser
);
2689 /* Set the location in case we create a decl now. */
2690 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2692 if (c_parser_next_token_is (parser
, CPP_NAME
))
2694 ident
= c_parser_peek_token (parser
)->value
;
2695 ident_loc
= c_parser_peek_token (parser
)->location
;
2696 struct_loc
= ident_loc
;
2697 c_parser_consume_token (parser
);
2699 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2701 /* Parse a struct or union definition. Start the scope of the
2702 tag before parsing components. */
2703 struct c_struct_parse_info
*struct_info
;
2704 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2706 /* We chain the components in reverse order, then put them in
2707 forward order at the end. Each struct-declaration may
2708 declare multiple components (comma-separated), so we must use
2709 chainon to join them, although when parsing each
2710 struct-declaration we can use TREE_CHAIN directly.
2712 The theory behind all this is that there will be more
2713 semicolon separated fields than comma separated fields, and
2714 so we'll be minimizing the number of node traversals required
2717 timevar_push (TV_PARSE_STRUCT
);
2718 contents
= NULL_TREE
;
2719 c_parser_consume_token (parser
);
2720 /* Handle the Objective-C @defs construct,
2721 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2722 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2725 gcc_assert (c_dialect_objc ());
2726 c_parser_consume_token (parser
);
2727 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2729 if (c_parser_next_token_is (parser
, CPP_NAME
)
2730 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2732 name
= c_parser_peek_token (parser
)->value
;
2733 c_parser_consume_token (parser
);
2737 c_parser_error (parser
, "expected class name");
2738 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2741 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2743 contents
= nreverse (objc_get_class_ivars (name
));
2746 /* Parse the struct-declarations and semicolons. Problems with
2747 semicolons are diagnosed here; empty structures are diagnosed
2752 /* Parse any stray semicolon. */
2753 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2755 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2756 "extra semicolon in struct or union specified");
2757 c_parser_consume_token (parser
);
2760 /* Stop if at the end of the struct or union contents. */
2761 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2763 c_parser_consume_token (parser
);
2766 /* Accept #pragmas at struct scope. */
2767 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2769 c_parser_pragma (parser
, pragma_struct
);
2772 /* Parse some comma-separated declarations, but not the
2773 trailing semicolon if any. */
2774 decls
= c_parser_struct_declaration (parser
);
2775 contents
= chainon (decls
, contents
);
2776 /* If no semicolon follows, either we have a parse error or
2777 are at the end of the struct or union and should
2779 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2780 c_parser_consume_token (parser
);
2783 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2784 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2785 "no semicolon at end of struct or union");
2786 else if (parser
->error
2787 || !c_parser_next_token_starts_declspecs (parser
))
2789 c_parser_error (parser
, "expected %<;%>");
2790 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2794 /* If we come here, we have already emitted an error
2795 for an expected `;', identifier or `(', and we also
2796 recovered already. Go on with the next field. */
2799 postfix_attrs
= c_parser_attributes (parser
);
2800 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2801 chainon (attrs
, postfix_attrs
), struct_info
);
2802 ret
.kind
= ctsk_tagdef
;
2803 ret
.expr
= NULL_TREE
;
2804 ret
.expr_const_operands
= true;
2805 timevar_pop (TV_PARSE_STRUCT
);
2810 c_parser_error (parser
, "expected %<{%>");
2811 ret
.spec
= error_mark_node
;
2812 ret
.kind
= ctsk_tagref
;
2813 ret
.expr
= NULL_TREE
;
2814 ret
.expr_const_operands
= true;
2817 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2821 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2822 the trailing semicolon.
2825 specifier-qualifier-list struct-declarator-list
2826 static_assert-declaration-no-semi
2828 specifier-qualifier-list:
2829 type-specifier specifier-qualifier-list[opt]
2830 type-qualifier specifier-qualifier-list[opt]
2831 attributes specifier-qualifier-list[opt]
2833 struct-declarator-list:
2835 struct-declarator-list , attributes[opt] struct-declarator
2838 declarator attributes[opt]
2839 declarator[opt] : constant-expression attributes[opt]
2844 __extension__ struct-declaration
2845 specifier-qualifier-list
2847 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2848 of attributes where shown is a GNU extension. In GNU C, we accept
2849 any expression without commas in the syntax (assignment
2850 expressions, not just conditional expressions); assignment
2851 expressions will be diagnosed as non-constant. */
2854 c_parser_struct_declaration (c_parser
*parser
)
2856 struct c_declspecs
*specs
;
2858 tree all_prefix_attrs
;
2860 location_t decl_loc
;
2861 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2865 ext
= disable_extension_diagnostics ();
2866 c_parser_consume_token (parser
);
2867 decl
= c_parser_struct_declaration (parser
);
2868 restore_extension_diagnostics (ext
);
2871 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2873 c_parser_static_assert_declaration_no_semi (parser
);
2876 specs
= build_null_declspecs ();
2877 decl_loc
= c_parser_peek_token (parser
)->location
;
2878 /* Strictly by the standard, we shouldn't allow _Alignas here,
2879 but it appears to have been intended to allow it there, so
2880 we're keeping it as it is until WG14 reaches a conclusion
2882 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2883 c_parser_declspecs (parser
, specs
, false, true, true,
2884 true, false, cla_nonabstract_decl
);
2887 if (!specs
->declspecs_seen_p
)
2889 c_parser_error (parser
, "expected specifier-qualifier-list");
2892 finish_declspecs (specs
);
2893 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2894 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2897 if (specs
->typespec_kind
== ctsk_none
)
2899 pedwarn (decl_loc
, OPT_Wpedantic
,
2900 "ISO C forbids member declarations with no members");
2901 shadow_tag_warned (specs
, pedantic
);
2906 /* Support for unnamed structs or unions as members of
2907 structs or unions (which is [a] useful and [b] supports
2911 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2912 build_id_declarator (NULL_TREE
), specs
,
2915 decl_attributes (&ret
, attrs
, 0);
2920 /* Provide better error recovery. Note that a type name here is valid,
2921 and will be treated as a field name. */
2922 if (specs
->typespec_kind
== ctsk_tagdef
2923 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2924 && c_parser_next_token_starts_declspecs (parser
)
2925 && !c_parser_next_token_is (parser
, CPP_NAME
))
2927 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2928 parser
->error
= false;
2932 pending_xref_error ();
2933 prefix_attrs
= specs
->attrs
;
2934 all_prefix_attrs
= prefix_attrs
;
2935 specs
->attrs
= NULL_TREE
;
2939 /* Declaring one or more declarators or un-named bit-fields. */
2940 struct c_declarator
*declarator
;
2942 if (c_parser_next_token_is (parser
, CPP_COLON
))
2943 declarator
= build_id_declarator (NULL_TREE
);
2945 declarator
= c_parser_declarator (parser
,
2946 specs
->typespec_kind
!= ctsk_none
,
2947 C_DTR_NORMAL
, &dummy
);
2948 if (declarator
== NULL
)
2950 c_parser_skip_to_end_of_block_or_statement (parser
);
2953 if (c_parser_next_token_is (parser
, CPP_COLON
)
2954 || c_parser_next_token_is (parser
, CPP_COMMA
)
2955 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2956 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2957 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2959 tree postfix_attrs
= NULL_TREE
;
2960 tree width
= NULL_TREE
;
2962 if (c_parser_next_token_is (parser
, CPP_COLON
))
2964 c_parser_consume_token (parser
);
2965 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2967 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2968 postfix_attrs
= c_parser_attributes (parser
);
2969 d
= grokfield (c_parser_peek_token (parser
)->location
,
2970 declarator
, specs
, width
, &all_prefix_attrs
);
2971 decl_attributes (&d
, chainon (postfix_attrs
,
2972 all_prefix_attrs
), 0);
2973 DECL_CHAIN (d
) = decls
;
2975 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2976 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2979 all_prefix_attrs
= prefix_attrs
;
2980 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2981 c_parser_consume_token (parser
);
2982 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2983 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2985 /* Semicolon consumed in caller. */
2990 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2996 c_parser_error (parser
,
2997 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2998 "%<__attribute__%>");
3005 /* Parse a typeof specifier (a GNU extension).
3008 typeof ( expression )
3009 typeof ( type-name )
3012 static struct c_typespec
3013 c_parser_typeof_specifier (c_parser
*parser
)
3015 struct c_typespec ret
;
3016 ret
.kind
= ctsk_typeof
;
3017 ret
.spec
= error_mark_node
;
3018 ret
.expr
= NULL_TREE
;
3019 ret
.expr_const_operands
= true;
3020 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3021 c_parser_consume_token (parser
);
3022 c_inhibit_evaluation_warnings
++;
3024 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3026 c_inhibit_evaluation_warnings
--;
3030 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3032 struct c_type_name
*type
= c_parser_type_name (parser
);
3033 c_inhibit_evaluation_warnings
--;
3037 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3038 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3044 location_t here
= c_parser_peek_token (parser
)->location
;
3045 struct c_expr expr
= c_parser_expression (parser
);
3046 c_inhibit_evaluation_warnings
--;
3048 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3049 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3050 error_at (here
, "%<typeof%> applied to a bit-field");
3051 mark_exp_read (expr
.value
);
3052 ret
.spec
= TREE_TYPE (expr
.value
);
3053 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3054 /* This is returned with the type so that when the type is
3055 evaluated, this can be evaluated. */
3057 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3058 pop_maybe_used (was_vm
);
3059 /* For use in macros such as those in <stdatomic.h>, remove all
3060 qualifiers from atomic types. (const can be an issue for more macros
3061 using typeof than just the <stdatomic.h> ones.) */
3062 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3063 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3065 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3069 /* Parse an alignment-specifier.
3073 alignment-specifier:
3074 _Alignas ( type-name )
3075 _Alignas ( constant-expression )
3079 c_parser_alignas_specifier (c_parser
* parser
)
3081 tree ret
= error_mark_node
;
3082 location_t loc
= c_parser_peek_token (parser
)->location
;
3083 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3084 c_parser_consume_token (parser
);
3086 pedwarn_c99 (loc
, OPT_Wpedantic
,
3087 "ISO C99 does not support %<_Alignas%>");
3089 pedwarn_c99 (loc
, OPT_Wpedantic
,
3090 "ISO C90 does not support %<_Alignas%>");
3091 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3093 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3095 struct c_type_name
*type
= c_parser_type_name (parser
);
3097 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3101 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3102 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3106 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3107 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3108 be redeclared; otherwise it may not. KIND indicates which kind of
3109 declarator is wanted. Returns a valid declarator except in the
3110 case of a syntax error in which case NULL is returned. *SEEN_ID is
3111 set to true if an identifier being declared is seen; this is used
3112 to diagnose bad forms of abstract array declarators and to
3113 determine whether an identifier list is syntactically permitted.
3116 pointer[opt] direct-declarator
3120 ( attributes[opt] declarator )
3121 direct-declarator array-declarator
3122 direct-declarator ( parameter-type-list )
3123 direct-declarator ( identifier-list[opt] )
3126 * type-qualifier-list[opt]
3127 * type-qualifier-list[opt] pointer
3129 type-qualifier-list:
3132 type-qualifier-list type-qualifier
3133 type-qualifier-list attributes
3136 [ type-qualifier-list[opt] assignment-expression[opt] ]
3137 [ static type-qualifier-list[opt] assignment-expression ]
3138 [ type-qualifier-list static assignment-expression ]
3139 [ type-qualifier-list[opt] * ]
3141 parameter-type-list:
3143 parameter-list , ...
3146 parameter-declaration
3147 parameter-list , parameter-declaration
3149 parameter-declaration:
3150 declaration-specifiers declarator attributes[opt]
3151 declaration-specifiers abstract-declarator[opt] attributes[opt]
3155 identifier-list , identifier
3157 abstract-declarator:
3159 pointer[opt] direct-abstract-declarator
3161 direct-abstract-declarator:
3162 ( attributes[opt] abstract-declarator )
3163 direct-abstract-declarator[opt] array-declarator
3164 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3169 direct-declarator ( parameter-forward-declarations
3170 parameter-type-list[opt] )
3172 direct-abstract-declarator:
3173 direct-abstract-declarator[opt] ( parameter-forward-declarations
3174 parameter-type-list[opt] )
3176 parameter-forward-declarations:
3178 parameter-forward-declarations parameter-list ;
3180 The uses of attributes shown above are GNU extensions.
3182 Some forms of array declarator are not included in C99 in the
3183 syntax for abstract declarators; these are disallowed elsewhere.
3184 This may be a defect (DR#289).
3186 This function also accepts an omitted abstract declarator as being
3187 an abstract declarator, although not part of the formal syntax. */
3189 static struct c_declarator
*
3190 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3193 /* Parse any initial pointer part. */
3194 if (c_parser_next_token_is (parser
, CPP_MULT
))
3196 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3197 struct c_declarator
*inner
;
3198 c_parser_consume_token (parser
);
3199 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3200 false, false, cla_prefer_id
);
3201 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3205 return make_pointer_declarator (quals_attrs
, inner
);
3207 /* Now we have a direct declarator, direct abstract declarator or
3208 nothing (which counts as a direct abstract declarator here). */
3209 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3212 /* Parse a direct declarator or direct abstract declarator; arguments
3213 as c_parser_declarator. */
3215 static struct c_declarator
*
3216 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3219 /* The direct declarator must start with an identifier (possibly
3220 omitted) or a parenthesized declarator (possibly abstract). In
3221 an ordinary declarator, initial parentheses must start a
3222 parenthesized declarator. In an abstract declarator or parameter
3223 declarator, they could start a parenthesized declarator or a
3224 parameter list. To tell which, the open parenthesis and any
3225 following attributes must be read. If a declaration specifier
3226 follows, then it is a parameter list; if the specifier is a
3227 typedef name, there might be an ambiguity about redeclaring it,
3228 which is resolved in the direction of treating it as a typedef
3229 name. If a close parenthesis follows, it is also an empty
3230 parameter list, as the syntax does not permit empty abstract
3231 declarators. Otherwise, it is a parenthesized declarator (in
3232 which case the analysis may be repeated inside it, recursively).
3234 ??? There is an ambiguity in a parameter declaration "int
3235 (__attribute__((foo)) x)", where x is not a typedef name: it
3236 could be an abstract declarator for a function, or declare x with
3237 parentheses. The proper resolution of this ambiguity needs
3238 documenting. At present we follow an accident of the old
3239 parser's implementation, whereby the first parameter must have
3240 some declaration specifiers other than just attributes. Thus as
3241 a parameter declaration it is treated as a parenthesized
3242 parameter named x, and as an abstract declarator it is
3245 ??? Also following the old parser, attributes inside an empty
3246 parameter list are ignored, making it a list not yielding a
3247 prototype, rather than giving an error or making it have one
3248 parameter with implicit type int.
3250 ??? Also following the old parser, typedef names may be
3251 redeclared in declarators, but not Objective-C class names. */
3253 if (kind
!= C_DTR_ABSTRACT
3254 && c_parser_next_token_is (parser
, CPP_NAME
)
3256 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3257 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3258 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3260 struct c_declarator
*inner
3261 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3263 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3264 c_parser_consume_token (parser
);
3265 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3268 if (kind
!= C_DTR_NORMAL
3269 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3271 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3272 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3275 /* Either we are at the end of an abstract declarator, or we have
3278 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3281 struct c_declarator
*inner
;
3282 c_parser_consume_token (parser
);
3283 attrs
= c_parser_attributes (parser
);
3284 if (kind
!= C_DTR_NORMAL
3285 && (c_parser_next_token_starts_declspecs (parser
)
3286 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3288 struct c_arg_info
*args
3289 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3296 = build_function_declarator (args
,
3297 build_id_declarator (NULL_TREE
));
3298 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3302 /* A parenthesized declarator. */
3303 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3304 if (inner
!= NULL
&& attrs
!= NULL
)
3305 inner
= build_attrs_declarator (attrs
, inner
);
3306 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3308 c_parser_consume_token (parser
);
3312 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3316 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3323 if (kind
== C_DTR_NORMAL
)
3325 c_parser_error (parser
, "expected identifier or %<(%>");
3329 return build_id_declarator (NULL_TREE
);
3333 /* Parse part of a direct declarator or direct abstract declarator,
3334 given that some (in INNER) has already been parsed; ID_PRESENT is
3335 true if an identifier is present, false for an abstract
3338 static struct c_declarator
*
3339 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3340 struct c_declarator
*inner
)
3342 /* Parse a sequence of array declarators and parameter lists. */
3343 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3345 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3346 struct c_declarator
*declarator
;
3347 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3350 struct c_expr dimen
;
3351 dimen
.value
= NULL_TREE
;
3352 dimen
.original_code
= ERROR_MARK
;
3353 dimen
.original_type
= NULL_TREE
;
3354 c_parser_consume_token (parser
);
3355 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3356 false, false, cla_prefer_id
);
3357 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3359 c_parser_consume_token (parser
);
3360 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3361 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3362 false, false, cla_prefer_id
);
3363 if (!quals_attrs
->declspecs_seen_p
)
3365 /* If "static" is present, there must be an array dimension.
3366 Otherwise, there may be a dimension, "*", or no
3371 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3375 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3377 dimen
.value
= NULL_TREE
;
3380 else if (flag_cilkplus
3381 && c_parser_next_token_is (parser
, CPP_COLON
))
3383 dimen
.value
= error_mark_node
;
3385 error_at (c_parser_peek_token (parser
)->location
,
3386 "array notations cannot be used in declaration");
3387 c_parser_consume_token (parser
);
3389 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3391 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3393 dimen
.value
= NULL_TREE
;
3395 c_parser_consume_token (parser
);
3400 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3406 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3409 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3410 c_parser_consume_token (parser
);
3411 else if (flag_cilkplus
3412 && c_parser_next_token_is (parser
, CPP_COLON
))
3414 error_at (c_parser_peek_token (parser
)->location
,
3415 "array notations cannot be used in declaration");
3416 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3421 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3426 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3427 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3428 static_seen
, star_seen
);
3429 if (declarator
== NULL
)
3431 inner
= set_array_declarator_inner (declarator
, inner
);
3432 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3434 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3437 struct c_arg_info
*args
;
3438 c_parser_consume_token (parser
);
3439 attrs
= c_parser_attributes (parser
);
3440 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3445 inner
= build_function_declarator (args
, inner
);
3446 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3452 /* Parse a parameter list or identifier list, including the closing
3453 parenthesis but not the opening one. ATTRS are the attributes at
3454 the start of the list. ID_LIST_OK is true if an identifier list is
3455 acceptable; such a list must not have attributes at the start. */
3457 static struct c_arg_info
*
3458 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3461 declare_parm_level ();
3462 /* If the list starts with an identifier, it is an identifier list.
3463 Otherwise, it is either a prototype list or an empty list. */
3466 && c_parser_next_token_is (parser
, CPP_NAME
)
3467 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3469 /* Look ahead to detect typos in type names. */
3470 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3471 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3472 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3473 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3475 tree list
= NULL_TREE
, *nextp
= &list
;
3476 while (c_parser_next_token_is (parser
, CPP_NAME
)
3477 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3479 *nextp
= build_tree_list (NULL_TREE
,
3480 c_parser_peek_token (parser
)->value
);
3481 nextp
= & TREE_CHAIN (*nextp
);
3482 c_parser_consume_token (parser
);
3483 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3485 c_parser_consume_token (parser
);
3486 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3488 c_parser_error (parser
, "expected identifier");
3492 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3494 struct c_arg_info
*ret
= build_arg_info ();
3496 c_parser_consume_token (parser
);
3502 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3510 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3517 /* Parse a parameter list (possibly empty), including the closing
3518 parenthesis but not the opening one. ATTRS are the attributes at
3519 the start of the list. EXPR is NULL or an expression that needs to
3520 be evaluated for the side effects of array size expressions in the
3523 static struct c_arg_info
*
3524 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3526 bool bad_parm
= false;
3528 /* ??? Following the old parser, forward parameter declarations may
3529 use abstract declarators, and if no real parameter declarations
3530 follow the forward declarations then this is not diagnosed. Also
3531 note as above that attributes are ignored as the only contents of
3532 the parentheses, or as the only contents after forward
3534 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3536 struct c_arg_info
*ret
= build_arg_info ();
3537 c_parser_consume_token (parser
);
3540 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3542 struct c_arg_info
*ret
= build_arg_info ();
3544 if (flag_allow_parameterless_variadic_functions
)
3546 /* F (...) is allowed. */
3547 ret
->types
= NULL_TREE
;
3551 /* Suppress -Wold-style-definition for this case. */
3552 ret
->types
= error_mark_node
;
3553 error_at (c_parser_peek_token (parser
)->location
,
3554 "ISO C requires a named argument before %<...%>");
3556 c_parser_consume_token (parser
);
3557 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3559 c_parser_consume_token (parser
);
3564 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3569 /* Nonempty list of parameters, either terminated with semicolon
3570 (forward declarations; recurse) or with close parenthesis (normal
3571 function) or with ", ... )" (variadic function). */
3574 /* Parse a parameter. */
3575 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3580 push_parm_decl (parm
, &expr
);
3581 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3584 c_parser_consume_token (parser
);
3585 mark_forward_parm_decls ();
3586 new_attrs
= c_parser_attributes (parser
);
3587 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3589 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3591 c_parser_consume_token (parser
);
3595 return get_parm_info (false, expr
);
3597 if (!c_parser_require (parser
, CPP_COMMA
,
3598 "expected %<;%>, %<,%> or %<)%>"))
3600 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3603 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3605 c_parser_consume_token (parser
);
3606 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3608 c_parser_consume_token (parser
);
3612 return get_parm_info (true, expr
);
3616 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3624 /* Parse a parameter declaration. ATTRS are the attributes at the
3625 start of the declaration if it is the first parameter. */
3627 static struct c_parm
*
3628 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3630 struct c_declspecs
*specs
;
3631 struct c_declarator
*declarator
;
3633 tree postfix_attrs
= NULL_TREE
;
3636 /* Accept #pragmas between parameter declarations. */
3637 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3638 c_parser_pragma (parser
, pragma_param
);
3640 if (!c_parser_next_token_starts_declspecs (parser
))
3642 c_token
*token
= c_parser_peek_token (parser
);
3645 c_parser_set_source_position_from_token (token
);
3646 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3648 error_at (token
->location
, "unknown type name %qE", token
->value
);
3649 parser
->error
= true;
3651 /* ??? In some Objective-C cases '...' isn't applicable so there
3652 should be a different message. */
3654 c_parser_error (parser
,
3655 "expected declaration specifiers or %<...%>");
3656 c_parser_skip_to_end_of_parameter (parser
);
3659 specs
= build_null_declspecs ();
3662 declspecs_add_attrs (input_location
, specs
, attrs
);
3665 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3666 cla_nonabstract_decl
);
3667 finish_declspecs (specs
);
3668 pending_xref_error ();
3669 prefix_attrs
= specs
->attrs
;
3670 specs
->attrs
= NULL_TREE
;
3671 declarator
= c_parser_declarator (parser
,
3672 specs
->typespec_kind
!= ctsk_none
,
3673 C_DTR_PARM
, &dummy
);
3674 if (declarator
== NULL
)
3676 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3679 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3680 postfix_attrs
= c_parser_attributes (parser
);
3681 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3685 /* Parse a string literal in an asm expression. It should not be
3686 translated, and wide string literals are an error although
3687 permitted by the syntax. This is a GNU extension.
3692 ??? At present, following the old parser, the caller needs to have
3693 set lex_untranslated_string to 1. It would be better to follow the
3694 C++ parser rather than using this kludge. */
3697 c_parser_asm_string_literal (c_parser
*parser
)
3700 int save_flag
= warn_overlength_strings
;
3701 warn_overlength_strings
= 0;
3702 if (c_parser_next_token_is (parser
, CPP_STRING
))
3704 str
= c_parser_peek_token (parser
)->value
;
3705 c_parser_consume_token (parser
);
3707 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3709 error_at (c_parser_peek_token (parser
)->location
,
3710 "wide string literal in %<asm%>");
3711 str
= build_string (1, "");
3712 c_parser_consume_token (parser
);
3716 c_parser_error (parser
, "expected string literal");
3719 warn_overlength_strings
= save_flag
;
3723 /* Parse a simple asm expression. This is used in restricted
3724 contexts, where a full expression with inputs and outputs does not
3725 make sense. This is a GNU extension.
3728 asm ( asm-string-literal )
3732 c_parser_simple_asm_expr (c_parser
*parser
)
3735 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3736 /* ??? Follow the C++ parser rather than using the
3737 lex_untranslated_string kludge. */
3738 parser
->lex_untranslated_string
= true;
3739 c_parser_consume_token (parser
);
3740 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3742 parser
->lex_untranslated_string
= false;
3745 str
= c_parser_asm_string_literal (parser
);
3746 parser
->lex_untranslated_string
= false;
3747 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3749 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3756 c_parser_attribute_any_word (c_parser
*parser
)
3758 tree attr_name
= NULL_TREE
;
3760 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3762 /* ??? See comment above about what keywords are accepted here. */
3764 switch (c_parser_peek_token (parser
)->keyword
)
3794 case RID_TRANSACTION_ATOMIC
:
3795 case RID_TRANSACTION_CANCEL
:
3811 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3812 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3814 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3815 attr_name
= c_parser_peek_token (parser
)->value
;
3820 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3821 "__vector" or "__vector__." */
3824 is_cilkplus_vector_p (tree name
)
3826 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3831 #define CILK_SIMD_FN_CLAUSE_MASK \
3832 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3833 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3834 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3835 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3836 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3838 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3839 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3840 pushed into the token list.
3843 vector (<vector attributes>). */
3846 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3848 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3850 int paren_scope
= 0;
3851 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3852 /* Consume the "vector" token. */
3853 c_parser_consume_token (parser
);
3855 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3857 c_parser_consume_token (parser
);
3860 while (paren_scope
> 0)
3862 c_token
*token
= c_parser_peek_token (parser
);
3863 if (token
->type
== CPP_OPEN_PAREN
)
3865 else if (token
->type
== CPP_CLOSE_PAREN
)
3867 /* Do not push the last ')' since we are not pushing the '('. */
3868 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3869 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3870 c_parser_consume_token (parser
);
3873 /* Since we are converting an attribute to a pragma, we need to end the
3874 attribute with PRAGMA_EOL. */
3876 memset (&eol_token
, 0, sizeof (eol_token
));
3877 eol_token
.type
= CPP_PRAGMA_EOL
;
3878 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3881 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3884 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3886 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3888 /* c_parser_attributes is called in several places, so if these EOF
3889 tokens are already inserted, then don't do them again. */
3890 if (last_token
.type
== CPP_EOF
)
3893 /* Two CPP_EOF token are added as a safety net since the normal C
3894 front-end has two token look-ahead. */
3896 eof_token
.type
= CPP_EOF
;
3897 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3898 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3901 /* Parse (possibly empty) attributes. This is a GNU extension.
3905 attributes attribute
3908 __attribute__ ( ( attribute-list ) )
3912 attribute_list , attrib
3917 any-word ( identifier )
3918 any-word ( identifier , nonempty-expr-list )
3919 any-word ( expr-list )
3921 where the "identifier" must not be declared as a type, and
3922 "any-word" may be any identifier (including one declared as a
3923 type), a reserved word storage class specifier, type specifier or
3924 type qualifier. ??? This still leaves out most reserved keywords
3925 (following the old parser), shouldn't we include them, and why not
3926 allow identifiers declared as types to start the arguments? */
3929 c_parser_attributes (c_parser
*parser
)
3931 tree attrs
= NULL_TREE
;
3932 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3934 /* ??? Follow the C++ parser rather than using the
3935 lex_untranslated_string kludge. */
3936 parser
->lex_untranslated_string
= true;
3937 c_parser_consume_token (parser
);
3938 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3940 parser
->lex_untranslated_string
= false;
3943 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3945 parser
->lex_untranslated_string
= false;
3946 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3949 /* Parse the attribute list. */
3950 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3951 || c_parser_next_token_is (parser
, CPP_NAME
)
3952 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3954 tree attr
, attr_name
, attr_args
;
3955 vec
<tree
, va_gc
> *expr_list
;
3956 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3958 c_parser_consume_token (parser
);
3962 attr_name
= c_parser_attribute_any_word (parser
);
3963 if (attr_name
== NULL
)
3965 if (is_cilkplus_vector_p (attr_name
))
3967 c_token
*v_token
= c_parser_peek_token (parser
);
3968 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3971 c_parser_consume_token (parser
);
3972 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3974 attr
= build_tree_list (attr_name
, NULL_TREE
);
3975 attrs
= chainon (attrs
, attr
);
3978 c_parser_consume_token (parser
);
3979 /* Parse the attribute contents. If they start with an
3980 identifier which is followed by a comma or close
3981 parenthesis, then the arguments start with that
3982 identifier; otherwise they are an expression list.
3983 In objective-c the identifier may be a classname. */
3984 if (c_parser_next_token_is (parser
, CPP_NAME
)
3985 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3986 || (c_dialect_objc ()
3987 && c_parser_peek_token (parser
)->id_kind
3989 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3990 || (c_parser_peek_2nd_token (parser
)->type
3991 == CPP_CLOSE_PAREN
))
3992 && (attribute_takes_identifier_p (attr_name
)
3993 || (c_dialect_objc ()
3994 && c_parser_peek_token (parser
)->id_kind
3995 == C_ID_CLASSNAME
)))
3997 tree arg1
= c_parser_peek_token (parser
)->value
;
3998 c_parser_consume_token (parser
);
3999 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4000 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4004 c_parser_consume_token (parser
);
4005 expr_list
= c_parser_expr_list (parser
, false, true,
4006 NULL
, NULL
, NULL
, NULL
);
4007 tree_list
= build_tree_list_vec (expr_list
);
4008 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4009 release_tree_vector (expr_list
);
4014 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4015 attr_args
= NULL_TREE
;
4018 expr_list
= c_parser_expr_list (parser
, false, true,
4019 NULL
, NULL
, NULL
, NULL
);
4020 attr_args
= build_tree_list_vec (expr_list
);
4021 release_tree_vector (expr_list
);
4024 attr
= build_tree_list (attr_name
, attr_args
);
4025 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4026 c_parser_consume_token (parser
);
4029 parser
->lex_untranslated_string
= false;
4030 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4034 attrs
= chainon (attrs
, attr
);
4036 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4037 c_parser_consume_token (parser
);
4040 parser
->lex_untranslated_string
= false;
4041 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4045 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4046 c_parser_consume_token (parser
);
4049 parser
->lex_untranslated_string
= false;
4050 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4054 parser
->lex_untranslated_string
= false;
4057 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4058 c_finish_cilk_simd_fn_tokens (parser
);
4062 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4065 specifier-qualifier-list abstract-declarator[opt]
4068 static struct c_type_name
*
4069 c_parser_type_name (c_parser
*parser
)
4071 struct c_declspecs
*specs
= build_null_declspecs ();
4072 struct c_declarator
*declarator
;
4073 struct c_type_name
*ret
;
4075 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4077 if (!specs
->declspecs_seen_p
)
4079 c_parser_error (parser
, "expected specifier-qualifier-list");
4082 if (specs
->type
!= error_mark_node
)
4084 pending_xref_error ();
4085 finish_declspecs (specs
);
4087 declarator
= c_parser_declarator (parser
,
4088 specs
->typespec_kind
!= ctsk_none
,
4089 C_DTR_ABSTRACT
, &dummy
);
4090 if (declarator
== NULL
)
4092 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4094 ret
->declarator
= declarator
;
4098 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4101 assignment-expression
4102 { initializer-list }
4103 { initializer-list , }
4106 designation[opt] initializer
4107 initializer-list , designation[opt] initializer
4114 designator-list designator
4121 [ constant-expression ]
4133 [ constant-expression ... constant-expression ]
4135 Any expression without commas is accepted in the syntax for the
4136 constant-expressions, with non-constant expressions rejected later.
4138 This function is only used for top-level initializers; for nested
4139 ones, see c_parser_initval. */
4141 static struct c_expr
4142 c_parser_initializer (c_parser
*parser
)
4144 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4145 return c_parser_braced_init (parser
, NULL_TREE
, false);
4149 location_t loc
= c_parser_peek_token (parser
)->location
;
4150 ret
= c_parser_expr_no_commas (parser
, NULL
);
4151 if (TREE_CODE (ret
.value
) != STRING_CST
4152 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4153 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4158 /* Parse a braced initializer list. TYPE is the type specified for a
4159 compound literal, and NULL_TREE for other initializers and for
4160 nested braced lists. NESTED_P is true for nested braced lists,
4161 false for the list of a compound literal or the list that is the
4162 top-level initializer in a declaration. */
4164 static struct c_expr
4165 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4168 struct obstack braced_init_obstack
;
4169 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4170 gcc_obstack_init (&braced_init_obstack
);
4171 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4172 c_parser_consume_token (parser
);
4174 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4176 really_start_incremental_init (type
);
4177 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4179 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4183 /* Parse a non-empty initializer list, possibly with a trailing
4187 c_parser_initelt (parser
, &braced_init_obstack
);
4190 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4191 c_parser_consume_token (parser
);
4194 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4198 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4200 ret
.value
= error_mark_node
;
4201 ret
.original_code
= ERROR_MARK
;
4202 ret
.original_type
= NULL
;
4203 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4204 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4205 obstack_free (&braced_init_obstack
, NULL
);
4208 c_parser_consume_token (parser
);
4209 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4210 obstack_free (&braced_init_obstack
, NULL
);
4214 /* Parse a nested initializer, including designators. */
4217 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4219 /* Parse any designator or designator list. A single array
4220 designator may have the subsequent "=" omitted in GNU C, but a
4221 longer list or a structure member designator may not. */
4222 if (c_parser_next_token_is (parser
, CPP_NAME
)
4223 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4225 /* Old-style structure member designator. */
4226 set_init_label (c_parser_peek_token (parser
)->location
,
4227 c_parser_peek_token (parser
)->value
,
4228 braced_init_obstack
);
4229 /* Use the colon as the error location. */
4230 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4231 "obsolete use of designated initializer with %<:%>");
4232 c_parser_consume_token (parser
);
4233 c_parser_consume_token (parser
);
4237 /* des_seen is 0 if there have been no designators, 1 if there
4238 has been a single array designator and 2 otherwise. */
4240 /* Location of a designator. */
4241 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4242 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4243 || c_parser_next_token_is (parser
, CPP_DOT
))
4245 int des_prev
= des_seen
;
4247 des_loc
= c_parser_peek_token (parser
)->location
;
4250 if (c_parser_next_token_is (parser
, CPP_DOT
))
4253 c_parser_consume_token (parser
);
4254 if (c_parser_next_token_is (parser
, CPP_NAME
))
4256 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4257 braced_init_obstack
);
4258 c_parser_consume_token (parser
);
4263 init
.value
= error_mark_node
;
4264 init
.original_code
= ERROR_MARK
;
4265 init
.original_type
= NULL
;
4266 c_parser_error (parser
, "expected identifier");
4267 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4268 process_init_element (input_location
, init
, false,
4269 braced_init_obstack
);
4276 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4277 location_t array_index_loc
= UNKNOWN_LOCATION
;
4278 /* ??? Following the old parser, [ objc-receiver
4279 objc-message-args ] is accepted as an initializer,
4280 being distinguished from a designator by what follows
4281 the first assignment expression inside the square
4282 brackets, but after a first array designator a
4283 subsequent square bracket is for Objective-C taken to
4284 start an expression, using the obsolete form of
4285 designated initializer without '=', rather than
4286 possibly being a second level of designation: in LALR
4287 terms, the '[' is shifted rather than reducing
4288 designator to designator-list. */
4289 if (des_prev
== 1 && c_dialect_objc ())
4291 des_seen
= des_prev
;
4294 if (des_prev
== 0 && c_dialect_objc ())
4296 /* This might be an array designator or an
4297 Objective-C message expression. If the former,
4298 continue parsing here; if the latter, parse the
4299 remainder of the initializer given the starting
4300 primary-expression. ??? It might make sense to
4301 distinguish when des_prev == 1 as well; see
4302 previous comment. */
4304 struct c_expr mexpr
;
4305 c_parser_consume_token (parser
);
4306 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4307 && ((c_parser_peek_token (parser
)->id_kind
4309 || (c_parser_peek_token (parser
)->id_kind
4310 == C_ID_CLASSNAME
)))
4312 /* Type name receiver. */
4313 tree id
= c_parser_peek_token (parser
)->value
;
4314 c_parser_consume_token (parser
);
4315 rec
= objc_get_class_reference (id
);
4316 goto parse_message_args
;
4318 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4319 mark_exp_read (first
);
4320 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4321 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4322 goto array_desig_after_first
;
4323 /* Expression receiver. So far only one part
4324 without commas has been parsed; there might be
4325 more of the expression. */
4327 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4330 location_t comma_loc
, exp_loc
;
4331 comma_loc
= c_parser_peek_token (parser
)->location
;
4332 c_parser_consume_token (parser
);
4333 exp_loc
= c_parser_peek_token (parser
)->location
;
4334 next
= c_parser_expr_no_commas (parser
, NULL
);
4335 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4337 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4340 /* Now parse the objc-message-args. */
4341 args
= c_parser_objc_message_args (parser
);
4342 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4345 = objc_build_message_expr (rec
, args
);
4346 mexpr
.original_code
= ERROR_MARK
;
4347 mexpr
.original_type
= NULL
;
4348 /* Now parse and process the remainder of the
4349 initializer, starting with this message
4350 expression as a primary-expression. */
4351 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4354 c_parser_consume_token (parser
);
4355 array_index_loc
= c_parser_peek_token (parser
)->location
;
4356 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4357 mark_exp_read (first
);
4358 array_desig_after_first
:
4359 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4361 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4362 c_parser_consume_token (parser
);
4363 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4364 mark_exp_read (second
);
4368 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4370 c_parser_consume_token (parser
);
4371 set_init_index (array_index_loc
, first
, second
,
4372 braced_init_obstack
);
4374 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4375 "ISO C forbids specifying range of elements to initialize");
4378 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4384 if (c_parser_next_token_is (parser
, CPP_EQ
))
4386 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4387 "ISO C90 forbids specifying subobject "
4389 c_parser_consume_token (parser
);
4394 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4395 "obsolete use of designated initializer without %<=%>");
4399 init
.value
= error_mark_node
;
4400 init
.original_code
= ERROR_MARK
;
4401 init
.original_type
= NULL
;
4402 c_parser_error (parser
, "expected %<=%>");
4403 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4404 process_init_element (input_location
, init
, false,
4405 braced_init_obstack
);
4411 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4414 /* Parse a nested initializer; as c_parser_initializer but parses
4415 initializers within braced lists, after any designators have been
4416 applied. If AFTER is not NULL then it is an Objective-C message
4417 expression which is the primary-expression starting the
4421 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4422 struct obstack
* braced_init_obstack
)
4425 gcc_assert (!after
|| c_dialect_objc ());
4426 location_t loc
= c_parser_peek_token (parser
)->location
;
4428 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4429 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4432 init
= c_parser_expr_no_commas (parser
, after
);
4433 if (init
.value
!= NULL_TREE
4434 && TREE_CODE (init
.value
) != STRING_CST
4435 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4436 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4438 process_init_element (loc
, init
, false, braced_init_obstack
);
4441 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4445 { block-item-list[opt] }
4446 { label-declarations block-item-list }
4450 block-item-list block-item
4462 { label-declarations block-item-list }
4465 __extension__ nested-declaration
4466 nested-function-definition
4470 label-declarations label-declaration
4473 __label__ identifier-list ;
4475 Allowing the mixing of declarations and code is new in C99. The
4476 GNU syntax also permits (not shown above) labels at the end of
4477 compound statements, which yield an error. We don't allow labels
4478 on declarations; this might seem like a natural extension, but
4479 there would be a conflict between attributes on the label and
4480 prefix attributes on the declaration. ??? The syntax follows the
4481 old parser in requiring something after label declarations.
4482 Although they are erroneous if the labels declared aren't defined,
4483 is it useful for the syntax to be this way?
4496 cancellation-point-directive */
4499 c_parser_compound_statement (c_parser
*parser
)
4502 location_t brace_loc
;
4503 brace_loc
= c_parser_peek_token (parser
)->location
;
4504 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4506 /* Ensure a scope is entered and left anyway to avoid confusion
4507 if we have just prepared to enter a function body. */
4508 stmt
= c_begin_compound_stmt (true);
4509 c_end_compound_stmt (brace_loc
, stmt
, true);
4510 return error_mark_node
;
4512 stmt
= c_begin_compound_stmt (true);
4513 c_parser_compound_statement_nostart (parser
);
4515 /* If the compound stmt contains array notations, then we expand them. */
4516 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4517 stmt
= expand_array_notation_exprs (stmt
);
4518 return c_end_compound_stmt (brace_loc
, stmt
, true);
4521 /* Parse a compound statement except for the opening brace. This is
4522 used for parsing both compound statements and statement expressions
4523 (which follow different paths to handling the opening). */
4526 c_parser_compound_statement_nostart (c_parser
*parser
)
4528 bool last_stmt
= false;
4529 bool last_label
= false;
4530 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4531 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4532 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4534 c_parser_consume_token (parser
);
4537 mark_valid_location_for_stdc_pragma (true);
4538 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4540 /* Read zero or more forward-declarations for labels that nested
4541 functions can jump to. */
4542 mark_valid_location_for_stdc_pragma (false);
4543 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4545 label_loc
= c_parser_peek_token (parser
)->location
;
4546 c_parser_consume_token (parser
);
4547 /* Any identifiers, including those declared as type names,
4552 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4554 c_parser_error (parser
, "expected identifier");
4558 = declare_label (c_parser_peek_token (parser
)->value
);
4559 C_DECLARED_LABEL_FLAG (label
) = 1;
4560 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4561 c_parser_consume_token (parser
);
4562 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4563 c_parser_consume_token (parser
);
4567 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4569 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4571 /* We must now have at least one statement, label or declaration. */
4572 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4574 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4575 c_parser_error (parser
, "expected declaration or statement");
4576 c_parser_consume_token (parser
);
4579 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4581 location_t loc
= c_parser_peek_token (parser
)->location
;
4582 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4583 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4584 || (c_parser_next_token_is (parser
, CPP_NAME
)
4585 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4587 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4588 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4590 label_loc
= c_parser_peek_token (parser
)->location
;
4593 mark_valid_location_for_stdc_pragma (false);
4594 c_parser_label (parser
);
4596 else if (!last_label
4597 && c_parser_next_tokens_start_declaration (parser
))
4600 mark_valid_location_for_stdc_pragma (false);
4601 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4604 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4605 "ISO C90 forbids mixed declarations and code");
4608 else if (!last_label
4609 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4611 /* __extension__ can start a declaration, but is also an
4612 unary operator that can start an expression. Consume all
4613 but the last of a possible series of __extension__ to
4615 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4616 && (c_parser_peek_2nd_token (parser
)->keyword
4618 c_parser_consume_token (parser
);
4619 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4622 ext
= disable_extension_diagnostics ();
4623 c_parser_consume_token (parser
);
4625 mark_valid_location_for_stdc_pragma (false);
4626 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4628 /* Following the old parser, __extension__ does not
4629 disable this diagnostic. */
4630 restore_extension_diagnostics (ext
);
4632 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4633 "ISO C90 forbids mixed declarations and code");
4639 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4641 /* External pragmas, and some omp pragmas, are not associated
4642 with regular c code, and so are not to be considered statements
4643 syntactically. This ensures that the user doesn't put them
4644 places that would turn into syntax errors if the directive
4646 if (c_parser_pragma (parser
, pragma_compound
))
4647 last_label
= false, last_stmt
= true;
4649 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4651 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4652 c_parser_error (parser
, "expected declaration or statement");
4655 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4657 if (parser
->in_if_block
)
4659 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4660 error_at (loc
, """expected %<}%> before %<else%>");
4665 error_at (loc
, "%<else%> without a previous %<if%>");
4666 c_parser_consume_token (parser
);
4675 mark_valid_location_for_stdc_pragma (false);
4676 c_parser_statement_after_labels (parser
);
4679 parser
->error
= false;
4682 error_at (label_loc
, "label at end of compound statement");
4683 c_parser_consume_token (parser
);
4684 /* Restore the value we started with. */
4685 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4688 /* Parse all consecutive labels. */
4691 c_parser_all_labels (c_parser
*parser
)
4693 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4694 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4695 || (c_parser_next_token_is (parser
, CPP_NAME
)
4696 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4697 c_parser_label (parser
);
4700 /* Parse a label (C90 6.6.1, C99 6.8.1).
4703 identifier : attributes[opt]
4704 case constant-expression :
4710 case constant-expression ... constant-expression :
4712 The use of attributes on labels is a GNU extension. The syntax in
4713 GNU C accepts any expressions without commas, non-constant
4714 expressions being rejected later. */
4717 c_parser_label (c_parser
*parser
)
4719 location_t loc1
= c_parser_peek_token (parser
)->location
;
4720 tree label
= NULL_TREE
;
4721 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4724 c_parser_consume_token (parser
);
4725 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4726 if (c_parser_next_token_is (parser
, CPP_COLON
))
4728 c_parser_consume_token (parser
);
4729 label
= do_case (loc1
, exp1
, NULL_TREE
);
4731 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4733 c_parser_consume_token (parser
);
4734 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4735 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4736 label
= do_case (loc1
, exp1
, exp2
);
4739 c_parser_error (parser
, "expected %<:%> or %<...%>");
4741 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4743 c_parser_consume_token (parser
);
4744 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4745 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4749 tree name
= c_parser_peek_token (parser
)->value
;
4752 location_t loc2
= c_parser_peek_token (parser
)->location
;
4753 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4754 c_parser_consume_token (parser
);
4755 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4756 c_parser_consume_token (parser
);
4757 attrs
= c_parser_attributes (parser
);
4758 tlab
= define_label (loc2
, name
);
4761 decl_attributes (&tlab
, attrs
, 0);
4762 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4767 if (c_parser_next_tokens_start_declaration (parser
))
4769 error_at (c_parser_peek_token (parser
)->location
,
4770 "a label can only be part of a statement and "
4771 "a declaration is not a statement");
4772 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4773 /*static_assert_ok*/ true,
4774 /*empty_ok*/ true, /*nested*/ true,
4775 /*start_attr_ok*/ true, NULL
,
4781 /* Parse a statement (C90 6.6, C99 6.8).
4786 expression-statement
4794 expression-statement:
4797 selection-statement:
4801 iteration-statement:
4810 return expression[opt] ;
4823 objc-throw-statement
4824 objc-try-catch-statement
4825 objc-synchronized-statement
4827 objc-throw-statement:
4843 parallel-for-construct
4844 parallel-for-simd-construct
4845 parallel-sections-construct
4852 parallel-directive structured-block
4855 for-directive iteration-statement
4858 simd-directive iteration-statements
4861 for-simd-directive iteration-statements
4864 sections-directive section-scope
4867 single-directive structured-block
4869 parallel-for-construct:
4870 parallel-for-directive iteration-statement
4872 parallel-for-simd-construct:
4873 parallel-for-simd-directive iteration-statement
4875 parallel-sections-construct:
4876 parallel-sections-directive section-scope
4879 master-directive structured-block
4882 critical-directive structured-block
4885 atomic-directive expression-statement
4888 ordered-directive structured-block
4890 Transactional Memory:
4893 transaction-statement
4894 transaction-cancel-statement
4898 c_parser_statement (c_parser
*parser
)
4900 c_parser_all_labels (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);
4939 error_at (c_parser_peek_token (parser
)->location
,
4940 "-fcilkplus must be enabled to use %<_Cilk_for%>");
4941 c_parser_skip_to_end_of_block_or_statement (parser
);
4944 c_parser_cilk_for (parser
, integer_zero_node
);
4947 c_parser_consume_token (parser
);
4948 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4950 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4952 add_stmt (build_cilk_sync ());
4955 c_parser_consume_token (parser
);
4956 if (c_parser_next_token_is (parser
, CPP_NAME
))
4958 stmt
= c_finish_goto_label (loc
,
4959 c_parser_peek_token (parser
)->value
);
4960 c_parser_consume_token (parser
);
4962 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4966 c_parser_consume_token (parser
);
4967 val
= c_parser_expression (parser
);
4968 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4969 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4972 c_parser_error (parser
, "expected identifier or %<*%>");
4973 goto expect_semicolon
;
4975 c_parser_consume_token (parser
);
4976 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4977 goto expect_semicolon
;
4979 c_parser_consume_token (parser
);
4980 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4981 goto expect_semicolon
;
4983 c_parser_consume_token (parser
);
4984 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4986 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4987 c_parser_consume_token (parser
);
4991 location_t xloc
= c_parser_peek_token (parser
)->location
;
4992 struct c_expr expr
= c_parser_expression_conv (parser
);
4993 mark_exp_read (expr
.value
);
4994 stmt
= c_finish_return (xloc
, expr
.value
, expr
.original_type
);
4995 goto expect_semicolon
;
4999 stmt
= c_parser_asm_statement (parser
);
5001 case RID_TRANSACTION_ATOMIC
:
5002 case RID_TRANSACTION_RELAXED
:
5003 stmt
= c_parser_transaction (parser
,
5004 c_parser_peek_token (parser
)->keyword
);
5006 case RID_TRANSACTION_CANCEL
:
5007 stmt
= c_parser_transaction_cancel (parser
);
5008 goto expect_semicolon
;
5010 gcc_assert (c_dialect_objc ());
5011 c_parser_consume_token (parser
);
5012 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5014 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5015 c_parser_consume_token (parser
);
5019 struct c_expr expr
= c_parser_expression (parser
);
5020 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5021 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5022 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5023 goto expect_semicolon
;
5027 gcc_assert (c_dialect_objc ());
5028 c_parser_objc_try_catch_finally_statement (parser
);
5030 case RID_AT_SYNCHRONIZED
:
5031 gcc_assert (c_dialect_objc ());
5032 c_parser_objc_synchronized_statement (parser
);
5039 c_parser_consume_token (parser
);
5041 case CPP_CLOSE_PAREN
:
5042 case CPP_CLOSE_SQUARE
:
5043 /* Avoid infinite loop in error recovery:
5044 c_parser_skip_until_found stops at a closing nesting
5045 delimiter without consuming it, but here we need to consume
5046 it to proceed further. */
5047 c_parser_error (parser
, "expected statement");
5048 c_parser_consume_token (parser
);
5051 c_parser_pragma (parser
, pragma_stmt
);
5055 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5057 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5060 /* Two cases cannot and do not have line numbers associated: If stmt
5061 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5062 cannot hold line numbers. But that's OK because the statement
5063 will either be changed to a MODIFY_EXPR during gimplification of
5064 the statement expr, or discarded. If stmt was compound, but
5065 without new variables, we will have skipped the creation of a
5066 BIND and will have a bare STATEMENT_LIST. But that's OK because
5067 (recursively) all of the component statements should already have
5068 line numbers assigned. ??? Can we discard no-op statements
5070 if (CAN_HAVE_LOCATION_P (stmt
)
5071 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5072 SET_EXPR_LOCATION (stmt
, loc
);
5074 parser
->in_if_block
= in_if_block
;
5077 /* Parse the condition from an if, do, while or for statements. */
5080 c_parser_condition (c_parser
*parser
)
5082 location_t loc
= c_parser_peek_token (parser
)->location
;
5084 cond
= c_parser_expression_conv (parser
).value
;
5085 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5086 cond
= c_fully_fold (cond
, false, NULL
);
5087 if (warn_sequence_point
)
5088 verify_sequence_points (cond
);
5092 /* Parse a parenthesized condition from an if, do or while statement.
5098 c_parser_paren_condition (c_parser
*parser
)
5101 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5102 return error_mark_node
;
5103 cond
= c_parser_condition (parser
);
5104 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5108 /* Parse a statement which is a block in C99. */
5111 c_parser_c99_block_statement (c_parser
*parser
)
5113 tree block
= c_begin_compound_stmt (flag_isoc99
);
5114 location_t loc
= c_parser_peek_token (parser
)->location
;
5115 c_parser_statement (parser
);
5116 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5119 /* Parse the body of an if statement. This is just parsing a
5120 statement but (a) it is a block in C99, (b) we track whether the
5121 body is an if statement for the sake of -Wparentheses warnings, (c)
5122 we handle an empty body specially for the sake of -Wempty-body
5123 warnings, and (d) we call parser_compound_statement directly
5124 because c_parser_statement_after_labels resets
5125 parser->in_if_block. */
5128 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5130 tree block
= c_begin_compound_stmt (flag_isoc99
);
5131 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5132 c_parser_all_labels (parser
);
5133 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5134 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5136 location_t loc
= c_parser_peek_token (parser
)->location
;
5137 add_stmt (build_empty_stmt (loc
));
5138 c_parser_consume_token (parser
);
5139 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5140 warning_at (loc
, OPT_Wempty_body
,
5141 "suggest braces around empty body in an %<if%> statement");
5143 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5144 add_stmt (c_parser_compound_statement (parser
));
5146 c_parser_statement_after_labels (parser
);
5147 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5150 /* Parse the else body of an if statement. This is just parsing a
5151 statement but (a) it is a block in C99, (b) we handle an empty body
5152 specially for the sake of -Wempty-body warnings. */
5155 c_parser_else_body (c_parser
*parser
)
5157 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5158 tree block
= c_begin_compound_stmt (flag_isoc99
);
5159 c_parser_all_labels (parser
);
5160 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5162 location_t loc
= c_parser_peek_token (parser
)->location
;
5165 "suggest braces around empty body in an %<else%> statement");
5166 add_stmt (build_empty_stmt (loc
));
5167 c_parser_consume_token (parser
);
5170 c_parser_statement_after_labels (parser
);
5171 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5174 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5177 if ( expression ) statement
5178 if ( expression ) statement else statement
5182 c_parser_if_statement (c_parser
*parser
)
5187 bool first_if
= false;
5188 tree first_body
, second_body
;
5192 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5193 c_parser_consume_token (parser
);
5194 block
= c_begin_compound_stmt (flag_isoc99
);
5195 loc
= c_parser_peek_token (parser
)->location
;
5196 cond
= c_parser_paren_condition (parser
);
5197 in_if_block
= parser
->in_if_block
;
5198 parser
->in_if_block
= true;
5199 first_body
= c_parser_if_body (parser
, &first_if
);
5200 parser
->in_if_block
= in_if_block
;
5201 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5203 c_parser_consume_token (parser
);
5204 second_body
= c_parser_else_body (parser
);
5207 second_body
= NULL_TREE
;
5208 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5209 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5211 /* If the if statement contains array notations, then we expand them. */
5212 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5213 if_stmt
= fix_conditional_array_notations (if_stmt
);
5217 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5220 switch (expression) statement
5224 c_parser_switch_statement (c_parser
*parser
)
5227 tree block
, expr
, body
, save_break
;
5228 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5229 location_t switch_cond_loc
;
5230 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5231 c_parser_consume_token (parser
);
5232 block
= c_begin_compound_stmt (flag_isoc99
);
5233 bool explicit_cast_p
= false;
5234 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5236 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5237 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5238 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5239 explicit_cast_p
= true;
5240 ce
= c_parser_expression (parser
);
5241 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5243 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5245 error_at (switch_cond_loc
,
5246 "array notations cannot be used as a condition for switch "
5248 expr
= error_mark_node
;
5250 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5254 switch_cond_loc
= UNKNOWN_LOCATION
;
5255 expr
= error_mark_node
;
5257 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5258 save_break
= c_break_label
;
5259 c_break_label
= NULL_TREE
;
5260 body
= c_parser_c99_block_statement (parser
);
5261 c_finish_case (body
, ce
.original_type
);
5264 location_t here
= c_parser_peek_token (parser
)->location
;
5265 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5266 SET_EXPR_LOCATION (t
, here
);
5269 c_break_label
= save_break
;
5270 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5273 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5276 while (expression) statement
5280 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5282 tree block
, cond
, body
, save_break
, save_cont
;
5284 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5285 c_parser_consume_token (parser
);
5286 block
= c_begin_compound_stmt (flag_isoc99
);
5287 loc
= c_parser_peek_token (parser
)->location
;
5288 cond
= c_parser_paren_condition (parser
);
5289 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5291 error_at (loc
, "array notations cannot be used as a condition for while "
5293 cond
= error_mark_node
;
5296 if (ivdep
&& cond
!= error_mark_node
)
5297 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5298 build_int_cst (integer_type_node
,
5299 annot_expr_ivdep_kind
));
5300 save_break
= c_break_label
;
5301 c_break_label
= NULL_TREE
;
5302 save_cont
= c_cont_label
;
5303 c_cont_label
= NULL_TREE
;
5304 body
= c_parser_c99_block_statement (parser
);
5305 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5306 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5307 c_break_label
= save_break
;
5308 c_cont_label
= save_cont
;
5311 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5314 do statement while ( expression ) ;
5318 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5320 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5322 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5323 c_parser_consume_token (parser
);
5324 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5325 warning_at (c_parser_peek_token (parser
)->location
,
5327 "suggest braces around empty body in %<do%> statement");
5328 block
= c_begin_compound_stmt (flag_isoc99
);
5329 loc
= c_parser_peek_token (parser
)->location
;
5330 save_break
= c_break_label
;
5331 c_break_label
= NULL_TREE
;
5332 save_cont
= c_cont_label
;
5333 c_cont_label
= NULL_TREE
;
5334 body
= c_parser_c99_block_statement (parser
);
5335 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5336 new_break
= c_break_label
;
5337 c_break_label
= save_break
;
5338 new_cont
= c_cont_label
;
5339 c_cont_label
= save_cont
;
5340 cond
= c_parser_paren_condition (parser
);
5341 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5343 error_at (loc
, "array notations cannot be used as a condition for a "
5344 "do-while statement");
5345 cond
= error_mark_node
;
5347 if (ivdep
&& cond
!= error_mark_node
)
5348 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5349 build_int_cst (integer_type_node
,
5350 annot_expr_ivdep_kind
));
5351 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5352 c_parser_skip_to_end_of_block_or_statement (parser
);
5353 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5354 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5357 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5360 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5361 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5363 The form with a declaration is new in C99.
5365 ??? In accordance with the old parser, the declaration may be a
5366 nested function, which is then rejected in check_for_loop_decls,
5367 but does it make any sense for this to be included in the grammar?
5368 Note in particular that the nested function does not include a
5369 trailing ';', whereas the "declaration" production includes one.
5370 Also, can we reject bad declarations earlier and cheaper than
5371 check_for_loop_decls?
5373 In Objective-C, there are two additional variants:
5376 for ( expression in expresssion ) statement
5377 for ( declaration in expression ) statement
5379 This is inconsistent with C, because the second variant is allowed
5380 even if c99 is not enabled.
5382 The rest of the comment documents these Objective-C foreach-statement.
5384 Here is the canonical example of the first variant:
5385 for (object in array) { do something with object }
5386 we call the first expression ("object") the "object_expression" and
5387 the second expression ("array") the "collection_expression".
5388 object_expression must be an lvalue of type "id" (a generic Objective-C
5389 object) because the loop works by assigning to object_expression the
5390 various objects from the collection_expression. collection_expression
5391 must evaluate to something of type "id" which responds to the method
5392 countByEnumeratingWithState:objects:count:.
5394 The canonical example of the second variant is:
5395 for (id object in array) { do something with object }
5396 which is completely equivalent to
5399 for (object in array) { do something with object }
5401 Note that initizializing 'object' in some way (eg, "for ((object =
5402 xxx) in array) { do something with object }") is possibly
5403 technically valid, but completely pointless as 'object' will be
5404 assigned to something else as soon as the loop starts. We should
5405 most likely reject it (TODO).
5407 The beginning of the Objective-C foreach-statement looks exactly
5408 like the beginning of the for-statement, and we can tell it is a
5409 foreach-statement only because the initial declaration or
5410 expression is terminated by 'in' instead of ';'.
5414 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5416 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5417 /* The following are only used when parsing an ObjC foreach statement. */
5418 tree object_expression
;
5419 /* Silence the bogus uninitialized warning. */
5420 tree collection_expression
= NULL
;
5421 location_t loc
= c_parser_peek_token (parser
)->location
;
5422 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5423 bool is_foreach_statement
= false;
5424 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5425 c_parser_consume_token (parser
);
5426 /* Open a compound statement in Objective-C as well, just in case this is
5427 as foreach expression. */
5428 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5429 cond
= error_mark_node
;
5430 incr
= error_mark_node
;
5431 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5433 /* Parse the initialization declaration or expression. */
5434 object_expression
= error_mark_node
;
5435 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5436 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5438 parser
->objc_could_be_foreach_context
= false;
5439 c_parser_consume_token (parser
);
5440 c_finish_expr_stmt (loc
, NULL_TREE
);
5442 else if (c_parser_next_tokens_start_declaration (parser
))
5444 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5445 &object_expression
, vNULL
);
5446 parser
->objc_could_be_foreach_context
= false;
5448 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5450 c_parser_consume_token (parser
);
5451 is_foreach_statement
= true;
5452 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5453 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5456 check_for_loop_decls (for_loc
, flag_isoc99
);
5458 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5460 /* __extension__ can start a declaration, but is also an
5461 unary operator that can start an expression. Consume all
5462 but the last of a possible series of __extension__ to
5464 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5465 && (c_parser_peek_2nd_token (parser
)->keyword
5467 c_parser_consume_token (parser
);
5468 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5471 ext
= disable_extension_diagnostics ();
5472 c_parser_consume_token (parser
);
5473 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5474 true, &object_expression
, vNULL
);
5475 parser
->objc_could_be_foreach_context
= false;
5477 restore_extension_diagnostics (ext
);
5478 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5480 c_parser_consume_token (parser
);
5481 is_foreach_statement
= true;
5482 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5483 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5486 check_for_loop_decls (for_loc
, flag_isoc99
);
5496 tree init_expression
;
5497 ce
= c_parser_expression (parser
);
5498 init_expression
= ce
.value
;
5499 parser
->objc_could_be_foreach_context
= false;
5500 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5502 c_parser_consume_token (parser
);
5503 is_foreach_statement
= true;
5504 if (! lvalue_p (init_expression
))
5505 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5506 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5510 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5511 init_expression
= ce
.value
;
5512 c_finish_expr_stmt (loc
, init_expression
);
5513 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5517 /* Parse the loop condition. In the case of a foreach
5518 statement, there is no loop condition. */
5519 gcc_assert (!parser
->objc_could_be_foreach_context
);
5520 if (!is_foreach_statement
)
5522 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5526 c_parser_error (parser
, "missing loop condition in loop with "
5527 "%<GCC ivdep%> pragma");
5528 cond
= error_mark_node
;
5532 c_parser_consume_token (parser
);
5538 cond
= c_parser_condition (parser
);
5539 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5541 error_at (loc
, "array notations cannot be used in a "
5542 "condition for a for-loop");
5543 cond
= error_mark_node
;
5545 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5548 if (ivdep
&& cond
!= error_mark_node
)
5549 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5550 build_int_cst (integer_type_node
,
5551 annot_expr_ivdep_kind
));
5553 /* Parse the increment expression (the third expression in a
5554 for-statement). In the case of a foreach-statement, this is
5555 the expression that follows the 'in'. */
5556 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5558 if (is_foreach_statement
)
5560 c_parser_error (parser
, "missing collection in fast enumeration");
5561 collection_expression
= error_mark_node
;
5564 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5568 if (is_foreach_statement
)
5569 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5573 struct c_expr ce
= c_parser_expression (parser
);
5574 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5575 incr
= c_process_expr_stmt (loc
, ce
.value
);
5578 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5580 save_break
= c_break_label
;
5581 c_break_label
= NULL_TREE
;
5582 save_cont
= c_cont_label
;
5583 c_cont_label
= NULL_TREE
;
5584 body
= c_parser_c99_block_statement (parser
);
5585 if (is_foreach_statement
)
5586 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5588 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5589 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5590 c_break_label
= save_break
;
5591 c_cont_label
= save_cont
;
5594 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5595 statement with inputs, outputs, clobbers, and volatile tag
5599 asm type-qualifier[opt] ( asm-argument ) ;
5600 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5604 asm-string-literal : asm-operands[opt]
5605 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5606 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5609 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5612 Qualifiers other than volatile are accepted in the syntax but
5616 c_parser_asm_statement (c_parser
*parser
)
5618 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5619 bool simple
, is_goto
;
5620 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5621 int section
, nsections
;
5623 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5624 c_parser_consume_token (parser
);
5625 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5627 quals
= c_parser_peek_token (parser
)->value
;
5628 c_parser_consume_token (parser
);
5630 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5631 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5633 warning_at (c_parser_peek_token (parser
)->location
,
5635 "%E qualifier ignored on asm",
5636 c_parser_peek_token (parser
)->value
);
5638 c_parser_consume_token (parser
);
5644 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5646 c_parser_consume_token (parser
);
5650 /* ??? Follow the C++ parser rather than using the
5651 lex_untranslated_string kludge. */
5652 parser
->lex_untranslated_string
= true;
5655 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5658 str
= c_parser_asm_string_literal (parser
);
5659 if (str
== NULL_TREE
)
5660 goto error_close_paren
;
5663 outputs
= NULL_TREE
;
5665 clobbers
= NULL_TREE
;
5668 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5671 /* Parse each colon-delimited section of operands. */
5672 nsections
= 3 + is_goto
;
5673 for (section
= 0; section
< nsections
; ++section
)
5675 if (!c_parser_require (parser
, CPP_COLON
,
5678 : "expected %<:%> or %<)%>"))
5679 goto error_close_paren
;
5681 /* Once past any colon, we're no longer a simple asm. */
5684 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5685 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5690 /* For asm goto, we don't allow output operands, but reserve
5691 the slot for a future extension that does allow them. */
5693 outputs
= c_parser_asm_operands (parser
);
5696 inputs
= c_parser_asm_operands (parser
);
5699 clobbers
= c_parser_asm_clobbers (parser
);
5702 labels
= c_parser_asm_goto_operands (parser
);
5708 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5713 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5715 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5719 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5720 c_parser_skip_to_end_of_block_or_statement (parser
);
5722 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5723 clobbers
, labels
, simple
));
5726 parser
->lex_untranslated_string
= false;
5730 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5734 /* Parse asm operands, a GNU extension.
5738 asm-operands , asm-operand
5741 asm-string-literal ( expression )
5742 [ identifier ] asm-string-literal ( expression )
5746 c_parser_asm_operands (c_parser
*parser
)
5748 tree list
= NULL_TREE
;
5753 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5755 c_parser_consume_token (parser
);
5756 if (c_parser_next_token_is (parser
, CPP_NAME
))
5758 tree id
= c_parser_peek_token (parser
)->value
;
5759 c_parser_consume_token (parser
);
5760 name
= build_string (IDENTIFIER_LENGTH (id
),
5761 IDENTIFIER_POINTER (id
));
5765 c_parser_error (parser
, "expected identifier");
5766 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5769 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5774 str
= c_parser_asm_string_literal (parser
);
5775 if (str
== NULL_TREE
)
5777 parser
->lex_untranslated_string
= false;
5778 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5780 parser
->lex_untranslated_string
= true;
5783 expr
= c_parser_expression (parser
);
5784 mark_exp_read (expr
.value
);
5785 parser
->lex_untranslated_string
= true;
5786 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5788 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5791 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5793 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5794 c_parser_consume_token (parser
);
5801 /* Parse asm clobbers, a GNU extension.
5805 asm-clobbers , asm-string-literal
5809 c_parser_asm_clobbers (c_parser
*parser
)
5811 tree list
= NULL_TREE
;
5814 tree str
= c_parser_asm_string_literal (parser
);
5816 list
= tree_cons (NULL_TREE
, str
, list
);
5819 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5820 c_parser_consume_token (parser
);
5827 /* Parse asm goto labels, a GNU extension.
5831 asm-goto-operands , identifier
5835 c_parser_asm_goto_operands (c_parser
*parser
)
5837 tree list
= NULL_TREE
;
5842 if (c_parser_next_token_is (parser
, CPP_NAME
))
5844 c_token
*tok
= c_parser_peek_token (parser
);
5846 label
= lookup_label_for_goto (tok
->location
, name
);
5847 c_parser_consume_token (parser
);
5848 TREE_USED (label
) = 1;
5852 c_parser_error (parser
, "expected identifier");
5856 name
= build_string (IDENTIFIER_LENGTH (name
),
5857 IDENTIFIER_POINTER (name
));
5858 list
= tree_cons (name
, label
, list
);
5859 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5860 c_parser_consume_token (parser
);
5862 return nreverse (list
);
5866 /* Parse an expression other than a compound expression; that is, an
5867 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5868 NULL then it is an Objective-C message expression which is the
5869 primary-expression starting the expression as an initializer.
5871 assignment-expression:
5872 conditional-expression
5873 unary-expression assignment-operator assignment-expression
5875 assignment-operator: one of
5876 = *= /= %= += -= <<= >>= &= ^= |=
5878 In GNU C we accept any conditional expression on the LHS and
5879 diagnose the invalid lvalue rather than producing a syntax
5882 static struct c_expr
5883 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5884 tree omp_atomic_lhs
)
5886 struct c_expr lhs
, rhs
, ret
;
5887 enum tree_code code
;
5888 location_t op_location
, exp_location
;
5889 gcc_assert (!after
|| c_dialect_objc ());
5890 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5891 op_location
= c_parser_peek_token (parser
)->location
;
5892 switch (c_parser_peek_token (parser
)->type
)
5901 code
= TRUNC_DIV_EXPR
;
5904 code
= TRUNC_MOD_EXPR
;
5919 code
= BIT_AND_EXPR
;
5922 code
= BIT_XOR_EXPR
;
5925 code
= BIT_IOR_EXPR
;
5930 c_parser_consume_token (parser
);
5931 exp_location
= c_parser_peek_token (parser
)->location
;
5932 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5933 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5935 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5936 code
, exp_location
, rhs
.value
,
5938 if (code
== NOP_EXPR
)
5939 ret
.original_code
= MODIFY_EXPR
;
5942 TREE_NO_WARNING (ret
.value
) = 1;
5943 ret
.original_code
= ERROR_MARK
;
5945 ret
.original_type
= NULL
;
5949 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5950 is not NULL then it is an Objective-C message expression which is
5951 the primary-expression starting the expression as an initializer.
5953 conditional-expression:
5954 logical-OR-expression
5955 logical-OR-expression ? expression : conditional-expression
5959 conditional-expression:
5960 logical-OR-expression ? : conditional-expression
5963 static struct c_expr
5964 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5965 tree omp_atomic_lhs
)
5967 struct c_expr cond
, exp1
, exp2
, ret
;
5968 location_t cond_loc
, colon_loc
, middle_loc
;
5970 gcc_assert (!after
|| c_dialect_objc ());
5972 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5974 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5976 cond_loc
= c_parser_peek_token (parser
)->location
;
5977 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5978 c_parser_consume_token (parser
);
5979 if (c_parser_next_token_is (parser
, CPP_COLON
))
5981 tree eptype
= NULL_TREE
;
5983 middle_loc
= c_parser_peek_token (parser
)->location
;
5984 pedwarn (middle_loc
, OPT_Wpedantic
,
5985 "ISO C forbids omitting the middle term of a ?: expression");
5986 warn_for_omitted_condop (middle_loc
, cond
.value
);
5987 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5989 eptype
= TREE_TYPE (cond
.value
);
5990 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5992 /* Make sure first operand is calculated only once. */
5993 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5995 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5996 exp1
.original_type
= NULL
;
5997 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5998 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6003 = c_objc_common_truthvalue_conversion
6004 (cond_loc
, default_conversion (cond
.value
));
6005 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6006 exp1
= c_parser_expression_conv (parser
);
6007 mark_exp_read (exp1
.value
);
6008 c_inhibit_evaluation_warnings
+=
6009 ((cond
.value
== truthvalue_true_node
)
6010 - (cond
.value
== truthvalue_false_node
));
6013 colon_loc
= c_parser_peek_token (parser
)->location
;
6014 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6016 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6017 ret
.value
= error_mark_node
;
6018 ret
.original_code
= ERROR_MARK
;
6019 ret
.original_type
= NULL
;
6023 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6024 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6025 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6027 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6028 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6029 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6030 exp1
.value
, exp1
.original_type
,
6031 exp2
.value
, exp2
.original_type
);
6032 ret
.original_code
= ERROR_MARK
;
6033 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6034 ret
.original_type
= NULL
;
6039 /* If both sides are enum type, the default conversion will have
6040 made the type of the result be an integer type. We want to
6041 remember the enum types we started with. */
6042 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6043 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6044 ret
.original_type
= ((t1
!= error_mark_node
6045 && t2
!= error_mark_node
6046 && (TYPE_MAIN_VARIANT (t1
)
6047 == TYPE_MAIN_VARIANT (t2
)))
6054 /* Parse a binary expression; that is, a logical-OR-expression (C90
6055 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6056 an Objective-C message expression which is the primary-expression
6057 starting the expression as an initializer.
6059 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6060 when it should be the unfolded lhs. In a valid OpenMP source,
6061 one of the operands of the toplevel binary expression must be equal
6062 to it. In that case, just return a build2 created binary operation
6063 rather than result of parser_build_binary_op.
6065 multiplicative-expression:
6067 multiplicative-expression * cast-expression
6068 multiplicative-expression / cast-expression
6069 multiplicative-expression % cast-expression
6071 additive-expression:
6072 multiplicative-expression
6073 additive-expression + multiplicative-expression
6074 additive-expression - multiplicative-expression
6078 shift-expression << additive-expression
6079 shift-expression >> additive-expression
6081 relational-expression:
6083 relational-expression < shift-expression
6084 relational-expression > shift-expression
6085 relational-expression <= shift-expression
6086 relational-expression >= shift-expression
6088 equality-expression:
6089 relational-expression
6090 equality-expression == relational-expression
6091 equality-expression != relational-expression
6095 AND-expression & equality-expression
6097 exclusive-OR-expression:
6099 exclusive-OR-expression ^ AND-expression
6101 inclusive-OR-expression:
6102 exclusive-OR-expression
6103 inclusive-OR-expression | exclusive-OR-expression
6105 logical-AND-expression:
6106 inclusive-OR-expression
6107 logical-AND-expression && inclusive-OR-expression
6109 logical-OR-expression:
6110 logical-AND-expression
6111 logical-OR-expression || logical-AND-expression
6114 static struct c_expr
6115 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6116 tree omp_atomic_lhs
)
6118 /* A binary expression is parsed using operator-precedence parsing,
6119 with the operands being cast expressions. All the binary
6120 operators are left-associative. Thus a binary expression is of
6123 E0 op1 E1 op2 E2 ...
6125 which we represent on a stack. On the stack, the precedence
6126 levels are strictly increasing. When a new operator is
6127 encountered of higher precedence than that at the top of the
6128 stack, it is pushed; its LHS is the top expression, and its RHS
6129 is everything parsed until it is popped. When a new operator is
6130 encountered with precedence less than or equal to that at the top
6131 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6132 by the result of the operation until the operator at the top of
6133 the stack has lower precedence than the new operator or there is
6134 only one element on the stack; then the top expression is the LHS
6135 of the new operator. In the case of logical AND and OR
6136 expressions, we also need to adjust c_inhibit_evaluation_warnings
6137 as appropriate when the operators are pushed and popped. */
6140 /* The expression at this stack level. */
6142 /* The precedence of the operator on its left, PREC_NONE at the
6143 bottom of the stack. */
6144 enum c_parser_prec prec
;
6145 /* The operation on its left. */
6147 /* The source location of this operation. */
6151 /* Location of the binary operator. */
6152 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6155 switch (stack[sp].op) \
6157 case TRUTH_ANDIF_EXPR: \
6158 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6159 == truthvalue_false_node); \
6161 case TRUTH_ORIF_EXPR: \
6162 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6163 == truthvalue_true_node); \
6168 stack[sp - 1].expr \
6169 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6170 stack[sp - 1].expr, true, true); \
6172 = convert_lvalue_to_rvalue (stack[sp].loc, \
6173 stack[sp].expr, true, true); \
6174 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6175 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6176 && ((1 << stack[sp].prec) \
6177 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6178 | PREC_ADD | PREC_MULT))) \
6179 && stack[sp].op != TRUNC_MOD_EXPR \
6180 && stack[0].expr.value != error_mark_node \
6181 && stack[1].expr.value != error_mark_node \
6182 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6183 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6184 stack[0].expr.value \
6185 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6186 stack[0].expr.value, stack[1].expr.value); \
6188 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6190 stack[sp - 1].expr, \
6194 gcc_assert (!after
|| c_dialect_objc ());
6195 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6196 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6197 stack
[0].prec
= PREC_NONE
;
6201 enum c_parser_prec oprec
;
6202 enum tree_code ocode
;
6205 switch (c_parser_peek_token (parser
)->type
)
6213 ocode
= TRUNC_DIV_EXPR
;
6217 ocode
= TRUNC_MOD_EXPR
;
6229 ocode
= LSHIFT_EXPR
;
6233 ocode
= RSHIFT_EXPR
;
6247 case CPP_GREATER_EQ
:
6260 oprec
= PREC_BITAND
;
6261 ocode
= BIT_AND_EXPR
;
6264 oprec
= PREC_BITXOR
;
6265 ocode
= BIT_XOR_EXPR
;
6269 ocode
= BIT_IOR_EXPR
;
6272 oprec
= PREC_LOGAND
;
6273 ocode
= TRUTH_ANDIF_EXPR
;
6277 ocode
= TRUTH_ORIF_EXPR
;
6280 /* Not a binary operator, so end of the binary
6284 binary_loc
= c_parser_peek_token (parser
)->location
;
6285 while (oprec
<= stack
[sp
].prec
)
6287 c_parser_consume_token (parser
);
6290 case TRUTH_ANDIF_EXPR
:
6292 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6293 stack
[sp
].expr
, true, true);
6294 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6295 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6296 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6297 == truthvalue_false_node
);
6299 case TRUTH_ORIF_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_true_node
);
6312 stack
[sp
].loc
= binary_loc
;
6313 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6314 stack
[sp
].prec
= oprec
;
6315 stack
[sp
].op
= ocode
;
6316 stack
[sp
].loc
= binary_loc
;
6321 return stack
[0].expr
;
6325 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6326 NULL then it is an Objective-C message expression which is the
6327 primary-expression starting the expression as an initializer.
6331 ( type-name ) unary-expression
6334 static struct c_expr
6335 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6337 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6338 gcc_assert (!after
|| c_dialect_objc ());
6340 return c_parser_postfix_expression_after_primary (parser
,
6342 /* If the expression begins with a parenthesized type name, it may
6343 be either a cast or a compound literal; we need to see whether
6344 the next character is '{' to tell the difference. If not, it is
6345 an unary expression. Full detection of unknown typenames here
6346 would require a 3-token lookahead. */
6347 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6348 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6350 struct c_type_name
*type_name
;
6353 c_parser_consume_token (parser
);
6354 type_name
= c_parser_type_name (parser
);
6355 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6356 if (type_name
== NULL
)
6358 ret
.value
= error_mark_node
;
6359 ret
.original_code
= ERROR_MARK
;
6360 ret
.original_type
= NULL
;
6364 /* Save casted types in the function's used types hash table. */
6365 used_types_insert (type_name
->specs
->type
);
6367 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6368 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6371 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6372 expr
= c_parser_cast_expression (parser
, NULL
);
6373 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6375 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6376 ret
.original_code
= ERROR_MARK
;
6377 ret
.original_type
= NULL
;
6381 return c_parser_unary_expression (parser
);
6384 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6390 unary-operator cast-expression
6391 sizeof unary-expression
6392 sizeof ( type-name )
6394 unary-operator: one of
6400 __alignof__ unary-expression
6401 __alignof__ ( type-name )
6404 (C11 permits _Alignof with type names only.)
6406 unary-operator: one of
6407 __extension__ __real__ __imag__
6409 Transactional Memory:
6412 transaction-expression
6414 In addition, the GNU syntax treats ++ and -- as unary operators, so
6415 they may be applied to cast expressions with errors for non-lvalues
6418 static struct c_expr
6419 c_parser_unary_expression (c_parser
*parser
)
6422 struct c_expr ret
, op
;
6423 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6425 ret
.original_code
= ERROR_MARK
;
6426 ret
.original_type
= NULL
;
6427 switch (c_parser_peek_token (parser
)->type
)
6430 c_parser_consume_token (parser
);
6431 exp_loc
= c_parser_peek_token (parser
)->location
;
6432 op
= c_parser_cast_expression (parser
, NULL
);
6434 /* If there is array notations in op, we expand them. */
6435 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6436 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6439 op
= default_function_array_read_conversion (exp_loc
, op
);
6440 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6442 case CPP_MINUS_MINUS
:
6443 c_parser_consume_token (parser
);
6444 exp_loc
= c_parser_peek_token (parser
)->location
;
6445 op
= c_parser_cast_expression (parser
, NULL
);
6447 /* If there is array notations in op, we expand them. */
6448 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6449 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6452 op
= default_function_array_read_conversion (exp_loc
, op
);
6453 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6456 c_parser_consume_token (parser
);
6457 op
= c_parser_cast_expression (parser
, NULL
);
6458 mark_exp_read (op
.value
);
6459 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6461 c_parser_consume_token (parser
);
6462 exp_loc
= c_parser_peek_token (parser
)->location
;
6463 op
= c_parser_cast_expression (parser
, NULL
);
6464 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6465 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6468 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6471 "traditional C rejects the unary plus operator");
6472 c_parser_consume_token (parser
);
6473 exp_loc
= c_parser_peek_token (parser
)->location
;
6474 op
= c_parser_cast_expression (parser
, NULL
);
6475 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6476 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6478 c_parser_consume_token (parser
);
6479 exp_loc
= c_parser_peek_token (parser
)->location
;
6480 op
= c_parser_cast_expression (parser
, NULL
);
6481 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6482 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6484 c_parser_consume_token (parser
);
6485 exp_loc
= c_parser_peek_token (parser
)->location
;
6486 op
= c_parser_cast_expression (parser
, NULL
);
6487 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6488 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6490 c_parser_consume_token (parser
);
6491 exp_loc
= c_parser_peek_token (parser
)->location
;
6492 op
= c_parser_cast_expression (parser
, NULL
);
6493 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6494 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6496 /* Refer to the address of a label as a pointer. */
6497 c_parser_consume_token (parser
);
6498 if (c_parser_next_token_is (parser
, CPP_NAME
))
6500 ret
.value
= finish_label_address_expr
6501 (c_parser_peek_token (parser
)->value
, op_loc
);
6502 c_parser_consume_token (parser
);
6506 c_parser_error (parser
, "expected identifier");
6507 ret
.value
= error_mark_node
;
6511 switch (c_parser_peek_token (parser
)->keyword
)
6514 return c_parser_sizeof_expression (parser
);
6516 return c_parser_alignof_expression (parser
);
6518 c_parser_consume_token (parser
);
6519 ext
= disable_extension_diagnostics ();
6520 ret
= c_parser_cast_expression (parser
, NULL
);
6521 restore_extension_diagnostics (ext
);
6524 c_parser_consume_token (parser
);
6525 exp_loc
= c_parser_peek_token (parser
)->location
;
6526 op
= c_parser_cast_expression (parser
, NULL
);
6527 op
= default_function_array_conversion (exp_loc
, op
);
6528 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6530 c_parser_consume_token (parser
);
6531 exp_loc
= c_parser_peek_token (parser
)->location
;
6532 op
= c_parser_cast_expression (parser
, NULL
);
6533 op
= default_function_array_conversion (exp_loc
, op
);
6534 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6535 case RID_TRANSACTION_ATOMIC
:
6536 case RID_TRANSACTION_RELAXED
:
6537 return c_parser_transaction_expression (parser
,
6538 c_parser_peek_token (parser
)->keyword
);
6540 return c_parser_postfix_expression (parser
);
6543 return c_parser_postfix_expression (parser
);
6547 /* Parse a sizeof expression. */
6549 static struct c_expr
6550 c_parser_sizeof_expression (c_parser
*parser
)
6553 location_t expr_loc
;
6554 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6555 c_parser_consume_token (parser
);
6556 c_inhibit_evaluation_warnings
++;
6558 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6559 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6561 /* Either sizeof ( type-name ) or sizeof unary-expression
6562 starting with a compound literal. */
6563 struct c_type_name
*type_name
;
6564 c_parser_consume_token (parser
);
6565 expr_loc
= c_parser_peek_token (parser
)->location
;
6566 type_name
= c_parser_type_name (parser
);
6567 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6568 if (type_name
== NULL
)
6571 c_inhibit_evaluation_warnings
--;
6573 ret
.value
= error_mark_node
;
6574 ret
.original_code
= ERROR_MARK
;
6575 ret
.original_type
= NULL
;
6578 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6580 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6585 /* sizeof ( type-name ). */
6586 c_inhibit_evaluation_warnings
--;
6588 return c_expr_sizeof_type (expr_loc
, type_name
);
6592 expr_loc
= c_parser_peek_token (parser
)->location
;
6593 expr
= c_parser_unary_expression (parser
);
6595 c_inhibit_evaluation_warnings
--;
6597 mark_exp_read (expr
.value
);
6598 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6599 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6600 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6601 return c_expr_sizeof_expr (expr_loc
, expr
);
6605 /* Parse an alignof expression. */
6607 static struct c_expr
6608 c_parser_alignof_expression (c_parser
*parser
)
6611 location_t loc
= c_parser_peek_token (parser
)->location
;
6612 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6613 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6614 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6616 /* A diagnostic is not required for the use of this identifier in
6617 the implementation namespace; only diagnose it for the C11
6618 spelling because of existing code using the other spellings. */
6622 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6625 pedwarn_c99 (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6628 c_parser_consume_token (parser
);
6629 c_inhibit_evaluation_warnings
++;
6631 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6632 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6634 /* Either __alignof__ ( type-name ) or __alignof__
6635 unary-expression starting with a compound literal. */
6637 struct c_type_name
*type_name
;
6639 c_parser_consume_token (parser
);
6640 loc
= c_parser_peek_token (parser
)->location
;
6641 type_name
= c_parser_type_name (parser
);
6642 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6643 if (type_name
== NULL
)
6646 c_inhibit_evaluation_warnings
--;
6648 ret
.value
= error_mark_node
;
6649 ret
.original_code
= ERROR_MARK
;
6650 ret
.original_type
= NULL
;
6653 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6655 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6660 /* alignof ( type-name ). */
6661 c_inhibit_evaluation_warnings
--;
6663 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6665 false, is_c11_alignof
, 1);
6666 ret
.original_code
= ERROR_MARK
;
6667 ret
.original_type
= NULL
;
6673 expr
= c_parser_unary_expression (parser
);
6675 mark_exp_read (expr
.value
);
6676 c_inhibit_evaluation_warnings
--;
6678 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6680 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6681 ret
.original_code
= ERROR_MARK
;
6682 ret
.original_type
= NULL
;
6687 /* Helper function to read arguments of builtins which are interfaces
6688 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6689 others. The name of the builtin is passed using BNAME parameter.
6690 Function returns true if there were no errors while parsing and
6691 stores the arguments in CEXPR_LIST. */
6693 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6694 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6697 location_t loc
= c_parser_peek_token (parser
)->location
;
6698 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6700 bool saved_force_folding_builtin_constant_p
;
6702 *ret_cexpr_list
= NULL
;
6703 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6705 error_at (loc
, "cannot take address of %qs", bname
);
6709 c_parser_consume_token (parser
);
6711 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6713 c_parser_consume_token (parser
);
6717 saved_force_folding_builtin_constant_p
6718 = force_folding_builtin_constant_p
;
6719 force_folding_builtin_constant_p
|= choose_expr_p
;
6720 expr
= c_parser_expr_no_commas (parser
, NULL
);
6721 force_folding_builtin_constant_p
6722 = saved_force_folding_builtin_constant_p
;
6723 vec_alloc (cexpr_list
, 1);
6724 vec_safe_push (cexpr_list
, expr
);
6725 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6727 c_parser_consume_token (parser
);
6728 expr
= c_parser_expr_no_commas (parser
, NULL
);
6729 vec_safe_push (cexpr_list
, expr
);
6732 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6735 *ret_cexpr_list
= cexpr_list
;
6739 /* This represents a single generic-association. */
6741 struct c_generic_association
6743 /* The location of the starting token of the type. */
6744 location_t type_location
;
6745 /* The association's type, or NULL_TREE for 'default'. */
6747 /* The association's expression. */
6748 struct c_expr expression
;
6751 /* Parse a generic-selection. (C11 6.5.1.1).
6754 _Generic ( assignment-expression , generic-assoc-list )
6758 generic-assoc-list , generic-association
6760 generic-association:
6761 type-name : assignment-expression
6762 default : assignment-expression
6765 static struct c_expr
6766 c_parser_generic_selection (c_parser
*parser
)
6768 vec
<c_generic_association
> associations
= vNULL
;
6769 struct c_expr selector
, error_expr
;
6771 struct c_generic_association matched_assoc
;
6772 bool match_found
= false;
6773 location_t generic_loc
, selector_loc
;
6775 error_expr
.original_code
= ERROR_MARK
;
6776 error_expr
.original_type
= NULL
;
6777 error_expr
.value
= error_mark_node
;
6778 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6779 matched_assoc
.type
= NULL_TREE
;
6780 matched_assoc
.expression
= error_expr
;
6782 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6783 generic_loc
= c_parser_peek_token (parser
)->location
;
6784 c_parser_consume_token (parser
);
6786 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6787 "ISO C99 does not support %<_Generic%>");
6789 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
6790 "ISO C90 does not support %<_Generic%>");
6792 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6795 c_inhibit_evaluation_warnings
++;
6796 selector_loc
= c_parser_peek_token (parser
)->location
;
6797 selector
= c_parser_expr_no_commas (parser
, NULL
);
6798 selector
= default_function_array_conversion (selector_loc
, selector
);
6799 c_inhibit_evaluation_warnings
--;
6801 if (selector
.value
== error_mark_node
)
6803 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6806 selector_type
= TREE_TYPE (selector
.value
);
6807 /* In ISO C terms, rvalues (including the controlling expression of
6808 _Generic) do not have qualified types. */
6809 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6810 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6811 /* In ISO C terms, _Noreturn is not part of the type of expressions
6812 such as &abort, but in GCC it is represented internally as a type
6814 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6815 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6817 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6819 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6821 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6827 struct c_generic_association assoc
, *iter
;
6829 c_token
*token
= c_parser_peek_token (parser
);
6831 assoc
.type_location
= token
->location
;
6832 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6834 c_parser_consume_token (parser
);
6835 assoc
.type
= NULL_TREE
;
6839 struct c_type_name
*type_name
;
6841 type_name
= c_parser_type_name (parser
);
6842 if (type_name
== NULL
)
6844 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6847 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6848 if (assoc
.type
== error_mark_node
)
6850 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6854 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6855 error_at (assoc
.type_location
,
6856 "%<_Generic%> association has function type");
6857 else if (!COMPLETE_TYPE_P (assoc
.type
))
6858 error_at (assoc
.type_location
,
6859 "%<_Generic%> association has incomplete type");
6861 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6862 error_at (assoc
.type_location
,
6863 "%<_Generic%> association has "
6864 "variable length type");
6867 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6869 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6873 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6874 if (assoc
.expression
.value
== error_mark_node
)
6876 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6880 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6882 if (assoc
.type
== NULL_TREE
)
6884 if (iter
->type
== NULL_TREE
)
6886 error_at (assoc
.type_location
,
6887 "duplicate %<default%> case in %<_Generic%>");
6888 inform (iter
->type_location
, "original %<default%> is here");
6891 else if (iter
->type
!= NULL_TREE
)
6893 if (comptypes (assoc
.type
, iter
->type
))
6895 error_at (assoc
.type_location
,
6896 "%<_Generic%> specifies two compatible types");
6897 inform (iter
->type_location
, "compatible type is here");
6902 if (assoc
.type
== NULL_TREE
)
6906 matched_assoc
= assoc
;
6910 else if (comptypes (assoc
.type
, selector_type
))
6912 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6914 matched_assoc
= assoc
;
6919 error_at (assoc
.type_location
,
6920 "%<_Generic> selector matches multiple associations");
6921 inform (matched_assoc
.type_location
,
6922 "other match is here");
6926 associations
.safe_push (assoc
);
6928 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6930 c_parser_consume_token (parser
);
6933 associations
.release ();
6935 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6943 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6944 "compatible with any association",
6949 return matched_assoc
.expression
;
6952 associations
.release ();
6956 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6960 postfix-expression [ expression ]
6961 postfix-expression ( argument-expression-list[opt] )
6962 postfix-expression . identifier
6963 postfix-expression -> identifier
6964 postfix-expression ++
6965 postfix-expression --
6966 ( type-name ) { initializer-list }
6967 ( type-name ) { initializer-list , }
6969 argument-expression-list:
6971 argument-expression-list , argument-expression
6984 (treated as a keyword in GNU C)
6987 ( compound-statement )
6988 __builtin_va_arg ( assignment-expression , type-name )
6989 __builtin_offsetof ( type-name , offsetof-member-designator )
6990 __builtin_choose_expr ( assignment-expression ,
6991 assignment-expression ,
6992 assignment-expression )
6993 __builtin_types_compatible_p ( type-name , type-name )
6994 __builtin_complex ( assignment-expression , assignment-expression )
6995 __builtin_shuffle ( assignment-expression , assignment-expression )
6996 __builtin_shuffle ( assignment-expression ,
6997 assignment-expression ,
6998 assignment-expression, )
7000 offsetof-member-designator:
7002 offsetof-member-designator . identifier
7003 offsetof-member-designator [ expression ]
7008 [ objc-receiver objc-message-args ]
7009 @selector ( objc-selector-arg )
7010 @protocol ( identifier )
7011 @encode ( type-name )
7013 Classname . identifier
7016 static struct c_expr
7017 c_parser_postfix_expression (c_parser
*parser
)
7019 struct c_expr expr
, e1
;
7020 struct c_type_name
*t1
, *t2
;
7021 location_t loc
= c_parser_peek_token (parser
)->location
;;
7022 expr
.original_code
= ERROR_MARK
;
7023 expr
.original_type
= NULL
;
7024 switch (c_parser_peek_token (parser
)->type
)
7027 expr
.value
= c_parser_peek_token (parser
)->value
;
7028 loc
= c_parser_peek_token (parser
)->location
;
7029 c_parser_consume_token (parser
);
7030 if (TREE_CODE (expr
.value
) == FIXED_CST
7031 && !targetm
.fixed_point_supported_p ())
7033 error_at (loc
, "fixed-point types not supported for this target");
7034 expr
.value
= error_mark_node
;
7041 expr
.value
= c_parser_peek_token (parser
)->value
;
7042 c_parser_consume_token (parser
);
7048 case CPP_UTF8STRING
:
7049 expr
.value
= c_parser_peek_token (parser
)->value
;
7050 expr
.original_code
= STRING_CST
;
7051 c_parser_consume_token (parser
);
7053 case CPP_OBJC_STRING
:
7054 gcc_assert (c_dialect_objc ());
7056 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7057 c_parser_consume_token (parser
);
7060 switch (c_parser_peek_token (parser
)->id_kind
)
7064 tree id
= c_parser_peek_token (parser
)->value
;
7065 c_parser_consume_token (parser
);
7066 expr
.value
= build_external_ref (loc
, id
,
7067 (c_parser_peek_token (parser
)->type
7069 &expr
.original_type
);
7072 case C_ID_CLASSNAME
:
7074 /* Here we parse the Objective-C 2.0 Class.name dot
7076 tree class_name
= c_parser_peek_token (parser
)->value
;
7078 c_parser_consume_token (parser
);
7079 gcc_assert (c_dialect_objc ());
7080 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7082 expr
.value
= error_mark_node
;
7085 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7087 c_parser_error (parser
, "expected identifier");
7088 expr
.value
= error_mark_node
;
7091 component
= c_parser_peek_token (parser
)->value
;
7092 c_parser_consume_token (parser
);
7093 expr
.value
= objc_build_class_component_ref (class_name
,
7098 c_parser_error (parser
, "expected expression");
7099 expr
.value
= error_mark_node
;
7103 case CPP_OPEN_PAREN
:
7104 /* A parenthesized expression, statement expression or compound
7106 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7108 /* A statement expression. */
7110 location_t brace_loc
;
7111 c_parser_consume_token (parser
);
7112 brace_loc
= c_parser_peek_token (parser
)->location
;
7113 c_parser_consume_token (parser
);
7114 if (!building_stmt_list_p ())
7116 error_at (loc
, "braced-group within expression allowed "
7117 "only inside a function");
7118 parser
->error
= true;
7119 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7120 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7121 expr
.value
= error_mark_node
;
7124 stmt
= c_begin_stmt_expr ();
7125 c_parser_compound_statement_nostart (parser
);
7126 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7128 pedwarn (loc
, OPT_Wpedantic
,
7129 "ISO C forbids braced-groups within expressions");
7130 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7131 mark_exp_read (expr
.value
);
7133 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7135 /* A compound literal. ??? Can we actually get here rather
7136 than going directly to
7137 c_parser_postfix_expression_after_paren_type from
7140 struct c_type_name
*type_name
;
7141 c_parser_consume_token (parser
);
7142 loc
= c_parser_peek_token (parser
)->location
;
7143 type_name
= c_parser_type_name (parser
);
7144 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7146 if (type_name
== NULL
)
7148 expr
.value
= error_mark_node
;
7151 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7157 /* A parenthesized expression. */
7158 c_parser_consume_token (parser
);
7159 expr
= c_parser_expression (parser
);
7160 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7161 TREE_NO_WARNING (expr
.value
) = 1;
7162 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7163 expr
.original_code
= ERROR_MARK
;
7164 /* Don't change EXPR.ORIGINAL_TYPE. */
7165 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7170 switch (c_parser_peek_token (parser
)->keyword
)
7172 case RID_FUNCTION_NAME
:
7173 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7174 "%<__FUNCTION__%> predefined identifier");
7175 expr
.value
= fname_decl (loc
,
7176 c_parser_peek_token (parser
)->keyword
,
7177 c_parser_peek_token (parser
)->value
);
7178 c_parser_consume_token (parser
);
7180 case RID_PRETTY_FUNCTION_NAME
:
7181 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7182 "%<__PRETTY_FUNCTION__%> predefined identifier");
7183 expr
.value
= fname_decl (loc
,
7184 c_parser_peek_token (parser
)->keyword
,
7185 c_parser_peek_token (parser
)->value
);
7186 c_parser_consume_token (parser
);
7188 case RID_C99_FUNCTION_NAME
:
7189 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7190 "%<__func__%> predefined identifier");
7191 expr
.value
= fname_decl (loc
,
7192 c_parser_peek_token (parser
)->keyword
,
7193 c_parser_peek_token (parser
)->value
);
7194 c_parser_consume_token (parser
);
7197 c_parser_consume_token (parser
);
7198 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7200 expr
.value
= error_mark_node
;
7203 e1
= c_parser_expr_no_commas (parser
, NULL
);
7204 mark_exp_read (e1
.value
);
7205 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7206 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7208 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7209 expr
.value
= error_mark_node
;
7212 loc
= c_parser_peek_token (parser
)->location
;
7213 t1
= c_parser_type_name (parser
);
7214 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7218 expr
.value
= error_mark_node
;
7222 tree type_expr
= NULL_TREE
;
7223 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7224 groktypename (t1
, &type_expr
, NULL
));
7227 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7228 TREE_TYPE (expr
.value
), type_expr
,
7230 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7235 c_parser_consume_token (parser
);
7236 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7238 expr
.value
= error_mark_node
;
7241 t1
= c_parser_type_name (parser
);
7243 parser
->error
= true;
7244 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7245 gcc_assert (parser
->error
);
7248 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7249 expr
.value
= error_mark_node
;
7254 tree type
= groktypename (t1
, NULL
, NULL
);
7256 if (type
== error_mark_node
)
7257 offsetof_ref
= error_mark_node
;
7260 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7261 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7263 /* Parse the second argument to __builtin_offsetof. We
7264 must have one identifier, and beyond that we want to
7265 accept sub structure and sub array references. */
7266 if (c_parser_next_token_is (parser
, CPP_NAME
))
7268 offsetof_ref
= build_component_ref
7269 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7270 c_parser_consume_token (parser
);
7271 while (c_parser_next_token_is (parser
, CPP_DOT
)
7272 || c_parser_next_token_is (parser
,
7274 || c_parser_next_token_is (parser
,
7277 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7279 loc
= c_parser_peek_token (parser
)->location
;
7280 offsetof_ref
= build_array_ref (loc
,
7285 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7288 c_parser_consume_token (parser
);
7289 if (c_parser_next_token_is_not (parser
,
7292 c_parser_error (parser
, "expected identifier");
7295 offsetof_ref
= build_component_ref
7297 c_parser_peek_token (parser
)->value
);
7298 c_parser_consume_token (parser
);
7304 loc
= c_parser_peek_token (parser
)->location
;
7305 c_parser_consume_token (parser
);
7306 ce
= c_parser_expression (parser
);
7307 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7309 idx
= c_fully_fold (idx
, false, NULL
);
7310 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7312 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7317 c_parser_error (parser
, "expected identifier");
7318 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7320 expr
.value
= fold_offsetof (offsetof_ref
);
7323 case RID_CHOOSE_EXPR
:
7325 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7326 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7329 c_parser_consume_token (parser
);
7330 if (!c_parser_get_builtin_args (parser
,
7331 "__builtin_choose_expr",
7334 expr
.value
= error_mark_node
;
7338 if (vec_safe_length (cexpr_list
) != 3)
7340 error_at (loc
, "wrong number of arguments to "
7341 "%<__builtin_choose_expr%>");
7342 expr
.value
= error_mark_node
;
7346 e1_p
= &(*cexpr_list
)[0];
7347 e2_p
= &(*cexpr_list
)[1];
7348 e3_p
= &(*cexpr_list
)[2];
7351 mark_exp_read (e2_p
->value
);
7352 mark_exp_read (e3_p
->value
);
7353 if (TREE_CODE (c
) != INTEGER_CST
7354 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7356 "first argument to %<__builtin_choose_expr%> not"
7358 constant_expression_warning (c
);
7359 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7362 case RID_TYPES_COMPATIBLE_P
:
7363 c_parser_consume_token (parser
);
7364 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7366 expr
.value
= error_mark_node
;
7369 t1
= c_parser_type_name (parser
);
7372 expr
.value
= error_mark_node
;
7375 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7377 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7378 expr
.value
= error_mark_node
;
7381 t2
= c_parser_type_name (parser
);
7384 expr
.value
= error_mark_node
;
7387 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7391 e1
= groktypename (t1
, NULL
, NULL
);
7392 e2
= groktypename (t2
, NULL
, NULL
);
7393 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7395 expr
.value
= error_mark_node
;
7399 e1
= TYPE_MAIN_VARIANT (e1
);
7400 e2
= TYPE_MAIN_VARIANT (e2
);
7403 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7406 case RID_BUILTIN_COMPLEX
:
7408 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7409 c_expr_t
*e1_p
, *e2_p
;
7411 c_parser_consume_token (parser
);
7412 if (!c_parser_get_builtin_args (parser
,
7413 "__builtin_complex",
7414 &cexpr_list
, false))
7416 expr
.value
= error_mark_node
;
7420 if (vec_safe_length (cexpr_list
) != 2)
7422 error_at (loc
, "wrong number of arguments to "
7423 "%<__builtin_complex%>");
7424 expr
.value
= error_mark_node
;
7428 e1_p
= &(*cexpr_list
)[0];
7429 e2_p
= &(*cexpr_list
)[1];
7431 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7432 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7433 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7434 TREE_OPERAND (e1_p
->value
, 0));
7435 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7436 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7437 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7438 TREE_OPERAND (e2_p
->value
, 0));
7439 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7440 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7441 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7442 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7444 error_at (loc
, "%<__builtin_complex%> operand "
7445 "not of real binary floating-point type");
7446 expr
.value
= error_mark_node
;
7449 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7450 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7453 "%<__builtin_complex%> operands of different types");
7454 expr
.value
= error_mark_node
;
7457 pedwarn_c90 (loc
, OPT_Wpedantic
,
7458 "ISO C90 does not support complex types");
7459 expr
.value
= build2 (COMPLEX_EXPR
,
7462 (TREE_TYPE (e1_p
->value
))),
7463 e1_p
->value
, e2_p
->value
);
7466 case RID_BUILTIN_SHUFFLE
:
7468 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7472 c_parser_consume_token (parser
);
7473 if (!c_parser_get_builtin_args (parser
,
7474 "__builtin_shuffle",
7475 &cexpr_list
, false))
7477 expr
.value
= error_mark_node
;
7481 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7482 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7484 if (vec_safe_length (cexpr_list
) == 2)
7486 c_build_vec_perm_expr
7487 (loc
, (*cexpr_list
)[0].value
,
7488 NULL_TREE
, (*cexpr_list
)[1].value
);
7490 else if (vec_safe_length (cexpr_list
) == 3)
7492 c_build_vec_perm_expr
7493 (loc
, (*cexpr_list
)[0].value
,
7494 (*cexpr_list
)[1].value
,
7495 (*cexpr_list
)[2].value
);
7498 error_at (loc
, "wrong number of arguments to "
7499 "%<__builtin_shuffle%>");
7500 expr
.value
= error_mark_node
;
7504 case RID_AT_SELECTOR
:
7505 gcc_assert (c_dialect_objc ());
7506 c_parser_consume_token (parser
);
7507 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7509 expr
.value
= error_mark_node
;
7513 tree sel
= c_parser_objc_selector_arg (parser
);
7514 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7516 expr
.value
= objc_build_selector_expr (loc
, sel
);
7519 case RID_AT_PROTOCOL
:
7520 gcc_assert (c_dialect_objc ());
7521 c_parser_consume_token (parser
);
7522 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7524 expr
.value
= error_mark_node
;
7527 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7529 c_parser_error (parser
, "expected identifier");
7530 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7531 expr
.value
= error_mark_node
;
7535 tree id
= c_parser_peek_token (parser
)->value
;
7536 c_parser_consume_token (parser
);
7537 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7539 expr
.value
= objc_build_protocol_expr (id
);
7543 /* Extension to support C-structures in the archiver. */
7544 gcc_assert (c_dialect_objc ());
7545 c_parser_consume_token (parser
);
7546 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7548 expr
.value
= error_mark_node
;
7551 t1
= c_parser_type_name (parser
);
7554 expr
.value
= error_mark_node
;
7555 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7558 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7561 tree type
= groktypename (t1
, NULL
, NULL
);
7562 expr
.value
= objc_build_encode_expr (type
);
7566 expr
= c_parser_generic_selection (parser
);
7568 case RID_CILK_SPAWN
:
7569 c_parser_consume_token (parser
);
7572 error_at (loc
, "-fcilkplus must be enabled to use "
7574 expr
= c_parser_postfix_expression (parser
);
7575 expr
.value
= error_mark_node
;
7577 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7579 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7580 "are not permitted");
7581 /* Now flush out all the _Cilk_spawns. */
7582 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7583 c_parser_consume_token (parser
);
7584 expr
= c_parser_postfix_expression (parser
);
7588 expr
= c_parser_postfix_expression (parser
);
7589 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7593 c_parser_error (parser
, "expected expression");
7594 expr
.value
= error_mark_node
;
7598 case CPP_OPEN_SQUARE
:
7599 if (c_dialect_objc ())
7601 tree receiver
, args
;
7602 c_parser_consume_token (parser
);
7603 receiver
= c_parser_objc_receiver (parser
);
7604 args
= c_parser_objc_message_args (parser
);
7605 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7607 expr
.value
= objc_build_message_expr (receiver
, args
);
7610 /* Else fall through to report error. */
7612 c_parser_error (parser
, "expected expression");
7613 expr
.value
= error_mark_node
;
7616 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7619 /* Parse a postfix expression after a parenthesized type name: the
7620 brace-enclosed initializer of a compound literal, possibly followed
7621 by some postfix operators. This is separate because it is not
7622 possible to tell until after the type name whether a cast
7623 expression has a cast or a compound literal, or whether the operand
7624 of sizeof is a parenthesized type name or starts with a compound
7625 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7626 location of the first token after the parentheses around the type
7629 static struct c_expr
7630 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7631 struct c_type_name
*type_name
,
7632 location_t type_loc
)
7638 location_t start_loc
;
7639 tree type_expr
= NULL_TREE
;
7640 bool type_expr_const
= true;
7641 check_compound_literal_type (type_loc
, type_name
);
7642 start_init (NULL_TREE
, NULL
, 0);
7643 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7644 start_loc
= c_parser_peek_token (parser
)->location
;
7645 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7647 error_at (type_loc
, "compound literal has variable size");
7648 type
= error_mark_node
;
7650 init
= c_parser_braced_init (parser
, type
, false);
7652 maybe_warn_string_init (type_loc
, type
, init
);
7654 if (type
!= error_mark_node
7655 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7656 && current_function_decl
)
7658 error ("compound literal qualified by address-space qualifier");
7659 type
= error_mark_node
;
7662 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7663 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7664 ? CONSTRUCTOR_NON_CONST (init
.value
)
7665 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7666 non_const
|= !type_expr_const
;
7667 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7668 expr
.original_code
= ERROR_MARK
;
7669 expr
.original_type
= NULL
;
7672 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7674 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7675 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7679 gcc_assert (!non_const
);
7680 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7681 type_expr
, expr
.value
);
7684 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7687 /* Callback function for sizeof_pointer_memaccess_warning to compare
7691 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7693 return comptypes (type1
, type2
) == 1;
7696 /* Parse a postfix expression after the initial primary or compound
7697 literal; that is, parse a series of postfix operators.
7699 EXPR_LOC is the location of the primary expression. */
7701 static struct c_expr
7702 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7703 location_t expr_loc
,
7706 struct c_expr orig_expr
;
7708 location_t sizeof_arg_loc
[3];
7710 unsigned int literal_zero_mask
;
7712 vec
<tree
, va_gc
> *exprlist
;
7713 vec
<tree
, va_gc
> *origtypes
= NULL
;
7714 vec
<location_t
> arg_loc
= vNULL
;
7718 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7719 switch (c_parser_peek_token (parser
)->type
)
7721 case CPP_OPEN_SQUARE
:
7722 /* Array reference. */
7723 c_parser_consume_token (parser
);
7725 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7726 /* If we are here, then we have something like this:
7729 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7733 idx
= c_parser_expression (parser
).value
;
7734 /* Here we have 3 options:
7735 1. Array [EXPR] -- Normal Array call.
7736 2. Array [EXPR : EXPR] -- Array notation without stride.
7737 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7739 For 1, we just handle it just like a normal array expression.
7740 For 2 and 3 we handle it like we handle array notations. The
7741 idx value we have above becomes the initial/start index.
7744 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7745 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7749 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7751 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7754 expr
.original_code
= ERROR_MARK
;
7755 expr
.original_type
= NULL
;
7757 case CPP_OPEN_PAREN
:
7758 /* Function call. */
7759 c_parser_consume_token (parser
);
7760 for (i
= 0; i
< 3; i
++)
7762 sizeof_arg
[i
] = NULL_TREE
;
7763 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7765 literal_zero_mask
= 0;
7766 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7769 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7770 sizeof_arg_loc
, sizeof_arg
,
7771 &arg_loc
, &literal_zero_mask
);
7772 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7775 mark_exp_read (expr
.value
);
7776 if (warn_sizeof_pointer_memaccess
)
7777 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7778 expr
.value
, exprlist
,
7780 sizeof_ptr_memacc_comptypes
);
7781 if (warn_memset_transposed_args
7782 && TREE_CODE (expr
.value
) == FUNCTION_DECL
7783 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
7784 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
7785 && vec_safe_length (exprlist
) == 3
7786 && integer_zerop ((*exprlist
)[2])
7787 && (literal_zero_mask
& (1 << 2)) != 0
7788 && (!integer_zerop ((*exprlist
)[1])
7789 || (literal_zero_mask
& (1 << 1)) == 0))
7790 warning_at (expr_loc
, OPT_Wmemset_transposed_args
,
7791 "%<memset%> used with constant zero length parameter; "
7792 "this could be due to transposed parameters");
7795 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7796 exprlist
, origtypes
);
7797 expr
.original_code
= ERROR_MARK
;
7798 if (TREE_CODE (expr
.value
) == INTEGER_CST
7799 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7800 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7801 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7802 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7803 expr
.original_type
= NULL
;
7806 release_tree_vector (exprlist
);
7807 release_tree_vector (origtypes
);
7812 /* Structure element reference. */
7813 c_parser_consume_token (parser
);
7814 expr
= default_function_array_conversion (expr_loc
, expr
);
7815 if (c_parser_next_token_is (parser
, CPP_NAME
))
7816 ident
= c_parser_peek_token (parser
)->value
;
7819 c_parser_error (parser
, "expected identifier");
7820 expr
.value
= error_mark_node
;
7821 expr
.original_code
= ERROR_MARK
;
7822 expr
.original_type
= NULL
;
7825 c_parser_consume_token (parser
);
7826 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7827 expr
.original_code
= ERROR_MARK
;
7828 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7829 expr
.original_type
= NULL
;
7832 /* Remember the original type of a bitfield. */
7833 tree field
= TREE_OPERAND (expr
.value
, 1);
7834 if (TREE_CODE (field
) != FIELD_DECL
)
7835 expr
.original_type
= NULL
;
7837 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7841 /* Structure element reference. */
7842 c_parser_consume_token (parser
);
7843 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7844 if (c_parser_next_token_is (parser
, CPP_NAME
))
7845 ident
= c_parser_peek_token (parser
)->value
;
7848 c_parser_error (parser
, "expected identifier");
7849 expr
.value
= error_mark_node
;
7850 expr
.original_code
= ERROR_MARK
;
7851 expr
.original_type
= NULL
;
7854 c_parser_consume_token (parser
);
7855 expr
.value
= build_component_ref (op_loc
,
7856 build_indirect_ref (op_loc
,
7860 expr
.original_code
= ERROR_MARK
;
7861 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7862 expr
.original_type
= NULL
;
7865 /* Remember the original type of a bitfield. */
7866 tree field
= TREE_OPERAND (expr
.value
, 1);
7867 if (TREE_CODE (field
) != FIELD_DECL
)
7868 expr
.original_type
= NULL
;
7870 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7874 /* Postincrement. */
7875 c_parser_consume_token (parser
);
7876 /* If the expressions have array notations, we expand them. */
7878 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7879 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7882 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7883 expr
.value
= build_unary_op (op_loc
,
7884 POSTINCREMENT_EXPR
, expr
.value
, 0);
7886 expr
.original_code
= ERROR_MARK
;
7887 expr
.original_type
= NULL
;
7889 case CPP_MINUS_MINUS
:
7890 /* Postdecrement. */
7891 c_parser_consume_token (parser
);
7892 /* If the expressions have array notations, we expand them. */
7894 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7895 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7898 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7899 expr
.value
= build_unary_op (op_loc
,
7900 POSTDECREMENT_EXPR
, expr
.value
, 0);
7902 expr
.original_code
= ERROR_MARK
;
7903 expr
.original_type
= NULL
;
7911 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7914 assignment-expression
7915 expression , assignment-expression
7918 static struct c_expr
7919 c_parser_expression (c_parser
*parser
)
7921 location_t tloc
= c_parser_peek_token (parser
)->location
;
7923 expr
= c_parser_expr_no_commas (parser
, NULL
);
7924 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7925 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7926 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7930 location_t loc
= c_parser_peek_token (parser
)->location
;
7931 location_t expr_loc
;
7932 c_parser_consume_token (parser
);
7933 expr_loc
= c_parser_peek_token (parser
)->location
;
7934 lhsval
= expr
.value
;
7935 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7936 lhsval
= TREE_OPERAND (lhsval
, 1);
7937 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7938 mark_exp_read (lhsval
);
7939 next
= c_parser_expr_no_commas (parser
, NULL
);
7940 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7941 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7942 expr
.original_code
= COMPOUND_EXPR
;
7943 expr
.original_type
= next
.original_type
;
7948 /* Parse an expression and convert functions or arrays to pointers and
7949 lvalues to rvalues. */
7951 static struct c_expr
7952 c_parser_expression_conv (c_parser
*parser
)
7955 location_t loc
= c_parser_peek_token (parser
)->location
;
7956 expr
= c_parser_expression (parser
);
7957 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7961 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
7962 argument is a literal zero alone and if so, set it in literal_zero_mask. */
7965 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
7968 if (idx
>= HOST_BITS_PER_INT
)
7971 c_token
*tok
= c_parser_peek_token (parser
);
7979 /* If a parameter is literal zero alone, remember it
7980 for -Wmemset-transposed-args warning. */
7981 if (integer_zerop (tok
->value
)
7982 && !TREE_OVERFLOW (tok
->value
)
7983 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7984 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
7985 *literal_zero_mask
|= 1U << idx
;
7991 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7992 functions and arrays to pointers and lvalues to rvalues. If
7993 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7994 locations of function arguments into this vector.
7997 assignment-expression
7998 nonempty-expr-list , assignment-expression
8001 static vec
<tree
, va_gc
> *
8002 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8003 vec
<tree
, va_gc
> **p_orig_types
,
8004 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8005 vec
<location_t
> *locations
,
8006 unsigned int *literal_zero_mask
)
8008 vec
<tree
, va_gc
> *ret
;
8009 vec
<tree
, va_gc
> *orig_types
;
8011 location_t loc
= c_parser_peek_token (parser
)->location
;
8012 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8013 unsigned int idx
= 0;
8015 ret
= make_tree_vector ();
8016 if (p_orig_types
== NULL
)
8019 orig_types
= make_tree_vector ();
8021 if (sizeof_arg
!= NULL
8022 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8023 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8024 if (literal_zero_mask
)
8025 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8026 expr
= c_parser_expr_no_commas (parser
, NULL
);
8028 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8030 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8031 ret
->quick_push (expr
.value
);
8033 orig_types
->quick_push (expr
.original_type
);
8035 locations
->safe_push (loc
);
8036 if (sizeof_arg
!= NULL
8037 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8038 && expr
.original_code
== SIZEOF_EXPR
)
8040 sizeof_arg
[0] = c_last_sizeof_arg
;
8041 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8043 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8045 c_parser_consume_token (parser
);
8046 loc
= c_parser_peek_token (parser
)->location
;
8047 if (sizeof_arg
!= NULL
8048 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8049 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8051 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8052 if (literal_zero_mask
)
8053 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8054 expr
= c_parser_expr_no_commas (parser
, NULL
);
8056 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8058 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8059 vec_safe_push (ret
, expr
.value
);
8061 vec_safe_push (orig_types
, expr
.original_type
);
8063 locations
->safe_push (loc
);
8065 && sizeof_arg
!= NULL
8066 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8067 && expr
.original_code
== SIZEOF_EXPR
)
8069 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8070 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8074 *p_orig_types
= orig_types
;
8078 /* Parse Objective-C-specific constructs. */
8080 /* Parse an objc-class-definition.
8082 objc-class-definition:
8083 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8084 objc-class-instance-variables[opt] objc-methodprotolist @end
8085 @implementation identifier objc-superclass[opt]
8086 objc-class-instance-variables[opt]
8087 @interface identifier ( identifier ) objc-protocol-refs[opt]
8088 objc-methodprotolist @end
8089 @interface identifier ( ) objc-protocol-refs[opt]
8090 objc-methodprotolist @end
8091 @implementation identifier ( identifier )
8096 "@interface identifier (" must start "@interface identifier (
8097 identifier ) ...": objc-methodprotolist in the first production may
8098 not start with a parenthesized identifier as a declarator of a data
8099 definition with no declaration specifiers if the objc-superclass,
8100 objc-protocol-refs and objc-class-instance-variables are omitted. */
8103 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8108 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8110 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8115 c_parser_consume_token (parser
);
8116 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8118 c_parser_error (parser
, "expected identifier");
8121 id1
= c_parser_peek_token (parser
)->value
;
8122 c_parser_consume_token (parser
);
8123 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8125 /* We have a category or class extension. */
8127 tree proto
= NULL_TREE
;
8128 c_parser_consume_token (parser
);
8129 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8131 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8133 /* We have a class extension. */
8138 c_parser_error (parser
, "expected identifier or %<)%>");
8139 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8145 id2
= c_parser_peek_token (parser
)->value
;
8146 c_parser_consume_token (parser
);
8148 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8151 objc_start_category_implementation (id1
, id2
);
8154 if (c_parser_next_token_is (parser
, CPP_LESS
))
8155 proto
= c_parser_objc_protocol_refs (parser
);
8156 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8157 c_parser_objc_methodprotolist (parser
);
8158 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8159 objc_finish_interface ();
8162 if (c_parser_next_token_is (parser
, CPP_COLON
))
8164 c_parser_consume_token (parser
);
8165 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8167 c_parser_error (parser
, "expected identifier");
8170 superclass
= c_parser_peek_token (parser
)->value
;
8171 c_parser_consume_token (parser
);
8174 superclass
= NULL_TREE
;
8177 tree proto
= NULL_TREE
;
8178 if (c_parser_next_token_is (parser
, CPP_LESS
))
8179 proto
= c_parser_objc_protocol_refs (parser
);
8180 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8183 objc_start_class_implementation (id1
, superclass
);
8184 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8185 c_parser_objc_class_instance_variables (parser
);
8188 objc_continue_interface ();
8189 c_parser_objc_methodprotolist (parser
);
8190 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8191 objc_finish_interface ();
8195 objc_continue_implementation ();
8200 /* Parse objc-class-instance-variables.
8202 objc-class-instance-variables:
8203 { objc-instance-variable-decl-list[opt] }
8205 objc-instance-variable-decl-list:
8206 objc-visibility-spec
8207 objc-instance-variable-decl ;
8209 objc-instance-variable-decl-list objc-visibility-spec
8210 objc-instance-variable-decl-list objc-instance-variable-decl ;
8211 objc-instance-variable-decl-list ;
8213 objc-visibility-spec:
8218 objc-instance-variable-decl:
8223 c_parser_objc_class_instance_variables (c_parser
*parser
)
8225 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8226 c_parser_consume_token (parser
);
8227 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8230 /* Parse any stray semicolon. */
8231 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8233 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8235 c_parser_consume_token (parser
);
8238 /* Stop if at the end of the instance variables. */
8239 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8241 c_parser_consume_token (parser
);
8244 /* Parse any objc-visibility-spec. */
8245 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8247 c_parser_consume_token (parser
);
8248 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8251 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8253 c_parser_consume_token (parser
);
8254 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8257 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8259 c_parser_consume_token (parser
);
8260 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8263 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8265 c_parser_consume_token (parser
);
8266 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8269 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8271 c_parser_pragma (parser
, pragma_external
);
8275 /* Parse some comma-separated declarations. */
8276 decls
= c_parser_struct_declaration (parser
);
8279 /* There is a syntax error. We want to skip the offending
8280 tokens up to the next ';' (included) or '}'
8283 /* First, skip manually a ')' or ']'. This is because they
8284 reduce the nesting level, so c_parser_skip_until_found()
8285 wouldn't be able to skip past them. */
8286 c_token
*token
= c_parser_peek_token (parser
);
8287 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8288 c_parser_consume_token (parser
);
8290 /* Then, do the standard skipping. */
8291 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8293 /* We hopefully recovered. Start normal parsing again. */
8294 parser
->error
= false;
8299 /* Comma-separated instance variables are chained together
8300 in reverse order; add them one by one. */
8301 tree ivar
= nreverse (decls
);
8302 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8303 objc_add_instance_variable (copy_node (ivar
));
8305 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8309 /* Parse an objc-class-declaration.
8311 objc-class-declaration:
8312 @class identifier-list ;
8316 c_parser_objc_class_declaration (c_parser
*parser
)
8318 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8319 c_parser_consume_token (parser
);
8320 /* Any identifiers, including those declared as type names, are OK
8325 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8327 c_parser_error (parser
, "expected identifier");
8328 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8329 parser
->error
= false;
8332 id
= c_parser_peek_token (parser
)->value
;
8333 objc_declare_class (id
);
8334 c_parser_consume_token (parser
);
8335 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8336 c_parser_consume_token (parser
);
8340 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8343 /* Parse an objc-alias-declaration.
8345 objc-alias-declaration:
8346 @compatibility_alias identifier identifier ;
8350 c_parser_objc_alias_declaration (c_parser
*parser
)
8353 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8354 c_parser_consume_token (parser
);
8355 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8357 c_parser_error (parser
, "expected identifier");
8358 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8361 id1
= c_parser_peek_token (parser
)->value
;
8362 c_parser_consume_token (parser
);
8363 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8365 c_parser_error (parser
, "expected identifier");
8366 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8369 id2
= c_parser_peek_token (parser
)->value
;
8370 c_parser_consume_token (parser
);
8371 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8372 objc_declare_alias (id1
, id2
);
8375 /* Parse an objc-protocol-definition.
8377 objc-protocol-definition:
8378 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8379 @protocol identifier-list ;
8381 "@protocol identifier ;" should be resolved as "@protocol
8382 identifier-list ;": objc-methodprotolist may not start with a
8383 semicolon in the first alternative if objc-protocol-refs are
8387 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8389 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8391 c_parser_consume_token (parser
);
8392 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8394 c_parser_error (parser
, "expected identifier");
8397 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8398 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8400 /* Any identifiers, including those declared as type names, are
8405 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8407 c_parser_error (parser
, "expected identifier");
8410 id
= c_parser_peek_token (parser
)->value
;
8411 objc_declare_protocol (id
, attributes
);
8412 c_parser_consume_token (parser
);
8413 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8414 c_parser_consume_token (parser
);
8418 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8422 tree id
= c_parser_peek_token (parser
)->value
;
8423 tree proto
= NULL_TREE
;
8424 c_parser_consume_token (parser
);
8425 if (c_parser_next_token_is (parser
, CPP_LESS
))
8426 proto
= c_parser_objc_protocol_refs (parser
);
8427 parser
->objc_pq_context
= true;
8428 objc_start_protocol (id
, proto
, attributes
);
8429 c_parser_objc_methodprotolist (parser
);
8430 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8431 parser
->objc_pq_context
= false;
8432 objc_finish_interface ();
8436 /* Parse an objc-method-type.
8442 Return true if it is a class method (+) and false if it is
8443 an instance method (-).
8446 c_parser_objc_method_type (c_parser
*parser
)
8448 switch (c_parser_peek_token (parser
)->type
)
8451 c_parser_consume_token (parser
);
8454 c_parser_consume_token (parser
);
8461 /* Parse an objc-method-definition.
8463 objc-method-definition:
8464 objc-method-type objc-method-decl ;[opt] compound-statement
8468 c_parser_objc_method_definition (c_parser
*parser
)
8470 bool is_class_method
= c_parser_objc_method_type (parser
);
8471 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8472 parser
->objc_pq_context
= true;
8473 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8475 if (decl
== error_mark_node
)
8476 return; /* Bail here. */
8478 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8480 c_parser_consume_token (parser
);
8481 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8482 "extra semicolon in method definition specified");
8485 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8487 c_parser_error (parser
, "expected %<{%>");
8491 parser
->objc_pq_context
= false;
8492 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8494 add_stmt (c_parser_compound_statement (parser
));
8495 objc_finish_method_definition (current_function_decl
);
8499 /* This code is executed when we find a method definition
8500 outside of an @implementation context (or invalid for other
8501 reasons). Parse the method (to keep going) but do not emit
8504 c_parser_compound_statement (parser
);
8508 /* Parse an objc-methodprotolist.
8510 objc-methodprotolist:
8512 objc-methodprotolist objc-methodproto
8513 objc-methodprotolist declaration
8514 objc-methodprotolist ;
8518 The declaration is a data definition, which may be missing
8519 declaration specifiers under the same rules and diagnostics as
8520 other data definitions outside functions, and the stray semicolon
8521 is diagnosed the same way as a stray semicolon outside a
8525 c_parser_objc_methodprotolist (c_parser
*parser
)
8529 /* The list is terminated by @end. */
8530 switch (c_parser_peek_token (parser
)->type
)
8533 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8534 "ISO C does not allow extra %<;%> outside of a function");
8535 c_parser_consume_token (parser
);
8539 c_parser_objc_methodproto (parser
);
8542 c_parser_pragma (parser
, pragma_external
);
8547 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8549 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8550 c_parser_objc_at_property_declaration (parser
);
8551 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8553 objc_set_method_opt (true);
8554 c_parser_consume_token (parser
);
8556 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8558 objc_set_method_opt (false);
8559 c_parser_consume_token (parser
);
8562 c_parser_declaration_or_fndef (parser
, false, false, true,
8563 false, true, NULL
, vNULL
);
8569 /* Parse an objc-methodproto.
8572 objc-method-type objc-method-decl ;
8576 c_parser_objc_methodproto (c_parser
*parser
)
8578 bool is_class_method
= c_parser_objc_method_type (parser
);
8579 tree decl
, attributes
= NULL_TREE
;
8581 /* Remember protocol qualifiers in prototypes. */
8582 parser
->objc_pq_context
= true;
8583 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8585 /* Forget protocol qualifiers now. */
8586 parser
->objc_pq_context
= false;
8588 /* Do not allow the presence of attributes to hide an erroneous
8589 method implementation in the interface section. */
8590 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8592 c_parser_error (parser
, "expected %<;%>");
8596 if (decl
!= error_mark_node
)
8597 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8599 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8602 /* If we are at a position that method attributes may be present, check that
8603 there are not any parsed already (a syntax error) and then collect any
8604 specified at the current location. Finally, if new attributes were present,
8605 check that the next token is legal ( ';' for decls and '{' for defs). */
8608 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8613 c_parser_error (parser
,
8614 "method attributes must be specified at the end only");
8615 *attributes
= NULL_TREE
;
8619 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8620 *attributes
= c_parser_attributes (parser
);
8622 /* If there were no attributes here, just report any earlier error. */
8623 if (*attributes
== NULL_TREE
|| bad
)
8626 /* If the attributes are followed by a ; or {, then just report any earlier
8628 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8629 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8632 /* We've got attributes, but not at the end. */
8633 c_parser_error (parser
,
8634 "expected %<;%> or %<{%> after method attribute definition");
8638 /* Parse an objc-method-decl.
8641 ( objc-type-name ) objc-selector
8643 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8644 objc-keyword-selector objc-optparmlist
8647 objc-keyword-selector:
8649 objc-keyword-selector objc-keyword-decl
8652 objc-selector : ( objc-type-name ) identifier
8653 objc-selector : identifier
8654 : ( objc-type-name ) identifier
8658 objc-optparms objc-optellipsis
8662 objc-opt-parms , parameter-declaration
8670 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8671 tree
*attributes
, tree
*expr
)
8673 tree type
= NULL_TREE
;
8675 tree parms
= NULL_TREE
;
8676 bool ellipsis
= false;
8677 bool attr_err
= false;
8679 *attributes
= NULL_TREE
;
8680 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8682 c_parser_consume_token (parser
);
8683 type
= c_parser_objc_type_name (parser
);
8684 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8686 sel
= c_parser_objc_selector (parser
);
8687 /* If there is no selector, or a colon follows, we have an
8688 objc-keyword-selector. If there is a selector, and a colon does
8689 not follow, that selector ends the objc-method-decl. */
8690 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8693 tree list
= NULL_TREE
;
8696 tree atype
= NULL_TREE
, id
, keyworddecl
;
8697 tree param_attr
= NULL_TREE
;
8698 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8700 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8702 c_parser_consume_token (parser
);
8703 atype
= c_parser_objc_type_name (parser
);
8704 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8707 /* New ObjC allows attributes on method parameters. */
8708 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8709 param_attr
= c_parser_attributes (parser
);
8710 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8712 c_parser_error (parser
, "expected identifier");
8713 return error_mark_node
;
8715 id
= c_parser_peek_token (parser
)->value
;
8716 c_parser_consume_token (parser
);
8717 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8718 list
= chainon (list
, keyworddecl
);
8719 tsel
= c_parser_objc_selector (parser
);
8720 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8724 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8726 /* Parse the optional parameter list. Optional Objective-C
8727 method parameters follow the C syntax, and may include '...'
8728 to denote a variable number of arguments. */
8729 parms
= make_node (TREE_LIST
);
8730 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8732 struct c_parm
*parm
;
8733 c_parser_consume_token (parser
);
8734 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8737 c_parser_consume_token (parser
);
8738 attr_err
|= c_parser_objc_maybe_method_attributes
8739 (parser
, attributes
) ;
8742 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8745 parms
= chainon (parms
,
8746 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8751 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8755 c_parser_error (parser
, "objective-c method declaration is expected");
8756 return error_mark_node
;
8760 return error_mark_node
;
8762 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8765 /* Parse an objc-type-name.
8768 objc-type-qualifiers[opt] type-name
8769 objc-type-qualifiers[opt]
8771 objc-type-qualifiers:
8773 objc-type-qualifiers objc-type-qualifier
8775 objc-type-qualifier: one of
8776 in out inout bycopy byref oneway
8780 c_parser_objc_type_name (c_parser
*parser
)
8782 tree quals
= NULL_TREE
;
8783 struct c_type_name
*type_name
= NULL
;
8784 tree type
= NULL_TREE
;
8787 c_token
*token
= c_parser_peek_token (parser
);
8788 if (token
->type
== CPP_KEYWORD
8789 && (token
->keyword
== RID_IN
8790 || token
->keyword
== RID_OUT
8791 || token
->keyword
== RID_INOUT
8792 || token
->keyword
== RID_BYCOPY
8793 || token
->keyword
== RID_BYREF
8794 || token
->keyword
== RID_ONEWAY
))
8796 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8797 c_parser_consume_token (parser
);
8802 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8803 type_name
= c_parser_type_name (parser
);
8805 type
= groktypename (type_name
, NULL
, NULL
);
8807 /* If the type is unknown, and error has already been produced and
8808 we need to recover from the error. In that case, use NULL_TREE
8809 for the type, as if no type had been specified; this will use the
8810 default type ('id') which is good for error recovery. */
8811 if (type
== error_mark_node
)
8814 return build_tree_list (quals
, type
);
8817 /* Parse objc-protocol-refs.
8824 c_parser_objc_protocol_refs (c_parser
*parser
)
8826 tree list
= NULL_TREE
;
8827 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8828 c_parser_consume_token (parser
);
8829 /* Any identifiers, including those declared as type names, are OK
8834 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8836 c_parser_error (parser
, "expected identifier");
8839 id
= c_parser_peek_token (parser
)->value
;
8840 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8841 c_parser_consume_token (parser
);
8842 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8843 c_parser_consume_token (parser
);
8847 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8851 /* Parse an objc-try-catch-finally-statement.
8853 objc-try-catch-finally-statement:
8854 @try compound-statement objc-catch-list[opt]
8855 @try compound-statement objc-catch-list[opt] @finally compound-statement
8858 @catch ( objc-catch-parameter-declaration ) compound-statement
8859 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8861 objc-catch-parameter-declaration:
8862 parameter-declaration
8865 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8867 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8868 for C++. Keep them in sync. */
8871 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8873 location_t location
;
8876 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8877 c_parser_consume_token (parser
);
8878 location
= c_parser_peek_token (parser
)->location
;
8879 objc_maybe_warn_exceptions (location
);
8880 stmt
= c_parser_compound_statement (parser
);
8881 objc_begin_try_stmt (location
, stmt
);
8883 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8885 struct c_parm
*parm
;
8886 tree parameter_declaration
= error_mark_node
;
8887 bool seen_open_paren
= false;
8889 c_parser_consume_token (parser
);
8890 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8891 seen_open_paren
= true;
8892 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8894 /* We have "@catch (...)" (where the '...' are literally
8895 what is in the code). Skip the '...'.
8896 parameter_declaration is set to NULL_TREE, and
8897 objc_being_catch_clauses() knows that that means
8899 c_parser_consume_token (parser
);
8900 parameter_declaration
= NULL_TREE
;
8904 /* We have "@catch (NSException *exception)" or something
8905 like that. Parse the parameter declaration. */
8906 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8908 parameter_declaration
= error_mark_node
;
8910 parameter_declaration
= grokparm (parm
, NULL
);
8912 if (seen_open_paren
)
8913 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8916 /* If there was no open parenthesis, we are recovering from
8917 an error, and we are trying to figure out what mistake
8918 the user has made. */
8920 /* If there is an immediate closing parenthesis, the user
8921 probably forgot the opening one (ie, they typed "@catch
8922 NSException *e)". Parse the closing parenthesis and keep
8924 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8925 c_parser_consume_token (parser
);
8927 /* If these is no immediate closing parenthesis, the user
8928 probably doesn't know that parenthesis are required at
8929 all (ie, they typed "@catch NSException *e"). So, just
8930 forget about the closing parenthesis and keep going. */
8932 objc_begin_catch_clause (parameter_declaration
);
8933 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8934 c_parser_compound_statement_nostart (parser
);
8935 objc_finish_catch_clause ();
8937 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8939 c_parser_consume_token (parser
);
8940 location
= c_parser_peek_token (parser
)->location
;
8941 stmt
= c_parser_compound_statement (parser
);
8942 objc_build_finally_clause (location
, stmt
);
8944 objc_finish_try_stmt ();
8947 /* Parse an objc-synchronized-statement.
8949 objc-synchronized-statement:
8950 @synchronized ( expression ) compound-statement
8954 c_parser_objc_synchronized_statement (c_parser
*parser
)
8958 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8959 c_parser_consume_token (parser
);
8960 loc
= c_parser_peek_token (parser
)->location
;
8961 objc_maybe_warn_exceptions (loc
);
8962 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8964 struct c_expr ce
= c_parser_expression (parser
);
8965 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8967 expr
= c_fully_fold (expr
, false, NULL
);
8968 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8971 expr
= error_mark_node
;
8972 stmt
= c_parser_compound_statement (parser
);
8973 objc_build_synchronized (loc
, expr
, stmt
);
8976 /* Parse an objc-selector; return NULL_TREE without an error if the
8977 next token is not an objc-selector.
8982 enum struct union if else while do for switch case default
8983 break continue return goto asm sizeof typeof __alignof
8984 unsigned long const short volatile signed restrict _Complex
8985 in out inout bycopy byref oneway int char float double void _Bool
8988 ??? Why this selection of keywords but not, for example, storage
8989 class specifiers? */
8992 c_parser_objc_selector (c_parser
*parser
)
8994 c_token
*token
= c_parser_peek_token (parser
);
8995 tree value
= token
->value
;
8996 if (token
->type
== CPP_NAME
)
8998 c_parser_consume_token (parser
);
9001 if (token
->type
!= CPP_KEYWORD
)
9003 switch (token
->keyword
)
9050 c_parser_consume_token (parser
);
9057 /* Parse an objc-selector-arg.
9061 objc-keywordname-list
9063 objc-keywordname-list:
9065 objc-keywordname-list objc-keywordname
9073 c_parser_objc_selector_arg (c_parser
*parser
)
9075 tree sel
= c_parser_objc_selector (parser
);
9076 tree list
= NULL_TREE
;
9077 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9081 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9083 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9084 sel
= c_parser_objc_selector (parser
);
9085 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9091 /* Parse an objc-receiver.
9100 c_parser_objc_receiver (c_parser
*parser
)
9102 location_t loc
= c_parser_peek_token (parser
)->location
;
9104 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9105 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9106 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9108 tree id
= c_parser_peek_token (parser
)->value
;
9109 c_parser_consume_token (parser
);
9110 return objc_get_class_reference (id
);
9112 struct c_expr ce
= c_parser_expression (parser
);
9113 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9114 return c_fully_fold (ce
.value
, false, NULL
);
9117 /* Parse objc-message-args.
9121 objc-keywordarg-list
9123 objc-keywordarg-list:
9125 objc-keywordarg-list objc-keywordarg
9128 objc-selector : objc-keywordexpr
9133 c_parser_objc_message_args (c_parser
*parser
)
9135 tree sel
= c_parser_objc_selector (parser
);
9136 tree list
= NULL_TREE
;
9137 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9142 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9143 return error_mark_node
;
9144 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9145 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9146 sel
= c_parser_objc_selector (parser
);
9147 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9153 /* Parse an objc-keywordexpr.
9160 c_parser_objc_keywordexpr (c_parser
*parser
)
9163 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9164 NULL
, NULL
, NULL
, NULL
);
9165 if (vec_safe_length (expr_list
) == 1)
9167 /* Just return the expression, remove a level of
9169 ret
= (*expr_list
)[0];
9173 /* We have a comma expression, we will collapse later. */
9174 ret
= build_tree_list_vec (expr_list
);
9176 release_tree_vector (expr_list
);
9180 /* A check, needed in several places, that ObjC interface, implementation or
9181 method definitions are not prefixed by incorrect items. */
9183 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9184 struct c_declspecs
*specs
)
9186 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9187 || specs
->typespec_kind
!= ctsk_none
)
9189 c_parser_error (parser
,
9190 "no type or storage class may be specified here,");
9191 c_parser_skip_to_end_of_block_or_statement (parser
);
9197 /* Parse an Objective-C @property declaration. The syntax is:
9199 objc-property-declaration:
9200 '@property' objc-property-attributes[opt] struct-declaration ;
9202 objc-property-attributes:
9203 '(' objc-property-attribute-list ')'
9205 objc-property-attribute-list:
9206 objc-property-attribute
9207 objc-property-attribute-list, objc-property-attribute
9209 objc-property-attribute
9210 'getter' = identifier
9211 'setter' = identifier
9220 @property NSString *name;
9221 @property (readonly) id object;
9222 @property (retain, nonatomic, getter=getTheName) id name;
9223 @property int a, b, c;
9225 PS: This function is identical to cp_parser_objc_at_propery_declaration
9226 for C++. Keep them in sync. */
9228 c_parser_objc_at_property_declaration (c_parser
*parser
)
9230 /* The following variables hold the attributes of the properties as
9231 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9232 seen. When we see an attribute, we set them to 'true' (if they
9233 are boolean properties) or to the identifier (if they have an
9234 argument, ie, for getter and setter). Note that here we only
9235 parse the list of attributes, check the syntax and accumulate the
9236 attributes that we find. objc_add_property_declaration() will
9237 then process the information. */
9238 bool property_assign
= false;
9239 bool property_copy
= false;
9240 tree property_getter_ident
= NULL_TREE
;
9241 bool property_nonatomic
= false;
9242 bool property_readonly
= false;
9243 bool property_readwrite
= false;
9244 bool property_retain
= false;
9245 tree property_setter_ident
= NULL_TREE
;
9247 /* 'properties' is the list of properties that we read. Usually a
9248 single one, but maybe more (eg, in "@property int a, b, c;" there
9253 loc
= c_parser_peek_token (parser
)->location
;
9254 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9256 c_parser_consume_token (parser
); /* Eat '@property'. */
9258 /* Parse the optional attribute list... */
9259 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9262 c_parser_consume_token (parser
);
9264 /* Property attribute keywords are valid now. */
9265 parser
->objc_property_attr_context
= true;
9269 bool syntax_error
= false;
9270 c_token
*token
= c_parser_peek_token (parser
);
9273 if (token
->type
!= CPP_KEYWORD
)
9275 if (token
->type
== CPP_CLOSE_PAREN
)
9276 c_parser_error (parser
, "expected identifier");
9279 c_parser_consume_token (parser
);
9280 c_parser_error (parser
, "unknown property attribute");
9284 keyword
= token
->keyword
;
9285 c_parser_consume_token (parser
);
9288 case RID_ASSIGN
: property_assign
= true; break;
9289 case RID_COPY
: property_copy
= true; break;
9290 case RID_NONATOMIC
: property_nonatomic
= true; break;
9291 case RID_READONLY
: property_readonly
= true; break;
9292 case RID_READWRITE
: property_readwrite
= true; break;
9293 case RID_RETAIN
: property_retain
= true; break;
9297 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9299 if (keyword
== RID_GETTER
)
9300 c_parser_error (parser
,
9301 "missing %<=%> (after %<getter%> attribute)");
9303 c_parser_error (parser
,
9304 "missing %<=%> (after %<setter%> attribute)");
9305 syntax_error
= true;
9308 c_parser_consume_token (parser
); /* eat the = */
9309 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9311 c_parser_error (parser
, "expected identifier");
9312 syntax_error
= true;
9315 if (keyword
== RID_SETTER
)
9317 if (property_setter_ident
!= NULL_TREE
)
9318 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9320 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9321 c_parser_consume_token (parser
);
9322 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9323 c_parser_error (parser
, "setter name must terminate with %<:%>");
9325 c_parser_consume_token (parser
);
9329 if (property_getter_ident
!= NULL_TREE
)
9330 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9332 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9333 c_parser_consume_token (parser
);
9337 c_parser_error (parser
, "unknown property attribute");
9338 syntax_error
= true;
9345 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9346 c_parser_consume_token (parser
);
9350 parser
->objc_property_attr_context
= false;
9351 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9353 /* ... and the property declaration(s). */
9354 properties
= c_parser_struct_declaration (parser
);
9356 if (properties
== error_mark_node
)
9358 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9359 parser
->error
= false;
9363 if (properties
== NULL_TREE
)
9364 c_parser_error (parser
, "expected identifier");
9367 /* Comma-separated properties are chained together in
9368 reverse order; add them one by one. */
9369 properties
= nreverse (properties
);
9371 for (; properties
; properties
= TREE_CHAIN (properties
))
9372 objc_add_property_declaration (loc
, copy_node (properties
),
9373 property_readonly
, property_readwrite
,
9374 property_assign
, property_retain
,
9375 property_copy
, property_nonatomic
,
9376 property_getter_ident
, property_setter_ident
);
9379 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9380 parser
->error
= false;
9383 /* Parse an Objective-C @synthesize declaration. The syntax is:
9385 objc-synthesize-declaration:
9386 @synthesize objc-synthesize-identifier-list ;
9388 objc-synthesize-identifier-list:
9389 objc-synthesize-identifier
9390 objc-synthesize-identifier-list, objc-synthesize-identifier
9392 objc-synthesize-identifier
9394 identifier = identifier
9397 @synthesize MyProperty;
9398 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9400 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9401 for C++. Keep them in sync.
9404 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9406 tree list
= NULL_TREE
;
9408 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9409 loc
= c_parser_peek_token (parser
)->location
;
9411 c_parser_consume_token (parser
);
9414 tree property
, ivar
;
9415 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9417 c_parser_error (parser
, "expected identifier");
9418 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9419 /* Once we find the semicolon, we can resume normal parsing.
9420 We have to reset parser->error manually because
9421 c_parser_skip_until_found() won't reset it for us if the
9422 next token is precisely a semicolon. */
9423 parser
->error
= false;
9426 property
= c_parser_peek_token (parser
)->value
;
9427 c_parser_consume_token (parser
);
9428 if (c_parser_next_token_is (parser
, CPP_EQ
))
9430 c_parser_consume_token (parser
);
9431 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9433 c_parser_error (parser
, "expected identifier");
9434 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9435 parser
->error
= false;
9438 ivar
= c_parser_peek_token (parser
)->value
;
9439 c_parser_consume_token (parser
);
9443 list
= chainon (list
, build_tree_list (ivar
, property
));
9444 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9445 c_parser_consume_token (parser
);
9449 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9450 objc_add_synthesize_declaration (loc
, list
);
9453 /* Parse an Objective-C @dynamic declaration. The syntax is:
9455 objc-dynamic-declaration:
9456 @dynamic identifier-list ;
9459 @dynamic MyProperty;
9460 @dynamic MyProperty, AnotherProperty;
9462 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9463 for C++. Keep them in sync.
9466 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9468 tree list
= NULL_TREE
;
9470 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9471 loc
= c_parser_peek_token (parser
)->location
;
9473 c_parser_consume_token (parser
);
9477 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9479 c_parser_error (parser
, "expected identifier");
9480 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9481 parser
->error
= false;
9484 property
= c_parser_peek_token (parser
)->value
;
9485 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9486 c_parser_consume_token (parser
);
9487 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9488 c_parser_consume_token (parser
);
9492 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9493 objc_add_dynamic_declaration (loc
, list
);
9497 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9498 should be considered, statements. ALLOW_STMT is true if we're within
9499 the context of a function and such pragmas are to be allowed. Returns
9500 true if we actually parsed such a pragma. */
9503 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9507 id
= c_parser_peek_token (parser
)->pragma_kind
;
9508 gcc_assert (id
!= PRAGMA_NONE
);
9512 case PRAGMA_OMP_BARRIER
:
9513 if (context
!= pragma_compound
)
9515 if (context
== pragma_stmt
)
9516 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9517 "used in compound statements");
9520 c_parser_omp_barrier (parser
);
9523 case PRAGMA_OMP_FLUSH
:
9524 if (context
!= pragma_compound
)
9526 if (context
== pragma_stmt
)
9527 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9528 "used in compound statements");
9531 c_parser_omp_flush (parser
);
9534 case PRAGMA_OMP_TASKWAIT
:
9535 if (context
!= pragma_compound
)
9537 if (context
== pragma_stmt
)
9538 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9539 "used in compound statements");
9542 c_parser_omp_taskwait (parser
);
9545 case PRAGMA_OMP_TASKYIELD
:
9546 if (context
!= pragma_compound
)
9548 if (context
== pragma_stmt
)
9549 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9550 "used in compound statements");
9553 c_parser_omp_taskyield (parser
);
9556 case PRAGMA_OMP_CANCEL
:
9557 if (context
!= pragma_compound
)
9559 if (context
== pragma_stmt
)
9560 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9561 "used in compound statements");
9564 c_parser_omp_cancel (parser
);
9567 case PRAGMA_OMP_CANCELLATION_POINT
:
9568 if (context
!= pragma_compound
)
9570 if (context
== pragma_stmt
)
9571 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9572 "only be used in compound statements");
9575 c_parser_omp_cancellation_point (parser
);
9578 case PRAGMA_OMP_THREADPRIVATE
:
9579 c_parser_omp_threadprivate (parser
);
9582 case PRAGMA_OMP_TARGET
:
9583 return c_parser_omp_target (parser
, context
);
9585 case PRAGMA_OMP_END_DECLARE_TARGET
:
9586 c_parser_omp_end_declare_target (parser
);
9589 case PRAGMA_OMP_SECTION
:
9590 error_at (c_parser_peek_token (parser
)->location
,
9591 "%<#pragma omp section%> may only be used in "
9592 "%<#pragma omp sections%> construct");
9593 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9596 case PRAGMA_OMP_DECLARE_REDUCTION
:
9597 c_parser_omp_declare (parser
, context
);
9600 c_parser_consume_pragma (parser
);
9601 c_parser_skip_to_pragma_eol (parser
);
9602 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9603 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9604 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9606 c_parser_error (parser
, "for, while or do statement expected");
9609 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9610 c_parser_for_statement (parser
, true);
9611 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9612 c_parser_while_statement (parser
, true);
9614 c_parser_do_statement (parser
, true);
9617 case PRAGMA_GCC_PCH_PREPROCESS
:
9618 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9619 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9622 case PRAGMA_CILK_SIMD
:
9623 if (!c_parser_cilk_verify_simd (parser
, context
))
9625 c_parser_consume_pragma (parser
);
9626 c_parser_cilk_simd (parser
);
9628 case PRAGMA_CILK_GRAINSIZE
:
9631 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
9633 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9636 if (context
== pragma_external
)
9638 error_at (c_parser_peek_token (parser
)->location
,
9639 "%<#pragma grainsize%> must be inside a function");
9640 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9643 c_parser_cilk_grainsize (parser
);
9647 if (id
< PRAGMA_FIRST_EXTERNAL
)
9649 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9652 c_parser_error (parser
, "expected declaration specifiers");
9653 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9656 c_parser_omp_construct (parser
);
9662 c_parser_consume_pragma (parser
);
9663 c_invoke_pragma_handler (id
);
9665 /* Skip to EOL, but suppress any error message. Those will have been
9666 generated by the handler routine through calling error, as opposed
9667 to calling c_parser_error. */
9668 parser
->error
= true;
9669 c_parser_skip_to_pragma_eol (parser
);
9674 /* The interface the pragma parsers have to the lexer. */
9677 pragma_lex (tree
*value
)
9679 c_token
*tok
= c_parser_peek_token (the_parser
);
9680 enum cpp_ttype ret
= tok
->type
;
9682 *value
= tok
->value
;
9683 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9687 if (ret
== CPP_KEYWORD
)
9689 c_parser_consume_token (the_parser
);
9696 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9700 c_parser_consume_pragma (parser
);
9701 if (c_parser_next_token_is (parser
, CPP_STRING
))
9703 name
= c_parser_peek_token (parser
)->value
;
9704 c_parser_consume_token (parser
);
9707 c_parser_error (parser
, "expected string literal");
9708 c_parser_skip_to_pragma_eol (parser
);
9711 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9714 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9716 /* Returns name of the next clause.
9717 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9718 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9719 returned and the token is consumed. */
9721 static pragma_omp_clause
9722 c_parser_omp_clause_name (c_parser
*parser
)
9724 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9726 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9727 result
= PRAGMA_OMP_CLAUSE_IF
;
9728 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9729 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9730 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9731 result
= PRAGMA_OMP_CLAUSE_FOR
;
9732 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9734 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9739 if (!strcmp ("aligned", p
))
9740 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9743 if (!strcmp ("collapse", p
))
9744 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9745 else if (!strcmp ("copyin", p
))
9746 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9747 else if (!strcmp ("copyprivate", p
))
9748 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9751 if (!strcmp ("depend", p
))
9752 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9753 else if (!strcmp ("device", p
))
9754 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9755 else if (!strcmp ("dist_schedule", p
))
9756 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9759 if (!strcmp ("final", p
))
9760 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9761 else if (!strcmp ("firstprivate", p
))
9762 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9763 else if (!strcmp ("from", p
))
9764 result
= PRAGMA_OMP_CLAUSE_FROM
;
9767 if (!strcmp ("inbranch", p
))
9768 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9771 if (!strcmp ("lastprivate", p
))
9772 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9773 else if (!strcmp ("linear", p
))
9774 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9777 if (!strcmp ("map", p
))
9778 result
= PRAGMA_OMP_CLAUSE_MAP
;
9779 else if (!strcmp ("mergeable", p
))
9780 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9781 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9782 result
= PRAGMA_CILK_CLAUSE_MASK
;
9785 if (!strcmp ("notinbranch", p
))
9786 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9787 else if (!strcmp ("nowait", p
))
9788 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9789 else if (!strcmp ("num_teams", p
))
9790 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9791 else if (!strcmp ("num_threads", p
))
9792 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9793 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9794 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9797 if (!strcmp ("ordered", p
))
9798 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9801 if (!strcmp ("parallel", p
))
9802 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9803 else if (!strcmp ("private", p
))
9804 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9805 else if (!strcmp ("proc_bind", p
))
9806 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9809 if (!strcmp ("reduction", p
))
9810 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9813 if (!strcmp ("safelen", p
))
9814 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9815 else if (!strcmp ("schedule", p
))
9816 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9817 else if (!strcmp ("sections", p
))
9818 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9819 else if (!strcmp ("shared", p
))
9820 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9821 else if (!strcmp ("simdlen", p
))
9822 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9825 if (!strcmp ("taskgroup", p
))
9826 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9827 else if (!strcmp ("thread_limit", p
))
9828 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9829 else if (!strcmp ("to", p
))
9830 result
= PRAGMA_OMP_CLAUSE_TO
;
9833 if (!strcmp ("uniform", p
))
9834 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9835 else if (!strcmp ("untied", p
))
9836 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9839 if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9840 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9845 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9846 c_parser_consume_token (parser
);
9851 /* Validate that a clause of the given type does not already exist. */
9854 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9859 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9860 if (OMP_CLAUSE_CODE (c
) == code
)
9862 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9863 error_at (loc
, "too many %qs clauses", name
);
9871 variable-list , identifier
9873 If KIND is nonzero, create the appropriate node and install the
9874 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9875 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9877 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9878 return the list created. */
9881 c_parser_omp_variable_list (c_parser
*parser
,
9882 location_t clause_loc
,
9883 enum omp_clause_code kind
, tree list
)
9885 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9886 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9887 c_parser_error (parser
, "expected identifier");
9889 while (c_parser_next_token_is (parser
, CPP_NAME
)
9890 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9892 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9896 undeclared_variable (c_parser_peek_token (parser
)->location
,
9897 c_parser_peek_token (parser
)->value
);
9898 t
= error_mark_node
;
9901 c_parser_consume_token (parser
);
9903 if (t
== error_mark_node
)
9909 case OMP_CLAUSE_MAP
:
9910 case OMP_CLAUSE_FROM
:
9912 case OMP_CLAUSE_DEPEND
:
9913 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9915 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9917 c_parser_consume_token (parser
);
9918 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9920 low_bound
= c_parser_expression (parser
).value
;
9921 mark_exp_read (low_bound
);
9923 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9924 length
= integer_one_node
;
9928 if (!c_parser_require (parser
, CPP_COLON
,
9931 t
= error_mark_node
;
9934 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9936 length
= c_parser_expression (parser
).value
;
9937 mark_exp_read (length
);
9940 /* Look for the closing `]'. */
9941 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9944 t
= error_mark_node
;
9947 t
= tree_cons (low_bound
, length
, t
);
9954 if (t
!= error_mark_node
)
9956 tree u
= build_omp_clause (clause_loc
, kind
);
9957 OMP_CLAUSE_DECL (u
) = t
;
9958 OMP_CLAUSE_CHAIN (u
) = list
;
9963 list
= tree_cons (t
, NULL_TREE
, list
);
9965 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9968 c_parser_consume_token (parser
);
9974 /* Similarly, but expect leading and trailing parenthesis. This is a very
9975 common case for omp clauses. */
9978 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9981 /* The clauses location. */
9982 location_t loc
= c_parser_peek_token (parser
)->location
;
9984 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9986 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9987 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9993 collapse ( constant-expression ) */
9996 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9998 tree c
, num
= error_mark_node
;
10002 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10004 loc
= c_parser_peek_token (parser
)->location
;
10005 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10007 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10008 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10010 if (num
== error_mark_node
)
10012 mark_exp_read (num
);
10013 num
= c_fully_fold (num
, false, NULL
);
10014 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10015 || !tree_fits_shwi_p (num
)
10016 || (n
= tree_to_shwi (num
)) <= 0
10020 "collapse argument needs positive constant integer expression");
10023 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
10024 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
10025 OMP_CLAUSE_CHAIN (c
) = list
;
10030 copyin ( variable-list ) */
10033 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10035 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10039 copyprivate ( variable-list ) */
10042 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10044 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10048 default ( shared | none ) */
10051 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10053 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10054 location_t loc
= c_parser_peek_token (parser
)->location
;
10057 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10059 if (c_parser_next_token_is (parser
, CPP_NAME
))
10061 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10066 if (strcmp ("none", p
) != 0)
10068 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10072 if (strcmp ("shared", p
) != 0)
10074 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10081 c_parser_consume_token (parser
);
10086 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10088 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10090 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10093 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10094 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10095 OMP_CLAUSE_CHAIN (c
) = list
;
10096 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10102 firstprivate ( variable-list ) */
10105 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10107 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10111 final ( expression ) */
10114 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10116 location_t loc
= c_parser_peek_token (parser
)->location
;
10117 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10119 tree t
= c_parser_paren_condition (parser
);
10122 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10124 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10125 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10126 OMP_CLAUSE_CHAIN (c
) = list
;
10130 c_parser_error (parser
, "expected %<(%>");
10136 if ( expression ) */
10139 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10141 location_t loc
= c_parser_peek_token (parser
)->location
;
10142 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10144 tree t
= c_parser_paren_condition (parser
);
10147 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10149 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10150 OMP_CLAUSE_IF_EXPR (c
) = t
;
10151 OMP_CLAUSE_CHAIN (c
) = list
;
10155 c_parser_error (parser
, "expected %<(%>");
10161 lastprivate ( variable-list ) */
10164 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10166 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10173 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10177 /* FIXME: Should we allow duplicates? */
10178 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10180 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10181 OMP_CLAUSE_MERGEABLE
);
10182 OMP_CLAUSE_CHAIN (c
) = list
;
10191 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10194 location_t loc
= c_parser_peek_token (parser
)->location
;
10196 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10198 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10199 OMP_CLAUSE_CHAIN (c
) = list
;
10204 num_threads ( expression ) */
10207 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10209 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10210 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10212 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10213 tree c
, t
= c_parser_expression (parser
).value
;
10215 t
= c_fully_fold (t
, false, NULL
);
10217 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10219 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10221 c_parser_error (parser
, "expected integer expression");
10225 /* Attempt to statically determine when the number isn't positive. */
10226 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10227 build_int_cst (TREE_TYPE (t
), 0));
10228 if (CAN_HAVE_LOCATION_P (c
))
10229 SET_EXPR_LOCATION (c
, expr_loc
);
10230 if (c
== boolean_true_node
)
10232 warning_at (expr_loc
, 0,
10233 "%<num_threads%> value must be positive");
10234 t
= integer_one_node
;
10237 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10239 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10240 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10241 OMP_CLAUSE_CHAIN (c
) = list
;
10252 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10256 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10258 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10259 OMP_CLAUSE_ORDERED
);
10260 OMP_CLAUSE_CHAIN (c
) = list
;
10266 private ( variable-list ) */
10269 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10271 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10275 reduction ( reduction-operator : variable-list )
10277 reduction-operator:
10278 One of: + * - & ^ | && ||
10282 reduction-operator:
10283 One of: + * - & ^ | && || max min
10287 reduction-operator:
10288 One of: + * - & ^ | && ||
10292 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10294 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10295 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10297 enum tree_code code
= ERROR_MARK
;
10298 tree reduc_id
= NULL_TREE
;
10300 switch (c_parser_peek_token (parser
)->type
)
10312 code
= BIT_AND_EXPR
;
10315 code
= BIT_XOR_EXPR
;
10318 code
= BIT_IOR_EXPR
;
10321 code
= TRUTH_ANDIF_EXPR
;
10324 code
= TRUTH_ORIF_EXPR
;
10329 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10330 if (strcmp (p
, "min") == 0)
10335 if (strcmp (p
, "max") == 0)
10340 reduc_id
= c_parser_peek_token (parser
)->value
;
10344 c_parser_error (parser
,
10345 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10346 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10347 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10350 c_parser_consume_token (parser
);
10351 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10352 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10356 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10357 OMP_CLAUSE_REDUCTION
, list
);
10358 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10360 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10361 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10362 if (code
== ERROR_MARK
10363 || !(INTEGRAL_TYPE_P (type
)
10364 || TREE_CODE (type
) == REAL_TYPE
10365 || TREE_CODE (type
) == COMPLEX_TYPE
))
10366 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10367 = c_omp_reduction_lookup (reduc_id
,
10368 TYPE_MAIN_VARIANT (type
));
10373 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10379 schedule ( schedule-kind )
10380 schedule ( schedule-kind , expression )
10383 static | dynamic | guided | runtime | auto
10387 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10390 location_t loc
= c_parser_peek_token (parser
)->location
;
10392 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10395 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10397 if (c_parser_next_token_is (parser
, CPP_NAME
))
10399 tree kind
= c_parser_peek_token (parser
)->value
;
10400 const char *p
= IDENTIFIER_POINTER (kind
);
10405 if (strcmp ("dynamic", p
) != 0)
10407 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10411 if (strcmp ("guided", p
) != 0)
10413 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10417 if (strcmp ("runtime", p
) != 0)
10419 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10426 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10427 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10428 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10429 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10433 c_parser_consume_token (parser
);
10434 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10437 c_parser_consume_token (parser
);
10439 here
= c_parser_peek_token (parser
)->location
;
10440 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10442 t
= c_fully_fold (t
, false, NULL
);
10444 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10445 error_at (here
, "schedule %<runtime%> does not take "
10446 "a %<chunk_size%> parameter");
10447 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10449 "schedule %<auto%> does not take "
10450 "a %<chunk_size%> parameter");
10451 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10452 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10454 c_parser_error (parser
, "expected integer expression");
10456 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10459 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10460 "expected %<,%> or %<)%>");
10462 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10463 OMP_CLAUSE_CHAIN (c
) = list
;
10467 c_parser_error (parser
, "invalid schedule kind");
10468 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10473 shared ( variable-list ) */
10476 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10478 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10485 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10489 /* FIXME: Should we allow duplicates? */
10490 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10492 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10493 OMP_CLAUSE_UNTIED
);
10494 OMP_CLAUSE_CHAIN (c
) = list
;
10504 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10505 enum omp_clause_code code
, tree list
)
10507 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10509 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10510 OMP_CLAUSE_CHAIN (c
) = list
;
10522 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10523 enum omp_clause_code code
, tree list
)
10525 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10526 OMP_CLAUSE_CHAIN (c
) = list
;
10532 num_teams ( expression ) */
10535 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10537 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10538 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10540 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10541 tree c
, t
= c_parser_expression (parser
).value
;
10543 t
= c_fully_fold (t
, false, NULL
);
10545 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10547 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10549 c_parser_error (parser
, "expected integer expression");
10553 /* Attempt to statically determine when the number isn't positive. */
10554 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10555 build_int_cst (TREE_TYPE (t
), 0));
10556 if (CAN_HAVE_LOCATION_P (c
))
10557 SET_EXPR_LOCATION (c
, expr_loc
);
10558 if (c
== boolean_true_node
)
10560 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10561 t
= integer_one_node
;
10564 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10566 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10567 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10568 OMP_CLAUSE_CHAIN (c
) = list
;
10576 thread_limit ( expression ) */
10579 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10581 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
10582 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10584 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10585 tree c
, t
= c_parser_expression (parser
).value
;
10587 t
= c_fully_fold (t
, false, NULL
);
10589 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10591 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10593 c_parser_error (parser
, "expected integer expression");
10597 /* Attempt to statically determine when the number isn't positive. */
10598 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10599 build_int_cst (TREE_TYPE (t
), 0));
10600 if (CAN_HAVE_LOCATION_P (c
))
10601 SET_EXPR_LOCATION (c
, expr_loc
);
10602 if (c
== boolean_true_node
)
10604 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10605 t
= integer_one_node
;
10608 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10611 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10612 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10613 OMP_CLAUSE_CHAIN (c
) = list
;
10621 aligned ( variable-list )
10622 aligned ( variable-list : constant-expression ) */
10625 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10627 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10630 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10633 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10634 OMP_CLAUSE_ALIGNED
, list
);
10636 if (c_parser_next_token_is (parser
, CPP_COLON
))
10638 c_parser_consume_token (parser
);
10639 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10640 mark_exp_read (alignment
);
10641 alignment
= c_fully_fold (alignment
, false, NULL
);
10642 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10643 && TREE_CODE (alignment
) != INTEGER_CST
10644 && tree_int_cst_sgn (alignment
) != 1)
10646 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10647 "be positive constant integer expression");
10648 alignment
= NULL_TREE
;
10651 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10652 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10655 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10660 linear ( variable-list )
10661 linear ( variable-list : expression ) */
10664 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
10666 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10669 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10672 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10673 OMP_CLAUSE_LINEAR
, list
);
10675 if (c_parser_next_token_is (parser
, CPP_COLON
))
10677 c_parser_consume_token (parser
);
10678 step
= c_parser_expression (parser
).value
;
10679 mark_exp_read (step
);
10680 step
= c_fully_fold (step
, false, NULL
);
10681 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
10683 sorry ("using parameters for %<linear%> step is not supported yet");
10684 step
= integer_one_node
;
10686 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10688 error_at (clause_loc
, "%<linear%> clause step expression must "
10690 step
= integer_one_node
;
10695 step
= integer_one_node
;
10697 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10699 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10702 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10707 safelen ( constant-expression ) */
10710 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10712 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10715 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10718 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10720 t
= c_fully_fold (t
, false, NULL
);
10721 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10722 && TREE_CODE (t
) != INTEGER_CST
10723 && tree_int_cst_sgn (t
) != 1)
10725 error_at (clause_loc
, "%<safelen%> clause expression must "
10726 "be positive constant integer expression");
10730 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10731 if (t
== NULL_TREE
|| t
== error_mark_node
)
10734 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10736 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10737 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10738 OMP_CLAUSE_CHAIN (c
) = list
;
10743 simdlen ( constant-expression ) */
10746 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10748 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10751 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10754 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10756 t
= c_fully_fold (t
, false, NULL
);
10757 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10758 && TREE_CODE (t
) != INTEGER_CST
10759 && tree_int_cst_sgn (t
) != 1)
10761 error_at (clause_loc
, "%<simdlen%> clause expression must "
10762 "be positive constant integer expression");
10766 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10767 if (t
== NULL_TREE
|| t
== error_mark_node
)
10770 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10772 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10773 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10774 OMP_CLAUSE_CHAIN (c
) = list
;
10779 depend ( depend-kind: variable-list )
10782 in | out | inout */
10785 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10787 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10788 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10791 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10794 if (c_parser_next_token_is (parser
, CPP_NAME
))
10796 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10797 if (strcmp ("in", p
) == 0)
10798 kind
= OMP_CLAUSE_DEPEND_IN
;
10799 else if (strcmp ("inout", p
) == 0)
10800 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10801 else if (strcmp ("out", p
) == 0)
10802 kind
= OMP_CLAUSE_DEPEND_OUT
;
10809 c_parser_consume_token (parser
);
10810 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10813 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10814 OMP_CLAUSE_DEPEND
, list
);
10816 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10817 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10819 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10823 c_parser_error (parser
, "invalid depend kind");
10825 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10830 map ( map-kind: variable-list )
10831 map ( variable-list )
10834 alloc | to | from | tofrom */
10837 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10839 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10840 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10843 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10846 if (c_parser_next_token_is (parser
, CPP_NAME
)
10847 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10849 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10850 if (strcmp ("alloc", p
) == 0)
10851 kind
= OMP_CLAUSE_MAP_ALLOC
;
10852 else if (strcmp ("to", p
) == 0)
10853 kind
= OMP_CLAUSE_MAP_TO
;
10854 else if (strcmp ("from", p
) == 0)
10855 kind
= OMP_CLAUSE_MAP_FROM
;
10856 else if (strcmp ("tofrom", p
) == 0)
10857 kind
= OMP_CLAUSE_MAP_TOFROM
;
10860 c_parser_error (parser
, "invalid map kind");
10861 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10865 c_parser_consume_token (parser
);
10866 c_parser_consume_token (parser
);
10869 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10871 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10872 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10879 device ( expression ) */
10882 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10884 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10885 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10887 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10889 t
= c_fully_fold (t
, false, NULL
);
10891 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10893 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10895 c_parser_error (parser
, "expected integer expression");
10899 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10901 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10902 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10903 OMP_CLAUSE_CHAIN (c
) = list
;
10911 dist_schedule ( static )
10912 dist_schedule ( static , expression ) */
10915 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10917 tree c
, t
= NULL_TREE
;
10918 location_t loc
= c_parser_peek_token (parser
)->location
;
10920 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10923 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10925 c_parser_error (parser
, "invalid dist_schedule kind");
10926 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10931 c_parser_consume_token (parser
);
10932 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10934 c_parser_consume_token (parser
);
10936 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10938 t
= c_fully_fold (t
, false, NULL
);
10939 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10943 "expected %<,%> or %<)%>");
10945 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10946 if (t
== error_mark_node
)
10949 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10950 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10951 OMP_CLAUSE_CHAIN (c
) = list
;
10956 proc_bind ( proc-bind-kind )
10959 master | close | spread */
10962 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10964 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10965 enum omp_clause_proc_bind_kind kind
;
10968 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10971 if (c_parser_next_token_is (parser
, CPP_NAME
))
10973 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10974 if (strcmp ("master", p
) == 0)
10975 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10976 else if (strcmp ("close", p
) == 0)
10977 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10978 else if (strcmp ("spread", p
) == 0)
10979 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10986 c_parser_consume_token (parser
);
10987 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10988 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10989 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10990 OMP_CLAUSE_CHAIN (c
) = list
;
10994 c_parser_error (parser
, "invalid proc_bind kind");
10995 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11000 to ( variable-list ) */
11003 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
11005 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
11009 from ( variable-list ) */
11012 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
11014 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
11018 uniform ( variable-list ) */
11021 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
11023 /* The clauses location. */
11024 location_t loc
= c_parser_peek_token (parser
)->location
;
11026 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11028 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
11030 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11035 /* Parse all OpenMP clauses. The set clauses allowed by the directive
11036 is a bitmask in MASK. Return the list of clauses found; the result
11037 of clause default goes in *pdefault. */
11040 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11041 const char *where
, bool finish_p
= true)
11043 tree clauses
= NULL
;
11044 bool first
= true, cilk_simd_fn
= false;
11046 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11049 pragma_omp_clause c_kind
;
11050 const char *c_name
;
11051 tree prev
= clauses
;
11053 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11054 c_parser_consume_token (parser
);
11056 here
= c_parser_peek_token (parser
)->location
;
11057 c_kind
= c_parser_omp_clause_name (parser
);
11061 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11062 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11063 c_name
= "collapse";
11065 case PRAGMA_OMP_CLAUSE_COPYIN
:
11066 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11069 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11070 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11071 c_name
= "copyprivate";
11073 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11074 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11075 c_name
= "default";
11077 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11078 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11079 c_name
= "firstprivate";
11081 case PRAGMA_OMP_CLAUSE_FINAL
:
11082 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11085 case PRAGMA_OMP_CLAUSE_IF
:
11086 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11089 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11090 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11091 c_name
= "lastprivate";
11093 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11094 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11095 c_name
= "mergeable";
11097 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11098 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11101 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11102 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11103 c_name
= "num_threads";
11105 case PRAGMA_OMP_CLAUSE_ORDERED
:
11106 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11107 c_name
= "ordered";
11109 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11110 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11111 c_name
= "private";
11113 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11114 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11115 c_name
= "reduction";
11117 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11118 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11119 c_name
= "schedule";
11121 case PRAGMA_OMP_CLAUSE_SHARED
:
11122 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11125 case PRAGMA_OMP_CLAUSE_UNTIED
:
11126 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11129 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11130 case PRAGMA_CILK_CLAUSE_MASK
:
11131 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11133 c_name
= "inbranch";
11135 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11136 case PRAGMA_CILK_CLAUSE_NOMASK
:
11137 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11139 c_name
= "notinbranch";
11141 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11143 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11145 c_name
= "parallel";
11149 error_at (here
, "%qs must be the first clause of %qs",
11154 case PRAGMA_OMP_CLAUSE_FOR
:
11156 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11160 goto clause_not_first
;
11162 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11164 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11166 c_name
= "sections";
11168 goto clause_not_first
;
11170 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11172 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11174 c_name
= "taskgroup";
11176 goto clause_not_first
;
11178 case PRAGMA_OMP_CLAUSE_TO
:
11179 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11182 case PRAGMA_OMP_CLAUSE_FROM
:
11183 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11186 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11187 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11188 c_name
= "uniform";
11190 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11191 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11192 c_name
= "num_teams";
11194 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11195 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11196 c_name
= "thread_limit";
11198 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11199 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11200 c_name
= "aligned";
11202 case PRAGMA_OMP_CLAUSE_LINEAR
:
11203 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11204 cilk_simd_fn
= true;
11205 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11208 case PRAGMA_OMP_CLAUSE_DEPEND
:
11209 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11212 case PRAGMA_OMP_CLAUSE_MAP
:
11213 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11216 case PRAGMA_OMP_CLAUSE_DEVICE
:
11217 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11220 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11221 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11222 c_name
= "dist_schedule";
11224 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11225 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11226 c_name
= "proc_bind";
11228 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11229 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11230 c_name
= "safelen";
11232 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11233 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11234 c_name
= "simdlen";
11236 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11237 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11238 c_name
= "simdlen";
11241 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11247 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11249 /* Remove the invalid clause(s) from the list to avoid
11250 confusing the rest of the compiler. */
11252 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11257 c_parser_skip_to_pragma_eol (parser
);
11260 return c_finish_omp_clauses (clauses
);
11269 In practice, we're also interested in adding the statement to an
11270 outer node. So it is convenient if we work around the fact that
11271 c_parser_statement calls add_stmt. */
11274 c_parser_omp_structured_block (c_parser
*parser
)
11276 tree stmt
= push_stmt_list ();
11277 c_parser_statement (parser
);
11278 return pop_stmt_list (stmt
);
11282 # pragma omp atomic new-line
11286 x binop= expr | x++ | ++x | x-- | --x
11288 +, *, -, /, &, ^, |, <<, >>
11290 where x is an lvalue expression with scalar type.
11293 # pragma omp atomic new-line
11296 # pragma omp atomic read new-line
11299 # pragma omp atomic write new-line
11302 # pragma omp atomic update new-line
11305 # pragma omp atomic capture new-line
11308 # pragma omp atomic capture new-line
11316 expression-stmt | x = x binop expr
11318 v = expression-stmt
11320 { v = x; update-stmt; } | { update-stmt; v = x; }
11324 expression-stmt | x = x binop expr | x = expr binop x
11328 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11330 where x and v are lvalue expressions with scalar type.
11332 LOC is the location of the #pragma token. */
11335 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11337 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11338 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11339 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11340 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11341 struct c_expr expr
;
11343 bool structured_block
= false;
11344 bool swapped
= false;
11345 bool seq_cst
= false;
11347 if (c_parser_next_token_is (parser
, CPP_NAME
))
11349 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11350 if (!strcmp (p
, "seq_cst"))
11353 c_parser_consume_token (parser
);
11354 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11355 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11356 c_parser_consume_token (parser
);
11359 if (c_parser_next_token_is (parser
, CPP_NAME
))
11361 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11363 if (!strcmp (p
, "read"))
11364 code
= OMP_ATOMIC_READ
;
11365 else if (!strcmp (p
, "write"))
11367 else if (!strcmp (p
, "update"))
11369 else if (!strcmp (p
, "capture"))
11370 code
= OMP_ATOMIC_CAPTURE_NEW
;
11374 c_parser_consume_token (parser
);
11378 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11379 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11380 c_parser_consume_token (parser
);
11382 if (c_parser_next_token_is (parser
, CPP_NAME
))
11385 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11386 if (!strcmp (p
, "seq_cst"))
11389 c_parser_consume_token (parser
);
11393 c_parser_skip_to_pragma_eol (parser
);
11397 case OMP_ATOMIC_READ
:
11398 case NOP_EXPR
: /* atomic write */
11399 v
= c_parser_unary_expression (parser
).value
;
11400 v
= c_fully_fold (v
, false, NULL
);
11401 if (v
== error_mark_node
)
11403 loc
= c_parser_peek_token (parser
)->location
;
11404 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11406 if (code
== NOP_EXPR
)
11407 lhs
= c_parser_expression (parser
).value
;
11409 lhs
= c_parser_unary_expression (parser
).value
;
11410 lhs
= c_fully_fold (lhs
, false, NULL
);
11411 if (lhs
== error_mark_node
)
11413 if (code
== NOP_EXPR
)
11415 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11423 case OMP_ATOMIC_CAPTURE_NEW
:
11424 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11426 c_parser_consume_token (parser
);
11427 structured_block
= true;
11431 v
= c_parser_unary_expression (parser
).value
;
11432 v
= c_fully_fold (v
, false, NULL
);
11433 if (v
== error_mark_node
)
11435 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11443 /* For structured_block case we don't know yet whether
11444 old or new x should be captured. */
11446 eloc
= c_parser_peek_token (parser
)->location
;
11447 expr
= c_parser_unary_expression (parser
);
11449 expr
= default_function_array_conversion (eloc
, expr
);
11450 unfolded_lhs
= expr
.value
;
11451 lhs
= c_fully_fold (lhs
, false, NULL
);
11453 switch (TREE_CODE (lhs
))
11457 c_parser_skip_to_end_of_block_or_statement (parser
);
11458 if (structured_block
)
11460 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11461 c_parser_consume_token (parser
);
11462 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11464 c_parser_skip_to_end_of_block_or_statement (parser
);
11465 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11466 c_parser_consume_token (parser
);
11471 case POSTINCREMENT_EXPR
:
11472 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11473 code
= OMP_ATOMIC_CAPTURE_OLD
;
11475 case PREINCREMENT_EXPR
:
11476 lhs
= TREE_OPERAND (lhs
, 0);
11477 unfolded_lhs
= NULL_TREE
;
11478 opcode
= PLUS_EXPR
;
11479 rhs
= integer_one_node
;
11482 case POSTDECREMENT_EXPR
:
11483 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11484 code
= OMP_ATOMIC_CAPTURE_OLD
;
11486 case PREDECREMENT_EXPR
:
11487 lhs
= TREE_OPERAND (lhs
, 0);
11488 unfolded_lhs
= NULL_TREE
;
11489 opcode
= MINUS_EXPR
;
11490 rhs
= integer_one_node
;
11493 case COMPOUND_EXPR
:
11494 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11495 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11496 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11497 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11498 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11499 (TREE_OPERAND (lhs
, 1), 0), 0)))
11501 /* Undo effects of boolean_increment for post {in,de}crement. */
11502 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11505 if (TREE_CODE (lhs
) == MODIFY_EXPR
11506 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11508 /* Undo effects of boolean_increment. */
11509 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11511 /* This is pre or post increment. */
11512 rhs
= TREE_OPERAND (lhs
, 1);
11513 lhs
= TREE_OPERAND (lhs
, 0);
11514 unfolded_lhs
= NULL_TREE
;
11516 if (code
== OMP_ATOMIC_CAPTURE_NEW
11517 && !structured_block
11518 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11519 code
= OMP_ATOMIC_CAPTURE_OLD
;
11522 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11523 && TREE_OPERAND (lhs
, 0)
11524 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11526 /* This is pre or post decrement. */
11527 rhs
= TREE_OPERAND (lhs
, 1);
11528 lhs
= TREE_OPERAND (lhs
, 0);
11529 unfolded_lhs
= NULL_TREE
;
11531 if (code
== OMP_ATOMIC_CAPTURE_NEW
11532 && !structured_block
11533 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11534 code
= OMP_ATOMIC_CAPTURE_OLD
;
11540 switch (c_parser_peek_token (parser
)->type
)
11543 opcode
= MULT_EXPR
;
11546 opcode
= TRUNC_DIV_EXPR
;
11549 opcode
= PLUS_EXPR
;
11552 opcode
= MINUS_EXPR
;
11554 case CPP_LSHIFT_EQ
:
11555 opcode
= LSHIFT_EXPR
;
11557 case CPP_RSHIFT_EQ
:
11558 opcode
= RSHIFT_EXPR
;
11561 opcode
= BIT_AND_EXPR
;
11564 opcode
= BIT_IOR_EXPR
;
11567 opcode
= BIT_XOR_EXPR
;
11570 c_parser_consume_token (parser
);
11571 eloc
= c_parser_peek_token (parser
)->location
;
11572 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11574 switch (TREE_CODE (rhs1
))
11577 case TRUNC_DIV_EXPR
:
11585 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11587 opcode
= TREE_CODE (rhs1
);
11588 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11589 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11592 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11594 opcode
= TREE_CODE (rhs1
);
11595 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11596 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11597 swapped
= !commutative_tree_code (opcode
);
11606 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11608 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11610 code
= OMP_ATOMIC_CAPTURE_OLD
;
11613 expr
= default_function_array_read_conversion (eloc
, expr
);
11614 unfolded_lhs1
= expr
.value
;
11615 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11617 c_parser_consume_token (parser
);
11620 if (structured_block
)
11623 expr
= default_function_array_read_conversion (eloc
, expr
);
11624 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11629 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11632 c_parser_error (parser
,
11633 "invalid operator for %<#pragma omp atomic%>");
11637 /* Arrange to pass the location of the assignment operator to
11638 c_finish_omp_atomic. */
11639 loc
= c_parser_peek_token (parser
)->location
;
11640 c_parser_consume_token (parser
);
11641 eloc
= c_parser_peek_token (parser
)->location
;
11642 expr
= c_parser_expression (parser
);
11643 expr
= default_function_array_read_conversion (eloc
, expr
);
11645 rhs
= c_fully_fold (rhs
, false, NULL
);
11649 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11651 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11653 v
= c_parser_unary_expression (parser
).value
;
11654 v
= c_fully_fold (v
, false, NULL
);
11655 if (v
== error_mark_node
)
11657 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11659 eloc
= c_parser_peek_token (parser
)->location
;
11660 expr
= c_parser_unary_expression (parser
);
11662 expr
= default_function_array_read_conversion (eloc
, expr
);
11663 unfolded_lhs1
= expr
.value
;
11664 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11665 if (lhs1
== error_mark_node
)
11668 if (structured_block
)
11670 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11671 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11674 if (unfolded_lhs
&& unfolded_lhs1
11675 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11677 error ("%<#pragma omp atomic capture%> uses two different "
11678 "expressions for memory");
11679 stmt
= error_mark_node
;
11682 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11684 if (stmt
!= error_mark_node
)
11687 if (!structured_block
)
11688 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11693 # pragma omp barrier new-line
11697 c_parser_omp_barrier (c_parser
*parser
)
11699 location_t loc
= c_parser_peek_token (parser
)->location
;
11700 c_parser_consume_pragma (parser
);
11701 c_parser_skip_to_pragma_eol (parser
);
11703 c_finish_omp_barrier (loc
);
11707 # pragma omp critical [(name)] new-line
11710 LOC is the location of the #pragma itself. */
11713 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11715 tree stmt
, name
= NULL
;
11717 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11719 c_parser_consume_token (parser
);
11720 if (c_parser_next_token_is (parser
, CPP_NAME
))
11722 name
= c_parser_peek_token (parser
)->value
;
11723 c_parser_consume_token (parser
);
11724 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11727 c_parser_error (parser
, "expected identifier");
11729 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11730 c_parser_error (parser
, "expected %<(%> or end of line");
11731 c_parser_skip_to_pragma_eol (parser
);
11733 stmt
= c_parser_omp_structured_block (parser
);
11734 return c_finish_omp_critical (loc
, stmt
, name
);
11738 # pragma omp flush flush-vars[opt] new-line
11741 ( variable-list ) */
11744 c_parser_omp_flush (c_parser
*parser
)
11746 location_t loc
= c_parser_peek_token (parser
)->location
;
11747 c_parser_consume_pragma (parser
);
11748 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11749 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11750 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11751 c_parser_error (parser
, "expected %<(%> or end of line");
11752 c_parser_skip_to_pragma_eol (parser
);
11754 c_finish_omp_flush (loc
);
11757 /* Parse the restricted form of the for statement allowed by OpenMP.
11758 The real trick here is to determine the loop control variable early
11759 so that we can push a new decl if necessary to make it private.
11760 LOC is the location of the OMP in "#pragma omp". */
11763 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11764 tree clauses
, tree
*cclauses
)
11766 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11767 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11768 bool fail
= false, open_brace_parsed
= false;
11769 int i
, collapse
= 1, nbraces
= 0;
11770 location_t for_loc
;
11771 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11773 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11774 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11775 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
11777 gcc_assert (collapse
>= 1);
11779 declv
= make_tree_vec (collapse
);
11780 initv
= make_tree_vec (collapse
);
11781 condv
= make_tree_vec (collapse
);
11782 incrv
= make_tree_vec (collapse
);
11784 if (code
!= CILK_FOR
11785 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
11787 c_parser_error (parser
, "for statement expected");
11790 if (code
== CILK_FOR
11791 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
11793 c_parser_error (parser
, "_Cilk_for statement expected");
11796 for_loc
= c_parser_peek_token (parser
)->location
;
11797 c_parser_consume_token (parser
);
11799 for (i
= 0; i
< collapse
; i
++)
11801 int bracecount
= 0;
11803 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11806 /* Parse the initialization declaration or expression. */
11807 if (c_parser_next_tokens_start_declaration (parser
))
11810 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11811 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11813 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11816 if (DECL_INITIAL (decl
) == error_mark_node
)
11817 decl
= error_mark_node
;
11820 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11821 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11823 struct c_expr decl_exp
;
11824 struct c_expr init_exp
;
11825 location_t init_loc
;
11827 decl_exp
= c_parser_postfix_expression (parser
);
11828 decl
= decl_exp
.value
;
11830 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11832 init_loc
= c_parser_peek_token (parser
)->location
;
11833 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11834 init_exp
= default_function_array_read_conversion (init_loc
,
11836 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11837 NOP_EXPR
, init_loc
, init_exp
.value
,
11838 init_exp
.original_type
);
11839 init
= c_process_expr_stmt (init_loc
, init
);
11841 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11846 c_parser_error (parser
,
11847 "expected iteration declaration or initialization");
11848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11854 /* Parse the loop condition. */
11856 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11858 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11859 struct c_expr cond_expr
11860 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11862 cond
= cond_expr
.value
;
11863 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11864 cond
= c_fully_fold (cond
, false, NULL
);
11865 switch (cond_expr
.original_code
)
11873 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
11877 /* Can't be cond = error_mark_node, because we want to preserve
11878 the location until c_finish_omp_for. */
11879 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11882 protected_set_expr_location (cond
, cond_loc
);
11884 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11886 /* Parse the increment expression. */
11888 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11890 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11892 incr
= c_process_expr_stmt (incr_loc
,
11893 c_parser_expression (parser
).value
);
11895 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11897 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11901 TREE_VEC_ELT (declv
, i
) = decl
;
11902 TREE_VEC_ELT (initv
, i
) = init
;
11903 TREE_VEC_ELT (condv
, i
) = cond
;
11904 TREE_VEC_ELT (incrv
, i
) = incr
;
11908 if (i
== collapse
- 1)
11911 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11912 in between the collapsed for loops to be still considered perfectly
11913 nested. Hopefully the final version clarifies this.
11914 For now handle (multiple) {'s and empty statements. */
11917 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11919 c_parser_consume_token (parser
);
11922 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11924 c_parser_consume_token (parser
);
11927 else if (bracecount
11928 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11929 c_parser_consume_token (parser
);
11932 c_parser_error (parser
, "not enough perfectly nested loops");
11935 open_brace_parsed
= true;
11945 nbraces
+= bracecount
;
11948 save_break
= c_break_label
;
11949 if (code
== CILK_SIMD
)
11950 c_break_label
= build_int_cst (size_type_node
, 2);
11952 c_break_label
= size_one_node
;
11953 save_cont
= c_cont_label
;
11954 c_cont_label
= NULL_TREE
;
11955 body
= push_stmt_list ();
11957 if (open_brace_parsed
)
11959 location_t here
= c_parser_peek_token (parser
)->location
;
11960 stmt
= c_begin_compound_stmt (true);
11961 c_parser_compound_statement_nostart (parser
);
11962 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11965 add_stmt (c_parser_c99_block_statement (parser
));
11968 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11969 SET_EXPR_LOCATION (t
, loc
);
11973 body
= pop_stmt_list (body
);
11974 c_break_label
= save_break
;
11975 c_cont_label
= save_cont
;
11979 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11981 c_parser_consume_token (parser
);
11984 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11985 c_parser_consume_token (parser
);
11988 c_parser_error (parser
, "collapsed loops not perfectly nested");
11991 location_t here
= c_parser_peek_token (parser
)->location
;
11992 stmt
= c_begin_compound_stmt (true);
11994 c_parser_compound_statement_nostart (parser
);
11995 body
= c_end_compound_stmt (here
, stmt
, true);
12002 /* Only bother calling c_finish_omp_for if we haven't already generated
12003 an error from the initialization parsing. */
12006 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
12007 incrv
, body
, NULL
);
12010 if (cclauses
!= NULL
12011 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
12014 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
12015 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
12016 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
12017 c
= &OMP_CLAUSE_CHAIN (*c
);
12020 for (i
= 0; i
< collapse
; i
++)
12021 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
12024 c
= &OMP_CLAUSE_CHAIN (*c
);
12025 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
12028 "iteration variable %qD should not be firstprivate",
12029 OMP_CLAUSE_DECL (*c
));
12030 *c
= OMP_CLAUSE_CHAIN (*c
);
12034 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
12035 change it to shared (decl) in
12036 OMP_PARALLEL_CLAUSES. */
12037 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
12038 OMP_CLAUSE_LASTPRIVATE
);
12039 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
12040 if (code
== OMP_SIMD
)
12042 OMP_CLAUSE_CHAIN (l
)
12043 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12044 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
12048 OMP_CLAUSE_CHAIN (l
) = clauses
;
12051 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
12055 OMP_FOR_CLAUSES (stmt
) = clauses
;
12060 while (!for_block
->is_empty ())
12062 /* FIXME diagnostics: LOC below should be the actual location of
12063 this particular for block. We need to build a list of
12064 locations to go along with FOR_BLOCK. */
12065 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
12068 release_tree_vector (for_block
);
12072 /* Helper function for OpenMP parsing, split clauses and call
12073 finish_omp_clauses on each of the set of clauses afterwards. */
12076 omp_split_clauses (location_t loc
, enum tree_code code
,
12077 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
12080 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
12081 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
12083 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
12087 #pragma omp simd simd-clause[optseq] new-line
12090 LOC is the location of the #pragma token.
12093 #define OMP_SIMD_CLAUSE_MASK \
12094 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
12095 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12096 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12097 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12098 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12099 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12100 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12103 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
12104 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12106 tree block
, clauses
, ret
;
12108 strcat (p_name
, " simd");
12109 mask
|= OMP_SIMD_CLAUSE_MASK
;
12110 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
12112 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12115 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
12116 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
12119 block
= c_begin_compound_stmt (true);
12120 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
12121 block
= c_end_compound_stmt (loc
, block
, true);
12128 #pragma omp for for-clause[optseq] new-line
12132 #pragma omp for simd for-simd-clause[optseq] new-line
12135 LOC is the location of the #pragma token.
12138 #define OMP_FOR_CLAUSE_MASK \
12139 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12140 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12141 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12142 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12143 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12144 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12145 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12146 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12149 c_parser_omp_for (location_t loc
, c_parser
*parser
,
12150 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12152 tree block
, clauses
, ret
;
12154 strcat (p_name
, " for");
12155 mask
|= OMP_FOR_CLAUSE_MASK
;
12157 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12159 if (c_parser_next_token_is (parser
, CPP_NAME
))
12161 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12163 if (strcmp (p
, "simd") == 0)
12165 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12166 if (cclauses
== NULL
)
12167 cclauses
= cclauses_buf
;
12169 c_parser_consume_token (parser
);
12170 if (!flag_openmp
) /* flag_openmp_simd */
12171 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12172 block
= c_begin_compound_stmt (true);
12173 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12174 block
= c_end_compound_stmt (loc
, block
, true);
12175 if (ret
== NULL_TREE
)
12177 ret
= make_node (OMP_FOR
);
12178 TREE_TYPE (ret
) = void_type_node
;
12179 OMP_FOR_BODY (ret
) = block
;
12180 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12181 SET_EXPR_LOCATION (ret
, loc
);
12186 if (!flag_openmp
) /* flag_openmp_simd */
12188 c_parser_skip_to_pragma_eol (parser
);
12192 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12195 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12196 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12199 block
= c_begin_compound_stmt (true);
12200 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12201 block
= c_end_compound_stmt (loc
, block
, true);
12208 # pragma omp master new-line
12211 LOC is the location of the #pragma token.
12215 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12217 c_parser_skip_to_pragma_eol (parser
);
12218 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12222 # pragma omp ordered new-line
12225 LOC is the location of the #pragma itself.
12229 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12231 c_parser_skip_to_pragma_eol (parser
);
12232 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12238 { section-sequence }
12241 section-directive[opt] structured-block
12242 section-sequence section-directive structured-block
12244 SECTIONS_LOC is the location of the #pragma omp sections. */
12247 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12249 tree stmt
, substmt
;
12250 bool error_suppress
= false;
12253 loc
= c_parser_peek_token (parser
)->location
;
12254 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12256 /* Avoid skipping until the end of the block. */
12257 parser
->error
= false;
12261 stmt
= push_stmt_list ();
12263 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12265 substmt
= c_parser_omp_structured_block (parser
);
12266 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12267 SET_EXPR_LOCATION (substmt
, loc
);
12268 add_stmt (substmt
);
12273 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12275 if (c_parser_next_token_is (parser
, CPP_EOF
))
12278 loc
= c_parser_peek_token (parser
)->location
;
12279 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12281 c_parser_consume_pragma (parser
);
12282 c_parser_skip_to_pragma_eol (parser
);
12283 error_suppress
= false;
12285 else if (!error_suppress
)
12287 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12288 error_suppress
= true;
12291 substmt
= c_parser_omp_structured_block (parser
);
12292 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12293 SET_EXPR_LOCATION (substmt
, loc
);
12294 add_stmt (substmt
);
12296 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12297 "expected %<#pragma omp section%> or %<}%>");
12299 substmt
= pop_stmt_list (stmt
);
12301 stmt
= make_node (OMP_SECTIONS
);
12302 SET_EXPR_LOCATION (stmt
, sections_loc
);
12303 TREE_TYPE (stmt
) = void_type_node
;
12304 OMP_SECTIONS_BODY (stmt
) = substmt
;
12306 return add_stmt (stmt
);
12310 # pragma omp sections sections-clause[optseq] newline
12313 LOC is the location of the #pragma token.
12316 #define OMP_SECTIONS_CLAUSE_MASK \
12317 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12318 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12324 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12325 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12327 tree block
, clauses
, ret
;
12329 strcat (p_name
, " sections");
12330 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12332 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12334 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12337 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12338 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12341 block
= c_begin_compound_stmt (true);
12342 ret
= c_parser_omp_sections_scope (loc
, parser
);
12344 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12345 block
= c_end_compound_stmt (loc
, block
, true);
12352 # pragma omp parallel parallel-clause[optseq] new-line
12354 # pragma omp parallel for parallel-for-clause[optseq] new-line
12356 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12360 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12363 LOC is the location of the #pragma token.
12366 #define OMP_PARALLEL_CLAUSE_MASK \
12367 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12368 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12369 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12370 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12371 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12372 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12373 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12374 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12375 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12378 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12379 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12381 tree stmt
, clauses
, block
;
12383 strcat (p_name
, " parallel");
12384 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12386 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12388 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12389 if (cclauses
== NULL
)
12390 cclauses
= cclauses_buf
;
12392 c_parser_consume_token (parser
);
12393 if (!flag_openmp
) /* flag_openmp_simd */
12394 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12395 block
= c_begin_omp_parallel ();
12396 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12398 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12400 if (ret
== NULL_TREE
)
12402 OMP_PARALLEL_COMBINED (stmt
) = 1;
12407 error_at (loc
, "expected %<for%> after %qs", p_name
);
12408 c_parser_skip_to_pragma_eol (parser
);
12411 else if (!flag_openmp
) /* flag_openmp_simd */
12413 c_parser_skip_to_pragma_eol (parser
);
12416 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12418 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12419 if (strcmp (p
, "sections") == 0)
12421 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12422 if (cclauses
== NULL
)
12423 cclauses
= cclauses_buf
;
12425 c_parser_consume_token (parser
);
12426 block
= c_begin_omp_parallel ();
12427 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12428 stmt
= c_finish_omp_parallel (loc
,
12429 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12431 OMP_PARALLEL_COMBINED (stmt
) = 1;
12436 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12438 block
= c_begin_omp_parallel ();
12439 c_parser_statement (parser
);
12440 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12446 # pragma omp single single-clause[optseq] new-line
12449 LOC is the location of the #pragma.
12452 #define OMP_SINGLE_CLAUSE_MASK \
12453 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12454 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12455 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12456 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12459 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12461 tree stmt
= make_node (OMP_SINGLE
);
12462 SET_EXPR_LOCATION (stmt
, loc
);
12463 TREE_TYPE (stmt
) = void_type_node
;
12465 OMP_SINGLE_CLAUSES (stmt
)
12466 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12467 "#pragma omp single");
12468 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12470 return add_stmt (stmt
);
12474 # pragma omp task task-clause[optseq] new-line
12476 LOC is the location of the #pragma.
12479 #define OMP_TASK_CLAUSE_MASK \
12480 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12481 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12482 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12483 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12484 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12485 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12486 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12487 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12488 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12491 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12493 tree clauses
, block
;
12495 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12496 "#pragma omp task");
12498 block
= c_begin_omp_task ();
12499 c_parser_statement (parser
);
12500 return c_finish_omp_task (loc
, clauses
, block
);
12504 # pragma omp taskwait new-line
12508 c_parser_omp_taskwait (c_parser
*parser
)
12510 location_t loc
= c_parser_peek_token (parser
)->location
;
12511 c_parser_consume_pragma (parser
);
12512 c_parser_skip_to_pragma_eol (parser
);
12514 c_finish_omp_taskwait (loc
);
12518 # pragma omp taskyield new-line
12522 c_parser_omp_taskyield (c_parser
*parser
)
12524 location_t loc
= c_parser_peek_token (parser
)->location
;
12525 c_parser_consume_pragma (parser
);
12526 c_parser_skip_to_pragma_eol (parser
);
12528 c_finish_omp_taskyield (loc
);
12532 # pragma omp taskgroup new-line
12536 c_parser_omp_taskgroup (c_parser
*parser
)
12538 location_t loc
= c_parser_peek_token (parser
)->location
;
12539 c_parser_skip_to_pragma_eol (parser
);
12540 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12544 # pragma omp cancel cancel-clause[optseq] new-line
12546 LOC is the location of the #pragma.
12549 #define OMP_CANCEL_CLAUSE_MASK \
12550 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12551 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12552 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12553 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12554 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12557 c_parser_omp_cancel (c_parser
*parser
)
12559 location_t loc
= c_parser_peek_token (parser
)->location
;
12561 c_parser_consume_pragma (parser
);
12562 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12563 "#pragma omp cancel");
12565 c_finish_omp_cancel (loc
, clauses
);
12569 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12571 LOC is the location of the #pragma.
12574 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12575 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12576 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12577 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12578 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12581 c_parser_omp_cancellation_point (c_parser
*parser
)
12583 location_t loc
= c_parser_peek_token (parser
)->location
;
12585 bool point_seen
= false;
12587 c_parser_consume_pragma (parser
);
12588 if (c_parser_next_token_is (parser
, CPP_NAME
))
12590 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12591 if (strcmp (p
, "point") == 0)
12593 c_parser_consume_token (parser
);
12599 c_parser_error (parser
, "expected %<point%>");
12600 c_parser_skip_to_pragma_eol (parser
);
12605 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12606 "#pragma omp cancellation point");
12608 c_finish_omp_cancellation_point (loc
, clauses
);
12612 #pragma omp distribute distribute-clause[optseq] new-line
12615 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12616 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12622 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12623 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12625 tree clauses
, block
, ret
;
12627 strcat (p_name
, " distribute");
12628 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12630 if (c_parser_next_token_is (parser
, CPP_NAME
))
12632 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12634 bool parallel
= false;
12636 if (strcmp (p
, "simd") == 0)
12639 parallel
= strcmp (p
, "parallel") == 0;
12640 if (parallel
|| simd
)
12642 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12643 if (cclauses
== NULL
)
12644 cclauses
= cclauses_buf
;
12645 c_parser_consume_token (parser
);
12646 if (!flag_openmp
) /* flag_openmp_simd */
12649 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12651 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12654 block
= c_begin_compound_stmt (true);
12656 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12658 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12659 block
= c_end_compound_stmt (loc
, block
, true);
12662 ret
= make_node (OMP_DISTRIBUTE
);
12663 TREE_TYPE (ret
) = void_type_node
;
12664 OMP_FOR_BODY (ret
) = block
;
12665 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12666 SET_EXPR_LOCATION (ret
, loc
);
12671 if (!flag_openmp
) /* flag_openmp_simd */
12673 c_parser_skip_to_pragma_eol (parser
);
12677 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12680 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12681 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12684 block
= c_begin_compound_stmt (true);
12685 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12686 block
= c_end_compound_stmt (loc
, block
, true);
12693 # pragma omp teams teams-clause[optseq] new-line
12694 structured-block */
12696 #define OMP_TEAMS_CLAUSE_MASK \
12697 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12698 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12699 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12700 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12701 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12702 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12703 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12706 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12707 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12709 tree clauses
, block
, ret
;
12711 strcat (p_name
, " teams");
12712 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12714 if (c_parser_next_token_is (parser
, CPP_NAME
))
12716 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12717 if (strcmp (p
, "distribute") == 0)
12719 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12720 if (cclauses
== NULL
)
12721 cclauses
= cclauses_buf
;
12723 c_parser_consume_token (parser
);
12724 if (!flag_openmp
) /* flag_openmp_simd */
12725 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12726 block
= c_begin_compound_stmt (true);
12727 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12728 block
= c_end_compound_stmt (loc
, block
, true);
12731 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12732 ret
= make_node (OMP_TEAMS
);
12733 TREE_TYPE (ret
) = void_type_node
;
12734 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12735 OMP_TEAMS_BODY (ret
) = block
;
12736 return add_stmt (ret
);
12739 if (!flag_openmp
) /* flag_openmp_simd */
12741 c_parser_skip_to_pragma_eol (parser
);
12745 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12748 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12749 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12752 tree stmt
= make_node (OMP_TEAMS
);
12753 TREE_TYPE (stmt
) = void_type_node
;
12754 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12755 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12757 return add_stmt (stmt
);
12761 # pragma omp target data target-data-clause[optseq] new-line
12762 structured-block */
12764 #define OMP_TARGET_DATA_CLAUSE_MASK \
12765 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12766 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12767 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12770 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12772 tree stmt
= make_node (OMP_TARGET_DATA
);
12773 TREE_TYPE (stmt
) = void_type_node
;
12775 OMP_TARGET_DATA_CLAUSES (stmt
)
12776 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12777 "#pragma omp target data");
12778 keep_next_level ();
12779 tree block
= c_begin_compound_stmt (true);
12780 add_stmt (c_parser_omp_structured_block (parser
));
12781 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12783 SET_EXPR_LOCATION (stmt
, loc
);
12784 return add_stmt (stmt
);
12788 # pragma omp target update target-update-clause[optseq] new-line */
12790 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12791 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12792 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12793 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12794 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12797 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12798 enum pragma_context context
)
12800 if (context
== pragma_stmt
)
12803 "%<#pragma omp target update%> may only be "
12804 "used in compound statements");
12805 c_parser_skip_to_pragma_eol (parser
);
12810 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12811 "#pragma omp target update");
12812 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12813 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12816 "%<#pragma omp target update must contain at least one "
12817 "%<from%> or %<to%> clauses");
12821 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12822 TREE_TYPE (stmt
) = void_type_node
;
12823 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12824 SET_EXPR_LOCATION (stmt
, loc
);
12830 # pragma omp target target-clause[optseq] new-line
12831 structured-block */
12833 #define OMP_TARGET_CLAUSE_MASK \
12834 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12835 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12836 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12839 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12841 location_t loc
= c_parser_peek_token (parser
)->location
;
12842 c_parser_consume_pragma (parser
);
12844 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12846 c_parser_error (parser
, "expected declaration specifiers");
12847 c_parser_skip_to_pragma_eol (parser
);
12851 if (c_parser_next_token_is (parser
, CPP_NAME
))
12853 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12855 if (strcmp (p
, "teams") == 0)
12857 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12858 char p_name
[sizeof ("#pragma omp target teams distribute "
12859 "parallel for simd")];
12861 c_parser_consume_token (parser
);
12862 strcpy (p_name
, "#pragma omp target");
12863 if (!flag_openmp
) /* flag_openmp_simd */
12865 tree stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
12866 OMP_TARGET_CLAUSE_MASK
,
12868 return stmt
!= NULL_TREE
;
12870 keep_next_level ();
12871 tree block
= c_begin_compound_stmt (true);
12872 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12873 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12874 block
= c_end_compound_stmt (loc
, block
, true);
12875 if (ret
== NULL_TREE
)
12877 tree stmt
= make_node (OMP_TARGET
);
12878 TREE_TYPE (stmt
) = void_type_node
;
12879 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12880 OMP_TARGET_BODY (stmt
) = block
;
12884 else if (!flag_openmp
) /* flag_openmp_simd */
12886 c_parser_skip_to_pragma_eol (parser
);
12889 else if (strcmp (p
, "data") == 0)
12891 c_parser_consume_token (parser
);
12892 c_parser_omp_target_data (loc
, parser
);
12895 else if (strcmp (p
, "update") == 0)
12897 c_parser_consume_token (parser
);
12898 return c_parser_omp_target_update (loc
, parser
, context
);
12902 tree stmt
= make_node (OMP_TARGET
);
12903 TREE_TYPE (stmt
) = void_type_node
;
12905 OMP_TARGET_CLAUSES (stmt
)
12906 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12907 "#pragma omp target");
12908 keep_next_level ();
12909 tree block
= c_begin_compound_stmt (true);
12910 add_stmt (c_parser_omp_structured_block (parser
));
12911 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12913 SET_EXPR_LOCATION (stmt
, loc
);
12919 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12921 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12922 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12923 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12924 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12925 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12926 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12927 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12930 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12932 vec
<c_token
> clauses
= vNULL
;
12933 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12935 c_token
*token
= c_parser_peek_token (parser
);
12936 if (token
->type
== CPP_EOF
)
12938 c_parser_skip_to_pragma_eol (parser
);
12939 clauses
.release ();
12942 clauses
.safe_push (*token
);
12943 c_parser_consume_token (parser
);
12945 clauses
.safe_push (*c_parser_peek_token (parser
));
12946 c_parser_skip_to_pragma_eol (parser
);
12948 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12950 if (c_parser_peek_token (parser
)->pragma_kind
12951 != PRAGMA_OMP_DECLARE_REDUCTION
12952 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12953 || strcmp (IDENTIFIER_POINTER
12954 (c_parser_peek_2nd_token (parser
)->value
),
12957 c_parser_error (parser
,
12958 "%<#pragma omp declare simd%> must be followed by "
12959 "function declaration or definition or another "
12960 "%<#pragma omp declare simd%>");
12961 clauses
.release ();
12964 c_parser_consume_pragma (parser
);
12965 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12967 c_token
*token
= c_parser_peek_token (parser
);
12968 if (token
->type
== CPP_EOF
)
12970 c_parser_skip_to_pragma_eol (parser
);
12971 clauses
.release ();
12974 clauses
.safe_push (*token
);
12975 c_parser_consume_token (parser
);
12977 clauses
.safe_push (*c_parser_peek_token (parser
));
12978 c_parser_skip_to_pragma_eol (parser
);
12981 /* Make sure nothing tries to read past the end of the tokens. */
12983 memset (&eof_token
, 0, sizeof (eof_token
));
12984 eof_token
.type
= CPP_EOF
;
12985 clauses
.safe_push (eof_token
);
12986 clauses
.safe_push (eof_token
);
12990 case pragma_external
:
12991 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12992 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12994 int ext
= disable_extension_diagnostics ();
12996 c_parser_consume_token (parser
);
12997 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12998 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12999 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13001 restore_extension_diagnostics (ext
);
13004 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
13007 case pragma_struct
:
13009 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13010 "function declaration or definition");
13012 case pragma_compound
:
13014 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13015 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
13017 int ext
= disable_extension_diagnostics ();
13019 c_parser_consume_token (parser
);
13020 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
13021 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
13022 if (c_parser_next_tokens_start_declaration (parser
))
13024 c_parser_declaration_or_fndef (parser
, true, true, true, true,
13025 true, NULL
, clauses
);
13026 restore_extension_diagnostics (ext
);
13029 restore_extension_diagnostics (ext
);
13031 else if (c_parser_next_tokens_start_declaration (parser
))
13033 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
13037 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
13038 "function declaration or definition");
13041 gcc_unreachable ();
13043 clauses
.release ();
13046 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
13047 and put that into "omp declare simd" attribute. */
13050 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
13051 vec
<c_token
> clauses
)
13054 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13056 error ("%<#pragma omp declare simd%> cannot be used in the same "
13057 "function marked as a Cilk Plus SIMD-enabled function");
13058 vec_free (parser
->cilk_simd_fn_tokens
);
13062 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
13063 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
13064 has already processed the tokens. */
13065 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
13067 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
13069 error ("%<#pragma omp declare simd%> not immediately followed by "
13070 "a function declaration or definition");
13071 clauses
[0].type
= CPP_EOF
;
13074 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
13076 error_at (DECL_SOURCE_LOCATION (fndecl
),
13077 "%<#pragma omp declare simd%> not immediately followed by "
13078 "a single function declaration or definition");
13079 clauses
[0].type
= CPP_EOF
;
13083 if (parms
== NULL_TREE
)
13084 parms
= DECL_ARGUMENTS (fndecl
);
13086 unsigned int tokens_avail
= parser
->tokens_avail
;
13087 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13088 bool is_cilkplus_cilk_simd_fn
= false;
13090 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13092 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
13093 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
13094 is_cilkplus_cilk_simd_fn
= true;
13098 parser
->tokens
= clauses
.address ();
13099 parser
->tokens_avail
= clauses
.length ();
13102 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
13103 while (parser
->tokens_avail
> 3)
13105 c_token
*token
= c_parser_peek_token (parser
);
13106 if (!is_cilkplus_cilk_simd_fn
)
13107 gcc_assert (token
->type
== CPP_NAME
13108 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
13110 gcc_assert (token
->type
== CPP_NAME
13111 && is_cilkplus_vector_p (token
->value
));
13112 c_parser_consume_token (parser
);
13113 parser
->in_pragma
= true;
13115 tree c
= NULL_TREE
;
13116 if (is_cilkplus_cilk_simd_fn
)
13117 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
13118 "SIMD-enabled functions attribute");
13120 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
13121 "#pragma omp declare simd");
13122 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
13123 if (c
!= NULL_TREE
)
13124 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
13125 if (is_cilkplus_cilk_simd_fn
)
13127 tree k
= build_tree_list (get_identifier ("cilk simd function"),
13129 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
13130 DECL_ATTRIBUTES (fndecl
) = k
;
13132 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
13133 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
13134 DECL_ATTRIBUTES (fndecl
) = c
;
13137 parser
->tokens
= &parser
->tokens_buf
[0];
13138 parser
->tokens_avail
= tokens_avail
;
13139 if (clauses
.exists ())
13140 clauses
[0].type
= CPP_PRAGMA
;
13142 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
13143 vec_free (parser
->cilk_simd_fn_tokens
);
13148 # pragma omp declare target new-line
13149 declarations and definitions
13150 # pragma omp end declare target new-line */
13153 c_parser_omp_declare_target (c_parser
*parser
)
13155 c_parser_skip_to_pragma_eol (parser
);
13156 current_omp_declare_target_attribute
++;
13160 c_parser_omp_end_declare_target (c_parser
*parser
)
13162 location_t loc
= c_parser_peek_token (parser
)->location
;
13163 c_parser_consume_pragma (parser
);
13164 if (c_parser_next_token_is (parser
, CPP_NAME
)
13165 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13168 c_parser_consume_token (parser
);
13169 if (c_parser_next_token_is (parser
, CPP_NAME
)
13170 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13172 c_parser_consume_token (parser
);
13175 c_parser_error (parser
, "expected %<target%>");
13176 c_parser_skip_to_pragma_eol (parser
);
13182 c_parser_error (parser
, "expected %<declare%>");
13183 c_parser_skip_to_pragma_eol (parser
);
13186 c_parser_skip_to_pragma_eol (parser
);
13187 if (!current_omp_declare_target_attribute
)
13188 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13189 "%<#pragma omp declare target%>");
13191 current_omp_declare_target_attribute
--;
13196 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13197 initializer-clause[opt] new-line
13199 initializer-clause:
13200 initializer (omp_priv = initializer)
13201 initializer (function-name (argument-list)) */
13204 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13206 unsigned int tokens_avail
= 0, i
;
13207 vec
<tree
> types
= vNULL
;
13208 vec
<c_token
> clauses
= vNULL
;
13209 enum tree_code reduc_code
= ERROR_MARK
;
13210 tree reduc_id
= NULL_TREE
;
13212 location_t rloc
= c_parser_peek_token (parser
)->location
;
13214 if (context
== pragma_struct
|| context
== pragma_param
)
13216 error ("%<#pragma omp declare reduction%> not at file or block scope");
13220 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13223 switch (c_parser_peek_token (parser
)->type
)
13226 reduc_code
= PLUS_EXPR
;
13229 reduc_code
= MULT_EXPR
;
13232 reduc_code
= MINUS_EXPR
;
13235 reduc_code
= BIT_AND_EXPR
;
13238 reduc_code
= BIT_XOR_EXPR
;
13241 reduc_code
= BIT_IOR_EXPR
;
13244 reduc_code
= TRUTH_ANDIF_EXPR
;
13247 reduc_code
= TRUTH_ORIF_EXPR
;
13251 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13252 if (strcmp (p
, "min") == 0)
13254 reduc_code
= MIN_EXPR
;
13257 if (strcmp (p
, "max") == 0)
13259 reduc_code
= MAX_EXPR
;
13262 reduc_id
= c_parser_peek_token (parser
)->value
;
13265 c_parser_error (parser
,
13266 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13267 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13271 tree orig_reduc_id
, reduc_decl
;
13272 orig_reduc_id
= reduc_id
;
13273 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13274 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13275 c_parser_consume_token (parser
);
13277 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13282 location_t loc
= c_parser_peek_token (parser
)->location
;
13283 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13286 type
= groktypename (ctype
, NULL
, NULL
);
13287 if (type
== error_mark_node
)
13289 else if ((INTEGRAL_TYPE_P (type
)
13290 || TREE_CODE (type
) == REAL_TYPE
13291 || TREE_CODE (type
) == COMPLEX_TYPE
)
13292 && orig_reduc_id
== NULL_TREE
)
13293 error_at (loc
, "predeclared arithmetic type in "
13294 "%<#pragma omp declare reduction%>");
13295 else if (TREE_CODE (type
) == FUNCTION_TYPE
13296 || TREE_CODE (type
) == ARRAY_TYPE
)
13297 error_at (loc
, "function or array type in "
13298 "%<#pragma omp declare reduction%>");
13299 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13300 error_at (loc
, "const, volatile or restrict qualified type in "
13301 "%<#pragma omp declare reduction%>");
13305 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13306 if (comptypes (TREE_PURPOSE (t
), type
))
13308 error_at (loc
, "redeclaration of %qs "
13309 "%<#pragma omp declare reduction%> for "
13311 IDENTIFIER_POINTER (reduc_id
)
13312 + sizeof ("omp declare reduction ") - 1,
13315 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13317 error_at (ploc
, "previous %<#pragma omp declare "
13321 if (t
== NULL_TREE
)
13322 types
.safe_push (type
);
13324 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13325 c_parser_consume_token (parser
);
13333 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13334 || types
.is_empty ())
13337 clauses
.release ();
13341 c_token
*token
= c_parser_peek_token (parser
);
13342 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13344 c_parser_consume_token (parser
);
13346 c_parser_skip_to_pragma_eol (parser
);
13350 if (types
.length () > 1)
13352 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13354 c_token
*token
= c_parser_peek_token (parser
);
13355 if (token
->type
== CPP_EOF
)
13357 clauses
.safe_push (*token
);
13358 c_parser_consume_token (parser
);
13360 clauses
.safe_push (*c_parser_peek_token (parser
));
13361 c_parser_skip_to_pragma_eol (parser
);
13363 /* Make sure nothing tries to read past the end of the tokens. */
13365 memset (&eof_token
, 0, sizeof (eof_token
));
13366 eof_token
.type
= CPP_EOF
;
13367 clauses
.safe_push (eof_token
);
13368 clauses
.safe_push (eof_token
);
13371 int errs
= errorcount
;
13372 FOR_EACH_VEC_ELT (types
, i
, type
)
13374 tokens_avail
= parser
->tokens_avail
;
13375 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13376 if (!clauses
.is_empty ())
13378 parser
->tokens
= clauses
.address ();
13379 parser
->tokens_avail
= clauses
.length ();
13380 parser
->in_pragma
= true;
13383 bool nested
= current_function_decl
!= NULL_TREE
;
13385 c_push_function_context ();
13386 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13387 reduc_id
, default_function_type
);
13388 current_function_decl
= fndecl
;
13389 allocate_struct_function (fndecl
, true);
13391 tree stmt
= push_stmt_list ();
13392 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13393 warn about these. */
13394 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13395 get_identifier ("omp_out"), type
);
13396 DECL_ARTIFICIAL (omp_out
) = 1;
13397 DECL_CONTEXT (omp_out
) = fndecl
;
13398 pushdecl (omp_out
);
13399 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13400 get_identifier ("omp_in"), type
);
13401 DECL_ARTIFICIAL (omp_in
) = 1;
13402 DECL_CONTEXT (omp_in
) = fndecl
;
13404 struct c_expr combiner
= c_parser_expression (parser
);
13405 struct c_expr initializer
;
13406 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13408 initializer
.value
= error_mark_node
;
13409 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13411 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13412 && strcmp (IDENTIFIER_POINTER
13413 (c_parser_peek_token (parser
)->value
),
13414 "initializer") == 0)
13416 c_parser_consume_token (parser
);
13419 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13420 get_identifier ("omp_priv"), type
);
13421 DECL_ARTIFICIAL (omp_priv
) = 1;
13422 DECL_INITIAL (omp_priv
) = error_mark_node
;
13423 DECL_CONTEXT (omp_priv
) = fndecl
;
13424 pushdecl (omp_priv
);
13425 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13426 get_identifier ("omp_orig"), type
);
13427 DECL_ARTIFICIAL (omp_orig
) = 1;
13428 DECL_CONTEXT (omp_orig
) = fndecl
;
13429 pushdecl (omp_orig
);
13430 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13432 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13434 c_parser_error (parser
, "expected %<omp_priv%> or "
13438 else if (strcmp (IDENTIFIER_POINTER
13439 (c_parser_peek_token (parser
)->value
),
13442 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13443 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13445 c_parser_error (parser
, "expected function-name %<(%>");
13449 initializer
= c_parser_postfix_expression (parser
);
13450 if (initializer
.value
13451 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13454 tree c
= initializer
.value
;
13455 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13456 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13457 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13459 if (j
== call_expr_nargs (c
))
13460 error ("one of the initializer call arguments should be "
13466 c_parser_consume_token (parser
);
13467 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13471 tree st
= push_stmt_list ();
13472 start_init (omp_priv
, NULL_TREE
, 0);
13473 location_t loc
= c_parser_peek_token (parser
)->location
;
13474 struct c_expr init
= c_parser_initializer (parser
);
13476 finish_decl (omp_priv
, loc
, init
.value
,
13477 init
.original_type
, NULL_TREE
);
13478 pop_stmt_list (st
);
13482 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13488 c_parser_skip_to_pragma_eol (parser
);
13490 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13491 DECL_INITIAL (reduc_decl
));
13492 DECL_INITIAL (reduc_decl
) = t
;
13493 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13494 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13495 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13496 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13497 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13498 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13501 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13502 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13503 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13504 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13505 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13506 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13507 walk_tree (&DECL_INITIAL (omp_priv
),
13508 c_check_omp_declare_reduction_r
,
13509 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13513 pop_stmt_list (stmt
);
13515 if (cfun
->language
!= NULL
)
13517 ggc_free (cfun
->language
);
13518 cfun
->language
= NULL
;
13521 current_function_decl
= NULL_TREE
;
13523 c_pop_function_context ();
13525 if (!clauses
.is_empty ())
13527 parser
->tokens
= &parser
->tokens_buf
[0];
13528 parser
->tokens_avail
= tokens_avail
;
13532 if (errs
!= errorcount
)
13536 clauses
.release ();
13542 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13543 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13544 initializer-clause[opt] new-line
13545 #pragma omp declare target new-line */
13548 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13550 c_parser_consume_pragma (parser
);
13551 if (c_parser_next_token_is (parser
, CPP_NAME
))
13553 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13554 if (strcmp (p
, "simd") == 0)
13556 /* c_parser_consume_token (parser); done in
13557 c_parser_omp_declare_simd. */
13558 c_parser_omp_declare_simd (parser
, context
);
13561 if (strcmp (p
, "reduction") == 0)
13563 c_parser_consume_token (parser
);
13564 c_parser_omp_declare_reduction (parser
, context
);
13567 if (!flag_openmp
) /* flag_openmp_simd */
13569 c_parser_skip_to_pragma_eol (parser
);
13572 if (strcmp (p
, "target") == 0)
13574 c_parser_consume_token (parser
);
13575 c_parser_omp_declare_target (parser
);
13580 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13582 c_parser_skip_to_pragma_eol (parser
);
13585 /* Main entry point to parsing most OpenMP pragmas. */
13588 c_parser_omp_construct (c_parser
*parser
)
13590 enum pragma_kind p_kind
;
13593 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13594 omp_clause_mask
mask (0);
13596 loc
= c_parser_peek_token (parser
)->location
;
13597 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13598 c_parser_consume_pragma (parser
);
13602 case PRAGMA_OMP_ATOMIC
:
13603 c_parser_omp_atomic (loc
, parser
);
13605 case PRAGMA_OMP_CRITICAL
:
13606 stmt
= c_parser_omp_critical (loc
, parser
);
13608 case PRAGMA_OMP_DISTRIBUTE
:
13609 strcpy (p_name
, "#pragma omp");
13610 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13612 case PRAGMA_OMP_FOR
:
13613 strcpy (p_name
, "#pragma omp");
13614 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13616 case PRAGMA_OMP_MASTER
:
13617 stmt
= c_parser_omp_master (loc
, parser
);
13619 case PRAGMA_OMP_ORDERED
:
13620 stmt
= c_parser_omp_ordered (loc
, parser
);
13622 case PRAGMA_OMP_PARALLEL
:
13623 strcpy (p_name
, "#pragma omp");
13624 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13626 case PRAGMA_OMP_SECTIONS
:
13627 strcpy (p_name
, "#pragma omp");
13628 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13630 case PRAGMA_OMP_SIMD
:
13631 strcpy (p_name
, "#pragma omp");
13632 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13634 case PRAGMA_OMP_SINGLE
:
13635 stmt
= c_parser_omp_single (loc
, parser
);
13637 case PRAGMA_OMP_TASK
:
13638 stmt
= c_parser_omp_task (loc
, parser
);
13640 case PRAGMA_OMP_TASKGROUP
:
13641 stmt
= c_parser_omp_taskgroup (parser
);
13643 case PRAGMA_OMP_TEAMS
:
13644 strcpy (p_name
, "#pragma omp");
13645 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13648 gcc_unreachable ();
13652 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13657 # pragma omp threadprivate (variable-list) */
13660 c_parser_omp_threadprivate (c_parser
*parser
)
13665 c_parser_consume_pragma (parser
);
13666 loc
= c_parser_peek_token (parser
)->location
;
13667 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13669 /* Mark every variable in VARS to be assigned thread local storage. */
13670 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13672 tree v
= TREE_PURPOSE (t
);
13674 /* FIXME diagnostics: Ideally we should keep individual
13675 locations for all the variables in the var list to make the
13676 following errors more precise. Perhaps
13677 c_parser_omp_var_list_parens() should construct a list of
13678 locations to go along with the var list. */
13680 /* If V had already been marked threadprivate, it doesn't matter
13681 whether it had been used prior to this point. */
13682 if (TREE_CODE (v
) != VAR_DECL
)
13683 error_at (loc
, "%qD is not a variable", v
);
13684 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13685 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13686 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13687 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13688 else if (TREE_TYPE (v
) == error_mark_node
)
13690 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13691 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13694 if (! DECL_THREAD_LOCAL_P (v
))
13696 set_decl_tls_model (v
, decl_default_tls_model (v
));
13697 /* If rtl has been already set for this var, call
13698 make_decl_rtl once again, so that encode_section_info
13699 has a chance to look at the new decl flags. */
13700 if (DECL_RTL_SET_P (v
))
13703 C_DECL_THREADPRIVATE_P (v
) = 1;
13707 c_parser_skip_to_pragma_eol (parser
);
13710 /* Cilk Plus <#pragma simd> parsing routines. */
13712 /* Helper function for c_parser_pragma. Perform some sanity checking
13713 for <#pragma simd> constructs. Returns FALSE if there was a
13717 c_parser_cilk_verify_simd (c_parser
*parser
,
13718 enum pragma_context context
)
13720 if (!flag_cilkplus
)
13722 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13723 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13726 if (context
== pragma_external
)
13728 c_parser_error (parser
,"pragma simd must be inside a function");
13729 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13736 This function is shared by SIMD-enabled functions and #pragma simd.
13737 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
13738 CLAUSES is unused. The main purpose of this function is to parse a
13739 vectorlength attribute or clause and check for parse errors.
13740 When IS_SIMD_FN is true then the function is merely caching the tokens
13741 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
13742 cache is cleared since there is no reason to continue.
13744 vectorlength ( constant-expression ) */
13747 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
13751 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
13753 /* The vectorlength clause behaves exactly like OpenMP's safelen
13754 clause. Represent it in OpenMP terms. */
13755 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13757 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13760 location_t loc
= c_parser_peek_token (parser
)->location
;
13761 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13762 expr
= c_fully_fold (expr
, false, NULL
);
13764 /* If expr is an error_mark_node then the above function would have
13765 emitted an error. No reason to do it twice. */
13766 if (expr
== error_mark_node
)
13768 else if (!TREE_TYPE (expr
)
13769 || !TREE_CONSTANT (expr
)
13770 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13772 error_at (loc
, "vectorlength must be an integer constant");
13773 else if (wi::exact_log2 (expr
) == -1)
13774 error_at (loc
, "vectorlength must be a power of 2");
13779 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
13780 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
13781 OMP_CLAUSE_CHAIN (u
) = clauses
;
13786 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13787 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13788 OMP_CLAUSE_CHAIN (u
) = clauses
;
13793 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13799 linear ( simd-linear-variable-list )
13801 simd-linear-variable-list:
13802 simd-linear-variable
13803 simd-linear-variable-list , simd-linear-variable
13805 simd-linear-variable:
13807 id-expression : simd-linear-step
13810 conditional-expression */
13813 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13815 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13818 location_t loc
= c_parser_peek_token (parser
)->location
;
13820 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13821 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13822 c_parser_error (parser
, "expected identifier");
13824 while (c_parser_next_token_is (parser
, CPP_NAME
)
13825 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13827 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13831 undeclared_variable (c_parser_peek_token (parser
)->location
,
13832 c_parser_peek_token (parser
)->value
);
13833 c_parser_consume_token (parser
);
13835 else if (var
== error_mark_node
)
13836 c_parser_consume_token (parser
);
13839 tree step
= integer_one_node
;
13841 /* Parse the linear step if present. */
13842 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13844 c_parser_consume_token (parser
);
13845 c_parser_consume_token (parser
);
13847 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13848 expr
= c_fully_fold (expr
, false, NULL
);
13850 if (TREE_TYPE (expr
)
13851 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13852 && (TREE_CONSTANT (expr
)
13856 c_parser_error (parser
,
13857 "step size must be an integer constant "
13858 "expression or an integer variable");
13861 c_parser_consume_token (parser
);
13863 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13864 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13865 OMP_CLAUSE_DECL (u
) = var
;
13866 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13867 OMP_CLAUSE_CHAIN (u
) = clauses
;
13871 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13874 c_parser_consume_token (parser
);
13877 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13882 /* Returns the name of the next clause. If the clause is not
13883 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13884 not consumed. Otherwise, the appropriate pragma_simd_clause is
13885 returned and the token is consumed. */
13887 static pragma_omp_clause
13888 c_parser_cilk_clause_name (c_parser
*parser
)
13890 pragma_omp_clause result
;
13891 c_token
*token
= c_parser_peek_token (parser
);
13893 if (!token
->value
|| token
->type
!= CPP_NAME
)
13894 return PRAGMA_CILK_CLAUSE_NONE
;
13896 const char *p
= IDENTIFIER_POINTER (token
->value
);
13898 if (!strcmp (p
, "vectorlength"))
13899 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13900 else if (!strcmp (p
, "linear"))
13901 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13902 else if (!strcmp (p
, "private"))
13903 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13904 else if (!strcmp (p
, "firstprivate"))
13905 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13906 else if (!strcmp (p
, "lastprivate"))
13907 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13908 else if (!strcmp (p
, "reduction"))
13909 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13911 return PRAGMA_CILK_CLAUSE_NONE
;
13913 c_parser_consume_token (parser
);
13917 /* Parse all #<pragma simd> clauses. Return the list of clauses
13921 c_parser_cilk_all_clauses (c_parser
*parser
)
13923 tree clauses
= NULL
;
13925 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13927 pragma_omp_clause c_kind
;
13929 c_kind
= c_parser_cilk_clause_name (parser
);
13933 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13934 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
13936 case PRAGMA_CILK_CLAUSE_LINEAR
:
13937 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13939 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13940 /* Use the OpenMP counterpart. */
13941 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13943 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13944 /* Use the OpenMP counterpart. */
13945 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13947 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13948 /* Use the OpenMP counterpart. */
13949 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13951 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13952 /* Use the OpenMP counterpart. */
13953 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13956 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13962 c_parser_skip_to_pragma_eol (parser
);
13963 return c_finish_cilk_clauses (clauses
);
13966 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
13967 Here is the correct syntax of this pragma:
13968 #pragma cilk grainsize = <EXP>
13972 c_parser_cilk_grainsize (c_parser
*parser
)
13974 extern tree
convert_to_integer (tree
, tree
);
13976 /* consume the 'grainsize' keyword. */
13977 c_parser_consume_pragma (parser
);
13979 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
13981 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
13982 if (g_expr
.value
== error_mark_node
)
13984 c_parser_skip_to_pragma_eol (parser
);
13987 tree grain
= convert_to_integer (long_integer_type_node
,
13988 c_fully_fold (g_expr
.value
, false,
13990 c_parser_skip_to_pragma_eol (parser
);
13991 c_token
*token
= c_parser_peek_token (parser
);
13992 if (token
&& token
->type
== CPP_KEYWORD
13993 && token
->keyword
== RID_CILK_FOR
)
13995 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
13996 grain
= integer_zero_node
;
13997 c_parser_cilk_for (parser
, grain
);
14000 warning (0, "%<#pragma cilk grainsize%> is not followed by "
14004 c_parser_skip_to_pragma_eol (parser
);
14007 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
14010 c_parser_cilk_simd (c_parser
*parser
)
14012 tree clauses
= c_parser_cilk_all_clauses (parser
);
14013 tree block
= c_begin_compound_stmt (true);
14014 location_t loc
= c_parser_peek_token (parser
)->location
;
14015 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
14016 block
= c_end_compound_stmt (loc
, block
, true);
14020 /* Create an artificial decl with TYPE and emit initialization of it with
14024 c_get_temp_regvar (tree type
, tree init
)
14026 location_t loc
= EXPR_LOCATION (init
);
14027 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
14028 DECL_ARTIFICIAL (decl
) = 1;
14029 DECL_IGNORED_P (decl
) = 1;
14031 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
14036 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
14037 GRAIN is the grain value passed in through pragma or 0. */
14040 c_parser_cilk_for (c_parser
*parser
, tree grain
)
14042 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
14043 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
14044 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
14045 clauses
= c_finish_omp_clauses (clauses
);
14047 tree block
= c_begin_compound_stmt (true);
14048 tree sb
= push_stmt_list ();
14049 location_t loc
= c_parser_peek_token (parser
)->location
;
14050 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
);
14051 sb
= pop_stmt_list (sb
);
14055 tree omp_par
= make_node (OMP_PARALLEL
);
14056 TREE_TYPE (omp_par
) = void_type_node
;
14057 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
14058 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
14059 TREE_SIDE_EFFECTS (bind
) = 1;
14060 BIND_EXPR_BODY (bind
) = sb
;
14061 OMP_PARALLEL_BODY (omp_par
) = bind
;
14062 if (OMP_FOR_PRE_BODY (omp_for
))
14064 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
14065 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
14067 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
14068 tree decl
= TREE_OPERAND (init
, 0);
14069 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
14070 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
14071 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
14072 if (TREE_CODE (t
) != INTEGER_CST
)
14074 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
14075 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
14076 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
14077 OMP_CLAUSE_CHAIN (c
) = clauses
;
14080 if (TREE_CODE (incr
) == MODIFY_EXPR
)
14082 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
14083 if (TREE_CODE (t
) != INTEGER_CST
)
14085 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
14086 = c_get_temp_regvar (TREE_TYPE (t
), t
);
14087 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
14088 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
14089 OMP_CLAUSE_CHAIN (c
) = clauses
;
14093 t
= TREE_OPERAND (init
, 1);
14094 if (TREE_CODE (t
) != INTEGER_CST
)
14096 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
14097 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
14098 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
14099 OMP_CLAUSE_CHAIN (c
) = clauses
;
14102 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
14103 OMP_CLAUSE_DECL (c
) = decl
;
14104 OMP_CLAUSE_CHAIN (c
) = clauses
;
14106 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
14107 OMP_CLAUSE_OPERAND (c
, 0)
14108 = cilk_for_number_of_iterations (omp_for
);
14109 OMP_CLAUSE_CHAIN (c
) = clauses
;
14110 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
);
14111 add_stmt (omp_par
);
14114 block
= c_end_compound_stmt (loc
, block
, true);
14119 /* Parse a transaction attribute (GCC Extension).
14121 transaction-attribute:
14125 The transactional memory language description is written for C++,
14126 and uses the C++0x attribute syntax. For compatibility, allow the
14127 bracket style for transactions in C as well. */
14130 c_parser_transaction_attributes (c_parser
*parser
)
14132 tree attr_name
, attr
= NULL
;
14134 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
14135 return c_parser_attributes (parser
);
14137 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
14139 c_parser_consume_token (parser
);
14140 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
14143 attr_name
= c_parser_attribute_any_word (parser
);
14146 c_parser_consume_token (parser
);
14147 attr
= build_tree_list (attr_name
, NULL_TREE
);
14150 c_parser_error (parser
, "expected identifier");
14152 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14154 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14158 /* Parse a __transaction_atomic or __transaction_relaxed statement
14161 transaction-statement:
14162 __transaction_atomic transaction-attribute[opt] compound-statement
14163 __transaction_relaxed compound-statement
14165 Note that the only valid attribute is: "outer".
14169 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
14171 unsigned int old_in
= parser
->in_transaction
;
14172 unsigned int this_in
= 1, new_in
;
14173 location_t loc
= c_parser_peek_token (parser
)->location
;
14176 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
14177 || keyword
== RID_TRANSACTION_RELAXED
)
14178 && c_parser_next_token_is_keyword (parser
, keyword
));
14179 c_parser_consume_token (parser
);
14181 if (keyword
== RID_TRANSACTION_RELAXED
)
14182 this_in
|= TM_STMT_ATTR_RELAXED
;
14185 attrs
= c_parser_transaction_attributes (parser
);
14187 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
14190 /* Keep track if we're in the lexical scope of an outer transaction. */
14191 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
14193 parser
->in_transaction
= new_in
;
14194 stmt
= c_parser_compound_statement (parser
);
14195 parser
->in_transaction
= old_in
;
14198 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
14200 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
14201 "%<__transaction_atomic%> without transactional memory support enabled"
14202 : "%<__transaction_relaxed %> "
14203 "without transactional memory support enabled"));
14208 /* Parse a __transaction_atomic or __transaction_relaxed expression
14211 transaction-expression:
14212 __transaction_atomic ( expression )
14213 __transaction_relaxed ( expression )
14216 static struct c_expr
14217 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
14220 unsigned int old_in
= parser
->in_transaction
;
14221 unsigned int this_in
= 1;
14222 location_t loc
= c_parser_peek_token (parser
)->location
;
14225 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
14226 || keyword
== RID_TRANSACTION_RELAXED
)
14227 && c_parser_next_token_is_keyword (parser
, keyword
));
14228 c_parser_consume_token (parser
);
14230 if (keyword
== RID_TRANSACTION_RELAXED
)
14231 this_in
|= TM_STMT_ATTR_RELAXED
;
14234 attrs
= c_parser_transaction_attributes (parser
);
14236 this_in
|= parse_tm_stmt_attr (attrs
, 0);
14239 parser
->in_transaction
= this_in
;
14240 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14242 tree expr
= c_parser_expression (parser
).value
;
14243 ret
.original_type
= TREE_TYPE (expr
);
14244 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
14245 if (this_in
& TM_STMT_ATTR_RELAXED
)
14246 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
14247 SET_EXPR_LOCATION (ret
.value
, loc
);
14248 ret
.original_code
= TRANSACTION_EXPR
;
14249 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14251 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
14258 ret
.value
= error_mark_node
;
14259 ret
.original_code
= ERROR_MARK
;
14260 ret
.original_type
= NULL
;
14262 parser
->in_transaction
= old_in
;
14265 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
14266 "%<__transaction_atomic%> without transactional memory support enabled"
14267 : "%<__transaction_relaxed %> "
14268 "without transactional memory support enabled"));
14273 /* Parse a __transaction_cancel statement (GCC Extension).
14275 transaction-cancel-statement:
14276 __transaction_cancel transaction-attribute[opt] ;
14278 Note that the only valid attribute is "outer".
14282 c_parser_transaction_cancel (c_parser
*parser
)
14284 location_t loc
= c_parser_peek_token (parser
)->location
;
14286 bool is_outer
= false;
14288 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
14289 c_parser_consume_token (parser
);
14291 attrs
= c_parser_transaction_attributes (parser
);
14293 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
14297 error_at (loc
, "%<__transaction_cancel%> without "
14298 "transactional memory support enabled");
14301 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
14303 error_at (loc
, "%<__transaction_cancel%> within a "
14304 "%<__transaction_relaxed%>");
14309 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
14310 && !is_tm_may_cancel_outer (current_function_decl
))
14312 error_at (loc
, "outer %<__transaction_cancel%> not "
14313 "within outer %<__transaction_atomic%>");
14314 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
14318 else if (parser
->in_transaction
== 0)
14320 error_at (loc
, "%<__transaction_cancel%> not within "
14321 "%<__transaction_atomic%>");
14325 return add_stmt (build_tm_abort_call (loc
, is_outer
));
14328 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
14331 /* Parse a single source file. */
14334 c_parse_file (void)
14336 /* Use local storage to begin. If the first token is a pragma, parse it.
14337 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14338 which will cause garbage collection. */
14341 memset (&tparser
, 0, sizeof tparser
);
14342 tparser
.tokens
= &tparser
.tokens_buf
[0];
14343 the_parser
= &tparser
;
14345 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
14346 c_parser_pragma_pch_preprocess (&tparser
);
14348 the_parser
= ggc_alloc
<c_parser
> ();
14349 *the_parser
= tparser
;
14350 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
14351 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
14353 /* Initialize EH, if we've been told to do so. */
14354 if (flag_exceptions
)
14355 using_eh_for_cleanups ();
14357 c_parser_translation_unit (the_parser
);
14361 /* This function parses Cilk Plus array notation. The starting index is
14362 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14363 return value of this function is a tree_node called VALUE_TREE of type
14364 ARRAY_NOTATION_REF. */
14367 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
14370 c_token
*token
= NULL
;
14371 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
14372 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
14373 tree array_type_domain
= NULL_TREE
;
14375 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
14377 /* No need to continue. If either of these 2 were true, then an error
14378 must be emitted already. Thus, no need to emit them twice. */
14379 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14380 return error_mark_node
;
14383 array_type
= TREE_TYPE (array_value
);
14384 gcc_assert (array_type
);
14385 if (TREE_CODE (array_type
) != ARRAY_TYPE
14386 && TREE_CODE (array_type
) != POINTER_TYPE
)
14388 error_at (loc
, "base of array section must be pointer or array type");
14389 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14390 return error_mark_node
;
14392 type
= TREE_TYPE (array_type
);
14393 token
= c_parser_peek_token (parser
);
14395 if (token
->type
== CPP_EOF
)
14397 c_parser_error (parser
, "expected %<:%> or numeral");
14400 else if (token
->type
== CPP_COLON
)
14402 if (!initial_index
)
14404 /* If we are here, then we have a case like this A[:]. */
14405 c_parser_consume_token (parser
);
14406 if (TREE_CODE (array_type
) == POINTER_TYPE
)
14408 error_at (loc
, "start-index and length fields necessary for "
14409 "using array notations in pointers");
14410 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14411 return error_mark_node
;
14413 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14415 error_at (loc
, "array notations cannot be used with function "
14417 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14418 return error_mark_node
;
14420 array_type_domain
= TYPE_DOMAIN (array_type
);
14422 if (!array_type_domain
)
14424 error_at (loc
, "start-index and length fields necessary for "
14425 "using array notations in dimensionless arrays");
14426 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14427 return error_mark_node
;
14430 start_index
= TYPE_MINVAL (array_type_domain
);
14431 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
14433 if (!TYPE_MAXVAL (array_type_domain
)
14434 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
14436 error_at (loc
, "start-index and length fields necessary for "
14437 "using array notations in variable-length arrays");
14438 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14439 return error_mark_node
;
14441 end_index
= TYPE_MAXVAL (array_type_domain
);
14442 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
14443 end_index
, integer_one_node
);
14444 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
14445 stride
= build_int_cst (integer_type_node
, 1);
14446 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
14448 else if (initial_index
!= error_mark_node
)
14450 /* If we are here, then there should be 2 possibilities:
14451 1. Array [EXPR : EXPR]
14452 2. Array [EXPR : EXPR : EXPR]
14454 start_index
= initial_index
;
14456 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14458 error_at (loc
, "array notations cannot be used with function "
14460 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14461 return error_mark_node
;
14463 c_parser_consume_token (parser
); /* consume the ':' */
14464 struct c_expr ce
= c_parser_expression (parser
);
14465 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14466 end_index
= ce
.value
;
14467 if (!end_index
|| end_index
== error_mark_node
)
14469 c_parser_skip_to_end_of_block_or_statement (parser
);
14470 return error_mark_node
;
14472 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
14474 c_parser_consume_token (parser
);
14475 ce
= c_parser_expression (parser
);
14476 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14478 if (!stride
|| stride
== error_mark_node
)
14480 c_parser_skip_to_end_of_block_or_statement (parser
);
14481 return error_mark_node
;
14486 c_parser_error (parser
, "expected array notation expression");
14489 c_parser_error (parser
, "expected array notation expression");
14491 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14493 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
14494 end_index
, stride
, type
);
14495 if (value_tree
!= error_mark_node
)
14496 SET_EXPR_LOCATION (value_tree
, loc
);
14500 #include "gt-c-c-parser.h"