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 globals input_location and in_system_header from
781 c_parser_set_source_position_from_token (c_token
*token
)
783 if (token
->type
!= CPP_EOF
)
785 input_location
= token
->location
;
789 /* Issue a diagnostic of the form
790 FILE:LINE: MESSAGE before TOKEN
791 where TOKEN is the next token in the input stream of PARSER.
792 MESSAGE (specified by the caller) is usually of the form "expected
795 Do not issue a diagnostic if still recovering from an error.
797 ??? This is taken from the C++ parser, but building up messages in
798 this way is not i18n-friendly and some other approach should be
802 c_parser_error (c_parser
*parser
, const char *gmsgid
)
804 c_token
*token
= c_parser_peek_token (parser
);
807 parser
->error
= true;
810 /* This diagnostic makes more sense if it is tagged to the line of
811 the token we just peeked at. */
812 c_parser_set_source_position_from_token (token
);
813 c_parse_error (gmsgid
,
814 /* Because c_parse_error does not understand
815 CPP_KEYWORD, keywords are treated like
817 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
818 /* ??? The C parser does not save the cpp flags of a
819 token, we need to pass 0 here and we will not get
820 the source spelling of some tokens but rather the
821 canonical spelling. */
822 token
->value
, /*flags=*/0);
825 /* If the next token is of the indicated TYPE, consume it. Otherwise,
826 issue the error MSGID. If MSGID is NULL then a message has already
827 been produced and no message will be produced this time. Returns
828 true if found, false otherwise. */
831 c_parser_require (c_parser
*parser
,
835 if (c_parser_next_token_is (parser
, type
))
837 c_parser_consume_token (parser
);
842 c_parser_error (parser
, msgid
);
847 /* If the next token is the indicated keyword, consume it. Otherwise,
848 issue the error MSGID. Returns true if found, false otherwise. */
851 c_parser_require_keyword (c_parser
*parser
,
855 if (c_parser_next_token_is_keyword (parser
, keyword
))
857 c_parser_consume_token (parser
);
862 c_parser_error (parser
, msgid
);
867 /* Like c_parser_require, except that tokens will be skipped until the
868 desired token is found. An error message is still produced if the
869 next token is not as expected. If MSGID is NULL then a message has
870 already been produced and no message will be produced this
874 c_parser_skip_until_found (c_parser
*parser
,
878 unsigned nesting_depth
= 0;
880 if (c_parser_require (parser
, type
, msgid
))
883 /* Skip tokens until the desired token is found. */
886 /* Peek at the next token. */
887 c_token
*token
= c_parser_peek_token (parser
);
888 /* If we've reached the token we want, consume it and stop. */
889 if (token
->type
== type
&& !nesting_depth
)
891 c_parser_consume_token (parser
);
895 /* If we've run out of tokens, stop. */
896 if (token
->type
== CPP_EOF
)
898 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
900 if (token
->type
== CPP_OPEN_BRACE
901 || token
->type
== CPP_OPEN_PAREN
902 || token
->type
== CPP_OPEN_SQUARE
)
904 else if (token
->type
== CPP_CLOSE_BRACE
905 || token
->type
== CPP_CLOSE_PAREN
906 || token
->type
== CPP_CLOSE_SQUARE
)
908 if (nesting_depth
-- == 0)
911 /* Consume this token. */
912 c_parser_consume_token (parser
);
914 parser
->error
= false;
917 /* Skip tokens until the end of a parameter is found, but do not
918 consume the comma, semicolon or closing delimiter. */
921 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
923 unsigned nesting_depth
= 0;
927 c_token
*token
= c_parser_peek_token (parser
);
928 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
931 /* If we've run out of tokens, stop. */
932 if (token
->type
== CPP_EOF
)
934 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
936 if (token
->type
== CPP_OPEN_BRACE
937 || token
->type
== CPP_OPEN_PAREN
938 || token
->type
== CPP_OPEN_SQUARE
)
940 else if (token
->type
== CPP_CLOSE_BRACE
941 || token
->type
== CPP_CLOSE_PAREN
942 || token
->type
== CPP_CLOSE_SQUARE
)
944 if (nesting_depth
-- == 0)
947 /* Consume this token. */
948 c_parser_consume_token (parser
);
950 parser
->error
= false;
953 /* Expect to be at the end of the pragma directive and consume an
954 end of line marker. */
957 c_parser_skip_to_pragma_eol (c_parser
*parser
)
959 gcc_assert (parser
->in_pragma
);
960 parser
->in_pragma
= false;
962 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
965 c_token
*token
= c_parser_peek_token (parser
);
966 if (token
->type
== CPP_EOF
)
968 if (token
->type
== CPP_PRAGMA_EOL
)
970 c_parser_consume_token (parser
);
973 c_parser_consume_token (parser
);
976 parser
->error
= false;
979 /* Skip tokens until we have consumed an entire block, or until we
980 have consumed a non-nested ';'. */
983 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
985 unsigned nesting_depth
= 0;
986 bool save_error
= parser
->error
;
992 /* Peek at the next token. */
993 token
= c_parser_peek_token (parser
);
1000 case CPP_PRAGMA_EOL
:
1001 if (parser
->in_pragma
)
1006 /* If the next token is a ';', we have reached the
1007 end of the statement. */
1010 /* Consume the ';'. */
1011 c_parser_consume_token (parser
);
1016 case CPP_CLOSE_BRACE
:
1017 /* If the next token is a non-nested '}', then we have
1018 reached the end of the current block. */
1019 if (nesting_depth
== 0 || --nesting_depth
== 0)
1021 c_parser_consume_token (parser
);
1026 case CPP_OPEN_BRACE
:
1027 /* If it the next token is a '{', then we are entering a new
1028 block. Consume the entire block. */
1033 /* If we see a pragma, consume the whole thing at once. We
1034 have some safeguards against consuming pragmas willy-nilly.
1035 Normally, we'd expect to be here with parser->error set,
1036 which disables these safeguards. But it's possible to get
1037 here for secondary error recovery, after parser->error has
1039 c_parser_consume_pragma (parser
);
1040 c_parser_skip_to_pragma_eol (parser
);
1041 parser
->error
= save_error
;
1048 c_parser_consume_token (parser
);
1052 parser
->error
= false;
1055 /* CPP's options (initialized by c-opts.c). */
1056 extern cpp_options
*cpp_opts
;
1058 /* Save the warning flags which are controlled by __extension__. */
1061 disable_extension_diagnostics (void)
1064 | (warn_pointer_arith
<< 1)
1065 | (warn_traditional
<< 2)
1067 | (warn_long_long
<< 4)
1068 | (warn_cxx_compat
<< 5)
1069 | (warn_overlength_strings
<< 6));
1070 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1071 warn_pointer_arith
= 0;
1072 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1074 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1075 warn_cxx_compat
= 0;
1076 warn_overlength_strings
= 0;
1080 /* Restore the warning flags which are controlled by __extension__.
1081 FLAGS is the return value from disable_extension_diagnostics. */
1084 restore_extension_diagnostics (int flags
)
1086 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1087 warn_pointer_arith
= (flags
>> 1) & 1;
1088 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1089 flag_iso
= (flags
>> 3) & 1;
1090 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1091 warn_cxx_compat
= (flags
>> 5) & 1;
1092 warn_overlength_strings
= (flags
>> 6) & 1;
1095 /* Possibly kinds of declarator to parse. */
1096 typedef enum c_dtr_syn
{
1097 /* A normal declarator with an identifier. */
1099 /* An abstract declarator (maybe empty). */
1101 /* A parameter declarator: may be either, but after a type name does
1102 not redeclare a typedef name as an identifier if it can
1103 alternatively be interpreted as a typedef name; see DR#009,
1104 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1105 following DR#249. For example, given a typedef T, "int T" and
1106 "int *T" are valid parameter declarations redeclaring T, while
1107 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1108 abstract declarators rather than involving redundant parentheses;
1109 the same applies with attributes inside the parentheses before
1114 /* The binary operation precedence levels, where 0 is a dummy lowest level
1115 used for the bottom of the stack. */
1116 enum c_parser_prec
{
1131 static void c_parser_external_declaration (c_parser
*);
1132 static void c_parser_asm_definition (c_parser
*);
1133 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1134 bool, bool, tree
*, vec
<c_token
>);
1135 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1136 static void c_parser_static_assert_declaration (c_parser
*);
1137 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1138 bool, bool, bool, enum c_lookahead_kind
);
1139 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1140 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1141 static tree
c_parser_struct_declaration (c_parser
*);
1142 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1143 static tree
c_parser_alignas_specifier (c_parser
*);
1144 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1146 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1148 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1150 struct c_declarator
*);
1151 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1152 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1154 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1155 static tree
c_parser_simple_asm_expr (c_parser
*);
1156 static tree
c_parser_attributes (c_parser
*);
1157 static struct c_type_name
*c_parser_type_name (c_parser
*);
1158 static struct c_expr
c_parser_initializer (c_parser
*);
1159 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1160 static void c_parser_initelt (c_parser
*, struct obstack
*);
1161 static void c_parser_initval (c_parser
*, struct c_expr
*,
1163 static tree
c_parser_compound_statement (c_parser
*);
1164 static void c_parser_compound_statement_nostart (c_parser
*);
1165 static void c_parser_label (c_parser
*);
1166 static void c_parser_statement (c_parser
*);
1167 static void c_parser_statement_after_labels (c_parser
*);
1168 static void c_parser_if_statement (c_parser
*);
1169 static void c_parser_switch_statement (c_parser
*);
1170 static void c_parser_while_statement (c_parser
*, bool);
1171 static void c_parser_do_statement (c_parser
*, bool);
1172 static void c_parser_for_statement (c_parser
*, bool);
1173 static tree
c_parser_asm_statement (c_parser
*);
1174 static tree
c_parser_asm_operands (c_parser
*);
1175 static tree
c_parser_asm_goto_operands (c_parser
*);
1176 static tree
c_parser_asm_clobbers (c_parser
*);
1177 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1179 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1180 struct c_expr
*, tree
);
1181 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1183 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1184 static struct c_expr
c_parser_unary_expression (c_parser
*);
1185 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1186 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1187 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1188 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1189 struct c_type_name
*,
1191 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1194 static tree
c_parser_transaction (c_parser
*, enum rid
);
1195 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1196 static tree
c_parser_transaction_cancel (c_parser
*);
1197 static struct c_expr
c_parser_expression (c_parser
*);
1198 static struct c_expr
c_parser_expression_conv (c_parser
*);
1199 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1200 vec
<tree
, va_gc
> **, location_t
*,
1202 static void c_parser_omp_construct (c_parser
*);
1203 static void c_parser_omp_threadprivate (c_parser
*);
1204 static void c_parser_omp_barrier (c_parser
*);
1205 static void c_parser_omp_flush (c_parser
*);
1206 static void c_parser_omp_taskwait (c_parser
*);
1207 static void c_parser_omp_taskyield (c_parser
*);
1208 static void c_parser_omp_cancel (c_parser
*);
1209 static void c_parser_omp_cancellation_point (c_parser
*);
1211 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1212 pragma_stmt
, pragma_compound
};
1213 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1214 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1215 static void c_parser_omp_end_declare_target (c_parser
*);
1216 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1218 /* These Objective-C parser functions are only ever called when
1219 compiling Objective-C. */
1220 static void c_parser_objc_class_definition (c_parser
*, tree
);
1221 static void c_parser_objc_class_instance_variables (c_parser
*);
1222 static void c_parser_objc_class_declaration (c_parser
*);
1223 static void c_parser_objc_alias_declaration (c_parser
*);
1224 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1225 static bool c_parser_objc_method_type (c_parser
*);
1226 static void c_parser_objc_method_definition (c_parser
*);
1227 static void c_parser_objc_methodprotolist (c_parser
*);
1228 static void c_parser_objc_methodproto (c_parser
*);
1229 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1230 static tree
c_parser_objc_type_name (c_parser
*);
1231 static tree
c_parser_objc_protocol_refs (c_parser
*);
1232 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1233 static void c_parser_objc_synchronized_statement (c_parser
*);
1234 static tree
c_parser_objc_selector (c_parser
*);
1235 static tree
c_parser_objc_selector_arg (c_parser
*);
1236 static tree
c_parser_objc_receiver (c_parser
*);
1237 static tree
c_parser_objc_message_args (c_parser
*);
1238 static tree
c_parser_objc_keywordexpr (c_parser
*);
1239 static void c_parser_objc_at_property_declaration (c_parser
*);
1240 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1241 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1242 static bool c_parser_objc_diagnose_bad_element_prefix
1243 (c_parser
*, struct c_declspecs
*);
1245 /* Cilk Plus supporting routines. */
1246 static void c_parser_cilk_simd (c_parser
*);
1247 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1248 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1250 /* Parse a translation unit (C90 6.7, C99 6.9).
1253 external-declarations
1255 external-declarations:
1256 external-declaration
1257 external-declarations external-declaration
1266 c_parser_translation_unit (c_parser
*parser
)
1268 if (c_parser_next_token_is (parser
, CPP_EOF
))
1270 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1271 "ISO C forbids an empty translation unit");
1275 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1276 mark_valid_location_for_stdc_pragma (false);
1280 c_parser_external_declaration (parser
);
1281 obstack_free (&parser_obstack
, obstack_position
);
1283 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1287 /* Parse an external declaration (C90 6.7, C99 6.9).
1289 external-declaration:
1295 external-declaration:
1298 __extension__ external-declaration
1302 external-declaration:
1303 objc-class-definition
1304 objc-class-declaration
1305 objc-alias-declaration
1306 objc-protocol-definition
1307 objc-method-definition
1312 c_parser_external_declaration (c_parser
*parser
)
1315 switch (c_parser_peek_token (parser
)->type
)
1318 switch (c_parser_peek_token (parser
)->keyword
)
1321 ext
= disable_extension_diagnostics ();
1322 c_parser_consume_token (parser
);
1323 c_parser_external_declaration (parser
);
1324 restore_extension_diagnostics (ext
);
1327 c_parser_asm_definition (parser
);
1329 case RID_AT_INTERFACE
:
1330 case RID_AT_IMPLEMENTATION
:
1331 gcc_assert (c_dialect_objc ());
1332 c_parser_objc_class_definition (parser
, NULL_TREE
);
1335 gcc_assert (c_dialect_objc ());
1336 c_parser_objc_class_declaration (parser
);
1339 gcc_assert (c_dialect_objc ());
1340 c_parser_objc_alias_declaration (parser
);
1342 case RID_AT_PROTOCOL
:
1343 gcc_assert (c_dialect_objc ());
1344 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1346 case RID_AT_PROPERTY
:
1347 gcc_assert (c_dialect_objc ());
1348 c_parser_objc_at_property_declaration (parser
);
1350 case RID_AT_SYNTHESIZE
:
1351 gcc_assert (c_dialect_objc ());
1352 c_parser_objc_at_synthesize_declaration (parser
);
1354 case RID_AT_DYNAMIC
:
1355 gcc_assert (c_dialect_objc ());
1356 c_parser_objc_at_dynamic_declaration (parser
);
1359 gcc_assert (c_dialect_objc ());
1360 c_parser_consume_token (parser
);
1361 objc_finish_implementation ();
1368 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1369 "ISO C does not allow extra %<;%> outside of a function");
1370 c_parser_consume_token (parser
);
1373 mark_valid_location_for_stdc_pragma (true);
1374 c_parser_pragma (parser
, pragma_external
);
1375 mark_valid_location_for_stdc_pragma (false);
1379 if (c_dialect_objc ())
1381 c_parser_objc_method_definition (parser
);
1384 /* Else fall through, and yield a syntax error trying to parse
1385 as a declaration or function definition. */
1388 /* A declaration or a function definition (or, in Objective-C,
1389 an @interface or @protocol with prefix attributes). We can
1390 only tell which after parsing the declaration specifiers, if
1391 any, and the first declarator. */
1392 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1398 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1400 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1401 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1402 accepted; otherwise (old-style parameter declarations) only other
1403 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1404 assertion is accepted; otherwise (old-style parameter declarations)
1405 it is not. If NESTED is true, we are inside a function or parsing
1406 old-style parameter declarations; any functions encountered are
1407 nested functions and declaration specifiers are required; otherwise
1408 we are at top level and functions are normal functions and
1409 declaration specifiers may be optional. If EMPTY_OK is true, empty
1410 declarations are OK (subject to all other constraints); otherwise
1411 (old-style parameter declarations) they are diagnosed. If
1412 START_ATTR_OK is true, the declaration specifiers may start with
1413 attributes; otherwise they may not.
1414 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1415 declaration when parsing an Objective-C foreach statement.
1418 declaration-specifiers init-declarator-list[opt] ;
1419 static_assert-declaration
1421 function-definition:
1422 declaration-specifiers[opt] declarator declaration-list[opt]
1427 declaration-list declaration
1429 init-declarator-list:
1431 init-declarator-list , init-declarator
1434 declarator simple-asm-expr[opt] attributes[opt]
1435 declarator simple-asm-expr[opt] attributes[opt] = initializer
1439 nested-function-definition:
1440 declaration-specifiers declarator declaration-list[opt]
1444 attributes objc-class-definition
1445 attributes objc-category-definition
1446 attributes objc-protocol-definition
1448 The simple-asm-expr and attributes are GNU extensions.
1450 This function does not handle __extension__; that is handled in its
1451 callers. ??? Following the old parser, __extension__ may start
1452 external declarations, declarations in functions and declarations
1453 at the start of "for" loops, but not old-style parameter
1456 C99 requires declaration specifiers in a function definition; the
1457 absence is diagnosed through the diagnosis of implicit int. In GNU
1458 C we also allow but diagnose declarations without declaration
1459 specifiers, but only at top level (elsewhere they conflict with
1462 In Objective-C, declarations of the looping variable in a foreach
1463 statement are exceptionally terminated by 'in' (for example, 'for
1464 (NSObject *object in array) { ... }').
1469 threadprivate-directive */
1472 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1473 bool static_assert_ok
, bool empty_ok
,
1474 bool nested
, bool start_attr_ok
,
1475 tree
*objc_foreach_object_declaration
,
1476 vec
<c_token
> omp_declare_simd_clauses
)
1478 struct c_declspecs
*specs
;
1480 tree all_prefix_attrs
;
1481 bool diagnosed_no_specs
= false;
1482 location_t here
= c_parser_peek_token (parser
)->location
;
1484 if (static_assert_ok
1485 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1487 c_parser_static_assert_declaration (parser
);
1490 specs
= build_null_declspecs ();
1492 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1493 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1494 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1495 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1496 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1497 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1499 error_at (here
, "unknown type name %qE",
1500 c_parser_peek_token (parser
)->value
);
1502 /* Parse declspecs normally to get a correct pointer type, but avoid
1503 a further "fails to be a type name" error. Refuse nested functions
1504 since it is not how the user likely wants us to recover. */
1505 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1506 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1507 c_parser_peek_token (parser
)->value
= error_mark_node
;
1511 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1512 true, true, cla_nonabstract_decl
);
1515 c_parser_skip_to_end_of_block_or_statement (parser
);
1518 if (nested
&& !specs
->declspecs_seen_p
)
1520 c_parser_error (parser
, "expected declaration specifiers");
1521 c_parser_skip_to_end_of_block_or_statement (parser
);
1524 finish_declspecs (specs
);
1525 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1526 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1529 error_at (here
, "%<__auto_type%> in empty declaration");
1534 shadow_tag_warned (specs
, 1);
1535 pedwarn (here
, 0, "empty declaration");
1537 c_parser_consume_token (parser
);
1541 /* Provide better error recovery. Note that a type name here is usually
1542 better diagnosed as a redeclaration. */
1544 && specs
->typespec_kind
== ctsk_tagdef
1545 && c_parser_next_token_starts_declspecs (parser
)
1546 && !c_parser_next_token_is (parser
, CPP_NAME
))
1548 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1549 parser
->error
= false;
1550 shadow_tag_warned (specs
, 1);
1553 else if (c_dialect_objc () && !auto_type_p
)
1555 /* Prefix attributes are an error on method decls. */
1556 switch (c_parser_peek_token (parser
)->type
)
1560 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1564 warning_at (c_parser_peek_token (parser
)->location
,
1566 "prefix attributes are ignored for methods");
1567 specs
->attrs
= NULL_TREE
;
1570 c_parser_objc_method_definition (parser
);
1572 c_parser_objc_methodproto (parser
);
1578 /* This is where we parse 'attributes @interface ...',
1579 'attributes @implementation ...', 'attributes @protocol ...'
1580 (where attributes could be, for example, __attribute__
1583 switch (c_parser_peek_token (parser
)->keyword
)
1585 case RID_AT_INTERFACE
:
1587 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1589 c_parser_objc_class_definition (parser
, specs
->attrs
);
1593 case RID_AT_IMPLEMENTATION
:
1595 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1599 warning_at (c_parser_peek_token (parser
)->location
,
1601 "prefix attributes are ignored for implementations");
1602 specs
->attrs
= NULL_TREE
;
1604 c_parser_objc_class_definition (parser
, NULL_TREE
);
1608 case RID_AT_PROTOCOL
:
1610 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1612 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1619 case RID_AT_PROPERTY
:
1622 c_parser_error (parser
, "unexpected attribute");
1623 specs
->attrs
= NULL
;
1631 pending_xref_error ();
1632 prefix_attrs
= specs
->attrs
;
1633 all_prefix_attrs
= prefix_attrs
;
1634 specs
->attrs
= NULL_TREE
;
1637 struct c_declarator
*declarator
;
1641 /* Declaring either one or more declarators (in which case we
1642 should diagnose if there were no declaration specifiers) or a
1643 function definition (in which case the diagnostic for
1644 implicit int suffices). */
1645 declarator
= c_parser_declarator (parser
,
1646 specs
->typespec_kind
!= ctsk_none
,
1647 C_DTR_NORMAL
, &dummy
);
1648 if (declarator
== NULL
)
1650 if (omp_declare_simd_clauses
.exists ())
1651 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1652 omp_declare_simd_clauses
);
1653 c_parser_skip_to_end_of_block_or_statement (parser
);
1656 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1659 "%<__auto_type%> requires a plain identifier"
1661 c_parser_skip_to_end_of_block_or_statement (parser
);
1664 if (c_parser_next_token_is (parser
, CPP_EQ
)
1665 || c_parser_next_token_is (parser
, CPP_COMMA
)
1666 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1667 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1668 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1669 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1671 tree asm_name
= NULL_TREE
;
1672 tree postfix_attrs
= NULL_TREE
;
1673 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1675 diagnosed_no_specs
= true;
1676 pedwarn (here
, 0, "data definition has no type or storage class");
1678 /* Having seen a data definition, there cannot now be a
1679 function definition. */
1681 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1682 asm_name
= c_parser_simple_asm_expr (parser
);
1683 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1684 postfix_attrs
= c_parser_attributes (parser
);
1685 if (c_parser_next_token_is (parser
, CPP_EQ
))
1689 location_t init_loc
;
1690 c_parser_consume_token (parser
);
1693 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1694 init_loc
= c_parser_peek_token (parser
)->location
;
1695 init
= c_parser_expr_no_commas (parser
, NULL
);
1696 if (TREE_CODE (init
.value
) == COMPONENT_REF
1697 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1699 "%<__auto_type%> used with a bit-field"
1701 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1702 tree init_type
= TREE_TYPE (init
.value
);
1703 /* As with typeof, remove _Atomic and const
1704 qualifiers from atomic types. */
1705 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1707 = c_build_qualified_type (init_type
,
1708 (TYPE_QUALS (init_type
)
1709 & ~(TYPE_QUAL_ATOMIC
1710 | TYPE_QUAL_CONST
)));
1711 bool vm_type
= variably_modified_type_p (init_type
,
1714 init
.value
= c_save_expr (init
.value
);
1716 specs
->typespec_kind
= ctsk_typeof
;
1717 specs
->locations
[cdw_typedef
] = init_loc
;
1718 specs
->typedef_p
= true;
1719 specs
->type
= init_type
;
1722 bool maybe_const
= true;
1723 tree type_expr
= c_fully_fold (init
.value
, false,
1725 specs
->expr_const_operands
&= maybe_const
;
1727 specs
->expr
= build2 (COMPOUND_EXPR
,
1728 TREE_TYPE (type_expr
),
1729 specs
->expr
, type_expr
);
1731 specs
->expr
= type_expr
;
1733 d
= start_decl (declarator
, specs
, true,
1734 chainon (postfix_attrs
, all_prefix_attrs
));
1736 d
= error_mark_node
;
1737 if (omp_declare_simd_clauses
.exists ())
1738 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1739 omp_declare_simd_clauses
);
1743 /* The declaration of the variable is in effect while
1744 its initializer is parsed. */
1745 d
= start_decl (declarator
, specs
, true,
1746 chainon (postfix_attrs
, all_prefix_attrs
));
1748 d
= error_mark_node
;
1749 if (omp_declare_simd_clauses
.exists ())
1750 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1751 omp_declare_simd_clauses
);
1752 start_init (d
, asm_name
, global_bindings_p ());
1753 init_loc
= c_parser_peek_token (parser
)->location
;
1754 init
= c_parser_initializer (parser
);
1757 if (d
!= error_mark_node
)
1759 maybe_warn_string_init (TREE_TYPE (d
), init
);
1760 finish_decl (d
, init_loc
, init
.value
,
1761 init
.original_type
, asm_name
);
1769 "%<__auto_type%> requires an initialized "
1770 "data declaration");
1771 c_parser_skip_to_end_of_block_or_statement (parser
);
1774 tree d
= start_decl (declarator
, specs
, false,
1775 chainon (postfix_attrs
,
1777 if (omp_declare_simd_clauses
.exists ())
1779 tree parms
= NULL_TREE
;
1780 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1782 struct c_declarator
*ce
= declarator
;
1784 if (ce
->kind
== cdk_function
)
1786 parms
= ce
->u
.arg_info
->parms
;
1790 ce
= ce
->declarator
;
1793 temp_store_parm_decls (d
, parms
);
1794 c_finish_omp_declare_simd (parser
, d
, parms
,
1795 omp_declare_simd_clauses
);
1797 temp_pop_parm_decls ();
1800 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1801 NULL_TREE
, asm_name
);
1803 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1806 *objc_foreach_object_declaration
= d
;
1808 *objc_foreach_object_declaration
= error_mark_node
;
1811 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1816 "%<__auto_type%> may only be used with"
1817 " a single declarator");
1818 c_parser_skip_to_end_of_block_or_statement (parser
);
1821 c_parser_consume_token (parser
);
1822 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1823 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1826 all_prefix_attrs
= prefix_attrs
;
1829 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1831 c_parser_consume_token (parser
);
1834 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1836 /* This can only happen in Objective-C: we found the
1837 'in' that terminates the declaration inside an
1838 Objective-C foreach statement. Do not consume the
1839 token, so that the caller can use it to determine
1840 that this indeed is a foreach context. */
1845 c_parser_error (parser
, "expected %<,%> or %<;%>");
1846 c_parser_skip_to_end_of_block_or_statement (parser
);
1850 else if (auto_type_p
)
1853 "%<__auto_type%> requires an initialized data declaration");
1854 c_parser_skip_to_end_of_block_or_statement (parser
);
1859 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1860 "%<asm%> or %<__attribute__%>");
1861 c_parser_skip_to_end_of_block_or_statement (parser
);
1864 /* Function definition (nested or otherwise). */
1867 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1868 c_push_function_context ();
1870 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1872 /* This can appear in many cases looking nothing like a
1873 function definition, so we don't give a more specific
1874 error suggesting there was one. */
1875 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1876 "or %<__attribute__%>");
1878 c_pop_function_context ();
1882 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1883 tv
= TV_PARSE_INLINE
;
1888 /* Parse old-style parameter declarations. ??? Attributes are
1889 not allowed to start declaration specifiers here because of a
1890 syntax conflict between a function declaration with attribute
1891 suffix and a function definition with an attribute prefix on
1892 first old-style parameter declaration. Following the old
1893 parser, they are not accepted on subsequent old-style
1894 parameter declarations either. However, there is no
1895 ambiguity after the first declaration, nor indeed on the
1896 first as long as we don't allow postfix attributes after a
1897 declarator with a nonempty identifier list in a definition;
1898 and postfix attributes have never been accepted here in
1899 function definitions either. */
1900 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1901 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1902 c_parser_declaration_or_fndef (parser
, false, false, false,
1903 true, false, NULL
, vNULL
);
1904 store_parm_decls ();
1905 if (omp_declare_simd_clauses
.exists ())
1906 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1907 omp_declare_simd_clauses
);
1908 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1909 = c_parser_peek_token (parser
)->location
;
1910 fnbody
= c_parser_compound_statement (parser
);
1911 if (flag_enable_cilkplus
&& contains_array_notation_expr (fnbody
))
1912 fnbody
= expand_array_notation_exprs (fnbody
);
1915 tree decl
= current_function_decl
;
1916 /* Mark nested functions as needing static-chain initially.
1917 lower_nested_functions will recompute it but the
1918 DECL_STATIC_CHAIN flag is also used before that happens,
1919 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1920 DECL_STATIC_CHAIN (decl
) = 1;
1923 c_pop_function_context ();
1924 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1937 /* Parse an asm-definition (asm() outside a function body). This is a
1945 c_parser_asm_definition (c_parser
*parser
)
1947 tree asm_str
= c_parser_simple_asm_expr (parser
);
1949 add_asm_node (asm_str
);
1950 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1953 /* Parse a static assertion (C11 6.7.10).
1955 static_assert-declaration:
1956 static_assert-declaration-no-semi ;
1960 c_parser_static_assert_declaration (c_parser
*parser
)
1962 c_parser_static_assert_declaration_no_semi (parser
);
1964 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1965 c_parser_skip_to_end_of_block_or_statement (parser
);
1968 /* Parse a static assertion (C11 6.7.10), without the trailing
1971 static_assert-declaration-no-semi:
1972 _Static_assert ( constant-expression , string-literal )
1976 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1978 location_t assert_loc
, value_loc
;
1982 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1983 assert_loc
= c_parser_peek_token (parser
)->location
;
1987 pedwarn (assert_loc
, OPT_Wpedantic
,
1988 "ISO C99 does not support %<_Static_assert%>");
1990 pedwarn (assert_loc
, OPT_Wpedantic
,
1991 "ISO C90 does not support %<_Static_assert%>");
1993 c_parser_consume_token (parser
);
1994 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1996 value_loc
= c_parser_peek_token (parser
)->location
;
1997 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1998 parser
->lex_untranslated_string
= true;
1999 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2001 parser
->lex_untranslated_string
= false;
2004 switch (c_parser_peek_token (parser
)->type
)
2010 case CPP_UTF8STRING
:
2011 string
= c_parser_peek_token (parser
)->value
;
2012 c_parser_consume_token (parser
);
2013 parser
->lex_untranslated_string
= false;
2016 c_parser_error (parser
, "expected string literal");
2017 parser
->lex_untranslated_string
= false;
2020 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2022 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2024 error_at (value_loc
, "expression in static assertion is not an integer");
2027 if (TREE_CODE (value
) != INTEGER_CST
)
2029 value
= c_fully_fold (value
, false, NULL
);
2030 if (TREE_CODE (value
) == INTEGER_CST
)
2031 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2032 "is not an integer constant expression");
2034 if (TREE_CODE (value
) != INTEGER_CST
)
2036 error_at (value_loc
, "expression in static assertion is not constant");
2039 constant_expression_warning (value
);
2040 if (integer_zerop (value
))
2041 error_at (assert_loc
, "static assertion failed: %E", string
);
2044 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2045 6.7), adding them to SPECS (which may already include some).
2046 Storage class specifiers are accepted iff SCSPEC_OK; type
2047 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2048 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2049 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2051 declaration-specifiers:
2052 storage-class-specifier declaration-specifiers[opt]
2053 type-specifier declaration-specifiers[opt]
2054 type-qualifier declaration-specifiers[opt]
2055 function-specifier declaration-specifiers[opt]
2056 alignment-specifier declaration-specifiers[opt]
2058 Function specifiers (inline) are from C99, and are currently
2059 handled as storage class specifiers, as is __thread. Alignment
2060 specifiers are from C11.
2062 C90 6.5.1, C99 6.7.1:
2063 storage-class-specifier:
2071 (_Thread_local is new in C11.)
2078 (_Noreturn is new in C11.)
2080 C90 6.5.2, C99 6.7.2:
2093 [_Imaginary removed in C99 TC2]
2094 struct-or-union-specifier
2097 atomic-type-specifier
2099 (_Bool and _Complex are new in C99.)
2100 (atomic-type-specifier is new in C11.)
2102 C90 6.5.3, C99 6.7.3:
2108 address-space-qualifier
2111 (restrict is new in C99.)
2112 (_Atomic is new in C11.)
2116 declaration-specifiers:
2117 attributes declaration-specifiers[opt]
2123 identifier recognized by the target
2125 storage-class-specifier:
2139 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2140 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2142 atomic-type-specifier
2143 _Atomic ( type-name )
2148 class-name objc-protocol-refs[opt]
2149 typedef-name objc-protocol-refs
2154 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2155 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2156 bool alignspec_ok
, bool auto_type_ok
,
2157 enum c_lookahead_kind la
)
2159 bool attrs_ok
= start_attr_ok
;
2160 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2163 gcc_assert (la
== cla_prefer_id
);
2165 while (c_parser_next_token_is (parser
, CPP_NAME
)
2166 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2167 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2169 struct c_typespec t
;
2172 location_t loc
= c_parser_peek_token (parser
)->location
;
2174 /* If we cannot accept a type, exit if the next token must start
2175 one. Also, if we already have seen a tagged definition,
2176 a typename would be an error anyway and likely the user
2177 has simply forgotten a semicolon, so we exit. */
2178 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2179 && c_parser_next_tokens_start_typename (parser
, la
)
2180 && !c_parser_next_token_is_qualifier (parser
))
2183 if (c_parser_next_token_is (parser
, CPP_NAME
))
2185 c_token
*name_token
= c_parser_peek_token (parser
);
2186 tree value
= name_token
->value
;
2187 c_id_kind kind
= name_token
->id_kind
;
2189 if (kind
== C_ID_ADDRSPACE
)
2192 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2193 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2194 c_parser_consume_token (parser
);
2199 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2201 /* If we cannot accept a type, and the next token must start one,
2202 exit. Do the same if we already have seen a tagged definition,
2203 since it would be an error anyway and likely the user has simply
2204 forgotten a semicolon. */
2205 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2208 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2209 a C_ID_CLASSNAME. */
2210 c_parser_consume_token (parser
);
2213 if (kind
== C_ID_ID
)
2215 error ("unknown type name %qE", value
);
2216 t
.kind
= ctsk_typedef
;
2217 t
.spec
= error_mark_node
;
2219 else if (kind
== C_ID_TYPENAME
2220 && (!c_dialect_objc ()
2221 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2223 t
.kind
= ctsk_typedef
;
2224 /* For a typedef name, record the meaning, not the name.
2225 In case of 'foo foo, bar;'. */
2226 t
.spec
= lookup_name (value
);
2230 tree proto
= NULL_TREE
;
2231 gcc_assert (c_dialect_objc ());
2233 if (c_parser_next_token_is (parser
, CPP_LESS
))
2234 proto
= c_parser_objc_protocol_refs (parser
);
2235 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2238 t
.expr_const_operands
= true;
2239 declspecs_add_type (name_token
->location
, specs
, t
);
2242 if (c_parser_next_token_is (parser
, CPP_LESS
))
2244 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2245 nisse@lysator.liu.se. */
2247 gcc_assert (c_dialect_objc ());
2248 if (!typespec_ok
|| seen_type
)
2250 proto
= c_parser_objc_protocol_refs (parser
);
2252 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2254 t
.expr_const_operands
= true;
2255 declspecs_add_type (loc
, specs
, t
);
2258 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2259 switch (c_parser_peek_token (parser
)->keyword
)
2272 /* TODO: Distinguish between function specifiers (inline, noreturn)
2273 and storage class specifiers, either here or in
2274 declspecs_add_scspec. */
2275 declspecs_add_scspec (loc
, specs
,
2276 c_parser_peek_token (parser
)->value
);
2277 c_parser_consume_token (parser
);
2305 if (c_dialect_objc ())
2306 parser
->objc_need_raw_identifier
= true;
2307 t
.kind
= ctsk_resword
;
2308 t
.spec
= c_parser_peek_token (parser
)->value
;
2310 t
.expr_const_operands
= true;
2311 declspecs_add_type (loc
, specs
, t
);
2312 c_parser_consume_token (parser
);
2319 t
= c_parser_enum_specifier (parser
);
2320 declspecs_add_type (loc
, specs
, t
);
2328 t
= c_parser_struct_or_union_specifier (parser
);
2329 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2330 declspecs_add_type (loc
, specs
, t
);
2333 /* ??? The old parser rejected typeof after other type
2334 specifiers, but is a syntax error the best way of
2336 if (!typespec_ok
|| seen_type
)
2340 t
= c_parser_typeof_specifier (parser
);
2341 declspecs_add_type (loc
, specs
, t
);
2344 /* C parser handling of Objective-C constructs needs
2345 checking for correct lvalue-to-rvalue conversions, and
2346 the code in build_modify_expr handling various
2347 Objective-C cases, and that in build_unary_op handling
2348 Objective-C cases for increment / decrement, also needs
2349 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2350 and objc_types_are_equivalent may also need updates. */
2351 if (c_dialect_objc ())
2352 sorry ("%<_Atomic%> in Objective-C");
2353 /* C parser handling of OpenMP constructs needs checking for
2354 correct lvalue-to-rvalue conversions. */
2356 sorry ("%<_Atomic%> with OpenMP");
2360 pedwarn (loc
, OPT_Wpedantic
,
2361 "ISO C99 does not support the %<_Atomic%> qualifier");
2363 pedwarn (loc
, OPT_Wpedantic
,
2364 "ISO C90 does not support the %<_Atomic%> qualifier");
2368 value
= c_parser_peek_token (parser
)->value
;
2369 c_parser_consume_token (parser
);
2370 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2372 /* _Atomic ( type-name ). */
2374 c_parser_consume_token (parser
);
2375 struct c_type_name
*type
= c_parser_type_name (parser
);
2376 t
.kind
= ctsk_typeof
;
2377 t
.spec
= error_mark_node
;
2379 t
.expr_const_operands
= true;
2381 t
.spec
= groktypename (type
, &t
.expr
,
2382 &t
.expr_const_operands
);
2383 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2385 if (t
.spec
!= error_mark_node
)
2387 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2388 error_at (loc
, "%<_Atomic%>-qualified array type");
2389 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2390 error_at (loc
, "%<_Atomic%>-qualified function type");
2391 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2392 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2394 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2396 declspecs_add_type (loc
, specs
, t
);
2399 declspecs_add_qual (loc
, specs
, value
);
2405 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2406 c_parser_consume_token (parser
);
2411 attrs
= c_parser_attributes (parser
);
2412 declspecs_add_attrs (loc
, specs
, attrs
);
2417 align
= c_parser_alignas_specifier (parser
);
2418 declspecs_add_alignas (loc
, specs
, align
);
2427 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2430 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2431 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2432 enum attributes[opt] identifier
2434 The form with trailing comma is new in C99. The forms with
2435 attributes are GNU extensions. In GNU C, we accept any expression
2436 without commas in the syntax (assignment expressions, not just
2437 conditional expressions); assignment expressions will be diagnosed
2442 enumerator-list , enumerator
2445 enumeration-constant
2446 enumeration-constant = constant-expression
2449 static struct c_typespec
2450 c_parser_enum_specifier (c_parser
*parser
)
2452 struct c_typespec ret
;
2454 tree ident
= NULL_TREE
;
2455 location_t enum_loc
;
2456 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2457 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2458 enum_loc
= c_parser_peek_token (parser
)->location
;
2459 c_parser_consume_token (parser
);
2460 attrs
= c_parser_attributes (parser
);
2461 enum_loc
= c_parser_peek_token (parser
)->location
;
2462 /* Set the location in case we create a decl now. */
2463 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2464 if (c_parser_next_token_is (parser
, CPP_NAME
))
2466 ident
= c_parser_peek_token (parser
)->value
;
2467 ident_loc
= c_parser_peek_token (parser
)->location
;
2468 enum_loc
= ident_loc
;
2469 c_parser_consume_token (parser
);
2471 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2473 /* Parse an enum definition. */
2474 struct c_enum_contents the_enum
;
2477 /* We chain the enumerators in reverse order, then put them in
2478 forward order at the end. */
2480 timevar_push (TV_PARSE_ENUM
);
2481 type
= start_enum (enum_loc
, &the_enum
, ident
);
2483 c_parser_consume_token (parser
);
2491 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2492 location_t decl_loc
, value_loc
;
2493 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2495 c_parser_error (parser
, "expected identifier");
2496 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2497 values
= error_mark_node
;
2500 token
= c_parser_peek_token (parser
);
2501 enum_id
= token
->value
;
2502 /* Set the location in case we create a decl now. */
2503 c_parser_set_source_position_from_token (token
);
2504 decl_loc
= value_loc
= token
->location
;
2505 c_parser_consume_token (parser
);
2506 if (c_parser_next_token_is (parser
, CPP_EQ
))
2508 c_parser_consume_token (parser
);
2509 value_loc
= c_parser_peek_token (parser
)->location
;
2510 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2513 enum_value
= NULL_TREE
;
2514 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2515 &the_enum
, enum_id
, enum_value
);
2516 TREE_CHAIN (enum_decl
) = values
;
2519 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2521 comma_loc
= c_parser_peek_token (parser
)->location
;
2523 c_parser_consume_token (parser
);
2525 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2527 if (seen_comma
&& !flag_isoc99
)
2528 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2529 c_parser_consume_token (parser
);
2534 c_parser_error (parser
, "expected %<,%> or %<}%>");
2535 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2536 values
= error_mark_node
;
2540 postfix_attrs
= c_parser_attributes (parser
);
2541 ret
.spec
= finish_enum (type
, nreverse (values
),
2542 chainon (attrs
, postfix_attrs
));
2543 ret
.kind
= ctsk_tagdef
;
2544 ret
.expr
= NULL_TREE
;
2545 ret
.expr_const_operands
= true;
2546 timevar_pop (TV_PARSE_ENUM
);
2551 c_parser_error (parser
, "expected %<{%>");
2552 ret
.spec
= error_mark_node
;
2553 ret
.kind
= ctsk_tagref
;
2554 ret
.expr
= NULL_TREE
;
2555 ret
.expr_const_operands
= true;
2558 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2559 /* In ISO C, enumerated types can be referred to only if already
2561 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2564 pedwarn (enum_loc
, OPT_Wpedantic
,
2565 "ISO C forbids forward references to %<enum%> types");
2570 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2572 struct-or-union-specifier:
2573 struct-or-union attributes[opt] identifier[opt]
2574 { struct-contents } attributes[opt]
2575 struct-or-union attributes[opt] identifier
2578 struct-declaration-list
2580 struct-declaration-list:
2581 struct-declaration ;
2582 struct-declaration-list struct-declaration ;
2589 struct-declaration-list struct-declaration
2591 struct-declaration-list:
2592 struct-declaration-list ;
2595 (Note that in the syntax here, unlike that in ISO C, the semicolons
2596 are included here rather than in struct-declaration, in order to
2597 describe the syntax with extra semicolons and missing semicolon at
2602 struct-declaration-list:
2603 @defs ( class-name )
2605 (Note this does not include a trailing semicolon, but can be
2606 followed by further declarations, and gets a pedwarn-if-pedantic
2607 when followed by a semicolon.) */
2609 static struct c_typespec
2610 c_parser_struct_or_union_specifier (c_parser
*parser
)
2612 struct c_typespec ret
;
2614 tree ident
= NULL_TREE
;
2615 location_t struct_loc
;
2616 location_t ident_loc
= UNKNOWN_LOCATION
;
2617 enum tree_code code
;
2618 switch (c_parser_peek_token (parser
)->keyword
)
2629 struct_loc
= c_parser_peek_token (parser
)->location
;
2630 c_parser_consume_token (parser
);
2631 attrs
= c_parser_attributes (parser
);
2633 /* Set the location in case we create a decl now. */
2634 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2636 if (c_parser_next_token_is (parser
, CPP_NAME
))
2638 ident
= c_parser_peek_token (parser
)->value
;
2639 ident_loc
= c_parser_peek_token (parser
)->location
;
2640 struct_loc
= ident_loc
;
2641 c_parser_consume_token (parser
);
2643 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2645 /* Parse a struct or union definition. Start the scope of the
2646 tag before parsing components. */
2647 struct c_struct_parse_info
*struct_info
;
2648 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2650 /* We chain the components in reverse order, then put them in
2651 forward order at the end. Each struct-declaration may
2652 declare multiple components (comma-separated), so we must use
2653 chainon to join them, although when parsing each
2654 struct-declaration we can use TREE_CHAIN directly.
2656 The theory behind all this is that there will be more
2657 semicolon separated fields than comma separated fields, and
2658 so we'll be minimizing the number of node traversals required
2661 timevar_push (TV_PARSE_STRUCT
);
2662 contents
= NULL_TREE
;
2663 c_parser_consume_token (parser
);
2664 /* Handle the Objective-C @defs construct,
2665 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2666 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2669 gcc_assert (c_dialect_objc ());
2670 c_parser_consume_token (parser
);
2671 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2673 if (c_parser_next_token_is (parser
, CPP_NAME
)
2674 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2676 name
= c_parser_peek_token (parser
)->value
;
2677 c_parser_consume_token (parser
);
2681 c_parser_error (parser
, "expected class name");
2682 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2685 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2687 contents
= nreverse (objc_get_class_ivars (name
));
2690 /* Parse the struct-declarations and semicolons. Problems with
2691 semicolons are diagnosed here; empty structures are diagnosed
2696 /* Parse any stray semicolon. */
2697 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2699 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2700 "extra semicolon in struct or union specified");
2701 c_parser_consume_token (parser
);
2704 /* Stop if at the end of the struct or union contents. */
2705 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2707 c_parser_consume_token (parser
);
2710 /* Accept #pragmas at struct scope. */
2711 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2713 c_parser_pragma (parser
, pragma_struct
);
2716 /* Parse some comma-separated declarations, but not the
2717 trailing semicolon if any. */
2718 decls
= c_parser_struct_declaration (parser
);
2719 contents
= chainon (decls
, contents
);
2720 /* If no semicolon follows, either we have a parse error or
2721 are at the end of the struct or union and should
2723 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2724 c_parser_consume_token (parser
);
2727 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2728 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2729 "no semicolon at end of struct or union");
2730 else if (parser
->error
2731 || !c_parser_next_token_starts_declspecs (parser
))
2733 c_parser_error (parser
, "expected %<;%>");
2734 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2738 /* If we come here, we have already emitted an error
2739 for an expected `;', identifier or `(', and we also
2740 recovered already. Go on with the next field. */
2743 postfix_attrs
= c_parser_attributes (parser
);
2744 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2745 chainon (attrs
, postfix_attrs
), struct_info
);
2746 ret
.kind
= ctsk_tagdef
;
2747 ret
.expr
= NULL_TREE
;
2748 ret
.expr_const_operands
= true;
2749 timevar_pop (TV_PARSE_STRUCT
);
2754 c_parser_error (parser
, "expected %<{%>");
2755 ret
.spec
= error_mark_node
;
2756 ret
.kind
= ctsk_tagref
;
2757 ret
.expr
= NULL_TREE
;
2758 ret
.expr_const_operands
= true;
2761 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2765 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2766 the trailing semicolon.
2769 specifier-qualifier-list struct-declarator-list
2770 static_assert-declaration-no-semi
2772 specifier-qualifier-list:
2773 type-specifier specifier-qualifier-list[opt]
2774 type-qualifier specifier-qualifier-list[opt]
2775 attributes specifier-qualifier-list[opt]
2777 struct-declarator-list:
2779 struct-declarator-list , attributes[opt] struct-declarator
2782 declarator attributes[opt]
2783 declarator[opt] : constant-expression attributes[opt]
2788 __extension__ struct-declaration
2789 specifier-qualifier-list
2791 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2792 of attributes where shown is a GNU extension. In GNU C, we accept
2793 any expression without commas in the syntax (assignment
2794 expressions, not just conditional expressions); assignment
2795 expressions will be diagnosed as non-constant. */
2798 c_parser_struct_declaration (c_parser
*parser
)
2800 struct c_declspecs
*specs
;
2802 tree all_prefix_attrs
;
2804 location_t decl_loc
;
2805 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2809 ext
= disable_extension_diagnostics ();
2810 c_parser_consume_token (parser
);
2811 decl
= c_parser_struct_declaration (parser
);
2812 restore_extension_diagnostics (ext
);
2815 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2817 c_parser_static_assert_declaration_no_semi (parser
);
2820 specs
= build_null_declspecs ();
2821 decl_loc
= c_parser_peek_token (parser
)->location
;
2822 /* Strictly by the standard, we shouldn't allow _Alignas here,
2823 but it appears to have been intended to allow it there, so
2824 we're keeping it as it is until WG14 reaches a conclusion
2826 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2827 c_parser_declspecs (parser
, specs
, false, true, true,
2828 true, false, cla_nonabstract_decl
);
2831 if (!specs
->declspecs_seen_p
)
2833 c_parser_error (parser
, "expected specifier-qualifier-list");
2836 finish_declspecs (specs
);
2837 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2838 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2841 if (specs
->typespec_kind
== ctsk_none
)
2843 pedwarn (decl_loc
, OPT_Wpedantic
,
2844 "ISO C forbids member declarations with no members");
2845 shadow_tag_warned (specs
, pedantic
);
2850 /* Support for unnamed structs or unions as members of
2851 structs or unions (which is [a] useful and [b] supports
2855 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2856 build_id_declarator (NULL_TREE
), specs
,
2859 decl_attributes (&ret
, attrs
, 0);
2864 /* Provide better error recovery. Note that a type name here is valid,
2865 and will be treated as a field name. */
2866 if (specs
->typespec_kind
== ctsk_tagdef
2867 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2868 && c_parser_next_token_starts_declspecs (parser
)
2869 && !c_parser_next_token_is (parser
, CPP_NAME
))
2871 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2872 parser
->error
= false;
2876 pending_xref_error ();
2877 prefix_attrs
= specs
->attrs
;
2878 all_prefix_attrs
= prefix_attrs
;
2879 specs
->attrs
= NULL_TREE
;
2883 /* Declaring one or more declarators or un-named bit-fields. */
2884 struct c_declarator
*declarator
;
2886 if (c_parser_next_token_is (parser
, CPP_COLON
))
2887 declarator
= build_id_declarator (NULL_TREE
);
2889 declarator
= c_parser_declarator (parser
,
2890 specs
->typespec_kind
!= ctsk_none
,
2891 C_DTR_NORMAL
, &dummy
);
2892 if (declarator
== NULL
)
2894 c_parser_skip_to_end_of_block_or_statement (parser
);
2897 if (c_parser_next_token_is (parser
, CPP_COLON
)
2898 || c_parser_next_token_is (parser
, CPP_COMMA
)
2899 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2900 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2901 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2903 tree postfix_attrs
= NULL_TREE
;
2904 tree width
= NULL_TREE
;
2906 if (c_parser_next_token_is (parser
, CPP_COLON
))
2908 c_parser_consume_token (parser
);
2909 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2911 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2912 postfix_attrs
= c_parser_attributes (parser
);
2913 d
= grokfield (c_parser_peek_token (parser
)->location
,
2914 declarator
, specs
, width
, &all_prefix_attrs
);
2915 decl_attributes (&d
, chainon (postfix_attrs
,
2916 all_prefix_attrs
), 0);
2917 DECL_CHAIN (d
) = decls
;
2919 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2920 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2923 all_prefix_attrs
= prefix_attrs
;
2924 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2925 c_parser_consume_token (parser
);
2926 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2927 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2929 /* Semicolon consumed in caller. */
2934 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2940 c_parser_error (parser
,
2941 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2942 "%<__attribute__%>");
2949 /* Parse a typeof specifier (a GNU extension).
2952 typeof ( expression )
2953 typeof ( type-name )
2956 static struct c_typespec
2957 c_parser_typeof_specifier (c_parser
*parser
)
2959 struct c_typespec ret
;
2960 ret
.kind
= ctsk_typeof
;
2961 ret
.spec
= error_mark_node
;
2962 ret
.expr
= NULL_TREE
;
2963 ret
.expr_const_operands
= true;
2964 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2965 c_parser_consume_token (parser
);
2966 c_inhibit_evaluation_warnings
++;
2968 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2970 c_inhibit_evaluation_warnings
--;
2974 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2976 struct c_type_name
*type
= c_parser_type_name (parser
);
2977 c_inhibit_evaluation_warnings
--;
2981 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2982 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2988 location_t here
= c_parser_peek_token (parser
)->location
;
2989 struct c_expr expr
= c_parser_expression (parser
);
2990 c_inhibit_evaluation_warnings
--;
2992 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2993 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2994 error_at (here
, "%<typeof%> applied to a bit-field");
2995 mark_exp_read (expr
.value
);
2996 ret
.spec
= TREE_TYPE (expr
.value
);
2997 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2998 /* This is returned with the type so that when the type is
2999 evaluated, this can be evaluated. */
3001 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3002 pop_maybe_used (was_vm
);
3003 /* For use in macros such as those in <stdatomic.h>, remove
3004 _Atomic and const qualifiers from atomic types. (Possibly
3005 all qualifiers should be removed; const can be an issue for
3006 more macros using typeof than just the <stdatomic.h>
3008 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3009 ret
.spec
= c_build_qualified_type (ret
.spec
,
3010 (TYPE_QUALS (ret
.spec
)
3011 & ~(TYPE_QUAL_ATOMIC
3012 | TYPE_QUAL_CONST
)));
3014 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3018 /* Parse an alignment-specifier.
3022 alignment-specifier:
3023 _Alignas ( type-name )
3024 _Alignas ( constant-expression )
3028 c_parser_alignas_specifier (c_parser
* parser
)
3030 tree ret
= error_mark_node
;
3031 location_t loc
= c_parser_peek_token (parser
)->location
;
3032 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3033 c_parser_consume_token (parser
);
3037 pedwarn (loc
, OPT_Wpedantic
,
3038 "ISO C99 does not support %<_Alignas%>");
3040 pedwarn (loc
, OPT_Wpedantic
,
3041 "ISO C90 does not support %<_Alignas%>");
3043 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3045 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3047 struct c_type_name
*type
= c_parser_type_name (parser
);
3049 ret
= c_alignof (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
)
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 /* A diagnostic is not required for the use of this identifier in
6451 the implementation namespace; only diagnose it for the C11
6452 spelling because of existing code using the other spellings. */
6454 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6457 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6460 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6463 c_parser_consume_token (parser
);
6464 c_inhibit_evaluation_warnings
++;
6466 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6467 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6469 /* Either __alignof__ ( type-name ) or __alignof__
6470 unary-expression starting with a compound literal. */
6472 struct c_type_name
*type_name
;
6474 c_parser_consume_token (parser
);
6475 loc
= c_parser_peek_token (parser
)->location
;
6476 type_name
= c_parser_type_name (parser
);
6477 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6478 if (type_name
== NULL
)
6481 c_inhibit_evaluation_warnings
--;
6483 ret
.value
= error_mark_node
;
6484 ret
.original_code
= ERROR_MARK
;
6485 ret
.original_type
= NULL
;
6488 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6490 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6495 /* alignof ( type-name ). */
6496 c_inhibit_evaluation_warnings
--;
6498 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6499 ret
.original_code
= ERROR_MARK
;
6500 ret
.original_type
= NULL
;
6506 expr
= c_parser_unary_expression (parser
);
6508 mark_exp_read (expr
.value
);
6509 c_inhibit_evaluation_warnings
--;
6511 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6513 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6514 ret
.original_code
= ERROR_MARK
;
6515 ret
.original_type
= NULL
;
6520 /* Helper function to read arguments of builtins which are interfaces
6521 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6522 others. The name of the builtin is passed using BNAME parameter.
6523 Function returns true if there were no errors while parsing and
6524 stores the arguments in CEXPR_LIST. */
6526 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6527 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6530 location_t loc
= c_parser_peek_token (parser
)->location
;
6531 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6533 bool saved_force_folding_builtin_constant_p
;
6535 *ret_cexpr_list
= NULL
;
6536 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6538 error_at (loc
, "cannot take address of %qs", bname
);
6542 c_parser_consume_token (parser
);
6544 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6546 c_parser_consume_token (parser
);
6550 saved_force_folding_builtin_constant_p
6551 = force_folding_builtin_constant_p
;
6552 force_folding_builtin_constant_p
|= choose_expr_p
;
6553 expr
= c_parser_expr_no_commas (parser
, NULL
);
6554 force_folding_builtin_constant_p
6555 = saved_force_folding_builtin_constant_p
;
6556 vec_alloc (cexpr_list
, 1);
6557 C_EXPR_APPEND (cexpr_list
, expr
);
6558 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6560 c_parser_consume_token (parser
);
6561 expr
= c_parser_expr_no_commas (parser
, NULL
);
6562 C_EXPR_APPEND (cexpr_list
, expr
);
6565 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6568 *ret_cexpr_list
= cexpr_list
;
6572 /* This represents a single generic-association. */
6574 struct c_generic_association
6576 /* The location of the starting token of the type. */
6577 location_t type_location
;
6578 /* The association's type, or NULL_TREE for 'default'. */
6580 /* The association's expression. */
6581 struct c_expr expression
;
6584 /* Parse a generic-selection. (C11 6.5.1.1).
6587 _Generic ( assignment-expression , generic-assoc-list )
6591 generic-assoc-list , generic-association
6593 generic-association:
6594 type-name : assignment-expression
6595 default : assignment-expression
6598 static struct c_expr
6599 c_parser_generic_selection (c_parser
*parser
)
6601 vec
<c_generic_association
> associations
= vNULL
;
6602 struct c_expr selector
, error_expr
;
6604 struct c_generic_association matched_assoc
;
6605 bool match_found
= false;
6606 location_t generic_loc
, selector_loc
;
6608 error_expr
.original_code
= ERROR_MARK
;
6609 error_expr
.original_type
= NULL
;
6610 error_expr
.value
= error_mark_node
;
6611 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6612 matched_assoc
.type
= NULL_TREE
;
6613 matched_assoc
.expression
= error_expr
;
6615 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6616 generic_loc
= c_parser_peek_token (parser
)->location
;
6617 c_parser_consume_token (parser
);
6621 pedwarn (generic_loc
, OPT_Wpedantic
,
6622 "ISO C99 does not support %<_Generic%>");
6624 pedwarn (generic_loc
, OPT_Wpedantic
,
6625 "ISO C90 does not support %<_Generic%>");
6628 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6631 c_inhibit_evaluation_warnings
++;
6632 selector_loc
= c_parser_peek_token (parser
)->location
;
6633 selector
= c_parser_expr_no_commas (parser
, NULL
);
6634 selector
= default_function_array_conversion (selector_loc
, selector
);
6635 c_inhibit_evaluation_warnings
--;
6637 if (selector
.value
== error_mark_node
)
6639 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6642 selector_type
= TREE_TYPE (selector
.value
);
6643 /* In ISO C terms, rvalues (including the controlling expression of
6644 _Generic) do not have qualified types. */
6645 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6646 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6647 /* In ISO C terms, _Noreturn is not part of the type of expressions
6648 such as &abort, but in GCC it is represented internally as a type
6650 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6651 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6653 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6655 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6657 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6663 struct c_generic_association assoc
, *iter
;
6665 c_token
*token
= c_parser_peek_token (parser
);
6667 assoc
.type_location
= token
->location
;
6668 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6670 c_parser_consume_token (parser
);
6671 assoc
.type
= NULL_TREE
;
6675 struct c_type_name
*type_name
;
6677 type_name
= c_parser_type_name (parser
);
6678 if (type_name
== NULL
)
6680 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6683 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6684 if (assoc
.type
== error_mark_node
)
6686 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6690 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6691 error_at (assoc
.type_location
,
6692 "%<_Generic%> association has function type");
6693 else if (!COMPLETE_TYPE_P (assoc
.type
))
6694 error_at (assoc
.type_location
,
6695 "%<_Generic%> association has incomplete type");
6697 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6698 error_at (assoc
.type_location
,
6699 "%<_Generic%> association has "
6700 "variable length type");
6703 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6705 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6709 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6710 if (assoc
.expression
.value
== error_mark_node
)
6712 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6716 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6718 if (assoc
.type
== NULL_TREE
)
6720 if (iter
->type
== NULL_TREE
)
6722 error_at (assoc
.type_location
,
6723 "duplicate %<default%> case in %<_Generic%>");
6724 inform (iter
->type_location
, "original %<default%> is here");
6727 else if (iter
->type
!= NULL_TREE
)
6729 if (comptypes (assoc
.type
, iter
->type
))
6731 error_at (assoc
.type_location
,
6732 "%<_Generic%> specifies two compatible types");
6733 inform (iter
->type_location
, "compatible type is here");
6738 if (assoc
.type
== NULL_TREE
)
6742 matched_assoc
= assoc
;
6746 else if (comptypes (assoc
.type
, selector_type
))
6748 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6750 matched_assoc
= assoc
;
6755 error_at (assoc
.type_location
,
6756 "%<_Generic> selector matches multiple associations");
6757 inform (matched_assoc
.type_location
,
6758 "other match is here");
6762 associations
.safe_push (assoc
);
6764 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6766 c_parser_consume_token (parser
);
6769 associations
.release ();
6771 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6773 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6779 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6780 "compatible with any association",
6785 return matched_assoc
.expression
;
6788 associations
.release ();
6792 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6796 postfix-expression [ expression ]
6797 postfix-expression ( argument-expression-list[opt] )
6798 postfix-expression . identifier
6799 postfix-expression -> identifier
6800 postfix-expression ++
6801 postfix-expression --
6802 ( type-name ) { initializer-list }
6803 ( type-name ) { initializer-list , }
6805 argument-expression-list:
6807 argument-expression-list , argument-expression
6820 (treated as a keyword in GNU C)
6823 ( compound-statement )
6824 __builtin_va_arg ( assignment-expression , type-name )
6825 __builtin_offsetof ( type-name , offsetof-member-designator )
6826 __builtin_choose_expr ( assignment-expression ,
6827 assignment-expression ,
6828 assignment-expression )
6829 __builtin_types_compatible_p ( type-name , type-name )
6830 __builtin_complex ( assignment-expression , assignment-expression )
6831 __builtin_shuffle ( assignment-expression , assignment-expression )
6832 __builtin_shuffle ( assignment-expression ,
6833 assignment-expression ,
6834 assignment-expression, )
6836 offsetof-member-designator:
6838 offsetof-member-designator . identifier
6839 offsetof-member-designator [ expression ]
6844 [ objc-receiver objc-message-args ]
6845 @selector ( objc-selector-arg )
6846 @protocol ( identifier )
6847 @encode ( type-name )
6849 Classname . identifier
6852 static struct c_expr
6853 c_parser_postfix_expression (c_parser
*parser
)
6855 struct c_expr expr
, e1
;
6856 struct c_type_name
*t1
, *t2
;
6857 location_t loc
= c_parser_peek_token (parser
)->location
;;
6858 expr
.original_code
= ERROR_MARK
;
6859 expr
.original_type
= NULL
;
6860 switch (c_parser_peek_token (parser
)->type
)
6863 expr
.value
= c_parser_peek_token (parser
)->value
;
6864 loc
= c_parser_peek_token (parser
)->location
;
6865 c_parser_consume_token (parser
);
6866 if (TREE_CODE (expr
.value
) == FIXED_CST
6867 && !targetm
.fixed_point_supported_p ())
6869 error_at (loc
, "fixed-point types not supported for this target");
6870 expr
.value
= error_mark_node
;
6877 expr
.value
= c_parser_peek_token (parser
)->value
;
6878 c_parser_consume_token (parser
);
6884 case CPP_UTF8STRING
:
6885 expr
.value
= c_parser_peek_token (parser
)->value
;
6886 expr
.original_code
= STRING_CST
;
6887 c_parser_consume_token (parser
);
6889 case CPP_OBJC_STRING
:
6890 gcc_assert (c_dialect_objc ());
6892 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6893 c_parser_consume_token (parser
);
6896 switch (c_parser_peek_token (parser
)->id_kind
)
6900 tree id
= c_parser_peek_token (parser
)->value
;
6901 c_parser_consume_token (parser
);
6902 expr
.value
= build_external_ref (loc
, id
,
6903 (c_parser_peek_token (parser
)->type
6905 &expr
.original_type
);
6908 case C_ID_CLASSNAME
:
6910 /* Here we parse the Objective-C 2.0 Class.name dot
6912 tree class_name
= c_parser_peek_token (parser
)->value
;
6914 c_parser_consume_token (parser
);
6915 gcc_assert (c_dialect_objc ());
6916 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6918 expr
.value
= error_mark_node
;
6921 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6923 c_parser_error (parser
, "expected identifier");
6924 expr
.value
= error_mark_node
;
6927 component
= c_parser_peek_token (parser
)->value
;
6928 c_parser_consume_token (parser
);
6929 expr
.value
= objc_build_class_component_ref (class_name
,
6934 c_parser_error (parser
, "expected expression");
6935 expr
.value
= error_mark_node
;
6939 case CPP_OPEN_PAREN
:
6940 /* A parenthesized expression, statement expression or compound
6942 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6944 /* A statement expression. */
6946 location_t brace_loc
;
6947 c_parser_consume_token (parser
);
6948 brace_loc
= c_parser_peek_token (parser
)->location
;
6949 c_parser_consume_token (parser
);
6950 if (!building_stmt_list_p ())
6952 error_at (loc
, "braced-group within expression allowed "
6953 "only inside a function");
6954 parser
->error
= true;
6955 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6956 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6957 expr
.value
= error_mark_node
;
6960 stmt
= c_begin_stmt_expr ();
6961 c_parser_compound_statement_nostart (parser
);
6962 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6964 pedwarn (loc
, OPT_Wpedantic
,
6965 "ISO C forbids braced-groups within expressions");
6966 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6967 mark_exp_read (expr
.value
);
6969 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6971 /* A compound literal. ??? Can we actually get here rather
6972 than going directly to
6973 c_parser_postfix_expression_after_paren_type from
6976 struct c_type_name
*type_name
;
6977 c_parser_consume_token (parser
);
6978 loc
= c_parser_peek_token (parser
)->location
;
6979 type_name
= c_parser_type_name (parser
);
6980 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6982 if (type_name
== NULL
)
6984 expr
.value
= error_mark_node
;
6987 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6993 /* A parenthesized expression. */
6994 c_parser_consume_token (parser
);
6995 expr
= c_parser_expression (parser
);
6996 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6997 TREE_NO_WARNING (expr
.value
) = 1;
6998 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6999 expr
.original_code
= ERROR_MARK
;
7000 /* Don't change EXPR.ORIGINAL_TYPE. */
7001 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7006 switch (c_parser_peek_token (parser
)->keyword
)
7008 case RID_FUNCTION_NAME
:
7009 case RID_PRETTY_FUNCTION_NAME
:
7010 case RID_C99_FUNCTION_NAME
:
7011 expr
.value
= fname_decl (loc
,
7012 c_parser_peek_token (parser
)->keyword
,
7013 c_parser_peek_token (parser
)->value
);
7014 c_parser_consume_token (parser
);
7017 c_parser_consume_token (parser
);
7018 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7020 expr
.value
= error_mark_node
;
7023 e1
= c_parser_expr_no_commas (parser
, NULL
);
7024 mark_exp_read (e1
.value
);
7025 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7026 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7028 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7029 expr
.value
= error_mark_node
;
7032 loc
= c_parser_peek_token (parser
)->location
;
7033 t1
= c_parser_type_name (parser
);
7034 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7038 expr
.value
= error_mark_node
;
7042 tree type_expr
= NULL_TREE
;
7043 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7044 groktypename (t1
, &type_expr
, NULL
));
7047 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7048 TREE_TYPE (expr
.value
), type_expr
,
7050 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7055 c_parser_consume_token (parser
);
7056 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7058 expr
.value
= error_mark_node
;
7061 t1
= c_parser_type_name (parser
);
7063 parser
->error
= true;
7064 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7065 gcc_assert (parser
->error
);
7068 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7069 expr
.value
= error_mark_node
;
7074 tree type
= groktypename (t1
, NULL
, NULL
);
7076 if (type
== error_mark_node
)
7077 offsetof_ref
= error_mark_node
;
7080 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7081 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7083 /* Parse the second argument to __builtin_offsetof. We
7084 must have one identifier, and beyond that we want to
7085 accept sub structure and sub array references. */
7086 if (c_parser_next_token_is (parser
, CPP_NAME
))
7088 offsetof_ref
= build_component_ref
7089 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7090 c_parser_consume_token (parser
);
7091 while (c_parser_next_token_is (parser
, CPP_DOT
)
7092 || c_parser_next_token_is (parser
,
7094 || c_parser_next_token_is (parser
,
7097 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7099 loc
= c_parser_peek_token (parser
)->location
;
7100 offsetof_ref
= build_array_ref (loc
,
7105 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7108 c_parser_consume_token (parser
);
7109 if (c_parser_next_token_is_not (parser
,
7112 c_parser_error (parser
, "expected identifier");
7115 offsetof_ref
= build_component_ref
7117 c_parser_peek_token (parser
)->value
);
7118 c_parser_consume_token (parser
);
7124 loc
= c_parser_peek_token (parser
)->location
;
7125 c_parser_consume_token (parser
);
7126 ce
= c_parser_expression (parser
);
7127 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7129 idx
= c_fully_fold (idx
, false, NULL
);
7130 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7132 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7137 c_parser_error (parser
, "expected identifier");
7138 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7140 expr
.value
= fold_offsetof (offsetof_ref
);
7143 case RID_CHOOSE_EXPR
:
7145 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7146 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7149 c_parser_consume_token (parser
);
7150 if (!c_parser_get_builtin_args (parser
,
7151 "__builtin_choose_expr",
7154 expr
.value
= error_mark_node
;
7158 if (vec_safe_length (cexpr_list
) != 3)
7160 error_at (loc
, "wrong number of arguments to "
7161 "%<__builtin_choose_expr%>");
7162 expr
.value
= error_mark_node
;
7166 e1_p
= &(*cexpr_list
)[0];
7167 e2_p
= &(*cexpr_list
)[1];
7168 e3_p
= &(*cexpr_list
)[2];
7171 mark_exp_read (e2_p
->value
);
7172 mark_exp_read (e3_p
->value
);
7173 if (TREE_CODE (c
) != INTEGER_CST
7174 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7176 "first argument to %<__builtin_choose_expr%> not"
7178 constant_expression_warning (c
);
7179 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7182 case RID_TYPES_COMPATIBLE_P
:
7183 c_parser_consume_token (parser
);
7184 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7186 expr
.value
= error_mark_node
;
7189 t1
= c_parser_type_name (parser
);
7192 expr
.value
= error_mark_node
;
7195 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7197 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7198 expr
.value
= error_mark_node
;
7201 t2
= c_parser_type_name (parser
);
7204 expr
.value
= error_mark_node
;
7207 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7211 e1
= groktypename (t1
, NULL
, NULL
);
7212 e2
= groktypename (t2
, NULL
, NULL
);
7213 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7215 expr
.value
= error_mark_node
;
7219 e1
= TYPE_MAIN_VARIANT (e1
);
7220 e2
= TYPE_MAIN_VARIANT (e2
);
7223 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7226 case RID_BUILTIN_COMPLEX
:
7228 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7229 c_expr_t
*e1_p
, *e2_p
;
7231 c_parser_consume_token (parser
);
7232 if (!c_parser_get_builtin_args (parser
,
7233 "__builtin_complex",
7234 &cexpr_list
, false))
7236 expr
.value
= error_mark_node
;
7240 if (vec_safe_length (cexpr_list
) != 2)
7242 error_at (loc
, "wrong number of arguments to "
7243 "%<__builtin_complex%>");
7244 expr
.value
= error_mark_node
;
7248 e1_p
= &(*cexpr_list
)[0];
7249 e2_p
= &(*cexpr_list
)[1];
7251 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7252 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7253 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7254 TREE_OPERAND (e1_p
->value
, 0));
7255 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7256 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7257 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7258 TREE_OPERAND (e2_p
->value
, 0));
7259 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7260 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7261 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7262 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7264 error_at (loc
, "%<__builtin_complex%> operand "
7265 "not of real binary floating-point type");
7266 expr
.value
= error_mark_node
;
7269 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7270 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7273 "%<__builtin_complex%> operands of different types");
7274 expr
.value
= error_mark_node
;
7278 pedwarn (loc
, OPT_Wpedantic
,
7279 "ISO C90 does not support complex types");
7280 expr
.value
= build2 (COMPLEX_EXPR
,
7283 (TREE_TYPE (e1_p
->value
))),
7284 e1_p
->value
, e2_p
->value
);
7287 case RID_BUILTIN_SHUFFLE
:
7289 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7293 c_parser_consume_token (parser
);
7294 if (!c_parser_get_builtin_args (parser
,
7295 "__builtin_shuffle",
7296 &cexpr_list
, false))
7298 expr
.value
= error_mark_node
;
7302 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7303 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7305 if (vec_safe_length (cexpr_list
) == 2)
7307 c_build_vec_perm_expr
7308 (loc
, (*cexpr_list
)[0].value
,
7309 NULL_TREE
, (*cexpr_list
)[1].value
);
7311 else if (vec_safe_length (cexpr_list
) == 3)
7313 c_build_vec_perm_expr
7314 (loc
, (*cexpr_list
)[0].value
,
7315 (*cexpr_list
)[1].value
,
7316 (*cexpr_list
)[2].value
);
7319 error_at (loc
, "wrong number of arguments to "
7320 "%<__builtin_shuffle%>");
7321 expr
.value
= error_mark_node
;
7325 case RID_AT_SELECTOR
:
7326 gcc_assert (c_dialect_objc ());
7327 c_parser_consume_token (parser
);
7328 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7330 expr
.value
= error_mark_node
;
7334 tree sel
= c_parser_objc_selector_arg (parser
);
7335 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7337 expr
.value
= objc_build_selector_expr (loc
, sel
);
7340 case RID_AT_PROTOCOL
:
7341 gcc_assert (c_dialect_objc ());
7342 c_parser_consume_token (parser
);
7343 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7345 expr
.value
= error_mark_node
;
7348 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7350 c_parser_error (parser
, "expected identifier");
7351 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7352 expr
.value
= error_mark_node
;
7356 tree id
= c_parser_peek_token (parser
)->value
;
7357 c_parser_consume_token (parser
);
7358 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7360 expr
.value
= objc_build_protocol_expr (id
);
7364 /* Extension to support C-structures in the archiver. */
7365 gcc_assert (c_dialect_objc ());
7366 c_parser_consume_token (parser
);
7367 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7369 expr
.value
= error_mark_node
;
7372 t1
= c_parser_type_name (parser
);
7375 expr
.value
= error_mark_node
;
7376 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7379 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7382 tree type
= groktypename (t1
, NULL
, NULL
);
7383 expr
.value
= objc_build_encode_expr (type
);
7387 expr
= c_parser_generic_selection (parser
);
7389 case RID_CILK_SPAWN
:
7390 c_parser_consume_token (parser
);
7391 if (!flag_enable_cilkplus
)
7393 error_at (loc
, "-fcilkplus must be enabled to use "
7395 expr
= c_parser_postfix_expression (parser
);
7396 expr
.value
= error_mark_node
;
7398 if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7400 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7401 "are not permitted");
7402 /* Now flush out all the _Cilk_spawns. */
7403 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7404 c_parser_consume_token (parser
);
7405 expr
= c_parser_postfix_expression (parser
);
7409 expr
= c_parser_postfix_expression (parser
);
7410 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7414 c_parser_error (parser
, "expected expression");
7415 expr
.value
= error_mark_node
;
7419 case CPP_OPEN_SQUARE
:
7420 if (c_dialect_objc ())
7422 tree receiver
, args
;
7423 c_parser_consume_token (parser
);
7424 receiver
= c_parser_objc_receiver (parser
);
7425 args
= c_parser_objc_message_args (parser
);
7426 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7428 expr
.value
= objc_build_message_expr (receiver
, args
);
7431 /* Else fall through to report error. */
7433 c_parser_error (parser
, "expected expression");
7434 expr
.value
= error_mark_node
;
7437 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7440 /* Parse a postfix expression after a parenthesized type name: the
7441 brace-enclosed initializer of a compound literal, possibly followed
7442 by some postfix operators. This is separate because it is not
7443 possible to tell until after the type name whether a cast
7444 expression has a cast or a compound literal, or whether the operand
7445 of sizeof is a parenthesized type name or starts with a compound
7446 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7447 location of the first token after the parentheses around the type
7450 static struct c_expr
7451 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7452 struct c_type_name
*type_name
,
7453 location_t type_loc
)
7459 location_t start_loc
;
7460 tree type_expr
= NULL_TREE
;
7461 bool type_expr_const
= true;
7462 check_compound_literal_type (type_loc
, type_name
);
7463 start_init (NULL_TREE
, NULL
, 0);
7464 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7465 start_loc
= c_parser_peek_token (parser
)->location
;
7466 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7468 error_at (type_loc
, "compound literal has variable size");
7469 type
= error_mark_node
;
7471 init
= c_parser_braced_init (parser
, type
, false);
7473 maybe_warn_string_init (type
, init
);
7475 if (type
!= error_mark_node
7476 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7477 && current_function_decl
)
7479 error ("compound literal qualified by address-space qualifier");
7480 type
= error_mark_node
;
7484 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7485 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7486 ? CONSTRUCTOR_NON_CONST (init
.value
)
7487 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7488 non_const
|= !type_expr_const
;
7489 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7490 expr
.original_code
= ERROR_MARK
;
7491 expr
.original_type
= NULL
;
7494 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7496 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7497 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7501 gcc_assert (!non_const
);
7502 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7503 type_expr
, expr
.value
);
7506 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7509 /* Callback function for sizeof_pointer_memaccess_warning to compare
7513 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7515 return comptypes (type1
, type2
) == 1;
7518 /* Parse a postfix expression after the initial primary or compound
7519 literal; that is, parse a series of postfix operators.
7521 EXPR_LOC is the location of the primary expression. */
7523 static struct c_expr
7524 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7525 location_t expr_loc
,
7528 struct c_expr orig_expr
;
7530 location_t sizeof_arg_loc
[3];
7533 vec
<tree
, va_gc
> *exprlist
;
7534 vec
<tree
, va_gc
> *origtypes
= NULL
;
7537 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7538 switch (c_parser_peek_token (parser
)->type
)
7540 case CPP_OPEN_SQUARE
:
7541 /* Array reference. */
7542 c_parser_consume_token (parser
);
7543 if (flag_enable_cilkplus
7544 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7545 /* If we are here, then we have something like this:
7548 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7552 idx
= c_parser_expression (parser
).value
;
7553 /* Here we have 3 options:
7554 1. Array [EXPR] -- Normal Array call.
7555 2. Array [EXPR : EXPR] -- Array notation without stride.
7556 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7558 For 1, we just handle it just like a normal array expression.
7559 For 2 and 3 we handle it like we handle array notations. The
7560 idx value we have above becomes the initial/start index.
7562 if (flag_enable_cilkplus
7563 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7564 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7568 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7570 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7573 expr
.original_code
= ERROR_MARK
;
7574 expr
.original_type
= NULL
;
7576 case CPP_OPEN_PAREN
:
7577 /* Function call. */
7578 c_parser_consume_token (parser
);
7579 for (i
= 0; i
< 3; i
++)
7581 sizeof_arg
[i
] = NULL_TREE
;
7582 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7584 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7587 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7588 sizeof_arg_loc
, sizeof_arg
);
7589 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7592 mark_exp_read (expr
.value
);
7593 if (warn_sizeof_pointer_memaccess
)
7594 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7595 expr
.value
, exprlist
,
7597 sizeof_ptr_memacc_comptypes
);
7598 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7599 "(" after the FUNCNAME, which is what we have now. */
7600 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7602 expr
.original_code
= ERROR_MARK
;
7603 if (TREE_CODE (expr
.value
) == INTEGER_CST
7604 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7605 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7606 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7607 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7608 expr
.original_type
= NULL
;
7611 release_tree_vector (exprlist
);
7612 release_tree_vector (origtypes
);
7616 /* Structure element reference. */
7617 c_parser_consume_token (parser
);
7618 expr
= default_function_array_conversion (expr_loc
, expr
);
7619 if (c_parser_next_token_is (parser
, CPP_NAME
))
7620 ident
= c_parser_peek_token (parser
)->value
;
7623 c_parser_error (parser
, "expected identifier");
7624 expr
.value
= error_mark_node
;
7625 expr
.original_code
= ERROR_MARK
;
7626 expr
.original_type
= NULL
;
7629 c_parser_consume_token (parser
);
7630 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7631 expr
.original_code
= ERROR_MARK
;
7632 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7633 expr
.original_type
= NULL
;
7636 /* Remember the original type of a bitfield. */
7637 tree field
= TREE_OPERAND (expr
.value
, 1);
7638 if (TREE_CODE (field
) != FIELD_DECL
)
7639 expr
.original_type
= NULL
;
7641 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7645 /* Structure element reference. */
7646 c_parser_consume_token (parser
);
7647 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7648 if (c_parser_next_token_is (parser
, CPP_NAME
))
7649 ident
= c_parser_peek_token (parser
)->value
;
7652 c_parser_error (parser
, "expected identifier");
7653 expr
.value
= error_mark_node
;
7654 expr
.original_code
= ERROR_MARK
;
7655 expr
.original_type
= NULL
;
7658 c_parser_consume_token (parser
);
7659 expr
.value
= build_component_ref (op_loc
,
7660 build_indirect_ref (op_loc
,
7664 expr
.original_code
= ERROR_MARK
;
7665 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7666 expr
.original_type
= NULL
;
7669 /* Remember the original type of a bitfield. */
7670 tree field
= TREE_OPERAND (expr
.value
, 1);
7671 if (TREE_CODE (field
) != FIELD_DECL
)
7672 expr
.original_type
= NULL
;
7674 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7678 /* Postincrement. */
7679 c_parser_consume_token (parser
);
7680 /* If the expressions have array notations, we expand them. */
7681 if (flag_enable_cilkplus
7682 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7683 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7686 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7687 expr
.value
= build_unary_op (op_loc
,
7688 POSTINCREMENT_EXPR
, expr
.value
, 0);
7690 expr
.original_code
= ERROR_MARK
;
7691 expr
.original_type
= NULL
;
7693 case CPP_MINUS_MINUS
:
7694 /* Postdecrement. */
7695 c_parser_consume_token (parser
);
7696 /* If the expressions have array notations, we expand them. */
7697 if (flag_enable_cilkplus
7698 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7699 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7702 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7703 expr
.value
= build_unary_op (op_loc
,
7704 POSTDECREMENT_EXPR
, expr
.value
, 0);
7706 expr
.original_code
= ERROR_MARK
;
7707 expr
.original_type
= NULL
;
7715 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7718 assignment-expression
7719 expression , assignment-expression
7722 static struct c_expr
7723 c_parser_expression (c_parser
*parser
)
7725 location_t tloc
= c_parser_peek_token (parser
)->location
;
7727 expr
= c_parser_expr_no_commas (parser
, NULL
);
7728 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7729 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7730 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7734 location_t loc
= c_parser_peek_token (parser
)->location
;
7735 location_t expr_loc
;
7736 c_parser_consume_token (parser
);
7737 expr_loc
= c_parser_peek_token (parser
)->location
;
7738 lhsval
= expr
.value
;
7739 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7740 lhsval
= TREE_OPERAND (lhsval
, 1);
7741 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7742 mark_exp_read (lhsval
);
7743 next
= c_parser_expr_no_commas (parser
, NULL
);
7744 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7745 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7746 expr
.original_code
= COMPOUND_EXPR
;
7747 expr
.original_type
= next
.original_type
;
7752 /* Parse an expression and convert functions or arrays to pointers and
7753 lvalues to rvalues. */
7755 static struct c_expr
7756 c_parser_expression_conv (c_parser
*parser
)
7759 location_t loc
= c_parser_peek_token (parser
)->location
;
7760 expr
= c_parser_expression (parser
);
7761 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7765 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7766 functions and arrays to pointers and lvalues to rvalues. If
7767 FOLD_P, fold the expressions.
7770 assignment-expression
7771 nonempty-expr-list , assignment-expression
7774 static vec
<tree
, va_gc
> *
7775 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7776 vec
<tree
, va_gc
> **p_orig_types
,
7777 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7779 vec
<tree
, va_gc
> *ret
;
7780 vec
<tree
, va_gc
> *orig_types
;
7782 location_t loc
= c_parser_peek_token (parser
)->location
;
7783 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7784 unsigned int idx
= 0;
7786 ret
= make_tree_vector ();
7787 if (p_orig_types
== NULL
)
7790 orig_types
= make_tree_vector ();
7792 if (sizeof_arg
!= NULL
7793 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7794 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7795 expr
= c_parser_expr_no_commas (parser
, NULL
);
7797 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7799 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7800 ret
->quick_push (expr
.value
);
7802 orig_types
->quick_push (expr
.original_type
);
7803 if (sizeof_arg
!= NULL
7804 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7805 && expr
.original_code
== SIZEOF_EXPR
)
7807 sizeof_arg
[0] = c_last_sizeof_arg
;
7808 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7810 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7812 c_parser_consume_token (parser
);
7813 loc
= c_parser_peek_token (parser
)->location
;
7814 if (sizeof_arg
!= NULL
7815 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7816 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7818 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7819 expr
= c_parser_expr_no_commas (parser
, NULL
);
7821 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7823 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7824 vec_safe_push (ret
, expr
.value
);
7826 vec_safe_push (orig_types
, expr
.original_type
);
7828 && sizeof_arg
!= NULL
7829 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7830 && expr
.original_code
== SIZEOF_EXPR
)
7832 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7833 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7837 *p_orig_types
= orig_types
;
7841 /* Parse Objective-C-specific constructs. */
7843 /* Parse an objc-class-definition.
7845 objc-class-definition:
7846 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7847 objc-class-instance-variables[opt] objc-methodprotolist @end
7848 @implementation identifier objc-superclass[opt]
7849 objc-class-instance-variables[opt]
7850 @interface identifier ( identifier ) objc-protocol-refs[opt]
7851 objc-methodprotolist @end
7852 @interface identifier ( ) objc-protocol-refs[opt]
7853 objc-methodprotolist @end
7854 @implementation identifier ( identifier )
7859 "@interface identifier (" must start "@interface identifier (
7860 identifier ) ...": objc-methodprotolist in the first production may
7861 not start with a parenthesized identifier as a declarator of a data
7862 definition with no declaration specifiers if the objc-superclass,
7863 objc-protocol-refs and objc-class-instance-variables are omitted. */
7866 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7871 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7873 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7878 c_parser_consume_token (parser
);
7879 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7881 c_parser_error (parser
, "expected identifier");
7884 id1
= c_parser_peek_token (parser
)->value
;
7885 c_parser_consume_token (parser
);
7886 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7888 /* We have a category or class extension. */
7890 tree proto
= NULL_TREE
;
7891 c_parser_consume_token (parser
);
7892 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7894 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7896 /* We have a class extension. */
7901 c_parser_error (parser
, "expected identifier or %<)%>");
7902 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7908 id2
= c_parser_peek_token (parser
)->value
;
7909 c_parser_consume_token (parser
);
7911 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7914 objc_start_category_implementation (id1
, id2
);
7917 if (c_parser_next_token_is (parser
, CPP_LESS
))
7918 proto
= c_parser_objc_protocol_refs (parser
);
7919 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7920 c_parser_objc_methodprotolist (parser
);
7921 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7922 objc_finish_interface ();
7925 if (c_parser_next_token_is (parser
, CPP_COLON
))
7927 c_parser_consume_token (parser
);
7928 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7930 c_parser_error (parser
, "expected identifier");
7933 superclass
= c_parser_peek_token (parser
)->value
;
7934 c_parser_consume_token (parser
);
7937 superclass
= NULL_TREE
;
7940 tree proto
= NULL_TREE
;
7941 if (c_parser_next_token_is (parser
, CPP_LESS
))
7942 proto
= c_parser_objc_protocol_refs (parser
);
7943 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7946 objc_start_class_implementation (id1
, superclass
);
7947 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7948 c_parser_objc_class_instance_variables (parser
);
7951 objc_continue_interface ();
7952 c_parser_objc_methodprotolist (parser
);
7953 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7954 objc_finish_interface ();
7958 objc_continue_implementation ();
7963 /* Parse objc-class-instance-variables.
7965 objc-class-instance-variables:
7966 { objc-instance-variable-decl-list[opt] }
7968 objc-instance-variable-decl-list:
7969 objc-visibility-spec
7970 objc-instance-variable-decl ;
7972 objc-instance-variable-decl-list objc-visibility-spec
7973 objc-instance-variable-decl-list objc-instance-variable-decl ;
7974 objc-instance-variable-decl-list ;
7976 objc-visibility-spec:
7981 objc-instance-variable-decl:
7986 c_parser_objc_class_instance_variables (c_parser
*parser
)
7988 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7989 c_parser_consume_token (parser
);
7990 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7993 /* Parse any stray semicolon. */
7994 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7996 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7998 c_parser_consume_token (parser
);
8001 /* Stop if at the end of the instance variables. */
8002 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8004 c_parser_consume_token (parser
);
8007 /* Parse any objc-visibility-spec. */
8008 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8010 c_parser_consume_token (parser
);
8011 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8014 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8016 c_parser_consume_token (parser
);
8017 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8020 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8022 c_parser_consume_token (parser
);
8023 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8026 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8028 c_parser_consume_token (parser
);
8029 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8032 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8034 c_parser_pragma (parser
, pragma_external
);
8038 /* Parse some comma-separated declarations. */
8039 decls
= c_parser_struct_declaration (parser
);
8042 /* There is a syntax error. We want to skip the offending
8043 tokens up to the next ';' (included) or '}'
8046 /* First, skip manually a ')' or ']'. This is because they
8047 reduce the nesting level, so c_parser_skip_until_found()
8048 wouldn't be able to skip past them. */
8049 c_token
*token
= c_parser_peek_token (parser
);
8050 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8051 c_parser_consume_token (parser
);
8053 /* Then, do the standard skipping. */
8054 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8056 /* We hopefully recovered. Start normal parsing again. */
8057 parser
->error
= false;
8062 /* Comma-separated instance variables are chained together
8063 in reverse order; add them one by one. */
8064 tree ivar
= nreverse (decls
);
8065 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8066 objc_add_instance_variable (copy_node (ivar
));
8068 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8072 /* Parse an objc-class-declaration.
8074 objc-class-declaration:
8075 @class identifier-list ;
8079 c_parser_objc_class_declaration (c_parser
*parser
)
8081 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8082 c_parser_consume_token (parser
);
8083 /* Any identifiers, including those declared as type names, are OK
8088 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8090 c_parser_error (parser
, "expected identifier");
8091 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8092 parser
->error
= false;
8095 id
= c_parser_peek_token (parser
)->value
;
8096 objc_declare_class (id
);
8097 c_parser_consume_token (parser
);
8098 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8099 c_parser_consume_token (parser
);
8103 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8106 /* Parse an objc-alias-declaration.
8108 objc-alias-declaration:
8109 @compatibility_alias identifier identifier ;
8113 c_parser_objc_alias_declaration (c_parser
*parser
)
8116 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8117 c_parser_consume_token (parser
);
8118 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8120 c_parser_error (parser
, "expected identifier");
8121 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8124 id1
= c_parser_peek_token (parser
)->value
;
8125 c_parser_consume_token (parser
);
8126 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8128 c_parser_error (parser
, "expected identifier");
8129 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8132 id2
= c_parser_peek_token (parser
)->value
;
8133 c_parser_consume_token (parser
);
8134 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8135 objc_declare_alias (id1
, id2
);
8138 /* Parse an objc-protocol-definition.
8140 objc-protocol-definition:
8141 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8142 @protocol identifier-list ;
8144 "@protocol identifier ;" should be resolved as "@protocol
8145 identifier-list ;": objc-methodprotolist may not start with a
8146 semicolon in the first alternative if objc-protocol-refs are
8150 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8152 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8154 c_parser_consume_token (parser
);
8155 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8157 c_parser_error (parser
, "expected identifier");
8160 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8161 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8163 /* Any identifiers, including those declared as type names, are
8168 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8170 c_parser_error (parser
, "expected identifier");
8173 id
= c_parser_peek_token (parser
)->value
;
8174 objc_declare_protocol (id
, attributes
);
8175 c_parser_consume_token (parser
);
8176 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8177 c_parser_consume_token (parser
);
8181 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8185 tree id
= c_parser_peek_token (parser
)->value
;
8186 tree proto
= NULL_TREE
;
8187 c_parser_consume_token (parser
);
8188 if (c_parser_next_token_is (parser
, CPP_LESS
))
8189 proto
= c_parser_objc_protocol_refs (parser
);
8190 parser
->objc_pq_context
= true;
8191 objc_start_protocol (id
, proto
, attributes
);
8192 c_parser_objc_methodprotolist (parser
);
8193 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8194 parser
->objc_pq_context
= false;
8195 objc_finish_interface ();
8199 /* Parse an objc-method-type.
8205 Return true if it is a class method (+) and false if it is
8206 an instance method (-).
8209 c_parser_objc_method_type (c_parser
*parser
)
8211 switch (c_parser_peek_token (parser
)->type
)
8214 c_parser_consume_token (parser
);
8217 c_parser_consume_token (parser
);
8224 /* Parse an objc-method-definition.
8226 objc-method-definition:
8227 objc-method-type objc-method-decl ;[opt] compound-statement
8231 c_parser_objc_method_definition (c_parser
*parser
)
8233 bool is_class_method
= c_parser_objc_method_type (parser
);
8234 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8235 parser
->objc_pq_context
= true;
8236 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8238 if (decl
== error_mark_node
)
8239 return; /* Bail here. */
8241 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8243 c_parser_consume_token (parser
);
8244 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8245 "extra semicolon in method definition specified");
8248 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8250 c_parser_error (parser
, "expected %<{%>");
8254 parser
->objc_pq_context
= false;
8255 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8257 add_stmt (c_parser_compound_statement (parser
));
8258 objc_finish_method_definition (current_function_decl
);
8262 /* This code is executed when we find a method definition
8263 outside of an @implementation context (or invalid for other
8264 reasons). Parse the method (to keep going) but do not emit
8267 c_parser_compound_statement (parser
);
8271 /* Parse an objc-methodprotolist.
8273 objc-methodprotolist:
8275 objc-methodprotolist objc-methodproto
8276 objc-methodprotolist declaration
8277 objc-methodprotolist ;
8281 The declaration is a data definition, which may be missing
8282 declaration specifiers under the same rules and diagnostics as
8283 other data definitions outside functions, and the stray semicolon
8284 is diagnosed the same way as a stray semicolon outside a
8288 c_parser_objc_methodprotolist (c_parser
*parser
)
8292 /* The list is terminated by @end. */
8293 switch (c_parser_peek_token (parser
)->type
)
8296 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8297 "ISO C does not allow extra %<;%> outside of a function");
8298 c_parser_consume_token (parser
);
8302 c_parser_objc_methodproto (parser
);
8305 c_parser_pragma (parser
, pragma_external
);
8310 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8312 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8313 c_parser_objc_at_property_declaration (parser
);
8314 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8316 objc_set_method_opt (true);
8317 c_parser_consume_token (parser
);
8319 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8321 objc_set_method_opt (false);
8322 c_parser_consume_token (parser
);
8325 c_parser_declaration_or_fndef (parser
, false, false, true,
8326 false, true, NULL
, vNULL
);
8332 /* Parse an objc-methodproto.
8335 objc-method-type objc-method-decl ;
8339 c_parser_objc_methodproto (c_parser
*parser
)
8341 bool is_class_method
= c_parser_objc_method_type (parser
);
8342 tree decl
, attributes
= NULL_TREE
;
8344 /* Remember protocol qualifiers in prototypes. */
8345 parser
->objc_pq_context
= true;
8346 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8348 /* Forget protocol qualifiers now. */
8349 parser
->objc_pq_context
= false;
8351 /* Do not allow the presence of attributes to hide an erroneous
8352 method implementation in the interface section. */
8353 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8355 c_parser_error (parser
, "expected %<;%>");
8359 if (decl
!= error_mark_node
)
8360 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8362 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8365 /* If we are at a position that method attributes may be present, check that
8366 there are not any parsed already (a syntax error) and then collect any
8367 specified at the current location. Finally, if new attributes were present,
8368 check that the next token is legal ( ';' for decls and '{' for defs). */
8371 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8376 c_parser_error (parser
,
8377 "method attributes must be specified at the end only");
8378 *attributes
= NULL_TREE
;
8382 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8383 *attributes
= c_parser_attributes (parser
);
8385 /* If there were no attributes here, just report any earlier error. */
8386 if (*attributes
== NULL_TREE
|| bad
)
8389 /* If the attributes are followed by a ; or {, then just report any earlier
8391 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8392 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8395 /* We've got attributes, but not at the end. */
8396 c_parser_error (parser
,
8397 "expected %<;%> or %<{%> after method attribute definition");
8401 /* Parse an objc-method-decl.
8404 ( objc-type-name ) objc-selector
8406 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8407 objc-keyword-selector objc-optparmlist
8410 objc-keyword-selector:
8412 objc-keyword-selector objc-keyword-decl
8415 objc-selector : ( objc-type-name ) identifier
8416 objc-selector : identifier
8417 : ( objc-type-name ) identifier
8421 objc-optparms objc-optellipsis
8425 objc-opt-parms , parameter-declaration
8433 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8434 tree
*attributes
, tree
*expr
)
8436 tree type
= NULL_TREE
;
8438 tree parms
= NULL_TREE
;
8439 bool ellipsis
= false;
8440 bool attr_err
= false;
8442 *attributes
= NULL_TREE
;
8443 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8445 c_parser_consume_token (parser
);
8446 type
= c_parser_objc_type_name (parser
);
8447 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8449 sel
= c_parser_objc_selector (parser
);
8450 /* If there is no selector, or a colon follows, we have an
8451 objc-keyword-selector. If there is a selector, and a colon does
8452 not follow, that selector ends the objc-method-decl. */
8453 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8456 tree list
= NULL_TREE
;
8459 tree atype
= NULL_TREE
, id
, keyworddecl
;
8460 tree param_attr
= NULL_TREE
;
8461 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8463 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8465 c_parser_consume_token (parser
);
8466 atype
= c_parser_objc_type_name (parser
);
8467 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8470 /* New ObjC allows attributes on method parameters. */
8471 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8472 param_attr
= c_parser_attributes (parser
);
8473 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8475 c_parser_error (parser
, "expected identifier");
8476 return error_mark_node
;
8478 id
= c_parser_peek_token (parser
)->value
;
8479 c_parser_consume_token (parser
);
8480 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8481 list
= chainon (list
, keyworddecl
);
8482 tsel
= c_parser_objc_selector (parser
);
8483 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8487 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8489 /* Parse the optional parameter list. Optional Objective-C
8490 method parameters follow the C syntax, and may include '...'
8491 to denote a variable number of arguments. */
8492 parms
= make_node (TREE_LIST
);
8493 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8495 struct c_parm
*parm
;
8496 c_parser_consume_token (parser
);
8497 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8500 c_parser_consume_token (parser
);
8501 attr_err
|= c_parser_objc_maybe_method_attributes
8502 (parser
, attributes
) ;
8505 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8508 parms
= chainon (parms
,
8509 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8514 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8518 c_parser_error (parser
, "objective-c method declaration is expected");
8519 return error_mark_node
;
8523 return error_mark_node
;
8525 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8528 /* Parse an objc-type-name.
8531 objc-type-qualifiers[opt] type-name
8532 objc-type-qualifiers[opt]
8534 objc-type-qualifiers:
8536 objc-type-qualifiers objc-type-qualifier
8538 objc-type-qualifier: one of
8539 in out inout bycopy byref oneway
8543 c_parser_objc_type_name (c_parser
*parser
)
8545 tree quals
= NULL_TREE
;
8546 struct c_type_name
*type_name
= NULL
;
8547 tree type
= NULL_TREE
;
8550 c_token
*token
= c_parser_peek_token (parser
);
8551 if (token
->type
== CPP_KEYWORD
8552 && (token
->keyword
== RID_IN
8553 || token
->keyword
== RID_OUT
8554 || token
->keyword
== RID_INOUT
8555 || token
->keyword
== RID_BYCOPY
8556 || token
->keyword
== RID_BYREF
8557 || token
->keyword
== RID_ONEWAY
))
8559 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8560 c_parser_consume_token (parser
);
8565 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8566 type_name
= c_parser_type_name (parser
);
8568 type
= groktypename (type_name
, NULL
, NULL
);
8570 /* If the type is unknown, and error has already been produced and
8571 we need to recover from the error. In that case, use NULL_TREE
8572 for the type, as if no type had been specified; this will use the
8573 default type ('id') which is good for error recovery. */
8574 if (type
== error_mark_node
)
8577 return build_tree_list (quals
, type
);
8580 /* Parse objc-protocol-refs.
8587 c_parser_objc_protocol_refs (c_parser
*parser
)
8589 tree list
= NULL_TREE
;
8590 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8591 c_parser_consume_token (parser
);
8592 /* Any identifiers, including those declared as type names, are OK
8597 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8599 c_parser_error (parser
, "expected identifier");
8602 id
= c_parser_peek_token (parser
)->value
;
8603 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8604 c_parser_consume_token (parser
);
8605 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8606 c_parser_consume_token (parser
);
8610 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8614 /* Parse an objc-try-catch-finally-statement.
8616 objc-try-catch-finally-statement:
8617 @try compound-statement objc-catch-list[opt]
8618 @try compound-statement objc-catch-list[opt] @finally compound-statement
8621 @catch ( objc-catch-parameter-declaration ) compound-statement
8622 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8624 objc-catch-parameter-declaration:
8625 parameter-declaration
8628 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8630 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8631 for C++. Keep them in sync. */
8634 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8636 location_t location
;
8639 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8640 c_parser_consume_token (parser
);
8641 location
= c_parser_peek_token (parser
)->location
;
8642 objc_maybe_warn_exceptions (location
);
8643 stmt
= c_parser_compound_statement (parser
);
8644 objc_begin_try_stmt (location
, stmt
);
8646 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8648 struct c_parm
*parm
;
8649 tree parameter_declaration
= error_mark_node
;
8650 bool seen_open_paren
= false;
8652 c_parser_consume_token (parser
);
8653 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8654 seen_open_paren
= true;
8655 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8657 /* We have "@catch (...)" (where the '...' are literally
8658 what is in the code). Skip the '...'.
8659 parameter_declaration is set to NULL_TREE, and
8660 objc_being_catch_clauses() knows that that means
8662 c_parser_consume_token (parser
);
8663 parameter_declaration
= NULL_TREE
;
8667 /* We have "@catch (NSException *exception)" or something
8668 like that. Parse the parameter declaration. */
8669 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8671 parameter_declaration
= error_mark_node
;
8673 parameter_declaration
= grokparm (parm
, NULL
);
8675 if (seen_open_paren
)
8676 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8679 /* If there was no open parenthesis, we are recovering from
8680 an error, and we are trying to figure out what mistake
8681 the user has made. */
8683 /* If there is an immediate closing parenthesis, the user
8684 probably forgot the opening one (ie, they typed "@catch
8685 NSException *e)". Parse the closing parenthesis and keep
8687 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8688 c_parser_consume_token (parser
);
8690 /* If these is no immediate closing parenthesis, the user
8691 probably doesn't know that parenthesis are required at
8692 all (ie, they typed "@catch NSException *e"). So, just
8693 forget about the closing parenthesis and keep going. */
8695 objc_begin_catch_clause (parameter_declaration
);
8696 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8697 c_parser_compound_statement_nostart (parser
);
8698 objc_finish_catch_clause ();
8700 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8702 c_parser_consume_token (parser
);
8703 location
= c_parser_peek_token (parser
)->location
;
8704 stmt
= c_parser_compound_statement (parser
);
8705 objc_build_finally_clause (location
, stmt
);
8707 objc_finish_try_stmt ();
8710 /* Parse an objc-synchronized-statement.
8712 objc-synchronized-statement:
8713 @synchronized ( expression ) compound-statement
8717 c_parser_objc_synchronized_statement (c_parser
*parser
)
8721 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8722 c_parser_consume_token (parser
);
8723 loc
= c_parser_peek_token (parser
)->location
;
8724 objc_maybe_warn_exceptions (loc
);
8725 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8727 struct c_expr ce
= c_parser_expression (parser
);
8728 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8730 expr
= c_fully_fold (expr
, false, NULL
);
8731 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8734 expr
= error_mark_node
;
8735 stmt
= c_parser_compound_statement (parser
);
8736 objc_build_synchronized (loc
, expr
, stmt
);
8739 /* Parse an objc-selector; return NULL_TREE without an error if the
8740 next token is not an objc-selector.
8745 enum struct union if else while do for switch case default
8746 break continue return goto asm sizeof typeof __alignof
8747 unsigned long const short volatile signed restrict _Complex
8748 in out inout bycopy byref oneway int char float double void _Bool
8751 ??? Why this selection of keywords but not, for example, storage
8752 class specifiers? */
8755 c_parser_objc_selector (c_parser
*parser
)
8757 c_token
*token
= c_parser_peek_token (parser
);
8758 tree value
= token
->value
;
8759 if (token
->type
== CPP_NAME
)
8761 c_parser_consume_token (parser
);
8764 if (token
->type
!= CPP_KEYWORD
)
8766 switch (token
->keyword
)
8810 c_parser_consume_token (parser
);
8817 /* Parse an objc-selector-arg.
8821 objc-keywordname-list
8823 objc-keywordname-list:
8825 objc-keywordname-list objc-keywordname
8833 c_parser_objc_selector_arg (c_parser
*parser
)
8835 tree sel
= c_parser_objc_selector (parser
);
8836 tree list
= NULL_TREE
;
8837 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8841 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8843 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8844 sel
= c_parser_objc_selector (parser
);
8845 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8851 /* Parse an objc-receiver.
8860 c_parser_objc_receiver (c_parser
*parser
)
8862 location_t loc
= c_parser_peek_token (parser
)->location
;
8864 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8865 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8866 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8868 tree id
= c_parser_peek_token (parser
)->value
;
8869 c_parser_consume_token (parser
);
8870 return objc_get_class_reference (id
);
8872 struct c_expr ce
= c_parser_expression (parser
);
8873 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8874 return c_fully_fold (ce
.value
, false, NULL
);
8877 /* Parse objc-message-args.
8881 objc-keywordarg-list
8883 objc-keywordarg-list:
8885 objc-keywordarg-list objc-keywordarg
8888 objc-selector : objc-keywordexpr
8893 c_parser_objc_message_args (c_parser
*parser
)
8895 tree sel
= c_parser_objc_selector (parser
);
8896 tree list
= NULL_TREE
;
8897 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8902 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8903 return error_mark_node
;
8904 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8905 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8906 sel
= c_parser_objc_selector (parser
);
8907 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8913 /* Parse an objc-keywordexpr.
8920 c_parser_objc_keywordexpr (c_parser
*parser
)
8923 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8925 if (vec_safe_length (expr_list
) == 1)
8927 /* Just return the expression, remove a level of
8929 ret
= (*expr_list
)[0];
8933 /* We have a comma expression, we will collapse later. */
8934 ret
= build_tree_list_vec (expr_list
);
8936 release_tree_vector (expr_list
);
8940 /* A check, needed in several places, that ObjC interface, implementation or
8941 method definitions are not prefixed by incorrect items. */
8943 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8944 struct c_declspecs
*specs
)
8946 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8947 || specs
->typespec_kind
!= ctsk_none
)
8949 c_parser_error (parser
,
8950 "no type or storage class may be specified here,");
8951 c_parser_skip_to_end_of_block_or_statement (parser
);
8957 /* Parse an Objective-C @property declaration. The syntax is:
8959 objc-property-declaration:
8960 '@property' objc-property-attributes[opt] struct-declaration ;
8962 objc-property-attributes:
8963 '(' objc-property-attribute-list ')'
8965 objc-property-attribute-list:
8966 objc-property-attribute
8967 objc-property-attribute-list, objc-property-attribute
8969 objc-property-attribute
8970 'getter' = identifier
8971 'setter' = identifier
8980 @property NSString *name;
8981 @property (readonly) id object;
8982 @property (retain, nonatomic, getter=getTheName) id name;
8983 @property int a, b, c;
8985 PS: This function is identical to cp_parser_objc_at_propery_declaration
8986 for C++. Keep them in sync. */
8988 c_parser_objc_at_property_declaration (c_parser
*parser
)
8990 /* The following variables hold the attributes of the properties as
8991 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8992 seen. When we see an attribute, we set them to 'true' (if they
8993 are boolean properties) or to the identifier (if they have an
8994 argument, ie, for getter and setter). Note that here we only
8995 parse the list of attributes, check the syntax and accumulate the
8996 attributes that we find. objc_add_property_declaration() will
8997 then process the information. */
8998 bool property_assign
= false;
8999 bool property_copy
= false;
9000 tree property_getter_ident
= NULL_TREE
;
9001 bool property_nonatomic
= false;
9002 bool property_readonly
= false;
9003 bool property_readwrite
= false;
9004 bool property_retain
= false;
9005 tree property_setter_ident
= NULL_TREE
;
9007 /* 'properties' is the list of properties that we read. Usually a
9008 single one, but maybe more (eg, in "@property int a, b, c;" there
9013 loc
= c_parser_peek_token (parser
)->location
;
9014 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9016 c_parser_consume_token (parser
); /* Eat '@property'. */
9018 /* Parse the optional attribute list... */
9019 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9022 c_parser_consume_token (parser
);
9024 /* Property attribute keywords are valid now. */
9025 parser
->objc_property_attr_context
= true;
9029 bool syntax_error
= false;
9030 c_token
*token
= c_parser_peek_token (parser
);
9033 if (token
->type
!= CPP_KEYWORD
)
9035 if (token
->type
== CPP_CLOSE_PAREN
)
9036 c_parser_error (parser
, "expected identifier");
9039 c_parser_consume_token (parser
);
9040 c_parser_error (parser
, "unknown property attribute");
9044 keyword
= token
->keyword
;
9045 c_parser_consume_token (parser
);
9048 case RID_ASSIGN
: property_assign
= true; break;
9049 case RID_COPY
: property_copy
= true; break;
9050 case RID_NONATOMIC
: property_nonatomic
= true; break;
9051 case RID_READONLY
: property_readonly
= true; break;
9052 case RID_READWRITE
: property_readwrite
= true; break;
9053 case RID_RETAIN
: property_retain
= true; break;
9057 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9059 if (keyword
== RID_GETTER
)
9060 c_parser_error (parser
,
9061 "missing %<=%> (after %<getter%> attribute)");
9063 c_parser_error (parser
,
9064 "missing %<=%> (after %<setter%> attribute)");
9065 syntax_error
= true;
9068 c_parser_consume_token (parser
); /* eat the = */
9069 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9071 c_parser_error (parser
, "expected identifier");
9072 syntax_error
= true;
9075 if (keyword
== RID_SETTER
)
9077 if (property_setter_ident
!= NULL_TREE
)
9078 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9080 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9081 c_parser_consume_token (parser
);
9082 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9083 c_parser_error (parser
, "setter name must terminate with %<:%>");
9085 c_parser_consume_token (parser
);
9089 if (property_getter_ident
!= NULL_TREE
)
9090 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9092 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9093 c_parser_consume_token (parser
);
9097 c_parser_error (parser
, "unknown property attribute");
9098 syntax_error
= true;
9105 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9106 c_parser_consume_token (parser
);
9110 parser
->objc_property_attr_context
= false;
9111 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9113 /* ... and the property declaration(s). */
9114 properties
= c_parser_struct_declaration (parser
);
9116 if (properties
== error_mark_node
)
9118 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9119 parser
->error
= false;
9123 if (properties
== NULL_TREE
)
9124 c_parser_error (parser
, "expected identifier");
9127 /* Comma-separated properties are chained together in
9128 reverse order; add them one by one. */
9129 properties
= nreverse (properties
);
9131 for (; properties
; properties
= TREE_CHAIN (properties
))
9132 objc_add_property_declaration (loc
, copy_node (properties
),
9133 property_readonly
, property_readwrite
,
9134 property_assign
, property_retain
,
9135 property_copy
, property_nonatomic
,
9136 property_getter_ident
, property_setter_ident
);
9139 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9140 parser
->error
= false;
9143 /* Parse an Objective-C @synthesize declaration. The syntax is:
9145 objc-synthesize-declaration:
9146 @synthesize objc-synthesize-identifier-list ;
9148 objc-synthesize-identifier-list:
9149 objc-synthesize-identifier
9150 objc-synthesize-identifier-list, objc-synthesize-identifier
9152 objc-synthesize-identifier
9154 identifier = identifier
9157 @synthesize MyProperty;
9158 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9160 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9161 for C++. Keep them in sync.
9164 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9166 tree list
= NULL_TREE
;
9168 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9169 loc
= c_parser_peek_token (parser
)->location
;
9171 c_parser_consume_token (parser
);
9174 tree property
, ivar
;
9175 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9177 c_parser_error (parser
, "expected identifier");
9178 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9179 /* Once we find the semicolon, we can resume normal parsing.
9180 We have to reset parser->error manually because
9181 c_parser_skip_until_found() won't reset it for us if the
9182 next token is precisely a semicolon. */
9183 parser
->error
= false;
9186 property
= c_parser_peek_token (parser
)->value
;
9187 c_parser_consume_token (parser
);
9188 if (c_parser_next_token_is (parser
, CPP_EQ
))
9190 c_parser_consume_token (parser
);
9191 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9193 c_parser_error (parser
, "expected identifier");
9194 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9195 parser
->error
= false;
9198 ivar
= c_parser_peek_token (parser
)->value
;
9199 c_parser_consume_token (parser
);
9203 list
= chainon (list
, build_tree_list (ivar
, property
));
9204 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9205 c_parser_consume_token (parser
);
9209 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9210 objc_add_synthesize_declaration (loc
, list
);
9213 /* Parse an Objective-C @dynamic declaration. The syntax is:
9215 objc-dynamic-declaration:
9216 @dynamic identifier-list ;
9219 @dynamic MyProperty;
9220 @dynamic MyProperty, AnotherProperty;
9222 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9223 for C++. Keep them in sync.
9226 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9228 tree list
= NULL_TREE
;
9230 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9231 loc
= c_parser_peek_token (parser
)->location
;
9233 c_parser_consume_token (parser
);
9237 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9239 c_parser_error (parser
, "expected identifier");
9240 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9241 parser
->error
= false;
9244 property
= c_parser_peek_token (parser
)->value
;
9245 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9246 c_parser_consume_token (parser
);
9247 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9248 c_parser_consume_token (parser
);
9252 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9253 objc_add_dynamic_declaration (loc
, list
);
9257 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9258 should be considered, statements. ALLOW_STMT is true if we're within
9259 the context of a function and such pragmas are to be allowed. Returns
9260 true if we actually parsed such a pragma. */
9263 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9267 id
= c_parser_peek_token (parser
)->pragma_kind
;
9268 gcc_assert (id
!= PRAGMA_NONE
);
9272 case PRAGMA_OMP_BARRIER
:
9273 if (context
!= pragma_compound
)
9275 if (context
== pragma_stmt
)
9276 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9277 "used in compound statements");
9280 c_parser_omp_barrier (parser
);
9283 case PRAGMA_OMP_FLUSH
:
9284 if (context
!= pragma_compound
)
9286 if (context
== pragma_stmt
)
9287 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9288 "used in compound statements");
9291 c_parser_omp_flush (parser
);
9294 case PRAGMA_OMP_TASKWAIT
:
9295 if (context
!= pragma_compound
)
9297 if (context
== pragma_stmt
)
9298 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9299 "used in compound statements");
9302 c_parser_omp_taskwait (parser
);
9305 case PRAGMA_OMP_TASKYIELD
:
9306 if (context
!= pragma_compound
)
9308 if (context
== pragma_stmt
)
9309 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9310 "used in compound statements");
9313 c_parser_omp_taskyield (parser
);
9316 case PRAGMA_OMP_CANCEL
:
9317 if (context
!= pragma_compound
)
9319 if (context
== pragma_stmt
)
9320 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9321 "used in compound statements");
9324 c_parser_omp_cancel (parser
);
9327 case PRAGMA_OMP_CANCELLATION_POINT
:
9328 if (context
!= pragma_compound
)
9330 if (context
== pragma_stmt
)
9331 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9332 "only be used in compound statements");
9335 c_parser_omp_cancellation_point (parser
);
9338 case PRAGMA_OMP_THREADPRIVATE
:
9339 c_parser_omp_threadprivate (parser
);
9342 case PRAGMA_OMP_TARGET
:
9343 return c_parser_omp_target (parser
, context
);
9345 case PRAGMA_OMP_END_DECLARE_TARGET
:
9346 c_parser_omp_end_declare_target (parser
);
9349 case PRAGMA_OMP_SECTION
:
9350 error_at (c_parser_peek_token (parser
)->location
,
9351 "%<#pragma omp section%> may only be used in "
9352 "%<#pragma omp sections%> construct");
9353 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9356 case PRAGMA_OMP_DECLARE_REDUCTION
:
9357 c_parser_omp_declare (parser
, context
);
9360 c_parser_consume_pragma (parser
);
9361 c_parser_skip_to_pragma_eol (parser
);
9362 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9363 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9364 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9366 c_parser_error (parser
, "for, while or do statement expected");
9369 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9370 c_parser_for_statement (parser
, true);
9371 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9372 c_parser_while_statement (parser
, true);
9374 c_parser_do_statement (parser
, true);
9377 case PRAGMA_GCC_PCH_PREPROCESS
:
9378 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9379 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9382 case PRAGMA_CILK_SIMD
:
9383 if (!c_parser_cilk_verify_simd (parser
, context
))
9385 c_parser_consume_pragma (parser
);
9386 c_parser_cilk_simd (parser
);
9390 if (id
< PRAGMA_FIRST_EXTERNAL
)
9392 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9395 c_parser_error (parser
, "expected declaration specifiers");
9396 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9399 c_parser_omp_construct (parser
);
9405 c_parser_consume_pragma (parser
);
9406 c_invoke_pragma_handler (id
);
9408 /* Skip to EOL, but suppress any error message. Those will have been
9409 generated by the handler routine through calling error, as opposed
9410 to calling c_parser_error. */
9411 parser
->error
= true;
9412 c_parser_skip_to_pragma_eol (parser
);
9417 /* The interface the pragma parsers have to the lexer. */
9420 pragma_lex (tree
*value
)
9422 c_token
*tok
= c_parser_peek_token (the_parser
);
9423 enum cpp_ttype ret
= tok
->type
;
9425 *value
= tok
->value
;
9426 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9430 if (ret
== CPP_KEYWORD
)
9432 c_parser_consume_token (the_parser
);
9439 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9443 c_parser_consume_pragma (parser
);
9444 if (c_parser_next_token_is (parser
, CPP_STRING
))
9446 name
= c_parser_peek_token (parser
)->value
;
9447 c_parser_consume_token (parser
);
9450 c_parser_error (parser
, "expected string literal");
9451 c_parser_skip_to_pragma_eol (parser
);
9454 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9457 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9459 /* Returns name of the next clause.
9460 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9461 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9462 returned and the token is consumed. */
9464 static pragma_omp_clause
9465 c_parser_omp_clause_name (c_parser
*parser
)
9467 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9469 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9470 result
= PRAGMA_OMP_CLAUSE_IF
;
9471 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9472 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9473 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9474 result
= PRAGMA_OMP_CLAUSE_FOR
;
9475 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9477 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9482 if (!strcmp ("aligned", p
))
9483 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9486 if (!strcmp ("collapse", p
))
9487 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9488 else if (!strcmp ("copyin", p
))
9489 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9490 else if (!strcmp ("copyprivate", p
))
9491 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9494 if (!strcmp ("depend", p
))
9495 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9496 else if (!strcmp ("device", p
))
9497 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9498 else if (!strcmp ("dist_schedule", p
))
9499 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9502 if (!strcmp ("final", p
))
9503 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9504 else if (!strcmp ("firstprivate", p
))
9505 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9506 else if (!strcmp ("from", p
))
9507 result
= PRAGMA_OMP_CLAUSE_FROM
;
9510 if (!strcmp ("inbranch", p
))
9511 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9514 if (!strcmp ("lastprivate", p
))
9515 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9516 else if (!strcmp ("linear", p
))
9517 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9520 if (!strcmp ("map", p
))
9521 result
= PRAGMA_OMP_CLAUSE_MAP
;
9522 else if (!strcmp ("mergeable", p
))
9523 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9526 if (!strcmp ("notinbranch", p
))
9527 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9528 else if (!strcmp ("nowait", p
))
9529 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9530 else if (!strcmp ("num_teams", p
))
9531 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9532 else if (!strcmp ("num_threads", p
))
9533 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9536 if (!strcmp ("ordered", p
))
9537 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9540 if (!strcmp ("parallel", p
))
9541 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9542 else if (!strcmp ("private", p
))
9543 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9544 else if (!strcmp ("proc_bind", p
))
9545 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9548 if (!strcmp ("reduction", p
))
9549 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9552 if (!strcmp ("safelen", p
))
9553 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9554 else if (!strcmp ("schedule", p
))
9555 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9556 else if (!strcmp ("sections", p
))
9557 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9558 else if (!strcmp ("shared", p
))
9559 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9560 else if (!strcmp ("simdlen", p
))
9561 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9564 if (!strcmp ("taskgroup", p
))
9565 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9566 else if (!strcmp ("thread_limit", p
))
9567 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9568 else if (!strcmp ("to", p
))
9569 result
= PRAGMA_OMP_CLAUSE_TO
;
9572 if (!strcmp ("uniform", p
))
9573 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9574 else if (!strcmp ("untied", p
))
9575 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9580 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9581 c_parser_consume_token (parser
);
9586 /* Validate that a clause of the given type does not already exist. */
9589 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9594 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9595 if (OMP_CLAUSE_CODE (c
) == code
)
9597 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9598 error_at (loc
, "too many %qs clauses", name
);
9606 variable-list , identifier
9608 If KIND is nonzero, create the appropriate node and install the
9609 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9610 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9612 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9613 return the list created. */
9616 c_parser_omp_variable_list (c_parser
*parser
,
9617 location_t clause_loc
,
9618 enum omp_clause_code kind
, tree list
)
9620 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9621 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9622 c_parser_error (parser
, "expected identifier");
9624 while (c_parser_next_token_is (parser
, CPP_NAME
)
9625 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9627 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9631 undeclared_variable (c_parser_peek_token (parser
)->location
,
9632 c_parser_peek_token (parser
)->value
);
9633 t
= error_mark_node
;
9636 c_parser_consume_token (parser
);
9638 if (t
== error_mark_node
)
9644 case OMP_CLAUSE_MAP
:
9645 case OMP_CLAUSE_FROM
:
9647 case OMP_CLAUSE_DEPEND
:
9648 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9650 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9652 c_parser_consume_token (parser
);
9653 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9654 low_bound
= c_parser_expression (parser
).value
;
9655 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9656 length
= integer_one_node
;
9660 if (!c_parser_require (parser
, CPP_COLON
,
9663 t
= error_mark_node
;
9666 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9667 length
= c_parser_expression (parser
).value
;
9669 /* Look for the closing `]'. */
9670 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9673 t
= error_mark_node
;
9676 t
= tree_cons (low_bound
, length
, t
);
9683 if (t
!= error_mark_node
)
9685 tree u
= build_omp_clause (clause_loc
, kind
);
9686 OMP_CLAUSE_DECL (u
) = t
;
9687 OMP_CLAUSE_CHAIN (u
) = list
;
9692 list
= tree_cons (t
, NULL_TREE
, list
);
9694 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9697 c_parser_consume_token (parser
);
9703 /* Similarly, but expect leading and trailing parenthesis. This is a very
9704 common case for omp clauses. */
9707 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9710 /* The clauses location. */
9711 location_t loc
= c_parser_peek_token (parser
)->location
;
9713 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9715 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9716 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9722 collapse ( constant-expression ) */
9725 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9727 tree c
, num
= error_mark_node
;
9731 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9733 loc
= c_parser_peek_token (parser
)->location
;
9734 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9736 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9737 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9739 if (num
== error_mark_node
)
9741 mark_exp_read (num
);
9742 num
= c_fully_fold (num
, false, NULL
);
9743 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9744 || !tree_fits_shwi_p (num
)
9745 || (n
= tree_to_shwi (num
)) <= 0
9749 "collapse argument needs positive constant integer expression");
9752 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9753 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9754 OMP_CLAUSE_CHAIN (c
) = list
;
9759 copyin ( variable-list ) */
9762 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9764 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9768 copyprivate ( variable-list ) */
9771 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9773 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9777 default ( shared | none ) */
9780 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9782 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9783 location_t loc
= c_parser_peek_token (parser
)->location
;
9786 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9788 if (c_parser_next_token_is (parser
, CPP_NAME
))
9790 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9795 if (strcmp ("none", p
) != 0)
9797 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9801 if (strcmp ("shared", p
) != 0)
9803 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9810 c_parser_consume_token (parser
);
9815 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9817 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9819 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9822 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9823 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9824 OMP_CLAUSE_CHAIN (c
) = list
;
9825 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9831 firstprivate ( variable-list ) */
9834 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9836 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9840 final ( expression ) */
9843 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9845 location_t loc
= c_parser_peek_token (parser
)->location
;
9846 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9848 tree t
= c_parser_paren_condition (parser
);
9851 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9853 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9854 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9855 OMP_CLAUSE_CHAIN (c
) = list
;
9859 c_parser_error (parser
, "expected %<(%>");
9865 if ( expression ) */
9868 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9870 location_t loc
= c_parser_peek_token (parser
)->location
;
9871 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9873 tree t
= c_parser_paren_condition (parser
);
9876 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9878 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9879 OMP_CLAUSE_IF_EXPR (c
) = t
;
9880 OMP_CLAUSE_CHAIN (c
) = list
;
9884 c_parser_error (parser
, "expected %<(%>");
9890 lastprivate ( variable-list ) */
9893 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9895 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9902 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9906 /* FIXME: Should we allow duplicates? */
9907 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9909 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9910 OMP_CLAUSE_MERGEABLE
);
9911 OMP_CLAUSE_CHAIN (c
) = list
;
9920 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9923 location_t loc
= c_parser_peek_token (parser
)->location
;
9925 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9927 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9928 OMP_CLAUSE_CHAIN (c
) = list
;
9933 num_threads ( expression ) */
9936 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9938 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9939 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9941 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9942 tree c
, t
= c_parser_expression (parser
).value
;
9944 t
= c_fully_fold (t
, false, NULL
);
9946 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9948 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9950 c_parser_error (parser
, "expected integer expression");
9954 /* Attempt to statically determine when the number isn't positive. */
9955 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9956 build_int_cst (TREE_TYPE (t
), 0));
9957 if (CAN_HAVE_LOCATION_P (c
))
9958 SET_EXPR_LOCATION (c
, expr_loc
);
9959 if (c
== boolean_true_node
)
9961 warning_at (expr_loc
, 0,
9962 "%<num_threads%> value must be positive");
9963 t
= integer_one_node
;
9966 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9968 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9969 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9970 OMP_CLAUSE_CHAIN (c
) = list
;
9981 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9985 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9987 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9988 OMP_CLAUSE_ORDERED
);
9989 OMP_CLAUSE_CHAIN (c
) = list
;
9995 private ( variable-list ) */
9998 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10000 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10004 reduction ( reduction-operator : variable-list )
10006 reduction-operator:
10007 One of: + * - & ^ | && ||
10011 reduction-operator:
10012 One of: + * - & ^ | && || max min
10016 reduction-operator:
10017 One of: + * - & ^ | && ||
10021 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10023 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10024 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10026 enum tree_code code
= ERROR_MARK
;
10027 tree reduc_id
= NULL_TREE
;
10029 switch (c_parser_peek_token (parser
)->type
)
10041 code
= BIT_AND_EXPR
;
10044 code
= BIT_XOR_EXPR
;
10047 code
= BIT_IOR_EXPR
;
10050 code
= TRUTH_ANDIF_EXPR
;
10053 code
= TRUTH_ORIF_EXPR
;
10058 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10059 if (strcmp (p
, "min") == 0)
10064 if (strcmp (p
, "max") == 0)
10069 reduc_id
= c_parser_peek_token (parser
)->value
;
10073 c_parser_error (parser
,
10074 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10075 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10076 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10079 c_parser_consume_token (parser
);
10080 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10081 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10085 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10086 OMP_CLAUSE_REDUCTION
, list
);
10087 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10089 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10090 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10091 if (code
== ERROR_MARK
10092 || !(INTEGRAL_TYPE_P (type
)
10093 || TREE_CODE (type
) == REAL_TYPE
10094 || TREE_CODE (type
) == COMPLEX_TYPE
))
10095 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10096 = c_omp_reduction_lookup (reduc_id
,
10097 TYPE_MAIN_VARIANT (type
));
10102 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10108 schedule ( schedule-kind )
10109 schedule ( schedule-kind , expression )
10112 static | dynamic | guided | runtime | auto
10116 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10119 location_t loc
= c_parser_peek_token (parser
)->location
;
10121 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10124 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10126 if (c_parser_next_token_is (parser
, CPP_NAME
))
10128 tree kind
= c_parser_peek_token (parser
)->value
;
10129 const char *p
= IDENTIFIER_POINTER (kind
);
10134 if (strcmp ("dynamic", p
) != 0)
10136 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10140 if (strcmp ("guided", p
) != 0)
10142 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10146 if (strcmp ("runtime", p
) != 0)
10148 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10155 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10156 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10157 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10158 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10162 c_parser_consume_token (parser
);
10163 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10166 c_parser_consume_token (parser
);
10168 here
= c_parser_peek_token (parser
)->location
;
10169 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10171 t
= c_fully_fold (t
, false, NULL
);
10173 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10174 error_at (here
, "schedule %<runtime%> does not take "
10175 "a %<chunk_size%> parameter");
10176 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10178 "schedule %<auto%> does not take "
10179 "a %<chunk_size%> parameter");
10180 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10181 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10183 c_parser_error (parser
, "expected integer expression");
10185 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10188 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10189 "expected %<,%> or %<)%>");
10191 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10192 OMP_CLAUSE_CHAIN (c
) = list
;
10196 c_parser_error (parser
, "invalid schedule kind");
10197 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10202 shared ( variable-list ) */
10205 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10207 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10214 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10218 /* FIXME: Should we allow duplicates? */
10219 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10221 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10222 OMP_CLAUSE_UNTIED
);
10223 OMP_CLAUSE_CHAIN (c
) = list
;
10233 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10234 enum omp_clause_code code
, tree list
)
10236 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10238 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10239 OMP_CLAUSE_CHAIN (c
) = list
;
10251 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10252 enum omp_clause_code code
, tree list
)
10254 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10255 OMP_CLAUSE_CHAIN (c
) = list
;
10261 num_teams ( expression ) */
10264 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10266 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10267 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10269 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10270 tree c
, t
= c_parser_expression (parser
).value
;
10272 t
= c_fully_fold (t
, false, NULL
);
10274 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10276 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10278 c_parser_error (parser
, "expected integer expression");
10282 /* Attempt to statically determine when the number isn't positive. */
10283 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10284 build_int_cst (TREE_TYPE (t
), 0));
10285 if (CAN_HAVE_LOCATION_P (c
))
10286 SET_EXPR_LOCATION (c
, expr_loc
);
10287 if (c
== boolean_true_node
)
10289 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10290 t
= integer_one_node
;
10293 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10295 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10296 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10297 OMP_CLAUSE_CHAIN (c
) = list
;
10305 thread_limit ( expression ) */
10308 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10310 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10311 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10313 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10314 tree c
, t
= c_parser_expression (parser
).value
;
10316 t
= c_fully_fold (t
, false, NULL
);
10318 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10320 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10322 c_parser_error (parser
, "expected integer expression");
10326 /* Attempt to statically determine when the number isn't positive. */
10327 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10328 build_int_cst (TREE_TYPE (t
), 0));
10329 if (CAN_HAVE_LOCATION_P (c
))
10330 SET_EXPR_LOCATION (c
, expr_loc
);
10331 if (c
== boolean_true_node
)
10333 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10334 t
= integer_one_node
;
10337 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10340 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10341 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10342 OMP_CLAUSE_CHAIN (c
) = list
;
10350 aligned ( variable-list )
10351 aligned ( variable-list : constant-expression ) */
10354 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10356 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10359 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10362 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10363 OMP_CLAUSE_ALIGNED
, list
);
10365 if (c_parser_next_token_is (parser
, CPP_COLON
))
10367 c_parser_consume_token (parser
);
10368 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10369 mark_exp_read (alignment
);
10370 alignment
= c_fully_fold (alignment
, false, NULL
);
10371 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10372 && TREE_CODE (alignment
) != INTEGER_CST
10373 && tree_int_cst_sgn (alignment
) != 1)
10375 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10376 "be positive constant integer expression");
10377 alignment
= NULL_TREE
;
10380 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10381 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10384 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10389 linear ( variable-list )
10390 linear ( variable-list : expression ) */
10393 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
10395 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10398 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10401 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10402 OMP_CLAUSE_LINEAR
, list
);
10404 if (c_parser_next_token_is (parser
, CPP_COLON
))
10406 c_parser_consume_token (parser
);
10407 step
= c_parser_expression (parser
).value
;
10408 mark_exp_read (step
);
10409 step
= c_fully_fold (step
, false, NULL
);
10410 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10412 error_at (clause_loc
, "%<linear%> clause step expression must "
10414 step
= integer_one_node
;
10419 step
= integer_one_node
;
10421 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10423 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10426 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10431 safelen ( constant-expression ) */
10434 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10436 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10439 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10442 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10444 t
= c_fully_fold (t
, false, NULL
);
10445 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10446 && TREE_CODE (t
) != INTEGER_CST
10447 && tree_int_cst_sgn (t
) != 1)
10449 error_at (clause_loc
, "%<safelen%> clause expression must "
10450 "be positive constant integer expression");
10454 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10455 if (t
== NULL_TREE
|| t
== error_mark_node
)
10458 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10460 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10461 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10462 OMP_CLAUSE_CHAIN (c
) = list
;
10467 simdlen ( constant-expression ) */
10470 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10472 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10475 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10478 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10480 t
= c_fully_fold (t
, false, NULL
);
10481 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10482 && TREE_CODE (t
) != INTEGER_CST
10483 && tree_int_cst_sgn (t
) != 1)
10485 error_at (clause_loc
, "%<simdlen%> clause expression must "
10486 "be positive constant integer expression");
10490 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10491 if (t
== NULL_TREE
|| t
== error_mark_node
)
10494 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10496 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10497 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10498 OMP_CLAUSE_CHAIN (c
) = list
;
10503 depend ( depend-kind: variable-list )
10506 in | out | inout */
10509 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10511 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10512 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10515 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10518 if (c_parser_next_token_is (parser
, CPP_NAME
))
10520 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10521 if (strcmp ("in", p
) == 0)
10522 kind
= OMP_CLAUSE_DEPEND_IN
;
10523 else if (strcmp ("inout", p
) == 0)
10524 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10525 else if (strcmp ("out", p
) == 0)
10526 kind
= OMP_CLAUSE_DEPEND_OUT
;
10533 c_parser_consume_token (parser
);
10534 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10537 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10538 OMP_CLAUSE_DEPEND
, list
);
10540 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10541 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10543 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10547 c_parser_error (parser
, "invalid depend kind");
10549 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10554 map ( map-kind: variable-list )
10555 map ( variable-list )
10558 alloc | to | from | tofrom */
10561 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10563 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10564 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10567 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10570 if (c_parser_next_token_is (parser
, CPP_NAME
)
10571 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10573 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10574 if (strcmp ("alloc", p
) == 0)
10575 kind
= OMP_CLAUSE_MAP_ALLOC
;
10576 else if (strcmp ("to", p
) == 0)
10577 kind
= OMP_CLAUSE_MAP_TO
;
10578 else if (strcmp ("from", p
) == 0)
10579 kind
= OMP_CLAUSE_MAP_FROM
;
10580 else if (strcmp ("tofrom", p
) == 0)
10581 kind
= OMP_CLAUSE_MAP_TOFROM
;
10584 c_parser_error (parser
, "invalid map kind");
10585 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10589 c_parser_consume_token (parser
);
10590 c_parser_consume_token (parser
);
10593 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10595 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10596 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10598 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10603 device ( expression ) */
10606 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10608 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10609 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10611 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10613 t
= c_fully_fold (t
, false, NULL
);
10615 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10617 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10619 c_parser_error (parser
, "expected integer expression");
10623 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10625 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10626 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10627 OMP_CLAUSE_CHAIN (c
) = list
;
10635 dist_schedule ( static )
10636 dist_schedule ( static , expression ) */
10639 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10641 tree c
, t
= NULL_TREE
;
10642 location_t loc
= c_parser_peek_token (parser
)->location
;
10644 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10647 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10649 c_parser_error (parser
, "invalid dist_schedule kind");
10650 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10655 c_parser_consume_token (parser
);
10656 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10658 c_parser_consume_token (parser
);
10660 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10662 t
= c_fully_fold (t
, false, NULL
);
10663 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10666 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10667 "expected %<,%> or %<)%>");
10669 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10670 if (t
== error_mark_node
)
10673 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10674 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10675 OMP_CLAUSE_CHAIN (c
) = list
;
10680 proc_bind ( proc-bind-kind )
10683 master | close | spread */
10686 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10688 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10689 enum omp_clause_proc_bind_kind kind
;
10692 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10695 if (c_parser_next_token_is (parser
, CPP_NAME
))
10697 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10698 if (strcmp ("master", p
) == 0)
10699 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10700 else if (strcmp ("close", p
) == 0)
10701 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10702 else if (strcmp ("spread", p
) == 0)
10703 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10710 c_parser_consume_token (parser
);
10711 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10712 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10713 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10714 OMP_CLAUSE_CHAIN (c
) = list
;
10718 c_parser_error (parser
, "invalid proc_bind kind");
10719 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10724 to ( variable-list ) */
10727 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10729 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10733 from ( variable-list ) */
10736 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10738 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10742 uniform ( variable-list ) */
10745 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10747 /* The clauses location. */
10748 location_t loc
= c_parser_peek_token (parser
)->location
;
10750 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10752 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10754 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10759 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10760 is a bitmask in MASK. Return the list of clauses found; the result
10761 of clause default goes in *pdefault. */
10764 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10765 const char *where
, bool finish_p
= true)
10767 tree clauses
= NULL
;
10770 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10773 pragma_omp_clause c_kind
;
10774 const char *c_name
;
10775 tree prev
= clauses
;
10777 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10778 c_parser_consume_token (parser
);
10780 here
= c_parser_peek_token (parser
)->location
;
10781 c_kind
= c_parser_omp_clause_name (parser
);
10785 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10786 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10787 c_name
= "collapse";
10789 case PRAGMA_OMP_CLAUSE_COPYIN
:
10790 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10793 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10794 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10795 c_name
= "copyprivate";
10797 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10798 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10799 c_name
= "default";
10801 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
10802 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
10803 c_name
= "firstprivate";
10805 case PRAGMA_OMP_CLAUSE_FINAL
:
10806 clauses
= c_parser_omp_clause_final (parser
, clauses
);
10809 case PRAGMA_OMP_CLAUSE_IF
:
10810 clauses
= c_parser_omp_clause_if (parser
, clauses
);
10813 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
10814 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
10815 c_name
= "lastprivate";
10817 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
10818 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
10819 c_name
= "mergeable";
10821 case PRAGMA_OMP_CLAUSE_NOWAIT
:
10822 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
10825 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
10826 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
10827 c_name
= "num_threads";
10829 case PRAGMA_OMP_CLAUSE_ORDERED
:
10830 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
10831 c_name
= "ordered";
10833 case PRAGMA_OMP_CLAUSE_PRIVATE
:
10834 clauses
= c_parser_omp_clause_private (parser
, clauses
);
10835 c_name
= "private";
10837 case PRAGMA_OMP_CLAUSE_REDUCTION
:
10838 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
10839 c_name
= "reduction";
10841 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10842 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10843 c_name
= "schedule";
10845 case PRAGMA_OMP_CLAUSE_SHARED
:
10846 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10849 case PRAGMA_OMP_CLAUSE_UNTIED
:
10850 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
10853 case PRAGMA_OMP_CLAUSE_INBRANCH
:
10854 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
10856 c_name
= "inbranch";
10858 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
10859 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
10861 c_name
= "notinbranch";
10863 case PRAGMA_OMP_CLAUSE_PARALLEL
:
10865 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
10867 c_name
= "parallel";
10871 error_at (here
, "%qs must be the first clause of %qs",
10876 case PRAGMA_OMP_CLAUSE_FOR
:
10878 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
10882 goto clause_not_first
;
10884 case PRAGMA_OMP_CLAUSE_SECTIONS
:
10886 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
10888 c_name
= "sections";
10890 goto clause_not_first
;
10892 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
10894 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
10896 c_name
= "taskgroup";
10898 goto clause_not_first
;
10900 case PRAGMA_OMP_CLAUSE_TO
:
10901 clauses
= c_parser_omp_clause_to (parser
, clauses
);
10904 case PRAGMA_OMP_CLAUSE_FROM
:
10905 clauses
= c_parser_omp_clause_from (parser
, clauses
);
10908 case PRAGMA_OMP_CLAUSE_UNIFORM
:
10909 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
10910 c_name
= "uniform";
10912 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
10913 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
10914 c_name
= "num_teams";
10916 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
10917 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
10918 c_name
= "thread_limit";
10920 case PRAGMA_OMP_CLAUSE_ALIGNED
:
10921 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
10922 c_name
= "aligned";
10924 case PRAGMA_OMP_CLAUSE_LINEAR
:
10925 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
10928 case PRAGMA_OMP_CLAUSE_DEPEND
:
10929 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
10932 case PRAGMA_OMP_CLAUSE_MAP
:
10933 clauses
= c_parser_omp_clause_map (parser
, clauses
);
10936 case PRAGMA_OMP_CLAUSE_DEVICE
:
10937 clauses
= c_parser_omp_clause_device (parser
, clauses
);
10940 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
10941 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
10942 c_name
= "dist_schedule";
10944 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
10945 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
10946 c_name
= "proc_bind";
10948 case PRAGMA_OMP_CLAUSE_SAFELEN
:
10949 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
10950 c_name
= "safelen";
10952 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
10953 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
10954 c_name
= "simdlen";
10957 c_parser_error (parser
, "expected %<#pragma omp%> clause");
10963 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
10965 /* Remove the invalid clause(s) from the list to avoid
10966 confusing the rest of the compiler. */
10968 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
10973 c_parser_skip_to_pragma_eol (parser
);
10976 return c_finish_omp_clauses (clauses
);
10985 In practice, we're also interested in adding the statement to an
10986 outer node. So it is convenient if we work around the fact that
10987 c_parser_statement calls add_stmt. */
10990 c_parser_omp_structured_block (c_parser
*parser
)
10992 tree stmt
= push_stmt_list ();
10993 c_parser_statement (parser
);
10994 return pop_stmt_list (stmt
);
10998 # pragma omp atomic new-line
11002 x binop= expr | x++ | ++x | x-- | --x
11004 +, *, -, /, &, ^, |, <<, >>
11006 where x is an lvalue expression with scalar type.
11009 # pragma omp atomic new-line
11012 # pragma omp atomic read new-line
11015 # pragma omp atomic write new-line
11018 # pragma omp atomic update new-line
11021 # pragma omp atomic capture new-line
11024 # pragma omp atomic capture new-line
11032 expression-stmt | x = x binop expr
11034 v = expression-stmt
11036 { v = x; update-stmt; } | { update-stmt; v = x; }
11040 expression-stmt | x = x binop expr | x = expr binop x
11044 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11046 where x and v are lvalue expressions with scalar type.
11048 LOC is the location of the #pragma token. */
11051 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11053 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11054 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11055 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11056 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11057 struct c_expr expr
;
11059 bool structured_block
= false;
11060 bool swapped
= false;
11061 bool seq_cst
= false;
11063 if (c_parser_next_token_is (parser
, CPP_NAME
))
11065 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11067 if (!strcmp (p
, "read"))
11068 code
= OMP_ATOMIC_READ
;
11069 else if (!strcmp (p
, "write"))
11071 else if (!strcmp (p
, "update"))
11073 else if (!strcmp (p
, "capture"))
11074 code
= OMP_ATOMIC_CAPTURE_NEW
;
11078 c_parser_consume_token (parser
);
11080 if (c_parser_next_token_is (parser
, CPP_NAME
))
11082 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11083 if (!strcmp (p
, "seq_cst"))
11086 c_parser_consume_token (parser
);
11089 c_parser_skip_to_pragma_eol (parser
);
11093 case OMP_ATOMIC_READ
:
11094 case NOP_EXPR
: /* atomic write */
11095 v
= c_parser_unary_expression (parser
).value
;
11096 v
= c_fully_fold (v
, false, NULL
);
11097 if (v
== error_mark_node
)
11099 loc
= c_parser_peek_token (parser
)->location
;
11100 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11102 if (code
== NOP_EXPR
)
11103 lhs
= c_parser_expression (parser
).value
;
11105 lhs
= c_parser_unary_expression (parser
).value
;
11106 lhs
= c_fully_fold (lhs
, false, NULL
);
11107 if (lhs
== error_mark_node
)
11109 if (code
== NOP_EXPR
)
11111 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11119 case OMP_ATOMIC_CAPTURE_NEW
:
11120 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11122 c_parser_consume_token (parser
);
11123 structured_block
= true;
11127 v
= c_parser_unary_expression (parser
).value
;
11128 v
= c_fully_fold (v
, false, NULL
);
11129 if (v
== error_mark_node
)
11131 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11139 /* For structured_block case we don't know yet whether
11140 old or new x should be captured. */
11142 eloc
= c_parser_peek_token (parser
)->location
;
11143 expr
= c_parser_unary_expression (parser
);
11145 expr
= default_function_array_conversion (eloc
, expr
);
11146 unfolded_lhs
= expr
.value
;
11147 lhs
= c_fully_fold (lhs
, false, NULL
);
11149 switch (TREE_CODE (lhs
))
11153 c_parser_skip_to_end_of_block_or_statement (parser
);
11154 if (structured_block
)
11156 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11157 c_parser_consume_token (parser
);
11158 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11160 c_parser_skip_to_end_of_block_or_statement (parser
);
11161 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11162 c_parser_consume_token (parser
);
11167 case POSTINCREMENT_EXPR
:
11168 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11169 code
= OMP_ATOMIC_CAPTURE_OLD
;
11171 case PREINCREMENT_EXPR
:
11172 lhs
= TREE_OPERAND (lhs
, 0);
11173 unfolded_lhs
= NULL_TREE
;
11174 opcode
= PLUS_EXPR
;
11175 rhs
= integer_one_node
;
11178 case POSTDECREMENT_EXPR
:
11179 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11180 code
= OMP_ATOMIC_CAPTURE_OLD
;
11182 case PREDECREMENT_EXPR
:
11183 lhs
= TREE_OPERAND (lhs
, 0);
11184 unfolded_lhs
= NULL_TREE
;
11185 opcode
= MINUS_EXPR
;
11186 rhs
= integer_one_node
;
11189 case COMPOUND_EXPR
:
11190 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11191 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11192 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11193 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11194 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11195 (TREE_OPERAND (lhs
, 1), 0), 0)))
11197 /* Undo effects of boolean_increment for post {in,de}crement. */
11198 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11201 if (TREE_CODE (lhs
) == MODIFY_EXPR
11202 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11204 /* Undo effects of boolean_increment. */
11205 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11207 /* This is pre or post increment. */
11208 rhs
= TREE_OPERAND (lhs
, 1);
11209 lhs
= TREE_OPERAND (lhs
, 0);
11210 unfolded_lhs
= NULL_TREE
;
11212 if (code
== OMP_ATOMIC_CAPTURE_NEW
11213 && !structured_block
11214 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11215 code
= OMP_ATOMIC_CAPTURE_OLD
;
11218 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11219 && TREE_OPERAND (lhs
, 0)
11220 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11222 /* This is pre or post decrement. */
11223 rhs
= TREE_OPERAND (lhs
, 1);
11224 lhs
= TREE_OPERAND (lhs
, 0);
11225 unfolded_lhs
= NULL_TREE
;
11227 if (code
== OMP_ATOMIC_CAPTURE_NEW
11228 && !structured_block
11229 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11230 code
= OMP_ATOMIC_CAPTURE_OLD
;
11236 switch (c_parser_peek_token (parser
)->type
)
11239 opcode
= MULT_EXPR
;
11242 opcode
= TRUNC_DIV_EXPR
;
11245 opcode
= PLUS_EXPR
;
11248 opcode
= MINUS_EXPR
;
11250 case CPP_LSHIFT_EQ
:
11251 opcode
= LSHIFT_EXPR
;
11253 case CPP_RSHIFT_EQ
:
11254 opcode
= RSHIFT_EXPR
;
11257 opcode
= BIT_AND_EXPR
;
11260 opcode
= BIT_IOR_EXPR
;
11263 opcode
= BIT_XOR_EXPR
;
11266 c_parser_consume_token (parser
);
11267 eloc
= c_parser_peek_token (parser
)->location
;
11268 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11270 switch (TREE_CODE (rhs1
))
11273 case TRUNC_DIV_EXPR
:
11281 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11283 opcode
= TREE_CODE (rhs1
);
11284 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11285 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11288 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11290 opcode
= TREE_CODE (rhs1
);
11291 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11292 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11293 swapped
= !commutative_tree_code (opcode
);
11302 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11304 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11306 code
= OMP_ATOMIC_CAPTURE_OLD
;
11309 expr
= default_function_array_read_conversion (eloc
, expr
);
11310 unfolded_lhs1
= expr
.value
;
11311 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11313 c_parser_consume_token (parser
);
11316 if (structured_block
)
11319 expr
= default_function_array_read_conversion (eloc
, expr
);
11320 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11325 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11328 c_parser_error (parser
,
11329 "invalid operator for %<#pragma omp atomic%>");
11333 /* Arrange to pass the location of the assignment operator to
11334 c_finish_omp_atomic. */
11335 loc
= c_parser_peek_token (parser
)->location
;
11336 c_parser_consume_token (parser
);
11337 eloc
= c_parser_peek_token (parser
)->location
;
11338 expr
= c_parser_expression (parser
);
11339 expr
= default_function_array_read_conversion (eloc
, expr
);
11341 rhs
= c_fully_fold (rhs
, false, NULL
);
11345 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11347 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11349 v
= c_parser_unary_expression (parser
).value
;
11350 v
= c_fully_fold (v
, false, NULL
);
11351 if (v
== error_mark_node
)
11353 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11355 eloc
= c_parser_peek_token (parser
)->location
;
11356 expr
= c_parser_unary_expression (parser
);
11358 expr
= default_function_array_read_conversion (eloc
, expr
);
11359 unfolded_lhs1
= expr
.value
;
11360 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11361 if (lhs1
== error_mark_node
)
11364 if (structured_block
)
11366 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11367 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11370 if (unfolded_lhs
&& unfolded_lhs1
11371 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11373 error ("%<#pragma omp atomic capture%> uses two different "
11374 "expressions for memory");
11375 stmt
= error_mark_node
;
11378 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11380 if (stmt
!= error_mark_node
)
11383 if (!structured_block
)
11384 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11389 # pragma omp barrier new-line
11393 c_parser_omp_barrier (c_parser
*parser
)
11395 location_t loc
= c_parser_peek_token (parser
)->location
;
11396 c_parser_consume_pragma (parser
);
11397 c_parser_skip_to_pragma_eol (parser
);
11399 c_finish_omp_barrier (loc
);
11403 # pragma omp critical [(name)] new-line
11406 LOC is the location of the #pragma itself. */
11409 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11411 tree stmt
, name
= NULL
;
11413 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11415 c_parser_consume_token (parser
);
11416 if (c_parser_next_token_is (parser
, CPP_NAME
))
11418 name
= c_parser_peek_token (parser
)->value
;
11419 c_parser_consume_token (parser
);
11420 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11423 c_parser_error (parser
, "expected identifier");
11425 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11426 c_parser_error (parser
, "expected %<(%> or end of line");
11427 c_parser_skip_to_pragma_eol (parser
);
11429 stmt
= c_parser_omp_structured_block (parser
);
11430 return c_finish_omp_critical (loc
, stmt
, name
);
11434 # pragma omp flush flush-vars[opt] new-line
11437 ( variable-list ) */
11440 c_parser_omp_flush (c_parser
*parser
)
11442 location_t loc
= c_parser_peek_token (parser
)->location
;
11443 c_parser_consume_pragma (parser
);
11444 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11445 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11446 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11447 c_parser_error (parser
, "expected %<(%> or end of line");
11448 c_parser_skip_to_pragma_eol (parser
);
11450 c_finish_omp_flush (loc
);
11453 /* Parse the restricted form of the for statement allowed by OpenMP.
11454 The real trick here is to determine the loop control variable early
11455 so that we can push a new decl if necessary to make it private.
11456 LOC is the location of the OMP in "#pragma omp". */
11459 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11460 tree clauses
, tree
*cclauses
)
11462 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11463 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11464 bool fail
= false, open_brace_parsed
= false;
11465 int i
, collapse
= 1, nbraces
= 0;
11466 location_t for_loc
;
11467 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11469 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11470 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11471 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
11473 gcc_assert (collapse
>= 1);
11475 declv
= make_tree_vec (collapse
);
11476 initv
= make_tree_vec (collapse
);
11477 condv
= make_tree_vec (collapse
);
11478 incrv
= make_tree_vec (collapse
);
11480 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11482 c_parser_error (parser
, "for statement expected");
11485 for_loc
= c_parser_peek_token (parser
)->location
;
11486 c_parser_consume_token (parser
);
11488 for (i
= 0; i
< collapse
; i
++)
11490 int bracecount
= 0;
11492 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11495 /* Parse the initialization declaration or expression. */
11496 if (c_parser_next_tokens_start_declaration (parser
))
11499 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11500 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11502 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11505 if (DECL_INITIAL (decl
) == error_mark_node
)
11506 decl
= error_mark_node
;
11509 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11510 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11512 struct c_expr decl_exp
;
11513 struct c_expr init_exp
;
11514 location_t init_loc
;
11516 decl_exp
= c_parser_postfix_expression (parser
);
11517 decl
= decl_exp
.value
;
11519 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11521 init_loc
= c_parser_peek_token (parser
)->location
;
11522 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11523 init_exp
= default_function_array_read_conversion (init_loc
,
11525 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11526 NOP_EXPR
, init_loc
, init_exp
.value
,
11527 init_exp
.original_type
);
11528 init
= c_process_expr_stmt (init_loc
, init
);
11530 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11535 c_parser_error (parser
,
11536 "expected iteration declaration or initialization");
11537 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11543 /* Parse the loop condition. */
11545 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11547 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11548 struct c_expr cond_expr
11549 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11551 cond
= cond_expr
.value
;
11552 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11553 cond
= c_fully_fold (cond
, false, NULL
);
11554 switch (cond_expr
.original_code
)
11562 if (code
== CILK_SIMD
)
11566 /* Can't be cond = error_mark_node, because we want to preserve
11567 the location until c_finish_omp_for. */
11568 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11571 protected_set_expr_location (cond
, cond_loc
);
11573 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11575 /* Parse the increment expression. */
11577 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11579 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11581 incr
= c_process_expr_stmt (incr_loc
,
11582 c_parser_expression (parser
).value
);
11584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11586 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11590 TREE_VEC_ELT (declv
, i
) = decl
;
11591 TREE_VEC_ELT (initv
, i
) = init
;
11592 TREE_VEC_ELT (condv
, i
) = cond
;
11593 TREE_VEC_ELT (incrv
, i
) = incr
;
11597 if (i
== collapse
- 1)
11600 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11601 in between the collapsed for loops to be still considered perfectly
11602 nested. Hopefully the final version clarifies this.
11603 For now handle (multiple) {'s and empty statements. */
11606 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11608 c_parser_consume_token (parser
);
11611 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11613 c_parser_consume_token (parser
);
11616 else if (bracecount
11617 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11618 c_parser_consume_token (parser
);
11621 c_parser_error (parser
, "not enough perfectly nested loops");
11624 open_brace_parsed
= true;
11634 nbraces
+= bracecount
;
11637 save_break
= c_break_label
;
11638 if (code
== CILK_SIMD
)
11639 c_break_label
= build_int_cst (size_type_node
, 2);
11641 c_break_label
= size_one_node
;
11642 save_cont
= c_cont_label
;
11643 c_cont_label
= NULL_TREE
;
11644 body
= push_stmt_list ();
11646 if (open_brace_parsed
)
11648 location_t here
= c_parser_peek_token (parser
)->location
;
11649 stmt
= c_begin_compound_stmt (true);
11650 c_parser_compound_statement_nostart (parser
);
11651 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11654 add_stmt (c_parser_c99_block_statement (parser
));
11657 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11658 SET_EXPR_LOCATION (t
, loc
);
11662 body
= pop_stmt_list (body
);
11663 c_break_label
= save_break
;
11664 c_cont_label
= save_cont
;
11668 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11670 c_parser_consume_token (parser
);
11673 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11674 c_parser_consume_token (parser
);
11677 c_parser_error (parser
, "collapsed loops not perfectly nested");
11680 location_t here
= c_parser_peek_token (parser
)->location
;
11681 stmt
= c_begin_compound_stmt (true);
11683 c_parser_compound_statement_nostart (parser
);
11684 body
= c_end_compound_stmt (here
, stmt
, true);
11691 /* Only bother calling c_finish_omp_for if we haven't already generated
11692 an error from the initialization parsing. */
11695 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11696 incrv
, body
, NULL
);
11699 if (cclauses
!= NULL
11700 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11703 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11704 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11705 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11706 c
= &OMP_CLAUSE_CHAIN (*c
);
11709 for (i
= 0; i
< collapse
; i
++)
11710 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11713 c
= &OMP_CLAUSE_CHAIN (*c
);
11714 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11717 "iteration variable %qD should not be firstprivate",
11718 OMP_CLAUSE_DECL (*c
));
11719 *c
= OMP_CLAUSE_CHAIN (*c
);
11723 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11724 change it to shared (decl) in
11725 OMP_PARALLEL_CLAUSES. */
11726 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11727 OMP_CLAUSE_LASTPRIVATE
);
11728 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11729 OMP_CLAUSE_CHAIN (l
) = clauses
;
11731 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11735 OMP_FOR_CLAUSES (stmt
) = clauses
;
11740 while (!for_block
->is_empty ())
11742 /* FIXME diagnostics: LOC below should be the actual location of
11743 this particular for block. We need to build a list of
11744 locations to go along with FOR_BLOCK. */
11745 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11748 release_tree_vector (for_block
);
11752 /* Helper function for OpenMP parsing, split clauses and call
11753 finish_omp_clauses on each of the set of clauses afterwards. */
11756 omp_split_clauses (location_t loc
, enum tree_code code
,
11757 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11760 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11761 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11763 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11767 #pragma omp simd simd-clause[optseq] new-line
11770 LOC is the location of the #pragma token.
11773 #define OMP_SIMD_CLAUSE_MASK \
11774 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
11775 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
11776 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
11777 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11778 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11779 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11780 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
11783 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
11784 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11786 tree block
, clauses
, ret
;
11788 strcat (p_name
, " simd");
11789 mask
|= OMP_SIMD_CLAUSE_MASK
;
11790 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
11792 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11795 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
11796 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
11799 block
= c_begin_compound_stmt (true);
11800 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
11801 block
= c_end_compound_stmt (loc
, block
, true);
11808 #pragma omp for for-clause[optseq] new-line
11812 #pragma omp for simd for-simd-clause[optseq] new-line
11815 LOC is the location of the #pragma token.
11818 #define OMP_FOR_CLAUSE_MASK \
11819 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11820 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11821 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11822 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11823 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
11824 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
11825 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11826 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11829 c_parser_omp_for (location_t loc
, c_parser
*parser
,
11830 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11832 tree block
, clauses
, ret
;
11834 strcat (p_name
, " for");
11835 mask
|= OMP_FOR_CLAUSE_MASK
;
11837 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
11839 if (c_parser_next_token_is (parser
, CPP_NAME
))
11841 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11843 if (strcmp (p
, "simd") == 0)
11845 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
11846 if (cclauses
== NULL
)
11847 cclauses
= cclauses_buf
;
11849 c_parser_consume_token (parser
);
11850 if (!flag_openmp
) /* flag_openmp_simd */
11851 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
11852 block
= c_begin_compound_stmt (true);
11853 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
11854 block
= c_end_compound_stmt (loc
, block
, true);
11855 if (ret
== NULL_TREE
)
11857 ret
= make_node (OMP_FOR
);
11858 TREE_TYPE (ret
) = void_type_node
;
11859 OMP_FOR_BODY (ret
) = block
;
11860 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11861 SET_EXPR_LOCATION (ret
, loc
);
11866 if (!flag_openmp
) /* flag_openmp_simd */
11868 c_parser_skip_to_pragma_eol (parser
);
11872 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11875 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
11876 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11879 block
= c_begin_compound_stmt (true);
11880 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
11881 block
= c_end_compound_stmt (loc
, block
, true);
11888 # pragma omp master new-line
11891 LOC is the location of the #pragma token.
11895 c_parser_omp_master (location_t loc
, c_parser
*parser
)
11897 c_parser_skip_to_pragma_eol (parser
);
11898 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
11902 # pragma omp ordered new-line
11905 LOC is the location of the #pragma itself.
11909 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
11911 c_parser_skip_to_pragma_eol (parser
);
11912 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
11918 { section-sequence }
11921 section-directive[opt] structured-block
11922 section-sequence section-directive structured-block
11924 SECTIONS_LOC is the location of the #pragma omp sections. */
11927 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
11929 tree stmt
, substmt
;
11930 bool error_suppress
= false;
11933 loc
= c_parser_peek_token (parser
)->location
;
11934 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
11936 /* Avoid skipping until the end of the block. */
11937 parser
->error
= false;
11941 stmt
= push_stmt_list ();
11943 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
11945 substmt
= c_parser_omp_structured_block (parser
);
11946 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11947 SET_EXPR_LOCATION (substmt
, loc
);
11948 add_stmt (substmt
);
11953 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11955 if (c_parser_next_token_is (parser
, CPP_EOF
))
11958 loc
= c_parser_peek_token (parser
)->location
;
11959 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
11961 c_parser_consume_pragma (parser
);
11962 c_parser_skip_to_pragma_eol (parser
);
11963 error_suppress
= false;
11965 else if (!error_suppress
)
11967 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
11968 error_suppress
= true;
11971 substmt
= c_parser_omp_structured_block (parser
);
11972 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11973 SET_EXPR_LOCATION (substmt
, loc
);
11974 add_stmt (substmt
);
11976 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
11977 "expected %<#pragma omp section%> or %<}%>");
11979 substmt
= pop_stmt_list (stmt
);
11981 stmt
= make_node (OMP_SECTIONS
);
11982 SET_EXPR_LOCATION (stmt
, sections_loc
);
11983 TREE_TYPE (stmt
) = void_type_node
;
11984 OMP_SECTIONS_BODY (stmt
) = substmt
;
11986 return add_stmt (stmt
);
11990 # pragma omp sections sections-clause[optseq] newline
11993 LOC is the location of the #pragma token.
11996 #define OMP_SECTIONS_CLAUSE_MASK \
11997 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11998 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11999 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12000 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12001 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12004 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12005 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12007 tree block
, clauses
, ret
;
12009 strcat (p_name
, " sections");
12010 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12012 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12014 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12017 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12018 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12021 block
= c_begin_compound_stmt (true);
12022 ret
= c_parser_omp_sections_scope (loc
, parser
);
12024 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12025 block
= c_end_compound_stmt (loc
, block
, true);
12032 # pragma parallel parallel-clause new-line
12033 # pragma parallel for parallel-for-clause new-line
12034 # pragma parallel sections parallel-sections-clause new-line
12036 LOC is the location of the #pragma token.
12039 #define OMP_PARALLEL_CLAUSE_MASK \
12040 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12041 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12042 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12043 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12047 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12051 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12052 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12054 tree stmt
, clauses
, block
;
12056 strcat (p_name
, " parallel");
12057 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12059 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12061 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12062 if (cclauses
== NULL
)
12063 cclauses
= cclauses_buf
;
12065 c_parser_consume_token (parser
);
12066 if (!flag_openmp
) /* flag_openmp_simd */
12067 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12068 block
= c_begin_omp_parallel ();
12069 c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12071 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12073 OMP_PARALLEL_COMBINED (stmt
) = 1;
12078 error_at (loc
, "expected %<for%> after %qs", p_name
);
12079 c_parser_skip_to_pragma_eol (parser
);
12082 else if (!flag_openmp
) /* flag_openmp_simd */
12084 c_parser_skip_to_pragma_eol (parser
);
12087 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12089 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12090 if (strcmp (p
, "sections") == 0)
12092 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12093 if (cclauses
== NULL
)
12094 cclauses
= cclauses_buf
;
12096 c_parser_consume_token (parser
);
12097 block
= c_begin_omp_parallel ();
12098 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12099 stmt
= c_finish_omp_parallel (loc
,
12100 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12102 OMP_PARALLEL_COMBINED (stmt
) = 1;
12107 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12109 block
= c_begin_omp_parallel ();
12110 c_parser_statement (parser
);
12111 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12117 # pragma omp single single-clause[optseq] new-line
12120 LOC is the location of the #pragma.
12123 #define OMP_SINGLE_CLAUSE_MASK \
12124 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12125 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12126 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12127 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12130 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12132 tree stmt
= make_node (OMP_SINGLE
);
12133 SET_EXPR_LOCATION (stmt
, loc
);
12134 TREE_TYPE (stmt
) = void_type_node
;
12136 OMP_SINGLE_CLAUSES (stmt
)
12137 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12138 "#pragma omp single");
12139 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12141 return add_stmt (stmt
);
12145 # pragma omp task task-clause[optseq] new-line
12147 LOC is the location of the #pragma.
12150 #define OMP_TASK_CLAUSE_MASK \
12151 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12152 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12153 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12154 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12155 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12156 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12158 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12159 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12162 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12164 tree clauses
, block
;
12166 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12167 "#pragma omp task");
12169 block
= c_begin_omp_task ();
12170 c_parser_statement (parser
);
12171 return c_finish_omp_task (loc
, clauses
, block
);
12175 # pragma omp taskwait new-line
12179 c_parser_omp_taskwait (c_parser
*parser
)
12181 location_t loc
= c_parser_peek_token (parser
)->location
;
12182 c_parser_consume_pragma (parser
);
12183 c_parser_skip_to_pragma_eol (parser
);
12185 c_finish_omp_taskwait (loc
);
12189 # pragma omp taskyield new-line
12193 c_parser_omp_taskyield (c_parser
*parser
)
12195 location_t loc
= c_parser_peek_token (parser
)->location
;
12196 c_parser_consume_pragma (parser
);
12197 c_parser_skip_to_pragma_eol (parser
);
12199 c_finish_omp_taskyield (loc
);
12203 # pragma omp taskgroup new-line
12207 c_parser_omp_taskgroup (c_parser
*parser
)
12209 location_t loc
= c_parser_peek_token (parser
)->location
;
12210 c_parser_skip_to_pragma_eol (parser
);
12211 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12215 # pragma omp cancel cancel-clause[optseq] new-line
12217 LOC is the location of the #pragma.
12220 #define OMP_CANCEL_CLAUSE_MASK \
12221 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12222 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12223 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12224 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12225 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12228 c_parser_omp_cancel (c_parser
*parser
)
12230 location_t loc
= c_parser_peek_token (parser
)->location
;
12232 c_parser_consume_pragma (parser
);
12233 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12234 "#pragma omp cancel");
12236 c_finish_omp_cancel (loc
, clauses
);
12240 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12242 LOC is the location of the #pragma.
12245 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12246 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12247 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12248 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12249 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12252 c_parser_omp_cancellation_point (c_parser
*parser
)
12254 location_t loc
= c_parser_peek_token (parser
)->location
;
12256 bool point_seen
= false;
12258 c_parser_consume_pragma (parser
);
12259 if (c_parser_next_token_is (parser
, CPP_NAME
))
12261 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12262 if (strcmp (p
, "point") == 0)
12264 c_parser_consume_token (parser
);
12270 c_parser_error (parser
, "expected %<point%>");
12271 c_parser_skip_to_pragma_eol (parser
);
12276 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12277 "#pragma omp cancellation point");
12279 c_finish_omp_cancellation_point (loc
, clauses
);
12283 #pragma omp distribute distribute-clause[optseq] new-line
12286 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12287 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12288 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12289 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12290 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12293 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12294 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12296 tree clauses
, block
, ret
;
12298 strcat (p_name
, " distribute");
12299 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12301 if (c_parser_next_token_is (parser
, CPP_NAME
))
12303 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12305 bool parallel
= false;
12307 if (strcmp (p
, "simd") == 0)
12310 parallel
= strcmp (p
, "parallel") == 0;
12311 if (parallel
|| simd
)
12313 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12314 if (cclauses
== NULL
)
12315 cclauses
= cclauses_buf
;
12316 c_parser_consume_token (parser
);
12317 if (!flag_openmp
) /* flag_openmp_simd */
12320 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12322 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12325 block
= c_begin_compound_stmt (true);
12327 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12329 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12330 block
= c_end_compound_stmt (loc
, block
, true);
12333 ret
= make_node (OMP_DISTRIBUTE
);
12334 TREE_TYPE (ret
) = void_type_node
;
12335 OMP_FOR_BODY (ret
) = block
;
12336 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12337 SET_EXPR_LOCATION (ret
, loc
);
12342 if (!flag_openmp
) /* flag_openmp_simd */
12344 c_parser_skip_to_pragma_eol (parser
);
12348 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12351 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12352 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12355 block
= c_begin_compound_stmt (true);
12356 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12357 block
= c_end_compound_stmt (loc
, block
, true);
12364 # pragma omp teams teams-clause[optseq] new-line
12365 structured-block */
12367 #define OMP_TEAMS_CLAUSE_MASK \
12368 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12369 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12370 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12371 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12372 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12373 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12374 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12377 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12378 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12380 tree clauses
, block
, ret
;
12382 strcat (p_name
, " teams");
12383 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12385 if (c_parser_next_token_is (parser
, CPP_NAME
))
12387 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12388 if (strcmp (p
, "distribute") == 0)
12390 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12391 if (cclauses
== NULL
)
12392 cclauses
= cclauses_buf
;
12394 c_parser_consume_token (parser
);
12395 if (!flag_openmp
) /* flag_openmp_simd */
12396 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12397 block
= c_begin_compound_stmt (true);
12398 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12399 block
= c_end_compound_stmt (loc
, block
, true);
12402 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12403 ret
= make_node (OMP_TEAMS
);
12404 TREE_TYPE (ret
) = void_type_node
;
12405 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12406 OMP_TEAMS_BODY (ret
) = block
;
12407 return add_stmt (ret
);
12410 if (!flag_openmp
) /* flag_openmp_simd */
12412 c_parser_skip_to_pragma_eol (parser
);
12416 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12419 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12420 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12423 tree stmt
= make_node (OMP_TEAMS
);
12424 TREE_TYPE (stmt
) = void_type_node
;
12425 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12426 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12428 return add_stmt (stmt
);
12432 # pragma omp target data target-data-clause[optseq] new-line
12433 structured-block */
12435 #define OMP_TARGET_DATA_CLAUSE_MASK \
12436 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12437 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12438 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12441 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12443 tree stmt
= make_node (OMP_TARGET_DATA
);
12444 TREE_TYPE (stmt
) = void_type_node
;
12446 OMP_TARGET_DATA_CLAUSES (stmt
)
12447 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12448 "#pragma omp target data");
12449 keep_next_level ();
12450 tree block
= c_begin_compound_stmt (true);
12451 add_stmt (c_parser_omp_structured_block (parser
));
12452 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12454 SET_EXPR_LOCATION (stmt
, loc
);
12455 return add_stmt (stmt
);
12459 # pragma omp target update target-update-clause[optseq] new-line */
12461 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12462 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12463 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12464 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12465 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12468 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12469 enum pragma_context context
)
12471 if (context
== pragma_stmt
)
12474 "%<#pragma omp target update%> may only be "
12475 "used in compound statements");
12476 c_parser_skip_to_pragma_eol (parser
);
12481 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12482 "#pragma omp target update");
12483 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12484 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12487 "%<#pragma omp target update must contain at least one "
12488 "%<from%> or %<to%> clauses");
12492 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12493 TREE_TYPE (stmt
) = void_type_node
;
12494 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12495 SET_EXPR_LOCATION (stmt
, loc
);
12501 # pragma omp target target-clause[optseq] new-line
12502 structured-block */
12504 #define OMP_TARGET_CLAUSE_MASK \
12505 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12506 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12507 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12510 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12512 location_t loc
= c_parser_peek_token (parser
)->location
;
12513 c_parser_consume_pragma (parser
);
12515 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12517 c_parser_error (parser
, "expected declaration specifiers");
12518 c_parser_skip_to_pragma_eol (parser
);
12522 if (c_parser_next_token_is (parser
, CPP_NAME
))
12524 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12526 if (strcmp (p
, "teams") == 0)
12528 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12529 char p_name
[sizeof ("#pragma omp target teams distribute "
12530 "parallel for simd")];
12532 c_parser_consume_token (parser
);
12533 if (!flag_openmp
) /* flag_openmp_simd */
12534 return c_parser_omp_teams (loc
, parser
, p_name
,
12535 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12536 strcpy (p_name
, "#pragma omp target");
12537 keep_next_level ();
12538 tree block
= c_begin_compound_stmt (true);
12539 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12540 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12541 block
= c_end_compound_stmt (loc
, block
, true);
12544 tree stmt
= make_node (OMP_TARGET
);
12545 TREE_TYPE (stmt
) = void_type_node
;
12546 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12547 OMP_TARGET_BODY (stmt
) = block
;
12551 else if (!flag_openmp
) /* flag_openmp_simd */
12553 c_parser_skip_to_pragma_eol (parser
);
12556 else if (strcmp (p
, "data") == 0)
12558 c_parser_consume_token (parser
);
12559 c_parser_omp_target_data (loc
, parser
);
12562 else if (strcmp (p
, "update") == 0)
12564 c_parser_consume_token (parser
);
12565 return c_parser_omp_target_update (loc
, parser
, context
);
12569 tree stmt
= make_node (OMP_TARGET
);
12570 TREE_TYPE (stmt
) = void_type_node
;
12572 OMP_TARGET_CLAUSES (stmt
)
12573 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12574 "#pragma omp target");
12575 keep_next_level ();
12576 tree block
= c_begin_compound_stmt (true);
12577 add_stmt (c_parser_omp_structured_block (parser
));
12578 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12580 SET_EXPR_LOCATION (stmt
, loc
);
12586 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12588 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12589 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12590 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12591 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12592 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12593 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12594 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12597 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12599 vec
<c_token
> clauses
= vNULL
;
12600 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12602 c_token
*token
= c_parser_peek_token (parser
);
12603 if (token
->type
== CPP_EOF
)
12605 c_parser_skip_to_pragma_eol (parser
);
12606 clauses
.release ();
12609 clauses
.safe_push (*token
);
12610 c_parser_consume_token (parser
);
12612 clauses
.safe_push (*c_parser_peek_token (parser
));
12613 c_parser_skip_to_pragma_eol (parser
);
12615 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12617 if (c_parser_peek_token (parser
)->pragma_kind
12618 != PRAGMA_OMP_DECLARE_REDUCTION
12619 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12620 || strcmp (IDENTIFIER_POINTER
12621 (c_parser_peek_2nd_token (parser
)->value
),
12624 c_parser_error (parser
,
12625 "%<#pragma omp declare simd%> must be followed by "
12626 "function declaration or definition or another "
12627 "%<#pragma omp declare simd%>");
12628 clauses
.release ();
12631 c_parser_consume_pragma (parser
);
12632 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12634 c_token
*token
= c_parser_peek_token (parser
);
12635 if (token
->type
== CPP_EOF
)
12637 c_parser_skip_to_pragma_eol (parser
);
12638 clauses
.release ();
12641 clauses
.safe_push (*token
);
12642 c_parser_consume_token (parser
);
12644 clauses
.safe_push (*c_parser_peek_token (parser
));
12645 c_parser_skip_to_pragma_eol (parser
);
12648 /* Make sure nothing tries to read past the end of the tokens. */
12650 memset (&eof_token
, 0, sizeof (eof_token
));
12651 eof_token
.type
= CPP_EOF
;
12652 clauses
.safe_push (eof_token
);
12653 clauses
.safe_push (eof_token
);
12657 case pragma_external
:
12658 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12659 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12661 int ext
= disable_extension_diagnostics ();
12663 c_parser_consume_token (parser
);
12664 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12665 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12666 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12668 restore_extension_diagnostics (ext
);
12671 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12674 case pragma_struct
:
12676 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12677 "function declaration or definition");
12679 case pragma_compound
:
12681 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12682 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12684 int ext
= disable_extension_diagnostics ();
12686 c_parser_consume_token (parser
);
12687 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12688 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12689 if (c_parser_next_tokens_start_declaration (parser
))
12691 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12692 true, NULL
, clauses
);
12693 restore_extension_diagnostics (ext
);
12696 restore_extension_diagnostics (ext
);
12698 else if (c_parser_next_tokens_start_declaration (parser
))
12700 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12704 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12705 "function declaration or definition");
12708 gcc_unreachable ();
12710 clauses
.release ();
12713 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12714 and put that into "omp declare simd" attribute. */
12717 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12718 vec
<c_token
> clauses
)
12720 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12721 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12722 has already processed the tokens. */
12723 if (clauses
[0].type
== CPP_EOF
)
12725 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12727 error ("%<#pragma omp declare simd%> not immediately followed by "
12728 "a function declaration or definition");
12729 clauses
[0].type
= CPP_EOF
;
12732 if (clauses
[0].type
!= CPP_NAME
)
12734 error_at (DECL_SOURCE_LOCATION (fndecl
),
12735 "%<#pragma omp declare simd%> not immediately followed by "
12736 "a single function declaration or definition");
12737 clauses
[0].type
= CPP_EOF
;
12741 if (parms
== NULL_TREE
)
12742 parms
= DECL_ARGUMENTS (fndecl
);
12744 unsigned int tokens_avail
= parser
->tokens_avail
;
12745 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12746 parser
->tokens
= clauses
.address ();
12747 parser
->tokens_avail
= clauses
.length ();
12749 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12750 while (parser
->tokens_avail
> 3)
12752 c_token
*token
= c_parser_peek_token (parser
);
12753 gcc_assert (token
->type
== CPP_NAME
12754 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12755 c_parser_consume_token (parser
);
12756 parser
->in_pragma
= true;
12758 tree c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12759 "#pragma omp declare simd");
12760 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12761 if (c
!= NULL_TREE
)
12762 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12763 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12764 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12765 DECL_ATTRIBUTES (fndecl
) = c
;
12768 parser
->tokens
= &parser
->tokens_buf
[0];
12769 parser
->tokens_avail
= tokens_avail
;
12770 clauses
[0].type
= CPP_PRAGMA
;
12775 # pragma omp declare target new-line
12776 declarations and definitions
12777 # pragma omp end declare target new-line */
12780 c_parser_omp_declare_target (c_parser
*parser
)
12782 c_parser_skip_to_pragma_eol (parser
);
12783 current_omp_declare_target_attribute
++;
12787 c_parser_omp_end_declare_target (c_parser
*parser
)
12789 location_t loc
= c_parser_peek_token (parser
)->location
;
12790 c_parser_consume_pragma (parser
);
12791 if (c_parser_next_token_is (parser
, CPP_NAME
)
12792 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12795 c_parser_consume_token (parser
);
12796 if (c_parser_next_token_is (parser
, CPP_NAME
)
12797 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12799 c_parser_consume_token (parser
);
12802 c_parser_error (parser
, "expected %<target%>");
12803 c_parser_skip_to_pragma_eol (parser
);
12809 c_parser_error (parser
, "expected %<declare%>");
12810 c_parser_skip_to_pragma_eol (parser
);
12813 c_parser_skip_to_pragma_eol (parser
);
12814 if (!current_omp_declare_target_attribute
)
12815 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
12816 "%<#pragma omp declare target%>");
12818 current_omp_declare_target_attribute
--;
12823 #pragma omp declare reduction (reduction-id : typename-list : expression) \
12824 initializer-clause[opt] new-line
12826 initializer-clause:
12827 initializer (omp_priv = initializer)
12828 initializer (function-name (argument-list)) */
12831 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
12833 unsigned int tokens_avail
= 0, i
;
12834 vec
<tree
> types
= vNULL
;
12835 vec
<c_token
> clauses
= vNULL
;
12836 enum tree_code reduc_code
= ERROR_MARK
;
12837 tree reduc_id
= NULL_TREE
;
12839 location_t rloc
= c_parser_peek_token (parser
)->location
;
12841 if (context
== pragma_struct
|| context
== pragma_param
)
12843 error ("%<#pragma omp declare reduction%> not at file or block scope");
12847 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12850 switch (c_parser_peek_token (parser
)->type
)
12853 reduc_code
= PLUS_EXPR
;
12856 reduc_code
= MULT_EXPR
;
12859 reduc_code
= MINUS_EXPR
;
12862 reduc_code
= BIT_AND_EXPR
;
12865 reduc_code
= BIT_XOR_EXPR
;
12868 reduc_code
= BIT_IOR_EXPR
;
12871 reduc_code
= TRUTH_ANDIF_EXPR
;
12874 reduc_code
= TRUTH_ORIF_EXPR
;
12878 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12879 if (strcmp (p
, "min") == 0)
12881 reduc_code
= MIN_EXPR
;
12884 if (strcmp (p
, "max") == 0)
12886 reduc_code
= MAX_EXPR
;
12889 reduc_id
= c_parser_peek_token (parser
)->value
;
12892 c_parser_error (parser
,
12893 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12894 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
12898 tree orig_reduc_id
, reduc_decl
;
12899 orig_reduc_id
= reduc_id
;
12900 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
12901 reduc_decl
= c_omp_reduction_decl (reduc_id
);
12902 c_parser_consume_token (parser
);
12904 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12909 location_t loc
= c_parser_peek_token (parser
)->location
;
12910 struct c_type_name
*ctype
= c_parser_type_name (parser
);
12913 type
= groktypename (ctype
, NULL
, NULL
);
12914 if (type
== error_mark_node
)
12916 else if ((INTEGRAL_TYPE_P (type
)
12917 || TREE_CODE (type
) == REAL_TYPE
12918 || TREE_CODE (type
) == COMPLEX_TYPE
)
12919 && orig_reduc_id
== NULL_TREE
)
12920 error_at (loc
, "predeclared arithmetic type in "
12921 "%<#pragma omp declare reduction%>");
12922 else if (TREE_CODE (type
) == FUNCTION_TYPE
12923 || TREE_CODE (type
) == ARRAY_TYPE
)
12924 error_at (loc
, "function or array type in "
12925 "%<#pragma omp declare reduction%>");
12926 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
12927 error_at (loc
, "const, volatile or restrict qualified type in "
12928 "%<#pragma omp declare reduction%>");
12932 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
12933 if (comptypes (TREE_PURPOSE (t
), type
))
12935 error_at (loc
, "redeclaration of %qs "
12936 "%<#pragma omp declare reduction%> for "
12938 IDENTIFIER_POINTER (reduc_id
)
12939 + sizeof ("omp declare reduction ") - 1,
12942 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
12944 error_at (ploc
, "previous %<#pragma omp declare "
12948 if (t
== NULL_TREE
)
12949 types
.safe_push (type
);
12951 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12952 c_parser_consume_token (parser
);
12960 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
12961 || types
.is_empty ())
12964 clauses
.release ();
12968 c_token
*token
= c_parser_peek_token (parser
);
12969 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
12971 c_parser_consume_token (parser
);
12973 c_parser_skip_to_pragma_eol (parser
);
12977 if (types
.length () > 1)
12979 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12981 c_token
*token
= c_parser_peek_token (parser
);
12982 if (token
->type
== CPP_EOF
)
12984 clauses
.safe_push (*token
);
12985 c_parser_consume_token (parser
);
12987 clauses
.safe_push (*c_parser_peek_token (parser
));
12988 c_parser_skip_to_pragma_eol (parser
);
12990 /* Make sure nothing tries to read past the end of the tokens. */
12992 memset (&eof_token
, 0, sizeof (eof_token
));
12993 eof_token
.type
= CPP_EOF
;
12994 clauses
.safe_push (eof_token
);
12995 clauses
.safe_push (eof_token
);
12998 int errs
= errorcount
;
12999 FOR_EACH_VEC_ELT (types
, i
, type
)
13001 tokens_avail
= parser
->tokens_avail
;
13002 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13003 if (!clauses
.is_empty ())
13005 parser
->tokens
= clauses
.address ();
13006 parser
->tokens_avail
= clauses
.length ();
13007 parser
->in_pragma
= true;
13010 bool nested
= current_function_decl
!= NULL_TREE
;
13012 c_push_function_context ();
13013 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13014 reduc_id
, default_function_type
);
13015 current_function_decl
= fndecl
;
13016 allocate_struct_function (fndecl
, true);
13018 tree stmt
= push_stmt_list ();
13019 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13020 warn about these. */
13021 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13022 get_identifier ("omp_out"), type
);
13023 DECL_ARTIFICIAL (omp_out
) = 1;
13024 DECL_CONTEXT (omp_out
) = fndecl
;
13025 pushdecl (omp_out
);
13026 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13027 get_identifier ("omp_in"), type
);
13028 DECL_ARTIFICIAL (omp_in
) = 1;
13029 DECL_CONTEXT (omp_in
) = fndecl
;
13031 struct c_expr combiner
= c_parser_expression (parser
);
13032 struct c_expr initializer
;
13033 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13035 initializer
.value
= error_mark_node
;
13036 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13038 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13039 && strcmp (IDENTIFIER_POINTER
13040 (c_parser_peek_token (parser
)->value
),
13041 "initializer") == 0)
13043 c_parser_consume_token (parser
);
13046 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13047 get_identifier ("omp_priv"), type
);
13048 DECL_ARTIFICIAL (omp_priv
) = 1;
13049 DECL_INITIAL (omp_priv
) = error_mark_node
;
13050 DECL_CONTEXT (omp_priv
) = fndecl
;
13051 pushdecl (omp_priv
);
13052 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13053 get_identifier ("omp_orig"), type
);
13054 DECL_ARTIFICIAL (omp_orig
) = 1;
13055 DECL_CONTEXT (omp_orig
) = fndecl
;
13056 pushdecl (omp_orig
);
13057 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13059 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13061 c_parser_error (parser
, "expected %<omp_priv%> or "
13065 else if (strcmp (IDENTIFIER_POINTER
13066 (c_parser_peek_token (parser
)->value
),
13069 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13070 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13072 c_parser_error (parser
, "expected function-name %<(%>");
13076 initializer
= c_parser_postfix_expression (parser
);
13077 if (initializer
.value
13078 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13081 tree c
= initializer
.value
;
13082 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13083 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13084 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13086 if (j
== call_expr_nargs (c
))
13087 error ("one of the initializer call arguments should be "
13093 c_parser_consume_token (parser
);
13094 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13098 tree st
= push_stmt_list ();
13099 start_init (omp_priv
, NULL_TREE
, 0);
13100 location_t loc
= c_parser_peek_token (parser
)->location
;
13101 struct c_expr init
= c_parser_initializer (parser
);
13103 finish_decl (omp_priv
, loc
, init
.value
,
13104 init
.original_type
, NULL_TREE
);
13105 pop_stmt_list (st
);
13109 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13115 c_parser_skip_to_pragma_eol (parser
);
13117 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13118 DECL_INITIAL (reduc_decl
));
13119 DECL_INITIAL (reduc_decl
) = t
;
13120 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13121 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13122 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13123 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13124 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13125 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13128 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13129 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13130 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13131 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13132 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13133 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13134 walk_tree (&DECL_INITIAL (omp_priv
),
13135 c_check_omp_declare_reduction_r
,
13136 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13140 pop_stmt_list (stmt
);
13142 if (cfun
->language
!= NULL
)
13144 ggc_free (cfun
->language
);
13145 cfun
->language
= NULL
;
13148 current_function_decl
= NULL_TREE
;
13150 c_pop_function_context ();
13152 if (!clauses
.is_empty ())
13154 parser
->tokens
= &parser
->tokens_buf
[0];
13155 parser
->tokens_avail
= tokens_avail
;
13159 if (errs
!= errorcount
)
13163 clauses
.release ();
13169 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13170 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13171 initializer-clause[opt] new-line
13172 #pragma omp declare target new-line */
13175 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13177 c_parser_consume_pragma (parser
);
13178 if (c_parser_next_token_is (parser
, CPP_NAME
))
13180 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13181 if (strcmp (p
, "simd") == 0)
13183 /* c_parser_consume_token (parser); done in
13184 c_parser_omp_declare_simd. */
13185 c_parser_omp_declare_simd (parser
, context
);
13188 if (strcmp (p
, "reduction") == 0)
13190 c_parser_consume_token (parser
);
13191 c_parser_omp_declare_reduction (parser
, context
);
13194 if (!flag_openmp
) /* flag_openmp_simd */
13196 c_parser_skip_to_pragma_eol (parser
);
13199 if (strcmp (p
, "target") == 0)
13201 c_parser_consume_token (parser
);
13202 c_parser_omp_declare_target (parser
);
13207 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13209 c_parser_skip_to_pragma_eol (parser
);
13212 /* Main entry point to parsing most OpenMP pragmas. */
13215 c_parser_omp_construct (c_parser
*parser
)
13217 enum pragma_kind p_kind
;
13220 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13221 omp_clause_mask
mask (0);
13223 loc
= c_parser_peek_token (parser
)->location
;
13224 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13225 c_parser_consume_pragma (parser
);
13229 case PRAGMA_OMP_ATOMIC
:
13230 c_parser_omp_atomic (loc
, parser
);
13232 case PRAGMA_OMP_CRITICAL
:
13233 stmt
= c_parser_omp_critical (loc
, parser
);
13235 case PRAGMA_OMP_DISTRIBUTE
:
13236 strcpy (p_name
, "#pragma omp");
13237 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13239 case PRAGMA_OMP_FOR
:
13240 strcpy (p_name
, "#pragma omp");
13241 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13243 case PRAGMA_OMP_MASTER
:
13244 stmt
= c_parser_omp_master (loc
, parser
);
13246 case PRAGMA_OMP_ORDERED
:
13247 stmt
= c_parser_omp_ordered (loc
, parser
);
13249 case PRAGMA_OMP_PARALLEL
:
13250 strcpy (p_name
, "#pragma omp");
13251 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13253 case PRAGMA_OMP_SECTIONS
:
13254 strcpy (p_name
, "#pragma omp");
13255 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13257 case PRAGMA_OMP_SIMD
:
13258 strcpy (p_name
, "#pragma omp");
13259 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13261 case PRAGMA_OMP_SINGLE
:
13262 stmt
= c_parser_omp_single (loc
, parser
);
13264 case PRAGMA_OMP_TASK
:
13265 stmt
= c_parser_omp_task (loc
, parser
);
13267 case PRAGMA_OMP_TASKGROUP
:
13268 stmt
= c_parser_omp_taskgroup (parser
);
13270 case PRAGMA_OMP_TEAMS
:
13271 strcpy (p_name
, "#pragma omp");
13272 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13275 gcc_unreachable ();
13279 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13284 # pragma omp threadprivate (variable-list) */
13287 c_parser_omp_threadprivate (c_parser
*parser
)
13292 c_parser_consume_pragma (parser
);
13293 loc
= c_parser_peek_token (parser
)->location
;
13294 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13296 /* Mark every variable in VARS to be assigned thread local storage. */
13297 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13299 tree v
= TREE_PURPOSE (t
);
13301 /* FIXME diagnostics: Ideally we should keep individual
13302 locations for all the variables in the var list to make the
13303 following errors more precise. Perhaps
13304 c_parser_omp_var_list_parens() should construct a list of
13305 locations to go along with the var list. */
13307 /* If V had already been marked threadprivate, it doesn't matter
13308 whether it had been used prior to this point. */
13309 if (TREE_CODE (v
) != VAR_DECL
)
13310 error_at (loc
, "%qD is not a variable", v
);
13311 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13312 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13313 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13314 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13315 else if (TREE_TYPE (v
) == error_mark_node
)
13317 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13318 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13321 if (! DECL_THREAD_LOCAL_P (v
))
13323 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
13324 /* If rtl has been already set for this var, call
13325 make_decl_rtl once again, so that encode_section_info
13326 has a chance to look at the new decl flags. */
13327 if (DECL_RTL_SET_P (v
))
13330 C_DECL_THREADPRIVATE_P (v
) = 1;
13334 c_parser_skip_to_pragma_eol (parser
);
13337 /* Cilk Plus <#pragma simd> parsing routines. */
13339 /* Helper function for c_parser_pragma. Perform some sanity checking
13340 for <#pragma simd> constructs. Returns FALSE if there was a
13344 c_parser_cilk_verify_simd (c_parser
*parser
,
13345 enum pragma_context context
)
13347 if (!flag_enable_cilkplus
)
13349 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13350 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13353 if (context
== pragma_external
)
13355 c_parser_error (parser
,"pragma simd must be inside a function");
13356 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13363 vectorlength ( constant-expression ) */
13366 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
)
13368 /* The vectorlength clause behaves exactly like OpenMP's safelen
13369 clause. Represent it in OpenMP terms. */
13370 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13372 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13375 location_t loc
= c_parser_peek_token (parser
)->location
;
13376 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13377 expr
= c_fully_fold (expr
, false, NULL
);
13379 if (!TREE_TYPE (expr
)
13380 || !TREE_CONSTANT (expr
)
13381 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13382 error_at (loc
, "vectorlength must be an integer constant");
13383 else if (exact_log2 (TREE_INT_CST_LOW (expr
)) == -1)
13384 error_at (loc
, "vectorlength must be a power of 2");
13387 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13388 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13389 OMP_CLAUSE_CHAIN (u
) = clauses
;
13393 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13399 linear ( simd-linear-variable-list )
13401 simd-linear-variable-list:
13402 simd-linear-variable
13403 simd-linear-variable-list , simd-linear-variable
13405 simd-linear-variable:
13407 id-expression : simd-linear-step
13410 conditional-expression */
13413 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13415 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13418 location_t loc
= c_parser_peek_token (parser
)->location
;
13420 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13421 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13422 c_parser_error (parser
, "expected identifier");
13424 while (c_parser_next_token_is (parser
, CPP_NAME
)
13425 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13427 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13431 undeclared_variable (c_parser_peek_token (parser
)->location
,
13432 c_parser_peek_token (parser
)->value
);
13433 c_parser_consume_token (parser
);
13435 else if (var
== error_mark_node
)
13436 c_parser_consume_token (parser
);
13439 tree step
= integer_one_node
;
13441 /* Parse the linear step if present. */
13442 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13444 c_parser_consume_token (parser
);
13445 c_parser_consume_token (parser
);
13447 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13448 expr
= c_fully_fold (expr
, false, NULL
);
13450 if (TREE_TYPE (expr
)
13451 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13452 && (TREE_CONSTANT (expr
)
13456 c_parser_error (parser
,
13457 "step size must be an integer constant "
13458 "expression or an integer variable");
13461 c_parser_consume_token (parser
);
13463 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13464 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13465 OMP_CLAUSE_DECL (u
) = var
;
13466 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13467 OMP_CLAUSE_CHAIN (u
) = clauses
;
13471 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13474 c_parser_consume_token (parser
);
13477 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13482 /* Returns the name of the next clause. If the clause is not
13483 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13484 not consumed. Otherwise, the appropriate pragma_simd_clause is
13485 returned and the token is consumed. */
13487 static pragma_cilk_clause
13488 c_parser_cilk_clause_name (c_parser
*parser
)
13490 pragma_cilk_clause result
;
13491 c_token
*token
= c_parser_peek_token (parser
);
13493 if (!token
->value
|| token
->type
!= CPP_NAME
)
13494 return PRAGMA_CILK_CLAUSE_NONE
;
13496 const char *p
= IDENTIFIER_POINTER (token
->value
);
13498 if (!strcmp (p
, "vectorlength"))
13499 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13500 else if (!strcmp (p
, "linear"))
13501 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13502 else if (!strcmp (p
, "private"))
13503 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13504 else if (!strcmp (p
, "firstprivate"))
13505 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13506 else if (!strcmp (p
, "lastprivate"))
13507 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13508 else if (!strcmp (p
, "reduction"))
13509 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13511 return PRAGMA_CILK_CLAUSE_NONE
;
13513 c_parser_consume_token (parser
);
13517 /* Parse all #<pragma simd> clauses. Return the list of clauses
13521 c_parser_cilk_all_clauses (c_parser
*parser
)
13523 tree clauses
= NULL
;
13525 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13527 pragma_cilk_clause c_kind
;
13529 c_kind
= c_parser_cilk_clause_name (parser
);
13533 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13534 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
);
13536 case PRAGMA_CILK_CLAUSE_LINEAR
:
13537 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13539 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13540 /* Use the OpenMP counterpart. */
13541 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13543 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13544 /* Use the OpenMP counterpart. */
13545 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13547 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13548 /* Use the OpenMP counterpart. */
13549 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13551 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13552 /* Use the OpenMP counterpart. */
13553 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13556 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13562 c_parser_skip_to_pragma_eol (parser
);
13563 return c_finish_cilk_clauses (clauses
);
13566 /* Main entry point for parsing Cilk Plus <#pragma simd> for
13570 c_parser_cilk_simd (c_parser
*parser ATTRIBUTE_UNUSED
)
13573 strcpy (p_name
, "#pragma omp");
13574 tree clauses
= c_parser_cilk_all_clauses (parser
);
13575 tree block
= c_begin_compound_stmt (true);
13576 location_t loc
= c_parser_peek_token (parser
)->location
;
13577 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
13578 block
= c_end_compound_stmt (loc
, block
, true);
13582 /* Parse a transaction attribute (GCC Extension).
13584 transaction-attribute:
13588 The transactional memory language description is written for C++,
13589 and uses the C++0x attribute syntax. For compatibility, allow the
13590 bracket style for transactions in C as well. */
13593 c_parser_transaction_attributes (c_parser
*parser
)
13595 tree attr_name
, attr
= NULL
;
13597 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13598 return c_parser_attributes (parser
);
13600 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13602 c_parser_consume_token (parser
);
13603 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13606 attr_name
= c_parser_attribute_any_word (parser
);
13609 c_parser_consume_token (parser
);
13610 attr
= build_tree_list (attr_name
, NULL_TREE
);
13613 c_parser_error (parser
, "expected identifier");
13615 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13617 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13621 /* Parse a __transaction_atomic or __transaction_relaxed statement
13624 transaction-statement:
13625 __transaction_atomic transaction-attribute[opt] compound-statement
13626 __transaction_relaxed compound-statement
13628 Note that the only valid attribute is: "outer".
13632 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13634 unsigned int old_in
= parser
->in_transaction
;
13635 unsigned int this_in
= 1, new_in
;
13636 location_t loc
= c_parser_peek_token (parser
)->location
;
13639 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13640 || keyword
== RID_TRANSACTION_RELAXED
)
13641 && c_parser_next_token_is_keyword (parser
, keyword
));
13642 c_parser_consume_token (parser
);
13644 if (keyword
== RID_TRANSACTION_RELAXED
)
13645 this_in
|= TM_STMT_ATTR_RELAXED
;
13648 attrs
= c_parser_transaction_attributes (parser
);
13650 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13653 /* Keep track if we're in the lexical scope of an outer transaction. */
13654 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13656 parser
->in_transaction
= new_in
;
13657 stmt
= c_parser_compound_statement (parser
);
13658 parser
->in_transaction
= old_in
;
13661 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13663 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13664 "%<__transaction_atomic%> without transactional memory support enabled"
13665 : "%<__transaction_relaxed %> "
13666 "without transactional memory support enabled"));
13671 /* Parse a __transaction_atomic or __transaction_relaxed expression
13674 transaction-expression:
13675 __transaction_atomic ( expression )
13676 __transaction_relaxed ( expression )
13679 static struct c_expr
13680 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13683 unsigned int old_in
= parser
->in_transaction
;
13684 unsigned int this_in
= 1;
13685 location_t loc
= c_parser_peek_token (parser
)->location
;
13688 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13689 || keyword
== RID_TRANSACTION_RELAXED
)
13690 && c_parser_next_token_is_keyword (parser
, keyword
));
13691 c_parser_consume_token (parser
);
13693 if (keyword
== RID_TRANSACTION_RELAXED
)
13694 this_in
|= TM_STMT_ATTR_RELAXED
;
13697 attrs
= c_parser_transaction_attributes (parser
);
13699 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13702 parser
->in_transaction
= this_in
;
13703 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13705 tree expr
= c_parser_expression (parser
).value
;
13706 ret
.original_type
= TREE_TYPE (expr
);
13707 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13708 if (this_in
& TM_STMT_ATTR_RELAXED
)
13709 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13710 SET_EXPR_LOCATION (ret
.value
, loc
);
13711 ret
.original_code
= TRANSACTION_EXPR
;
13712 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13714 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13721 ret
.value
= error_mark_node
;
13722 ret
.original_code
= ERROR_MARK
;
13723 ret
.original_type
= NULL
;
13725 parser
->in_transaction
= old_in
;
13728 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13729 "%<__transaction_atomic%> without transactional memory support enabled"
13730 : "%<__transaction_relaxed %> "
13731 "without transactional memory support enabled"));
13736 /* Parse a __transaction_cancel statement (GCC Extension).
13738 transaction-cancel-statement:
13739 __transaction_cancel transaction-attribute[opt] ;
13741 Note that the only valid attribute is "outer".
13745 c_parser_transaction_cancel (c_parser
*parser
)
13747 location_t loc
= c_parser_peek_token (parser
)->location
;
13749 bool is_outer
= false;
13751 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
13752 c_parser_consume_token (parser
);
13754 attrs
= c_parser_transaction_attributes (parser
);
13756 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
13760 error_at (loc
, "%<__transaction_cancel%> without "
13761 "transactional memory support enabled");
13764 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
13766 error_at (loc
, "%<__transaction_cancel%> within a "
13767 "%<__transaction_relaxed%>");
13772 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
13773 && !is_tm_may_cancel_outer (current_function_decl
))
13775 error_at (loc
, "outer %<__transaction_cancel%> not "
13776 "within outer %<__transaction_atomic%>");
13777 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
13781 else if (parser
->in_transaction
== 0)
13783 error_at (loc
, "%<__transaction_cancel%> not within "
13784 "%<__transaction_atomic%>");
13788 return add_stmt (build_tm_abort_call (loc
, is_outer
));
13791 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
13794 /* Parse a single source file. */
13797 c_parse_file (void)
13799 /* Use local storage to begin. If the first token is a pragma, parse it.
13800 If it is #pragma GCC pch_preprocess, then this will load a PCH file
13801 which will cause garbage collection. */
13804 memset (&tparser
, 0, sizeof tparser
);
13805 tparser
.tokens
= &tparser
.tokens_buf
[0];
13806 the_parser
= &tparser
;
13808 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
13809 c_parser_pragma_pch_preprocess (&tparser
);
13811 the_parser
= ggc_alloc_c_parser ();
13812 *the_parser
= tparser
;
13813 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
13814 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
13816 /* Initialize EH, if we've been told to do so. */
13817 if (flag_exceptions
)
13818 using_eh_for_cleanups ();
13820 c_parser_translation_unit (the_parser
);
13824 /* This function parses Cilk Plus array notation. The starting index is
13825 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
13826 return value of this function is a tree_node called VALUE_TREE of type
13827 ARRAY_NOTATION_REF. */
13830 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
13833 c_token
*token
= NULL
;
13834 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
13835 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
13836 tree array_type_domain
= NULL_TREE
;
13838 if (array_value
== error_mark_node
)
13840 /* No need to continue. If either of these 2 were true, then an error
13841 must be emitted already. Thus, no need to emit them twice. */
13842 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13843 return error_mark_node
;
13846 array_type
= TREE_TYPE (array_value
);
13847 gcc_assert (array_type
);
13848 type
= TREE_TYPE (array_type
);
13849 token
= c_parser_peek_token (parser
);
13851 if (token
->type
== CPP_EOF
)
13853 c_parser_error (parser
, "expected %<:%> or numeral");
13856 else if (token
->type
== CPP_COLON
)
13858 if (!initial_index
)
13860 /* If we are here, then we have a case like this A[:]. */
13861 c_parser_consume_token (parser
);
13862 if (TREE_CODE (array_type
) == POINTER_TYPE
)
13864 error_at (loc
, "start-index and length fields necessary for "
13865 "using array notations in pointers");
13866 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13867 return error_mark_node
;
13869 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13871 error_at (loc
, "array notations cannot be used with function "
13873 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13874 return error_mark_node
;
13876 array_type_domain
= TYPE_DOMAIN (array_type
);
13878 if (!array_type_domain
)
13880 error_at (loc
, "start-index and length fields necessary for "
13881 "using array notations in dimensionless arrays");
13882 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13883 return error_mark_node
;
13886 start_index
= TYPE_MINVAL (array_type_domain
);
13887 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
13889 if (!TYPE_MAXVAL (array_type_domain
)
13890 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
13892 error_at (loc
, "start-index and length fields necessary for "
13893 "using array notations in variable-length arrays");
13894 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13895 return error_mark_node
;
13897 end_index
= TYPE_MAXVAL (array_type_domain
);
13898 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
13899 end_index
, integer_one_node
);
13900 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
13901 stride
= build_int_cst (integer_type_node
, 1);
13902 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
13904 else if (initial_index
!= error_mark_node
)
13906 /* If we are here, then there should be 2 possibilities:
13907 1. Array [EXPR : EXPR]
13908 2. Array [EXPR : EXPR : EXPR]
13910 start_index
= initial_index
;
13912 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13914 error_at (loc
, "array notations cannot be used with function "
13916 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13917 return error_mark_node
;
13919 c_parser_consume_token (parser
); /* consume the ':' */
13920 struct c_expr ce
= c_parser_expression (parser
);
13921 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
13922 end_index
= ce
.value
;
13923 if (!end_index
|| end_index
== error_mark_node
)
13925 c_parser_skip_to_end_of_block_or_statement (parser
);
13926 return error_mark_node
;
13928 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
13930 c_parser_consume_token (parser
);
13931 ce
= c_parser_expression (parser
);
13932 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
13934 if (!stride
|| stride
== error_mark_node
)
13936 c_parser_skip_to_end_of_block_or_statement (parser
);
13937 return error_mark_node
;
13942 c_parser_error (parser
, "expected array notation expression");
13945 c_parser_error (parser
, "expected array notation expression");
13947 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13949 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
13950 end_index
, stride
, type
);
13951 if (value_tree
!= error_mark_node
)
13952 SET_EXPR_LOCATION (value_tree
, loc
);
13956 #include "gt-c-c-parser.h"