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,
1183 static void c_parser_omp_construct (c_parser
*);
1184 static void c_parser_omp_threadprivate (c_parser
*);
1185 static void c_parser_omp_barrier (c_parser
*);
1186 static void c_parser_omp_flush (c_parser
*);
1187 static void c_parser_omp_taskwait (c_parser
*);
1188 static void c_parser_omp_taskyield (c_parser
*);
1190 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1191 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1193 /* These Objective-C parser functions are only ever called when
1194 compiling Objective-C. */
1195 static void c_parser_objc_class_definition (c_parser
*, tree
);
1196 static void c_parser_objc_class_instance_variables (c_parser
*);
1197 static void c_parser_objc_class_declaration (c_parser
*);
1198 static void c_parser_objc_alias_declaration (c_parser
*);
1199 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1200 static bool c_parser_objc_method_type (c_parser
*);
1201 static void c_parser_objc_method_definition (c_parser
*);
1202 static void c_parser_objc_methodprotolist (c_parser
*);
1203 static void c_parser_objc_methodproto (c_parser
*);
1204 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1205 static tree
c_parser_objc_type_name (c_parser
*);
1206 static tree
c_parser_objc_protocol_refs (c_parser
*);
1207 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1208 static void c_parser_objc_synchronized_statement (c_parser
*);
1209 static tree
c_parser_objc_selector (c_parser
*);
1210 static tree
c_parser_objc_selector_arg (c_parser
*);
1211 static tree
c_parser_objc_receiver (c_parser
*);
1212 static tree
c_parser_objc_message_args (c_parser
*);
1213 static tree
c_parser_objc_keywordexpr (c_parser
*);
1214 static void c_parser_objc_at_property_declaration (c_parser
*);
1215 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1216 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1217 static bool c_parser_objc_diagnose_bad_element_prefix
1218 (c_parser
*, struct c_declspecs
*);
1220 /* Parse a translation unit (C90 6.7, C99 6.9).
1223 external-declarations
1225 external-declarations:
1226 external-declaration
1227 external-declarations external-declaration
1236 c_parser_translation_unit (c_parser
*parser
)
1238 if (c_parser_next_token_is (parser
, CPP_EOF
))
1240 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1241 "ISO C forbids an empty translation unit");
1245 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1246 mark_valid_location_for_stdc_pragma (false);
1250 c_parser_external_declaration (parser
);
1251 obstack_free (&parser_obstack
, obstack_position
);
1253 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1257 /* Parse an external declaration (C90 6.7, C99 6.9).
1259 external-declaration:
1265 external-declaration:
1268 __extension__ external-declaration
1272 external-declaration:
1273 objc-class-definition
1274 objc-class-declaration
1275 objc-alias-declaration
1276 objc-protocol-definition
1277 objc-method-definition
1282 c_parser_external_declaration (c_parser
*parser
)
1285 switch (c_parser_peek_token (parser
)->type
)
1288 switch (c_parser_peek_token (parser
)->keyword
)
1291 ext
= disable_extension_diagnostics ();
1292 c_parser_consume_token (parser
);
1293 c_parser_external_declaration (parser
);
1294 restore_extension_diagnostics (ext
);
1297 c_parser_asm_definition (parser
);
1299 case RID_AT_INTERFACE
:
1300 case RID_AT_IMPLEMENTATION
:
1301 gcc_assert (c_dialect_objc ());
1302 c_parser_objc_class_definition (parser
, NULL_TREE
);
1305 gcc_assert (c_dialect_objc ());
1306 c_parser_objc_class_declaration (parser
);
1309 gcc_assert (c_dialect_objc ());
1310 c_parser_objc_alias_declaration (parser
);
1312 case RID_AT_PROTOCOL
:
1313 gcc_assert (c_dialect_objc ());
1314 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1316 case RID_AT_PROPERTY
:
1317 gcc_assert (c_dialect_objc ());
1318 c_parser_objc_at_property_declaration (parser
);
1320 case RID_AT_SYNTHESIZE
:
1321 gcc_assert (c_dialect_objc ());
1322 c_parser_objc_at_synthesize_declaration (parser
);
1324 case RID_AT_DYNAMIC
:
1325 gcc_assert (c_dialect_objc ());
1326 c_parser_objc_at_dynamic_declaration (parser
);
1329 gcc_assert (c_dialect_objc ());
1330 c_parser_consume_token (parser
);
1331 objc_finish_implementation ();
1338 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1339 "ISO C does not allow extra %<;%> outside of a function");
1340 c_parser_consume_token (parser
);
1343 mark_valid_location_for_stdc_pragma (true);
1344 c_parser_pragma (parser
, pragma_external
);
1345 mark_valid_location_for_stdc_pragma (false);
1349 if (c_dialect_objc ())
1351 c_parser_objc_method_definition (parser
);
1354 /* Else fall through, and yield a syntax error trying to parse
1355 as a declaration or function definition. */
1358 /* A declaration or a function definition (or, in Objective-C,
1359 an @interface or @protocol with prefix attributes). We can
1360 only tell which after parsing the declaration specifiers, if
1361 any, and the first declarator. */
1362 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1367 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1368 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1369 accepted; otherwise (old-style parameter declarations) only other
1370 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1371 assertion is accepted; otherwise (old-style parameter declarations)
1372 it is not. If NESTED is true, we are inside a function or parsing
1373 old-style parameter declarations; any functions encountered are
1374 nested functions and declaration specifiers are required; otherwise
1375 we are at top level and functions are normal functions and
1376 declaration specifiers may be optional. If EMPTY_OK is true, empty
1377 declarations are OK (subject to all other constraints); otherwise
1378 (old-style parameter declarations) they are diagnosed. If
1379 START_ATTR_OK is true, the declaration specifiers may start with
1380 attributes; otherwise they may not.
1381 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1382 declaration when parsing an Objective-C foreach statement.
1385 declaration-specifiers init-declarator-list[opt] ;
1386 static_assert-declaration
1388 function-definition:
1389 declaration-specifiers[opt] declarator declaration-list[opt]
1394 declaration-list declaration
1396 init-declarator-list:
1398 init-declarator-list , init-declarator
1401 declarator simple-asm-expr[opt] attributes[opt]
1402 declarator simple-asm-expr[opt] attributes[opt] = initializer
1406 nested-function-definition:
1407 declaration-specifiers declarator declaration-list[opt]
1411 attributes objc-class-definition
1412 attributes objc-category-definition
1413 attributes objc-protocol-definition
1415 The simple-asm-expr and attributes are GNU extensions.
1417 This function does not handle __extension__; that is handled in its
1418 callers. ??? Following the old parser, __extension__ may start
1419 external declarations, declarations in functions and declarations
1420 at the start of "for" loops, but not old-style parameter
1423 C99 requires declaration specifiers in a function definition; the
1424 absence is diagnosed through the diagnosis of implicit int. In GNU
1425 C we also allow but diagnose declarations without declaration
1426 specifiers, but only at top level (elsewhere they conflict with
1429 In Objective-C, declarations of the looping variable in a foreach
1430 statement are exceptionally terminated by 'in' (for example, 'for
1431 (NSObject *object in array) { ... }').
1436 threadprivate-directive */
1439 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1440 bool static_assert_ok
, bool empty_ok
,
1441 bool nested
, bool start_attr_ok
,
1442 tree
*objc_foreach_object_declaration
)
1444 struct c_declspecs
*specs
;
1446 tree all_prefix_attrs
;
1447 bool diagnosed_no_specs
= false;
1448 location_t here
= c_parser_peek_token (parser
)->location
;
1450 if (static_assert_ok
1451 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1453 c_parser_static_assert_declaration (parser
);
1456 specs
= build_null_declspecs ();
1458 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1459 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1460 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1461 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1462 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1463 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1465 error_at (here
, "unknown type name %qE",
1466 c_parser_peek_token (parser
)->value
);
1468 /* Parse declspecs normally to get a correct pointer type, but avoid
1469 a further "fails to be a type name" error. Refuse nested functions
1470 since it is not how the user likely wants us to recover. */
1471 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1472 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1473 c_parser_peek_token (parser
)->value
= error_mark_node
;
1477 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1480 c_parser_skip_to_end_of_block_or_statement (parser
);
1483 if (nested
&& !specs
->declspecs_seen_p
)
1485 c_parser_error (parser
, "expected declaration specifiers");
1486 c_parser_skip_to_end_of_block_or_statement (parser
);
1489 finish_declspecs (specs
);
1490 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1496 shadow_tag_warned (specs
, 1);
1497 pedwarn (here
, 0, "empty declaration");
1499 c_parser_consume_token (parser
);
1503 /* Provide better error recovery. Note that a type name here is usually
1504 better diagnosed as a redeclaration. */
1506 && specs
->typespec_kind
== ctsk_tagdef
1507 && c_parser_next_token_starts_declspecs (parser
)
1508 && !c_parser_next_token_is (parser
, CPP_NAME
))
1510 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1511 parser
->error
= false;
1512 shadow_tag_warned (specs
, 1);
1515 else if (c_dialect_objc ())
1517 /* Prefix attributes are an error on method decls. */
1518 switch (c_parser_peek_token (parser
)->type
)
1522 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1526 warning_at (c_parser_peek_token (parser
)->location
,
1528 "prefix attributes are ignored for methods");
1529 specs
->attrs
= NULL_TREE
;
1532 c_parser_objc_method_definition (parser
);
1534 c_parser_objc_methodproto (parser
);
1540 /* This is where we parse 'attributes @interface ...',
1541 'attributes @implementation ...', 'attributes @protocol ...'
1542 (where attributes could be, for example, __attribute__
1545 switch (c_parser_peek_token (parser
)->keyword
)
1547 case RID_AT_INTERFACE
:
1549 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1551 c_parser_objc_class_definition (parser
, specs
->attrs
);
1555 case RID_AT_IMPLEMENTATION
:
1557 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1561 warning_at (c_parser_peek_token (parser
)->location
,
1563 "prefix attributes are ignored for implementations");
1564 specs
->attrs
= NULL_TREE
;
1566 c_parser_objc_class_definition (parser
, NULL_TREE
);
1570 case RID_AT_PROTOCOL
:
1572 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1574 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1581 case RID_AT_PROPERTY
:
1584 c_parser_error (parser
, "unexpected attribute");
1585 specs
->attrs
= NULL
;
1593 pending_xref_error ();
1594 prefix_attrs
= specs
->attrs
;
1595 all_prefix_attrs
= prefix_attrs
;
1596 specs
->attrs
= NULL_TREE
;
1599 struct c_declarator
*declarator
;
1603 /* Declaring either one or more declarators (in which case we
1604 should diagnose if there were no declaration specifiers) or a
1605 function definition (in which case the diagnostic for
1606 implicit int suffices). */
1607 declarator
= c_parser_declarator (parser
,
1608 specs
->typespec_kind
!= ctsk_none
,
1609 C_DTR_NORMAL
, &dummy
);
1610 if (declarator
== NULL
)
1612 c_parser_skip_to_end_of_block_or_statement (parser
);
1615 if (c_parser_next_token_is (parser
, CPP_EQ
)
1616 || c_parser_next_token_is (parser
, CPP_COMMA
)
1617 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1618 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1619 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1620 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1622 tree asm_name
= NULL_TREE
;
1623 tree postfix_attrs
= NULL_TREE
;
1624 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1626 diagnosed_no_specs
= true;
1627 pedwarn (here
, 0, "data definition has no type or storage class");
1629 /* Having seen a data definition, there cannot now be a
1630 function definition. */
1632 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1633 asm_name
= c_parser_simple_asm_expr (parser
);
1634 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1635 postfix_attrs
= c_parser_attributes (parser
);
1636 if (c_parser_next_token_is (parser
, CPP_EQ
))
1640 location_t init_loc
;
1641 c_parser_consume_token (parser
);
1642 /* The declaration of the variable is in effect while
1643 its initializer is parsed. */
1644 d
= start_decl (declarator
, specs
, true,
1645 chainon (postfix_attrs
, all_prefix_attrs
));
1647 d
= error_mark_node
;
1648 start_init (d
, asm_name
, global_bindings_p ());
1649 init_loc
= c_parser_peek_token (parser
)->location
;
1650 init
= c_parser_initializer (parser
);
1652 if (d
!= error_mark_node
)
1654 maybe_warn_string_init (TREE_TYPE (d
), init
);
1655 finish_decl (d
, init_loc
, init
.value
,
1656 init
.original_type
, asm_name
);
1661 tree d
= start_decl (declarator
, specs
, false,
1662 chainon (postfix_attrs
,
1665 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1666 NULL_TREE
, asm_name
);
1668 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1671 *objc_foreach_object_declaration
= d
;
1673 *objc_foreach_object_declaration
= error_mark_node
;
1676 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1678 c_parser_consume_token (parser
);
1679 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1680 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1683 all_prefix_attrs
= prefix_attrs
;
1686 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1688 c_parser_consume_token (parser
);
1691 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1693 /* This can only happen in Objective-C: we found the
1694 'in' that terminates the declaration inside an
1695 Objective-C foreach statement. Do not consume the
1696 token, so that the caller can use it to determine
1697 that this indeed is a foreach context. */
1702 c_parser_error (parser
, "expected %<,%> or %<;%>");
1703 c_parser_skip_to_end_of_block_or_statement (parser
);
1709 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1710 "%<asm%> or %<__attribute__%>");
1711 c_parser_skip_to_end_of_block_or_statement (parser
);
1714 /* Function definition (nested or otherwise). */
1717 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1718 c_push_function_context ();
1720 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1722 /* This can appear in many cases looking nothing like a
1723 function definition, so we don't give a more specific
1724 error suggesting there was one. */
1725 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1726 "or %<__attribute__%>");
1728 c_pop_function_context ();
1732 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1733 tv
= TV_PARSE_INLINE
;
1738 /* Parse old-style parameter declarations. ??? Attributes are
1739 not allowed to start declaration specifiers here because of a
1740 syntax conflict between a function declaration with attribute
1741 suffix and a function definition with an attribute prefix on
1742 first old-style parameter declaration. Following the old
1743 parser, they are not accepted on subsequent old-style
1744 parameter declarations either. However, there is no
1745 ambiguity after the first declaration, nor indeed on the
1746 first as long as we don't allow postfix attributes after a
1747 declarator with a nonempty identifier list in a definition;
1748 and postfix attributes have never been accepted here in
1749 function definitions either. */
1750 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1751 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1752 c_parser_declaration_or_fndef (parser
, false, false, false,
1754 store_parm_decls ();
1755 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1756 = c_parser_peek_token (parser
)->location
;
1757 fnbody
= c_parser_compound_statement (parser
);
1760 tree decl
= current_function_decl
;
1761 /* Mark nested functions as needing static-chain initially.
1762 lower_nested_functions will recompute it but the
1763 DECL_STATIC_CHAIN flag is also used before that happens,
1764 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1765 DECL_STATIC_CHAIN (decl
) = 1;
1768 c_pop_function_context ();
1769 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1782 /* Parse an asm-definition (asm() outside a function body). This is a
1790 c_parser_asm_definition (c_parser
*parser
)
1792 tree asm_str
= c_parser_simple_asm_expr (parser
);
1794 add_asm_node (asm_str
);
1795 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1798 /* Parse a static assertion (C11 6.7.10).
1800 static_assert-declaration:
1801 static_assert-declaration-no-semi ;
1805 c_parser_static_assert_declaration (c_parser
*parser
)
1807 c_parser_static_assert_declaration_no_semi (parser
);
1809 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1810 c_parser_skip_to_end_of_block_or_statement (parser
);
1813 /* Parse a static assertion (C11 6.7.10), without the trailing
1816 static_assert-declaration-no-semi:
1817 _Static_assert ( constant-expression , string-literal )
1821 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1823 location_t assert_loc
, value_loc
;
1827 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1828 assert_loc
= c_parser_peek_token (parser
)->location
;
1832 pedwarn (assert_loc
, OPT_Wpedantic
,
1833 "ISO C99 does not support %<_Static_assert%>");
1835 pedwarn (assert_loc
, OPT_Wpedantic
,
1836 "ISO C90 does not support %<_Static_assert%>");
1838 c_parser_consume_token (parser
);
1839 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1841 value_loc
= c_parser_peek_token (parser
)->location
;
1842 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1843 parser
->lex_untranslated_string
= true;
1844 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1846 parser
->lex_untranslated_string
= false;
1849 switch (c_parser_peek_token (parser
)->type
)
1855 case CPP_UTF8STRING
:
1856 string
= c_parser_peek_token (parser
)->value
;
1857 c_parser_consume_token (parser
);
1858 parser
->lex_untranslated_string
= false;
1861 c_parser_error (parser
, "expected string literal");
1862 parser
->lex_untranslated_string
= false;
1865 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1867 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1869 error_at (value_loc
, "expression in static assertion is not an integer");
1872 if (TREE_CODE (value
) != INTEGER_CST
)
1874 value
= c_fully_fold (value
, false, NULL
);
1875 if (TREE_CODE (value
) == INTEGER_CST
)
1876 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1877 "is not an integer constant expression");
1879 if (TREE_CODE (value
) != INTEGER_CST
)
1881 error_at (value_loc
, "expression in static assertion is not constant");
1884 constant_expression_warning (value
);
1885 if (integer_zerop (value
))
1886 error_at (assert_loc
, "static assertion failed: %E", string
);
1889 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1890 6.7), adding them to SPECS (which may already include some).
1891 Storage class specifiers are accepted iff SCSPEC_OK; type
1892 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1893 the start iff START_ATTR_OK.
1895 declaration-specifiers:
1896 storage-class-specifier declaration-specifiers[opt]
1897 type-specifier declaration-specifiers[opt]
1898 type-qualifier declaration-specifiers[opt]
1899 function-specifier declaration-specifiers[opt]
1900 alignment-specifier declaration-specifiers[opt]
1902 Function specifiers (inline) are from C99, and are currently
1903 handled as storage class specifiers, as is __thread. Alignment
1904 specifiers are from C11.
1906 C90 6.5.1, C99 6.7.1:
1907 storage-class-specifier:
1919 (_Noreturn is new in C11.)
1921 C90 6.5.2, C99 6.7.2:
1934 [_Imaginary removed in C99 TC2]
1935 struct-or-union-specifier
1939 (_Bool and _Complex are new in C99.)
1941 C90 6.5.3, C99 6.7.3:
1947 address-space-qualifier
1949 (restrict is new in C99.)
1953 declaration-specifiers:
1954 attributes declaration-specifiers[opt]
1960 identifier recognized by the target
1962 storage-class-specifier:
1975 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1976 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1981 class-name objc-protocol-refs[opt]
1982 typedef-name objc-protocol-refs
1987 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1988 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1989 enum c_lookahead_kind la
)
1991 bool attrs_ok
= start_attr_ok
;
1992 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1995 gcc_assert (la
== cla_prefer_id
);
1997 while (c_parser_next_token_is (parser
, CPP_NAME
)
1998 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1999 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2001 struct c_typespec t
;
2004 location_t loc
= c_parser_peek_token (parser
)->location
;
2006 /* If we cannot accept a type, exit if the next token must start
2007 one. Also, if we already have seen a tagged definition,
2008 a typename would be an error anyway and likely the user
2009 has simply forgotten a semicolon, so we exit. */
2010 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2011 && c_parser_next_tokens_start_typename (parser
, la
)
2012 && !c_parser_next_token_is_qualifier (parser
))
2015 if (c_parser_next_token_is (parser
, CPP_NAME
))
2017 c_token
*name_token
= c_parser_peek_token (parser
);
2018 tree value
= name_token
->value
;
2019 c_id_kind kind
= name_token
->id_kind
;
2021 if (kind
== C_ID_ADDRSPACE
)
2024 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2025 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2026 c_parser_consume_token (parser
);
2031 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2033 /* If we cannot accept a type, and the next token must start one,
2034 exit. Do the same if we already have seen a tagged definition,
2035 since it would be an error anyway and likely the user has simply
2036 forgotten a semicolon. */
2037 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2040 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2041 a C_ID_CLASSNAME. */
2042 c_parser_consume_token (parser
);
2045 if (kind
== C_ID_ID
)
2047 error ("unknown type name %qE", value
);
2048 t
.kind
= ctsk_typedef
;
2049 t
.spec
= error_mark_node
;
2051 else if (kind
== C_ID_TYPENAME
2052 && (!c_dialect_objc ()
2053 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2055 t
.kind
= ctsk_typedef
;
2056 /* For a typedef name, record the meaning, not the name.
2057 In case of 'foo foo, bar;'. */
2058 t
.spec
= lookup_name (value
);
2062 tree proto
= NULL_TREE
;
2063 gcc_assert (c_dialect_objc ());
2065 if (c_parser_next_token_is (parser
, CPP_LESS
))
2066 proto
= c_parser_objc_protocol_refs (parser
);
2067 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2070 t
.expr_const_operands
= true;
2071 declspecs_add_type (name_token
->location
, specs
, t
);
2074 if (c_parser_next_token_is (parser
, CPP_LESS
))
2076 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2077 nisse@lysator.liu.se. */
2079 gcc_assert (c_dialect_objc ());
2080 if (!typespec_ok
|| seen_type
)
2082 proto
= c_parser_objc_protocol_refs (parser
);
2084 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2086 t
.expr_const_operands
= true;
2087 declspecs_add_type (loc
, specs
, t
);
2090 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2091 switch (c_parser_peek_token (parser
)->keyword
)
2104 /* TODO: Distinguish between function specifiers (inline, noreturn)
2105 and storage class specifiers, either here or in
2106 declspecs_add_scspec. */
2107 declspecs_add_scspec (loc
, specs
,
2108 c_parser_peek_token (parser
)->value
);
2109 c_parser_consume_token (parser
);
2133 if (c_dialect_objc ())
2134 parser
->objc_need_raw_identifier
= true;
2135 t
.kind
= ctsk_resword
;
2136 t
.spec
= c_parser_peek_token (parser
)->value
;
2138 t
.expr_const_operands
= true;
2139 declspecs_add_type (loc
, specs
, t
);
2140 c_parser_consume_token (parser
);
2147 t
= c_parser_enum_specifier (parser
);
2148 declspecs_add_type (loc
, specs
, t
);
2156 t
= c_parser_struct_or_union_specifier (parser
);
2157 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2158 declspecs_add_type (loc
, specs
, t
);
2161 /* ??? The old parser rejected typeof after other type
2162 specifiers, but is a syntax error the best way of
2164 if (!typespec_ok
|| seen_type
)
2168 t
= c_parser_typeof_specifier (parser
);
2169 declspecs_add_type (loc
, specs
, t
);
2175 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2176 c_parser_consume_token (parser
);
2181 attrs
= c_parser_attributes (parser
);
2182 declspecs_add_attrs (loc
, specs
, attrs
);
2185 align
= c_parser_alignas_specifier (parser
);
2186 declspecs_add_alignas (loc
, specs
, align
);
2195 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2198 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2199 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2200 enum attributes[opt] identifier
2202 The form with trailing comma is new in C99. The forms with
2203 attributes are GNU extensions. In GNU C, we accept any expression
2204 without commas in the syntax (assignment expressions, not just
2205 conditional expressions); assignment expressions will be diagnosed
2210 enumerator-list , enumerator
2213 enumeration-constant
2214 enumeration-constant = constant-expression
2217 static struct c_typespec
2218 c_parser_enum_specifier (c_parser
*parser
)
2220 struct c_typespec ret
;
2222 tree ident
= NULL_TREE
;
2223 location_t enum_loc
;
2224 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2225 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2226 enum_loc
= c_parser_peek_token (parser
)->location
;
2227 c_parser_consume_token (parser
);
2228 attrs
= c_parser_attributes (parser
);
2229 enum_loc
= c_parser_peek_token (parser
)->location
;
2230 /* Set the location in case we create a decl now. */
2231 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2232 if (c_parser_next_token_is (parser
, CPP_NAME
))
2234 ident
= c_parser_peek_token (parser
)->value
;
2235 ident_loc
= c_parser_peek_token (parser
)->location
;
2236 enum_loc
= ident_loc
;
2237 c_parser_consume_token (parser
);
2239 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2241 /* Parse an enum definition. */
2242 struct c_enum_contents the_enum
;
2245 /* We chain the enumerators in reverse order, then put them in
2246 forward order at the end. */
2248 timevar_push (TV_PARSE_ENUM
);
2249 type
= start_enum (enum_loc
, &the_enum
, ident
);
2251 c_parser_consume_token (parser
);
2259 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2260 location_t decl_loc
, value_loc
;
2261 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2263 c_parser_error (parser
, "expected identifier");
2264 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2265 values
= error_mark_node
;
2268 token
= c_parser_peek_token (parser
);
2269 enum_id
= token
->value
;
2270 /* Set the location in case we create a decl now. */
2271 c_parser_set_source_position_from_token (token
);
2272 decl_loc
= value_loc
= token
->location
;
2273 c_parser_consume_token (parser
);
2274 if (c_parser_next_token_is (parser
, CPP_EQ
))
2276 c_parser_consume_token (parser
);
2277 value_loc
= c_parser_peek_token (parser
)->location
;
2278 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2281 enum_value
= NULL_TREE
;
2282 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2283 &the_enum
, enum_id
, enum_value
);
2284 TREE_CHAIN (enum_decl
) = values
;
2287 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2289 comma_loc
= c_parser_peek_token (parser
)->location
;
2291 c_parser_consume_token (parser
);
2293 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2295 if (seen_comma
&& !flag_isoc99
)
2296 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2297 c_parser_consume_token (parser
);
2302 c_parser_error (parser
, "expected %<,%> or %<}%>");
2303 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2304 values
= error_mark_node
;
2308 postfix_attrs
= c_parser_attributes (parser
);
2309 ret
.spec
= finish_enum (type
, nreverse (values
),
2310 chainon (attrs
, postfix_attrs
));
2311 ret
.kind
= ctsk_tagdef
;
2312 ret
.expr
= NULL_TREE
;
2313 ret
.expr_const_operands
= true;
2314 timevar_pop (TV_PARSE_ENUM
);
2319 c_parser_error (parser
, "expected %<{%>");
2320 ret
.spec
= error_mark_node
;
2321 ret
.kind
= ctsk_tagref
;
2322 ret
.expr
= NULL_TREE
;
2323 ret
.expr_const_operands
= true;
2326 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2327 /* In ISO C, enumerated types can be referred to only if already
2329 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2332 pedwarn (enum_loc
, OPT_Wpedantic
,
2333 "ISO C forbids forward references to %<enum%> types");
2338 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2340 struct-or-union-specifier:
2341 struct-or-union attributes[opt] identifier[opt]
2342 { struct-contents } attributes[opt]
2343 struct-or-union attributes[opt] identifier
2346 struct-declaration-list
2348 struct-declaration-list:
2349 struct-declaration ;
2350 struct-declaration-list struct-declaration ;
2357 struct-declaration-list struct-declaration
2359 struct-declaration-list:
2360 struct-declaration-list ;
2363 (Note that in the syntax here, unlike that in ISO C, the semicolons
2364 are included here rather than in struct-declaration, in order to
2365 describe the syntax with extra semicolons and missing semicolon at
2370 struct-declaration-list:
2371 @defs ( class-name )
2373 (Note this does not include a trailing semicolon, but can be
2374 followed by further declarations, and gets a pedwarn-if-pedantic
2375 when followed by a semicolon.) */
2377 static struct c_typespec
2378 c_parser_struct_or_union_specifier (c_parser
*parser
)
2380 struct c_typespec ret
;
2382 tree ident
= NULL_TREE
;
2383 location_t struct_loc
;
2384 location_t ident_loc
= UNKNOWN_LOCATION
;
2385 enum tree_code code
;
2386 switch (c_parser_peek_token (parser
)->keyword
)
2397 struct_loc
= c_parser_peek_token (parser
)->location
;
2398 c_parser_consume_token (parser
);
2399 attrs
= c_parser_attributes (parser
);
2401 /* Set the location in case we create a decl now. */
2402 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2404 if (c_parser_next_token_is (parser
, CPP_NAME
))
2406 ident
= c_parser_peek_token (parser
)->value
;
2407 ident_loc
= c_parser_peek_token (parser
)->location
;
2408 struct_loc
= ident_loc
;
2409 c_parser_consume_token (parser
);
2411 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2413 /* Parse a struct or union definition. Start the scope of the
2414 tag before parsing components. */
2415 struct c_struct_parse_info
*struct_info
;
2416 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2418 /* We chain the components in reverse order, then put them in
2419 forward order at the end. Each struct-declaration may
2420 declare multiple components (comma-separated), so we must use
2421 chainon to join them, although when parsing each
2422 struct-declaration we can use TREE_CHAIN directly.
2424 The theory behind all this is that there will be more
2425 semicolon separated fields than comma separated fields, and
2426 so we'll be minimizing the number of node traversals required
2429 timevar_push (TV_PARSE_STRUCT
);
2430 contents
= NULL_TREE
;
2431 c_parser_consume_token (parser
);
2432 /* Handle the Objective-C @defs construct,
2433 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2434 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2437 gcc_assert (c_dialect_objc ());
2438 c_parser_consume_token (parser
);
2439 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2441 if (c_parser_next_token_is (parser
, CPP_NAME
)
2442 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2444 name
= c_parser_peek_token (parser
)->value
;
2445 c_parser_consume_token (parser
);
2449 c_parser_error (parser
, "expected class name");
2450 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2453 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2455 contents
= nreverse (objc_get_class_ivars (name
));
2458 /* Parse the struct-declarations and semicolons. Problems with
2459 semicolons are diagnosed here; empty structures are diagnosed
2464 /* Parse any stray semicolon. */
2465 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2467 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2468 "extra semicolon in struct or union specified");
2469 c_parser_consume_token (parser
);
2472 /* Stop if at the end of the struct or union contents. */
2473 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2475 c_parser_consume_token (parser
);
2478 /* Accept #pragmas at struct scope. */
2479 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2481 c_parser_pragma (parser
, pragma_external
);
2484 /* Parse some comma-separated declarations, but not the
2485 trailing semicolon if any. */
2486 decls
= c_parser_struct_declaration (parser
);
2487 contents
= chainon (decls
, contents
);
2488 /* If no semicolon follows, either we have a parse error or
2489 are at the end of the struct or union and should
2491 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2492 c_parser_consume_token (parser
);
2495 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2496 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2497 "no semicolon at end of struct or union");
2498 else if (parser
->error
2499 || !c_parser_next_token_starts_declspecs (parser
))
2501 c_parser_error (parser
, "expected %<;%>");
2502 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2506 /* If we come here, we have already emitted an error
2507 for an expected `;', identifier or `(', and we also
2508 recovered already. Go on with the next field. */
2511 postfix_attrs
= c_parser_attributes (parser
);
2512 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2513 chainon (attrs
, postfix_attrs
), struct_info
);
2514 ret
.kind
= ctsk_tagdef
;
2515 ret
.expr
= NULL_TREE
;
2516 ret
.expr_const_operands
= true;
2517 timevar_pop (TV_PARSE_STRUCT
);
2522 c_parser_error (parser
, "expected %<{%>");
2523 ret
.spec
= error_mark_node
;
2524 ret
.kind
= ctsk_tagref
;
2525 ret
.expr
= NULL_TREE
;
2526 ret
.expr_const_operands
= true;
2529 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2533 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2534 the trailing semicolon.
2537 specifier-qualifier-list struct-declarator-list
2538 static_assert-declaration-no-semi
2540 specifier-qualifier-list:
2541 type-specifier specifier-qualifier-list[opt]
2542 type-qualifier specifier-qualifier-list[opt]
2543 attributes specifier-qualifier-list[opt]
2545 struct-declarator-list:
2547 struct-declarator-list , attributes[opt] struct-declarator
2550 declarator attributes[opt]
2551 declarator[opt] : constant-expression attributes[opt]
2556 __extension__ struct-declaration
2557 specifier-qualifier-list
2559 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2560 of attributes where shown is a GNU extension. In GNU C, we accept
2561 any expression without commas in the syntax (assignment
2562 expressions, not just conditional expressions); assignment
2563 expressions will be diagnosed as non-constant. */
2566 c_parser_struct_declaration (c_parser
*parser
)
2568 struct c_declspecs
*specs
;
2570 tree all_prefix_attrs
;
2572 location_t decl_loc
;
2573 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2577 ext
= disable_extension_diagnostics ();
2578 c_parser_consume_token (parser
);
2579 decl
= c_parser_struct_declaration (parser
);
2580 restore_extension_diagnostics (ext
);
2583 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2585 c_parser_static_assert_declaration_no_semi (parser
);
2588 specs
= build_null_declspecs ();
2589 decl_loc
= c_parser_peek_token (parser
)->location
;
2590 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2593 if (!specs
->declspecs_seen_p
)
2595 c_parser_error (parser
, "expected specifier-qualifier-list");
2598 finish_declspecs (specs
);
2599 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2600 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2603 if (specs
->typespec_kind
== ctsk_none
)
2605 pedwarn (decl_loc
, OPT_Wpedantic
,
2606 "ISO C forbids member declarations with no members");
2607 shadow_tag_warned (specs
, pedantic
);
2612 /* Support for unnamed structs or unions as members of
2613 structs or unions (which is [a] useful and [b] supports
2617 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2618 build_id_declarator (NULL_TREE
), specs
,
2621 decl_attributes (&ret
, attrs
, 0);
2626 /* Provide better error recovery. Note that a type name here is valid,
2627 and will be treated as a field name. */
2628 if (specs
->typespec_kind
== ctsk_tagdef
2629 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2630 && c_parser_next_token_starts_declspecs (parser
)
2631 && !c_parser_next_token_is (parser
, CPP_NAME
))
2633 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2634 parser
->error
= false;
2638 pending_xref_error ();
2639 prefix_attrs
= specs
->attrs
;
2640 all_prefix_attrs
= prefix_attrs
;
2641 specs
->attrs
= NULL_TREE
;
2645 /* Declaring one or more declarators or un-named bit-fields. */
2646 struct c_declarator
*declarator
;
2648 if (c_parser_next_token_is (parser
, CPP_COLON
))
2649 declarator
= build_id_declarator (NULL_TREE
);
2651 declarator
= c_parser_declarator (parser
,
2652 specs
->typespec_kind
!= ctsk_none
,
2653 C_DTR_NORMAL
, &dummy
);
2654 if (declarator
== NULL
)
2656 c_parser_skip_to_end_of_block_or_statement (parser
);
2659 if (c_parser_next_token_is (parser
, CPP_COLON
)
2660 || c_parser_next_token_is (parser
, CPP_COMMA
)
2661 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2662 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2663 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2665 tree postfix_attrs
= NULL_TREE
;
2666 tree width
= NULL_TREE
;
2668 if (c_parser_next_token_is (parser
, CPP_COLON
))
2670 c_parser_consume_token (parser
);
2671 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2673 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2674 postfix_attrs
= c_parser_attributes (parser
);
2675 d
= grokfield (c_parser_peek_token (parser
)->location
,
2676 declarator
, specs
, width
, &all_prefix_attrs
);
2677 decl_attributes (&d
, chainon (postfix_attrs
,
2678 all_prefix_attrs
), 0);
2679 DECL_CHAIN (d
) = decls
;
2681 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2682 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2685 all_prefix_attrs
= prefix_attrs
;
2686 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2687 c_parser_consume_token (parser
);
2688 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2689 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2691 /* Semicolon consumed in caller. */
2696 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2702 c_parser_error (parser
,
2703 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2704 "%<__attribute__%>");
2711 /* Parse a typeof specifier (a GNU extension).
2714 typeof ( expression )
2715 typeof ( type-name )
2718 static struct c_typespec
2719 c_parser_typeof_specifier (c_parser
*parser
)
2721 struct c_typespec ret
;
2722 ret
.kind
= ctsk_typeof
;
2723 ret
.spec
= error_mark_node
;
2724 ret
.expr
= NULL_TREE
;
2725 ret
.expr_const_operands
= true;
2726 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2727 c_parser_consume_token (parser
);
2728 c_inhibit_evaluation_warnings
++;
2730 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2732 c_inhibit_evaluation_warnings
--;
2736 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2738 struct c_type_name
*type
= c_parser_type_name (parser
);
2739 c_inhibit_evaluation_warnings
--;
2743 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2744 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2750 location_t here
= c_parser_peek_token (parser
)->location
;
2751 struct c_expr expr
= c_parser_expression (parser
);
2752 c_inhibit_evaluation_warnings
--;
2754 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2755 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2756 error_at (here
, "%<typeof%> applied to a bit-field");
2757 mark_exp_read (expr
.value
);
2758 ret
.spec
= TREE_TYPE (expr
.value
);
2759 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2760 /* This is returned with the type so that when the type is
2761 evaluated, this can be evaluated. */
2763 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2764 pop_maybe_used (was_vm
);
2766 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2770 /* Parse an alignment-specifier.
2774 alignment-specifier:
2775 _Alignas ( type-name )
2776 _Alignas ( constant-expression )
2780 c_parser_alignas_specifier (c_parser
* parser
)
2782 tree ret
= error_mark_node
;
2783 location_t loc
= c_parser_peek_token (parser
)->location
;
2784 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2785 c_parser_consume_token (parser
);
2789 pedwarn (loc
, OPT_Wpedantic
,
2790 "ISO C99 does not support %<_Alignas%>");
2792 pedwarn (loc
, OPT_Wpedantic
,
2793 "ISO C90 does not support %<_Alignas%>");
2795 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2797 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2799 struct c_type_name
*type
= c_parser_type_name (parser
);
2801 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2804 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2805 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2809 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2810 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2811 be redeclared; otherwise it may not. KIND indicates which kind of
2812 declarator is wanted. Returns a valid declarator except in the
2813 case of a syntax error in which case NULL is returned. *SEEN_ID is
2814 set to true if an identifier being declared is seen; this is used
2815 to diagnose bad forms of abstract array declarators and to
2816 determine whether an identifier list is syntactically permitted.
2819 pointer[opt] direct-declarator
2823 ( attributes[opt] declarator )
2824 direct-declarator array-declarator
2825 direct-declarator ( parameter-type-list )
2826 direct-declarator ( identifier-list[opt] )
2829 * type-qualifier-list[opt]
2830 * type-qualifier-list[opt] pointer
2832 type-qualifier-list:
2835 type-qualifier-list type-qualifier
2836 type-qualifier-list attributes
2838 parameter-type-list:
2840 parameter-list , ...
2843 parameter-declaration
2844 parameter-list , parameter-declaration
2846 parameter-declaration:
2847 declaration-specifiers declarator attributes[opt]
2848 declaration-specifiers abstract-declarator[opt] attributes[opt]
2852 identifier-list , identifier
2854 abstract-declarator:
2856 pointer[opt] direct-abstract-declarator
2858 direct-abstract-declarator:
2859 ( attributes[opt] abstract-declarator )
2860 direct-abstract-declarator[opt] array-declarator
2861 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2866 direct-declarator ( parameter-forward-declarations
2867 parameter-type-list[opt] )
2869 direct-abstract-declarator:
2870 direct-abstract-declarator[opt] ( parameter-forward-declarations
2871 parameter-type-list[opt] )
2873 parameter-forward-declarations:
2875 parameter-forward-declarations parameter-list ;
2877 The uses of attributes shown above are GNU extensions.
2879 Some forms of array declarator are not included in C99 in the
2880 syntax for abstract declarators; these are disallowed elsewhere.
2881 This may be a defect (DR#289).
2883 This function also accepts an omitted abstract declarator as being
2884 an abstract declarator, although not part of the formal syntax. */
2886 static struct c_declarator
*
2887 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2890 /* Parse any initial pointer part. */
2891 if (c_parser_next_token_is (parser
, CPP_MULT
))
2893 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2894 struct c_declarator
*inner
;
2895 c_parser_consume_token (parser
);
2896 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2897 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2901 return make_pointer_declarator (quals_attrs
, inner
);
2903 /* Now we have a direct declarator, direct abstract declarator or
2904 nothing (which counts as a direct abstract declarator here). */
2905 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2908 /* Parse a direct declarator or direct abstract declarator; arguments
2909 as c_parser_declarator. */
2911 static struct c_declarator
*
2912 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2915 /* The direct declarator must start with an identifier (possibly
2916 omitted) or a parenthesized declarator (possibly abstract). In
2917 an ordinary declarator, initial parentheses must start a
2918 parenthesized declarator. In an abstract declarator or parameter
2919 declarator, they could start a parenthesized declarator or a
2920 parameter list. To tell which, the open parenthesis and any
2921 following attributes must be read. If a declaration specifier
2922 follows, then it is a parameter list; if the specifier is a
2923 typedef name, there might be an ambiguity about redeclaring it,
2924 which is resolved in the direction of treating it as a typedef
2925 name. If a close parenthesis follows, it is also an empty
2926 parameter list, as the syntax does not permit empty abstract
2927 declarators. Otherwise, it is a parenthesized declarator (in
2928 which case the analysis may be repeated inside it, recursively).
2930 ??? There is an ambiguity in a parameter declaration "int
2931 (__attribute__((foo)) x)", where x is not a typedef name: it
2932 could be an abstract declarator for a function, or declare x with
2933 parentheses. The proper resolution of this ambiguity needs
2934 documenting. At present we follow an accident of the old
2935 parser's implementation, whereby the first parameter must have
2936 some declaration specifiers other than just attributes. Thus as
2937 a parameter declaration it is treated as a parenthesized
2938 parameter named x, and as an abstract declarator it is
2941 ??? Also following the old parser, attributes inside an empty
2942 parameter list are ignored, making it a list not yielding a
2943 prototype, rather than giving an error or making it have one
2944 parameter with implicit type int.
2946 ??? Also following the old parser, typedef names may be
2947 redeclared in declarators, but not Objective-C class names. */
2949 if (kind
!= C_DTR_ABSTRACT
2950 && c_parser_next_token_is (parser
, CPP_NAME
)
2952 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2953 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2954 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2956 struct c_declarator
*inner
2957 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2959 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2960 c_parser_consume_token (parser
);
2961 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2964 if (kind
!= C_DTR_NORMAL
2965 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2967 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2968 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2971 /* Either we are at the end of an abstract declarator, or we have
2974 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2977 struct c_declarator
*inner
;
2978 c_parser_consume_token (parser
);
2979 attrs
= c_parser_attributes (parser
);
2980 if (kind
!= C_DTR_NORMAL
2981 && (c_parser_next_token_starts_declspecs (parser
)
2982 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2984 struct c_arg_info
*args
2985 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2992 = build_function_declarator (args
,
2993 build_id_declarator (NULL_TREE
));
2994 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2998 /* A parenthesized declarator. */
2999 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3000 if (inner
!= NULL
&& attrs
!= NULL
)
3001 inner
= build_attrs_declarator (attrs
, inner
);
3002 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3004 c_parser_consume_token (parser
);
3008 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3012 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3019 if (kind
== C_DTR_NORMAL
)
3021 c_parser_error (parser
, "expected identifier or %<(%>");
3025 return build_id_declarator (NULL_TREE
);
3029 /* Parse part of a direct declarator or direct abstract declarator,
3030 given that some (in INNER) has already been parsed; ID_PRESENT is
3031 true if an identifier is present, false for an abstract
3034 static struct c_declarator
*
3035 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3036 struct c_declarator
*inner
)
3038 /* Parse a sequence of array declarators and parameter lists. */
3039 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3041 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3042 struct c_declarator
*declarator
;
3043 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3047 c_parser_consume_token (parser
);
3048 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3049 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3051 c_parser_consume_token (parser
);
3052 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3053 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3054 if (!quals_attrs
->declspecs_seen_p
)
3056 /* If "static" is present, there must be an array dimension.
3057 Otherwise, there may be a dimension, "*", or no
3062 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3066 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3071 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3073 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3077 c_parser_consume_token (parser
);
3082 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3088 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3091 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3092 c_parser_consume_token (parser
);
3095 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3100 mark_exp_read (dimen
);
3101 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3102 static_seen
, star_seen
);
3103 if (declarator
== NULL
)
3105 inner
= set_array_declarator_inner (declarator
, inner
);
3106 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3108 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3111 struct c_arg_info
*args
;
3112 c_parser_consume_token (parser
);
3113 attrs
= c_parser_attributes (parser
);
3114 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3119 inner
= build_function_declarator (args
, inner
);
3120 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3126 /* Parse a parameter list or identifier list, including the closing
3127 parenthesis but not the opening one. ATTRS are the attributes at
3128 the start of the list. ID_LIST_OK is true if an identifier list is
3129 acceptable; such a list must not have attributes at the start. */
3131 static struct c_arg_info
*
3132 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3135 declare_parm_level ();
3136 /* If the list starts with an identifier, it is an identifier list.
3137 Otherwise, it is either a prototype list or an empty list. */
3140 && c_parser_next_token_is (parser
, CPP_NAME
)
3141 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3143 /* Look ahead to detect typos in type names. */
3144 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3145 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3146 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3147 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3149 tree list
= NULL_TREE
, *nextp
= &list
;
3150 while (c_parser_next_token_is (parser
, CPP_NAME
)
3151 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3153 *nextp
= build_tree_list (NULL_TREE
,
3154 c_parser_peek_token (parser
)->value
);
3155 nextp
= & TREE_CHAIN (*nextp
);
3156 c_parser_consume_token (parser
);
3157 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3159 c_parser_consume_token (parser
);
3160 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3162 c_parser_error (parser
, "expected identifier");
3166 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3168 struct c_arg_info
*ret
= build_arg_info ();
3170 c_parser_consume_token (parser
);
3176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3184 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3191 /* Parse a parameter list (possibly empty), including the closing
3192 parenthesis but not the opening one. ATTRS are the attributes at
3193 the start of the list. EXPR is NULL or an expression that needs to
3194 be evaluated for the side effects of array size expressions in the
3197 static struct c_arg_info
*
3198 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3200 bool bad_parm
= false;
3202 /* ??? Following the old parser, forward parameter declarations may
3203 use abstract declarators, and if no real parameter declarations
3204 follow the forward declarations then this is not diagnosed. Also
3205 note as above that attributes are ignored as the only contents of
3206 the parentheses, or as the only contents after forward
3208 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3210 struct c_arg_info
*ret
= build_arg_info ();
3211 c_parser_consume_token (parser
);
3214 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3216 struct c_arg_info
*ret
= build_arg_info ();
3218 if (flag_allow_parameterless_variadic_functions
)
3220 /* F (...) is allowed. */
3221 ret
->types
= NULL_TREE
;
3225 /* Suppress -Wold-style-definition for this case. */
3226 ret
->types
= error_mark_node
;
3227 error_at (c_parser_peek_token (parser
)->location
,
3228 "ISO C requires a named argument before %<...%>");
3230 c_parser_consume_token (parser
);
3231 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3233 c_parser_consume_token (parser
);
3238 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3243 /* Nonempty list of parameters, either terminated with semicolon
3244 (forward declarations; recurse) or with close parenthesis (normal
3245 function) or with ", ... )" (variadic function). */
3248 /* Parse a parameter. */
3249 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3254 push_parm_decl (parm
, &expr
);
3255 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3258 c_parser_consume_token (parser
);
3259 mark_forward_parm_decls ();
3260 new_attrs
= c_parser_attributes (parser
);
3261 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3263 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3265 c_parser_consume_token (parser
);
3269 return get_parm_info (false, expr
);
3271 if (!c_parser_require (parser
, CPP_COMMA
,
3272 "expected %<;%>, %<,%> or %<)%>"))
3274 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3277 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3279 c_parser_consume_token (parser
);
3280 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3282 c_parser_consume_token (parser
);
3286 return get_parm_info (true, expr
);
3290 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3298 /* Parse a parameter declaration. ATTRS are the attributes at the
3299 start of the declaration if it is the first parameter. */
3301 static struct c_parm
*
3302 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3304 struct c_declspecs
*specs
;
3305 struct c_declarator
*declarator
;
3307 tree postfix_attrs
= NULL_TREE
;
3310 /* Accept #pragmas between parameter declarations. */
3311 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3312 c_parser_pragma (parser
, pragma_external
);
3314 if (!c_parser_next_token_starts_declspecs (parser
))
3316 c_token
*token
= c_parser_peek_token (parser
);
3319 c_parser_set_source_position_from_token (token
);
3320 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3322 error ("unknown type name %qE", token
->value
);
3323 parser
->error
= true;
3325 /* ??? In some Objective-C cases '...' isn't applicable so there
3326 should be a different message. */
3328 c_parser_error (parser
,
3329 "expected declaration specifiers or %<...%>");
3330 c_parser_skip_to_end_of_parameter (parser
);
3333 specs
= build_null_declspecs ();
3336 declspecs_add_attrs (input_location
, specs
, attrs
);
3339 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3340 finish_declspecs (specs
);
3341 pending_xref_error ();
3342 prefix_attrs
= specs
->attrs
;
3343 specs
->attrs
= NULL_TREE
;
3344 declarator
= c_parser_declarator (parser
,
3345 specs
->typespec_kind
!= ctsk_none
,
3346 C_DTR_PARM
, &dummy
);
3347 if (declarator
== NULL
)
3349 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3352 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3353 postfix_attrs
= c_parser_attributes (parser
);
3354 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3358 /* Parse a string literal in an asm expression. It should not be
3359 translated, and wide string literals are an error although
3360 permitted by the syntax. This is a GNU extension.
3365 ??? At present, following the old parser, the caller needs to have
3366 set lex_untranslated_string to 1. It would be better to follow the
3367 C++ parser rather than using this kludge. */
3370 c_parser_asm_string_literal (c_parser
*parser
)
3373 int save_flag
= warn_overlength_strings
;
3374 warn_overlength_strings
= 0;
3375 if (c_parser_next_token_is (parser
, CPP_STRING
))
3377 str
= c_parser_peek_token (parser
)->value
;
3378 c_parser_consume_token (parser
);
3380 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3382 error_at (c_parser_peek_token (parser
)->location
,
3383 "wide string literal in %<asm%>");
3384 str
= build_string (1, "");
3385 c_parser_consume_token (parser
);
3389 c_parser_error (parser
, "expected string literal");
3392 warn_overlength_strings
= save_flag
;
3396 /* Parse a simple asm expression. This is used in restricted
3397 contexts, where a full expression with inputs and outputs does not
3398 make sense. This is a GNU extension.
3401 asm ( asm-string-literal )
3405 c_parser_simple_asm_expr (c_parser
*parser
)
3408 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3409 /* ??? Follow the C++ parser rather than using the
3410 lex_untranslated_string kludge. */
3411 parser
->lex_untranslated_string
= true;
3412 c_parser_consume_token (parser
);
3413 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3415 parser
->lex_untranslated_string
= false;
3418 str
= c_parser_asm_string_literal (parser
);
3419 parser
->lex_untranslated_string
= false;
3420 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3422 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3429 c_parser_attribute_any_word (c_parser
*parser
)
3431 tree attr_name
= NULL_TREE
;
3433 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3435 /* ??? See comment above about what keywords are accepted here. */
3437 switch (c_parser_peek_token (parser
)->keyword
)
3468 case RID_TRANSACTION_ATOMIC
:
3469 case RID_TRANSACTION_CANCEL
:
3479 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3480 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3482 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3483 attr_name
= c_parser_peek_token (parser
)->value
;
3488 /* Parse (possibly empty) attributes. This is a GNU extension.
3492 attributes attribute
3495 __attribute__ ( ( attribute-list ) )
3499 attribute_list , attrib
3504 any-word ( identifier )
3505 any-word ( identifier , nonempty-expr-list )
3506 any-word ( expr-list )
3508 where the "identifier" must not be declared as a type, and
3509 "any-word" may be any identifier (including one declared as a
3510 type), a reserved word storage class specifier, type specifier or
3511 type qualifier. ??? This still leaves out most reserved keywords
3512 (following the old parser), shouldn't we include them, and why not
3513 allow identifiers declared as types to start the arguments? */
3516 c_parser_attributes (c_parser
*parser
)
3518 tree attrs
= NULL_TREE
;
3519 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3521 /* ??? Follow the C++ parser rather than using the
3522 lex_untranslated_string kludge. */
3523 parser
->lex_untranslated_string
= true;
3524 c_parser_consume_token (parser
);
3525 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3527 parser
->lex_untranslated_string
= false;
3530 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3532 parser
->lex_untranslated_string
= false;
3533 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3536 /* Parse the attribute list. */
3537 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3538 || c_parser_next_token_is (parser
, CPP_NAME
)
3539 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3541 tree attr
, attr_name
, attr_args
;
3542 VEC(tree
,gc
) *expr_list
;
3543 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3545 c_parser_consume_token (parser
);
3549 attr_name
= c_parser_attribute_any_word (parser
);
3550 if (attr_name
== NULL
)
3552 c_parser_consume_token (parser
);
3553 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3555 attr
= build_tree_list (attr_name
, NULL_TREE
);
3556 attrs
= chainon (attrs
, attr
);
3559 c_parser_consume_token (parser
);
3560 /* Parse the attribute contents. If they start with an
3561 identifier which is followed by a comma or close
3562 parenthesis, then the arguments start with that
3563 identifier; otherwise they are an expression list.
3564 In objective-c the identifier may be a classname. */
3565 if (c_parser_next_token_is (parser
, CPP_NAME
)
3566 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3567 || (c_dialect_objc ()
3568 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3569 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3570 || (c_parser_peek_2nd_token (parser
)->type
3571 == CPP_CLOSE_PAREN
)))
3573 tree arg1
= c_parser_peek_token (parser
)->value
;
3574 c_parser_consume_token (parser
);
3575 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3576 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3580 c_parser_consume_token (parser
);
3581 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3582 tree_list
= build_tree_list_vec (expr_list
);
3583 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3584 release_tree_vector (expr_list
);
3589 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3590 attr_args
= NULL_TREE
;
3593 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3594 attr_args
= build_tree_list_vec (expr_list
);
3595 release_tree_vector (expr_list
);
3598 attr
= build_tree_list (attr_name
, attr_args
);
3599 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3600 c_parser_consume_token (parser
);
3603 parser
->lex_untranslated_string
= false;
3604 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3608 attrs
= chainon (attrs
, attr
);
3610 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3611 c_parser_consume_token (parser
);
3614 parser
->lex_untranslated_string
= false;
3615 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3619 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3620 c_parser_consume_token (parser
);
3623 parser
->lex_untranslated_string
= false;
3624 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3628 parser
->lex_untranslated_string
= false;
3633 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3636 specifier-qualifier-list abstract-declarator[opt]
3639 static struct c_type_name
*
3640 c_parser_type_name (c_parser
*parser
)
3642 struct c_declspecs
*specs
= build_null_declspecs ();
3643 struct c_declarator
*declarator
;
3644 struct c_type_name
*ret
;
3646 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3647 if (!specs
->declspecs_seen_p
)
3649 c_parser_error (parser
, "expected specifier-qualifier-list");
3652 if (specs
->type
!= error_mark_node
)
3654 pending_xref_error ();
3655 finish_declspecs (specs
);
3657 declarator
= c_parser_declarator (parser
,
3658 specs
->typespec_kind
!= ctsk_none
,
3659 C_DTR_ABSTRACT
, &dummy
);
3660 if (declarator
== NULL
)
3662 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3664 ret
->declarator
= declarator
;
3668 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3671 assignment-expression
3672 { initializer-list }
3673 { initializer-list , }
3676 designation[opt] initializer
3677 initializer-list , designation[opt] initializer
3684 designator-list designator
3691 [ constant-expression ]
3703 [ constant-expression ... constant-expression ]
3705 Any expression without commas is accepted in the syntax for the
3706 constant-expressions, with non-constant expressions rejected later.
3708 This function is only used for top-level initializers; for nested
3709 ones, see c_parser_initval. */
3711 static struct c_expr
3712 c_parser_initializer (c_parser
*parser
)
3714 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3715 return c_parser_braced_init (parser
, NULL_TREE
, false);
3719 location_t loc
= c_parser_peek_token (parser
)->location
;
3720 ret
= c_parser_expr_no_commas (parser
, NULL
);
3721 if (TREE_CODE (ret
.value
) != STRING_CST
3722 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3723 ret
= default_function_array_read_conversion (loc
, ret
);
3728 /* Parse a braced initializer list. TYPE is the type specified for a
3729 compound literal, and NULL_TREE for other initializers and for
3730 nested braced lists. NESTED_P is true for nested braced lists,
3731 false for the list of a compound literal or the list that is the
3732 top-level initializer in a declaration. */
3734 static struct c_expr
3735 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3738 struct obstack braced_init_obstack
;
3739 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3740 gcc_obstack_init (&braced_init_obstack
);
3741 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3742 c_parser_consume_token (parser
);
3744 push_init_level (0, &braced_init_obstack
);
3746 really_start_incremental_init (type
);
3747 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3749 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3753 /* Parse a non-empty initializer list, possibly with a trailing
3757 c_parser_initelt (parser
, &braced_init_obstack
);
3760 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3761 c_parser_consume_token (parser
);
3764 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3768 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3770 ret
.value
= error_mark_node
;
3771 ret
.original_code
= ERROR_MARK
;
3772 ret
.original_type
= NULL
;
3773 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3774 pop_init_level (0, &braced_init_obstack
);
3775 obstack_free (&braced_init_obstack
, NULL
);
3778 c_parser_consume_token (parser
);
3779 ret
= pop_init_level (0, &braced_init_obstack
);
3780 obstack_free (&braced_init_obstack
, NULL
);
3784 /* Parse a nested initializer, including designators. */
3787 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3789 /* Parse any designator or designator list. A single array
3790 designator may have the subsequent "=" omitted in GNU C, but a
3791 longer list or a structure member designator may not. */
3792 if (c_parser_next_token_is (parser
, CPP_NAME
)
3793 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3795 /* Old-style structure member designator. */
3796 set_init_label (c_parser_peek_token (parser
)->value
,
3797 braced_init_obstack
);
3798 /* Use the colon as the error location. */
3799 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3800 "obsolete use of designated initializer with %<:%>");
3801 c_parser_consume_token (parser
);
3802 c_parser_consume_token (parser
);
3806 /* des_seen is 0 if there have been no designators, 1 if there
3807 has been a single array designator and 2 otherwise. */
3809 /* Location of a designator. */
3810 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3811 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3812 || c_parser_next_token_is (parser
, CPP_DOT
))
3814 int des_prev
= des_seen
;
3816 des_loc
= c_parser_peek_token (parser
)->location
;
3819 if (c_parser_next_token_is (parser
, CPP_DOT
))
3822 c_parser_consume_token (parser
);
3823 if (c_parser_next_token_is (parser
, CPP_NAME
))
3825 set_init_label (c_parser_peek_token (parser
)->value
,
3826 braced_init_obstack
);
3827 c_parser_consume_token (parser
);
3832 init
.value
= error_mark_node
;
3833 init
.original_code
= ERROR_MARK
;
3834 init
.original_type
= NULL
;
3835 c_parser_error (parser
, "expected identifier");
3836 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3837 process_init_element (init
, false, braced_init_obstack
);
3844 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3845 /* ??? Following the old parser, [ objc-receiver
3846 objc-message-args ] is accepted as an initializer,
3847 being distinguished from a designator by what follows
3848 the first assignment expression inside the square
3849 brackets, but after a first array designator a
3850 subsequent square bracket is for Objective-C taken to
3851 start an expression, using the obsolete form of
3852 designated initializer without '=', rather than
3853 possibly being a second level of designation: in LALR
3854 terms, the '[' is shifted rather than reducing
3855 designator to designator-list. */
3856 if (des_prev
== 1 && c_dialect_objc ())
3858 des_seen
= des_prev
;
3861 if (des_prev
== 0 && c_dialect_objc ())
3863 /* This might be an array designator or an
3864 Objective-C message expression. If the former,
3865 continue parsing here; if the latter, parse the
3866 remainder of the initializer given the starting
3867 primary-expression. ??? It might make sense to
3868 distinguish when des_prev == 1 as well; see
3869 previous comment. */
3871 struct c_expr mexpr
;
3872 c_parser_consume_token (parser
);
3873 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3874 && ((c_parser_peek_token (parser
)->id_kind
3876 || (c_parser_peek_token (parser
)->id_kind
3877 == C_ID_CLASSNAME
)))
3879 /* Type name receiver. */
3880 tree id
= c_parser_peek_token (parser
)->value
;
3881 c_parser_consume_token (parser
);
3882 rec
= objc_get_class_reference (id
);
3883 goto parse_message_args
;
3885 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3886 mark_exp_read (first
);
3887 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3888 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3889 goto array_desig_after_first
;
3890 /* Expression receiver. So far only one part
3891 without commas has been parsed; there might be
3892 more of the expression. */
3894 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3897 location_t comma_loc
, exp_loc
;
3898 comma_loc
= c_parser_peek_token (parser
)->location
;
3899 c_parser_consume_token (parser
);
3900 exp_loc
= c_parser_peek_token (parser
)->location
;
3901 next
= c_parser_expr_no_commas (parser
, NULL
);
3902 next
= default_function_array_read_conversion (exp_loc
,
3904 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3907 /* Now parse the objc-message-args. */
3908 args
= c_parser_objc_message_args (parser
);
3909 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3912 = objc_build_message_expr (rec
, args
);
3913 mexpr
.original_code
= ERROR_MARK
;
3914 mexpr
.original_type
= NULL
;
3915 /* Now parse and process the remainder of the
3916 initializer, starting with this message
3917 expression as a primary-expression. */
3918 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3921 c_parser_consume_token (parser
);
3922 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3923 mark_exp_read (first
);
3924 array_desig_after_first
:
3925 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3927 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3928 c_parser_consume_token (parser
);
3929 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3930 mark_exp_read (second
);
3934 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3936 c_parser_consume_token (parser
);
3937 set_init_index (first
, second
, braced_init_obstack
);
3939 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
3940 "ISO C forbids specifying range of elements to initialize");
3943 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3949 if (c_parser_next_token_is (parser
, CPP_EQ
))
3952 pedwarn (des_loc
, OPT_Wpedantic
,
3953 "ISO C90 forbids specifying subobject to initialize");
3954 c_parser_consume_token (parser
);
3959 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
3960 "obsolete use of designated initializer without %<=%>");
3964 init
.value
= error_mark_node
;
3965 init
.original_code
= ERROR_MARK
;
3966 init
.original_type
= NULL
;
3967 c_parser_error (parser
, "expected %<=%>");
3968 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3969 process_init_element (init
, false, braced_init_obstack
);
3975 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3978 /* Parse a nested initializer; as c_parser_initializer but parses
3979 initializers within braced lists, after any designators have been
3980 applied. If AFTER is not NULL then it is an Objective-C message
3981 expression which is the primary-expression starting the
3985 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
3986 struct obstack
* braced_init_obstack
)
3989 gcc_assert (!after
|| c_dialect_objc ());
3990 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3991 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3994 location_t loc
= c_parser_peek_token (parser
)->location
;
3995 init
= c_parser_expr_no_commas (parser
, after
);
3996 if (init
.value
!= NULL_TREE
3997 && TREE_CODE (init
.value
) != STRING_CST
3998 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3999 init
= default_function_array_read_conversion (loc
, init
);
4001 process_init_element (init
, false, braced_init_obstack
);
4004 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4008 { block-item-list[opt] }
4009 { label-declarations block-item-list }
4013 block-item-list block-item
4025 { label-declarations block-item-list }
4028 __extension__ nested-declaration
4029 nested-function-definition
4033 label-declarations label-declaration
4036 __label__ identifier-list ;
4038 Allowing the mixing of declarations and code is new in C99. The
4039 GNU syntax also permits (not shown above) labels at the end of
4040 compound statements, which yield an error. We don't allow labels
4041 on declarations; this might seem like a natural extension, but
4042 there would be a conflict between attributes on the label and
4043 prefix attributes on the declaration. ??? The syntax follows the
4044 old parser in requiring something after label declarations.
4045 Although they are erroneous if the labels declared aren't defined,
4046 is it useful for the syntax to be this way?
4058 c_parser_compound_statement (c_parser
*parser
)
4061 location_t brace_loc
;
4062 brace_loc
= c_parser_peek_token (parser
)->location
;
4063 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4065 /* Ensure a scope is entered and left anyway to avoid confusion
4066 if we have just prepared to enter a function body. */
4067 stmt
= c_begin_compound_stmt (true);
4068 c_end_compound_stmt (brace_loc
, stmt
, true);
4069 return error_mark_node
;
4071 stmt
= c_begin_compound_stmt (true);
4072 c_parser_compound_statement_nostart (parser
);
4073 return c_end_compound_stmt (brace_loc
, stmt
, true);
4076 /* Parse a compound statement except for the opening brace. This is
4077 used for parsing both compound statements and statement expressions
4078 (which follow different paths to handling the opening). */
4081 c_parser_compound_statement_nostart (c_parser
*parser
)
4083 bool last_stmt
= false;
4084 bool last_label
= false;
4085 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4086 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4087 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4089 c_parser_consume_token (parser
);
4092 mark_valid_location_for_stdc_pragma (true);
4093 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4095 /* Read zero or more forward-declarations for labels that nested
4096 functions can jump to. */
4097 mark_valid_location_for_stdc_pragma (false);
4098 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4100 label_loc
= c_parser_peek_token (parser
)->location
;
4101 c_parser_consume_token (parser
);
4102 /* Any identifiers, including those declared as type names,
4107 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4109 c_parser_error (parser
, "expected identifier");
4113 = declare_label (c_parser_peek_token (parser
)->value
);
4114 C_DECLARED_LABEL_FLAG (label
) = 1;
4115 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4116 c_parser_consume_token (parser
);
4117 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4118 c_parser_consume_token (parser
);
4122 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4124 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4126 /* We must now have at least one statement, label or declaration. */
4127 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4129 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4130 c_parser_error (parser
, "expected declaration or statement");
4131 c_parser_consume_token (parser
);
4134 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4136 location_t loc
= c_parser_peek_token (parser
)->location
;
4137 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4138 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4139 || (c_parser_next_token_is (parser
, CPP_NAME
)
4140 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4142 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4143 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4145 label_loc
= c_parser_peek_token (parser
)->location
;
4148 mark_valid_location_for_stdc_pragma (false);
4149 c_parser_label (parser
);
4151 else if (!last_label
4152 && c_parser_next_tokens_start_declaration (parser
))
4155 mark_valid_location_for_stdc_pragma (false);
4156 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4159 (pedantic
&& !flag_isoc99
)
4161 : OPT_Wdeclaration_after_statement
,
4162 "ISO C90 forbids mixed declarations and code");
4165 else if (!last_label
4166 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4168 /* __extension__ can start a declaration, but is also an
4169 unary operator that can start an expression. Consume all
4170 but the last of a possible series of __extension__ to
4172 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4173 && (c_parser_peek_2nd_token (parser
)->keyword
4175 c_parser_consume_token (parser
);
4176 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4179 ext
= disable_extension_diagnostics ();
4180 c_parser_consume_token (parser
);
4182 mark_valid_location_for_stdc_pragma (false);
4183 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4185 /* Following the old parser, __extension__ does not
4186 disable this diagnostic. */
4187 restore_extension_diagnostics (ext
);
4189 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4191 : OPT_Wdeclaration_after_statement
,
4192 "ISO C90 forbids mixed declarations and code");
4198 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4200 /* External pragmas, and some omp pragmas, are not associated
4201 with regular c code, and so are not to be considered statements
4202 syntactically. This ensures that the user doesn't put them
4203 places that would turn into syntax errors if the directive
4205 if (c_parser_pragma (parser
, pragma_compound
))
4206 last_label
= false, last_stmt
= true;
4208 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4210 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4211 c_parser_error (parser
, "expected declaration or statement");
4214 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4216 if (parser
->in_if_block
)
4218 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4219 error_at (loc
, """expected %<}%> before %<else%>");
4224 error_at (loc
, "%<else%> without a previous %<if%>");
4225 c_parser_consume_token (parser
);
4234 mark_valid_location_for_stdc_pragma (false);
4235 c_parser_statement_after_labels (parser
);
4238 parser
->error
= false;
4241 error_at (label_loc
, "label at end of compound statement");
4242 c_parser_consume_token (parser
);
4243 /* Restore the value we started with. */
4244 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4247 /* Parse a label (C90 6.6.1, C99 6.8.1).
4250 identifier : attributes[opt]
4251 case constant-expression :
4257 case constant-expression ... constant-expression :
4259 The use of attributes on labels is a GNU extension. The syntax in
4260 GNU C accepts any expressions without commas, non-constant
4261 expressions being rejected later. */
4264 c_parser_label (c_parser
*parser
)
4266 location_t loc1
= c_parser_peek_token (parser
)->location
;
4267 tree label
= NULL_TREE
;
4268 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4271 c_parser_consume_token (parser
);
4272 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4273 if (c_parser_next_token_is (parser
, CPP_COLON
))
4275 c_parser_consume_token (parser
);
4276 label
= do_case (loc1
, exp1
, NULL_TREE
);
4278 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4280 c_parser_consume_token (parser
);
4281 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4282 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4283 label
= do_case (loc1
, exp1
, exp2
);
4286 c_parser_error (parser
, "expected %<:%> or %<...%>");
4288 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4290 c_parser_consume_token (parser
);
4291 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4292 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4296 tree name
= c_parser_peek_token (parser
)->value
;
4299 location_t loc2
= c_parser_peek_token (parser
)->location
;
4300 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4301 c_parser_consume_token (parser
);
4302 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4303 c_parser_consume_token (parser
);
4304 attrs
= c_parser_attributes (parser
);
4305 tlab
= define_label (loc2
, name
);
4308 decl_attributes (&tlab
, attrs
, 0);
4309 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4314 if (c_parser_next_tokens_start_declaration (parser
))
4316 error_at (c_parser_peek_token (parser
)->location
,
4317 "a label can only be part of a statement and "
4318 "a declaration is not a statement");
4319 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4320 /*static_assert_ok*/ true,
4321 /*nested*/ true, /*empty_ok*/ false,
4322 /*start_attr_ok*/ true, NULL
);
4327 /* Parse a statement (C90 6.6, C99 6.8).
4332 expression-statement
4340 expression-statement:
4343 selection-statement:
4347 iteration-statement:
4356 return expression[opt] ;
4369 objc-throw-statement
4370 objc-try-catch-statement
4371 objc-synchronized-statement
4373 objc-throw-statement:
4387 parallel-for-construct
4388 parallel-sections-construct
4395 parallel-directive structured-block
4398 for-directive iteration-statement
4401 sections-directive section-scope
4404 single-directive structured-block
4406 parallel-for-construct:
4407 parallel-for-directive iteration-statement
4409 parallel-sections-construct:
4410 parallel-sections-directive section-scope
4413 master-directive structured-block
4416 critical-directive structured-block
4419 atomic-directive expression-statement
4422 ordered-directive structured-block
4424 Transactional Memory:
4427 transaction-statement
4428 transaction-cancel-statement
4432 c_parser_statement (c_parser
*parser
)
4434 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4435 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4436 || (c_parser_next_token_is (parser
, CPP_NAME
)
4437 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4438 c_parser_label (parser
);
4439 c_parser_statement_after_labels (parser
);
4442 /* Parse a statement, other than a labeled statement. */
4445 c_parser_statement_after_labels (c_parser
*parser
)
4447 location_t loc
= c_parser_peek_token (parser
)->location
;
4448 tree stmt
= NULL_TREE
;
4449 bool in_if_block
= parser
->in_if_block
;
4450 parser
->in_if_block
= false;
4451 switch (c_parser_peek_token (parser
)->type
)
4453 case CPP_OPEN_BRACE
:
4454 add_stmt (c_parser_compound_statement (parser
));
4457 switch (c_parser_peek_token (parser
)->keyword
)
4460 c_parser_if_statement (parser
);
4463 c_parser_switch_statement (parser
);
4466 c_parser_while_statement (parser
);
4469 c_parser_do_statement (parser
);
4472 c_parser_for_statement (parser
);
4475 c_parser_consume_token (parser
);
4476 if (c_parser_next_token_is (parser
, CPP_NAME
))
4478 stmt
= c_finish_goto_label (loc
,
4479 c_parser_peek_token (parser
)->value
);
4480 c_parser_consume_token (parser
);
4482 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4486 c_parser_consume_token (parser
);
4487 val
= c_parser_expression (parser
).value
;
4488 mark_exp_read (val
);
4489 stmt
= c_finish_goto_ptr (loc
, val
);
4492 c_parser_error (parser
, "expected identifier or %<*%>");
4493 goto expect_semicolon
;
4495 c_parser_consume_token (parser
);
4496 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4497 goto expect_semicolon
;
4499 c_parser_consume_token (parser
);
4500 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4501 goto expect_semicolon
;
4503 c_parser_consume_token (parser
);
4504 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4506 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4507 c_parser_consume_token (parser
);
4511 struct c_expr expr
= c_parser_expression_conv (parser
);
4512 mark_exp_read (expr
.value
);
4513 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4514 goto expect_semicolon
;
4518 stmt
= c_parser_asm_statement (parser
);
4520 case RID_TRANSACTION_ATOMIC
:
4521 case RID_TRANSACTION_RELAXED
:
4522 stmt
= c_parser_transaction (parser
,
4523 c_parser_peek_token (parser
)->keyword
);
4525 case RID_TRANSACTION_CANCEL
:
4526 stmt
= c_parser_transaction_cancel (parser
);
4527 goto expect_semicolon
;
4529 gcc_assert (c_dialect_objc ());
4530 c_parser_consume_token (parser
);
4531 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4533 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4534 c_parser_consume_token (parser
);
4538 tree expr
= c_parser_expression (parser
).value
;
4539 expr
= c_fully_fold (expr
, false, NULL
);
4540 stmt
= objc_build_throw_stmt (loc
, expr
);
4541 goto expect_semicolon
;
4545 gcc_assert (c_dialect_objc ());
4546 c_parser_objc_try_catch_finally_statement (parser
);
4548 case RID_AT_SYNCHRONIZED
:
4549 gcc_assert (c_dialect_objc ());
4550 c_parser_objc_synchronized_statement (parser
);
4557 c_parser_consume_token (parser
);
4559 case CPP_CLOSE_PAREN
:
4560 case CPP_CLOSE_SQUARE
:
4561 /* Avoid infinite loop in error recovery:
4562 c_parser_skip_until_found stops at a closing nesting
4563 delimiter without consuming it, but here we need to consume
4564 it to proceed further. */
4565 c_parser_error (parser
, "expected statement");
4566 c_parser_consume_token (parser
);
4569 c_parser_pragma (parser
, pragma_stmt
);
4573 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4575 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4578 /* Two cases cannot and do not have line numbers associated: If stmt
4579 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4580 cannot hold line numbers. But that's OK because the statement
4581 will either be changed to a MODIFY_EXPR during gimplification of
4582 the statement expr, or discarded. If stmt was compound, but
4583 without new variables, we will have skipped the creation of a
4584 BIND and will have a bare STATEMENT_LIST. But that's OK because
4585 (recursively) all of the component statements should already have
4586 line numbers assigned. ??? Can we discard no-op statements
4588 if (CAN_HAVE_LOCATION_P (stmt
)
4589 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4590 SET_EXPR_LOCATION (stmt
, loc
);
4592 parser
->in_if_block
= in_if_block
;
4595 /* Parse the condition from an if, do, while or for statements. */
4598 c_parser_condition (c_parser
*parser
)
4600 location_t loc
= c_parser_peek_token (parser
)->location
;
4602 cond
= c_parser_expression_conv (parser
).value
;
4603 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4604 cond
= c_fully_fold (cond
, false, NULL
);
4605 if (warn_sequence_point
)
4606 verify_sequence_points (cond
);
4610 /* Parse a parenthesized condition from an if, do or while statement.
4616 c_parser_paren_condition (c_parser
*parser
)
4619 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4620 return error_mark_node
;
4621 cond
= c_parser_condition (parser
);
4622 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4626 /* Parse a statement which is a block in C99. */
4629 c_parser_c99_block_statement (c_parser
*parser
)
4631 tree block
= c_begin_compound_stmt (flag_isoc99
);
4632 location_t loc
= c_parser_peek_token (parser
)->location
;
4633 c_parser_statement (parser
);
4634 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4637 /* Parse the body of an if statement. This is just parsing a
4638 statement but (a) it is a block in C99, (b) we track whether the
4639 body is an if statement for the sake of -Wparentheses warnings, (c)
4640 we handle an empty body specially for the sake of -Wempty-body
4641 warnings, and (d) we call parser_compound_statement directly
4642 because c_parser_statement_after_labels resets
4643 parser->in_if_block. */
4646 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4648 tree block
= c_begin_compound_stmt (flag_isoc99
);
4649 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4650 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4651 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4652 || (c_parser_next_token_is (parser
, CPP_NAME
)
4653 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4654 c_parser_label (parser
);
4655 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4656 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4658 location_t loc
= c_parser_peek_token (parser
)->location
;
4659 add_stmt (build_empty_stmt (loc
));
4660 c_parser_consume_token (parser
);
4661 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4662 warning_at (loc
, OPT_Wempty_body
,
4663 "suggest braces around empty body in an %<if%> statement");
4665 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4666 add_stmt (c_parser_compound_statement (parser
));
4668 c_parser_statement_after_labels (parser
);
4669 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4672 /* Parse the else body of an if statement. This is just parsing a
4673 statement but (a) it is a block in C99, (b) we handle an empty body
4674 specially for the sake of -Wempty-body warnings. */
4677 c_parser_else_body (c_parser
*parser
)
4679 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4680 tree block
= c_begin_compound_stmt (flag_isoc99
);
4681 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4682 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4683 || (c_parser_next_token_is (parser
, CPP_NAME
)
4684 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4685 c_parser_label (parser
);
4686 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4688 location_t loc
= c_parser_peek_token (parser
)->location
;
4691 "suggest braces around empty body in an %<else%> statement");
4692 add_stmt (build_empty_stmt (loc
));
4693 c_parser_consume_token (parser
);
4696 c_parser_statement_after_labels (parser
);
4697 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4700 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4703 if ( expression ) statement
4704 if ( expression ) statement else statement
4708 c_parser_if_statement (c_parser
*parser
)
4713 bool first_if
= false;
4714 tree first_body
, second_body
;
4717 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4718 c_parser_consume_token (parser
);
4719 block
= c_begin_compound_stmt (flag_isoc99
);
4720 loc
= c_parser_peek_token (parser
)->location
;
4721 cond
= c_parser_paren_condition (parser
);
4722 in_if_block
= parser
->in_if_block
;
4723 parser
->in_if_block
= true;
4724 first_body
= c_parser_if_body (parser
, &first_if
);
4725 parser
->in_if_block
= in_if_block
;
4726 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4728 c_parser_consume_token (parser
);
4729 second_body
= c_parser_else_body (parser
);
4732 second_body
= NULL_TREE
;
4733 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4734 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4737 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4740 switch (expression) statement
4744 c_parser_switch_statement (c_parser
*parser
)
4746 tree block
, expr
, body
, save_break
;
4747 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4748 location_t switch_cond_loc
;
4749 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4750 c_parser_consume_token (parser
);
4751 block
= c_begin_compound_stmt (flag_isoc99
);
4752 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4754 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4755 expr
= c_parser_expression (parser
).value
;
4756 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4760 switch_cond_loc
= UNKNOWN_LOCATION
;
4761 expr
= error_mark_node
;
4763 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4764 save_break
= c_break_label
;
4765 c_break_label
= NULL_TREE
;
4766 body
= c_parser_c99_block_statement (parser
);
4767 c_finish_case (body
);
4770 location_t here
= c_parser_peek_token (parser
)->location
;
4771 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4772 SET_EXPR_LOCATION (t
, here
);
4775 c_break_label
= save_break
;
4776 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4779 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4782 while (expression) statement
4786 c_parser_while_statement (c_parser
*parser
)
4788 tree block
, cond
, body
, save_break
, save_cont
;
4790 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4791 c_parser_consume_token (parser
);
4792 block
= c_begin_compound_stmt (flag_isoc99
);
4793 loc
= c_parser_peek_token (parser
)->location
;
4794 cond
= c_parser_paren_condition (parser
);
4795 save_break
= c_break_label
;
4796 c_break_label
= NULL_TREE
;
4797 save_cont
= c_cont_label
;
4798 c_cont_label
= NULL_TREE
;
4799 body
= c_parser_c99_block_statement (parser
);
4800 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4801 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4802 c_break_label
= save_break
;
4803 c_cont_label
= save_cont
;
4806 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4809 do statement while ( expression ) ;
4813 c_parser_do_statement (c_parser
*parser
)
4815 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4817 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4818 c_parser_consume_token (parser
);
4819 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4820 warning_at (c_parser_peek_token (parser
)->location
,
4822 "suggest braces around empty body in %<do%> statement");
4823 block
= c_begin_compound_stmt (flag_isoc99
);
4824 loc
= c_parser_peek_token (parser
)->location
;
4825 save_break
= c_break_label
;
4826 c_break_label
= NULL_TREE
;
4827 save_cont
= c_cont_label
;
4828 c_cont_label
= NULL_TREE
;
4829 body
= c_parser_c99_block_statement (parser
);
4830 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4831 new_break
= c_break_label
;
4832 c_break_label
= save_break
;
4833 new_cont
= c_cont_label
;
4834 c_cont_label
= save_cont
;
4835 cond
= c_parser_paren_condition (parser
);
4836 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4837 c_parser_skip_to_end_of_block_or_statement (parser
);
4838 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4839 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4842 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4845 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4846 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4848 The form with a declaration is new in C99.
4850 ??? In accordance with the old parser, the declaration may be a
4851 nested function, which is then rejected in check_for_loop_decls,
4852 but does it make any sense for this to be included in the grammar?
4853 Note in particular that the nested function does not include a
4854 trailing ';', whereas the "declaration" production includes one.
4855 Also, can we reject bad declarations earlier and cheaper than
4856 check_for_loop_decls?
4858 In Objective-C, there are two additional variants:
4861 for ( expression in expresssion ) statement
4862 for ( declaration in expression ) statement
4864 This is inconsistent with C, because the second variant is allowed
4865 even if c99 is not enabled.
4867 The rest of the comment documents these Objective-C foreach-statement.
4869 Here is the canonical example of the first variant:
4870 for (object in array) { do something with object }
4871 we call the first expression ("object") the "object_expression" and
4872 the second expression ("array") the "collection_expression".
4873 object_expression must be an lvalue of type "id" (a generic Objective-C
4874 object) because the loop works by assigning to object_expression the
4875 various objects from the collection_expression. collection_expression
4876 must evaluate to something of type "id" which responds to the method
4877 countByEnumeratingWithState:objects:count:.
4879 The canonical example of the second variant is:
4880 for (id object in array) { do something with object }
4881 which is completely equivalent to
4884 for (object in array) { do something with object }
4886 Note that initizializing 'object' in some way (eg, "for ((object =
4887 xxx) in array) { do something with object }") is possibly
4888 technically valid, but completely pointless as 'object' will be
4889 assigned to something else as soon as the loop starts. We should
4890 most likely reject it (TODO).
4892 The beginning of the Objective-C foreach-statement looks exactly
4893 like the beginning of the for-statement, and we can tell it is a
4894 foreach-statement only because the initial declaration or
4895 expression is terminated by 'in' instead of ';'.
4899 c_parser_for_statement (c_parser
*parser
)
4901 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4902 /* The following are only used when parsing an ObjC foreach statement. */
4903 tree object_expression
;
4904 /* Silence the bogus uninitialized warning. */
4905 tree collection_expression
= NULL
;
4906 location_t loc
= c_parser_peek_token (parser
)->location
;
4907 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4908 bool is_foreach_statement
= false;
4909 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4910 c_parser_consume_token (parser
);
4911 /* Open a compound statement in Objective-C as well, just in case this is
4912 as foreach expression. */
4913 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4914 cond
= error_mark_node
;
4915 incr
= error_mark_node
;
4916 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4918 /* Parse the initialization declaration or expression. */
4919 object_expression
= error_mark_node
;
4920 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4921 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4923 parser
->objc_could_be_foreach_context
= false;
4924 c_parser_consume_token (parser
);
4925 c_finish_expr_stmt (loc
, NULL_TREE
);
4927 else if (c_parser_next_tokens_start_declaration (parser
))
4929 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4930 &object_expression
);
4931 parser
->objc_could_be_foreach_context
= false;
4933 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4935 c_parser_consume_token (parser
);
4936 is_foreach_statement
= true;
4937 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4938 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4941 check_for_loop_decls (for_loc
, flag_isoc99
);
4943 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4945 /* __extension__ can start a declaration, but is also an
4946 unary operator that can start an expression. Consume all
4947 but the last of a possible series of __extension__ to
4949 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4950 && (c_parser_peek_2nd_token (parser
)->keyword
4952 c_parser_consume_token (parser
);
4953 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4956 ext
= disable_extension_diagnostics ();
4957 c_parser_consume_token (parser
);
4958 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4959 true, &object_expression
);
4960 parser
->objc_could_be_foreach_context
= false;
4962 restore_extension_diagnostics (ext
);
4963 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4965 c_parser_consume_token (parser
);
4966 is_foreach_statement
= true;
4967 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4968 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4971 check_for_loop_decls (for_loc
, flag_isoc99
);
4980 tree init_expression
;
4981 init_expression
= c_parser_expression (parser
).value
;
4982 parser
->objc_could_be_foreach_context
= false;
4983 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4985 c_parser_consume_token (parser
);
4986 is_foreach_statement
= true;
4987 if (! lvalue_p (init_expression
))
4988 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
4989 object_expression
= c_fully_fold (init_expression
, false, NULL
);
4993 c_finish_expr_stmt (loc
, init_expression
);
4994 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4998 /* Parse the loop condition. In the case of a foreach
4999 statement, there is no loop condition. */
5000 gcc_assert (!parser
->objc_could_be_foreach_context
);
5001 if (!is_foreach_statement
)
5003 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5005 c_parser_consume_token (parser
);
5010 cond
= c_parser_condition (parser
);
5011 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5014 /* Parse the increment expression (the third expression in a
5015 for-statement). In the case of a foreach-statement, this is
5016 the expression that follows the 'in'. */
5017 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5019 if (is_foreach_statement
)
5021 c_parser_error (parser
, "missing collection in fast enumeration");
5022 collection_expression
= error_mark_node
;
5025 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5029 if (is_foreach_statement
)
5030 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5033 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5035 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5037 save_break
= c_break_label
;
5038 c_break_label
= NULL_TREE
;
5039 save_cont
= c_cont_label
;
5040 c_cont_label
= NULL_TREE
;
5041 body
= c_parser_c99_block_statement (parser
);
5042 if (is_foreach_statement
)
5043 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5045 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5046 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5047 c_break_label
= save_break
;
5048 c_cont_label
= save_cont
;
5051 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5052 statement with inputs, outputs, clobbers, and volatile tag
5056 asm type-qualifier[opt] ( asm-argument ) ;
5057 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5061 asm-string-literal : asm-operands[opt]
5062 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5063 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5066 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5069 Qualifiers other than volatile are accepted in the syntax but
5073 c_parser_asm_statement (c_parser
*parser
)
5075 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5076 bool simple
, is_goto
;
5077 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5078 int section
, nsections
;
5080 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5081 c_parser_consume_token (parser
);
5082 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5084 quals
= c_parser_peek_token (parser
)->value
;
5085 c_parser_consume_token (parser
);
5087 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5088 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5090 warning_at (c_parser_peek_token (parser
)->location
,
5092 "%E qualifier ignored on asm",
5093 c_parser_peek_token (parser
)->value
);
5095 c_parser_consume_token (parser
);
5101 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5103 c_parser_consume_token (parser
);
5107 /* ??? Follow the C++ parser rather than using the
5108 lex_untranslated_string kludge. */
5109 parser
->lex_untranslated_string
= true;
5112 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5115 str
= c_parser_asm_string_literal (parser
);
5116 if (str
== NULL_TREE
)
5117 goto error_close_paren
;
5120 outputs
= NULL_TREE
;
5122 clobbers
= NULL_TREE
;
5125 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5128 /* Parse each colon-delimited section of operands. */
5129 nsections
= 3 + is_goto
;
5130 for (section
= 0; section
< nsections
; ++section
)
5132 if (!c_parser_require (parser
, CPP_COLON
,
5135 : "expected %<:%> or %<)%>"))
5136 goto error_close_paren
;
5138 /* Once past any colon, we're no longer a simple asm. */
5141 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5142 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5147 /* For asm goto, we don't allow output operands, but reserve
5148 the slot for a future extension that does allow them. */
5150 outputs
= c_parser_asm_operands (parser
, false);
5153 inputs
= c_parser_asm_operands (parser
, true);
5156 clobbers
= c_parser_asm_clobbers (parser
);
5159 labels
= c_parser_asm_goto_operands (parser
);
5165 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5170 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5172 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5176 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5177 c_parser_skip_to_end_of_block_or_statement (parser
);
5179 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5180 clobbers
, labels
, simple
));
5183 parser
->lex_untranslated_string
= false;
5187 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5191 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5192 not outputs), apply the default conversion of functions and arrays
5197 asm-operands , asm-operand
5200 asm-string-literal ( expression )
5201 [ identifier ] asm-string-literal ( expression )
5205 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
5207 tree list
= NULL_TREE
;
5213 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5215 c_parser_consume_token (parser
);
5216 if (c_parser_next_token_is (parser
, CPP_NAME
))
5218 tree id
= c_parser_peek_token (parser
)->value
;
5219 c_parser_consume_token (parser
);
5220 name
= build_string (IDENTIFIER_LENGTH (id
),
5221 IDENTIFIER_POINTER (id
));
5225 c_parser_error (parser
, "expected identifier");
5226 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5229 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5234 str
= c_parser_asm_string_literal (parser
);
5235 if (str
== NULL_TREE
)
5237 parser
->lex_untranslated_string
= false;
5238 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5240 parser
->lex_untranslated_string
= true;
5243 loc
= c_parser_peek_token (parser
)->location
;
5244 expr
= c_parser_expression (parser
);
5245 mark_exp_read (expr
.value
);
5247 expr
= default_function_array_conversion (loc
, expr
);
5248 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5249 parser
->lex_untranslated_string
= true;
5250 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5252 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5255 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5257 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5258 c_parser_consume_token (parser
);
5265 /* Parse asm clobbers, a GNU extension.
5269 asm-clobbers , asm-string-literal
5273 c_parser_asm_clobbers (c_parser
*parser
)
5275 tree list
= NULL_TREE
;
5278 tree str
= c_parser_asm_string_literal (parser
);
5280 list
= tree_cons (NULL_TREE
, str
, list
);
5283 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5284 c_parser_consume_token (parser
);
5291 /* Parse asm goto labels, a GNU extension.
5295 asm-goto-operands , identifier
5299 c_parser_asm_goto_operands (c_parser
*parser
)
5301 tree list
= NULL_TREE
;
5306 if (c_parser_next_token_is (parser
, CPP_NAME
))
5308 c_token
*tok
= c_parser_peek_token (parser
);
5310 label
= lookup_label_for_goto (tok
->location
, name
);
5311 c_parser_consume_token (parser
);
5312 TREE_USED (label
) = 1;
5316 c_parser_error (parser
, "expected identifier");
5320 name
= build_string (IDENTIFIER_LENGTH (name
),
5321 IDENTIFIER_POINTER (name
));
5322 list
= tree_cons (name
, label
, list
);
5323 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5324 c_parser_consume_token (parser
);
5326 return nreverse (list
);
5330 /* Parse an expression other than a compound expression; that is, an
5331 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5332 NULL then it is an Objective-C message expression which is the
5333 primary-expression starting the expression as an initializer.
5335 assignment-expression:
5336 conditional-expression
5337 unary-expression assignment-operator assignment-expression
5339 assignment-operator: one of
5340 = *= /= %= += -= <<= >>= &= ^= |=
5342 In GNU C we accept any conditional expression on the LHS and
5343 diagnose the invalid lvalue rather than producing a syntax
5346 static struct c_expr
5347 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5349 struct c_expr lhs
, rhs
, ret
;
5350 enum tree_code code
;
5351 location_t op_location
, exp_location
;
5352 gcc_assert (!after
|| c_dialect_objc ());
5353 lhs
= c_parser_conditional_expression (parser
, after
);
5354 op_location
= c_parser_peek_token (parser
)->location
;
5355 switch (c_parser_peek_token (parser
)->type
)
5364 code
= TRUNC_DIV_EXPR
;
5367 code
= TRUNC_MOD_EXPR
;
5382 code
= BIT_AND_EXPR
;
5385 code
= BIT_XOR_EXPR
;
5388 code
= BIT_IOR_EXPR
;
5393 c_parser_consume_token (parser
);
5394 exp_location
= c_parser_peek_token (parser
)->location
;
5395 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5396 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5397 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5398 code
, exp_location
, rhs
.value
,
5400 if (code
== NOP_EXPR
)
5401 ret
.original_code
= MODIFY_EXPR
;
5404 TREE_NO_WARNING (ret
.value
) = 1;
5405 ret
.original_code
= ERROR_MARK
;
5407 ret
.original_type
= NULL
;
5411 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5412 is not NULL then it is an Objective-C message expression which is
5413 the primary-expression starting the expression as an initializer.
5415 conditional-expression:
5416 logical-OR-expression
5417 logical-OR-expression ? expression : conditional-expression
5421 conditional-expression:
5422 logical-OR-expression ? : conditional-expression
5425 static struct c_expr
5426 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5428 struct c_expr cond
, exp1
, exp2
, ret
;
5429 location_t cond_loc
, colon_loc
, middle_loc
;
5431 gcc_assert (!after
|| c_dialect_objc ());
5433 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5435 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5437 cond_loc
= c_parser_peek_token (parser
)->location
;
5438 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5439 c_parser_consume_token (parser
);
5440 if (c_parser_next_token_is (parser
, CPP_COLON
))
5442 tree eptype
= NULL_TREE
;
5444 middle_loc
= c_parser_peek_token (parser
)->location
;
5445 pedwarn (middle_loc
, OPT_Wpedantic
,
5446 "ISO C forbids omitting the middle term of a ?: expression");
5447 warn_for_omitted_condop (middle_loc
, cond
.value
);
5448 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5450 eptype
= TREE_TYPE (cond
.value
);
5451 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5453 /* Make sure first operand is calculated only once. */
5454 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5456 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5457 exp1
.original_type
= NULL
;
5458 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5459 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5464 = c_objc_common_truthvalue_conversion
5465 (cond_loc
, default_conversion (cond
.value
));
5466 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5467 exp1
= c_parser_expression_conv (parser
);
5468 mark_exp_read (exp1
.value
);
5469 c_inhibit_evaluation_warnings
+=
5470 ((cond
.value
== truthvalue_true_node
)
5471 - (cond
.value
== truthvalue_false_node
));
5474 colon_loc
= c_parser_peek_token (parser
)->location
;
5475 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5477 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5478 ret
.value
= error_mark_node
;
5479 ret
.original_code
= ERROR_MARK
;
5480 ret
.original_type
= NULL
;
5484 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5485 exp2
= c_parser_conditional_expression (parser
, NULL
);
5486 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5488 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5489 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5490 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5491 exp1
.value
, exp1
.original_type
,
5492 exp2
.value
, exp2
.original_type
);
5493 ret
.original_code
= ERROR_MARK
;
5494 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5495 ret
.original_type
= NULL
;
5500 /* If both sides are enum type, the default conversion will have
5501 made the type of the result be an integer type. We want to
5502 remember the enum types we started with. */
5503 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5504 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5505 ret
.original_type
= ((t1
!= error_mark_node
5506 && t2
!= error_mark_node
5507 && (TYPE_MAIN_VARIANT (t1
)
5508 == TYPE_MAIN_VARIANT (t2
)))
5515 /* Parse a binary expression; that is, a logical-OR-expression (C90
5516 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5517 an Objective-C message expression which is the primary-expression
5518 starting the expression as an initializer. PREC is the starting
5519 precedence, usually PREC_NONE.
5521 multiplicative-expression:
5523 multiplicative-expression * cast-expression
5524 multiplicative-expression / cast-expression
5525 multiplicative-expression % cast-expression
5527 additive-expression:
5528 multiplicative-expression
5529 additive-expression + multiplicative-expression
5530 additive-expression - multiplicative-expression
5534 shift-expression << additive-expression
5535 shift-expression >> additive-expression
5537 relational-expression:
5539 relational-expression < shift-expression
5540 relational-expression > shift-expression
5541 relational-expression <= shift-expression
5542 relational-expression >= shift-expression
5544 equality-expression:
5545 relational-expression
5546 equality-expression == relational-expression
5547 equality-expression != relational-expression
5551 AND-expression & equality-expression
5553 exclusive-OR-expression:
5555 exclusive-OR-expression ^ AND-expression
5557 inclusive-OR-expression:
5558 exclusive-OR-expression
5559 inclusive-OR-expression | exclusive-OR-expression
5561 logical-AND-expression:
5562 inclusive-OR-expression
5563 logical-AND-expression && inclusive-OR-expression
5565 logical-OR-expression:
5566 logical-AND-expression
5567 logical-OR-expression || logical-AND-expression
5570 static struct c_expr
5571 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5572 enum c_parser_prec prec
)
5574 /* A binary expression is parsed using operator-precedence parsing,
5575 with the operands being cast expressions. All the binary
5576 operators are left-associative. Thus a binary expression is of
5579 E0 op1 E1 op2 E2 ...
5581 which we represent on a stack. On the stack, the precedence
5582 levels are strictly increasing. When a new operator is
5583 encountered of higher precedence than that at the top of the
5584 stack, it is pushed; its LHS is the top expression, and its RHS
5585 is everything parsed until it is popped. When a new operator is
5586 encountered with precedence less than or equal to that at the top
5587 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5588 by the result of the operation until the operator at the top of
5589 the stack has lower precedence than the new operator or there is
5590 only one element on the stack; then the top expression is the LHS
5591 of the new operator. In the case of logical AND and OR
5592 expressions, we also need to adjust c_inhibit_evaluation_warnings
5593 as appropriate when the operators are pushed and popped. */
5596 /* The expression at this stack level. */
5598 /* The precedence of the operator on its left, PREC_NONE at the
5599 bottom of the stack. */
5600 enum c_parser_prec prec
;
5601 /* The operation on its left. */
5603 /* The source location of this operation. */
5607 /* Location of the binary operator. */
5608 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5611 switch (stack[sp].op) \
5613 case TRUTH_ANDIF_EXPR: \
5614 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5615 == truthvalue_false_node); \
5617 case TRUTH_ORIF_EXPR: \
5618 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5619 == truthvalue_true_node); \
5624 stack[sp - 1].expr \
5625 = default_function_array_read_conversion (stack[sp - 1].loc, \
5626 stack[sp - 1].expr); \
5628 = default_function_array_read_conversion (stack[sp].loc, \
5630 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5632 stack[sp - 1].expr, \
5636 gcc_assert (!after
|| c_dialect_objc ());
5637 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5638 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5639 stack
[0].prec
= prec
;
5643 enum c_parser_prec oprec
;
5644 enum tree_code ocode
;
5647 switch (c_parser_peek_token (parser
)->type
)
5655 ocode
= TRUNC_DIV_EXPR
;
5659 ocode
= TRUNC_MOD_EXPR
;
5671 ocode
= LSHIFT_EXPR
;
5675 ocode
= RSHIFT_EXPR
;
5689 case CPP_GREATER_EQ
:
5702 oprec
= PREC_BITAND
;
5703 ocode
= BIT_AND_EXPR
;
5706 oprec
= PREC_BITXOR
;
5707 ocode
= BIT_XOR_EXPR
;
5711 ocode
= BIT_IOR_EXPR
;
5714 oprec
= PREC_LOGAND
;
5715 ocode
= TRUTH_ANDIF_EXPR
;
5719 ocode
= TRUTH_ORIF_EXPR
;
5722 /* Not a binary operator, so end of the binary
5726 binary_loc
= c_parser_peek_token (parser
)->location
;
5727 while (oprec
<= stack
[sp
].prec
)
5733 c_parser_consume_token (parser
);
5736 case TRUTH_ANDIF_EXPR
:
5738 = default_function_array_read_conversion (stack
[sp
].loc
,
5740 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5741 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5742 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5743 == truthvalue_false_node
);
5745 case TRUTH_ORIF_EXPR
:
5747 = default_function_array_read_conversion (stack
[sp
].loc
,
5749 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5750 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5751 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5752 == truthvalue_true_node
);
5758 stack
[sp
].loc
= binary_loc
;
5759 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5760 stack
[sp
].prec
= oprec
;
5761 stack
[sp
].op
= ocode
;
5762 stack
[sp
].loc
= binary_loc
;
5767 return stack
[0].expr
;
5771 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5772 NULL then it is an Objective-C message expression which is the
5773 primary-expression starting the expression as an initializer.
5777 ( type-name ) unary-expression
5780 static struct c_expr
5781 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5783 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5784 gcc_assert (!after
|| c_dialect_objc ());
5786 return c_parser_postfix_expression_after_primary (parser
,
5788 /* If the expression begins with a parenthesized type name, it may
5789 be either a cast or a compound literal; we need to see whether
5790 the next character is '{' to tell the difference. If not, it is
5791 an unary expression. Full detection of unknown typenames here
5792 would require a 3-token lookahead. */
5793 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5794 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5796 struct c_type_name
*type_name
;
5799 c_parser_consume_token (parser
);
5800 type_name
= c_parser_type_name (parser
);
5801 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5802 if (type_name
== NULL
)
5804 ret
.value
= error_mark_node
;
5805 ret
.original_code
= ERROR_MARK
;
5806 ret
.original_type
= NULL
;
5810 /* Save casted types in the function's used types hash table. */
5811 used_types_insert (type_name
->specs
->type
);
5813 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5814 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5817 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5818 expr
= c_parser_cast_expression (parser
, NULL
);
5819 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5821 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5822 ret
.original_code
= ERROR_MARK
;
5823 ret
.original_type
= NULL
;
5827 return c_parser_unary_expression (parser
);
5830 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5836 unary-operator cast-expression
5837 sizeof unary-expression
5838 sizeof ( type-name )
5840 unary-operator: one of
5846 __alignof__ unary-expression
5847 __alignof__ ( type-name )
5850 (C11 permits _Alignof with type names only.)
5852 unary-operator: one of
5853 __extension__ __real__ __imag__
5855 Transactional Memory:
5858 transaction-expression
5860 In addition, the GNU syntax treats ++ and -- as unary operators, so
5861 they may be applied to cast expressions with errors for non-lvalues
5864 static struct c_expr
5865 c_parser_unary_expression (c_parser
*parser
)
5868 struct c_expr ret
, op
;
5869 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5871 ret
.original_code
= ERROR_MARK
;
5872 ret
.original_type
= NULL
;
5873 switch (c_parser_peek_token (parser
)->type
)
5876 c_parser_consume_token (parser
);
5877 exp_loc
= c_parser_peek_token (parser
)->location
;
5878 op
= c_parser_cast_expression (parser
, NULL
);
5879 op
= default_function_array_read_conversion (exp_loc
, op
);
5880 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5881 case CPP_MINUS_MINUS
:
5882 c_parser_consume_token (parser
);
5883 exp_loc
= c_parser_peek_token (parser
)->location
;
5884 op
= c_parser_cast_expression (parser
, NULL
);
5885 op
= default_function_array_read_conversion (exp_loc
, op
);
5886 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5888 c_parser_consume_token (parser
);
5889 op
= c_parser_cast_expression (parser
, NULL
);
5890 mark_exp_read (op
.value
);
5891 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5893 c_parser_consume_token (parser
);
5894 exp_loc
= c_parser_peek_token (parser
)->location
;
5895 op
= c_parser_cast_expression (parser
, NULL
);
5896 op
= default_function_array_read_conversion (exp_loc
, op
);
5897 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5900 if (!c_dialect_objc () && !in_system_header
)
5903 "traditional C rejects the unary plus operator");
5904 c_parser_consume_token (parser
);
5905 exp_loc
= c_parser_peek_token (parser
)->location
;
5906 op
= c_parser_cast_expression (parser
, NULL
);
5907 op
= default_function_array_read_conversion (exp_loc
, op
);
5908 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5910 c_parser_consume_token (parser
);
5911 exp_loc
= c_parser_peek_token (parser
)->location
;
5912 op
= c_parser_cast_expression (parser
, NULL
);
5913 op
= default_function_array_read_conversion (exp_loc
, op
);
5914 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5916 c_parser_consume_token (parser
);
5917 exp_loc
= c_parser_peek_token (parser
)->location
;
5918 op
= c_parser_cast_expression (parser
, NULL
);
5919 op
= default_function_array_read_conversion (exp_loc
, op
);
5920 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5922 c_parser_consume_token (parser
);
5923 exp_loc
= c_parser_peek_token (parser
)->location
;
5924 op
= c_parser_cast_expression (parser
, NULL
);
5925 op
= default_function_array_read_conversion (exp_loc
, op
);
5926 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5928 /* Refer to the address of a label as a pointer. */
5929 c_parser_consume_token (parser
);
5930 if (c_parser_next_token_is (parser
, CPP_NAME
))
5932 ret
.value
= finish_label_address_expr
5933 (c_parser_peek_token (parser
)->value
, op_loc
);
5934 c_parser_consume_token (parser
);
5938 c_parser_error (parser
, "expected identifier");
5939 ret
.value
= error_mark_node
;
5943 switch (c_parser_peek_token (parser
)->keyword
)
5946 return c_parser_sizeof_expression (parser
);
5948 return c_parser_alignof_expression (parser
);
5950 c_parser_consume_token (parser
);
5951 ext
= disable_extension_diagnostics ();
5952 ret
= c_parser_cast_expression (parser
, NULL
);
5953 restore_extension_diagnostics (ext
);
5956 c_parser_consume_token (parser
);
5957 exp_loc
= c_parser_peek_token (parser
)->location
;
5958 op
= c_parser_cast_expression (parser
, NULL
);
5959 op
= default_function_array_conversion (exp_loc
, op
);
5960 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5962 c_parser_consume_token (parser
);
5963 exp_loc
= c_parser_peek_token (parser
)->location
;
5964 op
= c_parser_cast_expression (parser
, NULL
);
5965 op
= default_function_array_conversion (exp_loc
, op
);
5966 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5967 case RID_TRANSACTION_ATOMIC
:
5968 case RID_TRANSACTION_RELAXED
:
5969 return c_parser_transaction_expression (parser
,
5970 c_parser_peek_token (parser
)->keyword
);
5972 return c_parser_postfix_expression (parser
);
5975 return c_parser_postfix_expression (parser
);
5979 /* Parse a sizeof expression. */
5981 static struct c_expr
5982 c_parser_sizeof_expression (c_parser
*parser
)
5985 location_t expr_loc
;
5986 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5987 c_parser_consume_token (parser
);
5988 c_inhibit_evaluation_warnings
++;
5990 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5991 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5993 /* Either sizeof ( type-name ) or sizeof unary-expression
5994 starting with a compound literal. */
5995 struct c_type_name
*type_name
;
5996 c_parser_consume_token (parser
);
5997 expr_loc
= c_parser_peek_token (parser
)->location
;
5998 type_name
= c_parser_type_name (parser
);
5999 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6000 if (type_name
== NULL
)
6003 c_inhibit_evaluation_warnings
--;
6005 ret
.value
= error_mark_node
;
6006 ret
.original_code
= ERROR_MARK
;
6007 ret
.original_type
= NULL
;
6010 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6012 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6017 /* sizeof ( type-name ). */
6018 c_inhibit_evaluation_warnings
--;
6020 return c_expr_sizeof_type (expr_loc
, type_name
);
6024 expr_loc
= c_parser_peek_token (parser
)->location
;
6025 expr
= c_parser_unary_expression (parser
);
6027 c_inhibit_evaluation_warnings
--;
6029 mark_exp_read (expr
.value
);
6030 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6031 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6032 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6033 return c_expr_sizeof_expr (expr_loc
, expr
);
6037 /* Parse an alignof expression. */
6039 static struct c_expr
6040 c_parser_alignof_expression (c_parser
*parser
)
6043 location_t loc
= c_parser_peek_token (parser
)->location
;
6044 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6045 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6046 /* A diagnostic is not required for the use of this identifier in
6047 the implementation namespace; only diagnose it for the C11
6048 spelling because of existing code using the other spellings. */
6050 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6053 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6056 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6059 c_parser_consume_token (parser
);
6060 c_inhibit_evaluation_warnings
++;
6062 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6063 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6065 /* Either __alignof__ ( type-name ) or __alignof__
6066 unary-expression starting with a compound literal. */
6068 struct c_type_name
*type_name
;
6070 c_parser_consume_token (parser
);
6071 loc
= c_parser_peek_token (parser
)->location
;
6072 type_name
= c_parser_type_name (parser
);
6073 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6074 if (type_name
== NULL
)
6077 c_inhibit_evaluation_warnings
--;
6079 ret
.value
= error_mark_node
;
6080 ret
.original_code
= ERROR_MARK
;
6081 ret
.original_type
= NULL
;
6084 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6086 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6091 /* alignof ( type-name ). */
6092 c_inhibit_evaluation_warnings
--;
6094 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6095 ret
.original_code
= ERROR_MARK
;
6096 ret
.original_type
= NULL
;
6102 expr
= c_parser_unary_expression (parser
);
6104 mark_exp_read (expr
.value
);
6105 c_inhibit_evaluation_warnings
--;
6107 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6109 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6110 ret
.original_code
= ERROR_MARK
;
6111 ret
.original_type
= NULL
;
6116 /* Helper function to read arguments of builtins which are interfaces
6117 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6118 others. The name of the builtin is passed using BNAME parameter.
6119 Function returns true if there were no errors while parsing and
6120 stores the arguments in CEXPR_LIST. */
6122 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6123 VEC(c_expr_t
,gc
) **ret_cexpr_list
)
6125 location_t loc
= c_parser_peek_token (parser
)->location
;
6126 VEC (c_expr_t
,gc
) *cexpr_list
;
6129 *ret_cexpr_list
= NULL
;
6130 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6132 error_at (loc
, "cannot take address of %qs", bname
);
6136 c_parser_consume_token (parser
);
6138 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6140 c_parser_consume_token (parser
);
6144 expr
= c_parser_expr_no_commas (parser
, NULL
);
6145 cexpr_list
= VEC_alloc (c_expr_t
, gc
, 1);
6146 C_EXPR_APPEND (cexpr_list
, expr
);
6147 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6149 c_parser_consume_token (parser
);
6150 expr
= c_parser_expr_no_commas (parser
, NULL
);
6151 C_EXPR_APPEND (cexpr_list
, expr
);
6154 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6157 *ret_cexpr_list
= cexpr_list
;
6162 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6166 postfix-expression [ expression ]
6167 postfix-expression ( argument-expression-list[opt] )
6168 postfix-expression . identifier
6169 postfix-expression -> identifier
6170 postfix-expression ++
6171 postfix-expression --
6172 ( type-name ) { initializer-list }
6173 ( type-name ) { initializer-list , }
6175 argument-expression-list:
6177 argument-expression-list , argument-expression
6189 (treated as a keyword in GNU C)
6192 ( compound-statement )
6193 __builtin_va_arg ( assignment-expression , type-name )
6194 __builtin_offsetof ( type-name , offsetof-member-designator )
6195 __builtin_choose_expr ( assignment-expression ,
6196 assignment-expression ,
6197 assignment-expression )
6198 __builtin_types_compatible_p ( type-name , type-name )
6199 __builtin_complex ( assignment-expression , assignment-expression )
6200 __builtin_shuffle ( assignment-expression , assignment-expression )
6201 __builtin_shuffle ( assignment-expression ,
6202 assignment-expression ,
6203 assignment-expression, )
6205 offsetof-member-designator:
6207 offsetof-member-designator . identifier
6208 offsetof-member-designator [ expression ]
6213 [ objc-receiver objc-message-args ]
6214 @selector ( objc-selector-arg )
6215 @protocol ( identifier )
6216 @encode ( type-name )
6218 Classname . identifier
6221 static struct c_expr
6222 c_parser_postfix_expression (c_parser
*parser
)
6224 struct c_expr expr
, e1
;
6225 struct c_type_name
*t1
, *t2
;
6226 location_t loc
= c_parser_peek_token (parser
)->location
;;
6227 expr
.original_code
= ERROR_MARK
;
6228 expr
.original_type
= NULL
;
6229 switch (c_parser_peek_token (parser
)->type
)
6232 expr
.value
= c_parser_peek_token (parser
)->value
;
6233 loc
= c_parser_peek_token (parser
)->location
;
6234 c_parser_consume_token (parser
);
6235 if (TREE_CODE (expr
.value
) == FIXED_CST
6236 && !targetm
.fixed_point_supported_p ())
6238 error_at (loc
, "fixed-point types not supported for this target");
6239 expr
.value
= error_mark_node
;
6246 expr
.value
= c_parser_peek_token (parser
)->value
;
6247 c_parser_consume_token (parser
);
6253 case CPP_UTF8STRING
:
6254 expr
.value
= c_parser_peek_token (parser
)->value
;
6255 expr
.original_code
= STRING_CST
;
6256 c_parser_consume_token (parser
);
6258 case CPP_OBJC_STRING
:
6259 gcc_assert (c_dialect_objc ());
6261 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6262 c_parser_consume_token (parser
);
6265 switch (c_parser_peek_token (parser
)->id_kind
)
6269 tree id
= c_parser_peek_token (parser
)->value
;
6270 c_parser_consume_token (parser
);
6271 expr
.value
= build_external_ref (loc
, id
,
6272 (c_parser_peek_token (parser
)->type
6274 &expr
.original_type
);
6277 case C_ID_CLASSNAME
:
6279 /* Here we parse the Objective-C 2.0 Class.name dot
6281 tree class_name
= c_parser_peek_token (parser
)->value
;
6283 c_parser_consume_token (parser
);
6284 gcc_assert (c_dialect_objc ());
6285 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6287 expr
.value
= error_mark_node
;
6290 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6292 c_parser_error (parser
, "expected identifier");
6293 expr
.value
= error_mark_node
;
6296 component
= c_parser_peek_token (parser
)->value
;
6297 c_parser_consume_token (parser
);
6298 expr
.value
= objc_build_class_component_ref (class_name
,
6303 c_parser_error (parser
, "expected expression");
6304 expr
.value
= error_mark_node
;
6308 case CPP_OPEN_PAREN
:
6309 /* A parenthesized expression, statement expression or compound
6311 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6313 /* A statement expression. */
6315 location_t brace_loc
;
6316 c_parser_consume_token (parser
);
6317 brace_loc
= c_parser_peek_token (parser
)->location
;
6318 c_parser_consume_token (parser
);
6319 if (!building_stmt_list_p ())
6321 error_at (loc
, "braced-group within expression allowed "
6322 "only inside a function");
6323 parser
->error
= true;
6324 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6325 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6326 expr
.value
= error_mark_node
;
6329 stmt
= c_begin_stmt_expr ();
6330 c_parser_compound_statement_nostart (parser
);
6331 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6333 pedwarn (loc
, OPT_Wpedantic
,
6334 "ISO C forbids braced-groups within expressions");
6335 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6336 mark_exp_read (expr
.value
);
6338 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6340 /* A compound literal. ??? Can we actually get here rather
6341 than going directly to
6342 c_parser_postfix_expression_after_paren_type from
6345 struct c_type_name
*type_name
;
6346 c_parser_consume_token (parser
);
6347 loc
= c_parser_peek_token (parser
)->location
;
6348 type_name
= c_parser_type_name (parser
);
6349 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6351 if (type_name
== NULL
)
6353 expr
.value
= error_mark_node
;
6356 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6362 /* A parenthesized expression. */
6363 c_parser_consume_token (parser
);
6364 expr
= c_parser_expression (parser
);
6365 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6366 TREE_NO_WARNING (expr
.value
) = 1;
6367 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6368 expr
.original_code
= ERROR_MARK
;
6369 /* Don't change EXPR.ORIGINAL_TYPE. */
6370 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6375 switch (c_parser_peek_token (parser
)->keyword
)
6377 case RID_FUNCTION_NAME
:
6378 case RID_PRETTY_FUNCTION_NAME
:
6379 case RID_C99_FUNCTION_NAME
:
6380 expr
.value
= fname_decl (loc
,
6381 c_parser_peek_token (parser
)->keyword
,
6382 c_parser_peek_token (parser
)->value
);
6383 c_parser_consume_token (parser
);
6386 c_parser_consume_token (parser
);
6387 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6389 expr
.value
= error_mark_node
;
6392 e1
= c_parser_expr_no_commas (parser
, NULL
);
6393 mark_exp_read (e1
.value
);
6394 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6395 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6397 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6398 expr
.value
= error_mark_node
;
6401 loc
= c_parser_peek_token (parser
)->location
;
6402 t1
= c_parser_type_name (parser
);
6403 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6407 expr
.value
= error_mark_node
;
6411 tree type_expr
= NULL_TREE
;
6412 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6413 groktypename (t1
, &type_expr
, NULL
));
6416 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6417 TREE_TYPE (expr
.value
), type_expr
,
6419 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6424 c_parser_consume_token (parser
);
6425 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6427 expr
.value
= error_mark_node
;
6430 t1
= c_parser_type_name (parser
);
6432 parser
->error
= true;
6433 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6434 gcc_assert (parser
->error
);
6437 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6438 expr
.value
= error_mark_node
;
6443 tree type
= groktypename (t1
, NULL
, NULL
);
6445 if (type
== error_mark_node
)
6446 offsetof_ref
= error_mark_node
;
6449 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6450 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6452 /* Parse the second argument to __builtin_offsetof. We
6453 must have one identifier, and beyond that we want to
6454 accept sub structure and sub array references. */
6455 if (c_parser_next_token_is (parser
, CPP_NAME
))
6457 offsetof_ref
= build_component_ref
6458 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6459 c_parser_consume_token (parser
);
6460 while (c_parser_next_token_is (parser
, CPP_DOT
)
6461 || c_parser_next_token_is (parser
,
6463 || c_parser_next_token_is (parser
,
6466 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6468 loc
= c_parser_peek_token (parser
)->location
;
6469 offsetof_ref
= build_array_ref (loc
,
6474 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6477 c_parser_consume_token (parser
);
6478 if (c_parser_next_token_is_not (parser
,
6481 c_parser_error (parser
, "expected identifier");
6484 offsetof_ref
= build_component_ref
6486 c_parser_peek_token (parser
)->value
);
6487 c_parser_consume_token (parser
);
6492 loc
= c_parser_peek_token (parser
)->location
;
6493 c_parser_consume_token (parser
);
6494 idx
= c_parser_expression (parser
).value
;
6495 idx
= c_fully_fold (idx
, false, NULL
);
6496 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6498 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6503 c_parser_error (parser
, "expected identifier");
6504 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6506 expr
.value
= fold_offsetof (offsetof_ref
);
6509 case RID_CHOOSE_EXPR
:
6511 VEC (c_expr_t
, gc
) *cexpr_list
;
6512 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6515 c_parser_consume_token (parser
);
6516 if (!c_parser_get_builtin_args (parser
,
6517 "__builtin_choose_expr",
6520 expr
.value
= error_mark_node
;
6524 if (VEC_length (c_expr_t
, cexpr_list
) != 3)
6526 error_at (loc
, "wrong number of arguments to "
6527 "%<__builtin_choose_expr%>");
6528 expr
.value
= error_mark_node
;
6532 e1_p
= VEC_index (c_expr_t
, cexpr_list
, 0);
6533 e2_p
= VEC_index (c_expr_t
, cexpr_list
, 1);
6534 e3_p
= VEC_index (c_expr_t
, cexpr_list
, 2);
6537 mark_exp_read (e2_p
->value
);
6538 mark_exp_read (e3_p
->value
);
6539 if (TREE_CODE (c
) != INTEGER_CST
6540 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6542 "first argument to %<__builtin_choose_expr%> not"
6544 constant_expression_warning (c
);
6545 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6548 case RID_TYPES_COMPATIBLE_P
:
6549 c_parser_consume_token (parser
);
6550 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6552 expr
.value
= error_mark_node
;
6555 t1
= c_parser_type_name (parser
);
6558 expr
.value
= error_mark_node
;
6561 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6563 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6564 expr
.value
= error_mark_node
;
6567 t2
= c_parser_type_name (parser
);
6570 expr
.value
= error_mark_node
;
6573 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6577 e1
= groktypename (t1
, NULL
, NULL
);
6578 e2
= groktypename (t2
, NULL
, NULL
);
6579 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6581 expr
.value
= error_mark_node
;
6585 e1
= TYPE_MAIN_VARIANT (e1
);
6586 e2
= TYPE_MAIN_VARIANT (e2
);
6589 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6592 case RID_BUILTIN_COMPLEX
:
6594 VEC(c_expr_t
, gc
) *cexpr_list
;
6595 c_expr_t
*e1_p
, *e2_p
;
6597 c_parser_consume_token (parser
);
6598 if (!c_parser_get_builtin_args (parser
,
6599 "__builtin_complex",
6602 expr
.value
= error_mark_node
;
6606 if (VEC_length (c_expr_t
, cexpr_list
) != 2)
6608 error_at (loc
, "wrong number of arguments to "
6609 "%<__builtin_complex%>");
6610 expr
.value
= error_mark_node
;
6614 e1_p
= VEC_index (c_expr_t
, cexpr_list
, 0);
6615 e2_p
= VEC_index (c_expr_t
, cexpr_list
, 1);
6617 mark_exp_read (e1_p
->value
);
6618 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
6619 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
6620 TREE_OPERAND (e1_p
->value
, 0));
6621 mark_exp_read (e2_p
->value
);
6622 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
6623 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
6624 TREE_OPERAND (e2_p
->value
, 0));
6625 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6626 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6627 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
6628 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
6630 error_at (loc
, "%<__builtin_complex%> operand "
6631 "not of real binary floating-point type");
6632 expr
.value
= error_mark_node
;
6635 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
6636 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
6639 "%<__builtin_complex%> operands of different types");
6640 expr
.value
= error_mark_node
;
6644 pedwarn (loc
, OPT_Wpedantic
,
6645 "ISO C90 does not support complex types");
6646 expr
.value
= build2 (COMPLEX_EXPR
,
6649 (TREE_TYPE (e1_p
->value
))),
6650 e1_p
->value
, e2_p
->value
);
6653 case RID_BUILTIN_SHUFFLE
:
6655 VEC(c_expr_t
,gc
) *cexpr_list
;
6659 c_parser_consume_token (parser
);
6660 if (!c_parser_get_builtin_args (parser
,
6661 "__builtin_shuffle",
6664 expr
.value
= error_mark_node
;
6668 FOR_EACH_VEC_ELT (c_expr_t
, cexpr_list
, i
, p
)
6669 mark_exp_read (p
->value
);
6671 if (VEC_length (c_expr_t
, cexpr_list
) == 2)
6673 c_build_vec_perm_expr
6674 (loc
, VEC_index (c_expr_t
, cexpr_list
, 0)->value
,
6675 NULL_TREE
, VEC_index (c_expr_t
, cexpr_list
, 1)->value
);
6677 else if (VEC_length (c_expr_t
, cexpr_list
) == 3)
6679 c_build_vec_perm_expr
6680 (loc
, VEC_index (c_expr_t
, cexpr_list
, 0)->value
,
6681 VEC_index (c_expr_t
, cexpr_list
, 1)->value
,
6682 VEC_index (c_expr_t
, cexpr_list
, 2)->value
);
6685 error_at (loc
, "wrong number of arguments to "
6686 "%<__builtin_shuffle%>");
6687 expr
.value
= error_mark_node
;
6691 case RID_AT_SELECTOR
:
6692 gcc_assert (c_dialect_objc ());
6693 c_parser_consume_token (parser
);
6694 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6696 expr
.value
= error_mark_node
;
6700 tree sel
= c_parser_objc_selector_arg (parser
);
6701 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6703 expr
.value
= objc_build_selector_expr (loc
, sel
);
6706 case RID_AT_PROTOCOL
:
6707 gcc_assert (c_dialect_objc ());
6708 c_parser_consume_token (parser
);
6709 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6711 expr
.value
= error_mark_node
;
6714 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6716 c_parser_error (parser
, "expected identifier");
6717 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6718 expr
.value
= error_mark_node
;
6722 tree id
= c_parser_peek_token (parser
)->value
;
6723 c_parser_consume_token (parser
);
6724 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6726 expr
.value
= objc_build_protocol_expr (id
);
6730 /* Extension to support C-structures in the archiver. */
6731 gcc_assert (c_dialect_objc ());
6732 c_parser_consume_token (parser
);
6733 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6735 expr
.value
= error_mark_node
;
6738 t1
= c_parser_type_name (parser
);
6741 expr
.value
= error_mark_node
;
6742 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6745 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6748 tree type
= groktypename (t1
, NULL
, NULL
);
6749 expr
.value
= objc_build_encode_expr (type
);
6753 c_parser_error (parser
, "expected expression");
6754 expr
.value
= error_mark_node
;
6758 case CPP_OPEN_SQUARE
:
6759 if (c_dialect_objc ())
6761 tree receiver
, args
;
6762 c_parser_consume_token (parser
);
6763 receiver
= c_parser_objc_receiver (parser
);
6764 args
= c_parser_objc_message_args (parser
);
6765 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6767 expr
.value
= objc_build_message_expr (receiver
, args
);
6770 /* Else fall through to report error. */
6772 c_parser_error (parser
, "expected expression");
6773 expr
.value
= error_mark_node
;
6776 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6779 /* Parse a postfix expression after a parenthesized type name: the
6780 brace-enclosed initializer of a compound literal, possibly followed
6781 by some postfix operators. This is separate because it is not
6782 possible to tell until after the type name whether a cast
6783 expression has a cast or a compound literal, or whether the operand
6784 of sizeof is a parenthesized type name or starts with a compound
6785 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6786 location of the first token after the parentheses around the type
6789 static struct c_expr
6790 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6791 struct c_type_name
*type_name
,
6792 location_t type_loc
)
6798 location_t start_loc
;
6799 tree type_expr
= NULL_TREE
;
6800 bool type_expr_const
= true;
6801 check_compound_literal_type (type_loc
, type_name
);
6802 start_init (NULL_TREE
, NULL
, 0);
6803 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6804 start_loc
= c_parser_peek_token (parser
)->location
;
6805 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6807 error_at (type_loc
, "compound literal has variable size");
6808 type
= error_mark_node
;
6810 init
= c_parser_braced_init (parser
, type
, false);
6812 maybe_warn_string_init (type
, init
);
6814 if (type
!= error_mark_node
6815 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6816 && current_function_decl
)
6818 error ("compound literal qualified by address-space qualifier");
6819 type
= error_mark_node
;
6823 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
6824 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6825 ? CONSTRUCTOR_NON_CONST (init
.value
)
6826 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6827 non_const
|= !type_expr_const
;
6828 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6829 expr
.original_code
= ERROR_MARK
;
6830 expr
.original_type
= NULL
;
6833 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6835 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6836 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6840 gcc_assert (!non_const
);
6841 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6842 type_expr
, expr
.value
);
6845 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6848 /* Parse a postfix expression after the initial primary or compound
6849 literal; that is, parse a series of postfix operators.
6851 EXPR_LOC is the location of the primary expression. */
6853 static struct c_expr
6854 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6855 location_t expr_loc
,
6858 struct c_expr orig_expr
;
6860 VEC(tree
,gc
) *exprlist
;
6861 VEC(tree
,gc
) *origtypes
;
6864 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6865 switch (c_parser_peek_token (parser
)->type
)
6867 case CPP_OPEN_SQUARE
:
6868 /* Array reference. */
6869 c_parser_consume_token (parser
);
6870 idx
= c_parser_expression (parser
).value
;
6871 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6873 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6874 expr
.original_code
= ERROR_MARK
;
6875 expr
.original_type
= NULL
;
6877 case CPP_OPEN_PAREN
:
6878 /* Function call. */
6879 c_parser_consume_token (parser
);
6880 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6883 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
6884 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6887 mark_exp_read (expr
.value
);
6888 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6889 "(" after the FUNCNAME, which is what we have now. */
6890 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6892 expr
.original_code
= ERROR_MARK
;
6893 if (TREE_CODE (expr
.value
) == INTEGER_CST
6894 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6895 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6896 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6897 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6898 expr
.original_type
= NULL
;
6899 if (exprlist
!= NULL
)
6901 release_tree_vector (exprlist
);
6902 release_tree_vector (origtypes
);
6906 /* Structure element reference. */
6907 c_parser_consume_token (parser
);
6908 expr
= default_function_array_conversion (expr_loc
, expr
);
6909 if (c_parser_next_token_is (parser
, CPP_NAME
))
6910 ident
= c_parser_peek_token (parser
)->value
;
6913 c_parser_error (parser
, "expected identifier");
6914 expr
.value
= error_mark_node
;
6915 expr
.original_code
= ERROR_MARK
;
6916 expr
.original_type
= NULL
;
6919 c_parser_consume_token (parser
);
6920 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6921 expr
.original_code
= ERROR_MARK
;
6922 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6923 expr
.original_type
= NULL
;
6926 /* Remember the original type of a bitfield. */
6927 tree field
= TREE_OPERAND (expr
.value
, 1);
6928 if (TREE_CODE (field
) != FIELD_DECL
)
6929 expr
.original_type
= NULL
;
6931 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6935 /* Structure element reference. */
6936 c_parser_consume_token (parser
);
6937 expr
= default_function_array_conversion (expr_loc
, expr
);
6938 if (c_parser_next_token_is (parser
, CPP_NAME
))
6939 ident
= c_parser_peek_token (parser
)->value
;
6942 c_parser_error (parser
, "expected identifier");
6943 expr
.value
= error_mark_node
;
6944 expr
.original_code
= ERROR_MARK
;
6945 expr
.original_type
= NULL
;
6948 c_parser_consume_token (parser
);
6949 expr
.value
= build_component_ref (op_loc
,
6950 build_indirect_ref (op_loc
,
6954 expr
.original_code
= ERROR_MARK
;
6955 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6956 expr
.original_type
= NULL
;
6959 /* Remember the original type of a bitfield. */
6960 tree field
= TREE_OPERAND (expr
.value
, 1);
6961 if (TREE_CODE (field
) != FIELD_DECL
)
6962 expr
.original_type
= NULL
;
6964 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6968 /* Postincrement. */
6969 c_parser_consume_token (parser
);
6970 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6971 expr
.value
= build_unary_op (op_loc
,
6972 POSTINCREMENT_EXPR
, expr
.value
, 0);
6973 expr
.original_code
= ERROR_MARK
;
6974 expr
.original_type
= NULL
;
6976 case CPP_MINUS_MINUS
:
6977 /* Postdecrement. */
6978 c_parser_consume_token (parser
);
6979 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6980 expr
.value
= build_unary_op (op_loc
,
6981 POSTDECREMENT_EXPR
, expr
.value
, 0);
6982 expr
.original_code
= ERROR_MARK
;
6983 expr
.original_type
= NULL
;
6991 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6994 assignment-expression
6995 expression , assignment-expression
6998 static struct c_expr
6999 c_parser_expression (c_parser
*parser
)
7002 expr
= c_parser_expr_no_commas (parser
, NULL
);
7003 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7007 location_t loc
= c_parser_peek_token (parser
)->location
;
7008 location_t expr_loc
;
7009 c_parser_consume_token (parser
);
7010 expr_loc
= c_parser_peek_token (parser
)->location
;
7011 lhsval
= expr
.value
;
7012 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7013 lhsval
= TREE_OPERAND (lhsval
, 1);
7014 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7015 mark_exp_read (lhsval
);
7016 next
= c_parser_expr_no_commas (parser
, NULL
);
7017 next
= default_function_array_conversion (expr_loc
, next
);
7018 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7019 expr
.original_code
= COMPOUND_EXPR
;
7020 expr
.original_type
= next
.original_type
;
7025 /* Parse an expression and convert functions or arrays to
7028 static struct c_expr
7029 c_parser_expression_conv (c_parser
*parser
)
7032 location_t loc
= c_parser_peek_token (parser
)->location
;
7033 expr
= c_parser_expression (parser
);
7034 expr
= default_function_array_conversion (loc
, expr
);
7038 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7039 functions and arrays to pointers. If FOLD_P, fold the expressions.
7042 assignment-expression
7043 nonempty-expr-list , assignment-expression
7046 static VEC(tree
,gc
) *
7047 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7048 VEC(tree
,gc
) **p_orig_types
)
7051 VEC(tree
,gc
) *orig_types
;
7053 location_t loc
= c_parser_peek_token (parser
)->location
;
7055 ret
= make_tree_vector ();
7056 if (p_orig_types
== NULL
)
7059 orig_types
= make_tree_vector ();
7061 expr
= c_parser_expr_no_commas (parser
, NULL
);
7063 expr
= default_function_array_read_conversion (loc
, expr
);
7065 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7066 VEC_quick_push (tree
, ret
, expr
.value
);
7067 if (orig_types
!= NULL
)
7068 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
7069 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7071 c_parser_consume_token (parser
);
7072 loc
= c_parser_peek_token (parser
)->location
;
7073 expr
= c_parser_expr_no_commas (parser
, NULL
);
7075 expr
= default_function_array_read_conversion (loc
, expr
);
7077 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7078 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
7079 if (orig_types
!= NULL
)
7080 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
7082 if (orig_types
!= NULL
)
7083 *p_orig_types
= orig_types
;
7087 /* Parse Objective-C-specific constructs. */
7089 /* Parse an objc-class-definition.
7091 objc-class-definition:
7092 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7093 objc-class-instance-variables[opt] objc-methodprotolist @end
7094 @implementation identifier objc-superclass[opt]
7095 objc-class-instance-variables[opt]
7096 @interface identifier ( identifier ) objc-protocol-refs[opt]
7097 objc-methodprotolist @end
7098 @interface identifier ( ) objc-protocol-refs[opt]
7099 objc-methodprotolist @end
7100 @implementation identifier ( identifier )
7105 "@interface identifier (" must start "@interface identifier (
7106 identifier ) ...": objc-methodprotolist in the first production may
7107 not start with a parenthesized identifier as a declarator of a data
7108 definition with no declaration specifiers if the objc-superclass,
7109 objc-protocol-refs and objc-class-instance-variables are omitted. */
7112 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7117 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7119 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7124 c_parser_consume_token (parser
);
7125 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7127 c_parser_error (parser
, "expected identifier");
7130 id1
= c_parser_peek_token (parser
)->value
;
7131 c_parser_consume_token (parser
);
7132 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7134 /* We have a category or class extension. */
7136 tree proto
= NULL_TREE
;
7137 c_parser_consume_token (parser
);
7138 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7140 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7142 /* We have a class extension. */
7147 c_parser_error (parser
, "expected identifier or %<)%>");
7148 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7154 id2
= c_parser_peek_token (parser
)->value
;
7155 c_parser_consume_token (parser
);
7157 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7160 objc_start_category_implementation (id1
, id2
);
7163 if (c_parser_next_token_is (parser
, CPP_LESS
))
7164 proto
= c_parser_objc_protocol_refs (parser
);
7165 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7166 c_parser_objc_methodprotolist (parser
);
7167 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7168 objc_finish_interface ();
7171 if (c_parser_next_token_is (parser
, CPP_COLON
))
7173 c_parser_consume_token (parser
);
7174 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7176 c_parser_error (parser
, "expected identifier");
7179 superclass
= c_parser_peek_token (parser
)->value
;
7180 c_parser_consume_token (parser
);
7183 superclass
= NULL_TREE
;
7186 tree proto
= NULL_TREE
;
7187 if (c_parser_next_token_is (parser
, CPP_LESS
))
7188 proto
= c_parser_objc_protocol_refs (parser
);
7189 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7192 objc_start_class_implementation (id1
, superclass
);
7193 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7194 c_parser_objc_class_instance_variables (parser
);
7197 objc_continue_interface ();
7198 c_parser_objc_methodprotolist (parser
);
7199 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7200 objc_finish_interface ();
7204 objc_continue_implementation ();
7209 /* Parse objc-class-instance-variables.
7211 objc-class-instance-variables:
7212 { objc-instance-variable-decl-list[opt] }
7214 objc-instance-variable-decl-list:
7215 objc-visibility-spec
7216 objc-instance-variable-decl ;
7218 objc-instance-variable-decl-list objc-visibility-spec
7219 objc-instance-variable-decl-list objc-instance-variable-decl ;
7220 objc-instance-variable-decl-list ;
7222 objc-visibility-spec:
7227 objc-instance-variable-decl:
7232 c_parser_objc_class_instance_variables (c_parser
*parser
)
7234 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7235 c_parser_consume_token (parser
);
7236 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7239 /* Parse any stray semicolon. */
7240 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7242 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7244 c_parser_consume_token (parser
);
7247 /* Stop if at the end of the instance variables. */
7248 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7250 c_parser_consume_token (parser
);
7253 /* Parse any objc-visibility-spec. */
7254 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7256 c_parser_consume_token (parser
);
7257 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7260 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7262 c_parser_consume_token (parser
);
7263 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7266 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7268 c_parser_consume_token (parser
);
7269 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7272 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7274 c_parser_consume_token (parser
);
7275 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7278 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7280 c_parser_pragma (parser
, pragma_external
);
7284 /* Parse some comma-separated declarations. */
7285 decls
= c_parser_struct_declaration (parser
);
7288 /* There is a syntax error. We want to skip the offending
7289 tokens up to the next ';' (included) or '}'
7292 /* First, skip manually a ')' or ']'. This is because they
7293 reduce the nesting level, so c_parser_skip_until_found()
7294 wouldn't be able to skip past them. */
7295 c_token
*token
= c_parser_peek_token (parser
);
7296 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7297 c_parser_consume_token (parser
);
7299 /* Then, do the standard skipping. */
7300 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7302 /* We hopefully recovered. Start normal parsing again. */
7303 parser
->error
= false;
7308 /* Comma-separated instance variables are chained together
7309 in reverse order; add them one by one. */
7310 tree ivar
= nreverse (decls
);
7311 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7312 objc_add_instance_variable (copy_node (ivar
));
7314 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7318 /* Parse an objc-class-declaration.
7320 objc-class-declaration:
7321 @class identifier-list ;
7325 c_parser_objc_class_declaration (c_parser
*parser
)
7327 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7328 c_parser_consume_token (parser
);
7329 /* Any identifiers, including those declared as type names, are OK
7334 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7336 c_parser_error (parser
, "expected identifier");
7337 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7338 parser
->error
= false;
7341 id
= c_parser_peek_token (parser
)->value
;
7342 objc_declare_class (id
);
7343 c_parser_consume_token (parser
);
7344 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7345 c_parser_consume_token (parser
);
7349 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7352 /* Parse an objc-alias-declaration.
7354 objc-alias-declaration:
7355 @compatibility_alias identifier identifier ;
7359 c_parser_objc_alias_declaration (c_parser
*parser
)
7362 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7363 c_parser_consume_token (parser
);
7364 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7366 c_parser_error (parser
, "expected identifier");
7367 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7370 id1
= c_parser_peek_token (parser
)->value
;
7371 c_parser_consume_token (parser
);
7372 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7374 c_parser_error (parser
, "expected identifier");
7375 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7378 id2
= c_parser_peek_token (parser
)->value
;
7379 c_parser_consume_token (parser
);
7380 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7381 objc_declare_alias (id1
, id2
);
7384 /* Parse an objc-protocol-definition.
7386 objc-protocol-definition:
7387 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7388 @protocol identifier-list ;
7390 "@protocol identifier ;" should be resolved as "@protocol
7391 identifier-list ;": objc-methodprotolist may not start with a
7392 semicolon in the first alternative if objc-protocol-refs are
7396 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7398 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7400 c_parser_consume_token (parser
);
7401 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7403 c_parser_error (parser
, "expected identifier");
7406 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7407 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7409 /* Any identifiers, including those declared as type names, are
7414 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7416 c_parser_error (parser
, "expected identifier");
7419 id
= c_parser_peek_token (parser
)->value
;
7420 objc_declare_protocol (id
, attributes
);
7421 c_parser_consume_token (parser
);
7422 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7423 c_parser_consume_token (parser
);
7427 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7431 tree id
= c_parser_peek_token (parser
)->value
;
7432 tree proto
= NULL_TREE
;
7433 c_parser_consume_token (parser
);
7434 if (c_parser_next_token_is (parser
, CPP_LESS
))
7435 proto
= c_parser_objc_protocol_refs (parser
);
7436 parser
->objc_pq_context
= true;
7437 objc_start_protocol (id
, proto
, attributes
);
7438 c_parser_objc_methodprotolist (parser
);
7439 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7440 parser
->objc_pq_context
= false;
7441 objc_finish_interface ();
7445 /* Parse an objc-method-type.
7451 Return true if it is a class method (+) and false if it is
7452 an instance method (-).
7455 c_parser_objc_method_type (c_parser
*parser
)
7457 switch (c_parser_peek_token (parser
)->type
)
7460 c_parser_consume_token (parser
);
7463 c_parser_consume_token (parser
);
7470 /* Parse an objc-method-definition.
7472 objc-method-definition:
7473 objc-method-type objc-method-decl ;[opt] compound-statement
7477 c_parser_objc_method_definition (c_parser
*parser
)
7479 bool is_class_method
= c_parser_objc_method_type (parser
);
7480 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7481 parser
->objc_pq_context
= true;
7482 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7484 if (decl
== error_mark_node
)
7485 return; /* Bail here. */
7487 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7489 c_parser_consume_token (parser
);
7490 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7491 "extra semicolon in method definition specified");
7494 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7496 c_parser_error (parser
, "expected %<{%>");
7500 parser
->objc_pq_context
= false;
7501 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7503 add_stmt (c_parser_compound_statement (parser
));
7504 objc_finish_method_definition (current_function_decl
);
7508 /* This code is executed when we find a method definition
7509 outside of an @implementation context (or invalid for other
7510 reasons). Parse the method (to keep going) but do not emit
7513 c_parser_compound_statement (parser
);
7517 /* Parse an objc-methodprotolist.
7519 objc-methodprotolist:
7521 objc-methodprotolist objc-methodproto
7522 objc-methodprotolist declaration
7523 objc-methodprotolist ;
7527 The declaration is a data definition, which may be missing
7528 declaration specifiers under the same rules and diagnostics as
7529 other data definitions outside functions, and the stray semicolon
7530 is diagnosed the same way as a stray semicolon outside a
7534 c_parser_objc_methodprotolist (c_parser
*parser
)
7538 /* The list is terminated by @end. */
7539 switch (c_parser_peek_token (parser
)->type
)
7542 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7543 "ISO C does not allow extra %<;%> outside of a function");
7544 c_parser_consume_token (parser
);
7548 c_parser_objc_methodproto (parser
);
7551 c_parser_pragma (parser
, pragma_external
);
7556 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7558 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7559 c_parser_objc_at_property_declaration (parser
);
7560 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7562 objc_set_method_opt (true);
7563 c_parser_consume_token (parser
);
7565 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7567 objc_set_method_opt (false);
7568 c_parser_consume_token (parser
);
7571 c_parser_declaration_or_fndef (parser
, false, false, true,
7578 /* Parse an objc-methodproto.
7581 objc-method-type objc-method-decl ;
7585 c_parser_objc_methodproto (c_parser
*parser
)
7587 bool is_class_method
= c_parser_objc_method_type (parser
);
7588 tree decl
, attributes
= NULL_TREE
;
7590 /* Remember protocol qualifiers in prototypes. */
7591 parser
->objc_pq_context
= true;
7592 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7594 /* Forget protocol qualifiers now. */
7595 parser
->objc_pq_context
= false;
7597 /* Do not allow the presence of attributes to hide an erroneous
7598 method implementation in the interface section. */
7599 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7601 c_parser_error (parser
, "expected %<;%>");
7605 if (decl
!= error_mark_node
)
7606 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7608 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7611 /* If we are at a position that method attributes may be present, check that
7612 there are not any parsed already (a syntax error) and then collect any
7613 specified at the current location. Finally, if new attributes were present,
7614 check that the next token is legal ( ';' for decls and '{' for defs). */
7617 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7622 c_parser_error (parser
,
7623 "method attributes must be specified at the end only");
7624 *attributes
= NULL_TREE
;
7628 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7629 *attributes
= c_parser_attributes (parser
);
7631 /* If there were no attributes here, just report any earlier error. */
7632 if (*attributes
== NULL_TREE
|| bad
)
7635 /* If the attributes are followed by a ; or {, then just report any earlier
7637 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7638 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7641 /* We've got attributes, but not at the end. */
7642 c_parser_error (parser
,
7643 "expected %<;%> or %<{%> after method attribute definition");
7647 /* Parse an objc-method-decl.
7650 ( objc-type-name ) objc-selector
7652 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7653 objc-keyword-selector objc-optparmlist
7656 objc-keyword-selector:
7658 objc-keyword-selector objc-keyword-decl
7661 objc-selector : ( objc-type-name ) identifier
7662 objc-selector : identifier
7663 : ( objc-type-name ) identifier
7667 objc-optparms objc-optellipsis
7671 objc-opt-parms , parameter-declaration
7679 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7680 tree
*attributes
, tree
*expr
)
7682 tree type
= NULL_TREE
;
7684 tree parms
= NULL_TREE
;
7685 bool ellipsis
= false;
7686 bool attr_err
= false;
7688 *attributes
= NULL_TREE
;
7689 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7691 c_parser_consume_token (parser
);
7692 type
= c_parser_objc_type_name (parser
);
7693 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7695 sel
= c_parser_objc_selector (parser
);
7696 /* If there is no selector, or a colon follows, we have an
7697 objc-keyword-selector. If there is a selector, and a colon does
7698 not follow, that selector ends the objc-method-decl. */
7699 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7702 tree list
= NULL_TREE
;
7705 tree atype
= NULL_TREE
, id
, keyworddecl
;
7706 tree param_attr
= NULL_TREE
;
7707 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7709 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7711 c_parser_consume_token (parser
);
7712 atype
= c_parser_objc_type_name (parser
);
7713 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7716 /* New ObjC allows attributes on method parameters. */
7717 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7718 param_attr
= c_parser_attributes (parser
);
7719 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7721 c_parser_error (parser
, "expected identifier");
7722 return error_mark_node
;
7724 id
= c_parser_peek_token (parser
)->value
;
7725 c_parser_consume_token (parser
);
7726 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7727 list
= chainon (list
, keyworddecl
);
7728 tsel
= c_parser_objc_selector (parser
);
7729 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7733 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7735 /* Parse the optional parameter list. Optional Objective-C
7736 method parameters follow the C syntax, and may include '...'
7737 to denote a variable number of arguments. */
7738 parms
= make_node (TREE_LIST
);
7739 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7741 struct c_parm
*parm
;
7742 c_parser_consume_token (parser
);
7743 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7746 c_parser_consume_token (parser
);
7747 attr_err
|= c_parser_objc_maybe_method_attributes
7748 (parser
, attributes
) ;
7751 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7754 parms
= chainon (parms
,
7755 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
7760 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7764 c_parser_error (parser
, "objective-c method declaration is expected");
7765 return error_mark_node
;
7769 return error_mark_node
;
7771 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7774 /* Parse an objc-type-name.
7777 objc-type-qualifiers[opt] type-name
7778 objc-type-qualifiers[opt]
7780 objc-type-qualifiers:
7782 objc-type-qualifiers objc-type-qualifier
7784 objc-type-qualifier: one of
7785 in out inout bycopy byref oneway
7789 c_parser_objc_type_name (c_parser
*parser
)
7791 tree quals
= NULL_TREE
;
7792 struct c_type_name
*type_name
= NULL
;
7793 tree type
= NULL_TREE
;
7796 c_token
*token
= c_parser_peek_token (parser
);
7797 if (token
->type
== CPP_KEYWORD
7798 && (token
->keyword
== RID_IN
7799 || token
->keyword
== RID_OUT
7800 || token
->keyword
== RID_INOUT
7801 || token
->keyword
== RID_BYCOPY
7802 || token
->keyword
== RID_BYREF
7803 || token
->keyword
== RID_ONEWAY
))
7805 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7806 c_parser_consume_token (parser
);
7811 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7812 type_name
= c_parser_type_name (parser
);
7814 type
= groktypename (type_name
, NULL
, NULL
);
7816 /* If the type is unknown, and error has already been produced and
7817 we need to recover from the error. In that case, use NULL_TREE
7818 for the type, as if no type had been specified; this will use the
7819 default type ('id') which is good for error recovery. */
7820 if (type
== error_mark_node
)
7823 return build_tree_list (quals
, type
);
7826 /* Parse objc-protocol-refs.
7833 c_parser_objc_protocol_refs (c_parser
*parser
)
7835 tree list
= NULL_TREE
;
7836 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7837 c_parser_consume_token (parser
);
7838 /* Any identifiers, including those declared as type names, are OK
7843 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7845 c_parser_error (parser
, "expected identifier");
7848 id
= c_parser_peek_token (parser
)->value
;
7849 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7850 c_parser_consume_token (parser
);
7851 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7852 c_parser_consume_token (parser
);
7856 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7860 /* Parse an objc-try-catch-finally-statement.
7862 objc-try-catch-finally-statement:
7863 @try compound-statement objc-catch-list[opt]
7864 @try compound-statement objc-catch-list[opt] @finally compound-statement
7867 @catch ( objc-catch-parameter-declaration ) compound-statement
7868 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7870 objc-catch-parameter-declaration:
7871 parameter-declaration
7874 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7876 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7877 for C++. Keep them in sync. */
7880 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
7882 location_t location
;
7885 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7886 c_parser_consume_token (parser
);
7887 location
= c_parser_peek_token (parser
)->location
;
7888 objc_maybe_warn_exceptions (location
);
7889 stmt
= c_parser_compound_statement (parser
);
7890 objc_begin_try_stmt (location
, stmt
);
7892 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7894 struct c_parm
*parm
;
7895 tree parameter_declaration
= error_mark_node
;
7896 bool seen_open_paren
= false;
7898 c_parser_consume_token (parser
);
7899 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7900 seen_open_paren
= true;
7901 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7903 /* We have "@catch (...)" (where the '...' are literally
7904 what is in the code). Skip the '...'.
7905 parameter_declaration is set to NULL_TREE, and
7906 objc_being_catch_clauses() knows that that means
7908 c_parser_consume_token (parser
);
7909 parameter_declaration
= NULL_TREE
;
7913 /* We have "@catch (NSException *exception)" or something
7914 like that. Parse the parameter declaration. */
7915 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7917 parameter_declaration
= error_mark_node
;
7919 parameter_declaration
= grokparm (parm
, NULL
);
7921 if (seen_open_paren
)
7922 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7925 /* If there was no open parenthesis, we are recovering from
7926 an error, and we are trying to figure out what mistake
7927 the user has made. */
7929 /* If there is an immediate closing parenthesis, the user
7930 probably forgot the opening one (ie, they typed "@catch
7931 NSException *e)". Parse the closing parenthesis and keep
7933 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7934 c_parser_consume_token (parser
);
7936 /* If these is no immediate closing parenthesis, the user
7937 probably doesn't know that parenthesis are required at
7938 all (ie, they typed "@catch NSException *e"). So, just
7939 forget about the closing parenthesis and keep going. */
7941 objc_begin_catch_clause (parameter_declaration
);
7942 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7943 c_parser_compound_statement_nostart (parser
);
7944 objc_finish_catch_clause ();
7946 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
7948 c_parser_consume_token (parser
);
7949 location
= c_parser_peek_token (parser
)->location
;
7950 stmt
= c_parser_compound_statement (parser
);
7951 objc_build_finally_clause (location
, stmt
);
7953 objc_finish_try_stmt ();
7956 /* Parse an objc-synchronized-statement.
7958 objc-synchronized-statement:
7959 @synchronized ( expression ) compound-statement
7963 c_parser_objc_synchronized_statement (c_parser
*parser
)
7967 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
7968 c_parser_consume_token (parser
);
7969 loc
= c_parser_peek_token (parser
)->location
;
7970 objc_maybe_warn_exceptions (loc
);
7971 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7973 expr
= c_parser_expression (parser
).value
;
7974 expr
= c_fully_fold (expr
, false, NULL
);
7975 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7978 expr
= error_mark_node
;
7979 stmt
= c_parser_compound_statement (parser
);
7980 objc_build_synchronized (loc
, expr
, stmt
);
7983 /* Parse an objc-selector; return NULL_TREE without an error if the
7984 next token is not an objc-selector.
7989 enum struct union if else while do for switch case default
7990 break continue return goto asm sizeof typeof __alignof
7991 unsigned long const short volatile signed restrict _Complex
7992 in out inout bycopy byref oneway int char float double void _Bool
7994 ??? Why this selection of keywords but not, for example, storage
7995 class specifiers? */
7998 c_parser_objc_selector (c_parser
*parser
)
8000 c_token
*token
= c_parser_peek_token (parser
);
8001 tree value
= token
->value
;
8002 if (token
->type
== CPP_NAME
)
8004 c_parser_consume_token (parser
);
8007 if (token
->type
!= CPP_KEYWORD
)
8009 switch (token
->keyword
)
8051 c_parser_consume_token (parser
);
8058 /* Parse an objc-selector-arg.
8062 objc-keywordname-list
8064 objc-keywordname-list:
8066 objc-keywordname-list objc-keywordname
8074 c_parser_objc_selector_arg (c_parser
*parser
)
8076 tree sel
= c_parser_objc_selector (parser
);
8077 tree list
= NULL_TREE
;
8078 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8082 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8084 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8085 sel
= c_parser_objc_selector (parser
);
8086 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8092 /* Parse an objc-receiver.
8101 c_parser_objc_receiver (c_parser
*parser
)
8103 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8104 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8105 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8107 tree id
= c_parser_peek_token (parser
)->value
;
8108 c_parser_consume_token (parser
);
8109 return objc_get_class_reference (id
);
8111 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8114 /* Parse objc-message-args.
8118 objc-keywordarg-list
8120 objc-keywordarg-list:
8122 objc-keywordarg-list objc-keywordarg
8125 objc-selector : objc-keywordexpr
8130 c_parser_objc_message_args (c_parser
*parser
)
8132 tree sel
= c_parser_objc_selector (parser
);
8133 tree list
= NULL_TREE
;
8134 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8139 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8140 return error_mark_node
;
8141 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8142 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8143 sel
= c_parser_objc_selector (parser
);
8144 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8150 /* Parse an objc-keywordexpr.
8157 c_parser_objc_keywordexpr (c_parser
*parser
)
8160 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
8161 if (VEC_length (tree
, expr_list
) == 1)
8163 /* Just return the expression, remove a level of
8165 ret
= VEC_index (tree
, expr_list
, 0);
8169 /* We have a comma expression, we will collapse later. */
8170 ret
= build_tree_list_vec (expr_list
);
8172 release_tree_vector (expr_list
);
8176 /* A check, needed in several places, that ObjC interface, implementation or
8177 method definitions are not prefixed by incorrect items. */
8179 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8180 struct c_declspecs
*specs
)
8182 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8183 || specs
->typespec_kind
!= ctsk_none
)
8185 c_parser_error (parser
,
8186 "no type or storage class may be specified here,");
8187 c_parser_skip_to_end_of_block_or_statement (parser
);
8193 /* Parse an Objective-C @property declaration. The syntax is:
8195 objc-property-declaration:
8196 '@property' objc-property-attributes[opt] struct-declaration ;
8198 objc-property-attributes:
8199 '(' objc-property-attribute-list ')'
8201 objc-property-attribute-list:
8202 objc-property-attribute
8203 objc-property-attribute-list, objc-property-attribute
8205 objc-property-attribute
8206 'getter' = identifier
8207 'setter' = identifier
8216 @property NSString *name;
8217 @property (readonly) id object;
8218 @property (retain, nonatomic, getter=getTheName) id name;
8219 @property int a, b, c;
8221 PS: This function is identical to cp_parser_objc_at_propery_declaration
8222 for C++. Keep them in sync. */
8224 c_parser_objc_at_property_declaration (c_parser
*parser
)
8226 /* The following variables hold the attributes of the properties as
8227 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8228 seen. When we see an attribute, we set them to 'true' (if they
8229 are boolean properties) or to the identifier (if they have an
8230 argument, ie, for getter and setter). Note that here we only
8231 parse the list of attributes, check the syntax and accumulate the
8232 attributes that we find. objc_add_property_declaration() will
8233 then process the information. */
8234 bool property_assign
= false;
8235 bool property_copy
= false;
8236 tree property_getter_ident
= NULL_TREE
;
8237 bool property_nonatomic
= false;
8238 bool property_readonly
= false;
8239 bool property_readwrite
= false;
8240 bool property_retain
= false;
8241 tree property_setter_ident
= NULL_TREE
;
8243 /* 'properties' is the list of properties that we read. Usually a
8244 single one, but maybe more (eg, in "@property int a, b, c;" there
8249 loc
= c_parser_peek_token (parser
)->location
;
8250 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8252 c_parser_consume_token (parser
); /* Eat '@property'. */
8254 /* Parse the optional attribute list... */
8255 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8258 c_parser_consume_token (parser
);
8260 /* Property attribute keywords are valid now. */
8261 parser
->objc_property_attr_context
= true;
8265 bool syntax_error
= false;
8266 c_token
*token
= c_parser_peek_token (parser
);
8269 if (token
->type
!= CPP_KEYWORD
)
8271 if (token
->type
== CPP_CLOSE_PAREN
)
8272 c_parser_error (parser
, "expected identifier");
8275 c_parser_consume_token (parser
);
8276 c_parser_error (parser
, "unknown property attribute");
8280 keyword
= token
->keyword
;
8281 c_parser_consume_token (parser
);
8284 case RID_ASSIGN
: property_assign
= true; break;
8285 case RID_COPY
: property_copy
= true; break;
8286 case RID_NONATOMIC
: property_nonatomic
= true; break;
8287 case RID_READONLY
: property_readonly
= true; break;
8288 case RID_READWRITE
: property_readwrite
= true; break;
8289 case RID_RETAIN
: property_retain
= true; break;
8293 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8295 if (keyword
== RID_GETTER
)
8296 c_parser_error (parser
,
8297 "missing %<=%> (after %<getter%> attribute)");
8299 c_parser_error (parser
,
8300 "missing %<=%> (after %<setter%> attribute)");
8301 syntax_error
= true;
8304 c_parser_consume_token (parser
); /* eat the = */
8305 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8307 c_parser_error (parser
, "expected identifier");
8308 syntax_error
= true;
8311 if (keyword
== RID_SETTER
)
8313 if (property_setter_ident
!= NULL_TREE
)
8314 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8316 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8317 c_parser_consume_token (parser
);
8318 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8319 c_parser_error (parser
, "setter name must terminate with %<:%>");
8321 c_parser_consume_token (parser
);
8325 if (property_getter_ident
!= NULL_TREE
)
8326 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8328 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8329 c_parser_consume_token (parser
);
8333 c_parser_error (parser
, "unknown property attribute");
8334 syntax_error
= true;
8341 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8342 c_parser_consume_token (parser
);
8346 parser
->objc_property_attr_context
= false;
8347 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8349 /* ... and the property declaration(s). */
8350 properties
= c_parser_struct_declaration (parser
);
8352 if (properties
== error_mark_node
)
8354 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8355 parser
->error
= false;
8359 if (properties
== NULL_TREE
)
8360 c_parser_error (parser
, "expected identifier");
8363 /* Comma-separated properties are chained together in
8364 reverse order; add them one by one. */
8365 properties
= nreverse (properties
);
8367 for (; properties
; properties
= TREE_CHAIN (properties
))
8368 objc_add_property_declaration (loc
, copy_node (properties
),
8369 property_readonly
, property_readwrite
,
8370 property_assign
, property_retain
,
8371 property_copy
, property_nonatomic
,
8372 property_getter_ident
, property_setter_ident
);
8375 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8376 parser
->error
= false;
8379 /* Parse an Objective-C @synthesize declaration. The syntax is:
8381 objc-synthesize-declaration:
8382 @synthesize objc-synthesize-identifier-list ;
8384 objc-synthesize-identifier-list:
8385 objc-synthesize-identifier
8386 objc-synthesize-identifier-list, objc-synthesize-identifier
8388 objc-synthesize-identifier
8390 identifier = identifier
8393 @synthesize MyProperty;
8394 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8396 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8397 for C++. Keep them in sync.
8400 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8402 tree list
= NULL_TREE
;
8404 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8405 loc
= c_parser_peek_token (parser
)->location
;
8407 c_parser_consume_token (parser
);
8410 tree property
, ivar
;
8411 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8413 c_parser_error (parser
, "expected identifier");
8414 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8415 /* Once we find the semicolon, we can resume normal parsing.
8416 We have to reset parser->error manually because
8417 c_parser_skip_until_found() won't reset it for us if the
8418 next token is precisely a semicolon. */
8419 parser
->error
= false;
8422 property
= c_parser_peek_token (parser
)->value
;
8423 c_parser_consume_token (parser
);
8424 if (c_parser_next_token_is (parser
, CPP_EQ
))
8426 c_parser_consume_token (parser
);
8427 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8429 c_parser_error (parser
, "expected identifier");
8430 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8431 parser
->error
= false;
8434 ivar
= c_parser_peek_token (parser
)->value
;
8435 c_parser_consume_token (parser
);
8439 list
= chainon (list
, build_tree_list (ivar
, property
));
8440 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8441 c_parser_consume_token (parser
);
8445 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8446 objc_add_synthesize_declaration (loc
, list
);
8449 /* Parse an Objective-C @dynamic declaration. The syntax is:
8451 objc-dynamic-declaration:
8452 @dynamic identifier-list ;
8455 @dynamic MyProperty;
8456 @dynamic MyProperty, AnotherProperty;
8458 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8459 for C++. Keep them in sync.
8462 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8464 tree list
= NULL_TREE
;
8466 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8467 loc
= c_parser_peek_token (parser
)->location
;
8469 c_parser_consume_token (parser
);
8473 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8475 c_parser_error (parser
, "expected identifier");
8476 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8477 parser
->error
= false;
8480 property
= c_parser_peek_token (parser
)->value
;
8481 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8482 c_parser_consume_token (parser
);
8483 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8484 c_parser_consume_token (parser
);
8488 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8489 objc_add_dynamic_declaration (loc
, list
);
8493 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8494 should be considered, statements. ALLOW_STMT is true if we're within
8495 the context of a function and such pragmas are to be allowed. Returns
8496 true if we actually parsed such a pragma. */
8499 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8503 id
= c_parser_peek_token (parser
)->pragma_kind
;
8504 gcc_assert (id
!= PRAGMA_NONE
);
8508 case PRAGMA_OMP_BARRIER
:
8509 if (context
!= pragma_compound
)
8511 if (context
== pragma_stmt
)
8512 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8513 "used in compound statements");
8516 c_parser_omp_barrier (parser
);
8519 case PRAGMA_OMP_FLUSH
:
8520 if (context
!= pragma_compound
)
8522 if (context
== pragma_stmt
)
8523 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8524 "used in compound statements");
8527 c_parser_omp_flush (parser
);
8530 case PRAGMA_OMP_TASKWAIT
:
8531 if (context
!= pragma_compound
)
8533 if (context
== pragma_stmt
)
8534 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8535 "used in compound statements");
8538 c_parser_omp_taskwait (parser
);
8541 case PRAGMA_OMP_TASKYIELD
:
8542 if (context
!= pragma_compound
)
8544 if (context
== pragma_stmt
)
8545 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
8546 "used in compound statements");
8549 c_parser_omp_taskyield (parser
);
8552 case PRAGMA_OMP_THREADPRIVATE
:
8553 c_parser_omp_threadprivate (parser
);
8556 case PRAGMA_OMP_SECTION
:
8557 error_at (c_parser_peek_token (parser
)->location
,
8558 "%<#pragma omp section%> may only be used in "
8559 "%<#pragma omp sections%> construct");
8560 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8563 case PRAGMA_GCC_PCH_PREPROCESS
:
8564 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8565 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8569 if (id
< PRAGMA_FIRST_EXTERNAL
)
8571 if (context
== pragma_external
)
8574 c_parser_error (parser
, "expected declaration specifiers");
8575 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8578 c_parser_omp_construct (parser
);
8584 c_parser_consume_pragma (parser
);
8585 c_invoke_pragma_handler (id
);
8587 /* Skip to EOL, but suppress any error message. Those will have been
8588 generated by the handler routine through calling error, as opposed
8589 to calling c_parser_error. */
8590 parser
->error
= true;
8591 c_parser_skip_to_pragma_eol (parser
);
8596 /* The interface the pragma parsers have to the lexer. */
8599 pragma_lex (tree
*value
)
8601 c_token
*tok
= c_parser_peek_token (the_parser
);
8602 enum cpp_ttype ret
= tok
->type
;
8604 *value
= tok
->value
;
8605 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8609 if (ret
== CPP_KEYWORD
)
8611 c_parser_consume_token (the_parser
);
8618 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8622 c_parser_consume_pragma (parser
);
8623 if (c_parser_next_token_is (parser
, CPP_STRING
))
8625 name
= c_parser_peek_token (parser
)->value
;
8626 c_parser_consume_token (parser
);
8629 c_parser_error (parser
, "expected string literal");
8630 c_parser_skip_to_pragma_eol (parser
);
8633 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8636 /* OpenMP 2.5 parsing routines. */
8638 /* Returns name of the next clause.
8639 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8640 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8641 returned and the token is consumed. */
8643 static pragma_omp_clause
8644 c_parser_omp_clause_name (c_parser
*parser
)
8646 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8648 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8649 result
= PRAGMA_OMP_CLAUSE_IF
;
8650 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8651 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8652 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8654 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8659 if (!strcmp ("collapse", p
))
8660 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8661 else if (!strcmp ("copyin", p
))
8662 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8663 else if (!strcmp ("copyprivate", p
))
8664 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8667 if (!strcmp ("final", p
))
8668 result
= PRAGMA_OMP_CLAUSE_FINAL
;
8669 else if (!strcmp ("firstprivate", p
))
8670 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8673 if (!strcmp ("lastprivate", p
))
8674 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8677 if (!strcmp ("mergeable", p
))
8678 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
8681 if (!strcmp ("nowait", p
))
8682 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8683 else if (!strcmp ("num_threads", p
))
8684 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8687 if (!strcmp ("ordered", p
))
8688 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8691 if (!strcmp ("private", p
))
8692 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8695 if (!strcmp ("reduction", p
))
8696 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8699 if (!strcmp ("schedule", p
))
8700 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8701 else if (!strcmp ("shared", p
))
8702 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8705 if (!strcmp ("untied", p
))
8706 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8711 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8712 c_parser_consume_token (parser
);
8717 /* Validate that a clause of the given type does not already exist. */
8720 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8725 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8726 if (OMP_CLAUSE_CODE (c
) == code
)
8728 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8729 error_at (loc
, "too many %qs clauses", name
);
8737 variable-list , identifier
8739 If KIND is nonzero, create the appropriate node and install the
8740 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8741 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8743 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8744 return the list created. */
8747 c_parser_omp_variable_list (c_parser
*parser
,
8748 location_t clause_loc
,
8749 enum omp_clause_code kind
,
8752 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8753 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8754 c_parser_error (parser
, "expected identifier");
8756 while (c_parser_next_token_is (parser
, CPP_NAME
)
8757 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8759 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8762 undeclared_variable (c_parser_peek_token (parser
)->location
,
8763 c_parser_peek_token (parser
)->value
);
8764 else if (t
== error_mark_node
)
8768 tree u
= build_omp_clause (clause_loc
, kind
);
8769 OMP_CLAUSE_DECL (u
) = t
;
8770 OMP_CLAUSE_CHAIN (u
) = list
;
8774 list
= tree_cons (t
, NULL_TREE
, list
);
8776 c_parser_consume_token (parser
);
8778 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8781 c_parser_consume_token (parser
);
8787 /* Similarly, but expect leading and trailing parenthesis. This is a very
8788 common case for omp clauses. */
8791 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8794 /* The clauses location. */
8795 location_t loc
= c_parser_peek_token (parser
)->location
;
8797 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8799 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8800 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8806 collapse ( constant-expression ) */
8809 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8811 tree c
, num
= error_mark_node
;
8815 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8817 loc
= c_parser_peek_token (parser
)->location
;
8818 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8820 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8821 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8823 if (num
== error_mark_node
)
8825 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8826 || !host_integerp (num
, 0)
8827 || (n
= tree_low_cst (num
, 0)) <= 0
8831 "collapse argument needs positive constant integer expression");
8834 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8835 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
8836 OMP_CLAUSE_CHAIN (c
) = list
;
8841 copyin ( variable-list ) */
8844 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
8846 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
8850 copyprivate ( variable-list ) */
8853 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
8855 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
8859 default ( shared | none ) */
8862 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
8864 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
8865 location_t loc
= c_parser_peek_token (parser
)->location
;
8868 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8870 if (c_parser_next_token_is (parser
, CPP_NAME
))
8872 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8877 if (strcmp ("none", p
) != 0)
8879 kind
= OMP_CLAUSE_DEFAULT_NONE
;
8883 if (strcmp ("shared", p
) != 0)
8885 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
8892 c_parser_consume_token (parser
);
8897 c_parser_error (parser
, "expected %<none%> or %<shared%>");
8899 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8901 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
8904 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
8905 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
8906 OMP_CLAUSE_CHAIN (c
) = list
;
8907 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
8913 firstprivate ( variable-list ) */
8916 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
8918 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
8922 final ( expression ) */
8925 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
8927 location_t loc
= c_parser_peek_token (parser
)->location
;
8928 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8930 tree t
= c_parser_paren_condition (parser
);
8933 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
8935 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
8936 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
8937 OMP_CLAUSE_CHAIN (c
) = list
;
8941 c_parser_error (parser
, "expected %<(%>");
8947 if ( expression ) */
8950 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
8952 location_t loc
= c_parser_peek_token (parser
)->location
;
8953 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8955 tree t
= c_parser_paren_condition (parser
);
8958 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
8960 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
8961 OMP_CLAUSE_IF_EXPR (c
) = t
;
8962 OMP_CLAUSE_CHAIN (c
) = list
;
8966 c_parser_error (parser
, "expected %<(%>");
8972 lastprivate ( variable-list ) */
8975 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
8977 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
8984 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8988 /* FIXME: Should we allow duplicates? */
8989 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
8991 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8992 OMP_CLAUSE_MERGEABLE
);
8993 OMP_CLAUSE_CHAIN (c
) = list
;
9002 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9005 location_t loc
= c_parser_peek_token (parser
)->location
;
9007 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9009 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9010 OMP_CLAUSE_CHAIN (c
) = list
;
9015 num_threads ( expression ) */
9018 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9020 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9021 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9023 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9024 tree c
, t
= c_parser_expression (parser
).value
;
9026 t
= c_fully_fold (t
, false, NULL
);
9028 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9030 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9032 c_parser_error (parser
, "expected integer expression");
9036 /* Attempt to statically determine when the number isn't positive. */
9037 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9038 build_int_cst (TREE_TYPE (t
), 0));
9039 if (CAN_HAVE_LOCATION_P (c
))
9040 SET_EXPR_LOCATION (c
, expr_loc
);
9041 if (c
== boolean_true_node
)
9043 warning_at (expr_loc
, 0,
9044 "%<num_threads%> value must be positive");
9045 t
= integer_one_node
;
9048 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9050 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9051 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9052 OMP_CLAUSE_CHAIN (c
) = list
;
9063 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9067 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9069 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9070 OMP_CLAUSE_ORDERED
);
9071 OMP_CLAUSE_CHAIN (c
) = list
;
9077 private ( variable-list ) */
9080 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9082 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9086 reduction ( reduction-operator : variable-list )
9089 One of: + * - & ^ | && ||
9094 One of: + * - & ^ | && || max min */
9097 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9099 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9100 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9102 enum tree_code code
;
9104 switch (c_parser_peek_token (parser
)->type
)
9116 code
= BIT_AND_EXPR
;
9119 code
= BIT_XOR_EXPR
;
9122 code
= BIT_IOR_EXPR
;
9125 code
= TRUTH_ANDIF_EXPR
;
9128 code
= TRUTH_ORIF_EXPR
;
9133 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9134 if (strcmp (p
, "min") == 0)
9139 if (strcmp (p
, "max") == 0)
9147 c_parser_error (parser
,
9148 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9149 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9150 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9153 c_parser_consume_token (parser
);
9154 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9158 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9159 OMP_CLAUSE_REDUCTION
, list
);
9160 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9161 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9165 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9171 schedule ( schedule-kind )
9172 schedule ( schedule-kind , expression )
9175 static | dynamic | guided | runtime | auto
9179 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9182 location_t loc
= c_parser_peek_token (parser
)->location
;
9184 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9187 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9189 if (c_parser_next_token_is (parser
, CPP_NAME
))
9191 tree kind
= c_parser_peek_token (parser
)->value
;
9192 const char *p
= IDENTIFIER_POINTER (kind
);
9197 if (strcmp ("dynamic", p
) != 0)
9199 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9203 if (strcmp ("guided", p
) != 0)
9205 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9209 if (strcmp ("runtime", p
) != 0)
9211 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9218 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9219 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9220 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9221 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9225 c_parser_consume_token (parser
);
9226 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9229 c_parser_consume_token (parser
);
9231 here
= c_parser_peek_token (parser
)->location
;
9232 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9234 t
= c_fully_fold (t
, false, NULL
);
9236 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9237 error_at (here
, "schedule %<runtime%> does not take "
9238 "a %<chunk_size%> parameter");
9239 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9241 "schedule %<auto%> does not take "
9242 "a %<chunk_size%> parameter");
9243 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9244 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9246 c_parser_error (parser
, "expected integer expression");
9248 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9251 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9252 "expected %<,%> or %<)%>");
9254 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9255 OMP_CLAUSE_CHAIN (c
) = list
;
9259 c_parser_error (parser
, "invalid schedule kind");
9260 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9265 shared ( variable-list ) */
9268 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9270 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9277 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9281 /* FIXME: Should we allow duplicates? */
9282 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9284 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9286 OMP_CLAUSE_CHAIN (c
) = list
;
9291 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9292 is a bitmask in MASK. Return the list of clauses found; the result
9293 of clause default goes in *pdefault. */
9296 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9299 tree clauses
= NULL
;
9302 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9305 pragma_omp_clause c_kind
;
9307 tree prev
= clauses
;
9309 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9310 c_parser_consume_token (parser
);
9313 here
= c_parser_peek_token (parser
)->location
;
9314 c_kind
= c_parser_omp_clause_name (parser
);
9318 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9319 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9320 c_name
= "collapse";
9322 case PRAGMA_OMP_CLAUSE_COPYIN
:
9323 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9326 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9327 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9328 c_name
= "copyprivate";
9330 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9331 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9334 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9335 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9336 c_name
= "firstprivate";
9338 case PRAGMA_OMP_CLAUSE_FINAL
:
9339 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9342 case PRAGMA_OMP_CLAUSE_IF
:
9343 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9346 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9347 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9348 c_name
= "lastprivate";
9350 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9351 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9352 c_name
= "mergeable";
9354 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9355 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9358 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9359 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9360 c_name
= "num_threads";
9362 case PRAGMA_OMP_CLAUSE_ORDERED
:
9363 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9366 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9367 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9370 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9371 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9372 c_name
= "reduction";
9374 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9375 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9376 c_name
= "schedule";
9378 case PRAGMA_OMP_CLAUSE_SHARED
:
9379 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9382 case PRAGMA_OMP_CLAUSE_UNTIED
:
9383 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9387 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9391 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9393 /* Remove the invalid clause(s) from the list to avoid
9394 confusing the rest of the compiler. */
9396 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9401 c_parser_skip_to_pragma_eol (parser
);
9403 return c_finish_omp_clauses (clauses
);
9410 In practice, we're also interested in adding the statement to an
9411 outer node. So it is convenient if we work around the fact that
9412 c_parser_statement calls add_stmt. */
9415 c_parser_omp_structured_block (c_parser
*parser
)
9417 tree stmt
= push_stmt_list ();
9418 c_parser_statement (parser
);
9419 return pop_stmt_list (stmt
);
9423 # pragma omp atomic new-line
9427 x binop= expr | x++ | ++x | x-- | --x
9429 +, *, -, /, &, ^, |, <<, >>
9431 where x is an lvalue expression with scalar type.
9434 # pragma omp atomic new-line
9437 # pragma omp atomic read new-line
9440 # pragma omp atomic write new-line
9443 # pragma omp atomic update new-line
9446 # pragma omp atomic capture new-line
9449 # pragma omp atomic capture new-line
9457 expression-stmt | x = x binop expr
9459 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9461 { v = x; update-stmt; } | { update-stmt; v = x; }
9463 where x and v are lvalue expressions with scalar type.
9465 LOC is the location of the #pragma token. */
9468 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9470 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9471 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9472 tree stmt
, orig_lhs
;
9473 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9474 struct c_expr rhs_expr
;
9475 bool structured_block
= false;
9477 if (c_parser_next_token_is (parser
, CPP_NAME
))
9479 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9481 if (!strcmp (p
, "read"))
9482 code
= OMP_ATOMIC_READ
;
9483 else if (!strcmp (p
, "write"))
9485 else if (!strcmp (p
, "update"))
9487 else if (!strcmp (p
, "capture"))
9488 code
= OMP_ATOMIC_CAPTURE_NEW
;
9492 c_parser_consume_token (parser
);
9494 c_parser_skip_to_pragma_eol (parser
);
9498 case OMP_ATOMIC_READ
:
9499 case NOP_EXPR
: /* atomic write */
9500 v
= c_parser_unary_expression (parser
).value
;
9501 v
= c_fully_fold (v
, false, NULL
);
9502 if (v
== error_mark_node
)
9504 loc
= c_parser_peek_token (parser
)->location
;
9505 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9507 if (code
== NOP_EXPR
)
9508 lhs
= c_parser_expression (parser
).value
;
9510 lhs
= c_parser_unary_expression (parser
).value
;
9511 lhs
= c_fully_fold (lhs
, false, NULL
);
9512 if (lhs
== error_mark_node
)
9514 if (code
== NOP_EXPR
)
9516 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9524 case OMP_ATOMIC_CAPTURE_NEW
:
9525 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9527 c_parser_consume_token (parser
);
9528 structured_block
= true;
9532 v
= c_parser_unary_expression (parser
).value
;
9533 v
= c_fully_fold (v
, false, NULL
);
9534 if (v
== error_mark_node
)
9536 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9544 /* For structured_block case we don't know yet whether
9545 old or new x should be captured. */
9547 lhs
= c_parser_unary_expression (parser
).value
;
9548 lhs
= c_fully_fold (lhs
, false, NULL
);
9550 switch (TREE_CODE (lhs
))
9554 c_parser_skip_to_end_of_block_or_statement (parser
);
9555 if (structured_block
)
9557 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9558 c_parser_consume_token (parser
);
9559 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9561 c_parser_skip_to_end_of_block_or_statement (parser
);
9562 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9563 c_parser_consume_token (parser
);
9568 case POSTINCREMENT_EXPR
:
9569 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9570 code
= OMP_ATOMIC_CAPTURE_OLD
;
9572 case PREINCREMENT_EXPR
:
9573 lhs
= TREE_OPERAND (lhs
, 0);
9575 rhs
= integer_one_node
;
9578 case POSTDECREMENT_EXPR
:
9579 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9580 code
= OMP_ATOMIC_CAPTURE_OLD
;
9582 case PREDECREMENT_EXPR
:
9583 lhs
= TREE_OPERAND (lhs
, 0);
9584 opcode
= MINUS_EXPR
;
9585 rhs
= integer_one_node
;
9589 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9590 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9591 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9592 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9593 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9594 (TREE_OPERAND (lhs
, 1), 0), 0)))
9596 /* Undo effects of boolean_increment for post {in,de}crement. */
9597 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9600 if (TREE_CODE (lhs
) == MODIFY_EXPR
9601 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9603 /* Undo effects of boolean_increment. */
9604 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9606 /* This is pre or post increment. */
9607 rhs
= TREE_OPERAND (lhs
, 1);
9608 lhs
= TREE_OPERAND (lhs
, 0);
9610 if (code
== OMP_ATOMIC_CAPTURE_NEW
9611 && !structured_block
9612 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9613 code
= OMP_ATOMIC_CAPTURE_OLD
;
9616 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9617 && TREE_OPERAND (lhs
, 0)
9618 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9620 /* This is pre or post decrement. */
9621 rhs
= TREE_OPERAND (lhs
, 1);
9622 lhs
= TREE_OPERAND (lhs
, 0);
9624 if (code
== OMP_ATOMIC_CAPTURE_NEW
9625 && !structured_block
9626 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9627 code
= OMP_ATOMIC_CAPTURE_OLD
;
9633 switch (c_parser_peek_token (parser
)->type
)
9639 opcode
= TRUNC_DIV_EXPR
;
9645 opcode
= MINUS_EXPR
;
9648 opcode
= LSHIFT_EXPR
;
9651 opcode
= RSHIFT_EXPR
;
9654 opcode
= BIT_AND_EXPR
;
9657 opcode
= BIT_IOR_EXPR
;
9660 opcode
= BIT_XOR_EXPR
;
9663 if (structured_block
|| code
== OMP_ATOMIC
)
9665 location_t aloc
= c_parser_peek_token (parser
)->location
;
9667 enum c_parser_prec oprec
= PREC_NONE
;
9669 c_parser_consume_token (parser
);
9670 rhs1
= c_parser_unary_expression (parser
).value
;
9671 rhs1
= c_fully_fold (rhs1
, false, NULL
);
9672 if (rhs1
== error_mark_node
)
9674 switch (c_parser_peek_token (parser
)->type
)
9677 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9679 code
= OMP_ATOMIC_CAPTURE_OLD
;
9684 c_parser_consume_token (parser
);
9687 c_parser_error (parser
,
9688 "invalid form of %<#pragma omp atomic%>");
9695 opcode
= TRUNC_DIV_EXPR
;
9703 opcode
= MINUS_EXPR
;
9707 opcode
= LSHIFT_EXPR
;
9711 opcode
= RSHIFT_EXPR
;
9715 opcode
= BIT_AND_EXPR
;
9716 oprec
= PREC_BITAND
;
9719 opcode
= BIT_IOR_EXPR
;
9723 opcode
= BIT_XOR_EXPR
;
9724 oprec
= PREC_BITXOR
;
9727 c_parser_error (parser
,
9728 "invalid operator for %<#pragma omp atomic%>");
9732 c_parser_consume_token (parser
);
9733 rhs_loc
= c_parser_peek_token (parser
)->location
;
9734 if (commutative_tree_code (opcode
))
9735 oprec
= (enum c_parser_prec
) (oprec
- 1);
9736 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
9737 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
9739 rhs
= rhs_expr
.value
;
9740 rhs
= c_fully_fold (rhs
, false, NULL
);
9745 c_parser_error (parser
,
9746 "invalid operator for %<#pragma omp atomic%>");
9750 /* Arrange to pass the location of the assignment operator to
9751 c_finish_omp_atomic. */
9752 loc
= c_parser_peek_token (parser
)->location
;
9753 c_parser_consume_token (parser
);
9755 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9756 rhs_expr
= c_parser_expression (parser
);
9757 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9759 rhs
= rhs_expr
.value
;
9760 rhs
= c_fully_fold (rhs
, false, NULL
);
9764 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
9766 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
9768 v
= c_parser_unary_expression (parser
).value
;
9769 v
= c_fully_fold (v
, false, NULL
);
9770 if (v
== error_mark_node
)
9772 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9774 lhs1
= c_parser_unary_expression (parser
).value
;
9775 lhs1
= c_fully_fold (lhs1
, false, NULL
);
9776 if (lhs1
== error_mark_node
)
9779 if (structured_block
)
9781 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9782 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
9785 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
9786 if (stmt
!= error_mark_node
)
9789 if (!structured_block
)
9790 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9795 # pragma omp barrier new-line
9799 c_parser_omp_barrier (c_parser
*parser
)
9801 location_t loc
= c_parser_peek_token (parser
)->location
;
9802 c_parser_consume_pragma (parser
);
9803 c_parser_skip_to_pragma_eol (parser
);
9805 c_finish_omp_barrier (loc
);
9809 # pragma omp critical [(name)] new-line
9812 LOC is the location of the #pragma itself. */
9815 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9817 tree stmt
, name
= NULL
;
9819 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9821 c_parser_consume_token (parser
);
9822 if (c_parser_next_token_is (parser
, CPP_NAME
))
9824 name
= c_parser_peek_token (parser
)->value
;
9825 c_parser_consume_token (parser
);
9826 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9829 c_parser_error (parser
, "expected identifier");
9831 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9832 c_parser_error (parser
, "expected %<(%> or end of line");
9833 c_parser_skip_to_pragma_eol (parser
);
9835 stmt
= c_parser_omp_structured_block (parser
);
9836 return c_finish_omp_critical (loc
, stmt
, name
);
9840 # pragma omp flush flush-vars[opt] new-line
9843 ( variable-list ) */
9846 c_parser_omp_flush (c_parser
*parser
)
9848 location_t loc
= c_parser_peek_token (parser
)->location
;
9849 c_parser_consume_pragma (parser
);
9850 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9851 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9852 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9853 c_parser_error (parser
, "expected %<(%> or end of line");
9854 c_parser_skip_to_pragma_eol (parser
);
9856 c_finish_omp_flush (loc
);
9859 /* Parse the restricted form of the for statement allowed by OpenMP.
9860 The real trick here is to determine the loop control variable early
9861 so that we can push a new decl if necessary to make it private.
9862 LOC is the location of the OMP in "#pragma omp". */
9865 c_parser_omp_for_loop (location_t loc
,
9866 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
9868 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
9869 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
9870 bool fail
= false, open_brace_parsed
= false;
9871 int i
, collapse
= 1, nbraces
= 0;
9873 VEC(tree
,gc
) *for_block
= make_tree_vector ();
9875 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
9876 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
9877 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
9879 gcc_assert (collapse
>= 1);
9881 declv
= make_tree_vec (collapse
);
9882 initv
= make_tree_vec (collapse
);
9883 condv
= make_tree_vec (collapse
);
9884 incrv
= make_tree_vec (collapse
);
9886 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
9888 c_parser_error (parser
, "for statement expected");
9891 for_loc
= c_parser_peek_token (parser
)->location
;
9892 c_parser_consume_token (parser
);
9894 for (i
= 0; i
< collapse
; i
++)
9898 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9901 /* Parse the initialization declaration or expression. */
9902 if (c_parser_next_tokens_start_declaration (parser
))
9905 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
9906 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
9907 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
9910 if (DECL_INITIAL (decl
) == error_mark_node
)
9911 decl
= error_mark_node
;
9914 else if (c_parser_next_token_is (parser
, CPP_NAME
)
9915 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
9917 struct c_expr decl_exp
;
9918 struct c_expr init_exp
;
9919 location_t init_loc
;
9921 decl_exp
= c_parser_postfix_expression (parser
);
9922 decl
= decl_exp
.value
;
9924 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
9926 init_loc
= c_parser_peek_token (parser
)->location
;
9927 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
9928 init_exp
= default_function_array_read_conversion (init_loc
,
9930 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
9931 NOP_EXPR
, init_loc
, init_exp
.value
,
9932 init_exp
.original_type
);
9933 init
= c_process_expr_stmt (init_loc
, init
);
9935 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9940 c_parser_error (parser
,
9941 "expected iteration declaration or initialization");
9942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9948 /* Parse the loop condition. */
9950 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
9952 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
9953 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
9956 cond
= cond_expr
.value
;
9957 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
9958 cond
= c_fully_fold (cond
, false, NULL
);
9959 switch (cond_expr
.original_code
)
9967 /* Can't be cond = error_mark_node, because we want to preserve
9968 the location until c_finish_omp_for. */
9969 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
9972 protected_set_expr_location (cond
, cond_loc
);
9974 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9976 /* Parse the increment expression. */
9978 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
9980 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
9982 incr
= c_process_expr_stmt (incr_loc
,
9983 c_parser_expression (parser
).value
);
9985 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9987 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
9991 TREE_VEC_ELT (declv
, i
) = decl
;
9992 TREE_VEC_ELT (initv
, i
) = init
;
9993 TREE_VEC_ELT (condv
, i
) = cond
;
9994 TREE_VEC_ELT (incrv
, i
) = incr
;
9998 if (i
== collapse
- 1)
10001 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10002 in between the collapsed for loops to be still considered perfectly
10003 nested. Hopefully the final version clarifies this.
10004 For now handle (multiple) {'s and empty statements. */
10007 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10009 c_parser_consume_token (parser
);
10012 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10014 c_parser_consume_token (parser
);
10017 else if (bracecount
10018 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10019 c_parser_consume_token (parser
);
10022 c_parser_error (parser
, "not enough perfectly nested loops");
10025 open_brace_parsed
= true;
10035 nbraces
+= bracecount
;
10038 save_break
= c_break_label
;
10039 c_break_label
= size_one_node
;
10040 save_cont
= c_cont_label
;
10041 c_cont_label
= NULL_TREE
;
10042 body
= push_stmt_list ();
10044 if (open_brace_parsed
)
10046 location_t here
= c_parser_peek_token (parser
)->location
;
10047 stmt
= c_begin_compound_stmt (true);
10048 c_parser_compound_statement_nostart (parser
);
10049 add_stmt (c_end_compound_stmt (here
, stmt
, true));
10052 add_stmt (c_parser_c99_block_statement (parser
));
10055 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
10056 SET_EXPR_LOCATION (t
, loc
);
10060 body
= pop_stmt_list (body
);
10061 c_break_label
= save_break
;
10062 c_cont_label
= save_cont
;
10066 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10068 c_parser_consume_token (parser
);
10071 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10072 c_parser_consume_token (parser
);
10075 c_parser_error (parser
, "collapsed loops not perfectly nested");
10078 location_t here
= c_parser_peek_token (parser
)->location
;
10079 stmt
= c_begin_compound_stmt (true);
10081 c_parser_compound_statement_nostart (parser
);
10082 body
= c_end_compound_stmt (here
, stmt
, true);
10089 /* Only bother calling c_finish_omp_for if we haven't already generated
10090 an error from the initialization parsing. */
10093 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
10096 if (par_clauses
!= NULL
)
10099 for (c
= par_clauses
; *c
; )
10100 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
10101 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
10102 c
= &OMP_CLAUSE_CHAIN (*c
);
10105 for (i
= 0; i
< collapse
; i
++)
10106 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
10109 c
= &OMP_CLAUSE_CHAIN (*c
);
10110 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
10113 "iteration variable %qD should not be firstprivate",
10114 OMP_CLAUSE_DECL (*c
));
10115 *c
= OMP_CLAUSE_CHAIN (*c
);
10119 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10120 change it to shared (decl) in
10121 OMP_PARALLEL_CLAUSES. */
10122 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
10123 OMP_CLAUSE_LASTPRIVATE
);
10124 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
10125 OMP_CLAUSE_CHAIN (l
) = clauses
;
10127 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
10131 OMP_FOR_CLAUSES (stmt
) = clauses
;
10136 while (!VEC_empty (tree
, for_block
))
10138 /* FIXME diagnostics: LOC below should be the actual location of
10139 this particular for block. We need to build a list of
10140 locations to go along with FOR_BLOCK. */
10141 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
10144 release_tree_vector (for_block
);
10149 #pragma omp for for-clause[optseq] new-line
10152 LOC is the location of the #pragma token.
10155 #define OMP_FOR_CLAUSE_MASK \
10156 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10157 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10158 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10159 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10160 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10161 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10162 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10163 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10166 c_parser_omp_for (location_t loc
, c_parser
*parser
)
10168 tree block
, clauses
, ret
;
10170 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
10171 "#pragma omp for");
10173 block
= c_begin_compound_stmt (true);
10174 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
10175 block
= c_end_compound_stmt (loc
, block
, true);
10182 # pragma omp master new-line
10185 LOC is the location of the #pragma token.
10189 c_parser_omp_master (location_t loc
, c_parser
*parser
)
10191 c_parser_skip_to_pragma_eol (parser
);
10192 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
10196 # pragma omp ordered new-line
10199 LOC is the location of the #pragma itself.
10203 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
10205 c_parser_skip_to_pragma_eol (parser
);
10206 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
10212 { section-sequence }
10215 section-directive[opt] structured-block
10216 section-sequence section-directive structured-block
10218 SECTIONS_LOC is the location of the #pragma omp sections. */
10221 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
10223 tree stmt
, substmt
;
10224 bool error_suppress
= false;
10227 loc
= c_parser_peek_token (parser
)->location
;
10228 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10230 /* Avoid skipping until the end of the block. */
10231 parser
->error
= false;
10235 stmt
= push_stmt_list ();
10237 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10239 substmt
= push_stmt_list ();
10243 c_parser_statement (parser
);
10245 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10247 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10249 if (c_parser_next_token_is (parser
, CPP_EOF
))
10253 substmt
= pop_stmt_list (substmt
);
10254 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10255 SET_EXPR_LOCATION (substmt
, loc
);
10256 add_stmt (substmt
);
10261 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10263 if (c_parser_next_token_is (parser
, CPP_EOF
))
10266 loc
= c_parser_peek_token (parser
)->location
;
10267 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10269 c_parser_consume_pragma (parser
);
10270 c_parser_skip_to_pragma_eol (parser
);
10271 error_suppress
= false;
10273 else if (!error_suppress
)
10275 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10276 error_suppress
= true;
10279 substmt
= c_parser_omp_structured_block (parser
);
10280 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10281 SET_EXPR_LOCATION (substmt
, loc
);
10282 add_stmt (substmt
);
10284 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10285 "expected %<#pragma omp section%> or %<}%>");
10287 substmt
= pop_stmt_list (stmt
);
10289 stmt
= make_node (OMP_SECTIONS
);
10290 SET_EXPR_LOCATION (stmt
, sections_loc
);
10291 TREE_TYPE (stmt
) = void_type_node
;
10292 OMP_SECTIONS_BODY (stmt
) = substmt
;
10294 return add_stmt (stmt
);
10298 # pragma omp sections sections-clause[optseq] newline
10301 LOC is the location of the #pragma token.
10304 #define OMP_SECTIONS_CLAUSE_MASK \
10305 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10306 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10307 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10308 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10309 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10312 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10314 tree block
, clauses
, ret
;
10316 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10317 "#pragma omp sections");
10319 block
= c_begin_compound_stmt (true);
10320 ret
= c_parser_omp_sections_scope (loc
, parser
);
10322 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10323 block
= c_end_compound_stmt (loc
, block
, true);
10330 # pragma parallel parallel-clause new-line
10331 # pragma parallel for parallel-for-clause new-line
10332 # pragma parallel sections parallel-sections-clause new-line
10334 LOC is the location of the #pragma token.
10337 #define OMP_PARALLEL_CLAUSE_MASK \
10338 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10339 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10340 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10341 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10342 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10343 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10344 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10345 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10348 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10350 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10351 const char *p_name
= "#pragma omp parallel";
10352 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10353 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10355 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10357 c_parser_consume_token (parser
);
10358 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10359 p_name
= "#pragma omp parallel for";
10360 mask
|= OMP_FOR_CLAUSE_MASK
;
10361 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10363 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10365 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10366 if (strcmp (p
, "sections") == 0)
10368 c_parser_consume_token (parser
);
10369 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10370 p_name
= "#pragma omp parallel sections";
10371 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10372 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10376 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10380 case PRAGMA_OMP_PARALLEL
:
10381 block
= c_begin_omp_parallel ();
10382 c_parser_statement (parser
);
10383 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10386 case PRAGMA_OMP_PARALLEL_FOR
:
10387 block
= c_begin_omp_parallel ();
10388 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10389 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10390 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10391 OMP_PARALLEL_COMBINED (stmt
) = 1;
10394 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10395 block
= c_begin_omp_parallel ();
10396 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10397 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10399 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10400 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10401 OMP_PARALLEL_COMBINED (stmt
) = 1;
10405 gcc_unreachable ();
10412 # pragma omp single single-clause[optseq] new-line
10415 LOC is the location of the #pragma.
10418 #define OMP_SINGLE_CLAUSE_MASK \
10419 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10420 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10421 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10422 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10425 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10427 tree stmt
= make_node (OMP_SINGLE
);
10428 SET_EXPR_LOCATION (stmt
, loc
);
10429 TREE_TYPE (stmt
) = void_type_node
;
10431 OMP_SINGLE_CLAUSES (stmt
)
10432 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10433 "#pragma omp single");
10434 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10436 return add_stmt (stmt
);
10440 # pragma omp task task-clause[optseq] new-line
10442 LOC is the location of the #pragma.
10445 #define OMP_TASK_CLAUSE_MASK \
10446 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10447 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10448 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10449 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10450 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10451 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10452 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10453 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10456 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10458 tree clauses
, block
;
10460 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10461 "#pragma omp task");
10463 block
= c_begin_omp_task ();
10464 c_parser_statement (parser
);
10465 return c_finish_omp_task (loc
, clauses
, block
);
10469 # pragma omp taskwait new-line
10473 c_parser_omp_taskwait (c_parser
*parser
)
10475 location_t loc
= c_parser_peek_token (parser
)->location
;
10476 c_parser_consume_pragma (parser
);
10477 c_parser_skip_to_pragma_eol (parser
);
10479 c_finish_omp_taskwait (loc
);
10483 # pragma omp taskyield new-line
10487 c_parser_omp_taskyield (c_parser
*parser
)
10489 location_t loc
= c_parser_peek_token (parser
)->location
;
10490 c_parser_consume_pragma (parser
);
10491 c_parser_skip_to_pragma_eol (parser
);
10493 c_finish_omp_taskyield (loc
);
10496 /* Main entry point to parsing most OpenMP pragmas. */
10499 c_parser_omp_construct (c_parser
*parser
)
10501 enum pragma_kind p_kind
;
10505 loc
= c_parser_peek_token (parser
)->location
;
10506 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
10507 c_parser_consume_pragma (parser
);
10511 case PRAGMA_OMP_ATOMIC
:
10512 c_parser_omp_atomic (loc
, parser
);
10514 case PRAGMA_OMP_CRITICAL
:
10515 stmt
= c_parser_omp_critical (loc
, parser
);
10517 case PRAGMA_OMP_FOR
:
10518 stmt
= c_parser_omp_for (loc
, parser
);
10520 case PRAGMA_OMP_MASTER
:
10521 stmt
= c_parser_omp_master (loc
, parser
);
10523 case PRAGMA_OMP_ORDERED
:
10524 stmt
= c_parser_omp_ordered (loc
, parser
);
10526 case PRAGMA_OMP_PARALLEL
:
10527 stmt
= c_parser_omp_parallel (loc
, parser
);
10529 case PRAGMA_OMP_SECTIONS
:
10530 stmt
= c_parser_omp_sections (loc
, parser
);
10532 case PRAGMA_OMP_SINGLE
:
10533 stmt
= c_parser_omp_single (loc
, parser
);
10535 case PRAGMA_OMP_TASK
:
10536 stmt
= c_parser_omp_task (loc
, parser
);
10539 gcc_unreachable ();
10543 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
10548 # pragma omp threadprivate (variable-list) */
10551 c_parser_omp_threadprivate (c_parser
*parser
)
10556 c_parser_consume_pragma (parser
);
10557 loc
= c_parser_peek_token (parser
)->location
;
10558 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10560 /* Mark every variable in VARS to be assigned thread local storage. */
10561 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
10563 tree v
= TREE_PURPOSE (t
);
10565 /* FIXME diagnostics: Ideally we should keep individual
10566 locations for all the variables in the var list to make the
10567 following errors more precise. Perhaps
10568 c_parser_omp_var_list_parens() should construct a list of
10569 locations to go along with the var list. */
10571 /* If V had already been marked threadprivate, it doesn't matter
10572 whether it had been used prior to this point. */
10573 if (TREE_CODE (v
) != VAR_DECL
)
10574 error_at (loc
, "%qD is not a variable", v
);
10575 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
10576 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
10577 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
10578 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
10579 else if (TREE_TYPE (v
) == error_mark_node
)
10581 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
10582 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
10585 if (! DECL_THREAD_LOCAL_P (v
))
10587 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
10588 /* If rtl has been already set for this var, call
10589 make_decl_rtl once again, so that encode_section_info
10590 has a chance to look at the new decl flags. */
10591 if (DECL_RTL_SET_P (v
))
10594 C_DECL_THREADPRIVATE_P (v
) = 1;
10598 c_parser_skip_to_pragma_eol (parser
);
10601 /* Parse a transaction attribute (GCC Extension).
10603 transaction-attribute:
10607 The transactional memory language description is written for C++,
10608 and uses the C++0x attribute syntax. For compatibility, allow the
10609 bracket style for transactions in C as well. */
10612 c_parser_transaction_attributes (c_parser
*parser
)
10614 tree attr_name
, attr
= NULL
;
10616 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10617 return c_parser_attributes (parser
);
10619 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10621 c_parser_consume_token (parser
);
10622 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
10625 attr_name
= c_parser_attribute_any_word (parser
);
10628 c_parser_consume_token (parser
);
10629 attr
= build_tree_list (attr_name
, NULL_TREE
);
10632 c_parser_error (parser
, "expected identifier");
10634 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10636 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10640 /* Parse a __transaction_atomic or __transaction_relaxed statement
10643 transaction-statement:
10644 __transaction_atomic transaction-attribute[opt] compound-statement
10645 __transaction_relaxed compound-statement
10647 Note that the only valid attribute is: "outer".
10651 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
10653 unsigned int old_in
= parser
->in_transaction
;
10654 unsigned int this_in
= 1, new_in
;
10655 location_t loc
= c_parser_peek_token (parser
)->location
;
10658 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10659 || keyword
== RID_TRANSACTION_RELAXED
)
10660 && c_parser_next_token_is_keyword (parser
, keyword
));
10661 c_parser_consume_token (parser
);
10663 if (keyword
== RID_TRANSACTION_RELAXED
)
10664 this_in
|= TM_STMT_ATTR_RELAXED
;
10667 attrs
= c_parser_transaction_attributes (parser
);
10669 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
10672 /* Keep track if we're in the lexical scope of an outer transaction. */
10673 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
10675 parser
->in_transaction
= new_in
;
10676 stmt
= c_parser_compound_statement (parser
);
10677 parser
->in_transaction
= old_in
;
10680 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
10682 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10683 "%<__transaction_atomic%> without transactional memory support enabled"
10684 : "%<__transaction_relaxed %> "
10685 "without transactional memory support enabled"));
10690 /* Parse a __transaction_atomic or __transaction_relaxed expression
10693 transaction-expression:
10694 __transaction_atomic ( expression )
10695 __transaction_relaxed ( expression )
10698 static struct c_expr
10699 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
10702 unsigned int old_in
= parser
->in_transaction
;
10703 unsigned int this_in
= 1;
10704 location_t loc
= c_parser_peek_token (parser
)->location
;
10707 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10708 || keyword
== RID_TRANSACTION_RELAXED
)
10709 && c_parser_next_token_is_keyword (parser
, keyword
));
10710 c_parser_consume_token (parser
);
10712 if (keyword
== RID_TRANSACTION_RELAXED
)
10713 this_in
|= TM_STMT_ATTR_RELAXED
;
10716 attrs
= c_parser_transaction_attributes (parser
);
10718 this_in
|= parse_tm_stmt_attr (attrs
, 0);
10721 parser
->in_transaction
= this_in
;
10722 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10724 tree expr
= c_parser_expression (parser
).value
;
10725 ret
.original_type
= TREE_TYPE (expr
);
10726 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
10727 if (this_in
& TM_STMT_ATTR_RELAXED
)
10728 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
10729 SET_EXPR_LOCATION (ret
.value
, loc
);
10730 ret
.original_code
= TRANSACTION_EXPR
;
10731 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10733 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
10740 ret
.value
= error_mark_node
;
10741 ret
.original_code
= ERROR_MARK
;
10742 ret
.original_type
= NULL
;
10744 parser
->in_transaction
= old_in
;
10747 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10748 "%<__transaction_atomic%> without transactional memory support enabled"
10749 : "%<__transaction_relaxed %> "
10750 "without transactional memory support enabled"));
10755 /* Parse a __transaction_cancel statement (GCC Extension).
10757 transaction-cancel-statement:
10758 __transaction_cancel transaction-attribute[opt] ;
10760 Note that the only valid attribute is "outer".
10764 c_parser_transaction_cancel(c_parser
*parser
)
10766 location_t loc
= c_parser_peek_token (parser
)->location
;
10768 bool is_outer
= false;
10770 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
10771 c_parser_consume_token (parser
);
10773 attrs
= c_parser_transaction_attributes (parser
);
10775 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
10779 error_at (loc
, "%<__transaction_cancel%> without "
10780 "transactional memory support enabled");
10783 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
10785 error_at (loc
, "%<__transaction_cancel%> within a "
10786 "%<__transaction_relaxed%>");
10791 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
10792 && !is_tm_may_cancel_outer (current_function_decl
))
10794 error_at (loc
, "outer %<__transaction_cancel%> not "
10795 "within outer %<__transaction_atomic%>");
10796 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
10800 else if (parser
->in_transaction
== 0)
10802 error_at (loc
, "%<__transaction_cancel%> not within "
10803 "%<__transaction_atomic%>");
10807 return add_stmt (build_tm_abort_call (loc
, is_outer
));
10810 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
10813 /* Parse a single source file. */
10816 c_parse_file (void)
10818 /* Use local storage to begin. If the first token is a pragma, parse it.
10819 If it is #pragma GCC pch_preprocess, then this will load a PCH file
10820 which will cause garbage collection. */
10823 memset (&tparser
, 0, sizeof tparser
);
10824 the_parser
= &tparser
;
10826 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
10827 c_parser_pragma_pch_preprocess (&tparser
);
10829 the_parser
= ggc_alloc_c_parser ();
10830 *the_parser
= tparser
;
10832 /* Initialize EH, if we've been told to do so. */
10833 if (flag_exceptions
)
10834 using_eh_for_cleanups ();
10836 c_parser_translation_unit (the_parser
);
10840 #include "gt-c-parser.h"