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"
51 #include "c-family/c-common.h"
52 #include "c-family/c-objc.h"
53 #include "c-family/c-upc.h"
59 #include "upc/upc-tree.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
73 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
74 the c_token structure. */
75 gcc_assert (RID_MAX
<= 255);
82 mask
|= D_ASM
| D_EXT
;
86 if (!c_dialect_objc ())
87 mask
|= D_OBJC
| D_CXX_OBJC
;
89 if (!c_dialect_upc ())
92 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
93 for (i
= 0; i
< num_c_common_reswords
; i
++)
95 /* If a keyword is disabled, do not enter it into the table
96 and so create a canonical spelling that isn't a keyword. */
97 if (c_common_reswords
[i
].disable
& mask
)
100 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
102 id
= get_identifier (c_common_reswords
[i
].word
);
103 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
104 C_IS_RESERVED_WORD (id
) = 1;
109 id
= get_identifier (c_common_reswords
[i
].word
);
110 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
111 C_IS_RESERVED_WORD (id
) = 1;
112 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
116 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
117 and the C parser. Unlike the C++ lexer, the parser structure
118 stores the lexer information instead of using a separate structure.
119 Identifiers are separated into ordinary identifiers, type names,
120 keywords and some other Objective-C types of identifiers, and some
121 look-ahead is maintained.
123 ??? It might be a good idea to lex the whole file up front (as for
124 C++). It would then be possible to share more of the C and C++
125 lexer code, if desired. */
127 /* The following local token type is used. */
130 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
132 /* More information about the type of a CPP_NAME token. */
133 typedef enum c_id_kind
{
134 /* An ordinary identifier. */
136 /* An identifier declared as a typedef name. */
138 /* An identifier declared as an Objective-C class name. */
140 /* An address space identifier. */
142 /* Not an identifier. */
146 /* A single C token after string literal concatenation and conversion
147 of preprocessing tokens to tokens. */
148 typedef struct GTY (()) c_token
{
149 /* The kind of token. */
150 ENUM_BITFIELD (cpp_ttype
) type
: 8;
151 /* If this token is a CPP_NAME, this value indicates whether also
152 declared as some kind of type. Otherwise, it is C_ID_NONE. */
153 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
154 /* If this token is a keyword, this value indicates which keyword.
155 Otherwise, this value is RID_MAX. */
156 ENUM_BITFIELD (rid
) keyword
: 8;
157 /* If this token is a CPP_PRAGMA, this indicates the pragma that
158 was seen. Otherwise it is PRAGMA_NONE. */
159 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
160 /* The location at which this token was found. */
162 /* The value associated with this token, if any. */
166 /* A parser structure recording information about the state and
167 context of parsing. Includes lexer information with up to two
168 tokens of look-ahead; more are not needed for C. */
169 typedef struct GTY(()) c_parser
{
170 /* The look-ahead tokens. */
172 /* How many look-ahead tokens are available (0, 1 or 2). */
174 /* True if a syntax error is being recovered from; false otherwise.
175 c_parser_error sets this flag. It should clear this flag when
176 enough tokens have been consumed to recover from the error. */
177 BOOL_BITFIELD error
: 1;
178 /* True if we're processing a pragma, and shouldn't automatically
179 consume CPP_PRAGMA_EOL. */
180 BOOL_BITFIELD in_pragma
: 1;
181 /* True if we're parsing the outermost block of an if statement. */
182 BOOL_BITFIELD in_if_block
: 1;
183 /* True if we want to lex an untranslated string. */
184 BOOL_BITFIELD lex_untranslated_string
: 1;
186 /* Objective-C specific parser/lexer information. */
188 /* True if we are in a context where the Objective-C "PQ" keywords
189 are considered keywords. */
190 BOOL_BITFIELD objc_pq_context
: 1;
191 /* True if we are parsing a (potential) Objective-C foreach
192 statement. This is set to true after we parsed 'for (' and while
193 we wait for 'in' or ';' to decide if it's a standard C for loop or an
194 Objective-C foreach loop. */
195 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
196 /* The following flag is needed to contextualize Objective-C lexical
197 analysis. In some cases (e.g., 'int NSObject;'), it is
198 undesirable to bind an identifier to an Objective-C class, even
199 if a class with that name exists. */
200 BOOL_BITFIELD objc_need_raw_identifier
: 1;
201 /* Nonzero if we're processing a __transaction statement. The value
202 is 1 | TM_STMT_ATTR_*. */
203 unsigned int in_transaction
: 4;
204 /* True if we are in a context where the Objective-C "Property attribute"
205 keywords are valid. */
206 BOOL_BITFIELD objc_property_attr_context
: 1;
210 /* The actual parser and external interface. ??? Does this need to be
211 garbage-collected? */
213 static GTY (()) c_parser
*the_parser
;
215 /* Read in and lex a single token, storing it in *TOKEN. */
218 c_lex_one_token (c_parser
*parser
, c_token
*token
)
220 timevar_push (TV_LEX
);
222 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
223 (parser
->lex_untranslated_string
224 ? C_LEX_STRING_NO_TRANSLATE
: 0));
225 token
->id_kind
= C_ID_NONE
;
226 token
->keyword
= RID_MAX
;
227 token
->pragma_kind
= PRAGMA_NONE
;
235 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
236 if (c_dialect_objc ())
237 parser
->objc_need_raw_identifier
= false;
239 if (C_IS_RESERVED_WORD (token
->value
))
241 enum rid rid_code
= C_RID_CODE (token
->value
);
243 if (rid_code
== RID_CXX_COMPAT_WARN
)
245 warning_at (token
->location
,
247 "identifier %qE conflicts with C++ keyword",
250 else if (rid_code
>= RID_FIRST_ADDR_SPACE
251 && rid_code
<= RID_LAST_ADDR_SPACE
)
253 token
->id_kind
= C_ID_ADDRSPACE
;
254 token
->keyword
= rid_code
;
257 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
259 /* We found an Objective-C "pq" keyword (in, out,
260 inout, bycopy, byref, oneway). They need special
261 care because the interpretation depends on the
263 if (parser
->objc_pq_context
)
265 token
->type
= CPP_KEYWORD
;
266 token
->keyword
= rid_code
;
269 else if (parser
->objc_could_be_foreach_context
270 && rid_code
== RID_IN
)
272 /* We are in Objective-C, inside a (potential)
273 foreach context (which means after having
274 parsed 'for (', but before having parsed ';'),
275 and we found 'in'. We consider it the keyword
276 which terminates the declaration at the
277 beginning of a foreach-statement. Note that
278 this means you can't use 'in' for anything else
279 in that context; in particular, in Objective-C
280 you can't use 'in' as the name of the running
281 variable in a C for loop. We could potentially
282 try to add code here to disambiguate, but it
283 seems a reasonable limitation. */
284 token
->type
= CPP_KEYWORD
;
285 token
->keyword
= rid_code
;
288 /* Else, "pq" keywords outside of the "pq" context are
289 not keywords, and we fall through to the code for
292 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
294 /* We found an Objective-C "property attribute"
295 keyword (getter, setter, readonly, etc). These are
296 only valid in the property context. */
297 if (parser
->objc_property_attr_context
)
299 token
->type
= CPP_KEYWORD
;
300 token
->keyword
= rid_code
;
303 /* Else they are not special keywords.
306 else if (c_dialect_objc ()
307 && (OBJC_IS_AT_KEYWORD (rid_code
)
308 || OBJC_IS_CXX_KEYWORD (rid_code
)))
310 /* We found one of the Objective-C "@" keywords (defs,
311 selector, synchronized, etc) or one of the
312 Objective-C "cxx" keywords (class, private,
313 protected, public, try, catch, throw) without a
314 preceding '@' sign. Do nothing and fall through to
315 the code for normal tokens (in C++ we would still
316 consider the CXX ones keywords, but not in C). */
321 token
->type
= CPP_KEYWORD
;
322 token
->keyword
= rid_code
;
327 decl
= lookup_name (token
->value
);
330 if (TREE_CODE (decl
) == TYPE_DECL
)
332 token
->id_kind
= C_ID_TYPENAME
;
336 else if (c_dialect_objc ())
338 tree objc_interface_decl
= objc_is_class_name (token
->value
);
339 /* Objective-C class names are in the same namespace as
340 variables and typedefs, and hence are shadowed by local
342 if (objc_interface_decl
343 && (!objc_force_identifier
|| global_bindings_p ()))
345 token
->value
= objc_interface_decl
;
346 token
->id_kind
= C_ID_CLASSNAME
;
350 token
->id_kind
= C_ID_ID
;
354 /* This only happens in Objective-C; it must be a keyword. */
355 token
->type
= CPP_KEYWORD
;
356 switch (C_RID_CODE (token
->value
))
358 /* Replace 'class' with '@class', 'private' with '@private',
359 etc. This prevents confusion with the C++ keyword
360 'class', and makes the tokens consistent with other
361 Objective-C 'AT' keywords. For example '@class' is
362 reported as RID_AT_CLASS which is consistent with
363 '@synchronized', which is reported as
366 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
367 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
368 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
369 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
370 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
371 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
372 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
373 default: token
->keyword
= C_RID_CODE (token
->value
);
378 case CPP_CLOSE_PAREN
:
380 /* These tokens may affect the interpretation of any identifiers
381 following, if doing Objective-C. */
382 if (c_dialect_objc ())
383 parser
->objc_need_raw_identifier
= false;
386 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
387 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
393 timevar_pop (TV_LEX
);
396 /* Return a pointer to the next token from PARSER, reading it in if
399 static inline c_token
*
400 c_parser_peek_token (c_parser
*parser
)
402 if (parser
->tokens_avail
== 0)
404 c_lex_one_token (parser
, &parser
->tokens
[0]);
405 parser
->tokens_avail
= 1;
407 return &parser
->tokens
[0];
410 /* Return true if the next token from PARSER has the indicated
414 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
416 return c_parser_peek_token (parser
)->type
== type
;
419 /* Return true if the next token from PARSER does not have the
423 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
425 return !c_parser_next_token_is (parser
, type
);
428 /* Return true if the next token from PARSER is the indicated
432 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
434 return c_parser_peek_token (parser
)->keyword
== keyword
;
437 /* Return a pointer to the next-but-one token from PARSER, reading it
438 in if necessary. The next token is already read in. */
441 c_parser_peek_2nd_token (c_parser
*parser
)
443 if (parser
->tokens_avail
>= 2)
444 return &parser
->tokens
[1];
445 gcc_assert (parser
->tokens_avail
== 1);
446 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
447 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
448 c_lex_one_token (parser
, &parser
->tokens
[1]);
449 parser
->tokens_avail
= 2;
450 return &parser
->tokens
[1];
453 /* Return true if TOKEN can start a type name,
456 c_token_starts_typename (c_token
*token
)
461 switch (token
->id_kind
)
470 gcc_assert (c_dialect_objc ());
476 switch (token
->keyword
)
514 if (c_dialect_objc ())
522 enum c_lookahead_kind
{
523 /* Always treat unknown identifiers as typenames. */
526 /* Could be parsing a nonabstract declarator. Only treat an identifier
527 as a typename if followed by another identifier or a star. */
528 cla_nonabstract_decl
,
530 /* Never treat identifiers as typenames. */
534 /* Return true if the next token from PARSER can start a type name,
535 false otherwise. LA specifies how to do lookahead in order to
536 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
539 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
541 c_token
*token
= c_parser_peek_token (parser
);
542 if (c_token_starts_typename (token
))
545 /* Try a bit harder to detect an unknown typename. */
546 if (la
!= cla_prefer_id
547 && token
->type
== CPP_NAME
548 && token
->id_kind
== C_ID_ID
550 /* Do not try too hard when we could have "object in array". */
551 && !parser
->objc_could_be_foreach_context
553 && (la
== cla_prefer_type
554 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
555 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
557 /* Only unknown identifiers. */
558 && !lookup_name (token
->value
))
564 /* Return true if TOKEN is a type qualifier, false otherwise. */
566 c_token_is_qualifier (c_token
*token
)
571 switch (token
->id_kind
)
579 switch (token
->keyword
)
601 /* Return true if the next token from PARSER is a type qualifier,
604 c_parser_next_token_is_qualifier (c_parser
*parser
)
606 c_token
*token
= c_parser_peek_token (parser
);
607 return c_token_is_qualifier (token
);
610 /* Return true if TOKEN can start declaration specifiers, false
613 c_token_starts_declspecs (c_token
*token
)
618 switch (token
->id_kind
)
627 gcc_assert (c_dialect_objc ());
633 switch (token
->keyword
)
680 if (c_dialect_objc ())
689 /* Return true if TOKEN can start declaration specifiers or a static
690 assertion, false otherwise. */
692 c_token_starts_declaration (c_token
*token
)
694 if (c_token_starts_declspecs (token
)
695 || token
->keyword
== RID_STATIC_ASSERT
)
701 /* Return true if the next token from PARSER can start declaration
702 specifiers, false otherwise. */
704 c_parser_next_token_starts_declspecs (c_parser
*parser
)
706 c_token
*token
= c_parser_peek_token (parser
);
708 /* In Objective-C, a classname normally starts a declspecs unless it
709 is immediately followed by a dot. In that case, it is the
710 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
711 setter/getter on the class. c_token_starts_declspecs() can't
712 differentiate between the two cases because it only checks the
713 current token, so we have a special check here. */
714 if (c_dialect_objc ()
715 && token
->type
== CPP_NAME
716 && token
->id_kind
== C_ID_CLASSNAME
717 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
720 return c_token_starts_declspecs (token
);
723 /* Return true if the next tokens from PARSER can start declaration
724 specifiers or a static assertion, false otherwise. */
726 c_parser_next_tokens_start_declaration (c_parser
*parser
)
728 c_token
*token
= c_parser_peek_token (parser
);
731 if (c_dialect_objc ()
732 && token
->type
== CPP_NAME
733 && token
->id_kind
== C_ID_CLASSNAME
734 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
737 /* Labels do not start declarations. */
738 if (token
->type
== CPP_NAME
739 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
742 if (c_token_starts_declaration (token
))
745 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
751 /* Consume the next token from PARSER. */
754 c_parser_consume_token (c_parser
*parser
)
756 gcc_assert (parser
->tokens_avail
>= 1);
757 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
758 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
759 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
760 if (parser
->tokens_avail
== 2)
761 parser
->tokens
[0] = parser
->tokens
[1];
762 parser
->tokens_avail
--;
765 /* Expect the current token to be a #pragma. Consume it and remember
766 that we've begun parsing a pragma. */
769 c_parser_consume_pragma (c_parser
*parser
)
771 gcc_assert (!parser
->in_pragma
);
772 gcc_assert (parser
->tokens_avail
>= 1);
773 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
774 if (parser
->tokens_avail
== 2)
775 parser
->tokens
[0] = parser
->tokens
[1];
776 parser
->tokens_avail
--;
777 parser
->in_pragma
= true;
780 /* Update the globals input_location and in_system_header from
783 c_parser_set_source_position_from_token (c_token
*token
)
785 if (token
->type
!= CPP_EOF
)
787 input_location
= token
->location
;
791 /* Issue a diagnostic of the form
792 FILE:LINE: MESSAGE before TOKEN
793 where TOKEN is the next token in the input stream of PARSER.
794 MESSAGE (specified by the caller) is usually of the form "expected
797 Do not issue a diagnostic if still recovering from an error.
799 ??? This is taken from the C++ parser, but building up messages in
800 this way is not i18n-friendly and some other approach should be
804 c_parser_error (c_parser
*parser
, const char *gmsgid
)
806 c_token
*token
= c_parser_peek_token (parser
);
809 parser
->error
= true;
812 /* This diagnostic makes more sense if it is tagged to the line of
813 the token we just peeked at. */
814 c_parser_set_source_position_from_token (token
);
815 c_parse_error (gmsgid
,
816 /* Because c_parse_error does not understand
817 CPP_KEYWORD, keywords are treated like
819 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
820 /* ??? The C parser does not save the cpp flags of a
821 token, we need to pass 0 here and we will not get
822 the source spelling of some tokens but rather the
823 canonical spelling. */
824 token
->value
, /*flags=*/0);
827 /* If the next token is of the indicated TYPE, consume it. Otherwise,
828 issue the error MSGID. If MSGID is NULL then a message has already
829 been produced and no message will be produced this time. Returns
830 true if found, false otherwise. */
833 c_parser_require (c_parser
*parser
,
837 if (c_parser_next_token_is (parser
, type
))
839 c_parser_consume_token (parser
);
844 c_parser_error (parser
, msgid
);
849 /* If the next token is the indicated keyword, consume it. Otherwise,
850 issue the error MSGID. Returns true if found, false otherwise. */
853 c_parser_require_keyword (c_parser
*parser
,
857 if (c_parser_next_token_is_keyword (parser
, keyword
))
859 c_parser_consume_token (parser
);
864 c_parser_error (parser
, msgid
);
869 /* Like c_parser_require, except that tokens will be skipped until the
870 desired token is found. An error message is still produced if the
871 next token is not as expected. If MSGID is NULL then a message has
872 already been produced and no message will be produced this
876 c_parser_skip_until_found (c_parser
*parser
,
880 unsigned nesting_depth
= 0;
882 if (c_parser_require (parser
, type
, msgid
))
885 /* Skip tokens until the desired token is found. */
888 /* Peek at the next token. */
889 c_token
*token
= c_parser_peek_token (parser
);
890 /* If we've reached the token we want, consume it and stop. */
891 if (token
->type
== type
&& !nesting_depth
)
893 c_parser_consume_token (parser
);
897 /* If we've run out of tokens, stop. */
898 if (token
->type
== CPP_EOF
)
900 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
902 if (token
->type
== CPP_OPEN_BRACE
903 || token
->type
== CPP_OPEN_PAREN
904 || token
->type
== CPP_OPEN_SQUARE
)
906 else if (token
->type
== CPP_CLOSE_BRACE
907 || token
->type
== CPP_CLOSE_PAREN
908 || token
->type
== CPP_CLOSE_SQUARE
)
910 if (nesting_depth
-- == 0)
913 /* Consume this token. */
914 c_parser_consume_token (parser
);
916 parser
->error
= false;
919 /* Skip tokens until the end of a parameter is found, but do not
920 consume the comma, semicolon or closing delimiter. */
923 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
925 unsigned nesting_depth
= 0;
929 c_token
*token
= c_parser_peek_token (parser
);
930 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
933 /* If we've run out of tokens, stop. */
934 if (token
->type
== CPP_EOF
)
936 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
938 if (token
->type
== CPP_OPEN_BRACE
939 || token
->type
== CPP_OPEN_PAREN
940 || token
->type
== CPP_OPEN_SQUARE
)
942 else if (token
->type
== CPP_CLOSE_BRACE
943 || token
->type
== CPP_CLOSE_PAREN
944 || token
->type
== CPP_CLOSE_SQUARE
)
946 if (nesting_depth
-- == 0)
949 /* Consume this token. */
950 c_parser_consume_token (parser
);
952 parser
->error
= false;
955 /* Expect to be at the end of the pragma directive and consume an
956 end of line marker. */
959 c_parser_skip_to_pragma_eol (c_parser
*parser
)
961 gcc_assert (parser
->in_pragma
);
962 parser
->in_pragma
= false;
964 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
967 c_token
*token
= c_parser_peek_token (parser
);
968 if (token
->type
== CPP_EOF
)
970 if (token
->type
== CPP_PRAGMA_EOL
)
972 c_parser_consume_token (parser
);
975 c_parser_consume_token (parser
);
978 parser
->error
= false;
981 /* Skip tokens until we have consumed an entire block, or until we
982 have consumed a non-nested ';'. */
985 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
987 unsigned nesting_depth
= 0;
988 bool save_error
= parser
->error
;
994 /* Peek at the next token. */
995 token
= c_parser_peek_token (parser
);
1002 case CPP_PRAGMA_EOL
:
1003 if (parser
->in_pragma
)
1008 /* If the next token is a ';', we have reached the
1009 end of the statement. */
1012 /* Consume the ';'. */
1013 c_parser_consume_token (parser
);
1018 case CPP_CLOSE_BRACE
:
1019 /* If the next token is a non-nested '}', then we have
1020 reached the end of the current block. */
1021 if (nesting_depth
== 0 || --nesting_depth
== 0)
1023 c_parser_consume_token (parser
);
1028 case CPP_OPEN_BRACE
:
1029 /* If it the next token is a '{', then we are entering a new
1030 block. Consume the entire block. */
1035 /* If we see a pragma, consume the whole thing at once. We
1036 have some safeguards against consuming pragmas willy-nilly.
1037 Normally, we'd expect to be here with parser->error set,
1038 which disables these safeguards. But it's possible to get
1039 here for secondary error recovery, after parser->error has
1041 c_parser_consume_pragma (parser
);
1042 c_parser_skip_to_pragma_eol (parser
);
1043 parser
->error
= save_error
;
1050 c_parser_consume_token (parser
);
1054 parser
->error
= false;
1057 /* CPP's options (initialized by c-opts.c). */
1058 extern cpp_options
*cpp_opts
;
1060 /* Save the warning flags which are controlled by __extension__. */
1063 disable_extension_diagnostics (void)
1066 | (warn_pointer_arith
<< 1)
1067 | (warn_traditional
<< 2)
1069 | (warn_long_long
<< 4)
1070 | (warn_cxx_compat
<< 5)
1071 | (warn_overlength_strings
<< 6));
1072 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1073 warn_pointer_arith
= 0;
1074 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1076 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1077 warn_cxx_compat
= 0;
1078 warn_overlength_strings
= 0;
1082 /* Restore the warning flags which are controlled by __extension__.
1083 FLAGS is the return value from disable_extension_diagnostics. */
1086 restore_extension_diagnostics (int flags
)
1088 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1089 warn_pointer_arith
= (flags
>> 1) & 1;
1090 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1091 flag_iso
= (flags
>> 3) & 1;
1092 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1093 warn_cxx_compat
= (flags
>> 5) & 1;
1094 warn_overlength_strings
= (flags
>> 6) & 1;
1097 /* Possibly kinds of declarator to parse. */
1098 typedef enum c_dtr_syn
{
1099 /* A normal declarator with an identifier. */
1101 /* An abstract declarator (maybe empty). */
1103 /* A parameter declarator: may be either, but after a type name does
1104 not redeclare a typedef name as an identifier if it can
1105 alternatively be interpreted as a typedef name; see DR#009,
1106 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1107 following DR#249. For example, given a typedef T, "int T" and
1108 "int *T" are valid parameter declarations redeclaring T, while
1109 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1110 abstract declarators rather than involving redundant parentheses;
1111 the same applies with attributes inside the parentheses before
1116 /* The binary operation precedence levels, where 0 is a dummy lowest level
1117 used for the bottom of the stack. */
1118 enum c_parser_prec
{
1133 static void c_parser_external_declaration (c_parser
*);
1134 static void c_parser_asm_definition (c_parser
*);
1135 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1136 bool, bool, tree
*);
1137 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1138 static void c_parser_static_assert_declaration (c_parser
*);
1139 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1140 bool, enum c_lookahead_kind
);
1141 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1142 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1143 static tree
c_parser_struct_declaration (c_parser
*);
1144 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1145 static tree
c_parser_alignas_specifier (c_parser
*);
1146 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1148 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1150 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1152 struct c_declarator
*);
1153 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1154 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1156 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1157 static tree
c_parser_simple_asm_expr (c_parser
*);
1158 static tree
c_parser_attributes (c_parser
*);
1159 static struct c_type_name
*c_parser_type_name (c_parser
*);
1160 static struct c_expr
c_parser_initializer (c_parser
*);
1161 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1162 static void c_parser_initelt (c_parser
*, struct obstack
*);
1163 static void c_parser_initval (c_parser
*, struct c_expr
*,
1165 static tree
c_parser_compound_statement (c_parser
*);
1166 static void c_parser_compound_statement_nostart (c_parser
*);
1167 static void c_parser_label (c_parser
*);
1168 static void c_parser_statement (c_parser
*);
1169 static void c_parser_statement_after_labels (c_parser
*);
1170 static void c_parser_if_statement (c_parser
*);
1171 static void c_parser_switch_statement (c_parser
*);
1172 static void c_parser_while_statement (c_parser
*);
1173 static void c_parser_do_statement (c_parser
*);
1174 static void c_parser_for_statement (c_parser
*);
1175 static tree
c_parser_asm_statement (c_parser
*);
1176 static tree
c_parser_asm_operands (c_parser
*);
1177 static tree
c_parser_asm_goto_operands (c_parser
*);
1178 static tree
c_parser_asm_clobbers (c_parser
*);
1179 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1180 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1182 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1183 enum c_parser_prec
);
1184 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1185 static struct c_expr
c_parser_unary_expression (c_parser
*);
1186 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1187 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1188 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1189 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1190 struct c_type_name
*,
1192 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1195 static tree
c_parser_transaction (c_parser
*, enum rid
);
1196 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1197 static tree
c_parser_transaction_cancel (c_parser
*);
1198 static struct c_expr
c_parser_expression (c_parser
*);
1199 static struct c_expr
c_parser_expression_conv (c_parser
*);
1200 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1201 vec
<tree
, va_gc
> **, location_t
*,
1203 static void c_parser_omp_construct (c_parser
*);
1204 static void c_parser_omp_threadprivate (c_parser
*);
1205 static void c_parser_omp_barrier (c_parser
*);
1206 static void c_parser_omp_flush (c_parser
*);
1207 static void c_parser_omp_taskwait (c_parser
*);
1208 static void c_parser_omp_taskyield (c_parser
*);
1210 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1211 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1213 /* These Objective-C parser functions are only ever called when
1214 compiling Objective-C. */
1215 static void c_parser_objc_class_definition (c_parser
*, tree
);
1216 static void c_parser_objc_class_instance_variables (c_parser
*);
1217 static void c_parser_objc_class_declaration (c_parser
*);
1218 static void c_parser_objc_alias_declaration (c_parser
*);
1219 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1220 static bool c_parser_objc_method_type (c_parser
*);
1221 static void c_parser_objc_method_definition (c_parser
*);
1222 static void c_parser_objc_methodprotolist (c_parser
*);
1223 static void c_parser_objc_methodproto (c_parser
*);
1224 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1225 static tree
c_parser_objc_type_name (c_parser
*);
1226 static tree
c_parser_objc_protocol_refs (c_parser
*);
1227 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1228 static void c_parser_objc_synchronized_statement (c_parser
*);
1229 static tree
c_parser_objc_selector (c_parser
*);
1230 static tree
c_parser_objc_selector_arg (c_parser
*);
1231 static tree
c_parser_objc_receiver (c_parser
*);
1232 static tree
c_parser_objc_message_args (c_parser
*);
1233 static tree
c_parser_objc_keywordexpr (c_parser
*);
1234 static void c_parser_objc_at_property_declaration (c_parser
*);
1235 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1236 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1237 static bool c_parser_objc_diagnose_bad_element_prefix
1238 (c_parser
*, struct c_declspecs
*);
1240 /* These UPC parser functions are only ever called when
1242 static void c_parser_upc_forall_statement (c_parser
*);
1243 static void c_parser_upc_sync_statement (c_parser
*, int);
1244 static void c_parser_upc_shared_qual (source_location
,
1246 struct c_declspecs
*);
1248 /* Parse a translation unit (C90 6.7, C99 6.9).
1251 external-declarations
1253 external-declarations:
1254 external-declaration
1255 external-declarations external-declaration
1264 c_parser_translation_unit (c_parser
*parser
)
1266 if (c_parser_next_token_is (parser
, CPP_EOF
))
1268 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1269 "ISO C forbids an empty translation unit");
1273 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1274 mark_valid_location_for_stdc_pragma (false);
1278 c_parser_external_declaration (parser
);
1279 obstack_free (&parser_obstack
, obstack_position
);
1281 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1285 /* Parse an external declaration (C90 6.7, C99 6.9).
1287 external-declaration:
1293 external-declaration:
1296 __extension__ external-declaration
1300 external-declaration:
1301 objc-class-definition
1302 objc-class-declaration
1303 objc-alias-declaration
1304 objc-protocol-definition
1305 objc-method-definition
1310 c_parser_external_declaration (c_parser
*parser
)
1313 switch (c_parser_peek_token (parser
)->type
)
1316 switch (c_parser_peek_token (parser
)->keyword
)
1319 ext
= disable_extension_diagnostics ();
1320 c_parser_consume_token (parser
);
1321 c_parser_external_declaration (parser
);
1322 restore_extension_diagnostics (ext
);
1325 c_parser_asm_definition (parser
);
1327 case RID_AT_INTERFACE
:
1328 case RID_AT_IMPLEMENTATION
:
1329 gcc_assert (c_dialect_objc ());
1330 c_parser_objc_class_definition (parser
, NULL_TREE
);
1333 gcc_assert (c_dialect_objc ());
1334 c_parser_objc_class_declaration (parser
);
1337 gcc_assert (c_dialect_objc ());
1338 c_parser_objc_alias_declaration (parser
);
1340 case RID_AT_PROTOCOL
:
1341 gcc_assert (c_dialect_objc ());
1342 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1344 case RID_AT_PROPERTY
:
1345 gcc_assert (c_dialect_objc ());
1346 c_parser_objc_at_property_declaration (parser
);
1348 case RID_AT_SYNTHESIZE
:
1349 gcc_assert (c_dialect_objc ());
1350 c_parser_objc_at_synthesize_declaration (parser
);
1352 case RID_AT_DYNAMIC
:
1353 gcc_assert (c_dialect_objc ());
1354 c_parser_objc_at_dynamic_declaration (parser
);
1357 gcc_assert (c_dialect_objc ());
1358 c_parser_consume_token (parser
);
1359 objc_finish_implementation ();
1366 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1367 "ISO C does not allow extra %<;%> outside of a function");
1368 c_parser_consume_token (parser
);
1371 mark_valid_location_for_stdc_pragma (true);
1372 c_parser_pragma (parser
, pragma_external
);
1373 mark_valid_location_for_stdc_pragma (false);
1377 if (c_dialect_objc ())
1379 c_parser_objc_method_definition (parser
);
1382 /* Else fall through, and yield a syntax error trying to parse
1383 as a declaration or function definition. */
1386 /* A declaration or a function definition (or, in Objective-C,
1387 an @interface or @protocol with prefix attributes). We can
1388 only tell which after parsing the declaration specifiers, if
1389 any, and the first declarator. */
1390 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1395 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1396 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1397 accepted; otherwise (old-style parameter declarations) only other
1398 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1399 assertion is accepted; otherwise (old-style parameter declarations)
1400 it is not. If NESTED is true, we are inside a function or parsing
1401 old-style parameter declarations; any functions encountered are
1402 nested functions and declaration specifiers are required; otherwise
1403 we are at top level and functions are normal functions and
1404 declaration specifiers may be optional. If EMPTY_OK is true, empty
1405 declarations are OK (subject to all other constraints); otherwise
1406 (old-style parameter declarations) they are diagnosed. If
1407 START_ATTR_OK is true, the declaration specifiers may start with
1408 attributes; otherwise they may not.
1409 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1410 declaration when parsing an Objective-C foreach statement.
1413 declaration-specifiers init-declarator-list[opt] ;
1414 static_assert-declaration
1416 function-definition:
1417 declaration-specifiers[opt] declarator declaration-list[opt]
1422 declaration-list declaration
1424 init-declarator-list:
1426 init-declarator-list , init-declarator
1429 declarator simple-asm-expr[opt] attributes[opt]
1430 declarator simple-asm-expr[opt] attributes[opt] = initializer
1434 nested-function-definition:
1435 declaration-specifiers declarator declaration-list[opt]
1439 attributes objc-class-definition
1440 attributes objc-category-definition
1441 attributes objc-protocol-definition
1443 The simple-asm-expr and attributes are GNU extensions.
1445 This function does not handle __extension__; that is handled in its
1446 callers. ??? Following the old parser, __extension__ may start
1447 external declarations, declarations in functions and declarations
1448 at the start of "for" loops, but not old-style parameter
1451 C99 requires declaration specifiers in a function definition; the
1452 absence is diagnosed through the diagnosis of implicit int. In GNU
1453 C we also allow but diagnose declarations without declaration
1454 specifiers, but only at top level (elsewhere they conflict with
1457 In Objective-C, declarations of the looping variable in a foreach
1458 statement are exceptionally terminated by 'in' (for example, 'for
1459 (NSObject *object in array) { ... }').
1464 threadprivate-directive */
1467 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1468 bool static_assert_ok
, bool empty_ok
,
1469 bool nested
, bool start_attr_ok
,
1470 tree
*objc_foreach_object_declaration
)
1472 struct c_declspecs
*specs
;
1474 tree all_prefix_attrs
;
1475 bool diagnosed_no_specs
= false;
1476 location_t here
= c_parser_peek_token (parser
)->location
;
1478 if (static_assert_ok
1479 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1481 c_parser_static_assert_declaration (parser
);
1484 specs
= build_null_declspecs ();
1486 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1487 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1488 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1489 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1490 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1491 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1493 error_at (here
, "unknown type name %qE",
1494 c_parser_peek_token (parser
)->value
);
1496 /* Parse declspecs normally to get a correct pointer type, but avoid
1497 a further "fails to be a type name" error. Refuse nested functions
1498 since it is not how the user likely wants us to recover. */
1499 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1500 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1501 c_parser_peek_token (parser
)->value
= error_mark_node
;
1505 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1508 c_parser_skip_to_end_of_block_or_statement (parser
);
1511 if (nested
&& !specs
->declspecs_seen_p
)
1513 c_parser_error (parser
, "expected declaration specifiers");
1514 c_parser_skip_to_end_of_block_or_statement (parser
);
1517 finish_declspecs (specs
);
1518 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1524 shadow_tag_warned (specs
, 1);
1525 pedwarn (here
, 0, "empty declaration");
1527 c_parser_consume_token (parser
);
1531 /* Provide better error recovery. Note that a type name here is usually
1532 better diagnosed as a redeclaration. */
1534 && specs
->typespec_kind
== ctsk_tagdef
1535 && c_parser_next_token_starts_declspecs (parser
)
1536 && !c_parser_next_token_is (parser
, CPP_NAME
))
1538 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1539 parser
->error
= false;
1540 shadow_tag_warned (specs
, 1);
1543 else if (c_dialect_objc ())
1545 /* Prefix attributes are an error on method decls. */
1546 switch (c_parser_peek_token (parser
)->type
)
1550 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1554 warning_at (c_parser_peek_token (parser
)->location
,
1556 "prefix attributes are ignored for methods");
1557 specs
->attrs
= NULL_TREE
;
1560 c_parser_objc_method_definition (parser
);
1562 c_parser_objc_methodproto (parser
);
1568 /* This is where we parse 'attributes @interface ...',
1569 'attributes @implementation ...', 'attributes @protocol ...'
1570 (where attributes could be, for example, __attribute__
1573 switch (c_parser_peek_token (parser
)->keyword
)
1575 case RID_AT_INTERFACE
:
1577 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1579 c_parser_objc_class_definition (parser
, specs
->attrs
);
1583 case RID_AT_IMPLEMENTATION
:
1585 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1589 warning_at (c_parser_peek_token (parser
)->location
,
1591 "prefix attributes are ignored for implementations");
1592 specs
->attrs
= NULL_TREE
;
1594 c_parser_objc_class_definition (parser
, NULL_TREE
);
1598 case RID_AT_PROTOCOL
:
1600 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1602 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1609 case RID_AT_PROPERTY
:
1612 c_parser_error (parser
, "unexpected attribute");
1613 specs
->attrs
= NULL
;
1621 pending_xref_error ();
1622 prefix_attrs
= specs
->attrs
;
1623 all_prefix_attrs
= prefix_attrs
;
1624 specs
->attrs
= NULL_TREE
;
1627 struct c_declarator
*declarator
;
1631 /* Declaring either one or more declarators (in which case we
1632 should diagnose if there were no declaration specifiers) or a
1633 function definition (in which case the diagnostic for
1634 implicit int suffices). */
1635 declarator
= c_parser_declarator (parser
,
1636 specs
->typespec_kind
!= ctsk_none
,
1637 C_DTR_NORMAL
, &dummy
);
1638 if (declarator
== NULL
)
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 start_init (d
, asm_name
, global_bindings_p ());
1677 init_loc
= c_parser_peek_token (parser
)->location
;
1678 init
= c_parser_initializer (parser
);
1680 if (d
!= error_mark_node
)
1682 maybe_warn_string_init (TREE_TYPE (d
), init
);
1683 finish_decl (d
, init_loc
, init
.value
,
1684 init
.original_type
, asm_name
);
1689 tree d
= start_decl (declarator
, specs
, false,
1690 chainon (postfix_attrs
,
1693 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1694 NULL_TREE
, asm_name
);
1696 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1699 *objc_foreach_object_declaration
= d
;
1701 *objc_foreach_object_declaration
= error_mark_node
;
1704 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1706 c_parser_consume_token (parser
);
1707 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1708 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1711 all_prefix_attrs
= prefix_attrs
;
1714 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1716 c_parser_consume_token (parser
);
1719 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1721 /* This can only happen in Objective-C: we found the
1722 'in' that terminates the declaration inside an
1723 Objective-C foreach statement. Do not consume the
1724 token, so that the caller can use it to determine
1725 that this indeed is a foreach context. */
1730 c_parser_error (parser
, "expected %<,%> or %<;%>");
1731 c_parser_skip_to_end_of_block_or_statement (parser
);
1737 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1738 "%<asm%> or %<__attribute__%>");
1739 c_parser_skip_to_end_of_block_or_statement (parser
);
1742 /* Function definition (nested or otherwise). */
1745 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1746 c_push_function_context ();
1748 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1750 /* This can appear in many cases looking nothing like a
1751 function definition, so we don't give a more specific
1752 error suggesting there was one. */
1753 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1754 "or %<__attribute__%>");
1756 c_pop_function_context ();
1760 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1761 tv
= TV_PARSE_INLINE
;
1766 /* Parse old-style parameter declarations. ??? Attributes are
1767 not allowed to start declaration specifiers here because of a
1768 syntax conflict between a function declaration with attribute
1769 suffix and a function definition with an attribute prefix on
1770 first old-style parameter declaration. Following the old
1771 parser, they are not accepted on subsequent old-style
1772 parameter declarations either. However, there is no
1773 ambiguity after the first declaration, nor indeed on the
1774 first as long as we don't allow postfix attributes after a
1775 declarator with a nonempty identifier list in a definition;
1776 and postfix attributes have never been accepted here in
1777 function definitions either. */
1778 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1779 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1780 c_parser_declaration_or_fndef (parser
, false, false, false,
1782 store_parm_decls ();
1783 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1784 = c_parser_peek_token (parser
)->location
;
1785 fnbody
= c_parser_compound_statement (parser
);
1788 tree decl
= current_function_decl
;
1789 /* Mark nested functions as needing static-chain initially.
1790 lower_nested_functions will recompute it but the
1791 DECL_STATIC_CHAIN flag is also used before that happens,
1792 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1793 DECL_STATIC_CHAIN (decl
) = 1;
1796 c_pop_function_context ();
1797 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1810 /* Parse an asm-definition (asm() outside a function body). This is a
1818 c_parser_asm_definition (c_parser
*parser
)
1820 tree asm_str
= c_parser_simple_asm_expr (parser
);
1822 add_asm_node (asm_str
);
1823 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1826 /* Parse a static assertion (C11 6.7.10).
1828 static_assert-declaration:
1829 static_assert-declaration-no-semi ;
1833 c_parser_static_assert_declaration (c_parser
*parser
)
1835 c_parser_static_assert_declaration_no_semi (parser
);
1837 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1838 c_parser_skip_to_end_of_block_or_statement (parser
);
1841 /* Parse a static assertion (C11 6.7.10), without the trailing
1844 static_assert-declaration-no-semi:
1845 _Static_assert ( constant-expression , string-literal )
1849 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1851 location_t assert_loc
, value_loc
;
1855 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1856 assert_loc
= c_parser_peek_token (parser
)->location
;
1860 pedwarn (assert_loc
, OPT_Wpedantic
,
1861 "ISO C99 does not support %<_Static_assert%>");
1863 pedwarn (assert_loc
, OPT_Wpedantic
,
1864 "ISO C90 does not support %<_Static_assert%>");
1866 c_parser_consume_token (parser
);
1867 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1869 value_loc
= c_parser_peek_token (parser
)->location
;
1870 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1871 parser
->lex_untranslated_string
= true;
1872 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1874 parser
->lex_untranslated_string
= false;
1877 switch (c_parser_peek_token (parser
)->type
)
1883 case CPP_UTF8STRING
:
1884 string
= c_parser_peek_token (parser
)->value
;
1885 c_parser_consume_token (parser
);
1886 parser
->lex_untranslated_string
= false;
1889 c_parser_error (parser
, "expected string literal");
1890 parser
->lex_untranslated_string
= false;
1893 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1895 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1897 error_at (value_loc
, "expression in static assertion is not an integer");
1900 if (TREE_CODE (value
) != INTEGER_CST
)
1902 value
= c_fully_fold (value
, false, NULL
);
1903 if (TREE_CODE (value
) == INTEGER_CST
)
1904 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1905 "is not an integer constant expression");
1907 if (TREE_CODE (value
) != INTEGER_CST
)
1909 error_at (value_loc
, "expression in static assertion is not constant");
1912 constant_expression_warning (value
);
1913 if (integer_zerop (value
))
1914 error_at (assert_loc
, "static assertion failed: %E", string
);
1917 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1918 6.7), adding them to SPECS (which may already include some).
1919 Storage class specifiers are accepted iff SCSPEC_OK; type
1920 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1921 the start iff START_ATTR_OK.
1923 declaration-specifiers:
1924 storage-class-specifier declaration-specifiers[opt]
1925 type-specifier declaration-specifiers[opt]
1926 type-qualifier declaration-specifiers[opt]
1927 function-specifier declaration-specifiers[opt]
1928 alignment-specifier declaration-specifiers[opt]
1930 Function specifiers (inline) are from C99, and are currently
1931 handled as storage class specifiers, as is __thread. Alignment
1932 specifiers are from C11.
1934 C90 6.5.1, C99 6.7.1:
1935 storage-class-specifier:
1947 (_Noreturn is new in C11.)
1949 C90 6.5.2, C99 6.7.2:
1962 [_Imaginary removed in C99 TC2]
1963 struct-or-union-specifier
1967 (_Bool and _Complex are new in C99.)
1969 C90 6.5.3, C99 6.7.3:
1975 address-space-qualifier
1977 (restrict is new in C99.)
1981 declaration-specifiers:
1982 attributes declaration-specifiers[opt]
1988 identifier recognized by the target
1990 storage-class-specifier:
2003 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2004 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2009 class-name objc-protocol-refs[opt]
2010 typedef-name objc-protocol-refs
2015 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2016 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2017 enum c_lookahead_kind la
)
2019 bool attrs_ok
= start_attr_ok
;
2020 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2023 gcc_assert (la
== cla_prefer_id
);
2025 while (c_parser_next_token_is (parser
, CPP_NAME
)
2026 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2027 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2029 struct c_typespec t
;
2032 location_t loc
= c_parser_peek_token (parser
)->location
;
2034 /* If we cannot accept a type, exit if the next token must start
2035 one. Also, if we already have seen a tagged definition,
2036 a typename would be an error anyway and likely the user
2037 has simply forgotten a semicolon, so we exit. */
2038 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2039 && c_parser_next_tokens_start_typename (parser
, la
)
2040 && !c_parser_next_token_is_qualifier (parser
))
2043 if (c_parser_next_token_is (parser
, CPP_NAME
))
2045 c_token
*name_token
= c_parser_peek_token (parser
);
2046 tree value
= name_token
->value
;
2047 c_id_kind kind
= name_token
->id_kind
;
2049 if (kind
== C_ID_ADDRSPACE
)
2052 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2053 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2054 c_parser_consume_token (parser
);
2059 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2061 /* If we cannot accept a type, and the next token must start one,
2062 exit. Do the same if we already have seen a tagged definition,
2063 since it would be an error anyway and likely the user has simply
2064 forgotten a semicolon. */
2065 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2068 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2069 a C_ID_CLASSNAME. */
2070 c_parser_consume_token (parser
);
2073 if (kind
== C_ID_ID
)
2075 error ("unknown type name %qE", value
);
2076 t
.kind
= ctsk_typedef
;
2077 t
.spec
= error_mark_node
;
2079 else if (kind
== C_ID_TYPENAME
2080 && (!c_dialect_objc ()
2081 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2083 t
.kind
= ctsk_typedef
;
2084 /* For a typedef name, record the meaning, not the name.
2085 In case of 'foo foo, bar;'. */
2086 t
.spec
= lookup_name (value
);
2090 tree proto
= NULL_TREE
;
2091 gcc_assert (c_dialect_objc ());
2093 if (c_parser_next_token_is (parser
, CPP_LESS
))
2094 proto
= c_parser_objc_protocol_refs (parser
);
2095 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2098 t
.expr_const_operands
= true;
2099 declspecs_add_type (name_token
->location
, specs
, t
);
2102 if (c_parser_next_token_is (parser
, CPP_LESS
))
2104 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2105 nisse@lysator.liu.se. */
2107 gcc_assert (c_dialect_objc ());
2108 if (!typespec_ok
|| seen_type
)
2110 proto
= c_parser_objc_protocol_refs (parser
);
2112 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2114 t
.expr_const_operands
= true;
2115 declspecs_add_type (loc
, specs
, t
);
2118 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2119 switch (c_parser_peek_token (parser
)->keyword
)
2132 /* TODO: Distinguish between function specifiers (inline, noreturn)
2133 and storage class specifiers, either here or in
2134 declspecs_add_scspec. */
2135 declspecs_add_scspec (loc
, specs
,
2136 c_parser_peek_token (parser
)->value
);
2137 c_parser_consume_token (parser
);
2161 if (c_dialect_objc ())
2162 parser
->objc_need_raw_identifier
= true;
2163 t
.kind
= ctsk_resword
;
2164 t
.spec
= c_parser_peek_token (parser
)->value
;
2166 t
.expr_const_operands
= true;
2167 declspecs_add_type (loc
, specs
, t
);
2168 c_parser_consume_token (parser
);
2175 t
= c_parser_enum_specifier (parser
);
2176 declspecs_add_type (loc
, specs
, t
);
2184 t
= c_parser_struct_or_union_specifier (parser
);
2185 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2186 declspecs_add_type (loc
, specs
, t
);
2189 /* ??? The old parser rejected typeof after other type
2190 specifiers, but is a syntax error the best way of
2192 if (!typespec_ok
|| seen_type
)
2196 t
= c_parser_typeof_specifier (parser
);
2197 declspecs_add_type (loc
, specs
, t
);
2203 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2204 c_parser_consume_token (parser
);
2206 /* UPC qualifiers */
2209 c_parser_upc_shared_qual (loc
, parser
, specs
);
2214 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2215 c_parser_consume_token (parser
);
2220 attrs
= c_parser_attributes (parser
);
2221 declspecs_add_attrs (loc
, specs
, attrs
);
2224 align
= c_parser_alignas_specifier (parser
);
2225 declspecs_add_alignas (loc
, specs
, align
);
2234 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2237 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2238 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2239 enum attributes[opt] identifier
2241 The form with trailing comma is new in C99. The forms with
2242 attributes are GNU extensions. In GNU C, we accept any expression
2243 without commas in the syntax (assignment expressions, not just
2244 conditional expressions); assignment expressions will be diagnosed
2249 enumerator-list , enumerator
2252 enumeration-constant
2253 enumeration-constant = constant-expression
2256 static struct c_typespec
2257 c_parser_enum_specifier (c_parser
*parser
)
2259 struct c_typespec ret
;
2261 tree ident
= NULL_TREE
;
2262 location_t enum_loc
;
2263 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2264 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2265 enum_loc
= c_parser_peek_token (parser
)->location
;
2266 c_parser_consume_token (parser
);
2267 attrs
= c_parser_attributes (parser
);
2268 enum_loc
= c_parser_peek_token (parser
)->location
;
2269 /* Set the location in case we create a decl now. */
2270 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2271 if (c_parser_next_token_is (parser
, CPP_NAME
))
2273 ident
= c_parser_peek_token (parser
)->value
;
2274 ident_loc
= c_parser_peek_token (parser
)->location
;
2275 enum_loc
= ident_loc
;
2276 c_parser_consume_token (parser
);
2278 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2280 /* Parse an enum definition. */
2281 struct c_enum_contents the_enum
;
2284 /* We chain the enumerators in reverse order, then put them in
2285 forward order at the end. */
2287 timevar_push (TV_PARSE_ENUM
);
2288 type
= start_enum (enum_loc
, &the_enum
, ident
);
2290 c_parser_consume_token (parser
);
2298 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2299 location_t decl_loc
, value_loc
;
2300 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2302 c_parser_error (parser
, "expected identifier");
2303 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2304 values
= error_mark_node
;
2307 token
= c_parser_peek_token (parser
);
2308 enum_id
= token
->value
;
2309 /* Set the location in case we create a decl now. */
2310 c_parser_set_source_position_from_token (token
);
2311 decl_loc
= value_loc
= token
->location
;
2312 c_parser_consume_token (parser
);
2313 if (c_parser_next_token_is (parser
, CPP_EQ
))
2315 c_parser_consume_token (parser
);
2316 value_loc
= c_parser_peek_token (parser
)->location
;
2317 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2320 enum_value
= NULL_TREE
;
2321 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2322 &the_enum
, enum_id
, enum_value
);
2323 TREE_CHAIN (enum_decl
) = values
;
2326 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2328 comma_loc
= c_parser_peek_token (parser
)->location
;
2330 c_parser_consume_token (parser
);
2332 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2334 if (seen_comma
&& !flag_isoc99
)
2335 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2336 c_parser_consume_token (parser
);
2341 c_parser_error (parser
, "expected %<,%> or %<}%>");
2342 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2343 values
= error_mark_node
;
2347 postfix_attrs
= c_parser_attributes (parser
);
2348 ret
.spec
= finish_enum (type
, nreverse (values
),
2349 chainon (attrs
, postfix_attrs
));
2350 ret
.kind
= ctsk_tagdef
;
2351 ret
.expr
= NULL_TREE
;
2352 ret
.expr_const_operands
= true;
2353 timevar_pop (TV_PARSE_ENUM
);
2358 c_parser_error (parser
, "expected %<{%>");
2359 ret
.spec
= error_mark_node
;
2360 ret
.kind
= ctsk_tagref
;
2361 ret
.expr
= NULL_TREE
;
2362 ret
.expr_const_operands
= true;
2365 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2366 /* In ISO C, enumerated types can be referred to only if already
2368 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2371 pedwarn (enum_loc
, OPT_Wpedantic
,
2372 "ISO C forbids forward references to %<enum%> types");
2377 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2379 struct-or-union-specifier:
2380 struct-or-union attributes[opt] identifier[opt]
2381 { struct-contents } attributes[opt]
2382 struct-or-union attributes[opt] identifier
2385 struct-declaration-list
2387 struct-declaration-list:
2388 struct-declaration ;
2389 struct-declaration-list struct-declaration ;
2396 struct-declaration-list struct-declaration
2398 struct-declaration-list:
2399 struct-declaration-list ;
2402 (Note that in the syntax here, unlike that in ISO C, the semicolons
2403 are included here rather than in struct-declaration, in order to
2404 describe the syntax with extra semicolons and missing semicolon at
2409 struct-declaration-list:
2410 @defs ( class-name )
2412 (Note this does not include a trailing semicolon, but can be
2413 followed by further declarations, and gets a pedwarn-if-pedantic
2414 when followed by a semicolon.) */
2416 static struct c_typespec
2417 c_parser_struct_or_union_specifier (c_parser
*parser
)
2419 struct c_typespec ret
;
2421 tree ident
= NULL_TREE
;
2422 location_t struct_loc
;
2423 location_t ident_loc
= UNKNOWN_LOCATION
;
2424 enum tree_code code
;
2425 switch (c_parser_peek_token (parser
)->keyword
)
2436 struct_loc
= c_parser_peek_token (parser
)->location
;
2437 c_parser_consume_token (parser
);
2438 attrs
= c_parser_attributes (parser
);
2440 /* Set the location in case we create a decl now. */
2441 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2443 if (c_parser_next_token_is (parser
, CPP_NAME
))
2445 ident
= c_parser_peek_token (parser
)->value
;
2446 ident_loc
= c_parser_peek_token (parser
)->location
;
2447 struct_loc
= ident_loc
;
2448 c_parser_consume_token (parser
);
2450 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2452 /* Parse a struct or union definition. Start the scope of the
2453 tag before parsing components. */
2454 struct c_struct_parse_info
*struct_info
;
2455 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2457 /* We chain the components in reverse order, then put them in
2458 forward order at the end. Each struct-declaration may
2459 declare multiple components (comma-separated), so we must use
2460 chainon to join them, although when parsing each
2461 struct-declaration we can use TREE_CHAIN directly.
2463 The theory behind all this is that there will be more
2464 semicolon separated fields than comma separated fields, and
2465 so we'll be minimizing the number of node traversals required
2468 timevar_push (TV_PARSE_STRUCT
);
2469 contents
= NULL_TREE
;
2470 c_parser_consume_token (parser
);
2471 /* Handle the Objective-C @defs construct,
2472 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2473 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2476 gcc_assert (c_dialect_objc ());
2477 c_parser_consume_token (parser
);
2478 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2480 if (c_parser_next_token_is (parser
, CPP_NAME
)
2481 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2483 name
= c_parser_peek_token (parser
)->value
;
2484 c_parser_consume_token (parser
);
2488 c_parser_error (parser
, "expected class name");
2489 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2492 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2494 contents
= nreverse (objc_get_class_ivars (name
));
2497 /* Parse the struct-declarations and semicolons. Problems with
2498 semicolons are diagnosed here; empty structures are diagnosed
2503 /* Parse any stray semicolon. */
2504 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2506 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2507 "extra semicolon in struct or union specified");
2508 c_parser_consume_token (parser
);
2511 /* Stop if at the end of the struct or union contents. */
2512 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2514 c_parser_consume_token (parser
);
2517 /* Accept #pragmas at struct scope. */
2518 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2520 c_parser_pragma (parser
, pragma_external
);
2523 /* Parse some comma-separated declarations, but not the
2524 trailing semicolon if any. */
2525 decls
= c_parser_struct_declaration (parser
);
2526 contents
= chainon (decls
, contents
);
2527 /* If no semicolon follows, either we have a parse error or
2528 are at the end of the struct or union and should
2530 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2531 c_parser_consume_token (parser
);
2534 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2535 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2536 "no semicolon at end of struct or union");
2537 else if (parser
->error
2538 || !c_parser_next_token_starts_declspecs (parser
))
2540 c_parser_error (parser
, "expected %<;%>");
2541 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2545 /* If we come here, we have already emitted an error
2546 for an expected `;', identifier or `(', and we also
2547 recovered already. Go on with the next field. */
2550 postfix_attrs
= c_parser_attributes (parser
);
2551 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2552 chainon (attrs
, postfix_attrs
), struct_info
);
2553 ret
.kind
= ctsk_tagdef
;
2554 ret
.expr
= NULL_TREE
;
2555 ret
.expr_const_operands
= true;
2556 timevar_pop (TV_PARSE_STRUCT
);
2561 c_parser_error (parser
, "expected %<{%>");
2562 ret
.spec
= error_mark_node
;
2563 ret
.kind
= ctsk_tagref
;
2564 ret
.expr
= NULL_TREE
;
2565 ret
.expr_const_operands
= true;
2568 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2572 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2573 the trailing semicolon.
2576 specifier-qualifier-list struct-declarator-list
2577 static_assert-declaration-no-semi
2579 specifier-qualifier-list:
2580 type-specifier specifier-qualifier-list[opt]
2581 type-qualifier specifier-qualifier-list[opt]
2582 attributes specifier-qualifier-list[opt]
2584 struct-declarator-list:
2586 struct-declarator-list , attributes[opt] struct-declarator
2589 declarator attributes[opt]
2590 declarator[opt] : constant-expression attributes[opt]
2595 __extension__ struct-declaration
2596 specifier-qualifier-list
2598 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2599 of attributes where shown is a GNU extension. In GNU C, we accept
2600 any expression without commas in the syntax (assignment
2601 expressions, not just conditional expressions); assignment
2602 expressions will be diagnosed as non-constant. */
2605 c_parser_struct_declaration (c_parser
*parser
)
2607 struct c_declspecs
*specs
;
2609 tree all_prefix_attrs
;
2611 location_t decl_loc
;
2612 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2616 ext
= disable_extension_diagnostics ();
2617 c_parser_consume_token (parser
);
2618 decl
= c_parser_struct_declaration (parser
);
2619 restore_extension_diagnostics (ext
);
2622 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2624 c_parser_static_assert_declaration_no_semi (parser
);
2627 specs
= build_null_declspecs ();
2628 decl_loc
= c_parser_peek_token (parser
)->location
;
2629 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2632 if (!specs
->declspecs_seen_p
)
2634 c_parser_error (parser
, "expected specifier-qualifier-list");
2637 finish_declspecs (specs
);
2638 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2639 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2642 if (specs
->typespec_kind
== ctsk_none
)
2644 pedwarn (decl_loc
, OPT_Wpedantic
,
2645 "ISO C forbids member declarations with no members");
2646 shadow_tag_warned (specs
, pedantic
);
2651 /* Support for unnamed structs or unions as members of
2652 structs or unions (which is [a] useful and [b] supports
2656 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2657 build_id_declarator (NULL_TREE
), specs
,
2660 decl_attributes (&ret
, attrs
, 0);
2665 /* Provide better error recovery. Note that a type name here is valid,
2666 and will be treated as a field name. */
2667 if (specs
->typespec_kind
== ctsk_tagdef
2668 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2669 && c_parser_next_token_starts_declspecs (parser
)
2670 && !c_parser_next_token_is (parser
, CPP_NAME
))
2672 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2673 parser
->error
= false;
2677 pending_xref_error ();
2678 prefix_attrs
= specs
->attrs
;
2679 all_prefix_attrs
= prefix_attrs
;
2680 specs
->attrs
= NULL_TREE
;
2684 /* Declaring one or more declarators or un-named bit-fields. */
2685 struct c_declarator
*declarator
;
2687 if (c_parser_next_token_is (parser
, CPP_COLON
))
2688 declarator
= build_id_declarator (NULL_TREE
);
2690 declarator
= c_parser_declarator (parser
,
2691 specs
->typespec_kind
!= ctsk_none
,
2692 C_DTR_NORMAL
, &dummy
);
2693 if (declarator
== NULL
)
2695 c_parser_skip_to_end_of_block_or_statement (parser
);
2698 if (c_parser_next_token_is (parser
, CPP_COLON
)
2699 || c_parser_next_token_is (parser
, CPP_COMMA
)
2700 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2701 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2702 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2704 tree postfix_attrs
= NULL_TREE
;
2705 tree width
= NULL_TREE
;
2707 if (c_parser_next_token_is (parser
, CPP_COLON
))
2709 c_parser_consume_token (parser
);
2710 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2712 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2713 postfix_attrs
= c_parser_attributes (parser
);
2714 d
= grokfield (c_parser_peek_token (parser
)->location
,
2715 declarator
, specs
, width
, &all_prefix_attrs
);
2716 decl_attributes (&d
, chainon (postfix_attrs
,
2717 all_prefix_attrs
), 0);
2718 DECL_CHAIN (d
) = decls
;
2720 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2721 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2724 all_prefix_attrs
= prefix_attrs
;
2725 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2726 c_parser_consume_token (parser
);
2727 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2728 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2730 /* Semicolon consumed in caller. */
2735 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2741 c_parser_error (parser
,
2742 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2743 "%<__attribute__%>");
2750 /* Parse a typeof specifier (a GNU extension).
2753 typeof ( expression )
2754 typeof ( type-name )
2757 static struct c_typespec
2758 c_parser_typeof_specifier (c_parser
*parser
)
2760 struct c_typespec ret
;
2761 ret
.kind
= ctsk_typeof
;
2762 ret
.spec
= error_mark_node
;
2763 ret
.expr
= NULL_TREE
;
2764 ret
.expr_const_operands
= true;
2765 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2766 c_parser_consume_token (parser
);
2767 c_inhibit_evaluation_warnings
++;
2769 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2771 c_inhibit_evaluation_warnings
--;
2775 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2777 struct c_type_name
*type
= c_parser_type_name (parser
);
2778 c_inhibit_evaluation_warnings
--;
2782 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2783 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2789 location_t here
= c_parser_peek_token (parser
)->location
;
2790 struct c_expr expr
= c_parser_expression (parser
);
2791 c_inhibit_evaluation_warnings
--;
2793 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2794 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2795 error_at (here
, "%<typeof%> applied to a bit-field");
2796 mark_exp_read (expr
.value
);
2797 ret
.spec
= TREE_TYPE (expr
.value
);
2798 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2799 /* This is returned with the type so that when the type is
2800 evaluated, this can be evaluated. */
2802 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2803 pop_maybe_used (was_vm
);
2805 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2809 /* Parse an alignment-specifier.
2813 alignment-specifier:
2814 _Alignas ( type-name )
2815 _Alignas ( constant-expression )
2819 c_parser_alignas_specifier (c_parser
* parser
)
2821 tree ret
= error_mark_node
;
2822 location_t loc
= c_parser_peek_token (parser
)->location
;
2823 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2824 c_parser_consume_token (parser
);
2828 pedwarn (loc
, OPT_Wpedantic
,
2829 "ISO C99 does not support %<_Alignas%>");
2831 pedwarn (loc
, OPT_Wpedantic
,
2832 "ISO C90 does not support %<_Alignas%>");
2834 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2836 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2838 struct c_type_name
*type
= c_parser_type_name (parser
);
2840 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2843 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2844 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2848 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2849 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2850 be redeclared; otherwise it may not. KIND indicates which kind of
2851 declarator is wanted. Returns a valid declarator except in the
2852 case of a syntax error in which case NULL is returned. *SEEN_ID is
2853 set to true if an identifier being declared is seen; this is used
2854 to diagnose bad forms of abstract array declarators and to
2855 determine whether an identifier list is syntactically permitted.
2858 pointer[opt] direct-declarator
2862 ( attributes[opt] declarator )
2863 direct-declarator array-declarator
2864 direct-declarator ( parameter-type-list )
2865 direct-declarator ( identifier-list[opt] )
2868 * type-qualifier-list[opt]
2869 * type-qualifier-list[opt] pointer
2871 type-qualifier-list:
2874 type-qualifier-list type-qualifier
2875 type-qualifier-list attributes
2877 parameter-type-list:
2879 parameter-list , ...
2882 parameter-declaration
2883 parameter-list , parameter-declaration
2885 parameter-declaration:
2886 declaration-specifiers declarator attributes[opt]
2887 declaration-specifiers abstract-declarator[opt] attributes[opt]
2891 identifier-list , identifier
2893 abstract-declarator:
2895 pointer[opt] direct-abstract-declarator
2897 direct-abstract-declarator:
2898 ( attributes[opt] abstract-declarator )
2899 direct-abstract-declarator[opt] array-declarator
2900 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2905 direct-declarator ( parameter-forward-declarations
2906 parameter-type-list[opt] )
2908 direct-abstract-declarator:
2909 direct-abstract-declarator[opt] ( parameter-forward-declarations
2910 parameter-type-list[opt] )
2912 parameter-forward-declarations:
2914 parameter-forward-declarations parameter-list ;
2916 The uses of attributes shown above are GNU extensions.
2918 Some forms of array declarator are not included in C99 in the
2919 syntax for abstract declarators; these are disallowed elsewhere.
2920 This may be a defect (DR#289).
2922 This function also accepts an omitted abstract declarator as being
2923 an abstract declarator, although not part of the formal syntax. */
2925 static struct c_declarator
*
2926 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2929 /* Parse any initial pointer part. */
2930 if (c_parser_next_token_is (parser
, CPP_MULT
))
2932 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2933 struct c_declarator
*inner
;
2934 c_parser_consume_token (parser
);
2935 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2936 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2940 return make_pointer_declarator (quals_attrs
, inner
);
2942 /* Now we have a direct declarator, direct abstract declarator or
2943 nothing (which counts as a direct abstract declarator here). */
2944 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2947 /* Parse a direct declarator or direct abstract declarator; arguments
2948 as c_parser_declarator. */
2950 static struct c_declarator
*
2951 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2954 /* The direct declarator must start with an identifier (possibly
2955 omitted) or a parenthesized declarator (possibly abstract). In
2956 an ordinary declarator, initial parentheses must start a
2957 parenthesized declarator. In an abstract declarator or parameter
2958 declarator, they could start a parenthesized declarator or a
2959 parameter list. To tell which, the open parenthesis and any
2960 following attributes must be read. If a declaration specifier
2961 follows, then it is a parameter list; if the specifier is a
2962 typedef name, there might be an ambiguity about redeclaring it,
2963 which is resolved in the direction of treating it as a typedef
2964 name. If a close parenthesis follows, it is also an empty
2965 parameter list, as the syntax does not permit empty abstract
2966 declarators. Otherwise, it is a parenthesized declarator (in
2967 which case the analysis may be repeated inside it, recursively).
2969 ??? There is an ambiguity in a parameter declaration "int
2970 (__attribute__((foo)) x)", where x is not a typedef name: it
2971 could be an abstract declarator for a function, or declare x with
2972 parentheses. The proper resolution of this ambiguity needs
2973 documenting. At present we follow an accident of the old
2974 parser's implementation, whereby the first parameter must have
2975 some declaration specifiers other than just attributes. Thus as
2976 a parameter declaration it is treated as a parenthesized
2977 parameter named x, and as an abstract declarator it is
2980 ??? Also following the old parser, attributes inside an empty
2981 parameter list are ignored, making it a list not yielding a
2982 prototype, rather than giving an error or making it have one
2983 parameter with implicit type int.
2985 ??? Also following the old parser, typedef names may be
2986 redeclared in declarators, but not Objective-C class names. */
2988 if (kind
!= C_DTR_ABSTRACT
2989 && c_parser_next_token_is (parser
, CPP_NAME
)
2991 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2992 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2993 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2995 struct c_declarator
*inner
2996 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2998 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2999 c_parser_consume_token (parser
);
3000 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3003 if (kind
!= C_DTR_NORMAL
3004 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3006 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3007 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3010 /* Either we are at the end of an abstract declarator, or we have
3013 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3016 struct c_declarator
*inner
;
3017 c_parser_consume_token (parser
);
3018 attrs
= c_parser_attributes (parser
);
3019 if (kind
!= C_DTR_NORMAL
3020 && (c_parser_next_token_starts_declspecs (parser
)
3021 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3023 struct c_arg_info
*args
3024 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3031 = build_function_declarator (args
,
3032 build_id_declarator (NULL_TREE
));
3033 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3037 /* A parenthesized declarator. */
3038 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3039 if (inner
!= NULL
&& attrs
!= NULL
)
3040 inner
= build_attrs_declarator (attrs
, inner
);
3041 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3043 c_parser_consume_token (parser
);
3047 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3051 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3058 if (kind
== C_DTR_NORMAL
)
3060 c_parser_error (parser
, "expected identifier or %<(%>");
3064 return build_id_declarator (NULL_TREE
);
3068 /* Parse part of a direct declarator or direct abstract declarator,
3069 given that some (in INNER) has already been parsed; ID_PRESENT is
3070 true if an identifier is present, false for an abstract
3073 static struct c_declarator
*
3074 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3075 struct c_declarator
*inner
)
3077 /* Parse a sequence of array declarators and parameter lists. */
3078 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3080 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3081 struct c_declarator
*declarator
;
3082 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3086 c_parser_consume_token (parser
);
3087 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3088 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3090 c_parser_consume_token (parser
);
3091 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3092 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3093 if (!quals_attrs
->declspecs_seen_p
)
3095 /* If "static" is present, there must be an array dimension.
3096 Otherwise, there may be a dimension, "*", or no
3101 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3105 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3110 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3112 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3116 c_parser_consume_token (parser
);
3121 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3127 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3130 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3131 c_parser_consume_token (parser
);
3134 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3139 mark_exp_read (dimen
);
3140 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3141 static_seen
, star_seen
);
3142 if (declarator
== NULL
)
3144 inner
= set_array_declarator_inner (declarator
, inner
);
3145 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3147 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3150 struct c_arg_info
*args
;
3151 c_parser_consume_token (parser
);
3152 attrs
= c_parser_attributes (parser
);
3153 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3158 inner
= build_function_declarator (args
, inner
);
3159 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3165 /* Parse a parameter list or identifier list, including the closing
3166 parenthesis but not the opening one. ATTRS are the attributes at
3167 the start of the list. ID_LIST_OK is true if an identifier list is
3168 acceptable; such a list must not have attributes at the start. */
3170 static struct c_arg_info
*
3171 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3174 declare_parm_level ();
3175 /* If the list starts with an identifier, it is an identifier list.
3176 Otherwise, it is either a prototype list or an empty list. */
3179 && c_parser_next_token_is (parser
, CPP_NAME
)
3180 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3182 /* Look ahead to detect typos in type names. */
3183 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3184 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3185 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3186 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3188 tree list
= NULL_TREE
, *nextp
= &list
;
3189 while (c_parser_next_token_is (parser
, CPP_NAME
)
3190 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3192 *nextp
= build_tree_list (NULL_TREE
,
3193 c_parser_peek_token (parser
)->value
);
3194 nextp
= & TREE_CHAIN (*nextp
);
3195 c_parser_consume_token (parser
);
3196 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3198 c_parser_consume_token (parser
);
3199 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3201 c_parser_error (parser
, "expected identifier");
3205 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3207 struct c_arg_info
*ret
= build_arg_info ();
3209 c_parser_consume_token (parser
);
3215 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3223 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3230 /* Parse a parameter list (possibly empty), including the closing
3231 parenthesis but not the opening one. ATTRS are the attributes at
3232 the start of the list. EXPR is NULL or an expression that needs to
3233 be evaluated for the side effects of array size expressions in the
3236 static struct c_arg_info
*
3237 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3239 bool bad_parm
= false;
3241 /* ??? Following the old parser, forward parameter declarations may
3242 use abstract declarators, and if no real parameter declarations
3243 follow the forward declarations then this is not diagnosed. Also
3244 note as above that attributes are ignored as the only contents of
3245 the parentheses, or as the only contents after forward
3247 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3249 struct c_arg_info
*ret
= build_arg_info ();
3250 c_parser_consume_token (parser
);
3253 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3255 struct c_arg_info
*ret
= build_arg_info ();
3257 if (flag_allow_parameterless_variadic_functions
)
3259 /* F (...) is allowed. */
3260 ret
->types
= NULL_TREE
;
3264 /* Suppress -Wold-style-definition for this case. */
3265 ret
->types
= error_mark_node
;
3266 error_at (c_parser_peek_token (parser
)->location
,
3267 "ISO C requires a named argument before %<...%>");
3269 c_parser_consume_token (parser
);
3270 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3272 c_parser_consume_token (parser
);
3277 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3282 /* Nonempty list of parameters, either terminated with semicolon
3283 (forward declarations; recurse) or with close parenthesis (normal
3284 function) or with ", ... )" (variadic function). */
3287 /* Parse a parameter. */
3288 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3293 push_parm_decl (parm
, &expr
);
3294 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3297 c_parser_consume_token (parser
);
3298 mark_forward_parm_decls ();
3299 new_attrs
= c_parser_attributes (parser
);
3300 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3302 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3304 c_parser_consume_token (parser
);
3308 return get_parm_info (false, expr
);
3310 if (!c_parser_require (parser
, CPP_COMMA
,
3311 "expected %<;%>, %<,%> or %<)%>"))
3313 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3316 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3318 c_parser_consume_token (parser
);
3319 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3321 c_parser_consume_token (parser
);
3325 return get_parm_info (true, expr
);
3329 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3337 /* Parse a parameter declaration. ATTRS are the attributes at the
3338 start of the declaration if it is the first parameter. */
3340 static struct c_parm
*
3341 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3343 struct c_declspecs
*specs
;
3344 struct c_declarator
*declarator
;
3346 tree postfix_attrs
= NULL_TREE
;
3349 /* Accept #pragmas between parameter declarations. */
3350 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3351 c_parser_pragma (parser
, pragma_external
);
3353 if (!c_parser_next_token_starts_declspecs (parser
))
3355 c_token
*token
= c_parser_peek_token (parser
);
3358 c_parser_set_source_position_from_token (token
);
3359 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3361 error ("unknown type name %qE", token
->value
);
3362 parser
->error
= true;
3364 /* ??? In some Objective-C cases '...' isn't applicable so there
3365 should be a different message. */
3367 c_parser_error (parser
,
3368 "expected declaration specifiers or %<...%>");
3369 c_parser_skip_to_end_of_parameter (parser
);
3372 specs
= build_null_declspecs ();
3375 declspecs_add_attrs (input_location
, specs
, attrs
);
3378 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3379 finish_declspecs (specs
);
3380 pending_xref_error ();
3381 prefix_attrs
= specs
->attrs
;
3382 specs
->attrs
= NULL_TREE
;
3383 declarator
= c_parser_declarator (parser
,
3384 specs
->typespec_kind
!= ctsk_none
,
3385 C_DTR_PARM
, &dummy
);
3386 if (declarator
== NULL
)
3388 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3391 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3392 postfix_attrs
= c_parser_attributes (parser
);
3393 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3397 /* Parse a string literal in an asm expression. It should not be
3398 translated, and wide string literals are an error although
3399 permitted by the syntax. This is a GNU extension.
3404 ??? At present, following the old parser, the caller needs to have
3405 set lex_untranslated_string to 1. It would be better to follow the
3406 C++ parser rather than using this kludge. */
3409 c_parser_asm_string_literal (c_parser
*parser
)
3412 int save_flag
= warn_overlength_strings
;
3413 warn_overlength_strings
= 0;
3414 if (c_parser_next_token_is (parser
, CPP_STRING
))
3416 str
= c_parser_peek_token (parser
)->value
;
3417 c_parser_consume_token (parser
);
3419 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3421 error_at (c_parser_peek_token (parser
)->location
,
3422 "wide string literal in %<asm%>");
3423 str
= build_string (1, "");
3424 c_parser_consume_token (parser
);
3428 c_parser_error (parser
, "expected string literal");
3431 warn_overlength_strings
= save_flag
;
3435 /* Parse a simple asm expression. This is used in restricted
3436 contexts, where a full expression with inputs and outputs does not
3437 make sense. This is a GNU extension.
3440 asm ( asm-string-literal )
3444 c_parser_simple_asm_expr (c_parser
*parser
)
3447 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3448 /* ??? Follow the C++ parser rather than using the
3449 lex_untranslated_string kludge. */
3450 parser
->lex_untranslated_string
= true;
3451 c_parser_consume_token (parser
);
3452 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3454 parser
->lex_untranslated_string
= false;
3457 str
= c_parser_asm_string_literal (parser
);
3458 parser
->lex_untranslated_string
= false;
3459 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3461 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3468 c_parser_attribute_any_word (c_parser
*parser
)
3470 tree attr_name
= NULL_TREE
;
3472 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3474 /* ??? See comment above about what keywords are accepted here. */
3476 switch (c_parser_peek_token (parser
)->keyword
)
3507 case RID_TRANSACTION_ATOMIC
:
3508 case RID_TRANSACTION_CANCEL
:
3518 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3519 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3521 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3522 attr_name
= c_parser_peek_token (parser
)->value
;
3527 /* Parse (possibly empty) attributes. This is a GNU extension.
3531 attributes attribute
3534 __attribute__ ( ( attribute-list ) )
3538 attribute_list , attrib
3543 any-word ( identifier )
3544 any-word ( identifier , nonempty-expr-list )
3545 any-word ( expr-list )
3547 where the "identifier" must not be declared as a type, and
3548 "any-word" may be any identifier (including one declared as a
3549 type), a reserved word storage class specifier, type specifier or
3550 type qualifier. ??? This still leaves out most reserved keywords
3551 (following the old parser), shouldn't we include them, and why not
3552 allow identifiers declared as types to start the arguments? */
3555 c_parser_attributes (c_parser
*parser
)
3557 tree attrs
= NULL_TREE
;
3558 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3560 /* ??? Follow the C++ parser rather than using the
3561 lex_untranslated_string kludge. */
3562 parser
->lex_untranslated_string
= true;
3563 c_parser_consume_token (parser
);
3564 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3566 parser
->lex_untranslated_string
= false;
3569 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3571 parser
->lex_untranslated_string
= false;
3572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3575 /* Parse the attribute list. */
3576 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3577 || c_parser_next_token_is (parser
, CPP_NAME
)
3578 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3580 tree attr
, attr_name
, attr_args
;
3581 vec
<tree
, va_gc
> *expr_list
;
3582 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3584 c_parser_consume_token (parser
);
3588 attr_name
= c_parser_attribute_any_word (parser
);
3589 if (attr_name
== NULL
)
3591 c_parser_consume_token (parser
);
3592 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3594 attr
= build_tree_list (attr_name
, NULL_TREE
);
3595 attrs
= chainon (attrs
, attr
);
3598 c_parser_consume_token (parser
);
3599 /* Parse the attribute contents. If they start with an
3600 identifier which is followed by a comma or close
3601 parenthesis, then the arguments start with that
3602 identifier; otherwise they are an expression list.
3603 In objective-c the identifier may be a classname. */
3604 if (c_parser_next_token_is (parser
, CPP_NAME
)
3605 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3606 || (c_dialect_objc ()
3607 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3608 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3609 || (c_parser_peek_2nd_token (parser
)->type
3610 == CPP_CLOSE_PAREN
)))
3612 tree arg1
= c_parser_peek_token (parser
)->value
;
3613 c_parser_consume_token (parser
);
3614 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3615 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3619 c_parser_consume_token (parser
);
3620 expr_list
= c_parser_expr_list (parser
, false, true,
3622 tree_list
= build_tree_list_vec (expr_list
);
3623 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3624 release_tree_vector (expr_list
);
3629 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3630 attr_args
= NULL_TREE
;
3633 expr_list
= c_parser_expr_list (parser
, false, true,
3635 attr_args
= build_tree_list_vec (expr_list
);
3636 release_tree_vector (expr_list
);
3639 attr
= build_tree_list (attr_name
, attr_args
);
3640 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3641 c_parser_consume_token (parser
);
3644 parser
->lex_untranslated_string
= false;
3645 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3649 attrs
= chainon (attrs
, attr
);
3651 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3652 c_parser_consume_token (parser
);
3655 parser
->lex_untranslated_string
= false;
3656 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3660 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3661 c_parser_consume_token (parser
);
3664 parser
->lex_untranslated_string
= false;
3665 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3669 parser
->lex_untranslated_string
= false;
3674 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3677 specifier-qualifier-list abstract-declarator[opt]
3680 static struct c_type_name
*
3681 c_parser_type_name (c_parser
*parser
)
3683 struct c_declspecs
*specs
= build_null_declspecs ();
3684 struct c_declarator
*declarator
;
3685 struct c_type_name
*ret
;
3687 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3688 if (!specs
->declspecs_seen_p
)
3690 c_parser_error (parser
, "expected specifier-qualifier-list");
3693 if (specs
->type
!= error_mark_node
)
3695 pending_xref_error ();
3696 finish_declspecs (specs
);
3698 declarator
= c_parser_declarator (parser
,
3699 specs
->typespec_kind
!= ctsk_none
,
3700 C_DTR_ABSTRACT
, &dummy
);
3701 if (declarator
== NULL
)
3703 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3705 ret
->declarator
= declarator
;
3709 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3712 assignment-expression
3713 { initializer-list }
3714 { initializer-list , }
3717 designation[opt] initializer
3718 initializer-list , designation[opt] initializer
3725 designator-list designator
3732 [ constant-expression ]
3744 [ constant-expression ... constant-expression ]
3746 Any expression without commas is accepted in the syntax for the
3747 constant-expressions, with non-constant expressions rejected later.
3749 This function is only used for top-level initializers; for nested
3750 ones, see c_parser_initval. */
3752 static struct c_expr
3753 c_parser_initializer (c_parser
*parser
)
3755 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3756 return c_parser_braced_init (parser
, NULL_TREE
, false);
3760 location_t loc
= c_parser_peek_token (parser
)->location
;
3761 ret
= c_parser_expr_no_commas (parser
, NULL
);
3762 if (TREE_CODE (ret
.value
) != STRING_CST
3763 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3764 ret
= default_function_array_read_conversion (loc
, ret
);
3769 /* Parse a braced initializer list. TYPE is the type specified for a
3770 compound literal, and NULL_TREE for other initializers and for
3771 nested braced lists. NESTED_P is true for nested braced lists,
3772 false for the list of a compound literal or the list that is the
3773 top-level initializer in a declaration. */
3775 static struct c_expr
3776 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3779 struct obstack braced_init_obstack
;
3780 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3781 gcc_obstack_init (&braced_init_obstack
);
3782 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3783 c_parser_consume_token (parser
);
3785 push_init_level (0, &braced_init_obstack
);
3787 really_start_incremental_init (type
);
3788 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3790 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3794 /* Parse a non-empty initializer list, possibly with a trailing
3798 c_parser_initelt (parser
, &braced_init_obstack
);
3801 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3802 c_parser_consume_token (parser
);
3805 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3809 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3811 ret
.value
= error_mark_node
;
3812 ret
.original_code
= ERROR_MARK
;
3813 ret
.original_type
= NULL
;
3814 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3815 pop_init_level (0, &braced_init_obstack
);
3816 obstack_free (&braced_init_obstack
, NULL
);
3819 c_parser_consume_token (parser
);
3820 ret
= pop_init_level (0, &braced_init_obstack
);
3821 obstack_free (&braced_init_obstack
, NULL
);
3825 /* Parse a nested initializer, including designators. */
3828 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3830 /* Parse any designator or designator list. A single array
3831 designator may have the subsequent "=" omitted in GNU C, but a
3832 longer list or a structure member designator may not. */
3833 if (c_parser_next_token_is (parser
, CPP_NAME
)
3834 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3836 /* Old-style structure member designator. */
3837 set_init_label (c_parser_peek_token (parser
)->value
,
3838 braced_init_obstack
);
3839 /* Use the colon as the error location. */
3840 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3841 "obsolete use of designated initializer with %<:%>");
3842 c_parser_consume_token (parser
);
3843 c_parser_consume_token (parser
);
3847 /* des_seen is 0 if there have been no designators, 1 if there
3848 has been a single array designator and 2 otherwise. */
3850 /* Location of a designator. */
3851 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3852 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3853 || c_parser_next_token_is (parser
, CPP_DOT
))
3855 int des_prev
= des_seen
;
3857 des_loc
= c_parser_peek_token (parser
)->location
;
3860 if (c_parser_next_token_is (parser
, CPP_DOT
))
3863 c_parser_consume_token (parser
);
3864 if (c_parser_next_token_is (parser
, CPP_NAME
))
3866 set_init_label (c_parser_peek_token (parser
)->value
,
3867 braced_init_obstack
);
3868 c_parser_consume_token (parser
);
3873 init
.value
= error_mark_node
;
3874 init
.original_code
= ERROR_MARK
;
3875 init
.original_type
= NULL
;
3876 c_parser_error (parser
, "expected identifier");
3877 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3878 process_init_element (init
, false, braced_init_obstack
);
3885 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3886 /* ??? Following the old parser, [ objc-receiver
3887 objc-message-args ] is accepted as an initializer,
3888 being distinguished from a designator by what follows
3889 the first assignment expression inside the square
3890 brackets, but after a first array designator a
3891 subsequent square bracket is for Objective-C taken to
3892 start an expression, using the obsolete form of
3893 designated initializer without '=', rather than
3894 possibly being a second level of designation: in LALR
3895 terms, the '[' is shifted rather than reducing
3896 designator to designator-list. */
3897 if (des_prev
== 1 && c_dialect_objc ())
3899 des_seen
= des_prev
;
3902 if (des_prev
== 0 && c_dialect_objc ())
3904 /* This might be an array designator or an
3905 Objective-C message expression. If the former,
3906 continue parsing here; if the latter, parse the
3907 remainder of the initializer given the starting
3908 primary-expression. ??? It might make sense to
3909 distinguish when des_prev == 1 as well; see
3910 previous comment. */
3912 struct c_expr mexpr
;
3913 c_parser_consume_token (parser
);
3914 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3915 && ((c_parser_peek_token (parser
)->id_kind
3917 || (c_parser_peek_token (parser
)->id_kind
3918 == C_ID_CLASSNAME
)))
3920 /* Type name receiver. */
3921 tree id
= c_parser_peek_token (parser
)->value
;
3922 c_parser_consume_token (parser
);
3923 rec
= objc_get_class_reference (id
);
3924 goto parse_message_args
;
3926 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3927 mark_exp_read (first
);
3928 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3929 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3930 goto array_desig_after_first
;
3931 /* Expression receiver. So far only one part
3932 without commas has been parsed; there might be
3933 more of the expression. */
3935 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3938 location_t comma_loc
, exp_loc
;
3939 comma_loc
= c_parser_peek_token (parser
)->location
;
3940 c_parser_consume_token (parser
);
3941 exp_loc
= c_parser_peek_token (parser
)->location
;
3942 next
= c_parser_expr_no_commas (parser
, NULL
);
3943 next
= default_function_array_read_conversion (exp_loc
,
3945 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3948 /* Now parse the objc-message-args. */
3949 args
= c_parser_objc_message_args (parser
);
3950 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3953 = objc_build_message_expr (rec
, args
);
3954 mexpr
.original_code
= ERROR_MARK
;
3955 mexpr
.original_type
= NULL
;
3956 /* Now parse and process the remainder of the
3957 initializer, starting with this message
3958 expression as a primary-expression. */
3959 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3962 c_parser_consume_token (parser
);
3963 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3964 mark_exp_read (first
);
3965 array_desig_after_first
:
3966 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3968 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3969 c_parser_consume_token (parser
);
3970 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3971 mark_exp_read (second
);
3975 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3977 c_parser_consume_token (parser
);
3978 set_init_index (first
, second
, braced_init_obstack
);
3980 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
3981 "ISO C forbids specifying range of elements to initialize");
3984 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3990 if (c_parser_next_token_is (parser
, CPP_EQ
))
3993 pedwarn (des_loc
, OPT_Wpedantic
,
3994 "ISO C90 forbids specifying subobject to initialize");
3995 c_parser_consume_token (parser
);
4000 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4001 "obsolete use of designated initializer without %<=%>");
4005 init
.value
= error_mark_node
;
4006 init
.original_code
= ERROR_MARK
;
4007 init
.original_type
= NULL
;
4008 c_parser_error (parser
, "expected %<=%>");
4009 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4010 process_init_element (init
, false, braced_init_obstack
);
4016 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4019 /* Parse a nested initializer; as c_parser_initializer but parses
4020 initializers within braced lists, after any designators have been
4021 applied. If AFTER is not NULL then it is an Objective-C message
4022 expression which is the primary-expression starting the
4026 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4027 struct obstack
* braced_init_obstack
)
4030 gcc_assert (!after
|| c_dialect_objc ());
4031 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4032 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4035 location_t loc
= c_parser_peek_token (parser
)->location
;
4036 init
= c_parser_expr_no_commas (parser
, after
);
4037 if (init
.value
!= NULL_TREE
4038 && TREE_CODE (init
.value
) != STRING_CST
4039 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4040 init
= default_function_array_read_conversion (loc
, init
);
4042 process_init_element (init
, false, braced_init_obstack
);
4045 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4049 { block-item-list[opt] }
4050 { label-declarations block-item-list }
4054 block-item-list block-item
4066 { label-declarations block-item-list }
4069 __extension__ nested-declaration
4070 nested-function-definition
4074 label-declarations label-declaration
4077 __label__ identifier-list ;
4079 Allowing the mixing of declarations and code is new in C99. The
4080 GNU syntax also permits (not shown above) labels at the end of
4081 compound statements, which yield an error. We don't allow labels
4082 on declarations; this might seem like a natural extension, but
4083 there would be a conflict between attributes on the label and
4084 prefix attributes on the declaration. ??? The syntax follows the
4085 old parser in requiring something after label declarations.
4086 Although they are erroneous if the labels declared aren't defined,
4087 is it useful for the syntax to be this way?
4099 c_parser_compound_statement (c_parser
*parser
)
4102 location_t brace_loc
;
4103 brace_loc
= c_parser_peek_token (parser
)->location
;
4104 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4106 /* Ensure a scope is entered and left anyway to avoid confusion
4107 if we have just prepared to enter a function body. */
4108 stmt
= c_begin_compound_stmt (true);
4109 c_end_compound_stmt (brace_loc
, stmt
, true);
4110 return error_mark_node
;
4112 stmt
= c_begin_compound_stmt (true);
4113 c_parser_compound_statement_nostart (parser
);
4114 return c_end_compound_stmt (brace_loc
, stmt
, true);
4117 /* Parse a compound statement except for the opening brace. This is
4118 used for parsing both compound statements and statement expressions
4119 (which follow different paths to handling the opening). */
4122 c_parser_compound_statement_nostart (c_parser
*parser
)
4124 bool last_stmt
= false;
4125 bool last_label
= false;
4126 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4127 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4128 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4130 c_parser_consume_token (parser
);
4133 mark_valid_location_for_stdc_pragma (true);
4134 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4136 /* Read zero or more forward-declarations for labels that nested
4137 functions can jump to. */
4138 mark_valid_location_for_stdc_pragma (false);
4139 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4141 label_loc
= c_parser_peek_token (parser
)->location
;
4142 c_parser_consume_token (parser
);
4143 /* Any identifiers, including those declared as type names,
4148 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4150 c_parser_error (parser
, "expected identifier");
4154 = declare_label (c_parser_peek_token (parser
)->value
);
4155 C_DECLARED_LABEL_FLAG (label
) = 1;
4156 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4157 c_parser_consume_token (parser
);
4158 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4159 c_parser_consume_token (parser
);
4163 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4165 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4167 /* We must now have at least one statement, label or declaration. */
4168 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4170 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4171 c_parser_error (parser
, "expected declaration or statement");
4172 c_parser_consume_token (parser
);
4175 /* Process all #pragma's just after the opening brace. This
4176 handles #pragma upc, which can only appear just after
4177 the opening brace, when it appears within a function body. */
4178 push_upc_consistency_mode ();
4179 permit_pragma_upc ();
4180 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4182 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4183 if (c_parser_pragma (parser
, pragma_compound
))
4184 last_label
= false, last_stmt
= true;
4185 parser
->error
= false;
4188 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4190 location_t loc
= c_parser_peek_token (parser
)->location
;
4191 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4192 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4193 || (c_parser_next_token_is (parser
, CPP_NAME
)
4194 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4196 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4197 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4199 label_loc
= c_parser_peek_token (parser
)->location
;
4202 mark_valid_location_for_stdc_pragma (false);
4203 c_parser_label (parser
);
4205 else if (!last_label
4206 && c_parser_next_tokens_start_declaration (parser
))
4209 mark_valid_location_for_stdc_pragma (false);
4210 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4213 (pedantic
&& !flag_isoc99
)
4215 : OPT_Wdeclaration_after_statement
,
4216 "ISO C90 forbids mixed declarations and code");
4219 else if (!last_label
4220 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4222 /* __extension__ can start a declaration, but is also an
4223 unary operator that can start an expression. Consume all
4224 but the last of a possible series of __extension__ to
4226 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4227 && (c_parser_peek_2nd_token (parser
)->keyword
4229 c_parser_consume_token (parser
);
4230 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4233 ext
= disable_extension_diagnostics ();
4234 c_parser_consume_token (parser
);
4236 mark_valid_location_for_stdc_pragma (false);
4237 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4239 /* Following the old parser, __extension__ does not
4240 disable this diagnostic. */
4241 restore_extension_diagnostics (ext
);
4243 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4245 : OPT_Wdeclaration_after_statement
,
4246 "ISO C90 forbids mixed declarations and code");
4252 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4254 /* External pragmas, and some omp pragmas, are not associated
4255 with regular c code, and so are not to be considered statements
4256 syntactically. This ensures that the user doesn't put them
4257 places that would turn into syntax errors if the directive
4259 if (c_parser_pragma (parser
, pragma_compound
))
4260 last_label
= false, last_stmt
= true;
4262 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4264 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4265 c_parser_error (parser
, "expected declaration or statement");
4268 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4270 if (parser
->in_if_block
)
4272 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4273 error_at (loc
, """expected %<}%> before %<else%>");
4278 error_at (loc
, "%<else%> without a previous %<if%>");
4279 c_parser_consume_token (parser
);
4288 mark_valid_location_for_stdc_pragma (false);
4289 c_parser_statement_after_labels (parser
);
4292 parser
->error
= false;
4295 error_at (label_loc
, "label at end of compound statement");
4296 c_parser_consume_token (parser
);
4297 pop_upc_consistency_mode ();
4298 /* Restore the value we started with. */
4299 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4302 /* Parse a label (C90 6.6.1, C99 6.8.1).
4305 identifier : attributes[opt]
4306 case constant-expression :
4312 case constant-expression ... constant-expression :
4314 The use of attributes on labels is a GNU extension. The syntax in
4315 GNU C accepts any expressions without commas, non-constant
4316 expressions being rejected later. */
4319 c_parser_label (c_parser
*parser
)
4321 location_t loc1
= c_parser_peek_token (parser
)->location
;
4322 tree label
= NULL_TREE
;
4323 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4326 c_parser_consume_token (parser
);
4327 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4328 if (c_parser_next_token_is (parser
, CPP_COLON
))
4330 c_parser_consume_token (parser
);
4331 label
= do_case (loc1
, exp1
, NULL_TREE
);
4333 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4335 c_parser_consume_token (parser
);
4336 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4337 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4338 label
= do_case (loc1
, exp1
, exp2
);
4341 c_parser_error (parser
, "expected %<:%> or %<...%>");
4343 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4345 c_parser_consume_token (parser
);
4346 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4347 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4351 tree name
= c_parser_peek_token (parser
)->value
;
4354 location_t loc2
= c_parser_peek_token (parser
)->location
;
4355 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4356 c_parser_consume_token (parser
);
4357 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4358 c_parser_consume_token (parser
);
4359 attrs
= c_parser_attributes (parser
);
4360 tlab
= define_label (loc2
, name
);
4363 decl_attributes (&tlab
, attrs
, 0);
4364 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4369 if (c_parser_next_tokens_start_declaration (parser
))
4371 error_at (c_parser_peek_token (parser
)->location
,
4372 "a label can only be part of a statement and "
4373 "a declaration is not a statement");
4374 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4375 /*static_assert_ok*/ true,
4376 /*empty_ok*/ true, /*nested*/ true,
4377 /*start_attr_ok*/ true, NULL
);
4382 /* Parse a statement (C90 6.6, C99 6.8).
4387 expression-statement
4395 expression-statement:
4398 selection-statement:
4402 iteration-statement:
4411 return expression[opt] ;
4424 objc-throw-statement
4425 objc-try-catch-statement
4426 objc-synchronized-statement
4428 objc-throw-statement:
4442 parallel-for-construct
4443 parallel-sections-construct
4450 parallel-directive structured-block
4453 for-directive iteration-statement
4456 sections-directive section-scope
4459 single-directive structured-block
4461 parallel-for-construct:
4462 parallel-for-directive iteration-statement
4464 parallel-sections-construct:
4465 parallel-sections-directive section-scope
4468 master-directive structured-block
4471 critical-directive structured-block
4474 atomic-directive expression-statement
4477 ordered-directive structured-block
4479 Transactional Memory:
4482 transaction-statement
4483 transaction-cancel-statement
4487 c_parser_statement (c_parser
*parser
)
4489 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4490 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4491 || (c_parser_next_token_is (parser
, CPP_NAME
)
4492 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4493 c_parser_label (parser
);
4494 c_parser_statement_after_labels (parser
);
4497 /* Parse a statement, other than a labeled statement. */
4500 c_parser_statement_after_labels (c_parser
*parser
)
4502 location_t loc
= c_parser_peek_token (parser
)->location
;
4503 tree stmt
= NULL_TREE
;
4504 bool in_if_block
= parser
->in_if_block
;
4505 parser
->in_if_block
= false;
4506 switch (c_parser_peek_token (parser
)->type
)
4508 case CPP_OPEN_BRACE
:
4509 add_stmt (c_parser_compound_statement (parser
));
4512 switch (c_parser_peek_token (parser
)->keyword
)
4515 c_parser_if_statement (parser
);
4518 c_parser_switch_statement (parser
);
4521 c_parser_while_statement (parser
);
4524 c_parser_do_statement (parser
);
4527 c_parser_for_statement (parser
);
4530 c_parser_consume_token (parser
);
4531 if (c_parser_next_token_is (parser
, CPP_NAME
))
4533 stmt
= c_finish_goto_label (loc
,
4534 c_parser_peek_token (parser
)->value
);
4535 c_parser_consume_token (parser
);
4537 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4541 c_parser_consume_token (parser
);
4542 val
= c_parser_expression (parser
).value
;
4543 mark_exp_read (val
);
4544 stmt
= c_finish_goto_ptr (loc
, val
);
4547 c_parser_error (parser
, "expected identifier or %<*%>");
4548 goto expect_semicolon
;
4550 c_parser_consume_token (parser
);
4551 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4552 goto expect_semicolon
;
4554 c_parser_consume_token (parser
);
4555 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4556 goto expect_semicolon
;
4558 c_parser_consume_token (parser
);
4559 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4561 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4562 c_parser_consume_token (parser
);
4566 struct c_expr expr
= c_parser_expression_conv (parser
);
4567 mark_exp_read (expr
.value
);
4568 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4569 goto expect_semicolon
;
4573 stmt
= c_parser_asm_statement (parser
);
4575 case RID_TRANSACTION_ATOMIC
:
4576 case RID_TRANSACTION_RELAXED
:
4577 stmt
= c_parser_transaction (parser
,
4578 c_parser_peek_token (parser
)->keyword
);
4580 case RID_TRANSACTION_CANCEL
:
4581 stmt
= c_parser_transaction_cancel (parser
);
4582 goto expect_semicolon
;
4584 gcc_assert (c_dialect_objc ());
4585 c_parser_consume_token (parser
);
4586 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4588 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4589 c_parser_consume_token (parser
);
4593 tree expr
= c_parser_expression (parser
).value
;
4594 expr
= c_fully_fold (expr
, false, NULL
);
4595 stmt
= objc_build_throw_stmt (loc
, expr
);
4596 goto expect_semicolon
;
4600 gcc_assert (c_dialect_objc ());
4601 c_parser_objc_try_catch_finally_statement (parser
);
4603 case RID_AT_SYNCHRONIZED
:
4604 gcc_assert (c_dialect_objc ());
4605 c_parser_objc_synchronized_statement (parser
);
4607 case RID_UPC_FORALL
:
4608 gcc_assert (c_dialect_upc ());
4609 c_parser_upc_forall_statement (parser
);
4611 case RID_UPC_NOTIFY
:
4612 gcc_assert (c_dialect_upc ());
4613 c_parser_upc_sync_statement (parser
, UPC_SYNC_NOTIFY_OP
);
4614 goto expect_semicolon
;
4616 gcc_assert (c_dialect_upc ());
4617 c_parser_upc_sync_statement (parser
, UPC_SYNC_WAIT_OP
);
4618 goto expect_semicolon
;
4619 case RID_UPC_BARRIER
:
4620 gcc_assert (c_dialect_upc ());
4621 c_parser_upc_sync_statement (parser
, UPC_SYNC_BARRIER_OP
);
4622 goto expect_semicolon
;
4628 c_parser_consume_token (parser
);
4630 case CPP_CLOSE_PAREN
:
4631 case CPP_CLOSE_SQUARE
:
4632 /* Avoid infinite loop in error recovery:
4633 c_parser_skip_until_found stops at a closing nesting
4634 delimiter without consuming it, but here we need to consume
4635 it to proceed further. */
4636 c_parser_error (parser
, "expected statement");
4637 c_parser_consume_token (parser
);
4640 c_parser_pragma (parser
, pragma_stmt
);
4644 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4646 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4649 /* Two cases cannot and do not have line numbers associated: If stmt
4650 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4651 cannot hold line numbers. But that's OK because the statement
4652 will either be changed to a MODIFY_EXPR during gimplification of
4653 the statement expr, or discarded. If stmt was compound, but
4654 without new variables, we will have skipped the creation of a
4655 BIND and will have a bare STATEMENT_LIST. But that's OK because
4656 (recursively) all of the component statements should already have
4657 line numbers assigned. ??? Can we discard no-op statements
4659 if (CAN_HAVE_LOCATION_P (stmt
)
4660 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4661 SET_EXPR_LOCATION (stmt
, loc
);
4663 parser
->in_if_block
= in_if_block
;
4666 /* Parse the condition from an if, do, while or for statements. */
4669 c_parser_condition (c_parser
*parser
)
4671 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4673 cond
= c_parser_expression_conv (parser
).value
;
4674 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4675 cond
= c_fully_fold (cond
, false, NULL
);
4676 if (warn_sequence_point
)
4677 verify_sequence_points (cond
);
4681 /* Parse a parenthesized condition from an if, do or while statement.
4687 c_parser_paren_condition (c_parser
*parser
)
4690 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4691 return error_mark_node
;
4692 cond
= c_parser_condition (parser
);
4693 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4697 /* Parse a statement which is a block in C99. */
4700 c_parser_c99_block_statement (c_parser
*parser
)
4702 tree block
= c_begin_compound_stmt (flag_isoc99
);
4703 location_t loc
= c_parser_peek_token (parser
)->location
;
4704 c_parser_statement (parser
);
4705 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4708 /* Parse the body of an if statement. This is just parsing a
4709 statement but (a) it is a block in C99, (b) we track whether the
4710 body is an if statement for the sake of -Wparentheses warnings, (c)
4711 we handle an empty body specially for the sake of -Wempty-body
4712 warnings, and (d) we call parser_compound_statement directly
4713 because c_parser_statement_after_labels resets
4714 parser->in_if_block. */
4717 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4719 tree block
= c_begin_compound_stmt (flag_isoc99
);
4720 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4721 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4722 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4723 || (c_parser_next_token_is (parser
, CPP_NAME
)
4724 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4725 c_parser_label (parser
);
4726 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4727 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4729 location_t loc
= c_parser_peek_token (parser
)->location
;
4730 add_stmt (build_empty_stmt (loc
));
4731 c_parser_consume_token (parser
);
4732 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4733 warning_at (loc
, OPT_Wempty_body
,
4734 "suggest braces around empty body in an %<if%> statement");
4736 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4737 add_stmt (c_parser_compound_statement (parser
));
4739 c_parser_statement_after_labels (parser
);
4740 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4743 /* Parse the else body of an if statement. This is just parsing a
4744 statement but (a) it is a block in C99, (b) we handle an empty body
4745 specially for the sake of -Wempty-body warnings. */
4748 c_parser_else_body (c_parser
*parser
)
4750 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4751 tree block
= c_begin_compound_stmt (flag_isoc99
);
4752 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4753 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4754 || (c_parser_next_token_is (parser
, CPP_NAME
)
4755 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4756 c_parser_label (parser
);
4757 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4759 location_t loc
= c_parser_peek_token (parser
)->location
;
4762 "suggest braces around empty body in an %<else%> statement");
4763 add_stmt (build_empty_stmt (loc
));
4764 c_parser_consume_token (parser
);
4767 c_parser_statement_after_labels (parser
);
4768 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4771 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4774 if ( expression ) statement
4775 if ( expression ) statement else statement
4779 c_parser_if_statement (c_parser
*parser
)
4784 bool first_if
= false;
4785 tree first_body
, second_body
;
4788 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4789 c_parser_consume_token (parser
);
4790 block
= c_begin_compound_stmt (flag_isoc99
);
4791 loc
= c_parser_peek_token (parser
)->location
;
4792 cond
= c_parser_paren_condition (parser
);
4793 in_if_block
= parser
->in_if_block
;
4794 parser
->in_if_block
= true;
4795 first_body
= c_parser_if_body (parser
, &first_if
);
4796 parser
->in_if_block
= in_if_block
;
4797 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4799 c_parser_consume_token (parser
);
4800 second_body
= c_parser_else_body (parser
);
4803 second_body
= NULL_TREE
;
4804 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4805 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4808 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4811 switch (expression) statement
4815 c_parser_switch_statement (c_parser
*parser
)
4817 tree block
, expr
, body
, save_break
;
4818 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4819 location_t switch_cond_loc
;
4820 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4821 c_parser_consume_token (parser
);
4822 block
= c_begin_compound_stmt (flag_isoc99
);
4823 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4825 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4826 expr
= c_parser_expression (parser
).value
;
4827 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4831 switch_cond_loc
= UNKNOWN_LOCATION
;
4832 expr
= error_mark_node
;
4834 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4835 save_break
= c_break_label
;
4836 c_break_label
= NULL_TREE
;
4837 body
= c_parser_c99_block_statement (parser
);
4838 c_finish_case (body
);
4841 location_t here
= c_parser_peek_token (parser
)->location
;
4842 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4843 SET_EXPR_LOCATION (t
, here
);
4846 c_break_label
= save_break
;
4847 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4850 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4853 while (expression) statement
4857 c_parser_while_statement (c_parser
*parser
)
4859 tree block
, cond
, body
, save_break
, save_cont
;
4861 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4862 c_parser_consume_token (parser
);
4863 block
= c_begin_compound_stmt (flag_isoc99
);
4864 loc
= c_parser_peek_token (parser
)->location
;
4865 cond
= c_parser_paren_condition (parser
);
4866 save_break
= c_break_label
;
4867 c_break_label
= NULL_TREE
;
4868 save_cont
= c_cont_label
;
4869 c_cont_label
= NULL_TREE
;
4870 body
= c_parser_c99_block_statement (parser
);
4871 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4872 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4873 c_break_label
= save_break
;
4874 c_cont_label
= save_cont
;
4877 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4880 do statement while ( expression ) ;
4884 c_parser_do_statement (c_parser
*parser
)
4886 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4888 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4889 c_parser_consume_token (parser
);
4890 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4891 warning_at (c_parser_peek_token (parser
)->location
,
4893 "suggest braces around empty body in %<do%> statement");
4894 block
= c_begin_compound_stmt (flag_isoc99
);
4895 loc
= c_parser_peek_token (parser
)->location
;
4896 save_break
= c_break_label
;
4897 c_break_label
= NULL_TREE
;
4898 save_cont
= c_cont_label
;
4899 c_cont_label
= NULL_TREE
;
4900 body
= c_parser_c99_block_statement (parser
);
4901 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4902 new_break
= c_break_label
;
4903 c_break_label
= save_break
;
4904 new_cont
= c_cont_label
;
4905 c_cont_label
= save_cont
;
4906 cond
= c_parser_paren_condition (parser
);
4907 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4908 c_parser_skip_to_end_of_block_or_statement (parser
);
4909 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4910 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4913 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4916 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4917 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4919 The form with a declaration is new in C99.
4921 ??? In accordance with the old parser, the declaration may be a
4922 nested function, which is then rejected in check_for_loop_decls,
4923 but does it make any sense for this to be included in the grammar?
4924 Note in particular that the nested function does not include a
4925 trailing ';', whereas the "declaration" production includes one.
4926 Also, can we reject bad declarations earlier and cheaper than
4927 check_for_loop_decls?
4929 In Objective-C, there are two additional variants:
4932 for ( expression in expresssion ) statement
4933 for ( declaration in expression ) statement
4935 This is inconsistent with C, because the second variant is allowed
4936 even if c99 is not enabled.
4938 The rest of the comment documents these Objective-C foreach-statement.
4940 Here is the canonical example of the first variant:
4941 for (object in array) { do something with object }
4942 we call the first expression ("object") the "object_expression" and
4943 the second expression ("array") the "collection_expression".
4944 object_expression must be an lvalue of type "id" (a generic Objective-C
4945 object) because the loop works by assigning to object_expression the
4946 various objects from the collection_expression. collection_expression
4947 must evaluate to something of type "id" which responds to the method
4948 countByEnumeratingWithState:objects:count:.
4950 The canonical example of the second variant is:
4951 for (id object in array) { do something with object }
4952 which is completely equivalent to
4955 for (object in array) { do something with object }
4957 Note that initizializing 'object' in some way (eg, "for ((object =
4958 xxx) in array) { do something with object }") is possibly
4959 technically valid, but completely pointless as 'object' will be
4960 assigned to something else as soon as the loop starts. We should
4961 most likely reject it (TODO).
4963 The beginning of the Objective-C foreach-statement looks exactly
4964 like the beginning of the for-statement, and we can tell it is a
4965 foreach-statement only because the initial declaration or
4966 expression is terminated by 'in' instead of ';'.
4970 c_parser_for_statement (c_parser
*parser
)
4972 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4973 /* The following are only used when parsing an ObjC foreach statement. */
4974 tree object_expression
;
4975 /* Silence the bogus uninitialized warning. */
4976 tree collection_expression
= NULL
;
4977 location_t loc
= c_parser_peek_token (parser
)->location
;
4978 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4979 bool is_foreach_statement
= false;
4980 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4981 c_parser_consume_token (parser
);
4982 /* Open a compound statement in Objective-C as well, just in case this is
4983 as foreach expression. */
4984 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4985 cond
= error_mark_node
;
4986 incr
= error_mark_node
;
4987 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4989 /* Parse the initialization declaration or expression. */
4990 object_expression
= error_mark_node
;
4991 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4992 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4994 parser
->objc_could_be_foreach_context
= false;
4995 c_parser_consume_token (parser
);
4996 c_finish_expr_stmt (loc
, NULL_TREE
);
4998 else if (c_parser_next_tokens_start_declaration (parser
))
5000 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5001 &object_expression
);
5002 parser
->objc_could_be_foreach_context
= false;
5004 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5006 c_parser_consume_token (parser
);
5007 is_foreach_statement
= true;
5008 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5009 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5012 check_for_loop_decls (for_loc
, flag_isoc99
);
5014 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5016 /* __extension__ can start a declaration, but is also an
5017 unary operator that can start an expression. Consume all
5018 but the last of a possible series of __extension__ to
5020 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5021 && (c_parser_peek_2nd_token (parser
)->keyword
5023 c_parser_consume_token (parser
);
5024 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5027 ext
= disable_extension_diagnostics ();
5028 c_parser_consume_token (parser
);
5029 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5030 true, &object_expression
);
5031 parser
->objc_could_be_foreach_context
= false;
5033 restore_extension_diagnostics (ext
);
5034 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5036 c_parser_consume_token (parser
);
5037 is_foreach_statement
= true;
5038 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5039 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5042 check_for_loop_decls (for_loc
, flag_isoc99
);
5051 tree init_expression
;
5052 init_expression
= c_parser_expression (parser
).value
;
5053 parser
->objc_could_be_foreach_context
= false;
5054 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5056 c_parser_consume_token (parser
);
5057 is_foreach_statement
= true;
5058 if (! lvalue_p (init_expression
))
5059 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5060 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5064 c_finish_expr_stmt (loc
, init_expression
);
5065 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5069 /* Parse the loop condition. In the case of a foreach
5070 statement, there is no loop condition. */
5071 gcc_assert (!parser
->objc_could_be_foreach_context
);
5072 if (!is_foreach_statement
)
5074 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5076 c_parser_consume_token (parser
);
5081 cond
= c_parser_condition (parser
);
5082 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5085 /* Parse the increment expression (the third expression in a
5086 for-statement). In the case of a foreach-statement, this is
5087 the expression that follows the 'in'. */
5088 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5090 if (is_foreach_statement
)
5092 c_parser_error (parser
, "missing collection in fast enumeration");
5093 collection_expression
= error_mark_node
;
5096 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5100 if (is_foreach_statement
)
5101 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5104 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5106 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5108 save_break
= c_break_label
;
5109 c_break_label
= NULL_TREE
;
5110 save_cont
= c_cont_label
;
5111 c_cont_label
= NULL_TREE
;
5112 body
= c_parser_c99_block_statement (parser
);
5113 if (is_foreach_statement
)
5114 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5116 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5117 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5118 c_break_label
= save_break
;
5119 c_cont_label
= save_cont
;
5122 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5123 statement with inputs, outputs, clobbers, and volatile tag
5127 asm type-qualifier[opt] ( asm-argument ) ;
5128 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5132 asm-string-literal : asm-operands[opt]
5133 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5134 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5137 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5140 Qualifiers other than volatile are accepted in the syntax but
5144 c_parser_asm_statement (c_parser
*parser
)
5146 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5147 bool simple
, is_goto
;
5148 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5149 int section
, nsections
;
5151 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5152 c_parser_consume_token (parser
);
5153 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5155 quals
= c_parser_peek_token (parser
)->value
;
5156 c_parser_consume_token (parser
);
5158 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5159 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5161 warning_at (c_parser_peek_token (parser
)->location
,
5163 "%E qualifier ignored on asm",
5164 c_parser_peek_token (parser
)->value
);
5166 c_parser_consume_token (parser
);
5172 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5174 c_parser_consume_token (parser
);
5178 /* ??? Follow the C++ parser rather than using the
5179 lex_untranslated_string kludge. */
5180 parser
->lex_untranslated_string
= true;
5183 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5186 str
= c_parser_asm_string_literal (parser
);
5187 if (str
== NULL_TREE
)
5188 goto error_close_paren
;
5191 outputs
= NULL_TREE
;
5193 clobbers
= NULL_TREE
;
5196 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5199 /* Parse each colon-delimited section of operands. */
5200 nsections
= 3 + is_goto
;
5201 for (section
= 0; section
< nsections
; ++section
)
5203 if (!c_parser_require (parser
, CPP_COLON
,
5206 : "expected %<:%> or %<)%>"))
5207 goto error_close_paren
;
5209 /* Once past any colon, we're no longer a simple asm. */
5212 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5213 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5218 /* For asm goto, we don't allow output operands, but reserve
5219 the slot for a future extension that does allow them. */
5221 outputs
= c_parser_asm_operands (parser
);
5224 inputs
= c_parser_asm_operands (parser
);
5227 clobbers
= c_parser_asm_clobbers (parser
);
5230 labels
= c_parser_asm_goto_operands (parser
);
5236 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5241 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5243 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5247 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5248 c_parser_skip_to_end_of_block_or_statement (parser
);
5250 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5251 clobbers
, labels
, simple
));
5254 parser
->lex_untranslated_string
= false;
5258 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5262 /* Parse asm operands, a GNU extension.
5266 asm-operands , asm-operand
5269 asm-string-literal ( expression )
5270 [ identifier ] asm-string-literal ( expression )
5274 c_parser_asm_operands (c_parser
*parser
)
5276 tree list
= NULL_TREE
;
5281 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5283 c_parser_consume_token (parser
);
5284 if (c_parser_next_token_is (parser
, CPP_NAME
))
5286 tree id
= c_parser_peek_token (parser
)->value
;
5287 c_parser_consume_token (parser
);
5288 name
= build_string (IDENTIFIER_LENGTH (id
),
5289 IDENTIFIER_POINTER (id
));
5293 c_parser_error (parser
, "expected identifier");
5294 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5297 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5302 str
= c_parser_asm_string_literal (parser
);
5303 if (str
== NULL_TREE
)
5305 parser
->lex_untranslated_string
= false;
5306 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5308 parser
->lex_untranslated_string
= true;
5311 expr
= c_parser_expression (parser
);
5312 mark_exp_read (expr
.value
);
5313 parser
->lex_untranslated_string
= true;
5314 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5316 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5319 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5321 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5322 c_parser_consume_token (parser
);
5329 /* Parse asm clobbers, a GNU extension.
5333 asm-clobbers , asm-string-literal
5337 c_parser_asm_clobbers (c_parser
*parser
)
5339 tree list
= NULL_TREE
;
5342 tree str
= c_parser_asm_string_literal (parser
);
5344 list
= tree_cons (NULL_TREE
, str
, list
);
5347 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5348 c_parser_consume_token (parser
);
5355 /* Parse asm goto labels, a GNU extension.
5359 asm-goto-operands , identifier
5363 c_parser_asm_goto_operands (c_parser
*parser
)
5365 tree list
= NULL_TREE
;
5370 if (c_parser_next_token_is (parser
, CPP_NAME
))
5372 c_token
*tok
= c_parser_peek_token (parser
);
5374 label
= lookup_label_for_goto (tok
->location
, name
);
5375 c_parser_consume_token (parser
);
5376 TREE_USED (label
) = 1;
5380 c_parser_error (parser
, "expected identifier");
5384 name
= build_string (IDENTIFIER_LENGTH (name
),
5385 IDENTIFIER_POINTER (name
));
5386 list
= tree_cons (name
, label
, list
);
5387 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5388 c_parser_consume_token (parser
);
5390 return nreverse (list
);
5394 /* Parse an expression other than a compound expression; that is, an
5395 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5396 NULL then it is an Objective-C message expression which is the
5397 primary-expression starting the expression as an initializer.
5399 assignment-expression:
5400 conditional-expression
5401 unary-expression assignment-operator assignment-expression
5403 assignment-operator: one of
5404 = *= /= %= += -= <<= >>= &= ^= |=
5406 In GNU C we accept any conditional expression on the LHS and
5407 diagnose the invalid lvalue rather than producing a syntax
5410 static struct c_expr
5411 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5413 struct c_expr lhs
, rhs
, ret
;
5414 enum tree_code code
;
5415 location_t op_location
, exp_location
;
5416 gcc_assert (!after
|| c_dialect_objc ());
5417 lhs
= c_parser_conditional_expression (parser
, after
);
5418 op_location
= c_parser_peek_token (parser
)->location
;
5419 switch (c_parser_peek_token (parser
)->type
)
5428 code
= TRUNC_DIV_EXPR
;
5431 code
= TRUNC_MOD_EXPR
;
5446 code
= BIT_AND_EXPR
;
5449 code
= BIT_XOR_EXPR
;
5452 code
= BIT_IOR_EXPR
;
5457 c_parser_consume_token (parser
);
5458 exp_location
= c_parser_peek_token (parser
)->location
;
5459 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5460 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5461 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5462 code
, exp_location
, rhs
.value
,
5464 if (code
== NOP_EXPR
)
5465 ret
.original_code
= MODIFY_EXPR
;
5468 TREE_NO_WARNING (ret
.value
) = 1;
5469 ret
.original_code
= ERROR_MARK
;
5471 ret
.original_type
= NULL
;
5475 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5476 is not NULL then it is an Objective-C message expression which is
5477 the primary-expression starting the expression as an initializer.
5479 conditional-expression:
5480 logical-OR-expression
5481 logical-OR-expression ? expression : conditional-expression
5485 conditional-expression:
5486 logical-OR-expression ? : conditional-expression
5489 static struct c_expr
5490 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5492 struct c_expr cond
, exp1
, exp2
, ret
;
5493 location_t cond_loc
, colon_loc
, middle_loc
;
5495 gcc_assert (!after
|| c_dialect_objc ());
5497 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5499 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5501 cond_loc
= c_parser_peek_token (parser
)->location
;
5502 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5503 c_parser_consume_token (parser
);
5504 if (c_parser_next_token_is (parser
, CPP_COLON
))
5506 tree eptype
= NULL_TREE
;
5508 middle_loc
= c_parser_peek_token (parser
)->location
;
5509 pedwarn (middle_loc
, OPT_Wpedantic
,
5510 "ISO C forbids omitting the middle term of a ?: expression");
5511 warn_for_omitted_condop (middle_loc
, cond
.value
);
5512 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5514 eptype
= TREE_TYPE (cond
.value
);
5515 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5517 /* Make sure first operand is calculated only once. */
5518 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5520 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5521 exp1
.original_type
= NULL
;
5522 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5523 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5528 = c_objc_common_truthvalue_conversion
5529 (cond_loc
, default_conversion (cond
.value
));
5530 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5531 exp1
= c_parser_expression_conv (parser
);
5532 mark_exp_read (exp1
.value
);
5533 c_inhibit_evaluation_warnings
+=
5534 ((cond
.value
== truthvalue_true_node
)
5535 - (cond
.value
== truthvalue_false_node
));
5538 colon_loc
= c_parser_peek_token (parser
)->location
;
5539 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5541 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5542 ret
.value
= error_mark_node
;
5543 ret
.original_code
= ERROR_MARK
;
5544 ret
.original_type
= NULL
;
5548 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5549 exp2
= c_parser_conditional_expression (parser
, NULL
);
5550 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5552 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5553 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5554 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5555 exp1
.value
, exp1
.original_type
,
5556 exp2
.value
, exp2
.original_type
);
5557 ret
.original_code
= ERROR_MARK
;
5558 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5559 ret
.original_type
= NULL
;
5564 /* If both sides are enum type, the default conversion will have
5565 made the type of the result be an integer type. We want to
5566 remember the enum types we started with. */
5567 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5568 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5569 ret
.original_type
= ((t1
!= error_mark_node
5570 && t2
!= error_mark_node
5571 && (TYPE_MAIN_VARIANT (t1
)
5572 == TYPE_MAIN_VARIANT (t2
)))
5579 /* Parse a binary expression; that is, a logical-OR-expression (C90
5580 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5581 an Objective-C message expression which is the primary-expression
5582 starting the expression as an initializer. PREC is the starting
5583 precedence, usually PREC_NONE.
5585 multiplicative-expression:
5587 multiplicative-expression * cast-expression
5588 multiplicative-expression / cast-expression
5589 multiplicative-expression % cast-expression
5591 additive-expression:
5592 multiplicative-expression
5593 additive-expression + multiplicative-expression
5594 additive-expression - multiplicative-expression
5598 shift-expression << additive-expression
5599 shift-expression >> additive-expression
5601 relational-expression:
5603 relational-expression < shift-expression
5604 relational-expression > shift-expression
5605 relational-expression <= shift-expression
5606 relational-expression >= shift-expression
5608 equality-expression:
5609 relational-expression
5610 equality-expression == relational-expression
5611 equality-expression != relational-expression
5615 AND-expression & equality-expression
5617 exclusive-OR-expression:
5619 exclusive-OR-expression ^ AND-expression
5621 inclusive-OR-expression:
5622 exclusive-OR-expression
5623 inclusive-OR-expression | exclusive-OR-expression
5625 logical-AND-expression:
5626 inclusive-OR-expression
5627 logical-AND-expression && inclusive-OR-expression
5629 logical-OR-expression:
5630 logical-AND-expression
5631 logical-OR-expression || logical-AND-expression
5634 static struct c_expr
5635 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5636 enum c_parser_prec prec
)
5638 /* A binary expression is parsed using operator-precedence parsing,
5639 with the operands being cast expressions. All the binary
5640 operators are left-associative. Thus a binary expression is of
5643 E0 op1 E1 op2 E2 ...
5645 which we represent on a stack. On the stack, the precedence
5646 levels are strictly increasing. When a new operator is
5647 encountered of higher precedence than that at the top of the
5648 stack, it is pushed; its LHS is the top expression, and its RHS
5649 is everything parsed until it is popped. When a new operator is
5650 encountered with precedence less than or equal to that at the top
5651 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5652 by the result of the operation until the operator at the top of
5653 the stack has lower precedence than the new operator or there is
5654 only one element on the stack; then the top expression is the LHS
5655 of the new operator. In the case of logical AND and OR
5656 expressions, we also need to adjust c_inhibit_evaluation_warnings
5657 as appropriate when the operators are pushed and popped. */
5660 /* The expression at this stack level. */
5662 /* The precedence of the operator on its left, PREC_NONE at the
5663 bottom of the stack. */
5664 enum c_parser_prec prec
;
5665 /* The operation on its left. */
5667 /* The source location of this operation. */
5671 /* Location of the binary operator. */
5672 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5675 switch (stack[sp].op) \
5677 case TRUTH_ANDIF_EXPR: \
5678 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5679 == truthvalue_false_node); \
5681 case TRUTH_ORIF_EXPR: \
5682 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5683 == truthvalue_true_node); \
5688 stack[sp - 1].expr \
5689 = default_function_array_read_conversion (stack[sp - 1].loc, \
5690 stack[sp - 1].expr); \
5692 = default_function_array_read_conversion (stack[sp].loc, \
5694 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5696 stack[sp - 1].expr, \
5700 gcc_assert (!after
|| c_dialect_objc ());
5701 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5702 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5703 stack
[0].prec
= prec
;
5707 enum c_parser_prec oprec
;
5708 enum tree_code ocode
;
5711 switch (c_parser_peek_token (parser
)->type
)
5719 ocode
= TRUNC_DIV_EXPR
;
5723 ocode
= TRUNC_MOD_EXPR
;
5735 ocode
= LSHIFT_EXPR
;
5739 ocode
= RSHIFT_EXPR
;
5753 case CPP_GREATER_EQ
:
5766 oprec
= PREC_BITAND
;
5767 ocode
= BIT_AND_EXPR
;
5770 oprec
= PREC_BITXOR
;
5771 ocode
= BIT_XOR_EXPR
;
5775 ocode
= BIT_IOR_EXPR
;
5778 oprec
= PREC_LOGAND
;
5779 ocode
= TRUTH_ANDIF_EXPR
;
5783 ocode
= TRUTH_ORIF_EXPR
;
5786 /* Not a binary operator, so end of the binary
5790 binary_loc
= c_parser_peek_token (parser
)->location
;
5791 while (oprec
<= stack
[sp
].prec
)
5797 c_parser_consume_token (parser
);
5800 case TRUTH_ANDIF_EXPR
:
5802 = default_function_array_read_conversion (stack
[sp
].loc
,
5804 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5805 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5806 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5807 == truthvalue_false_node
);
5809 case TRUTH_ORIF_EXPR
:
5811 = default_function_array_read_conversion (stack
[sp
].loc
,
5813 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5814 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5815 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5816 == truthvalue_true_node
);
5822 stack
[sp
].loc
= binary_loc
;
5823 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5824 stack
[sp
].prec
= oprec
;
5825 stack
[sp
].op
= ocode
;
5826 stack
[sp
].loc
= binary_loc
;
5831 return stack
[0].expr
;
5835 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5836 NULL then it is an Objective-C message expression which is the
5837 primary-expression starting the expression as an initializer.
5841 ( type-name ) unary-expression
5844 static struct c_expr
5845 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5847 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5848 gcc_assert (!after
|| c_dialect_objc ());
5850 return c_parser_postfix_expression_after_primary (parser
,
5852 /* If the expression begins with a parenthesized type name, it may
5853 be either a cast or a compound literal; we need to see whether
5854 the next character is '{' to tell the difference. If not, it is
5855 an unary expression. Full detection of unknown typenames here
5856 would require a 3-token lookahead. */
5857 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5858 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5860 struct c_type_name
*type_name
;
5863 c_parser_consume_token (parser
);
5864 type_name
= c_parser_type_name (parser
);
5865 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5866 if (type_name
== NULL
)
5868 ret
.value
= error_mark_node
;
5869 ret
.original_code
= ERROR_MARK
;
5870 ret
.original_type
= NULL
;
5874 /* Save casted types in the function's used types hash table. */
5875 used_types_insert (type_name
->specs
->type
);
5877 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5878 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5881 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5882 expr
= c_parser_cast_expression (parser
, NULL
);
5883 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5885 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5886 ret
.original_code
= ERROR_MARK
;
5887 ret
.original_type
= NULL
;
5891 return c_parser_unary_expression (parser
);
5894 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5900 unary-operator cast-expression
5901 sizeof unary-expression
5902 sizeof ( type-name )
5904 unary-operator: one of
5910 __alignof__ unary-expression
5911 __alignof__ ( type-name )
5914 (C11 permits _Alignof with type names only.)
5916 unary-operator: one of
5917 __extension__ __real__ __imag__
5919 Transactional Memory:
5922 transaction-expression
5924 In addition, the GNU syntax treats ++ and -- as unary operators, so
5925 they may be applied to cast expressions with errors for non-lvalues
5928 static struct c_expr
5929 c_parser_unary_expression (c_parser
*parser
)
5932 struct c_expr ret
, op
;
5933 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5935 ret
.original_code
= ERROR_MARK
;
5936 ret
.original_type
= NULL
;
5937 switch (c_parser_peek_token (parser
)->type
)
5940 c_parser_consume_token (parser
);
5941 exp_loc
= c_parser_peek_token (parser
)->location
;
5942 op
= c_parser_cast_expression (parser
, NULL
);
5943 op
= default_function_array_read_conversion (exp_loc
, op
);
5944 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5945 case CPP_MINUS_MINUS
:
5946 c_parser_consume_token (parser
);
5947 exp_loc
= c_parser_peek_token (parser
)->location
;
5948 op
= c_parser_cast_expression (parser
, NULL
);
5949 op
= default_function_array_read_conversion (exp_loc
, op
);
5950 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5952 c_parser_consume_token (parser
);
5953 op
= c_parser_cast_expression (parser
, NULL
);
5954 mark_exp_read (op
.value
);
5955 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5957 c_parser_consume_token (parser
);
5958 exp_loc
= c_parser_peek_token (parser
)->location
;
5959 op
= c_parser_cast_expression (parser
, NULL
);
5960 op
= default_function_array_read_conversion (exp_loc
, op
);
5961 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5964 if (!c_dialect_objc () && !in_system_header
)
5967 "traditional C rejects the unary plus operator");
5968 c_parser_consume_token (parser
);
5969 exp_loc
= c_parser_peek_token (parser
)->location
;
5970 op
= c_parser_cast_expression (parser
, NULL
);
5971 op
= default_function_array_read_conversion (exp_loc
, op
);
5972 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5974 c_parser_consume_token (parser
);
5975 exp_loc
= c_parser_peek_token (parser
)->location
;
5976 op
= c_parser_cast_expression (parser
, NULL
);
5977 op
= default_function_array_read_conversion (exp_loc
, op
);
5978 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5980 c_parser_consume_token (parser
);
5981 exp_loc
= c_parser_peek_token (parser
)->location
;
5982 op
= c_parser_cast_expression (parser
, NULL
);
5983 op
= default_function_array_read_conversion (exp_loc
, op
);
5984 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5986 c_parser_consume_token (parser
);
5987 exp_loc
= c_parser_peek_token (parser
)->location
;
5988 op
= c_parser_cast_expression (parser
, NULL
);
5989 op
= default_function_array_read_conversion (exp_loc
, op
);
5990 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5992 /* Refer to the address of a label as a pointer. */
5993 c_parser_consume_token (parser
);
5994 if (c_parser_next_token_is (parser
, CPP_NAME
))
5996 ret
.value
= finish_label_address_expr
5997 (c_parser_peek_token (parser
)->value
, op_loc
);
5998 c_parser_consume_token (parser
);
6002 c_parser_error (parser
, "expected identifier");
6003 ret
.value
= error_mark_node
;
6007 switch (c_parser_peek_token (parser
)->keyword
)
6010 return c_parser_sizeof_expression (parser
);
6011 case RID_UPC_BLOCKSIZEOF
:
6012 case RID_UPC_ELEMSIZEOF
:
6013 case RID_UPC_LOCALSIZEOF
:
6014 gcc_assert (c_dialect_upc ());
6015 return c_parser_sizeof_expression (parser
);
6017 return c_parser_alignof_expression (parser
);
6019 c_parser_consume_token (parser
);
6020 ext
= disable_extension_diagnostics ();
6021 ret
= c_parser_cast_expression (parser
, NULL
);
6022 restore_extension_diagnostics (ext
);
6025 c_parser_consume_token (parser
);
6026 exp_loc
= c_parser_peek_token (parser
)->location
;
6027 op
= c_parser_cast_expression (parser
, NULL
);
6028 op
= default_function_array_conversion (exp_loc
, op
);
6029 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6031 c_parser_consume_token (parser
);
6032 exp_loc
= c_parser_peek_token (parser
)->location
;
6033 op
= c_parser_cast_expression (parser
, NULL
);
6034 op
= default_function_array_conversion (exp_loc
, op
);
6035 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6036 case RID_TRANSACTION_ATOMIC
:
6037 case RID_TRANSACTION_RELAXED
:
6038 return c_parser_transaction_expression (parser
,
6039 c_parser_peek_token (parser
)->keyword
);
6041 return c_parser_postfix_expression (parser
);
6044 return c_parser_postfix_expression (parser
);
6048 /* Return the result of upc_blocksizeof applied to EXPR. */
6052 upc_blocksizeof_expr (location_t loc
, struct c_expr expr
)
6055 ret
.original_code
= ERROR_MARK
;
6056 ret
.original_type
= NULL_TREE
;
6057 if (expr
.value
== error_mark_node
)
6059 ret
.value
= error_mark_node
;
6060 pop_maybe_used (false);
6064 ret
.value
= upc_blocksizeof (loc
, TREE_TYPE (expr
.value
));
6065 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6070 /* Return the result of upc_blocksizeof applied to T, a structure
6071 for the type name passed to sizeof (rather than the type itself). */
6075 upc_blocksizeof_type (location_t loc
, struct c_type_name
*t
)
6079 ret
.original_code
= ERROR_MARK
;
6080 ret
.original_type
= NULL_TREE
;
6081 type
= groktypename (t
, NULL
, NULL
);
6082 if (type
== error_mark_node
)
6084 ret
.value
= error_mark_node
;
6085 pop_maybe_used (false);
6089 ret
.value
= upc_blocksizeof (loc
, type
);
6090 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6095 /* Return the result of upc_elemsizeof applied to EXPR. */
6099 upc_elemsizeof_expr (location_t loc
, struct c_expr expr
)
6102 ret
.original_code
= ERROR_MARK
;
6103 ret
.original_type
= NULL_TREE
;
6104 if (expr
.value
== error_mark_node
)
6106 ret
.value
= error_mark_node
;
6107 pop_maybe_used (false);
6111 ret
.value
= upc_elemsizeof (loc
, TREE_TYPE (expr
.value
));
6112 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6117 /* Return the result of upc_elemsizeof applied to T, a structure
6118 for the type name passed to sizeof (rather than the type itself). */
6122 upc_elemsizeof_type (location_t loc
, struct c_type_name
*t
)
6126 ret
.original_code
= ERROR_MARK
;
6127 ret
.original_type
= NULL_TREE
;
6128 type
= groktypename (t
, NULL
, NULL
);
6129 if (type
== error_mark_node
)
6131 ret
.value
= error_mark_node
;
6132 pop_maybe_used (false);
6136 ret
.value
= upc_elemsizeof (loc
, type
);
6137 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6142 /* Return the result of upc_localsizeof applied to EXPR. */
6146 upc_localsizeof_expr (location_t loc
, struct c_expr expr
)
6149 ret
.original_code
= ERROR_MARK
;
6150 ret
.original_type
= NULL_TREE
;
6151 if (expr
.value
== error_mark_node
)
6153 ret
.value
= error_mark_node
;
6154 pop_maybe_used (false);
6158 ret
.value
= upc_localsizeof (loc
, TREE_TYPE (expr
.value
));
6159 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6164 /* Return the result of upc_localsizeof applied to T, a structure
6165 for the type name passed to sizeof (rather than the type itself). */
6169 upc_localsizeof_type (location_t loc
, struct c_type_name
*t
)
6173 ret
.original_code
= ERROR_MARK
;
6174 ret
.original_type
= NULL_TREE
;
6175 type
= groktypename (t
, NULL
, NULL
);
6176 if (type
== error_mark_node
)
6178 ret
.value
= error_mark_node
;
6179 pop_maybe_used (false);
6183 ret
.value
= upc_localsizeof (loc
, type
);
6184 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6189 /* Parse a sizeof expression. */
6191 static struct c_expr
6192 c_parser_sizeof_expression (c_parser
*parser
)
6195 location_t expr_loc
;
6196 enum rid keyword
= c_parser_peek_token (parser
)->keyword
;
6197 c_parser_consume_token (parser
);
6198 c_inhibit_evaluation_warnings
++;
6200 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6201 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6203 /* Either sizeof ( type-name ) or sizeof unary-expression
6204 starting with a compound literal. */
6205 struct c_type_name
*type_name
;
6206 c_parser_consume_token (parser
);
6207 expr_loc
= c_parser_peek_token (parser
)->location
;
6208 type_name
= c_parser_type_name (parser
);
6209 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6210 if (type_name
== NULL
)
6213 c_inhibit_evaluation_warnings
--;
6215 ret
.value
= error_mark_node
;
6216 ret
.original_code
= ERROR_MARK
;
6217 ret
.original_type
= NULL
;
6220 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6222 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6227 /* sizeof ( type-name ). */
6228 c_inhibit_evaluation_warnings
--;
6230 /* Handle upc_*_sizeof (type) operations. */
6233 case RID_UPC_BLOCKSIZEOF
:
6234 return upc_blocksizeof_type (expr_loc
, type_name
);
6235 case RID_UPC_ELEMSIZEOF
:
6236 return upc_elemsizeof_type (expr_loc
, type_name
);
6237 case RID_UPC_LOCALSIZEOF
:
6238 return upc_localsizeof_type (expr_loc
, type_name
);
6241 return c_expr_sizeof_type (expr_loc
, type_name
);
6245 expr_loc
= c_parser_peek_token (parser
)->location
;
6246 expr
= c_parser_unary_expression (parser
);
6248 c_inhibit_evaluation_warnings
--;
6250 mark_exp_read (expr
.value
);
6251 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6252 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6253 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6254 /* Handle upc_*_sizeof (expr) operations. */
6257 case RID_UPC_BLOCKSIZEOF
:
6258 return upc_blocksizeof_expr (expr_loc
, expr
);
6259 case RID_UPC_ELEMSIZEOF
:
6260 return upc_elemsizeof_expr (expr_loc
, expr
);
6261 case RID_UPC_LOCALSIZEOF
:
6262 return upc_localsizeof_expr (expr_loc
, expr
);
6264 return c_expr_sizeof_expr (expr_loc
, expr
);
6267 return c_expr_sizeof_expr (expr_loc
, expr
);
6271 /* Parse an alignof expression. */
6273 static struct c_expr
6274 c_parser_alignof_expression (c_parser
*parser
)
6277 location_t loc
= c_parser_peek_token (parser
)->location
;
6278 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6279 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6280 /* A diagnostic is not required for the use of this identifier in
6281 the implementation namespace; only diagnose it for the C11
6282 spelling because of existing code using the other spellings. */
6284 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6287 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6290 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6293 c_parser_consume_token (parser
);
6294 c_inhibit_evaluation_warnings
++;
6296 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6297 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6299 /* Either __alignof__ ( type-name ) or __alignof__
6300 unary-expression starting with a compound literal. */
6302 struct c_type_name
*type_name
;
6304 c_parser_consume_token (parser
);
6305 loc
= c_parser_peek_token (parser
)->location
;
6306 type_name
= c_parser_type_name (parser
);
6307 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6308 if (type_name
== NULL
)
6311 c_inhibit_evaluation_warnings
--;
6313 ret
.value
= error_mark_node
;
6314 ret
.original_code
= ERROR_MARK
;
6315 ret
.original_type
= NULL
;
6318 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6320 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6325 /* alignof ( type-name ). */
6326 c_inhibit_evaluation_warnings
--;
6328 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6329 ret
.original_code
= ERROR_MARK
;
6330 ret
.original_type
= NULL
;
6336 expr
= c_parser_unary_expression (parser
);
6338 mark_exp_read (expr
.value
);
6339 c_inhibit_evaluation_warnings
--;
6341 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6343 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6344 ret
.original_code
= ERROR_MARK
;
6345 ret
.original_type
= NULL
;
6350 /* Helper function to read arguments of builtins which are interfaces
6351 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6352 others. The name of the builtin is passed using BNAME parameter.
6353 Function returns true if there were no errors while parsing and
6354 stores the arguments in CEXPR_LIST. */
6356 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6357 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
)
6359 location_t loc
= c_parser_peek_token (parser
)->location
;
6360 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6363 *ret_cexpr_list
= NULL
;
6364 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6366 error_at (loc
, "cannot take address of %qs", bname
);
6370 c_parser_consume_token (parser
);
6372 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6374 c_parser_consume_token (parser
);
6378 expr
= c_parser_expr_no_commas (parser
, NULL
);
6379 vec_alloc (cexpr_list
, 1);
6380 C_EXPR_APPEND (cexpr_list
, expr
);
6381 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6383 c_parser_consume_token (parser
);
6384 expr
= c_parser_expr_no_commas (parser
, NULL
);
6385 C_EXPR_APPEND (cexpr_list
, expr
);
6388 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6391 *ret_cexpr_list
= cexpr_list
;
6396 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6400 postfix-expression [ expression ]
6401 postfix-expression ( argument-expression-list[opt] )
6402 postfix-expression . identifier
6403 postfix-expression -> identifier
6404 postfix-expression ++
6405 postfix-expression --
6406 ( type-name ) { initializer-list }
6407 ( type-name ) { initializer-list , }
6409 argument-expression-list:
6411 argument-expression-list , argument-expression
6423 (treated as a keyword in GNU C)
6426 ( compound-statement )
6427 __builtin_va_arg ( assignment-expression , type-name )
6428 __builtin_offsetof ( type-name , offsetof-member-designator )
6429 __builtin_choose_expr ( assignment-expression ,
6430 assignment-expression ,
6431 assignment-expression )
6432 __builtin_types_compatible_p ( type-name , type-name )
6433 __builtin_complex ( assignment-expression , assignment-expression )
6434 __builtin_shuffle ( assignment-expression , assignment-expression )
6435 __builtin_shuffle ( assignment-expression ,
6436 assignment-expression ,
6437 assignment-expression, )
6439 offsetof-member-designator:
6441 offsetof-member-designator . identifier
6442 offsetof-member-designator [ expression ]
6447 [ objc-receiver objc-message-args ]
6448 @selector ( objc-selector-arg )
6449 @protocol ( identifier )
6450 @encode ( type-name )
6452 Classname . identifier
6455 static struct c_expr
6456 c_parser_postfix_expression (c_parser
*parser
)
6458 struct c_expr expr
, e1
;
6459 struct c_type_name
*t1
, *t2
;
6460 location_t loc
= c_parser_peek_token (parser
)->location
;;
6461 expr
.original_code
= ERROR_MARK
;
6462 expr
.original_type
= NULL
;
6463 switch (c_parser_peek_token (parser
)->type
)
6466 expr
.value
= c_parser_peek_token (parser
)->value
;
6467 loc
= c_parser_peek_token (parser
)->location
;
6468 c_parser_consume_token (parser
);
6469 if (TREE_CODE (expr
.value
) == FIXED_CST
6470 && !targetm
.fixed_point_supported_p ())
6472 error_at (loc
, "fixed-point types not supported for this target");
6473 expr
.value
= error_mark_node
;
6480 expr
.value
= c_parser_peek_token (parser
)->value
;
6481 c_parser_consume_token (parser
);
6487 case CPP_UTF8STRING
:
6488 expr
.value
= c_parser_peek_token (parser
)->value
;
6489 expr
.original_code
= STRING_CST
;
6490 c_parser_consume_token (parser
);
6492 case CPP_OBJC_STRING
:
6493 gcc_assert (c_dialect_objc ());
6495 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6496 c_parser_consume_token (parser
);
6499 switch (c_parser_peek_token (parser
)->id_kind
)
6503 tree id
= c_parser_peek_token (parser
)->value
;
6504 c_parser_consume_token (parser
);
6505 expr
.value
= build_external_ref (loc
, id
,
6506 (c_parser_peek_token (parser
)->type
6508 &expr
.original_type
);
6511 case C_ID_CLASSNAME
:
6513 /* Here we parse the Objective-C 2.0 Class.name dot
6515 tree class_name
= c_parser_peek_token (parser
)->value
;
6517 c_parser_consume_token (parser
);
6518 gcc_assert (c_dialect_objc ());
6519 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6521 expr
.value
= error_mark_node
;
6524 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6526 c_parser_error (parser
, "expected identifier");
6527 expr
.value
= error_mark_node
;
6530 component
= c_parser_peek_token (parser
)->value
;
6531 c_parser_consume_token (parser
);
6532 expr
.value
= objc_build_class_component_ref (class_name
,
6537 c_parser_error (parser
, "expected expression");
6538 expr
.value
= error_mark_node
;
6542 case CPP_OPEN_PAREN
:
6543 /* A parenthesized expression, statement expression or compound
6545 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6547 /* A statement expression. */
6549 location_t brace_loc
;
6550 c_parser_consume_token (parser
);
6551 brace_loc
= c_parser_peek_token (parser
)->location
;
6552 c_parser_consume_token (parser
);
6553 if (!building_stmt_list_p ())
6555 error_at (loc
, "braced-group within expression allowed "
6556 "only inside a function");
6557 parser
->error
= true;
6558 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6559 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6560 expr
.value
= error_mark_node
;
6563 stmt
= c_begin_stmt_expr ();
6564 c_parser_compound_statement_nostart (parser
);
6565 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6567 pedwarn (loc
, OPT_Wpedantic
,
6568 "ISO C forbids braced-groups within expressions");
6569 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6570 mark_exp_read (expr
.value
);
6572 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6574 /* A compound literal. ??? Can we actually get here rather
6575 than going directly to
6576 c_parser_postfix_expression_after_paren_type from
6579 struct c_type_name
*type_name
;
6580 c_parser_consume_token (parser
);
6581 loc
= c_parser_peek_token (parser
)->location
;
6582 type_name
= c_parser_type_name (parser
);
6583 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6585 if (type_name
== NULL
)
6587 expr
.value
= error_mark_node
;
6590 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6596 /* A parenthesized expression. */
6597 c_parser_consume_token (parser
);
6598 expr
= c_parser_expression (parser
);
6599 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6600 TREE_NO_WARNING (expr
.value
) = 1;
6601 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6602 expr
.original_code
= ERROR_MARK
;
6603 /* Don't change EXPR.ORIGINAL_TYPE. */
6604 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6609 switch (c_parser_peek_token (parser
)->keyword
)
6611 case RID_FUNCTION_NAME
:
6612 case RID_PRETTY_FUNCTION_NAME
:
6613 case RID_C99_FUNCTION_NAME
:
6614 expr
.value
= fname_decl (loc
,
6615 c_parser_peek_token (parser
)->keyword
,
6616 c_parser_peek_token (parser
)->value
);
6617 c_parser_consume_token (parser
);
6620 c_parser_consume_token (parser
);
6621 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6623 expr
.value
= error_mark_node
;
6626 e1
= c_parser_expr_no_commas (parser
, NULL
);
6627 mark_exp_read (e1
.value
);
6628 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6629 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6631 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6632 expr
.value
= error_mark_node
;
6635 loc
= c_parser_peek_token (parser
)->location
;
6636 t1
= c_parser_type_name (parser
);
6637 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6641 expr
.value
= error_mark_node
;
6645 tree type_expr
= NULL_TREE
;
6646 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6647 groktypename (t1
, &type_expr
, NULL
));
6650 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6651 TREE_TYPE (expr
.value
), type_expr
,
6653 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6658 c_parser_consume_token (parser
);
6659 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6661 expr
.value
= error_mark_node
;
6664 t1
= c_parser_type_name (parser
);
6666 parser
->error
= true;
6667 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6668 gcc_assert (parser
->error
);
6671 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6672 expr
.value
= error_mark_node
;
6677 tree type
= groktypename (t1
, NULL
, NULL
);
6679 if (type
== error_mark_node
)
6680 offsetof_ref
= error_mark_node
;
6683 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6684 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6686 /* Parse the second argument to __builtin_offsetof. We
6687 must have one identifier, and beyond that we want to
6688 accept sub structure and sub array references. */
6689 if (c_parser_next_token_is (parser
, CPP_NAME
))
6691 offsetof_ref
= build_component_ref
6692 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6693 c_parser_consume_token (parser
);
6694 while (c_parser_next_token_is (parser
, CPP_DOT
)
6695 || c_parser_next_token_is (parser
,
6697 || c_parser_next_token_is (parser
,
6700 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6702 loc
= c_parser_peek_token (parser
)->location
;
6703 offsetof_ref
= build_array_ref (loc
,
6708 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6711 c_parser_consume_token (parser
);
6712 if (c_parser_next_token_is_not (parser
,
6715 c_parser_error (parser
, "expected identifier");
6718 offsetof_ref
= build_component_ref
6720 c_parser_peek_token (parser
)->value
);
6721 c_parser_consume_token (parser
);
6726 loc
= c_parser_peek_token (parser
)->location
;
6727 c_parser_consume_token (parser
);
6728 idx
= c_parser_expression (parser
).value
;
6729 idx
= c_fully_fold (idx
, false, NULL
);
6730 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6732 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6737 c_parser_error (parser
, "expected identifier");
6738 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6740 expr
.value
= fold_offsetof (offsetof_ref
);
6743 case RID_CHOOSE_EXPR
:
6745 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6746 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6749 c_parser_consume_token (parser
);
6750 if (!c_parser_get_builtin_args (parser
,
6751 "__builtin_choose_expr",
6754 expr
.value
= error_mark_node
;
6758 if (vec_safe_length (cexpr_list
) != 3)
6760 error_at (loc
, "wrong number of arguments to "
6761 "%<__builtin_choose_expr%>");
6762 expr
.value
= error_mark_node
;
6766 e1_p
= &(*cexpr_list
)[0];
6767 e2_p
= &(*cexpr_list
)[1];
6768 e3_p
= &(*cexpr_list
)[2];
6771 mark_exp_read (e2_p
->value
);
6772 mark_exp_read (e3_p
->value
);
6773 if (TREE_CODE (c
) != INTEGER_CST
6774 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6776 "first argument to %<__builtin_choose_expr%> not"
6778 constant_expression_warning (c
);
6779 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6782 case RID_TYPES_COMPATIBLE_P
:
6783 c_parser_consume_token (parser
);
6784 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6786 expr
.value
= error_mark_node
;
6789 t1
= c_parser_type_name (parser
);
6792 expr
.value
= error_mark_node
;
6795 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6797 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6798 expr
.value
= error_mark_node
;
6801 t2
= c_parser_type_name (parser
);
6804 expr
.value
= error_mark_node
;
6807 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6811 e1
= groktypename (t1
, NULL
, NULL
);
6812 e2
= groktypename (t2
, NULL
, NULL
);
6813 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6815 expr
.value
= error_mark_node
;
6819 e1
= TYPE_MAIN_VARIANT (e1
);
6820 e2
= TYPE_MAIN_VARIANT (e2
);
6823 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6826 case RID_BUILTIN_COMPLEX
:
6828 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6829 c_expr_t
*e1_p
, *e2_p
;
6831 c_parser_consume_token (parser
);
6832 if (!c_parser_get_builtin_args (parser
,
6833 "__builtin_complex",
6836 expr
.value
= error_mark_node
;
6840 if (vec_safe_length (cexpr_list
) != 2)
6842 error_at (loc
, "wrong number of arguments to "
6843 "%<__builtin_complex%>");
6844 expr
.value
= error_mark_node
;
6848 e1_p
= &(*cexpr_list
)[0];
6849 e2_p
= &(*cexpr_list
)[1];
6851 mark_exp_read (e1_p
->value
);
6852 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
6853 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
6854 TREE_OPERAND (e1_p
->value
, 0));
6855 mark_exp_read (e2_p
->value
);
6856 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
6857 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
6858 TREE_OPERAND (e2_p
->value
, 0));
6859 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6860 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6861 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
6862 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
6864 error_at (loc
, "%<__builtin_complex%> operand "
6865 "not of real binary floating-point type");
6866 expr
.value
= error_mark_node
;
6869 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
6870 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
6873 "%<__builtin_complex%> operands of different types");
6874 expr
.value
= error_mark_node
;
6878 pedwarn (loc
, OPT_Wpedantic
,
6879 "ISO C90 does not support complex types");
6880 expr
.value
= build2 (COMPLEX_EXPR
,
6883 (TREE_TYPE (e1_p
->value
))),
6884 e1_p
->value
, e2_p
->value
);
6887 case RID_BUILTIN_SHUFFLE
:
6889 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6893 c_parser_consume_token (parser
);
6894 if (!c_parser_get_builtin_args (parser
,
6895 "__builtin_shuffle",
6898 expr
.value
= error_mark_node
;
6902 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
6903 mark_exp_read (p
->value
);
6905 if (vec_safe_length (cexpr_list
) == 2)
6907 c_build_vec_perm_expr
6908 (loc
, (*cexpr_list
)[0].value
,
6909 NULL_TREE
, (*cexpr_list
)[1].value
);
6911 else if (vec_safe_length (cexpr_list
) == 3)
6913 c_build_vec_perm_expr
6914 (loc
, (*cexpr_list
)[0].value
,
6915 (*cexpr_list
)[1].value
,
6916 (*cexpr_list
)[2].value
);
6919 error_at (loc
, "wrong number of arguments to "
6920 "%<__builtin_shuffle%>");
6921 expr
.value
= error_mark_node
;
6925 case RID_AT_SELECTOR
:
6926 gcc_assert (c_dialect_objc ());
6927 c_parser_consume_token (parser
);
6928 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6930 expr
.value
= error_mark_node
;
6934 tree sel
= c_parser_objc_selector_arg (parser
);
6935 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6937 expr
.value
= objc_build_selector_expr (loc
, sel
);
6940 case RID_AT_PROTOCOL
:
6941 gcc_assert (c_dialect_objc ());
6942 c_parser_consume_token (parser
);
6943 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6945 expr
.value
= error_mark_node
;
6948 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6950 c_parser_error (parser
, "expected identifier");
6951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6952 expr
.value
= error_mark_node
;
6956 tree id
= c_parser_peek_token (parser
)->value
;
6957 c_parser_consume_token (parser
);
6958 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6960 expr
.value
= objc_build_protocol_expr (id
);
6964 /* Extension to support C-structures in the archiver. */
6965 gcc_assert (c_dialect_objc ());
6966 c_parser_consume_token (parser
);
6967 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6969 expr
.value
= error_mark_node
;
6972 t1
= c_parser_type_name (parser
);
6975 expr
.value
= error_mark_node
;
6976 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6979 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6982 tree type
= groktypename (t1
, NULL
, NULL
);
6983 expr
.value
= objc_build_encode_expr (type
);
6987 c_parser_error (parser
, "expected expression");
6988 expr
.value
= error_mark_node
;
6992 case CPP_OPEN_SQUARE
:
6993 if (c_dialect_objc ())
6995 tree receiver
, args
;
6996 c_parser_consume_token (parser
);
6997 receiver
= c_parser_objc_receiver (parser
);
6998 args
= c_parser_objc_message_args (parser
);
6999 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7001 expr
.value
= objc_build_message_expr (receiver
, args
);
7004 /* Else fall through to report error. */
7006 c_parser_error (parser
, "expected expression");
7007 expr
.value
= error_mark_node
;
7010 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7013 /* Parse a postfix expression after a parenthesized type name: the
7014 brace-enclosed initializer of a compound literal, possibly followed
7015 by some postfix operators. This is separate because it is not
7016 possible to tell until after the type name whether a cast
7017 expression has a cast or a compound literal, or whether the operand
7018 of sizeof is a parenthesized type name or starts with a compound
7019 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7020 location of the first token after the parentheses around the type
7023 static struct c_expr
7024 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7025 struct c_type_name
*type_name
,
7026 location_t type_loc
)
7032 location_t start_loc
;
7033 tree type_expr
= NULL_TREE
;
7034 bool type_expr_const
= true;
7035 check_compound_literal_type (type_loc
, type_name
);
7036 start_init (NULL_TREE
, NULL
, 0);
7037 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7038 start_loc
= c_parser_peek_token (parser
)->location
;
7039 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7041 error_at (type_loc
, "compound literal has variable size");
7042 type
= error_mark_node
;
7044 init
= c_parser_braced_init (parser
, type
, false);
7046 maybe_warn_string_init (type
, init
);
7048 if (type
!= error_mark_node
7049 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7050 && current_function_decl
)
7052 error ("compound literal qualified by address-space qualifier");
7053 type
= error_mark_node
;
7057 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7058 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7059 ? CONSTRUCTOR_NON_CONST (init
.value
)
7060 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7061 non_const
|= !type_expr_const
;
7062 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7063 expr
.original_code
= ERROR_MARK
;
7064 expr
.original_type
= NULL
;
7067 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7069 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7070 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7074 gcc_assert (!non_const
);
7075 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7076 type_expr
, expr
.value
);
7079 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7082 /* Callback function for sizeof_pointer_memaccess_warning to compare
7086 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7088 return comptypes (type1
, type2
) == 1;
7091 /* Parse a postfix expression after the initial primary or compound
7092 literal; that is, parse a series of postfix operators.
7094 EXPR_LOC is the location of the primary expression. */
7096 static struct c_expr
7097 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7098 location_t expr_loc
,
7101 struct c_expr orig_expr
;
7103 location_t sizeof_arg_loc
[3];
7106 vec
<tree
, va_gc
> *exprlist
;
7107 vec
<tree
, va_gc
> *origtypes
;
7110 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7111 switch (c_parser_peek_token (parser
)->type
)
7113 case CPP_OPEN_SQUARE
:
7114 /* Array reference. */
7115 c_parser_consume_token (parser
);
7116 idx
= c_parser_expression (parser
).value
;
7117 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7119 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7120 expr
.original_code
= ERROR_MARK
;
7121 expr
.original_type
= NULL
;
7123 case CPP_OPEN_PAREN
:
7124 /* Function call. */
7125 c_parser_consume_token (parser
);
7126 for (i
= 0; i
< 3; i
++)
7128 sizeof_arg
[i
] = NULL_TREE
;
7129 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7131 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7134 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7135 sizeof_arg_loc
, sizeof_arg
);
7136 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7139 mark_exp_read (expr
.value
);
7140 if (warn_sizeof_pointer_memaccess
)
7141 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7142 expr
.value
, exprlist
,
7144 sizeof_ptr_memacc_comptypes
);
7145 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7146 "(" after the FUNCNAME, which is what we have now. */
7147 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7149 expr
.original_code
= ERROR_MARK
;
7150 if (TREE_CODE (expr
.value
) == INTEGER_CST
7151 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7152 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7153 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7154 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7155 expr
.original_type
= NULL
;
7158 release_tree_vector (exprlist
);
7159 release_tree_vector (origtypes
);
7163 /* Structure element reference. */
7164 c_parser_consume_token (parser
);
7165 expr
= default_function_array_conversion (expr_loc
, expr
);
7166 if (c_parser_next_token_is (parser
, CPP_NAME
))
7167 ident
= c_parser_peek_token (parser
)->value
;
7170 c_parser_error (parser
, "expected identifier");
7171 expr
.value
= error_mark_node
;
7172 expr
.original_code
= ERROR_MARK
;
7173 expr
.original_type
= NULL
;
7176 c_parser_consume_token (parser
);
7177 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7178 expr
.original_code
= ERROR_MARK
;
7179 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7180 expr
.original_type
= NULL
;
7183 /* Remember the original type of a bitfield. */
7184 tree field
= TREE_OPERAND (expr
.value
, 1);
7185 if (TREE_CODE (field
) != FIELD_DECL
)
7186 expr
.original_type
= NULL
;
7188 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7192 /* Structure element reference. */
7193 c_parser_consume_token (parser
);
7194 expr
= default_function_array_conversion (expr_loc
, expr
);
7195 if (c_parser_next_token_is (parser
, CPP_NAME
))
7196 ident
= c_parser_peek_token (parser
)->value
;
7199 c_parser_error (parser
, "expected identifier");
7200 expr
.value
= error_mark_node
;
7201 expr
.original_code
= ERROR_MARK
;
7202 expr
.original_type
= NULL
;
7205 c_parser_consume_token (parser
);
7206 expr
.value
= build_component_ref (op_loc
,
7207 build_indirect_ref (op_loc
,
7211 expr
.original_code
= ERROR_MARK
;
7212 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7213 expr
.original_type
= NULL
;
7216 /* Remember the original type of a bitfield. */
7217 tree field
= TREE_OPERAND (expr
.value
, 1);
7218 if (TREE_CODE (field
) != FIELD_DECL
)
7219 expr
.original_type
= NULL
;
7221 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7225 /* Postincrement. */
7226 c_parser_consume_token (parser
);
7227 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7228 expr
.value
= build_unary_op (op_loc
,
7229 POSTINCREMENT_EXPR
, expr
.value
, 0);
7230 expr
.original_code
= ERROR_MARK
;
7231 expr
.original_type
= NULL
;
7233 case CPP_MINUS_MINUS
:
7234 /* Postdecrement. */
7235 c_parser_consume_token (parser
);
7236 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7237 expr
.value
= build_unary_op (op_loc
,
7238 POSTDECREMENT_EXPR
, expr
.value
, 0);
7239 expr
.original_code
= ERROR_MARK
;
7240 expr
.original_type
= NULL
;
7248 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7251 assignment-expression
7252 expression , assignment-expression
7255 static struct c_expr
7256 c_parser_expression (c_parser
*parser
)
7259 expr
= c_parser_expr_no_commas (parser
, NULL
);
7260 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7264 location_t loc
= c_parser_peek_token (parser
)->location
;
7265 location_t expr_loc
;
7266 c_parser_consume_token (parser
);
7267 expr_loc
= c_parser_peek_token (parser
)->location
;
7268 lhsval
= expr
.value
;
7269 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7270 lhsval
= TREE_OPERAND (lhsval
, 1);
7271 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7272 mark_exp_read (lhsval
);
7273 next
= c_parser_expr_no_commas (parser
, NULL
);
7274 next
= default_function_array_conversion (expr_loc
, next
);
7275 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7276 expr
.original_code
= COMPOUND_EXPR
;
7277 expr
.original_type
= next
.original_type
;
7282 /* Parse an expression and convert functions or arrays to
7285 static struct c_expr
7286 c_parser_expression_conv (c_parser
*parser
)
7289 location_t loc
= c_parser_peek_token (parser
)->location
;
7290 expr
= c_parser_expression (parser
);
7291 expr
= default_function_array_conversion (loc
, expr
);
7295 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7296 functions and arrays to pointers. If FOLD_P, fold the expressions.
7299 assignment-expression
7300 nonempty-expr-list , assignment-expression
7303 static vec
<tree
, va_gc
> *
7304 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7305 vec
<tree
, va_gc
> **p_orig_types
,
7306 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7308 vec
<tree
, va_gc
> *ret
;
7309 vec
<tree
, va_gc
> *orig_types
;
7311 location_t loc
= c_parser_peek_token (parser
)->location
;
7312 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7313 unsigned int idx
= 0;
7315 ret
= make_tree_vector ();
7316 if (p_orig_types
== NULL
)
7319 orig_types
= make_tree_vector ();
7321 if (sizeof_arg
!= NULL
7322 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7323 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7324 expr
= c_parser_expr_no_commas (parser
, NULL
);
7326 expr
= default_function_array_read_conversion (loc
, expr
);
7328 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7329 ret
->quick_push (expr
.value
);
7331 orig_types
->quick_push (expr
.original_type
);
7332 if (sizeof_arg
!= NULL
7333 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7334 && expr
.original_code
== SIZEOF_EXPR
)
7336 sizeof_arg
[0] = c_last_sizeof_arg
;
7337 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7339 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7341 c_parser_consume_token (parser
);
7342 loc
= c_parser_peek_token (parser
)->location
;
7343 if (sizeof_arg
!= NULL
7344 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7345 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7347 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7348 expr
= c_parser_expr_no_commas (parser
, NULL
);
7350 expr
= default_function_array_read_conversion (loc
, expr
);
7352 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7353 vec_safe_push (ret
, expr
.value
);
7355 vec_safe_push (orig_types
, expr
.original_type
);
7357 && sizeof_arg
!= NULL
7358 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7359 && expr
.original_code
== SIZEOF_EXPR
)
7361 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7362 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7366 *p_orig_types
= orig_types
;
7370 /* Parse Objective-C-specific constructs. */
7372 /* Parse an objc-class-definition.
7374 objc-class-definition:
7375 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7376 objc-class-instance-variables[opt] objc-methodprotolist @end
7377 @implementation identifier objc-superclass[opt]
7378 objc-class-instance-variables[opt]
7379 @interface identifier ( identifier ) objc-protocol-refs[opt]
7380 objc-methodprotolist @end
7381 @interface identifier ( ) objc-protocol-refs[opt]
7382 objc-methodprotolist @end
7383 @implementation identifier ( identifier )
7388 "@interface identifier (" must start "@interface identifier (
7389 identifier ) ...": objc-methodprotolist in the first production may
7390 not start with a parenthesized identifier as a declarator of a data
7391 definition with no declaration specifiers if the objc-superclass,
7392 objc-protocol-refs and objc-class-instance-variables are omitted. */
7395 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7400 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7402 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7407 c_parser_consume_token (parser
);
7408 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7410 c_parser_error (parser
, "expected identifier");
7413 id1
= c_parser_peek_token (parser
)->value
;
7414 c_parser_consume_token (parser
);
7415 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7417 /* We have a category or class extension. */
7419 tree proto
= NULL_TREE
;
7420 c_parser_consume_token (parser
);
7421 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7423 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7425 /* We have a class extension. */
7430 c_parser_error (parser
, "expected identifier or %<)%>");
7431 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7437 id2
= c_parser_peek_token (parser
)->value
;
7438 c_parser_consume_token (parser
);
7440 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7443 objc_start_category_implementation (id1
, id2
);
7446 if (c_parser_next_token_is (parser
, CPP_LESS
))
7447 proto
= c_parser_objc_protocol_refs (parser
);
7448 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7449 c_parser_objc_methodprotolist (parser
);
7450 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7451 objc_finish_interface ();
7454 if (c_parser_next_token_is (parser
, CPP_COLON
))
7456 c_parser_consume_token (parser
);
7457 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7459 c_parser_error (parser
, "expected identifier");
7462 superclass
= c_parser_peek_token (parser
)->value
;
7463 c_parser_consume_token (parser
);
7466 superclass
= NULL_TREE
;
7469 tree proto
= NULL_TREE
;
7470 if (c_parser_next_token_is (parser
, CPP_LESS
))
7471 proto
= c_parser_objc_protocol_refs (parser
);
7472 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7475 objc_start_class_implementation (id1
, superclass
);
7476 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7477 c_parser_objc_class_instance_variables (parser
);
7480 objc_continue_interface ();
7481 c_parser_objc_methodprotolist (parser
);
7482 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7483 objc_finish_interface ();
7487 objc_continue_implementation ();
7492 /* Parse objc-class-instance-variables.
7494 objc-class-instance-variables:
7495 { objc-instance-variable-decl-list[opt] }
7497 objc-instance-variable-decl-list:
7498 objc-visibility-spec
7499 objc-instance-variable-decl ;
7501 objc-instance-variable-decl-list objc-visibility-spec
7502 objc-instance-variable-decl-list objc-instance-variable-decl ;
7503 objc-instance-variable-decl-list ;
7505 objc-visibility-spec:
7510 objc-instance-variable-decl:
7515 c_parser_objc_class_instance_variables (c_parser
*parser
)
7517 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7518 c_parser_consume_token (parser
);
7519 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7522 /* Parse any stray semicolon. */
7523 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7525 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7527 c_parser_consume_token (parser
);
7530 /* Stop if at the end of the instance variables. */
7531 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7533 c_parser_consume_token (parser
);
7536 /* Parse any objc-visibility-spec. */
7537 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7539 c_parser_consume_token (parser
);
7540 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7543 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7545 c_parser_consume_token (parser
);
7546 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7549 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7551 c_parser_consume_token (parser
);
7552 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7555 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7557 c_parser_consume_token (parser
);
7558 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7561 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7563 c_parser_pragma (parser
, pragma_external
);
7567 /* Parse some comma-separated declarations. */
7568 decls
= c_parser_struct_declaration (parser
);
7571 /* There is a syntax error. We want to skip the offending
7572 tokens up to the next ';' (included) or '}'
7575 /* First, skip manually a ')' or ']'. This is because they
7576 reduce the nesting level, so c_parser_skip_until_found()
7577 wouldn't be able to skip past them. */
7578 c_token
*token
= c_parser_peek_token (parser
);
7579 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7580 c_parser_consume_token (parser
);
7582 /* Then, do the standard skipping. */
7583 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7585 /* We hopefully recovered. Start normal parsing again. */
7586 parser
->error
= false;
7591 /* Comma-separated instance variables are chained together
7592 in reverse order; add them one by one. */
7593 tree ivar
= nreverse (decls
);
7594 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7595 objc_add_instance_variable (copy_node (ivar
));
7597 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7601 /* Parse an objc-class-declaration.
7603 objc-class-declaration:
7604 @class identifier-list ;
7608 c_parser_objc_class_declaration (c_parser
*parser
)
7610 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7611 c_parser_consume_token (parser
);
7612 /* Any identifiers, including those declared as type names, are OK
7617 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7619 c_parser_error (parser
, "expected identifier");
7620 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7621 parser
->error
= false;
7624 id
= c_parser_peek_token (parser
)->value
;
7625 objc_declare_class (id
);
7626 c_parser_consume_token (parser
);
7627 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7628 c_parser_consume_token (parser
);
7632 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7635 /* Parse an objc-alias-declaration.
7637 objc-alias-declaration:
7638 @compatibility_alias identifier identifier ;
7642 c_parser_objc_alias_declaration (c_parser
*parser
)
7645 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7646 c_parser_consume_token (parser
);
7647 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7649 c_parser_error (parser
, "expected identifier");
7650 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7653 id1
= c_parser_peek_token (parser
)->value
;
7654 c_parser_consume_token (parser
);
7655 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7657 c_parser_error (parser
, "expected identifier");
7658 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7661 id2
= c_parser_peek_token (parser
)->value
;
7662 c_parser_consume_token (parser
);
7663 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7664 objc_declare_alias (id1
, id2
);
7667 /* Parse an objc-protocol-definition.
7669 objc-protocol-definition:
7670 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7671 @protocol identifier-list ;
7673 "@protocol identifier ;" should be resolved as "@protocol
7674 identifier-list ;": objc-methodprotolist may not start with a
7675 semicolon in the first alternative if objc-protocol-refs are
7679 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7681 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7683 c_parser_consume_token (parser
);
7684 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7686 c_parser_error (parser
, "expected identifier");
7689 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7690 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7692 /* Any identifiers, including those declared as type names, are
7697 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7699 c_parser_error (parser
, "expected identifier");
7702 id
= c_parser_peek_token (parser
)->value
;
7703 objc_declare_protocol (id
, attributes
);
7704 c_parser_consume_token (parser
);
7705 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7706 c_parser_consume_token (parser
);
7710 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7714 tree id
= c_parser_peek_token (parser
)->value
;
7715 tree proto
= NULL_TREE
;
7716 c_parser_consume_token (parser
);
7717 if (c_parser_next_token_is (parser
, CPP_LESS
))
7718 proto
= c_parser_objc_protocol_refs (parser
);
7719 parser
->objc_pq_context
= true;
7720 objc_start_protocol (id
, proto
, attributes
);
7721 c_parser_objc_methodprotolist (parser
);
7722 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7723 parser
->objc_pq_context
= false;
7724 objc_finish_interface ();
7728 /* Parse an objc-method-type.
7734 Return true if it is a class method (+) and false if it is
7735 an instance method (-).
7738 c_parser_objc_method_type (c_parser
*parser
)
7740 switch (c_parser_peek_token (parser
)->type
)
7743 c_parser_consume_token (parser
);
7746 c_parser_consume_token (parser
);
7753 /* Parse an objc-method-definition.
7755 objc-method-definition:
7756 objc-method-type objc-method-decl ;[opt] compound-statement
7760 c_parser_objc_method_definition (c_parser
*parser
)
7762 bool is_class_method
= c_parser_objc_method_type (parser
);
7763 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7764 parser
->objc_pq_context
= true;
7765 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7767 if (decl
== error_mark_node
)
7768 return; /* Bail here. */
7770 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7772 c_parser_consume_token (parser
);
7773 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7774 "extra semicolon in method definition specified");
7777 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7779 c_parser_error (parser
, "expected %<{%>");
7783 parser
->objc_pq_context
= false;
7784 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7786 add_stmt (c_parser_compound_statement (parser
));
7787 objc_finish_method_definition (current_function_decl
);
7791 /* This code is executed when we find a method definition
7792 outside of an @implementation context (or invalid for other
7793 reasons). Parse the method (to keep going) but do not emit
7796 c_parser_compound_statement (parser
);
7800 /* Parse an objc-methodprotolist.
7802 objc-methodprotolist:
7804 objc-methodprotolist objc-methodproto
7805 objc-methodprotolist declaration
7806 objc-methodprotolist ;
7810 The declaration is a data definition, which may be missing
7811 declaration specifiers under the same rules and diagnostics as
7812 other data definitions outside functions, and the stray semicolon
7813 is diagnosed the same way as a stray semicolon outside a
7817 c_parser_objc_methodprotolist (c_parser
*parser
)
7821 /* The list is terminated by @end. */
7822 switch (c_parser_peek_token (parser
)->type
)
7825 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7826 "ISO C does not allow extra %<;%> outside of a function");
7827 c_parser_consume_token (parser
);
7831 c_parser_objc_methodproto (parser
);
7834 c_parser_pragma (parser
, pragma_external
);
7839 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7841 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7842 c_parser_objc_at_property_declaration (parser
);
7843 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7845 objc_set_method_opt (true);
7846 c_parser_consume_token (parser
);
7848 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7850 objc_set_method_opt (false);
7851 c_parser_consume_token (parser
);
7854 c_parser_declaration_or_fndef (parser
, false, false, true,
7861 /* Parse an objc-methodproto.
7864 objc-method-type objc-method-decl ;
7868 c_parser_objc_methodproto (c_parser
*parser
)
7870 bool is_class_method
= c_parser_objc_method_type (parser
);
7871 tree decl
, attributes
= NULL_TREE
;
7873 /* Remember protocol qualifiers in prototypes. */
7874 parser
->objc_pq_context
= true;
7875 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7877 /* Forget protocol qualifiers now. */
7878 parser
->objc_pq_context
= false;
7880 /* Do not allow the presence of attributes to hide an erroneous
7881 method implementation in the interface section. */
7882 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7884 c_parser_error (parser
, "expected %<;%>");
7888 if (decl
!= error_mark_node
)
7889 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7891 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7894 /* If we are at a position that method attributes may be present, check that
7895 there are not any parsed already (a syntax error) and then collect any
7896 specified at the current location. Finally, if new attributes were present,
7897 check that the next token is legal ( ';' for decls and '{' for defs). */
7900 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7905 c_parser_error (parser
,
7906 "method attributes must be specified at the end only");
7907 *attributes
= NULL_TREE
;
7911 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7912 *attributes
= c_parser_attributes (parser
);
7914 /* If there were no attributes here, just report any earlier error. */
7915 if (*attributes
== NULL_TREE
|| bad
)
7918 /* If the attributes are followed by a ; or {, then just report any earlier
7920 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7921 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7924 /* We've got attributes, but not at the end. */
7925 c_parser_error (parser
,
7926 "expected %<;%> or %<{%> after method attribute definition");
7930 /* Parse an objc-method-decl.
7933 ( objc-type-name ) objc-selector
7935 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7936 objc-keyword-selector objc-optparmlist
7939 objc-keyword-selector:
7941 objc-keyword-selector objc-keyword-decl
7944 objc-selector : ( objc-type-name ) identifier
7945 objc-selector : identifier
7946 : ( objc-type-name ) identifier
7950 objc-optparms objc-optellipsis
7954 objc-opt-parms , parameter-declaration
7962 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7963 tree
*attributes
, tree
*expr
)
7965 tree type
= NULL_TREE
;
7967 tree parms
= NULL_TREE
;
7968 bool ellipsis
= false;
7969 bool attr_err
= false;
7971 *attributes
= NULL_TREE
;
7972 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7974 c_parser_consume_token (parser
);
7975 type
= c_parser_objc_type_name (parser
);
7976 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7978 sel
= c_parser_objc_selector (parser
);
7979 /* If there is no selector, or a colon follows, we have an
7980 objc-keyword-selector. If there is a selector, and a colon does
7981 not follow, that selector ends the objc-method-decl. */
7982 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7985 tree list
= NULL_TREE
;
7988 tree atype
= NULL_TREE
, id
, keyworddecl
;
7989 tree param_attr
= NULL_TREE
;
7990 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7992 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7994 c_parser_consume_token (parser
);
7995 atype
= c_parser_objc_type_name (parser
);
7996 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7999 /* New ObjC allows attributes on method parameters. */
8000 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8001 param_attr
= c_parser_attributes (parser
);
8002 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8004 c_parser_error (parser
, "expected identifier");
8005 return error_mark_node
;
8007 id
= c_parser_peek_token (parser
)->value
;
8008 c_parser_consume_token (parser
);
8009 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8010 list
= chainon (list
, keyworddecl
);
8011 tsel
= c_parser_objc_selector (parser
);
8012 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8016 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8018 /* Parse the optional parameter list. Optional Objective-C
8019 method parameters follow the C syntax, and may include '...'
8020 to denote a variable number of arguments. */
8021 parms
= make_node (TREE_LIST
);
8022 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8024 struct c_parm
*parm
;
8025 c_parser_consume_token (parser
);
8026 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8029 c_parser_consume_token (parser
);
8030 attr_err
|= c_parser_objc_maybe_method_attributes
8031 (parser
, attributes
) ;
8034 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8037 parms
= chainon (parms
,
8038 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8043 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8047 c_parser_error (parser
, "objective-c method declaration is expected");
8048 return error_mark_node
;
8052 return error_mark_node
;
8054 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8057 /* Parse an objc-type-name.
8060 objc-type-qualifiers[opt] type-name
8061 objc-type-qualifiers[opt]
8063 objc-type-qualifiers:
8065 objc-type-qualifiers objc-type-qualifier
8067 objc-type-qualifier: one of
8068 in out inout bycopy byref oneway
8072 c_parser_objc_type_name (c_parser
*parser
)
8074 tree quals
= NULL_TREE
;
8075 struct c_type_name
*type_name
= NULL
;
8076 tree type
= NULL_TREE
;
8079 c_token
*token
= c_parser_peek_token (parser
);
8080 if (token
->type
== CPP_KEYWORD
8081 && (token
->keyword
== RID_IN
8082 || token
->keyword
== RID_OUT
8083 || token
->keyword
== RID_INOUT
8084 || token
->keyword
== RID_BYCOPY
8085 || token
->keyword
== RID_BYREF
8086 || token
->keyword
== RID_ONEWAY
))
8088 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8089 c_parser_consume_token (parser
);
8094 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8095 type_name
= c_parser_type_name (parser
);
8097 type
= groktypename (type_name
, NULL
, NULL
);
8099 /* If the type is unknown, and error has already been produced and
8100 we need to recover from the error. In that case, use NULL_TREE
8101 for the type, as if no type had been specified; this will use the
8102 default type ('id') which is good for error recovery. */
8103 if (type
== error_mark_node
)
8106 return build_tree_list (quals
, type
);
8109 /* Parse objc-protocol-refs.
8116 c_parser_objc_protocol_refs (c_parser
*parser
)
8118 tree list
= NULL_TREE
;
8119 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8120 c_parser_consume_token (parser
);
8121 /* Any identifiers, including those declared as type names, are OK
8126 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8128 c_parser_error (parser
, "expected identifier");
8131 id
= c_parser_peek_token (parser
)->value
;
8132 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8133 c_parser_consume_token (parser
);
8134 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8135 c_parser_consume_token (parser
);
8139 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8143 /* Parse an objc-try-catch-finally-statement.
8145 objc-try-catch-finally-statement:
8146 @try compound-statement objc-catch-list[opt]
8147 @try compound-statement objc-catch-list[opt] @finally compound-statement
8150 @catch ( objc-catch-parameter-declaration ) compound-statement
8151 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8153 objc-catch-parameter-declaration:
8154 parameter-declaration
8157 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8159 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8160 for C++. Keep them in sync. */
8163 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8165 location_t location
;
8168 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8169 c_parser_consume_token (parser
);
8170 location
= c_parser_peek_token (parser
)->location
;
8171 objc_maybe_warn_exceptions (location
);
8172 stmt
= c_parser_compound_statement (parser
);
8173 objc_begin_try_stmt (location
, stmt
);
8175 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8177 struct c_parm
*parm
;
8178 tree parameter_declaration
= error_mark_node
;
8179 bool seen_open_paren
= false;
8181 c_parser_consume_token (parser
);
8182 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8183 seen_open_paren
= true;
8184 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8186 /* We have "@catch (...)" (where the '...' are literally
8187 what is in the code). Skip the '...'.
8188 parameter_declaration is set to NULL_TREE, and
8189 objc_being_catch_clauses() knows that that means
8191 c_parser_consume_token (parser
);
8192 parameter_declaration
= NULL_TREE
;
8196 /* We have "@catch (NSException *exception)" or something
8197 like that. Parse the parameter declaration. */
8198 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8200 parameter_declaration
= error_mark_node
;
8202 parameter_declaration
= grokparm (parm
, NULL
);
8204 if (seen_open_paren
)
8205 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8208 /* If there was no open parenthesis, we are recovering from
8209 an error, and we are trying to figure out what mistake
8210 the user has made. */
8212 /* If there is an immediate closing parenthesis, the user
8213 probably forgot the opening one (ie, they typed "@catch
8214 NSException *e)". Parse the closing parenthesis and keep
8216 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8217 c_parser_consume_token (parser
);
8219 /* If these is no immediate closing parenthesis, the user
8220 probably doesn't know that parenthesis are required at
8221 all (ie, they typed "@catch NSException *e"). So, just
8222 forget about the closing parenthesis and keep going. */
8224 objc_begin_catch_clause (parameter_declaration
);
8225 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8226 c_parser_compound_statement_nostart (parser
);
8227 objc_finish_catch_clause ();
8229 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8231 c_parser_consume_token (parser
);
8232 location
= c_parser_peek_token (parser
)->location
;
8233 stmt
= c_parser_compound_statement (parser
);
8234 objc_build_finally_clause (location
, stmt
);
8236 objc_finish_try_stmt ();
8239 /* Parse an objc-synchronized-statement.
8241 objc-synchronized-statement:
8242 @synchronized ( expression ) compound-statement
8246 c_parser_objc_synchronized_statement (c_parser
*parser
)
8250 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8251 c_parser_consume_token (parser
);
8252 loc
= c_parser_peek_token (parser
)->location
;
8253 objc_maybe_warn_exceptions (loc
);
8254 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8256 expr
= c_parser_expression (parser
).value
;
8257 expr
= c_fully_fold (expr
, false, NULL
);
8258 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8261 expr
= error_mark_node
;
8262 stmt
= c_parser_compound_statement (parser
);
8263 objc_build_synchronized (loc
, expr
, stmt
);
8266 /* Parse an objc-selector; return NULL_TREE without an error if the
8267 next token is not an objc-selector.
8272 enum struct union if else while do for switch case default
8273 break continue return goto asm sizeof typeof __alignof
8274 unsigned long const short volatile signed restrict _Complex
8275 in out inout bycopy byref oneway int char float double void _Bool
8277 ??? Why this selection of keywords but not, for example, storage
8278 class specifiers? */
8281 c_parser_objc_selector (c_parser
*parser
)
8283 c_token
*token
= c_parser_peek_token (parser
);
8284 tree value
= token
->value
;
8285 if (token
->type
== CPP_NAME
)
8287 c_parser_consume_token (parser
);
8290 if (token
->type
!= CPP_KEYWORD
)
8292 switch (token
->keyword
)
8334 c_parser_consume_token (parser
);
8341 /* Parse an objc-selector-arg.
8345 objc-keywordname-list
8347 objc-keywordname-list:
8349 objc-keywordname-list objc-keywordname
8357 c_parser_objc_selector_arg (c_parser
*parser
)
8359 tree sel
= c_parser_objc_selector (parser
);
8360 tree list
= NULL_TREE
;
8361 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8365 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8367 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8368 sel
= c_parser_objc_selector (parser
);
8369 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8375 /* Parse an objc-receiver.
8384 c_parser_objc_receiver (c_parser
*parser
)
8386 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8387 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8388 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8390 tree id
= c_parser_peek_token (parser
)->value
;
8391 c_parser_consume_token (parser
);
8392 return objc_get_class_reference (id
);
8394 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8397 /* Parse objc-message-args.
8401 objc-keywordarg-list
8403 objc-keywordarg-list:
8405 objc-keywordarg-list objc-keywordarg
8408 objc-selector : objc-keywordexpr
8413 c_parser_objc_message_args (c_parser
*parser
)
8415 tree sel
= c_parser_objc_selector (parser
);
8416 tree list
= NULL_TREE
;
8417 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8422 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8423 return error_mark_node
;
8424 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8425 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8426 sel
= c_parser_objc_selector (parser
);
8427 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8433 /* Parse an objc-keywordexpr.
8440 c_parser_objc_keywordexpr (c_parser
*parser
)
8443 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8445 if (vec_safe_length (expr_list
) == 1)
8447 /* Just return the expression, remove a level of
8449 ret
= (*expr_list
)[0];
8453 /* We have a comma expression, we will collapse later. */
8454 ret
= build_tree_list_vec (expr_list
);
8456 release_tree_vector (expr_list
);
8460 /* A check, needed in several places, that ObjC interface, implementation or
8461 method definitions are not prefixed by incorrect items. */
8463 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8464 struct c_declspecs
*specs
)
8466 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8467 || specs
->typespec_kind
!= ctsk_none
)
8469 c_parser_error (parser
,
8470 "no type or storage class may be specified here,");
8471 c_parser_skip_to_end_of_block_or_statement (parser
);
8477 /* Parse an Objective-C @property declaration. The syntax is:
8479 objc-property-declaration:
8480 '@property' objc-property-attributes[opt] struct-declaration ;
8482 objc-property-attributes:
8483 '(' objc-property-attribute-list ')'
8485 objc-property-attribute-list:
8486 objc-property-attribute
8487 objc-property-attribute-list, objc-property-attribute
8489 objc-property-attribute
8490 'getter' = identifier
8491 'setter' = identifier
8500 @property NSString *name;
8501 @property (readonly) id object;
8502 @property (retain, nonatomic, getter=getTheName) id name;
8503 @property int a, b, c;
8505 PS: This function is identical to cp_parser_objc_at_propery_declaration
8506 for C++. Keep them in sync. */
8508 c_parser_objc_at_property_declaration (c_parser
*parser
)
8510 /* The following variables hold the attributes of the properties as
8511 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8512 seen. When we see an attribute, we set them to 'true' (if they
8513 are boolean properties) or to the identifier (if they have an
8514 argument, ie, for getter and setter). Note that here we only
8515 parse the list of attributes, check the syntax and accumulate the
8516 attributes that we find. objc_add_property_declaration() will
8517 then process the information. */
8518 bool property_assign
= false;
8519 bool property_copy
= false;
8520 tree property_getter_ident
= NULL_TREE
;
8521 bool property_nonatomic
= false;
8522 bool property_readonly
= false;
8523 bool property_readwrite
= false;
8524 bool property_retain
= false;
8525 tree property_setter_ident
= NULL_TREE
;
8527 /* 'properties' is the list of properties that we read. Usually a
8528 single one, but maybe more (eg, in "@property int a, b, c;" there
8533 loc
= c_parser_peek_token (parser
)->location
;
8534 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8536 c_parser_consume_token (parser
); /* Eat '@property'. */
8538 /* Parse the optional attribute list... */
8539 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8542 c_parser_consume_token (parser
);
8544 /* Property attribute keywords are valid now. */
8545 parser
->objc_property_attr_context
= true;
8549 bool syntax_error
= false;
8550 c_token
*token
= c_parser_peek_token (parser
);
8553 if (token
->type
!= CPP_KEYWORD
)
8555 if (token
->type
== CPP_CLOSE_PAREN
)
8556 c_parser_error (parser
, "expected identifier");
8559 c_parser_consume_token (parser
);
8560 c_parser_error (parser
, "unknown property attribute");
8564 keyword
= token
->keyword
;
8565 c_parser_consume_token (parser
);
8568 case RID_ASSIGN
: property_assign
= true; break;
8569 case RID_COPY
: property_copy
= true; break;
8570 case RID_NONATOMIC
: property_nonatomic
= true; break;
8571 case RID_READONLY
: property_readonly
= true; break;
8572 case RID_READWRITE
: property_readwrite
= true; break;
8573 case RID_RETAIN
: property_retain
= true; break;
8577 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8579 if (keyword
== RID_GETTER
)
8580 c_parser_error (parser
,
8581 "missing %<=%> (after %<getter%> attribute)");
8583 c_parser_error (parser
,
8584 "missing %<=%> (after %<setter%> attribute)");
8585 syntax_error
= true;
8588 c_parser_consume_token (parser
); /* eat the = */
8589 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8591 c_parser_error (parser
, "expected identifier");
8592 syntax_error
= true;
8595 if (keyword
== RID_SETTER
)
8597 if (property_setter_ident
!= NULL_TREE
)
8598 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8600 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8601 c_parser_consume_token (parser
);
8602 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8603 c_parser_error (parser
, "setter name must terminate with %<:%>");
8605 c_parser_consume_token (parser
);
8609 if (property_getter_ident
!= NULL_TREE
)
8610 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8612 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8613 c_parser_consume_token (parser
);
8617 c_parser_error (parser
, "unknown property attribute");
8618 syntax_error
= true;
8625 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8626 c_parser_consume_token (parser
);
8630 parser
->objc_property_attr_context
= false;
8631 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8633 /* ... and the property declaration(s). */
8634 properties
= c_parser_struct_declaration (parser
);
8636 if (properties
== error_mark_node
)
8638 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8639 parser
->error
= false;
8643 if (properties
== NULL_TREE
)
8644 c_parser_error (parser
, "expected identifier");
8647 /* Comma-separated properties are chained together in
8648 reverse order; add them one by one. */
8649 properties
= nreverse (properties
);
8651 for (; properties
; properties
= TREE_CHAIN (properties
))
8652 objc_add_property_declaration (loc
, copy_node (properties
),
8653 property_readonly
, property_readwrite
,
8654 property_assign
, property_retain
,
8655 property_copy
, property_nonatomic
,
8656 property_getter_ident
, property_setter_ident
);
8659 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8660 parser
->error
= false;
8663 /* Parse an Objective-C @synthesize declaration. The syntax is:
8665 objc-synthesize-declaration:
8666 @synthesize objc-synthesize-identifier-list ;
8668 objc-synthesize-identifier-list:
8669 objc-synthesize-identifier
8670 objc-synthesize-identifier-list, objc-synthesize-identifier
8672 objc-synthesize-identifier
8674 identifier = identifier
8677 @synthesize MyProperty;
8678 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8680 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8681 for C++. Keep them in sync.
8684 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8686 tree list
= NULL_TREE
;
8688 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8689 loc
= c_parser_peek_token (parser
)->location
;
8691 c_parser_consume_token (parser
);
8694 tree property
, ivar
;
8695 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8697 c_parser_error (parser
, "expected identifier");
8698 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8699 /* Once we find the semicolon, we can resume normal parsing.
8700 We have to reset parser->error manually because
8701 c_parser_skip_until_found() won't reset it for us if the
8702 next token is precisely a semicolon. */
8703 parser
->error
= false;
8706 property
= c_parser_peek_token (parser
)->value
;
8707 c_parser_consume_token (parser
);
8708 if (c_parser_next_token_is (parser
, CPP_EQ
))
8710 c_parser_consume_token (parser
);
8711 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8713 c_parser_error (parser
, "expected identifier");
8714 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8715 parser
->error
= false;
8718 ivar
= c_parser_peek_token (parser
)->value
;
8719 c_parser_consume_token (parser
);
8723 list
= chainon (list
, build_tree_list (ivar
, property
));
8724 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8725 c_parser_consume_token (parser
);
8729 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8730 objc_add_synthesize_declaration (loc
, list
);
8733 /* Parse an Objective-C @dynamic declaration. The syntax is:
8735 objc-dynamic-declaration:
8736 @dynamic identifier-list ;
8739 @dynamic MyProperty;
8740 @dynamic MyProperty, AnotherProperty;
8742 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8743 for C++. Keep them in sync.
8746 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8748 tree list
= NULL_TREE
;
8750 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8751 loc
= c_parser_peek_token (parser
)->location
;
8753 c_parser_consume_token (parser
);
8757 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8759 c_parser_error (parser
, "expected identifier");
8760 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8761 parser
->error
= false;
8764 property
= c_parser_peek_token (parser
)->value
;
8765 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8766 c_parser_consume_token (parser
);
8767 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8768 c_parser_consume_token (parser
);
8772 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8773 objc_add_dynamic_declaration (loc
, list
);
8776 /* Parse UPC shared qualifier
8778 shared-type-qualifier: shared layout-qualifier-opt
8779 layout-qualifier: [ constant-expression-opt ] | [ * ]
8783 c_parser_upc_shared_qual (source_location loc
,
8785 struct c_declspecs
*specs
)
8787 tree array_qual
, arg1
;
8789 /* consume "shared" part */
8790 c_parser_consume_token (parser
);
8792 /* check for shared array layout specifier */
8793 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
8795 declspecs_add_qual (loc
, specs
, ridpointers
[RID_SHARED
]);
8798 c_parser_consume_token (parser
);
8799 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
8801 /* [] layout specifier */
8802 arg1
= size_zero_node
;
8804 else if (c_parser_next_token_is (parser
, CPP_MULT
))
8806 /* [*] layout specifier */
8807 arg1
= build1 (INDIRECT_REF
, NULL_TREE
, NULL_TREE
);
8808 c_parser_consume_token (parser
);
8812 /* [ expression ] layout specifier */
8813 arg1
= c_parser_expression (parser
).value
;
8815 array_qual
= build4 (ARRAY_REF
, NULL_TREE
, NULL_TREE
,
8816 arg1
, NULL_TREE
, NULL_TREE
);
8817 declspecs_add_qual (loc
, specs
, array_qual
);
8819 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
8821 c_parser_error (parser
, "expected ]");
8823 c_parser_consume_token (parser
);
8826 /* Parse a UPC upc_forall statement
8828 upc_forall-statement:
8829 upc_forall ( expression[opt] ; expression[opt] ;
8830 expression[opt] ; affinity[opt] ) statement
8831 affinity: experssion | continue */
8834 c_parser_upc_forall_statement (c_parser
*parser
)
8836 tree block
, cond
, incr
, save_break
, save_cont
, body
;
8838 location_t loc
= c_parser_peek_token (parser
)->location
;
8839 location_t affinity_loc
= UNKNOWN_LOCATION
;
8840 const int profile_upc_forall
= flag_upc_instrument
&& get_upc_pupc_mode();
8841 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_FORALL
));
8842 c_parser_consume_token (parser
);
8843 block
= c_begin_compound_stmt (flag_isoc99
);
8844 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8846 /* Parse the initialization declaration or expression. */
8847 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8849 c_parser_consume_token (parser
);
8850 c_finish_expr_stmt (loc
, NULL_TREE
);
8852 else if (c_parser_next_token_starts_declspecs (parser
))
8854 c_parser_declaration_or_fndef (parser
, true, true, true,
8856 check_for_loop_decls (loc
, true);
8858 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
8860 /* __extension__ can start a declaration, but is also an
8861 unary operator that can start an expression. Consume all
8862 but the last of a possible series of __extension__ to
8864 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
8865 && (c_parser_peek_2nd_token (parser
)->keyword
8867 c_parser_consume_token (parser
);
8868 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
8871 ext
= disable_extension_diagnostics ();
8872 c_parser_consume_token (parser
);
8873 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
8874 restore_extension_diagnostics (ext
);
8875 check_for_loop_decls (loc
, true);
8883 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
8884 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8886 /* Parse the loop condition. */
8887 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8889 c_parser_consume_token (parser
);
8894 cond
= c_parser_condition (parser
);
8895 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8897 /* Parse the increment expression. */
8898 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8899 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
8901 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
8902 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8903 /* Parse the UPC affinity expression. */
8904 affinity_loc
= c_parser_peek_token (parser
)->location
;
8905 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8907 affinity
= NULL_TREE
;
8909 else if (c_parser_peek_token (parser
)->type
== CPP_KEYWORD
8910 && c_parser_peek_token (parser
)->keyword
== RID_CONTINUE
)
8912 affinity
= NULL_TREE
;
8913 c_parser_consume_token (parser
);
8917 affinity
= c_parser_expression_conv (parser
).value
;
8918 affinity
= c_fully_fold (affinity
, false, NULL
);
8920 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8922 affinity
= upc_affinity_test (affinity_loc
, affinity
);
8926 cond
= error_mark_node
;
8927 incr
= error_mark_node
;
8928 affinity
= error_mark_node
;
8930 save_break
= c_break_label
;
8931 c_break_label
= NULL_TREE
;
8932 save_cont
= c_cont_label
;
8933 c_cont_label
= NULL_TREE
;
8934 body
= c_parser_c99_block_statement (parser
);
8935 if (profile_upc_forall
)
8937 const tree gasp_start
= upc_instrument_forall (loc
, 1 /* start */);
8938 add_stmt (gasp_start
);
8940 loc
= c_parser_peek_token (parser
)->location
;
8941 if (affinity
!= NULL_TREE
&& affinity
!= error_mark_node
)
8943 tree upc_forall_depth
= upc_rts_forall_depth_var ();
8944 tree inc_depth
, depth_gt_one
;
8945 inc_depth
= build_unary_op (loc
, PREINCREMENT_EXPR
, upc_forall_depth
, 0);
8946 c_finish_expr_stmt (loc
, inc_depth
);
8947 depth_gt_one
= build_binary_op (affinity_loc
,
8948 GT_EXPR
, upc_forall_depth
, integer_one_node
, 0);
8949 depth_gt_one
= c_objc_common_truthvalue_conversion (affinity_loc
, depth_gt_one
);
8950 depth_gt_one
= c_fully_fold (depth_gt_one
, false, NULL
);
8951 affinity
= build_binary_op (affinity_loc
, TRUTH_OR_EXPR
,
8952 depth_gt_one
, affinity
, 0);
8953 body
= build3 (COND_EXPR
, void_type_node
, affinity
,
8955 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
8956 c_finish_expr_stmt (loc
,
8957 build_unary_op (loc
, PREDECREMENT_EXPR
, upc_forall_depth
, 0));
8960 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
8961 if (profile_upc_forall
)
8963 const tree gasp_end
= upc_instrument_forall (loc
, 0 /* start */);
8964 add_stmt (gasp_end
);
8966 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
8967 c_break_label
= save_break
;
8968 c_cont_label
= save_cont
;
8971 /* Parse an upc-sync-statement.
8973 upc_barrier, upc_wait, upc_notify
8977 c_parser_upc_sync_statement (c_parser
*parser
, int sync_kind
)
8980 tree expr
= NULL_TREE
;
8982 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_BARRIER
) ||
8983 c_parser_next_token_is_keyword (parser
, RID_UPC_NOTIFY
) ||
8984 c_parser_next_token_is_keyword (parser
, RID_UPC_WAIT
));
8985 loc
= c_parser_peek_token (parser
)->location
;
8986 c_parser_consume_token (parser
);
8987 if (c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
8989 expr
= c_parser_expression (parser
).value
;
8990 if (expr
== error_mark_node
)
8992 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
8994 c_parser_error (parser
, "expected integer expression");
8998 stmt
= size_int (sync_kind
);
8999 (void) upc_build_sync_stmt (loc
, stmt
, expr
);
9003 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9004 should be considered, statements. ALLOW_STMT is true if we're within
9005 the context of a function and such pragmas are to be allowed. Returns
9006 true if we actually parsed such a pragma. */
9009 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9013 id
= c_parser_peek_token (parser
)->pragma_kind
;
9014 gcc_assert (id
!= PRAGMA_NONE
);
9018 case PRAGMA_OMP_BARRIER
:
9019 if (context
!= pragma_compound
)
9021 if (context
== pragma_stmt
)
9022 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9023 "used in compound statements");
9026 c_parser_omp_barrier (parser
);
9029 case PRAGMA_OMP_FLUSH
:
9030 if (context
!= pragma_compound
)
9032 if (context
== pragma_stmt
)
9033 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9034 "used in compound statements");
9037 c_parser_omp_flush (parser
);
9040 case PRAGMA_OMP_TASKWAIT
:
9041 if (context
!= pragma_compound
)
9043 if (context
== pragma_stmt
)
9044 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9045 "used in compound statements");
9048 c_parser_omp_taskwait (parser
);
9051 case PRAGMA_OMP_TASKYIELD
:
9052 if (context
!= pragma_compound
)
9054 if (context
== pragma_stmt
)
9055 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9056 "used in compound statements");
9059 c_parser_omp_taskyield (parser
);
9062 case PRAGMA_OMP_THREADPRIVATE
:
9063 c_parser_omp_threadprivate (parser
);
9066 case PRAGMA_OMP_SECTION
:
9067 error_at (c_parser_peek_token (parser
)->location
,
9068 "%<#pragma omp section%> may only be used in "
9069 "%<#pragma omp sections%> construct");
9070 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9073 case PRAGMA_GCC_PCH_PREPROCESS
:
9074 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9075 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9079 if (id
< PRAGMA_FIRST_EXTERNAL
)
9081 if (context
== pragma_external
)
9084 c_parser_error (parser
, "expected declaration specifiers");
9085 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9088 c_parser_omp_construct (parser
);
9094 c_parser_consume_pragma (parser
);
9095 c_invoke_pragma_handler (id
);
9097 /* Skip to EOL, but suppress any error message. Those will have been
9098 generated by the handler routine through calling error, as opposed
9099 to calling c_parser_error. */
9100 parser
->error
= true;
9101 c_parser_skip_to_pragma_eol (parser
);
9106 /* The interface the pragma parsers have to the lexer. */
9109 pragma_lex (tree
*value
)
9111 c_token
*tok
= c_parser_peek_token (the_parser
);
9112 enum cpp_ttype ret
= tok
->type
;
9114 *value
= tok
->value
;
9115 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9119 if (ret
== CPP_KEYWORD
)
9121 c_parser_consume_token (the_parser
);
9128 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9132 c_parser_consume_pragma (parser
);
9133 if (c_parser_next_token_is (parser
, CPP_STRING
))
9135 name
= c_parser_peek_token (parser
)->value
;
9136 c_parser_consume_token (parser
);
9139 c_parser_error (parser
, "expected string literal");
9140 c_parser_skip_to_pragma_eol (parser
);
9143 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9146 /* OpenMP 2.5 parsing routines. */
9148 /* Returns name of the next clause.
9149 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9150 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9151 returned and the token is consumed. */
9153 static pragma_omp_clause
9154 c_parser_omp_clause_name (c_parser
*parser
)
9156 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9158 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9159 result
= PRAGMA_OMP_CLAUSE_IF
;
9160 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9161 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9162 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9164 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9169 if (!strcmp ("collapse", p
))
9170 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9171 else if (!strcmp ("copyin", p
))
9172 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9173 else if (!strcmp ("copyprivate", p
))
9174 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9177 if (!strcmp ("final", p
))
9178 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9179 else if (!strcmp ("firstprivate", p
))
9180 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9183 if (!strcmp ("lastprivate", p
))
9184 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9187 if (!strcmp ("mergeable", p
))
9188 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9191 if (!strcmp ("nowait", p
))
9192 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9193 else if (!strcmp ("num_threads", p
))
9194 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9197 if (!strcmp ("ordered", p
))
9198 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9201 if (!strcmp ("private", p
))
9202 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9205 if (!strcmp ("reduction", p
))
9206 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9209 if (!strcmp ("schedule", p
))
9210 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9211 else if (!strcmp ("shared", p
))
9212 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9215 if (!strcmp ("untied", p
))
9216 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9221 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9222 c_parser_consume_token (parser
);
9227 /* Validate that a clause of the given type does not already exist. */
9230 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9235 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9236 if (OMP_CLAUSE_CODE (c
) == code
)
9238 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9239 error_at (loc
, "too many %qs clauses", name
);
9247 variable-list , identifier
9249 If KIND is nonzero, create the appropriate node and install the
9250 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9251 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9253 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9254 return the list created. */
9257 c_parser_omp_variable_list (c_parser
*parser
,
9258 location_t clause_loc
,
9259 enum omp_clause_code kind
,
9262 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9263 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9264 c_parser_error (parser
, "expected identifier");
9266 while (c_parser_next_token_is (parser
, CPP_NAME
)
9267 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9269 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9272 undeclared_variable (c_parser_peek_token (parser
)->location
,
9273 c_parser_peek_token (parser
)->value
);
9274 else if (t
== error_mark_node
)
9278 tree u
= build_omp_clause (clause_loc
, kind
);
9279 OMP_CLAUSE_DECL (u
) = t
;
9280 OMP_CLAUSE_CHAIN (u
) = list
;
9284 list
= tree_cons (t
, NULL_TREE
, list
);
9286 c_parser_consume_token (parser
);
9288 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9291 c_parser_consume_token (parser
);
9297 /* Similarly, but expect leading and trailing parenthesis. This is a very
9298 common case for omp clauses. */
9301 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9304 /* The clauses location. */
9305 location_t loc
= c_parser_peek_token (parser
)->location
;
9307 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9309 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9310 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9316 collapse ( constant-expression ) */
9319 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9321 tree c
, num
= error_mark_node
;
9325 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9327 loc
= c_parser_peek_token (parser
)->location
;
9328 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9330 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9331 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9333 if (num
== error_mark_node
)
9335 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9336 || !host_integerp (num
, 0)
9337 || (n
= tree_low_cst (num
, 0)) <= 0
9341 "collapse argument needs positive constant integer expression");
9344 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9345 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9346 OMP_CLAUSE_CHAIN (c
) = list
;
9351 copyin ( variable-list ) */
9354 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9356 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9360 copyprivate ( variable-list ) */
9363 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9365 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9369 default ( shared | none ) */
9372 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9374 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9375 location_t loc
= c_parser_peek_token (parser
)->location
;
9378 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9380 if (c_parser_next_token_is (parser
, CPP_NAME
))
9382 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9387 if (strcmp ("none", p
) != 0)
9389 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9393 if (strcmp ("shared", p
) != 0)
9395 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9402 c_parser_consume_token (parser
);
9407 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9409 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9411 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9414 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9415 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9416 OMP_CLAUSE_CHAIN (c
) = list
;
9417 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9423 firstprivate ( variable-list ) */
9426 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9428 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9432 final ( expression ) */
9435 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9437 location_t loc
= c_parser_peek_token (parser
)->location
;
9438 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9440 tree t
= c_parser_paren_condition (parser
);
9443 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9445 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9446 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9447 OMP_CLAUSE_CHAIN (c
) = list
;
9451 c_parser_error (parser
, "expected %<(%>");
9457 if ( expression ) */
9460 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9462 location_t loc
= c_parser_peek_token (parser
)->location
;
9463 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9465 tree t
= c_parser_paren_condition (parser
);
9468 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9470 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9471 OMP_CLAUSE_IF_EXPR (c
) = t
;
9472 OMP_CLAUSE_CHAIN (c
) = list
;
9476 c_parser_error (parser
, "expected %<(%>");
9482 lastprivate ( variable-list ) */
9485 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9487 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9494 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9498 /* FIXME: Should we allow duplicates? */
9499 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9501 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9502 OMP_CLAUSE_MERGEABLE
);
9503 OMP_CLAUSE_CHAIN (c
) = list
;
9512 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9515 location_t loc
= c_parser_peek_token (parser
)->location
;
9517 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9519 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9520 OMP_CLAUSE_CHAIN (c
) = list
;
9525 num_threads ( expression ) */
9528 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9530 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9531 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9533 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9534 tree c
, t
= c_parser_expression (parser
).value
;
9536 t
= c_fully_fold (t
, false, NULL
);
9538 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9540 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9542 c_parser_error (parser
, "expected integer expression");
9546 /* Attempt to statically determine when the number isn't positive. */
9547 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9548 build_int_cst (TREE_TYPE (t
), 0));
9549 if (CAN_HAVE_LOCATION_P (c
))
9550 SET_EXPR_LOCATION (c
, expr_loc
);
9551 if (c
== boolean_true_node
)
9553 warning_at (expr_loc
, 0,
9554 "%<num_threads%> value must be positive");
9555 t
= integer_one_node
;
9558 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9560 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9561 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9562 OMP_CLAUSE_CHAIN (c
) = list
;
9573 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9577 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9579 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9580 OMP_CLAUSE_ORDERED
);
9581 OMP_CLAUSE_CHAIN (c
) = list
;
9587 private ( variable-list ) */
9590 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9592 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9596 reduction ( reduction-operator : variable-list )
9599 One of: + * - & ^ | && ||
9604 One of: + * - & ^ | && || max min */
9607 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9609 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9610 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9612 enum tree_code code
;
9614 switch (c_parser_peek_token (parser
)->type
)
9626 code
= BIT_AND_EXPR
;
9629 code
= BIT_XOR_EXPR
;
9632 code
= BIT_IOR_EXPR
;
9635 code
= TRUTH_ANDIF_EXPR
;
9638 code
= TRUTH_ORIF_EXPR
;
9643 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9644 if (strcmp (p
, "min") == 0)
9649 if (strcmp (p
, "max") == 0)
9657 c_parser_error (parser
,
9658 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9659 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9660 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9663 c_parser_consume_token (parser
);
9664 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9668 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9669 OMP_CLAUSE_REDUCTION
, list
);
9670 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9671 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9675 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9681 schedule ( schedule-kind )
9682 schedule ( schedule-kind , expression )
9685 static | dynamic | guided | runtime | auto
9689 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9692 location_t loc
= c_parser_peek_token (parser
)->location
;
9694 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9697 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9699 if (c_parser_next_token_is (parser
, CPP_NAME
))
9701 tree kind
= c_parser_peek_token (parser
)->value
;
9702 const char *p
= IDENTIFIER_POINTER (kind
);
9707 if (strcmp ("dynamic", p
) != 0)
9709 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9713 if (strcmp ("guided", p
) != 0)
9715 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9719 if (strcmp ("runtime", p
) != 0)
9721 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9728 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9729 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9730 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9731 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9735 c_parser_consume_token (parser
);
9736 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9739 c_parser_consume_token (parser
);
9741 here
= c_parser_peek_token (parser
)->location
;
9742 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9744 t
= c_fully_fold (t
, false, NULL
);
9746 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9747 error_at (here
, "schedule %<runtime%> does not take "
9748 "a %<chunk_size%> parameter");
9749 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9751 "schedule %<auto%> does not take "
9752 "a %<chunk_size%> parameter");
9753 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9754 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9756 c_parser_error (parser
, "expected integer expression");
9758 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9761 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9762 "expected %<,%> or %<)%>");
9764 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9765 OMP_CLAUSE_CHAIN (c
) = list
;
9769 c_parser_error (parser
, "invalid schedule kind");
9770 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9775 shared ( variable-list ) */
9778 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9780 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9787 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9791 /* FIXME: Should we allow duplicates? */
9792 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9794 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9796 OMP_CLAUSE_CHAIN (c
) = list
;
9801 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9802 is a bitmask in MASK. Return the list of clauses found; the result
9803 of clause default goes in *pdefault. */
9806 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9809 tree clauses
= NULL
;
9812 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9815 pragma_omp_clause c_kind
;
9817 tree prev
= clauses
;
9819 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9820 c_parser_consume_token (parser
);
9823 here
= c_parser_peek_token (parser
)->location
;
9824 c_kind
= c_parser_omp_clause_name (parser
);
9828 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9829 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9830 c_name
= "collapse";
9832 case PRAGMA_OMP_CLAUSE_COPYIN
:
9833 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9836 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9837 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9838 c_name
= "copyprivate";
9840 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9841 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9844 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9845 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9846 c_name
= "firstprivate";
9848 case PRAGMA_OMP_CLAUSE_FINAL
:
9849 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9852 case PRAGMA_OMP_CLAUSE_IF
:
9853 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9856 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9857 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9858 c_name
= "lastprivate";
9860 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9861 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9862 c_name
= "mergeable";
9864 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9865 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9868 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9869 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9870 c_name
= "num_threads";
9872 case PRAGMA_OMP_CLAUSE_ORDERED
:
9873 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9876 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9877 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9880 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9881 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9882 c_name
= "reduction";
9884 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9885 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9886 c_name
= "schedule";
9888 case PRAGMA_OMP_CLAUSE_SHARED
:
9889 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9892 case PRAGMA_OMP_CLAUSE_UNTIED
:
9893 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9897 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9901 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9903 /* Remove the invalid clause(s) from the list to avoid
9904 confusing the rest of the compiler. */
9906 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9911 c_parser_skip_to_pragma_eol (parser
);
9913 return c_finish_omp_clauses (clauses
);
9920 In practice, we're also interested in adding the statement to an
9921 outer node. So it is convenient if we work around the fact that
9922 c_parser_statement calls add_stmt. */
9925 c_parser_omp_structured_block (c_parser
*parser
)
9927 tree stmt
= push_stmt_list ();
9928 c_parser_statement (parser
);
9929 return pop_stmt_list (stmt
);
9933 # pragma omp atomic new-line
9937 x binop= expr | x++ | ++x | x-- | --x
9939 +, *, -, /, &, ^, |, <<, >>
9941 where x is an lvalue expression with scalar type.
9944 # pragma omp atomic new-line
9947 # pragma omp atomic read new-line
9950 # pragma omp atomic write new-line
9953 # pragma omp atomic update new-line
9956 # pragma omp atomic capture new-line
9959 # pragma omp atomic capture new-line
9967 expression-stmt | x = x binop expr
9969 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9971 { v = x; update-stmt; } | { update-stmt; v = x; }
9973 where x and v are lvalue expressions with scalar type.
9975 LOC is the location of the #pragma token. */
9978 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9980 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9981 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9982 tree stmt
, orig_lhs
;
9983 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9984 struct c_expr rhs_expr
;
9985 bool structured_block
= false;
9987 if (c_parser_next_token_is (parser
, CPP_NAME
))
9989 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9991 if (!strcmp (p
, "read"))
9992 code
= OMP_ATOMIC_READ
;
9993 else if (!strcmp (p
, "write"))
9995 else if (!strcmp (p
, "update"))
9997 else if (!strcmp (p
, "capture"))
9998 code
= OMP_ATOMIC_CAPTURE_NEW
;
10002 c_parser_consume_token (parser
);
10004 c_parser_skip_to_pragma_eol (parser
);
10008 case OMP_ATOMIC_READ
:
10009 case NOP_EXPR
: /* atomic write */
10010 v
= c_parser_unary_expression (parser
).value
;
10011 v
= c_fully_fold (v
, false, NULL
);
10012 if (v
== error_mark_node
)
10014 loc
= c_parser_peek_token (parser
)->location
;
10015 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10017 if (code
== NOP_EXPR
)
10018 lhs
= c_parser_expression (parser
).value
;
10020 lhs
= c_parser_unary_expression (parser
).value
;
10021 lhs
= c_fully_fold (lhs
, false, NULL
);
10022 if (lhs
== error_mark_node
)
10024 if (code
== NOP_EXPR
)
10026 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
10034 case OMP_ATOMIC_CAPTURE_NEW
:
10035 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10037 c_parser_consume_token (parser
);
10038 structured_block
= true;
10042 v
= c_parser_unary_expression (parser
).value
;
10043 v
= c_fully_fold (v
, false, NULL
);
10044 if (v
== error_mark_node
)
10046 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10054 /* For structured_block case we don't know yet whether
10055 old or new x should be captured. */
10057 lhs
= c_parser_unary_expression (parser
).value
;
10058 lhs
= c_fully_fold (lhs
, false, NULL
);
10060 switch (TREE_CODE (lhs
))
10064 c_parser_skip_to_end_of_block_or_statement (parser
);
10065 if (structured_block
)
10067 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10068 c_parser_consume_token (parser
);
10069 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
10071 c_parser_skip_to_end_of_block_or_statement (parser
);
10072 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10073 c_parser_consume_token (parser
);
10078 case POSTINCREMENT_EXPR
:
10079 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
10080 code
= OMP_ATOMIC_CAPTURE_OLD
;
10082 case PREINCREMENT_EXPR
:
10083 lhs
= TREE_OPERAND (lhs
, 0);
10084 opcode
= PLUS_EXPR
;
10085 rhs
= integer_one_node
;
10088 case POSTDECREMENT_EXPR
:
10089 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
10090 code
= OMP_ATOMIC_CAPTURE_OLD
;
10092 case PREDECREMENT_EXPR
:
10093 lhs
= TREE_OPERAND (lhs
, 0);
10094 opcode
= MINUS_EXPR
;
10095 rhs
= integer_one_node
;
10098 case COMPOUND_EXPR
:
10099 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
10100 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
10101 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
10102 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
10103 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
10104 (TREE_OPERAND (lhs
, 1), 0), 0)))
10106 /* Undo effects of boolean_increment for post {in,de}crement. */
10107 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
10110 if (TREE_CODE (lhs
) == MODIFY_EXPR
10111 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
10113 /* Undo effects of boolean_increment. */
10114 if (integer_onep (TREE_OPERAND (lhs
, 1)))
10116 /* This is pre or post increment. */
10117 rhs
= TREE_OPERAND (lhs
, 1);
10118 lhs
= TREE_OPERAND (lhs
, 0);
10120 if (code
== OMP_ATOMIC_CAPTURE_NEW
10121 && !structured_block
10122 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10123 code
= OMP_ATOMIC_CAPTURE_OLD
;
10126 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
10127 && TREE_OPERAND (lhs
, 0)
10128 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
10130 /* This is pre or post decrement. */
10131 rhs
= TREE_OPERAND (lhs
, 1);
10132 lhs
= TREE_OPERAND (lhs
, 0);
10134 if (code
== OMP_ATOMIC_CAPTURE_NEW
10135 && !structured_block
10136 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10137 code
= OMP_ATOMIC_CAPTURE_OLD
;
10143 switch (c_parser_peek_token (parser
)->type
)
10146 opcode
= MULT_EXPR
;
10149 opcode
= TRUNC_DIV_EXPR
;
10152 opcode
= PLUS_EXPR
;
10155 opcode
= MINUS_EXPR
;
10157 case CPP_LSHIFT_EQ
:
10158 opcode
= LSHIFT_EXPR
;
10160 case CPP_RSHIFT_EQ
:
10161 opcode
= RSHIFT_EXPR
;
10164 opcode
= BIT_AND_EXPR
;
10167 opcode
= BIT_IOR_EXPR
;
10170 opcode
= BIT_XOR_EXPR
;
10173 if (structured_block
|| code
== OMP_ATOMIC
)
10175 location_t aloc
= c_parser_peek_token (parser
)->location
;
10176 location_t rhs_loc
;
10177 enum c_parser_prec oprec
= PREC_NONE
;
10179 c_parser_consume_token (parser
);
10180 rhs1
= c_parser_unary_expression (parser
).value
;
10181 rhs1
= c_fully_fold (rhs1
, false, NULL
);
10182 if (rhs1
== error_mark_node
)
10184 switch (c_parser_peek_token (parser
)->type
)
10186 case CPP_SEMICOLON
:
10187 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
10189 code
= OMP_ATOMIC_CAPTURE_OLD
;
10194 c_parser_consume_token (parser
);
10197 c_parser_error (parser
,
10198 "invalid form of %<#pragma omp atomic%>");
10201 opcode
= MULT_EXPR
;
10205 opcode
= TRUNC_DIV_EXPR
;
10209 opcode
= PLUS_EXPR
;
10213 opcode
= MINUS_EXPR
;
10217 opcode
= LSHIFT_EXPR
;
10218 oprec
= PREC_SHIFT
;
10221 opcode
= RSHIFT_EXPR
;
10222 oprec
= PREC_SHIFT
;
10225 opcode
= BIT_AND_EXPR
;
10226 oprec
= PREC_BITAND
;
10229 opcode
= BIT_IOR_EXPR
;
10230 oprec
= PREC_BITOR
;
10233 opcode
= BIT_XOR_EXPR
;
10234 oprec
= PREC_BITXOR
;
10237 c_parser_error (parser
,
10238 "invalid operator for %<#pragma omp atomic%>");
10242 c_parser_consume_token (parser
);
10243 rhs_loc
= c_parser_peek_token (parser
)->location
;
10244 if (commutative_tree_code (opcode
))
10245 oprec
= (enum c_parser_prec
) (oprec
- 1);
10246 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
10247 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
10249 rhs
= rhs_expr
.value
;
10250 rhs
= c_fully_fold (rhs
, false, NULL
);
10255 c_parser_error (parser
,
10256 "invalid operator for %<#pragma omp atomic%>");
10260 /* Arrange to pass the location of the assignment operator to
10261 c_finish_omp_atomic. */
10262 loc
= c_parser_peek_token (parser
)->location
;
10263 c_parser_consume_token (parser
);
10265 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
10266 rhs_expr
= c_parser_expression (parser
);
10267 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
10269 rhs
= rhs_expr
.value
;
10270 rhs
= c_fully_fold (rhs
, false, NULL
);
10274 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
10276 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
10278 v
= c_parser_unary_expression (parser
).value
;
10279 v
= c_fully_fold (v
, false, NULL
);
10280 if (v
== error_mark_node
)
10282 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10284 lhs1
= c_parser_unary_expression (parser
).value
;
10285 lhs1
= c_fully_fold (lhs1
, false, NULL
);
10286 if (lhs1
== error_mark_node
)
10289 if (structured_block
)
10291 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10292 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
10295 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
10296 if (stmt
!= error_mark_node
)
10299 if (!structured_block
)
10300 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10305 # pragma omp barrier new-line
10309 c_parser_omp_barrier (c_parser
*parser
)
10311 location_t loc
= c_parser_peek_token (parser
)->location
;
10312 c_parser_consume_pragma (parser
);
10313 c_parser_skip_to_pragma_eol (parser
);
10315 c_finish_omp_barrier (loc
);
10319 # pragma omp critical [(name)] new-line
10322 LOC is the location of the #pragma itself. */
10325 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
10327 tree stmt
, name
= NULL
;
10329 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10331 c_parser_consume_token (parser
);
10332 if (c_parser_next_token_is (parser
, CPP_NAME
))
10334 name
= c_parser_peek_token (parser
)->value
;
10335 c_parser_consume_token (parser
);
10336 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10339 c_parser_error (parser
, "expected identifier");
10341 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10342 c_parser_error (parser
, "expected %<(%> or end of line");
10343 c_parser_skip_to_pragma_eol (parser
);
10345 stmt
= c_parser_omp_structured_block (parser
);
10346 return c_finish_omp_critical (loc
, stmt
, name
);
10350 # pragma omp flush flush-vars[opt] new-line
10353 ( variable-list ) */
10356 c_parser_omp_flush (c_parser
*parser
)
10358 location_t loc
= c_parser_peek_token (parser
)->location
;
10359 c_parser_consume_pragma (parser
);
10360 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10361 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10362 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10363 c_parser_error (parser
, "expected %<(%> or end of line");
10364 c_parser_skip_to_pragma_eol (parser
);
10366 c_finish_omp_flush (loc
);
10369 /* Parse the restricted form of the for statement allowed by OpenMP.
10370 The real trick here is to determine the loop control variable early
10371 so that we can push a new decl if necessary to make it private.
10372 LOC is the location of the OMP in "#pragma omp". */
10375 c_parser_omp_for_loop (location_t loc
,
10376 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
10378 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
10379 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
10380 bool fail
= false, open_brace_parsed
= false;
10381 int i
, collapse
= 1, nbraces
= 0;
10382 location_t for_loc
;
10383 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
10385 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
10386 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
10387 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
10389 gcc_assert (collapse
>= 1);
10391 declv
= make_tree_vec (collapse
);
10392 initv
= make_tree_vec (collapse
);
10393 condv
= make_tree_vec (collapse
);
10394 incrv
= make_tree_vec (collapse
);
10396 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
10398 c_parser_error (parser
, "for statement expected");
10401 for_loc
= c_parser_peek_token (parser
)->location
;
10402 c_parser_consume_token (parser
);
10404 for (i
= 0; i
< collapse
; i
++)
10406 int bracecount
= 0;
10408 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10411 /* Parse the initialization declaration or expression. */
10412 if (c_parser_next_tokens_start_declaration (parser
))
10415 vec_safe_push (for_block
, c_begin_compound_stmt (true));
10416 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
10417 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
10420 if (DECL_INITIAL (decl
) == error_mark_node
)
10421 decl
= error_mark_node
;
10424 else if (c_parser_next_token_is (parser
, CPP_NAME
)
10425 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
10427 struct c_expr decl_exp
;
10428 struct c_expr init_exp
;
10429 location_t init_loc
;
10431 decl_exp
= c_parser_postfix_expression (parser
);
10432 decl
= decl_exp
.value
;
10434 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
10436 init_loc
= c_parser_peek_token (parser
)->location
;
10437 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
10438 init_exp
= default_function_array_read_conversion (init_loc
,
10440 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
10441 NOP_EXPR
, init_loc
, init_exp
.value
,
10442 init_exp
.original_type
);
10443 init
= c_process_expr_stmt (init_loc
, init
);
10445 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10450 c_parser_error (parser
,
10451 "expected iteration declaration or initialization");
10452 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10458 /* Parse the loop condition. */
10460 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
10462 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
10463 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
10466 cond
= cond_expr
.value
;
10467 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
10468 cond
= c_fully_fold (cond
, false, NULL
);
10469 switch (cond_expr
.original_code
)
10477 /* Can't be cond = error_mark_node, because we want to preserve
10478 the location until c_finish_omp_for. */
10479 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
10482 protected_set_expr_location (cond
, cond_loc
);
10484 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10486 /* Parse the increment expression. */
10488 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
10490 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
10492 incr
= c_process_expr_stmt (incr_loc
,
10493 c_parser_expression (parser
).value
);
10495 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10497 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
10501 TREE_VEC_ELT (declv
, i
) = decl
;
10502 TREE_VEC_ELT (initv
, i
) = init
;
10503 TREE_VEC_ELT (condv
, i
) = cond
;
10504 TREE_VEC_ELT (incrv
, i
) = incr
;
10508 if (i
== collapse
- 1)
10511 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10512 in between the collapsed for loops to be still considered perfectly
10513 nested. Hopefully the final version clarifies this.
10514 For now handle (multiple) {'s and empty statements. */
10517 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10519 c_parser_consume_token (parser
);
10522 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10524 c_parser_consume_token (parser
);
10527 else if (bracecount
10528 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10529 c_parser_consume_token (parser
);
10532 c_parser_error (parser
, "not enough perfectly nested loops");
10535 open_brace_parsed
= true;
10545 nbraces
+= bracecount
;
10548 save_break
= c_break_label
;
10549 c_break_label
= size_one_node
;
10550 save_cont
= c_cont_label
;
10551 c_cont_label
= NULL_TREE
;
10552 body
= push_stmt_list ();
10554 if (open_brace_parsed
)
10556 location_t here
= c_parser_peek_token (parser
)->location
;
10557 stmt
= c_begin_compound_stmt (true);
10558 c_parser_compound_statement_nostart (parser
);
10559 add_stmt (c_end_compound_stmt (here
, stmt
, true));
10562 add_stmt (c_parser_c99_block_statement (parser
));
10565 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
10566 SET_EXPR_LOCATION (t
, loc
);
10570 body
= pop_stmt_list (body
);
10571 c_break_label
= save_break
;
10572 c_cont_label
= save_cont
;
10576 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10578 c_parser_consume_token (parser
);
10581 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10582 c_parser_consume_token (parser
);
10585 c_parser_error (parser
, "collapsed loops not perfectly nested");
10588 location_t here
= c_parser_peek_token (parser
)->location
;
10589 stmt
= c_begin_compound_stmt (true);
10591 c_parser_compound_statement_nostart (parser
);
10592 body
= c_end_compound_stmt (here
, stmt
, true);
10599 /* Only bother calling c_finish_omp_for if we haven't already generated
10600 an error from the initialization parsing. */
10603 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
10606 if (par_clauses
!= NULL
)
10609 for (c
= par_clauses
; *c
; )
10610 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
10611 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
10612 c
= &OMP_CLAUSE_CHAIN (*c
);
10615 for (i
= 0; i
< collapse
; i
++)
10616 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
10619 c
= &OMP_CLAUSE_CHAIN (*c
);
10620 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
10623 "iteration variable %qD should not be firstprivate",
10624 OMP_CLAUSE_DECL (*c
));
10625 *c
= OMP_CLAUSE_CHAIN (*c
);
10629 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10630 change it to shared (decl) in
10631 OMP_PARALLEL_CLAUSES. */
10632 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
10633 OMP_CLAUSE_LASTPRIVATE
);
10634 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
10635 OMP_CLAUSE_CHAIN (l
) = clauses
;
10637 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
10641 OMP_FOR_CLAUSES (stmt
) = clauses
;
10646 while (!for_block
->is_empty ())
10648 /* FIXME diagnostics: LOC below should be the actual location of
10649 this particular for block. We need to build a list of
10650 locations to go along with FOR_BLOCK. */
10651 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
10654 release_tree_vector (for_block
);
10659 #pragma omp for for-clause[optseq] new-line
10662 LOC is the location of the #pragma token.
10665 #define OMP_FOR_CLAUSE_MASK \
10666 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10667 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10668 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10669 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10670 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10671 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10672 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10673 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10676 c_parser_omp_for (location_t loc
, c_parser
*parser
)
10678 tree block
, clauses
, ret
;
10680 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
10681 "#pragma omp for");
10683 block
= c_begin_compound_stmt (true);
10684 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
10685 block
= c_end_compound_stmt (loc
, block
, true);
10692 # pragma omp master new-line
10695 LOC is the location of the #pragma token.
10699 c_parser_omp_master (location_t loc
, c_parser
*parser
)
10701 c_parser_skip_to_pragma_eol (parser
);
10702 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
10706 # pragma omp ordered new-line
10709 LOC is the location of the #pragma itself.
10713 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
10715 c_parser_skip_to_pragma_eol (parser
);
10716 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
10722 { section-sequence }
10725 section-directive[opt] structured-block
10726 section-sequence section-directive structured-block
10728 SECTIONS_LOC is the location of the #pragma omp sections. */
10731 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
10733 tree stmt
, substmt
;
10734 bool error_suppress
= false;
10737 loc
= c_parser_peek_token (parser
)->location
;
10738 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10740 /* Avoid skipping until the end of the block. */
10741 parser
->error
= false;
10745 stmt
= push_stmt_list ();
10747 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10749 substmt
= push_stmt_list ();
10753 c_parser_statement (parser
);
10755 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10757 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10759 if (c_parser_next_token_is (parser
, CPP_EOF
))
10763 substmt
= pop_stmt_list (substmt
);
10764 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10765 SET_EXPR_LOCATION (substmt
, loc
);
10766 add_stmt (substmt
);
10771 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10773 if (c_parser_next_token_is (parser
, CPP_EOF
))
10776 loc
= c_parser_peek_token (parser
)->location
;
10777 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10779 c_parser_consume_pragma (parser
);
10780 c_parser_skip_to_pragma_eol (parser
);
10781 error_suppress
= false;
10783 else if (!error_suppress
)
10785 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10786 error_suppress
= true;
10789 substmt
= c_parser_omp_structured_block (parser
);
10790 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10791 SET_EXPR_LOCATION (substmt
, loc
);
10792 add_stmt (substmt
);
10794 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10795 "expected %<#pragma omp section%> or %<}%>");
10797 substmt
= pop_stmt_list (stmt
);
10799 stmt
= make_node (OMP_SECTIONS
);
10800 SET_EXPR_LOCATION (stmt
, sections_loc
);
10801 TREE_TYPE (stmt
) = void_type_node
;
10802 OMP_SECTIONS_BODY (stmt
) = substmt
;
10804 return add_stmt (stmt
);
10808 # pragma omp sections sections-clause[optseq] newline
10811 LOC is the location of the #pragma token.
10814 #define OMP_SECTIONS_CLAUSE_MASK \
10815 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10816 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10817 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10818 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10819 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10822 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10824 tree block
, clauses
, ret
;
10826 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10827 "#pragma omp sections");
10829 block
= c_begin_compound_stmt (true);
10830 ret
= c_parser_omp_sections_scope (loc
, parser
);
10832 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10833 block
= c_end_compound_stmt (loc
, block
, true);
10840 # pragma parallel parallel-clause new-line
10841 # pragma parallel for parallel-for-clause new-line
10842 # pragma parallel sections parallel-sections-clause new-line
10844 LOC is the location of the #pragma token.
10847 #define OMP_PARALLEL_CLAUSE_MASK \
10848 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10849 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10850 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10851 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10852 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10853 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10854 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10855 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10858 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10860 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10861 const char *p_name
= "#pragma omp parallel";
10862 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10863 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10865 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10867 c_parser_consume_token (parser
);
10868 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10869 p_name
= "#pragma omp parallel for";
10870 mask
|= OMP_FOR_CLAUSE_MASK
;
10871 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10873 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10875 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10876 if (strcmp (p
, "sections") == 0)
10878 c_parser_consume_token (parser
);
10879 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10880 p_name
= "#pragma omp parallel sections";
10881 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10882 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10886 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10890 case PRAGMA_OMP_PARALLEL
:
10891 block
= c_begin_omp_parallel ();
10892 c_parser_statement (parser
);
10893 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10896 case PRAGMA_OMP_PARALLEL_FOR
:
10897 block
= c_begin_omp_parallel ();
10898 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10899 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10900 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10901 OMP_PARALLEL_COMBINED (stmt
) = 1;
10904 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10905 block
= c_begin_omp_parallel ();
10906 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10907 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10909 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10910 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10911 OMP_PARALLEL_COMBINED (stmt
) = 1;
10915 gcc_unreachable ();
10922 # pragma omp single single-clause[optseq] new-line
10925 LOC is the location of the #pragma.
10928 #define OMP_SINGLE_CLAUSE_MASK \
10929 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10930 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10931 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10932 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10935 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10937 tree stmt
= make_node (OMP_SINGLE
);
10938 SET_EXPR_LOCATION (stmt
, loc
);
10939 TREE_TYPE (stmt
) = void_type_node
;
10941 OMP_SINGLE_CLAUSES (stmt
)
10942 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10943 "#pragma omp single");
10944 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10946 return add_stmt (stmt
);
10950 # pragma omp task task-clause[optseq] new-line
10952 LOC is the location of the #pragma.
10955 #define OMP_TASK_CLAUSE_MASK \
10956 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10957 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10958 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10959 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10960 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10961 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10962 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10963 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10966 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10968 tree clauses
, block
;
10970 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10971 "#pragma omp task");
10973 block
= c_begin_omp_task ();
10974 c_parser_statement (parser
);
10975 return c_finish_omp_task (loc
, clauses
, block
);
10979 # pragma omp taskwait new-line
10983 c_parser_omp_taskwait (c_parser
*parser
)
10985 location_t loc
= c_parser_peek_token (parser
)->location
;
10986 c_parser_consume_pragma (parser
);
10987 c_parser_skip_to_pragma_eol (parser
);
10989 c_finish_omp_taskwait (loc
);
10993 # pragma omp taskyield new-line
10997 c_parser_omp_taskyield (c_parser
*parser
)
10999 location_t loc
= c_parser_peek_token (parser
)->location
;
11000 c_parser_consume_pragma (parser
);
11001 c_parser_skip_to_pragma_eol (parser
);
11003 c_finish_omp_taskyield (loc
);
11006 /* Main entry point to parsing most OpenMP pragmas. */
11009 c_parser_omp_construct (c_parser
*parser
)
11011 enum pragma_kind p_kind
;
11015 loc
= c_parser_peek_token (parser
)->location
;
11016 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
11017 c_parser_consume_pragma (parser
);
11021 case PRAGMA_OMP_ATOMIC
:
11022 c_parser_omp_atomic (loc
, parser
);
11024 case PRAGMA_OMP_CRITICAL
:
11025 stmt
= c_parser_omp_critical (loc
, parser
);
11027 case PRAGMA_OMP_FOR
:
11028 stmt
= c_parser_omp_for (loc
, parser
);
11030 case PRAGMA_OMP_MASTER
:
11031 stmt
= c_parser_omp_master (loc
, parser
);
11033 case PRAGMA_OMP_ORDERED
:
11034 stmt
= c_parser_omp_ordered (loc
, parser
);
11036 case PRAGMA_OMP_PARALLEL
:
11037 stmt
= c_parser_omp_parallel (loc
, parser
);
11039 case PRAGMA_OMP_SECTIONS
:
11040 stmt
= c_parser_omp_sections (loc
, parser
);
11042 case PRAGMA_OMP_SINGLE
:
11043 stmt
= c_parser_omp_single (loc
, parser
);
11045 case PRAGMA_OMP_TASK
:
11046 stmt
= c_parser_omp_task (loc
, parser
);
11049 gcc_unreachable ();
11053 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
11058 # pragma omp threadprivate (variable-list) */
11061 c_parser_omp_threadprivate (c_parser
*parser
)
11066 c_parser_consume_pragma (parser
);
11067 loc
= c_parser_peek_token (parser
)->location
;
11068 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11070 /* Mark every variable in VARS to be assigned thread local storage. */
11071 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
11073 tree v
= TREE_PURPOSE (t
);
11075 /* FIXME diagnostics: Ideally we should keep individual
11076 locations for all the variables in the var list to make the
11077 following errors more precise. Perhaps
11078 c_parser_omp_var_list_parens() should construct a list of
11079 locations to go along with the var list. */
11081 /* If V had already been marked threadprivate, it doesn't matter
11082 whether it had been used prior to this point. */
11083 if (TREE_CODE (v
) != VAR_DECL
)
11084 error_at (loc
, "%qD is not a variable", v
);
11085 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
11086 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
11087 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
11088 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
11089 else if (TREE_TYPE (v
) == error_mark_node
)
11091 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
11092 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
11095 if (! DECL_THREAD_LOCAL_P (v
))
11097 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
11098 /* If rtl has been already set for this var, call
11099 make_decl_rtl once again, so that encode_section_info
11100 has a chance to look at the new decl flags. */
11101 if (DECL_RTL_SET_P (v
))
11104 C_DECL_THREADPRIVATE_P (v
) = 1;
11108 c_parser_skip_to_pragma_eol (parser
);
11111 /* Parse a transaction attribute (GCC Extension).
11113 transaction-attribute:
11117 The transactional memory language description is written for C++,
11118 and uses the C++0x attribute syntax. For compatibility, allow the
11119 bracket style for transactions in C as well. */
11122 c_parser_transaction_attributes (c_parser
*parser
)
11124 tree attr_name
, attr
= NULL
;
11126 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
11127 return c_parser_attributes (parser
);
11129 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11131 c_parser_consume_token (parser
);
11132 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
11135 attr_name
= c_parser_attribute_any_word (parser
);
11138 c_parser_consume_token (parser
);
11139 attr
= build_tree_list (attr_name
, NULL_TREE
);
11142 c_parser_error (parser
, "expected identifier");
11144 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11146 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11150 /* Parse a __transaction_atomic or __transaction_relaxed statement
11153 transaction-statement:
11154 __transaction_atomic transaction-attribute[opt] compound-statement
11155 __transaction_relaxed compound-statement
11157 Note that the only valid attribute is: "outer".
11161 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
11163 unsigned int old_in
= parser
->in_transaction
;
11164 unsigned int this_in
= 1, new_in
;
11165 location_t loc
= c_parser_peek_token (parser
)->location
;
11168 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
11169 || keyword
== RID_TRANSACTION_RELAXED
)
11170 && c_parser_next_token_is_keyword (parser
, keyword
));
11171 c_parser_consume_token (parser
);
11173 if (keyword
== RID_TRANSACTION_RELAXED
)
11174 this_in
|= TM_STMT_ATTR_RELAXED
;
11177 attrs
= c_parser_transaction_attributes (parser
);
11179 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
11182 /* Keep track if we're in the lexical scope of an outer transaction. */
11183 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
11185 parser
->in_transaction
= new_in
;
11186 stmt
= c_parser_compound_statement (parser
);
11187 parser
->in_transaction
= old_in
;
11190 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
11192 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
11193 "%<__transaction_atomic%> without transactional memory support enabled"
11194 : "%<__transaction_relaxed %> "
11195 "without transactional memory support enabled"));
11200 /* Parse a __transaction_atomic or __transaction_relaxed expression
11203 transaction-expression:
11204 __transaction_atomic ( expression )
11205 __transaction_relaxed ( expression )
11208 static struct c_expr
11209 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
11212 unsigned int old_in
= parser
->in_transaction
;
11213 unsigned int this_in
= 1;
11214 location_t loc
= c_parser_peek_token (parser
)->location
;
11217 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
11218 || keyword
== RID_TRANSACTION_RELAXED
)
11219 && c_parser_next_token_is_keyword (parser
, keyword
));
11220 c_parser_consume_token (parser
);
11222 if (keyword
== RID_TRANSACTION_RELAXED
)
11223 this_in
|= TM_STMT_ATTR_RELAXED
;
11226 attrs
= c_parser_transaction_attributes (parser
);
11228 this_in
|= parse_tm_stmt_attr (attrs
, 0);
11231 parser
->in_transaction
= this_in
;
11232 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11234 tree expr
= c_parser_expression (parser
).value
;
11235 ret
.original_type
= TREE_TYPE (expr
);
11236 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
11237 if (this_in
& TM_STMT_ATTR_RELAXED
)
11238 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
11239 SET_EXPR_LOCATION (ret
.value
, loc
);
11240 ret
.original_code
= TRANSACTION_EXPR
;
11241 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11243 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
11250 ret
.value
= error_mark_node
;
11251 ret
.original_code
= ERROR_MARK
;
11252 ret
.original_type
= NULL
;
11254 parser
->in_transaction
= old_in
;
11257 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
11258 "%<__transaction_atomic%> without transactional memory support enabled"
11259 : "%<__transaction_relaxed %> "
11260 "without transactional memory support enabled"));
11265 /* Parse a __transaction_cancel statement (GCC Extension).
11267 transaction-cancel-statement:
11268 __transaction_cancel transaction-attribute[opt] ;
11270 Note that the only valid attribute is "outer".
11274 c_parser_transaction_cancel(c_parser
*parser
)
11276 location_t loc
= c_parser_peek_token (parser
)->location
;
11278 bool is_outer
= false;
11280 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
11281 c_parser_consume_token (parser
);
11283 attrs
= c_parser_transaction_attributes (parser
);
11285 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
11289 error_at (loc
, "%<__transaction_cancel%> without "
11290 "transactional memory support enabled");
11293 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
11295 error_at (loc
, "%<__transaction_cancel%> within a "
11296 "%<__transaction_relaxed%>");
11301 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
11302 && !is_tm_may_cancel_outer (current_function_decl
))
11304 error_at (loc
, "outer %<__transaction_cancel%> not "
11305 "within outer %<__transaction_atomic%>");
11306 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
11310 else if (parser
->in_transaction
== 0)
11312 error_at (loc
, "%<__transaction_cancel%> not within "
11313 "%<__transaction_atomic%>");
11317 return add_stmt (build_tm_abort_call (loc
, is_outer
));
11320 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
11323 /* Parse a single source file. */
11326 c_parse_file (void)
11328 /* Use local storage to begin. If the first token is a pragma, parse it.
11329 If it is #pragma GCC pch_preprocess, then this will load a PCH file
11330 which will cause garbage collection. */
11333 memset (&tparser
, 0, sizeof tparser
);
11334 the_parser
= &tparser
;
11336 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
11337 c_parser_pragma_pch_preprocess (&tparser
);
11339 the_parser
= ggc_alloc_c_parser ();
11340 *the_parser
= tparser
;
11342 /* Initialize EH, if we've been told to do so. */
11343 if (flag_exceptions
)
11344 using_eh_for_cleanups ();
11346 c_parser_translation_unit (the_parser
);
11350 #include "gt-c-c-parser.h"