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 "stringpool.h"
45 #include "stor-layout.h"
47 #include "trans-mem.h"
48 #include "langhooks.h"
52 #include "c-family/c-pragma.h"
57 #include "c-family/c-common.h"
58 #include "c-family/c-objc.h"
66 /* Initialization routine for this file. */
71 /* The only initialization required is of the reserved word
77 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
78 the c_token structure. */
79 gcc_assert (RID_MAX
<= 255);
86 mask
|= D_ASM
| D_EXT
;
90 if (!c_dialect_objc ())
91 mask
|= D_OBJC
| D_CXX_OBJC
;
93 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
94 for (i
= 0; i
< num_c_common_reswords
; i
++)
96 /* If a keyword is disabled, do not enter it into the table
97 and so create a canonical spelling that isn't a keyword. */
98 if (c_common_reswords
[i
].disable
& mask
)
101 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
103 id
= get_identifier (c_common_reswords
[i
].word
);
104 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
105 C_IS_RESERVED_WORD (id
) = 1;
110 id
= get_identifier (c_common_reswords
[i
].word
);
111 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
112 C_IS_RESERVED_WORD (id
) = 1;
113 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
117 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
118 and the C parser. Unlike the C++ lexer, the parser structure
119 stores the lexer information instead of using a separate structure.
120 Identifiers are separated into ordinary identifiers, type names,
121 keywords and some other Objective-C types of identifiers, and some
122 look-ahead is maintained.
124 ??? It might be a good idea to lex the whole file up front (as for
125 C++). It would then be possible to share more of the C and C++
126 lexer code, if desired. */
128 /* The following local token type is used. */
131 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
133 /* More information about the type of a CPP_NAME token. */
134 typedef enum c_id_kind
{
135 /* An ordinary identifier. */
137 /* An identifier declared as a typedef name. */
139 /* An identifier declared as an Objective-C class name. */
141 /* An address space identifier. */
143 /* Not an identifier. */
147 /* A single C token after string literal concatenation and conversion
148 of preprocessing tokens to tokens. */
149 typedef struct GTY (()) c_token
{
150 /* The kind of token. */
151 ENUM_BITFIELD (cpp_ttype
) type
: 8;
152 /* If this token is a CPP_NAME, this value indicates whether also
153 declared as some kind of type. Otherwise, it is C_ID_NONE. */
154 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
155 /* If this token is a keyword, this value indicates which keyword.
156 Otherwise, this value is RID_MAX. */
157 ENUM_BITFIELD (rid
) keyword
: 8;
158 /* If this token is a CPP_PRAGMA, this indicates the pragma that
159 was seen. Otherwise it is PRAGMA_NONE. */
160 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
161 /* The location at which this token was found. */
163 /* The value associated with this token, if any. */
167 /* A parser structure recording information about the state and
168 context of parsing. Includes lexer information with up to two
169 tokens of look-ahead; more are not needed for C. */
170 typedef struct GTY(()) c_parser
{
171 /* The look-ahead tokens. */
172 c_token
* GTY((skip
)) tokens
;
173 /* Buffer for look-ahead tokens. */
174 c_token tokens_buf
[2];
175 /* How many look-ahead tokens are available (0, 1 or 2, or
176 more if parsing from pre-lexed tokens). */
177 unsigned int tokens_avail
;
178 /* True if a syntax error is being recovered from; false otherwise.
179 c_parser_error sets this flag. It should clear this flag when
180 enough tokens have been consumed to recover from the error. */
181 BOOL_BITFIELD error
: 1;
182 /* True if we're processing a pragma, and shouldn't automatically
183 consume CPP_PRAGMA_EOL. */
184 BOOL_BITFIELD in_pragma
: 1;
185 /* True if we're parsing the outermost block of an if statement. */
186 BOOL_BITFIELD in_if_block
: 1;
187 /* True if we want to lex an untranslated string. */
188 BOOL_BITFIELD lex_untranslated_string
: 1;
190 /* Objective-C specific parser/lexer information. */
192 /* True if we are in a context where the Objective-C "PQ" keywords
193 are considered keywords. */
194 BOOL_BITFIELD objc_pq_context
: 1;
195 /* True if we are parsing a (potential) Objective-C foreach
196 statement. This is set to true after we parsed 'for (' and while
197 we wait for 'in' or ';' to decide if it's a standard C for loop or an
198 Objective-C foreach loop. */
199 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
200 /* The following flag is needed to contextualize Objective-C lexical
201 analysis. In some cases (e.g., 'int NSObject;'), it is
202 undesirable to bind an identifier to an Objective-C class, even
203 if a class with that name exists. */
204 BOOL_BITFIELD objc_need_raw_identifier
: 1;
205 /* Nonzero if we're processing a __transaction statement. The value
206 is 1 | TM_STMT_ATTR_*. */
207 unsigned int in_transaction
: 4;
208 /* True if we are in a context where the Objective-C "Property attribute"
209 keywords are valid. */
210 BOOL_BITFIELD objc_property_attr_context
: 1;
214 /* The actual parser and external interface. ??? Does this need to be
215 garbage-collected? */
217 static GTY (()) c_parser
*the_parser
;
219 /* Read in and lex a single token, storing it in *TOKEN. */
222 c_lex_one_token (c_parser
*parser
, c_token
*token
)
224 timevar_push (TV_LEX
);
226 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
227 (parser
->lex_untranslated_string
228 ? C_LEX_STRING_NO_TRANSLATE
: 0));
229 token
->id_kind
= C_ID_NONE
;
230 token
->keyword
= RID_MAX
;
231 token
->pragma_kind
= PRAGMA_NONE
;
239 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
240 if (c_dialect_objc ())
241 parser
->objc_need_raw_identifier
= false;
243 if (C_IS_RESERVED_WORD (token
->value
))
245 enum rid rid_code
= C_RID_CODE (token
->value
);
247 if (rid_code
== RID_CXX_COMPAT_WARN
)
249 warning_at (token
->location
,
251 "identifier %qE conflicts with C++ keyword",
254 else if (rid_code
>= RID_FIRST_ADDR_SPACE
255 && rid_code
<= RID_LAST_ADDR_SPACE
)
257 token
->id_kind
= C_ID_ADDRSPACE
;
258 token
->keyword
= rid_code
;
261 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
263 /* We found an Objective-C "pq" keyword (in, out,
264 inout, bycopy, byref, oneway). They need special
265 care because the interpretation depends on the
267 if (parser
->objc_pq_context
)
269 token
->type
= CPP_KEYWORD
;
270 token
->keyword
= rid_code
;
273 else if (parser
->objc_could_be_foreach_context
274 && rid_code
== RID_IN
)
276 /* We are in Objective-C, inside a (potential)
277 foreach context (which means after having
278 parsed 'for (', but before having parsed ';'),
279 and we found 'in'. We consider it the keyword
280 which terminates the declaration at the
281 beginning of a foreach-statement. Note that
282 this means you can't use 'in' for anything else
283 in that context; in particular, in Objective-C
284 you can't use 'in' as the name of the running
285 variable in a C for loop. We could potentially
286 try to add code here to disambiguate, but it
287 seems a reasonable limitation. */
288 token
->type
= CPP_KEYWORD
;
289 token
->keyword
= rid_code
;
292 /* Else, "pq" keywords outside of the "pq" context are
293 not keywords, and we fall through to the code for
296 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
298 /* We found an Objective-C "property attribute"
299 keyword (getter, setter, readonly, etc). These are
300 only valid in the property context. */
301 if (parser
->objc_property_attr_context
)
303 token
->type
= CPP_KEYWORD
;
304 token
->keyword
= rid_code
;
307 /* Else they are not special keywords.
310 else if (c_dialect_objc ()
311 && (OBJC_IS_AT_KEYWORD (rid_code
)
312 || OBJC_IS_CXX_KEYWORD (rid_code
)))
314 /* We found one of the Objective-C "@" keywords (defs,
315 selector, synchronized, etc) or one of the
316 Objective-C "cxx" keywords (class, private,
317 protected, public, try, catch, throw) without a
318 preceding '@' sign. Do nothing and fall through to
319 the code for normal tokens (in C++ we would still
320 consider the CXX ones keywords, but not in C). */
325 token
->type
= CPP_KEYWORD
;
326 token
->keyword
= rid_code
;
331 decl
= lookup_name (token
->value
);
334 if (TREE_CODE (decl
) == TYPE_DECL
)
336 token
->id_kind
= C_ID_TYPENAME
;
340 else if (c_dialect_objc ())
342 tree objc_interface_decl
= objc_is_class_name (token
->value
);
343 /* Objective-C class names are in the same namespace as
344 variables and typedefs, and hence are shadowed by local
346 if (objc_interface_decl
347 && (!objc_force_identifier
|| global_bindings_p ()))
349 token
->value
= objc_interface_decl
;
350 token
->id_kind
= C_ID_CLASSNAME
;
354 token
->id_kind
= C_ID_ID
;
358 /* This only happens in Objective-C; it must be a keyword. */
359 token
->type
= CPP_KEYWORD
;
360 switch (C_RID_CODE (token
->value
))
362 /* Replace 'class' with '@class', 'private' with '@private',
363 etc. This prevents confusion with the C++ keyword
364 'class', and makes the tokens consistent with other
365 Objective-C 'AT' keywords. For example '@class' is
366 reported as RID_AT_CLASS which is consistent with
367 '@synchronized', which is reported as
370 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
371 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
372 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
373 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
374 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
375 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
376 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
377 default: token
->keyword
= C_RID_CODE (token
->value
);
382 case CPP_CLOSE_PAREN
:
384 /* These tokens may affect the interpretation of any identifiers
385 following, if doing Objective-C. */
386 if (c_dialect_objc ())
387 parser
->objc_need_raw_identifier
= false;
390 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
391 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
397 timevar_pop (TV_LEX
);
400 /* Return a pointer to the next token from PARSER, reading it in if
403 static inline c_token
*
404 c_parser_peek_token (c_parser
*parser
)
406 if (parser
->tokens_avail
== 0)
408 c_lex_one_token (parser
, &parser
->tokens
[0]);
409 parser
->tokens_avail
= 1;
411 return &parser
->tokens
[0];
414 /* Return true if the next token from PARSER has the indicated
418 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
420 return c_parser_peek_token (parser
)->type
== type
;
423 /* Return true if the next token from PARSER does not have the
427 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
429 return !c_parser_next_token_is (parser
, type
);
432 /* Return true if the next token from PARSER is the indicated
436 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
438 return c_parser_peek_token (parser
)->keyword
== keyword
;
441 /* Return a pointer to the next-but-one token from PARSER, reading it
442 in if necessary. The next token is already read in. */
445 c_parser_peek_2nd_token (c_parser
*parser
)
447 if (parser
->tokens_avail
>= 2)
448 return &parser
->tokens
[1];
449 gcc_assert (parser
->tokens_avail
== 1);
450 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
451 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
452 c_lex_one_token (parser
, &parser
->tokens
[1]);
453 parser
->tokens_avail
= 2;
454 return &parser
->tokens
[1];
457 /* Return true if TOKEN can start a type name,
460 c_token_starts_typename (c_token
*token
)
465 switch (token
->id_kind
)
474 gcc_assert (c_dialect_objc ());
480 switch (token
->keyword
)
515 if (c_dialect_objc ())
523 enum c_lookahead_kind
{
524 /* Always treat unknown identifiers as typenames. */
527 /* Could be parsing a nonabstract declarator. Only treat an identifier
528 as a typename if followed by another identifier or a star. */
529 cla_nonabstract_decl
,
531 /* Never treat identifiers as typenames. */
535 /* Return true if the next token from PARSER can start a type name,
536 false otherwise. LA specifies how to do lookahead in order to
537 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
540 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
542 c_token
*token
= c_parser_peek_token (parser
);
543 if (c_token_starts_typename (token
))
546 /* Try a bit harder to detect an unknown typename. */
547 if (la
!= cla_prefer_id
548 && token
->type
== CPP_NAME
549 && token
->id_kind
== C_ID_ID
551 /* Do not try too hard when we could have "object in array". */
552 && !parser
->objc_could_be_foreach_context
554 && (la
== cla_prefer_type
555 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
556 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
558 /* Only unknown identifiers. */
559 && !lookup_name (token
->value
))
565 /* Return true if TOKEN is a type qualifier, false otherwise. */
567 c_token_is_qualifier (c_token
*token
)
572 switch (token
->id_kind
)
580 switch (token
->keyword
)
598 /* Return true if the next token from PARSER is a type qualifier,
601 c_parser_next_token_is_qualifier (c_parser
*parser
)
603 c_token
*token
= c_parser_peek_token (parser
);
604 return c_token_is_qualifier (token
);
607 /* Return true if TOKEN can start declaration specifiers, false
610 c_token_starts_declspecs (c_token
*token
)
615 switch (token
->id_kind
)
624 gcc_assert (c_dialect_objc ());
630 switch (token
->keyword
)
674 if (c_dialect_objc ())
683 /* Return true if TOKEN can start declaration specifiers or a static
684 assertion, false otherwise. */
686 c_token_starts_declaration (c_token
*token
)
688 if (c_token_starts_declspecs (token
)
689 || token
->keyword
== RID_STATIC_ASSERT
)
695 /* Return true if the next token from PARSER can start declaration
696 specifiers, false otherwise. */
698 c_parser_next_token_starts_declspecs (c_parser
*parser
)
700 c_token
*token
= c_parser_peek_token (parser
);
702 /* In Objective-C, a classname normally starts a declspecs unless it
703 is immediately followed by a dot. In that case, it is the
704 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
705 setter/getter on the class. c_token_starts_declspecs() can't
706 differentiate between the two cases because it only checks the
707 current token, so we have a special check here. */
708 if (c_dialect_objc ()
709 && token
->type
== CPP_NAME
710 && token
->id_kind
== C_ID_CLASSNAME
711 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
714 return c_token_starts_declspecs (token
);
717 /* Return true if the next tokens from PARSER can start declaration
718 specifiers or a static assertion, false otherwise. */
720 c_parser_next_tokens_start_declaration (c_parser
*parser
)
722 c_token
*token
= c_parser_peek_token (parser
);
725 if (c_dialect_objc ()
726 && token
->type
== CPP_NAME
727 && token
->id_kind
== C_ID_CLASSNAME
728 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
731 /* Labels do not start declarations. */
732 if (token
->type
== CPP_NAME
733 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
736 if (c_token_starts_declaration (token
))
739 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
745 /* Consume the next token from PARSER. */
748 c_parser_consume_token (c_parser
*parser
)
750 gcc_assert (parser
->tokens_avail
>= 1);
751 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
752 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
753 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
754 if (parser
->tokens
!= &parser
->tokens_buf
[0])
756 else if (parser
->tokens_avail
== 2)
757 parser
->tokens
[0] = parser
->tokens
[1];
758 parser
->tokens_avail
--;
761 /* Expect the current token to be a #pragma. Consume it and remember
762 that we've begun parsing a pragma. */
765 c_parser_consume_pragma (c_parser
*parser
)
767 gcc_assert (!parser
->in_pragma
);
768 gcc_assert (parser
->tokens_avail
>= 1);
769 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
770 if (parser
->tokens
!= &parser
->tokens_buf
[0])
772 else if (parser
->tokens_avail
== 2)
773 parser
->tokens
[0] = parser
->tokens
[1];
774 parser
->tokens_avail
--;
775 parser
->in_pragma
= true;
778 /* Update the global input_location from TOKEN. */
780 c_parser_set_source_position_from_token (c_token
*token
)
782 if (token
->type
!= CPP_EOF
)
784 input_location
= token
->location
;
788 /* Issue a diagnostic of the form
789 FILE:LINE: MESSAGE before TOKEN
790 where TOKEN is the next token in the input stream of PARSER.
791 MESSAGE (specified by the caller) is usually of the form "expected
794 Do not issue a diagnostic if still recovering from an error.
796 ??? This is taken from the C++ parser, but building up messages in
797 this way is not i18n-friendly and some other approach should be
801 c_parser_error (c_parser
*parser
, const char *gmsgid
)
803 c_token
*token
= c_parser_peek_token (parser
);
806 parser
->error
= true;
809 /* This diagnostic makes more sense if it is tagged to the line of
810 the token we just peeked at. */
811 c_parser_set_source_position_from_token (token
);
812 c_parse_error (gmsgid
,
813 /* Because c_parse_error does not understand
814 CPP_KEYWORD, keywords are treated like
816 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
817 /* ??? The C parser does not save the cpp flags of a
818 token, we need to pass 0 here and we will not get
819 the source spelling of some tokens but rather the
820 canonical spelling. */
821 token
->value
, /*flags=*/0);
824 /* If the next token is of the indicated TYPE, consume it. Otherwise,
825 issue the error MSGID. If MSGID is NULL then a message has already
826 been produced and no message will be produced this time. Returns
827 true if found, false otherwise. */
830 c_parser_require (c_parser
*parser
,
834 if (c_parser_next_token_is (parser
, type
))
836 c_parser_consume_token (parser
);
841 c_parser_error (parser
, msgid
);
846 /* If the next token is the indicated keyword, consume it. Otherwise,
847 issue the error MSGID. Returns true if found, false otherwise. */
850 c_parser_require_keyword (c_parser
*parser
,
854 if (c_parser_next_token_is_keyword (parser
, keyword
))
856 c_parser_consume_token (parser
);
861 c_parser_error (parser
, msgid
);
866 /* Like c_parser_require, except that tokens will be skipped until the
867 desired token is found. An error message is still produced if the
868 next token is not as expected. If MSGID is NULL then a message has
869 already been produced and no message will be produced this
873 c_parser_skip_until_found (c_parser
*parser
,
877 unsigned nesting_depth
= 0;
879 if (c_parser_require (parser
, type
, msgid
))
882 /* Skip tokens until the desired token is found. */
885 /* Peek at the next token. */
886 c_token
*token
= c_parser_peek_token (parser
);
887 /* If we've reached the token we want, consume it and stop. */
888 if (token
->type
== type
&& !nesting_depth
)
890 c_parser_consume_token (parser
);
894 /* If we've run out of tokens, stop. */
895 if (token
->type
== CPP_EOF
)
897 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
899 if (token
->type
== CPP_OPEN_BRACE
900 || token
->type
== CPP_OPEN_PAREN
901 || token
->type
== CPP_OPEN_SQUARE
)
903 else if (token
->type
== CPP_CLOSE_BRACE
904 || token
->type
== CPP_CLOSE_PAREN
905 || token
->type
== CPP_CLOSE_SQUARE
)
907 if (nesting_depth
-- == 0)
910 /* Consume this token. */
911 c_parser_consume_token (parser
);
913 parser
->error
= false;
916 /* Skip tokens until the end of a parameter is found, but do not
917 consume the comma, semicolon or closing delimiter. */
920 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
922 unsigned nesting_depth
= 0;
926 c_token
*token
= c_parser_peek_token (parser
);
927 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
930 /* If we've run out of tokens, stop. */
931 if (token
->type
== CPP_EOF
)
933 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
935 if (token
->type
== CPP_OPEN_BRACE
936 || token
->type
== CPP_OPEN_PAREN
937 || token
->type
== CPP_OPEN_SQUARE
)
939 else if (token
->type
== CPP_CLOSE_BRACE
940 || token
->type
== CPP_CLOSE_PAREN
941 || token
->type
== CPP_CLOSE_SQUARE
)
943 if (nesting_depth
-- == 0)
946 /* Consume this token. */
947 c_parser_consume_token (parser
);
949 parser
->error
= false;
952 /* Expect to be at the end of the pragma directive and consume an
953 end of line marker. */
956 c_parser_skip_to_pragma_eol (c_parser
*parser
)
958 gcc_assert (parser
->in_pragma
);
959 parser
->in_pragma
= false;
961 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
964 c_token
*token
= c_parser_peek_token (parser
);
965 if (token
->type
== CPP_EOF
)
967 if (token
->type
== CPP_PRAGMA_EOL
)
969 c_parser_consume_token (parser
);
972 c_parser_consume_token (parser
);
975 parser
->error
= false;
978 /* Skip tokens until we have consumed an entire block, or until we
979 have consumed a non-nested ';'. */
982 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
984 unsigned nesting_depth
= 0;
985 bool save_error
= parser
->error
;
991 /* Peek at the next token. */
992 token
= c_parser_peek_token (parser
);
1000 if (parser
->in_pragma
)
1005 /* If the next token is a ';', we have reached the
1006 end of the statement. */
1009 /* Consume the ';'. */
1010 c_parser_consume_token (parser
);
1015 case CPP_CLOSE_BRACE
:
1016 /* If the next token is a non-nested '}', then we have
1017 reached the end of the current block. */
1018 if (nesting_depth
== 0 || --nesting_depth
== 0)
1020 c_parser_consume_token (parser
);
1025 case CPP_OPEN_BRACE
:
1026 /* If it the next token is a '{', then we are entering a new
1027 block. Consume the entire block. */
1032 /* If we see a pragma, consume the whole thing at once. We
1033 have some safeguards against consuming pragmas willy-nilly.
1034 Normally, we'd expect to be here with parser->error set,
1035 which disables these safeguards. But it's possible to get
1036 here for secondary error recovery, after parser->error has
1038 c_parser_consume_pragma (parser
);
1039 c_parser_skip_to_pragma_eol (parser
);
1040 parser
->error
= save_error
;
1047 c_parser_consume_token (parser
);
1051 parser
->error
= false;
1054 /* CPP's options (initialized by c-opts.c). */
1055 extern cpp_options
*cpp_opts
;
1057 /* Save the warning flags which are controlled by __extension__. */
1060 disable_extension_diagnostics (void)
1063 | (warn_pointer_arith
<< 1)
1064 | (warn_traditional
<< 2)
1066 | (warn_long_long
<< 4)
1067 | (warn_cxx_compat
<< 5)
1068 | (warn_overlength_strings
<< 6));
1069 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1070 warn_pointer_arith
= 0;
1071 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1073 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1074 warn_cxx_compat
= 0;
1075 warn_overlength_strings
= 0;
1079 /* Restore the warning flags which are controlled by __extension__.
1080 FLAGS is the return value from disable_extension_diagnostics. */
1083 restore_extension_diagnostics (int flags
)
1085 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1086 warn_pointer_arith
= (flags
>> 1) & 1;
1087 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1088 flag_iso
= (flags
>> 3) & 1;
1089 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1090 warn_cxx_compat
= (flags
>> 5) & 1;
1091 warn_overlength_strings
= (flags
>> 6) & 1;
1094 /* Possibly kinds of declarator to parse. */
1095 typedef enum c_dtr_syn
{
1096 /* A normal declarator with an identifier. */
1098 /* An abstract declarator (maybe empty). */
1100 /* A parameter declarator: may be either, but after a type name does
1101 not redeclare a typedef name as an identifier if it can
1102 alternatively be interpreted as a typedef name; see DR#009,
1103 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1104 following DR#249. For example, given a typedef T, "int T" and
1105 "int *T" are valid parameter declarations redeclaring T, while
1106 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1107 abstract declarators rather than involving redundant parentheses;
1108 the same applies with attributes inside the parentheses before
1113 /* The binary operation precedence levels, where 0 is a dummy lowest level
1114 used for the bottom of the stack. */
1115 enum c_parser_prec
{
1130 static void c_parser_external_declaration (c_parser
*);
1131 static void c_parser_asm_definition (c_parser
*);
1132 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1133 bool, bool, tree
*, vec
<c_token
>);
1134 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1135 static void c_parser_static_assert_declaration (c_parser
*);
1136 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1137 bool, bool, bool, enum c_lookahead_kind
);
1138 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1139 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1140 static tree
c_parser_struct_declaration (c_parser
*);
1141 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1142 static tree
c_parser_alignas_specifier (c_parser
*);
1143 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1145 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1147 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1149 struct c_declarator
*);
1150 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1151 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1153 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1154 static tree
c_parser_simple_asm_expr (c_parser
*);
1155 static tree
c_parser_attributes (c_parser
*);
1156 static struct c_type_name
*c_parser_type_name (c_parser
*);
1157 static struct c_expr
c_parser_initializer (c_parser
*);
1158 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1159 static void c_parser_initelt (c_parser
*, struct obstack
*);
1160 static void c_parser_initval (c_parser
*, struct c_expr
*,
1162 static tree
c_parser_compound_statement (c_parser
*);
1163 static void c_parser_compound_statement_nostart (c_parser
*);
1164 static void c_parser_label (c_parser
*);
1165 static void c_parser_statement (c_parser
*);
1166 static void c_parser_statement_after_labels (c_parser
*);
1167 static void c_parser_if_statement (c_parser
*);
1168 static void c_parser_switch_statement (c_parser
*);
1169 static void c_parser_while_statement (c_parser
*, bool);
1170 static void c_parser_do_statement (c_parser
*, bool);
1171 static void c_parser_for_statement (c_parser
*, bool);
1172 static tree
c_parser_asm_statement (c_parser
*);
1173 static tree
c_parser_asm_operands (c_parser
*);
1174 static tree
c_parser_asm_goto_operands (c_parser
*);
1175 static tree
c_parser_asm_clobbers (c_parser
*);
1176 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1178 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1179 struct c_expr
*, tree
);
1180 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1182 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1183 static struct c_expr
c_parser_unary_expression (c_parser
*);
1184 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1185 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1186 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1187 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1188 struct c_type_name
*,
1190 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1193 static tree
c_parser_transaction (c_parser
*, enum rid
);
1194 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1195 static tree
c_parser_transaction_cancel (c_parser
*);
1196 static struct c_expr
c_parser_expression (c_parser
*);
1197 static struct c_expr
c_parser_expression_conv (c_parser
*);
1198 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1199 vec
<tree
, va_gc
> **, location_t
*,
1201 static void c_parser_omp_construct (c_parser
*);
1202 static void c_parser_omp_threadprivate (c_parser
*);
1203 static void c_parser_omp_barrier (c_parser
*);
1204 static void c_parser_omp_flush (c_parser
*);
1205 static void c_parser_omp_taskwait (c_parser
*);
1206 static void c_parser_omp_taskyield (c_parser
*);
1207 static void c_parser_omp_cancel (c_parser
*);
1208 static void c_parser_omp_cancellation_point (c_parser
*);
1210 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1211 pragma_stmt
, pragma_compound
};
1212 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1213 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1214 static void c_parser_omp_end_declare_target (c_parser
*);
1215 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1217 /* These Objective-C parser functions are only ever called when
1218 compiling Objective-C. */
1219 static void c_parser_objc_class_definition (c_parser
*, tree
);
1220 static void c_parser_objc_class_instance_variables (c_parser
*);
1221 static void c_parser_objc_class_declaration (c_parser
*);
1222 static void c_parser_objc_alias_declaration (c_parser
*);
1223 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1224 static bool c_parser_objc_method_type (c_parser
*);
1225 static void c_parser_objc_method_definition (c_parser
*);
1226 static void c_parser_objc_methodprotolist (c_parser
*);
1227 static void c_parser_objc_methodproto (c_parser
*);
1228 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1229 static tree
c_parser_objc_type_name (c_parser
*);
1230 static tree
c_parser_objc_protocol_refs (c_parser
*);
1231 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1232 static void c_parser_objc_synchronized_statement (c_parser
*);
1233 static tree
c_parser_objc_selector (c_parser
*);
1234 static tree
c_parser_objc_selector_arg (c_parser
*);
1235 static tree
c_parser_objc_receiver (c_parser
*);
1236 static tree
c_parser_objc_message_args (c_parser
*);
1237 static tree
c_parser_objc_keywordexpr (c_parser
*);
1238 static void c_parser_objc_at_property_declaration (c_parser
*);
1239 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1240 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1241 static bool c_parser_objc_diagnose_bad_element_prefix
1242 (c_parser
*, struct c_declspecs
*);
1244 /* Cilk Plus supporting routines. */
1245 static void c_parser_cilk_simd (c_parser
*);
1246 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1247 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1249 /* Parse a translation unit (C90 6.7, C99 6.9).
1252 external-declarations
1254 external-declarations:
1255 external-declaration
1256 external-declarations external-declaration
1265 c_parser_translation_unit (c_parser
*parser
)
1267 if (c_parser_next_token_is (parser
, CPP_EOF
))
1269 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1270 "ISO C forbids an empty translation unit");
1274 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1275 mark_valid_location_for_stdc_pragma (false);
1279 c_parser_external_declaration (parser
);
1280 obstack_free (&parser_obstack
, obstack_position
);
1282 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1286 /* Parse an external declaration (C90 6.7, C99 6.9).
1288 external-declaration:
1294 external-declaration:
1297 __extension__ external-declaration
1301 external-declaration:
1302 objc-class-definition
1303 objc-class-declaration
1304 objc-alias-declaration
1305 objc-protocol-definition
1306 objc-method-definition
1311 c_parser_external_declaration (c_parser
*parser
)
1314 switch (c_parser_peek_token (parser
)->type
)
1317 switch (c_parser_peek_token (parser
)->keyword
)
1320 ext
= disable_extension_diagnostics ();
1321 c_parser_consume_token (parser
);
1322 c_parser_external_declaration (parser
);
1323 restore_extension_diagnostics (ext
);
1326 c_parser_asm_definition (parser
);
1328 case RID_AT_INTERFACE
:
1329 case RID_AT_IMPLEMENTATION
:
1330 gcc_assert (c_dialect_objc ());
1331 c_parser_objc_class_definition (parser
, NULL_TREE
);
1334 gcc_assert (c_dialect_objc ());
1335 c_parser_objc_class_declaration (parser
);
1338 gcc_assert (c_dialect_objc ());
1339 c_parser_objc_alias_declaration (parser
);
1341 case RID_AT_PROTOCOL
:
1342 gcc_assert (c_dialect_objc ());
1343 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1345 case RID_AT_PROPERTY
:
1346 gcc_assert (c_dialect_objc ());
1347 c_parser_objc_at_property_declaration (parser
);
1349 case RID_AT_SYNTHESIZE
:
1350 gcc_assert (c_dialect_objc ());
1351 c_parser_objc_at_synthesize_declaration (parser
);
1353 case RID_AT_DYNAMIC
:
1354 gcc_assert (c_dialect_objc ());
1355 c_parser_objc_at_dynamic_declaration (parser
);
1358 gcc_assert (c_dialect_objc ());
1359 c_parser_consume_token (parser
);
1360 objc_finish_implementation ();
1367 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1368 "ISO C does not allow extra %<;%> outside of a function");
1369 c_parser_consume_token (parser
);
1372 mark_valid_location_for_stdc_pragma (true);
1373 c_parser_pragma (parser
, pragma_external
);
1374 mark_valid_location_for_stdc_pragma (false);
1378 if (c_dialect_objc ())
1380 c_parser_objc_method_definition (parser
);
1383 /* Else fall through, and yield a syntax error trying to parse
1384 as a declaration or function definition. */
1387 /* A declaration or a function definition (or, in Objective-C,
1388 an @interface or @protocol with prefix attributes). We can
1389 only tell which after parsing the declaration specifiers, if
1390 any, and the first declarator. */
1391 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1397 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1399 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1400 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1401 accepted; otherwise (old-style parameter declarations) only other
1402 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1403 assertion is accepted; otherwise (old-style parameter declarations)
1404 it is not. If NESTED is true, we are inside a function or parsing
1405 old-style parameter declarations; any functions encountered are
1406 nested functions and declaration specifiers are required; otherwise
1407 we are at top level and functions are normal functions and
1408 declaration specifiers may be optional. If EMPTY_OK is true, empty
1409 declarations are OK (subject to all other constraints); otherwise
1410 (old-style parameter declarations) they are diagnosed. If
1411 START_ATTR_OK is true, the declaration specifiers may start with
1412 attributes; otherwise they may not.
1413 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1414 declaration when parsing an Objective-C foreach statement.
1417 declaration-specifiers init-declarator-list[opt] ;
1418 static_assert-declaration
1420 function-definition:
1421 declaration-specifiers[opt] declarator declaration-list[opt]
1426 declaration-list declaration
1428 init-declarator-list:
1430 init-declarator-list , init-declarator
1433 declarator simple-asm-expr[opt] attributes[opt]
1434 declarator simple-asm-expr[opt] attributes[opt] = initializer
1438 nested-function-definition:
1439 declaration-specifiers declarator declaration-list[opt]
1443 attributes objc-class-definition
1444 attributes objc-category-definition
1445 attributes objc-protocol-definition
1447 The simple-asm-expr and attributes are GNU extensions.
1449 This function does not handle __extension__; that is handled in its
1450 callers. ??? Following the old parser, __extension__ may start
1451 external declarations, declarations in functions and declarations
1452 at the start of "for" loops, but not old-style parameter
1455 C99 requires declaration specifiers in a function definition; the
1456 absence is diagnosed through the diagnosis of implicit int. In GNU
1457 C we also allow but diagnose declarations without declaration
1458 specifiers, but only at top level (elsewhere they conflict with
1461 In Objective-C, declarations of the looping variable in a foreach
1462 statement are exceptionally terminated by 'in' (for example, 'for
1463 (NSObject *object in array) { ... }').
1468 threadprivate-directive */
1471 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1472 bool static_assert_ok
, bool empty_ok
,
1473 bool nested
, bool start_attr_ok
,
1474 tree
*objc_foreach_object_declaration
,
1475 vec
<c_token
> omp_declare_simd_clauses
)
1477 struct c_declspecs
*specs
;
1479 tree all_prefix_attrs
;
1480 bool diagnosed_no_specs
= false;
1481 location_t here
= c_parser_peek_token (parser
)->location
;
1483 if (static_assert_ok
1484 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1486 c_parser_static_assert_declaration (parser
);
1489 specs
= build_null_declspecs ();
1491 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1492 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1493 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1494 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1495 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1496 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1498 error_at (here
, "unknown type name %qE",
1499 c_parser_peek_token (parser
)->value
);
1501 /* Parse declspecs normally to get a correct pointer type, but avoid
1502 a further "fails to be a type name" error. Refuse nested functions
1503 since it is not how the user likely wants us to recover. */
1504 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1505 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1506 c_parser_peek_token (parser
)->value
= error_mark_node
;
1510 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1511 true, true, cla_nonabstract_decl
);
1514 c_parser_skip_to_end_of_block_or_statement (parser
);
1517 if (nested
&& !specs
->declspecs_seen_p
)
1519 c_parser_error (parser
, "expected declaration specifiers");
1520 c_parser_skip_to_end_of_block_or_statement (parser
);
1523 finish_declspecs (specs
);
1524 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1525 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1528 error_at (here
, "%<__auto_type%> in empty declaration");
1533 shadow_tag_warned (specs
, 1);
1534 pedwarn (here
, 0, "empty declaration");
1536 c_parser_consume_token (parser
);
1540 /* Provide better error recovery. Note that a type name here is usually
1541 better diagnosed as a redeclaration. */
1543 && specs
->typespec_kind
== ctsk_tagdef
1544 && c_parser_next_token_starts_declspecs (parser
)
1545 && !c_parser_next_token_is (parser
, CPP_NAME
))
1547 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1548 parser
->error
= false;
1549 shadow_tag_warned (specs
, 1);
1552 else if (c_dialect_objc () && !auto_type_p
)
1554 /* Prefix attributes are an error on method decls. */
1555 switch (c_parser_peek_token (parser
)->type
)
1559 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1563 warning_at (c_parser_peek_token (parser
)->location
,
1565 "prefix attributes are ignored for methods");
1566 specs
->attrs
= NULL_TREE
;
1569 c_parser_objc_method_definition (parser
);
1571 c_parser_objc_methodproto (parser
);
1577 /* This is where we parse 'attributes @interface ...',
1578 'attributes @implementation ...', 'attributes @protocol ...'
1579 (where attributes could be, for example, __attribute__
1582 switch (c_parser_peek_token (parser
)->keyword
)
1584 case RID_AT_INTERFACE
:
1586 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1588 c_parser_objc_class_definition (parser
, specs
->attrs
);
1592 case RID_AT_IMPLEMENTATION
:
1594 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1598 warning_at (c_parser_peek_token (parser
)->location
,
1600 "prefix attributes are ignored for implementations");
1601 specs
->attrs
= NULL_TREE
;
1603 c_parser_objc_class_definition (parser
, NULL_TREE
);
1607 case RID_AT_PROTOCOL
:
1609 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1611 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1618 case RID_AT_PROPERTY
:
1621 c_parser_error (parser
, "unexpected attribute");
1622 specs
->attrs
= NULL
;
1630 pending_xref_error ();
1631 prefix_attrs
= specs
->attrs
;
1632 all_prefix_attrs
= prefix_attrs
;
1633 specs
->attrs
= NULL_TREE
;
1636 struct c_declarator
*declarator
;
1640 /* Declaring either one or more declarators (in which case we
1641 should diagnose if there were no declaration specifiers) or a
1642 function definition (in which case the diagnostic for
1643 implicit int suffices). */
1644 declarator
= c_parser_declarator (parser
,
1645 specs
->typespec_kind
!= ctsk_none
,
1646 C_DTR_NORMAL
, &dummy
);
1647 if (declarator
== NULL
)
1649 if (omp_declare_simd_clauses
.exists ())
1650 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1651 omp_declare_simd_clauses
);
1652 c_parser_skip_to_end_of_block_or_statement (parser
);
1655 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1658 "%<__auto_type%> requires a plain identifier"
1660 c_parser_skip_to_end_of_block_or_statement (parser
);
1663 if (c_parser_next_token_is (parser
, CPP_EQ
)
1664 || c_parser_next_token_is (parser
, CPP_COMMA
)
1665 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1666 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1667 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1668 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1670 tree asm_name
= NULL_TREE
;
1671 tree postfix_attrs
= NULL_TREE
;
1672 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1674 diagnosed_no_specs
= true;
1675 pedwarn (here
, 0, "data definition has no type or storage class");
1677 /* Having seen a data definition, there cannot now be a
1678 function definition. */
1680 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1681 asm_name
= c_parser_simple_asm_expr (parser
);
1682 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1683 postfix_attrs
= c_parser_attributes (parser
);
1684 if (c_parser_next_token_is (parser
, CPP_EQ
))
1688 location_t init_loc
;
1689 c_parser_consume_token (parser
);
1692 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1693 init_loc
= c_parser_peek_token (parser
)->location
;
1694 init
= c_parser_expr_no_commas (parser
, NULL
);
1695 if (TREE_CODE (init
.value
) == COMPONENT_REF
1696 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1698 "%<__auto_type%> used with a bit-field"
1700 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1701 tree init_type
= TREE_TYPE (init
.value
);
1702 /* As with typeof, remove _Atomic and const
1703 qualifiers from atomic types. */
1704 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1706 = c_build_qualified_type (init_type
,
1707 (TYPE_QUALS (init_type
)
1708 & ~(TYPE_QUAL_ATOMIC
1709 | TYPE_QUAL_CONST
)));
1710 bool vm_type
= variably_modified_type_p (init_type
,
1713 init
.value
= c_save_expr (init
.value
);
1715 specs
->typespec_kind
= ctsk_typeof
;
1716 specs
->locations
[cdw_typedef
] = init_loc
;
1717 specs
->typedef_p
= true;
1718 specs
->type
= init_type
;
1721 bool maybe_const
= true;
1722 tree type_expr
= c_fully_fold (init
.value
, false,
1724 specs
->expr_const_operands
&= maybe_const
;
1726 specs
->expr
= build2 (COMPOUND_EXPR
,
1727 TREE_TYPE (type_expr
),
1728 specs
->expr
, type_expr
);
1730 specs
->expr
= type_expr
;
1732 d
= start_decl (declarator
, specs
, true,
1733 chainon (postfix_attrs
, all_prefix_attrs
));
1735 d
= error_mark_node
;
1736 if (omp_declare_simd_clauses
.exists ())
1737 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1738 omp_declare_simd_clauses
);
1742 /* The declaration of the variable is in effect while
1743 its initializer is parsed. */
1744 d
= start_decl (declarator
, specs
, true,
1745 chainon (postfix_attrs
, all_prefix_attrs
));
1747 d
= error_mark_node
;
1748 if (omp_declare_simd_clauses
.exists ())
1749 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1750 omp_declare_simd_clauses
);
1751 start_init (d
, asm_name
, global_bindings_p ());
1752 init_loc
= c_parser_peek_token (parser
)->location
;
1753 init
= c_parser_initializer (parser
);
1756 if (d
!= error_mark_node
)
1758 maybe_warn_string_init (TREE_TYPE (d
), init
);
1759 finish_decl (d
, init_loc
, init
.value
,
1760 init
.original_type
, asm_name
);
1768 "%<__auto_type%> requires an initialized "
1769 "data declaration");
1770 c_parser_skip_to_end_of_block_or_statement (parser
);
1773 tree d
= start_decl (declarator
, specs
, false,
1774 chainon (postfix_attrs
,
1776 if (omp_declare_simd_clauses
.exists ())
1778 tree parms
= NULL_TREE
;
1779 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1781 struct c_declarator
*ce
= declarator
;
1783 if (ce
->kind
== cdk_function
)
1785 parms
= ce
->u
.arg_info
->parms
;
1789 ce
= ce
->declarator
;
1792 temp_store_parm_decls (d
, parms
);
1793 c_finish_omp_declare_simd (parser
, d
, parms
,
1794 omp_declare_simd_clauses
);
1796 temp_pop_parm_decls ();
1799 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1800 NULL_TREE
, asm_name
);
1802 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1805 *objc_foreach_object_declaration
= d
;
1807 *objc_foreach_object_declaration
= error_mark_node
;
1810 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1815 "%<__auto_type%> may only be used with"
1816 " a single declarator");
1817 c_parser_skip_to_end_of_block_or_statement (parser
);
1820 c_parser_consume_token (parser
);
1821 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1822 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1825 all_prefix_attrs
= prefix_attrs
;
1828 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1830 c_parser_consume_token (parser
);
1833 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1835 /* This can only happen in Objective-C: we found the
1836 'in' that terminates the declaration inside an
1837 Objective-C foreach statement. Do not consume the
1838 token, so that the caller can use it to determine
1839 that this indeed is a foreach context. */
1844 c_parser_error (parser
, "expected %<,%> or %<;%>");
1845 c_parser_skip_to_end_of_block_or_statement (parser
);
1849 else if (auto_type_p
)
1852 "%<__auto_type%> requires an initialized data declaration");
1853 c_parser_skip_to_end_of_block_or_statement (parser
);
1858 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1859 "%<asm%> or %<__attribute__%>");
1860 c_parser_skip_to_end_of_block_or_statement (parser
);
1863 /* Function definition (nested or otherwise). */
1866 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1867 c_push_function_context ();
1869 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1871 /* This can appear in many cases looking nothing like a
1872 function definition, so we don't give a more specific
1873 error suggesting there was one. */
1874 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1875 "or %<__attribute__%>");
1877 c_pop_function_context ();
1881 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1882 tv
= TV_PARSE_INLINE
;
1887 /* Parse old-style parameter declarations. ??? Attributes are
1888 not allowed to start declaration specifiers here because of a
1889 syntax conflict between a function declaration with attribute
1890 suffix and a function definition with an attribute prefix on
1891 first old-style parameter declaration. Following the old
1892 parser, they are not accepted on subsequent old-style
1893 parameter declarations either. However, there is no
1894 ambiguity after the first declaration, nor indeed on the
1895 first as long as we don't allow postfix attributes after a
1896 declarator with a nonempty identifier list in a definition;
1897 and postfix attributes have never been accepted here in
1898 function definitions either. */
1899 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1900 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1901 c_parser_declaration_or_fndef (parser
, false, false, false,
1902 true, false, NULL
, vNULL
);
1903 store_parm_decls ();
1904 if (omp_declare_simd_clauses
.exists ())
1905 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1906 omp_declare_simd_clauses
);
1907 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1908 = c_parser_peek_token (parser
)->location
;
1909 fnbody
= c_parser_compound_statement (parser
);
1910 if (flag_enable_cilkplus
&& contains_array_notation_expr (fnbody
))
1911 fnbody
= expand_array_notation_exprs (fnbody
);
1914 tree decl
= current_function_decl
;
1915 /* Mark nested functions as needing static-chain initially.
1916 lower_nested_functions will recompute it but the
1917 DECL_STATIC_CHAIN flag is also used before that happens,
1918 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1919 DECL_STATIC_CHAIN (decl
) = 1;
1922 c_pop_function_context ();
1923 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1936 /* Parse an asm-definition (asm() outside a function body). This is a
1944 c_parser_asm_definition (c_parser
*parser
)
1946 tree asm_str
= c_parser_simple_asm_expr (parser
);
1948 add_asm_node (asm_str
);
1949 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1952 /* Parse a static assertion (C11 6.7.10).
1954 static_assert-declaration:
1955 static_assert-declaration-no-semi ;
1959 c_parser_static_assert_declaration (c_parser
*parser
)
1961 c_parser_static_assert_declaration_no_semi (parser
);
1963 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1964 c_parser_skip_to_end_of_block_or_statement (parser
);
1967 /* Parse a static assertion (C11 6.7.10), without the trailing
1970 static_assert-declaration-no-semi:
1971 _Static_assert ( constant-expression , string-literal )
1975 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1977 location_t assert_loc
, value_loc
;
1981 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1982 assert_loc
= c_parser_peek_token (parser
)->location
;
1986 pedwarn (assert_loc
, OPT_Wpedantic
,
1987 "ISO C99 does not support %<_Static_assert%>");
1989 pedwarn (assert_loc
, OPT_Wpedantic
,
1990 "ISO C90 does not support %<_Static_assert%>");
1992 c_parser_consume_token (parser
);
1993 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1995 value_loc
= c_parser_peek_token (parser
)->location
;
1996 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1997 parser
->lex_untranslated_string
= true;
1998 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2000 parser
->lex_untranslated_string
= false;
2003 switch (c_parser_peek_token (parser
)->type
)
2009 case CPP_UTF8STRING
:
2010 string
= c_parser_peek_token (parser
)->value
;
2011 c_parser_consume_token (parser
);
2012 parser
->lex_untranslated_string
= false;
2015 c_parser_error (parser
, "expected string literal");
2016 parser
->lex_untranslated_string
= false;
2019 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2021 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2023 error_at (value_loc
, "expression in static assertion is not an integer");
2026 if (TREE_CODE (value
) != INTEGER_CST
)
2028 value
= c_fully_fold (value
, false, NULL
);
2029 if (TREE_CODE (value
) == INTEGER_CST
)
2030 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2031 "is not an integer constant expression");
2033 if (TREE_CODE (value
) != INTEGER_CST
)
2035 error_at (value_loc
, "expression in static assertion is not constant");
2038 constant_expression_warning (value
);
2039 if (integer_zerop (value
))
2040 error_at (assert_loc
, "static assertion failed: %E", string
);
2043 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2044 6.7), adding them to SPECS (which may already include some).
2045 Storage class specifiers are accepted iff SCSPEC_OK; type
2046 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2047 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2048 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2050 declaration-specifiers:
2051 storage-class-specifier declaration-specifiers[opt]
2052 type-specifier declaration-specifiers[opt]
2053 type-qualifier declaration-specifiers[opt]
2054 function-specifier declaration-specifiers[opt]
2055 alignment-specifier declaration-specifiers[opt]
2057 Function specifiers (inline) are from C99, and are currently
2058 handled as storage class specifiers, as is __thread. Alignment
2059 specifiers are from C11.
2061 C90 6.5.1, C99 6.7.1:
2062 storage-class-specifier:
2070 (_Thread_local is new in C11.)
2077 (_Noreturn is new in C11.)
2079 C90 6.5.2, C99 6.7.2:
2092 [_Imaginary removed in C99 TC2]
2093 struct-or-union-specifier
2096 atomic-type-specifier
2098 (_Bool and _Complex are new in C99.)
2099 (atomic-type-specifier is new in C11.)
2101 C90 6.5.3, C99 6.7.3:
2107 address-space-qualifier
2110 (restrict is new in C99.)
2111 (_Atomic is new in C11.)
2115 declaration-specifiers:
2116 attributes declaration-specifiers[opt]
2122 identifier recognized by the target
2124 storage-class-specifier:
2138 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2139 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2141 atomic-type-specifier
2142 _Atomic ( type-name )
2147 class-name objc-protocol-refs[opt]
2148 typedef-name objc-protocol-refs
2153 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2154 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2155 bool alignspec_ok
, bool auto_type_ok
,
2156 enum c_lookahead_kind la
)
2158 bool attrs_ok
= start_attr_ok
;
2159 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2162 gcc_assert (la
== cla_prefer_id
);
2164 while (c_parser_next_token_is (parser
, CPP_NAME
)
2165 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2166 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2168 struct c_typespec t
;
2171 location_t loc
= c_parser_peek_token (parser
)->location
;
2173 /* If we cannot accept a type, exit if the next token must start
2174 one. Also, if we already have seen a tagged definition,
2175 a typename would be an error anyway and likely the user
2176 has simply forgotten a semicolon, so we exit. */
2177 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2178 && c_parser_next_tokens_start_typename (parser
, la
)
2179 && !c_parser_next_token_is_qualifier (parser
))
2182 if (c_parser_next_token_is (parser
, CPP_NAME
))
2184 c_token
*name_token
= c_parser_peek_token (parser
);
2185 tree value
= name_token
->value
;
2186 c_id_kind kind
= name_token
->id_kind
;
2188 if (kind
== C_ID_ADDRSPACE
)
2191 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2192 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2193 c_parser_consume_token (parser
);
2198 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2200 /* If we cannot accept a type, and the next token must start one,
2201 exit. Do the same if we already have seen a tagged definition,
2202 since it would be an error anyway and likely the user has simply
2203 forgotten a semicolon. */
2204 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2207 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2208 a C_ID_CLASSNAME. */
2209 c_parser_consume_token (parser
);
2212 if (kind
== C_ID_ID
)
2214 error ("unknown type name %qE", value
);
2215 t
.kind
= ctsk_typedef
;
2216 t
.spec
= error_mark_node
;
2218 else if (kind
== C_ID_TYPENAME
2219 && (!c_dialect_objc ()
2220 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2222 t
.kind
= ctsk_typedef
;
2223 /* For a typedef name, record the meaning, not the name.
2224 In case of 'foo foo, bar;'. */
2225 t
.spec
= lookup_name (value
);
2229 tree proto
= NULL_TREE
;
2230 gcc_assert (c_dialect_objc ());
2232 if (c_parser_next_token_is (parser
, CPP_LESS
))
2233 proto
= c_parser_objc_protocol_refs (parser
);
2234 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2237 t
.expr_const_operands
= true;
2238 declspecs_add_type (name_token
->location
, specs
, t
);
2241 if (c_parser_next_token_is (parser
, CPP_LESS
))
2243 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2244 nisse@lysator.liu.se. */
2246 gcc_assert (c_dialect_objc ());
2247 if (!typespec_ok
|| seen_type
)
2249 proto
= c_parser_objc_protocol_refs (parser
);
2251 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2253 t
.expr_const_operands
= true;
2254 declspecs_add_type (loc
, specs
, t
);
2257 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2258 switch (c_parser_peek_token (parser
)->keyword
)
2271 /* TODO: Distinguish between function specifiers (inline, noreturn)
2272 and storage class specifiers, either here or in
2273 declspecs_add_scspec. */
2274 declspecs_add_scspec (loc
, specs
,
2275 c_parser_peek_token (parser
)->value
);
2276 c_parser_consume_token (parser
);
2304 if (c_dialect_objc ())
2305 parser
->objc_need_raw_identifier
= true;
2306 t
.kind
= ctsk_resword
;
2307 t
.spec
= c_parser_peek_token (parser
)->value
;
2309 t
.expr_const_operands
= true;
2310 declspecs_add_type (loc
, specs
, t
);
2311 c_parser_consume_token (parser
);
2318 t
= c_parser_enum_specifier (parser
);
2319 declspecs_add_type (loc
, specs
, t
);
2327 t
= c_parser_struct_or_union_specifier (parser
);
2328 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2329 declspecs_add_type (loc
, specs
, t
);
2332 /* ??? The old parser rejected typeof after other type
2333 specifiers, but is a syntax error the best way of
2335 if (!typespec_ok
|| seen_type
)
2339 t
= c_parser_typeof_specifier (parser
);
2340 declspecs_add_type (loc
, specs
, t
);
2343 /* C parser handling of Objective-C constructs needs
2344 checking for correct lvalue-to-rvalue conversions, and
2345 the code in build_modify_expr handling various
2346 Objective-C cases, and that in build_unary_op handling
2347 Objective-C cases for increment / decrement, also needs
2348 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2349 and objc_types_are_equivalent may also need updates. */
2350 if (c_dialect_objc ())
2351 sorry ("%<_Atomic%> in Objective-C");
2352 /* C parser handling of OpenMP constructs needs checking for
2353 correct lvalue-to-rvalue conversions. */
2355 sorry ("%<_Atomic%> with OpenMP");
2359 pedwarn (loc
, OPT_Wpedantic
,
2360 "ISO C99 does not support the %<_Atomic%> qualifier");
2362 pedwarn (loc
, OPT_Wpedantic
,
2363 "ISO C90 does not support the %<_Atomic%> qualifier");
2367 value
= c_parser_peek_token (parser
)->value
;
2368 c_parser_consume_token (parser
);
2369 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2371 /* _Atomic ( type-name ). */
2373 c_parser_consume_token (parser
);
2374 struct c_type_name
*type
= c_parser_type_name (parser
);
2375 t
.kind
= ctsk_typeof
;
2376 t
.spec
= error_mark_node
;
2378 t
.expr_const_operands
= true;
2380 t
.spec
= groktypename (type
, &t
.expr
,
2381 &t
.expr_const_operands
);
2382 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2384 if (t
.spec
!= error_mark_node
)
2386 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2387 error_at (loc
, "%<_Atomic%>-qualified array type");
2388 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2389 error_at (loc
, "%<_Atomic%>-qualified function type");
2390 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2391 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2393 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2395 declspecs_add_type (loc
, specs
, t
);
2398 declspecs_add_qual (loc
, specs
, value
);
2404 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2405 c_parser_consume_token (parser
);
2410 attrs
= c_parser_attributes (parser
);
2411 declspecs_add_attrs (loc
, specs
, attrs
);
2416 align
= c_parser_alignas_specifier (parser
);
2417 declspecs_add_alignas (loc
, specs
, align
);
2426 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2429 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2430 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2431 enum attributes[opt] identifier
2433 The form with trailing comma is new in C99. The forms with
2434 attributes are GNU extensions. In GNU C, we accept any expression
2435 without commas in the syntax (assignment expressions, not just
2436 conditional expressions); assignment expressions will be diagnosed
2441 enumerator-list , enumerator
2444 enumeration-constant
2445 enumeration-constant = constant-expression
2448 static struct c_typespec
2449 c_parser_enum_specifier (c_parser
*parser
)
2451 struct c_typespec ret
;
2453 tree ident
= NULL_TREE
;
2454 location_t enum_loc
;
2455 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2456 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2457 enum_loc
= c_parser_peek_token (parser
)->location
;
2458 c_parser_consume_token (parser
);
2459 attrs
= c_parser_attributes (parser
);
2460 enum_loc
= c_parser_peek_token (parser
)->location
;
2461 /* Set the location in case we create a decl now. */
2462 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2463 if (c_parser_next_token_is (parser
, CPP_NAME
))
2465 ident
= c_parser_peek_token (parser
)->value
;
2466 ident_loc
= c_parser_peek_token (parser
)->location
;
2467 enum_loc
= ident_loc
;
2468 c_parser_consume_token (parser
);
2470 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2472 /* Parse an enum definition. */
2473 struct c_enum_contents the_enum
;
2476 /* We chain the enumerators in reverse order, then put them in
2477 forward order at the end. */
2479 timevar_push (TV_PARSE_ENUM
);
2480 type
= start_enum (enum_loc
, &the_enum
, ident
);
2482 c_parser_consume_token (parser
);
2490 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2491 location_t decl_loc
, value_loc
;
2492 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2494 c_parser_error (parser
, "expected identifier");
2495 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2496 values
= error_mark_node
;
2499 token
= c_parser_peek_token (parser
);
2500 enum_id
= token
->value
;
2501 /* Set the location in case we create a decl now. */
2502 c_parser_set_source_position_from_token (token
);
2503 decl_loc
= value_loc
= token
->location
;
2504 c_parser_consume_token (parser
);
2505 if (c_parser_next_token_is (parser
, CPP_EQ
))
2507 c_parser_consume_token (parser
);
2508 value_loc
= c_parser_peek_token (parser
)->location
;
2509 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2512 enum_value
= NULL_TREE
;
2513 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2514 &the_enum
, enum_id
, enum_value
);
2515 TREE_CHAIN (enum_decl
) = values
;
2518 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2520 comma_loc
= c_parser_peek_token (parser
)->location
;
2522 c_parser_consume_token (parser
);
2524 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2526 if (seen_comma
&& !flag_isoc99
)
2527 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2528 c_parser_consume_token (parser
);
2533 c_parser_error (parser
, "expected %<,%> or %<}%>");
2534 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2535 values
= error_mark_node
;
2539 postfix_attrs
= c_parser_attributes (parser
);
2540 ret
.spec
= finish_enum (type
, nreverse (values
),
2541 chainon (attrs
, postfix_attrs
));
2542 ret
.kind
= ctsk_tagdef
;
2543 ret
.expr
= NULL_TREE
;
2544 ret
.expr_const_operands
= true;
2545 timevar_pop (TV_PARSE_ENUM
);
2550 c_parser_error (parser
, "expected %<{%>");
2551 ret
.spec
= error_mark_node
;
2552 ret
.kind
= ctsk_tagref
;
2553 ret
.expr
= NULL_TREE
;
2554 ret
.expr_const_operands
= true;
2557 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2558 /* In ISO C, enumerated types can be referred to only if already
2560 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2563 pedwarn (enum_loc
, OPT_Wpedantic
,
2564 "ISO C forbids forward references to %<enum%> types");
2569 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2571 struct-or-union-specifier:
2572 struct-or-union attributes[opt] identifier[opt]
2573 { struct-contents } attributes[opt]
2574 struct-or-union attributes[opt] identifier
2577 struct-declaration-list
2579 struct-declaration-list:
2580 struct-declaration ;
2581 struct-declaration-list struct-declaration ;
2588 struct-declaration-list struct-declaration
2590 struct-declaration-list:
2591 struct-declaration-list ;
2594 (Note that in the syntax here, unlike that in ISO C, the semicolons
2595 are included here rather than in struct-declaration, in order to
2596 describe the syntax with extra semicolons and missing semicolon at
2601 struct-declaration-list:
2602 @defs ( class-name )
2604 (Note this does not include a trailing semicolon, but can be
2605 followed by further declarations, and gets a pedwarn-if-pedantic
2606 when followed by a semicolon.) */
2608 static struct c_typespec
2609 c_parser_struct_or_union_specifier (c_parser
*parser
)
2611 struct c_typespec ret
;
2613 tree ident
= NULL_TREE
;
2614 location_t struct_loc
;
2615 location_t ident_loc
= UNKNOWN_LOCATION
;
2616 enum tree_code code
;
2617 switch (c_parser_peek_token (parser
)->keyword
)
2628 struct_loc
= c_parser_peek_token (parser
)->location
;
2629 c_parser_consume_token (parser
);
2630 attrs
= c_parser_attributes (parser
);
2632 /* Set the location in case we create a decl now. */
2633 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2635 if (c_parser_next_token_is (parser
, CPP_NAME
))
2637 ident
= c_parser_peek_token (parser
)->value
;
2638 ident_loc
= c_parser_peek_token (parser
)->location
;
2639 struct_loc
= ident_loc
;
2640 c_parser_consume_token (parser
);
2642 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2644 /* Parse a struct or union definition. Start the scope of the
2645 tag before parsing components. */
2646 struct c_struct_parse_info
*struct_info
;
2647 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2649 /* We chain the components in reverse order, then put them in
2650 forward order at the end. Each struct-declaration may
2651 declare multiple components (comma-separated), so we must use
2652 chainon to join them, although when parsing each
2653 struct-declaration we can use TREE_CHAIN directly.
2655 The theory behind all this is that there will be more
2656 semicolon separated fields than comma separated fields, and
2657 so we'll be minimizing the number of node traversals required
2660 timevar_push (TV_PARSE_STRUCT
);
2661 contents
= NULL_TREE
;
2662 c_parser_consume_token (parser
);
2663 /* Handle the Objective-C @defs construct,
2664 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2665 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2668 gcc_assert (c_dialect_objc ());
2669 c_parser_consume_token (parser
);
2670 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2672 if (c_parser_next_token_is (parser
, CPP_NAME
)
2673 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2675 name
= c_parser_peek_token (parser
)->value
;
2676 c_parser_consume_token (parser
);
2680 c_parser_error (parser
, "expected class name");
2681 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2684 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2686 contents
= nreverse (objc_get_class_ivars (name
));
2689 /* Parse the struct-declarations and semicolons. Problems with
2690 semicolons are diagnosed here; empty structures are diagnosed
2695 /* Parse any stray semicolon. */
2696 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2698 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2699 "extra semicolon in struct or union specified");
2700 c_parser_consume_token (parser
);
2703 /* Stop if at the end of the struct or union contents. */
2704 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2706 c_parser_consume_token (parser
);
2709 /* Accept #pragmas at struct scope. */
2710 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2712 c_parser_pragma (parser
, pragma_struct
);
2715 /* Parse some comma-separated declarations, but not the
2716 trailing semicolon if any. */
2717 decls
= c_parser_struct_declaration (parser
);
2718 contents
= chainon (decls
, contents
);
2719 /* If no semicolon follows, either we have a parse error or
2720 are at the end of the struct or union and should
2722 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2723 c_parser_consume_token (parser
);
2726 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2727 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2728 "no semicolon at end of struct or union");
2729 else if (parser
->error
2730 || !c_parser_next_token_starts_declspecs (parser
))
2732 c_parser_error (parser
, "expected %<;%>");
2733 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2737 /* If we come here, we have already emitted an error
2738 for an expected `;', identifier or `(', and we also
2739 recovered already. Go on with the next field. */
2742 postfix_attrs
= c_parser_attributes (parser
);
2743 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2744 chainon (attrs
, postfix_attrs
), struct_info
);
2745 ret
.kind
= ctsk_tagdef
;
2746 ret
.expr
= NULL_TREE
;
2747 ret
.expr_const_operands
= true;
2748 timevar_pop (TV_PARSE_STRUCT
);
2753 c_parser_error (parser
, "expected %<{%>");
2754 ret
.spec
= error_mark_node
;
2755 ret
.kind
= ctsk_tagref
;
2756 ret
.expr
= NULL_TREE
;
2757 ret
.expr_const_operands
= true;
2760 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2764 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2765 the trailing semicolon.
2768 specifier-qualifier-list struct-declarator-list
2769 static_assert-declaration-no-semi
2771 specifier-qualifier-list:
2772 type-specifier specifier-qualifier-list[opt]
2773 type-qualifier specifier-qualifier-list[opt]
2774 attributes specifier-qualifier-list[opt]
2776 struct-declarator-list:
2778 struct-declarator-list , attributes[opt] struct-declarator
2781 declarator attributes[opt]
2782 declarator[opt] : constant-expression attributes[opt]
2787 __extension__ struct-declaration
2788 specifier-qualifier-list
2790 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2791 of attributes where shown is a GNU extension. In GNU C, we accept
2792 any expression without commas in the syntax (assignment
2793 expressions, not just conditional expressions); assignment
2794 expressions will be diagnosed as non-constant. */
2797 c_parser_struct_declaration (c_parser
*parser
)
2799 struct c_declspecs
*specs
;
2801 tree all_prefix_attrs
;
2803 location_t decl_loc
;
2804 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2808 ext
= disable_extension_diagnostics ();
2809 c_parser_consume_token (parser
);
2810 decl
= c_parser_struct_declaration (parser
);
2811 restore_extension_diagnostics (ext
);
2814 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2816 c_parser_static_assert_declaration_no_semi (parser
);
2819 specs
= build_null_declspecs ();
2820 decl_loc
= c_parser_peek_token (parser
)->location
;
2821 /* Strictly by the standard, we shouldn't allow _Alignas here,
2822 but it appears to have been intended to allow it there, so
2823 we're keeping it as it is until WG14 reaches a conclusion
2825 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2826 c_parser_declspecs (parser
, specs
, false, true, true,
2827 true, false, cla_nonabstract_decl
);
2830 if (!specs
->declspecs_seen_p
)
2832 c_parser_error (parser
, "expected specifier-qualifier-list");
2835 finish_declspecs (specs
);
2836 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2837 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2840 if (specs
->typespec_kind
== ctsk_none
)
2842 pedwarn (decl_loc
, OPT_Wpedantic
,
2843 "ISO C forbids member declarations with no members");
2844 shadow_tag_warned (specs
, pedantic
);
2849 /* Support for unnamed structs or unions as members of
2850 structs or unions (which is [a] useful and [b] supports
2854 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2855 build_id_declarator (NULL_TREE
), specs
,
2858 decl_attributes (&ret
, attrs
, 0);
2863 /* Provide better error recovery. Note that a type name here is valid,
2864 and will be treated as a field name. */
2865 if (specs
->typespec_kind
== ctsk_tagdef
2866 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2867 && c_parser_next_token_starts_declspecs (parser
)
2868 && !c_parser_next_token_is (parser
, CPP_NAME
))
2870 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2871 parser
->error
= false;
2875 pending_xref_error ();
2876 prefix_attrs
= specs
->attrs
;
2877 all_prefix_attrs
= prefix_attrs
;
2878 specs
->attrs
= NULL_TREE
;
2882 /* Declaring one or more declarators or un-named bit-fields. */
2883 struct c_declarator
*declarator
;
2885 if (c_parser_next_token_is (parser
, CPP_COLON
))
2886 declarator
= build_id_declarator (NULL_TREE
);
2888 declarator
= c_parser_declarator (parser
,
2889 specs
->typespec_kind
!= ctsk_none
,
2890 C_DTR_NORMAL
, &dummy
);
2891 if (declarator
== NULL
)
2893 c_parser_skip_to_end_of_block_or_statement (parser
);
2896 if (c_parser_next_token_is (parser
, CPP_COLON
)
2897 || c_parser_next_token_is (parser
, CPP_COMMA
)
2898 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2899 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2900 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2902 tree postfix_attrs
= NULL_TREE
;
2903 tree width
= NULL_TREE
;
2905 if (c_parser_next_token_is (parser
, CPP_COLON
))
2907 c_parser_consume_token (parser
);
2908 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2910 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2911 postfix_attrs
= c_parser_attributes (parser
);
2912 d
= grokfield (c_parser_peek_token (parser
)->location
,
2913 declarator
, specs
, width
, &all_prefix_attrs
);
2914 decl_attributes (&d
, chainon (postfix_attrs
,
2915 all_prefix_attrs
), 0);
2916 DECL_CHAIN (d
) = decls
;
2918 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2919 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2922 all_prefix_attrs
= prefix_attrs
;
2923 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2924 c_parser_consume_token (parser
);
2925 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2926 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2928 /* Semicolon consumed in caller. */
2933 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2939 c_parser_error (parser
,
2940 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2941 "%<__attribute__%>");
2948 /* Parse a typeof specifier (a GNU extension).
2951 typeof ( expression )
2952 typeof ( type-name )
2955 static struct c_typespec
2956 c_parser_typeof_specifier (c_parser
*parser
)
2958 struct c_typespec ret
;
2959 ret
.kind
= ctsk_typeof
;
2960 ret
.spec
= error_mark_node
;
2961 ret
.expr
= NULL_TREE
;
2962 ret
.expr_const_operands
= true;
2963 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2964 c_parser_consume_token (parser
);
2965 c_inhibit_evaluation_warnings
++;
2967 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2969 c_inhibit_evaluation_warnings
--;
2973 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2975 struct c_type_name
*type
= c_parser_type_name (parser
);
2976 c_inhibit_evaluation_warnings
--;
2980 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2981 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2987 location_t here
= c_parser_peek_token (parser
)->location
;
2988 struct c_expr expr
= c_parser_expression (parser
);
2989 c_inhibit_evaluation_warnings
--;
2991 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2992 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2993 error_at (here
, "%<typeof%> applied to a bit-field");
2994 mark_exp_read (expr
.value
);
2995 ret
.spec
= TREE_TYPE (expr
.value
);
2996 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2997 /* This is returned with the type so that when the type is
2998 evaluated, this can be evaluated. */
3000 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3001 pop_maybe_used (was_vm
);
3002 /* For use in macros such as those in <stdatomic.h>, remove
3003 _Atomic and const qualifiers from atomic types. (Possibly
3004 all qualifiers should be removed; const can be an issue for
3005 more macros using typeof than just the <stdatomic.h>
3007 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3008 ret
.spec
= c_build_qualified_type (ret
.spec
,
3009 (TYPE_QUALS (ret
.spec
)
3010 & ~(TYPE_QUAL_ATOMIC
3011 | TYPE_QUAL_CONST
)));
3013 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3017 /* Parse an alignment-specifier.
3021 alignment-specifier:
3022 _Alignas ( type-name )
3023 _Alignas ( constant-expression )
3027 c_parser_alignas_specifier (c_parser
* parser
)
3029 tree ret
= error_mark_node
;
3030 location_t loc
= c_parser_peek_token (parser
)->location
;
3031 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3032 c_parser_consume_token (parser
);
3036 pedwarn (loc
, OPT_Wpedantic
,
3037 "ISO C99 does not support %<_Alignas%>");
3039 pedwarn (loc
, OPT_Wpedantic
,
3040 "ISO C90 does not support %<_Alignas%>");
3042 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3044 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3046 struct c_type_name
*type
= c_parser_type_name (parser
);
3048 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3052 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3053 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3057 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3058 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3059 be redeclared; otherwise it may not. KIND indicates which kind of
3060 declarator is wanted. Returns a valid declarator except in the
3061 case of a syntax error in which case NULL is returned. *SEEN_ID is
3062 set to true if an identifier being declared is seen; this is used
3063 to diagnose bad forms of abstract array declarators and to
3064 determine whether an identifier list is syntactically permitted.
3067 pointer[opt] direct-declarator
3071 ( attributes[opt] declarator )
3072 direct-declarator array-declarator
3073 direct-declarator ( parameter-type-list )
3074 direct-declarator ( identifier-list[opt] )
3077 * type-qualifier-list[opt]
3078 * type-qualifier-list[opt] pointer
3080 type-qualifier-list:
3083 type-qualifier-list type-qualifier
3084 type-qualifier-list attributes
3087 [ type-qualifier-list[opt] assignment-expression[opt] ]
3088 [ static type-qualifier-list[opt] assignment-expression ]
3089 [ type-qualifier-list static assignment-expression ]
3090 [ type-qualifier-list[opt] * ]
3092 parameter-type-list:
3094 parameter-list , ...
3097 parameter-declaration
3098 parameter-list , parameter-declaration
3100 parameter-declaration:
3101 declaration-specifiers declarator attributes[opt]
3102 declaration-specifiers abstract-declarator[opt] attributes[opt]
3106 identifier-list , identifier
3108 abstract-declarator:
3110 pointer[opt] direct-abstract-declarator
3112 direct-abstract-declarator:
3113 ( attributes[opt] abstract-declarator )
3114 direct-abstract-declarator[opt] array-declarator
3115 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3120 direct-declarator ( parameter-forward-declarations
3121 parameter-type-list[opt] )
3123 direct-abstract-declarator:
3124 direct-abstract-declarator[opt] ( parameter-forward-declarations
3125 parameter-type-list[opt] )
3127 parameter-forward-declarations:
3129 parameter-forward-declarations parameter-list ;
3131 The uses of attributes shown above are GNU extensions.
3133 Some forms of array declarator are not included in C99 in the
3134 syntax for abstract declarators; these are disallowed elsewhere.
3135 This may be a defect (DR#289).
3137 This function also accepts an omitted abstract declarator as being
3138 an abstract declarator, although not part of the formal syntax. */
3140 static struct c_declarator
*
3141 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3144 /* Parse any initial pointer part. */
3145 if (c_parser_next_token_is (parser
, CPP_MULT
))
3147 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3148 struct c_declarator
*inner
;
3149 c_parser_consume_token (parser
);
3150 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3151 false, false, cla_prefer_id
);
3152 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3156 return make_pointer_declarator (quals_attrs
, inner
);
3158 /* Now we have a direct declarator, direct abstract declarator or
3159 nothing (which counts as a direct abstract declarator here). */
3160 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3163 /* Parse a direct declarator or direct abstract declarator; arguments
3164 as c_parser_declarator. */
3166 static struct c_declarator
*
3167 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3170 /* The direct declarator must start with an identifier (possibly
3171 omitted) or a parenthesized declarator (possibly abstract). In
3172 an ordinary declarator, initial parentheses must start a
3173 parenthesized declarator. In an abstract declarator or parameter
3174 declarator, they could start a parenthesized declarator or a
3175 parameter list. To tell which, the open parenthesis and any
3176 following attributes must be read. If a declaration specifier
3177 follows, then it is a parameter list; if the specifier is a
3178 typedef name, there might be an ambiguity about redeclaring it,
3179 which is resolved in the direction of treating it as a typedef
3180 name. If a close parenthesis follows, it is also an empty
3181 parameter list, as the syntax does not permit empty abstract
3182 declarators. Otherwise, it is a parenthesized declarator (in
3183 which case the analysis may be repeated inside it, recursively).
3185 ??? There is an ambiguity in a parameter declaration "int
3186 (__attribute__((foo)) x)", where x is not a typedef name: it
3187 could be an abstract declarator for a function, or declare x with
3188 parentheses. The proper resolution of this ambiguity needs
3189 documenting. At present we follow an accident of the old
3190 parser's implementation, whereby the first parameter must have
3191 some declaration specifiers other than just attributes. Thus as
3192 a parameter declaration it is treated as a parenthesized
3193 parameter named x, and as an abstract declarator it is
3196 ??? Also following the old parser, attributes inside an empty
3197 parameter list are ignored, making it a list not yielding a
3198 prototype, rather than giving an error or making it have one
3199 parameter with implicit type int.
3201 ??? Also following the old parser, typedef names may be
3202 redeclared in declarators, but not Objective-C class names. */
3204 if (kind
!= C_DTR_ABSTRACT
3205 && c_parser_next_token_is (parser
, CPP_NAME
)
3207 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3208 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3209 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3211 struct c_declarator
*inner
3212 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3214 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3215 c_parser_consume_token (parser
);
3216 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3219 if (kind
!= C_DTR_NORMAL
3220 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3222 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3223 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3226 /* Either we are at the end of an abstract declarator, or we have
3229 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3232 struct c_declarator
*inner
;
3233 c_parser_consume_token (parser
);
3234 attrs
= c_parser_attributes (parser
);
3235 if (kind
!= C_DTR_NORMAL
3236 && (c_parser_next_token_starts_declspecs (parser
)
3237 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3239 struct c_arg_info
*args
3240 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3247 = build_function_declarator (args
,
3248 build_id_declarator (NULL_TREE
));
3249 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3253 /* A parenthesized declarator. */
3254 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3255 if (inner
!= NULL
&& attrs
!= NULL
)
3256 inner
= build_attrs_declarator (attrs
, inner
);
3257 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3259 c_parser_consume_token (parser
);
3263 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3267 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3274 if (kind
== C_DTR_NORMAL
)
3276 c_parser_error (parser
, "expected identifier or %<(%>");
3280 return build_id_declarator (NULL_TREE
);
3284 /* Parse part of a direct declarator or direct abstract declarator,
3285 given that some (in INNER) has already been parsed; ID_PRESENT is
3286 true if an identifier is present, false for an abstract
3289 static struct c_declarator
*
3290 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3291 struct c_declarator
*inner
)
3293 /* Parse a sequence of array declarators and parameter lists. */
3294 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3296 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3297 struct c_declarator
*declarator
;
3298 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3301 struct c_expr dimen
;
3302 dimen
.value
= NULL_TREE
;
3303 dimen
.original_code
= ERROR_MARK
;
3304 dimen
.original_type
= NULL_TREE
;
3305 c_parser_consume_token (parser
);
3306 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3307 false, false, cla_prefer_id
);
3308 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3310 c_parser_consume_token (parser
);
3311 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3312 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3313 false, false, cla_prefer_id
);
3314 if (!quals_attrs
->declspecs_seen_p
)
3316 /* If "static" is present, there must be an array dimension.
3317 Otherwise, there may be a dimension, "*", or no
3322 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3326 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3328 dimen
.value
= NULL_TREE
;
3331 else if (flag_enable_cilkplus
3332 && c_parser_next_token_is (parser
, CPP_COLON
))
3334 dimen
.value
= error_mark_node
;
3336 error_at (c_parser_peek_token (parser
)->location
,
3337 "array notations cannot be used in declaration");
3338 c_parser_consume_token (parser
);
3340 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3342 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3344 dimen
.value
= NULL_TREE
;
3346 c_parser_consume_token (parser
);
3351 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3357 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3360 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3361 c_parser_consume_token (parser
);
3362 else if (flag_enable_cilkplus
3363 && c_parser_next_token_is (parser
, CPP_COLON
))
3365 error_at (c_parser_peek_token (parser
)->location
,
3366 "array notations cannot be used in declaration");
3367 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3372 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3377 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3378 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3379 static_seen
, star_seen
);
3380 if (declarator
== NULL
)
3382 inner
= set_array_declarator_inner (declarator
, inner
);
3383 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3385 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3388 struct c_arg_info
*args
;
3389 c_parser_consume_token (parser
);
3390 attrs
= c_parser_attributes (parser
);
3391 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3396 inner
= build_function_declarator (args
, inner
);
3397 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3403 /* Parse a parameter list or identifier list, including the closing
3404 parenthesis but not the opening one. ATTRS are the attributes at
3405 the start of the list. ID_LIST_OK is true if an identifier list is
3406 acceptable; such a list must not have attributes at the start. */
3408 static struct c_arg_info
*
3409 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3412 declare_parm_level ();
3413 /* If the list starts with an identifier, it is an identifier list.
3414 Otherwise, it is either a prototype list or an empty list. */
3417 && c_parser_next_token_is (parser
, CPP_NAME
)
3418 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3420 /* Look ahead to detect typos in type names. */
3421 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3422 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3423 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3424 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3426 tree list
= NULL_TREE
, *nextp
= &list
;
3427 while (c_parser_next_token_is (parser
, CPP_NAME
)
3428 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3430 *nextp
= build_tree_list (NULL_TREE
,
3431 c_parser_peek_token (parser
)->value
);
3432 nextp
= & TREE_CHAIN (*nextp
);
3433 c_parser_consume_token (parser
);
3434 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3436 c_parser_consume_token (parser
);
3437 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3439 c_parser_error (parser
, "expected identifier");
3443 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3445 struct c_arg_info
*ret
= build_arg_info ();
3447 c_parser_consume_token (parser
);
3453 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3461 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3468 /* Parse a parameter list (possibly empty), including the closing
3469 parenthesis but not the opening one. ATTRS are the attributes at
3470 the start of the list. EXPR is NULL or an expression that needs to
3471 be evaluated for the side effects of array size expressions in the
3474 static struct c_arg_info
*
3475 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3477 bool bad_parm
= false;
3479 /* ??? Following the old parser, forward parameter declarations may
3480 use abstract declarators, and if no real parameter declarations
3481 follow the forward declarations then this is not diagnosed. Also
3482 note as above that attributes are ignored as the only contents of
3483 the parentheses, or as the only contents after forward
3485 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3487 struct c_arg_info
*ret
= build_arg_info ();
3488 c_parser_consume_token (parser
);
3491 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3493 struct c_arg_info
*ret
= build_arg_info ();
3495 if (flag_allow_parameterless_variadic_functions
)
3497 /* F (...) is allowed. */
3498 ret
->types
= NULL_TREE
;
3502 /* Suppress -Wold-style-definition for this case. */
3503 ret
->types
= error_mark_node
;
3504 error_at (c_parser_peek_token (parser
)->location
,
3505 "ISO C requires a named argument before %<...%>");
3507 c_parser_consume_token (parser
);
3508 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3510 c_parser_consume_token (parser
);
3515 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3520 /* Nonempty list of parameters, either terminated with semicolon
3521 (forward declarations; recurse) or with close parenthesis (normal
3522 function) or with ", ... )" (variadic function). */
3525 /* Parse a parameter. */
3526 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3531 push_parm_decl (parm
, &expr
);
3532 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3535 c_parser_consume_token (parser
);
3536 mark_forward_parm_decls ();
3537 new_attrs
= c_parser_attributes (parser
);
3538 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3540 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3542 c_parser_consume_token (parser
);
3546 return get_parm_info (false, expr
);
3548 if (!c_parser_require (parser
, CPP_COMMA
,
3549 "expected %<;%>, %<,%> or %<)%>"))
3551 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3554 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3556 c_parser_consume_token (parser
);
3557 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3559 c_parser_consume_token (parser
);
3563 return get_parm_info (true, expr
);
3567 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3575 /* Parse a parameter declaration. ATTRS are the attributes at the
3576 start of the declaration if it is the first parameter. */
3578 static struct c_parm
*
3579 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3581 struct c_declspecs
*specs
;
3582 struct c_declarator
*declarator
;
3584 tree postfix_attrs
= NULL_TREE
;
3587 /* Accept #pragmas between parameter declarations. */
3588 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3589 c_parser_pragma (parser
, pragma_param
);
3591 if (!c_parser_next_token_starts_declspecs (parser
))
3593 c_token
*token
= c_parser_peek_token (parser
);
3596 c_parser_set_source_position_from_token (token
);
3597 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3599 error ("unknown type name %qE", token
->value
);
3600 parser
->error
= true;
3602 /* ??? In some Objective-C cases '...' isn't applicable so there
3603 should be a different message. */
3605 c_parser_error (parser
,
3606 "expected declaration specifiers or %<...%>");
3607 c_parser_skip_to_end_of_parameter (parser
);
3610 specs
= build_null_declspecs ();
3613 declspecs_add_attrs (input_location
, specs
, attrs
);
3616 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3617 cla_nonabstract_decl
);
3618 finish_declspecs (specs
);
3619 pending_xref_error ();
3620 prefix_attrs
= specs
->attrs
;
3621 specs
->attrs
= NULL_TREE
;
3622 declarator
= c_parser_declarator (parser
,
3623 specs
->typespec_kind
!= ctsk_none
,
3624 C_DTR_PARM
, &dummy
);
3625 if (declarator
== NULL
)
3627 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3630 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3631 postfix_attrs
= c_parser_attributes (parser
);
3632 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3636 /* Parse a string literal in an asm expression. It should not be
3637 translated, and wide string literals are an error although
3638 permitted by the syntax. This is a GNU extension.
3643 ??? At present, following the old parser, the caller needs to have
3644 set lex_untranslated_string to 1. It would be better to follow the
3645 C++ parser rather than using this kludge. */
3648 c_parser_asm_string_literal (c_parser
*parser
)
3651 int save_flag
= warn_overlength_strings
;
3652 warn_overlength_strings
= 0;
3653 if (c_parser_next_token_is (parser
, CPP_STRING
))
3655 str
= c_parser_peek_token (parser
)->value
;
3656 c_parser_consume_token (parser
);
3658 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3660 error_at (c_parser_peek_token (parser
)->location
,
3661 "wide string literal in %<asm%>");
3662 str
= build_string (1, "");
3663 c_parser_consume_token (parser
);
3667 c_parser_error (parser
, "expected string literal");
3670 warn_overlength_strings
= save_flag
;
3674 /* Parse a simple asm expression. This is used in restricted
3675 contexts, where a full expression with inputs and outputs does not
3676 make sense. This is a GNU extension.
3679 asm ( asm-string-literal )
3683 c_parser_simple_asm_expr (c_parser
*parser
)
3686 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3687 /* ??? Follow the C++ parser rather than using the
3688 lex_untranslated_string kludge. */
3689 parser
->lex_untranslated_string
= true;
3690 c_parser_consume_token (parser
);
3691 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3693 parser
->lex_untranslated_string
= false;
3696 str
= c_parser_asm_string_literal (parser
);
3697 parser
->lex_untranslated_string
= false;
3698 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3700 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3707 c_parser_attribute_any_word (c_parser
*parser
)
3709 tree attr_name
= NULL_TREE
;
3711 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3713 /* ??? See comment above about what keywords are accepted here. */
3715 switch (c_parser_peek_token (parser
)->keyword
)
3746 case RID_TRANSACTION_ATOMIC
:
3747 case RID_TRANSACTION_CANCEL
:
3759 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3760 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3762 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3763 attr_name
= c_parser_peek_token (parser
)->value
;
3768 /* Parse (possibly empty) attributes. This is a GNU extension.
3772 attributes attribute
3775 __attribute__ ( ( attribute-list ) )
3779 attribute_list , attrib
3784 any-word ( identifier )
3785 any-word ( identifier , nonempty-expr-list )
3786 any-word ( expr-list )
3788 where the "identifier" must not be declared as a type, and
3789 "any-word" may be any identifier (including one declared as a
3790 type), a reserved word storage class specifier, type specifier or
3791 type qualifier. ??? This still leaves out most reserved keywords
3792 (following the old parser), shouldn't we include them, and why not
3793 allow identifiers declared as types to start the arguments? */
3796 c_parser_attributes (c_parser
*parser
)
3798 tree attrs
= NULL_TREE
;
3799 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3801 /* ??? Follow the C++ parser rather than using the
3802 lex_untranslated_string kludge. */
3803 parser
->lex_untranslated_string
= true;
3804 c_parser_consume_token (parser
);
3805 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3807 parser
->lex_untranslated_string
= false;
3810 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3812 parser
->lex_untranslated_string
= false;
3813 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3816 /* Parse the attribute list. */
3817 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3818 || c_parser_next_token_is (parser
, CPP_NAME
)
3819 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3821 tree attr
, attr_name
, attr_args
;
3822 vec
<tree
, va_gc
> *expr_list
;
3823 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3825 c_parser_consume_token (parser
);
3829 attr_name
= c_parser_attribute_any_word (parser
);
3830 if (attr_name
== NULL
)
3832 c_parser_consume_token (parser
);
3833 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3835 attr
= build_tree_list (attr_name
, NULL_TREE
);
3836 attrs
= chainon (attrs
, attr
);
3839 c_parser_consume_token (parser
);
3840 /* Parse the attribute contents. If they start with an
3841 identifier which is followed by a comma or close
3842 parenthesis, then the arguments start with that
3843 identifier; otherwise they are an expression list.
3844 In objective-c the identifier may be a classname. */
3845 if (c_parser_next_token_is (parser
, CPP_NAME
)
3846 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3847 || (c_dialect_objc ()
3848 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3849 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3850 || (c_parser_peek_2nd_token (parser
)->type
3851 == CPP_CLOSE_PAREN
)))
3853 tree arg1
= c_parser_peek_token (parser
)->value
;
3854 c_parser_consume_token (parser
);
3855 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3856 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3860 c_parser_consume_token (parser
);
3861 expr_list
= c_parser_expr_list (parser
, false, true,
3863 tree_list
= build_tree_list_vec (expr_list
);
3864 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3865 release_tree_vector (expr_list
);
3870 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3871 attr_args
= NULL_TREE
;
3874 expr_list
= c_parser_expr_list (parser
, false, true,
3876 attr_args
= build_tree_list_vec (expr_list
);
3877 release_tree_vector (expr_list
);
3880 attr
= build_tree_list (attr_name
, attr_args
);
3881 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3882 c_parser_consume_token (parser
);
3885 parser
->lex_untranslated_string
= false;
3886 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3890 attrs
= chainon (attrs
, attr
);
3892 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3893 c_parser_consume_token (parser
);
3896 parser
->lex_untranslated_string
= false;
3897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3901 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3902 c_parser_consume_token (parser
);
3905 parser
->lex_untranslated_string
= false;
3906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3910 parser
->lex_untranslated_string
= false;
3915 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3918 specifier-qualifier-list abstract-declarator[opt]
3921 static struct c_type_name
*
3922 c_parser_type_name (c_parser
*parser
)
3924 struct c_declspecs
*specs
= build_null_declspecs ();
3925 struct c_declarator
*declarator
;
3926 struct c_type_name
*ret
;
3928 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
3930 if (!specs
->declspecs_seen_p
)
3932 c_parser_error (parser
, "expected specifier-qualifier-list");
3935 if (specs
->type
!= error_mark_node
)
3937 pending_xref_error ();
3938 finish_declspecs (specs
);
3940 declarator
= c_parser_declarator (parser
,
3941 specs
->typespec_kind
!= ctsk_none
,
3942 C_DTR_ABSTRACT
, &dummy
);
3943 if (declarator
== NULL
)
3945 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3947 ret
->declarator
= declarator
;
3951 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3954 assignment-expression
3955 { initializer-list }
3956 { initializer-list , }
3959 designation[opt] initializer
3960 initializer-list , designation[opt] initializer
3967 designator-list designator
3974 [ constant-expression ]
3986 [ constant-expression ... constant-expression ]
3988 Any expression without commas is accepted in the syntax for the
3989 constant-expressions, with non-constant expressions rejected later.
3991 This function is only used for top-level initializers; for nested
3992 ones, see c_parser_initval. */
3994 static struct c_expr
3995 c_parser_initializer (c_parser
*parser
)
3997 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3998 return c_parser_braced_init (parser
, NULL_TREE
, false);
4002 location_t loc
= c_parser_peek_token (parser
)->location
;
4003 ret
= c_parser_expr_no_commas (parser
, NULL
);
4004 if (TREE_CODE (ret
.value
) != STRING_CST
4005 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4006 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4011 /* Parse a braced initializer list. TYPE is the type specified for a
4012 compound literal, and NULL_TREE for other initializers and for
4013 nested braced lists. NESTED_P is true for nested braced lists,
4014 false for the list of a compound literal or the list that is the
4015 top-level initializer in a declaration. */
4017 static struct c_expr
4018 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4021 struct obstack braced_init_obstack
;
4022 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4023 gcc_obstack_init (&braced_init_obstack
);
4024 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4025 c_parser_consume_token (parser
);
4027 push_init_level (0, &braced_init_obstack
);
4029 really_start_incremental_init (type
);
4030 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4032 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4036 /* Parse a non-empty initializer list, possibly with a trailing
4040 c_parser_initelt (parser
, &braced_init_obstack
);
4043 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4044 c_parser_consume_token (parser
);
4047 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4051 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4053 ret
.value
= error_mark_node
;
4054 ret
.original_code
= ERROR_MARK
;
4055 ret
.original_type
= NULL
;
4056 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4057 pop_init_level (0, &braced_init_obstack
);
4058 obstack_free (&braced_init_obstack
, NULL
);
4061 c_parser_consume_token (parser
);
4062 ret
= pop_init_level (0, &braced_init_obstack
);
4063 obstack_free (&braced_init_obstack
, NULL
);
4067 /* Parse a nested initializer, including designators. */
4070 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4072 /* Parse any designator or designator list. A single array
4073 designator may have the subsequent "=" omitted in GNU C, but a
4074 longer list or a structure member designator may not. */
4075 if (c_parser_next_token_is (parser
, CPP_NAME
)
4076 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4078 /* Old-style structure member designator. */
4079 set_init_label (c_parser_peek_token (parser
)->value
,
4080 braced_init_obstack
);
4081 /* Use the colon as the error location. */
4082 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4083 "obsolete use of designated initializer with %<:%>");
4084 c_parser_consume_token (parser
);
4085 c_parser_consume_token (parser
);
4089 /* des_seen is 0 if there have been no designators, 1 if there
4090 has been a single array designator and 2 otherwise. */
4092 /* Location of a designator. */
4093 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4094 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4095 || c_parser_next_token_is (parser
, CPP_DOT
))
4097 int des_prev
= des_seen
;
4099 des_loc
= c_parser_peek_token (parser
)->location
;
4102 if (c_parser_next_token_is (parser
, CPP_DOT
))
4105 c_parser_consume_token (parser
);
4106 if (c_parser_next_token_is (parser
, CPP_NAME
))
4108 set_init_label (c_parser_peek_token (parser
)->value
,
4109 braced_init_obstack
);
4110 c_parser_consume_token (parser
);
4115 init
.value
= error_mark_node
;
4116 init
.original_code
= ERROR_MARK
;
4117 init
.original_type
= NULL
;
4118 c_parser_error (parser
, "expected identifier");
4119 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4120 process_init_element (init
, false, braced_init_obstack
);
4127 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4128 /* ??? Following the old parser, [ objc-receiver
4129 objc-message-args ] is accepted as an initializer,
4130 being distinguished from a designator by what follows
4131 the first assignment expression inside the square
4132 brackets, but after a first array designator a
4133 subsequent square bracket is for Objective-C taken to
4134 start an expression, using the obsolete form of
4135 designated initializer without '=', rather than
4136 possibly being a second level of designation: in LALR
4137 terms, the '[' is shifted rather than reducing
4138 designator to designator-list. */
4139 if (des_prev
== 1 && c_dialect_objc ())
4141 des_seen
= des_prev
;
4144 if (des_prev
== 0 && c_dialect_objc ())
4146 /* This might be an array designator or an
4147 Objective-C message expression. If the former,
4148 continue parsing here; if the latter, parse the
4149 remainder of the initializer given the starting
4150 primary-expression. ??? It might make sense to
4151 distinguish when des_prev == 1 as well; see
4152 previous comment. */
4154 struct c_expr mexpr
;
4155 c_parser_consume_token (parser
);
4156 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4157 && ((c_parser_peek_token (parser
)->id_kind
4159 || (c_parser_peek_token (parser
)->id_kind
4160 == C_ID_CLASSNAME
)))
4162 /* Type name receiver. */
4163 tree id
= c_parser_peek_token (parser
)->value
;
4164 c_parser_consume_token (parser
);
4165 rec
= objc_get_class_reference (id
);
4166 goto parse_message_args
;
4168 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4169 mark_exp_read (first
);
4170 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4171 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4172 goto array_desig_after_first
;
4173 /* Expression receiver. So far only one part
4174 without commas has been parsed; there might be
4175 more of the expression. */
4177 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4180 location_t comma_loc
, exp_loc
;
4181 comma_loc
= c_parser_peek_token (parser
)->location
;
4182 c_parser_consume_token (parser
);
4183 exp_loc
= c_parser_peek_token (parser
)->location
;
4184 next
= c_parser_expr_no_commas (parser
, NULL
);
4185 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4187 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4190 /* Now parse the objc-message-args. */
4191 args
= c_parser_objc_message_args (parser
);
4192 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4195 = objc_build_message_expr (rec
, args
);
4196 mexpr
.original_code
= ERROR_MARK
;
4197 mexpr
.original_type
= NULL
;
4198 /* Now parse and process the remainder of the
4199 initializer, starting with this message
4200 expression as a primary-expression. */
4201 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4204 c_parser_consume_token (parser
);
4205 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4206 mark_exp_read (first
);
4207 array_desig_after_first
:
4208 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4210 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4211 c_parser_consume_token (parser
);
4212 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4213 mark_exp_read (second
);
4217 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4219 c_parser_consume_token (parser
);
4220 set_init_index (first
, second
, braced_init_obstack
);
4222 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4223 "ISO C forbids specifying range of elements to initialize");
4226 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4232 if (c_parser_next_token_is (parser
, CPP_EQ
))
4235 pedwarn (des_loc
, OPT_Wpedantic
,
4236 "ISO C90 forbids specifying subobject to initialize");
4237 c_parser_consume_token (parser
);
4242 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4243 "obsolete use of designated initializer without %<=%>");
4247 init
.value
= error_mark_node
;
4248 init
.original_code
= ERROR_MARK
;
4249 init
.original_type
= NULL
;
4250 c_parser_error (parser
, "expected %<=%>");
4251 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4252 process_init_element (init
, false, braced_init_obstack
);
4258 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4261 /* Parse a nested initializer; as c_parser_initializer but parses
4262 initializers within braced lists, after any designators have been
4263 applied. If AFTER is not NULL then it is an Objective-C message
4264 expression which is the primary-expression starting the
4268 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4269 struct obstack
* braced_init_obstack
)
4272 gcc_assert (!after
|| c_dialect_objc ());
4273 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4274 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4277 location_t loc
= c_parser_peek_token (parser
)->location
;
4278 init
= c_parser_expr_no_commas (parser
, after
);
4279 if (init
.value
!= NULL_TREE
4280 && TREE_CODE (init
.value
) != STRING_CST
4281 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4282 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4284 process_init_element (init
, false, braced_init_obstack
);
4287 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4291 { block-item-list[opt] }
4292 { label-declarations block-item-list }
4296 block-item-list block-item
4308 { label-declarations block-item-list }
4311 __extension__ nested-declaration
4312 nested-function-definition
4316 label-declarations label-declaration
4319 __label__ identifier-list ;
4321 Allowing the mixing of declarations and code is new in C99. The
4322 GNU syntax also permits (not shown above) labels at the end of
4323 compound statements, which yield an error. We don't allow labels
4324 on declarations; this might seem like a natural extension, but
4325 there would be a conflict between attributes on the label and
4326 prefix attributes on the declaration. ??? The syntax follows the
4327 old parser in requiring something after label declarations.
4328 Although they are erroneous if the labels declared aren't defined,
4329 is it useful for the syntax to be this way?
4342 cancellation-point-directive */
4345 c_parser_compound_statement (c_parser
*parser
)
4348 location_t brace_loc
;
4349 brace_loc
= c_parser_peek_token (parser
)->location
;
4350 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4352 /* Ensure a scope is entered and left anyway to avoid confusion
4353 if we have just prepared to enter a function body. */
4354 stmt
= c_begin_compound_stmt (true);
4355 c_end_compound_stmt (brace_loc
, stmt
, true);
4356 return error_mark_node
;
4358 stmt
= c_begin_compound_stmt (true);
4359 c_parser_compound_statement_nostart (parser
);
4361 /* If the compound stmt contains array notations, then we expand them. */
4362 if (flag_enable_cilkplus
&& contains_array_notation_expr (stmt
))
4363 stmt
= expand_array_notation_exprs (stmt
);
4364 return c_end_compound_stmt (brace_loc
, stmt
, true);
4367 /* Parse a compound statement except for the opening brace. This is
4368 used for parsing both compound statements and statement expressions
4369 (which follow different paths to handling the opening). */
4372 c_parser_compound_statement_nostart (c_parser
*parser
)
4374 bool last_stmt
= false;
4375 bool last_label
= false;
4376 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4377 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4378 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4380 c_parser_consume_token (parser
);
4383 mark_valid_location_for_stdc_pragma (true);
4384 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4386 /* Read zero or more forward-declarations for labels that nested
4387 functions can jump to. */
4388 mark_valid_location_for_stdc_pragma (false);
4389 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4391 label_loc
= c_parser_peek_token (parser
)->location
;
4392 c_parser_consume_token (parser
);
4393 /* Any identifiers, including those declared as type names,
4398 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4400 c_parser_error (parser
, "expected identifier");
4404 = declare_label (c_parser_peek_token (parser
)->value
);
4405 C_DECLARED_LABEL_FLAG (label
) = 1;
4406 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4407 c_parser_consume_token (parser
);
4408 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4409 c_parser_consume_token (parser
);
4413 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4415 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4417 /* We must now have at least one statement, label or declaration. */
4418 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4420 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4421 c_parser_error (parser
, "expected declaration or statement");
4422 c_parser_consume_token (parser
);
4425 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4427 location_t loc
= c_parser_peek_token (parser
)->location
;
4428 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4429 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4430 || (c_parser_next_token_is (parser
, CPP_NAME
)
4431 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4433 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4434 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4436 label_loc
= c_parser_peek_token (parser
)->location
;
4439 mark_valid_location_for_stdc_pragma (false);
4440 c_parser_label (parser
);
4442 else if (!last_label
4443 && c_parser_next_tokens_start_declaration (parser
))
4446 mark_valid_location_for_stdc_pragma (false);
4447 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4451 (pedantic
&& !flag_isoc99
)
4453 : OPT_Wdeclaration_after_statement
,
4454 "ISO C90 forbids mixed declarations and code");
4457 else if (!last_label
4458 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4460 /* __extension__ can start a declaration, but is also an
4461 unary operator that can start an expression. Consume all
4462 but the last of a possible series of __extension__ to
4464 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4465 && (c_parser_peek_2nd_token (parser
)->keyword
4467 c_parser_consume_token (parser
);
4468 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4471 ext
= disable_extension_diagnostics ();
4472 c_parser_consume_token (parser
);
4474 mark_valid_location_for_stdc_pragma (false);
4475 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4477 /* Following the old parser, __extension__ does not
4478 disable this diagnostic. */
4479 restore_extension_diagnostics (ext
);
4481 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4483 : OPT_Wdeclaration_after_statement
,
4484 "ISO C90 forbids mixed declarations and code");
4490 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4492 /* External pragmas, and some omp pragmas, are not associated
4493 with regular c code, and so are not to be considered statements
4494 syntactically. This ensures that the user doesn't put them
4495 places that would turn into syntax errors if the directive
4497 if (c_parser_pragma (parser
, pragma_compound
))
4498 last_label
= false, last_stmt
= true;
4500 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4502 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4503 c_parser_error (parser
, "expected declaration or statement");
4506 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4508 if (parser
->in_if_block
)
4510 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4511 error_at (loc
, """expected %<}%> before %<else%>");
4516 error_at (loc
, "%<else%> without a previous %<if%>");
4517 c_parser_consume_token (parser
);
4526 mark_valid_location_for_stdc_pragma (false);
4527 c_parser_statement_after_labels (parser
);
4530 parser
->error
= false;
4533 error_at (label_loc
, "label at end of compound statement");
4534 c_parser_consume_token (parser
);
4535 /* Restore the value we started with. */
4536 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4539 /* Parse a label (C90 6.6.1, C99 6.8.1).
4542 identifier : attributes[opt]
4543 case constant-expression :
4549 case constant-expression ... constant-expression :
4551 The use of attributes on labels is a GNU extension. The syntax in
4552 GNU C accepts any expressions without commas, non-constant
4553 expressions being rejected later. */
4556 c_parser_label (c_parser
*parser
)
4558 location_t loc1
= c_parser_peek_token (parser
)->location
;
4559 tree label
= NULL_TREE
;
4560 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4563 c_parser_consume_token (parser
);
4564 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4565 if (c_parser_next_token_is (parser
, CPP_COLON
))
4567 c_parser_consume_token (parser
);
4568 label
= do_case (loc1
, exp1
, NULL_TREE
);
4570 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4572 c_parser_consume_token (parser
);
4573 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4574 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4575 label
= do_case (loc1
, exp1
, exp2
);
4578 c_parser_error (parser
, "expected %<:%> or %<...%>");
4580 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4582 c_parser_consume_token (parser
);
4583 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4584 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4588 tree name
= c_parser_peek_token (parser
)->value
;
4591 location_t loc2
= c_parser_peek_token (parser
)->location
;
4592 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4593 c_parser_consume_token (parser
);
4594 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4595 c_parser_consume_token (parser
);
4596 attrs
= c_parser_attributes (parser
);
4597 tlab
= define_label (loc2
, name
);
4600 decl_attributes (&tlab
, attrs
, 0);
4601 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4606 if (c_parser_next_tokens_start_declaration (parser
))
4608 error_at (c_parser_peek_token (parser
)->location
,
4609 "a label can only be part of a statement and "
4610 "a declaration is not a statement");
4611 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4612 /*static_assert_ok*/ true,
4613 /*empty_ok*/ true, /*nested*/ true,
4614 /*start_attr_ok*/ true, NULL
,
4620 /* Parse a statement (C90 6.6, C99 6.8).
4625 expression-statement
4633 expression-statement:
4636 selection-statement:
4640 iteration-statement:
4649 return expression[opt] ;
4662 objc-throw-statement
4663 objc-try-catch-statement
4664 objc-synchronized-statement
4666 objc-throw-statement:
4682 parallel-for-construct
4683 parallel-for-simd-construct
4684 parallel-sections-construct
4691 parallel-directive structured-block
4694 for-directive iteration-statement
4697 simd-directive iteration-statements
4700 for-simd-directive iteration-statements
4703 sections-directive section-scope
4706 single-directive structured-block
4708 parallel-for-construct:
4709 parallel-for-directive iteration-statement
4711 parallel-for-simd-construct:
4712 parallel-for-simd-directive iteration-statement
4714 parallel-sections-construct:
4715 parallel-sections-directive section-scope
4718 master-directive structured-block
4721 critical-directive structured-block
4724 atomic-directive expression-statement
4727 ordered-directive structured-block
4729 Transactional Memory:
4732 transaction-statement
4733 transaction-cancel-statement
4737 c_parser_statement (c_parser
*parser
)
4739 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4740 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4741 || (c_parser_next_token_is (parser
, CPP_NAME
)
4742 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4743 c_parser_label (parser
);
4744 c_parser_statement_after_labels (parser
);
4747 /* Parse a statement, other than a labeled statement. */
4750 c_parser_statement_after_labels (c_parser
*parser
)
4752 location_t loc
= c_parser_peek_token (parser
)->location
;
4753 tree stmt
= NULL_TREE
;
4754 bool in_if_block
= parser
->in_if_block
;
4755 parser
->in_if_block
= false;
4756 switch (c_parser_peek_token (parser
)->type
)
4758 case CPP_OPEN_BRACE
:
4759 add_stmt (c_parser_compound_statement (parser
));
4762 switch (c_parser_peek_token (parser
)->keyword
)
4765 c_parser_if_statement (parser
);
4768 c_parser_switch_statement (parser
);
4771 c_parser_while_statement (parser
, false);
4774 c_parser_do_statement (parser
, false);
4777 c_parser_for_statement (parser
, false);
4780 c_parser_consume_token (parser
);
4781 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4782 if (!flag_enable_cilkplus
)
4783 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4785 add_stmt (build_cilk_sync ());
4788 c_parser_consume_token (parser
);
4789 if (c_parser_next_token_is (parser
, CPP_NAME
))
4791 stmt
= c_finish_goto_label (loc
,
4792 c_parser_peek_token (parser
)->value
);
4793 c_parser_consume_token (parser
);
4795 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4799 c_parser_consume_token (parser
);
4800 val
= c_parser_expression (parser
);
4801 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4802 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4805 c_parser_error (parser
, "expected identifier or %<*%>");
4806 goto expect_semicolon
;
4808 c_parser_consume_token (parser
);
4809 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4810 goto expect_semicolon
;
4812 c_parser_consume_token (parser
);
4813 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4814 goto expect_semicolon
;
4816 c_parser_consume_token (parser
);
4817 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4819 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4820 c_parser_consume_token (parser
);
4824 struct c_expr expr
= c_parser_expression_conv (parser
);
4825 mark_exp_read (expr
.value
);
4826 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4827 goto expect_semicolon
;
4831 stmt
= c_parser_asm_statement (parser
);
4833 case RID_TRANSACTION_ATOMIC
:
4834 case RID_TRANSACTION_RELAXED
:
4835 stmt
= c_parser_transaction (parser
,
4836 c_parser_peek_token (parser
)->keyword
);
4838 case RID_TRANSACTION_CANCEL
:
4839 stmt
= c_parser_transaction_cancel (parser
);
4840 goto expect_semicolon
;
4842 gcc_assert (c_dialect_objc ());
4843 c_parser_consume_token (parser
);
4844 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4846 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4847 c_parser_consume_token (parser
);
4851 struct c_expr expr
= c_parser_expression (parser
);
4852 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
4853 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4854 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
4855 goto expect_semicolon
;
4859 gcc_assert (c_dialect_objc ());
4860 c_parser_objc_try_catch_finally_statement (parser
);
4862 case RID_AT_SYNCHRONIZED
:
4863 gcc_assert (c_dialect_objc ());
4864 c_parser_objc_synchronized_statement (parser
);
4871 c_parser_consume_token (parser
);
4873 case CPP_CLOSE_PAREN
:
4874 case CPP_CLOSE_SQUARE
:
4875 /* Avoid infinite loop in error recovery:
4876 c_parser_skip_until_found stops at a closing nesting
4877 delimiter without consuming it, but here we need to consume
4878 it to proceed further. */
4879 c_parser_error (parser
, "expected statement");
4880 c_parser_consume_token (parser
);
4883 c_parser_pragma (parser
, pragma_stmt
);
4887 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4889 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4892 /* Two cases cannot and do not have line numbers associated: If stmt
4893 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4894 cannot hold line numbers. But that's OK because the statement
4895 will either be changed to a MODIFY_EXPR during gimplification of
4896 the statement expr, or discarded. If stmt was compound, but
4897 without new variables, we will have skipped the creation of a
4898 BIND and will have a bare STATEMENT_LIST. But that's OK because
4899 (recursively) all of the component statements should already have
4900 line numbers assigned. ??? Can we discard no-op statements
4902 if (CAN_HAVE_LOCATION_P (stmt
)
4903 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4904 SET_EXPR_LOCATION (stmt
, loc
);
4906 parser
->in_if_block
= in_if_block
;
4909 /* Parse the condition from an if, do, while or for statements. */
4912 c_parser_condition (c_parser
*parser
)
4914 location_t loc
= c_parser_peek_token (parser
)->location
;
4916 cond
= c_parser_expression_conv (parser
).value
;
4917 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4918 cond
= c_fully_fold (cond
, false, NULL
);
4919 if (warn_sequence_point
)
4920 verify_sequence_points (cond
);
4924 /* Parse a parenthesized condition from an if, do or while statement.
4930 c_parser_paren_condition (c_parser
*parser
)
4933 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4934 return error_mark_node
;
4935 cond
= c_parser_condition (parser
);
4936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4940 /* Parse a statement which is a block in C99. */
4943 c_parser_c99_block_statement (c_parser
*parser
)
4945 tree block
= c_begin_compound_stmt (flag_isoc99
);
4946 location_t loc
= c_parser_peek_token (parser
)->location
;
4947 c_parser_statement (parser
);
4948 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4951 /* Parse the body of an if statement. This is just parsing a
4952 statement but (a) it is a block in C99, (b) we track whether the
4953 body is an if statement for the sake of -Wparentheses warnings, (c)
4954 we handle an empty body specially for the sake of -Wempty-body
4955 warnings, and (d) we call parser_compound_statement directly
4956 because c_parser_statement_after_labels resets
4957 parser->in_if_block. */
4960 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4962 tree block
= c_begin_compound_stmt (flag_isoc99
);
4963 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4964 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4965 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4966 || (c_parser_next_token_is (parser
, CPP_NAME
)
4967 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4968 c_parser_label (parser
);
4969 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4970 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4972 location_t loc
= c_parser_peek_token (parser
)->location
;
4973 add_stmt (build_empty_stmt (loc
));
4974 c_parser_consume_token (parser
);
4975 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4976 warning_at (loc
, OPT_Wempty_body
,
4977 "suggest braces around empty body in an %<if%> statement");
4979 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4980 add_stmt (c_parser_compound_statement (parser
));
4982 c_parser_statement_after_labels (parser
);
4983 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4986 /* Parse the else body of an if statement. This is just parsing a
4987 statement but (a) it is a block in C99, (b) we handle an empty body
4988 specially for the sake of -Wempty-body warnings. */
4991 c_parser_else_body (c_parser
*parser
)
4993 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4994 tree block
= c_begin_compound_stmt (flag_isoc99
);
4995 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4996 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4997 || (c_parser_next_token_is (parser
, CPP_NAME
)
4998 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4999 c_parser_label (parser
);
5000 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5002 location_t loc
= c_parser_peek_token (parser
)->location
;
5005 "suggest braces around empty body in an %<else%> statement");
5006 add_stmt (build_empty_stmt (loc
));
5007 c_parser_consume_token (parser
);
5010 c_parser_statement_after_labels (parser
);
5011 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5014 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5017 if ( expression ) statement
5018 if ( expression ) statement else statement
5022 c_parser_if_statement (c_parser
*parser
)
5027 bool first_if
= false;
5028 tree first_body
, second_body
;
5032 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5033 c_parser_consume_token (parser
);
5034 block
= c_begin_compound_stmt (flag_isoc99
);
5035 loc
= c_parser_peek_token (parser
)->location
;
5036 cond
= c_parser_paren_condition (parser
);
5037 in_if_block
= parser
->in_if_block
;
5038 parser
->in_if_block
= true;
5039 first_body
= c_parser_if_body (parser
, &first_if
);
5040 parser
->in_if_block
= in_if_block
;
5041 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5043 c_parser_consume_token (parser
);
5044 second_body
= c_parser_else_body (parser
);
5047 second_body
= NULL_TREE
;
5048 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5049 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5051 /* If the if statement contains array notations, then we expand them. */
5052 if (flag_enable_cilkplus
&& contains_array_notation_expr (if_stmt
))
5053 if_stmt
= fix_conditional_array_notations (if_stmt
);
5057 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5060 switch (expression) statement
5064 c_parser_switch_statement (c_parser
*parser
)
5067 tree block
, expr
, body
, save_break
;
5068 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5069 location_t switch_cond_loc
;
5070 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5071 c_parser_consume_token (parser
);
5072 block
= c_begin_compound_stmt (flag_isoc99
);
5073 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5075 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5076 ce
= c_parser_expression (parser
);
5077 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5079 if (flag_enable_cilkplus
&& contains_array_notation_expr (expr
))
5081 error_at (switch_cond_loc
,
5082 "array notations cannot be used as a condition for switch "
5084 expr
= error_mark_node
;
5086 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5090 switch_cond_loc
= UNKNOWN_LOCATION
;
5091 expr
= error_mark_node
;
5093 c_start_case (switch_loc
, switch_cond_loc
, expr
);
5094 save_break
= c_break_label
;
5095 c_break_label
= NULL_TREE
;
5096 body
= c_parser_c99_block_statement (parser
);
5097 c_finish_case (body
);
5100 location_t here
= c_parser_peek_token (parser
)->location
;
5101 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5102 SET_EXPR_LOCATION (t
, here
);
5105 c_break_label
= save_break
;
5106 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5109 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5112 while (expression) statement
5116 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5118 tree block
, cond
, body
, save_break
, save_cont
;
5120 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5121 c_parser_consume_token (parser
);
5122 block
= c_begin_compound_stmt (flag_isoc99
);
5123 loc
= c_parser_peek_token (parser
)->location
;
5124 cond
= c_parser_paren_condition (parser
);
5125 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5127 error_at (loc
, "array notations cannot be used as a condition for while "
5129 cond
= error_mark_node
;
5132 if (ivdep
&& cond
!= error_mark_node
)
5133 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5134 build_int_cst (integer_type_node
,
5135 annot_expr_ivdep_kind
));
5136 save_break
= c_break_label
;
5137 c_break_label
= NULL_TREE
;
5138 save_cont
= c_cont_label
;
5139 c_cont_label
= NULL_TREE
;
5140 body
= c_parser_c99_block_statement (parser
);
5141 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5142 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5143 c_break_label
= save_break
;
5144 c_cont_label
= save_cont
;
5147 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5150 do statement while ( expression ) ;
5154 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5156 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5158 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5159 c_parser_consume_token (parser
);
5160 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5161 warning_at (c_parser_peek_token (parser
)->location
,
5163 "suggest braces around empty body in %<do%> statement");
5164 block
= c_begin_compound_stmt (flag_isoc99
);
5165 loc
= c_parser_peek_token (parser
)->location
;
5166 save_break
= c_break_label
;
5167 c_break_label
= NULL_TREE
;
5168 save_cont
= c_cont_label
;
5169 c_cont_label
= NULL_TREE
;
5170 body
= c_parser_c99_block_statement (parser
);
5171 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5172 new_break
= c_break_label
;
5173 c_break_label
= save_break
;
5174 new_cont
= c_cont_label
;
5175 c_cont_label
= save_cont
;
5176 cond
= c_parser_paren_condition (parser
);
5177 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5179 error_at (loc
, "array notations cannot be used as a condition for a "
5180 "do-while statement");
5181 cond
= error_mark_node
;
5183 if (ivdep
&& cond
!= error_mark_node
)
5184 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5185 build_int_cst (integer_type_node
,
5186 annot_expr_ivdep_kind
));
5187 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5188 c_parser_skip_to_end_of_block_or_statement (parser
);
5189 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5190 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5193 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5196 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5197 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5199 The form with a declaration is new in C99.
5201 ??? In accordance with the old parser, the declaration may be a
5202 nested function, which is then rejected in check_for_loop_decls,
5203 but does it make any sense for this to be included in the grammar?
5204 Note in particular that the nested function does not include a
5205 trailing ';', whereas the "declaration" production includes one.
5206 Also, can we reject bad declarations earlier and cheaper than
5207 check_for_loop_decls?
5209 In Objective-C, there are two additional variants:
5212 for ( expression in expresssion ) statement
5213 for ( declaration in expression ) statement
5215 This is inconsistent with C, because the second variant is allowed
5216 even if c99 is not enabled.
5218 The rest of the comment documents these Objective-C foreach-statement.
5220 Here is the canonical example of the first variant:
5221 for (object in array) { do something with object }
5222 we call the first expression ("object") the "object_expression" and
5223 the second expression ("array") the "collection_expression".
5224 object_expression must be an lvalue of type "id" (a generic Objective-C
5225 object) because the loop works by assigning to object_expression the
5226 various objects from the collection_expression. collection_expression
5227 must evaluate to something of type "id" which responds to the method
5228 countByEnumeratingWithState:objects:count:.
5230 The canonical example of the second variant is:
5231 for (id object in array) { do something with object }
5232 which is completely equivalent to
5235 for (object in array) { do something with object }
5237 Note that initizializing 'object' in some way (eg, "for ((object =
5238 xxx) in array) { do something with object }") is possibly
5239 technically valid, but completely pointless as 'object' will be
5240 assigned to something else as soon as the loop starts. We should
5241 most likely reject it (TODO).
5243 The beginning of the Objective-C foreach-statement looks exactly
5244 like the beginning of the for-statement, and we can tell it is a
5245 foreach-statement only because the initial declaration or
5246 expression is terminated by 'in' instead of ';'.
5250 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5252 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5253 /* The following are only used when parsing an ObjC foreach statement. */
5254 tree object_expression
;
5255 /* Silence the bogus uninitialized warning. */
5256 tree collection_expression
= NULL
;
5257 location_t loc
= c_parser_peek_token (parser
)->location
;
5258 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5259 bool is_foreach_statement
= false;
5260 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5261 c_parser_consume_token (parser
);
5262 /* Open a compound statement in Objective-C as well, just in case this is
5263 as foreach expression. */
5264 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5265 cond
= error_mark_node
;
5266 incr
= error_mark_node
;
5267 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5269 /* Parse the initialization declaration or expression. */
5270 object_expression
= error_mark_node
;
5271 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5272 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5274 parser
->objc_could_be_foreach_context
= false;
5275 c_parser_consume_token (parser
);
5276 c_finish_expr_stmt (loc
, NULL_TREE
);
5278 else if (c_parser_next_tokens_start_declaration (parser
))
5280 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5281 &object_expression
, vNULL
);
5282 parser
->objc_could_be_foreach_context
= false;
5284 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5286 c_parser_consume_token (parser
);
5287 is_foreach_statement
= true;
5288 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5289 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5292 check_for_loop_decls (for_loc
, flag_isoc99
);
5294 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5296 /* __extension__ can start a declaration, but is also an
5297 unary operator that can start an expression. Consume all
5298 but the last of a possible series of __extension__ to
5300 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5301 && (c_parser_peek_2nd_token (parser
)->keyword
5303 c_parser_consume_token (parser
);
5304 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5307 ext
= disable_extension_diagnostics ();
5308 c_parser_consume_token (parser
);
5309 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5310 true, &object_expression
, vNULL
);
5311 parser
->objc_could_be_foreach_context
= false;
5313 restore_extension_diagnostics (ext
);
5314 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5316 c_parser_consume_token (parser
);
5317 is_foreach_statement
= true;
5318 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5319 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5322 check_for_loop_decls (for_loc
, flag_isoc99
);
5332 tree init_expression
;
5333 ce
= c_parser_expression (parser
);
5334 init_expression
= ce
.value
;
5335 parser
->objc_could_be_foreach_context
= false;
5336 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5338 c_parser_consume_token (parser
);
5339 is_foreach_statement
= true;
5340 if (! lvalue_p (init_expression
))
5341 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5342 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5346 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5347 init_expression
= ce
.value
;
5348 c_finish_expr_stmt (loc
, init_expression
);
5349 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5353 /* Parse the loop condition. In the case of a foreach
5354 statement, there is no loop condition. */
5355 gcc_assert (!parser
->objc_could_be_foreach_context
);
5356 if (!is_foreach_statement
)
5358 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5362 c_parser_error (parser
, "missing loop condition in loop with "
5363 "%<GCC ivdep%> pragma");
5364 cond
= error_mark_node
;
5368 c_parser_consume_token (parser
);
5374 cond
= c_parser_condition (parser
);
5375 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5377 error_at (loc
, "array notations cannot be used in a "
5378 "condition for a for-loop");
5379 cond
= error_mark_node
;
5381 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5384 if (ivdep
&& cond
!= error_mark_node
)
5385 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5386 build_int_cst (integer_type_node
,
5387 annot_expr_ivdep_kind
));
5389 /* Parse the increment expression (the third expression in a
5390 for-statement). In the case of a foreach-statement, this is
5391 the expression that follows the 'in'. */
5392 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5394 if (is_foreach_statement
)
5396 c_parser_error (parser
, "missing collection in fast enumeration");
5397 collection_expression
= error_mark_node
;
5400 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5404 if (is_foreach_statement
)
5405 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5409 struct c_expr ce
= c_parser_expression (parser
);
5410 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5411 incr
= c_process_expr_stmt (loc
, ce
.value
);
5414 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5416 save_break
= c_break_label
;
5417 c_break_label
= NULL_TREE
;
5418 save_cont
= c_cont_label
;
5419 c_cont_label
= NULL_TREE
;
5420 body
= c_parser_c99_block_statement (parser
);
5421 if (is_foreach_statement
)
5422 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5424 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5425 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5426 c_break_label
= save_break
;
5427 c_cont_label
= save_cont
;
5430 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5431 statement with inputs, outputs, clobbers, and volatile tag
5435 asm type-qualifier[opt] ( asm-argument ) ;
5436 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5440 asm-string-literal : asm-operands[opt]
5441 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5442 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5445 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5448 Qualifiers other than volatile are accepted in the syntax but
5452 c_parser_asm_statement (c_parser
*parser
)
5454 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5455 bool simple
, is_goto
;
5456 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5457 int section
, nsections
;
5459 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5460 c_parser_consume_token (parser
);
5461 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5463 quals
= c_parser_peek_token (parser
)->value
;
5464 c_parser_consume_token (parser
);
5466 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5467 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5469 warning_at (c_parser_peek_token (parser
)->location
,
5471 "%E qualifier ignored on asm",
5472 c_parser_peek_token (parser
)->value
);
5474 c_parser_consume_token (parser
);
5480 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5482 c_parser_consume_token (parser
);
5486 /* ??? Follow the C++ parser rather than using the
5487 lex_untranslated_string kludge. */
5488 parser
->lex_untranslated_string
= true;
5491 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5494 str
= c_parser_asm_string_literal (parser
);
5495 if (str
== NULL_TREE
)
5496 goto error_close_paren
;
5499 outputs
= NULL_TREE
;
5501 clobbers
= NULL_TREE
;
5504 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5507 /* Parse each colon-delimited section of operands. */
5508 nsections
= 3 + is_goto
;
5509 for (section
= 0; section
< nsections
; ++section
)
5511 if (!c_parser_require (parser
, CPP_COLON
,
5514 : "expected %<:%> or %<)%>"))
5515 goto error_close_paren
;
5517 /* Once past any colon, we're no longer a simple asm. */
5520 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5521 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5526 /* For asm goto, we don't allow output operands, but reserve
5527 the slot for a future extension that does allow them. */
5529 outputs
= c_parser_asm_operands (parser
);
5532 inputs
= c_parser_asm_operands (parser
);
5535 clobbers
= c_parser_asm_clobbers (parser
);
5538 labels
= c_parser_asm_goto_operands (parser
);
5544 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5549 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5551 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5555 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5556 c_parser_skip_to_end_of_block_or_statement (parser
);
5558 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5559 clobbers
, labels
, simple
));
5562 parser
->lex_untranslated_string
= false;
5566 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5570 /* Parse asm operands, a GNU extension.
5574 asm-operands , asm-operand
5577 asm-string-literal ( expression )
5578 [ identifier ] asm-string-literal ( expression )
5582 c_parser_asm_operands (c_parser
*parser
)
5584 tree list
= NULL_TREE
;
5589 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5591 c_parser_consume_token (parser
);
5592 if (c_parser_next_token_is (parser
, CPP_NAME
))
5594 tree id
= c_parser_peek_token (parser
)->value
;
5595 c_parser_consume_token (parser
);
5596 name
= build_string (IDENTIFIER_LENGTH (id
),
5597 IDENTIFIER_POINTER (id
));
5601 c_parser_error (parser
, "expected identifier");
5602 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5605 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5610 str
= c_parser_asm_string_literal (parser
);
5611 if (str
== NULL_TREE
)
5613 parser
->lex_untranslated_string
= false;
5614 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5616 parser
->lex_untranslated_string
= true;
5619 expr
= c_parser_expression (parser
);
5620 mark_exp_read (expr
.value
);
5621 parser
->lex_untranslated_string
= true;
5622 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5624 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5627 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5629 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5630 c_parser_consume_token (parser
);
5637 /* Parse asm clobbers, a GNU extension.
5641 asm-clobbers , asm-string-literal
5645 c_parser_asm_clobbers (c_parser
*parser
)
5647 tree list
= NULL_TREE
;
5650 tree str
= c_parser_asm_string_literal (parser
);
5652 list
= tree_cons (NULL_TREE
, str
, list
);
5655 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5656 c_parser_consume_token (parser
);
5663 /* Parse asm goto labels, a GNU extension.
5667 asm-goto-operands , identifier
5671 c_parser_asm_goto_operands (c_parser
*parser
)
5673 tree list
= NULL_TREE
;
5678 if (c_parser_next_token_is (parser
, CPP_NAME
))
5680 c_token
*tok
= c_parser_peek_token (parser
);
5682 label
= lookup_label_for_goto (tok
->location
, name
);
5683 c_parser_consume_token (parser
);
5684 TREE_USED (label
) = 1;
5688 c_parser_error (parser
, "expected identifier");
5692 name
= build_string (IDENTIFIER_LENGTH (name
),
5693 IDENTIFIER_POINTER (name
));
5694 list
= tree_cons (name
, label
, list
);
5695 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5696 c_parser_consume_token (parser
);
5698 return nreverse (list
);
5702 /* Parse an expression other than a compound expression; that is, an
5703 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5704 NULL then it is an Objective-C message expression which is the
5705 primary-expression starting the expression as an initializer.
5707 assignment-expression:
5708 conditional-expression
5709 unary-expression assignment-operator assignment-expression
5711 assignment-operator: one of
5712 = *= /= %= += -= <<= >>= &= ^= |=
5714 In GNU C we accept any conditional expression on the LHS and
5715 diagnose the invalid lvalue rather than producing a syntax
5718 static struct c_expr
5719 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5720 tree omp_atomic_lhs
)
5722 struct c_expr lhs
, rhs
, ret
;
5723 enum tree_code code
;
5724 location_t op_location
, exp_location
;
5725 gcc_assert (!after
|| c_dialect_objc ());
5726 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5727 op_location
= c_parser_peek_token (parser
)->location
;
5728 switch (c_parser_peek_token (parser
)->type
)
5737 code
= TRUNC_DIV_EXPR
;
5740 code
= TRUNC_MOD_EXPR
;
5755 code
= BIT_AND_EXPR
;
5758 code
= BIT_XOR_EXPR
;
5761 code
= BIT_IOR_EXPR
;
5766 c_parser_consume_token (parser
);
5767 exp_location
= c_parser_peek_token (parser
)->location
;
5768 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5769 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5771 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5772 code
, exp_location
, rhs
.value
,
5774 if (code
== NOP_EXPR
)
5775 ret
.original_code
= MODIFY_EXPR
;
5778 TREE_NO_WARNING (ret
.value
) = 1;
5779 ret
.original_code
= ERROR_MARK
;
5781 ret
.original_type
= NULL
;
5785 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5786 is not NULL then it is an Objective-C message expression which is
5787 the primary-expression starting the expression as an initializer.
5789 conditional-expression:
5790 logical-OR-expression
5791 logical-OR-expression ? expression : conditional-expression
5795 conditional-expression:
5796 logical-OR-expression ? : conditional-expression
5799 static struct c_expr
5800 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5801 tree omp_atomic_lhs
)
5803 struct c_expr cond
, exp1
, exp2
, ret
;
5804 location_t cond_loc
, colon_loc
, middle_loc
;
5806 gcc_assert (!after
|| c_dialect_objc ());
5808 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5810 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5812 cond_loc
= c_parser_peek_token (parser
)->location
;
5813 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5814 c_parser_consume_token (parser
);
5815 if (c_parser_next_token_is (parser
, CPP_COLON
))
5817 tree eptype
= NULL_TREE
;
5819 middle_loc
= c_parser_peek_token (parser
)->location
;
5820 pedwarn (middle_loc
, OPT_Wpedantic
,
5821 "ISO C forbids omitting the middle term of a ?: expression");
5822 warn_for_omitted_condop (middle_loc
, cond
.value
);
5823 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5825 eptype
= TREE_TYPE (cond
.value
);
5826 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5828 /* Make sure first operand is calculated only once. */
5829 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5831 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5832 exp1
.original_type
= NULL
;
5833 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5834 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5839 = c_objc_common_truthvalue_conversion
5840 (cond_loc
, default_conversion (cond
.value
));
5841 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5842 exp1
= c_parser_expression_conv (parser
);
5843 mark_exp_read (exp1
.value
);
5844 c_inhibit_evaluation_warnings
+=
5845 ((cond
.value
== truthvalue_true_node
)
5846 - (cond
.value
== truthvalue_false_node
));
5849 colon_loc
= c_parser_peek_token (parser
)->location
;
5850 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5852 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5853 ret
.value
= error_mark_node
;
5854 ret
.original_code
= ERROR_MARK
;
5855 ret
.original_type
= NULL
;
5859 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5860 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5861 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
5863 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5864 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5865 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5866 exp1
.value
, exp1
.original_type
,
5867 exp2
.value
, exp2
.original_type
);
5868 ret
.original_code
= ERROR_MARK
;
5869 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5870 ret
.original_type
= NULL
;
5875 /* If both sides are enum type, the default conversion will have
5876 made the type of the result be an integer type. We want to
5877 remember the enum types we started with. */
5878 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5879 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5880 ret
.original_type
= ((t1
!= error_mark_node
5881 && t2
!= error_mark_node
5882 && (TYPE_MAIN_VARIANT (t1
)
5883 == TYPE_MAIN_VARIANT (t2
)))
5890 /* Parse a binary expression; that is, a logical-OR-expression (C90
5891 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5892 an Objective-C message expression which is the primary-expression
5893 starting the expression as an initializer.
5895 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
5896 when it should be the unfolded lhs. In a valid OpenMP source,
5897 one of the operands of the toplevel binary expression must be equal
5898 to it. In that case, just return a build2 created binary operation
5899 rather than result of parser_build_binary_op.
5901 multiplicative-expression:
5903 multiplicative-expression * cast-expression
5904 multiplicative-expression / cast-expression
5905 multiplicative-expression % cast-expression
5907 additive-expression:
5908 multiplicative-expression
5909 additive-expression + multiplicative-expression
5910 additive-expression - multiplicative-expression
5914 shift-expression << additive-expression
5915 shift-expression >> additive-expression
5917 relational-expression:
5919 relational-expression < shift-expression
5920 relational-expression > shift-expression
5921 relational-expression <= shift-expression
5922 relational-expression >= shift-expression
5924 equality-expression:
5925 relational-expression
5926 equality-expression == relational-expression
5927 equality-expression != relational-expression
5931 AND-expression & equality-expression
5933 exclusive-OR-expression:
5935 exclusive-OR-expression ^ AND-expression
5937 inclusive-OR-expression:
5938 exclusive-OR-expression
5939 inclusive-OR-expression | exclusive-OR-expression
5941 logical-AND-expression:
5942 inclusive-OR-expression
5943 logical-AND-expression && inclusive-OR-expression
5945 logical-OR-expression:
5946 logical-AND-expression
5947 logical-OR-expression || logical-AND-expression
5950 static struct c_expr
5951 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5952 tree omp_atomic_lhs
)
5954 /* A binary expression is parsed using operator-precedence parsing,
5955 with the operands being cast expressions. All the binary
5956 operators are left-associative. Thus a binary expression is of
5959 E0 op1 E1 op2 E2 ...
5961 which we represent on a stack. On the stack, the precedence
5962 levels are strictly increasing. When a new operator is
5963 encountered of higher precedence than that at the top of the
5964 stack, it is pushed; its LHS is the top expression, and its RHS
5965 is everything parsed until it is popped. When a new operator is
5966 encountered with precedence less than or equal to that at the top
5967 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5968 by the result of the operation until the operator at the top of
5969 the stack has lower precedence than the new operator or there is
5970 only one element on the stack; then the top expression is the LHS
5971 of the new operator. In the case of logical AND and OR
5972 expressions, we also need to adjust c_inhibit_evaluation_warnings
5973 as appropriate when the operators are pushed and popped. */
5976 /* The expression at this stack level. */
5978 /* The precedence of the operator on its left, PREC_NONE at the
5979 bottom of the stack. */
5980 enum c_parser_prec prec
;
5981 /* The operation on its left. */
5983 /* The source location of this operation. */
5987 /* Location of the binary operator. */
5988 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5991 switch (stack[sp].op) \
5993 case TRUTH_ANDIF_EXPR: \
5994 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5995 == truthvalue_false_node); \
5997 case TRUTH_ORIF_EXPR: \
5998 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5999 == truthvalue_true_node); \
6004 stack[sp - 1].expr \
6005 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6006 stack[sp - 1].expr, true, true); \
6008 = convert_lvalue_to_rvalue (stack[sp].loc, \
6009 stack[sp].expr, true, true); \
6010 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6011 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6012 && ((1 << stack[sp].prec) \
6013 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6014 | PREC_ADD | PREC_MULT))) \
6015 && stack[sp].op != TRUNC_MOD_EXPR \
6016 && stack[0].expr.value != error_mark_node \
6017 && stack[1].expr.value != error_mark_node \
6018 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6019 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6020 stack[0].expr.value \
6021 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6022 stack[0].expr.value, stack[1].expr.value); \
6024 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6026 stack[sp - 1].expr, \
6030 gcc_assert (!after
|| c_dialect_objc ());
6031 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6032 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6033 stack
[0].prec
= PREC_NONE
;
6037 enum c_parser_prec oprec
;
6038 enum tree_code ocode
;
6041 switch (c_parser_peek_token (parser
)->type
)
6049 ocode
= TRUNC_DIV_EXPR
;
6053 ocode
= TRUNC_MOD_EXPR
;
6065 ocode
= LSHIFT_EXPR
;
6069 ocode
= RSHIFT_EXPR
;
6083 case CPP_GREATER_EQ
:
6096 oprec
= PREC_BITAND
;
6097 ocode
= BIT_AND_EXPR
;
6100 oprec
= PREC_BITXOR
;
6101 ocode
= BIT_XOR_EXPR
;
6105 ocode
= BIT_IOR_EXPR
;
6108 oprec
= PREC_LOGAND
;
6109 ocode
= TRUTH_ANDIF_EXPR
;
6113 ocode
= TRUTH_ORIF_EXPR
;
6116 /* Not a binary operator, so end of the binary
6120 binary_loc
= c_parser_peek_token (parser
)->location
;
6121 while (oprec
<= stack
[sp
].prec
)
6123 c_parser_consume_token (parser
);
6126 case TRUTH_ANDIF_EXPR
:
6128 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6129 stack
[sp
].expr
, true, true);
6130 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6131 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6132 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6133 == truthvalue_false_node
);
6135 case TRUTH_ORIF_EXPR
:
6137 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6138 stack
[sp
].expr
, true, true);
6139 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6140 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6141 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6142 == truthvalue_true_node
);
6148 stack
[sp
].loc
= binary_loc
;
6149 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6150 stack
[sp
].prec
= oprec
;
6151 stack
[sp
].op
= ocode
;
6152 stack
[sp
].loc
= binary_loc
;
6157 return stack
[0].expr
;
6161 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6162 NULL then it is an Objective-C message expression which is the
6163 primary-expression starting the expression as an initializer.
6167 ( type-name ) unary-expression
6170 static struct c_expr
6171 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6173 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6174 gcc_assert (!after
|| c_dialect_objc ());
6176 return c_parser_postfix_expression_after_primary (parser
,
6178 /* If the expression begins with a parenthesized type name, it may
6179 be either a cast or a compound literal; we need to see whether
6180 the next character is '{' to tell the difference. If not, it is
6181 an unary expression. Full detection of unknown typenames here
6182 would require a 3-token lookahead. */
6183 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6184 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6186 struct c_type_name
*type_name
;
6189 c_parser_consume_token (parser
);
6190 type_name
= c_parser_type_name (parser
);
6191 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6192 if (type_name
== NULL
)
6194 ret
.value
= error_mark_node
;
6195 ret
.original_code
= ERROR_MARK
;
6196 ret
.original_type
= NULL
;
6200 /* Save casted types in the function's used types hash table. */
6201 used_types_insert (type_name
->specs
->type
);
6203 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6204 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6207 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6208 expr
= c_parser_cast_expression (parser
, NULL
);
6209 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6211 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6212 ret
.original_code
= ERROR_MARK
;
6213 ret
.original_type
= NULL
;
6217 return c_parser_unary_expression (parser
);
6220 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6226 unary-operator cast-expression
6227 sizeof unary-expression
6228 sizeof ( type-name )
6230 unary-operator: one of
6236 __alignof__ unary-expression
6237 __alignof__ ( type-name )
6240 (C11 permits _Alignof with type names only.)
6242 unary-operator: one of
6243 __extension__ __real__ __imag__
6245 Transactional Memory:
6248 transaction-expression
6250 In addition, the GNU syntax treats ++ and -- as unary operators, so
6251 they may be applied to cast expressions with errors for non-lvalues
6254 static struct c_expr
6255 c_parser_unary_expression (c_parser
*parser
)
6258 struct c_expr ret
, op
;
6259 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6261 ret
.original_code
= ERROR_MARK
;
6262 ret
.original_type
= NULL
;
6263 switch (c_parser_peek_token (parser
)->type
)
6266 c_parser_consume_token (parser
);
6267 exp_loc
= c_parser_peek_token (parser
)->location
;
6268 op
= c_parser_cast_expression (parser
, NULL
);
6270 /* If there is array notations in op, we expand them. */
6271 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6272 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6275 op
= default_function_array_read_conversion (exp_loc
, op
);
6276 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6278 case CPP_MINUS_MINUS
:
6279 c_parser_consume_token (parser
);
6280 exp_loc
= c_parser_peek_token (parser
)->location
;
6281 op
= c_parser_cast_expression (parser
, NULL
);
6283 /* If there is array notations in op, we expand them. */
6284 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6285 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6288 op
= default_function_array_read_conversion (exp_loc
, op
);
6289 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6292 c_parser_consume_token (parser
);
6293 op
= c_parser_cast_expression (parser
, NULL
);
6294 mark_exp_read (op
.value
);
6295 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6297 c_parser_consume_token (parser
);
6298 exp_loc
= c_parser_peek_token (parser
)->location
;
6299 op
= c_parser_cast_expression (parser
, NULL
);
6300 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6301 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6304 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6307 "traditional C rejects the unary plus operator");
6308 c_parser_consume_token (parser
);
6309 exp_loc
= c_parser_peek_token (parser
)->location
;
6310 op
= c_parser_cast_expression (parser
, NULL
);
6311 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6312 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6314 c_parser_consume_token (parser
);
6315 exp_loc
= c_parser_peek_token (parser
)->location
;
6316 op
= c_parser_cast_expression (parser
, NULL
);
6317 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6318 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6320 c_parser_consume_token (parser
);
6321 exp_loc
= c_parser_peek_token (parser
)->location
;
6322 op
= c_parser_cast_expression (parser
, NULL
);
6323 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6324 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6326 c_parser_consume_token (parser
);
6327 exp_loc
= c_parser_peek_token (parser
)->location
;
6328 op
= c_parser_cast_expression (parser
, NULL
);
6329 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6330 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6332 /* Refer to the address of a label as a pointer. */
6333 c_parser_consume_token (parser
);
6334 if (c_parser_next_token_is (parser
, CPP_NAME
))
6336 ret
.value
= finish_label_address_expr
6337 (c_parser_peek_token (parser
)->value
, op_loc
);
6338 c_parser_consume_token (parser
);
6342 c_parser_error (parser
, "expected identifier");
6343 ret
.value
= error_mark_node
;
6347 switch (c_parser_peek_token (parser
)->keyword
)
6350 return c_parser_sizeof_expression (parser
);
6352 return c_parser_alignof_expression (parser
);
6354 c_parser_consume_token (parser
);
6355 ext
= disable_extension_diagnostics ();
6356 ret
= c_parser_cast_expression (parser
, NULL
);
6357 restore_extension_diagnostics (ext
);
6360 c_parser_consume_token (parser
);
6361 exp_loc
= c_parser_peek_token (parser
)->location
;
6362 op
= c_parser_cast_expression (parser
, NULL
);
6363 op
= default_function_array_conversion (exp_loc
, op
);
6364 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6366 c_parser_consume_token (parser
);
6367 exp_loc
= c_parser_peek_token (parser
)->location
;
6368 op
= c_parser_cast_expression (parser
, NULL
);
6369 op
= default_function_array_conversion (exp_loc
, op
);
6370 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6371 case RID_TRANSACTION_ATOMIC
:
6372 case RID_TRANSACTION_RELAXED
:
6373 return c_parser_transaction_expression (parser
,
6374 c_parser_peek_token (parser
)->keyword
);
6376 return c_parser_postfix_expression (parser
);
6379 return c_parser_postfix_expression (parser
);
6383 /* Parse a sizeof expression. */
6385 static struct c_expr
6386 c_parser_sizeof_expression (c_parser
*parser
)
6389 location_t expr_loc
;
6390 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6391 c_parser_consume_token (parser
);
6392 c_inhibit_evaluation_warnings
++;
6394 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6395 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6397 /* Either sizeof ( type-name ) or sizeof unary-expression
6398 starting with a compound literal. */
6399 struct c_type_name
*type_name
;
6400 c_parser_consume_token (parser
);
6401 expr_loc
= c_parser_peek_token (parser
)->location
;
6402 type_name
= c_parser_type_name (parser
);
6403 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6404 if (type_name
== NULL
)
6407 c_inhibit_evaluation_warnings
--;
6409 ret
.value
= error_mark_node
;
6410 ret
.original_code
= ERROR_MARK
;
6411 ret
.original_type
= NULL
;
6414 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6416 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6421 /* sizeof ( type-name ). */
6422 c_inhibit_evaluation_warnings
--;
6424 return c_expr_sizeof_type (expr_loc
, type_name
);
6428 expr_loc
= c_parser_peek_token (parser
)->location
;
6429 expr
= c_parser_unary_expression (parser
);
6431 c_inhibit_evaluation_warnings
--;
6433 mark_exp_read (expr
.value
);
6434 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6435 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6436 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6437 return c_expr_sizeof_expr (expr_loc
, expr
);
6441 /* Parse an alignof expression. */
6443 static struct c_expr
6444 c_parser_alignof_expression (c_parser
*parser
)
6447 location_t loc
= c_parser_peek_token (parser
)->location
;
6448 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6449 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6450 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6452 /* A diagnostic is not required for the use of this identifier in
6453 the implementation namespace; only diagnose it for the C11
6454 spelling because of existing code using the other spellings. */
6455 if (!flag_isoc11
&& is_c11_alignof
)
6458 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6461 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6464 c_parser_consume_token (parser
);
6465 c_inhibit_evaluation_warnings
++;
6467 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6468 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6470 /* Either __alignof__ ( type-name ) or __alignof__
6471 unary-expression starting with a compound literal. */
6473 struct c_type_name
*type_name
;
6475 c_parser_consume_token (parser
);
6476 loc
= c_parser_peek_token (parser
)->location
;
6477 type_name
= c_parser_type_name (parser
);
6478 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6479 if (type_name
== NULL
)
6482 c_inhibit_evaluation_warnings
--;
6484 ret
.value
= error_mark_node
;
6485 ret
.original_code
= ERROR_MARK
;
6486 ret
.original_type
= NULL
;
6489 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6491 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6496 /* alignof ( type-name ). */
6497 c_inhibit_evaluation_warnings
--;
6499 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6501 false, is_c11_alignof
, 1);
6502 ret
.original_code
= ERROR_MARK
;
6503 ret
.original_type
= NULL
;
6509 expr
= c_parser_unary_expression (parser
);
6511 mark_exp_read (expr
.value
);
6512 c_inhibit_evaluation_warnings
--;
6514 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6516 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6517 ret
.original_code
= ERROR_MARK
;
6518 ret
.original_type
= NULL
;
6523 /* Helper function to read arguments of builtins which are interfaces
6524 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6525 others. The name of the builtin is passed using BNAME parameter.
6526 Function returns true if there were no errors while parsing and
6527 stores the arguments in CEXPR_LIST. */
6529 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6530 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6533 location_t loc
= c_parser_peek_token (parser
)->location
;
6534 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6536 bool saved_force_folding_builtin_constant_p
;
6538 *ret_cexpr_list
= NULL
;
6539 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6541 error_at (loc
, "cannot take address of %qs", bname
);
6545 c_parser_consume_token (parser
);
6547 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6549 c_parser_consume_token (parser
);
6553 saved_force_folding_builtin_constant_p
6554 = force_folding_builtin_constant_p
;
6555 force_folding_builtin_constant_p
|= choose_expr_p
;
6556 expr
= c_parser_expr_no_commas (parser
, NULL
);
6557 force_folding_builtin_constant_p
6558 = saved_force_folding_builtin_constant_p
;
6559 vec_alloc (cexpr_list
, 1);
6560 C_EXPR_APPEND (cexpr_list
, expr
);
6561 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6563 c_parser_consume_token (parser
);
6564 expr
= c_parser_expr_no_commas (parser
, NULL
);
6565 C_EXPR_APPEND (cexpr_list
, expr
);
6568 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6571 *ret_cexpr_list
= cexpr_list
;
6575 /* This represents a single generic-association. */
6577 struct c_generic_association
6579 /* The location of the starting token of the type. */
6580 location_t type_location
;
6581 /* The association's type, or NULL_TREE for 'default'. */
6583 /* The association's expression. */
6584 struct c_expr expression
;
6587 /* Parse a generic-selection. (C11 6.5.1.1).
6590 _Generic ( assignment-expression , generic-assoc-list )
6594 generic-assoc-list , generic-association
6596 generic-association:
6597 type-name : assignment-expression
6598 default : assignment-expression
6601 static struct c_expr
6602 c_parser_generic_selection (c_parser
*parser
)
6604 vec
<c_generic_association
> associations
= vNULL
;
6605 struct c_expr selector
, error_expr
;
6607 struct c_generic_association matched_assoc
;
6608 bool match_found
= false;
6609 location_t generic_loc
, selector_loc
;
6611 error_expr
.original_code
= ERROR_MARK
;
6612 error_expr
.original_type
= NULL
;
6613 error_expr
.value
= error_mark_node
;
6614 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6615 matched_assoc
.type
= NULL_TREE
;
6616 matched_assoc
.expression
= error_expr
;
6618 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6619 generic_loc
= c_parser_peek_token (parser
)->location
;
6620 c_parser_consume_token (parser
);
6624 pedwarn (generic_loc
, OPT_Wpedantic
,
6625 "ISO C99 does not support %<_Generic%>");
6627 pedwarn (generic_loc
, OPT_Wpedantic
,
6628 "ISO C90 does not support %<_Generic%>");
6631 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6634 c_inhibit_evaluation_warnings
++;
6635 selector_loc
= c_parser_peek_token (parser
)->location
;
6636 selector
= c_parser_expr_no_commas (parser
, NULL
);
6637 selector
= default_function_array_conversion (selector_loc
, selector
);
6638 c_inhibit_evaluation_warnings
--;
6640 if (selector
.value
== error_mark_node
)
6642 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6645 selector_type
= TREE_TYPE (selector
.value
);
6646 /* In ISO C terms, rvalues (including the controlling expression of
6647 _Generic) do not have qualified types. */
6648 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6649 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6650 /* In ISO C terms, _Noreturn is not part of the type of expressions
6651 such as &abort, but in GCC it is represented internally as a type
6653 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6654 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6656 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6658 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6660 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6666 struct c_generic_association assoc
, *iter
;
6668 c_token
*token
= c_parser_peek_token (parser
);
6670 assoc
.type_location
= token
->location
;
6671 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6673 c_parser_consume_token (parser
);
6674 assoc
.type
= NULL_TREE
;
6678 struct c_type_name
*type_name
;
6680 type_name
= c_parser_type_name (parser
);
6681 if (type_name
== NULL
)
6683 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6686 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6687 if (assoc
.type
== error_mark_node
)
6689 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6693 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6694 error_at (assoc
.type_location
,
6695 "%<_Generic%> association has function type");
6696 else if (!COMPLETE_TYPE_P (assoc
.type
))
6697 error_at (assoc
.type_location
,
6698 "%<_Generic%> association has incomplete type");
6700 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6701 error_at (assoc
.type_location
,
6702 "%<_Generic%> association has "
6703 "variable length type");
6706 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6708 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6712 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6713 if (assoc
.expression
.value
== error_mark_node
)
6715 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6719 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6721 if (assoc
.type
== NULL_TREE
)
6723 if (iter
->type
== NULL_TREE
)
6725 error_at (assoc
.type_location
,
6726 "duplicate %<default%> case in %<_Generic%>");
6727 inform (iter
->type_location
, "original %<default%> is here");
6730 else if (iter
->type
!= NULL_TREE
)
6732 if (comptypes (assoc
.type
, iter
->type
))
6734 error_at (assoc
.type_location
,
6735 "%<_Generic%> specifies two compatible types");
6736 inform (iter
->type_location
, "compatible type is here");
6741 if (assoc
.type
== NULL_TREE
)
6745 matched_assoc
= assoc
;
6749 else if (comptypes (assoc
.type
, selector_type
))
6751 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6753 matched_assoc
= assoc
;
6758 error_at (assoc
.type_location
,
6759 "%<_Generic> selector matches multiple associations");
6760 inform (matched_assoc
.type_location
,
6761 "other match is here");
6765 associations
.safe_push (assoc
);
6767 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6769 c_parser_consume_token (parser
);
6772 associations
.release ();
6774 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6776 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6782 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6783 "compatible with any association",
6788 return matched_assoc
.expression
;
6791 associations
.release ();
6795 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6799 postfix-expression [ expression ]
6800 postfix-expression ( argument-expression-list[opt] )
6801 postfix-expression . identifier
6802 postfix-expression -> identifier
6803 postfix-expression ++
6804 postfix-expression --
6805 ( type-name ) { initializer-list }
6806 ( type-name ) { initializer-list , }
6808 argument-expression-list:
6810 argument-expression-list , argument-expression
6823 (treated as a keyword in GNU C)
6826 ( compound-statement )
6827 __builtin_va_arg ( assignment-expression , type-name )
6828 __builtin_offsetof ( type-name , offsetof-member-designator )
6829 __builtin_choose_expr ( assignment-expression ,
6830 assignment-expression ,
6831 assignment-expression )
6832 __builtin_types_compatible_p ( type-name , type-name )
6833 __builtin_complex ( assignment-expression , assignment-expression )
6834 __builtin_shuffle ( assignment-expression , assignment-expression )
6835 __builtin_shuffle ( assignment-expression ,
6836 assignment-expression ,
6837 assignment-expression, )
6839 offsetof-member-designator:
6841 offsetof-member-designator . identifier
6842 offsetof-member-designator [ expression ]
6847 [ objc-receiver objc-message-args ]
6848 @selector ( objc-selector-arg )
6849 @protocol ( identifier )
6850 @encode ( type-name )
6852 Classname . identifier
6855 static struct c_expr
6856 c_parser_postfix_expression (c_parser
*parser
)
6858 struct c_expr expr
, e1
;
6859 struct c_type_name
*t1
, *t2
;
6860 location_t loc
= c_parser_peek_token (parser
)->location
;;
6861 expr
.original_code
= ERROR_MARK
;
6862 expr
.original_type
= NULL
;
6863 switch (c_parser_peek_token (parser
)->type
)
6866 expr
.value
= c_parser_peek_token (parser
)->value
;
6867 loc
= c_parser_peek_token (parser
)->location
;
6868 c_parser_consume_token (parser
);
6869 if (TREE_CODE (expr
.value
) == FIXED_CST
6870 && !targetm
.fixed_point_supported_p ())
6872 error_at (loc
, "fixed-point types not supported for this target");
6873 expr
.value
= error_mark_node
;
6880 expr
.value
= c_parser_peek_token (parser
)->value
;
6881 c_parser_consume_token (parser
);
6887 case CPP_UTF8STRING
:
6888 expr
.value
= c_parser_peek_token (parser
)->value
;
6889 expr
.original_code
= STRING_CST
;
6890 c_parser_consume_token (parser
);
6892 case CPP_OBJC_STRING
:
6893 gcc_assert (c_dialect_objc ());
6895 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6896 c_parser_consume_token (parser
);
6899 switch (c_parser_peek_token (parser
)->id_kind
)
6903 tree id
= c_parser_peek_token (parser
)->value
;
6904 c_parser_consume_token (parser
);
6905 expr
.value
= build_external_ref (loc
, id
,
6906 (c_parser_peek_token (parser
)->type
6908 &expr
.original_type
);
6911 case C_ID_CLASSNAME
:
6913 /* Here we parse the Objective-C 2.0 Class.name dot
6915 tree class_name
= c_parser_peek_token (parser
)->value
;
6917 c_parser_consume_token (parser
);
6918 gcc_assert (c_dialect_objc ());
6919 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6921 expr
.value
= error_mark_node
;
6924 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6926 c_parser_error (parser
, "expected identifier");
6927 expr
.value
= error_mark_node
;
6930 component
= c_parser_peek_token (parser
)->value
;
6931 c_parser_consume_token (parser
);
6932 expr
.value
= objc_build_class_component_ref (class_name
,
6937 c_parser_error (parser
, "expected expression");
6938 expr
.value
= error_mark_node
;
6942 case CPP_OPEN_PAREN
:
6943 /* A parenthesized expression, statement expression or compound
6945 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6947 /* A statement expression. */
6949 location_t brace_loc
;
6950 c_parser_consume_token (parser
);
6951 brace_loc
= c_parser_peek_token (parser
)->location
;
6952 c_parser_consume_token (parser
);
6953 if (!building_stmt_list_p ())
6955 error_at (loc
, "braced-group within expression allowed "
6956 "only inside a function");
6957 parser
->error
= true;
6958 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6959 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6960 expr
.value
= error_mark_node
;
6963 stmt
= c_begin_stmt_expr ();
6964 c_parser_compound_statement_nostart (parser
);
6965 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6967 pedwarn (loc
, OPT_Wpedantic
,
6968 "ISO C forbids braced-groups within expressions");
6969 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6970 mark_exp_read (expr
.value
);
6972 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6974 /* A compound literal. ??? Can we actually get here rather
6975 than going directly to
6976 c_parser_postfix_expression_after_paren_type from
6979 struct c_type_name
*type_name
;
6980 c_parser_consume_token (parser
);
6981 loc
= c_parser_peek_token (parser
)->location
;
6982 type_name
= c_parser_type_name (parser
);
6983 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6985 if (type_name
== NULL
)
6987 expr
.value
= error_mark_node
;
6990 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6996 /* A parenthesized expression. */
6997 c_parser_consume_token (parser
);
6998 expr
= c_parser_expression (parser
);
6999 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7000 TREE_NO_WARNING (expr
.value
) = 1;
7001 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7002 expr
.original_code
= ERROR_MARK
;
7003 /* Don't change EXPR.ORIGINAL_TYPE. */
7004 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7009 switch (c_parser_peek_token (parser
)->keyword
)
7011 case RID_FUNCTION_NAME
:
7012 case RID_PRETTY_FUNCTION_NAME
:
7013 case RID_C99_FUNCTION_NAME
:
7014 expr
.value
= fname_decl (loc
,
7015 c_parser_peek_token (parser
)->keyword
,
7016 c_parser_peek_token (parser
)->value
);
7017 c_parser_consume_token (parser
);
7020 c_parser_consume_token (parser
);
7021 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7023 expr
.value
= error_mark_node
;
7026 e1
= c_parser_expr_no_commas (parser
, NULL
);
7027 mark_exp_read (e1
.value
);
7028 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7029 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7031 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7032 expr
.value
= error_mark_node
;
7035 loc
= c_parser_peek_token (parser
)->location
;
7036 t1
= c_parser_type_name (parser
);
7037 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7041 expr
.value
= error_mark_node
;
7045 tree type_expr
= NULL_TREE
;
7046 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7047 groktypename (t1
, &type_expr
, NULL
));
7050 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7051 TREE_TYPE (expr
.value
), type_expr
,
7053 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7058 c_parser_consume_token (parser
);
7059 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7061 expr
.value
= error_mark_node
;
7064 t1
= c_parser_type_name (parser
);
7066 parser
->error
= true;
7067 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7068 gcc_assert (parser
->error
);
7071 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7072 expr
.value
= error_mark_node
;
7077 tree type
= groktypename (t1
, NULL
, NULL
);
7079 if (type
== error_mark_node
)
7080 offsetof_ref
= error_mark_node
;
7083 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7084 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7086 /* Parse the second argument to __builtin_offsetof. We
7087 must have one identifier, and beyond that we want to
7088 accept sub structure and sub array references. */
7089 if (c_parser_next_token_is (parser
, CPP_NAME
))
7091 offsetof_ref
= build_component_ref
7092 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7093 c_parser_consume_token (parser
);
7094 while (c_parser_next_token_is (parser
, CPP_DOT
)
7095 || c_parser_next_token_is (parser
,
7097 || c_parser_next_token_is (parser
,
7100 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7102 loc
= c_parser_peek_token (parser
)->location
;
7103 offsetof_ref
= build_array_ref (loc
,
7108 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7111 c_parser_consume_token (parser
);
7112 if (c_parser_next_token_is_not (parser
,
7115 c_parser_error (parser
, "expected identifier");
7118 offsetof_ref
= build_component_ref
7120 c_parser_peek_token (parser
)->value
);
7121 c_parser_consume_token (parser
);
7127 loc
= c_parser_peek_token (parser
)->location
;
7128 c_parser_consume_token (parser
);
7129 ce
= c_parser_expression (parser
);
7130 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7132 idx
= c_fully_fold (idx
, false, NULL
);
7133 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7135 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7140 c_parser_error (parser
, "expected identifier");
7141 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7143 expr
.value
= fold_offsetof (offsetof_ref
);
7146 case RID_CHOOSE_EXPR
:
7148 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7149 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7152 c_parser_consume_token (parser
);
7153 if (!c_parser_get_builtin_args (parser
,
7154 "__builtin_choose_expr",
7157 expr
.value
= error_mark_node
;
7161 if (vec_safe_length (cexpr_list
) != 3)
7163 error_at (loc
, "wrong number of arguments to "
7164 "%<__builtin_choose_expr%>");
7165 expr
.value
= error_mark_node
;
7169 e1_p
= &(*cexpr_list
)[0];
7170 e2_p
= &(*cexpr_list
)[1];
7171 e3_p
= &(*cexpr_list
)[2];
7174 mark_exp_read (e2_p
->value
);
7175 mark_exp_read (e3_p
->value
);
7176 if (TREE_CODE (c
) != INTEGER_CST
7177 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7179 "first argument to %<__builtin_choose_expr%> not"
7181 constant_expression_warning (c
);
7182 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7185 case RID_TYPES_COMPATIBLE_P
:
7186 c_parser_consume_token (parser
);
7187 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7189 expr
.value
= error_mark_node
;
7192 t1
= c_parser_type_name (parser
);
7195 expr
.value
= error_mark_node
;
7198 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7200 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7201 expr
.value
= error_mark_node
;
7204 t2
= c_parser_type_name (parser
);
7207 expr
.value
= error_mark_node
;
7210 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7214 e1
= groktypename (t1
, NULL
, NULL
);
7215 e2
= groktypename (t2
, NULL
, NULL
);
7216 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7218 expr
.value
= error_mark_node
;
7222 e1
= TYPE_MAIN_VARIANT (e1
);
7223 e2
= TYPE_MAIN_VARIANT (e2
);
7226 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7229 case RID_BUILTIN_COMPLEX
:
7231 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7232 c_expr_t
*e1_p
, *e2_p
;
7234 c_parser_consume_token (parser
);
7235 if (!c_parser_get_builtin_args (parser
,
7236 "__builtin_complex",
7237 &cexpr_list
, false))
7239 expr
.value
= error_mark_node
;
7243 if (vec_safe_length (cexpr_list
) != 2)
7245 error_at (loc
, "wrong number of arguments to "
7246 "%<__builtin_complex%>");
7247 expr
.value
= error_mark_node
;
7251 e1_p
= &(*cexpr_list
)[0];
7252 e2_p
= &(*cexpr_list
)[1];
7254 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7255 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7256 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7257 TREE_OPERAND (e1_p
->value
, 0));
7258 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7259 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7260 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7261 TREE_OPERAND (e2_p
->value
, 0));
7262 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7263 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7264 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7265 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7267 error_at (loc
, "%<__builtin_complex%> operand "
7268 "not of real binary floating-point type");
7269 expr
.value
= error_mark_node
;
7272 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7273 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7276 "%<__builtin_complex%> operands of different types");
7277 expr
.value
= error_mark_node
;
7281 pedwarn (loc
, OPT_Wpedantic
,
7282 "ISO C90 does not support complex types");
7283 expr
.value
= build2 (COMPLEX_EXPR
,
7286 (TREE_TYPE (e1_p
->value
))),
7287 e1_p
->value
, e2_p
->value
);
7290 case RID_BUILTIN_SHUFFLE
:
7292 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7296 c_parser_consume_token (parser
);
7297 if (!c_parser_get_builtin_args (parser
,
7298 "__builtin_shuffle",
7299 &cexpr_list
, false))
7301 expr
.value
= error_mark_node
;
7305 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7306 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7308 if (vec_safe_length (cexpr_list
) == 2)
7310 c_build_vec_perm_expr
7311 (loc
, (*cexpr_list
)[0].value
,
7312 NULL_TREE
, (*cexpr_list
)[1].value
);
7314 else if (vec_safe_length (cexpr_list
) == 3)
7316 c_build_vec_perm_expr
7317 (loc
, (*cexpr_list
)[0].value
,
7318 (*cexpr_list
)[1].value
,
7319 (*cexpr_list
)[2].value
);
7322 error_at (loc
, "wrong number of arguments to "
7323 "%<__builtin_shuffle%>");
7324 expr
.value
= error_mark_node
;
7328 case RID_AT_SELECTOR
:
7329 gcc_assert (c_dialect_objc ());
7330 c_parser_consume_token (parser
);
7331 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7333 expr
.value
= error_mark_node
;
7337 tree sel
= c_parser_objc_selector_arg (parser
);
7338 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7340 expr
.value
= objc_build_selector_expr (loc
, sel
);
7343 case RID_AT_PROTOCOL
:
7344 gcc_assert (c_dialect_objc ());
7345 c_parser_consume_token (parser
);
7346 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7348 expr
.value
= error_mark_node
;
7351 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7353 c_parser_error (parser
, "expected identifier");
7354 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7355 expr
.value
= error_mark_node
;
7359 tree id
= c_parser_peek_token (parser
)->value
;
7360 c_parser_consume_token (parser
);
7361 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7363 expr
.value
= objc_build_protocol_expr (id
);
7367 /* Extension to support C-structures in the archiver. */
7368 gcc_assert (c_dialect_objc ());
7369 c_parser_consume_token (parser
);
7370 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7372 expr
.value
= error_mark_node
;
7375 t1
= c_parser_type_name (parser
);
7378 expr
.value
= error_mark_node
;
7379 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7382 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7385 tree type
= groktypename (t1
, NULL
, NULL
);
7386 expr
.value
= objc_build_encode_expr (type
);
7390 expr
= c_parser_generic_selection (parser
);
7392 case RID_CILK_SPAWN
:
7393 c_parser_consume_token (parser
);
7394 if (!flag_enable_cilkplus
)
7396 error_at (loc
, "-fcilkplus must be enabled to use "
7398 expr
= c_parser_postfix_expression (parser
);
7399 expr
.value
= error_mark_node
;
7401 if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7403 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7404 "are not permitted");
7405 /* Now flush out all the _Cilk_spawns. */
7406 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7407 c_parser_consume_token (parser
);
7408 expr
= c_parser_postfix_expression (parser
);
7412 expr
= c_parser_postfix_expression (parser
);
7413 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7417 c_parser_error (parser
, "expected expression");
7418 expr
.value
= error_mark_node
;
7422 case CPP_OPEN_SQUARE
:
7423 if (c_dialect_objc ())
7425 tree receiver
, args
;
7426 c_parser_consume_token (parser
);
7427 receiver
= c_parser_objc_receiver (parser
);
7428 args
= c_parser_objc_message_args (parser
);
7429 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7431 expr
.value
= objc_build_message_expr (receiver
, args
);
7434 /* Else fall through to report error. */
7436 c_parser_error (parser
, "expected expression");
7437 expr
.value
= error_mark_node
;
7440 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7443 /* Parse a postfix expression after a parenthesized type name: the
7444 brace-enclosed initializer of a compound literal, possibly followed
7445 by some postfix operators. This is separate because it is not
7446 possible to tell until after the type name whether a cast
7447 expression has a cast or a compound literal, or whether the operand
7448 of sizeof is a parenthesized type name or starts with a compound
7449 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7450 location of the first token after the parentheses around the type
7453 static struct c_expr
7454 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7455 struct c_type_name
*type_name
,
7456 location_t type_loc
)
7462 location_t start_loc
;
7463 tree type_expr
= NULL_TREE
;
7464 bool type_expr_const
= true;
7465 check_compound_literal_type (type_loc
, type_name
);
7466 start_init (NULL_TREE
, NULL
, 0);
7467 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7468 start_loc
= c_parser_peek_token (parser
)->location
;
7469 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7471 error_at (type_loc
, "compound literal has variable size");
7472 type
= error_mark_node
;
7474 init
= c_parser_braced_init (parser
, type
, false);
7476 maybe_warn_string_init (type
, init
);
7478 if (type
!= error_mark_node
7479 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7480 && current_function_decl
)
7482 error ("compound literal qualified by address-space qualifier");
7483 type
= error_mark_node
;
7487 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7488 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7489 ? CONSTRUCTOR_NON_CONST (init
.value
)
7490 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7491 non_const
|= !type_expr_const
;
7492 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7493 expr
.original_code
= ERROR_MARK
;
7494 expr
.original_type
= NULL
;
7497 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7499 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7500 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7504 gcc_assert (!non_const
);
7505 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7506 type_expr
, expr
.value
);
7509 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7512 /* Callback function for sizeof_pointer_memaccess_warning to compare
7516 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7518 return comptypes (type1
, type2
) == 1;
7521 /* Parse a postfix expression after the initial primary or compound
7522 literal; that is, parse a series of postfix operators.
7524 EXPR_LOC is the location of the primary expression. */
7526 static struct c_expr
7527 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7528 location_t expr_loc
,
7531 struct c_expr orig_expr
;
7533 location_t sizeof_arg_loc
[3];
7536 vec
<tree
, va_gc
> *exprlist
;
7537 vec
<tree
, va_gc
> *origtypes
= NULL
;
7540 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7541 switch (c_parser_peek_token (parser
)->type
)
7543 case CPP_OPEN_SQUARE
:
7544 /* Array reference. */
7545 c_parser_consume_token (parser
);
7546 if (flag_enable_cilkplus
7547 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7548 /* If we are here, then we have something like this:
7551 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7555 idx
= c_parser_expression (parser
).value
;
7556 /* Here we have 3 options:
7557 1. Array [EXPR] -- Normal Array call.
7558 2. Array [EXPR : EXPR] -- Array notation without stride.
7559 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7561 For 1, we just handle it just like a normal array expression.
7562 For 2 and 3 we handle it like we handle array notations. The
7563 idx value we have above becomes the initial/start index.
7565 if (flag_enable_cilkplus
7566 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7567 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7571 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7573 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7576 expr
.original_code
= ERROR_MARK
;
7577 expr
.original_type
= NULL
;
7579 case CPP_OPEN_PAREN
:
7580 /* Function call. */
7581 c_parser_consume_token (parser
);
7582 for (i
= 0; i
< 3; i
++)
7584 sizeof_arg
[i
] = NULL_TREE
;
7585 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7587 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7590 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7591 sizeof_arg_loc
, sizeof_arg
);
7592 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7595 mark_exp_read (expr
.value
);
7596 if (warn_sizeof_pointer_memaccess
)
7597 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7598 expr
.value
, exprlist
,
7600 sizeof_ptr_memacc_comptypes
);
7601 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7602 "(" after the FUNCNAME, which is what we have now. */
7603 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7605 expr
.original_code
= ERROR_MARK
;
7606 if (TREE_CODE (expr
.value
) == INTEGER_CST
7607 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7608 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7609 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7610 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7611 expr
.original_type
= NULL
;
7614 release_tree_vector (exprlist
);
7615 release_tree_vector (origtypes
);
7619 /* Structure element reference. */
7620 c_parser_consume_token (parser
);
7621 expr
= default_function_array_conversion (expr_loc
, expr
);
7622 if (c_parser_next_token_is (parser
, CPP_NAME
))
7623 ident
= c_parser_peek_token (parser
)->value
;
7626 c_parser_error (parser
, "expected identifier");
7627 expr
.value
= error_mark_node
;
7628 expr
.original_code
= ERROR_MARK
;
7629 expr
.original_type
= NULL
;
7632 c_parser_consume_token (parser
);
7633 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7634 expr
.original_code
= ERROR_MARK
;
7635 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7636 expr
.original_type
= NULL
;
7639 /* Remember the original type of a bitfield. */
7640 tree field
= TREE_OPERAND (expr
.value
, 1);
7641 if (TREE_CODE (field
) != FIELD_DECL
)
7642 expr
.original_type
= NULL
;
7644 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7648 /* Structure element reference. */
7649 c_parser_consume_token (parser
);
7650 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7651 if (c_parser_next_token_is (parser
, CPP_NAME
))
7652 ident
= c_parser_peek_token (parser
)->value
;
7655 c_parser_error (parser
, "expected identifier");
7656 expr
.value
= error_mark_node
;
7657 expr
.original_code
= ERROR_MARK
;
7658 expr
.original_type
= NULL
;
7661 c_parser_consume_token (parser
);
7662 expr
.value
= build_component_ref (op_loc
,
7663 build_indirect_ref (op_loc
,
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 /* Postincrement. */
7682 c_parser_consume_token (parser
);
7683 /* If the expressions have array notations, we expand them. */
7684 if (flag_enable_cilkplus
7685 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7686 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7689 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7690 expr
.value
= build_unary_op (op_loc
,
7691 POSTINCREMENT_EXPR
, expr
.value
, 0);
7693 expr
.original_code
= ERROR_MARK
;
7694 expr
.original_type
= NULL
;
7696 case CPP_MINUS_MINUS
:
7697 /* Postdecrement. */
7698 c_parser_consume_token (parser
);
7699 /* If the expressions have array notations, we expand them. */
7700 if (flag_enable_cilkplus
7701 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7702 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7705 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7706 expr
.value
= build_unary_op (op_loc
,
7707 POSTDECREMENT_EXPR
, expr
.value
, 0);
7709 expr
.original_code
= ERROR_MARK
;
7710 expr
.original_type
= NULL
;
7718 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7721 assignment-expression
7722 expression , assignment-expression
7725 static struct c_expr
7726 c_parser_expression (c_parser
*parser
)
7728 location_t tloc
= c_parser_peek_token (parser
)->location
;
7730 expr
= c_parser_expr_no_commas (parser
, NULL
);
7731 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7732 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7733 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7737 location_t loc
= c_parser_peek_token (parser
)->location
;
7738 location_t expr_loc
;
7739 c_parser_consume_token (parser
);
7740 expr_loc
= c_parser_peek_token (parser
)->location
;
7741 lhsval
= expr
.value
;
7742 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7743 lhsval
= TREE_OPERAND (lhsval
, 1);
7744 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7745 mark_exp_read (lhsval
);
7746 next
= c_parser_expr_no_commas (parser
, NULL
);
7747 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7748 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7749 expr
.original_code
= COMPOUND_EXPR
;
7750 expr
.original_type
= next
.original_type
;
7755 /* Parse an expression and convert functions or arrays to pointers and
7756 lvalues to rvalues. */
7758 static struct c_expr
7759 c_parser_expression_conv (c_parser
*parser
)
7762 location_t loc
= c_parser_peek_token (parser
)->location
;
7763 expr
= c_parser_expression (parser
);
7764 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7768 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7769 functions and arrays to pointers and lvalues to rvalues. If
7770 FOLD_P, fold the expressions.
7773 assignment-expression
7774 nonempty-expr-list , assignment-expression
7777 static vec
<tree
, va_gc
> *
7778 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7779 vec
<tree
, va_gc
> **p_orig_types
,
7780 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7782 vec
<tree
, va_gc
> *ret
;
7783 vec
<tree
, va_gc
> *orig_types
;
7785 location_t loc
= c_parser_peek_token (parser
)->location
;
7786 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7787 unsigned int idx
= 0;
7789 ret
= make_tree_vector ();
7790 if (p_orig_types
== NULL
)
7793 orig_types
= make_tree_vector ();
7795 if (sizeof_arg
!= NULL
7796 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7797 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7798 expr
= c_parser_expr_no_commas (parser
, NULL
);
7800 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7802 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7803 ret
->quick_push (expr
.value
);
7805 orig_types
->quick_push (expr
.original_type
);
7806 if (sizeof_arg
!= NULL
7807 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7808 && expr
.original_code
== SIZEOF_EXPR
)
7810 sizeof_arg
[0] = c_last_sizeof_arg
;
7811 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7813 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7815 c_parser_consume_token (parser
);
7816 loc
= c_parser_peek_token (parser
)->location
;
7817 if (sizeof_arg
!= NULL
7818 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7819 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7821 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7822 expr
= c_parser_expr_no_commas (parser
, NULL
);
7824 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7826 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7827 vec_safe_push (ret
, expr
.value
);
7829 vec_safe_push (orig_types
, expr
.original_type
);
7831 && sizeof_arg
!= NULL
7832 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7833 && expr
.original_code
== SIZEOF_EXPR
)
7835 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7836 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7840 *p_orig_types
= orig_types
;
7844 /* Parse Objective-C-specific constructs. */
7846 /* Parse an objc-class-definition.
7848 objc-class-definition:
7849 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7850 objc-class-instance-variables[opt] objc-methodprotolist @end
7851 @implementation identifier objc-superclass[opt]
7852 objc-class-instance-variables[opt]
7853 @interface identifier ( identifier ) objc-protocol-refs[opt]
7854 objc-methodprotolist @end
7855 @interface identifier ( ) objc-protocol-refs[opt]
7856 objc-methodprotolist @end
7857 @implementation identifier ( identifier )
7862 "@interface identifier (" must start "@interface identifier (
7863 identifier ) ...": objc-methodprotolist in the first production may
7864 not start with a parenthesized identifier as a declarator of a data
7865 definition with no declaration specifiers if the objc-superclass,
7866 objc-protocol-refs and objc-class-instance-variables are omitted. */
7869 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7874 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7876 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7881 c_parser_consume_token (parser
);
7882 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7884 c_parser_error (parser
, "expected identifier");
7887 id1
= c_parser_peek_token (parser
)->value
;
7888 c_parser_consume_token (parser
);
7889 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7891 /* We have a category or class extension. */
7893 tree proto
= NULL_TREE
;
7894 c_parser_consume_token (parser
);
7895 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7897 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7899 /* We have a class extension. */
7904 c_parser_error (parser
, "expected identifier or %<)%>");
7905 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7911 id2
= c_parser_peek_token (parser
)->value
;
7912 c_parser_consume_token (parser
);
7914 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7917 objc_start_category_implementation (id1
, id2
);
7920 if (c_parser_next_token_is (parser
, CPP_LESS
))
7921 proto
= c_parser_objc_protocol_refs (parser
);
7922 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7923 c_parser_objc_methodprotolist (parser
);
7924 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7925 objc_finish_interface ();
7928 if (c_parser_next_token_is (parser
, CPP_COLON
))
7930 c_parser_consume_token (parser
);
7931 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7933 c_parser_error (parser
, "expected identifier");
7936 superclass
= c_parser_peek_token (parser
)->value
;
7937 c_parser_consume_token (parser
);
7940 superclass
= NULL_TREE
;
7943 tree proto
= NULL_TREE
;
7944 if (c_parser_next_token_is (parser
, CPP_LESS
))
7945 proto
= c_parser_objc_protocol_refs (parser
);
7946 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7949 objc_start_class_implementation (id1
, superclass
);
7950 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7951 c_parser_objc_class_instance_variables (parser
);
7954 objc_continue_interface ();
7955 c_parser_objc_methodprotolist (parser
);
7956 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7957 objc_finish_interface ();
7961 objc_continue_implementation ();
7966 /* Parse objc-class-instance-variables.
7968 objc-class-instance-variables:
7969 { objc-instance-variable-decl-list[opt] }
7971 objc-instance-variable-decl-list:
7972 objc-visibility-spec
7973 objc-instance-variable-decl ;
7975 objc-instance-variable-decl-list objc-visibility-spec
7976 objc-instance-variable-decl-list objc-instance-variable-decl ;
7977 objc-instance-variable-decl-list ;
7979 objc-visibility-spec:
7984 objc-instance-variable-decl:
7989 c_parser_objc_class_instance_variables (c_parser
*parser
)
7991 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7992 c_parser_consume_token (parser
);
7993 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7996 /* Parse any stray semicolon. */
7997 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7999 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8001 c_parser_consume_token (parser
);
8004 /* Stop if at the end of the instance variables. */
8005 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8007 c_parser_consume_token (parser
);
8010 /* Parse any objc-visibility-spec. */
8011 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8013 c_parser_consume_token (parser
);
8014 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8017 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8019 c_parser_consume_token (parser
);
8020 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8023 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8025 c_parser_consume_token (parser
);
8026 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8029 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8031 c_parser_consume_token (parser
);
8032 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8035 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8037 c_parser_pragma (parser
, pragma_external
);
8041 /* Parse some comma-separated declarations. */
8042 decls
= c_parser_struct_declaration (parser
);
8045 /* There is a syntax error. We want to skip the offending
8046 tokens up to the next ';' (included) or '}'
8049 /* First, skip manually a ')' or ']'. This is because they
8050 reduce the nesting level, so c_parser_skip_until_found()
8051 wouldn't be able to skip past them. */
8052 c_token
*token
= c_parser_peek_token (parser
);
8053 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8054 c_parser_consume_token (parser
);
8056 /* Then, do the standard skipping. */
8057 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8059 /* We hopefully recovered. Start normal parsing again. */
8060 parser
->error
= false;
8065 /* Comma-separated instance variables are chained together
8066 in reverse order; add them one by one. */
8067 tree ivar
= nreverse (decls
);
8068 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8069 objc_add_instance_variable (copy_node (ivar
));
8071 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8075 /* Parse an objc-class-declaration.
8077 objc-class-declaration:
8078 @class identifier-list ;
8082 c_parser_objc_class_declaration (c_parser
*parser
)
8084 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8085 c_parser_consume_token (parser
);
8086 /* Any identifiers, including those declared as type names, are OK
8091 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8093 c_parser_error (parser
, "expected identifier");
8094 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8095 parser
->error
= false;
8098 id
= c_parser_peek_token (parser
)->value
;
8099 objc_declare_class (id
);
8100 c_parser_consume_token (parser
);
8101 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8102 c_parser_consume_token (parser
);
8106 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8109 /* Parse an objc-alias-declaration.
8111 objc-alias-declaration:
8112 @compatibility_alias identifier identifier ;
8116 c_parser_objc_alias_declaration (c_parser
*parser
)
8119 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8120 c_parser_consume_token (parser
);
8121 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8123 c_parser_error (parser
, "expected identifier");
8124 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8127 id1
= c_parser_peek_token (parser
)->value
;
8128 c_parser_consume_token (parser
);
8129 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8131 c_parser_error (parser
, "expected identifier");
8132 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8135 id2
= c_parser_peek_token (parser
)->value
;
8136 c_parser_consume_token (parser
);
8137 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8138 objc_declare_alias (id1
, id2
);
8141 /* Parse an objc-protocol-definition.
8143 objc-protocol-definition:
8144 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8145 @protocol identifier-list ;
8147 "@protocol identifier ;" should be resolved as "@protocol
8148 identifier-list ;": objc-methodprotolist may not start with a
8149 semicolon in the first alternative if objc-protocol-refs are
8153 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8155 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8157 c_parser_consume_token (parser
);
8158 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8160 c_parser_error (parser
, "expected identifier");
8163 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8164 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8166 /* Any identifiers, including those declared as type names, are
8171 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8173 c_parser_error (parser
, "expected identifier");
8176 id
= c_parser_peek_token (parser
)->value
;
8177 objc_declare_protocol (id
, attributes
);
8178 c_parser_consume_token (parser
);
8179 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8180 c_parser_consume_token (parser
);
8184 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8188 tree id
= c_parser_peek_token (parser
)->value
;
8189 tree proto
= NULL_TREE
;
8190 c_parser_consume_token (parser
);
8191 if (c_parser_next_token_is (parser
, CPP_LESS
))
8192 proto
= c_parser_objc_protocol_refs (parser
);
8193 parser
->objc_pq_context
= true;
8194 objc_start_protocol (id
, proto
, attributes
);
8195 c_parser_objc_methodprotolist (parser
);
8196 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8197 parser
->objc_pq_context
= false;
8198 objc_finish_interface ();
8202 /* Parse an objc-method-type.
8208 Return true if it is a class method (+) and false if it is
8209 an instance method (-).
8212 c_parser_objc_method_type (c_parser
*parser
)
8214 switch (c_parser_peek_token (parser
)->type
)
8217 c_parser_consume_token (parser
);
8220 c_parser_consume_token (parser
);
8227 /* Parse an objc-method-definition.
8229 objc-method-definition:
8230 objc-method-type objc-method-decl ;[opt] compound-statement
8234 c_parser_objc_method_definition (c_parser
*parser
)
8236 bool is_class_method
= c_parser_objc_method_type (parser
);
8237 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8238 parser
->objc_pq_context
= true;
8239 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8241 if (decl
== error_mark_node
)
8242 return; /* Bail here. */
8244 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8246 c_parser_consume_token (parser
);
8247 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8248 "extra semicolon in method definition specified");
8251 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8253 c_parser_error (parser
, "expected %<{%>");
8257 parser
->objc_pq_context
= false;
8258 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8260 add_stmt (c_parser_compound_statement (parser
));
8261 objc_finish_method_definition (current_function_decl
);
8265 /* This code is executed when we find a method definition
8266 outside of an @implementation context (or invalid for other
8267 reasons). Parse the method (to keep going) but do not emit
8270 c_parser_compound_statement (parser
);
8274 /* Parse an objc-methodprotolist.
8276 objc-methodprotolist:
8278 objc-methodprotolist objc-methodproto
8279 objc-methodprotolist declaration
8280 objc-methodprotolist ;
8284 The declaration is a data definition, which may be missing
8285 declaration specifiers under the same rules and diagnostics as
8286 other data definitions outside functions, and the stray semicolon
8287 is diagnosed the same way as a stray semicolon outside a
8291 c_parser_objc_methodprotolist (c_parser
*parser
)
8295 /* The list is terminated by @end. */
8296 switch (c_parser_peek_token (parser
)->type
)
8299 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8300 "ISO C does not allow extra %<;%> outside of a function");
8301 c_parser_consume_token (parser
);
8305 c_parser_objc_methodproto (parser
);
8308 c_parser_pragma (parser
, pragma_external
);
8313 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8315 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8316 c_parser_objc_at_property_declaration (parser
);
8317 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8319 objc_set_method_opt (true);
8320 c_parser_consume_token (parser
);
8322 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8324 objc_set_method_opt (false);
8325 c_parser_consume_token (parser
);
8328 c_parser_declaration_or_fndef (parser
, false, false, true,
8329 false, true, NULL
, vNULL
);
8335 /* Parse an objc-methodproto.
8338 objc-method-type objc-method-decl ;
8342 c_parser_objc_methodproto (c_parser
*parser
)
8344 bool is_class_method
= c_parser_objc_method_type (parser
);
8345 tree decl
, attributes
= NULL_TREE
;
8347 /* Remember protocol qualifiers in prototypes. */
8348 parser
->objc_pq_context
= true;
8349 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8351 /* Forget protocol qualifiers now. */
8352 parser
->objc_pq_context
= false;
8354 /* Do not allow the presence of attributes to hide an erroneous
8355 method implementation in the interface section. */
8356 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8358 c_parser_error (parser
, "expected %<;%>");
8362 if (decl
!= error_mark_node
)
8363 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8365 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8368 /* If we are at a position that method attributes may be present, check that
8369 there are not any parsed already (a syntax error) and then collect any
8370 specified at the current location. Finally, if new attributes were present,
8371 check that the next token is legal ( ';' for decls and '{' for defs). */
8374 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8379 c_parser_error (parser
,
8380 "method attributes must be specified at the end only");
8381 *attributes
= NULL_TREE
;
8385 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8386 *attributes
= c_parser_attributes (parser
);
8388 /* If there were no attributes here, just report any earlier error. */
8389 if (*attributes
== NULL_TREE
|| bad
)
8392 /* If the attributes are followed by a ; or {, then just report any earlier
8394 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8395 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8398 /* We've got attributes, but not at the end. */
8399 c_parser_error (parser
,
8400 "expected %<;%> or %<{%> after method attribute definition");
8404 /* Parse an objc-method-decl.
8407 ( objc-type-name ) objc-selector
8409 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8410 objc-keyword-selector objc-optparmlist
8413 objc-keyword-selector:
8415 objc-keyword-selector objc-keyword-decl
8418 objc-selector : ( objc-type-name ) identifier
8419 objc-selector : identifier
8420 : ( objc-type-name ) identifier
8424 objc-optparms objc-optellipsis
8428 objc-opt-parms , parameter-declaration
8436 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8437 tree
*attributes
, tree
*expr
)
8439 tree type
= NULL_TREE
;
8441 tree parms
= NULL_TREE
;
8442 bool ellipsis
= false;
8443 bool attr_err
= false;
8445 *attributes
= NULL_TREE
;
8446 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8448 c_parser_consume_token (parser
);
8449 type
= c_parser_objc_type_name (parser
);
8450 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8452 sel
= c_parser_objc_selector (parser
);
8453 /* If there is no selector, or a colon follows, we have an
8454 objc-keyword-selector. If there is a selector, and a colon does
8455 not follow, that selector ends the objc-method-decl. */
8456 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8459 tree list
= NULL_TREE
;
8462 tree atype
= NULL_TREE
, id
, keyworddecl
;
8463 tree param_attr
= NULL_TREE
;
8464 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8466 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8468 c_parser_consume_token (parser
);
8469 atype
= c_parser_objc_type_name (parser
);
8470 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8473 /* New ObjC allows attributes on method parameters. */
8474 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8475 param_attr
= c_parser_attributes (parser
);
8476 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8478 c_parser_error (parser
, "expected identifier");
8479 return error_mark_node
;
8481 id
= c_parser_peek_token (parser
)->value
;
8482 c_parser_consume_token (parser
);
8483 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8484 list
= chainon (list
, keyworddecl
);
8485 tsel
= c_parser_objc_selector (parser
);
8486 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8490 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8492 /* Parse the optional parameter list. Optional Objective-C
8493 method parameters follow the C syntax, and may include '...'
8494 to denote a variable number of arguments. */
8495 parms
= make_node (TREE_LIST
);
8496 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8498 struct c_parm
*parm
;
8499 c_parser_consume_token (parser
);
8500 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8503 c_parser_consume_token (parser
);
8504 attr_err
|= c_parser_objc_maybe_method_attributes
8505 (parser
, attributes
) ;
8508 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8511 parms
= chainon (parms
,
8512 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8517 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8521 c_parser_error (parser
, "objective-c method declaration is expected");
8522 return error_mark_node
;
8526 return error_mark_node
;
8528 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8531 /* Parse an objc-type-name.
8534 objc-type-qualifiers[opt] type-name
8535 objc-type-qualifiers[opt]
8537 objc-type-qualifiers:
8539 objc-type-qualifiers objc-type-qualifier
8541 objc-type-qualifier: one of
8542 in out inout bycopy byref oneway
8546 c_parser_objc_type_name (c_parser
*parser
)
8548 tree quals
= NULL_TREE
;
8549 struct c_type_name
*type_name
= NULL
;
8550 tree type
= NULL_TREE
;
8553 c_token
*token
= c_parser_peek_token (parser
);
8554 if (token
->type
== CPP_KEYWORD
8555 && (token
->keyword
== RID_IN
8556 || token
->keyword
== RID_OUT
8557 || token
->keyword
== RID_INOUT
8558 || token
->keyword
== RID_BYCOPY
8559 || token
->keyword
== RID_BYREF
8560 || token
->keyword
== RID_ONEWAY
))
8562 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8563 c_parser_consume_token (parser
);
8568 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8569 type_name
= c_parser_type_name (parser
);
8571 type
= groktypename (type_name
, NULL
, NULL
);
8573 /* If the type is unknown, and error has already been produced and
8574 we need to recover from the error. In that case, use NULL_TREE
8575 for the type, as if no type had been specified; this will use the
8576 default type ('id') which is good for error recovery. */
8577 if (type
== error_mark_node
)
8580 return build_tree_list (quals
, type
);
8583 /* Parse objc-protocol-refs.
8590 c_parser_objc_protocol_refs (c_parser
*parser
)
8592 tree list
= NULL_TREE
;
8593 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8594 c_parser_consume_token (parser
);
8595 /* Any identifiers, including those declared as type names, are OK
8600 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8602 c_parser_error (parser
, "expected identifier");
8605 id
= c_parser_peek_token (parser
)->value
;
8606 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8607 c_parser_consume_token (parser
);
8608 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8609 c_parser_consume_token (parser
);
8613 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8617 /* Parse an objc-try-catch-finally-statement.
8619 objc-try-catch-finally-statement:
8620 @try compound-statement objc-catch-list[opt]
8621 @try compound-statement objc-catch-list[opt] @finally compound-statement
8624 @catch ( objc-catch-parameter-declaration ) compound-statement
8625 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8627 objc-catch-parameter-declaration:
8628 parameter-declaration
8631 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8633 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8634 for C++. Keep them in sync. */
8637 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8639 location_t location
;
8642 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8643 c_parser_consume_token (parser
);
8644 location
= c_parser_peek_token (parser
)->location
;
8645 objc_maybe_warn_exceptions (location
);
8646 stmt
= c_parser_compound_statement (parser
);
8647 objc_begin_try_stmt (location
, stmt
);
8649 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8651 struct c_parm
*parm
;
8652 tree parameter_declaration
= error_mark_node
;
8653 bool seen_open_paren
= false;
8655 c_parser_consume_token (parser
);
8656 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8657 seen_open_paren
= true;
8658 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8660 /* We have "@catch (...)" (where the '...' are literally
8661 what is in the code). Skip the '...'.
8662 parameter_declaration is set to NULL_TREE, and
8663 objc_being_catch_clauses() knows that that means
8665 c_parser_consume_token (parser
);
8666 parameter_declaration
= NULL_TREE
;
8670 /* We have "@catch (NSException *exception)" or something
8671 like that. Parse the parameter declaration. */
8672 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8674 parameter_declaration
= error_mark_node
;
8676 parameter_declaration
= grokparm (parm
, NULL
);
8678 if (seen_open_paren
)
8679 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8682 /* If there was no open parenthesis, we are recovering from
8683 an error, and we are trying to figure out what mistake
8684 the user has made. */
8686 /* If there is an immediate closing parenthesis, the user
8687 probably forgot the opening one (ie, they typed "@catch
8688 NSException *e)". Parse the closing parenthesis and keep
8690 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8691 c_parser_consume_token (parser
);
8693 /* If these is no immediate closing parenthesis, the user
8694 probably doesn't know that parenthesis are required at
8695 all (ie, they typed "@catch NSException *e"). So, just
8696 forget about the closing parenthesis and keep going. */
8698 objc_begin_catch_clause (parameter_declaration
);
8699 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8700 c_parser_compound_statement_nostart (parser
);
8701 objc_finish_catch_clause ();
8703 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8705 c_parser_consume_token (parser
);
8706 location
= c_parser_peek_token (parser
)->location
;
8707 stmt
= c_parser_compound_statement (parser
);
8708 objc_build_finally_clause (location
, stmt
);
8710 objc_finish_try_stmt ();
8713 /* Parse an objc-synchronized-statement.
8715 objc-synchronized-statement:
8716 @synchronized ( expression ) compound-statement
8720 c_parser_objc_synchronized_statement (c_parser
*parser
)
8724 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8725 c_parser_consume_token (parser
);
8726 loc
= c_parser_peek_token (parser
)->location
;
8727 objc_maybe_warn_exceptions (loc
);
8728 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8730 struct c_expr ce
= c_parser_expression (parser
);
8731 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8733 expr
= c_fully_fold (expr
, false, NULL
);
8734 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8737 expr
= error_mark_node
;
8738 stmt
= c_parser_compound_statement (parser
);
8739 objc_build_synchronized (loc
, expr
, stmt
);
8742 /* Parse an objc-selector; return NULL_TREE without an error if the
8743 next token is not an objc-selector.
8748 enum struct union if else while do for switch case default
8749 break continue return goto asm sizeof typeof __alignof
8750 unsigned long const short volatile signed restrict _Complex
8751 in out inout bycopy byref oneway int char float double void _Bool
8754 ??? Why this selection of keywords but not, for example, storage
8755 class specifiers? */
8758 c_parser_objc_selector (c_parser
*parser
)
8760 c_token
*token
= c_parser_peek_token (parser
);
8761 tree value
= token
->value
;
8762 if (token
->type
== CPP_NAME
)
8764 c_parser_consume_token (parser
);
8767 if (token
->type
!= CPP_KEYWORD
)
8769 switch (token
->keyword
)
8813 c_parser_consume_token (parser
);
8820 /* Parse an objc-selector-arg.
8824 objc-keywordname-list
8826 objc-keywordname-list:
8828 objc-keywordname-list objc-keywordname
8836 c_parser_objc_selector_arg (c_parser
*parser
)
8838 tree sel
= c_parser_objc_selector (parser
);
8839 tree list
= NULL_TREE
;
8840 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8844 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8846 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8847 sel
= c_parser_objc_selector (parser
);
8848 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8854 /* Parse an objc-receiver.
8863 c_parser_objc_receiver (c_parser
*parser
)
8865 location_t loc
= c_parser_peek_token (parser
)->location
;
8867 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8868 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8869 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8871 tree id
= c_parser_peek_token (parser
)->value
;
8872 c_parser_consume_token (parser
);
8873 return objc_get_class_reference (id
);
8875 struct c_expr ce
= c_parser_expression (parser
);
8876 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8877 return c_fully_fold (ce
.value
, false, NULL
);
8880 /* Parse objc-message-args.
8884 objc-keywordarg-list
8886 objc-keywordarg-list:
8888 objc-keywordarg-list objc-keywordarg
8891 objc-selector : objc-keywordexpr
8896 c_parser_objc_message_args (c_parser
*parser
)
8898 tree sel
= c_parser_objc_selector (parser
);
8899 tree list
= NULL_TREE
;
8900 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8905 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8906 return error_mark_node
;
8907 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8908 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8909 sel
= c_parser_objc_selector (parser
);
8910 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8916 /* Parse an objc-keywordexpr.
8923 c_parser_objc_keywordexpr (c_parser
*parser
)
8926 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8928 if (vec_safe_length (expr_list
) == 1)
8930 /* Just return the expression, remove a level of
8932 ret
= (*expr_list
)[0];
8936 /* We have a comma expression, we will collapse later. */
8937 ret
= build_tree_list_vec (expr_list
);
8939 release_tree_vector (expr_list
);
8943 /* A check, needed in several places, that ObjC interface, implementation or
8944 method definitions are not prefixed by incorrect items. */
8946 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8947 struct c_declspecs
*specs
)
8949 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8950 || specs
->typespec_kind
!= ctsk_none
)
8952 c_parser_error (parser
,
8953 "no type or storage class may be specified here,");
8954 c_parser_skip_to_end_of_block_or_statement (parser
);
8960 /* Parse an Objective-C @property declaration. The syntax is:
8962 objc-property-declaration:
8963 '@property' objc-property-attributes[opt] struct-declaration ;
8965 objc-property-attributes:
8966 '(' objc-property-attribute-list ')'
8968 objc-property-attribute-list:
8969 objc-property-attribute
8970 objc-property-attribute-list, objc-property-attribute
8972 objc-property-attribute
8973 'getter' = identifier
8974 'setter' = identifier
8983 @property NSString *name;
8984 @property (readonly) id object;
8985 @property (retain, nonatomic, getter=getTheName) id name;
8986 @property int a, b, c;
8988 PS: This function is identical to cp_parser_objc_at_propery_declaration
8989 for C++. Keep them in sync. */
8991 c_parser_objc_at_property_declaration (c_parser
*parser
)
8993 /* The following variables hold the attributes of the properties as
8994 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8995 seen. When we see an attribute, we set them to 'true' (if they
8996 are boolean properties) or to the identifier (if they have an
8997 argument, ie, for getter and setter). Note that here we only
8998 parse the list of attributes, check the syntax and accumulate the
8999 attributes that we find. objc_add_property_declaration() will
9000 then process the information. */
9001 bool property_assign
= false;
9002 bool property_copy
= false;
9003 tree property_getter_ident
= NULL_TREE
;
9004 bool property_nonatomic
= false;
9005 bool property_readonly
= false;
9006 bool property_readwrite
= false;
9007 bool property_retain
= false;
9008 tree property_setter_ident
= NULL_TREE
;
9010 /* 'properties' is the list of properties that we read. Usually a
9011 single one, but maybe more (eg, in "@property int a, b, c;" there
9016 loc
= c_parser_peek_token (parser
)->location
;
9017 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9019 c_parser_consume_token (parser
); /* Eat '@property'. */
9021 /* Parse the optional attribute list... */
9022 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9025 c_parser_consume_token (parser
);
9027 /* Property attribute keywords are valid now. */
9028 parser
->objc_property_attr_context
= true;
9032 bool syntax_error
= false;
9033 c_token
*token
= c_parser_peek_token (parser
);
9036 if (token
->type
!= CPP_KEYWORD
)
9038 if (token
->type
== CPP_CLOSE_PAREN
)
9039 c_parser_error (parser
, "expected identifier");
9042 c_parser_consume_token (parser
);
9043 c_parser_error (parser
, "unknown property attribute");
9047 keyword
= token
->keyword
;
9048 c_parser_consume_token (parser
);
9051 case RID_ASSIGN
: property_assign
= true; break;
9052 case RID_COPY
: property_copy
= true; break;
9053 case RID_NONATOMIC
: property_nonatomic
= true; break;
9054 case RID_READONLY
: property_readonly
= true; break;
9055 case RID_READWRITE
: property_readwrite
= true; break;
9056 case RID_RETAIN
: property_retain
= true; break;
9060 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9062 if (keyword
== RID_GETTER
)
9063 c_parser_error (parser
,
9064 "missing %<=%> (after %<getter%> attribute)");
9066 c_parser_error (parser
,
9067 "missing %<=%> (after %<setter%> attribute)");
9068 syntax_error
= true;
9071 c_parser_consume_token (parser
); /* eat the = */
9072 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9074 c_parser_error (parser
, "expected identifier");
9075 syntax_error
= true;
9078 if (keyword
== RID_SETTER
)
9080 if (property_setter_ident
!= NULL_TREE
)
9081 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9083 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9084 c_parser_consume_token (parser
);
9085 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9086 c_parser_error (parser
, "setter name must terminate with %<:%>");
9088 c_parser_consume_token (parser
);
9092 if (property_getter_ident
!= NULL_TREE
)
9093 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9095 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9096 c_parser_consume_token (parser
);
9100 c_parser_error (parser
, "unknown property attribute");
9101 syntax_error
= true;
9108 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9109 c_parser_consume_token (parser
);
9113 parser
->objc_property_attr_context
= false;
9114 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9116 /* ... and the property declaration(s). */
9117 properties
= c_parser_struct_declaration (parser
);
9119 if (properties
== error_mark_node
)
9121 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9122 parser
->error
= false;
9126 if (properties
== NULL_TREE
)
9127 c_parser_error (parser
, "expected identifier");
9130 /* Comma-separated properties are chained together in
9131 reverse order; add them one by one. */
9132 properties
= nreverse (properties
);
9134 for (; properties
; properties
= TREE_CHAIN (properties
))
9135 objc_add_property_declaration (loc
, copy_node (properties
),
9136 property_readonly
, property_readwrite
,
9137 property_assign
, property_retain
,
9138 property_copy
, property_nonatomic
,
9139 property_getter_ident
, property_setter_ident
);
9142 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9143 parser
->error
= false;
9146 /* Parse an Objective-C @synthesize declaration. The syntax is:
9148 objc-synthesize-declaration:
9149 @synthesize objc-synthesize-identifier-list ;
9151 objc-synthesize-identifier-list:
9152 objc-synthesize-identifier
9153 objc-synthesize-identifier-list, objc-synthesize-identifier
9155 objc-synthesize-identifier
9157 identifier = identifier
9160 @synthesize MyProperty;
9161 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9163 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9164 for C++. Keep them in sync.
9167 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9169 tree list
= NULL_TREE
;
9171 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9172 loc
= c_parser_peek_token (parser
)->location
;
9174 c_parser_consume_token (parser
);
9177 tree property
, ivar
;
9178 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9180 c_parser_error (parser
, "expected identifier");
9181 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9182 /* Once we find the semicolon, we can resume normal parsing.
9183 We have to reset parser->error manually because
9184 c_parser_skip_until_found() won't reset it for us if the
9185 next token is precisely a semicolon. */
9186 parser
->error
= false;
9189 property
= c_parser_peek_token (parser
)->value
;
9190 c_parser_consume_token (parser
);
9191 if (c_parser_next_token_is (parser
, CPP_EQ
))
9193 c_parser_consume_token (parser
);
9194 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9196 c_parser_error (parser
, "expected identifier");
9197 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9198 parser
->error
= false;
9201 ivar
= c_parser_peek_token (parser
)->value
;
9202 c_parser_consume_token (parser
);
9206 list
= chainon (list
, build_tree_list (ivar
, property
));
9207 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9208 c_parser_consume_token (parser
);
9212 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9213 objc_add_synthesize_declaration (loc
, list
);
9216 /* Parse an Objective-C @dynamic declaration. The syntax is:
9218 objc-dynamic-declaration:
9219 @dynamic identifier-list ;
9222 @dynamic MyProperty;
9223 @dynamic MyProperty, AnotherProperty;
9225 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9226 for C++. Keep them in sync.
9229 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9231 tree list
= NULL_TREE
;
9233 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9234 loc
= c_parser_peek_token (parser
)->location
;
9236 c_parser_consume_token (parser
);
9240 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9242 c_parser_error (parser
, "expected identifier");
9243 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9244 parser
->error
= false;
9247 property
= c_parser_peek_token (parser
)->value
;
9248 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9249 c_parser_consume_token (parser
);
9250 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9251 c_parser_consume_token (parser
);
9255 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9256 objc_add_dynamic_declaration (loc
, list
);
9260 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9261 should be considered, statements. ALLOW_STMT is true if we're within
9262 the context of a function and such pragmas are to be allowed. Returns
9263 true if we actually parsed such a pragma. */
9266 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9270 id
= c_parser_peek_token (parser
)->pragma_kind
;
9271 gcc_assert (id
!= PRAGMA_NONE
);
9275 case PRAGMA_OMP_BARRIER
:
9276 if (context
!= pragma_compound
)
9278 if (context
== pragma_stmt
)
9279 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9280 "used in compound statements");
9283 c_parser_omp_barrier (parser
);
9286 case PRAGMA_OMP_FLUSH
:
9287 if (context
!= pragma_compound
)
9289 if (context
== pragma_stmt
)
9290 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9291 "used in compound statements");
9294 c_parser_omp_flush (parser
);
9297 case PRAGMA_OMP_TASKWAIT
:
9298 if (context
!= pragma_compound
)
9300 if (context
== pragma_stmt
)
9301 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9302 "used in compound statements");
9305 c_parser_omp_taskwait (parser
);
9308 case PRAGMA_OMP_TASKYIELD
:
9309 if (context
!= pragma_compound
)
9311 if (context
== pragma_stmt
)
9312 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9313 "used in compound statements");
9316 c_parser_omp_taskyield (parser
);
9319 case PRAGMA_OMP_CANCEL
:
9320 if (context
!= pragma_compound
)
9322 if (context
== pragma_stmt
)
9323 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9324 "used in compound statements");
9327 c_parser_omp_cancel (parser
);
9330 case PRAGMA_OMP_CANCELLATION_POINT
:
9331 if (context
!= pragma_compound
)
9333 if (context
== pragma_stmt
)
9334 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9335 "only be used in compound statements");
9338 c_parser_omp_cancellation_point (parser
);
9341 case PRAGMA_OMP_THREADPRIVATE
:
9342 c_parser_omp_threadprivate (parser
);
9345 case PRAGMA_OMP_TARGET
:
9346 return c_parser_omp_target (parser
, context
);
9348 case PRAGMA_OMP_END_DECLARE_TARGET
:
9349 c_parser_omp_end_declare_target (parser
);
9352 case PRAGMA_OMP_SECTION
:
9353 error_at (c_parser_peek_token (parser
)->location
,
9354 "%<#pragma omp section%> may only be used in "
9355 "%<#pragma omp sections%> construct");
9356 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9359 case PRAGMA_OMP_DECLARE_REDUCTION
:
9360 c_parser_omp_declare (parser
, context
);
9363 c_parser_consume_pragma (parser
);
9364 c_parser_skip_to_pragma_eol (parser
);
9365 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9366 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9367 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9369 c_parser_error (parser
, "for, while or do statement expected");
9372 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9373 c_parser_for_statement (parser
, true);
9374 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9375 c_parser_while_statement (parser
, true);
9377 c_parser_do_statement (parser
, true);
9380 case PRAGMA_GCC_PCH_PREPROCESS
:
9381 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9382 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9385 case PRAGMA_CILK_SIMD
:
9386 if (!c_parser_cilk_verify_simd (parser
, context
))
9388 c_parser_consume_pragma (parser
);
9389 c_parser_cilk_simd (parser
);
9393 if (id
< PRAGMA_FIRST_EXTERNAL
)
9395 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9398 c_parser_error (parser
, "expected declaration specifiers");
9399 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9402 c_parser_omp_construct (parser
);
9408 c_parser_consume_pragma (parser
);
9409 c_invoke_pragma_handler (id
);
9411 /* Skip to EOL, but suppress any error message. Those will have been
9412 generated by the handler routine through calling error, as opposed
9413 to calling c_parser_error. */
9414 parser
->error
= true;
9415 c_parser_skip_to_pragma_eol (parser
);
9420 /* The interface the pragma parsers have to the lexer. */
9423 pragma_lex (tree
*value
)
9425 c_token
*tok
= c_parser_peek_token (the_parser
);
9426 enum cpp_ttype ret
= tok
->type
;
9428 *value
= tok
->value
;
9429 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9433 if (ret
== CPP_KEYWORD
)
9435 c_parser_consume_token (the_parser
);
9442 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9446 c_parser_consume_pragma (parser
);
9447 if (c_parser_next_token_is (parser
, CPP_STRING
))
9449 name
= c_parser_peek_token (parser
)->value
;
9450 c_parser_consume_token (parser
);
9453 c_parser_error (parser
, "expected string literal");
9454 c_parser_skip_to_pragma_eol (parser
);
9457 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9460 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9462 /* Returns name of the next clause.
9463 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9464 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9465 returned and the token is consumed. */
9467 static pragma_omp_clause
9468 c_parser_omp_clause_name (c_parser
*parser
)
9470 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9472 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9473 result
= PRAGMA_OMP_CLAUSE_IF
;
9474 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9475 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9476 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9477 result
= PRAGMA_OMP_CLAUSE_FOR
;
9478 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9480 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9485 if (!strcmp ("aligned", p
))
9486 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9489 if (!strcmp ("collapse", p
))
9490 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9491 else if (!strcmp ("copyin", p
))
9492 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9493 else if (!strcmp ("copyprivate", p
))
9494 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9497 if (!strcmp ("depend", p
))
9498 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9499 else if (!strcmp ("device", p
))
9500 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9501 else if (!strcmp ("dist_schedule", p
))
9502 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9505 if (!strcmp ("final", p
))
9506 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9507 else if (!strcmp ("firstprivate", p
))
9508 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9509 else if (!strcmp ("from", p
))
9510 result
= PRAGMA_OMP_CLAUSE_FROM
;
9513 if (!strcmp ("inbranch", p
))
9514 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9517 if (!strcmp ("lastprivate", p
))
9518 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9519 else if (!strcmp ("linear", p
))
9520 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9523 if (!strcmp ("map", p
))
9524 result
= PRAGMA_OMP_CLAUSE_MAP
;
9525 else if (!strcmp ("mergeable", p
))
9526 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9529 if (!strcmp ("notinbranch", p
))
9530 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9531 else if (!strcmp ("nowait", p
))
9532 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9533 else if (!strcmp ("num_teams", p
))
9534 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9535 else if (!strcmp ("num_threads", p
))
9536 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9539 if (!strcmp ("ordered", p
))
9540 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9543 if (!strcmp ("parallel", p
))
9544 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9545 else if (!strcmp ("private", p
))
9546 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9547 else if (!strcmp ("proc_bind", p
))
9548 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9551 if (!strcmp ("reduction", p
))
9552 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9555 if (!strcmp ("safelen", p
))
9556 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9557 else if (!strcmp ("schedule", p
))
9558 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9559 else if (!strcmp ("sections", p
))
9560 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9561 else if (!strcmp ("shared", p
))
9562 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9563 else if (!strcmp ("simdlen", p
))
9564 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9567 if (!strcmp ("taskgroup", p
))
9568 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9569 else if (!strcmp ("thread_limit", p
))
9570 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9571 else if (!strcmp ("to", p
))
9572 result
= PRAGMA_OMP_CLAUSE_TO
;
9575 if (!strcmp ("uniform", p
))
9576 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9577 else if (!strcmp ("untied", p
))
9578 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9583 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9584 c_parser_consume_token (parser
);
9589 /* Validate that a clause of the given type does not already exist. */
9592 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9597 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9598 if (OMP_CLAUSE_CODE (c
) == code
)
9600 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9601 error_at (loc
, "too many %qs clauses", name
);
9609 variable-list , identifier
9611 If KIND is nonzero, create the appropriate node and install the
9612 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9613 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9615 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9616 return the list created. */
9619 c_parser_omp_variable_list (c_parser
*parser
,
9620 location_t clause_loc
,
9621 enum omp_clause_code kind
, tree list
)
9623 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9624 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9625 c_parser_error (parser
, "expected identifier");
9627 while (c_parser_next_token_is (parser
, CPP_NAME
)
9628 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9630 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9634 undeclared_variable (c_parser_peek_token (parser
)->location
,
9635 c_parser_peek_token (parser
)->value
);
9636 t
= error_mark_node
;
9639 c_parser_consume_token (parser
);
9641 if (t
== error_mark_node
)
9647 case OMP_CLAUSE_MAP
:
9648 case OMP_CLAUSE_FROM
:
9650 case OMP_CLAUSE_DEPEND
:
9651 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9653 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9655 c_parser_consume_token (parser
);
9656 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9657 low_bound
= c_parser_expression (parser
).value
;
9658 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9659 length
= integer_one_node
;
9663 if (!c_parser_require (parser
, CPP_COLON
,
9666 t
= error_mark_node
;
9669 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9670 length
= c_parser_expression (parser
).value
;
9672 /* Look for the closing `]'. */
9673 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9676 t
= error_mark_node
;
9679 t
= tree_cons (low_bound
, length
, t
);
9686 if (t
!= error_mark_node
)
9688 tree u
= build_omp_clause (clause_loc
, kind
);
9689 OMP_CLAUSE_DECL (u
) = t
;
9690 OMP_CLAUSE_CHAIN (u
) = list
;
9695 list
= tree_cons (t
, NULL_TREE
, list
);
9697 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9700 c_parser_consume_token (parser
);
9706 /* Similarly, but expect leading and trailing parenthesis. This is a very
9707 common case for omp clauses. */
9710 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9713 /* The clauses location. */
9714 location_t loc
= c_parser_peek_token (parser
)->location
;
9716 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9718 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9719 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9725 collapse ( constant-expression ) */
9728 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9730 tree c
, num
= error_mark_node
;
9734 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9736 loc
= c_parser_peek_token (parser
)->location
;
9737 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9739 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9740 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9742 if (num
== error_mark_node
)
9744 mark_exp_read (num
);
9745 num
= c_fully_fold (num
, false, NULL
);
9746 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9747 || !tree_fits_shwi_p (num
)
9748 || (n
= tree_to_shwi (num
)) <= 0
9752 "collapse argument needs positive constant integer expression");
9755 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9756 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9757 OMP_CLAUSE_CHAIN (c
) = list
;
9762 copyin ( variable-list ) */
9765 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9767 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9771 copyprivate ( variable-list ) */
9774 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9776 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9780 default ( shared | none ) */
9783 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9785 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9786 location_t loc
= c_parser_peek_token (parser
)->location
;
9789 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9791 if (c_parser_next_token_is (parser
, CPP_NAME
))
9793 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9798 if (strcmp ("none", p
) != 0)
9800 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9804 if (strcmp ("shared", p
) != 0)
9806 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9813 c_parser_consume_token (parser
);
9818 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9820 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9822 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9825 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9826 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9827 OMP_CLAUSE_CHAIN (c
) = list
;
9828 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9834 firstprivate ( variable-list ) */
9837 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9839 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9843 final ( expression ) */
9846 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9848 location_t loc
= c_parser_peek_token (parser
)->location
;
9849 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9851 tree t
= c_parser_paren_condition (parser
);
9854 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9856 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9857 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9858 OMP_CLAUSE_CHAIN (c
) = list
;
9862 c_parser_error (parser
, "expected %<(%>");
9868 if ( expression ) */
9871 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9873 location_t loc
= c_parser_peek_token (parser
)->location
;
9874 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9876 tree t
= c_parser_paren_condition (parser
);
9879 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9881 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9882 OMP_CLAUSE_IF_EXPR (c
) = t
;
9883 OMP_CLAUSE_CHAIN (c
) = list
;
9887 c_parser_error (parser
, "expected %<(%>");
9893 lastprivate ( variable-list ) */
9896 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9898 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9905 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9909 /* FIXME: Should we allow duplicates? */
9910 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9912 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9913 OMP_CLAUSE_MERGEABLE
);
9914 OMP_CLAUSE_CHAIN (c
) = list
;
9923 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9926 location_t loc
= c_parser_peek_token (parser
)->location
;
9928 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9930 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9931 OMP_CLAUSE_CHAIN (c
) = list
;
9936 num_threads ( expression ) */
9939 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9941 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9942 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9944 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9945 tree c
, t
= c_parser_expression (parser
).value
;
9947 t
= c_fully_fold (t
, false, NULL
);
9949 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9951 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9953 c_parser_error (parser
, "expected integer expression");
9957 /* Attempt to statically determine when the number isn't positive. */
9958 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9959 build_int_cst (TREE_TYPE (t
), 0));
9960 if (CAN_HAVE_LOCATION_P (c
))
9961 SET_EXPR_LOCATION (c
, expr_loc
);
9962 if (c
== boolean_true_node
)
9964 warning_at (expr_loc
, 0,
9965 "%<num_threads%> value must be positive");
9966 t
= integer_one_node
;
9969 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9971 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9972 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9973 OMP_CLAUSE_CHAIN (c
) = list
;
9984 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9988 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9990 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9991 OMP_CLAUSE_ORDERED
);
9992 OMP_CLAUSE_CHAIN (c
) = list
;
9998 private ( variable-list ) */
10001 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10003 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10007 reduction ( reduction-operator : variable-list )
10009 reduction-operator:
10010 One of: + * - & ^ | && ||
10014 reduction-operator:
10015 One of: + * - & ^ | && || max min
10019 reduction-operator:
10020 One of: + * - & ^ | && ||
10024 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10026 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10027 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10029 enum tree_code code
= ERROR_MARK
;
10030 tree reduc_id
= NULL_TREE
;
10032 switch (c_parser_peek_token (parser
)->type
)
10044 code
= BIT_AND_EXPR
;
10047 code
= BIT_XOR_EXPR
;
10050 code
= BIT_IOR_EXPR
;
10053 code
= TRUTH_ANDIF_EXPR
;
10056 code
= TRUTH_ORIF_EXPR
;
10061 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10062 if (strcmp (p
, "min") == 0)
10067 if (strcmp (p
, "max") == 0)
10072 reduc_id
= c_parser_peek_token (parser
)->value
;
10076 c_parser_error (parser
,
10077 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10078 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10079 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10082 c_parser_consume_token (parser
);
10083 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10084 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10088 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10089 OMP_CLAUSE_REDUCTION
, list
);
10090 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10092 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10093 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10094 if (code
== ERROR_MARK
10095 || !(INTEGRAL_TYPE_P (type
)
10096 || TREE_CODE (type
) == REAL_TYPE
10097 || TREE_CODE (type
) == COMPLEX_TYPE
))
10098 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10099 = c_omp_reduction_lookup (reduc_id
,
10100 TYPE_MAIN_VARIANT (type
));
10105 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10111 schedule ( schedule-kind )
10112 schedule ( schedule-kind , expression )
10115 static | dynamic | guided | runtime | auto
10119 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10122 location_t loc
= c_parser_peek_token (parser
)->location
;
10124 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10127 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10129 if (c_parser_next_token_is (parser
, CPP_NAME
))
10131 tree kind
= c_parser_peek_token (parser
)->value
;
10132 const char *p
= IDENTIFIER_POINTER (kind
);
10137 if (strcmp ("dynamic", p
) != 0)
10139 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10143 if (strcmp ("guided", p
) != 0)
10145 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10149 if (strcmp ("runtime", p
) != 0)
10151 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10158 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10159 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10160 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10161 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10165 c_parser_consume_token (parser
);
10166 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10169 c_parser_consume_token (parser
);
10171 here
= c_parser_peek_token (parser
)->location
;
10172 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10174 t
= c_fully_fold (t
, false, NULL
);
10176 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10177 error_at (here
, "schedule %<runtime%> does not take "
10178 "a %<chunk_size%> parameter");
10179 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10181 "schedule %<auto%> does not take "
10182 "a %<chunk_size%> parameter");
10183 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10184 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10186 c_parser_error (parser
, "expected integer expression");
10188 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10191 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10192 "expected %<,%> or %<)%>");
10194 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10195 OMP_CLAUSE_CHAIN (c
) = list
;
10199 c_parser_error (parser
, "invalid schedule kind");
10200 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10205 shared ( variable-list ) */
10208 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10210 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10217 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10221 /* FIXME: Should we allow duplicates? */
10222 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10224 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10225 OMP_CLAUSE_UNTIED
);
10226 OMP_CLAUSE_CHAIN (c
) = list
;
10236 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10237 enum omp_clause_code code
, tree list
)
10239 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10241 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10242 OMP_CLAUSE_CHAIN (c
) = list
;
10254 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10255 enum omp_clause_code code
, tree list
)
10257 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10258 OMP_CLAUSE_CHAIN (c
) = list
;
10264 num_teams ( expression ) */
10267 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10269 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10270 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10272 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10273 tree c
, t
= c_parser_expression (parser
).value
;
10275 t
= c_fully_fold (t
, false, NULL
);
10277 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10279 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10281 c_parser_error (parser
, "expected integer expression");
10285 /* Attempt to statically determine when the number isn't positive. */
10286 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10287 build_int_cst (TREE_TYPE (t
), 0));
10288 if (CAN_HAVE_LOCATION_P (c
))
10289 SET_EXPR_LOCATION (c
, expr_loc
);
10290 if (c
== boolean_true_node
)
10292 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10293 t
= integer_one_node
;
10296 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10298 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10299 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10300 OMP_CLAUSE_CHAIN (c
) = list
;
10308 thread_limit ( expression ) */
10311 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10313 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10314 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10316 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10317 tree c
, t
= c_parser_expression (parser
).value
;
10319 t
= c_fully_fold (t
, false, NULL
);
10321 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10323 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10325 c_parser_error (parser
, "expected integer expression");
10329 /* Attempt to statically determine when the number isn't positive. */
10330 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10331 build_int_cst (TREE_TYPE (t
), 0));
10332 if (CAN_HAVE_LOCATION_P (c
))
10333 SET_EXPR_LOCATION (c
, expr_loc
);
10334 if (c
== boolean_true_node
)
10336 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10337 t
= integer_one_node
;
10340 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10343 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10344 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10345 OMP_CLAUSE_CHAIN (c
) = list
;
10353 aligned ( variable-list )
10354 aligned ( variable-list : constant-expression ) */
10357 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10359 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10362 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10365 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10366 OMP_CLAUSE_ALIGNED
, list
);
10368 if (c_parser_next_token_is (parser
, CPP_COLON
))
10370 c_parser_consume_token (parser
);
10371 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10372 mark_exp_read (alignment
);
10373 alignment
= c_fully_fold (alignment
, false, NULL
);
10374 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10375 && TREE_CODE (alignment
) != INTEGER_CST
10376 && tree_int_cst_sgn (alignment
) != 1)
10378 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10379 "be positive constant integer expression");
10380 alignment
= NULL_TREE
;
10383 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10384 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10387 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10392 linear ( variable-list )
10393 linear ( variable-list : expression ) */
10396 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
10398 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10401 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10404 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10405 OMP_CLAUSE_LINEAR
, list
);
10407 if (c_parser_next_token_is (parser
, CPP_COLON
))
10409 c_parser_consume_token (parser
);
10410 step
= c_parser_expression (parser
).value
;
10411 mark_exp_read (step
);
10412 step
= c_fully_fold (step
, false, NULL
);
10413 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10415 error_at (clause_loc
, "%<linear%> clause step expression must "
10417 step
= integer_one_node
;
10422 step
= integer_one_node
;
10424 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10426 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10429 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10434 safelen ( constant-expression ) */
10437 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10439 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10442 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10445 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10447 t
= c_fully_fold (t
, false, NULL
);
10448 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10449 && TREE_CODE (t
) != INTEGER_CST
10450 && tree_int_cst_sgn (t
) != 1)
10452 error_at (clause_loc
, "%<safelen%> clause expression must "
10453 "be positive constant integer expression");
10457 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10458 if (t
== NULL_TREE
|| t
== error_mark_node
)
10461 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10463 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10464 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10465 OMP_CLAUSE_CHAIN (c
) = list
;
10470 simdlen ( constant-expression ) */
10473 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10475 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10478 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10481 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10483 t
= c_fully_fold (t
, false, NULL
);
10484 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10485 && TREE_CODE (t
) != INTEGER_CST
10486 && tree_int_cst_sgn (t
) != 1)
10488 error_at (clause_loc
, "%<simdlen%> clause expression must "
10489 "be positive constant integer expression");
10493 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10494 if (t
== NULL_TREE
|| t
== error_mark_node
)
10497 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10499 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10500 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10501 OMP_CLAUSE_CHAIN (c
) = list
;
10506 depend ( depend-kind: variable-list )
10509 in | out | inout */
10512 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10514 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10515 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10518 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10521 if (c_parser_next_token_is (parser
, CPP_NAME
))
10523 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10524 if (strcmp ("in", p
) == 0)
10525 kind
= OMP_CLAUSE_DEPEND_IN
;
10526 else if (strcmp ("inout", p
) == 0)
10527 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10528 else if (strcmp ("out", p
) == 0)
10529 kind
= OMP_CLAUSE_DEPEND_OUT
;
10536 c_parser_consume_token (parser
);
10537 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10540 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10541 OMP_CLAUSE_DEPEND
, list
);
10543 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10544 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10546 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10550 c_parser_error (parser
, "invalid depend kind");
10552 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10557 map ( map-kind: variable-list )
10558 map ( variable-list )
10561 alloc | to | from | tofrom */
10564 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10566 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10567 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10570 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10573 if (c_parser_next_token_is (parser
, CPP_NAME
)
10574 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10576 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10577 if (strcmp ("alloc", p
) == 0)
10578 kind
= OMP_CLAUSE_MAP_ALLOC
;
10579 else if (strcmp ("to", p
) == 0)
10580 kind
= OMP_CLAUSE_MAP_TO
;
10581 else if (strcmp ("from", p
) == 0)
10582 kind
= OMP_CLAUSE_MAP_FROM
;
10583 else if (strcmp ("tofrom", p
) == 0)
10584 kind
= OMP_CLAUSE_MAP_TOFROM
;
10587 c_parser_error (parser
, "invalid map kind");
10588 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10592 c_parser_consume_token (parser
);
10593 c_parser_consume_token (parser
);
10596 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10598 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10599 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10601 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10606 device ( expression ) */
10609 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10611 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10612 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10614 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10616 t
= c_fully_fold (t
, false, NULL
);
10618 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10620 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10622 c_parser_error (parser
, "expected integer expression");
10626 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10628 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10629 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10630 OMP_CLAUSE_CHAIN (c
) = list
;
10638 dist_schedule ( static )
10639 dist_schedule ( static , expression ) */
10642 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10644 tree c
, t
= NULL_TREE
;
10645 location_t loc
= c_parser_peek_token (parser
)->location
;
10647 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10650 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10652 c_parser_error (parser
, "invalid dist_schedule kind");
10653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10658 c_parser_consume_token (parser
);
10659 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10661 c_parser_consume_token (parser
);
10663 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10665 t
= c_fully_fold (t
, false, NULL
);
10666 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10669 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10670 "expected %<,%> or %<)%>");
10672 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10673 if (t
== error_mark_node
)
10676 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10677 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10678 OMP_CLAUSE_CHAIN (c
) = list
;
10683 proc_bind ( proc-bind-kind )
10686 master | close | spread */
10689 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10691 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10692 enum omp_clause_proc_bind_kind kind
;
10695 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10698 if (c_parser_next_token_is (parser
, CPP_NAME
))
10700 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10701 if (strcmp ("master", p
) == 0)
10702 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10703 else if (strcmp ("close", p
) == 0)
10704 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10705 else if (strcmp ("spread", p
) == 0)
10706 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10713 c_parser_consume_token (parser
);
10714 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10715 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10716 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10717 OMP_CLAUSE_CHAIN (c
) = list
;
10721 c_parser_error (parser
, "invalid proc_bind kind");
10722 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10727 to ( variable-list ) */
10730 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10732 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10736 from ( variable-list ) */
10739 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10741 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10745 uniform ( variable-list ) */
10748 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10750 /* The clauses location. */
10751 location_t loc
= c_parser_peek_token (parser
)->location
;
10753 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10755 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10757 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10762 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10763 is a bitmask in MASK. Return the list of clauses found; the result
10764 of clause default goes in *pdefault. */
10767 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10768 const char *where
, bool finish_p
= true)
10770 tree clauses
= NULL
;
10773 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10776 pragma_omp_clause c_kind
;
10777 const char *c_name
;
10778 tree prev
= clauses
;
10780 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10781 c_parser_consume_token (parser
);
10783 here
= c_parser_peek_token (parser
)->location
;
10784 c_kind
= c_parser_omp_clause_name (parser
);
10788 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10789 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10790 c_name
= "collapse";
10792 case PRAGMA_OMP_CLAUSE_COPYIN
:
10793 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10796 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10797 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10798 c_name
= "copyprivate";
10800 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10801 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10802 c_name
= "default";
10804 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
10805 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
10806 c_name
= "firstprivate";
10808 case PRAGMA_OMP_CLAUSE_FINAL
:
10809 clauses
= c_parser_omp_clause_final (parser
, clauses
);
10812 case PRAGMA_OMP_CLAUSE_IF
:
10813 clauses
= c_parser_omp_clause_if (parser
, clauses
);
10816 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
10817 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
10818 c_name
= "lastprivate";
10820 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
10821 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
10822 c_name
= "mergeable";
10824 case PRAGMA_OMP_CLAUSE_NOWAIT
:
10825 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
10828 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
10829 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
10830 c_name
= "num_threads";
10832 case PRAGMA_OMP_CLAUSE_ORDERED
:
10833 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
10834 c_name
= "ordered";
10836 case PRAGMA_OMP_CLAUSE_PRIVATE
:
10837 clauses
= c_parser_omp_clause_private (parser
, clauses
);
10838 c_name
= "private";
10840 case PRAGMA_OMP_CLAUSE_REDUCTION
:
10841 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
10842 c_name
= "reduction";
10844 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10845 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10846 c_name
= "schedule";
10848 case PRAGMA_OMP_CLAUSE_SHARED
:
10849 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10852 case PRAGMA_OMP_CLAUSE_UNTIED
:
10853 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
10856 case PRAGMA_OMP_CLAUSE_INBRANCH
:
10857 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
10859 c_name
= "inbranch";
10861 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
10862 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
10864 c_name
= "notinbranch";
10866 case PRAGMA_OMP_CLAUSE_PARALLEL
:
10868 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
10870 c_name
= "parallel";
10874 error_at (here
, "%qs must be the first clause of %qs",
10879 case PRAGMA_OMP_CLAUSE_FOR
:
10881 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
10885 goto clause_not_first
;
10887 case PRAGMA_OMP_CLAUSE_SECTIONS
:
10889 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
10891 c_name
= "sections";
10893 goto clause_not_first
;
10895 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
10897 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
10899 c_name
= "taskgroup";
10901 goto clause_not_first
;
10903 case PRAGMA_OMP_CLAUSE_TO
:
10904 clauses
= c_parser_omp_clause_to (parser
, clauses
);
10907 case PRAGMA_OMP_CLAUSE_FROM
:
10908 clauses
= c_parser_omp_clause_from (parser
, clauses
);
10911 case PRAGMA_OMP_CLAUSE_UNIFORM
:
10912 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
10913 c_name
= "uniform";
10915 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
10916 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
10917 c_name
= "num_teams";
10919 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
10920 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
10921 c_name
= "thread_limit";
10923 case PRAGMA_OMP_CLAUSE_ALIGNED
:
10924 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
10925 c_name
= "aligned";
10927 case PRAGMA_OMP_CLAUSE_LINEAR
:
10928 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
10931 case PRAGMA_OMP_CLAUSE_DEPEND
:
10932 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
10935 case PRAGMA_OMP_CLAUSE_MAP
:
10936 clauses
= c_parser_omp_clause_map (parser
, clauses
);
10939 case PRAGMA_OMP_CLAUSE_DEVICE
:
10940 clauses
= c_parser_omp_clause_device (parser
, clauses
);
10943 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
10944 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
10945 c_name
= "dist_schedule";
10947 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
10948 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
10949 c_name
= "proc_bind";
10951 case PRAGMA_OMP_CLAUSE_SAFELEN
:
10952 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
10953 c_name
= "safelen";
10955 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
10956 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
10957 c_name
= "simdlen";
10960 c_parser_error (parser
, "expected %<#pragma omp%> clause");
10966 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
10968 /* Remove the invalid clause(s) from the list to avoid
10969 confusing the rest of the compiler. */
10971 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
10976 c_parser_skip_to_pragma_eol (parser
);
10979 return c_finish_omp_clauses (clauses
);
10988 In practice, we're also interested in adding the statement to an
10989 outer node. So it is convenient if we work around the fact that
10990 c_parser_statement calls add_stmt. */
10993 c_parser_omp_structured_block (c_parser
*parser
)
10995 tree stmt
= push_stmt_list ();
10996 c_parser_statement (parser
);
10997 return pop_stmt_list (stmt
);
11001 # pragma omp atomic new-line
11005 x binop= expr | x++ | ++x | x-- | --x
11007 +, *, -, /, &, ^, |, <<, >>
11009 where x is an lvalue expression with scalar type.
11012 # pragma omp atomic new-line
11015 # pragma omp atomic read new-line
11018 # pragma omp atomic write new-line
11021 # pragma omp atomic update new-line
11024 # pragma omp atomic capture new-line
11027 # pragma omp atomic capture new-line
11035 expression-stmt | x = x binop expr
11037 v = expression-stmt
11039 { v = x; update-stmt; } | { update-stmt; v = x; }
11043 expression-stmt | x = x binop expr | x = expr binop x
11047 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11049 where x and v are lvalue expressions with scalar type.
11051 LOC is the location of the #pragma token. */
11054 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11056 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11057 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11058 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11059 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11060 struct c_expr expr
;
11062 bool structured_block
= false;
11063 bool swapped
= false;
11064 bool seq_cst
= false;
11066 if (c_parser_next_token_is (parser
, CPP_NAME
))
11068 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11070 if (!strcmp (p
, "read"))
11071 code
= OMP_ATOMIC_READ
;
11072 else if (!strcmp (p
, "write"))
11074 else if (!strcmp (p
, "update"))
11076 else if (!strcmp (p
, "capture"))
11077 code
= OMP_ATOMIC_CAPTURE_NEW
;
11081 c_parser_consume_token (parser
);
11083 if (c_parser_next_token_is (parser
, CPP_NAME
))
11085 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11086 if (!strcmp (p
, "seq_cst"))
11089 c_parser_consume_token (parser
);
11092 c_parser_skip_to_pragma_eol (parser
);
11096 case OMP_ATOMIC_READ
:
11097 case NOP_EXPR
: /* atomic write */
11098 v
= c_parser_unary_expression (parser
).value
;
11099 v
= c_fully_fold (v
, false, NULL
);
11100 if (v
== error_mark_node
)
11102 loc
= c_parser_peek_token (parser
)->location
;
11103 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11105 if (code
== NOP_EXPR
)
11106 lhs
= c_parser_expression (parser
).value
;
11108 lhs
= c_parser_unary_expression (parser
).value
;
11109 lhs
= c_fully_fold (lhs
, false, NULL
);
11110 if (lhs
== error_mark_node
)
11112 if (code
== NOP_EXPR
)
11114 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11122 case OMP_ATOMIC_CAPTURE_NEW
:
11123 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11125 c_parser_consume_token (parser
);
11126 structured_block
= true;
11130 v
= c_parser_unary_expression (parser
).value
;
11131 v
= c_fully_fold (v
, false, NULL
);
11132 if (v
== error_mark_node
)
11134 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11142 /* For structured_block case we don't know yet whether
11143 old or new x should be captured. */
11145 eloc
= c_parser_peek_token (parser
)->location
;
11146 expr
= c_parser_unary_expression (parser
);
11148 expr
= default_function_array_conversion (eloc
, expr
);
11149 unfolded_lhs
= expr
.value
;
11150 lhs
= c_fully_fold (lhs
, false, NULL
);
11152 switch (TREE_CODE (lhs
))
11156 c_parser_skip_to_end_of_block_or_statement (parser
);
11157 if (structured_block
)
11159 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11160 c_parser_consume_token (parser
);
11161 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11163 c_parser_skip_to_end_of_block_or_statement (parser
);
11164 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11165 c_parser_consume_token (parser
);
11170 case POSTINCREMENT_EXPR
:
11171 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11172 code
= OMP_ATOMIC_CAPTURE_OLD
;
11174 case PREINCREMENT_EXPR
:
11175 lhs
= TREE_OPERAND (lhs
, 0);
11176 unfolded_lhs
= NULL_TREE
;
11177 opcode
= PLUS_EXPR
;
11178 rhs
= integer_one_node
;
11181 case POSTDECREMENT_EXPR
:
11182 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11183 code
= OMP_ATOMIC_CAPTURE_OLD
;
11185 case PREDECREMENT_EXPR
:
11186 lhs
= TREE_OPERAND (lhs
, 0);
11187 unfolded_lhs
= NULL_TREE
;
11188 opcode
= MINUS_EXPR
;
11189 rhs
= integer_one_node
;
11192 case COMPOUND_EXPR
:
11193 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11194 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11195 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11196 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11197 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11198 (TREE_OPERAND (lhs
, 1), 0), 0)))
11200 /* Undo effects of boolean_increment for post {in,de}crement. */
11201 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11204 if (TREE_CODE (lhs
) == MODIFY_EXPR
11205 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11207 /* Undo effects of boolean_increment. */
11208 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11210 /* This is pre or post increment. */
11211 rhs
= TREE_OPERAND (lhs
, 1);
11212 lhs
= TREE_OPERAND (lhs
, 0);
11213 unfolded_lhs
= NULL_TREE
;
11215 if (code
== OMP_ATOMIC_CAPTURE_NEW
11216 && !structured_block
11217 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11218 code
= OMP_ATOMIC_CAPTURE_OLD
;
11221 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11222 && TREE_OPERAND (lhs
, 0)
11223 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11225 /* This is pre or post decrement. */
11226 rhs
= TREE_OPERAND (lhs
, 1);
11227 lhs
= TREE_OPERAND (lhs
, 0);
11228 unfolded_lhs
= NULL_TREE
;
11230 if (code
== OMP_ATOMIC_CAPTURE_NEW
11231 && !structured_block
11232 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11233 code
= OMP_ATOMIC_CAPTURE_OLD
;
11239 switch (c_parser_peek_token (parser
)->type
)
11242 opcode
= MULT_EXPR
;
11245 opcode
= TRUNC_DIV_EXPR
;
11248 opcode
= PLUS_EXPR
;
11251 opcode
= MINUS_EXPR
;
11253 case CPP_LSHIFT_EQ
:
11254 opcode
= LSHIFT_EXPR
;
11256 case CPP_RSHIFT_EQ
:
11257 opcode
= RSHIFT_EXPR
;
11260 opcode
= BIT_AND_EXPR
;
11263 opcode
= BIT_IOR_EXPR
;
11266 opcode
= BIT_XOR_EXPR
;
11269 c_parser_consume_token (parser
);
11270 eloc
= c_parser_peek_token (parser
)->location
;
11271 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11273 switch (TREE_CODE (rhs1
))
11276 case TRUNC_DIV_EXPR
:
11284 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11286 opcode
= TREE_CODE (rhs1
);
11287 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11288 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11291 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11293 opcode
= TREE_CODE (rhs1
);
11294 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11295 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11296 swapped
= !commutative_tree_code (opcode
);
11305 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11307 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11309 code
= OMP_ATOMIC_CAPTURE_OLD
;
11312 expr
= default_function_array_read_conversion (eloc
, expr
);
11313 unfolded_lhs1
= expr
.value
;
11314 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11316 c_parser_consume_token (parser
);
11319 if (structured_block
)
11322 expr
= default_function_array_read_conversion (eloc
, expr
);
11323 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11328 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11331 c_parser_error (parser
,
11332 "invalid operator for %<#pragma omp atomic%>");
11336 /* Arrange to pass the location of the assignment operator to
11337 c_finish_omp_atomic. */
11338 loc
= c_parser_peek_token (parser
)->location
;
11339 c_parser_consume_token (parser
);
11340 eloc
= c_parser_peek_token (parser
)->location
;
11341 expr
= c_parser_expression (parser
);
11342 expr
= default_function_array_read_conversion (eloc
, expr
);
11344 rhs
= c_fully_fold (rhs
, false, NULL
);
11348 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11350 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11352 v
= c_parser_unary_expression (parser
).value
;
11353 v
= c_fully_fold (v
, false, NULL
);
11354 if (v
== error_mark_node
)
11356 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11358 eloc
= c_parser_peek_token (parser
)->location
;
11359 expr
= c_parser_unary_expression (parser
);
11361 expr
= default_function_array_read_conversion (eloc
, expr
);
11362 unfolded_lhs1
= expr
.value
;
11363 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11364 if (lhs1
== error_mark_node
)
11367 if (structured_block
)
11369 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11370 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11373 if (unfolded_lhs
&& unfolded_lhs1
11374 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11376 error ("%<#pragma omp atomic capture%> uses two different "
11377 "expressions for memory");
11378 stmt
= error_mark_node
;
11381 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11383 if (stmt
!= error_mark_node
)
11386 if (!structured_block
)
11387 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11392 # pragma omp barrier new-line
11396 c_parser_omp_barrier (c_parser
*parser
)
11398 location_t loc
= c_parser_peek_token (parser
)->location
;
11399 c_parser_consume_pragma (parser
);
11400 c_parser_skip_to_pragma_eol (parser
);
11402 c_finish_omp_barrier (loc
);
11406 # pragma omp critical [(name)] new-line
11409 LOC is the location of the #pragma itself. */
11412 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11414 tree stmt
, name
= NULL
;
11416 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11418 c_parser_consume_token (parser
);
11419 if (c_parser_next_token_is (parser
, CPP_NAME
))
11421 name
= c_parser_peek_token (parser
)->value
;
11422 c_parser_consume_token (parser
);
11423 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11426 c_parser_error (parser
, "expected identifier");
11428 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11429 c_parser_error (parser
, "expected %<(%> or end of line");
11430 c_parser_skip_to_pragma_eol (parser
);
11432 stmt
= c_parser_omp_structured_block (parser
);
11433 return c_finish_omp_critical (loc
, stmt
, name
);
11437 # pragma omp flush flush-vars[opt] new-line
11440 ( variable-list ) */
11443 c_parser_omp_flush (c_parser
*parser
)
11445 location_t loc
= c_parser_peek_token (parser
)->location
;
11446 c_parser_consume_pragma (parser
);
11447 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11448 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11449 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11450 c_parser_error (parser
, "expected %<(%> or end of line");
11451 c_parser_skip_to_pragma_eol (parser
);
11453 c_finish_omp_flush (loc
);
11456 /* Parse the restricted form of the for statement allowed by OpenMP.
11457 The real trick here is to determine the loop control variable early
11458 so that we can push a new decl if necessary to make it private.
11459 LOC is the location of the OMP in "#pragma omp". */
11462 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11463 tree clauses
, tree
*cclauses
)
11465 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11466 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11467 bool fail
= false, open_brace_parsed
= false;
11468 int i
, collapse
= 1, nbraces
= 0;
11469 location_t for_loc
;
11470 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11472 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11473 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11474 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
11476 gcc_assert (collapse
>= 1);
11478 declv
= make_tree_vec (collapse
);
11479 initv
= make_tree_vec (collapse
);
11480 condv
= make_tree_vec (collapse
);
11481 incrv
= make_tree_vec (collapse
);
11483 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11485 c_parser_error (parser
, "for statement expected");
11488 for_loc
= c_parser_peek_token (parser
)->location
;
11489 c_parser_consume_token (parser
);
11491 for (i
= 0; i
< collapse
; i
++)
11493 int bracecount
= 0;
11495 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11498 /* Parse the initialization declaration or expression. */
11499 if (c_parser_next_tokens_start_declaration (parser
))
11502 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11503 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11505 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11508 if (DECL_INITIAL (decl
) == error_mark_node
)
11509 decl
= error_mark_node
;
11512 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11513 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11515 struct c_expr decl_exp
;
11516 struct c_expr init_exp
;
11517 location_t init_loc
;
11519 decl_exp
= c_parser_postfix_expression (parser
);
11520 decl
= decl_exp
.value
;
11522 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11524 init_loc
= c_parser_peek_token (parser
)->location
;
11525 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11526 init_exp
= default_function_array_read_conversion (init_loc
,
11528 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11529 NOP_EXPR
, init_loc
, init_exp
.value
,
11530 init_exp
.original_type
);
11531 init
= c_process_expr_stmt (init_loc
, init
);
11533 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11538 c_parser_error (parser
,
11539 "expected iteration declaration or initialization");
11540 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11546 /* Parse the loop condition. */
11548 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11550 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11551 struct c_expr cond_expr
11552 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11554 cond
= cond_expr
.value
;
11555 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11556 cond
= c_fully_fold (cond
, false, NULL
);
11557 switch (cond_expr
.original_code
)
11565 if (code
== CILK_SIMD
)
11569 /* Can't be cond = error_mark_node, because we want to preserve
11570 the location until c_finish_omp_for. */
11571 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11574 protected_set_expr_location (cond
, cond_loc
);
11576 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11578 /* Parse the increment expression. */
11580 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11582 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11584 incr
= c_process_expr_stmt (incr_loc
,
11585 c_parser_expression (parser
).value
);
11587 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11589 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11593 TREE_VEC_ELT (declv
, i
) = decl
;
11594 TREE_VEC_ELT (initv
, i
) = init
;
11595 TREE_VEC_ELT (condv
, i
) = cond
;
11596 TREE_VEC_ELT (incrv
, i
) = incr
;
11600 if (i
== collapse
- 1)
11603 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11604 in between the collapsed for loops to be still considered perfectly
11605 nested. Hopefully the final version clarifies this.
11606 For now handle (multiple) {'s and empty statements. */
11609 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11611 c_parser_consume_token (parser
);
11614 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11616 c_parser_consume_token (parser
);
11619 else if (bracecount
11620 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11621 c_parser_consume_token (parser
);
11624 c_parser_error (parser
, "not enough perfectly nested loops");
11627 open_brace_parsed
= true;
11637 nbraces
+= bracecount
;
11640 save_break
= c_break_label
;
11641 if (code
== CILK_SIMD
)
11642 c_break_label
= build_int_cst (size_type_node
, 2);
11644 c_break_label
= size_one_node
;
11645 save_cont
= c_cont_label
;
11646 c_cont_label
= NULL_TREE
;
11647 body
= push_stmt_list ();
11649 if (open_brace_parsed
)
11651 location_t here
= c_parser_peek_token (parser
)->location
;
11652 stmt
= c_begin_compound_stmt (true);
11653 c_parser_compound_statement_nostart (parser
);
11654 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11657 add_stmt (c_parser_c99_block_statement (parser
));
11660 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11661 SET_EXPR_LOCATION (t
, loc
);
11665 body
= pop_stmt_list (body
);
11666 c_break_label
= save_break
;
11667 c_cont_label
= save_cont
;
11671 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11673 c_parser_consume_token (parser
);
11676 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11677 c_parser_consume_token (parser
);
11680 c_parser_error (parser
, "collapsed loops not perfectly nested");
11683 location_t here
= c_parser_peek_token (parser
)->location
;
11684 stmt
= c_begin_compound_stmt (true);
11686 c_parser_compound_statement_nostart (parser
);
11687 body
= c_end_compound_stmt (here
, stmt
, true);
11694 /* Only bother calling c_finish_omp_for if we haven't already generated
11695 an error from the initialization parsing. */
11698 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11699 incrv
, body
, NULL
);
11702 if (cclauses
!= NULL
11703 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11706 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11707 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11708 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11709 c
= &OMP_CLAUSE_CHAIN (*c
);
11712 for (i
= 0; i
< collapse
; i
++)
11713 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11716 c
= &OMP_CLAUSE_CHAIN (*c
);
11717 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11720 "iteration variable %qD should not be firstprivate",
11721 OMP_CLAUSE_DECL (*c
));
11722 *c
= OMP_CLAUSE_CHAIN (*c
);
11726 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11727 change it to shared (decl) in
11728 OMP_PARALLEL_CLAUSES. */
11729 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11730 OMP_CLAUSE_LASTPRIVATE
);
11731 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11732 OMP_CLAUSE_CHAIN (l
) = clauses
;
11734 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11738 OMP_FOR_CLAUSES (stmt
) = clauses
;
11743 while (!for_block
->is_empty ())
11745 /* FIXME diagnostics: LOC below should be the actual location of
11746 this particular for block. We need to build a list of
11747 locations to go along with FOR_BLOCK. */
11748 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11751 release_tree_vector (for_block
);
11755 /* Helper function for OpenMP parsing, split clauses and call
11756 finish_omp_clauses on each of the set of clauses afterwards. */
11759 omp_split_clauses (location_t loc
, enum tree_code code
,
11760 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11763 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11764 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11766 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11770 #pragma omp simd simd-clause[optseq] new-line
11773 LOC is the location of the #pragma token.
11776 #define OMP_SIMD_CLAUSE_MASK \
11777 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
11778 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
11779 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
11780 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11781 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11782 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11783 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
11786 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
11787 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11789 tree block
, clauses
, ret
;
11791 strcat (p_name
, " simd");
11792 mask
|= OMP_SIMD_CLAUSE_MASK
;
11793 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
11795 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11798 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
11799 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
11802 block
= c_begin_compound_stmt (true);
11803 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
11804 block
= c_end_compound_stmt (loc
, block
, true);
11811 #pragma omp for for-clause[optseq] new-line
11815 #pragma omp for simd for-simd-clause[optseq] new-line
11818 LOC is the location of the #pragma token.
11821 #define OMP_FOR_CLAUSE_MASK \
11822 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11823 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11824 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11825 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11826 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
11827 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
11828 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11829 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11832 c_parser_omp_for (location_t loc
, c_parser
*parser
,
11833 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11835 tree block
, clauses
, ret
;
11837 strcat (p_name
, " for");
11838 mask
|= OMP_FOR_CLAUSE_MASK
;
11840 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
11842 if (c_parser_next_token_is (parser
, CPP_NAME
))
11844 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11846 if (strcmp (p
, "simd") == 0)
11848 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
11849 if (cclauses
== NULL
)
11850 cclauses
= cclauses_buf
;
11852 c_parser_consume_token (parser
);
11853 if (!flag_openmp
) /* flag_openmp_simd */
11854 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
11855 block
= c_begin_compound_stmt (true);
11856 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
11857 block
= c_end_compound_stmt (loc
, block
, true);
11858 if (ret
== NULL_TREE
)
11860 ret
= make_node (OMP_FOR
);
11861 TREE_TYPE (ret
) = void_type_node
;
11862 OMP_FOR_BODY (ret
) = block
;
11863 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11864 SET_EXPR_LOCATION (ret
, loc
);
11869 if (!flag_openmp
) /* flag_openmp_simd */
11871 c_parser_skip_to_pragma_eol (parser
);
11875 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11878 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
11879 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11882 block
= c_begin_compound_stmt (true);
11883 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
11884 block
= c_end_compound_stmt (loc
, block
, true);
11891 # pragma omp master new-line
11894 LOC is the location of the #pragma token.
11898 c_parser_omp_master (location_t loc
, c_parser
*parser
)
11900 c_parser_skip_to_pragma_eol (parser
);
11901 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
11905 # pragma omp ordered new-line
11908 LOC is the location of the #pragma itself.
11912 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
11914 c_parser_skip_to_pragma_eol (parser
);
11915 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
11921 { section-sequence }
11924 section-directive[opt] structured-block
11925 section-sequence section-directive structured-block
11927 SECTIONS_LOC is the location of the #pragma omp sections. */
11930 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
11932 tree stmt
, substmt
;
11933 bool error_suppress
= false;
11936 loc
= c_parser_peek_token (parser
)->location
;
11937 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
11939 /* Avoid skipping until the end of the block. */
11940 parser
->error
= false;
11944 stmt
= push_stmt_list ();
11946 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
11948 substmt
= c_parser_omp_structured_block (parser
);
11949 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11950 SET_EXPR_LOCATION (substmt
, loc
);
11951 add_stmt (substmt
);
11956 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11958 if (c_parser_next_token_is (parser
, CPP_EOF
))
11961 loc
= c_parser_peek_token (parser
)->location
;
11962 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
11964 c_parser_consume_pragma (parser
);
11965 c_parser_skip_to_pragma_eol (parser
);
11966 error_suppress
= false;
11968 else if (!error_suppress
)
11970 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
11971 error_suppress
= true;
11974 substmt
= c_parser_omp_structured_block (parser
);
11975 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11976 SET_EXPR_LOCATION (substmt
, loc
);
11977 add_stmt (substmt
);
11979 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
11980 "expected %<#pragma omp section%> or %<}%>");
11982 substmt
= pop_stmt_list (stmt
);
11984 stmt
= make_node (OMP_SECTIONS
);
11985 SET_EXPR_LOCATION (stmt
, sections_loc
);
11986 TREE_TYPE (stmt
) = void_type_node
;
11987 OMP_SECTIONS_BODY (stmt
) = substmt
;
11989 return add_stmt (stmt
);
11993 # pragma omp sections sections-clause[optseq] newline
11996 LOC is the location of the #pragma token.
11999 #define OMP_SECTIONS_CLAUSE_MASK \
12000 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12001 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12002 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12003 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12004 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12007 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12008 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12010 tree block
, clauses
, ret
;
12012 strcat (p_name
, " sections");
12013 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12015 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12017 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12020 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12021 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12024 block
= c_begin_compound_stmt (true);
12025 ret
= c_parser_omp_sections_scope (loc
, parser
);
12027 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12028 block
= c_end_compound_stmt (loc
, block
, true);
12035 # pragma omp parallel parallel-clause[optseq] new-line
12037 # pragma omp parallel for parallel-for-clause[optseq] new-line
12039 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12043 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12046 LOC is the location of the #pragma token.
12049 #define OMP_PARALLEL_CLAUSE_MASK \
12050 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
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_DEFAULT) \
12054 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12055 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12056 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12057 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12058 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12061 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12062 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12064 tree stmt
, clauses
, block
;
12066 strcat (p_name
, " parallel");
12067 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12069 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12071 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12072 if (cclauses
== NULL
)
12073 cclauses
= cclauses_buf
;
12075 c_parser_consume_token (parser
);
12076 if (!flag_openmp
) /* flag_openmp_simd */
12077 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12078 block
= c_begin_omp_parallel ();
12079 c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12081 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12083 OMP_PARALLEL_COMBINED (stmt
) = 1;
12088 error_at (loc
, "expected %<for%> after %qs", p_name
);
12089 c_parser_skip_to_pragma_eol (parser
);
12092 else if (!flag_openmp
) /* flag_openmp_simd */
12094 c_parser_skip_to_pragma_eol (parser
);
12097 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12099 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12100 if (strcmp (p
, "sections") == 0)
12102 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12103 if (cclauses
== NULL
)
12104 cclauses
= cclauses_buf
;
12106 c_parser_consume_token (parser
);
12107 block
= c_begin_omp_parallel ();
12108 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12109 stmt
= c_finish_omp_parallel (loc
,
12110 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12112 OMP_PARALLEL_COMBINED (stmt
) = 1;
12117 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12119 block
= c_begin_omp_parallel ();
12120 c_parser_statement (parser
);
12121 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12127 # pragma omp single single-clause[optseq] new-line
12130 LOC is the location of the #pragma.
12133 #define OMP_SINGLE_CLAUSE_MASK \
12134 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12135 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12136 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12137 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12140 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12142 tree stmt
= make_node (OMP_SINGLE
);
12143 SET_EXPR_LOCATION (stmt
, loc
);
12144 TREE_TYPE (stmt
) = void_type_node
;
12146 OMP_SINGLE_CLAUSES (stmt
)
12147 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12148 "#pragma omp single");
12149 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12151 return add_stmt (stmt
);
12155 # pragma omp task task-clause[optseq] new-line
12157 LOC is the location of the #pragma.
12160 #define OMP_TASK_CLAUSE_MASK \
12161 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12162 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12163 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12164 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12165 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12166 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12167 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12168 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12169 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12172 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12174 tree clauses
, block
;
12176 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12177 "#pragma omp task");
12179 block
= c_begin_omp_task ();
12180 c_parser_statement (parser
);
12181 return c_finish_omp_task (loc
, clauses
, block
);
12185 # pragma omp taskwait new-line
12189 c_parser_omp_taskwait (c_parser
*parser
)
12191 location_t loc
= c_parser_peek_token (parser
)->location
;
12192 c_parser_consume_pragma (parser
);
12193 c_parser_skip_to_pragma_eol (parser
);
12195 c_finish_omp_taskwait (loc
);
12199 # pragma omp taskyield new-line
12203 c_parser_omp_taskyield (c_parser
*parser
)
12205 location_t loc
= c_parser_peek_token (parser
)->location
;
12206 c_parser_consume_pragma (parser
);
12207 c_parser_skip_to_pragma_eol (parser
);
12209 c_finish_omp_taskyield (loc
);
12213 # pragma omp taskgroup new-line
12217 c_parser_omp_taskgroup (c_parser
*parser
)
12219 location_t loc
= c_parser_peek_token (parser
)->location
;
12220 c_parser_skip_to_pragma_eol (parser
);
12221 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12225 # pragma omp cancel cancel-clause[optseq] new-line
12227 LOC is the location of the #pragma.
12230 #define OMP_CANCEL_CLAUSE_MASK \
12231 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12232 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12233 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12234 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12235 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12238 c_parser_omp_cancel (c_parser
*parser
)
12240 location_t loc
= c_parser_peek_token (parser
)->location
;
12242 c_parser_consume_pragma (parser
);
12243 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12244 "#pragma omp cancel");
12246 c_finish_omp_cancel (loc
, clauses
);
12250 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12252 LOC is the location of the #pragma.
12255 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12256 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12257 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12258 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12259 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12262 c_parser_omp_cancellation_point (c_parser
*parser
)
12264 location_t loc
= c_parser_peek_token (parser
)->location
;
12266 bool point_seen
= false;
12268 c_parser_consume_pragma (parser
);
12269 if (c_parser_next_token_is (parser
, CPP_NAME
))
12271 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12272 if (strcmp (p
, "point") == 0)
12274 c_parser_consume_token (parser
);
12280 c_parser_error (parser
, "expected %<point%>");
12281 c_parser_skip_to_pragma_eol (parser
);
12286 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12287 "#pragma omp cancellation point");
12289 c_finish_omp_cancellation_point (loc
, clauses
);
12293 #pragma omp distribute distribute-clause[optseq] new-line
12296 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12297 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12298 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12299 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12303 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12304 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12306 tree clauses
, block
, ret
;
12308 strcat (p_name
, " distribute");
12309 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12311 if (c_parser_next_token_is (parser
, CPP_NAME
))
12313 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12315 bool parallel
= false;
12317 if (strcmp (p
, "simd") == 0)
12320 parallel
= strcmp (p
, "parallel") == 0;
12321 if (parallel
|| simd
)
12323 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12324 if (cclauses
== NULL
)
12325 cclauses
= cclauses_buf
;
12326 c_parser_consume_token (parser
);
12327 if (!flag_openmp
) /* flag_openmp_simd */
12330 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12332 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12335 block
= c_begin_compound_stmt (true);
12337 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12339 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12340 block
= c_end_compound_stmt (loc
, block
, true);
12343 ret
= make_node (OMP_DISTRIBUTE
);
12344 TREE_TYPE (ret
) = void_type_node
;
12345 OMP_FOR_BODY (ret
) = block
;
12346 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12347 SET_EXPR_LOCATION (ret
, loc
);
12352 if (!flag_openmp
) /* flag_openmp_simd */
12354 c_parser_skip_to_pragma_eol (parser
);
12358 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12361 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12362 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12365 block
= c_begin_compound_stmt (true);
12366 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12367 block
= c_end_compound_stmt (loc
, block
, true);
12374 # pragma omp teams teams-clause[optseq] new-line
12375 structured-block */
12377 #define OMP_TEAMS_CLAUSE_MASK \
12378 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12379 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12380 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12381 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12382 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12383 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12384 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12387 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12388 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12390 tree clauses
, block
, ret
;
12392 strcat (p_name
, " teams");
12393 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12395 if (c_parser_next_token_is (parser
, CPP_NAME
))
12397 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12398 if (strcmp (p
, "distribute") == 0)
12400 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12401 if (cclauses
== NULL
)
12402 cclauses
= cclauses_buf
;
12404 c_parser_consume_token (parser
);
12405 if (!flag_openmp
) /* flag_openmp_simd */
12406 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12407 block
= c_begin_compound_stmt (true);
12408 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12409 block
= c_end_compound_stmt (loc
, block
, true);
12412 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12413 ret
= make_node (OMP_TEAMS
);
12414 TREE_TYPE (ret
) = void_type_node
;
12415 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12416 OMP_TEAMS_BODY (ret
) = block
;
12417 return add_stmt (ret
);
12420 if (!flag_openmp
) /* flag_openmp_simd */
12422 c_parser_skip_to_pragma_eol (parser
);
12426 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12429 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12430 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12433 tree stmt
= make_node (OMP_TEAMS
);
12434 TREE_TYPE (stmt
) = void_type_node
;
12435 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12436 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12438 return add_stmt (stmt
);
12442 # pragma omp target data target-data-clause[optseq] new-line
12443 structured-block */
12445 #define OMP_TARGET_DATA_CLAUSE_MASK \
12446 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12447 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12448 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12451 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12453 tree stmt
= make_node (OMP_TARGET_DATA
);
12454 TREE_TYPE (stmt
) = void_type_node
;
12456 OMP_TARGET_DATA_CLAUSES (stmt
)
12457 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12458 "#pragma omp target data");
12459 keep_next_level ();
12460 tree block
= c_begin_compound_stmt (true);
12461 add_stmt (c_parser_omp_structured_block (parser
));
12462 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12464 SET_EXPR_LOCATION (stmt
, loc
);
12465 return add_stmt (stmt
);
12469 # pragma omp target update target-update-clause[optseq] new-line */
12471 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12472 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12473 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12474 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12475 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12478 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12479 enum pragma_context context
)
12481 if (context
== pragma_stmt
)
12484 "%<#pragma omp target update%> may only be "
12485 "used in compound statements");
12486 c_parser_skip_to_pragma_eol (parser
);
12491 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12492 "#pragma omp target update");
12493 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12494 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12497 "%<#pragma omp target update must contain at least one "
12498 "%<from%> or %<to%> clauses");
12502 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12503 TREE_TYPE (stmt
) = void_type_node
;
12504 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12505 SET_EXPR_LOCATION (stmt
, loc
);
12511 # pragma omp target target-clause[optseq] new-line
12512 structured-block */
12514 #define OMP_TARGET_CLAUSE_MASK \
12515 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12520 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12522 location_t loc
= c_parser_peek_token (parser
)->location
;
12523 c_parser_consume_pragma (parser
);
12525 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12527 c_parser_error (parser
, "expected declaration specifiers");
12528 c_parser_skip_to_pragma_eol (parser
);
12532 if (c_parser_next_token_is (parser
, CPP_NAME
))
12534 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12536 if (strcmp (p
, "teams") == 0)
12538 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12539 char p_name
[sizeof ("#pragma omp target teams distribute "
12540 "parallel for simd")];
12542 c_parser_consume_token (parser
);
12543 strcpy (p_name
, "#pragma omp target");
12544 if (!flag_openmp
) /* flag_openmp_simd */
12545 return c_parser_omp_teams (loc
, parser
, p_name
,
12546 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12547 keep_next_level ();
12548 tree block
= c_begin_compound_stmt (true);
12549 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12550 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12551 block
= c_end_compound_stmt (loc
, block
, true);
12554 tree stmt
= make_node (OMP_TARGET
);
12555 TREE_TYPE (stmt
) = void_type_node
;
12556 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12557 OMP_TARGET_BODY (stmt
) = block
;
12561 else if (!flag_openmp
) /* flag_openmp_simd */
12563 c_parser_skip_to_pragma_eol (parser
);
12566 else if (strcmp (p
, "data") == 0)
12568 c_parser_consume_token (parser
);
12569 c_parser_omp_target_data (loc
, parser
);
12572 else if (strcmp (p
, "update") == 0)
12574 c_parser_consume_token (parser
);
12575 return c_parser_omp_target_update (loc
, parser
, context
);
12579 tree stmt
= make_node (OMP_TARGET
);
12580 TREE_TYPE (stmt
) = void_type_node
;
12582 OMP_TARGET_CLAUSES (stmt
)
12583 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12584 "#pragma omp target");
12585 keep_next_level ();
12586 tree block
= c_begin_compound_stmt (true);
12587 add_stmt (c_parser_omp_structured_block (parser
));
12588 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12590 SET_EXPR_LOCATION (stmt
, loc
);
12596 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12598 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12599 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12600 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12601 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12602 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12603 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12607 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12609 vec
<c_token
> clauses
= vNULL
;
12610 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12612 c_token
*token
= c_parser_peek_token (parser
);
12613 if (token
->type
== CPP_EOF
)
12615 c_parser_skip_to_pragma_eol (parser
);
12616 clauses
.release ();
12619 clauses
.safe_push (*token
);
12620 c_parser_consume_token (parser
);
12622 clauses
.safe_push (*c_parser_peek_token (parser
));
12623 c_parser_skip_to_pragma_eol (parser
);
12625 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12627 if (c_parser_peek_token (parser
)->pragma_kind
12628 != PRAGMA_OMP_DECLARE_REDUCTION
12629 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12630 || strcmp (IDENTIFIER_POINTER
12631 (c_parser_peek_2nd_token (parser
)->value
),
12634 c_parser_error (parser
,
12635 "%<#pragma omp declare simd%> must be followed by "
12636 "function declaration or definition or another "
12637 "%<#pragma omp declare simd%>");
12638 clauses
.release ();
12641 c_parser_consume_pragma (parser
);
12642 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12644 c_token
*token
= c_parser_peek_token (parser
);
12645 if (token
->type
== CPP_EOF
)
12647 c_parser_skip_to_pragma_eol (parser
);
12648 clauses
.release ();
12651 clauses
.safe_push (*token
);
12652 c_parser_consume_token (parser
);
12654 clauses
.safe_push (*c_parser_peek_token (parser
));
12655 c_parser_skip_to_pragma_eol (parser
);
12658 /* Make sure nothing tries to read past the end of the tokens. */
12660 memset (&eof_token
, 0, sizeof (eof_token
));
12661 eof_token
.type
= CPP_EOF
;
12662 clauses
.safe_push (eof_token
);
12663 clauses
.safe_push (eof_token
);
12667 case pragma_external
:
12668 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12669 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12671 int ext
= disable_extension_diagnostics ();
12673 c_parser_consume_token (parser
);
12674 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12675 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12676 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12678 restore_extension_diagnostics (ext
);
12681 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12684 case pragma_struct
:
12686 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12687 "function declaration or definition");
12689 case pragma_compound
:
12691 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12692 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12694 int ext
= disable_extension_diagnostics ();
12696 c_parser_consume_token (parser
);
12697 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12698 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12699 if (c_parser_next_tokens_start_declaration (parser
))
12701 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12702 true, NULL
, clauses
);
12703 restore_extension_diagnostics (ext
);
12706 restore_extension_diagnostics (ext
);
12708 else if (c_parser_next_tokens_start_declaration (parser
))
12710 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12714 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12715 "function declaration or definition");
12718 gcc_unreachable ();
12720 clauses
.release ();
12723 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12724 and put that into "omp declare simd" attribute. */
12727 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12728 vec
<c_token
> clauses
)
12730 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12731 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12732 has already processed the tokens. */
12733 if (clauses
[0].type
== CPP_EOF
)
12735 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12737 error ("%<#pragma omp declare simd%> not immediately followed by "
12738 "a function declaration or definition");
12739 clauses
[0].type
= CPP_EOF
;
12742 if (clauses
[0].type
!= CPP_NAME
)
12744 error_at (DECL_SOURCE_LOCATION (fndecl
),
12745 "%<#pragma omp declare simd%> not immediately followed by "
12746 "a single function declaration or definition");
12747 clauses
[0].type
= CPP_EOF
;
12751 if (parms
== NULL_TREE
)
12752 parms
= DECL_ARGUMENTS (fndecl
);
12754 unsigned int tokens_avail
= parser
->tokens_avail
;
12755 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12756 parser
->tokens
= clauses
.address ();
12757 parser
->tokens_avail
= clauses
.length ();
12759 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12760 while (parser
->tokens_avail
> 3)
12762 c_token
*token
= c_parser_peek_token (parser
);
12763 gcc_assert (token
->type
== CPP_NAME
12764 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12765 c_parser_consume_token (parser
);
12766 parser
->in_pragma
= true;
12768 tree c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12769 "#pragma omp declare simd");
12770 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12771 if (c
!= NULL_TREE
)
12772 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12773 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12774 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12775 DECL_ATTRIBUTES (fndecl
) = c
;
12778 parser
->tokens
= &parser
->tokens_buf
[0];
12779 parser
->tokens_avail
= tokens_avail
;
12780 clauses
[0].type
= CPP_PRAGMA
;
12785 # pragma omp declare target new-line
12786 declarations and definitions
12787 # pragma omp end declare target new-line */
12790 c_parser_omp_declare_target (c_parser
*parser
)
12792 c_parser_skip_to_pragma_eol (parser
);
12793 current_omp_declare_target_attribute
++;
12797 c_parser_omp_end_declare_target (c_parser
*parser
)
12799 location_t loc
= c_parser_peek_token (parser
)->location
;
12800 c_parser_consume_pragma (parser
);
12801 if (c_parser_next_token_is (parser
, CPP_NAME
)
12802 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12805 c_parser_consume_token (parser
);
12806 if (c_parser_next_token_is (parser
, CPP_NAME
)
12807 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12809 c_parser_consume_token (parser
);
12812 c_parser_error (parser
, "expected %<target%>");
12813 c_parser_skip_to_pragma_eol (parser
);
12819 c_parser_error (parser
, "expected %<declare%>");
12820 c_parser_skip_to_pragma_eol (parser
);
12823 c_parser_skip_to_pragma_eol (parser
);
12824 if (!current_omp_declare_target_attribute
)
12825 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
12826 "%<#pragma omp declare target%>");
12828 current_omp_declare_target_attribute
--;
12833 #pragma omp declare reduction (reduction-id : typename-list : expression) \
12834 initializer-clause[opt] new-line
12836 initializer-clause:
12837 initializer (omp_priv = initializer)
12838 initializer (function-name (argument-list)) */
12841 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
12843 unsigned int tokens_avail
= 0, i
;
12844 vec
<tree
> types
= vNULL
;
12845 vec
<c_token
> clauses
= vNULL
;
12846 enum tree_code reduc_code
= ERROR_MARK
;
12847 tree reduc_id
= NULL_TREE
;
12849 location_t rloc
= c_parser_peek_token (parser
)->location
;
12851 if (context
== pragma_struct
|| context
== pragma_param
)
12853 error ("%<#pragma omp declare reduction%> not at file or block scope");
12857 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12860 switch (c_parser_peek_token (parser
)->type
)
12863 reduc_code
= PLUS_EXPR
;
12866 reduc_code
= MULT_EXPR
;
12869 reduc_code
= MINUS_EXPR
;
12872 reduc_code
= BIT_AND_EXPR
;
12875 reduc_code
= BIT_XOR_EXPR
;
12878 reduc_code
= BIT_IOR_EXPR
;
12881 reduc_code
= TRUTH_ANDIF_EXPR
;
12884 reduc_code
= TRUTH_ORIF_EXPR
;
12888 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12889 if (strcmp (p
, "min") == 0)
12891 reduc_code
= MIN_EXPR
;
12894 if (strcmp (p
, "max") == 0)
12896 reduc_code
= MAX_EXPR
;
12899 reduc_id
= c_parser_peek_token (parser
)->value
;
12902 c_parser_error (parser
,
12903 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12904 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
12908 tree orig_reduc_id
, reduc_decl
;
12909 orig_reduc_id
= reduc_id
;
12910 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
12911 reduc_decl
= c_omp_reduction_decl (reduc_id
);
12912 c_parser_consume_token (parser
);
12914 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12919 location_t loc
= c_parser_peek_token (parser
)->location
;
12920 struct c_type_name
*ctype
= c_parser_type_name (parser
);
12923 type
= groktypename (ctype
, NULL
, NULL
);
12924 if (type
== error_mark_node
)
12926 else if ((INTEGRAL_TYPE_P (type
)
12927 || TREE_CODE (type
) == REAL_TYPE
12928 || TREE_CODE (type
) == COMPLEX_TYPE
)
12929 && orig_reduc_id
== NULL_TREE
)
12930 error_at (loc
, "predeclared arithmetic type in "
12931 "%<#pragma omp declare reduction%>");
12932 else if (TREE_CODE (type
) == FUNCTION_TYPE
12933 || TREE_CODE (type
) == ARRAY_TYPE
)
12934 error_at (loc
, "function or array type in "
12935 "%<#pragma omp declare reduction%>");
12936 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
12937 error_at (loc
, "const, volatile or restrict qualified type in "
12938 "%<#pragma omp declare reduction%>");
12942 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
12943 if (comptypes (TREE_PURPOSE (t
), type
))
12945 error_at (loc
, "redeclaration of %qs "
12946 "%<#pragma omp declare reduction%> for "
12948 IDENTIFIER_POINTER (reduc_id
)
12949 + sizeof ("omp declare reduction ") - 1,
12952 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
12954 error_at (ploc
, "previous %<#pragma omp declare "
12958 if (t
== NULL_TREE
)
12959 types
.safe_push (type
);
12961 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12962 c_parser_consume_token (parser
);
12970 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
12971 || types
.is_empty ())
12974 clauses
.release ();
12978 c_token
*token
= c_parser_peek_token (parser
);
12979 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
12981 c_parser_consume_token (parser
);
12983 c_parser_skip_to_pragma_eol (parser
);
12987 if (types
.length () > 1)
12989 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12991 c_token
*token
= c_parser_peek_token (parser
);
12992 if (token
->type
== CPP_EOF
)
12994 clauses
.safe_push (*token
);
12995 c_parser_consume_token (parser
);
12997 clauses
.safe_push (*c_parser_peek_token (parser
));
12998 c_parser_skip_to_pragma_eol (parser
);
13000 /* Make sure nothing tries to read past the end of the tokens. */
13002 memset (&eof_token
, 0, sizeof (eof_token
));
13003 eof_token
.type
= CPP_EOF
;
13004 clauses
.safe_push (eof_token
);
13005 clauses
.safe_push (eof_token
);
13008 int errs
= errorcount
;
13009 FOR_EACH_VEC_ELT (types
, i
, type
)
13011 tokens_avail
= parser
->tokens_avail
;
13012 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13013 if (!clauses
.is_empty ())
13015 parser
->tokens
= clauses
.address ();
13016 parser
->tokens_avail
= clauses
.length ();
13017 parser
->in_pragma
= true;
13020 bool nested
= current_function_decl
!= NULL_TREE
;
13022 c_push_function_context ();
13023 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13024 reduc_id
, default_function_type
);
13025 current_function_decl
= fndecl
;
13026 allocate_struct_function (fndecl
, true);
13028 tree stmt
= push_stmt_list ();
13029 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13030 warn about these. */
13031 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13032 get_identifier ("omp_out"), type
);
13033 DECL_ARTIFICIAL (omp_out
) = 1;
13034 DECL_CONTEXT (omp_out
) = fndecl
;
13035 pushdecl (omp_out
);
13036 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13037 get_identifier ("omp_in"), type
);
13038 DECL_ARTIFICIAL (omp_in
) = 1;
13039 DECL_CONTEXT (omp_in
) = fndecl
;
13041 struct c_expr combiner
= c_parser_expression (parser
);
13042 struct c_expr initializer
;
13043 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13045 initializer
.value
= error_mark_node
;
13046 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13048 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13049 && strcmp (IDENTIFIER_POINTER
13050 (c_parser_peek_token (parser
)->value
),
13051 "initializer") == 0)
13053 c_parser_consume_token (parser
);
13056 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13057 get_identifier ("omp_priv"), type
);
13058 DECL_ARTIFICIAL (omp_priv
) = 1;
13059 DECL_INITIAL (omp_priv
) = error_mark_node
;
13060 DECL_CONTEXT (omp_priv
) = fndecl
;
13061 pushdecl (omp_priv
);
13062 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13063 get_identifier ("omp_orig"), type
);
13064 DECL_ARTIFICIAL (omp_orig
) = 1;
13065 DECL_CONTEXT (omp_orig
) = fndecl
;
13066 pushdecl (omp_orig
);
13067 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13069 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13071 c_parser_error (parser
, "expected %<omp_priv%> or "
13075 else if (strcmp (IDENTIFIER_POINTER
13076 (c_parser_peek_token (parser
)->value
),
13079 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13080 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13082 c_parser_error (parser
, "expected function-name %<(%>");
13086 initializer
= c_parser_postfix_expression (parser
);
13087 if (initializer
.value
13088 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13091 tree c
= initializer
.value
;
13092 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13093 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13094 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13096 if (j
== call_expr_nargs (c
))
13097 error ("one of the initializer call arguments should be "
13103 c_parser_consume_token (parser
);
13104 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13108 tree st
= push_stmt_list ();
13109 start_init (omp_priv
, NULL_TREE
, 0);
13110 location_t loc
= c_parser_peek_token (parser
)->location
;
13111 struct c_expr init
= c_parser_initializer (parser
);
13113 finish_decl (omp_priv
, loc
, init
.value
,
13114 init
.original_type
, NULL_TREE
);
13115 pop_stmt_list (st
);
13119 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13125 c_parser_skip_to_pragma_eol (parser
);
13127 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13128 DECL_INITIAL (reduc_decl
));
13129 DECL_INITIAL (reduc_decl
) = t
;
13130 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13131 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13132 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13133 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13134 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13135 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13138 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13139 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13140 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13141 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13142 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13143 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13144 walk_tree (&DECL_INITIAL (omp_priv
),
13145 c_check_omp_declare_reduction_r
,
13146 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13150 pop_stmt_list (stmt
);
13152 if (cfun
->language
!= NULL
)
13154 ggc_free (cfun
->language
);
13155 cfun
->language
= NULL
;
13158 current_function_decl
= NULL_TREE
;
13160 c_pop_function_context ();
13162 if (!clauses
.is_empty ())
13164 parser
->tokens
= &parser
->tokens_buf
[0];
13165 parser
->tokens_avail
= tokens_avail
;
13169 if (errs
!= errorcount
)
13173 clauses
.release ();
13179 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13180 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13181 initializer-clause[opt] new-line
13182 #pragma omp declare target new-line */
13185 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13187 c_parser_consume_pragma (parser
);
13188 if (c_parser_next_token_is (parser
, CPP_NAME
))
13190 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13191 if (strcmp (p
, "simd") == 0)
13193 /* c_parser_consume_token (parser); done in
13194 c_parser_omp_declare_simd. */
13195 c_parser_omp_declare_simd (parser
, context
);
13198 if (strcmp (p
, "reduction") == 0)
13200 c_parser_consume_token (parser
);
13201 c_parser_omp_declare_reduction (parser
, context
);
13204 if (!flag_openmp
) /* flag_openmp_simd */
13206 c_parser_skip_to_pragma_eol (parser
);
13209 if (strcmp (p
, "target") == 0)
13211 c_parser_consume_token (parser
);
13212 c_parser_omp_declare_target (parser
);
13217 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13219 c_parser_skip_to_pragma_eol (parser
);
13222 /* Main entry point to parsing most OpenMP pragmas. */
13225 c_parser_omp_construct (c_parser
*parser
)
13227 enum pragma_kind p_kind
;
13230 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13231 omp_clause_mask
mask (0);
13233 loc
= c_parser_peek_token (parser
)->location
;
13234 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13235 c_parser_consume_pragma (parser
);
13239 case PRAGMA_OMP_ATOMIC
:
13240 c_parser_omp_atomic (loc
, parser
);
13242 case PRAGMA_OMP_CRITICAL
:
13243 stmt
= c_parser_omp_critical (loc
, parser
);
13245 case PRAGMA_OMP_DISTRIBUTE
:
13246 strcpy (p_name
, "#pragma omp");
13247 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13249 case PRAGMA_OMP_FOR
:
13250 strcpy (p_name
, "#pragma omp");
13251 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13253 case PRAGMA_OMP_MASTER
:
13254 stmt
= c_parser_omp_master (loc
, parser
);
13256 case PRAGMA_OMP_ORDERED
:
13257 stmt
= c_parser_omp_ordered (loc
, parser
);
13259 case PRAGMA_OMP_PARALLEL
:
13260 strcpy (p_name
, "#pragma omp");
13261 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13263 case PRAGMA_OMP_SECTIONS
:
13264 strcpy (p_name
, "#pragma omp");
13265 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13267 case PRAGMA_OMP_SIMD
:
13268 strcpy (p_name
, "#pragma omp");
13269 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13271 case PRAGMA_OMP_SINGLE
:
13272 stmt
= c_parser_omp_single (loc
, parser
);
13274 case PRAGMA_OMP_TASK
:
13275 stmt
= c_parser_omp_task (loc
, parser
);
13277 case PRAGMA_OMP_TASKGROUP
:
13278 stmt
= c_parser_omp_taskgroup (parser
);
13280 case PRAGMA_OMP_TEAMS
:
13281 strcpy (p_name
, "#pragma omp");
13282 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13285 gcc_unreachable ();
13289 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13294 # pragma omp threadprivate (variable-list) */
13297 c_parser_omp_threadprivate (c_parser
*parser
)
13302 c_parser_consume_pragma (parser
);
13303 loc
= c_parser_peek_token (parser
)->location
;
13304 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13306 /* Mark every variable in VARS to be assigned thread local storage. */
13307 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13309 tree v
= TREE_PURPOSE (t
);
13311 /* FIXME diagnostics: Ideally we should keep individual
13312 locations for all the variables in the var list to make the
13313 following errors more precise. Perhaps
13314 c_parser_omp_var_list_parens() should construct a list of
13315 locations to go along with the var list. */
13317 /* If V had already been marked threadprivate, it doesn't matter
13318 whether it had been used prior to this point. */
13319 if (TREE_CODE (v
) != VAR_DECL
)
13320 error_at (loc
, "%qD is not a variable", v
);
13321 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13322 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13323 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13324 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13325 else if (TREE_TYPE (v
) == error_mark_node
)
13327 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13328 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13331 if (! DECL_THREAD_LOCAL_P (v
))
13333 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
13334 /* If rtl has been already set for this var, call
13335 make_decl_rtl once again, so that encode_section_info
13336 has a chance to look at the new decl flags. */
13337 if (DECL_RTL_SET_P (v
))
13340 C_DECL_THREADPRIVATE_P (v
) = 1;
13344 c_parser_skip_to_pragma_eol (parser
);
13347 /* Cilk Plus <#pragma simd> parsing routines. */
13349 /* Helper function for c_parser_pragma. Perform some sanity checking
13350 for <#pragma simd> constructs. Returns FALSE if there was a
13354 c_parser_cilk_verify_simd (c_parser
*parser
,
13355 enum pragma_context context
)
13357 if (!flag_enable_cilkplus
)
13359 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13360 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13363 if (context
== pragma_external
)
13365 c_parser_error (parser
,"pragma simd must be inside a function");
13366 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13373 vectorlength ( constant-expression ) */
13376 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
)
13378 /* The vectorlength clause behaves exactly like OpenMP's safelen
13379 clause. Represent it in OpenMP terms. */
13380 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13382 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13385 location_t loc
= c_parser_peek_token (parser
)->location
;
13386 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13387 expr
= c_fully_fold (expr
, false, NULL
);
13389 if (!TREE_TYPE (expr
)
13390 || !TREE_CONSTANT (expr
)
13391 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13392 error_at (loc
, "vectorlength must be an integer constant");
13393 else if (exact_log2 (TREE_INT_CST_LOW (expr
)) == -1)
13394 error_at (loc
, "vectorlength must be a power of 2");
13397 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13398 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13399 OMP_CLAUSE_CHAIN (u
) = clauses
;
13403 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13409 linear ( simd-linear-variable-list )
13411 simd-linear-variable-list:
13412 simd-linear-variable
13413 simd-linear-variable-list , simd-linear-variable
13415 simd-linear-variable:
13417 id-expression : simd-linear-step
13420 conditional-expression */
13423 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13425 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13428 location_t loc
= c_parser_peek_token (parser
)->location
;
13430 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13431 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13432 c_parser_error (parser
, "expected identifier");
13434 while (c_parser_next_token_is (parser
, CPP_NAME
)
13435 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13437 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13441 undeclared_variable (c_parser_peek_token (parser
)->location
,
13442 c_parser_peek_token (parser
)->value
);
13443 c_parser_consume_token (parser
);
13445 else if (var
== error_mark_node
)
13446 c_parser_consume_token (parser
);
13449 tree step
= integer_one_node
;
13451 /* Parse the linear step if present. */
13452 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13454 c_parser_consume_token (parser
);
13455 c_parser_consume_token (parser
);
13457 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13458 expr
= c_fully_fold (expr
, false, NULL
);
13460 if (TREE_TYPE (expr
)
13461 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13462 && (TREE_CONSTANT (expr
)
13466 c_parser_error (parser
,
13467 "step size must be an integer constant "
13468 "expression or an integer variable");
13471 c_parser_consume_token (parser
);
13473 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13474 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13475 OMP_CLAUSE_DECL (u
) = var
;
13476 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13477 OMP_CLAUSE_CHAIN (u
) = clauses
;
13481 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13484 c_parser_consume_token (parser
);
13487 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13492 /* Returns the name of the next clause. If the clause is not
13493 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13494 not consumed. Otherwise, the appropriate pragma_simd_clause is
13495 returned and the token is consumed. */
13497 static pragma_cilk_clause
13498 c_parser_cilk_clause_name (c_parser
*parser
)
13500 pragma_cilk_clause result
;
13501 c_token
*token
= c_parser_peek_token (parser
);
13503 if (!token
->value
|| token
->type
!= CPP_NAME
)
13504 return PRAGMA_CILK_CLAUSE_NONE
;
13506 const char *p
= IDENTIFIER_POINTER (token
->value
);
13508 if (!strcmp (p
, "vectorlength"))
13509 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13510 else if (!strcmp (p
, "linear"))
13511 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13512 else if (!strcmp (p
, "private"))
13513 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13514 else if (!strcmp (p
, "firstprivate"))
13515 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13516 else if (!strcmp (p
, "lastprivate"))
13517 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13518 else if (!strcmp (p
, "reduction"))
13519 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13521 return PRAGMA_CILK_CLAUSE_NONE
;
13523 c_parser_consume_token (parser
);
13527 /* Parse all #<pragma simd> clauses. Return the list of clauses
13531 c_parser_cilk_all_clauses (c_parser
*parser
)
13533 tree clauses
= NULL
;
13535 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13537 pragma_cilk_clause c_kind
;
13539 c_kind
= c_parser_cilk_clause_name (parser
);
13543 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13544 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
);
13546 case PRAGMA_CILK_CLAUSE_LINEAR
:
13547 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13549 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13550 /* Use the OpenMP counterpart. */
13551 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13553 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13554 /* Use the OpenMP counterpart. */
13555 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13557 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13558 /* Use the OpenMP counterpart. */
13559 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13561 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13562 /* Use the OpenMP counterpart. */
13563 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13566 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13572 c_parser_skip_to_pragma_eol (parser
);
13573 return c_finish_cilk_clauses (clauses
);
13576 /* Main entry point for parsing Cilk Plus <#pragma simd> for
13580 c_parser_cilk_simd (c_parser
*parser
)
13582 tree clauses
= c_parser_cilk_all_clauses (parser
);
13583 tree block
= c_begin_compound_stmt (true);
13584 location_t loc
= c_parser_peek_token (parser
)->location
;
13585 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
13586 block
= c_end_compound_stmt (loc
, block
, true);
13590 /* Parse a transaction attribute (GCC Extension).
13592 transaction-attribute:
13596 The transactional memory language description is written for C++,
13597 and uses the C++0x attribute syntax. For compatibility, allow the
13598 bracket style for transactions in C as well. */
13601 c_parser_transaction_attributes (c_parser
*parser
)
13603 tree attr_name
, attr
= NULL
;
13605 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13606 return c_parser_attributes (parser
);
13608 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13610 c_parser_consume_token (parser
);
13611 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13614 attr_name
= c_parser_attribute_any_word (parser
);
13617 c_parser_consume_token (parser
);
13618 attr
= build_tree_list (attr_name
, NULL_TREE
);
13621 c_parser_error (parser
, "expected identifier");
13623 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13625 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13629 /* Parse a __transaction_atomic or __transaction_relaxed statement
13632 transaction-statement:
13633 __transaction_atomic transaction-attribute[opt] compound-statement
13634 __transaction_relaxed compound-statement
13636 Note that the only valid attribute is: "outer".
13640 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13642 unsigned int old_in
= parser
->in_transaction
;
13643 unsigned int this_in
= 1, new_in
;
13644 location_t loc
= c_parser_peek_token (parser
)->location
;
13647 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13648 || keyword
== RID_TRANSACTION_RELAXED
)
13649 && c_parser_next_token_is_keyword (parser
, keyword
));
13650 c_parser_consume_token (parser
);
13652 if (keyword
== RID_TRANSACTION_RELAXED
)
13653 this_in
|= TM_STMT_ATTR_RELAXED
;
13656 attrs
= c_parser_transaction_attributes (parser
);
13658 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13661 /* Keep track if we're in the lexical scope of an outer transaction. */
13662 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13664 parser
->in_transaction
= new_in
;
13665 stmt
= c_parser_compound_statement (parser
);
13666 parser
->in_transaction
= old_in
;
13669 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13671 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13672 "%<__transaction_atomic%> without transactional memory support enabled"
13673 : "%<__transaction_relaxed %> "
13674 "without transactional memory support enabled"));
13679 /* Parse a __transaction_atomic or __transaction_relaxed expression
13682 transaction-expression:
13683 __transaction_atomic ( expression )
13684 __transaction_relaxed ( expression )
13687 static struct c_expr
13688 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13691 unsigned int old_in
= parser
->in_transaction
;
13692 unsigned int this_in
= 1;
13693 location_t loc
= c_parser_peek_token (parser
)->location
;
13696 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13697 || keyword
== RID_TRANSACTION_RELAXED
)
13698 && c_parser_next_token_is_keyword (parser
, keyword
));
13699 c_parser_consume_token (parser
);
13701 if (keyword
== RID_TRANSACTION_RELAXED
)
13702 this_in
|= TM_STMT_ATTR_RELAXED
;
13705 attrs
= c_parser_transaction_attributes (parser
);
13707 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13710 parser
->in_transaction
= this_in
;
13711 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13713 tree expr
= c_parser_expression (parser
).value
;
13714 ret
.original_type
= TREE_TYPE (expr
);
13715 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13716 if (this_in
& TM_STMT_ATTR_RELAXED
)
13717 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13718 SET_EXPR_LOCATION (ret
.value
, loc
);
13719 ret
.original_code
= TRANSACTION_EXPR
;
13720 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13722 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13729 ret
.value
= error_mark_node
;
13730 ret
.original_code
= ERROR_MARK
;
13731 ret
.original_type
= NULL
;
13733 parser
->in_transaction
= old_in
;
13736 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13737 "%<__transaction_atomic%> without transactional memory support enabled"
13738 : "%<__transaction_relaxed %> "
13739 "without transactional memory support enabled"));
13744 /* Parse a __transaction_cancel statement (GCC Extension).
13746 transaction-cancel-statement:
13747 __transaction_cancel transaction-attribute[opt] ;
13749 Note that the only valid attribute is "outer".
13753 c_parser_transaction_cancel (c_parser
*parser
)
13755 location_t loc
= c_parser_peek_token (parser
)->location
;
13757 bool is_outer
= false;
13759 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
13760 c_parser_consume_token (parser
);
13762 attrs
= c_parser_transaction_attributes (parser
);
13764 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
13768 error_at (loc
, "%<__transaction_cancel%> without "
13769 "transactional memory support enabled");
13772 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
13774 error_at (loc
, "%<__transaction_cancel%> within a "
13775 "%<__transaction_relaxed%>");
13780 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
13781 && !is_tm_may_cancel_outer (current_function_decl
))
13783 error_at (loc
, "outer %<__transaction_cancel%> not "
13784 "within outer %<__transaction_atomic%>");
13785 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
13789 else if (parser
->in_transaction
== 0)
13791 error_at (loc
, "%<__transaction_cancel%> not within "
13792 "%<__transaction_atomic%>");
13796 return add_stmt (build_tm_abort_call (loc
, is_outer
));
13799 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
13802 /* Parse a single source file. */
13805 c_parse_file (void)
13807 /* Use local storage to begin. If the first token is a pragma, parse it.
13808 If it is #pragma GCC pch_preprocess, then this will load a PCH file
13809 which will cause garbage collection. */
13812 memset (&tparser
, 0, sizeof tparser
);
13813 tparser
.tokens
= &tparser
.tokens_buf
[0];
13814 the_parser
= &tparser
;
13816 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
13817 c_parser_pragma_pch_preprocess (&tparser
);
13819 the_parser
= ggc_alloc_c_parser ();
13820 *the_parser
= tparser
;
13821 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
13822 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
13824 /* Initialize EH, if we've been told to do so. */
13825 if (flag_exceptions
)
13826 using_eh_for_cleanups ();
13828 c_parser_translation_unit (the_parser
);
13832 /* This function parses Cilk Plus array notation. The starting index is
13833 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
13834 return value of this function is a tree_node called VALUE_TREE of type
13835 ARRAY_NOTATION_REF. */
13838 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
13841 c_token
*token
= NULL
;
13842 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
13843 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
13844 tree array_type_domain
= NULL_TREE
;
13846 if (array_value
== error_mark_node
)
13848 /* No need to continue. If either of these 2 were true, then an error
13849 must be emitted already. Thus, no need to emit them twice. */
13850 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13851 return error_mark_node
;
13854 array_type
= TREE_TYPE (array_value
);
13855 gcc_assert (array_type
);
13856 type
= TREE_TYPE (array_type
);
13857 token
= c_parser_peek_token (parser
);
13859 if (token
->type
== CPP_EOF
)
13861 c_parser_error (parser
, "expected %<:%> or numeral");
13864 else if (token
->type
== CPP_COLON
)
13866 if (!initial_index
)
13868 /* If we are here, then we have a case like this A[:]. */
13869 c_parser_consume_token (parser
);
13870 if (TREE_CODE (array_type
) == POINTER_TYPE
)
13872 error_at (loc
, "start-index and length fields necessary for "
13873 "using array notations in pointers");
13874 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13875 return error_mark_node
;
13877 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13879 error_at (loc
, "array notations cannot be used with function "
13881 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13882 return error_mark_node
;
13884 array_type_domain
= TYPE_DOMAIN (array_type
);
13886 if (!array_type_domain
)
13888 error_at (loc
, "start-index and length fields necessary for "
13889 "using array notations in dimensionless arrays");
13890 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13891 return error_mark_node
;
13894 start_index
= TYPE_MINVAL (array_type_domain
);
13895 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
13897 if (!TYPE_MAXVAL (array_type_domain
)
13898 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
13900 error_at (loc
, "start-index and length fields necessary for "
13901 "using array notations in variable-length arrays");
13902 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13903 return error_mark_node
;
13905 end_index
= TYPE_MAXVAL (array_type_domain
);
13906 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
13907 end_index
, integer_one_node
);
13908 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
13909 stride
= build_int_cst (integer_type_node
, 1);
13910 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
13912 else if (initial_index
!= error_mark_node
)
13914 /* If we are here, then there should be 2 possibilities:
13915 1. Array [EXPR : EXPR]
13916 2. Array [EXPR : EXPR : EXPR]
13918 start_index
= initial_index
;
13920 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13922 error_at (loc
, "array notations cannot be used with function "
13924 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13925 return error_mark_node
;
13927 c_parser_consume_token (parser
); /* consume the ':' */
13928 struct c_expr ce
= c_parser_expression (parser
);
13929 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
13930 end_index
= ce
.value
;
13931 if (!end_index
|| end_index
== error_mark_node
)
13933 c_parser_skip_to_end_of_block_or_statement (parser
);
13934 return error_mark_node
;
13936 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
13938 c_parser_consume_token (parser
);
13939 ce
= c_parser_expression (parser
);
13940 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
13942 if (!stride
|| stride
== error_mark_node
)
13944 c_parser_skip_to_end_of_block_or_statement (parser
);
13945 return error_mark_node
;
13950 c_parser_error (parser
, "expected array notation expression");
13953 c_parser_error (parser
, "expected array notation expression");
13955 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13957 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
13958 end_index
, stride
, type
);
13959 if (value_tree
!= error_mark_node
)
13960 SET_EXPR_LOCATION (value_tree
, loc
);
13964 #include "gt-c-c-parser.h"