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"
54 #include "c-family/c-common.h"
55 #include "c-family/c-objc.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
73 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
74 the c_token structure. */
75 gcc_assert (RID_MAX
<= 255);
82 mask
|= D_ASM
| D_EXT
;
86 if (!c_dialect_objc ())
87 mask
|= D_OBJC
| D_CXX_OBJC
;
89 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
90 for (i
= 0; i
< num_c_common_reswords
; i
++)
92 /* If a keyword is disabled, do not enter it into the table
93 and so create a canonical spelling that isn't a keyword. */
94 if (c_common_reswords
[i
].disable
& mask
)
97 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
99 id
= get_identifier (c_common_reswords
[i
].word
);
100 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
101 C_IS_RESERVED_WORD (id
) = 1;
106 id
= get_identifier (c_common_reswords
[i
].word
);
107 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
108 C_IS_RESERVED_WORD (id
) = 1;
109 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
113 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
114 and the C parser. Unlike the C++ lexer, the parser structure
115 stores the lexer information instead of using a separate structure.
116 Identifiers are separated into ordinary identifiers, type names,
117 keywords and some other Objective-C types of identifiers, and some
118 look-ahead is maintained.
120 ??? It might be a good idea to lex the whole file up front (as for
121 C++). It would then be possible to share more of the C and C++
122 lexer code, if desired. */
124 /* The following local token type is used. */
127 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
129 /* More information about the type of a CPP_NAME token. */
130 typedef enum c_id_kind
{
131 /* An ordinary identifier. */
133 /* An identifier declared as a typedef name. */
135 /* An identifier declared as an Objective-C class name. */
137 /* An address space identifier. */
139 /* Not an identifier. */
143 /* A single C token after string literal concatenation and conversion
144 of preprocessing tokens to tokens. */
145 typedef struct GTY (()) c_token
{
146 /* The kind of token. */
147 ENUM_BITFIELD (cpp_ttype
) type
: 8;
148 /* If this token is a CPP_NAME, this value indicates whether also
149 declared as some kind of type. Otherwise, it is C_ID_NONE. */
150 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
151 /* If this token is a keyword, this value indicates which keyword.
152 Otherwise, this value is RID_MAX. */
153 ENUM_BITFIELD (rid
) keyword
: 8;
154 /* If this token is a CPP_PRAGMA, this indicates the pragma that
155 was seen. Otherwise it is PRAGMA_NONE. */
156 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
157 /* The location at which this token was found. */
159 /* The value associated with this token, if any. */
163 /* A parser structure recording information about the state and
164 context of parsing. Includes lexer information with up to two
165 tokens of look-ahead; more are not needed for C. */
166 typedef struct GTY(()) c_parser
{
167 /* The look-ahead tokens. */
169 /* How many look-ahead tokens are available (0, 1 or 2). */
171 /* True if a syntax error is being recovered from; false otherwise.
172 c_parser_error sets this flag. It should clear this flag when
173 enough tokens have been consumed to recover from the error. */
174 BOOL_BITFIELD error
: 1;
175 /* True if we're processing a pragma, and shouldn't automatically
176 consume CPP_PRAGMA_EOL. */
177 BOOL_BITFIELD in_pragma
: 1;
178 /* True if we're parsing the outermost block of an if statement. */
179 BOOL_BITFIELD in_if_block
: 1;
180 /* True if we want to lex an untranslated string. */
181 BOOL_BITFIELD lex_untranslated_string
: 1;
183 /* Objective-C specific parser/lexer information. */
185 /* True if we are in a context where the Objective-C "PQ" keywords
186 are considered keywords. */
187 BOOL_BITFIELD objc_pq_context
: 1;
188 /* True if we are parsing a (potential) Objective-C foreach
189 statement. This is set to true after we parsed 'for (' and while
190 we wait for 'in' or ';' to decide if it's a standard C for loop or an
191 Objective-C foreach loop. */
192 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
193 /* The following flag is needed to contextualize Objective-C lexical
194 analysis. In some cases (e.g., 'int NSObject;'), it is
195 undesirable to bind an identifier to an Objective-C class, even
196 if a class with that name exists. */
197 BOOL_BITFIELD objc_need_raw_identifier
: 1;
198 /* Nonzero if we're processing a __transaction statement. The value
199 is 1 | TM_STMT_ATTR_*. */
200 unsigned int in_transaction
: 4;
201 /* True if we are in a context where the Objective-C "Property attribute"
202 keywords are valid. */
203 BOOL_BITFIELD objc_property_attr_context
: 1;
207 /* The actual parser and external interface. ??? Does this need to be
208 garbage-collected? */
210 static GTY (()) c_parser
*the_parser
;
212 /* Read in and lex a single token, storing it in *TOKEN. */
215 c_lex_one_token (c_parser
*parser
, c_token
*token
)
217 timevar_push (TV_LEX
);
219 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
220 (parser
->lex_untranslated_string
221 ? C_LEX_STRING_NO_TRANSLATE
: 0));
222 token
->id_kind
= C_ID_NONE
;
223 token
->keyword
= RID_MAX
;
224 token
->pragma_kind
= PRAGMA_NONE
;
232 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
233 if (c_dialect_objc ())
234 parser
->objc_need_raw_identifier
= false;
236 if (C_IS_RESERVED_WORD (token
->value
))
238 enum rid rid_code
= C_RID_CODE (token
->value
);
240 if (rid_code
== RID_CXX_COMPAT_WARN
)
242 warning_at (token
->location
,
244 "identifier %qE conflicts with C++ keyword",
247 else if (rid_code
>= RID_FIRST_ADDR_SPACE
248 && rid_code
<= RID_LAST_ADDR_SPACE
)
250 token
->id_kind
= C_ID_ADDRSPACE
;
251 token
->keyword
= rid_code
;
254 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
256 /* We found an Objective-C "pq" keyword (in, out,
257 inout, bycopy, byref, oneway). They need special
258 care because the interpretation depends on the
260 if (parser
->objc_pq_context
)
262 token
->type
= CPP_KEYWORD
;
263 token
->keyword
= rid_code
;
266 else if (parser
->objc_could_be_foreach_context
267 && rid_code
== RID_IN
)
269 /* We are in Objective-C, inside a (potential)
270 foreach context (which means after having
271 parsed 'for (', but before having parsed ';'),
272 and we found 'in'. We consider it the keyword
273 which terminates the declaration at the
274 beginning of a foreach-statement. Note that
275 this means you can't use 'in' for anything else
276 in that context; in particular, in Objective-C
277 you can't use 'in' as the name of the running
278 variable in a C for loop. We could potentially
279 try to add code here to disambiguate, but it
280 seems a reasonable limitation. */
281 token
->type
= CPP_KEYWORD
;
282 token
->keyword
= rid_code
;
285 /* Else, "pq" keywords outside of the "pq" context are
286 not keywords, and we fall through to the code for
289 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
291 /* We found an Objective-C "property attribute"
292 keyword (getter, setter, readonly, etc). These are
293 only valid in the property context. */
294 if (parser
->objc_property_attr_context
)
296 token
->type
= CPP_KEYWORD
;
297 token
->keyword
= rid_code
;
300 /* Else they are not special keywords.
303 else if (c_dialect_objc ()
304 && (OBJC_IS_AT_KEYWORD (rid_code
)
305 || OBJC_IS_CXX_KEYWORD (rid_code
)))
307 /* We found one of the Objective-C "@" keywords (defs,
308 selector, synchronized, etc) or one of the
309 Objective-C "cxx" keywords (class, private,
310 protected, public, try, catch, throw) without a
311 preceding '@' sign. Do nothing and fall through to
312 the code for normal tokens (in C++ we would still
313 consider the CXX ones keywords, but not in C). */
318 token
->type
= CPP_KEYWORD
;
319 token
->keyword
= rid_code
;
324 decl
= lookup_name (token
->value
);
327 if (TREE_CODE (decl
) == TYPE_DECL
)
329 token
->id_kind
= C_ID_TYPENAME
;
333 else if (c_dialect_objc ())
335 tree objc_interface_decl
= objc_is_class_name (token
->value
);
336 /* Objective-C class names are in the same namespace as
337 variables and typedefs, and hence are shadowed by local
339 if (objc_interface_decl
340 && (!objc_force_identifier
|| global_bindings_p ()))
342 token
->value
= objc_interface_decl
;
343 token
->id_kind
= C_ID_CLASSNAME
;
347 token
->id_kind
= C_ID_ID
;
351 /* This only happens in Objective-C; it must be a keyword. */
352 token
->type
= CPP_KEYWORD
;
353 switch (C_RID_CODE (token
->value
))
355 /* Replace 'class' with '@class', 'private' with '@private',
356 etc. This prevents confusion with the C++ keyword
357 'class', and makes the tokens consistent with other
358 Objective-C 'AT' keywords. For example '@class' is
359 reported as RID_AT_CLASS which is consistent with
360 '@synchronized', which is reported as
363 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
364 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
365 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
366 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
367 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
368 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
369 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
370 default: token
->keyword
= C_RID_CODE (token
->value
);
375 case CPP_CLOSE_PAREN
:
377 /* These tokens may affect the interpretation of any identifiers
378 following, if doing Objective-C. */
379 if (c_dialect_objc ())
380 parser
->objc_need_raw_identifier
= false;
383 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
384 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
390 timevar_pop (TV_LEX
);
393 /* Return a pointer to the next token from PARSER, reading it in if
396 static inline c_token
*
397 c_parser_peek_token (c_parser
*parser
)
399 if (parser
->tokens_avail
== 0)
401 c_lex_one_token (parser
, &parser
->tokens
[0]);
402 parser
->tokens_avail
= 1;
404 return &parser
->tokens
[0];
407 /* Return true if the next token from PARSER has the indicated
411 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
413 return c_parser_peek_token (parser
)->type
== type
;
416 /* Return true if the next token from PARSER does not have the
420 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
422 return !c_parser_next_token_is (parser
, type
);
425 /* Return true if the next token from PARSER is the indicated
429 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
431 return c_parser_peek_token (parser
)->keyword
== keyword
;
434 /* Return a pointer to the next-but-one token from PARSER, reading it
435 in if necessary. The next token is already read in. */
438 c_parser_peek_2nd_token (c_parser
*parser
)
440 if (parser
->tokens_avail
>= 2)
441 return &parser
->tokens
[1];
442 gcc_assert (parser
->tokens_avail
== 1);
443 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
444 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
445 c_lex_one_token (parser
, &parser
->tokens
[1]);
446 parser
->tokens_avail
= 2;
447 return &parser
->tokens
[1];
450 /* Return true if TOKEN can start a type name,
453 c_token_starts_typename (c_token
*token
)
458 switch (token
->id_kind
)
467 gcc_assert (c_dialect_objc ());
473 switch (token
->keyword
)
506 if (c_dialect_objc ())
514 enum c_lookahead_kind
{
515 /* Always treat unknown identifiers as typenames. */
518 /* Could be parsing a nonabstract declarator. Only treat an identifier
519 as a typename if followed by another identifier or a star. */
520 cla_nonabstract_decl
,
522 /* Never treat identifiers as typenames. */
526 /* Return true if the next token from PARSER can start a type name,
527 false otherwise. LA specifies how to do lookahead in order to
528 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
531 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
533 c_token
*token
= c_parser_peek_token (parser
);
534 if (c_token_starts_typename (token
))
537 /* Try a bit harder to detect an unknown typename. */
538 if (la
!= cla_prefer_id
539 && token
->type
== CPP_NAME
540 && token
->id_kind
== C_ID_ID
542 /* Do not try too hard when we could have "object in array". */
543 && !parser
->objc_could_be_foreach_context
545 && (la
== cla_prefer_type
546 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
547 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
549 /* Only unknown identifiers. */
550 && !lookup_name (token
->value
))
556 /* Return true if TOKEN is a type qualifier, false otherwise. */
558 c_token_is_qualifier (c_token
*token
)
563 switch (token
->id_kind
)
571 switch (token
->keyword
)
588 /* Return true if the next token from PARSER is a type qualifier,
591 c_parser_next_token_is_qualifier (c_parser
*parser
)
593 c_token
*token
= c_parser_peek_token (parser
);
594 return c_token_is_qualifier (token
);
597 /* Return true if TOKEN can start declaration specifiers, false
600 c_token_starts_declspecs (c_token
*token
)
605 switch (token
->id_kind
)
614 gcc_assert (c_dialect_objc ());
620 switch (token
->keyword
)
662 if (c_dialect_objc ())
671 /* Return true if TOKEN can start declaration specifiers or a static
672 assertion, false otherwise. */
674 c_token_starts_declaration (c_token
*token
)
676 if (c_token_starts_declspecs (token
)
677 || token
->keyword
== RID_STATIC_ASSERT
)
683 /* Return true if the next token from PARSER can start declaration
684 specifiers, false otherwise. */
686 c_parser_next_token_starts_declspecs (c_parser
*parser
)
688 c_token
*token
= c_parser_peek_token (parser
);
690 /* In Objective-C, a classname normally starts a declspecs unless it
691 is immediately followed by a dot. In that case, it is the
692 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
693 setter/getter on the class. c_token_starts_declspecs() can't
694 differentiate between the two cases because it only checks the
695 current token, so we have a special check here. */
696 if (c_dialect_objc ()
697 && token
->type
== CPP_NAME
698 && token
->id_kind
== C_ID_CLASSNAME
699 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
702 return c_token_starts_declspecs (token
);
705 /* Return true if the next tokens from PARSER can start declaration
706 specifiers or a static assertion, false otherwise. */
708 c_parser_next_tokens_start_declaration (c_parser
*parser
)
710 c_token
*token
= c_parser_peek_token (parser
);
713 if (c_dialect_objc ()
714 && token
->type
== CPP_NAME
715 && token
->id_kind
== C_ID_CLASSNAME
716 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
719 /* Labels do not start declarations. */
720 if (token
->type
== CPP_NAME
721 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
724 if (c_token_starts_declaration (token
))
727 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
733 /* Consume the next token from PARSER. */
736 c_parser_consume_token (c_parser
*parser
)
738 gcc_assert (parser
->tokens_avail
>= 1);
739 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
740 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
741 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
742 if (parser
->tokens_avail
== 2)
743 parser
->tokens
[0] = parser
->tokens
[1];
744 parser
->tokens_avail
--;
747 /* Expect the current token to be a #pragma. Consume it and remember
748 that we've begun parsing a pragma. */
751 c_parser_consume_pragma (c_parser
*parser
)
753 gcc_assert (!parser
->in_pragma
);
754 gcc_assert (parser
->tokens_avail
>= 1);
755 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
756 if (parser
->tokens_avail
== 2)
757 parser
->tokens
[0] = parser
->tokens
[1];
758 parser
->tokens_avail
--;
759 parser
->in_pragma
= true;
762 /* Update the globals input_location and in_system_header from
765 c_parser_set_source_position_from_token (c_token
*token
)
767 if (token
->type
!= CPP_EOF
)
769 input_location
= token
->location
;
773 /* Issue a diagnostic of the form
774 FILE:LINE: MESSAGE before TOKEN
775 where TOKEN is the next token in the input stream of PARSER.
776 MESSAGE (specified by the caller) is usually of the form "expected
779 Do not issue a diagnostic if still recovering from an error.
781 ??? This is taken from the C++ parser, but building up messages in
782 this way is not i18n-friendly and some other approach should be
786 c_parser_error (c_parser
*parser
, const char *gmsgid
)
788 c_token
*token
= c_parser_peek_token (parser
);
791 parser
->error
= true;
794 /* This diagnostic makes more sense if it is tagged to the line of
795 the token we just peeked at. */
796 c_parser_set_source_position_from_token (token
);
797 c_parse_error (gmsgid
,
798 /* Because c_parse_error does not understand
799 CPP_KEYWORD, keywords are treated like
801 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
802 /* ??? The C parser does not save the cpp flags of a
803 token, we need to pass 0 here and we will not get
804 the source spelling of some tokens but rather the
805 canonical spelling. */
806 token
->value
, /*flags=*/0);
809 /* If the next token is of the indicated TYPE, consume it. Otherwise,
810 issue the error MSGID. If MSGID is NULL then a message has already
811 been produced and no message will be produced this time. Returns
812 true if found, false otherwise. */
815 c_parser_require (c_parser
*parser
,
819 if (c_parser_next_token_is (parser
, type
))
821 c_parser_consume_token (parser
);
826 c_parser_error (parser
, msgid
);
831 /* If the next token is the indicated keyword, consume it. Otherwise,
832 issue the error MSGID. Returns true if found, false otherwise. */
835 c_parser_require_keyword (c_parser
*parser
,
839 if (c_parser_next_token_is_keyword (parser
, keyword
))
841 c_parser_consume_token (parser
);
846 c_parser_error (parser
, msgid
);
851 /* Like c_parser_require, except that tokens will be skipped until the
852 desired token is found. An error message is still produced if the
853 next token is not as expected. If MSGID is NULL then a message has
854 already been produced and no message will be produced this
858 c_parser_skip_until_found (c_parser
*parser
,
862 unsigned nesting_depth
= 0;
864 if (c_parser_require (parser
, type
, msgid
))
867 /* Skip tokens until the desired token is found. */
870 /* Peek at the next token. */
871 c_token
*token
= c_parser_peek_token (parser
);
872 /* If we've reached the token we want, consume it and stop. */
873 if (token
->type
== type
&& !nesting_depth
)
875 c_parser_consume_token (parser
);
879 /* If we've run out of tokens, stop. */
880 if (token
->type
== CPP_EOF
)
882 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
884 if (token
->type
== CPP_OPEN_BRACE
885 || token
->type
== CPP_OPEN_PAREN
886 || token
->type
== CPP_OPEN_SQUARE
)
888 else if (token
->type
== CPP_CLOSE_BRACE
889 || token
->type
== CPP_CLOSE_PAREN
890 || token
->type
== CPP_CLOSE_SQUARE
)
892 if (nesting_depth
-- == 0)
895 /* Consume this token. */
896 c_parser_consume_token (parser
);
898 parser
->error
= false;
901 /* Skip tokens until the end of a parameter is found, but do not
902 consume the comma, semicolon or closing delimiter. */
905 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
907 unsigned nesting_depth
= 0;
911 c_token
*token
= c_parser_peek_token (parser
);
912 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
915 /* If we've run out of tokens, stop. */
916 if (token
->type
== CPP_EOF
)
918 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
920 if (token
->type
== CPP_OPEN_BRACE
921 || token
->type
== CPP_OPEN_PAREN
922 || token
->type
== CPP_OPEN_SQUARE
)
924 else if (token
->type
== CPP_CLOSE_BRACE
925 || token
->type
== CPP_CLOSE_PAREN
926 || token
->type
== CPP_CLOSE_SQUARE
)
928 if (nesting_depth
-- == 0)
931 /* Consume this token. */
932 c_parser_consume_token (parser
);
934 parser
->error
= false;
937 /* Expect to be at the end of the pragma directive and consume an
938 end of line marker. */
941 c_parser_skip_to_pragma_eol (c_parser
*parser
)
943 gcc_assert (parser
->in_pragma
);
944 parser
->in_pragma
= false;
946 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
949 c_token
*token
= c_parser_peek_token (parser
);
950 if (token
->type
== CPP_EOF
)
952 if (token
->type
== CPP_PRAGMA_EOL
)
954 c_parser_consume_token (parser
);
957 c_parser_consume_token (parser
);
960 parser
->error
= false;
963 /* Skip tokens until we have consumed an entire block, or until we
964 have consumed a non-nested ';'. */
967 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
969 unsigned nesting_depth
= 0;
970 bool save_error
= parser
->error
;
976 /* Peek at the next token. */
977 token
= c_parser_peek_token (parser
);
985 if (parser
->in_pragma
)
990 /* If the next token is a ';', we have reached the
991 end of the statement. */
994 /* Consume the ';'. */
995 c_parser_consume_token (parser
);
1000 case CPP_CLOSE_BRACE
:
1001 /* If the next token is a non-nested '}', then we have
1002 reached the end of the current block. */
1003 if (nesting_depth
== 0 || --nesting_depth
== 0)
1005 c_parser_consume_token (parser
);
1010 case CPP_OPEN_BRACE
:
1011 /* If it the next token is a '{', then we are entering a new
1012 block. Consume the entire block. */
1017 /* If we see a pragma, consume the whole thing at once. We
1018 have some safeguards against consuming pragmas willy-nilly.
1019 Normally, we'd expect to be here with parser->error set,
1020 which disables these safeguards. But it's possible to get
1021 here for secondary error recovery, after parser->error has
1023 c_parser_consume_pragma (parser
);
1024 c_parser_skip_to_pragma_eol (parser
);
1025 parser
->error
= save_error
;
1032 c_parser_consume_token (parser
);
1036 parser
->error
= false;
1039 /* CPP's options (initialized by c-opts.c). */
1040 extern cpp_options
*cpp_opts
;
1042 /* Save the warning flags which are controlled by __extension__. */
1045 disable_extension_diagnostics (void)
1048 | (warn_pointer_arith
<< 1)
1049 | (warn_traditional
<< 2)
1051 | (warn_long_long
<< 4)
1052 | (warn_cxx_compat
<< 5)
1053 | (warn_overlength_strings
<< 6));
1054 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1055 warn_pointer_arith
= 0;
1056 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1058 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1059 warn_cxx_compat
= 0;
1060 warn_overlength_strings
= 0;
1064 /* Restore the warning flags which are controlled by __extension__.
1065 FLAGS is the return value from disable_extension_diagnostics. */
1068 restore_extension_diagnostics (int flags
)
1070 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1071 warn_pointer_arith
= (flags
>> 1) & 1;
1072 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1073 flag_iso
= (flags
>> 3) & 1;
1074 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1075 warn_cxx_compat
= (flags
>> 5) & 1;
1076 warn_overlength_strings
= (flags
>> 6) & 1;
1079 /* Possibly kinds of declarator to parse. */
1080 typedef enum c_dtr_syn
{
1081 /* A normal declarator with an identifier. */
1083 /* An abstract declarator (maybe empty). */
1085 /* A parameter declarator: may be either, but after a type name does
1086 not redeclare a typedef name as an identifier if it can
1087 alternatively be interpreted as a typedef name; see DR#009,
1088 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1089 following DR#249. For example, given a typedef T, "int T" and
1090 "int *T" are valid parameter declarations redeclaring T, while
1091 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1092 abstract declarators rather than involving redundant parentheses;
1093 the same applies with attributes inside the parentheses before
1098 /* The binary operation precedence levels, where 0 is a dummy lowest level
1099 used for the bottom of the stack. */
1100 enum c_parser_prec
{
1115 static void c_parser_external_declaration (c_parser
*);
1116 static void c_parser_asm_definition (c_parser
*);
1117 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1118 bool, bool, tree
*);
1119 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1120 static void c_parser_static_assert_declaration (c_parser
*);
1121 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1122 bool, enum c_lookahead_kind
);
1123 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1124 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1125 static tree
c_parser_struct_declaration (c_parser
*);
1126 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1127 static tree
c_parser_alignas_specifier (c_parser
*);
1128 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1130 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1132 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1134 struct c_declarator
*);
1135 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1136 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1138 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1139 static tree
c_parser_simple_asm_expr (c_parser
*);
1140 static tree
c_parser_attributes (c_parser
*);
1141 static struct c_type_name
*c_parser_type_name (c_parser
*);
1142 static struct c_expr
c_parser_initializer (c_parser
*);
1143 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1144 static void c_parser_initelt (c_parser
*, struct obstack
*);
1145 static void c_parser_initval (c_parser
*, struct c_expr
*,
1147 static tree
c_parser_compound_statement (c_parser
*);
1148 static void c_parser_compound_statement_nostart (c_parser
*);
1149 static void c_parser_label (c_parser
*);
1150 static void c_parser_statement (c_parser
*);
1151 static void c_parser_statement_after_labels (c_parser
*);
1152 static void c_parser_if_statement (c_parser
*);
1153 static void c_parser_switch_statement (c_parser
*);
1154 static void c_parser_while_statement (c_parser
*);
1155 static void c_parser_do_statement (c_parser
*);
1156 static void c_parser_for_statement (c_parser
*);
1157 static tree
c_parser_asm_statement (c_parser
*);
1158 static tree
c_parser_asm_operands (c_parser
*, bool);
1159 static tree
c_parser_asm_goto_operands (c_parser
*);
1160 static tree
c_parser_asm_clobbers (c_parser
*);
1161 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1162 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1164 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1165 enum c_parser_prec
);
1166 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1167 static struct c_expr
c_parser_unary_expression (c_parser
*);
1168 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1169 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1170 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1171 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1172 struct c_type_name
*,
1174 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1177 static tree
c_parser_transaction (c_parser
*, enum rid
);
1178 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1179 static tree
c_parser_transaction_cancel (c_parser
*);
1180 static struct c_expr
c_parser_expression (c_parser
*);
1181 static struct c_expr
c_parser_expression_conv (c_parser
*);
1182 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
1184 static void c_parser_omp_construct (c_parser
*);
1185 static void c_parser_omp_threadprivate (c_parser
*);
1186 static void c_parser_omp_barrier (c_parser
*);
1187 static void c_parser_omp_flush (c_parser
*);
1188 static void c_parser_omp_taskwait (c_parser
*);
1189 static void c_parser_omp_taskyield (c_parser
*);
1191 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1192 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1194 /* These Objective-C parser functions are only ever called when
1195 compiling Objective-C. */
1196 static void c_parser_objc_class_definition (c_parser
*, tree
);
1197 static void c_parser_objc_class_instance_variables (c_parser
*);
1198 static void c_parser_objc_class_declaration (c_parser
*);
1199 static void c_parser_objc_alias_declaration (c_parser
*);
1200 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1201 static bool c_parser_objc_method_type (c_parser
*);
1202 static void c_parser_objc_method_definition (c_parser
*);
1203 static void c_parser_objc_methodprotolist (c_parser
*);
1204 static void c_parser_objc_methodproto (c_parser
*);
1205 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1206 static tree
c_parser_objc_type_name (c_parser
*);
1207 static tree
c_parser_objc_protocol_refs (c_parser
*);
1208 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1209 static void c_parser_objc_synchronized_statement (c_parser
*);
1210 static tree
c_parser_objc_selector (c_parser
*);
1211 static tree
c_parser_objc_selector_arg (c_parser
*);
1212 static tree
c_parser_objc_receiver (c_parser
*);
1213 static tree
c_parser_objc_message_args (c_parser
*);
1214 static tree
c_parser_objc_keywordexpr (c_parser
*);
1215 static void c_parser_objc_at_property_declaration (c_parser
*);
1216 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1217 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1218 static bool c_parser_objc_diagnose_bad_element_prefix
1219 (c_parser
*, struct c_declspecs
*);
1221 /* Parse a translation unit (C90 6.7, C99 6.9).
1224 external-declarations
1226 external-declarations:
1227 external-declaration
1228 external-declarations external-declaration
1237 c_parser_translation_unit (c_parser
*parser
)
1239 if (c_parser_next_token_is (parser
, CPP_EOF
))
1241 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1242 "ISO C forbids an empty translation unit");
1246 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1247 mark_valid_location_for_stdc_pragma (false);
1251 c_parser_external_declaration (parser
);
1252 obstack_free (&parser_obstack
, obstack_position
);
1254 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1258 /* Parse an external declaration (C90 6.7, C99 6.9).
1260 external-declaration:
1266 external-declaration:
1269 __extension__ external-declaration
1273 external-declaration:
1274 objc-class-definition
1275 objc-class-declaration
1276 objc-alias-declaration
1277 objc-protocol-definition
1278 objc-method-definition
1283 c_parser_external_declaration (c_parser
*parser
)
1286 switch (c_parser_peek_token (parser
)->type
)
1289 switch (c_parser_peek_token (parser
)->keyword
)
1292 ext
= disable_extension_diagnostics ();
1293 c_parser_consume_token (parser
);
1294 c_parser_external_declaration (parser
);
1295 restore_extension_diagnostics (ext
);
1298 c_parser_asm_definition (parser
);
1300 case RID_AT_INTERFACE
:
1301 case RID_AT_IMPLEMENTATION
:
1302 gcc_assert (c_dialect_objc ());
1303 c_parser_objc_class_definition (parser
, NULL_TREE
);
1306 gcc_assert (c_dialect_objc ());
1307 c_parser_objc_class_declaration (parser
);
1310 gcc_assert (c_dialect_objc ());
1311 c_parser_objc_alias_declaration (parser
);
1313 case RID_AT_PROTOCOL
:
1314 gcc_assert (c_dialect_objc ());
1315 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1317 case RID_AT_PROPERTY
:
1318 gcc_assert (c_dialect_objc ());
1319 c_parser_objc_at_property_declaration (parser
);
1321 case RID_AT_SYNTHESIZE
:
1322 gcc_assert (c_dialect_objc ());
1323 c_parser_objc_at_synthesize_declaration (parser
);
1325 case RID_AT_DYNAMIC
:
1326 gcc_assert (c_dialect_objc ());
1327 c_parser_objc_at_dynamic_declaration (parser
);
1330 gcc_assert (c_dialect_objc ());
1331 c_parser_consume_token (parser
);
1332 objc_finish_implementation ();
1339 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1340 "ISO C does not allow extra %<;%> outside of a function");
1341 c_parser_consume_token (parser
);
1344 mark_valid_location_for_stdc_pragma (true);
1345 c_parser_pragma (parser
, pragma_external
);
1346 mark_valid_location_for_stdc_pragma (false);
1350 if (c_dialect_objc ())
1352 c_parser_objc_method_definition (parser
);
1355 /* Else fall through, and yield a syntax error trying to parse
1356 as a declaration or function definition. */
1359 /* A declaration or a function definition (or, in Objective-C,
1360 an @interface or @protocol with prefix attributes). We can
1361 only tell which after parsing the declaration specifiers, if
1362 any, and the first declarator. */
1363 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1368 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1369 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1370 accepted; otherwise (old-style parameter declarations) only other
1371 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1372 assertion is accepted; otherwise (old-style parameter declarations)
1373 it is not. If NESTED is true, we are inside a function or parsing
1374 old-style parameter declarations; any functions encountered are
1375 nested functions and declaration specifiers are required; otherwise
1376 we are at top level and functions are normal functions and
1377 declaration specifiers may be optional. If EMPTY_OK is true, empty
1378 declarations are OK (subject to all other constraints); otherwise
1379 (old-style parameter declarations) they are diagnosed. If
1380 START_ATTR_OK is true, the declaration specifiers may start with
1381 attributes; otherwise they may not.
1382 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1383 declaration when parsing an Objective-C foreach statement.
1386 declaration-specifiers init-declarator-list[opt] ;
1387 static_assert-declaration
1389 function-definition:
1390 declaration-specifiers[opt] declarator declaration-list[opt]
1395 declaration-list declaration
1397 init-declarator-list:
1399 init-declarator-list , init-declarator
1402 declarator simple-asm-expr[opt] attributes[opt]
1403 declarator simple-asm-expr[opt] attributes[opt] = initializer
1407 nested-function-definition:
1408 declaration-specifiers declarator declaration-list[opt]
1412 attributes objc-class-definition
1413 attributes objc-category-definition
1414 attributes objc-protocol-definition
1416 The simple-asm-expr and attributes are GNU extensions.
1418 This function does not handle __extension__; that is handled in its
1419 callers. ??? Following the old parser, __extension__ may start
1420 external declarations, declarations in functions and declarations
1421 at the start of "for" loops, but not old-style parameter
1424 C99 requires declaration specifiers in a function definition; the
1425 absence is diagnosed through the diagnosis of implicit int. In GNU
1426 C we also allow but diagnose declarations without declaration
1427 specifiers, but only at top level (elsewhere they conflict with
1430 In Objective-C, declarations of the looping variable in a foreach
1431 statement are exceptionally terminated by 'in' (for example, 'for
1432 (NSObject *object in array) { ... }').
1437 threadprivate-directive */
1440 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1441 bool static_assert_ok
, bool empty_ok
,
1442 bool nested
, bool start_attr_ok
,
1443 tree
*objc_foreach_object_declaration
)
1445 struct c_declspecs
*specs
;
1447 tree all_prefix_attrs
;
1448 bool diagnosed_no_specs
= false;
1449 location_t here
= c_parser_peek_token (parser
)->location
;
1451 if (static_assert_ok
1452 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1454 c_parser_static_assert_declaration (parser
);
1457 specs
= build_null_declspecs ();
1459 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1460 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1461 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1462 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1463 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1464 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1466 error_at (here
, "unknown type name %qE",
1467 c_parser_peek_token (parser
)->value
);
1469 /* Parse declspecs normally to get a correct pointer type, but avoid
1470 a further "fails to be a type name" error. Refuse nested functions
1471 since it is not how the user likely wants us to recover. */
1472 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1473 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1474 c_parser_peek_token (parser
)->value
= error_mark_node
;
1478 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1481 c_parser_skip_to_end_of_block_or_statement (parser
);
1484 if (nested
&& !specs
->declspecs_seen_p
)
1486 c_parser_error (parser
, "expected declaration specifiers");
1487 c_parser_skip_to_end_of_block_or_statement (parser
);
1490 finish_declspecs (specs
);
1491 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1497 shadow_tag_warned (specs
, 1);
1498 pedwarn (here
, 0, "empty declaration");
1500 c_parser_consume_token (parser
);
1504 /* Provide better error recovery. Note that a type name here is usually
1505 better diagnosed as a redeclaration. */
1507 && specs
->typespec_kind
== ctsk_tagdef
1508 && c_parser_next_token_starts_declspecs (parser
)
1509 && !c_parser_next_token_is (parser
, CPP_NAME
))
1511 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1512 parser
->error
= false;
1513 shadow_tag_warned (specs
, 1);
1516 else if (c_dialect_objc ())
1518 /* Prefix attributes are an error on method decls. */
1519 switch (c_parser_peek_token (parser
)->type
)
1523 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1527 warning_at (c_parser_peek_token (parser
)->location
,
1529 "prefix attributes are ignored for methods");
1530 specs
->attrs
= NULL_TREE
;
1533 c_parser_objc_method_definition (parser
);
1535 c_parser_objc_methodproto (parser
);
1541 /* This is where we parse 'attributes @interface ...',
1542 'attributes @implementation ...', 'attributes @protocol ...'
1543 (where attributes could be, for example, __attribute__
1546 switch (c_parser_peek_token (parser
)->keyword
)
1548 case RID_AT_INTERFACE
:
1550 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1552 c_parser_objc_class_definition (parser
, specs
->attrs
);
1556 case RID_AT_IMPLEMENTATION
:
1558 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1562 warning_at (c_parser_peek_token (parser
)->location
,
1564 "prefix attributes are ignored for implementations");
1565 specs
->attrs
= NULL_TREE
;
1567 c_parser_objc_class_definition (parser
, NULL_TREE
);
1571 case RID_AT_PROTOCOL
:
1573 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1575 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1582 case RID_AT_PROPERTY
:
1585 c_parser_error (parser
, "unexpected attribute");
1586 specs
->attrs
= NULL
;
1594 pending_xref_error ();
1595 prefix_attrs
= specs
->attrs
;
1596 all_prefix_attrs
= prefix_attrs
;
1597 specs
->attrs
= NULL_TREE
;
1600 struct c_declarator
*declarator
;
1604 /* Declaring either one or more declarators (in which case we
1605 should diagnose if there were no declaration specifiers) or a
1606 function definition (in which case the diagnostic for
1607 implicit int suffices). */
1608 declarator
= c_parser_declarator (parser
,
1609 specs
->typespec_kind
!= ctsk_none
,
1610 C_DTR_NORMAL
, &dummy
);
1611 if (declarator
== NULL
)
1613 c_parser_skip_to_end_of_block_or_statement (parser
);
1616 if (c_parser_next_token_is (parser
, CPP_EQ
)
1617 || c_parser_next_token_is (parser
, CPP_COMMA
)
1618 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1619 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1620 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1621 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1623 tree asm_name
= NULL_TREE
;
1624 tree postfix_attrs
= NULL_TREE
;
1625 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1627 diagnosed_no_specs
= true;
1628 pedwarn (here
, 0, "data definition has no type or storage class");
1630 /* Having seen a data definition, there cannot now be a
1631 function definition. */
1633 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1634 asm_name
= c_parser_simple_asm_expr (parser
);
1635 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1636 postfix_attrs
= c_parser_attributes (parser
);
1637 if (c_parser_next_token_is (parser
, CPP_EQ
))
1641 location_t init_loc
;
1642 c_parser_consume_token (parser
);
1643 /* The declaration of the variable is in effect while
1644 its initializer is parsed. */
1645 d
= start_decl (declarator
, specs
, true,
1646 chainon (postfix_attrs
, all_prefix_attrs
));
1648 d
= error_mark_node
;
1649 start_init (d
, asm_name
, global_bindings_p ());
1650 init_loc
= c_parser_peek_token (parser
)->location
;
1651 init
= c_parser_initializer (parser
);
1653 if (d
!= error_mark_node
)
1655 maybe_warn_string_init (TREE_TYPE (d
), init
);
1656 finish_decl (d
, init_loc
, init
.value
,
1657 init
.original_type
, asm_name
);
1662 tree d
= start_decl (declarator
, specs
, false,
1663 chainon (postfix_attrs
,
1666 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1667 NULL_TREE
, asm_name
);
1669 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1672 *objc_foreach_object_declaration
= d
;
1674 *objc_foreach_object_declaration
= error_mark_node
;
1677 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1679 c_parser_consume_token (parser
);
1680 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1681 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1684 all_prefix_attrs
= prefix_attrs
;
1687 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1689 c_parser_consume_token (parser
);
1692 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1694 /* This can only happen in Objective-C: we found the
1695 'in' that terminates the declaration inside an
1696 Objective-C foreach statement. Do not consume the
1697 token, so that the caller can use it to determine
1698 that this indeed is a foreach context. */
1703 c_parser_error (parser
, "expected %<,%> or %<;%>");
1704 c_parser_skip_to_end_of_block_or_statement (parser
);
1710 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1711 "%<asm%> or %<__attribute__%>");
1712 c_parser_skip_to_end_of_block_or_statement (parser
);
1715 /* Function definition (nested or otherwise). */
1718 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1719 c_push_function_context ();
1721 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1723 /* This can appear in many cases looking nothing like a
1724 function definition, so we don't give a more specific
1725 error suggesting there was one. */
1726 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1727 "or %<__attribute__%>");
1729 c_pop_function_context ();
1733 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1734 tv
= TV_PARSE_INLINE
;
1739 /* Parse old-style parameter declarations. ??? Attributes are
1740 not allowed to start declaration specifiers here because of a
1741 syntax conflict between a function declaration with attribute
1742 suffix and a function definition with an attribute prefix on
1743 first old-style parameter declaration. Following the old
1744 parser, they are not accepted on subsequent old-style
1745 parameter declarations either. However, there is no
1746 ambiguity after the first declaration, nor indeed on the
1747 first as long as we don't allow postfix attributes after a
1748 declarator with a nonempty identifier list in a definition;
1749 and postfix attributes have never been accepted here in
1750 function definitions either. */
1751 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1752 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1753 c_parser_declaration_or_fndef (parser
, false, false, false,
1755 store_parm_decls ();
1756 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1757 = c_parser_peek_token (parser
)->location
;
1758 fnbody
= c_parser_compound_statement (parser
);
1761 tree decl
= current_function_decl
;
1762 /* Mark nested functions as needing static-chain initially.
1763 lower_nested_functions will recompute it but the
1764 DECL_STATIC_CHAIN flag is also used before that happens,
1765 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1766 DECL_STATIC_CHAIN (decl
) = 1;
1769 c_pop_function_context ();
1770 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1783 /* Parse an asm-definition (asm() outside a function body). This is a
1791 c_parser_asm_definition (c_parser
*parser
)
1793 tree asm_str
= c_parser_simple_asm_expr (parser
);
1795 cgraph_add_asm_node (asm_str
);
1796 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1799 /* Parse a static assertion (C11 6.7.10).
1801 static_assert-declaration:
1802 static_assert-declaration-no-semi ;
1806 c_parser_static_assert_declaration (c_parser
*parser
)
1808 c_parser_static_assert_declaration_no_semi (parser
);
1810 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1811 c_parser_skip_to_end_of_block_or_statement (parser
);
1814 /* Parse a static assertion (C11 6.7.10), without the trailing
1817 static_assert-declaration-no-semi:
1818 _Static_assert ( constant-expression , string-literal )
1822 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1824 location_t assert_loc
, value_loc
;
1828 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1829 assert_loc
= c_parser_peek_token (parser
)->location
;
1833 pedwarn (assert_loc
, OPT_pedantic
,
1834 "ISO C99 does not support %<_Static_assert%>");
1836 pedwarn (assert_loc
, OPT_pedantic
,
1837 "ISO C90 does not support %<_Static_assert%>");
1839 c_parser_consume_token (parser
);
1840 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1842 value_loc
= c_parser_peek_token (parser
)->location
;
1843 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1844 parser
->lex_untranslated_string
= true;
1845 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1847 parser
->lex_untranslated_string
= false;
1850 switch (c_parser_peek_token (parser
)->type
)
1856 case CPP_UTF8STRING
:
1857 string
= c_parser_peek_token (parser
)->value
;
1858 c_parser_consume_token (parser
);
1859 parser
->lex_untranslated_string
= false;
1862 c_parser_error (parser
, "expected string literal");
1863 parser
->lex_untranslated_string
= false;
1866 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1868 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1870 error_at (value_loc
, "expression in static assertion is not an integer");
1873 if (TREE_CODE (value
) != INTEGER_CST
)
1875 value
= c_fully_fold (value
, false, NULL
);
1876 if (TREE_CODE (value
) == INTEGER_CST
)
1877 pedwarn (value_loc
, OPT_pedantic
, "expression in static assertion "
1878 "is not an integer constant expression");
1880 if (TREE_CODE (value
) != INTEGER_CST
)
1882 error_at (value_loc
, "expression in static assertion is not constant");
1885 constant_expression_warning (value
);
1886 if (integer_zerop (value
))
1887 error_at (assert_loc
, "static assertion failed: %E", string
);
1890 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1891 6.7), adding them to SPECS (which may already include some).
1892 Storage class specifiers are accepted iff SCSPEC_OK; type
1893 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1894 the start iff START_ATTR_OK.
1896 declaration-specifiers:
1897 storage-class-specifier declaration-specifiers[opt]
1898 type-specifier declaration-specifiers[opt]
1899 type-qualifier declaration-specifiers[opt]
1900 function-specifier declaration-specifiers[opt]
1901 alignment-specifier declaration-specifiers[opt]
1903 Function specifiers (inline) are from C99, and are currently
1904 handled as storage class specifiers, as is __thread. Alignment
1905 specifiers are from C11.
1907 C90 6.5.1, C99 6.7.1:
1908 storage-class-specifier:
1920 (_Noreturn is new in C11.)
1922 C90 6.5.2, C99 6.7.2:
1935 [_Imaginary removed in C99 TC2]
1936 struct-or-union-specifier
1940 (_Bool and _Complex are new in C99.)
1942 C90 6.5.3, C99 6.7.3:
1948 address-space-qualifier
1950 (restrict is new in C99.)
1954 declaration-specifiers:
1955 attributes declaration-specifiers[opt]
1961 identifier recognized by the target
1963 storage-class-specifier:
1976 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1977 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1982 class-name objc-protocol-refs[opt]
1983 typedef-name objc-protocol-refs
1988 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1989 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1990 enum c_lookahead_kind la
)
1992 bool attrs_ok
= start_attr_ok
;
1993 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1996 gcc_assert (la
== cla_prefer_id
);
1998 while (c_parser_next_token_is (parser
, CPP_NAME
)
1999 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2000 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2002 struct c_typespec t
;
2005 location_t loc
= c_parser_peek_token (parser
)->location
;
2007 /* If we cannot accept a type, exit if the next token must start
2008 one. Also, if we already have seen a tagged definition,
2009 a typename would be an error anyway and likely the user
2010 has simply forgotten a semicolon, so we exit. */
2011 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2012 && c_parser_next_tokens_start_typename (parser
, la
)
2013 && !c_parser_next_token_is_qualifier (parser
))
2016 if (c_parser_next_token_is (parser
, CPP_NAME
))
2018 tree value
= c_parser_peek_token (parser
)->value
;
2019 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
2021 if (kind
== C_ID_ADDRSPACE
)
2024 = c_parser_peek_token (parser
)->keyword
- RID_FIRST_ADDR_SPACE
;
2025 declspecs_add_addrspace (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 (loc
, 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 (specs
, c_parser_peek_token (parser
)->value
);
2108 c_parser_consume_token (parser
);
2132 if (c_dialect_objc ())
2133 parser
->objc_need_raw_identifier
= true;
2134 t
.kind
= ctsk_resword
;
2135 t
.spec
= c_parser_peek_token (parser
)->value
;
2137 t
.expr_const_operands
= true;
2138 declspecs_add_type (loc
, specs
, t
);
2139 c_parser_consume_token (parser
);
2146 t
= c_parser_enum_specifier (parser
);
2147 declspecs_add_type (loc
, specs
, t
);
2155 t
= c_parser_struct_or_union_specifier (parser
);
2156 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2157 declspecs_add_type (loc
, specs
, t
);
2160 /* ??? The old parser rejected typeof after other type
2161 specifiers, but is a syntax error the best way of
2163 if (!typespec_ok
|| seen_type
)
2167 t
= c_parser_typeof_specifier (parser
);
2168 declspecs_add_type (loc
, specs
, t
);
2174 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
2175 c_parser_consume_token (parser
);
2180 attrs
= c_parser_attributes (parser
);
2181 declspecs_add_attrs (specs
, attrs
);
2184 align
= c_parser_alignas_specifier (parser
);
2185 declspecs_add_alignas (specs
, align
);
2194 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2197 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2198 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2199 enum attributes[opt] identifier
2201 The form with trailing comma is new in C99. The forms with
2202 attributes are GNU extensions. In GNU C, we accept any expression
2203 without commas in the syntax (assignment expressions, not just
2204 conditional expressions); assignment expressions will be diagnosed
2209 enumerator-list , enumerator
2212 enumeration-constant
2213 enumeration-constant = constant-expression
2216 static struct c_typespec
2217 c_parser_enum_specifier (c_parser
*parser
)
2219 struct c_typespec ret
;
2221 tree ident
= NULL_TREE
;
2222 location_t enum_loc
;
2223 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2224 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2225 enum_loc
= c_parser_peek_token (parser
)->location
;
2226 c_parser_consume_token (parser
);
2227 attrs
= c_parser_attributes (parser
);
2228 enum_loc
= c_parser_peek_token (parser
)->location
;
2229 /* Set the location in case we create a decl now. */
2230 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2231 if (c_parser_next_token_is (parser
, CPP_NAME
))
2233 ident
= c_parser_peek_token (parser
)->value
;
2234 ident_loc
= c_parser_peek_token (parser
)->location
;
2235 enum_loc
= ident_loc
;
2236 c_parser_consume_token (parser
);
2238 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2240 /* Parse an enum definition. */
2241 struct c_enum_contents the_enum
;
2244 /* We chain the enumerators in reverse order, then put them in
2245 forward order at the end. */
2247 timevar_push (TV_PARSE_ENUM
);
2248 type
= start_enum (enum_loc
, &the_enum
, ident
);
2250 c_parser_consume_token (parser
);
2258 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2259 location_t decl_loc
, value_loc
;
2260 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2262 c_parser_error (parser
, "expected identifier");
2263 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2264 values
= error_mark_node
;
2267 token
= c_parser_peek_token (parser
);
2268 enum_id
= token
->value
;
2269 /* Set the location in case we create a decl now. */
2270 c_parser_set_source_position_from_token (token
);
2271 decl_loc
= value_loc
= token
->location
;
2272 c_parser_consume_token (parser
);
2273 if (c_parser_next_token_is (parser
, CPP_EQ
))
2275 c_parser_consume_token (parser
);
2276 value_loc
= c_parser_peek_token (parser
)->location
;
2277 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2280 enum_value
= NULL_TREE
;
2281 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2282 &the_enum
, enum_id
, enum_value
);
2283 TREE_CHAIN (enum_decl
) = values
;
2286 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2288 comma_loc
= c_parser_peek_token (parser
)->location
;
2290 c_parser_consume_token (parser
);
2292 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2294 if (seen_comma
&& !flag_isoc99
)
2295 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
2296 c_parser_consume_token (parser
);
2301 c_parser_error (parser
, "expected %<,%> or %<}%>");
2302 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2303 values
= error_mark_node
;
2307 postfix_attrs
= c_parser_attributes (parser
);
2308 ret
.spec
= finish_enum (type
, nreverse (values
),
2309 chainon (attrs
, postfix_attrs
));
2310 ret
.kind
= ctsk_tagdef
;
2311 ret
.expr
= NULL_TREE
;
2312 ret
.expr_const_operands
= true;
2313 timevar_pop (TV_PARSE_ENUM
);
2318 c_parser_error (parser
, "expected %<{%>");
2319 ret
.spec
= error_mark_node
;
2320 ret
.kind
= ctsk_tagref
;
2321 ret
.expr
= NULL_TREE
;
2322 ret
.expr_const_operands
= true;
2325 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2326 /* In ISO C, enumerated types can be referred to only if already
2328 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2331 pedwarn (enum_loc
, OPT_pedantic
,
2332 "ISO C forbids forward references to %<enum%> types");
2337 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2339 struct-or-union-specifier:
2340 struct-or-union attributes[opt] identifier[opt]
2341 { struct-contents } attributes[opt]
2342 struct-or-union attributes[opt] identifier
2345 struct-declaration-list
2347 struct-declaration-list:
2348 struct-declaration ;
2349 struct-declaration-list struct-declaration ;
2356 struct-declaration-list struct-declaration
2358 struct-declaration-list:
2359 struct-declaration-list ;
2362 (Note that in the syntax here, unlike that in ISO C, the semicolons
2363 are included here rather than in struct-declaration, in order to
2364 describe the syntax with extra semicolons and missing semicolon at
2369 struct-declaration-list:
2370 @defs ( class-name )
2372 (Note this does not include a trailing semicolon, but can be
2373 followed by further declarations, and gets a pedwarn-if-pedantic
2374 when followed by a semicolon.) */
2376 static struct c_typespec
2377 c_parser_struct_or_union_specifier (c_parser
*parser
)
2379 struct c_typespec ret
;
2381 tree ident
= NULL_TREE
;
2382 location_t struct_loc
;
2383 location_t ident_loc
= UNKNOWN_LOCATION
;
2384 enum tree_code code
;
2385 switch (c_parser_peek_token (parser
)->keyword
)
2396 struct_loc
= c_parser_peek_token (parser
)->location
;
2397 c_parser_consume_token (parser
);
2398 attrs
= c_parser_attributes (parser
);
2400 /* Set the location in case we create a decl now. */
2401 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2403 if (c_parser_next_token_is (parser
, CPP_NAME
))
2405 ident
= c_parser_peek_token (parser
)->value
;
2406 ident_loc
= c_parser_peek_token (parser
)->location
;
2407 struct_loc
= ident_loc
;
2408 c_parser_consume_token (parser
);
2410 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2412 /* Parse a struct or union definition. Start the scope of the
2413 tag before parsing components. */
2414 struct c_struct_parse_info
*struct_info
;
2415 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2417 /* We chain the components in reverse order, then put them in
2418 forward order at the end. Each struct-declaration may
2419 declare multiple components (comma-separated), so we must use
2420 chainon to join them, although when parsing each
2421 struct-declaration we can use TREE_CHAIN directly.
2423 The theory behind all this is that there will be more
2424 semicolon separated fields than comma separated fields, and
2425 so we'll be minimizing the number of node traversals required
2428 timevar_push (TV_PARSE_STRUCT
);
2429 contents
= NULL_TREE
;
2430 c_parser_consume_token (parser
);
2431 /* Handle the Objective-C @defs construct,
2432 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2433 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2436 gcc_assert (c_dialect_objc ());
2437 c_parser_consume_token (parser
);
2438 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2440 if (c_parser_next_token_is (parser
, CPP_NAME
)
2441 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2443 name
= c_parser_peek_token (parser
)->value
;
2444 c_parser_consume_token (parser
);
2448 c_parser_error (parser
, "expected class name");
2449 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2452 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2454 contents
= nreverse (objc_get_class_ivars (name
));
2457 /* Parse the struct-declarations and semicolons. Problems with
2458 semicolons are diagnosed here; empty structures are diagnosed
2463 /* Parse any stray semicolon. */
2464 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2466 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
2467 "extra semicolon in struct or union specified");
2468 c_parser_consume_token (parser
);
2471 /* Stop if at the end of the struct or union contents. */
2472 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2474 c_parser_consume_token (parser
);
2477 /* Accept #pragmas at struct scope. */
2478 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2480 c_parser_pragma (parser
, pragma_external
);
2483 /* Parse some comma-separated declarations, but not the
2484 trailing semicolon if any. */
2485 decls
= c_parser_struct_declaration (parser
);
2486 contents
= chainon (decls
, contents
);
2487 /* If no semicolon follows, either we have a parse error or
2488 are at the end of the struct or union and should
2490 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2491 c_parser_consume_token (parser
);
2494 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2495 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2496 "no semicolon at end of struct or union");
2497 else if (parser
->error
2498 || !c_parser_next_token_starts_declspecs (parser
))
2500 c_parser_error (parser
, "expected %<;%>");
2501 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2505 /* If we come here, we have already emitted an error
2506 for an expected `;', identifier or `(', and we also
2507 recovered already. Go on with the next field. */
2510 postfix_attrs
= c_parser_attributes (parser
);
2511 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2512 chainon (attrs
, postfix_attrs
), struct_info
);
2513 ret
.kind
= ctsk_tagdef
;
2514 ret
.expr
= NULL_TREE
;
2515 ret
.expr_const_operands
= true;
2516 timevar_pop (TV_PARSE_STRUCT
);
2521 c_parser_error (parser
, "expected %<{%>");
2522 ret
.spec
= error_mark_node
;
2523 ret
.kind
= ctsk_tagref
;
2524 ret
.expr
= NULL_TREE
;
2525 ret
.expr_const_operands
= true;
2528 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2532 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2533 the trailing semicolon.
2536 specifier-qualifier-list struct-declarator-list
2537 static_assert-declaration-no-semi
2539 specifier-qualifier-list:
2540 type-specifier specifier-qualifier-list[opt]
2541 type-qualifier specifier-qualifier-list[opt]
2542 attributes specifier-qualifier-list[opt]
2544 struct-declarator-list:
2546 struct-declarator-list , attributes[opt] struct-declarator
2549 declarator attributes[opt]
2550 declarator[opt] : constant-expression attributes[opt]
2555 __extension__ struct-declaration
2556 specifier-qualifier-list
2558 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2559 of attributes where shown is a GNU extension. In GNU C, we accept
2560 any expression without commas in the syntax (assignment
2561 expressions, not just conditional expressions); assignment
2562 expressions will be diagnosed as non-constant. */
2565 c_parser_struct_declaration (c_parser
*parser
)
2567 struct c_declspecs
*specs
;
2569 tree all_prefix_attrs
;
2571 location_t decl_loc
;
2572 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2576 ext
= disable_extension_diagnostics ();
2577 c_parser_consume_token (parser
);
2578 decl
= c_parser_struct_declaration (parser
);
2579 restore_extension_diagnostics (ext
);
2582 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2584 c_parser_static_assert_declaration_no_semi (parser
);
2587 specs
= build_null_declspecs ();
2588 decl_loc
= c_parser_peek_token (parser
)->location
;
2589 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2592 if (!specs
->declspecs_seen_p
)
2594 c_parser_error (parser
, "expected specifier-qualifier-list");
2597 finish_declspecs (specs
);
2598 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2599 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2602 if (specs
->typespec_kind
== ctsk_none
)
2604 pedwarn (decl_loc
, OPT_pedantic
,
2605 "ISO C forbids member declarations with no members");
2606 shadow_tag_warned (specs
, pedantic
);
2611 /* Support for unnamed structs or unions as members of
2612 structs or unions (which is [a] useful and [b] supports
2616 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2617 build_id_declarator (NULL_TREE
), specs
,
2620 decl_attributes (&ret
, attrs
, 0);
2625 /* Provide better error recovery. Note that a type name here is valid,
2626 and will be treated as a field name. */
2627 if (specs
->typespec_kind
== ctsk_tagdef
2628 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2629 && c_parser_next_token_starts_declspecs (parser
)
2630 && !c_parser_next_token_is (parser
, CPP_NAME
))
2632 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2633 parser
->error
= false;
2637 pending_xref_error ();
2638 prefix_attrs
= specs
->attrs
;
2639 all_prefix_attrs
= prefix_attrs
;
2640 specs
->attrs
= NULL_TREE
;
2644 /* Declaring one or more declarators or un-named bit-fields. */
2645 struct c_declarator
*declarator
;
2647 if (c_parser_next_token_is (parser
, CPP_COLON
))
2648 declarator
= build_id_declarator (NULL_TREE
);
2650 declarator
= c_parser_declarator (parser
,
2651 specs
->typespec_kind
!= ctsk_none
,
2652 C_DTR_NORMAL
, &dummy
);
2653 if (declarator
== NULL
)
2655 c_parser_skip_to_end_of_block_or_statement (parser
);
2658 if (c_parser_next_token_is (parser
, CPP_COLON
)
2659 || c_parser_next_token_is (parser
, CPP_COMMA
)
2660 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2661 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2662 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2664 tree postfix_attrs
= NULL_TREE
;
2665 tree width
= NULL_TREE
;
2667 if (c_parser_next_token_is (parser
, CPP_COLON
))
2669 c_parser_consume_token (parser
);
2670 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2672 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2673 postfix_attrs
= c_parser_attributes (parser
);
2674 d
= grokfield (c_parser_peek_token (parser
)->location
,
2675 declarator
, specs
, width
, &all_prefix_attrs
);
2676 decl_attributes (&d
, chainon (postfix_attrs
,
2677 all_prefix_attrs
), 0);
2678 DECL_CHAIN (d
) = decls
;
2680 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2681 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2684 all_prefix_attrs
= prefix_attrs
;
2685 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2686 c_parser_consume_token (parser
);
2687 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2688 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2690 /* Semicolon consumed in caller. */
2695 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2701 c_parser_error (parser
,
2702 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2703 "%<__attribute__%>");
2710 /* Parse a typeof specifier (a GNU extension).
2713 typeof ( expression )
2714 typeof ( type-name )
2717 static struct c_typespec
2718 c_parser_typeof_specifier (c_parser
*parser
)
2720 struct c_typespec ret
;
2721 ret
.kind
= ctsk_typeof
;
2722 ret
.spec
= error_mark_node
;
2723 ret
.expr
= NULL_TREE
;
2724 ret
.expr_const_operands
= true;
2725 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2726 c_parser_consume_token (parser
);
2727 c_inhibit_evaluation_warnings
++;
2729 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2731 c_inhibit_evaluation_warnings
--;
2735 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2737 struct c_type_name
*type
= c_parser_type_name (parser
);
2738 c_inhibit_evaluation_warnings
--;
2742 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2743 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2749 location_t here
= c_parser_peek_token (parser
)->location
;
2750 struct c_expr expr
= c_parser_expression (parser
);
2751 c_inhibit_evaluation_warnings
--;
2753 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2754 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2755 error_at (here
, "%<typeof%> applied to a bit-field");
2756 mark_exp_read (expr
.value
);
2757 ret
.spec
= TREE_TYPE (expr
.value
);
2758 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2759 /* This is returned with the type so that when the type is
2760 evaluated, this can be evaluated. */
2762 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2763 pop_maybe_used (was_vm
);
2765 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2769 /* Parse an alignment-specifier.
2773 alignment-specifier:
2774 _Alignas ( type-name )
2775 _Alignas ( constant-expression )
2779 c_parser_alignas_specifier (c_parser
* parser
)
2781 tree ret
= error_mark_node
;
2782 location_t loc
= c_parser_peek_token (parser
)->location
;
2783 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2784 c_parser_consume_token (parser
);
2788 pedwarn (loc
, OPT_pedantic
,
2789 "ISO C99 does not support %<_Alignas%>");
2791 pedwarn (loc
, OPT_pedantic
,
2792 "ISO C90 does not support %<_Alignas%>");
2794 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2796 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2798 struct c_type_name
*type
= c_parser_type_name (parser
);
2800 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2803 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2804 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2808 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2809 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2810 be redeclared; otherwise it may not. KIND indicates which kind of
2811 declarator is wanted. Returns a valid declarator except in the
2812 case of a syntax error in which case NULL is returned. *SEEN_ID is
2813 set to true if an identifier being declared is seen; this is used
2814 to diagnose bad forms of abstract array declarators and to
2815 determine whether an identifier list is syntactically permitted.
2818 pointer[opt] direct-declarator
2822 ( attributes[opt] declarator )
2823 direct-declarator array-declarator
2824 direct-declarator ( parameter-type-list )
2825 direct-declarator ( identifier-list[opt] )
2828 * type-qualifier-list[opt]
2829 * type-qualifier-list[opt] pointer
2831 type-qualifier-list:
2834 type-qualifier-list type-qualifier
2835 type-qualifier-list attributes
2837 parameter-type-list:
2839 parameter-list , ...
2842 parameter-declaration
2843 parameter-list , parameter-declaration
2845 parameter-declaration:
2846 declaration-specifiers declarator attributes[opt]
2847 declaration-specifiers abstract-declarator[opt] attributes[opt]
2851 identifier-list , identifier
2853 abstract-declarator:
2855 pointer[opt] direct-abstract-declarator
2857 direct-abstract-declarator:
2858 ( attributes[opt] abstract-declarator )
2859 direct-abstract-declarator[opt] array-declarator
2860 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2865 direct-declarator ( parameter-forward-declarations
2866 parameter-type-list[opt] )
2868 direct-abstract-declarator:
2869 direct-abstract-declarator[opt] ( parameter-forward-declarations
2870 parameter-type-list[opt] )
2872 parameter-forward-declarations:
2874 parameter-forward-declarations parameter-list ;
2876 The uses of attributes shown above are GNU extensions.
2878 Some forms of array declarator are not included in C99 in the
2879 syntax for abstract declarators; these are disallowed elsewhere.
2880 This may be a defect (DR#289).
2882 This function also accepts an omitted abstract declarator as being
2883 an abstract declarator, although not part of the formal syntax. */
2885 static struct c_declarator
*
2886 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2889 /* Parse any initial pointer part. */
2890 if (c_parser_next_token_is (parser
, CPP_MULT
))
2892 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2893 struct c_declarator
*inner
;
2894 c_parser_consume_token (parser
);
2895 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2896 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2900 return make_pointer_declarator (quals_attrs
, inner
);
2902 /* Now we have a direct declarator, direct abstract declarator or
2903 nothing (which counts as a direct abstract declarator here). */
2904 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2907 /* Parse a direct declarator or direct abstract declarator; arguments
2908 as c_parser_declarator. */
2910 static struct c_declarator
*
2911 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2914 /* The direct declarator must start with an identifier (possibly
2915 omitted) or a parenthesized declarator (possibly abstract). In
2916 an ordinary declarator, initial parentheses must start a
2917 parenthesized declarator. In an abstract declarator or parameter
2918 declarator, they could start a parenthesized declarator or a
2919 parameter list. To tell which, the open parenthesis and any
2920 following attributes must be read. If a declaration specifier
2921 follows, then it is a parameter list; if the specifier is a
2922 typedef name, there might be an ambiguity about redeclaring it,
2923 which is resolved in the direction of treating it as a typedef
2924 name. If a close parenthesis follows, it is also an empty
2925 parameter list, as the syntax does not permit empty abstract
2926 declarators. Otherwise, it is a parenthesized declarator (in
2927 which case the analysis may be repeated inside it, recursively).
2929 ??? There is an ambiguity in a parameter declaration "int
2930 (__attribute__((foo)) x)", where x is not a typedef name: it
2931 could be an abstract declarator for a function, or declare x with
2932 parentheses. The proper resolution of this ambiguity needs
2933 documenting. At present we follow an accident of the old
2934 parser's implementation, whereby the first parameter must have
2935 some declaration specifiers other than just attributes. Thus as
2936 a parameter declaration it is treated as a parenthesized
2937 parameter named x, and as an abstract declarator it is
2940 ??? Also following the old parser, attributes inside an empty
2941 parameter list are ignored, making it a list not yielding a
2942 prototype, rather than giving an error or making it have one
2943 parameter with implicit type int.
2945 ??? Also following the old parser, typedef names may be
2946 redeclared in declarators, but not Objective-C class names. */
2948 if (kind
!= C_DTR_ABSTRACT
2949 && c_parser_next_token_is (parser
, CPP_NAME
)
2951 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2952 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2953 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2955 struct c_declarator
*inner
2956 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2958 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2959 c_parser_consume_token (parser
);
2960 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2963 if (kind
!= C_DTR_NORMAL
2964 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2966 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2967 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2970 /* Either we are at the end of an abstract declarator, or we have
2973 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2976 struct c_declarator
*inner
;
2977 c_parser_consume_token (parser
);
2978 attrs
= c_parser_attributes (parser
);
2979 if (kind
!= C_DTR_NORMAL
2980 && (c_parser_next_token_starts_declspecs (parser
)
2981 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2983 struct c_arg_info
*args
2984 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2991 = build_function_declarator (args
,
2992 build_id_declarator (NULL_TREE
));
2993 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2997 /* A parenthesized declarator. */
2998 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2999 if (inner
!= NULL
&& attrs
!= NULL
)
3000 inner
= build_attrs_declarator (attrs
, inner
);
3001 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3003 c_parser_consume_token (parser
);
3007 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3011 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3018 if (kind
== C_DTR_NORMAL
)
3020 c_parser_error (parser
, "expected identifier or %<(%>");
3024 return build_id_declarator (NULL_TREE
);
3028 /* Parse part of a direct declarator or direct abstract declarator,
3029 given that some (in INNER) has already been parsed; ID_PRESENT is
3030 true if an identifier is present, false for an abstract
3033 static struct c_declarator
*
3034 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3035 struct c_declarator
*inner
)
3037 /* Parse a sequence of array declarators and parameter lists. */
3038 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3040 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3041 struct c_declarator
*declarator
;
3042 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3046 c_parser_consume_token (parser
);
3047 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3048 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3050 c_parser_consume_token (parser
);
3051 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3052 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3053 if (!quals_attrs
->declspecs_seen_p
)
3055 /* If "static" is present, there must be an array dimension.
3056 Otherwise, there may be a dimension, "*", or no
3061 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3065 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3070 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3072 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3076 c_parser_consume_token (parser
);
3081 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3087 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3090 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3091 c_parser_consume_token (parser
);
3094 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3099 mark_exp_read (dimen
);
3100 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3101 static_seen
, star_seen
);
3102 if (declarator
== NULL
)
3104 inner
= set_array_declarator_inner (declarator
, inner
);
3105 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3107 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3110 struct c_arg_info
*args
;
3111 c_parser_consume_token (parser
);
3112 attrs
= c_parser_attributes (parser
);
3113 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3118 inner
= build_function_declarator (args
, inner
);
3119 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3125 /* Parse a parameter list or identifier list, including the closing
3126 parenthesis but not the opening one. ATTRS are the attributes at
3127 the start of the list. ID_LIST_OK is true if an identifier list is
3128 acceptable; such a list must not have attributes at the start. */
3130 static struct c_arg_info
*
3131 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3134 declare_parm_level ();
3135 /* If the list starts with an identifier, it is an identifier list.
3136 Otherwise, it is either a prototype list or an empty list. */
3139 && c_parser_next_token_is (parser
, CPP_NAME
)
3140 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3142 /* Look ahead to detect typos in type names. */
3143 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3144 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3145 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3146 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3148 tree list
= NULL_TREE
, *nextp
= &list
;
3149 while (c_parser_next_token_is (parser
, CPP_NAME
)
3150 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3152 *nextp
= build_tree_list (NULL_TREE
,
3153 c_parser_peek_token (parser
)->value
);
3154 nextp
= & TREE_CHAIN (*nextp
);
3155 c_parser_consume_token (parser
);
3156 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3158 c_parser_consume_token (parser
);
3159 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3161 c_parser_error (parser
, "expected identifier");
3165 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3167 struct c_arg_info
*ret
= build_arg_info ();
3169 c_parser_consume_token (parser
);
3175 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3183 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3190 /* Parse a parameter list (possibly empty), including the closing
3191 parenthesis but not the opening one. ATTRS are the attributes at
3192 the start of the list. EXPR is NULL or an expression that needs to
3193 be evaluated for the side effects of array size expressions in the
3196 static struct c_arg_info
*
3197 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3199 bool bad_parm
= false;
3201 /* ??? Following the old parser, forward parameter declarations may
3202 use abstract declarators, and if no real parameter declarations
3203 follow the forward declarations then this is not diagnosed. Also
3204 note as above that attributes are ignored as the only contents of
3205 the parentheses, or as the only contents after forward
3207 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3209 struct c_arg_info
*ret
= build_arg_info ();
3210 c_parser_consume_token (parser
);
3213 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3215 struct c_arg_info
*ret
= build_arg_info ();
3217 if (flag_allow_parameterless_variadic_functions
)
3219 /* F (...) is allowed. */
3220 ret
->types
= NULL_TREE
;
3224 /* Suppress -Wold-style-definition for this case. */
3225 ret
->types
= error_mark_node
;
3226 error_at (c_parser_peek_token (parser
)->location
,
3227 "ISO C requires a named argument before %<...%>");
3229 c_parser_consume_token (parser
);
3230 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3232 c_parser_consume_token (parser
);
3237 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3242 /* Nonempty list of parameters, either terminated with semicolon
3243 (forward declarations; recurse) or with close parenthesis (normal
3244 function) or with ", ... )" (variadic function). */
3247 /* Parse a parameter. */
3248 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3253 push_parm_decl (parm
, &expr
);
3254 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3257 c_parser_consume_token (parser
);
3258 mark_forward_parm_decls ();
3259 new_attrs
= c_parser_attributes (parser
);
3260 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3262 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3264 c_parser_consume_token (parser
);
3268 return get_parm_info (false, expr
);
3270 if (!c_parser_require (parser
, CPP_COMMA
,
3271 "expected %<;%>, %<,%> or %<)%>"))
3273 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3276 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3278 c_parser_consume_token (parser
);
3279 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3281 c_parser_consume_token (parser
);
3285 return get_parm_info (true, expr
);
3289 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3297 /* Parse a parameter declaration. ATTRS are the attributes at the
3298 start of the declaration if it is the first parameter. */
3300 static struct c_parm
*
3301 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3303 struct c_declspecs
*specs
;
3304 struct c_declarator
*declarator
;
3306 tree postfix_attrs
= NULL_TREE
;
3309 /* Accept #pragmas between parameter declarations. */
3310 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3311 c_parser_pragma (parser
, pragma_external
);
3313 if (!c_parser_next_token_starts_declspecs (parser
))
3315 c_token
*token
= c_parser_peek_token (parser
);
3318 c_parser_set_source_position_from_token (token
);
3319 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3321 error ("unknown type name %qE", token
->value
);
3322 parser
->error
= true;
3324 /* ??? In some Objective-C cases '...' isn't applicable so there
3325 should be a different message. */
3327 c_parser_error (parser
,
3328 "expected declaration specifiers or %<...%>");
3329 c_parser_skip_to_end_of_parameter (parser
);
3332 specs
= build_null_declspecs ();
3335 declspecs_add_attrs (specs
, attrs
);
3338 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3339 finish_declspecs (specs
);
3340 pending_xref_error ();
3341 prefix_attrs
= specs
->attrs
;
3342 specs
->attrs
= NULL_TREE
;
3343 declarator
= c_parser_declarator (parser
,
3344 specs
->typespec_kind
!= ctsk_none
,
3345 C_DTR_PARM
, &dummy
);
3346 if (declarator
== NULL
)
3348 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3351 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3352 postfix_attrs
= c_parser_attributes (parser
);
3353 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3357 /* Parse a string literal in an asm expression. It should not be
3358 translated, and wide string literals are an error although
3359 permitted by the syntax. This is a GNU extension.
3364 ??? At present, following the old parser, the caller needs to have
3365 set lex_untranslated_string to 1. It would be better to follow the
3366 C++ parser rather than using this kludge. */
3369 c_parser_asm_string_literal (c_parser
*parser
)
3372 int save_flag
= warn_overlength_strings
;
3373 warn_overlength_strings
= 0;
3374 if (c_parser_next_token_is (parser
, CPP_STRING
))
3376 str
= c_parser_peek_token (parser
)->value
;
3377 c_parser_consume_token (parser
);
3379 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3381 error_at (c_parser_peek_token (parser
)->location
,
3382 "wide string literal in %<asm%>");
3383 str
= build_string (1, "");
3384 c_parser_consume_token (parser
);
3388 c_parser_error (parser
, "expected string literal");
3391 warn_overlength_strings
= save_flag
;
3395 /* Parse a simple asm expression. This is used in restricted
3396 contexts, where a full expression with inputs and outputs does not
3397 make sense. This is a GNU extension.
3400 asm ( asm-string-literal )
3404 c_parser_simple_asm_expr (c_parser
*parser
)
3407 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3408 /* ??? Follow the C++ parser rather than using the
3409 lex_untranslated_string kludge. */
3410 parser
->lex_untranslated_string
= true;
3411 c_parser_consume_token (parser
);
3412 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3414 parser
->lex_untranslated_string
= false;
3417 str
= c_parser_asm_string_literal (parser
);
3418 parser
->lex_untranslated_string
= false;
3419 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3421 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3428 c_parser_attribute_any_word (c_parser
*parser
)
3430 tree attr_name
= NULL_TREE
;
3432 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3434 /* ??? See comment above about what keywords are accepted here. */
3436 switch (c_parser_peek_token (parser
)->keyword
)
3467 case RID_TRANSACTION_ATOMIC
:
3468 case RID_TRANSACTION_CANCEL
:
3478 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3479 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3481 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3482 attr_name
= c_parser_peek_token (parser
)->value
;
3487 /* Parse (possibly empty) attributes. This is a GNU extension.
3491 attributes attribute
3494 __attribute__ ( ( attribute-list ) )
3498 attribute_list , attrib
3503 any-word ( identifier )
3504 any-word ( identifier , nonempty-expr-list )
3505 any-word ( expr-list )
3507 where the "identifier" must not be declared as a type, and
3508 "any-word" may be any identifier (including one declared as a
3509 type), a reserved word storage class specifier, type specifier or
3510 type qualifier. ??? This still leaves out most reserved keywords
3511 (following the old parser), shouldn't we include them, and why not
3512 allow identifiers declared as types to start the arguments? */
3515 c_parser_attributes (c_parser
*parser
)
3517 tree attrs
= NULL_TREE
;
3518 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3520 /* ??? Follow the C++ parser rather than using the
3521 lex_untranslated_string kludge. */
3522 parser
->lex_untranslated_string
= true;
3523 c_parser_consume_token (parser
);
3524 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3526 parser
->lex_untranslated_string
= false;
3529 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3531 parser
->lex_untranslated_string
= false;
3532 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3535 /* Parse the attribute list. */
3536 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3537 || c_parser_next_token_is (parser
, CPP_NAME
)
3538 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3540 tree attr
, attr_name
, attr_args
;
3541 VEC(tree
,gc
) *expr_list
;
3542 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3544 c_parser_consume_token (parser
);
3548 attr_name
= c_parser_attribute_any_word (parser
);
3549 if (attr_name
== NULL
)
3551 c_parser_consume_token (parser
);
3552 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3554 attr
= build_tree_list (attr_name
, NULL_TREE
);
3555 attrs
= chainon (attrs
, attr
);
3558 c_parser_consume_token (parser
);
3559 /* Parse the attribute contents. If they start with an
3560 identifier which is followed by a comma or close
3561 parenthesis, then the arguments start with that
3562 identifier; otherwise they are an expression list.
3563 In objective-c the identifier may be a classname. */
3564 if (c_parser_next_token_is (parser
, CPP_NAME
)
3565 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3566 || (c_dialect_objc ()
3567 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3568 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3569 || (c_parser_peek_2nd_token (parser
)->type
3570 == CPP_CLOSE_PAREN
)))
3572 tree arg1
= c_parser_peek_token (parser
)->value
;
3573 c_parser_consume_token (parser
);
3574 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3575 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3579 c_parser_consume_token (parser
);
3580 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3581 tree_list
= build_tree_list_vec (expr_list
);
3582 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3583 release_tree_vector (expr_list
);
3588 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3589 attr_args
= NULL_TREE
;
3592 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3593 attr_args
= build_tree_list_vec (expr_list
);
3594 release_tree_vector (expr_list
);
3597 attr
= build_tree_list (attr_name
, attr_args
);
3598 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3599 c_parser_consume_token (parser
);
3602 parser
->lex_untranslated_string
= false;
3603 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3607 attrs
= chainon (attrs
, attr
);
3609 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3610 c_parser_consume_token (parser
);
3613 parser
->lex_untranslated_string
= false;
3614 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3618 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3619 c_parser_consume_token (parser
);
3622 parser
->lex_untranslated_string
= false;
3623 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3627 parser
->lex_untranslated_string
= false;
3632 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3635 specifier-qualifier-list abstract-declarator[opt]
3638 static struct c_type_name
*
3639 c_parser_type_name (c_parser
*parser
)
3641 struct c_declspecs
*specs
= build_null_declspecs ();
3642 struct c_declarator
*declarator
;
3643 struct c_type_name
*ret
;
3645 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3646 if (!specs
->declspecs_seen_p
)
3648 c_parser_error (parser
, "expected specifier-qualifier-list");
3651 if (specs
->type
!= error_mark_node
)
3653 pending_xref_error ();
3654 finish_declspecs (specs
);
3656 declarator
= c_parser_declarator (parser
,
3657 specs
->typespec_kind
!= ctsk_none
,
3658 C_DTR_ABSTRACT
, &dummy
);
3659 if (declarator
== NULL
)
3661 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3663 ret
->declarator
= declarator
;
3667 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3670 assignment-expression
3671 { initializer-list }
3672 { initializer-list , }
3675 designation[opt] initializer
3676 initializer-list , designation[opt] initializer
3683 designator-list designator
3690 [ constant-expression ]
3702 [ constant-expression ... constant-expression ]
3704 Any expression without commas is accepted in the syntax for the
3705 constant-expressions, with non-constant expressions rejected later.
3707 This function is only used for top-level initializers; for nested
3708 ones, see c_parser_initval. */
3710 static struct c_expr
3711 c_parser_initializer (c_parser
*parser
)
3713 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3714 return c_parser_braced_init (parser
, NULL_TREE
, false);
3718 location_t loc
= c_parser_peek_token (parser
)->location
;
3719 ret
= c_parser_expr_no_commas (parser
, NULL
);
3720 if (TREE_CODE (ret
.value
) != STRING_CST
3721 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3722 ret
= default_function_array_read_conversion (loc
, ret
);
3727 /* Parse a braced initializer list. TYPE is the type specified for a
3728 compound literal, and NULL_TREE for other initializers and for
3729 nested braced lists. NESTED_P is true for nested braced lists,
3730 false for the list of a compound literal or the list that is the
3731 top-level initializer in a declaration. */
3733 static struct c_expr
3734 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3737 struct obstack braced_init_obstack
;
3738 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3739 gcc_obstack_init (&braced_init_obstack
);
3740 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3741 c_parser_consume_token (parser
);
3743 push_init_level (0, &braced_init_obstack
);
3745 really_start_incremental_init (type
);
3746 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3748 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3752 /* Parse a non-empty initializer list, possibly with a trailing
3756 c_parser_initelt (parser
, &braced_init_obstack
);
3759 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3760 c_parser_consume_token (parser
);
3763 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3767 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3769 ret
.value
= error_mark_node
;
3770 ret
.original_code
= ERROR_MARK
;
3771 ret
.original_type
= NULL
;
3772 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3773 pop_init_level (0, &braced_init_obstack
);
3774 obstack_free (&braced_init_obstack
, NULL
);
3777 c_parser_consume_token (parser
);
3778 ret
= pop_init_level (0, &braced_init_obstack
);
3779 obstack_free (&braced_init_obstack
, NULL
);
3783 /* Parse a nested initializer, including designators. */
3786 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3788 /* Parse any designator or designator list. A single array
3789 designator may have the subsequent "=" omitted in GNU C, but a
3790 longer list or a structure member designator may not. */
3791 if (c_parser_next_token_is (parser
, CPP_NAME
)
3792 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3794 /* Old-style structure member designator. */
3795 set_init_label (c_parser_peek_token (parser
)->value
,
3796 braced_init_obstack
);
3797 /* Use the colon as the error location. */
3798 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3799 "obsolete use of designated initializer with %<:%>");
3800 c_parser_consume_token (parser
);
3801 c_parser_consume_token (parser
);
3805 /* des_seen is 0 if there have been no designators, 1 if there
3806 has been a single array designator and 2 otherwise. */
3808 /* Location of a designator. */
3809 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3810 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3811 || c_parser_next_token_is (parser
, CPP_DOT
))
3813 int des_prev
= des_seen
;
3815 des_loc
= c_parser_peek_token (parser
)->location
;
3818 if (c_parser_next_token_is (parser
, CPP_DOT
))
3821 c_parser_consume_token (parser
);
3822 if (c_parser_next_token_is (parser
, CPP_NAME
))
3824 set_init_label (c_parser_peek_token (parser
)->value
,
3825 braced_init_obstack
);
3826 c_parser_consume_token (parser
);
3831 init
.value
= error_mark_node
;
3832 init
.original_code
= ERROR_MARK
;
3833 init
.original_type
= NULL
;
3834 c_parser_error (parser
, "expected identifier");
3835 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3836 process_init_element (init
, false, braced_init_obstack
);
3843 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3844 /* ??? Following the old parser, [ objc-receiver
3845 objc-message-args ] is accepted as an initializer,
3846 being distinguished from a designator by what follows
3847 the first assignment expression inside the square
3848 brackets, but after a first array designator a
3849 subsequent square bracket is for Objective-C taken to
3850 start an expression, using the obsolete form of
3851 designated initializer without '=', rather than
3852 possibly being a second level of designation: in LALR
3853 terms, the '[' is shifted rather than reducing
3854 designator to designator-list. */
3855 if (des_prev
== 1 && c_dialect_objc ())
3857 des_seen
= des_prev
;
3860 if (des_prev
== 0 && c_dialect_objc ())
3862 /* This might be an array designator or an
3863 Objective-C message expression. If the former,
3864 continue parsing here; if the latter, parse the
3865 remainder of the initializer given the starting
3866 primary-expression. ??? It might make sense to
3867 distinguish when des_prev == 1 as well; see
3868 previous comment. */
3870 struct c_expr mexpr
;
3871 c_parser_consume_token (parser
);
3872 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3873 && ((c_parser_peek_token (parser
)->id_kind
3875 || (c_parser_peek_token (parser
)->id_kind
3876 == C_ID_CLASSNAME
)))
3878 /* Type name receiver. */
3879 tree id
= c_parser_peek_token (parser
)->value
;
3880 c_parser_consume_token (parser
);
3881 rec
= objc_get_class_reference (id
);
3882 goto parse_message_args
;
3884 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3885 mark_exp_read (first
);
3886 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3887 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3888 goto array_desig_after_first
;
3889 /* Expression receiver. So far only one part
3890 without commas has been parsed; there might be
3891 more of the expression. */
3893 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3896 location_t comma_loc
, exp_loc
;
3897 comma_loc
= c_parser_peek_token (parser
)->location
;
3898 c_parser_consume_token (parser
);
3899 exp_loc
= c_parser_peek_token (parser
)->location
;
3900 next
= c_parser_expr_no_commas (parser
, NULL
);
3901 next
= default_function_array_read_conversion (exp_loc
,
3903 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3906 /* Now parse the objc-message-args. */
3907 args
= c_parser_objc_message_args (parser
);
3908 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3911 = objc_build_message_expr (rec
, args
);
3912 mexpr
.original_code
= ERROR_MARK
;
3913 mexpr
.original_type
= NULL
;
3914 /* Now parse and process the remainder of the
3915 initializer, starting with this message
3916 expression as a primary-expression. */
3917 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3920 c_parser_consume_token (parser
);
3921 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3922 mark_exp_read (first
);
3923 array_desig_after_first
:
3924 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3926 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3927 c_parser_consume_token (parser
);
3928 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3929 mark_exp_read (second
);
3933 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3935 c_parser_consume_token (parser
);
3936 set_init_index (first
, second
, braced_init_obstack
);
3938 pedwarn (ellipsis_loc
, OPT_pedantic
,
3939 "ISO C forbids specifying range of elements to initialize");
3942 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3948 if (c_parser_next_token_is (parser
, CPP_EQ
))
3951 pedwarn (des_loc
, OPT_pedantic
,
3952 "ISO C90 forbids specifying subobject to initialize");
3953 c_parser_consume_token (parser
);
3958 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3959 "obsolete use of designated initializer without %<=%>");
3963 init
.value
= error_mark_node
;
3964 init
.original_code
= ERROR_MARK
;
3965 init
.original_type
= NULL
;
3966 c_parser_error (parser
, "expected %<=%>");
3967 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3968 process_init_element (init
, false, braced_init_obstack
);
3974 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3977 /* Parse a nested initializer; as c_parser_initializer but parses
3978 initializers within braced lists, after any designators have been
3979 applied. If AFTER is not NULL then it is an Objective-C message
3980 expression which is the primary-expression starting the
3984 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
3985 struct obstack
* braced_init_obstack
)
3988 gcc_assert (!after
|| c_dialect_objc ());
3989 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3990 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3993 location_t loc
= c_parser_peek_token (parser
)->location
;
3994 init
= c_parser_expr_no_commas (parser
, after
);
3995 if (init
.value
!= NULL_TREE
3996 && TREE_CODE (init
.value
) != STRING_CST
3997 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3998 init
= default_function_array_read_conversion (loc
, init
);
4000 process_init_element (init
, false, braced_init_obstack
);
4003 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4007 { block-item-list[opt] }
4008 { label-declarations block-item-list }
4012 block-item-list block-item
4024 { label-declarations block-item-list }
4027 __extension__ nested-declaration
4028 nested-function-definition
4032 label-declarations label-declaration
4035 __label__ identifier-list ;
4037 Allowing the mixing of declarations and code is new in C99. The
4038 GNU syntax also permits (not shown above) labels at the end of
4039 compound statements, which yield an error. We don't allow labels
4040 on declarations; this might seem like a natural extension, but
4041 there would be a conflict between attributes on the label and
4042 prefix attributes on the declaration. ??? The syntax follows the
4043 old parser in requiring something after label declarations.
4044 Although they are erroneous if the labels declared aren't defined,
4045 is it useful for the syntax to be this way?
4057 c_parser_compound_statement (c_parser
*parser
)
4060 location_t brace_loc
;
4061 brace_loc
= c_parser_peek_token (parser
)->location
;
4062 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4064 /* Ensure a scope is entered and left anyway to avoid confusion
4065 if we have just prepared to enter a function body. */
4066 stmt
= c_begin_compound_stmt (true);
4067 c_end_compound_stmt (brace_loc
, stmt
, true);
4068 return error_mark_node
;
4070 stmt
= c_begin_compound_stmt (true);
4071 c_parser_compound_statement_nostart (parser
);
4072 return c_end_compound_stmt (brace_loc
, stmt
, true);
4075 /* Parse a compound statement except for the opening brace. This is
4076 used for parsing both compound statements and statement expressions
4077 (which follow different paths to handling the opening). */
4080 c_parser_compound_statement_nostart (c_parser
*parser
)
4082 bool last_stmt
= false;
4083 bool last_label
= false;
4084 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4085 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4086 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4088 c_parser_consume_token (parser
);
4091 mark_valid_location_for_stdc_pragma (true);
4092 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4094 /* Read zero or more forward-declarations for labels that nested
4095 functions can jump to. */
4096 mark_valid_location_for_stdc_pragma (false);
4097 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4099 label_loc
= c_parser_peek_token (parser
)->location
;
4100 c_parser_consume_token (parser
);
4101 /* Any identifiers, including those declared as type names,
4106 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4108 c_parser_error (parser
, "expected identifier");
4112 = declare_label (c_parser_peek_token (parser
)->value
);
4113 C_DECLARED_LABEL_FLAG (label
) = 1;
4114 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4115 c_parser_consume_token (parser
);
4116 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4117 c_parser_consume_token (parser
);
4121 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4123 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
4125 /* We must now have at least one statement, label or declaration. */
4126 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4128 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4129 c_parser_error (parser
, "expected declaration or statement");
4130 c_parser_consume_token (parser
);
4133 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4135 location_t loc
= c_parser_peek_token (parser
)->location
;
4136 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4137 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4138 || (c_parser_next_token_is (parser
, CPP_NAME
)
4139 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4141 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4142 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4144 label_loc
= c_parser_peek_token (parser
)->location
;
4147 mark_valid_location_for_stdc_pragma (false);
4148 c_parser_label (parser
);
4150 else if (!last_label
4151 && c_parser_next_tokens_start_declaration (parser
))
4154 mark_valid_location_for_stdc_pragma (false);
4155 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4158 (pedantic
&& !flag_isoc99
)
4160 : OPT_Wdeclaration_after_statement
,
4161 "ISO C90 forbids mixed declarations and code");
4164 else if (!last_label
4165 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4167 /* __extension__ can start a declaration, but is also an
4168 unary operator that can start an expression. Consume all
4169 but the last of a possible series of __extension__ to
4171 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4172 && (c_parser_peek_2nd_token (parser
)->keyword
4174 c_parser_consume_token (parser
);
4175 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4178 ext
= disable_extension_diagnostics ();
4179 c_parser_consume_token (parser
);
4181 mark_valid_location_for_stdc_pragma (false);
4182 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4184 /* Following the old parser, __extension__ does not
4185 disable this diagnostic. */
4186 restore_extension_diagnostics (ext
);
4188 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4190 : OPT_Wdeclaration_after_statement
,
4191 "ISO C90 forbids mixed declarations and code");
4197 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4199 /* External pragmas, and some omp pragmas, are not associated
4200 with regular c code, and so are not to be considered statements
4201 syntactically. This ensures that the user doesn't put them
4202 places that would turn into syntax errors if the directive
4204 if (c_parser_pragma (parser
, pragma_compound
))
4205 last_label
= false, last_stmt
= true;
4207 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4209 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4210 c_parser_error (parser
, "expected declaration or statement");
4213 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4215 if (parser
->in_if_block
)
4217 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4218 error_at (loc
, """expected %<}%> before %<else%>");
4223 error_at (loc
, "%<else%> without a previous %<if%>");
4224 c_parser_consume_token (parser
);
4233 mark_valid_location_for_stdc_pragma (false);
4234 c_parser_statement_after_labels (parser
);
4237 parser
->error
= false;
4240 error_at (label_loc
, "label at end of compound statement");
4241 c_parser_consume_token (parser
);
4242 /* Restore the value we started with. */
4243 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4246 /* Parse a label (C90 6.6.1, C99 6.8.1).
4249 identifier : attributes[opt]
4250 case constant-expression :
4256 case constant-expression ... constant-expression :
4258 The use of attributes on labels is a GNU extension. The syntax in
4259 GNU C accepts any expressions without commas, non-constant
4260 expressions being rejected later. */
4263 c_parser_label (c_parser
*parser
)
4265 location_t loc1
= c_parser_peek_token (parser
)->location
;
4266 tree label
= NULL_TREE
;
4267 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4270 c_parser_consume_token (parser
);
4271 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4272 if (c_parser_next_token_is (parser
, CPP_COLON
))
4274 c_parser_consume_token (parser
);
4275 label
= do_case (loc1
, exp1
, NULL_TREE
);
4277 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4279 c_parser_consume_token (parser
);
4280 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4281 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4282 label
= do_case (loc1
, exp1
, exp2
);
4285 c_parser_error (parser
, "expected %<:%> or %<...%>");
4287 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4289 c_parser_consume_token (parser
);
4290 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4291 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4295 tree name
= c_parser_peek_token (parser
)->value
;
4298 location_t loc2
= c_parser_peek_token (parser
)->location
;
4299 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4300 c_parser_consume_token (parser
);
4301 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4302 c_parser_consume_token (parser
);
4303 attrs
= c_parser_attributes (parser
);
4304 tlab
= define_label (loc2
, name
);
4307 decl_attributes (&tlab
, attrs
, 0);
4308 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4313 if (c_parser_next_tokens_start_declaration (parser
))
4315 error_at (c_parser_peek_token (parser
)->location
,
4316 "a label can only be part of a statement and "
4317 "a declaration is not a statement");
4318 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4319 /*static_assert_ok*/ true,
4320 /*nested*/ true, /*empty_ok*/ false,
4321 /*start_attr_ok*/ true, NULL
);
4326 /* Parse a statement (C90 6.6, C99 6.8).
4331 expression-statement
4339 expression-statement:
4342 selection-statement:
4346 iteration-statement:
4355 return expression[opt] ;
4368 objc-throw-statement
4369 objc-try-catch-statement
4370 objc-synchronized-statement
4372 objc-throw-statement:
4386 parallel-for-construct
4387 parallel-sections-construct
4394 parallel-directive structured-block
4397 for-directive iteration-statement
4400 sections-directive section-scope
4403 single-directive structured-block
4405 parallel-for-construct:
4406 parallel-for-directive iteration-statement
4408 parallel-sections-construct:
4409 parallel-sections-directive section-scope
4412 master-directive structured-block
4415 critical-directive structured-block
4418 atomic-directive expression-statement
4421 ordered-directive structured-block
4423 Transactional Memory:
4426 transaction-statement
4427 transaction-cancel-statement
4431 c_parser_statement (c_parser
*parser
)
4433 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4434 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4435 || (c_parser_next_token_is (parser
, CPP_NAME
)
4436 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4437 c_parser_label (parser
);
4438 c_parser_statement_after_labels (parser
);
4441 /* Parse a statement, other than a labeled statement. */
4444 c_parser_statement_after_labels (c_parser
*parser
)
4446 location_t loc
= c_parser_peek_token (parser
)->location
;
4447 tree stmt
= NULL_TREE
;
4448 bool in_if_block
= parser
->in_if_block
;
4449 parser
->in_if_block
= false;
4450 switch (c_parser_peek_token (parser
)->type
)
4452 case CPP_OPEN_BRACE
:
4453 add_stmt (c_parser_compound_statement (parser
));
4456 switch (c_parser_peek_token (parser
)->keyword
)
4459 c_parser_if_statement (parser
);
4462 c_parser_switch_statement (parser
);
4465 c_parser_while_statement (parser
);
4468 c_parser_do_statement (parser
);
4471 c_parser_for_statement (parser
);
4474 c_parser_consume_token (parser
);
4475 if (c_parser_next_token_is (parser
, CPP_NAME
))
4477 stmt
= c_finish_goto_label (loc
,
4478 c_parser_peek_token (parser
)->value
);
4479 c_parser_consume_token (parser
);
4481 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4485 c_parser_consume_token (parser
);
4486 val
= c_parser_expression (parser
).value
;
4487 mark_exp_read (val
);
4488 stmt
= c_finish_goto_ptr (loc
, val
);
4491 c_parser_error (parser
, "expected identifier or %<*%>");
4492 goto expect_semicolon
;
4494 c_parser_consume_token (parser
);
4495 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4496 goto expect_semicolon
;
4498 c_parser_consume_token (parser
);
4499 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4500 goto expect_semicolon
;
4502 c_parser_consume_token (parser
);
4503 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4505 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4506 c_parser_consume_token (parser
);
4510 struct c_expr expr
= c_parser_expression_conv (parser
);
4511 mark_exp_read (expr
.value
);
4512 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4513 goto expect_semicolon
;
4517 stmt
= c_parser_asm_statement (parser
);
4519 case RID_TRANSACTION_ATOMIC
:
4520 case RID_TRANSACTION_RELAXED
:
4521 stmt
= c_parser_transaction (parser
,
4522 c_parser_peek_token (parser
)->keyword
);
4524 case RID_TRANSACTION_CANCEL
:
4525 stmt
= c_parser_transaction_cancel (parser
);
4526 goto expect_semicolon
;
4528 gcc_assert (c_dialect_objc ());
4529 c_parser_consume_token (parser
);
4530 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4532 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4533 c_parser_consume_token (parser
);
4537 tree expr
= c_parser_expression (parser
).value
;
4538 expr
= c_fully_fold (expr
, false, NULL
);
4539 stmt
= objc_build_throw_stmt (loc
, expr
);
4540 goto expect_semicolon
;
4544 gcc_assert (c_dialect_objc ());
4545 c_parser_objc_try_catch_finally_statement (parser
);
4547 case RID_AT_SYNCHRONIZED
:
4548 gcc_assert (c_dialect_objc ());
4549 c_parser_objc_synchronized_statement (parser
);
4556 c_parser_consume_token (parser
);
4558 case CPP_CLOSE_PAREN
:
4559 case CPP_CLOSE_SQUARE
:
4560 /* Avoid infinite loop in error recovery:
4561 c_parser_skip_until_found stops at a closing nesting
4562 delimiter without consuming it, but here we need to consume
4563 it to proceed further. */
4564 c_parser_error (parser
, "expected statement");
4565 c_parser_consume_token (parser
);
4568 c_parser_pragma (parser
, pragma_stmt
);
4572 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4574 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4577 /* Two cases cannot and do not have line numbers associated: If stmt
4578 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4579 cannot hold line numbers. But that's OK because the statement
4580 will either be changed to a MODIFY_EXPR during gimplification of
4581 the statement expr, or discarded. If stmt was compound, but
4582 without new variables, we will have skipped the creation of a
4583 BIND and will have a bare STATEMENT_LIST. But that's OK because
4584 (recursively) all of the component statements should already have
4585 line numbers assigned. ??? Can we discard no-op statements
4587 if (CAN_HAVE_LOCATION_P (stmt
)
4588 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4589 SET_EXPR_LOCATION (stmt
, loc
);
4591 parser
->in_if_block
= in_if_block
;
4594 /* Parse the condition from an if, do, while or for statements. */
4597 c_parser_condition (c_parser
*parser
)
4599 location_t loc
= c_parser_peek_token (parser
)->location
;
4601 cond
= c_parser_expression_conv (parser
).value
;
4602 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4603 cond
= c_fully_fold (cond
, false, NULL
);
4604 if (warn_sequence_point
)
4605 verify_sequence_points (cond
);
4609 /* Parse a parenthesized condition from an if, do or while statement.
4615 c_parser_paren_condition (c_parser
*parser
)
4618 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4619 return error_mark_node
;
4620 cond
= c_parser_condition (parser
);
4621 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4625 /* Parse a statement which is a block in C99. */
4628 c_parser_c99_block_statement (c_parser
*parser
)
4630 tree block
= c_begin_compound_stmt (flag_isoc99
);
4631 location_t loc
= c_parser_peek_token (parser
)->location
;
4632 c_parser_statement (parser
);
4633 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4636 /* Parse the body of an if statement. This is just parsing a
4637 statement but (a) it is a block in C99, (b) we track whether the
4638 body is an if statement for the sake of -Wparentheses warnings, (c)
4639 we handle an empty body specially for the sake of -Wempty-body
4640 warnings, and (d) we call parser_compound_statement directly
4641 because c_parser_statement_after_labels resets
4642 parser->in_if_block. */
4645 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4647 tree block
= c_begin_compound_stmt (flag_isoc99
);
4648 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4649 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4650 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4651 || (c_parser_next_token_is (parser
, CPP_NAME
)
4652 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4653 c_parser_label (parser
);
4654 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4655 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4657 location_t loc
= c_parser_peek_token (parser
)->location
;
4658 add_stmt (build_empty_stmt (loc
));
4659 c_parser_consume_token (parser
);
4660 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4661 warning_at (loc
, OPT_Wempty_body
,
4662 "suggest braces around empty body in an %<if%> statement");
4664 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4665 add_stmt (c_parser_compound_statement (parser
));
4667 c_parser_statement_after_labels (parser
);
4668 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4671 /* Parse the else body of an if statement. This is just parsing a
4672 statement but (a) it is a block in C99, (b) we handle an empty body
4673 specially for the sake of -Wempty-body warnings. */
4676 c_parser_else_body (c_parser
*parser
)
4678 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4679 tree block
= c_begin_compound_stmt (flag_isoc99
);
4680 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4681 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4682 || (c_parser_next_token_is (parser
, CPP_NAME
)
4683 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4684 c_parser_label (parser
);
4685 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4687 location_t loc
= c_parser_peek_token (parser
)->location
;
4690 "suggest braces around empty body in an %<else%> statement");
4691 add_stmt (build_empty_stmt (loc
));
4692 c_parser_consume_token (parser
);
4695 c_parser_statement_after_labels (parser
);
4696 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4699 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4702 if ( expression ) statement
4703 if ( expression ) statement else statement
4707 c_parser_if_statement (c_parser
*parser
)
4712 bool first_if
= false;
4713 tree first_body
, second_body
;
4716 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4717 c_parser_consume_token (parser
);
4718 block
= c_begin_compound_stmt (flag_isoc99
);
4719 loc
= c_parser_peek_token (parser
)->location
;
4720 cond
= c_parser_paren_condition (parser
);
4721 in_if_block
= parser
->in_if_block
;
4722 parser
->in_if_block
= true;
4723 first_body
= c_parser_if_body (parser
, &first_if
);
4724 parser
->in_if_block
= in_if_block
;
4725 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4727 c_parser_consume_token (parser
);
4728 second_body
= c_parser_else_body (parser
);
4731 second_body
= NULL_TREE
;
4732 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4733 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4736 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4739 switch (expression) statement
4743 c_parser_switch_statement (c_parser
*parser
)
4745 tree block
, expr
, body
, save_break
;
4746 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4747 location_t switch_cond_loc
;
4748 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4749 c_parser_consume_token (parser
);
4750 block
= c_begin_compound_stmt (flag_isoc99
);
4751 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4753 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4754 expr
= c_parser_expression (parser
).value
;
4755 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4759 switch_cond_loc
= UNKNOWN_LOCATION
;
4760 expr
= error_mark_node
;
4762 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4763 save_break
= c_break_label
;
4764 c_break_label
= NULL_TREE
;
4765 body
= c_parser_c99_block_statement (parser
);
4766 c_finish_case (body
);
4769 location_t here
= c_parser_peek_token (parser
)->location
;
4770 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4771 SET_EXPR_LOCATION (t
, here
);
4774 c_break_label
= save_break
;
4775 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4778 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4781 while (expression) statement
4785 c_parser_while_statement (c_parser
*parser
)
4787 tree block
, cond
, body
, save_break
, save_cont
;
4789 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4790 c_parser_consume_token (parser
);
4791 block
= c_begin_compound_stmt (flag_isoc99
);
4792 loc
= c_parser_peek_token (parser
)->location
;
4793 cond
= c_parser_paren_condition (parser
);
4794 save_break
= c_break_label
;
4795 c_break_label
= NULL_TREE
;
4796 save_cont
= c_cont_label
;
4797 c_cont_label
= NULL_TREE
;
4798 body
= c_parser_c99_block_statement (parser
);
4799 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4800 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4801 c_break_label
= save_break
;
4802 c_cont_label
= save_cont
;
4805 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4808 do statement while ( expression ) ;
4812 c_parser_do_statement (c_parser
*parser
)
4814 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4816 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4817 c_parser_consume_token (parser
);
4818 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4819 warning_at (c_parser_peek_token (parser
)->location
,
4821 "suggest braces around empty body in %<do%> statement");
4822 block
= c_begin_compound_stmt (flag_isoc99
);
4823 loc
= c_parser_peek_token (parser
)->location
;
4824 save_break
= c_break_label
;
4825 c_break_label
= NULL_TREE
;
4826 save_cont
= c_cont_label
;
4827 c_cont_label
= NULL_TREE
;
4828 body
= c_parser_c99_block_statement (parser
);
4829 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4830 new_break
= c_break_label
;
4831 c_break_label
= save_break
;
4832 new_cont
= c_cont_label
;
4833 c_cont_label
= save_cont
;
4834 cond
= c_parser_paren_condition (parser
);
4835 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4836 c_parser_skip_to_end_of_block_or_statement (parser
);
4837 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4838 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4841 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4844 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4845 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4847 The form with a declaration is new in C99.
4849 ??? In accordance with the old parser, the declaration may be a
4850 nested function, which is then rejected in check_for_loop_decls,
4851 but does it make any sense for this to be included in the grammar?
4852 Note in particular that the nested function does not include a
4853 trailing ';', whereas the "declaration" production includes one.
4854 Also, can we reject bad declarations earlier and cheaper than
4855 check_for_loop_decls?
4857 In Objective-C, there are two additional variants:
4860 for ( expression in expresssion ) statement
4861 for ( declaration in expression ) statement
4863 This is inconsistent with C, because the second variant is allowed
4864 even if c99 is not enabled.
4866 The rest of the comment documents these Objective-C foreach-statement.
4868 Here is the canonical example of the first variant:
4869 for (object in array) { do something with object }
4870 we call the first expression ("object") the "object_expression" and
4871 the second expression ("array") the "collection_expression".
4872 object_expression must be an lvalue of type "id" (a generic Objective-C
4873 object) because the loop works by assigning to object_expression the
4874 various objects from the collection_expression. collection_expression
4875 must evaluate to something of type "id" which responds to the method
4876 countByEnumeratingWithState:objects:count:.
4878 The canonical example of the second variant is:
4879 for (id object in array) { do something with object }
4880 which is completely equivalent to
4883 for (object in array) { do something with object }
4885 Note that initizializing 'object' in some way (eg, "for ((object =
4886 xxx) in array) { do something with object }") is possibly
4887 technically valid, but completely pointless as 'object' will be
4888 assigned to something else as soon as the loop starts. We should
4889 most likely reject it (TODO).
4891 The beginning of the Objective-C foreach-statement looks exactly
4892 like the beginning of the for-statement, and we can tell it is a
4893 foreach-statement only because the initial declaration or
4894 expression is terminated by 'in' instead of ';'.
4898 c_parser_for_statement (c_parser
*parser
)
4900 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4901 /* The following are only used when parsing an ObjC foreach statement. */
4902 tree object_expression
;
4903 /* Silence the bogus uninitialized warning. */
4904 tree collection_expression
= NULL
;
4905 location_t loc
= c_parser_peek_token (parser
)->location
;
4906 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4907 bool is_foreach_statement
= false;
4908 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4909 c_parser_consume_token (parser
);
4910 /* Open a compound statement in Objective-C as well, just in case this is
4911 as foreach expression. */
4912 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4913 cond
= error_mark_node
;
4914 incr
= error_mark_node
;
4915 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4917 /* Parse the initialization declaration or expression. */
4918 object_expression
= error_mark_node
;
4919 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4920 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4922 parser
->objc_could_be_foreach_context
= false;
4923 c_parser_consume_token (parser
);
4924 c_finish_expr_stmt (loc
, NULL_TREE
);
4926 else if (c_parser_next_tokens_start_declaration (parser
))
4928 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4929 &object_expression
);
4930 parser
->objc_could_be_foreach_context
= false;
4932 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4934 c_parser_consume_token (parser
);
4935 is_foreach_statement
= true;
4936 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4937 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4940 check_for_loop_decls (for_loc
, flag_isoc99
);
4942 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4944 /* __extension__ can start a declaration, but is also an
4945 unary operator that can start an expression. Consume all
4946 but the last of a possible series of __extension__ to
4948 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4949 && (c_parser_peek_2nd_token (parser
)->keyword
4951 c_parser_consume_token (parser
);
4952 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4955 ext
= disable_extension_diagnostics ();
4956 c_parser_consume_token (parser
);
4957 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4958 true, &object_expression
);
4959 parser
->objc_could_be_foreach_context
= false;
4961 restore_extension_diagnostics (ext
);
4962 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4964 c_parser_consume_token (parser
);
4965 is_foreach_statement
= true;
4966 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4967 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4970 check_for_loop_decls (for_loc
, flag_isoc99
);
4979 tree init_expression
;
4980 init_expression
= c_parser_expression (parser
).value
;
4981 parser
->objc_could_be_foreach_context
= false;
4982 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4984 c_parser_consume_token (parser
);
4985 is_foreach_statement
= true;
4986 if (! lvalue_p (init_expression
))
4987 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
4988 object_expression
= c_fully_fold (init_expression
, false, NULL
);
4992 c_finish_expr_stmt (loc
, init_expression
);
4993 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4997 /* Parse the loop condition. In the case of a foreach
4998 statement, there is no loop condition. */
4999 gcc_assert (!parser
->objc_could_be_foreach_context
);
5000 if (!is_foreach_statement
)
5002 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5004 c_parser_consume_token (parser
);
5009 cond
= c_parser_condition (parser
);
5010 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5013 /* Parse the increment expression (the third expression in a
5014 for-statement). In the case of a foreach-statement, this is
5015 the expression that follows the 'in'. */
5016 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5018 if (is_foreach_statement
)
5020 c_parser_error (parser
, "missing collection in fast enumeration");
5021 collection_expression
= error_mark_node
;
5024 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5028 if (is_foreach_statement
)
5029 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5032 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5034 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5036 save_break
= c_break_label
;
5037 c_break_label
= NULL_TREE
;
5038 save_cont
= c_cont_label
;
5039 c_cont_label
= NULL_TREE
;
5040 body
= c_parser_c99_block_statement (parser
);
5041 if (is_foreach_statement
)
5042 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5044 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5045 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5046 c_break_label
= save_break
;
5047 c_cont_label
= save_cont
;
5050 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5051 statement with inputs, outputs, clobbers, and volatile tag
5055 asm type-qualifier[opt] ( asm-argument ) ;
5056 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5060 asm-string-literal : asm-operands[opt]
5061 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5062 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5065 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5068 Qualifiers other than volatile are accepted in the syntax but
5072 c_parser_asm_statement (c_parser
*parser
)
5074 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5075 bool simple
, is_goto
;
5076 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5077 int section
, nsections
;
5079 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5080 c_parser_consume_token (parser
);
5081 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5083 quals
= c_parser_peek_token (parser
)->value
;
5084 c_parser_consume_token (parser
);
5086 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5087 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5089 warning_at (c_parser_peek_token (parser
)->location
,
5091 "%E qualifier ignored on asm",
5092 c_parser_peek_token (parser
)->value
);
5094 c_parser_consume_token (parser
);
5100 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5102 c_parser_consume_token (parser
);
5106 /* ??? Follow the C++ parser rather than using the
5107 lex_untranslated_string kludge. */
5108 parser
->lex_untranslated_string
= true;
5111 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5114 str
= c_parser_asm_string_literal (parser
);
5115 if (str
== NULL_TREE
)
5116 goto error_close_paren
;
5119 outputs
= NULL_TREE
;
5121 clobbers
= NULL_TREE
;
5124 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5127 /* Parse each colon-delimited section of operands. */
5128 nsections
= 3 + is_goto
;
5129 for (section
= 0; section
< nsections
; ++section
)
5131 if (!c_parser_require (parser
, CPP_COLON
,
5134 : "expected %<:%> or %<)%>"))
5135 goto error_close_paren
;
5137 /* Once past any colon, we're no longer a simple asm. */
5140 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5141 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5146 /* For asm goto, we don't allow output operands, but reserve
5147 the slot for a future extension that does allow them. */
5149 outputs
= c_parser_asm_operands (parser
, false);
5152 inputs
= c_parser_asm_operands (parser
, true);
5155 clobbers
= c_parser_asm_clobbers (parser
);
5158 labels
= c_parser_asm_goto_operands (parser
);
5164 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5169 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5171 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5175 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5176 c_parser_skip_to_end_of_block_or_statement (parser
);
5178 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5179 clobbers
, labels
, simple
));
5182 parser
->lex_untranslated_string
= false;
5186 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5190 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5191 not outputs), apply the default conversion of functions and arrays
5196 asm-operands , asm-operand
5199 asm-string-literal ( expression )
5200 [ identifier ] asm-string-literal ( expression )
5204 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
5206 tree list
= NULL_TREE
;
5212 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5214 c_parser_consume_token (parser
);
5215 if (c_parser_next_token_is (parser
, CPP_NAME
))
5217 tree id
= c_parser_peek_token (parser
)->value
;
5218 c_parser_consume_token (parser
);
5219 name
= build_string (IDENTIFIER_LENGTH (id
),
5220 IDENTIFIER_POINTER (id
));
5224 c_parser_error (parser
, "expected identifier");
5225 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5228 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5233 str
= c_parser_asm_string_literal (parser
);
5234 if (str
== NULL_TREE
)
5236 parser
->lex_untranslated_string
= false;
5237 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5239 parser
->lex_untranslated_string
= true;
5242 loc
= c_parser_peek_token (parser
)->location
;
5243 expr
= c_parser_expression (parser
);
5244 mark_exp_read (expr
.value
);
5246 expr
= default_function_array_conversion (loc
, expr
);
5247 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5248 parser
->lex_untranslated_string
= true;
5249 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5251 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5254 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5256 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5257 c_parser_consume_token (parser
);
5264 /* Parse asm clobbers, a GNU extension.
5268 asm-clobbers , asm-string-literal
5272 c_parser_asm_clobbers (c_parser
*parser
)
5274 tree list
= NULL_TREE
;
5277 tree str
= c_parser_asm_string_literal (parser
);
5279 list
= tree_cons (NULL_TREE
, str
, list
);
5282 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5283 c_parser_consume_token (parser
);
5290 /* Parse asm goto labels, a GNU extension.
5294 asm-goto-operands , identifier
5298 c_parser_asm_goto_operands (c_parser
*parser
)
5300 tree list
= NULL_TREE
;
5305 if (c_parser_next_token_is (parser
, CPP_NAME
))
5307 c_token
*tok
= c_parser_peek_token (parser
);
5309 label
= lookup_label_for_goto (tok
->location
, name
);
5310 c_parser_consume_token (parser
);
5311 TREE_USED (label
) = 1;
5315 c_parser_error (parser
, "expected identifier");
5319 name
= build_string (IDENTIFIER_LENGTH (name
),
5320 IDENTIFIER_POINTER (name
));
5321 list
= tree_cons (name
, label
, list
);
5322 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5323 c_parser_consume_token (parser
);
5325 return nreverse (list
);
5329 /* Parse an expression other than a compound expression; that is, an
5330 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5331 NULL then it is an Objective-C message expression which is the
5332 primary-expression starting the expression as an initializer.
5334 assignment-expression:
5335 conditional-expression
5336 unary-expression assignment-operator assignment-expression
5338 assignment-operator: one of
5339 = *= /= %= += -= <<= >>= &= ^= |=
5341 In GNU C we accept any conditional expression on the LHS and
5342 diagnose the invalid lvalue rather than producing a syntax
5345 static struct c_expr
5346 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5348 struct c_expr lhs
, rhs
, ret
;
5349 enum tree_code code
;
5350 location_t op_location
, exp_location
;
5351 gcc_assert (!after
|| c_dialect_objc ());
5352 lhs
= c_parser_conditional_expression (parser
, after
);
5353 op_location
= c_parser_peek_token (parser
)->location
;
5354 switch (c_parser_peek_token (parser
)->type
)
5363 code
= TRUNC_DIV_EXPR
;
5366 code
= TRUNC_MOD_EXPR
;
5381 code
= BIT_AND_EXPR
;
5384 code
= BIT_XOR_EXPR
;
5387 code
= BIT_IOR_EXPR
;
5392 c_parser_consume_token (parser
);
5393 exp_location
= c_parser_peek_token (parser
)->location
;
5394 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5395 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5396 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5397 code
, exp_location
, rhs
.value
,
5399 if (code
== NOP_EXPR
)
5400 ret
.original_code
= MODIFY_EXPR
;
5403 TREE_NO_WARNING (ret
.value
) = 1;
5404 ret
.original_code
= ERROR_MARK
;
5406 ret
.original_type
= NULL
;
5410 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5411 is not NULL then it is an Objective-C message expression which is
5412 the primary-expression starting the expression as an initializer.
5414 conditional-expression:
5415 logical-OR-expression
5416 logical-OR-expression ? expression : conditional-expression
5420 conditional-expression:
5421 logical-OR-expression ? : conditional-expression
5424 static struct c_expr
5425 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5427 struct c_expr cond
, exp1
, exp2
, ret
;
5428 location_t cond_loc
, colon_loc
, middle_loc
;
5430 gcc_assert (!after
|| c_dialect_objc ());
5432 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5434 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5436 cond_loc
= c_parser_peek_token (parser
)->location
;
5437 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5438 c_parser_consume_token (parser
);
5439 if (c_parser_next_token_is (parser
, CPP_COLON
))
5441 tree eptype
= NULL_TREE
;
5443 middle_loc
= c_parser_peek_token (parser
)->location
;
5444 pedwarn (middle_loc
, OPT_pedantic
,
5445 "ISO C forbids omitting the middle term of a ?: expression");
5446 warn_for_omitted_condop (middle_loc
, cond
.value
);
5447 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5449 eptype
= TREE_TYPE (cond
.value
);
5450 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5452 /* Make sure first operand is calculated only once. */
5453 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5455 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5456 exp1
.original_type
= NULL
;
5457 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5458 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5463 = c_objc_common_truthvalue_conversion
5464 (cond_loc
, default_conversion (cond
.value
));
5465 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5466 exp1
= c_parser_expression_conv (parser
);
5467 mark_exp_read (exp1
.value
);
5468 c_inhibit_evaluation_warnings
+=
5469 ((cond
.value
== truthvalue_true_node
)
5470 - (cond
.value
== truthvalue_false_node
));
5473 colon_loc
= c_parser_peek_token (parser
)->location
;
5474 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5476 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5477 ret
.value
= error_mark_node
;
5478 ret
.original_code
= ERROR_MARK
;
5479 ret
.original_type
= NULL
;
5483 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5484 exp2
= c_parser_conditional_expression (parser
, NULL
);
5485 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5487 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5488 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5489 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5490 exp1
.value
, exp1
.original_type
,
5491 exp2
.value
, exp2
.original_type
);
5492 ret
.original_code
= ERROR_MARK
;
5493 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5494 ret
.original_type
= NULL
;
5499 /* If both sides are enum type, the default conversion will have
5500 made the type of the result be an integer type. We want to
5501 remember the enum types we started with. */
5502 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5503 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5504 ret
.original_type
= ((t1
!= error_mark_node
5505 && t2
!= error_mark_node
5506 && (TYPE_MAIN_VARIANT (t1
)
5507 == TYPE_MAIN_VARIANT (t2
)))
5514 /* Parse a binary expression; that is, a logical-OR-expression (C90
5515 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5516 an Objective-C message expression which is the primary-expression
5517 starting the expression as an initializer. PREC is the starting
5518 precedence, usually PREC_NONE.
5520 multiplicative-expression:
5522 multiplicative-expression * cast-expression
5523 multiplicative-expression / cast-expression
5524 multiplicative-expression % cast-expression
5526 additive-expression:
5527 multiplicative-expression
5528 additive-expression + multiplicative-expression
5529 additive-expression - multiplicative-expression
5533 shift-expression << additive-expression
5534 shift-expression >> additive-expression
5536 relational-expression:
5538 relational-expression < shift-expression
5539 relational-expression > shift-expression
5540 relational-expression <= shift-expression
5541 relational-expression >= shift-expression
5543 equality-expression:
5544 relational-expression
5545 equality-expression == relational-expression
5546 equality-expression != relational-expression
5550 AND-expression & equality-expression
5552 exclusive-OR-expression:
5554 exclusive-OR-expression ^ AND-expression
5556 inclusive-OR-expression:
5557 exclusive-OR-expression
5558 inclusive-OR-expression | exclusive-OR-expression
5560 logical-AND-expression:
5561 inclusive-OR-expression
5562 logical-AND-expression && inclusive-OR-expression
5564 logical-OR-expression:
5565 logical-AND-expression
5566 logical-OR-expression || logical-AND-expression
5569 static struct c_expr
5570 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5571 enum c_parser_prec prec
)
5573 /* A binary expression is parsed using operator-precedence parsing,
5574 with the operands being cast expressions. All the binary
5575 operators are left-associative. Thus a binary expression is of
5578 E0 op1 E1 op2 E2 ...
5580 which we represent on a stack. On the stack, the precedence
5581 levels are strictly increasing. When a new operator is
5582 encountered of higher precedence than that at the top of the
5583 stack, it is pushed; its LHS is the top expression, and its RHS
5584 is everything parsed until it is popped. When a new operator is
5585 encountered with precedence less than or equal to that at the top
5586 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5587 by the result of the operation until the operator at the top of
5588 the stack has lower precedence than the new operator or there is
5589 only one element on the stack; then the top expression is the LHS
5590 of the new operator. In the case of logical AND and OR
5591 expressions, we also need to adjust c_inhibit_evaluation_warnings
5592 as appropriate when the operators are pushed and popped. */
5595 /* The expression at this stack level. */
5597 /* The precedence of the operator on its left, PREC_NONE at the
5598 bottom of the stack. */
5599 enum c_parser_prec prec
;
5600 /* The operation on its left. */
5602 /* The source location of this operation. */
5606 /* Location of the binary operator. */
5607 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5610 switch (stack[sp].op) \
5612 case TRUTH_ANDIF_EXPR: \
5613 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5614 == truthvalue_false_node); \
5616 case TRUTH_ORIF_EXPR: \
5617 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5618 == truthvalue_true_node); \
5623 stack[sp - 1].expr \
5624 = default_function_array_read_conversion (stack[sp - 1].loc, \
5625 stack[sp - 1].expr); \
5627 = default_function_array_read_conversion (stack[sp].loc, \
5629 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5631 stack[sp - 1].expr, \
5635 gcc_assert (!after
|| c_dialect_objc ());
5636 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5637 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5638 stack
[0].prec
= prec
;
5642 enum c_parser_prec oprec
;
5643 enum tree_code ocode
;
5646 switch (c_parser_peek_token (parser
)->type
)
5654 ocode
= TRUNC_DIV_EXPR
;
5658 ocode
= TRUNC_MOD_EXPR
;
5670 ocode
= LSHIFT_EXPR
;
5674 ocode
= RSHIFT_EXPR
;
5688 case CPP_GREATER_EQ
:
5701 oprec
= PREC_BITAND
;
5702 ocode
= BIT_AND_EXPR
;
5705 oprec
= PREC_BITXOR
;
5706 ocode
= BIT_XOR_EXPR
;
5710 ocode
= BIT_IOR_EXPR
;
5713 oprec
= PREC_LOGAND
;
5714 ocode
= TRUTH_ANDIF_EXPR
;
5718 ocode
= TRUTH_ORIF_EXPR
;
5721 /* Not a binary operator, so end of the binary
5725 binary_loc
= c_parser_peek_token (parser
)->location
;
5726 while (oprec
<= stack
[sp
].prec
)
5732 c_parser_consume_token (parser
);
5735 case TRUTH_ANDIF_EXPR
:
5737 = default_function_array_read_conversion (stack
[sp
].loc
,
5739 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5740 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5741 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5742 == truthvalue_false_node
);
5744 case TRUTH_ORIF_EXPR
:
5746 = default_function_array_read_conversion (stack
[sp
].loc
,
5748 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5749 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5750 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5751 == truthvalue_true_node
);
5757 stack
[sp
].loc
= binary_loc
;
5758 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5759 stack
[sp
].prec
= oprec
;
5760 stack
[sp
].op
= ocode
;
5761 stack
[sp
].loc
= binary_loc
;
5766 return stack
[0].expr
;
5770 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5771 NULL then it is an Objective-C message expression which is the
5772 primary-expression starting the expression as an initializer.
5776 ( type-name ) unary-expression
5779 static struct c_expr
5780 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5782 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5783 gcc_assert (!after
|| c_dialect_objc ());
5785 return c_parser_postfix_expression_after_primary (parser
,
5787 /* If the expression begins with a parenthesized type name, it may
5788 be either a cast or a compound literal; we need to see whether
5789 the next character is '{' to tell the difference. If not, it is
5790 an unary expression. Full detection of unknown typenames here
5791 would require a 3-token lookahead. */
5792 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5793 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5795 struct c_type_name
*type_name
;
5798 c_parser_consume_token (parser
);
5799 type_name
= c_parser_type_name (parser
);
5800 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5801 if (type_name
== NULL
)
5803 ret
.value
= error_mark_node
;
5804 ret
.original_code
= ERROR_MARK
;
5805 ret
.original_type
= NULL
;
5809 /* Save casted types in the function's used types hash table. */
5810 used_types_insert (type_name
->specs
->type
);
5812 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5813 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5816 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5817 expr
= c_parser_cast_expression (parser
, NULL
);
5818 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5820 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5821 ret
.original_code
= ERROR_MARK
;
5822 ret
.original_type
= NULL
;
5826 return c_parser_unary_expression (parser
);
5829 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5835 unary-operator cast-expression
5836 sizeof unary-expression
5837 sizeof ( type-name )
5839 unary-operator: one of
5845 __alignof__ unary-expression
5846 __alignof__ ( type-name )
5849 (C11 permits _Alignof with type names only.)
5851 unary-operator: one of
5852 __extension__ __real__ __imag__
5854 Transactional Memory:
5857 transaction-expression
5859 In addition, the GNU syntax treats ++ and -- as unary operators, so
5860 they may be applied to cast expressions with errors for non-lvalues
5863 static struct c_expr
5864 c_parser_unary_expression (c_parser
*parser
)
5867 struct c_expr ret
, op
;
5868 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5870 ret
.original_code
= ERROR_MARK
;
5871 ret
.original_type
= NULL
;
5872 switch (c_parser_peek_token (parser
)->type
)
5875 c_parser_consume_token (parser
);
5876 exp_loc
= c_parser_peek_token (parser
)->location
;
5877 op
= c_parser_cast_expression (parser
, NULL
);
5878 op
= default_function_array_read_conversion (exp_loc
, op
);
5879 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5880 case CPP_MINUS_MINUS
:
5881 c_parser_consume_token (parser
);
5882 exp_loc
= c_parser_peek_token (parser
)->location
;
5883 op
= c_parser_cast_expression (parser
, NULL
);
5884 op
= default_function_array_read_conversion (exp_loc
, op
);
5885 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5887 c_parser_consume_token (parser
);
5888 op
= c_parser_cast_expression (parser
, NULL
);
5889 mark_exp_read (op
.value
);
5890 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5892 c_parser_consume_token (parser
);
5893 exp_loc
= c_parser_peek_token (parser
)->location
;
5894 op
= c_parser_cast_expression (parser
, NULL
);
5895 op
= default_function_array_read_conversion (exp_loc
, op
);
5896 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5899 if (!c_dialect_objc () && !in_system_header
)
5902 "traditional C rejects the unary plus operator");
5903 c_parser_consume_token (parser
);
5904 exp_loc
= c_parser_peek_token (parser
)->location
;
5905 op
= c_parser_cast_expression (parser
, NULL
);
5906 op
= default_function_array_read_conversion (exp_loc
, op
);
5907 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5909 c_parser_consume_token (parser
);
5910 exp_loc
= c_parser_peek_token (parser
)->location
;
5911 op
= c_parser_cast_expression (parser
, NULL
);
5912 op
= default_function_array_read_conversion (exp_loc
, op
);
5913 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5915 c_parser_consume_token (parser
);
5916 exp_loc
= c_parser_peek_token (parser
)->location
;
5917 op
= c_parser_cast_expression (parser
, NULL
);
5918 op
= default_function_array_read_conversion (exp_loc
, op
);
5919 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5921 c_parser_consume_token (parser
);
5922 exp_loc
= c_parser_peek_token (parser
)->location
;
5923 op
= c_parser_cast_expression (parser
, NULL
);
5924 op
= default_function_array_read_conversion (exp_loc
, op
);
5925 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5927 /* Refer to the address of a label as a pointer. */
5928 c_parser_consume_token (parser
);
5929 if (c_parser_next_token_is (parser
, CPP_NAME
))
5931 ret
.value
= finish_label_address_expr
5932 (c_parser_peek_token (parser
)->value
, op_loc
);
5933 c_parser_consume_token (parser
);
5937 c_parser_error (parser
, "expected identifier");
5938 ret
.value
= error_mark_node
;
5942 switch (c_parser_peek_token (parser
)->keyword
)
5945 return c_parser_sizeof_expression (parser
);
5947 return c_parser_alignof_expression (parser
);
5949 c_parser_consume_token (parser
);
5950 ext
= disable_extension_diagnostics ();
5951 ret
= c_parser_cast_expression (parser
, NULL
);
5952 restore_extension_diagnostics (ext
);
5955 c_parser_consume_token (parser
);
5956 exp_loc
= c_parser_peek_token (parser
)->location
;
5957 op
= c_parser_cast_expression (parser
, NULL
);
5958 op
= default_function_array_conversion (exp_loc
, op
);
5959 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5961 c_parser_consume_token (parser
);
5962 exp_loc
= c_parser_peek_token (parser
)->location
;
5963 op
= c_parser_cast_expression (parser
, NULL
);
5964 op
= default_function_array_conversion (exp_loc
, op
);
5965 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5966 case RID_TRANSACTION_ATOMIC
:
5967 case RID_TRANSACTION_RELAXED
:
5968 return c_parser_transaction_expression (parser
,
5969 c_parser_peek_token (parser
)->keyword
);
5971 return c_parser_postfix_expression (parser
);
5974 return c_parser_postfix_expression (parser
);
5978 /* Parse a sizeof expression. */
5980 static struct c_expr
5981 c_parser_sizeof_expression (c_parser
*parser
)
5984 location_t expr_loc
;
5985 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5986 c_parser_consume_token (parser
);
5987 c_inhibit_evaluation_warnings
++;
5989 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5990 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5992 /* Either sizeof ( type-name ) or sizeof unary-expression
5993 starting with a compound literal. */
5994 struct c_type_name
*type_name
;
5995 c_parser_consume_token (parser
);
5996 expr_loc
= c_parser_peek_token (parser
)->location
;
5997 type_name
= c_parser_type_name (parser
);
5998 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5999 if (type_name
== NULL
)
6002 c_inhibit_evaluation_warnings
--;
6004 ret
.value
= error_mark_node
;
6005 ret
.original_code
= ERROR_MARK
;
6006 ret
.original_type
= NULL
;
6009 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6011 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6016 /* sizeof ( type-name ). */
6017 c_inhibit_evaluation_warnings
--;
6019 return c_expr_sizeof_type (expr_loc
, type_name
);
6023 expr_loc
= c_parser_peek_token (parser
)->location
;
6024 expr
= c_parser_unary_expression (parser
);
6026 c_inhibit_evaluation_warnings
--;
6028 mark_exp_read (expr
.value
);
6029 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6030 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6031 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6032 return c_expr_sizeof_expr (expr_loc
, expr
);
6036 /* Parse an alignof expression. */
6038 static struct c_expr
6039 c_parser_alignof_expression (c_parser
*parser
)
6042 location_t loc
= c_parser_peek_token (parser
)->location
;
6043 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6044 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6045 /* A diagnostic is not required for the use of this identifier in
6046 the implementation namespace; only diagnose it for the C11
6047 spelling because of existing code using the other spellings. */
6049 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6052 pedwarn (loc
, OPT_pedantic
, "ISO C99 does not support %qE",
6055 pedwarn (loc
, OPT_pedantic
, "ISO C90 does not support %qE",
6058 c_parser_consume_token (parser
);
6059 c_inhibit_evaluation_warnings
++;
6061 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6062 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6064 /* Either __alignof__ ( type-name ) or __alignof__
6065 unary-expression starting with a compound literal. */
6067 struct c_type_name
*type_name
;
6069 c_parser_consume_token (parser
);
6070 loc
= c_parser_peek_token (parser
)->location
;
6071 type_name
= c_parser_type_name (parser
);
6072 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6073 if (type_name
== NULL
)
6076 c_inhibit_evaluation_warnings
--;
6078 ret
.value
= error_mark_node
;
6079 ret
.original_code
= ERROR_MARK
;
6080 ret
.original_type
= NULL
;
6083 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6085 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6090 /* alignof ( type-name ). */
6091 c_inhibit_evaluation_warnings
--;
6093 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6094 ret
.original_code
= ERROR_MARK
;
6095 ret
.original_type
= NULL
;
6101 expr
= c_parser_unary_expression (parser
);
6103 mark_exp_read (expr
.value
);
6104 c_inhibit_evaluation_warnings
--;
6106 pedwarn (loc
, OPT_pedantic
, "ISO C does not allow %<%E (expression)%>",
6108 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6109 ret
.original_code
= ERROR_MARK
;
6110 ret
.original_type
= NULL
;
6115 /* Helper function to read arguments of builtins which are interfaces
6116 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6117 others. The name of the builtin is passed using BNAME parameter.
6118 Function returns true if there were no errors while parsing and
6119 stores the arguments in CEXPR_LIST. */
6121 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6122 VEC(c_expr_t
,gc
) **ret_cexpr_list
)
6124 location_t loc
= c_parser_peek_token (parser
)->location
;
6125 VEC (c_expr_t
,gc
) *cexpr_list
;
6128 *ret_cexpr_list
= NULL
;
6129 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6131 error_at (loc
, "cannot take address of %qs", bname
);
6135 c_parser_consume_token (parser
);
6137 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6139 c_parser_consume_token (parser
);
6143 expr
= c_parser_expr_no_commas (parser
, NULL
);
6144 cexpr_list
= VEC_alloc (c_expr_t
, gc
, 1);
6145 C_EXPR_APPEND (cexpr_list
, expr
);
6146 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6148 c_parser_consume_token (parser
);
6149 expr
= c_parser_expr_no_commas (parser
, NULL
);
6150 C_EXPR_APPEND (cexpr_list
, expr
);
6153 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6156 *ret_cexpr_list
= cexpr_list
;
6161 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6165 postfix-expression [ expression ]
6166 postfix-expression ( argument-expression-list[opt] )
6167 postfix-expression . identifier
6168 postfix-expression -> identifier
6169 postfix-expression ++
6170 postfix-expression --
6171 ( type-name ) { initializer-list }
6172 ( type-name ) { initializer-list , }
6174 argument-expression-list:
6176 argument-expression-list , argument-expression
6188 (treated as a keyword in GNU C)
6191 ( compound-statement )
6192 __builtin_va_arg ( assignment-expression , type-name )
6193 __builtin_offsetof ( type-name , offsetof-member-designator )
6194 __builtin_choose_expr ( assignment-expression ,
6195 assignment-expression ,
6196 assignment-expression )
6197 __builtin_types_compatible_p ( type-name , type-name )
6198 __builtin_complex ( assignment-expression , assignment-expression )
6199 __builtin_shuffle ( assignment-expression , assignment-expression )
6200 __builtin_shuffle ( assignment-expression ,
6201 assignment-expression ,
6202 assignment-expression, )
6204 offsetof-member-designator:
6206 offsetof-member-designator . identifier
6207 offsetof-member-designator [ expression ]
6212 [ objc-receiver objc-message-args ]
6213 @selector ( objc-selector-arg )
6214 @protocol ( identifier )
6215 @encode ( type-name )
6217 Classname . identifier
6220 static struct c_expr
6221 c_parser_postfix_expression (c_parser
*parser
)
6223 struct c_expr expr
, e1
;
6224 struct c_type_name
*t1
, *t2
;
6225 location_t loc
= c_parser_peek_token (parser
)->location
;;
6226 expr
.original_code
= ERROR_MARK
;
6227 expr
.original_type
= NULL
;
6228 switch (c_parser_peek_token (parser
)->type
)
6231 expr
.value
= c_parser_peek_token (parser
)->value
;
6232 loc
= c_parser_peek_token (parser
)->location
;
6233 c_parser_consume_token (parser
);
6234 if (TREE_CODE (expr
.value
) == FIXED_CST
6235 && !targetm
.fixed_point_supported_p ())
6237 error_at (loc
, "fixed-point types not supported for this target");
6238 expr
.value
= error_mark_node
;
6245 expr
.value
= c_parser_peek_token (parser
)->value
;
6246 c_parser_consume_token (parser
);
6252 case CPP_UTF8STRING
:
6253 expr
.value
= c_parser_peek_token (parser
)->value
;
6254 expr
.original_code
= STRING_CST
;
6255 c_parser_consume_token (parser
);
6257 case CPP_OBJC_STRING
:
6258 gcc_assert (c_dialect_objc ());
6260 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6261 c_parser_consume_token (parser
);
6264 switch (c_parser_peek_token (parser
)->id_kind
)
6268 tree id
= c_parser_peek_token (parser
)->value
;
6269 c_parser_consume_token (parser
);
6270 expr
.value
= build_external_ref (loc
, id
,
6271 (c_parser_peek_token (parser
)->type
6273 &expr
.original_type
);
6276 case C_ID_CLASSNAME
:
6278 /* Here we parse the Objective-C 2.0 Class.name dot
6280 tree class_name
= c_parser_peek_token (parser
)->value
;
6282 c_parser_consume_token (parser
);
6283 gcc_assert (c_dialect_objc ());
6284 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6286 expr
.value
= error_mark_node
;
6289 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6291 c_parser_error (parser
, "expected identifier");
6292 expr
.value
= error_mark_node
;
6295 component
= c_parser_peek_token (parser
)->value
;
6296 c_parser_consume_token (parser
);
6297 expr
.value
= objc_build_class_component_ref (class_name
,
6302 c_parser_error (parser
, "expected expression");
6303 expr
.value
= error_mark_node
;
6307 case CPP_OPEN_PAREN
:
6308 /* A parenthesized expression, statement expression or compound
6310 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6312 /* A statement expression. */
6314 location_t brace_loc
;
6315 c_parser_consume_token (parser
);
6316 brace_loc
= c_parser_peek_token (parser
)->location
;
6317 c_parser_consume_token (parser
);
6318 if (!building_stmt_list_p ())
6320 error_at (loc
, "braced-group within expression allowed "
6321 "only inside a function");
6322 parser
->error
= true;
6323 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6324 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6325 expr
.value
= error_mark_node
;
6328 stmt
= c_begin_stmt_expr ();
6329 c_parser_compound_statement_nostart (parser
);
6330 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6332 pedwarn (loc
, OPT_pedantic
,
6333 "ISO C forbids braced-groups within expressions");
6334 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6335 mark_exp_read (expr
.value
);
6337 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6339 /* A compound literal. ??? Can we actually get here rather
6340 than going directly to
6341 c_parser_postfix_expression_after_paren_type from
6344 struct c_type_name
*type_name
;
6345 c_parser_consume_token (parser
);
6346 loc
= c_parser_peek_token (parser
)->location
;
6347 type_name
= c_parser_type_name (parser
);
6348 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6350 if (type_name
== NULL
)
6352 expr
.value
= error_mark_node
;
6355 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6361 /* A parenthesized expression. */
6362 c_parser_consume_token (parser
);
6363 expr
= c_parser_expression (parser
);
6364 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6365 TREE_NO_WARNING (expr
.value
) = 1;
6366 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6367 expr
.original_code
= ERROR_MARK
;
6368 /* Don't change EXPR.ORIGINAL_TYPE. */
6369 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6374 switch (c_parser_peek_token (parser
)->keyword
)
6376 case RID_FUNCTION_NAME
:
6377 case RID_PRETTY_FUNCTION_NAME
:
6378 case RID_C99_FUNCTION_NAME
:
6379 expr
.value
= fname_decl (loc
,
6380 c_parser_peek_token (parser
)->keyword
,
6381 c_parser_peek_token (parser
)->value
);
6382 c_parser_consume_token (parser
);
6385 c_parser_consume_token (parser
);
6386 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6388 expr
.value
= error_mark_node
;
6391 e1
= c_parser_expr_no_commas (parser
, NULL
);
6392 mark_exp_read (e1
.value
);
6393 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6394 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6396 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6397 expr
.value
= error_mark_node
;
6400 loc
= c_parser_peek_token (parser
)->location
;
6401 t1
= c_parser_type_name (parser
);
6402 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6406 expr
.value
= error_mark_node
;
6410 tree type_expr
= NULL_TREE
;
6411 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6412 groktypename (t1
, &type_expr
, NULL
));
6415 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6416 TREE_TYPE (expr
.value
), type_expr
,
6418 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6423 c_parser_consume_token (parser
);
6424 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6426 expr
.value
= error_mark_node
;
6429 t1
= c_parser_type_name (parser
);
6431 parser
->error
= true;
6432 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6433 gcc_assert (parser
->error
);
6436 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6437 expr
.value
= error_mark_node
;
6442 tree type
= groktypename (t1
, NULL
, NULL
);
6444 if (type
== error_mark_node
)
6445 offsetof_ref
= error_mark_node
;
6448 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6449 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6451 /* Parse the second argument to __builtin_offsetof. We
6452 must have one identifier, and beyond that we want to
6453 accept sub structure and sub array references. */
6454 if (c_parser_next_token_is (parser
, CPP_NAME
))
6456 offsetof_ref
= build_component_ref
6457 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6458 c_parser_consume_token (parser
);
6459 while (c_parser_next_token_is (parser
, CPP_DOT
)
6460 || c_parser_next_token_is (parser
,
6462 || c_parser_next_token_is (parser
,
6465 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6467 loc
= c_parser_peek_token (parser
)->location
;
6468 offsetof_ref
= build_array_ref (loc
,
6473 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6476 c_parser_consume_token (parser
);
6477 if (c_parser_next_token_is_not (parser
,
6480 c_parser_error (parser
, "expected identifier");
6483 offsetof_ref
= build_component_ref
6485 c_parser_peek_token (parser
)->value
);
6486 c_parser_consume_token (parser
);
6491 loc
= c_parser_peek_token (parser
)->location
;
6492 c_parser_consume_token (parser
);
6493 idx
= c_parser_expression (parser
).value
;
6494 idx
= c_fully_fold (idx
, false, NULL
);
6495 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6497 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6502 c_parser_error (parser
, "expected identifier");
6503 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6505 expr
.value
= fold_offsetof (offsetof_ref
);
6508 case RID_CHOOSE_EXPR
:
6510 VEC (c_expr_t
, gc
) *cexpr_list
;
6511 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6514 c_parser_consume_token (parser
);
6515 if (!c_parser_get_builtin_args (parser
,
6516 "__builtin_choose_expr",
6519 expr
.value
= error_mark_node
;
6523 if (VEC_length (c_expr_t
, cexpr_list
) != 3)
6525 error_at (loc
, "wrong number of arguments to "
6526 "%<__builtin_choose_expr%>");
6527 expr
.value
= error_mark_node
;
6531 e1_p
= VEC_index (c_expr_t
, cexpr_list
, 0);
6532 e2_p
= VEC_index (c_expr_t
, cexpr_list
, 1);
6533 e3_p
= VEC_index (c_expr_t
, cexpr_list
, 2);
6536 mark_exp_read (e2_p
->value
);
6537 mark_exp_read (e3_p
->value
);
6538 if (TREE_CODE (c
) != INTEGER_CST
6539 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6541 "first argument to %<__builtin_choose_expr%> not"
6543 constant_expression_warning (c
);
6544 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6547 case RID_TYPES_COMPATIBLE_P
:
6548 c_parser_consume_token (parser
);
6549 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6551 expr
.value
= error_mark_node
;
6554 t1
= c_parser_type_name (parser
);
6557 expr
.value
= error_mark_node
;
6560 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6562 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6563 expr
.value
= error_mark_node
;
6566 t2
= c_parser_type_name (parser
);
6569 expr
.value
= error_mark_node
;
6572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6576 e1
= groktypename (t1
, NULL
, NULL
);
6577 e2
= groktypename (t2
, NULL
, NULL
);
6578 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6580 expr
.value
= error_mark_node
;
6584 e1
= TYPE_MAIN_VARIANT (e1
);
6585 e2
= TYPE_MAIN_VARIANT (e2
);
6588 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6591 case RID_BUILTIN_COMPLEX
:
6593 VEC(c_expr_t
, gc
) *cexpr_list
;
6594 c_expr_t
*e1_p
, *e2_p
;
6596 c_parser_consume_token (parser
);
6597 if (!c_parser_get_builtin_args (parser
,
6598 "__builtin_complex",
6601 expr
.value
= error_mark_node
;
6605 if (VEC_length (c_expr_t
, cexpr_list
) != 2)
6607 error_at (loc
, "wrong number of arguments to "
6608 "%<__builtin_complex%>");
6609 expr
.value
= error_mark_node
;
6613 e1_p
= VEC_index (c_expr_t
, cexpr_list
, 0);
6614 e2_p
= VEC_index (c_expr_t
, cexpr_list
, 1);
6616 mark_exp_read (e1_p
->value
);
6617 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
6618 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
6619 TREE_OPERAND (e1_p
->value
, 0));
6620 mark_exp_read (e2_p
->value
);
6621 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
6622 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
6623 TREE_OPERAND (e2_p
->value
, 0));
6624 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6625 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6626 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
6627 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
6629 error_at (loc
, "%<__builtin_complex%> operand "
6630 "not of real binary floating-point type");
6631 expr
.value
= error_mark_node
;
6634 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
6635 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
6638 "%<__builtin_complex%> operands of different types");
6639 expr
.value
= error_mark_node
;
6643 pedwarn (loc
, OPT_pedantic
,
6644 "ISO C90 does not support complex types");
6645 expr
.value
= build2 (COMPLEX_EXPR
,
6648 (TREE_TYPE (e1_p
->value
))),
6649 e1_p
->value
, e2_p
->value
);
6652 case RID_BUILTIN_SHUFFLE
:
6654 VEC(c_expr_t
,gc
) *cexpr_list
;
6658 c_parser_consume_token (parser
);
6659 if (!c_parser_get_builtin_args (parser
,
6660 "__builtin_shuffle",
6663 expr
.value
= error_mark_node
;
6667 FOR_EACH_VEC_ELT (c_expr_t
, cexpr_list
, i
, p
)
6668 mark_exp_read (p
->value
);
6670 if (VEC_length (c_expr_t
, cexpr_list
) == 2)
6672 c_build_vec_perm_expr
6673 (loc
, VEC_index (c_expr_t
, cexpr_list
, 0)->value
,
6674 NULL_TREE
, VEC_index (c_expr_t
, cexpr_list
, 1)->value
);
6676 else if (VEC_length (c_expr_t
, cexpr_list
) == 3)
6678 c_build_vec_perm_expr
6679 (loc
, VEC_index (c_expr_t
, cexpr_list
, 0)->value
,
6680 VEC_index (c_expr_t
, cexpr_list
, 1)->value
,
6681 VEC_index (c_expr_t
, cexpr_list
, 2)->value
);
6684 error_at (loc
, "wrong number of arguments to "
6685 "%<__builtin_shuffle%>");
6686 expr
.value
= error_mark_node
;
6690 case RID_AT_SELECTOR
:
6691 gcc_assert (c_dialect_objc ());
6692 c_parser_consume_token (parser
);
6693 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6695 expr
.value
= error_mark_node
;
6699 tree sel
= c_parser_objc_selector_arg (parser
);
6700 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6702 expr
.value
= objc_build_selector_expr (loc
, sel
);
6705 case RID_AT_PROTOCOL
:
6706 gcc_assert (c_dialect_objc ());
6707 c_parser_consume_token (parser
);
6708 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6710 expr
.value
= error_mark_node
;
6713 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6715 c_parser_error (parser
, "expected identifier");
6716 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6717 expr
.value
= error_mark_node
;
6721 tree id
= c_parser_peek_token (parser
)->value
;
6722 c_parser_consume_token (parser
);
6723 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6725 expr
.value
= objc_build_protocol_expr (id
);
6729 /* Extension to support C-structures in the archiver. */
6730 gcc_assert (c_dialect_objc ());
6731 c_parser_consume_token (parser
);
6732 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6734 expr
.value
= error_mark_node
;
6737 t1
= c_parser_type_name (parser
);
6740 expr
.value
= error_mark_node
;
6741 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6744 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6747 tree type
= groktypename (t1
, NULL
, NULL
);
6748 expr
.value
= objc_build_encode_expr (type
);
6752 c_parser_error (parser
, "expected expression");
6753 expr
.value
= error_mark_node
;
6757 case CPP_OPEN_SQUARE
:
6758 if (c_dialect_objc ())
6760 tree receiver
, args
;
6761 c_parser_consume_token (parser
);
6762 receiver
= c_parser_objc_receiver (parser
);
6763 args
= c_parser_objc_message_args (parser
);
6764 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6766 expr
.value
= objc_build_message_expr (receiver
, args
);
6769 /* Else fall through to report error. */
6771 c_parser_error (parser
, "expected expression");
6772 expr
.value
= error_mark_node
;
6775 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6778 /* Parse a postfix expression after a parenthesized type name: the
6779 brace-enclosed initializer of a compound literal, possibly followed
6780 by some postfix operators. This is separate because it is not
6781 possible to tell until after the type name whether a cast
6782 expression has a cast or a compound literal, or whether the operand
6783 of sizeof is a parenthesized type name or starts with a compound
6784 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6785 location of the first token after the parentheses around the type
6788 static struct c_expr
6789 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6790 struct c_type_name
*type_name
,
6791 location_t type_loc
)
6797 location_t start_loc
;
6798 tree type_expr
= NULL_TREE
;
6799 bool type_expr_const
= true;
6800 check_compound_literal_type (type_loc
, type_name
);
6801 start_init (NULL_TREE
, NULL
, 0);
6802 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6803 start_loc
= c_parser_peek_token (parser
)->location
;
6804 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6806 error_at (type_loc
, "compound literal has variable size");
6807 type
= error_mark_node
;
6809 init
= c_parser_braced_init (parser
, type
, false);
6811 maybe_warn_string_init (type
, init
);
6813 if (type
!= error_mark_node
6814 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6815 && current_function_decl
)
6817 error ("compound literal qualified by address-space qualifier");
6818 type
= error_mark_node
;
6822 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
6823 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6824 ? CONSTRUCTOR_NON_CONST (init
.value
)
6825 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6826 non_const
|= !type_expr_const
;
6827 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6828 expr
.original_code
= ERROR_MARK
;
6829 expr
.original_type
= NULL
;
6832 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6834 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6835 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6839 gcc_assert (!non_const
);
6840 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6841 type_expr
, expr
.value
);
6844 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6847 /* Parse a postfix expression after the initial primary or compound
6848 literal; that is, parse a series of postfix operators.
6850 EXPR_LOC is the location of the primary expression. */
6852 static struct c_expr
6853 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6854 location_t expr_loc
,
6857 struct c_expr orig_expr
;
6859 VEC(tree
,gc
) *exprlist
;
6860 VEC(tree
,gc
) *origtypes
;
6863 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6864 switch (c_parser_peek_token (parser
)->type
)
6866 case CPP_OPEN_SQUARE
:
6867 /* Array reference. */
6868 c_parser_consume_token (parser
);
6869 idx
= c_parser_expression (parser
).value
;
6870 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6872 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6873 expr
.original_code
= ERROR_MARK
;
6874 expr
.original_type
= NULL
;
6876 case CPP_OPEN_PAREN
:
6877 /* Function call. */
6878 c_parser_consume_token (parser
);
6879 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6882 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
6883 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6886 mark_exp_read (expr
.value
);
6887 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6888 "(" after the FUNCNAME, which is what we have now. */
6889 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6891 expr
.original_code
= ERROR_MARK
;
6892 if (TREE_CODE (expr
.value
) == INTEGER_CST
6893 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6894 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6895 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6896 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6897 expr
.original_type
= NULL
;
6898 if (exprlist
!= NULL
)
6900 release_tree_vector (exprlist
);
6901 release_tree_vector (origtypes
);
6905 /* Structure element reference. */
6906 c_parser_consume_token (parser
);
6907 expr
= default_function_array_conversion (expr_loc
, expr
);
6908 if (c_parser_next_token_is (parser
, CPP_NAME
))
6909 ident
= c_parser_peek_token (parser
)->value
;
6912 c_parser_error (parser
, "expected identifier");
6913 expr
.value
= error_mark_node
;
6914 expr
.original_code
= ERROR_MARK
;
6915 expr
.original_type
= NULL
;
6918 c_parser_consume_token (parser
);
6919 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6920 expr
.original_code
= ERROR_MARK
;
6921 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6922 expr
.original_type
= NULL
;
6925 /* Remember the original type of a bitfield. */
6926 tree field
= TREE_OPERAND (expr
.value
, 1);
6927 if (TREE_CODE (field
) != FIELD_DECL
)
6928 expr
.original_type
= NULL
;
6930 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6934 /* Structure element reference. */
6935 c_parser_consume_token (parser
);
6936 expr
= default_function_array_conversion (expr_loc
, expr
);
6937 if (c_parser_next_token_is (parser
, CPP_NAME
))
6938 ident
= c_parser_peek_token (parser
)->value
;
6941 c_parser_error (parser
, "expected identifier");
6942 expr
.value
= error_mark_node
;
6943 expr
.original_code
= ERROR_MARK
;
6944 expr
.original_type
= NULL
;
6947 c_parser_consume_token (parser
);
6948 expr
.value
= build_component_ref (op_loc
,
6949 build_indirect_ref (op_loc
,
6953 expr
.original_code
= ERROR_MARK
;
6954 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6955 expr
.original_type
= NULL
;
6958 /* Remember the original type of a bitfield. */
6959 tree field
= TREE_OPERAND (expr
.value
, 1);
6960 if (TREE_CODE (field
) != FIELD_DECL
)
6961 expr
.original_type
= NULL
;
6963 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6967 /* Postincrement. */
6968 c_parser_consume_token (parser
);
6969 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6970 expr
.value
= build_unary_op (op_loc
,
6971 POSTINCREMENT_EXPR
, expr
.value
, 0);
6972 expr
.original_code
= ERROR_MARK
;
6973 expr
.original_type
= NULL
;
6975 case CPP_MINUS_MINUS
:
6976 /* Postdecrement. */
6977 c_parser_consume_token (parser
);
6978 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6979 expr
.value
= build_unary_op (op_loc
,
6980 POSTDECREMENT_EXPR
, expr
.value
, 0);
6981 expr
.original_code
= ERROR_MARK
;
6982 expr
.original_type
= NULL
;
6990 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6993 assignment-expression
6994 expression , assignment-expression
6997 static struct c_expr
6998 c_parser_expression (c_parser
*parser
)
7001 expr
= c_parser_expr_no_commas (parser
, NULL
);
7002 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7006 location_t loc
= c_parser_peek_token (parser
)->location
;
7007 location_t expr_loc
;
7008 c_parser_consume_token (parser
);
7009 expr_loc
= c_parser_peek_token (parser
)->location
;
7010 lhsval
= expr
.value
;
7011 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7012 lhsval
= TREE_OPERAND (lhsval
, 1);
7013 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7014 mark_exp_read (lhsval
);
7015 next
= c_parser_expr_no_commas (parser
, NULL
);
7016 next
= default_function_array_conversion (expr_loc
, next
);
7017 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7018 expr
.original_code
= COMPOUND_EXPR
;
7019 expr
.original_type
= next
.original_type
;
7024 /* Parse an expression and convert functions or arrays to
7027 static struct c_expr
7028 c_parser_expression_conv (c_parser
*parser
)
7031 location_t loc
= c_parser_peek_token (parser
)->location
;
7032 expr
= c_parser_expression (parser
);
7033 expr
= default_function_array_conversion (loc
, expr
);
7037 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7038 functions and arrays to pointers. If FOLD_P, fold the expressions.
7041 assignment-expression
7042 nonempty-expr-list , assignment-expression
7045 static VEC(tree
,gc
) *
7046 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7047 VEC(tree
,gc
) **p_orig_types
)
7050 VEC(tree
,gc
) *orig_types
;
7052 location_t loc
= c_parser_peek_token (parser
)->location
;
7054 ret
= make_tree_vector ();
7055 if (p_orig_types
== NULL
)
7058 orig_types
= make_tree_vector ();
7060 expr
= c_parser_expr_no_commas (parser
, NULL
);
7062 expr
= default_function_array_read_conversion (loc
, expr
);
7064 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7065 VEC_quick_push (tree
, ret
, expr
.value
);
7066 if (orig_types
!= NULL
)
7067 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
7068 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7070 c_parser_consume_token (parser
);
7071 loc
= c_parser_peek_token (parser
)->location
;
7072 expr
= c_parser_expr_no_commas (parser
, NULL
);
7074 expr
= default_function_array_read_conversion (loc
, expr
);
7076 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7077 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
7078 if (orig_types
!= NULL
)
7079 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
7081 if (orig_types
!= NULL
)
7082 *p_orig_types
= orig_types
;
7086 /* Parse Objective-C-specific constructs. */
7088 /* Parse an objc-class-definition.
7090 objc-class-definition:
7091 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7092 objc-class-instance-variables[opt] objc-methodprotolist @end
7093 @implementation identifier objc-superclass[opt]
7094 objc-class-instance-variables[opt]
7095 @interface identifier ( identifier ) objc-protocol-refs[opt]
7096 objc-methodprotolist @end
7097 @interface identifier ( ) objc-protocol-refs[opt]
7098 objc-methodprotolist @end
7099 @implementation identifier ( identifier )
7104 "@interface identifier (" must start "@interface identifier (
7105 identifier ) ...": objc-methodprotolist in the first production may
7106 not start with a parenthesized identifier as a declarator of a data
7107 definition with no declaration specifiers if the objc-superclass,
7108 objc-protocol-refs and objc-class-instance-variables are omitted. */
7111 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7116 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7118 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7123 c_parser_consume_token (parser
);
7124 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7126 c_parser_error (parser
, "expected identifier");
7129 id1
= c_parser_peek_token (parser
)->value
;
7130 c_parser_consume_token (parser
);
7131 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7133 /* We have a category or class extension. */
7135 tree proto
= NULL_TREE
;
7136 c_parser_consume_token (parser
);
7137 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7139 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7141 /* We have a class extension. */
7146 c_parser_error (parser
, "expected identifier or %<)%>");
7147 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7153 id2
= c_parser_peek_token (parser
)->value
;
7154 c_parser_consume_token (parser
);
7156 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7159 objc_start_category_implementation (id1
, id2
);
7162 if (c_parser_next_token_is (parser
, CPP_LESS
))
7163 proto
= c_parser_objc_protocol_refs (parser
);
7164 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7165 c_parser_objc_methodprotolist (parser
);
7166 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7167 objc_finish_interface ();
7170 if (c_parser_next_token_is (parser
, CPP_COLON
))
7172 c_parser_consume_token (parser
);
7173 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7175 c_parser_error (parser
, "expected identifier");
7178 superclass
= c_parser_peek_token (parser
)->value
;
7179 c_parser_consume_token (parser
);
7182 superclass
= NULL_TREE
;
7185 tree proto
= NULL_TREE
;
7186 if (c_parser_next_token_is (parser
, CPP_LESS
))
7187 proto
= c_parser_objc_protocol_refs (parser
);
7188 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7191 objc_start_class_implementation (id1
, superclass
);
7192 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7193 c_parser_objc_class_instance_variables (parser
);
7196 objc_continue_interface ();
7197 c_parser_objc_methodprotolist (parser
);
7198 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7199 objc_finish_interface ();
7203 objc_continue_implementation ();
7208 /* Parse objc-class-instance-variables.
7210 objc-class-instance-variables:
7211 { objc-instance-variable-decl-list[opt] }
7213 objc-instance-variable-decl-list:
7214 objc-visibility-spec
7215 objc-instance-variable-decl ;
7217 objc-instance-variable-decl-list objc-visibility-spec
7218 objc-instance-variable-decl-list objc-instance-variable-decl ;
7219 objc-instance-variable-decl-list ;
7221 objc-visibility-spec:
7226 objc-instance-variable-decl:
7231 c_parser_objc_class_instance_variables (c_parser
*parser
)
7233 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7234 c_parser_consume_token (parser
);
7235 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7238 /* Parse any stray semicolon. */
7239 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7241 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7243 c_parser_consume_token (parser
);
7246 /* Stop if at the end of the instance variables. */
7247 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7249 c_parser_consume_token (parser
);
7252 /* Parse any objc-visibility-spec. */
7253 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7255 c_parser_consume_token (parser
);
7256 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7259 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7261 c_parser_consume_token (parser
);
7262 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7265 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7267 c_parser_consume_token (parser
);
7268 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7271 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7273 c_parser_consume_token (parser
);
7274 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7277 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7279 c_parser_pragma (parser
, pragma_external
);
7283 /* Parse some comma-separated declarations. */
7284 decls
= c_parser_struct_declaration (parser
);
7287 /* There is a syntax error. We want to skip the offending
7288 tokens up to the next ';' (included) or '}'
7291 /* First, skip manually a ')' or ']'. This is because they
7292 reduce the nesting level, so c_parser_skip_until_found()
7293 wouldn't be able to skip past them. */
7294 c_token
*token
= c_parser_peek_token (parser
);
7295 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7296 c_parser_consume_token (parser
);
7298 /* Then, do the standard skipping. */
7299 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7301 /* We hopefully recovered. Start normal parsing again. */
7302 parser
->error
= false;
7307 /* Comma-separated instance variables are chained together
7308 in reverse order; add them one by one. */
7309 tree ivar
= nreverse (decls
);
7310 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7311 objc_add_instance_variable (copy_node (ivar
));
7313 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7317 /* Parse an objc-class-declaration.
7319 objc-class-declaration:
7320 @class identifier-list ;
7324 c_parser_objc_class_declaration (c_parser
*parser
)
7326 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7327 c_parser_consume_token (parser
);
7328 /* Any identifiers, including those declared as type names, are OK
7333 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7335 c_parser_error (parser
, "expected identifier");
7336 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7337 parser
->error
= false;
7340 id
= c_parser_peek_token (parser
)->value
;
7341 objc_declare_class (id
);
7342 c_parser_consume_token (parser
);
7343 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7344 c_parser_consume_token (parser
);
7348 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7351 /* Parse an objc-alias-declaration.
7353 objc-alias-declaration:
7354 @compatibility_alias identifier identifier ;
7358 c_parser_objc_alias_declaration (c_parser
*parser
)
7361 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7362 c_parser_consume_token (parser
);
7363 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7365 c_parser_error (parser
, "expected identifier");
7366 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7369 id1
= c_parser_peek_token (parser
)->value
;
7370 c_parser_consume_token (parser
);
7371 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7373 c_parser_error (parser
, "expected identifier");
7374 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7377 id2
= c_parser_peek_token (parser
)->value
;
7378 c_parser_consume_token (parser
);
7379 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7380 objc_declare_alias (id1
, id2
);
7383 /* Parse an objc-protocol-definition.
7385 objc-protocol-definition:
7386 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7387 @protocol identifier-list ;
7389 "@protocol identifier ;" should be resolved as "@protocol
7390 identifier-list ;": objc-methodprotolist may not start with a
7391 semicolon in the first alternative if objc-protocol-refs are
7395 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7397 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7399 c_parser_consume_token (parser
);
7400 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7402 c_parser_error (parser
, "expected identifier");
7405 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7406 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7408 /* Any identifiers, including those declared as type names, are
7413 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7415 c_parser_error (parser
, "expected identifier");
7418 id
= c_parser_peek_token (parser
)->value
;
7419 objc_declare_protocol (id
, attributes
);
7420 c_parser_consume_token (parser
);
7421 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7422 c_parser_consume_token (parser
);
7426 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7430 tree id
= c_parser_peek_token (parser
)->value
;
7431 tree proto
= NULL_TREE
;
7432 c_parser_consume_token (parser
);
7433 if (c_parser_next_token_is (parser
, CPP_LESS
))
7434 proto
= c_parser_objc_protocol_refs (parser
);
7435 parser
->objc_pq_context
= true;
7436 objc_start_protocol (id
, proto
, attributes
);
7437 c_parser_objc_methodprotolist (parser
);
7438 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7439 parser
->objc_pq_context
= false;
7440 objc_finish_interface ();
7444 /* Parse an objc-method-type.
7450 Return true if it is a class method (+) and false if it is
7451 an instance method (-).
7454 c_parser_objc_method_type (c_parser
*parser
)
7456 switch (c_parser_peek_token (parser
)->type
)
7459 c_parser_consume_token (parser
);
7462 c_parser_consume_token (parser
);
7469 /* Parse an objc-method-definition.
7471 objc-method-definition:
7472 objc-method-type objc-method-decl ;[opt] compound-statement
7476 c_parser_objc_method_definition (c_parser
*parser
)
7478 bool is_class_method
= c_parser_objc_method_type (parser
);
7479 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7480 parser
->objc_pq_context
= true;
7481 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7483 if (decl
== error_mark_node
)
7484 return; /* Bail here. */
7486 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7488 c_parser_consume_token (parser
);
7489 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7490 "extra semicolon in method definition specified");
7493 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7495 c_parser_error (parser
, "expected %<{%>");
7499 parser
->objc_pq_context
= false;
7500 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7502 add_stmt (c_parser_compound_statement (parser
));
7503 objc_finish_method_definition (current_function_decl
);
7507 /* This code is executed when we find a method definition
7508 outside of an @implementation context (or invalid for other
7509 reasons). Parse the method (to keep going) but do not emit
7512 c_parser_compound_statement (parser
);
7516 /* Parse an objc-methodprotolist.
7518 objc-methodprotolist:
7520 objc-methodprotolist objc-methodproto
7521 objc-methodprotolist declaration
7522 objc-methodprotolist ;
7526 The declaration is a data definition, which may be missing
7527 declaration specifiers under the same rules and diagnostics as
7528 other data definitions outside functions, and the stray semicolon
7529 is diagnosed the same way as a stray semicolon outside a
7533 c_parser_objc_methodprotolist (c_parser
*parser
)
7537 /* The list is terminated by @end. */
7538 switch (c_parser_peek_token (parser
)->type
)
7541 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7542 "ISO C does not allow extra %<;%> outside of a function");
7543 c_parser_consume_token (parser
);
7547 c_parser_objc_methodproto (parser
);
7550 c_parser_pragma (parser
, pragma_external
);
7555 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7557 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7558 c_parser_objc_at_property_declaration (parser
);
7559 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7561 objc_set_method_opt (true);
7562 c_parser_consume_token (parser
);
7564 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7566 objc_set_method_opt (false);
7567 c_parser_consume_token (parser
);
7570 c_parser_declaration_or_fndef (parser
, false, false, true,
7577 /* Parse an objc-methodproto.
7580 objc-method-type objc-method-decl ;
7584 c_parser_objc_methodproto (c_parser
*parser
)
7586 bool is_class_method
= c_parser_objc_method_type (parser
);
7587 tree decl
, attributes
= NULL_TREE
;
7589 /* Remember protocol qualifiers in prototypes. */
7590 parser
->objc_pq_context
= true;
7591 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7593 /* Forget protocol qualifiers now. */
7594 parser
->objc_pq_context
= false;
7596 /* Do not allow the presence of attributes to hide an erroneous
7597 method implementation in the interface section. */
7598 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7600 c_parser_error (parser
, "expected %<;%>");
7604 if (decl
!= error_mark_node
)
7605 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7607 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7610 /* If we are at a position that method attributes may be present, check that
7611 there are not any parsed already (a syntax error) and then collect any
7612 specified at the current location. Finally, if new attributes were present,
7613 check that the next token is legal ( ';' for decls and '{' for defs). */
7616 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7621 c_parser_error (parser
,
7622 "method attributes must be specified at the end only");
7623 *attributes
= NULL_TREE
;
7627 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7628 *attributes
= c_parser_attributes (parser
);
7630 /* If there were no attributes here, just report any earlier error. */
7631 if (*attributes
== NULL_TREE
|| bad
)
7634 /* If the attributes are followed by a ; or {, then just report any earlier
7636 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7637 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7640 /* We've got attributes, but not at the end. */
7641 c_parser_error (parser
,
7642 "expected %<;%> or %<{%> after method attribute definition");
7646 /* Parse an objc-method-decl.
7649 ( objc-type-name ) objc-selector
7651 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7652 objc-keyword-selector objc-optparmlist
7655 objc-keyword-selector:
7657 objc-keyword-selector objc-keyword-decl
7660 objc-selector : ( objc-type-name ) identifier
7661 objc-selector : identifier
7662 : ( objc-type-name ) identifier
7666 objc-optparms objc-optellipsis
7670 objc-opt-parms , parameter-declaration
7678 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7679 tree
*attributes
, tree
*expr
)
7681 tree type
= NULL_TREE
;
7683 tree parms
= NULL_TREE
;
7684 bool ellipsis
= false;
7685 bool attr_err
= false;
7687 *attributes
= NULL_TREE
;
7688 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7690 c_parser_consume_token (parser
);
7691 type
= c_parser_objc_type_name (parser
);
7692 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7694 sel
= c_parser_objc_selector (parser
);
7695 /* If there is no selector, or a colon follows, we have an
7696 objc-keyword-selector. If there is a selector, and a colon does
7697 not follow, that selector ends the objc-method-decl. */
7698 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7701 tree list
= NULL_TREE
;
7704 tree atype
= NULL_TREE
, id
, keyworddecl
;
7705 tree param_attr
= NULL_TREE
;
7706 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7708 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7710 c_parser_consume_token (parser
);
7711 atype
= c_parser_objc_type_name (parser
);
7712 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7715 /* New ObjC allows attributes on method parameters. */
7716 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7717 param_attr
= c_parser_attributes (parser
);
7718 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7720 c_parser_error (parser
, "expected identifier");
7721 return error_mark_node
;
7723 id
= c_parser_peek_token (parser
)->value
;
7724 c_parser_consume_token (parser
);
7725 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7726 list
= chainon (list
, keyworddecl
);
7727 tsel
= c_parser_objc_selector (parser
);
7728 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7732 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7734 /* Parse the optional parameter list. Optional Objective-C
7735 method parameters follow the C syntax, and may include '...'
7736 to denote a variable number of arguments. */
7737 parms
= make_node (TREE_LIST
);
7738 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7740 struct c_parm
*parm
;
7741 c_parser_consume_token (parser
);
7742 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7745 c_parser_consume_token (parser
);
7746 attr_err
|= c_parser_objc_maybe_method_attributes
7747 (parser
, attributes
) ;
7750 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7753 parms
= chainon (parms
,
7754 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
7759 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7763 c_parser_error (parser
, "objective-c method declaration is expected");
7764 return error_mark_node
;
7768 return error_mark_node
;
7770 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7773 /* Parse an objc-type-name.
7776 objc-type-qualifiers[opt] type-name
7777 objc-type-qualifiers[opt]
7779 objc-type-qualifiers:
7781 objc-type-qualifiers objc-type-qualifier
7783 objc-type-qualifier: one of
7784 in out inout bycopy byref oneway
7788 c_parser_objc_type_name (c_parser
*parser
)
7790 tree quals
= NULL_TREE
;
7791 struct c_type_name
*type_name
= NULL
;
7792 tree type
= NULL_TREE
;
7795 c_token
*token
= c_parser_peek_token (parser
);
7796 if (token
->type
== CPP_KEYWORD
7797 && (token
->keyword
== RID_IN
7798 || token
->keyword
== RID_OUT
7799 || token
->keyword
== RID_INOUT
7800 || token
->keyword
== RID_BYCOPY
7801 || token
->keyword
== RID_BYREF
7802 || token
->keyword
== RID_ONEWAY
))
7804 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7805 c_parser_consume_token (parser
);
7810 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7811 type_name
= c_parser_type_name (parser
);
7813 type
= groktypename (type_name
, NULL
, NULL
);
7815 /* If the type is unknown, and error has already been produced and
7816 we need to recover from the error. In that case, use NULL_TREE
7817 for the type, as if no type had been specified; this will use the
7818 default type ('id') which is good for error recovery. */
7819 if (type
== error_mark_node
)
7822 return build_tree_list (quals
, type
);
7825 /* Parse objc-protocol-refs.
7832 c_parser_objc_protocol_refs (c_parser
*parser
)
7834 tree list
= NULL_TREE
;
7835 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7836 c_parser_consume_token (parser
);
7837 /* Any identifiers, including those declared as type names, are OK
7842 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7844 c_parser_error (parser
, "expected identifier");
7847 id
= c_parser_peek_token (parser
)->value
;
7848 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7849 c_parser_consume_token (parser
);
7850 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7851 c_parser_consume_token (parser
);
7855 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7859 /* Parse an objc-try-catch-finally-statement.
7861 objc-try-catch-finally-statement:
7862 @try compound-statement objc-catch-list[opt]
7863 @try compound-statement objc-catch-list[opt] @finally compound-statement
7866 @catch ( objc-catch-parameter-declaration ) compound-statement
7867 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7869 objc-catch-parameter-declaration:
7870 parameter-declaration
7873 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7875 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7876 for C++. Keep them in sync. */
7879 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
7881 location_t location
;
7884 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7885 c_parser_consume_token (parser
);
7886 location
= c_parser_peek_token (parser
)->location
;
7887 objc_maybe_warn_exceptions (location
);
7888 stmt
= c_parser_compound_statement (parser
);
7889 objc_begin_try_stmt (location
, stmt
);
7891 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7893 struct c_parm
*parm
;
7894 tree parameter_declaration
= error_mark_node
;
7895 bool seen_open_paren
= false;
7897 c_parser_consume_token (parser
);
7898 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7899 seen_open_paren
= true;
7900 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7902 /* We have "@catch (...)" (where the '...' are literally
7903 what is in the code). Skip the '...'.
7904 parameter_declaration is set to NULL_TREE, and
7905 objc_being_catch_clauses() knows that that means
7907 c_parser_consume_token (parser
);
7908 parameter_declaration
= NULL_TREE
;
7912 /* We have "@catch (NSException *exception)" or something
7913 like that. Parse the parameter declaration. */
7914 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7916 parameter_declaration
= error_mark_node
;
7918 parameter_declaration
= grokparm (parm
, NULL
);
7920 if (seen_open_paren
)
7921 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7924 /* If there was no open parenthesis, we are recovering from
7925 an error, and we are trying to figure out what mistake
7926 the user has made. */
7928 /* If there is an immediate closing parenthesis, the user
7929 probably forgot the opening one (ie, they typed "@catch
7930 NSException *e)". Parse the closing parenthesis and keep
7932 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7933 c_parser_consume_token (parser
);
7935 /* If these is no immediate closing parenthesis, the user
7936 probably doesn't know that parenthesis are required at
7937 all (ie, they typed "@catch NSException *e"). So, just
7938 forget about the closing parenthesis and keep going. */
7940 objc_begin_catch_clause (parameter_declaration
);
7941 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7942 c_parser_compound_statement_nostart (parser
);
7943 objc_finish_catch_clause ();
7945 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
7947 c_parser_consume_token (parser
);
7948 location
= c_parser_peek_token (parser
)->location
;
7949 stmt
= c_parser_compound_statement (parser
);
7950 objc_build_finally_clause (location
, stmt
);
7952 objc_finish_try_stmt ();
7955 /* Parse an objc-synchronized-statement.
7957 objc-synchronized-statement:
7958 @synchronized ( expression ) compound-statement
7962 c_parser_objc_synchronized_statement (c_parser
*parser
)
7966 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
7967 c_parser_consume_token (parser
);
7968 loc
= c_parser_peek_token (parser
)->location
;
7969 objc_maybe_warn_exceptions (loc
);
7970 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7972 expr
= c_parser_expression (parser
).value
;
7973 expr
= c_fully_fold (expr
, false, NULL
);
7974 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7977 expr
= error_mark_node
;
7978 stmt
= c_parser_compound_statement (parser
);
7979 objc_build_synchronized (loc
, expr
, stmt
);
7982 /* Parse an objc-selector; return NULL_TREE without an error if the
7983 next token is not an objc-selector.
7988 enum struct union if else while do for switch case default
7989 break continue return goto asm sizeof typeof __alignof
7990 unsigned long const short volatile signed restrict _Complex
7991 in out inout bycopy byref oneway int char float double void _Bool
7993 ??? Why this selection of keywords but not, for example, storage
7994 class specifiers? */
7997 c_parser_objc_selector (c_parser
*parser
)
7999 c_token
*token
= c_parser_peek_token (parser
);
8000 tree value
= token
->value
;
8001 if (token
->type
== CPP_NAME
)
8003 c_parser_consume_token (parser
);
8006 if (token
->type
!= CPP_KEYWORD
)
8008 switch (token
->keyword
)
8050 c_parser_consume_token (parser
);
8057 /* Parse an objc-selector-arg.
8061 objc-keywordname-list
8063 objc-keywordname-list:
8065 objc-keywordname-list objc-keywordname
8073 c_parser_objc_selector_arg (c_parser
*parser
)
8075 tree sel
= c_parser_objc_selector (parser
);
8076 tree list
= NULL_TREE
;
8077 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8081 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8083 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8084 sel
= c_parser_objc_selector (parser
);
8085 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8091 /* Parse an objc-receiver.
8100 c_parser_objc_receiver (c_parser
*parser
)
8102 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8103 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8104 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8106 tree id
= c_parser_peek_token (parser
)->value
;
8107 c_parser_consume_token (parser
);
8108 return objc_get_class_reference (id
);
8110 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8113 /* Parse objc-message-args.
8117 objc-keywordarg-list
8119 objc-keywordarg-list:
8121 objc-keywordarg-list objc-keywordarg
8124 objc-selector : objc-keywordexpr
8129 c_parser_objc_message_args (c_parser
*parser
)
8131 tree sel
= c_parser_objc_selector (parser
);
8132 tree list
= NULL_TREE
;
8133 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8138 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8139 return error_mark_node
;
8140 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8141 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8142 sel
= c_parser_objc_selector (parser
);
8143 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8149 /* Parse an objc-keywordexpr.
8156 c_parser_objc_keywordexpr (c_parser
*parser
)
8159 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
8160 if (VEC_length (tree
, expr_list
) == 1)
8162 /* Just return the expression, remove a level of
8164 ret
= VEC_index (tree
, expr_list
, 0);
8168 /* We have a comma expression, we will collapse later. */
8169 ret
= build_tree_list_vec (expr_list
);
8171 release_tree_vector (expr_list
);
8175 /* A check, needed in several places, that ObjC interface, implementation or
8176 method definitions are not prefixed by incorrect items. */
8178 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8179 struct c_declspecs
*specs
)
8181 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8182 || specs
->typespec_kind
!= ctsk_none
)
8184 c_parser_error (parser
,
8185 "no type or storage class may be specified here,");
8186 c_parser_skip_to_end_of_block_or_statement (parser
);
8192 /* Parse an Objective-C @property declaration. The syntax is:
8194 objc-property-declaration:
8195 '@property' objc-property-attributes[opt] struct-declaration ;
8197 objc-property-attributes:
8198 '(' objc-property-attribute-list ')'
8200 objc-property-attribute-list:
8201 objc-property-attribute
8202 objc-property-attribute-list, objc-property-attribute
8204 objc-property-attribute
8205 'getter' = identifier
8206 'setter' = identifier
8215 @property NSString *name;
8216 @property (readonly) id object;
8217 @property (retain, nonatomic, getter=getTheName) id name;
8218 @property int a, b, c;
8220 PS: This function is identical to cp_parser_objc_at_propery_declaration
8221 for C++. Keep them in sync. */
8223 c_parser_objc_at_property_declaration (c_parser
*parser
)
8225 /* The following variables hold the attributes of the properties as
8226 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8227 seen. When we see an attribute, we set them to 'true' (if they
8228 are boolean properties) or to the identifier (if they have an
8229 argument, ie, for getter and setter). Note that here we only
8230 parse the list of attributes, check the syntax and accumulate the
8231 attributes that we find. objc_add_property_declaration() will
8232 then process the information. */
8233 bool property_assign
= false;
8234 bool property_copy
= false;
8235 tree property_getter_ident
= NULL_TREE
;
8236 bool property_nonatomic
= false;
8237 bool property_readonly
= false;
8238 bool property_readwrite
= false;
8239 bool property_retain
= false;
8240 tree property_setter_ident
= NULL_TREE
;
8242 /* 'properties' is the list of properties that we read. Usually a
8243 single one, but maybe more (eg, in "@property int a, b, c;" there
8248 loc
= c_parser_peek_token (parser
)->location
;
8249 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8251 c_parser_consume_token (parser
); /* Eat '@property'. */
8253 /* Parse the optional attribute list... */
8254 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8257 c_parser_consume_token (parser
);
8259 /* Property attribute keywords are valid now. */
8260 parser
->objc_property_attr_context
= true;
8264 bool syntax_error
= false;
8265 c_token
*token
= c_parser_peek_token (parser
);
8268 if (token
->type
!= CPP_KEYWORD
)
8270 if (token
->type
== CPP_CLOSE_PAREN
)
8271 c_parser_error (parser
, "expected identifier");
8274 c_parser_consume_token (parser
);
8275 c_parser_error (parser
, "unknown property attribute");
8279 keyword
= token
->keyword
;
8280 c_parser_consume_token (parser
);
8283 case RID_ASSIGN
: property_assign
= true; break;
8284 case RID_COPY
: property_copy
= true; break;
8285 case RID_NONATOMIC
: property_nonatomic
= true; break;
8286 case RID_READONLY
: property_readonly
= true; break;
8287 case RID_READWRITE
: property_readwrite
= true; break;
8288 case RID_RETAIN
: property_retain
= true; break;
8292 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8294 if (keyword
== RID_GETTER
)
8295 c_parser_error (parser
,
8296 "missing %<=%> (after %<getter%> attribute)");
8298 c_parser_error (parser
,
8299 "missing %<=%> (after %<setter%> attribute)");
8300 syntax_error
= true;
8303 c_parser_consume_token (parser
); /* eat the = */
8304 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8306 c_parser_error (parser
, "expected identifier");
8307 syntax_error
= true;
8310 if (keyword
== RID_SETTER
)
8312 if (property_setter_ident
!= NULL_TREE
)
8313 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8315 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8316 c_parser_consume_token (parser
);
8317 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8318 c_parser_error (parser
, "setter name must terminate with %<:%>");
8320 c_parser_consume_token (parser
);
8324 if (property_getter_ident
!= NULL_TREE
)
8325 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8327 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8328 c_parser_consume_token (parser
);
8332 c_parser_error (parser
, "unknown property attribute");
8333 syntax_error
= true;
8340 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8341 c_parser_consume_token (parser
);
8345 parser
->objc_property_attr_context
= false;
8346 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8348 /* ... and the property declaration(s). */
8349 properties
= c_parser_struct_declaration (parser
);
8351 if (properties
== error_mark_node
)
8353 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8354 parser
->error
= false;
8358 if (properties
== NULL_TREE
)
8359 c_parser_error (parser
, "expected identifier");
8362 /* Comma-separated properties are chained together in
8363 reverse order; add them one by one. */
8364 properties
= nreverse (properties
);
8366 for (; properties
; properties
= TREE_CHAIN (properties
))
8367 objc_add_property_declaration (loc
, copy_node (properties
),
8368 property_readonly
, property_readwrite
,
8369 property_assign
, property_retain
,
8370 property_copy
, property_nonatomic
,
8371 property_getter_ident
, property_setter_ident
);
8374 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8375 parser
->error
= false;
8378 /* Parse an Objective-C @synthesize declaration. The syntax is:
8380 objc-synthesize-declaration:
8381 @synthesize objc-synthesize-identifier-list ;
8383 objc-synthesize-identifier-list:
8384 objc-synthesize-identifier
8385 objc-synthesize-identifier-list, objc-synthesize-identifier
8387 objc-synthesize-identifier
8389 identifier = identifier
8392 @synthesize MyProperty;
8393 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8395 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8396 for C++. Keep them in sync.
8399 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8401 tree list
= NULL_TREE
;
8403 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8404 loc
= c_parser_peek_token (parser
)->location
;
8406 c_parser_consume_token (parser
);
8409 tree property
, ivar
;
8410 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8412 c_parser_error (parser
, "expected identifier");
8413 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8414 /* Once we find the semicolon, we can resume normal parsing.
8415 We have to reset parser->error manually because
8416 c_parser_skip_until_found() won't reset it for us if the
8417 next token is precisely a semicolon. */
8418 parser
->error
= false;
8421 property
= c_parser_peek_token (parser
)->value
;
8422 c_parser_consume_token (parser
);
8423 if (c_parser_next_token_is (parser
, CPP_EQ
))
8425 c_parser_consume_token (parser
);
8426 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8428 c_parser_error (parser
, "expected identifier");
8429 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8430 parser
->error
= false;
8433 ivar
= c_parser_peek_token (parser
)->value
;
8434 c_parser_consume_token (parser
);
8438 list
= chainon (list
, build_tree_list (ivar
, property
));
8439 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8440 c_parser_consume_token (parser
);
8444 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8445 objc_add_synthesize_declaration (loc
, list
);
8448 /* Parse an Objective-C @dynamic declaration. The syntax is:
8450 objc-dynamic-declaration:
8451 @dynamic identifier-list ;
8454 @dynamic MyProperty;
8455 @dynamic MyProperty, AnotherProperty;
8457 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8458 for C++. Keep them in sync.
8461 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8463 tree list
= NULL_TREE
;
8465 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8466 loc
= c_parser_peek_token (parser
)->location
;
8468 c_parser_consume_token (parser
);
8472 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8474 c_parser_error (parser
, "expected identifier");
8475 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8476 parser
->error
= false;
8479 property
= c_parser_peek_token (parser
)->value
;
8480 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8481 c_parser_consume_token (parser
);
8482 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8483 c_parser_consume_token (parser
);
8487 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8488 objc_add_dynamic_declaration (loc
, list
);
8492 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8493 should be considered, statements. ALLOW_STMT is true if we're within
8494 the context of a function and such pragmas are to be allowed. Returns
8495 true if we actually parsed such a pragma. */
8498 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8502 id
= c_parser_peek_token (parser
)->pragma_kind
;
8503 gcc_assert (id
!= PRAGMA_NONE
);
8507 case PRAGMA_OMP_BARRIER
:
8508 if (context
!= pragma_compound
)
8510 if (context
== pragma_stmt
)
8511 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8512 "used in compound statements");
8515 c_parser_omp_barrier (parser
);
8518 case PRAGMA_OMP_FLUSH
:
8519 if (context
!= pragma_compound
)
8521 if (context
== pragma_stmt
)
8522 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8523 "used in compound statements");
8526 c_parser_omp_flush (parser
);
8529 case PRAGMA_OMP_TASKWAIT
:
8530 if (context
!= pragma_compound
)
8532 if (context
== pragma_stmt
)
8533 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8534 "used in compound statements");
8537 c_parser_omp_taskwait (parser
);
8540 case PRAGMA_OMP_TASKYIELD
:
8541 if (context
!= pragma_compound
)
8543 if (context
== pragma_stmt
)
8544 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
8545 "used in compound statements");
8548 c_parser_omp_taskyield (parser
);
8551 case PRAGMA_OMP_THREADPRIVATE
:
8552 c_parser_omp_threadprivate (parser
);
8555 case PRAGMA_OMP_SECTION
:
8556 error_at (c_parser_peek_token (parser
)->location
,
8557 "%<#pragma omp section%> may only be used in "
8558 "%<#pragma omp sections%> construct");
8559 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8562 case PRAGMA_GCC_PCH_PREPROCESS
:
8563 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8564 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8568 if (id
< PRAGMA_FIRST_EXTERNAL
)
8570 if (context
== pragma_external
)
8573 c_parser_error (parser
, "expected declaration specifiers");
8574 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8577 c_parser_omp_construct (parser
);
8583 c_parser_consume_pragma (parser
);
8584 c_invoke_pragma_handler (id
);
8586 /* Skip to EOL, but suppress any error message. Those will have been
8587 generated by the handler routine through calling error, as opposed
8588 to calling c_parser_error. */
8589 parser
->error
= true;
8590 c_parser_skip_to_pragma_eol (parser
);
8595 /* The interface the pragma parsers have to the lexer. */
8598 pragma_lex (tree
*value
)
8600 c_token
*tok
= c_parser_peek_token (the_parser
);
8601 enum cpp_ttype ret
= tok
->type
;
8603 *value
= tok
->value
;
8604 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8608 if (ret
== CPP_KEYWORD
)
8610 c_parser_consume_token (the_parser
);
8617 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8621 c_parser_consume_pragma (parser
);
8622 if (c_parser_next_token_is (parser
, CPP_STRING
))
8624 name
= c_parser_peek_token (parser
)->value
;
8625 c_parser_consume_token (parser
);
8628 c_parser_error (parser
, "expected string literal");
8629 c_parser_skip_to_pragma_eol (parser
);
8632 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8635 /* OpenMP 2.5 parsing routines. */
8637 /* Returns name of the next clause.
8638 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8639 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8640 returned and the token is consumed. */
8642 static pragma_omp_clause
8643 c_parser_omp_clause_name (c_parser
*parser
)
8645 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8647 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8648 result
= PRAGMA_OMP_CLAUSE_IF
;
8649 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8650 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8651 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8653 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8658 if (!strcmp ("collapse", p
))
8659 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8660 else if (!strcmp ("copyin", p
))
8661 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8662 else if (!strcmp ("copyprivate", p
))
8663 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8666 if (!strcmp ("final", p
))
8667 result
= PRAGMA_OMP_CLAUSE_FINAL
;
8668 else if (!strcmp ("firstprivate", p
))
8669 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8672 if (!strcmp ("lastprivate", p
))
8673 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8676 if (!strcmp ("mergeable", p
))
8677 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
8680 if (!strcmp ("nowait", p
))
8681 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8682 else if (!strcmp ("num_threads", p
))
8683 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8686 if (!strcmp ("ordered", p
))
8687 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8690 if (!strcmp ("private", p
))
8691 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8694 if (!strcmp ("reduction", p
))
8695 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8698 if (!strcmp ("schedule", p
))
8699 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8700 else if (!strcmp ("shared", p
))
8701 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8704 if (!strcmp ("untied", p
))
8705 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8710 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8711 c_parser_consume_token (parser
);
8716 /* Validate that a clause of the given type does not already exist. */
8719 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8724 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8725 if (OMP_CLAUSE_CODE (c
) == code
)
8727 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8728 error_at (loc
, "too many %qs clauses", name
);
8736 variable-list , identifier
8738 If KIND is nonzero, create the appropriate node and install the
8739 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8740 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8742 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8743 return the list created. */
8746 c_parser_omp_variable_list (c_parser
*parser
,
8747 location_t clause_loc
,
8748 enum omp_clause_code kind
,
8751 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8752 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8753 c_parser_error (parser
, "expected identifier");
8755 while (c_parser_next_token_is (parser
, CPP_NAME
)
8756 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8758 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8761 undeclared_variable (c_parser_peek_token (parser
)->location
,
8762 c_parser_peek_token (parser
)->value
);
8763 else if (t
== error_mark_node
)
8767 tree u
= build_omp_clause (clause_loc
, kind
);
8768 OMP_CLAUSE_DECL (u
) = t
;
8769 OMP_CLAUSE_CHAIN (u
) = list
;
8773 list
= tree_cons (t
, NULL_TREE
, list
);
8775 c_parser_consume_token (parser
);
8777 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8780 c_parser_consume_token (parser
);
8786 /* Similarly, but expect leading and trailing parenthesis. This is a very
8787 common case for omp clauses. */
8790 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8793 /* The clauses location. */
8794 location_t loc
= c_parser_peek_token (parser
)->location
;
8796 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8798 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8799 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8805 collapse ( constant-expression ) */
8808 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8810 tree c
, num
= error_mark_node
;
8814 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8816 loc
= c_parser_peek_token (parser
)->location
;
8817 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8819 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8820 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8822 if (num
== error_mark_node
)
8824 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8825 || !host_integerp (num
, 0)
8826 || (n
= tree_low_cst (num
, 0)) <= 0
8830 "collapse argument needs positive constant integer expression");
8833 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8834 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
8835 OMP_CLAUSE_CHAIN (c
) = list
;
8840 copyin ( variable-list ) */
8843 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
8845 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
8849 copyprivate ( variable-list ) */
8852 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
8854 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
8858 default ( shared | none ) */
8861 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
8863 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
8864 location_t loc
= c_parser_peek_token (parser
)->location
;
8867 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8869 if (c_parser_next_token_is (parser
, CPP_NAME
))
8871 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8876 if (strcmp ("none", p
) != 0)
8878 kind
= OMP_CLAUSE_DEFAULT_NONE
;
8882 if (strcmp ("shared", p
) != 0)
8884 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
8891 c_parser_consume_token (parser
);
8896 c_parser_error (parser
, "expected %<none%> or %<shared%>");
8898 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8900 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
8903 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
8904 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
8905 OMP_CLAUSE_CHAIN (c
) = list
;
8906 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
8912 firstprivate ( variable-list ) */
8915 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
8917 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
8921 final ( expression ) */
8924 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
8926 location_t loc
= c_parser_peek_token (parser
)->location
;
8927 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8929 tree t
= c_parser_paren_condition (parser
);
8932 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
8934 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
8935 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
8936 OMP_CLAUSE_CHAIN (c
) = list
;
8940 c_parser_error (parser
, "expected %<(%>");
8946 if ( expression ) */
8949 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
8951 location_t loc
= c_parser_peek_token (parser
)->location
;
8952 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8954 tree t
= c_parser_paren_condition (parser
);
8957 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
8959 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
8960 OMP_CLAUSE_IF_EXPR (c
) = t
;
8961 OMP_CLAUSE_CHAIN (c
) = list
;
8965 c_parser_error (parser
, "expected %<(%>");
8971 lastprivate ( variable-list ) */
8974 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
8976 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
8983 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8987 /* FIXME: Should we allow duplicates? */
8988 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
8990 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8991 OMP_CLAUSE_MERGEABLE
);
8992 OMP_CLAUSE_CHAIN (c
) = list
;
9001 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9004 location_t loc
= c_parser_peek_token (parser
)->location
;
9006 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9008 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9009 OMP_CLAUSE_CHAIN (c
) = list
;
9014 num_threads ( expression ) */
9017 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9019 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9020 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9022 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9023 tree c
, t
= c_parser_expression (parser
).value
;
9025 t
= c_fully_fold (t
, false, NULL
);
9027 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9029 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9031 c_parser_error (parser
, "expected integer expression");
9035 /* Attempt to statically determine when the number isn't positive. */
9036 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9037 build_int_cst (TREE_TYPE (t
), 0));
9038 if (CAN_HAVE_LOCATION_P (c
))
9039 SET_EXPR_LOCATION (c
, expr_loc
);
9040 if (c
== boolean_true_node
)
9042 warning_at (expr_loc
, 0,
9043 "%<num_threads%> value must be positive");
9044 t
= integer_one_node
;
9047 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9049 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9050 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9051 OMP_CLAUSE_CHAIN (c
) = list
;
9062 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9066 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9068 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9069 OMP_CLAUSE_ORDERED
);
9070 OMP_CLAUSE_CHAIN (c
) = list
;
9076 private ( variable-list ) */
9079 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9081 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9085 reduction ( reduction-operator : variable-list )
9088 One of: + * - & ^ | && ||
9093 One of: + * - & ^ | && || max min */
9096 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9098 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9099 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9101 enum tree_code code
;
9103 switch (c_parser_peek_token (parser
)->type
)
9115 code
= BIT_AND_EXPR
;
9118 code
= BIT_XOR_EXPR
;
9121 code
= BIT_IOR_EXPR
;
9124 code
= TRUTH_ANDIF_EXPR
;
9127 code
= TRUTH_ORIF_EXPR
;
9132 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9133 if (strcmp (p
, "min") == 0)
9138 if (strcmp (p
, "max") == 0)
9146 c_parser_error (parser
,
9147 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9148 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9149 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9152 c_parser_consume_token (parser
);
9153 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9157 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9158 OMP_CLAUSE_REDUCTION
, list
);
9159 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9160 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9164 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9170 schedule ( schedule-kind )
9171 schedule ( schedule-kind , expression )
9174 static | dynamic | guided | runtime | auto
9178 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9181 location_t loc
= c_parser_peek_token (parser
)->location
;
9183 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9186 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9188 if (c_parser_next_token_is (parser
, CPP_NAME
))
9190 tree kind
= c_parser_peek_token (parser
)->value
;
9191 const char *p
= IDENTIFIER_POINTER (kind
);
9196 if (strcmp ("dynamic", p
) != 0)
9198 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9202 if (strcmp ("guided", p
) != 0)
9204 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9208 if (strcmp ("runtime", p
) != 0)
9210 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9217 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9218 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9219 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9220 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9224 c_parser_consume_token (parser
);
9225 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9228 c_parser_consume_token (parser
);
9230 here
= c_parser_peek_token (parser
)->location
;
9231 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9233 t
= c_fully_fold (t
, false, NULL
);
9235 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9236 error_at (here
, "schedule %<runtime%> does not take "
9237 "a %<chunk_size%> parameter");
9238 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9240 "schedule %<auto%> does not take "
9241 "a %<chunk_size%> parameter");
9242 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9243 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9245 c_parser_error (parser
, "expected integer expression");
9247 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9250 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9251 "expected %<,%> or %<)%>");
9253 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9254 OMP_CLAUSE_CHAIN (c
) = list
;
9258 c_parser_error (parser
, "invalid schedule kind");
9259 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9264 shared ( variable-list ) */
9267 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9269 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9276 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9280 /* FIXME: Should we allow duplicates? */
9281 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9283 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9285 OMP_CLAUSE_CHAIN (c
) = list
;
9290 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9291 is a bitmask in MASK. Return the list of clauses found; the result
9292 of clause default goes in *pdefault. */
9295 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9298 tree clauses
= NULL
;
9301 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9304 pragma_omp_clause c_kind
;
9306 tree prev
= clauses
;
9308 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9309 c_parser_consume_token (parser
);
9312 here
= c_parser_peek_token (parser
)->location
;
9313 c_kind
= c_parser_omp_clause_name (parser
);
9317 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9318 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9319 c_name
= "collapse";
9321 case PRAGMA_OMP_CLAUSE_COPYIN
:
9322 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9325 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9326 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9327 c_name
= "copyprivate";
9329 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9330 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9333 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9334 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9335 c_name
= "firstprivate";
9337 case PRAGMA_OMP_CLAUSE_FINAL
:
9338 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9341 case PRAGMA_OMP_CLAUSE_IF
:
9342 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9345 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9346 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9347 c_name
= "lastprivate";
9349 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9350 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9351 c_name
= "mergeable";
9353 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9354 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9357 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9358 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9359 c_name
= "num_threads";
9361 case PRAGMA_OMP_CLAUSE_ORDERED
:
9362 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9365 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9366 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9369 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9370 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9371 c_name
= "reduction";
9373 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9374 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9375 c_name
= "schedule";
9377 case PRAGMA_OMP_CLAUSE_SHARED
:
9378 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9381 case PRAGMA_OMP_CLAUSE_UNTIED
:
9382 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9386 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9390 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9392 /* Remove the invalid clause(s) from the list to avoid
9393 confusing the rest of the compiler. */
9395 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9400 c_parser_skip_to_pragma_eol (parser
);
9402 return c_finish_omp_clauses (clauses
);
9409 In practice, we're also interested in adding the statement to an
9410 outer node. So it is convenient if we work around the fact that
9411 c_parser_statement calls add_stmt. */
9414 c_parser_omp_structured_block (c_parser
*parser
)
9416 tree stmt
= push_stmt_list ();
9417 c_parser_statement (parser
);
9418 return pop_stmt_list (stmt
);
9422 # pragma omp atomic new-line
9426 x binop= expr | x++ | ++x | x-- | --x
9428 +, *, -, /, &, ^, |, <<, >>
9430 where x is an lvalue expression with scalar type.
9433 # pragma omp atomic new-line
9436 # pragma omp atomic read new-line
9439 # pragma omp atomic write new-line
9442 # pragma omp atomic update new-line
9445 # pragma omp atomic capture new-line
9448 # pragma omp atomic capture new-line
9456 expression-stmt | x = x binop expr
9458 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9460 { v = x; update-stmt; } | { update-stmt; v = x; }
9462 where x and v are lvalue expressions with scalar type.
9464 LOC is the location of the #pragma token. */
9467 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9469 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9470 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9471 tree stmt
, orig_lhs
;
9472 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9473 struct c_expr rhs_expr
;
9474 bool structured_block
= false;
9476 if (c_parser_next_token_is (parser
, CPP_NAME
))
9478 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9480 if (!strcmp (p
, "read"))
9481 code
= OMP_ATOMIC_READ
;
9482 else if (!strcmp (p
, "write"))
9484 else if (!strcmp (p
, "update"))
9486 else if (!strcmp (p
, "capture"))
9487 code
= OMP_ATOMIC_CAPTURE_NEW
;
9491 c_parser_consume_token (parser
);
9493 c_parser_skip_to_pragma_eol (parser
);
9497 case OMP_ATOMIC_READ
:
9498 case NOP_EXPR
: /* atomic write */
9499 v
= c_parser_unary_expression (parser
).value
;
9500 v
= c_fully_fold (v
, false, NULL
);
9501 if (v
== error_mark_node
)
9503 loc
= c_parser_peek_token (parser
)->location
;
9504 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9506 if (code
== NOP_EXPR
)
9507 lhs
= c_parser_expression (parser
).value
;
9509 lhs
= c_parser_unary_expression (parser
).value
;
9510 lhs
= c_fully_fold (lhs
, false, NULL
);
9511 if (lhs
== error_mark_node
)
9513 if (code
== NOP_EXPR
)
9515 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9523 case OMP_ATOMIC_CAPTURE_NEW
:
9524 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9526 c_parser_consume_token (parser
);
9527 structured_block
= true;
9531 v
= c_parser_unary_expression (parser
).value
;
9532 v
= c_fully_fold (v
, false, NULL
);
9533 if (v
== error_mark_node
)
9535 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9543 /* For structured_block case we don't know yet whether
9544 old or new x should be captured. */
9546 lhs
= c_parser_unary_expression (parser
).value
;
9547 lhs
= c_fully_fold (lhs
, false, NULL
);
9549 switch (TREE_CODE (lhs
))
9553 c_parser_skip_to_end_of_block_or_statement (parser
);
9554 if (structured_block
)
9556 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9557 c_parser_consume_token (parser
);
9558 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9560 c_parser_skip_to_end_of_block_or_statement (parser
);
9561 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9562 c_parser_consume_token (parser
);
9567 case POSTINCREMENT_EXPR
:
9568 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9569 code
= OMP_ATOMIC_CAPTURE_OLD
;
9571 case PREINCREMENT_EXPR
:
9572 lhs
= TREE_OPERAND (lhs
, 0);
9574 rhs
= integer_one_node
;
9577 case POSTDECREMENT_EXPR
:
9578 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9579 code
= OMP_ATOMIC_CAPTURE_OLD
;
9581 case PREDECREMENT_EXPR
:
9582 lhs
= TREE_OPERAND (lhs
, 0);
9583 opcode
= MINUS_EXPR
;
9584 rhs
= integer_one_node
;
9588 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9589 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9590 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9591 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9592 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9593 (TREE_OPERAND (lhs
, 1), 0), 0)))
9595 /* Undo effects of boolean_increment for post {in,de}crement. */
9596 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9599 if (TREE_CODE (lhs
) == MODIFY_EXPR
9600 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9602 /* Undo effects of boolean_increment. */
9603 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9605 /* This is pre or post increment. */
9606 rhs
= TREE_OPERAND (lhs
, 1);
9607 lhs
= TREE_OPERAND (lhs
, 0);
9609 if (code
== OMP_ATOMIC_CAPTURE_NEW
9610 && !structured_block
9611 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9612 code
= OMP_ATOMIC_CAPTURE_OLD
;
9615 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9616 && TREE_OPERAND (lhs
, 0)
9617 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9619 /* This is pre or post decrement. */
9620 rhs
= TREE_OPERAND (lhs
, 1);
9621 lhs
= TREE_OPERAND (lhs
, 0);
9623 if (code
== OMP_ATOMIC_CAPTURE_NEW
9624 && !structured_block
9625 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9626 code
= OMP_ATOMIC_CAPTURE_OLD
;
9632 switch (c_parser_peek_token (parser
)->type
)
9638 opcode
= TRUNC_DIV_EXPR
;
9644 opcode
= MINUS_EXPR
;
9647 opcode
= LSHIFT_EXPR
;
9650 opcode
= RSHIFT_EXPR
;
9653 opcode
= BIT_AND_EXPR
;
9656 opcode
= BIT_IOR_EXPR
;
9659 opcode
= BIT_XOR_EXPR
;
9662 if (structured_block
|| code
== OMP_ATOMIC
)
9664 location_t aloc
= c_parser_peek_token (parser
)->location
;
9666 enum c_parser_prec oprec
= PREC_NONE
;
9668 c_parser_consume_token (parser
);
9669 rhs1
= c_parser_unary_expression (parser
).value
;
9670 rhs1
= c_fully_fold (rhs1
, false, NULL
);
9671 if (rhs1
== error_mark_node
)
9673 switch (c_parser_peek_token (parser
)->type
)
9676 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9678 code
= OMP_ATOMIC_CAPTURE_OLD
;
9683 c_parser_consume_token (parser
);
9686 c_parser_error (parser
,
9687 "invalid form of %<#pragma omp atomic%>");
9694 opcode
= TRUNC_DIV_EXPR
;
9702 opcode
= MINUS_EXPR
;
9706 opcode
= LSHIFT_EXPR
;
9710 opcode
= RSHIFT_EXPR
;
9714 opcode
= BIT_AND_EXPR
;
9715 oprec
= PREC_BITAND
;
9718 opcode
= BIT_IOR_EXPR
;
9722 opcode
= BIT_XOR_EXPR
;
9723 oprec
= PREC_BITXOR
;
9726 c_parser_error (parser
,
9727 "invalid operator for %<#pragma omp atomic%>");
9731 c_parser_consume_token (parser
);
9732 rhs_loc
= c_parser_peek_token (parser
)->location
;
9733 if (commutative_tree_code (opcode
))
9734 oprec
= (enum c_parser_prec
) (oprec
- 1);
9735 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
9736 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
9738 rhs
= rhs_expr
.value
;
9739 rhs
= c_fully_fold (rhs
, false, NULL
);
9744 c_parser_error (parser
,
9745 "invalid operator for %<#pragma omp atomic%>");
9749 /* Arrange to pass the location of the assignment operator to
9750 c_finish_omp_atomic. */
9751 loc
= c_parser_peek_token (parser
)->location
;
9752 c_parser_consume_token (parser
);
9754 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9755 rhs_expr
= c_parser_expression (parser
);
9756 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9758 rhs
= rhs_expr
.value
;
9759 rhs
= c_fully_fold (rhs
, false, NULL
);
9763 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
9765 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
9767 v
= c_parser_unary_expression (parser
).value
;
9768 v
= c_fully_fold (v
, false, NULL
);
9769 if (v
== error_mark_node
)
9771 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9773 lhs1
= c_parser_unary_expression (parser
).value
;
9774 lhs1
= c_fully_fold (lhs1
, false, NULL
);
9775 if (lhs1
== error_mark_node
)
9778 if (structured_block
)
9780 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9781 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
9784 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
9785 if (stmt
!= error_mark_node
)
9788 if (!structured_block
)
9789 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9794 # pragma omp barrier new-line
9798 c_parser_omp_barrier (c_parser
*parser
)
9800 location_t loc
= c_parser_peek_token (parser
)->location
;
9801 c_parser_consume_pragma (parser
);
9802 c_parser_skip_to_pragma_eol (parser
);
9804 c_finish_omp_barrier (loc
);
9808 # pragma omp critical [(name)] new-line
9811 LOC is the location of the #pragma itself. */
9814 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9816 tree stmt
, name
= NULL
;
9818 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9820 c_parser_consume_token (parser
);
9821 if (c_parser_next_token_is (parser
, CPP_NAME
))
9823 name
= c_parser_peek_token (parser
)->value
;
9824 c_parser_consume_token (parser
);
9825 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9828 c_parser_error (parser
, "expected identifier");
9830 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9831 c_parser_error (parser
, "expected %<(%> or end of line");
9832 c_parser_skip_to_pragma_eol (parser
);
9834 stmt
= c_parser_omp_structured_block (parser
);
9835 return c_finish_omp_critical (loc
, stmt
, name
);
9839 # pragma omp flush flush-vars[opt] new-line
9842 ( variable-list ) */
9845 c_parser_omp_flush (c_parser
*parser
)
9847 location_t loc
= c_parser_peek_token (parser
)->location
;
9848 c_parser_consume_pragma (parser
);
9849 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9850 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9851 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9852 c_parser_error (parser
, "expected %<(%> or end of line");
9853 c_parser_skip_to_pragma_eol (parser
);
9855 c_finish_omp_flush (loc
);
9858 /* Parse the restricted form of the for statement allowed by OpenMP.
9859 The real trick here is to determine the loop control variable early
9860 so that we can push a new decl if necessary to make it private.
9861 LOC is the location of the OMP in "#pragma omp". */
9864 c_parser_omp_for_loop (location_t loc
,
9865 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
9867 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
9868 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
9869 bool fail
= false, open_brace_parsed
= false;
9870 int i
, collapse
= 1, nbraces
= 0;
9872 VEC(tree
,gc
) *for_block
= make_tree_vector ();
9874 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
9875 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
9876 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
9878 gcc_assert (collapse
>= 1);
9880 declv
= make_tree_vec (collapse
);
9881 initv
= make_tree_vec (collapse
);
9882 condv
= make_tree_vec (collapse
);
9883 incrv
= make_tree_vec (collapse
);
9885 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
9887 c_parser_error (parser
, "for statement expected");
9890 for_loc
= c_parser_peek_token (parser
)->location
;
9891 c_parser_consume_token (parser
);
9893 for (i
= 0; i
< collapse
; i
++)
9897 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9900 /* Parse the initialization declaration or expression. */
9901 if (c_parser_next_tokens_start_declaration (parser
))
9904 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
9905 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
9906 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
9909 if (DECL_INITIAL (decl
) == error_mark_node
)
9910 decl
= error_mark_node
;
9913 else if (c_parser_next_token_is (parser
, CPP_NAME
)
9914 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
9916 struct c_expr decl_exp
;
9917 struct c_expr init_exp
;
9918 location_t init_loc
;
9920 decl_exp
= c_parser_postfix_expression (parser
);
9921 decl
= decl_exp
.value
;
9923 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
9925 init_loc
= c_parser_peek_token (parser
)->location
;
9926 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
9927 init_exp
= default_function_array_read_conversion (init_loc
,
9929 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
9930 NOP_EXPR
, init_loc
, init_exp
.value
,
9931 init_exp
.original_type
);
9932 init
= c_process_expr_stmt (init_loc
, init
);
9934 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9939 c_parser_error (parser
,
9940 "expected iteration declaration or initialization");
9941 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9947 /* Parse the loop condition. */
9949 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
9951 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
9952 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
9955 cond
= cond_expr
.value
;
9956 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
9957 cond
= c_fully_fold (cond
, false, NULL
);
9958 switch (cond_expr
.original_code
)
9966 /* Can't be cond = error_mark_node, because we want to preserve
9967 the location until c_finish_omp_for. */
9968 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
9971 protected_set_expr_location (cond
, cond_loc
);
9973 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9975 /* Parse the increment expression. */
9977 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
9979 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
9981 incr
= c_process_expr_stmt (incr_loc
,
9982 c_parser_expression (parser
).value
);
9984 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9986 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
9990 TREE_VEC_ELT (declv
, i
) = decl
;
9991 TREE_VEC_ELT (initv
, i
) = init
;
9992 TREE_VEC_ELT (condv
, i
) = cond
;
9993 TREE_VEC_ELT (incrv
, i
) = incr
;
9997 if (i
== collapse
- 1)
10000 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10001 in between the collapsed for loops to be still considered perfectly
10002 nested. Hopefully the final version clarifies this.
10003 For now handle (multiple) {'s and empty statements. */
10006 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10008 c_parser_consume_token (parser
);
10011 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10013 c_parser_consume_token (parser
);
10016 else if (bracecount
10017 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10018 c_parser_consume_token (parser
);
10021 c_parser_error (parser
, "not enough perfectly nested loops");
10024 open_brace_parsed
= true;
10034 nbraces
+= bracecount
;
10037 save_break
= c_break_label
;
10038 c_break_label
= size_one_node
;
10039 save_cont
= c_cont_label
;
10040 c_cont_label
= NULL_TREE
;
10041 body
= push_stmt_list ();
10043 if (open_brace_parsed
)
10045 location_t here
= c_parser_peek_token (parser
)->location
;
10046 stmt
= c_begin_compound_stmt (true);
10047 c_parser_compound_statement_nostart (parser
);
10048 add_stmt (c_end_compound_stmt (here
, stmt
, true));
10051 add_stmt (c_parser_c99_block_statement (parser
));
10054 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
10055 SET_EXPR_LOCATION (t
, loc
);
10059 body
= pop_stmt_list (body
);
10060 c_break_label
= save_break
;
10061 c_cont_label
= save_cont
;
10065 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10067 c_parser_consume_token (parser
);
10070 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10071 c_parser_consume_token (parser
);
10074 c_parser_error (parser
, "collapsed loops not perfectly nested");
10077 location_t here
= c_parser_peek_token (parser
)->location
;
10078 stmt
= c_begin_compound_stmt (true);
10080 c_parser_compound_statement_nostart (parser
);
10081 body
= c_end_compound_stmt (here
, stmt
, true);
10088 /* Only bother calling c_finish_omp_for if we haven't already generated
10089 an error from the initialization parsing. */
10092 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
10095 if (par_clauses
!= NULL
)
10098 for (c
= par_clauses
; *c
; )
10099 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
10100 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
10101 c
= &OMP_CLAUSE_CHAIN (*c
);
10104 for (i
= 0; i
< collapse
; i
++)
10105 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
10108 c
= &OMP_CLAUSE_CHAIN (*c
);
10109 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
10112 "iteration variable %qD should not be firstprivate",
10113 OMP_CLAUSE_DECL (*c
));
10114 *c
= OMP_CLAUSE_CHAIN (*c
);
10118 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10119 change it to shared (decl) in
10120 OMP_PARALLEL_CLAUSES. */
10121 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
10122 OMP_CLAUSE_LASTPRIVATE
);
10123 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
10124 OMP_CLAUSE_CHAIN (l
) = clauses
;
10126 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
10130 OMP_FOR_CLAUSES (stmt
) = clauses
;
10135 while (!VEC_empty (tree
, for_block
))
10137 /* FIXME diagnostics: LOC below should be the actual location of
10138 this particular for block. We need to build a list of
10139 locations to go along with FOR_BLOCK. */
10140 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
10143 release_tree_vector (for_block
);
10148 #pragma omp for for-clause[optseq] new-line
10151 LOC is the location of the #pragma token.
10154 #define OMP_FOR_CLAUSE_MASK \
10155 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10156 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10157 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10158 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10159 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10160 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10161 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10162 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10165 c_parser_omp_for (location_t loc
, c_parser
*parser
)
10167 tree block
, clauses
, ret
;
10169 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
10170 "#pragma omp for");
10172 block
= c_begin_compound_stmt (true);
10173 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
10174 block
= c_end_compound_stmt (loc
, block
, true);
10181 # pragma omp master new-line
10184 LOC is the location of the #pragma token.
10188 c_parser_omp_master (location_t loc
, c_parser
*parser
)
10190 c_parser_skip_to_pragma_eol (parser
);
10191 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
10195 # pragma omp ordered new-line
10198 LOC is the location of the #pragma itself.
10202 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
10204 c_parser_skip_to_pragma_eol (parser
);
10205 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
10211 { section-sequence }
10214 section-directive[opt] structured-block
10215 section-sequence section-directive structured-block
10217 SECTIONS_LOC is the location of the #pragma omp sections. */
10220 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
10222 tree stmt
, substmt
;
10223 bool error_suppress
= false;
10226 loc
= c_parser_peek_token (parser
)->location
;
10227 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10229 /* Avoid skipping until the end of the block. */
10230 parser
->error
= false;
10234 stmt
= push_stmt_list ();
10236 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10238 substmt
= push_stmt_list ();
10242 c_parser_statement (parser
);
10244 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10246 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10248 if (c_parser_next_token_is (parser
, CPP_EOF
))
10252 substmt
= pop_stmt_list (substmt
);
10253 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10254 SET_EXPR_LOCATION (substmt
, loc
);
10255 add_stmt (substmt
);
10260 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10262 if (c_parser_next_token_is (parser
, CPP_EOF
))
10265 loc
= c_parser_peek_token (parser
)->location
;
10266 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10268 c_parser_consume_pragma (parser
);
10269 c_parser_skip_to_pragma_eol (parser
);
10270 error_suppress
= false;
10272 else if (!error_suppress
)
10274 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10275 error_suppress
= true;
10278 substmt
= c_parser_omp_structured_block (parser
);
10279 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10280 SET_EXPR_LOCATION (substmt
, loc
);
10281 add_stmt (substmt
);
10283 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10284 "expected %<#pragma omp section%> or %<}%>");
10286 substmt
= pop_stmt_list (stmt
);
10288 stmt
= make_node (OMP_SECTIONS
);
10289 SET_EXPR_LOCATION (stmt
, sections_loc
);
10290 TREE_TYPE (stmt
) = void_type_node
;
10291 OMP_SECTIONS_BODY (stmt
) = substmt
;
10293 return add_stmt (stmt
);
10297 # pragma omp sections sections-clause[optseq] newline
10300 LOC is the location of the #pragma token.
10303 #define OMP_SECTIONS_CLAUSE_MASK \
10304 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10305 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10306 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10307 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10308 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10311 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10313 tree block
, clauses
, ret
;
10315 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10316 "#pragma omp sections");
10318 block
= c_begin_compound_stmt (true);
10319 ret
= c_parser_omp_sections_scope (loc
, parser
);
10321 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10322 block
= c_end_compound_stmt (loc
, block
, true);
10329 # pragma parallel parallel-clause new-line
10330 # pragma parallel for parallel-for-clause new-line
10331 # pragma parallel sections parallel-sections-clause new-line
10333 LOC is the location of the #pragma token.
10336 #define OMP_PARALLEL_CLAUSE_MASK \
10337 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10338 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10339 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10340 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10341 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10342 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10343 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10344 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10347 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10349 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10350 const char *p_name
= "#pragma omp parallel";
10351 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10352 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10354 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10356 c_parser_consume_token (parser
);
10357 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10358 p_name
= "#pragma omp parallel for";
10359 mask
|= OMP_FOR_CLAUSE_MASK
;
10360 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10362 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10364 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10365 if (strcmp (p
, "sections") == 0)
10367 c_parser_consume_token (parser
);
10368 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10369 p_name
= "#pragma omp parallel sections";
10370 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10371 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10375 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10379 case PRAGMA_OMP_PARALLEL
:
10380 block
= c_begin_omp_parallel ();
10381 c_parser_statement (parser
);
10382 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10385 case PRAGMA_OMP_PARALLEL_FOR
:
10386 block
= c_begin_omp_parallel ();
10387 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10388 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10389 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10390 OMP_PARALLEL_COMBINED (stmt
) = 1;
10393 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10394 block
= c_begin_omp_parallel ();
10395 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10396 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10398 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10399 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10400 OMP_PARALLEL_COMBINED (stmt
) = 1;
10404 gcc_unreachable ();
10411 # pragma omp single single-clause[optseq] new-line
10414 LOC is the location of the #pragma.
10417 #define OMP_SINGLE_CLAUSE_MASK \
10418 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10419 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10420 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10421 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10424 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10426 tree stmt
= make_node (OMP_SINGLE
);
10427 SET_EXPR_LOCATION (stmt
, loc
);
10428 TREE_TYPE (stmt
) = void_type_node
;
10430 OMP_SINGLE_CLAUSES (stmt
)
10431 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10432 "#pragma omp single");
10433 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10435 return add_stmt (stmt
);
10439 # pragma omp task task-clause[optseq] new-line
10441 LOC is the location of the #pragma.
10444 #define OMP_TASK_CLAUSE_MASK \
10445 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10446 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10447 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10448 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10449 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10450 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10451 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10452 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10455 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10457 tree clauses
, block
;
10459 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10460 "#pragma omp task");
10462 block
= c_begin_omp_task ();
10463 c_parser_statement (parser
);
10464 return c_finish_omp_task (loc
, clauses
, block
);
10468 # pragma omp taskwait new-line
10472 c_parser_omp_taskwait (c_parser
*parser
)
10474 location_t loc
= c_parser_peek_token (parser
)->location
;
10475 c_parser_consume_pragma (parser
);
10476 c_parser_skip_to_pragma_eol (parser
);
10478 c_finish_omp_taskwait (loc
);
10482 # pragma omp taskyield new-line
10486 c_parser_omp_taskyield (c_parser
*parser
)
10488 location_t loc
= c_parser_peek_token (parser
)->location
;
10489 c_parser_consume_pragma (parser
);
10490 c_parser_skip_to_pragma_eol (parser
);
10492 c_finish_omp_taskyield (loc
);
10495 /* Main entry point to parsing most OpenMP pragmas. */
10498 c_parser_omp_construct (c_parser
*parser
)
10500 enum pragma_kind p_kind
;
10504 loc
= c_parser_peek_token (parser
)->location
;
10505 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
10506 c_parser_consume_pragma (parser
);
10510 case PRAGMA_OMP_ATOMIC
:
10511 c_parser_omp_atomic (loc
, parser
);
10513 case PRAGMA_OMP_CRITICAL
:
10514 stmt
= c_parser_omp_critical (loc
, parser
);
10516 case PRAGMA_OMP_FOR
:
10517 stmt
= c_parser_omp_for (loc
, parser
);
10519 case PRAGMA_OMP_MASTER
:
10520 stmt
= c_parser_omp_master (loc
, parser
);
10522 case PRAGMA_OMP_ORDERED
:
10523 stmt
= c_parser_omp_ordered (loc
, parser
);
10525 case PRAGMA_OMP_PARALLEL
:
10526 stmt
= c_parser_omp_parallel (loc
, parser
);
10528 case PRAGMA_OMP_SECTIONS
:
10529 stmt
= c_parser_omp_sections (loc
, parser
);
10531 case PRAGMA_OMP_SINGLE
:
10532 stmt
= c_parser_omp_single (loc
, parser
);
10534 case PRAGMA_OMP_TASK
:
10535 stmt
= c_parser_omp_task (loc
, parser
);
10538 gcc_unreachable ();
10542 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
10547 # pragma omp threadprivate (variable-list) */
10550 c_parser_omp_threadprivate (c_parser
*parser
)
10555 c_parser_consume_pragma (parser
);
10556 loc
= c_parser_peek_token (parser
)->location
;
10557 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10559 /* Mark every variable in VARS to be assigned thread local storage. */
10560 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
10562 tree v
= TREE_PURPOSE (t
);
10564 /* FIXME diagnostics: Ideally we should keep individual
10565 locations for all the variables in the var list to make the
10566 following errors more precise. Perhaps
10567 c_parser_omp_var_list_parens() should construct a list of
10568 locations to go along with the var list. */
10570 /* If V had already been marked threadprivate, it doesn't matter
10571 whether it had been used prior to this point. */
10572 if (TREE_CODE (v
) != VAR_DECL
)
10573 error_at (loc
, "%qD is not a variable", v
);
10574 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
10575 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
10576 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
10577 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
10578 else if (TREE_TYPE (v
) == error_mark_node
)
10580 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
10581 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
10584 if (! DECL_THREAD_LOCAL_P (v
))
10586 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
10587 /* If rtl has been already set for this var, call
10588 make_decl_rtl once again, so that encode_section_info
10589 has a chance to look at the new decl flags. */
10590 if (DECL_RTL_SET_P (v
))
10593 C_DECL_THREADPRIVATE_P (v
) = 1;
10597 c_parser_skip_to_pragma_eol (parser
);
10600 /* Parse a transaction attribute (GCC Extension).
10602 transaction-attribute:
10606 The transactional memory language description is written for C++,
10607 and uses the C++0x attribute syntax. For compatibility, allow the
10608 bracket style for transactions in C as well. */
10611 c_parser_transaction_attributes (c_parser
*parser
)
10613 tree attr_name
, attr
= NULL
;
10615 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10616 return c_parser_attributes (parser
);
10618 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10620 c_parser_consume_token (parser
);
10621 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
10624 attr_name
= c_parser_attribute_any_word (parser
);
10627 c_parser_consume_token (parser
);
10628 attr
= build_tree_list (attr_name
, NULL_TREE
);
10631 c_parser_error (parser
, "expected identifier");
10633 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10635 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10639 /* Parse a __transaction_atomic or __transaction_relaxed statement
10642 transaction-statement:
10643 __transaction_atomic transaction-attribute[opt] compound-statement
10644 __transaction_relaxed compound-statement
10646 Note that the only valid attribute is: "outer".
10650 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
10652 unsigned int old_in
= parser
->in_transaction
;
10653 unsigned int this_in
= 1, new_in
;
10654 location_t loc
= c_parser_peek_token (parser
)->location
;
10657 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10658 || keyword
== RID_TRANSACTION_RELAXED
)
10659 && c_parser_next_token_is_keyword (parser
, keyword
));
10660 c_parser_consume_token (parser
);
10662 if (keyword
== RID_TRANSACTION_RELAXED
)
10663 this_in
|= TM_STMT_ATTR_RELAXED
;
10666 attrs
= c_parser_transaction_attributes (parser
);
10668 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
10671 /* Keep track if we're in the lexical scope of an outer transaction. */
10672 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
10674 parser
->in_transaction
= new_in
;
10675 stmt
= c_parser_compound_statement (parser
);
10676 parser
->in_transaction
= old_in
;
10679 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
10681 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10682 "%<__transaction_atomic%> without transactional memory support enabled"
10683 : "%<__transaction_relaxed %> "
10684 "without transactional memory support enabled"));
10689 /* Parse a __transaction_atomic or __transaction_relaxed expression
10692 transaction-expression:
10693 __transaction_atomic ( expression )
10694 __transaction_relaxed ( expression )
10697 static struct c_expr
10698 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
10701 unsigned int old_in
= parser
->in_transaction
;
10702 unsigned int this_in
= 1;
10703 location_t loc
= c_parser_peek_token (parser
)->location
;
10706 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10707 || keyword
== RID_TRANSACTION_RELAXED
)
10708 && c_parser_next_token_is_keyword (parser
, keyword
));
10709 c_parser_consume_token (parser
);
10711 if (keyword
== RID_TRANSACTION_RELAXED
)
10712 this_in
|= TM_STMT_ATTR_RELAXED
;
10715 attrs
= c_parser_transaction_attributes (parser
);
10717 this_in
|= parse_tm_stmt_attr (attrs
, 0);
10720 parser
->in_transaction
= this_in
;
10721 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10723 tree expr
= c_parser_expression (parser
).value
;
10724 ret
.original_type
= TREE_TYPE (expr
);
10725 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
10726 if (this_in
& TM_STMT_ATTR_RELAXED
)
10727 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
10728 SET_EXPR_LOCATION (ret
.value
, loc
);
10729 ret
.original_code
= TRANSACTION_EXPR
;
10730 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10732 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
10739 ret
.value
= error_mark_node
;
10740 ret
.original_code
= ERROR_MARK
;
10741 ret
.original_type
= NULL
;
10743 parser
->in_transaction
= old_in
;
10746 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10747 "%<__transaction_atomic%> without transactional memory support enabled"
10748 : "%<__transaction_relaxed %> "
10749 "without transactional memory support enabled"));
10754 /* Parse a __transaction_cancel statement (GCC Extension).
10756 transaction-cancel-statement:
10757 __transaction_cancel transaction-attribute[opt] ;
10759 Note that the only valid attribute is "outer".
10763 c_parser_transaction_cancel(c_parser
*parser
)
10765 location_t loc
= c_parser_peek_token (parser
)->location
;
10767 bool is_outer
= false;
10769 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
10770 c_parser_consume_token (parser
);
10772 attrs
= c_parser_transaction_attributes (parser
);
10774 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
10778 error_at (loc
, "%<__transaction_cancel%> without "
10779 "transactional memory support enabled");
10782 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
10784 error_at (loc
, "%<__transaction_cancel%> within a "
10785 "%<__transaction_relaxed%>");
10790 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
10791 && !is_tm_may_cancel_outer (current_function_decl
))
10793 error_at (loc
, "outer %<__transaction_cancel%> not "
10794 "within outer %<__transaction_atomic%>");
10795 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
10799 else if (parser
->in_transaction
== 0)
10801 error_at (loc
, "%<__transaction_cancel%> not within "
10802 "%<__transaction_atomic%>");
10806 return add_stmt (build_tm_abort_call (loc
, is_outer
));
10809 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
10812 /* Parse a single source file. */
10815 c_parse_file (void)
10817 /* Use local storage to begin. If the first token is a pragma, parse it.
10818 If it is #pragma GCC pch_preprocess, then this will load a PCH file
10819 which will cause garbage collection. */
10822 memset (&tparser
, 0, sizeof tparser
);
10823 the_parser
= &tparser
;
10825 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
10826 c_parser_pragma_pch_preprocess (&tparser
);
10828 the_parser
= ggc_alloc_c_parser ();
10829 *the_parser
= tparser
;
10831 /* Initialize EH, if we've been told to do so. */
10832 if (flag_exceptions
)
10833 using_eh_for_cleanups ();
10835 c_parser_translation_unit (the_parser
);
10839 #include "gt-c-parser.h"