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 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 /* True if we are in a context where the Objective-C "Property attribute"
199 keywords are valid. */
200 BOOL_BITFIELD objc_property_attr_context
: 1;
204 /* The actual parser and external interface. ??? Does this need to be
205 garbage-collected? */
207 static GTY (()) c_parser
*the_parser
;
209 /* Read in and lex a single token, storing it in *TOKEN. */
212 c_lex_one_token (c_parser
*parser
, c_token
*token
)
214 timevar_push (TV_LEX
);
216 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
217 (parser
->lex_untranslated_string
218 ? C_LEX_STRING_NO_TRANSLATE
: 0));
219 token
->id_kind
= C_ID_NONE
;
220 token
->keyword
= RID_MAX
;
221 token
->pragma_kind
= PRAGMA_NONE
;
229 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
230 if (c_dialect_objc ())
231 parser
->objc_need_raw_identifier
= false;
233 if (C_IS_RESERVED_WORD (token
->value
))
235 enum rid rid_code
= C_RID_CODE (token
->value
);
237 if (rid_code
== RID_CXX_COMPAT_WARN
)
239 warning_at (token
->location
,
241 "identifier %qE conflicts with C++ keyword",
244 else if (rid_code
>= RID_FIRST_ADDR_SPACE
245 && rid_code
<= RID_LAST_ADDR_SPACE
)
247 token
->id_kind
= C_ID_ADDRSPACE
;
248 token
->keyword
= rid_code
;
251 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
253 /* We found an Objective-C "pq" keyword (in, out,
254 inout, bycopy, byref, oneway). They need special
255 care because the interpretation depends on the
257 if (parser
->objc_pq_context
)
259 token
->type
= CPP_KEYWORD
;
260 token
->keyword
= rid_code
;
263 else if (parser
->objc_could_be_foreach_context
264 && rid_code
== RID_IN
)
266 /* We are in Objective-C, inside a (potential)
267 foreach context (which means after having
268 parsed 'for (', but before having parsed ';'),
269 and we found 'in'. We consider it the keyword
270 which terminates the declaration at the
271 beginning of a foreach-statement. Note that
272 this means you can't use 'in' for anything else
273 in that context; in particular, in Objective-C
274 you can't use 'in' as the name of the running
275 variable in a C for loop. We could potentially
276 try to add code here to disambiguate, but it
277 seems a reasonable limitation. */
278 token
->type
= CPP_KEYWORD
;
279 token
->keyword
= rid_code
;
282 /* Else, "pq" keywords outside of the "pq" context are
283 not keywords, and we fall through to the code for
286 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
288 /* We found an Objective-C "property attribute"
289 keyword (getter, setter, readonly, etc). These are
290 only valid in the property context. */
291 if (parser
->objc_property_attr_context
)
293 token
->type
= CPP_KEYWORD
;
294 token
->keyword
= rid_code
;
297 /* Else they are not special keywords.
300 else if (c_dialect_objc ()
301 && (OBJC_IS_AT_KEYWORD (rid_code
)
302 || OBJC_IS_CXX_KEYWORD (rid_code
)))
304 /* We found one of the Objective-C "@" keywords (defs,
305 selector, synchronized, etc) or one of the
306 Objective-C "cxx" keywords (class, private,
307 protected, public, try, catch, throw) without a
308 preceding '@' sign. Do nothing and fall through to
309 the code for normal tokens (in C++ we would still
310 consider the CXX ones keywords, but not in C). */
315 token
->type
= CPP_KEYWORD
;
316 token
->keyword
= rid_code
;
321 decl
= lookup_name (token
->value
);
324 if (TREE_CODE (decl
) == TYPE_DECL
)
326 token
->id_kind
= C_ID_TYPENAME
;
330 else if (c_dialect_objc ())
332 tree objc_interface_decl
= objc_is_class_name (token
->value
);
333 /* Objective-C class names are in the same namespace as
334 variables and typedefs, and hence are shadowed by local
336 if (objc_interface_decl
337 && (!objc_force_identifier
|| global_bindings_p ()))
339 token
->value
= objc_interface_decl
;
340 token
->id_kind
= C_ID_CLASSNAME
;
344 token
->id_kind
= C_ID_ID
;
348 /* This only happens in Objective-C; it must be a keyword. */
349 token
->type
= CPP_KEYWORD
;
350 switch (C_RID_CODE (token
->value
))
352 /* Replace 'class' with '@class', 'private' with '@private',
353 etc. This prevents confusion with the C++ keyword
354 'class', and makes the tokens consistent with other
355 Objective-C 'AT' keywords. For example '@class' is
356 reported as RID_AT_CLASS which is consistent with
357 '@synchronized', which is reported as
360 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
361 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
362 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
363 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
364 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
365 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
366 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
367 default: token
->keyword
= C_RID_CODE (token
->value
);
372 case CPP_CLOSE_PAREN
:
374 /* These tokens may affect the interpretation of any identifiers
375 following, if doing Objective-C. */
376 if (c_dialect_objc ())
377 parser
->objc_need_raw_identifier
= false;
380 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
381 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
387 timevar_pop (TV_LEX
);
390 /* Return a pointer to the next token from PARSER, reading it in if
393 static inline c_token
*
394 c_parser_peek_token (c_parser
*parser
)
396 if (parser
->tokens_avail
== 0)
398 c_lex_one_token (parser
, &parser
->tokens
[0]);
399 parser
->tokens_avail
= 1;
401 return &parser
->tokens
[0];
404 /* Return true if the next token from PARSER has the indicated
408 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
410 return c_parser_peek_token (parser
)->type
== type
;
413 /* Return true if the next token from PARSER does not have the
417 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
419 return !c_parser_next_token_is (parser
, type
);
422 /* Return true if the next token from PARSER is the indicated
426 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
428 return c_parser_peek_token (parser
)->keyword
== keyword
;
431 /* Return a pointer to the next-but-one token from PARSER, reading it
432 in if necessary. The next token is already read in. */
435 c_parser_peek_2nd_token (c_parser
*parser
)
437 if (parser
->tokens_avail
>= 2)
438 return &parser
->tokens
[1];
439 gcc_assert (parser
->tokens_avail
== 1);
440 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
441 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
442 c_lex_one_token (parser
, &parser
->tokens
[1]);
443 parser
->tokens_avail
= 2;
444 return &parser
->tokens
[1];
447 /* Return true if TOKEN can start a type name,
450 c_token_starts_typename (c_token
*token
)
455 switch (token
->id_kind
)
464 gcc_assert (c_dialect_objc ());
470 switch (token
->keyword
)
503 if (c_dialect_objc ())
511 enum c_lookahead_kind
{
512 /* Always treat unknown identifiers as typenames. */
515 /* Could be parsing a nonabstract declarator. Only treat an identifier
516 as a typename if followed by another identifier or a star. */
517 cla_nonabstract_decl
,
519 /* Never treat identifiers as typenames. */
523 /* Return true if the next token from PARSER can start a type name,
524 false otherwise. LA specifies how to do lookahead in order to
525 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
528 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
530 c_token
*token
= c_parser_peek_token (parser
);
531 if (c_token_starts_typename (token
))
534 /* Try a bit harder to detect an unknown typename. */
535 if (la
!= cla_prefer_id
536 && token
->type
== CPP_NAME
537 && token
->id_kind
== C_ID_ID
539 /* Do not try too hard when we could have "object in array". */
540 && !parser
->objc_could_be_foreach_context
542 && (la
== cla_prefer_type
543 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
544 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
546 /* Only unknown identifiers. */
547 && !lookup_name (token
->value
))
553 /* Return true if TOKEN is a type qualifier, false otherwise. */
555 c_token_is_qualifier (c_token
*token
)
560 switch (token
->id_kind
)
568 switch (token
->keyword
)
585 /* Return true if the next token from PARSER is a type qualifier,
588 c_parser_next_token_is_qualifier (c_parser
*parser
)
590 c_token
*token
= c_parser_peek_token (parser
);
591 return c_token_is_qualifier (token
);
594 /* Return true if TOKEN can start declaration specifiers, false
597 c_token_starts_declspecs (c_token
*token
)
602 switch (token
->id_kind
)
611 gcc_assert (c_dialect_objc ());
617 switch (token
->keyword
)
657 if (c_dialect_objc ())
666 /* Return true if TOKEN can start declaration specifiers or a static
667 assertion, false otherwise. */
669 c_token_starts_declaration (c_token
*token
)
671 if (c_token_starts_declspecs (token
)
672 || token
->keyword
== RID_STATIC_ASSERT
)
678 /* Return true if the next token from PARSER can start declaration
679 specifiers, false otherwise. */
681 c_parser_next_token_starts_declspecs (c_parser
*parser
)
683 c_token
*token
= c_parser_peek_token (parser
);
685 /* In Objective-C, a classname normally starts a declspecs unless it
686 is immediately followed by a dot. In that case, it is the
687 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
688 setter/getter on the class. c_token_starts_declspecs() can't
689 differentiate between the two cases because it only checks the
690 current token, so we have a special check here. */
691 if (c_dialect_objc ()
692 && token
->type
== CPP_NAME
693 && token
->id_kind
== C_ID_CLASSNAME
694 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
697 return c_token_starts_declspecs (token
);
700 /* Return true if the next tokens from PARSER can start declaration
701 specifiers or a static assertion, false otherwise. */
703 c_parser_next_tokens_start_declaration (c_parser
*parser
)
705 c_token
*token
= c_parser_peek_token (parser
);
708 if (c_dialect_objc ()
709 && token
->type
== CPP_NAME
710 && token
->id_kind
== C_ID_CLASSNAME
711 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
714 /* Labels do not start declarations. */
715 if (token
->type
== CPP_NAME
716 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
719 if (c_token_starts_declaration (token
))
722 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
728 /* Consume the next token from PARSER. */
731 c_parser_consume_token (c_parser
*parser
)
733 gcc_assert (parser
->tokens_avail
>= 1);
734 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
735 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
736 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
737 if (parser
->tokens_avail
== 2)
738 parser
->tokens
[0] = parser
->tokens
[1];
739 parser
->tokens_avail
--;
742 /* Expect the current token to be a #pragma. Consume it and remember
743 that we've begun parsing a pragma. */
746 c_parser_consume_pragma (c_parser
*parser
)
748 gcc_assert (!parser
->in_pragma
);
749 gcc_assert (parser
->tokens_avail
>= 1);
750 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
751 if (parser
->tokens_avail
== 2)
752 parser
->tokens
[0] = parser
->tokens
[1];
753 parser
->tokens_avail
--;
754 parser
->in_pragma
= true;
757 /* Update the globals input_location and in_system_header from
760 c_parser_set_source_position_from_token (c_token
*token
)
762 if (token
->type
!= CPP_EOF
)
764 input_location
= token
->location
;
768 /* Issue a diagnostic of the form
769 FILE:LINE: MESSAGE before TOKEN
770 where TOKEN is the next token in the input stream of PARSER.
771 MESSAGE (specified by the caller) is usually of the form "expected
774 Do not issue a diagnostic if still recovering from an error.
776 ??? This is taken from the C++ parser, but building up messages in
777 this way is not i18n-friendly and some other approach should be
781 c_parser_error (c_parser
*parser
, const char *gmsgid
)
783 c_token
*token
= c_parser_peek_token (parser
);
786 parser
->error
= true;
789 /* This diagnostic makes more sense if it is tagged to the line of
790 the token we just peeked at. */
791 c_parser_set_source_position_from_token (token
);
792 c_parse_error (gmsgid
,
793 /* Because c_parse_error does not understand
794 CPP_KEYWORD, keywords are treated like
796 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
797 /* ??? The C parser does not save the cpp flags of a
798 token, we need to pass 0 here and we will not get
799 the source spelling of some tokens but rather the
800 canonical spelling. */
801 token
->value
, /*flags=*/0);
804 /* If the next token is of the indicated TYPE, consume it. Otherwise,
805 issue the error MSGID. If MSGID is NULL then a message has already
806 been produced and no message will be produced this time. Returns
807 true if found, false otherwise. */
810 c_parser_require (c_parser
*parser
,
814 if (c_parser_next_token_is (parser
, type
))
816 c_parser_consume_token (parser
);
821 c_parser_error (parser
, msgid
);
826 /* If the next token is the indicated keyword, consume it. Otherwise,
827 issue the error MSGID. Returns true if found, false otherwise. */
830 c_parser_require_keyword (c_parser
*parser
,
834 if (c_parser_next_token_is_keyword (parser
, keyword
))
836 c_parser_consume_token (parser
);
841 c_parser_error (parser
, msgid
);
846 /* Like c_parser_require, except that tokens will be skipped until the
847 desired token is found. An error message is still produced if the
848 next token is not as expected. If MSGID is NULL then a message has
849 already been produced and no message will be produced this
853 c_parser_skip_until_found (c_parser
*parser
,
857 unsigned nesting_depth
= 0;
859 if (c_parser_require (parser
, type
, msgid
))
862 /* Skip tokens until the desired token is found. */
865 /* Peek at the next token. */
866 c_token
*token
= c_parser_peek_token (parser
);
867 /* If we've reached the token we want, consume it and stop. */
868 if (token
->type
== type
&& !nesting_depth
)
870 c_parser_consume_token (parser
);
874 /* If we've run out of tokens, stop. */
875 if (token
->type
== CPP_EOF
)
877 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
879 if (token
->type
== CPP_OPEN_BRACE
880 || token
->type
== CPP_OPEN_PAREN
881 || token
->type
== CPP_OPEN_SQUARE
)
883 else if (token
->type
== CPP_CLOSE_BRACE
884 || token
->type
== CPP_CLOSE_PAREN
885 || token
->type
== CPP_CLOSE_SQUARE
)
887 if (nesting_depth
-- == 0)
890 /* Consume this token. */
891 c_parser_consume_token (parser
);
893 parser
->error
= false;
896 /* Skip tokens until the end of a parameter is found, but do not
897 consume the comma, semicolon or closing delimiter. */
900 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
902 unsigned nesting_depth
= 0;
906 c_token
*token
= c_parser_peek_token (parser
);
907 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
910 /* If we've run out of tokens, stop. */
911 if (token
->type
== CPP_EOF
)
913 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
915 if (token
->type
== CPP_OPEN_BRACE
916 || token
->type
== CPP_OPEN_PAREN
917 || token
->type
== CPP_OPEN_SQUARE
)
919 else if (token
->type
== CPP_CLOSE_BRACE
920 || token
->type
== CPP_CLOSE_PAREN
921 || token
->type
== CPP_CLOSE_SQUARE
)
923 if (nesting_depth
-- == 0)
926 /* Consume this token. */
927 c_parser_consume_token (parser
);
929 parser
->error
= false;
932 /* Expect to be at the end of the pragma directive and consume an
933 end of line marker. */
936 c_parser_skip_to_pragma_eol (c_parser
*parser
)
938 gcc_assert (parser
->in_pragma
);
939 parser
->in_pragma
= false;
941 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
944 c_token
*token
= c_parser_peek_token (parser
);
945 if (token
->type
== CPP_EOF
)
947 if (token
->type
== CPP_PRAGMA_EOL
)
949 c_parser_consume_token (parser
);
952 c_parser_consume_token (parser
);
955 parser
->error
= false;
958 /* Skip tokens until we have consumed an entire block, or until we
959 have consumed a non-nested ';'. */
962 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
964 unsigned nesting_depth
= 0;
965 bool save_error
= parser
->error
;
971 /* Peek at the next token. */
972 token
= c_parser_peek_token (parser
);
980 if (parser
->in_pragma
)
985 /* If the next token is a ';', we have reached the
986 end of the statement. */
989 /* Consume the ';'. */
990 c_parser_consume_token (parser
);
995 case CPP_CLOSE_BRACE
:
996 /* If the next token is a non-nested '}', then we have
997 reached the end of the current block. */
998 if (nesting_depth
== 0 || --nesting_depth
== 0)
1000 c_parser_consume_token (parser
);
1005 case CPP_OPEN_BRACE
:
1006 /* If it the next token is a '{', then we are entering a new
1007 block. Consume the entire block. */
1012 /* If we see a pragma, consume the whole thing at once. We
1013 have some safeguards against consuming pragmas willy-nilly.
1014 Normally, we'd expect to be here with parser->error set,
1015 which disables these safeguards. But it's possible to get
1016 here for secondary error recovery, after parser->error has
1018 c_parser_consume_pragma (parser
);
1019 c_parser_skip_to_pragma_eol (parser
);
1020 parser
->error
= save_error
;
1027 c_parser_consume_token (parser
);
1031 parser
->error
= false;
1034 /* CPP's options (initialized by c-opts.c). */
1035 extern cpp_options
*cpp_opts
;
1037 /* Save the warning flags which are controlled by __extension__. */
1040 disable_extension_diagnostics (void)
1043 | (warn_pointer_arith
<< 1)
1044 | (warn_traditional
<< 2)
1046 | (warn_long_long
<< 4)
1047 | (warn_cxx_compat
<< 5)
1048 | (warn_overlength_strings
<< 6));
1049 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1050 warn_pointer_arith
= 0;
1051 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1053 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1054 warn_cxx_compat
= 0;
1055 warn_overlength_strings
= 0;
1059 /* Restore the warning flags which are controlled by __extension__.
1060 FLAGS is the return value from disable_extension_diagnostics. */
1063 restore_extension_diagnostics (int flags
)
1065 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1066 warn_pointer_arith
= (flags
>> 1) & 1;
1067 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1068 flag_iso
= (flags
>> 3) & 1;
1069 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1070 warn_cxx_compat
= (flags
>> 5) & 1;
1071 warn_overlength_strings
= (flags
>> 6) & 1;
1074 /* Possibly kinds of declarator to parse. */
1075 typedef enum c_dtr_syn
{
1076 /* A normal declarator with an identifier. */
1078 /* An abstract declarator (maybe empty). */
1080 /* A parameter declarator: may be either, but after a type name does
1081 not redeclare a typedef name as an identifier if it can
1082 alternatively be interpreted as a typedef name; see DR#009,
1083 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1084 following DR#249. For example, given a typedef T, "int T" and
1085 "int *T" are valid parameter declarations redeclaring T, while
1086 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1087 abstract declarators rather than involving redundant parentheses;
1088 the same applies with attributes inside the parentheses before
1093 /* The binary operation precedence levels, where 0 is a dummy lowest level
1094 used for the bottom of the stack. */
1095 enum c_parser_prec
{
1110 static void c_parser_external_declaration (c_parser
*);
1111 static void c_parser_asm_definition (c_parser
*);
1112 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1113 bool, bool, tree
*);
1114 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1115 static void c_parser_static_assert_declaration (c_parser
*);
1116 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1117 bool, enum c_lookahead_kind
);
1118 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1119 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1120 static tree
c_parser_struct_declaration (c_parser
*);
1121 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1122 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1124 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1126 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1128 struct c_declarator
*);
1129 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1130 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1132 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1133 static tree
c_parser_simple_asm_expr (c_parser
*);
1134 static tree
c_parser_attributes (c_parser
*);
1135 static struct c_type_name
*c_parser_type_name (c_parser
*);
1136 static struct c_expr
c_parser_initializer (c_parser
*);
1137 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1138 static void c_parser_initelt (c_parser
*, struct obstack
*);
1139 static void c_parser_initval (c_parser
*, struct c_expr
*,
1141 static tree
c_parser_compound_statement (c_parser
*);
1142 static void c_parser_compound_statement_nostart (c_parser
*);
1143 static void c_parser_label (c_parser
*);
1144 static void c_parser_statement (c_parser
*);
1145 static void c_parser_statement_after_labels (c_parser
*);
1146 static void c_parser_if_statement (c_parser
*);
1147 static void c_parser_switch_statement (c_parser
*);
1148 static void c_parser_while_statement (c_parser
*);
1149 static void c_parser_do_statement (c_parser
*);
1150 static void c_parser_for_statement (c_parser
*);
1151 static tree
c_parser_asm_statement (c_parser
*);
1152 static tree
c_parser_asm_operands (c_parser
*, bool);
1153 static tree
c_parser_asm_goto_operands (c_parser
*);
1154 static tree
c_parser_asm_clobbers (c_parser
*);
1155 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1156 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1158 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1159 enum c_parser_prec
);
1160 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1161 static struct c_expr
c_parser_unary_expression (c_parser
*);
1162 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1163 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1164 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1165 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1166 struct c_type_name
*,
1168 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1171 static struct c_expr
c_parser_expression (c_parser
*);
1172 static struct c_expr
c_parser_expression_conv (c_parser
*);
1173 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
1175 static void c_parser_omp_construct (c_parser
*);
1176 static void c_parser_omp_threadprivate (c_parser
*);
1177 static void c_parser_omp_barrier (c_parser
*);
1178 static void c_parser_omp_flush (c_parser
*);
1179 static void c_parser_omp_taskwait (c_parser
*);
1180 static void c_parser_omp_taskyield (c_parser
*);
1182 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1183 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1185 /* These Objective-C parser functions are only ever called when
1186 compiling Objective-C. */
1187 static void c_parser_objc_class_definition (c_parser
*, tree
);
1188 static void c_parser_objc_class_instance_variables (c_parser
*);
1189 static void c_parser_objc_class_declaration (c_parser
*);
1190 static void c_parser_objc_alias_declaration (c_parser
*);
1191 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1192 static bool c_parser_objc_method_type (c_parser
*);
1193 static void c_parser_objc_method_definition (c_parser
*);
1194 static void c_parser_objc_methodprotolist (c_parser
*);
1195 static void c_parser_objc_methodproto (c_parser
*);
1196 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1197 static tree
c_parser_objc_type_name (c_parser
*);
1198 static tree
c_parser_objc_protocol_refs (c_parser
*);
1199 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1200 static void c_parser_objc_synchronized_statement (c_parser
*);
1201 static tree
c_parser_objc_selector (c_parser
*);
1202 static tree
c_parser_objc_selector_arg (c_parser
*);
1203 static tree
c_parser_objc_receiver (c_parser
*);
1204 static tree
c_parser_objc_message_args (c_parser
*);
1205 static tree
c_parser_objc_keywordexpr (c_parser
*);
1206 static void c_parser_objc_at_property_declaration (c_parser
*);
1207 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1208 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1209 static bool c_parser_objc_diagnose_bad_element_prefix
1210 (c_parser
*, struct c_declspecs
*);
1212 /* Parse a translation unit (C90 6.7, C99 6.9).
1215 external-declarations
1217 external-declarations:
1218 external-declaration
1219 external-declarations external-declaration
1228 c_parser_translation_unit (c_parser
*parser
)
1230 if (c_parser_next_token_is (parser
, CPP_EOF
))
1232 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1233 "ISO C forbids an empty translation unit");
1237 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1238 mark_valid_location_for_stdc_pragma (false);
1242 c_parser_external_declaration (parser
);
1243 obstack_free (&parser_obstack
, obstack_position
);
1245 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1249 /* Parse an external declaration (C90 6.7, C99 6.9).
1251 external-declaration:
1257 external-declaration:
1260 __extension__ external-declaration
1264 external-declaration:
1265 objc-class-definition
1266 objc-class-declaration
1267 objc-alias-declaration
1268 objc-protocol-definition
1269 objc-method-definition
1274 c_parser_external_declaration (c_parser
*parser
)
1277 switch (c_parser_peek_token (parser
)->type
)
1280 switch (c_parser_peek_token (parser
)->keyword
)
1283 ext
= disable_extension_diagnostics ();
1284 c_parser_consume_token (parser
);
1285 c_parser_external_declaration (parser
);
1286 restore_extension_diagnostics (ext
);
1289 c_parser_asm_definition (parser
);
1291 case RID_AT_INTERFACE
:
1292 case RID_AT_IMPLEMENTATION
:
1293 gcc_assert (c_dialect_objc ());
1294 c_parser_objc_class_definition (parser
, NULL_TREE
);
1297 gcc_assert (c_dialect_objc ());
1298 c_parser_objc_class_declaration (parser
);
1301 gcc_assert (c_dialect_objc ());
1302 c_parser_objc_alias_declaration (parser
);
1304 case RID_AT_PROTOCOL
:
1305 gcc_assert (c_dialect_objc ());
1306 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1308 case RID_AT_PROPERTY
:
1309 gcc_assert (c_dialect_objc ());
1310 c_parser_objc_at_property_declaration (parser
);
1312 case RID_AT_SYNTHESIZE
:
1313 gcc_assert (c_dialect_objc ());
1314 c_parser_objc_at_synthesize_declaration (parser
);
1316 case RID_AT_DYNAMIC
:
1317 gcc_assert (c_dialect_objc ());
1318 c_parser_objc_at_dynamic_declaration (parser
);
1321 gcc_assert (c_dialect_objc ());
1322 c_parser_consume_token (parser
);
1323 objc_finish_implementation ();
1330 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1331 "ISO C does not allow extra %<;%> outside of a function");
1332 c_parser_consume_token (parser
);
1335 mark_valid_location_for_stdc_pragma (true);
1336 c_parser_pragma (parser
, pragma_external
);
1337 mark_valid_location_for_stdc_pragma (false);
1341 if (c_dialect_objc ())
1343 c_parser_objc_method_definition (parser
);
1346 /* Else fall through, and yield a syntax error trying to parse
1347 as a declaration or function definition. */
1350 /* A declaration or a function definition (or, in Objective-C,
1351 an @interface or @protocol with prefix attributes). We can
1352 only tell which after parsing the declaration specifiers, if
1353 any, and the first declarator. */
1354 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1359 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1360 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1361 accepted; otherwise (old-style parameter declarations) only other
1362 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1363 assertion is accepted; otherwise (old-style parameter declarations)
1364 it is not. If NESTED is true, we are inside a function or parsing
1365 old-style parameter declarations; any functions encountered are
1366 nested functions and declaration specifiers are required; otherwise
1367 we are at top level and functions are normal functions and
1368 declaration specifiers may be optional. If EMPTY_OK is true, empty
1369 declarations are OK (subject to all other constraints); otherwise
1370 (old-style parameter declarations) they are diagnosed. If
1371 START_ATTR_OK is true, the declaration specifiers may start with
1372 attributes; otherwise they may not.
1373 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1374 declaration when parsing an Objective-C foreach statement.
1377 declaration-specifiers init-declarator-list[opt] ;
1378 static_assert-declaration
1380 function-definition:
1381 declaration-specifiers[opt] declarator declaration-list[opt]
1386 declaration-list declaration
1388 init-declarator-list:
1390 init-declarator-list , init-declarator
1393 declarator simple-asm-expr[opt] attributes[opt]
1394 declarator simple-asm-expr[opt] attributes[opt] = initializer
1398 nested-function-definition:
1399 declaration-specifiers declarator declaration-list[opt]
1403 attributes objc-class-definition
1404 attributes objc-category-definition
1405 attributes objc-protocol-definition
1407 The simple-asm-expr and attributes are GNU extensions.
1409 This function does not handle __extension__; that is handled in its
1410 callers. ??? Following the old parser, __extension__ may start
1411 external declarations, declarations in functions and declarations
1412 at the start of "for" loops, but not old-style parameter
1415 C99 requires declaration specifiers in a function definition; the
1416 absence is diagnosed through the diagnosis of implicit int. In GNU
1417 C we also allow but diagnose declarations without declaration
1418 specifiers, but only at top level (elsewhere they conflict with
1421 In Objective-C, declarations of the looping variable in a foreach
1422 statement are exceptionally terminated by 'in' (for example, 'for
1423 (NSObject *object in array) { ... }').
1428 threadprivate-directive */
1431 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1432 bool static_assert_ok
, bool empty_ok
,
1433 bool nested
, bool start_attr_ok
,
1434 tree
*objc_foreach_object_declaration
)
1436 struct c_declspecs
*specs
;
1438 tree all_prefix_attrs
;
1439 bool diagnosed_no_specs
= false;
1440 location_t here
= c_parser_peek_token (parser
)->location
;
1442 if (static_assert_ok
1443 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1445 c_parser_static_assert_declaration (parser
);
1448 specs
= build_null_declspecs ();
1450 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1451 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1452 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1453 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1454 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1455 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1457 error_at (here
, "unknown type name %qE",
1458 c_parser_peek_token (parser
)->value
);
1460 /* Parse declspecs normally to get a correct pointer type, but avoid
1461 a further "fails to be a type name" error. Refuse nested functions
1462 since it is not how the user likely wants us to recover. */
1463 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1464 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1465 c_parser_peek_token (parser
)->value
= error_mark_node
;
1469 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1472 c_parser_skip_to_end_of_block_or_statement (parser
);
1475 if (nested
&& !specs
->declspecs_seen_p
)
1477 c_parser_error (parser
, "expected declaration specifiers");
1478 c_parser_skip_to_end_of_block_or_statement (parser
);
1481 finish_declspecs (specs
);
1482 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1488 shadow_tag_warned (specs
, 1);
1489 pedwarn (here
, 0, "empty declaration");
1491 c_parser_consume_token (parser
);
1495 /* Provide better error recovery. Note that a type name here is usually
1496 better diagnosed as a redeclaration. */
1498 && specs
->typespec_kind
== ctsk_tagdef
1499 && c_parser_next_token_starts_declspecs (parser
)
1500 && !c_parser_next_token_is (parser
, CPP_NAME
))
1502 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1503 parser
->error
= false;
1504 shadow_tag_warned (specs
, 1);
1507 else if (c_dialect_objc ())
1509 /* Prefix attributes are an error on method decls. */
1510 switch (c_parser_peek_token (parser
)->type
)
1514 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1518 warning_at (c_parser_peek_token (parser
)->location
,
1520 "prefix attributes are ignored for methods");
1521 specs
->attrs
= NULL_TREE
;
1524 c_parser_objc_method_definition (parser
);
1526 c_parser_objc_methodproto (parser
);
1532 /* This is where we parse 'attributes @interface ...',
1533 'attributes @implementation ...', 'attributes @protocol ...'
1534 (where attributes could be, for example, __attribute__
1537 switch (c_parser_peek_token (parser
)->keyword
)
1539 case RID_AT_INTERFACE
:
1541 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1543 c_parser_objc_class_definition (parser
, specs
->attrs
);
1547 case RID_AT_IMPLEMENTATION
:
1549 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1553 warning_at (c_parser_peek_token (parser
)->location
,
1555 "prefix attributes are ignored for implementations");
1556 specs
->attrs
= NULL_TREE
;
1558 c_parser_objc_class_definition (parser
, NULL_TREE
);
1562 case RID_AT_PROTOCOL
:
1564 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1566 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1573 case RID_AT_PROPERTY
:
1576 c_parser_error (parser
, "unexpected attribute");
1577 specs
->attrs
= NULL
;
1585 pending_xref_error ();
1586 prefix_attrs
= specs
->attrs
;
1587 all_prefix_attrs
= prefix_attrs
;
1588 specs
->attrs
= NULL_TREE
;
1591 struct c_declarator
*declarator
;
1595 /* Declaring either one or more declarators (in which case we
1596 should diagnose if there were no declaration specifiers) or a
1597 function definition (in which case the diagnostic for
1598 implicit int suffices). */
1599 declarator
= c_parser_declarator (parser
,
1600 specs
->typespec_kind
!= ctsk_none
,
1601 C_DTR_NORMAL
, &dummy
);
1602 if (declarator
== NULL
)
1604 c_parser_skip_to_end_of_block_or_statement (parser
);
1607 if (c_parser_next_token_is (parser
, CPP_EQ
)
1608 || c_parser_next_token_is (parser
, CPP_COMMA
)
1609 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1610 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1611 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1612 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1614 tree asm_name
= NULL_TREE
;
1615 tree postfix_attrs
= NULL_TREE
;
1616 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1618 diagnosed_no_specs
= true;
1619 pedwarn (here
, 0, "data definition has no type or storage class");
1621 /* Having seen a data definition, there cannot now be a
1622 function definition. */
1624 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1625 asm_name
= c_parser_simple_asm_expr (parser
);
1626 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1627 postfix_attrs
= c_parser_attributes (parser
);
1628 if (c_parser_next_token_is (parser
, CPP_EQ
))
1632 location_t init_loc
;
1633 c_parser_consume_token (parser
);
1634 /* The declaration of the variable is in effect while
1635 its initializer is parsed. */
1636 d
= start_decl (declarator
, specs
, true,
1637 chainon (postfix_attrs
, all_prefix_attrs
));
1639 d
= error_mark_node
;
1640 start_init (d
, asm_name
, global_bindings_p ());
1641 init_loc
= c_parser_peek_token (parser
)->location
;
1642 init
= c_parser_initializer (parser
);
1644 if (d
!= error_mark_node
)
1646 maybe_warn_string_init (TREE_TYPE (d
), init
);
1647 finish_decl (d
, init_loc
, init
.value
,
1648 init
.original_type
, asm_name
);
1653 tree d
= start_decl (declarator
, specs
, false,
1654 chainon (postfix_attrs
,
1657 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1658 NULL_TREE
, asm_name
);
1660 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1663 *objc_foreach_object_declaration
= d
;
1665 *objc_foreach_object_declaration
= error_mark_node
;
1668 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1670 c_parser_consume_token (parser
);
1671 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1672 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1675 all_prefix_attrs
= prefix_attrs
;
1678 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1680 c_parser_consume_token (parser
);
1683 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1685 /* This can only happen in Objective-C: we found the
1686 'in' that terminates the declaration inside an
1687 Objective-C foreach statement. Do not consume the
1688 token, so that the caller can use it to determine
1689 that this indeed is a foreach context. */
1694 c_parser_error (parser
, "expected %<,%> or %<;%>");
1695 c_parser_skip_to_end_of_block_or_statement (parser
);
1701 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1702 "%<asm%> or %<__attribute__%>");
1703 c_parser_skip_to_end_of_block_or_statement (parser
);
1706 /* Function definition (nested or otherwise). */
1709 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1710 c_push_function_context ();
1712 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1714 /* This can appear in many cases looking nothing like a
1715 function definition, so we don't give a more specific
1716 error suggesting there was one. */
1717 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1718 "or %<__attribute__%>");
1720 c_pop_function_context ();
1724 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1725 tv
= TV_PARSE_INLINE
;
1730 /* Parse old-style parameter declarations. ??? Attributes are
1731 not allowed to start declaration specifiers here because of a
1732 syntax conflict between a function declaration with attribute
1733 suffix and a function definition with an attribute prefix on
1734 first old-style parameter declaration. Following the old
1735 parser, they are not accepted on subsequent old-style
1736 parameter declarations either. However, there is no
1737 ambiguity after the first declaration, nor indeed on the
1738 first as long as we don't allow postfix attributes after a
1739 declarator with a nonempty identifier list in a definition;
1740 and postfix attributes have never been accepted here in
1741 function definitions either. */
1742 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1743 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1744 c_parser_declaration_or_fndef (parser
, false, false, false,
1746 store_parm_decls ();
1747 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1748 = c_parser_peek_token (parser
)->location
;
1749 fnbody
= c_parser_compound_statement (parser
);
1752 tree decl
= current_function_decl
;
1753 /* Mark nested functions as needing static-chain initially.
1754 lower_nested_functions will recompute it but the
1755 DECL_STATIC_CHAIN flag is also used before that happens,
1756 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1757 DECL_STATIC_CHAIN (decl
) = 1;
1760 c_pop_function_context ();
1761 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1774 /* Parse an asm-definition (asm() outside a function body). This is a
1782 c_parser_asm_definition (c_parser
*parser
)
1784 tree asm_str
= c_parser_simple_asm_expr (parser
);
1786 cgraph_add_asm_node (asm_str
);
1787 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1790 /* Parse a static assertion (C1X N1425 6.7.10).
1792 static_assert-declaration:
1793 static_assert-declaration-no-semi ;
1797 c_parser_static_assert_declaration (c_parser
*parser
)
1799 c_parser_static_assert_declaration_no_semi (parser
);
1801 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1802 c_parser_skip_to_end_of_block_or_statement (parser
);
1805 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1808 static_assert-declaration-no-semi:
1809 _Static_assert ( constant-expression , string-literal )
1813 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1815 location_t assert_loc
, value_loc
;
1819 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1820 assert_loc
= c_parser_peek_token (parser
)->location
;
1824 pedwarn (assert_loc
, OPT_pedantic
,
1825 "ISO C99 does not support %<_Static_assert%>");
1827 pedwarn (assert_loc
, OPT_pedantic
,
1828 "ISO C90 does not support %<_Static_assert%>");
1830 c_parser_consume_token (parser
);
1831 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1833 value_loc
= c_parser_peek_token (parser
)->location
;
1834 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1835 parser
->lex_untranslated_string
= true;
1836 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1838 parser
->lex_untranslated_string
= false;
1841 switch (c_parser_peek_token (parser
)->type
)
1847 case CPP_UTF8STRING
:
1848 string
= c_parser_peek_token (parser
)->value
;
1849 c_parser_consume_token (parser
);
1850 parser
->lex_untranslated_string
= false;
1853 c_parser_error (parser
, "expected string literal");
1854 parser
->lex_untranslated_string
= false;
1857 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1859 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1861 error_at (value_loc
, "expression in static assertion is not an integer");
1864 if (TREE_CODE (value
) != INTEGER_CST
)
1866 value
= c_fully_fold (value
, false, NULL
);
1867 if (TREE_CODE (value
) == INTEGER_CST
)
1868 pedwarn (value_loc
, OPT_pedantic
, "expression in static assertion "
1869 "is not an integer constant expression");
1871 if (TREE_CODE (value
) != INTEGER_CST
)
1873 error_at (value_loc
, "expression in static assertion is not constant");
1876 constant_expression_warning (value
);
1877 if (integer_zerop (value
))
1878 error_at (assert_loc
, "static assertion failed: %E", string
);
1881 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1882 6.7), adding them to SPECS (which may already include some).
1883 Storage class specifiers are accepted iff SCSPEC_OK; type
1884 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1885 the start iff START_ATTR_OK.
1887 declaration-specifiers:
1888 storage-class-specifier declaration-specifiers[opt]
1889 type-specifier declaration-specifiers[opt]
1890 type-qualifier declaration-specifiers[opt]
1891 function-specifier declaration-specifiers[opt]
1893 Function specifiers (inline) are from C99, and are currently
1894 handled as storage class specifiers, as is __thread.
1896 C90 6.5.1, C99 6.7.1:
1897 storage-class-specifier:
1908 C90 6.5.2, C99 6.7.2:
1921 [_Imaginary removed in C99 TC2]
1922 struct-or-union-specifier
1926 (_Bool and _Complex are new in C99.)
1928 C90 6.5.3, C99 6.7.3:
1934 address-space-qualifier
1936 (restrict is new in C99.)
1940 declaration-specifiers:
1941 attributes declaration-specifiers[opt]
1947 identifier recognized by the target
1949 storage-class-specifier:
1962 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1963 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1968 class-name objc-protocol-refs[opt]
1969 typedef-name objc-protocol-refs
1974 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1975 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1976 enum c_lookahead_kind la
)
1978 bool attrs_ok
= start_attr_ok
;
1979 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1982 gcc_assert (la
== cla_prefer_id
);
1984 while (c_parser_next_token_is (parser
, CPP_NAME
)
1985 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1986 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1988 struct c_typespec t
;
1990 location_t loc
= c_parser_peek_token (parser
)->location
;
1992 /* If we cannot accept a type, exit if the next token must start
1993 one. Also, if we already have seen a tagged definition,
1994 a typename would be an error anyway and likely the user
1995 has simply forgotten a semicolon, so we exit. */
1996 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
1997 && c_parser_next_tokens_start_typename (parser
, la
)
1998 && !c_parser_next_token_is_qualifier (parser
))
2001 if (c_parser_next_token_is (parser
, CPP_NAME
))
2003 tree value
= c_parser_peek_token (parser
)->value
;
2004 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
2006 if (kind
== C_ID_ADDRSPACE
)
2009 = c_parser_peek_token (parser
)->keyword
- RID_FIRST_ADDR_SPACE
;
2010 declspecs_add_addrspace (specs
, as
);
2011 c_parser_consume_token (parser
);
2016 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2018 /* If we cannot accept a type, and the next token must start one,
2019 exit. Do the same if we already have seen a tagged definition,
2020 since it would be an error anyway and likely the user has simply
2021 forgotten a semicolon. */
2022 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2025 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2026 a C_ID_CLASSNAME. */
2027 c_parser_consume_token (parser
);
2030 if (kind
== C_ID_ID
)
2032 error ("unknown type name %qE", value
);
2033 t
.kind
= ctsk_typedef
;
2034 t
.spec
= error_mark_node
;
2036 else if (kind
== C_ID_TYPENAME
2037 && (!c_dialect_objc ()
2038 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2040 t
.kind
= ctsk_typedef
;
2041 /* For a typedef name, record the meaning, not the name.
2042 In case of 'foo foo, bar;'. */
2043 t
.spec
= lookup_name (value
);
2047 tree proto
= NULL_TREE
;
2048 gcc_assert (c_dialect_objc ());
2050 if (c_parser_next_token_is (parser
, CPP_LESS
))
2051 proto
= c_parser_objc_protocol_refs (parser
);
2052 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2055 t
.expr_const_operands
= true;
2056 declspecs_add_type (loc
, specs
, t
);
2059 if (c_parser_next_token_is (parser
, CPP_LESS
))
2061 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2062 nisse@lysator.liu.se. */
2064 gcc_assert (c_dialect_objc ());
2065 if (!typespec_ok
|| seen_type
)
2067 proto
= c_parser_objc_protocol_refs (parser
);
2069 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2071 t
.expr_const_operands
= true;
2072 declspecs_add_type (loc
, specs
, t
);
2075 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2076 switch (c_parser_peek_token (parser
)->keyword
)
2088 /* TODO: Distinguish between function specifiers (inline)
2089 and storage class specifiers, either here or in
2090 declspecs_add_scspec. */
2091 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
2092 c_parser_consume_token (parser
);
2116 if (c_dialect_objc ())
2117 parser
->objc_need_raw_identifier
= true;
2118 t
.kind
= ctsk_resword
;
2119 t
.spec
= c_parser_peek_token (parser
)->value
;
2121 t
.expr_const_operands
= true;
2122 declspecs_add_type (loc
, specs
, t
);
2123 c_parser_consume_token (parser
);
2130 t
= c_parser_enum_specifier (parser
);
2131 declspecs_add_type (loc
, specs
, t
);
2139 t
= c_parser_struct_or_union_specifier (parser
);
2140 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2141 declspecs_add_type (loc
, specs
, t
);
2144 /* ??? The old parser rejected typeof after other type
2145 specifiers, but is a syntax error the best way of
2147 if (!typespec_ok
|| seen_type
)
2151 t
= c_parser_typeof_specifier (parser
);
2152 declspecs_add_type (loc
, specs
, t
);
2158 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
2159 c_parser_consume_token (parser
);
2164 attrs
= c_parser_attributes (parser
);
2165 declspecs_add_attrs (specs
, attrs
);
2174 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2177 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2178 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2179 enum attributes[opt] identifier
2181 The form with trailing comma is new in C99. The forms with
2182 attributes are GNU extensions. In GNU C, we accept any expression
2183 without commas in the syntax (assignment expressions, not just
2184 conditional expressions); assignment expressions will be diagnosed
2189 enumerator-list , enumerator
2192 enumeration-constant
2193 enumeration-constant = constant-expression
2196 static struct c_typespec
2197 c_parser_enum_specifier (c_parser
*parser
)
2199 struct c_typespec ret
;
2201 tree ident
= NULL_TREE
;
2202 location_t enum_loc
;
2203 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2204 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2205 enum_loc
= c_parser_peek_token (parser
)->location
;
2206 c_parser_consume_token (parser
);
2207 attrs
= c_parser_attributes (parser
);
2208 enum_loc
= c_parser_peek_token (parser
)->location
;
2209 /* Set the location in case we create a decl now. */
2210 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2211 if (c_parser_next_token_is (parser
, CPP_NAME
))
2213 ident
= c_parser_peek_token (parser
)->value
;
2214 ident_loc
= c_parser_peek_token (parser
)->location
;
2215 enum_loc
= ident_loc
;
2216 c_parser_consume_token (parser
);
2218 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2220 /* Parse an enum definition. */
2221 struct c_enum_contents the_enum
;
2224 /* We chain the enumerators in reverse order, then put them in
2225 forward order at the end. */
2227 timevar_push (TV_PARSE_ENUM
);
2228 type
= start_enum (enum_loc
, &the_enum
, ident
);
2230 c_parser_consume_token (parser
);
2238 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2239 location_t decl_loc
, value_loc
;
2240 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2242 c_parser_error (parser
, "expected identifier");
2243 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2244 values
= error_mark_node
;
2247 token
= c_parser_peek_token (parser
);
2248 enum_id
= token
->value
;
2249 /* Set the location in case we create a decl now. */
2250 c_parser_set_source_position_from_token (token
);
2251 decl_loc
= value_loc
= token
->location
;
2252 c_parser_consume_token (parser
);
2253 if (c_parser_next_token_is (parser
, CPP_EQ
))
2255 c_parser_consume_token (parser
);
2256 value_loc
= c_parser_peek_token (parser
)->location
;
2257 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2260 enum_value
= NULL_TREE
;
2261 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2262 &the_enum
, enum_id
, enum_value
);
2263 TREE_CHAIN (enum_decl
) = values
;
2266 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2268 comma_loc
= c_parser_peek_token (parser
)->location
;
2270 c_parser_consume_token (parser
);
2272 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2274 if (seen_comma
&& !flag_isoc99
)
2275 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
2276 c_parser_consume_token (parser
);
2281 c_parser_error (parser
, "expected %<,%> or %<}%>");
2282 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2283 values
= error_mark_node
;
2287 postfix_attrs
= c_parser_attributes (parser
);
2288 ret
.spec
= finish_enum (type
, nreverse (values
),
2289 chainon (attrs
, postfix_attrs
));
2290 ret
.kind
= ctsk_tagdef
;
2291 ret
.expr
= NULL_TREE
;
2292 ret
.expr_const_operands
= true;
2293 timevar_pop (TV_PARSE_ENUM
);
2298 c_parser_error (parser
, "expected %<{%>");
2299 ret
.spec
= error_mark_node
;
2300 ret
.kind
= ctsk_tagref
;
2301 ret
.expr
= NULL_TREE
;
2302 ret
.expr_const_operands
= true;
2305 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2306 /* In ISO C, enumerated types can be referred to only if already
2308 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2311 pedwarn (enum_loc
, OPT_pedantic
,
2312 "ISO C forbids forward references to %<enum%> types");
2317 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2319 struct-or-union-specifier:
2320 struct-or-union attributes[opt] identifier[opt]
2321 { struct-contents } attributes[opt]
2322 struct-or-union attributes[opt] identifier
2325 struct-declaration-list
2327 struct-declaration-list:
2328 struct-declaration ;
2329 struct-declaration-list struct-declaration ;
2336 struct-declaration-list struct-declaration
2338 struct-declaration-list:
2339 struct-declaration-list ;
2342 (Note that in the syntax here, unlike that in ISO C, the semicolons
2343 are included here rather than in struct-declaration, in order to
2344 describe the syntax with extra semicolons and missing semicolon at
2349 struct-declaration-list:
2350 @defs ( class-name )
2352 (Note this does not include a trailing semicolon, but can be
2353 followed by further declarations, and gets a pedwarn-if-pedantic
2354 when followed by a semicolon.) */
2356 static struct c_typespec
2357 c_parser_struct_or_union_specifier (c_parser
*parser
)
2359 struct c_typespec ret
;
2361 tree ident
= NULL_TREE
;
2362 location_t struct_loc
;
2363 location_t ident_loc
= UNKNOWN_LOCATION
;
2364 enum tree_code code
;
2365 switch (c_parser_peek_token (parser
)->keyword
)
2376 struct_loc
= c_parser_peek_token (parser
)->location
;
2377 c_parser_consume_token (parser
);
2378 attrs
= c_parser_attributes (parser
);
2380 /* Set the location in case we create a decl now. */
2381 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2383 if (c_parser_next_token_is (parser
, CPP_NAME
))
2385 ident
= c_parser_peek_token (parser
)->value
;
2386 ident_loc
= c_parser_peek_token (parser
)->location
;
2387 struct_loc
= ident_loc
;
2388 c_parser_consume_token (parser
);
2390 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2392 /* Parse a struct or union definition. Start the scope of the
2393 tag before parsing components. */
2394 struct c_struct_parse_info
*struct_info
;
2395 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2397 /* We chain the components in reverse order, then put them in
2398 forward order at the end. Each struct-declaration may
2399 declare multiple components (comma-separated), so we must use
2400 chainon to join them, although when parsing each
2401 struct-declaration we can use TREE_CHAIN directly.
2403 The theory behind all this is that there will be more
2404 semicolon separated fields than comma separated fields, and
2405 so we'll be minimizing the number of node traversals required
2408 timevar_push (TV_PARSE_STRUCT
);
2409 contents
= NULL_TREE
;
2410 c_parser_consume_token (parser
);
2411 /* Handle the Objective-C @defs construct,
2412 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2413 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2416 gcc_assert (c_dialect_objc ());
2417 c_parser_consume_token (parser
);
2418 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2420 if (c_parser_next_token_is (parser
, CPP_NAME
)
2421 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2423 name
= c_parser_peek_token (parser
)->value
;
2424 c_parser_consume_token (parser
);
2428 c_parser_error (parser
, "expected class name");
2429 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2432 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2434 contents
= nreverse (objc_get_class_ivars (name
));
2437 /* Parse the struct-declarations and semicolons. Problems with
2438 semicolons are diagnosed here; empty structures are diagnosed
2443 /* Parse any stray semicolon. */
2444 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2446 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
2447 "extra semicolon in struct or union specified");
2448 c_parser_consume_token (parser
);
2451 /* Stop if at the end of the struct or union contents. */
2452 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2454 c_parser_consume_token (parser
);
2457 /* Accept #pragmas at struct scope. */
2458 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2460 c_parser_pragma (parser
, pragma_external
);
2463 /* Parse some comma-separated declarations, but not the
2464 trailing semicolon if any. */
2465 decls
= c_parser_struct_declaration (parser
);
2466 contents
= chainon (decls
, contents
);
2467 /* If no semicolon follows, either we have a parse error or
2468 are at the end of the struct or union and should
2470 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2471 c_parser_consume_token (parser
);
2474 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2475 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2476 "no semicolon at end of struct or union");
2477 else if (parser
->error
2478 || !c_parser_next_token_starts_declspecs (parser
))
2480 c_parser_error (parser
, "expected %<;%>");
2481 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2485 /* If we come here, we have already emitted an error
2486 for an expected `;', identifier or `(', and we also
2487 recovered already. Go on with the next field. */
2490 postfix_attrs
= c_parser_attributes (parser
);
2491 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2492 chainon (attrs
, postfix_attrs
), struct_info
);
2493 ret
.kind
= ctsk_tagdef
;
2494 ret
.expr
= NULL_TREE
;
2495 ret
.expr_const_operands
= true;
2496 timevar_pop (TV_PARSE_STRUCT
);
2501 c_parser_error (parser
, "expected %<{%>");
2502 ret
.spec
= error_mark_node
;
2503 ret
.kind
= ctsk_tagref
;
2504 ret
.expr
= NULL_TREE
;
2505 ret
.expr_const_operands
= true;
2508 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2512 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2513 the trailing semicolon.
2516 specifier-qualifier-list struct-declarator-list
2517 static_assert-declaration-no-semi
2519 specifier-qualifier-list:
2520 type-specifier specifier-qualifier-list[opt]
2521 type-qualifier specifier-qualifier-list[opt]
2522 attributes specifier-qualifier-list[opt]
2524 struct-declarator-list:
2526 struct-declarator-list , attributes[opt] struct-declarator
2529 declarator attributes[opt]
2530 declarator[opt] : constant-expression attributes[opt]
2535 __extension__ struct-declaration
2536 specifier-qualifier-list
2538 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2539 of attributes where shown is a GNU extension. In GNU C, we accept
2540 any expression without commas in the syntax (assignment
2541 expressions, not just conditional expressions); assignment
2542 expressions will be diagnosed as non-constant. */
2545 c_parser_struct_declaration (c_parser
*parser
)
2547 struct c_declspecs
*specs
;
2549 tree all_prefix_attrs
;
2551 location_t decl_loc
;
2552 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2556 ext
= disable_extension_diagnostics ();
2557 c_parser_consume_token (parser
);
2558 decl
= c_parser_struct_declaration (parser
);
2559 restore_extension_diagnostics (ext
);
2562 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2564 c_parser_static_assert_declaration_no_semi (parser
);
2567 specs
= build_null_declspecs ();
2568 decl_loc
= c_parser_peek_token (parser
)->location
;
2569 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2572 if (!specs
->declspecs_seen_p
)
2574 c_parser_error (parser
, "expected specifier-qualifier-list");
2577 finish_declspecs (specs
);
2578 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2579 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2582 if (specs
->typespec_kind
== ctsk_none
)
2584 pedwarn (decl_loc
, OPT_pedantic
,
2585 "ISO C forbids member declarations with no members");
2586 shadow_tag_warned (specs
, pedantic
);
2591 /* Support for unnamed structs or unions as members of
2592 structs or unions (which is [a] useful and [b] supports
2596 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2597 build_id_declarator (NULL_TREE
), specs
,
2600 decl_attributes (&ret
, attrs
, 0);
2605 /* Provide better error recovery. Note that a type name here is valid,
2606 and will be treated as a field name. */
2607 if (specs
->typespec_kind
== ctsk_tagdef
2608 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2609 && c_parser_next_token_starts_declspecs (parser
)
2610 && !c_parser_next_token_is (parser
, CPP_NAME
))
2612 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2613 parser
->error
= false;
2617 pending_xref_error ();
2618 prefix_attrs
= specs
->attrs
;
2619 all_prefix_attrs
= prefix_attrs
;
2620 specs
->attrs
= NULL_TREE
;
2624 /* Declaring one or more declarators or un-named bit-fields. */
2625 struct c_declarator
*declarator
;
2627 if (c_parser_next_token_is (parser
, CPP_COLON
))
2628 declarator
= build_id_declarator (NULL_TREE
);
2630 declarator
= c_parser_declarator (parser
,
2631 specs
->typespec_kind
!= ctsk_none
,
2632 C_DTR_NORMAL
, &dummy
);
2633 if (declarator
== NULL
)
2635 c_parser_skip_to_end_of_block_or_statement (parser
);
2638 if (c_parser_next_token_is (parser
, CPP_COLON
)
2639 || c_parser_next_token_is (parser
, CPP_COMMA
)
2640 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2641 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2642 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2644 tree postfix_attrs
= NULL_TREE
;
2645 tree width
= NULL_TREE
;
2647 if (c_parser_next_token_is (parser
, CPP_COLON
))
2649 c_parser_consume_token (parser
);
2650 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2652 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2653 postfix_attrs
= c_parser_attributes (parser
);
2654 d
= grokfield (c_parser_peek_token (parser
)->location
,
2655 declarator
, specs
, width
, &all_prefix_attrs
);
2656 decl_attributes (&d
, chainon (postfix_attrs
,
2657 all_prefix_attrs
), 0);
2658 DECL_CHAIN (d
) = decls
;
2660 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2661 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2664 all_prefix_attrs
= prefix_attrs
;
2665 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2666 c_parser_consume_token (parser
);
2667 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2668 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2670 /* Semicolon consumed in caller. */
2675 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2681 c_parser_error (parser
,
2682 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2683 "%<__attribute__%>");
2690 /* Parse a typeof specifier (a GNU extension).
2693 typeof ( expression )
2694 typeof ( type-name )
2697 static struct c_typespec
2698 c_parser_typeof_specifier (c_parser
*parser
)
2700 struct c_typespec ret
;
2701 ret
.kind
= ctsk_typeof
;
2702 ret
.spec
= error_mark_node
;
2703 ret
.expr
= NULL_TREE
;
2704 ret
.expr_const_operands
= true;
2705 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2706 c_parser_consume_token (parser
);
2707 c_inhibit_evaluation_warnings
++;
2709 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2711 c_inhibit_evaluation_warnings
--;
2715 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2717 struct c_type_name
*type
= c_parser_type_name (parser
);
2718 c_inhibit_evaluation_warnings
--;
2722 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2723 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2729 location_t here
= c_parser_peek_token (parser
)->location
;
2730 struct c_expr expr
= c_parser_expression (parser
);
2731 c_inhibit_evaluation_warnings
--;
2733 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2734 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2735 error_at (here
, "%<typeof%> applied to a bit-field");
2736 mark_exp_read (expr
.value
);
2737 ret
.spec
= TREE_TYPE (expr
.value
);
2738 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2739 /* This is returned with the type so that when the type is
2740 evaluated, this can be evaluated. */
2742 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2743 pop_maybe_used (was_vm
);
2745 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2749 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2750 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2751 be redeclared; otherwise it may not. KIND indicates which kind of
2752 declarator is wanted. Returns a valid declarator except in the
2753 case of a syntax error in which case NULL is returned. *SEEN_ID is
2754 set to true if an identifier being declared is seen; this is used
2755 to diagnose bad forms of abstract array declarators and to
2756 determine whether an identifier list is syntactically permitted.
2759 pointer[opt] direct-declarator
2763 ( attributes[opt] declarator )
2764 direct-declarator array-declarator
2765 direct-declarator ( parameter-type-list )
2766 direct-declarator ( identifier-list[opt] )
2769 * type-qualifier-list[opt]
2770 * type-qualifier-list[opt] pointer
2772 type-qualifier-list:
2775 type-qualifier-list type-qualifier
2776 type-qualifier-list attributes
2778 parameter-type-list:
2780 parameter-list , ...
2783 parameter-declaration
2784 parameter-list , parameter-declaration
2786 parameter-declaration:
2787 declaration-specifiers declarator attributes[opt]
2788 declaration-specifiers abstract-declarator[opt] attributes[opt]
2792 identifier-list , identifier
2794 abstract-declarator:
2796 pointer[opt] direct-abstract-declarator
2798 direct-abstract-declarator:
2799 ( attributes[opt] abstract-declarator )
2800 direct-abstract-declarator[opt] array-declarator
2801 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2806 direct-declarator ( parameter-forward-declarations
2807 parameter-type-list[opt] )
2809 direct-abstract-declarator:
2810 direct-abstract-declarator[opt] ( parameter-forward-declarations
2811 parameter-type-list[opt] )
2813 parameter-forward-declarations:
2815 parameter-forward-declarations parameter-list ;
2817 The uses of attributes shown above are GNU extensions.
2819 Some forms of array declarator are not included in C99 in the
2820 syntax for abstract declarators; these are disallowed elsewhere.
2821 This may be a defect (DR#289).
2823 This function also accepts an omitted abstract declarator as being
2824 an abstract declarator, although not part of the formal syntax. */
2826 static struct c_declarator
*
2827 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2830 /* Parse any initial pointer part. */
2831 if (c_parser_next_token_is (parser
, CPP_MULT
))
2833 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2834 struct c_declarator
*inner
;
2835 c_parser_consume_token (parser
);
2836 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2837 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2841 return make_pointer_declarator (quals_attrs
, inner
);
2843 /* Now we have a direct declarator, direct abstract declarator or
2844 nothing (which counts as a direct abstract declarator here). */
2845 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2848 /* Parse a direct declarator or direct abstract declarator; arguments
2849 as c_parser_declarator. */
2851 static struct c_declarator
*
2852 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2855 /* The direct declarator must start with an identifier (possibly
2856 omitted) or a parenthesized declarator (possibly abstract). In
2857 an ordinary declarator, initial parentheses must start a
2858 parenthesized declarator. In an abstract declarator or parameter
2859 declarator, they could start a parenthesized declarator or a
2860 parameter list. To tell which, the open parenthesis and any
2861 following attributes must be read. If a declaration specifier
2862 follows, then it is a parameter list; if the specifier is a
2863 typedef name, there might be an ambiguity about redeclaring it,
2864 which is resolved in the direction of treating it as a typedef
2865 name. If a close parenthesis follows, it is also an empty
2866 parameter list, as the syntax does not permit empty abstract
2867 declarators. Otherwise, it is a parenthesized declarator (in
2868 which case the analysis may be repeated inside it, recursively).
2870 ??? There is an ambiguity in a parameter declaration "int
2871 (__attribute__((foo)) x)", where x is not a typedef name: it
2872 could be an abstract declarator for a function, or declare x with
2873 parentheses. The proper resolution of this ambiguity needs
2874 documenting. At present we follow an accident of the old
2875 parser's implementation, whereby the first parameter must have
2876 some declaration specifiers other than just attributes. Thus as
2877 a parameter declaration it is treated as a parenthesized
2878 parameter named x, and as an abstract declarator it is
2881 ??? Also following the old parser, attributes inside an empty
2882 parameter list are ignored, making it a list not yielding a
2883 prototype, rather than giving an error or making it have one
2884 parameter with implicit type int.
2886 ??? Also following the old parser, typedef names may be
2887 redeclared in declarators, but not Objective-C class names. */
2889 if (kind
!= C_DTR_ABSTRACT
2890 && c_parser_next_token_is (parser
, CPP_NAME
)
2892 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2893 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2894 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2896 struct c_declarator
*inner
2897 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2899 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2900 c_parser_consume_token (parser
);
2901 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2904 if (kind
!= C_DTR_NORMAL
2905 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2907 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2908 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2911 /* Either we are at the end of an abstract declarator, or we have
2914 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2917 struct c_declarator
*inner
;
2918 c_parser_consume_token (parser
);
2919 attrs
= c_parser_attributes (parser
);
2920 if (kind
!= C_DTR_NORMAL
2921 && (c_parser_next_token_starts_declspecs (parser
)
2922 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2924 struct c_arg_info
*args
2925 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2932 = build_function_declarator (args
,
2933 build_id_declarator (NULL_TREE
));
2934 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2938 /* A parenthesized declarator. */
2939 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2940 if (inner
!= NULL
&& attrs
!= NULL
)
2941 inner
= build_attrs_declarator (attrs
, inner
);
2942 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2944 c_parser_consume_token (parser
);
2948 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2952 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2959 if (kind
== C_DTR_NORMAL
)
2961 c_parser_error (parser
, "expected identifier or %<(%>");
2965 return build_id_declarator (NULL_TREE
);
2969 /* Parse part of a direct declarator or direct abstract declarator,
2970 given that some (in INNER) has already been parsed; ID_PRESENT is
2971 true if an identifier is present, false for an abstract
2974 static struct c_declarator
*
2975 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2976 struct c_declarator
*inner
)
2978 /* Parse a sequence of array declarators and parameter lists. */
2979 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2981 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2982 struct c_declarator
*declarator
;
2983 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2987 c_parser_consume_token (parser
);
2988 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2989 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2991 c_parser_consume_token (parser
);
2992 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2993 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2994 if (!quals_attrs
->declspecs_seen_p
)
2996 /* If "static" is present, there must be an array dimension.
2997 Otherwise, there may be a dimension, "*", or no
3002 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3006 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3011 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3013 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3017 c_parser_consume_token (parser
);
3022 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3028 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3031 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3032 c_parser_consume_token (parser
);
3035 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3040 mark_exp_read (dimen
);
3041 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3042 static_seen
, star_seen
);
3043 if (declarator
== NULL
)
3045 inner
= set_array_declarator_inner (declarator
, inner
);
3046 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3048 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3051 struct c_arg_info
*args
;
3052 c_parser_consume_token (parser
);
3053 attrs
= c_parser_attributes (parser
);
3054 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3059 inner
= build_function_declarator (args
, inner
);
3060 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3066 /* Parse a parameter list or identifier list, including the closing
3067 parenthesis but not the opening one. ATTRS are the attributes at
3068 the start of the list. ID_LIST_OK is true if an identifier list is
3069 acceptable; such a list must not have attributes at the start. */
3071 static struct c_arg_info
*
3072 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3075 declare_parm_level ();
3076 /* If the list starts with an identifier, it is an identifier list.
3077 Otherwise, it is either a prototype list or an empty list. */
3080 && c_parser_next_token_is (parser
, CPP_NAME
)
3081 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3083 /* Look ahead to detect typos in type names. */
3084 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3085 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3086 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3087 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3089 tree list
= NULL_TREE
, *nextp
= &list
;
3090 while (c_parser_next_token_is (parser
, CPP_NAME
)
3091 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3093 *nextp
= build_tree_list (NULL_TREE
,
3094 c_parser_peek_token (parser
)->value
);
3095 nextp
= & TREE_CHAIN (*nextp
);
3096 c_parser_consume_token (parser
);
3097 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3099 c_parser_consume_token (parser
);
3100 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3102 c_parser_error (parser
, "expected identifier");
3106 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3108 struct c_arg_info
*ret
= build_arg_info ();
3110 c_parser_consume_token (parser
);
3116 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3124 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3131 /* Parse a parameter list (possibly empty), including the closing
3132 parenthesis but not the opening one. ATTRS are the attributes at
3133 the start of the list. EXPR is NULL or an expression that needs to
3134 be evaluated for the side effects of array size expressions in the
3137 static struct c_arg_info
*
3138 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3140 bool bad_parm
= false;
3142 /* ??? Following the old parser, forward parameter declarations may
3143 use abstract declarators, and if no real parameter declarations
3144 follow the forward declarations then this is not diagnosed. Also
3145 note as above that attributes are ignored as the only contents of
3146 the parentheses, or as the only contents after forward
3148 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3150 struct c_arg_info
*ret
= build_arg_info ();
3151 c_parser_consume_token (parser
);
3154 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3156 struct c_arg_info
*ret
= build_arg_info ();
3157 /* Suppress -Wold-style-definition for this case. */
3158 ret
->types
= error_mark_node
;
3159 error_at (c_parser_peek_token (parser
)->location
,
3160 "ISO C requires a named argument before %<...%>");
3161 c_parser_consume_token (parser
);
3162 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3164 c_parser_consume_token (parser
);
3169 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3174 /* Nonempty list of parameters, either terminated with semicolon
3175 (forward declarations; recurse) or with close parenthesis (normal
3176 function) or with ", ... )" (variadic function). */
3179 /* Parse a parameter. */
3180 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3185 push_parm_decl (parm
, &expr
);
3186 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3189 c_parser_consume_token (parser
);
3190 mark_forward_parm_decls ();
3191 new_attrs
= c_parser_attributes (parser
);
3192 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3194 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3196 c_parser_consume_token (parser
);
3200 return get_parm_info (false, expr
);
3202 if (!c_parser_require (parser
, CPP_COMMA
,
3203 "expected %<;%>, %<,%> or %<)%>"))
3205 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3208 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3210 c_parser_consume_token (parser
);
3211 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3213 c_parser_consume_token (parser
);
3217 return get_parm_info (true, expr
);
3221 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3229 /* Parse a parameter declaration. ATTRS are the attributes at the
3230 start of the declaration if it is the first parameter. */
3232 static struct c_parm
*
3233 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3235 struct c_declspecs
*specs
;
3236 struct c_declarator
*declarator
;
3238 tree postfix_attrs
= NULL_TREE
;
3240 if (!c_parser_next_token_starts_declspecs (parser
))
3242 c_token
*token
= c_parser_peek_token (parser
);
3245 c_parser_set_source_position_from_token (token
);
3246 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3248 error ("unknown type name %qE", token
->value
);
3249 parser
->error
= true;
3251 /* ??? In some Objective-C cases '...' isn't applicable so there
3252 should be a different message. */
3254 c_parser_error (parser
,
3255 "expected declaration specifiers or %<...%>");
3256 c_parser_skip_to_end_of_parameter (parser
);
3259 specs
= build_null_declspecs ();
3262 declspecs_add_attrs (specs
, attrs
);
3265 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3266 finish_declspecs (specs
);
3267 pending_xref_error ();
3268 prefix_attrs
= specs
->attrs
;
3269 specs
->attrs
= NULL_TREE
;
3270 declarator
= c_parser_declarator (parser
,
3271 specs
->typespec_kind
!= ctsk_none
,
3272 C_DTR_PARM
, &dummy
);
3273 if (declarator
== NULL
)
3275 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3278 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3279 postfix_attrs
= c_parser_attributes (parser
);
3280 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3284 /* Parse a string literal in an asm expression. It should not be
3285 translated, and wide string literals are an error although
3286 permitted by the syntax. This is a GNU extension.
3291 ??? At present, following the old parser, the caller needs to have
3292 set lex_untranslated_string to 1. It would be better to follow the
3293 C++ parser rather than using this kludge. */
3296 c_parser_asm_string_literal (c_parser
*parser
)
3299 int save_flag
= warn_overlength_strings
;
3300 warn_overlength_strings
= 0;
3301 if (c_parser_next_token_is (parser
, CPP_STRING
))
3303 str
= c_parser_peek_token (parser
)->value
;
3304 c_parser_consume_token (parser
);
3306 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3308 error_at (c_parser_peek_token (parser
)->location
,
3309 "wide string literal in %<asm%>");
3310 str
= build_string (1, "");
3311 c_parser_consume_token (parser
);
3315 c_parser_error (parser
, "expected string literal");
3318 warn_overlength_strings
= save_flag
;
3322 /* Parse a simple asm expression. This is used in restricted
3323 contexts, where a full expression with inputs and outputs does not
3324 make sense. This is a GNU extension.
3327 asm ( asm-string-literal )
3331 c_parser_simple_asm_expr (c_parser
*parser
)
3334 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3335 /* ??? Follow the C++ parser rather than using the
3336 lex_untranslated_string kludge. */
3337 parser
->lex_untranslated_string
= true;
3338 c_parser_consume_token (parser
);
3339 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3341 parser
->lex_untranslated_string
= false;
3344 str
= c_parser_asm_string_literal (parser
);
3345 parser
->lex_untranslated_string
= false;
3346 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3348 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3354 /* Parse (possibly empty) attributes. This is a GNU extension.
3358 attributes attribute
3361 __attribute__ ( ( attribute-list ) )
3365 attribute_list , attrib
3370 any-word ( identifier )
3371 any-word ( identifier , nonempty-expr-list )
3372 any-word ( expr-list )
3374 where the "identifier" must not be declared as a type, and
3375 "any-word" may be any identifier (including one declared as a
3376 type), a reserved word storage class specifier, type specifier or
3377 type qualifier. ??? This still leaves out most reserved keywords
3378 (following the old parser), shouldn't we include them, and why not
3379 allow identifiers declared as types to start the arguments? */
3382 c_parser_attributes (c_parser
*parser
)
3384 tree attrs
= NULL_TREE
;
3385 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3387 /* ??? Follow the C++ parser rather than using the
3388 lex_untranslated_string kludge. */
3389 parser
->lex_untranslated_string
= true;
3390 c_parser_consume_token (parser
);
3391 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3393 parser
->lex_untranslated_string
= false;
3396 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3398 parser
->lex_untranslated_string
= false;
3399 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3402 /* Parse the attribute list. */
3403 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3404 || c_parser_next_token_is (parser
, CPP_NAME
)
3405 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3407 tree attr
, attr_name
, attr_args
;
3408 VEC(tree
,gc
) *expr_list
;
3409 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3411 c_parser_consume_token (parser
);
3414 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3416 /* ??? See comment above about what keywords are
3419 switch (c_parser_peek_token (parser
)->keyword
)
3457 /* Accept __attribute__((__const)) as __attribute__((const))
3460 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3463 attr_name
= c_parser_peek_token (parser
)->value
;
3464 c_parser_consume_token (parser
);
3465 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3467 attr
= build_tree_list (attr_name
, NULL_TREE
);
3468 attrs
= chainon (attrs
, attr
);
3471 c_parser_consume_token (parser
);
3472 /* Parse the attribute contents. If they start with an
3473 identifier which is followed by a comma or close
3474 parenthesis, then the arguments start with that
3475 identifier; otherwise they are an expression list.
3476 In objective-c the identifier may be a classname. */
3477 if (c_parser_next_token_is (parser
, CPP_NAME
)
3478 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3479 || (c_dialect_objc ()
3480 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3481 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3482 || (c_parser_peek_2nd_token (parser
)->type
3483 == CPP_CLOSE_PAREN
)))
3485 tree arg1
= c_parser_peek_token (parser
)->value
;
3486 c_parser_consume_token (parser
);
3487 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3488 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3492 c_parser_consume_token (parser
);
3493 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3494 tree_list
= build_tree_list_vec (expr_list
);
3495 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3496 release_tree_vector (expr_list
);
3501 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3502 attr_args
= NULL_TREE
;
3505 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3506 attr_args
= build_tree_list_vec (expr_list
);
3507 release_tree_vector (expr_list
);
3510 attr
= build_tree_list (attr_name
, attr_args
);
3511 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3512 c_parser_consume_token (parser
);
3515 parser
->lex_untranslated_string
= false;
3516 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3520 attrs
= chainon (attrs
, attr
);
3522 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3523 c_parser_consume_token (parser
);
3526 parser
->lex_untranslated_string
= false;
3527 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3531 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3532 c_parser_consume_token (parser
);
3535 parser
->lex_untranslated_string
= false;
3536 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3540 parser
->lex_untranslated_string
= false;
3545 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3548 specifier-qualifier-list abstract-declarator[opt]
3551 static struct c_type_name
*
3552 c_parser_type_name (c_parser
*parser
)
3554 struct c_declspecs
*specs
= build_null_declspecs ();
3555 struct c_declarator
*declarator
;
3556 struct c_type_name
*ret
;
3558 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3559 if (!specs
->declspecs_seen_p
)
3561 c_parser_error (parser
, "expected specifier-qualifier-list");
3564 if (specs
->type
!= error_mark_node
)
3566 pending_xref_error ();
3567 finish_declspecs (specs
);
3569 declarator
= c_parser_declarator (parser
,
3570 specs
->typespec_kind
!= ctsk_none
,
3571 C_DTR_ABSTRACT
, &dummy
);
3572 if (declarator
== NULL
)
3574 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3576 ret
->declarator
= declarator
;
3580 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3583 assignment-expression
3584 { initializer-list }
3585 { initializer-list , }
3588 designation[opt] initializer
3589 initializer-list , designation[opt] initializer
3596 designator-list designator
3603 [ constant-expression ]
3615 [ constant-expression ... constant-expression ]
3617 Any expression without commas is accepted in the syntax for the
3618 constant-expressions, with non-constant expressions rejected later.
3620 This function is only used for top-level initializers; for nested
3621 ones, see c_parser_initval. */
3623 static struct c_expr
3624 c_parser_initializer (c_parser
*parser
)
3626 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3627 return c_parser_braced_init (parser
, NULL_TREE
, false);
3631 location_t loc
= c_parser_peek_token (parser
)->location
;
3632 ret
= c_parser_expr_no_commas (parser
, NULL
);
3633 if (TREE_CODE (ret
.value
) != STRING_CST
3634 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3635 ret
= default_function_array_read_conversion (loc
, ret
);
3640 /* Parse a braced initializer list. TYPE is the type specified for a
3641 compound literal, and NULL_TREE for other initializers and for
3642 nested braced lists. NESTED_P is true for nested braced lists,
3643 false for the list of a compound literal or the list that is the
3644 top-level initializer in a declaration. */
3646 static struct c_expr
3647 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3650 struct obstack braced_init_obstack
;
3651 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3652 gcc_obstack_init (&braced_init_obstack
);
3653 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3654 c_parser_consume_token (parser
);
3656 push_init_level (0, &braced_init_obstack
);
3658 really_start_incremental_init (type
);
3659 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3661 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3665 /* Parse a non-empty initializer list, possibly with a trailing
3669 c_parser_initelt (parser
, &braced_init_obstack
);
3672 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3673 c_parser_consume_token (parser
);
3676 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3680 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3682 ret
.value
= error_mark_node
;
3683 ret
.original_code
= ERROR_MARK
;
3684 ret
.original_type
= NULL
;
3685 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3686 pop_init_level (0, &braced_init_obstack
);
3687 obstack_free (&braced_init_obstack
, NULL
);
3690 c_parser_consume_token (parser
);
3691 ret
= pop_init_level (0, &braced_init_obstack
);
3692 obstack_free (&braced_init_obstack
, NULL
);
3696 /* Parse a nested initializer, including designators. */
3699 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3701 /* Parse any designator or designator list. A single array
3702 designator may have the subsequent "=" omitted in GNU C, but a
3703 longer list or a structure member designator may not. */
3704 if (c_parser_next_token_is (parser
, CPP_NAME
)
3705 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3707 /* Old-style structure member designator. */
3708 set_init_label (c_parser_peek_token (parser
)->value
,
3709 braced_init_obstack
);
3710 /* Use the colon as the error location. */
3711 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3712 "obsolete use of designated initializer with %<:%>");
3713 c_parser_consume_token (parser
);
3714 c_parser_consume_token (parser
);
3718 /* des_seen is 0 if there have been no designators, 1 if there
3719 has been a single array designator and 2 otherwise. */
3721 /* Location of a designator. */
3722 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3723 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3724 || c_parser_next_token_is (parser
, CPP_DOT
))
3726 int des_prev
= des_seen
;
3728 des_loc
= c_parser_peek_token (parser
)->location
;
3731 if (c_parser_next_token_is (parser
, CPP_DOT
))
3734 c_parser_consume_token (parser
);
3735 if (c_parser_next_token_is (parser
, CPP_NAME
))
3737 set_init_label (c_parser_peek_token (parser
)->value
,
3738 braced_init_obstack
);
3739 c_parser_consume_token (parser
);
3744 init
.value
= error_mark_node
;
3745 init
.original_code
= ERROR_MARK
;
3746 init
.original_type
= NULL
;
3747 c_parser_error (parser
, "expected identifier");
3748 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3749 process_init_element (init
, false, braced_init_obstack
);
3756 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3757 /* ??? Following the old parser, [ objc-receiver
3758 objc-message-args ] is accepted as an initializer,
3759 being distinguished from a designator by what follows
3760 the first assignment expression inside the square
3761 brackets, but after a first array designator a
3762 subsequent square bracket is for Objective-C taken to
3763 start an expression, using the obsolete form of
3764 designated initializer without '=', rather than
3765 possibly being a second level of designation: in LALR
3766 terms, the '[' is shifted rather than reducing
3767 designator to designator-list. */
3768 if (des_prev
== 1 && c_dialect_objc ())
3770 des_seen
= des_prev
;
3773 if (des_prev
== 0 && c_dialect_objc ())
3775 /* This might be an array designator or an
3776 Objective-C message expression. If the former,
3777 continue parsing here; if the latter, parse the
3778 remainder of the initializer given the starting
3779 primary-expression. ??? It might make sense to
3780 distinguish when des_prev == 1 as well; see
3781 previous comment. */
3783 struct c_expr mexpr
;
3784 c_parser_consume_token (parser
);
3785 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3786 && ((c_parser_peek_token (parser
)->id_kind
3788 || (c_parser_peek_token (parser
)->id_kind
3789 == C_ID_CLASSNAME
)))
3791 /* Type name receiver. */
3792 tree id
= c_parser_peek_token (parser
)->value
;
3793 c_parser_consume_token (parser
);
3794 rec
= objc_get_class_reference (id
);
3795 goto parse_message_args
;
3797 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3798 mark_exp_read (first
);
3799 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3800 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3801 goto array_desig_after_first
;
3802 /* Expression receiver. So far only one part
3803 without commas has been parsed; there might be
3804 more of the expression. */
3806 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3809 location_t comma_loc
, exp_loc
;
3810 comma_loc
= c_parser_peek_token (parser
)->location
;
3811 c_parser_consume_token (parser
);
3812 exp_loc
= c_parser_peek_token (parser
)->location
;
3813 next
= c_parser_expr_no_commas (parser
, NULL
);
3814 next
= default_function_array_read_conversion (exp_loc
,
3816 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3819 /* Now parse the objc-message-args. */
3820 args
= c_parser_objc_message_args (parser
);
3821 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3824 = objc_build_message_expr (rec
, args
);
3825 mexpr
.original_code
= ERROR_MARK
;
3826 mexpr
.original_type
= NULL
;
3827 /* Now parse and process the remainder of the
3828 initializer, starting with this message
3829 expression as a primary-expression. */
3830 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3833 c_parser_consume_token (parser
);
3834 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3835 mark_exp_read (first
);
3836 array_desig_after_first
:
3837 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3839 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3840 c_parser_consume_token (parser
);
3841 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3842 mark_exp_read (second
);
3846 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3848 c_parser_consume_token (parser
);
3849 set_init_index (first
, second
, braced_init_obstack
);
3851 pedwarn (ellipsis_loc
, OPT_pedantic
,
3852 "ISO C forbids specifying range of elements to initialize");
3855 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3861 if (c_parser_next_token_is (parser
, CPP_EQ
))
3864 pedwarn (des_loc
, OPT_pedantic
,
3865 "ISO C90 forbids specifying subobject to initialize");
3866 c_parser_consume_token (parser
);
3871 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3872 "obsolete use of designated initializer without %<=%>");
3876 init
.value
= error_mark_node
;
3877 init
.original_code
= ERROR_MARK
;
3878 init
.original_type
= NULL
;
3879 c_parser_error (parser
, "expected %<=%>");
3880 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3881 process_init_element (init
, false, braced_init_obstack
);
3887 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3890 /* Parse a nested initializer; as c_parser_initializer but parses
3891 initializers within braced lists, after any designators have been
3892 applied. If AFTER is not NULL then it is an Objective-C message
3893 expression which is the primary-expression starting the
3897 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
3898 struct obstack
* braced_init_obstack
)
3901 gcc_assert (!after
|| c_dialect_objc ());
3902 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3903 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3906 location_t loc
= c_parser_peek_token (parser
)->location
;
3907 init
= c_parser_expr_no_commas (parser
, after
);
3908 if (init
.value
!= NULL_TREE
3909 && TREE_CODE (init
.value
) != STRING_CST
3910 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3911 init
= default_function_array_read_conversion (loc
, init
);
3913 process_init_element (init
, false, braced_init_obstack
);
3916 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3920 { block-item-list[opt] }
3921 { label-declarations block-item-list }
3925 block-item-list block-item
3937 { label-declarations block-item-list }
3940 __extension__ nested-declaration
3941 nested-function-definition
3945 label-declarations label-declaration
3948 __label__ identifier-list ;
3950 Allowing the mixing of declarations and code is new in C99. The
3951 GNU syntax also permits (not shown above) labels at the end of
3952 compound statements, which yield an error. We don't allow labels
3953 on declarations; this might seem like a natural extension, but
3954 there would be a conflict between attributes on the label and
3955 prefix attributes on the declaration. ??? The syntax follows the
3956 old parser in requiring something after label declarations.
3957 Although they are erroneous if the labels declared aren't defined,
3958 is it useful for the syntax to be this way?
3970 c_parser_compound_statement (c_parser
*parser
)
3973 location_t brace_loc
;
3974 brace_loc
= c_parser_peek_token (parser
)->location
;
3975 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3977 /* Ensure a scope is entered and left anyway to avoid confusion
3978 if we have just prepared to enter a function body. */
3979 stmt
= c_begin_compound_stmt (true);
3980 c_end_compound_stmt (brace_loc
, stmt
, true);
3981 return error_mark_node
;
3983 stmt
= c_begin_compound_stmt (true);
3984 c_parser_compound_statement_nostart (parser
);
3985 return c_end_compound_stmt (brace_loc
, stmt
, true);
3988 /* Parse a compound statement except for the opening brace. This is
3989 used for parsing both compound statements and statement expressions
3990 (which follow different paths to handling the opening). */
3993 c_parser_compound_statement_nostart (c_parser
*parser
)
3995 bool last_stmt
= false;
3996 bool last_label
= false;
3997 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3998 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3999 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4001 c_parser_consume_token (parser
);
4004 mark_valid_location_for_stdc_pragma (true);
4005 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4007 /* Read zero or more forward-declarations for labels that nested
4008 functions can jump to. */
4009 mark_valid_location_for_stdc_pragma (false);
4010 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4012 label_loc
= c_parser_peek_token (parser
)->location
;
4013 c_parser_consume_token (parser
);
4014 /* Any identifiers, including those declared as type names,
4019 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4021 c_parser_error (parser
, "expected identifier");
4025 = declare_label (c_parser_peek_token (parser
)->value
);
4026 C_DECLARED_LABEL_FLAG (label
) = 1;
4027 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4028 c_parser_consume_token (parser
);
4029 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4030 c_parser_consume_token (parser
);
4034 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4036 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
4038 /* We must now have at least one statement, label or declaration. */
4039 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4041 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4042 c_parser_error (parser
, "expected declaration or statement");
4043 c_parser_consume_token (parser
);
4046 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4048 location_t loc
= c_parser_peek_token (parser
)->location
;
4049 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4050 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4051 || (c_parser_next_token_is (parser
, CPP_NAME
)
4052 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4054 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4055 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4057 label_loc
= c_parser_peek_token (parser
)->location
;
4060 mark_valid_location_for_stdc_pragma (false);
4061 c_parser_label (parser
);
4063 else if (!last_label
4064 && c_parser_next_tokens_start_declaration (parser
))
4067 mark_valid_location_for_stdc_pragma (false);
4068 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4071 (pedantic
&& !flag_isoc99
)
4073 : OPT_Wdeclaration_after_statement
,
4074 "ISO C90 forbids mixed declarations and code");
4077 else if (!last_label
4078 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4080 /* __extension__ can start a declaration, but is also an
4081 unary operator that can start an expression. Consume all
4082 but the last of a possible series of __extension__ to
4084 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4085 && (c_parser_peek_2nd_token (parser
)->keyword
4087 c_parser_consume_token (parser
);
4088 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4091 ext
= disable_extension_diagnostics ();
4092 c_parser_consume_token (parser
);
4094 mark_valid_location_for_stdc_pragma (false);
4095 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4097 /* Following the old parser, __extension__ does not
4098 disable this diagnostic. */
4099 restore_extension_diagnostics (ext
);
4101 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4103 : OPT_Wdeclaration_after_statement
,
4104 "ISO C90 forbids mixed declarations and code");
4110 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4112 /* External pragmas, and some omp pragmas, are not associated
4113 with regular c code, and so are not to be considered statements
4114 syntactically. This ensures that the user doesn't put them
4115 places that would turn into syntax errors if the directive
4117 if (c_parser_pragma (parser
, pragma_compound
))
4118 last_label
= false, last_stmt
= true;
4120 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4122 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4123 c_parser_error (parser
, "expected declaration or statement");
4126 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4128 if (parser
->in_if_block
)
4130 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4131 error_at (loc
, """expected %<}%> before %<else%>");
4136 error_at (loc
, "%<else%> without a previous %<if%>");
4137 c_parser_consume_token (parser
);
4146 mark_valid_location_for_stdc_pragma (false);
4147 c_parser_statement_after_labels (parser
);
4150 parser
->error
= false;
4153 error_at (label_loc
, "label at end of compound statement");
4154 c_parser_consume_token (parser
);
4155 /* Restore the value we started with. */
4156 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4159 /* Parse a label (C90 6.6.1, C99 6.8.1).
4162 identifier : attributes[opt]
4163 case constant-expression :
4169 case constant-expression ... constant-expression :
4171 The use of attributes on labels is a GNU extension. The syntax in
4172 GNU C accepts any expressions without commas, non-constant
4173 expressions being rejected later. */
4176 c_parser_label (c_parser
*parser
)
4178 location_t loc1
= c_parser_peek_token (parser
)->location
;
4179 tree label
= NULL_TREE
;
4180 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4183 c_parser_consume_token (parser
);
4184 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4185 if (c_parser_next_token_is (parser
, CPP_COLON
))
4187 c_parser_consume_token (parser
);
4188 label
= do_case (loc1
, exp1
, NULL_TREE
);
4190 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4192 c_parser_consume_token (parser
);
4193 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4194 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4195 label
= do_case (loc1
, exp1
, exp2
);
4198 c_parser_error (parser
, "expected %<:%> or %<...%>");
4200 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4202 c_parser_consume_token (parser
);
4203 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4204 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4208 tree name
= c_parser_peek_token (parser
)->value
;
4211 location_t loc2
= c_parser_peek_token (parser
)->location
;
4212 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4213 c_parser_consume_token (parser
);
4214 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4215 c_parser_consume_token (parser
);
4216 attrs
= c_parser_attributes (parser
);
4217 tlab
= define_label (loc2
, name
);
4220 decl_attributes (&tlab
, attrs
, 0);
4221 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4226 if (c_parser_next_tokens_start_declaration (parser
))
4228 error_at (c_parser_peek_token (parser
)->location
,
4229 "a label can only be part of a statement and "
4230 "a declaration is not a statement");
4231 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4232 /*static_assert_ok*/ true,
4233 /*nested*/ true, /*empty_ok*/ false,
4234 /*start_attr_ok*/ true, NULL
);
4239 /* Parse a statement (C90 6.6, C99 6.8).
4244 expression-statement
4252 expression-statement:
4255 selection-statement:
4259 iteration-statement:
4268 return expression[opt] ;
4281 objc-throw-statement
4282 objc-try-catch-statement
4283 objc-synchronized-statement
4285 objc-throw-statement:
4299 parallel-for-construct
4300 parallel-sections-construct
4307 parallel-directive structured-block
4310 for-directive iteration-statement
4313 sections-directive section-scope
4316 single-directive structured-block
4318 parallel-for-construct:
4319 parallel-for-directive iteration-statement
4321 parallel-sections-construct:
4322 parallel-sections-directive section-scope
4325 master-directive structured-block
4328 critical-directive structured-block
4331 atomic-directive expression-statement
4334 ordered-directive structured-block */
4337 c_parser_statement (c_parser
*parser
)
4339 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4340 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4341 || (c_parser_next_token_is (parser
, CPP_NAME
)
4342 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4343 c_parser_label (parser
);
4344 c_parser_statement_after_labels (parser
);
4347 /* Parse a statement, other than a labeled statement. */
4350 c_parser_statement_after_labels (c_parser
*parser
)
4352 location_t loc
= c_parser_peek_token (parser
)->location
;
4353 tree stmt
= NULL_TREE
;
4354 bool in_if_block
= parser
->in_if_block
;
4355 parser
->in_if_block
= false;
4356 switch (c_parser_peek_token (parser
)->type
)
4358 case CPP_OPEN_BRACE
:
4359 add_stmt (c_parser_compound_statement (parser
));
4362 switch (c_parser_peek_token (parser
)->keyword
)
4365 c_parser_if_statement (parser
);
4368 c_parser_switch_statement (parser
);
4371 c_parser_while_statement (parser
);
4374 c_parser_do_statement (parser
);
4377 c_parser_for_statement (parser
);
4380 c_parser_consume_token (parser
);
4381 if (c_parser_next_token_is (parser
, CPP_NAME
))
4383 stmt
= c_finish_goto_label (loc
,
4384 c_parser_peek_token (parser
)->value
);
4385 c_parser_consume_token (parser
);
4387 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4391 c_parser_consume_token (parser
);
4392 val
= c_parser_expression (parser
).value
;
4393 mark_exp_read (val
);
4394 stmt
= c_finish_goto_ptr (loc
, val
);
4397 c_parser_error (parser
, "expected identifier or %<*%>");
4398 goto expect_semicolon
;
4400 c_parser_consume_token (parser
);
4401 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4402 goto expect_semicolon
;
4404 c_parser_consume_token (parser
);
4405 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4406 goto expect_semicolon
;
4408 c_parser_consume_token (parser
);
4409 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4411 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4412 c_parser_consume_token (parser
);
4416 struct c_expr expr
= c_parser_expression_conv (parser
);
4417 mark_exp_read (expr
.value
);
4418 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4419 goto expect_semicolon
;
4423 stmt
= c_parser_asm_statement (parser
);
4426 gcc_assert (c_dialect_objc ());
4427 c_parser_consume_token (parser
);
4428 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4430 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4431 c_parser_consume_token (parser
);
4435 tree expr
= c_parser_expression (parser
).value
;
4436 expr
= c_fully_fold (expr
, false, NULL
);
4437 stmt
= objc_build_throw_stmt (loc
, expr
);
4438 goto expect_semicolon
;
4442 gcc_assert (c_dialect_objc ());
4443 c_parser_objc_try_catch_finally_statement (parser
);
4445 case RID_AT_SYNCHRONIZED
:
4446 gcc_assert (c_dialect_objc ());
4447 c_parser_objc_synchronized_statement (parser
);
4454 c_parser_consume_token (parser
);
4456 case CPP_CLOSE_PAREN
:
4457 case CPP_CLOSE_SQUARE
:
4458 /* Avoid infinite loop in error recovery:
4459 c_parser_skip_until_found stops at a closing nesting
4460 delimiter without consuming it, but here we need to consume
4461 it to proceed further. */
4462 c_parser_error (parser
, "expected statement");
4463 c_parser_consume_token (parser
);
4466 c_parser_pragma (parser
, pragma_stmt
);
4470 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4472 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4475 /* Two cases cannot and do not have line numbers associated: If stmt
4476 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4477 cannot hold line numbers. But that's OK because the statement
4478 will either be changed to a MODIFY_EXPR during gimplification of
4479 the statement expr, or discarded. If stmt was compound, but
4480 without new variables, we will have skipped the creation of a
4481 BIND and will have a bare STATEMENT_LIST. But that's OK because
4482 (recursively) all of the component statements should already have
4483 line numbers assigned. ??? Can we discard no-op statements
4485 if (CAN_HAVE_LOCATION_P (stmt
)
4486 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4487 SET_EXPR_LOCATION (stmt
, loc
);
4489 parser
->in_if_block
= in_if_block
;
4492 /* Parse the condition from an if, do, while or for statements. */
4495 c_parser_condition (c_parser
*parser
)
4497 location_t loc
= c_parser_peek_token (parser
)->location
;
4499 cond
= c_parser_expression_conv (parser
).value
;
4500 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4501 cond
= c_fully_fold (cond
, false, NULL
);
4502 if (warn_sequence_point
)
4503 verify_sequence_points (cond
);
4507 /* Parse a parenthesized condition from an if, do or while statement.
4513 c_parser_paren_condition (c_parser
*parser
)
4516 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4517 return error_mark_node
;
4518 cond
= c_parser_condition (parser
);
4519 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4523 /* Parse a statement which is a block in C99. */
4526 c_parser_c99_block_statement (c_parser
*parser
)
4528 tree block
= c_begin_compound_stmt (flag_isoc99
);
4529 location_t loc
= c_parser_peek_token (parser
)->location
;
4530 c_parser_statement (parser
);
4531 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4534 /* Parse the body of an if statement. This is just parsing a
4535 statement but (a) it is a block in C99, (b) we track whether the
4536 body is an if statement for the sake of -Wparentheses warnings, (c)
4537 we handle an empty body specially for the sake of -Wempty-body
4538 warnings, and (d) we call parser_compound_statement directly
4539 because c_parser_statement_after_labels resets
4540 parser->in_if_block. */
4543 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4545 tree block
= c_begin_compound_stmt (flag_isoc99
);
4546 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4547 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4548 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4549 || (c_parser_next_token_is (parser
, CPP_NAME
)
4550 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4551 c_parser_label (parser
);
4552 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4553 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4555 location_t loc
= c_parser_peek_token (parser
)->location
;
4556 add_stmt (build_empty_stmt (loc
));
4557 c_parser_consume_token (parser
);
4558 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4559 warning_at (loc
, OPT_Wempty_body
,
4560 "suggest braces around empty body in an %<if%> statement");
4562 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4563 add_stmt (c_parser_compound_statement (parser
));
4565 c_parser_statement_after_labels (parser
);
4566 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4569 /* Parse the else body of an if statement. This is just parsing a
4570 statement but (a) it is a block in C99, (b) we handle an empty body
4571 specially for the sake of -Wempty-body warnings. */
4574 c_parser_else_body (c_parser
*parser
)
4576 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4577 tree block
= c_begin_compound_stmt (flag_isoc99
);
4578 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4579 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4580 || (c_parser_next_token_is (parser
, CPP_NAME
)
4581 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4582 c_parser_label (parser
);
4583 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4585 location_t loc
= c_parser_peek_token (parser
)->location
;
4588 "suggest braces around empty body in an %<else%> statement");
4589 add_stmt (build_empty_stmt (loc
));
4590 c_parser_consume_token (parser
);
4593 c_parser_statement_after_labels (parser
);
4594 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4597 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4600 if ( expression ) statement
4601 if ( expression ) statement else statement
4605 c_parser_if_statement (c_parser
*parser
)
4610 bool first_if
= false;
4611 tree first_body
, second_body
;
4614 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4615 c_parser_consume_token (parser
);
4616 block
= c_begin_compound_stmt (flag_isoc99
);
4617 loc
= c_parser_peek_token (parser
)->location
;
4618 cond
= c_parser_paren_condition (parser
);
4619 in_if_block
= parser
->in_if_block
;
4620 parser
->in_if_block
= true;
4621 first_body
= c_parser_if_body (parser
, &first_if
);
4622 parser
->in_if_block
= in_if_block
;
4623 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4625 c_parser_consume_token (parser
);
4626 second_body
= c_parser_else_body (parser
);
4629 second_body
= NULL_TREE
;
4630 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4631 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4634 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4637 switch (expression) statement
4641 c_parser_switch_statement (c_parser
*parser
)
4643 tree block
, expr
, body
, save_break
;
4644 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4645 location_t switch_cond_loc
;
4646 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4647 c_parser_consume_token (parser
);
4648 block
= c_begin_compound_stmt (flag_isoc99
);
4649 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4651 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4652 expr
= c_parser_expression (parser
).value
;
4653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4657 switch_cond_loc
= UNKNOWN_LOCATION
;
4658 expr
= error_mark_node
;
4660 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4661 save_break
= c_break_label
;
4662 c_break_label
= NULL_TREE
;
4663 body
= c_parser_c99_block_statement (parser
);
4664 c_finish_case (body
);
4667 location_t here
= c_parser_peek_token (parser
)->location
;
4668 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4669 SET_EXPR_LOCATION (t
, here
);
4672 c_break_label
= save_break
;
4673 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4676 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4679 while (expression) statement
4683 c_parser_while_statement (c_parser
*parser
)
4685 tree block
, cond
, body
, save_break
, save_cont
;
4687 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4688 c_parser_consume_token (parser
);
4689 block
= c_begin_compound_stmt (flag_isoc99
);
4690 loc
= c_parser_peek_token (parser
)->location
;
4691 cond
= c_parser_paren_condition (parser
);
4692 save_break
= c_break_label
;
4693 c_break_label
= NULL_TREE
;
4694 save_cont
= c_cont_label
;
4695 c_cont_label
= NULL_TREE
;
4696 body
= c_parser_c99_block_statement (parser
);
4697 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4698 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4699 c_break_label
= save_break
;
4700 c_cont_label
= save_cont
;
4703 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4706 do statement while ( expression ) ;
4710 c_parser_do_statement (c_parser
*parser
)
4712 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4714 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4715 c_parser_consume_token (parser
);
4716 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4717 warning_at (c_parser_peek_token (parser
)->location
,
4719 "suggest braces around empty body in %<do%> statement");
4720 block
= c_begin_compound_stmt (flag_isoc99
);
4721 loc
= c_parser_peek_token (parser
)->location
;
4722 save_break
= c_break_label
;
4723 c_break_label
= NULL_TREE
;
4724 save_cont
= c_cont_label
;
4725 c_cont_label
= NULL_TREE
;
4726 body
= c_parser_c99_block_statement (parser
);
4727 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4728 new_break
= c_break_label
;
4729 c_break_label
= save_break
;
4730 new_cont
= c_cont_label
;
4731 c_cont_label
= save_cont
;
4732 cond
= c_parser_paren_condition (parser
);
4733 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4734 c_parser_skip_to_end_of_block_or_statement (parser
);
4735 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4736 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4739 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4742 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4743 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4745 The form with a declaration is new in C99.
4747 ??? In accordance with the old parser, the declaration may be a
4748 nested function, which is then rejected in check_for_loop_decls,
4749 but does it make any sense for this to be included in the grammar?
4750 Note in particular that the nested function does not include a
4751 trailing ';', whereas the "declaration" production includes one.
4752 Also, can we reject bad declarations earlier and cheaper than
4753 check_for_loop_decls?
4755 In Objective-C, there are two additional variants:
4758 for ( expression in expresssion ) statement
4759 for ( declaration in expression ) statement
4761 This is inconsistent with C, because the second variant is allowed
4762 even if c99 is not enabled.
4764 The rest of the comment documents these Objective-C foreach-statement.
4766 Here is the canonical example of the first variant:
4767 for (object in array) { do something with object }
4768 we call the first expression ("object") the "object_expression" and
4769 the second expression ("array") the "collection_expression".
4770 object_expression must be an lvalue of type "id" (a generic Objective-C
4771 object) because the loop works by assigning to object_expression the
4772 various objects from the collection_expression. collection_expression
4773 must evaluate to something of type "id" which responds to the method
4774 countByEnumeratingWithState:objects:count:.
4776 The canonical example of the second variant is:
4777 for (id object in array) { do something with object }
4778 which is completely equivalent to
4781 for (object in array) { do something with object }
4783 Note that initizializing 'object' in some way (eg, "for ((object =
4784 xxx) in array) { do something with object }") is possibly
4785 technically valid, but completely pointless as 'object' will be
4786 assigned to something else as soon as the loop starts. We should
4787 most likely reject it (TODO).
4789 The beginning of the Objective-C foreach-statement looks exactly
4790 like the beginning of the for-statement, and we can tell it is a
4791 foreach-statement only because the initial declaration or
4792 expression is terminated by 'in' instead of ';'.
4796 c_parser_for_statement (c_parser
*parser
)
4798 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4799 /* The following are only used when parsing an ObjC foreach statement. */
4800 tree object_expression
;
4801 /* Silence the bogus uninitialized warning. */
4802 tree collection_expression
= NULL
;
4803 location_t loc
= c_parser_peek_token (parser
)->location
;
4804 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4805 bool is_foreach_statement
= false;
4806 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4807 c_parser_consume_token (parser
);
4808 /* Open a compound statement in Objective-C as well, just in case this is
4809 as foreach expression. */
4810 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4811 cond
= error_mark_node
;
4812 incr
= error_mark_node
;
4813 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4815 /* Parse the initialization declaration or expression. */
4816 object_expression
= error_mark_node
;
4817 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4818 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4820 parser
->objc_could_be_foreach_context
= false;
4821 c_parser_consume_token (parser
);
4822 c_finish_expr_stmt (loc
, NULL_TREE
);
4824 else if (c_parser_next_tokens_start_declaration (parser
))
4826 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4827 &object_expression
);
4828 parser
->objc_could_be_foreach_context
= false;
4830 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4832 c_parser_consume_token (parser
);
4833 is_foreach_statement
= true;
4834 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4835 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4838 check_for_loop_decls (for_loc
, flag_isoc99
);
4840 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4842 /* __extension__ can start a declaration, but is also an
4843 unary operator that can start an expression. Consume all
4844 but the last of a possible series of __extension__ to
4846 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4847 && (c_parser_peek_2nd_token (parser
)->keyword
4849 c_parser_consume_token (parser
);
4850 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4853 ext
= disable_extension_diagnostics ();
4854 c_parser_consume_token (parser
);
4855 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4856 true, &object_expression
);
4857 parser
->objc_could_be_foreach_context
= false;
4859 restore_extension_diagnostics (ext
);
4860 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4862 c_parser_consume_token (parser
);
4863 is_foreach_statement
= true;
4864 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4865 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4868 check_for_loop_decls (for_loc
, flag_isoc99
);
4877 tree init_expression
;
4878 init_expression
= c_parser_expression (parser
).value
;
4879 parser
->objc_could_be_foreach_context
= false;
4880 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4882 c_parser_consume_token (parser
);
4883 is_foreach_statement
= true;
4884 if (! lvalue_p (init_expression
))
4885 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
4886 object_expression
= c_fully_fold (init_expression
, false, NULL
);
4890 c_finish_expr_stmt (loc
, init_expression
);
4891 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4895 /* Parse the loop condition. In the case of a foreach
4896 statement, there is no loop condition. */
4897 gcc_assert (!parser
->objc_could_be_foreach_context
);
4898 if (!is_foreach_statement
)
4900 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4902 c_parser_consume_token (parser
);
4907 cond
= c_parser_condition (parser
);
4908 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4911 /* Parse the increment expression (the third expression in a
4912 for-statement). In the case of a foreach-statement, this is
4913 the expression that follows the 'in'. */
4914 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4916 if (is_foreach_statement
)
4918 c_parser_error (parser
, "missing collection in fast enumeration");
4919 collection_expression
= error_mark_node
;
4922 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4926 if (is_foreach_statement
)
4927 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
4930 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4932 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4934 save_break
= c_break_label
;
4935 c_break_label
= NULL_TREE
;
4936 save_cont
= c_cont_label
;
4937 c_cont_label
= NULL_TREE
;
4938 body
= c_parser_c99_block_statement (parser
);
4939 if (is_foreach_statement
)
4940 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
4942 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4943 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
4944 c_break_label
= save_break
;
4945 c_cont_label
= save_cont
;
4948 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4949 statement with inputs, outputs, clobbers, and volatile tag
4953 asm type-qualifier[opt] ( asm-argument ) ;
4954 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4958 asm-string-literal : asm-operands[opt]
4959 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4960 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4963 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4966 Qualifiers other than volatile are accepted in the syntax but
4970 c_parser_asm_statement (c_parser
*parser
)
4972 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4973 bool simple
, is_goto
;
4974 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4975 int section
, nsections
;
4977 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4978 c_parser_consume_token (parser
);
4979 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4981 quals
= c_parser_peek_token (parser
)->value
;
4982 c_parser_consume_token (parser
);
4984 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4985 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4987 warning_at (c_parser_peek_token (parser
)->location
,
4989 "%E qualifier ignored on asm",
4990 c_parser_peek_token (parser
)->value
);
4992 c_parser_consume_token (parser
);
4998 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5000 c_parser_consume_token (parser
);
5004 /* ??? Follow the C++ parser rather than using the
5005 lex_untranslated_string kludge. */
5006 parser
->lex_untranslated_string
= true;
5009 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5012 str
= c_parser_asm_string_literal (parser
);
5013 if (str
== NULL_TREE
)
5014 goto error_close_paren
;
5017 outputs
= NULL_TREE
;
5019 clobbers
= NULL_TREE
;
5022 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5025 /* Parse each colon-delimited section of operands. */
5026 nsections
= 3 + is_goto
;
5027 for (section
= 0; section
< nsections
; ++section
)
5029 if (!c_parser_require (parser
, CPP_COLON
,
5032 : "expected %<:%> or %<)%>"))
5033 goto error_close_paren
;
5035 /* Once past any colon, we're no longer a simple asm. */
5038 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5039 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5044 /* For asm goto, we don't allow output operands, but reserve
5045 the slot for a future extension that does allow them. */
5047 outputs
= c_parser_asm_operands (parser
, false);
5050 inputs
= c_parser_asm_operands (parser
, true);
5053 clobbers
= c_parser_asm_clobbers (parser
);
5056 labels
= c_parser_asm_goto_operands (parser
);
5062 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5067 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5069 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5073 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5074 c_parser_skip_to_end_of_block_or_statement (parser
);
5076 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5077 clobbers
, labels
, simple
));
5080 parser
->lex_untranslated_string
= false;
5084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5088 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5089 not outputs), apply the default conversion of functions and arrays
5094 asm-operands , asm-operand
5097 asm-string-literal ( expression )
5098 [ identifier ] asm-string-literal ( expression )
5102 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
5104 tree list
= NULL_TREE
;
5110 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5112 c_parser_consume_token (parser
);
5113 if (c_parser_next_token_is (parser
, CPP_NAME
))
5115 tree id
= c_parser_peek_token (parser
)->value
;
5116 c_parser_consume_token (parser
);
5117 name
= build_string (IDENTIFIER_LENGTH (id
),
5118 IDENTIFIER_POINTER (id
));
5122 c_parser_error (parser
, "expected identifier");
5123 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5126 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5131 str
= c_parser_asm_string_literal (parser
);
5132 if (str
== NULL_TREE
)
5134 parser
->lex_untranslated_string
= false;
5135 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5137 parser
->lex_untranslated_string
= true;
5140 loc
= c_parser_peek_token (parser
)->location
;
5141 expr
= c_parser_expression (parser
);
5142 mark_exp_read (expr
.value
);
5144 expr
= default_function_array_conversion (loc
, expr
);
5145 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5146 parser
->lex_untranslated_string
= true;
5147 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5149 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5152 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5154 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5155 c_parser_consume_token (parser
);
5162 /* Parse asm clobbers, a GNU extension.
5166 asm-clobbers , asm-string-literal
5170 c_parser_asm_clobbers (c_parser
*parser
)
5172 tree list
= NULL_TREE
;
5175 tree str
= c_parser_asm_string_literal (parser
);
5177 list
= tree_cons (NULL_TREE
, str
, list
);
5180 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5181 c_parser_consume_token (parser
);
5188 /* Parse asm goto labels, a GNU extension.
5192 asm-goto-operands , identifier
5196 c_parser_asm_goto_operands (c_parser
*parser
)
5198 tree list
= NULL_TREE
;
5203 if (c_parser_next_token_is (parser
, CPP_NAME
))
5205 c_token
*tok
= c_parser_peek_token (parser
);
5207 label
= lookup_label_for_goto (tok
->location
, name
);
5208 c_parser_consume_token (parser
);
5209 TREE_USED (label
) = 1;
5213 c_parser_error (parser
, "expected identifier");
5217 name
= build_string (IDENTIFIER_LENGTH (name
),
5218 IDENTIFIER_POINTER (name
));
5219 list
= tree_cons (name
, label
, list
);
5220 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5221 c_parser_consume_token (parser
);
5223 return nreverse (list
);
5227 /* Parse an expression other than a compound expression; that is, an
5228 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5229 NULL then it is an Objective-C message expression which is the
5230 primary-expression starting the expression as an initializer.
5232 assignment-expression:
5233 conditional-expression
5234 unary-expression assignment-operator assignment-expression
5236 assignment-operator: one of
5237 = *= /= %= += -= <<= >>= &= ^= |=
5239 In GNU C we accept any conditional expression on the LHS and
5240 diagnose the invalid lvalue rather than producing a syntax
5243 static struct c_expr
5244 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5246 struct c_expr lhs
, rhs
, ret
;
5247 enum tree_code code
;
5248 location_t op_location
, exp_location
;
5249 gcc_assert (!after
|| c_dialect_objc ());
5250 lhs
= c_parser_conditional_expression (parser
, after
);
5251 op_location
= c_parser_peek_token (parser
)->location
;
5252 switch (c_parser_peek_token (parser
)->type
)
5261 code
= TRUNC_DIV_EXPR
;
5264 code
= TRUNC_MOD_EXPR
;
5279 code
= BIT_AND_EXPR
;
5282 code
= BIT_XOR_EXPR
;
5285 code
= BIT_IOR_EXPR
;
5290 c_parser_consume_token (parser
);
5291 exp_location
= c_parser_peek_token (parser
)->location
;
5292 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5293 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5294 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5295 code
, exp_location
, rhs
.value
,
5297 if (code
== NOP_EXPR
)
5298 ret
.original_code
= MODIFY_EXPR
;
5301 TREE_NO_WARNING (ret
.value
) = 1;
5302 ret
.original_code
= ERROR_MARK
;
5304 ret
.original_type
= NULL
;
5308 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5309 is not NULL then it is an Objective-C message expression which is
5310 the primary-expression starting the expression as an initializer.
5312 conditional-expression:
5313 logical-OR-expression
5314 logical-OR-expression ? expression : conditional-expression
5318 conditional-expression:
5319 logical-OR-expression ? : conditional-expression
5322 static struct c_expr
5323 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5325 struct c_expr cond
, exp1
, exp2
, ret
;
5326 location_t cond_loc
, colon_loc
, middle_loc
;
5328 gcc_assert (!after
|| c_dialect_objc ());
5330 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5332 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5334 cond_loc
= c_parser_peek_token (parser
)->location
;
5335 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5336 c_parser_consume_token (parser
);
5337 if (c_parser_next_token_is (parser
, CPP_COLON
))
5339 tree eptype
= NULL_TREE
;
5341 middle_loc
= c_parser_peek_token (parser
)->location
;
5342 pedwarn (middle_loc
, OPT_pedantic
,
5343 "ISO C forbids omitting the middle term of a ?: expression");
5344 warn_for_omitted_condop (middle_loc
, cond
.value
);
5345 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5347 eptype
= TREE_TYPE (cond
.value
);
5348 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5350 /* Make sure first operand is calculated only once. */
5351 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5353 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5354 exp1
.original_type
= NULL
;
5355 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5356 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5361 = c_objc_common_truthvalue_conversion
5362 (cond_loc
, default_conversion (cond
.value
));
5363 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5364 exp1
= c_parser_expression_conv (parser
);
5365 mark_exp_read (exp1
.value
);
5366 c_inhibit_evaluation_warnings
+=
5367 ((cond
.value
== truthvalue_true_node
)
5368 - (cond
.value
== truthvalue_false_node
));
5371 colon_loc
= c_parser_peek_token (parser
)->location
;
5372 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5374 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5375 ret
.value
= error_mark_node
;
5376 ret
.original_code
= ERROR_MARK
;
5377 ret
.original_type
= NULL
;
5381 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5382 exp2
= c_parser_conditional_expression (parser
, NULL
);
5383 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5385 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5386 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5387 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5388 exp1
.value
, exp1
.original_type
,
5389 exp2
.value
, exp2
.original_type
);
5390 ret
.original_code
= ERROR_MARK
;
5391 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5392 ret
.original_type
= NULL
;
5397 /* If both sides are enum type, the default conversion will have
5398 made the type of the result be an integer type. We want to
5399 remember the enum types we started with. */
5400 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5401 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5402 ret
.original_type
= ((t1
!= error_mark_node
5403 && t2
!= error_mark_node
5404 && (TYPE_MAIN_VARIANT (t1
)
5405 == TYPE_MAIN_VARIANT (t2
)))
5412 /* Parse a binary expression; that is, a logical-OR-expression (C90
5413 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5414 an Objective-C message expression which is the primary-expression
5415 starting the expression as an initializer. PREC is the starting
5416 precedence, usually PREC_NONE.
5418 multiplicative-expression:
5420 multiplicative-expression * cast-expression
5421 multiplicative-expression / cast-expression
5422 multiplicative-expression % cast-expression
5424 additive-expression:
5425 multiplicative-expression
5426 additive-expression + multiplicative-expression
5427 additive-expression - multiplicative-expression
5431 shift-expression << additive-expression
5432 shift-expression >> additive-expression
5434 relational-expression:
5436 relational-expression < shift-expression
5437 relational-expression > shift-expression
5438 relational-expression <= shift-expression
5439 relational-expression >= shift-expression
5441 equality-expression:
5442 relational-expression
5443 equality-expression == relational-expression
5444 equality-expression != relational-expression
5448 AND-expression & equality-expression
5450 exclusive-OR-expression:
5452 exclusive-OR-expression ^ AND-expression
5454 inclusive-OR-expression:
5455 exclusive-OR-expression
5456 inclusive-OR-expression | exclusive-OR-expression
5458 logical-AND-expression:
5459 inclusive-OR-expression
5460 logical-AND-expression && inclusive-OR-expression
5462 logical-OR-expression:
5463 logical-AND-expression
5464 logical-OR-expression || logical-AND-expression
5467 static struct c_expr
5468 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5469 enum c_parser_prec prec
)
5471 /* A binary expression is parsed using operator-precedence parsing,
5472 with the operands being cast expressions. All the binary
5473 operators are left-associative. Thus a binary expression is of
5476 E0 op1 E1 op2 E2 ...
5478 which we represent on a stack. On the stack, the precedence
5479 levels are strictly increasing. When a new operator is
5480 encountered of higher precedence than that at the top of the
5481 stack, it is pushed; its LHS is the top expression, and its RHS
5482 is everything parsed until it is popped. When a new operator is
5483 encountered with precedence less than or equal to that at the top
5484 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5485 by the result of the operation until the operator at the top of
5486 the stack has lower precedence than the new operator or there is
5487 only one element on the stack; then the top expression is the LHS
5488 of the new operator. In the case of logical AND and OR
5489 expressions, we also need to adjust c_inhibit_evaluation_warnings
5490 as appropriate when the operators are pushed and popped. */
5493 /* The expression at this stack level. */
5495 /* The precedence of the operator on its left, PREC_NONE at the
5496 bottom of the stack. */
5497 enum c_parser_prec prec
;
5498 /* The operation on its left. */
5500 /* The source location of this operation. */
5504 /* Location of the binary operator. */
5505 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5508 switch (stack[sp].op) \
5510 case TRUTH_ANDIF_EXPR: \
5511 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5512 == truthvalue_false_node); \
5514 case TRUTH_ORIF_EXPR: \
5515 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5516 == truthvalue_true_node); \
5521 stack[sp - 1].expr \
5522 = default_function_array_read_conversion (stack[sp - 1].loc, \
5523 stack[sp - 1].expr); \
5525 = default_function_array_read_conversion (stack[sp].loc, \
5527 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5529 stack[sp - 1].expr, \
5533 gcc_assert (!after
|| c_dialect_objc ());
5534 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5535 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5536 stack
[0].prec
= prec
;
5540 enum c_parser_prec oprec
;
5541 enum tree_code ocode
;
5544 switch (c_parser_peek_token (parser
)->type
)
5552 ocode
= TRUNC_DIV_EXPR
;
5556 ocode
= TRUNC_MOD_EXPR
;
5568 ocode
= LSHIFT_EXPR
;
5572 ocode
= RSHIFT_EXPR
;
5586 case CPP_GREATER_EQ
:
5599 oprec
= PREC_BITAND
;
5600 ocode
= BIT_AND_EXPR
;
5603 oprec
= PREC_BITXOR
;
5604 ocode
= BIT_XOR_EXPR
;
5608 ocode
= BIT_IOR_EXPR
;
5611 oprec
= PREC_LOGAND
;
5612 ocode
= TRUTH_ANDIF_EXPR
;
5616 ocode
= TRUTH_ORIF_EXPR
;
5619 /* Not a binary operator, so end of the binary
5623 binary_loc
= c_parser_peek_token (parser
)->location
;
5624 while (oprec
<= stack
[sp
].prec
)
5630 c_parser_consume_token (parser
);
5633 case TRUTH_ANDIF_EXPR
:
5635 = default_function_array_read_conversion (stack
[sp
].loc
,
5637 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5638 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5639 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5640 == truthvalue_false_node
);
5642 case TRUTH_ORIF_EXPR
:
5644 = default_function_array_read_conversion (stack
[sp
].loc
,
5646 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5647 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5648 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5649 == truthvalue_true_node
);
5655 stack
[sp
].loc
= binary_loc
;
5656 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5657 stack
[sp
].prec
= oprec
;
5658 stack
[sp
].op
= ocode
;
5659 stack
[sp
].loc
= binary_loc
;
5664 return stack
[0].expr
;
5668 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5669 NULL then it is an Objective-C message expression which is the
5670 primary-expression starting the expression as an initializer.
5674 ( type-name ) unary-expression
5677 static struct c_expr
5678 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5680 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5681 gcc_assert (!after
|| c_dialect_objc ());
5683 return c_parser_postfix_expression_after_primary (parser
,
5685 /* If the expression begins with a parenthesized type name, it may
5686 be either a cast or a compound literal; we need to see whether
5687 the next character is '{' to tell the difference. If not, it is
5688 an unary expression. Full detection of unknown typenames here
5689 would require a 3-token lookahead. */
5690 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5691 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5693 struct c_type_name
*type_name
;
5696 c_parser_consume_token (parser
);
5697 type_name
= c_parser_type_name (parser
);
5698 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5699 if (type_name
== NULL
)
5701 ret
.value
= error_mark_node
;
5702 ret
.original_code
= ERROR_MARK
;
5703 ret
.original_type
= NULL
;
5707 /* Save casted types in the function's used types hash table. */
5708 used_types_insert (type_name
->specs
->type
);
5710 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5711 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5714 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5715 expr
= c_parser_cast_expression (parser
, NULL
);
5716 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5718 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5719 ret
.original_code
= ERROR_MARK
;
5720 ret
.original_type
= NULL
;
5724 return c_parser_unary_expression (parser
);
5727 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5733 unary-operator cast-expression
5734 sizeof unary-expression
5735 sizeof ( type-name )
5737 unary-operator: one of
5743 __alignof__ unary-expression
5744 __alignof__ ( type-name )
5747 unary-operator: one of
5748 __extension__ __real__ __imag__
5750 In addition, the GNU syntax treats ++ and -- as unary operators, so
5751 they may be applied to cast expressions with errors for non-lvalues
5754 static struct c_expr
5755 c_parser_unary_expression (c_parser
*parser
)
5758 struct c_expr ret
, op
;
5759 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5761 ret
.original_code
= ERROR_MARK
;
5762 ret
.original_type
= NULL
;
5763 switch (c_parser_peek_token (parser
)->type
)
5766 c_parser_consume_token (parser
);
5767 exp_loc
= c_parser_peek_token (parser
)->location
;
5768 op
= c_parser_cast_expression (parser
, NULL
);
5769 op
= default_function_array_read_conversion (exp_loc
, op
);
5770 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5771 case CPP_MINUS_MINUS
:
5772 c_parser_consume_token (parser
);
5773 exp_loc
= c_parser_peek_token (parser
)->location
;
5774 op
= c_parser_cast_expression (parser
, NULL
);
5775 op
= default_function_array_read_conversion (exp_loc
, op
);
5776 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5778 c_parser_consume_token (parser
);
5779 op
= c_parser_cast_expression (parser
, NULL
);
5780 mark_exp_read (op
.value
);
5781 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5783 c_parser_consume_token (parser
);
5784 exp_loc
= c_parser_peek_token (parser
)->location
;
5785 op
= c_parser_cast_expression (parser
, NULL
);
5786 op
= default_function_array_read_conversion (exp_loc
, op
);
5787 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5790 if (!c_dialect_objc () && !in_system_header
)
5793 "traditional C rejects the unary plus operator");
5794 c_parser_consume_token (parser
);
5795 exp_loc
= c_parser_peek_token (parser
)->location
;
5796 op
= c_parser_cast_expression (parser
, NULL
);
5797 op
= default_function_array_read_conversion (exp_loc
, op
);
5798 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5800 c_parser_consume_token (parser
);
5801 exp_loc
= c_parser_peek_token (parser
)->location
;
5802 op
= c_parser_cast_expression (parser
, NULL
);
5803 op
= default_function_array_read_conversion (exp_loc
, op
);
5804 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5806 c_parser_consume_token (parser
);
5807 exp_loc
= c_parser_peek_token (parser
)->location
;
5808 op
= c_parser_cast_expression (parser
, NULL
);
5809 op
= default_function_array_read_conversion (exp_loc
, op
);
5810 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5812 c_parser_consume_token (parser
);
5813 exp_loc
= c_parser_peek_token (parser
)->location
;
5814 op
= c_parser_cast_expression (parser
, NULL
);
5815 op
= default_function_array_read_conversion (exp_loc
, op
);
5816 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5818 /* Refer to the address of a label as a pointer. */
5819 c_parser_consume_token (parser
);
5820 if (c_parser_next_token_is (parser
, CPP_NAME
))
5822 ret
.value
= finish_label_address_expr
5823 (c_parser_peek_token (parser
)->value
, op_loc
);
5824 c_parser_consume_token (parser
);
5828 c_parser_error (parser
, "expected identifier");
5829 ret
.value
= error_mark_node
;
5833 switch (c_parser_peek_token (parser
)->keyword
)
5836 return c_parser_sizeof_expression (parser
);
5838 return c_parser_alignof_expression (parser
);
5840 c_parser_consume_token (parser
);
5841 ext
= disable_extension_diagnostics ();
5842 ret
= c_parser_cast_expression (parser
, NULL
);
5843 restore_extension_diagnostics (ext
);
5846 c_parser_consume_token (parser
);
5847 exp_loc
= c_parser_peek_token (parser
)->location
;
5848 op
= c_parser_cast_expression (parser
, NULL
);
5849 op
= default_function_array_conversion (exp_loc
, op
);
5850 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5852 c_parser_consume_token (parser
);
5853 exp_loc
= c_parser_peek_token (parser
)->location
;
5854 op
= c_parser_cast_expression (parser
, NULL
);
5855 op
= default_function_array_conversion (exp_loc
, op
);
5856 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5858 return c_parser_postfix_expression (parser
);
5861 return c_parser_postfix_expression (parser
);
5865 /* Parse a sizeof expression. */
5867 static struct c_expr
5868 c_parser_sizeof_expression (c_parser
*parser
)
5871 location_t expr_loc
;
5872 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5873 c_parser_consume_token (parser
);
5874 c_inhibit_evaluation_warnings
++;
5876 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5877 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5879 /* Either sizeof ( type-name ) or sizeof unary-expression
5880 starting with a compound literal. */
5881 struct c_type_name
*type_name
;
5882 c_parser_consume_token (parser
);
5883 expr_loc
= c_parser_peek_token (parser
)->location
;
5884 type_name
= c_parser_type_name (parser
);
5885 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5886 if (type_name
== NULL
)
5889 c_inhibit_evaluation_warnings
--;
5891 ret
.value
= error_mark_node
;
5892 ret
.original_code
= ERROR_MARK
;
5893 ret
.original_type
= NULL
;
5896 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5898 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5903 /* sizeof ( type-name ). */
5904 c_inhibit_evaluation_warnings
--;
5906 return c_expr_sizeof_type (expr_loc
, type_name
);
5910 expr_loc
= c_parser_peek_token (parser
)->location
;
5911 expr
= c_parser_unary_expression (parser
);
5913 c_inhibit_evaluation_warnings
--;
5915 mark_exp_read (expr
.value
);
5916 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5917 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5918 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5919 return c_expr_sizeof_expr (expr_loc
, expr
);
5923 /* Parse an alignof expression. */
5925 static struct c_expr
5926 c_parser_alignof_expression (c_parser
*parser
)
5929 location_t loc
= c_parser_peek_token (parser
)->location
;
5930 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5931 c_parser_consume_token (parser
);
5932 c_inhibit_evaluation_warnings
++;
5934 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5935 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5937 /* Either __alignof__ ( type-name ) or __alignof__
5938 unary-expression starting with a compound literal. */
5940 struct c_type_name
*type_name
;
5942 c_parser_consume_token (parser
);
5943 loc
= c_parser_peek_token (parser
)->location
;
5944 type_name
= c_parser_type_name (parser
);
5945 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5946 if (type_name
== NULL
)
5949 c_inhibit_evaluation_warnings
--;
5951 ret
.value
= error_mark_node
;
5952 ret
.original_code
= ERROR_MARK
;
5953 ret
.original_type
= NULL
;
5956 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5958 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5963 /* alignof ( type-name ). */
5964 c_inhibit_evaluation_warnings
--;
5966 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5967 ret
.original_code
= ERROR_MARK
;
5968 ret
.original_type
= NULL
;
5974 expr
= c_parser_unary_expression (parser
);
5976 mark_exp_read (expr
.value
);
5977 c_inhibit_evaluation_warnings
--;
5979 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5980 ret
.original_code
= ERROR_MARK
;
5981 ret
.original_type
= NULL
;
5986 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5990 postfix-expression [ expression ]
5991 postfix-expression ( argument-expression-list[opt] )
5992 postfix-expression . identifier
5993 postfix-expression -> identifier
5994 postfix-expression ++
5995 postfix-expression --
5996 ( type-name ) { initializer-list }
5997 ( type-name ) { initializer-list , }
5999 argument-expression-list:
6001 argument-expression-list , argument-expression
6013 (treated as a keyword in GNU C)
6016 ( compound-statement )
6017 __builtin_va_arg ( assignment-expression , type-name )
6018 __builtin_offsetof ( type-name , offsetof-member-designator )
6019 __builtin_choose_expr ( assignment-expression ,
6020 assignment-expression ,
6021 assignment-expression )
6022 __builtin_types_compatible_p ( type-name , type-name )
6024 offsetof-member-designator:
6026 offsetof-member-designator . identifier
6027 offsetof-member-designator [ expression ]
6032 [ objc-receiver objc-message-args ]
6033 @selector ( objc-selector-arg )
6034 @protocol ( identifier )
6035 @encode ( type-name )
6037 Classname . identifier
6040 static struct c_expr
6041 c_parser_postfix_expression (c_parser
*parser
)
6043 struct c_expr expr
, e1
, e2
, e3
;
6044 struct c_type_name
*t1
, *t2
;
6045 location_t loc
= c_parser_peek_token (parser
)->location
;;
6046 expr
.original_code
= ERROR_MARK
;
6047 expr
.original_type
= NULL
;
6048 switch (c_parser_peek_token (parser
)->type
)
6051 expr
.value
= c_parser_peek_token (parser
)->value
;
6052 loc
= c_parser_peek_token (parser
)->location
;
6053 c_parser_consume_token (parser
);
6054 if (TREE_CODE (expr
.value
) == FIXED_CST
6055 && !targetm
.fixed_point_supported_p ())
6057 error_at (loc
, "fixed-point types not supported for this target");
6058 expr
.value
= error_mark_node
;
6065 expr
.value
= c_parser_peek_token (parser
)->value
;
6066 c_parser_consume_token (parser
);
6072 case CPP_UTF8STRING
:
6073 expr
.value
= c_parser_peek_token (parser
)->value
;
6074 expr
.original_code
= STRING_CST
;
6075 c_parser_consume_token (parser
);
6077 case CPP_OBJC_STRING
:
6078 gcc_assert (c_dialect_objc ());
6080 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6081 c_parser_consume_token (parser
);
6084 switch (c_parser_peek_token (parser
)->id_kind
)
6088 tree id
= c_parser_peek_token (parser
)->value
;
6089 c_parser_consume_token (parser
);
6090 expr
.value
= build_external_ref (loc
, id
,
6091 (c_parser_peek_token (parser
)->type
6093 &expr
.original_type
);
6096 case C_ID_CLASSNAME
:
6098 /* Here we parse the Objective-C 2.0 Class.name dot
6100 tree class_name
= c_parser_peek_token (parser
)->value
;
6102 c_parser_consume_token (parser
);
6103 gcc_assert (c_dialect_objc ());
6104 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6106 expr
.value
= error_mark_node
;
6109 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6111 c_parser_error (parser
, "expected identifier");
6112 expr
.value
= error_mark_node
;
6115 component
= c_parser_peek_token (parser
)->value
;
6116 c_parser_consume_token (parser
);
6117 expr
.value
= objc_build_class_component_ref (class_name
,
6122 c_parser_error (parser
, "expected expression");
6123 expr
.value
= error_mark_node
;
6127 case CPP_OPEN_PAREN
:
6128 /* A parenthesized expression, statement expression or compound
6130 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6132 /* A statement expression. */
6134 location_t brace_loc
;
6135 c_parser_consume_token (parser
);
6136 brace_loc
= c_parser_peek_token (parser
)->location
;
6137 c_parser_consume_token (parser
);
6138 if (!building_stmt_list_p ())
6140 error_at (loc
, "braced-group within expression allowed "
6141 "only inside a function");
6142 parser
->error
= true;
6143 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6144 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6145 expr
.value
= error_mark_node
;
6148 stmt
= c_begin_stmt_expr ();
6149 c_parser_compound_statement_nostart (parser
);
6150 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6152 pedwarn (loc
, OPT_pedantic
,
6153 "ISO C forbids braced-groups within expressions");
6154 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6155 mark_exp_read (expr
.value
);
6157 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6159 /* A compound literal. ??? Can we actually get here rather
6160 than going directly to
6161 c_parser_postfix_expression_after_paren_type from
6164 struct c_type_name
*type_name
;
6165 c_parser_consume_token (parser
);
6166 loc
= c_parser_peek_token (parser
)->location
;
6167 type_name
= c_parser_type_name (parser
);
6168 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6170 if (type_name
== NULL
)
6172 expr
.value
= error_mark_node
;
6175 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6181 /* A parenthesized expression. */
6182 c_parser_consume_token (parser
);
6183 expr
= c_parser_expression (parser
);
6184 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6185 TREE_NO_WARNING (expr
.value
) = 1;
6186 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6187 expr
.original_code
= ERROR_MARK
;
6188 /* Don't change EXPR.ORIGINAL_TYPE. */
6189 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6194 switch (c_parser_peek_token (parser
)->keyword
)
6196 case RID_FUNCTION_NAME
:
6197 case RID_PRETTY_FUNCTION_NAME
:
6198 case RID_C99_FUNCTION_NAME
:
6199 expr
.value
= fname_decl (loc
,
6200 c_parser_peek_token (parser
)->keyword
,
6201 c_parser_peek_token (parser
)->value
);
6202 c_parser_consume_token (parser
);
6205 c_parser_consume_token (parser
);
6206 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6208 expr
.value
= error_mark_node
;
6211 e1
= c_parser_expr_no_commas (parser
, NULL
);
6212 mark_exp_read (e1
.value
);
6213 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6214 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6216 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6217 expr
.value
= error_mark_node
;
6220 loc
= c_parser_peek_token (parser
)->location
;
6221 t1
= c_parser_type_name (parser
);
6222 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6226 expr
.value
= error_mark_node
;
6230 tree type_expr
= NULL_TREE
;
6231 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6232 groktypename (t1
, &type_expr
, NULL
));
6235 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6236 TREE_TYPE (expr
.value
), type_expr
,
6238 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6243 c_parser_consume_token (parser
);
6244 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6246 expr
.value
= error_mark_node
;
6249 t1
= c_parser_type_name (parser
);
6251 parser
->error
= true;
6252 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6253 gcc_assert (parser
->error
);
6256 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6257 expr
.value
= error_mark_node
;
6262 tree type
= groktypename (t1
, NULL
, NULL
);
6264 if (type
== error_mark_node
)
6265 offsetof_ref
= error_mark_node
;
6268 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6269 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6271 /* Parse the second argument to __builtin_offsetof. We
6272 must have one identifier, and beyond that we want to
6273 accept sub structure and sub array references. */
6274 if (c_parser_next_token_is (parser
, CPP_NAME
))
6276 offsetof_ref
= build_component_ref
6277 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6278 c_parser_consume_token (parser
);
6279 while (c_parser_next_token_is (parser
, CPP_DOT
)
6280 || c_parser_next_token_is (parser
,
6282 || c_parser_next_token_is (parser
,
6285 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6287 loc
= c_parser_peek_token (parser
)->location
;
6288 offsetof_ref
= build_array_ref (loc
,
6293 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6296 c_parser_consume_token (parser
);
6297 if (c_parser_next_token_is_not (parser
,
6300 c_parser_error (parser
, "expected identifier");
6303 offsetof_ref
= build_component_ref
6305 c_parser_peek_token (parser
)->value
);
6306 c_parser_consume_token (parser
);
6311 loc
= c_parser_peek_token (parser
)->location
;
6312 c_parser_consume_token (parser
);
6313 idx
= c_parser_expression (parser
).value
;
6314 idx
= c_fully_fold (idx
, false, NULL
);
6315 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6317 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6322 c_parser_error (parser
, "expected identifier");
6323 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6325 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
6328 case RID_CHOOSE_EXPR
:
6329 c_parser_consume_token (parser
);
6330 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6332 expr
.value
= error_mark_node
;
6335 loc
= c_parser_peek_token (parser
)->location
;
6336 e1
= c_parser_expr_no_commas (parser
, NULL
);
6337 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6339 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6340 expr
.value
= error_mark_node
;
6343 e2
= c_parser_expr_no_commas (parser
, NULL
);
6344 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6346 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6347 expr
.value
= error_mark_node
;
6350 e3
= c_parser_expr_no_commas (parser
, NULL
);
6351 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6357 mark_exp_read (e2
.value
);
6358 mark_exp_read (e3
.value
);
6359 if (TREE_CODE (c
) != INTEGER_CST
6360 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6362 "first argument to %<__builtin_choose_expr%> not"
6364 constant_expression_warning (c
);
6365 expr
= integer_zerop (c
) ? e3
: e2
;
6368 case RID_TYPES_COMPATIBLE_P
:
6369 c_parser_consume_token (parser
);
6370 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6372 expr
.value
= error_mark_node
;
6375 t1
= c_parser_type_name (parser
);
6378 expr
.value
= error_mark_node
;
6381 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6383 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6384 expr
.value
= error_mark_node
;
6387 t2
= c_parser_type_name (parser
);
6390 expr
.value
= error_mark_node
;
6393 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6398 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
6399 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
6402 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6405 case RID_AT_SELECTOR
:
6406 gcc_assert (c_dialect_objc ());
6407 c_parser_consume_token (parser
);
6408 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6410 expr
.value
= error_mark_node
;
6414 tree sel
= c_parser_objc_selector_arg (parser
);
6415 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6417 expr
.value
= objc_build_selector_expr (loc
, sel
);
6420 case RID_AT_PROTOCOL
:
6421 gcc_assert (c_dialect_objc ());
6422 c_parser_consume_token (parser
);
6423 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6425 expr
.value
= error_mark_node
;
6428 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6430 c_parser_error (parser
, "expected identifier");
6431 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6432 expr
.value
= error_mark_node
;
6436 tree id
= c_parser_peek_token (parser
)->value
;
6437 c_parser_consume_token (parser
);
6438 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6440 expr
.value
= objc_build_protocol_expr (id
);
6444 /* Extension to support C-structures in the archiver. */
6445 gcc_assert (c_dialect_objc ());
6446 c_parser_consume_token (parser
);
6447 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6449 expr
.value
= error_mark_node
;
6452 t1
= c_parser_type_name (parser
);
6455 expr
.value
= error_mark_node
;
6456 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6459 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6462 tree type
= groktypename (t1
, NULL
, NULL
);
6463 expr
.value
= objc_build_encode_expr (type
);
6467 c_parser_error (parser
, "expected expression");
6468 expr
.value
= error_mark_node
;
6472 case CPP_OPEN_SQUARE
:
6473 if (c_dialect_objc ())
6475 tree receiver
, args
;
6476 c_parser_consume_token (parser
);
6477 receiver
= c_parser_objc_receiver (parser
);
6478 args
= c_parser_objc_message_args (parser
);
6479 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6481 expr
.value
= objc_build_message_expr (receiver
, args
);
6484 /* Else fall through to report error. */
6486 c_parser_error (parser
, "expected expression");
6487 expr
.value
= error_mark_node
;
6490 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6493 /* Parse a postfix expression after a parenthesized type name: the
6494 brace-enclosed initializer of a compound literal, possibly followed
6495 by some postfix operators. This is separate because it is not
6496 possible to tell until after the type name whether a cast
6497 expression has a cast or a compound literal, or whether the operand
6498 of sizeof is a parenthesized type name or starts with a compound
6499 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6500 location of the first token after the parentheses around the type
6503 static struct c_expr
6504 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6505 struct c_type_name
*type_name
,
6506 location_t type_loc
)
6512 location_t start_loc
;
6513 tree type_expr
= NULL_TREE
;
6514 bool type_expr_const
= true;
6515 check_compound_literal_type (type_loc
, type_name
);
6516 start_init (NULL_TREE
, NULL
, 0);
6517 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6518 start_loc
= c_parser_peek_token (parser
)->location
;
6519 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6521 error_at (type_loc
, "compound literal has variable size");
6522 type
= error_mark_node
;
6524 init
= c_parser_braced_init (parser
, type
, false);
6526 maybe_warn_string_init (type
, init
);
6528 if (type
!= error_mark_node
6529 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6530 && current_function_decl
)
6532 error ("compound literal qualified by address-space qualifier");
6533 type
= error_mark_node
;
6537 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
6538 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6539 ? CONSTRUCTOR_NON_CONST (init
.value
)
6540 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6541 non_const
|= !type_expr_const
;
6542 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6543 expr
.original_code
= ERROR_MARK
;
6544 expr
.original_type
= NULL
;
6547 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6549 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6550 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6554 gcc_assert (!non_const
);
6555 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6556 type_expr
, expr
.value
);
6559 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6562 /* Parse a postfix expression after the initial primary or compound
6563 literal; that is, parse a series of postfix operators.
6565 EXPR_LOC is the location of the primary expression. */
6567 static struct c_expr
6568 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6569 location_t expr_loc
,
6572 struct c_expr orig_expr
;
6574 VEC(tree
,gc
) *exprlist
;
6575 VEC(tree
,gc
) *origtypes
;
6578 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6579 switch (c_parser_peek_token (parser
)->type
)
6581 case CPP_OPEN_SQUARE
:
6582 /* Array reference. */
6583 c_parser_consume_token (parser
);
6584 idx
= c_parser_expression (parser
).value
;
6585 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6587 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6588 expr
.original_code
= ERROR_MARK
;
6589 expr
.original_type
= NULL
;
6591 case CPP_OPEN_PAREN
:
6592 /* Function call. */
6593 c_parser_consume_token (parser
);
6594 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6597 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
6598 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6601 mark_exp_read (expr
.value
);
6602 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6603 "(" after the FUNCNAME, which is what we have now. */
6604 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6606 expr
.original_code
= ERROR_MARK
;
6607 if (TREE_CODE (expr
.value
) == INTEGER_CST
6608 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6609 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6610 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6611 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6612 expr
.original_type
= NULL
;
6613 if (exprlist
!= NULL
)
6615 release_tree_vector (exprlist
);
6616 release_tree_vector (origtypes
);
6620 /* Structure element reference. */
6621 c_parser_consume_token (parser
);
6622 expr
= default_function_array_conversion (expr_loc
, expr
);
6623 if (c_parser_next_token_is (parser
, CPP_NAME
))
6624 ident
= c_parser_peek_token (parser
)->value
;
6627 c_parser_error (parser
, "expected identifier");
6628 expr
.value
= error_mark_node
;
6629 expr
.original_code
= ERROR_MARK
;
6630 expr
.original_type
= NULL
;
6633 c_parser_consume_token (parser
);
6634 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6635 expr
.original_code
= ERROR_MARK
;
6636 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6637 expr
.original_type
= NULL
;
6640 /* Remember the original type of a bitfield. */
6641 tree field
= TREE_OPERAND (expr
.value
, 1);
6642 if (TREE_CODE (field
) != FIELD_DECL
)
6643 expr
.original_type
= NULL
;
6645 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6649 /* Structure element reference. */
6650 c_parser_consume_token (parser
);
6651 expr
= default_function_array_conversion (expr_loc
, expr
);
6652 if (c_parser_next_token_is (parser
, CPP_NAME
))
6653 ident
= c_parser_peek_token (parser
)->value
;
6656 c_parser_error (parser
, "expected identifier");
6657 expr
.value
= error_mark_node
;
6658 expr
.original_code
= ERROR_MARK
;
6659 expr
.original_type
= NULL
;
6662 c_parser_consume_token (parser
);
6663 expr
.value
= build_component_ref (op_loc
,
6664 build_indirect_ref (op_loc
,
6668 expr
.original_code
= ERROR_MARK
;
6669 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6670 expr
.original_type
= NULL
;
6673 /* Remember the original type of a bitfield. */
6674 tree field
= TREE_OPERAND (expr
.value
, 1);
6675 if (TREE_CODE (field
) != FIELD_DECL
)
6676 expr
.original_type
= NULL
;
6678 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6682 /* Postincrement. */
6683 c_parser_consume_token (parser
);
6684 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6685 expr
.value
= build_unary_op (op_loc
,
6686 POSTINCREMENT_EXPR
, expr
.value
, 0);
6687 expr
.original_code
= ERROR_MARK
;
6688 expr
.original_type
= NULL
;
6690 case CPP_MINUS_MINUS
:
6691 /* Postdecrement. */
6692 c_parser_consume_token (parser
);
6693 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6694 expr
.value
= build_unary_op (op_loc
,
6695 POSTDECREMENT_EXPR
, expr
.value
, 0);
6696 expr
.original_code
= ERROR_MARK
;
6697 expr
.original_type
= NULL
;
6705 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6708 assignment-expression
6709 expression , assignment-expression
6712 static struct c_expr
6713 c_parser_expression (c_parser
*parser
)
6716 expr
= c_parser_expr_no_commas (parser
, NULL
);
6717 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6721 location_t loc
= c_parser_peek_token (parser
)->location
;
6722 location_t expr_loc
;
6723 c_parser_consume_token (parser
);
6724 expr_loc
= c_parser_peek_token (parser
)->location
;
6725 lhsval
= expr
.value
;
6726 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
6727 lhsval
= TREE_OPERAND (lhsval
, 1);
6728 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
6729 mark_exp_read (lhsval
);
6730 next
= c_parser_expr_no_commas (parser
, NULL
);
6731 next
= default_function_array_conversion (expr_loc
, next
);
6732 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
6733 expr
.original_code
= COMPOUND_EXPR
;
6734 expr
.original_type
= next
.original_type
;
6739 /* Parse an expression and convert functions or arrays to
6742 static struct c_expr
6743 c_parser_expression_conv (c_parser
*parser
)
6746 location_t loc
= c_parser_peek_token (parser
)->location
;
6747 expr
= c_parser_expression (parser
);
6748 expr
= default_function_array_conversion (loc
, expr
);
6752 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6753 functions and arrays to pointers. If FOLD_P, fold the expressions.
6756 assignment-expression
6757 nonempty-expr-list , assignment-expression
6760 static VEC(tree
,gc
) *
6761 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
6762 VEC(tree
,gc
) **p_orig_types
)
6765 VEC(tree
,gc
) *orig_types
;
6767 location_t loc
= c_parser_peek_token (parser
)->location
;
6769 ret
= make_tree_vector ();
6770 if (p_orig_types
== NULL
)
6773 orig_types
= make_tree_vector ();
6775 expr
= c_parser_expr_no_commas (parser
, NULL
);
6777 expr
= default_function_array_read_conversion (loc
, expr
);
6779 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6780 VEC_quick_push (tree
, ret
, expr
.value
);
6781 if (orig_types
!= NULL
)
6782 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6783 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6785 c_parser_consume_token (parser
);
6786 loc
= c_parser_peek_token (parser
)->location
;
6787 expr
= c_parser_expr_no_commas (parser
, NULL
);
6789 expr
= default_function_array_read_conversion (loc
, expr
);
6791 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6792 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6793 if (orig_types
!= NULL
)
6794 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6796 if (orig_types
!= NULL
)
6797 *p_orig_types
= orig_types
;
6801 /* Parse Objective-C-specific constructs. */
6803 /* Parse an objc-class-definition.
6805 objc-class-definition:
6806 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6807 objc-class-instance-variables[opt] objc-methodprotolist @end
6808 @implementation identifier objc-superclass[opt]
6809 objc-class-instance-variables[opt]
6810 @interface identifier ( identifier ) objc-protocol-refs[opt]
6811 objc-methodprotolist @end
6812 @interface identifier ( ) objc-protocol-refs[opt]
6813 objc-methodprotolist @end
6814 @implementation identifier ( identifier )
6819 "@interface identifier (" must start "@interface identifier (
6820 identifier ) ...": objc-methodprotolist in the first production may
6821 not start with a parenthesized identifier as a declarator of a data
6822 definition with no declaration specifiers if the objc-superclass,
6823 objc-protocol-refs and objc-class-instance-variables are omitted. */
6826 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
6831 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6833 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6838 c_parser_consume_token (parser
);
6839 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6841 c_parser_error (parser
, "expected identifier");
6844 id1
= c_parser_peek_token (parser
)->value
;
6845 c_parser_consume_token (parser
);
6846 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6848 /* We have a category or class extension. */
6850 tree proto
= NULL_TREE
;
6851 c_parser_consume_token (parser
);
6852 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6854 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6856 /* We have a class extension. */
6861 c_parser_error (parser
, "expected identifier or %<)%>");
6862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6868 id2
= c_parser_peek_token (parser
)->value
;
6869 c_parser_consume_token (parser
);
6871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6874 objc_start_category_implementation (id1
, id2
);
6877 if (c_parser_next_token_is (parser
, CPP_LESS
))
6878 proto
= c_parser_objc_protocol_refs (parser
);
6879 objc_start_category_interface (id1
, id2
, proto
, attributes
);
6880 c_parser_objc_methodprotolist (parser
);
6881 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6882 objc_finish_interface ();
6885 if (c_parser_next_token_is (parser
, CPP_COLON
))
6887 c_parser_consume_token (parser
);
6888 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6890 c_parser_error (parser
, "expected identifier");
6893 superclass
= c_parser_peek_token (parser
)->value
;
6894 c_parser_consume_token (parser
);
6897 superclass
= NULL_TREE
;
6900 tree proto
= NULL_TREE
;
6901 if (c_parser_next_token_is (parser
, CPP_LESS
))
6902 proto
= c_parser_objc_protocol_refs (parser
);
6903 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
6906 objc_start_class_implementation (id1
, superclass
);
6907 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6908 c_parser_objc_class_instance_variables (parser
);
6911 objc_continue_interface ();
6912 c_parser_objc_methodprotolist (parser
);
6913 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6914 objc_finish_interface ();
6918 objc_continue_implementation ();
6923 /* Parse objc-class-instance-variables.
6925 objc-class-instance-variables:
6926 { objc-instance-variable-decl-list[opt] }
6928 objc-instance-variable-decl-list:
6929 objc-visibility-spec
6930 objc-instance-variable-decl ;
6932 objc-instance-variable-decl-list objc-visibility-spec
6933 objc-instance-variable-decl-list objc-instance-variable-decl ;
6934 objc-instance-variable-decl-list ;
6936 objc-visibility-spec:
6941 objc-instance-variable-decl:
6946 c_parser_objc_class_instance_variables (c_parser
*parser
)
6948 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6949 c_parser_consume_token (parser
);
6950 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6953 /* Parse any stray semicolon. */
6954 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6956 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6958 c_parser_consume_token (parser
);
6961 /* Stop if at the end of the instance variables. */
6962 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6964 c_parser_consume_token (parser
);
6967 /* Parse any objc-visibility-spec. */
6968 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
6970 c_parser_consume_token (parser
);
6971 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
6974 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
6976 c_parser_consume_token (parser
);
6977 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
6980 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
6982 c_parser_consume_token (parser
);
6983 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
6986 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
6988 c_parser_consume_token (parser
);
6989 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
6992 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6994 c_parser_pragma (parser
, pragma_external
);
6998 /* Parse some comma-separated declarations. */
6999 decls
= c_parser_struct_declaration (parser
);
7002 /* There is a syntax error. We want to skip the offending
7003 tokens up to the next ';' (included) or '}'
7006 /* First, skip manually a ')' or ']'. This is because they
7007 reduce the nesting level, so c_parser_skip_until_found()
7008 wouldn't be able to skip past them. */
7009 c_token
*token
= c_parser_peek_token (parser
);
7010 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7011 c_parser_consume_token (parser
);
7013 /* Then, do the standard skipping. */
7014 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7016 /* We hopefully recovered. Start normal parsing again. */
7017 parser
->error
= false;
7022 /* Comma-separated instance variables are chained together
7023 in reverse order; add them one by one. */
7024 tree ivar
= nreverse (decls
);
7025 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7026 objc_add_instance_variable (copy_node (ivar
));
7028 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7032 /* Parse an objc-class-declaration.
7034 objc-class-declaration:
7035 @class identifier-list ;
7039 c_parser_objc_class_declaration (c_parser
*parser
)
7041 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7042 c_parser_consume_token (parser
);
7043 /* Any identifiers, including those declared as type names, are OK
7048 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7050 c_parser_error (parser
, "expected identifier");
7051 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7052 parser
->error
= false;
7055 id
= c_parser_peek_token (parser
)->value
;
7056 objc_declare_class (id
);
7057 c_parser_consume_token (parser
);
7058 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7059 c_parser_consume_token (parser
);
7063 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7066 /* Parse an objc-alias-declaration.
7068 objc-alias-declaration:
7069 @compatibility_alias identifier identifier ;
7073 c_parser_objc_alias_declaration (c_parser
*parser
)
7076 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7077 c_parser_consume_token (parser
);
7078 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7080 c_parser_error (parser
, "expected identifier");
7081 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7084 id1
= c_parser_peek_token (parser
)->value
;
7085 c_parser_consume_token (parser
);
7086 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7088 c_parser_error (parser
, "expected identifier");
7089 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7092 id2
= c_parser_peek_token (parser
)->value
;
7093 c_parser_consume_token (parser
);
7094 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7095 objc_declare_alias (id1
, id2
);
7098 /* Parse an objc-protocol-definition.
7100 objc-protocol-definition:
7101 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7102 @protocol identifier-list ;
7104 "@protocol identifier ;" should be resolved as "@protocol
7105 identifier-list ;": objc-methodprotolist may not start with a
7106 semicolon in the first alternative if objc-protocol-refs are
7110 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7112 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7114 c_parser_consume_token (parser
);
7115 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7117 c_parser_error (parser
, "expected identifier");
7120 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7121 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7123 /* Any identifiers, including those declared as type names, are
7128 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7130 c_parser_error (parser
, "expected identifier");
7133 id
= c_parser_peek_token (parser
)->value
;
7134 objc_declare_protocol (id
, attributes
);
7135 c_parser_consume_token (parser
);
7136 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7137 c_parser_consume_token (parser
);
7141 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7145 tree id
= c_parser_peek_token (parser
)->value
;
7146 tree proto
= NULL_TREE
;
7147 c_parser_consume_token (parser
);
7148 if (c_parser_next_token_is (parser
, CPP_LESS
))
7149 proto
= c_parser_objc_protocol_refs (parser
);
7150 parser
->objc_pq_context
= true;
7151 objc_start_protocol (id
, proto
, attributes
);
7152 c_parser_objc_methodprotolist (parser
);
7153 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7154 parser
->objc_pq_context
= false;
7155 objc_finish_interface ();
7159 /* Parse an objc-method-type.
7165 Return true if it is a class method (+) and false if it is
7166 an instance method (-).
7169 c_parser_objc_method_type (c_parser
*parser
)
7171 switch (c_parser_peek_token (parser
)->type
)
7174 c_parser_consume_token (parser
);
7177 c_parser_consume_token (parser
);
7184 /* Parse an objc-method-definition.
7186 objc-method-definition:
7187 objc-method-type objc-method-decl ;[opt] compound-statement
7191 c_parser_objc_method_definition (c_parser
*parser
)
7193 bool is_class_method
= c_parser_objc_method_type (parser
);
7194 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7195 parser
->objc_pq_context
= true;
7196 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7198 if (decl
== error_mark_node
)
7199 return; /* Bail here. */
7201 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7203 c_parser_consume_token (parser
);
7204 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7205 "extra semicolon in method definition specified");
7208 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7210 c_parser_error (parser
, "expected %<{%>");
7214 parser
->objc_pq_context
= false;
7215 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7217 add_stmt (c_parser_compound_statement (parser
));
7218 objc_finish_method_definition (current_function_decl
);
7222 /* This code is executed when we find a method definition
7223 outside of an @implementation context (or invalid for other
7224 reasons). Parse the method (to keep going) but do not emit
7227 c_parser_compound_statement (parser
);
7231 /* Parse an objc-methodprotolist.
7233 objc-methodprotolist:
7235 objc-methodprotolist objc-methodproto
7236 objc-methodprotolist declaration
7237 objc-methodprotolist ;
7241 The declaration is a data definition, which may be missing
7242 declaration specifiers under the same rules and diagnostics as
7243 other data definitions outside functions, and the stray semicolon
7244 is diagnosed the same way as a stray semicolon outside a
7248 c_parser_objc_methodprotolist (c_parser
*parser
)
7252 /* The list is terminated by @end. */
7253 switch (c_parser_peek_token (parser
)->type
)
7256 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7257 "ISO C does not allow extra %<;%> outside of a function");
7258 c_parser_consume_token (parser
);
7262 c_parser_objc_methodproto (parser
);
7265 c_parser_pragma (parser
, pragma_external
);
7270 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7272 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7273 c_parser_objc_at_property_declaration (parser
);
7274 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7276 objc_set_method_opt (true);
7277 c_parser_consume_token (parser
);
7279 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7281 objc_set_method_opt (false);
7282 c_parser_consume_token (parser
);
7285 c_parser_declaration_or_fndef (parser
, false, false, true,
7292 /* Parse an objc-methodproto.
7295 objc-method-type objc-method-decl ;
7299 c_parser_objc_methodproto (c_parser
*parser
)
7301 bool is_class_method
= c_parser_objc_method_type (parser
);
7302 tree decl
, attributes
= NULL_TREE
;
7304 /* Remember protocol qualifiers in prototypes. */
7305 parser
->objc_pq_context
= true;
7306 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7308 /* Forget protocol qualifiers now. */
7309 parser
->objc_pq_context
= false;
7311 /* Do not allow the presence of attributes to hide an erroneous
7312 method implementation in the interface section. */
7313 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7315 c_parser_error (parser
, "expected %<;%>");
7319 if (decl
!= error_mark_node
)
7320 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7322 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7325 /* If we are at a position that method attributes may be present, check that
7326 there are not any parsed already (a syntax error) and then collect any
7327 specified at the current location. Finally, if new attributes were present,
7328 check that the next token is legal ( ';' for decls and '{' for defs). */
7331 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7336 c_parser_error (parser
,
7337 "method attributes must be specified at the end only");
7338 *attributes
= NULL_TREE
;
7342 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7343 *attributes
= c_parser_attributes (parser
);
7345 /* If there were no attributes here, just report any earlier error. */
7346 if (*attributes
== NULL_TREE
|| bad
)
7349 /* If the attributes are followed by a ; or {, then just report any earlier
7351 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7352 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7355 /* We've got attributes, but not at the end. */
7356 c_parser_error (parser
,
7357 "expected %<;%> or %<{%> after method attribute definition");
7361 /* Parse an objc-method-decl.
7364 ( objc-type-name ) objc-selector
7366 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7367 objc-keyword-selector objc-optparmlist
7370 objc-keyword-selector:
7372 objc-keyword-selector objc-keyword-decl
7375 objc-selector : ( objc-type-name ) identifier
7376 objc-selector : identifier
7377 : ( objc-type-name ) identifier
7381 objc-optparms objc-optellipsis
7385 objc-opt-parms , parameter-declaration
7393 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7394 tree
*attributes
, tree
*expr
)
7396 tree type
= NULL_TREE
;
7398 tree parms
= NULL_TREE
;
7399 bool ellipsis
= false;
7400 bool attr_err
= false;
7402 *attributes
= NULL_TREE
;
7403 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7405 c_parser_consume_token (parser
);
7406 type
= c_parser_objc_type_name (parser
);
7407 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7409 sel
= c_parser_objc_selector (parser
);
7410 /* If there is no selector, or a colon follows, we have an
7411 objc-keyword-selector. If there is a selector, and a colon does
7412 not follow, that selector ends the objc-method-decl. */
7413 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7416 tree list
= NULL_TREE
;
7419 tree atype
= NULL_TREE
, id
, keyworddecl
;
7420 tree param_attr
= NULL_TREE
;
7421 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7423 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7425 c_parser_consume_token (parser
);
7426 atype
= c_parser_objc_type_name (parser
);
7427 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7430 /* New ObjC allows attributes on method parameters. */
7431 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7432 param_attr
= c_parser_attributes (parser
);
7433 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7435 c_parser_error (parser
, "expected identifier");
7436 return error_mark_node
;
7438 id
= c_parser_peek_token (parser
)->value
;
7439 c_parser_consume_token (parser
);
7440 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7441 list
= chainon (list
, keyworddecl
);
7442 tsel
= c_parser_objc_selector (parser
);
7443 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7447 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7449 /* Parse the optional parameter list. Optional Objective-C
7450 method parameters follow the C syntax, and may include '...'
7451 to denote a variable number of arguments. */
7452 parms
= make_node (TREE_LIST
);
7453 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7455 struct c_parm
*parm
;
7456 c_parser_consume_token (parser
);
7457 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7460 c_parser_consume_token (parser
);
7461 attr_err
|= c_parser_objc_maybe_method_attributes
7462 (parser
, attributes
) ;
7465 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7468 parms
= chainon (parms
,
7469 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
7474 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7478 c_parser_error (parser
, "objective-c method declaration is expected");
7479 return error_mark_node
;
7483 return error_mark_node
;
7485 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7488 /* Parse an objc-type-name.
7491 objc-type-qualifiers[opt] type-name
7492 objc-type-qualifiers[opt]
7494 objc-type-qualifiers:
7496 objc-type-qualifiers objc-type-qualifier
7498 objc-type-qualifier: one of
7499 in out inout bycopy byref oneway
7503 c_parser_objc_type_name (c_parser
*parser
)
7505 tree quals
= NULL_TREE
;
7506 struct c_type_name
*type_name
= NULL
;
7507 tree type
= NULL_TREE
;
7510 c_token
*token
= c_parser_peek_token (parser
);
7511 if (token
->type
== CPP_KEYWORD
7512 && (token
->keyword
== RID_IN
7513 || token
->keyword
== RID_OUT
7514 || token
->keyword
== RID_INOUT
7515 || token
->keyword
== RID_BYCOPY
7516 || token
->keyword
== RID_BYREF
7517 || token
->keyword
== RID_ONEWAY
))
7519 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7520 c_parser_consume_token (parser
);
7525 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7526 type_name
= c_parser_type_name (parser
);
7528 type
= groktypename (type_name
, NULL
, NULL
);
7530 /* If the type is unknown, and error has already been produced and
7531 we need to recover from the error. In that case, use NULL_TREE
7532 for the type, as if no type had been specified; this will use the
7533 default type ('id') which is good for error recovery. */
7534 if (type
== error_mark_node
)
7537 return build_tree_list (quals
, type
);
7540 /* Parse objc-protocol-refs.
7547 c_parser_objc_protocol_refs (c_parser
*parser
)
7549 tree list
= NULL_TREE
;
7550 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7551 c_parser_consume_token (parser
);
7552 /* Any identifiers, including those declared as type names, are OK
7557 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7559 c_parser_error (parser
, "expected identifier");
7562 id
= c_parser_peek_token (parser
)->value
;
7563 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7564 c_parser_consume_token (parser
);
7565 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7566 c_parser_consume_token (parser
);
7570 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7574 /* Parse an objc-try-catch-finally-statement.
7576 objc-try-catch-finally-statement:
7577 @try compound-statement objc-catch-list[opt]
7578 @try compound-statement objc-catch-list[opt] @finally compound-statement
7581 @catch ( objc-catch-parameter-declaration ) compound-statement
7582 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7584 objc-catch-parameter-declaration:
7585 parameter-declaration
7588 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7590 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7591 for C++. Keep them in sync. */
7594 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
7596 location_t location
;
7599 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7600 c_parser_consume_token (parser
);
7601 location
= c_parser_peek_token (parser
)->location
;
7602 objc_maybe_warn_exceptions (location
);
7603 stmt
= c_parser_compound_statement (parser
);
7604 objc_begin_try_stmt (location
, stmt
);
7606 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7608 struct c_parm
*parm
;
7609 tree parameter_declaration
= error_mark_node
;
7610 bool seen_open_paren
= false;
7612 c_parser_consume_token (parser
);
7613 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7614 seen_open_paren
= true;
7615 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7617 /* We have "@catch (...)" (where the '...' are literally
7618 what is in the code). Skip the '...'.
7619 parameter_declaration is set to NULL_TREE, and
7620 objc_being_catch_clauses() knows that that means
7622 c_parser_consume_token (parser
);
7623 parameter_declaration
= NULL_TREE
;
7627 /* We have "@catch (NSException *exception)" or something
7628 like that. Parse the parameter declaration. */
7629 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7631 parameter_declaration
= error_mark_node
;
7633 parameter_declaration
= grokparm (parm
, NULL
);
7635 if (seen_open_paren
)
7636 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7639 /* If there was no open parenthesis, we are recovering from
7640 an error, and we are trying to figure out what mistake
7641 the user has made. */
7643 /* If there is an immediate closing parenthesis, the user
7644 probably forgot the opening one (ie, they typed "@catch
7645 NSException *e)". Parse the closing parenthesis and keep
7647 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7648 c_parser_consume_token (parser
);
7650 /* If these is no immediate closing parenthesis, the user
7651 probably doesn't know that parenthesis are required at
7652 all (ie, they typed "@catch NSException *e"). So, just
7653 forget about the closing parenthesis and keep going. */
7655 objc_begin_catch_clause (parameter_declaration
);
7656 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7657 c_parser_compound_statement_nostart (parser
);
7658 objc_finish_catch_clause ();
7660 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
7662 c_parser_consume_token (parser
);
7663 location
= c_parser_peek_token (parser
)->location
;
7664 stmt
= c_parser_compound_statement (parser
);
7665 objc_build_finally_clause (location
, stmt
);
7667 objc_finish_try_stmt ();
7670 /* Parse an objc-synchronized-statement.
7672 objc-synchronized-statement:
7673 @synchronized ( expression ) compound-statement
7677 c_parser_objc_synchronized_statement (c_parser
*parser
)
7681 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
7682 c_parser_consume_token (parser
);
7683 loc
= c_parser_peek_token (parser
)->location
;
7684 objc_maybe_warn_exceptions (loc
);
7685 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7687 expr
= c_parser_expression (parser
).value
;
7688 expr
= c_fully_fold (expr
, false, NULL
);
7689 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7692 expr
= error_mark_node
;
7693 stmt
= c_parser_compound_statement (parser
);
7694 objc_build_synchronized (loc
, expr
, stmt
);
7697 /* Parse an objc-selector; return NULL_TREE without an error if the
7698 next token is not an objc-selector.
7703 enum struct union if else while do for switch case default
7704 break continue return goto asm sizeof typeof __alignof
7705 unsigned long const short volatile signed restrict _Complex
7706 in out inout bycopy byref oneway int char float double void _Bool
7708 ??? Why this selection of keywords but not, for example, storage
7709 class specifiers? */
7712 c_parser_objc_selector (c_parser
*parser
)
7714 c_token
*token
= c_parser_peek_token (parser
);
7715 tree value
= token
->value
;
7716 if (token
->type
== CPP_NAME
)
7718 c_parser_consume_token (parser
);
7721 if (token
->type
!= CPP_KEYWORD
)
7723 switch (token
->keyword
)
7765 c_parser_consume_token (parser
);
7772 /* Parse an objc-selector-arg.
7776 objc-keywordname-list
7778 objc-keywordname-list:
7780 objc-keywordname-list objc-keywordname
7788 c_parser_objc_selector_arg (c_parser
*parser
)
7790 tree sel
= c_parser_objc_selector (parser
);
7791 tree list
= NULL_TREE
;
7792 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7796 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7798 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
7799 sel
= c_parser_objc_selector (parser
);
7800 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7806 /* Parse an objc-receiver.
7815 c_parser_objc_receiver (c_parser
*parser
)
7817 if (c_parser_peek_token (parser
)->type
== CPP_NAME
7818 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
7819 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
7821 tree id
= c_parser_peek_token (parser
)->value
;
7822 c_parser_consume_token (parser
);
7823 return objc_get_class_reference (id
);
7825 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
7828 /* Parse objc-message-args.
7832 objc-keywordarg-list
7834 objc-keywordarg-list:
7836 objc-keywordarg-list objc-keywordarg
7839 objc-selector : objc-keywordexpr
7844 c_parser_objc_message_args (c_parser
*parser
)
7846 tree sel
= c_parser_objc_selector (parser
);
7847 tree list
= NULL_TREE
;
7848 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7853 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7854 return error_mark_node
;
7855 keywordexpr
= c_parser_objc_keywordexpr (parser
);
7856 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
7857 sel
= c_parser_objc_selector (parser
);
7858 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7864 /* Parse an objc-keywordexpr.
7871 c_parser_objc_keywordexpr (c_parser
*parser
)
7874 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
7875 if (VEC_length (tree
, expr_list
) == 1)
7877 /* Just return the expression, remove a level of
7879 ret
= VEC_index (tree
, expr_list
, 0);
7883 /* We have a comma expression, we will collapse later. */
7884 ret
= build_tree_list_vec (expr_list
);
7886 release_tree_vector (expr_list
);
7890 /* A check, needed in several places, that ObjC interface, implementation or
7891 method definitions are not prefixed by incorrect items. */
7893 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
7894 struct c_declspecs
*specs
)
7896 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
7897 || specs
->typespec_kind
!= ctsk_none
)
7899 c_parser_error (parser
,
7900 "no type or storage class may be specified here,");
7901 c_parser_skip_to_end_of_block_or_statement (parser
);
7907 /* Parse an Objective-C @property declaration. The syntax is:
7909 objc-property-declaration:
7910 '@property' objc-property-attributes[opt] struct-declaration ;
7912 objc-property-attributes:
7913 '(' objc-property-attribute-list ')'
7915 objc-property-attribute-list:
7916 objc-property-attribute
7917 objc-property-attribute-list, objc-property-attribute
7919 objc-property-attribute
7920 'getter' = identifier
7921 'setter' = identifier
7930 @property NSString *name;
7931 @property (readonly) id object;
7932 @property (retain, nonatomic, getter=getTheName) id name;
7933 @property int a, b, c;
7935 PS: This function is identical to cp_parser_objc_at_propery_declaration
7936 for C++. Keep them in sync. */
7938 c_parser_objc_at_property_declaration (c_parser
*parser
)
7940 /* The following variables hold the attributes of the properties as
7941 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7942 seen. When we see an attribute, we set them to 'true' (if they
7943 are boolean properties) or to the identifier (if they have an
7944 argument, ie, for getter and setter). Note that here we only
7945 parse the list of attributes, check the syntax and accumulate the
7946 attributes that we find. objc_add_property_declaration() will
7947 then process the information. */
7948 bool property_assign
= false;
7949 bool property_copy
= false;
7950 tree property_getter_ident
= NULL_TREE
;
7951 bool property_nonatomic
= false;
7952 bool property_readonly
= false;
7953 bool property_readwrite
= false;
7954 bool property_retain
= false;
7955 tree property_setter_ident
= NULL_TREE
;
7957 /* 'properties' is the list of properties that we read. Usually a
7958 single one, but maybe more (eg, in "@property int a, b, c;" there
7963 loc
= c_parser_peek_token (parser
)->location
;
7964 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
7966 c_parser_consume_token (parser
); /* Eat '@property'. */
7968 /* Parse the optional attribute list... */
7969 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7972 c_parser_consume_token (parser
);
7974 /* Property attribute keywords are valid now. */
7975 parser
->objc_property_attr_context
= true;
7979 bool syntax_error
= false;
7980 c_token
*token
= c_parser_peek_token (parser
);
7983 if (token
->type
!= CPP_KEYWORD
)
7985 if (token
->type
== CPP_CLOSE_PAREN
)
7986 c_parser_error (parser
, "expected identifier");
7989 c_parser_consume_token (parser
);
7990 c_parser_error (parser
, "unknown property attribute");
7994 keyword
= token
->keyword
;
7995 c_parser_consume_token (parser
);
7998 case RID_ASSIGN
: property_assign
= true; break;
7999 case RID_COPY
: property_copy
= true; break;
8000 case RID_NONATOMIC
: property_nonatomic
= true; break;
8001 case RID_READONLY
: property_readonly
= true; break;
8002 case RID_READWRITE
: property_readwrite
= true; break;
8003 case RID_RETAIN
: property_retain
= true; break;
8007 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8009 if (keyword
== RID_GETTER
)
8010 c_parser_error (parser
,
8011 "missing %<=%> (after %<getter%> attribute)");
8013 c_parser_error (parser
,
8014 "missing %<=%> (after %<setter%> attribute)");
8015 syntax_error
= true;
8018 c_parser_consume_token (parser
); /* eat the = */
8019 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8021 c_parser_error (parser
, "expected identifier");
8022 syntax_error
= true;
8025 if (keyword
== RID_SETTER
)
8027 if (property_setter_ident
!= NULL_TREE
)
8028 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8030 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8031 c_parser_consume_token (parser
);
8032 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8033 c_parser_error (parser
, "setter name must terminate with %<:%>");
8035 c_parser_consume_token (parser
);
8039 if (property_getter_ident
!= NULL_TREE
)
8040 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8042 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8043 c_parser_consume_token (parser
);
8047 c_parser_error (parser
, "unknown property attribute");
8048 syntax_error
= true;
8055 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8056 c_parser_consume_token (parser
);
8060 parser
->objc_property_attr_context
= false;
8061 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8063 /* ... and the property declaration(s). */
8064 properties
= c_parser_struct_declaration (parser
);
8066 if (properties
== error_mark_node
)
8068 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8069 parser
->error
= false;
8073 if (properties
== NULL_TREE
)
8074 c_parser_error (parser
, "expected identifier");
8077 /* Comma-separated properties are chained together in
8078 reverse order; add them one by one. */
8079 properties
= nreverse (properties
);
8081 for (; properties
; properties
= TREE_CHAIN (properties
))
8082 objc_add_property_declaration (loc
, copy_node (properties
),
8083 property_readonly
, property_readwrite
,
8084 property_assign
, property_retain
,
8085 property_copy
, property_nonatomic
,
8086 property_getter_ident
, property_setter_ident
);
8089 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8090 parser
->error
= false;
8093 /* Parse an Objective-C @synthesize declaration. The syntax is:
8095 objc-synthesize-declaration:
8096 @synthesize objc-synthesize-identifier-list ;
8098 objc-synthesize-identifier-list:
8099 objc-synthesize-identifier
8100 objc-synthesize-identifier-list, objc-synthesize-identifier
8102 objc-synthesize-identifier
8104 identifier = identifier
8107 @synthesize MyProperty;
8108 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8110 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8111 for C++. Keep them in sync.
8114 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8116 tree list
= NULL_TREE
;
8118 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8119 loc
= c_parser_peek_token (parser
)->location
;
8121 c_parser_consume_token (parser
);
8124 tree property
, ivar
;
8125 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8127 c_parser_error (parser
, "expected identifier");
8128 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8129 /* Once we find the semicolon, we can resume normal parsing.
8130 We have to reset parser->error manually because
8131 c_parser_skip_until_found() won't reset it for us if the
8132 next token is precisely a semicolon. */
8133 parser
->error
= false;
8136 property
= c_parser_peek_token (parser
)->value
;
8137 c_parser_consume_token (parser
);
8138 if (c_parser_next_token_is (parser
, CPP_EQ
))
8140 c_parser_consume_token (parser
);
8141 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8143 c_parser_error (parser
, "expected identifier");
8144 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8145 parser
->error
= false;
8148 ivar
= c_parser_peek_token (parser
)->value
;
8149 c_parser_consume_token (parser
);
8153 list
= chainon (list
, build_tree_list (ivar
, property
));
8154 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8155 c_parser_consume_token (parser
);
8159 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8160 objc_add_synthesize_declaration (loc
, list
);
8163 /* Parse an Objective-C @dynamic declaration. The syntax is:
8165 objc-dynamic-declaration:
8166 @dynamic identifier-list ;
8169 @dynamic MyProperty;
8170 @dynamic MyProperty, AnotherProperty;
8172 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8173 for C++. Keep them in sync.
8176 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8178 tree list
= NULL_TREE
;
8180 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8181 loc
= c_parser_peek_token (parser
)->location
;
8183 c_parser_consume_token (parser
);
8187 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8189 c_parser_error (parser
, "expected identifier");
8190 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8191 parser
->error
= false;
8194 property
= c_parser_peek_token (parser
)->value
;
8195 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8196 c_parser_consume_token (parser
);
8197 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8198 c_parser_consume_token (parser
);
8202 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8203 objc_add_dynamic_declaration (loc
, list
);
8207 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8208 should be considered, statements. ALLOW_STMT is true if we're within
8209 the context of a function and such pragmas are to be allowed. Returns
8210 true if we actually parsed such a pragma. */
8213 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8217 id
= c_parser_peek_token (parser
)->pragma_kind
;
8218 gcc_assert (id
!= PRAGMA_NONE
);
8222 case PRAGMA_OMP_BARRIER
:
8223 if (context
!= pragma_compound
)
8225 if (context
== pragma_stmt
)
8226 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8227 "used in compound statements");
8230 c_parser_omp_barrier (parser
);
8233 case PRAGMA_OMP_FLUSH
:
8234 if (context
!= pragma_compound
)
8236 if (context
== pragma_stmt
)
8237 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8238 "used in compound statements");
8241 c_parser_omp_flush (parser
);
8244 case PRAGMA_OMP_TASKWAIT
:
8245 if (context
!= pragma_compound
)
8247 if (context
== pragma_stmt
)
8248 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8249 "used in compound statements");
8252 c_parser_omp_taskwait (parser
);
8255 case PRAGMA_OMP_TASKYIELD
:
8256 if (context
!= pragma_compound
)
8258 if (context
== pragma_stmt
)
8259 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
8260 "used in compound statements");
8263 c_parser_omp_taskyield (parser
);
8266 case PRAGMA_OMP_THREADPRIVATE
:
8267 c_parser_omp_threadprivate (parser
);
8270 case PRAGMA_OMP_SECTION
:
8271 error_at (c_parser_peek_token (parser
)->location
,
8272 "%<#pragma omp section%> may only be used in "
8273 "%<#pragma omp sections%> construct");
8274 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8277 case PRAGMA_GCC_PCH_PREPROCESS
:
8278 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8279 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8283 if (id
< PRAGMA_FIRST_EXTERNAL
)
8285 if (context
== pragma_external
)
8288 c_parser_error (parser
, "expected declaration specifiers");
8289 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8292 c_parser_omp_construct (parser
);
8298 c_parser_consume_pragma (parser
);
8299 c_invoke_pragma_handler (id
);
8301 /* Skip to EOL, but suppress any error message. Those will have been
8302 generated by the handler routine through calling error, as opposed
8303 to calling c_parser_error. */
8304 parser
->error
= true;
8305 c_parser_skip_to_pragma_eol (parser
);
8310 /* The interface the pragma parsers have to the lexer. */
8313 pragma_lex (tree
*value
)
8315 c_token
*tok
= c_parser_peek_token (the_parser
);
8316 enum cpp_ttype ret
= tok
->type
;
8318 *value
= tok
->value
;
8319 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8323 if (ret
== CPP_KEYWORD
)
8325 c_parser_consume_token (the_parser
);
8332 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8336 c_parser_consume_pragma (parser
);
8337 if (c_parser_next_token_is (parser
, CPP_STRING
))
8339 name
= c_parser_peek_token (parser
)->value
;
8340 c_parser_consume_token (parser
);
8343 c_parser_error (parser
, "expected string literal");
8344 c_parser_skip_to_pragma_eol (parser
);
8347 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8350 /* OpenMP 2.5 parsing routines. */
8352 /* Returns name of the next clause.
8353 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8354 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8355 returned and the token is consumed. */
8357 static pragma_omp_clause
8358 c_parser_omp_clause_name (c_parser
*parser
)
8360 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8362 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8363 result
= PRAGMA_OMP_CLAUSE_IF
;
8364 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8365 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8366 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8368 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8373 if (!strcmp ("collapse", p
))
8374 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8375 else if (!strcmp ("copyin", p
))
8376 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8377 else if (!strcmp ("copyprivate", p
))
8378 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8381 if (!strcmp ("final", p
))
8382 result
= PRAGMA_OMP_CLAUSE_FINAL
;
8383 else if (!strcmp ("firstprivate", p
))
8384 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8387 if (!strcmp ("lastprivate", p
))
8388 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8391 if (!strcmp ("mergeable", p
))
8392 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
8395 if (!strcmp ("nowait", p
))
8396 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8397 else if (!strcmp ("num_threads", p
))
8398 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8401 if (!strcmp ("ordered", p
))
8402 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8405 if (!strcmp ("private", p
))
8406 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8409 if (!strcmp ("reduction", p
))
8410 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8413 if (!strcmp ("schedule", p
))
8414 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8415 else if (!strcmp ("shared", p
))
8416 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8419 if (!strcmp ("untied", p
))
8420 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8425 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8426 c_parser_consume_token (parser
);
8431 /* Validate that a clause of the given type does not already exist. */
8434 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8439 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8440 if (OMP_CLAUSE_CODE (c
) == code
)
8442 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8443 error_at (loc
, "too many %qs clauses", name
);
8451 variable-list , identifier
8453 If KIND is nonzero, create the appropriate node and install the
8454 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8455 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8457 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8458 return the list created. */
8461 c_parser_omp_variable_list (c_parser
*parser
,
8462 location_t clause_loc
,
8463 enum omp_clause_code kind
,
8466 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8467 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8468 c_parser_error (parser
, "expected identifier");
8470 while (c_parser_next_token_is (parser
, CPP_NAME
)
8471 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8473 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8476 undeclared_variable (c_parser_peek_token (parser
)->location
,
8477 c_parser_peek_token (parser
)->value
);
8478 else if (t
== error_mark_node
)
8482 tree u
= build_omp_clause (clause_loc
, kind
);
8483 OMP_CLAUSE_DECL (u
) = t
;
8484 OMP_CLAUSE_CHAIN (u
) = list
;
8488 list
= tree_cons (t
, NULL_TREE
, list
);
8490 c_parser_consume_token (parser
);
8492 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8495 c_parser_consume_token (parser
);
8501 /* Similarly, but expect leading and trailing parenthesis. This is a very
8502 common case for omp clauses. */
8505 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8508 /* The clauses location. */
8509 location_t loc
= c_parser_peek_token (parser
)->location
;
8511 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8513 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8514 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8520 collapse ( constant-expression ) */
8523 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8525 tree c
, num
= error_mark_node
;
8529 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8531 loc
= c_parser_peek_token (parser
)->location
;
8532 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8534 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8535 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8537 if (num
== error_mark_node
)
8539 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8540 || !host_integerp (num
, 0)
8541 || (n
= tree_low_cst (num
, 0)) <= 0
8545 "collapse argument needs positive constant integer expression");
8548 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8549 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
8550 OMP_CLAUSE_CHAIN (c
) = list
;
8555 copyin ( variable-list ) */
8558 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
8560 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
8564 copyprivate ( variable-list ) */
8567 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
8569 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
8573 default ( shared | none ) */
8576 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
8578 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
8579 location_t loc
= c_parser_peek_token (parser
)->location
;
8582 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8584 if (c_parser_next_token_is (parser
, CPP_NAME
))
8586 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8591 if (strcmp ("none", p
) != 0)
8593 kind
= OMP_CLAUSE_DEFAULT_NONE
;
8597 if (strcmp ("shared", p
) != 0)
8599 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
8606 c_parser_consume_token (parser
);
8611 c_parser_error (parser
, "expected %<none%> or %<shared%>");
8613 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8615 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
8618 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
8619 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
8620 OMP_CLAUSE_CHAIN (c
) = list
;
8621 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
8627 firstprivate ( variable-list ) */
8630 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
8632 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
8636 final ( expression ) */
8639 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
8641 location_t loc
= c_parser_peek_token (parser
)->location
;
8642 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8644 tree t
= c_parser_paren_condition (parser
);
8647 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
8649 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
8650 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
8651 OMP_CLAUSE_CHAIN (c
) = list
;
8655 c_parser_error (parser
, "expected %<(%>");
8661 if ( expression ) */
8664 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
8666 location_t loc
= c_parser_peek_token (parser
)->location
;
8667 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8669 tree t
= c_parser_paren_condition (parser
);
8672 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
8674 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
8675 OMP_CLAUSE_IF_EXPR (c
) = t
;
8676 OMP_CLAUSE_CHAIN (c
) = list
;
8680 c_parser_error (parser
, "expected %<(%>");
8686 lastprivate ( variable-list ) */
8689 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
8691 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
8698 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8702 /* FIXME: Should we allow duplicates? */
8703 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
8705 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8706 OMP_CLAUSE_MERGEABLE
);
8707 OMP_CLAUSE_CHAIN (c
) = list
;
8716 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8719 location_t loc
= c_parser_peek_token (parser
)->location
;
8721 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
8723 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
8724 OMP_CLAUSE_CHAIN (c
) = list
;
8729 num_threads ( expression ) */
8732 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
8734 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
8735 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8737 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
8738 tree c
, t
= c_parser_expression (parser
).value
;
8739 t
= c_fully_fold (t
, false, NULL
);
8741 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8743 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8745 c_parser_error (parser
, "expected integer expression");
8749 /* Attempt to statically determine when the number isn't positive. */
8750 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
8751 build_int_cst (TREE_TYPE (t
), 0));
8752 if (CAN_HAVE_LOCATION_P (c
))
8753 SET_EXPR_LOCATION (c
, expr_loc
);
8754 if (c
== boolean_true_node
)
8756 warning_at (expr_loc
, 0,
8757 "%<num_threads%> value must be positive");
8758 t
= integer_one_node
;
8761 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
8763 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
8764 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
8765 OMP_CLAUSE_CHAIN (c
) = list
;
8776 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
8780 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
8782 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8783 OMP_CLAUSE_ORDERED
);
8784 OMP_CLAUSE_CHAIN (c
) = list
;
8790 private ( variable-list ) */
8793 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
8795 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
8799 reduction ( reduction-operator : variable-list )
8802 One of: + * - & ^ | && ||
8807 One of: + * - & ^ | && || max min */
8810 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
8812 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
8813 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8815 enum tree_code code
;
8817 switch (c_parser_peek_token (parser
)->type
)
8829 code
= BIT_AND_EXPR
;
8832 code
= BIT_XOR_EXPR
;
8835 code
= BIT_IOR_EXPR
;
8838 code
= TRUTH_ANDIF_EXPR
;
8841 code
= TRUTH_ORIF_EXPR
;
8846 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8847 if (strcmp (p
, "min") == 0)
8852 if (strcmp (p
, "max") == 0)
8860 c_parser_error (parser
,
8861 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8862 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
8863 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8866 c_parser_consume_token (parser
);
8867 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8871 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
8872 OMP_CLAUSE_REDUCTION
, list
);
8873 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
8874 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
8878 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8884 schedule ( schedule-kind )
8885 schedule ( schedule-kind , expression )
8888 static | dynamic | guided | runtime | auto
8892 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
8895 location_t loc
= c_parser_peek_token (parser
)->location
;
8897 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8900 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
8902 if (c_parser_next_token_is (parser
, CPP_NAME
))
8904 tree kind
= c_parser_peek_token (parser
)->value
;
8905 const char *p
= IDENTIFIER_POINTER (kind
);
8910 if (strcmp ("dynamic", p
) != 0)
8912 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
8916 if (strcmp ("guided", p
) != 0)
8918 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
8922 if (strcmp ("runtime", p
) != 0)
8924 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
8931 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
8932 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
8933 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
8934 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
8938 c_parser_consume_token (parser
);
8939 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8942 c_parser_consume_token (parser
);
8944 here
= c_parser_peek_token (parser
)->location
;
8945 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
8946 t
= c_fully_fold (t
, false, NULL
);
8948 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
8949 error_at (here
, "schedule %<runtime%> does not take "
8950 "a %<chunk_size%> parameter");
8951 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
8953 "schedule %<auto%> does not take "
8954 "a %<chunk_size%> parameter");
8955 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
8956 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
8958 c_parser_error (parser
, "expected integer expression");
8960 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8963 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8964 "expected %<,%> or %<)%>");
8966 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
8967 OMP_CLAUSE_CHAIN (c
) = list
;
8971 c_parser_error (parser
, "invalid schedule kind");
8972 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8977 shared ( variable-list ) */
8980 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
8982 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
8989 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8993 /* FIXME: Should we allow duplicates? */
8994 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
8996 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8998 OMP_CLAUSE_CHAIN (c
) = list
;
9003 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9004 is a bitmask in MASK. Return the list of clauses found; the result
9005 of clause default goes in *pdefault. */
9008 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9011 tree clauses
= NULL
;
9014 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9017 pragma_omp_clause c_kind
;
9019 tree prev
= clauses
;
9021 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9022 c_parser_consume_token (parser
);
9025 here
= c_parser_peek_token (parser
)->location
;
9026 c_kind
= c_parser_omp_clause_name (parser
);
9030 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9031 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9032 c_name
= "collapse";
9034 case PRAGMA_OMP_CLAUSE_COPYIN
:
9035 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9038 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9039 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9040 c_name
= "copyprivate";
9042 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9043 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9046 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9047 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9048 c_name
= "firstprivate";
9050 case PRAGMA_OMP_CLAUSE_FINAL
:
9051 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9054 case PRAGMA_OMP_CLAUSE_IF
:
9055 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9058 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9059 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9060 c_name
= "lastprivate";
9062 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9063 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9064 c_name
= "mergeable";
9066 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9067 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9070 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9071 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9072 c_name
= "num_threads";
9074 case PRAGMA_OMP_CLAUSE_ORDERED
:
9075 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9078 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9079 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9082 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9083 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9084 c_name
= "reduction";
9086 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9087 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9088 c_name
= "schedule";
9090 case PRAGMA_OMP_CLAUSE_SHARED
:
9091 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9094 case PRAGMA_OMP_CLAUSE_UNTIED
:
9095 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9099 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9103 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9105 /* Remove the invalid clause(s) from the list to avoid
9106 confusing the rest of the compiler. */
9108 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9113 c_parser_skip_to_pragma_eol (parser
);
9115 return c_finish_omp_clauses (clauses
);
9122 In practice, we're also interested in adding the statement to an
9123 outer node. So it is convenient if we work around the fact that
9124 c_parser_statement calls add_stmt. */
9127 c_parser_omp_structured_block (c_parser
*parser
)
9129 tree stmt
= push_stmt_list ();
9130 c_parser_statement (parser
);
9131 return pop_stmt_list (stmt
);
9135 # pragma omp atomic new-line
9139 x binop= expr | x++ | ++x | x-- | --x
9141 +, *, -, /, &, ^, |, <<, >>
9143 where x is an lvalue expression with scalar type.
9146 # pragma omp atomic new-line
9149 # pragma omp atomic read new-line
9152 # pragma omp atomic write new-line
9155 # pragma omp atomic update new-line
9158 # pragma omp atomic capture new-line
9161 # pragma omp atomic capture new-line
9169 expression-stmt | x = x binop expr
9171 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9173 { v = x; update-stmt; } | { update-stmt; v = x; }
9175 where x and v are lvalue expressions with scalar type.
9177 LOC is the location of the #pragma token. */
9180 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9182 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9183 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9184 tree stmt
, orig_lhs
;
9185 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9186 struct c_expr rhs_expr
;
9187 bool structured_block
= false;
9189 if (c_parser_next_token_is (parser
, CPP_NAME
))
9191 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9193 if (!strcmp (p
, "read"))
9194 code
= OMP_ATOMIC_READ
;
9195 else if (!strcmp (p
, "write"))
9197 else if (!strcmp (p
, "update"))
9199 else if (!strcmp (p
, "capture"))
9200 code
= OMP_ATOMIC_CAPTURE_NEW
;
9204 c_parser_consume_token (parser
);
9206 c_parser_skip_to_pragma_eol (parser
);
9210 case OMP_ATOMIC_READ
:
9211 case NOP_EXPR
: /* atomic write */
9212 v
= c_parser_unary_expression (parser
).value
;
9213 v
= c_fully_fold (v
, false, NULL
);
9214 if (v
== error_mark_node
)
9216 loc
= c_parser_peek_token (parser
)->location
;
9217 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9219 if (code
== NOP_EXPR
)
9220 lhs
= c_parser_expression (parser
).value
;
9222 lhs
= c_parser_unary_expression (parser
).value
;
9223 lhs
= c_fully_fold (lhs
, false, NULL
);
9224 if (lhs
== error_mark_node
)
9226 if (code
== NOP_EXPR
)
9228 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9236 case OMP_ATOMIC_CAPTURE_NEW
:
9237 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9239 c_parser_consume_token (parser
);
9240 structured_block
= true;
9244 v
= c_parser_unary_expression (parser
).value
;
9245 v
= c_fully_fold (v
, false, NULL
);
9246 if (v
== error_mark_node
)
9248 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9256 /* For structured_block case we don't know yet whether
9257 old or new x should be captured. */
9259 lhs
= c_parser_unary_expression (parser
).value
;
9260 lhs
= c_fully_fold (lhs
, false, NULL
);
9262 switch (TREE_CODE (lhs
))
9266 c_parser_skip_to_end_of_block_or_statement (parser
);
9267 if (structured_block
)
9269 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9270 c_parser_consume_token (parser
);
9271 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9273 c_parser_skip_to_end_of_block_or_statement (parser
);
9274 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9275 c_parser_consume_token (parser
);
9280 case POSTINCREMENT_EXPR
:
9281 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9282 code
= OMP_ATOMIC_CAPTURE_OLD
;
9284 case PREINCREMENT_EXPR
:
9285 lhs
= TREE_OPERAND (lhs
, 0);
9287 rhs
= integer_one_node
;
9290 case POSTDECREMENT_EXPR
:
9291 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9292 code
= OMP_ATOMIC_CAPTURE_OLD
;
9294 case PREDECREMENT_EXPR
:
9295 lhs
= TREE_OPERAND (lhs
, 0);
9296 opcode
= MINUS_EXPR
;
9297 rhs
= integer_one_node
;
9301 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9302 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9303 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9304 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9305 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9306 (TREE_OPERAND (lhs
, 1), 0), 0)))
9308 /* Undo effects of boolean_increment for post {in,de}crement. */
9309 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9312 if (TREE_CODE (lhs
) == MODIFY_EXPR
9313 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9315 /* Undo effects of boolean_increment. */
9316 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9318 /* This is pre or post increment. */
9319 rhs
= TREE_OPERAND (lhs
, 1);
9320 lhs
= TREE_OPERAND (lhs
, 0);
9322 if (code
== OMP_ATOMIC_CAPTURE_NEW
9323 && !structured_block
9324 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9325 code
= OMP_ATOMIC_CAPTURE_OLD
;
9328 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9329 && TREE_OPERAND (lhs
, 0)
9330 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9332 /* This is pre or post decrement. */
9333 rhs
= TREE_OPERAND (lhs
, 1);
9334 lhs
= TREE_OPERAND (lhs
, 0);
9336 if (code
== OMP_ATOMIC_CAPTURE_NEW
9337 && !structured_block
9338 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9339 code
= OMP_ATOMIC_CAPTURE_OLD
;
9345 switch (c_parser_peek_token (parser
)->type
)
9351 opcode
= TRUNC_DIV_EXPR
;
9357 opcode
= MINUS_EXPR
;
9360 opcode
= LSHIFT_EXPR
;
9363 opcode
= RSHIFT_EXPR
;
9366 opcode
= BIT_AND_EXPR
;
9369 opcode
= BIT_IOR_EXPR
;
9372 opcode
= BIT_XOR_EXPR
;
9375 if (structured_block
|| code
== OMP_ATOMIC
)
9377 location_t aloc
= c_parser_peek_token (parser
)->location
;
9379 enum c_parser_prec oprec
= PREC_NONE
;
9381 c_parser_consume_token (parser
);
9382 rhs1
= c_parser_unary_expression (parser
).value
;
9383 rhs1
= c_fully_fold (rhs1
, false, NULL
);
9384 if (rhs1
== error_mark_node
)
9386 switch (c_parser_peek_token (parser
)->type
)
9389 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9391 code
= OMP_ATOMIC_CAPTURE_OLD
;
9396 c_parser_consume_token (parser
);
9399 c_parser_error (parser
,
9400 "invalid form of %<#pragma omp atomic%>");
9407 opcode
= TRUNC_DIV_EXPR
;
9415 opcode
= MINUS_EXPR
;
9419 opcode
= LSHIFT_EXPR
;
9423 opcode
= RSHIFT_EXPR
;
9427 opcode
= BIT_AND_EXPR
;
9428 oprec
= PREC_BITAND
;
9431 opcode
= BIT_IOR_EXPR
;
9435 opcode
= BIT_XOR_EXPR
;
9436 oprec
= PREC_BITXOR
;
9439 c_parser_error (parser
,
9440 "invalid operator for %<#pragma omp atomic%>");
9444 c_parser_consume_token (parser
);
9445 rhs_loc
= c_parser_peek_token (parser
)->location
;
9446 if (commutative_tree_code (opcode
))
9447 oprec
= (enum c_parser_prec
) (oprec
- 1);
9448 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
9449 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
9451 rhs
= rhs_expr
.value
;
9452 rhs
= c_fully_fold (rhs
, false, NULL
);
9457 c_parser_error (parser
,
9458 "invalid operator for %<#pragma omp atomic%>");
9462 /* Arrange to pass the location of the assignment operator to
9463 c_finish_omp_atomic. */
9464 loc
= c_parser_peek_token (parser
)->location
;
9465 c_parser_consume_token (parser
);
9467 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9468 rhs_expr
= c_parser_expression (parser
);
9469 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9471 rhs
= rhs_expr
.value
;
9472 rhs
= c_fully_fold (rhs
, false, NULL
);
9476 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
9478 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
9480 v
= c_parser_unary_expression (parser
).value
;
9481 v
= c_fully_fold (v
, false, NULL
);
9482 if (v
== error_mark_node
)
9484 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9486 lhs1
= c_parser_unary_expression (parser
).value
;
9487 lhs1
= c_fully_fold (lhs1
, false, NULL
);
9488 if (lhs1
== error_mark_node
)
9491 if (structured_block
)
9493 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9494 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
9497 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
9498 if (stmt
!= error_mark_node
)
9501 if (!structured_block
)
9502 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9507 # pragma omp barrier new-line
9511 c_parser_omp_barrier (c_parser
*parser
)
9513 location_t loc
= c_parser_peek_token (parser
)->location
;
9514 c_parser_consume_pragma (parser
);
9515 c_parser_skip_to_pragma_eol (parser
);
9517 c_finish_omp_barrier (loc
);
9521 # pragma omp critical [(name)] new-line
9524 LOC is the location of the #pragma itself. */
9527 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9529 tree stmt
, name
= NULL
;
9531 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9533 c_parser_consume_token (parser
);
9534 if (c_parser_next_token_is (parser
, CPP_NAME
))
9536 name
= c_parser_peek_token (parser
)->value
;
9537 c_parser_consume_token (parser
);
9538 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9541 c_parser_error (parser
, "expected identifier");
9543 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9544 c_parser_error (parser
, "expected %<(%> or end of line");
9545 c_parser_skip_to_pragma_eol (parser
);
9547 stmt
= c_parser_omp_structured_block (parser
);
9548 return c_finish_omp_critical (loc
, stmt
, name
);
9552 # pragma omp flush flush-vars[opt] new-line
9555 ( variable-list ) */
9558 c_parser_omp_flush (c_parser
*parser
)
9560 location_t loc
= c_parser_peek_token (parser
)->location
;
9561 c_parser_consume_pragma (parser
);
9562 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9563 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9564 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9565 c_parser_error (parser
, "expected %<(%> or end of line");
9566 c_parser_skip_to_pragma_eol (parser
);
9568 c_finish_omp_flush (loc
);
9571 /* Parse the restricted form of the for statement allowed by OpenMP.
9572 The real trick here is to determine the loop control variable early
9573 so that we can push a new decl if necessary to make it private.
9574 LOC is the location of the OMP in "#pragma omp". */
9577 c_parser_omp_for_loop (location_t loc
,
9578 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
9580 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
9581 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
9582 bool fail
= false, open_brace_parsed
= false;
9583 int i
, collapse
= 1, nbraces
= 0;
9585 VEC(tree
,gc
) *for_block
= make_tree_vector ();
9587 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
9588 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
9589 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
9591 gcc_assert (collapse
>= 1);
9593 declv
= make_tree_vec (collapse
);
9594 initv
= make_tree_vec (collapse
);
9595 condv
= make_tree_vec (collapse
);
9596 incrv
= make_tree_vec (collapse
);
9598 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
9600 c_parser_error (parser
, "for statement expected");
9603 for_loc
= c_parser_peek_token (parser
)->location
;
9604 c_parser_consume_token (parser
);
9606 for (i
= 0; i
< collapse
; i
++)
9610 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9613 /* Parse the initialization declaration or expression. */
9614 if (c_parser_next_tokens_start_declaration (parser
))
9617 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
9618 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
9619 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
9622 if (DECL_INITIAL (decl
) == error_mark_node
)
9623 decl
= error_mark_node
;
9626 else if (c_parser_next_token_is (parser
, CPP_NAME
)
9627 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
9629 struct c_expr decl_exp
;
9630 struct c_expr init_exp
;
9631 location_t init_loc
;
9633 decl_exp
= c_parser_postfix_expression (parser
);
9634 decl
= decl_exp
.value
;
9636 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
9638 init_loc
= c_parser_peek_token (parser
)->location
;
9639 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
9640 init_exp
= default_function_array_read_conversion (init_loc
,
9642 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
9643 NOP_EXPR
, init_loc
, init_exp
.value
,
9644 init_exp
.original_type
);
9645 init
= c_process_expr_stmt (init_loc
, init
);
9647 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9652 c_parser_error (parser
,
9653 "expected iteration declaration or initialization");
9654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9660 /* Parse the loop condition. */
9662 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
9664 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
9665 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
9668 cond
= cond_expr
.value
;
9669 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
9670 cond
= c_fully_fold (cond
, false, NULL
);
9671 switch (cond_expr
.original_code
)
9679 /* Can't be cond = error_mark_node, because we want to preserve
9680 the location until c_finish_omp_for. */
9681 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
9684 protected_set_expr_location (cond
, cond_loc
);
9686 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9688 /* Parse the increment expression. */
9690 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
9692 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
9694 incr
= c_process_expr_stmt (incr_loc
,
9695 c_parser_expression (parser
).value
);
9697 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9699 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
9703 TREE_VEC_ELT (declv
, i
) = decl
;
9704 TREE_VEC_ELT (initv
, i
) = init
;
9705 TREE_VEC_ELT (condv
, i
) = cond
;
9706 TREE_VEC_ELT (incrv
, i
) = incr
;
9710 if (i
== collapse
- 1)
9713 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9714 in between the collapsed for loops to be still considered perfectly
9715 nested. Hopefully the final version clarifies this.
9716 For now handle (multiple) {'s and empty statements. */
9719 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9721 c_parser_consume_token (parser
);
9724 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9726 c_parser_consume_token (parser
);
9730 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9731 c_parser_consume_token (parser
);
9734 c_parser_error (parser
, "not enough perfectly nested loops");
9737 open_brace_parsed
= true;
9747 nbraces
+= bracecount
;
9750 save_break
= c_break_label
;
9751 c_break_label
= size_one_node
;
9752 save_cont
= c_cont_label
;
9753 c_cont_label
= NULL_TREE
;
9754 body
= push_stmt_list ();
9756 if (open_brace_parsed
)
9758 location_t here
= c_parser_peek_token (parser
)->location
;
9759 stmt
= c_begin_compound_stmt (true);
9760 c_parser_compound_statement_nostart (parser
);
9761 add_stmt (c_end_compound_stmt (here
, stmt
, true));
9764 add_stmt (c_parser_c99_block_statement (parser
));
9767 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
9768 SET_EXPR_LOCATION (t
, loc
);
9772 body
= pop_stmt_list (body
);
9773 c_break_label
= save_break
;
9774 c_cont_label
= save_cont
;
9778 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9780 c_parser_consume_token (parser
);
9783 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9784 c_parser_consume_token (parser
);
9787 c_parser_error (parser
, "collapsed loops not perfectly nested");
9790 location_t here
= c_parser_peek_token (parser
)->location
;
9791 stmt
= c_begin_compound_stmt (true);
9793 c_parser_compound_statement_nostart (parser
);
9794 body
= c_end_compound_stmt (here
, stmt
, true);
9801 /* Only bother calling c_finish_omp_for if we haven't already generated
9802 an error from the initialization parsing. */
9805 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
9808 if (par_clauses
!= NULL
)
9811 for (c
= par_clauses
; *c
; )
9812 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
9813 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
9814 c
= &OMP_CLAUSE_CHAIN (*c
);
9817 for (i
= 0; i
< collapse
; i
++)
9818 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
9821 c
= &OMP_CLAUSE_CHAIN (*c
);
9822 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
9825 "iteration variable %qD should not be firstprivate",
9826 OMP_CLAUSE_DECL (*c
));
9827 *c
= OMP_CLAUSE_CHAIN (*c
);
9831 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9832 change it to shared (decl) in
9833 OMP_PARALLEL_CLAUSES. */
9834 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
9835 OMP_CLAUSE_LASTPRIVATE
);
9836 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
9837 OMP_CLAUSE_CHAIN (l
) = clauses
;
9839 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
9843 OMP_FOR_CLAUSES (stmt
) = clauses
;
9848 while (!VEC_empty (tree
, for_block
))
9850 /* FIXME diagnostics: LOC below should be the actual location of
9851 this particular for block. We need to build a list of
9852 locations to go along with FOR_BLOCK. */
9853 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
9856 release_tree_vector (for_block
);
9861 #pragma omp for for-clause[optseq] new-line
9864 LOC is the location of the #pragma token.
9867 #define OMP_FOR_CLAUSE_MASK \
9868 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9869 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9870 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9871 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9872 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9873 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9874 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9875 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9878 c_parser_omp_for (location_t loc
, c_parser
*parser
)
9880 tree block
, clauses
, ret
;
9882 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
9885 block
= c_begin_compound_stmt (true);
9886 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
9887 block
= c_end_compound_stmt (loc
, block
, true);
9894 # pragma omp master new-line
9897 LOC is the location of the #pragma token.
9901 c_parser_omp_master (location_t loc
, c_parser
*parser
)
9903 c_parser_skip_to_pragma_eol (parser
);
9904 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
9908 # pragma omp ordered new-line
9911 LOC is the location of the #pragma itself.
9915 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
9917 c_parser_skip_to_pragma_eol (parser
);
9918 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
9924 { section-sequence }
9927 section-directive[opt] structured-block
9928 section-sequence section-directive structured-block
9930 SECTIONS_LOC is the location of the #pragma omp sections. */
9933 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
9936 bool error_suppress
= false;
9939 loc
= c_parser_peek_token (parser
)->location
;
9940 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9942 /* Avoid skipping until the end of the block. */
9943 parser
->error
= false;
9947 stmt
= push_stmt_list ();
9949 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
9951 substmt
= push_stmt_list ();
9955 c_parser_statement (parser
);
9957 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9959 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9961 if (c_parser_next_token_is (parser
, CPP_EOF
))
9965 substmt
= pop_stmt_list (substmt
);
9966 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9967 SET_EXPR_LOCATION (substmt
, loc
);
9973 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9975 if (c_parser_next_token_is (parser
, CPP_EOF
))
9978 loc
= c_parser_peek_token (parser
)->location
;
9979 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9981 c_parser_consume_pragma (parser
);
9982 c_parser_skip_to_pragma_eol (parser
);
9983 error_suppress
= false;
9985 else if (!error_suppress
)
9987 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
9988 error_suppress
= true;
9991 substmt
= c_parser_omp_structured_block (parser
);
9992 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9993 SET_EXPR_LOCATION (substmt
, loc
);
9996 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
9997 "expected %<#pragma omp section%> or %<}%>");
9999 substmt
= pop_stmt_list (stmt
);
10001 stmt
= make_node (OMP_SECTIONS
);
10002 SET_EXPR_LOCATION (stmt
, sections_loc
);
10003 TREE_TYPE (stmt
) = void_type_node
;
10004 OMP_SECTIONS_BODY (stmt
) = substmt
;
10006 return add_stmt (stmt
);
10010 # pragma omp sections sections-clause[optseq] newline
10013 LOC is the location of the #pragma token.
10016 #define OMP_SECTIONS_CLAUSE_MASK \
10017 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10018 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10019 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10020 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10021 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10024 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10026 tree block
, clauses
, ret
;
10028 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10029 "#pragma omp sections");
10031 block
= c_begin_compound_stmt (true);
10032 ret
= c_parser_omp_sections_scope (loc
, parser
);
10034 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10035 block
= c_end_compound_stmt (loc
, block
, true);
10042 # pragma parallel parallel-clause new-line
10043 # pragma parallel for parallel-for-clause new-line
10044 # pragma parallel sections parallel-sections-clause new-line
10046 LOC is the location of the #pragma token.
10049 #define OMP_PARALLEL_CLAUSE_MASK \
10050 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10051 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10052 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10053 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10054 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10055 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10056 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10057 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10060 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10062 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10063 const char *p_name
= "#pragma omp parallel";
10064 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10065 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10067 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10069 c_parser_consume_token (parser
);
10070 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10071 p_name
= "#pragma omp parallel for";
10072 mask
|= OMP_FOR_CLAUSE_MASK
;
10073 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10075 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10077 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10078 if (strcmp (p
, "sections") == 0)
10080 c_parser_consume_token (parser
);
10081 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10082 p_name
= "#pragma omp parallel sections";
10083 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10084 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10088 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10092 case PRAGMA_OMP_PARALLEL
:
10093 block
= c_begin_omp_parallel ();
10094 c_parser_statement (parser
);
10095 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10098 case PRAGMA_OMP_PARALLEL_FOR
:
10099 block
= c_begin_omp_parallel ();
10100 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10101 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10102 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10103 OMP_PARALLEL_COMBINED (stmt
) = 1;
10106 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10107 block
= c_begin_omp_parallel ();
10108 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10109 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10111 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10112 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10113 OMP_PARALLEL_COMBINED (stmt
) = 1;
10117 gcc_unreachable ();
10124 # pragma omp single single-clause[optseq] new-line
10127 LOC is the location of the #pragma.
10130 #define OMP_SINGLE_CLAUSE_MASK \
10131 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10132 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10133 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10134 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10137 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10139 tree stmt
= make_node (OMP_SINGLE
);
10140 SET_EXPR_LOCATION (stmt
, loc
);
10141 TREE_TYPE (stmt
) = void_type_node
;
10143 OMP_SINGLE_CLAUSES (stmt
)
10144 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10145 "#pragma omp single");
10146 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10148 return add_stmt (stmt
);
10152 # pragma omp task task-clause[optseq] new-line
10154 LOC is the location of the #pragma.
10157 #define OMP_TASK_CLAUSE_MASK \
10158 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10159 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10160 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10161 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10162 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10163 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10164 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10165 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10168 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10170 tree clauses
, block
;
10172 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10173 "#pragma omp task");
10175 block
= c_begin_omp_task ();
10176 c_parser_statement (parser
);
10177 return c_finish_omp_task (loc
, clauses
, block
);
10181 # pragma omp taskwait new-line
10185 c_parser_omp_taskwait (c_parser
*parser
)
10187 location_t loc
= c_parser_peek_token (parser
)->location
;
10188 c_parser_consume_pragma (parser
);
10189 c_parser_skip_to_pragma_eol (parser
);
10191 c_finish_omp_taskwait (loc
);
10195 # pragma omp taskyield new-line
10199 c_parser_omp_taskyield (c_parser
*parser
)
10201 location_t loc
= c_parser_peek_token (parser
)->location
;
10202 c_parser_consume_pragma (parser
);
10203 c_parser_skip_to_pragma_eol (parser
);
10205 c_finish_omp_taskyield (loc
);
10208 /* Main entry point to parsing most OpenMP pragmas. */
10211 c_parser_omp_construct (c_parser
*parser
)
10213 enum pragma_kind p_kind
;
10217 loc
= c_parser_peek_token (parser
)->location
;
10218 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
10219 c_parser_consume_pragma (parser
);
10223 case PRAGMA_OMP_ATOMIC
:
10224 c_parser_omp_atomic (loc
, parser
);
10226 case PRAGMA_OMP_CRITICAL
:
10227 stmt
= c_parser_omp_critical (loc
, parser
);
10229 case PRAGMA_OMP_FOR
:
10230 stmt
= c_parser_omp_for (loc
, parser
);
10232 case PRAGMA_OMP_MASTER
:
10233 stmt
= c_parser_omp_master (loc
, parser
);
10235 case PRAGMA_OMP_ORDERED
:
10236 stmt
= c_parser_omp_ordered (loc
, parser
);
10238 case PRAGMA_OMP_PARALLEL
:
10239 stmt
= c_parser_omp_parallel (loc
, parser
);
10241 case PRAGMA_OMP_SECTIONS
:
10242 stmt
= c_parser_omp_sections (loc
, parser
);
10244 case PRAGMA_OMP_SINGLE
:
10245 stmt
= c_parser_omp_single (loc
, parser
);
10247 case PRAGMA_OMP_TASK
:
10248 stmt
= c_parser_omp_task (loc
, parser
);
10251 gcc_unreachable ();
10255 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
10260 # pragma omp threadprivate (variable-list) */
10263 c_parser_omp_threadprivate (c_parser
*parser
)
10268 c_parser_consume_pragma (parser
);
10269 loc
= c_parser_peek_token (parser
)->location
;
10270 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10272 /* Mark every variable in VARS to be assigned thread local storage. */
10273 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
10275 tree v
= TREE_PURPOSE (t
);
10277 /* FIXME diagnostics: Ideally we should keep individual
10278 locations for all the variables in the var list to make the
10279 following errors more precise. Perhaps
10280 c_parser_omp_var_list_parens() should construct a list of
10281 locations to go along with the var list. */
10283 /* If V had already been marked threadprivate, it doesn't matter
10284 whether it had been used prior to this point. */
10285 if (TREE_CODE (v
) != VAR_DECL
)
10286 error_at (loc
, "%qD is not a variable", v
);
10287 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
10288 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
10289 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
10290 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
10291 else if (TREE_TYPE (v
) == error_mark_node
)
10293 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
10294 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
10297 if (! DECL_THREAD_LOCAL_P (v
))
10299 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
10300 /* If rtl has been already set for this var, call
10301 make_decl_rtl once again, so that encode_section_info
10302 has a chance to look at the new decl flags. */
10303 if (DECL_RTL_SET_P (v
))
10306 C_DECL_THREADPRIVATE_P (v
) = 1;
10310 c_parser_skip_to_pragma_eol (parser
);
10314 /* Parse a single source file. */
10317 c_parse_file (void)
10319 /* Use local storage to begin. If the first token is a pragma, parse it.
10320 If it is #pragma GCC pch_preprocess, then this will load a PCH file
10321 which will cause garbage collection. */
10324 memset (&tparser
, 0, sizeof tparser
);
10325 the_parser
= &tparser
;
10327 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
10328 c_parser_pragma_pch_preprocess (&tparser
);
10330 the_parser
= ggc_alloc_c_parser ();
10331 *the_parser
= tparser
;
10333 /* Initialize EH, if we've been told to do so. */
10334 if (flag_exceptions
)
10335 using_eh_for_cleanups ();
10337 c_parser_translation_unit (the_parser
);
10341 #include "gt-c-parser.h"