1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2013 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 "langhooks.h"
47 #include "c-family/c-pragma.h"
52 #include "c-family/c-common.h"
53 #include "c-family/c-objc.h"
54 #include "c-family/c-upc.h"
61 #include "upc/upc-tree.h"
64 /* Initialization routine for this file. */
69 /* The only initialization required is of the reserved word
75 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
76 the c_token structure. */
77 gcc_assert (RID_MAX
<= 255);
84 mask
|= D_ASM
| D_EXT
;
88 if (!c_dialect_objc ())
89 mask
|= D_OBJC
| D_CXX_OBJC
;
91 if (!c_dialect_upc ())
94 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
95 for (i
= 0; i
< num_c_common_reswords
; i
++)
97 /* If a keyword is disabled, do not enter it into the table
98 and so create a canonical spelling that isn't a keyword. */
99 if (c_common_reswords
[i
].disable
& mask
)
102 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
104 id
= get_identifier (c_common_reswords
[i
].word
);
105 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
106 C_IS_RESERVED_WORD (id
) = 1;
111 id
= get_identifier (c_common_reswords
[i
].word
);
112 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
113 C_IS_RESERVED_WORD (id
) = 1;
114 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
118 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
119 and the C parser. Unlike the C++ lexer, the parser structure
120 stores the lexer information instead of using a separate structure.
121 Identifiers are separated into ordinary identifiers, type names,
122 keywords and some other Objective-C types of identifiers, and some
123 look-ahead is maintained.
125 ??? It might be a good idea to lex the whole file up front (as for
126 C++). It would then be possible to share more of the C and C++
127 lexer code, if desired. */
129 /* The following local token type is used. */
132 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
134 /* More information about the type of a CPP_NAME token. */
135 typedef enum c_id_kind
{
136 /* An ordinary identifier. */
138 /* An identifier declared as a typedef name. */
140 /* An identifier declared as an Objective-C class name. */
142 /* An address space identifier. */
144 /* Not an identifier. */
148 /* A single C token after string literal concatenation and conversion
149 of preprocessing tokens to tokens. */
150 typedef struct GTY (()) c_token
{
151 /* The kind of token. */
152 ENUM_BITFIELD (cpp_ttype
) type
: 8;
153 /* If this token is a CPP_NAME, this value indicates whether also
154 declared as some kind of type. Otherwise, it is C_ID_NONE. */
155 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
156 /* If this token is a keyword, this value indicates which keyword.
157 Otherwise, this value is RID_MAX. */
158 ENUM_BITFIELD (rid
) keyword
: 8;
159 /* If this token is a CPP_PRAGMA, this indicates the pragma that
160 was seen. Otherwise it is PRAGMA_NONE. */
161 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
162 /* The location at which this token was found. */
164 /* The value associated with this token, if any. */
168 /* A parser structure recording information about the state and
169 context of parsing. Includes lexer information with up to two
170 tokens of look-ahead; more are not needed for C. */
171 typedef struct GTY(()) c_parser
{
172 /* The look-ahead tokens. */
173 c_token
* GTY((skip
)) tokens
;
174 /* Buffer for look-ahead tokens. */
175 c_token tokens_buf
[2];
176 /* How many look-ahead tokens are available (0, 1 or 2, or
177 more if parsing from pre-lexed tokens). */
178 unsigned int tokens_avail
;
179 /* True if a syntax error is being recovered from; false otherwise.
180 c_parser_error sets this flag. It should clear this flag when
181 enough tokens have been consumed to recover from the error. */
182 BOOL_BITFIELD error
: 1;
183 /* True if we're processing a pragma, and shouldn't automatically
184 consume CPP_PRAGMA_EOL. */
185 BOOL_BITFIELD in_pragma
: 1;
186 /* True if we're parsing the outermost block of an if statement. */
187 BOOL_BITFIELD in_if_block
: 1;
188 /* True if we want to lex an untranslated string. */
189 BOOL_BITFIELD lex_untranslated_string
: 1;
191 /* Objective-C specific parser/lexer information. */
193 /* True if we are in a context where the Objective-C "PQ" keywords
194 are considered keywords. */
195 BOOL_BITFIELD objc_pq_context
: 1;
196 /* True if we are parsing a (potential) Objective-C foreach
197 statement. This is set to true after we parsed 'for (' and while
198 we wait for 'in' or ';' to decide if it's a standard C for loop or an
199 Objective-C foreach loop. */
200 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
201 /* The following flag is needed to contextualize Objective-C lexical
202 analysis. In some cases (e.g., 'int NSObject;'), it is
203 undesirable to bind an identifier to an Objective-C class, even
204 if a class with that name exists. */
205 BOOL_BITFIELD objc_need_raw_identifier
: 1;
206 /* Nonzero if we're processing a __transaction statement. The value
207 is 1 | TM_STMT_ATTR_*. */
208 unsigned int in_transaction
: 4;
209 /* True if we are in a context where the Objective-C "Property attribute"
210 keywords are valid. */
211 BOOL_BITFIELD objc_property_attr_context
: 1;
215 /* The actual parser and external interface. ??? Does this need to be
216 garbage-collected? */
218 static GTY (()) c_parser
*the_parser
;
220 /* Read in and lex a single token, storing it in *TOKEN. */
223 c_lex_one_token (c_parser
*parser
, c_token
*token
)
225 timevar_push (TV_LEX
);
227 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
228 (parser
->lex_untranslated_string
229 ? C_LEX_STRING_NO_TRANSLATE
: 0));
230 token
->id_kind
= C_ID_NONE
;
231 token
->keyword
= RID_MAX
;
232 token
->pragma_kind
= PRAGMA_NONE
;
240 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
241 if (c_dialect_objc ())
242 parser
->objc_need_raw_identifier
= false;
244 if (C_IS_RESERVED_WORD (token
->value
))
246 enum rid rid_code
= C_RID_CODE (token
->value
);
248 if (rid_code
== RID_CXX_COMPAT_WARN
)
250 warning_at (token
->location
,
252 "identifier %qE conflicts with C++ keyword",
255 else if (rid_code
>= RID_FIRST_ADDR_SPACE
256 && rid_code
<= RID_LAST_ADDR_SPACE
)
258 token
->id_kind
= C_ID_ADDRSPACE
;
259 token
->keyword
= rid_code
;
262 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
264 /* We found an Objective-C "pq" keyword (in, out,
265 inout, bycopy, byref, oneway). They need special
266 care because the interpretation depends on the
268 if (parser
->objc_pq_context
)
270 token
->type
= CPP_KEYWORD
;
271 token
->keyword
= rid_code
;
274 else if (parser
->objc_could_be_foreach_context
275 && rid_code
== RID_IN
)
277 /* We are in Objective-C, inside a (potential)
278 foreach context (which means after having
279 parsed 'for (', but before having parsed ';'),
280 and we found 'in'. We consider it the keyword
281 which terminates the declaration at the
282 beginning of a foreach-statement. Note that
283 this means you can't use 'in' for anything else
284 in that context; in particular, in Objective-C
285 you can't use 'in' as the name of the running
286 variable in a C for loop. We could potentially
287 try to add code here to disambiguate, but it
288 seems a reasonable limitation. */
289 token
->type
= CPP_KEYWORD
;
290 token
->keyword
= rid_code
;
293 /* Else, "pq" keywords outside of the "pq" context are
294 not keywords, and we fall through to the code for
297 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
299 /* We found an Objective-C "property attribute"
300 keyword (getter, setter, readonly, etc). These are
301 only valid in the property context. */
302 if (parser
->objc_property_attr_context
)
304 token
->type
= CPP_KEYWORD
;
305 token
->keyword
= rid_code
;
308 /* Else they are not special keywords.
311 else if (c_dialect_objc ()
312 && (OBJC_IS_AT_KEYWORD (rid_code
)
313 || OBJC_IS_CXX_KEYWORD (rid_code
)))
315 /* We found one of the Objective-C "@" keywords (defs,
316 selector, synchronized, etc) or one of the
317 Objective-C "cxx" keywords (class, private,
318 protected, public, try, catch, throw) without a
319 preceding '@' sign. Do nothing and fall through to
320 the code for normal tokens (in C++ we would still
321 consider the CXX ones keywords, but not in C). */
326 token
->type
= CPP_KEYWORD
;
327 token
->keyword
= rid_code
;
332 decl
= lookup_name (token
->value
);
335 if (TREE_CODE (decl
) == TYPE_DECL
)
337 token
->id_kind
= C_ID_TYPENAME
;
341 else if (c_dialect_objc ())
343 tree objc_interface_decl
= objc_is_class_name (token
->value
);
344 /* Objective-C class names are in the same namespace as
345 variables and typedefs, and hence are shadowed by local
347 if (objc_interface_decl
348 && (!objc_force_identifier
|| global_bindings_p ()))
350 token
->value
= objc_interface_decl
;
351 token
->id_kind
= C_ID_CLASSNAME
;
355 token
->id_kind
= C_ID_ID
;
359 /* This only happens in Objective-C; it must be a keyword. */
360 token
->type
= CPP_KEYWORD
;
361 switch (C_RID_CODE (token
->value
))
363 /* Replace 'class' with '@class', 'private' with '@private',
364 etc. This prevents confusion with the C++ keyword
365 'class', and makes the tokens consistent with other
366 Objective-C 'AT' keywords. For example '@class' is
367 reported as RID_AT_CLASS which is consistent with
368 '@synchronized', which is reported as
371 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
372 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
373 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
374 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
375 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
376 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
377 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
378 default: token
->keyword
= C_RID_CODE (token
->value
);
383 case CPP_CLOSE_PAREN
:
385 /* These tokens may affect the interpretation of any identifiers
386 following, if doing Objective-C. */
387 if (c_dialect_objc ())
388 parser
->objc_need_raw_identifier
= false;
391 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
392 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
398 timevar_pop (TV_LEX
);
401 /* Return a pointer to the next token from PARSER, reading it in if
404 static inline c_token
*
405 c_parser_peek_token (c_parser
*parser
)
407 if (parser
->tokens_avail
== 0)
409 c_lex_one_token (parser
, &parser
->tokens
[0]);
410 parser
->tokens_avail
= 1;
412 return &parser
->tokens
[0];
415 /* Return true if the next token from PARSER has the indicated
419 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
421 return c_parser_peek_token (parser
)->type
== type
;
424 /* Return true if the next token from PARSER does not have the
428 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
430 return !c_parser_next_token_is (parser
, type
);
433 /* Return true if the next token from PARSER is the indicated
437 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
439 return c_parser_peek_token (parser
)->keyword
== keyword
;
442 /* Return a pointer to the next-but-one token from PARSER, reading it
443 in if necessary. The next token is already read in. */
446 c_parser_peek_2nd_token (c_parser
*parser
)
448 if (parser
->tokens_avail
>= 2)
449 return &parser
->tokens
[1];
450 gcc_assert (parser
->tokens_avail
== 1);
451 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
452 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
453 c_lex_one_token (parser
, &parser
->tokens
[1]);
454 parser
->tokens_avail
= 2;
455 return &parser
->tokens
[1];
458 /* Return true if TOKEN can start a type name,
461 c_token_starts_typename (c_token
*token
)
466 switch (token
->id_kind
)
475 gcc_assert (c_dialect_objc ());
481 switch (token
->keyword
)
519 if (c_dialect_objc ())
527 enum c_lookahead_kind
{
528 /* Always treat unknown identifiers as typenames. */
531 /* Could be parsing a nonabstract declarator. Only treat an identifier
532 as a typename if followed by another identifier or a star. */
533 cla_nonabstract_decl
,
535 /* Never treat identifiers as typenames. */
539 /* Return true if the next token from PARSER can start a type name,
540 false otherwise. LA specifies how to do lookahead in order to
541 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
544 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
546 c_token
*token
= c_parser_peek_token (parser
);
547 if (c_token_starts_typename (token
))
550 /* Try a bit harder to detect an unknown typename. */
551 if (la
!= cla_prefer_id
552 && token
->type
== CPP_NAME
553 && token
->id_kind
== C_ID_ID
555 /* Do not try too hard when we could have "object in array". */
556 && !parser
->objc_could_be_foreach_context
558 && (la
== cla_prefer_type
559 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
560 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
562 /* Only unknown identifiers. */
563 && !lookup_name (token
->value
))
569 /* Return true if TOKEN is a type qualifier, false otherwise. */
571 c_token_is_qualifier (c_token
*token
)
576 switch (token
->id_kind
)
584 switch (token
->keyword
)
606 /* Return true if the next token from PARSER is a type qualifier,
609 c_parser_next_token_is_qualifier (c_parser
*parser
)
611 c_token
*token
= c_parser_peek_token (parser
);
612 return c_token_is_qualifier (token
);
615 /* Return true if TOKEN can start declaration specifiers, false
618 c_token_starts_declspecs (c_token
*token
)
623 switch (token
->id_kind
)
632 gcc_assert (c_dialect_objc ());
638 switch (token
->keyword
)
685 if (c_dialect_objc ())
694 /* Return true if TOKEN can start declaration specifiers or a static
695 assertion, false otherwise. */
697 c_token_starts_declaration (c_token
*token
)
699 if (c_token_starts_declspecs (token
)
700 || token
->keyword
== RID_STATIC_ASSERT
)
706 /* Return true if the next token from PARSER can start declaration
707 specifiers, false otherwise. */
709 c_parser_next_token_starts_declspecs (c_parser
*parser
)
711 c_token
*token
= c_parser_peek_token (parser
);
713 /* In Objective-C, a classname normally starts a declspecs unless it
714 is immediately followed by a dot. In that case, it is the
715 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
716 setter/getter on the class. c_token_starts_declspecs() can't
717 differentiate between the two cases because it only checks the
718 current token, so we have a special check here. */
719 if (c_dialect_objc ()
720 && token
->type
== CPP_NAME
721 && token
->id_kind
== C_ID_CLASSNAME
722 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
725 return c_token_starts_declspecs (token
);
728 /* Return true if the next tokens from PARSER can start declaration
729 specifiers or a static assertion, false otherwise. */
731 c_parser_next_tokens_start_declaration (c_parser
*parser
)
733 c_token
*token
= c_parser_peek_token (parser
);
736 if (c_dialect_objc ()
737 && token
->type
== CPP_NAME
738 && token
->id_kind
== C_ID_CLASSNAME
739 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
742 /* Labels do not start declarations. */
743 if (token
->type
== CPP_NAME
744 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
747 if (c_token_starts_declaration (token
))
750 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
756 /* Consume the next token from PARSER. */
759 c_parser_consume_token (c_parser
*parser
)
761 gcc_assert (parser
->tokens_avail
>= 1);
762 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
763 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
764 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
765 if (parser
->tokens
!= &parser
->tokens_buf
[0])
767 else if (parser
->tokens_avail
== 2)
768 parser
->tokens
[0] = parser
->tokens
[1];
769 parser
->tokens_avail
--;
772 /* Expect the current token to be a #pragma. Consume it and remember
773 that we've begun parsing a pragma. */
776 c_parser_consume_pragma (c_parser
*parser
)
778 gcc_assert (!parser
->in_pragma
);
779 gcc_assert (parser
->tokens_avail
>= 1);
780 gcc_assert (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
--;
786 parser
->in_pragma
= true;
789 /* Update the globals input_location and in_system_header from
792 c_parser_set_source_position_from_token (c_token
*token
)
794 if (token
->type
!= CPP_EOF
)
796 input_location
= token
->location
;
800 /* Issue a diagnostic of the form
801 FILE:LINE: MESSAGE before TOKEN
802 where TOKEN is the next token in the input stream of PARSER.
803 MESSAGE (specified by the caller) is usually of the form "expected
806 Do not issue a diagnostic if still recovering from an error.
808 ??? This is taken from the C++ parser, but building up messages in
809 this way is not i18n-friendly and some other approach should be
813 c_parser_error (c_parser
*parser
, const char *gmsgid
)
815 c_token
*token
= c_parser_peek_token (parser
);
818 parser
->error
= true;
821 /* This diagnostic makes more sense if it is tagged to the line of
822 the token we just peeked at. */
823 c_parser_set_source_position_from_token (token
);
824 c_parse_error (gmsgid
,
825 /* Because c_parse_error does not understand
826 CPP_KEYWORD, keywords are treated like
828 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
829 /* ??? The C parser does not save the cpp flags of a
830 token, we need to pass 0 here and we will not get
831 the source spelling of some tokens but rather the
832 canonical spelling. */
833 token
->value
, /*flags=*/0);
836 /* If the next token is of the indicated TYPE, consume it. Otherwise,
837 issue the error MSGID. If MSGID is NULL then a message has already
838 been produced and no message will be produced this time. Returns
839 true if found, false otherwise. */
842 c_parser_require (c_parser
*parser
,
846 if (c_parser_next_token_is (parser
, type
))
848 c_parser_consume_token (parser
);
853 c_parser_error (parser
, msgid
);
858 /* If the next token is the indicated keyword, consume it. Otherwise,
859 issue the error MSGID. Returns true if found, false otherwise. */
862 c_parser_require_keyword (c_parser
*parser
,
866 if (c_parser_next_token_is_keyword (parser
, keyword
))
868 c_parser_consume_token (parser
);
873 c_parser_error (parser
, msgid
);
878 /* Like c_parser_require, except that tokens will be skipped until the
879 desired token is found. An error message is still produced if the
880 next token is not as expected. If MSGID is NULL then a message has
881 already been produced and no message will be produced this
885 c_parser_skip_until_found (c_parser
*parser
,
889 unsigned nesting_depth
= 0;
891 if (c_parser_require (parser
, type
, msgid
))
894 /* Skip tokens until the desired token is found. */
897 /* Peek at the next token. */
898 c_token
*token
= c_parser_peek_token (parser
);
899 /* If we've reached the token we want, consume it and stop. */
900 if (token
->type
== type
&& !nesting_depth
)
902 c_parser_consume_token (parser
);
906 /* If we've run out of tokens, stop. */
907 if (token
->type
== CPP_EOF
)
909 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
911 if (token
->type
== CPP_OPEN_BRACE
912 || token
->type
== CPP_OPEN_PAREN
913 || token
->type
== CPP_OPEN_SQUARE
)
915 else if (token
->type
== CPP_CLOSE_BRACE
916 || token
->type
== CPP_CLOSE_PAREN
917 || token
->type
== CPP_CLOSE_SQUARE
)
919 if (nesting_depth
-- == 0)
922 /* Consume this token. */
923 c_parser_consume_token (parser
);
925 parser
->error
= false;
928 /* Skip tokens until the end of a parameter is found, but do not
929 consume the comma, semicolon or closing delimiter. */
932 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
934 unsigned nesting_depth
= 0;
938 c_token
*token
= c_parser_peek_token (parser
);
939 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
942 /* If we've run out of tokens, stop. */
943 if (token
->type
== CPP_EOF
)
945 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
947 if (token
->type
== CPP_OPEN_BRACE
948 || token
->type
== CPP_OPEN_PAREN
949 || token
->type
== CPP_OPEN_SQUARE
)
951 else if (token
->type
== CPP_CLOSE_BRACE
952 || token
->type
== CPP_CLOSE_PAREN
953 || token
->type
== CPP_CLOSE_SQUARE
)
955 if (nesting_depth
-- == 0)
958 /* Consume this token. */
959 c_parser_consume_token (parser
);
961 parser
->error
= false;
964 /* Expect to be at the end of the pragma directive and consume an
965 end of line marker. */
968 c_parser_skip_to_pragma_eol (c_parser
*parser
)
970 gcc_assert (parser
->in_pragma
);
971 parser
->in_pragma
= false;
973 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
976 c_token
*token
= c_parser_peek_token (parser
);
977 if (token
->type
== CPP_EOF
)
979 if (token
->type
== CPP_PRAGMA_EOL
)
981 c_parser_consume_token (parser
);
984 c_parser_consume_token (parser
);
987 parser
->error
= false;
990 /* Skip tokens until we have consumed an entire block, or until we
991 have consumed a non-nested ';'. */
994 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
996 unsigned nesting_depth
= 0;
997 bool save_error
= parser
->error
;
1003 /* Peek at the next token. */
1004 token
= c_parser_peek_token (parser
);
1006 switch (token
->type
)
1011 case CPP_PRAGMA_EOL
:
1012 if (parser
->in_pragma
)
1017 /* If the next token is a ';', we have reached the
1018 end of the statement. */
1021 /* Consume the ';'. */
1022 c_parser_consume_token (parser
);
1027 case CPP_CLOSE_BRACE
:
1028 /* If the next token is a non-nested '}', then we have
1029 reached the end of the current block. */
1030 if (nesting_depth
== 0 || --nesting_depth
== 0)
1032 c_parser_consume_token (parser
);
1037 case CPP_OPEN_BRACE
:
1038 /* If it the next token is a '{', then we are entering a new
1039 block. Consume the entire block. */
1044 /* If we see a pragma, consume the whole thing at once. We
1045 have some safeguards against consuming pragmas willy-nilly.
1046 Normally, we'd expect to be here with parser->error set,
1047 which disables these safeguards. But it's possible to get
1048 here for secondary error recovery, after parser->error has
1050 c_parser_consume_pragma (parser
);
1051 c_parser_skip_to_pragma_eol (parser
);
1052 parser
->error
= save_error
;
1059 c_parser_consume_token (parser
);
1063 parser
->error
= false;
1066 /* CPP's options (initialized by c-opts.c). */
1067 extern cpp_options
*cpp_opts
;
1069 /* Save the warning flags which are controlled by __extension__. */
1072 disable_extension_diagnostics (void)
1075 | (warn_pointer_arith
<< 1)
1076 | (warn_traditional
<< 2)
1078 | (warn_long_long
<< 4)
1079 | (warn_cxx_compat
<< 5)
1080 | (warn_overlength_strings
<< 6));
1081 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1082 warn_pointer_arith
= 0;
1083 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1085 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1086 warn_cxx_compat
= 0;
1087 warn_overlength_strings
= 0;
1091 /* Restore the warning flags which are controlled by __extension__.
1092 FLAGS is the return value from disable_extension_diagnostics. */
1095 restore_extension_diagnostics (int flags
)
1097 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1098 warn_pointer_arith
= (flags
>> 1) & 1;
1099 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1100 flag_iso
= (flags
>> 3) & 1;
1101 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1102 warn_cxx_compat
= (flags
>> 5) & 1;
1103 warn_overlength_strings
= (flags
>> 6) & 1;
1106 /* Possibly kinds of declarator to parse. */
1107 typedef enum c_dtr_syn
{
1108 /* A normal declarator with an identifier. */
1110 /* An abstract declarator (maybe empty). */
1112 /* A parameter declarator: may be either, but after a type name does
1113 not redeclare a typedef name as an identifier if it can
1114 alternatively be interpreted as a typedef name; see DR#009,
1115 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1116 following DR#249. For example, given a typedef T, "int T" and
1117 "int *T" are valid parameter declarations redeclaring T, while
1118 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1119 abstract declarators rather than involving redundant parentheses;
1120 the same applies with attributes inside the parentheses before
1125 /* The binary operation precedence levels, where 0 is a dummy lowest level
1126 used for the bottom of the stack. */
1127 enum c_parser_prec
{
1142 static void c_parser_external_declaration (c_parser
*);
1143 static void c_parser_asm_definition (c_parser
*);
1144 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1145 bool, bool, tree
*, vec
<c_token
>);
1146 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1147 static void c_parser_static_assert_declaration (c_parser
*);
1148 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1149 bool, bool, enum c_lookahead_kind
);
1150 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1151 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1152 static tree
c_parser_struct_declaration (c_parser
*);
1153 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1154 static tree
c_parser_alignas_specifier (c_parser
*);
1155 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1157 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1159 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1161 struct c_declarator
*);
1162 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1163 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1165 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1166 static tree
c_parser_simple_asm_expr (c_parser
*);
1167 static tree
c_parser_attributes (c_parser
*);
1168 static struct c_type_name
*c_parser_type_name (c_parser
*);
1169 static struct c_expr
c_parser_initializer (c_parser
*);
1170 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1171 static void c_parser_initelt (c_parser
*, struct obstack
*);
1172 static void c_parser_initval (c_parser
*, struct c_expr
*,
1174 static tree
c_parser_compound_statement (c_parser
*);
1175 static void c_parser_compound_statement_nostart (c_parser
*);
1176 static void c_parser_label (c_parser
*);
1177 static void c_parser_statement (c_parser
*);
1178 static void c_parser_statement_after_labels (c_parser
*);
1179 static void c_parser_if_statement (c_parser
*);
1180 static void c_parser_switch_statement (c_parser
*);
1181 static void c_parser_while_statement (c_parser
*, bool);
1182 static void c_parser_do_statement (c_parser
*, bool);
1183 static void c_parser_for_statement (c_parser
*, bool);
1184 static tree
c_parser_asm_statement (c_parser
*);
1185 static tree
c_parser_asm_operands (c_parser
*);
1186 static tree
c_parser_asm_goto_operands (c_parser
*);
1187 static tree
c_parser_asm_clobbers (c_parser
*);
1188 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1190 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1191 struct c_expr
*, tree
);
1192 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1194 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1195 static struct c_expr
c_parser_unary_expression (c_parser
*);
1196 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1197 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1198 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1199 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1200 struct c_type_name
*,
1202 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1205 static tree
c_parser_transaction (c_parser
*, enum rid
);
1206 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1207 static tree
c_parser_transaction_cancel (c_parser
*);
1208 static struct c_expr
c_parser_expression (c_parser
*);
1209 static struct c_expr
c_parser_expression_conv (c_parser
*);
1210 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1211 vec
<tree
, va_gc
> **, location_t
*,
1213 static void c_parser_omp_construct (c_parser
*);
1214 static void c_parser_omp_threadprivate (c_parser
*);
1215 static void c_parser_omp_barrier (c_parser
*);
1216 static void c_parser_omp_flush (c_parser
*);
1217 static void c_parser_omp_taskwait (c_parser
*);
1218 static void c_parser_omp_taskyield (c_parser
*);
1219 static void c_parser_omp_cancel (c_parser
*);
1220 static void c_parser_omp_cancellation_point (c_parser
*);
1222 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1223 pragma_stmt
, pragma_compound
};
1224 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1225 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1226 static void c_parser_omp_end_declare_target (c_parser
*);
1227 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1229 /* These Objective-C parser functions are only ever called when
1230 compiling Objective-C. */
1231 static void c_parser_objc_class_definition (c_parser
*, tree
);
1232 static void c_parser_objc_class_instance_variables (c_parser
*);
1233 static void c_parser_objc_class_declaration (c_parser
*);
1234 static void c_parser_objc_alias_declaration (c_parser
*);
1235 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1236 static bool c_parser_objc_method_type (c_parser
*);
1237 static void c_parser_objc_method_definition (c_parser
*);
1238 static void c_parser_objc_methodprotolist (c_parser
*);
1239 static void c_parser_objc_methodproto (c_parser
*);
1240 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1241 static tree
c_parser_objc_type_name (c_parser
*);
1242 static tree
c_parser_objc_protocol_refs (c_parser
*);
1243 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1244 static void c_parser_objc_synchronized_statement (c_parser
*);
1245 static tree
c_parser_objc_selector (c_parser
*);
1246 static tree
c_parser_objc_selector_arg (c_parser
*);
1247 static tree
c_parser_objc_receiver (c_parser
*);
1248 static tree
c_parser_objc_message_args (c_parser
*);
1249 static tree
c_parser_objc_keywordexpr (c_parser
*);
1250 static void c_parser_objc_at_property_declaration (c_parser
*);
1251 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1252 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1253 static bool c_parser_objc_diagnose_bad_element_prefix
1254 (c_parser
*, struct c_declspecs
*);
1256 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1258 /* These UPC parser functions are only ever called when
1260 static void c_parser_upc_forall_statement (c_parser
*);
1261 static void c_parser_upc_sync_statement (c_parser
*, int);
1262 static void c_parser_upc_shared_qual (source_location
,
1264 struct c_declspecs
*);
1266 /* Parse a translation unit (C90 6.7, C99 6.9).
1269 external-declarations
1271 external-declarations:
1272 external-declaration
1273 external-declarations external-declaration
1282 c_parser_translation_unit (c_parser
*parser
)
1284 if (c_parser_next_token_is (parser
, CPP_EOF
))
1286 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1287 "ISO C forbids an empty translation unit");
1291 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1292 mark_valid_location_for_stdc_pragma (false);
1296 c_parser_external_declaration (parser
);
1297 obstack_free (&parser_obstack
, obstack_position
);
1299 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1303 /* Parse an external declaration (C90 6.7, C99 6.9).
1305 external-declaration:
1311 external-declaration:
1314 __extension__ external-declaration
1318 external-declaration:
1319 objc-class-definition
1320 objc-class-declaration
1321 objc-alias-declaration
1322 objc-protocol-definition
1323 objc-method-definition
1328 c_parser_external_declaration (c_parser
*parser
)
1331 switch (c_parser_peek_token (parser
)->type
)
1334 switch (c_parser_peek_token (parser
)->keyword
)
1337 ext
= disable_extension_diagnostics ();
1338 c_parser_consume_token (parser
);
1339 c_parser_external_declaration (parser
);
1340 restore_extension_diagnostics (ext
);
1343 c_parser_asm_definition (parser
);
1345 case RID_AT_INTERFACE
:
1346 case RID_AT_IMPLEMENTATION
:
1347 gcc_assert (c_dialect_objc ());
1348 c_parser_objc_class_definition (parser
, NULL_TREE
);
1351 gcc_assert (c_dialect_objc ());
1352 c_parser_objc_class_declaration (parser
);
1355 gcc_assert (c_dialect_objc ());
1356 c_parser_objc_alias_declaration (parser
);
1358 case RID_AT_PROTOCOL
:
1359 gcc_assert (c_dialect_objc ());
1360 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1362 case RID_AT_PROPERTY
:
1363 gcc_assert (c_dialect_objc ());
1364 c_parser_objc_at_property_declaration (parser
);
1366 case RID_AT_SYNTHESIZE
:
1367 gcc_assert (c_dialect_objc ());
1368 c_parser_objc_at_synthesize_declaration (parser
);
1370 case RID_AT_DYNAMIC
:
1371 gcc_assert (c_dialect_objc ());
1372 c_parser_objc_at_dynamic_declaration (parser
);
1375 gcc_assert (c_dialect_objc ());
1376 c_parser_consume_token (parser
);
1377 objc_finish_implementation ();
1384 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1385 "ISO C does not allow extra %<;%> outside of a function");
1386 c_parser_consume_token (parser
);
1389 mark_valid_location_for_stdc_pragma (true);
1390 c_parser_pragma (parser
, pragma_external
);
1391 mark_valid_location_for_stdc_pragma (false);
1395 if (c_dialect_objc ())
1397 c_parser_objc_method_definition (parser
);
1400 /* Else fall through, and yield a syntax error trying to parse
1401 as a declaration or function definition. */
1404 /* A declaration or a function definition (or, in Objective-C,
1405 an @interface or @protocol with prefix attributes). We can
1406 only tell which after parsing the declaration specifiers, if
1407 any, and the first declarator. */
1408 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1414 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1416 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1417 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1418 accepted; otherwise (old-style parameter declarations) only other
1419 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1420 assertion is accepted; otherwise (old-style parameter declarations)
1421 it is not. If NESTED is true, we are inside a function or parsing
1422 old-style parameter declarations; any functions encountered are
1423 nested functions and declaration specifiers are required; otherwise
1424 we are at top level and functions are normal functions and
1425 declaration specifiers may be optional. If EMPTY_OK is true, empty
1426 declarations are OK (subject to all other constraints); otherwise
1427 (old-style parameter declarations) they are diagnosed. If
1428 START_ATTR_OK is true, the declaration specifiers may start with
1429 attributes; otherwise they may not.
1430 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1431 declaration when parsing an Objective-C foreach statement.
1434 declaration-specifiers init-declarator-list[opt] ;
1435 static_assert-declaration
1437 function-definition:
1438 declaration-specifiers[opt] declarator declaration-list[opt]
1443 declaration-list declaration
1445 init-declarator-list:
1447 init-declarator-list , init-declarator
1450 declarator simple-asm-expr[opt] attributes[opt]
1451 declarator simple-asm-expr[opt] attributes[opt] = initializer
1455 nested-function-definition:
1456 declaration-specifiers declarator declaration-list[opt]
1460 attributes objc-class-definition
1461 attributes objc-category-definition
1462 attributes objc-protocol-definition
1464 The simple-asm-expr and attributes are GNU extensions.
1466 This function does not handle __extension__; that is handled in its
1467 callers. ??? Following the old parser, __extension__ may start
1468 external declarations, declarations in functions and declarations
1469 at the start of "for" loops, but not old-style parameter
1472 C99 requires declaration specifiers in a function definition; the
1473 absence is diagnosed through the diagnosis of implicit int. In GNU
1474 C we also allow but diagnose declarations without declaration
1475 specifiers, but only at top level (elsewhere they conflict with
1478 In Objective-C, declarations of the looping variable in a foreach
1479 statement are exceptionally terminated by 'in' (for example, 'for
1480 (NSObject *object in array) { ... }').
1485 threadprivate-directive */
1488 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1489 bool static_assert_ok
, bool empty_ok
,
1490 bool nested
, bool start_attr_ok
,
1491 tree
*objc_foreach_object_declaration
,
1492 vec
<c_token
> omp_declare_simd_clauses
)
1494 struct c_declspecs
*specs
;
1496 tree all_prefix_attrs
;
1497 bool diagnosed_no_specs
= false;
1498 location_t here
= c_parser_peek_token (parser
)->location
;
1500 if (static_assert_ok
1501 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1503 c_parser_static_assert_declaration (parser
);
1506 specs
= build_null_declspecs ();
1508 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1509 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1510 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1511 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1512 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1513 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1515 error_at (here
, "unknown type name %qE",
1516 c_parser_peek_token (parser
)->value
);
1518 /* Parse declspecs normally to get a correct pointer type, but avoid
1519 a further "fails to be a type name" error. Refuse nested functions
1520 since it is not how the user likely wants us to recover. */
1521 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1522 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1523 c_parser_peek_token (parser
)->value
= error_mark_node
;
1527 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1528 true, cla_nonabstract_decl
);
1531 c_parser_skip_to_end_of_block_or_statement (parser
);
1534 if (nested
&& !specs
->declspecs_seen_p
)
1536 c_parser_error (parser
, "expected declaration specifiers");
1537 c_parser_skip_to_end_of_block_or_statement (parser
);
1540 finish_declspecs (specs
);
1541 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1547 shadow_tag_warned (specs
, 1);
1548 pedwarn (here
, 0, "empty declaration");
1550 c_parser_consume_token (parser
);
1554 /* Provide better error recovery. Note that a type name here is usually
1555 better diagnosed as a redeclaration. */
1557 && specs
->typespec_kind
== ctsk_tagdef
1558 && c_parser_next_token_starts_declspecs (parser
)
1559 && !c_parser_next_token_is (parser
, CPP_NAME
))
1561 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1562 parser
->error
= false;
1563 shadow_tag_warned (specs
, 1);
1566 else if (c_dialect_objc ())
1568 /* Prefix attributes are an error on method decls. */
1569 switch (c_parser_peek_token (parser
)->type
)
1573 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1577 warning_at (c_parser_peek_token (parser
)->location
,
1579 "prefix attributes are ignored for methods");
1580 specs
->attrs
= NULL_TREE
;
1583 c_parser_objc_method_definition (parser
);
1585 c_parser_objc_methodproto (parser
);
1591 /* This is where we parse 'attributes @interface ...',
1592 'attributes @implementation ...', 'attributes @protocol ...'
1593 (where attributes could be, for example, __attribute__
1596 switch (c_parser_peek_token (parser
)->keyword
)
1598 case RID_AT_INTERFACE
:
1600 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1602 c_parser_objc_class_definition (parser
, specs
->attrs
);
1606 case RID_AT_IMPLEMENTATION
:
1608 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1612 warning_at (c_parser_peek_token (parser
)->location
,
1614 "prefix attributes are ignored for implementations");
1615 specs
->attrs
= NULL_TREE
;
1617 c_parser_objc_class_definition (parser
, NULL_TREE
);
1621 case RID_AT_PROTOCOL
:
1623 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1625 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1632 case RID_AT_PROPERTY
:
1635 c_parser_error (parser
, "unexpected attribute");
1636 specs
->attrs
= NULL
;
1644 pending_xref_error ();
1645 prefix_attrs
= specs
->attrs
;
1646 all_prefix_attrs
= prefix_attrs
;
1647 specs
->attrs
= NULL_TREE
;
1650 struct c_declarator
*declarator
;
1654 /* Declaring either one or more declarators (in which case we
1655 should diagnose if there were no declaration specifiers) or a
1656 function definition (in which case the diagnostic for
1657 implicit int suffices). */
1658 declarator
= c_parser_declarator (parser
,
1659 specs
->typespec_kind
!= ctsk_none
,
1660 C_DTR_NORMAL
, &dummy
);
1661 if (declarator
== NULL
)
1663 if (omp_declare_simd_clauses
.exists ())
1664 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1665 omp_declare_simd_clauses
);
1666 c_parser_skip_to_end_of_block_or_statement (parser
);
1669 if (c_parser_next_token_is (parser
, CPP_EQ
)
1670 || c_parser_next_token_is (parser
, CPP_COMMA
)
1671 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1672 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1673 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1674 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1676 tree asm_name
= NULL_TREE
;
1677 tree postfix_attrs
= NULL_TREE
;
1678 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1680 diagnosed_no_specs
= true;
1681 pedwarn (here
, 0, "data definition has no type or storage class");
1683 /* Having seen a data definition, there cannot now be a
1684 function definition. */
1686 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1687 asm_name
= c_parser_simple_asm_expr (parser
);
1688 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1689 postfix_attrs
= c_parser_attributes (parser
);
1690 if (c_parser_next_token_is (parser
, CPP_EQ
))
1694 location_t init_loc
;
1695 c_parser_consume_token (parser
);
1696 /* The declaration of the variable is in effect while
1697 its initializer is parsed. */
1698 d
= start_decl (declarator
, specs
, true,
1699 chainon (postfix_attrs
, all_prefix_attrs
));
1701 d
= error_mark_node
;
1702 if (omp_declare_simd_clauses
.exists ())
1703 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1704 omp_declare_simd_clauses
);
1705 start_init (d
, asm_name
, global_bindings_p ());
1706 init_loc
= c_parser_peek_token (parser
)->location
;
1707 init
= c_parser_initializer (parser
);
1709 if (d
!= error_mark_node
)
1711 maybe_warn_string_init (TREE_TYPE (d
), init
);
1712 finish_decl (d
, init_loc
, init
.value
,
1713 init
.original_type
, asm_name
);
1718 tree d
= start_decl (declarator
, specs
, false,
1719 chainon (postfix_attrs
,
1721 if (omp_declare_simd_clauses
.exists ())
1723 tree parms
= NULL_TREE
;
1724 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1726 struct c_declarator
*ce
= declarator
;
1728 if (ce
->kind
== cdk_function
)
1730 parms
= ce
->u
.arg_info
->parms
;
1734 ce
= ce
->declarator
;
1737 temp_store_parm_decls (d
, parms
);
1738 c_finish_omp_declare_simd (parser
, d
, parms
,
1739 omp_declare_simd_clauses
);
1741 temp_pop_parm_decls ();
1744 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1745 NULL_TREE
, asm_name
);
1747 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1750 *objc_foreach_object_declaration
= d
;
1752 *objc_foreach_object_declaration
= error_mark_node
;
1755 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1757 c_parser_consume_token (parser
);
1758 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1759 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1762 all_prefix_attrs
= prefix_attrs
;
1765 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1767 c_parser_consume_token (parser
);
1770 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1772 /* This can only happen in Objective-C: we found the
1773 'in' that terminates the declaration inside an
1774 Objective-C foreach statement. Do not consume the
1775 token, so that the caller can use it to determine
1776 that this indeed is a foreach context. */
1781 c_parser_error (parser
, "expected %<,%> or %<;%>");
1782 c_parser_skip_to_end_of_block_or_statement (parser
);
1788 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1789 "%<asm%> or %<__attribute__%>");
1790 c_parser_skip_to_end_of_block_or_statement (parser
);
1793 /* Function definition (nested or otherwise). */
1796 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1797 c_push_function_context ();
1799 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1801 /* This can appear in many cases looking nothing like a
1802 function definition, so we don't give a more specific
1803 error suggesting there was one. */
1804 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1805 "or %<__attribute__%>");
1807 c_pop_function_context ();
1811 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1812 tv
= TV_PARSE_INLINE
;
1817 /* Parse old-style parameter declarations. ??? Attributes are
1818 not allowed to start declaration specifiers here because of a
1819 syntax conflict between a function declaration with attribute
1820 suffix and a function definition with an attribute prefix on
1821 first old-style parameter declaration. Following the old
1822 parser, they are not accepted on subsequent old-style
1823 parameter declarations either. However, there is no
1824 ambiguity after the first declaration, nor indeed on the
1825 first as long as we don't allow postfix attributes after a
1826 declarator with a nonempty identifier list in a definition;
1827 and postfix attributes have never been accepted here in
1828 function definitions either. */
1829 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1830 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1831 c_parser_declaration_or_fndef (parser
, false, false, false,
1832 true, false, NULL
, vNULL
);
1833 store_parm_decls ();
1834 if (omp_declare_simd_clauses
.exists ())
1835 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1836 omp_declare_simd_clauses
);
1837 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1838 = c_parser_peek_token (parser
)->location
;
1839 fnbody
= c_parser_compound_statement (parser
);
1840 if (flag_enable_cilkplus
&& contains_array_notation_expr (fnbody
))
1841 fnbody
= expand_array_notation_exprs (fnbody
);
1844 tree decl
= current_function_decl
;
1845 /* Mark nested functions as needing static-chain initially.
1846 lower_nested_functions will recompute it but the
1847 DECL_STATIC_CHAIN flag is also used before that happens,
1848 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1849 DECL_STATIC_CHAIN (decl
) = 1;
1852 c_pop_function_context ();
1853 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1866 /* Parse an asm-definition (asm() outside a function body). This is a
1874 c_parser_asm_definition (c_parser
*parser
)
1876 tree asm_str
= c_parser_simple_asm_expr (parser
);
1878 add_asm_node (asm_str
);
1879 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1882 /* Parse a static assertion (C11 6.7.10).
1884 static_assert-declaration:
1885 static_assert-declaration-no-semi ;
1889 c_parser_static_assert_declaration (c_parser
*parser
)
1891 c_parser_static_assert_declaration_no_semi (parser
);
1893 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1894 c_parser_skip_to_end_of_block_or_statement (parser
);
1897 /* Parse a static assertion (C11 6.7.10), without the trailing
1900 static_assert-declaration-no-semi:
1901 _Static_assert ( constant-expression , string-literal )
1905 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1907 location_t assert_loc
, value_loc
;
1911 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1912 assert_loc
= c_parser_peek_token (parser
)->location
;
1916 pedwarn (assert_loc
, OPT_Wpedantic
,
1917 "ISO C99 does not support %<_Static_assert%>");
1919 pedwarn (assert_loc
, OPT_Wpedantic
,
1920 "ISO C90 does not support %<_Static_assert%>");
1922 c_parser_consume_token (parser
);
1923 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1925 value_loc
= c_parser_peek_token (parser
)->location
;
1926 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1927 parser
->lex_untranslated_string
= true;
1928 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1930 parser
->lex_untranslated_string
= false;
1933 switch (c_parser_peek_token (parser
)->type
)
1939 case CPP_UTF8STRING
:
1940 string
= c_parser_peek_token (parser
)->value
;
1941 c_parser_consume_token (parser
);
1942 parser
->lex_untranslated_string
= false;
1945 c_parser_error (parser
, "expected string literal");
1946 parser
->lex_untranslated_string
= false;
1949 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1951 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1953 error_at (value_loc
, "expression in static assertion is not an integer");
1956 if (TREE_CODE (value
) != INTEGER_CST
)
1958 value
= c_fully_fold (value
, false, NULL
);
1959 if (TREE_CODE (value
) == INTEGER_CST
)
1960 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1961 "is not an integer constant expression");
1963 if (TREE_CODE (value
) != INTEGER_CST
)
1965 error_at (value_loc
, "expression in static assertion is not constant");
1968 constant_expression_warning (value
);
1969 if (integer_zerop (value
))
1970 error_at (assert_loc
, "static assertion failed: %E", string
);
1973 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1974 6.7), adding them to SPECS (which may already include some).
1975 Storage class specifiers are accepted iff SCSPEC_OK; type
1976 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
1977 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
1980 declaration-specifiers:
1981 storage-class-specifier declaration-specifiers[opt]
1982 type-specifier declaration-specifiers[opt]
1983 type-qualifier declaration-specifiers[opt]
1984 function-specifier declaration-specifiers[opt]
1985 alignment-specifier declaration-specifiers[opt]
1987 Function specifiers (inline) are from C99, and are currently
1988 handled as storage class specifiers, as is __thread. Alignment
1989 specifiers are from C11.
1991 C90 6.5.1, C99 6.7.1:
1992 storage-class-specifier:
2004 (_Noreturn is new in C11.)
2006 C90 6.5.2, C99 6.7.2:
2019 [_Imaginary removed in C99 TC2]
2020 struct-or-union-specifier
2024 (_Bool and _Complex are new in C99.)
2026 C90 6.5.3, C99 6.7.3:
2032 address-space-qualifier
2034 (restrict is new in C99.)
2038 declaration-specifiers:
2039 attributes declaration-specifiers[opt]
2045 identifier recognized by the target
2047 storage-class-specifier:
2060 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2061 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2066 class-name objc-protocol-refs[opt]
2067 typedef-name objc-protocol-refs
2072 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2073 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2074 bool alignspec_ok
, enum c_lookahead_kind la
)
2076 bool attrs_ok
= start_attr_ok
;
2077 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2080 gcc_assert (la
== cla_prefer_id
);
2082 while (c_parser_next_token_is (parser
, CPP_NAME
)
2083 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2084 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2086 struct c_typespec t
;
2089 location_t loc
= c_parser_peek_token (parser
)->location
;
2091 /* If we cannot accept a type, exit if the next token must start
2092 one. Also, if we already have seen a tagged definition,
2093 a typename would be an error anyway and likely the user
2094 has simply forgotten a semicolon, so we exit. */
2095 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2096 && c_parser_next_tokens_start_typename (parser
, la
)
2097 && !c_parser_next_token_is_qualifier (parser
))
2100 if (c_parser_next_token_is (parser
, CPP_NAME
))
2102 c_token
*name_token
= c_parser_peek_token (parser
);
2103 tree value
= name_token
->value
;
2104 c_id_kind kind
= name_token
->id_kind
;
2106 if (kind
== C_ID_ADDRSPACE
)
2109 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2110 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2111 c_parser_consume_token (parser
);
2116 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2118 /* If we cannot accept a type, and the next token must start one,
2119 exit. Do the same if we already have seen a tagged definition,
2120 since it would be an error anyway and likely the user has simply
2121 forgotten a semicolon. */
2122 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2125 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2126 a C_ID_CLASSNAME. */
2127 c_parser_consume_token (parser
);
2130 if (kind
== C_ID_ID
)
2132 error ("unknown type name %qE", value
);
2133 t
.kind
= ctsk_typedef
;
2134 t
.spec
= error_mark_node
;
2136 else if (kind
== C_ID_TYPENAME
2137 && (!c_dialect_objc ()
2138 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2140 t
.kind
= ctsk_typedef
;
2141 /* For a typedef name, record the meaning, not the name.
2142 In case of 'foo foo, bar;'. */
2143 t
.spec
= lookup_name (value
);
2147 tree proto
= NULL_TREE
;
2148 gcc_assert (c_dialect_objc ());
2150 if (c_parser_next_token_is (parser
, CPP_LESS
))
2151 proto
= c_parser_objc_protocol_refs (parser
);
2152 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2155 t
.expr_const_operands
= true;
2156 declspecs_add_type (name_token
->location
, specs
, t
);
2159 if (c_parser_next_token_is (parser
, CPP_LESS
))
2161 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2162 nisse@lysator.liu.se. */
2164 gcc_assert (c_dialect_objc ());
2165 if (!typespec_ok
|| seen_type
)
2167 proto
= c_parser_objc_protocol_refs (parser
);
2169 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2171 t
.expr_const_operands
= true;
2172 declspecs_add_type (loc
, specs
, t
);
2175 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2176 switch (c_parser_peek_token (parser
)->keyword
)
2189 /* TODO: Distinguish between function specifiers (inline, noreturn)
2190 and storage class specifiers, either here or in
2191 declspecs_add_scspec. */
2192 declspecs_add_scspec (loc
, specs
,
2193 c_parser_peek_token (parser
)->value
);
2194 c_parser_consume_token (parser
);
2218 if (c_dialect_objc ())
2219 parser
->objc_need_raw_identifier
= true;
2220 t
.kind
= ctsk_resword
;
2221 t
.spec
= c_parser_peek_token (parser
)->value
;
2223 t
.expr_const_operands
= true;
2224 declspecs_add_type (loc
, specs
, t
);
2225 c_parser_consume_token (parser
);
2232 t
= c_parser_enum_specifier (parser
);
2233 declspecs_add_type (loc
, specs
, t
);
2241 t
= c_parser_struct_or_union_specifier (parser
);
2242 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2243 declspecs_add_type (loc
, specs
, t
);
2246 /* ??? The old parser rejected typeof after other type
2247 specifiers, but is a syntax error the best way of
2249 if (!typespec_ok
|| seen_type
)
2253 t
= c_parser_typeof_specifier (parser
);
2254 declspecs_add_type (loc
, specs
, t
);
2260 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2261 c_parser_consume_token (parser
);
2263 /* UPC qualifiers */
2266 c_parser_upc_shared_qual (loc
, parser
, specs
);
2271 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2272 c_parser_consume_token (parser
);
2277 attrs
= c_parser_attributes (parser
);
2278 declspecs_add_attrs (loc
, specs
, attrs
);
2283 align
= c_parser_alignas_specifier (parser
);
2284 declspecs_add_alignas (loc
, specs
, align
);
2293 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2296 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2297 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2298 enum attributes[opt] identifier
2300 The form with trailing comma is new in C99. The forms with
2301 attributes are GNU extensions. In GNU C, we accept any expression
2302 without commas in the syntax (assignment expressions, not just
2303 conditional expressions); assignment expressions will be diagnosed
2308 enumerator-list , enumerator
2311 enumeration-constant
2312 enumeration-constant = constant-expression
2315 static struct c_typespec
2316 c_parser_enum_specifier (c_parser
*parser
)
2318 struct c_typespec ret
;
2320 tree ident
= NULL_TREE
;
2321 location_t enum_loc
;
2322 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2323 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2324 enum_loc
= c_parser_peek_token (parser
)->location
;
2325 c_parser_consume_token (parser
);
2326 attrs
= c_parser_attributes (parser
);
2327 enum_loc
= c_parser_peek_token (parser
)->location
;
2328 /* Set the location in case we create a decl now. */
2329 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2330 if (c_parser_next_token_is (parser
, CPP_NAME
))
2332 ident
= c_parser_peek_token (parser
)->value
;
2333 ident_loc
= c_parser_peek_token (parser
)->location
;
2334 enum_loc
= ident_loc
;
2335 c_parser_consume_token (parser
);
2337 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2339 /* Parse an enum definition. */
2340 struct c_enum_contents the_enum
;
2343 /* We chain the enumerators in reverse order, then put them in
2344 forward order at the end. */
2346 timevar_push (TV_PARSE_ENUM
);
2347 type
= start_enum (enum_loc
, &the_enum
, ident
);
2349 c_parser_consume_token (parser
);
2357 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2358 location_t decl_loc
, value_loc
;
2359 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2361 c_parser_error (parser
, "expected identifier");
2362 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2363 values
= error_mark_node
;
2366 token
= c_parser_peek_token (parser
);
2367 enum_id
= token
->value
;
2368 /* Set the location in case we create a decl now. */
2369 c_parser_set_source_position_from_token (token
);
2370 decl_loc
= value_loc
= token
->location
;
2371 c_parser_consume_token (parser
);
2372 if (c_parser_next_token_is (parser
, CPP_EQ
))
2374 c_parser_consume_token (parser
);
2375 value_loc
= c_parser_peek_token (parser
)->location
;
2376 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2379 enum_value
= NULL_TREE
;
2380 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2381 &the_enum
, enum_id
, enum_value
);
2382 TREE_CHAIN (enum_decl
) = values
;
2385 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2387 comma_loc
= c_parser_peek_token (parser
)->location
;
2389 c_parser_consume_token (parser
);
2391 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2393 if (seen_comma
&& !flag_isoc99
)
2394 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2395 c_parser_consume_token (parser
);
2400 c_parser_error (parser
, "expected %<,%> or %<}%>");
2401 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2402 values
= error_mark_node
;
2406 postfix_attrs
= c_parser_attributes (parser
);
2407 ret
.spec
= finish_enum (type
, nreverse (values
),
2408 chainon (attrs
, postfix_attrs
));
2409 ret
.kind
= ctsk_tagdef
;
2410 ret
.expr
= NULL_TREE
;
2411 ret
.expr_const_operands
= true;
2412 timevar_pop (TV_PARSE_ENUM
);
2417 c_parser_error (parser
, "expected %<{%>");
2418 ret
.spec
= error_mark_node
;
2419 ret
.kind
= ctsk_tagref
;
2420 ret
.expr
= NULL_TREE
;
2421 ret
.expr_const_operands
= true;
2424 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2425 /* In ISO C, enumerated types can be referred to only if already
2427 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2430 pedwarn (enum_loc
, OPT_Wpedantic
,
2431 "ISO C forbids forward references to %<enum%> types");
2436 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2438 struct-or-union-specifier:
2439 struct-or-union attributes[opt] identifier[opt]
2440 { struct-contents } attributes[opt]
2441 struct-or-union attributes[opt] identifier
2444 struct-declaration-list
2446 struct-declaration-list:
2447 struct-declaration ;
2448 struct-declaration-list struct-declaration ;
2455 struct-declaration-list struct-declaration
2457 struct-declaration-list:
2458 struct-declaration-list ;
2461 (Note that in the syntax here, unlike that in ISO C, the semicolons
2462 are included here rather than in struct-declaration, in order to
2463 describe the syntax with extra semicolons and missing semicolon at
2468 struct-declaration-list:
2469 @defs ( class-name )
2471 (Note this does not include a trailing semicolon, but can be
2472 followed by further declarations, and gets a pedwarn-if-pedantic
2473 when followed by a semicolon.) */
2475 static struct c_typespec
2476 c_parser_struct_or_union_specifier (c_parser
*parser
)
2478 struct c_typespec ret
;
2480 tree ident
= NULL_TREE
;
2481 location_t struct_loc
;
2482 location_t ident_loc
= UNKNOWN_LOCATION
;
2483 enum tree_code code
;
2484 switch (c_parser_peek_token (parser
)->keyword
)
2495 struct_loc
= c_parser_peek_token (parser
)->location
;
2496 c_parser_consume_token (parser
);
2497 attrs
= c_parser_attributes (parser
);
2499 /* Set the location in case we create a decl now. */
2500 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2502 if (c_parser_next_token_is (parser
, CPP_NAME
))
2504 ident
= c_parser_peek_token (parser
)->value
;
2505 ident_loc
= c_parser_peek_token (parser
)->location
;
2506 struct_loc
= ident_loc
;
2507 c_parser_consume_token (parser
);
2509 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2511 /* Parse a struct or union definition. Start the scope of the
2512 tag before parsing components. */
2513 struct c_struct_parse_info
*struct_info
;
2514 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2516 /* We chain the components in reverse order, then put them in
2517 forward order at the end. Each struct-declaration may
2518 declare multiple components (comma-separated), so we must use
2519 chainon to join them, although when parsing each
2520 struct-declaration we can use TREE_CHAIN directly.
2522 The theory behind all this is that there will be more
2523 semicolon separated fields than comma separated fields, and
2524 so we'll be minimizing the number of node traversals required
2527 timevar_push (TV_PARSE_STRUCT
);
2528 contents
= NULL_TREE
;
2529 c_parser_consume_token (parser
);
2530 /* Handle the Objective-C @defs construct,
2531 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2532 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2535 gcc_assert (c_dialect_objc ());
2536 c_parser_consume_token (parser
);
2537 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2539 if (c_parser_next_token_is (parser
, CPP_NAME
)
2540 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2542 name
= c_parser_peek_token (parser
)->value
;
2543 c_parser_consume_token (parser
);
2547 c_parser_error (parser
, "expected class name");
2548 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2551 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2553 contents
= nreverse (objc_get_class_ivars (name
));
2556 /* Parse the struct-declarations and semicolons. Problems with
2557 semicolons are diagnosed here; empty structures are diagnosed
2562 /* Parse any stray semicolon. */
2563 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2565 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2566 "extra semicolon in struct or union specified");
2567 c_parser_consume_token (parser
);
2570 /* Stop if at the end of the struct or union contents. */
2571 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2573 c_parser_consume_token (parser
);
2576 /* Accept #pragmas at struct scope. */
2577 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2579 c_parser_pragma (parser
, pragma_struct
);
2582 /* Parse some comma-separated declarations, but not the
2583 trailing semicolon if any. */
2584 decls
= c_parser_struct_declaration (parser
);
2585 contents
= chainon (decls
, contents
);
2586 /* If no semicolon follows, either we have a parse error or
2587 are at the end of the struct or union and should
2589 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2590 c_parser_consume_token (parser
);
2593 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2594 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2595 "no semicolon at end of struct or union");
2596 else if (parser
->error
2597 || !c_parser_next_token_starts_declspecs (parser
))
2599 c_parser_error (parser
, "expected %<;%>");
2600 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2604 /* If we come here, we have already emitted an error
2605 for an expected `;', identifier or `(', and we also
2606 recovered already. Go on with the next field. */
2609 postfix_attrs
= c_parser_attributes (parser
);
2610 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2611 chainon (attrs
, postfix_attrs
), struct_info
);
2612 ret
.kind
= ctsk_tagdef
;
2613 ret
.expr
= NULL_TREE
;
2614 ret
.expr_const_operands
= true;
2615 timevar_pop (TV_PARSE_STRUCT
);
2620 c_parser_error (parser
, "expected %<{%>");
2621 ret
.spec
= error_mark_node
;
2622 ret
.kind
= ctsk_tagref
;
2623 ret
.expr
= NULL_TREE
;
2624 ret
.expr_const_operands
= true;
2627 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2631 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2632 the trailing semicolon.
2635 specifier-qualifier-list struct-declarator-list
2636 static_assert-declaration-no-semi
2638 specifier-qualifier-list:
2639 type-specifier specifier-qualifier-list[opt]
2640 type-qualifier specifier-qualifier-list[opt]
2641 attributes specifier-qualifier-list[opt]
2643 struct-declarator-list:
2645 struct-declarator-list , attributes[opt] struct-declarator
2648 declarator attributes[opt]
2649 declarator[opt] : constant-expression attributes[opt]
2654 __extension__ struct-declaration
2655 specifier-qualifier-list
2657 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2658 of attributes where shown is a GNU extension. In GNU C, we accept
2659 any expression without commas in the syntax (assignment
2660 expressions, not just conditional expressions); assignment
2661 expressions will be diagnosed as non-constant. */
2664 c_parser_struct_declaration (c_parser
*parser
)
2666 struct c_declspecs
*specs
;
2668 tree all_prefix_attrs
;
2670 location_t decl_loc
;
2671 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2675 ext
= disable_extension_diagnostics ();
2676 c_parser_consume_token (parser
);
2677 decl
= c_parser_struct_declaration (parser
);
2678 restore_extension_diagnostics (ext
);
2681 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2683 c_parser_static_assert_declaration_no_semi (parser
);
2686 specs
= build_null_declspecs ();
2687 decl_loc
= c_parser_peek_token (parser
)->location
;
2688 /* Strictly by the standard, we shouldn't allow _Alignas here,
2689 but it appears to have been intended to allow it there, so
2690 we're keeping it as it is until WG14 reaches a conclusion
2692 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2693 c_parser_declspecs (parser
, specs
, false, true, true,
2694 true, cla_nonabstract_decl
);
2697 if (!specs
->declspecs_seen_p
)
2699 c_parser_error (parser
, "expected specifier-qualifier-list");
2702 finish_declspecs (specs
);
2703 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2704 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2707 if (specs
->typespec_kind
== ctsk_none
)
2709 pedwarn (decl_loc
, OPT_Wpedantic
,
2710 "ISO C forbids member declarations with no members");
2711 shadow_tag_warned (specs
, pedantic
);
2716 /* Support for unnamed structs or unions as members of
2717 structs or unions (which is [a] useful and [b] supports
2721 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2722 build_id_declarator (NULL_TREE
), specs
,
2725 decl_attributes (&ret
, attrs
, 0);
2730 /* Provide better error recovery. Note that a type name here is valid,
2731 and will be treated as a field name. */
2732 if (specs
->typespec_kind
== ctsk_tagdef
2733 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2734 && c_parser_next_token_starts_declspecs (parser
)
2735 && !c_parser_next_token_is (parser
, CPP_NAME
))
2737 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2738 parser
->error
= false;
2742 pending_xref_error ();
2743 prefix_attrs
= specs
->attrs
;
2744 all_prefix_attrs
= prefix_attrs
;
2745 specs
->attrs
= NULL_TREE
;
2749 /* Declaring one or more declarators or un-named bit-fields. */
2750 struct c_declarator
*declarator
;
2752 if (c_parser_next_token_is (parser
, CPP_COLON
))
2753 declarator
= build_id_declarator (NULL_TREE
);
2755 declarator
= c_parser_declarator (parser
,
2756 specs
->typespec_kind
!= ctsk_none
,
2757 C_DTR_NORMAL
, &dummy
);
2758 if (declarator
== NULL
)
2760 c_parser_skip_to_end_of_block_or_statement (parser
);
2763 if (c_parser_next_token_is (parser
, CPP_COLON
)
2764 || c_parser_next_token_is (parser
, CPP_COMMA
)
2765 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2766 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2767 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2769 tree postfix_attrs
= NULL_TREE
;
2770 tree width
= NULL_TREE
;
2772 if (c_parser_next_token_is (parser
, CPP_COLON
))
2774 c_parser_consume_token (parser
);
2775 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2777 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2778 postfix_attrs
= c_parser_attributes (parser
);
2779 d
= grokfield (c_parser_peek_token (parser
)->location
,
2780 declarator
, specs
, width
, &all_prefix_attrs
);
2781 decl_attributes (&d
, chainon (postfix_attrs
,
2782 all_prefix_attrs
), 0);
2783 DECL_CHAIN (d
) = decls
;
2785 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2786 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2789 all_prefix_attrs
= prefix_attrs
;
2790 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2791 c_parser_consume_token (parser
);
2792 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2793 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2795 /* Semicolon consumed in caller. */
2800 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2806 c_parser_error (parser
,
2807 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2808 "%<__attribute__%>");
2815 /* Parse a typeof specifier (a GNU extension).
2818 typeof ( expression )
2819 typeof ( type-name )
2822 static struct c_typespec
2823 c_parser_typeof_specifier (c_parser
*parser
)
2825 struct c_typespec ret
;
2826 ret
.kind
= ctsk_typeof
;
2827 ret
.spec
= error_mark_node
;
2828 ret
.expr
= NULL_TREE
;
2829 ret
.expr_const_operands
= true;
2830 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2831 c_parser_consume_token (parser
);
2832 c_inhibit_evaluation_warnings
++;
2834 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2836 c_inhibit_evaluation_warnings
--;
2840 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2842 struct c_type_name
*type
= c_parser_type_name (parser
);
2843 c_inhibit_evaluation_warnings
--;
2847 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2848 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2854 location_t here
= c_parser_peek_token (parser
)->location
;
2855 struct c_expr expr
= c_parser_expression (parser
);
2856 c_inhibit_evaluation_warnings
--;
2858 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2859 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2860 error_at (here
, "%<typeof%> applied to a bit-field");
2861 mark_exp_read (expr
.value
);
2862 ret
.spec
= TREE_TYPE (expr
.value
);
2863 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2864 /* This is returned with the type so that when the type is
2865 evaluated, this can be evaluated. */
2867 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2868 pop_maybe_used (was_vm
);
2870 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2874 /* Parse an alignment-specifier.
2878 alignment-specifier:
2879 _Alignas ( type-name )
2880 _Alignas ( constant-expression )
2884 c_parser_alignas_specifier (c_parser
* parser
)
2886 tree ret
= error_mark_node
;
2887 location_t loc
= c_parser_peek_token (parser
)->location
;
2888 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2889 c_parser_consume_token (parser
);
2893 pedwarn (loc
, OPT_Wpedantic
,
2894 "ISO C99 does not support %<_Alignas%>");
2896 pedwarn (loc
, OPT_Wpedantic
,
2897 "ISO C90 does not support %<_Alignas%>");
2899 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2901 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2903 struct c_type_name
*type
= c_parser_type_name (parser
);
2905 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2908 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2909 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2913 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2914 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2915 be redeclared; otherwise it may not. KIND indicates which kind of
2916 declarator is wanted. Returns a valid declarator except in the
2917 case of a syntax error in which case NULL is returned. *SEEN_ID is
2918 set to true if an identifier being declared is seen; this is used
2919 to diagnose bad forms of abstract array declarators and to
2920 determine whether an identifier list is syntactically permitted.
2923 pointer[opt] direct-declarator
2927 ( attributes[opt] declarator )
2928 direct-declarator array-declarator
2929 direct-declarator ( parameter-type-list )
2930 direct-declarator ( identifier-list[opt] )
2933 * type-qualifier-list[opt]
2934 * type-qualifier-list[opt] pointer
2936 type-qualifier-list:
2939 type-qualifier-list type-qualifier
2940 type-qualifier-list attributes
2943 [ type-qualifier-list[opt] assignment-expression[opt] ]
2944 [ static type-qualifier-list[opt] assignment-expression ]
2945 [ type-qualifier-list static assignment-expression ]
2946 [ type-qualifier-list[opt] * ]
2948 parameter-type-list:
2950 parameter-list , ...
2953 parameter-declaration
2954 parameter-list , parameter-declaration
2956 parameter-declaration:
2957 declaration-specifiers declarator attributes[opt]
2958 declaration-specifiers abstract-declarator[opt] attributes[opt]
2962 identifier-list , identifier
2964 abstract-declarator:
2966 pointer[opt] direct-abstract-declarator
2968 direct-abstract-declarator:
2969 ( attributes[opt] abstract-declarator )
2970 direct-abstract-declarator[opt] array-declarator
2971 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2976 direct-declarator ( parameter-forward-declarations
2977 parameter-type-list[opt] )
2979 direct-abstract-declarator:
2980 direct-abstract-declarator[opt] ( parameter-forward-declarations
2981 parameter-type-list[opt] )
2983 parameter-forward-declarations:
2985 parameter-forward-declarations parameter-list ;
2987 The uses of attributes shown above are GNU extensions.
2989 Some forms of array declarator are not included in C99 in the
2990 syntax for abstract declarators; these are disallowed elsewhere.
2991 This may be a defect (DR#289).
2993 This function also accepts an omitted abstract declarator as being
2994 an abstract declarator, although not part of the formal syntax. */
2996 static struct c_declarator
*
2997 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3000 /* Parse any initial pointer part. */
3001 if (c_parser_next_token_is (parser
, CPP_MULT
))
3003 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3004 struct c_declarator
*inner
;
3005 c_parser_consume_token (parser
);
3006 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3007 false, cla_prefer_id
);
3008 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3012 return make_pointer_declarator (quals_attrs
, inner
);
3014 /* Now we have a direct declarator, direct abstract declarator or
3015 nothing (which counts as a direct abstract declarator here). */
3016 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3019 /* Parse a direct declarator or direct abstract declarator; arguments
3020 as c_parser_declarator. */
3022 static struct c_declarator
*
3023 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3026 /* The direct declarator must start with an identifier (possibly
3027 omitted) or a parenthesized declarator (possibly abstract). In
3028 an ordinary declarator, initial parentheses must start a
3029 parenthesized declarator. In an abstract declarator or parameter
3030 declarator, they could start a parenthesized declarator or a
3031 parameter list. To tell which, the open parenthesis and any
3032 following attributes must be read. If a declaration specifier
3033 follows, then it is a parameter list; if the specifier is a
3034 typedef name, there might be an ambiguity about redeclaring it,
3035 which is resolved in the direction of treating it as a typedef
3036 name. If a close parenthesis follows, it is also an empty
3037 parameter list, as the syntax does not permit empty abstract
3038 declarators. Otherwise, it is a parenthesized declarator (in
3039 which case the analysis may be repeated inside it, recursively).
3041 ??? There is an ambiguity in a parameter declaration "int
3042 (__attribute__((foo)) x)", where x is not a typedef name: it
3043 could be an abstract declarator for a function, or declare x with
3044 parentheses. The proper resolution of this ambiguity needs
3045 documenting. At present we follow an accident of the old
3046 parser's implementation, whereby the first parameter must have
3047 some declaration specifiers other than just attributes. Thus as
3048 a parameter declaration it is treated as a parenthesized
3049 parameter named x, and as an abstract declarator it is
3052 ??? Also following the old parser, attributes inside an empty
3053 parameter list are ignored, making it a list not yielding a
3054 prototype, rather than giving an error or making it have one
3055 parameter with implicit type int.
3057 ??? Also following the old parser, typedef names may be
3058 redeclared in declarators, but not Objective-C class names. */
3060 if (kind
!= C_DTR_ABSTRACT
3061 && c_parser_next_token_is (parser
, CPP_NAME
)
3063 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3064 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3065 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3067 struct c_declarator
*inner
3068 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3070 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3071 c_parser_consume_token (parser
);
3072 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3075 if (kind
!= C_DTR_NORMAL
3076 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3078 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3079 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3082 /* Either we are at the end of an abstract declarator, or we have
3085 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3088 struct c_declarator
*inner
;
3089 c_parser_consume_token (parser
);
3090 attrs
= c_parser_attributes (parser
);
3091 if (kind
!= C_DTR_NORMAL
3092 && (c_parser_next_token_starts_declspecs (parser
)
3093 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3095 struct c_arg_info
*args
3096 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3103 = build_function_declarator (args
,
3104 build_id_declarator (NULL_TREE
));
3105 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3109 /* A parenthesized declarator. */
3110 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3111 if (inner
!= NULL
&& attrs
!= NULL
)
3112 inner
= build_attrs_declarator (attrs
, inner
);
3113 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3115 c_parser_consume_token (parser
);
3119 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3123 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3130 if (kind
== C_DTR_NORMAL
)
3132 c_parser_error (parser
, "expected identifier or %<(%>");
3136 return build_id_declarator (NULL_TREE
);
3140 /* Parse part of a direct declarator or direct abstract declarator,
3141 given that some (in INNER) has already been parsed; ID_PRESENT is
3142 true if an identifier is present, false for an abstract
3145 static struct c_declarator
*
3146 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3147 struct c_declarator
*inner
)
3149 /* Parse a sequence of array declarators and parameter lists. */
3150 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3152 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3153 struct c_declarator
*declarator
;
3154 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3158 c_parser_consume_token (parser
);
3159 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3160 false, cla_prefer_id
);
3161 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3163 c_parser_consume_token (parser
);
3164 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3165 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3166 false, cla_prefer_id
);
3167 if (!quals_attrs
->declspecs_seen_p
)
3169 /* If "static" is present, there must be an array dimension.
3170 Otherwise, there may be a dimension, "*", or no
3175 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3179 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3184 else if (flag_enable_cilkplus
3185 && c_parser_next_token_is (parser
, CPP_COLON
))
3187 dimen
= error_mark_node
;
3189 error_at (c_parser_peek_token (parser
)->location
,
3190 "array notations cannot be used in declaration");
3191 c_parser_consume_token (parser
);
3193 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3195 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3199 c_parser_consume_token (parser
);
3204 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3210 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3213 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3214 c_parser_consume_token (parser
);
3215 else if (flag_enable_cilkplus
3216 && c_parser_next_token_is (parser
, CPP_COLON
))
3218 error_at (c_parser_peek_token (parser
)->location
,
3219 "array notations cannot be used in declaration");
3220 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3225 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3230 mark_exp_read (dimen
);
3231 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3232 static_seen
, star_seen
);
3233 if (declarator
== NULL
)
3235 inner
= set_array_declarator_inner (declarator
, inner
);
3236 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3238 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3241 struct c_arg_info
*args
;
3242 c_parser_consume_token (parser
);
3243 attrs
= c_parser_attributes (parser
);
3244 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3249 inner
= build_function_declarator (args
, inner
);
3250 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3256 /* Parse a parameter list or identifier list, including the closing
3257 parenthesis but not the opening one. ATTRS are the attributes at
3258 the start of the list. ID_LIST_OK is true if an identifier list is
3259 acceptable; such a list must not have attributes at the start. */
3261 static struct c_arg_info
*
3262 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3265 declare_parm_level ();
3266 /* If the list starts with an identifier, it is an identifier list.
3267 Otherwise, it is either a prototype list or an empty list. */
3270 && c_parser_next_token_is (parser
, CPP_NAME
)
3271 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3273 /* Look ahead to detect typos in type names. */
3274 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3275 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3276 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3277 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3279 tree list
= NULL_TREE
, *nextp
= &list
;
3280 while (c_parser_next_token_is (parser
, CPP_NAME
)
3281 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3283 *nextp
= build_tree_list (NULL_TREE
,
3284 c_parser_peek_token (parser
)->value
);
3285 nextp
= & TREE_CHAIN (*nextp
);
3286 c_parser_consume_token (parser
);
3287 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3289 c_parser_consume_token (parser
);
3290 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3292 c_parser_error (parser
, "expected identifier");
3296 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3298 struct c_arg_info
*ret
= build_arg_info ();
3300 c_parser_consume_token (parser
);
3306 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3314 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3321 /* Parse a parameter list (possibly empty), including the closing
3322 parenthesis but not the opening one. ATTRS are the attributes at
3323 the start of the list. EXPR is NULL or an expression that needs to
3324 be evaluated for the side effects of array size expressions in the
3327 static struct c_arg_info
*
3328 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3330 bool bad_parm
= false;
3332 /* ??? Following the old parser, forward parameter declarations may
3333 use abstract declarators, and if no real parameter declarations
3334 follow the forward declarations then this is not diagnosed. Also
3335 note as above that attributes are ignored as the only contents of
3336 the parentheses, or as the only contents after forward
3338 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3340 struct c_arg_info
*ret
= build_arg_info ();
3341 c_parser_consume_token (parser
);
3344 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3346 struct c_arg_info
*ret
= build_arg_info ();
3348 if (flag_allow_parameterless_variadic_functions
)
3350 /* F (...) is allowed. */
3351 ret
->types
= NULL_TREE
;
3355 /* Suppress -Wold-style-definition for this case. */
3356 ret
->types
= error_mark_node
;
3357 error_at (c_parser_peek_token (parser
)->location
,
3358 "ISO C requires a named argument before %<...%>");
3360 c_parser_consume_token (parser
);
3361 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3363 c_parser_consume_token (parser
);
3368 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3373 /* Nonempty list of parameters, either terminated with semicolon
3374 (forward declarations; recurse) or with close parenthesis (normal
3375 function) or with ", ... )" (variadic function). */
3378 /* Parse a parameter. */
3379 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3384 push_parm_decl (parm
, &expr
);
3385 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3388 c_parser_consume_token (parser
);
3389 mark_forward_parm_decls ();
3390 new_attrs
= c_parser_attributes (parser
);
3391 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3393 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3395 c_parser_consume_token (parser
);
3399 return get_parm_info (false, expr
);
3401 if (!c_parser_require (parser
, CPP_COMMA
,
3402 "expected %<;%>, %<,%> or %<)%>"))
3404 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3407 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3409 c_parser_consume_token (parser
);
3410 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3412 c_parser_consume_token (parser
);
3416 return get_parm_info (true, expr
);
3420 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3428 /* Parse a parameter declaration. ATTRS are the attributes at the
3429 start of the declaration if it is the first parameter. */
3431 static struct c_parm
*
3432 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3434 struct c_declspecs
*specs
;
3435 struct c_declarator
*declarator
;
3437 tree postfix_attrs
= NULL_TREE
;
3440 /* Accept #pragmas between parameter declarations. */
3441 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3442 c_parser_pragma (parser
, pragma_param
);
3444 if (!c_parser_next_token_starts_declspecs (parser
))
3446 c_token
*token
= c_parser_peek_token (parser
);
3449 c_parser_set_source_position_from_token (token
);
3450 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3452 error ("unknown type name %qE", token
->value
);
3453 parser
->error
= true;
3455 /* ??? In some Objective-C cases '...' isn't applicable so there
3456 should be a different message. */
3458 c_parser_error (parser
,
3459 "expected declaration specifiers or %<...%>");
3460 c_parser_skip_to_end_of_parameter (parser
);
3463 specs
= build_null_declspecs ();
3466 declspecs_add_attrs (input_location
, specs
, attrs
);
3469 c_parser_declspecs (parser
, specs
, true, true, true, true,
3470 cla_nonabstract_decl
);
3471 finish_declspecs (specs
);
3472 pending_xref_error ();
3473 prefix_attrs
= specs
->attrs
;
3474 specs
->attrs
= NULL_TREE
;
3475 declarator
= c_parser_declarator (parser
,
3476 specs
->typespec_kind
!= ctsk_none
,
3477 C_DTR_PARM
, &dummy
);
3478 if (declarator
== NULL
)
3480 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3483 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3484 postfix_attrs
= c_parser_attributes (parser
);
3485 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3489 /* Parse a string literal in an asm expression. It should not be
3490 translated, and wide string literals are an error although
3491 permitted by the syntax. This is a GNU extension.
3496 ??? At present, following the old parser, the caller needs to have
3497 set lex_untranslated_string to 1. It would be better to follow the
3498 C++ parser rather than using this kludge. */
3501 c_parser_asm_string_literal (c_parser
*parser
)
3504 int save_flag
= warn_overlength_strings
;
3505 warn_overlength_strings
= 0;
3506 if (c_parser_next_token_is (parser
, CPP_STRING
))
3508 str
= c_parser_peek_token (parser
)->value
;
3509 c_parser_consume_token (parser
);
3511 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3513 error_at (c_parser_peek_token (parser
)->location
,
3514 "wide string literal in %<asm%>");
3515 str
= build_string (1, "");
3516 c_parser_consume_token (parser
);
3520 c_parser_error (parser
, "expected string literal");
3523 warn_overlength_strings
= save_flag
;
3527 /* Parse a simple asm expression. This is used in restricted
3528 contexts, where a full expression with inputs and outputs does not
3529 make sense. This is a GNU extension.
3532 asm ( asm-string-literal )
3536 c_parser_simple_asm_expr (c_parser
*parser
)
3539 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3540 /* ??? Follow the C++ parser rather than using the
3541 lex_untranslated_string kludge. */
3542 parser
->lex_untranslated_string
= true;
3543 c_parser_consume_token (parser
);
3544 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3546 parser
->lex_untranslated_string
= false;
3549 str
= c_parser_asm_string_literal (parser
);
3550 parser
->lex_untranslated_string
= false;
3551 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3553 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3560 c_parser_attribute_any_word (c_parser
*parser
)
3562 tree attr_name
= NULL_TREE
;
3564 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3566 /* ??? See comment above about what keywords are accepted here. */
3568 switch (c_parser_peek_token (parser
)->keyword
)
3599 case RID_TRANSACTION_ATOMIC
:
3600 case RID_TRANSACTION_CANCEL
:
3610 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3611 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3613 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3614 attr_name
= c_parser_peek_token (parser
)->value
;
3619 /* Parse (possibly empty) attributes. This is a GNU extension.
3623 attributes attribute
3626 __attribute__ ( ( attribute-list ) )
3630 attribute_list , attrib
3635 any-word ( identifier )
3636 any-word ( identifier , nonempty-expr-list )
3637 any-word ( expr-list )
3639 where the "identifier" must not be declared as a type, and
3640 "any-word" may be any identifier (including one declared as a
3641 type), a reserved word storage class specifier, type specifier or
3642 type qualifier. ??? This still leaves out most reserved keywords
3643 (following the old parser), shouldn't we include them, and why not
3644 allow identifiers declared as types to start the arguments? */
3647 c_parser_attributes (c_parser
*parser
)
3649 tree attrs
= NULL_TREE
;
3650 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3652 /* ??? Follow the C++ parser rather than using the
3653 lex_untranslated_string kludge. */
3654 parser
->lex_untranslated_string
= true;
3655 c_parser_consume_token (parser
);
3656 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3658 parser
->lex_untranslated_string
= false;
3661 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3663 parser
->lex_untranslated_string
= false;
3664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3667 /* Parse the attribute list. */
3668 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3669 || c_parser_next_token_is (parser
, CPP_NAME
)
3670 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3672 tree attr
, attr_name
, attr_args
;
3673 vec
<tree
, va_gc
> *expr_list
;
3674 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3676 c_parser_consume_token (parser
);
3680 attr_name
= c_parser_attribute_any_word (parser
);
3681 if (attr_name
== NULL
)
3683 c_parser_consume_token (parser
);
3684 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3686 attr
= build_tree_list (attr_name
, NULL_TREE
);
3687 attrs
= chainon (attrs
, attr
);
3690 c_parser_consume_token (parser
);
3691 /* Parse the attribute contents. If they start with an
3692 identifier which is followed by a comma or close
3693 parenthesis, then the arguments start with that
3694 identifier; otherwise they are an expression list.
3695 In objective-c the identifier may be a classname. */
3696 if (c_parser_next_token_is (parser
, CPP_NAME
)
3697 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3698 || (c_dialect_objc ()
3699 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3700 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3701 || (c_parser_peek_2nd_token (parser
)->type
3702 == CPP_CLOSE_PAREN
)))
3704 tree arg1
= c_parser_peek_token (parser
)->value
;
3705 c_parser_consume_token (parser
);
3706 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3707 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3711 c_parser_consume_token (parser
);
3712 expr_list
= c_parser_expr_list (parser
, false, true,
3714 tree_list
= build_tree_list_vec (expr_list
);
3715 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3716 release_tree_vector (expr_list
);
3721 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3722 attr_args
= NULL_TREE
;
3725 expr_list
= c_parser_expr_list (parser
, false, true,
3727 attr_args
= build_tree_list_vec (expr_list
);
3728 release_tree_vector (expr_list
);
3731 attr
= build_tree_list (attr_name
, attr_args
);
3732 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3733 c_parser_consume_token (parser
);
3736 parser
->lex_untranslated_string
= false;
3737 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3741 attrs
= chainon (attrs
, attr
);
3743 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3744 c_parser_consume_token (parser
);
3747 parser
->lex_untranslated_string
= false;
3748 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3752 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3753 c_parser_consume_token (parser
);
3756 parser
->lex_untranslated_string
= false;
3757 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3761 parser
->lex_untranslated_string
= false;
3766 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3769 specifier-qualifier-list abstract-declarator[opt]
3772 static struct c_type_name
*
3773 c_parser_type_name (c_parser
*parser
)
3775 struct c_declspecs
*specs
= build_null_declspecs ();
3776 struct c_declarator
*declarator
;
3777 struct c_type_name
*ret
;
3779 c_parser_declspecs (parser
, specs
, false, true, true, false,
3781 if (!specs
->declspecs_seen_p
)
3783 c_parser_error (parser
, "expected specifier-qualifier-list");
3786 if (specs
->type
!= error_mark_node
)
3788 pending_xref_error ();
3789 finish_declspecs (specs
);
3791 declarator
= c_parser_declarator (parser
,
3792 specs
->typespec_kind
!= ctsk_none
,
3793 C_DTR_ABSTRACT
, &dummy
);
3794 if (declarator
== NULL
)
3796 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3798 ret
->declarator
= declarator
;
3802 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3805 assignment-expression
3806 { initializer-list }
3807 { initializer-list , }
3810 designation[opt] initializer
3811 initializer-list , designation[opt] initializer
3818 designator-list designator
3825 [ constant-expression ]
3837 [ constant-expression ... constant-expression ]
3839 Any expression without commas is accepted in the syntax for the
3840 constant-expressions, with non-constant expressions rejected later.
3842 This function is only used for top-level initializers; for nested
3843 ones, see c_parser_initval. */
3845 static struct c_expr
3846 c_parser_initializer (c_parser
*parser
)
3848 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3849 return c_parser_braced_init (parser
, NULL_TREE
, false);
3853 location_t loc
= c_parser_peek_token (parser
)->location
;
3854 ret
= c_parser_expr_no_commas (parser
, NULL
);
3855 if (TREE_CODE (ret
.value
) != STRING_CST
3856 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3857 ret
= default_function_array_read_conversion (loc
, ret
);
3862 /* Parse a braced initializer list. TYPE is the type specified for a
3863 compound literal, and NULL_TREE for other initializers and for
3864 nested braced lists. NESTED_P is true for nested braced lists,
3865 false for the list of a compound literal or the list that is the
3866 top-level initializer in a declaration. */
3868 static struct c_expr
3869 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3872 struct obstack braced_init_obstack
;
3873 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3874 gcc_obstack_init (&braced_init_obstack
);
3875 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3876 c_parser_consume_token (parser
);
3878 push_init_level (0, &braced_init_obstack
);
3880 really_start_incremental_init (type
);
3881 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3883 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3887 /* Parse a non-empty initializer list, possibly with a trailing
3891 c_parser_initelt (parser
, &braced_init_obstack
);
3894 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3895 c_parser_consume_token (parser
);
3898 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3902 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3904 ret
.value
= error_mark_node
;
3905 ret
.original_code
= ERROR_MARK
;
3906 ret
.original_type
= NULL
;
3907 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3908 pop_init_level (0, &braced_init_obstack
);
3909 obstack_free (&braced_init_obstack
, NULL
);
3912 c_parser_consume_token (parser
);
3913 ret
= pop_init_level (0, &braced_init_obstack
);
3914 obstack_free (&braced_init_obstack
, NULL
);
3918 /* Parse a nested initializer, including designators. */
3921 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3923 /* Parse any designator or designator list. A single array
3924 designator may have the subsequent "=" omitted in GNU C, but a
3925 longer list or a structure member designator may not. */
3926 if (c_parser_next_token_is (parser
, CPP_NAME
)
3927 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3929 /* Old-style structure member designator. */
3930 set_init_label (c_parser_peek_token (parser
)->value
,
3931 braced_init_obstack
);
3932 /* Use the colon as the error location. */
3933 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3934 "obsolete use of designated initializer with %<:%>");
3935 c_parser_consume_token (parser
);
3936 c_parser_consume_token (parser
);
3940 /* des_seen is 0 if there have been no designators, 1 if there
3941 has been a single array designator and 2 otherwise. */
3943 /* Location of a designator. */
3944 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3945 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3946 || c_parser_next_token_is (parser
, CPP_DOT
))
3948 int des_prev
= des_seen
;
3950 des_loc
= c_parser_peek_token (parser
)->location
;
3953 if (c_parser_next_token_is (parser
, CPP_DOT
))
3956 c_parser_consume_token (parser
);
3957 if (c_parser_next_token_is (parser
, CPP_NAME
))
3959 set_init_label (c_parser_peek_token (parser
)->value
,
3960 braced_init_obstack
);
3961 c_parser_consume_token (parser
);
3966 init
.value
= error_mark_node
;
3967 init
.original_code
= ERROR_MARK
;
3968 init
.original_type
= NULL
;
3969 c_parser_error (parser
, "expected identifier");
3970 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3971 process_init_element (init
, false, braced_init_obstack
);
3978 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3979 /* ??? Following the old parser, [ objc-receiver
3980 objc-message-args ] is accepted as an initializer,
3981 being distinguished from a designator by what follows
3982 the first assignment expression inside the square
3983 brackets, but after a first array designator a
3984 subsequent square bracket is for Objective-C taken to
3985 start an expression, using the obsolete form of
3986 designated initializer without '=', rather than
3987 possibly being a second level of designation: in LALR
3988 terms, the '[' is shifted rather than reducing
3989 designator to designator-list. */
3990 if (des_prev
== 1 && c_dialect_objc ())
3992 des_seen
= des_prev
;
3995 if (des_prev
== 0 && c_dialect_objc ())
3997 /* This might be an array designator or an
3998 Objective-C message expression. If the former,
3999 continue parsing here; if the latter, parse the
4000 remainder of the initializer given the starting
4001 primary-expression. ??? It might make sense to
4002 distinguish when des_prev == 1 as well; see
4003 previous comment. */
4005 struct c_expr mexpr
;
4006 c_parser_consume_token (parser
);
4007 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4008 && ((c_parser_peek_token (parser
)->id_kind
4010 || (c_parser_peek_token (parser
)->id_kind
4011 == C_ID_CLASSNAME
)))
4013 /* Type name receiver. */
4014 tree id
= c_parser_peek_token (parser
)->value
;
4015 c_parser_consume_token (parser
);
4016 rec
= objc_get_class_reference (id
);
4017 goto parse_message_args
;
4019 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4020 mark_exp_read (first
);
4021 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4022 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4023 goto array_desig_after_first
;
4024 /* Expression receiver. So far only one part
4025 without commas has been parsed; there might be
4026 more of the expression. */
4028 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4031 location_t comma_loc
, exp_loc
;
4032 comma_loc
= c_parser_peek_token (parser
)->location
;
4033 c_parser_consume_token (parser
);
4034 exp_loc
= c_parser_peek_token (parser
)->location
;
4035 next
= c_parser_expr_no_commas (parser
, NULL
);
4036 next
= default_function_array_read_conversion (exp_loc
,
4038 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4041 /* Now parse the objc-message-args. */
4042 args
= c_parser_objc_message_args (parser
);
4043 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4046 = objc_build_message_expr (rec
, args
);
4047 mexpr
.original_code
= ERROR_MARK
;
4048 mexpr
.original_type
= NULL
;
4049 /* Now parse and process the remainder of the
4050 initializer, starting with this message
4051 expression as a primary-expression. */
4052 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4055 c_parser_consume_token (parser
);
4056 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4057 mark_exp_read (first
);
4058 array_desig_after_first
:
4059 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4061 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4062 c_parser_consume_token (parser
);
4063 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4064 mark_exp_read (second
);
4068 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4070 c_parser_consume_token (parser
);
4071 set_init_index (first
, second
, braced_init_obstack
);
4073 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4074 "ISO C forbids specifying range of elements to initialize");
4077 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4083 if (c_parser_next_token_is (parser
, CPP_EQ
))
4086 pedwarn (des_loc
, OPT_Wpedantic
,
4087 "ISO C90 forbids specifying subobject to initialize");
4088 c_parser_consume_token (parser
);
4093 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4094 "obsolete use of designated initializer without %<=%>");
4098 init
.value
= error_mark_node
;
4099 init
.original_code
= ERROR_MARK
;
4100 init
.original_type
= NULL
;
4101 c_parser_error (parser
, "expected %<=%>");
4102 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4103 process_init_element (init
, false, braced_init_obstack
);
4109 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4112 /* Parse a nested initializer; as c_parser_initializer but parses
4113 initializers within braced lists, after any designators have been
4114 applied. If AFTER is not NULL then it is an Objective-C message
4115 expression which is the primary-expression starting the
4119 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4120 struct obstack
* braced_init_obstack
)
4123 gcc_assert (!after
|| c_dialect_objc ());
4124 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4125 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4128 location_t loc
= c_parser_peek_token (parser
)->location
;
4129 init
= c_parser_expr_no_commas (parser
, after
);
4130 if (init
.value
!= NULL_TREE
4131 && TREE_CODE (init
.value
) != STRING_CST
4132 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4133 init
= default_function_array_read_conversion (loc
, init
);
4135 process_init_element (init
, false, braced_init_obstack
);
4138 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4142 { block-item-list[opt] }
4143 { label-declarations block-item-list }
4147 block-item-list block-item
4159 { label-declarations block-item-list }
4162 __extension__ nested-declaration
4163 nested-function-definition
4167 label-declarations label-declaration
4170 __label__ identifier-list ;
4172 Allowing the mixing of declarations and code is new in C99. The
4173 GNU syntax also permits (not shown above) labels at the end of
4174 compound statements, which yield an error. We don't allow labels
4175 on declarations; this might seem like a natural extension, but
4176 there would be a conflict between attributes on the label and
4177 prefix attributes on the declaration. ??? The syntax follows the
4178 old parser in requiring something after label declarations.
4179 Although they are erroneous if the labels declared aren't defined,
4180 is it useful for the syntax to be this way?
4193 cancellation-point-directive */
4196 c_parser_compound_statement (c_parser
*parser
)
4199 location_t brace_loc
;
4200 brace_loc
= c_parser_peek_token (parser
)->location
;
4201 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4203 /* Ensure a scope is entered and left anyway to avoid confusion
4204 if we have just prepared to enter a function body. */
4205 stmt
= c_begin_compound_stmt (true);
4206 c_end_compound_stmt (brace_loc
, stmt
, true);
4207 return error_mark_node
;
4209 stmt
= c_begin_compound_stmt (true);
4210 c_parser_compound_statement_nostart (parser
);
4212 /* If the compound stmt contains array notations, then we expand them. */
4213 if (flag_enable_cilkplus
&& contains_array_notation_expr (stmt
))
4214 stmt
= expand_array_notation_exprs (stmt
);
4215 return c_end_compound_stmt (brace_loc
, stmt
, true);
4218 /* Parse a compound statement except for the opening brace. This is
4219 used for parsing both compound statements and statement expressions
4220 (which follow different paths to handling the opening). */
4223 c_parser_compound_statement_nostart (c_parser
*parser
)
4225 bool last_stmt
= false;
4226 bool last_label
= false;
4227 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4228 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4229 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4231 c_parser_consume_token (parser
);
4234 mark_valid_location_for_stdc_pragma (true);
4235 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4237 /* Read zero or more forward-declarations for labels that nested
4238 functions can jump to. */
4239 mark_valid_location_for_stdc_pragma (false);
4240 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4242 label_loc
= c_parser_peek_token (parser
)->location
;
4243 c_parser_consume_token (parser
);
4244 /* Any identifiers, including those declared as type names,
4249 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4251 c_parser_error (parser
, "expected identifier");
4255 = declare_label (c_parser_peek_token (parser
)->value
);
4256 C_DECLARED_LABEL_FLAG (label
) = 1;
4257 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4258 c_parser_consume_token (parser
);
4259 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4260 c_parser_consume_token (parser
);
4264 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4266 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4268 /* We must now have at least one statement, label or declaration. */
4269 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4271 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4272 c_parser_error (parser
, "expected declaration or statement");
4273 c_parser_consume_token (parser
);
4276 /* Process all #pragma's just after the opening brace. This
4277 handles #pragma upc, which can only appear just after
4278 the opening brace, when it appears within a function body. */
4279 push_upc_consistency_mode ();
4280 permit_pragma_upc ();
4281 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4283 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4284 if (c_parser_pragma (parser
, pragma_compound
))
4285 last_label
= false, last_stmt
= true;
4286 parser
->error
= false;
4289 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4291 location_t loc
= c_parser_peek_token (parser
)->location
;
4292 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4293 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4294 || (c_parser_next_token_is (parser
, CPP_NAME
)
4295 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4297 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4298 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4300 label_loc
= c_parser_peek_token (parser
)->location
;
4303 mark_valid_location_for_stdc_pragma (false);
4304 c_parser_label (parser
);
4306 else if (!last_label
4307 && c_parser_next_tokens_start_declaration (parser
))
4310 mark_valid_location_for_stdc_pragma (false);
4311 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4315 (pedantic
&& !flag_isoc99
)
4317 : OPT_Wdeclaration_after_statement
,
4318 "ISO C90 forbids mixed declarations and code");
4321 else if (!last_label
4322 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4324 /* __extension__ can start a declaration, but is also an
4325 unary operator that can start an expression. Consume all
4326 but the last of a possible series of __extension__ to
4328 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4329 && (c_parser_peek_2nd_token (parser
)->keyword
4331 c_parser_consume_token (parser
);
4332 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4335 ext
= disable_extension_diagnostics ();
4336 c_parser_consume_token (parser
);
4338 mark_valid_location_for_stdc_pragma (false);
4339 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4341 /* Following the old parser, __extension__ does not
4342 disable this diagnostic. */
4343 restore_extension_diagnostics (ext
);
4345 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4347 : OPT_Wdeclaration_after_statement
,
4348 "ISO C90 forbids mixed declarations and code");
4354 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4356 /* External pragmas, and some omp pragmas, are not associated
4357 with regular c code, and so are not to be considered statements
4358 syntactically. This ensures that the user doesn't put them
4359 places that would turn into syntax errors if the directive
4361 if (c_parser_pragma (parser
, pragma_compound
))
4362 last_label
= false, last_stmt
= true;
4364 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4366 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4367 c_parser_error (parser
, "expected declaration or statement");
4370 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4372 if (parser
->in_if_block
)
4374 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4375 error_at (loc
, """expected %<}%> before %<else%>");
4380 error_at (loc
, "%<else%> without a previous %<if%>");
4381 c_parser_consume_token (parser
);
4390 mark_valid_location_for_stdc_pragma (false);
4391 c_parser_statement_after_labels (parser
);
4394 parser
->error
= false;
4397 error_at (label_loc
, "label at end of compound statement");
4398 c_parser_consume_token (parser
);
4399 pop_upc_consistency_mode ();
4400 /* Restore the value we started with. */
4401 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4404 /* Parse a label (C90 6.6.1, C99 6.8.1).
4407 identifier : attributes[opt]
4408 case constant-expression :
4414 case constant-expression ... constant-expression :
4416 The use of attributes on labels is a GNU extension. The syntax in
4417 GNU C accepts any expressions without commas, non-constant
4418 expressions being rejected later. */
4421 c_parser_label (c_parser
*parser
)
4423 location_t loc1
= c_parser_peek_token (parser
)->location
;
4424 tree label
= NULL_TREE
;
4425 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4428 c_parser_consume_token (parser
);
4429 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4430 if (c_parser_next_token_is (parser
, CPP_COLON
))
4432 c_parser_consume_token (parser
);
4433 label
= do_case (loc1
, exp1
, NULL_TREE
);
4435 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4437 c_parser_consume_token (parser
);
4438 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4439 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4440 label
= do_case (loc1
, exp1
, exp2
);
4443 c_parser_error (parser
, "expected %<:%> or %<...%>");
4445 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4447 c_parser_consume_token (parser
);
4448 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4449 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4453 tree name
= c_parser_peek_token (parser
)->value
;
4456 location_t loc2
= c_parser_peek_token (parser
)->location
;
4457 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4458 c_parser_consume_token (parser
);
4459 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4460 c_parser_consume_token (parser
);
4461 attrs
= c_parser_attributes (parser
);
4462 tlab
= define_label (loc2
, name
);
4465 decl_attributes (&tlab
, attrs
, 0);
4466 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4471 if (c_parser_next_tokens_start_declaration (parser
))
4473 error_at (c_parser_peek_token (parser
)->location
,
4474 "a label can only be part of a statement and "
4475 "a declaration is not a statement");
4476 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4477 /*static_assert_ok*/ true,
4478 /*empty_ok*/ true, /*nested*/ true,
4479 /*start_attr_ok*/ true, NULL
,
4485 /* Parse a statement (C90 6.6, C99 6.8).
4490 expression-statement
4498 expression-statement:
4501 selection-statement:
4505 iteration-statement:
4514 return expression[opt] ;
4527 objc-throw-statement
4528 objc-try-catch-statement
4529 objc-synchronized-statement
4531 objc-throw-statement:
4547 parallel-for-construct
4548 parallel-for-simd-construct
4549 parallel-sections-construct
4556 parallel-directive structured-block
4559 for-directive iteration-statement
4562 simd-directive iteration-statements
4565 for-simd-directive iteration-statements
4568 sections-directive section-scope
4571 single-directive structured-block
4573 parallel-for-construct:
4574 parallel-for-directive iteration-statement
4576 parallel-for-simd-construct:
4577 parallel-for-simd-directive iteration-statement
4579 parallel-sections-construct:
4580 parallel-sections-directive section-scope
4583 master-directive structured-block
4586 critical-directive structured-block
4589 atomic-directive expression-statement
4592 ordered-directive structured-block
4594 Transactional Memory:
4597 transaction-statement
4598 transaction-cancel-statement
4602 c_parser_statement (c_parser
*parser
)
4604 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4605 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4606 || (c_parser_next_token_is (parser
, CPP_NAME
)
4607 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4608 c_parser_label (parser
);
4609 c_parser_statement_after_labels (parser
);
4612 /* Parse a statement, other than a labeled statement. */
4615 c_parser_statement_after_labels (c_parser
*parser
)
4617 location_t loc
= c_parser_peek_token (parser
)->location
;
4618 tree stmt
= NULL_TREE
;
4619 bool in_if_block
= parser
->in_if_block
;
4620 parser
->in_if_block
= false;
4621 switch (c_parser_peek_token (parser
)->type
)
4623 case CPP_OPEN_BRACE
:
4624 add_stmt (c_parser_compound_statement (parser
));
4627 switch (c_parser_peek_token (parser
)->keyword
)
4630 c_parser_if_statement (parser
);
4633 c_parser_switch_statement (parser
);
4636 c_parser_while_statement (parser
, false);
4639 c_parser_do_statement (parser
, false);
4642 c_parser_for_statement (parser
, false);
4645 c_parser_consume_token (parser
);
4646 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4647 if (!flag_enable_cilkplus
)
4648 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4650 add_stmt (build_cilk_sync ());
4653 c_parser_consume_token (parser
);
4654 if (c_parser_next_token_is (parser
, CPP_NAME
))
4656 stmt
= c_finish_goto_label (loc
,
4657 c_parser_peek_token (parser
)->value
);
4658 c_parser_consume_token (parser
);
4660 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4664 c_parser_consume_token (parser
);
4665 val
= c_parser_expression (parser
).value
;
4666 mark_exp_read (val
);
4667 stmt
= c_finish_goto_ptr (loc
, val
);
4670 c_parser_error (parser
, "expected identifier or %<*%>");
4671 goto expect_semicolon
;
4673 c_parser_consume_token (parser
);
4674 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4675 goto expect_semicolon
;
4677 c_parser_consume_token (parser
);
4678 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4679 goto expect_semicolon
;
4681 c_parser_consume_token (parser
);
4682 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4684 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4685 c_parser_consume_token (parser
);
4689 struct c_expr expr
= c_parser_expression_conv (parser
);
4690 mark_exp_read (expr
.value
);
4691 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4692 goto expect_semicolon
;
4696 stmt
= c_parser_asm_statement (parser
);
4698 case RID_TRANSACTION_ATOMIC
:
4699 case RID_TRANSACTION_RELAXED
:
4700 stmt
= c_parser_transaction (parser
,
4701 c_parser_peek_token (parser
)->keyword
);
4703 case RID_TRANSACTION_CANCEL
:
4704 stmt
= c_parser_transaction_cancel (parser
);
4705 goto expect_semicolon
;
4707 gcc_assert (c_dialect_objc ());
4708 c_parser_consume_token (parser
);
4709 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4711 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4712 c_parser_consume_token (parser
);
4716 tree expr
= c_parser_expression (parser
).value
;
4717 expr
= c_fully_fold (expr
, false, NULL
);
4718 stmt
= objc_build_throw_stmt (loc
, expr
);
4719 goto expect_semicolon
;
4723 gcc_assert (c_dialect_objc ());
4724 c_parser_objc_try_catch_finally_statement (parser
);
4726 case RID_AT_SYNCHRONIZED
:
4727 gcc_assert (c_dialect_objc ());
4728 c_parser_objc_synchronized_statement (parser
);
4730 case RID_UPC_FORALL
:
4731 gcc_assert (c_dialect_upc ());
4732 c_parser_upc_forall_statement (parser
);
4734 case RID_UPC_NOTIFY
:
4735 gcc_assert (c_dialect_upc ());
4736 c_parser_upc_sync_statement (parser
, UPC_SYNC_NOTIFY_OP
);
4737 goto expect_semicolon
;
4739 gcc_assert (c_dialect_upc ());
4740 c_parser_upc_sync_statement (parser
, UPC_SYNC_WAIT_OP
);
4741 goto expect_semicolon
;
4742 case RID_UPC_BARRIER
:
4743 gcc_assert (c_dialect_upc ());
4744 c_parser_upc_sync_statement (parser
, UPC_SYNC_BARRIER_OP
);
4745 goto expect_semicolon
;
4751 c_parser_consume_token (parser
);
4753 case CPP_CLOSE_PAREN
:
4754 case CPP_CLOSE_SQUARE
:
4755 /* Avoid infinite loop in error recovery:
4756 c_parser_skip_until_found stops at a closing nesting
4757 delimiter without consuming it, but here we need to consume
4758 it to proceed further. */
4759 c_parser_error (parser
, "expected statement");
4760 c_parser_consume_token (parser
);
4763 c_parser_pragma (parser
, pragma_stmt
);
4767 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4769 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4772 /* Two cases cannot and do not have line numbers associated: If stmt
4773 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4774 cannot hold line numbers. But that's OK because the statement
4775 will either be changed to a MODIFY_EXPR during gimplification of
4776 the statement expr, or discarded. If stmt was compound, but
4777 without new variables, we will have skipped the creation of a
4778 BIND and will have a bare STATEMENT_LIST. But that's OK because
4779 (recursively) all of the component statements should already have
4780 line numbers assigned. ??? Can we discard no-op statements
4782 if (CAN_HAVE_LOCATION_P (stmt
)
4783 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4784 SET_EXPR_LOCATION (stmt
, loc
);
4786 parser
->in_if_block
= in_if_block
;
4789 /* Parse the condition from an if, do, while or for statements. */
4792 c_parser_condition (c_parser
*parser
)
4794 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4796 cond
= c_parser_expression_conv (parser
).value
;
4797 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4798 cond
= c_fully_fold (cond
, false, NULL
);
4799 if (warn_sequence_point
)
4800 verify_sequence_points (cond
);
4804 /* Parse a parenthesized condition from an if, do or while statement.
4810 c_parser_paren_condition (c_parser
*parser
)
4813 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4814 return error_mark_node
;
4815 cond
= c_parser_condition (parser
);
4816 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4820 /* Parse a statement which is a block in C99. */
4823 c_parser_c99_block_statement (c_parser
*parser
)
4825 tree block
= c_begin_compound_stmt (flag_isoc99
);
4826 location_t loc
= c_parser_peek_token (parser
)->location
;
4827 c_parser_statement (parser
);
4828 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4831 /* Parse the body of an if statement. This is just parsing a
4832 statement but (a) it is a block in C99, (b) we track whether the
4833 body is an if statement for the sake of -Wparentheses warnings, (c)
4834 we handle an empty body specially for the sake of -Wempty-body
4835 warnings, and (d) we call parser_compound_statement directly
4836 because c_parser_statement_after_labels resets
4837 parser->in_if_block. */
4840 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4842 tree block
= c_begin_compound_stmt (flag_isoc99
);
4843 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4844 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4845 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4846 || (c_parser_next_token_is (parser
, CPP_NAME
)
4847 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4848 c_parser_label (parser
);
4849 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4850 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4852 location_t loc
= c_parser_peek_token (parser
)->location
;
4853 add_stmt (build_empty_stmt (loc
));
4854 c_parser_consume_token (parser
);
4855 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4856 warning_at (loc
, OPT_Wempty_body
,
4857 "suggest braces around empty body in an %<if%> statement");
4859 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4860 add_stmt (c_parser_compound_statement (parser
));
4862 c_parser_statement_after_labels (parser
);
4863 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4866 /* Parse the else body of an if statement. This is just parsing a
4867 statement but (a) it is a block in C99, (b) we handle an empty body
4868 specially for the sake of -Wempty-body warnings. */
4871 c_parser_else_body (c_parser
*parser
)
4873 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4874 tree block
= c_begin_compound_stmt (flag_isoc99
);
4875 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4876 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4877 || (c_parser_next_token_is (parser
, CPP_NAME
)
4878 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4879 c_parser_label (parser
);
4880 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4882 location_t loc
= c_parser_peek_token (parser
)->location
;
4885 "suggest braces around empty body in an %<else%> statement");
4886 add_stmt (build_empty_stmt (loc
));
4887 c_parser_consume_token (parser
);
4890 c_parser_statement_after_labels (parser
);
4891 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4894 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4897 if ( expression ) statement
4898 if ( expression ) statement else statement
4902 c_parser_if_statement (c_parser
*parser
)
4907 bool first_if
= false;
4908 tree first_body
, second_body
;
4912 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4913 c_parser_consume_token (parser
);
4914 block
= c_begin_compound_stmt (flag_isoc99
);
4915 loc
= c_parser_peek_token (parser
)->location
;
4916 cond
= c_parser_paren_condition (parser
);
4917 in_if_block
= parser
->in_if_block
;
4918 parser
->in_if_block
= true;
4919 first_body
= c_parser_if_body (parser
, &first_if
);
4920 parser
->in_if_block
= in_if_block
;
4921 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4923 c_parser_consume_token (parser
);
4924 second_body
= c_parser_else_body (parser
);
4927 second_body
= NULL_TREE
;
4928 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4929 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
4931 /* If the if statement contains array notations, then we expand them. */
4932 if (flag_enable_cilkplus
&& contains_array_notation_expr (if_stmt
))
4933 if_stmt
= fix_conditional_array_notations (if_stmt
);
4937 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4940 switch (expression) statement
4944 c_parser_switch_statement (c_parser
*parser
)
4946 tree block
, expr
, body
, save_break
;
4947 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4948 location_t switch_cond_loc
;
4949 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4950 c_parser_consume_token (parser
);
4951 block
= c_begin_compound_stmt (flag_isoc99
);
4952 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4954 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4955 expr
= c_parser_expression (parser
).value
;
4956 if (flag_enable_cilkplus
&& contains_array_notation_expr (expr
))
4958 error_at (switch_cond_loc
,
4959 "array notations cannot be used as a condition for switch "
4961 expr
= error_mark_node
;
4963 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4967 switch_cond_loc
= UNKNOWN_LOCATION
;
4968 expr
= error_mark_node
;
4970 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4971 save_break
= c_break_label
;
4972 c_break_label
= NULL_TREE
;
4973 body
= c_parser_c99_block_statement (parser
);
4974 c_finish_case (body
);
4977 location_t here
= c_parser_peek_token (parser
)->location
;
4978 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4979 SET_EXPR_LOCATION (t
, here
);
4982 c_break_label
= save_break
;
4983 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4986 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4989 while (expression) statement
4993 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
4995 tree block
, cond
, body
, save_break
, save_cont
;
4997 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4998 c_parser_consume_token (parser
);
4999 block
= c_begin_compound_stmt (flag_isoc99
);
5000 loc
= c_parser_peek_token (parser
)->location
;
5001 cond
= c_parser_paren_condition (parser
);
5002 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5004 error_at (loc
, "array notations cannot be used as a condition for while "
5006 cond
= error_mark_node
;
5009 if (ivdep
&& cond
!= error_mark_node
)
5010 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5011 build_int_cst (integer_type_node
,
5012 annot_expr_ivdep_kind
));
5013 save_break
= c_break_label
;
5014 c_break_label
= NULL_TREE
;
5015 save_cont
= c_cont_label
;
5016 c_cont_label
= NULL_TREE
;
5017 body
= c_parser_c99_block_statement (parser
);
5018 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5019 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5020 c_break_label
= save_break
;
5021 c_cont_label
= save_cont
;
5024 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5027 do statement while ( expression ) ;
5031 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5033 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5035 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5036 c_parser_consume_token (parser
);
5037 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5038 warning_at (c_parser_peek_token (parser
)->location
,
5040 "suggest braces around empty body in %<do%> statement");
5041 block
= c_begin_compound_stmt (flag_isoc99
);
5042 loc
= c_parser_peek_token (parser
)->location
;
5043 save_break
= c_break_label
;
5044 c_break_label
= NULL_TREE
;
5045 save_cont
= c_cont_label
;
5046 c_cont_label
= NULL_TREE
;
5047 body
= c_parser_c99_block_statement (parser
);
5048 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5049 new_break
= c_break_label
;
5050 c_break_label
= save_break
;
5051 new_cont
= c_cont_label
;
5052 c_cont_label
= save_cont
;
5053 cond
= c_parser_paren_condition (parser
);
5054 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5056 error_at (loc
, "array notations cannot be used as a condition for a "
5057 "do-while statement");
5058 cond
= error_mark_node
;
5060 if (ivdep
&& cond
!= error_mark_node
)
5061 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5062 build_int_cst (integer_type_node
,
5063 annot_expr_ivdep_kind
));
5064 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5065 c_parser_skip_to_end_of_block_or_statement (parser
);
5066 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5067 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5070 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5073 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5074 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5076 The form with a declaration is new in C99.
5078 ??? In accordance with the old parser, the declaration may be a
5079 nested function, which is then rejected in check_for_loop_decls,
5080 but does it make any sense for this to be included in the grammar?
5081 Note in particular that the nested function does not include a
5082 trailing ';', whereas the "declaration" production includes one.
5083 Also, can we reject bad declarations earlier and cheaper than
5084 check_for_loop_decls?
5086 In Objective-C, there are two additional variants:
5089 for ( expression in expresssion ) statement
5090 for ( declaration in expression ) statement
5092 This is inconsistent with C, because the second variant is allowed
5093 even if c99 is not enabled.
5095 The rest of the comment documents these Objective-C foreach-statement.
5097 Here is the canonical example of the first variant:
5098 for (object in array) { do something with object }
5099 we call the first expression ("object") the "object_expression" and
5100 the second expression ("array") the "collection_expression".
5101 object_expression must be an lvalue of type "id" (a generic Objective-C
5102 object) because the loop works by assigning to object_expression the
5103 various objects from the collection_expression. collection_expression
5104 must evaluate to something of type "id" which responds to the method
5105 countByEnumeratingWithState:objects:count:.
5107 The canonical example of the second variant is:
5108 for (id object in array) { do something with object }
5109 which is completely equivalent to
5112 for (object in array) { do something with object }
5114 Note that initizializing 'object' in some way (eg, "for ((object =
5115 xxx) in array) { do something with object }") is possibly
5116 technically valid, but completely pointless as 'object' will be
5117 assigned to something else as soon as the loop starts. We should
5118 most likely reject it (TODO).
5120 The beginning of the Objective-C foreach-statement looks exactly
5121 like the beginning of the for-statement, and we can tell it is a
5122 foreach-statement only because the initial declaration or
5123 expression is terminated by 'in' instead of ';'.
5127 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5129 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5130 /* The following are only used when parsing an ObjC foreach statement. */
5131 tree object_expression
;
5132 /* Silence the bogus uninitialized warning. */
5133 tree collection_expression
= NULL
;
5134 location_t loc
= c_parser_peek_token (parser
)->location
;
5135 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5136 bool is_foreach_statement
= false;
5137 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5138 c_parser_consume_token (parser
);
5139 /* Open a compound statement in Objective-C as well, just in case this is
5140 as foreach expression. */
5141 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5142 cond
= error_mark_node
;
5143 incr
= error_mark_node
;
5144 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5146 /* Parse the initialization declaration or expression. */
5147 object_expression
= error_mark_node
;
5148 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5149 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5151 parser
->objc_could_be_foreach_context
= false;
5152 c_parser_consume_token (parser
);
5153 c_finish_expr_stmt (loc
, NULL_TREE
);
5155 else if (c_parser_next_tokens_start_declaration (parser
))
5157 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5158 &object_expression
, vNULL
);
5159 parser
->objc_could_be_foreach_context
= false;
5161 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5163 c_parser_consume_token (parser
);
5164 is_foreach_statement
= true;
5165 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5166 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5169 check_for_loop_decls (for_loc
, flag_isoc99
);
5171 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5173 /* __extension__ can start a declaration, but is also an
5174 unary operator that can start an expression. Consume all
5175 but the last of a possible series of __extension__ to
5177 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5178 && (c_parser_peek_2nd_token (parser
)->keyword
5180 c_parser_consume_token (parser
);
5181 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5184 ext
= disable_extension_diagnostics ();
5185 c_parser_consume_token (parser
);
5186 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5187 true, &object_expression
, vNULL
);
5188 parser
->objc_could_be_foreach_context
= false;
5190 restore_extension_diagnostics (ext
);
5191 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5193 c_parser_consume_token (parser
);
5194 is_foreach_statement
= true;
5195 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5196 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5199 check_for_loop_decls (for_loc
, flag_isoc99
);
5208 tree init_expression
;
5209 init_expression
= c_parser_expression (parser
).value
;
5210 parser
->objc_could_be_foreach_context
= false;
5211 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5213 c_parser_consume_token (parser
);
5214 is_foreach_statement
= true;
5215 if (! lvalue_p (init_expression
))
5216 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5217 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5221 c_finish_expr_stmt (loc
, init_expression
);
5222 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5226 /* Parse the loop condition. In the case of a foreach
5227 statement, there is no loop condition. */
5228 gcc_assert (!parser
->objc_could_be_foreach_context
);
5229 if (!is_foreach_statement
)
5231 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5235 c_parser_error (parser
, "missing loop condition in loop with "
5236 "%<GCC ivdep%> pragma");
5237 cond
= error_mark_node
;
5241 c_parser_consume_token (parser
);
5247 cond
= c_parser_condition (parser
);
5248 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5250 error_at (loc
, "array notations cannot be used in a "
5251 "condition for a for-loop");
5252 cond
= error_mark_node
;
5254 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5257 if (ivdep
&& cond
!= error_mark_node
)
5258 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5259 build_int_cst (integer_type_node
,
5260 annot_expr_ivdep_kind
));
5262 /* Parse the increment expression (the third expression in a
5263 for-statement). In the case of a foreach-statement, this is
5264 the expression that follows the 'in'. */
5265 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5267 if (is_foreach_statement
)
5269 c_parser_error (parser
, "missing collection in fast enumeration");
5270 collection_expression
= error_mark_node
;
5273 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5277 if (is_foreach_statement
)
5278 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5281 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5283 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5285 save_break
= c_break_label
;
5286 c_break_label
= NULL_TREE
;
5287 save_cont
= c_cont_label
;
5288 c_cont_label
= NULL_TREE
;
5289 body
= c_parser_c99_block_statement (parser
);
5290 if (is_foreach_statement
)
5291 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5293 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5294 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5295 c_break_label
= save_break
;
5296 c_cont_label
= save_cont
;
5299 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5300 statement with inputs, outputs, clobbers, and volatile tag
5304 asm type-qualifier[opt] ( asm-argument ) ;
5305 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5309 asm-string-literal : asm-operands[opt]
5310 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5311 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5314 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5317 Qualifiers other than volatile are accepted in the syntax but
5321 c_parser_asm_statement (c_parser
*parser
)
5323 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5324 bool simple
, is_goto
;
5325 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5326 int section
, nsections
;
5328 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5329 c_parser_consume_token (parser
);
5330 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5332 quals
= c_parser_peek_token (parser
)->value
;
5333 c_parser_consume_token (parser
);
5335 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5336 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5338 warning_at (c_parser_peek_token (parser
)->location
,
5340 "%E qualifier ignored on asm",
5341 c_parser_peek_token (parser
)->value
);
5343 c_parser_consume_token (parser
);
5349 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5351 c_parser_consume_token (parser
);
5355 /* ??? Follow the C++ parser rather than using the
5356 lex_untranslated_string kludge. */
5357 parser
->lex_untranslated_string
= true;
5360 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5363 str
= c_parser_asm_string_literal (parser
);
5364 if (str
== NULL_TREE
)
5365 goto error_close_paren
;
5368 outputs
= NULL_TREE
;
5370 clobbers
= NULL_TREE
;
5373 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5376 /* Parse each colon-delimited section of operands. */
5377 nsections
= 3 + is_goto
;
5378 for (section
= 0; section
< nsections
; ++section
)
5380 if (!c_parser_require (parser
, CPP_COLON
,
5383 : "expected %<:%> or %<)%>"))
5384 goto error_close_paren
;
5386 /* Once past any colon, we're no longer a simple asm. */
5389 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5390 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5395 /* For asm goto, we don't allow output operands, but reserve
5396 the slot for a future extension that does allow them. */
5398 outputs
= c_parser_asm_operands (parser
);
5401 inputs
= c_parser_asm_operands (parser
);
5404 clobbers
= c_parser_asm_clobbers (parser
);
5407 labels
= c_parser_asm_goto_operands (parser
);
5413 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5418 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5420 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5424 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5425 c_parser_skip_to_end_of_block_or_statement (parser
);
5427 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5428 clobbers
, labels
, simple
));
5431 parser
->lex_untranslated_string
= false;
5435 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5439 /* Parse asm operands, a GNU extension.
5443 asm-operands , asm-operand
5446 asm-string-literal ( expression )
5447 [ identifier ] asm-string-literal ( expression )
5451 c_parser_asm_operands (c_parser
*parser
)
5453 tree list
= NULL_TREE
;
5458 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5460 c_parser_consume_token (parser
);
5461 if (c_parser_next_token_is (parser
, CPP_NAME
))
5463 tree id
= c_parser_peek_token (parser
)->value
;
5464 c_parser_consume_token (parser
);
5465 name
= build_string (IDENTIFIER_LENGTH (id
),
5466 IDENTIFIER_POINTER (id
));
5470 c_parser_error (parser
, "expected identifier");
5471 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5474 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5479 str
= c_parser_asm_string_literal (parser
);
5480 if (str
== NULL_TREE
)
5482 parser
->lex_untranslated_string
= false;
5483 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5485 parser
->lex_untranslated_string
= true;
5488 expr
= c_parser_expression (parser
);
5489 mark_exp_read (expr
.value
);
5490 parser
->lex_untranslated_string
= true;
5491 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5493 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5496 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5498 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5499 c_parser_consume_token (parser
);
5506 /* Parse asm clobbers, a GNU extension.
5510 asm-clobbers , asm-string-literal
5514 c_parser_asm_clobbers (c_parser
*parser
)
5516 tree list
= NULL_TREE
;
5519 tree str
= c_parser_asm_string_literal (parser
);
5521 list
= tree_cons (NULL_TREE
, str
, list
);
5524 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5525 c_parser_consume_token (parser
);
5532 /* Parse asm goto labels, a GNU extension.
5536 asm-goto-operands , identifier
5540 c_parser_asm_goto_operands (c_parser
*parser
)
5542 tree list
= NULL_TREE
;
5547 if (c_parser_next_token_is (parser
, CPP_NAME
))
5549 c_token
*tok
= c_parser_peek_token (parser
);
5551 label
= lookup_label_for_goto (tok
->location
, name
);
5552 c_parser_consume_token (parser
);
5553 TREE_USED (label
) = 1;
5557 c_parser_error (parser
, "expected identifier");
5561 name
= build_string (IDENTIFIER_LENGTH (name
),
5562 IDENTIFIER_POINTER (name
));
5563 list
= tree_cons (name
, label
, list
);
5564 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5565 c_parser_consume_token (parser
);
5567 return nreverse (list
);
5571 /* Parse an expression other than a compound expression; that is, an
5572 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5573 NULL then it is an Objective-C message expression which is the
5574 primary-expression starting the expression as an initializer.
5576 assignment-expression:
5577 conditional-expression
5578 unary-expression assignment-operator assignment-expression
5580 assignment-operator: one of
5581 = *= /= %= += -= <<= >>= &= ^= |=
5583 In GNU C we accept any conditional expression on the LHS and
5584 diagnose the invalid lvalue rather than producing a syntax
5587 static struct c_expr
5588 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5589 tree omp_atomic_lhs
)
5591 struct c_expr lhs
, rhs
, ret
;
5592 enum tree_code code
;
5593 location_t op_location
, exp_location
;
5594 gcc_assert (!after
|| c_dialect_objc ());
5595 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5596 op_location
= c_parser_peek_token (parser
)->location
;
5597 switch (c_parser_peek_token (parser
)->type
)
5606 code
= TRUNC_DIV_EXPR
;
5609 code
= TRUNC_MOD_EXPR
;
5624 code
= BIT_AND_EXPR
;
5627 code
= BIT_XOR_EXPR
;
5630 code
= BIT_IOR_EXPR
;
5635 c_parser_consume_token (parser
);
5636 exp_location
= c_parser_peek_token (parser
)->location
;
5637 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5638 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5640 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5641 code
, exp_location
, rhs
.value
,
5643 if (code
== NOP_EXPR
)
5644 ret
.original_code
= MODIFY_EXPR
;
5647 TREE_NO_WARNING (ret
.value
) = 1;
5648 ret
.original_code
= ERROR_MARK
;
5650 ret
.original_type
= NULL
;
5654 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5655 is not NULL then it is an Objective-C message expression which is
5656 the primary-expression starting the expression as an initializer.
5658 conditional-expression:
5659 logical-OR-expression
5660 logical-OR-expression ? expression : conditional-expression
5664 conditional-expression:
5665 logical-OR-expression ? : conditional-expression
5668 static struct c_expr
5669 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5670 tree omp_atomic_lhs
)
5672 struct c_expr cond
, exp1
, exp2
, ret
;
5673 location_t cond_loc
, colon_loc
, middle_loc
;
5675 gcc_assert (!after
|| c_dialect_objc ());
5677 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5679 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5681 cond_loc
= c_parser_peek_token (parser
)->location
;
5682 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5683 c_parser_consume_token (parser
);
5684 if (c_parser_next_token_is (parser
, CPP_COLON
))
5686 tree eptype
= NULL_TREE
;
5688 middle_loc
= c_parser_peek_token (parser
)->location
;
5689 pedwarn (middle_loc
, OPT_Wpedantic
,
5690 "ISO C forbids omitting the middle term of a ?: expression");
5691 warn_for_omitted_condop (middle_loc
, cond
.value
);
5692 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5694 eptype
= TREE_TYPE (cond
.value
);
5695 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5697 /* Make sure first operand is calculated only once. */
5698 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5700 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5701 exp1
.original_type
= NULL
;
5702 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5703 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5708 = c_objc_common_truthvalue_conversion
5709 (cond_loc
, default_conversion (cond
.value
));
5710 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5711 exp1
= c_parser_expression_conv (parser
);
5712 mark_exp_read (exp1
.value
);
5713 c_inhibit_evaluation_warnings
+=
5714 ((cond
.value
== truthvalue_true_node
)
5715 - (cond
.value
== truthvalue_false_node
));
5718 colon_loc
= c_parser_peek_token (parser
)->location
;
5719 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5721 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5722 ret
.value
= error_mark_node
;
5723 ret
.original_code
= ERROR_MARK
;
5724 ret
.original_type
= NULL
;
5728 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5729 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5730 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5732 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5733 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5734 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5735 exp1
.value
, exp1
.original_type
,
5736 exp2
.value
, exp2
.original_type
);
5737 ret
.original_code
= ERROR_MARK
;
5738 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5739 ret
.original_type
= NULL
;
5744 /* If both sides are enum type, the default conversion will have
5745 made the type of the result be an integer type. We want to
5746 remember the enum types we started with. */
5747 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5748 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5749 ret
.original_type
= ((t1
!= error_mark_node
5750 && t2
!= error_mark_node
5751 && (TYPE_MAIN_VARIANT (t1
)
5752 == TYPE_MAIN_VARIANT (t2
)))
5759 /* Parse a binary expression; that is, a logical-OR-expression (C90
5760 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5761 an Objective-C message expression which is the primary-expression
5762 starting the expression as an initializer.
5764 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
5765 when it should be the unfolded lhs. In a valid OpenMP source,
5766 one of the operands of the toplevel binary expression must be equal
5767 to it. In that case, just return a build2 created binary operation
5768 rather than result of parser_build_binary_op.
5770 multiplicative-expression:
5772 multiplicative-expression * cast-expression
5773 multiplicative-expression / cast-expression
5774 multiplicative-expression % cast-expression
5776 additive-expression:
5777 multiplicative-expression
5778 additive-expression + multiplicative-expression
5779 additive-expression - multiplicative-expression
5783 shift-expression << additive-expression
5784 shift-expression >> additive-expression
5786 relational-expression:
5788 relational-expression < shift-expression
5789 relational-expression > shift-expression
5790 relational-expression <= shift-expression
5791 relational-expression >= shift-expression
5793 equality-expression:
5794 relational-expression
5795 equality-expression == relational-expression
5796 equality-expression != relational-expression
5800 AND-expression & equality-expression
5802 exclusive-OR-expression:
5804 exclusive-OR-expression ^ AND-expression
5806 inclusive-OR-expression:
5807 exclusive-OR-expression
5808 inclusive-OR-expression | exclusive-OR-expression
5810 logical-AND-expression:
5811 inclusive-OR-expression
5812 logical-AND-expression && inclusive-OR-expression
5814 logical-OR-expression:
5815 logical-AND-expression
5816 logical-OR-expression || logical-AND-expression
5819 static struct c_expr
5820 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5821 tree omp_atomic_lhs
)
5823 /* A binary expression is parsed using operator-precedence parsing,
5824 with the operands being cast expressions. All the binary
5825 operators are left-associative. Thus a binary expression is of
5828 E0 op1 E1 op2 E2 ...
5830 which we represent on a stack. On the stack, the precedence
5831 levels are strictly increasing. When a new operator is
5832 encountered of higher precedence than that at the top of the
5833 stack, it is pushed; its LHS is the top expression, and its RHS
5834 is everything parsed until it is popped. When a new operator is
5835 encountered with precedence less than or equal to that at the top
5836 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5837 by the result of the operation until the operator at the top of
5838 the stack has lower precedence than the new operator or there is
5839 only one element on the stack; then the top expression is the LHS
5840 of the new operator. In the case of logical AND and OR
5841 expressions, we also need to adjust c_inhibit_evaluation_warnings
5842 as appropriate when the operators are pushed and popped. */
5845 /* The expression at this stack level. */
5847 /* The precedence of the operator on its left, PREC_NONE at the
5848 bottom of the stack. */
5849 enum c_parser_prec prec
;
5850 /* The operation on its left. */
5852 /* The source location of this operation. */
5856 /* Location of the binary operator. */
5857 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5860 switch (stack[sp].op) \
5862 case TRUTH_ANDIF_EXPR: \
5863 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5864 == truthvalue_false_node); \
5866 case TRUTH_ORIF_EXPR: \
5867 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5868 == truthvalue_true_node); \
5873 stack[sp - 1].expr \
5874 = default_function_array_read_conversion (stack[sp - 1].loc, \
5875 stack[sp - 1].expr); \
5877 = default_function_array_read_conversion (stack[sp].loc, \
5879 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
5880 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
5881 && ((1 << stack[sp].prec) \
5882 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
5883 | PREC_ADD | PREC_MULT))) \
5884 && stack[sp].op != TRUNC_MOD_EXPR \
5885 && stack[0].expr.value != error_mark_node \
5886 && stack[1].expr.value != error_mark_node \
5887 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
5888 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
5889 stack[0].expr.value \
5890 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
5891 stack[0].expr.value, stack[1].expr.value); \
5893 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5895 stack[sp - 1].expr, \
5899 gcc_assert (!after
|| c_dialect_objc ());
5900 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5901 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5902 stack
[0].prec
= PREC_NONE
;
5906 enum c_parser_prec oprec
;
5907 enum tree_code ocode
;
5910 switch (c_parser_peek_token (parser
)->type
)
5918 ocode
= TRUNC_DIV_EXPR
;
5922 ocode
= TRUNC_MOD_EXPR
;
5934 ocode
= LSHIFT_EXPR
;
5938 ocode
= RSHIFT_EXPR
;
5952 case CPP_GREATER_EQ
:
5965 oprec
= PREC_BITAND
;
5966 ocode
= BIT_AND_EXPR
;
5969 oprec
= PREC_BITXOR
;
5970 ocode
= BIT_XOR_EXPR
;
5974 ocode
= BIT_IOR_EXPR
;
5977 oprec
= PREC_LOGAND
;
5978 ocode
= TRUTH_ANDIF_EXPR
;
5982 ocode
= TRUTH_ORIF_EXPR
;
5985 /* Not a binary operator, so end of the binary
5989 binary_loc
= c_parser_peek_token (parser
)->location
;
5990 while (oprec
<= stack
[sp
].prec
)
5992 c_parser_consume_token (parser
);
5995 case TRUTH_ANDIF_EXPR
:
5997 = default_function_array_read_conversion (stack
[sp
].loc
,
5999 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6000 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6001 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6002 == truthvalue_false_node
);
6004 case TRUTH_ORIF_EXPR
:
6006 = default_function_array_read_conversion (stack
[sp
].loc
,
6008 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6009 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6010 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6011 == truthvalue_true_node
);
6017 stack
[sp
].loc
= binary_loc
;
6018 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6019 stack
[sp
].prec
= oprec
;
6020 stack
[sp
].op
= ocode
;
6021 stack
[sp
].loc
= binary_loc
;
6026 return stack
[0].expr
;
6030 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6031 NULL then it is an Objective-C message expression which is the
6032 primary-expression starting the expression as an initializer.
6036 ( type-name ) unary-expression
6039 static struct c_expr
6040 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6042 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6043 gcc_assert (!after
|| c_dialect_objc ());
6045 return c_parser_postfix_expression_after_primary (parser
,
6047 /* If the expression begins with a parenthesized type name, it may
6048 be either a cast or a compound literal; we need to see whether
6049 the next character is '{' to tell the difference. If not, it is
6050 an unary expression. Full detection of unknown typenames here
6051 would require a 3-token lookahead. */
6052 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6053 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6055 struct c_type_name
*type_name
;
6058 c_parser_consume_token (parser
);
6059 type_name
= c_parser_type_name (parser
);
6060 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6061 if (type_name
== NULL
)
6063 ret
.value
= error_mark_node
;
6064 ret
.original_code
= ERROR_MARK
;
6065 ret
.original_type
= NULL
;
6069 /* Save casted types in the function's used types hash table. */
6070 used_types_insert (type_name
->specs
->type
);
6072 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6073 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6076 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6077 expr
= c_parser_cast_expression (parser
, NULL
);
6078 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6080 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6081 ret
.original_code
= ERROR_MARK
;
6082 ret
.original_type
= NULL
;
6086 return c_parser_unary_expression (parser
);
6089 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6095 unary-operator cast-expression
6096 sizeof unary-expression
6097 sizeof ( type-name )
6099 unary-operator: one of
6105 __alignof__ unary-expression
6106 __alignof__ ( type-name )
6109 (C11 permits _Alignof with type names only.)
6111 unary-operator: one of
6112 __extension__ __real__ __imag__
6114 Transactional Memory:
6117 transaction-expression
6119 In addition, the GNU syntax treats ++ and -- as unary operators, so
6120 they may be applied to cast expressions with errors for non-lvalues
6123 static struct c_expr
6124 c_parser_unary_expression (c_parser
*parser
)
6127 struct c_expr ret
, op
;
6128 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6130 ret
.original_code
= ERROR_MARK
;
6131 ret
.original_type
= NULL
;
6132 switch (c_parser_peek_token (parser
)->type
)
6135 c_parser_consume_token (parser
);
6136 exp_loc
= c_parser_peek_token (parser
)->location
;
6137 op
= c_parser_cast_expression (parser
, NULL
);
6139 /* If there is array notations in op, we expand them. */
6140 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6141 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6144 op
= default_function_array_read_conversion (exp_loc
, op
);
6145 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6147 case CPP_MINUS_MINUS
:
6148 c_parser_consume_token (parser
);
6149 exp_loc
= c_parser_peek_token (parser
)->location
;
6150 op
= c_parser_cast_expression (parser
, NULL
);
6152 /* If there is array notations in op, we expand them. */
6153 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6154 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6157 op
= default_function_array_read_conversion (exp_loc
, op
);
6158 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6161 c_parser_consume_token (parser
);
6162 op
= c_parser_cast_expression (parser
, NULL
);
6163 mark_exp_read (op
.value
);
6164 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6166 c_parser_consume_token (parser
);
6167 exp_loc
= c_parser_peek_token (parser
)->location
;
6168 op
= c_parser_cast_expression (parser
, NULL
);
6169 op
= default_function_array_read_conversion (exp_loc
, op
);
6170 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6173 if (!c_dialect_objc () && !in_system_header
)
6176 "traditional C rejects the unary plus operator");
6177 c_parser_consume_token (parser
);
6178 exp_loc
= c_parser_peek_token (parser
)->location
;
6179 op
= c_parser_cast_expression (parser
, NULL
);
6180 op
= default_function_array_read_conversion (exp_loc
, op
);
6181 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6183 c_parser_consume_token (parser
);
6184 exp_loc
= c_parser_peek_token (parser
)->location
;
6185 op
= c_parser_cast_expression (parser
, NULL
);
6186 op
= default_function_array_read_conversion (exp_loc
, op
);
6187 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6189 c_parser_consume_token (parser
);
6190 exp_loc
= c_parser_peek_token (parser
)->location
;
6191 op
= c_parser_cast_expression (parser
, NULL
);
6192 op
= default_function_array_read_conversion (exp_loc
, op
);
6193 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6195 c_parser_consume_token (parser
);
6196 exp_loc
= c_parser_peek_token (parser
)->location
;
6197 op
= c_parser_cast_expression (parser
, NULL
);
6198 op
= default_function_array_read_conversion (exp_loc
, op
);
6199 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6201 /* Refer to the address of a label as a pointer. */
6202 c_parser_consume_token (parser
);
6203 if (c_parser_next_token_is (parser
, CPP_NAME
))
6205 ret
.value
= finish_label_address_expr
6206 (c_parser_peek_token (parser
)->value
, op_loc
);
6207 c_parser_consume_token (parser
);
6211 c_parser_error (parser
, "expected identifier");
6212 ret
.value
= error_mark_node
;
6216 switch (c_parser_peek_token (parser
)->keyword
)
6219 return c_parser_sizeof_expression (parser
);
6220 case RID_UPC_BLOCKSIZEOF
:
6221 case RID_UPC_ELEMSIZEOF
:
6222 case RID_UPC_LOCALSIZEOF
:
6223 gcc_assert (c_dialect_upc ());
6224 return c_parser_sizeof_expression (parser
);
6226 return c_parser_alignof_expression (parser
);
6228 c_parser_consume_token (parser
);
6229 ext
= disable_extension_diagnostics ();
6230 ret
= c_parser_cast_expression (parser
, NULL
);
6231 restore_extension_diagnostics (ext
);
6234 c_parser_consume_token (parser
);
6235 exp_loc
= c_parser_peek_token (parser
)->location
;
6236 op
= c_parser_cast_expression (parser
, NULL
);
6237 op
= default_function_array_conversion (exp_loc
, op
);
6238 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6240 c_parser_consume_token (parser
);
6241 exp_loc
= c_parser_peek_token (parser
)->location
;
6242 op
= c_parser_cast_expression (parser
, NULL
);
6243 op
= default_function_array_conversion (exp_loc
, op
);
6244 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6245 case RID_TRANSACTION_ATOMIC
:
6246 case RID_TRANSACTION_RELAXED
:
6247 return c_parser_transaction_expression (parser
,
6248 c_parser_peek_token (parser
)->keyword
);
6250 return c_parser_postfix_expression (parser
);
6253 return c_parser_postfix_expression (parser
);
6257 /* Return the result of upc_blocksizeof applied to EXPR. */
6261 upc_blocksizeof_expr (location_t loc
, struct c_expr expr
)
6264 ret
.original_code
= ERROR_MARK
;
6265 ret
.original_type
= NULL_TREE
;
6266 if (expr
.value
== error_mark_node
)
6268 ret
.value
= error_mark_node
;
6269 pop_maybe_used (false);
6273 ret
.value
= upc_blocksizeof (loc
, TREE_TYPE (expr
.value
));
6274 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6279 /* Return the result of upc_blocksizeof applied to T, a structure
6280 for the type name passed to sizeof (rather than the type itself). */
6284 upc_blocksizeof_type (location_t loc
, struct c_type_name
*t
)
6288 ret
.original_code
= ERROR_MARK
;
6289 ret
.original_type
= NULL_TREE
;
6290 type
= groktypename (t
, NULL
, NULL
);
6291 if (type
== error_mark_node
)
6293 ret
.value
= error_mark_node
;
6294 pop_maybe_used (false);
6298 ret
.value
= upc_blocksizeof (loc
, type
);
6299 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6304 /* Return the result of upc_elemsizeof applied to EXPR. */
6308 upc_elemsizeof_expr (location_t loc
, struct c_expr expr
)
6311 ret
.original_code
= ERROR_MARK
;
6312 ret
.original_type
= NULL_TREE
;
6313 if (expr
.value
== error_mark_node
)
6315 ret
.value
= error_mark_node
;
6316 pop_maybe_used (false);
6320 ret
.value
= upc_elemsizeof (loc
, TREE_TYPE (expr
.value
));
6321 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6326 /* Return the result of upc_elemsizeof applied to T, a structure
6327 for the type name passed to sizeof (rather than the type itself). */
6331 upc_elemsizeof_type (location_t loc
, struct c_type_name
*t
)
6335 ret
.original_code
= ERROR_MARK
;
6336 ret
.original_type
= NULL_TREE
;
6337 type
= groktypename (t
, NULL
, NULL
);
6338 if (type
== error_mark_node
)
6340 ret
.value
= error_mark_node
;
6341 pop_maybe_used (false);
6345 ret
.value
= upc_elemsizeof (loc
, type
);
6346 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6351 /* Return the result of upc_localsizeof applied to EXPR. */
6355 upc_localsizeof_expr (location_t loc
, struct c_expr expr
)
6358 ret
.original_code
= ERROR_MARK
;
6359 ret
.original_type
= NULL_TREE
;
6360 if (expr
.value
== error_mark_node
)
6362 ret
.value
= error_mark_node
;
6363 pop_maybe_used (false);
6367 ret
.value
= upc_localsizeof (loc
, TREE_TYPE (expr
.value
));
6368 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6373 /* Return the result of upc_localsizeof applied to T, a structure
6374 for the type name passed to sizeof (rather than the type itself). */
6378 upc_localsizeof_type (location_t loc
, struct c_type_name
*t
)
6382 ret
.original_code
= ERROR_MARK
;
6383 ret
.original_type
= NULL_TREE
;
6384 type
= groktypename (t
, NULL
, NULL
);
6385 if (type
== error_mark_node
)
6387 ret
.value
= error_mark_node
;
6388 pop_maybe_used (false);
6392 ret
.value
= upc_localsizeof (loc
, type
);
6393 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6398 /* Parse a sizeof expression. */
6400 static struct c_expr
6401 c_parser_sizeof_expression (c_parser
*parser
)
6404 location_t expr_loc
;
6405 enum rid keyword
= c_parser_peek_token (parser
)->keyword
;
6406 c_parser_consume_token (parser
);
6407 c_inhibit_evaluation_warnings
++;
6409 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6410 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6412 /* Either sizeof ( type-name ) or sizeof unary-expression
6413 starting with a compound literal. */
6414 struct c_type_name
*type_name
;
6415 c_parser_consume_token (parser
);
6416 expr_loc
= c_parser_peek_token (parser
)->location
;
6417 type_name
= c_parser_type_name (parser
);
6418 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6419 if (type_name
== NULL
)
6422 c_inhibit_evaluation_warnings
--;
6424 ret
.value
= error_mark_node
;
6425 ret
.original_code
= ERROR_MARK
;
6426 ret
.original_type
= NULL
;
6429 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6431 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6436 /* sizeof ( type-name ). */
6437 c_inhibit_evaluation_warnings
--;
6439 /* Handle upc_*_sizeof (type) operations. */
6442 case RID_UPC_BLOCKSIZEOF
:
6443 return upc_blocksizeof_type (expr_loc
, type_name
);
6444 case RID_UPC_ELEMSIZEOF
:
6445 return upc_elemsizeof_type (expr_loc
, type_name
);
6446 case RID_UPC_LOCALSIZEOF
:
6447 return upc_localsizeof_type (expr_loc
, type_name
);
6450 return c_expr_sizeof_type (expr_loc
, type_name
);
6454 expr_loc
= c_parser_peek_token (parser
)->location
;
6455 expr
= c_parser_unary_expression (parser
);
6457 c_inhibit_evaluation_warnings
--;
6459 mark_exp_read (expr
.value
);
6460 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6461 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6462 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6463 /* Handle upc_*_sizeof (expr) operations. */
6466 case RID_UPC_BLOCKSIZEOF
:
6467 return upc_blocksizeof_expr (expr_loc
, expr
);
6468 case RID_UPC_ELEMSIZEOF
:
6469 return upc_elemsizeof_expr (expr_loc
, expr
);
6470 case RID_UPC_LOCALSIZEOF
:
6471 return upc_localsizeof_expr (expr_loc
, expr
);
6473 return c_expr_sizeof_expr (expr_loc
, expr
);
6476 return c_expr_sizeof_expr (expr_loc
, expr
);
6480 /* Parse an alignof expression. */
6482 static struct c_expr
6483 c_parser_alignof_expression (c_parser
*parser
)
6486 location_t loc
= c_parser_peek_token (parser
)->location
;
6487 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6488 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6489 /* A diagnostic is not required for the use of this identifier in
6490 the implementation namespace; only diagnose it for the C11
6491 spelling because of existing code using the other spellings. */
6493 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6496 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6499 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6502 c_parser_consume_token (parser
);
6503 c_inhibit_evaluation_warnings
++;
6505 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6506 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6508 /* Either __alignof__ ( type-name ) or __alignof__
6509 unary-expression starting with a compound literal. */
6511 struct c_type_name
*type_name
;
6513 c_parser_consume_token (parser
);
6514 loc
= c_parser_peek_token (parser
)->location
;
6515 type_name
= c_parser_type_name (parser
);
6516 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6517 if (type_name
== NULL
)
6520 c_inhibit_evaluation_warnings
--;
6522 ret
.value
= error_mark_node
;
6523 ret
.original_code
= ERROR_MARK
;
6524 ret
.original_type
= NULL
;
6527 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6529 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6534 /* alignof ( type-name ). */
6535 c_inhibit_evaluation_warnings
--;
6537 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6538 ret
.original_code
= ERROR_MARK
;
6539 ret
.original_type
= NULL
;
6545 expr
= c_parser_unary_expression (parser
);
6547 mark_exp_read (expr
.value
);
6548 c_inhibit_evaluation_warnings
--;
6550 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6552 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6553 ret
.original_code
= ERROR_MARK
;
6554 ret
.original_type
= NULL
;
6559 /* Helper function to read arguments of builtins which are interfaces
6560 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6561 others. The name of the builtin is passed using BNAME parameter.
6562 Function returns true if there were no errors while parsing and
6563 stores the arguments in CEXPR_LIST. */
6565 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6566 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6569 location_t loc
= c_parser_peek_token (parser
)->location
;
6570 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6572 bool saved_force_folding_builtin_constant_p
;
6574 *ret_cexpr_list
= NULL
;
6575 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6577 error_at (loc
, "cannot take address of %qs", bname
);
6581 c_parser_consume_token (parser
);
6583 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6585 c_parser_consume_token (parser
);
6589 saved_force_folding_builtin_constant_p
6590 = force_folding_builtin_constant_p
;
6591 force_folding_builtin_constant_p
|= choose_expr_p
;
6592 expr
= c_parser_expr_no_commas (parser
, NULL
);
6593 force_folding_builtin_constant_p
6594 = saved_force_folding_builtin_constant_p
;
6595 vec_alloc (cexpr_list
, 1);
6596 C_EXPR_APPEND (cexpr_list
, expr
);
6597 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6599 c_parser_consume_token (parser
);
6600 expr
= c_parser_expr_no_commas (parser
, NULL
);
6601 C_EXPR_APPEND (cexpr_list
, expr
);
6604 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6607 *ret_cexpr_list
= cexpr_list
;
6611 /* This represents a single generic-association. */
6613 struct c_generic_association
6615 /* The location of the starting token of the type. */
6616 location_t type_location
;
6617 /* The association's type, or NULL_TREE for 'default'. */
6619 /* The association's expression. */
6620 struct c_expr expression
;
6623 /* Parse a generic-selection. (C11 6.5.1.1).
6626 _Generic ( assignment-expression , generic-assoc-list )
6630 generic-assoc-list , generic-association
6632 generic-association:
6633 type-name : assignment-expression
6634 default : assignment-expression
6637 static struct c_expr
6638 c_parser_generic_selection (c_parser
*parser
)
6640 vec
<c_generic_association
> associations
= vNULL
;
6641 struct c_expr selector
, error_expr
;
6643 struct c_generic_association matched_assoc
;
6644 bool match_found
= false;
6645 location_t generic_loc
, selector_loc
;
6647 error_expr
.original_code
= ERROR_MARK
;
6648 error_expr
.original_type
= NULL
;
6649 error_expr
.value
= error_mark_node
;
6650 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6651 matched_assoc
.type
= NULL_TREE
;
6652 matched_assoc
.expression
= error_expr
;
6654 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6655 generic_loc
= c_parser_peek_token (parser
)->location
;
6656 c_parser_consume_token (parser
);
6660 pedwarn (generic_loc
, OPT_Wpedantic
,
6661 "ISO C99 does not support %<_Generic%>");
6663 pedwarn (generic_loc
, OPT_Wpedantic
,
6664 "ISO C90 does not support %<_Generic%>");
6667 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6670 c_inhibit_evaluation_warnings
++;
6671 selector_loc
= c_parser_peek_token (parser
)->location
;
6672 selector
= c_parser_expr_no_commas (parser
, NULL
);
6673 selector
= default_function_array_conversion (selector_loc
, selector
);
6674 c_inhibit_evaluation_warnings
--;
6676 if (selector
.value
== error_mark_node
)
6678 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6681 selector_type
= TREE_TYPE (selector
.value
);
6682 /* In ISO C terms, rvalues (including the controlling expression of
6683 _Generic) do not have qualified types. */
6684 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6685 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6686 /* In ISO C terms, _Noreturn is not part of the type of expressions
6687 such as &abort, but in GCC it is represented internally as a type
6689 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6690 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6692 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6694 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6696 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6702 struct c_generic_association assoc
, *iter
;
6704 c_token
*token
= c_parser_peek_token (parser
);
6706 assoc
.type_location
= token
->location
;
6707 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6709 c_parser_consume_token (parser
);
6710 assoc
.type
= NULL_TREE
;
6714 struct c_type_name
*type_name
;
6716 type_name
= c_parser_type_name (parser
);
6717 if (type_name
== NULL
)
6719 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6722 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6723 if (assoc
.type
== error_mark_node
)
6725 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6729 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6730 error_at (assoc
.type_location
,
6731 "%<_Generic%> association has function type");
6732 else if (!COMPLETE_TYPE_P (assoc
.type
))
6733 error_at (assoc
.type_location
,
6734 "%<_Generic%> association has incomplete type");
6736 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6737 error_at (assoc
.type_location
,
6738 "%<_Generic%> association has "
6739 "variable length type");
6742 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6744 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6748 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6749 if (assoc
.expression
.value
== error_mark_node
)
6751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6755 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6757 if (assoc
.type
== NULL_TREE
)
6759 if (iter
->type
== NULL_TREE
)
6761 error_at (assoc
.type_location
,
6762 "duplicate %<default%> case in %<_Generic%>");
6763 inform (iter
->type_location
, "original %<default%> is here");
6766 else if (iter
->type
!= NULL_TREE
)
6768 if (comptypes (assoc
.type
, iter
->type
))
6770 error_at (assoc
.type_location
,
6771 "%<_Generic%> specifies two compatible types");
6772 inform (iter
->type_location
, "compatible type is here");
6777 if (assoc
.type
== NULL_TREE
)
6781 matched_assoc
= assoc
;
6785 else if (comptypes (assoc
.type
, selector_type
))
6787 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6789 matched_assoc
= assoc
;
6794 error_at (assoc
.type_location
,
6795 "%<_Generic> selector matches multiple associations");
6796 inform (matched_assoc
.type_location
,
6797 "other match is here");
6801 associations
.safe_push (assoc
);
6803 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6805 c_parser_consume_token (parser
);
6808 associations
.release ();
6810 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6812 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6818 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6819 "compatible with any association",
6824 return matched_assoc
.expression
;
6827 associations
.release ();
6831 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6835 postfix-expression [ expression ]
6836 postfix-expression ( argument-expression-list[opt] )
6837 postfix-expression . identifier
6838 postfix-expression -> identifier
6839 postfix-expression ++
6840 postfix-expression --
6841 ( type-name ) { initializer-list }
6842 ( type-name ) { initializer-list , }
6844 argument-expression-list:
6846 argument-expression-list , argument-expression
6859 (treated as a keyword in GNU C)
6862 ( compound-statement )
6863 __builtin_va_arg ( assignment-expression , type-name )
6864 __builtin_offsetof ( type-name , offsetof-member-designator )
6865 __builtin_choose_expr ( assignment-expression ,
6866 assignment-expression ,
6867 assignment-expression )
6868 __builtin_types_compatible_p ( type-name , type-name )
6869 __builtin_complex ( assignment-expression , assignment-expression )
6870 __builtin_shuffle ( assignment-expression , assignment-expression )
6871 __builtin_shuffle ( assignment-expression ,
6872 assignment-expression ,
6873 assignment-expression, )
6875 offsetof-member-designator:
6877 offsetof-member-designator . identifier
6878 offsetof-member-designator [ expression ]
6883 [ objc-receiver objc-message-args ]
6884 @selector ( objc-selector-arg )
6885 @protocol ( identifier )
6886 @encode ( type-name )
6888 Classname . identifier
6891 static struct c_expr
6892 c_parser_postfix_expression (c_parser
*parser
)
6894 struct c_expr expr
, e1
;
6895 struct c_type_name
*t1
, *t2
;
6896 location_t loc
= c_parser_peek_token (parser
)->location
;;
6897 expr
.original_code
= ERROR_MARK
;
6898 expr
.original_type
= NULL
;
6899 switch (c_parser_peek_token (parser
)->type
)
6902 expr
.value
= c_parser_peek_token (parser
)->value
;
6903 loc
= c_parser_peek_token (parser
)->location
;
6904 c_parser_consume_token (parser
);
6905 if (TREE_CODE (expr
.value
) == FIXED_CST
6906 && !targetm
.fixed_point_supported_p ())
6908 error_at (loc
, "fixed-point types not supported for this target");
6909 expr
.value
= error_mark_node
;
6916 expr
.value
= c_parser_peek_token (parser
)->value
;
6917 c_parser_consume_token (parser
);
6923 case CPP_UTF8STRING
:
6924 expr
.value
= c_parser_peek_token (parser
)->value
;
6925 expr
.original_code
= STRING_CST
;
6926 c_parser_consume_token (parser
);
6928 case CPP_OBJC_STRING
:
6929 gcc_assert (c_dialect_objc ());
6931 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6932 c_parser_consume_token (parser
);
6935 switch (c_parser_peek_token (parser
)->id_kind
)
6939 tree id
= c_parser_peek_token (parser
)->value
;
6940 c_parser_consume_token (parser
);
6941 expr
.value
= build_external_ref (loc
, id
,
6942 (c_parser_peek_token (parser
)->type
6944 &expr
.original_type
);
6947 case C_ID_CLASSNAME
:
6949 /* Here we parse the Objective-C 2.0 Class.name dot
6951 tree class_name
= c_parser_peek_token (parser
)->value
;
6953 c_parser_consume_token (parser
);
6954 gcc_assert (c_dialect_objc ());
6955 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6957 expr
.value
= error_mark_node
;
6960 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6962 c_parser_error (parser
, "expected identifier");
6963 expr
.value
= error_mark_node
;
6966 component
= c_parser_peek_token (parser
)->value
;
6967 c_parser_consume_token (parser
);
6968 expr
.value
= objc_build_class_component_ref (class_name
,
6973 c_parser_error (parser
, "expected expression");
6974 expr
.value
= error_mark_node
;
6978 case CPP_OPEN_PAREN
:
6979 /* A parenthesized expression, statement expression or compound
6981 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6983 /* A statement expression. */
6985 location_t brace_loc
;
6986 c_parser_consume_token (parser
);
6987 brace_loc
= c_parser_peek_token (parser
)->location
;
6988 c_parser_consume_token (parser
);
6989 if (!building_stmt_list_p ())
6991 error_at (loc
, "braced-group within expression allowed "
6992 "only inside a function");
6993 parser
->error
= true;
6994 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6995 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6996 expr
.value
= error_mark_node
;
6999 stmt
= c_begin_stmt_expr ();
7000 c_parser_compound_statement_nostart (parser
);
7001 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7003 pedwarn (loc
, OPT_Wpedantic
,
7004 "ISO C forbids braced-groups within expressions");
7005 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7006 mark_exp_read (expr
.value
);
7008 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7010 /* A compound literal. ??? Can we actually get here rather
7011 than going directly to
7012 c_parser_postfix_expression_after_paren_type from
7015 struct c_type_name
*type_name
;
7016 c_parser_consume_token (parser
);
7017 loc
= c_parser_peek_token (parser
)->location
;
7018 type_name
= c_parser_type_name (parser
);
7019 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7021 if (type_name
== NULL
)
7023 expr
.value
= error_mark_node
;
7026 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7032 /* A parenthesized expression. */
7033 c_parser_consume_token (parser
);
7034 expr
= c_parser_expression (parser
);
7035 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7036 TREE_NO_WARNING (expr
.value
) = 1;
7037 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7038 expr
.original_code
= ERROR_MARK
;
7039 /* Don't change EXPR.ORIGINAL_TYPE. */
7040 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7045 switch (c_parser_peek_token (parser
)->keyword
)
7047 case RID_FUNCTION_NAME
:
7048 case RID_PRETTY_FUNCTION_NAME
:
7049 case RID_C99_FUNCTION_NAME
:
7050 expr
.value
= fname_decl (loc
,
7051 c_parser_peek_token (parser
)->keyword
,
7052 c_parser_peek_token (parser
)->value
);
7053 c_parser_consume_token (parser
);
7056 c_parser_consume_token (parser
);
7057 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7059 expr
.value
= error_mark_node
;
7062 e1
= c_parser_expr_no_commas (parser
, NULL
);
7063 mark_exp_read (e1
.value
);
7064 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7065 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7067 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7068 expr
.value
= error_mark_node
;
7071 loc
= c_parser_peek_token (parser
)->location
;
7072 t1
= c_parser_type_name (parser
);
7073 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7077 expr
.value
= error_mark_node
;
7081 tree type_expr
= NULL_TREE
;
7082 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7083 groktypename (t1
, &type_expr
, NULL
));
7086 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7087 TREE_TYPE (expr
.value
), type_expr
,
7089 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7094 c_parser_consume_token (parser
);
7095 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7097 expr
.value
= error_mark_node
;
7100 t1
= c_parser_type_name (parser
);
7102 parser
->error
= true;
7103 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7104 gcc_assert (parser
->error
);
7107 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7108 expr
.value
= error_mark_node
;
7113 tree type
= groktypename (t1
, NULL
, NULL
);
7115 if (type
== error_mark_node
)
7116 offsetof_ref
= error_mark_node
;
7119 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7120 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7122 /* Parse the second argument to __builtin_offsetof. We
7123 must have one identifier, and beyond that we want to
7124 accept sub structure and sub array references. */
7125 if (c_parser_next_token_is (parser
, CPP_NAME
))
7127 offsetof_ref
= build_component_ref
7128 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7129 c_parser_consume_token (parser
);
7130 while (c_parser_next_token_is (parser
, CPP_DOT
)
7131 || c_parser_next_token_is (parser
,
7133 || c_parser_next_token_is (parser
,
7136 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7138 loc
= c_parser_peek_token (parser
)->location
;
7139 offsetof_ref
= build_array_ref (loc
,
7144 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7147 c_parser_consume_token (parser
);
7148 if (c_parser_next_token_is_not (parser
,
7151 c_parser_error (parser
, "expected identifier");
7154 offsetof_ref
= build_component_ref
7156 c_parser_peek_token (parser
)->value
);
7157 c_parser_consume_token (parser
);
7162 loc
= c_parser_peek_token (parser
)->location
;
7163 c_parser_consume_token (parser
);
7164 idx
= c_parser_expression (parser
).value
;
7165 idx
= c_fully_fold (idx
, false, NULL
);
7166 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7168 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7173 c_parser_error (parser
, "expected identifier");
7174 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7176 expr
.value
= fold_offsetof (offsetof_ref
);
7179 case RID_CHOOSE_EXPR
:
7181 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7182 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7185 c_parser_consume_token (parser
);
7186 if (!c_parser_get_builtin_args (parser
,
7187 "__builtin_choose_expr",
7190 expr
.value
= error_mark_node
;
7194 if (vec_safe_length (cexpr_list
) != 3)
7196 error_at (loc
, "wrong number of arguments to "
7197 "%<__builtin_choose_expr%>");
7198 expr
.value
= error_mark_node
;
7202 e1_p
= &(*cexpr_list
)[0];
7203 e2_p
= &(*cexpr_list
)[1];
7204 e3_p
= &(*cexpr_list
)[2];
7207 mark_exp_read (e2_p
->value
);
7208 mark_exp_read (e3_p
->value
);
7209 if (TREE_CODE (c
) != INTEGER_CST
7210 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7212 "first argument to %<__builtin_choose_expr%> not"
7214 constant_expression_warning (c
);
7215 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7218 case RID_TYPES_COMPATIBLE_P
:
7219 c_parser_consume_token (parser
);
7220 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7222 expr
.value
= error_mark_node
;
7225 t1
= c_parser_type_name (parser
);
7228 expr
.value
= error_mark_node
;
7231 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7233 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7234 expr
.value
= error_mark_node
;
7237 t2
= c_parser_type_name (parser
);
7240 expr
.value
= error_mark_node
;
7243 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7247 e1
= groktypename (t1
, NULL
, NULL
);
7248 e2
= groktypename (t2
, NULL
, NULL
);
7249 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7251 expr
.value
= error_mark_node
;
7255 e1
= TYPE_MAIN_VARIANT (e1
);
7256 e2
= TYPE_MAIN_VARIANT (e2
);
7259 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7262 case RID_BUILTIN_COMPLEX
:
7264 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7265 c_expr_t
*e1_p
, *e2_p
;
7267 c_parser_consume_token (parser
);
7268 if (!c_parser_get_builtin_args (parser
,
7269 "__builtin_complex",
7270 &cexpr_list
, false))
7272 expr
.value
= error_mark_node
;
7276 if (vec_safe_length (cexpr_list
) != 2)
7278 error_at (loc
, "wrong number of arguments to "
7279 "%<__builtin_complex%>");
7280 expr
.value
= error_mark_node
;
7284 e1_p
= &(*cexpr_list
)[0];
7285 e2_p
= &(*cexpr_list
)[1];
7287 mark_exp_read (e1_p
->value
);
7288 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7289 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7290 TREE_OPERAND (e1_p
->value
, 0));
7291 mark_exp_read (e2_p
->value
);
7292 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7293 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7294 TREE_OPERAND (e2_p
->value
, 0));
7295 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7296 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7297 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7298 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7300 error_at (loc
, "%<__builtin_complex%> operand "
7301 "not of real binary floating-point type");
7302 expr
.value
= error_mark_node
;
7305 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7306 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7309 "%<__builtin_complex%> operands of different types");
7310 expr
.value
= error_mark_node
;
7314 pedwarn (loc
, OPT_Wpedantic
,
7315 "ISO C90 does not support complex types");
7316 expr
.value
= build2 (COMPLEX_EXPR
,
7319 (TREE_TYPE (e1_p
->value
))),
7320 e1_p
->value
, e2_p
->value
);
7323 case RID_BUILTIN_SHUFFLE
:
7325 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7329 c_parser_consume_token (parser
);
7330 if (!c_parser_get_builtin_args (parser
,
7331 "__builtin_shuffle",
7332 &cexpr_list
, false))
7334 expr
.value
= error_mark_node
;
7338 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7339 mark_exp_read (p
->value
);
7341 if (vec_safe_length (cexpr_list
) == 2)
7343 c_build_vec_perm_expr
7344 (loc
, (*cexpr_list
)[0].value
,
7345 NULL_TREE
, (*cexpr_list
)[1].value
);
7347 else if (vec_safe_length (cexpr_list
) == 3)
7349 c_build_vec_perm_expr
7350 (loc
, (*cexpr_list
)[0].value
,
7351 (*cexpr_list
)[1].value
,
7352 (*cexpr_list
)[2].value
);
7355 error_at (loc
, "wrong number of arguments to "
7356 "%<__builtin_shuffle%>");
7357 expr
.value
= error_mark_node
;
7361 case RID_AT_SELECTOR
:
7362 gcc_assert (c_dialect_objc ());
7363 c_parser_consume_token (parser
);
7364 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7366 expr
.value
= error_mark_node
;
7370 tree sel
= c_parser_objc_selector_arg (parser
);
7371 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7373 expr
.value
= objc_build_selector_expr (loc
, sel
);
7376 case RID_AT_PROTOCOL
:
7377 gcc_assert (c_dialect_objc ());
7378 c_parser_consume_token (parser
);
7379 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7381 expr
.value
= error_mark_node
;
7384 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7386 c_parser_error (parser
, "expected identifier");
7387 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7388 expr
.value
= error_mark_node
;
7392 tree id
= c_parser_peek_token (parser
)->value
;
7393 c_parser_consume_token (parser
);
7394 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7396 expr
.value
= objc_build_protocol_expr (id
);
7400 /* Extension to support C-structures in the archiver. */
7401 gcc_assert (c_dialect_objc ());
7402 c_parser_consume_token (parser
);
7403 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7405 expr
.value
= error_mark_node
;
7408 t1
= c_parser_type_name (parser
);
7411 expr
.value
= error_mark_node
;
7412 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7415 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7418 tree type
= groktypename (t1
, NULL
, NULL
);
7419 expr
.value
= objc_build_encode_expr (type
);
7423 expr
= c_parser_generic_selection (parser
);
7425 case RID_CILK_SPAWN
:
7426 c_parser_consume_token (parser
);
7427 if (!flag_enable_cilkplus
)
7429 error_at (loc
, "-fcilkplus must be enabled to use "
7431 expr
= c_parser_postfix_expression (parser
);
7432 expr
.value
= error_mark_node
;
7434 if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7436 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7437 "are not permitted");
7438 /* Now flush out all the _Cilk_spawns. */
7439 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7440 c_parser_consume_token (parser
);
7441 expr
= c_parser_postfix_expression (parser
);
7445 expr
= c_parser_postfix_expression (parser
);
7446 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7450 c_parser_error (parser
, "expected expression");
7451 expr
.value
= error_mark_node
;
7455 case CPP_OPEN_SQUARE
:
7456 if (c_dialect_objc ())
7458 tree receiver
, args
;
7459 c_parser_consume_token (parser
);
7460 receiver
= c_parser_objc_receiver (parser
);
7461 args
= c_parser_objc_message_args (parser
);
7462 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7464 expr
.value
= objc_build_message_expr (receiver
, args
);
7467 /* Else fall through to report error. */
7469 c_parser_error (parser
, "expected expression");
7470 expr
.value
= error_mark_node
;
7473 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7476 /* Parse a postfix expression after a parenthesized type name: the
7477 brace-enclosed initializer of a compound literal, possibly followed
7478 by some postfix operators. This is separate because it is not
7479 possible to tell until after the type name whether a cast
7480 expression has a cast or a compound literal, or whether the operand
7481 of sizeof is a parenthesized type name or starts with a compound
7482 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7483 location of the first token after the parentheses around the type
7486 static struct c_expr
7487 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7488 struct c_type_name
*type_name
,
7489 location_t type_loc
)
7495 location_t start_loc
;
7496 tree type_expr
= NULL_TREE
;
7497 bool type_expr_const
= true;
7498 check_compound_literal_type (type_loc
, type_name
);
7499 start_init (NULL_TREE
, NULL
, 0);
7500 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7501 start_loc
= c_parser_peek_token (parser
)->location
;
7502 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7504 error_at (type_loc
, "compound literal has variable size");
7505 type
= error_mark_node
;
7507 init
= c_parser_braced_init (parser
, type
, false);
7509 maybe_warn_string_init (type
, init
);
7511 if (type
!= error_mark_node
7512 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7513 && current_function_decl
)
7515 error ("compound literal qualified by address-space qualifier");
7516 type
= error_mark_node
;
7520 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7521 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7522 ? CONSTRUCTOR_NON_CONST (init
.value
)
7523 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7524 non_const
|= !type_expr_const
;
7525 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7526 expr
.original_code
= ERROR_MARK
;
7527 expr
.original_type
= NULL
;
7530 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7532 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7533 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7537 gcc_assert (!non_const
);
7538 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7539 type_expr
, expr
.value
);
7542 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7545 /* Callback function for sizeof_pointer_memaccess_warning to compare
7549 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7551 return comptypes (type1
, type2
) == 1;
7554 /* Parse a postfix expression after the initial primary or compound
7555 literal; that is, parse a series of postfix operators.
7557 EXPR_LOC is the location of the primary expression. */
7559 static struct c_expr
7560 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7561 location_t expr_loc
,
7564 struct c_expr orig_expr
;
7566 location_t sizeof_arg_loc
[3];
7569 vec
<tree
, va_gc
> *exprlist
;
7570 vec
<tree
, va_gc
> *origtypes
= NULL
;
7573 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7574 switch (c_parser_peek_token (parser
)->type
)
7576 case CPP_OPEN_SQUARE
:
7577 /* Array reference. */
7578 c_parser_consume_token (parser
);
7579 if (flag_enable_cilkplus
7580 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7581 /* If we are here, then we have something like this:
7584 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7588 idx
= c_parser_expression (parser
).value
;
7589 /* Here we have 3 options:
7590 1. Array [EXPR] -- Normal Array call.
7591 2. Array [EXPR : EXPR] -- Array notation without stride.
7592 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7594 For 1, we just handle it just like a normal array expression.
7595 For 2 and 3 we handle it like we handle array notations. The
7596 idx value we have above becomes the initial/start index.
7598 if (flag_enable_cilkplus
7599 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7600 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7604 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7606 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7609 expr
.original_code
= ERROR_MARK
;
7610 expr
.original_type
= NULL
;
7612 case CPP_OPEN_PAREN
:
7613 /* Function call. */
7614 c_parser_consume_token (parser
);
7615 for (i
= 0; i
< 3; i
++)
7617 sizeof_arg
[i
] = NULL_TREE
;
7618 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7620 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7623 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7624 sizeof_arg_loc
, sizeof_arg
);
7625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7628 mark_exp_read (expr
.value
);
7629 if (warn_sizeof_pointer_memaccess
)
7630 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7631 expr
.value
, exprlist
,
7633 sizeof_ptr_memacc_comptypes
);
7634 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7635 "(" after the FUNCNAME, which is what we have now. */
7636 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7638 expr
.original_code
= ERROR_MARK
;
7639 if (TREE_CODE (expr
.value
) == INTEGER_CST
7640 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7641 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7642 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7643 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7644 expr
.original_type
= NULL
;
7647 release_tree_vector (exprlist
);
7648 release_tree_vector (origtypes
);
7652 /* Structure element reference. */
7653 c_parser_consume_token (parser
);
7654 expr
= default_function_array_conversion (expr_loc
, expr
);
7655 if (c_parser_next_token_is (parser
, CPP_NAME
))
7656 ident
= c_parser_peek_token (parser
)->value
;
7659 c_parser_error (parser
, "expected identifier");
7660 expr
.value
= error_mark_node
;
7661 expr
.original_code
= ERROR_MARK
;
7662 expr
.original_type
= NULL
;
7665 c_parser_consume_token (parser
);
7666 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7667 expr
.original_code
= ERROR_MARK
;
7668 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7669 expr
.original_type
= NULL
;
7672 /* Remember the original type of a bitfield. */
7673 tree field
= TREE_OPERAND (expr
.value
, 1);
7674 if (TREE_CODE (field
) != FIELD_DECL
)
7675 expr
.original_type
= NULL
;
7677 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7681 /* Structure element reference. */
7682 c_parser_consume_token (parser
);
7683 expr
= default_function_array_conversion (expr_loc
, expr
);
7684 if (c_parser_next_token_is (parser
, CPP_NAME
))
7685 ident
= c_parser_peek_token (parser
)->value
;
7688 c_parser_error (parser
, "expected identifier");
7689 expr
.value
= error_mark_node
;
7690 expr
.original_code
= ERROR_MARK
;
7691 expr
.original_type
= NULL
;
7694 c_parser_consume_token (parser
);
7695 expr
.value
= build_component_ref (op_loc
,
7696 build_indirect_ref (op_loc
,
7700 expr
.original_code
= ERROR_MARK
;
7701 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7702 expr
.original_type
= NULL
;
7705 /* Remember the original type of a bitfield. */
7706 tree field
= TREE_OPERAND (expr
.value
, 1);
7707 if (TREE_CODE (field
) != FIELD_DECL
)
7708 expr
.original_type
= NULL
;
7710 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7714 /* Postincrement. */
7715 c_parser_consume_token (parser
);
7716 /* If the expressions have array notations, we expand them. */
7717 if (flag_enable_cilkplus
7718 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7719 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7722 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7723 expr
.value
= build_unary_op (op_loc
,
7724 POSTINCREMENT_EXPR
, expr
.value
, 0);
7726 expr
.original_code
= ERROR_MARK
;
7727 expr
.original_type
= NULL
;
7729 case CPP_MINUS_MINUS
:
7730 /* Postdecrement. */
7731 c_parser_consume_token (parser
);
7732 /* If the expressions have array notations, we expand them. */
7733 if (flag_enable_cilkplus
7734 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7735 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7738 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7739 expr
.value
= build_unary_op (op_loc
,
7740 POSTDECREMENT_EXPR
, expr
.value
, 0);
7742 expr
.original_code
= ERROR_MARK
;
7743 expr
.original_type
= NULL
;
7751 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7754 assignment-expression
7755 expression , assignment-expression
7758 static struct c_expr
7759 c_parser_expression (c_parser
*parser
)
7762 expr
= c_parser_expr_no_commas (parser
, NULL
);
7763 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7767 location_t loc
= c_parser_peek_token (parser
)->location
;
7768 location_t expr_loc
;
7769 c_parser_consume_token (parser
);
7770 expr_loc
= c_parser_peek_token (parser
)->location
;
7771 lhsval
= expr
.value
;
7772 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7773 lhsval
= TREE_OPERAND (lhsval
, 1);
7774 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7775 mark_exp_read (lhsval
);
7776 next
= c_parser_expr_no_commas (parser
, NULL
);
7777 next
= default_function_array_conversion (expr_loc
, next
);
7778 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7779 expr
.original_code
= COMPOUND_EXPR
;
7780 expr
.original_type
= next
.original_type
;
7785 /* Parse an expression and convert functions or arrays to
7788 static struct c_expr
7789 c_parser_expression_conv (c_parser
*parser
)
7792 location_t loc
= c_parser_peek_token (parser
)->location
;
7793 expr
= c_parser_expression (parser
);
7794 expr
= default_function_array_conversion (loc
, expr
);
7798 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7799 functions and arrays to pointers. If FOLD_P, fold the expressions.
7802 assignment-expression
7803 nonempty-expr-list , assignment-expression
7806 static vec
<tree
, va_gc
> *
7807 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7808 vec
<tree
, va_gc
> **p_orig_types
,
7809 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7811 vec
<tree
, va_gc
> *ret
;
7812 vec
<tree
, va_gc
> *orig_types
;
7814 location_t loc
= c_parser_peek_token (parser
)->location
;
7815 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7816 unsigned int idx
= 0;
7818 ret
= make_tree_vector ();
7819 if (p_orig_types
== NULL
)
7822 orig_types
= make_tree_vector ();
7824 if (sizeof_arg
!= NULL
7825 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7826 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7827 expr
= c_parser_expr_no_commas (parser
, NULL
);
7829 expr
= default_function_array_read_conversion (loc
, expr
);
7831 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7832 ret
->quick_push (expr
.value
);
7834 orig_types
->quick_push (expr
.original_type
);
7835 if (sizeof_arg
!= NULL
7836 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7837 && expr
.original_code
== SIZEOF_EXPR
)
7839 sizeof_arg
[0] = c_last_sizeof_arg
;
7840 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7842 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7844 c_parser_consume_token (parser
);
7845 loc
= c_parser_peek_token (parser
)->location
;
7846 if (sizeof_arg
!= NULL
7847 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7848 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7850 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7851 expr
= c_parser_expr_no_commas (parser
, NULL
);
7853 expr
= default_function_array_read_conversion (loc
, expr
);
7855 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7856 vec_safe_push (ret
, expr
.value
);
7858 vec_safe_push (orig_types
, expr
.original_type
);
7860 && sizeof_arg
!= NULL
7861 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7862 && expr
.original_code
== SIZEOF_EXPR
)
7864 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7865 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7869 *p_orig_types
= orig_types
;
7873 /* Parse Objective-C-specific constructs. */
7875 /* Parse an objc-class-definition.
7877 objc-class-definition:
7878 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7879 objc-class-instance-variables[opt] objc-methodprotolist @end
7880 @implementation identifier objc-superclass[opt]
7881 objc-class-instance-variables[opt]
7882 @interface identifier ( identifier ) objc-protocol-refs[opt]
7883 objc-methodprotolist @end
7884 @interface identifier ( ) objc-protocol-refs[opt]
7885 objc-methodprotolist @end
7886 @implementation identifier ( identifier )
7891 "@interface identifier (" must start "@interface identifier (
7892 identifier ) ...": objc-methodprotolist in the first production may
7893 not start with a parenthesized identifier as a declarator of a data
7894 definition with no declaration specifiers if the objc-superclass,
7895 objc-protocol-refs and objc-class-instance-variables are omitted. */
7898 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7903 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7905 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7910 c_parser_consume_token (parser
);
7911 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7913 c_parser_error (parser
, "expected identifier");
7916 id1
= c_parser_peek_token (parser
)->value
;
7917 c_parser_consume_token (parser
);
7918 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7920 /* We have a category or class extension. */
7922 tree proto
= NULL_TREE
;
7923 c_parser_consume_token (parser
);
7924 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7926 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7928 /* We have a class extension. */
7933 c_parser_error (parser
, "expected identifier or %<)%>");
7934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7940 id2
= c_parser_peek_token (parser
)->value
;
7941 c_parser_consume_token (parser
);
7943 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7946 objc_start_category_implementation (id1
, id2
);
7949 if (c_parser_next_token_is (parser
, CPP_LESS
))
7950 proto
= c_parser_objc_protocol_refs (parser
);
7951 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7952 c_parser_objc_methodprotolist (parser
);
7953 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7954 objc_finish_interface ();
7957 if (c_parser_next_token_is (parser
, CPP_COLON
))
7959 c_parser_consume_token (parser
);
7960 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7962 c_parser_error (parser
, "expected identifier");
7965 superclass
= c_parser_peek_token (parser
)->value
;
7966 c_parser_consume_token (parser
);
7969 superclass
= NULL_TREE
;
7972 tree proto
= NULL_TREE
;
7973 if (c_parser_next_token_is (parser
, CPP_LESS
))
7974 proto
= c_parser_objc_protocol_refs (parser
);
7975 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7978 objc_start_class_implementation (id1
, superclass
);
7979 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7980 c_parser_objc_class_instance_variables (parser
);
7983 objc_continue_interface ();
7984 c_parser_objc_methodprotolist (parser
);
7985 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7986 objc_finish_interface ();
7990 objc_continue_implementation ();
7995 /* Parse objc-class-instance-variables.
7997 objc-class-instance-variables:
7998 { objc-instance-variable-decl-list[opt] }
8000 objc-instance-variable-decl-list:
8001 objc-visibility-spec
8002 objc-instance-variable-decl ;
8004 objc-instance-variable-decl-list objc-visibility-spec
8005 objc-instance-variable-decl-list objc-instance-variable-decl ;
8006 objc-instance-variable-decl-list ;
8008 objc-visibility-spec:
8013 objc-instance-variable-decl:
8018 c_parser_objc_class_instance_variables (c_parser
*parser
)
8020 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8021 c_parser_consume_token (parser
);
8022 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8025 /* Parse any stray semicolon. */
8026 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8028 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8030 c_parser_consume_token (parser
);
8033 /* Stop if at the end of the instance variables. */
8034 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8036 c_parser_consume_token (parser
);
8039 /* Parse any objc-visibility-spec. */
8040 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8042 c_parser_consume_token (parser
);
8043 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8046 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8048 c_parser_consume_token (parser
);
8049 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8052 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8054 c_parser_consume_token (parser
);
8055 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8058 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8060 c_parser_consume_token (parser
);
8061 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8064 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8066 c_parser_pragma (parser
, pragma_external
);
8070 /* Parse some comma-separated declarations. */
8071 decls
= c_parser_struct_declaration (parser
);
8074 /* There is a syntax error. We want to skip the offending
8075 tokens up to the next ';' (included) or '}'
8078 /* First, skip manually a ')' or ']'. This is because they
8079 reduce the nesting level, so c_parser_skip_until_found()
8080 wouldn't be able to skip past them. */
8081 c_token
*token
= c_parser_peek_token (parser
);
8082 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8083 c_parser_consume_token (parser
);
8085 /* Then, do the standard skipping. */
8086 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8088 /* We hopefully recovered. Start normal parsing again. */
8089 parser
->error
= false;
8094 /* Comma-separated instance variables are chained together
8095 in reverse order; add them one by one. */
8096 tree ivar
= nreverse (decls
);
8097 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8098 objc_add_instance_variable (copy_node (ivar
));
8100 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8104 /* Parse an objc-class-declaration.
8106 objc-class-declaration:
8107 @class identifier-list ;
8111 c_parser_objc_class_declaration (c_parser
*parser
)
8113 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8114 c_parser_consume_token (parser
);
8115 /* Any identifiers, including those declared as type names, are OK
8120 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8122 c_parser_error (parser
, "expected identifier");
8123 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8124 parser
->error
= false;
8127 id
= c_parser_peek_token (parser
)->value
;
8128 objc_declare_class (id
);
8129 c_parser_consume_token (parser
);
8130 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8131 c_parser_consume_token (parser
);
8135 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8138 /* Parse an objc-alias-declaration.
8140 objc-alias-declaration:
8141 @compatibility_alias identifier identifier ;
8145 c_parser_objc_alias_declaration (c_parser
*parser
)
8148 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8149 c_parser_consume_token (parser
);
8150 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8152 c_parser_error (parser
, "expected identifier");
8153 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8156 id1
= c_parser_peek_token (parser
)->value
;
8157 c_parser_consume_token (parser
);
8158 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8160 c_parser_error (parser
, "expected identifier");
8161 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8164 id2
= c_parser_peek_token (parser
)->value
;
8165 c_parser_consume_token (parser
);
8166 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8167 objc_declare_alias (id1
, id2
);
8170 /* Parse an objc-protocol-definition.
8172 objc-protocol-definition:
8173 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8174 @protocol identifier-list ;
8176 "@protocol identifier ;" should be resolved as "@protocol
8177 identifier-list ;": objc-methodprotolist may not start with a
8178 semicolon in the first alternative if objc-protocol-refs are
8182 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8184 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8186 c_parser_consume_token (parser
);
8187 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8189 c_parser_error (parser
, "expected identifier");
8192 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8193 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8195 /* Any identifiers, including those declared as type names, are
8200 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8202 c_parser_error (parser
, "expected identifier");
8205 id
= c_parser_peek_token (parser
)->value
;
8206 objc_declare_protocol (id
, attributes
);
8207 c_parser_consume_token (parser
);
8208 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8209 c_parser_consume_token (parser
);
8213 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8217 tree id
= c_parser_peek_token (parser
)->value
;
8218 tree proto
= NULL_TREE
;
8219 c_parser_consume_token (parser
);
8220 if (c_parser_next_token_is (parser
, CPP_LESS
))
8221 proto
= c_parser_objc_protocol_refs (parser
);
8222 parser
->objc_pq_context
= true;
8223 objc_start_protocol (id
, proto
, attributes
);
8224 c_parser_objc_methodprotolist (parser
);
8225 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8226 parser
->objc_pq_context
= false;
8227 objc_finish_interface ();
8231 /* Parse an objc-method-type.
8237 Return true if it is a class method (+) and false if it is
8238 an instance method (-).
8241 c_parser_objc_method_type (c_parser
*parser
)
8243 switch (c_parser_peek_token (parser
)->type
)
8246 c_parser_consume_token (parser
);
8249 c_parser_consume_token (parser
);
8256 /* Parse an objc-method-definition.
8258 objc-method-definition:
8259 objc-method-type objc-method-decl ;[opt] compound-statement
8263 c_parser_objc_method_definition (c_parser
*parser
)
8265 bool is_class_method
= c_parser_objc_method_type (parser
);
8266 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8267 parser
->objc_pq_context
= true;
8268 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8270 if (decl
== error_mark_node
)
8271 return; /* Bail here. */
8273 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8275 c_parser_consume_token (parser
);
8276 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8277 "extra semicolon in method definition specified");
8280 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8282 c_parser_error (parser
, "expected %<{%>");
8286 parser
->objc_pq_context
= false;
8287 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8289 add_stmt (c_parser_compound_statement (parser
));
8290 objc_finish_method_definition (current_function_decl
);
8294 /* This code is executed when we find a method definition
8295 outside of an @implementation context (or invalid for other
8296 reasons). Parse the method (to keep going) but do not emit
8299 c_parser_compound_statement (parser
);
8303 /* Parse an objc-methodprotolist.
8305 objc-methodprotolist:
8307 objc-methodprotolist objc-methodproto
8308 objc-methodprotolist declaration
8309 objc-methodprotolist ;
8313 The declaration is a data definition, which may be missing
8314 declaration specifiers under the same rules and diagnostics as
8315 other data definitions outside functions, and the stray semicolon
8316 is diagnosed the same way as a stray semicolon outside a
8320 c_parser_objc_methodprotolist (c_parser
*parser
)
8324 /* The list is terminated by @end. */
8325 switch (c_parser_peek_token (parser
)->type
)
8328 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8329 "ISO C does not allow extra %<;%> outside of a function");
8330 c_parser_consume_token (parser
);
8334 c_parser_objc_methodproto (parser
);
8337 c_parser_pragma (parser
, pragma_external
);
8342 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8344 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8345 c_parser_objc_at_property_declaration (parser
);
8346 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8348 objc_set_method_opt (true);
8349 c_parser_consume_token (parser
);
8351 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8353 objc_set_method_opt (false);
8354 c_parser_consume_token (parser
);
8357 c_parser_declaration_or_fndef (parser
, false, false, true,
8358 false, true, NULL
, vNULL
);
8364 /* Parse an objc-methodproto.
8367 objc-method-type objc-method-decl ;
8371 c_parser_objc_methodproto (c_parser
*parser
)
8373 bool is_class_method
= c_parser_objc_method_type (parser
);
8374 tree decl
, attributes
= NULL_TREE
;
8376 /* Remember protocol qualifiers in prototypes. */
8377 parser
->objc_pq_context
= true;
8378 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8380 /* Forget protocol qualifiers now. */
8381 parser
->objc_pq_context
= false;
8383 /* Do not allow the presence of attributes to hide an erroneous
8384 method implementation in the interface section. */
8385 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8387 c_parser_error (parser
, "expected %<;%>");
8391 if (decl
!= error_mark_node
)
8392 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8394 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8397 /* If we are at a position that method attributes may be present, check that
8398 there are not any parsed already (a syntax error) and then collect any
8399 specified at the current location. Finally, if new attributes were present,
8400 check that the next token is legal ( ';' for decls and '{' for defs). */
8403 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8408 c_parser_error (parser
,
8409 "method attributes must be specified at the end only");
8410 *attributes
= NULL_TREE
;
8414 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8415 *attributes
= c_parser_attributes (parser
);
8417 /* If there were no attributes here, just report any earlier error. */
8418 if (*attributes
== NULL_TREE
|| bad
)
8421 /* If the attributes are followed by a ; or {, then just report any earlier
8423 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8424 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8427 /* We've got attributes, but not at the end. */
8428 c_parser_error (parser
,
8429 "expected %<;%> or %<{%> after method attribute definition");
8433 /* Parse an objc-method-decl.
8436 ( objc-type-name ) objc-selector
8438 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8439 objc-keyword-selector objc-optparmlist
8442 objc-keyword-selector:
8444 objc-keyword-selector objc-keyword-decl
8447 objc-selector : ( objc-type-name ) identifier
8448 objc-selector : identifier
8449 : ( objc-type-name ) identifier
8453 objc-optparms objc-optellipsis
8457 objc-opt-parms , parameter-declaration
8465 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8466 tree
*attributes
, tree
*expr
)
8468 tree type
= NULL_TREE
;
8470 tree parms
= NULL_TREE
;
8471 bool ellipsis
= false;
8472 bool attr_err
= false;
8474 *attributes
= NULL_TREE
;
8475 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8477 c_parser_consume_token (parser
);
8478 type
= c_parser_objc_type_name (parser
);
8479 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8481 sel
= c_parser_objc_selector (parser
);
8482 /* If there is no selector, or a colon follows, we have an
8483 objc-keyword-selector. If there is a selector, and a colon does
8484 not follow, that selector ends the objc-method-decl. */
8485 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8488 tree list
= NULL_TREE
;
8491 tree atype
= NULL_TREE
, id
, keyworddecl
;
8492 tree param_attr
= NULL_TREE
;
8493 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8495 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8497 c_parser_consume_token (parser
);
8498 atype
= c_parser_objc_type_name (parser
);
8499 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8502 /* New ObjC allows attributes on method parameters. */
8503 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8504 param_attr
= c_parser_attributes (parser
);
8505 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8507 c_parser_error (parser
, "expected identifier");
8508 return error_mark_node
;
8510 id
= c_parser_peek_token (parser
)->value
;
8511 c_parser_consume_token (parser
);
8512 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8513 list
= chainon (list
, keyworddecl
);
8514 tsel
= c_parser_objc_selector (parser
);
8515 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8519 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8521 /* Parse the optional parameter list. Optional Objective-C
8522 method parameters follow the C syntax, and may include '...'
8523 to denote a variable number of arguments. */
8524 parms
= make_node (TREE_LIST
);
8525 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8527 struct c_parm
*parm
;
8528 c_parser_consume_token (parser
);
8529 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8532 c_parser_consume_token (parser
);
8533 attr_err
|= c_parser_objc_maybe_method_attributes
8534 (parser
, attributes
) ;
8537 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8540 parms
= chainon (parms
,
8541 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8546 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8550 c_parser_error (parser
, "objective-c method declaration is expected");
8551 return error_mark_node
;
8555 return error_mark_node
;
8557 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8560 /* Parse an objc-type-name.
8563 objc-type-qualifiers[opt] type-name
8564 objc-type-qualifiers[opt]
8566 objc-type-qualifiers:
8568 objc-type-qualifiers objc-type-qualifier
8570 objc-type-qualifier: one of
8571 in out inout bycopy byref oneway
8575 c_parser_objc_type_name (c_parser
*parser
)
8577 tree quals
= NULL_TREE
;
8578 struct c_type_name
*type_name
= NULL
;
8579 tree type
= NULL_TREE
;
8582 c_token
*token
= c_parser_peek_token (parser
);
8583 if (token
->type
== CPP_KEYWORD
8584 && (token
->keyword
== RID_IN
8585 || token
->keyword
== RID_OUT
8586 || token
->keyword
== RID_INOUT
8587 || token
->keyword
== RID_BYCOPY
8588 || token
->keyword
== RID_BYREF
8589 || token
->keyword
== RID_ONEWAY
))
8591 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8592 c_parser_consume_token (parser
);
8597 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8598 type_name
= c_parser_type_name (parser
);
8600 type
= groktypename (type_name
, NULL
, NULL
);
8602 /* If the type is unknown, and error has already been produced and
8603 we need to recover from the error. In that case, use NULL_TREE
8604 for the type, as if no type had been specified; this will use the
8605 default type ('id') which is good for error recovery. */
8606 if (type
== error_mark_node
)
8609 return build_tree_list (quals
, type
);
8612 /* Parse objc-protocol-refs.
8619 c_parser_objc_protocol_refs (c_parser
*parser
)
8621 tree list
= NULL_TREE
;
8622 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8623 c_parser_consume_token (parser
);
8624 /* Any identifiers, including those declared as type names, are OK
8629 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8631 c_parser_error (parser
, "expected identifier");
8634 id
= c_parser_peek_token (parser
)->value
;
8635 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8636 c_parser_consume_token (parser
);
8637 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8638 c_parser_consume_token (parser
);
8642 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8646 /* Parse an objc-try-catch-finally-statement.
8648 objc-try-catch-finally-statement:
8649 @try compound-statement objc-catch-list[opt]
8650 @try compound-statement objc-catch-list[opt] @finally compound-statement
8653 @catch ( objc-catch-parameter-declaration ) compound-statement
8654 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8656 objc-catch-parameter-declaration:
8657 parameter-declaration
8660 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8662 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8663 for C++. Keep them in sync. */
8666 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8668 location_t location
;
8671 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8672 c_parser_consume_token (parser
);
8673 location
= c_parser_peek_token (parser
)->location
;
8674 objc_maybe_warn_exceptions (location
);
8675 stmt
= c_parser_compound_statement (parser
);
8676 objc_begin_try_stmt (location
, stmt
);
8678 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8680 struct c_parm
*parm
;
8681 tree parameter_declaration
= error_mark_node
;
8682 bool seen_open_paren
= false;
8684 c_parser_consume_token (parser
);
8685 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8686 seen_open_paren
= true;
8687 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8689 /* We have "@catch (...)" (where the '...' are literally
8690 what is in the code). Skip the '...'.
8691 parameter_declaration is set to NULL_TREE, and
8692 objc_being_catch_clauses() knows that that means
8694 c_parser_consume_token (parser
);
8695 parameter_declaration
= NULL_TREE
;
8699 /* We have "@catch (NSException *exception)" or something
8700 like that. Parse the parameter declaration. */
8701 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8703 parameter_declaration
= error_mark_node
;
8705 parameter_declaration
= grokparm (parm
, NULL
);
8707 if (seen_open_paren
)
8708 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8711 /* If there was no open parenthesis, we are recovering from
8712 an error, and we are trying to figure out what mistake
8713 the user has made. */
8715 /* If there is an immediate closing parenthesis, the user
8716 probably forgot the opening one (ie, they typed "@catch
8717 NSException *e)". Parse the closing parenthesis and keep
8719 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8720 c_parser_consume_token (parser
);
8722 /* If these is no immediate closing parenthesis, the user
8723 probably doesn't know that parenthesis are required at
8724 all (ie, they typed "@catch NSException *e"). So, just
8725 forget about the closing parenthesis and keep going. */
8727 objc_begin_catch_clause (parameter_declaration
);
8728 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8729 c_parser_compound_statement_nostart (parser
);
8730 objc_finish_catch_clause ();
8732 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8734 c_parser_consume_token (parser
);
8735 location
= c_parser_peek_token (parser
)->location
;
8736 stmt
= c_parser_compound_statement (parser
);
8737 objc_build_finally_clause (location
, stmt
);
8739 objc_finish_try_stmt ();
8742 /* Parse an objc-synchronized-statement.
8744 objc-synchronized-statement:
8745 @synchronized ( expression ) compound-statement
8749 c_parser_objc_synchronized_statement (c_parser
*parser
)
8753 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8754 c_parser_consume_token (parser
);
8755 loc
= c_parser_peek_token (parser
)->location
;
8756 objc_maybe_warn_exceptions (loc
);
8757 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8759 expr
= c_parser_expression (parser
).value
;
8760 expr
= c_fully_fold (expr
, false, NULL
);
8761 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8764 expr
= error_mark_node
;
8765 stmt
= c_parser_compound_statement (parser
);
8766 objc_build_synchronized (loc
, expr
, stmt
);
8769 /* Parse an objc-selector; return NULL_TREE without an error if the
8770 next token is not an objc-selector.
8775 enum struct union if else while do for switch case default
8776 break continue return goto asm sizeof typeof __alignof
8777 unsigned long const short volatile signed restrict _Complex
8778 in out inout bycopy byref oneway int char float double void _Bool
8780 ??? Why this selection of keywords but not, for example, storage
8781 class specifiers? */
8784 c_parser_objc_selector (c_parser
*parser
)
8786 c_token
*token
= c_parser_peek_token (parser
);
8787 tree value
= token
->value
;
8788 if (token
->type
== CPP_NAME
)
8790 c_parser_consume_token (parser
);
8793 if (token
->type
!= CPP_KEYWORD
)
8795 switch (token
->keyword
)
8837 c_parser_consume_token (parser
);
8844 /* Parse an objc-selector-arg.
8848 objc-keywordname-list
8850 objc-keywordname-list:
8852 objc-keywordname-list objc-keywordname
8860 c_parser_objc_selector_arg (c_parser
*parser
)
8862 tree sel
= c_parser_objc_selector (parser
);
8863 tree list
= NULL_TREE
;
8864 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8868 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8870 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8871 sel
= c_parser_objc_selector (parser
);
8872 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8878 /* Parse an objc-receiver.
8887 c_parser_objc_receiver (c_parser
*parser
)
8889 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8890 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8891 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8893 tree id
= c_parser_peek_token (parser
)->value
;
8894 c_parser_consume_token (parser
);
8895 return objc_get_class_reference (id
);
8897 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8900 /* Parse objc-message-args.
8904 objc-keywordarg-list
8906 objc-keywordarg-list:
8908 objc-keywordarg-list objc-keywordarg
8911 objc-selector : objc-keywordexpr
8916 c_parser_objc_message_args (c_parser
*parser
)
8918 tree sel
= c_parser_objc_selector (parser
);
8919 tree list
= NULL_TREE
;
8920 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8925 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8926 return error_mark_node
;
8927 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8928 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8929 sel
= c_parser_objc_selector (parser
);
8930 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8936 /* Parse an objc-keywordexpr.
8943 c_parser_objc_keywordexpr (c_parser
*parser
)
8946 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8948 if (vec_safe_length (expr_list
) == 1)
8950 /* Just return the expression, remove a level of
8952 ret
= (*expr_list
)[0];
8956 /* We have a comma expression, we will collapse later. */
8957 ret
= build_tree_list_vec (expr_list
);
8959 release_tree_vector (expr_list
);
8963 /* A check, needed in several places, that ObjC interface, implementation or
8964 method definitions are not prefixed by incorrect items. */
8966 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8967 struct c_declspecs
*specs
)
8969 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8970 || specs
->typespec_kind
!= ctsk_none
)
8972 c_parser_error (parser
,
8973 "no type or storage class may be specified here,");
8974 c_parser_skip_to_end_of_block_or_statement (parser
);
8980 /* Parse an Objective-C @property declaration. The syntax is:
8982 objc-property-declaration:
8983 '@property' objc-property-attributes[opt] struct-declaration ;
8985 objc-property-attributes:
8986 '(' objc-property-attribute-list ')'
8988 objc-property-attribute-list:
8989 objc-property-attribute
8990 objc-property-attribute-list, objc-property-attribute
8992 objc-property-attribute
8993 'getter' = identifier
8994 'setter' = identifier
9003 @property NSString *name;
9004 @property (readonly) id object;
9005 @property (retain, nonatomic, getter=getTheName) id name;
9006 @property int a, b, c;
9008 PS: This function is identical to cp_parser_objc_at_propery_declaration
9009 for C++. Keep them in sync. */
9011 c_parser_objc_at_property_declaration (c_parser
*parser
)
9013 /* The following variables hold the attributes of the properties as
9014 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9015 seen. When we see an attribute, we set them to 'true' (if they
9016 are boolean properties) or to the identifier (if they have an
9017 argument, ie, for getter and setter). Note that here we only
9018 parse the list of attributes, check the syntax and accumulate the
9019 attributes that we find. objc_add_property_declaration() will
9020 then process the information. */
9021 bool property_assign
= false;
9022 bool property_copy
= false;
9023 tree property_getter_ident
= NULL_TREE
;
9024 bool property_nonatomic
= false;
9025 bool property_readonly
= false;
9026 bool property_readwrite
= false;
9027 bool property_retain
= false;
9028 tree property_setter_ident
= NULL_TREE
;
9030 /* 'properties' is the list of properties that we read. Usually a
9031 single one, but maybe more (eg, in "@property int a, b, c;" there
9036 loc
= c_parser_peek_token (parser
)->location
;
9037 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9039 c_parser_consume_token (parser
); /* Eat '@property'. */
9041 /* Parse the optional attribute list... */
9042 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9045 c_parser_consume_token (parser
);
9047 /* Property attribute keywords are valid now. */
9048 parser
->objc_property_attr_context
= true;
9052 bool syntax_error
= false;
9053 c_token
*token
= c_parser_peek_token (parser
);
9056 if (token
->type
!= CPP_KEYWORD
)
9058 if (token
->type
== CPP_CLOSE_PAREN
)
9059 c_parser_error (parser
, "expected identifier");
9062 c_parser_consume_token (parser
);
9063 c_parser_error (parser
, "unknown property attribute");
9067 keyword
= token
->keyword
;
9068 c_parser_consume_token (parser
);
9071 case RID_ASSIGN
: property_assign
= true; break;
9072 case RID_COPY
: property_copy
= true; break;
9073 case RID_NONATOMIC
: property_nonatomic
= true; break;
9074 case RID_READONLY
: property_readonly
= true; break;
9075 case RID_READWRITE
: property_readwrite
= true; break;
9076 case RID_RETAIN
: property_retain
= true; break;
9080 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9082 if (keyword
== RID_GETTER
)
9083 c_parser_error (parser
,
9084 "missing %<=%> (after %<getter%> attribute)");
9086 c_parser_error (parser
,
9087 "missing %<=%> (after %<setter%> attribute)");
9088 syntax_error
= true;
9091 c_parser_consume_token (parser
); /* eat the = */
9092 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9094 c_parser_error (parser
, "expected identifier");
9095 syntax_error
= true;
9098 if (keyword
== RID_SETTER
)
9100 if (property_setter_ident
!= NULL_TREE
)
9101 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9103 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9104 c_parser_consume_token (parser
);
9105 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9106 c_parser_error (parser
, "setter name must terminate with %<:%>");
9108 c_parser_consume_token (parser
);
9112 if (property_getter_ident
!= NULL_TREE
)
9113 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9115 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9116 c_parser_consume_token (parser
);
9120 c_parser_error (parser
, "unknown property attribute");
9121 syntax_error
= true;
9128 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9129 c_parser_consume_token (parser
);
9133 parser
->objc_property_attr_context
= false;
9134 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9136 /* ... and the property declaration(s). */
9137 properties
= c_parser_struct_declaration (parser
);
9139 if (properties
== error_mark_node
)
9141 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9142 parser
->error
= false;
9146 if (properties
== NULL_TREE
)
9147 c_parser_error (parser
, "expected identifier");
9150 /* Comma-separated properties are chained together in
9151 reverse order; add them one by one. */
9152 properties
= nreverse (properties
);
9154 for (; properties
; properties
= TREE_CHAIN (properties
))
9155 objc_add_property_declaration (loc
, copy_node (properties
),
9156 property_readonly
, property_readwrite
,
9157 property_assign
, property_retain
,
9158 property_copy
, property_nonatomic
,
9159 property_getter_ident
, property_setter_ident
);
9162 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9163 parser
->error
= false;
9166 /* Parse an Objective-C @synthesize declaration. The syntax is:
9168 objc-synthesize-declaration:
9169 @synthesize objc-synthesize-identifier-list ;
9171 objc-synthesize-identifier-list:
9172 objc-synthesize-identifier
9173 objc-synthesize-identifier-list, objc-synthesize-identifier
9175 objc-synthesize-identifier
9177 identifier = identifier
9180 @synthesize MyProperty;
9181 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9183 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9184 for C++. Keep them in sync.
9187 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9189 tree list
= NULL_TREE
;
9191 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9192 loc
= c_parser_peek_token (parser
)->location
;
9194 c_parser_consume_token (parser
);
9197 tree property
, ivar
;
9198 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9200 c_parser_error (parser
, "expected identifier");
9201 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9202 /* Once we find the semicolon, we can resume normal parsing.
9203 We have to reset parser->error manually because
9204 c_parser_skip_until_found() won't reset it for us if the
9205 next token is precisely a semicolon. */
9206 parser
->error
= false;
9209 property
= c_parser_peek_token (parser
)->value
;
9210 c_parser_consume_token (parser
);
9211 if (c_parser_next_token_is (parser
, CPP_EQ
))
9213 c_parser_consume_token (parser
);
9214 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9216 c_parser_error (parser
, "expected identifier");
9217 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9218 parser
->error
= false;
9221 ivar
= c_parser_peek_token (parser
)->value
;
9222 c_parser_consume_token (parser
);
9226 list
= chainon (list
, build_tree_list (ivar
, property
));
9227 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9228 c_parser_consume_token (parser
);
9232 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9233 objc_add_synthesize_declaration (loc
, list
);
9236 /* Parse an Objective-C @dynamic declaration. The syntax is:
9238 objc-dynamic-declaration:
9239 @dynamic identifier-list ;
9242 @dynamic MyProperty;
9243 @dynamic MyProperty, AnotherProperty;
9245 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9246 for C++. Keep them in sync.
9249 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9251 tree list
= NULL_TREE
;
9253 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9254 loc
= c_parser_peek_token (parser
)->location
;
9256 c_parser_consume_token (parser
);
9260 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9262 c_parser_error (parser
, "expected identifier");
9263 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9264 parser
->error
= false;
9267 property
= c_parser_peek_token (parser
)->value
;
9268 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9269 c_parser_consume_token (parser
);
9270 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9271 c_parser_consume_token (parser
);
9275 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9276 objc_add_dynamic_declaration (loc
, list
);
9279 /* Parse UPC shared qualifier
9281 shared-type-qualifier: shared layout-qualifier-opt
9282 layout-qualifier: [ constant-expression-opt ] | [ * ]
9286 c_parser_upc_shared_qual (source_location loc
,
9288 struct c_declspecs
*specs
)
9290 tree array_qual
, arg1
;
9292 /* consume "shared" part */
9293 c_parser_consume_token (parser
);
9295 /* check for shared array layout specifier */
9296 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9298 declspecs_add_qual (loc
, specs
, ridpointers
[RID_SHARED
]);
9301 c_parser_consume_token (parser
);
9302 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9304 /* [] layout specifier */
9305 arg1
= size_zero_node
;
9307 else if (c_parser_next_token_is (parser
, CPP_MULT
))
9309 /* [*] layout specifier */
9310 arg1
= build1 (INDIRECT_REF
, NULL_TREE
, NULL_TREE
);
9311 c_parser_consume_token (parser
);
9315 /* [ expression ] layout specifier */
9316 arg1
= c_parser_expression (parser
).value
;
9318 array_qual
= build4 (ARRAY_REF
, NULL_TREE
, NULL_TREE
,
9319 arg1
, NULL_TREE
, NULL_TREE
);
9320 declspecs_add_qual (loc
, specs
, array_qual
);
9322 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9324 c_parser_error (parser
, "expected ]");
9326 c_parser_consume_token (parser
);
9329 /* Parse a UPC upc_forall statement
9331 upc_forall-statement:
9332 upc_forall ( expression[opt] ; expression[opt] ;
9333 expression[opt] ; affinity[opt] ) statement
9334 affinity: experssion | continue */
9337 c_parser_upc_forall_statement (c_parser
*parser
)
9339 tree block
, cond
, incr
, save_break
, save_cont
, body
;
9341 location_t loc
= c_parser_peek_token (parser
)->location
;
9342 location_t affinity_loc
= UNKNOWN_LOCATION
;
9343 const int profile_upc_forall
= flag_upc_instrument
&& get_upc_pupc_mode();
9344 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_FORALL
));
9345 c_parser_consume_token (parser
);
9346 block
= c_begin_compound_stmt (flag_isoc99
);
9347 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9349 /* Parse the initialization declaration or expression. */
9350 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9352 c_parser_consume_token (parser
);
9353 c_finish_expr_stmt (loc
, NULL_TREE
);
9355 else if (c_parser_next_token_starts_declspecs (parser
))
9357 c_parser_declaration_or_fndef (parser
, true, true, true,
9358 true, true, NULL
, vNULL
);
9359 check_for_loop_decls (loc
, true);
9361 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
9363 /* __extension__ can start a declaration, but is also an
9364 unary operator that can start an expression. Consume all
9365 but the last of a possible series of __extension__ to
9367 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
9368 && (c_parser_peek_2nd_token (parser
)->keyword
9370 c_parser_consume_token (parser
);
9371 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
9374 ext
= disable_extension_diagnostics ();
9375 c_parser_consume_token (parser
);
9376 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
9378 restore_extension_diagnostics (ext
);
9379 check_for_loop_decls (loc
, true);
9387 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
9388 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9390 /* Parse the loop condition. */
9391 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9393 c_parser_consume_token (parser
);
9398 cond
= c_parser_condition (parser
);
9399 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9401 /* Parse the increment expression. */
9402 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9403 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
9405 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
9406 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9407 /* Parse the UPC affinity expression. */
9408 affinity_loc
= c_parser_peek_token (parser
)->location
;
9409 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9411 affinity
= NULL_TREE
;
9413 else if (c_parser_peek_token (parser
)->type
== CPP_KEYWORD
9414 && c_parser_peek_token (parser
)->keyword
== RID_CONTINUE
)
9416 affinity
= NULL_TREE
;
9417 c_parser_consume_token (parser
);
9421 affinity
= c_parser_expression_conv (parser
).value
;
9422 affinity
= c_fully_fold (affinity
, false, NULL
);
9424 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9426 affinity
= upc_affinity_test (affinity_loc
, affinity
);
9430 cond
= error_mark_node
;
9431 incr
= error_mark_node
;
9432 affinity
= error_mark_node
;
9434 save_break
= c_break_label
;
9435 c_break_label
= NULL_TREE
;
9436 save_cont
= c_cont_label
;
9437 c_cont_label
= NULL_TREE
;
9438 body
= c_parser_c99_block_statement (parser
);
9439 if (profile_upc_forall
)
9441 const tree gasp_start
= upc_instrument_forall (loc
, 1 /* start */);
9442 add_stmt (gasp_start
);
9444 loc
= c_parser_peek_token (parser
)->location
;
9445 if (affinity
!= NULL_TREE
&& affinity
!= error_mark_node
)
9447 tree upc_forall_depth
= upc_rts_forall_depth_var ();
9448 tree inc_depth
, depth_gt_one
;
9449 inc_depth
= build_unary_op (loc
, PREINCREMENT_EXPR
, upc_forall_depth
, 0);
9450 c_finish_expr_stmt (loc
, inc_depth
);
9451 depth_gt_one
= build_binary_op (affinity_loc
,
9452 GT_EXPR
, upc_forall_depth
, integer_one_node
, 0);
9453 depth_gt_one
= c_objc_common_truthvalue_conversion (affinity_loc
, depth_gt_one
);
9454 depth_gt_one
= c_fully_fold (depth_gt_one
, false, NULL
);
9455 affinity
= build_binary_op (affinity_loc
, TRUTH_OR_EXPR
,
9456 depth_gt_one
, affinity
, 0);
9457 body
= build3 (COND_EXPR
, void_type_node
, affinity
,
9459 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
9460 c_finish_expr_stmt (loc
,
9461 build_unary_op (loc
, PREDECREMENT_EXPR
, upc_forall_depth
, 0));
9464 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
9465 if (profile_upc_forall
)
9467 const tree gasp_end
= upc_instrument_forall (loc
, 0 /* start */);
9468 add_stmt (gasp_end
);
9470 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
9471 c_break_label
= save_break
;
9472 c_cont_label
= save_cont
;
9475 /* Parse an upc-sync-statement.
9477 upc_barrier, upc_wait, upc_notify
9481 c_parser_upc_sync_statement (c_parser
*parser
, int sync_kind
)
9484 tree expr
= NULL_TREE
;
9486 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_BARRIER
) ||
9487 c_parser_next_token_is_keyword (parser
, RID_UPC_NOTIFY
) ||
9488 c_parser_next_token_is_keyword (parser
, RID_UPC_WAIT
));
9489 loc
= c_parser_peek_token (parser
)->location
;
9490 c_parser_consume_token (parser
);
9491 if (c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
9493 loc
= c_parser_peek_token (parser
)->location
;
9494 expr
= c_parser_expression (parser
).value
;
9495 if (expr
== error_mark_node
)
9498 stmt
= size_int (sync_kind
);
9499 (void) upc_build_sync_stmt (loc
, stmt
, expr
);
9503 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9504 should be considered, statements. ALLOW_STMT is true if we're within
9505 the context of a function and such pragmas are to be allowed. Returns
9506 true if we actually parsed such a pragma. */
9509 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9513 id
= c_parser_peek_token (parser
)->pragma_kind
;
9514 gcc_assert (id
!= PRAGMA_NONE
);
9518 case PRAGMA_OMP_BARRIER
:
9519 if (context
!= pragma_compound
)
9521 if (context
== pragma_stmt
)
9522 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9523 "used in compound statements");
9526 c_parser_omp_barrier (parser
);
9529 case PRAGMA_OMP_FLUSH
:
9530 if (context
!= pragma_compound
)
9532 if (context
== pragma_stmt
)
9533 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9534 "used in compound statements");
9537 c_parser_omp_flush (parser
);
9540 case PRAGMA_OMP_TASKWAIT
:
9541 if (context
!= pragma_compound
)
9543 if (context
== pragma_stmt
)
9544 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9545 "used in compound statements");
9548 c_parser_omp_taskwait (parser
);
9551 case PRAGMA_OMP_TASKYIELD
:
9552 if (context
!= pragma_compound
)
9554 if (context
== pragma_stmt
)
9555 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9556 "used in compound statements");
9559 c_parser_omp_taskyield (parser
);
9562 case PRAGMA_OMP_CANCEL
:
9563 if (context
!= pragma_compound
)
9565 if (context
== pragma_stmt
)
9566 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9567 "used in compound statements");
9570 c_parser_omp_cancel (parser
);
9573 case PRAGMA_OMP_CANCELLATION_POINT
:
9574 if (context
!= pragma_compound
)
9576 if (context
== pragma_stmt
)
9577 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9578 "only be used in compound statements");
9581 c_parser_omp_cancellation_point (parser
);
9584 case PRAGMA_OMP_THREADPRIVATE
:
9585 c_parser_omp_threadprivate (parser
);
9588 case PRAGMA_OMP_TARGET
:
9589 return c_parser_omp_target (parser
, context
);
9591 case PRAGMA_OMP_END_DECLARE_TARGET
:
9592 c_parser_omp_end_declare_target (parser
);
9595 case PRAGMA_OMP_SECTION
:
9596 error_at (c_parser_peek_token (parser
)->location
,
9597 "%<#pragma omp section%> may only be used in "
9598 "%<#pragma omp sections%> construct");
9599 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9602 case PRAGMA_OMP_DECLARE_REDUCTION
:
9603 c_parser_omp_declare (parser
, context
);
9606 c_parser_consume_pragma (parser
);
9607 c_parser_skip_to_pragma_eol (parser
);
9608 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9609 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9610 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9612 c_parser_error (parser
, "for, while or do statement expected");
9615 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9616 c_parser_for_statement (parser
, true);
9617 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9618 c_parser_while_statement (parser
, true);
9620 c_parser_do_statement (parser
, true);
9623 case PRAGMA_GCC_PCH_PREPROCESS
:
9624 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9625 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9629 if (id
< PRAGMA_FIRST_EXTERNAL
)
9631 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9634 c_parser_error (parser
, "expected declaration specifiers");
9635 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9638 c_parser_omp_construct (parser
);
9644 c_parser_consume_pragma (parser
);
9645 c_invoke_pragma_handler (id
);
9647 /* Skip to EOL, but suppress any error message. Those will have been
9648 generated by the handler routine through calling error, as opposed
9649 to calling c_parser_error. */
9650 parser
->error
= true;
9651 c_parser_skip_to_pragma_eol (parser
);
9656 /* The interface the pragma parsers have to the lexer. */
9659 pragma_lex (tree
*value
)
9661 c_token
*tok
= c_parser_peek_token (the_parser
);
9662 enum cpp_ttype ret
= tok
->type
;
9664 *value
= tok
->value
;
9665 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9669 if (ret
== CPP_KEYWORD
)
9671 c_parser_consume_token (the_parser
);
9678 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9682 c_parser_consume_pragma (parser
);
9683 if (c_parser_next_token_is (parser
, CPP_STRING
))
9685 name
= c_parser_peek_token (parser
)->value
;
9686 c_parser_consume_token (parser
);
9689 c_parser_error (parser
, "expected string literal");
9690 c_parser_skip_to_pragma_eol (parser
);
9693 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9696 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9698 /* Returns name of the next clause.
9699 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9700 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9701 returned and the token is consumed. */
9703 static pragma_omp_clause
9704 c_parser_omp_clause_name (c_parser
*parser
)
9706 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9708 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9709 result
= PRAGMA_OMP_CLAUSE_IF
;
9710 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9711 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9712 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9713 result
= PRAGMA_OMP_CLAUSE_FOR
;
9714 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9716 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9721 if (!strcmp ("aligned", p
))
9722 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9725 if (!strcmp ("collapse", p
))
9726 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9727 else if (!strcmp ("copyin", p
))
9728 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9729 else if (!strcmp ("copyprivate", p
))
9730 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9733 if (!strcmp ("depend", p
))
9734 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9735 else if (!strcmp ("device", p
))
9736 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9737 else if (!strcmp ("dist_schedule", p
))
9738 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9741 if (!strcmp ("final", p
))
9742 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9743 else if (!strcmp ("firstprivate", p
))
9744 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9745 else if (!strcmp ("from", p
))
9746 result
= PRAGMA_OMP_CLAUSE_FROM
;
9749 if (!strcmp ("inbranch", p
))
9750 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9753 if (!strcmp ("lastprivate", p
))
9754 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9755 else if (!strcmp ("linear", p
))
9756 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9759 if (!strcmp ("map", p
))
9760 result
= PRAGMA_OMP_CLAUSE_MAP
;
9761 else if (!strcmp ("mergeable", p
))
9762 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9765 if (!strcmp ("notinbranch", p
))
9766 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9767 else if (!strcmp ("nowait", p
))
9768 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9769 else if (!strcmp ("num_teams", p
))
9770 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9771 else if (!strcmp ("num_threads", p
))
9772 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9775 if (!strcmp ("ordered", p
))
9776 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9779 if (!strcmp ("parallel", p
))
9780 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9781 else if (!strcmp ("private", p
))
9782 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9783 else if (!strcmp ("proc_bind", p
))
9784 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9787 if (!strcmp ("reduction", p
))
9788 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9791 if (!strcmp ("safelen", p
))
9792 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9793 else if (!strcmp ("schedule", p
))
9794 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9795 else if (!strcmp ("sections", p
))
9796 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9797 else if (!strcmp ("shared", p
))
9798 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9799 else if (!strcmp ("simdlen", p
))
9800 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9803 if (!strcmp ("taskgroup", p
))
9804 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9805 else if (!strcmp ("thread_limit", p
))
9806 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9807 else if (!strcmp ("to", p
))
9808 result
= PRAGMA_OMP_CLAUSE_TO
;
9811 if (!strcmp ("uniform", p
))
9812 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9813 else if (!strcmp ("untied", p
))
9814 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9819 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9820 c_parser_consume_token (parser
);
9825 /* Validate that a clause of the given type does not already exist. */
9828 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9833 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9834 if (OMP_CLAUSE_CODE (c
) == code
)
9836 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9837 error_at (loc
, "too many %qs clauses", name
);
9845 variable-list , identifier
9847 If KIND is nonzero, create the appropriate node and install the
9848 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9849 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9851 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9852 return the list created. */
9855 c_parser_omp_variable_list (c_parser
*parser
,
9856 location_t clause_loc
,
9857 enum omp_clause_code kind
, tree list
)
9859 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9860 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9861 c_parser_error (parser
, "expected identifier");
9863 while (c_parser_next_token_is (parser
, CPP_NAME
)
9864 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9866 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9870 undeclared_variable (c_parser_peek_token (parser
)->location
,
9871 c_parser_peek_token (parser
)->value
);
9872 t
= error_mark_node
;
9875 c_parser_consume_token (parser
);
9877 if (t
== error_mark_node
)
9883 case OMP_CLAUSE_MAP
:
9884 case OMP_CLAUSE_FROM
:
9886 case OMP_CLAUSE_DEPEND
:
9887 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9889 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9891 c_parser_consume_token (parser
);
9892 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9893 low_bound
= c_parser_expression (parser
).value
;
9894 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9895 length
= integer_one_node
;
9899 if (!c_parser_require (parser
, CPP_COLON
,
9902 t
= error_mark_node
;
9905 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9906 length
= c_parser_expression (parser
).value
;
9908 /* Look for the closing `]'. */
9909 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9912 t
= error_mark_node
;
9915 t
= tree_cons (low_bound
, length
, t
);
9922 if (t
!= error_mark_node
)
9924 tree u
= build_omp_clause (clause_loc
, kind
);
9925 OMP_CLAUSE_DECL (u
) = t
;
9926 OMP_CLAUSE_CHAIN (u
) = list
;
9931 list
= tree_cons (t
, NULL_TREE
, list
);
9933 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9936 c_parser_consume_token (parser
);
9942 /* Similarly, but expect leading and trailing parenthesis. This is a very
9943 common case for omp clauses. */
9946 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9949 /* The clauses location. */
9950 location_t loc
= c_parser_peek_token (parser
)->location
;
9952 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9954 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9955 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9961 collapse ( constant-expression ) */
9964 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9966 tree c
, num
= error_mark_node
;
9970 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9972 loc
= c_parser_peek_token (parser
)->location
;
9973 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9975 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9976 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9978 if (num
== error_mark_node
)
9980 mark_exp_read (num
);
9981 num
= c_fully_fold (num
, false, NULL
);
9982 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9983 || !host_integerp (num
, 0)
9984 || (n
= tree_low_cst (num
, 0)) <= 0
9988 "collapse argument needs positive constant integer expression");
9991 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9992 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9993 OMP_CLAUSE_CHAIN (c
) = list
;
9998 copyin ( variable-list ) */
10001 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
10003 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
10007 copyprivate ( variable-list ) */
10010 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
10012 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
10016 default ( shared | none ) */
10019 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
10021 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
10022 location_t loc
= c_parser_peek_token (parser
)->location
;
10025 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10027 if (c_parser_next_token_is (parser
, CPP_NAME
))
10029 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10034 if (strcmp ("none", p
) != 0)
10036 kind
= OMP_CLAUSE_DEFAULT_NONE
;
10040 if (strcmp ("shared", p
) != 0)
10042 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
10049 c_parser_consume_token (parser
);
10054 c_parser_error (parser
, "expected %<none%> or %<shared%>");
10056 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10058 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
10061 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
10062 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
10063 OMP_CLAUSE_CHAIN (c
) = list
;
10064 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
10070 firstprivate ( variable-list ) */
10073 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
10075 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
10079 final ( expression ) */
10082 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
10084 location_t loc
= c_parser_peek_token (parser
)->location
;
10085 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10087 tree t
= c_parser_paren_condition (parser
);
10090 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
10092 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
10093 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
10094 OMP_CLAUSE_CHAIN (c
) = list
;
10098 c_parser_error (parser
, "expected %<(%>");
10104 if ( expression ) */
10107 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
10109 location_t loc
= c_parser_peek_token (parser
)->location
;
10110 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10112 tree t
= c_parser_paren_condition (parser
);
10115 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
10117 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10118 OMP_CLAUSE_IF_EXPR (c
) = t
;
10119 OMP_CLAUSE_CHAIN (c
) = list
;
10123 c_parser_error (parser
, "expected %<(%>");
10129 lastprivate ( variable-list ) */
10132 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10134 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10141 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10145 /* FIXME: Should we allow duplicates? */
10146 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10148 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10149 OMP_CLAUSE_MERGEABLE
);
10150 OMP_CLAUSE_CHAIN (c
) = list
;
10159 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10162 location_t loc
= c_parser_peek_token (parser
)->location
;
10164 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10166 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10167 OMP_CLAUSE_CHAIN (c
) = list
;
10172 num_threads ( expression ) */
10175 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10177 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10178 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10180 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10181 tree c
, t
= c_parser_expression (parser
).value
;
10183 t
= c_fully_fold (t
, false, NULL
);
10185 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10187 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10189 c_parser_error (parser
, "expected integer expression");
10193 /* Attempt to statically determine when the number isn't positive. */
10194 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10195 build_int_cst (TREE_TYPE (t
), 0));
10196 if (CAN_HAVE_LOCATION_P (c
))
10197 SET_EXPR_LOCATION (c
, expr_loc
);
10198 if (c
== boolean_true_node
)
10200 warning_at (expr_loc
, 0,
10201 "%<num_threads%> value must be positive");
10202 t
= integer_one_node
;
10205 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10207 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10208 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10209 OMP_CLAUSE_CHAIN (c
) = list
;
10220 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10224 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10226 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10227 OMP_CLAUSE_ORDERED
);
10228 OMP_CLAUSE_CHAIN (c
) = list
;
10234 private ( variable-list ) */
10237 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10239 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10243 reduction ( reduction-operator : variable-list )
10245 reduction-operator:
10246 One of: + * - & ^ | && ||
10250 reduction-operator:
10251 One of: + * - & ^ | && || max min
10255 reduction-operator:
10256 One of: + * - & ^ | && ||
10260 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10262 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10263 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10265 enum tree_code code
= ERROR_MARK
;
10266 tree reduc_id
= NULL_TREE
;
10268 switch (c_parser_peek_token (parser
)->type
)
10280 code
= BIT_AND_EXPR
;
10283 code
= BIT_XOR_EXPR
;
10286 code
= BIT_IOR_EXPR
;
10289 code
= TRUTH_ANDIF_EXPR
;
10292 code
= TRUTH_ORIF_EXPR
;
10297 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10298 if (strcmp (p
, "min") == 0)
10303 if (strcmp (p
, "max") == 0)
10308 reduc_id
= c_parser_peek_token (parser
)->value
;
10312 c_parser_error (parser
,
10313 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10314 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10315 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10318 c_parser_consume_token (parser
);
10319 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10320 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10324 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10325 OMP_CLAUSE_REDUCTION
, list
);
10326 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10328 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10329 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10330 if (code
== ERROR_MARK
10331 || !(INTEGRAL_TYPE_P (type
)
10332 || TREE_CODE (type
) == REAL_TYPE
10333 || TREE_CODE (type
) == COMPLEX_TYPE
))
10334 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10335 = c_omp_reduction_lookup (reduc_id
,
10336 TYPE_MAIN_VARIANT (type
));
10341 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10347 schedule ( schedule-kind )
10348 schedule ( schedule-kind , expression )
10351 static | dynamic | guided | runtime | auto
10355 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10358 location_t loc
= c_parser_peek_token (parser
)->location
;
10360 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10363 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10365 if (c_parser_next_token_is (parser
, CPP_NAME
))
10367 tree kind
= c_parser_peek_token (parser
)->value
;
10368 const char *p
= IDENTIFIER_POINTER (kind
);
10373 if (strcmp ("dynamic", p
) != 0)
10375 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10379 if (strcmp ("guided", p
) != 0)
10381 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10385 if (strcmp ("runtime", p
) != 0)
10387 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10394 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10395 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10396 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10397 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10401 c_parser_consume_token (parser
);
10402 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10405 c_parser_consume_token (parser
);
10407 here
= c_parser_peek_token (parser
)->location
;
10408 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10410 t
= c_fully_fold (t
, false, NULL
);
10412 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10413 error_at (here
, "schedule %<runtime%> does not take "
10414 "a %<chunk_size%> parameter");
10415 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10417 "schedule %<auto%> does not take "
10418 "a %<chunk_size%> parameter");
10419 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10420 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10422 c_parser_error (parser
, "expected integer expression");
10424 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10427 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10428 "expected %<,%> or %<)%>");
10430 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10431 OMP_CLAUSE_CHAIN (c
) = list
;
10435 c_parser_error (parser
, "invalid schedule kind");
10436 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10441 shared ( variable-list ) */
10444 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10446 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10453 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10457 /* FIXME: Should we allow duplicates? */
10458 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10460 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10461 OMP_CLAUSE_UNTIED
);
10462 OMP_CLAUSE_CHAIN (c
) = list
;
10472 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10473 enum omp_clause_code code
, tree list
)
10475 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10477 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10478 OMP_CLAUSE_CHAIN (c
) = list
;
10490 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10491 enum omp_clause_code code
, tree list
)
10493 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10494 OMP_CLAUSE_CHAIN (c
) = list
;
10500 num_teams ( expression ) */
10503 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10505 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10506 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10508 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10509 tree c
, t
= c_parser_expression (parser
).value
;
10511 t
= c_fully_fold (t
, false, NULL
);
10513 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10515 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10517 c_parser_error (parser
, "expected integer expression");
10521 /* Attempt to statically determine when the number isn't positive. */
10522 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10523 build_int_cst (TREE_TYPE (t
), 0));
10524 if (CAN_HAVE_LOCATION_P (c
))
10525 SET_EXPR_LOCATION (c
, expr_loc
);
10526 if (c
== boolean_true_node
)
10528 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10529 t
= integer_one_node
;
10532 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10534 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10535 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10536 OMP_CLAUSE_CHAIN (c
) = list
;
10544 thread_limit ( expression ) */
10547 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10549 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10550 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10552 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10553 tree c
, t
= c_parser_expression (parser
).value
;
10555 t
= c_fully_fold (t
, false, NULL
);
10557 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10559 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10561 c_parser_error (parser
, "expected integer expression");
10565 /* Attempt to statically determine when the number isn't positive. */
10566 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10567 build_int_cst (TREE_TYPE (t
), 0));
10568 if (CAN_HAVE_LOCATION_P (c
))
10569 SET_EXPR_LOCATION (c
, expr_loc
);
10570 if (c
== boolean_true_node
)
10572 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10573 t
= integer_one_node
;
10576 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10579 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10580 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10581 OMP_CLAUSE_CHAIN (c
) = list
;
10589 aligned ( variable-list )
10590 aligned ( variable-list : constant-expression ) */
10593 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10595 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10598 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10601 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10602 OMP_CLAUSE_ALIGNED
, list
);
10604 if (c_parser_next_token_is (parser
, CPP_COLON
))
10606 c_parser_consume_token (parser
);
10607 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10608 mark_exp_read (alignment
);
10609 alignment
= c_fully_fold (alignment
, false, NULL
);
10610 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10611 && TREE_CODE (alignment
) != INTEGER_CST
10612 && tree_int_cst_sgn (alignment
) != 1)
10614 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10615 "be positive constant integer expression");
10616 alignment
= NULL_TREE
;
10619 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10620 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10623 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10628 linear ( variable-list )
10629 linear ( variable-list : expression ) */
10632 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
10634 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10637 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10640 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10641 OMP_CLAUSE_LINEAR
, list
);
10643 if (c_parser_next_token_is (parser
, CPP_COLON
))
10645 c_parser_consume_token (parser
);
10646 step
= c_parser_expression (parser
).value
;
10647 mark_exp_read (step
);
10648 step
= c_fully_fold (step
, false, NULL
);
10649 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10651 error_at (clause_loc
, "%<linear%> clause step expression must "
10653 step
= integer_one_node
;
10658 step
= integer_one_node
;
10660 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10662 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10665 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10670 safelen ( constant-expression ) */
10673 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10675 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10678 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10681 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10683 t
= c_fully_fold (t
, false, NULL
);
10684 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10685 && TREE_CODE (t
) != INTEGER_CST
10686 && tree_int_cst_sgn (t
) != 1)
10688 error_at (clause_loc
, "%<safelen%> clause expression must "
10689 "be positive constant integer expression");
10693 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10694 if (t
== NULL_TREE
|| t
== error_mark_node
)
10697 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10699 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10700 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10701 OMP_CLAUSE_CHAIN (c
) = list
;
10706 simdlen ( constant-expression ) */
10709 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10711 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10714 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10717 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10719 t
= c_fully_fold (t
, false, NULL
);
10720 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10721 && TREE_CODE (t
) != INTEGER_CST
10722 && tree_int_cst_sgn (t
) != 1)
10724 error_at (clause_loc
, "%<simdlen%> clause expression must "
10725 "be positive constant integer expression");
10729 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10730 if (t
== NULL_TREE
|| t
== error_mark_node
)
10733 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10735 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10736 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10737 OMP_CLAUSE_CHAIN (c
) = list
;
10742 depend ( depend-kind: variable-list )
10745 in | out | inout */
10748 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10750 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10751 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10754 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10757 if (c_parser_next_token_is (parser
, CPP_NAME
))
10759 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10760 if (strcmp ("in", p
) == 0)
10761 kind
= OMP_CLAUSE_DEPEND_IN
;
10762 else if (strcmp ("inout", p
) == 0)
10763 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10764 else if (strcmp ("out", p
) == 0)
10765 kind
= OMP_CLAUSE_DEPEND_OUT
;
10772 c_parser_consume_token (parser
);
10773 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10776 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10777 OMP_CLAUSE_DEPEND
, list
);
10779 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10780 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10782 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10786 c_parser_error (parser
, "invalid depend kind");
10788 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10793 map ( map-kind: variable-list )
10794 map ( variable-list )
10797 alloc | to | from | tofrom */
10800 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10802 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10803 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10806 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10809 if (c_parser_next_token_is (parser
, CPP_NAME
)
10810 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10812 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10813 if (strcmp ("alloc", p
) == 0)
10814 kind
= OMP_CLAUSE_MAP_ALLOC
;
10815 else if (strcmp ("to", p
) == 0)
10816 kind
= OMP_CLAUSE_MAP_TO
;
10817 else if (strcmp ("from", p
) == 0)
10818 kind
= OMP_CLAUSE_MAP_FROM
;
10819 else if (strcmp ("tofrom", p
) == 0)
10820 kind
= OMP_CLAUSE_MAP_TOFROM
;
10823 c_parser_error (parser
, "invalid map kind");
10824 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10828 c_parser_consume_token (parser
);
10829 c_parser_consume_token (parser
);
10832 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10834 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10835 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10837 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10842 device ( expression ) */
10845 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10847 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10848 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10850 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10852 t
= c_fully_fold (t
, false, NULL
);
10854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10856 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10858 c_parser_error (parser
, "expected integer expression");
10862 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10864 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10865 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10866 OMP_CLAUSE_CHAIN (c
) = list
;
10874 dist_schedule ( static )
10875 dist_schedule ( static , expression ) */
10878 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10880 tree c
, t
= NULL_TREE
;
10881 location_t loc
= c_parser_peek_token (parser
)->location
;
10883 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10886 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10888 c_parser_error (parser
, "invalid dist_schedule kind");
10889 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10894 c_parser_consume_token (parser
);
10895 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10897 c_parser_consume_token (parser
);
10899 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10901 t
= c_fully_fold (t
, false, NULL
);
10902 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10905 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10906 "expected %<,%> or %<)%>");
10908 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10909 if (t
== error_mark_node
)
10912 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10913 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10914 OMP_CLAUSE_CHAIN (c
) = list
;
10919 proc_bind ( proc-bind-kind )
10922 master | close | spread */
10925 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10927 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10928 enum omp_clause_proc_bind_kind kind
;
10931 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10934 if (c_parser_next_token_is (parser
, CPP_NAME
))
10936 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10937 if (strcmp ("master", p
) == 0)
10938 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10939 else if (strcmp ("close", p
) == 0)
10940 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10941 else if (strcmp ("spread", p
) == 0)
10942 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10949 c_parser_consume_token (parser
);
10950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10951 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10952 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10953 OMP_CLAUSE_CHAIN (c
) = list
;
10957 c_parser_error (parser
, "invalid proc_bind kind");
10958 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10963 to ( variable-list ) */
10966 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10968 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10972 from ( variable-list ) */
10975 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10977 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10981 uniform ( variable-list ) */
10984 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10986 /* The clauses location. */
10987 location_t loc
= c_parser_peek_token (parser
)->location
;
10989 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10991 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10993 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10998 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10999 is a bitmask in MASK. Return the list of clauses found; the result
11000 of clause default goes in *pdefault. */
11003 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
11004 const char *where
, bool finish_p
= true)
11006 tree clauses
= NULL
;
11009 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11012 pragma_omp_clause c_kind
;
11013 const char *c_name
;
11014 tree prev
= clauses
;
11016 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
11017 c_parser_consume_token (parser
);
11019 here
= c_parser_peek_token (parser
)->location
;
11020 c_kind
= c_parser_omp_clause_name (parser
);
11024 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
11025 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
11026 c_name
= "collapse";
11028 case PRAGMA_OMP_CLAUSE_COPYIN
:
11029 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
11032 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
11033 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
11034 c_name
= "copyprivate";
11036 case PRAGMA_OMP_CLAUSE_DEFAULT
:
11037 clauses
= c_parser_omp_clause_default (parser
, clauses
);
11038 c_name
= "default";
11040 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
11041 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
11042 c_name
= "firstprivate";
11044 case PRAGMA_OMP_CLAUSE_FINAL
:
11045 clauses
= c_parser_omp_clause_final (parser
, clauses
);
11048 case PRAGMA_OMP_CLAUSE_IF
:
11049 clauses
= c_parser_omp_clause_if (parser
, clauses
);
11052 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
11053 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
11054 c_name
= "lastprivate";
11056 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
11057 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
11058 c_name
= "mergeable";
11060 case PRAGMA_OMP_CLAUSE_NOWAIT
:
11061 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
11064 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
11065 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
11066 c_name
= "num_threads";
11068 case PRAGMA_OMP_CLAUSE_ORDERED
:
11069 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
11070 c_name
= "ordered";
11072 case PRAGMA_OMP_CLAUSE_PRIVATE
:
11073 clauses
= c_parser_omp_clause_private (parser
, clauses
);
11074 c_name
= "private";
11076 case PRAGMA_OMP_CLAUSE_REDUCTION
:
11077 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
11078 c_name
= "reduction";
11080 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
11081 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
11082 c_name
= "schedule";
11084 case PRAGMA_OMP_CLAUSE_SHARED
:
11085 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
11088 case PRAGMA_OMP_CLAUSE_UNTIED
:
11089 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
11092 case PRAGMA_OMP_CLAUSE_INBRANCH
:
11093 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
11095 c_name
= "inbranch";
11097 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
11098 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
11100 c_name
= "notinbranch";
11102 case PRAGMA_OMP_CLAUSE_PARALLEL
:
11104 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
11106 c_name
= "parallel";
11110 error_at (here
, "%qs must be the first clause of %qs",
11115 case PRAGMA_OMP_CLAUSE_FOR
:
11117 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11121 goto clause_not_first
;
11123 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11125 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11127 c_name
= "sections";
11129 goto clause_not_first
;
11131 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11133 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11135 c_name
= "taskgroup";
11137 goto clause_not_first
;
11139 case PRAGMA_OMP_CLAUSE_TO
:
11140 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11143 case PRAGMA_OMP_CLAUSE_FROM
:
11144 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11147 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11148 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11149 c_name
= "uniform";
11151 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11152 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11153 c_name
= "num_teams";
11155 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11156 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11157 c_name
= "thread_limit";
11159 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11160 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11161 c_name
= "aligned";
11163 case PRAGMA_OMP_CLAUSE_LINEAR
:
11164 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
11167 case PRAGMA_OMP_CLAUSE_DEPEND
:
11168 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11171 case PRAGMA_OMP_CLAUSE_MAP
:
11172 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11175 case PRAGMA_OMP_CLAUSE_DEVICE
:
11176 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11179 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11180 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11181 c_name
= "dist_schedule";
11183 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11184 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11185 c_name
= "proc_bind";
11187 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11188 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11189 c_name
= "safelen";
11191 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11192 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11193 c_name
= "simdlen";
11196 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11202 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11204 /* Remove the invalid clause(s) from the list to avoid
11205 confusing the rest of the compiler. */
11207 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11212 c_parser_skip_to_pragma_eol (parser
);
11215 return c_finish_omp_clauses (clauses
);
11224 In practice, we're also interested in adding the statement to an
11225 outer node. So it is convenient if we work around the fact that
11226 c_parser_statement calls add_stmt. */
11229 c_parser_omp_structured_block (c_parser
*parser
)
11231 tree stmt
= push_stmt_list ();
11232 c_parser_statement (parser
);
11233 return pop_stmt_list (stmt
);
11237 # pragma omp atomic new-line
11241 x binop= expr | x++ | ++x | x-- | --x
11243 +, *, -, /, &, ^, |, <<, >>
11245 where x is an lvalue expression with scalar type.
11248 # pragma omp atomic new-line
11251 # pragma omp atomic read new-line
11254 # pragma omp atomic write new-line
11257 # pragma omp atomic update new-line
11260 # pragma omp atomic capture new-line
11263 # pragma omp atomic capture new-line
11271 expression-stmt | x = x binop expr
11273 v = expression-stmt
11275 { v = x; update-stmt; } | { update-stmt; v = x; }
11279 expression-stmt | x = x binop expr | x = expr binop x
11283 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11285 where x and v are lvalue expressions with scalar type.
11287 LOC is the location of the #pragma token. */
11290 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11292 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11293 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11294 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11295 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11296 struct c_expr expr
;
11298 bool structured_block
= false;
11299 bool swapped
= false;
11300 bool seq_cst
= false;
11302 if (c_parser_next_token_is (parser
, CPP_NAME
))
11304 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11306 if (!strcmp (p
, "read"))
11307 code
= OMP_ATOMIC_READ
;
11308 else if (!strcmp (p
, "write"))
11310 else if (!strcmp (p
, "update"))
11312 else if (!strcmp (p
, "capture"))
11313 code
= OMP_ATOMIC_CAPTURE_NEW
;
11317 c_parser_consume_token (parser
);
11319 if (c_parser_next_token_is (parser
, CPP_NAME
))
11321 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11322 if (!strcmp (p
, "seq_cst"))
11325 c_parser_consume_token (parser
);
11328 c_parser_skip_to_pragma_eol (parser
);
11332 case OMP_ATOMIC_READ
:
11333 case NOP_EXPR
: /* atomic write */
11334 v
= c_parser_unary_expression (parser
).value
;
11335 v
= c_fully_fold (v
, false, NULL
);
11336 if (v
== error_mark_node
)
11338 loc
= c_parser_peek_token (parser
)->location
;
11339 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11341 if (code
== NOP_EXPR
)
11342 lhs
= c_parser_expression (parser
).value
;
11344 lhs
= c_parser_unary_expression (parser
).value
;
11345 lhs
= c_fully_fold (lhs
, false, NULL
);
11346 if (lhs
== error_mark_node
)
11348 if (code
== NOP_EXPR
)
11350 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11358 case OMP_ATOMIC_CAPTURE_NEW
:
11359 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11361 c_parser_consume_token (parser
);
11362 structured_block
= true;
11366 v
= c_parser_unary_expression (parser
).value
;
11367 v
= c_fully_fold (v
, false, NULL
);
11368 if (v
== error_mark_node
)
11370 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11378 /* For structured_block case we don't know yet whether
11379 old or new x should be captured. */
11381 eloc
= c_parser_peek_token (parser
)->location
;
11382 expr
= c_parser_unary_expression (parser
);
11384 expr
= default_function_array_conversion (eloc
, expr
);
11385 unfolded_lhs
= expr
.value
;
11386 lhs
= c_fully_fold (lhs
, false, NULL
);
11388 switch (TREE_CODE (lhs
))
11392 c_parser_skip_to_end_of_block_or_statement (parser
);
11393 if (structured_block
)
11395 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11396 c_parser_consume_token (parser
);
11397 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11399 c_parser_skip_to_end_of_block_or_statement (parser
);
11400 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11401 c_parser_consume_token (parser
);
11406 case POSTINCREMENT_EXPR
:
11407 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11408 code
= OMP_ATOMIC_CAPTURE_OLD
;
11410 case PREINCREMENT_EXPR
:
11411 lhs
= TREE_OPERAND (lhs
, 0);
11412 unfolded_lhs
= NULL_TREE
;
11413 opcode
= PLUS_EXPR
;
11414 rhs
= integer_one_node
;
11417 case POSTDECREMENT_EXPR
:
11418 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11419 code
= OMP_ATOMIC_CAPTURE_OLD
;
11421 case PREDECREMENT_EXPR
:
11422 lhs
= TREE_OPERAND (lhs
, 0);
11423 unfolded_lhs
= NULL_TREE
;
11424 opcode
= MINUS_EXPR
;
11425 rhs
= integer_one_node
;
11428 case COMPOUND_EXPR
:
11429 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11430 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11431 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11432 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11433 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11434 (TREE_OPERAND (lhs
, 1), 0), 0)))
11436 /* Undo effects of boolean_increment for post {in,de}crement. */
11437 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11440 if (TREE_CODE (lhs
) == MODIFY_EXPR
11441 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11443 /* Undo effects of boolean_increment. */
11444 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11446 /* This is pre or post increment. */
11447 rhs
= TREE_OPERAND (lhs
, 1);
11448 lhs
= TREE_OPERAND (lhs
, 0);
11449 unfolded_lhs
= NULL_TREE
;
11451 if (code
== OMP_ATOMIC_CAPTURE_NEW
11452 && !structured_block
11453 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11454 code
= OMP_ATOMIC_CAPTURE_OLD
;
11457 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11458 && TREE_OPERAND (lhs
, 0)
11459 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11461 /* This is pre or post decrement. */
11462 rhs
= TREE_OPERAND (lhs
, 1);
11463 lhs
= TREE_OPERAND (lhs
, 0);
11464 unfolded_lhs
= NULL_TREE
;
11466 if (code
== OMP_ATOMIC_CAPTURE_NEW
11467 && !structured_block
11468 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11469 code
= OMP_ATOMIC_CAPTURE_OLD
;
11475 switch (c_parser_peek_token (parser
)->type
)
11478 opcode
= MULT_EXPR
;
11481 opcode
= TRUNC_DIV_EXPR
;
11484 opcode
= PLUS_EXPR
;
11487 opcode
= MINUS_EXPR
;
11489 case CPP_LSHIFT_EQ
:
11490 opcode
= LSHIFT_EXPR
;
11492 case CPP_RSHIFT_EQ
:
11493 opcode
= RSHIFT_EXPR
;
11496 opcode
= BIT_AND_EXPR
;
11499 opcode
= BIT_IOR_EXPR
;
11502 opcode
= BIT_XOR_EXPR
;
11505 c_parser_consume_token (parser
);
11506 eloc
= c_parser_peek_token (parser
)->location
;
11507 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11509 switch (TREE_CODE (rhs1
))
11512 case TRUNC_DIV_EXPR
:
11520 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11522 opcode
= TREE_CODE (rhs1
);
11523 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11524 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11527 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11529 opcode
= TREE_CODE (rhs1
);
11530 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11531 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11532 swapped
= !commutative_tree_code (opcode
);
11541 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11543 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11545 code
= OMP_ATOMIC_CAPTURE_OLD
;
11548 expr
= default_function_array_read_conversion (eloc
, expr
);
11549 unfolded_lhs1
= expr
.value
;
11550 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11552 c_parser_consume_token (parser
);
11555 if (structured_block
)
11558 expr
= default_function_array_read_conversion (eloc
, expr
);
11559 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11564 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11567 c_parser_error (parser
,
11568 "invalid operator for %<#pragma omp atomic%>");
11572 /* Arrange to pass the location of the assignment operator to
11573 c_finish_omp_atomic. */
11574 loc
= c_parser_peek_token (parser
)->location
;
11575 c_parser_consume_token (parser
);
11576 eloc
= c_parser_peek_token (parser
)->location
;
11577 expr
= c_parser_expression (parser
);
11578 expr
= default_function_array_read_conversion (eloc
, expr
);
11580 rhs
= c_fully_fold (rhs
, false, NULL
);
11584 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11586 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11588 v
= c_parser_unary_expression (parser
).value
;
11589 v
= c_fully_fold (v
, false, NULL
);
11590 if (v
== error_mark_node
)
11592 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11594 eloc
= c_parser_peek_token (parser
)->location
;
11595 expr
= c_parser_unary_expression (parser
);
11597 expr
= default_function_array_read_conversion (eloc
, expr
);
11598 unfolded_lhs1
= expr
.value
;
11599 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11600 if (lhs1
== error_mark_node
)
11603 if (structured_block
)
11605 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11606 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11609 if (unfolded_lhs
&& unfolded_lhs1
11610 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11612 error ("%<#pragma omp atomic capture%> uses two different "
11613 "expressions for memory");
11614 stmt
= error_mark_node
;
11617 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11619 if (stmt
!= error_mark_node
)
11622 if (!structured_block
)
11623 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11628 # pragma omp barrier new-line
11632 c_parser_omp_barrier (c_parser
*parser
)
11634 location_t loc
= c_parser_peek_token (parser
)->location
;
11635 c_parser_consume_pragma (parser
);
11636 c_parser_skip_to_pragma_eol (parser
);
11638 c_finish_omp_barrier (loc
);
11642 # pragma omp critical [(name)] new-line
11645 LOC is the location of the #pragma itself. */
11648 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11650 tree stmt
, name
= NULL
;
11652 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11654 c_parser_consume_token (parser
);
11655 if (c_parser_next_token_is (parser
, CPP_NAME
))
11657 name
= c_parser_peek_token (parser
)->value
;
11658 c_parser_consume_token (parser
);
11659 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11662 c_parser_error (parser
, "expected identifier");
11664 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11665 c_parser_error (parser
, "expected %<(%> or end of line");
11666 c_parser_skip_to_pragma_eol (parser
);
11668 stmt
= c_parser_omp_structured_block (parser
);
11669 return c_finish_omp_critical (loc
, stmt
, name
);
11673 # pragma omp flush flush-vars[opt] new-line
11676 ( variable-list ) */
11679 c_parser_omp_flush (c_parser
*parser
)
11681 location_t loc
= c_parser_peek_token (parser
)->location
;
11682 c_parser_consume_pragma (parser
);
11683 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11684 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11685 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11686 c_parser_error (parser
, "expected %<(%> or end of line");
11687 c_parser_skip_to_pragma_eol (parser
);
11689 c_finish_omp_flush (loc
);
11692 /* Parse the restricted form of the for statement allowed by OpenMP.
11693 The real trick here is to determine the loop control variable early
11694 so that we can push a new decl if necessary to make it private.
11695 LOC is the location of the OMP in "#pragma omp". */
11698 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11699 tree clauses
, tree
*cclauses
)
11701 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11702 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11703 bool fail
= false, open_brace_parsed
= false;
11704 int i
, collapse
= 1, nbraces
= 0;
11705 location_t for_loc
;
11706 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11708 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11709 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11710 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
11712 gcc_assert (collapse
>= 1);
11714 declv
= make_tree_vec (collapse
);
11715 initv
= make_tree_vec (collapse
);
11716 condv
= make_tree_vec (collapse
);
11717 incrv
= make_tree_vec (collapse
);
11719 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11721 c_parser_error (parser
, "for statement expected");
11724 for_loc
= c_parser_peek_token (parser
)->location
;
11725 c_parser_consume_token (parser
);
11727 for (i
= 0; i
< collapse
; i
++)
11729 int bracecount
= 0;
11731 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11734 /* Parse the initialization declaration or expression. */
11735 if (c_parser_next_tokens_start_declaration (parser
))
11738 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11739 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11741 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11744 if (DECL_INITIAL (decl
) == error_mark_node
)
11745 decl
= error_mark_node
;
11748 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11749 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11751 struct c_expr decl_exp
;
11752 struct c_expr init_exp
;
11753 location_t init_loc
;
11755 decl_exp
= c_parser_postfix_expression (parser
);
11756 decl
= decl_exp
.value
;
11758 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11760 init_loc
= c_parser_peek_token (parser
)->location
;
11761 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11762 init_exp
= default_function_array_read_conversion (init_loc
,
11764 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11765 NOP_EXPR
, init_loc
, init_exp
.value
,
11766 init_exp
.original_type
);
11767 init
= c_process_expr_stmt (init_loc
, init
);
11769 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11774 c_parser_error (parser
,
11775 "expected iteration declaration or initialization");
11776 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11782 /* Parse the loop condition. */
11784 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11786 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11787 struct c_expr cond_expr
11788 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11790 cond
= cond_expr
.value
;
11791 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11792 cond
= c_fully_fold (cond
, false, NULL
);
11793 switch (cond_expr
.original_code
)
11801 /* Can't be cond = error_mark_node, because we want to preserve
11802 the location until c_finish_omp_for. */
11803 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11806 protected_set_expr_location (cond
, cond_loc
);
11808 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11810 /* Parse the increment expression. */
11812 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11814 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11816 incr
= c_process_expr_stmt (incr_loc
,
11817 c_parser_expression (parser
).value
);
11819 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11821 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11825 TREE_VEC_ELT (declv
, i
) = decl
;
11826 TREE_VEC_ELT (initv
, i
) = init
;
11827 TREE_VEC_ELT (condv
, i
) = cond
;
11828 TREE_VEC_ELT (incrv
, i
) = incr
;
11832 if (i
== collapse
- 1)
11835 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11836 in between the collapsed for loops to be still considered perfectly
11837 nested. Hopefully the final version clarifies this.
11838 For now handle (multiple) {'s and empty statements. */
11841 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11843 c_parser_consume_token (parser
);
11846 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11848 c_parser_consume_token (parser
);
11851 else if (bracecount
11852 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11853 c_parser_consume_token (parser
);
11856 c_parser_error (parser
, "not enough perfectly nested loops");
11859 open_brace_parsed
= true;
11869 nbraces
+= bracecount
;
11872 save_break
= c_break_label
;
11873 c_break_label
= size_one_node
;
11874 save_cont
= c_cont_label
;
11875 c_cont_label
= NULL_TREE
;
11876 body
= push_stmt_list ();
11878 if (open_brace_parsed
)
11880 location_t here
= c_parser_peek_token (parser
)->location
;
11881 stmt
= c_begin_compound_stmt (true);
11882 c_parser_compound_statement_nostart (parser
);
11883 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11886 add_stmt (c_parser_c99_block_statement (parser
));
11889 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11890 SET_EXPR_LOCATION (t
, loc
);
11894 body
= pop_stmt_list (body
);
11895 c_break_label
= save_break
;
11896 c_cont_label
= save_cont
;
11900 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11902 c_parser_consume_token (parser
);
11905 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11906 c_parser_consume_token (parser
);
11909 c_parser_error (parser
, "collapsed loops not perfectly nested");
11912 location_t here
= c_parser_peek_token (parser
)->location
;
11913 stmt
= c_begin_compound_stmt (true);
11915 c_parser_compound_statement_nostart (parser
);
11916 body
= c_end_compound_stmt (here
, stmt
, true);
11923 /* Only bother calling c_finish_omp_for if we haven't already generated
11924 an error from the initialization parsing. */
11927 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11928 incrv
, body
, NULL
);
11931 if (cclauses
!= NULL
11932 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11935 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11936 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11937 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11938 c
= &OMP_CLAUSE_CHAIN (*c
);
11941 for (i
= 0; i
< collapse
; i
++)
11942 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11945 c
= &OMP_CLAUSE_CHAIN (*c
);
11946 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11949 "iteration variable %qD should not be firstprivate",
11950 OMP_CLAUSE_DECL (*c
));
11951 *c
= OMP_CLAUSE_CHAIN (*c
);
11955 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11956 change it to shared (decl) in
11957 OMP_PARALLEL_CLAUSES. */
11958 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11959 OMP_CLAUSE_LASTPRIVATE
);
11960 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11961 OMP_CLAUSE_CHAIN (l
) = clauses
;
11963 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11967 OMP_FOR_CLAUSES (stmt
) = clauses
;
11972 while (!for_block
->is_empty ())
11974 /* FIXME diagnostics: LOC below should be the actual location of
11975 this particular for block. We need to build a list of
11976 locations to go along with FOR_BLOCK. */
11977 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11980 release_tree_vector (for_block
);
11984 /* Helper function for OpenMP parsing, split clauses and call
11985 finish_omp_clauses on each of the set of clauses afterwards. */
11988 omp_split_clauses (location_t loc
, enum tree_code code
,
11989 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11992 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11993 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11995 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11999 #pragma omp simd simd-clause[optseq] new-line
12002 LOC is the location of the #pragma token.
12005 #define OMP_SIMD_CLAUSE_MASK \
12006 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
12007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12009 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12010 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12011 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12012 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12015 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
12016 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12018 tree block
, clauses
, ret
;
12020 strcat (p_name
, " simd");
12021 mask
|= OMP_SIMD_CLAUSE_MASK
;
12022 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
12024 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12027 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
12028 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
12031 block
= c_begin_compound_stmt (true);
12032 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
12033 block
= c_end_compound_stmt (loc
, block
, true);
12040 #pragma omp for for-clause[optseq] new-line
12044 #pragma omp for simd for-simd-clause[optseq] new-line
12047 LOC is the location of the #pragma token.
12050 #define OMP_FOR_CLAUSE_MASK \
12051 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12052 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12053 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12054 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12055 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
12056 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
12057 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
12058 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12061 c_parser_omp_for (location_t loc
, c_parser
*parser
,
12062 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12064 tree block
, clauses
, ret
;
12066 strcat (p_name
, " for");
12067 mask
|= OMP_FOR_CLAUSE_MASK
;
12069 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12071 if (c_parser_next_token_is (parser
, CPP_NAME
))
12073 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12075 if (strcmp (p
, "simd") == 0)
12077 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12078 if (cclauses
== NULL
)
12079 cclauses
= cclauses_buf
;
12081 c_parser_consume_token (parser
);
12082 block
= c_begin_compound_stmt (true);
12083 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12084 block
= c_end_compound_stmt (loc
, block
, true);
12085 if (ret
== NULL_TREE
)
12087 ret
= make_node (OMP_FOR
);
12088 TREE_TYPE (ret
) = void_type_node
;
12089 OMP_FOR_BODY (ret
) = block
;
12090 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12091 SET_EXPR_LOCATION (ret
, loc
);
12097 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12100 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12101 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12104 block
= c_begin_compound_stmt (true);
12105 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12106 block
= c_end_compound_stmt (loc
, block
, true);
12113 # pragma omp master new-line
12116 LOC is the location of the #pragma token.
12120 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12122 c_parser_skip_to_pragma_eol (parser
);
12123 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12127 # pragma omp ordered new-line
12130 LOC is the location of the #pragma itself.
12134 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12136 c_parser_skip_to_pragma_eol (parser
);
12137 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12143 { section-sequence }
12146 section-directive[opt] structured-block
12147 section-sequence section-directive structured-block
12149 SECTIONS_LOC is the location of the #pragma omp sections. */
12152 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12154 tree stmt
, substmt
;
12155 bool error_suppress
= false;
12158 loc
= c_parser_peek_token (parser
)->location
;
12159 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12161 /* Avoid skipping until the end of the block. */
12162 parser
->error
= false;
12166 stmt
= push_stmt_list ();
12168 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12170 substmt
= c_parser_omp_structured_block (parser
);
12171 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12172 SET_EXPR_LOCATION (substmt
, loc
);
12173 add_stmt (substmt
);
12178 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12180 if (c_parser_next_token_is (parser
, CPP_EOF
))
12183 loc
= c_parser_peek_token (parser
)->location
;
12184 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12186 c_parser_consume_pragma (parser
);
12187 c_parser_skip_to_pragma_eol (parser
);
12188 error_suppress
= false;
12190 else if (!error_suppress
)
12192 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12193 error_suppress
= true;
12196 substmt
= c_parser_omp_structured_block (parser
);
12197 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12198 SET_EXPR_LOCATION (substmt
, loc
);
12199 add_stmt (substmt
);
12201 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12202 "expected %<#pragma omp section%> or %<}%>");
12204 substmt
= pop_stmt_list (stmt
);
12206 stmt
= make_node (OMP_SECTIONS
);
12207 SET_EXPR_LOCATION (stmt
, sections_loc
);
12208 TREE_TYPE (stmt
) = void_type_node
;
12209 OMP_SECTIONS_BODY (stmt
) = substmt
;
12211 return add_stmt (stmt
);
12215 # pragma omp sections sections-clause[optseq] newline
12218 LOC is the location of the #pragma token.
12221 #define OMP_SECTIONS_CLAUSE_MASK \
12222 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12223 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12224 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12225 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12226 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12229 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12230 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12232 tree block
, clauses
, ret
;
12234 strcat (p_name
, " sections");
12235 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12237 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12239 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12242 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12243 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12246 block
= c_begin_compound_stmt (true);
12247 ret
= c_parser_omp_sections_scope (loc
, parser
);
12249 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12250 block
= c_end_compound_stmt (loc
, block
, true);
12257 # pragma parallel parallel-clause new-line
12258 # pragma parallel for parallel-for-clause new-line
12259 # pragma parallel sections parallel-sections-clause new-line
12261 LOC is the location of the #pragma token.
12264 #define OMP_PARALLEL_CLAUSE_MASK \
12265 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12267 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12268 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12269 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12270 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12272 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12273 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12276 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12277 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12279 tree stmt
, clauses
, block
;
12281 strcat (p_name
, " parallel");
12282 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12284 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12286 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12287 if (cclauses
== NULL
)
12288 cclauses
= cclauses_buf
;
12290 c_parser_consume_token (parser
);
12291 block
= c_begin_omp_parallel ();
12292 c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12294 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12296 OMP_PARALLEL_COMBINED (stmt
) = 1;
12301 error_at (loc
, "expected %<for%> after %qs", p_name
);
12302 c_parser_skip_to_pragma_eol (parser
);
12305 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12307 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12308 if (strcmp (p
, "sections") == 0)
12310 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12311 if (cclauses
== NULL
)
12312 cclauses
= cclauses_buf
;
12314 c_parser_consume_token (parser
);
12315 block
= c_begin_omp_parallel ();
12316 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12317 stmt
= c_finish_omp_parallel (loc
,
12318 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12320 OMP_PARALLEL_COMBINED (stmt
) = 1;
12325 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12327 block
= c_begin_omp_parallel ();
12328 c_parser_statement (parser
);
12329 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12335 # pragma omp single single-clause[optseq] new-line
12338 LOC is the location of the #pragma.
12341 #define OMP_SINGLE_CLAUSE_MASK \
12342 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12343 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12344 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12345 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12348 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12350 tree stmt
= make_node (OMP_SINGLE
);
12351 SET_EXPR_LOCATION (stmt
, loc
);
12352 TREE_TYPE (stmt
) = void_type_node
;
12354 OMP_SINGLE_CLAUSES (stmt
)
12355 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12356 "#pragma omp single");
12357 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12359 return add_stmt (stmt
);
12363 # pragma omp task task-clause[optseq] new-line
12365 LOC is the location of the #pragma.
12368 #define OMP_TASK_CLAUSE_MASK \
12369 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12370 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12371 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12372 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12373 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12374 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12375 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12376 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12377 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12380 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12382 tree clauses
, block
;
12384 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12385 "#pragma omp task");
12387 block
= c_begin_omp_task ();
12388 c_parser_statement (parser
);
12389 return c_finish_omp_task (loc
, clauses
, block
);
12393 # pragma omp taskwait new-line
12397 c_parser_omp_taskwait (c_parser
*parser
)
12399 location_t loc
= c_parser_peek_token (parser
)->location
;
12400 c_parser_consume_pragma (parser
);
12401 c_parser_skip_to_pragma_eol (parser
);
12403 c_finish_omp_taskwait (loc
);
12407 # pragma omp taskyield new-line
12411 c_parser_omp_taskyield (c_parser
*parser
)
12413 location_t loc
= c_parser_peek_token (parser
)->location
;
12414 c_parser_consume_pragma (parser
);
12415 c_parser_skip_to_pragma_eol (parser
);
12417 c_finish_omp_taskyield (loc
);
12421 # pragma omp taskgroup new-line
12425 c_parser_omp_taskgroup (c_parser
*parser
)
12427 location_t loc
= c_parser_peek_token (parser
)->location
;
12428 c_parser_skip_to_pragma_eol (parser
);
12429 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12433 # pragma omp cancel cancel-clause[optseq] new-line
12435 LOC is the location of the #pragma.
12438 #define OMP_CANCEL_CLAUSE_MASK \
12439 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12440 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12441 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12442 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12443 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12446 c_parser_omp_cancel (c_parser
*parser
)
12448 location_t loc
= c_parser_peek_token (parser
)->location
;
12450 c_parser_consume_pragma (parser
);
12451 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12452 "#pragma omp cancel");
12454 c_finish_omp_cancel (loc
, clauses
);
12458 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12460 LOC is the location of the #pragma.
12463 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12464 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12465 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12466 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12467 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12470 c_parser_omp_cancellation_point (c_parser
*parser
)
12472 location_t loc
= c_parser_peek_token (parser
)->location
;
12474 bool point_seen
= false;
12476 c_parser_consume_pragma (parser
);
12477 if (c_parser_next_token_is (parser
, CPP_NAME
))
12479 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12480 if (strcmp (p
, "point") == 0)
12482 c_parser_consume_token (parser
);
12488 c_parser_error (parser
, "expected %<point%>");
12489 c_parser_skip_to_pragma_eol (parser
);
12494 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12495 "#pragma omp cancellation point");
12497 c_finish_omp_cancellation_point (loc
, clauses
);
12501 #pragma omp distribute distribute-clause[optseq] new-line
12504 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12505 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12506 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12507 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12508 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12511 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12512 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12514 tree clauses
, block
, ret
;
12516 strcat (p_name
, " distribute");
12517 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12519 if (c_parser_next_token_is (parser
, CPP_NAME
))
12521 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12523 bool parallel
= false;
12525 if (strcmp (p
, "simd") == 0)
12528 parallel
= strcmp (p
, "parallel") == 0;
12529 if (parallel
|| simd
)
12531 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12532 if (cclauses
== NULL
)
12533 cclauses
= cclauses_buf
;
12534 c_parser_consume_token (parser
);
12535 block
= c_begin_compound_stmt (true);
12537 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12539 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12540 block
= c_end_compound_stmt (loc
, block
, true);
12543 ret
= make_node (OMP_DISTRIBUTE
);
12544 TREE_TYPE (ret
) = void_type_node
;
12545 OMP_FOR_BODY (ret
) = block
;
12546 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12547 SET_EXPR_LOCATION (ret
, loc
);
12553 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12556 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12557 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12560 block
= c_begin_compound_stmt (true);
12561 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12562 block
= c_end_compound_stmt (loc
, block
, true);
12569 # pragma omp teams teams-clause[optseq] new-line
12570 structured-block */
12572 #define OMP_TEAMS_CLAUSE_MASK \
12573 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12574 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12575 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12576 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12577 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12578 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12579 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12582 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12583 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12585 tree clauses
, block
, ret
;
12587 strcat (p_name
, " teams");
12588 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12590 if (c_parser_next_token_is (parser
, CPP_NAME
))
12592 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12593 if (strcmp (p
, "distribute") == 0)
12595 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12596 if (cclauses
== NULL
)
12597 cclauses
= cclauses_buf
;
12599 c_parser_consume_token (parser
);
12600 block
= c_begin_compound_stmt (true);
12601 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12602 block
= c_end_compound_stmt (loc
, block
, true);
12605 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12606 ret
= make_node (OMP_TEAMS
);
12607 TREE_TYPE (ret
) = void_type_node
;
12608 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12609 OMP_TEAMS_BODY (ret
) = block
;
12610 return add_stmt (ret
);
12614 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12617 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12618 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12621 tree stmt
= make_node (OMP_TEAMS
);
12622 TREE_TYPE (stmt
) = void_type_node
;
12623 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12624 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12626 return add_stmt (stmt
);
12630 # pragma omp target data target-data-clause[optseq] new-line
12631 structured-block */
12633 #define OMP_TARGET_DATA_CLAUSE_MASK \
12634 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12635 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12636 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12639 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12641 tree stmt
= make_node (OMP_TARGET_DATA
);
12642 TREE_TYPE (stmt
) = void_type_node
;
12644 OMP_TARGET_DATA_CLAUSES (stmt
)
12645 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12646 "#pragma omp target data");
12647 keep_next_level ();
12648 tree block
= c_begin_compound_stmt (true);
12649 add_stmt (c_parser_omp_structured_block (parser
));
12650 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12652 SET_EXPR_LOCATION (stmt
, loc
);
12653 return add_stmt (stmt
);
12657 # pragma omp target update target-update-clause[optseq] new-line */
12659 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12660 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12662 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12663 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12666 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12667 enum pragma_context context
)
12669 if (context
== pragma_stmt
)
12672 "%<#pragma omp target update%> may only be "
12673 "used in compound statements");
12674 c_parser_skip_to_pragma_eol (parser
);
12679 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12680 "#pragma omp target update");
12681 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12682 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12685 "%<#pragma omp target update must contain at least one "
12686 "%<from%> or %<to%> clauses");
12690 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12691 TREE_TYPE (stmt
) = void_type_node
;
12692 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12693 SET_EXPR_LOCATION (stmt
, loc
);
12699 # pragma omp target target-clause[optseq] new-line
12700 structured-block */
12702 #define OMP_TARGET_CLAUSE_MASK \
12703 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12704 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12705 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12708 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12710 location_t loc
= c_parser_peek_token (parser
)->location
;
12711 c_parser_consume_pragma (parser
);
12713 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12715 c_parser_error (parser
, "expected declaration specifiers");
12716 c_parser_skip_to_pragma_eol (parser
);
12720 if (c_parser_next_token_is (parser
, CPP_NAME
))
12722 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12724 if (strcmp (p
, "data") == 0)
12726 c_parser_consume_token (parser
);
12727 c_parser_omp_target_data (loc
, parser
);
12730 else if (strcmp (p
, "update") == 0)
12732 c_parser_consume_token (parser
);
12733 return c_parser_omp_target_update (loc
, parser
, context
);
12735 else if (strcmp (p
, "teams") == 0)
12737 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12738 char p_name
[sizeof ("#pragma omp target teams distribute "
12739 "parallel for simd")];
12741 c_parser_consume_token (parser
);
12742 strcpy (p_name
, "#pragma omp target");
12743 keep_next_level ();
12744 tree block
= c_begin_compound_stmt (true);
12745 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12746 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12747 block
= c_end_compound_stmt (loc
, block
, true);
12750 tree stmt
= make_node (OMP_TARGET
);
12751 TREE_TYPE (stmt
) = void_type_node
;
12752 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12753 OMP_TARGET_BODY (stmt
) = block
;
12759 tree stmt
= make_node (OMP_TARGET
);
12760 TREE_TYPE (stmt
) = void_type_node
;
12762 OMP_TARGET_CLAUSES (stmt
)
12763 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12764 "#pragma omp target");
12765 keep_next_level ();
12766 tree block
= c_begin_compound_stmt (true);
12767 add_stmt (c_parser_omp_structured_block (parser
));
12768 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12770 SET_EXPR_LOCATION (stmt
, loc
);
12776 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12778 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12779 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12780 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12781 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12782 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12783 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12784 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12787 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12789 vec
<c_token
> clauses
= vNULL
;
12790 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12792 c_token
*token
= c_parser_peek_token (parser
);
12793 if (token
->type
== CPP_EOF
)
12795 c_parser_skip_to_pragma_eol (parser
);
12796 clauses
.release ();
12799 clauses
.safe_push (*token
);
12800 c_parser_consume_token (parser
);
12802 clauses
.safe_push (*c_parser_peek_token (parser
));
12803 c_parser_skip_to_pragma_eol (parser
);
12805 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12807 if (c_parser_peek_token (parser
)->pragma_kind
12808 != PRAGMA_OMP_DECLARE_REDUCTION
12809 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12810 || strcmp (IDENTIFIER_POINTER
12811 (c_parser_peek_2nd_token (parser
)->value
),
12814 c_parser_error (parser
,
12815 "%<#pragma omp declare simd%> must be followed by "
12816 "function declaration or definition or another "
12817 "%<#pragma omp declare simd%>");
12818 clauses
.release ();
12821 c_parser_consume_pragma (parser
);
12822 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12824 c_token
*token
= c_parser_peek_token (parser
);
12825 if (token
->type
== CPP_EOF
)
12827 c_parser_skip_to_pragma_eol (parser
);
12828 clauses
.release ();
12831 clauses
.safe_push (*token
);
12832 c_parser_consume_token (parser
);
12834 clauses
.safe_push (*c_parser_peek_token (parser
));
12835 c_parser_skip_to_pragma_eol (parser
);
12838 /* Make sure nothing tries to read past the end of the tokens. */
12840 memset (&eof_token
, 0, sizeof (eof_token
));
12841 eof_token
.type
= CPP_EOF
;
12842 clauses
.safe_push (eof_token
);
12843 clauses
.safe_push (eof_token
);
12847 case pragma_external
:
12848 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12849 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12851 int ext
= disable_extension_diagnostics ();
12853 c_parser_consume_token (parser
);
12854 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12855 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12856 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12858 restore_extension_diagnostics (ext
);
12861 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12864 case pragma_struct
:
12866 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12867 "function declaration or definition");
12869 case pragma_compound
:
12871 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12872 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12874 int ext
= disable_extension_diagnostics ();
12876 c_parser_consume_token (parser
);
12877 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12878 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12879 if (c_parser_next_tokens_start_declaration (parser
))
12881 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12882 true, NULL
, clauses
);
12883 restore_extension_diagnostics (ext
);
12886 restore_extension_diagnostics (ext
);
12888 else if (c_parser_next_tokens_start_declaration (parser
))
12890 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12894 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12895 "function declaration or definition");
12898 gcc_unreachable ();
12900 clauses
.release ();
12903 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12904 and put that into "omp declare simd" attribute. */
12907 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12908 vec
<c_token
> clauses
)
12910 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12911 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12912 has already processed the tokens. */
12913 if (clauses
[0].type
== CPP_EOF
)
12915 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12917 error ("%<#pragma omp declare simd%> not immediately followed by "
12918 "a function declaration or definition");
12919 clauses
[0].type
= CPP_EOF
;
12922 if (clauses
[0].type
!= CPP_NAME
)
12924 error_at (DECL_SOURCE_LOCATION (fndecl
),
12925 "%<#pragma omp declare simd%> not immediately followed by "
12926 "a single function declaration or definition");
12927 clauses
[0].type
= CPP_EOF
;
12931 if (parms
== NULL_TREE
)
12932 parms
= DECL_ARGUMENTS (fndecl
);
12934 unsigned int tokens_avail
= parser
->tokens_avail
;
12935 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12936 parser
->tokens
= clauses
.address ();
12937 parser
->tokens_avail
= clauses
.length ();
12939 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12940 while (parser
->tokens_avail
> 3)
12942 c_token
*token
= c_parser_peek_token (parser
);
12943 gcc_assert (token
->type
== CPP_NAME
12944 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12945 c_parser_consume_token (parser
);
12946 parser
->in_pragma
= true;
12948 tree c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12949 "#pragma omp declare simd");
12950 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12951 if (c
!= NULL_TREE
)
12952 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12953 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12954 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12955 DECL_ATTRIBUTES (fndecl
) = c
;
12958 parser
->tokens
= &parser
->tokens_buf
[0];
12959 parser
->tokens_avail
= tokens_avail
;
12960 clauses
[0].type
= CPP_PRAGMA
;
12965 # pragma omp declare target new-line
12966 declarations and definitions
12967 # pragma omp end declare target new-line */
12970 c_parser_omp_declare_target (c_parser
*parser
)
12972 c_parser_skip_to_pragma_eol (parser
);
12973 current_omp_declare_target_attribute
++;
12977 c_parser_omp_end_declare_target (c_parser
*parser
)
12979 location_t loc
= c_parser_peek_token (parser
)->location
;
12980 c_parser_consume_pragma (parser
);
12981 if (c_parser_next_token_is (parser
, CPP_NAME
)
12982 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12985 c_parser_consume_token (parser
);
12986 if (c_parser_next_token_is (parser
, CPP_NAME
)
12987 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12989 c_parser_consume_token (parser
);
12992 c_parser_error (parser
, "expected %<target%>");
12993 c_parser_skip_to_pragma_eol (parser
);
12999 c_parser_error (parser
, "expected %<declare%>");
13000 c_parser_skip_to_pragma_eol (parser
);
13003 c_parser_skip_to_pragma_eol (parser
);
13004 if (!current_omp_declare_target_attribute
)
13005 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13006 "%<#pragma omp declare target%>");
13008 current_omp_declare_target_attribute
--;
13013 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13014 initializer-clause[opt] new-line
13016 initializer-clause:
13017 initializer (omp_priv = initializer)
13018 initializer (function-name (argument-list)) */
13021 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13023 unsigned int tokens_avail
= 0, i
;
13024 vec
<tree
> types
= vNULL
;
13025 vec
<c_token
> clauses
= vNULL
;
13026 enum tree_code reduc_code
= ERROR_MARK
;
13027 tree reduc_id
= NULL_TREE
;
13029 location_t rloc
= c_parser_peek_token (parser
)->location
;
13031 if (context
== pragma_struct
|| context
== pragma_param
)
13033 error ("%<#pragma omp declare reduction%> not at file or block scope");
13037 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13040 switch (c_parser_peek_token (parser
)->type
)
13043 reduc_code
= PLUS_EXPR
;
13046 reduc_code
= MULT_EXPR
;
13049 reduc_code
= MINUS_EXPR
;
13052 reduc_code
= BIT_AND_EXPR
;
13055 reduc_code
= BIT_XOR_EXPR
;
13058 reduc_code
= BIT_IOR_EXPR
;
13061 reduc_code
= TRUTH_ANDIF_EXPR
;
13064 reduc_code
= TRUTH_ORIF_EXPR
;
13068 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13069 if (strcmp (p
, "min") == 0)
13071 reduc_code
= MIN_EXPR
;
13074 if (strcmp (p
, "max") == 0)
13076 reduc_code
= MAX_EXPR
;
13079 reduc_id
= c_parser_peek_token (parser
)->value
;
13082 c_parser_error (parser
,
13083 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13084 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13088 tree orig_reduc_id
, reduc_decl
;
13089 orig_reduc_id
= reduc_id
;
13090 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13091 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13092 c_parser_consume_token (parser
);
13094 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13099 location_t loc
= c_parser_peek_token (parser
)->location
;
13100 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13103 type
= groktypename (ctype
, NULL
, NULL
);
13104 if (type
== error_mark_node
)
13106 else if ((INTEGRAL_TYPE_P (type
)
13107 || TREE_CODE (type
) == REAL_TYPE
13108 || TREE_CODE (type
) == COMPLEX_TYPE
)
13109 && orig_reduc_id
== NULL_TREE
)
13110 error_at (loc
, "predeclared arithmetic type in "
13111 "%<#pragma omp declare reduction%>");
13112 else if (TREE_CODE (type
) == FUNCTION_TYPE
13113 || TREE_CODE (type
) == ARRAY_TYPE
)
13114 error_at (loc
, "function or array type in "
13115 "%<#pragma omp declare reduction%>");
13116 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13117 error_at (loc
, "const, volatile or restrict qualified type in "
13118 "%<#pragma omp declare reduction%>");
13122 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13123 if (comptypes (TREE_PURPOSE (t
), type
))
13125 error_at (loc
, "redeclaration of %qs "
13126 "%<#pragma omp declare reduction%> for "
13128 IDENTIFIER_POINTER (reduc_id
)
13129 + sizeof ("omp declare reduction ") - 1,
13132 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13134 error_at (ploc
, "previous %<#pragma omp declare "
13138 if (t
== NULL_TREE
)
13139 types
.safe_push (type
);
13141 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13142 c_parser_consume_token (parser
);
13150 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13151 || types
.is_empty ())
13154 clauses
.release ();
13158 c_token
*token
= c_parser_peek_token (parser
);
13159 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13161 c_parser_consume_token (parser
);
13163 c_parser_skip_to_pragma_eol (parser
);
13167 if (types
.length () > 1)
13169 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13171 c_token
*token
= c_parser_peek_token (parser
);
13172 if (token
->type
== CPP_EOF
)
13174 clauses
.safe_push (*token
);
13175 c_parser_consume_token (parser
);
13177 clauses
.safe_push (*c_parser_peek_token (parser
));
13178 c_parser_skip_to_pragma_eol (parser
);
13180 /* Make sure nothing tries to read past the end of the tokens. */
13182 memset (&eof_token
, 0, sizeof (eof_token
));
13183 eof_token
.type
= CPP_EOF
;
13184 clauses
.safe_push (eof_token
);
13185 clauses
.safe_push (eof_token
);
13188 int errs
= errorcount
;
13189 FOR_EACH_VEC_ELT (types
, i
, type
)
13191 tokens_avail
= parser
->tokens_avail
;
13192 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13193 if (!clauses
.is_empty ())
13195 parser
->tokens
= clauses
.address ();
13196 parser
->tokens_avail
= clauses
.length ();
13197 parser
->in_pragma
= true;
13200 bool nested
= current_function_decl
!= NULL_TREE
;
13202 c_push_function_context ();
13203 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13204 reduc_id
, default_function_type
);
13205 current_function_decl
= fndecl
;
13206 allocate_struct_function (fndecl
, true);
13208 tree stmt
= push_stmt_list ();
13209 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13210 warn about these. */
13211 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13212 get_identifier ("omp_out"), type
);
13213 DECL_ARTIFICIAL (omp_out
) = 1;
13214 DECL_CONTEXT (omp_out
) = fndecl
;
13215 pushdecl (omp_out
);
13216 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13217 get_identifier ("omp_in"), type
);
13218 DECL_ARTIFICIAL (omp_in
) = 1;
13219 DECL_CONTEXT (omp_in
) = fndecl
;
13221 struct c_expr combiner
= c_parser_expression (parser
);
13222 struct c_expr initializer
;
13223 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13225 initializer
.value
= error_mark_node
;
13226 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13228 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13229 && strcmp (IDENTIFIER_POINTER
13230 (c_parser_peek_token (parser
)->value
),
13231 "initializer") == 0)
13233 c_parser_consume_token (parser
);
13236 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13237 get_identifier ("omp_priv"), type
);
13238 DECL_ARTIFICIAL (omp_priv
) = 1;
13239 DECL_INITIAL (omp_priv
) = error_mark_node
;
13240 DECL_CONTEXT (omp_priv
) = fndecl
;
13241 pushdecl (omp_priv
);
13242 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13243 get_identifier ("omp_orig"), type
);
13244 DECL_ARTIFICIAL (omp_orig
) = 1;
13245 DECL_CONTEXT (omp_orig
) = fndecl
;
13246 pushdecl (omp_orig
);
13247 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13249 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13251 c_parser_error (parser
, "expected %<omp_priv%> or "
13255 else if (strcmp (IDENTIFIER_POINTER
13256 (c_parser_peek_token (parser
)->value
),
13259 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13260 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13262 c_parser_error (parser
, "expected function-name %<(%>");
13266 initializer
= c_parser_postfix_expression (parser
);
13267 if (initializer
.value
13268 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13271 tree c
= initializer
.value
;
13272 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13273 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13274 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13276 if (j
== call_expr_nargs (c
))
13277 error ("one of the initializer call arguments should be "
13283 c_parser_consume_token (parser
);
13284 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13288 tree st
= push_stmt_list ();
13289 start_init (omp_priv
, NULL_TREE
, 0);
13290 location_t loc
= c_parser_peek_token (parser
)->location
;
13291 struct c_expr init
= c_parser_initializer (parser
);
13293 finish_decl (omp_priv
, loc
, init
.value
,
13294 init
.original_type
, NULL_TREE
);
13295 pop_stmt_list (st
);
13299 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13305 c_parser_skip_to_pragma_eol (parser
);
13307 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13308 DECL_INITIAL (reduc_decl
));
13309 DECL_INITIAL (reduc_decl
) = t
;
13310 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13311 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13312 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13313 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13314 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13315 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13318 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13319 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13320 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13321 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13322 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13323 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13324 walk_tree (&DECL_INITIAL (omp_priv
),
13325 c_check_omp_declare_reduction_r
,
13326 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13330 pop_stmt_list (stmt
);
13332 if (cfun
->language
!= NULL
)
13334 ggc_free (cfun
->language
);
13335 cfun
->language
= NULL
;
13338 current_function_decl
= NULL_TREE
;
13340 c_pop_function_context ();
13342 if (!clauses
.is_empty ())
13344 parser
->tokens
= &parser
->tokens_buf
[0];
13345 parser
->tokens_avail
= tokens_avail
;
13349 if (errs
!= errorcount
)
13353 clauses
.release ();
13359 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13360 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13361 initializer-clause[opt] new-line
13362 #pragma omp declare target new-line */
13365 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13367 c_parser_consume_pragma (parser
);
13368 if (c_parser_next_token_is (parser
, CPP_NAME
))
13370 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13371 if (strcmp (p
, "simd") == 0)
13373 /* c_parser_consume_token (parser); done in
13374 c_parser_omp_declare_simd. */
13375 c_parser_omp_declare_simd (parser
, context
);
13378 if (strcmp (p
, "reduction") == 0)
13380 c_parser_consume_token (parser
);
13381 c_parser_omp_declare_reduction (parser
, context
);
13384 if (strcmp (p
, "target") == 0)
13386 c_parser_consume_token (parser
);
13387 c_parser_omp_declare_target (parser
);
13392 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13394 c_parser_skip_to_pragma_eol (parser
);
13397 /* Main entry point to parsing most OpenMP pragmas. */
13400 c_parser_omp_construct (c_parser
*parser
)
13402 enum pragma_kind p_kind
;
13405 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13406 omp_clause_mask
mask (0);
13408 loc
= c_parser_peek_token (parser
)->location
;
13409 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13410 c_parser_consume_pragma (parser
);
13414 case PRAGMA_OMP_ATOMIC
:
13415 c_parser_omp_atomic (loc
, parser
);
13417 case PRAGMA_OMP_CRITICAL
:
13418 stmt
= c_parser_omp_critical (loc
, parser
);
13420 case PRAGMA_OMP_DISTRIBUTE
:
13421 strcpy (p_name
, "#pragma omp");
13422 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13424 case PRAGMA_OMP_FOR
:
13425 strcpy (p_name
, "#pragma omp");
13426 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13428 case PRAGMA_OMP_MASTER
:
13429 stmt
= c_parser_omp_master (loc
, parser
);
13431 case PRAGMA_OMP_ORDERED
:
13432 stmt
= c_parser_omp_ordered (loc
, parser
);
13434 case PRAGMA_OMP_PARALLEL
:
13435 strcpy (p_name
, "#pragma omp");
13436 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13438 case PRAGMA_OMP_SECTIONS
:
13439 strcpy (p_name
, "#pragma omp");
13440 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13442 case PRAGMA_OMP_SIMD
:
13443 strcpy (p_name
, "#pragma omp");
13444 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13446 case PRAGMA_OMP_SINGLE
:
13447 stmt
= c_parser_omp_single (loc
, parser
);
13449 case PRAGMA_OMP_TASK
:
13450 stmt
= c_parser_omp_task (loc
, parser
);
13452 case PRAGMA_OMP_TASKGROUP
:
13453 stmt
= c_parser_omp_taskgroup (parser
);
13455 case PRAGMA_OMP_TEAMS
:
13456 strcpy (p_name
, "#pragma omp");
13457 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13460 gcc_unreachable ();
13464 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13469 # pragma omp threadprivate (variable-list) */
13472 c_parser_omp_threadprivate (c_parser
*parser
)
13477 c_parser_consume_pragma (parser
);
13478 loc
= c_parser_peek_token (parser
)->location
;
13479 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13481 /* Mark every variable in VARS to be assigned thread local storage. */
13482 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13484 tree v
= TREE_PURPOSE (t
);
13486 /* FIXME diagnostics: Ideally we should keep individual
13487 locations for all the variables in the var list to make the
13488 following errors more precise. Perhaps
13489 c_parser_omp_var_list_parens() should construct a list of
13490 locations to go along with the var list. */
13492 /* If V had already been marked threadprivate, it doesn't matter
13493 whether it had been used prior to this point. */
13494 if (TREE_CODE (v
) != VAR_DECL
)
13495 error_at (loc
, "%qD is not a variable", v
);
13496 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13497 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13498 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13499 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13500 else if (TREE_TYPE (v
) == error_mark_node
)
13502 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13503 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13506 if (! DECL_THREAD_LOCAL_P (v
))
13508 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
13509 /* If rtl has been already set for this var, call
13510 make_decl_rtl once again, so that encode_section_info
13511 has a chance to look at the new decl flags. */
13512 if (DECL_RTL_SET_P (v
))
13515 C_DECL_THREADPRIVATE_P (v
) = 1;
13519 c_parser_skip_to_pragma_eol (parser
);
13522 /* Parse a transaction attribute (GCC Extension).
13524 transaction-attribute:
13528 The transactional memory language description is written for C++,
13529 and uses the C++0x attribute syntax. For compatibility, allow the
13530 bracket style for transactions in C as well. */
13533 c_parser_transaction_attributes (c_parser
*parser
)
13535 tree attr_name
, attr
= NULL
;
13537 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13538 return c_parser_attributes (parser
);
13540 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13542 c_parser_consume_token (parser
);
13543 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13546 attr_name
= c_parser_attribute_any_word (parser
);
13549 c_parser_consume_token (parser
);
13550 attr
= build_tree_list (attr_name
, NULL_TREE
);
13553 c_parser_error (parser
, "expected identifier");
13555 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13557 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13561 /* Parse a __transaction_atomic or __transaction_relaxed statement
13564 transaction-statement:
13565 __transaction_atomic transaction-attribute[opt] compound-statement
13566 __transaction_relaxed compound-statement
13568 Note that the only valid attribute is: "outer".
13572 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13574 unsigned int old_in
= parser
->in_transaction
;
13575 unsigned int this_in
= 1, new_in
;
13576 location_t loc
= c_parser_peek_token (parser
)->location
;
13579 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13580 || keyword
== RID_TRANSACTION_RELAXED
)
13581 && c_parser_next_token_is_keyword (parser
, keyword
));
13582 c_parser_consume_token (parser
);
13584 if (keyword
== RID_TRANSACTION_RELAXED
)
13585 this_in
|= TM_STMT_ATTR_RELAXED
;
13588 attrs
= c_parser_transaction_attributes (parser
);
13590 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13593 /* Keep track if we're in the lexical scope of an outer transaction. */
13594 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13596 parser
->in_transaction
= new_in
;
13597 stmt
= c_parser_compound_statement (parser
);
13598 parser
->in_transaction
= old_in
;
13601 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13603 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13604 "%<__transaction_atomic%> without transactional memory support enabled"
13605 : "%<__transaction_relaxed %> "
13606 "without transactional memory support enabled"));
13611 /* Parse a __transaction_atomic or __transaction_relaxed expression
13614 transaction-expression:
13615 __transaction_atomic ( expression )
13616 __transaction_relaxed ( expression )
13619 static struct c_expr
13620 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13623 unsigned int old_in
= parser
->in_transaction
;
13624 unsigned int this_in
= 1;
13625 location_t loc
= c_parser_peek_token (parser
)->location
;
13628 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13629 || keyword
== RID_TRANSACTION_RELAXED
)
13630 && c_parser_next_token_is_keyword (parser
, keyword
));
13631 c_parser_consume_token (parser
);
13633 if (keyword
== RID_TRANSACTION_RELAXED
)
13634 this_in
|= TM_STMT_ATTR_RELAXED
;
13637 attrs
= c_parser_transaction_attributes (parser
);
13639 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13642 parser
->in_transaction
= this_in
;
13643 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13645 tree expr
= c_parser_expression (parser
).value
;
13646 ret
.original_type
= TREE_TYPE (expr
);
13647 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13648 if (this_in
& TM_STMT_ATTR_RELAXED
)
13649 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13650 SET_EXPR_LOCATION (ret
.value
, loc
);
13651 ret
.original_code
= TRANSACTION_EXPR
;
13652 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13661 ret
.value
= error_mark_node
;
13662 ret
.original_code
= ERROR_MARK
;
13663 ret
.original_type
= NULL
;
13665 parser
->in_transaction
= old_in
;
13668 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13669 "%<__transaction_atomic%> without transactional memory support enabled"
13670 : "%<__transaction_relaxed %> "
13671 "without transactional memory support enabled"));
13676 /* Parse a __transaction_cancel statement (GCC Extension).
13678 transaction-cancel-statement:
13679 __transaction_cancel transaction-attribute[opt] ;
13681 Note that the only valid attribute is "outer".
13685 c_parser_transaction_cancel (c_parser
*parser
)
13687 location_t loc
= c_parser_peek_token (parser
)->location
;
13689 bool is_outer
= false;
13691 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
13692 c_parser_consume_token (parser
);
13694 attrs
= c_parser_transaction_attributes (parser
);
13696 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
13700 error_at (loc
, "%<__transaction_cancel%> without "
13701 "transactional memory support enabled");
13704 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
13706 error_at (loc
, "%<__transaction_cancel%> within a "
13707 "%<__transaction_relaxed%>");
13712 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
13713 && !is_tm_may_cancel_outer (current_function_decl
))
13715 error_at (loc
, "outer %<__transaction_cancel%> not "
13716 "within outer %<__transaction_atomic%>");
13717 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
13721 else if (parser
->in_transaction
== 0)
13723 error_at (loc
, "%<__transaction_cancel%> not within "
13724 "%<__transaction_atomic%>");
13728 return add_stmt (build_tm_abort_call (loc
, is_outer
));
13731 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
13734 /* Parse a single source file. */
13737 c_parse_file (void)
13739 /* Use local storage to begin. If the first token is a pragma, parse it.
13740 If it is #pragma GCC pch_preprocess, then this will load a PCH file
13741 which will cause garbage collection. */
13744 memset (&tparser
, 0, sizeof tparser
);
13745 tparser
.tokens
= &tparser
.tokens_buf
[0];
13746 the_parser
= &tparser
;
13748 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
13749 c_parser_pragma_pch_preprocess (&tparser
);
13751 the_parser
= ggc_alloc_c_parser ();
13752 *the_parser
= tparser
;
13753 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
13754 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
13756 /* Initialize EH, if we've been told to do so. */
13757 if (flag_exceptions
)
13758 using_eh_for_cleanups ();
13760 c_parser_translation_unit (the_parser
);
13764 /* This function parses Cilk Plus array notation. The starting index is
13765 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
13766 return value of this function is a tree_node called VALUE_TREE of type
13767 ARRAY_NOTATION_REF. */
13770 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
13773 c_token
*token
= NULL
;
13774 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
13775 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
13776 tree array_type_domain
= NULL_TREE
;
13778 if (array_value
== error_mark_node
)
13780 /* No need to continue. If either of these 2 were true, then an error
13781 must be emitted already. Thus, no need to emit them twice. */
13782 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13783 return error_mark_node
;
13786 array_type
= TREE_TYPE (array_value
);
13787 gcc_assert (array_type
);
13788 type
= TREE_TYPE (array_type
);
13789 token
= c_parser_peek_token (parser
);
13791 if (token
->type
== CPP_EOF
)
13793 c_parser_error (parser
, "expected %<:%> or numeral");
13796 else if (token
->type
== CPP_COLON
)
13798 if (!initial_index
)
13800 /* If we are here, then we have a case like this A[:]. */
13801 c_parser_consume_token (parser
);
13802 if (TREE_CODE (array_type
) == POINTER_TYPE
)
13804 error_at (loc
, "start-index and length fields necessary for "
13805 "using array notations in pointers");
13806 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13807 return error_mark_node
;
13809 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13811 error_at (loc
, "array notations cannot be used with function "
13813 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13814 return error_mark_node
;
13816 array_type_domain
= TYPE_DOMAIN (array_type
);
13818 if (!array_type_domain
)
13820 error_at (loc
, "start-index and length fields necessary for "
13821 "using array notations in dimensionless arrays");
13822 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13823 return error_mark_node
;
13826 start_index
= TYPE_MINVAL (array_type_domain
);
13827 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
13829 if (!TYPE_MAXVAL (array_type_domain
)
13830 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
13832 error_at (loc
, "start-index and length fields necessary for "
13833 "using array notations in variable-length arrays");
13834 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13835 return error_mark_node
;
13837 end_index
= TYPE_MAXVAL (array_type_domain
);
13838 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
13839 end_index
, integer_one_node
);
13840 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
13841 stride
= build_int_cst (integer_type_node
, 1);
13842 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
13844 else if (initial_index
!= error_mark_node
)
13846 /* If we are here, then there should be 2 possibilities:
13847 1. Array [EXPR : EXPR]
13848 2. Array [EXPR : EXPR : EXPR]
13850 start_index
= initial_index
;
13852 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13854 error_at (loc
, "array notations cannot be used with function "
13856 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13857 return error_mark_node
;
13859 c_parser_consume_token (parser
); /* consume the ':' */
13860 end_index
= c_parser_expression (parser
).value
;
13861 if (!end_index
|| end_index
== error_mark_node
)
13863 c_parser_skip_to_end_of_block_or_statement (parser
);
13864 return error_mark_node
;
13866 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
13868 c_parser_consume_token (parser
);
13869 stride
= c_parser_expression (parser
).value
;
13870 if (!stride
|| stride
== error_mark_node
)
13872 c_parser_skip_to_end_of_block_or_statement (parser
);
13873 return error_mark_node
;
13878 c_parser_error (parser
, "expected array notation expression");
13881 c_parser_error (parser
, "expected array notation expression");
13883 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13885 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
13886 end_index
, stride
, type
);
13887 if (value_tree
!= error_mark_node
)
13888 SET_EXPR_LOCATION (value_tree
, loc
);
13892 #include "gt-c-c-parser.h"