1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011,
4 2012 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
43 #include "tm.h" /* For rtl.h: needs enum reg_class. */
45 #include "langhooks.h"
49 #include "c-family/c-pragma.h"
53 #include "c-family/c-common.h"
54 #include "c-family/c-objc.h"
61 /* Initialization routine for this file. */
66 /* The only initialization required is of the reserved word
72 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
73 the c_token structure. */
74 gcc_assert (RID_MAX
<= 255);
81 mask
|= D_ASM
| D_EXT
;
85 if (!c_dialect_objc ())
86 mask
|= D_OBJC
| D_CXX_OBJC
;
88 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
89 for (i
= 0; i
< num_c_common_reswords
; i
++)
91 /* If a keyword is disabled, do not enter it into the table
92 and so create a canonical spelling that isn't a keyword. */
93 if (c_common_reswords
[i
].disable
& mask
)
96 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
98 id
= get_identifier (c_common_reswords
[i
].word
);
99 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
100 C_IS_RESERVED_WORD (id
) = 1;
105 id
= get_identifier (c_common_reswords
[i
].word
);
106 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
107 C_IS_RESERVED_WORD (id
) = 1;
108 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
112 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
113 and the C parser. Unlike the C++ lexer, the parser structure
114 stores the lexer information instead of using a separate structure.
115 Identifiers are separated into ordinary identifiers, type names,
116 keywords and some other Objective-C types of identifiers, and some
117 look-ahead is maintained.
119 ??? It might be a good idea to lex the whole file up front (as for
120 C++). It would then be possible to share more of the C and C++
121 lexer code, if desired. */
123 /* The following local token type is used. */
126 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
128 /* More information about the type of a CPP_NAME token. */
129 typedef enum c_id_kind
{
130 /* An ordinary identifier. */
132 /* An identifier declared as a typedef name. */
134 /* An identifier declared as an Objective-C class name. */
136 /* An address space identifier. */
138 /* Not an identifier. */
142 /* A single C token after string literal concatenation and conversion
143 of preprocessing tokens to tokens. */
144 typedef struct GTY (()) c_token
{
145 /* The kind of token. */
146 ENUM_BITFIELD (cpp_ttype
) type
: 8;
147 /* If this token is a CPP_NAME, this value indicates whether also
148 declared as some kind of type. Otherwise, it is C_ID_NONE. */
149 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
150 /* If this token is a keyword, this value indicates which keyword.
151 Otherwise, this value is RID_MAX. */
152 ENUM_BITFIELD (rid
) keyword
: 8;
153 /* If this token is a CPP_PRAGMA, this indicates the pragma that
154 was seen. Otherwise it is PRAGMA_NONE. */
155 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
156 /* The location at which this token was found. */
158 /* The value associated with this token, if any. */
162 /* A parser structure recording information about the state and
163 context of parsing. Includes lexer information with up to two
164 tokens of look-ahead; more are not needed for C. */
165 typedef struct GTY(()) c_parser
{
166 /* The look-ahead tokens. */
168 /* How many look-ahead tokens are available (0, 1 or 2). */
170 /* True if a syntax error is being recovered from; false otherwise.
171 c_parser_error sets this flag. It should clear this flag when
172 enough tokens have been consumed to recover from the error. */
173 BOOL_BITFIELD error
: 1;
174 /* True if we're processing a pragma, and shouldn't automatically
175 consume CPP_PRAGMA_EOL. */
176 BOOL_BITFIELD in_pragma
: 1;
177 /* True if we're parsing the outermost block of an if statement. */
178 BOOL_BITFIELD in_if_block
: 1;
179 /* True if we want to lex an untranslated string. */
180 BOOL_BITFIELD lex_untranslated_string
: 1;
182 /* Objective-C specific parser/lexer information. */
184 /* True if we are in a context where the Objective-C "PQ" keywords
185 are considered keywords. */
186 BOOL_BITFIELD objc_pq_context
: 1;
187 /* True if we are parsing a (potential) Objective-C foreach
188 statement. This is set to true after we parsed 'for (' and while
189 we wait for 'in' or ';' to decide if it's a standard C for loop or an
190 Objective-C foreach loop. */
191 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
192 /* The following flag is needed to contextualize Objective-C lexical
193 analysis. In some cases (e.g., 'int NSObject;'), it is
194 undesirable to bind an identifier to an Objective-C class, even
195 if a class with that name exists. */
196 BOOL_BITFIELD objc_need_raw_identifier
: 1;
197 /* Nonzero if we're processing a __transaction statement. The value
198 is 1 | TM_STMT_ATTR_*. */
199 unsigned int in_transaction
: 4;
200 /* True if we are in a context where the Objective-C "Property attribute"
201 keywords are valid. */
202 BOOL_BITFIELD objc_property_attr_context
: 1;
206 /* The actual parser and external interface. ??? Does this need to be
207 garbage-collected? */
209 static GTY (()) c_parser
*the_parser
;
211 /* Read in and lex a single token, storing it in *TOKEN. */
214 c_lex_one_token (c_parser
*parser
, c_token
*token
)
216 timevar_push (TV_LEX
);
218 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
219 (parser
->lex_untranslated_string
220 ? C_LEX_STRING_NO_TRANSLATE
: 0));
221 token
->id_kind
= C_ID_NONE
;
222 token
->keyword
= RID_MAX
;
223 token
->pragma_kind
= PRAGMA_NONE
;
231 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
232 if (c_dialect_objc ())
233 parser
->objc_need_raw_identifier
= false;
235 if (C_IS_RESERVED_WORD (token
->value
))
237 enum rid rid_code
= C_RID_CODE (token
->value
);
239 if (rid_code
== RID_CXX_COMPAT_WARN
)
241 warning_at (token
->location
,
243 "identifier %qE conflicts with C++ keyword",
246 else if (rid_code
>= RID_FIRST_ADDR_SPACE
247 && rid_code
<= RID_LAST_ADDR_SPACE
)
249 token
->id_kind
= C_ID_ADDRSPACE
;
250 token
->keyword
= rid_code
;
253 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
255 /* We found an Objective-C "pq" keyword (in, out,
256 inout, bycopy, byref, oneway). They need special
257 care because the interpretation depends on the
259 if (parser
->objc_pq_context
)
261 token
->type
= CPP_KEYWORD
;
262 token
->keyword
= rid_code
;
265 else if (parser
->objc_could_be_foreach_context
266 && rid_code
== RID_IN
)
268 /* We are in Objective-C, inside a (potential)
269 foreach context (which means after having
270 parsed 'for (', but before having parsed ';'),
271 and we found 'in'. We consider it the keyword
272 which terminates the declaration at the
273 beginning of a foreach-statement. Note that
274 this means you can't use 'in' for anything else
275 in that context; in particular, in Objective-C
276 you can't use 'in' as the name of the running
277 variable in a C for loop. We could potentially
278 try to add code here to disambiguate, but it
279 seems a reasonable limitation. */
280 token
->type
= CPP_KEYWORD
;
281 token
->keyword
= rid_code
;
284 /* Else, "pq" keywords outside of the "pq" context are
285 not keywords, and we fall through to the code for
288 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
290 /* We found an Objective-C "property attribute"
291 keyword (getter, setter, readonly, etc). These are
292 only valid in the property context. */
293 if (parser
->objc_property_attr_context
)
295 token
->type
= CPP_KEYWORD
;
296 token
->keyword
= rid_code
;
299 /* Else they are not special keywords.
302 else if (c_dialect_objc ()
303 && (OBJC_IS_AT_KEYWORD (rid_code
)
304 || OBJC_IS_CXX_KEYWORD (rid_code
)))
306 /* We found one of the Objective-C "@" keywords (defs,
307 selector, synchronized, etc) or one of the
308 Objective-C "cxx" keywords (class, private,
309 protected, public, try, catch, throw) without a
310 preceding '@' sign. Do nothing and fall through to
311 the code for normal tokens (in C++ we would still
312 consider the CXX ones keywords, but not in C). */
317 token
->type
= CPP_KEYWORD
;
318 token
->keyword
= rid_code
;
323 decl
= lookup_name (token
->value
);
326 if (TREE_CODE (decl
) == TYPE_DECL
)
328 token
->id_kind
= C_ID_TYPENAME
;
332 else if (c_dialect_objc ())
334 tree objc_interface_decl
= objc_is_class_name (token
->value
);
335 /* Objective-C class names are in the same namespace as
336 variables and typedefs, and hence are shadowed by local
338 if (objc_interface_decl
339 && (!objc_force_identifier
|| global_bindings_p ()))
341 token
->value
= objc_interface_decl
;
342 token
->id_kind
= C_ID_CLASSNAME
;
346 token
->id_kind
= C_ID_ID
;
350 /* This only happens in Objective-C; it must be a keyword. */
351 token
->type
= CPP_KEYWORD
;
352 switch (C_RID_CODE (token
->value
))
354 /* Replace 'class' with '@class', 'private' with '@private',
355 etc. This prevents confusion with the C++ keyword
356 'class', and makes the tokens consistent with other
357 Objective-C 'AT' keywords. For example '@class' is
358 reported as RID_AT_CLASS which is consistent with
359 '@synchronized', which is reported as
362 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
363 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
364 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
365 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
366 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
367 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
368 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
369 default: token
->keyword
= C_RID_CODE (token
->value
);
374 case CPP_CLOSE_PAREN
:
376 /* These tokens may affect the interpretation of any identifiers
377 following, if doing Objective-C. */
378 if (c_dialect_objc ())
379 parser
->objc_need_raw_identifier
= false;
382 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
383 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
389 timevar_pop (TV_LEX
);
392 /* Return a pointer to the next token from PARSER, reading it in if
395 static inline c_token
*
396 c_parser_peek_token (c_parser
*parser
)
398 if (parser
->tokens_avail
== 0)
400 c_lex_one_token (parser
, &parser
->tokens
[0]);
401 parser
->tokens_avail
= 1;
403 return &parser
->tokens
[0];
406 /* Return true if the next token from PARSER has the indicated
410 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
412 return c_parser_peek_token (parser
)->type
== type
;
415 /* Return true if the next token from PARSER does not have the
419 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
421 return !c_parser_next_token_is (parser
, type
);
424 /* Return true if the next token from PARSER is the indicated
428 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
430 return c_parser_peek_token (parser
)->keyword
== keyword
;
433 /* Return a pointer to the next-but-one token from PARSER, reading it
434 in if necessary. The next token is already read in. */
437 c_parser_peek_2nd_token (c_parser
*parser
)
439 if (parser
->tokens_avail
>= 2)
440 return &parser
->tokens
[1];
441 gcc_assert (parser
->tokens_avail
== 1);
442 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
443 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
444 c_lex_one_token (parser
, &parser
->tokens
[1]);
445 parser
->tokens_avail
= 2;
446 return &parser
->tokens
[1];
449 /* Return true if TOKEN can start a type name,
452 c_token_starts_typename (c_token
*token
)
457 switch (token
->id_kind
)
466 gcc_assert (c_dialect_objc ());
472 switch (token
->keyword
)
505 if (c_dialect_objc ())
513 enum c_lookahead_kind
{
514 /* Always treat unknown identifiers as typenames. */
517 /* Could be parsing a nonabstract declarator. Only treat an identifier
518 as a typename if followed by another identifier or a star. */
519 cla_nonabstract_decl
,
521 /* Never treat identifiers as typenames. */
525 /* Return true if the next token from PARSER can start a type name,
526 false otherwise. LA specifies how to do lookahead in order to
527 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
530 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
532 c_token
*token
= c_parser_peek_token (parser
);
533 if (c_token_starts_typename (token
))
536 /* Try a bit harder to detect an unknown typename. */
537 if (la
!= cla_prefer_id
538 && token
->type
== CPP_NAME
539 && token
->id_kind
== C_ID_ID
541 /* Do not try too hard when we could have "object in array". */
542 && !parser
->objc_could_be_foreach_context
544 && (la
== cla_prefer_type
545 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
546 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
548 /* Only unknown identifiers. */
549 && !lookup_name (token
->value
))
555 /* Return true if TOKEN is a type qualifier, false otherwise. */
557 c_token_is_qualifier (c_token
*token
)
562 switch (token
->id_kind
)
570 switch (token
->keyword
)
587 /* Return true if the next token from PARSER is a type qualifier,
590 c_parser_next_token_is_qualifier (c_parser
*parser
)
592 c_token
*token
= c_parser_peek_token (parser
);
593 return c_token_is_qualifier (token
);
596 /* Return true if TOKEN can start declaration specifiers, false
599 c_token_starts_declspecs (c_token
*token
)
604 switch (token
->id_kind
)
613 gcc_assert (c_dialect_objc ());
619 switch (token
->keyword
)
661 if (c_dialect_objc ())
670 /* Return true if TOKEN can start declaration specifiers or a static
671 assertion, false otherwise. */
673 c_token_starts_declaration (c_token
*token
)
675 if (c_token_starts_declspecs (token
)
676 || token
->keyword
== RID_STATIC_ASSERT
)
682 /* Return true if the next token from PARSER can start declaration
683 specifiers, false otherwise. */
685 c_parser_next_token_starts_declspecs (c_parser
*parser
)
687 c_token
*token
= c_parser_peek_token (parser
);
689 /* In Objective-C, a classname normally starts a declspecs unless it
690 is immediately followed by a dot. In that case, it is the
691 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
692 setter/getter on the class. c_token_starts_declspecs() can't
693 differentiate between the two cases because it only checks the
694 current token, so we have a special check here. */
695 if (c_dialect_objc ()
696 && token
->type
== CPP_NAME
697 && token
->id_kind
== C_ID_CLASSNAME
698 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
701 return c_token_starts_declspecs (token
);
704 /* Return true if the next tokens from PARSER can start declaration
705 specifiers or a static assertion, false otherwise. */
707 c_parser_next_tokens_start_declaration (c_parser
*parser
)
709 c_token
*token
= c_parser_peek_token (parser
);
712 if (c_dialect_objc ()
713 && token
->type
== CPP_NAME
714 && token
->id_kind
== C_ID_CLASSNAME
715 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
718 /* Labels do not start declarations. */
719 if (token
->type
== CPP_NAME
720 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
723 if (c_token_starts_declaration (token
))
726 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
732 /* Consume the next token from PARSER. */
735 c_parser_consume_token (c_parser
*parser
)
737 gcc_assert (parser
->tokens_avail
>= 1);
738 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
739 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
740 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
741 if (parser
->tokens_avail
== 2)
742 parser
->tokens
[0] = parser
->tokens
[1];
743 parser
->tokens_avail
--;
746 /* Expect the current token to be a #pragma. Consume it and remember
747 that we've begun parsing a pragma. */
750 c_parser_consume_pragma (c_parser
*parser
)
752 gcc_assert (!parser
->in_pragma
);
753 gcc_assert (parser
->tokens_avail
>= 1);
754 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
755 if (parser
->tokens_avail
== 2)
756 parser
->tokens
[0] = parser
->tokens
[1];
757 parser
->tokens_avail
--;
758 parser
->in_pragma
= true;
761 /* Update the globals input_location and in_system_header from
764 c_parser_set_source_position_from_token (c_token
*token
)
766 if (token
->type
!= CPP_EOF
)
768 input_location
= token
->location
;
772 /* Issue a diagnostic of the form
773 FILE:LINE: MESSAGE before TOKEN
774 where TOKEN is the next token in the input stream of PARSER.
775 MESSAGE (specified by the caller) is usually of the form "expected
778 Do not issue a diagnostic if still recovering from an error.
780 ??? This is taken from the C++ parser, but building up messages in
781 this way is not i18n-friendly and some other approach should be
785 c_parser_error (c_parser
*parser
, const char *gmsgid
)
787 c_token
*token
= c_parser_peek_token (parser
);
790 parser
->error
= true;
793 /* This diagnostic makes more sense if it is tagged to the line of
794 the token we just peeked at. */
795 c_parser_set_source_position_from_token (token
);
796 c_parse_error (gmsgid
,
797 /* Because c_parse_error does not understand
798 CPP_KEYWORD, keywords are treated like
800 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
801 /* ??? The C parser does not save the cpp flags of a
802 token, we need to pass 0 here and we will not get
803 the source spelling of some tokens but rather the
804 canonical spelling. */
805 token
->value
, /*flags=*/0);
808 /* If the next token is of the indicated TYPE, consume it. Otherwise,
809 issue the error MSGID. If MSGID is NULL then a message has already
810 been produced and no message will be produced this time. Returns
811 true if found, false otherwise. */
814 c_parser_require (c_parser
*parser
,
818 if (c_parser_next_token_is (parser
, type
))
820 c_parser_consume_token (parser
);
825 c_parser_error (parser
, msgid
);
830 /* If the next token is the indicated keyword, consume it. Otherwise,
831 issue the error MSGID. Returns true if found, false otherwise. */
834 c_parser_require_keyword (c_parser
*parser
,
838 if (c_parser_next_token_is_keyword (parser
, keyword
))
840 c_parser_consume_token (parser
);
845 c_parser_error (parser
, msgid
);
850 /* Like c_parser_require, except that tokens will be skipped until the
851 desired token is found. An error message is still produced if the
852 next token is not as expected. If MSGID is NULL then a message has
853 already been produced and no message will be produced this
857 c_parser_skip_until_found (c_parser
*parser
,
861 unsigned nesting_depth
= 0;
863 if (c_parser_require (parser
, type
, msgid
))
866 /* Skip tokens until the desired token is found. */
869 /* Peek at the next token. */
870 c_token
*token
= c_parser_peek_token (parser
);
871 /* If we've reached the token we want, consume it and stop. */
872 if (token
->type
== type
&& !nesting_depth
)
874 c_parser_consume_token (parser
);
878 /* If we've run out of tokens, stop. */
879 if (token
->type
== CPP_EOF
)
881 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
883 if (token
->type
== CPP_OPEN_BRACE
884 || token
->type
== CPP_OPEN_PAREN
885 || token
->type
== CPP_OPEN_SQUARE
)
887 else if (token
->type
== CPP_CLOSE_BRACE
888 || token
->type
== CPP_CLOSE_PAREN
889 || token
->type
== CPP_CLOSE_SQUARE
)
891 if (nesting_depth
-- == 0)
894 /* Consume this token. */
895 c_parser_consume_token (parser
);
897 parser
->error
= false;
900 /* Skip tokens until the end of a parameter is found, but do not
901 consume the comma, semicolon or closing delimiter. */
904 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
906 unsigned nesting_depth
= 0;
910 c_token
*token
= c_parser_peek_token (parser
);
911 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
914 /* If we've run out of tokens, stop. */
915 if (token
->type
== CPP_EOF
)
917 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
919 if (token
->type
== CPP_OPEN_BRACE
920 || token
->type
== CPP_OPEN_PAREN
921 || token
->type
== CPP_OPEN_SQUARE
)
923 else if (token
->type
== CPP_CLOSE_BRACE
924 || token
->type
== CPP_CLOSE_PAREN
925 || token
->type
== CPP_CLOSE_SQUARE
)
927 if (nesting_depth
-- == 0)
930 /* Consume this token. */
931 c_parser_consume_token (parser
);
933 parser
->error
= false;
936 /* Expect to be at the end of the pragma directive and consume an
937 end of line marker. */
940 c_parser_skip_to_pragma_eol (c_parser
*parser
)
942 gcc_assert (parser
->in_pragma
);
943 parser
->in_pragma
= false;
945 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
948 c_token
*token
= c_parser_peek_token (parser
);
949 if (token
->type
== CPP_EOF
)
951 if (token
->type
== CPP_PRAGMA_EOL
)
953 c_parser_consume_token (parser
);
956 c_parser_consume_token (parser
);
959 parser
->error
= false;
962 /* Skip tokens until we have consumed an entire block, or until we
963 have consumed a non-nested ';'. */
966 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
968 unsigned nesting_depth
= 0;
969 bool save_error
= parser
->error
;
975 /* Peek at the next token. */
976 token
= c_parser_peek_token (parser
);
984 if (parser
->in_pragma
)
989 /* If the next token is a ';', we have reached the
990 end of the statement. */
993 /* Consume the ';'. */
994 c_parser_consume_token (parser
);
999 case CPP_CLOSE_BRACE
:
1000 /* If the next token is a non-nested '}', then we have
1001 reached the end of the current block. */
1002 if (nesting_depth
== 0 || --nesting_depth
== 0)
1004 c_parser_consume_token (parser
);
1009 case CPP_OPEN_BRACE
:
1010 /* If it the next token is a '{', then we are entering a new
1011 block. Consume the entire block. */
1016 /* If we see a pragma, consume the whole thing at once. We
1017 have some safeguards against consuming pragmas willy-nilly.
1018 Normally, we'd expect to be here with parser->error set,
1019 which disables these safeguards. But it's possible to get
1020 here for secondary error recovery, after parser->error has
1022 c_parser_consume_pragma (parser
);
1023 c_parser_skip_to_pragma_eol (parser
);
1024 parser
->error
= save_error
;
1031 c_parser_consume_token (parser
);
1035 parser
->error
= false;
1038 /* CPP's options (initialized by c-opts.c). */
1039 extern cpp_options
*cpp_opts
;
1041 /* Save the warning flags which are controlled by __extension__. */
1044 disable_extension_diagnostics (void)
1047 | (warn_pointer_arith
<< 1)
1048 | (warn_traditional
<< 2)
1050 | (warn_long_long
<< 4)
1051 | (warn_cxx_compat
<< 5)
1052 | (warn_overlength_strings
<< 6));
1053 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1054 warn_pointer_arith
= 0;
1055 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1057 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1058 warn_cxx_compat
= 0;
1059 warn_overlength_strings
= 0;
1063 /* Restore the warning flags which are controlled by __extension__.
1064 FLAGS is the return value from disable_extension_diagnostics. */
1067 restore_extension_diagnostics (int flags
)
1069 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1070 warn_pointer_arith
= (flags
>> 1) & 1;
1071 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1072 flag_iso
= (flags
>> 3) & 1;
1073 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1074 warn_cxx_compat
= (flags
>> 5) & 1;
1075 warn_overlength_strings
= (flags
>> 6) & 1;
1078 /* Possibly kinds of declarator to parse. */
1079 typedef enum c_dtr_syn
{
1080 /* A normal declarator with an identifier. */
1082 /* An abstract declarator (maybe empty). */
1084 /* A parameter declarator: may be either, but after a type name does
1085 not redeclare a typedef name as an identifier if it can
1086 alternatively be interpreted as a typedef name; see DR#009,
1087 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1088 following DR#249. For example, given a typedef T, "int T" and
1089 "int *T" are valid parameter declarations redeclaring T, while
1090 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1091 abstract declarators rather than involving redundant parentheses;
1092 the same applies with attributes inside the parentheses before
1097 /* The binary operation precedence levels, where 0 is a dummy lowest level
1098 used for the bottom of the stack. */
1099 enum c_parser_prec
{
1114 static void c_parser_external_declaration (c_parser
*);
1115 static void c_parser_asm_definition (c_parser
*);
1116 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1117 bool, bool, tree
*);
1118 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1119 static void c_parser_static_assert_declaration (c_parser
*);
1120 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1121 bool, enum c_lookahead_kind
);
1122 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1123 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1124 static tree
c_parser_struct_declaration (c_parser
*);
1125 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1126 static tree
c_parser_alignas_specifier (c_parser
*);
1127 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1129 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1131 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1133 struct c_declarator
*);
1134 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1135 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1137 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1138 static tree
c_parser_simple_asm_expr (c_parser
*);
1139 static tree
c_parser_attributes (c_parser
*);
1140 static struct c_type_name
*c_parser_type_name (c_parser
*);
1141 static struct c_expr
c_parser_initializer (c_parser
*);
1142 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1143 static void c_parser_initelt (c_parser
*, struct obstack
*);
1144 static void c_parser_initval (c_parser
*, struct c_expr
*,
1146 static tree
c_parser_compound_statement (c_parser
*);
1147 static void c_parser_compound_statement_nostart (c_parser
*);
1148 static void c_parser_label (c_parser
*);
1149 static void c_parser_statement (c_parser
*);
1150 static void c_parser_statement_after_labels (c_parser
*);
1151 static void c_parser_if_statement (c_parser
*);
1152 static void c_parser_switch_statement (c_parser
*);
1153 static void c_parser_while_statement (c_parser
*);
1154 static void c_parser_do_statement (c_parser
*);
1155 static void c_parser_for_statement (c_parser
*);
1156 static tree
c_parser_asm_statement (c_parser
*);
1157 static tree
c_parser_asm_operands (c_parser
*, bool);
1158 static tree
c_parser_asm_goto_operands (c_parser
*);
1159 static tree
c_parser_asm_clobbers (c_parser
*);
1160 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1161 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1163 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1164 enum c_parser_prec
);
1165 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1166 static struct c_expr
c_parser_unary_expression (c_parser
*);
1167 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1168 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1169 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1170 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1171 struct c_type_name
*,
1173 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1176 static tree
c_parser_transaction (c_parser
*, enum rid
);
1177 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1178 static tree
c_parser_transaction_cancel (c_parser
*);
1179 static struct c_expr
c_parser_expression (c_parser
*);
1180 static struct c_expr
c_parser_expression_conv (c_parser
*);
1181 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
1182 VEC(tree
,gc
) **, location_t
*,
1184 static void c_parser_omp_construct (c_parser
*);
1185 static void c_parser_omp_threadprivate (c_parser
*);
1186 static void c_parser_omp_barrier (c_parser
*);
1187 static void c_parser_omp_flush (c_parser
*);
1188 static void c_parser_omp_taskwait (c_parser
*);
1189 static void c_parser_omp_taskyield (c_parser
*);
1191 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1192 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1194 /* These Objective-C parser functions are only ever called when
1195 compiling Objective-C. */
1196 static void c_parser_objc_class_definition (c_parser
*, tree
);
1197 static void c_parser_objc_class_instance_variables (c_parser
*);
1198 static void c_parser_objc_class_declaration (c_parser
*);
1199 static void c_parser_objc_alias_declaration (c_parser
*);
1200 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1201 static bool c_parser_objc_method_type (c_parser
*);
1202 static void c_parser_objc_method_definition (c_parser
*);
1203 static void c_parser_objc_methodprotolist (c_parser
*);
1204 static void c_parser_objc_methodproto (c_parser
*);
1205 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1206 static tree
c_parser_objc_type_name (c_parser
*);
1207 static tree
c_parser_objc_protocol_refs (c_parser
*);
1208 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1209 static void c_parser_objc_synchronized_statement (c_parser
*);
1210 static tree
c_parser_objc_selector (c_parser
*);
1211 static tree
c_parser_objc_selector_arg (c_parser
*);
1212 static tree
c_parser_objc_receiver (c_parser
*);
1213 static tree
c_parser_objc_message_args (c_parser
*);
1214 static tree
c_parser_objc_keywordexpr (c_parser
*);
1215 static void c_parser_objc_at_property_declaration (c_parser
*);
1216 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1217 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1218 static bool c_parser_objc_diagnose_bad_element_prefix
1219 (c_parser
*, struct c_declspecs
*);
1221 /* Parse a translation unit (C90 6.7, C99 6.9).
1224 external-declarations
1226 external-declarations:
1227 external-declaration
1228 external-declarations external-declaration
1237 c_parser_translation_unit (c_parser
*parser
)
1239 if (c_parser_next_token_is (parser
, CPP_EOF
))
1241 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1242 "ISO C forbids an empty translation unit");
1246 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1247 mark_valid_location_for_stdc_pragma (false);
1251 c_parser_external_declaration (parser
);
1252 obstack_free (&parser_obstack
, obstack_position
);
1254 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1258 /* Parse an external declaration (C90 6.7, C99 6.9).
1260 external-declaration:
1266 external-declaration:
1269 __extension__ external-declaration
1273 external-declaration:
1274 objc-class-definition
1275 objc-class-declaration
1276 objc-alias-declaration
1277 objc-protocol-definition
1278 objc-method-definition
1283 c_parser_external_declaration (c_parser
*parser
)
1286 switch (c_parser_peek_token (parser
)->type
)
1289 switch (c_parser_peek_token (parser
)->keyword
)
1292 ext
= disable_extension_diagnostics ();
1293 c_parser_consume_token (parser
);
1294 c_parser_external_declaration (parser
);
1295 restore_extension_diagnostics (ext
);
1298 c_parser_asm_definition (parser
);
1300 case RID_AT_INTERFACE
:
1301 case RID_AT_IMPLEMENTATION
:
1302 gcc_assert (c_dialect_objc ());
1303 c_parser_objc_class_definition (parser
, NULL_TREE
);
1306 gcc_assert (c_dialect_objc ());
1307 c_parser_objc_class_declaration (parser
);
1310 gcc_assert (c_dialect_objc ());
1311 c_parser_objc_alias_declaration (parser
);
1313 case RID_AT_PROTOCOL
:
1314 gcc_assert (c_dialect_objc ());
1315 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1317 case RID_AT_PROPERTY
:
1318 gcc_assert (c_dialect_objc ());
1319 c_parser_objc_at_property_declaration (parser
);
1321 case RID_AT_SYNTHESIZE
:
1322 gcc_assert (c_dialect_objc ());
1323 c_parser_objc_at_synthesize_declaration (parser
);
1325 case RID_AT_DYNAMIC
:
1326 gcc_assert (c_dialect_objc ());
1327 c_parser_objc_at_dynamic_declaration (parser
);
1330 gcc_assert (c_dialect_objc ());
1331 c_parser_consume_token (parser
);
1332 objc_finish_implementation ();
1339 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1340 "ISO C does not allow extra %<;%> outside of a function");
1341 c_parser_consume_token (parser
);
1344 mark_valid_location_for_stdc_pragma (true);
1345 c_parser_pragma (parser
, pragma_external
);
1346 mark_valid_location_for_stdc_pragma (false);
1350 if (c_dialect_objc ())
1352 c_parser_objc_method_definition (parser
);
1355 /* Else fall through, and yield a syntax error trying to parse
1356 as a declaration or function definition. */
1359 /* A declaration or a function definition (or, in Objective-C,
1360 an @interface or @protocol with prefix attributes). We can
1361 only tell which after parsing the declaration specifiers, if
1362 any, and the first declarator. */
1363 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1368 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1369 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1370 accepted; otherwise (old-style parameter declarations) only other
1371 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1372 assertion is accepted; otherwise (old-style parameter declarations)
1373 it is not. If NESTED is true, we are inside a function or parsing
1374 old-style parameter declarations; any functions encountered are
1375 nested functions and declaration specifiers are required; otherwise
1376 we are at top level and functions are normal functions and
1377 declaration specifiers may be optional. If EMPTY_OK is true, empty
1378 declarations are OK (subject to all other constraints); otherwise
1379 (old-style parameter declarations) they are diagnosed. If
1380 START_ATTR_OK is true, the declaration specifiers may start with
1381 attributes; otherwise they may not.
1382 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1383 declaration when parsing an Objective-C foreach statement.
1386 declaration-specifiers init-declarator-list[opt] ;
1387 static_assert-declaration
1389 function-definition:
1390 declaration-specifiers[opt] declarator declaration-list[opt]
1395 declaration-list declaration
1397 init-declarator-list:
1399 init-declarator-list , init-declarator
1402 declarator simple-asm-expr[opt] attributes[opt]
1403 declarator simple-asm-expr[opt] attributes[opt] = initializer
1407 nested-function-definition:
1408 declaration-specifiers declarator declaration-list[opt]
1412 attributes objc-class-definition
1413 attributes objc-category-definition
1414 attributes objc-protocol-definition
1416 The simple-asm-expr and attributes are GNU extensions.
1418 This function does not handle __extension__; that is handled in its
1419 callers. ??? Following the old parser, __extension__ may start
1420 external declarations, declarations in functions and declarations
1421 at the start of "for" loops, but not old-style parameter
1424 C99 requires declaration specifiers in a function definition; the
1425 absence is diagnosed through the diagnosis of implicit int. In GNU
1426 C we also allow but diagnose declarations without declaration
1427 specifiers, but only at top level (elsewhere they conflict with
1430 In Objective-C, declarations of the looping variable in a foreach
1431 statement are exceptionally terminated by 'in' (for example, 'for
1432 (NSObject *object in array) { ... }').
1437 threadprivate-directive */
1440 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1441 bool static_assert_ok
, bool empty_ok
,
1442 bool nested
, bool start_attr_ok
,
1443 tree
*objc_foreach_object_declaration
)
1445 struct c_declspecs
*specs
;
1447 tree all_prefix_attrs
;
1448 bool diagnosed_no_specs
= false;
1449 location_t here
= c_parser_peek_token (parser
)->location
;
1451 if (static_assert_ok
1452 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1454 c_parser_static_assert_declaration (parser
);
1457 specs
= build_null_declspecs ();
1459 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1460 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1461 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1462 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1463 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1464 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1466 error_at (here
, "unknown type name %qE",
1467 c_parser_peek_token (parser
)->value
);
1469 /* Parse declspecs normally to get a correct pointer type, but avoid
1470 a further "fails to be a type name" error. Refuse nested functions
1471 since it is not how the user likely wants us to recover. */
1472 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1473 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1474 c_parser_peek_token (parser
)->value
= error_mark_node
;
1478 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1481 c_parser_skip_to_end_of_block_or_statement (parser
);
1484 if (nested
&& !specs
->declspecs_seen_p
)
1486 c_parser_error (parser
, "expected declaration specifiers");
1487 c_parser_skip_to_end_of_block_or_statement (parser
);
1490 finish_declspecs (specs
);
1491 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1497 shadow_tag_warned (specs
, 1);
1498 pedwarn (here
, 0, "empty declaration");
1500 c_parser_consume_token (parser
);
1504 /* Provide better error recovery. Note that a type name here is usually
1505 better diagnosed as a redeclaration. */
1507 && specs
->typespec_kind
== ctsk_tagdef
1508 && c_parser_next_token_starts_declspecs (parser
)
1509 && !c_parser_next_token_is (parser
, CPP_NAME
))
1511 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1512 parser
->error
= false;
1513 shadow_tag_warned (specs
, 1);
1516 else if (c_dialect_objc ())
1518 /* Prefix attributes are an error on method decls. */
1519 switch (c_parser_peek_token (parser
)->type
)
1523 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1527 warning_at (c_parser_peek_token (parser
)->location
,
1529 "prefix attributes are ignored for methods");
1530 specs
->attrs
= NULL_TREE
;
1533 c_parser_objc_method_definition (parser
);
1535 c_parser_objc_methodproto (parser
);
1541 /* This is where we parse 'attributes @interface ...',
1542 'attributes @implementation ...', 'attributes @protocol ...'
1543 (where attributes could be, for example, __attribute__
1546 switch (c_parser_peek_token (parser
)->keyword
)
1548 case RID_AT_INTERFACE
:
1550 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1552 c_parser_objc_class_definition (parser
, specs
->attrs
);
1556 case RID_AT_IMPLEMENTATION
:
1558 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1562 warning_at (c_parser_peek_token (parser
)->location
,
1564 "prefix attributes are ignored for implementations");
1565 specs
->attrs
= NULL_TREE
;
1567 c_parser_objc_class_definition (parser
, NULL_TREE
);
1571 case RID_AT_PROTOCOL
:
1573 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1575 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1582 case RID_AT_PROPERTY
:
1585 c_parser_error (parser
, "unexpected attribute");
1586 specs
->attrs
= NULL
;
1594 pending_xref_error ();
1595 prefix_attrs
= specs
->attrs
;
1596 all_prefix_attrs
= prefix_attrs
;
1597 specs
->attrs
= NULL_TREE
;
1600 struct c_declarator
*declarator
;
1604 /* Declaring either one or more declarators (in which case we
1605 should diagnose if there were no declaration specifiers) or a
1606 function definition (in which case the diagnostic for
1607 implicit int suffices). */
1608 declarator
= c_parser_declarator (parser
,
1609 specs
->typespec_kind
!= ctsk_none
,
1610 C_DTR_NORMAL
, &dummy
);
1611 if (declarator
== NULL
)
1613 c_parser_skip_to_end_of_block_or_statement (parser
);
1616 if (c_parser_next_token_is (parser
, CPP_EQ
)
1617 || c_parser_next_token_is (parser
, CPP_COMMA
)
1618 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1619 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1620 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1621 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1623 tree asm_name
= NULL_TREE
;
1624 tree postfix_attrs
= NULL_TREE
;
1625 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1627 diagnosed_no_specs
= true;
1628 pedwarn (here
, 0, "data definition has no type or storage class");
1630 /* Having seen a data definition, there cannot now be a
1631 function definition. */
1633 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1634 asm_name
= c_parser_simple_asm_expr (parser
);
1635 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1636 postfix_attrs
= c_parser_attributes (parser
);
1637 if (c_parser_next_token_is (parser
, CPP_EQ
))
1641 location_t init_loc
;
1642 c_parser_consume_token (parser
);
1643 /* The declaration of the variable is in effect while
1644 its initializer is parsed. */
1645 d
= start_decl (declarator
, specs
, true,
1646 chainon (postfix_attrs
, all_prefix_attrs
));
1648 d
= error_mark_node
;
1649 start_init (d
, asm_name
, global_bindings_p ());
1650 init_loc
= c_parser_peek_token (parser
)->location
;
1651 init
= c_parser_initializer (parser
);
1653 if (d
!= error_mark_node
)
1655 maybe_warn_string_init (TREE_TYPE (d
), init
);
1656 finish_decl (d
, init_loc
, init
.value
,
1657 init
.original_type
, asm_name
);
1662 tree d
= start_decl (declarator
, specs
, false,
1663 chainon (postfix_attrs
,
1666 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1667 NULL_TREE
, asm_name
);
1669 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1672 *objc_foreach_object_declaration
= d
;
1674 *objc_foreach_object_declaration
= error_mark_node
;
1677 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1679 c_parser_consume_token (parser
);
1680 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1681 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1684 all_prefix_attrs
= prefix_attrs
;
1687 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1689 c_parser_consume_token (parser
);
1692 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1694 /* This can only happen in Objective-C: we found the
1695 'in' that terminates the declaration inside an
1696 Objective-C foreach statement. Do not consume the
1697 token, so that the caller can use it to determine
1698 that this indeed is a foreach context. */
1703 c_parser_error (parser
, "expected %<,%> or %<;%>");
1704 c_parser_skip_to_end_of_block_or_statement (parser
);
1710 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1711 "%<asm%> or %<__attribute__%>");
1712 c_parser_skip_to_end_of_block_or_statement (parser
);
1715 /* Function definition (nested or otherwise). */
1718 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1719 c_push_function_context ();
1721 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1723 /* This can appear in many cases looking nothing like a
1724 function definition, so we don't give a more specific
1725 error suggesting there was one. */
1726 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1727 "or %<__attribute__%>");
1729 c_pop_function_context ();
1733 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1734 tv
= TV_PARSE_INLINE
;
1739 /* Parse old-style parameter declarations. ??? Attributes are
1740 not allowed to start declaration specifiers here because of a
1741 syntax conflict between a function declaration with attribute
1742 suffix and a function definition with an attribute prefix on
1743 first old-style parameter declaration. Following the old
1744 parser, they are not accepted on subsequent old-style
1745 parameter declarations either. However, there is no
1746 ambiguity after the first declaration, nor indeed on the
1747 first as long as we don't allow postfix attributes after a
1748 declarator with a nonempty identifier list in a definition;
1749 and postfix attributes have never been accepted here in
1750 function definitions either. */
1751 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1752 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1753 c_parser_declaration_or_fndef (parser
, false, false, false,
1755 store_parm_decls ();
1756 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1757 = c_parser_peek_token (parser
)->location
;
1758 fnbody
= c_parser_compound_statement (parser
);
1761 tree decl
= current_function_decl
;
1762 /* Mark nested functions as needing static-chain initially.
1763 lower_nested_functions will recompute it but the
1764 DECL_STATIC_CHAIN flag is also used before that happens,
1765 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1766 DECL_STATIC_CHAIN (decl
) = 1;
1769 c_pop_function_context ();
1770 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1783 /* Parse an asm-definition (asm() outside a function body). This is a
1791 c_parser_asm_definition (c_parser
*parser
)
1793 tree asm_str
= c_parser_simple_asm_expr (parser
);
1795 add_asm_node (asm_str
);
1796 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1799 /* Parse a static assertion (C11 6.7.10).
1801 static_assert-declaration:
1802 static_assert-declaration-no-semi ;
1806 c_parser_static_assert_declaration (c_parser
*parser
)
1808 c_parser_static_assert_declaration_no_semi (parser
);
1810 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1811 c_parser_skip_to_end_of_block_or_statement (parser
);
1814 /* Parse a static assertion (C11 6.7.10), without the trailing
1817 static_assert-declaration-no-semi:
1818 _Static_assert ( constant-expression , string-literal )
1822 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1824 location_t assert_loc
, value_loc
;
1828 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1829 assert_loc
= c_parser_peek_token (parser
)->location
;
1833 pedwarn (assert_loc
, OPT_Wpedantic
,
1834 "ISO C99 does not support %<_Static_assert%>");
1836 pedwarn (assert_loc
, OPT_Wpedantic
,
1837 "ISO C90 does not support %<_Static_assert%>");
1839 c_parser_consume_token (parser
);
1840 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1842 value_loc
= c_parser_peek_token (parser
)->location
;
1843 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1844 parser
->lex_untranslated_string
= true;
1845 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1847 parser
->lex_untranslated_string
= false;
1850 switch (c_parser_peek_token (parser
)->type
)
1856 case CPP_UTF8STRING
:
1857 string
= c_parser_peek_token (parser
)->value
;
1858 c_parser_consume_token (parser
);
1859 parser
->lex_untranslated_string
= false;
1862 c_parser_error (parser
, "expected string literal");
1863 parser
->lex_untranslated_string
= false;
1866 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1868 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1870 error_at (value_loc
, "expression in static assertion is not an integer");
1873 if (TREE_CODE (value
) != INTEGER_CST
)
1875 value
= c_fully_fold (value
, false, NULL
);
1876 if (TREE_CODE (value
) == INTEGER_CST
)
1877 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1878 "is not an integer constant expression");
1880 if (TREE_CODE (value
) != INTEGER_CST
)
1882 error_at (value_loc
, "expression in static assertion is not constant");
1885 constant_expression_warning (value
);
1886 if (integer_zerop (value
))
1887 error_at (assert_loc
, "static assertion failed: %E", string
);
1890 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1891 6.7), adding them to SPECS (which may already include some).
1892 Storage class specifiers are accepted iff SCSPEC_OK; type
1893 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1894 the start iff START_ATTR_OK.
1896 declaration-specifiers:
1897 storage-class-specifier declaration-specifiers[opt]
1898 type-specifier declaration-specifiers[opt]
1899 type-qualifier declaration-specifiers[opt]
1900 function-specifier declaration-specifiers[opt]
1901 alignment-specifier declaration-specifiers[opt]
1903 Function specifiers (inline) are from C99, and are currently
1904 handled as storage class specifiers, as is __thread. Alignment
1905 specifiers are from C11.
1907 C90 6.5.1, C99 6.7.1:
1908 storage-class-specifier:
1920 (_Noreturn is new in C11.)
1922 C90 6.5.2, C99 6.7.2:
1935 [_Imaginary removed in C99 TC2]
1936 struct-or-union-specifier
1940 (_Bool and _Complex are new in C99.)
1942 C90 6.5.3, C99 6.7.3:
1948 address-space-qualifier
1950 (restrict is new in C99.)
1954 declaration-specifiers:
1955 attributes declaration-specifiers[opt]
1961 identifier recognized by the target
1963 storage-class-specifier:
1976 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1977 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1982 class-name objc-protocol-refs[opt]
1983 typedef-name objc-protocol-refs
1988 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1989 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1990 enum c_lookahead_kind la
)
1992 bool attrs_ok
= start_attr_ok
;
1993 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1996 gcc_assert (la
== cla_prefer_id
);
1998 while (c_parser_next_token_is (parser
, CPP_NAME
)
1999 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2000 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2002 struct c_typespec t
;
2005 location_t loc
= c_parser_peek_token (parser
)->location
;
2007 /* If we cannot accept a type, exit if the next token must start
2008 one. Also, if we already have seen a tagged definition,
2009 a typename would be an error anyway and likely the user
2010 has simply forgotten a semicolon, so we exit. */
2011 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2012 && c_parser_next_tokens_start_typename (parser
, la
)
2013 && !c_parser_next_token_is_qualifier (parser
))
2016 if (c_parser_next_token_is (parser
, CPP_NAME
))
2018 c_token
*name_token
= c_parser_peek_token (parser
);
2019 tree value
= name_token
->value
;
2020 c_id_kind kind
= name_token
->id_kind
;
2022 if (kind
== C_ID_ADDRSPACE
)
2025 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2026 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2027 c_parser_consume_token (parser
);
2032 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2034 /* If we cannot accept a type, and the next token must start one,
2035 exit. Do the same if we already have seen a tagged definition,
2036 since it would be an error anyway and likely the user has simply
2037 forgotten a semicolon. */
2038 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2041 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2042 a C_ID_CLASSNAME. */
2043 c_parser_consume_token (parser
);
2046 if (kind
== C_ID_ID
)
2048 error ("unknown type name %qE", value
);
2049 t
.kind
= ctsk_typedef
;
2050 t
.spec
= error_mark_node
;
2052 else if (kind
== C_ID_TYPENAME
2053 && (!c_dialect_objc ()
2054 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2056 t
.kind
= ctsk_typedef
;
2057 /* For a typedef name, record the meaning, not the name.
2058 In case of 'foo foo, bar;'. */
2059 t
.spec
= lookup_name (value
);
2063 tree proto
= NULL_TREE
;
2064 gcc_assert (c_dialect_objc ());
2066 if (c_parser_next_token_is (parser
, CPP_LESS
))
2067 proto
= c_parser_objc_protocol_refs (parser
);
2068 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2071 t
.expr_const_operands
= true;
2072 declspecs_add_type (name_token
->location
, specs
, t
);
2075 if (c_parser_next_token_is (parser
, CPP_LESS
))
2077 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2078 nisse@lysator.liu.se. */
2080 gcc_assert (c_dialect_objc ());
2081 if (!typespec_ok
|| seen_type
)
2083 proto
= c_parser_objc_protocol_refs (parser
);
2085 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2087 t
.expr_const_operands
= true;
2088 declspecs_add_type (loc
, specs
, t
);
2091 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2092 switch (c_parser_peek_token (parser
)->keyword
)
2105 /* TODO: Distinguish between function specifiers (inline, noreturn)
2106 and storage class specifiers, either here or in
2107 declspecs_add_scspec. */
2108 declspecs_add_scspec (loc
, specs
,
2109 c_parser_peek_token (parser
)->value
);
2110 c_parser_consume_token (parser
);
2134 if (c_dialect_objc ())
2135 parser
->objc_need_raw_identifier
= true;
2136 t
.kind
= ctsk_resword
;
2137 t
.spec
= c_parser_peek_token (parser
)->value
;
2139 t
.expr_const_operands
= true;
2140 declspecs_add_type (loc
, specs
, t
);
2141 c_parser_consume_token (parser
);
2148 t
= c_parser_enum_specifier (parser
);
2149 declspecs_add_type (loc
, specs
, t
);
2157 t
= c_parser_struct_or_union_specifier (parser
);
2158 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2159 declspecs_add_type (loc
, specs
, t
);
2162 /* ??? The old parser rejected typeof after other type
2163 specifiers, but is a syntax error the best way of
2165 if (!typespec_ok
|| seen_type
)
2169 t
= c_parser_typeof_specifier (parser
);
2170 declspecs_add_type (loc
, specs
, t
);
2176 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2177 c_parser_consume_token (parser
);
2182 attrs
= c_parser_attributes (parser
);
2183 declspecs_add_attrs (loc
, specs
, attrs
);
2186 align
= c_parser_alignas_specifier (parser
);
2187 declspecs_add_alignas (loc
, specs
, align
);
2196 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2199 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2200 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2201 enum attributes[opt] identifier
2203 The form with trailing comma is new in C99. The forms with
2204 attributes are GNU extensions. In GNU C, we accept any expression
2205 without commas in the syntax (assignment expressions, not just
2206 conditional expressions); assignment expressions will be diagnosed
2211 enumerator-list , enumerator
2214 enumeration-constant
2215 enumeration-constant = constant-expression
2218 static struct c_typespec
2219 c_parser_enum_specifier (c_parser
*parser
)
2221 struct c_typespec ret
;
2223 tree ident
= NULL_TREE
;
2224 location_t enum_loc
;
2225 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2226 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2227 enum_loc
= c_parser_peek_token (parser
)->location
;
2228 c_parser_consume_token (parser
);
2229 attrs
= c_parser_attributes (parser
);
2230 enum_loc
= c_parser_peek_token (parser
)->location
;
2231 /* Set the location in case we create a decl now. */
2232 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2233 if (c_parser_next_token_is (parser
, CPP_NAME
))
2235 ident
= c_parser_peek_token (parser
)->value
;
2236 ident_loc
= c_parser_peek_token (parser
)->location
;
2237 enum_loc
= ident_loc
;
2238 c_parser_consume_token (parser
);
2240 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2242 /* Parse an enum definition. */
2243 struct c_enum_contents the_enum
;
2246 /* We chain the enumerators in reverse order, then put them in
2247 forward order at the end. */
2249 timevar_push (TV_PARSE_ENUM
);
2250 type
= start_enum (enum_loc
, &the_enum
, ident
);
2252 c_parser_consume_token (parser
);
2260 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2261 location_t decl_loc
, value_loc
;
2262 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2264 c_parser_error (parser
, "expected identifier");
2265 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2266 values
= error_mark_node
;
2269 token
= c_parser_peek_token (parser
);
2270 enum_id
= token
->value
;
2271 /* Set the location in case we create a decl now. */
2272 c_parser_set_source_position_from_token (token
);
2273 decl_loc
= value_loc
= token
->location
;
2274 c_parser_consume_token (parser
);
2275 if (c_parser_next_token_is (parser
, CPP_EQ
))
2277 c_parser_consume_token (parser
);
2278 value_loc
= c_parser_peek_token (parser
)->location
;
2279 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2282 enum_value
= NULL_TREE
;
2283 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2284 &the_enum
, enum_id
, enum_value
);
2285 TREE_CHAIN (enum_decl
) = values
;
2288 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2290 comma_loc
= c_parser_peek_token (parser
)->location
;
2292 c_parser_consume_token (parser
);
2294 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2296 if (seen_comma
&& !flag_isoc99
)
2297 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2298 c_parser_consume_token (parser
);
2303 c_parser_error (parser
, "expected %<,%> or %<}%>");
2304 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2305 values
= error_mark_node
;
2309 postfix_attrs
= c_parser_attributes (parser
);
2310 ret
.spec
= finish_enum (type
, nreverse (values
),
2311 chainon (attrs
, postfix_attrs
));
2312 ret
.kind
= ctsk_tagdef
;
2313 ret
.expr
= NULL_TREE
;
2314 ret
.expr_const_operands
= true;
2315 timevar_pop (TV_PARSE_ENUM
);
2320 c_parser_error (parser
, "expected %<{%>");
2321 ret
.spec
= error_mark_node
;
2322 ret
.kind
= ctsk_tagref
;
2323 ret
.expr
= NULL_TREE
;
2324 ret
.expr_const_operands
= true;
2327 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2328 /* In ISO C, enumerated types can be referred to only if already
2330 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2333 pedwarn (enum_loc
, OPT_Wpedantic
,
2334 "ISO C forbids forward references to %<enum%> types");
2339 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2341 struct-or-union-specifier:
2342 struct-or-union attributes[opt] identifier[opt]
2343 { struct-contents } attributes[opt]
2344 struct-or-union attributes[opt] identifier
2347 struct-declaration-list
2349 struct-declaration-list:
2350 struct-declaration ;
2351 struct-declaration-list struct-declaration ;
2358 struct-declaration-list struct-declaration
2360 struct-declaration-list:
2361 struct-declaration-list ;
2364 (Note that in the syntax here, unlike that in ISO C, the semicolons
2365 are included here rather than in struct-declaration, in order to
2366 describe the syntax with extra semicolons and missing semicolon at
2371 struct-declaration-list:
2372 @defs ( class-name )
2374 (Note this does not include a trailing semicolon, but can be
2375 followed by further declarations, and gets a pedwarn-if-pedantic
2376 when followed by a semicolon.) */
2378 static struct c_typespec
2379 c_parser_struct_or_union_specifier (c_parser
*parser
)
2381 struct c_typespec ret
;
2383 tree ident
= NULL_TREE
;
2384 location_t struct_loc
;
2385 location_t ident_loc
= UNKNOWN_LOCATION
;
2386 enum tree_code code
;
2387 switch (c_parser_peek_token (parser
)->keyword
)
2398 struct_loc
= c_parser_peek_token (parser
)->location
;
2399 c_parser_consume_token (parser
);
2400 attrs
= c_parser_attributes (parser
);
2402 /* Set the location in case we create a decl now. */
2403 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2405 if (c_parser_next_token_is (parser
, CPP_NAME
))
2407 ident
= c_parser_peek_token (parser
)->value
;
2408 ident_loc
= c_parser_peek_token (parser
)->location
;
2409 struct_loc
= ident_loc
;
2410 c_parser_consume_token (parser
);
2412 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2414 /* Parse a struct or union definition. Start the scope of the
2415 tag before parsing components. */
2416 struct c_struct_parse_info
*struct_info
;
2417 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2419 /* We chain the components in reverse order, then put them in
2420 forward order at the end. Each struct-declaration may
2421 declare multiple components (comma-separated), so we must use
2422 chainon to join them, although when parsing each
2423 struct-declaration we can use TREE_CHAIN directly.
2425 The theory behind all this is that there will be more
2426 semicolon separated fields than comma separated fields, and
2427 so we'll be minimizing the number of node traversals required
2430 timevar_push (TV_PARSE_STRUCT
);
2431 contents
= NULL_TREE
;
2432 c_parser_consume_token (parser
);
2433 /* Handle the Objective-C @defs construct,
2434 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2435 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2438 gcc_assert (c_dialect_objc ());
2439 c_parser_consume_token (parser
);
2440 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2442 if (c_parser_next_token_is (parser
, CPP_NAME
)
2443 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2445 name
= c_parser_peek_token (parser
)->value
;
2446 c_parser_consume_token (parser
);
2450 c_parser_error (parser
, "expected class name");
2451 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2454 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2456 contents
= nreverse (objc_get_class_ivars (name
));
2459 /* Parse the struct-declarations and semicolons. Problems with
2460 semicolons are diagnosed here; empty structures are diagnosed
2465 /* Parse any stray semicolon. */
2466 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2468 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2469 "extra semicolon in struct or union specified");
2470 c_parser_consume_token (parser
);
2473 /* Stop if at the end of the struct or union contents. */
2474 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2476 c_parser_consume_token (parser
);
2479 /* Accept #pragmas at struct scope. */
2480 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2482 c_parser_pragma (parser
, pragma_external
);
2485 /* Parse some comma-separated declarations, but not the
2486 trailing semicolon if any. */
2487 decls
= c_parser_struct_declaration (parser
);
2488 contents
= chainon (decls
, contents
);
2489 /* If no semicolon follows, either we have a parse error or
2490 are at the end of the struct or union and should
2492 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2493 c_parser_consume_token (parser
);
2496 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2497 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2498 "no semicolon at end of struct or union");
2499 else if (parser
->error
2500 || !c_parser_next_token_starts_declspecs (parser
))
2502 c_parser_error (parser
, "expected %<;%>");
2503 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2507 /* If we come here, we have already emitted an error
2508 for an expected `;', identifier or `(', and we also
2509 recovered already. Go on with the next field. */
2512 postfix_attrs
= c_parser_attributes (parser
);
2513 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2514 chainon (attrs
, postfix_attrs
), struct_info
);
2515 ret
.kind
= ctsk_tagdef
;
2516 ret
.expr
= NULL_TREE
;
2517 ret
.expr_const_operands
= true;
2518 timevar_pop (TV_PARSE_STRUCT
);
2523 c_parser_error (parser
, "expected %<{%>");
2524 ret
.spec
= error_mark_node
;
2525 ret
.kind
= ctsk_tagref
;
2526 ret
.expr
= NULL_TREE
;
2527 ret
.expr_const_operands
= true;
2530 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2534 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2535 the trailing semicolon.
2538 specifier-qualifier-list struct-declarator-list
2539 static_assert-declaration-no-semi
2541 specifier-qualifier-list:
2542 type-specifier specifier-qualifier-list[opt]
2543 type-qualifier specifier-qualifier-list[opt]
2544 attributes specifier-qualifier-list[opt]
2546 struct-declarator-list:
2548 struct-declarator-list , attributes[opt] struct-declarator
2551 declarator attributes[opt]
2552 declarator[opt] : constant-expression attributes[opt]
2557 __extension__ struct-declaration
2558 specifier-qualifier-list
2560 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2561 of attributes where shown is a GNU extension. In GNU C, we accept
2562 any expression without commas in the syntax (assignment
2563 expressions, not just conditional expressions); assignment
2564 expressions will be diagnosed as non-constant. */
2567 c_parser_struct_declaration (c_parser
*parser
)
2569 struct c_declspecs
*specs
;
2571 tree all_prefix_attrs
;
2573 location_t decl_loc
;
2574 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2578 ext
= disable_extension_diagnostics ();
2579 c_parser_consume_token (parser
);
2580 decl
= c_parser_struct_declaration (parser
);
2581 restore_extension_diagnostics (ext
);
2584 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2586 c_parser_static_assert_declaration_no_semi (parser
);
2589 specs
= build_null_declspecs ();
2590 decl_loc
= c_parser_peek_token (parser
)->location
;
2591 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2594 if (!specs
->declspecs_seen_p
)
2596 c_parser_error (parser
, "expected specifier-qualifier-list");
2599 finish_declspecs (specs
);
2600 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2601 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2604 if (specs
->typespec_kind
== ctsk_none
)
2606 pedwarn (decl_loc
, OPT_Wpedantic
,
2607 "ISO C forbids member declarations with no members");
2608 shadow_tag_warned (specs
, pedantic
);
2613 /* Support for unnamed structs or unions as members of
2614 structs or unions (which is [a] useful and [b] supports
2618 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2619 build_id_declarator (NULL_TREE
), specs
,
2622 decl_attributes (&ret
, attrs
, 0);
2627 /* Provide better error recovery. Note that a type name here is valid,
2628 and will be treated as a field name. */
2629 if (specs
->typespec_kind
== ctsk_tagdef
2630 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2631 && c_parser_next_token_starts_declspecs (parser
)
2632 && !c_parser_next_token_is (parser
, CPP_NAME
))
2634 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2635 parser
->error
= false;
2639 pending_xref_error ();
2640 prefix_attrs
= specs
->attrs
;
2641 all_prefix_attrs
= prefix_attrs
;
2642 specs
->attrs
= NULL_TREE
;
2646 /* Declaring one or more declarators or un-named bit-fields. */
2647 struct c_declarator
*declarator
;
2649 if (c_parser_next_token_is (parser
, CPP_COLON
))
2650 declarator
= build_id_declarator (NULL_TREE
);
2652 declarator
= c_parser_declarator (parser
,
2653 specs
->typespec_kind
!= ctsk_none
,
2654 C_DTR_NORMAL
, &dummy
);
2655 if (declarator
== NULL
)
2657 c_parser_skip_to_end_of_block_or_statement (parser
);
2660 if (c_parser_next_token_is (parser
, CPP_COLON
)
2661 || c_parser_next_token_is (parser
, CPP_COMMA
)
2662 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2663 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2664 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2666 tree postfix_attrs
= NULL_TREE
;
2667 tree width
= NULL_TREE
;
2669 if (c_parser_next_token_is (parser
, CPP_COLON
))
2671 c_parser_consume_token (parser
);
2672 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2674 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2675 postfix_attrs
= c_parser_attributes (parser
);
2676 d
= grokfield (c_parser_peek_token (parser
)->location
,
2677 declarator
, specs
, width
, &all_prefix_attrs
);
2678 decl_attributes (&d
, chainon (postfix_attrs
,
2679 all_prefix_attrs
), 0);
2680 DECL_CHAIN (d
) = decls
;
2682 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2683 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2686 all_prefix_attrs
= prefix_attrs
;
2687 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2688 c_parser_consume_token (parser
);
2689 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2690 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2692 /* Semicolon consumed in caller. */
2697 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2703 c_parser_error (parser
,
2704 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2705 "%<__attribute__%>");
2712 /* Parse a typeof specifier (a GNU extension).
2715 typeof ( expression )
2716 typeof ( type-name )
2719 static struct c_typespec
2720 c_parser_typeof_specifier (c_parser
*parser
)
2722 struct c_typespec ret
;
2723 ret
.kind
= ctsk_typeof
;
2724 ret
.spec
= error_mark_node
;
2725 ret
.expr
= NULL_TREE
;
2726 ret
.expr_const_operands
= true;
2727 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2728 c_parser_consume_token (parser
);
2729 c_inhibit_evaluation_warnings
++;
2731 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2733 c_inhibit_evaluation_warnings
--;
2737 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2739 struct c_type_name
*type
= c_parser_type_name (parser
);
2740 c_inhibit_evaluation_warnings
--;
2744 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2745 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2751 location_t here
= c_parser_peek_token (parser
)->location
;
2752 struct c_expr expr
= c_parser_expression (parser
);
2753 c_inhibit_evaluation_warnings
--;
2755 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2756 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2757 error_at (here
, "%<typeof%> applied to a bit-field");
2758 mark_exp_read (expr
.value
);
2759 ret
.spec
= TREE_TYPE (expr
.value
);
2760 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2761 /* This is returned with the type so that when the type is
2762 evaluated, this can be evaluated. */
2764 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2765 pop_maybe_used (was_vm
);
2767 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2771 /* Parse an alignment-specifier.
2775 alignment-specifier:
2776 _Alignas ( type-name )
2777 _Alignas ( constant-expression )
2781 c_parser_alignas_specifier (c_parser
* parser
)
2783 tree ret
= error_mark_node
;
2784 location_t loc
= c_parser_peek_token (parser
)->location
;
2785 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2786 c_parser_consume_token (parser
);
2790 pedwarn (loc
, OPT_Wpedantic
,
2791 "ISO C99 does not support %<_Alignas%>");
2793 pedwarn (loc
, OPT_Wpedantic
,
2794 "ISO C90 does not support %<_Alignas%>");
2796 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2798 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2800 struct c_type_name
*type
= c_parser_type_name (parser
);
2802 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2805 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2806 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2810 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2811 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2812 be redeclared; otherwise it may not. KIND indicates which kind of
2813 declarator is wanted. Returns a valid declarator except in the
2814 case of a syntax error in which case NULL is returned. *SEEN_ID is
2815 set to true if an identifier being declared is seen; this is used
2816 to diagnose bad forms of abstract array declarators and to
2817 determine whether an identifier list is syntactically permitted.
2820 pointer[opt] direct-declarator
2824 ( attributes[opt] declarator )
2825 direct-declarator array-declarator
2826 direct-declarator ( parameter-type-list )
2827 direct-declarator ( identifier-list[opt] )
2830 * type-qualifier-list[opt]
2831 * type-qualifier-list[opt] pointer
2833 type-qualifier-list:
2836 type-qualifier-list type-qualifier
2837 type-qualifier-list attributes
2839 parameter-type-list:
2841 parameter-list , ...
2844 parameter-declaration
2845 parameter-list , parameter-declaration
2847 parameter-declaration:
2848 declaration-specifiers declarator attributes[opt]
2849 declaration-specifiers abstract-declarator[opt] attributes[opt]
2853 identifier-list , identifier
2855 abstract-declarator:
2857 pointer[opt] direct-abstract-declarator
2859 direct-abstract-declarator:
2860 ( attributes[opt] abstract-declarator )
2861 direct-abstract-declarator[opt] array-declarator
2862 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2867 direct-declarator ( parameter-forward-declarations
2868 parameter-type-list[opt] )
2870 direct-abstract-declarator:
2871 direct-abstract-declarator[opt] ( parameter-forward-declarations
2872 parameter-type-list[opt] )
2874 parameter-forward-declarations:
2876 parameter-forward-declarations parameter-list ;
2878 The uses of attributes shown above are GNU extensions.
2880 Some forms of array declarator are not included in C99 in the
2881 syntax for abstract declarators; these are disallowed elsewhere.
2882 This may be a defect (DR#289).
2884 This function also accepts an omitted abstract declarator as being
2885 an abstract declarator, although not part of the formal syntax. */
2887 static struct c_declarator
*
2888 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2891 /* Parse any initial pointer part. */
2892 if (c_parser_next_token_is (parser
, CPP_MULT
))
2894 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2895 struct c_declarator
*inner
;
2896 c_parser_consume_token (parser
);
2897 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2898 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2902 return make_pointer_declarator (quals_attrs
, inner
);
2904 /* Now we have a direct declarator, direct abstract declarator or
2905 nothing (which counts as a direct abstract declarator here). */
2906 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2909 /* Parse a direct declarator or direct abstract declarator; arguments
2910 as c_parser_declarator. */
2912 static struct c_declarator
*
2913 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2916 /* The direct declarator must start with an identifier (possibly
2917 omitted) or a parenthesized declarator (possibly abstract). In
2918 an ordinary declarator, initial parentheses must start a
2919 parenthesized declarator. In an abstract declarator or parameter
2920 declarator, they could start a parenthesized declarator or a
2921 parameter list. To tell which, the open parenthesis and any
2922 following attributes must be read. If a declaration specifier
2923 follows, then it is a parameter list; if the specifier is a
2924 typedef name, there might be an ambiguity about redeclaring it,
2925 which is resolved in the direction of treating it as a typedef
2926 name. If a close parenthesis follows, it is also an empty
2927 parameter list, as the syntax does not permit empty abstract
2928 declarators. Otherwise, it is a parenthesized declarator (in
2929 which case the analysis may be repeated inside it, recursively).
2931 ??? There is an ambiguity in a parameter declaration "int
2932 (__attribute__((foo)) x)", where x is not a typedef name: it
2933 could be an abstract declarator for a function, or declare x with
2934 parentheses. The proper resolution of this ambiguity needs
2935 documenting. At present we follow an accident of the old
2936 parser's implementation, whereby the first parameter must have
2937 some declaration specifiers other than just attributes. Thus as
2938 a parameter declaration it is treated as a parenthesized
2939 parameter named x, and as an abstract declarator it is
2942 ??? Also following the old parser, attributes inside an empty
2943 parameter list are ignored, making it a list not yielding a
2944 prototype, rather than giving an error or making it have one
2945 parameter with implicit type int.
2947 ??? Also following the old parser, typedef names may be
2948 redeclared in declarators, but not Objective-C class names. */
2950 if (kind
!= C_DTR_ABSTRACT
2951 && c_parser_next_token_is (parser
, CPP_NAME
)
2953 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2954 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2955 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2957 struct c_declarator
*inner
2958 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2960 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2961 c_parser_consume_token (parser
);
2962 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2965 if (kind
!= C_DTR_NORMAL
2966 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2968 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2969 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2972 /* Either we are at the end of an abstract declarator, or we have
2975 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2978 struct c_declarator
*inner
;
2979 c_parser_consume_token (parser
);
2980 attrs
= c_parser_attributes (parser
);
2981 if (kind
!= C_DTR_NORMAL
2982 && (c_parser_next_token_starts_declspecs (parser
)
2983 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2985 struct c_arg_info
*args
2986 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2993 = build_function_declarator (args
,
2994 build_id_declarator (NULL_TREE
));
2995 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2999 /* A parenthesized declarator. */
3000 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3001 if (inner
!= NULL
&& attrs
!= NULL
)
3002 inner
= build_attrs_declarator (attrs
, inner
);
3003 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3005 c_parser_consume_token (parser
);
3009 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3013 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3020 if (kind
== C_DTR_NORMAL
)
3022 c_parser_error (parser
, "expected identifier or %<(%>");
3026 return build_id_declarator (NULL_TREE
);
3030 /* Parse part of a direct declarator or direct abstract declarator,
3031 given that some (in INNER) has already been parsed; ID_PRESENT is
3032 true if an identifier is present, false for an abstract
3035 static struct c_declarator
*
3036 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3037 struct c_declarator
*inner
)
3039 /* Parse a sequence of array declarators and parameter lists. */
3040 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3042 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3043 struct c_declarator
*declarator
;
3044 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3048 c_parser_consume_token (parser
);
3049 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3050 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3052 c_parser_consume_token (parser
);
3053 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3054 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3055 if (!quals_attrs
->declspecs_seen_p
)
3057 /* If "static" is present, there must be an array dimension.
3058 Otherwise, there may be a dimension, "*", or no
3063 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3067 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3072 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3074 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3078 c_parser_consume_token (parser
);
3083 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3089 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3092 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3093 c_parser_consume_token (parser
);
3096 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3101 mark_exp_read (dimen
);
3102 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3103 static_seen
, star_seen
);
3104 if (declarator
== NULL
)
3106 inner
= set_array_declarator_inner (declarator
, inner
);
3107 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3109 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3112 struct c_arg_info
*args
;
3113 c_parser_consume_token (parser
);
3114 attrs
= c_parser_attributes (parser
);
3115 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3120 inner
= build_function_declarator (args
, inner
);
3121 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3127 /* Parse a parameter list or identifier list, including the closing
3128 parenthesis but not the opening one. ATTRS are the attributes at
3129 the start of the list. ID_LIST_OK is true if an identifier list is
3130 acceptable; such a list must not have attributes at the start. */
3132 static struct c_arg_info
*
3133 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3136 declare_parm_level ();
3137 /* If the list starts with an identifier, it is an identifier list.
3138 Otherwise, it is either a prototype list or an empty list. */
3141 && c_parser_next_token_is (parser
, CPP_NAME
)
3142 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3144 /* Look ahead to detect typos in type names. */
3145 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3146 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3147 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3148 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3150 tree list
= NULL_TREE
, *nextp
= &list
;
3151 while (c_parser_next_token_is (parser
, CPP_NAME
)
3152 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3154 *nextp
= build_tree_list (NULL_TREE
,
3155 c_parser_peek_token (parser
)->value
);
3156 nextp
= & TREE_CHAIN (*nextp
);
3157 c_parser_consume_token (parser
);
3158 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3160 c_parser_consume_token (parser
);
3161 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3163 c_parser_error (parser
, "expected identifier");
3167 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3169 struct c_arg_info
*ret
= build_arg_info ();
3171 c_parser_consume_token (parser
);
3177 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3185 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3192 /* Parse a parameter list (possibly empty), including the closing
3193 parenthesis but not the opening one. ATTRS are the attributes at
3194 the start of the list. EXPR is NULL or an expression that needs to
3195 be evaluated for the side effects of array size expressions in the
3198 static struct c_arg_info
*
3199 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3201 bool bad_parm
= false;
3203 /* ??? Following the old parser, forward parameter declarations may
3204 use abstract declarators, and if no real parameter declarations
3205 follow the forward declarations then this is not diagnosed. Also
3206 note as above that attributes are ignored as the only contents of
3207 the parentheses, or as the only contents after forward
3209 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3211 struct c_arg_info
*ret
= build_arg_info ();
3212 c_parser_consume_token (parser
);
3215 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3217 struct c_arg_info
*ret
= build_arg_info ();
3219 if (flag_allow_parameterless_variadic_functions
)
3221 /* F (...) is allowed. */
3222 ret
->types
= NULL_TREE
;
3226 /* Suppress -Wold-style-definition for this case. */
3227 ret
->types
= error_mark_node
;
3228 error_at (c_parser_peek_token (parser
)->location
,
3229 "ISO C requires a named argument before %<...%>");
3231 c_parser_consume_token (parser
);
3232 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3234 c_parser_consume_token (parser
);
3239 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3244 /* Nonempty list of parameters, either terminated with semicolon
3245 (forward declarations; recurse) or with close parenthesis (normal
3246 function) or with ", ... )" (variadic function). */
3249 /* Parse a parameter. */
3250 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3255 push_parm_decl (parm
, &expr
);
3256 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3259 c_parser_consume_token (parser
);
3260 mark_forward_parm_decls ();
3261 new_attrs
= c_parser_attributes (parser
);
3262 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3264 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3266 c_parser_consume_token (parser
);
3270 return get_parm_info (false, expr
);
3272 if (!c_parser_require (parser
, CPP_COMMA
,
3273 "expected %<;%>, %<,%> or %<)%>"))
3275 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3278 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3280 c_parser_consume_token (parser
);
3281 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3283 c_parser_consume_token (parser
);
3287 return get_parm_info (true, expr
);
3291 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3299 /* Parse a parameter declaration. ATTRS are the attributes at the
3300 start of the declaration if it is the first parameter. */
3302 static struct c_parm
*
3303 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3305 struct c_declspecs
*specs
;
3306 struct c_declarator
*declarator
;
3308 tree postfix_attrs
= NULL_TREE
;
3311 /* Accept #pragmas between parameter declarations. */
3312 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3313 c_parser_pragma (parser
, pragma_external
);
3315 if (!c_parser_next_token_starts_declspecs (parser
))
3317 c_token
*token
= c_parser_peek_token (parser
);
3320 c_parser_set_source_position_from_token (token
);
3321 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3323 error ("unknown type name %qE", token
->value
);
3324 parser
->error
= true;
3326 /* ??? In some Objective-C cases '...' isn't applicable so there
3327 should be a different message. */
3329 c_parser_error (parser
,
3330 "expected declaration specifiers or %<...%>");
3331 c_parser_skip_to_end_of_parameter (parser
);
3334 specs
= build_null_declspecs ();
3337 declspecs_add_attrs (input_location
, specs
, attrs
);
3340 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3341 finish_declspecs (specs
);
3342 pending_xref_error ();
3343 prefix_attrs
= specs
->attrs
;
3344 specs
->attrs
= NULL_TREE
;
3345 declarator
= c_parser_declarator (parser
,
3346 specs
->typespec_kind
!= ctsk_none
,
3347 C_DTR_PARM
, &dummy
);
3348 if (declarator
== NULL
)
3350 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3353 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3354 postfix_attrs
= c_parser_attributes (parser
);
3355 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3359 /* Parse a string literal in an asm expression. It should not be
3360 translated, and wide string literals are an error although
3361 permitted by the syntax. This is a GNU extension.
3366 ??? At present, following the old parser, the caller needs to have
3367 set lex_untranslated_string to 1. It would be better to follow the
3368 C++ parser rather than using this kludge. */
3371 c_parser_asm_string_literal (c_parser
*parser
)
3374 int save_flag
= warn_overlength_strings
;
3375 warn_overlength_strings
= 0;
3376 if (c_parser_next_token_is (parser
, CPP_STRING
))
3378 str
= c_parser_peek_token (parser
)->value
;
3379 c_parser_consume_token (parser
);
3381 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3383 error_at (c_parser_peek_token (parser
)->location
,
3384 "wide string literal in %<asm%>");
3385 str
= build_string (1, "");
3386 c_parser_consume_token (parser
);
3390 c_parser_error (parser
, "expected string literal");
3393 warn_overlength_strings
= save_flag
;
3397 /* Parse a simple asm expression. This is used in restricted
3398 contexts, where a full expression with inputs and outputs does not
3399 make sense. This is a GNU extension.
3402 asm ( asm-string-literal )
3406 c_parser_simple_asm_expr (c_parser
*parser
)
3409 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3410 /* ??? Follow the C++ parser rather than using the
3411 lex_untranslated_string kludge. */
3412 parser
->lex_untranslated_string
= true;
3413 c_parser_consume_token (parser
);
3414 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3416 parser
->lex_untranslated_string
= false;
3419 str
= c_parser_asm_string_literal (parser
);
3420 parser
->lex_untranslated_string
= false;
3421 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3423 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3430 c_parser_attribute_any_word (c_parser
*parser
)
3432 tree attr_name
= NULL_TREE
;
3434 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3436 /* ??? See comment above about what keywords are accepted here. */
3438 switch (c_parser_peek_token (parser
)->keyword
)
3469 case RID_TRANSACTION_ATOMIC
:
3470 case RID_TRANSACTION_CANCEL
:
3480 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3481 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3483 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3484 attr_name
= c_parser_peek_token (parser
)->value
;
3489 /* Parse (possibly empty) attributes. This is a GNU extension.
3493 attributes attribute
3496 __attribute__ ( ( attribute-list ) )
3500 attribute_list , attrib
3505 any-word ( identifier )
3506 any-word ( identifier , nonempty-expr-list )
3507 any-word ( expr-list )
3509 where the "identifier" must not be declared as a type, and
3510 "any-word" may be any identifier (including one declared as a
3511 type), a reserved word storage class specifier, type specifier or
3512 type qualifier. ??? This still leaves out most reserved keywords
3513 (following the old parser), shouldn't we include them, and why not
3514 allow identifiers declared as types to start the arguments? */
3517 c_parser_attributes (c_parser
*parser
)
3519 tree attrs
= NULL_TREE
;
3520 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3522 /* ??? Follow the C++ parser rather than using the
3523 lex_untranslated_string kludge. */
3524 parser
->lex_untranslated_string
= true;
3525 c_parser_consume_token (parser
);
3526 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3528 parser
->lex_untranslated_string
= false;
3531 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3533 parser
->lex_untranslated_string
= false;
3534 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3537 /* Parse the attribute list. */
3538 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3539 || c_parser_next_token_is (parser
, CPP_NAME
)
3540 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3542 tree attr
, attr_name
, attr_args
;
3543 VEC(tree
,gc
) *expr_list
;
3544 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3546 c_parser_consume_token (parser
);
3550 attr_name
= c_parser_attribute_any_word (parser
);
3551 if (attr_name
== NULL
)
3553 c_parser_consume_token (parser
);
3554 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3556 attr
= build_tree_list (attr_name
, NULL_TREE
);
3557 attrs
= chainon (attrs
, attr
);
3560 c_parser_consume_token (parser
);
3561 /* Parse the attribute contents. If they start with an
3562 identifier which is followed by a comma or close
3563 parenthesis, then the arguments start with that
3564 identifier; otherwise they are an expression list.
3565 In objective-c the identifier may be a classname. */
3566 if (c_parser_next_token_is (parser
, CPP_NAME
)
3567 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3568 || (c_dialect_objc ()
3569 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3570 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3571 || (c_parser_peek_2nd_token (parser
)->type
3572 == CPP_CLOSE_PAREN
)))
3574 tree arg1
= c_parser_peek_token (parser
)->value
;
3575 c_parser_consume_token (parser
);
3576 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3577 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3581 c_parser_consume_token (parser
);
3582 expr_list
= c_parser_expr_list (parser
, false, true,
3584 tree_list
= build_tree_list_vec (expr_list
);
3585 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3586 release_tree_vector (expr_list
);
3591 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3592 attr_args
= NULL_TREE
;
3595 expr_list
= c_parser_expr_list (parser
, false, true,
3597 attr_args
= build_tree_list_vec (expr_list
);
3598 release_tree_vector (expr_list
);
3601 attr
= build_tree_list (attr_name
, attr_args
);
3602 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3603 c_parser_consume_token (parser
);
3606 parser
->lex_untranslated_string
= false;
3607 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3611 attrs
= chainon (attrs
, attr
);
3613 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3614 c_parser_consume_token (parser
);
3617 parser
->lex_untranslated_string
= false;
3618 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3622 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3623 c_parser_consume_token (parser
);
3626 parser
->lex_untranslated_string
= false;
3627 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3631 parser
->lex_untranslated_string
= false;
3636 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3639 specifier-qualifier-list abstract-declarator[opt]
3642 static struct c_type_name
*
3643 c_parser_type_name (c_parser
*parser
)
3645 struct c_declspecs
*specs
= build_null_declspecs ();
3646 struct c_declarator
*declarator
;
3647 struct c_type_name
*ret
;
3649 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3650 if (!specs
->declspecs_seen_p
)
3652 c_parser_error (parser
, "expected specifier-qualifier-list");
3655 if (specs
->type
!= error_mark_node
)
3657 pending_xref_error ();
3658 finish_declspecs (specs
);
3660 declarator
= c_parser_declarator (parser
,
3661 specs
->typespec_kind
!= ctsk_none
,
3662 C_DTR_ABSTRACT
, &dummy
);
3663 if (declarator
== NULL
)
3665 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3667 ret
->declarator
= declarator
;
3671 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3674 assignment-expression
3675 { initializer-list }
3676 { initializer-list , }
3679 designation[opt] initializer
3680 initializer-list , designation[opt] initializer
3687 designator-list designator
3694 [ constant-expression ]
3706 [ constant-expression ... constant-expression ]
3708 Any expression without commas is accepted in the syntax for the
3709 constant-expressions, with non-constant expressions rejected later.
3711 This function is only used for top-level initializers; for nested
3712 ones, see c_parser_initval. */
3714 static struct c_expr
3715 c_parser_initializer (c_parser
*parser
)
3717 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3718 return c_parser_braced_init (parser
, NULL_TREE
, false);
3722 location_t loc
= c_parser_peek_token (parser
)->location
;
3723 ret
= c_parser_expr_no_commas (parser
, NULL
);
3724 if (TREE_CODE (ret
.value
) != STRING_CST
3725 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3726 ret
= default_function_array_read_conversion (loc
, ret
);
3731 /* Parse a braced initializer list. TYPE is the type specified for a
3732 compound literal, and NULL_TREE for other initializers and for
3733 nested braced lists. NESTED_P is true for nested braced lists,
3734 false for the list of a compound literal or the list that is the
3735 top-level initializer in a declaration. */
3737 static struct c_expr
3738 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3741 struct obstack braced_init_obstack
;
3742 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3743 gcc_obstack_init (&braced_init_obstack
);
3744 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3745 c_parser_consume_token (parser
);
3747 push_init_level (0, &braced_init_obstack
);
3749 really_start_incremental_init (type
);
3750 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3752 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3756 /* Parse a non-empty initializer list, possibly with a trailing
3760 c_parser_initelt (parser
, &braced_init_obstack
);
3763 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3764 c_parser_consume_token (parser
);
3767 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3771 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3773 ret
.value
= error_mark_node
;
3774 ret
.original_code
= ERROR_MARK
;
3775 ret
.original_type
= NULL
;
3776 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3777 pop_init_level (0, &braced_init_obstack
);
3778 obstack_free (&braced_init_obstack
, NULL
);
3781 c_parser_consume_token (parser
);
3782 ret
= pop_init_level (0, &braced_init_obstack
);
3783 obstack_free (&braced_init_obstack
, NULL
);
3787 /* Parse a nested initializer, including designators. */
3790 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3792 /* Parse any designator or designator list. A single array
3793 designator may have the subsequent "=" omitted in GNU C, but a
3794 longer list or a structure member designator may not. */
3795 if (c_parser_next_token_is (parser
, CPP_NAME
)
3796 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3798 /* Old-style structure member designator. */
3799 set_init_label (c_parser_peek_token (parser
)->value
,
3800 braced_init_obstack
);
3801 /* Use the colon as the error location. */
3802 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3803 "obsolete use of designated initializer with %<:%>");
3804 c_parser_consume_token (parser
);
3805 c_parser_consume_token (parser
);
3809 /* des_seen is 0 if there have been no designators, 1 if there
3810 has been a single array designator and 2 otherwise. */
3812 /* Location of a designator. */
3813 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3814 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3815 || c_parser_next_token_is (parser
, CPP_DOT
))
3817 int des_prev
= des_seen
;
3819 des_loc
= c_parser_peek_token (parser
)->location
;
3822 if (c_parser_next_token_is (parser
, CPP_DOT
))
3825 c_parser_consume_token (parser
);
3826 if (c_parser_next_token_is (parser
, CPP_NAME
))
3828 set_init_label (c_parser_peek_token (parser
)->value
,
3829 braced_init_obstack
);
3830 c_parser_consume_token (parser
);
3835 init
.value
= error_mark_node
;
3836 init
.original_code
= ERROR_MARK
;
3837 init
.original_type
= NULL
;
3838 c_parser_error (parser
, "expected identifier");
3839 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3840 process_init_element (init
, false, braced_init_obstack
);
3847 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3848 /* ??? Following the old parser, [ objc-receiver
3849 objc-message-args ] is accepted as an initializer,
3850 being distinguished from a designator by what follows
3851 the first assignment expression inside the square
3852 brackets, but after a first array designator a
3853 subsequent square bracket is for Objective-C taken to
3854 start an expression, using the obsolete form of
3855 designated initializer without '=', rather than
3856 possibly being a second level of designation: in LALR
3857 terms, the '[' is shifted rather than reducing
3858 designator to designator-list. */
3859 if (des_prev
== 1 && c_dialect_objc ())
3861 des_seen
= des_prev
;
3864 if (des_prev
== 0 && c_dialect_objc ())
3866 /* This might be an array designator or an
3867 Objective-C message expression. If the former,
3868 continue parsing here; if the latter, parse the
3869 remainder of the initializer given the starting
3870 primary-expression. ??? It might make sense to
3871 distinguish when des_prev == 1 as well; see
3872 previous comment. */
3874 struct c_expr mexpr
;
3875 c_parser_consume_token (parser
);
3876 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3877 && ((c_parser_peek_token (parser
)->id_kind
3879 || (c_parser_peek_token (parser
)->id_kind
3880 == C_ID_CLASSNAME
)))
3882 /* Type name receiver. */
3883 tree id
= c_parser_peek_token (parser
)->value
;
3884 c_parser_consume_token (parser
);
3885 rec
= objc_get_class_reference (id
);
3886 goto parse_message_args
;
3888 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3889 mark_exp_read (first
);
3890 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3891 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3892 goto array_desig_after_first
;
3893 /* Expression receiver. So far only one part
3894 without commas has been parsed; there might be
3895 more of the expression. */
3897 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3900 location_t comma_loc
, exp_loc
;
3901 comma_loc
= c_parser_peek_token (parser
)->location
;
3902 c_parser_consume_token (parser
);
3903 exp_loc
= c_parser_peek_token (parser
)->location
;
3904 next
= c_parser_expr_no_commas (parser
, NULL
);
3905 next
= default_function_array_read_conversion (exp_loc
,
3907 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3910 /* Now parse the objc-message-args. */
3911 args
= c_parser_objc_message_args (parser
);
3912 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3915 = objc_build_message_expr (rec
, args
);
3916 mexpr
.original_code
= ERROR_MARK
;
3917 mexpr
.original_type
= NULL
;
3918 /* Now parse and process the remainder of the
3919 initializer, starting with this message
3920 expression as a primary-expression. */
3921 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3924 c_parser_consume_token (parser
);
3925 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3926 mark_exp_read (first
);
3927 array_desig_after_first
:
3928 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3930 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3931 c_parser_consume_token (parser
);
3932 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3933 mark_exp_read (second
);
3937 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3939 c_parser_consume_token (parser
);
3940 set_init_index (first
, second
, braced_init_obstack
);
3942 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
3943 "ISO C forbids specifying range of elements to initialize");
3946 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3952 if (c_parser_next_token_is (parser
, CPP_EQ
))
3955 pedwarn (des_loc
, OPT_Wpedantic
,
3956 "ISO C90 forbids specifying subobject to initialize");
3957 c_parser_consume_token (parser
);
3962 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
3963 "obsolete use of designated initializer without %<=%>");
3967 init
.value
= error_mark_node
;
3968 init
.original_code
= ERROR_MARK
;
3969 init
.original_type
= NULL
;
3970 c_parser_error (parser
, "expected %<=%>");
3971 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3972 process_init_element (init
, false, braced_init_obstack
);
3978 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3981 /* Parse a nested initializer; as c_parser_initializer but parses
3982 initializers within braced lists, after any designators have been
3983 applied. If AFTER is not NULL then it is an Objective-C message
3984 expression which is the primary-expression starting the
3988 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
3989 struct obstack
* braced_init_obstack
)
3992 gcc_assert (!after
|| c_dialect_objc ());
3993 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3994 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3997 location_t loc
= c_parser_peek_token (parser
)->location
;
3998 init
= c_parser_expr_no_commas (parser
, after
);
3999 if (init
.value
!= NULL_TREE
4000 && TREE_CODE (init
.value
) != STRING_CST
4001 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4002 init
= default_function_array_read_conversion (loc
, init
);
4004 process_init_element (init
, false, braced_init_obstack
);
4007 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4011 { block-item-list[opt] }
4012 { label-declarations block-item-list }
4016 block-item-list block-item
4028 { label-declarations block-item-list }
4031 __extension__ nested-declaration
4032 nested-function-definition
4036 label-declarations label-declaration
4039 __label__ identifier-list ;
4041 Allowing the mixing of declarations and code is new in C99. The
4042 GNU syntax also permits (not shown above) labels at the end of
4043 compound statements, which yield an error. We don't allow labels
4044 on declarations; this might seem like a natural extension, but
4045 there would be a conflict between attributes on the label and
4046 prefix attributes on the declaration. ??? The syntax follows the
4047 old parser in requiring something after label declarations.
4048 Although they are erroneous if the labels declared aren't defined,
4049 is it useful for the syntax to be this way?
4061 c_parser_compound_statement (c_parser
*parser
)
4064 location_t brace_loc
;
4065 brace_loc
= c_parser_peek_token (parser
)->location
;
4066 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4068 /* Ensure a scope is entered and left anyway to avoid confusion
4069 if we have just prepared to enter a function body. */
4070 stmt
= c_begin_compound_stmt (true);
4071 c_end_compound_stmt (brace_loc
, stmt
, true);
4072 return error_mark_node
;
4074 stmt
= c_begin_compound_stmt (true);
4075 c_parser_compound_statement_nostart (parser
);
4076 return c_end_compound_stmt (brace_loc
, stmt
, true);
4079 /* Parse a compound statement except for the opening brace. This is
4080 used for parsing both compound statements and statement expressions
4081 (which follow different paths to handling the opening). */
4084 c_parser_compound_statement_nostart (c_parser
*parser
)
4086 bool last_stmt
= false;
4087 bool last_label
= false;
4088 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4089 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4090 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4092 c_parser_consume_token (parser
);
4095 mark_valid_location_for_stdc_pragma (true);
4096 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4098 /* Read zero or more forward-declarations for labels that nested
4099 functions can jump to. */
4100 mark_valid_location_for_stdc_pragma (false);
4101 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4103 label_loc
= c_parser_peek_token (parser
)->location
;
4104 c_parser_consume_token (parser
);
4105 /* Any identifiers, including those declared as type names,
4110 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4112 c_parser_error (parser
, "expected identifier");
4116 = declare_label (c_parser_peek_token (parser
)->value
);
4117 C_DECLARED_LABEL_FLAG (label
) = 1;
4118 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4119 c_parser_consume_token (parser
);
4120 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4121 c_parser_consume_token (parser
);
4125 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4127 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4129 /* We must now have at least one statement, label or declaration. */
4130 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4132 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4133 c_parser_error (parser
, "expected declaration or statement");
4134 c_parser_consume_token (parser
);
4137 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4139 location_t loc
= c_parser_peek_token (parser
)->location
;
4140 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4141 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4142 || (c_parser_next_token_is (parser
, CPP_NAME
)
4143 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4145 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4146 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4148 label_loc
= c_parser_peek_token (parser
)->location
;
4151 mark_valid_location_for_stdc_pragma (false);
4152 c_parser_label (parser
);
4154 else if (!last_label
4155 && c_parser_next_tokens_start_declaration (parser
))
4158 mark_valid_location_for_stdc_pragma (false);
4159 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4162 (pedantic
&& !flag_isoc99
)
4164 : OPT_Wdeclaration_after_statement
,
4165 "ISO C90 forbids mixed declarations and code");
4168 else if (!last_label
4169 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4171 /* __extension__ can start a declaration, but is also an
4172 unary operator that can start an expression. Consume all
4173 but the last of a possible series of __extension__ to
4175 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4176 && (c_parser_peek_2nd_token (parser
)->keyword
4178 c_parser_consume_token (parser
);
4179 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4182 ext
= disable_extension_diagnostics ();
4183 c_parser_consume_token (parser
);
4185 mark_valid_location_for_stdc_pragma (false);
4186 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4188 /* Following the old parser, __extension__ does not
4189 disable this diagnostic. */
4190 restore_extension_diagnostics (ext
);
4192 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4194 : OPT_Wdeclaration_after_statement
,
4195 "ISO C90 forbids mixed declarations and code");
4201 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4203 /* External pragmas, and some omp pragmas, are not associated
4204 with regular c code, and so are not to be considered statements
4205 syntactically. This ensures that the user doesn't put them
4206 places that would turn into syntax errors if the directive
4208 if (c_parser_pragma (parser
, pragma_compound
))
4209 last_label
= false, last_stmt
= true;
4211 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4213 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4214 c_parser_error (parser
, "expected declaration or statement");
4217 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4219 if (parser
->in_if_block
)
4221 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4222 error_at (loc
, """expected %<}%> before %<else%>");
4227 error_at (loc
, "%<else%> without a previous %<if%>");
4228 c_parser_consume_token (parser
);
4237 mark_valid_location_for_stdc_pragma (false);
4238 c_parser_statement_after_labels (parser
);
4241 parser
->error
= false;
4244 error_at (label_loc
, "label at end of compound statement");
4245 c_parser_consume_token (parser
);
4246 /* Restore the value we started with. */
4247 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4250 /* Parse a label (C90 6.6.1, C99 6.8.1).
4253 identifier : attributes[opt]
4254 case constant-expression :
4260 case constant-expression ... constant-expression :
4262 The use of attributes on labels is a GNU extension. The syntax in
4263 GNU C accepts any expressions without commas, non-constant
4264 expressions being rejected later. */
4267 c_parser_label (c_parser
*parser
)
4269 location_t loc1
= c_parser_peek_token (parser
)->location
;
4270 tree label
= NULL_TREE
;
4271 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4274 c_parser_consume_token (parser
);
4275 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4276 if (c_parser_next_token_is (parser
, CPP_COLON
))
4278 c_parser_consume_token (parser
);
4279 label
= do_case (loc1
, exp1
, NULL_TREE
);
4281 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4283 c_parser_consume_token (parser
);
4284 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4285 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4286 label
= do_case (loc1
, exp1
, exp2
);
4289 c_parser_error (parser
, "expected %<:%> or %<...%>");
4291 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4293 c_parser_consume_token (parser
);
4294 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4295 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4299 tree name
= c_parser_peek_token (parser
)->value
;
4302 location_t loc2
= c_parser_peek_token (parser
)->location
;
4303 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4304 c_parser_consume_token (parser
);
4305 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4306 c_parser_consume_token (parser
);
4307 attrs
= c_parser_attributes (parser
);
4308 tlab
= define_label (loc2
, name
);
4311 decl_attributes (&tlab
, attrs
, 0);
4312 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4317 if (c_parser_next_tokens_start_declaration (parser
))
4319 error_at (c_parser_peek_token (parser
)->location
,
4320 "a label can only be part of a statement and "
4321 "a declaration is not a statement");
4322 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4323 /*static_assert_ok*/ true,
4324 /*empty_ok*/ true, /*nested*/ true,
4325 /*start_attr_ok*/ true, NULL
);
4330 /* Parse a statement (C90 6.6, C99 6.8).
4335 expression-statement
4343 expression-statement:
4346 selection-statement:
4350 iteration-statement:
4359 return expression[opt] ;
4372 objc-throw-statement
4373 objc-try-catch-statement
4374 objc-synchronized-statement
4376 objc-throw-statement:
4390 parallel-for-construct
4391 parallel-sections-construct
4398 parallel-directive structured-block
4401 for-directive iteration-statement
4404 sections-directive section-scope
4407 single-directive structured-block
4409 parallel-for-construct:
4410 parallel-for-directive iteration-statement
4412 parallel-sections-construct:
4413 parallel-sections-directive section-scope
4416 master-directive structured-block
4419 critical-directive structured-block
4422 atomic-directive expression-statement
4425 ordered-directive structured-block
4427 Transactional Memory:
4430 transaction-statement
4431 transaction-cancel-statement
4435 c_parser_statement (c_parser
*parser
)
4437 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4438 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4439 || (c_parser_next_token_is (parser
, CPP_NAME
)
4440 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4441 c_parser_label (parser
);
4442 c_parser_statement_after_labels (parser
);
4445 /* Parse a statement, other than a labeled statement. */
4448 c_parser_statement_after_labels (c_parser
*parser
)
4450 location_t loc
= c_parser_peek_token (parser
)->location
;
4451 tree stmt
= NULL_TREE
;
4452 bool in_if_block
= parser
->in_if_block
;
4453 parser
->in_if_block
= false;
4454 switch (c_parser_peek_token (parser
)->type
)
4456 case CPP_OPEN_BRACE
:
4457 add_stmt (c_parser_compound_statement (parser
));
4460 switch (c_parser_peek_token (parser
)->keyword
)
4463 c_parser_if_statement (parser
);
4466 c_parser_switch_statement (parser
);
4469 c_parser_while_statement (parser
);
4472 c_parser_do_statement (parser
);
4475 c_parser_for_statement (parser
);
4478 c_parser_consume_token (parser
);
4479 if (c_parser_next_token_is (parser
, CPP_NAME
))
4481 stmt
= c_finish_goto_label (loc
,
4482 c_parser_peek_token (parser
)->value
);
4483 c_parser_consume_token (parser
);
4485 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4489 c_parser_consume_token (parser
);
4490 val
= c_parser_expression (parser
).value
;
4491 mark_exp_read (val
);
4492 stmt
= c_finish_goto_ptr (loc
, val
);
4495 c_parser_error (parser
, "expected identifier or %<*%>");
4496 goto expect_semicolon
;
4498 c_parser_consume_token (parser
);
4499 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4500 goto expect_semicolon
;
4502 c_parser_consume_token (parser
);
4503 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4504 goto expect_semicolon
;
4506 c_parser_consume_token (parser
);
4507 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4509 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4510 c_parser_consume_token (parser
);
4514 struct c_expr expr
= c_parser_expression_conv (parser
);
4515 mark_exp_read (expr
.value
);
4516 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4517 goto expect_semicolon
;
4521 stmt
= c_parser_asm_statement (parser
);
4523 case RID_TRANSACTION_ATOMIC
:
4524 case RID_TRANSACTION_RELAXED
:
4525 stmt
= c_parser_transaction (parser
,
4526 c_parser_peek_token (parser
)->keyword
);
4528 case RID_TRANSACTION_CANCEL
:
4529 stmt
= c_parser_transaction_cancel (parser
);
4530 goto expect_semicolon
;
4532 gcc_assert (c_dialect_objc ());
4533 c_parser_consume_token (parser
);
4534 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4536 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4537 c_parser_consume_token (parser
);
4541 tree expr
= c_parser_expression (parser
).value
;
4542 expr
= c_fully_fold (expr
, false, NULL
);
4543 stmt
= objc_build_throw_stmt (loc
, expr
);
4544 goto expect_semicolon
;
4548 gcc_assert (c_dialect_objc ());
4549 c_parser_objc_try_catch_finally_statement (parser
);
4551 case RID_AT_SYNCHRONIZED
:
4552 gcc_assert (c_dialect_objc ());
4553 c_parser_objc_synchronized_statement (parser
);
4560 c_parser_consume_token (parser
);
4562 case CPP_CLOSE_PAREN
:
4563 case CPP_CLOSE_SQUARE
:
4564 /* Avoid infinite loop in error recovery:
4565 c_parser_skip_until_found stops at a closing nesting
4566 delimiter without consuming it, but here we need to consume
4567 it to proceed further. */
4568 c_parser_error (parser
, "expected statement");
4569 c_parser_consume_token (parser
);
4572 c_parser_pragma (parser
, pragma_stmt
);
4576 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4578 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4581 /* Two cases cannot and do not have line numbers associated: If stmt
4582 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4583 cannot hold line numbers. But that's OK because the statement
4584 will either be changed to a MODIFY_EXPR during gimplification of
4585 the statement expr, or discarded. If stmt was compound, but
4586 without new variables, we will have skipped the creation of a
4587 BIND and will have a bare STATEMENT_LIST. But that's OK because
4588 (recursively) all of the component statements should already have
4589 line numbers assigned. ??? Can we discard no-op statements
4591 if (CAN_HAVE_LOCATION_P (stmt
)
4592 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4593 SET_EXPR_LOCATION (stmt
, loc
);
4595 parser
->in_if_block
= in_if_block
;
4598 /* Parse the condition from an if, do, while or for statements. */
4601 c_parser_condition (c_parser
*parser
)
4603 location_t loc
= c_parser_peek_token (parser
)->location
;
4605 cond
= c_parser_expression_conv (parser
).value
;
4606 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4607 cond
= c_fully_fold (cond
, false, NULL
);
4608 if (warn_sequence_point
)
4609 verify_sequence_points (cond
);
4613 /* Parse a parenthesized condition from an if, do or while statement.
4619 c_parser_paren_condition (c_parser
*parser
)
4622 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4623 return error_mark_node
;
4624 cond
= c_parser_condition (parser
);
4625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4629 /* Parse a statement which is a block in C99. */
4632 c_parser_c99_block_statement (c_parser
*parser
)
4634 tree block
= c_begin_compound_stmt (flag_isoc99
);
4635 location_t loc
= c_parser_peek_token (parser
)->location
;
4636 c_parser_statement (parser
);
4637 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4640 /* Parse the body of an if statement. This is just parsing a
4641 statement but (a) it is a block in C99, (b) we track whether the
4642 body is an if statement for the sake of -Wparentheses warnings, (c)
4643 we handle an empty body specially for the sake of -Wempty-body
4644 warnings, and (d) we call parser_compound_statement directly
4645 because c_parser_statement_after_labels resets
4646 parser->in_if_block. */
4649 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4651 tree block
= c_begin_compound_stmt (flag_isoc99
);
4652 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4653 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4654 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4655 || (c_parser_next_token_is (parser
, CPP_NAME
)
4656 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4657 c_parser_label (parser
);
4658 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4659 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4661 location_t loc
= c_parser_peek_token (parser
)->location
;
4662 add_stmt (build_empty_stmt (loc
));
4663 c_parser_consume_token (parser
);
4664 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4665 warning_at (loc
, OPT_Wempty_body
,
4666 "suggest braces around empty body in an %<if%> statement");
4668 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4669 add_stmt (c_parser_compound_statement (parser
));
4671 c_parser_statement_after_labels (parser
);
4672 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4675 /* Parse the else body of an if statement. This is just parsing a
4676 statement but (a) it is a block in C99, (b) we handle an empty body
4677 specially for the sake of -Wempty-body warnings. */
4680 c_parser_else_body (c_parser
*parser
)
4682 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4683 tree block
= c_begin_compound_stmt (flag_isoc99
);
4684 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4685 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4686 || (c_parser_next_token_is (parser
, CPP_NAME
)
4687 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4688 c_parser_label (parser
);
4689 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4691 location_t loc
= c_parser_peek_token (parser
)->location
;
4694 "suggest braces around empty body in an %<else%> statement");
4695 add_stmt (build_empty_stmt (loc
));
4696 c_parser_consume_token (parser
);
4699 c_parser_statement_after_labels (parser
);
4700 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4703 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4706 if ( expression ) statement
4707 if ( expression ) statement else statement
4711 c_parser_if_statement (c_parser
*parser
)
4716 bool first_if
= false;
4717 tree first_body
, second_body
;
4720 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4721 c_parser_consume_token (parser
);
4722 block
= c_begin_compound_stmt (flag_isoc99
);
4723 loc
= c_parser_peek_token (parser
)->location
;
4724 cond
= c_parser_paren_condition (parser
);
4725 in_if_block
= parser
->in_if_block
;
4726 parser
->in_if_block
= true;
4727 first_body
= c_parser_if_body (parser
, &first_if
);
4728 parser
->in_if_block
= in_if_block
;
4729 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4731 c_parser_consume_token (parser
);
4732 second_body
= c_parser_else_body (parser
);
4735 second_body
= NULL_TREE
;
4736 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4737 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4740 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4743 switch (expression) statement
4747 c_parser_switch_statement (c_parser
*parser
)
4749 tree block
, expr
, body
, save_break
;
4750 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4751 location_t switch_cond_loc
;
4752 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4753 c_parser_consume_token (parser
);
4754 block
= c_begin_compound_stmt (flag_isoc99
);
4755 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4757 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4758 expr
= c_parser_expression (parser
).value
;
4759 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4763 switch_cond_loc
= UNKNOWN_LOCATION
;
4764 expr
= error_mark_node
;
4766 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4767 save_break
= c_break_label
;
4768 c_break_label
= NULL_TREE
;
4769 body
= c_parser_c99_block_statement (parser
);
4770 c_finish_case (body
);
4773 location_t here
= c_parser_peek_token (parser
)->location
;
4774 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4775 SET_EXPR_LOCATION (t
, here
);
4778 c_break_label
= save_break
;
4779 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4782 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4785 while (expression) statement
4789 c_parser_while_statement (c_parser
*parser
)
4791 tree block
, cond
, body
, save_break
, save_cont
;
4793 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4794 c_parser_consume_token (parser
);
4795 block
= c_begin_compound_stmt (flag_isoc99
);
4796 loc
= c_parser_peek_token (parser
)->location
;
4797 cond
= c_parser_paren_condition (parser
);
4798 save_break
= c_break_label
;
4799 c_break_label
= NULL_TREE
;
4800 save_cont
= c_cont_label
;
4801 c_cont_label
= NULL_TREE
;
4802 body
= c_parser_c99_block_statement (parser
);
4803 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4804 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4805 c_break_label
= save_break
;
4806 c_cont_label
= save_cont
;
4809 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4812 do statement while ( expression ) ;
4816 c_parser_do_statement (c_parser
*parser
)
4818 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4820 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4821 c_parser_consume_token (parser
);
4822 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4823 warning_at (c_parser_peek_token (parser
)->location
,
4825 "suggest braces around empty body in %<do%> statement");
4826 block
= c_begin_compound_stmt (flag_isoc99
);
4827 loc
= c_parser_peek_token (parser
)->location
;
4828 save_break
= c_break_label
;
4829 c_break_label
= NULL_TREE
;
4830 save_cont
= c_cont_label
;
4831 c_cont_label
= NULL_TREE
;
4832 body
= c_parser_c99_block_statement (parser
);
4833 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4834 new_break
= c_break_label
;
4835 c_break_label
= save_break
;
4836 new_cont
= c_cont_label
;
4837 c_cont_label
= save_cont
;
4838 cond
= c_parser_paren_condition (parser
);
4839 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4840 c_parser_skip_to_end_of_block_or_statement (parser
);
4841 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4842 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4845 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4848 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4849 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4851 The form with a declaration is new in C99.
4853 ??? In accordance with the old parser, the declaration may be a
4854 nested function, which is then rejected in check_for_loop_decls,
4855 but does it make any sense for this to be included in the grammar?
4856 Note in particular that the nested function does not include a
4857 trailing ';', whereas the "declaration" production includes one.
4858 Also, can we reject bad declarations earlier and cheaper than
4859 check_for_loop_decls?
4861 In Objective-C, there are two additional variants:
4864 for ( expression in expresssion ) statement
4865 for ( declaration in expression ) statement
4867 This is inconsistent with C, because the second variant is allowed
4868 even if c99 is not enabled.
4870 The rest of the comment documents these Objective-C foreach-statement.
4872 Here is the canonical example of the first variant:
4873 for (object in array) { do something with object }
4874 we call the first expression ("object") the "object_expression" and
4875 the second expression ("array") the "collection_expression".
4876 object_expression must be an lvalue of type "id" (a generic Objective-C
4877 object) because the loop works by assigning to object_expression the
4878 various objects from the collection_expression. collection_expression
4879 must evaluate to something of type "id" which responds to the method
4880 countByEnumeratingWithState:objects:count:.
4882 The canonical example of the second variant is:
4883 for (id object in array) { do something with object }
4884 which is completely equivalent to
4887 for (object in array) { do something with object }
4889 Note that initizializing 'object' in some way (eg, "for ((object =
4890 xxx) in array) { do something with object }") is possibly
4891 technically valid, but completely pointless as 'object' will be
4892 assigned to something else as soon as the loop starts. We should
4893 most likely reject it (TODO).
4895 The beginning of the Objective-C foreach-statement looks exactly
4896 like the beginning of the for-statement, and we can tell it is a
4897 foreach-statement only because the initial declaration or
4898 expression is terminated by 'in' instead of ';'.
4902 c_parser_for_statement (c_parser
*parser
)
4904 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4905 /* The following are only used when parsing an ObjC foreach statement. */
4906 tree object_expression
;
4907 /* Silence the bogus uninitialized warning. */
4908 tree collection_expression
= NULL
;
4909 location_t loc
= c_parser_peek_token (parser
)->location
;
4910 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4911 bool is_foreach_statement
= false;
4912 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4913 c_parser_consume_token (parser
);
4914 /* Open a compound statement in Objective-C as well, just in case this is
4915 as foreach expression. */
4916 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4917 cond
= error_mark_node
;
4918 incr
= error_mark_node
;
4919 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4921 /* Parse the initialization declaration or expression. */
4922 object_expression
= error_mark_node
;
4923 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4924 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4926 parser
->objc_could_be_foreach_context
= false;
4927 c_parser_consume_token (parser
);
4928 c_finish_expr_stmt (loc
, NULL_TREE
);
4930 else if (c_parser_next_tokens_start_declaration (parser
))
4932 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4933 &object_expression
);
4934 parser
->objc_could_be_foreach_context
= false;
4936 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4938 c_parser_consume_token (parser
);
4939 is_foreach_statement
= true;
4940 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4941 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4944 check_for_loop_decls (for_loc
, flag_isoc99
);
4946 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4948 /* __extension__ can start a declaration, but is also an
4949 unary operator that can start an expression. Consume all
4950 but the last of a possible series of __extension__ to
4952 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4953 && (c_parser_peek_2nd_token (parser
)->keyword
4955 c_parser_consume_token (parser
);
4956 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4959 ext
= disable_extension_diagnostics ();
4960 c_parser_consume_token (parser
);
4961 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4962 true, &object_expression
);
4963 parser
->objc_could_be_foreach_context
= false;
4965 restore_extension_diagnostics (ext
);
4966 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4968 c_parser_consume_token (parser
);
4969 is_foreach_statement
= true;
4970 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4971 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4974 check_for_loop_decls (for_loc
, flag_isoc99
);
4983 tree init_expression
;
4984 init_expression
= c_parser_expression (parser
).value
;
4985 parser
->objc_could_be_foreach_context
= false;
4986 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4988 c_parser_consume_token (parser
);
4989 is_foreach_statement
= true;
4990 if (! lvalue_p (init_expression
))
4991 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
4992 object_expression
= c_fully_fold (init_expression
, false, NULL
);
4996 c_finish_expr_stmt (loc
, init_expression
);
4997 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5001 /* Parse the loop condition. In the case of a foreach
5002 statement, there is no loop condition. */
5003 gcc_assert (!parser
->objc_could_be_foreach_context
);
5004 if (!is_foreach_statement
)
5006 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5008 c_parser_consume_token (parser
);
5013 cond
= c_parser_condition (parser
);
5014 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5017 /* Parse the increment expression (the third expression in a
5018 for-statement). In the case of a foreach-statement, this is
5019 the expression that follows the 'in'. */
5020 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5022 if (is_foreach_statement
)
5024 c_parser_error (parser
, "missing collection in fast enumeration");
5025 collection_expression
= error_mark_node
;
5028 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5032 if (is_foreach_statement
)
5033 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5036 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5038 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5040 save_break
= c_break_label
;
5041 c_break_label
= NULL_TREE
;
5042 save_cont
= c_cont_label
;
5043 c_cont_label
= NULL_TREE
;
5044 body
= c_parser_c99_block_statement (parser
);
5045 if (is_foreach_statement
)
5046 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5048 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5049 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5050 c_break_label
= save_break
;
5051 c_cont_label
= save_cont
;
5054 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5055 statement with inputs, outputs, clobbers, and volatile tag
5059 asm type-qualifier[opt] ( asm-argument ) ;
5060 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5064 asm-string-literal : asm-operands[opt]
5065 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5066 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5069 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5072 Qualifiers other than volatile are accepted in the syntax but
5076 c_parser_asm_statement (c_parser
*parser
)
5078 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5079 bool simple
, is_goto
;
5080 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5081 int section
, nsections
;
5083 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5084 c_parser_consume_token (parser
);
5085 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5087 quals
= c_parser_peek_token (parser
)->value
;
5088 c_parser_consume_token (parser
);
5090 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5091 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5093 warning_at (c_parser_peek_token (parser
)->location
,
5095 "%E qualifier ignored on asm",
5096 c_parser_peek_token (parser
)->value
);
5098 c_parser_consume_token (parser
);
5104 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5106 c_parser_consume_token (parser
);
5110 /* ??? Follow the C++ parser rather than using the
5111 lex_untranslated_string kludge. */
5112 parser
->lex_untranslated_string
= true;
5115 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5118 str
= c_parser_asm_string_literal (parser
);
5119 if (str
== NULL_TREE
)
5120 goto error_close_paren
;
5123 outputs
= NULL_TREE
;
5125 clobbers
= NULL_TREE
;
5128 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5131 /* Parse each colon-delimited section of operands. */
5132 nsections
= 3 + is_goto
;
5133 for (section
= 0; section
< nsections
; ++section
)
5135 if (!c_parser_require (parser
, CPP_COLON
,
5138 : "expected %<:%> or %<)%>"))
5139 goto error_close_paren
;
5141 /* Once past any colon, we're no longer a simple asm. */
5144 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5145 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5150 /* For asm goto, we don't allow output operands, but reserve
5151 the slot for a future extension that does allow them. */
5153 outputs
= c_parser_asm_operands (parser
, false);
5156 inputs
= c_parser_asm_operands (parser
, true);
5159 clobbers
= c_parser_asm_clobbers (parser
);
5162 labels
= c_parser_asm_goto_operands (parser
);
5168 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5173 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5175 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5179 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5180 c_parser_skip_to_end_of_block_or_statement (parser
);
5182 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5183 clobbers
, labels
, simple
));
5186 parser
->lex_untranslated_string
= false;
5190 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5194 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5195 not outputs), apply the default conversion of functions and arrays
5200 asm-operands , asm-operand
5203 asm-string-literal ( expression )
5204 [ identifier ] asm-string-literal ( expression )
5208 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
5210 tree list
= NULL_TREE
;
5216 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5218 c_parser_consume_token (parser
);
5219 if (c_parser_next_token_is (parser
, CPP_NAME
))
5221 tree id
= c_parser_peek_token (parser
)->value
;
5222 c_parser_consume_token (parser
);
5223 name
= build_string (IDENTIFIER_LENGTH (id
),
5224 IDENTIFIER_POINTER (id
));
5228 c_parser_error (parser
, "expected identifier");
5229 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5232 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5237 str
= c_parser_asm_string_literal (parser
);
5238 if (str
== NULL_TREE
)
5240 parser
->lex_untranslated_string
= false;
5241 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5243 parser
->lex_untranslated_string
= true;
5246 loc
= c_parser_peek_token (parser
)->location
;
5247 expr
= c_parser_expression (parser
);
5248 mark_exp_read (expr
.value
);
5250 expr
= default_function_array_conversion (loc
, expr
);
5251 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5252 parser
->lex_untranslated_string
= true;
5253 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5255 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5258 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5260 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5261 c_parser_consume_token (parser
);
5268 /* Parse asm clobbers, a GNU extension.
5272 asm-clobbers , asm-string-literal
5276 c_parser_asm_clobbers (c_parser
*parser
)
5278 tree list
= NULL_TREE
;
5281 tree str
= c_parser_asm_string_literal (parser
);
5283 list
= tree_cons (NULL_TREE
, str
, list
);
5286 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5287 c_parser_consume_token (parser
);
5294 /* Parse asm goto labels, a GNU extension.
5298 asm-goto-operands , identifier
5302 c_parser_asm_goto_operands (c_parser
*parser
)
5304 tree list
= NULL_TREE
;
5309 if (c_parser_next_token_is (parser
, CPP_NAME
))
5311 c_token
*tok
= c_parser_peek_token (parser
);
5313 label
= lookup_label_for_goto (tok
->location
, name
);
5314 c_parser_consume_token (parser
);
5315 TREE_USED (label
) = 1;
5319 c_parser_error (parser
, "expected identifier");
5323 name
= build_string (IDENTIFIER_LENGTH (name
),
5324 IDENTIFIER_POINTER (name
));
5325 list
= tree_cons (name
, label
, list
);
5326 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5327 c_parser_consume_token (parser
);
5329 return nreverse (list
);
5333 /* Parse an expression other than a compound expression; that is, an
5334 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5335 NULL then it is an Objective-C message expression which is the
5336 primary-expression starting the expression as an initializer.
5338 assignment-expression:
5339 conditional-expression
5340 unary-expression assignment-operator assignment-expression
5342 assignment-operator: one of
5343 = *= /= %= += -= <<= >>= &= ^= |=
5345 In GNU C we accept any conditional expression on the LHS and
5346 diagnose the invalid lvalue rather than producing a syntax
5349 static struct c_expr
5350 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5352 struct c_expr lhs
, rhs
, ret
;
5353 enum tree_code code
;
5354 location_t op_location
, exp_location
;
5355 gcc_assert (!after
|| c_dialect_objc ());
5356 lhs
= c_parser_conditional_expression (parser
, after
);
5357 op_location
= c_parser_peek_token (parser
)->location
;
5358 switch (c_parser_peek_token (parser
)->type
)
5367 code
= TRUNC_DIV_EXPR
;
5370 code
= TRUNC_MOD_EXPR
;
5385 code
= BIT_AND_EXPR
;
5388 code
= BIT_XOR_EXPR
;
5391 code
= BIT_IOR_EXPR
;
5396 c_parser_consume_token (parser
);
5397 exp_location
= c_parser_peek_token (parser
)->location
;
5398 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5399 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5400 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5401 code
, exp_location
, rhs
.value
,
5403 if (code
== NOP_EXPR
)
5404 ret
.original_code
= MODIFY_EXPR
;
5407 TREE_NO_WARNING (ret
.value
) = 1;
5408 ret
.original_code
= ERROR_MARK
;
5410 ret
.original_type
= NULL
;
5414 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5415 is not NULL then it is an Objective-C message expression which is
5416 the primary-expression starting the expression as an initializer.
5418 conditional-expression:
5419 logical-OR-expression
5420 logical-OR-expression ? expression : conditional-expression
5424 conditional-expression:
5425 logical-OR-expression ? : conditional-expression
5428 static struct c_expr
5429 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5431 struct c_expr cond
, exp1
, exp2
, ret
;
5432 location_t cond_loc
, colon_loc
, middle_loc
;
5434 gcc_assert (!after
|| c_dialect_objc ());
5436 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5438 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5440 cond_loc
= c_parser_peek_token (parser
)->location
;
5441 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5442 c_parser_consume_token (parser
);
5443 if (c_parser_next_token_is (parser
, CPP_COLON
))
5445 tree eptype
= NULL_TREE
;
5447 middle_loc
= c_parser_peek_token (parser
)->location
;
5448 pedwarn (middle_loc
, OPT_Wpedantic
,
5449 "ISO C forbids omitting the middle term of a ?: expression");
5450 warn_for_omitted_condop (middle_loc
, cond
.value
);
5451 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5453 eptype
= TREE_TYPE (cond
.value
);
5454 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5456 /* Make sure first operand is calculated only once. */
5457 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5459 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5460 exp1
.original_type
= NULL
;
5461 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5462 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5467 = c_objc_common_truthvalue_conversion
5468 (cond_loc
, default_conversion (cond
.value
));
5469 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5470 exp1
= c_parser_expression_conv (parser
);
5471 mark_exp_read (exp1
.value
);
5472 c_inhibit_evaluation_warnings
+=
5473 ((cond
.value
== truthvalue_true_node
)
5474 - (cond
.value
== truthvalue_false_node
));
5477 colon_loc
= c_parser_peek_token (parser
)->location
;
5478 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5480 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5481 ret
.value
= error_mark_node
;
5482 ret
.original_code
= ERROR_MARK
;
5483 ret
.original_type
= NULL
;
5487 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5488 exp2
= c_parser_conditional_expression (parser
, NULL
);
5489 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5491 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5492 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5493 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5494 exp1
.value
, exp1
.original_type
,
5495 exp2
.value
, exp2
.original_type
);
5496 ret
.original_code
= ERROR_MARK
;
5497 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5498 ret
.original_type
= NULL
;
5503 /* If both sides are enum type, the default conversion will have
5504 made the type of the result be an integer type. We want to
5505 remember the enum types we started with. */
5506 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5507 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5508 ret
.original_type
= ((t1
!= error_mark_node
5509 && t2
!= error_mark_node
5510 && (TYPE_MAIN_VARIANT (t1
)
5511 == TYPE_MAIN_VARIANT (t2
)))
5518 /* Parse a binary expression; that is, a logical-OR-expression (C90
5519 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5520 an Objective-C message expression which is the primary-expression
5521 starting the expression as an initializer. PREC is the starting
5522 precedence, usually PREC_NONE.
5524 multiplicative-expression:
5526 multiplicative-expression * cast-expression
5527 multiplicative-expression / cast-expression
5528 multiplicative-expression % cast-expression
5530 additive-expression:
5531 multiplicative-expression
5532 additive-expression + multiplicative-expression
5533 additive-expression - multiplicative-expression
5537 shift-expression << additive-expression
5538 shift-expression >> additive-expression
5540 relational-expression:
5542 relational-expression < shift-expression
5543 relational-expression > shift-expression
5544 relational-expression <= shift-expression
5545 relational-expression >= shift-expression
5547 equality-expression:
5548 relational-expression
5549 equality-expression == relational-expression
5550 equality-expression != relational-expression
5554 AND-expression & equality-expression
5556 exclusive-OR-expression:
5558 exclusive-OR-expression ^ AND-expression
5560 inclusive-OR-expression:
5561 exclusive-OR-expression
5562 inclusive-OR-expression | exclusive-OR-expression
5564 logical-AND-expression:
5565 inclusive-OR-expression
5566 logical-AND-expression && inclusive-OR-expression
5568 logical-OR-expression:
5569 logical-AND-expression
5570 logical-OR-expression || logical-AND-expression
5573 static struct c_expr
5574 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5575 enum c_parser_prec prec
)
5577 /* A binary expression is parsed using operator-precedence parsing,
5578 with the operands being cast expressions. All the binary
5579 operators are left-associative. Thus a binary expression is of
5582 E0 op1 E1 op2 E2 ...
5584 which we represent on a stack. On the stack, the precedence
5585 levels are strictly increasing. When a new operator is
5586 encountered of higher precedence than that at the top of the
5587 stack, it is pushed; its LHS is the top expression, and its RHS
5588 is everything parsed until it is popped. When a new operator is
5589 encountered with precedence less than or equal to that at the top
5590 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5591 by the result of the operation until the operator at the top of
5592 the stack has lower precedence than the new operator or there is
5593 only one element on the stack; then the top expression is the LHS
5594 of the new operator. In the case of logical AND and OR
5595 expressions, we also need to adjust c_inhibit_evaluation_warnings
5596 as appropriate when the operators are pushed and popped. */
5599 /* The expression at this stack level. */
5601 /* The precedence of the operator on its left, PREC_NONE at the
5602 bottom of the stack. */
5603 enum c_parser_prec prec
;
5604 /* The operation on its left. */
5606 /* The source location of this operation. */
5610 /* Location of the binary operator. */
5611 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5614 switch (stack[sp].op) \
5616 case TRUTH_ANDIF_EXPR: \
5617 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5618 == truthvalue_false_node); \
5620 case TRUTH_ORIF_EXPR: \
5621 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5622 == truthvalue_true_node); \
5627 stack[sp - 1].expr \
5628 = default_function_array_read_conversion (stack[sp - 1].loc, \
5629 stack[sp - 1].expr); \
5631 = default_function_array_read_conversion (stack[sp].loc, \
5633 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5635 stack[sp - 1].expr, \
5639 gcc_assert (!after
|| c_dialect_objc ());
5640 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5641 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5642 stack
[0].prec
= prec
;
5646 enum c_parser_prec oprec
;
5647 enum tree_code ocode
;
5650 switch (c_parser_peek_token (parser
)->type
)
5658 ocode
= TRUNC_DIV_EXPR
;
5662 ocode
= TRUNC_MOD_EXPR
;
5674 ocode
= LSHIFT_EXPR
;
5678 ocode
= RSHIFT_EXPR
;
5692 case CPP_GREATER_EQ
:
5705 oprec
= PREC_BITAND
;
5706 ocode
= BIT_AND_EXPR
;
5709 oprec
= PREC_BITXOR
;
5710 ocode
= BIT_XOR_EXPR
;
5714 ocode
= BIT_IOR_EXPR
;
5717 oprec
= PREC_LOGAND
;
5718 ocode
= TRUTH_ANDIF_EXPR
;
5722 ocode
= TRUTH_ORIF_EXPR
;
5725 /* Not a binary operator, so end of the binary
5729 binary_loc
= c_parser_peek_token (parser
)->location
;
5730 while (oprec
<= stack
[sp
].prec
)
5736 c_parser_consume_token (parser
);
5739 case TRUTH_ANDIF_EXPR
:
5741 = default_function_array_read_conversion (stack
[sp
].loc
,
5743 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5744 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5745 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5746 == truthvalue_false_node
);
5748 case TRUTH_ORIF_EXPR
:
5750 = default_function_array_read_conversion (stack
[sp
].loc
,
5752 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5753 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5754 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5755 == truthvalue_true_node
);
5761 stack
[sp
].loc
= binary_loc
;
5762 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5763 stack
[sp
].prec
= oprec
;
5764 stack
[sp
].op
= ocode
;
5765 stack
[sp
].loc
= binary_loc
;
5770 return stack
[0].expr
;
5774 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5775 NULL then it is an Objective-C message expression which is the
5776 primary-expression starting the expression as an initializer.
5780 ( type-name ) unary-expression
5783 static struct c_expr
5784 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5786 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5787 gcc_assert (!after
|| c_dialect_objc ());
5789 return c_parser_postfix_expression_after_primary (parser
,
5791 /* If the expression begins with a parenthesized type name, it may
5792 be either a cast or a compound literal; we need to see whether
5793 the next character is '{' to tell the difference. If not, it is
5794 an unary expression. Full detection of unknown typenames here
5795 would require a 3-token lookahead. */
5796 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5797 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5799 struct c_type_name
*type_name
;
5802 c_parser_consume_token (parser
);
5803 type_name
= c_parser_type_name (parser
);
5804 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5805 if (type_name
== NULL
)
5807 ret
.value
= error_mark_node
;
5808 ret
.original_code
= ERROR_MARK
;
5809 ret
.original_type
= NULL
;
5813 /* Save casted types in the function's used types hash table. */
5814 used_types_insert (type_name
->specs
->type
);
5816 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5817 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5820 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5821 expr
= c_parser_cast_expression (parser
, NULL
);
5822 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5824 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5825 ret
.original_code
= ERROR_MARK
;
5826 ret
.original_type
= NULL
;
5830 return c_parser_unary_expression (parser
);
5833 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5839 unary-operator cast-expression
5840 sizeof unary-expression
5841 sizeof ( type-name )
5843 unary-operator: one of
5849 __alignof__ unary-expression
5850 __alignof__ ( type-name )
5853 (C11 permits _Alignof with type names only.)
5855 unary-operator: one of
5856 __extension__ __real__ __imag__
5858 Transactional Memory:
5861 transaction-expression
5863 In addition, the GNU syntax treats ++ and -- as unary operators, so
5864 they may be applied to cast expressions with errors for non-lvalues
5867 static struct c_expr
5868 c_parser_unary_expression (c_parser
*parser
)
5871 struct c_expr ret
, op
;
5872 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5874 ret
.original_code
= ERROR_MARK
;
5875 ret
.original_type
= NULL
;
5876 switch (c_parser_peek_token (parser
)->type
)
5879 c_parser_consume_token (parser
);
5880 exp_loc
= c_parser_peek_token (parser
)->location
;
5881 op
= c_parser_cast_expression (parser
, NULL
);
5882 op
= default_function_array_read_conversion (exp_loc
, op
);
5883 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5884 case CPP_MINUS_MINUS
:
5885 c_parser_consume_token (parser
);
5886 exp_loc
= c_parser_peek_token (parser
)->location
;
5887 op
= c_parser_cast_expression (parser
, NULL
);
5888 op
= default_function_array_read_conversion (exp_loc
, op
);
5889 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5891 c_parser_consume_token (parser
);
5892 op
= c_parser_cast_expression (parser
, NULL
);
5893 mark_exp_read (op
.value
);
5894 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5896 c_parser_consume_token (parser
);
5897 exp_loc
= c_parser_peek_token (parser
)->location
;
5898 op
= c_parser_cast_expression (parser
, NULL
);
5899 op
= default_function_array_read_conversion (exp_loc
, op
);
5900 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5903 if (!c_dialect_objc () && !in_system_header
)
5906 "traditional C rejects the unary plus operator");
5907 c_parser_consume_token (parser
);
5908 exp_loc
= c_parser_peek_token (parser
)->location
;
5909 op
= c_parser_cast_expression (parser
, NULL
);
5910 op
= default_function_array_read_conversion (exp_loc
, op
);
5911 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5913 c_parser_consume_token (parser
);
5914 exp_loc
= c_parser_peek_token (parser
)->location
;
5915 op
= c_parser_cast_expression (parser
, NULL
);
5916 op
= default_function_array_read_conversion (exp_loc
, op
);
5917 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5919 c_parser_consume_token (parser
);
5920 exp_loc
= c_parser_peek_token (parser
)->location
;
5921 op
= c_parser_cast_expression (parser
, NULL
);
5922 op
= default_function_array_read_conversion (exp_loc
, op
);
5923 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5925 c_parser_consume_token (parser
);
5926 exp_loc
= c_parser_peek_token (parser
)->location
;
5927 op
= c_parser_cast_expression (parser
, NULL
);
5928 op
= default_function_array_read_conversion (exp_loc
, op
);
5929 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5931 /* Refer to the address of a label as a pointer. */
5932 c_parser_consume_token (parser
);
5933 if (c_parser_next_token_is (parser
, CPP_NAME
))
5935 ret
.value
= finish_label_address_expr
5936 (c_parser_peek_token (parser
)->value
, op_loc
);
5937 c_parser_consume_token (parser
);
5941 c_parser_error (parser
, "expected identifier");
5942 ret
.value
= error_mark_node
;
5946 switch (c_parser_peek_token (parser
)->keyword
)
5949 return c_parser_sizeof_expression (parser
);
5951 return c_parser_alignof_expression (parser
);
5953 c_parser_consume_token (parser
);
5954 ext
= disable_extension_diagnostics ();
5955 ret
= c_parser_cast_expression (parser
, NULL
);
5956 restore_extension_diagnostics (ext
);
5959 c_parser_consume_token (parser
);
5960 exp_loc
= c_parser_peek_token (parser
)->location
;
5961 op
= c_parser_cast_expression (parser
, NULL
);
5962 op
= default_function_array_conversion (exp_loc
, op
);
5963 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5965 c_parser_consume_token (parser
);
5966 exp_loc
= c_parser_peek_token (parser
)->location
;
5967 op
= c_parser_cast_expression (parser
, NULL
);
5968 op
= default_function_array_conversion (exp_loc
, op
);
5969 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5970 case RID_TRANSACTION_ATOMIC
:
5971 case RID_TRANSACTION_RELAXED
:
5972 return c_parser_transaction_expression (parser
,
5973 c_parser_peek_token (parser
)->keyword
);
5975 return c_parser_postfix_expression (parser
);
5978 return c_parser_postfix_expression (parser
);
5982 /* Parse a sizeof expression. */
5984 static struct c_expr
5985 c_parser_sizeof_expression (c_parser
*parser
)
5988 location_t expr_loc
;
5989 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5990 c_parser_consume_token (parser
);
5991 c_inhibit_evaluation_warnings
++;
5993 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5994 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5996 /* Either sizeof ( type-name ) or sizeof unary-expression
5997 starting with a compound literal. */
5998 struct c_type_name
*type_name
;
5999 c_parser_consume_token (parser
);
6000 expr_loc
= c_parser_peek_token (parser
)->location
;
6001 type_name
= c_parser_type_name (parser
);
6002 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6003 if (type_name
== NULL
)
6006 c_inhibit_evaluation_warnings
--;
6008 ret
.value
= error_mark_node
;
6009 ret
.original_code
= ERROR_MARK
;
6010 ret
.original_type
= NULL
;
6013 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6015 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6020 /* sizeof ( type-name ). */
6021 c_inhibit_evaluation_warnings
--;
6023 return c_expr_sizeof_type (expr_loc
, type_name
);
6027 expr_loc
= c_parser_peek_token (parser
)->location
;
6028 expr
= c_parser_unary_expression (parser
);
6030 c_inhibit_evaluation_warnings
--;
6032 mark_exp_read (expr
.value
);
6033 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6034 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6035 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6036 return c_expr_sizeof_expr (expr_loc
, expr
);
6040 /* Parse an alignof expression. */
6042 static struct c_expr
6043 c_parser_alignof_expression (c_parser
*parser
)
6046 location_t loc
= c_parser_peek_token (parser
)->location
;
6047 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6048 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6049 /* A diagnostic is not required for the use of this identifier in
6050 the implementation namespace; only diagnose it for the C11
6051 spelling because of existing code using the other spellings. */
6053 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6056 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6059 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6062 c_parser_consume_token (parser
);
6063 c_inhibit_evaluation_warnings
++;
6065 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6066 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6068 /* Either __alignof__ ( type-name ) or __alignof__
6069 unary-expression starting with a compound literal. */
6071 struct c_type_name
*type_name
;
6073 c_parser_consume_token (parser
);
6074 loc
= c_parser_peek_token (parser
)->location
;
6075 type_name
= c_parser_type_name (parser
);
6076 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6077 if (type_name
== NULL
)
6080 c_inhibit_evaluation_warnings
--;
6082 ret
.value
= error_mark_node
;
6083 ret
.original_code
= ERROR_MARK
;
6084 ret
.original_type
= NULL
;
6087 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6089 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6094 /* alignof ( type-name ). */
6095 c_inhibit_evaluation_warnings
--;
6097 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6098 ret
.original_code
= ERROR_MARK
;
6099 ret
.original_type
= NULL
;
6105 expr
= c_parser_unary_expression (parser
);
6107 mark_exp_read (expr
.value
);
6108 c_inhibit_evaluation_warnings
--;
6110 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6112 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6113 ret
.original_code
= ERROR_MARK
;
6114 ret
.original_type
= NULL
;
6119 /* Helper function to read arguments of builtins which are interfaces
6120 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6121 others. The name of the builtin is passed using BNAME parameter.
6122 Function returns true if there were no errors while parsing and
6123 stores the arguments in CEXPR_LIST. */
6125 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6126 VEC(c_expr_t
,gc
) **ret_cexpr_list
)
6128 location_t loc
= c_parser_peek_token (parser
)->location
;
6129 VEC (c_expr_t
,gc
) *cexpr_list
;
6132 *ret_cexpr_list
= NULL
;
6133 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6135 error_at (loc
, "cannot take address of %qs", bname
);
6139 c_parser_consume_token (parser
);
6141 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6143 c_parser_consume_token (parser
);
6147 expr
= c_parser_expr_no_commas (parser
, NULL
);
6148 cexpr_list
= VEC_alloc (c_expr_t
, gc
, 1);
6149 C_EXPR_APPEND (cexpr_list
, expr
);
6150 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6152 c_parser_consume_token (parser
);
6153 expr
= c_parser_expr_no_commas (parser
, NULL
);
6154 C_EXPR_APPEND (cexpr_list
, expr
);
6157 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6160 *ret_cexpr_list
= cexpr_list
;
6165 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6169 postfix-expression [ expression ]
6170 postfix-expression ( argument-expression-list[opt] )
6171 postfix-expression . identifier
6172 postfix-expression -> identifier
6173 postfix-expression ++
6174 postfix-expression --
6175 ( type-name ) { initializer-list }
6176 ( type-name ) { initializer-list , }
6178 argument-expression-list:
6180 argument-expression-list , argument-expression
6192 (treated as a keyword in GNU C)
6195 ( compound-statement )
6196 __builtin_va_arg ( assignment-expression , type-name )
6197 __builtin_offsetof ( type-name , offsetof-member-designator )
6198 __builtin_choose_expr ( assignment-expression ,
6199 assignment-expression ,
6200 assignment-expression )
6201 __builtin_types_compatible_p ( type-name , type-name )
6202 __builtin_complex ( assignment-expression , assignment-expression )
6203 __builtin_shuffle ( assignment-expression , assignment-expression )
6204 __builtin_shuffle ( assignment-expression ,
6205 assignment-expression ,
6206 assignment-expression, )
6208 offsetof-member-designator:
6210 offsetof-member-designator . identifier
6211 offsetof-member-designator [ expression ]
6216 [ objc-receiver objc-message-args ]
6217 @selector ( objc-selector-arg )
6218 @protocol ( identifier )
6219 @encode ( type-name )
6221 Classname . identifier
6224 static struct c_expr
6225 c_parser_postfix_expression (c_parser
*parser
)
6227 struct c_expr expr
, e1
;
6228 struct c_type_name
*t1
, *t2
;
6229 location_t loc
= c_parser_peek_token (parser
)->location
;;
6230 expr
.original_code
= ERROR_MARK
;
6231 expr
.original_type
= NULL
;
6232 switch (c_parser_peek_token (parser
)->type
)
6235 expr
.value
= c_parser_peek_token (parser
)->value
;
6236 loc
= c_parser_peek_token (parser
)->location
;
6237 c_parser_consume_token (parser
);
6238 if (TREE_CODE (expr
.value
) == FIXED_CST
6239 && !targetm
.fixed_point_supported_p ())
6241 error_at (loc
, "fixed-point types not supported for this target");
6242 expr
.value
= error_mark_node
;
6249 expr
.value
= c_parser_peek_token (parser
)->value
;
6250 c_parser_consume_token (parser
);
6256 case CPP_UTF8STRING
:
6257 expr
.value
= c_parser_peek_token (parser
)->value
;
6258 expr
.original_code
= STRING_CST
;
6259 c_parser_consume_token (parser
);
6261 case CPP_OBJC_STRING
:
6262 gcc_assert (c_dialect_objc ());
6264 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6265 c_parser_consume_token (parser
);
6268 switch (c_parser_peek_token (parser
)->id_kind
)
6272 tree id
= c_parser_peek_token (parser
)->value
;
6273 c_parser_consume_token (parser
);
6274 expr
.value
= build_external_ref (loc
, id
,
6275 (c_parser_peek_token (parser
)->type
6277 &expr
.original_type
);
6280 case C_ID_CLASSNAME
:
6282 /* Here we parse the Objective-C 2.0 Class.name dot
6284 tree class_name
= c_parser_peek_token (parser
)->value
;
6286 c_parser_consume_token (parser
);
6287 gcc_assert (c_dialect_objc ());
6288 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6290 expr
.value
= error_mark_node
;
6293 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6295 c_parser_error (parser
, "expected identifier");
6296 expr
.value
= error_mark_node
;
6299 component
= c_parser_peek_token (parser
)->value
;
6300 c_parser_consume_token (parser
);
6301 expr
.value
= objc_build_class_component_ref (class_name
,
6306 c_parser_error (parser
, "expected expression");
6307 expr
.value
= error_mark_node
;
6311 case CPP_OPEN_PAREN
:
6312 /* A parenthesized expression, statement expression or compound
6314 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6316 /* A statement expression. */
6318 location_t brace_loc
;
6319 c_parser_consume_token (parser
);
6320 brace_loc
= c_parser_peek_token (parser
)->location
;
6321 c_parser_consume_token (parser
);
6322 if (!building_stmt_list_p ())
6324 error_at (loc
, "braced-group within expression allowed "
6325 "only inside a function");
6326 parser
->error
= true;
6327 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6328 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6329 expr
.value
= error_mark_node
;
6332 stmt
= c_begin_stmt_expr ();
6333 c_parser_compound_statement_nostart (parser
);
6334 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6336 pedwarn (loc
, OPT_Wpedantic
,
6337 "ISO C forbids braced-groups within expressions");
6338 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6339 mark_exp_read (expr
.value
);
6341 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6343 /* A compound literal. ??? Can we actually get here rather
6344 than going directly to
6345 c_parser_postfix_expression_after_paren_type from
6348 struct c_type_name
*type_name
;
6349 c_parser_consume_token (parser
);
6350 loc
= c_parser_peek_token (parser
)->location
;
6351 type_name
= c_parser_type_name (parser
);
6352 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6354 if (type_name
== NULL
)
6356 expr
.value
= error_mark_node
;
6359 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6365 /* A parenthesized expression. */
6366 c_parser_consume_token (parser
);
6367 expr
= c_parser_expression (parser
);
6368 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6369 TREE_NO_WARNING (expr
.value
) = 1;
6370 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6371 expr
.original_code
= ERROR_MARK
;
6372 /* Don't change EXPR.ORIGINAL_TYPE. */
6373 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6378 switch (c_parser_peek_token (parser
)->keyword
)
6380 case RID_FUNCTION_NAME
:
6381 case RID_PRETTY_FUNCTION_NAME
:
6382 case RID_C99_FUNCTION_NAME
:
6383 expr
.value
= fname_decl (loc
,
6384 c_parser_peek_token (parser
)->keyword
,
6385 c_parser_peek_token (parser
)->value
);
6386 c_parser_consume_token (parser
);
6389 c_parser_consume_token (parser
);
6390 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6392 expr
.value
= error_mark_node
;
6395 e1
= c_parser_expr_no_commas (parser
, NULL
);
6396 mark_exp_read (e1
.value
);
6397 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6398 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6400 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6401 expr
.value
= error_mark_node
;
6404 loc
= c_parser_peek_token (parser
)->location
;
6405 t1
= c_parser_type_name (parser
);
6406 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6410 expr
.value
= error_mark_node
;
6414 tree type_expr
= NULL_TREE
;
6415 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6416 groktypename (t1
, &type_expr
, NULL
));
6419 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6420 TREE_TYPE (expr
.value
), type_expr
,
6422 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6427 c_parser_consume_token (parser
);
6428 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6430 expr
.value
= error_mark_node
;
6433 t1
= c_parser_type_name (parser
);
6435 parser
->error
= true;
6436 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6437 gcc_assert (parser
->error
);
6440 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6441 expr
.value
= error_mark_node
;
6446 tree type
= groktypename (t1
, NULL
, NULL
);
6448 if (type
== error_mark_node
)
6449 offsetof_ref
= error_mark_node
;
6452 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6453 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6455 /* Parse the second argument to __builtin_offsetof. We
6456 must have one identifier, and beyond that we want to
6457 accept sub structure and sub array references. */
6458 if (c_parser_next_token_is (parser
, CPP_NAME
))
6460 offsetof_ref
= build_component_ref
6461 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6462 c_parser_consume_token (parser
);
6463 while (c_parser_next_token_is (parser
, CPP_DOT
)
6464 || c_parser_next_token_is (parser
,
6466 || c_parser_next_token_is (parser
,
6469 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6471 loc
= c_parser_peek_token (parser
)->location
;
6472 offsetof_ref
= build_array_ref (loc
,
6477 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6480 c_parser_consume_token (parser
);
6481 if (c_parser_next_token_is_not (parser
,
6484 c_parser_error (parser
, "expected identifier");
6487 offsetof_ref
= build_component_ref
6489 c_parser_peek_token (parser
)->value
);
6490 c_parser_consume_token (parser
);
6495 loc
= c_parser_peek_token (parser
)->location
;
6496 c_parser_consume_token (parser
);
6497 idx
= c_parser_expression (parser
).value
;
6498 idx
= c_fully_fold (idx
, false, NULL
);
6499 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6501 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6506 c_parser_error (parser
, "expected identifier");
6507 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6509 expr
.value
= fold_offsetof (offsetof_ref
);
6512 case RID_CHOOSE_EXPR
:
6514 VEC (c_expr_t
, gc
) *cexpr_list
;
6515 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6518 c_parser_consume_token (parser
);
6519 if (!c_parser_get_builtin_args (parser
,
6520 "__builtin_choose_expr",
6523 expr
.value
= error_mark_node
;
6527 if (VEC_length (c_expr_t
, cexpr_list
) != 3)
6529 error_at (loc
, "wrong number of arguments to "
6530 "%<__builtin_choose_expr%>");
6531 expr
.value
= error_mark_node
;
6535 e1_p
= &VEC_index (c_expr_t
, cexpr_list
, 0);
6536 e2_p
= &VEC_index (c_expr_t
, cexpr_list
, 1);
6537 e3_p
= &VEC_index (c_expr_t
, cexpr_list
, 2);
6540 mark_exp_read (e2_p
->value
);
6541 mark_exp_read (e3_p
->value
);
6542 if (TREE_CODE (c
) != INTEGER_CST
6543 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6545 "first argument to %<__builtin_choose_expr%> not"
6547 constant_expression_warning (c
);
6548 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6551 case RID_TYPES_COMPATIBLE_P
:
6552 c_parser_consume_token (parser
);
6553 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6555 expr
.value
= error_mark_node
;
6558 t1
= c_parser_type_name (parser
);
6561 expr
.value
= error_mark_node
;
6564 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6566 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6567 expr
.value
= error_mark_node
;
6570 t2
= c_parser_type_name (parser
);
6573 expr
.value
= error_mark_node
;
6576 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6580 e1
= groktypename (t1
, NULL
, NULL
);
6581 e2
= groktypename (t2
, NULL
, NULL
);
6582 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6584 expr
.value
= error_mark_node
;
6588 e1
= TYPE_MAIN_VARIANT (e1
);
6589 e2
= TYPE_MAIN_VARIANT (e2
);
6592 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6595 case RID_BUILTIN_COMPLEX
:
6597 VEC(c_expr_t
, gc
) *cexpr_list
;
6598 c_expr_t
*e1_p
, *e2_p
;
6600 c_parser_consume_token (parser
);
6601 if (!c_parser_get_builtin_args (parser
,
6602 "__builtin_complex",
6605 expr
.value
= error_mark_node
;
6609 if (VEC_length (c_expr_t
, cexpr_list
) != 2)
6611 error_at (loc
, "wrong number of arguments to "
6612 "%<__builtin_complex%>");
6613 expr
.value
= error_mark_node
;
6617 e1_p
= &VEC_index (c_expr_t
, cexpr_list
, 0);
6618 e2_p
= &VEC_index (c_expr_t
, cexpr_list
, 1);
6620 mark_exp_read (e1_p
->value
);
6621 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
6622 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
6623 TREE_OPERAND (e1_p
->value
, 0));
6624 mark_exp_read (e2_p
->value
);
6625 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
6626 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
6627 TREE_OPERAND (e2_p
->value
, 0));
6628 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6629 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6630 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
6631 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
6633 error_at (loc
, "%<__builtin_complex%> operand "
6634 "not of real binary floating-point type");
6635 expr
.value
= error_mark_node
;
6638 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
6639 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
6642 "%<__builtin_complex%> operands of different types");
6643 expr
.value
= error_mark_node
;
6647 pedwarn (loc
, OPT_Wpedantic
,
6648 "ISO C90 does not support complex types");
6649 expr
.value
= build2 (COMPLEX_EXPR
,
6652 (TREE_TYPE (e1_p
->value
))),
6653 e1_p
->value
, e2_p
->value
);
6656 case RID_BUILTIN_SHUFFLE
:
6658 VEC(c_expr_t
,gc
) *cexpr_list
;
6662 c_parser_consume_token (parser
);
6663 if (!c_parser_get_builtin_args (parser
,
6664 "__builtin_shuffle",
6667 expr
.value
= error_mark_node
;
6671 FOR_EACH_VEC_ELT (c_expr_t
, cexpr_list
, i
, p
)
6672 mark_exp_read (p
->value
);
6674 if (VEC_length (c_expr_t
, cexpr_list
) == 2)
6676 c_build_vec_perm_expr
6677 (loc
, VEC_index (c_expr_t
, cexpr_list
, 0).value
,
6678 NULL_TREE
, VEC_index (c_expr_t
, cexpr_list
, 1).value
);
6680 else if (VEC_length (c_expr_t
, cexpr_list
) == 3)
6682 c_build_vec_perm_expr
6683 (loc
, VEC_index (c_expr_t
, cexpr_list
, 0).value
,
6684 VEC_index (c_expr_t
, cexpr_list
, 1).value
,
6685 VEC_index (c_expr_t
, cexpr_list
, 2).value
);
6688 error_at (loc
, "wrong number of arguments to "
6689 "%<__builtin_shuffle%>");
6690 expr
.value
= error_mark_node
;
6694 case RID_AT_SELECTOR
:
6695 gcc_assert (c_dialect_objc ());
6696 c_parser_consume_token (parser
);
6697 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6699 expr
.value
= error_mark_node
;
6703 tree sel
= c_parser_objc_selector_arg (parser
);
6704 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6706 expr
.value
= objc_build_selector_expr (loc
, sel
);
6709 case RID_AT_PROTOCOL
:
6710 gcc_assert (c_dialect_objc ());
6711 c_parser_consume_token (parser
);
6712 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6714 expr
.value
= error_mark_node
;
6717 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6719 c_parser_error (parser
, "expected identifier");
6720 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6721 expr
.value
= error_mark_node
;
6725 tree id
= c_parser_peek_token (parser
)->value
;
6726 c_parser_consume_token (parser
);
6727 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6729 expr
.value
= objc_build_protocol_expr (id
);
6733 /* Extension to support C-structures in the archiver. */
6734 gcc_assert (c_dialect_objc ());
6735 c_parser_consume_token (parser
);
6736 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6738 expr
.value
= error_mark_node
;
6741 t1
= c_parser_type_name (parser
);
6744 expr
.value
= error_mark_node
;
6745 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6748 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6751 tree type
= groktypename (t1
, NULL
, NULL
);
6752 expr
.value
= objc_build_encode_expr (type
);
6756 c_parser_error (parser
, "expected expression");
6757 expr
.value
= error_mark_node
;
6761 case CPP_OPEN_SQUARE
:
6762 if (c_dialect_objc ())
6764 tree receiver
, args
;
6765 c_parser_consume_token (parser
);
6766 receiver
= c_parser_objc_receiver (parser
);
6767 args
= c_parser_objc_message_args (parser
);
6768 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6770 expr
.value
= objc_build_message_expr (receiver
, args
);
6773 /* Else fall through to report error. */
6775 c_parser_error (parser
, "expected expression");
6776 expr
.value
= error_mark_node
;
6779 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6782 /* Parse a postfix expression after a parenthesized type name: the
6783 brace-enclosed initializer of a compound literal, possibly followed
6784 by some postfix operators. This is separate because it is not
6785 possible to tell until after the type name whether a cast
6786 expression has a cast or a compound literal, or whether the operand
6787 of sizeof is a parenthesized type name or starts with a compound
6788 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6789 location of the first token after the parentheses around the type
6792 static struct c_expr
6793 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6794 struct c_type_name
*type_name
,
6795 location_t type_loc
)
6801 location_t start_loc
;
6802 tree type_expr
= NULL_TREE
;
6803 bool type_expr_const
= true;
6804 check_compound_literal_type (type_loc
, type_name
);
6805 start_init (NULL_TREE
, NULL
, 0);
6806 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6807 start_loc
= c_parser_peek_token (parser
)->location
;
6808 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6810 error_at (type_loc
, "compound literal has variable size");
6811 type
= error_mark_node
;
6813 init
= c_parser_braced_init (parser
, type
, false);
6815 maybe_warn_string_init (type
, init
);
6817 if (type
!= error_mark_node
6818 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6819 && current_function_decl
)
6821 error ("compound literal qualified by address-space qualifier");
6822 type
= error_mark_node
;
6826 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
6827 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6828 ? CONSTRUCTOR_NON_CONST (init
.value
)
6829 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6830 non_const
|= !type_expr_const
;
6831 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6832 expr
.original_code
= ERROR_MARK
;
6833 expr
.original_type
= NULL
;
6836 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6838 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6839 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6843 gcc_assert (!non_const
);
6844 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6845 type_expr
, expr
.value
);
6848 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6851 /* Callback function for sizeof_pointer_memaccess_warning to compare
6855 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
6857 return comptypes (type1
, type2
) == 1;
6860 /* Parse a postfix expression after the initial primary or compound
6861 literal; that is, parse a series of postfix operators.
6863 EXPR_LOC is the location of the primary expression. */
6865 static struct c_expr
6866 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6867 location_t expr_loc
,
6870 struct c_expr orig_expr
;
6872 location_t sizeof_arg_loc
[3];
6875 VEC(tree
,gc
) *exprlist
;
6876 VEC(tree
,gc
) *origtypes
;
6879 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6880 switch (c_parser_peek_token (parser
)->type
)
6882 case CPP_OPEN_SQUARE
:
6883 /* Array reference. */
6884 c_parser_consume_token (parser
);
6885 idx
= c_parser_expression (parser
).value
;
6886 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6888 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6889 expr
.original_code
= ERROR_MARK
;
6890 expr
.original_type
= NULL
;
6892 case CPP_OPEN_PAREN
:
6893 /* Function call. */
6894 c_parser_consume_token (parser
);
6895 for (i
= 0; i
< 3; i
++)
6897 sizeof_arg
[i
] = NULL_TREE
;
6898 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
6900 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6903 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
6904 sizeof_arg_loc
, sizeof_arg
);
6905 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6908 mark_exp_read (expr
.value
);
6909 if (warn_sizeof_pointer_memaccess
)
6910 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
6911 expr
.value
, exprlist
,
6913 sizeof_ptr_memacc_comptypes
);
6914 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6915 "(" after the FUNCNAME, which is what we have now. */
6916 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6918 expr
.original_code
= ERROR_MARK
;
6919 if (TREE_CODE (expr
.value
) == INTEGER_CST
6920 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6921 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6922 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6923 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6924 expr
.original_type
= NULL
;
6925 if (exprlist
!= NULL
)
6927 release_tree_vector (exprlist
);
6928 release_tree_vector (origtypes
);
6932 /* Structure element reference. */
6933 c_parser_consume_token (parser
);
6934 expr
= default_function_array_conversion (expr_loc
, expr
);
6935 if (c_parser_next_token_is (parser
, CPP_NAME
))
6936 ident
= c_parser_peek_token (parser
)->value
;
6939 c_parser_error (parser
, "expected identifier");
6940 expr
.value
= error_mark_node
;
6941 expr
.original_code
= ERROR_MARK
;
6942 expr
.original_type
= NULL
;
6945 c_parser_consume_token (parser
);
6946 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6947 expr
.original_code
= ERROR_MARK
;
6948 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6949 expr
.original_type
= NULL
;
6952 /* Remember the original type of a bitfield. */
6953 tree field
= TREE_OPERAND (expr
.value
, 1);
6954 if (TREE_CODE (field
) != FIELD_DECL
)
6955 expr
.original_type
= NULL
;
6957 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6961 /* Structure element reference. */
6962 c_parser_consume_token (parser
);
6963 expr
= default_function_array_conversion (expr_loc
, expr
);
6964 if (c_parser_next_token_is (parser
, CPP_NAME
))
6965 ident
= c_parser_peek_token (parser
)->value
;
6968 c_parser_error (parser
, "expected identifier");
6969 expr
.value
= error_mark_node
;
6970 expr
.original_code
= ERROR_MARK
;
6971 expr
.original_type
= NULL
;
6974 c_parser_consume_token (parser
);
6975 expr
.value
= build_component_ref (op_loc
,
6976 build_indirect_ref (op_loc
,
6980 expr
.original_code
= ERROR_MARK
;
6981 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6982 expr
.original_type
= NULL
;
6985 /* Remember the original type of a bitfield. */
6986 tree field
= TREE_OPERAND (expr
.value
, 1);
6987 if (TREE_CODE (field
) != FIELD_DECL
)
6988 expr
.original_type
= NULL
;
6990 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6994 /* Postincrement. */
6995 c_parser_consume_token (parser
);
6996 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6997 expr
.value
= build_unary_op (op_loc
,
6998 POSTINCREMENT_EXPR
, expr
.value
, 0);
6999 expr
.original_code
= ERROR_MARK
;
7000 expr
.original_type
= NULL
;
7002 case CPP_MINUS_MINUS
:
7003 /* Postdecrement. */
7004 c_parser_consume_token (parser
);
7005 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7006 expr
.value
= build_unary_op (op_loc
,
7007 POSTDECREMENT_EXPR
, expr
.value
, 0);
7008 expr
.original_code
= ERROR_MARK
;
7009 expr
.original_type
= NULL
;
7017 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7020 assignment-expression
7021 expression , assignment-expression
7024 static struct c_expr
7025 c_parser_expression (c_parser
*parser
)
7028 expr
= c_parser_expr_no_commas (parser
, NULL
);
7029 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7033 location_t loc
= c_parser_peek_token (parser
)->location
;
7034 location_t expr_loc
;
7035 c_parser_consume_token (parser
);
7036 expr_loc
= c_parser_peek_token (parser
)->location
;
7037 lhsval
= expr
.value
;
7038 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7039 lhsval
= TREE_OPERAND (lhsval
, 1);
7040 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7041 mark_exp_read (lhsval
);
7042 next
= c_parser_expr_no_commas (parser
, NULL
);
7043 next
= default_function_array_conversion (expr_loc
, next
);
7044 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7045 expr
.original_code
= COMPOUND_EXPR
;
7046 expr
.original_type
= next
.original_type
;
7051 /* Parse an expression and convert functions or arrays to
7054 static struct c_expr
7055 c_parser_expression_conv (c_parser
*parser
)
7058 location_t loc
= c_parser_peek_token (parser
)->location
;
7059 expr
= c_parser_expression (parser
);
7060 expr
= default_function_array_conversion (loc
, expr
);
7064 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7065 functions and arrays to pointers. If FOLD_P, fold the expressions.
7068 assignment-expression
7069 nonempty-expr-list , assignment-expression
7072 static VEC(tree
,gc
) *
7073 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7074 VEC(tree
,gc
) **p_orig_types
, location_t
*sizeof_arg_loc
,
7078 VEC(tree
,gc
) *orig_types
;
7080 location_t loc
= c_parser_peek_token (parser
)->location
;
7081 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7082 unsigned int idx
= 0;
7084 ret
= make_tree_vector ();
7085 if (p_orig_types
== NULL
)
7088 orig_types
= make_tree_vector ();
7090 if (sizeof_arg
!= NULL
7091 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7092 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7093 expr
= c_parser_expr_no_commas (parser
, NULL
);
7095 expr
= default_function_array_read_conversion (loc
, expr
);
7097 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7098 VEC_quick_push (tree
, ret
, expr
.value
);
7099 if (orig_types
!= NULL
)
7100 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
7101 if (sizeof_arg
!= NULL
7102 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7103 && expr
.original_code
== SIZEOF_EXPR
)
7105 sizeof_arg
[0] = c_last_sizeof_arg
;
7106 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7108 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7110 c_parser_consume_token (parser
);
7111 loc
= c_parser_peek_token (parser
)->location
;
7112 if (sizeof_arg
!= NULL
7113 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7114 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7116 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7117 expr
= c_parser_expr_no_commas (parser
, NULL
);
7119 expr
= default_function_array_read_conversion (loc
, expr
);
7121 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7122 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
7123 if (orig_types
!= NULL
)
7124 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
7126 && sizeof_arg
!= NULL
7127 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7128 && expr
.original_code
== SIZEOF_EXPR
)
7130 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7131 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7134 if (orig_types
!= NULL
)
7135 *p_orig_types
= orig_types
;
7139 /* Parse Objective-C-specific constructs. */
7141 /* Parse an objc-class-definition.
7143 objc-class-definition:
7144 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7145 objc-class-instance-variables[opt] objc-methodprotolist @end
7146 @implementation identifier objc-superclass[opt]
7147 objc-class-instance-variables[opt]
7148 @interface identifier ( identifier ) objc-protocol-refs[opt]
7149 objc-methodprotolist @end
7150 @interface identifier ( ) objc-protocol-refs[opt]
7151 objc-methodprotolist @end
7152 @implementation identifier ( identifier )
7157 "@interface identifier (" must start "@interface identifier (
7158 identifier ) ...": objc-methodprotolist in the first production may
7159 not start with a parenthesized identifier as a declarator of a data
7160 definition with no declaration specifiers if the objc-superclass,
7161 objc-protocol-refs and objc-class-instance-variables are omitted. */
7164 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7169 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7171 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7176 c_parser_consume_token (parser
);
7177 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7179 c_parser_error (parser
, "expected identifier");
7182 id1
= c_parser_peek_token (parser
)->value
;
7183 c_parser_consume_token (parser
);
7184 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7186 /* We have a category or class extension. */
7188 tree proto
= NULL_TREE
;
7189 c_parser_consume_token (parser
);
7190 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7192 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7194 /* We have a class extension. */
7199 c_parser_error (parser
, "expected identifier or %<)%>");
7200 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7206 id2
= c_parser_peek_token (parser
)->value
;
7207 c_parser_consume_token (parser
);
7209 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7212 objc_start_category_implementation (id1
, id2
);
7215 if (c_parser_next_token_is (parser
, CPP_LESS
))
7216 proto
= c_parser_objc_protocol_refs (parser
);
7217 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7218 c_parser_objc_methodprotolist (parser
);
7219 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7220 objc_finish_interface ();
7223 if (c_parser_next_token_is (parser
, CPP_COLON
))
7225 c_parser_consume_token (parser
);
7226 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7228 c_parser_error (parser
, "expected identifier");
7231 superclass
= c_parser_peek_token (parser
)->value
;
7232 c_parser_consume_token (parser
);
7235 superclass
= NULL_TREE
;
7238 tree proto
= NULL_TREE
;
7239 if (c_parser_next_token_is (parser
, CPP_LESS
))
7240 proto
= c_parser_objc_protocol_refs (parser
);
7241 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7244 objc_start_class_implementation (id1
, superclass
);
7245 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7246 c_parser_objc_class_instance_variables (parser
);
7249 objc_continue_interface ();
7250 c_parser_objc_methodprotolist (parser
);
7251 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7252 objc_finish_interface ();
7256 objc_continue_implementation ();
7261 /* Parse objc-class-instance-variables.
7263 objc-class-instance-variables:
7264 { objc-instance-variable-decl-list[opt] }
7266 objc-instance-variable-decl-list:
7267 objc-visibility-spec
7268 objc-instance-variable-decl ;
7270 objc-instance-variable-decl-list objc-visibility-spec
7271 objc-instance-variable-decl-list objc-instance-variable-decl ;
7272 objc-instance-variable-decl-list ;
7274 objc-visibility-spec:
7279 objc-instance-variable-decl:
7284 c_parser_objc_class_instance_variables (c_parser
*parser
)
7286 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7287 c_parser_consume_token (parser
);
7288 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7291 /* Parse any stray semicolon. */
7292 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7294 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7296 c_parser_consume_token (parser
);
7299 /* Stop if at the end of the instance variables. */
7300 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7302 c_parser_consume_token (parser
);
7305 /* Parse any objc-visibility-spec. */
7306 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7308 c_parser_consume_token (parser
);
7309 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7312 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7314 c_parser_consume_token (parser
);
7315 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7318 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7320 c_parser_consume_token (parser
);
7321 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7324 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7326 c_parser_consume_token (parser
);
7327 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7330 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7332 c_parser_pragma (parser
, pragma_external
);
7336 /* Parse some comma-separated declarations. */
7337 decls
= c_parser_struct_declaration (parser
);
7340 /* There is a syntax error. We want to skip the offending
7341 tokens up to the next ';' (included) or '}'
7344 /* First, skip manually a ')' or ']'. This is because they
7345 reduce the nesting level, so c_parser_skip_until_found()
7346 wouldn't be able to skip past them. */
7347 c_token
*token
= c_parser_peek_token (parser
);
7348 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7349 c_parser_consume_token (parser
);
7351 /* Then, do the standard skipping. */
7352 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7354 /* We hopefully recovered. Start normal parsing again. */
7355 parser
->error
= false;
7360 /* Comma-separated instance variables are chained together
7361 in reverse order; add them one by one. */
7362 tree ivar
= nreverse (decls
);
7363 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7364 objc_add_instance_variable (copy_node (ivar
));
7366 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7370 /* Parse an objc-class-declaration.
7372 objc-class-declaration:
7373 @class identifier-list ;
7377 c_parser_objc_class_declaration (c_parser
*parser
)
7379 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7380 c_parser_consume_token (parser
);
7381 /* Any identifiers, including those declared as type names, are OK
7386 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7388 c_parser_error (parser
, "expected identifier");
7389 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7390 parser
->error
= false;
7393 id
= c_parser_peek_token (parser
)->value
;
7394 objc_declare_class (id
);
7395 c_parser_consume_token (parser
);
7396 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7397 c_parser_consume_token (parser
);
7401 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7404 /* Parse an objc-alias-declaration.
7406 objc-alias-declaration:
7407 @compatibility_alias identifier identifier ;
7411 c_parser_objc_alias_declaration (c_parser
*parser
)
7414 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7415 c_parser_consume_token (parser
);
7416 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7418 c_parser_error (parser
, "expected identifier");
7419 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7422 id1
= c_parser_peek_token (parser
)->value
;
7423 c_parser_consume_token (parser
);
7424 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7426 c_parser_error (parser
, "expected identifier");
7427 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7430 id2
= c_parser_peek_token (parser
)->value
;
7431 c_parser_consume_token (parser
);
7432 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7433 objc_declare_alias (id1
, id2
);
7436 /* Parse an objc-protocol-definition.
7438 objc-protocol-definition:
7439 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7440 @protocol identifier-list ;
7442 "@protocol identifier ;" should be resolved as "@protocol
7443 identifier-list ;": objc-methodprotolist may not start with a
7444 semicolon in the first alternative if objc-protocol-refs are
7448 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7450 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7452 c_parser_consume_token (parser
);
7453 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7455 c_parser_error (parser
, "expected identifier");
7458 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7459 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7461 /* Any identifiers, including those declared as type names, are
7466 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7468 c_parser_error (parser
, "expected identifier");
7471 id
= c_parser_peek_token (parser
)->value
;
7472 objc_declare_protocol (id
, attributes
);
7473 c_parser_consume_token (parser
);
7474 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7475 c_parser_consume_token (parser
);
7479 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7483 tree id
= c_parser_peek_token (parser
)->value
;
7484 tree proto
= NULL_TREE
;
7485 c_parser_consume_token (parser
);
7486 if (c_parser_next_token_is (parser
, CPP_LESS
))
7487 proto
= c_parser_objc_protocol_refs (parser
);
7488 parser
->objc_pq_context
= true;
7489 objc_start_protocol (id
, proto
, attributes
);
7490 c_parser_objc_methodprotolist (parser
);
7491 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7492 parser
->objc_pq_context
= false;
7493 objc_finish_interface ();
7497 /* Parse an objc-method-type.
7503 Return true if it is a class method (+) and false if it is
7504 an instance method (-).
7507 c_parser_objc_method_type (c_parser
*parser
)
7509 switch (c_parser_peek_token (parser
)->type
)
7512 c_parser_consume_token (parser
);
7515 c_parser_consume_token (parser
);
7522 /* Parse an objc-method-definition.
7524 objc-method-definition:
7525 objc-method-type objc-method-decl ;[opt] compound-statement
7529 c_parser_objc_method_definition (c_parser
*parser
)
7531 bool is_class_method
= c_parser_objc_method_type (parser
);
7532 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7533 parser
->objc_pq_context
= true;
7534 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7536 if (decl
== error_mark_node
)
7537 return; /* Bail here. */
7539 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7541 c_parser_consume_token (parser
);
7542 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7543 "extra semicolon in method definition specified");
7546 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7548 c_parser_error (parser
, "expected %<{%>");
7552 parser
->objc_pq_context
= false;
7553 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7555 add_stmt (c_parser_compound_statement (parser
));
7556 objc_finish_method_definition (current_function_decl
);
7560 /* This code is executed when we find a method definition
7561 outside of an @implementation context (or invalid for other
7562 reasons). Parse the method (to keep going) but do not emit
7565 c_parser_compound_statement (parser
);
7569 /* Parse an objc-methodprotolist.
7571 objc-methodprotolist:
7573 objc-methodprotolist objc-methodproto
7574 objc-methodprotolist declaration
7575 objc-methodprotolist ;
7579 The declaration is a data definition, which may be missing
7580 declaration specifiers under the same rules and diagnostics as
7581 other data definitions outside functions, and the stray semicolon
7582 is diagnosed the same way as a stray semicolon outside a
7586 c_parser_objc_methodprotolist (c_parser
*parser
)
7590 /* The list is terminated by @end. */
7591 switch (c_parser_peek_token (parser
)->type
)
7594 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7595 "ISO C does not allow extra %<;%> outside of a function");
7596 c_parser_consume_token (parser
);
7600 c_parser_objc_methodproto (parser
);
7603 c_parser_pragma (parser
, pragma_external
);
7608 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7610 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7611 c_parser_objc_at_property_declaration (parser
);
7612 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7614 objc_set_method_opt (true);
7615 c_parser_consume_token (parser
);
7617 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7619 objc_set_method_opt (false);
7620 c_parser_consume_token (parser
);
7623 c_parser_declaration_or_fndef (parser
, false, false, true,
7630 /* Parse an objc-methodproto.
7633 objc-method-type objc-method-decl ;
7637 c_parser_objc_methodproto (c_parser
*parser
)
7639 bool is_class_method
= c_parser_objc_method_type (parser
);
7640 tree decl
, attributes
= NULL_TREE
;
7642 /* Remember protocol qualifiers in prototypes. */
7643 parser
->objc_pq_context
= true;
7644 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7646 /* Forget protocol qualifiers now. */
7647 parser
->objc_pq_context
= false;
7649 /* Do not allow the presence of attributes to hide an erroneous
7650 method implementation in the interface section. */
7651 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7653 c_parser_error (parser
, "expected %<;%>");
7657 if (decl
!= error_mark_node
)
7658 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7660 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7663 /* If we are at a position that method attributes may be present, check that
7664 there are not any parsed already (a syntax error) and then collect any
7665 specified at the current location. Finally, if new attributes were present,
7666 check that the next token is legal ( ';' for decls and '{' for defs). */
7669 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7674 c_parser_error (parser
,
7675 "method attributes must be specified at the end only");
7676 *attributes
= NULL_TREE
;
7680 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7681 *attributes
= c_parser_attributes (parser
);
7683 /* If there were no attributes here, just report any earlier error. */
7684 if (*attributes
== NULL_TREE
|| bad
)
7687 /* If the attributes are followed by a ; or {, then just report any earlier
7689 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7690 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7693 /* We've got attributes, but not at the end. */
7694 c_parser_error (parser
,
7695 "expected %<;%> or %<{%> after method attribute definition");
7699 /* Parse an objc-method-decl.
7702 ( objc-type-name ) objc-selector
7704 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7705 objc-keyword-selector objc-optparmlist
7708 objc-keyword-selector:
7710 objc-keyword-selector objc-keyword-decl
7713 objc-selector : ( objc-type-name ) identifier
7714 objc-selector : identifier
7715 : ( objc-type-name ) identifier
7719 objc-optparms objc-optellipsis
7723 objc-opt-parms , parameter-declaration
7731 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7732 tree
*attributes
, tree
*expr
)
7734 tree type
= NULL_TREE
;
7736 tree parms
= NULL_TREE
;
7737 bool ellipsis
= false;
7738 bool attr_err
= false;
7740 *attributes
= NULL_TREE
;
7741 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7743 c_parser_consume_token (parser
);
7744 type
= c_parser_objc_type_name (parser
);
7745 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7747 sel
= c_parser_objc_selector (parser
);
7748 /* If there is no selector, or a colon follows, we have an
7749 objc-keyword-selector. If there is a selector, and a colon does
7750 not follow, that selector ends the objc-method-decl. */
7751 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7754 tree list
= NULL_TREE
;
7757 tree atype
= NULL_TREE
, id
, keyworddecl
;
7758 tree param_attr
= NULL_TREE
;
7759 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7761 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7763 c_parser_consume_token (parser
);
7764 atype
= c_parser_objc_type_name (parser
);
7765 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7768 /* New ObjC allows attributes on method parameters. */
7769 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7770 param_attr
= c_parser_attributes (parser
);
7771 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7773 c_parser_error (parser
, "expected identifier");
7774 return error_mark_node
;
7776 id
= c_parser_peek_token (parser
)->value
;
7777 c_parser_consume_token (parser
);
7778 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7779 list
= chainon (list
, keyworddecl
);
7780 tsel
= c_parser_objc_selector (parser
);
7781 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7785 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7787 /* Parse the optional parameter list. Optional Objective-C
7788 method parameters follow the C syntax, and may include '...'
7789 to denote a variable number of arguments. */
7790 parms
= make_node (TREE_LIST
);
7791 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7793 struct c_parm
*parm
;
7794 c_parser_consume_token (parser
);
7795 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7798 c_parser_consume_token (parser
);
7799 attr_err
|= c_parser_objc_maybe_method_attributes
7800 (parser
, attributes
) ;
7803 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7806 parms
= chainon (parms
,
7807 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
7812 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7816 c_parser_error (parser
, "objective-c method declaration is expected");
7817 return error_mark_node
;
7821 return error_mark_node
;
7823 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7826 /* Parse an objc-type-name.
7829 objc-type-qualifiers[opt] type-name
7830 objc-type-qualifiers[opt]
7832 objc-type-qualifiers:
7834 objc-type-qualifiers objc-type-qualifier
7836 objc-type-qualifier: one of
7837 in out inout bycopy byref oneway
7841 c_parser_objc_type_name (c_parser
*parser
)
7843 tree quals
= NULL_TREE
;
7844 struct c_type_name
*type_name
= NULL
;
7845 tree type
= NULL_TREE
;
7848 c_token
*token
= c_parser_peek_token (parser
);
7849 if (token
->type
== CPP_KEYWORD
7850 && (token
->keyword
== RID_IN
7851 || token
->keyword
== RID_OUT
7852 || token
->keyword
== RID_INOUT
7853 || token
->keyword
== RID_BYCOPY
7854 || token
->keyword
== RID_BYREF
7855 || token
->keyword
== RID_ONEWAY
))
7857 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7858 c_parser_consume_token (parser
);
7863 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7864 type_name
= c_parser_type_name (parser
);
7866 type
= groktypename (type_name
, NULL
, NULL
);
7868 /* If the type is unknown, and error has already been produced and
7869 we need to recover from the error. In that case, use NULL_TREE
7870 for the type, as if no type had been specified; this will use the
7871 default type ('id') which is good for error recovery. */
7872 if (type
== error_mark_node
)
7875 return build_tree_list (quals
, type
);
7878 /* Parse objc-protocol-refs.
7885 c_parser_objc_protocol_refs (c_parser
*parser
)
7887 tree list
= NULL_TREE
;
7888 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7889 c_parser_consume_token (parser
);
7890 /* Any identifiers, including those declared as type names, are OK
7895 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7897 c_parser_error (parser
, "expected identifier");
7900 id
= c_parser_peek_token (parser
)->value
;
7901 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7902 c_parser_consume_token (parser
);
7903 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7904 c_parser_consume_token (parser
);
7908 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7912 /* Parse an objc-try-catch-finally-statement.
7914 objc-try-catch-finally-statement:
7915 @try compound-statement objc-catch-list[opt]
7916 @try compound-statement objc-catch-list[opt] @finally compound-statement
7919 @catch ( objc-catch-parameter-declaration ) compound-statement
7920 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7922 objc-catch-parameter-declaration:
7923 parameter-declaration
7926 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7928 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7929 for C++. Keep them in sync. */
7932 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
7934 location_t location
;
7937 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7938 c_parser_consume_token (parser
);
7939 location
= c_parser_peek_token (parser
)->location
;
7940 objc_maybe_warn_exceptions (location
);
7941 stmt
= c_parser_compound_statement (parser
);
7942 objc_begin_try_stmt (location
, stmt
);
7944 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7946 struct c_parm
*parm
;
7947 tree parameter_declaration
= error_mark_node
;
7948 bool seen_open_paren
= false;
7950 c_parser_consume_token (parser
);
7951 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7952 seen_open_paren
= true;
7953 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7955 /* We have "@catch (...)" (where the '...' are literally
7956 what is in the code). Skip the '...'.
7957 parameter_declaration is set to NULL_TREE, and
7958 objc_being_catch_clauses() knows that that means
7960 c_parser_consume_token (parser
);
7961 parameter_declaration
= NULL_TREE
;
7965 /* We have "@catch (NSException *exception)" or something
7966 like that. Parse the parameter declaration. */
7967 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7969 parameter_declaration
= error_mark_node
;
7971 parameter_declaration
= grokparm (parm
, NULL
);
7973 if (seen_open_paren
)
7974 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7977 /* If there was no open parenthesis, we are recovering from
7978 an error, and we are trying to figure out what mistake
7979 the user has made. */
7981 /* If there is an immediate closing parenthesis, the user
7982 probably forgot the opening one (ie, they typed "@catch
7983 NSException *e)". Parse the closing parenthesis and keep
7985 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7986 c_parser_consume_token (parser
);
7988 /* If these is no immediate closing parenthesis, the user
7989 probably doesn't know that parenthesis are required at
7990 all (ie, they typed "@catch NSException *e"). So, just
7991 forget about the closing parenthesis and keep going. */
7993 objc_begin_catch_clause (parameter_declaration
);
7994 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7995 c_parser_compound_statement_nostart (parser
);
7996 objc_finish_catch_clause ();
7998 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8000 c_parser_consume_token (parser
);
8001 location
= c_parser_peek_token (parser
)->location
;
8002 stmt
= c_parser_compound_statement (parser
);
8003 objc_build_finally_clause (location
, stmt
);
8005 objc_finish_try_stmt ();
8008 /* Parse an objc-synchronized-statement.
8010 objc-synchronized-statement:
8011 @synchronized ( expression ) compound-statement
8015 c_parser_objc_synchronized_statement (c_parser
*parser
)
8019 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8020 c_parser_consume_token (parser
);
8021 loc
= c_parser_peek_token (parser
)->location
;
8022 objc_maybe_warn_exceptions (loc
);
8023 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8025 expr
= c_parser_expression (parser
).value
;
8026 expr
= c_fully_fold (expr
, false, NULL
);
8027 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8030 expr
= error_mark_node
;
8031 stmt
= c_parser_compound_statement (parser
);
8032 objc_build_synchronized (loc
, expr
, stmt
);
8035 /* Parse an objc-selector; return NULL_TREE without an error if the
8036 next token is not an objc-selector.
8041 enum struct union if else while do for switch case default
8042 break continue return goto asm sizeof typeof __alignof
8043 unsigned long const short volatile signed restrict _Complex
8044 in out inout bycopy byref oneway int char float double void _Bool
8046 ??? Why this selection of keywords but not, for example, storage
8047 class specifiers? */
8050 c_parser_objc_selector (c_parser
*parser
)
8052 c_token
*token
= c_parser_peek_token (parser
);
8053 tree value
= token
->value
;
8054 if (token
->type
== CPP_NAME
)
8056 c_parser_consume_token (parser
);
8059 if (token
->type
!= CPP_KEYWORD
)
8061 switch (token
->keyword
)
8103 c_parser_consume_token (parser
);
8110 /* Parse an objc-selector-arg.
8114 objc-keywordname-list
8116 objc-keywordname-list:
8118 objc-keywordname-list objc-keywordname
8126 c_parser_objc_selector_arg (c_parser
*parser
)
8128 tree sel
= c_parser_objc_selector (parser
);
8129 tree list
= NULL_TREE
;
8130 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8134 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8136 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8137 sel
= c_parser_objc_selector (parser
);
8138 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8144 /* Parse an objc-receiver.
8153 c_parser_objc_receiver (c_parser
*parser
)
8155 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8156 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8157 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8159 tree id
= c_parser_peek_token (parser
)->value
;
8160 c_parser_consume_token (parser
);
8161 return objc_get_class_reference (id
);
8163 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8166 /* Parse objc-message-args.
8170 objc-keywordarg-list
8172 objc-keywordarg-list:
8174 objc-keywordarg-list objc-keywordarg
8177 objc-selector : objc-keywordexpr
8182 c_parser_objc_message_args (c_parser
*parser
)
8184 tree sel
= c_parser_objc_selector (parser
);
8185 tree list
= NULL_TREE
;
8186 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8191 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8192 return error_mark_node
;
8193 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8194 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8195 sel
= c_parser_objc_selector (parser
);
8196 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8202 /* Parse an objc-keywordexpr.
8209 c_parser_objc_keywordexpr (c_parser
*parser
)
8212 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true,
8214 if (VEC_length (tree
, expr_list
) == 1)
8216 /* Just return the expression, remove a level of
8218 ret
= VEC_index (tree
, expr_list
, 0);
8222 /* We have a comma expression, we will collapse later. */
8223 ret
= build_tree_list_vec (expr_list
);
8225 release_tree_vector (expr_list
);
8229 /* A check, needed in several places, that ObjC interface, implementation or
8230 method definitions are not prefixed by incorrect items. */
8232 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8233 struct c_declspecs
*specs
)
8235 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8236 || specs
->typespec_kind
!= ctsk_none
)
8238 c_parser_error (parser
,
8239 "no type or storage class may be specified here,");
8240 c_parser_skip_to_end_of_block_or_statement (parser
);
8246 /* Parse an Objective-C @property declaration. The syntax is:
8248 objc-property-declaration:
8249 '@property' objc-property-attributes[opt] struct-declaration ;
8251 objc-property-attributes:
8252 '(' objc-property-attribute-list ')'
8254 objc-property-attribute-list:
8255 objc-property-attribute
8256 objc-property-attribute-list, objc-property-attribute
8258 objc-property-attribute
8259 'getter' = identifier
8260 'setter' = identifier
8269 @property NSString *name;
8270 @property (readonly) id object;
8271 @property (retain, nonatomic, getter=getTheName) id name;
8272 @property int a, b, c;
8274 PS: This function is identical to cp_parser_objc_at_propery_declaration
8275 for C++. Keep them in sync. */
8277 c_parser_objc_at_property_declaration (c_parser
*parser
)
8279 /* The following variables hold the attributes of the properties as
8280 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8281 seen. When we see an attribute, we set them to 'true' (if they
8282 are boolean properties) or to the identifier (if they have an
8283 argument, ie, for getter and setter). Note that here we only
8284 parse the list of attributes, check the syntax and accumulate the
8285 attributes that we find. objc_add_property_declaration() will
8286 then process the information. */
8287 bool property_assign
= false;
8288 bool property_copy
= false;
8289 tree property_getter_ident
= NULL_TREE
;
8290 bool property_nonatomic
= false;
8291 bool property_readonly
= false;
8292 bool property_readwrite
= false;
8293 bool property_retain
= false;
8294 tree property_setter_ident
= NULL_TREE
;
8296 /* 'properties' is the list of properties that we read. Usually a
8297 single one, but maybe more (eg, in "@property int a, b, c;" there
8302 loc
= c_parser_peek_token (parser
)->location
;
8303 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8305 c_parser_consume_token (parser
); /* Eat '@property'. */
8307 /* Parse the optional attribute list... */
8308 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8311 c_parser_consume_token (parser
);
8313 /* Property attribute keywords are valid now. */
8314 parser
->objc_property_attr_context
= true;
8318 bool syntax_error
= false;
8319 c_token
*token
= c_parser_peek_token (parser
);
8322 if (token
->type
!= CPP_KEYWORD
)
8324 if (token
->type
== CPP_CLOSE_PAREN
)
8325 c_parser_error (parser
, "expected identifier");
8328 c_parser_consume_token (parser
);
8329 c_parser_error (parser
, "unknown property attribute");
8333 keyword
= token
->keyword
;
8334 c_parser_consume_token (parser
);
8337 case RID_ASSIGN
: property_assign
= true; break;
8338 case RID_COPY
: property_copy
= true; break;
8339 case RID_NONATOMIC
: property_nonatomic
= true; break;
8340 case RID_READONLY
: property_readonly
= true; break;
8341 case RID_READWRITE
: property_readwrite
= true; break;
8342 case RID_RETAIN
: property_retain
= true; break;
8346 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8348 if (keyword
== RID_GETTER
)
8349 c_parser_error (parser
,
8350 "missing %<=%> (after %<getter%> attribute)");
8352 c_parser_error (parser
,
8353 "missing %<=%> (after %<setter%> attribute)");
8354 syntax_error
= true;
8357 c_parser_consume_token (parser
); /* eat the = */
8358 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8360 c_parser_error (parser
, "expected identifier");
8361 syntax_error
= true;
8364 if (keyword
== RID_SETTER
)
8366 if (property_setter_ident
!= NULL_TREE
)
8367 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8369 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8370 c_parser_consume_token (parser
);
8371 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8372 c_parser_error (parser
, "setter name must terminate with %<:%>");
8374 c_parser_consume_token (parser
);
8378 if (property_getter_ident
!= NULL_TREE
)
8379 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8381 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8382 c_parser_consume_token (parser
);
8386 c_parser_error (parser
, "unknown property attribute");
8387 syntax_error
= true;
8394 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8395 c_parser_consume_token (parser
);
8399 parser
->objc_property_attr_context
= false;
8400 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8402 /* ... and the property declaration(s). */
8403 properties
= c_parser_struct_declaration (parser
);
8405 if (properties
== error_mark_node
)
8407 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8408 parser
->error
= false;
8412 if (properties
== NULL_TREE
)
8413 c_parser_error (parser
, "expected identifier");
8416 /* Comma-separated properties are chained together in
8417 reverse order; add them one by one. */
8418 properties
= nreverse (properties
);
8420 for (; properties
; properties
= TREE_CHAIN (properties
))
8421 objc_add_property_declaration (loc
, copy_node (properties
),
8422 property_readonly
, property_readwrite
,
8423 property_assign
, property_retain
,
8424 property_copy
, property_nonatomic
,
8425 property_getter_ident
, property_setter_ident
);
8428 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8429 parser
->error
= false;
8432 /* Parse an Objective-C @synthesize declaration. The syntax is:
8434 objc-synthesize-declaration:
8435 @synthesize objc-synthesize-identifier-list ;
8437 objc-synthesize-identifier-list:
8438 objc-synthesize-identifier
8439 objc-synthesize-identifier-list, objc-synthesize-identifier
8441 objc-synthesize-identifier
8443 identifier = identifier
8446 @synthesize MyProperty;
8447 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8449 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8450 for C++. Keep them in sync.
8453 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8455 tree list
= NULL_TREE
;
8457 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8458 loc
= c_parser_peek_token (parser
)->location
;
8460 c_parser_consume_token (parser
);
8463 tree property
, ivar
;
8464 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8466 c_parser_error (parser
, "expected identifier");
8467 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8468 /* Once we find the semicolon, we can resume normal parsing.
8469 We have to reset parser->error manually because
8470 c_parser_skip_until_found() won't reset it for us if the
8471 next token is precisely a semicolon. */
8472 parser
->error
= false;
8475 property
= c_parser_peek_token (parser
)->value
;
8476 c_parser_consume_token (parser
);
8477 if (c_parser_next_token_is (parser
, CPP_EQ
))
8479 c_parser_consume_token (parser
);
8480 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8482 c_parser_error (parser
, "expected identifier");
8483 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8484 parser
->error
= false;
8487 ivar
= c_parser_peek_token (parser
)->value
;
8488 c_parser_consume_token (parser
);
8492 list
= chainon (list
, build_tree_list (ivar
, property
));
8493 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8494 c_parser_consume_token (parser
);
8498 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8499 objc_add_synthesize_declaration (loc
, list
);
8502 /* Parse an Objective-C @dynamic declaration. The syntax is:
8504 objc-dynamic-declaration:
8505 @dynamic identifier-list ;
8508 @dynamic MyProperty;
8509 @dynamic MyProperty, AnotherProperty;
8511 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8512 for C++. Keep them in sync.
8515 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8517 tree list
= NULL_TREE
;
8519 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8520 loc
= c_parser_peek_token (parser
)->location
;
8522 c_parser_consume_token (parser
);
8526 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8528 c_parser_error (parser
, "expected identifier");
8529 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8530 parser
->error
= false;
8533 property
= c_parser_peek_token (parser
)->value
;
8534 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8535 c_parser_consume_token (parser
);
8536 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8537 c_parser_consume_token (parser
);
8541 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8542 objc_add_dynamic_declaration (loc
, list
);
8546 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8547 should be considered, statements. ALLOW_STMT is true if we're within
8548 the context of a function and such pragmas are to be allowed. Returns
8549 true if we actually parsed such a pragma. */
8552 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8556 id
= c_parser_peek_token (parser
)->pragma_kind
;
8557 gcc_assert (id
!= PRAGMA_NONE
);
8561 case PRAGMA_OMP_BARRIER
:
8562 if (context
!= pragma_compound
)
8564 if (context
== pragma_stmt
)
8565 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8566 "used in compound statements");
8569 c_parser_omp_barrier (parser
);
8572 case PRAGMA_OMP_FLUSH
:
8573 if (context
!= pragma_compound
)
8575 if (context
== pragma_stmt
)
8576 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8577 "used in compound statements");
8580 c_parser_omp_flush (parser
);
8583 case PRAGMA_OMP_TASKWAIT
:
8584 if (context
!= pragma_compound
)
8586 if (context
== pragma_stmt
)
8587 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8588 "used in compound statements");
8591 c_parser_omp_taskwait (parser
);
8594 case PRAGMA_OMP_TASKYIELD
:
8595 if (context
!= pragma_compound
)
8597 if (context
== pragma_stmt
)
8598 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
8599 "used in compound statements");
8602 c_parser_omp_taskyield (parser
);
8605 case PRAGMA_OMP_THREADPRIVATE
:
8606 c_parser_omp_threadprivate (parser
);
8609 case PRAGMA_OMP_SECTION
:
8610 error_at (c_parser_peek_token (parser
)->location
,
8611 "%<#pragma omp section%> may only be used in "
8612 "%<#pragma omp sections%> construct");
8613 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8616 case PRAGMA_GCC_PCH_PREPROCESS
:
8617 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8618 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8622 if (id
< PRAGMA_FIRST_EXTERNAL
)
8624 if (context
== pragma_external
)
8627 c_parser_error (parser
, "expected declaration specifiers");
8628 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8631 c_parser_omp_construct (parser
);
8637 c_parser_consume_pragma (parser
);
8638 c_invoke_pragma_handler (id
);
8640 /* Skip to EOL, but suppress any error message. Those will have been
8641 generated by the handler routine through calling error, as opposed
8642 to calling c_parser_error. */
8643 parser
->error
= true;
8644 c_parser_skip_to_pragma_eol (parser
);
8649 /* The interface the pragma parsers have to the lexer. */
8652 pragma_lex (tree
*value
)
8654 c_token
*tok
= c_parser_peek_token (the_parser
);
8655 enum cpp_ttype ret
= tok
->type
;
8657 *value
= tok
->value
;
8658 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8662 if (ret
== CPP_KEYWORD
)
8664 c_parser_consume_token (the_parser
);
8671 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8675 c_parser_consume_pragma (parser
);
8676 if (c_parser_next_token_is (parser
, CPP_STRING
))
8678 name
= c_parser_peek_token (parser
)->value
;
8679 c_parser_consume_token (parser
);
8682 c_parser_error (parser
, "expected string literal");
8683 c_parser_skip_to_pragma_eol (parser
);
8686 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8689 /* OpenMP 2.5 parsing routines. */
8691 /* Returns name of the next clause.
8692 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8693 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8694 returned and the token is consumed. */
8696 static pragma_omp_clause
8697 c_parser_omp_clause_name (c_parser
*parser
)
8699 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8701 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8702 result
= PRAGMA_OMP_CLAUSE_IF
;
8703 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8704 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8705 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8707 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8712 if (!strcmp ("collapse", p
))
8713 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8714 else if (!strcmp ("copyin", p
))
8715 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8716 else if (!strcmp ("copyprivate", p
))
8717 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8720 if (!strcmp ("final", p
))
8721 result
= PRAGMA_OMP_CLAUSE_FINAL
;
8722 else if (!strcmp ("firstprivate", p
))
8723 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8726 if (!strcmp ("lastprivate", p
))
8727 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8730 if (!strcmp ("mergeable", p
))
8731 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
8734 if (!strcmp ("nowait", p
))
8735 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8736 else if (!strcmp ("num_threads", p
))
8737 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8740 if (!strcmp ("ordered", p
))
8741 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8744 if (!strcmp ("private", p
))
8745 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8748 if (!strcmp ("reduction", p
))
8749 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8752 if (!strcmp ("schedule", p
))
8753 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8754 else if (!strcmp ("shared", p
))
8755 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8758 if (!strcmp ("untied", p
))
8759 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8764 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8765 c_parser_consume_token (parser
);
8770 /* Validate that a clause of the given type does not already exist. */
8773 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8778 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8779 if (OMP_CLAUSE_CODE (c
) == code
)
8781 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8782 error_at (loc
, "too many %qs clauses", name
);
8790 variable-list , identifier
8792 If KIND is nonzero, create the appropriate node and install the
8793 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8794 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8796 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8797 return the list created. */
8800 c_parser_omp_variable_list (c_parser
*parser
,
8801 location_t clause_loc
,
8802 enum omp_clause_code kind
,
8805 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8806 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8807 c_parser_error (parser
, "expected identifier");
8809 while (c_parser_next_token_is (parser
, CPP_NAME
)
8810 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8812 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8815 undeclared_variable (c_parser_peek_token (parser
)->location
,
8816 c_parser_peek_token (parser
)->value
);
8817 else if (t
== error_mark_node
)
8821 tree u
= build_omp_clause (clause_loc
, kind
);
8822 OMP_CLAUSE_DECL (u
) = t
;
8823 OMP_CLAUSE_CHAIN (u
) = list
;
8827 list
= tree_cons (t
, NULL_TREE
, list
);
8829 c_parser_consume_token (parser
);
8831 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8834 c_parser_consume_token (parser
);
8840 /* Similarly, but expect leading and trailing parenthesis. This is a very
8841 common case for omp clauses. */
8844 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8847 /* The clauses location. */
8848 location_t loc
= c_parser_peek_token (parser
)->location
;
8850 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8852 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8853 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8859 collapse ( constant-expression ) */
8862 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8864 tree c
, num
= error_mark_node
;
8868 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8870 loc
= c_parser_peek_token (parser
)->location
;
8871 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8873 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8876 if (num
== error_mark_node
)
8878 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8879 || !host_integerp (num
, 0)
8880 || (n
= tree_low_cst (num
, 0)) <= 0
8884 "collapse argument needs positive constant integer expression");
8887 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8888 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
8889 OMP_CLAUSE_CHAIN (c
) = list
;
8894 copyin ( variable-list ) */
8897 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
8899 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
8903 copyprivate ( variable-list ) */
8906 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
8908 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
8912 default ( shared | none ) */
8915 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
8917 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
8918 location_t loc
= c_parser_peek_token (parser
)->location
;
8921 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8923 if (c_parser_next_token_is (parser
, CPP_NAME
))
8925 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8930 if (strcmp ("none", p
) != 0)
8932 kind
= OMP_CLAUSE_DEFAULT_NONE
;
8936 if (strcmp ("shared", p
) != 0)
8938 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
8945 c_parser_consume_token (parser
);
8950 c_parser_error (parser
, "expected %<none%> or %<shared%>");
8952 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8954 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
8957 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
8958 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
8959 OMP_CLAUSE_CHAIN (c
) = list
;
8960 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
8966 firstprivate ( variable-list ) */
8969 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
8971 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
8975 final ( expression ) */
8978 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
8980 location_t loc
= c_parser_peek_token (parser
)->location
;
8981 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8983 tree t
= c_parser_paren_condition (parser
);
8986 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
8988 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
8989 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
8990 OMP_CLAUSE_CHAIN (c
) = list
;
8994 c_parser_error (parser
, "expected %<(%>");
9000 if ( expression ) */
9003 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9005 location_t loc
= c_parser_peek_token (parser
)->location
;
9006 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9008 tree t
= c_parser_paren_condition (parser
);
9011 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9013 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9014 OMP_CLAUSE_IF_EXPR (c
) = t
;
9015 OMP_CLAUSE_CHAIN (c
) = list
;
9019 c_parser_error (parser
, "expected %<(%>");
9025 lastprivate ( variable-list ) */
9028 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9030 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9037 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9041 /* FIXME: Should we allow duplicates? */
9042 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9044 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9045 OMP_CLAUSE_MERGEABLE
);
9046 OMP_CLAUSE_CHAIN (c
) = list
;
9055 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9058 location_t loc
= c_parser_peek_token (parser
)->location
;
9060 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9062 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9063 OMP_CLAUSE_CHAIN (c
) = list
;
9068 num_threads ( expression ) */
9071 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9073 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9074 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9076 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9077 tree c
, t
= c_parser_expression (parser
).value
;
9079 t
= c_fully_fold (t
, false, NULL
);
9081 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9083 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9085 c_parser_error (parser
, "expected integer expression");
9089 /* Attempt to statically determine when the number isn't positive. */
9090 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9091 build_int_cst (TREE_TYPE (t
), 0));
9092 if (CAN_HAVE_LOCATION_P (c
))
9093 SET_EXPR_LOCATION (c
, expr_loc
);
9094 if (c
== boolean_true_node
)
9096 warning_at (expr_loc
, 0,
9097 "%<num_threads%> value must be positive");
9098 t
= integer_one_node
;
9101 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9103 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9104 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9105 OMP_CLAUSE_CHAIN (c
) = list
;
9116 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9120 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9122 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9123 OMP_CLAUSE_ORDERED
);
9124 OMP_CLAUSE_CHAIN (c
) = list
;
9130 private ( variable-list ) */
9133 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9135 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9139 reduction ( reduction-operator : variable-list )
9142 One of: + * - & ^ | && ||
9147 One of: + * - & ^ | && || max min */
9150 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9152 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9153 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9155 enum tree_code code
;
9157 switch (c_parser_peek_token (parser
)->type
)
9169 code
= BIT_AND_EXPR
;
9172 code
= BIT_XOR_EXPR
;
9175 code
= BIT_IOR_EXPR
;
9178 code
= TRUTH_ANDIF_EXPR
;
9181 code
= TRUTH_ORIF_EXPR
;
9186 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9187 if (strcmp (p
, "min") == 0)
9192 if (strcmp (p
, "max") == 0)
9200 c_parser_error (parser
,
9201 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9202 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9203 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9206 c_parser_consume_token (parser
);
9207 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9211 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9212 OMP_CLAUSE_REDUCTION
, list
);
9213 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9214 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9218 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9224 schedule ( schedule-kind )
9225 schedule ( schedule-kind , expression )
9228 static | dynamic | guided | runtime | auto
9232 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9235 location_t loc
= c_parser_peek_token (parser
)->location
;
9237 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9240 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9242 if (c_parser_next_token_is (parser
, CPP_NAME
))
9244 tree kind
= c_parser_peek_token (parser
)->value
;
9245 const char *p
= IDENTIFIER_POINTER (kind
);
9250 if (strcmp ("dynamic", p
) != 0)
9252 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9256 if (strcmp ("guided", p
) != 0)
9258 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9262 if (strcmp ("runtime", p
) != 0)
9264 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9271 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9272 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9273 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9274 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9278 c_parser_consume_token (parser
);
9279 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9282 c_parser_consume_token (parser
);
9284 here
= c_parser_peek_token (parser
)->location
;
9285 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9287 t
= c_fully_fold (t
, false, NULL
);
9289 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9290 error_at (here
, "schedule %<runtime%> does not take "
9291 "a %<chunk_size%> parameter");
9292 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9294 "schedule %<auto%> does not take "
9295 "a %<chunk_size%> parameter");
9296 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9297 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9299 c_parser_error (parser
, "expected integer expression");
9301 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9305 "expected %<,%> or %<)%>");
9307 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9308 OMP_CLAUSE_CHAIN (c
) = list
;
9312 c_parser_error (parser
, "invalid schedule kind");
9313 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9318 shared ( variable-list ) */
9321 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9323 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9330 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9334 /* FIXME: Should we allow duplicates? */
9335 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9337 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9339 OMP_CLAUSE_CHAIN (c
) = list
;
9344 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9345 is a bitmask in MASK. Return the list of clauses found; the result
9346 of clause default goes in *pdefault. */
9349 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9352 tree clauses
= NULL
;
9355 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9358 pragma_omp_clause c_kind
;
9360 tree prev
= clauses
;
9362 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9363 c_parser_consume_token (parser
);
9366 here
= c_parser_peek_token (parser
)->location
;
9367 c_kind
= c_parser_omp_clause_name (parser
);
9371 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9372 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9373 c_name
= "collapse";
9375 case PRAGMA_OMP_CLAUSE_COPYIN
:
9376 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9379 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9380 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9381 c_name
= "copyprivate";
9383 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9384 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9387 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9388 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9389 c_name
= "firstprivate";
9391 case PRAGMA_OMP_CLAUSE_FINAL
:
9392 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9395 case PRAGMA_OMP_CLAUSE_IF
:
9396 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9399 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9400 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9401 c_name
= "lastprivate";
9403 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9404 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9405 c_name
= "mergeable";
9407 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9408 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9411 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9412 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9413 c_name
= "num_threads";
9415 case PRAGMA_OMP_CLAUSE_ORDERED
:
9416 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9419 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9420 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9423 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9424 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9425 c_name
= "reduction";
9427 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9428 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9429 c_name
= "schedule";
9431 case PRAGMA_OMP_CLAUSE_SHARED
:
9432 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9435 case PRAGMA_OMP_CLAUSE_UNTIED
:
9436 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9440 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9444 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9446 /* Remove the invalid clause(s) from the list to avoid
9447 confusing the rest of the compiler. */
9449 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9454 c_parser_skip_to_pragma_eol (parser
);
9456 return c_finish_omp_clauses (clauses
);
9463 In practice, we're also interested in adding the statement to an
9464 outer node. So it is convenient if we work around the fact that
9465 c_parser_statement calls add_stmt. */
9468 c_parser_omp_structured_block (c_parser
*parser
)
9470 tree stmt
= push_stmt_list ();
9471 c_parser_statement (parser
);
9472 return pop_stmt_list (stmt
);
9476 # pragma omp atomic new-line
9480 x binop= expr | x++ | ++x | x-- | --x
9482 +, *, -, /, &, ^, |, <<, >>
9484 where x is an lvalue expression with scalar type.
9487 # pragma omp atomic new-line
9490 # pragma omp atomic read new-line
9493 # pragma omp atomic write new-line
9496 # pragma omp atomic update new-line
9499 # pragma omp atomic capture new-line
9502 # pragma omp atomic capture new-line
9510 expression-stmt | x = x binop expr
9512 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9514 { v = x; update-stmt; } | { update-stmt; v = x; }
9516 where x and v are lvalue expressions with scalar type.
9518 LOC is the location of the #pragma token. */
9521 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9523 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9524 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9525 tree stmt
, orig_lhs
;
9526 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9527 struct c_expr rhs_expr
;
9528 bool structured_block
= false;
9530 if (c_parser_next_token_is (parser
, CPP_NAME
))
9532 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9534 if (!strcmp (p
, "read"))
9535 code
= OMP_ATOMIC_READ
;
9536 else if (!strcmp (p
, "write"))
9538 else if (!strcmp (p
, "update"))
9540 else if (!strcmp (p
, "capture"))
9541 code
= OMP_ATOMIC_CAPTURE_NEW
;
9545 c_parser_consume_token (parser
);
9547 c_parser_skip_to_pragma_eol (parser
);
9551 case OMP_ATOMIC_READ
:
9552 case NOP_EXPR
: /* atomic write */
9553 v
= c_parser_unary_expression (parser
).value
;
9554 v
= c_fully_fold (v
, false, NULL
);
9555 if (v
== error_mark_node
)
9557 loc
= c_parser_peek_token (parser
)->location
;
9558 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9560 if (code
== NOP_EXPR
)
9561 lhs
= c_parser_expression (parser
).value
;
9563 lhs
= c_parser_unary_expression (parser
).value
;
9564 lhs
= c_fully_fold (lhs
, false, NULL
);
9565 if (lhs
== error_mark_node
)
9567 if (code
== NOP_EXPR
)
9569 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9577 case OMP_ATOMIC_CAPTURE_NEW
:
9578 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9580 c_parser_consume_token (parser
);
9581 structured_block
= true;
9585 v
= c_parser_unary_expression (parser
).value
;
9586 v
= c_fully_fold (v
, false, NULL
);
9587 if (v
== error_mark_node
)
9589 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9597 /* For structured_block case we don't know yet whether
9598 old or new x should be captured. */
9600 lhs
= c_parser_unary_expression (parser
).value
;
9601 lhs
= c_fully_fold (lhs
, false, NULL
);
9603 switch (TREE_CODE (lhs
))
9607 c_parser_skip_to_end_of_block_or_statement (parser
);
9608 if (structured_block
)
9610 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9611 c_parser_consume_token (parser
);
9612 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9614 c_parser_skip_to_end_of_block_or_statement (parser
);
9615 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9616 c_parser_consume_token (parser
);
9621 case POSTINCREMENT_EXPR
:
9622 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9623 code
= OMP_ATOMIC_CAPTURE_OLD
;
9625 case PREINCREMENT_EXPR
:
9626 lhs
= TREE_OPERAND (lhs
, 0);
9628 rhs
= integer_one_node
;
9631 case POSTDECREMENT_EXPR
:
9632 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9633 code
= OMP_ATOMIC_CAPTURE_OLD
;
9635 case PREDECREMENT_EXPR
:
9636 lhs
= TREE_OPERAND (lhs
, 0);
9637 opcode
= MINUS_EXPR
;
9638 rhs
= integer_one_node
;
9642 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9643 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9644 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9645 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9646 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9647 (TREE_OPERAND (lhs
, 1), 0), 0)))
9649 /* Undo effects of boolean_increment for post {in,de}crement. */
9650 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9653 if (TREE_CODE (lhs
) == MODIFY_EXPR
9654 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9656 /* Undo effects of boolean_increment. */
9657 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9659 /* This is pre or post increment. */
9660 rhs
= TREE_OPERAND (lhs
, 1);
9661 lhs
= TREE_OPERAND (lhs
, 0);
9663 if (code
== OMP_ATOMIC_CAPTURE_NEW
9664 && !structured_block
9665 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9666 code
= OMP_ATOMIC_CAPTURE_OLD
;
9669 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9670 && TREE_OPERAND (lhs
, 0)
9671 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9673 /* This is pre or post decrement. */
9674 rhs
= TREE_OPERAND (lhs
, 1);
9675 lhs
= TREE_OPERAND (lhs
, 0);
9677 if (code
== OMP_ATOMIC_CAPTURE_NEW
9678 && !structured_block
9679 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9680 code
= OMP_ATOMIC_CAPTURE_OLD
;
9686 switch (c_parser_peek_token (parser
)->type
)
9692 opcode
= TRUNC_DIV_EXPR
;
9698 opcode
= MINUS_EXPR
;
9701 opcode
= LSHIFT_EXPR
;
9704 opcode
= RSHIFT_EXPR
;
9707 opcode
= BIT_AND_EXPR
;
9710 opcode
= BIT_IOR_EXPR
;
9713 opcode
= BIT_XOR_EXPR
;
9716 if (structured_block
|| code
== OMP_ATOMIC
)
9718 location_t aloc
= c_parser_peek_token (parser
)->location
;
9720 enum c_parser_prec oprec
= PREC_NONE
;
9722 c_parser_consume_token (parser
);
9723 rhs1
= c_parser_unary_expression (parser
).value
;
9724 rhs1
= c_fully_fold (rhs1
, false, NULL
);
9725 if (rhs1
== error_mark_node
)
9727 switch (c_parser_peek_token (parser
)->type
)
9730 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9732 code
= OMP_ATOMIC_CAPTURE_OLD
;
9737 c_parser_consume_token (parser
);
9740 c_parser_error (parser
,
9741 "invalid form of %<#pragma omp atomic%>");
9748 opcode
= TRUNC_DIV_EXPR
;
9756 opcode
= MINUS_EXPR
;
9760 opcode
= LSHIFT_EXPR
;
9764 opcode
= RSHIFT_EXPR
;
9768 opcode
= BIT_AND_EXPR
;
9769 oprec
= PREC_BITAND
;
9772 opcode
= BIT_IOR_EXPR
;
9776 opcode
= BIT_XOR_EXPR
;
9777 oprec
= PREC_BITXOR
;
9780 c_parser_error (parser
,
9781 "invalid operator for %<#pragma omp atomic%>");
9785 c_parser_consume_token (parser
);
9786 rhs_loc
= c_parser_peek_token (parser
)->location
;
9787 if (commutative_tree_code (opcode
))
9788 oprec
= (enum c_parser_prec
) (oprec
- 1);
9789 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
9790 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
9792 rhs
= rhs_expr
.value
;
9793 rhs
= c_fully_fold (rhs
, false, NULL
);
9798 c_parser_error (parser
,
9799 "invalid operator for %<#pragma omp atomic%>");
9803 /* Arrange to pass the location of the assignment operator to
9804 c_finish_omp_atomic. */
9805 loc
= c_parser_peek_token (parser
)->location
;
9806 c_parser_consume_token (parser
);
9808 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9809 rhs_expr
= c_parser_expression (parser
);
9810 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9812 rhs
= rhs_expr
.value
;
9813 rhs
= c_fully_fold (rhs
, false, NULL
);
9817 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
9819 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
9821 v
= c_parser_unary_expression (parser
).value
;
9822 v
= c_fully_fold (v
, false, NULL
);
9823 if (v
== error_mark_node
)
9825 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9827 lhs1
= c_parser_unary_expression (parser
).value
;
9828 lhs1
= c_fully_fold (lhs1
, false, NULL
);
9829 if (lhs1
== error_mark_node
)
9832 if (structured_block
)
9834 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9835 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
9838 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
9839 if (stmt
!= error_mark_node
)
9842 if (!structured_block
)
9843 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9848 # pragma omp barrier new-line
9852 c_parser_omp_barrier (c_parser
*parser
)
9854 location_t loc
= c_parser_peek_token (parser
)->location
;
9855 c_parser_consume_pragma (parser
);
9856 c_parser_skip_to_pragma_eol (parser
);
9858 c_finish_omp_barrier (loc
);
9862 # pragma omp critical [(name)] new-line
9865 LOC is the location of the #pragma itself. */
9868 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9870 tree stmt
, name
= NULL
;
9872 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9874 c_parser_consume_token (parser
);
9875 if (c_parser_next_token_is (parser
, CPP_NAME
))
9877 name
= c_parser_peek_token (parser
)->value
;
9878 c_parser_consume_token (parser
);
9879 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9882 c_parser_error (parser
, "expected identifier");
9884 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9885 c_parser_error (parser
, "expected %<(%> or end of line");
9886 c_parser_skip_to_pragma_eol (parser
);
9888 stmt
= c_parser_omp_structured_block (parser
);
9889 return c_finish_omp_critical (loc
, stmt
, name
);
9893 # pragma omp flush flush-vars[opt] new-line
9896 ( variable-list ) */
9899 c_parser_omp_flush (c_parser
*parser
)
9901 location_t loc
= c_parser_peek_token (parser
)->location
;
9902 c_parser_consume_pragma (parser
);
9903 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9904 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9905 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9906 c_parser_error (parser
, "expected %<(%> or end of line");
9907 c_parser_skip_to_pragma_eol (parser
);
9909 c_finish_omp_flush (loc
);
9912 /* Parse the restricted form of the for statement allowed by OpenMP.
9913 The real trick here is to determine the loop control variable early
9914 so that we can push a new decl if necessary to make it private.
9915 LOC is the location of the OMP in "#pragma omp". */
9918 c_parser_omp_for_loop (location_t loc
,
9919 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
9921 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
9922 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
9923 bool fail
= false, open_brace_parsed
= false;
9924 int i
, collapse
= 1, nbraces
= 0;
9926 VEC(tree
,gc
) *for_block
= make_tree_vector ();
9928 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
9929 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
9930 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
9932 gcc_assert (collapse
>= 1);
9934 declv
= make_tree_vec (collapse
);
9935 initv
= make_tree_vec (collapse
);
9936 condv
= make_tree_vec (collapse
);
9937 incrv
= make_tree_vec (collapse
);
9939 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
9941 c_parser_error (parser
, "for statement expected");
9944 for_loc
= c_parser_peek_token (parser
)->location
;
9945 c_parser_consume_token (parser
);
9947 for (i
= 0; i
< collapse
; i
++)
9951 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9954 /* Parse the initialization declaration or expression. */
9955 if (c_parser_next_tokens_start_declaration (parser
))
9958 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
9959 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
9960 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
9963 if (DECL_INITIAL (decl
) == error_mark_node
)
9964 decl
= error_mark_node
;
9967 else if (c_parser_next_token_is (parser
, CPP_NAME
)
9968 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
9970 struct c_expr decl_exp
;
9971 struct c_expr init_exp
;
9972 location_t init_loc
;
9974 decl_exp
= c_parser_postfix_expression (parser
);
9975 decl
= decl_exp
.value
;
9977 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
9979 init_loc
= c_parser_peek_token (parser
)->location
;
9980 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
9981 init_exp
= default_function_array_read_conversion (init_loc
,
9983 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
9984 NOP_EXPR
, init_loc
, init_exp
.value
,
9985 init_exp
.original_type
);
9986 init
= c_process_expr_stmt (init_loc
, init
);
9988 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9993 c_parser_error (parser
,
9994 "expected iteration declaration or initialization");
9995 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10001 /* Parse the loop condition. */
10003 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
10005 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
10006 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
10009 cond
= cond_expr
.value
;
10010 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
10011 cond
= c_fully_fold (cond
, false, NULL
);
10012 switch (cond_expr
.original_code
)
10020 /* Can't be cond = error_mark_node, because we want to preserve
10021 the location until c_finish_omp_for. */
10022 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
10025 protected_set_expr_location (cond
, cond_loc
);
10027 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10029 /* Parse the increment expression. */
10031 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
10033 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
10035 incr
= c_process_expr_stmt (incr_loc
,
10036 c_parser_expression (parser
).value
);
10038 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10040 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
10044 TREE_VEC_ELT (declv
, i
) = decl
;
10045 TREE_VEC_ELT (initv
, i
) = init
;
10046 TREE_VEC_ELT (condv
, i
) = cond
;
10047 TREE_VEC_ELT (incrv
, i
) = incr
;
10051 if (i
== collapse
- 1)
10054 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10055 in between the collapsed for loops to be still considered perfectly
10056 nested. Hopefully the final version clarifies this.
10057 For now handle (multiple) {'s and empty statements. */
10060 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10062 c_parser_consume_token (parser
);
10065 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10067 c_parser_consume_token (parser
);
10070 else if (bracecount
10071 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10072 c_parser_consume_token (parser
);
10075 c_parser_error (parser
, "not enough perfectly nested loops");
10078 open_brace_parsed
= true;
10088 nbraces
+= bracecount
;
10091 save_break
= c_break_label
;
10092 c_break_label
= size_one_node
;
10093 save_cont
= c_cont_label
;
10094 c_cont_label
= NULL_TREE
;
10095 body
= push_stmt_list ();
10097 if (open_brace_parsed
)
10099 location_t here
= c_parser_peek_token (parser
)->location
;
10100 stmt
= c_begin_compound_stmt (true);
10101 c_parser_compound_statement_nostart (parser
);
10102 add_stmt (c_end_compound_stmt (here
, stmt
, true));
10105 add_stmt (c_parser_c99_block_statement (parser
));
10108 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
10109 SET_EXPR_LOCATION (t
, loc
);
10113 body
= pop_stmt_list (body
);
10114 c_break_label
= save_break
;
10115 c_cont_label
= save_cont
;
10119 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10121 c_parser_consume_token (parser
);
10124 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10125 c_parser_consume_token (parser
);
10128 c_parser_error (parser
, "collapsed loops not perfectly nested");
10131 location_t here
= c_parser_peek_token (parser
)->location
;
10132 stmt
= c_begin_compound_stmt (true);
10134 c_parser_compound_statement_nostart (parser
);
10135 body
= c_end_compound_stmt (here
, stmt
, true);
10142 /* Only bother calling c_finish_omp_for if we haven't already generated
10143 an error from the initialization parsing. */
10146 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
10149 if (par_clauses
!= NULL
)
10152 for (c
= par_clauses
; *c
; )
10153 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
10154 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
10155 c
= &OMP_CLAUSE_CHAIN (*c
);
10158 for (i
= 0; i
< collapse
; i
++)
10159 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
10162 c
= &OMP_CLAUSE_CHAIN (*c
);
10163 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
10166 "iteration variable %qD should not be firstprivate",
10167 OMP_CLAUSE_DECL (*c
));
10168 *c
= OMP_CLAUSE_CHAIN (*c
);
10172 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10173 change it to shared (decl) in
10174 OMP_PARALLEL_CLAUSES. */
10175 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
10176 OMP_CLAUSE_LASTPRIVATE
);
10177 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
10178 OMP_CLAUSE_CHAIN (l
) = clauses
;
10180 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
10184 OMP_FOR_CLAUSES (stmt
) = clauses
;
10189 while (!VEC_empty (tree
, for_block
))
10191 /* FIXME diagnostics: LOC below should be the actual location of
10192 this particular for block. We need to build a list of
10193 locations to go along with FOR_BLOCK. */
10194 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
10197 release_tree_vector (for_block
);
10202 #pragma omp for for-clause[optseq] new-line
10205 LOC is the location of the #pragma token.
10208 #define OMP_FOR_CLAUSE_MASK \
10209 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10210 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10211 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10212 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10213 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10214 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10215 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10216 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10219 c_parser_omp_for (location_t loc
, c_parser
*parser
)
10221 tree block
, clauses
, ret
;
10223 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
10224 "#pragma omp for");
10226 block
= c_begin_compound_stmt (true);
10227 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
10228 block
= c_end_compound_stmt (loc
, block
, true);
10235 # pragma omp master new-line
10238 LOC is the location of the #pragma token.
10242 c_parser_omp_master (location_t loc
, c_parser
*parser
)
10244 c_parser_skip_to_pragma_eol (parser
);
10245 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
10249 # pragma omp ordered new-line
10252 LOC is the location of the #pragma itself.
10256 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
10258 c_parser_skip_to_pragma_eol (parser
);
10259 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
10265 { section-sequence }
10268 section-directive[opt] structured-block
10269 section-sequence section-directive structured-block
10271 SECTIONS_LOC is the location of the #pragma omp sections. */
10274 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
10276 tree stmt
, substmt
;
10277 bool error_suppress
= false;
10280 loc
= c_parser_peek_token (parser
)->location
;
10281 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10283 /* Avoid skipping until the end of the block. */
10284 parser
->error
= false;
10288 stmt
= push_stmt_list ();
10290 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10292 substmt
= push_stmt_list ();
10296 c_parser_statement (parser
);
10298 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10300 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10302 if (c_parser_next_token_is (parser
, CPP_EOF
))
10306 substmt
= pop_stmt_list (substmt
);
10307 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10308 SET_EXPR_LOCATION (substmt
, loc
);
10309 add_stmt (substmt
);
10314 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10316 if (c_parser_next_token_is (parser
, CPP_EOF
))
10319 loc
= c_parser_peek_token (parser
)->location
;
10320 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10322 c_parser_consume_pragma (parser
);
10323 c_parser_skip_to_pragma_eol (parser
);
10324 error_suppress
= false;
10326 else if (!error_suppress
)
10328 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10329 error_suppress
= true;
10332 substmt
= c_parser_omp_structured_block (parser
);
10333 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10334 SET_EXPR_LOCATION (substmt
, loc
);
10335 add_stmt (substmt
);
10337 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10338 "expected %<#pragma omp section%> or %<}%>");
10340 substmt
= pop_stmt_list (stmt
);
10342 stmt
= make_node (OMP_SECTIONS
);
10343 SET_EXPR_LOCATION (stmt
, sections_loc
);
10344 TREE_TYPE (stmt
) = void_type_node
;
10345 OMP_SECTIONS_BODY (stmt
) = substmt
;
10347 return add_stmt (stmt
);
10351 # pragma omp sections sections-clause[optseq] newline
10354 LOC is the location of the #pragma token.
10357 #define OMP_SECTIONS_CLAUSE_MASK \
10358 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10359 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10360 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10361 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10362 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10365 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10367 tree block
, clauses
, ret
;
10369 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10370 "#pragma omp sections");
10372 block
= c_begin_compound_stmt (true);
10373 ret
= c_parser_omp_sections_scope (loc
, parser
);
10375 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10376 block
= c_end_compound_stmt (loc
, block
, true);
10383 # pragma parallel parallel-clause new-line
10384 # pragma parallel for parallel-for-clause new-line
10385 # pragma parallel sections parallel-sections-clause new-line
10387 LOC is the location of the #pragma token.
10390 #define OMP_PARALLEL_CLAUSE_MASK \
10391 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10392 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10393 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10394 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10395 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10396 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10397 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10398 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10401 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10403 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10404 const char *p_name
= "#pragma omp parallel";
10405 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10406 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10408 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10410 c_parser_consume_token (parser
);
10411 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10412 p_name
= "#pragma omp parallel for";
10413 mask
|= OMP_FOR_CLAUSE_MASK
;
10414 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10416 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10418 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10419 if (strcmp (p
, "sections") == 0)
10421 c_parser_consume_token (parser
);
10422 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10423 p_name
= "#pragma omp parallel sections";
10424 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10425 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10429 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10433 case PRAGMA_OMP_PARALLEL
:
10434 block
= c_begin_omp_parallel ();
10435 c_parser_statement (parser
);
10436 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10439 case PRAGMA_OMP_PARALLEL_FOR
:
10440 block
= c_begin_omp_parallel ();
10441 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10442 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10443 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10444 OMP_PARALLEL_COMBINED (stmt
) = 1;
10447 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10448 block
= c_begin_omp_parallel ();
10449 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10450 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10452 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10453 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10454 OMP_PARALLEL_COMBINED (stmt
) = 1;
10458 gcc_unreachable ();
10465 # pragma omp single single-clause[optseq] new-line
10468 LOC is the location of the #pragma.
10471 #define OMP_SINGLE_CLAUSE_MASK \
10472 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10473 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10474 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10475 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10478 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10480 tree stmt
= make_node (OMP_SINGLE
);
10481 SET_EXPR_LOCATION (stmt
, loc
);
10482 TREE_TYPE (stmt
) = void_type_node
;
10484 OMP_SINGLE_CLAUSES (stmt
)
10485 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10486 "#pragma omp single");
10487 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10489 return add_stmt (stmt
);
10493 # pragma omp task task-clause[optseq] new-line
10495 LOC is the location of the #pragma.
10498 #define OMP_TASK_CLAUSE_MASK \
10499 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10500 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10501 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10502 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10503 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10504 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10505 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10506 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10509 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10511 tree clauses
, block
;
10513 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10514 "#pragma omp task");
10516 block
= c_begin_omp_task ();
10517 c_parser_statement (parser
);
10518 return c_finish_omp_task (loc
, clauses
, block
);
10522 # pragma omp taskwait new-line
10526 c_parser_omp_taskwait (c_parser
*parser
)
10528 location_t loc
= c_parser_peek_token (parser
)->location
;
10529 c_parser_consume_pragma (parser
);
10530 c_parser_skip_to_pragma_eol (parser
);
10532 c_finish_omp_taskwait (loc
);
10536 # pragma omp taskyield new-line
10540 c_parser_omp_taskyield (c_parser
*parser
)
10542 location_t loc
= c_parser_peek_token (parser
)->location
;
10543 c_parser_consume_pragma (parser
);
10544 c_parser_skip_to_pragma_eol (parser
);
10546 c_finish_omp_taskyield (loc
);
10549 /* Main entry point to parsing most OpenMP pragmas. */
10552 c_parser_omp_construct (c_parser
*parser
)
10554 enum pragma_kind p_kind
;
10558 loc
= c_parser_peek_token (parser
)->location
;
10559 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
10560 c_parser_consume_pragma (parser
);
10564 case PRAGMA_OMP_ATOMIC
:
10565 c_parser_omp_atomic (loc
, parser
);
10567 case PRAGMA_OMP_CRITICAL
:
10568 stmt
= c_parser_omp_critical (loc
, parser
);
10570 case PRAGMA_OMP_FOR
:
10571 stmt
= c_parser_omp_for (loc
, parser
);
10573 case PRAGMA_OMP_MASTER
:
10574 stmt
= c_parser_omp_master (loc
, parser
);
10576 case PRAGMA_OMP_ORDERED
:
10577 stmt
= c_parser_omp_ordered (loc
, parser
);
10579 case PRAGMA_OMP_PARALLEL
:
10580 stmt
= c_parser_omp_parallel (loc
, parser
);
10582 case PRAGMA_OMP_SECTIONS
:
10583 stmt
= c_parser_omp_sections (loc
, parser
);
10585 case PRAGMA_OMP_SINGLE
:
10586 stmt
= c_parser_omp_single (loc
, parser
);
10588 case PRAGMA_OMP_TASK
:
10589 stmt
= c_parser_omp_task (loc
, parser
);
10592 gcc_unreachable ();
10596 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
10601 # pragma omp threadprivate (variable-list) */
10604 c_parser_omp_threadprivate (c_parser
*parser
)
10609 c_parser_consume_pragma (parser
);
10610 loc
= c_parser_peek_token (parser
)->location
;
10611 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10613 /* Mark every variable in VARS to be assigned thread local storage. */
10614 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
10616 tree v
= TREE_PURPOSE (t
);
10618 /* FIXME diagnostics: Ideally we should keep individual
10619 locations for all the variables in the var list to make the
10620 following errors more precise. Perhaps
10621 c_parser_omp_var_list_parens() should construct a list of
10622 locations to go along with the var list. */
10624 /* If V had already been marked threadprivate, it doesn't matter
10625 whether it had been used prior to this point. */
10626 if (TREE_CODE (v
) != VAR_DECL
)
10627 error_at (loc
, "%qD is not a variable", v
);
10628 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
10629 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
10630 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
10631 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
10632 else if (TREE_TYPE (v
) == error_mark_node
)
10634 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
10635 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
10638 if (! DECL_THREAD_LOCAL_P (v
))
10640 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
10641 /* If rtl has been already set for this var, call
10642 make_decl_rtl once again, so that encode_section_info
10643 has a chance to look at the new decl flags. */
10644 if (DECL_RTL_SET_P (v
))
10647 C_DECL_THREADPRIVATE_P (v
) = 1;
10651 c_parser_skip_to_pragma_eol (parser
);
10654 /* Parse a transaction attribute (GCC Extension).
10656 transaction-attribute:
10660 The transactional memory language description is written for C++,
10661 and uses the C++0x attribute syntax. For compatibility, allow the
10662 bracket style for transactions in C as well. */
10665 c_parser_transaction_attributes (c_parser
*parser
)
10667 tree attr_name
, attr
= NULL
;
10669 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10670 return c_parser_attributes (parser
);
10672 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10674 c_parser_consume_token (parser
);
10675 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
10678 attr_name
= c_parser_attribute_any_word (parser
);
10681 c_parser_consume_token (parser
);
10682 attr
= build_tree_list (attr_name
, NULL_TREE
);
10685 c_parser_error (parser
, "expected identifier");
10687 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10689 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10693 /* Parse a __transaction_atomic or __transaction_relaxed statement
10696 transaction-statement:
10697 __transaction_atomic transaction-attribute[opt] compound-statement
10698 __transaction_relaxed compound-statement
10700 Note that the only valid attribute is: "outer".
10704 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
10706 unsigned int old_in
= parser
->in_transaction
;
10707 unsigned int this_in
= 1, new_in
;
10708 location_t loc
= c_parser_peek_token (parser
)->location
;
10711 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10712 || keyword
== RID_TRANSACTION_RELAXED
)
10713 && c_parser_next_token_is_keyword (parser
, keyword
));
10714 c_parser_consume_token (parser
);
10716 if (keyword
== RID_TRANSACTION_RELAXED
)
10717 this_in
|= TM_STMT_ATTR_RELAXED
;
10720 attrs
= c_parser_transaction_attributes (parser
);
10722 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
10725 /* Keep track if we're in the lexical scope of an outer transaction. */
10726 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
10728 parser
->in_transaction
= new_in
;
10729 stmt
= c_parser_compound_statement (parser
);
10730 parser
->in_transaction
= old_in
;
10733 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
10735 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10736 "%<__transaction_atomic%> without transactional memory support enabled"
10737 : "%<__transaction_relaxed %> "
10738 "without transactional memory support enabled"));
10743 /* Parse a __transaction_atomic or __transaction_relaxed expression
10746 transaction-expression:
10747 __transaction_atomic ( expression )
10748 __transaction_relaxed ( expression )
10751 static struct c_expr
10752 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
10755 unsigned int old_in
= parser
->in_transaction
;
10756 unsigned int this_in
= 1;
10757 location_t loc
= c_parser_peek_token (parser
)->location
;
10760 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10761 || keyword
== RID_TRANSACTION_RELAXED
)
10762 && c_parser_next_token_is_keyword (parser
, keyword
));
10763 c_parser_consume_token (parser
);
10765 if (keyword
== RID_TRANSACTION_RELAXED
)
10766 this_in
|= TM_STMT_ATTR_RELAXED
;
10769 attrs
= c_parser_transaction_attributes (parser
);
10771 this_in
|= parse_tm_stmt_attr (attrs
, 0);
10774 parser
->in_transaction
= this_in
;
10775 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10777 tree expr
= c_parser_expression (parser
).value
;
10778 ret
.original_type
= TREE_TYPE (expr
);
10779 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
10780 if (this_in
& TM_STMT_ATTR_RELAXED
)
10781 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
10782 SET_EXPR_LOCATION (ret
.value
, loc
);
10783 ret
.original_code
= TRANSACTION_EXPR
;
10784 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10786 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
10793 ret
.value
= error_mark_node
;
10794 ret
.original_code
= ERROR_MARK
;
10795 ret
.original_type
= NULL
;
10797 parser
->in_transaction
= old_in
;
10800 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10801 "%<__transaction_atomic%> without transactional memory support enabled"
10802 : "%<__transaction_relaxed %> "
10803 "without transactional memory support enabled"));
10808 /* Parse a __transaction_cancel statement (GCC Extension).
10810 transaction-cancel-statement:
10811 __transaction_cancel transaction-attribute[opt] ;
10813 Note that the only valid attribute is "outer".
10817 c_parser_transaction_cancel(c_parser
*parser
)
10819 location_t loc
= c_parser_peek_token (parser
)->location
;
10821 bool is_outer
= false;
10823 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
10824 c_parser_consume_token (parser
);
10826 attrs
= c_parser_transaction_attributes (parser
);
10828 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
10832 error_at (loc
, "%<__transaction_cancel%> without "
10833 "transactional memory support enabled");
10836 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
10838 error_at (loc
, "%<__transaction_cancel%> within a "
10839 "%<__transaction_relaxed%>");
10844 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
10845 && !is_tm_may_cancel_outer (current_function_decl
))
10847 error_at (loc
, "outer %<__transaction_cancel%> not "
10848 "within outer %<__transaction_atomic%>");
10849 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
10853 else if (parser
->in_transaction
== 0)
10855 error_at (loc
, "%<__transaction_cancel%> not within "
10856 "%<__transaction_atomic%>");
10860 return add_stmt (build_tm_abort_call (loc
, is_outer
));
10863 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
10866 /* Parse a single source file. */
10869 c_parse_file (void)
10871 /* Use local storage to begin. If the first token is a pragma, parse it.
10872 If it is #pragma GCC pch_preprocess, then this will load a PCH file
10873 which will cause garbage collection. */
10876 memset (&tparser
, 0, sizeof tparser
);
10877 the_parser
= &tparser
;
10879 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
10880 c_parser_pragma_pch_preprocess (&tparser
);
10882 the_parser
= ggc_alloc_c_parser ();
10883 *the_parser
= tparser
;
10885 /* Initialize EH, if we've been told to do so. */
10886 if (flag_exceptions
)
10887 using_eh_for_cleanups ();
10889 c_parser_translation_unit (the_parser
);
10893 #include "gt-c-c-parser.h"