1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
43 #include "langhooks.h"
47 #include "c-family/c-pragma.h"
52 #include "c-family/c-common.h"
53 #include "c-family/c-objc.h"
61 /* Initialization routine for this file. */
66 /* The only initialization required is of the reserved word
72 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
73 the c_token structure. */
74 gcc_assert (RID_MAX
<= 255);
81 mask
|= D_ASM
| D_EXT
;
85 if (!c_dialect_objc ())
86 mask
|= D_OBJC
| D_CXX_OBJC
;
88 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
89 for (i
= 0; i
< num_c_common_reswords
; i
++)
91 /* If a keyword is disabled, do not enter it into the table
92 and so create a canonical spelling that isn't a keyword. */
93 if (c_common_reswords
[i
].disable
& mask
)
96 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
98 id
= get_identifier (c_common_reswords
[i
].word
);
99 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
100 C_IS_RESERVED_WORD (id
) = 1;
105 id
= get_identifier (c_common_reswords
[i
].word
);
106 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
107 C_IS_RESERVED_WORD (id
) = 1;
108 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
112 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
113 and the C parser. Unlike the C++ lexer, the parser structure
114 stores the lexer information instead of using a separate structure.
115 Identifiers are separated into ordinary identifiers, type names,
116 keywords and some other Objective-C types of identifiers, and some
117 look-ahead is maintained.
119 ??? It might be a good idea to lex the whole file up front (as for
120 C++). It would then be possible to share more of the C and C++
121 lexer code, if desired. */
123 /* The following local token type is used. */
126 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
128 /* More information about the type of a CPP_NAME token. */
129 typedef enum c_id_kind
{
130 /* An ordinary identifier. */
132 /* An identifier declared as a typedef name. */
134 /* An identifier declared as an Objective-C class name. */
136 /* An address space identifier. */
138 /* Not an identifier. */
142 /* A single C token after string literal concatenation and conversion
143 of preprocessing tokens to tokens. */
144 typedef struct GTY (()) c_token
{
145 /* The kind of token. */
146 ENUM_BITFIELD (cpp_ttype
) type
: 8;
147 /* If this token is a CPP_NAME, this value indicates whether also
148 declared as some kind of type. Otherwise, it is C_ID_NONE. */
149 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
150 /* If this token is a keyword, this value indicates which keyword.
151 Otherwise, this value is RID_MAX. */
152 ENUM_BITFIELD (rid
) keyword
: 8;
153 /* If this token is a CPP_PRAGMA, this indicates the pragma that
154 was seen. Otherwise it is PRAGMA_NONE. */
155 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
156 /* The location at which this token was found. */
158 /* The value associated with this token, if any. */
162 /* A parser structure recording information about the state and
163 context of parsing. Includes lexer information with up to two
164 tokens of look-ahead; more are not needed for C. */
165 typedef struct GTY(()) c_parser
{
166 /* The look-ahead tokens. */
167 c_token
* GTY((skip
)) tokens
;
168 /* Buffer for look-ahead tokens. */
169 c_token tokens_buf
[2];
170 /* How many look-ahead tokens are available (0, 1 or 2, or
171 more if parsing from pre-lexed tokens). */
172 unsigned int tokens_avail
;
173 /* True if a syntax error is being recovered from; false otherwise.
174 c_parser_error sets this flag. It should clear this flag when
175 enough tokens have been consumed to recover from the error. */
176 BOOL_BITFIELD error
: 1;
177 /* True if we're processing a pragma, and shouldn't automatically
178 consume CPP_PRAGMA_EOL. */
179 BOOL_BITFIELD in_pragma
: 1;
180 /* True if we're parsing the outermost block of an if statement. */
181 BOOL_BITFIELD in_if_block
: 1;
182 /* True if we want to lex an untranslated string. */
183 BOOL_BITFIELD lex_untranslated_string
: 1;
185 /* Objective-C specific parser/lexer information. */
187 /* True if we are in a context where the Objective-C "PQ" keywords
188 are considered keywords. */
189 BOOL_BITFIELD objc_pq_context
: 1;
190 /* True if we are parsing a (potential) Objective-C foreach
191 statement. This is set to true after we parsed 'for (' and while
192 we wait for 'in' or ';' to decide if it's a standard C for loop or an
193 Objective-C foreach loop. */
194 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
195 /* The following flag is needed to contextualize Objective-C lexical
196 analysis. In some cases (e.g., 'int NSObject;'), it is
197 undesirable to bind an identifier to an Objective-C class, even
198 if a class with that name exists. */
199 BOOL_BITFIELD objc_need_raw_identifier
: 1;
200 /* Nonzero if we're processing a __transaction statement. The value
201 is 1 | TM_STMT_ATTR_*. */
202 unsigned int in_transaction
: 4;
203 /* True if we are in a context where the Objective-C "Property attribute"
204 keywords are valid. */
205 BOOL_BITFIELD objc_property_attr_context
: 1;
209 /* The actual parser and external interface. ??? Does this need to be
210 garbage-collected? */
212 static GTY (()) c_parser
*the_parser
;
214 /* Read in and lex a single token, storing it in *TOKEN. */
217 c_lex_one_token (c_parser
*parser
, c_token
*token
)
219 timevar_push (TV_LEX
);
221 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
222 (parser
->lex_untranslated_string
223 ? C_LEX_STRING_NO_TRANSLATE
: 0));
224 token
->id_kind
= C_ID_NONE
;
225 token
->keyword
= RID_MAX
;
226 token
->pragma_kind
= PRAGMA_NONE
;
234 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
235 if (c_dialect_objc ())
236 parser
->objc_need_raw_identifier
= false;
238 if (C_IS_RESERVED_WORD (token
->value
))
240 enum rid rid_code
= C_RID_CODE (token
->value
);
242 if (rid_code
== RID_CXX_COMPAT_WARN
)
244 warning_at (token
->location
,
246 "identifier %qE conflicts with C++ keyword",
249 else if (rid_code
>= RID_FIRST_ADDR_SPACE
250 && rid_code
<= RID_LAST_ADDR_SPACE
)
252 token
->id_kind
= C_ID_ADDRSPACE
;
253 token
->keyword
= rid_code
;
256 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
258 /* We found an Objective-C "pq" keyword (in, out,
259 inout, bycopy, byref, oneway). They need special
260 care because the interpretation depends on the
262 if (parser
->objc_pq_context
)
264 token
->type
= CPP_KEYWORD
;
265 token
->keyword
= rid_code
;
268 else if (parser
->objc_could_be_foreach_context
269 && rid_code
== RID_IN
)
271 /* We are in Objective-C, inside a (potential)
272 foreach context (which means after having
273 parsed 'for (', but before having parsed ';'),
274 and we found 'in'. We consider it the keyword
275 which terminates the declaration at the
276 beginning of a foreach-statement. Note that
277 this means you can't use 'in' for anything else
278 in that context; in particular, in Objective-C
279 you can't use 'in' as the name of the running
280 variable in a C for loop. We could potentially
281 try to add code here to disambiguate, but it
282 seems a reasonable limitation. */
283 token
->type
= CPP_KEYWORD
;
284 token
->keyword
= rid_code
;
287 /* Else, "pq" keywords outside of the "pq" context are
288 not keywords, and we fall through to the code for
291 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
293 /* We found an Objective-C "property attribute"
294 keyword (getter, setter, readonly, etc). These are
295 only valid in the property context. */
296 if (parser
->objc_property_attr_context
)
298 token
->type
= CPP_KEYWORD
;
299 token
->keyword
= rid_code
;
302 /* Else they are not special keywords.
305 else if (c_dialect_objc ()
306 && (OBJC_IS_AT_KEYWORD (rid_code
)
307 || OBJC_IS_CXX_KEYWORD (rid_code
)))
309 /* We found one of the Objective-C "@" keywords (defs,
310 selector, synchronized, etc) or one of the
311 Objective-C "cxx" keywords (class, private,
312 protected, public, try, catch, throw) without a
313 preceding '@' sign. Do nothing and fall through to
314 the code for normal tokens (in C++ we would still
315 consider the CXX ones keywords, but not in C). */
320 token
->type
= CPP_KEYWORD
;
321 token
->keyword
= rid_code
;
326 decl
= lookup_name (token
->value
);
329 if (TREE_CODE (decl
) == TYPE_DECL
)
331 token
->id_kind
= C_ID_TYPENAME
;
335 else if (c_dialect_objc ())
337 tree objc_interface_decl
= objc_is_class_name (token
->value
);
338 /* Objective-C class names are in the same namespace as
339 variables and typedefs, and hence are shadowed by local
341 if (objc_interface_decl
342 && (!objc_force_identifier
|| global_bindings_p ()))
344 token
->value
= objc_interface_decl
;
345 token
->id_kind
= C_ID_CLASSNAME
;
349 token
->id_kind
= C_ID_ID
;
353 /* This only happens in Objective-C; it must be a keyword. */
354 token
->type
= CPP_KEYWORD
;
355 switch (C_RID_CODE (token
->value
))
357 /* Replace 'class' with '@class', 'private' with '@private',
358 etc. This prevents confusion with the C++ keyword
359 'class', and makes the tokens consistent with other
360 Objective-C 'AT' keywords. For example '@class' is
361 reported as RID_AT_CLASS which is consistent with
362 '@synchronized', which is reported as
365 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
366 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
367 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
368 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
369 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
370 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
371 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
372 default: token
->keyword
= C_RID_CODE (token
->value
);
377 case CPP_CLOSE_PAREN
:
379 /* These tokens may affect the interpretation of any identifiers
380 following, if doing Objective-C. */
381 if (c_dialect_objc ())
382 parser
->objc_need_raw_identifier
= false;
385 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
386 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
392 timevar_pop (TV_LEX
);
395 /* Return a pointer to the next token from PARSER, reading it in if
398 static inline c_token
*
399 c_parser_peek_token (c_parser
*parser
)
401 if (parser
->tokens_avail
== 0)
403 c_lex_one_token (parser
, &parser
->tokens
[0]);
404 parser
->tokens_avail
= 1;
406 return &parser
->tokens
[0];
409 /* Return true if the next token from PARSER has the indicated
413 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
415 return c_parser_peek_token (parser
)->type
== type
;
418 /* Return true if the next token from PARSER does not have the
422 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
424 return !c_parser_next_token_is (parser
, type
);
427 /* Return true if the next token from PARSER is the indicated
431 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
433 return c_parser_peek_token (parser
)->keyword
== keyword
;
436 /* Return a pointer to the next-but-one token from PARSER, reading it
437 in if necessary. The next token is already read in. */
440 c_parser_peek_2nd_token (c_parser
*parser
)
442 if (parser
->tokens_avail
>= 2)
443 return &parser
->tokens
[1];
444 gcc_assert (parser
->tokens_avail
== 1);
445 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
446 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
447 c_lex_one_token (parser
, &parser
->tokens
[1]);
448 parser
->tokens_avail
= 2;
449 return &parser
->tokens
[1];
452 /* Return true if TOKEN can start a type name,
455 c_token_starts_typename (c_token
*token
)
460 switch (token
->id_kind
)
469 gcc_assert (c_dialect_objc ());
475 switch (token
->keyword
)
510 if (c_dialect_objc ())
518 enum c_lookahead_kind
{
519 /* Always treat unknown identifiers as typenames. */
522 /* Could be parsing a nonabstract declarator. Only treat an identifier
523 as a typename if followed by another identifier or a star. */
524 cla_nonabstract_decl
,
526 /* Never treat identifiers as typenames. */
530 /* Return true if the next token from PARSER can start a type name,
531 false otherwise. LA specifies how to do lookahead in order to
532 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
535 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
537 c_token
*token
= c_parser_peek_token (parser
);
538 if (c_token_starts_typename (token
))
541 /* Try a bit harder to detect an unknown typename. */
542 if (la
!= cla_prefer_id
543 && token
->type
== CPP_NAME
544 && token
->id_kind
== C_ID_ID
546 /* Do not try too hard when we could have "object in array". */
547 && !parser
->objc_could_be_foreach_context
549 && (la
== cla_prefer_type
550 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
551 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
553 /* Only unknown identifiers. */
554 && !lookup_name (token
->value
))
560 /* Return true if TOKEN is a type qualifier, false otherwise. */
562 c_token_is_qualifier (c_token
*token
)
567 switch (token
->id_kind
)
575 switch (token
->keyword
)
593 /* Return true if the next token from PARSER is a type qualifier,
596 c_parser_next_token_is_qualifier (c_parser
*parser
)
598 c_token
*token
= c_parser_peek_token (parser
);
599 return c_token_is_qualifier (token
);
602 /* Return true if TOKEN can start declaration specifiers, false
605 c_token_starts_declspecs (c_token
*token
)
610 switch (token
->id_kind
)
619 gcc_assert (c_dialect_objc ());
625 switch (token
->keyword
)
669 if (c_dialect_objc ())
678 /* Return true if TOKEN can start declaration specifiers or a static
679 assertion, false otherwise. */
681 c_token_starts_declaration (c_token
*token
)
683 if (c_token_starts_declspecs (token
)
684 || token
->keyword
== RID_STATIC_ASSERT
)
690 /* Return true if the next token from PARSER can start declaration
691 specifiers, false otherwise. */
693 c_parser_next_token_starts_declspecs (c_parser
*parser
)
695 c_token
*token
= c_parser_peek_token (parser
);
697 /* In Objective-C, a classname normally starts a declspecs unless it
698 is immediately followed by a dot. In that case, it is the
699 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
700 setter/getter on the class. c_token_starts_declspecs() can't
701 differentiate between the two cases because it only checks the
702 current token, so we have a special check here. */
703 if (c_dialect_objc ()
704 && token
->type
== CPP_NAME
705 && token
->id_kind
== C_ID_CLASSNAME
706 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
709 return c_token_starts_declspecs (token
);
712 /* Return true if the next tokens from PARSER can start declaration
713 specifiers or a static assertion, false otherwise. */
715 c_parser_next_tokens_start_declaration (c_parser
*parser
)
717 c_token
*token
= c_parser_peek_token (parser
);
720 if (c_dialect_objc ()
721 && token
->type
== CPP_NAME
722 && token
->id_kind
== C_ID_CLASSNAME
723 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
726 /* Labels do not start declarations. */
727 if (token
->type
== CPP_NAME
728 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
731 if (c_token_starts_declaration (token
))
734 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
740 /* Consume the next token from PARSER. */
743 c_parser_consume_token (c_parser
*parser
)
745 gcc_assert (parser
->tokens_avail
>= 1);
746 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
747 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
748 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
749 if (parser
->tokens
!= &parser
->tokens_buf
[0])
751 else if (parser
->tokens_avail
== 2)
752 parser
->tokens
[0] = parser
->tokens
[1];
753 parser
->tokens_avail
--;
756 /* Expect the current token to be a #pragma. Consume it and remember
757 that we've begun parsing a pragma. */
760 c_parser_consume_pragma (c_parser
*parser
)
762 gcc_assert (!parser
->in_pragma
);
763 gcc_assert (parser
->tokens_avail
>= 1);
764 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
765 if (parser
->tokens
!= &parser
->tokens_buf
[0])
767 else if (parser
->tokens_avail
== 2)
768 parser
->tokens
[0] = parser
->tokens
[1];
769 parser
->tokens_avail
--;
770 parser
->in_pragma
= true;
773 /* Update the globals input_location and in_system_header from
776 c_parser_set_source_position_from_token (c_token
*token
)
778 if (token
->type
!= CPP_EOF
)
780 input_location
= token
->location
;
784 /* Issue a diagnostic of the form
785 FILE:LINE: MESSAGE before TOKEN
786 where TOKEN is the next token in the input stream of PARSER.
787 MESSAGE (specified by the caller) is usually of the form "expected
790 Do not issue a diagnostic if still recovering from an error.
792 ??? This is taken from the C++ parser, but building up messages in
793 this way is not i18n-friendly and some other approach should be
797 c_parser_error (c_parser
*parser
, const char *gmsgid
)
799 c_token
*token
= c_parser_peek_token (parser
);
802 parser
->error
= true;
805 /* This diagnostic makes more sense if it is tagged to the line of
806 the token we just peeked at. */
807 c_parser_set_source_position_from_token (token
);
808 c_parse_error (gmsgid
,
809 /* Because c_parse_error does not understand
810 CPP_KEYWORD, keywords are treated like
812 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
813 /* ??? The C parser does not save the cpp flags of a
814 token, we need to pass 0 here and we will not get
815 the source spelling of some tokens but rather the
816 canonical spelling. */
817 token
->value
, /*flags=*/0);
820 /* If the next token is of the indicated TYPE, consume it. Otherwise,
821 issue the error MSGID. If MSGID is NULL then a message has already
822 been produced and no message will be produced this time. Returns
823 true if found, false otherwise. */
826 c_parser_require (c_parser
*parser
,
830 if (c_parser_next_token_is (parser
, type
))
832 c_parser_consume_token (parser
);
837 c_parser_error (parser
, msgid
);
842 /* If the next token is the indicated keyword, consume it. Otherwise,
843 issue the error MSGID. Returns true if found, false otherwise. */
846 c_parser_require_keyword (c_parser
*parser
,
850 if (c_parser_next_token_is_keyword (parser
, keyword
))
852 c_parser_consume_token (parser
);
857 c_parser_error (parser
, msgid
);
862 /* Like c_parser_require, except that tokens will be skipped until the
863 desired token is found. An error message is still produced if the
864 next token is not as expected. If MSGID is NULL then a message has
865 already been produced and no message will be produced this
869 c_parser_skip_until_found (c_parser
*parser
,
873 unsigned nesting_depth
= 0;
875 if (c_parser_require (parser
, type
, msgid
))
878 /* Skip tokens until the desired token is found. */
881 /* Peek at the next token. */
882 c_token
*token
= c_parser_peek_token (parser
);
883 /* If we've reached the token we want, consume it and stop. */
884 if (token
->type
== type
&& !nesting_depth
)
886 c_parser_consume_token (parser
);
890 /* If we've run out of tokens, stop. */
891 if (token
->type
== CPP_EOF
)
893 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
895 if (token
->type
== CPP_OPEN_BRACE
896 || token
->type
== CPP_OPEN_PAREN
897 || token
->type
== CPP_OPEN_SQUARE
)
899 else if (token
->type
== CPP_CLOSE_BRACE
900 || token
->type
== CPP_CLOSE_PAREN
901 || token
->type
== CPP_CLOSE_SQUARE
)
903 if (nesting_depth
-- == 0)
906 /* Consume this token. */
907 c_parser_consume_token (parser
);
909 parser
->error
= false;
912 /* Skip tokens until the end of a parameter is found, but do not
913 consume the comma, semicolon or closing delimiter. */
916 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
918 unsigned nesting_depth
= 0;
922 c_token
*token
= c_parser_peek_token (parser
);
923 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
926 /* If we've run out of tokens, stop. */
927 if (token
->type
== CPP_EOF
)
929 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
931 if (token
->type
== CPP_OPEN_BRACE
932 || token
->type
== CPP_OPEN_PAREN
933 || token
->type
== CPP_OPEN_SQUARE
)
935 else if (token
->type
== CPP_CLOSE_BRACE
936 || token
->type
== CPP_CLOSE_PAREN
937 || token
->type
== CPP_CLOSE_SQUARE
)
939 if (nesting_depth
-- == 0)
942 /* Consume this token. */
943 c_parser_consume_token (parser
);
945 parser
->error
= false;
948 /* Expect to be at the end of the pragma directive and consume an
949 end of line marker. */
952 c_parser_skip_to_pragma_eol (c_parser
*parser
)
954 gcc_assert (parser
->in_pragma
);
955 parser
->in_pragma
= false;
957 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
960 c_token
*token
= c_parser_peek_token (parser
);
961 if (token
->type
== CPP_EOF
)
963 if (token
->type
== CPP_PRAGMA_EOL
)
965 c_parser_consume_token (parser
);
968 c_parser_consume_token (parser
);
971 parser
->error
= false;
974 /* Skip tokens until we have consumed an entire block, or until we
975 have consumed a non-nested ';'. */
978 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
980 unsigned nesting_depth
= 0;
981 bool save_error
= parser
->error
;
987 /* Peek at the next token. */
988 token
= c_parser_peek_token (parser
);
996 if (parser
->in_pragma
)
1001 /* If the next token is a ';', we have reached the
1002 end of the statement. */
1005 /* Consume the ';'. */
1006 c_parser_consume_token (parser
);
1011 case CPP_CLOSE_BRACE
:
1012 /* If the next token is a non-nested '}', then we have
1013 reached the end of the current block. */
1014 if (nesting_depth
== 0 || --nesting_depth
== 0)
1016 c_parser_consume_token (parser
);
1021 case CPP_OPEN_BRACE
:
1022 /* If it the next token is a '{', then we are entering a new
1023 block. Consume the entire block. */
1028 /* If we see a pragma, consume the whole thing at once. We
1029 have some safeguards against consuming pragmas willy-nilly.
1030 Normally, we'd expect to be here with parser->error set,
1031 which disables these safeguards. But it's possible to get
1032 here for secondary error recovery, after parser->error has
1034 c_parser_consume_pragma (parser
);
1035 c_parser_skip_to_pragma_eol (parser
);
1036 parser
->error
= save_error
;
1043 c_parser_consume_token (parser
);
1047 parser
->error
= false;
1050 /* CPP's options (initialized by c-opts.c). */
1051 extern cpp_options
*cpp_opts
;
1053 /* Save the warning flags which are controlled by __extension__. */
1056 disable_extension_diagnostics (void)
1059 | (warn_pointer_arith
<< 1)
1060 | (warn_traditional
<< 2)
1062 | (warn_long_long
<< 4)
1063 | (warn_cxx_compat
<< 5)
1064 | (warn_overlength_strings
<< 6));
1065 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1066 warn_pointer_arith
= 0;
1067 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1069 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1070 warn_cxx_compat
= 0;
1071 warn_overlength_strings
= 0;
1075 /* Restore the warning flags which are controlled by __extension__.
1076 FLAGS is the return value from disable_extension_diagnostics. */
1079 restore_extension_diagnostics (int flags
)
1081 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1082 warn_pointer_arith
= (flags
>> 1) & 1;
1083 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1084 flag_iso
= (flags
>> 3) & 1;
1085 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1086 warn_cxx_compat
= (flags
>> 5) & 1;
1087 warn_overlength_strings
= (flags
>> 6) & 1;
1090 /* Possibly kinds of declarator to parse. */
1091 typedef enum c_dtr_syn
{
1092 /* A normal declarator with an identifier. */
1094 /* An abstract declarator (maybe empty). */
1096 /* A parameter declarator: may be either, but after a type name does
1097 not redeclare a typedef name as an identifier if it can
1098 alternatively be interpreted as a typedef name; see DR#009,
1099 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1100 following DR#249. For example, given a typedef T, "int T" and
1101 "int *T" are valid parameter declarations redeclaring T, while
1102 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1103 abstract declarators rather than involving redundant parentheses;
1104 the same applies with attributes inside the parentheses before
1109 /* The binary operation precedence levels, where 0 is a dummy lowest level
1110 used for the bottom of the stack. */
1111 enum c_parser_prec
{
1126 static void c_parser_external_declaration (c_parser
*);
1127 static void c_parser_asm_definition (c_parser
*);
1128 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1129 bool, bool, tree
*, vec
<c_token
>);
1130 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1131 static void c_parser_static_assert_declaration (c_parser
*);
1132 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1133 bool, bool, bool, enum c_lookahead_kind
);
1134 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1135 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1136 static tree
c_parser_struct_declaration (c_parser
*);
1137 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1138 static tree
c_parser_alignas_specifier (c_parser
*);
1139 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1141 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1143 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1145 struct c_declarator
*);
1146 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1147 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1149 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1150 static tree
c_parser_simple_asm_expr (c_parser
*);
1151 static tree
c_parser_attributes (c_parser
*);
1152 static struct c_type_name
*c_parser_type_name (c_parser
*);
1153 static struct c_expr
c_parser_initializer (c_parser
*);
1154 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1155 static void c_parser_initelt (c_parser
*, struct obstack
*);
1156 static void c_parser_initval (c_parser
*, struct c_expr
*,
1158 static tree
c_parser_compound_statement (c_parser
*);
1159 static void c_parser_compound_statement_nostart (c_parser
*);
1160 static void c_parser_label (c_parser
*);
1161 static void c_parser_statement (c_parser
*);
1162 static void c_parser_statement_after_labels (c_parser
*);
1163 static void c_parser_if_statement (c_parser
*);
1164 static void c_parser_switch_statement (c_parser
*);
1165 static void c_parser_while_statement (c_parser
*, bool);
1166 static void c_parser_do_statement (c_parser
*, bool);
1167 static void c_parser_for_statement (c_parser
*, bool);
1168 static tree
c_parser_asm_statement (c_parser
*);
1169 static tree
c_parser_asm_operands (c_parser
*);
1170 static tree
c_parser_asm_goto_operands (c_parser
*);
1171 static tree
c_parser_asm_clobbers (c_parser
*);
1172 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1174 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1175 struct c_expr
*, tree
);
1176 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1178 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1179 static struct c_expr
c_parser_unary_expression (c_parser
*);
1180 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1181 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1182 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1183 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1184 struct c_type_name
*,
1186 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1189 static tree
c_parser_transaction (c_parser
*, enum rid
);
1190 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1191 static tree
c_parser_transaction_cancel (c_parser
*);
1192 static struct c_expr
c_parser_expression (c_parser
*);
1193 static struct c_expr
c_parser_expression_conv (c_parser
*);
1194 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1195 vec
<tree
, va_gc
> **, location_t
*,
1197 static void c_parser_omp_construct (c_parser
*);
1198 static void c_parser_omp_threadprivate (c_parser
*);
1199 static void c_parser_omp_barrier (c_parser
*);
1200 static void c_parser_omp_flush (c_parser
*);
1201 static void c_parser_omp_taskwait (c_parser
*);
1202 static void c_parser_omp_taskyield (c_parser
*);
1203 static void c_parser_omp_cancel (c_parser
*);
1204 static void c_parser_omp_cancellation_point (c_parser
*);
1206 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1207 pragma_stmt
, pragma_compound
};
1208 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1209 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1210 static void c_parser_omp_end_declare_target (c_parser
*);
1211 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1213 /* These Objective-C parser functions are only ever called when
1214 compiling Objective-C. */
1215 static void c_parser_objc_class_definition (c_parser
*, tree
);
1216 static void c_parser_objc_class_instance_variables (c_parser
*);
1217 static void c_parser_objc_class_declaration (c_parser
*);
1218 static void c_parser_objc_alias_declaration (c_parser
*);
1219 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1220 static bool c_parser_objc_method_type (c_parser
*);
1221 static void c_parser_objc_method_definition (c_parser
*);
1222 static void c_parser_objc_methodprotolist (c_parser
*);
1223 static void c_parser_objc_methodproto (c_parser
*);
1224 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1225 static tree
c_parser_objc_type_name (c_parser
*);
1226 static tree
c_parser_objc_protocol_refs (c_parser
*);
1227 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1228 static void c_parser_objc_synchronized_statement (c_parser
*);
1229 static tree
c_parser_objc_selector (c_parser
*);
1230 static tree
c_parser_objc_selector_arg (c_parser
*);
1231 static tree
c_parser_objc_receiver (c_parser
*);
1232 static tree
c_parser_objc_message_args (c_parser
*);
1233 static tree
c_parser_objc_keywordexpr (c_parser
*);
1234 static void c_parser_objc_at_property_declaration (c_parser
*);
1235 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1236 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1237 static bool c_parser_objc_diagnose_bad_element_prefix
1238 (c_parser
*, struct c_declspecs
*);
1240 /* Cilk Plus supporting routines. */
1241 static void c_parser_cilk_simd (c_parser
*);
1242 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1243 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1245 /* Parse a translation unit (C90 6.7, C99 6.9).
1248 external-declarations
1250 external-declarations:
1251 external-declaration
1252 external-declarations external-declaration
1261 c_parser_translation_unit (c_parser
*parser
)
1263 if (c_parser_next_token_is (parser
, CPP_EOF
))
1265 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1266 "ISO C forbids an empty translation unit");
1270 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1271 mark_valid_location_for_stdc_pragma (false);
1275 c_parser_external_declaration (parser
);
1276 obstack_free (&parser_obstack
, obstack_position
);
1278 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1282 /* Parse an external declaration (C90 6.7, C99 6.9).
1284 external-declaration:
1290 external-declaration:
1293 __extension__ external-declaration
1297 external-declaration:
1298 objc-class-definition
1299 objc-class-declaration
1300 objc-alias-declaration
1301 objc-protocol-definition
1302 objc-method-definition
1307 c_parser_external_declaration (c_parser
*parser
)
1310 switch (c_parser_peek_token (parser
)->type
)
1313 switch (c_parser_peek_token (parser
)->keyword
)
1316 ext
= disable_extension_diagnostics ();
1317 c_parser_consume_token (parser
);
1318 c_parser_external_declaration (parser
);
1319 restore_extension_diagnostics (ext
);
1322 c_parser_asm_definition (parser
);
1324 case RID_AT_INTERFACE
:
1325 case RID_AT_IMPLEMENTATION
:
1326 gcc_assert (c_dialect_objc ());
1327 c_parser_objc_class_definition (parser
, NULL_TREE
);
1330 gcc_assert (c_dialect_objc ());
1331 c_parser_objc_class_declaration (parser
);
1334 gcc_assert (c_dialect_objc ());
1335 c_parser_objc_alias_declaration (parser
);
1337 case RID_AT_PROTOCOL
:
1338 gcc_assert (c_dialect_objc ());
1339 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1341 case RID_AT_PROPERTY
:
1342 gcc_assert (c_dialect_objc ());
1343 c_parser_objc_at_property_declaration (parser
);
1345 case RID_AT_SYNTHESIZE
:
1346 gcc_assert (c_dialect_objc ());
1347 c_parser_objc_at_synthesize_declaration (parser
);
1349 case RID_AT_DYNAMIC
:
1350 gcc_assert (c_dialect_objc ());
1351 c_parser_objc_at_dynamic_declaration (parser
);
1354 gcc_assert (c_dialect_objc ());
1355 c_parser_consume_token (parser
);
1356 objc_finish_implementation ();
1363 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1364 "ISO C does not allow extra %<;%> outside of a function");
1365 c_parser_consume_token (parser
);
1368 mark_valid_location_for_stdc_pragma (true);
1369 c_parser_pragma (parser
, pragma_external
);
1370 mark_valid_location_for_stdc_pragma (false);
1374 if (c_dialect_objc ())
1376 c_parser_objc_method_definition (parser
);
1379 /* Else fall through, and yield a syntax error trying to parse
1380 as a declaration or function definition. */
1383 /* A declaration or a function definition (or, in Objective-C,
1384 an @interface or @protocol with prefix attributes). We can
1385 only tell which after parsing the declaration specifiers, if
1386 any, and the first declarator. */
1387 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1393 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1395 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1396 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1397 accepted; otherwise (old-style parameter declarations) only other
1398 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1399 assertion is accepted; otherwise (old-style parameter declarations)
1400 it is not. If NESTED is true, we are inside a function or parsing
1401 old-style parameter declarations; any functions encountered are
1402 nested functions and declaration specifiers are required; otherwise
1403 we are at top level and functions are normal functions and
1404 declaration specifiers may be optional. If EMPTY_OK is true, empty
1405 declarations are OK (subject to all other constraints); otherwise
1406 (old-style parameter declarations) they are diagnosed. If
1407 START_ATTR_OK is true, the declaration specifiers may start with
1408 attributes; otherwise they may not.
1409 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1410 declaration when parsing an Objective-C foreach statement.
1413 declaration-specifiers init-declarator-list[opt] ;
1414 static_assert-declaration
1416 function-definition:
1417 declaration-specifiers[opt] declarator declaration-list[opt]
1422 declaration-list declaration
1424 init-declarator-list:
1426 init-declarator-list , init-declarator
1429 declarator simple-asm-expr[opt] attributes[opt]
1430 declarator simple-asm-expr[opt] attributes[opt] = initializer
1434 nested-function-definition:
1435 declaration-specifiers declarator declaration-list[opt]
1439 attributes objc-class-definition
1440 attributes objc-category-definition
1441 attributes objc-protocol-definition
1443 The simple-asm-expr and attributes are GNU extensions.
1445 This function does not handle __extension__; that is handled in its
1446 callers. ??? Following the old parser, __extension__ may start
1447 external declarations, declarations in functions and declarations
1448 at the start of "for" loops, but not old-style parameter
1451 C99 requires declaration specifiers in a function definition; the
1452 absence is diagnosed through the diagnosis of implicit int. In GNU
1453 C we also allow but diagnose declarations without declaration
1454 specifiers, but only at top level (elsewhere they conflict with
1457 In Objective-C, declarations of the looping variable in a foreach
1458 statement are exceptionally terminated by 'in' (for example, 'for
1459 (NSObject *object in array) { ... }').
1464 threadprivate-directive */
1467 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1468 bool static_assert_ok
, bool empty_ok
,
1469 bool nested
, bool start_attr_ok
,
1470 tree
*objc_foreach_object_declaration
,
1471 vec
<c_token
> omp_declare_simd_clauses
)
1473 struct c_declspecs
*specs
;
1475 tree all_prefix_attrs
;
1476 bool diagnosed_no_specs
= false;
1477 location_t here
= c_parser_peek_token (parser
)->location
;
1479 if (static_assert_ok
1480 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1482 c_parser_static_assert_declaration (parser
);
1485 specs
= build_null_declspecs ();
1487 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1488 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1489 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1490 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1491 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1492 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1494 error_at (here
, "unknown type name %qE",
1495 c_parser_peek_token (parser
)->value
);
1497 /* Parse declspecs normally to get a correct pointer type, but avoid
1498 a further "fails to be a type name" error. Refuse nested functions
1499 since it is not how the user likely wants us to recover. */
1500 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1501 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1502 c_parser_peek_token (parser
)->value
= error_mark_node
;
1506 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1507 true, true, cla_nonabstract_decl
);
1510 c_parser_skip_to_end_of_block_or_statement (parser
);
1513 if (nested
&& !specs
->declspecs_seen_p
)
1515 c_parser_error (parser
, "expected declaration specifiers");
1516 c_parser_skip_to_end_of_block_or_statement (parser
);
1519 finish_declspecs (specs
);
1520 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1521 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1524 error_at (here
, "%<__auto_type%> in empty declaration");
1529 shadow_tag_warned (specs
, 1);
1530 pedwarn (here
, 0, "empty declaration");
1532 c_parser_consume_token (parser
);
1536 /* Provide better error recovery. Note that a type name here is usually
1537 better diagnosed as a redeclaration. */
1539 && specs
->typespec_kind
== ctsk_tagdef
1540 && c_parser_next_token_starts_declspecs (parser
)
1541 && !c_parser_next_token_is (parser
, CPP_NAME
))
1543 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1544 parser
->error
= false;
1545 shadow_tag_warned (specs
, 1);
1548 else if (c_dialect_objc () && !auto_type_p
)
1550 /* Prefix attributes are an error on method decls. */
1551 switch (c_parser_peek_token (parser
)->type
)
1555 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1559 warning_at (c_parser_peek_token (parser
)->location
,
1561 "prefix attributes are ignored for methods");
1562 specs
->attrs
= NULL_TREE
;
1565 c_parser_objc_method_definition (parser
);
1567 c_parser_objc_methodproto (parser
);
1573 /* This is where we parse 'attributes @interface ...',
1574 'attributes @implementation ...', 'attributes @protocol ...'
1575 (where attributes could be, for example, __attribute__
1578 switch (c_parser_peek_token (parser
)->keyword
)
1580 case RID_AT_INTERFACE
:
1582 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1584 c_parser_objc_class_definition (parser
, specs
->attrs
);
1588 case RID_AT_IMPLEMENTATION
:
1590 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1594 warning_at (c_parser_peek_token (parser
)->location
,
1596 "prefix attributes are ignored for implementations");
1597 specs
->attrs
= NULL_TREE
;
1599 c_parser_objc_class_definition (parser
, NULL_TREE
);
1603 case RID_AT_PROTOCOL
:
1605 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1607 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1614 case RID_AT_PROPERTY
:
1617 c_parser_error (parser
, "unexpected attribute");
1618 specs
->attrs
= NULL
;
1626 pending_xref_error ();
1627 prefix_attrs
= specs
->attrs
;
1628 all_prefix_attrs
= prefix_attrs
;
1629 specs
->attrs
= NULL_TREE
;
1632 struct c_declarator
*declarator
;
1636 /* Declaring either one or more declarators (in which case we
1637 should diagnose if there were no declaration specifiers) or a
1638 function definition (in which case the diagnostic for
1639 implicit int suffices). */
1640 declarator
= c_parser_declarator (parser
,
1641 specs
->typespec_kind
!= ctsk_none
,
1642 C_DTR_NORMAL
, &dummy
);
1643 if (declarator
== NULL
)
1645 if (omp_declare_simd_clauses
.exists ())
1646 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1647 omp_declare_simd_clauses
);
1648 c_parser_skip_to_end_of_block_or_statement (parser
);
1651 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1654 "%<__auto_type%> requires a plain identifier"
1656 c_parser_skip_to_end_of_block_or_statement (parser
);
1659 if (c_parser_next_token_is (parser
, CPP_EQ
)
1660 || c_parser_next_token_is (parser
, CPP_COMMA
)
1661 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1662 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1663 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1664 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1666 tree asm_name
= NULL_TREE
;
1667 tree postfix_attrs
= NULL_TREE
;
1668 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1670 diagnosed_no_specs
= true;
1671 pedwarn (here
, 0, "data definition has no type or storage class");
1673 /* Having seen a data definition, there cannot now be a
1674 function definition. */
1676 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1677 asm_name
= c_parser_simple_asm_expr (parser
);
1678 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1679 postfix_attrs
= c_parser_attributes (parser
);
1680 if (c_parser_next_token_is (parser
, CPP_EQ
))
1684 location_t init_loc
;
1685 c_parser_consume_token (parser
);
1688 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1689 init_loc
= c_parser_peek_token (parser
)->location
;
1690 init
= c_parser_expr_no_commas (parser
, NULL
);
1691 if (TREE_CODE (init
.value
) == COMPONENT_REF
1692 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1694 "%<__auto_type%> used with a bit-field"
1696 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1697 tree init_type
= TREE_TYPE (init
.value
);
1698 /* As with typeof, remove _Atomic and const
1699 qualifiers from atomic types. */
1700 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1702 = c_build_qualified_type (init_type
,
1703 (TYPE_QUALS (init_type
)
1704 & ~(TYPE_QUAL_ATOMIC
1705 | TYPE_QUAL_CONST
)));
1706 bool vm_type
= variably_modified_type_p (init_type
,
1709 init
.value
= c_save_expr (init
.value
);
1711 specs
->typespec_kind
= ctsk_typeof
;
1712 specs
->locations
[cdw_typedef
] = init_loc
;
1713 specs
->typedef_p
= true;
1714 specs
->type
= init_type
;
1717 bool maybe_const
= true;
1718 tree type_expr
= c_fully_fold (init
.value
, false,
1720 specs
->expr_const_operands
&= maybe_const
;
1722 specs
->expr
= build2 (COMPOUND_EXPR
,
1723 TREE_TYPE (type_expr
),
1724 specs
->expr
, type_expr
);
1726 specs
->expr
= type_expr
;
1728 d
= start_decl (declarator
, specs
, true,
1729 chainon (postfix_attrs
, all_prefix_attrs
));
1731 d
= error_mark_node
;
1732 if (omp_declare_simd_clauses
.exists ())
1733 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1734 omp_declare_simd_clauses
);
1738 /* The declaration of the variable is in effect while
1739 its initializer is parsed. */
1740 d
= start_decl (declarator
, specs
, true,
1741 chainon (postfix_attrs
, all_prefix_attrs
));
1743 d
= error_mark_node
;
1744 if (omp_declare_simd_clauses
.exists ())
1745 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1746 omp_declare_simd_clauses
);
1747 start_init (d
, asm_name
, global_bindings_p ());
1748 init_loc
= c_parser_peek_token (parser
)->location
;
1749 init
= c_parser_initializer (parser
);
1752 if (d
!= error_mark_node
)
1754 maybe_warn_string_init (TREE_TYPE (d
), init
);
1755 finish_decl (d
, init_loc
, init
.value
,
1756 init
.original_type
, asm_name
);
1764 "%<__auto_type%> requires an initialized "
1765 "data declaration");
1766 c_parser_skip_to_end_of_block_or_statement (parser
);
1769 tree d
= start_decl (declarator
, specs
, false,
1770 chainon (postfix_attrs
,
1772 if (omp_declare_simd_clauses
.exists ())
1774 tree parms
= NULL_TREE
;
1775 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1777 struct c_declarator
*ce
= declarator
;
1779 if (ce
->kind
== cdk_function
)
1781 parms
= ce
->u
.arg_info
->parms
;
1785 ce
= ce
->declarator
;
1788 temp_store_parm_decls (d
, parms
);
1789 c_finish_omp_declare_simd (parser
, d
, parms
,
1790 omp_declare_simd_clauses
);
1792 temp_pop_parm_decls ();
1795 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1796 NULL_TREE
, asm_name
);
1798 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1801 *objc_foreach_object_declaration
= d
;
1803 *objc_foreach_object_declaration
= error_mark_node
;
1806 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1811 "%<__auto_type%> may only be used with"
1812 " a single declarator");
1813 c_parser_skip_to_end_of_block_or_statement (parser
);
1816 c_parser_consume_token (parser
);
1817 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1818 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1821 all_prefix_attrs
= prefix_attrs
;
1824 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1826 c_parser_consume_token (parser
);
1829 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1831 /* This can only happen in Objective-C: we found the
1832 'in' that terminates the declaration inside an
1833 Objective-C foreach statement. Do not consume the
1834 token, so that the caller can use it to determine
1835 that this indeed is a foreach context. */
1840 c_parser_error (parser
, "expected %<,%> or %<;%>");
1841 c_parser_skip_to_end_of_block_or_statement (parser
);
1845 else if (auto_type_p
)
1848 "%<__auto_type%> requires an initialized data declaration");
1849 c_parser_skip_to_end_of_block_or_statement (parser
);
1854 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1855 "%<asm%> or %<__attribute__%>");
1856 c_parser_skip_to_end_of_block_or_statement (parser
);
1859 /* Function definition (nested or otherwise). */
1862 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1863 c_push_function_context ();
1865 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1867 /* This can appear in many cases looking nothing like a
1868 function definition, so we don't give a more specific
1869 error suggesting there was one. */
1870 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1871 "or %<__attribute__%>");
1873 c_pop_function_context ();
1877 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1878 tv
= TV_PARSE_INLINE
;
1883 /* Parse old-style parameter declarations. ??? Attributes are
1884 not allowed to start declaration specifiers here because of a
1885 syntax conflict between a function declaration with attribute
1886 suffix and a function definition with an attribute prefix on
1887 first old-style parameter declaration. Following the old
1888 parser, they are not accepted on subsequent old-style
1889 parameter declarations either. However, there is no
1890 ambiguity after the first declaration, nor indeed on the
1891 first as long as we don't allow postfix attributes after a
1892 declarator with a nonempty identifier list in a definition;
1893 and postfix attributes have never been accepted here in
1894 function definitions either. */
1895 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1896 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1897 c_parser_declaration_or_fndef (parser
, false, false, false,
1898 true, false, NULL
, vNULL
);
1899 store_parm_decls ();
1900 if (omp_declare_simd_clauses
.exists ())
1901 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1902 omp_declare_simd_clauses
);
1903 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1904 = c_parser_peek_token (parser
)->location
;
1905 fnbody
= c_parser_compound_statement (parser
);
1906 if (flag_enable_cilkplus
&& contains_array_notation_expr (fnbody
))
1907 fnbody
= expand_array_notation_exprs (fnbody
);
1910 tree decl
= current_function_decl
;
1911 /* Mark nested functions as needing static-chain initially.
1912 lower_nested_functions will recompute it but the
1913 DECL_STATIC_CHAIN flag is also used before that happens,
1914 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1915 DECL_STATIC_CHAIN (decl
) = 1;
1918 c_pop_function_context ();
1919 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1932 /* Parse an asm-definition (asm() outside a function body). This is a
1940 c_parser_asm_definition (c_parser
*parser
)
1942 tree asm_str
= c_parser_simple_asm_expr (parser
);
1944 add_asm_node (asm_str
);
1945 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1948 /* Parse a static assertion (C11 6.7.10).
1950 static_assert-declaration:
1951 static_assert-declaration-no-semi ;
1955 c_parser_static_assert_declaration (c_parser
*parser
)
1957 c_parser_static_assert_declaration_no_semi (parser
);
1959 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1960 c_parser_skip_to_end_of_block_or_statement (parser
);
1963 /* Parse a static assertion (C11 6.7.10), without the trailing
1966 static_assert-declaration-no-semi:
1967 _Static_assert ( constant-expression , string-literal )
1971 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1973 location_t assert_loc
, value_loc
;
1977 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1978 assert_loc
= c_parser_peek_token (parser
)->location
;
1982 pedwarn (assert_loc
, OPT_Wpedantic
,
1983 "ISO C99 does not support %<_Static_assert%>");
1985 pedwarn (assert_loc
, OPT_Wpedantic
,
1986 "ISO C90 does not support %<_Static_assert%>");
1988 c_parser_consume_token (parser
);
1989 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1991 value_loc
= c_parser_peek_token (parser
)->location
;
1992 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1993 parser
->lex_untranslated_string
= true;
1994 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1996 parser
->lex_untranslated_string
= false;
1999 switch (c_parser_peek_token (parser
)->type
)
2005 case CPP_UTF8STRING
:
2006 string
= c_parser_peek_token (parser
)->value
;
2007 c_parser_consume_token (parser
);
2008 parser
->lex_untranslated_string
= false;
2011 c_parser_error (parser
, "expected string literal");
2012 parser
->lex_untranslated_string
= false;
2015 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2017 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2019 error_at (value_loc
, "expression in static assertion is not an integer");
2022 if (TREE_CODE (value
) != INTEGER_CST
)
2024 value
= c_fully_fold (value
, false, NULL
);
2025 if (TREE_CODE (value
) == INTEGER_CST
)
2026 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2027 "is not an integer constant expression");
2029 if (TREE_CODE (value
) != INTEGER_CST
)
2031 error_at (value_loc
, "expression in static assertion is not constant");
2034 constant_expression_warning (value
);
2035 if (integer_zerop (value
))
2036 error_at (assert_loc
, "static assertion failed: %E", string
);
2039 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2040 6.7), adding them to SPECS (which may already include some).
2041 Storage class specifiers are accepted iff SCSPEC_OK; type
2042 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2043 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2044 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2046 declaration-specifiers:
2047 storage-class-specifier declaration-specifiers[opt]
2048 type-specifier declaration-specifiers[opt]
2049 type-qualifier declaration-specifiers[opt]
2050 function-specifier declaration-specifiers[opt]
2051 alignment-specifier declaration-specifiers[opt]
2053 Function specifiers (inline) are from C99, and are currently
2054 handled as storage class specifiers, as is __thread. Alignment
2055 specifiers are from C11.
2057 C90 6.5.1, C99 6.7.1:
2058 storage-class-specifier:
2066 (_Thread_local is new in C11.)
2073 (_Noreturn is new in C11.)
2075 C90 6.5.2, C99 6.7.2:
2088 [_Imaginary removed in C99 TC2]
2089 struct-or-union-specifier
2092 atomic-type-specifier
2094 (_Bool and _Complex are new in C99.)
2095 (atomic-type-specifier is new in C11.)
2097 C90 6.5.3, C99 6.7.3:
2103 address-space-qualifier
2106 (restrict is new in C99.)
2107 (_Atomic is new in C11.)
2111 declaration-specifiers:
2112 attributes declaration-specifiers[opt]
2118 identifier recognized by the target
2120 storage-class-specifier:
2134 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2135 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2137 atomic-type-specifier
2138 _Atomic ( type-name )
2143 class-name objc-protocol-refs[opt]
2144 typedef-name objc-protocol-refs
2149 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2150 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2151 bool alignspec_ok
, bool auto_type_ok
,
2152 enum c_lookahead_kind la
)
2154 bool attrs_ok
= start_attr_ok
;
2155 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2158 gcc_assert (la
== cla_prefer_id
);
2160 while (c_parser_next_token_is (parser
, CPP_NAME
)
2161 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2162 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2164 struct c_typespec t
;
2167 location_t loc
= c_parser_peek_token (parser
)->location
;
2169 /* If we cannot accept a type, exit if the next token must start
2170 one. Also, if we already have seen a tagged definition,
2171 a typename would be an error anyway and likely the user
2172 has simply forgotten a semicolon, so we exit. */
2173 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2174 && c_parser_next_tokens_start_typename (parser
, la
)
2175 && !c_parser_next_token_is_qualifier (parser
))
2178 if (c_parser_next_token_is (parser
, CPP_NAME
))
2180 c_token
*name_token
= c_parser_peek_token (parser
);
2181 tree value
= name_token
->value
;
2182 c_id_kind kind
= name_token
->id_kind
;
2184 if (kind
== C_ID_ADDRSPACE
)
2187 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2188 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2189 c_parser_consume_token (parser
);
2194 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2196 /* If we cannot accept a type, and the next token must start one,
2197 exit. Do the same if we already have seen a tagged definition,
2198 since it would be an error anyway and likely the user has simply
2199 forgotten a semicolon. */
2200 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2203 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2204 a C_ID_CLASSNAME. */
2205 c_parser_consume_token (parser
);
2208 if (kind
== C_ID_ID
)
2210 error ("unknown type name %qE", value
);
2211 t
.kind
= ctsk_typedef
;
2212 t
.spec
= error_mark_node
;
2214 else if (kind
== C_ID_TYPENAME
2215 && (!c_dialect_objc ()
2216 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2218 t
.kind
= ctsk_typedef
;
2219 /* For a typedef name, record the meaning, not the name.
2220 In case of 'foo foo, bar;'. */
2221 t
.spec
= lookup_name (value
);
2225 tree proto
= NULL_TREE
;
2226 gcc_assert (c_dialect_objc ());
2228 if (c_parser_next_token_is (parser
, CPP_LESS
))
2229 proto
= c_parser_objc_protocol_refs (parser
);
2230 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2233 t
.expr_const_operands
= true;
2234 declspecs_add_type (name_token
->location
, specs
, t
);
2237 if (c_parser_next_token_is (parser
, CPP_LESS
))
2239 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2240 nisse@lysator.liu.se. */
2242 gcc_assert (c_dialect_objc ());
2243 if (!typespec_ok
|| seen_type
)
2245 proto
= c_parser_objc_protocol_refs (parser
);
2247 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2249 t
.expr_const_operands
= true;
2250 declspecs_add_type (loc
, specs
, t
);
2253 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2254 switch (c_parser_peek_token (parser
)->keyword
)
2267 /* TODO: Distinguish between function specifiers (inline, noreturn)
2268 and storage class specifiers, either here or in
2269 declspecs_add_scspec. */
2270 declspecs_add_scspec (loc
, specs
,
2271 c_parser_peek_token (parser
)->value
);
2272 c_parser_consume_token (parser
);
2300 if (c_dialect_objc ())
2301 parser
->objc_need_raw_identifier
= true;
2302 t
.kind
= ctsk_resword
;
2303 t
.spec
= c_parser_peek_token (parser
)->value
;
2305 t
.expr_const_operands
= true;
2306 declspecs_add_type (loc
, specs
, t
);
2307 c_parser_consume_token (parser
);
2314 t
= c_parser_enum_specifier (parser
);
2315 declspecs_add_type (loc
, specs
, t
);
2323 t
= c_parser_struct_or_union_specifier (parser
);
2324 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2325 declspecs_add_type (loc
, specs
, t
);
2328 /* ??? The old parser rejected typeof after other type
2329 specifiers, but is a syntax error the best way of
2331 if (!typespec_ok
|| seen_type
)
2335 t
= c_parser_typeof_specifier (parser
);
2336 declspecs_add_type (loc
, specs
, t
);
2339 /* C parser handling of Objective-C constructs needs
2340 checking for correct lvalue-to-rvalue conversions, and
2341 the code in build_modify_expr handling various
2342 Objective-C cases, and that in build_unary_op handling
2343 Objective-C cases for increment / decrement, also needs
2344 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2345 and objc_types_are_equivalent may also need updates. */
2346 if (c_dialect_objc ())
2347 sorry ("%<_Atomic%> in Objective-C");
2348 /* C parser handling of OpenMP constructs needs checking for
2349 correct lvalue-to-rvalue conversions. */
2351 sorry ("%<_Atomic%> with OpenMP");
2355 pedwarn (loc
, OPT_Wpedantic
,
2356 "ISO C99 does not support the %<_Atomic%> qualifier");
2358 pedwarn (loc
, OPT_Wpedantic
,
2359 "ISO C90 does not support the %<_Atomic%> qualifier");
2363 value
= c_parser_peek_token (parser
)->value
;
2364 c_parser_consume_token (parser
);
2365 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2367 /* _Atomic ( type-name ). */
2369 c_parser_consume_token (parser
);
2370 struct c_type_name
*type
= c_parser_type_name (parser
);
2371 t
.kind
= ctsk_typeof
;
2372 t
.spec
= error_mark_node
;
2374 t
.expr_const_operands
= true;
2376 t
.spec
= groktypename (type
, &t
.expr
,
2377 &t
.expr_const_operands
);
2378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2380 if (t
.spec
!= error_mark_node
)
2382 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2383 error_at (loc
, "%<_Atomic%>-qualified array type");
2384 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2385 error_at (loc
, "%<_Atomic%>-qualified function type");
2386 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2387 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2389 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2391 declspecs_add_type (loc
, specs
, t
);
2394 declspecs_add_qual (loc
, specs
, value
);
2400 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2401 c_parser_consume_token (parser
);
2406 attrs
= c_parser_attributes (parser
);
2407 declspecs_add_attrs (loc
, specs
, attrs
);
2412 align
= c_parser_alignas_specifier (parser
);
2413 declspecs_add_alignas (loc
, specs
, align
);
2422 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2425 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2426 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2427 enum attributes[opt] identifier
2429 The form with trailing comma is new in C99. The forms with
2430 attributes are GNU extensions. In GNU C, we accept any expression
2431 without commas in the syntax (assignment expressions, not just
2432 conditional expressions); assignment expressions will be diagnosed
2437 enumerator-list , enumerator
2440 enumeration-constant
2441 enumeration-constant = constant-expression
2444 static struct c_typespec
2445 c_parser_enum_specifier (c_parser
*parser
)
2447 struct c_typespec ret
;
2449 tree ident
= NULL_TREE
;
2450 location_t enum_loc
;
2451 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2452 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2453 enum_loc
= c_parser_peek_token (parser
)->location
;
2454 c_parser_consume_token (parser
);
2455 attrs
= c_parser_attributes (parser
);
2456 enum_loc
= c_parser_peek_token (parser
)->location
;
2457 /* Set the location in case we create a decl now. */
2458 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2459 if (c_parser_next_token_is (parser
, CPP_NAME
))
2461 ident
= c_parser_peek_token (parser
)->value
;
2462 ident_loc
= c_parser_peek_token (parser
)->location
;
2463 enum_loc
= ident_loc
;
2464 c_parser_consume_token (parser
);
2466 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2468 /* Parse an enum definition. */
2469 struct c_enum_contents the_enum
;
2472 /* We chain the enumerators in reverse order, then put them in
2473 forward order at the end. */
2475 timevar_push (TV_PARSE_ENUM
);
2476 type
= start_enum (enum_loc
, &the_enum
, ident
);
2478 c_parser_consume_token (parser
);
2486 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2487 location_t decl_loc
, value_loc
;
2488 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2490 c_parser_error (parser
, "expected identifier");
2491 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2492 values
= error_mark_node
;
2495 token
= c_parser_peek_token (parser
);
2496 enum_id
= token
->value
;
2497 /* Set the location in case we create a decl now. */
2498 c_parser_set_source_position_from_token (token
);
2499 decl_loc
= value_loc
= token
->location
;
2500 c_parser_consume_token (parser
);
2501 if (c_parser_next_token_is (parser
, CPP_EQ
))
2503 c_parser_consume_token (parser
);
2504 value_loc
= c_parser_peek_token (parser
)->location
;
2505 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2508 enum_value
= NULL_TREE
;
2509 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2510 &the_enum
, enum_id
, enum_value
);
2511 TREE_CHAIN (enum_decl
) = values
;
2514 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2516 comma_loc
= c_parser_peek_token (parser
)->location
;
2518 c_parser_consume_token (parser
);
2520 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2522 if (seen_comma
&& !flag_isoc99
)
2523 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2524 c_parser_consume_token (parser
);
2529 c_parser_error (parser
, "expected %<,%> or %<}%>");
2530 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2531 values
= error_mark_node
;
2535 postfix_attrs
= c_parser_attributes (parser
);
2536 ret
.spec
= finish_enum (type
, nreverse (values
),
2537 chainon (attrs
, postfix_attrs
));
2538 ret
.kind
= ctsk_tagdef
;
2539 ret
.expr
= NULL_TREE
;
2540 ret
.expr_const_operands
= true;
2541 timevar_pop (TV_PARSE_ENUM
);
2546 c_parser_error (parser
, "expected %<{%>");
2547 ret
.spec
= error_mark_node
;
2548 ret
.kind
= ctsk_tagref
;
2549 ret
.expr
= NULL_TREE
;
2550 ret
.expr_const_operands
= true;
2553 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2554 /* In ISO C, enumerated types can be referred to only if already
2556 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2559 pedwarn (enum_loc
, OPT_Wpedantic
,
2560 "ISO C forbids forward references to %<enum%> types");
2565 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2567 struct-or-union-specifier:
2568 struct-or-union attributes[opt] identifier[opt]
2569 { struct-contents } attributes[opt]
2570 struct-or-union attributes[opt] identifier
2573 struct-declaration-list
2575 struct-declaration-list:
2576 struct-declaration ;
2577 struct-declaration-list struct-declaration ;
2584 struct-declaration-list struct-declaration
2586 struct-declaration-list:
2587 struct-declaration-list ;
2590 (Note that in the syntax here, unlike that in ISO C, the semicolons
2591 are included here rather than in struct-declaration, in order to
2592 describe the syntax with extra semicolons and missing semicolon at
2597 struct-declaration-list:
2598 @defs ( class-name )
2600 (Note this does not include a trailing semicolon, but can be
2601 followed by further declarations, and gets a pedwarn-if-pedantic
2602 when followed by a semicolon.) */
2604 static struct c_typespec
2605 c_parser_struct_or_union_specifier (c_parser
*parser
)
2607 struct c_typespec ret
;
2609 tree ident
= NULL_TREE
;
2610 location_t struct_loc
;
2611 location_t ident_loc
= UNKNOWN_LOCATION
;
2612 enum tree_code code
;
2613 switch (c_parser_peek_token (parser
)->keyword
)
2624 struct_loc
= c_parser_peek_token (parser
)->location
;
2625 c_parser_consume_token (parser
);
2626 attrs
= c_parser_attributes (parser
);
2628 /* Set the location in case we create a decl now. */
2629 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2631 if (c_parser_next_token_is (parser
, CPP_NAME
))
2633 ident
= c_parser_peek_token (parser
)->value
;
2634 ident_loc
= c_parser_peek_token (parser
)->location
;
2635 struct_loc
= ident_loc
;
2636 c_parser_consume_token (parser
);
2638 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2640 /* Parse a struct or union definition. Start the scope of the
2641 tag before parsing components. */
2642 struct c_struct_parse_info
*struct_info
;
2643 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2645 /* We chain the components in reverse order, then put them in
2646 forward order at the end. Each struct-declaration may
2647 declare multiple components (comma-separated), so we must use
2648 chainon to join them, although when parsing each
2649 struct-declaration we can use TREE_CHAIN directly.
2651 The theory behind all this is that there will be more
2652 semicolon separated fields than comma separated fields, and
2653 so we'll be minimizing the number of node traversals required
2656 timevar_push (TV_PARSE_STRUCT
);
2657 contents
= NULL_TREE
;
2658 c_parser_consume_token (parser
);
2659 /* Handle the Objective-C @defs construct,
2660 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2661 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2664 gcc_assert (c_dialect_objc ());
2665 c_parser_consume_token (parser
);
2666 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2668 if (c_parser_next_token_is (parser
, CPP_NAME
)
2669 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2671 name
= c_parser_peek_token (parser
)->value
;
2672 c_parser_consume_token (parser
);
2676 c_parser_error (parser
, "expected class name");
2677 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2680 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2682 contents
= nreverse (objc_get_class_ivars (name
));
2685 /* Parse the struct-declarations and semicolons. Problems with
2686 semicolons are diagnosed here; empty structures are diagnosed
2691 /* Parse any stray semicolon. */
2692 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2694 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2695 "extra semicolon in struct or union specified");
2696 c_parser_consume_token (parser
);
2699 /* Stop if at the end of the struct or union contents. */
2700 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2702 c_parser_consume_token (parser
);
2705 /* Accept #pragmas at struct scope. */
2706 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2708 c_parser_pragma (parser
, pragma_struct
);
2711 /* Parse some comma-separated declarations, but not the
2712 trailing semicolon if any. */
2713 decls
= c_parser_struct_declaration (parser
);
2714 contents
= chainon (decls
, contents
);
2715 /* If no semicolon follows, either we have a parse error or
2716 are at the end of the struct or union and should
2718 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2719 c_parser_consume_token (parser
);
2722 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2723 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2724 "no semicolon at end of struct or union");
2725 else if (parser
->error
2726 || !c_parser_next_token_starts_declspecs (parser
))
2728 c_parser_error (parser
, "expected %<;%>");
2729 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2733 /* If we come here, we have already emitted an error
2734 for an expected `;', identifier or `(', and we also
2735 recovered already. Go on with the next field. */
2738 postfix_attrs
= c_parser_attributes (parser
);
2739 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2740 chainon (attrs
, postfix_attrs
), struct_info
);
2741 ret
.kind
= ctsk_tagdef
;
2742 ret
.expr
= NULL_TREE
;
2743 ret
.expr_const_operands
= true;
2744 timevar_pop (TV_PARSE_STRUCT
);
2749 c_parser_error (parser
, "expected %<{%>");
2750 ret
.spec
= error_mark_node
;
2751 ret
.kind
= ctsk_tagref
;
2752 ret
.expr
= NULL_TREE
;
2753 ret
.expr_const_operands
= true;
2756 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2760 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2761 the trailing semicolon.
2764 specifier-qualifier-list struct-declarator-list
2765 static_assert-declaration-no-semi
2767 specifier-qualifier-list:
2768 type-specifier specifier-qualifier-list[opt]
2769 type-qualifier specifier-qualifier-list[opt]
2770 attributes specifier-qualifier-list[opt]
2772 struct-declarator-list:
2774 struct-declarator-list , attributes[opt] struct-declarator
2777 declarator attributes[opt]
2778 declarator[opt] : constant-expression attributes[opt]
2783 __extension__ struct-declaration
2784 specifier-qualifier-list
2786 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2787 of attributes where shown is a GNU extension. In GNU C, we accept
2788 any expression without commas in the syntax (assignment
2789 expressions, not just conditional expressions); assignment
2790 expressions will be diagnosed as non-constant. */
2793 c_parser_struct_declaration (c_parser
*parser
)
2795 struct c_declspecs
*specs
;
2797 tree all_prefix_attrs
;
2799 location_t decl_loc
;
2800 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2804 ext
= disable_extension_diagnostics ();
2805 c_parser_consume_token (parser
);
2806 decl
= c_parser_struct_declaration (parser
);
2807 restore_extension_diagnostics (ext
);
2810 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2812 c_parser_static_assert_declaration_no_semi (parser
);
2815 specs
= build_null_declspecs ();
2816 decl_loc
= c_parser_peek_token (parser
)->location
;
2817 /* Strictly by the standard, we shouldn't allow _Alignas here,
2818 but it appears to have been intended to allow it there, so
2819 we're keeping it as it is until WG14 reaches a conclusion
2821 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2822 c_parser_declspecs (parser
, specs
, false, true, true,
2823 true, false, cla_nonabstract_decl
);
2826 if (!specs
->declspecs_seen_p
)
2828 c_parser_error (parser
, "expected specifier-qualifier-list");
2831 finish_declspecs (specs
);
2832 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2833 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2836 if (specs
->typespec_kind
== ctsk_none
)
2838 pedwarn (decl_loc
, OPT_Wpedantic
,
2839 "ISO C forbids member declarations with no members");
2840 shadow_tag_warned (specs
, pedantic
);
2845 /* Support for unnamed structs or unions as members of
2846 structs or unions (which is [a] useful and [b] supports
2850 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2851 build_id_declarator (NULL_TREE
), specs
,
2854 decl_attributes (&ret
, attrs
, 0);
2859 /* Provide better error recovery. Note that a type name here is valid,
2860 and will be treated as a field name. */
2861 if (specs
->typespec_kind
== ctsk_tagdef
2862 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2863 && c_parser_next_token_starts_declspecs (parser
)
2864 && !c_parser_next_token_is (parser
, CPP_NAME
))
2866 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2867 parser
->error
= false;
2871 pending_xref_error ();
2872 prefix_attrs
= specs
->attrs
;
2873 all_prefix_attrs
= prefix_attrs
;
2874 specs
->attrs
= NULL_TREE
;
2878 /* Declaring one or more declarators or un-named bit-fields. */
2879 struct c_declarator
*declarator
;
2881 if (c_parser_next_token_is (parser
, CPP_COLON
))
2882 declarator
= build_id_declarator (NULL_TREE
);
2884 declarator
= c_parser_declarator (parser
,
2885 specs
->typespec_kind
!= ctsk_none
,
2886 C_DTR_NORMAL
, &dummy
);
2887 if (declarator
== NULL
)
2889 c_parser_skip_to_end_of_block_or_statement (parser
);
2892 if (c_parser_next_token_is (parser
, CPP_COLON
)
2893 || c_parser_next_token_is (parser
, CPP_COMMA
)
2894 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2895 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2896 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2898 tree postfix_attrs
= NULL_TREE
;
2899 tree width
= NULL_TREE
;
2901 if (c_parser_next_token_is (parser
, CPP_COLON
))
2903 c_parser_consume_token (parser
);
2904 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2906 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2907 postfix_attrs
= c_parser_attributes (parser
);
2908 d
= grokfield (c_parser_peek_token (parser
)->location
,
2909 declarator
, specs
, width
, &all_prefix_attrs
);
2910 decl_attributes (&d
, chainon (postfix_attrs
,
2911 all_prefix_attrs
), 0);
2912 DECL_CHAIN (d
) = decls
;
2914 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2915 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2918 all_prefix_attrs
= prefix_attrs
;
2919 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2920 c_parser_consume_token (parser
);
2921 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2922 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2924 /* Semicolon consumed in caller. */
2929 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2935 c_parser_error (parser
,
2936 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2937 "%<__attribute__%>");
2944 /* Parse a typeof specifier (a GNU extension).
2947 typeof ( expression )
2948 typeof ( type-name )
2951 static struct c_typespec
2952 c_parser_typeof_specifier (c_parser
*parser
)
2954 struct c_typespec ret
;
2955 ret
.kind
= ctsk_typeof
;
2956 ret
.spec
= error_mark_node
;
2957 ret
.expr
= NULL_TREE
;
2958 ret
.expr_const_operands
= true;
2959 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2960 c_parser_consume_token (parser
);
2961 c_inhibit_evaluation_warnings
++;
2963 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2965 c_inhibit_evaluation_warnings
--;
2969 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2971 struct c_type_name
*type
= c_parser_type_name (parser
);
2972 c_inhibit_evaluation_warnings
--;
2976 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2977 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2983 location_t here
= c_parser_peek_token (parser
)->location
;
2984 struct c_expr expr
= c_parser_expression (parser
);
2985 c_inhibit_evaluation_warnings
--;
2987 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2988 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2989 error_at (here
, "%<typeof%> applied to a bit-field");
2990 mark_exp_read (expr
.value
);
2991 ret
.spec
= TREE_TYPE (expr
.value
);
2992 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2993 /* This is returned with the type so that when the type is
2994 evaluated, this can be evaluated. */
2996 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2997 pop_maybe_used (was_vm
);
2998 /* For use in macros such as those in <stdatomic.h>, remove
2999 _Atomic and const qualifiers from atomic types. (Possibly
3000 all qualifiers should be removed; const can be an issue for
3001 more macros using typeof than just the <stdatomic.h>
3003 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3004 ret
.spec
= c_build_qualified_type (ret
.spec
,
3005 (TYPE_QUALS (ret
.spec
)
3006 & ~(TYPE_QUAL_ATOMIC
3007 | TYPE_QUAL_CONST
)));
3009 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3013 /* Parse an alignment-specifier.
3017 alignment-specifier:
3018 _Alignas ( type-name )
3019 _Alignas ( constant-expression )
3023 c_parser_alignas_specifier (c_parser
* parser
)
3025 tree ret
= error_mark_node
;
3026 location_t loc
= c_parser_peek_token (parser
)->location
;
3027 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3028 c_parser_consume_token (parser
);
3032 pedwarn (loc
, OPT_Wpedantic
,
3033 "ISO C99 does not support %<_Alignas%>");
3035 pedwarn (loc
, OPT_Wpedantic
,
3036 "ISO C90 does not support %<_Alignas%>");
3038 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3040 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3042 struct c_type_name
*type
= c_parser_type_name (parser
);
3044 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
3047 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3048 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3052 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3053 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3054 be redeclared; otherwise it may not. KIND indicates which kind of
3055 declarator is wanted. Returns a valid declarator except in the
3056 case of a syntax error in which case NULL is returned. *SEEN_ID is
3057 set to true if an identifier being declared is seen; this is used
3058 to diagnose bad forms of abstract array declarators and to
3059 determine whether an identifier list is syntactically permitted.
3062 pointer[opt] direct-declarator
3066 ( attributes[opt] declarator )
3067 direct-declarator array-declarator
3068 direct-declarator ( parameter-type-list )
3069 direct-declarator ( identifier-list[opt] )
3072 * type-qualifier-list[opt]
3073 * type-qualifier-list[opt] pointer
3075 type-qualifier-list:
3078 type-qualifier-list type-qualifier
3079 type-qualifier-list attributes
3082 [ type-qualifier-list[opt] assignment-expression[opt] ]
3083 [ static type-qualifier-list[opt] assignment-expression ]
3084 [ type-qualifier-list static assignment-expression ]
3085 [ type-qualifier-list[opt] * ]
3087 parameter-type-list:
3089 parameter-list , ...
3092 parameter-declaration
3093 parameter-list , parameter-declaration
3095 parameter-declaration:
3096 declaration-specifiers declarator attributes[opt]
3097 declaration-specifiers abstract-declarator[opt] attributes[opt]
3101 identifier-list , identifier
3103 abstract-declarator:
3105 pointer[opt] direct-abstract-declarator
3107 direct-abstract-declarator:
3108 ( attributes[opt] abstract-declarator )
3109 direct-abstract-declarator[opt] array-declarator
3110 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3115 direct-declarator ( parameter-forward-declarations
3116 parameter-type-list[opt] )
3118 direct-abstract-declarator:
3119 direct-abstract-declarator[opt] ( parameter-forward-declarations
3120 parameter-type-list[opt] )
3122 parameter-forward-declarations:
3124 parameter-forward-declarations parameter-list ;
3126 The uses of attributes shown above are GNU extensions.
3128 Some forms of array declarator are not included in C99 in the
3129 syntax for abstract declarators; these are disallowed elsewhere.
3130 This may be a defect (DR#289).
3132 This function also accepts an omitted abstract declarator as being
3133 an abstract declarator, although not part of the formal syntax. */
3135 static struct c_declarator
*
3136 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3139 /* Parse any initial pointer part. */
3140 if (c_parser_next_token_is (parser
, CPP_MULT
))
3142 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3143 struct c_declarator
*inner
;
3144 c_parser_consume_token (parser
);
3145 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3146 false, false, cla_prefer_id
);
3147 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3151 return make_pointer_declarator (quals_attrs
, inner
);
3153 /* Now we have a direct declarator, direct abstract declarator or
3154 nothing (which counts as a direct abstract declarator here). */
3155 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3158 /* Parse a direct declarator or direct abstract declarator; arguments
3159 as c_parser_declarator. */
3161 static struct c_declarator
*
3162 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3165 /* The direct declarator must start with an identifier (possibly
3166 omitted) or a parenthesized declarator (possibly abstract). In
3167 an ordinary declarator, initial parentheses must start a
3168 parenthesized declarator. In an abstract declarator or parameter
3169 declarator, they could start a parenthesized declarator or a
3170 parameter list. To tell which, the open parenthesis and any
3171 following attributes must be read. If a declaration specifier
3172 follows, then it is a parameter list; if the specifier is a
3173 typedef name, there might be an ambiguity about redeclaring it,
3174 which is resolved in the direction of treating it as a typedef
3175 name. If a close parenthesis follows, it is also an empty
3176 parameter list, as the syntax does not permit empty abstract
3177 declarators. Otherwise, it is a parenthesized declarator (in
3178 which case the analysis may be repeated inside it, recursively).
3180 ??? There is an ambiguity in a parameter declaration "int
3181 (__attribute__((foo)) x)", where x is not a typedef name: it
3182 could be an abstract declarator for a function, or declare x with
3183 parentheses. The proper resolution of this ambiguity needs
3184 documenting. At present we follow an accident of the old
3185 parser's implementation, whereby the first parameter must have
3186 some declaration specifiers other than just attributes. Thus as
3187 a parameter declaration it is treated as a parenthesized
3188 parameter named x, and as an abstract declarator it is
3191 ??? Also following the old parser, attributes inside an empty
3192 parameter list are ignored, making it a list not yielding a
3193 prototype, rather than giving an error or making it have one
3194 parameter with implicit type int.
3196 ??? Also following the old parser, typedef names may be
3197 redeclared in declarators, but not Objective-C class names. */
3199 if (kind
!= C_DTR_ABSTRACT
3200 && c_parser_next_token_is (parser
, CPP_NAME
)
3202 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3203 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3204 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3206 struct c_declarator
*inner
3207 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3209 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3210 c_parser_consume_token (parser
);
3211 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3214 if (kind
!= C_DTR_NORMAL
3215 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3217 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3218 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3221 /* Either we are at the end of an abstract declarator, or we have
3224 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3227 struct c_declarator
*inner
;
3228 c_parser_consume_token (parser
);
3229 attrs
= c_parser_attributes (parser
);
3230 if (kind
!= C_DTR_NORMAL
3231 && (c_parser_next_token_starts_declspecs (parser
)
3232 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3234 struct c_arg_info
*args
3235 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3242 = build_function_declarator (args
,
3243 build_id_declarator (NULL_TREE
));
3244 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3248 /* A parenthesized declarator. */
3249 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3250 if (inner
!= NULL
&& attrs
!= NULL
)
3251 inner
= build_attrs_declarator (attrs
, inner
);
3252 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3254 c_parser_consume_token (parser
);
3258 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3262 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3269 if (kind
== C_DTR_NORMAL
)
3271 c_parser_error (parser
, "expected identifier or %<(%>");
3275 return build_id_declarator (NULL_TREE
);
3279 /* Parse part of a direct declarator or direct abstract declarator,
3280 given that some (in INNER) has already been parsed; ID_PRESENT is
3281 true if an identifier is present, false for an abstract
3284 static struct c_declarator
*
3285 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3286 struct c_declarator
*inner
)
3288 /* Parse a sequence of array declarators and parameter lists. */
3289 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3291 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3292 struct c_declarator
*declarator
;
3293 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3296 struct c_expr dimen
;
3297 dimen
.value
= NULL_TREE
;
3298 dimen
.original_code
= ERROR_MARK
;
3299 dimen
.original_type
= NULL_TREE
;
3300 c_parser_consume_token (parser
);
3301 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3302 false, false, cla_prefer_id
);
3303 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3305 c_parser_consume_token (parser
);
3306 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3307 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3308 false, false, cla_prefer_id
);
3309 if (!quals_attrs
->declspecs_seen_p
)
3311 /* If "static" is present, there must be an array dimension.
3312 Otherwise, there may be a dimension, "*", or no
3317 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3321 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3323 dimen
.value
= NULL_TREE
;
3326 else if (flag_enable_cilkplus
3327 && c_parser_next_token_is (parser
, CPP_COLON
))
3329 dimen
.value
= error_mark_node
;
3331 error_at (c_parser_peek_token (parser
)->location
,
3332 "array notations cannot be used in declaration");
3333 c_parser_consume_token (parser
);
3335 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3337 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3339 dimen
.value
= NULL_TREE
;
3341 c_parser_consume_token (parser
);
3346 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3352 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3355 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3356 c_parser_consume_token (parser
);
3357 else if (flag_enable_cilkplus
3358 && c_parser_next_token_is (parser
, CPP_COLON
))
3360 error_at (c_parser_peek_token (parser
)->location
,
3361 "array notations cannot be used in declaration");
3362 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3367 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3372 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3373 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3374 static_seen
, star_seen
);
3375 if (declarator
== NULL
)
3377 inner
= set_array_declarator_inner (declarator
, inner
);
3378 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3380 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3383 struct c_arg_info
*args
;
3384 c_parser_consume_token (parser
);
3385 attrs
= c_parser_attributes (parser
);
3386 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3391 inner
= build_function_declarator (args
, inner
);
3392 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3398 /* Parse a parameter list or identifier list, including the closing
3399 parenthesis but not the opening one. ATTRS are the attributes at
3400 the start of the list. ID_LIST_OK is true if an identifier list is
3401 acceptable; such a list must not have attributes at the start. */
3403 static struct c_arg_info
*
3404 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3407 declare_parm_level ();
3408 /* If the list starts with an identifier, it is an identifier list.
3409 Otherwise, it is either a prototype list or an empty list. */
3412 && c_parser_next_token_is (parser
, CPP_NAME
)
3413 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3415 /* Look ahead to detect typos in type names. */
3416 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3417 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3418 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3419 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3421 tree list
= NULL_TREE
, *nextp
= &list
;
3422 while (c_parser_next_token_is (parser
, CPP_NAME
)
3423 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3425 *nextp
= build_tree_list (NULL_TREE
,
3426 c_parser_peek_token (parser
)->value
);
3427 nextp
= & TREE_CHAIN (*nextp
);
3428 c_parser_consume_token (parser
);
3429 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3431 c_parser_consume_token (parser
);
3432 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3434 c_parser_error (parser
, "expected identifier");
3438 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3440 struct c_arg_info
*ret
= build_arg_info ();
3442 c_parser_consume_token (parser
);
3448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3456 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3463 /* Parse a parameter list (possibly empty), including the closing
3464 parenthesis but not the opening one. ATTRS are the attributes at
3465 the start of the list. EXPR is NULL or an expression that needs to
3466 be evaluated for the side effects of array size expressions in the
3469 static struct c_arg_info
*
3470 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3472 bool bad_parm
= false;
3474 /* ??? Following the old parser, forward parameter declarations may
3475 use abstract declarators, and if no real parameter declarations
3476 follow the forward declarations then this is not diagnosed. Also
3477 note as above that attributes are ignored as the only contents of
3478 the parentheses, or as the only contents after forward
3480 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3482 struct c_arg_info
*ret
= build_arg_info ();
3483 c_parser_consume_token (parser
);
3486 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3488 struct c_arg_info
*ret
= build_arg_info ();
3490 if (flag_allow_parameterless_variadic_functions
)
3492 /* F (...) is allowed. */
3493 ret
->types
= NULL_TREE
;
3497 /* Suppress -Wold-style-definition for this case. */
3498 ret
->types
= error_mark_node
;
3499 error_at (c_parser_peek_token (parser
)->location
,
3500 "ISO C requires a named argument before %<...%>");
3502 c_parser_consume_token (parser
);
3503 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3505 c_parser_consume_token (parser
);
3510 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3515 /* Nonempty list of parameters, either terminated with semicolon
3516 (forward declarations; recurse) or with close parenthesis (normal
3517 function) or with ", ... )" (variadic function). */
3520 /* Parse a parameter. */
3521 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3526 push_parm_decl (parm
, &expr
);
3527 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3530 c_parser_consume_token (parser
);
3531 mark_forward_parm_decls ();
3532 new_attrs
= c_parser_attributes (parser
);
3533 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3535 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3537 c_parser_consume_token (parser
);
3541 return get_parm_info (false, expr
);
3543 if (!c_parser_require (parser
, CPP_COMMA
,
3544 "expected %<;%>, %<,%> or %<)%>"))
3546 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3549 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3551 c_parser_consume_token (parser
);
3552 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3554 c_parser_consume_token (parser
);
3558 return get_parm_info (true, expr
);
3562 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3570 /* Parse a parameter declaration. ATTRS are the attributes at the
3571 start of the declaration if it is the first parameter. */
3573 static struct c_parm
*
3574 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3576 struct c_declspecs
*specs
;
3577 struct c_declarator
*declarator
;
3579 tree postfix_attrs
= NULL_TREE
;
3582 /* Accept #pragmas between parameter declarations. */
3583 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3584 c_parser_pragma (parser
, pragma_param
);
3586 if (!c_parser_next_token_starts_declspecs (parser
))
3588 c_token
*token
= c_parser_peek_token (parser
);
3591 c_parser_set_source_position_from_token (token
);
3592 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3594 error ("unknown type name %qE", token
->value
);
3595 parser
->error
= true;
3597 /* ??? In some Objective-C cases '...' isn't applicable so there
3598 should be a different message. */
3600 c_parser_error (parser
,
3601 "expected declaration specifiers or %<...%>");
3602 c_parser_skip_to_end_of_parameter (parser
);
3605 specs
= build_null_declspecs ();
3608 declspecs_add_attrs (input_location
, specs
, attrs
);
3611 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3612 cla_nonabstract_decl
);
3613 finish_declspecs (specs
);
3614 pending_xref_error ();
3615 prefix_attrs
= specs
->attrs
;
3616 specs
->attrs
= NULL_TREE
;
3617 declarator
= c_parser_declarator (parser
,
3618 specs
->typespec_kind
!= ctsk_none
,
3619 C_DTR_PARM
, &dummy
);
3620 if (declarator
== NULL
)
3622 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3625 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3626 postfix_attrs
= c_parser_attributes (parser
);
3627 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3631 /* Parse a string literal in an asm expression. It should not be
3632 translated, and wide string literals are an error although
3633 permitted by the syntax. This is a GNU extension.
3638 ??? At present, following the old parser, the caller needs to have
3639 set lex_untranslated_string to 1. It would be better to follow the
3640 C++ parser rather than using this kludge. */
3643 c_parser_asm_string_literal (c_parser
*parser
)
3646 int save_flag
= warn_overlength_strings
;
3647 warn_overlength_strings
= 0;
3648 if (c_parser_next_token_is (parser
, CPP_STRING
))
3650 str
= c_parser_peek_token (parser
)->value
;
3651 c_parser_consume_token (parser
);
3653 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3655 error_at (c_parser_peek_token (parser
)->location
,
3656 "wide string literal in %<asm%>");
3657 str
= build_string (1, "");
3658 c_parser_consume_token (parser
);
3662 c_parser_error (parser
, "expected string literal");
3665 warn_overlength_strings
= save_flag
;
3669 /* Parse a simple asm expression. This is used in restricted
3670 contexts, where a full expression with inputs and outputs does not
3671 make sense. This is a GNU extension.
3674 asm ( asm-string-literal )
3678 c_parser_simple_asm_expr (c_parser
*parser
)
3681 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3682 /* ??? Follow the C++ parser rather than using the
3683 lex_untranslated_string kludge. */
3684 parser
->lex_untranslated_string
= true;
3685 c_parser_consume_token (parser
);
3686 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3688 parser
->lex_untranslated_string
= false;
3691 str
= c_parser_asm_string_literal (parser
);
3692 parser
->lex_untranslated_string
= false;
3693 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3695 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3702 c_parser_attribute_any_word (c_parser
*parser
)
3704 tree attr_name
= NULL_TREE
;
3706 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3708 /* ??? See comment above about what keywords are accepted here. */
3710 switch (c_parser_peek_token (parser
)->keyword
)
3741 case RID_TRANSACTION_ATOMIC
:
3742 case RID_TRANSACTION_CANCEL
:
3754 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3755 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3757 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3758 attr_name
= c_parser_peek_token (parser
)->value
;
3763 /* Parse (possibly empty) attributes. This is a GNU extension.
3767 attributes attribute
3770 __attribute__ ( ( attribute-list ) )
3774 attribute_list , attrib
3779 any-word ( identifier )
3780 any-word ( identifier , nonempty-expr-list )
3781 any-word ( expr-list )
3783 where the "identifier" must not be declared as a type, and
3784 "any-word" may be any identifier (including one declared as a
3785 type), a reserved word storage class specifier, type specifier or
3786 type qualifier. ??? This still leaves out most reserved keywords
3787 (following the old parser), shouldn't we include them, and why not
3788 allow identifiers declared as types to start the arguments? */
3791 c_parser_attributes (c_parser
*parser
)
3793 tree attrs
= NULL_TREE
;
3794 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3796 /* ??? Follow the C++ parser rather than using the
3797 lex_untranslated_string kludge. */
3798 parser
->lex_untranslated_string
= true;
3799 c_parser_consume_token (parser
);
3800 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3802 parser
->lex_untranslated_string
= false;
3805 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3807 parser
->lex_untranslated_string
= false;
3808 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3811 /* Parse the attribute list. */
3812 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3813 || c_parser_next_token_is (parser
, CPP_NAME
)
3814 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3816 tree attr
, attr_name
, attr_args
;
3817 vec
<tree
, va_gc
> *expr_list
;
3818 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3820 c_parser_consume_token (parser
);
3824 attr_name
= c_parser_attribute_any_word (parser
);
3825 if (attr_name
== NULL
)
3827 c_parser_consume_token (parser
);
3828 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3830 attr
= build_tree_list (attr_name
, NULL_TREE
);
3831 attrs
= chainon (attrs
, attr
);
3834 c_parser_consume_token (parser
);
3835 /* Parse the attribute contents. If they start with an
3836 identifier which is followed by a comma or close
3837 parenthesis, then the arguments start with that
3838 identifier; otherwise they are an expression list.
3839 In objective-c the identifier may be a classname. */
3840 if (c_parser_next_token_is (parser
, CPP_NAME
)
3841 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3842 || (c_dialect_objc ()
3843 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3844 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3845 || (c_parser_peek_2nd_token (parser
)->type
3846 == CPP_CLOSE_PAREN
)))
3848 tree arg1
= c_parser_peek_token (parser
)->value
;
3849 c_parser_consume_token (parser
);
3850 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3851 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3855 c_parser_consume_token (parser
);
3856 expr_list
= c_parser_expr_list (parser
, false, true,
3858 tree_list
= build_tree_list_vec (expr_list
);
3859 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3860 release_tree_vector (expr_list
);
3865 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3866 attr_args
= NULL_TREE
;
3869 expr_list
= c_parser_expr_list (parser
, false, true,
3871 attr_args
= build_tree_list_vec (expr_list
);
3872 release_tree_vector (expr_list
);
3875 attr
= build_tree_list (attr_name
, attr_args
);
3876 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3877 c_parser_consume_token (parser
);
3880 parser
->lex_untranslated_string
= false;
3881 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3885 attrs
= chainon (attrs
, attr
);
3887 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3888 c_parser_consume_token (parser
);
3891 parser
->lex_untranslated_string
= false;
3892 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3896 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3897 c_parser_consume_token (parser
);
3900 parser
->lex_untranslated_string
= false;
3901 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3905 parser
->lex_untranslated_string
= false;
3910 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3913 specifier-qualifier-list abstract-declarator[opt]
3916 static struct c_type_name
*
3917 c_parser_type_name (c_parser
*parser
)
3919 struct c_declspecs
*specs
= build_null_declspecs ();
3920 struct c_declarator
*declarator
;
3921 struct c_type_name
*ret
;
3923 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
3925 if (!specs
->declspecs_seen_p
)
3927 c_parser_error (parser
, "expected specifier-qualifier-list");
3930 if (specs
->type
!= error_mark_node
)
3932 pending_xref_error ();
3933 finish_declspecs (specs
);
3935 declarator
= c_parser_declarator (parser
,
3936 specs
->typespec_kind
!= ctsk_none
,
3937 C_DTR_ABSTRACT
, &dummy
);
3938 if (declarator
== NULL
)
3940 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3942 ret
->declarator
= declarator
;
3946 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3949 assignment-expression
3950 { initializer-list }
3951 { initializer-list , }
3954 designation[opt] initializer
3955 initializer-list , designation[opt] initializer
3962 designator-list designator
3969 [ constant-expression ]
3981 [ constant-expression ... constant-expression ]
3983 Any expression without commas is accepted in the syntax for the
3984 constant-expressions, with non-constant expressions rejected later.
3986 This function is only used for top-level initializers; for nested
3987 ones, see c_parser_initval. */
3989 static struct c_expr
3990 c_parser_initializer (c_parser
*parser
)
3992 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3993 return c_parser_braced_init (parser
, NULL_TREE
, false);
3997 location_t loc
= c_parser_peek_token (parser
)->location
;
3998 ret
= c_parser_expr_no_commas (parser
, NULL
);
3999 if (TREE_CODE (ret
.value
) != STRING_CST
4000 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4001 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4006 /* Parse a braced initializer list. TYPE is the type specified for a
4007 compound literal, and NULL_TREE for other initializers and for
4008 nested braced lists. NESTED_P is true for nested braced lists,
4009 false for the list of a compound literal or the list that is the
4010 top-level initializer in a declaration. */
4012 static struct c_expr
4013 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4016 struct obstack braced_init_obstack
;
4017 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4018 gcc_obstack_init (&braced_init_obstack
);
4019 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4020 c_parser_consume_token (parser
);
4022 push_init_level (0, &braced_init_obstack
);
4024 really_start_incremental_init (type
);
4025 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4027 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4031 /* Parse a non-empty initializer list, possibly with a trailing
4035 c_parser_initelt (parser
, &braced_init_obstack
);
4038 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4039 c_parser_consume_token (parser
);
4042 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4046 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4048 ret
.value
= error_mark_node
;
4049 ret
.original_code
= ERROR_MARK
;
4050 ret
.original_type
= NULL
;
4051 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4052 pop_init_level (0, &braced_init_obstack
);
4053 obstack_free (&braced_init_obstack
, NULL
);
4056 c_parser_consume_token (parser
);
4057 ret
= pop_init_level (0, &braced_init_obstack
);
4058 obstack_free (&braced_init_obstack
, NULL
);
4062 /* Parse a nested initializer, including designators. */
4065 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4067 /* Parse any designator or designator list. A single array
4068 designator may have the subsequent "=" omitted in GNU C, but a
4069 longer list or a structure member designator may not. */
4070 if (c_parser_next_token_is (parser
, CPP_NAME
)
4071 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4073 /* Old-style structure member designator. */
4074 set_init_label (c_parser_peek_token (parser
)->value
,
4075 braced_init_obstack
);
4076 /* Use the colon as the error location. */
4077 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4078 "obsolete use of designated initializer with %<:%>");
4079 c_parser_consume_token (parser
);
4080 c_parser_consume_token (parser
);
4084 /* des_seen is 0 if there have been no designators, 1 if there
4085 has been a single array designator and 2 otherwise. */
4087 /* Location of a designator. */
4088 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4089 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4090 || c_parser_next_token_is (parser
, CPP_DOT
))
4092 int des_prev
= des_seen
;
4094 des_loc
= c_parser_peek_token (parser
)->location
;
4097 if (c_parser_next_token_is (parser
, CPP_DOT
))
4100 c_parser_consume_token (parser
);
4101 if (c_parser_next_token_is (parser
, CPP_NAME
))
4103 set_init_label (c_parser_peek_token (parser
)->value
,
4104 braced_init_obstack
);
4105 c_parser_consume_token (parser
);
4110 init
.value
= error_mark_node
;
4111 init
.original_code
= ERROR_MARK
;
4112 init
.original_type
= NULL
;
4113 c_parser_error (parser
, "expected identifier");
4114 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4115 process_init_element (init
, false, braced_init_obstack
);
4122 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4123 /* ??? Following the old parser, [ objc-receiver
4124 objc-message-args ] is accepted as an initializer,
4125 being distinguished from a designator by what follows
4126 the first assignment expression inside the square
4127 brackets, but after a first array designator a
4128 subsequent square bracket is for Objective-C taken to
4129 start an expression, using the obsolete form of
4130 designated initializer without '=', rather than
4131 possibly being a second level of designation: in LALR
4132 terms, the '[' is shifted rather than reducing
4133 designator to designator-list. */
4134 if (des_prev
== 1 && c_dialect_objc ())
4136 des_seen
= des_prev
;
4139 if (des_prev
== 0 && c_dialect_objc ())
4141 /* This might be an array designator or an
4142 Objective-C message expression. If the former,
4143 continue parsing here; if the latter, parse the
4144 remainder of the initializer given the starting
4145 primary-expression. ??? It might make sense to
4146 distinguish when des_prev == 1 as well; see
4147 previous comment. */
4149 struct c_expr mexpr
;
4150 c_parser_consume_token (parser
);
4151 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4152 && ((c_parser_peek_token (parser
)->id_kind
4154 || (c_parser_peek_token (parser
)->id_kind
4155 == C_ID_CLASSNAME
)))
4157 /* Type name receiver. */
4158 tree id
= c_parser_peek_token (parser
)->value
;
4159 c_parser_consume_token (parser
);
4160 rec
= objc_get_class_reference (id
);
4161 goto parse_message_args
;
4163 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4164 mark_exp_read (first
);
4165 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4166 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4167 goto array_desig_after_first
;
4168 /* Expression receiver. So far only one part
4169 without commas has been parsed; there might be
4170 more of the expression. */
4172 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4175 location_t comma_loc
, exp_loc
;
4176 comma_loc
= c_parser_peek_token (parser
)->location
;
4177 c_parser_consume_token (parser
);
4178 exp_loc
= c_parser_peek_token (parser
)->location
;
4179 next
= c_parser_expr_no_commas (parser
, NULL
);
4180 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4182 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4185 /* Now parse the objc-message-args. */
4186 args
= c_parser_objc_message_args (parser
);
4187 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4190 = objc_build_message_expr (rec
, args
);
4191 mexpr
.original_code
= ERROR_MARK
;
4192 mexpr
.original_type
= NULL
;
4193 /* Now parse and process the remainder of the
4194 initializer, starting with this message
4195 expression as a primary-expression. */
4196 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4199 c_parser_consume_token (parser
);
4200 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4201 mark_exp_read (first
);
4202 array_desig_after_first
:
4203 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4205 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4206 c_parser_consume_token (parser
);
4207 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4208 mark_exp_read (second
);
4212 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4214 c_parser_consume_token (parser
);
4215 set_init_index (first
, second
, braced_init_obstack
);
4217 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4218 "ISO C forbids specifying range of elements to initialize");
4221 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4227 if (c_parser_next_token_is (parser
, CPP_EQ
))
4230 pedwarn (des_loc
, OPT_Wpedantic
,
4231 "ISO C90 forbids specifying subobject to initialize");
4232 c_parser_consume_token (parser
);
4237 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4238 "obsolete use of designated initializer without %<=%>");
4242 init
.value
= error_mark_node
;
4243 init
.original_code
= ERROR_MARK
;
4244 init
.original_type
= NULL
;
4245 c_parser_error (parser
, "expected %<=%>");
4246 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4247 process_init_element (init
, false, braced_init_obstack
);
4253 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4256 /* Parse a nested initializer; as c_parser_initializer but parses
4257 initializers within braced lists, after any designators have been
4258 applied. If AFTER is not NULL then it is an Objective-C message
4259 expression which is the primary-expression starting the
4263 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4264 struct obstack
* braced_init_obstack
)
4267 gcc_assert (!after
|| c_dialect_objc ());
4268 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4269 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4272 location_t loc
= c_parser_peek_token (parser
)->location
;
4273 init
= c_parser_expr_no_commas (parser
, after
);
4274 if (init
.value
!= NULL_TREE
4275 && TREE_CODE (init
.value
) != STRING_CST
4276 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4277 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4279 process_init_element (init
, false, braced_init_obstack
);
4282 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4286 { block-item-list[opt] }
4287 { label-declarations block-item-list }
4291 block-item-list block-item
4303 { label-declarations block-item-list }
4306 __extension__ nested-declaration
4307 nested-function-definition
4311 label-declarations label-declaration
4314 __label__ identifier-list ;
4316 Allowing the mixing of declarations and code is new in C99. The
4317 GNU syntax also permits (not shown above) labels at the end of
4318 compound statements, which yield an error. We don't allow labels
4319 on declarations; this might seem like a natural extension, but
4320 there would be a conflict between attributes on the label and
4321 prefix attributes on the declaration. ??? The syntax follows the
4322 old parser in requiring something after label declarations.
4323 Although they are erroneous if the labels declared aren't defined,
4324 is it useful for the syntax to be this way?
4337 cancellation-point-directive */
4340 c_parser_compound_statement (c_parser
*parser
)
4343 location_t brace_loc
;
4344 brace_loc
= c_parser_peek_token (parser
)->location
;
4345 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4347 /* Ensure a scope is entered and left anyway to avoid confusion
4348 if we have just prepared to enter a function body. */
4349 stmt
= c_begin_compound_stmt (true);
4350 c_end_compound_stmt (brace_loc
, stmt
, true);
4351 return error_mark_node
;
4353 stmt
= c_begin_compound_stmt (true);
4354 c_parser_compound_statement_nostart (parser
);
4356 /* If the compound stmt contains array notations, then we expand them. */
4357 if (flag_enable_cilkplus
&& contains_array_notation_expr (stmt
))
4358 stmt
= expand_array_notation_exprs (stmt
);
4359 return c_end_compound_stmt (brace_loc
, stmt
, true);
4362 /* Parse a compound statement except for the opening brace. This is
4363 used for parsing both compound statements and statement expressions
4364 (which follow different paths to handling the opening). */
4367 c_parser_compound_statement_nostart (c_parser
*parser
)
4369 bool last_stmt
= false;
4370 bool last_label
= false;
4371 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4372 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4373 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4375 c_parser_consume_token (parser
);
4378 mark_valid_location_for_stdc_pragma (true);
4379 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4381 /* Read zero or more forward-declarations for labels that nested
4382 functions can jump to. */
4383 mark_valid_location_for_stdc_pragma (false);
4384 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4386 label_loc
= c_parser_peek_token (parser
)->location
;
4387 c_parser_consume_token (parser
);
4388 /* Any identifiers, including those declared as type names,
4393 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4395 c_parser_error (parser
, "expected identifier");
4399 = declare_label (c_parser_peek_token (parser
)->value
);
4400 C_DECLARED_LABEL_FLAG (label
) = 1;
4401 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4402 c_parser_consume_token (parser
);
4403 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4404 c_parser_consume_token (parser
);
4408 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4410 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4412 /* We must now have at least one statement, label or declaration. */
4413 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4415 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4416 c_parser_error (parser
, "expected declaration or statement");
4417 c_parser_consume_token (parser
);
4420 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4422 location_t loc
= c_parser_peek_token (parser
)->location
;
4423 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4424 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4425 || (c_parser_next_token_is (parser
, CPP_NAME
)
4426 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4428 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4429 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4431 label_loc
= c_parser_peek_token (parser
)->location
;
4434 mark_valid_location_for_stdc_pragma (false);
4435 c_parser_label (parser
);
4437 else if (!last_label
4438 && c_parser_next_tokens_start_declaration (parser
))
4441 mark_valid_location_for_stdc_pragma (false);
4442 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4446 (pedantic
&& !flag_isoc99
)
4448 : OPT_Wdeclaration_after_statement
,
4449 "ISO C90 forbids mixed declarations and code");
4452 else if (!last_label
4453 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4455 /* __extension__ can start a declaration, but is also an
4456 unary operator that can start an expression. Consume all
4457 but the last of a possible series of __extension__ to
4459 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4460 && (c_parser_peek_2nd_token (parser
)->keyword
4462 c_parser_consume_token (parser
);
4463 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4466 ext
= disable_extension_diagnostics ();
4467 c_parser_consume_token (parser
);
4469 mark_valid_location_for_stdc_pragma (false);
4470 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4472 /* Following the old parser, __extension__ does not
4473 disable this diagnostic. */
4474 restore_extension_diagnostics (ext
);
4476 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4478 : OPT_Wdeclaration_after_statement
,
4479 "ISO C90 forbids mixed declarations and code");
4485 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4487 /* External pragmas, and some omp pragmas, are not associated
4488 with regular c code, and so are not to be considered statements
4489 syntactically. This ensures that the user doesn't put them
4490 places that would turn into syntax errors if the directive
4492 if (c_parser_pragma (parser
, pragma_compound
))
4493 last_label
= false, last_stmt
= true;
4495 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4497 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4498 c_parser_error (parser
, "expected declaration or statement");
4501 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4503 if (parser
->in_if_block
)
4505 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4506 error_at (loc
, """expected %<}%> before %<else%>");
4511 error_at (loc
, "%<else%> without a previous %<if%>");
4512 c_parser_consume_token (parser
);
4521 mark_valid_location_for_stdc_pragma (false);
4522 c_parser_statement_after_labels (parser
);
4525 parser
->error
= false;
4528 error_at (label_loc
, "label at end of compound statement");
4529 c_parser_consume_token (parser
);
4530 /* Restore the value we started with. */
4531 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4534 /* Parse a label (C90 6.6.1, C99 6.8.1).
4537 identifier : attributes[opt]
4538 case constant-expression :
4544 case constant-expression ... constant-expression :
4546 The use of attributes on labels is a GNU extension. The syntax in
4547 GNU C accepts any expressions without commas, non-constant
4548 expressions being rejected later. */
4551 c_parser_label (c_parser
*parser
)
4553 location_t loc1
= c_parser_peek_token (parser
)->location
;
4554 tree label
= NULL_TREE
;
4555 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4558 c_parser_consume_token (parser
);
4559 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4560 if (c_parser_next_token_is (parser
, CPP_COLON
))
4562 c_parser_consume_token (parser
);
4563 label
= do_case (loc1
, exp1
, NULL_TREE
);
4565 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4567 c_parser_consume_token (parser
);
4568 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4569 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4570 label
= do_case (loc1
, exp1
, exp2
);
4573 c_parser_error (parser
, "expected %<:%> or %<...%>");
4575 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4577 c_parser_consume_token (parser
);
4578 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4579 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4583 tree name
= c_parser_peek_token (parser
)->value
;
4586 location_t loc2
= c_parser_peek_token (parser
)->location
;
4587 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4588 c_parser_consume_token (parser
);
4589 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4590 c_parser_consume_token (parser
);
4591 attrs
= c_parser_attributes (parser
);
4592 tlab
= define_label (loc2
, name
);
4595 decl_attributes (&tlab
, attrs
, 0);
4596 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4601 if (c_parser_next_tokens_start_declaration (parser
))
4603 error_at (c_parser_peek_token (parser
)->location
,
4604 "a label can only be part of a statement and "
4605 "a declaration is not a statement");
4606 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4607 /*static_assert_ok*/ true,
4608 /*empty_ok*/ true, /*nested*/ true,
4609 /*start_attr_ok*/ true, NULL
,
4615 /* Parse a statement (C90 6.6, C99 6.8).
4620 expression-statement
4628 expression-statement:
4631 selection-statement:
4635 iteration-statement:
4644 return expression[opt] ;
4657 objc-throw-statement
4658 objc-try-catch-statement
4659 objc-synchronized-statement
4661 objc-throw-statement:
4677 parallel-for-construct
4678 parallel-for-simd-construct
4679 parallel-sections-construct
4686 parallel-directive structured-block
4689 for-directive iteration-statement
4692 simd-directive iteration-statements
4695 for-simd-directive iteration-statements
4698 sections-directive section-scope
4701 single-directive structured-block
4703 parallel-for-construct:
4704 parallel-for-directive iteration-statement
4706 parallel-for-simd-construct:
4707 parallel-for-simd-directive iteration-statement
4709 parallel-sections-construct:
4710 parallel-sections-directive section-scope
4713 master-directive structured-block
4716 critical-directive structured-block
4719 atomic-directive expression-statement
4722 ordered-directive structured-block
4724 Transactional Memory:
4727 transaction-statement
4728 transaction-cancel-statement
4732 c_parser_statement (c_parser
*parser
)
4734 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4735 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4736 || (c_parser_next_token_is (parser
, CPP_NAME
)
4737 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4738 c_parser_label (parser
);
4739 c_parser_statement_after_labels (parser
);
4742 /* Parse a statement, other than a labeled statement. */
4745 c_parser_statement_after_labels (c_parser
*parser
)
4747 location_t loc
= c_parser_peek_token (parser
)->location
;
4748 tree stmt
= NULL_TREE
;
4749 bool in_if_block
= parser
->in_if_block
;
4750 parser
->in_if_block
= false;
4751 switch (c_parser_peek_token (parser
)->type
)
4753 case CPP_OPEN_BRACE
:
4754 add_stmt (c_parser_compound_statement (parser
));
4757 switch (c_parser_peek_token (parser
)->keyword
)
4760 c_parser_if_statement (parser
);
4763 c_parser_switch_statement (parser
);
4766 c_parser_while_statement (parser
, false);
4769 c_parser_do_statement (parser
, false);
4772 c_parser_for_statement (parser
, false);
4775 c_parser_consume_token (parser
);
4776 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4777 if (!flag_enable_cilkplus
)
4778 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4780 add_stmt (build_cilk_sync ());
4783 c_parser_consume_token (parser
);
4784 if (c_parser_next_token_is (parser
, CPP_NAME
))
4786 stmt
= c_finish_goto_label (loc
,
4787 c_parser_peek_token (parser
)->value
);
4788 c_parser_consume_token (parser
);
4790 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4794 c_parser_consume_token (parser
);
4795 val
= c_parser_expression (parser
);
4796 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4797 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4800 c_parser_error (parser
, "expected identifier or %<*%>");
4801 goto expect_semicolon
;
4803 c_parser_consume_token (parser
);
4804 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4805 goto expect_semicolon
;
4807 c_parser_consume_token (parser
);
4808 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4809 goto expect_semicolon
;
4811 c_parser_consume_token (parser
);
4812 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4814 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4815 c_parser_consume_token (parser
);
4819 struct c_expr expr
= c_parser_expression_conv (parser
);
4820 mark_exp_read (expr
.value
);
4821 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4822 goto expect_semicolon
;
4826 stmt
= c_parser_asm_statement (parser
);
4828 case RID_TRANSACTION_ATOMIC
:
4829 case RID_TRANSACTION_RELAXED
:
4830 stmt
= c_parser_transaction (parser
,
4831 c_parser_peek_token (parser
)->keyword
);
4833 case RID_TRANSACTION_CANCEL
:
4834 stmt
= c_parser_transaction_cancel (parser
);
4835 goto expect_semicolon
;
4837 gcc_assert (c_dialect_objc ());
4838 c_parser_consume_token (parser
);
4839 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4841 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4842 c_parser_consume_token (parser
);
4846 struct c_expr expr
= c_parser_expression (parser
);
4847 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
4848 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4849 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
4850 goto expect_semicolon
;
4854 gcc_assert (c_dialect_objc ());
4855 c_parser_objc_try_catch_finally_statement (parser
);
4857 case RID_AT_SYNCHRONIZED
:
4858 gcc_assert (c_dialect_objc ());
4859 c_parser_objc_synchronized_statement (parser
);
4866 c_parser_consume_token (parser
);
4868 case CPP_CLOSE_PAREN
:
4869 case CPP_CLOSE_SQUARE
:
4870 /* Avoid infinite loop in error recovery:
4871 c_parser_skip_until_found stops at a closing nesting
4872 delimiter without consuming it, but here we need to consume
4873 it to proceed further. */
4874 c_parser_error (parser
, "expected statement");
4875 c_parser_consume_token (parser
);
4878 c_parser_pragma (parser
, pragma_stmt
);
4882 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4884 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4887 /* Two cases cannot and do not have line numbers associated: If stmt
4888 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4889 cannot hold line numbers. But that's OK because the statement
4890 will either be changed to a MODIFY_EXPR during gimplification of
4891 the statement expr, or discarded. If stmt was compound, but
4892 without new variables, we will have skipped the creation of a
4893 BIND and will have a bare STATEMENT_LIST. But that's OK because
4894 (recursively) all of the component statements should already have
4895 line numbers assigned. ??? Can we discard no-op statements
4897 if (CAN_HAVE_LOCATION_P (stmt
)
4898 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4899 SET_EXPR_LOCATION (stmt
, loc
);
4901 parser
->in_if_block
= in_if_block
;
4904 /* Parse the condition from an if, do, while or for statements. */
4907 c_parser_condition (c_parser
*parser
)
4909 location_t loc
= c_parser_peek_token (parser
)->location
;
4911 cond
= c_parser_expression_conv (parser
).value
;
4912 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4913 cond
= c_fully_fold (cond
, false, NULL
);
4914 if (warn_sequence_point
)
4915 verify_sequence_points (cond
);
4919 /* Parse a parenthesized condition from an if, do or while statement.
4925 c_parser_paren_condition (c_parser
*parser
)
4928 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4929 return error_mark_node
;
4930 cond
= c_parser_condition (parser
);
4931 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4935 /* Parse a statement which is a block in C99. */
4938 c_parser_c99_block_statement (c_parser
*parser
)
4940 tree block
= c_begin_compound_stmt (flag_isoc99
);
4941 location_t loc
= c_parser_peek_token (parser
)->location
;
4942 c_parser_statement (parser
);
4943 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4946 /* Parse the body of an if statement. This is just parsing a
4947 statement but (a) it is a block in C99, (b) we track whether the
4948 body is an if statement for the sake of -Wparentheses warnings, (c)
4949 we handle an empty body specially for the sake of -Wempty-body
4950 warnings, and (d) we call parser_compound_statement directly
4951 because c_parser_statement_after_labels resets
4952 parser->in_if_block. */
4955 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4957 tree block
= c_begin_compound_stmt (flag_isoc99
);
4958 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4959 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4960 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4961 || (c_parser_next_token_is (parser
, CPP_NAME
)
4962 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4963 c_parser_label (parser
);
4964 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4965 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4967 location_t loc
= c_parser_peek_token (parser
)->location
;
4968 add_stmt (build_empty_stmt (loc
));
4969 c_parser_consume_token (parser
);
4970 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4971 warning_at (loc
, OPT_Wempty_body
,
4972 "suggest braces around empty body in an %<if%> statement");
4974 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4975 add_stmt (c_parser_compound_statement (parser
));
4977 c_parser_statement_after_labels (parser
);
4978 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4981 /* Parse the else body of an if statement. This is just parsing a
4982 statement but (a) it is a block in C99, (b) we handle an empty body
4983 specially for the sake of -Wempty-body warnings. */
4986 c_parser_else_body (c_parser
*parser
)
4988 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4989 tree block
= c_begin_compound_stmt (flag_isoc99
);
4990 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4991 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4992 || (c_parser_next_token_is (parser
, CPP_NAME
)
4993 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4994 c_parser_label (parser
);
4995 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4997 location_t loc
= c_parser_peek_token (parser
)->location
;
5000 "suggest braces around empty body in an %<else%> statement");
5001 add_stmt (build_empty_stmt (loc
));
5002 c_parser_consume_token (parser
);
5005 c_parser_statement_after_labels (parser
);
5006 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5009 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5012 if ( expression ) statement
5013 if ( expression ) statement else statement
5017 c_parser_if_statement (c_parser
*parser
)
5022 bool first_if
= false;
5023 tree first_body
, second_body
;
5027 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5028 c_parser_consume_token (parser
);
5029 block
= c_begin_compound_stmt (flag_isoc99
);
5030 loc
= c_parser_peek_token (parser
)->location
;
5031 cond
= c_parser_paren_condition (parser
);
5032 in_if_block
= parser
->in_if_block
;
5033 parser
->in_if_block
= true;
5034 first_body
= c_parser_if_body (parser
, &first_if
);
5035 parser
->in_if_block
= in_if_block
;
5036 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5038 c_parser_consume_token (parser
);
5039 second_body
= c_parser_else_body (parser
);
5042 second_body
= NULL_TREE
;
5043 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5044 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5046 /* If the if statement contains array notations, then we expand them. */
5047 if (flag_enable_cilkplus
&& contains_array_notation_expr (if_stmt
))
5048 if_stmt
= fix_conditional_array_notations (if_stmt
);
5052 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5055 switch (expression) statement
5059 c_parser_switch_statement (c_parser
*parser
)
5062 tree block
, expr
, body
, save_break
;
5063 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5064 location_t switch_cond_loc
;
5065 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5066 c_parser_consume_token (parser
);
5067 block
= c_begin_compound_stmt (flag_isoc99
);
5068 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5070 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5071 ce
= c_parser_expression (parser
);
5072 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5074 if (flag_enable_cilkplus
&& contains_array_notation_expr (expr
))
5076 error_at (switch_cond_loc
,
5077 "array notations cannot be used as a condition for switch "
5079 expr
= error_mark_node
;
5081 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5085 switch_cond_loc
= UNKNOWN_LOCATION
;
5086 expr
= error_mark_node
;
5088 c_start_case (switch_loc
, switch_cond_loc
, expr
);
5089 save_break
= c_break_label
;
5090 c_break_label
= NULL_TREE
;
5091 body
= c_parser_c99_block_statement (parser
);
5092 c_finish_case (body
);
5095 location_t here
= c_parser_peek_token (parser
)->location
;
5096 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5097 SET_EXPR_LOCATION (t
, here
);
5100 c_break_label
= save_break
;
5101 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5104 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5107 while (expression) statement
5111 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5113 tree block
, cond
, body
, save_break
, save_cont
;
5115 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5116 c_parser_consume_token (parser
);
5117 block
= c_begin_compound_stmt (flag_isoc99
);
5118 loc
= c_parser_peek_token (parser
)->location
;
5119 cond
= c_parser_paren_condition (parser
);
5120 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5122 error_at (loc
, "array notations cannot be used as a condition for while "
5124 cond
= error_mark_node
;
5127 if (ivdep
&& cond
!= error_mark_node
)
5128 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5129 build_int_cst (integer_type_node
,
5130 annot_expr_ivdep_kind
));
5131 save_break
= c_break_label
;
5132 c_break_label
= NULL_TREE
;
5133 save_cont
= c_cont_label
;
5134 c_cont_label
= NULL_TREE
;
5135 body
= c_parser_c99_block_statement (parser
);
5136 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5137 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5138 c_break_label
= save_break
;
5139 c_cont_label
= save_cont
;
5142 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5145 do statement while ( expression ) ;
5149 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5151 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5153 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5154 c_parser_consume_token (parser
);
5155 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5156 warning_at (c_parser_peek_token (parser
)->location
,
5158 "suggest braces around empty body in %<do%> statement");
5159 block
= c_begin_compound_stmt (flag_isoc99
);
5160 loc
= c_parser_peek_token (parser
)->location
;
5161 save_break
= c_break_label
;
5162 c_break_label
= NULL_TREE
;
5163 save_cont
= c_cont_label
;
5164 c_cont_label
= NULL_TREE
;
5165 body
= c_parser_c99_block_statement (parser
);
5166 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5167 new_break
= c_break_label
;
5168 c_break_label
= save_break
;
5169 new_cont
= c_cont_label
;
5170 c_cont_label
= save_cont
;
5171 cond
= c_parser_paren_condition (parser
);
5172 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5174 error_at (loc
, "array notations cannot be used as a condition for a "
5175 "do-while statement");
5176 cond
= error_mark_node
;
5178 if (ivdep
&& cond
!= error_mark_node
)
5179 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5180 build_int_cst (integer_type_node
,
5181 annot_expr_ivdep_kind
));
5182 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5183 c_parser_skip_to_end_of_block_or_statement (parser
);
5184 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5185 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5188 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5191 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5192 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5194 The form with a declaration is new in C99.
5196 ??? In accordance with the old parser, the declaration may be a
5197 nested function, which is then rejected in check_for_loop_decls,
5198 but does it make any sense for this to be included in the grammar?
5199 Note in particular that the nested function does not include a
5200 trailing ';', whereas the "declaration" production includes one.
5201 Also, can we reject bad declarations earlier and cheaper than
5202 check_for_loop_decls?
5204 In Objective-C, there are two additional variants:
5207 for ( expression in expresssion ) statement
5208 for ( declaration in expression ) statement
5210 This is inconsistent with C, because the second variant is allowed
5211 even if c99 is not enabled.
5213 The rest of the comment documents these Objective-C foreach-statement.
5215 Here is the canonical example of the first variant:
5216 for (object in array) { do something with object }
5217 we call the first expression ("object") the "object_expression" and
5218 the second expression ("array") the "collection_expression".
5219 object_expression must be an lvalue of type "id" (a generic Objective-C
5220 object) because the loop works by assigning to object_expression the
5221 various objects from the collection_expression. collection_expression
5222 must evaluate to something of type "id" which responds to the method
5223 countByEnumeratingWithState:objects:count:.
5225 The canonical example of the second variant is:
5226 for (id object in array) { do something with object }
5227 which is completely equivalent to
5230 for (object in array) { do something with object }
5232 Note that initizializing 'object' in some way (eg, "for ((object =
5233 xxx) in array) { do something with object }") is possibly
5234 technically valid, but completely pointless as 'object' will be
5235 assigned to something else as soon as the loop starts. We should
5236 most likely reject it (TODO).
5238 The beginning of the Objective-C foreach-statement looks exactly
5239 like the beginning of the for-statement, and we can tell it is a
5240 foreach-statement only because the initial declaration or
5241 expression is terminated by 'in' instead of ';'.
5245 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5247 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5248 /* The following are only used when parsing an ObjC foreach statement. */
5249 tree object_expression
;
5250 /* Silence the bogus uninitialized warning. */
5251 tree collection_expression
= NULL
;
5252 location_t loc
= c_parser_peek_token (parser
)->location
;
5253 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5254 bool is_foreach_statement
= false;
5255 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5256 c_parser_consume_token (parser
);
5257 /* Open a compound statement in Objective-C as well, just in case this is
5258 as foreach expression. */
5259 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5260 cond
= error_mark_node
;
5261 incr
= error_mark_node
;
5262 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5264 /* Parse the initialization declaration or expression. */
5265 object_expression
= error_mark_node
;
5266 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5267 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5269 parser
->objc_could_be_foreach_context
= false;
5270 c_parser_consume_token (parser
);
5271 c_finish_expr_stmt (loc
, NULL_TREE
);
5273 else if (c_parser_next_tokens_start_declaration (parser
))
5275 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5276 &object_expression
, vNULL
);
5277 parser
->objc_could_be_foreach_context
= false;
5279 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5281 c_parser_consume_token (parser
);
5282 is_foreach_statement
= true;
5283 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5284 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5287 check_for_loop_decls (for_loc
, flag_isoc99
);
5289 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5291 /* __extension__ can start a declaration, but is also an
5292 unary operator that can start an expression. Consume all
5293 but the last of a possible series of __extension__ to
5295 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5296 && (c_parser_peek_2nd_token (parser
)->keyword
5298 c_parser_consume_token (parser
);
5299 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5302 ext
= disable_extension_diagnostics ();
5303 c_parser_consume_token (parser
);
5304 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5305 true, &object_expression
, vNULL
);
5306 parser
->objc_could_be_foreach_context
= false;
5308 restore_extension_diagnostics (ext
);
5309 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5311 c_parser_consume_token (parser
);
5312 is_foreach_statement
= true;
5313 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5314 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5317 check_for_loop_decls (for_loc
, flag_isoc99
);
5327 tree init_expression
;
5328 ce
= c_parser_expression (parser
);
5329 init_expression
= ce
.value
;
5330 parser
->objc_could_be_foreach_context
= false;
5331 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5333 c_parser_consume_token (parser
);
5334 is_foreach_statement
= true;
5335 if (! lvalue_p (init_expression
))
5336 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5337 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5341 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5342 init_expression
= ce
.value
;
5343 c_finish_expr_stmt (loc
, init_expression
);
5344 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5348 /* Parse the loop condition. In the case of a foreach
5349 statement, there is no loop condition. */
5350 gcc_assert (!parser
->objc_could_be_foreach_context
);
5351 if (!is_foreach_statement
)
5353 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5357 c_parser_error (parser
, "missing loop condition in loop with "
5358 "%<GCC ivdep%> pragma");
5359 cond
= error_mark_node
;
5363 c_parser_consume_token (parser
);
5369 cond
= c_parser_condition (parser
);
5370 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5372 error_at (loc
, "array notations cannot be used in a "
5373 "condition for a for-loop");
5374 cond
= error_mark_node
;
5376 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5379 if (ivdep
&& cond
!= error_mark_node
)
5380 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5381 build_int_cst (integer_type_node
,
5382 annot_expr_ivdep_kind
));
5384 /* Parse the increment expression (the third expression in a
5385 for-statement). In the case of a foreach-statement, this is
5386 the expression that follows the 'in'. */
5387 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5389 if (is_foreach_statement
)
5391 c_parser_error (parser
, "missing collection in fast enumeration");
5392 collection_expression
= error_mark_node
;
5395 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5399 if (is_foreach_statement
)
5400 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5404 struct c_expr ce
= c_parser_expression (parser
);
5405 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5406 incr
= c_process_expr_stmt (loc
, ce
.value
);
5409 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5411 save_break
= c_break_label
;
5412 c_break_label
= NULL_TREE
;
5413 save_cont
= c_cont_label
;
5414 c_cont_label
= NULL_TREE
;
5415 body
= c_parser_c99_block_statement (parser
);
5416 if (is_foreach_statement
)
5417 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5419 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5420 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5421 c_break_label
= save_break
;
5422 c_cont_label
= save_cont
;
5425 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5426 statement with inputs, outputs, clobbers, and volatile tag
5430 asm type-qualifier[opt] ( asm-argument ) ;
5431 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5435 asm-string-literal : asm-operands[opt]
5436 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5437 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5440 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5443 Qualifiers other than volatile are accepted in the syntax but
5447 c_parser_asm_statement (c_parser
*parser
)
5449 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5450 bool simple
, is_goto
;
5451 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5452 int section
, nsections
;
5454 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5455 c_parser_consume_token (parser
);
5456 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5458 quals
= c_parser_peek_token (parser
)->value
;
5459 c_parser_consume_token (parser
);
5461 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5462 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5464 warning_at (c_parser_peek_token (parser
)->location
,
5466 "%E qualifier ignored on asm",
5467 c_parser_peek_token (parser
)->value
);
5469 c_parser_consume_token (parser
);
5475 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5477 c_parser_consume_token (parser
);
5481 /* ??? Follow the C++ parser rather than using the
5482 lex_untranslated_string kludge. */
5483 parser
->lex_untranslated_string
= true;
5486 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5489 str
= c_parser_asm_string_literal (parser
);
5490 if (str
== NULL_TREE
)
5491 goto error_close_paren
;
5494 outputs
= NULL_TREE
;
5496 clobbers
= NULL_TREE
;
5499 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5502 /* Parse each colon-delimited section of operands. */
5503 nsections
= 3 + is_goto
;
5504 for (section
= 0; section
< nsections
; ++section
)
5506 if (!c_parser_require (parser
, CPP_COLON
,
5509 : "expected %<:%> or %<)%>"))
5510 goto error_close_paren
;
5512 /* Once past any colon, we're no longer a simple asm. */
5515 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5516 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5521 /* For asm goto, we don't allow output operands, but reserve
5522 the slot for a future extension that does allow them. */
5524 outputs
= c_parser_asm_operands (parser
);
5527 inputs
= c_parser_asm_operands (parser
);
5530 clobbers
= c_parser_asm_clobbers (parser
);
5533 labels
= c_parser_asm_goto_operands (parser
);
5539 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5544 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5546 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5550 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5551 c_parser_skip_to_end_of_block_or_statement (parser
);
5553 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5554 clobbers
, labels
, simple
));
5557 parser
->lex_untranslated_string
= false;
5561 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5565 /* Parse asm operands, a GNU extension.
5569 asm-operands , asm-operand
5572 asm-string-literal ( expression )
5573 [ identifier ] asm-string-literal ( expression )
5577 c_parser_asm_operands (c_parser
*parser
)
5579 tree list
= NULL_TREE
;
5584 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5586 c_parser_consume_token (parser
);
5587 if (c_parser_next_token_is (parser
, CPP_NAME
))
5589 tree id
= c_parser_peek_token (parser
)->value
;
5590 c_parser_consume_token (parser
);
5591 name
= build_string (IDENTIFIER_LENGTH (id
),
5592 IDENTIFIER_POINTER (id
));
5596 c_parser_error (parser
, "expected identifier");
5597 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5600 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5605 str
= c_parser_asm_string_literal (parser
);
5606 if (str
== NULL_TREE
)
5608 parser
->lex_untranslated_string
= false;
5609 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5611 parser
->lex_untranslated_string
= true;
5614 expr
= c_parser_expression (parser
);
5615 mark_exp_read (expr
.value
);
5616 parser
->lex_untranslated_string
= true;
5617 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5619 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5622 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5624 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5625 c_parser_consume_token (parser
);
5632 /* Parse asm clobbers, a GNU extension.
5636 asm-clobbers , asm-string-literal
5640 c_parser_asm_clobbers (c_parser
*parser
)
5642 tree list
= NULL_TREE
;
5645 tree str
= c_parser_asm_string_literal (parser
);
5647 list
= tree_cons (NULL_TREE
, str
, list
);
5650 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5651 c_parser_consume_token (parser
);
5658 /* Parse asm goto labels, a GNU extension.
5662 asm-goto-operands , identifier
5666 c_parser_asm_goto_operands (c_parser
*parser
)
5668 tree list
= NULL_TREE
;
5673 if (c_parser_next_token_is (parser
, CPP_NAME
))
5675 c_token
*tok
= c_parser_peek_token (parser
);
5677 label
= lookup_label_for_goto (tok
->location
, name
);
5678 c_parser_consume_token (parser
);
5679 TREE_USED (label
) = 1;
5683 c_parser_error (parser
, "expected identifier");
5687 name
= build_string (IDENTIFIER_LENGTH (name
),
5688 IDENTIFIER_POINTER (name
));
5689 list
= tree_cons (name
, label
, list
);
5690 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5691 c_parser_consume_token (parser
);
5693 return nreverse (list
);
5697 /* Parse an expression other than a compound expression; that is, an
5698 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5699 NULL then it is an Objective-C message expression which is the
5700 primary-expression starting the expression as an initializer.
5702 assignment-expression:
5703 conditional-expression
5704 unary-expression assignment-operator assignment-expression
5706 assignment-operator: one of
5707 = *= /= %= += -= <<= >>= &= ^= |=
5709 In GNU C we accept any conditional expression on the LHS and
5710 diagnose the invalid lvalue rather than producing a syntax
5713 static struct c_expr
5714 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5715 tree omp_atomic_lhs
)
5717 struct c_expr lhs
, rhs
, ret
;
5718 enum tree_code code
;
5719 location_t op_location
, exp_location
;
5720 gcc_assert (!after
|| c_dialect_objc ());
5721 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5722 op_location
= c_parser_peek_token (parser
)->location
;
5723 switch (c_parser_peek_token (parser
)->type
)
5732 code
= TRUNC_DIV_EXPR
;
5735 code
= TRUNC_MOD_EXPR
;
5750 code
= BIT_AND_EXPR
;
5753 code
= BIT_XOR_EXPR
;
5756 code
= BIT_IOR_EXPR
;
5761 c_parser_consume_token (parser
);
5762 exp_location
= c_parser_peek_token (parser
)->location
;
5763 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5764 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5766 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5767 code
, exp_location
, rhs
.value
,
5769 if (code
== NOP_EXPR
)
5770 ret
.original_code
= MODIFY_EXPR
;
5773 TREE_NO_WARNING (ret
.value
) = 1;
5774 ret
.original_code
= ERROR_MARK
;
5776 ret
.original_type
= NULL
;
5780 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5781 is not NULL then it is an Objective-C message expression which is
5782 the primary-expression starting the expression as an initializer.
5784 conditional-expression:
5785 logical-OR-expression
5786 logical-OR-expression ? expression : conditional-expression
5790 conditional-expression:
5791 logical-OR-expression ? : conditional-expression
5794 static struct c_expr
5795 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5796 tree omp_atomic_lhs
)
5798 struct c_expr cond
, exp1
, exp2
, ret
;
5799 location_t cond_loc
, colon_loc
, middle_loc
;
5801 gcc_assert (!after
|| c_dialect_objc ());
5803 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5805 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5807 cond_loc
= c_parser_peek_token (parser
)->location
;
5808 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5809 c_parser_consume_token (parser
);
5810 if (c_parser_next_token_is (parser
, CPP_COLON
))
5812 tree eptype
= NULL_TREE
;
5814 middle_loc
= c_parser_peek_token (parser
)->location
;
5815 pedwarn (middle_loc
, OPT_Wpedantic
,
5816 "ISO C forbids omitting the middle term of a ?: expression");
5817 warn_for_omitted_condop (middle_loc
, cond
.value
);
5818 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5820 eptype
= TREE_TYPE (cond
.value
);
5821 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5823 /* Make sure first operand is calculated only once. */
5824 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5826 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5827 exp1
.original_type
= NULL
;
5828 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5829 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5834 = c_objc_common_truthvalue_conversion
5835 (cond_loc
, default_conversion (cond
.value
));
5836 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5837 exp1
= c_parser_expression_conv (parser
);
5838 mark_exp_read (exp1
.value
);
5839 c_inhibit_evaluation_warnings
+=
5840 ((cond
.value
== truthvalue_true_node
)
5841 - (cond
.value
== truthvalue_false_node
));
5844 colon_loc
= c_parser_peek_token (parser
)->location
;
5845 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5847 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5848 ret
.value
= error_mark_node
;
5849 ret
.original_code
= ERROR_MARK
;
5850 ret
.original_type
= NULL
;
5854 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5855 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5856 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
5858 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5859 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5860 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5861 exp1
.value
, exp1
.original_type
,
5862 exp2
.value
, exp2
.original_type
);
5863 ret
.original_code
= ERROR_MARK
;
5864 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5865 ret
.original_type
= NULL
;
5870 /* If both sides are enum type, the default conversion will have
5871 made the type of the result be an integer type. We want to
5872 remember the enum types we started with. */
5873 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5874 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5875 ret
.original_type
= ((t1
!= error_mark_node
5876 && t2
!= error_mark_node
5877 && (TYPE_MAIN_VARIANT (t1
)
5878 == TYPE_MAIN_VARIANT (t2
)))
5885 /* Parse a binary expression; that is, a logical-OR-expression (C90
5886 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5887 an Objective-C message expression which is the primary-expression
5888 starting the expression as an initializer.
5890 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
5891 when it should be the unfolded lhs. In a valid OpenMP source,
5892 one of the operands of the toplevel binary expression must be equal
5893 to it. In that case, just return a build2 created binary operation
5894 rather than result of parser_build_binary_op.
5896 multiplicative-expression:
5898 multiplicative-expression * cast-expression
5899 multiplicative-expression / cast-expression
5900 multiplicative-expression % cast-expression
5902 additive-expression:
5903 multiplicative-expression
5904 additive-expression + multiplicative-expression
5905 additive-expression - multiplicative-expression
5909 shift-expression << additive-expression
5910 shift-expression >> additive-expression
5912 relational-expression:
5914 relational-expression < shift-expression
5915 relational-expression > shift-expression
5916 relational-expression <= shift-expression
5917 relational-expression >= shift-expression
5919 equality-expression:
5920 relational-expression
5921 equality-expression == relational-expression
5922 equality-expression != relational-expression
5926 AND-expression & equality-expression
5928 exclusive-OR-expression:
5930 exclusive-OR-expression ^ AND-expression
5932 inclusive-OR-expression:
5933 exclusive-OR-expression
5934 inclusive-OR-expression | exclusive-OR-expression
5936 logical-AND-expression:
5937 inclusive-OR-expression
5938 logical-AND-expression && inclusive-OR-expression
5940 logical-OR-expression:
5941 logical-AND-expression
5942 logical-OR-expression || logical-AND-expression
5945 static struct c_expr
5946 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5947 tree omp_atomic_lhs
)
5949 /* A binary expression is parsed using operator-precedence parsing,
5950 with the operands being cast expressions. All the binary
5951 operators are left-associative. Thus a binary expression is of
5954 E0 op1 E1 op2 E2 ...
5956 which we represent on a stack. On the stack, the precedence
5957 levels are strictly increasing. When a new operator is
5958 encountered of higher precedence than that at the top of the
5959 stack, it is pushed; its LHS is the top expression, and its RHS
5960 is everything parsed until it is popped. When a new operator is
5961 encountered with precedence less than or equal to that at the top
5962 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5963 by the result of the operation until the operator at the top of
5964 the stack has lower precedence than the new operator or there is
5965 only one element on the stack; then the top expression is the LHS
5966 of the new operator. In the case of logical AND and OR
5967 expressions, we also need to adjust c_inhibit_evaluation_warnings
5968 as appropriate when the operators are pushed and popped. */
5971 /* The expression at this stack level. */
5973 /* The precedence of the operator on its left, PREC_NONE at the
5974 bottom of the stack. */
5975 enum c_parser_prec prec
;
5976 /* The operation on its left. */
5978 /* The source location of this operation. */
5982 /* Location of the binary operator. */
5983 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5986 switch (stack[sp].op) \
5988 case TRUTH_ANDIF_EXPR: \
5989 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5990 == truthvalue_false_node); \
5992 case TRUTH_ORIF_EXPR: \
5993 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5994 == truthvalue_true_node); \
5999 stack[sp - 1].expr \
6000 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6001 stack[sp - 1].expr, true, true); \
6003 = convert_lvalue_to_rvalue (stack[sp].loc, \
6004 stack[sp].expr, true, true); \
6005 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6006 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6007 && ((1 << stack[sp].prec) \
6008 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6009 | PREC_ADD | PREC_MULT))) \
6010 && stack[sp].op != TRUNC_MOD_EXPR \
6011 && stack[0].expr.value != error_mark_node \
6012 && stack[1].expr.value != error_mark_node \
6013 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6014 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6015 stack[0].expr.value \
6016 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6017 stack[0].expr.value, stack[1].expr.value); \
6019 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6021 stack[sp - 1].expr, \
6025 gcc_assert (!after
|| c_dialect_objc ());
6026 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6027 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6028 stack
[0].prec
= PREC_NONE
;
6032 enum c_parser_prec oprec
;
6033 enum tree_code ocode
;
6036 switch (c_parser_peek_token (parser
)->type
)
6044 ocode
= TRUNC_DIV_EXPR
;
6048 ocode
= TRUNC_MOD_EXPR
;
6060 ocode
= LSHIFT_EXPR
;
6064 ocode
= RSHIFT_EXPR
;
6078 case CPP_GREATER_EQ
:
6091 oprec
= PREC_BITAND
;
6092 ocode
= BIT_AND_EXPR
;
6095 oprec
= PREC_BITXOR
;
6096 ocode
= BIT_XOR_EXPR
;
6100 ocode
= BIT_IOR_EXPR
;
6103 oprec
= PREC_LOGAND
;
6104 ocode
= TRUTH_ANDIF_EXPR
;
6108 ocode
= TRUTH_ORIF_EXPR
;
6111 /* Not a binary operator, so end of the binary
6115 binary_loc
= c_parser_peek_token (parser
)->location
;
6116 while (oprec
<= stack
[sp
].prec
)
6118 c_parser_consume_token (parser
);
6121 case TRUTH_ANDIF_EXPR
:
6123 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6124 stack
[sp
].expr
, true, true);
6125 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6126 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6127 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6128 == truthvalue_false_node
);
6130 case TRUTH_ORIF_EXPR
:
6132 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6133 stack
[sp
].expr
, true, true);
6134 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6135 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6136 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6137 == truthvalue_true_node
);
6143 stack
[sp
].loc
= binary_loc
;
6144 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6145 stack
[sp
].prec
= oprec
;
6146 stack
[sp
].op
= ocode
;
6147 stack
[sp
].loc
= binary_loc
;
6152 return stack
[0].expr
;
6156 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6157 NULL then it is an Objective-C message expression which is the
6158 primary-expression starting the expression as an initializer.
6162 ( type-name ) unary-expression
6165 static struct c_expr
6166 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6168 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6169 gcc_assert (!after
|| c_dialect_objc ());
6171 return c_parser_postfix_expression_after_primary (parser
,
6173 /* If the expression begins with a parenthesized type name, it may
6174 be either a cast or a compound literal; we need to see whether
6175 the next character is '{' to tell the difference. If not, it is
6176 an unary expression. Full detection of unknown typenames here
6177 would require a 3-token lookahead. */
6178 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6179 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6181 struct c_type_name
*type_name
;
6184 c_parser_consume_token (parser
);
6185 type_name
= c_parser_type_name (parser
);
6186 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6187 if (type_name
== NULL
)
6189 ret
.value
= error_mark_node
;
6190 ret
.original_code
= ERROR_MARK
;
6191 ret
.original_type
= NULL
;
6195 /* Save casted types in the function's used types hash table. */
6196 used_types_insert (type_name
->specs
->type
);
6198 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6199 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6202 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6203 expr
= c_parser_cast_expression (parser
, NULL
);
6204 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6206 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6207 ret
.original_code
= ERROR_MARK
;
6208 ret
.original_type
= NULL
;
6212 return c_parser_unary_expression (parser
);
6215 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6221 unary-operator cast-expression
6222 sizeof unary-expression
6223 sizeof ( type-name )
6225 unary-operator: one of
6231 __alignof__ unary-expression
6232 __alignof__ ( type-name )
6235 (C11 permits _Alignof with type names only.)
6237 unary-operator: one of
6238 __extension__ __real__ __imag__
6240 Transactional Memory:
6243 transaction-expression
6245 In addition, the GNU syntax treats ++ and -- as unary operators, so
6246 they may be applied to cast expressions with errors for non-lvalues
6249 static struct c_expr
6250 c_parser_unary_expression (c_parser
*parser
)
6253 struct c_expr ret
, op
;
6254 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6256 ret
.original_code
= ERROR_MARK
;
6257 ret
.original_type
= NULL
;
6258 switch (c_parser_peek_token (parser
)->type
)
6261 c_parser_consume_token (parser
);
6262 exp_loc
= c_parser_peek_token (parser
)->location
;
6263 op
= c_parser_cast_expression (parser
, NULL
);
6265 /* If there is array notations in op, we expand them. */
6266 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6267 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6270 op
= default_function_array_read_conversion (exp_loc
, op
);
6271 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6273 case CPP_MINUS_MINUS
:
6274 c_parser_consume_token (parser
);
6275 exp_loc
= c_parser_peek_token (parser
)->location
;
6276 op
= c_parser_cast_expression (parser
, NULL
);
6278 /* If there is array notations in op, we expand them. */
6279 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6280 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6283 op
= default_function_array_read_conversion (exp_loc
, op
);
6284 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6287 c_parser_consume_token (parser
);
6288 op
= c_parser_cast_expression (parser
, NULL
);
6289 mark_exp_read (op
.value
);
6290 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6292 c_parser_consume_token (parser
);
6293 exp_loc
= c_parser_peek_token (parser
)->location
;
6294 op
= c_parser_cast_expression (parser
, NULL
);
6295 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6296 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6299 if (!c_dialect_objc () && !in_system_header
)
6302 "traditional C rejects the unary plus operator");
6303 c_parser_consume_token (parser
);
6304 exp_loc
= c_parser_peek_token (parser
)->location
;
6305 op
= c_parser_cast_expression (parser
, NULL
);
6306 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6307 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6309 c_parser_consume_token (parser
);
6310 exp_loc
= c_parser_peek_token (parser
)->location
;
6311 op
= c_parser_cast_expression (parser
, NULL
);
6312 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6313 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6315 c_parser_consume_token (parser
);
6316 exp_loc
= c_parser_peek_token (parser
)->location
;
6317 op
= c_parser_cast_expression (parser
, NULL
);
6318 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6319 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6321 c_parser_consume_token (parser
);
6322 exp_loc
= c_parser_peek_token (parser
)->location
;
6323 op
= c_parser_cast_expression (parser
, NULL
);
6324 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6325 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6327 /* Refer to the address of a label as a pointer. */
6328 c_parser_consume_token (parser
);
6329 if (c_parser_next_token_is (parser
, CPP_NAME
))
6331 ret
.value
= finish_label_address_expr
6332 (c_parser_peek_token (parser
)->value
, op_loc
);
6333 c_parser_consume_token (parser
);
6337 c_parser_error (parser
, "expected identifier");
6338 ret
.value
= error_mark_node
;
6342 switch (c_parser_peek_token (parser
)->keyword
)
6345 return c_parser_sizeof_expression (parser
);
6347 return c_parser_alignof_expression (parser
);
6349 c_parser_consume_token (parser
);
6350 ext
= disable_extension_diagnostics ();
6351 ret
= c_parser_cast_expression (parser
, NULL
);
6352 restore_extension_diagnostics (ext
);
6355 c_parser_consume_token (parser
);
6356 exp_loc
= c_parser_peek_token (parser
)->location
;
6357 op
= c_parser_cast_expression (parser
, NULL
);
6358 op
= default_function_array_conversion (exp_loc
, op
);
6359 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6361 c_parser_consume_token (parser
);
6362 exp_loc
= c_parser_peek_token (parser
)->location
;
6363 op
= c_parser_cast_expression (parser
, NULL
);
6364 op
= default_function_array_conversion (exp_loc
, op
);
6365 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6366 case RID_TRANSACTION_ATOMIC
:
6367 case RID_TRANSACTION_RELAXED
:
6368 return c_parser_transaction_expression (parser
,
6369 c_parser_peek_token (parser
)->keyword
);
6371 return c_parser_postfix_expression (parser
);
6374 return c_parser_postfix_expression (parser
);
6378 /* Parse a sizeof expression. */
6380 static struct c_expr
6381 c_parser_sizeof_expression (c_parser
*parser
)
6384 location_t expr_loc
;
6385 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6386 c_parser_consume_token (parser
);
6387 c_inhibit_evaluation_warnings
++;
6389 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6390 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6392 /* Either sizeof ( type-name ) or sizeof unary-expression
6393 starting with a compound literal. */
6394 struct c_type_name
*type_name
;
6395 c_parser_consume_token (parser
);
6396 expr_loc
= c_parser_peek_token (parser
)->location
;
6397 type_name
= c_parser_type_name (parser
);
6398 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6399 if (type_name
== NULL
)
6402 c_inhibit_evaluation_warnings
--;
6404 ret
.value
= error_mark_node
;
6405 ret
.original_code
= ERROR_MARK
;
6406 ret
.original_type
= NULL
;
6409 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6411 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6416 /* sizeof ( type-name ). */
6417 c_inhibit_evaluation_warnings
--;
6419 return c_expr_sizeof_type (expr_loc
, type_name
);
6423 expr_loc
= c_parser_peek_token (parser
)->location
;
6424 expr
= c_parser_unary_expression (parser
);
6426 c_inhibit_evaluation_warnings
--;
6428 mark_exp_read (expr
.value
);
6429 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6430 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6431 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6432 return c_expr_sizeof_expr (expr_loc
, expr
);
6436 /* Parse an alignof expression. */
6438 static struct c_expr
6439 c_parser_alignof_expression (c_parser
*parser
)
6442 location_t loc
= c_parser_peek_token (parser
)->location
;
6443 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6444 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6445 /* A diagnostic is not required for the use of this identifier in
6446 the implementation namespace; only diagnose it for the C11
6447 spelling because of existing code using the other spellings. */
6449 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6452 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6455 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6458 c_parser_consume_token (parser
);
6459 c_inhibit_evaluation_warnings
++;
6461 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6462 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6464 /* Either __alignof__ ( type-name ) or __alignof__
6465 unary-expression starting with a compound literal. */
6467 struct c_type_name
*type_name
;
6469 c_parser_consume_token (parser
);
6470 loc
= c_parser_peek_token (parser
)->location
;
6471 type_name
= c_parser_type_name (parser
);
6472 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6473 if (type_name
== NULL
)
6476 c_inhibit_evaluation_warnings
--;
6478 ret
.value
= error_mark_node
;
6479 ret
.original_code
= ERROR_MARK
;
6480 ret
.original_type
= NULL
;
6483 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6485 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6490 /* alignof ( type-name ). */
6491 c_inhibit_evaluation_warnings
--;
6493 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6494 ret
.original_code
= ERROR_MARK
;
6495 ret
.original_type
= NULL
;
6501 expr
= c_parser_unary_expression (parser
);
6503 mark_exp_read (expr
.value
);
6504 c_inhibit_evaluation_warnings
--;
6506 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6508 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6509 ret
.original_code
= ERROR_MARK
;
6510 ret
.original_type
= NULL
;
6515 /* Helper function to read arguments of builtins which are interfaces
6516 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6517 others. The name of the builtin is passed using BNAME parameter.
6518 Function returns true if there were no errors while parsing and
6519 stores the arguments in CEXPR_LIST. */
6521 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6522 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6525 location_t loc
= c_parser_peek_token (parser
)->location
;
6526 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6528 bool saved_force_folding_builtin_constant_p
;
6530 *ret_cexpr_list
= NULL
;
6531 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6533 error_at (loc
, "cannot take address of %qs", bname
);
6537 c_parser_consume_token (parser
);
6539 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6541 c_parser_consume_token (parser
);
6545 saved_force_folding_builtin_constant_p
6546 = force_folding_builtin_constant_p
;
6547 force_folding_builtin_constant_p
|= choose_expr_p
;
6548 expr
= c_parser_expr_no_commas (parser
, NULL
);
6549 force_folding_builtin_constant_p
6550 = saved_force_folding_builtin_constant_p
;
6551 vec_alloc (cexpr_list
, 1);
6552 C_EXPR_APPEND (cexpr_list
, expr
);
6553 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6555 c_parser_consume_token (parser
);
6556 expr
= c_parser_expr_no_commas (parser
, NULL
);
6557 C_EXPR_APPEND (cexpr_list
, expr
);
6560 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6563 *ret_cexpr_list
= cexpr_list
;
6567 /* This represents a single generic-association. */
6569 struct c_generic_association
6571 /* The location of the starting token of the type. */
6572 location_t type_location
;
6573 /* The association's type, or NULL_TREE for 'default'. */
6575 /* The association's expression. */
6576 struct c_expr expression
;
6579 /* Parse a generic-selection. (C11 6.5.1.1).
6582 _Generic ( assignment-expression , generic-assoc-list )
6586 generic-assoc-list , generic-association
6588 generic-association:
6589 type-name : assignment-expression
6590 default : assignment-expression
6593 static struct c_expr
6594 c_parser_generic_selection (c_parser
*parser
)
6596 vec
<c_generic_association
> associations
= vNULL
;
6597 struct c_expr selector
, error_expr
;
6599 struct c_generic_association matched_assoc
;
6600 bool match_found
= false;
6601 location_t generic_loc
, selector_loc
;
6603 error_expr
.original_code
= ERROR_MARK
;
6604 error_expr
.original_type
= NULL
;
6605 error_expr
.value
= error_mark_node
;
6606 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6607 matched_assoc
.type
= NULL_TREE
;
6608 matched_assoc
.expression
= error_expr
;
6610 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6611 generic_loc
= c_parser_peek_token (parser
)->location
;
6612 c_parser_consume_token (parser
);
6616 pedwarn (generic_loc
, OPT_Wpedantic
,
6617 "ISO C99 does not support %<_Generic%>");
6619 pedwarn (generic_loc
, OPT_Wpedantic
,
6620 "ISO C90 does not support %<_Generic%>");
6623 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6626 c_inhibit_evaluation_warnings
++;
6627 selector_loc
= c_parser_peek_token (parser
)->location
;
6628 selector
= c_parser_expr_no_commas (parser
, NULL
);
6629 selector
= default_function_array_conversion (selector_loc
, selector
);
6630 c_inhibit_evaluation_warnings
--;
6632 if (selector
.value
== error_mark_node
)
6634 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6637 selector_type
= TREE_TYPE (selector
.value
);
6638 /* In ISO C terms, rvalues (including the controlling expression of
6639 _Generic) do not have qualified types. */
6640 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6641 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6642 /* In ISO C terms, _Noreturn is not part of the type of expressions
6643 such as &abort, but in GCC it is represented internally as a type
6645 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6646 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6648 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6650 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6652 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6658 struct c_generic_association assoc
, *iter
;
6660 c_token
*token
= c_parser_peek_token (parser
);
6662 assoc
.type_location
= token
->location
;
6663 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6665 c_parser_consume_token (parser
);
6666 assoc
.type
= NULL_TREE
;
6670 struct c_type_name
*type_name
;
6672 type_name
= c_parser_type_name (parser
);
6673 if (type_name
== NULL
)
6675 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6678 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6679 if (assoc
.type
== error_mark_node
)
6681 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6685 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6686 error_at (assoc
.type_location
,
6687 "%<_Generic%> association has function type");
6688 else if (!COMPLETE_TYPE_P (assoc
.type
))
6689 error_at (assoc
.type_location
,
6690 "%<_Generic%> association has incomplete type");
6692 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6693 error_at (assoc
.type_location
,
6694 "%<_Generic%> association has "
6695 "variable length type");
6698 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6700 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6704 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6705 if (assoc
.expression
.value
== error_mark_node
)
6707 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6711 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6713 if (assoc
.type
== NULL_TREE
)
6715 if (iter
->type
== NULL_TREE
)
6717 error_at (assoc
.type_location
,
6718 "duplicate %<default%> case in %<_Generic%>");
6719 inform (iter
->type_location
, "original %<default%> is here");
6722 else if (iter
->type
!= NULL_TREE
)
6724 if (comptypes (assoc
.type
, iter
->type
))
6726 error_at (assoc
.type_location
,
6727 "%<_Generic%> specifies two compatible types");
6728 inform (iter
->type_location
, "compatible type is here");
6733 if (assoc
.type
== NULL_TREE
)
6737 matched_assoc
= assoc
;
6741 else if (comptypes (assoc
.type
, selector_type
))
6743 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6745 matched_assoc
= assoc
;
6750 error_at (assoc
.type_location
,
6751 "%<_Generic> selector matches multiple associations");
6752 inform (matched_assoc
.type_location
,
6753 "other match is here");
6757 associations
.safe_push (assoc
);
6759 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6761 c_parser_consume_token (parser
);
6764 associations
.release ();
6766 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6768 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6774 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6775 "compatible with any association",
6780 return matched_assoc
.expression
;
6783 associations
.release ();
6787 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6791 postfix-expression [ expression ]
6792 postfix-expression ( argument-expression-list[opt] )
6793 postfix-expression . identifier
6794 postfix-expression -> identifier
6795 postfix-expression ++
6796 postfix-expression --
6797 ( type-name ) { initializer-list }
6798 ( type-name ) { initializer-list , }
6800 argument-expression-list:
6802 argument-expression-list , argument-expression
6815 (treated as a keyword in GNU C)
6818 ( compound-statement )
6819 __builtin_va_arg ( assignment-expression , type-name )
6820 __builtin_offsetof ( type-name , offsetof-member-designator )
6821 __builtin_choose_expr ( assignment-expression ,
6822 assignment-expression ,
6823 assignment-expression )
6824 __builtin_types_compatible_p ( type-name , type-name )
6825 __builtin_complex ( assignment-expression , assignment-expression )
6826 __builtin_shuffle ( assignment-expression , assignment-expression )
6827 __builtin_shuffle ( assignment-expression ,
6828 assignment-expression ,
6829 assignment-expression, )
6831 offsetof-member-designator:
6833 offsetof-member-designator . identifier
6834 offsetof-member-designator [ expression ]
6839 [ objc-receiver objc-message-args ]
6840 @selector ( objc-selector-arg )
6841 @protocol ( identifier )
6842 @encode ( type-name )
6844 Classname . identifier
6847 static struct c_expr
6848 c_parser_postfix_expression (c_parser
*parser
)
6850 struct c_expr expr
, e1
;
6851 struct c_type_name
*t1
, *t2
;
6852 location_t loc
= c_parser_peek_token (parser
)->location
;;
6853 expr
.original_code
= ERROR_MARK
;
6854 expr
.original_type
= NULL
;
6855 switch (c_parser_peek_token (parser
)->type
)
6858 expr
.value
= c_parser_peek_token (parser
)->value
;
6859 loc
= c_parser_peek_token (parser
)->location
;
6860 c_parser_consume_token (parser
);
6861 if (TREE_CODE (expr
.value
) == FIXED_CST
6862 && !targetm
.fixed_point_supported_p ())
6864 error_at (loc
, "fixed-point types not supported for this target");
6865 expr
.value
= error_mark_node
;
6872 expr
.value
= c_parser_peek_token (parser
)->value
;
6873 c_parser_consume_token (parser
);
6879 case CPP_UTF8STRING
:
6880 expr
.value
= c_parser_peek_token (parser
)->value
;
6881 expr
.original_code
= STRING_CST
;
6882 c_parser_consume_token (parser
);
6884 case CPP_OBJC_STRING
:
6885 gcc_assert (c_dialect_objc ());
6887 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6888 c_parser_consume_token (parser
);
6891 switch (c_parser_peek_token (parser
)->id_kind
)
6895 tree id
= c_parser_peek_token (parser
)->value
;
6896 c_parser_consume_token (parser
);
6897 expr
.value
= build_external_ref (loc
, id
,
6898 (c_parser_peek_token (parser
)->type
6900 &expr
.original_type
);
6903 case C_ID_CLASSNAME
:
6905 /* Here we parse the Objective-C 2.0 Class.name dot
6907 tree class_name
= c_parser_peek_token (parser
)->value
;
6909 c_parser_consume_token (parser
);
6910 gcc_assert (c_dialect_objc ());
6911 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6913 expr
.value
= error_mark_node
;
6916 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6918 c_parser_error (parser
, "expected identifier");
6919 expr
.value
= error_mark_node
;
6922 component
= c_parser_peek_token (parser
)->value
;
6923 c_parser_consume_token (parser
);
6924 expr
.value
= objc_build_class_component_ref (class_name
,
6929 c_parser_error (parser
, "expected expression");
6930 expr
.value
= error_mark_node
;
6934 case CPP_OPEN_PAREN
:
6935 /* A parenthesized expression, statement expression or compound
6937 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6939 /* A statement expression. */
6941 location_t brace_loc
;
6942 c_parser_consume_token (parser
);
6943 brace_loc
= c_parser_peek_token (parser
)->location
;
6944 c_parser_consume_token (parser
);
6945 if (!building_stmt_list_p ())
6947 error_at (loc
, "braced-group within expression allowed "
6948 "only inside a function");
6949 parser
->error
= true;
6950 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6952 expr
.value
= error_mark_node
;
6955 stmt
= c_begin_stmt_expr ();
6956 c_parser_compound_statement_nostart (parser
);
6957 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6959 pedwarn (loc
, OPT_Wpedantic
,
6960 "ISO C forbids braced-groups within expressions");
6961 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6962 mark_exp_read (expr
.value
);
6964 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6966 /* A compound literal. ??? Can we actually get here rather
6967 than going directly to
6968 c_parser_postfix_expression_after_paren_type from
6971 struct c_type_name
*type_name
;
6972 c_parser_consume_token (parser
);
6973 loc
= c_parser_peek_token (parser
)->location
;
6974 type_name
= c_parser_type_name (parser
);
6975 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6977 if (type_name
== NULL
)
6979 expr
.value
= error_mark_node
;
6982 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6988 /* A parenthesized expression. */
6989 c_parser_consume_token (parser
);
6990 expr
= c_parser_expression (parser
);
6991 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6992 TREE_NO_WARNING (expr
.value
) = 1;
6993 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6994 expr
.original_code
= ERROR_MARK
;
6995 /* Don't change EXPR.ORIGINAL_TYPE. */
6996 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7001 switch (c_parser_peek_token (parser
)->keyword
)
7003 case RID_FUNCTION_NAME
:
7004 case RID_PRETTY_FUNCTION_NAME
:
7005 case RID_C99_FUNCTION_NAME
:
7006 expr
.value
= fname_decl (loc
,
7007 c_parser_peek_token (parser
)->keyword
,
7008 c_parser_peek_token (parser
)->value
);
7009 c_parser_consume_token (parser
);
7012 c_parser_consume_token (parser
);
7013 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7015 expr
.value
= error_mark_node
;
7018 e1
= c_parser_expr_no_commas (parser
, NULL
);
7019 mark_exp_read (e1
.value
);
7020 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7021 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7023 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7024 expr
.value
= error_mark_node
;
7027 loc
= c_parser_peek_token (parser
)->location
;
7028 t1
= c_parser_type_name (parser
);
7029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7033 expr
.value
= error_mark_node
;
7037 tree type_expr
= NULL_TREE
;
7038 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7039 groktypename (t1
, &type_expr
, NULL
));
7042 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7043 TREE_TYPE (expr
.value
), type_expr
,
7045 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7050 c_parser_consume_token (parser
);
7051 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7053 expr
.value
= error_mark_node
;
7056 t1
= c_parser_type_name (parser
);
7058 parser
->error
= true;
7059 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7060 gcc_assert (parser
->error
);
7063 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7064 expr
.value
= error_mark_node
;
7069 tree type
= groktypename (t1
, NULL
, NULL
);
7071 if (type
== error_mark_node
)
7072 offsetof_ref
= error_mark_node
;
7075 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7076 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7078 /* Parse the second argument to __builtin_offsetof. We
7079 must have one identifier, and beyond that we want to
7080 accept sub structure and sub array references. */
7081 if (c_parser_next_token_is (parser
, CPP_NAME
))
7083 offsetof_ref
= build_component_ref
7084 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7085 c_parser_consume_token (parser
);
7086 while (c_parser_next_token_is (parser
, CPP_DOT
)
7087 || c_parser_next_token_is (parser
,
7089 || c_parser_next_token_is (parser
,
7092 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7094 loc
= c_parser_peek_token (parser
)->location
;
7095 offsetof_ref
= build_array_ref (loc
,
7100 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7103 c_parser_consume_token (parser
);
7104 if (c_parser_next_token_is_not (parser
,
7107 c_parser_error (parser
, "expected identifier");
7110 offsetof_ref
= build_component_ref
7112 c_parser_peek_token (parser
)->value
);
7113 c_parser_consume_token (parser
);
7119 loc
= c_parser_peek_token (parser
)->location
;
7120 c_parser_consume_token (parser
);
7121 ce
= c_parser_expression (parser
);
7122 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7124 idx
= c_fully_fold (idx
, false, NULL
);
7125 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7127 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7132 c_parser_error (parser
, "expected identifier");
7133 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7135 expr
.value
= fold_offsetof (offsetof_ref
);
7138 case RID_CHOOSE_EXPR
:
7140 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7141 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7144 c_parser_consume_token (parser
);
7145 if (!c_parser_get_builtin_args (parser
,
7146 "__builtin_choose_expr",
7149 expr
.value
= error_mark_node
;
7153 if (vec_safe_length (cexpr_list
) != 3)
7155 error_at (loc
, "wrong number of arguments to "
7156 "%<__builtin_choose_expr%>");
7157 expr
.value
= error_mark_node
;
7161 e1_p
= &(*cexpr_list
)[0];
7162 e2_p
= &(*cexpr_list
)[1];
7163 e3_p
= &(*cexpr_list
)[2];
7166 mark_exp_read (e2_p
->value
);
7167 mark_exp_read (e3_p
->value
);
7168 if (TREE_CODE (c
) != INTEGER_CST
7169 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7171 "first argument to %<__builtin_choose_expr%> not"
7173 constant_expression_warning (c
);
7174 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7177 case RID_TYPES_COMPATIBLE_P
:
7178 c_parser_consume_token (parser
);
7179 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7181 expr
.value
= error_mark_node
;
7184 t1
= c_parser_type_name (parser
);
7187 expr
.value
= error_mark_node
;
7190 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7193 expr
.value
= error_mark_node
;
7196 t2
= c_parser_type_name (parser
);
7199 expr
.value
= error_mark_node
;
7202 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7206 e1
= groktypename (t1
, NULL
, NULL
);
7207 e2
= groktypename (t2
, NULL
, NULL
);
7208 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7210 expr
.value
= error_mark_node
;
7214 e1
= TYPE_MAIN_VARIANT (e1
);
7215 e2
= TYPE_MAIN_VARIANT (e2
);
7218 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7221 case RID_BUILTIN_COMPLEX
:
7223 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7224 c_expr_t
*e1_p
, *e2_p
;
7226 c_parser_consume_token (parser
);
7227 if (!c_parser_get_builtin_args (parser
,
7228 "__builtin_complex",
7229 &cexpr_list
, false))
7231 expr
.value
= error_mark_node
;
7235 if (vec_safe_length (cexpr_list
) != 2)
7237 error_at (loc
, "wrong number of arguments to "
7238 "%<__builtin_complex%>");
7239 expr
.value
= error_mark_node
;
7243 e1_p
= &(*cexpr_list
)[0];
7244 e2_p
= &(*cexpr_list
)[1];
7246 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7247 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7248 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7249 TREE_OPERAND (e1_p
->value
, 0));
7250 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7251 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7252 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7253 TREE_OPERAND (e2_p
->value
, 0));
7254 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7255 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7256 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7257 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7259 error_at (loc
, "%<__builtin_complex%> operand "
7260 "not of real binary floating-point type");
7261 expr
.value
= error_mark_node
;
7264 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7265 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7268 "%<__builtin_complex%> operands of different types");
7269 expr
.value
= error_mark_node
;
7273 pedwarn (loc
, OPT_Wpedantic
,
7274 "ISO C90 does not support complex types");
7275 expr
.value
= build2 (COMPLEX_EXPR
,
7278 (TREE_TYPE (e1_p
->value
))),
7279 e1_p
->value
, e2_p
->value
);
7282 case RID_BUILTIN_SHUFFLE
:
7284 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7288 c_parser_consume_token (parser
);
7289 if (!c_parser_get_builtin_args (parser
,
7290 "__builtin_shuffle",
7291 &cexpr_list
, false))
7293 expr
.value
= error_mark_node
;
7297 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7298 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7300 if (vec_safe_length (cexpr_list
) == 2)
7302 c_build_vec_perm_expr
7303 (loc
, (*cexpr_list
)[0].value
,
7304 NULL_TREE
, (*cexpr_list
)[1].value
);
7306 else if (vec_safe_length (cexpr_list
) == 3)
7308 c_build_vec_perm_expr
7309 (loc
, (*cexpr_list
)[0].value
,
7310 (*cexpr_list
)[1].value
,
7311 (*cexpr_list
)[2].value
);
7314 error_at (loc
, "wrong number of arguments to "
7315 "%<__builtin_shuffle%>");
7316 expr
.value
= error_mark_node
;
7320 case RID_AT_SELECTOR
:
7321 gcc_assert (c_dialect_objc ());
7322 c_parser_consume_token (parser
);
7323 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7325 expr
.value
= error_mark_node
;
7329 tree sel
= c_parser_objc_selector_arg (parser
);
7330 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7332 expr
.value
= objc_build_selector_expr (loc
, sel
);
7335 case RID_AT_PROTOCOL
:
7336 gcc_assert (c_dialect_objc ());
7337 c_parser_consume_token (parser
);
7338 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7340 expr
.value
= error_mark_node
;
7343 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7345 c_parser_error (parser
, "expected identifier");
7346 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7347 expr
.value
= error_mark_node
;
7351 tree id
= c_parser_peek_token (parser
)->value
;
7352 c_parser_consume_token (parser
);
7353 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7355 expr
.value
= objc_build_protocol_expr (id
);
7359 /* Extension to support C-structures in the archiver. */
7360 gcc_assert (c_dialect_objc ());
7361 c_parser_consume_token (parser
);
7362 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7364 expr
.value
= error_mark_node
;
7367 t1
= c_parser_type_name (parser
);
7370 expr
.value
= error_mark_node
;
7371 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7374 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7377 tree type
= groktypename (t1
, NULL
, NULL
);
7378 expr
.value
= objc_build_encode_expr (type
);
7382 expr
= c_parser_generic_selection (parser
);
7384 case RID_CILK_SPAWN
:
7385 c_parser_consume_token (parser
);
7386 if (!flag_enable_cilkplus
)
7388 error_at (loc
, "-fcilkplus must be enabled to use "
7390 expr
= c_parser_postfix_expression (parser
);
7391 expr
.value
= error_mark_node
;
7393 if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7395 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7396 "are not permitted");
7397 /* Now flush out all the _Cilk_spawns. */
7398 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7399 c_parser_consume_token (parser
);
7400 expr
= c_parser_postfix_expression (parser
);
7404 expr
= c_parser_postfix_expression (parser
);
7405 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7409 c_parser_error (parser
, "expected expression");
7410 expr
.value
= error_mark_node
;
7414 case CPP_OPEN_SQUARE
:
7415 if (c_dialect_objc ())
7417 tree receiver
, args
;
7418 c_parser_consume_token (parser
);
7419 receiver
= c_parser_objc_receiver (parser
);
7420 args
= c_parser_objc_message_args (parser
);
7421 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7423 expr
.value
= objc_build_message_expr (receiver
, args
);
7426 /* Else fall through to report error. */
7428 c_parser_error (parser
, "expected expression");
7429 expr
.value
= error_mark_node
;
7432 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7435 /* Parse a postfix expression after a parenthesized type name: the
7436 brace-enclosed initializer of a compound literal, possibly followed
7437 by some postfix operators. This is separate because it is not
7438 possible to tell until after the type name whether a cast
7439 expression has a cast or a compound literal, or whether the operand
7440 of sizeof is a parenthesized type name or starts with a compound
7441 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7442 location of the first token after the parentheses around the type
7445 static struct c_expr
7446 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7447 struct c_type_name
*type_name
,
7448 location_t type_loc
)
7454 location_t start_loc
;
7455 tree type_expr
= NULL_TREE
;
7456 bool type_expr_const
= true;
7457 check_compound_literal_type (type_loc
, type_name
);
7458 start_init (NULL_TREE
, NULL
, 0);
7459 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7460 start_loc
= c_parser_peek_token (parser
)->location
;
7461 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7463 error_at (type_loc
, "compound literal has variable size");
7464 type
= error_mark_node
;
7466 init
= c_parser_braced_init (parser
, type
, false);
7468 maybe_warn_string_init (type
, init
);
7470 if (type
!= error_mark_node
7471 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7472 && current_function_decl
)
7474 error ("compound literal qualified by address-space qualifier");
7475 type
= error_mark_node
;
7479 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7480 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7481 ? CONSTRUCTOR_NON_CONST (init
.value
)
7482 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7483 non_const
|= !type_expr_const
;
7484 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7485 expr
.original_code
= ERROR_MARK
;
7486 expr
.original_type
= NULL
;
7489 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7491 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7492 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7496 gcc_assert (!non_const
);
7497 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7498 type_expr
, expr
.value
);
7501 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7504 /* Callback function for sizeof_pointer_memaccess_warning to compare
7508 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7510 return comptypes (type1
, type2
) == 1;
7513 /* Parse a postfix expression after the initial primary or compound
7514 literal; that is, parse a series of postfix operators.
7516 EXPR_LOC is the location of the primary expression. */
7518 static struct c_expr
7519 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7520 location_t expr_loc
,
7523 struct c_expr orig_expr
;
7525 location_t sizeof_arg_loc
[3];
7528 vec
<tree
, va_gc
> *exprlist
;
7529 vec
<tree
, va_gc
> *origtypes
= NULL
;
7532 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7533 switch (c_parser_peek_token (parser
)->type
)
7535 case CPP_OPEN_SQUARE
:
7536 /* Array reference. */
7537 c_parser_consume_token (parser
);
7538 if (flag_enable_cilkplus
7539 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7540 /* If we are here, then we have something like this:
7543 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7547 idx
= c_parser_expression (parser
).value
;
7548 /* Here we have 3 options:
7549 1. Array [EXPR] -- Normal Array call.
7550 2. Array [EXPR : EXPR] -- Array notation without stride.
7551 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7553 For 1, we just handle it just like a normal array expression.
7554 For 2 and 3 we handle it like we handle array notations. The
7555 idx value we have above becomes the initial/start index.
7557 if (flag_enable_cilkplus
7558 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7559 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7563 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7565 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7568 expr
.original_code
= ERROR_MARK
;
7569 expr
.original_type
= NULL
;
7571 case CPP_OPEN_PAREN
:
7572 /* Function call. */
7573 c_parser_consume_token (parser
);
7574 for (i
= 0; i
< 3; i
++)
7576 sizeof_arg
[i
] = NULL_TREE
;
7577 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7579 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7582 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7583 sizeof_arg_loc
, sizeof_arg
);
7584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7587 mark_exp_read (expr
.value
);
7588 if (warn_sizeof_pointer_memaccess
)
7589 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7590 expr
.value
, exprlist
,
7592 sizeof_ptr_memacc_comptypes
);
7593 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7594 "(" after the FUNCNAME, which is what we have now. */
7595 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7597 expr
.original_code
= ERROR_MARK
;
7598 if (TREE_CODE (expr
.value
) == INTEGER_CST
7599 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7600 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7601 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7602 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7603 expr
.original_type
= NULL
;
7606 release_tree_vector (exprlist
);
7607 release_tree_vector (origtypes
);
7611 /* Structure element reference. */
7612 c_parser_consume_token (parser
);
7613 expr
= default_function_array_conversion (expr_loc
, expr
);
7614 if (c_parser_next_token_is (parser
, CPP_NAME
))
7615 ident
= c_parser_peek_token (parser
)->value
;
7618 c_parser_error (parser
, "expected identifier");
7619 expr
.value
= error_mark_node
;
7620 expr
.original_code
= ERROR_MARK
;
7621 expr
.original_type
= NULL
;
7624 c_parser_consume_token (parser
);
7625 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7626 expr
.original_code
= ERROR_MARK
;
7627 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7628 expr
.original_type
= NULL
;
7631 /* Remember the original type of a bitfield. */
7632 tree field
= TREE_OPERAND (expr
.value
, 1);
7633 if (TREE_CODE (field
) != FIELD_DECL
)
7634 expr
.original_type
= NULL
;
7636 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7640 /* Structure element reference. */
7641 c_parser_consume_token (parser
);
7642 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7643 if (c_parser_next_token_is (parser
, CPP_NAME
))
7644 ident
= c_parser_peek_token (parser
)->value
;
7647 c_parser_error (parser
, "expected identifier");
7648 expr
.value
= error_mark_node
;
7649 expr
.original_code
= ERROR_MARK
;
7650 expr
.original_type
= NULL
;
7653 c_parser_consume_token (parser
);
7654 expr
.value
= build_component_ref (op_loc
,
7655 build_indirect_ref (op_loc
,
7659 expr
.original_code
= ERROR_MARK
;
7660 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7661 expr
.original_type
= NULL
;
7664 /* Remember the original type of a bitfield. */
7665 tree field
= TREE_OPERAND (expr
.value
, 1);
7666 if (TREE_CODE (field
) != FIELD_DECL
)
7667 expr
.original_type
= NULL
;
7669 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7673 /* Postincrement. */
7674 c_parser_consume_token (parser
);
7675 /* If the expressions have array notations, we expand them. */
7676 if (flag_enable_cilkplus
7677 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7678 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7681 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7682 expr
.value
= build_unary_op (op_loc
,
7683 POSTINCREMENT_EXPR
, expr
.value
, 0);
7685 expr
.original_code
= ERROR_MARK
;
7686 expr
.original_type
= NULL
;
7688 case CPP_MINUS_MINUS
:
7689 /* Postdecrement. */
7690 c_parser_consume_token (parser
);
7691 /* If the expressions have array notations, we expand them. */
7692 if (flag_enable_cilkplus
7693 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7694 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7697 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7698 expr
.value
= build_unary_op (op_loc
,
7699 POSTDECREMENT_EXPR
, expr
.value
, 0);
7701 expr
.original_code
= ERROR_MARK
;
7702 expr
.original_type
= NULL
;
7710 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7713 assignment-expression
7714 expression , assignment-expression
7717 static struct c_expr
7718 c_parser_expression (c_parser
*parser
)
7720 location_t tloc
= c_parser_peek_token (parser
)->location
;
7722 expr
= c_parser_expr_no_commas (parser
, NULL
);
7723 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7724 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7725 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7729 location_t loc
= c_parser_peek_token (parser
)->location
;
7730 location_t expr_loc
;
7731 c_parser_consume_token (parser
);
7732 expr_loc
= c_parser_peek_token (parser
)->location
;
7733 lhsval
= expr
.value
;
7734 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7735 lhsval
= TREE_OPERAND (lhsval
, 1);
7736 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7737 mark_exp_read (lhsval
);
7738 next
= c_parser_expr_no_commas (parser
, NULL
);
7739 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7740 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7741 expr
.original_code
= COMPOUND_EXPR
;
7742 expr
.original_type
= next
.original_type
;
7747 /* Parse an expression and convert functions or arrays to pointers and
7748 lvalues to rvalues. */
7750 static struct c_expr
7751 c_parser_expression_conv (c_parser
*parser
)
7754 location_t loc
= c_parser_peek_token (parser
)->location
;
7755 expr
= c_parser_expression (parser
);
7756 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7760 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7761 functions and arrays to pointers and lvalues to rvalues. If
7762 FOLD_P, fold the expressions.
7765 assignment-expression
7766 nonempty-expr-list , assignment-expression
7769 static vec
<tree
, va_gc
> *
7770 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7771 vec
<tree
, va_gc
> **p_orig_types
,
7772 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7774 vec
<tree
, va_gc
> *ret
;
7775 vec
<tree
, va_gc
> *orig_types
;
7777 location_t loc
= c_parser_peek_token (parser
)->location
;
7778 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7779 unsigned int idx
= 0;
7781 ret
= make_tree_vector ();
7782 if (p_orig_types
== NULL
)
7785 orig_types
= make_tree_vector ();
7787 if (sizeof_arg
!= NULL
7788 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7789 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7790 expr
= c_parser_expr_no_commas (parser
, NULL
);
7792 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7794 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7795 ret
->quick_push (expr
.value
);
7797 orig_types
->quick_push (expr
.original_type
);
7798 if (sizeof_arg
!= NULL
7799 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7800 && expr
.original_code
== SIZEOF_EXPR
)
7802 sizeof_arg
[0] = c_last_sizeof_arg
;
7803 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7805 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7807 c_parser_consume_token (parser
);
7808 loc
= c_parser_peek_token (parser
)->location
;
7809 if (sizeof_arg
!= NULL
7810 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7811 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7813 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7814 expr
= c_parser_expr_no_commas (parser
, NULL
);
7816 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7818 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7819 vec_safe_push (ret
, expr
.value
);
7821 vec_safe_push (orig_types
, expr
.original_type
);
7823 && sizeof_arg
!= NULL
7824 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7825 && expr
.original_code
== SIZEOF_EXPR
)
7827 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7828 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7832 *p_orig_types
= orig_types
;
7836 /* Parse Objective-C-specific constructs. */
7838 /* Parse an objc-class-definition.
7840 objc-class-definition:
7841 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7842 objc-class-instance-variables[opt] objc-methodprotolist @end
7843 @implementation identifier objc-superclass[opt]
7844 objc-class-instance-variables[opt]
7845 @interface identifier ( identifier ) objc-protocol-refs[opt]
7846 objc-methodprotolist @end
7847 @interface identifier ( ) objc-protocol-refs[opt]
7848 objc-methodprotolist @end
7849 @implementation identifier ( identifier )
7854 "@interface identifier (" must start "@interface identifier (
7855 identifier ) ...": objc-methodprotolist in the first production may
7856 not start with a parenthesized identifier as a declarator of a data
7857 definition with no declaration specifiers if the objc-superclass,
7858 objc-protocol-refs and objc-class-instance-variables are omitted. */
7861 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7866 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7868 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7873 c_parser_consume_token (parser
);
7874 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7876 c_parser_error (parser
, "expected identifier");
7879 id1
= c_parser_peek_token (parser
)->value
;
7880 c_parser_consume_token (parser
);
7881 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7883 /* We have a category or class extension. */
7885 tree proto
= NULL_TREE
;
7886 c_parser_consume_token (parser
);
7887 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7889 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7891 /* We have a class extension. */
7896 c_parser_error (parser
, "expected identifier or %<)%>");
7897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7903 id2
= c_parser_peek_token (parser
)->value
;
7904 c_parser_consume_token (parser
);
7906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7909 objc_start_category_implementation (id1
, id2
);
7912 if (c_parser_next_token_is (parser
, CPP_LESS
))
7913 proto
= c_parser_objc_protocol_refs (parser
);
7914 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7915 c_parser_objc_methodprotolist (parser
);
7916 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7917 objc_finish_interface ();
7920 if (c_parser_next_token_is (parser
, CPP_COLON
))
7922 c_parser_consume_token (parser
);
7923 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7925 c_parser_error (parser
, "expected identifier");
7928 superclass
= c_parser_peek_token (parser
)->value
;
7929 c_parser_consume_token (parser
);
7932 superclass
= NULL_TREE
;
7935 tree proto
= NULL_TREE
;
7936 if (c_parser_next_token_is (parser
, CPP_LESS
))
7937 proto
= c_parser_objc_protocol_refs (parser
);
7938 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7941 objc_start_class_implementation (id1
, superclass
);
7942 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7943 c_parser_objc_class_instance_variables (parser
);
7946 objc_continue_interface ();
7947 c_parser_objc_methodprotolist (parser
);
7948 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7949 objc_finish_interface ();
7953 objc_continue_implementation ();
7958 /* Parse objc-class-instance-variables.
7960 objc-class-instance-variables:
7961 { objc-instance-variable-decl-list[opt] }
7963 objc-instance-variable-decl-list:
7964 objc-visibility-spec
7965 objc-instance-variable-decl ;
7967 objc-instance-variable-decl-list objc-visibility-spec
7968 objc-instance-variable-decl-list objc-instance-variable-decl ;
7969 objc-instance-variable-decl-list ;
7971 objc-visibility-spec:
7976 objc-instance-variable-decl:
7981 c_parser_objc_class_instance_variables (c_parser
*parser
)
7983 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7984 c_parser_consume_token (parser
);
7985 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7988 /* Parse any stray semicolon. */
7989 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7991 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7993 c_parser_consume_token (parser
);
7996 /* Stop if at the end of the instance variables. */
7997 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7999 c_parser_consume_token (parser
);
8002 /* Parse any objc-visibility-spec. */
8003 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8005 c_parser_consume_token (parser
);
8006 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8009 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8011 c_parser_consume_token (parser
);
8012 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8015 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8017 c_parser_consume_token (parser
);
8018 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8021 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8023 c_parser_consume_token (parser
);
8024 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8027 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8029 c_parser_pragma (parser
, pragma_external
);
8033 /* Parse some comma-separated declarations. */
8034 decls
= c_parser_struct_declaration (parser
);
8037 /* There is a syntax error. We want to skip the offending
8038 tokens up to the next ';' (included) or '}'
8041 /* First, skip manually a ')' or ']'. This is because they
8042 reduce the nesting level, so c_parser_skip_until_found()
8043 wouldn't be able to skip past them. */
8044 c_token
*token
= c_parser_peek_token (parser
);
8045 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8046 c_parser_consume_token (parser
);
8048 /* Then, do the standard skipping. */
8049 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8051 /* We hopefully recovered. Start normal parsing again. */
8052 parser
->error
= false;
8057 /* Comma-separated instance variables are chained together
8058 in reverse order; add them one by one. */
8059 tree ivar
= nreverse (decls
);
8060 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8061 objc_add_instance_variable (copy_node (ivar
));
8063 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8067 /* Parse an objc-class-declaration.
8069 objc-class-declaration:
8070 @class identifier-list ;
8074 c_parser_objc_class_declaration (c_parser
*parser
)
8076 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8077 c_parser_consume_token (parser
);
8078 /* Any identifiers, including those declared as type names, are OK
8083 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8085 c_parser_error (parser
, "expected identifier");
8086 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8087 parser
->error
= false;
8090 id
= c_parser_peek_token (parser
)->value
;
8091 objc_declare_class (id
);
8092 c_parser_consume_token (parser
);
8093 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8094 c_parser_consume_token (parser
);
8098 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8101 /* Parse an objc-alias-declaration.
8103 objc-alias-declaration:
8104 @compatibility_alias identifier identifier ;
8108 c_parser_objc_alias_declaration (c_parser
*parser
)
8111 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8112 c_parser_consume_token (parser
);
8113 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8115 c_parser_error (parser
, "expected identifier");
8116 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8119 id1
= c_parser_peek_token (parser
)->value
;
8120 c_parser_consume_token (parser
);
8121 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8123 c_parser_error (parser
, "expected identifier");
8124 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8127 id2
= c_parser_peek_token (parser
)->value
;
8128 c_parser_consume_token (parser
);
8129 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8130 objc_declare_alias (id1
, id2
);
8133 /* Parse an objc-protocol-definition.
8135 objc-protocol-definition:
8136 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8137 @protocol identifier-list ;
8139 "@protocol identifier ;" should be resolved as "@protocol
8140 identifier-list ;": objc-methodprotolist may not start with a
8141 semicolon in the first alternative if objc-protocol-refs are
8145 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8147 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8149 c_parser_consume_token (parser
);
8150 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8152 c_parser_error (parser
, "expected identifier");
8155 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8156 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8158 /* Any identifiers, including those declared as type names, are
8163 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8165 c_parser_error (parser
, "expected identifier");
8168 id
= c_parser_peek_token (parser
)->value
;
8169 objc_declare_protocol (id
, attributes
);
8170 c_parser_consume_token (parser
);
8171 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8172 c_parser_consume_token (parser
);
8176 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8180 tree id
= c_parser_peek_token (parser
)->value
;
8181 tree proto
= NULL_TREE
;
8182 c_parser_consume_token (parser
);
8183 if (c_parser_next_token_is (parser
, CPP_LESS
))
8184 proto
= c_parser_objc_protocol_refs (parser
);
8185 parser
->objc_pq_context
= true;
8186 objc_start_protocol (id
, proto
, attributes
);
8187 c_parser_objc_methodprotolist (parser
);
8188 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8189 parser
->objc_pq_context
= false;
8190 objc_finish_interface ();
8194 /* Parse an objc-method-type.
8200 Return true if it is a class method (+) and false if it is
8201 an instance method (-).
8204 c_parser_objc_method_type (c_parser
*parser
)
8206 switch (c_parser_peek_token (parser
)->type
)
8209 c_parser_consume_token (parser
);
8212 c_parser_consume_token (parser
);
8219 /* Parse an objc-method-definition.
8221 objc-method-definition:
8222 objc-method-type objc-method-decl ;[opt] compound-statement
8226 c_parser_objc_method_definition (c_parser
*parser
)
8228 bool is_class_method
= c_parser_objc_method_type (parser
);
8229 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8230 parser
->objc_pq_context
= true;
8231 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8233 if (decl
== error_mark_node
)
8234 return; /* Bail here. */
8236 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8238 c_parser_consume_token (parser
);
8239 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8240 "extra semicolon in method definition specified");
8243 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8245 c_parser_error (parser
, "expected %<{%>");
8249 parser
->objc_pq_context
= false;
8250 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8252 add_stmt (c_parser_compound_statement (parser
));
8253 objc_finish_method_definition (current_function_decl
);
8257 /* This code is executed when we find a method definition
8258 outside of an @implementation context (or invalid for other
8259 reasons). Parse the method (to keep going) but do not emit
8262 c_parser_compound_statement (parser
);
8266 /* Parse an objc-methodprotolist.
8268 objc-methodprotolist:
8270 objc-methodprotolist objc-methodproto
8271 objc-methodprotolist declaration
8272 objc-methodprotolist ;
8276 The declaration is a data definition, which may be missing
8277 declaration specifiers under the same rules and diagnostics as
8278 other data definitions outside functions, and the stray semicolon
8279 is diagnosed the same way as a stray semicolon outside a
8283 c_parser_objc_methodprotolist (c_parser
*parser
)
8287 /* The list is terminated by @end. */
8288 switch (c_parser_peek_token (parser
)->type
)
8291 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8292 "ISO C does not allow extra %<;%> outside of a function");
8293 c_parser_consume_token (parser
);
8297 c_parser_objc_methodproto (parser
);
8300 c_parser_pragma (parser
, pragma_external
);
8305 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8307 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8308 c_parser_objc_at_property_declaration (parser
);
8309 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8311 objc_set_method_opt (true);
8312 c_parser_consume_token (parser
);
8314 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8316 objc_set_method_opt (false);
8317 c_parser_consume_token (parser
);
8320 c_parser_declaration_or_fndef (parser
, false, false, true,
8321 false, true, NULL
, vNULL
);
8327 /* Parse an objc-methodproto.
8330 objc-method-type objc-method-decl ;
8334 c_parser_objc_methodproto (c_parser
*parser
)
8336 bool is_class_method
= c_parser_objc_method_type (parser
);
8337 tree decl
, attributes
= NULL_TREE
;
8339 /* Remember protocol qualifiers in prototypes. */
8340 parser
->objc_pq_context
= true;
8341 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8343 /* Forget protocol qualifiers now. */
8344 parser
->objc_pq_context
= false;
8346 /* Do not allow the presence of attributes to hide an erroneous
8347 method implementation in the interface section. */
8348 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8350 c_parser_error (parser
, "expected %<;%>");
8354 if (decl
!= error_mark_node
)
8355 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8357 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8360 /* If we are at a position that method attributes may be present, check that
8361 there are not any parsed already (a syntax error) and then collect any
8362 specified at the current location. Finally, if new attributes were present,
8363 check that the next token is legal ( ';' for decls and '{' for defs). */
8366 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8371 c_parser_error (parser
,
8372 "method attributes must be specified at the end only");
8373 *attributes
= NULL_TREE
;
8377 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8378 *attributes
= c_parser_attributes (parser
);
8380 /* If there were no attributes here, just report any earlier error. */
8381 if (*attributes
== NULL_TREE
|| bad
)
8384 /* If the attributes are followed by a ; or {, then just report any earlier
8386 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8387 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8390 /* We've got attributes, but not at the end. */
8391 c_parser_error (parser
,
8392 "expected %<;%> or %<{%> after method attribute definition");
8396 /* Parse an objc-method-decl.
8399 ( objc-type-name ) objc-selector
8401 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8402 objc-keyword-selector objc-optparmlist
8405 objc-keyword-selector:
8407 objc-keyword-selector objc-keyword-decl
8410 objc-selector : ( objc-type-name ) identifier
8411 objc-selector : identifier
8412 : ( objc-type-name ) identifier
8416 objc-optparms objc-optellipsis
8420 objc-opt-parms , parameter-declaration
8428 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8429 tree
*attributes
, tree
*expr
)
8431 tree type
= NULL_TREE
;
8433 tree parms
= NULL_TREE
;
8434 bool ellipsis
= false;
8435 bool attr_err
= false;
8437 *attributes
= NULL_TREE
;
8438 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8440 c_parser_consume_token (parser
);
8441 type
= c_parser_objc_type_name (parser
);
8442 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8444 sel
= c_parser_objc_selector (parser
);
8445 /* If there is no selector, or a colon follows, we have an
8446 objc-keyword-selector. If there is a selector, and a colon does
8447 not follow, that selector ends the objc-method-decl. */
8448 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8451 tree list
= NULL_TREE
;
8454 tree atype
= NULL_TREE
, id
, keyworddecl
;
8455 tree param_attr
= NULL_TREE
;
8456 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8458 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8460 c_parser_consume_token (parser
);
8461 atype
= c_parser_objc_type_name (parser
);
8462 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8465 /* New ObjC allows attributes on method parameters. */
8466 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8467 param_attr
= c_parser_attributes (parser
);
8468 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8470 c_parser_error (parser
, "expected identifier");
8471 return error_mark_node
;
8473 id
= c_parser_peek_token (parser
)->value
;
8474 c_parser_consume_token (parser
);
8475 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8476 list
= chainon (list
, keyworddecl
);
8477 tsel
= c_parser_objc_selector (parser
);
8478 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8482 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8484 /* Parse the optional parameter list. Optional Objective-C
8485 method parameters follow the C syntax, and may include '...'
8486 to denote a variable number of arguments. */
8487 parms
= make_node (TREE_LIST
);
8488 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8490 struct c_parm
*parm
;
8491 c_parser_consume_token (parser
);
8492 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8495 c_parser_consume_token (parser
);
8496 attr_err
|= c_parser_objc_maybe_method_attributes
8497 (parser
, attributes
) ;
8500 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8503 parms
= chainon (parms
,
8504 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8509 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8513 c_parser_error (parser
, "objective-c method declaration is expected");
8514 return error_mark_node
;
8518 return error_mark_node
;
8520 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8523 /* Parse an objc-type-name.
8526 objc-type-qualifiers[opt] type-name
8527 objc-type-qualifiers[opt]
8529 objc-type-qualifiers:
8531 objc-type-qualifiers objc-type-qualifier
8533 objc-type-qualifier: one of
8534 in out inout bycopy byref oneway
8538 c_parser_objc_type_name (c_parser
*parser
)
8540 tree quals
= NULL_TREE
;
8541 struct c_type_name
*type_name
= NULL
;
8542 tree type
= NULL_TREE
;
8545 c_token
*token
= c_parser_peek_token (parser
);
8546 if (token
->type
== CPP_KEYWORD
8547 && (token
->keyword
== RID_IN
8548 || token
->keyword
== RID_OUT
8549 || token
->keyword
== RID_INOUT
8550 || token
->keyword
== RID_BYCOPY
8551 || token
->keyword
== RID_BYREF
8552 || token
->keyword
== RID_ONEWAY
))
8554 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8555 c_parser_consume_token (parser
);
8560 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8561 type_name
= c_parser_type_name (parser
);
8563 type
= groktypename (type_name
, NULL
, NULL
);
8565 /* If the type is unknown, and error has already been produced and
8566 we need to recover from the error. In that case, use NULL_TREE
8567 for the type, as if no type had been specified; this will use the
8568 default type ('id') which is good for error recovery. */
8569 if (type
== error_mark_node
)
8572 return build_tree_list (quals
, type
);
8575 /* Parse objc-protocol-refs.
8582 c_parser_objc_protocol_refs (c_parser
*parser
)
8584 tree list
= NULL_TREE
;
8585 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8586 c_parser_consume_token (parser
);
8587 /* Any identifiers, including those declared as type names, are OK
8592 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8594 c_parser_error (parser
, "expected identifier");
8597 id
= c_parser_peek_token (parser
)->value
;
8598 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8599 c_parser_consume_token (parser
);
8600 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8601 c_parser_consume_token (parser
);
8605 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8609 /* Parse an objc-try-catch-finally-statement.
8611 objc-try-catch-finally-statement:
8612 @try compound-statement objc-catch-list[opt]
8613 @try compound-statement objc-catch-list[opt] @finally compound-statement
8616 @catch ( objc-catch-parameter-declaration ) compound-statement
8617 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8619 objc-catch-parameter-declaration:
8620 parameter-declaration
8623 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8625 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8626 for C++. Keep them in sync. */
8629 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8631 location_t location
;
8634 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8635 c_parser_consume_token (parser
);
8636 location
= c_parser_peek_token (parser
)->location
;
8637 objc_maybe_warn_exceptions (location
);
8638 stmt
= c_parser_compound_statement (parser
);
8639 objc_begin_try_stmt (location
, stmt
);
8641 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8643 struct c_parm
*parm
;
8644 tree parameter_declaration
= error_mark_node
;
8645 bool seen_open_paren
= false;
8647 c_parser_consume_token (parser
);
8648 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8649 seen_open_paren
= true;
8650 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8652 /* We have "@catch (...)" (where the '...' are literally
8653 what is in the code). Skip the '...'.
8654 parameter_declaration is set to NULL_TREE, and
8655 objc_being_catch_clauses() knows that that means
8657 c_parser_consume_token (parser
);
8658 parameter_declaration
= NULL_TREE
;
8662 /* We have "@catch (NSException *exception)" or something
8663 like that. Parse the parameter declaration. */
8664 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8666 parameter_declaration
= error_mark_node
;
8668 parameter_declaration
= grokparm (parm
, NULL
);
8670 if (seen_open_paren
)
8671 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8674 /* If there was no open parenthesis, we are recovering from
8675 an error, and we are trying to figure out what mistake
8676 the user has made. */
8678 /* If there is an immediate closing parenthesis, the user
8679 probably forgot the opening one (ie, they typed "@catch
8680 NSException *e)". Parse the closing parenthesis and keep
8682 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8683 c_parser_consume_token (parser
);
8685 /* If these is no immediate closing parenthesis, the user
8686 probably doesn't know that parenthesis are required at
8687 all (ie, they typed "@catch NSException *e"). So, just
8688 forget about the closing parenthesis and keep going. */
8690 objc_begin_catch_clause (parameter_declaration
);
8691 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8692 c_parser_compound_statement_nostart (parser
);
8693 objc_finish_catch_clause ();
8695 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8697 c_parser_consume_token (parser
);
8698 location
= c_parser_peek_token (parser
)->location
;
8699 stmt
= c_parser_compound_statement (parser
);
8700 objc_build_finally_clause (location
, stmt
);
8702 objc_finish_try_stmt ();
8705 /* Parse an objc-synchronized-statement.
8707 objc-synchronized-statement:
8708 @synchronized ( expression ) compound-statement
8712 c_parser_objc_synchronized_statement (c_parser
*parser
)
8716 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8717 c_parser_consume_token (parser
);
8718 loc
= c_parser_peek_token (parser
)->location
;
8719 objc_maybe_warn_exceptions (loc
);
8720 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8722 struct c_expr ce
= c_parser_expression (parser
);
8723 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8725 expr
= c_fully_fold (expr
, false, NULL
);
8726 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8729 expr
= error_mark_node
;
8730 stmt
= c_parser_compound_statement (parser
);
8731 objc_build_synchronized (loc
, expr
, stmt
);
8734 /* Parse an objc-selector; return NULL_TREE without an error if the
8735 next token is not an objc-selector.
8740 enum struct union if else while do for switch case default
8741 break continue return goto asm sizeof typeof __alignof
8742 unsigned long const short volatile signed restrict _Complex
8743 in out inout bycopy byref oneway int char float double void _Bool
8746 ??? Why this selection of keywords but not, for example, storage
8747 class specifiers? */
8750 c_parser_objc_selector (c_parser
*parser
)
8752 c_token
*token
= c_parser_peek_token (parser
);
8753 tree value
= token
->value
;
8754 if (token
->type
== CPP_NAME
)
8756 c_parser_consume_token (parser
);
8759 if (token
->type
!= CPP_KEYWORD
)
8761 switch (token
->keyword
)
8805 c_parser_consume_token (parser
);
8812 /* Parse an objc-selector-arg.
8816 objc-keywordname-list
8818 objc-keywordname-list:
8820 objc-keywordname-list objc-keywordname
8828 c_parser_objc_selector_arg (c_parser
*parser
)
8830 tree sel
= c_parser_objc_selector (parser
);
8831 tree list
= NULL_TREE
;
8832 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8836 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8838 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8839 sel
= c_parser_objc_selector (parser
);
8840 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8846 /* Parse an objc-receiver.
8855 c_parser_objc_receiver (c_parser
*parser
)
8857 location_t loc
= c_parser_peek_token (parser
)->location
;
8859 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8860 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8861 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8863 tree id
= c_parser_peek_token (parser
)->value
;
8864 c_parser_consume_token (parser
);
8865 return objc_get_class_reference (id
);
8867 struct c_expr ce
= c_parser_expression (parser
);
8868 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8869 return c_fully_fold (ce
.value
, false, NULL
);
8872 /* Parse objc-message-args.
8876 objc-keywordarg-list
8878 objc-keywordarg-list:
8880 objc-keywordarg-list objc-keywordarg
8883 objc-selector : objc-keywordexpr
8888 c_parser_objc_message_args (c_parser
*parser
)
8890 tree sel
= c_parser_objc_selector (parser
);
8891 tree list
= NULL_TREE
;
8892 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8897 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8898 return error_mark_node
;
8899 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8900 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8901 sel
= c_parser_objc_selector (parser
);
8902 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8908 /* Parse an objc-keywordexpr.
8915 c_parser_objc_keywordexpr (c_parser
*parser
)
8918 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8920 if (vec_safe_length (expr_list
) == 1)
8922 /* Just return the expression, remove a level of
8924 ret
= (*expr_list
)[0];
8928 /* We have a comma expression, we will collapse later. */
8929 ret
= build_tree_list_vec (expr_list
);
8931 release_tree_vector (expr_list
);
8935 /* A check, needed in several places, that ObjC interface, implementation or
8936 method definitions are not prefixed by incorrect items. */
8938 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8939 struct c_declspecs
*specs
)
8941 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8942 || specs
->typespec_kind
!= ctsk_none
)
8944 c_parser_error (parser
,
8945 "no type or storage class may be specified here,");
8946 c_parser_skip_to_end_of_block_or_statement (parser
);
8952 /* Parse an Objective-C @property declaration. The syntax is:
8954 objc-property-declaration:
8955 '@property' objc-property-attributes[opt] struct-declaration ;
8957 objc-property-attributes:
8958 '(' objc-property-attribute-list ')'
8960 objc-property-attribute-list:
8961 objc-property-attribute
8962 objc-property-attribute-list, objc-property-attribute
8964 objc-property-attribute
8965 'getter' = identifier
8966 'setter' = identifier
8975 @property NSString *name;
8976 @property (readonly) id object;
8977 @property (retain, nonatomic, getter=getTheName) id name;
8978 @property int a, b, c;
8980 PS: This function is identical to cp_parser_objc_at_propery_declaration
8981 for C++. Keep them in sync. */
8983 c_parser_objc_at_property_declaration (c_parser
*parser
)
8985 /* The following variables hold the attributes of the properties as
8986 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8987 seen. When we see an attribute, we set them to 'true' (if they
8988 are boolean properties) or to the identifier (if they have an
8989 argument, ie, for getter and setter). Note that here we only
8990 parse the list of attributes, check the syntax and accumulate the
8991 attributes that we find. objc_add_property_declaration() will
8992 then process the information. */
8993 bool property_assign
= false;
8994 bool property_copy
= false;
8995 tree property_getter_ident
= NULL_TREE
;
8996 bool property_nonatomic
= false;
8997 bool property_readonly
= false;
8998 bool property_readwrite
= false;
8999 bool property_retain
= false;
9000 tree property_setter_ident
= NULL_TREE
;
9002 /* 'properties' is the list of properties that we read. Usually a
9003 single one, but maybe more (eg, in "@property int a, b, c;" there
9008 loc
= c_parser_peek_token (parser
)->location
;
9009 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9011 c_parser_consume_token (parser
); /* Eat '@property'. */
9013 /* Parse the optional attribute list... */
9014 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9017 c_parser_consume_token (parser
);
9019 /* Property attribute keywords are valid now. */
9020 parser
->objc_property_attr_context
= true;
9024 bool syntax_error
= false;
9025 c_token
*token
= c_parser_peek_token (parser
);
9028 if (token
->type
!= CPP_KEYWORD
)
9030 if (token
->type
== CPP_CLOSE_PAREN
)
9031 c_parser_error (parser
, "expected identifier");
9034 c_parser_consume_token (parser
);
9035 c_parser_error (parser
, "unknown property attribute");
9039 keyword
= token
->keyword
;
9040 c_parser_consume_token (parser
);
9043 case RID_ASSIGN
: property_assign
= true; break;
9044 case RID_COPY
: property_copy
= true; break;
9045 case RID_NONATOMIC
: property_nonatomic
= true; break;
9046 case RID_READONLY
: property_readonly
= true; break;
9047 case RID_READWRITE
: property_readwrite
= true; break;
9048 case RID_RETAIN
: property_retain
= true; break;
9052 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9054 if (keyword
== RID_GETTER
)
9055 c_parser_error (parser
,
9056 "missing %<=%> (after %<getter%> attribute)");
9058 c_parser_error (parser
,
9059 "missing %<=%> (after %<setter%> attribute)");
9060 syntax_error
= true;
9063 c_parser_consume_token (parser
); /* eat the = */
9064 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9066 c_parser_error (parser
, "expected identifier");
9067 syntax_error
= true;
9070 if (keyword
== RID_SETTER
)
9072 if (property_setter_ident
!= NULL_TREE
)
9073 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9075 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9076 c_parser_consume_token (parser
);
9077 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9078 c_parser_error (parser
, "setter name must terminate with %<:%>");
9080 c_parser_consume_token (parser
);
9084 if (property_getter_ident
!= NULL_TREE
)
9085 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9087 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9088 c_parser_consume_token (parser
);
9092 c_parser_error (parser
, "unknown property attribute");
9093 syntax_error
= true;
9100 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9101 c_parser_consume_token (parser
);
9105 parser
->objc_property_attr_context
= false;
9106 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9108 /* ... and the property declaration(s). */
9109 properties
= c_parser_struct_declaration (parser
);
9111 if (properties
== error_mark_node
)
9113 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9114 parser
->error
= false;
9118 if (properties
== NULL_TREE
)
9119 c_parser_error (parser
, "expected identifier");
9122 /* Comma-separated properties are chained together in
9123 reverse order; add them one by one. */
9124 properties
= nreverse (properties
);
9126 for (; properties
; properties
= TREE_CHAIN (properties
))
9127 objc_add_property_declaration (loc
, copy_node (properties
),
9128 property_readonly
, property_readwrite
,
9129 property_assign
, property_retain
,
9130 property_copy
, property_nonatomic
,
9131 property_getter_ident
, property_setter_ident
);
9134 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9135 parser
->error
= false;
9138 /* Parse an Objective-C @synthesize declaration. The syntax is:
9140 objc-synthesize-declaration:
9141 @synthesize objc-synthesize-identifier-list ;
9143 objc-synthesize-identifier-list:
9144 objc-synthesize-identifier
9145 objc-synthesize-identifier-list, objc-synthesize-identifier
9147 objc-synthesize-identifier
9149 identifier = identifier
9152 @synthesize MyProperty;
9153 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9155 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9156 for C++. Keep them in sync.
9159 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9161 tree list
= NULL_TREE
;
9163 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9164 loc
= c_parser_peek_token (parser
)->location
;
9166 c_parser_consume_token (parser
);
9169 tree property
, ivar
;
9170 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9172 c_parser_error (parser
, "expected identifier");
9173 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9174 /* Once we find the semicolon, we can resume normal parsing.
9175 We have to reset parser->error manually because
9176 c_parser_skip_until_found() won't reset it for us if the
9177 next token is precisely a semicolon. */
9178 parser
->error
= false;
9181 property
= c_parser_peek_token (parser
)->value
;
9182 c_parser_consume_token (parser
);
9183 if (c_parser_next_token_is (parser
, CPP_EQ
))
9185 c_parser_consume_token (parser
);
9186 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9188 c_parser_error (parser
, "expected identifier");
9189 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9190 parser
->error
= false;
9193 ivar
= c_parser_peek_token (parser
)->value
;
9194 c_parser_consume_token (parser
);
9198 list
= chainon (list
, build_tree_list (ivar
, property
));
9199 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9200 c_parser_consume_token (parser
);
9204 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9205 objc_add_synthesize_declaration (loc
, list
);
9208 /* Parse an Objective-C @dynamic declaration. The syntax is:
9210 objc-dynamic-declaration:
9211 @dynamic identifier-list ;
9214 @dynamic MyProperty;
9215 @dynamic MyProperty, AnotherProperty;
9217 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9218 for C++. Keep them in sync.
9221 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9223 tree list
= NULL_TREE
;
9225 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9226 loc
= c_parser_peek_token (parser
)->location
;
9228 c_parser_consume_token (parser
);
9232 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9234 c_parser_error (parser
, "expected identifier");
9235 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9236 parser
->error
= false;
9239 property
= c_parser_peek_token (parser
)->value
;
9240 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9241 c_parser_consume_token (parser
);
9242 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9243 c_parser_consume_token (parser
);
9247 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9248 objc_add_dynamic_declaration (loc
, list
);
9252 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9253 should be considered, statements. ALLOW_STMT is true if we're within
9254 the context of a function and such pragmas are to be allowed. Returns
9255 true if we actually parsed such a pragma. */
9258 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9262 id
= c_parser_peek_token (parser
)->pragma_kind
;
9263 gcc_assert (id
!= PRAGMA_NONE
);
9267 case PRAGMA_OMP_BARRIER
:
9268 if (context
!= pragma_compound
)
9270 if (context
== pragma_stmt
)
9271 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9272 "used in compound statements");
9275 c_parser_omp_barrier (parser
);
9278 case PRAGMA_OMP_FLUSH
:
9279 if (context
!= pragma_compound
)
9281 if (context
== pragma_stmt
)
9282 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9283 "used in compound statements");
9286 c_parser_omp_flush (parser
);
9289 case PRAGMA_OMP_TASKWAIT
:
9290 if (context
!= pragma_compound
)
9292 if (context
== pragma_stmt
)
9293 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9294 "used in compound statements");
9297 c_parser_omp_taskwait (parser
);
9300 case PRAGMA_OMP_TASKYIELD
:
9301 if (context
!= pragma_compound
)
9303 if (context
== pragma_stmt
)
9304 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9305 "used in compound statements");
9308 c_parser_omp_taskyield (parser
);
9311 case PRAGMA_OMP_CANCEL
:
9312 if (context
!= pragma_compound
)
9314 if (context
== pragma_stmt
)
9315 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9316 "used in compound statements");
9319 c_parser_omp_cancel (parser
);
9322 case PRAGMA_OMP_CANCELLATION_POINT
:
9323 if (context
!= pragma_compound
)
9325 if (context
== pragma_stmt
)
9326 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9327 "only be used in compound statements");
9330 c_parser_omp_cancellation_point (parser
);
9333 case PRAGMA_OMP_THREADPRIVATE
:
9334 c_parser_omp_threadprivate (parser
);
9337 case PRAGMA_OMP_TARGET
:
9338 return c_parser_omp_target (parser
, context
);
9340 case PRAGMA_OMP_END_DECLARE_TARGET
:
9341 c_parser_omp_end_declare_target (parser
);
9344 case PRAGMA_OMP_SECTION
:
9345 error_at (c_parser_peek_token (parser
)->location
,
9346 "%<#pragma omp section%> may only be used in "
9347 "%<#pragma omp sections%> construct");
9348 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9351 case PRAGMA_OMP_DECLARE_REDUCTION
:
9352 c_parser_omp_declare (parser
, context
);
9355 c_parser_consume_pragma (parser
);
9356 c_parser_skip_to_pragma_eol (parser
);
9357 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9358 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9359 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9361 c_parser_error (parser
, "for, while or do statement expected");
9364 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9365 c_parser_for_statement (parser
, true);
9366 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9367 c_parser_while_statement (parser
, true);
9369 c_parser_do_statement (parser
, true);
9372 case PRAGMA_GCC_PCH_PREPROCESS
:
9373 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9374 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9377 case PRAGMA_CILK_SIMD
:
9378 if (!c_parser_cilk_verify_simd (parser
, context
))
9380 c_parser_consume_pragma (parser
);
9381 c_parser_cilk_simd (parser
);
9385 if (id
< PRAGMA_FIRST_EXTERNAL
)
9387 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9390 c_parser_error (parser
, "expected declaration specifiers");
9391 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9394 c_parser_omp_construct (parser
);
9400 c_parser_consume_pragma (parser
);
9401 c_invoke_pragma_handler (id
);
9403 /* Skip to EOL, but suppress any error message. Those will have been
9404 generated by the handler routine through calling error, as opposed
9405 to calling c_parser_error. */
9406 parser
->error
= true;
9407 c_parser_skip_to_pragma_eol (parser
);
9412 /* The interface the pragma parsers have to the lexer. */
9415 pragma_lex (tree
*value
)
9417 c_token
*tok
= c_parser_peek_token (the_parser
);
9418 enum cpp_ttype ret
= tok
->type
;
9420 *value
= tok
->value
;
9421 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9425 if (ret
== CPP_KEYWORD
)
9427 c_parser_consume_token (the_parser
);
9434 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9438 c_parser_consume_pragma (parser
);
9439 if (c_parser_next_token_is (parser
, CPP_STRING
))
9441 name
= c_parser_peek_token (parser
)->value
;
9442 c_parser_consume_token (parser
);
9445 c_parser_error (parser
, "expected string literal");
9446 c_parser_skip_to_pragma_eol (parser
);
9449 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9452 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9454 /* Returns name of the next clause.
9455 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9456 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9457 returned and the token is consumed. */
9459 static pragma_omp_clause
9460 c_parser_omp_clause_name (c_parser
*parser
)
9462 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9464 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9465 result
= PRAGMA_OMP_CLAUSE_IF
;
9466 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9467 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9468 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9469 result
= PRAGMA_OMP_CLAUSE_FOR
;
9470 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9472 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9477 if (!strcmp ("aligned", p
))
9478 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9481 if (!strcmp ("collapse", p
))
9482 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9483 else if (!strcmp ("copyin", p
))
9484 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9485 else if (!strcmp ("copyprivate", p
))
9486 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9489 if (!strcmp ("depend", p
))
9490 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9491 else if (!strcmp ("device", p
))
9492 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9493 else if (!strcmp ("dist_schedule", p
))
9494 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9497 if (!strcmp ("final", p
))
9498 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9499 else if (!strcmp ("firstprivate", p
))
9500 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9501 else if (!strcmp ("from", p
))
9502 result
= PRAGMA_OMP_CLAUSE_FROM
;
9505 if (!strcmp ("inbranch", p
))
9506 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9509 if (!strcmp ("lastprivate", p
))
9510 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9511 else if (!strcmp ("linear", p
))
9512 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9515 if (!strcmp ("map", p
))
9516 result
= PRAGMA_OMP_CLAUSE_MAP
;
9517 else if (!strcmp ("mergeable", p
))
9518 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9521 if (!strcmp ("notinbranch", p
))
9522 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9523 else if (!strcmp ("nowait", p
))
9524 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9525 else if (!strcmp ("num_teams", p
))
9526 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9527 else if (!strcmp ("num_threads", p
))
9528 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9531 if (!strcmp ("ordered", p
))
9532 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9535 if (!strcmp ("parallel", p
))
9536 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9537 else if (!strcmp ("private", p
))
9538 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9539 else if (!strcmp ("proc_bind", p
))
9540 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9543 if (!strcmp ("reduction", p
))
9544 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9547 if (!strcmp ("safelen", p
))
9548 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9549 else if (!strcmp ("schedule", p
))
9550 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9551 else if (!strcmp ("sections", p
))
9552 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9553 else if (!strcmp ("shared", p
))
9554 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9555 else if (!strcmp ("simdlen", p
))
9556 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9559 if (!strcmp ("taskgroup", p
))
9560 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9561 else if (!strcmp ("thread_limit", p
))
9562 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9563 else if (!strcmp ("to", p
))
9564 result
= PRAGMA_OMP_CLAUSE_TO
;
9567 if (!strcmp ("uniform", p
))
9568 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9569 else if (!strcmp ("untied", p
))
9570 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9575 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9576 c_parser_consume_token (parser
);
9581 /* Validate that a clause of the given type does not already exist. */
9584 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9589 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9590 if (OMP_CLAUSE_CODE (c
) == code
)
9592 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9593 error_at (loc
, "too many %qs clauses", name
);
9601 variable-list , identifier
9603 If KIND is nonzero, create the appropriate node and install the
9604 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9605 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9607 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9608 return the list created. */
9611 c_parser_omp_variable_list (c_parser
*parser
,
9612 location_t clause_loc
,
9613 enum omp_clause_code kind
, tree list
)
9615 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9616 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9617 c_parser_error (parser
, "expected identifier");
9619 while (c_parser_next_token_is (parser
, CPP_NAME
)
9620 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9622 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9626 undeclared_variable (c_parser_peek_token (parser
)->location
,
9627 c_parser_peek_token (parser
)->value
);
9628 t
= error_mark_node
;
9631 c_parser_consume_token (parser
);
9633 if (t
== error_mark_node
)
9639 case OMP_CLAUSE_MAP
:
9640 case OMP_CLAUSE_FROM
:
9642 case OMP_CLAUSE_DEPEND
:
9643 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9645 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9647 c_parser_consume_token (parser
);
9648 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9649 low_bound
= c_parser_expression (parser
).value
;
9650 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9651 length
= integer_one_node
;
9655 if (!c_parser_require (parser
, CPP_COLON
,
9658 t
= error_mark_node
;
9661 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9662 length
= c_parser_expression (parser
).value
;
9664 /* Look for the closing `]'. */
9665 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9668 t
= error_mark_node
;
9671 t
= tree_cons (low_bound
, length
, t
);
9678 if (t
!= error_mark_node
)
9680 tree u
= build_omp_clause (clause_loc
, kind
);
9681 OMP_CLAUSE_DECL (u
) = t
;
9682 OMP_CLAUSE_CHAIN (u
) = list
;
9687 list
= tree_cons (t
, NULL_TREE
, list
);
9689 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9692 c_parser_consume_token (parser
);
9698 /* Similarly, but expect leading and trailing parenthesis. This is a very
9699 common case for omp clauses. */
9702 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9705 /* The clauses location. */
9706 location_t loc
= c_parser_peek_token (parser
)->location
;
9708 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9710 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9711 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9717 collapse ( constant-expression ) */
9720 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9722 tree c
, num
= error_mark_node
;
9726 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9728 loc
= c_parser_peek_token (parser
)->location
;
9729 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9731 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9732 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9734 if (num
== error_mark_node
)
9736 mark_exp_read (num
);
9737 num
= c_fully_fold (num
, false, NULL
);
9738 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9739 || !host_integerp (num
, 0)
9740 || (n
= tree_low_cst (num
, 0)) <= 0
9744 "collapse argument needs positive constant integer expression");
9747 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9748 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9749 OMP_CLAUSE_CHAIN (c
) = list
;
9754 copyin ( variable-list ) */
9757 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9759 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9763 copyprivate ( variable-list ) */
9766 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9768 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9772 default ( shared | none ) */
9775 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9777 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9778 location_t loc
= c_parser_peek_token (parser
)->location
;
9781 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9783 if (c_parser_next_token_is (parser
, CPP_NAME
))
9785 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9790 if (strcmp ("none", p
) != 0)
9792 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9796 if (strcmp ("shared", p
) != 0)
9798 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9805 c_parser_consume_token (parser
);
9810 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9812 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9814 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9817 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9818 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9819 OMP_CLAUSE_CHAIN (c
) = list
;
9820 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9826 firstprivate ( variable-list ) */
9829 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9831 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9835 final ( expression ) */
9838 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9840 location_t loc
= c_parser_peek_token (parser
)->location
;
9841 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9843 tree t
= c_parser_paren_condition (parser
);
9846 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9848 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9849 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9850 OMP_CLAUSE_CHAIN (c
) = list
;
9854 c_parser_error (parser
, "expected %<(%>");
9860 if ( expression ) */
9863 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9865 location_t loc
= c_parser_peek_token (parser
)->location
;
9866 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9868 tree t
= c_parser_paren_condition (parser
);
9871 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9873 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9874 OMP_CLAUSE_IF_EXPR (c
) = t
;
9875 OMP_CLAUSE_CHAIN (c
) = list
;
9879 c_parser_error (parser
, "expected %<(%>");
9885 lastprivate ( variable-list ) */
9888 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9890 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9897 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9901 /* FIXME: Should we allow duplicates? */
9902 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9904 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9905 OMP_CLAUSE_MERGEABLE
);
9906 OMP_CLAUSE_CHAIN (c
) = list
;
9915 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9918 location_t loc
= c_parser_peek_token (parser
)->location
;
9920 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9922 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9923 OMP_CLAUSE_CHAIN (c
) = list
;
9928 num_threads ( expression ) */
9931 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9933 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9934 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9936 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9937 tree c
, t
= c_parser_expression (parser
).value
;
9939 t
= c_fully_fold (t
, false, NULL
);
9941 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9943 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9945 c_parser_error (parser
, "expected integer expression");
9949 /* Attempt to statically determine when the number isn't positive. */
9950 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9951 build_int_cst (TREE_TYPE (t
), 0));
9952 if (CAN_HAVE_LOCATION_P (c
))
9953 SET_EXPR_LOCATION (c
, expr_loc
);
9954 if (c
== boolean_true_node
)
9956 warning_at (expr_loc
, 0,
9957 "%<num_threads%> value must be positive");
9958 t
= integer_one_node
;
9961 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9963 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9964 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9965 OMP_CLAUSE_CHAIN (c
) = list
;
9976 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9980 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9982 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9983 OMP_CLAUSE_ORDERED
);
9984 OMP_CLAUSE_CHAIN (c
) = list
;
9990 private ( variable-list ) */
9993 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9995 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9999 reduction ( reduction-operator : variable-list )
10001 reduction-operator:
10002 One of: + * - & ^ | && ||
10006 reduction-operator:
10007 One of: + * - & ^ | && || max min
10011 reduction-operator:
10012 One of: + * - & ^ | && ||
10016 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10018 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10019 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10021 enum tree_code code
= ERROR_MARK
;
10022 tree reduc_id
= NULL_TREE
;
10024 switch (c_parser_peek_token (parser
)->type
)
10036 code
= BIT_AND_EXPR
;
10039 code
= BIT_XOR_EXPR
;
10042 code
= BIT_IOR_EXPR
;
10045 code
= TRUTH_ANDIF_EXPR
;
10048 code
= TRUTH_ORIF_EXPR
;
10053 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10054 if (strcmp (p
, "min") == 0)
10059 if (strcmp (p
, "max") == 0)
10064 reduc_id
= c_parser_peek_token (parser
)->value
;
10068 c_parser_error (parser
,
10069 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10070 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10071 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10074 c_parser_consume_token (parser
);
10075 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10076 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10080 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10081 OMP_CLAUSE_REDUCTION
, list
);
10082 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10084 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10085 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10086 if (code
== ERROR_MARK
10087 || !(INTEGRAL_TYPE_P (type
)
10088 || TREE_CODE (type
) == REAL_TYPE
10089 || TREE_CODE (type
) == COMPLEX_TYPE
))
10090 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10091 = c_omp_reduction_lookup (reduc_id
,
10092 TYPE_MAIN_VARIANT (type
));
10097 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10103 schedule ( schedule-kind )
10104 schedule ( schedule-kind , expression )
10107 static | dynamic | guided | runtime | auto
10111 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10114 location_t loc
= c_parser_peek_token (parser
)->location
;
10116 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10119 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10121 if (c_parser_next_token_is (parser
, CPP_NAME
))
10123 tree kind
= c_parser_peek_token (parser
)->value
;
10124 const char *p
= IDENTIFIER_POINTER (kind
);
10129 if (strcmp ("dynamic", p
) != 0)
10131 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10135 if (strcmp ("guided", p
) != 0)
10137 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10141 if (strcmp ("runtime", p
) != 0)
10143 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10150 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10151 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10152 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10153 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10157 c_parser_consume_token (parser
);
10158 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10161 c_parser_consume_token (parser
);
10163 here
= c_parser_peek_token (parser
)->location
;
10164 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10166 t
= c_fully_fold (t
, false, NULL
);
10168 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10169 error_at (here
, "schedule %<runtime%> does not take "
10170 "a %<chunk_size%> parameter");
10171 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10173 "schedule %<auto%> does not take "
10174 "a %<chunk_size%> parameter");
10175 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10176 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10178 c_parser_error (parser
, "expected integer expression");
10180 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10183 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10184 "expected %<,%> or %<)%>");
10186 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10187 OMP_CLAUSE_CHAIN (c
) = list
;
10191 c_parser_error (parser
, "invalid schedule kind");
10192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10197 shared ( variable-list ) */
10200 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10202 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10209 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10213 /* FIXME: Should we allow duplicates? */
10214 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10216 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10217 OMP_CLAUSE_UNTIED
);
10218 OMP_CLAUSE_CHAIN (c
) = list
;
10228 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10229 enum omp_clause_code code
, tree list
)
10231 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10233 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10234 OMP_CLAUSE_CHAIN (c
) = list
;
10246 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10247 enum omp_clause_code code
, tree list
)
10249 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10250 OMP_CLAUSE_CHAIN (c
) = list
;
10256 num_teams ( expression ) */
10259 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10261 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10262 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10264 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10265 tree c
, t
= c_parser_expression (parser
).value
;
10267 t
= c_fully_fold (t
, false, NULL
);
10269 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10271 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10273 c_parser_error (parser
, "expected integer expression");
10277 /* Attempt to statically determine when the number isn't positive. */
10278 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10279 build_int_cst (TREE_TYPE (t
), 0));
10280 if (CAN_HAVE_LOCATION_P (c
))
10281 SET_EXPR_LOCATION (c
, expr_loc
);
10282 if (c
== boolean_true_node
)
10284 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10285 t
= integer_one_node
;
10288 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10290 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10291 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10292 OMP_CLAUSE_CHAIN (c
) = list
;
10300 thread_limit ( expression ) */
10303 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10305 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10306 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10308 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10309 tree c
, t
= c_parser_expression (parser
).value
;
10311 t
= c_fully_fold (t
, false, NULL
);
10313 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10315 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10317 c_parser_error (parser
, "expected integer expression");
10321 /* Attempt to statically determine when the number isn't positive. */
10322 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10323 build_int_cst (TREE_TYPE (t
), 0));
10324 if (CAN_HAVE_LOCATION_P (c
))
10325 SET_EXPR_LOCATION (c
, expr_loc
);
10326 if (c
== boolean_true_node
)
10328 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10329 t
= integer_one_node
;
10332 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10335 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10336 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10337 OMP_CLAUSE_CHAIN (c
) = list
;
10345 aligned ( variable-list )
10346 aligned ( variable-list : constant-expression ) */
10349 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10351 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10354 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10357 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10358 OMP_CLAUSE_ALIGNED
, list
);
10360 if (c_parser_next_token_is (parser
, CPP_COLON
))
10362 c_parser_consume_token (parser
);
10363 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10364 mark_exp_read (alignment
);
10365 alignment
= c_fully_fold (alignment
, false, NULL
);
10366 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10367 && TREE_CODE (alignment
) != INTEGER_CST
10368 && tree_int_cst_sgn (alignment
) != 1)
10370 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10371 "be positive constant integer expression");
10372 alignment
= NULL_TREE
;
10375 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10376 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10379 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10384 linear ( variable-list )
10385 linear ( variable-list : expression ) */
10388 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
10390 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10393 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10396 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10397 OMP_CLAUSE_LINEAR
, list
);
10399 if (c_parser_next_token_is (parser
, CPP_COLON
))
10401 c_parser_consume_token (parser
);
10402 step
= c_parser_expression (parser
).value
;
10403 mark_exp_read (step
);
10404 step
= c_fully_fold (step
, false, NULL
);
10405 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10407 error_at (clause_loc
, "%<linear%> clause step expression must "
10409 step
= integer_one_node
;
10414 step
= integer_one_node
;
10416 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10418 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10421 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10426 safelen ( constant-expression ) */
10429 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10431 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10434 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10437 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10439 t
= c_fully_fold (t
, false, NULL
);
10440 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10441 && TREE_CODE (t
) != INTEGER_CST
10442 && tree_int_cst_sgn (t
) != 1)
10444 error_at (clause_loc
, "%<safelen%> clause expression must "
10445 "be positive constant integer expression");
10449 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10450 if (t
== NULL_TREE
|| t
== error_mark_node
)
10453 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10455 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10456 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10457 OMP_CLAUSE_CHAIN (c
) = list
;
10462 simdlen ( constant-expression ) */
10465 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10467 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10470 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10473 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10475 t
= c_fully_fold (t
, false, NULL
);
10476 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10477 && TREE_CODE (t
) != INTEGER_CST
10478 && tree_int_cst_sgn (t
) != 1)
10480 error_at (clause_loc
, "%<simdlen%> clause expression must "
10481 "be positive constant integer expression");
10485 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10486 if (t
== NULL_TREE
|| t
== error_mark_node
)
10489 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10491 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10492 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10493 OMP_CLAUSE_CHAIN (c
) = list
;
10498 depend ( depend-kind: variable-list )
10501 in | out | inout */
10504 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10506 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10507 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10510 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10513 if (c_parser_next_token_is (parser
, CPP_NAME
))
10515 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10516 if (strcmp ("in", p
) == 0)
10517 kind
= OMP_CLAUSE_DEPEND_IN
;
10518 else if (strcmp ("inout", p
) == 0)
10519 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10520 else if (strcmp ("out", p
) == 0)
10521 kind
= OMP_CLAUSE_DEPEND_OUT
;
10528 c_parser_consume_token (parser
);
10529 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10532 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10533 OMP_CLAUSE_DEPEND
, list
);
10535 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10536 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10538 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10542 c_parser_error (parser
, "invalid depend kind");
10544 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10549 map ( map-kind: variable-list )
10550 map ( variable-list )
10553 alloc | to | from | tofrom */
10556 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10558 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10559 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10562 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10565 if (c_parser_next_token_is (parser
, CPP_NAME
)
10566 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10568 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10569 if (strcmp ("alloc", p
) == 0)
10570 kind
= OMP_CLAUSE_MAP_ALLOC
;
10571 else if (strcmp ("to", p
) == 0)
10572 kind
= OMP_CLAUSE_MAP_TO
;
10573 else if (strcmp ("from", p
) == 0)
10574 kind
= OMP_CLAUSE_MAP_FROM
;
10575 else if (strcmp ("tofrom", p
) == 0)
10576 kind
= OMP_CLAUSE_MAP_TOFROM
;
10579 c_parser_error (parser
, "invalid map kind");
10580 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10584 c_parser_consume_token (parser
);
10585 c_parser_consume_token (parser
);
10588 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10590 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10591 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10593 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10598 device ( expression ) */
10601 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10603 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10604 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10606 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10608 t
= c_fully_fold (t
, false, NULL
);
10610 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10612 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10614 c_parser_error (parser
, "expected integer expression");
10618 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10620 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10621 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10622 OMP_CLAUSE_CHAIN (c
) = list
;
10630 dist_schedule ( static )
10631 dist_schedule ( static , expression ) */
10634 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10636 tree c
, t
= NULL_TREE
;
10637 location_t loc
= c_parser_peek_token (parser
)->location
;
10639 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10642 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10644 c_parser_error (parser
, "invalid dist_schedule kind");
10645 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10650 c_parser_consume_token (parser
);
10651 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10653 c_parser_consume_token (parser
);
10655 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10657 t
= c_fully_fold (t
, false, NULL
);
10658 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10661 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10662 "expected %<,%> or %<)%>");
10664 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10665 if (t
== error_mark_node
)
10668 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10669 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10670 OMP_CLAUSE_CHAIN (c
) = list
;
10675 proc_bind ( proc-bind-kind )
10678 master | close | spread */
10681 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10683 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10684 enum omp_clause_proc_bind_kind kind
;
10687 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10690 if (c_parser_next_token_is (parser
, CPP_NAME
))
10692 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10693 if (strcmp ("master", p
) == 0)
10694 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10695 else if (strcmp ("close", p
) == 0)
10696 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10697 else if (strcmp ("spread", p
) == 0)
10698 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10705 c_parser_consume_token (parser
);
10706 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10707 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10708 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10709 OMP_CLAUSE_CHAIN (c
) = list
;
10713 c_parser_error (parser
, "invalid proc_bind kind");
10714 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10719 to ( variable-list ) */
10722 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10724 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10728 from ( variable-list ) */
10731 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10733 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10737 uniform ( variable-list ) */
10740 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10742 /* The clauses location. */
10743 location_t loc
= c_parser_peek_token (parser
)->location
;
10745 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10747 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10749 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10754 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10755 is a bitmask in MASK. Return the list of clauses found; the result
10756 of clause default goes in *pdefault. */
10759 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10760 const char *where
, bool finish_p
= true)
10762 tree clauses
= NULL
;
10765 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10768 pragma_omp_clause c_kind
;
10769 const char *c_name
;
10770 tree prev
= clauses
;
10772 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10773 c_parser_consume_token (parser
);
10775 here
= c_parser_peek_token (parser
)->location
;
10776 c_kind
= c_parser_omp_clause_name (parser
);
10780 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10781 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10782 c_name
= "collapse";
10784 case PRAGMA_OMP_CLAUSE_COPYIN
:
10785 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10788 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10789 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10790 c_name
= "copyprivate";
10792 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10793 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10794 c_name
= "default";
10796 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
10797 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
10798 c_name
= "firstprivate";
10800 case PRAGMA_OMP_CLAUSE_FINAL
:
10801 clauses
= c_parser_omp_clause_final (parser
, clauses
);
10804 case PRAGMA_OMP_CLAUSE_IF
:
10805 clauses
= c_parser_omp_clause_if (parser
, clauses
);
10808 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
10809 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
10810 c_name
= "lastprivate";
10812 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
10813 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
10814 c_name
= "mergeable";
10816 case PRAGMA_OMP_CLAUSE_NOWAIT
:
10817 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
10820 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
10821 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
10822 c_name
= "num_threads";
10824 case PRAGMA_OMP_CLAUSE_ORDERED
:
10825 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
10826 c_name
= "ordered";
10828 case PRAGMA_OMP_CLAUSE_PRIVATE
:
10829 clauses
= c_parser_omp_clause_private (parser
, clauses
);
10830 c_name
= "private";
10832 case PRAGMA_OMP_CLAUSE_REDUCTION
:
10833 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
10834 c_name
= "reduction";
10836 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10837 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10838 c_name
= "schedule";
10840 case PRAGMA_OMP_CLAUSE_SHARED
:
10841 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10844 case PRAGMA_OMP_CLAUSE_UNTIED
:
10845 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
10848 case PRAGMA_OMP_CLAUSE_INBRANCH
:
10849 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
10851 c_name
= "inbranch";
10853 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
10854 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
10856 c_name
= "notinbranch";
10858 case PRAGMA_OMP_CLAUSE_PARALLEL
:
10860 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
10862 c_name
= "parallel";
10866 error_at (here
, "%qs must be the first clause of %qs",
10871 case PRAGMA_OMP_CLAUSE_FOR
:
10873 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
10877 goto clause_not_first
;
10879 case PRAGMA_OMP_CLAUSE_SECTIONS
:
10881 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
10883 c_name
= "sections";
10885 goto clause_not_first
;
10887 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
10889 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
10891 c_name
= "taskgroup";
10893 goto clause_not_first
;
10895 case PRAGMA_OMP_CLAUSE_TO
:
10896 clauses
= c_parser_omp_clause_to (parser
, clauses
);
10899 case PRAGMA_OMP_CLAUSE_FROM
:
10900 clauses
= c_parser_omp_clause_from (parser
, clauses
);
10903 case PRAGMA_OMP_CLAUSE_UNIFORM
:
10904 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
10905 c_name
= "uniform";
10907 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
10908 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
10909 c_name
= "num_teams";
10911 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
10912 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
10913 c_name
= "thread_limit";
10915 case PRAGMA_OMP_CLAUSE_ALIGNED
:
10916 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
10917 c_name
= "aligned";
10919 case PRAGMA_OMP_CLAUSE_LINEAR
:
10920 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
10923 case PRAGMA_OMP_CLAUSE_DEPEND
:
10924 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
10927 case PRAGMA_OMP_CLAUSE_MAP
:
10928 clauses
= c_parser_omp_clause_map (parser
, clauses
);
10931 case PRAGMA_OMP_CLAUSE_DEVICE
:
10932 clauses
= c_parser_omp_clause_device (parser
, clauses
);
10935 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
10936 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
10937 c_name
= "dist_schedule";
10939 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
10940 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
10941 c_name
= "proc_bind";
10943 case PRAGMA_OMP_CLAUSE_SAFELEN
:
10944 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
10945 c_name
= "safelen";
10947 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
10948 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
10949 c_name
= "simdlen";
10952 c_parser_error (parser
, "expected %<#pragma omp%> clause");
10958 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
10960 /* Remove the invalid clause(s) from the list to avoid
10961 confusing the rest of the compiler. */
10963 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
10968 c_parser_skip_to_pragma_eol (parser
);
10971 return c_finish_omp_clauses (clauses
);
10980 In practice, we're also interested in adding the statement to an
10981 outer node. So it is convenient if we work around the fact that
10982 c_parser_statement calls add_stmt. */
10985 c_parser_omp_structured_block (c_parser
*parser
)
10987 tree stmt
= push_stmt_list ();
10988 c_parser_statement (parser
);
10989 return pop_stmt_list (stmt
);
10993 # pragma omp atomic new-line
10997 x binop= expr | x++ | ++x | x-- | --x
10999 +, *, -, /, &, ^, |, <<, >>
11001 where x is an lvalue expression with scalar type.
11004 # pragma omp atomic new-line
11007 # pragma omp atomic read new-line
11010 # pragma omp atomic write new-line
11013 # pragma omp atomic update new-line
11016 # pragma omp atomic capture new-line
11019 # pragma omp atomic capture new-line
11027 expression-stmt | x = x binop expr
11029 v = expression-stmt
11031 { v = x; update-stmt; } | { update-stmt; v = x; }
11035 expression-stmt | x = x binop expr | x = expr binop x
11039 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11041 where x and v are lvalue expressions with scalar type.
11043 LOC is the location of the #pragma token. */
11046 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11048 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11049 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11050 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11051 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11052 struct c_expr expr
;
11054 bool structured_block
= false;
11055 bool swapped
= false;
11056 bool seq_cst
= false;
11058 if (c_parser_next_token_is (parser
, CPP_NAME
))
11060 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11062 if (!strcmp (p
, "read"))
11063 code
= OMP_ATOMIC_READ
;
11064 else if (!strcmp (p
, "write"))
11066 else if (!strcmp (p
, "update"))
11068 else if (!strcmp (p
, "capture"))
11069 code
= OMP_ATOMIC_CAPTURE_NEW
;
11073 c_parser_consume_token (parser
);
11075 if (c_parser_next_token_is (parser
, CPP_NAME
))
11077 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11078 if (!strcmp (p
, "seq_cst"))
11081 c_parser_consume_token (parser
);
11084 c_parser_skip_to_pragma_eol (parser
);
11088 case OMP_ATOMIC_READ
:
11089 case NOP_EXPR
: /* atomic write */
11090 v
= c_parser_unary_expression (parser
).value
;
11091 v
= c_fully_fold (v
, false, NULL
);
11092 if (v
== error_mark_node
)
11094 loc
= c_parser_peek_token (parser
)->location
;
11095 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11097 if (code
== NOP_EXPR
)
11098 lhs
= c_parser_expression (parser
).value
;
11100 lhs
= c_parser_unary_expression (parser
).value
;
11101 lhs
= c_fully_fold (lhs
, false, NULL
);
11102 if (lhs
== error_mark_node
)
11104 if (code
== NOP_EXPR
)
11106 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11114 case OMP_ATOMIC_CAPTURE_NEW
:
11115 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11117 c_parser_consume_token (parser
);
11118 structured_block
= true;
11122 v
= c_parser_unary_expression (parser
).value
;
11123 v
= c_fully_fold (v
, false, NULL
);
11124 if (v
== error_mark_node
)
11126 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11134 /* For structured_block case we don't know yet whether
11135 old or new x should be captured. */
11137 eloc
= c_parser_peek_token (parser
)->location
;
11138 expr
= c_parser_unary_expression (parser
);
11140 expr
= default_function_array_conversion (eloc
, expr
);
11141 unfolded_lhs
= expr
.value
;
11142 lhs
= c_fully_fold (lhs
, false, NULL
);
11144 switch (TREE_CODE (lhs
))
11148 c_parser_skip_to_end_of_block_or_statement (parser
);
11149 if (structured_block
)
11151 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11152 c_parser_consume_token (parser
);
11153 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11155 c_parser_skip_to_end_of_block_or_statement (parser
);
11156 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11157 c_parser_consume_token (parser
);
11162 case POSTINCREMENT_EXPR
:
11163 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11164 code
= OMP_ATOMIC_CAPTURE_OLD
;
11166 case PREINCREMENT_EXPR
:
11167 lhs
= TREE_OPERAND (lhs
, 0);
11168 unfolded_lhs
= NULL_TREE
;
11169 opcode
= PLUS_EXPR
;
11170 rhs
= integer_one_node
;
11173 case POSTDECREMENT_EXPR
:
11174 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11175 code
= OMP_ATOMIC_CAPTURE_OLD
;
11177 case PREDECREMENT_EXPR
:
11178 lhs
= TREE_OPERAND (lhs
, 0);
11179 unfolded_lhs
= NULL_TREE
;
11180 opcode
= MINUS_EXPR
;
11181 rhs
= integer_one_node
;
11184 case COMPOUND_EXPR
:
11185 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11186 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11187 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11188 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11189 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11190 (TREE_OPERAND (lhs
, 1), 0), 0)))
11192 /* Undo effects of boolean_increment for post {in,de}crement. */
11193 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11196 if (TREE_CODE (lhs
) == MODIFY_EXPR
11197 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11199 /* Undo effects of boolean_increment. */
11200 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11202 /* This is pre or post increment. */
11203 rhs
= TREE_OPERAND (lhs
, 1);
11204 lhs
= TREE_OPERAND (lhs
, 0);
11205 unfolded_lhs
= NULL_TREE
;
11207 if (code
== OMP_ATOMIC_CAPTURE_NEW
11208 && !structured_block
11209 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11210 code
= OMP_ATOMIC_CAPTURE_OLD
;
11213 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11214 && TREE_OPERAND (lhs
, 0)
11215 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11217 /* This is pre or post decrement. */
11218 rhs
= TREE_OPERAND (lhs
, 1);
11219 lhs
= TREE_OPERAND (lhs
, 0);
11220 unfolded_lhs
= NULL_TREE
;
11222 if (code
== OMP_ATOMIC_CAPTURE_NEW
11223 && !structured_block
11224 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11225 code
= OMP_ATOMIC_CAPTURE_OLD
;
11231 switch (c_parser_peek_token (parser
)->type
)
11234 opcode
= MULT_EXPR
;
11237 opcode
= TRUNC_DIV_EXPR
;
11240 opcode
= PLUS_EXPR
;
11243 opcode
= MINUS_EXPR
;
11245 case CPP_LSHIFT_EQ
:
11246 opcode
= LSHIFT_EXPR
;
11248 case CPP_RSHIFT_EQ
:
11249 opcode
= RSHIFT_EXPR
;
11252 opcode
= BIT_AND_EXPR
;
11255 opcode
= BIT_IOR_EXPR
;
11258 opcode
= BIT_XOR_EXPR
;
11261 c_parser_consume_token (parser
);
11262 eloc
= c_parser_peek_token (parser
)->location
;
11263 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11265 switch (TREE_CODE (rhs1
))
11268 case TRUNC_DIV_EXPR
:
11276 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11278 opcode
= TREE_CODE (rhs1
);
11279 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11280 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11283 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11285 opcode
= TREE_CODE (rhs1
);
11286 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11287 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11288 swapped
= !commutative_tree_code (opcode
);
11297 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11299 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11301 code
= OMP_ATOMIC_CAPTURE_OLD
;
11304 expr
= default_function_array_read_conversion (eloc
, expr
);
11305 unfolded_lhs1
= expr
.value
;
11306 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11308 c_parser_consume_token (parser
);
11311 if (structured_block
)
11314 expr
= default_function_array_read_conversion (eloc
, expr
);
11315 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11320 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11323 c_parser_error (parser
,
11324 "invalid operator for %<#pragma omp atomic%>");
11328 /* Arrange to pass the location of the assignment operator to
11329 c_finish_omp_atomic. */
11330 loc
= c_parser_peek_token (parser
)->location
;
11331 c_parser_consume_token (parser
);
11332 eloc
= c_parser_peek_token (parser
)->location
;
11333 expr
= c_parser_expression (parser
);
11334 expr
= default_function_array_read_conversion (eloc
, expr
);
11336 rhs
= c_fully_fold (rhs
, false, NULL
);
11340 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11342 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11344 v
= c_parser_unary_expression (parser
).value
;
11345 v
= c_fully_fold (v
, false, NULL
);
11346 if (v
== error_mark_node
)
11348 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11350 eloc
= c_parser_peek_token (parser
)->location
;
11351 expr
= c_parser_unary_expression (parser
);
11353 expr
= default_function_array_read_conversion (eloc
, expr
);
11354 unfolded_lhs1
= expr
.value
;
11355 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11356 if (lhs1
== error_mark_node
)
11359 if (structured_block
)
11361 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11362 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11365 if (unfolded_lhs
&& unfolded_lhs1
11366 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11368 error ("%<#pragma omp atomic capture%> uses two different "
11369 "expressions for memory");
11370 stmt
= error_mark_node
;
11373 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11375 if (stmt
!= error_mark_node
)
11378 if (!structured_block
)
11379 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11384 # pragma omp barrier new-line
11388 c_parser_omp_barrier (c_parser
*parser
)
11390 location_t loc
= c_parser_peek_token (parser
)->location
;
11391 c_parser_consume_pragma (parser
);
11392 c_parser_skip_to_pragma_eol (parser
);
11394 c_finish_omp_barrier (loc
);
11398 # pragma omp critical [(name)] new-line
11401 LOC is the location of the #pragma itself. */
11404 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11406 tree stmt
, name
= NULL
;
11408 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11410 c_parser_consume_token (parser
);
11411 if (c_parser_next_token_is (parser
, CPP_NAME
))
11413 name
= c_parser_peek_token (parser
)->value
;
11414 c_parser_consume_token (parser
);
11415 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11418 c_parser_error (parser
, "expected identifier");
11420 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11421 c_parser_error (parser
, "expected %<(%> or end of line");
11422 c_parser_skip_to_pragma_eol (parser
);
11424 stmt
= c_parser_omp_structured_block (parser
);
11425 return c_finish_omp_critical (loc
, stmt
, name
);
11429 # pragma omp flush flush-vars[opt] new-line
11432 ( variable-list ) */
11435 c_parser_omp_flush (c_parser
*parser
)
11437 location_t loc
= c_parser_peek_token (parser
)->location
;
11438 c_parser_consume_pragma (parser
);
11439 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11440 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11441 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11442 c_parser_error (parser
, "expected %<(%> or end of line");
11443 c_parser_skip_to_pragma_eol (parser
);
11445 c_finish_omp_flush (loc
);
11448 /* Parse the restricted form of the for statement allowed by OpenMP.
11449 The real trick here is to determine the loop control variable early
11450 so that we can push a new decl if necessary to make it private.
11451 LOC is the location of the OMP in "#pragma omp". */
11454 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11455 tree clauses
, tree
*cclauses
)
11457 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11458 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11459 bool fail
= false, open_brace_parsed
= false;
11460 int i
, collapse
= 1, nbraces
= 0;
11461 location_t for_loc
;
11462 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11464 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11465 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11466 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
11468 gcc_assert (collapse
>= 1);
11470 declv
= make_tree_vec (collapse
);
11471 initv
= make_tree_vec (collapse
);
11472 condv
= make_tree_vec (collapse
);
11473 incrv
= make_tree_vec (collapse
);
11475 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11477 c_parser_error (parser
, "for statement expected");
11480 for_loc
= c_parser_peek_token (parser
)->location
;
11481 c_parser_consume_token (parser
);
11483 for (i
= 0; i
< collapse
; i
++)
11485 int bracecount
= 0;
11487 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11490 /* Parse the initialization declaration or expression. */
11491 if (c_parser_next_tokens_start_declaration (parser
))
11494 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11495 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11497 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11500 if (DECL_INITIAL (decl
) == error_mark_node
)
11501 decl
= error_mark_node
;
11504 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11505 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11507 struct c_expr decl_exp
;
11508 struct c_expr init_exp
;
11509 location_t init_loc
;
11511 decl_exp
= c_parser_postfix_expression (parser
);
11512 decl
= decl_exp
.value
;
11514 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11516 init_loc
= c_parser_peek_token (parser
)->location
;
11517 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11518 init_exp
= default_function_array_read_conversion (init_loc
,
11520 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11521 NOP_EXPR
, init_loc
, init_exp
.value
,
11522 init_exp
.original_type
);
11523 init
= c_process_expr_stmt (init_loc
, init
);
11525 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11530 c_parser_error (parser
,
11531 "expected iteration declaration or initialization");
11532 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11538 /* Parse the loop condition. */
11540 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11542 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11543 struct c_expr cond_expr
11544 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11546 cond
= cond_expr
.value
;
11547 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11548 cond
= c_fully_fold (cond
, false, NULL
);
11549 switch (cond_expr
.original_code
)
11557 if (code
== CILK_SIMD
)
11561 /* Can't be cond = error_mark_node, because we want to preserve
11562 the location until c_finish_omp_for. */
11563 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11566 protected_set_expr_location (cond
, cond_loc
);
11568 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11570 /* Parse the increment expression. */
11572 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11574 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11576 incr
= c_process_expr_stmt (incr_loc
,
11577 c_parser_expression (parser
).value
);
11579 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11581 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11585 TREE_VEC_ELT (declv
, i
) = decl
;
11586 TREE_VEC_ELT (initv
, i
) = init
;
11587 TREE_VEC_ELT (condv
, i
) = cond
;
11588 TREE_VEC_ELT (incrv
, i
) = incr
;
11592 if (i
== collapse
- 1)
11595 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11596 in between the collapsed for loops to be still considered perfectly
11597 nested. Hopefully the final version clarifies this.
11598 For now handle (multiple) {'s and empty statements. */
11601 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11603 c_parser_consume_token (parser
);
11606 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11608 c_parser_consume_token (parser
);
11611 else if (bracecount
11612 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11613 c_parser_consume_token (parser
);
11616 c_parser_error (parser
, "not enough perfectly nested loops");
11619 open_brace_parsed
= true;
11629 nbraces
+= bracecount
;
11632 save_break
= c_break_label
;
11633 if (code
== CILK_SIMD
)
11634 c_break_label
= build_int_cst (size_type_node
, 2);
11636 c_break_label
= size_one_node
;
11637 save_cont
= c_cont_label
;
11638 c_cont_label
= NULL_TREE
;
11639 body
= push_stmt_list ();
11641 if (open_brace_parsed
)
11643 location_t here
= c_parser_peek_token (parser
)->location
;
11644 stmt
= c_begin_compound_stmt (true);
11645 c_parser_compound_statement_nostart (parser
);
11646 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11649 add_stmt (c_parser_c99_block_statement (parser
));
11652 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11653 SET_EXPR_LOCATION (t
, loc
);
11657 body
= pop_stmt_list (body
);
11658 c_break_label
= save_break
;
11659 c_cont_label
= save_cont
;
11663 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11665 c_parser_consume_token (parser
);
11668 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11669 c_parser_consume_token (parser
);
11672 c_parser_error (parser
, "collapsed loops not perfectly nested");
11675 location_t here
= c_parser_peek_token (parser
)->location
;
11676 stmt
= c_begin_compound_stmt (true);
11678 c_parser_compound_statement_nostart (parser
);
11679 body
= c_end_compound_stmt (here
, stmt
, true);
11686 /* Only bother calling c_finish_omp_for if we haven't already generated
11687 an error from the initialization parsing. */
11690 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11691 incrv
, body
, NULL
);
11694 if (cclauses
!= NULL
11695 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11698 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11699 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11700 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11701 c
= &OMP_CLAUSE_CHAIN (*c
);
11704 for (i
= 0; i
< collapse
; i
++)
11705 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11708 c
= &OMP_CLAUSE_CHAIN (*c
);
11709 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11712 "iteration variable %qD should not be firstprivate",
11713 OMP_CLAUSE_DECL (*c
));
11714 *c
= OMP_CLAUSE_CHAIN (*c
);
11718 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11719 change it to shared (decl) in
11720 OMP_PARALLEL_CLAUSES. */
11721 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11722 OMP_CLAUSE_LASTPRIVATE
);
11723 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11724 OMP_CLAUSE_CHAIN (l
) = clauses
;
11726 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11730 OMP_FOR_CLAUSES (stmt
) = clauses
;
11735 while (!for_block
->is_empty ())
11737 /* FIXME diagnostics: LOC below should be the actual location of
11738 this particular for block. We need to build a list of
11739 locations to go along with FOR_BLOCK. */
11740 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11743 release_tree_vector (for_block
);
11747 /* Helper function for OpenMP parsing, split clauses and call
11748 finish_omp_clauses on each of the set of clauses afterwards. */
11751 omp_split_clauses (location_t loc
, enum tree_code code
,
11752 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11755 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11756 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11758 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11762 #pragma omp simd simd-clause[optseq] new-line
11765 LOC is the location of the #pragma token.
11768 #define OMP_SIMD_CLAUSE_MASK \
11769 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
11770 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
11771 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
11772 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11773 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11774 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11775 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
11778 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
11779 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11781 tree block
, clauses
, ret
;
11783 strcat (p_name
, " simd");
11784 mask
|= OMP_SIMD_CLAUSE_MASK
;
11785 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
11787 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11790 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
11791 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
11794 block
= c_begin_compound_stmt (true);
11795 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
11796 block
= c_end_compound_stmt (loc
, block
, true);
11803 #pragma omp for for-clause[optseq] new-line
11807 #pragma omp for simd for-simd-clause[optseq] new-line
11810 LOC is the location of the #pragma token.
11813 #define OMP_FOR_CLAUSE_MASK \
11814 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11815 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11816 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11817 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11818 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
11819 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
11820 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11821 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11824 c_parser_omp_for (location_t loc
, c_parser
*parser
,
11825 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11827 tree block
, clauses
, ret
;
11829 strcat (p_name
, " for");
11830 mask
|= OMP_FOR_CLAUSE_MASK
;
11832 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
11834 if (c_parser_next_token_is (parser
, CPP_NAME
))
11836 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11838 if (strcmp (p
, "simd") == 0)
11840 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
11841 if (cclauses
== NULL
)
11842 cclauses
= cclauses_buf
;
11844 c_parser_consume_token (parser
);
11845 if (!flag_openmp
) /* flag_openmp_simd */
11846 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
11847 block
= c_begin_compound_stmt (true);
11848 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
11849 block
= c_end_compound_stmt (loc
, block
, true);
11850 if (ret
== NULL_TREE
)
11852 ret
= make_node (OMP_FOR
);
11853 TREE_TYPE (ret
) = void_type_node
;
11854 OMP_FOR_BODY (ret
) = block
;
11855 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11856 SET_EXPR_LOCATION (ret
, loc
);
11861 if (!flag_openmp
) /* flag_openmp_simd */
11863 c_parser_skip_to_pragma_eol (parser
);
11867 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11870 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
11871 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11874 block
= c_begin_compound_stmt (true);
11875 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
11876 block
= c_end_compound_stmt (loc
, block
, true);
11883 # pragma omp master new-line
11886 LOC is the location of the #pragma token.
11890 c_parser_omp_master (location_t loc
, c_parser
*parser
)
11892 c_parser_skip_to_pragma_eol (parser
);
11893 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
11897 # pragma omp ordered new-line
11900 LOC is the location of the #pragma itself.
11904 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
11906 c_parser_skip_to_pragma_eol (parser
);
11907 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
11913 { section-sequence }
11916 section-directive[opt] structured-block
11917 section-sequence section-directive structured-block
11919 SECTIONS_LOC is the location of the #pragma omp sections. */
11922 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
11924 tree stmt
, substmt
;
11925 bool error_suppress
= false;
11928 loc
= c_parser_peek_token (parser
)->location
;
11929 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
11931 /* Avoid skipping until the end of the block. */
11932 parser
->error
= false;
11936 stmt
= push_stmt_list ();
11938 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
11940 substmt
= c_parser_omp_structured_block (parser
);
11941 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11942 SET_EXPR_LOCATION (substmt
, loc
);
11943 add_stmt (substmt
);
11948 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11950 if (c_parser_next_token_is (parser
, CPP_EOF
))
11953 loc
= c_parser_peek_token (parser
)->location
;
11954 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
11956 c_parser_consume_pragma (parser
);
11957 c_parser_skip_to_pragma_eol (parser
);
11958 error_suppress
= false;
11960 else if (!error_suppress
)
11962 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
11963 error_suppress
= true;
11966 substmt
= c_parser_omp_structured_block (parser
);
11967 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11968 SET_EXPR_LOCATION (substmt
, loc
);
11969 add_stmt (substmt
);
11971 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
11972 "expected %<#pragma omp section%> or %<}%>");
11974 substmt
= pop_stmt_list (stmt
);
11976 stmt
= make_node (OMP_SECTIONS
);
11977 SET_EXPR_LOCATION (stmt
, sections_loc
);
11978 TREE_TYPE (stmt
) = void_type_node
;
11979 OMP_SECTIONS_BODY (stmt
) = substmt
;
11981 return add_stmt (stmt
);
11985 # pragma omp sections sections-clause[optseq] newline
11988 LOC is the location of the #pragma token.
11991 #define OMP_SECTIONS_CLAUSE_MASK \
11992 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11993 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11994 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11995 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11996 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11999 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12000 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12002 tree block
, clauses
, ret
;
12004 strcat (p_name
, " sections");
12005 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12007 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12009 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12012 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12013 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12016 block
= c_begin_compound_stmt (true);
12017 ret
= c_parser_omp_sections_scope (loc
, parser
);
12019 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12020 block
= c_end_compound_stmt (loc
, block
, true);
12027 # pragma parallel parallel-clause new-line
12028 # pragma parallel for parallel-for-clause new-line
12029 # pragma parallel sections parallel-sections-clause new-line
12031 LOC is the location of the #pragma token.
12034 #define OMP_PARALLEL_CLAUSE_MASK \
12035 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12036 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12037 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12038 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12039 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12040 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12041 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12042 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12043 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12046 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12047 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12049 tree stmt
, clauses
, block
;
12051 strcat (p_name
, " parallel");
12052 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12054 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12056 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12057 if (cclauses
== NULL
)
12058 cclauses
= cclauses_buf
;
12060 c_parser_consume_token (parser
);
12061 if (!flag_openmp
) /* flag_openmp_simd */
12062 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12063 block
= c_begin_omp_parallel ();
12064 c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12066 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12068 OMP_PARALLEL_COMBINED (stmt
) = 1;
12073 error_at (loc
, "expected %<for%> after %qs", p_name
);
12074 c_parser_skip_to_pragma_eol (parser
);
12077 else if (!flag_openmp
) /* flag_openmp_simd */
12079 c_parser_skip_to_pragma_eol (parser
);
12082 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12084 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12085 if (strcmp (p
, "sections") == 0)
12087 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12088 if (cclauses
== NULL
)
12089 cclauses
= cclauses_buf
;
12091 c_parser_consume_token (parser
);
12092 block
= c_begin_omp_parallel ();
12093 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12094 stmt
= c_finish_omp_parallel (loc
,
12095 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12097 OMP_PARALLEL_COMBINED (stmt
) = 1;
12102 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12104 block
= c_begin_omp_parallel ();
12105 c_parser_statement (parser
);
12106 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12112 # pragma omp single single-clause[optseq] new-line
12115 LOC is the location of the #pragma.
12118 #define OMP_SINGLE_CLAUSE_MASK \
12119 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12120 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12121 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12122 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12125 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12127 tree stmt
= make_node (OMP_SINGLE
);
12128 SET_EXPR_LOCATION (stmt
, loc
);
12129 TREE_TYPE (stmt
) = void_type_node
;
12131 OMP_SINGLE_CLAUSES (stmt
)
12132 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12133 "#pragma omp single");
12134 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12136 return add_stmt (stmt
);
12140 # pragma omp task task-clause[optseq] new-line
12142 LOC is the location of the #pragma.
12145 #define OMP_TASK_CLAUSE_MASK \
12146 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12147 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12148 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12149 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12150 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12151 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12152 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12153 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12154 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12157 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12159 tree clauses
, block
;
12161 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12162 "#pragma omp task");
12164 block
= c_begin_omp_task ();
12165 c_parser_statement (parser
);
12166 return c_finish_omp_task (loc
, clauses
, block
);
12170 # pragma omp taskwait new-line
12174 c_parser_omp_taskwait (c_parser
*parser
)
12176 location_t loc
= c_parser_peek_token (parser
)->location
;
12177 c_parser_consume_pragma (parser
);
12178 c_parser_skip_to_pragma_eol (parser
);
12180 c_finish_omp_taskwait (loc
);
12184 # pragma omp taskyield new-line
12188 c_parser_omp_taskyield (c_parser
*parser
)
12190 location_t loc
= c_parser_peek_token (parser
)->location
;
12191 c_parser_consume_pragma (parser
);
12192 c_parser_skip_to_pragma_eol (parser
);
12194 c_finish_omp_taskyield (loc
);
12198 # pragma omp taskgroup new-line
12202 c_parser_omp_taskgroup (c_parser
*parser
)
12204 location_t loc
= c_parser_peek_token (parser
)->location
;
12205 c_parser_skip_to_pragma_eol (parser
);
12206 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12210 # pragma omp cancel cancel-clause[optseq] new-line
12212 LOC is the location of the #pragma.
12215 #define OMP_CANCEL_CLAUSE_MASK \
12216 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12217 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12218 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12219 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12220 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12223 c_parser_omp_cancel (c_parser
*parser
)
12225 location_t loc
= c_parser_peek_token (parser
)->location
;
12227 c_parser_consume_pragma (parser
);
12228 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12229 "#pragma omp cancel");
12231 c_finish_omp_cancel (loc
, clauses
);
12235 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12237 LOC is the location of the #pragma.
12240 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12241 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12242 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12243 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12244 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12247 c_parser_omp_cancellation_point (c_parser
*parser
)
12249 location_t loc
= c_parser_peek_token (parser
)->location
;
12251 bool point_seen
= false;
12253 c_parser_consume_pragma (parser
);
12254 if (c_parser_next_token_is (parser
, CPP_NAME
))
12256 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12257 if (strcmp (p
, "point") == 0)
12259 c_parser_consume_token (parser
);
12265 c_parser_error (parser
, "expected %<point%>");
12266 c_parser_skip_to_pragma_eol (parser
);
12271 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12272 "#pragma omp cancellation point");
12274 c_finish_omp_cancellation_point (loc
, clauses
);
12278 #pragma omp distribute distribute-clause[optseq] new-line
12281 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12282 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12283 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12284 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12285 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12288 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12289 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12291 tree clauses
, block
, ret
;
12293 strcat (p_name
, " distribute");
12294 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12296 if (c_parser_next_token_is (parser
, CPP_NAME
))
12298 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12300 bool parallel
= false;
12302 if (strcmp (p
, "simd") == 0)
12305 parallel
= strcmp (p
, "parallel") == 0;
12306 if (parallel
|| simd
)
12308 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12309 if (cclauses
== NULL
)
12310 cclauses
= cclauses_buf
;
12311 c_parser_consume_token (parser
);
12312 if (!flag_openmp
) /* flag_openmp_simd */
12315 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12317 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12320 block
= c_begin_compound_stmt (true);
12322 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12324 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12325 block
= c_end_compound_stmt (loc
, block
, true);
12328 ret
= make_node (OMP_DISTRIBUTE
);
12329 TREE_TYPE (ret
) = void_type_node
;
12330 OMP_FOR_BODY (ret
) = block
;
12331 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12332 SET_EXPR_LOCATION (ret
, loc
);
12337 if (!flag_openmp
) /* flag_openmp_simd */
12339 c_parser_skip_to_pragma_eol (parser
);
12343 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12346 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12347 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12350 block
= c_begin_compound_stmt (true);
12351 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12352 block
= c_end_compound_stmt (loc
, block
, true);
12359 # pragma omp teams teams-clause[optseq] new-line
12360 structured-block */
12362 #define OMP_TEAMS_CLAUSE_MASK \
12363 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12364 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12365 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12366 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12367 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12368 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12369 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12372 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12373 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12375 tree clauses
, block
, ret
;
12377 strcat (p_name
, " teams");
12378 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12380 if (c_parser_next_token_is (parser
, CPP_NAME
))
12382 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12383 if (strcmp (p
, "distribute") == 0)
12385 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12386 if (cclauses
== NULL
)
12387 cclauses
= cclauses_buf
;
12389 c_parser_consume_token (parser
);
12390 if (!flag_openmp
) /* flag_openmp_simd */
12391 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12392 block
= c_begin_compound_stmt (true);
12393 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12394 block
= c_end_compound_stmt (loc
, block
, true);
12397 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12398 ret
= make_node (OMP_TEAMS
);
12399 TREE_TYPE (ret
) = void_type_node
;
12400 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12401 OMP_TEAMS_BODY (ret
) = block
;
12402 return add_stmt (ret
);
12405 if (!flag_openmp
) /* flag_openmp_simd */
12407 c_parser_skip_to_pragma_eol (parser
);
12411 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12414 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12415 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12418 tree stmt
= make_node (OMP_TEAMS
);
12419 TREE_TYPE (stmt
) = void_type_node
;
12420 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12421 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12423 return add_stmt (stmt
);
12427 # pragma omp target data target-data-clause[optseq] new-line
12428 structured-block */
12430 #define OMP_TARGET_DATA_CLAUSE_MASK \
12431 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12432 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12433 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12436 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12438 tree stmt
= make_node (OMP_TARGET_DATA
);
12439 TREE_TYPE (stmt
) = void_type_node
;
12441 OMP_TARGET_DATA_CLAUSES (stmt
)
12442 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12443 "#pragma omp target data");
12444 keep_next_level ();
12445 tree block
= c_begin_compound_stmt (true);
12446 add_stmt (c_parser_omp_structured_block (parser
));
12447 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12449 SET_EXPR_LOCATION (stmt
, loc
);
12450 return add_stmt (stmt
);
12454 # pragma omp target update target-update-clause[optseq] new-line */
12456 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12457 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12458 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12459 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12460 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12463 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12464 enum pragma_context context
)
12466 if (context
== pragma_stmt
)
12469 "%<#pragma omp target update%> may only be "
12470 "used in compound statements");
12471 c_parser_skip_to_pragma_eol (parser
);
12476 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12477 "#pragma omp target update");
12478 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12479 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12482 "%<#pragma omp target update must contain at least one "
12483 "%<from%> or %<to%> clauses");
12487 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12488 TREE_TYPE (stmt
) = void_type_node
;
12489 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12490 SET_EXPR_LOCATION (stmt
, loc
);
12496 # pragma omp target target-clause[optseq] new-line
12497 structured-block */
12499 #define OMP_TARGET_CLAUSE_MASK \
12500 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12501 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12502 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12505 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12507 location_t loc
= c_parser_peek_token (parser
)->location
;
12508 c_parser_consume_pragma (parser
);
12510 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12512 c_parser_error (parser
, "expected declaration specifiers");
12513 c_parser_skip_to_pragma_eol (parser
);
12517 if (c_parser_next_token_is (parser
, CPP_NAME
))
12519 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12521 if (strcmp (p
, "teams") == 0)
12523 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12524 char p_name
[sizeof ("#pragma omp target teams distribute "
12525 "parallel for simd")];
12527 c_parser_consume_token (parser
);
12528 if (!flag_openmp
) /* flag_openmp_simd */
12529 return c_parser_omp_teams (loc
, parser
, p_name
,
12530 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12531 strcpy (p_name
, "#pragma omp target");
12532 keep_next_level ();
12533 tree block
= c_begin_compound_stmt (true);
12534 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12535 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12536 block
= c_end_compound_stmt (loc
, block
, true);
12539 tree stmt
= make_node (OMP_TARGET
);
12540 TREE_TYPE (stmt
) = void_type_node
;
12541 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12542 OMP_TARGET_BODY (stmt
) = block
;
12546 else if (!flag_openmp
) /* flag_openmp_simd */
12548 c_parser_skip_to_pragma_eol (parser
);
12551 else if (strcmp (p
, "data") == 0)
12553 c_parser_consume_token (parser
);
12554 c_parser_omp_target_data (loc
, parser
);
12557 else if (strcmp (p
, "update") == 0)
12559 c_parser_consume_token (parser
);
12560 return c_parser_omp_target_update (loc
, parser
, context
);
12564 tree stmt
= make_node (OMP_TARGET
);
12565 TREE_TYPE (stmt
) = void_type_node
;
12567 OMP_TARGET_CLAUSES (stmt
)
12568 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12569 "#pragma omp target");
12570 keep_next_level ();
12571 tree block
= c_begin_compound_stmt (true);
12572 add_stmt (c_parser_omp_structured_block (parser
));
12573 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12575 SET_EXPR_LOCATION (stmt
, loc
);
12581 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12583 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12584 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12585 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12587 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12588 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12589 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12592 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12594 vec
<c_token
> clauses
= vNULL
;
12595 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12597 c_token
*token
= c_parser_peek_token (parser
);
12598 if (token
->type
== CPP_EOF
)
12600 c_parser_skip_to_pragma_eol (parser
);
12601 clauses
.release ();
12604 clauses
.safe_push (*token
);
12605 c_parser_consume_token (parser
);
12607 clauses
.safe_push (*c_parser_peek_token (parser
));
12608 c_parser_skip_to_pragma_eol (parser
);
12610 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12612 if (c_parser_peek_token (parser
)->pragma_kind
12613 != PRAGMA_OMP_DECLARE_REDUCTION
12614 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12615 || strcmp (IDENTIFIER_POINTER
12616 (c_parser_peek_2nd_token (parser
)->value
),
12619 c_parser_error (parser
,
12620 "%<#pragma omp declare simd%> must be followed by "
12621 "function declaration or definition or another "
12622 "%<#pragma omp declare simd%>");
12623 clauses
.release ();
12626 c_parser_consume_pragma (parser
);
12627 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12629 c_token
*token
= c_parser_peek_token (parser
);
12630 if (token
->type
== CPP_EOF
)
12632 c_parser_skip_to_pragma_eol (parser
);
12633 clauses
.release ();
12636 clauses
.safe_push (*token
);
12637 c_parser_consume_token (parser
);
12639 clauses
.safe_push (*c_parser_peek_token (parser
));
12640 c_parser_skip_to_pragma_eol (parser
);
12643 /* Make sure nothing tries to read past the end of the tokens. */
12645 memset (&eof_token
, 0, sizeof (eof_token
));
12646 eof_token
.type
= CPP_EOF
;
12647 clauses
.safe_push (eof_token
);
12648 clauses
.safe_push (eof_token
);
12652 case pragma_external
:
12653 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12654 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12656 int ext
= disable_extension_diagnostics ();
12658 c_parser_consume_token (parser
);
12659 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12660 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12661 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12663 restore_extension_diagnostics (ext
);
12666 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12669 case pragma_struct
:
12671 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12672 "function declaration or definition");
12674 case pragma_compound
:
12676 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12677 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12679 int ext
= disable_extension_diagnostics ();
12681 c_parser_consume_token (parser
);
12682 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12683 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12684 if (c_parser_next_tokens_start_declaration (parser
))
12686 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12687 true, NULL
, clauses
);
12688 restore_extension_diagnostics (ext
);
12691 restore_extension_diagnostics (ext
);
12693 else if (c_parser_next_tokens_start_declaration (parser
))
12695 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12699 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12700 "function declaration or definition");
12703 gcc_unreachable ();
12705 clauses
.release ();
12708 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12709 and put that into "omp declare simd" attribute. */
12712 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12713 vec
<c_token
> clauses
)
12715 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12716 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12717 has already processed the tokens. */
12718 if (clauses
[0].type
== CPP_EOF
)
12720 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12722 error ("%<#pragma omp declare simd%> not immediately followed by "
12723 "a function declaration or definition");
12724 clauses
[0].type
= CPP_EOF
;
12727 if (clauses
[0].type
!= CPP_NAME
)
12729 error_at (DECL_SOURCE_LOCATION (fndecl
),
12730 "%<#pragma omp declare simd%> not immediately followed by "
12731 "a single function declaration or definition");
12732 clauses
[0].type
= CPP_EOF
;
12736 if (parms
== NULL_TREE
)
12737 parms
= DECL_ARGUMENTS (fndecl
);
12739 unsigned int tokens_avail
= parser
->tokens_avail
;
12740 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12741 parser
->tokens
= clauses
.address ();
12742 parser
->tokens_avail
= clauses
.length ();
12744 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12745 while (parser
->tokens_avail
> 3)
12747 c_token
*token
= c_parser_peek_token (parser
);
12748 gcc_assert (token
->type
== CPP_NAME
12749 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12750 c_parser_consume_token (parser
);
12751 parser
->in_pragma
= true;
12753 tree c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12754 "#pragma omp declare simd");
12755 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12756 if (c
!= NULL_TREE
)
12757 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12758 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12759 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12760 DECL_ATTRIBUTES (fndecl
) = c
;
12763 parser
->tokens
= &parser
->tokens_buf
[0];
12764 parser
->tokens_avail
= tokens_avail
;
12765 clauses
[0].type
= CPP_PRAGMA
;
12770 # pragma omp declare target new-line
12771 declarations and definitions
12772 # pragma omp end declare target new-line */
12775 c_parser_omp_declare_target (c_parser
*parser
)
12777 c_parser_skip_to_pragma_eol (parser
);
12778 current_omp_declare_target_attribute
++;
12782 c_parser_omp_end_declare_target (c_parser
*parser
)
12784 location_t loc
= c_parser_peek_token (parser
)->location
;
12785 c_parser_consume_pragma (parser
);
12786 if (c_parser_next_token_is (parser
, CPP_NAME
)
12787 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12790 c_parser_consume_token (parser
);
12791 if (c_parser_next_token_is (parser
, CPP_NAME
)
12792 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12794 c_parser_consume_token (parser
);
12797 c_parser_error (parser
, "expected %<target%>");
12798 c_parser_skip_to_pragma_eol (parser
);
12804 c_parser_error (parser
, "expected %<declare%>");
12805 c_parser_skip_to_pragma_eol (parser
);
12808 c_parser_skip_to_pragma_eol (parser
);
12809 if (!current_omp_declare_target_attribute
)
12810 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
12811 "%<#pragma omp declare target%>");
12813 current_omp_declare_target_attribute
--;
12818 #pragma omp declare reduction (reduction-id : typename-list : expression) \
12819 initializer-clause[opt] new-line
12821 initializer-clause:
12822 initializer (omp_priv = initializer)
12823 initializer (function-name (argument-list)) */
12826 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
12828 unsigned int tokens_avail
= 0, i
;
12829 vec
<tree
> types
= vNULL
;
12830 vec
<c_token
> clauses
= vNULL
;
12831 enum tree_code reduc_code
= ERROR_MARK
;
12832 tree reduc_id
= NULL_TREE
;
12834 location_t rloc
= c_parser_peek_token (parser
)->location
;
12836 if (context
== pragma_struct
|| context
== pragma_param
)
12838 error ("%<#pragma omp declare reduction%> not at file or block scope");
12842 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12845 switch (c_parser_peek_token (parser
)->type
)
12848 reduc_code
= PLUS_EXPR
;
12851 reduc_code
= MULT_EXPR
;
12854 reduc_code
= MINUS_EXPR
;
12857 reduc_code
= BIT_AND_EXPR
;
12860 reduc_code
= BIT_XOR_EXPR
;
12863 reduc_code
= BIT_IOR_EXPR
;
12866 reduc_code
= TRUTH_ANDIF_EXPR
;
12869 reduc_code
= TRUTH_ORIF_EXPR
;
12873 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12874 if (strcmp (p
, "min") == 0)
12876 reduc_code
= MIN_EXPR
;
12879 if (strcmp (p
, "max") == 0)
12881 reduc_code
= MAX_EXPR
;
12884 reduc_id
= c_parser_peek_token (parser
)->value
;
12887 c_parser_error (parser
,
12888 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12889 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
12893 tree orig_reduc_id
, reduc_decl
;
12894 orig_reduc_id
= reduc_id
;
12895 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
12896 reduc_decl
= c_omp_reduction_decl (reduc_id
);
12897 c_parser_consume_token (parser
);
12899 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12904 location_t loc
= c_parser_peek_token (parser
)->location
;
12905 struct c_type_name
*ctype
= c_parser_type_name (parser
);
12908 type
= groktypename (ctype
, NULL
, NULL
);
12909 if (type
== error_mark_node
)
12911 else if ((INTEGRAL_TYPE_P (type
)
12912 || TREE_CODE (type
) == REAL_TYPE
12913 || TREE_CODE (type
) == COMPLEX_TYPE
)
12914 && orig_reduc_id
== NULL_TREE
)
12915 error_at (loc
, "predeclared arithmetic type in "
12916 "%<#pragma omp declare reduction%>");
12917 else if (TREE_CODE (type
) == FUNCTION_TYPE
12918 || TREE_CODE (type
) == ARRAY_TYPE
)
12919 error_at (loc
, "function or array type in "
12920 "%<#pragma omp declare reduction%>");
12921 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
12922 error_at (loc
, "const, volatile or restrict qualified type in "
12923 "%<#pragma omp declare reduction%>");
12927 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
12928 if (comptypes (TREE_PURPOSE (t
), type
))
12930 error_at (loc
, "redeclaration of %qs "
12931 "%<#pragma omp declare reduction%> for "
12933 IDENTIFIER_POINTER (reduc_id
)
12934 + sizeof ("omp declare reduction ") - 1,
12937 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
12939 error_at (ploc
, "previous %<#pragma omp declare "
12943 if (t
== NULL_TREE
)
12944 types
.safe_push (type
);
12946 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12947 c_parser_consume_token (parser
);
12955 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
12956 || types
.is_empty ())
12959 clauses
.release ();
12963 c_token
*token
= c_parser_peek_token (parser
);
12964 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
12966 c_parser_consume_token (parser
);
12968 c_parser_skip_to_pragma_eol (parser
);
12972 if (types
.length () > 1)
12974 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12976 c_token
*token
= c_parser_peek_token (parser
);
12977 if (token
->type
== CPP_EOF
)
12979 clauses
.safe_push (*token
);
12980 c_parser_consume_token (parser
);
12982 clauses
.safe_push (*c_parser_peek_token (parser
));
12983 c_parser_skip_to_pragma_eol (parser
);
12985 /* Make sure nothing tries to read past the end of the tokens. */
12987 memset (&eof_token
, 0, sizeof (eof_token
));
12988 eof_token
.type
= CPP_EOF
;
12989 clauses
.safe_push (eof_token
);
12990 clauses
.safe_push (eof_token
);
12993 int errs
= errorcount
;
12994 FOR_EACH_VEC_ELT (types
, i
, type
)
12996 tokens_avail
= parser
->tokens_avail
;
12997 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12998 if (!clauses
.is_empty ())
13000 parser
->tokens
= clauses
.address ();
13001 parser
->tokens_avail
= clauses
.length ();
13002 parser
->in_pragma
= true;
13005 bool nested
= current_function_decl
!= NULL_TREE
;
13007 c_push_function_context ();
13008 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13009 reduc_id
, default_function_type
);
13010 current_function_decl
= fndecl
;
13011 allocate_struct_function (fndecl
, true);
13013 tree stmt
= push_stmt_list ();
13014 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13015 warn about these. */
13016 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13017 get_identifier ("omp_out"), type
);
13018 DECL_ARTIFICIAL (omp_out
) = 1;
13019 DECL_CONTEXT (omp_out
) = fndecl
;
13020 pushdecl (omp_out
);
13021 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13022 get_identifier ("omp_in"), type
);
13023 DECL_ARTIFICIAL (omp_in
) = 1;
13024 DECL_CONTEXT (omp_in
) = fndecl
;
13026 struct c_expr combiner
= c_parser_expression (parser
);
13027 struct c_expr initializer
;
13028 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13030 initializer
.value
= error_mark_node
;
13031 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13033 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13034 && strcmp (IDENTIFIER_POINTER
13035 (c_parser_peek_token (parser
)->value
),
13036 "initializer") == 0)
13038 c_parser_consume_token (parser
);
13041 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13042 get_identifier ("omp_priv"), type
);
13043 DECL_ARTIFICIAL (omp_priv
) = 1;
13044 DECL_INITIAL (omp_priv
) = error_mark_node
;
13045 DECL_CONTEXT (omp_priv
) = fndecl
;
13046 pushdecl (omp_priv
);
13047 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13048 get_identifier ("omp_orig"), type
);
13049 DECL_ARTIFICIAL (omp_orig
) = 1;
13050 DECL_CONTEXT (omp_orig
) = fndecl
;
13051 pushdecl (omp_orig
);
13052 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13054 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13056 c_parser_error (parser
, "expected %<omp_priv%> or "
13060 else if (strcmp (IDENTIFIER_POINTER
13061 (c_parser_peek_token (parser
)->value
),
13064 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13065 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13067 c_parser_error (parser
, "expected function-name %<(%>");
13071 initializer
= c_parser_postfix_expression (parser
);
13072 if (initializer
.value
13073 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13076 tree c
= initializer
.value
;
13077 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13078 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13079 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13081 if (j
== call_expr_nargs (c
))
13082 error ("one of the initializer call arguments should be "
13088 c_parser_consume_token (parser
);
13089 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13093 tree st
= push_stmt_list ();
13094 start_init (omp_priv
, NULL_TREE
, 0);
13095 location_t loc
= c_parser_peek_token (parser
)->location
;
13096 struct c_expr init
= c_parser_initializer (parser
);
13098 finish_decl (omp_priv
, loc
, init
.value
,
13099 init
.original_type
, NULL_TREE
);
13100 pop_stmt_list (st
);
13104 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13110 c_parser_skip_to_pragma_eol (parser
);
13112 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13113 DECL_INITIAL (reduc_decl
));
13114 DECL_INITIAL (reduc_decl
) = t
;
13115 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13116 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13117 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13118 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13119 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13120 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13123 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13124 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13125 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13126 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13127 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13128 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13129 walk_tree (&DECL_INITIAL (omp_priv
),
13130 c_check_omp_declare_reduction_r
,
13131 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13135 pop_stmt_list (stmt
);
13137 if (cfun
->language
!= NULL
)
13139 ggc_free (cfun
->language
);
13140 cfun
->language
= NULL
;
13143 current_function_decl
= NULL_TREE
;
13145 c_pop_function_context ();
13147 if (!clauses
.is_empty ())
13149 parser
->tokens
= &parser
->tokens_buf
[0];
13150 parser
->tokens_avail
= tokens_avail
;
13154 if (errs
!= errorcount
)
13158 clauses
.release ();
13164 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13165 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13166 initializer-clause[opt] new-line
13167 #pragma omp declare target new-line */
13170 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13172 c_parser_consume_pragma (parser
);
13173 if (c_parser_next_token_is (parser
, CPP_NAME
))
13175 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13176 if (strcmp (p
, "simd") == 0)
13178 /* c_parser_consume_token (parser); done in
13179 c_parser_omp_declare_simd. */
13180 c_parser_omp_declare_simd (parser
, context
);
13183 if (strcmp (p
, "reduction") == 0)
13185 c_parser_consume_token (parser
);
13186 c_parser_omp_declare_reduction (parser
, context
);
13189 if (!flag_openmp
) /* flag_openmp_simd */
13191 c_parser_skip_to_pragma_eol (parser
);
13194 if (strcmp (p
, "target") == 0)
13196 c_parser_consume_token (parser
);
13197 c_parser_omp_declare_target (parser
);
13202 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13204 c_parser_skip_to_pragma_eol (parser
);
13207 /* Main entry point to parsing most OpenMP pragmas. */
13210 c_parser_omp_construct (c_parser
*parser
)
13212 enum pragma_kind p_kind
;
13215 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13216 omp_clause_mask
mask (0);
13218 loc
= c_parser_peek_token (parser
)->location
;
13219 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13220 c_parser_consume_pragma (parser
);
13224 case PRAGMA_OMP_ATOMIC
:
13225 c_parser_omp_atomic (loc
, parser
);
13227 case PRAGMA_OMP_CRITICAL
:
13228 stmt
= c_parser_omp_critical (loc
, parser
);
13230 case PRAGMA_OMP_DISTRIBUTE
:
13231 strcpy (p_name
, "#pragma omp");
13232 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13234 case PRAGMA_OMP_FOR
:
13235 strcpy (p_name
, "#pragma omp");
13236 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13238 case PRAGMA_OMP_MASTER
:
13239 stmt
= c_parser_omp_master (loc
, parser
);
13241 case PRAGMA_OMP_ORDERED
:
13242 stmt
= c_parser_omp_ordered (loc
, parser
);
13244 case PRAGMA_OMP_PARALLEL
:
13245 strcpy (p_name
, "#pragma omp");
13246 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13248 case PRAGMA_OMP_SECTIONS
:
13249 strcpy (p_name
, "#pragma omp");
13250 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13252 case PRAGMA_OMP_SIMD
:
13253 strcpy (p_name
, "#pragma omp");
13254 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13256 case PRAGMA_OMP_SINGLE
:
13257 stmt
= c_parser_omp_single (loc
, parser
);
13259 case PRAGMA_OMP_TASK
:
13260 stmt
= c_parser_omp_task (loc
, parser
);
13262 case PRAGMA_OMP_TASKGROUP
:
13263 stmt
= c_parser_omp_taskgroup (parser
);
13265 case PRAGMA_OMP_TEAMS
:
13266 strcpy (p_name
, "#pragma omp");
13267 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13270 gcc_unreachable ();
13274 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13279 # pragma omp threadprivate (variable-list) */
13282 c_parser_omp_threadprivate (c_parser
*parser
)
13287 c_parser_consume_pragma (parser
);
13288 loc
= c_parser_peek_token (parser
)->location
;
13289 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13291 /* Mark every variable in VARS to be assigned thread local storage. */
13292 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13294 tree v
= TREE_PURPOSE (t
);
13296 /* FIXME diagnostics: Ideally we should keep individual
13297 locations for all the variables in the var list to make the
13298 following errors more precise. Perhaps
13299 c_parser_omp_var_list_parens() should construct a list of
13300 locations to go along with the var list. */
13302 /* If V had already been marked threadprivate, it doesn't matter
13303 whether it had been used prior to this point. */
13304 if (TREE_CODE (v
) != VAR_DECL
)
13305 error_at (loc
, "%qD is not a variable", v
);
13306 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13307 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13308 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13309 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13310 else if (TREE_TYPE (v
) == error_mark_node
)
13312 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13313 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13316 if (! DECL_THREAD_LOCAL_P (v
))
13318 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
13319 /* If rtl has been already set for this var, call
13320 make_decl_rtl once again, so that encode_section_info
13321 has a chance to look at the new decl flags. */
13322 if (DECL_RTL_SET_P (v
))
13325 C_DECL_THREADPRIVATE_P (v
) = 1;
13329 c_parser_skip_to_pragma_eol (parser
);
13332 /* Cilk Plus <#pragma simd> parsing routines. */
13334 /* Helper function for c_parser_pragma. Perform some sanity checking
13335 for <#pragma simd> constructs. Returns FALSE if there was a
13339 c_parser_cilk_verify_simd (c_parser
*parser
,
13340 enum pragma_context context
)
13342 if (!flag_enable_cilkplus
)
13344 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13345 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13348 if (context
== pragma_external
)
13350 c_parser_error (parser
,"pragma simd must be inside a function");
13351 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13358 vectorlength ( constant-expression ) */
13361 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
)
13363 /* The vectorlength clause behaves exactly like OpenMP's safelen
13364 clause. Represent it in OpenMP terms. */
13365 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13367 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13370 location_t loc
= c_parser_peek_token (parser
)->location
;
13371 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13372 expr
= c_fully_fold (expr
, false, NULL
);
13374 if (!TREE_TYPE (expr
)
13375 || !TREE_CONSTANT (expr
)
13376 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13377 error_at (loc
, "vectorlength must be an integer constant");
13378 else if (exact_log2 (TREE_INT_CST_LOW (expr
)) == -1)
13379 error_at (loc
, "vectorlength must be a power of 2");
13382 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13383 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13384 OMP_CLAUSE_CHAIN (u
) = clauses
;
13388 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13394 linear ( simd-linear-variable-list )
13396 simd-linear-variable-list:
13397 simd-linear-variable
13398 simd-linear-variable-list , simd-linear-variable
13400 simd-linear-variable:
13402 id-expression : simd-linear-step
13405 conditional-expression */
13408 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13410 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13413 location_t loc
= c_parser_peek_token (parser
)->location
;
13415 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13416 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13417 c_parser_error (parser
, "expected identifier");
13419 while (c_parser_next_token_is (parser
, CPP_NAME
)
13420 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13422 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13426 undeclared_variable (c_parser_peek_token (parser
)->location
,
13427 c_parser_peek_token (parser
)->value
);
13428 c_parser_consume_token (parser
);
13430 else if (var
== error_mark_node
)
13431 c_parser_consume_token (parser
);
13434 tree step
= integer_one_node
;
13436 /* Parse the linear step if present. */
13437 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13439 c_parser_consume_token (parser
);
13440 c_parser_consume_token (parser
);
13442 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13443 expr
= c_fully_fold (expr
, false, NULL
);
13445 if (TREE_TYPE (expr
)
13446 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13447 && (TREE_CONSTANT (expr
)
13451 c_parser_error (parser
,
13452 "step size must be an integer constant "
13453 "expression or an integer variable");
13456 c_parser_consume_token (parser
);
13458 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13459 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13460 OMP_CLAUSE_DECL (u
) = var
;
13461 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13462 OMP_CLAUSE_CHAIN (u
) = clauses
;
13466 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13469 c_parser_consume_token (parser
);
13472 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13477 /* Returns the name of the next clause. If the clause is not
13478 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13479 not consumed. Otherwise, the appropriate pragma_simd_clause is
13480 returned and the token is consumed. */
13482 static pragma_cilk_clause
13483 c_parser_cilk_clause_name (c_parser
*parser
)
13485 pragma_cilk_clause result
;
13486 c_token
*token
= c_parser_peek_token (parser
);
13488 if (!token
->value
|| token
->type
!= CPP_NAME
)
13489 return PRAGMA_CILK_CLAUSE_NONE
;
13491 const char *p
= IDENTIFIER_POINTER (token
->value
);
13493 if (!strcmp (p
, "vectorlength"))
13494 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13495 else if (!strcmp (p
, "linear"))
13496 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13497 else if (!strcmp (p
, "private"))
13498 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13499 else if (!strcmp (p
, "firstprivate"))
13500 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13501 else if (!strcmp (p
, "lastprivate"))
13502 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13503 else if (!strcmp (p
, "reduction"))
13504 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13506 return PRAGMA_CILK_CLAUSE_NONE
;
13508 c_parser_consume_token (parser
);
13512 /* Parse all #<pragma simd> clauses. Return the list of clauses
13516 c_parser_cilk_all_clauses (c_parser
*parser
)
13518 tree clauses
= NULL
;
13520 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13522 pragma_cilk_clause c_kind
;
13524 c_kind
= c_parser_cilk_clause_name (parser
);
13528 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13529 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
);
13531 case PRAGMA_CILK_CLAUSE_LINEAR
:
13532 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13534 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13535 /* Use the OpenMP counterpart. */
13536 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13538 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13539 /* Use the OpenMP counterpart. */
13540 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13542 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13543 /* Use the OpenMP counterpart. */
13544 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13546 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13547 /* Use the OpenMP counterpart. */
13548 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13551 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13557 c_parser_skip_to_pragma_eol (parser
);
13558 return c_finish_cilk_clauses (clauses
);
13561 /* Main entry point for parsing Cilk Plus <#pragma simd> for
13565 c_parser_cilk_simd (c_parser
*parser ATTRIBUTE_UNUSED
)
13568 strcpy (p_name
, "#pragma omp");
13569 tree clauses
= c_parser_cilk_all_clauses (parser
);
13570 tree block
= c_begin_compound_stmt (true);
13571 location_t loc
= c_parser_peek_token (parser
)->location
;
13572 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
13573 block
= c_end_compound_stmt (loc
, block
, true);
13577 /* Parse a transaction attribute (GCC Extension).
13579 transaction-attribute:
13583 The transactional memory language description is written for C++,
13584 and uses the C++0x attribute syntax. For compatibility, allow the
13585 bracket style for transactions in C as well. */
13588 c_parser_transaction_attributes (c_parser
*parser
)
13590 tree attr_name
, attr
= NULL
;
13592 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13593 return c_parser_attributes (parser
);
13595 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13597 c_parser_consume_token (parser
);
13598 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13601 attr_name
= c_parser_attribute_any_word (parser
);
13604 c_parser_consume_token (parser
);
13605 attr
= build_tree_list (attr_name
, NULL_TREE
);
13608 c_parser_error (parser
, "expected identifier");
13610 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13612 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13616 /* Parse a __transaction_atomic or __transaction_relaxed statement
13619 transaction-statement:
13620 __transaction_atomic transaction-attribute[opt] compound-statement
13621 __transaction_relaxed compound-statement
13623 Note that the only valid attribute is: "outer".
13627 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13629 unsigned int old_in
= parser
->in_transaction
;
13630 unsigned int this_in
= 1, new_in
;
13631 location_t loc
= c_parser_peek_token (parser
)->location
;
13634 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13635 || keyword
== RID_TRANSACTION_RELAXED
)
13636 && c_parser_next_token_is_keyword (parser
, keyword
));
13637 c_parser_consume_token (parser
);
13639 if (keyword
== RID_TRANSACTION_RELAXED
)
13640 this_in
|= TM_STMT_ATTR_RELAXED
;
13643 attrs
= c_parser_transaction_attributes (parser
);
13645 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13648 /* Keep track if we're in the lexical scope of an outer transaction. */
13649 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13651 parser
->in_transaction
= new_in
;
13652 stmt
= c_parser_compound_statement (parser
);
13653 parser
->in_transaction
= old_in
;
13656 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13658 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13659 "%<__transaction_atomic%> without transactional memory support enabled"
13660 : "%<__transaction_relaxed %> "
13661 "without transactional memory support enabled"));
13666 /* Parse a __transaction_atomic or __transaction_relaxed expression
13669 transaction-expression:
13670 __transaction_atomic ( expression )
13671 __transaction_relaxed ( expression )
13674 static struct c_expr
13675 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13678 unsigned int old_in
= parser
->in_transaction
;
13679 unsigned int this_in
= 1;
13680 location_t loc
= c_parser_peek_token (parser
)->location
;
13683 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13684 || keyword
== RID_TRANSACTION_RELAXED
)
13685 && c_parser_next_token_is_keyword (parser
, keyword
));
13686 c_parser_consume_token (parser
);
13688 if (keyword
== RID_TRANSACTION_RELAXED
)
13689 this_in
|= TM_STMT_ATTR_RELAXED
;
13692 attrs
= c_parser_transaction_attributes (parser
);
13694 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13697 parser
->in_transaction
= this_in
;
13698 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13700 tree expr
= c_parser_expression (parser
).value
;
13701 ret
.original_type
= TREE_TYPE (expr
);
13702 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13703 if (this_in
& TM_STMT_ATTR_RELAXED
)
13704 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13705 SET_EXPR_LOCATION (ret
.value
, loc
);
13706 ret
.original_code
= TRANSACTION_EXPR
;
13707 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13709 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13716 ret
.value
= error_mark_node
;
13717 ret
.original_code
= ERROR_MARK
;
13718 ret
.original_type
= NULL
;
13720 parser
->in_transaction
= old_in
;
13723 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13724 "%<__transaction_atomic%> without transactional memory support enabled"
13725 : "%<__transaction_relaxed %> "
13726 "without transactional memory support enabled"));
13731 /* Parse a __transaction_cancel statement (GCC Extension).
13733 transaction-cancel-statement:
13734 __transaction_cancel transaction-attribute[opt] ;
13736 Note that the only valid attribute is "outer".
13740 c_parser_transaction_cancel (c_parser
*parser
)
13742 location_t loc
= c_parser_peek_token (parser
)->location
;
13744 bool is_outer
= false;
13746 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
13747 c_parser_consume_token (parser
);
13749 attrs
= c_parser_transaction_attributes (parser
);
13751 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
13755 error_at (loc
, "%<__transaction_cancel%> without "
13756 "transactional memory support enabled");
13759 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
13761 error_at (loc
, "%<__transaction_cancel%> within a "
13762 "%<__transaction_relaxed%>");
13767 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
13768 && !is_tm_may_cancel_outer (current_function_decl
))
13770 error_at (loc
, "outer %<__transaction_cancel%> not "
13771 "within outer %<__transaction_atomic%>");
13772 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
13776 else if (parser
->in_transaction
== 0)
13778 error_at (loc
, "%<__transaction_cancel%> not within "
13779 "%<__transaction_atomic%>");
13783 return add_stmt (build_tm_abort_call (loc
, is_outer
));
13786 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
13789 /* Parse a single source file. */
13792 c_parse_file (void)
13794 /* Use local storage to begin. If the first token is a pragma, parse it.
13795 If it is #pragma GCC pch_preprocess, then this will load a PCH file
13796 which will cause garbage collection. */
13799 memset (&tparser
, 0, sizeof tparser
);
13800 tparser
.tokens
= &tparser
.tokens_buf
[0];
13801 the_parser
= &tparser
;
13803 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
13804 c_parser_pragma_pch_preprocess (&tparser
);
13806 the_parser
= ggc_alloc_c_parser ();
13807 *the_parser
= tparser
;
13808 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
13809 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
13811 /* Initialize EH, if we've been told to do so. */
13812 if (flag_exceptions
)
13813 using_eh_for_cleanups ();
13815 c_parser_translation_unit (the_parser
);
13819 /* This function parses Cilk Plus array notation. The starting index is
13820 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
13821 return value of this function is a tree_node called VALUE_TREE of type
13822 ARRAY_NOTATION_REF. */
13825 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
13828 c_token
*token
= NULL
;
13829 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
13830 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
13831 tree array_type_domain
= NULL_TREE
;
13833 if (array_value
== error_mark_node
)
13835 /* No need to continue. If either of these 2 were true, then an error
13836 must be emitted already. Thus, no need to emit them twice. */
13837 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13838 return error_mark_node
;
13841 array_type
= TREE_TYPE (array_value
);
13842 gcc_assert (array_type
);
13843 type
= TREE_TYPE (array_type
);
13844 token
= c_parser_peek_token (parser
);
13846 if (token
->type
== CPP_EOF
)
13848 c_parser_error (parser
, "expected %<:%> or numeral");
13851 else if (token
->type
== CPP_COLON
)
13853 if (!initial_index
)
13855 /* If we are here, then we have a case like this A[:]. */
13856 c_parser_consume_token (parser
);
13857 if (TREE_CODE (array_type
) == POINTER_TYPE
)
13859 error_at (loc
, "start-index and length fields necessary for "
13860 "using array notations in pointers");
13861 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13862 return error_mark_node
;
13864 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13866 error_at (loc
, "array notations cannot be used with function "
13868 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13869 return error_mark_node
;
13871 array_type_domain
= TYPE_DOMAIN (array_type
);
13873 if (!array_type_domain
)
13875 error_at (loc
, "start-index and length fields necessary for "
13876 "using array notations in dimensionless arrays");
13877 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13878 return error_mark_node
;
13881 start_index
= TYPE_MINVAL (array_type_domain
);
13882 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
13884 if (!TYPE_MAXVAL (array_type_domain
)
13885 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
13887 error_at (loc
, "start-index and length fields necessary for "
13888 "using array notations in variable-length arrays");
13889 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13890 return error_mark_node
;
13892 end_index
= TYPE_MAXVAL (array_type_domain
);
13893 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
13894 end_index
, integer_one_node
);
13895 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
13896 stride
= build_int_cst (integer_type_node
, 1);
13897 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
13899 else if (initial_index
!= error_mark_node
)
13901 /* If we are here, then there should be 2 possibilities:
13902 1. Array [EXPR : EXPR]
13903 2. Array [EXPR : EXPR : EXPR]
13905 start_index
= initial_index
;
13907 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13909 error_at (loc
, "array notations cannot be used with function "
13911 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13912 return error_mark_node
;
13914 c_parser_consume_token (parser
); /* consume the ':' */
13915 struct c_expr ce
= c_parser_expression (parser
);
13916 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
13917 end_index
= ce
.value
;
13918 if (!end_index
|| end_index
== error_mark_node
)
13920 c_parser_skip_to_end_of_block_or_statement (parser
);
13921 return error_mark_node
;
13923 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
13925 c_parser_consume_token (parser
);
13926 ce
= c_parser_expression (parser
);
13927 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
13929 if (!stride
|| stride
== error_mark_node
)
13931 c_parser_skip_to_end_of_block_or_statement (parser
);
13932 return error_mark_node
;
13937 c_parser_error (parser
, "expected array notation expression");
13940 c_parser_error (parser
, "expected array notation expression");
13942 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13944 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
13945 end_index
, stride
, type
);
13946 if (value_tree
!= error_mark_node
)
13947 SET_EXPR_LOCATION (value_tree
, loc
);
13951 #include "gt-c-c-parser.h"