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
)
508 if (c_dialect_objc ())
516 enum c_lookahead_kind
{
517 /* Always treat unknown identifiers as typenames. */
520 /* Could be parsing a nonabstract declarator. Only treat an identifier
521 as a typename if followed by another identifier or a star. */
522 cla_nonabstract_decl
,
524 /* Never treat identifiers as typenames. */
528 /* Return true if the next token from PARSER can start a type name,
529 false otherwise. LA specifies how to do lookahead in order to
530 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
533 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
535 c_token
*token
= c_parser_peek_token (parser
);
536 if (c_token_starts_typename (token
))
539 /* Try a bit harder to detect an unknown typename. */
540 if (la
!= cla_prefer_id
541 && token
->type
== CPP_NAME
542 && token
->id_kind
== C_ID_ID
544 /* Do not try too hard when we could have "object in array". */
545 && !parser
->objc_could_be_foreach_context
547 && (la
== cla_prefer_type
548 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
549 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
551 /* Only unknown identifiers. */
552 && !lookup_name (token
->value
))
558 /* Return true if TOKEN is a type qualifier, false otherwise. */
560 c_token_is_qualifier (c_token
*token
)
565 switch (token
->id_kind
)
573 switch (token
->keyword
)
590 /* Return true if the next token from PARSER is a type qualifier,
593 c_parser_next_token_is_qualifier (c_parser
*parser
)
595 c_token
*token
= c_parser_peek_token (parser
);
596 return c_token_is_qualifier (token
);
599 /* Return true if TOKEN can start declaration specifiers, false
602 c_token_starts_declspecs (c_token
*token
)
607 switch (token
->id_kind
)
616 gcc_assert (c_dialect_objc ());
622 switch (token
->keyword
)
664 if (c_dialect_objc ())
673 /* Return true if TOKEN can start declaration specifiers or a static
674 assertion, false otherwise. */
676 c_token_starts_declaration (c_token
*token
)
678 if (c_token_starts_declspecs (token
)
679 || token
->keyword
== RID_STATIC_ASSERT
)
685 /* Return true if the next token from PARSER can start declaration
686 specifiers, false otherwise. */
688 c_parser_next_token_starts_declspecs (c_parser
*parser
)
690 c_token
*token
= c_parser_peek_token (parser
);
692 /* In Objective-C, a classname normally starts a declspecs unless it
693 is immediately followed by a dot. In that case, it is the
694 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
695 setter/getter on the class. c_token_starts_declspecs() can't
696 differentiate between the two cases because it only checks the
697 current token, so we have a special check here. */
698 if (c_dialect_objc ()
699 && token
->type
== CPP_NAME
700 && token
->id_kind
== C_ID_CLASSNAME
701 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
704 return c_token_starts_declspecs (token
);
707 /* Return true if the next tokens from PARSER can start declaration
708 specifiers or a static assertion, false otherwise. */
710 c_parser_next_tokens_start_declaration (c_parser
*parser
)
712 c_token
*token
= c_parser_peek_token (parser
);
715 if (c_dialect_objc ()
716 && token
->type
== CPP_NAME
717 && token
->id_kind
== C_ID_CLASSNAME
718 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
721 /* Labels do not start declarations. */
722 if (token
->type
== CPP_NAME
723 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
726 if (c_token_starts_declaration (token
))
729 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
735 /* Consume the next token from PARSER. */
738 c_parser_consume_token (c_parser
*parser
)
740 gcc_assert (parser
->tokens_avail
>= 1);
741 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
742 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
743 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
744 if (parser
->tokens
!= &parser
->tokens_buf
[0])
746 else if (parser
->tokens_avail
== 2)
747 parser
->tokens
[0] = parser
->tokens
[1];
748 parser
->tokens_avail
--;
751 /* Expect the current token to be a #pragma. Consume it and remember
752 that we've begun parsing a pragma. */
755 c_parser_consume_pragma (c_parser
*parser
)
757 gcc_assert (!parser
->in_pragma
);
758 gcc_assert (parser
->tokens_avail
>= 1);
759 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
760 if (parser
->tokens
!= &parser
->tokens_buf
[0])
762 else if (parser
->tokens_avail
== 2)
763 parser
->tokens
[0] = parser
->tokens
[1];
764 parser
->tokens_avail
--;
765 parser
->in_pragma
= true;
768 /* Update the globals input_location and in_system_header from
771 c_parser_set_source_position_from_token (c_token
*token
)
773 if (token
->type
!= CPP_EOF
)
775 input_location
= token
->location
;
779 /* Issue a diagnostic of the form
780 FILE:LINE: MESSAGE before TOKEN
781 where TOKEN is the next token in the input stream of PARSER.
782 MESSAGE (specified by the caller) is usually of the form "expected
785 Do not issue a diagnostic if still recovering from an error.
787 ??? This is taken from the C++ parser, but building up messages in
788 this way is not i18n-friendly and some other approach should be
792 c_parser_error (c_parser
*parser
, const char *gmsgid
)
794 c_token
*token
= c_parser_peek_token (parser
);
797 parser
->error
= true;
800 /* This diagnostic makes more sense if it is tagged to the line of
801 the token we just peeked at. */
802 c_parser_set_source_position_from_token (token
);
803 c_parse_error (gmsgid
,
804 /* Because c_parse_error does not understand
805 CPP_KEYWORD, keywords are treated like
807 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
808 /* ??? The C parser does not save the cpp flags of a
809 token, we need to pass 0 here and we will not get
810 the source spelling of some tokens but rather the
811 canonical spelling. */
812 token
->value
, /*flags=*/0);
815 /* If the next token is of the indicated TYPE, consume it. Otherwise,
816 issue the error MSGID. If MSGID is NULL then a message has already
817 been produced and no message will be produced this time. Returns
818 true if found, false otherwise. */
821 c_parser_require (c_parser
*parser
,
825 if (c_parser_next_token_is (parser
, type
))
827 c_parser_consume_token (parser
);
832 c_parser_error (parser
, msgid
);
837 /* If the next token is the indicated keyword, consume it. Otherwise,
838 issue the error MSGID. Returns true if found, false otherwise. */
841 c_parser_require_keyword (c_parser
*parser
,
845 if (c_parser_next_token_is_keyword (parser
, keyword
))
847 c_parser_consume_token (parser
);
852 c_parser_error (parser
, msgid
);
857 /* Like c_parser_require, except that tokens will be skipped until the
858 desired token is found. An error message is still produced if the
859 next token is not as expected. If MSGID is NULL then a message has
860 already been produced and no message will be produced this
864 c_parser_skip_until_found (c_parser
*parser
,
868 unsigned nesting_depth
= 0;
870 if (c_parser_require (parser
, type
, msgid
))
873 /* Skip tokens until the desired token is found. */
876 /* Peek at the next token. */
877 c_token
*token
= c_parser_peek_token (parser
);
878 /* If we've reached the token we want, consume it and stop. */
879 if (token
->type
== type
&& !nesting_depth
)
881 c_parser_consume_token (parser
);
885 /* If we've run out of tokens, stop. */
886 if (token
->type
== CPP_EOF
)
888 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
890 if (token
->type
== CPP_OPEN_BRACE
891 || token
->type
== CPP_OPEN_PAREN
892 || token
->type
== CPP_OPEN_SQUARE
)
894 else if (token
->type
== CPP_CLOSE_BRACE
895 || token
->type
== CPP_CLOSE_PAREN
896 || token
->type
== CPP_CLOSE_SQUARE
)
898 if (nesting_depth
-- == 0)
901 /* Consume this token. */
902 c_parser_consume_token (parser
);
904 parser
->error
= false;
907 /* Skip tokens until the end of a parameter is found, but do not
908 consume the comma, semicolon or closing delimiter. */
911 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
913 unsigned nesting_depth
= 0;
917 c_token
*token
= c_parser_peek_token (parser
);
918 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
921 /* If we've run out of tokens, stop. */
922 if (token
->type
== CPP_EOF
)
924 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
926 if (token
->type
== CPP_OPEN_BRACE
927 || token
->type
== CPP_OPEN_PAREN
928 || token
->type
== CPP_OPEN_SQUARE
)
930 else if (token
->type
== CPP_CLOSE_BRACE
931 || token
->type
== CPP_CLOSE_PAREN
932 || token
->type
== CPP_CLOSE_SQUARE
)
934 if (nesting_depth
-- == 0)
937 /* Consume this token. */
938 c_parser_consume_token (parser
);
940 parser
->error
= false;
943 /* Expect to be at the end of the pragma directive and consume an
944 end of line marker. */
947 c_parser_skip_to_pragma_eol (c_parser
*parser
)
949 gcc_assert (parser
->in_pragma
);
950 parser
->in_pragma
= false;
952 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
955 c_token
*token
= c_parser_peek_token (parser
);
956 if (token
->type
== CPP_EOF
)
958 if (token
->type
== CPP_PRAGMA_EOL
)
960 c_parser_consume_token (parser
);
963 c_parser_consume_token (parser
);
966 parser
->error
= false;
969 /* Skip tokens until we have consumed an entire block, or until we
970 have consumed a non-nested ';'. */
973 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
975 unsigned nesting_depth
= 0;
976 bool save_error
= parser
->error
;
982 /* Peek at the next token. */
983 token
= c_parser_peek_token (parser
);
991 if (parser
->in_pragma
)
996 /* If the next token is a ';', we have reached the
997 end of the statement. */
1000 /* Consume the ';'. */
1001 c_parser_consume_token (parser
);
1006 case CPP_CLOSE_BRACE
:
1007 /* If the next token is a non-nested '}', then we have
1008 reached the end of the current block. */
1009 if (nesting_depth
== 0 || --nesting_depth
== 0)
1011 c_parser_consume_token (parser
);
1016 case CPP_OPEN_BRACE
:
1017 /* If it the next token is a '{', then we are entering a new
1018 block. Consume the entire block. */
1023 /* If we see a pragma, consume the whole thing at once. We
1024 have some safeguards against consuming pragmas willy-nilly.
1025 Normally, we'd expect to be here with parser->error set,
1026 which disables these safeguards. But it's possible to get
1027 here for secondary error recovery, after parser->error has
1029 c_parser_consume_pragma (parser
);
1030 c_parser_skip_to_pragma_eol (parser
);
1031 parser
->error
= save_error
;
1038 c_parser_consume_token (parser
);
1042 parser
->error
= false;
1045 /* CPP's options (initialized by c-opts.c). */
1046 extern cpp_options
*cpp_opts
;
1048 /* Save the warning flags which are controlled by __extension__. */
1051 disable_extension_diagnostics (void)
1054 | (warn_pointer_arith
<< 1)
1055 | (warn_traditional
<< 2)
1057 | (warn_long_long
<< 4)
1058 | (warn_cxx_compat
<< 5)
1059 | (warn_overlength_strings
<< 6));
1060 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1061 warn_pointer_arith
= 0;
1062 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1064 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1065 warn_cxx_compat
= 0;
1066 warn_overlength_strings
= 0;
1070 /* Restore the warning flags which are controlled by __extension__.
1071 FLAGS is the return value from disable_extension_diagnostics. */
1074 restore_extension_diagnostics (int flags
)
1076 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1077 warn_pointer_arith
= (flags
>> 1) & 1;
1078 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1079 flag_iso
= (flags
>> 3) & 1;
1080 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1081 warn_cxx_compat
= (flags
>> 5) & 1;
1082 warn_overlength_strings
= (flags
>> 6) & 1;
1085 /* Possibly kinds of declarator to parse. */
1086 typedef enum c_dtr_syn
{
1087 /* A normal declarator with an identifier. */
1089 /* An abstract declarator (maybe empty). */
1091 /* A parameter declarator: may be either, but after a type name does
1092 not redeclare a typedef name as an identifier if it can
1093 alternatively be interpreted as a typedef name; see DR#009,
1094 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1095 following DR#249. For example, given a typedef T, "int T" and
1096 "int *T" are valid parameter declarations redeclaring T, while
1097 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1098 abstract declarators rather than involving redundant parentheses;
1099 the same applies with attributes inside the parentheses before
1104 /* The binary operation precedence levels, where 0 is a dummy lowest level
1105 used for the bottom of the stack. */
1106 enum c_parser_prec
{
1121 static void c_parser_external_declaration (c_parser
*);
1122 static void c_parser_asm_definition (c_parser
*);
1123 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1124 bool, bool, tree
*, vec
<c_token
>);
1125 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1126 static void c_parser_static_assert_declaration (c_parser
*);
1127 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1128 bool, bool, enum c_lookahead_kind
);
1129 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1130 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1131 static tree
c_parser_struct_declaration (c_parser
*);
1132 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1133 static tree
c_parser_alignas_specifier (c_parser
*);
1134 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1136 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1138 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1140 struct c_declarator
*);
1141 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1142 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1144 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1145 static tree
c_parser_simple_asm_expr (c_parser
*);
1146 static tree
c_parser_attributes (c_parser
*);
1147 static struct c_type_name
*c_parser_type_name (c_parser
*);
1148 static struct c_expr
c_parser_initializer (c_parser
*);
1149 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1150 static void c_parser_initelt (c_parser
*, struct obstack
*);
1151 static void c_parser_initval (c_parser
*, struct c_expr
*,
1153 static tree
c_parser_compound_statement (c_parser
*);
1154 static void c_parser_compound_statement_nostart (c_parser
*);
1155 static void c_parser_label (c_parser
*);
1156 static void c_parser_statement (c_parser
*);
1157 static void c_parser_statement_after_labels (c_parser
*);
1158 static void c_parser_if_statement (c_parser
*);
1159 static void c_parser_switch_statement (c_parser
*);
1160 static void c_parser_while_statement (c_parser
*);
1161 static void c_parser_do_statement (c_parser
*);
1162 static void c_parser_for_statement (c_parser
*, bool);
1163 static tree
c_parser_asm_statement (c_parser
*);
1164 static tree
c_parser_asm_operands (c_parser
*);
1165 static tree
c_parser_asm_goto_operands (c_parser
*);
1166 static tree
c_parser_asm_clobbers (c_parser
*);
1167 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1169 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1170 struct c_expr
*, tree
);
1171 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1173 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1174 static struct c_expr
c_parser_unary_expression (c_parser
*);
1175 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1176 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1177 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1178 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1179 struct c_type_name
*,
1181 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1184 static tree
c_parser_transaction (c_parser
*, enum rid
);
1185 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1186 static tree
c_parser_transaction_cancel (c_parser
*);
1187 static struct c_expr
c_parser_expression (c_parser
*);
1188 static struct c_expr
c_parser_expression_conv (c_parser
*);
1189 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1190 vec
<tree
, va_gc
> **, location_t
*,
1192 static void c_parser_omp_construct (c_parser
*);
1193 static void c_parser_omp_threadprivate (c_parser
*);
1194 static void c_parser_omp_barrier (c_parser
*);
1195 static void c_parser_omp_flush (c_parser
*);
1196 static void c_parser_omp_taskwait (c_parser
*);
1197 static void c_parser_omp_taskyield (c_parser
*);
1198 static void c_parser_omp_cancel (c_parser
*);
1199 static void c_parser_omp_cancellation_point (c_parser
*);
1201 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1202 pragma_stmt
, pragma_compound
};
1203 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1204 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1205 static void c_parser_omp_end_declare_target (c_parser
*);
1206 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1208 /* These Objective-C parser functions are only ever called when
1209 compiling Objective-C. */
1210 static void c_parser_objc_class_definition (c_parser
*, tree
);
1211 static void c_parser_objc_class_instance_variables (c_parser
*);
1212 static void c_parser_objc_class_declaration (c_parser
*);
1213 static void c_parser_objc_alias_declaration (c_parser
*);
1214 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1215 static bool c_parser_objc_method_type (c_parser
*);
1216 static void c_parser_objc_method_definition (c_parser
*);
1217 static void c_parser_objc_methodprotolist (c_parser
*);
1218 static void c_parser_objc_methodproto (c_parser
*);
1219 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1220 static tree
c_parser_objc_type_name (c_parser
*);
1221 static tree
c_parser_objc_protocol_refs (c_parser
*);
1222 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1223 static void c_parser_objc_synchronized_statement (c_parser
*);
1224 static tree
c_parser_objc_selector (c_parser
*);
1225 static tree
c_parser_objc_selector_arg (c_parser
*);
1226 static tree
c_parser_objc_receiver (c_parser
*);
1227 static tree
c_parser_objc_message_args (c_parser
*);
1228 static tree
c_parser_objc_keywordexpr (c_parser
*);
1229 static void c_parser_objc_at_property_declaration (c_parser
*);
1230 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1231 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1232 static bool c_parser_objc_diagnose_bad_element_prefix
1233 (c_parser
*, struct c_declspecs
*);
1235 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1237 /* Parse a translation unit (C90 6.7, C99 6.9).
1240 external-declarations
1242 external-declarations:
1243 external-declaration
1244 external-declarations external-declaration
1253 c_parser_translation_unit (c_parser
*parser
)
1255 if (c_parser_next_token_is (parser
, CPP_EOF
))
1257 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1258 "ISO C forbids an empty translation unit");
1262 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1263 mark_valid_location_for_stdc_pragma (false);
1267 c_parser_external_declaration (parser
);
1268 obstack_free (&parser_obstack
, obstack_position
);
1270 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1274 /* Parse an external declaration (C90 6.7, C99 6.9).
1276 external-declaration:
1282 external-declaration:
1285 __extension__ external-declaration
1289 external-declaration:
1290 objc-class-definition
1291 objc-class-declaration
1292 objc-alias-declaration
1293 objc-protocol-definition
1294 objc-method-definition
1299 c_parser_external_declaration (c_parser
*parser
)
1302 switch (c_parser_peek_token (parser
)->type
)
1305 switch (c_parser_peek_token (parser
)->keyword
)
1308 ext
= disable_extension_diagnostics ();
1309 c_parser_consume_token (parser
);
1310 c_parser_external_declaration (parser
);
1311 restore_extension_diagnostics (ext
);
1314 c_parser_asm_definition (parser
);
1316 case RID_AT_INTERFACE
:
1317 case RID_AT_IMPLEMENTATION
:
1318 gcc_assert (c_dialect_objc ());
1319 c_parser_objc_class_definition (parser
, NULL_TREE
);
1322 gcc_assert (c_dialect_objc ());
1323 c_parser_objc_class_declaration (parser
);
1326 gcc_assert (c_dialect_objc ());
1327 c_parser_objc_alias_declaration (parser
);
1329 case RID_AT_PROTOCOL
:
1330 gcc_assert (c_dialect_objc ());
1331 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1333 case RID_AT_PROPERTY
:
1334 gcc_assert (c_dialect_objc ());
1335 c_parser_objc_at_property_declaration (parser
);
1337 case RID_AT_SYNTHESIZE
:
1338 gcc_assert (c_dialect_objc ());
1339 c_parser_objc_at_synthesize_declaration (parser
);
1341 case RID_AT_DYNAMIC
:
1342 gcc_assert (c_dialect_objc ());
1343 c_parser_objc_at_dynamic_declaration (parser
);
1346 gcc_assert (c_dialect_objc ());
1347 c_parser_consume_token (parser
);
1348 objc_finish_implementation ();
1355 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1356 "ISO C does not allow extra %<;%> outside of a function");
1357 c_parser_consume_token (parser
);
1360 mark_valid_location_for_stdc_pragma (true);
1361 c_parser_pragma (parser
, pragma_external
);
1362 mark_valid_location_for_stdc_pragma (false);
1366 if (c_dialect_objc ())
1368 c_parser_objc_method_definition (parser
);
1371 /* Else fall through, and yield a syntax error trying to parse
1372 as a declaration or function definition. */
1375 /* A declaration or a function definition (or, in Objective-C,
1376 an @interface or @protocol with prefix attributes). We can
1377 only tell which after parsing the declaration specifiers, if
1378 any, and the first declarator. */
1379 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1385 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1387 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1388 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1389 accepted; otherwise (old-style parameter declarations) only other
1390 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1391 assertion is accepted; otherwise (old-style parameter declarations)
1392 it is not. If NESTED is true, we are inside a function or parsing
1393 old-style parameter declarations; any functions encountered are
1394 nested functions and declaration specifiers are required; otherwise
1395 we are at top level and functions are normal functions and
1396 declaration specifiers may be optional. If EMPTY_OK is true, empty
1397 declarations are OK (subject to all other constraints); otherwise
1398 (old-style parameter declarations) they are diagnosed. If
1399 START_ATTR_OK is true, the declaration specifiers may start with
1400 attributes; otherwise they may not.
1401 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1402 declaration when parsing an Objective-C foreach statement.
1405 declaration-specifiers init-declarator-list[opt] ;
1406 static_assert-declaration
1408 function-definition:
1409 declaration-specifiers[opt] declarator declaration-list[opt]
1414 declaration-list declaration
1416 init-declarator-list:
1418 init-declarator-list , init-declarator
1421 declarator simple-asm-expr[opt] attributes[opt]
1422 declarator simple-asm-expr[opt] attributes[opt] = initializer
1426 nested-function-definition:
1427 declaration-specifiers declarator declaration-list[opt]
1431 attributes objc-class-definition
1432 attributes objc-category-definition
1433 attributes objc-protocol-definition
1435 The simple-asm-expr and attributes are GNU extensions.
1437 This function does not handle __extension__; that is handled in its
1438 callers. ??? Following the old parser, __extension__ may start
1439 external declarations, declarations in functions and declarations
1440 at the start of "for" loops, but not old-style parameter
1443 C99 requires declaration specifiers in a function definition; the
1444 absence is diagnosed through the diagnosis of implicit int. In GNU
1445 C we also allow but diagnose declarations without declaration
1446 specifiers, but only at top level (elsewhere they conflict with
1449 In Objective-C, declarations of the looping variable in a foreach
1450 statement are exceptionally terminated by 'in' (for example, 'for
1451 (NSObject *object in array) { ... }').
1456 threadprivate-directive */
1459 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1460 bool static_assert_ok
, bool empty_ok
,
1461 bool nested
, bool start_attr_ok
,
1462 tree
*objc_foreach_object_declaration
,
1463 vec
<c_token
> omp_declare_simd_clauses
)
1465 struct c_declspecs
*specs
;
1467 tree all_prefix_attrs
;
1468 bool diagnosed_no_specs
= false;
1469 location_t here
= c_parser_peek_token (parser
)->location
;
1471 if (static_assert_ok
1472 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1474 c_parser_static_assert_declaration (parser
);
1477 specs
= build_null_declspecs ();
1479 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1480 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1481 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1482 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1483 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1484 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1486 error_at (here
, "unknown type name %qE",
1487 c_parser_peek_token (parser
)->value
);
1489 /* Parse declspecs normally to get a correct pointer type, but avoid
1490 a further "fails to be a type name" error. Refuse nested functions
1491 since it is not how the user likely wants us to recover. */
1492 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1493 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1494 c_parser_peek_token (parser
)->value
= error_mark_node
;
1498 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1499 true, cla_nonabstract_decl
);
1502 c_parser_skip_to_end_of_block_or_statement (parser
);
1505 if (nested
&& !specs
->declspecs_seen_p
)
1507 c_parser_error (parser
, "expected declaration specifiers");
1508 c_parser_skip_to_end_of_block_or_statement (parser
);
1511 finish_declspecs (specs
);
1512 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1518 shadow_tag_warned (specs
, 1);
1519 pedwarn (here
, 0, "empty declaration");
1521 c_parser_consume_token (parser
);
1525 /* Provide better error recovery. Note that a type name here is usually
1526 better diagnosed as a redeclaration. */
1528 && specs
->typespec_kind
== ctsk_tagdef
1529 && c_parser_next_token_starts_declspecs (parser
)
1530 && !c_parser_next_token_is (parser
, CPP_NAME
))
1532 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1533 parser
->error
= false;
1534 shadow_tag_warned (specs
, 1);
1537 else if (c_dialect_objc ())
1539 /* Prefix attributes are an error on method decls. */
1540 switch (c_parser_peek_token (parser
)->type
)
1544 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1548 warning_at (c_parser_peek_token (parser
)->location
,
1550 "prefix attributes are ignored for methods");
1551 specs
->attrs
= NULL_TREE
;
1554 c_parser_objc_method_definition (parser
);
1556 c_parser_objc_methodproto (parser
);
1562 /* This is where we parse 'attributes @interface ...',
1563 'attributes @implementation ...', 'attributes @protocol ...'
1564 (where attributes could be, for example, __attribute__
1567 switch (c_parser_peek_token (parser
)->keyword
)
1569 case RID_AT_INTERFACE
:
1571 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1573 c_parser_objc_class_definition (parser
, specs
->attrs
);
1577 case RID_AT_IMPLEMENTATION
:
1579 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1583 warning_at (c_parser_peek_token (parser
)->location
,
1585 "prefix attributes are ignored for implementations");
1586 specs
->attrs
= NULL_TREE
;
1588 c_parser_objc_class_definition (parser
, NULL_TREE
);
1592 case RID_AT_PROTOCOL
:
1594 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1596 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1603 case RID_AT_PROPERTY
:
1606 c_parser_error (parser
, "unexpected attribute");
1607 specs
->attrs
= NULL
;
1615 pending_xref_error ();
1616 prefix_attrs
= specs
->attrs
;
1617 all_prefix_attrs
= prefix_attrs
;
1618 specs
->attrs
= NULL_TREE
;
1621 struct c_declarator
*declarator
;
1625 /* Declaring either one or more declarators (in which case we
1626 should diagnose if there were no declaration specifiers) or a
1627 function definition (in which case the diagnostic for
1628 implicit int suffices). */
1629 declarator
= c_parser_declarator (parser
,
1630 specs
->typespec_kind
!= ctsk_none
,
1631 C_DTR_NORMAL
, &dummy
);
1632 if (declarator
== NULL
)
1634 if (omp_declare_simd_clauses
.exists ())
1635 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1636 omp_declare_simd_clauses
);
1637 c_parser_skip_to_end_of_block_or_statement (parser
);
1640 if (c_parser_next_token_is (parser
, CPP_EQ
)
1641 || c_parser_next_token_is (parser
, CPP_COMMA
)
1642 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1643 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1644 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1645 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1647 tree asm_name
= NULL_TREE
;
1648 tree postfix_attrs
= NULL_TREE
;
1649 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1651 diagnosed_no_specs
= true;
1652 pedwarn (here
, 0, "data definition has no type or storage class");
1654 /* Having seen a data definition, there cannot now be a
1655 function definition. */
1657 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1658 asm_name
= c_parser_simple_asm_expr (parser
);
1659 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1660 postfix_attrs
= c_parser_attributes (parser
);
1661 if (c_parser_next_token_is (parser
, CPP_EQ
))
1665 location_t init_loc
;
1666 c_parser_consume_token (parser
);
1667 /* The declaration of the variable is in effect while
1668 its initializer is parsed. */
1669 d
= start_decl (declarator
, specs
, true,
1670 chainon (postfix_attrs
, all_prefix_attrs
));
1672 d
= error_mark_node
;
1673 if (omp_declare_simd_clauses
.exists ())
1674 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1675 omp_declare_simd_clauses
);
1676 start_init (d
, asm_name
, global_bindings_p ());
1677 init_loc
= c_parser_peek_token (parser
)->location
;
1678 init
= c_parser_initializer (parser
);
1680 if (d
!= error_mark_node
)
1682 maybe_warn_string_init (TREE_TYPE (d
), init
);
1683 finish_decl (d
, init_loc
, init
.value
,
1684 init
.original_type
, asm_name
);
1689 tree d
= start_decl (declarator
, specs
, false,
1690 chainon (postfix_attrs
,
1692 if (omp_declare_simd_clauses
.exists ())
1694 tree parms
= NULL_TREE
;
1695 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1697 struct c_declarator
*ce
= declarator
;
1699 if (ce
->kind
== cdk_function
)
1701 parms
= ce
->u
.arg_info
->parms
;
1705 ce
= ce
->declarator
;
1708 temp_store_parm_decls (d
, parms
);
1709 c_finish_omp_declare_simd (parser
, d
, parms
,
1710 omp_declare_simd_clauses
);
1712 temp_pop_parm_decls ();
1715 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1716 NULL_TREE
, asm_name
);
1718 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1721 *objc_foreach_object_declaration
= d
;
1723 *objc_foreach_object_declaration
= error_mark_node
;
1726 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1728 c_parser_consume_token (parser
);
1729 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1730 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1733 all_prefix_attrs
= prefix_attrs
;
1736 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1738 c_parser_consume_token (parser
);
1741 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1743 /* This can only happen in Objective-C: we found the
1744 'in' that terminates the declaration inside an
1745 Objective-C foreach statement. Do not consume the
1746 token, so that the caller can use it to determine
1747 that this indeed is a foreach context. */
1752 c_parser_error (parser
, "expected %<,%> or %<;%>");
1753 c_parser_skip_to_end_of_block_or_statement (parser
);
1759 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1760 "%<asm%> or %<__attribute__%>");
1761 c_parser_skip_to_end_of_block_or_statement (parser
);
1764 /* Function definition (nested or otherwise). */
1767 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1768 c_push_function_context ();
1770 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1772 /* This can appear in many cases looking nothing like a
1773 function definition, so we don't give a more specific
1774 error suggesting there was one. */
1775 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1776 "or %<__attribute__%>");
1778 c_pop_function_context ();
1782 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1783 tv
= TV_PARSE_INLINE
;
1788 /* Parse old-style parameter declarations. ??? Attributes are
1789 not allowed to start declaration specifiers here because of a
1790 syntax conflict between a function declaration with attribute
1791 suffix and a function definition with an attribute prefix on
1792 first old-style parameter declaration. Following the old
1793 parser, they are not accepted on subsequent old-style
1794 parameter declarations either. However, there is no
1795 ambiguity after the first declaration, nor indeed on the
1796 first as long as we don't allow postfix attributes after a
1797 declarator with a nonempty identifier list in a definition;
1798 and postfix attributes have never been accepted here in
1799 function definitions either. */
1800 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1801 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1802 c_parser_declaration_or_fndef (parser
, false, false, false,
1803 true, false, NULL
, vNULL
);
1804 store_parm_decls ();
1805 if (omp_declare_simd_clauses
.exists ())
1806 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1807 omp_declare_simd_clauses
);
1808 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1809 = c_parser_peek_token (parser
)->location
;
1810 fnbody
= c_parser_compound_statement (parser
);
1811 if (flag_enable_cilkplus
&& contains_array_notation_expr (fnbody
))
1812 fnbody
= expand_array_notation_exprs (fnbody
);
1815 tree decl
= current_function_decl
;
1816 /* Mark nested functions as needing static-chain initially.
1817 lower_nested_functions will recompute it but the
1818 DECL_STATIC_CHAIN flag is also used before that happens,
1819 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1820 DECL_STATIC_CHAIN (decl
) = 1;
1823 c_pop_function_context ();
1824 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1837 /* Parse an asm-definition (asm() outside a function body). This is a
1845 c_parser_asm_definition (c_parser
*parser
)
1847 tree asm_str
= c_parser_simple_asm_expr (parser
);
1849 add_asm_node (asm_str
);
1850 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1853 /* Parse a static assertion (C11 6.7.10).
1855 static_assert-declaration:
1856 static_assert-declaration-no-semi ;
1860 c_parser_static_assert_declaration (c_parser
*parser
)
1862 c_parser_static_assert_declaration_no_semi (parser
);
1864 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1865 c_parser_skip_to_end_of_block_or_statement (parser
);
1868 /* Parse a static assertion (C11 6.7.10), without the trailing
1871 static_assert-declaration-no-semi:
1872 _Static_assert ( constant-expression , string-literal )
1876 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1878 location_t assert_loc
, value_loc
;
1882 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1883 assert_loc
= c_parser_peek_token (parser
)->location
;
1887 pedwarn (assert_loc
, OPT_Wpedantic
,
1888 "ISO C99 does not support %<_Static_assert%>");
1890 pedwarn (assert_loc
, OPT_Wpedantic
,
1891 "ISO C90 does not support %<_Static_assert%>");
1893 c_parser_consume_token (parser
);
1894 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1896 value_loc
= c_parser_peek_token (parser
)->location
;
1897 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1898 parser
->lex_untranslated_string
= true;
1899 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1901 parser
->lex_untranslated_string
= false;
1904 switch (c_parser_peek_token (parser
)->type
)
1910 case CPP_UTF8STRING
:
1911 string
= c_parser_peek_token (parser
)->value
;
1912 c_parser_consume_token (parser
);
1913 parser
->lex_untranslated_string
= false;
1916 c_parser_error (parser
, "expected string literal");
1917 parser
->lex_untranslated_string
= false;
1920 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1922 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1924 error_at (value_loc
, "expression in static assertion is not an integer");
1927 if (TREE_CODE (value
) != INTEGER_CST
)
1929 value
= c_fully_fold (value
, false, NULL
);
1930 if (TREE_CODE (value
) == INTEGER_CST
)
1931 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1932 "is not an integer constant expression");
1934 if (TREE_CODE (value
) != INTEGER_CST
)
1936 error_at (value_loc
, "expression in static assertion is not constant");
1939 constant_expression_warning (value
);
1940 if (integer_zerop (value
))
1941 error_at (assert_loc
, "static assertion failed: %E", string
);
1944 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1945 6.7), adding them to SPECS (which may already include some).
1946 Storage class specifiers are accepted iff SCSPEC_OK; type
1947 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
1948 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
1951 declaration-specifiers:
1952 storage-class-specifier declaration-specifiers[opt]
1953 type-specifier declaration-specifiers[opt]
1954 type-qualifier declaration-specifiers[opt]
1955 function-specifier declaration-specifiers[opt]
1956 alignment-specifier declaration-specifiers[opt]
1958 Function specifiers (inline) are from C99, and are currently
1959 handled as storage class specifiers, as is __thread. Alignment
1960 specifiers are from C11.
1962 C90 6.5.1, C99 6.7.1:
1963 storage-class-specifier:
1975 (_Noreturn is new in C11.)
1977 C90 6.5.2, C99 6.7.2:
1990 [_Imaginary removed in C99 TC2]
1991 struct-or-union-specifier
1995 (_Bool and _Complex are new in C99.)
1997 C90 6.5.3, C99 6.7.3:
2003 address-space-qualifier
2005 (restrict is new in C99.)
2009 declaration-specifiers:
2010 attributes declaration-specifiers[opt]
2016 identifier recognized by the target
2018 storage-class-specifier:
2031 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2032 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2037 class-name objc-protocol-refs[opt]
2038 typedef-name objc-protocol-refs
2043 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2044 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2045 bool alignspec_ok
, enum c_lookahead_kind la
)
2047 bool attrs_ok
= start_attr_ok
;
2048 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2051 gcc_assert (la
== cla_prefer_id
);
2053 while (c_parser_next_token_is (parser
, CPP_NAME
)
2054 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2055 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2057 struct c_typespec t
;
2060 location_t loc
= c_parser_peek_token (parser
)->location
;
2062 /* If we cannot accept a type, exit if the next token must start
2063 one. Also, if we already have seen a tagged definition,
2064 a typename would be an error anyway and likely the user
2065 has simply forgotten a semicolon, so we exit. */
2066 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2067 && c_parser_next_tokens_start_typename (parser
, la
)
2068 && !c_parser_next_token_is_qualifier (parser
))
2071 if (c_parser_next_token_is (parser
, CPP_NAME
))
2073 c_token
*name_token
= c_parser_peek_token (parser
);
2074 tree value
= name_token
->value
;
2075 c_id_kind kind
= name_token
->id_kind
;
2077 if (kind
== C_ID_ADDRSPACE
)
2080 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2081 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2082 c_parser_consume_token (parser
);
2087 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2089 /* If we cannot accept a type, and the next token must start one,
2090 exit. Do the same if we already have seen a tagged definition,
2091 since it would be an error anyway and likely the user has simply
2092 forgotten a semicolon. */
2093 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2096 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2097 a C_ID_CLASSNAME. */
2098 c_parser_consume_token (parser
);
2101 if (kind
== C_ID_ID
)
2103 error ("unknown type name %qE", value
);
2104 t
.kind
= ctsk_typedef
;
2105 t
.spec
= error_mark_node
;
2107 else if (kind
== C_ID_TYPENAME
2108 && (!c_dialect_objc ()
2109 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2111 t
.kind
= ctsk_typedef
;
2112 /* For a typedef name, record the meaning, not the name.
2113 In case of 'foo foo, bar;'. */
2114 t
.spec
= lookup_name (value
);
2118 tree proto
= NULL_TREE
;
2119 gcc_assert (c_dialect_objc ());
2121 if (c_parser_next_token_is (parser
, CPP_LESS
))
2122 proto
= c_parser_objc_protocol_refs (parser
);
2123 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2126 t
.expr_const_operands
= true;
2127 declspecs_add_type (name_token
->location
, specs
, t
);
2130 if (c_parser_next_token_is (parser
, CPP_LESS
))
2132 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2133 nisse@lysator.liu.se. */
2135 gcc_assert (c_dialect_objc ());
2136 if (!typespec_ok
|| seen_type
)
2138 proto
= c_parser_objc_protocol_refs (parser
);
2140 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2142 t
.expr_const_operands
= true;
2143 declspecs_add_type (loc
, specs
, t
);
2146 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2147 switch (c_parser_peek_token (parser
)->keyword
)
2160 /* TODO: Distinguish between function specifiers (inline, noreturn)
2161 and storage class specifiers, either here or in
2162 declspecs_add_scspec. */
2163 declspecs_add_scspec (loc
, specs
,
2164 c_parser_peek_token (parser
)->value
);
2165 c_parser_consume_token (parser
);
2189 if (c_dialect_objc ())
2190 parser
->objc_need_raw_identifier
= true;
2191 t
.kind
= ctsk_resword
;
2192 t
.spec
= c_parser_peek_token (parser
)->value
;
2194 t
.expr_const_operands
= true;
2195 declspecs_add_type (loc
, specs
, t
);
2196 c_parser_consume_token (parser
);
2203 t
= c_parser_enum_specifier (parser
);
2204 declspecs_add_type (loc
, specs
, t
);
2212 t
= c_parser_struct_or_union_specifier (parser
);
2213 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2214 declspecs_add_type (loc
, specs
, t
);
2217 /* ??? The old parser rejected typeof after other type
2218 specifiers, but is a syntax error the best way of
2220 if (!typespec_ok
|| seen_type
)
2224 t
= c_parser_typeof_specifier (parser
);
2225 declspecs_add_type (loc
, specs
, t
);
2231 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2232 c_parser_consume_token (parser
);
2237 attrs
= c_parser_attributes (parser
);
2238 declspecs_add_attrs (loc
, specs
, attrs
);
2243 align
= c_parser_alignas_specifier (parser
);
2244 declspecs_add_alignas (loc
, specs
, align
);
2253 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2256 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2257 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2258 enum attributes[opt] identifier
2260 The form with trailing comma is new in C99. The forms with
2261 attributes are GNU extensions. In GNU C, we accept any expression
2262 without commas in the syntax (assignment expressions, not just
2263 conditional expressions); assignment expressions will be diagnosed
2268 enumerator-list , enumerator
2271 enumeration-constant
2272 enumeration-constant = constant-expression
2275 static struct c_typespec
2276 c_parser_enum_specifier (c_parser
*parser
)
2278 struct c_typespec ret
;
2280 tree ident
= NULL_TREE
;
2281 location_t enum_loc
;
2282 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2283 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2284 enum_loc
= c_parser_peek_token (parser
)->location
;
2285 c_parser_consume_token (parser
);
2286 attrs
= c_parser_attributes (parser
);
2287 enum_loc
= c_parser_peek_token (parser
)->location
;
2288 /* Set the location in case we create a decl now. */
2289 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2290 if (c_parser_next_token_is (parser
, CPP_NAME
))
2292 ident
= c_parser_peek_token (parser
)->value
;
2293 ident_loc
= c_parser_peek_token (parser
)->location
;
2294 enum_loc
= ident_loc
;
2295 c_parser_consume_token (parser
);
2297 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2299 /* Parse an enum definition. */
2300 struct c_enum_contents the_enum
;
2303 /* We chain the enumerators in reverse order, then put them in
2304 forward order at the end. */
2306 timevar_push (TV_PARSE_ENUM
);
2307 type
= start_enum (enum_loc
, &the_enum
, ident
);
2309 c_parser_consume_token (parser
);
2317 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2318 location_t decl_loc
, value_loc
;
2319 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2321 c_parser_error (parser
, "expected identifier");
2322 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2323 values
= error_mark_node
;
2326 token
= c_parser_peek_token (parser
);
2327 enum_id
= token
->value
;
2328 /* Set the location in case we create a decl now. */
2329 c_parser_set_source_position_from_token (token
);
2330 decl_loc
= value_loc
= token
->location
;
2331 c_parser_consume_token (parser
);
2332 if (c_parser_next_token_is (parser
, CPP_EQ
))
2334 c_parser_consume_token (parser
);
2335 value_loc
= c_parser_peek_token (parser
)->location
;
2336 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2339 enum_value
= NULL_TREE
;
2340 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2341 &the_enum
, enum_id
, enum_value
);
2342 TREE_CHAIN (enum_decl
) = values
;
2345 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2347 comma_loc
= c_parser_peek_token (parser
)->location
;
2349 c_parser_consume_token (parser
);
2351 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2353 if (seen_comma
&& !flag_isoc99
)
2354 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2355 c_parser_consume_token (parser
);
2360 c_parser_error (parser
, "expected %<,%> or %<}%>");
2361 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2362 values
= error_mark_node
;
2366 postfix_attrs
= c_parser_attributes (parser
);
2367 ret
.spec
= finish_enum (type
, nreverse (values
),
2368 chainon (attrs
, postfix_attrs
));
2369 ret
.kind
= ctsk_tagdef
;
2370 ret
.expr
= NULL_TREE
;
2371 ret
.expr_const_operands
= true;
2372 timevar_pop (TV_PARSE_ENUM
);
2377 c_parser_error (parser
, "expected %<{%>");
2378 ret
.spec
= error_mark_node
;
2379 ret
.kind
= ctsk_tagref
;
2380 ret
.expr
= NULL_TREE
;
2381 ret
.expr_const_operands
= true;
2384 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2385 /* In ISO C, enumerated types can be referred to only if already
2387 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2390 pedwarn (enum_loc
, OPT_Wpedantic
,
2391 "ISO C forbids forward references to %<enum%> types");
2396 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2398 struct-or-union-specifier:
2399 struct-or-union attributes[opt] identifier[opt]
2400 { struct-contents } attributes[opt]
2401 struct-or-union attributes[opt] identifier
2404 struct-declaration-list
2406 struct-declaration-list:
2407 struct-declaration ;
2408 struct-declaration-list struct-declaration ;
2415 struct-declaration-list struct-declaration
2417 struct-declaration-list:
2418 struct-declaration-list ;
2421 (Note that in the syntax here, unlike that in ISO C, the semicolons
2422 are included here rather than in struct-declaration, in order to
2423 describe the syntax with extra semicolons and missing semicolon at
2428 struct-declaration-list:
2429 @defs ( class-name )
2431 (Note this does not include a trailing semicolon, but can be
2432 followed by further declarations, and gets a pedwarn-if-pedantic
2433 when followed by a semicolon.) */
2435 static struct c_typespec
2436 c_parser_struct_or_union_specifier (c_parser
*parser
)
2438 struct c_typespec ret
;
2440 tree ident
= NULL_TREE
;
2441 location_t struct_loc
;
2442 location_t ident_loc
= UNKNOWN_LOCATION
;
2443 enum tree_code code
;
2444 switch (c_parser_peek_token (parser
)->keyword
)
2455 struct_loc
= c_parser_peek_token (parser
)->location
;
2456 c_parser_consume_token (parser
);
2457 attrs
= c_parser_attributes (parser
);
2459 /* Set the location in case we create a decl now. */
2460 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2462 if (c_parser_next_token_is (parser
, CPP_NAME
))
2464 ident
= c_parser_peek_token (parser
)->value
;
2465 ident_loc
= c_parser_peek_token (parser
)->location
;
2466 struct_loc
= ident_loc
;
2467 c_parser_consume_token (parser
);
2469 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2471 /* Parse a struct or union definition. Start the scope of the
2472 tag before parsing components. */
2473 struct c_struct_parse_info
*struct_info
;
2474 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2476 /* We chain the components in reverse order, then put them in
2477 forward order at the end. Each struct-declaration may
2478 declare multiple components (comma-separated), so we must use
2479 chainon to join them, although when parsing each
2480 struct-declaration we can use TREE_CHAIN directly.
2482 The theory behind all this is that there will be more
2483 semicolon separated fields than comma separated fields, and
2484 so we'll be minimizing the number of node traversals required
2487 timevar_push (TV_PARSE_STRUCT
);
2488 contents
= NULL_TREE
;
2489 c_parser_consume_token (parser
);
2490 /* Handle the Objective-C @defs construct,
2491 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2492 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2495 gcc_assert (c_dialect_objc ());
2496 c_parser_consume_token (parser
);
2497 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2499 if (c_parser_next_token_is (parser
, CPP_NAME
)
2500 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2502 name
= c_parser_peek_token (parser
)->value
;
2503 c_parser_consume_token (parser
);
2507 c_parser_error (parser
, "expected class name");
2508 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2511 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2513 contents
= nreverse (objc_get_class_ivars (name
));
2516 /* Parse the struct-declarations and semicolons. Problems with
2517 semicolons are diagnosed here; empty structures are diagnosed
2522 /* Parse any stray semicolon. */
2523 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2525 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2526 "extra semicolon in struct or union specified");
2527 c_parser_consume_token (parser
);
2530 /* Stop if at the end of the struct or union contents. */
2531 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2533 c_parser_consume_token (parser
);
2536 /* Accept #pragmas at struct scope. */
2537 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2539 c_parser_pragma (parser
, pragma_struct
);
2542 /* Parse some comma-separated declarations, but not the
2543 trailing semicolon if any. */
2544 decls
= c_parser_struct_declaration (parser
);
2545 contents
= chainon (decls
, contents
);
2546 /* If no semicolon follows, either we have a parse error or
2547 are at the end of the struct or union and should
2549 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2550 c_parser_consume_token (parser
);
2553 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2554 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2555 "no semicolon at end of struct or union");
2556 else if (parser
->error
2557 || !c_parser_next_token_starts_declspecs (parser
))
2559 c_parser_error (parser
, "expected %<;%>");
2560 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2564 /* If we come here, we have already emitted an error
2565 for an expected `;', identifier or `(', and we also
2566 recovered already. Go on with the next field. */
2569 postfix_attrs
= c_parser_attributes (parser
);
2570 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2571 chainon (attrs
, postfix_attrs
), struct_info
);
2572 ret
.kind
= ctsk_tagdef
;
2573 ret
.expr
= NULL_TREE
;
2574 ret
.expr_const_operands
= true;
2575 timevar_pop (TV_PARSE_STRUCT
);
2580 c_parser_error (parser
, "expected %<{%>");
2581 ret
.spec
= error_mark_node
;
2582 ret
.kind
= ctsk_tagref
;
2583 ret
.expr
= NULL_TREE
;
2584 ret
.expr_const_operands
= true;
2587 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2591 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2592 the trailing semicolon.
2595 specifier-qualifier-list struct-declarator-list
2596 static_assert-declaration-no-semi
2598 specifier-qualifier-list:
2599 type-specifier specifier-qualifier-list[opt]
2600 type-qualifier specifier-qualifier-list[opt]
2601 attributes specifier-qualifier-list[opt]
2603 struct-declarator-list:
2605 struct-declarator-list , attributes[opt] struct-declarator
2608 declarator attributes[opt]
2609 declarator[opt] : constant-expression attributes[opt]
2614 __extension__ struct-declaration
2615 specifier-qualifier-list
2617 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2618 of attributes where shown is a GNU extension. In GNU C, we accept
2619 any expression without commas in the syntax (assignment
2620 expressions, not just conditional expressions); assignment
2621 expressions will be diagnosed as non-constant. */
2624 c_parser_struct_declaration (c_parser
*parser
)
2626 struct c_declspecs
*specs
;
2628 tree all_prefix_attrs
;
2630 location_t decl_loc
;
2631 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2635 ext
= disable_extension_diagnostics ();
2636 c_parser_consume_token (parser
);
2637 decl
= c_parser_struct_declaration (parser
);
2638 restore_extension_diagnostics (ext
);
2641 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2643 c_parser_static_assert_declaration_no_semi (parser
);
2646 specs
= build_null_declspecs ();
2647 decl_loc
= c_parser_peek_token (parser
)->location
;
2648 /* Strictly by the standard, we shouldn't allow _Alignas here,
2649 but it appears to have been intended to allow it there, so
2650 we're keeping it as it is until WG14 reaches a conclusion
2652 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2653 c_parser_declspecs (parser
, specs
, false, true, true,
2654 true, cla_nonabstract_decl
);
2657 if (!specs
->declspecs_seen_p
)
2659 c_parser_error (parser
, "expected specifier-qualifier-list");
2662 finish_declspecs (specs
);
2663 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2664 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2667 if (specs
->typespec_kind
== ctsk_none
)
2669 pedwarn (decl_loc
, OPT_Wpedantic
,
2670 "ISO C forbids member declarations with no members");
2671 shadow_tag_warned (specs
, pedantic
);
2676 /* Support for unnamed structs or unions as members of
2677 structs or unions (which is [a] useful and [b] supports
2681 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2682 build_id_declarator (NULL_TREE
), specs
,
2685 decl_attributes (&ret
, attrs
, 0);
2690 /* Provide better error recovery. Note that a type name here is valid,
2691 and will be treated as a field name. */
2692 if (specs
->typespec_kind
== ctsk_tagdef
2693 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2694 && c_parser_next_token_starts_declspecs (parser
)
2695 && !c_parser_next_token_is (parser
, CPP_NAME
))
2697 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2698 parser
->error
= false;
2702 pending_xref_error ();
2703 prefix_attrs
= specs
->attrs
;
2704 all_prefix_attrs
= prefix_attrs
;
2705 specs
->attrs
= NULL_TREE
;
2709 /* Declaring one or more declarators or un-named bit-fields. */
2710 struct c_declarator
*declarator
;
2712 if (c_parser_next_token_is (parser
, CPP_COLON
))
2713 declarator
= build_id_declarator (NULL_TREE
);
2715 declarator
= c_parser_declarator (parser
,
2716 specs
->typespec_kind
!= ctsk_none
,
2717 C_DTR_NORMAL
, &dummy
);
2718 if (declarator
== NULL
)
2720 c_parser_skip_to_end_of_block_or_statement (parser
);
2723 if (c_parser_next_token_is (parser
, CPP_COLON
)
2724 || c_parser_next_token_is (parser
, CPP_COMMA
)
2725 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2726 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2727 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2729 tree postfix_attrs
= NULL_TREE
;
2730 tree width
= NULL_TREE
;
2732 if (c_parser_next_token_is (parser
, CPP_COLON
))
2734 c_parser_consume_token (parser
);
2735 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2737 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2738 postfix_attrs
= c_parser_attributes (parser
);
2739 d
= grokfield (c_parser_peek_token (parser
)->location
,
2740 declarator
, specs
, width
, &all_prefix_attrs
);
2741 decl_attributes (&d
, chainon (postfix_attrs
,
2742 all_prefix_attrs
), 0);
2743 DECL_CHAIN (d
) = decls
;
2745 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2746 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2749 all_prefix_attrs
= prefix_attrs
;
2750 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2751 c_parser_consume_token (parser
);
2752 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2753 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2755 /* Semicolon consumed in caller. */
2760 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2766 c_parser_error (parser
,
2767 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2768 "%<__attribute__%>");
2775 /* Parse a typeof specifier (a GNU extension).
2778 typeof ( expression )
2779 typeof ( type-name )
2782 static struct c_typespec
2783 c_parser_typeof_specifier (c_parser
*parser
)
2785 struct c_typespec ret
;
2786 ret
.kind
= ctsk_typeof
;
2787 ret
.spec
= error_mark_node
;
2788 ret
.expr
= NULL_TREE
;
2789 ret
.expr_const_operands
= true;
2790 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2791 c_parser_consume_token (parser
);
2792 c_inhibit_evaluation_warnings
++;
2794 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2796 c_inhibit_evaluation_warnings
--;
2800 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2802 struct c_type_name
*type
= c_parser_type_name (parser
);
2803 c_inhibit_evaluation_warnings
--;
2807 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2808 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2814 location_t here
= c_parser_peek_token (parser
)->location
;
2815 struct c_expr expr
= c_parser_expression (parser
);
2816 c_inhibit_evaluation_warnings
--;
2818 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2819 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2820 error_at (here
, "%<typeof%> applied to a bit-field");
2821 mark_exp_read (expr
.value
);
2822 ret
.spec
= TREE_TYPE (expr
.value
);
2823 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2824 /* This is returned with the type so that when the type is
2825 evaluated, this can be evaluated. */
2827 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2828 pop_maybe_used (was_vm
);
2830 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2834 /* Parse an alignment-specifier.
2838 alignment-specifier:
2839 _Alignas ( type-name )
2840 _Alignas ( constant-expression )
2844 c_parser_alignas_specifier (c_parser
* parser
)
2846 tree ret
= error_mark_node
;
2847 location_t loc
= c_parser_peek_token (parser
)->location
;
2848 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2849 c_parser_consume_token (parser
);
2853 pedwarn (loc
, OPT_Wpedantic
,
2854 "ISO C99 does not support %<_Alignas%>");
2856 pedwarn (loc
, OPT_Wpedantic
,
2857 "ISO C90 does not support %<_Alignas%>");
2859 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2861 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2863 struct c_type_name
*type
= c_parser_type_name (parser
);
2865 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2868 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2869 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2873 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2874 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2875 be redeclared; otherwise it may not. KIND indicates which kind of
2876 declarator is wanted. Returns a valid declarator except in the
2877 case of a syntax error in which case NULL is returned. *SEEN_ID is
2878 set to true if an identifier being declared is seen; this is used
2879 to diagnose bad forms of abstract array declarators and to
2880 determine whether an identifier list is syntactically permitted.
2883 pointer[opt] direct-declarator
2887 ( attributes[opt] declarator )
2888 direct-declarator array-declarator
2889 direct-declarator ( parameter-type-list )
2890 direct-declarator ( identifier-list[opt] )
2893 * type-qualifier-list[opt]
2894 * type-qualifier-list[opt] pointer
2896 type-qualifier-list:
2899 type-qualifier-list type-qualifier
2900 type-qualifier-list attributes
2903 [ type-qualifier-list[opt] assignment-expression[opt] ]
2904 [ static type-qualifier-list[opt] assignment-expression ]
2905 [ type-qualifier-list static assignment-expression ]
2906 [ type-qualifier-list[opt] * ]
2908 parameter-type-list:
2910 parameter-list , ...
2913 parameter-declaration
2914 parameter-list , parameter-declaration
2916 parameter-declaration:
2917 declaration-specifiers declarator attributes[opt]
2918 declaration-specifiers abstract-declarator[opt] attributes[opt]
2922 identifier-list , identifier
2924 abstract-declarator:
2926 pointer[opt] direct-abstract-declarator
2928 direct-abstract-declarator:
2929 ( attributes[opt] abstract-declarator )
2930 direct-abstract-declarator[opt] array-declarator
2931 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2936 direct-declarator ( parameter-forward-declarations
2937 parameter-type-list[opt] )
2939 direct-abstract-declarator:
2940 direct-abstract-declarator[opt] ( parameter-forward-declarations
2941 parameter-type-list[opt] )
2943 parameter-forward-declarations:
2945 parameter-forward-declarations parameter-list ;
2947 The uses of attributes shown above are GNU extensions.
2949 Some forms of array declarator are not included in C99 in the
2950 syntax for abstract declarators; these are disallowed elsewhere.
2951 This may be a defect (DR#289).
2953 This function also accepts an omitted abstract declarator as being
2954 an abstract declarator, although not part of the formal syntax. */
2956 static struct c_declarator
*
2957 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2960 /* Parse any initial pointer part. */
2961 if (c_parser_next_token_is (parser
, CPP_MULT
))
2963 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2964 struct c_declarator
*inner
;
2965 c_parser_consume_token (parser
);
2966 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
2967 false, cla_prefer_id
);
2968 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2972 return make_pointer_declarator (quals_attrs
, inner
);
2974 /* Now we have a direct declarator, direct abstract declarator or
2975 nothing (which counts as a direct abstract declarator here). */
2976 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2979 /* Parse a direct declarator or direct abstract declarator; arguments
2980 as c_parser_declarator. */
2982 static struct c_declarator
*
2983 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2986 /* The direct declarator must start with an identifier (possibly
2987 omitted) or a parenthesized declarator (possibly abstract). In
2988 an ordinary declarator, initial parentheses must start a
2989 parenthesized declarator. In an abstract declarator or parameter
2990 declarator, they could start a parenthesized declarator or a
2991 parameter list. To tell which, the open parenthesis and any
2992 following attributes must be read. If a declaration specifier
2993 follows, then it is a parameter list; if the specifier is a
2994 typedef name, there might be an ambiguity about redeclaring it,
2995 which is resolved in the direction of treating it as a typedef
2996 name. If a close parenthesis follows, it is also an empty
2997 parameter list, as the syntax does not permit empty abstract
2998 declarators. Otherwise, it is a parenthesized declarator (in
2999 which case the analysis may be repeated inside it, recursively).
3001 ??? There is an ambiguity in a parameter declaration "int
3002 (__attribute__((foo)) x)", where x is not a typedef name: it
3003 could be an abstract declarator for a function, or declare x with
3004 parentheses. The proper resolution of this ambiguity needs
3005 documenting. At present we follow an accident of the old
3006 parser's implementation, whereby the first parameter must have
3007 some declaration specifiers other than just attributes. Thus as
3008 a parameter declaration it is treated as a parenthesized
3009 parameter named x, and as an abstract declarator it is
3012 ??? Also following the old parser, attributes inside an empty
3013 parameter list are ignored, making it a list not yielding a
3014 prototype, rather than giving an error or making it have one
3015 parameter with implicit type int.
3017 ??? Also following the old parser, typedef names may be
3018 redeclared in declarators, but not Objective-C class names. */
3020 if (kind
!= C_DTR_ABSTRACT
3021 && c_parser_next_token_is (parser
, CPP_NAME
)
3023 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3024 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3025 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3027 struct c_declarator
*inner
3028 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3030 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3031 c_parser_consume_token (parser
);
3032 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3035 if (kind
!= C_DTR_NORMAL
3036 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3038 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3039 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3042 /* Either we are at the end of an abstract declarator, or we have
3045 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3048 struct c_declarator
*inner
;
3049 c_parser_consume_token (parser
);
3050 attrs
= c_parser_attributes (parser
);
3051 if (kind
!= C_DTR_NORMAL
3052 && (c_parser_next_token_starts_declspecs (parser
)
3053 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3055 struct c_arg_info
*args
3056 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3063 = build_function_declarator (args
,
3064 build_id_declarator (NULL_TREE
));
3065 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3069 /* A parenthesized declarator. */
3070 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3071 if (inner
!= NULL
&& attrs
!= NULL
)
3072 inner
= build_attrs_declarator (attrs
, inner
);
3073 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3075 c_parser_consume_token (parser
);
3079 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3083 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3090 if (kind
== C_DTR_NORMAL
)
3092 c_parser_error (parser
, "expected identifier or %<(%>");
3096 return build_id_declarator (NULL_TREE
);
3100 /* Parse part of a direct declarator or direct abstract declarator,
3101 given that some (in INNER) has already been parsed; ID_PRESENT is
3102 true if an identifier is present, false for an abstract
3105 static struct c_declarator
*
3106 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3107 struct c_declarator
*inner
)
3109 /* Parse a sequence of array declarators and parameter lists. */
3110 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3112 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3113 struct c_declarator
*declarator
;
3114 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3118 c_parser_consume_token (parser
);
3119 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3120 false, cla_prefer_id
);
3121 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3123 c_parser_consume_token (parser
);
3124 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3125 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3126 false, cla_prefer_id
);
3127 if (!quals_attrs
->declspecs_seen_p
)
3129 /* If "static" is present, there must be an array dimension.
3130 Otherwise, there may be a dimension, "*", or no
3135 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3139 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3144 else if (flag_enable_cilkplus
3145 && c_parser_next_token_is (parser
, CPP_COLON
))
3147 dimen
= error_mark_node
;
3149 error_at (c_parser_peek_token (parser
)->location
,
3150 "array notations cannot be used in declaration");
3151 c_parser_consume_token (parser
);
3153 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3155 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3159 c_parser_consume_token (parser
);
3164 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3170 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3173 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3174 c_parser_consume_token (parser
);
3175 else if (flag_enable_cilkplus
3176 && c_parser_next_token_is (parser
, CPP_COLON
))
3178 error_at (c_parser_peek_token (parser
)->location
,
3179 "array notations cannot be used in declaration");
3180 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3185 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3190 mark_exp_read (dimen
);
3191 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3192 static_seen
, star_seen
);
3193 if (declarator
== NULL
)
3195 inner
= set_array_declarator_inner (declarator
, inner
);
3196 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3198 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3201 struct c_arg_info
*args
;
3202 c_parser_consume_token (parser
);
3203 attrs
= c_parser_attributes (parser
);
3204 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3209 inner
= build_function_declarator (args
, inner
);
3210 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3216 /* Parse a parameter list or identifier list, including the closing
3217 parenthesis but not the opening one. ATTRS are the attributes at
3218 the start of the list. ID_LIST_OK is true if an identifier list is
3219 acceptable; such a list must not have attributes at the start. */
3221 static struct c_arg_info
*
3222 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3225 declare_parm_level ();
3226 /* If the list starts with an identifier, it is an identifier list.
3227 Otherwise, it is either a prototype list or an empty list. */
3230 && c_parser_next_token_is (parser
, CPP_NAME
)
3231 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3233 /* Look ahead to detect typos in type names. */
3234 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3235 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3236 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3237 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3239 tree list
= NULL_TREE
, *nextp
= &list
;
3240 while (c_parser_next_token_is (parser
, CPP_NAME
)
3241 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3243 *nextp
= build_tree_list (NULL_TREE
,
3244 c_parser_peek_token (parser
)->value
);
3245 nextp
= & TREE_CHAIN (*nextp
);
3246 c_parser_consume_token (parser
);
3247 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3249 c_parser_consume_token (parser
);
3250 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3252 c_parser_error (parser
, "expected identifier");
3256 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3258 struct c_arg_info
*ret
= build_arg_info ();
3260 c_parser_consume_token (parser
);
3266 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3274 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3281 /* Parse a parameter list (possibly empty), including the closing
3282 parenthesis but not the opening one. ATTRS are the attributes at
3283 the start of the list. EXPR is NULL or an expression that needs to
3284 be evaluated for the side effects of array size expressions in the
3287 static struct c_arg_info
*
3288 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3290 bool bad_parm
= false;
3292 /* ??? Following the old parser, forward parameter declarations may
3293 use abstract declarators, and if no real parameter declarations
3294 follow the forward declarations then this is not diagnosed. Also
3295 note as above that attributes are ignored as the only contents of
3296 the parentheses, or as the only contents after forward
3298 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3300 struct c_arg_info
*ret
= build_arg_info ();
3301 c_parser_consume_token (parser
);
3304 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3306 struct c_arg_info
*ret
= build_arg_info ();
3308 if (flag_allow_parameterless_variadic_functions
)
3310 /* F (...) is allowed. */
3311 ret
->types
= NULL_TREE
;
3315 /* Suppress -Wold-style-definition for this case. */
3316 ret
->types
= error_mark_node
;
3317 error_at (c_parser_peek_token (parser
)->location
,
3318 "ISO C requires a named argument before %<...%>");
3320 c_parser_consume_token (parser
);
3321 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3323 c_parser_consume_token (parser
);
3328 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3333 /* Nonempty list of parameters, either terminated with semicolon
3334 (forward declarations; recurse) or with close parenthesis (normal
3335 function) or with ", ... )" (variadic function). */
3338 /* Parse a parameter. */
3339 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3344 push_parm_decl (parm
, &expr
);
3345 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3348 c_parser_consume_token (parser
);
3349 mark_forward_parm_decls ();
3350 new_attrs
= c_parser_attributes (parser
);
3351 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3353 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3355 c_parser_consume_token (parser
);
3359 return get_parm_info (false, expr
);
3361 if (!c_parser_require (parser
, CPP_COMMA
,
3362 "expected %<;%>, %<,%> or %<)%>"))
3364 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3367 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3369 c_parser_consume_token (parser
);
3370 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3372 c_parser_consume_token (parser
);
3376 return get_parm_info (true, expr
);
3380 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3388 /* Parse a parameter declaration. ATTRS are the attributes at the
3389 start of the declaration if it is the first parameter. */
3391 static struct c_parm
*
3392 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3394 struct c_declspecs
*specs
;
3395 struct c_declarator
*declarator
;
3397 tree postfix_attrs
= NULL_TREE
;
3400 /* Accept #pragmas between parameter declarations. */
3401 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3402 c_parser_pragma (parser
, pragma_param
);
3404 if (!c_parser_next_token_starts_declspecs (parser
))
3406 c_token
*token
= c_parser_peek_token (parser
);
3409 c_parser_set_source_position_from_token (token
);
3410 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3412 error ("unknown type name %qE", token
->value
);
3413 parser
->error
= true;
3415 /* ??? In some Objective-C cases '...' isn't applicable so there
3416 should be a different message. */
3418 c_parser_error (parser
,
3419 "expected declaration specifiers or %<...%>");
3420 c_parser_skip_to_end_of_parameter (parser
);
3423 specs
= build_null_declspecs ();
3426 declspecs_add_attrs (input_location
, specs
, attrs
);
3429 c_parser_declspecs (parser
, specs
, true, true, true, true,
3430 cla_nonabstract_decl
);
3431 finish_declspecs (specs
);
3432 pending_xref_error ();
3433 prefix_attrs
= specs
->attrs
;
3434 specs
->attrs
= NULL_TREE
;
3435 declarator
= c_parser_declarator (parser
,
3436 specs
->typespec_kind
!= ctsk_none
,
3437 C_DTR_PARM
, &dummy
);
3438 if (declarator
== NULL
)
3440 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3443 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3444 postfix_attrs
= c_parser_attributes (parser
);
3445 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3449 /* Parse a string literal in an asm expression. It should not be
3450 translated, and wide string literals are an error although
3451 permitted by the syntax. This is a GNU extension.
3456 ??? At present, following the old parser, the caller needs to have
3457 set lex_untranslated_string to 1. It would be better to follow the
3458 C++ parser rather than using this kludge. */
3461 c_parser_asm_string_literal (c_parser
*parser
)
3464 int save_flag
= warn_overlength_strings
;
3465 warn_overlength_strings
= 0;
3466 if (c_parser_next_token_is (parser
, CPP_STRING
))
3468 str
= c_parser_peek_token (parser
)->value
;
3469 c_parser_consume_token (parser
);
3471 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3473 error_at (c_parser_peek_token (parser
)->location
,
3474 "wide string literal in %<asm%>");
3475 str
= build_string (1, "");
3476 c_parser_consume_token (parser
);
3480 c_parser_error (parser
, "expected string literal");
3483 warn_overlength_strings
= save_flag
;
3487 /* Parse a simple asm expression. This is used in restricted
3488 contexts, where a full expression with inputs and outputs does not
3489 make sense. This is a GNU extension.
3492 asm ( asm-string-literal )
3496 c_parser_simple_asm_expr (c_parser
*parser
)
3499 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3500 /* ??? Follow the C++ parser rather than using the
3501 lex_untranslated_string kludge. */
3502 parser
->lex_untranslated_string
= true;
3503 c_parser_consume_token (parser
);
3504 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3506 parser
->lex_untranslated_string
= false;
3509 str
= c_parser_asm_string_literal (parser
);
3510 parser
->lex_untranslated_string
= false;
3511 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3513 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3520 c_parser_attribute_any_word (c_parser
*parser
)
3522 tree attr_name
= NULL_TREE
;
3524 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3526 /* ??? See comment above about what keywords are accepted here. */
3528 switch (c_parser_peek_token (parser
)->keyword
)
3559 case RID_TRANSACTION_ATOMIC
:
3560 case RID_TRANSACTION_CANCEL
:
3570 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3571 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3573 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3574 attr_name
= c_parser_peek_token (parser
)->value
;
3579 /* Parse (possibly empty) attributes. This is a GNU extension.
3583 attributes attribute
3586 __attribute__ ( ( attribute-list ) )
3590 attribute_list , attrib
3595 any-word ( identifier )
3596 any-word ( identifier , nonempty-expr-list )
3597 any-word ( expr-list )
3599 where the "identifier" must not be declared as a type, and
3600 "any-word" may be any identifier (including one declared as a
3601 type), a reserved word storage class specifier, type specifier or
3602 type qualifier. ??? This still leaves out most reserved keywords
3603 (following the old parser), shouldn't we include them, and why not
3604 allow identifiers declared as types to start the arguments? */
3607 c_parser_attributes (c_parser
*parser
)
3609 tree attrs
= NULL_TREE
;
3610 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3612 /* ??? Follow the C++ parser rather than using the
3613 lex_untranslated_string kludge. */
3614 parser
->lex_untranslated_string
= true;
3615 c_parser_consume_token (parser
);
3616 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3618 parser
->lex_untranslated_string
= false;
3621 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3623 parser
->lex_untranslated_string
= false;
3624 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3627 /* Parse the attribute list. */
3628 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3629 || c_parser_next_token_is (parser
, CPP_NAME
)
3630 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3632 tree attr
, attr_name
, attr_args
;
3633 vec
<tree
, va_gc
> *expr_list
;
3634 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3636 c_parser_consume_token (parser
);
3640 attr_name
= c_parser_attribute_any_word (parser
);
3641 if (attr_name
== NULL
)
3643 c_parser_consume_token (parser
);
3644 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3646 attr
= build_tree_list (attr_name
, NULL_TREE
);
3647 attrs
= chainon (attrs
, attr
);
3650 c_parser_consume_token (parser
);
3651 /* Parse the attribute contents. If they start with an
3652 identifier which is followed by a comma or close
3653 parenthesis, then the arguments start with that
3654 identifier; otherwise they are an expression list.
3655 In objective-c the identifier may be a classname. */
3656 if (c_parser_next_token_is (parser
, CPP_NAME
)
3657 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3658 || (c_dialect_objc ()
3659 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3660 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3661 || (c_parser_peek_2nd_token (parser
)->type
3662 == CPP_CLOSE_PAREN
)))
3664 tree arg1
= c_parser_peek_token (parser
)->value
;
3665 c_parser_consume_token (parser
);
3666 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3667 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3671 c_parser_consume_token (parser
);
3672 expr_list
= c_parser_expr_list (parser
, false, true,
3674 tree_list
= build_tree_list_vec (expr_list
);
3675 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3676 release_tree_vector (expr_list
);
3681 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3682 attr_args
= NULL_TREE
;
3685 expr_list
= c_parser_expr_list (parser
, false, true,
3687 attr_args
= build_tree_list_vec (expr_list
);
3688 release_tree_vector (expr_list
);
3691 attr
= build_tree_list (attr_name
, attr_args
);
3692 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3693 c_parser_consume_token (parser
);
3696 parser
->lex_untranslated_string
= false;
3697 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3701 attrs
= chainon (attrs
, attr
);
3703 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3704 c_parser_consume_token (parser
);
3707 parser
->lex_untranslated_string
= false;
3708 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3712 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3713 c_parser_consume_token (parser
);
3716 parser
->lex_untranslated_string
= false;
3717 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3721 parser
->lex_untranslated_string
= false;
3726 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3729 specifier-qualifier-list abstract-declarator[opt]
3732 static struct c_type_name
*
3733 c_parser_type_name (c_parser
*parser
)
3735 struct c_declspecs
*specs
= build_null_declspecs ();
3736 struct c_declarator
*declarator
;
3737 struct c_type_name
*ret
;
3739 c_parser_declspecs (parser
, specs
, false, true, true, false,
3741 if (!specs
->declspecs_seen_p
)
3743 c_parser_error (parser
, "expected specifier-qualifier-list");
3746 if (specs
->type
!= error_mark_node
)
3748 pending_xref_error ();
3749 finish_declspecs (specs
);
3751 declarator
= c_parser_declarator (parser
,
3752 specs
->typespec_kind
!= ctsk_none
,
3753 C_DTR_ABSTRACT
, &dummy
);
3754 if (declarator
== NULL
)
3756 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3758 ret
->declarator
= declarator
;
3762 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3765 assignment-expression
3766 { initializer-list }
3767 { initializer-list , }
3770 designation[opt] initializer
3771 initializer-list , designation[opt] initializer
3778 designator-list designator
3785 [ constant-expression ]
3797 [ constant-expression ... constant-expression ]
3799 Any expression without commas is accepted in the syntax for the
3800 constant-expressions, with non-constant expressions rejected later.
3802 This function is only used for top-level initializers; for nested
3803 ones, see c_parser_initval. */
3805 static struct c_expr
3806 c_parser_initializer (c_parser
*parser
)
3808 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3809 return c_parser_braced_init (parser
, NULL_TREE
, false);
3813 location_t loc
= c_parser_peek_token (parser
)->location
;
3814 ret
= c_parser_expr_no_commas (parser
, NULL
);
3815 if (TREE_CODE (ret
.value
) != STRING_CST
3816 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3817 ret
= default_function_array_read_conversion (loc
, ret
);
3822 /* Parse a braced initializer list. TYPE is the type specified for a
3823 compound literal, and NULL_TREE for other initializers and for
3824 nested braced lists. NESTED_P is true for nested braced lists,
3825 false for the list of a compound literal or the list that is the
3826 top-level initializer in a declaration. */
3828 static struct c_expr
3829 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3832 struct obstack braced_init_obstack
;
3833 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3834 gcc_obstack_init (&braced_init_obstack
);
3835 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3836 c_parser_consume_token (parser
);
3838 push_init_level (0, &braced_init_obstack
);
3840 really_start_incremental_init (type
);
3841 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3843 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3847 /* Parse a non-empty initializer list, possibly with a trailing
3851 c_parser_initelt (parser
, &braced_init_obstack
);
3854 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3855 c_parser_consume_token (parser
);
3858 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3862 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3864 ret
.value
= error_mark_node
;
3865 ret
.original_code
= ERROR_MARK
;
3866 ret
.original_type
= NULL
;
3867 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3868 pop_init_level (0, &braced_init_obstack
);
3869 obstack_free (&braced_init_obstack
, NULL
);
3872 c_parser_consume_token (parser
);
3873 ret
= pop_init_level (0, &braced_init_obstack
);
3874 obstack_free (&braced_init_obstack
, NULL
);
3878 /* Parse a nested initializer, including designators. */
3881 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3883 /* Parse any designator or designator list. A single array
3884 designator may have the subsequent "=" omitted in GNU C, but a
3885 longer list or a structure member designator may not. */
3886 if (c_parser_next_token_is (parser
, CPP_NAME
)
3887 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3889 /* Old-style structure member designator. */
3890 set_init_label (c_parser_peek_token (parser
)->value
,
3891 braced_init_obstack
);
3892 /* Use the colon as the error location. */
3893 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3894 "obsolete use of designated initializer with %<:%>");
3895 c_parser_consume_token (parser
);
3896 c_parser_consume_token (parser
);
3900 /* des_seen is 0 if there have been no designators, 1 if there
3901 has been a single array designator and 2 otherwise. */
3903 /* Location of a designator. */
3904 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3905 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3906 || c_parser_next_token_is (parser
, CPP_DOT
))
3908 int des_prev
= des_seen
;
3910 des_loc
= c_parser_peek_token (parser
)->location
;
3913 if (c_parser_next_token_is (parser
, CPP_DOT
))
3916 c_parser_consume_token (parser
);
3917 if (c_parser_next_token_is (parser
, CPP_NAME
))
3919 set_init_label (c_parser_peek_token (parser
)->value
,
3920 braced_init_obstack
);
3921 c_parser_consume_token (parser
);
3926 init
.value
= error_mark_node
;
3927 init
.original_code
= ERROR_MARK
;
3928 init
.original_type
= NULL
;
3929 c_parser_error (parser
, "expected identifier");
3930 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3931 process_init_element (init
, false, braced_init_obstack
);
3938 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3939 /* ??? Following the old parser, [ objc-receiver
3940 objc-message-args ] is accepted as an initializer,
3941 being distinguished from a designator by what follows
3942 the first assignment expression inside the square
3943 brackets, but after a first array designator a
3944 subsequent square bracket is for Objective-C taken to
3945 start an expression, using the obsolete form of
3946 designated initializer without '=', rather than
3947 possibly being a second level of designation: in LALR
3948 terms, the '[' is shifted rather than reducing
3949 designator to designator-list. */
3950 if (des_prev
== 1 && c_dialect_objc ())
3952 des_seen
= des_prev
;
3955 if (des_prev
== 0 && c_dialect_objc ())
3957 /* This might be an array designator or an
3958 Objective-C message expression. If the former,
3959 continue parsing here; if the latter, parse the
3960 remainder of the initializer given the starting
3961 primary-expression. ??? It might make sense to
3962 distinguish when des_prev == 1 as well; see
3963 previous comment. */
3965 struct c_expr mexpr
;
3966 c_parser_consume_token (parser
);
3967 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3968 && ((c_parser_peek_token (parser
)->id_kind
3970 || (c_parser_peek_token (parser
)->id_kind
3971 == C_ID_CLASSNAME
)))
3973 /* Type name receiver. */
3974 tree id
= c_parser_peek_token (parser
)->value
;
3975 c_parser_consume_token (parser
);
3976 rec
= objc_get_class_reference (id
);
3977 goto parse_message_args
;
3979 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3980 mark_exp_read (first
);
3981 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3982 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3983 goto array_desig_after_first
;
3984 /* Expression receiver. So far only one part
3985 without commas has been parsed; there might be
3986 more of the expression. */
3988 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3991 location_t comma_loc
, exp_loc
;
3992 comma_loc
= c_parser_peek_token (parser
)->location
;
3993 c_parser_consume_token (parser
);
3994 exp_loc
= c_parser_peek_token (parser
)->location
;
3995 next
= c_parser_expr_no_commas (parser
, NULL
);
3996 next
= default_function_array_read_conversion (exp_loc
,
3998 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4001 /* Now parse the objc-message-args. */
4002 args
= c_parser_objc_message_args (parser
);
4003 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4006 = objc_build_message_expr (rec
, args
);
4007 mexpr
.original_code
= ERROR_MARK
;
4008 mexpr
.original_type
= NULL
;
4009 /* Now parse and process the remainder of the
4010 initializer, starting with this message
4011 expression as a primary-expression. */
4012 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4015 c_parser_consume_token (parser
);
4016 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4017 mark_exp_read (first
);
4018 array_desig_after_first
:
4019 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4021 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4022 c_parser_consume_token (parser
);
4023 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4024 mark_exp_read (second
);
4028 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4030 c_parser_consume_token (parser
);
4031 set_init_index (first
, second
, braced_init_obstack
);
4033 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4034 "ISO C forbids specifying range of elements to initialize");
4037 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4043 if (c_parser_next_token_is (parser
, CPP_EQ
))
4046 pedwarn (des_loc
, OPT_Wpedantic
,
4047 "ISO C90 forbids specifying subobject to initialize");
4048 c_parser_consume_token (parser
);
4053 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4054 "obsolete use of designated initializer without %<=%>");
4058 init
.value
= error_mark_node
;
4059 init
.original_code
= ERROR_MARK
;
4060 init
.original_type
= NULL
;
4061 c_parser_error (parser
, "expected %<=%>");
4062 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4063 process_init_element (init
, false, braced_init_obstack
);
4069 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4072 /* Parse a nested initializer; as c_parser_initializer but parses
4073 initializers within braced lists, after any designators have been
4074 applied. If AFTER is not NULL then it is an Objective-C message
4075 expression which is the primary-expression starting the
4079 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4080 struct obstack
* braced_init_obstack
)
4083 gcc_assert (!after
|| c_dialect_objc ());
4084 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4085 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4088 location_t loc
= c_parser_peek_token (parser
)->location
;
4089 init
= c_parser_expr_no_commas (parser
, after
);
4090 if (init
.value
!= NULL_TREE
4091 && TREE_CODE (init
.value
) != STRING_CST
4092 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4093 init
= default_function_array_read_conversion (loc
, init
);
4095 process_init_element (init
, false, braced_init_obstack
);
4098 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4102 { block-item-list[opt] }
4103 { label-declarations block-item-list }
4107 block-item-list block-item
4119 { label-declarations block-item-list }
4122 __extension__ nested-declaration
4123 nested-function-definition
4127 label-declarations label-declaration
4130 __label__ identifier-list ;
4132 Allowing the mixing of declarations and code is new in C99. The
4133 GNU syntax also permits (not shown above) labels at the end of
4134 compound statements, which yield an error. We don't allow labels
4135 on declarations; this might seem like a natural extension, but
4136 there would be a conflict between attributes on the label and
4137 prefix attributes on the declaration. ??? The syntax follows the
4138 old parser in requiring something after label declarations.
4139 Although they are erroneous if the labels declared aren't defined,
4140 is it useful for the syntax to be this way?
4153 cancellation-point-directive */
4156 c_parser_compound_statement (c_parser
*parser
)
4159 location_t brace_loc
;
4160 brace_loc
= c_parser_peek_token (parser
)->location
;
4161 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4163 /* Ensure a scope is entered and left anyway to avoid confusion
4164 if we have just prepared to enter a function body. */
4165 stmt
= c_begin_compound_stmt (true);
4166 c_end_compound_stmt (brace_loc
, stmt
, true);
4167 return error_mark_node
;
4169 stmt
= c_begin_compound_stmt (true);
4170 c_parser_compound_statement_nostart (parser
);
4172 /* If the compound stmt contains array notations, then we expand them. */
4173 if (flag_enable_cilkplus
&& contains_array_notation_expr (stmt
))
4174 stmt
= expand_array_notation_exprs (stmt
);
4175 return c_end_compound_stmt (brace_loc
, stmt
, true);
4178 /* Parse a compound statement except for the opening brace. This is
4179 used for parsing both compound statements and statement expressions
4180 (which follow different paths to handling the opening). */
4183 c_parser_compound_statement_nostart (c_parser
*parser
)
4185 bool last_stmt
= false;
4186 bool last_label
= false;
4187 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4188 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4189 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4191 c_parser_consume_token (parser
);
4194 mark_valid_location_for_stdc_pragma (true);
4195 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4197 /* Read zero or more forward-declarations for labels that nested
4198 functions can jump to. */
4199 mark_valid_location_for_stdc_pragma (false);
4200 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4202 label_loc
= c_parser_peek_token (parser
)->location
;
4203 c_parser_consume_token (parser
);
4204 /* Any identifiers, including those declared as type names,
4209 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4211 c_parser_error (parser
, "expected identifier");
4215 = declare_label (c_parser_peek_token (parser
)->value
);
4216 C_DECLARED_LABEL_FLAG (label
) = 1;
4217 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4218 c_parser_consume_token (parser
);
4219 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4220 c_parser_consume_token (parser
);
4224 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4226 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4228 /* We must now have at least one statement, label or declaration. */
4229 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4231 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4232 c_parser_error (parser
, "expected declaration or statement");
4233 c_parser_consume_token (parser
);
4236 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4238 location_t loc
= c_parser_peek_token (parser
)->location
;
4239 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4240 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4241 || (c_parser_next_token_is (parser
, CPP_NAME
)
4242 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4244 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4245 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4247 label_loc
= c_parser_peek_token (parser
)->location
;
4250 mark_valid_location_for_stdc_pragma (false);
4251 c_parser_label (parser
);
4253 else if (!last_label
4254 && c_parser_next_tokens_start_declaration (parser
))
4257 mark_valid_location_for_stdc_pragma (false);
4258 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4262 (pedantic
&& !flag_isoc99
)
4264 : OPT_Wdeclaration_after_statement
,
4265 "ISO C90 forbids mixed declarations and code");
4268 else if (!last_label
4269 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4271 /* __extension__ can start a declaration, but is also an
4272 unary operator that can start an expression. Consume all
4273 but the last of a possible series of __extension__ to
4275 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4276 && (c_parser_peek_2nd_token (parser
)->keyword
4278 c_parser_consume_token (parser
);
4279 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4282 ext
= disable_extension_diagnostics ();
4283 c_parser_consume_token (parser
);
4285 mark_valid_location_for_stdc_pragma (false);
4286 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4288 /* Following the old parser, __extension__ does not
4289 disable this diagnostic. */
4290 restore_extension_diagnostics (ext
);
4292 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4294 : OPT_Wdeclaration_after_statement
,
4295 "ISO C90 forbids mixed declarations and code");
4301 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4303 /* External pragmas, and some omp pragmas, are not associated
4304 with regular c code, and so are not to be considered statements
4305 syntactically. This ensures that the user doesn't put them
4306 places that would turn into syntax errors if the directive
4308 if (c_parser_pragma (parser
, pragma_compound
))
4309 last_label
= false, last_stmt
= true;
4311 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4313 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4314 c_parser_error (parser
, "expected declaration or statement");
4317 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4319 if (parser
->in_if_block
)
4321 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4322 error_at (loc
, """expected %<}%> before %<else%>");
4327 error_at (loc
, "%<else%> without a previous %<if%>");
4328 c_parser_consume_token (parser
);
4337 mark_valid_location_for_stdc_pragma (false);
4338 c_parser_statement_after_labels (parser
);
4341 parser
->error
= false;
4344 error_at (label_loc
, "label at end of compound statement");
4345 c_parser_consume_token (parser
);
4346 /* Restore the value we started with. */
4347 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4350 /* Parse a label (C90 6.6.1, C99 6.8.1).
4353 identifier : attributes[opt]
4354 case constant-expression :
4360 case constant-expression ... constant-expression :
4362 The use of attributes on labels is a GNU extension. The syntax in
4363 GNU C accepts any expressions without commas, non-constant
4364 expressions being rejected later. */
4367 c_parser_label (c_parser
*parser
)
4369 location_t loc1
= c_parser_peek_token (parser
)->location
;
4370 tree label
= NULL_TREE
;
4371 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4374 c_parser_consume_token (parser
);
4375 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4376 if (c_parser_next_token_is (parser
, CPP_COLON
))
4378 c_parser_consume_token (parser
);
4379 label
= do_case (loc1
, exp1
, NULL_TREE
);
4381 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4383 c_parser_consume_token (parser
);
4384 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4385 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4386 label
= do_case (loc1
, exp1
, exp2
);
4389 c_parser_error (parser
, "expected %<:%> or %<...%>");
4391 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4393 c_parser_consume_token (parser
);
4394 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4395 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4399 tree name
= c_parser_peek_token (parser
)->value
;
4402 location_t loc2
= c_parser_peek_token (parser
)->location
;
4403 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4404 c_parser_consume_token (parser
);
4405 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4406 c_parser_consume_token (parser
);
4407 attrs
= c_parser_attributes (parser
);
4408 tlab
= define_label (loc2
, name
);
4411 decl_attributes (&tlab
, attrs
, 0);
4412 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4417 if (c_parser_next_tokens_start_declaration (parser
))
4419 error_at (c_parser_peek_token (parser
)->location
,
4420 "a label can only be part of a statement and "
4421 "a declaration is not a statement");
4422 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4423 /*static_assert_ok*/ true,
4424 /*empty_ok*/ true, /*nested*/ true,
4425 /*start_attr_ok*/ true, NULL
,
4431 /* Parse a statement (C90 6.6, C99 6.8).
4436 expression-statement
4444 expression-statement:
4447 selection-statement:
4451 iteration-statement:
4460 return expression[opt] ;
4473 objc-throw-statement
4474 objc-try-catch-statement
4475 objc-synchronized-statement
4477 objc-throw-statement:
4493 parallel-for-construct
4494 parallel-for-simd-construct
4495 parallel-sections-construct
4502 parallel-directive structured-block
4505 for-directive iteration-statement
4508 simd-directive iteration-statements
4511 for-simd-directive iteration-statements
4514 sections-directive section-scope
4517 single-directive structured-block
4519 parallel-for-construct:
4520 parallel-for-directive iteration-statement
4522 parallel-for-simd-construct:
4523 parallel-for-simd-directive iteration-statement
4525 parallel-sections-construct:
4526 parallel-sections-directive section-scope
4529 master-directive structured-block
4532 critical-directive structured-block
4535 atomic-directive expression-statement
4538 ordered-directive structured-block
4540 Transactional Memory:
4543 transaction-statement
4544 transaction-cancel-statement
4548 c_parser_statement (c_parser
*parser
)
4550 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4551 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4552 || (c_parser_next_token_is (parser
, CPP_NAME
)
4553 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4554 c_parser_label (parser
);
4555 c_parser_statement_after_labels (parser
);
4558 /* Parse a statement, other than a labeled statement. */
4561 c_parser_statement_after_labels (c_parser
*parser
)
4563 location_t loc
= c_parser_peek_token (parser
)->location
;
4564 tree stmt
= NULL_TREE
;
4565 bool in_if_block
= parser
->in_if_block
;
4566 parser
->in_if_block
= false;
4567 switch (c_parser_peek_token (parser
)->type
)
4569 case CPP_OPEN_BRACE
:
4570 add_stmt (c_parser_compound_statement (parser
));
4573 switch (c_parser_peek_token (parser
)->keyword
)
4576 c_parser_if_statement (parser
);
4579 c_parser_switch_statement (parser
);
4582 c_parser_while_statement (parser
);
4585 c_parser_do_statement (parser
);
4588 c_parser_for_statement (parser
, false);
4591 c_parser_consume_token (parser
);
4592 if (c_parser_next_token_is (parser
, CPP_NAME
))
4594 stmt
= c_finish_goto_label (loc
,
4595 c_parser_peek_token (parser
)->value
);
4596 c_parser_consume_token (parser
);
4598 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4602 c_parser_consume_token (parser
);
4603 val
= c_parser_expression (parser
).value
;
4604 mark_exp_read (val
);
4605 stmt
= c_finish_goto_ptr (loc
, val
);
4608 c_parser_error (parser
, "expected identifier or %<*%>");
4609 goto expect_semicolon
;
4611 c_parser_consume_token (parser
);
4612 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4613 goto expect_semicolon
;
4615 c_parser_consume_token (parser
);
4616 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4617 goto expect_semicolon
;
4619 c_parser_consume_token (parser
);
4620 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4622 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4623 c_parser_consume_token (parser
);
4627 struct c_expr expr
= c_parser_expression_conv (parser
);
4628 mark_exp_read (expr
.value
);
4629 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4630 goto expect_semicolon
;
4634 stmt
= c_parser_asm_statement (parser
);
4636 case RID_TRANSACTION_ATOMIC
:
4637 case RID_TRANSACTION_RELAXED
:
4638 stmt
= c_parser_transaction (parser
,
4639 c_parser_peek_token (parser
)->keyword
);
4641 case RID_TRANSACTION_CANCEL
:
4642 stmt
= c_parser_transaction_cancel (parser
);
4643 goto expect_semicolon
;
4645 gcc_assert (c_dialect_objc ());
4646 c_parser_consume_token (parser
);
4647 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4649 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4650 c_parser_consume_token (parser
);
4654 tree expr
= c_parser_expression (parser
).value
;
4655 expr
= c_fully_fold (expr
, false, NULL
);
4656 stmt
= objc_build_throw_stmt (loc
, expr
);
4657 goto expect_semicolon
;
4661 gcc_assert (c_dialect_objc ());
4662 c_parser_objc_try_catch_finally_statement (parser
);
4664 case RID_AT_SYNCHRONIZED
:
4665 gcc_assert (c_dialect_objc ());
4666 c_parser_objc_synchronized_statement (parser
);
4673 c_parser_consume_token (parser
);
4675 case CPP_CLOSE_PAREN
:
4676 case CPP_CLOSE_SQUARE
:
4677 /* Avoid infinite loop in error recovery:
4678 c_parser_skip_until_found stops at a closing nesting
4679 delimiter without consuming it, but here we need to consume
4680 it to proceed further. */
4681 c_parser_error (parser
, "expected statement");
4682 c_parser_consume_token (parser
);
4685 c_parser_pragma (parser
, pragma_stmt
);
4689 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4691 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4694 /* Two cases cannot and do not have line numbers associated: If stmt
4695 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4696 cannot hold line numbers. But that's OK because the statement
4697 will either be changed to a MODIFY_EXPR during gimplification of
4698 the statement expr, or discarded. If stmt was compound, but
4699 without new variables, we will have skipped the creation of a
4700 BIND and will have a bare STATEMENT_LIST. But that's OK because
4701 (recursively) all of the component statements should already have
4702 line numbers assigned. ??? Can we discard no-op statements
4704 if (CAN_HAVE_LOCATION_P (stmt
)
4705 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4706 SET_EXPR_LOCATION (stmt
, loc
);
4708 parser
->in_if_block
= in_if_block
;
4711 /* Parse the condition from an if, do, while or for statements. */
4714 c_parser_condition (c_parser
*parser
)
4716 location_t loc
= c_parser_peek_token (parser
)->location
;
4718 cond
= c_parser_expression_conv (parser
).value
;
4719 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4720 cond
= c_fully_fold (cond
, false, NULL
);
4721 if (warn_sequence_point
)
4722 verify_sequence_points (cond
);
4726 /* Parse a parenthesized condition from an if, do or while statement.
4732 c_parser_paren_condition (c_parser
*parser
)
4735 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4736 return error_mark_node
;
4737 cond
= c_parser_condition (parser
);
4738 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4742 /* Parse a statement which is a block in C99. */
4745 c_parser_c99_block_statement (c_parser
*parser
)
4747 tree block
= c_begin_compound_stmt (flag_isoc99
);
4748 location_t loc
= c_parser_peek_token (parser
)->location
;
4749 c_parser_statement (parser
);
4750 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4753 /* Parse the body of an if statement. This is just parsing a
4754 statement but (a) it is a block in C99, (b) we track whether the
4755 body is an if statement for the sake of -Wparentheses warnings, (c)
4756 we handle an empty body specially for the sake of -Wempty-body
4757 warnings, and (d) we call parser_compound_statement directly
4758 because c_parser_statement_after_labels resets
4759 parser->in_if_block. */
4762 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4764 tree block
= c_begin_compound_stmt (flag_isoc99
);
4765 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4766 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4767 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4768 || (c_parser_next_token_is (parser
, CPP_NAME
)
4769 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4770 c_parser_label (parser
);
4771 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4772 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4774 location_t loc
= c_parser_peek_token (parser
)->location
;
4775 add_stmt (build_empty_stmt (loc
));
4776 c_parser_consume_token (parser
);
4777 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4778 warning_at (loc
, OPT_Wempty_body
,
4779 "suggest braces around empty body in an %<if%> statement");
4781 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4782 add_stmt (c_parser_compound_statement (parser
));
4784 c_parser_statement_after_labels (parser
);
4785 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4788 /* Parse the else body of an if statement. This is just parsing a
4789 statement but (a) it is a block in C99, (b) we handle an empty body
4790 specially for the sake of -Wempty-body warnings. */
4793 c_parser_else_body (c_parser
*parser
)
4795 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4796 tree block
= c_begin_compound_stmt (flag_isoc99
);
4797 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4798 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4799 || (c_parser_next_token_is (parser
, CPP_NAME
)
4800 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4801 c_parser_label (parser
);
4802 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4804 location_t loc
= c_parser_peek_token (parser
)->location
;
4807 "suggest braces around empty body in an %<else%> statement");
4808 add_stmt (build_empty_stmt (loc
));
4809 c_parser_consume_token (parser
);
4812 c_parser_statement_after_labels (parser
);
4813 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4816 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4819 if ( expression ) statement
4820 if ( expression ) statement else statement
4824 c_parser_if_statement (c_parser
*parser
)
4829 bool first_if
= false;
4830 tree first_body
, second_body
;
4834 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4835 c_parser_consume_token (parser
);
4836 block
= c_begin_compound_stmt (flag_isoc99
);
4837 loc
= c_parser_peek_token (parser
)->location
;
4838 cond
= c_parser_paren_condition (parser
);
4839 in_if_block
= parser
->in_if_block
;
4840 parser
->in_if_block
= true;
4841 first_body
= c_parser_if_body (parser
, &first_if
);
4842 parser
->in_if_block
= in_if_block
;
4843 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4845 c_parser_consume_token (parser
);
4846 second_body
= c_parser_else_body (parser
);
4849 second_body
= NULL_TREE
;
4850 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4851 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
4853 /* If the if statement contains array notations, then we expand them. */
4854 if (flag_enable_cilkplus
&& contains_array_notation_expr (if_stmt
))
4855 if_stmt
= fix_conditional_array_notations (if_stmt
);
4859 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4862 switch (expression) statement
4866 c_parser_switch_statement (c_parser
*parser
)
4868 tree block
, expr
, body
, save_break
;
4869 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4870 location_t switch_cond_loc
;
4871 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4872 c_parser_consume_token (parser
);
4873 block
= c_begin_compound_stmt (flag_isoc99
);
4874 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4876 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4877 expr
= c_parser_expression (parser
).value
;
4878 if (flag_enable_cilkplus
&& contains_array_notation_expr (expr
))
4880 error_at (switch_cond_loc
,
4881 "array notations cannot be used as a condition for switch "
4883 expr
= error_mark_node
;
4885 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4889 switch_cond_loc
= UNKNOWN_LOCATION
;
4890 expr
= error_mark_node
;
4892 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4893 save_break
= c_break_label
;
4894 c_break_label
= NULL_TREE
;
4895 body
= c_parser_c99_block_statement (parser
);
4896 c_finish_case (body
);
4899 location_t here
= c_parser_peek_token (parser
)->location
;
4900 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4901 SET_EXPR_LOCATION (t
, here
);
4904 c_break_label
= save_break
;
4905 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4908 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4911 while (expression) statement
4915 c_parser_while_statement (c_parser
*parser
)
4917 tree block
, cond
, body
, save_break
, save_cont
;
4919 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4920 c_parser_consume_token (parser
);
4921 block
= c_begin_compound_stmt (flag_isoc99
);
4922 loc
= c_parser_peek_token (parser
)->location
;
4923 cond
= c_parser_paren_condition (parser
);
4924 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4926 error_at (loc
, "array notations cannot be used as a condition for while "
4928 cond
= error_mark_node
;
4930 save_break
= c_break_label
;
4931 c_break_label
= NULL_TREE
;
4932 save_cont
= c_cont_label
;
4933 c_cont_label
= NULL_TREE
;
4934 body
= c_parser_c99_block_statement (parser
);
4935 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4936 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4937 c_break_label
= save_break
;
4938 c_cont_label
= save_cont
;
4941 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4944 do statement while ( expression ) ;
4948 c_parser_do_statement (c_parser
*parser
)
4950 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4952 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4953 c_parser_consume_token (parser
);
4954 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4955 warning_at (c_parser_peek_token (parser
)->location
,
4957 "suggest braces around empty body in %<do%> statement");
4958 block
= c_begin_compound_stmt (flag_isoc99
);
4959 loc
= c_parser_peek_token (parser
)->location
;
4960 save_break
= c_break_label
;
4961 c_break_label
= NULL_TREE
;
4962 save_cont
= c_cont_label
;
4963 c_cont_label
= NULL_TREE
;
4964 body
= c_parser_c99_block_statement (parser
);
4965 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4966 new_break
= c_break_label
;
4967 c_break_label
= save_break
;
4968 new_cont
= c_cont_label
;
4969 c_cont_label
= save_cont
;
4970 cond
= c_parser_paren_condition (parser
);
4971 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4973 error_at (loc
, "array notations cannot be used as a condition for a "
4974 "do-while statement");
4975 cond
= error_mark_node
;
4978 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4979 c_parser_skip_to_end_of_block_or_statement (parser
);
4980 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4981 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4984 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4987 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4988 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4990 The form with a declaration is new in C99.
4992 ??? In accordance with the old parser, the declaration may be a
4993 nested function, which is then rejected in check_for_loop_decls,
4994 but does it make any sense for this to be included in the grammar?
4995 Note in particular that the nested function does not include a
4996 trailing ';', whereas the "declaration" production includes one.
4997 Also, can we reject bad declarations earlier and cheaper than
4998 check_for_loop_decls?
5000 In Objective-C, there are two additional variants:
5003 for ( expression in expresssion ) statement
5004 for ( declaration in expression ) statement
5006 This is inconsistent with C, because the second variant is allowed
5007 even if c99 is not enabled.
5009 The rest of the comment documents these Objective-C foreach-statement.
5011 Here is the canonical example of the first variant:
5012 for (object in array) { do something with object }
5013 we call the first expression ("object") the "object_expression" and
5014 the second expression ("array") the "collection_expression".
5015 object_expression must be an lvalue of type "id" (a generic Objective-C
5016 object) because the loop works by assigning to object_expression the
5017 various objects from the collection_expression. collection_expression
5018 must evaluate to something of type "id" which responds to the method
5019 countByEnumeratingWithState:objects:count:.
5021 The canonical example of the second variant is:
5022 for (id object in array) { do something with object }
5023 which is completely equivalent to
5026 for (object in array) { do something with object }
5028 Note that initizializing 'object' in some way (eg, "for ((object =
5029 xxx) in array) { do something with object }") is possibly
5030 technically valid, but completely pointless as 'object' will be
5031 assigned to something else as soon as the loop starts. We should
5032 most likely reject it (TODO).
5034 The beginning of the Objective-C foreach-statement looks exactly
5035 like the beginning of the for-statement, and we can tell it is a
5036 foreach-statement only because the initial declaration or
5037 expression is terminated by 'in' instead of ';'.
5041 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5043 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5044 /* The following are only used when parsing an ObjC foreach statement. */
5045 tree object_expression
;
5046 /* Silence the bogus uninitialized warning. */
5047 tree collection_expression
= NULL
;
5048 location_t loc
= c_parser_peek_token (parser
)->location
;
5049 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5050 bool is_foreach_statement
= false;
5051 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5052 c_parser_consume_token (parser
);
5053 /* Open a compound statement in Objective-C as well, just in case this is
5054 as foreach expression. */
5055 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5056 cond
= error_mark_node
;
5057 incr
= error_mark_node
;
5058 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5060 /* Parse the initialization declaration or expression. */
5061 object_expression
= error_mark_node
;
5062 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5063 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5065 parser
->objc_could_be_foreach_context
= false;
5066 c_parser_consume_token (parser
);
5067 c_finish_expr_stmt (loc
, NULL_TREE
);
5069 else if (c_parser_next_tokens_start_declaration (parser
))
5071 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5072 &object_expression
, vNULL
);
5073 parser
->objc_could_be_foreach_context
= false;
5075 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5077 c_parser_consume_token (parser
);
5078 is_foreach_statement
= true;
5079 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5080 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5083 check_for_loop_decls (for_loc
, flag_isoc99
);
5085 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5087 /* __extension__ can start a declaration, but is also an
5088 unary operator that can start an expression. Consume all
5089 but the last of a possible series of __extension__ to
5091 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5092 && (c_parser_peek_2nd_token (parser
)->keyword
5094 c_parser_consume_token (parser
);
5095 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5098 ext
= disable_extension_diagnostics ();
5099 c_parser_consume_token (parser
);
5100 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5101 true, &object_expression
, vNULL
);
5102 parser
->objc_could_be_foreach_context
= false;
5104 restore_extension_diagnostics (ext
);
5105 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5107 c_parser_consume_token (parser
);
5108 is_foreach_statement
= true;
5109 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5110 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5113 check_for_loop_decls (for_loc
, flag_isoc99
);
5122 tree init_expression
;
5123 init_expression
= c_parser_expression (parser
).value
;
5124 parser
->objc_could_be_foreach_context
= false;
5125 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5127 c_parser_consume_token (parser
);
5128 is_foreach_statement
= true;
5129 if (! lvalue_p (init_expression
))
5130 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5131 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5135 c_finish_expr_stmt (loc
, init_expression
);
5136 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5140 /* Parse the loop condition. In the case of a foreach
5141 statement, there is no loop condition. */
5142 gcc_assert (!parser
->objc_could_be_foreach_context
);
5143 if (!is_foreach_statement
)
5145 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5149 c_parser_error (parser
, "missing loop condition in loop with "
5150 "%<GCC ivdep%> pragma");
5151 cond
= error_mark_node
;
5155 c_parser_consume_token (parser
);
5161 cond
= c_parser_condition (parser
);
5162 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5164 error_at (loc
, "array notations cannot be used in a "
5165 "condition for a for-loop");
5166 cond
= error_mark_node
;
5168 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5171 if (ivdep
&& cond
!= error_mark_node
)
5172 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5173 build_int_cst (integer_type_node
,
5174 annot_expr_ivdep_kind
));
5176 /* Parse the increment expression (the third expression in a
5177 for-statement). In the case of a foreach-statement, this is
5178 the expression that follows the 'in'. */
5179 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5181 if (is_foreach_statement
)
5183 c_parser_error (parser
, "missing collection in fast enumeration");
5184 collection_expression
= error_mark_node
;
5187 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5191 if (is_foreach_statement
)
5192 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5195 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5197 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5199 save_break
= c_break_label
;
5200 c_break_label
= NULL_TREE
;
5201 save_cont
= c_cont_label
;
5202 c_cont_label
= NULL_TREE
;
5203 body
= c_parser_c99_block_statement (parser
);
5204 if (is_foreach_statement
)
5205 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5207 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5208 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5209 c_break_label
= save_break
;
5210 c_cont_label
= save_cont
;
5213 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5214 statement with inputs, outputs, clobbers, and volatile tag
5218 asm type-qualifier[opt] ( asm-argument ) ;
5219 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5223 asm-string-literal : asm-operands[opt]
5224 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5225 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5228 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5231 Qualifiers other than volatile are accepted in the syntax but
5235 c_parser_asm_statement (c_parser
*parser
)
5237 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5238 bool simple
, is_goto
;
5239 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5240 int section
, nsections
;
5242 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5243 c_parser_consume_token (parser
);
5244 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5246 quals
= c_parser_peek_token (parser
)->value
;
5247 c_parser_consume_token (parser
);
5249 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5250 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5252 warning_at (c_parser_peek_token (parser
)->location
,
5254 "%E qualifier ignored on asm",
5255 c_parser_peek_token (parser
)->value
);
5257 c_parser_consume_token (parser
);
5263 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5265 c_parser_consume_token (parser
);
5269 /* ??? Follow the C++ parser rather than using the
5270 lex_untranslated_string kludge. */
5271 parser
->lex_untranslated_string
= true;
5274 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5277 str
= c_parser_asm_string_literal (parser
);
5278 if (str
== NULL_TREE
)
5279 goto error_close_paren
;
5282 outputs
= NULL_TREE
;
5284 clobbers
= NULL_TREE
;
5287 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5290 /* Parse each colon-delimited section of operands. */
5291 nsections
= 3 + is_goto
;
5292 for (section
= 0; section
< nsections
; ++section
)
5294 if (!c_parser_require (parser
, CPP_COLON
,
5297 : "expected %<:%> or %<)%>"))
5298 goto error_close_paren
;
5300 /* Once past any colon, we're no longer a simple asm. */
5303 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5304 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5309 /* For asm goto, we don't allow output operands, but reserve
5310 the slot for a future extension that does allow them. */
5312 outputs
= c_parser_asm_operands (parser
);
5315 inputs
= c_parser_asm_operands (parser
);
5318 clobbers
= c_parser_asm_clobbers (parser
);
5321 labels
= c_parser_asm_goto_operands (parser
);
5327 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5332 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5334 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5338 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5339 c_parser_skip_to_end_of_block_or_statement (parser
);
5341 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5342 clobbers
, labels
, simple
));
5345 parser
->lex_untranslated_string
= false;
5349 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5353 /* Parse asm operands, a GNU extension.
5357 asm-operands , asm-operand
5360 asm-string-literal ( expression )
5361 [ identifier ] asm-string-literal ( expression )
5365 c_parser_asm_operands (c_parser
*parser
)
5367 tree list
= NULL_TREE
;
5372 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5374 c_parser_consume_token (parser
);
5375 if (c_parser_next_token_is (parser
, CPP_NAME
))
5377 tree id
= c_parser_peek_token (parser
)->value
;
5378 c_parser_consume_token (parser
);
5379 name
= build_string (IDENTIFIER_LENGTH (id
),
5380 IDENTIFIER_POINTER (id
));
5384 c_parser_error (parser
, "expected identifier");
5385 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5388 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5393 str
= c_parser_asm_string_literal (parser
);
5394 if (str
== NULL_TREE
)
5396 parser
->lex_untranslated_string
= false;
5397 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5399 parser
->lex_untranslated_string
= true;
5402 expr
= c_parser_expression (parser
);
5403 mark_exp_read (expr
.value
);
5404 parser
->lex_untranslated_string
= true;
5405 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5407 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5410 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5412 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5413 c_parser_consume_token (parser
);
5420 /* Parse asm clobbers, a GNU extension.
5424 asm-clobbers , asm-string-literal
5428 c_parser_asm_clobbers (c_parser
*parser
)
5430 tree list
= NULL_TREE
;
5433 tree str
= c_parser_asm_string_literal (parser
);
5435 list
= tree_cons (NULL_TREE
, str
, list
);
5438 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5439 c_parser_consume_token (parser
);
5446 /* Parse asm goto labels, a GNU extension.
5450 asm-goto-operands , identifier
5454 c_parser_asm_goto_operands (c_parser
*parser
)
5456 tree list
= NULL_TREE
;
5461 if (c_parser_next_token_is (parser
, CPP_NAME
))
5463 c_token
*tok
= c_parser_peek_token (parser
);
5465 label
= lookup_label_for_goto (tok
->location
, name
);
5466 c_parser_consume_token (parser
);
5467 TREE_USED (label
) = 1;
5471 c_parser_error (parser
, "expected identifier");
5475 name
= build_string (IDENTIFIER_LENGTH (name
),
5476 IDENTIFIER_POINTER (name
));
5477 list
= tree_cons (name
, label
, list
);
5478 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5479 c_parser_consume_token (parser
);
5481 return nreverse (list
);
5485 /* Parse an expression other than a compound expression; that is, an
5486 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5487 NULL then it is an Objective-C message expression which is the
5488 primary-expression starting the expression as an initializer.
5490 assignment-expression:
5491 conditional-expression
5492 unary-expression assignment-operator assignment-expression
5494 assignment-operator: one of
5495 = *= /= %= += -= <<= >>= &= ^= |=
5497 In GNU C we accept any conditional expression on the LHS and
5498 diagnose the invalid lvalue rather than producing a syntax
5501 static struct c_expr
5502 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5503 tree omp_atomic_lhs
)
5505 struct c_expr lhs
, rhs
, ret
;
5506 enum tree_code code
;
5507 location_t op_location
, exp_location
;
5508 gcc_assert (!after
|| c_dialect_objc ());
5509 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5510 op_location
= c_parser_peek_token (parser
)->location
;
5511 switch (c_parser_peek_token (parser
)->type
)
5520 code
= TRUNC_DIV_EXPR
;
5523 code
= TRUNC_MOD_EXPR
;
5538 code
= BIT_AND_EXPR
;
5541 code
= BIT_XOR_EXPR
;
5544 code
= BIT_IOR_EXPR
;
5549 c_parser_consume_token (parser
);
5550 exp_location
= c_parser_peek_token (parser
)->location
;
5551 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5552 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5554 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5555 code
, exp_location
, rhs
.value
,
5557 if (code
== NOP_EXPR
)
5558 ret
.original_code
= MODIFY_EXPR
;
5561 TREE_NO_WARNING (ret
.value
) = 1;
5562 ret
.original_code
= ERROR_MARK
;
5564 ret
.original_type
= NULL
;
5568 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5569 is not NULL then it is an Objective-C message expression which is
5570 the primary-expression starting the expression as an initializer.
5572 conditional-expression:
5573 logical-OR-expression
5574 logical-OR-expression ? expression : conditional-expression
5578 conditional-expression:
5579 logical-OR-expression ? : conditional-expression
5582 static struct c_expr
5583 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5584 tree omp_atomic_lhs
)
5586 struct c_expr cond
, exp1
, exp2
, ret
;
5587 location_t cond_loc
, colon_loc
, middle_loc
;
5589 gcc_assert (!after
|| c_dialect_objc ());
5591 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5593 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5595 cond_loc
= c_parser_peek_token (parser
)->location
;
5596 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5597 c_parser_consume_token (parser
);
5598 if (c_parser_next_token_is (parser
, CPP_COLON
))
5600 tree eptype
= NULL_TREE
;
5602 middle_loc
= c_parser_peek_token (parser
)->location
;
5603 pedwarn (middle_loc
, OPT_Wpedantic
,
5604 "ISO C forbids omitting the middle term of a ?: expression");
5605 warn_for_omitted_condop (middle_loc
, cond
.value
);
5606 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5608 eptype
= TREE_TYPE (cond
.value
);
5609 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5611 /* Make sure first operand is calculated only once. */
5612 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5614 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5615 exp1
.original_type
= NULL
;
5616 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5617 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5622 = c_objc_common_truthvalue_conversion
5623 (cond_loc
, default_conversion (cond
.value
));
5624 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5625 exp1
= c_parser_expression_conv (parser
);
5626 mark_exp_read (exp1
.value
);
5627 c_inhibit_evaluation_warnings
+=
5628 ((cond
.value
== truthvalue_true_node
)
5629 - (cond
.value
== truthvalue_false_node
));
5632 colon_loc
= c_parser_peek_token (parser
)->location
;
5633 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5635 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5636 ret
.value
= error_mark_node
;
5637 ret
.original_code
= ERROR_MARK
;
5638 ret
.original_type
= NULL
;
5642 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5643 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5644 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5646 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5647 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5648 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5649 exp1
.value
, exp1
.original_type
,
5650 exp2
.value
, exp2
.original_type
);
5651 ret
.original_code
= ERROR_MARK
;
5652 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5653 ret
.original_type
= NULL
;
5658 /* If both sides are enum type, the default conversion will have
5659 made the type of the result be an integer type. We want to
5660 remember the enum types we started with. */
5661 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5662 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5663 ret
.original_type
= ((t1
!= error_mark_node
5664 && t2
!= error_mark_node
5665 && (TYPE_MAIN_VARIANT (t1
)
5666 == TYPE_MAIN_VARIANT (t2
)))
5673 /* Parse a binary expression; that is, a logical-OR-expression (C90
5674 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5675 an Objective-C message expression which is the primary-expression
5676 starting the expression as an initializer.
5678 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
5679 when it should be the unfolded lhs. In a valid OpenMP source,
5680 one of the operands of the toplevel binary expression must be equal
5681 to it. In that case, just return a build2 created binary operation
5682 rather than result of parser_build_binary_op.
5684 multiplicative-expression:
5686 multiplicative-expression * cast-expression
5687 multiplicative-expression / cast-expression
5688 multiplicative-expression % cast-expression
5690 additive-expression:
5691 multiplicative-expression
5692 additive-expression + multiplicative-expression
5693 additive-expression - multiplicative-expression
5697 shift-expression << additive-expression
5698 shift-expression >> additive-expression
5700 relational-expression:
5702 relational-expression < shift-expression
5703 relational-expression > shift-expression
5704 relational-expression <= shift-expression
5705 relational-expression >= shift-expression
5707 equality-expression:
5708 relational-expression
5709 equality-expression == relational-expression
5710 equality-expression != relational-expression
5714 AND-expression & equality-expression
5716 exclusive-OR-expression:
5718 exclusive-OR-expression ^ AND-expression
5720 inclusive-OR-expression:
5721 exclusive-OR-expression
5722 inclusive-OR-expression | exclusive-OR-expression
5724 logical-AND-expression:
5725 inclusive-OR-expression
5726 logical-AND-expression && inclusive-OR-expression
5728 logical-OR-expression:
5729 logical-AND-expression
5730 logical-OR-expression || logical-AND-expression
5733 static struct c_expr
5734 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5735 tree omp_atomic_lhs
)
5737 /* A binary expression is parsed using operator-precedence parsing,
5738 with the operands being cast expressions. All the binary
5739 operators are left-associative. Thus a binary expression is of
5742 E0 op1 E1 op2 E2 ...
5744 which we represent on a stack. On the stack, the precedence
5745 levels are strictly increasing. When a new operator is
5746 encountered of higher precedence than that at the top of the
5747 stack, it is pushed; its LHS is the top expression, and its RHS
5748 is everything parsed until it is popped. When a new operator is
5749 encountered with precedence less than or equal to that at the top
5750 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5751 by the result of the operation until the operator at the top of
5752 the stack has lower precedence than the new operator or there is
5753 only one element on the stack; then the top expression is the LHS
5754 of the new operator. In the case of logical AND and OR
5755 expressions, we also need to adjust c_inhibit_evaluation_warnings
5756 as appropriate when the operators are pushed and popped. */
5759 /* The expression at this stack level. */
5761 /* The precedence of the operator on its left, PREC_NONE at the
5762 bottom of the stack. */
5763 enum c_parser_prec prec
;
5764 /* The operation on its left. */
5766 /* The source location of this operation. */
5770 /* Location of the binary operator. */
5771 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5774 switch (stack[sp].op) \
5776 case TRUTH_ANDIF_EXPR: \
5777 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5778 == truthvalue_false_node); \
5780 case TRUTH_ORIF_EXPR: \
5781 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5782 == truthvalue_true_node); \
5787 stack[sp - 1].expr \
5788 = default_function_array_read_conversion (stack[sp - 1].loc, \
5789 stack[sp - 1].expr); \
5791 = default_function_array_read_conversion (stack[sp].loc, \
5793 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
5794 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
5795 && ((1 << stack[sp].prec) \
5796 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
5797 | PREC_ADD | PREC_MULT))) \
5798 && stack[sp].op != TRUNC_MOD_EXPR \
5799 && stack[0].expr.value != error_mark_node \
5800 && stack[1].expr.value != error_mark_node \
5801 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
5802 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
5803 stack[0].expr.value \
5804 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
5805 stack[0].expr.value, stack[1].expr.value); \
5807 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5809 stack[sp - 1].expr, \
5813 gcc_assert (!after
|| c_dialect_objc ());
5814 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5815 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5816 stack
[0].prec
= PREC_NONE
;
5820 enum c_parser_prec oprec
;
5821 enum tree_code ocode
;
5824 switch (c_parser_peek_token (parser
)->type
)
5832 ocode
= TRUNC_DIV_EXPR
;
5836 ocode
= TRUNC_MOD_EXPR
;
5848 ocode
= LSHIFT_EXPR
;
5852 ocode
= RSHIFT_EXPR
;
5866 case CPP_GREATER_EQ
:
5879 oprec
= PREC_BITAND
;
5880 ocode
= BIT_AND_EXPR
;
5883 oprec
= PREC_BITXOR
;
5884 ocode
= BIT_XOR_EXPR
;
5888 ocode
= BIT_IOR_EXPR
;
5891 oprec
= PREC_LOGAND
;
5892 ocode
= TRUTH_ANDIF_EXPR
;
5896 ocode
= TRUTH_ORIF_EXPR
;
5899 /* Not a binary operator, so end of the binary
5903 binary_loc
= c_parser_peek_token (parser
)->location
;
5904 while (oprec
<= stack
[sp
].prec
)
5906 c_parser_consume_token (parser
);
5909 case TRUTH_ANDIF_EXPR
:
5911 = default_function_array_read_conversion (stack
[sp
].loc
,
5913 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5914 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5915 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5916 == truthvalue_false_node
);
5918 case TRUTH_ORIF_EXPR
:
5920 = default_function_array_read_conversion (stack
[sp
].loc
,
5922 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5923 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5924 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5925 == truthvalue_true_node
);
5931 stack
[sp
].loc
= binary_loc
;
5932 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5933 stack
[sp
].prec
= oprec
;
5934 stack
[sp
].op
= ocode
;
5935 stack
[sp
].loc
= binary_loc
;
5940 return stack
[0].expr
;
5944 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5945 NULL then it is an Objective-C message expression which is the
5946 primary-expression starting the expression as an initializer.
5950 ( type-name ) unary-expression
5953 static struct c_expr
5954 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5956 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5957 gcc_assert (!after
|| c_dialect_objc ());
5959 return c_parser_postfix_expression_after_primary (parser
,
5961 /* If the expression begins with a parenthesized type name, it may
5962 be either a cast or a compound literal; we need to see whether
5963 the next character is '{' to tell the difference. If not, it is
5964 an unary expression. Full detection of unknown typenames here
5965 would require a 3-token lookahead. */
5966 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5967 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5969 struct c_type_name
*type_name
;
5972 c_parser_consume_token (parser
);
5973 type_name
= c_parser_type_name (parser
);
5974 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5975 if (type_name
== NULL
)
5977 ret
.value
= error_mark_node
;
5978 ret
.original_code
= ERROR_MARK
;
5979 ret
.original_type
= NULL
;
5983 /* Save casted types in the function's used types hash table. */
5984 used_types_insert (type_name
->specs
->type
);
5986 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5987 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5990 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5991 expr
= c_parser_cast_expression (parser
, NULL
);
5992 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5994 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5995 ret
.original_code
= ERROR_MARK
;
5996 ret
.original_type
= NULL
;
6000 return c_parser_unary_expression (parser
);
6003 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6009 unary-operator cast-expression
6010 sizeof unary-expression
6011 sizeof ( type-name )
6013 unary-operator: one of
6019 __alignof__ unary-expression
6020 __alignof__ ( type-name )
6023 (C11 permits _Alignof with type names only.)
6025 unary-operator: one of
6026 __extension__ __real__ __imag__
6028 Transactional Memory:
6031 transaction-expression
6033 In addition, the GNU syntax treats ++ and -- as unary operators, so
6034 they may be applied to cast expressions with errors for non-lvalues
6037 static struct c_expr
6038 c_parser_unary_expression (c_parser
*parser
)
6041 struct c_expr ret
, op
;
6042 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6044 ret
.original_code
= ERROR_MARK
;
6045 ret
.original_type
= NULL
;
6046 switch (c_parser_peek_token (parser
)->type
)
6049 c_parser_consume_token (parser
);
6050 exp_loc
= c_parser_peek_token (parser
)->location
;
6051 op
= c_parser_cast_expression (parser
, NULL
);
6053 /* If there is array notations in op, we expand them. */
6054 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6055 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6058 op
= default_function_array_read_conversion (exp_loc
, op
);
6059 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6061 case CPP_MINUS_MINUS
:
6062 c_parser_consume_token (parser
);
6063 exp_loc
= c_parser_peek_token (parser
)->location
;
6064 op
= c_parser_cast_expression (parser
, NULL
);
6066 /* If there is array notations in op, we expand them. */
6067 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6068 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6071 op
= default_function_array_read_conversion (exp_loc
, op
);
6072 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6075 c_parser_consume_token (parser
);
6076 op
= c_parser_cast_expression (parser
, NULL
);
6077 mark_exp_read (op
.value
);
6078 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6080 c_parser_consume_token (parser
);
6081 exp_loc
= c_parser_peek_token (parser
)->location
;
6082 op
= c_parser_cast_expression (parser
, NULL
);
6083 op
= default_function_array_read_conversion (exp_loc
, op
);
6084 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6087 if (!c_dialect_objc () && !in_system_header
)
6090 "traditional C rejects the unary plus operator");
6091 c_parser_consume_token (parser
);
6092 exp_loc
= c_parser_peek_token (parser
)->location
;
6093 op
= c_parser_cast_expression (parser
, NULL
);
6094 op
= default_function_array_read_conversion (exp_loc
, op
);
6095 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6097 c_parser_consume_token (parser
);
6098 exp_loc
= c_parser_peek_token (parser
)->location
;
6099 op
= c_parser_cast_expression (parser
, NULL
);
6100 op
= default_function_array_read_conversion (exp_loc
, op
);
6101 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6103 c_parser_consume_token (parser
);
6104 exp_loc
= c_parser_peek_token (parser
)->location
;
6105 op
= c_parser_cast_expression (parser
, NULL
);
6106 op
= default_function_array_read_conversion (exp_loc
, op
);
6107 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6109 c_parser_consume_token (parser
);
6110 exp_loc
= c_parser_peek_token (parser
)->location
;
6111 op
= c_parser_cast_expression (parser
, NULL
);
6112 op
= default_function_array_read_conversion (exp_loc
, op
);
6113 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6115 /* Refer to the address of a label as a pointer. */
6116 c_parser_consume_token (parser
);
6117 if (c_parser_next_token_is (parser
, CPP_NAME
))
6119 ret
.value
= finish_label_address_expr
6120 (c_parser_peek_token (parser
)->value
, op_loc
);
6121 c_parser_consume_token (parser
);
6125 c_parser_error (parser
, "expected identifier");
6126 ret
.value
= error_mark_node
;
6130 switch (c_parser_peek_token (parser
)->keyword
)
6133 return c_parser_sizeof_expression (parser
);
6135 return c_parser_alignof_expression (parser
);
6137 c_parser_consume_token (parser
);
6138 ext
= disable_extension_diagnostics ();
6139 ret
= c_parser_cast_expression (parser
, NULL
);
6140 restore_extension_diagnostics (ext
);
6143 c_parser_consume_token (parser
);
6144 exp_loc
= c_parser_peek_token (parser
)->location
;
6145 op
= c_parser_cast_expression (parser
, NULL
);
6146 op
= default_function_array_conversion (exp_loc
, op
);
6147 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6149 c_parser_consume_token (parser
);
6150 exp_loc
= c_parser_peek_token (parser
)->location
;
6151 op
= c_parser_cast_expression (parser
, NULL
);
6152 op
= default_function_array_conversion (exp_loc
, op
);
6153 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6154 case RID_TRANSACTION_ATOMIC
:
6155 case RID_TRANSACTION_RELAXED
:
6156 return c_parser_transaction_expression (parser
,
6157 c_parser_peek_token (parser
)->keyword
);
6159 return c_parser_postfix_expression (parser
);
6162 return c_parser_postfix_expression (parser
);
6166 /* Parse a sizeof expression. */
6168 static struct c_expr
6169 c_parser_sizeof_expression (c_parser
*parser
)
6172 location_t expr_loc
;
6173 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6174 c_parser_consume_token (parser
);
6175 c_inhibit_evaluation_warnings
++;
6177 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6178 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6180 /* Either sizeof ( type-name ) or sizeof unary-expression
6181 starting with a compound literal. */
6182 struct c_type_name
*type_name
;
6183 c_parser_consume_token (parser
);
6184 expr_loc
= c_parser_peek_token (parser
)->location
;
6185 type_name
= c_parser_type_name (parser
);
6186 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6187 if (type_name
== NULL
)
6190 c_inhibit_evaluation_warnings
--;
6192 ret
.value
= error_mark_node
;
6193 ret
.original_code
= ERROR_MARK
;
6194 ret
.original_type
= NULL
;
6197 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6199 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6204 /* sizeof ( type-name ). */
6205 c_inhibit_evaluation_warnings
--;
6207 return c_expr_sizeof_type (expr_loc
, type_name
);
6211 expr_loc
= c_parser_peek_token (parser
)->location
;
6212 expr
= c_parser_unary_expression (parser
);
6214 c_inhibit_evaluation_warnings
--;
6216 mark_exp_read (expr
.value
);
6217 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6218 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6219 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6220 return c_expr_sizeof_expr (expr_loc
, expr
);
6224 /* Parse an alignof expression. */
6226 static struct c_expr
6227 c_parser_alignof_expression (c_parser
*parser
)
6230 location_t loc
= c_parser_peek_token (parser
)->location
;
6231 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6232 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6233 /* A diagnostic is not required for the use of this identifier in
6234 the implementation namespace; only diagnose it for the C11
6235 spelling because of existing code using the other spellings. */
6237 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6240 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6243 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6246 c_parser_consume_token (parser
);
6247 c_inhibit_evaluation_warnings
++;
6249 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6250 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6252 /* Either __alignof__ ( type-name ) or __alignof__
6253 unary-expression starting with a compound literal. */
6255 struct c_type_name
*type_name
;
6257 c_parser_consume_token (parser
);
6258 loc
= c_parser_peek_token (parser
)->location
;
6259 type_name
= c_parser_type_name (parser
);
6260 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6261 if (type_name
== NULL
)
6264 c_inhibit_evaluation_warnings
--;
6266 ret
.value
= error_mark_node
;
6267 ret
.original_code
= ERROR_MARK
;
6268 ret
.original_type
= NULL
;
6271 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6273 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6278 /* alignof ( type-name ). */
6279 c_inhibit_evaluation_warnings
--;
6281 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6282 ret
.original_code
= ERROR_MARK
;
6283 ret
.original_type
= NULL
;
6289 expr
= c_parser_unary_expression (parser
);
6291 mark_exp_read (expr
.value
);
6292 c_inhibit_evaluation_warnings
--;
6294 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6296 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6297 ret
.original_code
= ERROR_MARK
;
6298 ret
.original_type
= NULL
;
6303 /* Helper function to read arguments of builtins which are interfaces
6304 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6305 others. The name of the builtin is passed using BNAME parameter.
6306 Function returns true if there were no errors while parsing and
6307 stores the arguments in CEXPR_LIST. */
6309 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6310 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6313 location_t loc
= c_parser_peek_token (parser
)->location
;
6314 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6316 bool saved_force_folding_builtin_constant_p
;
6318 *ret_cexpr_list
= NULL
;
6319 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6321 error_at (loc
, "cannot take address of %qs", bname
);
6325 c_parser_consume_token (parser
);
6327 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6329 c_parser_consume_token (parser
);
6333 saved_force_folding_builtin_constant_p
6334 = force_folding_builtin_constant_p
;
6335 force_folding_builtin_constant_p
|= choose_expr_p
;
6336 expr
= c_parser_expr_no_commas (parser
, NULL
);
6337 force_folding_builtin_constant_p
6338 = saved_force_folding_builtin_constant_p
;
6339 vec_alloc (cexpr_list
, 1);
6340 C_EXPR_APPEND (cexpr_list
, expr
);
6341 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6343 c_parser_consume_token (parser
);
6344 expr
= c_parser_expr_no_commas (parser
, NULL
);
6345 C_EXPR_APPEND (cexpr_list
, expr
);
6348 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6351 *ret_cexpr_list
= cexpr_list
;
6355 /* This represents a single generic-association. */
6357 struct c_generic_association
6359 /* The location of the starting token of the type. */
6360 location_t type_location
;
6361 /* The association's type, or NULL_TREE for 'default'. */
6363 /* The association's expression. */
6364 struct c_expr expression
;
6367 /* Parse a generic-selection. (C11 6.5.1.1).
6370 _Generic ( assignment-expression , generic-assoc-list )
6374 generic-assoc-list , generic-association
6376 generic-association:
6377 type-name : assignment-expression
6378 default : assignment-expression
6381 static struct c_expr
6382 c_parser_generic_selection (c_parser
*parser
)
6384 vec
<c_generic_association
> associations
= vNULL
;
6385 struct c_expr selector
, error_expr
;
6387 struct c_generic_association matched_assoc
;
6388 bool match_found
= false;
6389 location_t generic_loc
, selector_loc
;
6391 error_expr
.original_code
= ERROR_MARK
;
6392 error_expr
.original_type
= NULL
;
6393 error_expr
.value
= error_mark_node
;
6394 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6395 matched_assoc
.type
= NULL_TREE
;
6396 matched_assoc
.expression
= error_expr
;
6398 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6399 generic_loc
= c_parser_peek_token (parser
)->location
;
6400 c_parser_consume_token (parser
);
6404 pedwarn (generic_loc
, OPT_Wpedantic
,
6405 "ISO C99 does not support %<_Generic%>");
6407 pedwarn (generic_loc
, OPT_Wpedantic
,
6408 "ISO C90 does not support %<_Generic%>");
6411 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6414 c_inhibit_evaluation_warnings
++;
6415 selector_loc
= c_parser_peek_token (parser
)->location
;
6416 selector
= c_parser_expr_no_commas (parser
, NULL
);
6417 selector
= default_function_array_conversion (selector_loc
, selector
);
6418 c_inhibit_evaluation_warnings
--;
6420 if (selector
.value
== error_mark_node
)
6422 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6425 selector_type
= TREE_TYPE (selector
.value
);
6426 /* In ISO C terms, rvalues (including the controlling expression of
6427 _Generic) do not have qualified types. */
6428 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6429 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6430 /* In ISO C terms, _Noreturn is not part of the type of expressions
6431 such as &abort, but in GCC it is represented internally as a type
6433 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6434 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6436 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6438 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6440 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6446 struct c_generic_association assoc
, *iter
;
6448 c_token
*token
= c_parser_peek_token (parser
);
6450 assoc
.type_location
= token
->location
;
6451 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6453 c_parser_consume_token (parser
);
6454 assoc
.type
= NULL_TREE
;
6458 struct c_type_name
*type_name
;
6460 type_name
= c_parser_type_name (parser
);
6461 if (type_name
== NULL
)
6463 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6466 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6467 if (assoc
.type
== error_mark_node
)
6469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6473 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6474 error_at (assoc
.type_location
,
6475 "%<_Generic%> association has function type");
6476 else if (!COMPLETE_TYPE_P (assoc
.type
))
6477 error_at (assoc
.type_location
,
6478 "%<_Generic%> association has incomplete type");
6480 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6481 error_at (assoc
.type_location
,
6482 "%<_Generic%> association has "
6483 "variable length type");
6486 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6488 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6492 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6493 if (assoc
.expression
.value
== error_mark_node
)
6495 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6499 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6501 if (assoc
.type
== NULL_TREE
)
6503 if (iter
->type
== NULL_TREE
)
6505 error_at (assoc
.type_location
,
6506 "duplicate %<default%> case in %<_Generic%>");
6507 inform (iter
->type_location
, "original %<default%> is here");
6510 else if (iter
->type
!= NULL_TREE
)
6512 if (comptypes (assoc
.type
, iter
->type
))
6514 error_at (assoc
.type_location
,
6515 "%<_Generic%> specifies two compatible types");
6516 inform (iter
->type_location
, "compatible type is here");
6521 if (assoc
.type
== NULL_TREE
)
6525 matched_assoc
= assoc
;
6529 else if (comptypes (assoc
.type
, selector_type
))
6531 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6533 matched_assoc
= assoc
;
6538 error_at (assoc
.type_location
,
6539 "%<_Generic> selector matches multiple associations");
6540 inform (matched_assoc
.type_location
,
6541 "other match is here");
6545 associations
.safe_push (assoc
);
6547 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6549 c_parser_consume_token (parser
);
6552 associations
.release ();
6554 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6556 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6562 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6563 "compatible with any association",
6568 return matched_assoc
.expression
;
6571 associations
.release ();
6575 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6579 postfix-expression [ expression ]
6580 postfix-expression ( argument-expression-list[opt] )
6581 postfix-expression . identifier
6582 postfix-expression -> identifier
6583 postfix-expression ++
6584 postfix-expression --
6585 ( type-name ) { initializer-list }
6586 ( type-name ) { initializer-list , }
6588 argument-expression-list:
6590 argument-expression-list , argument-expression
6603 (treated as a keyword in GNU C)
6606 ( compound-statement )
6607 __builtin_va_arg ( assignment-expression , type-name )
6608 __builtin_offsetof ( type-name , offsetof-member-designator )
6609 __builtin_choose_expr ( assignment-expression ,
6610 assignment-expression ,
6611 assignment-expression )
6612 __builtin_types_compatible_p ( type-name , type-name )
6613 __builtin_complex ( assignment-expression , assignment-expression )
6614 __builtin_shuffle ( assignment-expression , assignment-expression )
6615 __builtin_shuffle ( assignment-expression ,
6616 assignment-expression ,
6617 assignment-expression, )
6619 offsetof-member-designator:
6621 offsetof-member-designator . identifier
6622 offsetof-member-designator [ expression ]
6627 [ objc-receiver objc-message-args ]
6628 @selector ( objc-selector-arg )
6629 @protocol ( identifier )
6630 @encode ( type-name )
6632 Classname . identifier
6635 static struct c_expr
6636 c_parser_postfix_expression (c_parser
*parser
)
6638 struct c_expr expr
, e1
;
6639 struct c_type_name
*t1
, *t2
;
6640 location_t loc
= c_parser_peek_token (parser
)->location
;;
6641 expr
.original_code
= ERROR_MARK
;
6642 expr
.original_type
= NULL
;
6643 switch (c_parser_peek_token (parser
)->type
)
6646 expr
.value
= c_parser_peek_token (parser
)->value
;
6647 loc
= c_parser_peek_token (parser
)->location
;
6648 c_parser_consume_token (parser
);
6649 if (TREE_CODE (expr
.value
) == FIXED_CST
6650 && !targetm
.fixed_point_supported_p ())
6652 error_at (loc
, "fixed-point types not supported for this target");
6653 expr
.value
= error_mark_node
;
6660 expr
.value
= c_parser_peek_token (parser
)->value
;
6661 c_parser_consume_token (parser
);
6667 case CPP_UTF8STRING
:
6668 expr
.value
= c_parser_peek_token (parser
)->value
;
6669 expr
.original_code
= STRING_CST
;
6670 c_parser_consume_token (parser
);
6672 case CPP_OBJC_STRING
:
6673 gcc_assert (c_dialect_objc ());
6675 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6676 c_parser_consume_token (parser
);
6679 switch (c_parser_peek_token (parser
)->id_kind
)
6683 tree id
= c_parser_peek_token (parser
)->value
;
6684 c_parser_consume_token (parser
);
6685 expr
.value
= build_external_ref (loc
, id
,
6686 (c_parser_peek_token (parser
)->type
6688 &expr
.original_type
);
6691 case C_ID_CLASSNAME
:
6693 /* Here we parse the Objective-C 2.0 Class.name dot
6695 tree class_name
= c_parser_peek_token (parser
)->value
;
6697 c_parser_consume_token (parser
);
6698 gcc_assert (c_dialect_objc ());
6699 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6701 expr
.value
= error_mark_node
;
6704 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6706 c_parser_error (parser
, "expected identifier");
6707 expr
.value
= error_mark_node
;
6710 component
= c_parser_peek_token (parser
)->value
;
6711 c_parser_consume_token (parser
);
6712 expr
.value
= objc_build_class_component_ref (class_name
,
6717 c_parser_error (parser
, "expected expression");
6718 expr
.value
= error_mark_node
;
6722 case CPP_OPEN_PAREN
:
6723 /* A parenthesized expression, statement expression or compound
6725 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6727 /* A statement expression. */
6729 location_t brace_loc
;
6730 c_parser_consume_token (parser
);
6731 brace_loc
= c_parser_peek_token (parser
)->location
;
6732 c_parser_consume_token (parser
);
6733 if (!building_stmt_list_p ())
6735 error_at (loc
, "braced-group within expression allowed "
6736 "only inside a function");
6737 parser
->error
= true;
6738 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6739 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6740 expr
.value
= error_mark_node
;
6743 stmt
= c_begin_stmt_expr ();
6744 c_parser_compound_statement_nostart (parser
);
6745 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6747 pedwarn (loc
, OPT_Wpedantic
,
6748 "ISO C forbids braced-groups within expressions");
6749 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6750 mark_exp_read (expr
.value
);
6752 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6754 /* A compound literal. ??? Can we actually get here rather
6755 than going directly to
6756 c_parser_postfix_expression_after_paren_type from
6759 struct c_type_name
*type_name
;
6760 c_parser_consume_token (parser
);
6761 loc
= c_parser_peek_token (parser
)->location
;
6762 type_name
= c_parser_type_name (parser
);
6763 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6765 if (type_name
== NULL
)
6767 expr
.value
= error_mark_node
;
6770 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6776 /* A parenthesized expression. */
6777 c_parser_consume_token (parser
);
6778 expr
= c_parser_expression (parser
);
6779 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6780 TREE_NO_WARNING (expr
.value
) = 1;
6781 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6782 expr
.original_code
= ERROR_MARK
;
6783 /* Don't change EXPR.ORIGINAL_TYPE. */
6784 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6789 switch (c_parser_peek_token (parser
)->keyword
)
6791 case RID_FUNCTION_NAME
:
6792 case RID_PRETTY_FUNCTION_NAME
:
6793 case RID_C99_FUNCTION_NAME
:
6794 expr
.value
= fname_decl (loc
,
6795 c_parser_peek_token (parser
)->keyword
,
6796 c_parser_peek_token (parser
)->value
);
6797 c_parser_consume_token (parser
);
6800 c_parser_consume_token (parser
);
6801 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6803 expr
.value
= error_mark_node
;
6806 e1
= c_parser_expr_no_commas (parser
, NULL
);
6807 mark_exp_read (e1
.value
);
6808 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6809 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6811 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6812 expr
.value
= error_mark_node
;
6815 loc
= c_parser_peek_token (parser
)->location
;
6816 t1
= c_parser_type_name (parser
);
6817 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6821 expr
.value
= error_mark_node
;
6825 tree type_expr
= NULL_TREE
;
6826 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6827 groktypename (t1
, &type_expr
, NULL
));
6830 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6831 TREE_TYPE (expr
.value
), type_expr
,
6833 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6838 c_parser_consume_token (parser
);
6839 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6841 expr
.value
= error_mark_node
;
6844 t1
= c_parser_type_name (parser
);
6846 parser
->error
= true;
6847 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6848 gcc_assert (parser
->error
);
6851 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6852 expr
.value
= error_mark_node
;
6857 tree type
= groktypename (t1
, NULL
, NULL
);
6859 if (type
== error_mark_node
)
6860 offsetof_ref
= error_mark_node
;
6863 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6864 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6866 /* Parse the second argument to __builtin_offsetof. We
6867 must have one identifier, and beyond that we want to
6868 accept sub structure and sub array references. */
6869 if (c_parser_next_token_is (parser
, CPP_NAME
))
6871 offsetof_ref
= build_component_ref
6872 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6873 c_parser_consume_token (parser
);
6874 while (c_parser_next_token_is (parser
, CPP_DOT
)
6875 || c_parser_next_token_is (parser
,
6877 || c_parser_next_token_is (parser
,
6880 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6882 loc
= c_parser_peek_token (parser
)->location
;
6883 offsetof_ref
= build_array_ref (loc
,
6888 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6891 c_parser_consume_token (parser
);
6892 if (c_parser_next_token_is_not (parser
,
6895 c_parser_error (parser
, "expected identifier");
6898 offsetof_ref
= build_component_ref
6900 c_parser_peek_token (parser
)->value
);
6901 c_parser_consume_token (parser
);
6906 loc
= c_parser_peek_token (parser
)->location
;
6907 c_parser_consume_token (parser
);
6908 idx
= c_parser_expression (parser
).value
;
6909 idx
= c_fully_fold (idx
, false, NULL
);
6910 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6912 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6917 c_parser_error (parser
, "expected identifier");
6918 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6920 expr
.value
= fold_offsetof (offsetof_ref
);
6923 case RID_CHOOSE_EXPR
:
6925 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6926 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6929 c_parser_consume_token (parser
);
6930 if (!c_parser_get_builtin_args (parser
,
6931 "__builtin_choose_expr",
6934 expr
.value
= error_mark_node
;
6938 if (vec_safe_length (cexpr_list
) != 3)
6940 error_at (loc
, "wrong number of arguments to "
6941 "%<__builtin_choose_expr%>");
6942 expr
.value
= error_mark_node
;
6946 e1_p
= &(*cexpr_list
)[0];
6947 e2_p
= &(*cexpr_list
)[1];
6948 e3_p
= &(*cexpr_list
)[2];
6951 mark_exp_read (e2_p
->value
);
6952 mark_exp_read (e3_p
->value
);
6953 if (TREE_CODE (c
) != INTEGER_CST
6954 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6956 "first argument to %<__builtin_choose_expr%> not"
6958 constant_expression_warning (c
);
6959 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6962 case RID_TYPES_COMPATIBLE_P
:
6963 c_parser_consume_token (parser
);
6964 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6966 expr
.value
= error_mark_node
;
6969 t1
= c_parser_type_name (parser
);
6972 expr
.value
= error_mark_node
;
6975 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6977 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6978 expr
.value
= error_mark_node
;
6981 t2
= c_parser_type_name (parser
);
6984 expr
.value
= error_mark_node
;
6987 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6991 e1
= groktypename (t1
, NULL
, NULL
);
6992 e2
= groktypename (t2
, NULL
, NULL
);
6993 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6995 expr
.value
= error_mark_node
;
6999 e1
= TYPE_MAIN_VARIANT (e1
);
7000 e2
= TYPE_MAIN_VARIANT (e2
);
7003 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7006 case RID_BUILTIN_COMPLEX
:
7008 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7009 c_expr_t
*e1_p
, *e2_p
;
7011 c_parser_consume_token (parser
);
7012 if (!c_parser_get_builtin_args (parser
,
7013 "__builtin_complex",
7014 &cexpr_list
, false))
7016 expr
.value
= error_mark_node
;
7020 if (vec_safe_length (cexpr_list
) != 2)
7022 error_at (loc
, "wrong number of arguments to "
7023 "%<__builtin_complex%>");
7024 expr
.value
= error_mark_node
;
7028 e1_p
= &(*cexpr_list
)[0];
7029 e2_p
= &(*cexpr_list
)[1];
7031 mark_exp_read (e1_p
->value
);
7032 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7033 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7034 TREE_OPERAND (e1_p
->value
, 0));
7035 mark_exp_read (e2_p
->value
);
7036 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7037 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7038 TREE_OPERAND (e2_p
->value
, 0));
7039 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7040 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7041 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7042 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7044 error_at (loc
, "%<__builtin_complex%> operand "
7045 "not of real binary floating-point type");
7046 expr
.value
= error_mark_node
;
7049 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7050 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7053 "%<__builtin_complex%> operands of different types");
7054 expr
.value
= error_mark_node
;
7058 pedwarn (loc
, OPT_Wpedantic
,
7059 "ISO C90 does not support complex types");
7060 expr
.value
= build2 (COMPLEX_EXPR
,
7063 (TREE_TYPE (e1_p
->value
))),
7064 e1_p
->value
, e2_p
->value
);
7067 case RID_BUILTIN_SHUFFLE
:
7069 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7073 c_parser_consume_token (parser
);
7074 if (!c_parser_get_builtin_args (parser
,
7075 "__builtin_shuffle",
7076 &cexpr_list
, false))
7078 expr
.value
= error_mark_node
;
7082 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7083 mark_exp_read (p
->value
);
7085 if (vec_safe_length (cexpr_list
) == 2)
7087 c_build_vec_perm_expr
7088 (loc
, (*cexpr_list
)[0].value
,
7089 NULL_TREE
, (*cexpr_list
)[1].value
);
7091 else if (vec_safe_length (cexpr_list
) == 3)
7093 c_build_vec_perm_expr
7094 (loc
, (*cexpr_list
)[0].value
,
7095 (*cexpr_list
)[1].value
,
7096 (*cexpr_list
)[2].value
);
7099 error_at (loc
, "wrong number of arguments to "
7100 "%<__builtin_shuffle%>");
7101 expr
.value
= error_mark_node
;
7105 case RID_AT_SELECTOR
:
7106 gcc_assert (c_dialect_objc ());
7107 c_parser_consume_token (parser
);
7108 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7110 expr
.value
= error_mark_node
;
7114 tree sel
= c_parser_objc_selector_arg (parser
);
7115 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7117 expr
.value
= objc_build_selector_expr (loc
, sel
);
7120 case RID_AT_PROTOCOL
:
7121 gcc_assert (c_dialect_objc ());
7122 c_parser_consume_token (parser
);
7123 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7125 expr
.value
= error_mark_node
;
7128 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7130 c_parser_error (parser
, "expected identifier");
7131 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7132 expr
.value
= error_mark_node
;
7136 tree id
= c_parser_peek_token (parser
)->value
;
7137 c_parser_consume_token (parser
);
7138 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7140 expr
.value
= objc_build_protocol_expr (id
);
7144 /* Extension to support C-structures in the archiver. */
7145 gcc_assert (c_dialect_objc ());
7146 c_parser_consume_token (parser
);
7147 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7149 expr
.value
= error_mark_node
;
7152 t1
= c_parser_type_name (parser
);
7155 expr
.value
= error_mark_node
;
7156 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7159 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7162 tree type
= groktypename (t1
, NULL
, NULL
);
7163 expr
.value
= objc_build_encode_expr (type
);
7167 expr
= c_parser_generic_selection (parser
);
7170 c_parser_error (parser
, "expected expression");
7171 expr
.value
= error_mark_node
;
7175 case CPP_OPEN_SQUARE
:
7176 if (c_dialect_objc ())
7178 tree receiver
, args
;
7179 c_parser_consume_token (parser
);
7180 receiver
= c_parser_objc_receiver (parser
);
7181 args
= c_parser_objc_message_args (parser
);
7182 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7184 expr
.value
= objc_build_message_expr (receiver
, args
);
7187 /* Else fall through to report error. */
7189 c_parser_error (parser
, "expected expression");
7190 expr
.value
= error_mark_node
;
7193 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7196 /* Parse a postfix expression after a parenthesized type name: the
7197 brace-enclosed initializer of a compound literal, possibly followed
7198 by some postfix operators. This is separate because it is not
7199 possible to tell until after the type name whether a cast
7200 expression has a cast or a compound literal, or whether the operand
7201 of sizeof is a parenthesized type name or starts with a compound
7202 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7203 location of the first token after the parentheses around the type
7206 static struct c_expr
7207 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7208 struct c_type_name
*type_name
,
7209 location_t type_loc
)
7215 location_t start_loc
;
7216 tree type_expr
= NULL_TREE
;
7217 bool type_expr_const
= true;
7218 check_compound_literal_type (type_loc
, type_name
);
7219 start_init (NULL_TREE
, NULL
, 0);
7220 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7221 start_loc
= c_parser_peek_token (parser
)->location
;
7222 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7224 error_at (type_loc
, "compound literal has variable size");
7225 type
= error_mark_node
;
7227 init
= c_parser_braced_init (parser
, type
, false);
7229 maybe_warn_string_init (type
, init
);
7231 if (type
!= error_mark_node
7232 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7233 && current_function_decl
)
7235 error ("compound literal qualified by address-space qualifier");
7236 type
= error_mark_node
;
7240 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7241 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7242 ? CONSTRUCTOR_NON_CONST (init
.value
)
7243 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7244 non_const
|= !type_expr_const
;
7245 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7246 expr
.original_code
= ERROR_MARK
;
7247 expr
.original_type
= NULL
;
7250 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7252 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7253 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7257 gcc_assert (!non_const
);
7258 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7259 type_expr
, expr
.value
);
7262 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7265 /* Callback function for sizeof_pointer_memaccess_warning to compare
7269 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7271 return comptypes (type1
, type2
) == 1;
7274 /* Parse a postfix expression after the initial primary or compound
7275 literal; that is, parse a series of postfix operators.
7277 EXPR_LOC is the location of the primary expression. */
7279 static struct c_expr
7280 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7281 location_t expr_loc
,
7284 struct c_expr orig_expr
;
7286 location_t sizeof_arg_loc
[3];
7289 vec
<tree
, va_gc
> *exprlist
;
7290 vec
<tree
, va_gc
> *origtypes
= NULL
;
7293 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7294 switch (c_parser_peek_token (parser
)->type
)
7296 case CPP_OPEN_SQUARE
:
7297 /* Array reference. */
7298 c_parser_consume_token (parser
);
7299 if (flag_enable_cilkplus
7300 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7301 /* If we are here, then we have something like this:
7304 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7308 idx
= c_parser_expression (parser
).value
;
7309 /* Here we have 3 options:
7310 1. Array [EXPR] -- Normal Array call.
7311 2. Array [EXPR : EXPR] -- Array notation without stride.
7312 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7314 For 1, we just handle it just like a normal array expression.
7315 For 2 and 3 we handle it like we handle array notations. The
7316 idx value we have above becomes the initial/start index.
7318 if (flag_enable_cilkplus
7319 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7320 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7324 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7326 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7329 expr
.original_code
= ERROR_MARK
;
7330 expr
.original_type
= NULL
;
7332 case CPP_OPEN_PAREN
:
7333 /* Function call. */
7334 c_parser_consume_token (parser
);
7335 for (i
= 0; i
< 3; i
++)
7337 sizeof_arg
[i
] = NULL_TREE
;
7338 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7340 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7343 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7344 sizeof_arg_loc
, sizeof_arg
);
7345 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7348 mark_exp_read (expr
.value
);
7349 if (warn_sizeof_pointer_memaccess
)
7350 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7351 expr
.value
, exprlist
,
7353 sizeof_ptr_memacc_comptypes
);
7354 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7355 "(" after the FUNCNAME, which is what we have now. */
7356 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7358 expr
.original_code
= ERROR_MARK
;
7359 if (TREE_CODE (expr
.value
) == INTEGER_CST
7360 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7361 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7362 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7363 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7364 expr
.original_type
= NULL
;
7367 release_tree_vector (exprlist
);
7368 release_tree_vector (origtypes
);
7372 /* Structure element reference. */
7373 c_parser_consume_token (parser
);
7374 expr
= default_function_array_conversion (expr_loc
, expr
);
7375 if (c_parser_next_token_is (parser
, CPP_NAME
))
7376 ident
= c_parser_peek_token (parser
)->value
;
7379 c_parser_error (parser
, "expected identifier");
7380 expr
.value
= error_mark_node
;
7381 expr
.original_code
= ERROR_MARK
;
7382 expr
.original_type
= NULL
;
7385 c_parser_consume_token (parser
);
7386 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7387 expr
.original_code
= ERROR_MARK
;
7388 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7389 expr
.original_type
= NULL
;
7392 /* Remember the original type of a bitfield. */
7393 tree field
= TREE_OPERAND (expr
.value
, 1);
7394 if (TREE_CODE (field
) != FIELD_DECL
)
7395 expr
.original_type
= NULL
;
7397 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7401 /* Structure element reference. */
7402 c_parser_consume_token (parser
);
7403 expr
= default_function_array_conversion (expr_loc
, expr
);
7404 if (c_parser_next_token_is (parser
, CPP_NAME
))
7405 ident
= c_parser_peek_token (parser
)->value
;
7408 c_parser_error (parser
, "expected identifier");
7409 expr
.value
= error_mark_node
;
7410 expr
.original_code
= ERROR_MARK
;
7411 expr
.original_type
= NULL
;
7414 c_parser_consume_token (parser
);
7415 expr
.value
= build_component_ref (op_loc
,
7416 build_indirect_ref (op_loc
,
7420 expr
.original_code
= ERROR_MARK
;
7421 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7422 expr
.original_type
= NULL
;
7425 /* Remember the original type of a bitfield. */
7426 tree field
= TREE_OPERAND (expr
.value
, 1);
7427 if (TREE_CODE (field
) != FIELD_DECL
)
7428 expr
.original_type
= NULL
;
7430 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7434 /* Postincrement. */
7435 c_parser_consume_token (parser
);
7436 /* If the expressions have array notations, we expand them. */
7437 if (flag_enable_cilkplus
7438 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7439 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7442 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7443 expr
.value
= build_unary_op (op_loc
,
7444 POSTINCREMENT_EXPR
, expr
.value
, 0);
7446 expr
.original_code
= ERROR_MARK
;
7447 expr
.original_type
= NULL
;
7449 case CPP_MINUS_MINUS
:
7450 /* Postdecrement. */
7451 c_parser_consume_token (parser
);
7452 /* If the expressions have array notations, we expand them. */
7453 if (flag_enable_cilkplus
7454 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7455 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7458 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7459 expr
.value
= build_unary_op (op_loc
,
7460 POSTDECREMENT_EXPR
, expr
.value
, 0);
7462 expr
.original_code
= ERROR_MARK
;
7463 expr
.original_type
= NULL
;
7471 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7474 assignment-expression
7475 expression , assignment-expression
7478 static struct c_expr
7479 c_parser_expression (c_parser
*parser
)
7482 expr
= c_parser_expr_no_commas (parser
, NULL
);
7483 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7487 location_t loc
= c_parser_peek_token (parser
)->location
;
7488 location_t expr_loc
;
7489 c_parser_consume_token (parser
);
7490 expr_loc
= c_parser_peek_token (parser
)->location
;
7491 lhsval
= expr
.value
;
7492 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7493 lhsval
= TREE_OPERAND (lhsval
, 1);
7494 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7495 mark_exp_read (lhsval
);
7496 next
= c_parser_expr_no_commas (parser
, NULL
);
7497 next
= default_function_array_conversion (expr_loc
, next
);
7498 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7499 expr
.original_code
= COMPOUND_EXPR
;
7500 expr
.original_type
= next
.original_type
;
7505 /* Parse an expression and convert functions or arrays to
7508 static struct c_expr
7509 c_parser_expression_conv (c_parser
*parser
)
7512 location_t loc
= c_parser_peek_token (parser
)->location
;
7513 expr
= c_parser_expression (parser
);
7514 expr
= default_function_array_conversion (loc
, expr
);
7518 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7519 functions and arrays to pointers. If FOLD_P, fold the expressions.
7522 assignment-expression
7523 nonempty-expr-list , assignment-expression
7526 static vec
<tree
, va_gc
> *
7527 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7528 vec
<tree
, va_gc
> **p_orig_types
,
7529 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7531 vec
<tree
, va_gc
> *ret
;
7532 vec
<tree
, va_gc
> *orig_types
;
7534 location_t loc
= c_parser_peek_token (parser
)->location
;
7535 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7536 unsigned int idx
= 0;
7538 ret
= make_tree_vector ();
7539 if (p_orig_types
== NULL
)
7542 orig_types
= make_tree_vector ();
7544 if (sizeof_arg
!= NULL
7545 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7546 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7547 expr
= c_parser_expr_no_commas (parser
, NULL
);
7549 expr
= default_function_array_read_conversion (loc
, expr
);
7551 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7552 ret
->quick_push (expr
.value
);
7554 orig_types
->quick_push (expr
.original_type
);
7555 if (sizeof_arg
!= NULL
7556 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7557 && expr
.original_code
== SIZEOF_EXPR
)
7559 sizeof_arg
[0] = c_last_sizeof_arg
;
7560 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7562 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7564 c_parser_consume_token (parser
);
7565 loc
= c_parser_peek_token (parser
)->location
;
7566 if (sizeof_arg
!= NULL
7567 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7568 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7570 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7571 expr
= c_parser_expr_no_commas (parser
, NULL
);
7573 expr
= default_function_array_read_conversion (loc
, expr
);
7575 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7576 vec_safe_push (ret
, expr
.value
);
7578 vec_safe_push (orig_types
, expr
.original_type
);
7580 && sizeof_arg
!= NULL
7581 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7582 && expr
.original_code
== SIZEOF_EXPR
)
7584 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7585 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7589 *p_orig_types
= orig_types
;
7593 /* Parse Objective-C-specific constructs. */
7595 /* Parse an objc-class-definition.
7597 objc-class-definition:
7598 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7599 objc-class-instance-variables[opt] objc-methodprotolist @end
7600 @implementation identifier objc-superclass[opt]
7601 objc-class-instance-variables[opt]
7602 @interface identifier ( identifier ) objc-protocol-refs[opt]
7603 objc-methodprotolist @end
7604 @interface identifier ( ) objc-protocol-refs[opt]
7605 objc-methodprotolist @end
7606 @implementation identifier ( identifier )
7611 "@interface identifier (" must start "@interface identifier (
7612 identifier ) ...": objc-methodprotolist in the first production may
7613 not start with a parenthesized identifier as a declarator of a data
7614 definition with no declaration specifiers if the objc-superclass,
7615 objc-protocol-refs and objc-class-instance-variables are omitted. */
7618 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7623 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7625 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7630 c_parser_consume_token (parser
);
7631 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7633 c_parser_error (parser
, "expected identifier");
7636 id1
= c_parser_peek_token (parser
)->value
;
7637 c_parser_consume_token (parser
);
7638 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7640 /* We have a category or class extension. */
7642 tree proto
= NULL_TREE
;
7643 c_parser_consume_token (parser
);
7644 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7646 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7648 /* We have a class extension. */
7653 c_parser_error (parser
, "expected identifier or %<)%>");
7654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7660 id2
= c_parser_peek_token (parser
)->value
;
7661 c_parser_consume_token (parser
);
7663 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7666 objc_start_category_implementation (id1
, id2
);
7669 if (c_parser_next_token_is (parser
, CPP_LESS
))
7670 proto
= c_parser_objc_protocol_refs (parser
);
7671 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7672 c_parser_objc_methodprotolist (parser
);
7673 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7674 objc_finish_interface ();
7677 if (c_parser_next_token_is (parser
, CPP_COLON
))
7679 c_parser_consume_token (parser
);
7680 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7682 c_parser_error (parser
, "expected identifier");
7685 superclass
= c_parser_peek_token (parser
)->value
;
7686 c_parser_consume_token (parser
);
7689 superclass
= NULL_TREE
;
7692 tree proto
= NULL_TREE
;
7693 if (c_parser_next_token_is (parser
, CPP_LESS
))
7694 proto
= c_parser_objc_protocol_refs (parser
);
7695 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7698 objc_start_class_implementation (id1
, superclass
);
7699 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7700 c_parser_objc_class_instance_variables (parser
);
7703 objc_continue_interface ();
7704 c_parser_objc_methodprotolist (parser
);
7705 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7706 objc_finish_interface ();
7710 objc_continue_implementation ();
7715 /* Parse objc-class-instance-variables.
7717 objc-class-instance-variables:
7718 { objc-instance-variable-decl-list[opt] }
7720 objc-instance-variable-decl-list:
7721 objc-visibility-spec
7722 objc-instance-variable-decl ;
7724 objc-instance-variable-decl-list objc-visibility-spec
7725 objc-instance-variable-decl-list objc-instance-variable-decl ;
7726 objc-instance-variable-decl-list ;
7728 objc-visibility-spec:
7733 objc-instance-variable-decl:
7738 c_parser_objc_class_instance_variables (c_parser
*parser
)
7740 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7741 c_parser_consume_token (parser
);
7742 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7745 /* Parse any stray semicolon. */
7746 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7748 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7750 c_parser_consume_token (parser
);
7753 /* Stop if at the end of the instance variables. */
7754 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7756 c_parser_consume_token (parser
);
7759 /* Parse any objc-visibility-spec. */
7760 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7762 c_parser_consume_token (parser
);
7763 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7766 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7768 c_parser_consume_token (parser
);
7769 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7772 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7774 c_parser_consume_token (parser
);
7775 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7778 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7780 c_parser_consume_token (parser
);
7781 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7784 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7786 c_parser_pragma (parser
, pragma_external
);
7790 /* Parse some comma-separated declarations. */
7791 decls
= c_parser_struct_declaration (parser
);
7794 /* There is a syntax error. We want to skip the offending
7795 tokens up to the next ';' (included) or '}'
7798 /* First, skip manually a ')' or ']'. This is because they
7799 reduce the nesting level, so c_parser_skip_until_found()
7800 wouldn't be able to skip past them. */
7801 c_token
*token
= c_parser_peek_token (parser
);
7802 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7803 c_parser_consume_token (parser
);
7805 /* Then, do the standard skipping. */
7806 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7808 /* We hopefully recovered. Start normal parsing again. */
7809 parser
->error
= false;
7814 /* Comma-separated instance variables are chained together
7815 in reverse order; add them one by one. */
7816 tree ivar
= nreverse (decls
);
7817 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7818 objc_add_instance_variable (copy_node (ivar
));
7820 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7824 /* Parse an objc-class-declaration.
7826 objc-class-declaration:
7827 @class identifier-list ;
7831 c_parser_objc_class_declaration (c_parser
*parser
)
7833 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7834 c_parser_consume_token (parser
);
7835 /* Any identifiers, including those declared as type names, are OK
7840 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7842 c_parser_error (parser
, "expected identifier");
7843 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7844 parser
->error
= false;
7847 id
= c_parser_peek_token (parser
)->value
;
7848 objc_declare_class (id
);
7849 c_parser_consume_token (parser
);
7850 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7851 c_parser_consume_token (parser
);
7855 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7858 /* Parse an objc-alias-declaration.
7860 objc-alias-declaration:
7861 @compatibility_alias identifier identifier ;
7865 c_parser_objc_alias_declaration (c_parser
*parser
)
7868 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7869 c_parser_consume_token (parser
);
7870 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7872 c_parser_error (parser
, "expected identifier");
7873 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7876 id1
= c_parser_peek_token (parser
)->value
;
7877 c_parser_consume_token (parser
);
7878 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7880 c_parser_error (parser
, "expected identifier");
7881 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7884 id2
= c_parser_peek_token (parser
)->value
;
7885 c_parser_consume_token (parser
);
7886 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7887 objc_declare_alias (id1
, id2
);
7890 /* Parse an objc-protocol-definition.
7892 objc-protocol-definition:
7893 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7894 @protocol identifier-list ;
7896 "@protocol identifier ;" should be resolved as "@protocol
7897 identifier-list ;": objc-methodprotolist may not start with a
7898 semicolon in the first alternative if objc-protocol-refs are
7902 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7904 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7906 c_parser_consume_token (parser
);
7907 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7909 c_parser_error (parser
, "expected identifier");
7912 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7913 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7915 /* Any identifiers, including those declared as type names, are
7920 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7922 c_parser_error (parser
, "expected identifier");
7925 id
= c_parser_peek_token (parser
)->value
;
7926 objc_declare_protocol (id
, attributes
);
7927 c_parser_consume_token (parser
);
7928 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7929 c_parser_consume_token (parser
);
7933 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7937 tree id
= c_parser_peek_token (parser
)->value
;
7938 tree proto
= NULL_TREE
;
7939 c_parser_consume_token (parser
);
7940 if (c_parser_next_token_is (parser
, CPP_LESS
))
7941 proto
= c_parser_objc_protocol_refs (parser
);
7942 parser
->objc_pq_context
= true;
7943 objc_start_protocol (id
, proto
, attributes
);
7944 c_parser_objc_methodprotolist (parser
);
7945 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7946 parser
->objc_pq_context
= false;
7947 objc_finish_interface ();
7951 /* Parse an objc-method-type.
7957 Return true if it is a class method (+) and false if it is
7958 an instance method (-).
7961 c_parser_objc_method_type (c_parser
*parser
)
7963 switch (c_parser_peek_token (parser
)->type
)
7966 c_parser_consume_token (parser
);
7969 c_parser_consume_token (parser
);
7976 /* Parse an objc-method-definition.
7978 objc-method-definition:
7979 objc-method-type objc-method-decl ;[opt] compound-statement
7983 c_parser_objc_method_definition (c_parser
*parser
)
7985 bool is_class_method
= c_parser_objc_method_type (parser
);
7986 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7987 parser
->objc_pq_context
= true;
7988 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7990 if (decl
== error_mark_node
)
7991 return; /* Bail here. */
7993 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7995 c_parser_consume_token (parser
);
7996 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7997 "extra semicolon in method definition specified");
8000 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8002 c_parser_error (parser
, "expected %<{%>");
8006 parser
->objc_pq_context
= false;
8007 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8009 add_stmt (c_parser_compound_statement (parser
));
8010 objc_finish_method_definition (current_function_decl
);
8014 /* This code is executed when we find a method definition
8015 outside of an @implementation context (or invalid for other
8016 reasons). Parse the method (to keep going) but do not emit
8019 c_parser_compound_statement (parser
);
8023 /* Parse an objc-methodprotolist.
8025 objc-methodprotolist:
8027 objc-methodprotolist objc-methodproto
8028 objc-methodprotolist declaration
8029 objc-methodprotolist ;
8033 The declaration is a data definition, which may be missing
8034 declaration specifiers under the same rules and diagnostics as
8035 other data definitions outside functions, and the stray semicolon
8036 is diagnosed the same way as a stray semicolon outside a
8040 c_parser_objc_methodprotolist (c_parser
*parser
)
8044 /* The list is terminated by @end. */
8045 switch (c_parser_peek_token (parser
)->type
)
8048 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8049 "ISO C does not allow extra %<;%> outside of a function");
8050 c_parser_consume_token (parser
);
8054 c_parser_objc_methodproto (parser
);
8057 c_parser_pragma (parser
, pragma_external
);
8062 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8064 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8065 c_parser_objc_at_property_declaration (parser
);
8066 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8068 objc_set_method_opt (true);
8069 c_parser_consume_token (parser
);
8071 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8073 objc_set_method_opt (false);
8074 c_parser_consume_token (parser
);
8077 c_parser_declaration_or_fndef (parser
, false, false, true,
8078 false, true, NULL
, vNULL
);
8084 /* Parse an objc-methodproto.
8087 objc-method-type objc-method-decl ;
8091 c_parser_objc_methodproto (c_parser
*parser
)
8093 bool is_class_method
= c_parser_objc_method_type (parser
);
8094 tree decl
, attributes
= NULL_TREE
;
8096 /* Remember protocol qualifiers in prototypes. */
8097 parser
->objc_pq_context
= true;
8098 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8100 /* Forget protocol qualifiers now. */
8101 parser
->objc_pq_context
= false;
8103 /* Do not allow the presence of attributes to hide an erroneous
8104 method implementation in the interface section. */
8105 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8107 c_parser_error (parser
, "expected %<;%>");
8111 if (decl
!= error_mark_node
)
8112 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8114 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8117 /* If we are at a position that method attributes may be present, check that
8118 there are not any parsed already (a syntax error) and then collect any
8119 specified at the current location. Finally, if new attributes were present,
8120 check that the next token is legal ( ';' for decls and '{' for defs). */
8123 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8128 c_parser_error (parser
,
8129 "method attributes must be specified at the end only");
8130 *attributes
= NULL_TREE
;
8134 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8135 *attributes
= c_parser_attributes (parser
);
8137 /* If there were no attributes here, just report any earlier error. */
8138 if (*attributes
== NULL_TREE
|| bad
)
8141 /* If the attributes are followed by a ; or {, then just report any earlier
8143 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8144 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8147 /* We've got attributes, but not at the end. */
8148 c_parser_error (parser
,
8149 "expected %<;%> or %<{%> after method attribute definition");
8153 /* Parse an objc-method-decl.
8156 ( objc-type-name ) objc-selector
8158 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8159 objc-keyword-selector objc-optparmlist
8162 objc-keyword-selector:
8164 objc-keyword-selector objc-keyword-decl
8167 objc-selector : ( objc-type-name ) identifier
8168 objc-selector : identifier
8169 : ( objc-type-name ) identifier
8173 objc-optparms objc-optellipsis
8177 objc-opt-parms , parameter-declaration
8185 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8186 tree
*attributes
, tree
*expr
)
8188 tree type
= NULL_TREE
;
8190 tree parms
= NULL_TREE
;
8191 bool ellipsis
= false;
8192 bool attr_err
= false;
8194 *attributes
= NULL_TREE
;
8195 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8197 c_parser_consume_token (parser
);
8198 type
= c_parser_objc_type_name (parser
);
8199 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8201 sel
= c_parser_objc_selector (parser
);
8202 /* If there is no selector, or a colon follows, we have an
8203 objc-keyword-selector. If there is a selector, and a colon does
8204 not follow, that selector ends the objc-method-decl. */
8205 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8208 tree list
= NULL_TREE
;
8211 tree atype
= NULL_TREE
, id
, keyworddecl
;
8212 tree param_attr
= NULL_TREE
;
8213 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8215 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8217 c_parser_consume_token (parser
);
8218 atype
= c_parser_objc_type_name (parser
);
8219 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8222 /* New ObjC allows attributes on method parameters. */
8223 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8224 param_attr
= c_parser_attributes (parser
);
8225 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8227 c_parser_error (parser
, "expected identifier");
8228 return error_mark_node
;
8230 id
= c_parser_peek_token (parser
)->value
;
8231 c_parser_consume_token (parser
);
8232 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8233 list
= chainon (list
, keyworddecl
);
8234 tsel
= c_parser_objc_selector (parser
);
8235 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8239 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8241 /* Parse the optional parameter list. Optional Objective-C
8242 method parameters follow the C syntax, and may include '...'
8243 to denote a variable number of arguments. */
8244 parms
= make_node (TREE_LIST
);
8245 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8247 struct c_parm
*parm
;
8248 c_parser_consume_token (parser
);
8249 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8252 c_parser_consume_token (parser
);
8253 attr_err
|= c_parser_objc_maybe_method_attributes
8254 (parser
, attributes
) ;
8257 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8260 parms
= chainon (parms
,
8261 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8266 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8270 c_parser_error (parser
, "objective-c method declaration is expected");
8271 return error_mark_node
;
8275 return error_mark_node
;
8277 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8280 /* Parse an objc-type-name.
8283 objc-type-qualifiers[opt] type-name
8284 objc-type-qualifiers[opt]
8286 objc-type-qualifiers:
8288 objc-type-qualifiers objc-type-qualifier
8290 objc-type-qualifier: one of
8291 in out inout bycopy byref oneway
8295 c_parser_objc_type_name (c_parser
*parser
)
8297 tree quals
= NULL_TREE
;
8298 struct c_type_name
*type_name
= NULL
;
8299 tree type
= NULL_TREE
;
8302 c_token
*token
= c_parser_peek_token (parser
);
8303 if (token
->type
== CPP_KEYWORD
8304 && (token
->keyword
== RID_IN
8305 || token
->keyword
== RID_OUT
8306 || token
->keyword
== RID_INOUT
8307 || token
->keyword
== RID_BYCOPY
8308 || token
->keyword
== RID_BYREF
8309 || token
->keyword
== RID_ONEWAY
))
8311 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8312 c_parser_consume_token (parser
);
8317 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8318 type_name
= c_parser_type_name (parser
);
8320 type
= groktypename (type_name
, NULL
, NULL
);
8322 /* If the type is unknown, and error has already been produced and
8323 we need to recover from the error. In that case, use NULL_TREE
8324 for the type, as if no type had been specified; this will use the
8325 default type ('id') which is good for error recovery. */
8326 if (type
== error_mark_node
)
8329 return build_tree_list (quals
, type
);
8332 /* Parse objc-protocol-refs.
8339 c_parser_objc_protocol_refs (c_parser
*parser
)
8341 tree list
= NULL_TREE
;
8342 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8343 c_parser_consume_token (parser
);
8344 /* Any identifiers, including those declared as type names, are OK
8349 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8351 c_parser_error (parser
, "expected identifier");
8354 id
= c_parser_peek_token (parser
)->value
;
8355 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8356 c_parser_consume_token (parser
);
8357 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8358 c_parser_consume_token (parser
);
8362 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8366 /* Parse an objc-try-catch-finally-statement.
8368 objc-try-catch-finally-statement:
8369 @try compound-statement objc-catch-list[opt]
8370 @try compound-statement objc-catch-list[opt] @finally compound-statement
8373 @catch ( objc-catch-parameter-declaration ) compound-statement
8374 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8376 objc-catch-parameter-declaration:
8377 parameter-declaration
8380 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8382 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8383 for C++. Keep them in sync. */
8386 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8388 location_t location
;
8391 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8392 c_parser_consume_token (parser
);
8393 location
= c_parser_peek_token (parser
)->location
;
8394 objc_maybe_warn_exceptions (location
);
8395 stmt
= c_parser_compound_statement (parser
);
8396 objc_begin_try_stmt (location
, stmt
);
8398 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8400 struct c_parm
*parm
;
8401 tree parameter_declaration
= error_mark_node
;
8402 bool seen_open_paren
= false;
8404 c_parser_consume_token (parser
);
8405 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8406 seen_open_paren
= true;
8407 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8409 /* We have "@catch (...)" (where the '...' are literally
8410 what is in the code). Skip the '...'.
8411 parameter_declaration is set to NULL_TREE, and
8412 objc_being_catch_clauses() knows that that means
8414 c_parser_consume_token (parser
);
8415 parameter_declaration
= NULL_TREE
;
8419 /* We have "@catch (NSException *exception)" or something
8420 like that. Parse the parameter declaration. */
8421 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8423 parameter_declaration
= error_mark_node
;
8425 parameter_declaration
= grokparm (parm
, NULL
);
8427 if (seen_open_paren
)
8428 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8431 /* If there was no open parenthesis, we are recovering from
8432 an error, and we are trying to figure out what mistake
8433 the user has made. */
8435 /* If there is an immediate closing parenthesis, the user
8436 probably forgot the opening one (ie, they typed "@catch
8437 NSException *e)". Parse the closing parenthesis and keep
8439 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8440 c_parser_consume_token (parser
);
8442 /* If these is no immediate closing parenthesis, the user
8443 probably doesn't know that parenthesis are required at
8444 all (ie, they typed "@catch NSException *e"). So, just
8445 forget about the closing parenthesis and keep going. */
8447 objc_begin_catch_clause (parameter_declaration
);
8448 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8449 c_parser_compound_statement_nostart (parser
);
8450 objc_finish_catch_clause ();
8452 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8454 c_parser_consume_token (parser
);
8455 location
= c_parser_peek_token (parser
)->location
;
8456 stmt
= c_parser_compound_statement (parser
);
8457 objc_build_finally_clause (location
, stmt
);
8459 objc_finish_try_stmt ();
8462 /* Parse an objc-synchronized-statement.
8464 objc-synchronized-statement:
8465 @synchronized ( expression ) compound-statement
8469 c_parser_objc_synchronized_statement (c_parser
*parser
)
8473 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8474 c_parser_consume_token (parser
);
8475 loc
= c_parser_peek_token (parser
)->location
;
8476 objc_maybe_warn_exceptions (loc
);
8477 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8479 expr
= c_parser_expression (parser
).value
;
8480 expr
= c_fully_fold (expr
, false, NULL
);
8481 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8484 expr
= error_mark_node
;
8485 stmt
= c_parser_compound_statement (parser
);
8486 objc_build_synchronized (loc
, expr
, stmt
);
8489 /* Parse an objc-selector; return NULL_TREE without an error if the
8490 next token is not an objc-selector.
8495 enum struct union if else while do for switch case default
8496 break continue return goto asm sizeof typeof __alignof
8497 unsigned long const short volatile signed restrict _Complex
8498 in out inout bycopy byref oneway int char float double void _Bool
8500 ??? Why this selection of keywords but not, for example, storage
8501 class specifiers? */
8504 c_parser_objc_selector (c_parser
*parser
)
8506 c_token
*token
= c_parser_peek_token (parser
);
8507 tree value
= token
->value
;
8508 if (token
->type
== CPP_NAME
)
8510 c_parser_consume_token (parser
);
8513 if (token
->type
!= CPP_KEYWORD
)
8515 switch (token
->keyword
)
8557 c_parser_consume_token (parser
);
8564 /* Parse an objc-selector-arg.
8568 objc-keywordname-list
8570 objc-keywordname-list:
8572 objc-keywordname-list objc-keywordname
8580 c_parser_objc_selector_arg (c_parser
*parser
)
8582 tree sel
= c_parser_objc_selector (parser
);
8583 tree list
= NULL_TREE
;
8584 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8588 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8590 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8591 sel
= c_parser_objc_selector (parser
);
8592 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8598 /* Parse an objc-receiver.
8607 c_parser_objc_receiver (c_parser
*parser
)
8609 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8610 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8611 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8613 tree id
= c_parser_peek_token (parser
)->value
;
8614 c_parser_consume_token (parser
);
8615 return objc_get_class_reference (id
);
8617 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8620 /* Parse objc-message-args.
8624 objc-keywordarg-list
8626 objc-keywordarg-list:
8628 objc-keywordarg-list objc-keywordarg
8631 objc-selector : objc-keywordexpr
8636 c_parser_objc_message_args (c_parser
*parser
)
8638 tree sel
= c_parser_objc_selector (parser
);
8639 tree list
= NULL_TREE
;
8640 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8645 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8646 return error_mark_node
;
8647 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8648 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8649 sel
= c_parser_objc_selector (parser
);
8650 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8656 /* Parse an objc-keywordexpr.
8663 c_parser_objc_keywordexpr (c_parser
*parser
)
8666 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8668 if (vec_safe_length (expr_list
) == 1)
8670 /* Just return the expression, remove a level of
8672 ret
= (*expr_list
)[0];
8676 /* We have a comma expression, we will collapse later. */
8677 ret
= build_tree_list_vec (expr_list
);
8679 release_tree_vector (expr_list
);
8683 /* A check, needed in several places, that ObjC interface, implementation or
8684 method definitions are not prefixed by incorrect items. */
8686 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8687 struct c_declspecs
*specs
)
8689 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8690 || specs
->typespec_kind
!= ctsk_none
)
8692 c_parser_error (parser
,
8693 "no type or storage class may be specified here,");
8694 c_parser_skip_to_end_of_block_or_statement (parser
);
8700 /* Parse an Objective-C @property declaration. The syntax is:
8702 objc-property-declaration:
8703 '@property' objc-property-attributes[opt] struct-declaration ;
8705 objc-property-attributes:
8706 '(' objc-property-attribute-list ')'
8708 objc-property-attribute-list:
8709 objc-property-attribute
8710 objc-property-attribute-list, objc-property-attribute
8712 objc-property-attribute
8713 'getter' = identifier
8714 'setter' = identifier
8723 @property NSString *name;
8724 @property (readonly) id object;
8725 @property (retain, nonatomic, getter=getTheName) id name;
8726 @property int a, b, c;
8728 PS: This function is identical to cp_parser_objc_at_propery_declaration
8729 for C++. Keep them in sync. */
8731 c_parser_objc_at_property_declaration (c_parser
*parser
)
8733 /* The following variables hold the attributes of the properties as
8734 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8735 seen. When we see an attribute, we set them to 'true' (if they
8736 are boolean properties) or to the identifier (if they have an
8737 argument, ie, for getter and setter). Note that here we only
8738 parse the list of attributes, check the syntax and accumulate the
8739 attributes that we find. objc_add_property_declaration() will
8740 then process the information. */
8741 bool property_assign
= false;
8742 bool property_copy
= false;
8743 tree property_getter_ident
= NULL_TREE
;
8744 bool property_nonatomic
= false;
8745 bool property_readonly
= false;
8746 bool property_readwrite
= false;
8747 bool property_retain
= false;
8748 tree property_setter_ident
= NULL_TREE
;
8750 /* 'properties' is the list of properties that we read. Usually a
8751 single one, but maybe more (eg, in "@property int a, b, c;" there
8756 loc
= c_parser_peek_token (parser
)->location
;
8757 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8759 c_parser_consume_token (parser
); /* Eat '@property'. */
8761 /* Parse the optional attribute list... */
8762 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8765 c_parser_consume_token (parser
);
8767 /* Property attribute keywords are valid now. */
8768 parser
->objc_property_attr_context
= true;
8772 bool syntax_error
= false;
8773 c_token
*token
= c_parser_peek_token (parser
);
8776 if (token
->type
!= CPP_KEYWORD
)
8778 if (token
->type
== CPP_CLOSE_PAREN
)
8779 c_parser_error (parser
, "expected identifier");
8782 c_parser_consume_token (parser
);
8783 c_parser_error (parser
, "unknown property attribute");
8787 keyword
= token
->keyword
;
8788 c_parser_consume_token (parser
);
8791 case RID_ASSIGN
: property_assign
= true; break;
8792 case RID_COPY
: property_copy
= true; break;
8793 case RID_NONATOMIC
: property_nonatomic
= true; break;
8794 case RID_READONLY
: property_readonly
= true; break;
8795 case RID_READWRITE
: property_readwrite
= true; break;
8796 case RID_RETAIN
: property_retain
= true; break;
8800 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8802 if (keyword
== RID_GETTER
)
8803 c_parser_error (parser
,
8804 "missing %<=%> (after %<getter%> attribute)");
8806 c_parser_error (parser
,
8807 "missing %<=%> (after %<setter%> attribute)");
8808 syntax_error
= true;
8811 c_parser_consume_token (parser
); /* eat the = */
8812 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8814 c_parser_error (parser
, "expected identifier");
8815 syntax_error
= true;
8818 if (keyword
== RID_SETTER
)
8820 if (property_setter_ident
!= NULL_TREE
)
8821 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8823 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8824 c_parser_consume_token (parser
);
8825 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8826 c_parser_error (parser
, "setter name must terminate with %<:%>");
8828 c_parser_consume_token (parser
);
8832 if (property_getter_ident
!= NULL_TREE
)
8833 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8835 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8836 c_parser_consume_token (parser
);
8840 c_parser_error (parser
, "unknown property attribute");
8841 syntax_error
= true;
8848 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8849 c_parser_consume_token (parser
);
8853 parser
->objc_property_attr_context
= false;
8854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8856 /* ... and the property declaration(s). */
8857 properties
= c_parser_struct_declaration (parser
);
8859 if (properties
== error_mark_node
)
8861 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8862 parser
->error
= false;
8866 if (properties
== NULL_TREE
)
8867 c_parser_error (parser
, "expected identifier");
8870 /* Comma-separated properties are chained together in
8871 reverse order; add them one by one. */
8872 properties
= nreverse (properties
);
8874 for (; properties
; properties
= TREE_CHAIN (properties
))
8875 objc_add_property_declaration (loc
, copy_node (properties
),
8876 property_readonly
, property_readwrite
,
8877 property_assign
, property_retain
,
8878 property_copy
, property_nonatomic
,
8879 property_getter_ident
, property_setter_ident
);
8882 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8883 parser
->error
= false;
8886 /* Parse an Objective-C @synthesize declaration. The syntax is:
8888 objc-synthesize-declaration:
8889 @synthesize objc-synthesize-identifier-list ;
8891 objc-synthesize-identifier-list:
8892 objc-synthesize-identifier
8893 objc-synthesize-identifier-list, objc-synthesize-identifier
8895 objc-synthesize-identifier
8897 identifier = identifier
8900 @synthesize MyProperty;
8901 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8903 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8904 for C++. Keep them in sync.
8907 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8909 tree list
= NULL_TREE
;
8911 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8912 loc
= c_parser_peek_token (parser
)->location
;
8914 c_parser_consume_token (parser
);
8917 tree property
, ivar
;
8918 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8920 c_parser_error (parser
, "expected identifier");
8921 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8922 /* Once we find the semicolon, we can resume normal parsing.
8923 We have to reset parser->error manually because
8924 c_parser_skip_until_found() won't reset it for us if the
8925 next token is precisely a semicolon. */
8926 parser
->error
= false;
8929 property
= c_parser_peek_token (parser
)->value
;
8930 c_parser_consume_token (parser
);
8931 if (c_parser_next_token_is (parser
, CPP_EQ
))
8933 c_parser_consume_token (parser
);
8934 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8936 c_parser_error (parser
, "expected identifier");
8937 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8938 parser
->error
= false;
8941 ivar
= c_parser_peek_token (parser
)->value
;
8942 c_parser_consume_token (parser
);
8946 list
= chainon (list
, build_tree_list (ivar
, property
));
8947 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8948 c_parser_consume_token (parser
);
8952 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8953 objc_add_synthesize_declaration (loc
, list
);
8956 /* Parse an Objective-C @dynamic declaration. The syntax is:
8958 objc-dynamic-declaration:
8959 @dynamic identifier-list ;
8962 @dynamic MyProperty;
8963 @dynamic MyProperty, AnotherProperty;
8965 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8966 for C++. Keep them in sync.
8969 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8971 tree list
= NULL_TREE
;
8973 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8974 loc
= c_parser_peek_token (parser
)->location
;
8976 c_parser_consume_token (parser
);
8980 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8982 c_parser_error (parser
, "expected identifier");
8983 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8984 parser
->error
= false;
8987 property
= c_parser_peek_token (parser
)->value
;
8988 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8989 c_parser_consume_token (parser
);
8990 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8991 c_parser_consume_token (parser
);
8995 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8996 objc_add_dynamic_declaration (loc
, list
);
9000 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9001 should be considered, statements. ALLOW_STMT is true if we're within
9002 the context of a function and such pragmas are to be allowed. Returns
9003 true if we actually parsed such a pragma. */
9006 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9010 id
= c_parser_peek_token (parser
)->pragma_kind
;
9011 gcc_assert (id
!= PRAGMA_NONE
);
9015 case PRAGMA_OMP_BARRIER
:
9016 if (context
!= pragma_compound
)
9018 if (context
== pragma_stmt
)
9019 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9020 "used in compound statements");
9023 c_parser_omp_barrier (parser
);
9026 case PRAGMA_OMP_FLUSH
:
9027 if (context
!= pragma_compound
)
9029 if (context
== pragma_stmt
)
9030 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9031 "used in compound statements");
9034 c_parser_omp_flush (parser
);
9037 case PRAGMA_OMP_TASKWAIT
:
9038 if (context
!= pragma_compound
)
9040 if (context
== pragma_stmt
)
9041 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9042 "used in compound statements");
9045 c_parser_omp_taskwait (parser
);
9048 case PRAGMA_OMP_TASKYIELD
:
9049 if (context
!= pragma_compound
)
9051 if (context
== pragma_stmt
)
9052 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9053 "used in compound statements");
9056 c_parser_omp_taskyield (parser
);
9059 case PRAGMA_OMP_CANCEL
:
9060 if (context
!= pragma_compound
)
9062 if (context
== pragma_stmt
)
9063 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9064 "used in compound statements");
9067 c_parser_omp_cancel (parser
);
9070 case PRAGMA_OMP_CANCELLATION_POINT
:
9071 if (context
!= pragma_compound
)
9073 if (context
== pragma_stmt
)
9074 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9075 "only be used in compound statements");
9078 c_parser_omp_cancellation_point (parser
);
9081 case PRAGMA_OMP_THREADPRIVATE
:
9082 c_parser_omp_threadprivate (parser
);
9085 case PRAGMA_OMP_TARGET
:
9086 return c_parser_omp_target (parser
, context
);
9088 case PRAGMA_OMP_END_DECLARE_TARGET
:
9089 c_parser_omp_end_declare_target (parser
);
9092 case PRAGMA_OMP_SECTION
:
9093 error_at (c_parser_peek_token (parser
)->location
,
9094 "%<#pragma omp section%> may only be used in "
9095 "%<#pragma omp sections%> construct");
9096 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9099 case PRAGMA_OMP_DECLARE_REDUCTION
:
9100 c_parser_omp_declare (parser
, context
);
9103 c_parser_consume_pragma (parser
);
9104 c_parser_skip_to_pragma_eol (parser
);
9105 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
9107 c_parser_error (parser
, "for statement expected");
9110 c_parser_for_statement (parser
, true);
9113 case PRAGMA_GCC_PCH_PREPROCESS
:
9114 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9115 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9119 if (id
< PRAGMA_FIRST_EXTERNAL
)
9121 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9124 c_parser_error (parser
, "expected declaration specifiers");
9125 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9128 c_parser_omp_construct (parser
);
9134 c_parser_consume_pragma (parser
);
9135 c_invoke_pragma_handler (id
);
9137 /* Skip to EOL, but suppress any error message. Those will have been
9138 generated by the handler routine through calling error, as opposed
9139 to calling c_parser_error. */
9140 parser
->error
= true;
9141 c_parser_skip_to_pragma_eol (parser
);
9146 /* The interface the pragma parsers have to the lexer. */
9149 pragma_lex (tree
*value
)
9151 c_token
*tok
= c_parser_peek_token (the_parser
);
9152 enum cpp_ttype ret
= tok
->type
;
9154 *value
= tok
->value
;
9155 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9159 if (ret
== CPP_KEYWORD
)
9161 c_parser_consume_token (the_parser
);
9168 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9172 c_parser_consume_pragma (parser
);
9173 if (c_parser_next_token_is (parser
, CPP_STRING
))
9175 name
= c_parser_peek_token (parser
)->value
;
9176 c_parser_consume_token (parser
);
9179 c_parser_error (parser
, "expected string literal");
9180 c_parser_skip_to_pragma_eol (parser
);
9183 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9186 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9188 /* Returns name of the next clause.
9189 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9190 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9191 returned and the token is consumed. */
9193 static pragma_omp_clause
9194 c_parser_omp_clause_name (c_parser
*parser
)
9196 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9198 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9199 result
= PRAGMA_OMP_CLAUSE_IF
;
9200 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9201 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9202 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9203 result
= PRAGMA_OMP_CLAUSE_FOR
;
9204 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9206 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9211 if (!strcmp ("aligned", p
))
9212 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9215 if (!strcmp ("collapse", p
))
9216 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9217 else if (!strcmp ("copyin", p
))
9218 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9219 else if (!strcmp ("copyprivate", p
))
9220 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9223 if (!strcmp ("depend", p
))
9224 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9225 else if (!strcmp ("device", p
))
9226 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9227 else if (!strcmp ("dist_schedule", p
))
9228 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9231 if (!strcmp ("final", p
))
9232 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9233 else if (!strcmp ("firstprivate", p
))
9234 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9235 else if (!strcmp ("from", p
))
9236 result
= PRAGMA_OMP_CLAUSE_FROM
;
9239 if (!strcmp ("inbranch", p
))
9240 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9243 if (!strcmp ("lastprivate", p
))
9244 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9245 else if (!strcmp ("linear", p
))
9246 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9249 if (!strcmp ("map", p
))
9250 result
= PRAGMA_OMP_CLAUSE_MAP
;
9251 else if (!strcmp ("mergeable", p
))
9252 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9255 if (!strcmp ("notinbranch", p
))
9256 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9257 else if (!strcmp ("nowait", p
))
9258 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9259 else if (!strcmp ("num_teams", p
))
9260 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9261 else if (!strcmp ("num_threads", p
))
9262 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9265 if (!strcmp ("ordered", p
))
9266 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9269 if (!strcmp ("parallel", p
))
9270 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9271 else if (!strcmp ("private", p
))
9272 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9273 else if (!strcmp ("proc_bind", p
))
9274 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9277 if (!strcmp ("reduction", p
))
9278 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9281 if (!strcmp ("safelen", p
))
9282 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9283 else if (!strcmp ("schedule", p
))
9284 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9285 else if (!strcmp ("sections", p
))
9286 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9287 else if (!strcmp ("shared", p
))
9288 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9289 else if (!strcmp ("simdlen", p
))
9290 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9293 if (!strcmp ("taskgroup", p
))
9294 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9295 else if (!strcmp ("thread_limit", p
))
9296 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9297 else if (!strcmp ("to", p
))
9298 result
= PRAGMA_OMP_CLAUSE_TO
;
9301 if (!strcmp ("uniform", p
))
9302 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9303 else if (!strcmp ("untied", p
))
9304 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9309 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9310 c_parser_consume_token (parser
);
9315 /* Validate that a clause of the given type does not already exist. */
9318 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9323 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9324 if (OMP_CLAUSE_CODE (c
) == code
)
9326 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9327 error_at (loc
, "too many %qs clauses", name
);
9335 variable-list , identifier
9337 If KIND is nonzero, create the appropriate node and install the
9338 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9339 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9341 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9342 return the list created. */
9345 c_parser_omp_variable_list (c_parser
*parser
,
9346 location_t clause_loc
,
9347 enum omp_clause_code kind
, tree list
)
9349 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9350 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9351 c_parser_error (parser
, "expected identifier");
9353 while (c_parser_next_token_is (parser
, CPP_NAME
)
9354 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9356 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9360 undeclared_variable (c_parser_peek_token (parser
)->location
,
9361 c_parser_peek_token (parser
)->value
);
9362 t
= error_mark_node
;
9365 c_parser_consume_token (parser
);
9367 if (t
== error_mark_node
)
9373 case OMP_CLAUSE_MAP
:
9374 case OMP_CLAUSE_FROM
:
9376 case OMP_CLAUSE_DEPEND
:
9377 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9379 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9381 c_parser_consume_token (parser
);
9382 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9383 low_bound
= c_parser_expression (parser
).value
;
9384 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9385 length
= integer_one_node
;
9389 if (!c_parser_require (parser
, CPP_COLON
,
9392 t
= error_mark_node
;
9395 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9396 length
= c_parser_expression (parser
).value
;
9398 /* Look for the closing `]'. */
9399 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9402 t
= error_mark_node
;
9405 t
= tree_cons (low_bound
, length
, t
);
9412 if (t
!= error_mark_node
)
9414 tree u
= build_omp_clause (clause_loc
, kind
);
9415 OMP_CLAUSE_DECL (u
) = t
;
9416 OMP_CLAUSE_CHAIN (u
) = list
;
9421 list
= tree_cons (t
, NULL_TREE
, list
);
9423 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9426 c_parser_consume_token (parser
);
9432 /* Similarly, but expect leading and trailing parenthesis. This is a very
9433 common case for omp clauses. */
9436 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9439 /* The clauses location. */
9440 location_t loc
= c_parser_peek_token (parser
)->location
;
9442 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9444 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9445 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9451 collapse ( constant-expression ) */
9454 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9456 tree c
, num
= error_mark_node
;
9460 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9462 loc
= c_parser_peek_token (parser
)->location
;
9463 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9465 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9466 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9468 if (num
== error_mark_node
)
9470 mark_exp_read (num
);
9471 num
= c_fully_fold (num
, false, NULL
);
9472 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9473 || !host_integerp (num
, 0)
9474 || (n
= tree_low_cst (num
, 0)) <= 0
9478 "collapse argument needs positive constant integer expression");
9481 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9482 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9483 OMP_CLAUSE_CHAIN (c
) = list
;
9488 copyin ( variable-list ) */
9491 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9493 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9497 copyprivate ( variable-list ) */
9500 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9502 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9506 default ( shared | none ) */
9509 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9511 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9512 location_t loc
= c_parser_peek_token (parser
)->location
;
9515 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9517 if (c_parser_next_token_is (parser
, CPP_NAME
))
9519 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9524 if (strcmp ("none", p
) != 0)
9526 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9530 if (strcmp ("shared", p
) != 0)
9532 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9539 c_parser_consume_token (parser
);
9544 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9546 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9548 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9551 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9552 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9553 OMP_CLAUSE_CHAIN (c
) = list
;
9554 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9560 firstprivate ( variable-list ) */
9563 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9565 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9569 final ( expression ) */
9572 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9574 location_t loc
= c_parser_peek_token (parser
)->location
;
9575 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9577 tree t
= c_parser_paren_condition (parser
);
9580 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9582 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9583 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9584 OMP_CLAUSE_CHAIN (c
) = list
;
9588 c_parser_error (parser
, "expected %<(%>");
9594 if ( expression ) */
9597 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9599 location_t loc
= c_parser_peek_token (parser
)->location
;
9600 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9602 tree t
= c_parser_paren_condition (parser
);
9605 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9607 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9608 OMP_CLAUSE_IF_EXPR (c
) = t
;
9609 OMP_CLAUSE_CHAIN (c
) = list
;
9613 c_parser_error (parser
, "expected %<(%>");
9619 lastprivate ( variable-list ) */
9622 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9624 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9631 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9635 /* FIXME: Should we allow duplicates? */
9636 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9638 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9639 OMP_CLAUSE_MERGEABLE
);
9640 OMP_CLAUSE_CHAIN (c
) = list
;
9649 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9652 location_t loc
= c_parser_peek_token (parser
)->location
;
9654 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9656 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9657 OMP_CLAUSE_CHAIN (c
) = list
;
9662 num_threads ( expression ) */
9665 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9667 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9668 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9670 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9671 tree c
, t
= c_parser_expression (parser
).value
;
9673 t
= c_fully_fold (t
, false, NULL
);
9675 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9677 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9679 c_parser_error (parser
, "expected integer expression");
9683 /* Attempt to statically determine when the number isn't positive. */
9684 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9685 build_int_cst (TREE_TYPE (t
), 0));
9686 if (CAN_HAVE_LOCATION_P (c
))
9687 SET_EXPR_LOCATION (c
, expr_loc
);
9688 if (c
== boolean_true_node
)
9690 warning_at (expr_loc
, 0,
9691 "%<num_threads%> value must be positive");
9692 t
= integer_one_node
;
9695 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9697 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9698 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9699 OMP_CLAUSE_CHAIN (c
) = list
;
9710 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9714 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9716 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9717 OMP_CLAUSE_ORDERED
);
9718 OMP_CLAUSE_CHAIN (c
) = list
;
9724 private ( variable-list ) */
9727 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9729 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9733 reduction ( reduction-operator : variable-list )
9736 One of: + * - & ^ | && ||
9741 One of: + * - & ^ | && || max min
9746 One of: + * - & ^ | && ||
9750 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9752 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9753 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9755 enum tree_code code
= ERROR_MARK
;
9756 tree reduc_id
= NULL_TREE
;
9758 switch (c_parser_peek_token (parser
)->type
)
9770 code
= BIT_AND_EXPR
;
9773 code
= BIT_XOR_EXPR
;
9776 code
= BIT_IOR_EXPR
;
9779 code
= TRUTH_ANDIF_EXPR
;
9782 code
= TRUTH_ORIF_EXPR
;
9787 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9788 if (strcmp (p
, "min") == 0)
9793 if (strcmp (p
, "max") == 0)
9798 reduc_id
= c_parser_peek_token (parser
)->value
;
9802 c_parser_error (parser
,
9803 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9804 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9805 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9808 c_parser_consume_token (parser
);
9809 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
9810 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9814 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9815 OMP_CLAUSE_REDUCTION
, list
);
9816 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9818 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
9819 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9820 if (code
== ERROR_MARK
9821 || !(INTEGRAL_TYPE_P (type
)
9822 || TREE_CODE (type
) == REAL_TYPE
9823 || TREE_CODE (type
) == COMPLEX_TYPE
))
9824 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
9825 = c_omp_reduction_lookup (reduc_id
,
9826 TYPE_MAIN_VARIANT (type
));
9831 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9837 schedule ( schedule-kind )
9838 schedule ( schedule-kind , expression )
9841 static | dynamic | guided | runtime | auto
9845 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9848 location_t loc
= c_parser_peek_token (parser
)->location
;
9850 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9853 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9855 if (c_parser_next_token_is (parser
, CPP_NAME
))
9857 tree kind
= c_parser_peek_token (parser
)->value
;
9858 const char *p
= IDENTIFIER_POINTER (kind
);
9863 if (strcmp ("dynamic", p
) != 0)
9865 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9869 if (strcmp ("guided", p
) != 0)
9871 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9875 if (strcmp ("runtime", p
) != 0)
9877 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9884 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9885 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9886 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9887 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9891 c_parser_consume_token (parser
);
9892 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9895 c_parser_consume_token (parser
);
9897 here
= c_parser_peek_token (parser
)->location
;
9898 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9900 t
= c_fully_fold (t
, false, NULL
);
9902 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9903 error_at (here
, "schedule %<runtime%> does not take "
9904 "a %<chunk_size%> parameter");
9905 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9907 "schedule %<auto%> does not take "
9908 "a %<chunk_size%> parameter");
9909 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9910 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9912 c_parser_error (parser
, "expected integer expression");
9914 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9917 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9918 "expected %<,%> or %<)%>");
9920 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9921 OMP_CLAUSE_CHAIN (c
) = list
;
9925 c_parser_error (parser
, "invalid schedule kind");
9926 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9931 shared ( variable-list ) */
9934 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9936 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9943 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9947 /* FIXME: Should we allow duplicates? */
9948 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9950 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9952 OMP_CLAUSE_CHAIN (c
) = list
;
9962 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
9963 enum omp_clause_code code
, tree list
)
9965 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
9967 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
9968 OMP_CLAUSE_CHAIN (c
) = list
;
9980 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
9981 enum omp_clause_code code
, tree list
)
9983 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
9984 OMP_CLAUSE_CHAIN (c
) = list
;
9990 num_teams ( expression ) */
9993 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
9995 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
9996 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9998 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9999 tree c
, t
= c_parser_expression (parser
).value
;
10001 t
= c_fully_fold (t
, false, NULL
);
10003 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10005 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10007 c_parser_error (parser
, "expected integer expression");
10011 /* Attempt to statically determine when the number isn't positive. */
10012 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10013 build_int_cst (TREE_TYPE (t
), 0));
10014 if (CAN_HAVE_LOCATION_P (c
))
10015 SET_EXPR_LOCATION (c
, expr_loc
);
10016 if (c
== boolean_true_node
)
10018 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10019 t
= integer_one_node
;
10022 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10024 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10025 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10026 OMP_CLAUSE_CHAIN (c
) = list
;
10034 thread_limit ( expression ) */
10037 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10039 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10040 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10042 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10043 tree c
, t
= c_parser_expression (parser
).value
;
10045 t
= c_fully_fold (t
, false, NULL
);
10047 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10049 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10051 c_parser_error (parser
, "expected integer expression");
10055 /* Attempt to statically determine when the number isn't positive. */
10056 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10057 build_int_cst (TREE_TYPE (t
), 0));
10058 if (CAN_HAVE_LOCATION_P (c
))
10059 SET_EXPR_LOCATION (c
, expr_loc
);
10060 if (c
== boolean_true_node
)
10062 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10063 t
= integer_one_node
;
10066 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10069 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10070 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10071 OMP_CLAUSE_CHAIN (c
) = list
;
10079 aligned ( variable-list )
10080 aligned ( variable-list : constant-expression ) */
10083 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10085 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10088 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10091 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10092 OMP_CLAUSE_ALIGNED
, list
);
10094 if (c_parser_next_token_is (parser
, CPP_COLON
))
10096 c_parser_consume_token (parser
);
10097 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10098 mark_exp_read (alignment
);
10099 alignment
= c_fully_fold (alignment
, false, NULL
);
10100 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10101 && TREE_CODE (alignment
) != INTEGER_CST
10102 && tree_int_cst_sgn (alignment
) != 1)
10104 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10105 "be positive constant integer expression");
10106 alignment
= NULL_TREE
;
10109 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10110 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10113 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10118 linear ( variable-list )
10119 linear ( variable-list : expression ) */
10122 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
10124 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10127 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10130 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10131 OMP_CLAUSE_LINEAR
, list
);
10133 if (c_parser_next_token_is (parser
, CPP_COLON
))
10135 c_parser_consume_token (parser
);
10136 step
= c_parser_expression (parser
).value
;
10137 mark_exp_read (step
);
10138 step
= c_fully_fold (step
, false, NULL
);
10139 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10141 error_at (clause_loc
, "%<linear%> clause step expression must "
10143 step
= integer_one_node
;
10148 step
= integer_one_node
;
10150 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10152 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10155 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10160 safelen ( constant-expression ) */
10163 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10165 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10168 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10171 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10173 t
= c_fully_fold (t
, false, NULL
);
10174 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10175 && TREE_CODE (t
) != INTEGER_CST
10176 && tree_int_cst_sgn (t
) != 1)
10178 error_at (clause_loc
, "%<safelen%> clause expression must "
10179 "be positive constant integer expression");
10183 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10184 if (t
== NULL_TREE
|| t
== error_mark_node
)
10187 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10189 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10190 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10191 OMP_CLAUSE_CHAIN (c
) = list
;
10196 simdlen ( constant-expression ) */
10199 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10201 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10204 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10207 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10209 t
= c_fully_fold (t
, false, NULL
);
10210 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10211 && TREE_CODE (t
) != INTEGER_CST
10212 && tree_int_cst_sgn (t
) != 1)
10214 error_at (clause_loc
, "%<simdlen%> clause expression must "
10215 "be positive constant integer expression");
10219 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10220 if (t
== NULL_TREE
|| t
== error_mark_node
)
10223 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10225 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10226 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10227 OMP_CLAUSE_CHAIN (c
) = list
;
10232 depend ( depend-kind: variable-list )
10235 in | out | inout */
10238 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10240 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10241 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10244 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10247 if (c_parser_next_token_is (parser
, CPP_NAME
))
10249 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10250 if (strcmp ("in", p
) == 0)
10251 kind
= OMP_CLAUSE_DEPEND_IN
;
10252 else if (strcmp ("inout", p
) == 0)
10253 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10254 else if (strcmp ("out", p
) == 0)
10255 kind
= OMP_CLAUSE_DEPEND_OUT
;
10262 c_parser_consume_token (parser
);
10263 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10266 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10267 OMP_CLAUSE_DEPEND
, list
);
10269 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10270 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10272 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10276 c_parser_error (parser
, "invalid depend kind");
10278 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10283 map ( map-kind: variable-list )
10284 map ( variable-list )
10287 alloc | to | from | tofrom */
10290 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10292 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10293 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10296 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10299 if (c_parser_next_token_is (parser
, CPP_NAME
)
10300 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10302 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10303 if (strcmp ("alloc", p
) == 0)
10304 kind
= OMP_CLAUSE_MAP_ALLOC
;
10305 else if (strcmp ("to", p
) == 0)
10306 kind
= OMP_CLAUSE_MAP_TO
;
10307 else if (strcmp ("from", p
) == 0)
10308 kind
= OMP_CLAUSE_MAP_FROM
;
10309 else if (strcmp ("tofrom", p
) == 0)
10310 kind
= OMP_CLAUSE_MAP_TOFROM
;
10313 c_parser_error (parser
, "invalid map kind");
10314 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10318 c_parser_consume_token (parser
);
10319 c_parser_consume_token (parser
);
10322 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10324 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10325 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10327 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10332 device ( expression ) */
10335 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10337 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10338 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10340 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10342 t
= c_fully_fold (t
, false, NULL
);
10344 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10346 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10348 c_parser_error (parser
, "expected integer expression");
10352 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10354 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10355 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10356 OMP_CLAUSE_CHAIN (c
) = list
;
10364 dist_schedule ( static )
10365 dist_schedule ( static , expression ) */
10368 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10370 tree c
, t
= NULL_TREE
;
10371 location_t loc
= c_parser_peek_token (parser
)->location
;
10373 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10376 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10378 c_parser_error (parser
, "invalid dist_schedule kind");
10379 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10384 c_parser_consume_token (parser
);
10385 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10387 c_parser_consume_token (parser
);
10389 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10391 t
= c_fully_fold (t
, false, NULL
);
10392 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10395 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10396 "expected %<,%> or %<)%>");
10398 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10399 if (t
== error_mark_node
)
10402 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10403 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10404 OMP_CLAUSE_CHAIN (c
) = list
;
10409 proc_bind ( proc-bind-kind )
10412 master | close | spread */
10415 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10417 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10418 enum omp_clause_proc_bind_kind kind
;
10421 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10424 if (c_parser_next_token_is (parser
, CPP_NAME
))
10426 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10427 if (strcmp ("master", p
) == 0)
10428 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10429 else if (strcmp ("close", p
) == 0)
10430 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10431 else if (strcmp ("spread", p
) == 0)
10432 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10439 c_parser_consume_token (parser
);
10440 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10441 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10442 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10443 OMP_CLAUSE_CHAIN (c
) = list
;
10447 c_parser_error (parser
, "invalid proc_bind kind");
10448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10453 to ( variable-list ) */
10456 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10458 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10462 from ( variable-list ) */
10465 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10467 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10471 uniform ( variable-list ) */
10474 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10476 /* The clauses location. */
10477 location_t loc
= c_parser_peek_token (parser
)->location
;
10479 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10481 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10483 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10488 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10489 is a bitmask in MASK. Return the list of clauses found; the result
10490 of clause default goes in *pdefault. */
10493 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10494 const char *where
, bool finish_p
= true)
10496 tree clauses
= NULL
;
10499 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10502 pragma_omp_clause c_kind
;
10503 const char *c_name
;
10504 tree prev
= clauses
;
10506 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10507 c_parser_consume_token (parser
);
10509 here
= c_parser_peek_token (parser
)->location
;
10510 c_kind
= c_parser_omp_clause_name (parser
);
10514 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10515 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10516 c_name
= "collapse";
10518 case PRAGMA_OMP_CLAUSE_COPYIN
:
10519 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10522 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10523 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10524 c_name
= "copyprivate";
10526 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10527 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10528 c_name
= "default";
10530 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
10531 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
10532 c_name
= "firstprivate";
10534 case PRAGMA_OMP_CLAUSE_FINAL
:
10535 clauses
= c_parser_omp_clause_final (parser
, clauses
);
10538 case PRAGMA_OMP_CLAUSE_IF
:
10539 clauses
= c_parser_omp_clause_if (parser
, clauses
);
10542 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
10543 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
10544 c_name
= "lastprivate";
10546 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
10547 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
10548 c_name
= "mergeable";
10550 case PRAGMA_OMP_CLAUSE_NOWAIT
:
10551 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
10554 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
10555 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
10556 c_name
= "num_threads";
10558 case PRAGMA_OMP_CLAUSE_ORDERED
:
10559 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
10560 c_name
= "ordered";
10562 case PRAGMA_OMP_CLAUSE_PRIVATE
:
10563 clauses
= c_parser_omp_clause_private (parser
, clauses
);
10564 c_name
= "private";
10566 case PRAGMA_OMP_CLAUSE_REDUCTION
:
10567 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
10568 c_name
= "reduction";
10570 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10571 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10572 c_name
= "schedule";
10574 case PRAGMA_OMP_CLAUSE_SHARED
:
10575 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10578 case PRAGMA_OMP_CLAUSE_UNTIED
:
10579 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
10582 case PRAGMA_OMP_CLAUSE_INBRANCH
:
10583 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
10585 c_name
= "inbranch";
10587 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
10588 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
10590 c_name
= "notinbranch";
10592 case PRAGMA_OMP_CLAUSE_PARALLEL
:
10594 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
10596 c_name
= "parallel";
10600 error_at (here
, "%qs must be the first clause of %qs",
10605 case PRAGMA_OMP_CLAUSE_FOR
:
10607 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
10611 goto clause_not_first
;
10613 case PRAGMA_OMP_CLAUSE_SECTIONS
:
10615 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
10617 c_name
= "sections";
10619 goto clause_not_first
;
10621 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
10623 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
10625 c_name
= "taskgroup";
10627 goto clause_not_first
;
10629 case PRAGMA_OMP_CLAUSE_TO
:
10630 clauses
= c_parser_omp_clause_to (parser
, clauses
);
10633 case PRAGMA_OMP_CLAUSE_FROM
:
10634 clauses
= c_parser_omp_clause_from (parser
, clauses
);
10637 case PRAGMA_OMP_CLAUSE_UNIFORM
:
10638 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
10639 c_name
= "uniform";
10641 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
10642 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
10643 c_name
= "num_teams";
10645 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
10646 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
10647 c_name
= "thread_limit";
10649 case PRAGMA_OMP_CLAUSE_ALIGNED
:
10650 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
10651 c_name
= "aligned";
10653 case PRAGMA_OMP_CLAUSE_LINEAR
:
10654 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
10657 case PRAGMA_OMP_CLAUSE_DEPEND
:
10658 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
10661 case PRAGMA_OMP_CLAUSE_MAP
:
10662 clauses
= c_parser_omp_clause_map (parser
, clauses
);
10665 case PRAGMA_OMP_CLAUSE_DEVICE
:
10666 clauses
= c_parser_omp_clause_device (parser
, clauses
);
10669 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
10670 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
10671 c_name
= "dist_schedule";
10673 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
10674 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
10675 c_name
= "proc_bind";
10677 case PRAGMA_OMP_CLAUSE_SAFELEN
:
10678 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
10679 c_name
= "safelen";
10681 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
10682 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
10683 c_name
= "simdlen";
10686 c_parser_error (parser
, "expected %<#pragma omp%> clause");
10692 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
10694 /* Remove the invalid clause(s) from the list to avoid
10695 confusing the rest of the compiler. */
10697 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
10702 c_parser_skip_to_pragma_eol (parser
);
10705 return c_finish_omp_clauses (clauses
);
10714 In practice, we're also interested in adding the statement to an
10715 outer node. So it is convenient if we work around the fact that
10716 c_parser_statement calls add_stmt. */
10719 c_parser_omp_structured_block (c_parser
*parser
)
10721 tree stmt
= push_stmt_list ();
10722 c_parser_statement (parser
);
10723 return pop_stmt_list (stmt
);
10727 # pragma omp atomic new-line
10731 x binop= expr | x++ | ++x | x-- | --x
10733 +, *, -, /, &, ^, |, <<, >>
10735 where x is an lvalue expression with scalar type.
10738 # pragma omp atomic new-line
10741 # pragma omp atomic read new-line
10744 # pragma omp atomic write new-line
10747 # pragma omp atomic update new-line
10750 # pragma omp atomic capture new-line
10753 # pragma omp atomic capture new-line
10761 expression-stmt | x = x binop expr
10763 v = expression-stmt
10765 { v = x; update-stmt; } | { update-stmt; v = x; }
10769 expression-stmt | x = x binop expr | x = expr binop x
10773 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
10775 where x and v are lvalue expressions with scalar type.
10777 LOC is the location of the #pragma token. */
10780 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
10782 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
10783 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
10784 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
10785 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
10786 struct c_expr expr
;
10788 bool structured_block
= false;
10789 bool swapped
= false;
10790 bool seq_cst
= false;
10792 if (c_parser_next_token_is (parser
, CPP_NAME
))
10794 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10796 if (!strcmp (p
, "read"))
10797 code
= OMP_ATOMIC_READ
;
10798 else if (!strcmp (p
, "write"))
10800 else if (!strcmp (p
, "update"))
10802 else if (!strcmp (p
, "capture"))
10803 code
= OMP_ATOMIC_CAPTURE_NEW
;
10807 c_parser_consume_token (parser
);
10809 if (c_parser_next_token_is (parser
, CPP_NAME
))
10811 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10812 if (!strcmp (p
, "seq_cst"))
10815 c_parser_consume_token (parser
);
10818 c_parser_skip_to_pragma_eol (parser
);
10822 case OMP_ATOMIC_READ
:
10823 case NOP_EXPR
: /* atomic write */
10824 v
= c_parser_unary_expression (parser
).value
;
10825 v
= c_fully_fold (v
, false, NULL
);
10826 if (v
== error_mark_node
)
10828 loc
= c_parser_peek_token (parser
)->location
;
10829 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10831 if (code
== NOP_EXPR
)
10832 lhs
= c_parser_expression (parser
).value
;
10834 lhs
= c_parser_unary_expression (parser
).value
;
10835 lhs
= c_fully_fold (lhs
, false, NULL
);
10836 if (lhs
== error_mark_node
)
10838 if (code
== NOP_EXPR
)
10840 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
10848 case OMP_ATOMIC_CAPTURE_NEW
:
10849 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10851 c_parser_consume_token (parser
);
10852 structured_block
= true;
10856 v
= c_parser_unary_expression (parser
).value
;
10857 v
= c_fully_fold (v
, false, NULL
);
10858 if (v
== error_mark_node
)
10860 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10868 /* For structured_block case we don't know yet whether
10869 old or new x should be captured. */
10871 eloc
= c_parser_peek_token (parser
)->location
;
10872 expr
= c_parser_unary_expression (parser
);
10874 expr
= default_function_array_conversion (eloc
, expr
);
10875 unfolded_lhs
= expr
.value
;
10876 lhs
= c_fully_fold (lhs
, false, NULL
);
10878 switch (TREE_CODE (lhs
))
10882 c_parser_skip_to_end_of_block_or_statement (parser
);
10883 if (structured_block
)
10885 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10886 c_parser_consume_token (parser
);
10887 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
10889 c_parser_skip_to_end_of_block_or_statement (parser
);
10890 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10891 c_parser_consume_token (parser
);
10896 case POSTINCREMENT_EXPR
:
10897 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
10898 code
= OMP_ATOMIC_CAPTURE_OLD
;
10900 case PREINCREMENT_EXPR
:
10901 lhs
= TREE_OPERAND (lhs
, 0);
10902 unfolded_lhs
= NULL_TREE
;
10903 opcode
= PLUS_EXPR
;
10904 rhs
= integer_one_node
;
10907 case POSTDECREMENT_EXPR
:
10908 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
10909 code
= OMP_ATOMIC_CAPTURE_OLD
;
10911 case PREDECREMENT_EXPR
:
10912 lhs
= TREE_OPERAND (lhs
, 0);
10913 unfolded_lhs
= NULL_TREE
;
10914 opcode
= MINUS_EXPR
;
10915 rhs
= integer_one_node
;
10918 case COMPOUND_EXPR
:
10919 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
10920 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
10921 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
10922 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
10923 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
10924 (TREE_OPERAND (lhs
, 1), 0), 0)))
10926 /* Undo effects of boolean_increment for post {in,de}crement. */
10927 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
10930 if (TREE_CODE (lhs
) == MODIFY_EXPR
10931 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
10933 /* Undo effects of boolean_increment. */
10934 if (integer_onep (TREE_OPERAND (lhs
, 1)))
10936 /* This is pre or post increment. */
10937 rhs
= TREE_OPERAND (lhs
, 1);
10938 lhs
= TREE_OPERAND (lhs
, 0);
10939 unfolded_lhs
= NULL_TREE
;
10941 if (code
== OMP_ATOMIC_CAPTURE_NEW
10942 && !structured_block
10943 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10944 code
= OMP_ATOMIC_CAPTURE_OLD
;
10947 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
10948 && TREE_OPERAND (lhs
, 0)
10949 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
10951 /* This is pre or post decrement. */
10952 rhs
= TREE_OPERAND (lhs
, 1);
10953 lhs
= TREE_OPERAND (lhs
, 0);
10954 unfolded_lhs
= NULL_TREE
;
10956 if (code
== OMP_ATOMIC_CAPTURE_NEW
10957 && !structured_block
10958 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10959 code
= OMP_ATOMIC_CAPTURE_OLD
;
10965 switch (c_parser_peek_token (parser
)->type
)
10968 opcode
= MULT_EXPR
;
10971 opcode
= TRUNC_DIV_EXPR
;
10974 opcode
= PLUS_EXPR
;
10977 opcode
= MINUS_EXPR
;
10979 case CPP_LSHIFT_EQ
:
10980 opcode
= LSHIFT_EXPR
;
10982 case CPP_RSHIFT_EQ
:
10983 opcode
= RSHIFT_EXPR
;
10986 opcode
= BIT_AND_EXPR
;
10989 opcode
= BIT_IOR_EXPR
;
10992 opcode
= BIT_XOR_EXPR
;
10995 c_parser_consume_token (parser
);
10996 eloc
= c_parser_peek_token (parser
)->location
;
10997 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
10999 switch (TREE_CODE (rhs1
))
11002 case TRUNC_DIV_EXPR
:
11010 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11012 opcode
= TREE_CODE (rhs1
);
11013 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11014 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11017 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11019 opcode
= TREE_CODE (rhs1
);
11020 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11021 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11022 swapped
= !commutative_tree_code (opcode
);
11031 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11033 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11035 code
= OMP_ATOMIC_CAPTURE_OLD
;
11038 expr
= default_function_array_read_conversion (eloc
, expr
);
11039 unfolded_lhs1
= expr
.value
;
11040 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11042 c_parser_consume_token (parser
);
11045 if (structured_block
)
11048 expr
= default_function_array_read_conversion (eloc
, expr
);
11049 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11054 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11057 c_parser_error (parser
,
11058 "invalid operator for %<#pragma omp atomic%>");
11062 /* Arrange to pass the location of the assignment operator to
11063 c_finish_omp_atomic. */
11064 loc
= c_parser_peek_token (parser
)->location
;
11065 c_parser_consume_token (parser
);
11066 eloc
= c_parser_peek_token (parser
)->location
;
11067 expr
= c_parser_expression (parser
);
11068 expr
= default_function_array_read_conversion (eloc
, expr
);
11070 rhs
= c_fully_fold (rhs
, false, NULL
);
11074 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11076 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11078 v
= c_parser_unary_expression (parser
).value
;
11079 v
= c_fully_fold (v
, false, NULL
);
11080 if (v
== error_mark_node
)
11082 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11084 eloc
= c_parser_peek_token (parser
)->location
;
11085 expr
= c_parser_unary_expression (parser
);
11087 expr
= default_function_array_read_conversion (eloc
, expr
);
11088 unfolded_lhs1
= expr
.value
;
11089 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11090 if (lhs1
== error_mark_node
)
11093 if (structured_block
)
11095 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11096 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11099 if (unfolded_lhs
&& unfolded_lhs1
11100 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11102 error ("%<#pragma omp atomic capture%> uses two different "
11103 "expressions for memory");
11104 stmt
= error_mark_node
;
11107 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11109 if (stmt
!= error_mark_node
)
11112 if (!structured_block
)
11113 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11118 # pragma omp barrier new-line
11122 c_parser_omp_barrier (c_parser
*parser
)
11124 location_t loc
= c_parser_peek_token (parser
)->location
;
11125 c_parser_consume_pragma (parser
);
11126 c_parser_skip_to_pragma_eol (parser
);
11128 c_finish_omp_barrier (loc
);
11132 # pragma omp critical [(name)] new-line
11135 LOC is the location of the #pragma itself. */
11138 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11140 tree stmt
, name
= NULL
;
11142 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11144 c_parser_consume_token (parser
);
11145 if (c_parser_next_token_is (parser
, CPP_NAME
))
11147 name
= c_parser_peek_token (parser
)->value
;
11148 c_parser_consume_token (parser
);
11149 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11152 c_parser_error (parser
, "expected identifier");
11154 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11155 c_parser_error (parser
, "expected %<(%> or end of line");
11156 c_parser_skip_to_pragma_eol (parser
);
11158 stmt
= c_parser_omp_structured_block (parser
);
11159 return c_finish_omp_critical (loc
, stmt
, name
);
11163 # pragma omp flush flush-vars[opt] new-line
11166 ( variable-list ) */
11169 c_parser_omp_flush (c_parser
*parser
)
11171 location_t loc
= c_parser_peek_token (parser
)->location
;
11172 c_parser_consume_pragma (parser
);
11173 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11174 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11175 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11176 c_parser_error (parser
, "expected %<(%> or end of line");
11177 c_parser_skip_to_pragma_eol (parser
);
11179 c_finish_omp_flush (loc
);
11182 /* Parse the restricted form of the for statement allowed by OpenMP.
11183 The real trick here is to determine the loop control variable early
11184 so that we can push a new decl if necessary to make it private.
11185 LOC is the location of the OMP in "#pragma omp". */
11188 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11189 tree clauses
, tree
*cclauses
)
11191 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11192 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11193 bool fail
= false, open_brace_parsed
= false;
11194 int i
, collapse
= 1, nbraces
= 0;
11195 location_t for_loc
;
11196 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11198 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11199 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11200 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
11202 gcc_assert (collapse
>= 1);
11204 declv
= make_tree_vec (collapse
);
11205 initv
= make_tree_vec (collapse
);
11206 condv
= make_tree_vec (collapse
);
11207 incrv
= make_tree_vec (collapse
);
11209 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11211 c_parser_error (parser
, "for statement expected");
11214 for_loc
= c_parser_peek_token (parser
)->location
;
11215 c_parser_consume_token (parser
);
11217 for (i
= 0; i
< collapse
; i
++)
11219 int bracecount
= 0;
11221 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11224 /* Parse the initialization declaration or expression. */
11225 if (c_parser_next_tokens_start_declaration (parser
))
11228 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11229 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11231 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11234 if (DECL_INITIAL (decl
) == error_mark_node
)
11235 decl
= error_mark_node
;
11238 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11239 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11241 struct c_expr decl_exp
;
11242 struct c_expr init_exp
;
11243 location_t init_loc
;
11245 decl_exp
= c_parser_postfix_expression (parser
);
11246 decl
= decl_exp
.value
;
11248 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11250 init_loc
= c_parser_peek_token (parser
)->location
;
11251 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11252 init_exp
= default_function_array_read_conversion (init_loc
,
11254 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11255 NOP_EXPR
, init_loc
, init_exp
.value
,
11256 init_exp
.original_type
);
11257 init
= c_process_expr_stmt (init_loc
, init
);
11259 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11264 c_parser_error (parser
,
11265 "expected iteration declaration or initialization");
11266 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11272 /* Parse the loop condition. */
11274 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11276 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11277 struct c_expr cond_expr
11278 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11280 cond
= cond_expr
.value
;
11281 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11282 cond
= c_fully_fold (cond
, false, NULL
);
11283 switch (cond_expr
.original_code
)
11291 /* Can't be cond = error_mark_node, because we want to preserve
11292 the location until c_finish_omp_for. */
11293 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11296 protected_set_expr_location (cond
, cond_loc
);
11298 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11300 /* Parse the increment expression. */
11302 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11304 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11306 incr
= c_process_expr_stmt (incr_loc
,
11307 c_parser_expression (parser
).value
);
11309 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11311 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11315 TREE_VEC_ELT (declv
, i
) = decl
;
11316 TREE_VEC_ELT (initv
, i
) = init
;
11317 TREE_VEC_ELT (condv
, i
) = cond
;
11318 TREE_VEC_ELT (incrv
, i
) = incr
;
11322 if (i
== collapse
- 1)
11325 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11326 in between the collapsed for loops to be still considered perfectly
11327 nested. Hopefully the final version clarifies this.
11328 For now handle (multiple) {'s and empty statements. */
11331 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11333 c_parser_consume_token (parser
);
11336 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11338 c_parser_consume_token (parser
);
11341 else if (bracecount
11342 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11343 c_parser_consume_token (parser
);
11346 c_parser_error (parser
, "not enough perfectly nested loops");
11349 open_brace_parsed
= true;
11359 nbraces
+= bracecount
;
11362 save_break
= c_break_label
;
11363 c_break_label
= size_one_node
;
11364 save_cont
= c_cont_label
;
11365 c_cont_label
= NULL_TREE
;
11366 body
= push_stmt_list ();
11368 if (open_brace_parsed
)
11370 location_t here
= c_parser_peek_token (parser
)->location
;
11371 stmt
= c_begin_compound_stmt (true);
11372 c_parser_compound_statement_nostart (parser
);
11373 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11376 add_stmt (c_parser_c99_block_statement (parser
));
11379 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11380 SET_EXPR_LOCATION (t
, loc
);
11384 body
= pop_stmt_list (body
);
11385 c_break_label
= save_break
;
11386 c_cont_label
= save_cont
;
11390 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11392 c_parser_consume_token (parser
);
11395 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11396 c_parser_consume_token (parser
);
11399 c_parser_error (parser
, "collapsed loops not perfectly nested");
11402 location_t here
= c_parser_peek_token (parser
)->location
;
11403 stmt
= c_begin_compound_stmt (true);
11405 c_parser_compound_statement_nostart (parser
);
11406 body
= c_end_compound_stmt (here
, stmt
, true);
11413 /* Only bother calling c_finish_omp_for if we haven't already generated
11414 an error from the initialization parsing. */
11417 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11418 incrv
, body
, NULL
);
11421 if (cclauses
!= NULL
11422 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11425 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11426 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11427 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11428 c
= &OMP_CLAUSE_CHAIN (*c
);
11431 for (i
= 0; i
< collapse
; i
++)
11432 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11435 c
= &OMP_CLAUSE_CHAIN (*c
);
11436 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11439 "iteration variable %qD should not be firstprivate",
11440 OMP_CLAUSE_DECL (*c
));
11441 *c
= OMP_CLAUSE_CHAIN (*c
);
11445 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11446 change it to shared (decl) in
11447 OMP_PARALLEL_CLAUSES. */
11448 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11449 OMP_CLAUSE_LASTPRIVATE
);
11450 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11451 OMP_CLAUSE_CHAIN (l
) = clauses
;
11453 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11457 OMP_FOR_CLAUSES (stmt
) = clauses
;
11462 while (!for_block
->is_empty ())
11464 /* FIXME diagnostics: LOC below should be the actual location of
11465 this particular for block. We need to build a list of
11466 locations to go along with FOR_BLOCK. */
11467 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11470 release_tree_vector (for_block
);
11474 /* Helper function for OpenMP parsing, split clauses and call
11475 finish_omp_clauses on each of the set of clauses afterwards. */
11478 omp_split_clauses (location_t loc
, enum tree_code code
,
11479 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11482 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11483 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11485 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11489 #pragma omp simd simd-clause[optseq] new-line
11492 LOC is the location of the #pragma token.
11495 #define OMP_SIMD_CLAUSE_MASK \
11496 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
11497 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
11498 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
11499 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11500 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11501 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11502 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
11505 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
11506 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11508 tree block
, clauses
, ret
;
11510 strcat (p_name
, " simd");
11511 mask
|= OMP_SIMD_CLAUSE_MASK
;
11512 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
11514 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11517 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
11518 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
11521 block
= c_begin_compound_stmt (true);
11522 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
11523 block
= c_end_compound_stmt (loc
, block
, true);
11530 #pragma omp for for-clause[optseq] new-line
11534 #pragma omp for simd for-simd-clause[optseq] new-line
11537 LOC is the location of the #pragma token.
11540 #define OMP_FOR_CLAUSE_MASK \
11541 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11542 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11543 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11545 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
11546 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
11547 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11548 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11551 c_parser_omp_for (location_t loc
, c_parser
*parser
,
11552 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11554 tree block
, clauses
, ret
;
11556 strcat (p_name
, " for");
11557 mask
|= OMP_FOR_CLAUSE_MASK
;
11559 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
11561 if (c_parser_next_token_is (parser
, CPP_NAME
))
11563 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11565 if (strcmp (p
, "simd") == 0)
11567 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
11568 if (cclauses
== NULL
)
11569 cclauses
= cclauses_buf
;
11571 c_parser_consume_token (parser
);
11572 block
= c_begin_compound_stmt (true);
11573 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
11574 block
= c_end_compound_stmt (loc
, block
, true);
11575 if (ret
== NULL_TREE
)
11577 ret
= make_node (OMP_FOR
);
11578 TREE_TYPE (ret
) = void_type_node
;
11579 OMP_FOR_BODY (ret
) = block
;
11580 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11581 SET_EXPR_LOCATION (ret
, loc
);
11587 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11590 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
11591 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11594 block
= c_begin_compound_stmt (true);
11595 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
11596 block
= c_end_compound_stmt (loc
, block
, true);
11603 # pragma omp master new-line
11606 LOC is the location of the #pragma token.
11610 c_parser_omp_master (location_t loc
, c_parser
*parser
)
11612 c_parser_skip_to_pragma_eol (parser
);
11613 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
11617 # pragma omp ordered new-line
11620 LOC is the location of the #pragma itself.
11624 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
11626 c_parser_skip_to_pragma_eol (parser
);
11627 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
11633 { section-sequence }
11636 section-directive[opt] structured-block
11637 section-sequence section-directive structured-block
11639 SECTIONS_LOC is the location of the #pragma omp sections. */
11642 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
11644 tree stmt
, substmt
;
11645 bool error_suppress
= false;
11648 loc
= c_parser_peek_token (parser
)->location
;
11649 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
11651 /* Avoid skipping until the end of the block. */
11652 parser
->error
= false;
11656 stmt
= push_stmt_list ();
11658 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
11660 substmt
= c_parser_omp_structured_block (parser
);
11661 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11662 SET_EXPR_LOCATION (substmt
, loc
);
11663 add_stmt (substmt
);
11668 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11670 if (c_parser_next_token_is (parser
, CPP_EOF
))
11673 loc
= c_parser_peek_token (parser
)->location
;
11674 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
11676 c_parser_consume_pragma (parser
);
11677 c_parser_skip_to_pragma_eol (parser
);
11678 error_suppress
= false;
11680 else if (!error_suppress
)
11682 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
11683 error_suppress
= true;
11686 substmt
= c_parser_omp_structured_block (parser
);
11687 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11688 SET_EXPR_LOCATION (substmt
, loc
);
11689 add_stmt (substmt
);
11691 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
11692 "expected %<#pragma omp section%> or %<}%>");
11694 substmt
= pop_stmt_list (stmt
);
11696 stmt
= make_node (OMP_SECTIONS
);
11697 SET_EXPR_LOCATION (stmt
, sections_loc
);
11698 TREE_TYPE (stmt
) = void_type_node
;
11699 OMP_SECTIONS_BODY (stmt
) = substmt
;
11701 return add_stmt (stmt
);
11705 # pragma omp sections sections-clause[optseq] newline
11708 LOC is the location of the #pragma token.
11711 #define OMP_SECTIONS_CLAUSE_MASK \
11712 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11713 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11714 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11715 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11716 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11719 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
11720 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11722 tree block
, clauses
, ret
;
11724 strcat (p_name
, " sections");
11725 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
11727 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
11729 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11732 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
11733 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
11736 block
= c_begin_compound_stmt (true);
11737 ret
= c_parser_omp_sections_scope (loc
, parser
);
11739 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
11740 block
= c_end_compound_stmt (loc
, block
, true);
11747 # pragma parallel parallel-clause new-line
11748 # pragma parallel for parallel-for-clause new-line
11749 # pragma parallel sections parallel-sections-clause new-line
11751 LOC is the location of the #pragma token.
11754 #define OMP_PARALLEL_CLAUSE_MASK \
11755 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11756 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11757 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11758 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
11759 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
11760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11762 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
11763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
11766 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
11767 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11769 tree stmt
, clauses
, block
;
11771 strcat (p_name
, " parallel");
11772 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
11774 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11776 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
11777 if (cclauses
== NULL
)
11778 cclauses
= cclauses_buf
;
11780 c_parser_consume_token (parser
);
11781 block
= c_begin_omp_parallel ();
11782 c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
11784 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
11786 OMP_PARALLEL_COMBINED (stmt
) = 1;
11791 error_at (loc
, "expected %<for%> after %qs", p_name
);
11792 c_parser_skip_to_pragma_eol (parser
);
11795 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11797 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11798 if (strcmp (p
, "sections") == 0)
11800 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
11801 if (cclauses
== NULL
)
11802 cclauses
= cclauses_buf
;
11804 c_parser_consume_token (parser
);
11805 block
= c_begin_omp_parallel ();
11806 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
11807 stmt
= c_finish_omp_parallel (loc
,
11808 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
11810 OMP_PARALLEL_COMBINED (stmt
) = 1;
11815 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11817 block
= c_begin_omp_parallel ();
11818 c_parser_statement (parser
);
11819 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
11825 # pragma omp single single-clause[optseq] new-line
11828 LOC is the location of the #pragma.
11831 #define OMP_SINGLE_CLAUSE_MASK \
11832 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11833 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11834 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
11835 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11838 c_parser_omp_single (location_t loc
, c_parser
*parser
)
11840 tree stmt
= make_node (OMP_SINGLE
);
11841 SET_EXPR_LOCATION (stmt
, loc
);
11842 TREE_TYPE (stmt
) = void_type_node
;
11844 OMP_SINGLE_CLAUSES (stmt
)
11845 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
11846 "#pragma omp single");
11847 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
11849 return add_stmt (stmt
);
11853 # pragma omp task task-clause[optseq] new-line
11855 LOC is the location of the #pragma.
11858 #define OMP_TASK_CLAUSE_MASK \
11859 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11860 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
11861 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
11862 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11863 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11864 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
11865 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
11866 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
11867 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
11870 c_parser_omp_task (location_t loc
, c_parser
*parser
)
11872 tree clauses
, block
;
11874 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
11875 "#pragma omp task");
11877 block
= c_begin_omp_task ();
11878 c_parser_statement (parser
);
11879 return c_finish_omp_task (loc
, clauses
, block
);
11883 # pragma omp taskwait new-line
11887 c_parser_omp_taskwait (c_parser
*parser
)
11889 location_t loc
= c_parser_peek_token (parser
)->location
;
11890 c_parser_consume_pragma (parser
);
11891 c_parser_skip_to_pragma_eol (parser
);
11893 c_finish_omp_taskwait (loc
);
11897 # pragma omp taskyield new-line
11901 c_parser_omp_taskyield (c_parser
*parser
)
11903 location_t loc
= c_parser_peek_token (parser
)->location
;
11904 c_parser_consume_pragma (parser
);
11905 c_parser_skip_to_pragma_eol (parser
);
11907 c_finish_omp_taskyield (loc
);
11911 # pragma omp taskgroup new-line
11915 c_parser_omp_taskgroup (c_parser
*parser
)
11917 location_t loc
= c_parser_peek_token (parser
)->location
;
11918 c_parser_skip_to_pragma_eol (parser
);
11919 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
11923 # pragma omp cancel cancel-clause[optseq] new-line
11925 LOC is the location of the #pragma.
11928 #define OMP_CANCEL_CLAUSE_MASK \
11929 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
11930 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
11931 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
11932 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
11933 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
11936 c_parser_omp_cancel (c_parser
*parser
)
11938 location_t loc
= c_parser_peek_token (parser
)->location
;
11940 c_parser_consume_pragma (parser
);
11941 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
11942 "#pragma omp cancel");
11944 c_finish_omp_cancel (loc
, clauses
);
11948 # pragma omp cancellation point cancelpt-clause[optseq] new-line
11950 LOC is the location of the #pragma.
11953 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
11954 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
11955 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
11956 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
11957 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
11960 c_parser_omp_cancellation_point (c_parser
*parser
)
11962 location_t loc
= c_parser_peek_token (parser
)->location
;
11964 bool point_seen
= false;
11966 c_parser_consume_pragma (parser
);
11967 if (c_parser_next_token_is (parser
, CPP_NAME
))
11969 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11970 if (strcmp (p
, "point") == 0)
11972 c_parser_consume_token (parser
);
11978 c_parser_error (parser
, "expected %<point%>");
11979 c_parser_skip_to_pragma_eol (parser
);
11984 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
11985 "#pragma omp cancellation point");
11987 c_finish_omp_cancellation_point (loc
, clauses
);
11991 #pragma omp distribute distribute-clause[optseq] new-line
11994 #define OMP_DISTRIBUTE_CLAUSE_MASK \
11995 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11996 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11997 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
11998 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12001 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12002 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12004 tree clauses
, block
, ret
;
12006 strcat (p_name
, " distribute");
12007 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12009 if (c_parser_next_token_is (parser
, CPP_NAME
))
12011 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12013 bool parallel
= false;
12015 if (strcmp (p
, "simd") == 0)
12018 parallel
= strcmp (p
, "parallel") == 0;
12019 if (parallel
|| simd
)
12021 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12022 if (cclauses
== NULL
)
12023 cclauses
= cclauses_buf
;
12024 c_parser_consume_token (parser
);
12025 block
= c_begin_compound_stmt (true);
12027 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12029 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12030 block
= c_end_compound_stmt (loc
, block
, true);
12033 ret
= make_node (OMP_DISTRIBUTE
);
12034 TREE_TYPE (ret
) = void_type_node
;
12035 OMP_FOR_BODY (ret
) = block
;
12036 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12037 SET_EXPR_LOCATION (ret
, loc
);
12043 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12046 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12047 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12050 block
= c_begin_compound_stmt (true);
12051 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12052 block
= c_end_compound_stmt (loc
, block
, true);
12059 # pragma omp teams teams-clause[optseq] new-line
12060 structured-block */
12062 #define OMP_TEAMS_CLAUSE_MASK \
12063 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12064 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12065 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12068 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12069 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12072 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12073 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12075 tree clauses
, block
, ret
;
12077 strcat (p_name
, " teams");
12078 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12080 if (c_parser_next_token_is (parser
, CPP_NAME
))
12082 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12083 if (strcmp (p
, "distribute") == 0)
12085 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12086 if (cclauses
== NULL
)
12087 cclauses
= cclauses_buf
;
12089 c_parser_consume_token (parser
);
12090 block
= c_begin_compound_stmt (true);
12091 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12092 block
= c_end_compound_stmt (loc
, block
, true);
12095 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12096 ret
= make_node (OMP_TEAMS
);
12097 TREE_TYPE (ret
) = void_type_node
;
12098 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12099 OMP_TEAMS_BODY (ret
) = block
;
12100 return add_stmt (ret
);
12104 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12107 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12108 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12111 tree stmt
= make_node (OMP_TEAMS
);
12112 TREE_TYPE (stmt
) = void_type_node
;
12113 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12114 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12116 return add_stmt (stmt
);
12120 # pragma omp target data target-data-clause[optseq] new-line
12121 structured-block */
12123 #define OMP_TARGET_DATA_CLAUSE_MASK \
12124 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12125 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12126 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12129 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12131 tree stmt
= make_node (OMP_TARGET_DATA
);
12132 TREE_TYPE (stmt
) = void_type_node
;
12134 OMP_TARGET_DATA_CLAUSES (stmt
)
12135 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12136 "#pragma omp target data");
12137 keep_next_level ();
12138 tree block
= c_begin_compound_stmt (true);
12139 add_stmt (c_parser_omp_structured_block (parser
));
12140 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12142 SET_EXPR_LOCATION (stmt
, loc
);
12143 return add_stmt (stmt
);
12147 # pragma omp target update target-update-clause[optseq] new-line */
12149 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12150 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12151 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12152 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12153 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12156 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12157 enum pragma_context context
)
12159 if (context
== pragma_stmt
)
12162 "%<#pragma omp target update%> may only be "
12163 "used in compound statements");
12164 c_parser_skip_to_pragma_eol (parser
);
12169 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12170 "#pragma omp target update");
12171 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12172 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12175 "%<#pragma omp target update must contain at least one "
12176 "%<from%> or %<to%> clauses");
12180 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12181 TREE_TYPE (stmt
) = void_type_node
;
12182 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12183 SET_EXPR_LOCATION (stmt
, loc
);
12189 # pragma omp target target-clause[optseq] new-line
12190 structured-block */
12192 #define OMP_TARGET_CLAUSE_MASK \
12193 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12194 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12195 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12198 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12200 location_t loc
= c_parser_peek_token (parser
)->location
;
12201 c_parser_consume_pragma (parser
);
12203 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12205 c_parser_error (parser
, "expected declaration specifiers");
12206 c_parser_skip_to_pragma_eol (parser
);
12210 if (c_parser_next_token_is (parser
, CPP_NAME
))
12212 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12214 if (strcmp (p
, "data") == 0)
12216 c_parser_consume_token (parser
);
12217 c_parser_omp_target_data (loc
, parser
);
12220 else if (strcmp (p
, "update") == 0)
12222 c_parser_consume_token (parser
);
12223 return c_parser_omp_target_update (loc
, parser
, context
);
12225 else if (strcmp (p
, "teams") == 0)
12227 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12228 char p_name
[sizeof ("#pragma omp target teams distribute "
12229 "parallel for simd")];
12231 c_parser_consume_token (parser
);
12232 strcpy (p_name
, "#pragma omp target");
12233 keep_next_level ();
12234 tree block
= c_begin_compound_stmt (true);
12235 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12236 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12237 block
= c_end_compound_stmt (loc
, block
, true);
12240 tree stmt
= make_node (OMP_TARGET
);
12241 TREE_TYPE (stmt
) = void_type_node
;
12242 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12243 OMP_TARGET_BODY (stmt
) = block
;
12249 tree stmt
= make_node (OMP_TARGET
);
12250 TREE_TYPE (stmt
) = void_type_node
;
12252 OMP_TARGET_CLAUSES (stmt
)
12253 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12254 "#pragma omp target");
12255 keep_next_level ();
12256 tree block
= c_begin_compound_stmt (true);
12257 add_stmt (c_parser_omp_structured_block (parser
));
12258 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12260 SET_EXPR_LOCATION (stmt
, loc
);
12266 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12268 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12269 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12270 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12272 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12273 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12274 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12277 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12279 vec
<c_token
> clauses
= vNULL
;
12280 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12282 c_token
*token
= c_parser_peek_token (parser
);
12283 if (token
->type
== CPP_EOF
)
12285 c_parser_skip_to_pragma_eol (parser
);
12286 clauses
.release ();
12289 clauses
.safe_push (*token
);
12290 c_parser_consume_token (parser
);
12292 clauses
.safe_push (*c_parser_peek_token (parser
));
12293 c_parser_skip_to_pragma_eol (parser
);
12295 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12297 if (c_parser_peek_token (parser
)->pragma_kind
12298 != PRAGMA_OMP_DECLARE_REDUCTION
12299 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12300 || strcmp (IDENTIFIER_POINTER
12301 (c_parser_peek_2nd_token (parser
)->value
),
12304 c_parser_error (parser
,
12305 "%<#pragma omp declare simd%> must be followed by "
12306 "function declaration or definition or another "
12307 "%<#pragma omp declare simd%>");
12308 clauses
.release ();
12311 c_parser_consume_pragma (parser
);
12312 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12314 c_token
*token
= c_parser_peek_token (parser
);
12315 if (token
->type
== CPP_EOF
)
12317 c_parser_skip_to_pragma_eol (parser
);
12318 clauses
.release ();
12321 clauses
.safe_push (*token
);
12322 c_parser_consume_token (parser
);
12324 clauses
.safe_push (*c_parser_peek_token (parser
));
12325 c_parser_skip_to_pragma_eol (parser
);
12328 /* Make sure nothing tries to read past the end of the tokens. */
12330 memset (&eof_token
, 0, sizeof (eof_token
));
12331 eof_token
.type
= CPP_EOF
;
12332 clauses
.safe_push (eof_token
);
12333 clauses
.safe_push (eof_token
);
12337 case pragma_external
:
12338 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12339 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12341 int ext
= disable_extension_diagnostics ();
12343 c_parser_consume_token (parser
);
12344 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12345 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12346 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12348 restore_extension_diagnostics (ext
);
12351 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12354 case pragma_struct
:
12356 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12357 "function declaration or definition");
12359 case pragma_compound
:
12361 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12362 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12364 int ext
= disable_extension_diagnostics ();
12366 c_parser_consume_token (parser
);
12367 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12368 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12369 if (c_parser_next_tokens_start_declaration (parser
))
12371 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12372 true, NULL
, clauses
);
12373 restore_extension_diagnostics (ext
);
12376 restore_extension_diagnostics (ext
);
12378 else if (c_parser_next_tokens_start_declaration (parser
))
12380 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12384 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12385 "function declaration or definition");
12388 gcc_unreachable ();
12390 clauses
.release ();
12393 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12394 and put that into "omp declare simd" attribute. */
12397 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12398 vec
<c_token
> clauses
)
12400 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12401 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12402 has already processed the tokens. */
12403 if (clauses
[0].type
== CPP_EOF
)
12405 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12407 error ("%<#pragma omp declare simd%> not immediately followed by "
12408 "a function declaration or definition");
12409 clauses
[0].type
= CPP_EOF
;
12412 if (clauses
[0].type
!= CPP_NAME
)
12414 error_at (DECL_SOURCE_LOCATION (fndecl
),
12415 "%<#pragma omp declare simd%> not immediately followed by "
12416 "a single function declaration or definition");
12417 clauses
[0].type
= CPP_EOF
;
12421 if (parms
== NULL_TREE
)
12422 parms
= DECL_ARGUMENTS (fndecl
);
12424 unsigned int tokens_avail
= parser
->tokens_avail
;
12425 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12426 parser
->tokens
= clauses
.address ();
12427 parser
->tokens_avail
= clauses
.length ();
12429 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12430 while (parser
->tokens_avail
> 3)
12432 c_token
*token
= c_parser_peek_token (parser
);
12433 gcc_assert (token
->type
== CPP_NAME
12434 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12435 c_parser_consume_token (parser
);
12436 parser
->in_pragma
= true;
12438 tree c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12439 "#pragma omp declare simd");
12440 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12441 if (c
!= NULL_TREE
)
12442 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12443 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12444 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12445 DECL_ATTRIBUTES (fndecl
) = c
;
12448 parser
->tokens
= &parser
->tokens_buf
[0];
12449 parser
->tokens_avail
= tokens_avail
;
12450 clauses
[0].type
= CPP_PRAGMA
;
12455 # pragma omp declare target new-line
12456 declarations and definitions
12457 # pragma omp end declare target new-line */
12460 c_parser_omp_declare_target (c_parser
*parser
)
12462 c_parser_skip_to_pragma_eol (parser
);
12463 current_omp_declare_target_attribute
++;
12467 c_parser_omp_end_declare_target (c_parser
*parser
)
12469 location_t loc
= c_parser_peek_token (parser
)->location
;
12470 c_parser_consume_pragma (parser
);
12471 if (c_parser_next_token_is (parser
, CPP_NAME
)
12472 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12475 c_parser_consume_token (parser
);
12476 if (c_parser_next_token_is (parser
, CPP_NAME
)
12477 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12479 c_parser_consume_token (parser
);
12482 c_parser_error (parser
, "expected %<target%>");
12483 c_parser_skip_to_pragma_eol (parser
);
12489 c_parser_error (parser
, "expected %<declare%>");
12490 c_parser_skip_to_pragma_eol (parser
);
12493 c_parser_skip_to_pragma_eol (parser
);
12494 if (!current_omp_declare_target_attribute
)
12495 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
12496 "%<#pragma omp declare target%>");
12498 current_omp_declare_target_attribute
--;
12503 #pragma omp declare reduction (reduction-id : typename-list : expression) \
12504 initializer-clause[opt] new-line
12506 initializer-clause:
12507 initializer (omp_priv = initializer)
12508 initializer (function-name (argument-list)) */
12511 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
12513 unsigned int tokens_avail
= 0, i
;
12514 vec
<tree
> types
= vNULL
;
12515 vec
<c_token
> clauses
= vNULL
;
12516 enum tree_code reduc_code
= ERROR_MARK
;
12517 tree reduc_id
= NULL_TREE
;
12519 location_t rloc
= c_parser_peek_token (parser
)->location
;
12521 if (context
== pragma_struct
|| context
== pragma_param
)
12523 error ("%<#pragma omp declare reduction%> not at file or block scope");
12527 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12530 switch (c_parser_peek_token (parser
)->type
)
12533 reduc_code
= PLUS_EXPR
;
12536 reduc_code
= MULT_EXPR
;
12539 reduc_code
= MINUS_EXPR
;
12542 reduc_code
= BIT_AND_EXPR
;
12545 reduc_code
= BIT_XOR_EXPR
;
12548 reduc_code
= BIT_IOR_EXPR
;
12551 reduc_code
= TRUTH_ANDIF_EXPR
;
12554 reduc_code
= TRUTH_ORIF_EXPR
;
12558 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12559 if (strcmp (p
, "min") == 0)
12561 reduc_code
= MIN_EXPR
;
12564 if (strcmp (p
, "max") == 0)
12566 reduc_code
= MAX_EXPR
;
12569 reduc_id
= c_parser_peek_token (parser
)->value
;
12572 c_parser_error (parser
,
12573 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12574 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
12578 tree orig_reduc_id
, reduc_decl
;
12579 orig_reduc_id
= reduc_id
;
12580 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
12581 reduc_decl
= c_omp_reduction_decl (reduc_id
);
12582 c_parser_consume_token (parser
);
12584 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12589 location_t loc
= c_parser_peek_token (parser
)->location
;
12590 struct c_type_name
*ctype
= c_parser_type_name (parser
);
12593 type
= groktypename (ctype
, NULL
, NULL
);
12594 if (type
== error_mark_node
)
12596 else if ((INTEGRAL_TYPE_P (type
)
12597 || TREE_CODE (type
) == REAL_TYPE
12598 || TREE_CODE (type
) == COMPLEX_TYPE
)
12599 && orig_reduc_id
== NULL_TREE
)
12600 error_at (loc
, "predeclared arithmetic type in "
12601 "%<#pragma omp declare reduction%>");
12602 else if (TREE_CODE (type
) == FUNCTION_TYPE
12603 || TREE_CODE (type
) == ARRAY_TYPE
)
12604 error_at (loc
, "function or array type in "
12605 "%<#pragma omp declare reduction%>");
12606 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
12607 error_at (loc
, "const, volatile or restrict qualified type in "
12608 "%<#pragma omp declare reduction%>");
12612 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
12613 if (comptypes (TREE_PURPOSE (t
), type
))
12615 error_at (loc
, "redeclaration of %qs "
12616 "%<#pragma omp declare reduction%> for "
12618 IDENTIFIER_POINTER (reduc_id
)
12619 + sizeof ("omp declare reduction ") - 1,
12622 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
12624 error_at (ploc
, "previous %<#pragma omp declare "
12628 if (t
== NULL_TREE
)
12629 types
.safe_push (type
);
12631 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12632 c_parser_consume_token (parser
);
12640 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
12641 || types
.is_empty ())
12644 clauses
.release ();
12648 c_token
*token
= c_parser_peek_token (parser
);
12649 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
12651 c_parser_consume_token (parser
);
12653 c_parser_skip_to_pragma_eol (parser
);
12657 if (types
.length () > 1)
12659 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12661 c_token
*token
= c_parser_peek_token (parser
);
12662 if (token
->type
== CPP_EOF
)
12664 clauses
.safe_push (*token
);
12665 c_parser_consume_token (parser
);
12667 clauses
.safe_push (*c_parser_peek_token (parser
));
12668 c_parser_skip_to_pragma_eol (parser
);
12670 /* Make sure nothing tries to read past the end of the tokens. */
12672 memset (&eof_token
, 0, sizeof (eof_token
));
12673 eof_token
.type
= CPP_EOF
;
12674 clauses
.safe_push (eof_token
);
12675 clauses
.safe_push (eof_token
);
12678 int errs
= errorcount
;
12679 FOR_EACH_VEC_ELT (types
, i
, type
)
12681 tokens_avail
= parser
->tokens_avail
;
12682 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12683 if (!clauses
.is_empty ())
12685 parser
->tokens
= clauses
.address ();
12686 parser
->tokens_avail
= clauses
.length ();
12687 parser
->in_pragma
= true;
12690 bool nested
= current_function_decl
!= NULL_TREE
;
12692 c_push_function_context ();
12693 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
12694 reduc_id
, default_function_type
);
12695 current_function_decl
= fndecl
;
12696 allocate_struct_function (fndecl
, true);
12698 tree stmt
= push_stmt_list ();
12699 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
12700 warn about these. */
12701 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
12702 get_identifier ("omp_out"), type
);
12703 DECL_ARTIFICIAL (omp_out
) = 1;
12704 DECL_CONTEXT (omp_out
) = fndecl
;
12705 pushdecl (omp_out
);
12706 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
12707 get_identifier ("omp_in"), type
);
12708 DECL_ARTIFICIAL (omp_in
) = 1;
12709 DECL_CONTEXT (omp_in
) = fndecl
;
12711 struct c_expr combiner
= c_parser_expression (parser
);
12712 struct c_expr initializer
;
12713 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
12715 initializer
.value
= error_mark_node
;
12716 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12718 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12719 && strcmp (IDENTIFIER_POINTER
12720 (c_parser_peek_token (parser
)->value
),
12721 "initializer") == 0)
12723 c_parser_consume_token (parser
);
12726 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
12727 get_identifier ("omp_priv"), type
);
12728 DECL_ARTIFICIAL (omp_priv
) = 1;
12729 DECL_INITIAL (omp_priv
) = error_mark_node
;
12730 DECL_CONTEXT (omp_priv
) = fndecl
;
12731 pushdecl (omp_priv
);
12732 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
12733 get_identifier ("omp_orig"), type
);
12734 DECL_ARTIFICIAL (omp_orig
) = 1;
12735 DECL_CONTEXT (omp_orig
) = fndecl
;
12736 pushdecl (omp_orig
);
12737 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12739 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
12741 c_parser_error (parser
, "expected %<omp_priv%> or "
12745 else if (strcmp (IDENTIFIER_POINTER
12746 (c_parser_peek_token (parser
)->value
),
12749 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
12750 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12752 c_parser_error (parser
, "expected function-name %<(%>");
12756 initializer
= c_parser_postfix_expression (parser
);
12757 if (initializer
.value
12758 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
12761 tree c
= initializer
.value
;
12762 for (j
= 0; j
< call_expr_nargs (c
); j
++)
12763 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
12764 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
12766 if (j
== call_expr_nargs (c
))
12767 error ("one of the initializer call arguments should be "
12773 c_parser_consume_token (parser
);
12774 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12778 tree st
= push_stmt_list ();
12779 start_init (omp_priv
, NULL_TREE
, 0);
12780 location_t loc
= c_parser_peek_token (parser
)->location
;
12781 struct c_expr init
= c_parser_initializer (parser
);
12783 finish_decl (omp_priv
, loc
, init
.value
,
12784 init
.original_type
, NULL_TREE
);
12785 pop_stmt_list (st
);
12789 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12795 c_parser_skip_to_pragma_eol (parser
);
12797 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
12798 DECL_INITIAL (reduc_decl
));
12799 DECL_INITIAL (reduc_decl
) = t
;
12800 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
12801 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
12802 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
12803 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
12804 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
12805 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
12808 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
12809 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
12810 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
12811 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
12812 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
12813 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
12814 walk_tree (&DECL_INITIAL (omp_priv
),
12815 c_check_omp_declare_reduction_r
,
12816 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
12820 pop_stmt_list (stmt
);
12822 if (cfun
->language
!= NULL
)
12824 ggc_free (cfun
->language
);
12825 cfun
->language
= NULL
;
12828 current_function_decl
= NULL_TREE
;
12830 c_pop_function_context ();
12832 if (!clauses
.is_empty ())
12834 parser
->tokens
= &parser
->tokens_buf
[0];
12835 parser
->tokens_avail
= tokens_avail
;
12839 if (errs
!= errorcount
)
12843 clauses
.release ();
12849 #pragma omp declare simd declare-simd-clauses[optseq] new-line
12850 #pragma omp declare reduction (reduction-id : typename-list : expression) \
12851 initializer-clause[opt] new-line
12852 #pragma omp declare target new-line */
12855 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
12857 c_parser_consume_pragma (parser
);
12858 if (c_parser_next_token_is (parser
, CPP_NAME
))
12860 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12861 if (strcmp (p
, "simd") == 0)
12863 /* c_parser_consume_token (parser); done in
12864 c_parser_omp_declare_simd. */
12865 c_parser_omp_declare_simd (parser
, context
);
12868 if (strcmp (p
, "reduction") == 0)
12870 c_parser_consume_token (parser
);
12871 c_parser_omp_declare_reduction (parser
, context
);
12874 if (strcmp (p
, "target") == 0)
12876 c_parser_consume_token (parser
);
12877 c_parser_omp_declare_target (parser
);
12882 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
12884 c_parser_skip_to_pragma_eol (parser
);
12887 /* Main entry point to parsing most OpenMP pragmas. */
12890 c_parser_omp_construct (c_parser
*parser
)
12892 enum pragma_kind p_kind
;
12895 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
12896 omp_clause_mask
mask (0);
12898 loc
= c_parser_peek_token (parser
)->location
;
12899 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
12900 c_parser_consume_pragma (parser
);
12904 case PRAGMA_OMP_ATOMIC
:
12905 c_parser_omp_atomic (loc
, parser
);
12907 case PRAGMA_OMP_CRITICAL
:
12908 stmt
= c_parser_omp_critical (loc
, parser
);
12910 case PRAGMA_OMP_DISTRIBUTE
:
12911 strcpy (p_name
, "#pragma omp");
12912 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
12914 case PRAGMA_OMP_FOR
:
12915 strcpy (p_name
, "#pragma omp");
12916 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
12918 case PRAGMA_OMP_MASTER
:
12919 stmt
= c_parser_omp_master (loc
, parser
);
12921 case PRAGMA_OMP_ORDERED
:
12922 stmt
= c_parser_omp_ordered (loc
, parser
);
12924 case PRAGMA_OMP_PARALLEL
:
12925 strcpy (p_name
, "#pragma omp");
12926 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
12928 case PRAGMA_OMP_SECTIONS
:
12929 strcpy (p_name
, "#pragma omp");
12930 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
12932 case PRAGMA_OMP_SIMD
:
12933 strcpy (p_name
, "#pragma omp");
12934 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
12936 case PRAGMA_OMP_SINGLE
:
12937 stmt
= c_parser_omp_single (loc
, parser
);
12939 case PRAGMA_OMP_TASK
:
12940 stmt
= c_parser_omp_task (loc
, parser
);
12942 case PRAGMA_OMP_TASKGROUP
:
12943 stmt
= c_parser_omp_taskgroup (parser
);
12945 case PRAGMA_OMP_TEAMS
:
12946 strcpy (p_name
, "#pragma omp");
12947 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
12950 gcc_unreachable ();
12954 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
12959 # pragma omp threadprivate (variable-list) */
12962 c_parser_omp_threadprivate (c_parser
*parser
)
12967 c_parser_consume_pragma (parser
);
12968 loc
= c_parser_peek_token (parser
)->location
;
12969 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
12971 /* Mark every variable in VARS to be assigned thread local storage. */
12972 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
12974 tree v
= TREE_PURPOSE (t
);
12976 /* FIXME diagnostics: Ideally we should keep individual
12977 locations for all the variables in the var list to make the
12978 following errors more precise. Perhaps
12979 c_parser_omp_var_list_parens() should construct a list of
12980 locations to go along with the var list. */
12982 /* If V had already been marked threadprivate, it doesn't matter
12983 whether it had been used prior to this point. */
12984 if (TREE_CODE (v
) != VAR_DECL
)
12985 error_at (loc
, "%qD is not a variable", v
);
12986 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
12987 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
12988 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
12989 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
12990 else if (TREE_TYPE (v
) == error_mark_node
)
12992 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
12993 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
12996 if (! DECL_THREAD_LOCAL_P (v
))
12998 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
12999 /* If rtl has been already set for this var, call
13000 make_decl_rtl once again, so that encode_section_info
13001 has a chance to look at the new decl flags. */
13002 if (DECL_RTL_SET_P (v
))
13005 C_DECL_THREADPRIVATE_P (v
) = 1;
13009 c_parser_skip_to_pragma_eol (parser
);
13012 /* Parse a transaction attribute (GCC Extension).
13014 transaction-attribute:
13018 The transactional memory language description is written for C++,
13019 and uses the C++0x attribute syntax. For compatibility, allow the
13020 bracket style for transactions in C as well. */
13023 c_parser_transaction_attributes (c_parser
*parser
)
13025 tree attr_name
, attr
= NULL
;
13027 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13028 return c_parser_attributes (parser
);
13030 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13032 c_parser_consume_token (parser
);
13033 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13036 attr_name
= c_parser_attribute_any_word (parser
);
13039 c_parser_consume_token (parser
);
13040 attr
= build_tree_list (attr_name
, NULL_TREE
);
13043 c_parser_error (parser
, "expected identifier");
13045 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13047 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13051 /* Parse a __transaction_atomic or __transaction_relaxed statement
13054 transaction-statement:
13055 __transaction_atomic transaction-attribute[opt] compound-statement
13056 __transaction_relaxed compound-statement
13058 Note that the only valid attribute is: "outer".
13062 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13064 unsigned int old_in
= parser
->in_transaction
;
13065 unsigned int this_in
= 1, new_in
;
13066 location_t loc
= c_parser_peek_token (parser
)->location
;
13069 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13070 || keyword
== RID_TRANSACTION_RELAXED
)
13071 && c_parser_next_token_is_keyword (parser
, keyword
));
13072 c_parser_consume_token (parser
);
13074 if (keyword
== RID_TRANSACTION_RELAXED
)
13075 this_in
|= TM_STMT_ATTR_RELAXED
;
13078 attrs
= c_parser_transaction_attributes (parser
);
13080 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13083 /* Keep track if we're in the lexical scope of an outer transaction. */
13084 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13086 parser
->in_transaction
= new_in
;
13087 stmt
= c_parser_compound_statement (parser
);
13088 parser
->in_transaction
= old_in
;
13091 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13093 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13094 "%<__transaction_atomic%> without transactional memory support enabled"
13095 : "%<__transaction_relaxed %> "
13096 "without transactional memory support enabled"));
13101 /* Parse a __transaction_atomic or __transaction_relaxed expression
13104 transaction-expression:
13105 __transaction_atomic ( expression )
13106 __transaction_relaxed ( expression )
13109 static struct c_expr
13110 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13113 unsigned int old_in
= parser
->in_transaction
;
13114 unsigned int this_in
= 1;
13115 location_t loc
= c_parser_peek_token (parser
)->location
;
13118 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13119 || keyword
== RID_TRANSACTION_RELAXED
)
13120 && c_parser_next_token_is_keyword (parser
, keyword
));
13121 c_parser_consume_token (parser
);
13123 if (keyword
== RID_TRANSACTION_RELAXED
)
13124 this_in
|= TM_STMT_ATTR_RELAXED
;
13127 attrs
= c_parser_transaction_attributes (parser
);
13129 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13132 parser
->in_transaction
= this_in
;
13133 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13135 tree expr
= c_parser_expression (parser
).value
;
13136 ret
.original_type
= TREE_TYPE (expr
);
13137 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13138 if (this_in
& TM_STMT_ATTR_RELAXED
)
13139 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13140 SET_EXPR_LOCATION (ret
.value
, loc
);
13141 ret
.original_code
= TRANSACTION_EXPR
;
13142 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13144 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13151 ret
.value
= error_mark_node
;
13152 ret
.original_code
= ERROR_MARK
;
13153 ret
.original_type
= NULL
;
13155 parser
->in_transaction
= old_in
;
13158 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13159 "%<__transaction_atomic%> without transactional memory support enabled"
13160 : "%<__transaction_relaxed %> "
13161 "without transactional memory support enabled"));
13166 /* Parse a __transaction_cancel statement (GCC Extension).
13168 transaction-cancel-statement:
13169 __transaction_cancel transaction-attribute[opt] ;
13171 Note that the only valid attribute is "outer".
13175 c_parser_transaction_cancel (c_parser
*parser
)
13177 location_t loc
= c_parser_peek_token (parser
)->location
;
13179 bool is_outer
= false;
13181 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
13182 c_parser_consume_token (parser
);
13184 attrs
= c_parser_transaction_attributes (parser
);
13186 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
13190 error_at (loc
, "%<__transaction_cancel%> without "
13191 "transactional memory support enabled");
13194 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
13196 error_at (loc
, "%<__transaction_cancel%> within a "
13197 "%<__transaction_relaxed%>");
13202 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
13203 && !is_tm_may_cancel_outer (current_function_decl
))
13205 error_at (loc
, "outer %<__transaction_cancel%> not "
13206 "within outer %<__transaction_atomic%>");
13207 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
13211 else if (parser
->in_transaction
== 0)
13213 error_at (loc
, "%<__transaction_cancel%> not within "
13214 "%<__transaction_atomic%>");
13218 return add_stmt (build_tm_abort_call (loc
, is_outer
));
13221 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
13224 /* Parse a single source file. */
13227 c_parse_file (void)
13229 /* Use local storage to begin. If the first token is a pragma, parse it.
13230 If it is #pragma GCC pch_preprocess, then this will load a PCH file
13231 which will cause garbage collection. */
13234 memset (&tparser
, 0, sizeof tparser
);
13235 tparser
.tokens
= &tparser
.tokens_buf
[0];
13236 the_parser
= &tparser
;
13238 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
13239 c_parser_pragma_pch_preprocess (&tparser
);
13241 the_parser
= ggc_alloc_c_parser ();
13242 *the_parser
= tparser
;
13243 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
13244 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
13246 /* Initialize EH, if we've been told to do so. */
13247 if (flag_exceptions
)
13248 using_eh_for_cleanups ();
13250 c_parser_translation_unit (the_parser
);
13254 /* This function parses Cilk Plus array notation. The starting index is
13255 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
13256 return value of this function is a tree_node called VALUE_TREE of type
13257 ARRAY_NOTATION_REF. */
13260 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
13263 c_token
*token
= NULL
;
13264 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
13265 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
13266 tree array_type_domain
= NULL_TREE
;
13268 if (array_value
== error_mark_node
)
13270 /* No need to continue. If either of these 2 were true, then an error
13271 must be emitted already. Thus, no need to emit them twice. */
13272 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13273 return error_mark_node
;
13276 array_type
= TREE_TYPE (array_value
);
13277 gcc_assert (array_type
);
13278 type
= TREE_TYPE (array_type
);
13279 token
= c_parser_peek_token (parser
);
13281 if (token
->type
== CPP_EOF
)
13283 c_parser_error (parser
, "expected %<:%> or numeral");
13286 else if (token
->type
== CPP_COLON
)
13288 if (!initial_index
)
13290 /* If we are here, then we have a case like this A[:]. */
13291 c_parser_consume_token (parser
);
13292 if (TREE_CODE (array_type
) == POINTER_TYPE
)
13294 error_at (loc
, "start-index and length fields necessary for "
13295 "using array notations in pointers");
13296 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13297 return error_mark_node
;
13299 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13301 error_at (loc
, "array notations cannot be used with function "
13303 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13304 return error_mark_node
;
13306 array_type_domain
= TYPE_DOMAIN (array_type
);
13308 if (!array_type_domain
)
13310 error_at (loc
, "start-index and length fields necessary for "
13311 "using array notations in dimensionless arrays");
13312 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13313 return error_mark_node
;
13316 start_index
= TYPE_MINVAL (array_type_domain
);
13317 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
13319 if (!TYPE_MAXVAL (array_type_domain
)
13320 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
13322 error_at (loc
, "start-index and length fields necessary for "
13323 "using array notations in variable-length arrays");
13324 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13325 return error_mark_node
;
13327 end_index
= TYPE_MAXVAL (array_type_domain
);
13328 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
13329 end_index
, integer_one_node
);
13330 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
13331 stride
= build_int_cst (integer_type_node
, 1);
13332 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
13334 else if (initial_index
!= error_mark_node
)
13336 /* If we are here, then there should be 2 possibilities:
13337 1. Array [EXPR : EXPR]
13338 2. Array [EXPR : EXPR : EXPR]
13340 start_index
= initial_index
;
13342 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13344 error_at (loc
, "array notations cannot be used with function "
13346 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13347 return error_mark_node
;
13349 c_parser_consume_token (parser
); /* consume the ':' */
13350 end_index
= c_parser_expression (parser
).value
;
13351 if (!end_index
|| end_index
== error_mark_node
)
13353 c_parser_skip_to_end_of_block_or_statement (parser
);
13354 return error_mark_node
;
13356 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
13358 c_parser_consume_token (parser
);
13359 stride
= c_parser_expression (parser
).value
;
13360 if (!stride
|| stride
== error_mark_node
)
13362 c_parser_skip_to_end_of_block_or_statement (parser
);
13363 return error_mark_node
;
13368 c_parser_error (parser
, "expected array notation expression");
13371 c_parser_error (parser
, "expected array notation expression");
13373 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13375 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
13376 end_index
, stride
, type
);
13377 if (value_tree
!= error_mark_node
)
13378 SET_EXPR_LOCATION (value_tree
, loc
);
13382 #include "gt-c-c-parser.h"