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
)
509 if (c_dialect_objc ())
517 enum c_lookahead_kind
{
518 /* Always treat unknown identifiers as typenames. */
521 /* Could be parsing a nonabstract declarator. Only treat an identifier
522 as a typename if followed by another identifier or a star. */
523 cla_nonabstract_decl
,
525 /* Never treat identifiers as typenames. */
529 /* Return true if the next token from PARSER can start a type name,
530 false otherwise. LA specifies how to do lookahead in order to
531 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
534 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
536 c_token
*token
= c_parser_peek_token (parser
);
537 if (c_token_starts_typename (token
))
540 /* Try a bit harder to detect an unknown typename. */
541 if (la
!= cla_prefer_id
542 && token
->type
== CPP_NAME
543 && token
->id_kind
== C_ID_ID
545 /* Do not try too hard when we could have "object in array". */
546 && !parser
->objc_could_be_foreach_context
548 && (la
== cla_prefer_type
549 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
550 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
552 /* Only unknown identifiers. */
553 && !lookup_name (token
->value
))
559 /* Return true if TOKEN is a type qualifier, false otherwise. */
561 c_token_is_qualifier (c_token
*token
)
566 switch (token
->id_kind
)
574 switch (token
->keyword
)
592 /* Return true if the next token from PARSER is a type qualifier,
595 c_parser_next_token_is_qualifier (c_parser
*parser
)
597 c_token
*token
= c_parser_peek_token (parser
);
598 return c_token_is_qualifier (token
);
601 /* Return true if TOKEN can start declaration specifiers, false
604 c_token_starts_declspecs (c_token
*token
)
609 switch (token
->id_kind
)
618 gcc_assert (c_dialect_objc ());
624 switch (token
->keyword
)
667 if (c_dialect_objc ())
676 /* Return true if TOKEN can start declaration specifiers or a static
677 assertion, false otherwise. */
679 c_token_starts_declaration (c_token
*token
)
681 if (c_token_starts_declspecs (token
)
682 || token
->keyword
== RID_STATIC_ASSERT
)
688 /* Return true if the next token from PARSER can start declaration
689 specifiers, false otherwise. */
691 c_parser_next_token_starts_declspecs (c_parser
*parser
)
693 c_token
*token
= c_parser_peek_token (parser
);
695 /* In Objective-C, a classname normally starts a declspecs unless it
696 is immediately followed by a dot. In that case, it is the
697 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
698 setter/getter on the class. c_token_starts_declspecs() can't
699 differentiate between the two cases because it only checks the
700 current token, so we have a special check here. */
701 if (c_dialect_objc ()
702 && token
->type
== CPP_NAME
703 && token
->id_kind
== C_ID_CLASSNAME
704 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
707 return c_token_starts_declspecs (token
);
710 /* Return true if the next tokens from PARSER can start declaration
711 specifiers or a static assertion, false otherwise. */
713 c_parser_next_tokens_start_declaration (c_parser
*parser
)
715 c_token
*token
= c_parser_peek_token (parser
);
718 if (c_dialect_objc ()
719 && token
->type
== CPP_NAME
720 && token
->id_kind
== C_ID_CLASSNAME
721 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
724 /* Labels do not start declarations. */
725 if (token
->type
== CPP_NAME
726 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
729 if (c_token_starts_declaration (token
))
732 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
738 /* Consume the next token from PARSER. */
741 c_parser_consume_token (c_parser
*parser
)
743 gcc_assert (parser
->tokens_avail
>= 1);
744 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
745 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
746 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
747 if (parser
->tokens
!= &parser
->tokens_buf
[0])
749 else if (parser
->tokens_avail
== 2)
750 parser
->tokens
[0] = parser
->tokens
[1];
751 parser
->tokens_avail
--;
754 /* Expect the current token to be a #pragma. Consume it and remember
755 that we've begun parsing a pragma. */
758 c_parser_consume_pragma (c_parser
*parser
)
760 gcc_assert (!parser
->in_pragma
);
761 gcc_assert (parser
->tokens_avail
>= 1);
762 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
763 if (parser
->tokens
!= &parser
->tokens_buf
[0])
765 else if (parser
->tokens_avail
== 2)
766 parser
->tokens
[0] = parser
->tokens
[1];
767 parser
->tokens_avail
--;
768 parser
->in_pragma
= true;
771 /* Update the globals input_location and in_system_header from
774 c_parser_set_source_position_from_token (c_token
*token
)
776 if (token
->type
!= CPP_EOF
)
778 input_location
= token
->location
;
782 /* Issue a diagnostic of the form
783 FILE:LINE: MESSAGE before TOKEN
784 where TOKEN is the next token in the input stream of PARSER.
785 MESSAGE (specified by the caller) is usually of the form "expected
788 Do not issue a diagnostic if still recovering from an error.
790 ??? This is taken from the C++ parser, but building up messages in
791 this way is not i18n-friendly and some other approach should be
795 c_parser_error (c_parser
*parser
, const char *gmsgid
)
797 c_token
*token
= c_parser_peek_token (parser
);
800 parser
->error
= true;
803 /* This diagnostic makes more sense if it is tagged to the line of
804 the token we just peeked at. */
805 c_parser_set_source_position_from_token (token
);
806 c_parse_error (gmsgid
,
807 /* Because c_parse_error does not understand
808 CPP_KEYWORD, keywords are treated like
810 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
811 /* ??? The C parser does not save the cpp flags of a
812 token, we need to pass 0 here and we will not get
813 the source spelling of some tokens but rather the
814 canonical spelling. */
815 token
->value
, /*flags=*/0);
818 /* If the next token is of the indicated TYPE, consume it. Otherwise,
819 issue the error MSGID. If MSGID is NULL then a message has already
820 been produced and no message will be produced this time. Returns
821 true if found, false otherwise. */
824 c_parser_require (c_parser
*parser
,
828 if (c_parser_next_token_is (parser
, type
))
830 c_parser_consume_token (parser
);
835 c_parser_error (parser
, msgid
);
840 /* If the next token is the indicated keyword, consume it. Otherwise,
841 issue the error MSGID. Returns true if found, false otherwise. */
844 c_parser_require_keyword (c_parser
*parser
,
848 if (c_parser_next_token_is_keyword (parser
, keyword
))
850 c_parser_consume_token (parser
);
855 c_parser_error (parser
, msgid
);
860 /* Like c_parser_require, except that tokens will be skipped until the
861 desired token is found. An error message is still produced if the
862 next token is not as expected. If MSGID is NULL then a message has
863 already been produced and no message will be produced this
867 c_parser_skip_until_found (c_parser
*parser
,
871 unsigned nesting_depth
= 0;
873 if (c_parser_require (parser
, type
, msgid
))
876 /* Skip tokens until the desired token is found. */
879 /* Peek at the next token. */
880 c_token
*token
= c_parser_peek_token (parser
);
881 /* If we've reached the token we want, consume it and stop. */
882 if (token
->type
== type
&& !nesting_depth
)
884 c_parser_consume_token (parser
);
888 /* If we've run out of tokens, stop. */
889 if (token
->type
== CPP_EOF
)
891 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
893 if (token
->type
== CPP_OPEN_BRACE
894 || token
->type
== CPP_OPEN_PAREN
895 || token
->type
== CPP_OPEN_SQUARE
)
897 else if (token
->type
== CPP_CLOSE_BRACE
898 || token
->type
== CPP_CLOSE_PAREN
899 || token
->type
== CPP_CLOSE_SQUARE
)
901 if (nesting_depth
-- == 0)
904 /* Consume this token. */
905 c_parser_consume_token (parser
);
907 parser
->error
= false;
910 /* Skip tokens until the end of a parameter is found, but do not
911 consume the comma, semicolon or closing delimiter. */
914 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
916 unsigned nesting_depth
= 0;
920 c_token
*token
= c_parser_peek_token (parser
);
921 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
924 /* If we've run out of tokens, stop. */
925 if (token
->type
== CPP_EOF
)
927 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
929 if (token
->type
== CPP_OPEN_BRACE
930 || token
->type
== CPP_OPEN_PAREN
931 || token
->type
== CPP_OPEN_SQUARE
)
933 else if (token
->type
== CPP_CLOSE_BRACE
934 || token
->type
== CPP_CLOSE_PAREN
935 || token
->type
== CPP_CLOSE_SQUARE
)
937 if (nesting_depth
-- == 0)
940 /* Consume this token. */
941 c_parser_consume_token (parser
);
943 parser
->error
= false;
946 /* Expect to be at the end of the pragma directive and consume an
947 end of line marker. */
950 c_parser_skip_to_pragma_eol (c_parser
*parser
)
952 gcc_assert (parser
->in_pragma
);
953 parser
->in_pragma
= false;
955 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
958 c_token
*token
= c_parser_peek_token (parser
);
959 if (token
->type
== CPP_EOF
)
961 if (token
->type
== CPP_PRAGMA_EOL
)
963 c_parser_consume_token (parser
);
966 c_parser_consume_token (parser
);
969 parser
->error
= false;
972 /* Skip tokens until we have consumed an entire block, or until we
973 have consumed a non-nested ';'. */
976 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
978 unsigned nesting_depth
= 0;
979 bool save_error
= parser
->error
;
985 /* Peek at the next token. */
986 token
= c_parser_peek_token (parser
);
994 if (parser
->in_pragma
)
999 /* If the next token is a ';', we have reached the
1000 end of the statement. */
1003 /* Consume the ';'. */
1004 c_parser_consume_token (parser
);
1009 case CPP_CLOSE_BRACE
:
1010 /* If the next token is a non-nested '}', then we have
1011 reached the end of the current block. */
1012 if (nesting_depth
== 0 || --nesting_depth
== 0)
1014 c_parser_consume_token (parser
);
1019 case CPP_OPEN_BRACE
:
1020 /* If it the next token is a '{', then we are entering a new
1021 block. Consume the entire block. */
1026 /* If we see a pragma, consume the whole thing at once. We
1027 have some safeguards against consuming pragmas willy-nilly.
1028 Normally, we'd expect to be here with parser->error set,
1029 which disables these safeguards. But it's possible to get
1030 here for secondary error recovery, after parser->error has
1032 c_parser_consume_pragma (parser
);
1033 c_parser_skip_to_pragma_eol (parser
);
1034 parser
->error
= save_error
;
1041 c_parser_consume_token (parser
);
1045 parser
->error
= false;
1048 /* CPP's options (initialized by c-opts.c). */
1049 extern cpp_options
*cpp_opts
;
1051 /* Save the warning flags which are controlled by __extension__. */
1054 disable_extension_diagnostics (void)
1057 | (warn_pointer_arith
<< 1)
1058 | (warn_traditional
<< 2)
1060 | (warn_long_long
<< 4)
1061 | (warn_cxx_compat
<< 5)
1062 | (warn_overlength_strings
<< 6));
1063 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1064 warn_pointer_arith
= 0;
1065 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1067 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1068 warn_cxx_compat
= 0;
1069 warn_overlength_strings
= 0;
1073 /* Restore the warning flags which are controlled by __extension__.
1074 FLAGS is the return value from disable_extension_diagnostics. */
1077 restore_extension_diagnostics (int flags
)
1079 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1080 warn_pointer_arith
= (flags
>> 1) & 1;
1081 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1082 flag_iso
= (flags
>> 3) & 1;
1083 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1084 warn_cxx_compat
= (flags
>> 5) & 1;
1085 warn_overlength_strings
= (flags
>> 6) & 1;
1088 /* Possibly kinds of declarator to parse. */
1089 typedef enum c_dtr_syn
{
1090 /* A normal declarator with an identifier. */
1092 /* An abstract declarator (maybe empty). */
1094 /* A parameter declarator: may be either, but after a type name does
1095 not redeclare a typedef name as an identifier if it can
1096 alternatively be interpreted as a typedef name; see DR#009,
1097 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1098 following DR#249. For example, given a typedef T, "int T" and
1099 "int *T" are valid parameter declarations redeclaring T, while
1100 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1101 abstract declarators rather than involving redundant parentheses;
1102 the same applies with attributes inside the parentheses before
1107 /* The binary operation precedence levels, where 0 is a dummy lowest level
1108 used for the bottom of the stack. */
1109 enum c_parser_prec
{
1124 static void c_parser_external_declaration (c_parser
*);
1125 static void c_parser_asm_definition (c_parser
*);
1126 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1127 bool, bool, tree
*, vec
<c_token
>);
1128 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1129 static void c_parser_static_assert_declaration (c_parser
*);
1130 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1131 bool, bool, enum c_lookahead_kind
);
1132 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1133 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1134 static tree
c_parser_struct_declaration (c_parser
*);
1135 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1136 static tree
c_parser_alignas_specifier (c_parser
*);
1137 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1139 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1141 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1143 struct c_declarator
*);
1144 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1145 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1147 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1148 static tree
c_parser_simple_asm_expr (c_parser
*);
1149 static tree
c_parser_attributes (c_parser
*);
1150 static struct c_type_name
*c_parser_type_name (c_parser
*);
1151 static struct c_expr
c_parser_initializer (c_parser
*);
1152 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1153 static void c_parser_initelt (c_parser
*, struct obstack
*);
1154 static void c_parser_initval (c_parser
*, struct c_expr
*,
1156 static tree
c_parser_compound_statement (c_parser
*);
1157 static void c_parser_compound_statement_nostart (c_parser
*);
1158 static void c_parser_label (c_parser
*);
1159 static void c_parser_statement (c_parser
*);
1160 static void c_parser_statement_after_labels (c_parser
*);
1161 static void c_parser_if_statement (c_parser
*);
1162 static void c_parser_switch_statement (c_parser
*);
1163 static void c_parser_while_statement (c_parser
*, bool);
1164 static void c_parser_do_statement (c_parser
*, bool);
1165 static void c_parser_for_statement (c_parser
*, bool);
1166 static tree
c_parser_asm_statement (c_parser
*);
1167 static tree
c_parser_asm_operands (c_parser
*);
1168 static tree
c_parser_asm_goto_operands (c_parser
*);
1169 static tree
c_parser_asm_clobbers (c_parser
*);
1170 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1172 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1173 struct c_expr
*, tree
);
1174 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1176 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1177 static struct c_expr
c_parser_unary_expression (c_parser
*);
1178 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1179 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1180 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1181 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1182 struct c_type_name
*,
1184 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1187 static tree
c_parser_transaction (c_parser
*, enum rid
);
1188 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1189 static tree
c_parser_transaction_cancel (c_parser
*);
1190 static struct c_expr
c_parser_expression (c_parser
*);
1191 static struct c_expr
c_parser_expression_conv (c_parser
*);
1192 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1193 vec
<tree
, va_gc
> **, location_t
*,
1195 static void c_parser_omp_construct (c_parser
*);
1196 static void c_parser_omp_threadprivate (c_parser
*);
1197 static void c_parser_omp_barrier (c_parser
*);
1198 static void c_parser_omp_flush (c_parser
*);
1199 static void c_parser_omp_taskwait (c_parser
*);
1200 static void c_parser_omp_taskyield (c_parser
*);
1201 static void c_parser_omp_cancel (c_parser
*);
1202 static void c_parser_omp_cancellation_point (c_parser
*);
1204 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1205 pragma_stmt
, pragma_compound
};
1206 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1207 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1208 static void c_parser_omp_end_declare_target (c_parser
*);
1209 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1211 /* These Objective-C parser functions are only ever called when
1212 compiling Objective-C. */
1213 static void c_parser_objc_class_definition (c_parser
*, tree
);
1214 static void c_parser_objc_class_instance_variables (c_parser
*);
1215 static void c_parser_objc_class_declaration (c_parser
*);
1216 static void c_parser_objc_alias_declaration (c_parser
*);
1217 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1218 static bool c_parser_objc_method_type (c_parser
*);
1219 static void c_parser_objc_method_definition (c_parser
*);
1220 static void c_parser_objc_methodprotolist (c_parser
*);
1221 static void c_parser_objc_methodproto (c_parser
*);
1222 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1223 static tree
c_parser_objc_type_name (c_parser
*);
1224 static tree
c_parser_objc_protocol_refs (c_parser
*);
1225 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1226 static void c_parser_objc_synchronized_statement (c_parser
*);
1227 static tree
c_parser_objc_selector (c_parser
*);
1228 static tree
c_parser_objc_selector_arg (c_parser
*);
1229 static tree
c_parser_objc_receiver (c_parser
*);
1230 static tree
c_parser_objc_message_args (c_parser
*);
1231 static tree
c_parser_objc_keywordexpr (c_parser
*);
1232 static void c_parser_objc_at_property_declaration (c_parser
*);
1233 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1234 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1235 static bool c_parser_objc_diagnose_bad_element_prefix
1236 (c_parser
*, struct c_declspecs
*);
1238 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1240 /* Parse a translation unit (C90 6.7, C99 6.9).
1243 external-declarations
1245 external-declarations:
1246 external-declaration
1247 external-declarations external-declaration
1256 c_parser_translation_unit (c_parser
*parser
)
1258 if (c_parser_next_token_is (parser
, CPP_EOF
))
1260 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1261 "ISO C forbids an empty translation unit");
1265 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1266 mark_valid_location_for_stdc_pragma (false);
1270 c_parser_external_declaration (parser
);
1271 obstack_free (&parser_obstack
, obstack_position
);
1273 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1277 /* Parse an external declaration (C90 6.7, C99 6.9).
1279 external-declaration:
1285 external-declaration:
1288 __extension__ external-declaration
1292 external-declaration:
1293 objc-class-definition
1294 objc-class-declaration
1295 objc-alias-declaration
1296 objc-protocol-definition
1297 objc-method-definition
1302 c_parser_external_declaration (c_parser
*parser
)
1305 switch (c_parser_peek_token (parser
)->type
)
1308 switch (c_parser_peek_token (parser
)->keyword
)
1311 ext
= disable_extension_diagnostics ();
1312 c_parser_consume_token (parser
);
1313 c_parser_external_declaration (parser
);
1314 restore_extension_diagnostics (ext
);
1317 c_parser_asm_definition (parser
);
1319 case RID_AT_INTERFACE
:
1320 case RID_AT_IMPLEMENTATION
:
1321 gcc_assert (c_dialect_objc ());
1322 c_parser_objc_class_definition (parser
, NULL_TREE
);
1325 gcc_assert (c_dialect_objc ());
1326 c_parser_objc_class_declaration (parser
);
1329 gcc_assert (c_dialect_objc ());
1330 c_parser_objc_alias_declaration (parser
);
1332 case RID_AT_PROTOCOL
:
1333 gcc_assert (c_dialect_objc ());
1334 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1336 case RID_AT_PROPERTY
:
1337 gcc_assert (c_dialect_objc ());
1338 c_parser_objc_at_property_declaration (parser
);
1340 case RID_AT_SYNTHESIZE
:
1341 gcc_assert (c_dialect_objc ());
1342 c_parser_objc_at_synthesize_declaration (parser
);
1344 case RID_AT_DYNAMIC
:
1345 gcc_assert (c_dialect_objc ());
1346 c_parser_objc_at_dynamic_declaration (parser
);
1349 gcc_assert (c_dialect_objc ());
1350 c_parser_consume_token (parser
);
1351 objc_finish_implementation ();
1358 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1359 "ISO C does not allow extra %<;%> outside of a function");
1360 c_parser_consume_token (parser
);
1363 mark_valid_location_for_stdc_pragma (true);
1364 c_parser_pragma (parser
, pragma_external
);
1365 mark_valid_location_for_stdc_pragma (false);
1369 if (c_dialect_objc ())
1371 c_parser_objc_method_definition (parser
);
1374 /* Else fall through, and yield a syntax error trying to parse
1375 as a declaration or function definition. */
1378 /* A declaration or a function definition (or, in Objective-C,
1379 an @interface or @protocol with prefix attributes). We can
1380 only tell which after parsing the declaration specifiers, if
1381 any, and the first declarator. */
1382 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1388 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1390 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1391 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1392 accepted; otherwise (old-style parameter declarations) only other
1393 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1394 assertion is accepted; otherwise (old-style parameter declarations)
1395 it is not. If NESTED is true, we are inside a function or parsing
1396 old-style parameter declarations; any functions encountered are
1397 nested functions and declaration specifiers are required; otherwise
1398 we are at top level and functions are normal functions and
1399 declaration specifiers may be optional. If EMPTY_OK is true, empty
1400 declarations are OK (subject to all other constraints); otherwise
1401 (old-style parameter declarations) they are diagnosed. If
1402 START_ATTR_OK is true, the declaration specifiers may start with
1403 attributes; otherwise they may not.
1404 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1405 declaration when parsing an Objective-C foreach statement.
1408 declaration-specifiers init-declarator-list[opt] ;
1409 static_assert-declaration
1411 function-definition:
1412 declaration-specifiers[opt] declarator declaration-list[opt]
1417 declaration-list declaration
1419 init-declarator-list:
1421 init-declarator-list , init-declarator
1424 declarator simple-asm-expr[opt] attributes[opt]
1425 declarator simple-asm-expr[opt] attributes[opt] = initializer
1429 nested-function-definition:
1430 declaration-specifiers declarator declaration-list[opt]
1434 attributes objc-class-definition
1435 attributes objc-category-definition
1436 attributes objc-protocol-definition
1438 The simple-asm-expr and attributes are GNU extensions.
1440 This function does not handle __extension__; that is handled in its
1441 callers. ??? Following the old parser, __extension__ may start
1442 external declarations, declarations in functions and declarations
1443 at the start of "for" loops, but not old-style parameter
1446 C99 requires declaration specifiers in a function definition; the
1447 absence is diagnosed through the diagnosis of implicit int. In GNU
1448 C we also allow but diagnose declarations without declaration
1449 specifiers, but only at top level (elsewhere they conflict with
1452 In Objective-C, declarations of the looping variable in a foreach
1453 statement are exceptionally terminated by 'in' (for example, 'for
1454 (NSObject *object in array) { ... }').
1459 threadprivate-directive */
1462 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1463 bool static_assert_ok
, bool empty_ok
,
1464 bool nested
, bool start_attr_ok
,
1465 tree
*objc_foreach_object_declaration
,
1466 vec
<c_token
> omp_declare_simd_clauses
)
1468 struct c_declspecs
*specs
;
1470 tree all_prefix_attrs
;
1471 bool diagnosed_no_specs
= false;
1472 location_t here
= c_parser_peek_token (parser
)->location
;
1474 if (static_assert_ok
1475 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1477 c_parser_static_assert_declaration (parser
);
1480 specs
= build_null_declspecs ();
1482 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1483 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1484 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1485 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1486 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1487 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1489 error_at (here
, "unknown type name %qE",
1490 c_parser_peek_token (parser
)->value
);
1492 /* Parse declspecs normally to get a correct pointer type, but avoid
1493 a further "fails to be a type name" error. Refuse nested functions
1494 since it is not how the user likely wants us to recover. */
1495 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1496 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1497 c_parser_peek_token (parser
)->value
= error_mark_node
;
1501 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1502 true, cla_nonabstract_decl
);
1505 c_parser_skip_to_end_of_block_or_statement (parser
);
1508 if (nested
&& !specs
->declspecs_seen_p
)
1510 c_parser_error (parser
, "expected declaration specifiers");
1511 c_parser_skip_to_end_of_block_or_statement (parser
);
1514 finish_declspecs (specs
);
1515 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1521 shadow_tag_warned (specs
, 1);
1522 pedwarn (here
, 0, "empty declaration");
1524 c_parser_consume_token (parser
);
1528 /* Provide better error recovery. Note that a type name here is usually
1529 better diagnosed as a redeclaration. */
1531 && specs
->typespec_kind
== ctsk_tagdef
1532 && c_parser_next_token_starts_declspecs (parser
)
1533 && !c_parser_next_token_is (parser
, CPP_NAME
))
1535 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1536 parser
->error
= false;
1537 shadow_tag_warned (specs
, 1);
1540 else if (c_dialect_objc ())
1542 /* Prefix attributes are an error on method decls. */
1543 switch (c_parser_peek_token (parser
)->type
)
1547 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1551 warning_at (c_parser_peek_token (parser
)->location
,
1553 "prefix attributes are ignored for methods");
1554 specs
->attrs
= NULL_TREE
;
1557 c_parser_objc_method_definition (parser
);
1559 c_parser_objc_methodproto (parser
);
1565 /* This is where we parse 'attributes @interface ...',
1566 'attributes @implementation ...', 'attributes @protocol ...'
1567 (where attributes could be, for example, __attribute__
1570 switch (c_parser_peek_token (parser
)->keyword
)
1572 case RID_AT_INTERFACE
:
1574 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1576 c_parser_objc_class_definition (parser
, specs
->attrs
);
1580 case RID_AT_IMPLEMENTATION
:
1582 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1586 warning_at (c_parser_peek_token (parser
)->location
,
1588 "prefix attributes are ignored for implementations");
1589 specs
->attrs
= NULL_TREE
;
1591 c_parser_objc_class_definition (parser
, NULL_TREE
);
1595 case RID_AT_PROTOCOL
:
1597 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1599 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1606 case RID_AT_PROPERTY
:
1609 c_parser_error (parser
, "unexpected attribute");
1610 specs
->attrs
= NULL
;
1618 pending_xref_error ();
1619 prefix_attrs
= specs
->attrs
;
1620 all_prefix_attrs
= prefix_attrs
;
1621 specs
->attrs
= NULL_TREE
;
1624 struct c_declarator
*declarator
;
1628 /* Declaring either one or more declarators (in which case we
1629 should diagnose if there were no declaration specifiers) or a
1630 function definition (in which case the diagnostic for
1631 implicit int suffices). */
1632 declarator
= c_parser_declarator (parser
,
1633 specs
->typespec_kind
!= ctsk_none
,
1634 C_DTR_NORMAL
, &dummy
);
1635 if (declarator
== NULL
)
1637 if (omp_declare_simd_clauses
.exists ())
1638 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1639 omp_declare_simd_clauses
);
1640 c_parser_skip_to_end_of_block_or_statement (parser
);
1643 if (c_parser_next_token_is (parser
, CPP_EQ
)
1644 || c_parser_next_token_is (parser
, CPP_COMMA
)
1645 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1646 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1647 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1648 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1650 tree asm_name
= NULL_TREE
;
1651 tree postfix_attrs
= NULL_TREE
;
1652 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1654 diagnosed_no_specs
= true;
1655 pedwarn (here
, 0, "data definition has no type or storage class");
1657 /* Having seen a data definition, there cannot now be a
1658 function definition. */
1660 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1661 asm_name
= c_parser_simple_asm_expr (parser
);
1662 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1663 postfix_attrs
= c_parser_attributes (parser
);
1664 if (c_parser_next_token_is (parser
, CPP_EQ
))
1668 location_t init_loc
;
1669 c_parser_consume_token (parser
);
1670 /* The declaration of the variable is in effect while
1671 its initializer is parsed. */
1672 d
= start_decl (declarator
, specs
, true,
1673 chainon (postfix_attrs
, all_prefix_attrs
));
1675 d
= error_mark_node
;
1676 if (omp_declare_simd_clauses
.exists ())
1677 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1678 omp_declare_simd_clauses
);
1679 start_init (d
, asm_name
, global_bindings_p ());
1680 init_loc
= c_parser_peek_token (parser
)->location
;
1681 init
= c_parser_initializer (parser
);
1683 if (d
!= error_mark_node
)
1685 maybe_warn_string_init (TREE_TYPE (d
), init
);
1686 finish_decl (d
, init_loc
, init
.value
,
1687 init
.original_type
, asm_name
);
1692 tree d
= start_decl (declarator
, specs
, false,
1693 chainon (postfix_attrs
,
1695 if (omp_declare_simd_clauses
.exists ())
1697 tree parms
= NULL_TREE
;
1698 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1700 struct c_declarator
*ce
= declarator
;
1702 if (ce
->kind
== cdk_function
)
1704 parms
= ce
->u
.arg_info
->parms
;
1708 ce
= ce
->declarator
;
1711 temp_store_parm_decls (d
, parms
);
1712 c_finish_omp_declare_simd (parser
, d
, parms
,
1713 omp_declare_simd_clauses
);
1715 temp_pop_parm_decls ();
1718 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1719 NULL_TREE
, asm_name
);
1721 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1724 *objc_foreach_object_declaration
= d
;
1726 *objc_foreach_object_declaration
= error_mark_node
;
1729 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1731 c_parser_consume_token (parser
);
1732 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1733 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1736 all_prefix_attrs
= prefix_attrs
;
1739 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1741 c_parser_consume_token (parser
);
1744 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1746 /* This can only happen in Objective-C: we found the
1747 'in' that terminates the declaration inside an
1748 Objective-C foreach statement. Do not consume the
1749 token, so that the caller can use it to determine
1750 that this indeed is a foreach context. */
1755 c_parser_error (parser
, "expected %<,%> or %<;%>");
1756 c_parser_skip_to_end_of_block_or_statement (parser
);
1762 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1763 "%<asm%> or %<__attribute__%>");
1764 c_parser_skip_to_end_of_block_or_statement (parser
);
1767 /* Function definition (nested or otherwise). */
1770 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1771 c_push_function_context ();
1773 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1775 /* This can appear in many cases looking nothing like a
1776 function definition, so we don't give a more specific
1777 error suggesting there was one. */
1778 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1779 "or %<__attribute__%>");
1781 c_pop_function_context ();
1785 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1786 tv
= TV_PARSE_INLINE
;
1791 /* Parse old-style parameter declarations. ??? Attributes are
1792 not allowed to start declaration specifiers here because of a
1793 syntax conflict between a function declaration with attribute
1794 suffix and a function definition with an attribute prefix on
1795 first old-style parameter declaration. Following the old
1796 parser, they are not accepted on subsequent old-style
1797 parameter declarations either. However, there is no
1798 ambiguity after the first declaration, nor indeed on the
1799 first as long as we don't allow postfix attributes after a
1800 declarator with a nonempty identifier list in a definition;
1801 and postfix attributes have never been accepted here in
1802 function definitions either. */
1803 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1804 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1805 c_parser_declaration_or_fndef (parser
, false, false, false,
1806 true, false, NULL
, vNULL
);
1807 store_parm_decls ();
1808 if (omp_declare_simd_clauses
.exists ())
1809 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1810 omp_declare_simd_clauses
);
1811 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1812 = c_parser_peek_token (parser
)->location
;
1813 fnbody
= c_parser_compound_statement (parser
);
1814 if (flag_enable_cilkplus
&& contains_array_notation_expr (fnbody
))
1815 fnbody
= expand_array_notation_exprs (fnbody
);
1818 tree decl
= current_function_decl
;
1819 /* Mark nested functions as needing static-chain initially.
1820 lower_nested_functions will recompute it but the
1821 DECL_STATIC_CHAIN flag is also used before that happens,
1822 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1823 DECL_STATIC_CHAIN (decl
) = 1;
1826 c_pop_function_context ();
1827 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1840 /* Parse an asm-definition (asm() outside a function body). This is a
1848 c_parser_asm_definition (c_parser
*parser
)
1850 tree asm_str
= c_parser_simple_asm_expr (parser
);
1852 add_asm_node (asm_str
);
1853 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1856 /* Parse a static assertion (C11 6.7.10).
1858 static_assert-declaration:
1859 static_assert-declaration-no-semi ;
1863 c_parser_static_assert_declaration (c_parser
*parser
)
1865 c_parser_static_assert_declaration_no_semi (parser
);
1867 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1868 c_parser_skip_to_end_of_block_or_statement (parser
);
1871 /* Parse a static assertion (C11 6.7.10), without the trailing
1874 static_assert-declaration-no-semi:
1875 _Static_assert ( constant-expression , string-literal )
1879 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1881 location_t assert_loc
, value_loc
;
1885 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1886 assert_loc
= c_parser_peek_token (parser
)->location
;
1890 pedwarn (assert_loc
, OPT_Wpedantic
,
1891 "ISO C99 does not support %<_Static_assert%>");
1893 pedwarn (assert_loc
, OPT_Wpedantic
,
1894 "ISO C90 does not support %<_Static_assert%>");
1896 c_parser_consume_token (parser
);
1897 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1899 value_loc
= c_parser_peek_token (parser
)->location
;
1900 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1901 parser
->lex_untranslated_string
= true;
1902 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1904 parser
->lex_untranslated_string
= false;
1907 switch (c_parser_peek_token (parser
)->type
)
1913 case CPP_UTF8STRING
:
1914 string
= c_parser_peek_token (parser
)->value
;
1915 c_parser_consume_token (parser
);
1916 parser
->lex_untranslated_string
= false;
1919 c_parser_error (parser
, "expected string literal");
1920 parser
->lex_untranslated_string
= false;
1923 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1925 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1927 error_at (value_loc
, "expression in static assertion is not an integer");
1930 if (TREE_CODE (value
) != INTEGER_CST
)
1932 value
= c_fully_fold (value
, false, NULL
);
1933 if (TREE_CODE (value
) == INTEGER_CST
)
1934 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1935 "is not an integer constant expression");
1937 if (TREE_CODE (value
) != INTEGER_CST
)
1939 error_at (value_loc
, "expression in static assertion is not constant");
1942 constant_expression_warning (value
);
1943 if (integer_zerop (value
))
1944 error_at (assert_loc
, "static assertion failed: %E", string
);
1947 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1948 6.7), adding them to SPECS (which may already include some).
1949 Storage class specifiers are accepted iff SCSPEC_OK; type
1950 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
1951 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
1954 declaration-specifiers:
1955 storage-class-specifier declaration-specifiers[opt]
1956 type-specifier declaration-specifiers[opt]
1957 type-qualifier declaration-specifiers[opt]
1958 function-specifier declaration-specifiers[opt]
1959 alignment-specifier declaration-specifiers[opt]
1961 Function specifiers (inline) are from C99, and are currently
1962 handled as storage class specifiers, as is __thread. Alignment
1963 specifiers are from C11.
1965 C90 6.5.1, C99 6.7.1:
1966 storage-class-specifier:
1974 (_Thread_local is new in C11.)
1981 (_Noreturn is new in C11.)
1983 C90 6.5.2, C99 6.7.2:
1996 [_Imaginary removed in C99 TC2]
1997 struct-or-union-specifier
2000 atomic-type-specifier
2002 (_Bool and _Complex are new in C99.)
2003 (atomic-type-specifier is new in C11.)
2005 C90 6.5.3, C99 6.7.3:
2011 address-space-qualifier
2014 (restrict is new in C99.)
2015 (_Atomic is new in C11.)
2019 declaration-specifiers:
2020 attributes declaration-specifiers[opt]
2026 identifier recognized by the target
2028 storage-class-specifier:
2041 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2042 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2044 atomic-type-specifier
2045 _Atomic ( type-name )
2050 class-name objc-protocol-refs[opt]
2051 typedef-name objc-protocol-refs
2056 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2057 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2058 bool alignspec_ok
, enum c_lookahead_kind la
)
2060 bool attrs_ok
= start_attr_ok
;
2061 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2064 gcc_assert (la
== cla_prefer_id
);
2066 while (c_parser_next_token_is (parser
, CPP_NAME
)
2067 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2068 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2070 struct c_typespec t
;
2073 location_t loc
= c_parser_peek_token (parser
)->location
;
2075 /* If we cannot accept a type, exit if the next token must start
2076 one. Also, if we already have seen a tagged definition,
2077 a typename would be an error anyway and likely the user
2078 has simply forgotten a semicolon, so we exit. */
2079 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2080 && c_parser_next_tokens_start_typename (parser
, la
)
2081 && !c_parser_next_token_is_qualifier (parser
))
2084 if (c_parser_next_token_is (parser
, CPP_NAME
))
2086 c_token
*name_token
= c_parser_peek_token (parser
);
2087 tree value
= name_token
->value
;
2088 c_id_kind kind
= name_token
->id_kind
;
2090 if (kind
== C_ID_ADDRSPACE
)
2093 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2094 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2095 c_parser_consume_token (parser
);
2100 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2102 /* If we cannot accept a type, and the next token must start one,
2103 exit. Do the same if we already have seen a tagged definition,
2104 since it would be an error anyway and likely the user has simply
2105 forgotten a semicolon. */
2106 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2109 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2110 a C_ID_CLASSNAME. */
2111 c_parser_consume_token (parser
);
2114 if (kind
== C_ID_ID
)
2116 error ("unknown type name %qE", value
);
2117 t
.kind
= ctsk_typedef
;
2118 t
.spec
= error_mark_node
;
2120 else if (kind
== C_ID_TYPENAME
2121 && (!c_dialect_objc ()
2122 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2124 t
.kind
= ctsk_typedef
;
2125 /* For a typedef name, record the meaning, not the name.
2126 In case of 'foo foo, bar;'. */
2127 t
.spec
= lookup_name (value
);
2131 tree proto
= NULL_TREE
;
2132 gcc_assert (c_dialect_objc ());
2134 if (c_parser_next_token_is (parser
, CPP_LESS
))
2135 proto
= c_parser_objc_protocol_refs (parser
);
2136 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2139 t
.expr_const_operands
= true;
2140 declspecs_add_type (name_token
->location
, specs
, t
);
2143 if (c_parser_next_token_is (parser
, CPP_LESS
))
2145 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2146 nisse@lysator.liu.se. */
2148 gcc_assert (c_dialect_objc ());
2149 if (!typespec_ok
|| seen_type
)
2151 proto
= c_parser_objc_protocol_refs (parser
);
2153 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2155 t
.expr_const_operands
= true;
2156 declspecs_add_type (loc
, specs
, t
);
2159 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2160 switch (c_parser_peek_token (parser
)->keyword
)
2173 /* TODO: Distinguish between function specifiers (inline, noreturn)
2174 and storage class specifiers, either here or in
2175 declspecs_add_scspec. */
2176 declspecs_add_scspec (loc
, specs
,
2177 c_parser_peek_token (parser
)->value
);
2178 c_parser_consume_token (parser
);
2202 if (c_dialect_objc ())
2203 parser
->objc_need_raw_identifier
= true;
2204 t
.kind
= ctsk_resword
;
2205 t
.spec
= c_parser_peek_token (parser
)->value
;
2207 t
.expr_const_operands
= true;
2208 declspecs_add_type (loc
, specs
, t
);
2209 c_parser_consume_token (parser
);
2216 t
= c_parser_enum_specifier (parser
);
2217 declspecs_add_type (loc
, specs
, t
);
2225 t
= c_parser_struct_or_union_specifier (parser
);
2226 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2227 declspecs_add_type (loc
, specs
, t
);
2230 /* ??? The old parser rejected typeof after other type
2231 specifiers, but is a syntax error the best way of
2233 if (!typespec_ok
|| seen_type
)
2237 t
= c_parser_typeof_specifier (parser
);
2238 declspecs_add_type (loc
, specs
, t
);
2241 /* C parser handling of Objective-C constructs needs
2242 checking for correct lvalue-to-rvalue conversions, and
2243 the code in build_modify_expr handling various
2244 Objective-C cases, and that in build_unary_op handling
2245 Objective-C cases for increment / decrement, also needs
2246 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2247 and objc_types_are_equivalent may also need updates. */
2248 if (c_dialect_objc ())
2249 sorry ("%<_Atomic%> in Objective-C");
2250 /* C parser handling of OpenMP constructs needs checking for
2251 correct lvalue-to-rvalue conversions. */
2253 sorry ("%<_Atomic%> with OpenMP");
2257 pedwarn (loc
, OPT_Wpedantic
,
2258 "ISO C99 does not support the %<_Atomic%> qualifier");
2260 pedwarn (loc
, OPT_Wpedantic
,
2261 "ISO C90 does not support the %<_Atomic%> qualifier");
2265 value
= c_parser_peek_token (parser
)->value
;
2266 c_parser_consume_token (parser
);
2267 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2269 /* _Atomic ( type-name ). */
2271 c_parser_consume_token (parser
);
2272 struct c_type_name
*type
= c_parser_type_name (parser
);
2273 t
.kind
= ctsk_typeof
;
2274 t
.spec
= error_mark_node
;
2276 t
.expr_const_operands
= true;
2278 t
.spec
= groktypename (type
, &t
.expr
,
2279 &t
.expr_const_operands
);
2280 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2282 if (t
.spec
!= error_mark_node
)
2284 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2285 error_at (loc
, "%<_Atomic%>-qualified array type");
2286 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2287 error_at (loc
, "%<_Atomic%>-qualified function type");
2288 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2289 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2291 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2293 declspecs_add_type (loc
, specs
, t
);
2296 declspecs_add_qual (loc
, specs
, value
);
2302 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2303 c_parser_consume_token (parser
);
2308 attrs
= c_parser_attributes (parser
);
2309 declspecs_add_attrs (loc
, specs
, attrs
);
2314 align
= c_parser_alignas_specifier (parser
);
2315 declspecs_add_alignas (loc
, specs
, align
);
2324 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2327 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2328 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2329 enum attributes[opt] identifier
2331 The form with trailing comma is new in C99. The forms with
2332 attributes are GNU extensions. In GNU C, we accept any expression
2333 without commas in the syntax (assignment expressions, not just
2334 conditional expressions); assignment expressions will be diagnosed
2339 enumerator-list , enumerator
2342 enumeration-constant
2343 enumeration-constant = constant-expression
2346 static struct c_typespec
2347 c_parser_enum_specifier (c_parser
*parser
)
2349 struct c_typespec ret
;
2351 tree ident
= NULL_TREE
;
2352 location_t enum_loc
;
2353 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2354 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2355 enum_loc
= c_parser_peek_token (parser
)->location
;
2356 c_parser_consume_token (parser
);
2357 attrs
= c_parser_attributes (parser
);
2358 enum_loc
= c_parser_peek_token (parser
)->location
;
2359 /* Set the location in case we create a decl now. */
2360 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2361 if (c_parser_next_token_is (parser
, CPP_NAME
))
2363 ident
= c_parser_peek_token (parser
)->value
;
2364 ident_loc
= c_parser_peek_token (parser
)->location
;
2365 enum_loc
= ident_loc
;
2366 c_parser_consume_token (parser
);
2368 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2370 /* Parse an enum definition. */
2371 struct c_enum_contents the_enum
;
2374 /* We chain the enumerators in reverse order, then put them in
2375 forward order at the end. */
2377 timevar_push (TV_PARSE_ENUM
);
2378 type
= start_enum (enum_loc
, &the_enum
, ident
);
2380 c_parser_consume_token (parser
);
2388 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2389 location_t decl_loc
, value_loc
;
2390 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2392 c_parser_error (parser
, "expected identifier");
2393 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2394 values
= error_mark_node
;
2397 token
= c_parser_peek_token (parser
);
2398 enum_id
= token
->value
;
2399 /* Set the location in case we create a decl now. */
2400 c_parser_set_source_position_from_token (token
);
2401 decl_loc
= value_loc
= token
->location
;
2402 c_parser_consume_token (parser
);
2403 if (c_parser_next_token_is (parser
, CPP_EQ
))
2405 c_parser_consume_token (parser
);
2406 value_loc
= c_parser_peek_token (parser
)->location
;
2407 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2410 enum_value
= NULL_TREE
;
2411 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2412 &the_enum
, enum_id
, enum_value
);
2413 TREE_CHAIN (enum_decl
) = values
;
2416 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2418 comma_loc
= c_parser_peek_token (parser
)->location
;
2420 c_parser_consume_token (parser
);
2422 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2424 if (seen_comma
&& !flag_isoc99
)
2425 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2426 c_parser_consume_token (parser
);
2431 c_parser_error (parser
, "expected %<,%> or %<}%>");
2432 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2433 values
= error_mark_node
;
2437 postfix_attrs
= c_parser_attributes (parser
);
2438 ret
.spec
= finish_enum (type
, nreverse (values
),
2439 chainon (attrs
, postfix_attrs
));
2440 ret
.kind
= ctsk_tagdef
;
2441 ret
.expr
= NULL_TREE
;
2442 ret
.expr_const_operands
= true;
2443 timevar_pop (TV_PARSE_ENUM
);
2448 c_parser_error (parser
, "expected %<{%>");
2449 ret
.spec
= error_mark_node
;
2450 ret
.kind
= ctsk_tagref
;
2451 ret
.expr
= NULL_TREE
;
2452 ret
.expr_const_operands
= true;
2455 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2456 /* In ISO C, enumerated types can be referred to only if already
2458 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2461 pedwarn (enum_loc
, OPT_Wpedantic
,
2462 "ISO C forbids forward references to %<enum%> types");
2467 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2469 struct-or-union-specifier:
2470 struct-or-union attributes[opt] identifier[opt]
2471 { struct-contents } attributes[opt]
2472 struct-or-union attributes[opt] identifier
2475 struct-declaration-list
2477 struct-declaration-list:
2478 struct-declaration ;
2479 struct-declaration-list struct-declaration ;
2486 struct-declaration-list struct-declaration
2488 struct-declaration-list:
2489 struct-declaration-list ;
2492 (Note that in the syntax here, unlike that in ISO C, the semicolons
2493 are included here rather than in struct-declaration, in order to
2494 describe the syntax with extra semicolons and missing semicolon at
2499 struct-declaration-list:
2500 @defs ( class-name )
2502 (Note this does not include a trailing semicolon, but can be
2503 followed by further declarations, and gets a pedwarn-if-pedantic
2504 when followed by a semicolon.) */
2506 static struct c_typespec
2507 c_parser_struct_or_union_specifier (c_parser
*parser
)
2509 struct c_typespec ret
;
2511 tree ident
= NULL_TREE
;
2512 location_t struct_loc
;
2513 location_t ident_loc
= UNKNOWN_LOCATION
;
2514 enum tree_code code
;
2515 switch (c_parser_peek_token (parser
)->keyword
)
2526 struct_loc
= c_parser_peek_token (parser
)->location
;
2527 c_parser_consume_token (parser
);
2528 attrs
= c_parser_attributes (parser
);
2530 /* Set the location in case we create a decl now. */
2531 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2533 if (c_parser_next_token_is (parser
, CPP_NAME
))
2535 ident
= c_parser_peek_token (parser
)->value
;
2536 ident_loc
= c_parser_peek_token (parser
)->location
;
2537 struct_loc
= ident_loc
;
2538 c_parser_consume_token (parser
);
2540 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2542 /* Parse a struct or union definition. Start the scope of the
2543 tag before parsing components. */
2544 struct c_struct_parse_info
*struct_info
;
2545 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2547 /* We chain the components in reverse order, then put them in
2548 forward order at the end. Each struct-declaration may
2549 declare multiple components (comma-separated), so we must use
2550 chainon to join them, although when parsing each
2551 struct-declaration we can use TREE_CHAIN directly.
2553 The theory behind all this is that there will be more
2554 semicolon separated fields than comma separated fields, and
2555 so we'll be minimizing the number of node traversals required
2558 timevar_push (TV_PARSE_STRUCT
);
2559 contents
= NULL_TREE
;
2560 c_parser_consume_token (parser
);
2561 /* Handle the Objective-C @defs construct,
2562 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2563 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2566 gcc_assert (c_dialect_objc ());
2567 c_parser_consume_token (parser
);
2568 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2570 if (c_parser_next_token_is (parser
, CPP_NAME
)
2571 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2573 name
= c_parser_peek_token (parser
)->value
;
2574 c_parser_consume_token (parser
);
2578 c_parser_error (parser
, "expected class name");
2579 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2582 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2584 contents
= nreverse (objc_get_class_ivars (name
));
2587 /* Parse the struct-declarations and semicolons. Problems with
2588 semicolons are diagnosed here; empty structures are diagnosed
2593 /* Parse any stray semicolon. */
2594 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2596 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2597 "extra semicolon in struct or union specified");
2598 c_parser_consume_token (parser
);
2601 /* Stop if at the end of the struct or union contents. */
2602 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2604 c_parser_consume_token (parser
);
2607 /* Accept #pragmas at struct scope. */
2608 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2610 c_parser_pragma (parser
, pragma_struct
);
2613 /* Parse some comma-separated declarations, but not the
2614 trailing semicolon if any. */
2615 decls
= c_parser_struct_declaration (parser
);
2616 contents
= chainon (decls
, contents
);
2617 /* If no semicolon follows, either we have a parse error or
2618 are at the end of the struct or union and should
2620 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2621 c_parser_consume_token (parser
);
2624 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2625 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2626 "no semicolon at end of struct or union");
2627 else if (parser
->error
2628 || !c_parser_next_token_starts_declspecs (parser
))
2630 c_parser_error (parser
, "expected %<;%>");
2631 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2635 /* If we come here, we have already emitted an error
2636 for an expected `;', identifier or `(', and we also
2637 recovered already. Go on with the next field. */
2640 postfix_attrs
= c_parser_attributes (parser
);
2641 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2642 chainon (attrs
, postfix_attrs
), struct_info
);
2643 ret
.kind
= ctsk_tagdef
;
2644 ret
.expr
= NULL_TREE
;
2645 ret
.expr_const_operands
= true;
2646 timevar_pop (TV_PARSE_STRUCT
);
2651 c_parser_error (parser
, "expected %<{%>");
2652 ret
.spec
= error_mark_node
;
2653 ret
.kind
= ctsk_tagref
;
2654 ret
.expr
= NULL_TREE
;
2655 ret
.expr_const_operands
= true;
2658 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2662 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2663 the trailing semicolon.
2666 specifier-qualifier-list struct-declarator-list
2667 static_assert-declaration-no-semi
2669 specifier-qualifier-list:
2670 type-specifier specifier-qualifier-list[opt]
2671 type-qualifier specifier-qualifier-list[opt]
2672 attributes specifier-qualifier-list[opt]
2674 struct-declarator-list:
2676 struct-declarator-list , attributes[opt] struct-declarator
2679 declarator attributes[opt]
2680 declarator[opt] : constant-expression attributes[opt]
2685 __extension__ struct-declaration
2686 specifier-qualifier-list
2688 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2689 of attributes where shown is a GNU extension. In GNU C, we accept
2690 any expression without commas in the syntax (assignment
2691 expressions, not just conditional expressions); assignment
2692 expressions will be diagnosed as non-constant. */
2695 c_parser_struct_declaration (c_parser
*parser
)
2697 struct c_declspecs
*specs
;
2699 tree all_prefix_attrs
;
2701 location_t decl_loc
;
2702 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2706 ext
= disable_extension_diagnostics ();
2707 c_parser_consume_token (parser
);
2708 decl
= c_parser_struct_declaration (parser
);
2709 restore_extension_diagnostics (ext
);
2712 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2714 c_parser_static_assert_declaration_no_semi (parser
);
2717 specs
= build_null_declspecs ();
2718 decl_loc
= c_parser_peek_token (parser
)->location
;
2719 /* Strictly by the standard, we shouldn't allow _Alignas here,
2720 but it appears to have been intended to allow it there, so
2721 we're keeping it as it is until WG14 reaches a conclusion
2723 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2724 c_parser_declspecs (parser
, specs
, false, true, true,
2725 true, cla_nonabstract_decl
);
2728 if (!specs
->declspecs_seen_p
)
2730 c_parser_error (parser
, "expected specifier-qualifier-list");
2733 finish_declspecs (specs
);
2734 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2735 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2738 if (specs
->typespec_kind
== ctsk_none
)
2740 pedwarn (decl_loc
, OPT_Wpedantic
,
2741 "ISO C forbids member declarations with no members");
2742 shadow_tag_warned (specs
, pedantic
);
2747 /* Support for unnamed structs or unions as members of
2748 structs or unions (which is [a] useful and [b] supports
2752 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2753 build_id_declarator (NULL_TREE
), specs
,
2756 decl_attributes (&ret
, attrs
, 0);
2761 /* Provide better error recovery. Note that a type name here is valid,
2762 and will be treated as a field name. */
2763 if (specs
->typespec_kind
== ctsk_tagdef
2764 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2765 && c_parser_next_token_starts_declspecs (parser
)
2766 && !c_parser_next_token_is (parser
, CPP_NAME
))
2768 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2769 parser
->error
= false;
2773 pending_xref_error ();
2774 prefix_attrs
= specs
->attrs
;
2775 all_prefix_attrs
= prefix_attrs
;
2776 specs
->attrs
= NULL_TREE
;
2780 /* Declaring one or more declarators or un-named bit-fields. */
2781 struct c_declarator
*declarator
;
2783 if (c_parser_next_token_is (parser
, CPP_COLON
))
2784 declarator
= build_id_declarator (NULL_TREE
);
2786 declarator
= c_parser_declarator (parser
,
2787 specs
->typespec_kind
!= ctsk_none
,
2788 C_DTR_NORMAL
, &dummy
);
2789 if (declarator
== NULL
)
2791 c_parser_skip_to_end_of_block_or_statement (parser
);
2794 if (c_parser_next_token_is (parser
, CPP_COLON
)
2795 || c_parser_next_token_is (parser
, CPP_COMMA
)
2796 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2797 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2798 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2800 tree postfix_attrs
= NULL_TREE
;
2801 tree width
= NULL_TREE
;
2803 if (c_parser_next_token_is (parser
, CPP_COLON
))
2805 c_parser_consume_token (parser
);
2806 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2808 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2809 postfix_attrs
= c_parser_attributes (parser
);
2810 d
= grokfield (c_parser_peek_token (parser
)->location
,
2811 declarator
, specs
, width
, &all_prefix_attrs
);
2812 decl_attributes (&d
, chainon (postfix_attrs
,
2813 all_prefix_attrs
), 0);
2814 DECL_CHAIN (d
) = decls
;
2816 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2817 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2820 all_prefix_attrs
= prefix_attrs
;
2821 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2822 c_parser_consume_token (parser
);
2823 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2824 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2826 /* Semicolon consumed in caller. */
2831 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2837 c_parser_error (parser
,
2838 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2839 "%<__attribute__%>");
2846 /* Parse a typeof specifier (a GNU extension).
2849 typeof ( expression )
2850 typeof ( type-name )
2853 static struct c_typespec
2854 c_parser_typeof_specifier (c_parser
*parser
)
2856 struct c_typespec ret
;
2857 ret
.kind
= ctsk_typeof
;
2858 ret
.spec
= error_mark_node
;
2859 ret
.expr
= NULL_TREE
;
2860 ret
.expr_const_operands
= true;
2861 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2862 c_parser_consume_token (parser
);
2863 c_inhibit_evaluation_warnings
++;
2865 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2867 c_inhibit_evaluation_warnings
--;
2871 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2873 struct c_type_name
*type
= c_parser_type_name (parser
);
2874 c_inhibit_evaluation_warnings
--;
2878 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2879 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2885 location_t here
= c_parser_peek_token (parser
)->location
;
2886 struct c_expr expr
= c_parser_expression (parser
);
2887 c_inhibit_evaluation_warnings
--;
2889 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2890 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2891 error_at (here
, "%<typeof%> applied to a bit-field");
2892 mark_exp_read (expr
.value
);
2893 ret
.spec
= TREE_TYPE (expr
.value
);
2894 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2895 /* This is returned with the type so that when the type is
2896 evaluated, this can be evaluated. */
2898 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2899 pop_maybe_used (was_vm
);
2900 /* For use in macros such as those in <stdatomic.h>, remove
2901 _Atomic and const qualifiers from atomic types. (Possibly
2902 all qualifiers should be removed; const can be an issue for
2903 more macros using typeof than just the <stdatomic.h>
2905 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
2906 ret
.spec
= c_build_qualified_type (ret
.spec
,
2907 (TYPE_QUALS (ret
.spec
)
2908 & ~(TYPE_QUAL_ATOMIC
2909 | TYPE_QUAL_CONST
)));
2911 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2915 /* Parse an alignment-specifier.
2919 alignment-specifier:
2920 _Alignas ( type-name )
2921 _Alignas ( constant-expression )
2925 c_parser_alignas_specifier (c_parser
* parser
)
2927 tree ret
= error_mark_node
;
2928 location_t loc
= c_parser_peek_token (parser
)->location
;
2929 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2930 c_parser_consume_token (parser
);
2934 pedwarn (loc
, OPT_Wpedantic
,
2935 "ISO C99 does not support %<_Alignas%>");
2937 pedwarn (loc
, OPT_Wpedantic
,
2938 "ISO C90 does not support %<_Alignas%>");
2940 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2942 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2944 struct c_type_name
*type
= c_parser_type_name (parser
);
2946 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2949 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2954 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2955 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2956 be redeclared; otherwise it may not. KIND indicates which kind of
2957 declarator is wanted. Returns a valid declarator except in the
2958 case of a syntax error in which case NULL is returned. *SEEN_ID is
2959 set to true if an identifier being declared is seen; this is used
2960 to diagnose bad forms of abstract array declarators and to
2961 determine whether an identifier list is syntactically permitted.
2964 pointer[opt] direct-declarator
2968 ( attributes[opt] declarator )
2969 direct-declarator array-declarator
2970 direct-declarator ( parameter-type-list )
2971 direct-declarator ( identifier-list[opt] )
2974 * type-qualifier-list[opt]
2975 * type-qualifier-list[opt] pointer
2977 type-qualifier-list:
2980 type-qualifier-list type-qualifier
2981 type-qualifier-list attributes
2984 [ type-qualifier-list[opt] assignment-expression[opt] ]
2985 [ static type-qualifier-list[opt] assignment-expression ]
2986 [ type-qualifier-list static assignment-expression ]
2987 [ type-qualifier-list[opt] * ]
2989 parameter-type-list:
2991 parameter-list , ...
2994 parameter-declaration
2995 parameter-list , parameter-declaration
2997 parameter-declaration:
2998 declaration-specifiers declarator attributes[opt]
2999 declaration-specifiers abstract-declarator[opt] attributes[opt]
3003 identifier-list , identifier
3005 abstract-declarator:
3007 pointer[opt] direct-abstract-declarator
3009 direct-abstract-declarator:
3010 ( attributes[opt] abstract-declarator )
3011 direct-abstract-declarator[opt] array-declarator
3012 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3017 direct-declarator ( parameter-forward-declarations
3018 parameter-type-list[opt] )
3020 direct-abstract-declarator:
3021 direct-abstract-declarator[opt] ( parameter-forward-declarations
3022 parameter-type-list[opt] )
3024 parameter-forward-declarations:
3026 parameter-forward-declarations parameter-list ;
3028 The uses of attributes shown above are GNU extensions.
3030 Some forms of array declarator are not included in C99 in the
3031 syntax for abstract declarators; these are disallowed elsewhere.
3032 This may be a defect (DR#289).
3034 This function also accepts an omitted abstract declarator as being
3035 an abstract declarator, although not part of the formal syntax. */
3037 static struct c_declarator
*
3038 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3041 /* Parse any initial pointer part. */
3042 if (c_parser_next_token_is (parser
, CPP_MULT
))
3044 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3045 struct c_declarator
*inner
;
3046 c_parser_consume_token (parser
);
3047 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3048 false, cla_prefer_id
);
3049 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3053 return make_pointer_declarator (quals_attrs
, inner
);
3055 /* Now we have a direct declarator, direct abstract declarator or
3056 nothing (which counts as a direct abstract declarator here). */
3057 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3060 /* Parse a direct declarator or direct abstract declarator; arguments
3061 as c_parser_declarator. */
3063 static struct c_declarator
*
3064 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3067 /* The direct declarator must start with an identifier (possibly
3068 omitted) or a parenthesized declarator (possibly abstract). In
3069 an ordinary declarator, initial parentheses must start a
3070 parenthesized declarator. In an abstract declarator or parameter
3071 declarator, they could start a parenthesized declarator or a
3072 parameter list. To tell which, the open parenthesis and any
3073 following attributes must be read. If a declaration specifier
3074 follows, then it is a parameter list; if the specifier is a
3075 typedef name, there might be an ambiguity about redeclaring it,
3076 which is resolved in the direction of treating it as a typedef
3077 name. If a close parenthesis follows, it is also an empty
3078 parameter list, as the syntax does not permit empty abstract
3079 declarators. Otherwise, it is a parenthesized declarator (in
3080 which case the analysis may be repeated inside it, recursively).
3082 ??? There is an ambiguity in a parameter declaration "int
3083 (__attribute__((foo)) x)", where x is not a typedef name: it
3084 could be an abstract declarator for a function, or declare x with
3085 parentheses. The proper resolution of this ambiguity needs
3086 documenting. At present we follow an accident of the old
3087 parser's implementation, whereby the first parameter must have
3088 some declaration specifiers other than just attributes. Thus as
3089 a parameter declaration it is treated as a parenthesized
3090 parameter named x, and as an abstract declarator it is
3093 ??? Also following the old parser, attributes inside an empty
3094 parameter list are ignored, making it a list not yielding a
3095 prototype, rather than giving an error or making it have one
3096 parameter with implicit type int.
3098 ??? Also following the old parser, typedef names may be
3099 redeclared in declarators, but not Objective-C class names. */
3101 if (kind
!= C_DTR_ABSTRACT
3102 && c_parser_next_token_is (parser
, CPP_NAME
)
3104 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3105 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3106 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3108 struct c_declarator
*inner
3109 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3111 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3112 c_parser_consume_token (parser
);
3113 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3116 if (kind
!= C_DTR_NORMAL
3117 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3119 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3120 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3123 /* Either we are at the end of an abstract declarator, or we have
3126 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3129 struct c_declarator
*inner
;
3130 c_parser_consume_token (parser
);
3131 attrs
= c_parser_attributes (parser
);
3132 if (kind
!= C_DTR_NORMAL
3133 && (c_parser_next_token_starts_declspecs (parser
)
3134 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3136 struct c_arg_info
*args
3137 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3144 = build_function_declarator (args
,
3145 build_id_declarator (NULL_TREE
));
3146 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3150 /* A parenthesized declarator. */
3151 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3152 if (inner
!= NULL
&& attrs
!= NULL
)
3153 inner
= build_attrs_declarator (attrs
, inner
);
3154 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3156 c_parser_consume_token (parser
);
3160 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3164 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3171 if (kind
== C_DTR_NORMAL
)
3173 c_parser_error (parser
, "expected identifier or %<(%>");
3177 return build_id_declarator (NULL_TREE
);
3181 /* Parse part of a direct declarator or direct abstract declarator,
3182 given that some (in INNER) has already been parsed; ID_PRESENT is
3183 true if an identifier is present, false for an abstract
3186 static struct c_declarator
*
3187 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3188 struct c_declarator
*inner
)
3190 /* Parse a sequence of array declarators and parameter lists. */
3191 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3193 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3194 struct c_declarator
*declarator
;
3195 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3198 struct c_expr dimen
;
3199 dimen
.value
= NULL_TREE
;
3200 dimen
.original_code
= ERROR_MARK
;
3201 dimen
.original_type
= NULL_TREE
;
3202 c_parser_consume_token (parser
);
3203 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3204 false, cla_prefer_id
);
3205 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3207 c_parser_consume_token (parser
);
3208 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3209 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3210 false, cla_prefer_id
);
3211 if (!quals_attrs
->declspecs_seen_p
)
3213 /* If "static" is present, there must be an array dimension.
3214 Otherwise, there may be a dimension, "*", or no
3219 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3223 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3225 dimen
.value
= NULL_TREE
;
3228 else if (flag_enable_cilkplus
3229 && c_parser_next_token_is (parser
, CPP_COLON
))
3231 dimen
.value
= error_mark_node
;
3233 error_at (c_parser_peek_token (parser
)->location
,
3234 "array notations cannot be used in declaration");
3235 c_parser_consume_token (parser
);
3237 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3239 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3241 dimen
.value
= NULL_TREE
;
3243 c_parser_consume_token (parser
);
3248 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3254 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3257 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3258 c_parser_consume_token (parser
);
3259 else if (flag_enable_cilkplus
3260 && c_parser_next_token_is (parser
, CPP_COLON
))
3262 error_at (c_parser_peek_token (parser
)->location
,
3263 "array notations cannot be used in declaration");
3264 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3269 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3274 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3275 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3276 static_seen
, star_seen
);
3277 if (declarator
== NULL
)
3279 inner
= set_array_declarator_inner (declarator
, inner
);
3280 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3282 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3285 struct c_arg_info
*args
;
3286 c_parser_consume_token (parser
);
3287 attrs
= c_parser_attributes (parser
);
3288 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3293 inner
= build_function_declarator (args
, inner
);
3294 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3300 /* Parse a parameter list or identifier list, including the closing
3301 parenthesis but not the opening one. ATTRS are the attributes at
3302 the start of the list. ID_LIST_OK is true if an identifier list is
3303 acceptable; such a list must not have attributes at the start. */
3305 static struct c_arg_info
*
3306 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3309 declare_parm_level ();
3310 /* If the list starts with an identifier, it is an identifier list.
3311 Otherwise, it is either a prototype list or an empty list. */
3314 && c_parser_next_token_is (parser
, CPP_NAME
)
3315 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3317 /* Look ahead to detect typos in type names. */
3318 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3319 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3320 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3321 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3323 tree list
= NULL_TREE
, *nextp
= &list
;
3324 while (c_parser_next_token_is (parser
, CPP_NAME
)
3325 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3327 *nextp
= build_tree_list (NULL_TREE
,
3328 c_parser_peek_token (parser
)->value
);
3329 nextp
= & TREE_CHAIN (*nextp
);
3330 c_parser_consume_token (parser
);
3331 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3333 c_parser_consume_token (parser
);
3334 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3336 c_parser_error (parser
, "expected identifier");
3340 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3342 struct c_arg_info
*ret
= build_arg_info ();
3344 c_parser_consume_token (parser
);
3350 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3358 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3365 /* Parse a parameter list (possibly empty), including the closing
3366 parenthesis but not the opening one. ATTRS are the attributes at
3367 the start of the list. EXPR is NULL or an expression that needs to
3368 be evaluated for the side effects of array size expressions in the
3371 static struct c_arg_info
*
3372 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3374 bool bad_parm
= false;
3376 /* ??? Following the old parser, forward parameter declarations may
3377 use abstract declarators, and if no real parameter declarations
3378 follow the forward declarations then this is not diagnosed. Also
3379 note as above that attributes are ignored as the only contents of
3380 the parentheses, or as the only contents after forward
3382 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3384 struct c_arg_info
*ret
= build_arg_info ();
3385 c_parser_consume_token (parser
);
3388 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3390 struct c_arg_info
*ret
= build_arg_info ();
3392 if (flag_allow_parameterless_variadic_functions
)
3394 /* F (...) is allowed. */
3395 ret
->types
= NULL_TREE
;
3399 /* Suppress -Wold-style-definition for this case. */
3400 ret
->types
= error_mark_node
;
3401 error_at (c_parser_peek_token (parser
)->location
,
3402 "ISO C requires a named argument before %<...%>");
3404 c_parser_consume_token (parser
);
3405 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3407 c_parser_consume_token (parser
);
3412 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3417 /* Nonempty list of parameters, either terminated with semicolon
3418 (forward declarations; recurse) or with close parenthesis (normal
3419 function) or with ", ... )" (variadic function). */
3422 /* Parse a parameter. */
3423 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3428 push_parm_decl (parm
, &expr
);
3429 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3432 c_parser_consume_token (parser
);
3433 mark_forward_parm_decls ();
3434 new_attrs
= c_parser_attributes (parser
);
3435 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3437 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3439 c_parser_consume_token (parser
);
3443 return get_parm_info (false, expr
);
3445 if (!c_parser_require (parser
, CPP_COMMA
,
3446 "expected %<;%>, %<,%> or %<)%>"))
3448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3451 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3453 c_parser_consume_token (parser
);
3454 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3456 c_parser_consume_token (parser
);
3460 return get_parm_info (true, expr
);
3464 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3472 /* Parse a parameter declaration. ATTRS are the attributes at the
3473 start of the declaration if it is the first parameter. */
3475 static struct c_parm
*
3476 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3478 struct c_declspecs
*specs
;
3479 struct c_declarator
*declarator
;
3481 tree postfix_attrs
= NULL_TREE
;
3484 /* Accept #pragmas between parameter declarations. */
3485 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3486 c_parser_pragma (parser
, pragma_param
);
3488 if (!c_parser_next_token_starts_declspecs (parser
))
3490 c_token
*token
= c_parser_peek_token (parser
);
3493 c_parser_set_source_position_from_token (token
);
3494 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3496 error ("unknown type name %qE", token
->value
);
3497 parser
->error
= true;
3499 /* ??? In some Objective-C cases '...' isn't applicable so there
3500 should be a different message. */
3502 c_parser_error (parser
,
3503 "expected declaration specifiers or %<...%>");
3504 c_parser_skip_to_end_of_parameter (parser
);
3507 specs
= build_null_declspecs ();
3510 declspecs_add_attrs (input_location
, specs
, attrs
);
3513 c_parser_declspecs (parser
, specs
, true, true, true, true,
3514 cla_nonabstract_decl
);
3515 finish_declspecs (specs
);
3516 pending_xref_error ();
3517 prefix_attrs
= specs
->attrs
;
3518 specs
->attrs
= NULL_TREE
;
3519 declarator
= c_parser_declarator (parser
,
3520 specs
->typespec_kind
!= ctsk_none
,
3521 C_DTR_PARM
, &dummy
);
3522 if (declarator
== NULL
)
3524 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3527 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3528 postfix_attrs
= c_parser_attributes (parser
);
3529 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3533 /* Parse a string literal in an asm expression. It should not be
3534 translated, and wide string literals are an error although
3535 permitted by the syntax. This is a GNU extension.
3540 ??? At present, following the old parser, the caller needs to have
3541 set lex_untranslated_string to 1. It would be better to follow the
3542 C++ parser rather than using this kludge. */
3545 c_parser_asm_string_literal (c_parser
*parser
)
3548 int save_flag
= warn_overlength_strings
;
3549 warn_overlength_strings
= 0;
3550 if (c_parser_next_token_is (parser
, CPP_STRING
))
3552 str
= c_parser_peek_token (parser
)->value
;
3553 c_parser_consume_token (parser
);
3555 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3557 error_at (c_parser_peek_token (parser
)->location
,
3558 "wide string literal in %<asm%>");
3559 str
= build_string (1, "");
3560 c_parser_consume_token (parser
);
3564 c_parser_error (parser
, "expected string literal");
3567 warn_overlength_strings
= save_flag
;
3571 /* Parse a simple asm expression. This is used in restricted
3572 contexts, where a full expression with inputs and outputs does not
3573 make sense. This is a GNU extension.
3576 asm ( asm-string-literal )
3580 c_parser_simple_asm_expr (c_parser
*parser
)
3583 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3584 /* ??? Follow the C++ parser rather than using the
3585 lex_untranslated_string kludge. */
3586 parser
->lex_untranslated_string
= true;
3587 c_parser_consume_token (parser
);
3588 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3590 parser
->lex_untranslated_string
= false;
3593 str
= c_parser_asm_string_literal (parser
);
3594 parser
->lex_untranslated_string
= false;
3595 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3597 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3604 c_parser_attribute_any_word (c_parser
*parser
)
3606 tree attr_name
= NULL_TREE
;
3608 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3610 /* ??? See comment above about what keywords are accepted here. */
3612 switch (c_parser_peek_token (parser
)->keyword
)
3643 case RID_TRANSACTION_ATOMIC
:
3644 case RID_TRANSACTION_CANCEL
:
3655 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3656 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3658 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3659 attr_name
= c_parser_peek_token (parser
)->value
;
3664 /* Parse (possibly empty) attributes. This is a GNU extension.
3668 attributes attribute
3671 __attribute__ ( ( attribute-list ) )
3675 attribute_list , attrib
3680 any-word ( identifier )
3681 any-word ( identifier , nonempty-expr-list )
3682 any-word ( expr-list )
3684 where the "identifier" must not be declared as a type, and
3685 "any-word" may be any identifier (including one declared as a
3686 type), a reserved word storage class specifier, type specifier or
3687 type qualifier. ??? This still leaves out most reserved keywords
3688 (following the old parser), shouldn't we include them, and why not
3689 allow identifiers declared as types to start the arguments? */
3692 c_parser_attributes (c_parser
*parser
)
3694 tree attrs
= NULL_TREE
;
3695 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3697 /* ??? Follow the C++ parser rather than using the
3698 lex_untranslated_string kludge. */
3699 parser
->lex_untranslated_string
= true;
3700 c_parser_consume_token (parser
);
3701 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3703 parser
->lex_untranslated_string
= false;
3706 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3708 parser
->lex_untranslated_string
= false;
3709 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3712 /* Parse the attribute list. */
3713 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3714 || c_parser_next_token_is (parser
, CPP_NAME
)
3715 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3717 tree attr
, attr_name
, attr_args
;
3718 vec
<tree
, va_gc
> *expr_list
;
3719 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3721 c_parser_consume_token (parser
);
3725 attr_name
= c_parser_attribute_any_word (parser
);
3726 if (attr_name
== NULL
)
3728 c_parser_consume_token (parser
);
3729 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3731 attr
= build_tree_list (attr_name
, NULL_TREE
);
3732 attrs
= chainon (attrs
, attr
);
3735 c_parser_consume_token (parser
);
3736 /* Parse the attribute contents. If they start with an
3737 identifier which is followed by a comma or close
3738 parenthesis, then the arguments start with that
3739 identifier; otherwise they are an expression list.
3740 In objective-c the identifier may be a classname. */
3741 if (c_parser_next_token_is (parser
, CPP_NAME
)
3742 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3743 || (c_dialect_objc ()
3744 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3745 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3746 || (c_parser_peek_2nd_token (parser
)->type
3747 == CPP_CLOSE_PAREN
)))
3749 tree arg1
= c_parser_peek_token (parser
)->value
;
3750 c_parser_consume_token (parser
);
3751 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3752 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3756 c_parser_consume_token (parser
);
3757 expr_list
= c_parser_expr_list (parser
, false, true,
3759 tree_list
= build_tree_list_vec (expr_list
);
3760 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3761 release_tree_vector (expr_list
);
3766 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3767 attr_args
= NULL_TREE
;
3770 expr_list
= c_parser_expr_list (parser
, false, true,
3772 attr_args
= build_tree_list_vec (expr_list
);
3773 release_tree_vector (expr_list
);
3776 attr
= build_tree_list (attr_name
, attr_args
);
3777 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3778 c_parser_consume_token (parser
);
3781 parser
->lex_untranslated_string
= false;
3782 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3786 attrs
= chainon (attrs
, attr
);
3788 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3789 c_parser_consume_token (parser
);
3792 parser
->lex_untranslated_string
= false;
3793 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3797 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3798 c_parser_consume_token (parser
);
3801 parser
->lex_untranslated_string
= false;
3802 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3806 parser
->lex_untranslated_string
= false;
3811 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3814 specifier-qualifier-list abstract-declarator[opt]
3817 static struct c_type_name
*
3818 c_parser_type_name (c_parser
*parser
)
3820 struct c_declspecs
*specs
= build_null_declspecs ();
3821 struct c_declarator
*declarator
;
3822 struct c_type_name
*ret
;
3824 c_parser_declspecs (parser
, specs
, false, true, true, false,
3826 if (!specs
->declspecs_seen_p
)
3828 c_parser_error (parser
, "expected specifier-qualifier-list");
3831 if (specs
->type
!= error_mark_node
)
3833 pending_xref_error ();
3834 finish_declspecs (specs
);
3836 declarator
= c_parser_declarator (parser
,
3837 specs
->typespec_kind
!= ctsk_none
,
3838 C_DTR_ABSTRACT
, &dummy
);
3839 if (declarator
== NULL
)
3841 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3843 ret
->declarator
= declarator
;
3847 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3850 assignment-expression
3851 { initializer-list }
3852 { initializer-list , }
3855 designation[opt] initializer
3856 initializer-list , designation[opt] initializer
3863 designator-list designator
3870 [ constant-expression ]
3882 [ constant-expression ... constant-expression ]
3884 Any expression without commas is accepted in the syntax for the
3885 constant-expressions, with non-constant expressions rejected later.
3887 This function is only used for top-level initializers; for nested
3888 ones, see c_parser_initval. */
3890 static struct c_expr
3891 c_parser_initializer (c_parser
*parser
)
3893 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3894 return c_parser_braced_init (parser
, NULL_TREE
, false);
3898 location_t loc
= c_parser_peek_token (parser
)->location
;
3899 ret
= c_parser_expr_no_commas (parser
, NULL
);
3900 if (TREE_CODE (ret
.value
) != STRING_CST
3901 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3902 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
3907 /* Parse a braced initializer list. TYPE is the type specified for a
3908 compound literal, and NULL_TREE for other initializers and for
3909 nested braced lists. NESTED_P is true for nested braced lists,
3910 false for the list of a compound literal or the list that is the
3911 top-level initializer in a declaration. */
3913 static struct c_expr
3914 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3917 struct obstack braced_init_obstack
;
3918 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3919 gcc_obstack_init (&braced_init_obstack
);
3920 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3921 c_parser_consume_token (parser
);
3923 push_init_level (0, &braced_init_obstack
);
3925 really_start_incremental_init (type
);
3926 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3928 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3932 /* Parse a non-empty initializer list, possibly with a trailing
3936 c_parser_initelt (parser
, &braced_init_obstack
);
3939 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3940 c_parser_consume_token (parser
);
3943 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3947 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3949 ret
.value
= error_mark_node
;
3950 ret
.original_code
= ERROR_MARK
;
3951 ret
.original_type
= NULL
;
3952 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3953 pop_init_level (0, &braced_init_obstack
);
3954 obstack_free (&braced_init_obstack
, NULL
);
3957 c_parser_consume_token (parser
);
3958 ret
= pop_init_level (0, &braced_init_obstack
);
3959 obstack_free (&braced_init_obstack
, NULL
);
3963 /* Parse a nested initializer, including designators. */
3966 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3968 /* Parse any designator or designator list. A single array
3969 designator may have the subsequent "=" omitted in GNU C, but a
3970 longer list or a structure member designator may not. */
3971 if (c_parser_next_token_is (parser
, CPP_NAME
)
3972 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3974 /* Old-style structure member designator. */
3975 set_init_label (c_parser_peek_token (parser
)->value
,
3976 braced_init_obstack
);
3977 /* Use the colon as the error location. */
3978 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3979 "obsolete use of designated initializer with %<:%>");
3980 c_parser_consume_token (parser
);
3981 c_parser_consume_token (parser
);
3985 /* des_seen is 0 if there have been no designators, 1 if there
3986 has been a single array designator and 2 otherwise. */
3988 /* Location of a designator. */
3989 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3990 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3991 || c_parser_next_token_is (parser
, CPP_DOT
))
3993 int des_prev
= des_seen
;
3995 des_loc
= c_parser_peek_token (parser
)->location
;
3998 if (c_parser_next_token_is (parser
, CPP_DOT
))
4001 c_parser_consume_token (parser
);
4002 if (c_parser_next_token_is (parser
, CPP_NAME
))
4004 set_init_label (c_parser_peek_token (parser
)->value
,
4005 braced_init_obstack
);
4006 c_parser_consume_token (parser
);
4011 init
.value
= error_mark_node
;
4012 init
.original_code
= ERROR_MARK
;
4013 init
.original_type
= NULL
;
4014 c_parser_error (parser
, "expected identifier");
4015 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4016 process_init_element (init
, false, braced_init_obstack
);
4023 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4024 /* ??? Following the old parser, [ objc-receiver
4025 objc-message-args ] is accepted as an initializer,
4026 being distinguished from a designator by what follows
4027 the first assignment expression inside the square
4028 brackets, but after a first array designator a
4029 subsequent square bracket is for Objective-C taken to
4030 start an expression, using the obsolete form of
4031 designated initializer without '=', rather than
4032 possibly being a second level of designation: in LALR
4033 terms, the '[' is shifted rather than reducing
4034 designator to designator-list. */
4035 if (des_prev
== 1 && c_dialect_objc ())
4037 des_seen
= des_prev
;
4040 if (des_prev
== 0 && c_dialect_objc ())
4042 /* This might be an array designator or an
4043 Objective-C message expression. If the former,
4044 continue parsing here; if the latter, parse the
4045 remainder of the initializer given the starting
4046 primary-expression. ??? It might make sense to
4047 distinguish when des_prev == 1 as well; see
4048 previous comment. */
4050 struct c_expr mexpr
;
4051 c_parser_consume_token (parser
);
4052 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4053 && ((c_parser_peek_token (parser
)->id_kind
4055 || (c_parser_peek_token (parser
)->id_kind
4056 == C_ID_CLASSNAME
)))
4058 /* Type name receiver. */
4059 tree id
= c_parser_peek_token (parser
)->value
;
4060 c_parser_consume_token (parser
);
4061 rec
= objc_get_class_reference (id
);
4062 goto parse_message_args
;
4064 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4065 mark_exp_read (first
);
4066 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4067 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4068 goto array_desig_after_first
;
4069 /* Expression receiver. So far only one part
4070 without commas has been parsed; there might be
4071 more of the expression. */
4073 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4076 location_t comma_loc
, exp_loc
;
4077 comma_loc
= c_parser_peek_token (parser
)->location
;
4078 c_parser_consume_token (parser
);
4079 exp_loc
= c_parser_peek_token (parser
)->location
;
4080 next
= c_parser_expr_no_commas (parser
, NULL
);
4081 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4083 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4086 /* Now parse the objc-message-args. */
4087 args
= c_parser_objc_message_args (parser
);
4088 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4091 = objc_build_message_expr (rec
, args
);
4092 mexpr
.original_code
= ERROR_MARK
;
4093 mexpr
.original_type
= NULL
;
4094 /* Now parse and process the remainder of the
4095 initializer, starting with this message
4096 expression as a primary-expression. */
4097 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4100 c_parser_consume_token (parser
);
4101 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4102 mark_exp_read (first
);
4103 array_desig_after_first
:
4104 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4106 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4107 c_parser_consume_token (parser
);
4108 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4109 mark_exp_read (second
);
4113 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4115 c_parser_consume_token (parser
);
4116 set_init_index (first
, second
, braced_init_obstack
);
4118 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4119 "ISO C forbids specifying range of elements to initialize");
4122 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4128 if (c_parser_next_token_is (parser
, CPP_EQ
))
4131 pedwarn (des_loc
, OPT_Wpedantic
,
4132 "ISO C90 forbids specifying subobject to initialize");
4133 c_parser_consume_token (parser
);
4138 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4139 "obsolete use of designated initializer without %<=%>");
4143 init
.value
= error_mark_node
;
4144 init
.original_code
= ERROR_MARK
;
4145 init
.original_type
= NULL
;
4146 c_parser_error (parser
, "expected %<=%>");
4147 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4148 process_init_element (init
, false, braced_init_obstack
);
4154 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4157 /* Parse a nested initializer; as c_parser_initializer but parses
4158 initializers within braced lists, after any designators have been
4159 applied. If AFTER is not NULL then it is an Objective-C message
4160 expression which is the primary-expression starting the
4164 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4165 struct obstack
* braced_init_obstack
)
4168 gcc_assert (!after
|| c_dialect_objc ());
4169 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4170 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4173 location_t loc
= c_parser_peek_token (parser
)->location
;
4174 init
= c_parser_expr_no_commas (parser
, after
);
4175 if (init
.value
!= NULL_TREE
4176 && TREE_CODE (init
.value
) != STRING_CST
4177 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4178 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4180 process_init_element (init
, false, braced_init_obstack
);
4183 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4187 { block-item-list[opt] }
4188 { label-declarations block-item-list }
4192 block-item-list block-item
4204 { label-declarations block-item-list }
4207 __extension__ nested-declaration
4208 nested-function-definition
4212 label-declarations label-declaration
4215 __label__ identifier-list ;
4217 Allowing the mixing of declarations and code is new in C99. The
4218 GNU syntax also permits (not shown above) labels at the end of
4219 compound statements, which yield an error. We don't allow labels
4220 on declarations; this might seem like a natural extension, but
4221 there would be a conflict between attributes on the label and
4222 prefix attributes on the declaration. ??? The syntax follows the
4223 old parser in requiring something after label declarations.
4224 Although they are erroneous if the labels declared aren't defined,
4225 is it useful for the syntax to be this way?
4238 cancellation-point-directive */
4241 c_parser_compound_statement (c_parser
*parser
)
4244 location_t brace_loc
;
4245 brace_loc
= c_parser_peek_token (parser
)->location
;
4246 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4248 /* Ensure a scope is entered and left anyway to avoid confusion
4249 if we have just prepared to enter a function body. */
4250 stmt
= c_begin_compound_stmt (true);
4251 c_end_compound_stmt (brace_loc
, stmt
, true);
4252 return error_mark_node
;
4254 stmt
= c_begin_compound_stmt (true);
4255 c_parser_compound_statement_nostart (parser
);
4257 /* If the compound stmt contains array notations, then we expand them. */
4258 if (flag_enable_cilkplus
&& contains_array_notation_expr (stmt
))
4259 stmt
= expand_array_notation_exprs (stmt
);
4260 return c_end_compound_stmt (brace_loc
, stmt
, true);
4263 /* Parse a compound statement except for the opening brace. This is
4264 used for parsing both compound statements and statement expressions
4265 (which follow different paths to handling the opening). */
4268 c_parser_compound_statement_nostart (c_parser
*parser
)
4270 bool last_stmt
= false;
4271 bool last_label
= false;
4272 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4273 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4274 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4276 c_parser_consume_token (parser
);
4279 mark_valid_location_for_stdc_pragma (true);
4280 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4282 /* Read zero or more forward-declarations for labels that nested
4283 functions can jump to. */
4284 mark_valid_location_for_stdc_pragma (false);
4285 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4287 label_loc
= c_parser_peek_token (parser
)->location
;
4288 c_parser_consume_token (parser
);
4289 /* Any identifiers, including those declared as type names,
4294 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4296 c_parser_error (parser
, "expected identifier");
4300 = declare_label (c_parser_peek_token (parser
)->value
);
4301 C_DECLARED_LABEL_FLAG (label
) = 1;
4302 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4303 c_parser_consume_token (parser
);
4304 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4305 c_parser_consume_token (parser
);
4309 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4311 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4313 /* We must now have at least one statement, label or declaration. */
4314 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4316 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4317 c_parser_error (parser
, "expected declaration or statement");
4318 c_parser_consume_token (parser
);
4321 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4323 location_t loc
= c_parser_peek_token (parser
)->location
;
4324 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4325 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4326 || (c_parser_next_token_is (parser
, CPP_NAME
)
4327 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4329 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4330 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4332 label_loc
= c_parser_peek_token (parser
)->location
;
4335 mark_valid_location_for_stdc_pragma (false);
4336 c_parser_label (parser
);
4338 else if (!last_label
4339 && c_parser_next_tokens_start_declaration (parser
))
4342 mark_valid_location_for_stdc_pragma (false);
4343 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4347 (pedantic
&& !flag_isoc99
)
4349 : OPT_Wdeclaration_after_statement
,
4350 "ISO C90 forbids mixed declarations and code");
4353 else if (!last_label
4354 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4356 /* __extension__ can start a declaration, but is also an
4357 unary operator that can start an expression. Consume all
4358 but the last of a possible series of __extension__ to
4360 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4361 && (c_parser_peek_2nd_token (parser
)->keyword
4363 c_parser_consume_token (parser
);
4364 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4367 ext
= disable_extension_diagnostics ();
4368 c_parser_consume_token (parser
);
4370 mark_valid_location_for_stdc_pragma (false);
4371 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4373 /* Following the old parser, __extension__ does not
4374 disable this diagnostic. */
4375 restore_extension_diagnostics (ext
);
4377 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4379 : OPT_Wdeclaration_after_statement
,
4380 "ISO C90 forbids mixed declarations and code");
4386 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4388 /* External pragmas, and some omp pragmas, are not associated
4389 with regular c code, and so are not to be considered statements
4390 syntactically. This ensures that the user doesn't put them
4391 places that would turn into syntax errors if the directive
4393 if (c_parser_pragma (parser
, pragma_compound
))
4394 last_label
= false, last_stmt
= true;
4396 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4398 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4399 c_parser_error (parser
, "expected declaration or statement");
4402 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4404 if (parser
->in_if_block
)
4406 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4407 error_at (loc
, """expected %<}%> before %<else%>");
4412 error_at (loc
, "%<else%> without a previous %<if%>");
4413 c_parser_consume_token (parser
);
4422 mark_valid_location_for_stdc_pragma (false);
4423 c_parser_statement_after_labels (parser
);
4426 parser
->error
= false;
4429 error_at (label_loc
, "label at end of compound statement");
4430 c_parser_consume_token (parser
);
4431 /* Restore the value we started with. */
4432 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4435 /* Parse a label (C90 6.6.1, C99 6.8.1).
4438 identifier : attributes[opt]
4439 case constant-expression :
4445 case constant-expression ... constant-expression :
4447 The use of attributes on labels is a GNU extension. The syntax in
4448 GNU C accepts any expressions without commas, non-constant
4449 expressions being rejected later. */
4452 c_parser_label (c_parser
*parser
)
4454 location_t loc1
= c_parser_peek_token (parser
)->location
;
4455 tree label
= NULL_TREE
;
4456 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4459 c_parser_consume_token (parser
);
4460 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4461 if (c_parser_next_token_is (parser
, CPP_COLON
))
4463 c_parser_consume_token (parser
);
4464 label
= do_case (loc1
, exp1
, NULL_TREE
);
4466 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4468 c_parser_consume_token (parser
);
4469 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4470 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4471 label
= do_case (loc1
, exp1
, exp2
);
4474 c_parser_error (parser
, "expected %<:%> or %<...%>");
4476 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4478 c_parser_consume_token (parser
);
4479 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4480 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4484 tree name
= c_parser_peek_token (parser
)->value
;
4487 location_t loc2
= c_parser_peek_token (parser
)->location
;
4488 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4489 c_parser_consume_token (parser
);
4490 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4491 c_parser_consume_token (parser
);
4492 attrs
= c_parser_attributes (parser
);
4493 tlab
= define_label (loc2
, name
);
4496 decl_attributes (&tlab
, attrs
, 0);
4497 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4502 if (c_parser_next_tokens_start_declaration (parser
))
4504 error_at (c_parser_peek_token (parser
)->location
,
4505 "a label can only be part of a statement and "
4506 "a declaration is not a statement");
4507 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4508 /*static_assert_ok*/ true,
4509 /*empty_ok*/ true, /*nested*/ true,
4510 /*start_attr_ok*/ true, NULL
,
4516 /* Parse a statement (C90 6.6, C99 6.8).
4521 expression-statement
4529 expression-statement:
4532 selection-statement:
4536 iteration-statement:
4545 return expression[opt] ;
4558 objc-throw-statement
4559 objc-try-catch-statement
4560 objc-synchronized-statement
4562 objc-throw-statement:
4578 parallel-for-construct
4579 parallel-for-simd-construct
4580 parallel-sections-construct
4587 parallel-directive structured-block
4590 for-directive iteration-statement
4593 simd-directive iteration-statements
4596 for-simd-directive iteration-statements
4599 sections-directive section-scope
4602 single-directive structured-block
4604 parallel-for-construct:
4605 parallel-for-directive iteration-statement
4607 parallel-for-simd-construct:
4608 parallel-for-simd-directive iteration-statement
4610 parallel-sections-construct:
4611 parallel-sections-directive section-scope
4614 master-directive structured-block
4617 critical-directive structured-block
4620 atomic-directive expression-statement
4623 ordered-directive structured-block
4625 Transactional Memory:
4628 transaction-statement
4629 transaction-cancel-statement
4633 c_parser_statement (c_parser
*parser
)
4635 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4636 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4637 || (c_parser_next_token_is (parser
, CPP_NAME
)
4638 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4639 c_parser_label (parser
);
4640 c_parser_statement_after_labels (parser
);
4643 /* Parse a statement, other than a labeled statement. */
4646 c_parser_statement_after_labels (c_parser
*parser
)
4648 location_t loc
= c_parser_peek_token (parser
)->location
;
4649 tree stmt
= NULL_TREE
;
4650 bool in_if_block
= parser
->in_if_block
;
4651 parser
->in_if_block
= false;
4652 switch (c_parser_peek_token (parser
)->type
)
4654 case CPP_OPEN_BRACE
:
4655 add_stmt (c_parser_compound_statement (parser
));
4658 switch (c_parser_peek_token (parser
)->keyword
)
4661 c_parser_if_statement (parser
);
4664 c_parser_switch_statement (parser
);
4667 c_parser_while_statement (parser
, false);
4670 c_parser_do_statement (parser
, false);
4673 c_parser_for_statement (parser
, false);
4676 c_parser_consume_token (parser
);
4677 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4678 if (!flag_enable_cilkplus
)
4679 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4681 add_stmt (build_cilk_sync ());
4684 c_parser_consume_token (parser
);
4685 if (c_parser_next_token_is (parser
, CPP_NAME
))
4687 stmt
= c_finish_goto_label (loc
,
4688 c_parser_peek_token (parser
)->value
);
4689 c_parser_consume_token (parser
);
4691 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4695 c_parser_consume_token (parser
);
4696 val
= c_parser_expression (parser
);
4697 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4698 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4701 c_parser_error (parser
, "expected identifier or %<*%>");
4702 goto expect_semicolon
;
4704 c_parser_consume_token (parser
);
4705 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4706 goto expect_semicolon
;
4708 c_parser_consume_token (parser
);
4709 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4710 goto expect_semicolon
;
4712 c_parser_consume_token (parser
);
4713 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4715 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4716 c_parser_consume_token (parser
);
4720 struct c_expr expr
= c_parser_expression_conv (parser
);
4721 mark_exp_read (expr
.value
);
4722 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4723 goto expect_semicolon
;
4727 stmt
= c_parser_asm_statement (parser
);
4729 case RID_TRANSACTION_ATOMIC
:
4730 case RID_TRANSACTION_RELAXED
:
4731 stmt
= c_parser_transaction (parser
,
4732 c_parser_peek_token (parser
)->keyword
);
4734 case RID_TRANSACTION_CANCEL
:
4735 stmt
= c_parser_transaction_cancel (parser
);
4736 goto expect_semicolon
;
4738 gcc_assert (c_dialect_objc ());
4739 c_parser_consume_token (parser
);
4740 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4742 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4743 c_parser_consume_token (parser
);
4747 struct c_expr expr
= c_parser_expression (parser
);
4748 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
4749 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4750 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
4751 goto expect_semicolon
;
4755 gcc_assert (c_dialect_objc ());
4756 c_parser_objc_try_catch_finally_statement (parser
);
4758 case RID_AT_SYNCHRONIZED
:
4759 gcc_assert (c_dialect_objc ());
4760 c_parser_objc_synchronized_statement (parser
);
4767 c_parser_consume_token (parser
);
4769 case CPP_CLOSE_PAREN
:
4770 case CPP_CLOSE_SQUARE
:
4771 /* Avoid infinite loop in error recovery:
4772 c_parser_skip_until_found stops at a closing nesting
4773 delimiter without consuming it, but here we need to consume
4774 it to proceed further. */
4775 c_parser_error (parser
, "expected statement");
4776 c_parser_consume_token (parser
);
4779 c_parser_pragma (parser
, pragma_stmt
);
4783 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4785 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4788 /* Two cases cannot and do not have line numbers associated: If stmt
4789 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4790 cannot hold line numbers. But that's OK because the statement
4791 will either be changed to a MODIFY_EXPR during gimplification of
4792 the statement expr, or discarded. If stmt was compound, but
4793 without new variables, we will have skipped the creation of a
4794 BIND and will have a bare STATEMENT_LIST. But that's OK because
4795 (recursively) all of the component statements should already have
4796 line numbers assigned. ??? Can we discard no-op statements
4798 if (CAN_HAVE_LOCATION_P (stmt
)
4799 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4800 SET_EXPR_LOCATION (stmt
, loc
);
4802 parser
->in_if_block
= in_if_block
;
4805 /* Parse the condition from an if, do, while or for statements. */
4808 c_parser_condition (c_parser
*parser
)
4810 location_t loc
= c_parser_peek_token (parser
)->location
;
4812 cond
= c_parser_expression_conv (parser
).value
;
4813 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4814 cond
= c_fully_fold (cond
, false, NULL
);
4815 if (warn_sequence_point
)
4816 verify_sequence_points (cond
);
4820 /* Parse a parenthesized condition from an if, do or while statement.
4826 c_parser_paren_condition (c_parser
*parser
)
4829 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4830 return error_mark_node
;
4831 cond
= c_parser_condition (parser
);
4832 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4836 /* Parse a statement which is a block in C99. */
4839 c_parser_c99_block_statement (c_parser
*parser
)
4841 tree block
= c_begin_compound_stmt (flag_isoc99
);
4842 location_t loc
= c_parser_peek_token (parser
)->location
;
4843 c_parser_statement (parser
);
4844 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4847 /* Parse the body of an if statement. This is just parsing a
4848 statement but (a) it is a block in C99, (b) we track whether the
4849 body is an if statement for the sake of -Wparentheses warnings, (c)
4850 we handle an empty body specially for the sake of -Wempty-body
4851 warnings, and (d) we call parser_compound_statement directly
4852 because c_parser_statement_after_labels resets
4853 parser->in_if_block. */
4856 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4858 tree block
= c_begin_compound_stmt (flag_isoc99
);
4859 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4860 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4861 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4862 || (c_parser_next_token_is (parser
, CPP_NAME
)
4863 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4864 c_parser_label (parser
);
4865 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4866 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4868 location_t loc
= c_parser_peek_token (parser
)->location
;
4869 add_stmt (build_empty_stmt (loc
));
4870 c_parser_consume_token (parser
);
4871 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4872 warning_at (loc
, OPT_Wempty_body
,
4873 "suggest braces around empty body in an %<if%> statement");
4875 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4876 add_stmt (c_parser_compound_statement (parser
));
4878 c_parser_statement_after_labels (parser
);
4879 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4882 /* Parse the else body of an if statement. This is just parsing a
4883 statement but (a) it is a block in C99, (b) we handle an empty body
4884 specially for the sake of -Wempty-body warnings. */
4887 c_parser_else_body (c_parser
*parser
)
4889 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4890 tree block
= c_begin_compound_stmt (flag_isoc99
);
4891 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4892 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4893 || (c_parser_next_token_is (parser
, CPP_NAME
)
4894 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4895 c_parser_label (parser
);
4896 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4898 location_t loc
= c_parser_peek_token (parser
)->location
;
4901 "suggest braces around empty body in an %<else%> statement");
4902 add_stmt (build_empty_stmt (loc
));
4903 c_parser_consume_token (parser
);
4906 c_parser_statement_after_labels (parser
);
4907 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4910 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4913 if ( expression ) statement
4914 if ( expression ) statement else statement
4918 c_parser_if_statement (c_parser
*parser
)
4923 bool first_if
= false;
4924 tree first_body
, second_body
;
4928 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4929 c_parser_consume_token (parser
);
4930 block
= c_begin_compound_stmt (flag_isoc99
);
4931 loc
= c_parser_peek_token (parser
)->location
;
4932 cond
= c_parser_paren_condition (parser
);
4933 in_if_block
= parser
->in_if_block
;
4934 parser
->in_if_block
= true;
4935 first_body
= c_parser_if_body (parser
, &first_if
);
4936 parser
->in_if_block
= in_if_block
;
4937 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4939 c_parser_consume_token (parser
);
4940 second_body
= c_parser_else_body (parser
);
4943 second_body
= NULL_TREE
;
4944 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4945 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
4947 /* If the if statement contains array notations, then we expand them. */
4948 if (flag_enable_cilkplus
&& contains_array_notation_expr (if_stmt
))
4949 if_stmt
= fix_conditional_array_notations (if_stmt
);
4953 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4956 switch (expression) statement
4960 c_parser_switch_statement (c_parser
*parser
)
4963 tree block
, expr
, body
, save_break
;
4964 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4965 location_t switch_cond_loc
;
4966 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4967 c_parser_consume_token (parser
);
4968 block
= c_begin_compound_stmt (flag_isoc99
);
4969 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4971 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4972 ce
= c_parser_expression (parser
);
4973 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
4975 if (flag_enable_cilkplus
&& contains_array_notation_expr (expr
))
4977 error_at (switch_cond_loc
,
4978 "array notations cannot be used as a condition for switch "
4980 expr
= error_mark_node
;
4982 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4986 switch_cond_loc
= UNKNOWN_LOCATION
;
4987 expr
= error_mark_node
;
4989 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4990 save_break
= c_break_label
;
4991 c_break_label
= NULL_TREE
;
4992 body
= c_parser_c99_block_statement (parser
);
4993 c_finish_case (body
);
4996 location_t here
= c_parser_peek_token (parser
)->location
;
4997 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4998 SET_EXPR_LOCATION (t
, here
);
5001 c_break_label
= save_break
;
5002 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5005 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5008 while (expression) statement
5012 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5014 tree block
, cond
, body
, save_break
, save_cont
;
5016 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5017 c_parser_consume_token (parser
);
5018 block
= c_begin_compound_stmt (flag_isoc99
);
5019 loc
= c_parser_peek_token (parser
)->location
;
5020 cond
= c_parser_paren_condition (parser
);
5021 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5023 error_at (loc
, "array notations cannot be used as a condition for while "
5025 cond
= error_mark_node
;
5028 if (ivdep
&& cond
!= error_mark_node
)
5029 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5030 build_int_cst (integer_type_node
,
5031 annot_expr_ivdep_kind
));
5032 save_break
= c_break_label
;
5033 c_break_label
= NULL_TREE
;
5034 save_cont
= c_cont_label
;
5035 c_cont_label
= NULL_TREE
;
5036 body
= c_parser_c99_block_statement (parser
);
5037 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5038 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5039 c_break_label
= save_break
;
5040 c_cont_label
= save_cont
;
5043 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5046 do statement while ( expression ) ;
5050 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5052 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5054 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5055 c_parser_consume_token (parser
);
5056 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5057 warning_at (c_parser_peek_token (parser
)->location
,
5059 "suggest braces around empty body in %<do%> statement");
5060 block
= c_begin_compound_stmt (flag_isoc99
);
5061 loc
= c_parser_peek_token (parser
)->location
;
5062 save_break
= c_break_label
;
5063 c_break_label
= NULL_TREE
;
5064 save_cont
= c_cont_label
;
5065 c_cont_label
= NULL_TREE
;
5066 body
= c_parser_c99_block_statement (parser
);
5067 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5068 new_break
= c_break_label
;
5069 c_break_label
= save_break
;
5070 new_cont
= c_cont_label
;
5071 c_cont_label
= save_cont
;
5072 cond
= c_parser_paren_condition (parser
);
5073 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5075 error_at (loc
, "array notations cannot be used as a condition for a "
5076 "do-while statement");
5077 cond
= error_mark_node
;
5079 if (ivdep
&& cond
!= error_mark_node
)
5080 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5081 build_int_cst (integer_type_node
,
5082 annot_expr_ivdep_kind
));
5083 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5084 c_parser_skip_to_end_of_block_or_statement (parser
);
5085 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5086 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5089 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5092 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5093 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5095 The form with a declaration is new in C99.
5097 ??? In accordance with the old parser, the declaration may be a
5098 nested function, which is then rejected in check_for_loop_decls,
5099 but does it make any sense for this to be included in the grammar?
5100 Note in particular that the nested function does not include a
5101 trailing ';', whereas the "declaration" production includes one.
5102 Also, can we reject bad declarations earlier and cheaper than
5103 check_for_loop_decls?
5105 In Objective-C, there are two additional variants:
5108 for ( expression in expresssion ) statement
5109 for ( declaration in expression ) statement
5111 This is inconsistent with C, because the second variant is allowed
5112 even if c99 is not enabled.
5114 The rest of the comment documents these Objective-C foreach-statement.
5116 Here is the canonical example of the first variant:
5117 for (object in array) { do something with object }
5118 we call the first expression ("object") the "object_expression" and
5119 the second expression ("array") the "collection_expression".
5120 object_expression must be an lvalue of type "id" (a generic Objective-C
5121 object) because the loop works by assigning to object_expression the
5122 various objects from the collection_expression. collection_expression
5123 must evaluate to something of type "id" which responds to the method
5124 countByEnumeratingWithState:objects:count:.
5126 The canonical example of the second variant is:
5127 for (id object in array) { do something with object }
5128 which is completely equivalent to
5131 for (object in array) { do something with object }
5133 Note that initizializing 'object' in some way (eg, "for ((object =
5134 xxx) in array) { do something with object }") is possibly
5135 technically valid, but completely pointless as 'object' will be
5136 assigned to something else as soon as the loop starts. We should
5137 most likely reject it (TODO).
5139 The beginning of the Objective-C foreach-statement looks exactly
5140 like the beginning of the for-statement, and we can tell it is a
5141 foreach-statement only because the initial declaration or
5142 expression is terminated by 'in' instead of ';'.
5146 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5148 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5149 /* The following are only used when parsing an ObjC foreach statement. */
5150 tree object_expression
;
5151 /* Silence the bogus uninitialized warning. */
5152 tree collection_expression
= NULL
;
5153 location_t loc
= c_parser_peek_token (parser
)->location
;
5154 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5155 bool is_foreach_statement
= false;
5156 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5157 c_parser_consume_token (parser
);
5158 /* Open a compound statement in Objective-C as well, just in case this is
5159 as foreach expression. */
5160 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5161 cond
= error_mark_node
;
5162 incr
= error_mark_node
;
5163 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5165 /* Parse the initialization declaration or expression. */
5166 object_expression
= error_mark_node
;
5167 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5168 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5170 parser
->objc_could_be_foreach_context
= false;
5171 c_parser_consume_token (parser
);
5172 c_finish_expr_stmt (loc
, NULL_TREE
);
5174 else if (c_parser_next_tokens_start_declaration (parser
))
5176 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5177 &object_expression
, vNULL
);
5178 parser
->objc_could_be_foreach_context
= false;
5180 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5182 c_parser_consume_token (parser
);
5183 is_foreach_statement
= true;
5184 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5185 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5188 check_for_loop_decls (for_loc
, flag_isoc99
);
5190 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5192 /* __extension__ can start a declaration, but is also an
5193 unary operator that can start an expression. Consume all
5194 but the last of a possible series of __extension__ to
5196 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5197 && (c_parser_peek_2nd_token (parser
)->keyword
5199 c_parser_consume_token (parser
);
5200 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5203 ext
= disable_extension_diagnostics ();
5204 c_parser_consume_token (parser
);
5205 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5206 true, &object_expression
, vNULL
);
5207 parser
->objc_could_be_foreach_context
= false;
5209 restore_extension_diagnostics (ext
);
5210 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5212 c_parser_consume_token (parser
);
5213 is_foreach_statement
= true;
5214 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5215 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5218 check_for_loop_decls (for_loc
, flag_isoc99
);
5228 tree init_expression
;
5229 ce
= c_parser_expression (parser
);
5230 init_expression
= ce
.value
;
5231 parser
->objc_could_be_foreach_context
= false;
5232 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5234 c_parser_consume_token (parser
);
5235 is_foreach_statement
= true;
5236 if (! lvalue_p (init_expression
))
5237 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5238 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5242 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5243 init_expression
= ce
.value
;
5244 c_finish_expr_stmt (loc
, init_expression
);
5245 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5249 /* Parse the loop condition. In the case of a foreach
5250 statement, there is no loop condition. */
5251 gcc_assert (!parser
->objc_could_be_foreach_context
);
5252 if (!is_foreach_statement
)
5254 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5258 c_parser_error (parser
, "missing loop condition in loop with "
5259 "%<GCC ivdep%> pragma");
5260 cond
= error_mark_node
;
5264 c_parser_consume_token (parser
);
5270 cond
= c_parser_condition (parser
);
5271 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5273 error_at (loc
, "array notations cannot be used in a "
5274 "condition for a for-loop");
5275 cond
= error_mark_node
;
5277 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5280 if (ivdep
&& cond
!= error_mark_node
)
5281 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5282 build_int_cst (integer_type_node
,
5283 annot_expr_ivdep_kind
));
5285 /* Parse the increment expression (the third expression in a
5286 for-statement). In the case of a foreach-statement, this is
5287 the expression that follows the 'in'. */
5288 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5290 if (is_foreach_statement
)
5292 c_parser_error (parser
, "missing collection in fast enumeration");
5293 collection_expression
= error_mark_node
;
5296 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5300 if (is_foreach_statement
)
5301 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5305 struct c_expr ce
= c_parser_expression (parser
);
5306 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5307 incr
= c_process_expr_stmt (loc
, ce
.value
);
5310 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5312 save_break
= c_break_label
;
5313 c_break_label
= NULL_TREE
;
5314 save_cont
= c_cont_label
;
5315 c_cont_label
= NULL_TREE
;
5316 body
= c_parser_c99_block_statement (parser
);
5317 if (is_foreach_statement
)
5318 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5320 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5321 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5322 c_break_label
= save_break
;
5323 c_cont_label
= save_cont
;
5326 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5327 statement with inputs, outputs, clobbers, and volatile tag
5331 asm type-qualifier[opt] ( asm-argument ) ;
5332 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5336 asm-string-literal : asm-operands[opt]
5337 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5338 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5341 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5344 Qualifiers other than volatile are accepted in the syntax but
5348 c_parser_asm_statement (c_parser
*parser
)
5350 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5351 bool simple
, is_goto
;
5352 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5353 int section
, nsections
;
5355 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5356 c_parser_consume_token (parser
);
5357 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5359 quals
= c_parser_peek_token (parser
)->value
;
5360 c_parser_consume_token (parser
);
5362 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5363 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5365 warning_at (c_parser_peek_token (parser
)->location
,
5367 "%E qualifier ignored on asm",
5368 c_parser_peek_token (parser
)->value
);
5370 c_parser_consume_token (parser
);
5376 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5378 c_parser_consume_token (parser
);
5382 /* ??? Follow the C++ parser rather than using the
5383 lex_untranslated_string kludge. */
5384 parser
->lex_untranslated_string
= true;
5387 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5390 str
= c_parser_asm_string_literal (parser
);
5391 if (str
== NULL_TREE
)
5392 goto error_close_paren
;
5395 outputs
= NULL_TREE
;
5397 clobbers
= NULL_TREE
;
5400 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5403 /* Parse each colon-delimited section of operands. */
5404 nsections
= 3 + is_goto
;
5405 for (section
= 0; section
< nsections
; ++section
)
5407 if (!c_parser_require (parser
, CPP_COLON
,
5410 : "expected %<:%> or %<)%>"))
5411 goto error_close_paren
;
5413 /* Once past any colon, we're no longer a simple asm. */
5416 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5417 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5422 /* For asm goto, we don't allow output operands, but reserve
5423 the slot for a future extension that does allow them. */
5425 outputs
= c_parser_asm_operands (parser
);
5428 inputs
= c_parser_asm_operands (parser
);
5431 clobbers
= c_parser_asm_clobbers (parser
);
5434 labels
= c_parser_asm_goto_operands (parser
);
5440 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5445 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5447 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5451 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5452 c_parser_skip_to_end_of_block_or_statement (parser
);
5454 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5455 clobbers
, labels
, simple
));
5458 parser
->lex_untranslated_string
= false;
5462 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5466 /* Parse asm operands, a GNU extension.
5470 asm-operands , asm-operand
5473 asm-string-literal ( expression )
5474 [ identifier ] asm-string-literal ( expression )
5478 c_parser_asm_operands (c_parser
*parser
)
5480 tree list
= NULL_TREE
;
5485 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5487 c_parser_consume_token (parser
);
5488 if (c_parser_next_token_is (parser
, CPP_NAME
))
5490 tree id
= c_parser_peek_token (parser
)->value
;
5491 c_parser_consume_token (parser
);
5492 name
= build_string (IDENTIFIER_LENGTH (id
),
5493 IDENTIFIER_POINTER (id
));
5497 c_parser_error (parser
, "expected identifier");
5498 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5501 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5506 str
= c_parser_asm_string_literal (parser
);
5507 if (str
== NULL_TREE
)
5509 parser
->lex_untranslated_string
= false;
5510 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5512 parser
->lex_untranslated_string
= true;
5515 expr
= c_parser_expression (parser
);
5516 mark_exp_read (expr
.value
);
5517 parser
->lex_untranslated_string
= true;
5518 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5520 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5523 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5525 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5526 c_parser_consume_token (parser
);
5533 /* Parse asm clobbers, a GNU extension.
5537 asm-clobbers , asm-string-literal
5541 c_parser_asm_clobbers (c_parser
*parser
)
5543 tree list
= NULL_TREE
;
5546 tree str
= c_parser_asm_string_literal (parser
);
5548 list
= tree_cons (NULL_TREE
, str
, list
);
5551 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5552 c_parser_consume_token (parser
);
5559 /* Parse asm goto labels, a GNU extension.
5563 asm-goto-operands , identifier
5567 c_parser_asm_goto_operands (c_parser
*parser
)
5569 tree list
= NULL_TREE
;
5574 if (c_parser_next_token_is (parser
, CPP_NAME
))
5576 c_token
*tok
= c_parser_peek_token (parser
);
5578 label
= lookup_label_for_goto (tok
->location
, name
);
5579 c_parser_consume_token (parser
);
5580 TREE_USED (label
) = 1;
5584 c_parser_error (parser
, "expected identifier");
5588 name
= build_string (IDENTIFIER_LENGTH (name
),
5589 IDENTIFIER_POINTER (name
));
5590 list
= tree_cons (name
, label
, list
);
5591 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5592 c_parser_consume_token (parser
);
5594 return nreverse (list
);
5598 /* Parse an expression other than a compound expression; that is, an
5599 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5600 NULL then it is an Objective-C message expression which is the
5601 primary-expression starting the expression as an initializer.
5603 assignment-expression:
5604 conditional-expression
5605 unary-expression assignment-operator assignment-expression
5607 assignment-operator: one of
5608 = *= /= %= += -= <<= >>= &= ^= |=
5610 In GNU C we accept any conditional expression on the LHS and
5611 diagnose the invalid lvalue rather than producing a syntax
5614 static struct c_expr
5615 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5616 tree omp_atomic_lhs
)
5618 struct c_expr lhs
, rhs
, ret
;
5619 enum tree_code code
;
5620 location_t op_location
, exp_location
;
5621 gcc_assert (!after
|| c_dialect_objc ());
5622 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5623 op_location
= c_parser_peek_token (parser
)->location
;
5624 switch (c_parser_peek_token (parser
)->type
)
5633 code
= TRUNC_DIV_EXPR
;
5636 code
= TRUNC_MOD_EXPR
;
5651 code
= BIT_AND_EXPR
;
5654 code
= BIT_XOR_EXPR
;
5657 code
= BIT_IOR_EXPR
;
5662 c_parser_consume_token (parser
);
5663 exp_location
= c_parser_peek_token (parser
)->location
;
5664 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5665 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5667 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5668 code
, exp_location
, rhs
.value
,
5670 if (code
== NOP_EXPR
)
5671 ret
.original_code
= MODIFY_EXPR
;
5674 TREE_NO_WARNING (ret
.value
) = 1;
5675 ret
.original_code
= ERROR_MARK
;
5677 ret
.original_type
= NULL
;
5681 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5682 is not NULL then it is an Objective-C message expression which is
5683 the primary-expression starting the expression as an initializer.
5685 conditional-expression:
5686 logical-OR-expression
5687 logical-OR-expression ? expression : conditional-expression
5691 conditional-expression:
5692 logical-OR-expression ? : conditional-expression
5695 static struct c_expr
5696 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5697 tree omp_atomic_lhs
)
5699 struct c_expr cond
, exp1
, exp2
, ret
;
5700 location_t cond_loc
, colon_loc
, middle_loc
;
5702 gcc_assert (!after
|| c_dialect_objc ());
5704 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5706 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5708 cond_loc
= c_parser_peek_token (parser
)->location
;
5709 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5710 c_parser_consume_token (parser
);
5711 if (c_parser_next_token_is (parser
, CPP_COLON
))
5713 tree eptype
= NULL_TREE
;
5715 middle_loc
= c_parser_peek_token (parser
)->location
;
5716 pedwarn (middle_loc
, OPT_Wpedantic
,
5717 "ISO C forbids omitting the middle term of a ?: expression");
5718 warn_for_omitted_condop (middle_loc
, cond
.value
);
5719 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5721 eptype
= TREE_TYPE (cond
.value
);
5722 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5724 /* Make sure first operand is calculated only once. */
5725 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5727 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5728 exp1
.original_type
= NULL
;
5729 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5730 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5735 = c_objc_common_truthvalue_conversion
5736 (cond_loc
, default_conversion (cond
.value
));
5737 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5738 exp1
= c_parser_expression_conv (parser
);
5739 mark_exp_read (exp1
.value
);
5740 c_inhibit_evaluation_warnings
+=
5741 ((cond
.value
== truthvalue_true_node
)
5742 - (cond
.value
== truthvalue_false_node
));
5745 colon_loc
= c_parser_peek_token (parser
)->location
;
5746 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5748 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5749 ret
.value
= error_mark_node
;
5750 ret
.original_code
= ERROR_MARK
;
5751 ret
.original_type
= NULL
;
5755 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5756 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5757 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
5759 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5760 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5761 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5762 exp1
.value
, exp1
.original_type
,
5763 exp2
.value
, exp2
.original_type
);
5764 ret
.original_code
= ERROR_MARK
;
5765 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5766 ret
.original_type
= NULL
;
5771 /* If both sides are enum type, the default conversion will have
5772 made the type of the result be an integer type. We want to
5773 remember the enum types we started with. */
5774 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5775 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5776 ret
.original_type
= ((t1
!= error_mark_node
5777 && t2
!= error_mark_node
5778 && (TYPE_MAIN_VARIANT (t1
)
5779 == TYPE_MAIN_VARIANT (t2
)))
5786 /* Parse a binary expression; that is, a logical-OR-expression (C90
5787 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5788 an Objective-C message expression which is the primary-expression
5789 starting the expression as an initializer.
5791 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
5792 when it should be the unfolded lhs. In a valid OpenMP source,
5793 one of the operands of the toplevel binary expression must be equal
5794 to it. In that case, just return a build2 created binary operation
5795 rather than result of parser_build_binary_op.
5797 multiplicative-expression:
5799 multiplicative-expression * cast-expression
5800 multiplicative-expression / cast-expression
5801 multiplicative-expression % cast-expression
5803 additive-expression:
5804 multiplicative-expression
5805 additive-expression + multiplicative-expression
5806 additive-expression - multiplicative-expression
5810 shift-expression << additive-expression
5811 shift-expression >> additive-expression
5813 relational-expression:
5815 relational-expression < shift-expression
5816 relational-expression > shift-expression
5817 relational-expression <= shift-expression
5818 relational-expression >= shift-expression
5820 equality-expression:
5821 relational-expression
5822 equality-expression == relational-expression
5823 equality-expression != relational-expression
5827 AND-expression & equality-expression
5829 exclusive-OR-expression:
5831 exclusive-OR-expression ^ AND-expression
5833 inclusive-OR-expression:
5834 exclusive-OR-expression
5835 inclusive-OR-expression | exclusive-OR-expression
5837 logical-AND-expression:
5838 inclusive-OR-expression
5839 logical-AND-expression && inclusive-OR-expression
5841 logical-OR-expression:
5842 logical-AND-expression
5843 logical-OR-expression || logical-AND-expression
5846 static struct c_expr
5847 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5848 tree omp_atomic_lhs
)
5850 /* A binary expression is parsed using operator-precedence parsing,
5851 with the operands being cast expressions. All the binary
5852 operators are left-associative. Thus a binary expression is of
5855 E0 op1 E1 op2 E2 ...
5857 which we represent on a stack. On the stack, the precedence
5858 levels are strictly increasing. When a new operator is
5859 encountered of higher precedence than that at the top of the
5860 stack, it is pushed; its LHS is the top expression, and its RHS
5861 is everything parsed until it is popped. When a new operator is
5862 encountered with precedence less than or equal to that at the top
5863 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5864 by the result of the operation until the operator at the top of
5865 the stack has lower precedence than the new operator or there is
5866 only one element on the stack; then the top expression is the LHS
5867 of the new operator. In the case of logical AND and OR
5868 expressions, we also need to adjust c_inhibit_evaluation_warnings
5869 as appropriate when the operators are pushed and popped. */
5872 /* The expression at this stack level. */
5874 /* The precedence of the operator on its left, PREC_NONE at the
5875 bottom of the stack. */
5876 enum c_parser_prec prec
;
5877 /* The operation on its left. */
5879 /* The source location of this operation. */
5883 /* Location of the binary operator. */
5884 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5887 switch (stack[sp].op) \
5889 case TRUTH_ANDIF_EXPR: \
5890 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5891 == truthvalue_false_node); \
5893 case TRUTH_ORIF_EXPR: \
5894 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5895 == truthvalue_true_node); \
5900 stack[sp - 1].expr \
5901 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
5902 stack[sp - 1].expr, true, true); \
5904 = convert_lvalue_to_rvalue (stack[sp].loc, \
5905 stack[sp].expr, true, true); \
5906 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
5907 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
5908 && ((1 << stack[sp].prec) \
5909 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
5910 | PREC_ADD | PREC_MULT))) \
5911 && stack[sp].op != TRUNC_MOD_EXPR \
5912 && stack[0].expr.value != error_mark_node \
5913 && stack[1].expr.value != error_mark_node \
5914 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
5915 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
5916 stack[0].expr.value \
5917 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
5918 stack[0].expr.value, stack[1].expr.value); \
5920 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5922 stack[sp - 1].expr, \
5926 gcc_assert (!after
|| c_dialect_objc ());
5927 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5928 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5929 stack
[0].prec
= PREC_NONE
;
5933 enum c_parser_prec oprec
;
5934 enum tree_code ocode
;
5937 switch (c_parser_peek_token (parser
)->type
)
5945 ocode
= TRUNC_DIV_EXPR
;
5949 ocode
= TRUNC_MOD_EXPR
;
5961 ocode
= LSHIFT_EXPR
;
5965 ocode
= RSHIFT_EXPR
;
5979 case CPP_GREATER_EQ
:
5992 oprec
= PREC_BITAND
;
5993 ocode
= BIT_AND_EXPR
;
5996 oprec
= PREC_BITXOR
;
5997 ocode
= BIT_XOR_EXPR
;
6001 ocode
= BIT_IOR_EXPR
;
6004 oprec
= PREC_LOGAND
;
6005 ocode
= TRUTH_ANDIF_EXPR
;
6009 ocode
= TRUTH_ORIF_EXPR
;
6012 /* Not a binary operator, so end of the binary
6016 binary_loc
= c_parser_peek_token (parser
)->location
;
6017 while (oprec
<= stack
[sp
].prec
)
6019 c_parser_consume_token (parser
);
6022 case TRUTH_ANDIF_EXPR
:
6024 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6025 stack
[sp
].expr
, true, true);
6026 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6027 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6028 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6029 == truthvalue_false_node
);
6031 case TRUTH_ORIF_EXPR
:
6033 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6034 stack
[sp
].expr
, true, true);
6035 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6036 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6037 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6038 == truthvalue_true_node
);
6044 stack
[sp
].loc
= binary_loc
;
6045 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6046 stack
[sp
].prec
= oprec
;
6047 stack
[sp
].op
= ocode
;
6048 stack
[sp
].loc
= binary_loc
;
6053 return stack
[0].expr
;
6057 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6058 NULL then it is an Objective-C message expression which is the
6059 primary-expression starting the expression as an initializer.
6063 ( type-name ) unary-expression
6066 static struct c_expr
6067 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6069 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6070 gcc_assert (!after
|| c_dialect_objc ());
6072 return c_parser_postfix_expression_after_primary (parser
,
6074 /* If the expression begins with a parenthesized type name, it may
6075 be either a cast or a compound literal; we need to see whether
6076 the next character is '{' to tell the difference. If not, it is
6077 an unary expression. Full detection of unknown typenames here
6078 would require a 3-token lookahead. */
6079 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6080 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6082 struct c_type_name
*type_name
;
6085 c_parser_consume_token (parser
);
6086 type_name
= c_parser_type_name (parser
);
6087 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6088 if (type_name
== NULL
)
6090 ret
.value
= error_mark_node
;
6091 ret
.original_code
= ERROR_MARK
;
6092 ret
.original_type
= NULL
;
6096 /* Save casted types in the function's used types hash table. */
6097 used_types_insert (type_name
->specs
->type
);
6099 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6100 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6103 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6104 expr
= c_parser_cast_expression (parser
, NULL
);
6105 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6107 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6108 ret
.original_code
= ERROR_MARK
;
6109 ret
.original_type
= NULL
;
6113 return c_parser_unary_expression (parser
);
6116 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6122 unary-operator cast-expression
6123 sizeof unary-expression
6124 sizeof ( type-name )
6126 unary-operator: one of
6132 __alignof__ unary-expression
6133 __alignof__ ( type-name )
6136 (C11 permits _Alignof with type names only.)
6138 unary-operator: one of
6139 __extension__ __real__ __imag__
6141 Transactional Memory:
6144 transaction-expression
6146 In addition, the GNU syntax treats ++ and -- as unary operators, so
6147 they may be applied to cast expressions with errors for non-lvalues
6150 static struct c_expr
6151 c_parser_unary_expression (c_parser
*parser
)
6154 struct c_expr ret
, op
;
6155 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6157 ret
.original_code
= ERROR_MARK
;
6158 ret
.original_type
= NULL
;
6159 switch (c_parser_peek_token (parser
)->type
)
6162 c_parser_consume_token (parser
);
6163 exp_loc
= c_parser_peek_token (parser
)->location
;
6164 op
= c_parser_cast_expression (parser
, NULL
);
6166 /* If there is array notations in op, we expand them. */
6167 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6168 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6171 op
= default_function_array_read_conversion (exp_loc
, op
);
6172 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6174 case CPP_MINUS_MINUS
:
6175 c_parser_consume_token (parser
);
6176 exp_loc
= c_parser_peek_token (parser
)->location
;
6177 op
= c_parser_cast_expression (parser
, NULL
);
6179 /* If there is array notations in op, we expand them. */
6180 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6181 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6184 op
= default_function_array_read_conversion (exp_loc
, op
);
6185 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6188 c_parser_consume_token (parser
);
6189 op
= c_parser_cast_expression (parser
, NULL
);
6190 mark_exp_read (op
.value
);
6191 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6193 c_parser_consume_token (parser
);
6194 exp_loc
= c_parser_peek_token (parser
)->location
;
6195 op
= c_parser_cast_expression (parser
, NULL
);
6196 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6197 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6200 if (!c_dialect_objc () && !in_system_header
)
6203 "traditional C rejects the unary plus operator");
6204 c_parser_consume_token (parser
);
6205 exp_loc
= c_parser_peek_token (parser
)->location
;
6206 op
= c_parser_cast_expression (parser
, NULL
);
6207 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6208 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6210 c_parser_consume_token (parser
);
6211 exp_loc
= c_parser_peek_token (parser
)->location
;
6212 op
= c_parser_cast_expression (parser
, NULL
);
6213 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6214 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6216 c_parser_consume_token (parser
);
6217 exp_loc
= c_parser_peek_token (parser
)->location
;
6218 op
= c_parser_cast_expression (parser
, NULL
);
6219 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6220 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6222 c_parser_consume_token (parser
);
6223 exp_loc
= c_parser_peek_token (parser
)->location
;
6224 op
= c_parser_cast_expression (parser
, NULL
);
6225 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6226 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6228 /* Refer to the address of a label as a pointer. */
6229 c_parser_consume_token (parser
);
6230 if (c_parser_next_token_is (parser
, CPP_NAME
))
6232 ret
.value
= finish_label_address_expr
6233 (c_parser_peek_token (parser
)->value
, op_loc
);
6234 c_parser_consume_token (parser
);
6238 c_parser_error (parser
, "expected identifier");
6239 ret
.value
= error_mark_node
;
6243 switch (c_parser_peek_token (parser
)->keyword
)
6246 return c_parser_sizeof_expression (parser
);
6248 return c_parser_alignof_expression (parser
);
6250 c_parser_consume_token (parser
);
6251 ext
= disable_extension_diagnostics ();
6252 ret
= c_parser_cast_expression (parser
, NULL
);
6253 restore_extension_diagnostics (ext
);
6256 c_parser_consume_token (parser
);
6257 exp_loc
= c_parser_peek_token (parser
)->location
;
6258 op
= c_parser_cast_expression (parser
, NULL
);
6259 op
= default_function_array_conversion (exp_loc
, op
);
6260 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6262 c_parser_consume_token (parser
);
6263 exp_loc
= c_parser_peek_token (parser
)->location
;
6264 op
= c_parser_cast_expression (parser
, NULL
);
6265 op
= default_function_array_conversion (exp_loc
, op
);
6266 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6267 case RID_TRANSACTION_ATOMIC
:
6268 case RID_TRANSACTION_RELAXED
:
6269 return c_parser_transaction_expression (parser
,
6270 c_parser_peek_token (parser
)->keyword
);
6272 return c_parser_postfix_expression (parser
);
6275 return c_parser_postfix_expression (parser
);
6279 /* Parse a sizeof expression. */
6281 static struct c_expr
6282 c_parser_sizeof_expression (c_parser
*parser
)
6285 location_t expr_loc
;
6286 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6287 c_parser_consume_token (parser
);
6288 c_inhibit_evaluation_warnings
++;
6290 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6291 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6293 /* Either sizeof ( type-name ) or sizeof unary-expression
6294 starting with a compound literal. */
6295 struct c_type_name
*type_name
;
6296 c_parser_consume_token (parser
);
6297 expr_loc
= c_parser_peek_token (parser
)->location
;
6298 type_name
= c_parser_type_name (parser
);
6299 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6300 if (type_name
== NULL
)
6303 c_inhibit_evaluation_warnings
--;
6305 ret
.value
= error_mark_node
;
6306 ret
.original_code
= ERROR_MARK
;
6307 ret
.original_type
= NULL
;
6310 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6312 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6317 /* sizeof ( type-name ). */
6318 c_inhibit_evaluation_warnings
--;
6320 return c_expr_sizeof_type (expr_loc
, type_name
);
6324 expr_loc
= c_parser_peek_token (parser
)->location
;
6325 expr
= c_parser_unary_expression (parser
);
6327 c_inhibit_evaluation_warnings
--;
6329 mark_exp_read (expr
.value
);
6330 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6331 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6332 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6333 return c_expr_sizeof_expr (expr_loc
, expr
);
6337 /* Parse an alignof expression. */
6339 static struct c_expr
6340 c_parser_alignof_expression (c_parser
*parser
)
6343 location_t loc
= c_parser_peek_token (parser
)->location
;
6344 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6345 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6346 /* A diagnostic is not required for the use of this identifier in
6347 the implementation namespace; only diagnose it for the C11
6348 spelling because of existing code using the other spellings. */
6350 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6353 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6356 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6359 c_parser_consume_token (parser
);
6360 c_inhibit_evaluation_warnings
++;
6362 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6363 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6365 /* Either __alignof__ ( type-name ) or __alignof__
6366 unary-expression starting with a compound literal. */
6368 struct c_type_name
*type_name
;
6370 c_parser_consume_token (parser
);
6371 loc
= c_parser_peek_token (parser
)->location
;
6372 type_name
= c_parser_type_name (parser
);
6373 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6374 if (type_name
== NULL
)
6377 c_inhibit_evaluation_warnings
--;
6379 ret
.value
= error_mark_node
;
6380 ret
.original_code
= ERROR_MARK
;
6381 ret
.original_type
= NULL
;
6384 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6386 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6391 /* alignof ( type-name ). */
6392 c_inhibit_evaluation_warnings
--;
6394 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6395 ret
.original_code
= ERROR_MARK
;
6396 ret
.original_type
= NULL
;
6402 expr
= c_parser_unary_expression (parser
);
6404 mark_exp_read (expr
.value
);
6405 c_inhibit_evaluation_warnings
--;
6407 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6409 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6410 ret
.original_code
= ERROR_MARK
;
6411 ret
.original_type
= NULL
;
6416 /* Helper function to read arguments of builtins which are interfaces
6417 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6418 others. The name of the builtin is passed using BNAME parameter.
6419 Function returns true if there were no errors while parsing and
6420 stores the arguments in CEXPR_LIST. */
6422 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6423 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6426 location_t loc
= c_parser_peek_token (parser
)->location
;
6427 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6429 bool saved_force_folding_builtin_constant_p
;
6431 *ret_cexpr_list
= NULL
;
6432 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6434 error_at (loc
, "cannot take address of %qs", bname
);
6438 c_parser_consume_token (parser
);
6440 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6442 c_parser_consume_token (parser
);
6446 saved_force_folding_builtin_constant_p
6447 = force_folding_builtin_constant_p
;
6448 force_folding_builtin_constant_p
|= choose_expr_p
;
6449 expr
= c_parser_expr_no_commas (parser
, NULL
);
6450 force_folding_builtin_constant_p
6451 = saved_force_folding_builtin_constant_p
;
6452 vec_alloc (cexpr_list
, 1);
6453 C_EXPR_APPEND (cexpr_list
, expr
);
6454 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6456 c_parser_consume_token (parser
);
6457 expr
= c_parser_expr_no_commas (parser
, NULL
);
6458 C_EXPR_APPEND (cexpr_list
, expr
);
6461 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6464 *ret_cexpr_list
= cexpr_list
;
6468 /* This represents a single generic-association. */
6470 struct c_generic_association
6472 /* The location of the starting token of the type. */
6473 location_t type_location
;
6474 /* The association's type, or NULL_TREE for 'default'. */
6476 /* The association's expression. */
6477 struct c_expr expression
;
6480 /* Parse a generic-selection. (C11 6.5.1.1).
6483 _Generic ( assignment-expression , generic-assoc-list )
6487 generic-assoc-list , generic-association
6489 generic-association:
6490 type-name : assignment-expression
6491 default : assignment-expression
6494 static struct c_expr
6495 c_parser_generic_selection (c_parser
*parser
)
6497 vec
<c_generic_association
> associations
= vNULL
;
6498 struct c_expr selector
, error_expr
;
6500 struct c_generic_association matched_assoc
;
6501 bool match_found
= false;
6502 location_t generic_loc
, selector_loc
;
6504 error_expr
.original_code
= ERROR_MARK
;
6505 error_expr
.original_type
= NULL
;
6506 error_expr
.value
= error_mark_node
;
6507 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6508 matched_assoc
.type
= NULL_TREE
;
6509 matched_assoc
.expression
= error_expr
;
6511 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6512 generic_loc
= c_parser_peek_token (parser
)->location
;
6513 c_parser_consume_token (parser
);
6517 pedwarn (generic_loc
, OPT_Wpedantic
,
6518 "ISO C99 does not support %<_Generic%>");
6520 pedwarn (generic_loc
, OPT_Wpedantic
,
6521 "ISO C90 does not support %<_Generic%>");
6524 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6527 c_inhibit_evaluation_warnings
++;
6528 selector_loc
= c_parser_peek_token (parser
)->location
;
6529 selector
= c_parser_expr_no_commas (parser
, NULL
);
6530 selector
= default_function_array_conversion (selector_loc
, selector
);
6531 c_inhibit_evaluation_warnings
--;
6533 if (selector
.value
== error_mark_node
)
6535 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6538 selector_type
= TREE_TYPE (selector
.value
);
6539 /* In ISO C terms, rvalues (including the controlling expression of
6540 _Generic) do not have qualified types. */
6541 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6542 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6543 /* In ISO C terms, _Noreturn is not part of the type of expressions
6544 such as &abort, but in GCC it is represented internally as a type
6546 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6547 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6549 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6551 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6553 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6559 struct c_generic_association assoc
, *iter
;
6561 c_token
*token
= c_parser_peek_token (parser
);
6563 assoc
.type_location
= token
->location
;
6564 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6566 c_parser_consume_token (parser
);
6567 assoc
.type
= NULL_TREE
;
6571 struct c_type_name
*type_name
;
6573 type_name
= c_parser_type_name (parser
);
6574 if (type_name
== NULL
)
6576 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6579 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6580 if (assoc
.type
== error_mark_node
)
6582 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6586 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6587 error_at (assoc
.type_location
,
6588 "%<_Generic%> association has function type");
6589 else if (!COMPLETE_TYPE_P (assoc
.type
))
6590 error_at (assoc
.type_location
,
6591 "%<_Generic%> association has incomplete type");
6593 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6594 error_at (assoc
.type_location
,
6595 "%<_Generic%> association has "
6596 "variable length type");
6599 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6601 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6605 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6606 if (assoc
.expression
.value
== error_mark_node
)
6608 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6612 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6614 if (assoc
.type
== NULL_TREE
)
6616 if (iter
->type
== NULL_TREE
)
6618 error_at (assoc
.type_location
,
6619 "duplicate %<default%> case in %<_Generic%>");
6620 inform (iter
->type_location
, "original %<default%> is here");
6623 else if (iter
->type
!= NULL_TREE
)
6625 if (comptypes (assoc
.type
, iter
->type
))
6627 error_at (assoc
.type_location
,
6628 "%<_Generic%> specifies two compatible types");
6629 inform (iter
->type_location
, "compatible type is here");
6634 if (assoc
.type
== NULL_TREE
)
6638 matched_assoc
= assoc
;
6642 else if (comptypes (assoc
.type
, selector_type
))
6644 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6646 matched_assoc
= assoc
;
6651 error_at (assoc
.type_location
,
6652 "%<_Generic> selector matches multiple associations");
6653 inform (matched_assoc
.type_location
,
6654 "other match is here");
6658 associations
.safe_push (assoc
);
6660 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6662 c_parser_consume_token (parser
);
6665 associations
.release ();
6667 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6669 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6675 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6676 "compatible with any association",
6681 return matched_assoc
.expression
;
6684 associations
.release ();
6688 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6692 postfix-expression [ expression ]
6693 postfix-expression ( argument-expression-list[opt] )
6694 postfix-expression . identifier
6695 postfix-expression -> identifier
6696 postfix-expression ++
6697 postfix-expression --
6698 ( type-name ) { initializer-list }
6699 ( type-name ) { initializer-list , }
6701 argument-expression-list:
6703 argument-expression-list , argument-expression
6716 (treated as a keyword in GNU C)
6719 ( compound-statement )
6720 __builtin_va_arg ( assignment-expression , type-name )
6721 __builtin_offsetof ( type-name , offsetof-member-designator )
6722 __builtin_choose_expr ( assignment-expression ,
6723 assignment-expression ,
6724 assignment-expression )
6725 __builtin_types_compatible_p ( type-name , type-name )
6726 __builtin_complex ( assignment-expression , assignment-expression )
6727 __builtin_shuffle ( assignment-expression , assignment-expression )
6728 __builtin_shuffle ( assignment-expression ,
6729 assignment-expression ,
6730 assignment-expression, )
6732 offsetof-member-designator:
6734 offsetof-member-designator . identifier
6735 offsetof-member-designator [ expression ]
6740 [ objc-receiver objc-message-args ]
6741 @selector ( objc-selector-arg )
6742 @protocol ( identifier )
6743 @encode ( type-name )
6745 Classname . identifier
6748 static struct c_expr
6749 c_parser_postfix_expression (c_parser
*parser
)
6751 struct c_expr expr
, e1
;
6752 struct c_type_name
*t1
, *t2
;
6753 location_t loc
= c_parser_peek_token (parser
)->location
;;
6754 expr
.original_code
= ERROR_MARK
;
6755 expr
.original_type
= NULL
;
6756 switch (c_parser_peek_token (parser
)->type
)
6759 expr
.value
= c_parser_peek_token (parser
)->value
;
6760 loc
= c_parser_peek_token (parser
)->location
;
6761 c_parser_consume_token (parser
);
6762 if (TREE_CODE (expr
.value
) == FIXED_CST
6763 && !targetm
.fixed_point_supported_p ())
6765 error_at (loc
, "fixed-point types not supported for this target");
6766 expr
.value
= error_mark_node
;
6773 expr
.value
= c_parser_peek_token (parser
)->value
;
6774 c_parser_consume_token (parser
);
6780 case CPP_UTF8STRING
:
6781 expr
.value
= c_parser_peek_token (parser
)->value
;
6782 expr
.original_code
= STRING_CST
;
6783 c_parser_consume_token (parser
);
6785 case CPP_OBJC_STRING
:
6786 gcc_assert (c_dialect_objc ());
6788 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6789 c_parser_consume_token (parser
);
6792 switch (c_parser_peek_token (parser
)->id_kind
)
6796 tree id
= c_parser_peek_token (parser
)->value
;
6797 c_parser_consume_token (parser
);
6798 expr
.value
= build_external_ref (loc
, id
,
6799 (c_parser_peek_token (parser
)->type
6801 &expr
.original_type
);
6804 case C_ID_CLASSNAME
:
6806 /* Here we parse the Objective-C 2.0 Class.name dot
6808 tree class_name
= c_parser_peek_token (parser
)->value
;
6810 c_parser_consume_token (parser
);
6811 gcc_assert (c_dialect_objc ());
6812 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6814 expr
.value
= error_mark_node
;
6817 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6819 c_parser_error (parser
, "expected identifier");
6820 expr
.value
= error_mark_node
;
6823 component
= c_parser_peek_token (parser
)->value
;
6824 c_parser_consume_token (parser
);
6825 expr
.value
= objc_build_class_component_ref (class_name
,
6830 c_parser_error (parser
, "expected expression");
6831 expr
.value
= error_mark_node
;
6835 case CPP_OPEN_PAREN
:
6836 /* A parenthesized expression, statement expression or compound
6838 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6840 /* A statement expression. */
6842 location_t brace_loc
;
6843 c_parser_consume_token (parser
);
6844 brace_loc
= c_parser_peek_token (parser
)->location
;
6845 c_parser_consume_token (parser
);
6846 if (!building_stmt_list_p ())
6848 error_at (loc
, "braced-group within expression allowed "
6849 "only inside a function");
6850 parser
->error
= true;
6851 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6852 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6853 expr
.value
= error_mark_node
;
6856 stmt
= c_begin_stmt_expr ();
6857 c_parser_compound_statement_nostart (parser
);
6858 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6860 pedwarn (loc
, OPT_Wpedantic
,
6861 "ISO C forbids braced-groups within expressions");
6862 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6863 mark_exp_read (expr
.value
);
6865 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6867 /* A compound literal. ??? Can we actually get here rather
6868 than going directly to
6869 c_parser_postfix_expression_after_paren_type from
6872 struct c_type_name
*type_name
;
6873 c_parser_consume_token (parser
);
6874 loc
= c_parser_peek_token (parser
)->location
;
6875 type_name
= c_parser_type_name (parser
);
6876 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6878 if (type_name
== NULL
)
6880 expr
.value
= error_mark_node
;
6883 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6889 /* A parenthesized expression. */
6890 c_parser_consume_token (parser
);
6891 expr
= c_parser_expression (parser
);
6892 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6893 TREE_NO_WARNING (expr
.value
) = 1;
6894 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6895 expr
.original_code
= ERROR_MARK
;
6896 /* Don't change EXPR.ORIGINAL_TYPE. */
6897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6902 switch (c_parser_peek_token (parser
)->keyword
)
6904 case RID_FUNCTION_NAME
:
6905 case RID_PRETTY_FUNCTION_NAME
:
6906 case RID_C99_FUNCTION_NAME
:
6907 expr
.value
= fname_decl (loc
,
6908 c_parser_peek_token (parser
)->keyword
,
6909 c_parser_peek_token (parser
)->value
);
6910 c_parser_consume_token (parser
);
6913 c_parser_consume_token (parser
);
6914 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6916 expr
.value
= error_mark_node
;
6919 e1
= c_parser_expr_no_commas (parser
, NULL
);
6920 mark_exp_read (e1
.value
);
6921 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6922 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6924 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6925 expr
.value
= error_mark_node
;
6928 loc
= c_parser_peek_token (parser
)->location
;
6929 t1
= c_parser_type_name (parser
);
6930 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6934 expr
.value
= error_mark_node
;
6938 tree type_expr
= NULL_TREE
;
6939 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6940 groktypename (t1
, &type_expr
, NULL
));
6943 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6944 TREE_TYPE (expr
.value
), type_expr
,
6946 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6951 c_parser_consume_token (parser
);
6952 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6954 expr
.value
= error_mark_node
;
6957 t1
= c_parser_type_name (parser
);
6959 parser
->error
= true;
6960 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6961 gcc_assert (parser
->error
);
6964 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6965 expr
.value
= error_mark_node
;
6970 tree type
= groktypename (t1
, NULL
, NULL
);
6972 if (type
== error_mark_node
)
6973 offsetof_ref
= error_mark_node
;
6976 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6977 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6979 /* Parse the second argument to __builtin_offsetof. We
6980 must have one identifier, and beyond that we want to
6981 accept sub structure and sub array references. */
6982 if (c_parser_next_token_is (parser
, CPP_NAME
))
6984 offsetof_ref
= build_component_ref
6985 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6986 c_parser_consume_token (parser
);
6987 while (c_parser_next_token_is (parser
, CPP_DOT
)
6988 || c_parser_next_token_is (parser
,
6990 || c_parser_next_token_is (parser
,
6993 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6995 loc
= c_parser_peek_token (parser
)->location
;
6996 offsetof_ref
= build_array_ref (loc
,
7001 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7004 c_parser_consume_token (parser
);
7005 if (c_parser_next_token_is_not (parser
,
7008 c_parser_error (parser
, "expected identifier");
7011 offsetof_ref
= build_component_ref
7013 c_parser_peek_token (parser
)->value
);
7014 c_parser_consume_token (parser
);
7020 loc
= c_parser_peek_token (parser
)->location
;
7021 c_parser_consume_token (parser
);
7022 ce
= c_parser_expression (parser
);
7023 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7025 idx
= c_fully_fold (idx
, false, NULL
);
7026 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7028 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7033 c_parser_error (parser
, "expected identifier");
7034 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7036 expr
.value
= fold_offsetof (offsetof_ref
);
7039 case RID_CHOOSE_EXPR
:
7041 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7042 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7045 c_parser_consume_token (parser
);
7046 if (!c_parser_get_builtin_args (parser
,
7047 "__builtin_choose_expr",
7050 expr
.value
= error_mark_node
;
7054 if (vec_safe_length (cexpr_list
) != 3)
7056 error_at (loc
, "wrong number of arguments to "
7057 "%<__builtin_choose_expr%>");
7058 expr
.value
= error_mark_node
;
7062 e1_p
= &(*cexpr_list
)[0];
7063 e2_p
= &(*cexpr_list
)[1];
7064 e3_p
= &(*cexpr_list
)[2];
7067 mark_exp_read (e2_p
->value
);
7068 mark_exp_read (e3_p
->value
);
7069 if (TREE_CODE (c
) != INTEGER_CST
7070 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7072 "first argument to %<__builtin_choose_expr%> not"
7074 constant_expression_warning (c
);
7075 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7078 case RID_TYPES_COMPATIBLE_P
:
7079 c_parser_consume_token (parser
);
7080 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7082 expr
.value
= error_mark_node
;
7085 t1
= c_parser_type_name (parser
);
7088 expr
.value
= error_mark_node
;
7091 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7093 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7094 expr
.value
= error_mark_node
;
7097 t2
= c_parser_type_name (parser
);
7100 expr
.value
= error_mark_node
;
7103 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7107 e1
= groktypename (t1
, NULL
, NULL
);
7108 e2
= groktypename (t2
, NULL
, NULL
);
7109 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7111 expr
.value
= error_mark_node
;
7115 e1
= TYPE_MAIN_VARIANT (e1
);
7116 e2
= TYPE_MAIN_VARIANT (e2
);
7119 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7122 case RID_BUILTIN_COMPLEX
:
7124 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7125 c_expr_t
*e1_p
, *e2_p
;
7127 c_parser_consume_token (parser
);
7128 if (!c_parser_get_builtin_args (parser
,
7129 "__builtin_complex",
7130 &cexpr_list
, false))
7132 expr
.value
= error_mark_node
;
7136 if (vec_safe_length (cexpr_list
) != 2)
7138 error_at (loc
, "wrong number of arguments to "
7139 "%<__builtin_complex%>");
7140 expr
.value
= error_mark_node
;
7144 e1_p
= &(*cexpr_list
)[0];
7145 e2_p
= &(*cexpr_list
)[1];
7147 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7148 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7149 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7150 TREE_OPERAND (e1_p
->value
, 0));
7151 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7152 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7153 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7154 TREE_OPERAND (e2_p
->value
, 0));
7155 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7156 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7157 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7158 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7160 error_at (loc
, "%<__builtin_complex%> operand "
7161 "not of real binary floating-point type");
7162 expr
.value
= error_mark_node
;
7165 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7166 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7169 "%<__builtin_complex%> operands of different types");
7170 expr
.value
= error_mark_node
;
7174 pedwarn (loc
, OPT_Wpedantic
,
7175 "ISO C90 does not support complex types");
7176 expr
.value
= build2 (COMPLEX_EXPR
,
7179 (TREE_TYPE (e1_p
->value
))),
7180 e1_p
->value
, e2_p
->value
);
7183 case RID_BUILTIN_SHUFFLE
:
7185 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7189 c_parser_consume_token (parser
);
7190 if (!c_parser_get_builtin_args (parser
,
7191 "__builtin_shuffle",
7192 &cexpr_list
, false))
7194 expr
.value
= error_mark_node
;
7198 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7199 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7201 if (vec_safe_length (cexpr_list
) == 2)
7203 c_build_vec_perm_expr
7204 (loc
, (*cexpr_list
)[0].value
,
7205 NULL_TREE
, (*cexpr_list
)[1].value
);
7207 else if (vec_safe_length (cexpr_list
) == 3)
7209 c_build_vec_perm_expr
7210 (loc
, (*cexpr_list
)[0].value
,
7211 (*cexpr_list
)[1].value
,
7212 (*cexpr_list
)[2].value
);
7215 error_at (loc
, "wrong number of arguments to "
7216 "%<__builtin_shuffle%>");
7217 expr
.value
= error_mark_node
;
7221 case RID_AT_SELECTOR
:
7222 gcc_assert (c_dialect_objc ());
7223 c_parser_consume_token (parser
);
7224 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7226 expr
.value
= error_mark_node
;
7230 tree sel
= c_parser_objc_selector_arg (parser
);
7231 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7233 expr
.value
= objc_build_selector_expr (loc
, sel
);
7236 case RID_AT_PROTOCOL
:
7237 gcc_assert (c_dialect_objc ());
7238 c_parser_consume_token (parser
);
7239 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7241 expr
.value
= error_mark_node
;
7244 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7246 c_parser_error (parser
, "expected identifier");
7247 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7248 expr
.value
= error_mark_node
;
7252 tree id
= c_parser_peek_token (parser
)->value
;
7253 c_parser_consume_token (parser
);
7254 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7256 expr
.value
= objc_build_protocol_expr (id
);
7260 /* Extension to support C-structures in the archiver. */
7261 gcc_assert (c_dialect_objc ());
7262 c_parser_consume_token (parser
);
7263 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7265 expr
.value
= error_mark_node
;
7268 t1
= c_parser_type_name (parser
);
7271 expr
.value
= error_mark_node
;
7272 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7275 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7278 tree type
= groktypename (t1
, NULL
, NULL
);
7279 expr
.value
= objc_build_encode_expr (type
);
7283 expr
= c_parser_generic_selection (parser
);
7285 case RID_CILK_SPAWN
:
7286 c_parser_consume_token (parser
);
7287 if (!flag_enable_cilkplus
)
7289 error_at (loc
, "-fcilkplus must be enabled to use "
7291 expr
= c_parser_postfix_expression (parser
);
7292 expr
.value
= error_mark_node
;
7294 if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7296 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7297 "are not permitted");
7298 /* Now flush out all the _Cilk_spawns. */
7299 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7300 c_parser_consume_token (parser
);
7301 expr
= c_parser_postfix_expression (parser
);
7305 expr
= c_parser_postfix_expression (parser
);
7306 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7310 c_parser_error (parser
, "expected expression");
7311 expr
.value
= error_mark_node
;
7315 case CPP_OPEN_SQUARE
:
7316 if (c_dialect_objc ())
7318 tree receiver
, args
;
7319 c_parser_consume_token (parser
);
7320 receiver
= c_parser_objc_receiver (parser
);
7321 args
= c_parser_objc_message_args (parser
);
7322 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7324 expr
.value
= objc_build_message_expr (receiver
, args
);
7327 /* Else fall through to report error. */
7329 c_parser_error (parser
, "expected expression");
7330 expr
.value
= error_mark_node
;
7333 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7336 /* Parse a postfix expression after a parenthesized type name: the
7337 brace-enclosed initializer of a compound literal, possibly followed
7338 by some postfix operators. This is separate because it is not
7339 possible to tell until after the type name whether a cast
7340 expression has a cast or a compound literal, or whether the operand
7341 of sizeof is a parenthesized type name or starts with a compound
7342 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7343 location of the first token after the parentheses around the type
7346 static struct c_expr
7347 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7348 struct c_type_name
*type_name
,
7349 location_t type_loc
)
7355 location_t start_loc
;
7356 tree type_expr
= NULL_TREE
;
7357 bool type_expr_const
= true;
7358 check_compound_literal_type (type_loc
, type_name
);
7359 start_init (NULL_TREE
, NULL
, 0);
7360 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7361 start_loc
= c_parser_peek_token (parser
)->location
;
7362 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7364 error_at (type_loc
, "compound literal has variable size");
7365 type
= error_mark_node
;
7367 init
= c_parser_braced_init (parser
, type
, false);
7369 maybe_warn_string_init (type
, init
);
7371 if (type
!= error_mark_node
7372 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7373 && current_function_decl
)
7375 error ("compound literal qualified by address-space qualifier");
7376 type
= error_mark_node
;
7380 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7381 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7382 ? CONSTRUCTOR_NON_CONST (init
.value
)
7383 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7384 non_const
|= !type_expr_const
;
7385 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7386 expr
.original_code
= ERROR_MARK
;
7387 expr
.original_type
= NULL
;
7390 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7392 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7393 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7397 gcc_assert (!non_const
);
7398 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7399 type_expr
, expr
.value
);
7402 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7405 /* Callback function for sizeof_pointer_memaccess_warning to compare
7409 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7411 return comptypes (type1
, type2
) == 1;
7414 /* Parse a postfix expression after the initial primary or compound
7415 literal; that is, parse a series of postfix operators.
7417 EXPR_LOC is the location of the primary expression. */
7419 static struct c_expr
7420 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7421 location_t expr_loc
,
7424 struct c_expr orig_expr
;
7426 location_t sizeof_arg_loc
[3];
7429 vec
<tree
, va_gc
> *exprlist
;
7430 vec
<tree
, va_gc
> *origtypes
= NULL
;
7433 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7434 switch (c_parser_peek_token (parser
)->type
)
7436 case CPP_OPEN_SQUARE
:
7437 /* Array reference. */
7438 c_parser_consume_token (parser
);
7439 if (flag_enable_cilkplus
7440 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7441 /* If we are here, then we have something like this:
7444 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7448 idx
= c_parser_expression (parser
).value
;
7449 /* Here we have 3 options:
7450 1. Array [EXPR] -- Normal Array call.
7451 2. Array [EXPR : EXPR] -- Array notation without stride.
7452 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7454 For 1, we just handle it just like a normal array expression.
7455 For 2 and 3 we handle it like we handle array notations. The
7456 idx value we have above becomes the initial/start index.
7458 if (flag_enable_cilkplus
7459 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7460 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7464 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7466 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7469 expr
.original_code
= ERROR_MARK
;
7470 expr
.original_type
= NULL
;
7472 case CPP_OPEN_PAREN
:
7473 /* Function call. */
7474 c_parser_consume_token (parser
);
7475 for (i
= 0; i
< 3; i
++)
7477 sizeof_arg
[i
] = NULL_TREE
;
7478 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7480 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7483 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7484 sizeof_arg_loc
, sizeof_arg
);
7485 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7488 mark_exp_read (expr
.value
);
7489 if (warn_sizeof_pointer_memaccess
)
7490 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7491 expr
.value
, exprlist
,
7493 sizeof_ptr_memacc_comptypes
);
7494 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7495 "(" after the FUNCNAME, which is what we have now. */
7496 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7498 expr
.original_code
= ERROR_MARK
;
7499 if (TREE_CODE (expr
.value
) == INTEGER_CST
7500 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7501 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7502 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7503 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7504 expr
.original_type
= NULL
;
7507 release_tree_vector (exprlist
);
7508 release_tree_vector (origtypes
);
7512 /* Structure element reference. */
7513 c_parser_consume_token (parser
);
7514 expr
= default_function_array_conversion (expr_loc
, expr
);
7515 if (c_parser_next_token_is (parser
, CPP_NAME
))
7516 ident
= c_parser_peek_token (parser
)->value
;
7519 c_parser_error (parser
, "expected identifier");
7520 expr
.value
= error_mark_node
;
7521 expr
.original_code
= ERROR_MARK
;
7522 expr
.original_type
= NULL
;
7525 c_parser_consume_token (parser
);
7526 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7527 expr
.original_code
= ERROR_MARK
;
7528 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7529 expr
.original_type
= NULL
;
7532 /* Remember the original type of a bitfield. */
7533 tree field
= TREE_OPERAND (expr
.value
, 1);
7534 if (TREE_CODE (field
) != FIELD_DECL
)
7535 expr
.original_type
= NULL
;
7537 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7541 /* Structure element reference. */
7542 c_parser_consume_token (parser
);
7543 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7544 if (c_parser_next_token_is (parser
, CPP_NAME
))
7545 ident
= c_parser_peek_token (parser
)->value
;
7548 c_parser_error (parser
, "expected identifier");
7549 expr
.value
= error_mark_node
;
7550 expr
.original_code
= ERROR_MARK
;
7551 expr
.original_type
= NULL
;
7554 c_parser_consume_token (parser
);
7555 expr
.value
= build_component_ref (op_loc
,
7556 build_indirect_ref (op_loc
,
7560 expr
.original_code
= ERROR_MARK
;
7561 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7562 expr
.original_type
= NULL
;
7565 /* Remember the original type of a bitfield. */
7566 tree field
= TREE_OPERAND (expr
.value
, 1);
7567 if (TREE_CODE (field
) != FIELD_DECL
)
7568 expr
.original_type
= NULL
;
7570 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7574 /* Postincrement. */
7575 c_parser_consume_token (parser
);
7576 /* If the expressions have array notations, we expand them. */
7577 if (flag_enable_cilkplus
7578 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7579 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7582 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7583 expr
.value
= build_unary_op (op_loc
,
7584 POSTINCREMENT_EXPR
, expr
.value
, 0);
7586 expr
.original_code
= ERROR_MARK
;
7587 expr
.original_type
= NULL
;
7589 case CPP_MINUS_MINUS
:
7590 /* Postdecrement. */
7591 c_parser_consume_token (parser
);
7592 /* If the expressions have array notations, we expand them. */
7593 if (flag_enable_cilkplus
7594 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7595 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7598 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7599 expr
.value
= build_unary_op (op_loc
,
7600 POSTDECREMENT_EXPR
, expr
.value
, 0);
7602 expr
.original_code
= ERROR_MARK
;
7603 expr
.original_type
= NULL
;
7611 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7614 assignment-expression
7615 expression , assignment-expression
7618 static struct c_expr
7619 c_parser_expression (c_parser
*parser
)
7621 location_t tloc
= c_parser_peek_token (parser
)->location
;
7623 expr
= c_parser_expr_no_commas (parser
, NULL
);
7624 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7625 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7626 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7630 location_t loc
= c_parser_peek_token (parser
)->location
;
7631 location_t expr_loc
;
7632 c_parser_consume_token (parser
);
7633 expr_loc
= c_parser_peek_token (parser
)->location
;
7634 lhsval
= expr
.value
;
7635 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7636 lhsval
= TREE_OPERAND (lhsval
, 1);
7637 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7638 mark_exp_read (lhsval
);
7639 next
= c_parser_expr_no_commas (parser
, NULL
);
7640 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7641 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7642 expr
.original_code
= COMPOUND_EXPR
;
7643 expr
.original_type
= next
.original_type
;
7648 /* Parse an expression and convert functions or arrays to pointers and
7649 lvalues to rvalues. */
7651 static struct c_expr
7652 c_parser_expression_conv (c_parser
*parser
)
7655 location_t loc
= c_parser_peek_token (parser
)->location
;
7656 expr
= c_parser_expression (parser
);
7657 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7661 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7662 functions and arrays to pointers and lvalues to rvalues. If
7663 FOLD_P, fold the expressions.
7666 assignment-expression
7667 nonempty-expr-list , assignment-expression
7670 static vec
<tree
, va_gc
> *
7671 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7672 vec
<tree
, va_gc
> **p_orig_types
,
7673 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7675 vec
<tree
, va_gc
> *ret
;
7676 vec
<tree
, va_gc
> *orig_types
;
7678 location_t loc
= c_parser_peek_token (parser
)->location
;
7679 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7680 unsigned int idx
= 0;
7682 ret
= make_tree_vector ();
7683 if (p_orig_types
== NULL
)
7686 orig_types
= make_tree_vector ();
7688 if (sizeof_arg
!= NULL
7689 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7690 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7691 expr
= c_parser_expr_no_commas (parser
, NULL
);
7693 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7695 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7696 ret
->quick_push (expr
.value
);
7698 orig_types
->quick_push (expr
.original_type
);
7699 if (sizeof_arg
!= NULL
7700 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7701 && expr
.original_code
== SIZEOF_EXPR
)
7703 sizeof_arg
[0] = c_last_sizeof_arg
;
7704 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7706 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7708 c_parser_consume_token (parser
);
7709 loc
= c_parser_peek_token (parser
)->location
;
7710 if (sizeof_arg
!= NULL
7711 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7712 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7714 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7715 expr
= c_parser_expr_no_commas (parser
, NULL
);
7717 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7719 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7720 vec_safe_push (ret
, expr
.value
);
7722 vec_safe_push (orig_types
, expr
.original_type
);
7724 && sizeof_arg
!= NULL
7725 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7726 && expr
.original_code
== SIZEOF_EXPR
)
7728 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7729 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7733 *p_orig_types
= orig_types
;
7737 /* Parse Objective-C-specific constructs. */
7739 /* Parse an objc-class-definition.
7741 objc-class-definition:
7742 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7743 objc-class-instance-variables[opt] objc-methodprotolist @end
7744 @implementation identifier objc-superclass[opt]
7745 objc-class-instance-variables[opt]
7746 @interface identifier ( identifier ) objc-protocol-refs[opt]
7747 objc-methodprotolist @end
7748 @interface identifier ( ) objc-protocol-refs[opt]
7749 objc-methodprotolist @end
7750 @implementation identifier ( identifier )
7755 "@interface identifier (" must start "@interface identifier (
7756 identifier ) ...": objc-methodprotolist in the first production may
7757 not start with a parenthesized identifier as a declarator of a data
7758 definition with no declaration specifiers if the objc-superclass,
7759 objc-protocol-refs and objc-class-instance-variables are omitted. */
7762 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7767 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7769 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7774 c_parser_consume_token (parser
);
7775 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7777 c_parser_error (parser
, "expected identifier");
7780 id1
= c_parser_peek_token (parser
)->value
;
7781 c_parser_consume_token (parser
);
7782 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7784 /* We have a category or class extension. */
7786 tree proto
= NULL_TREE
;
7787 c_parser_consume_token (parser
);
7788 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7790 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7792 /* We have a class extension. */
7797 c_parser_error (parser
, "expected identifier or %<)%>");
7798 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7804 id2
= c_parser_peek_token (parser
)->value
;
7805 c_parser_consume_token (parser
);
7807 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7810 objc_start_category_implementation (id1
, id2
);
7813 if (c_parser_next_token_is (parser
, CPP_LESS
))
7814 proto
= c_parser_objc_protocol_refs (parser
);
7815 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7816 c_parser_objc_methodprotolist (parser
);
7817 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7818 objc_finish_interface ();
7821 if (c_parser_next_token_is (parser
, CPP_COLON
))
7823 c_parser_consume_token (parser
);
7824 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7826 c_parser_error (parser
, "expected identifier");
7829 superclass
= c_parser_peek_token (parser
)->value
;
7830 c_parser_consume_token (parser
);
7833 superclass
= NULL_TREE
;
7836 tree proto
= NULL_TREE
;
7837 if (c_parser_next_token_is (parser
, CPP_LESS
))
7838 proto
= c_parser_objc_protocol_refs (parser
);
7839 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7842 objc_start_class_implementation (id1
, superclass
);
7843 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7844 c_parser_objc_class_instance_variables (parser
);
7847 objc_continue_interface ();
7848 c_parser_objc_methodprotolist (parser
);
7849 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7850 objc_finish_interface ();
7854 objc_continue_implementation ();
7859 /* Parse objc-class-instance-variables.
7861 objc-class-instance-variables:
7862 { objc-instance-variable-decl-list[opt] }
7864 objc-instance-variable-decl-list:
7865 objc-visibility-spec
7866 objc-instance-variable-decl ;
7868 objc-instance-variable-decl-list objc-visibility-spec
7869 objc-instance-variable-decl-list objc-instance-variable-decl ;
7870 objc-instance-variable-decl-list ;
7872 objc-visibility-spec:
7877 objc-instance-variable-decl:
7882 c_parser_objc_class_instance_variables (c_parser
*parser
)
7884 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7885 c_parser_consume_token (parser
);
7886 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7889 /* Parse any stray semicolon. */
7890 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7892 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7894 c_parser_consume_token (parser
);
7897 /* Stop if at the end of the instance variables. */
7898 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7900 c_parser_consume_token (parser
);
7903 /* Parse any objc-visibility-spec. */
7904 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7906 c_parser_consume_token (parser
);
7907 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7910 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7912 c_parser_consume_token (parser
);
7913 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7916 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7918 c_parser_consume_token (parser
);
7919 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7922 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7924 c_parser_consume_token (parser
);
7925 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7928 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7930 c_parser_pragma (parser
, pragma_external
);
7934 /* Parse some comma-separated declarations. */
7935 decls
= c_parser_struct_declaration (parser
);
7938 /* There is a syntax error. We want to skip the offending
7939 tokens up to the next ';' (included) or '}'
7942 /* First, skip manually a ')' or ']'. This is because they
7943 reduce the nesting level, so c_parser_skip_until_found()
7944 wouldn't be able to skip past them. */
7945 c_token
*token
= c_parser_peek_token (parser
);
7946 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7947 c_parser_consume_token (parser
);
7949 /* Then, do the standard skipping. */
7950 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7952 /* We hopefully recovered. Start normal parsing again. */
7953 parser
->error
= false;
7958 /* Comma-separated instance variables are chained together
7959 in reverse order; add them one by one. */
7960 tree ivar
= nreverse (decls
);
7961 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7962 objc_add_instance_variable (copy_node (ivar
));
7964 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7968 /* Parse an objc-class-declaration.
7970 objc-class-declaration:
7971 @class identifier-list ;
7975 c_parser_objc_class_declaration (c_parser
*parser
)
7977 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7978 c_parser_consume_token (parser
);
7979 /* Any identifiers, including those declared as type names, are OK
7984 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7986 c_parser_error (parser
, "expected identifier");
7987 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7988 parser
->error
= false;
7991 id
= c_parser_peek_token (parser
)->value
;
7992 objc_declare_class (id
);
7993 c_parser_consume_token (parser
);
7994 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7995 c_parser_consume_token (parser
);
7999 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8002 /* Parse an objc-alias-declaration.
8004 objc-alias-declaration:
8005 @compatibility_alias identifier identifier ;
8009 c_parser_objc_alias_declaration (c_parser
*parser
)
8012 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8013 c_parser_consume_token (parser
);
8014 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8016 c_parser_error (parser
, "expected identifier");
8017 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8020 id1
= c_parser_peek_token (parser
)->value
;
8021 c_parser_consume_token (parser
);
8022 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8024 c_parser_error (parser
, "expected identifier");
8025 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8028 id2
= c_parser_peek_token (parser
)->value
;
8029 c_parser_consume_token (parser
);
8030 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8031 objc_declare_alias (id1
, id2
);
8034 /* Parse an objc-protocol-definition.
8036 objc-protocol-definition:
8037 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8038 @protocol identifier-list ;
8040 "@protocol identifier ;" should be resolved as "@protocol
8041 identifier-list ;": objc-methodprotolist may not start with a
8042 semicolon in the first alternative if objc-protocol-refs are
8046 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8048 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8050 c_parser_consume_token (parser
);
8051 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8053 c_parser_error (parser
, "expected identifier");
8056 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8057 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8059 /* Any identifiers, including those declared as type names, are
8064 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8066 c_parser_error (parser
, "expected identifier");
8069 id
= c_parser_peek_token (parser
)->value
;
8070 objc_declare_protocol (id
, attributes
);
8071 c_parser_consume_token (parser
);
8072 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8073 c_parser_consume_token (parser
);
8077 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8081 tree id
= c_parser_peek_token (parser
)->value
;
8082 tree proto
= NULL_TREE
;
8083 c_parser_consume_token (parser
);
8084 if (c_parser_next_token_is (parser
, CPP_LESS
))
8085 proto
= c_parser_objc_protocol_refs (parser
);
8086 parser
->objc_pq_context
= true;
8087 objc_start_protocol (id
, proto
, attributes
);
8088 c_parser_objc_methodprotolist (parser
);
8089 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8090 parser
->objc_pq_context
= false;
8091 objc_finish_interface ();
8095 /* Parse an objc-method-type.
8101 Return true if it is a class method (+) and false if it is
8102 an instance method (-).
8105 c_parser_objc_method_type (c_parser
*parser
)
8107 switch (c_parser_peek_token (parser
)->type
)
8110 c_parser_consume_token (parser
);
8113 c_parser_consume_token (parser
);
8120 /* Parse an objc-method-definition.
8122 objc-method-definition:
8123 objc-method-type objc-method-decl ;[opt] compound-statement
8127 c_parser_objc_method_definition (c_parser
*parser
)
8129 bool is_class_method
= c_parser_objc_method_type (parser
);
8130 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8131 parser
->objc_pq_context
= true;
8132 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8134 if (decl
== error_mark_node
)
8135 return; /* Bail here. */
8137 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8139 c_parser_consume_token (parser
);
8140 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8141 "extra semicolon in method definition specified");
8144 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8146 c_parser_error (parser
, "expected %<{%>");
8150 parser
->objc_pq_context
= false;
8151 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8153 add_stmt (c_parser_compound_statement (parser
));
8154 objc_finish_method_definition (current_function_decl
);
8158 /* This code is executed when we find a method definition
8159 outside of an @implementation context (or invalid for other
8160 reasons). Parse the method (to keep going) but do not emit
8163 c_parser_compound_statement (parser
);
8167 /* Parse an objc-methodprotolist.
8169 objc-methodprotolist:
8171 objc-methodprotolist objc-methodproto
8172 objc-methodprotolist declaration
8173 objc-methodprotolist ;
8177 The declaration is a data definition, which may be missing
8178 declaration specifiers under the same rules and diagnostics as
8179 other data definitions outside functions, and the stray semicolon
8180 is diagnosed the same way as a stray semicolon outside a
8184 c_parser_objc_methodprotolist (c_parser
*parser
)
8188 /* The list is terminated by @end. */
8189 switch (c_parser_peek_token (parser
)->type
)
8192 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8193 "ISO C does not allow extra %<;%> outside of a function");
8194 c_parser_consume_token (parser
);
8198 c_parser_objc_methodproto (parser
);
8201 c_parser_pragma (parser
, pragma_external
);
8206 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8208 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8209 c_parser_objc_at_property_declaration (parser
);
8210 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8212 objc_set_method_opt (true);
8213 c_parser_consume_token (parser
);
8215 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8217 objc_set_method_opt (false);
8218 c_parser_consume_token (parser
);
8221 c_parser_declaration_or_fndef (parser
, false, false, true,
8222 false, true, NULL
, vNULL
);
8228 /* Parse an objc-methodproto.
8231 objc-method-type objc-method-decl ;
8235 c_parser_objc_methodproto (c_parser
*parser
)
8237 bool is_class_method
= c_parser_objc_method_type (parser
);
8238 tree decl
, attributes
= NULL_TREE
;
8240 /* Remember protocol qualifiers in prototypes. */
8241 parser
->objc_pq_context
= true;
8242 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8244 /* Forget protocol qualifiers now. */
8245 parser
->objc_pq_context
= false;
8247 /* Do not allow the presence of attributes to hide an erroneous
8248 method implementation in the interface section. */
8249 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8251 c_parser_error (parser
, "expected %<;%>");
8255 if (decl
!= error_mark_node
)
8256 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8258 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8261 /* If we are at a position that method attributes may be present, check that
8262 there are not any parsed already (a syntax error) and then collect any
8263 specified at the current location. Finally, if new attributes were present,
8264 check that the next token is legal ( ';' for decls and '{' for defs). */
8267 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8272 c_parser_error (parser
,
8273 "method attributes must be specified at the end only");
8274 *attributes
= NULL_TREE
;
8278 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8279 *attributes
= c_parser_attributes (parser
);
8281 /* If there were no attributes here, just report any earlier error. */
8282 if (*attributes
== NULL_TREE
|| bad
)
8285 /* If the attributes are followed by a ; or {, then just report any earlier
8287 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8288 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8291 /* We've got attributes, but not at the end. */
8292 c_parser_error (parser
,
8293 "expected %<;%> or %<{%> after method attribute definition");
8297 /* Parse an objc-method-decl.
8300 ( objc-type-name ) objc-selector
8302 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8303 objc-keyword-selector objc-optparmlist
8306 objc-keyword-selector:
8308 objc-keyword-selector objc-keyword-decl
8311 objc-selector : ( objc-type-name ) identifier
8312 objc-selector : identifier
8313 : ( objc-type-name ) identifier
8317 objc-optparms objc-optellipsis
8321 objc-opt-parms , parameter-declaration
8329 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8330 tree
*attributes
, tree
*expr
)
8332 tree type
= NULL_TREE
;
8334 tree parms
= NULL_TREE
;
8335 bool ellipsis
= false;
8336 bool attr_err
= false;
8338 *attributes
= NULL_TREE
;
8339 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8341 c_parser_consume_token (parser
);
8342 type
= c_parser_objc_type_name (parser
);
8343 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8345 sel
= c_parser_objc_selector (parser
);
8346 /* If there is no selector, or a colon follows, we have an
8347 objc-keyword-selector. If there is a selector, and a colon does
8348 not follow, that selector ends the objc-method-decl. */
8349 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8352 tree list
= NULL_TREE
;
8355 tree atype
= NULL_TREE
, id
, keyworddecl
;
8356 tree param_attr
= NULL_TREE
;
8357 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8359 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8361 c_parser_consume_token (parser
);
8362 atype
= c_parser_objc_type_name (parser
);
8363 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8366 /* New ObjC allows attributes on method parameters. */
8367 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8368 param_attr
= c_parser_attributes (parser
);
8369 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8371 c_parser_error (parser
, "expected identifier");
8372 return error_mark_node
;
8374 id
= c_parser_peek_token (parser
)->value
;
8375 c_parser_consume_token (parser
);
8376 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8377 list
= chainon (list
, keyworddecl
);
8378 tsel
= c_parser_objc_selector (parser
);
8379 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8383 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8385 /* Parse the optional parameter list. Optional Objective-C
8386 method parameters follow the C syntax, and may include '...'
8387 to denote a variable number of arguments. */
8388 parms
= make_node (TREE_LIST
);
8389 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8391 struct c_parm
*parm
;
8392 c_parser_consume_token (parser
);
8393 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8396 c_parser_consume_token (parser
);
8397 attr_err
|= c_parser_objc_maybe_method_attributes
8398 (parser
, attributes
) ;
8401 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8404 parms
= chainon (parms
,
8405 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8410 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8414 c_parser_error (parser
, "objective-c method declaration is expected");
8415 return error_mark_node
;
8419 return error_mark_node
;
8421 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8424 /* Parse an objc-type-name.
8427 objc-type-qualifiers[opt] type-name
8428 objc-type-qualifiers[opt]
8430 objc-type-qualifiers:
8432 objc-type-qualifiers objc-type-qualifier
8434 objc-type-qualifier: one of
8435 in out inout bycopy byref oneway
8439 c_parser_objc_type_name (c_parser
*parser
)
8441 tree quals
= NULL_TREE
;
8442 struct c_type_name
*type_name
= NULL
;
8443 tree type
= NULL_TREE
;
8446 c_token
*token
= c_parser_peek_token (parser
);
8447 if (token
->type
== CPP_KEYWORD
8448 && (token
->keyword
== RID_IN
8449 || token
->keyword
== RID_OUT
8450 || token
->keyword
== RID_INOUT
8451 || token
->keyword
== RID_BYCOPY
8452 || token
->keyword
== RID_BYREF
8453 || token
->keyword
== RID_ONEWAY
))
8455 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8456 c_parser_consume_token (parser
);
8461 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8462 type_name
= c_parser_type_name (parser
);
8464 type
= groktypename (type_name
, NULL
, NULL
);
8466 /* If the type is unknown, and error has already been produced and
8467 we need to recover from the error. In that case, use NULL_TREE
8468 for the type, as if no type had been specified; this will use the
8469 default type ('id') which is good for error recovery. */
8470 if (type
== error_mark_node
)
8473 return build_tree_list (quals
, type
);
8476 /* Parse objc-protocol-refs.
8483 c_parser_objc_protocol_refs (c_parser
*parser
)
8485 tree list
= NULL_TREE
;
8486 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8487 c_parser_consume_token (parser
);
8488 /* Any identifiers, including those declared as type names, are OK
8493 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8495 c_parser_error (parser
, "expected identifier");
8498 id
= c_parser_peek_token (parser
)->value
;
8499 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8500 c_parser_consume_token (parser
);
8501 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8502 c_parser_consume_token (parser
);
8506 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8510 /* Parse an objc-try-catch-finally-statement.
8512 objc-try-catch-finally-statement:
8513 @try compound-statement objc-catch-list[opt]
8514 @try compound-statement objc-catch-list[opt] @finally compound-statement
8517 @catch ( objc-catch-parameter-declaration ) compound-statement
8518 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8520 objc-catch-parameter-declaration:
8521 parameter-declaration
8524 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8526 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8527 for C++. Keep them in sync. */
8530 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8532 location_t location
;
8535 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8536 c_parser_consume_token (parser
);
8537 location
= c_parser_peek_token (parser
)->location
;
8538 objc_maybe_warn_exceptions (location
);
8539 stmt
= c_parser_compound_statement (parser
);
8540 objc_begin_try_stmt (location
, stmt
);
8542 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8544 struct c_parm
*parm
;
8545 tree parameter_declaration
= error_mark_node
;
8546 bool seen_open_paren
= false;
8548 c_parser_consume_token (parser
);
8549 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8550 seen_open_paren
= true;
8551 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8553 /* We have "@catch (...)" (where the '...' are literally
8554 what is in the code). Skip the '...'.
8555 parameter_declaration is set to NULL_TREE, and
8556 objc_being_catch_clauses() knows that that means
8558 c_parser_consume_token (parser
);
8559 parameter_declaration
= NULL_TREE
;
8563 /* We have "@catch (NSException *exception)" or something
8564 like that. Parse the parameter declaration. */
8565 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8567 parameter_declaration
= error_mark_node
;
8569 parameter_declaration
= grokparm (parm
, NULL
);
8571 if (seen_open_paren
)
8572 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8575 /* If there was no open parenthesis, we are recovering from
8576 an error, and we are trying to figure out what mistake
8577 the user has made. */
8579 /* If there is an immediate closing parenthesis, the user
8580 probably forgot the opening one (ie, they typed "@catch
8581 NSException *e)". Parse the closing parenthesis and keep
8583 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8584 c_parser_consume_token (parser
);
8586 /* If these is no immediate closing parenthesis, the user
8587 probably doesn't know that parenthesis are required at
8588 all (ie, they typed "@catch NSException *e"). So, just
8589 forget about the closing parenthesis and keep going. */
8591 objc_begin_catch_clause (parameter_declaration
);
8592 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8593 c_parser_compound_statement_nostart (parser
);
8594 objc_finish_catch_clause ();
8596 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8598 c_parser_consume_token (parser
);
8599 location
= c_parser_peek_token (parser
)->location
;
8600 stmt
= c_parser_compound_statement (parser
);
8601 objc_build_finally_clause (location
, stmt
);
8603 objc_finish_try_stmt ();
8606 /* Parse an objc-synchronized-statement.
8608 objc-synchronized-statement:
8609 @synchronized ( expression ) compound-statement
8613 c_parser_objc_synchronized_statement (c_parser
*parser
)
8617 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8618 c_parser_consume_token (parser
);
8619 loc
= c_parser_peek_token (parser
)->location
;
8620 objc_maybe_warn_exceptions (loc
);
8621 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8623 struct c_expr ce
= c_parser_expression (parser
);
8624 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8626 expr
= c_fully_fold (expr
, false, NULL
);
8627 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8630 expr
= error_mark_node
;
8631 stmt
= c_parser_compound_statement (parser
);
8632 objc_build_synchronized (loc
, expr
, stmt
);
8635 /* Parse an objc-selector; return NULL_TREE without an error if the
8636 next token is not an objc-selector.
8641 enum struct union if else while do for switch case default
8642 break continue return goto asm sizeof typeof __alignof
8643 unsigned long const short volatile signed restrict _Complex
8644 in out inout bycopy byref oneway int char float double void _Bool
8647 ??? Why this selection of keywords but not, for example, storage
8648 class specifiers? */
8651 c_parser_objc_selector (c_parser
*parser
)
8653 c_token
*token
= c_parser_peek_token (parser
);
8654 tree value
= token
->value
;
8655 if (token
->type
== CPP_NAME
)
8657 c_parser_consume_token (parser
);
8660 if (token
->type
!= CPP_KEYWORD
)
8662 switch (token
->keyword
)
8705 c_parser_consume_token (parser
);
8712 /* Parse an objc-selector-arg.
8716 objc-keywordname-list
8718 objc-keywordname-list:
8720 objc-keywordname-list objc-keywordname
8728 c_parser_objc_selector_arg (c_parser
*parser
)
8730 tree sel
= c_parser_objc_selector (parser
);
8731 tree list
= NULL_TREE
;
8732 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8736 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8738 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8739 sel
= c_parser_objc_selector (parser
);
8740 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8746 /* Parse an objc-receiver.
8755 c_parser_objc_receiver (c_parser
*parser
)
8757 location_t loc
= c_parser_peek_token (parser
)->location
;
8759 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8760 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8761 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8763 tree id
= c_parser_peek_token (parser
)->value
;
8764 c_parser_consume_token (parser
);
8765 return objc_get_class_reference (id
);
8767 struct c_expr ce
= c_parser_expression (parser
);
8768 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8769 return c_fully_fold (ce
.value
, false, NULL
);
8772 /* Parse objc-message-args.
8776 objc-keywordarg-list
8778 objc-keywordarg-list:
8780 objc-keywordarg-list objc-keywordarg
8783 objc-selector : objc-keywordexpr
8788 c_parser_objc_message_args (c_parser
*parser
)
8790 tree sel
= c_parser_objc_selector (parser
);
8791 tree list
= NULL_TREE
;
8792 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8797 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8798 return error_mark_node
;
8799 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8800 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8801 sel
= c_parser_objc_selector (parser
);
8802 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8808 /* Parse an objc-keywordexpr.
8815 c_parser_objc_keywordexpr (c_parser
*parser
)
8818 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8820 if (vec_safe_length (expr_list
) == 1)
8822 /* Just return the expression, remove a level of
8824 ret
= (*expr_list
)[0];
8828 /* We have a comma expression, we will collapse later. */
8829 ret
= build_tree_list_vec (expr_list
);
8831 release_tree_vector (expr_list
);
8835 /* A check, needed in several places, that ObjC interface, implementation or
8836 method definitions are not prefixed by incorrect items. */
8838 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8839 struct c_declspecs
*specs
)
8841 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8842 || specs
->typespec_kind
!= ctsk_none
)
8844 c_parser_error (parser
,
8845 "no type or storage class may be specified here,");
8846 c_parser_skip_to_end_of_block_or_statement (parser
);
8852 /* Parse an Objective-C @property declaration. The syntax is:
8854 objc-property-declaration:
8855 '@property' objc-property-attributes[opt] struct-declaration ;
8857 objc-property-attributes:
8858 '(' objc-property-attribute-list ')'
8860 objc-property-attribute-list:
8861 objc-property-attribute
8862 objc-property-attribute-list, objc-property-attribute
8864 objc-property-attribute
8865 'getter' = identifier
8866 'setter' = identifier
8875 @property NSString *name;
8876 @property (readonly) id object;
8877 @property (retain, nonatomic, getter=getTheName) id name;
8878 @property int a, b, c;
8880 PS: This function is identical to cp_parser_objc_at_propery_declaration
8881 for C++. Keep them in sync. */
8883 c_parser_objc_at_property_declaration (c_parser
*parser
)
8885 /* The following variables hold the attributes of the properties as
8886 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8887 seen. When we see an attribute, we set them to 'true' (if they
8888 are boolean properties) or to the identifier (if they have an
8889 argument, ie, for getter and setter). Note that here we only
8890 parse the list of attributes, check the syntax and accumulate the
8891 attributes that we find. objc_add_property_declaration() will
8892 then process the information. */
8893 bool property_assign
= false;
8894 bool property_copy
= false;
8895 tree property_getter_ident
= NULL_TREE
;
8896 bool property_nonatomic
= false;
8897 bool property_readonly
= false;
8898 bool property_readwrite
= false;
8899 bool property_retain
= false;
8900 tree property_setter_ident
= NULL_TREE
;
8902 /* 'properties' is the list of properties that we read. Usually a
8903 single one, but maybe more (eg, in "@property int a, b, c;" there
8908 loc
= c_parser_peek_token (parser
)->location
;
8909 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8911 c_parser_consume_token (parser
); /* Eat '@property'. */
8913 /* Parse the optional attribute list... */
8914 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8917 c_parser_consume_token (parser
);
8919 /* Property attribute keywords are valid now. */
8920 parser
->objc_property_attr_context
= true;
8924 bool syntax_error
= false;
8925 c_token
*token
= c_parser_peek_token (parser
);
8928 if (token
->type
!= CPP_KEYWORD
)
8930 if (token
->type
== CPP_CLOSE_PAREN
)
8931 c_parser_error (parser
, "expected identifier");
8934 c_parser_consume_token (parser
);
8935 c_parser_error (parser
, "unknown property attribute");
8939 keyword
= token
->keyword
;
8940 c_parser_consume_token (parser
);
8943 case RID_ASSIGN
: property_assign
= true; break;
8944 case RID_COPY
: property_copy
= true; break;
8945 case RID_NONATOMIC
: property_nonatomic
= true; break;
8946 case RID_READONLY
: property_readonly
= true; break;
8947 case RID_READWRITE
: property_readwrite
= true; break;
8948 case RID_RETAIN
: property_retain
= true; break;
8952 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8954 if (keyword
== RID_GETTER
)
8955 c_parser_error (parser
,
8956 "missing %<=%> (after %<getter%> attribute)");
8958 c_parser_error (parser
,
8959 "missing %<=%> (after %<setter%> attribute)");
8960 syntax_error
= true;
8963 c_parser_consume_token (parser
); /* eat the = */
8964 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8966 c_parser_error (parser
, "expected identifier");
8967 syntax_error
= true;
8970 if (keyword
== RID_SETTER
)
8972 if (property_setter_ident
!= NULL_TREE
)
8973 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8975 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8976 c_parser_consume_token (parser
);
8977 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8978 c_parser_error (parser
, "setter name must terminate with %<:%>");
8980 c_parser_consume_token (parser
);
8984 if (property_getter_ident
!= NULL_TREE
)
8985 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8987 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8988 c_parser_consume_token (parser
);
8992 c_parser_error (parser
, "unknown property attribute");
8993 syntax_error
= true;
9000 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9001 c_parser_consume_token (parser
);
9005 parser
->objc_property_attr_context
= false;
9006 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9008 /* ... and the property declaration(s). */
9009 properties
= c_parser_struct_declaration (parser
);
9011 if (properties
== error_mark_node
)
9013 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9014 parser
->error
= false;
9018 if (properties
== NULL_TREE
)
9019 c_parser_error (parser
, "expected identifier");
9022 /* Comma-separated properties are chained together in
9023 reverse order; add them one by one. */
9024 properties
= nreverse (properties
);
9026 for (; properties
; properties
= TREE_CHAIN (properties
))
9027 objc_add_property_declaration (loc
, copy_node (properties
),
9028 property_readonly
, property_readwrite
,
9029 property_assign
, property_retain
,
9030 property_copy
, property_nonatomic
,
9031 property_getter_ident
, property_setter_ident
);
9034 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9035 parser
->error
= false;
9038 /* Parse an Objective-C @synthesize declaration. The syntax is:
9040 objc-synthesize-declaration:
9041 @synthesize objc-synthesize-identifier-list ;
9043 objc-synthesize-identifier-list:
9044 objc-synthesize-identifier
9045 objc-synthesize-identifier-list, objc-synthesize-identifier
9047 objc-synthesize-identifier
9049 identifier = identifier
9052 @synthesize MyProperty;
9053 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9055 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9056 for C++. Keep them in sync.
9059 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9061 tree list
= NULL_TREE
;
9063 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9064 loc
= c_parser_peek_token (parser
)->location
;
9066 c_parser_consume_token (parser
);
9069 tree property
, ivar
;
9070 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9072 c_parser_error (parser
, "expected identifier");
9073 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9074 /* Once we find the semicolon, we can resume normal parsing.
9075 We have to reset parser->error manually because
9076 c_parser_skip_until_found() won't reset it for us if the
9077 next token is precisely a semicolon. */
9078 parser
->error
= false;
9081 property
= c_parser_peek_token (parser
)->value
;
9082 c_parser_consume_token (parser
);
9083 if (c_parser_next_token_is (parser
, CPP_EQ
))
9085 c_parser_consume_token (parser
);
9086 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9088 c_parser_error (parser
, "expected identifier");
9089 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9090 parser
->error
= false;
9093 ivar
= c_parser_peek_token (parser
)->value
;
9094 c_parser_consume_token (parser
);
9098 list
= chainon (list
, build_tree_list (ivar
, property
));
9099 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9100 c_parser_consume_token (parser
);
9104 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9105 objc_add_synthesize_declaration (loc
, list
);
9108 /* Parse an Objective-C @dynamic declaration. The syntax is:
9110 objc-dynamic-declaration:
9111 @dynamic identifier-list ;
9114 @dynamic MyProperty;
9115 @dynamic MyProperty, AnotherProperty;
9117 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9118 for C++. Keep them in sync.
9121 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9123 tree list
= NULL_TREE
;
9125 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9126 loc
= c_parser_peek_token (parser
)->location
;
9128 c_parser_consume_token (parser
);
9132 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9134 c_parser_error (parser
, "expected identifier");
9135 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9136 parser
->error
= false;
9139 property
= c_parser_peek_token (parser
)->value
;
9140 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9141 c_parser_consume_token (parser
);
9142 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9143 c_parser_consume_token (parser
);
9147 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9148 objc_add_dynamic_declaration (loc
, list
);
9152 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9153 should be considered, statements. ALLOW_STMT is true if we're within
9154 the context of a function and such pragmas are to be allowed. Returns
9155 true if we actually parsed such a pragma. */
9158 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9162 id
= c_parser_peek_token (parser
)->pragma_kind
;
9163 gcc_assert (id
!= PRAGMA_NONE
);
9167 case PRAGMA_OMP_BARRIER
:
9168 if (context
!= pragma_compound
)
9170 if (context
== pragma_stmt
)
9171 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9172 "used in compound statements");
9175 c_parser_omp_barrier (parser
);
9178 case PRAGMA_OMP_FLUSH
:
9179 if (context
!= pragma_compound
)
9181 if (context
== pragma_stmt
)
9182 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9183 "used in compound statements");
9186 c_parser_omp_flush (parser
);
9189 case PRAGMA_OMP_TASKWAIT
:
9190 if (context
!= pragma_compound
)
9192 if (context
== pragma_stmt
)
9193 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9194 "used in compound statements");
9197 c_parser_omp_taskwait (parser
);
9200 case PRAGMA_OMP_TASKYIELD
:
9201 if (context
!= pragma_compound
)
9203 if (context
== pragma_stmt
)
9204 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9205 "used in compound statements");
9208 c_parser_omp_taskyield (parser
);
9211 case PRAGMA_OMP_CANCEL
:
9212 if (context
!= pragma_compound
)
9214 if (context
== pragma_stmt
)
9215 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9216 "used in compound statements");
9219 c_parser_omp_cancel (parser
);
9222 case PRAGMA_OMP_CANCELLATION_POINT
:
9223 if (context
!= pragma_compound
)
9225 if (context
== pragma_stmt
)
9226 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9227 "only be used in compound statements");
9230 c_parser_omp_cancellation_point (parser
);
9233 case PRAGMA_OMP_THREADPRIVATE
:
9234 c_parser_omp_threadprivate (parser
);
9237 case PRAGMA_OMP_TARGET
:
9238 return c_parser_omp_target (parser
, context
);
9240 case PRAGMA_OMP_END_DECLARE_TARGET
:
9241 c_parser_omp_end_declare_target (parser
);
9244 case PRAGMA_OMP_SECTION
:
9245 error_at (c_parser_peek_token (parser
)->location
,
9246 "%<#pragma omp section%> may only be used in "
9247 "%<#pragma omp sections%> construct");
9248 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9251 case PRAGMA_OMP_DECLARE_REDUCTION
:
9252 c_parser_omp_declare (parser
, context
);
9255 c_parser_consume_pragma (parser
);
9256 c_parser_skip_to_pragma_eol (parser
);
9257 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9258 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9259 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9261 c_parser_error (parser
, "for, while or do statement expected");
9264 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9265 c_parser_for_statement (parser
, true);
9266 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9267 c_parser_while_statement (parser
, true);
9269 c_parser_do_statement (parser
, true);
9272 case PRAGMA_GCC_PCH_PREPROCESS
:
9273 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9274 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9278 if (id
< PRAGMA_FIRST_EXTERNAL
)
9280 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9283 c_parser_error (parser
, "expected declaration specifiers");
9284 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9287 c_parser_omp_construct (parser
);
9293 c_parser_consume_pragma (parser
);
9294 c_invoke_pragma_handler (id
);
9296 /* Skip to EOL, but suppress any error message. Those will have been
9297 generated by the handler routine through calling error, as opposed
9298 to calling c_parser_error. */
9299 parser
->error
= true;
9300 c_parser_skip_to_pragma_eol (parser
);
9305 /* The interface the pragma parsers have to the lexer. */
9308 pragma_lex (tree
*value
)
9310 c_token
*tok
= c_parser_peek_token (the_parser
);
9311 enum cpp_ttype ret
= tok
->type
;
9313 *value
= tok
->value
;
9314 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9318 if (ret
== CPP_KEYWORD
)
9320 c_parser_consume_token (the_parser
);
9327 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9331 c_parser_consume_pragma (parser
);
9332 if (c_parser_next_token_is (parser
, CPP_STRING
))
9334 name
= c_parser_peek_token (parser
)->value
;
9335 c_parser_consume_token (parser
);
9338 c_parser_error (parser
, "expected string literal");
9339 c_parser_skip_to_pragma_eol (parser
);
9342 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9345 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9347 /* Returns name of the next clause.
9348 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9349 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9350 returned and the token is consumed. */
9352 static pragma_omp_clause
9353 c_parser_omp_clause_name (c_parser
*parser
)
9355 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9357 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9358 result
= PRAGMA_OMP_CLAUSE_IF
;
9359 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9360 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9361 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9362 result
= PRAGMA_OMP_CLAUSE_FOR
;
9363 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9365 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9370 if (!strcmp ("aligned", p
))
9371 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9374 if (!strcmp ("collapse", p
))
9375 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9376 else if (!strcmp ("copyin", p
))
9377 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9378 else if (!strcmp ("copyprivate", p
))
9379 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9382 if (!strcmp ("depend", p
))
9383 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9384 else if (!strcmp ("device", p
))
9385 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9386 else if (!strcmp ("dist_schedule", p
))
9387 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9390 if (!strcmp ("final", p
))
9391 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9392 else if (!strcmp ("firstprivate", p
))
9393 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9394 else if (!strcmp ("from", p
))
9395 result
= PRAGMA_OMP_CLAUSE_FROM
;
9398 if (!strcmp ("inbranch", p
))
9399 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9402 if (!strcmp ("lastprivate", p
))
9403 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9404 else if (!strcmp ("linear", p
))
9405 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9408 if (!strcmp ("map", p
))
9409 result
= PRAGMA_OMP_CLAUSE_MAP
;
9410 else if (!strcmp ("mergeable", p
))
9411 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9414 if (!strcmp ("notinbranch", p
))
9415 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9416 else if (!strcmp ("nowait", p
))
9417 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9418 else if (!strcmp ("num_teams", p
))
9419 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9420 else if (!strcmp ("num_threads", p
))
9421 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9424 if (!strcmp ("ordered", p
))
9425 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9428 if (!strcmp ("parallel", p
))
9429 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9430 else if (!strcmp ("private", p
))
9431 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9432 else if (!strcmp ("proc_bind", p
))
9433 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9436 if (!strcmp ("reduction", p
))
9437 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9440 if (!strcmp ("safelen", p
))
9441 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9442 else if (!strcmp ("schedule", p
))
9443 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9444 else if (!strcmp ("sections", p
))
9445 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9446 else if (!strcmp ("shared", p
))
9447 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9448 else if (!strcmp ("simdlen", p
))
9449 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9452 if (!strcmp ("taskgroup", p
))
9453 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9454 else if (!strcmp ("thread_limit", p
))
9455 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9456 else if (!strcmp ("to", p
))
9457 result
= PRAGMA_OMP_CLAUSE_TO
;
9460 if (!strcmp ("uniform", p
))
9461 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9462 else if (!strcmp ("untied", p
))
9463 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9468 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9469 c_parser_consume_token (parser
);
9474 /* Validate that a clause of the given type does not already exist. */
9477 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9482 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9483 if (OMP_CLAUSE_CODE (c
) == code
)
9485 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9486 error_at (loc
, "too many %qs clauses", name
);
9494 variable-list , identifier
9496 If KIND is nonzero, create the appropriate node and install the
9497 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9498 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9500 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9501 return the list created. */
9504 c_parser_omp_variable_list (c_parser
*parser
,
9505 location_t clause_loc
,
9506 enum omp_clause_code kind
, tree list
)
9508 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9509 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9510 c_parser_error (parser
, "expected identifier");
9512 while (c_parser_next_token_is (parser
, CPP_NAME
)
9513 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9515 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9519 undeclared_variable (c_parser_peek_token (parser
)->location
,
9520 c_parser_peek_token (parser
)->value
);
9521 t
= error_mark_node
;
9524 c_parser_consume_token (parser
);
9526 if (t
== error_mark_node
)
9532 case OMP_CLAUSE_MAP
:
9533 case OMP_CLAUSE_FROM
:
9535 case OMP_CLAUSE_DEPEND
:
9536 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9538 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9540 c_parser_consume_token (parser
);
9541 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9542 low_bound
= c_parser_expression (parser
).value
;
9543 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9544 length
= integer_one_node
;
9548 if (!c_parser_require (parser
, CPP_COLON
,
9551 t
= error_mark_node
;
9554 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9555 length
= c_parser_expression (parser
).value
;
9557 /* Look for the closing `]'. */
9558 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9561 t
= error_mark_node
;
9564 t
= tree_cons (low_bound
, length
, t
);
9571 if (t
!= error_mark_node
)
9573 tree u
= build_omp_clause (clause_loc
, kind
);
9574 OMP_CLAUSE_DECL (u
) = t
;
9575 OMP_CLAUSE_CHAIN (u
) = list
;
9580 list
= tree_cons (t
, NULL_TREE
, list
);
9582 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9585 c_parser_consume_token (parser
);
9591 /* Similarly, but expect leading and trailing parenthesis. This is a very
9592 common case for omp clauses. */
9595 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9598 /* The clauses location. */
9599 location_t loc
= c_parser_peek_token (parser
)->location
;
9601 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9603 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9604 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9610 collapse ( constant-expression ) */
9613 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9615 tree c
, num
= error_mark_node
;
9619 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9621 loc
= c_parser_peek_token (parser
)->location
;
9622 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9624 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9627 if (num
== error_mark_node
)
9629 mark_exp_read (num
);
9630 num
= c_fully_fold (num
, false, NULL
);
9631 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9632 || !host_integerp (num
, 0)
9633 || (n
= tree_low_cst (num
, 0)) <= 0
9637 "collapse argument needs positive constant integer expression");
9640 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9641 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9642 OMP_CLAUSE_CHAIN (c
) = list
;
9647 copyin ( variable-list ) */
9650 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9652 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9656 copyprivate ( variable-list ) */
9659 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9661 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9665 default ( shared | none ) */
9668 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9670 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9671 location_t loc
= c_parser_peek_token (parser
)->location
;
9674 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9676 if (c_parser_next_token_is (parser
, CPP_NAME
))
9678 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9683 if (strcmp ("none", p
) != 0)
9685 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9689 if (strcmp ("shared", p
) != 0)
9691 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9698 c_parser_consume_token (parser
);
9703 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9705 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9707 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9710 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9711 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9712 OMP_CLAUSE_CHAIN (c
) = list
;
9713 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9719 firstprivate ( variable-list ) */
9722 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9724 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9728 final ( expression ) */
9731 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9733 location_t loc
= c_parser_peek_token (parser
)->location
;
9734 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9736 tree t
= c_parser_paren_condition (parser
);
9739 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9741 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9742 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9743 OMP_CLAUSE_CHAIN (c
) = list
;
9747 c_parser_error (parser
, "expected %<(%>");
9753 if ( expression ) */
9756 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9758 location_t loc
= c_parser_peek_token (parser
)->location
;
9759 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9761 tree t
= c_parser_paren_condition (parser
);
9764 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9766 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9767 OMP_CLAUSE_IF_EXPR (c
) = t
;
9768 OMP_CLAUSE_CHAIN (c
) = list
;
9772 c_parser_error (parser
, "expected %<(%>");
9778 lastprivate ( variable-list ) */
9781 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9783 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9790 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9794 /* FIXME: Should we allow duplicates? */
9795 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9797 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9798 OMP_CLAUSE_MERGEABLE
);
9799 OMP_CLAUSE_CHAIN (c
) = list
;
9808 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9811 location_t loc
= c_parser_peek_token (parser
)->location
;
9813 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9815 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9816 OMP_CLAUSE_CHAIN (c
) = list
;
9821 num_threads ( expression ) */
9824 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9826 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9827 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9829 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9830 tree c
, t
= c_parser_expression (parser
).value
;
9832 t
= c_fully_fold (t
, false, NULL
);
9834 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9836 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9838 c_parser_error (parser
, "expected integer expression");
9842 /* Attempt to statically determine when the number isn't positive. */
9843 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9844 build_int_cst (TREE_TYPE (t
), 0));
9845 if (CAN_HAVE_LOCATION_P (c
))
9846 SET_EXPR_LOCATION (c
, expr_loc
);
9847 if (c
== boolean_true_node
)
9849 warning_at (expr_loc
, 0,
9850 "%<num_threads%> value must be positive");
9851 t
= integer_one_node
;
9854 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9856 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9857 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9858 OMP_CLAUSE_CHAIN (c
) = list
;
9869 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9873 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9875 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9876 OMP_CLAUSE_ORDERED
);
9877 OMP_CLAUSE_CHAIN (c
) = list
;
9883 private ( variable-list ) */
9886 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9888 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9892 reduction ( reduction-operator : variable-list )
9895 One of: + * - & ^ | && ||
9900 One of: + * - & ^ | && || max min
9905 One of: + * - & ^ | && ||
9909 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9911 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9912 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9914 enum tree_code code
= ERROR_MARK
;
9915 tree reduc_id
= NULL_TREE
;
9917 switch (c_parser_peek_token (parser
)->type
)
9929 code
= BIT_AND_EXPR
;
9932 code
= BIT_XOR_EXPR
;
9935 code
= BIT_IOR_EXPR
;
9938 code
= TRUTH_ANDIF_EXPR
;
9941 code
= TRUTH_ORIF_EXPR
;
9946 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9947 if (strcmp (p
, "min") == 0)
9952 if (strcmp (p
, "max") == 0)
9957 reduc_id
= c_parser_peek_token (parser
)->value
;
9961 c_parser_error (parser
,
9962 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9963 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9964 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9967 c_parser_consume_token (parser
);
9968 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
9969 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9973 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9974 OMP_CLAUSE_REDUCTION
, list
);
9975 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9977 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
9978 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9979 if (code
== ERROR_MARK
9980 || !(INTEGRAL_TYPE_P (type
)
9981 || TREE_CODE (type
) == REAL_TYPE
9982 || TREE_CODE (type
) == COMPLEX_TYPE
))
9983 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
9984 = c_omp_reduction_lookup (reduc_id
,
9985 TYPE_MAIN_VARIANT (type
));
9990 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9996 schedule ( schedule-kind )
9997 schedule ( schedule-kind , expression )
10000 static | dynamic | guided | runtime | auto
10004 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10007 location_t loc
= c_parser_peek_token (parser
)->location
;
10009 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10012 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10014 if (c_parser_next_token_is (parser
, CPP_NAME
))
10016 tree kind
= c_parser_peek_token (parser
)->value
;
10017 const char *p
= IDENTIFIER_POINTER (kind
);
10022 if (strcmp ("dynamic", p
) != 0)
10024 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10028 if (strcmp ("guided", p
) != 0)
10030 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10034 if (strcmp ("runtime", p
) != 0)
10036 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10043 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10044 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10045 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10046 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10050 c_parser_consume_token (parser
);
10051 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10054 c_parser_consume_token (parser
);
10056 here
= c_parser_peek_token (parser
)->location
;
10057 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10059 t
= c_fully_fold (t
, false, NULL
);
10061 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10062 error_at (here
, "schedule %<runtime%> does not take "
10063 "a %<chunk_size%> parameter");
10064 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10066 "schedule %<auto%> does not take "
10067 "a %<chunk_size%> parameter");
10068 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10069 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10071 c_parser_error (parser
, "expected integer expression");
10073 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10076 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10077 "expected %<,%> or %<)%>");
10079 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10080 OMP_CLAUSE_CHAIN (c
) = list
;
10084 c_parser_error (parser
, "invalid schedule kind");
10085 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10090 shared ( variable-list ) */
10093 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10095 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10102 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10106 /* FIXME: Should we allow duplicates? */
10107 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10109 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10110 OMP_CLAUSE_UNTIED
);
10111 OMP_CLAUSE_CHAIN (c
) = list
;
10121 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10122 enum omp_clause_code code
, tree list
)
10124 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10126 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10127 OMP_CLAUSE_CHAIN (c
) = list
;
10139 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10140 enum omp_clause_code code
, tree list
)
10142 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10143 OMP_CLAUSE_CHAIN (c
) = list
;
10149 num_teams ( expression ) */
10152 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10154 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10155 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10157 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10158 tree c
, t
= c_parser_expression (parser
).value
;
10160 t
= c_fully_fold (t
, false, NULL
);
10162 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10164 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10166 c_parser_error (parser
, "expected integer expression");
10170 /* Attempt to statically determine when the number isn't positive. */
10171 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10172 build_int_cst (TREE_TYPE (t
), 0));
10173 if (CAN_HAVE_LOCATION_P (c
))
10174 SET_EXPR_LOCATION (c
, expr_loc
);
10175 if (c
== boolean_true_node
)
10177 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10178 t
= integer_one_node
;
10181 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10183 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10184 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10185 OMP_CLAUSE_CHAIN (c
) = list
;
10193 thread_limit ( expression ) */
10196 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10198 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10199 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10201 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10202 tree c
, t
= c_parser_expression (parser
).value
;
10204 t
= c_fully_fold (t
, false, NULL
);
10206 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10208 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10210 c_parser_error (parser
, "expected integer expression");
10214 /* Attempt to statically determine when the number isn't positive. */
10215 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10216 build_int_cst (TREE_TYPE (t
), 0));
10217 if (CAN_HAVE_LOCATION_P (c
))
10218 SET_EXPR_LOCATION (c
, expr_loc
);
10219 if (c
== boolean_true_node
)
10221 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10222 t
= integer_one_node
;
10225 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10228 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10229 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10230 OMP_CLAUSE_CHAIN (c
) = list
;
10238 aligned ( variable-list )
10239 aligned ( variable-list : constant-expression ) */
10242 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10244 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10247 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10250 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10251 OMP_CLAUSE_ALIGNED
, list
);
10253 if (c_parser_next_token_is (parser
, CPP_COLON
))
10255 c_parser_consume_token (parser
);
10256 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10257 mark_exp_read (alignment
);
10258 alignment
= c_fully_fold (alignment
, false, NULL
);
10259 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10260 && TREE_CODE (alignment
) != INTEGER_CST
10261 && tree_int_cst_sgn (alignment
) != 1)
10263 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10264 "be positive constant integer expression");
10265 alignment
= NULL_TREE
;
10268 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10269 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10272 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10277 linear ( variable-list )
10278 linear ( variable-list : expression ) */
10281 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
10283 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10286 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10289 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10290 OMP_CLAUSE_LINEAR
, list
);
10292 if (c_parser_next_token_is (parser
, CPP_COLON
))
10294 c_parser_consume_token (parser
);
10295 step
= c_parser_expression (parser
).value
;
10296 mark_exp_read (step
);
10297 step
= c_fully_fold (step
, false, NULL
);
10298 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10300 error_at (clause_loc
, "%<linear%> clause step expression must "
10302 step
= integer_one_node
;
10307 step
= integer_one_node
;
10309 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10311 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10314 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10319 safelen ( constant-expression ) */
10322 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10324 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10327 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10330 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10332 t
= c_fully_fold (t
, false, NULL
);
10333 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10334 && TREE_CODE (t
) != INTEGER_CST
10335 && tree_int_cst_sgn (t
) != 1)
10337 error_at (clause_loc
, "%<safelen%> clause expression must "
10338 "be positive constant integer expression");
10342 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10343 if (t
== NULL_TREE
|| t
== error_mark_node
)
10346 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10348 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10349 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10350 OMP_CLAUSE_CHAIN (c
) = list
;
10355 simdlen ( constant-expression ) */
10358 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10360 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10363 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10366 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10368 t
= c_fully_fold (t
, false, NULL
);
10369 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10370 && TREE_CODE (t
) != INTEGER_CST
10371 && tree_int_cst_sgn (t
) != 1)
10373 error_at (clause_loc
, "%<simdlen%> clause expression must "
10374 "be positive constant integer expression");
10378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10379 if (t
== NULL_TREE
|| t
== error_mark_node
)
10382 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10384 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10385 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10386 OMP_CLAUSE_CHAIN (c
) = list
;
10391 depend ( depend-kind: variable-list )
10394 in | out | inout */
10397 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10399 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10400 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10403 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10406 if (c_parser_next_token_is (parser
, CPP_NAME
))
10408 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10409 if (strcmp ("in", p
) == 0)
10410 kind
= OMP_CLAUSE_DEPEND_IN
;
10411 else if (strcmp ("inout", p
) == 0)
10412 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10413 else if (strcmp ("out", p
) == 0)
10414 kind
= OMP_CLAUSE_DEPEND_OUT
;
10421 c_parser_consume_token (parser
);
10422 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10425 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10426 OMP_CLAUSE_DEPEND
, list
);
10428 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10429 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10431 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10435 c_parser_error (parser
, "invalid depend kind");
10437 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10442 map ( map-kind: variable-list )
10443 map ( variable-list )
10446 alloc | to | from | tofrom */
10449 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10451 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10452 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10455 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10458 if (c_parser_next_token_is (parser
, CPP_NAME
)
10459 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10461 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10462 if (strcmp ("alloc", p
) == 0)
10463 kind
= OMP_CLAUSE_MAP_ALLOC
;
10464 else if (strcmp ("to", p
) == 0)
10465 kind
= OMP_CLAUSE_MAP_TO
;
10466 else if (strcmp ("from", p
) == 0)
10467 kind
= OMP_CLAUSE_MAP_FROM
;
10468 else if (strcmp ("tofrom", p
) == 0)
10469 kind
= OMP_CLAUSE_MAP_TOFROM
;
10472 c_parser_error (parser
, "invalid map kind");
10473 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10477 c_parser_consume_token (parser
);
10478 c_parser_consume_token (parser
);
10481 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10483 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10484 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10486 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10491 device ( expression ) */
10494 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10496 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10497 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10499 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10501 t
= c_fully_fold (t
, false, NULL
);
10503 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10505 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10507 c_parser_error (parser
, "expected integer expression");
10511 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10513 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10514 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10515 OMP_CLAUSE_CHAIN (c
) = list
;
10523 dist_schedule ( static )
10524 dist_schedule ( static , expression ) */
10527 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10529 tree c
, t
= NULL_TREE
;
10530 location_t loc
= c_parser_peek_token (parser
)->location
;
10532 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10535 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10537 c_parser_error (parser
, "invalid dist_schedule kind");
10538 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10543 c_parser_consume_token (parser
);
10544 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10546 c_parser_consume_token (parser
);
10548 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10550 t
= c_fully_fold (t
, false, NULL
);
10551 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10554 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10555 "expected %<,%> or %<)%>");
10557 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10558 if (t
== error_mark_node
)
10561 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10562 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10563 OMP_CLAUSE_CHAIN (c
) = list
;
10568 proc_bind ( proc-bind-kind )
10571 master | close | spread */
10574 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10576 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10577 enum omp_clause_proc_bind_kind kind
;
10580 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10583 if (c_parser_next_token_is (parser
, CPP_NAME
))
10585 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10586 if (strcmp ("master", p
) == 0)
10587 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10588 else if (strcmp ("close", p
) == 0)
10589 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10590 else if (strcmp ("spread", p
) == 0)
10591 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10598 c_parser_consume_token (parser
);
10599 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10600 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10601 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10602 OMP_CLAUSE_CHAIN (c
) = list
;
10606 c_parser_error (parser
, "invalid proc_bind kind");
10607 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10612 to ( variable-list ) */
10615 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10617 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10621 from ( variable-list ) */
10624 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10626 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10630 uniform ( variable-list ) */
10633 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10635 /* The clauses location. */
10636 location_t loc
= c_parser_peek_token (parser
)->location
;
10638 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10640 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10642 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10647 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10648 is a bitmask in MASK. Return the list of clauses found; the result
10649 of clause default goes in *pdefault. */
10652 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10653 const char *where
, bool finish_p
= true)
10655 tree clauses
= NULL
;
10658 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10661 pragma_omp_clause c_kind
;
10662 const char *c_name
;
10663 tree prev
= clauses
;
10665 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10666 c_parser_consume_token (parser
);
10668 here
= c_parser_peek_token (parser
)->location
;
10669 c_kind
= c_parser_omp_clause_name (parser
);
10673 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10674 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10675 c_name
= "collapse";
10677 case PRAGMA_OMP_CLAUSE_COPYIN
:
10678 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10681 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10682 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10683 c_name
= "copyprivate";
10685 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10686 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10687 c_name
= "default";
10689 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
10690 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
10691 c_name
= "firstprivate";
10693 case PRAGMA_OMP_CLAUSE_FINAL
:
10694 clauses
= c_parser_omp_clause_final (parser
, clauses
);
10697 case PRAGMA_OMP_CLAUSE_IF
:
10698 clauses
= c_parser_omp_clause_if (parser
, clauses
);
10701 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
10702 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
10703 c_name
= "lastprivate";
10705 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
10706 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
10707 c_name
= "mergeable";
10709 case PRAGMA_OMP_CLAUSE_NOWAIT
:
10710 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
10713 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
10714 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
10715 c_name
= "num_threads";
10717 case PRAGMA_OMP_CLAUSE_ORDERED
:
10718 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
10719 c_name
= "ordered";
10721 case PRAGMA_OMP_CLAUSE_PRIVATE
:
10722 clauses
= c_parser_omp_clause_private (parser
, clauses
);
10723 c_name
= "private";
10725 case PRAGMA_OMP_CLAUSE_REDUCTION
:
10726 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
10727 c_name
= "reduction";
10729 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10730 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10731 c_name
= "schedule";
10733 case PRAGMA_OMP_CLAUSE_SHARED
:
10734 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10737 case PRAGMA_OMP_CLAUSE_UNTIED
:
10738 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
10741 case PRAGMA_OMP_CLAUSE_INBRANCH
:
10742 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
10744 c_name
= "inbranch";
10746 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
10747 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
10749 c_name
= "notinbranch";
10751 case PRAGMA_OMP_CLAUSE_PARALLEL
:
10753 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
10755 c_name
= "parallel";
10759 error_at (here
, "%qs must be the first clause of %qs",
10764 case PRAGMA_OMP_CLAUSE_FOR
:
10766 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
10770 goto clause_not_first
;
10772 case PRAGMA_OMP_CLAUSE_SECTIONS
:
10774 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
10776 c_name
= "sections";
10778 goto clause_not_first
;
10780 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
10782 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
10784 c_name
= "taskgroup";
10786 goto clause_not_first
;
10788 case PRAGMA_OMP_CLAUSE_TO
:
10789 clauses
= c_parser_omp_clause_to (parser
, clauses
);
10792 case PRAGMA_OMP_CLAUSE_FROM
:
10793 clauses
= c_parser_omp_clause_from (parser
, clauses
);
10796 case PRAGMA_OMP_CLAUSE_UNIFORM
:
10797 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
10798 c_name
= "uniform";
10800 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
10801 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
10802 c_name
= "num_teams";
10804 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
10805 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
10806 c_name
= "thread_limit";
10808 case PRAGMA_OMP_CLAUSE_ALIGNED
:
10809 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
10810 c_name
= "aligned";
10812 case PRAGMA_OMP_CLAUSE_LINEAR
:
10813 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
10816 case PRAGMA_OMP_CLAUSE_DEPEND
:
10817 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
10820 case PRAGMA_OMP_CLAUSE_MAP
:
10821 clauses
= c_parser_omp_clause_map (parser
, clauses
);
10824 case PRAGMA_OMP_CLAUSE_DEVICE
:
10825 clauses
= c_parser_omp_clause_device (parser
, clauses
);
10828 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
10829 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
10830 c_name
= "dist_schedule";
10832 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
10833 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
10834 c_name
= "proc_bind";
10836 case PRAGMA_OMP_CLAUSE_SAFELEN
:
10837 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
10838 c_name
= "safelen";
10840 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
10841 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
10842 c_name
= "simdlen";
10845 c_parser_error (parser
, "expected %<#pragma omp%> clause");
10851 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
10853 /* Remove the invalid clause(s) from the list to avoid
10854 confusing the rest of the compiler. */
10856 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
10861 c_parser_skip_to_pragma_eol (parser
);
10864 return c_finish_omp_clauses (clauses
);
10873 In practice, we're also interested in adding the statement to an
10874 outer node. So it is convenient if we work around the fact that
10875 c_parser_statement calls add_stmt. */
10878 c_parser_omp_structured_block (c_parser
*parser
)
10880 tree stmt
= push_stmt_list ();
10881 c_parser_statement (parser
);
10882 return pop_stmt_list (stmt
);
10886 # pragma omp atomic new-line
10890 x binop= expr | x++ | ++x | x-- | --x
10892 +, *, -, /, &, ^, |, <<, >>
10894 where x is an lvalue expression with scalar type.
10897 # pragma omp atomic new-line
10900 # pragma omp atomic read new-line
10903 # pragma omp atomic write new-line
10906 # pragma omp atomic update new-line
10909 # pragma omp atomic capture new-line
10912 # pragma omp atomic capture new-line
10920 expression-stmt | x = x binop expr
10922 v = expression-stmt
10924 { v = x; update-stmt; } | { update-stmt; v = x; }
10928 expression-stmt | x = x binop expr | x = expr binop x
10932 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
10934 where x and v are lvalue expressions with scalar type.
10936 LOC is the location of the #pragma token. */
10939 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
10941 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
10942 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
10943 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
10944 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
10945 struct c_expr expr
;
10947 bool structured_block
= false;
10948 bool swapped
= false;
10949 bool seq_cst
= false;
10951 if (c_parser_next_token_is (parser
, CPP_NAME
))
10953 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10955 if (!strcmp (p
, "read"))
10956 code
= OMP_ATOMIC_READ
;
10957 else if (!strcmp (p
, "write"))
10959 else if (!strcmp (p
, "update"))
10961 else if (!strcmp (p
, "capture"))
10962 code
= OMP_ATOMIC_CAPTURE_NEW
;
10966 c_parser_consume_token (parser
);
10968 if (c_parser_next_token_is (parser
, CPP_NAME
))
10970 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10971 if (!strcmp (p
, "seq_cst"))
10974 c_parser_consume_token (parser
);
10977 c_parser_skip_to_pragma_eol (parser
);
10981 case OMP_ATOMIC_READ
:
10982 case NOP_EXPR
: /* atomic write */
10983 v
= c_parser_unary_expression (parser
).value
;
10984 v
= c_fully_fold (v
, false, NULL
);
10985 if (v
== error_mark_node
)
10987 loc
= c_parser_peek_token (parser
)->location
;
10988 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10990 if (code
== NOP_EXPR
)
10991 lhs
= c_parser_expression (parser
).value
;
10993 lhs
= c_parser_unary_expression (parser
).value
;
10994 lhs
= c_fully_fold (lhs
, false, NULL
);
10995 if (lhs
== error_mark_node
)
10997 if (code
== NOP_EXPR
)
10999 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11007 case OMP_ATOMIC_CAPTURE_NEW
:
11008 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11010 c_parser_consume_token (parser
);
11011 structured_block
= true;
11015 v
= c_parser_unary_expression (parser
).value
;
11016 v
= c_fully_fold (v
, false, NULL
);
11017 if (v
== error_mark_node
)
11019 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11027 /* For structured_block case we don't know yet whether
11028 old or new x should be captured. */
11030 eloc
= c_parser_peek_token (parser
)->location
;
11031 expr
= c_parser_unary_expression (parser
);
11033 expr
= default_function_array_conversion (eloc
, expr
);
11034 unfolded_lhs
= expr
.value
;
11035 lhs
= c_fully_fold (lhs
, false, NULL
);
11037 switch (TREE_CODE (lhs
))
11041 c_parser_skip_to_end_of_block_or_statement (parser
);
11042 if (structured_block
)
11044 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11045 c_parser_consume_token (parser
);
11046 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11048 c_parser_skip_to_end_of_block_or_statement (parser
);
11049 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11050 c_parser_consume_token (parser
);
11055 case POSTINCREMENT_EXPR
:
11056 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11057 code
= OMP_ATOMIC_CAPTURE_OLD
;
11059 case PREINCREMENT_EXPR
:
11060 lhs
= TREE_OPERAND (lhs
, 0);
11061 unfolded_lhs
= NULL_TREE
;
11062 opcode
= PLUS_EXPR
;
11063 rhs
= integer_one_node
;
11066 case POSTDECREMENT_EXPR
:
11067 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11068 code
= OMP_ATOMIC_CAPTURE_OLD
;
11070 case PREDECREMENT_EXPR
:
11071 lhs
= TREE_OPERAND (lhs
, 0);
11072 unfolded_lhs
= NULL_TREE
;
11073 opcode
= MINUS_EXPR
;
11074 rhs
= integer_one_node
;
11077 case COMPOUND_EXPR
:
11078 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11079 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11080 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11081 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11082 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11083 (TREE_OPERAND (lhs
, 1), 0), 0)))
11085 /* Undo effects of boolean_increment for post {in,de}crement. */
11086 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11089 if (TREE_CODE (lhs
) == MODIFY_EXPR
11090 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11092 /* Undo effects of boolean_increment. */
11093 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11095 /* This is pre or post increment. */
11096 rhs
= TREE_OPERAND (lhs
, 1);
11097 lhs
= TREE_OPERAND (lhs
, 0);
11098 unfolded_lhs
= NULL_TREE
;
11100 if (code
== OMP_ATOMIC_CAPTURE_NEW
11101 && !structured_block
11102 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11103 code
= OMP_ATOMIC_CAPTURE_OLD
;
11106 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11107 && TREE_OPERAND (lhs
, 0)
11108 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11110 /* This is pre or post decrement. */
11111 rhs
= TREE_OPERAND (lhs
, 1);
11112 lhs
= TREE_OPERAND (lhs
, 0);
11113 unfolded_lhs
= NULL_TREE
;
11115 if (code
== OMP_ATOMIC_CAPTURE_NEW
11116 && !structured_block
11117 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11118 code
= OMP_ATOMIC_CAPTURE_OLD
;
11124 switch (c_parser_peek_token (parser
)->type
)
11127 opcode
= MULT_EXPR
;
11130 opcode
= TRUNC_DIV_EXPR
;
11133 opcode
= PLUS_EXPR
;
11136 opcode
= MINUS_EXPR
;
11138 case CPP_LSHIFT_EQ
:
11139 opcode
= LSHIFT_EXPR
;
11141 case CPP_RSHIFT_EQ
:
11142 opcode
= RSHIFT_EXPR
;
11145 opcode
= BIT_AND_EXPR
;
11148 opcode
= BIT_IOR_EXPR
;
11151 opcode
= BIT_XOR_EXPR
;
11154 c_parser_consume_token (parser
);
11155 eloc
= c_parser_peek_token (parser
)->location
;
11156 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11158 switch (TREE_CODE (rhs1
))
11161 case TRUNC_DIV_EXPR
:
11169 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11171 opcode
= TREE_CODE (rhs1
);
11172 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11173 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11176 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11178 opcode
= TREE_CODE (rhs1
);
11179 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11180 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11181 swapped
= !commutative_tree_code (opcode
);
11190 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11192 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11194 code
= OMP_ATOMIC_CAPTURE_OLD
;
11197 expr
= default_function_array_read_conversion (eloc
, expr
);
11198 unfolded_lhs1
= expr
.value
;
11199 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11201 c_parser_consume_token (parser
);
11204 if (structured_block
)
11207 expr
= default_function_array_read_conversion (eloc
, expr
);
11208 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11213 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11216 c_parser_error (parser
,
11217 "invalid operator for %<#pragma omp atomic%>");
11221 /* Arrange to pass the location of the assignment operator to
11222 c_finish_omp_atomic. */
11223 loc
= c_parser_peek_token (parser
)->location
;
11224 c_parser_consume_token (parser
);
11225 eloc
= c_parser_peek_token (parser
)->location
;
11226 expr
= c_parser_expression (parser
);
11227 expr
= default_function_array_read_conversion (eloc
, expr
);
11229 rhs
= c_fully_fold (rhs
, false, NULL
);
11233 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11235 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11237 v
= c_parser_unary_expression (parser
).value
;
11238 v
= c_fully_fold (v
, false, NULL
);
11239 if (v
== error_mark_node
)
11241 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11243 eloc
= c_parser_peek_token (parser
)->location
;
11244 expr
= c_parser_unary_expression (parser
);
11246 expr
= default_function_array_read_conversion (eloc
, expr
);
11247 unfolded_lhs1
= expr
.value
;
11248 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11249 if (lhs1
== error_mark_node
)
11252 if (structured_block
)
11254 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11255 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11258 if (unfolded_lhs
&& unfolded_lhs1
11259 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11261 error ("%<#pragma omp atomic capture%> uses two different "
11262 "expressions for memory");
11263 stmt
= error_mark_node
;
11266 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11268 if (stmt
!= error_mark_node
)
11271 if (!structured_block
)
11272 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11277 # pragma omp barrier new-line
11281 c_parser_omp_barrier (c_parser
*parser
)
11283 location_t loc
= c_parser_peek_token (parser
)->location
;
11284 c_parser_consume_pragma (parser
);
11285 c_parser_skip_to_pragma_eol (parser
);
11287 c_finish_omp_barrier (loc
);
11291 # pragma omp critical [(name)] new-line
11294 LOC is the location of the #pragma itself. */
11297 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11299 tree stmt
, name
= NULL
;
11301 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11303 c_parser_consume_token (parser
);
11304 if (c_parser_next_token_is (parser
, CPP_NAME
))
11306 name
= c_parser_peek_token (parser
)->value
;
11307 c_parser_consume_token (parser
);
11308 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11311 c_parser_error (parser
, "expected identifier");
11313 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11314 c_parser_error (parser
, "expected %<(%> or end of line");
11315 c_parser_skip_to_pragma_eol (parser
);
11317 stmt
= c_parser_omp_structured_block (parser
);
11318 return c_finish_omp_critical (loc
, stmt
, name
);
11322 # pragma omp flush flush-vars[opt] new-line
11325 ( variable-list ) */
11328 c_parser_omp_flush (c_parser
*parser
)
11330 location_t loc
= c_parser_peek_token (parser
)->location
;
11331 c_parser_consume_pragma (parser
);
11332 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11333 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11334 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11335 c_parser_error (parser
, "expected %<(%> or end of line");
11336 c_parser_skip_to_pragma_eol (parser
);
11338 c_finish_omp_flush (loc
);
11341 /* Parse the restricted form of the for statement allowed by OpenMP.
11342 The real trick here is to determine the loop control variable early
11343 so that we can push a new decl if necessary to make it private.
11344 LOC is the location of the OMP in "#pragma omp". */
11347 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11348 tree clauses
, tree
*cclauses
)
11350 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11351 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11352 bool fail
= false, open_brace_parsed
= false;
11353 int i
, collapse
= 1, nbraces
= 0;
11354 location_t for_loc
;
11355 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11357 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11358 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11359 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
11361 gcc_assert (collapse
>= 1);
11363 declv
= make_tree_vec (collapse
);
11364 initv
= make_tree_vec (collapse
);
11365 condv
= make_tree_vec (collapse
);
11366 incrv
= make_tree_vec (collapse
);
11368 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11370 c_parser_error (parser
, "for statement expected");
11373 for_loc
= c_parser_peek_token (parser
)->location
;
11374 c_parser_consume_token (parser
);
11376 for (i
= 0; i
< collapse
; i
++)
11378 int bracecount
= 0;
11380 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11383 /* Parse the initialization declaration or expression. */
11384 if (c_parser_next_tokens_start_declaration (parser
))
11387 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11388 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11390 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11393 if (DECL_INITIAL (decl
) == error_mark_node
)
11394 decl
= error_mark_node
;
11397 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11398 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11400 struct c_expr decl_exp
;
11401 struct c_expr init_exp
;
11402 location_t init_loc
;
11404 decl_exp
= c_parser_postfix_expression (parser
);
11405 decl
= decl_exp
.value
;
11407 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11409 init_loc
= c_parser_peek_token (parser
)->location
;
11410 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11411 init_exp
= default_function_array_read_conversion (init_loc
,
11413 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11414 NOP_EXPR
, init_loc
, init_exp
.value
,
11415 init_exp
.original_type
);
11416 init
= c_process_expr_stmt (init_loc
, init
);
11418 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11423 c_parser_error (parser
,
11424 "expected iteration declaration or initialization");
11425 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11431 /* Parse the loop condition. */
11433 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11435 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11436 struct c_expr cond_expr
11437 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11439 cond
= cond_expr
.value
;
11440 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11441 cond
= c_fully_fold (cond
, false, NULL
);
11442 switch (cond_expr
.original_code
)
11450 /* Can't be cond = error_mark_node, because we want to preserve
11451 the location until c_finish_omp_for. */
11452 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11455 protected_set_expr_location (cond
, cond_loc
);
11457 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11459 /* Parse the increment expression. */
11461 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11463 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11465 incr
= c_process_expr_stmt (incr_loc
,
11466 c_parser_expression (parser
).value
);
11468 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11470 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11474 TREE_VEC_ELT (declv
, i
) = decl
;
11475 TREE_VEC_ELT (initv
, i
) = init
;
11476 TREE_VEC_ELT (condv
, i
) = cond
;
11477 TREE_VEC_ELT (incrv
, i
) = incr
;
11481 if (i
== collapse
- 1)
11484 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11485 in between the collapsed for loops to be still considered perfectly
11486 nested. Hopefully the final version clarifies this.
11487 For now handle (multiple) {'s and empty statements. */
11490 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11492 c_parser_consume_token (parser
);
11495 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11497 c_parser_consume_token (parser
);
11500 else if (bracecount
11501 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11502 c_parser_consume_token (parser
);
11505 c_parser_error (parser
, "not enough perfectly nested loops");
11508 open_brace_parsed
= true;
11518 nbraces
+= bracecount
;
11521 save_break
= c_break_label
;
11522 c_break_label
= size_one_node
;
11523 save_cont
= c_cont_label
;
11524 c_cont_label
= NULL_TREE
;
11525 body
= push_stmt_list ();
11527 if (open_brace_parsed
)
11529 location_t here
= c_parser_peek_token (parser
)->location
;
11530 stmt
= c_begin_compound_stmt (true);
11531 c_parser_compound_statement_nostart (parser
);
11532 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11535 add_stmt (c_parser_c99_block_statement (parser
));
11538 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11539 SET_EXPR_LOCATION (t
, loc
);
11543 body
= pop_stmt_list (body
);
11544 c_break_label
= save_break
;
11545 c_cont_label
= save_cont
;
11549 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11551 c_parser_consume_token (parser
);
11554 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11555 c_parser_consume_token (parser
);
11558 c_parser_error (parser
, "collapsed loops not perfectly nested");
11561 location_t here
= c_parser_peek_token (parser
)->location
;
11562 stmt
= c_begin_compound_stmt (true);
11564 c_parser_compound_statement_nostart (parser
);
11565 body
= c_end_compound_stmt (here
, stmt
, true);
11572 /* Only bother calling c_finish_omp_for if we haven't already generated
11573 an error from the initialization parsing. */
11576 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11577 incrv
, body
, NULL
);
11580 if (cclauses
!= NULL
11581 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11584 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11585 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11586 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11587 c
= &OMP_CLAUSE_CHAIN (*c
);
11590 for (i
= 0; i
< collapse
; i
++)
11591 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11594 c
= &OMP_CLAUSE_CHAIN (*c
);
11595 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11598 "iteration variable %qD should not be firstprivate",
11599 OMP_CLAUSE_DECL (*c
));
11600 *c
= OMP_CLAUSE_CHAIN (*c
);
11604 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11605 change it to shared (decl) in
11606 OMP_PARALLEL_CLAUSES. */
11607 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11608 OMP_CLAUSE_LASTPRIVATE
);
11609 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11610 OMP_CLAUSE_CHAIN (l
) = clauses
;
11612 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11616 OMP_FOR_CLAUSES (stmt
) = clauses
;
11621 while (!for_block
->is_empty ())
11623 /* FIXME diagnostics: LOC below should be the actual location of
11624 this particular for block. We need to build a list of
11625 locations to go along with FOR_BLOCK. */
11626 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11629 release_tree_vector (for_block
);
11633 /* Helper function for OpenMP parsing, split clauses and call
11634 finish_omp_clauses on each of the set of clauses afterwards. */
11637 omp_split_clauses (location_t loc
, enum tree_code code
,
11638 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11641 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11642 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11644 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11648 #pragma omp simd simd-clause[optseq] new-line
11651 LOC is the location of the #pragma token.
11654 #define OMP_SIMD_CLAUSE_MASK \
11655 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
11656 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
11657 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
11658 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11659 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11660 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11661 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
11664 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
11665 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11667 tree block
, clauses
, ret
;
11669 strcat (p_name
, " simd");
11670 mask
|= OMP_SIMD_CLAUSE_MASK
;
11671 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
11673 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11676 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
11677 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
11680 block
= c_begin_compound_stmt (true);
11681 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
11682 block
= c_end_compound_stmt (loc
, block
, true);
11689 #pragma omp for for-clause[optseq] new-line
11693 #pragma omp for simd for-simd-clause[optseq] new-line
11696 LOC is the location of the #pragma token.
11699 #define OMP_FOR_CLAUSE_MASK \
11700 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11701 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11702 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11703 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11704 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
11705 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
11706 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11707 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11710 c_parser_omp_for (location_t loc
, c_parser
*parser
,
11711 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11713 tree block
, clauses
, ret
;
11715 strcat (p_name
, " for");
11716 mask
|= OMP_FOR_CLAUSE_MASK
;
11718 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
11720 if (c_parser_next_token_is (parser
, CPP_NAME
))
11722 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11724 if (strcmp (p
, "simd") == 0)
11726 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
11727 if (cclauses
== NULL
)
11728 cclauses
= cclauses_buf
;
11730 c_parser_consume_token (parser
);
11731 if (!flag_openmp
) /* flag_openmp_simd */
11732 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
11733 block
= c_begin_compound_stmt (true);
11734 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
11735 block
= c_end_compound_stmt (loc
, block
, true);
11736 if (ret
== NULL_TREE
)
11738 ret
= make_node (OMP_FOR
);
11739 TREE_TYPE (ret
) = void_type_node
;
11740 OMP_FOR_BODY (ret
) = block
;
11741 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11742 SET_EXPR_LOCATION (ret
, loc
);
11747 if (!flag_openmp
) /* flag_openmp_simd */
11749 c_parser_skip_to_pragma_eol (parser
);
11753 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11756 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
11757 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11760 block
= c_begin_compound_stmt (true);
11761 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
11762 block
= c_end_compound_stmt (loc
, block
, true);
11769 # pragma omp master new-line
11772 LOC is the location of the #pragma token.
11776 c_parser_omp_master (location_t loc
, c_parser
*parser
)
11778 c_parser_skip_to_pragma_eol (parser
);
11779 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
11783 # pragma omp ordered new-line
11786 LOC is the location of the #pragma itself.
11790 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
11792 c_parser_skip_to_pragma_eol (parser
);
11793 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
11799 { section-sequence }
11802 section-directive[opt] structured-block
11803 section-sequence section-directive structured-block
11805 SECTIONS_LOC is the location of the #pragma omp sections. */
11808 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
11810 tree stmt
, substmt
;
11811 bool error_suppress
= false;
11814 loc
= c_parser_peek_token (parser
)->location
;
11815 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
11817 /* Avoid skipping until the end of the block. */
11818 parser
->error
= false;
11822 stmt
= push_stmt_list ();
11824 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
11826 substmt
= c_parser_omp_structured_block (parser
);
11827 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11828 SET_EXPR_LOCATION (substmt
, loc
);
11829 add_stmt (substmt
);
11834 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11836 if (c_parser_next_token_is (parser
, CPP_EOF
))
11839 loc
= c_parser_peek_token (parser
)->location
;
11840 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
11842 c_parser_consume_pragma (parser
);
11843 c_parser_skip_to_pragma_eol (parser
);
11844 error_suppress
= false;
11846 else if (!error_suppress
)
11848 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
11849 error_suppress
= true;
11852 substmt
= c_parser_omp_structured_block (parser
);
11853 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
11854 SET_EXPR_LOCATION (substmt
, loc
);
11855 add_stmt (substmt
);
11857 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
11858 "expected %<#pragma omp section%> or %<}%>");
11860 substmt
= pop_stmt_list (stmt
);
11862 stmt
= make_node (OMP_SECTIONS
);
11863 SET_EXPR_LOCATION (stmt
, sections_loc
);
11864 TREE_TYPE (stmt
) = void_type_node
;
11865 OMP_SECTIONS_BODY (stmt
) = substmt
;
11867 return add_stmt (stmt
);
11871 # pragma omp sections sections-clause[optseq] newline
11874 LOC is the location of the #pragma token.
11877 #define OMP_SECTIONS_CLAUSE_MASK \
11878 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11879 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11880 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11881 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11882 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11885 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
11886 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11888 tree block
, clauses
, ret
;
11890 strcat (p_name
, " sections");
11891 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
11893 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
11895 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11898 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
11899 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
11902 block
= c_begin_compound_stmt (true);
11903 ret
= c_parser_omp_sections_scope (loc
, parser
);
11905 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
11906 block
= c_end_compound_stmt (loc
, block
, true);
11913 # pragma parallel parallel-clause new-line
11914 # pragma parallel for parallel-for-clause new-line
11915 # pragma parallel sections parallel-sections-clause new-line
11917 LOC is the location of the #pragma token.
11920 #define OMP_PARALLEL_CLAUSE_MASK \
11921 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
11922 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11923 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11924 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
11925 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
11926 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
11927 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11928 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
11929 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
11932 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
11933 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11935 tree stmt
, clauses
, block
;
11937 strcat (p_name
, " parallel");
11938 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
11940 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11942 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
11943 if (cclauses
== NULL
)
11944 cclauses
= cclauses_buf
;
11946 c_parser_consume_token (parser
);
11947 if (!flag_openmp
) /* flag_openmp_simd */
11948 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
11949 block
= c_begin_omp_parallel ();
11950 c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
11952 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
11954 OMP_PARALLEL_COMBINED (stmt
) = 1;
11959 error_at (loc
, "expected %<for%> after %qs", p_name
);
11960 c_parser_skip_to_pragma_eol (parser
);
11963 else if (!flag_openmp
) /* flag_openmp_simd */
11965 c_parser_skip_to_pragma_eol (parser
);
11968 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11970 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11971 if (strcmp (p
, "sections") == 0)
11973 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
11974 if (cclauses
== NULL
)
11975 cclauses
= cclauses_buf
;
11977 c_parser_consume_token (parser
);
11978 block
= c_begin_omp_parallel ();
11979 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
11980 stmt
= c_finish_omp_parallel (loc
,
11981 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
11983 OMP_PARALLEL_COMBINED (stmt
) = 1;
11988 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11990 block
= c_begin_omp_parallel ();
11991 c_parser_statement (parser
);
11992 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
11998 # pragma omp single single-clause[optseq] new-line
12001 LOC is the location of the #pragma.
12004 #define OMP_SINGLE_CLAUSE_MASK \
12005 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12006 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12007 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12011 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12013 tree stmt
= make_node (OMP_SINGLE
);
12014 SET_EXPR_LOCATION (stmt
, loc
);
12015 TREE_TYPE (stmt
) = void_type_node
;
12017 OMP_SINGLE_CLAUSES (stmt
)
12018 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12019 "#pragma omp single");
12020 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12022 return add_stmt (stmt
);
12026 # pragma omp task task-clause[optseq] new-line
12028 LOC is the location of the #pragma.
12031 #define OMP_TASK_CLAUSE_MASK \
12032 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12033 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12034 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12035 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12036 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12037 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12038 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12039 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12040 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12043 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12045 tree clauses
, block
;
12047 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12048 "#pragma omp task");
12050 block
= c_begin_omp_task ();
12051 c_parser_statement (parser
);
12052 return c_finish_omp_task (loc
, clauses
, block
);
12056 # pragma omp taskwait new-line
12060 c_parser_omp_taskwait (c_parser
*parser
)
12062 location_t loc
= c_parser_peek_token (parser
)->location
;
12063 c_parser_consume_pragma (parser
);
12064 c_parser_skip_to_pragma_eol (parser
);
12066 c_finish_omp_taskwait (loc
);
12070 # pragma omp taskyield new-line
12074 c_parser_omp_taskyield (c_parser
*parser
)
12076 location_t loc
= c_parser_peek_token (parser
)->location
;
12077 c_parser_consume_pragma (parser
);
12078 c_parser_skip_to_pragma_eol (parser
);
12080 c_finish_omp_taskyield (loc
);
12084 # pragma omp taskgroup new-line
12088 c_parser_omp_taskgroup (c_parser
*parser
)
12090 location_t loc
= c_parser_peek_token (parser
)->location
;
12091 c_parser_skip_to_pragma_eol (parser
);
12092 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12096 # pragma omp cancel cancel-clause[optseq] new-line
12098 LOC is the location of the #pragma.
12101 #define OMP_CANCEL_CLAUSE_MASK \
12102 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12103 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12104 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12105 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12106 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12109 c_parser_omp_cancel (c_parser
*parser
)
12111 location_t loc
= c_parser_peek_token (parser
)->location
;
12113 c_parser_consume_pragma (parser
);
12114 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12115 "#pragma omp cancel");
12117 c_finish_omp_cancel (loc
, clauses
);
12121 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12123 LOC is the location of the #pragma.
12126 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12127 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12128 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12129 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12130 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12133 c_parser_omp_cancellation_point (c_parser
*parser
)
12135 location_t loc
= c_parser_peek_token (parser
)->location
;
12137 bool point_seen
= false;
12139 c_parser_consume_pragma (parser
);
12140 if (c_parser_next_token_is (parser
, CPP_NAME
))
12142 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12143 if (strcmp (p
, "point") == 0)
12145 c_parser_consume_token (parser
);
12151 c_parser_error (parser
, "expected %<point%>");
12152 c_parser_skip_to_pragma_eol (parser
);
12157 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12158 "#pragma omp cancellation point");
12160 c_finish_omp_cancellation_point (loc
, clauses
);
12164 #pragma omp distribute distribute-clause[optseq] new-line
12167 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12168 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12169 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12170 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12171 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12174 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12175 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12177 tree clauses
, block
, ret
;
12179 strcat (p_name
, " distribute");
12180 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12182 if (c_parser_next_token_is (parser
, CPP_NAME
))
12184 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12186 bool parallel
= false;
12188 if (strcmp (p
, "simd") == 0)
12191 parallel
= strcmp (p
, "parallel") == 0;
12192 if (parallel
|| simd
)
12194 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12195 if (cclauses
== NULL
)
12196 cclauses
= cclauses_buf
;
12197 c_parser_consume_token (parser
);
12198 if (!flag_openmp
) /* flag_openmp_simd */
12201 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12203 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12206 block
= c_begin_compound_stmt (true);
12208 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12210 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12211 block
= c_end_compound_stmt (loc
, block
, true);
12214 ret
= make_node (OMP_DISTRIBUTE
);
12215 TREE_TYPE (ret
) = void_type_node
;
12216 OMP_FOR_BODY (ret
) = block
;
12217 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12218 SET_EXPR_LOCATION (ret
, loc
);
12223 if (!flag_openmp
) /* flag_openmp_simd */
12225 c_parser_skip_to_pragma_eol (parser
);
12229 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12232 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12233 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12236 block
= c_begin_compound_stmt (true);
12237 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12238 block
= c_end_compound_stmt (loc
, block
, true);
12245 # pragma omp teams teams-clause[optseq] new-line
12246 structured-block */
12248 #define OMP_TEAMS_CLAUSE_MASK \
12249 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12250 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12251 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12252 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12253 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12254 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12255 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12258 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12259 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12261 tree clauses
, block
, ret
;
12263 strcat (p_name
, " teams");
12264 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12266 if (c_parser_next_token_is (parser
, CPP_NAME
))
12268 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12269 if (strcmp (p
, "distribute") == 0)
12271 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12272 if (cclauses
== NULL
)
12273 cclauses
= cclauses_buf
;
12275 c_parser_consume_token (parser
);
12276 if (!flag_openmp
) /* flag_openmp_simd */
12277 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12278 block
= c_begin_compound_stmt (true);
12279 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12280 block
= c_end_compound_stmt (loc
, block
, true);
12283 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12284 ret
= make_node (OMP_TEAMS
);
12285 TREE_TYPE (ret
) = void_type_node
;
12286 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12287 OMP_TEAMS_BODY (ret
) = block
;
12288 return add_stmt (ret
);
12291 if (!flag_openmp
) /* flag_openmp_simd */
12293 c_parser_skip_to_pragma_eol (parser
);
12297 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12300 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12301 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12304 tree stmt
= make_node (OMP_TEAMS
);
12305 TREE_TYPE (stmt
) = void_type_node
;
12306 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12307 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12309 return add_stmt (stmt
);
12313 # pragma omp target data target-data-clause[optseq] new-line
12314 structured-block */
12316 #define OMP_TARGET_DATA_CLAUSE_MASK \
12317 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12318 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12322 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12324 tree stmt
= make_node (OMP_TARGET_DATA
);
12325 TREE_TYPE (stmt
) = void_type_node
;
12327 OMP_TARGET_DATA_CLAUSES (stmt
)
12328 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12329 "#pragma omp target data");
12330 keep_next_level ();
12331 tree block
= c_begin_compound_stmt (true);
12332 add_stmt (c_parser_omp_structured_block (parser
));
12333 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12335 SET_EXPR_LOCATION (stmt
, loc
);
12336 return add_stmt (stmt
);
12340 # pragma omp target update target-update-clause[optseq] new-line */
12342 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12343 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12344 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12345 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12346 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12349 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12350 enum pragma_context context
)
12352 if (context
== pragma_stmt
)
12355 "%<#pragma omp target update%> may only be "
12356 "used in compound statements");
12357 c_parser_skip_to_pragma_eol (parser
);
12362 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12363 "#pragma omp target update");
12364 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12365 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12368 "%<#pragma omp target update must contain at least one "
12369 "%<from%> or %<to%> clauses");
12373 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12374 TREE_TYPE (stmt
) = void_type_node
;
12375 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12376 SET_EXPR_LOCATION (stmt
, loc
);
12382 # pragma omp target target-clause[optseq] new-line
12383 structured-block */
12385 #define OMP_TARGET_CLAUSE_MASK \
12386 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12387 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12388 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12391 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12393 location_t loc
= c_parser_peek_token (parser
)->location
;
12394 c_parser_consume_pragma (parser
);
12396 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12398 c_parser_error (parser
, "expected declaration specifiers");
12399 c_parser_skip_to_pragma_eol (parser
);
12403 if (c_parser_next_token_is (parser
, CPP_NAME
))
12405 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12407 if (strcmp (p
, "teams") == 0)
12409 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12410 char p_name
[sizeof ("#pragma omp target teams distribute "
12411 "parallel for simd")];
12413 c_parser_consume_token (parser
);
12414 if (!flag_openmp
) /* flag_openmp_simd */
12415 return c_parser_omp_teams (loc
, parser
, p_name
,
12416 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12417 strcpy (p_name
, "#pragma omp target");
12418 keep_next_level ();
12419 tree block
= c_begin_compound_stmt (true);
12420 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12421 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12422 block
= c_end_compound_stmt (loc
, block
, true);
12425 tree stmt
= make_node (OMP_TARGET
);
12426 TREE_TYPE (stmt
) = void_type_node
;
12427 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12428 OMP_TARGET_BODY (stmt
) = block
;
12432 else if (!flag_openmp
) /* flag_openmp_simd */
12434 c_parser_skip_to_pragma_eol (parser
);
12437 else if (strcmp (p
, "data") == 0)
12439 c_parser_consume_token (parser
);
12440 c_parser_omp_target_data (loc
, parser
);
12443 else if (strcmp (p
, "update") == 0)
12445 c_parser_consume_token (parser
);
12446 return c_parser_omp_target_update (loc
, parser
, context
);
12450 tree stmt
= make_node (OMP_TARGET
);
12451 TREE_TYPE (stmt
) = void_type_node
;
12453 OMP_TARGET_CLAUSES (stmt
)
12454 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12455 "#pragma omp target");
12456 keep_next_level ();
12457 tree block
= c_begin_compound_stmt (true);
12458 add_stmt (c_parser_omp_structured_block (parser
));
12459 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12461 SET_EXPR_LOCATION (stmt
, loc
);
12467 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12469 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12470 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12471 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12472 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12473 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12474 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12475 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12478 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12480 vec
<c_token
> clauses
= vNULL
;
12481 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12483 c_token
*token
= c_parser_peek_token (parser
);
12484 if (token
->type
== CPP_EOF
)
12486 c_parser_skip_to_pragma_eol (parser
);
12487 clauses
.release ();
12490 clauses
.safe_push (*token
);
12491 c_parser_consume_token (parser
);
12493 clauses
.safe_push (*c_parser_peek_token (parser
));
12494 c_parser_skip_to_pragma_eol (parser
);
12496 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12498 if (c_parser_peek_token (parser
)->pragma_kind
12499 != PRAGMA_OMP_DECLARE_REDUCTION
12500 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12501 || strcmp (IDENTIFIER_POINTER
12502 (c_parser_peek_2nd_token (parser
)->value
),
12505 c_parser_error (parser
,
12506 "%<#pragma omp declare simd%> must be followed by "
12507 "function declaration or definition or another "
12508 "%<#pragma omp declare simd%>");
12509 clauses
.release ();
12512 c_parser_consume_pragma (parser
);
12513 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12515 c_token
*token
= c_parser_peek_token (parser
);
12516 if (token
->type
== CPP_EOF
)
12518 c_parser_skip_to_pragma_eol (parser
);
12519 clauses
.release ();
12522 clauses
.safe_push (*token
);
12523 c_parser_consume_token (parser
);
12525 clauses
.safe_push (*c_parser_peek_token (parser
));
12526 c_parser_skip_to_pragma_eol (parser
);
12529 /* Make sure nothing tries to read past the end of the tokens. */
12531 memset (&eof_token
, 0, sizeof (eof_token
));
12532 eof_token
.type
= CPP_EOF
;
12533 clauses
.safe_push (eof_token
);
12534 clauses
.safe_push (eof_token
);
12538 case pragma_external
:
12539 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12540 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12542 int ext
= disable_extension_diagnostics ();
12544 c_parser_consume_token (parser
);
12545 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12546 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12547 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12549 restore_extension_diagnostics (ext
);
12552 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12555 case pragma_struct
:
12557 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12558 "function declaration or definition");
12560 case pragma_compound
:
12562 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12563 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12565 int ext
= disable_extension_diagnostics ();
12567 c_parser_consume_token (parser
);
12568 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12569 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12570 if (c_parser_next_tokens_start_declaration (parser
))
12572 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12573 true, NULL
, clauses
);
12574 restore_extension_diagnostics (ext
);
12577 restore_extension_diagnostics (ext
);
12579 else if (c_parser_next_tokens_start_declaration (parser
))
12581 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12585 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12586 "function declaration or definition");
12589 gcc_unreachable ();
12591 clauses
.release ();
12594 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12595 and put that into "omp declare simd" attribute. */
12598 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12599 vec
<c_token
> clauses
)
12601 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12602 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12603 has already processed the tokens. */
12604 if (clauses
[0].type
== CPP_EOF
)
12606 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12608 error ("%<#pragma omp declare simd%> not immediately followed by "
12609 "a function declaration or definition");
12610 clauses
[0].type
= CPP_EOF
;
12613 if (clauses
[0].type
!= CPP_NAME
)
12615 error_at (DECL_SOURCE_LOCATION (fndecl
),
12616 "%<#pragma omp declare simd%> not immediately followed by "
12617 "a single function declaration or definition");
12618 clauses
[0].type
= CPP_EOF
;
12622 if (parms
== NULL_TREE
)
12623 parms
= DECL_ARGUMENTS (fndecl
);
12625 unsigned int tokens_avail
= parser
->tokens_avail
;
12626 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12627 parser
->tokens
= clauses
.address ();
12628 parser
->tokens_avail
= clauses
.length ();
12630 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12631 while (parser
->tokens_avail
> 3)
12633 c_token
*token
= c_parser_peek_token (parser
);
12634 gcc_assert (token
->type
== CPP_NAME
12635 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12636 c_parser_consume_token (parser
);
12637 parser
->in_pragma
= true;
12639 tree c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12640 "#pragma omp declare simd");
12641 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12642 if (c
!= NULL_TREE
)
12643 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12644 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12645 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12646 DECL_ATTRIBUTES (fndecl
) = c
;
12649 parser
->tokens
= &parser
->tokens_buf
[0];
12650 parser
->tokens_avail
= tokens_avail
;
12651 clauses
[0].type
= CPP_PRAGMA
;
12656 # pragma omp declare target new-line
12657 declarations and definitions
12658 # pragma omp end declare target new-line */
12661 c_parser_omp_declare_target (c_parser
*parser
)
12663 c_parser_skip_to_pragma_eol (parser
);
12664 current_omp_declare_target_attribute
++;
12668 c_parser_omp_end_declare_target (c_parser
*parser
)
12670 location_t loc
= c_parser_peek_token (parser
)->location
;
12671 c_parser_consume_pragma (parser
);
12672 if (c_parser_next_token_is (parser
, CPP_NAME
)
12673 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12676 c_parser_consume_token (parser
);
12677 if (c_parser_next_token_is (parser
, CPP_NAME
)
12678 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12680 c_parser_consume_token (parser
);
12683 c_parser_error (parser
, "expected %<target%>");
12684 c_parser_skip_to_pragma_eol (parser
);
12690 c_parser_error (parser
, "expected %<declare%>");
12691 c_parser_skip_to_pragma_eol (parser
);
12694 c_parser_skip_to_pragma_eol (parser
);
12695 if (!current_omp_declare_target_attribute
)
12696 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
12697 "%<#pragma omp declare target%>");
12699 current_omp_declare_target_attribute
--;
12704 #pragma omp declare reduction (reduction-id : typename-list : expression) \
12705 initializer-clause[opt] new-line
12707 initializer-clause:
12708 initializer (omp_priv = initializer)
12709 initializer (function-name (argument-list)) */
12712 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
12714 unsigned int tokens_avail
= 0, i
;
12715 vec
<tree
> types
= vNULL
;
12716 vec
<c_token
> clauses
= vNULL
;
12717 enum tree_code reduc_code
= ERROR_MARK
;
12718 tree reduc_id
= NULL_TREE
;
12720 location_t rloc
= c_parser_peek_token (parser
)->location
;
12722 if (context
== pragma_struct
|| context
== pragma_param
)
12724 error ("%<#pragma omp declare reduction%> not at file or block scope");
12728 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12731 switch (c_parser_peek_token (parser
)->type
)
12734 reduc_code
= PLUS_EXPR
;
12737 reduc_code
= MULT_EXPR
;
12740 reduc_code
= MINUS_EXPR
;
12743 reduc_code
= BIT_AND_EXPR
;
12746 reduc_code
= BIT_XOR_EXPR
;
12749 reduc_code
= BIT_IOR_EXPR
;
12752 reduc_code
= TRUTH_ANDIF_EXPR
;
12755 reduc_code
= TRUTH_ORIF_EXPR
;
12759 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12760 if (strcmp (p
, "min") == 0)
12762 reduc_code
= MIN_EXPR
;
12765 if (strcmp (p
, "max") == 0)
12767 reduc_code
= MAX_EXPR
;
12770 reduc_id
= c_parser_peek_token (parser
)->value
;
12773 c_parser_error (parser
,
12774 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12775 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
12779 tree orig_reduc_id
, reduc_decl
;
12780 orig_reduc_id
= reduc_id
;
12781 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
12782 reduc_decl
= c_omp_reduction_decl (reduc_id
);
12783 c_parser_consume_token (parser
);
12785 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12790 location_t loc
= c_parser_peek_token (parser
)->location
;
12791 struct c_type_name
*ctype
= c_parser_type_name (parser
);
12794 type
= groktypename (ctype
, NULL
, NULL
);
12795 if (type
== error_mark_node
)
12797 else if ((INTEGRAL_TYPE_P (type
)
12798 || TREE_CODE (type
) == REAL_TYPE
12799 || TREE_CODE (type
) == COMPLEX_TYPE
)
12800 && orig_reduc_id
== NULL_TREE
)
12801 error_at (loc
, "predeclared arithmetic type in "
12802 "%<#pragma omp declare reduction%>");
12803 else if (TREE_CODE (type
) == FUNCTION_TYPE
12804 || TREE_CODE (type
) == ARRAY_TYPE
)
12805 error_at (loc
, "function or array type in "
12806 "%<#pragma omp declare reduction%>");
12807 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
12808 error_at (loc
, "const, volatile or restrict qualified type in "
12809 "%<#pragma omp declare reduction%>");
12813 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
12814 if (comptypes (TREE_PURPOSE (t
), type
))
12816 error_at (loc
, "redeclaration of %qs "
12817 "%<#pragma omp declare reduction%> for "
12819 IDENTIFIER_POINTER (reduc_id
)
12820 + sizeof ("omp declare reduction ") - 1,
12823 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
12825 error_at (ploc
, "previous %<#pragma omp declare "
12829 if (t
== NULL_TREE
)
12830 types
.safe_push (type
);
12832 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12833 c_parser_consume_token (parser
);
12841 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
12842 || types
.is_empty ())
12845 clauses
.release ();
12849 c_token
*token
= c_parser_peek_token (parser
);
12850 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
12852 c_parser_consume_token (parser
);
12854 c_parser_skip_to_pragma_eol (parser
);
12858 if (types
.length () > 1)
12860 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12862 c_token
*token
= c_parser_peek_token (parser
);
12863 if (token
->type
== CPP_EOF
)
12865 clauses
.safe_push (*token
);
12866 c_parser_consume_token (parser
);
12868 clauses
.safe_push (*c_parser_peek_token (parser
));
12869 c_parser_skip_to_pragma_eol (parser
);
12871 /* Make sure nothing tries to read past the end of the tokens. */
12873 memset (&eof_token
, 0, sizeof (eof_token
));
12874 eof_token
.type
= CPP_EOF
;
12875 clauses
.safe_push (eof_token
);
12876 clauses
.safe_push (eof_token
);
12879 int errs
= errorcount
;
12880 FOR_EACH_VEC_ELT (types
, i
, type
)
12882 tokens_avail
= parser
->tokens_avail
;
12883 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12884 if (!clauses
.is_empty ())
12886 parser
->tokens
= clauses
.address ();
12887 parser
->tokens_avail
= clauses
.length ();
12888 parser
->in_pragma
= true;
12891 bool nested
= current_function_decl
!= NULL_TREE
;
12893 c_push_function_context ();
12894 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
12895 reduc_id
, default_function_type
);
12896 current_function_decl
= fndecl
;
12897 allocate_struct_function (fndecl
, true);
12899 tree stmt
= push_stmt_list ();
12900 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
12901 warn about these. */
12902 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
12903 get_identifier ("omp_out"), type
);
12904 DECL_ARTIFICIAL (omp_out
) = 1;
12905 DECL_CONTEXT (omp_out
) = fndecl
;
12906 pushdecl (omp_out
);
12907 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
12908 get_identifier ("omp_in"), type
);
12909 DECL_ARTIFICIAL (omp_in
) = 1;
12910 DECL_CONTEXT (omp_in
) = fndecl
;
12912 struct c_expr combiner
= c_parser_expression (parser
);
12913 struct c_expr initializer
;
12914 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
12916 initializer
.value
= error_mark_node
;
12917 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12919 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12920 && strcmp (IDENTIFIER_POINTER
12921 (c_parser_peek_token (parser
)->value
),
12922 "initializer") == 0)
12924 c_parser_consume_token (parser
);
12927 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
12928 get_identifier ("omp_priv"), type
);
12929 DECL_ARTIFICIAL (omp_priv
) = 1;
12930 DECL_INITIAL (omp_priv
) = error_mark_node
;
12931 DECL_CONTEXT (omp_priv
) = fndecl
;
12932 pushdecl (omp_priv
);
12933 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
12934 get_identifier ("omp_orig"), type
);
12935 DECL_ARTIFICIAL (omp_orig
) = 1;
12936 DECL_CONTEXT (omp_orig
) = fndecl
;
12937 pushdecl (omp_orig
);
12938 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12940 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
12942 c_parser_error (parser
, "expected %<omp_priv%> or "
12946 else if (strcmp (IDENTIFIER_POINTER
12947 (c_parser_peek_token (parser
)->value
),
12950 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
12951 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12953 c_parser_error (parser
, "expected function-name %<(%>");
12957 initializer
= c_parser_postfix_expression (parser
);
12958 if (initializer
.value
12959 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
12962 tree c
= initializer
.value
;
12963 for (j
= 0; j
< call_expr_nargs (c
); j
++)
12964 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
12965 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
12967 if (j
== call_expr_nargs (c
))
12968 error ("one of the initializer call arguments should be "
12974 c_parser_consume_token (parser
);
12975 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
12979 tree st
= push_stmt_list ();
12980 start_init (omp_priv
, NULL_TREE
, 0);
12981 location_t loc
= c_parser_peek_token (parser
)->location
;
12982 struct c_expr init
= c_parser_initializer (parser
);
12984 finish_decl (omp_priv
, loc
, init
.value
,
12985 init
.original_type
, NULL_TREE
);
12986 pop_stmt_list (st
);
12990 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12996 c_parser_skip_to_pragma_eol (parser
);
12998 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
12999 DECL_INITIAL (reduc_decl
));
13000 DECL_INITIAL (reduc_decl
) = t
;
13001 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13002 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13003 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13004 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13005 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13006 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13009 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13010 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13011 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13012 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13013 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13014 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13015 walk_tree (&DECL_INITIAL (omp_priv
),
13016 c_check_omp_declare_reduction_r
,
13017 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13021 pop_stmt_list (stmt
);
13023 if (cfun
->language
!= NULL
)
13025 ggc_free (cfun
->language
);
13026 cfun
->language
= NULL
;
13029 current_function_decl
= NULL_TREE
;
13031 c_pop_function_context ();
13033 if (!clauses
.is_empty ())
13035 parser
->tokens
= &parser
->tokens_buf
[0];
13036 parser
->tokens_avail
= tokens_avail
;
13040 if (errs
!= errorcount
)
13044 clauses
.release ();
13050 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13051 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13052 initializer-clause[opt] new-line
13053 #pragma omp declare target new-line */
13056 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13058 c_parser_consume_pragma (parser
);
13059 if (c_parser_next_token_is (parser
, CPP_NAME
))
13061 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13062 if (strcmp (p
, "simd") == 0)
13064 /* c_parser_consume_token (parser); done in
13065 c_parser_omp_declare_simd. */
13066 c_parser_omp_declare_simd (parser
, context
);
13069 if (strcmp (p
, "reduction") == 0)
13071 c_parser_consume_token (parser
);
13072 c_parser_omp_declare_reduction (parser
, context
);
13075 if (!flag_openmp
) /* flag_openmp_simd */
13077 c_parser_skip_to_pragma_eol (parser
);
13080 if (strcmp (p
, "target") == 0)
13082 c_parser_consume_token (parser
);
13083 c_parser_omp_declare_target (parser
);
13088 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13090 c_parser_skip_to_pragma_eol (parser
);
13093 /* Main entry point to parsing most OpenMP pragmas. */
13096 c_parser_omp_construct (c_parser
*parser
)
13098 enum pragma_kind p_kind
;
13101 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13102 omp_clause_mask
mask (0);
13104 loc
= c_parser_peek_token (parser
)->location
;
13105 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13106 c_parser_consume_pragma (parser
);
13110 case PRAGMA_OMP_ATOMIC
:
13111 c_parser_omp_atomic (loc
, parser
);
13113 case PRAGMA_OMP_CRITICAL
:
13114 stmt
= c_parser_omp_critical (loc
, parser
);
13116 case PRAGMA_OMP_DISTRIBUTE
:
13117 strcpy (p_name
, "#pragma omp");
13118 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13120 case PRAGMA_OMP_FOR
:
13121 strcpy (p_name
, "#pragma omp");
13122 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13124 case PRAGMA_OMP_MASTER
:
13125 stmt
= c_parser_omp_master (loc
, parser
);
13127 case PRAGMA_OMP_ORDERED
:
13128 stmt
= c_parser_omp_ordered (loc
, parser
);
13130 case PRAGMA_OMP_PARALLEL
:
13131 strcpy (p_name
, "#pragma omp");
13132 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13134 case PRAGMA_OMP_SECTIONS
:
13135 strcpy (p_name
, "#pragma omp");
13136 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13138 case PRAGMA_OMP_SIMD
:
13139 strcpy (p_name
, "#pragma omp");
13140 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13142 case PRAGMA_OMP_SINGLE
:
13143 stmt
= c_parser_omp_single (loc
, parser
);
13145 case PRAGMA_OMP_TASK
:
13146 stmt
= c_parser_omp_task (loc
, parser
);
13148 case PRAGMA_OMP_TASKGROUP
:
13149 stmt
= c_parser_omp_taskgroup (parser
);
13151 case PRAGMA_OMP_TEAMS
:
13152 strcpy (p_name
, "#pragma omp");
13153 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13156 gcc_unreachable ();
13160 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13165 # pragma omp threadprivate (variable-list) */
13168 c_parser_omp_threadprivate (c_parser
*parser
)
13173 c_parser_consume_pragma (parser
);
13174 loc
= c_parser_peek_token (parser
)->location
;
13175 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13177 /* Mark every variable in VARS to be assigned thread local storage. */
13178 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13180 tree v
= TREE_PURPOSE (t
);
13182 /* FIXME diagnostics: Ideally we should keep individual
13183 locations for all the variables in the var list to make the
13184 following errors more precise. Perhaps
13185 c_parser_omp_var_list_parens() should construct a list of
13186 locations to go along with the var list. */
13188 /* If V had already been marked threadprivate, it doesn't matter
13189 whether it had been used prior to this point. */
13190 if (TREE_CODE (v
) != VAR_DECL
)
13191 error_at (loc
, "%qD is not a variable", v
);
13192 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13193 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13194 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13195 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13196 else if (TREE_TYPE (v
) == error_mark_node
)
13198 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13199 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13202 if (! DECL_THREAD_LOCAL_P (v
))
13204 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
13205 /* If rtl has been already set for this var, call
13206 make_decl_rtl once again, so that encode_section_info
13207 has a chance to look at the new decl flags. */
13208 if (DECL_RTL_SET_P (v
))
13211 C_DECL_THREADPRIVATE_P (v
) = 1;
13215 c_parser_skip_to_pragma_eol (parser
);
13218 /* Parse a transaction attribute (GCC Extension).
13220 transaction-attribute:
13224 The transactional memory language description is written for C++,
13225 and uses the C++0x attribute syntax. For compatibility, allow the
13226 bracket style for transactions in C as well. */
13229 c_parser_transaction_attributes (c_parser
*parser
)
13231 tree attr_name
, attr
= NULL
;
13233 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13234 return c_parser_attributes (parser
);
13236 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13238 c_parser_consume_token (parser
);
13239 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13242 attr_name
= c_parser_attribute_any_word (parser
);
13245 c_parser_consume_token (parser
);
13246 attr
= build_tree_list (attr_name
, NULL_TREE
);
13249 c_parser_error (parser
, "expected identifier");
13251 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13253 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13257 /* Parse a __transaction_atomic or __transaction_relaxed statement
13260 transaction-statement:
13261 __transaction_atomic transaction-attribute[opt] compound-statement
13262 __transaction_relaxed compound-statement
13264 Note that the only valid attribute is: "outer".
13268 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13270 unsigned int old_in
= parser
->in_transaction
;
13271 unsigned int this_in
= 1, new_in
;
13272 location_t loc
= c_parser_peek_token (parser
)->location
;
13275 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13276 || keyword
== RID_TRANSACTION_RELAXED
)
13277 && c_parser_next_token_is_keyword (parser
, keyword
));
13278 c_parser_consume_token (parser
);
13280 if (keyword
== RID_TRANSACTION_RELAXED
)
13281 this_in
|= TM_STMT_ATTR_RELAXED
;
13284 attrs
= c_parser_transaction_attributes (parser
);
13286 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13289 /* Keep track if we're in the lexical scope of an outer transaction. */
13290 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13292 parser
->in_transaction
= new_in
;
13293 stmt
= c_parser_compound_statement (parser
);
13294 parser
->in_transaction
= old_in
;
13297 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13299 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13300 "%<__transaction_atomic%> without transactional memory support enabled"
13301 : "%<__transaction_relaxed %> "
13302 "without transactional memory support enabled"));
13307 /* Parse a __transaction_atomic or __transaction_relaxed expression
13310 transaction-expression:
13311 __transaction_atomic ( expression )
13312 __transaction_relaxed ( expression )
13315 static struct c_expr
13316 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13319 unsigned int old_in
= parser
->in_transaction
;
13320 unsigned int this_in
= 1;
13321 location_t loc
= c_parser_peek_token (parser
)->location
;
13324 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13325 || keyword
== RID_TRANSACTION_RELAXED
)
13326 && c_parser_next_token_is_keyword (parser
, keyword
));
13327 c_parser_consume_token (parser
);
13329 if (keyword
== RID_TRANSACTION_RELAXED
)
13330 this_in
|= TM_STMT_ATTR_RELAXED
;
13333 attrs
= c_parser_transaction_attributes (parser
);
13335 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13338 parser
->in_transaction
= this_in
;
13339 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13341 tree expr
= c_parser_expression (parser
).value
;
13342 ret
.original_type
= TREE_TYPE (expr
);
13343 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13344 if (this_in
& TM_STMT_ATTR_RELAXED
)
13345 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13346 SET_EXPR_LOCATION (ret
.value
, loc
);
13347 ret
.original_code
= TRANSACTION_EXPR
;
13348 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13350 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13357 ret
.value
= error_mark_node
;
13358 ret
.original_code
= ERROR_MARK
;
13359 ret
.original_type
= NULL
;
13361 parser
->in_transaction
= old_in
;
13364 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13365 "%<__transaction_atomic%> without transactional memory support enabled"
13366 : "%<__transaction_relaxed %> "
13367 "without transactional memory support enabled"));
13372 /* Parse a __transaction_cancel statement (GCC Extension).
13374 transaction-cancel-statement:
13375 __transaction_cancel transaction-attribute[opt] ;
13377 Note that the only valid attribute is "outer".
13381 c_parser_transaction_cancel (c_parser
*parser
)
13383 location_t loc
= c_parser_peek_token (parser
)->location
;
13385 bool is_outer
= false;
13387 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
13388 c_parser_consume_token (parser
);
13390 attrs
= c_parser_transaction_attributes (parser
);
13392 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
13396 error_at (loc
, "%<__transaction_cancel%> without "
13397 "transactional memory support enabled");
13400 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
13402 error_at (loc
, "%<__transaction_cancel%> within a "
13403 "%<__transaction_relaxed%>");
13408 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
13409 && !is_tm_may_cancel_outer (current_function_decl
))
13411 error_at (loc
, "outer %<__transaction_cancel%> not "
13412 "within outer %<__transaction_atomic%>");
13413 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
13417 else if (parser
->in_transaction
== 0)
13419 error_at (loc
, "%<__transaction_cancel%> not within "
13420 "%<__transaction_atomic%>");
13424 return add_stmt (build_tm_abort_call (loc
, is_outer
));
13427 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
13430 /* Parse a single source file. */
13433 c_parse_file (void)
13435 /* Use local storage to begin. If the first token is a pragma, parse it.
13436 If it is #pragma GCC pch_preprocess, then this will load a PCH file
13437 which will cause garbage collection. */
13440 memset (&tparser
, 0, sizeof tparser
);
13441 tparser
.tokens
= &tparser
.tokens_buf
[0];
13442 the_parser
= &tparser
;
13444 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
13445 c_parser_pragma_pch_preprocess (&tparser
);
13447 the_parser
= ggc_alloc_c_parser ();
13448 *the_parser
= tparser
;
13449 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
13450 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
13452 /* Initialize EH, if we've been told to do so. */
13453 if (flag_exceptions
)
13454 using_eh_for_cleanups ();
13456 c_parser_translation_unit (the_parser
);
13460 /* This function parses Cilk Plus array notation. The starting index is
13461 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
13462 return value of this function is a tree_node called VALUE_TREE of type
13463 ARRAY_NOTATION_REF. */
13466 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
13469 c_token
*token
= NULL
;
13470 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
13471 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
13472 tree array_type_domain
= NULL_TREE
;
13474 if (array_value
== error_mark_node
)
13476 /* No need to continue. If either of these 2 were true, then an error
13477 must be emitted already. Thus, no need to emit them twice. */
13478 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13479 return error_mark_node
;
13482 array_type
= TREE_TYPE (array_value
);
13483 gcc_assert (array_type
);
13484 type
= TREE_TYPE (array_type
);
13485 token
= c_parser_peek_token (parser
);
13487 if (token
->type
== CPP_EOF
)
13489 c_parser_error (parser
, "expected %<:%> or numeral");
13492 else if (token
->type
== CPP_COLON
)
13494 if (!initial_index
)
13496 /* If we are here, then we have a case like this A[:]. */
13497 c_parser_consume_token (parser
);
13498 if (TREE_CODE (array_type
) == POINTER_TYPE
)
13500 error_at (loc
, "start-index and length fields necessary for "
13501 "using array notations in pointers");
13502 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13503 return error_mark_node
;
13505 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13507 error_at (loc
, "array notations cannot be used with function "
13509 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13510 return error_mark_node
;
13512 array_type_domain
= TYPE_DOMAIN (array_type
);
13514 if (!array_type_domain
)
13516 error_at (loc
, "start-index and length fields necessary for "
13517 "using array notations in dimensionless arrays");
13518 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13519 return error_mark_node
;
13522 start_index
= TYPE_MINVAL (array_type_domain
);
13523 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
13525 if (!TYPE_MAXVAL (array_type_domain
)
13526 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
13528 error_at (loc
, "start-index and length fields necessary for "
13529 "using array notations in variable-length arrays");
13530 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13531 return error_mark_node
;
13533 end_index
= TYPE_MAXVAL (array_type_domain
);
13534 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
13535 end_index
, integer_one_node
);
13536 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
13537 stride
= build_int_cst (integer_type_node
, 1);
13538 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
13540 else if (initial_index
!= error_mark_node
)
13542 /* If we are here, then there should be 2 possibilities:
13543 1. Array [EXPR : EXPR]
13544 2. Array [EXPR : EXPR : EXPR]
13546 start_index
= initial_index
;
13548 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
13550 error_at (loc
, "array notations cannot be used with function "
13552 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
13553 return error_mark_node
;
13555 c_parser_consume_token (parser
); /* consume the ':' */
13556 struct c_expr ce
= c_parser_expression (parser
);
13557 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
13558 end_index
= ce
.value
;
13559 if (!end_index
|| end_index
== error_mark_node
)
13561 c_parser_skip_to_end_of_block_or_statement (parser
);
13562 return error_mark_node
;
13564 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
13566 c_parser_consume_token (parser
);
13567 ce
= c_parser_expression (parser
);
13568 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
13570 if (!stride
|| stride
== error_mark_node
)
13572 c_parser_skip_to_end_of_block_or_statement (parser
);
13573 return error_mark_node
;
13578 c_parser_error (parser
, "expected array notation expression");
13581 c_parser_error (parser
, "expected array notation expression");
13583 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13585 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
13586 end_index
, stride
, type
);
13587 if (value_tree
!= error_mark_node
)
13588 SET_EXPR_LOCATION (value_tree
, loc
);
13592 #include "gt-c-c-parser.h"