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 static void c_parser_external_declaration (c_parser
*);
1094 static void c_parser_asm_definition (c_parser
*);
1095 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1096 bool, bool, tree
*);
1097 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1098 static void c_parser_static_assert_declaration (c_parser
*);
1099 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1100 bool, enum c_lookahead_kind
);
1101 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1102 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1103 static tree
c_parser_struct_declaration (c_parser
*);
1104 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1105 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1107 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1109 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1111 struct c_declarator
*);
1112 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1113 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1115 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1116 static tree
c_parser_simple_asm_expr (c_parser
*);
1117 static tree
c_parser_attributes (c_parser
*);
1118 static struct c_type_name
*c_parser_type_name (c_parser
*);
1119 static struct c_expr
c_parser_initializer (c_parser
*);
1120 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1121 static void c_parser_initelt (c_parser
*, struct obstack
*);
1122 static void c_parser_initval (c_parser
*, struct c_expr
*,
1124 static tree
c_parser_compound_statement (c_parser
*);
1125 static void c_parser_compound_statement_nostart (c_parser
*);
1126 static void c_parser_label (c_parser
*);
1127 static void c_parser_statement (c_parser
*);
1128 static void c_parser_statement_after_labels (c_parser
*);
1129 static void c_parser_if_statement (c_parser
*);
1130 static void c_parser_switch_statement (c_parser
*);
1131 static void c_parser_while_statement (c_parser
*);
1132 static void c_parser_do_statement (c_parser
*);
1133 static void c_parser_for_statement (c_parser
*);
1134 static tree
c_parser_asm_statement (c_parser
*);
1135 static tree
c_parser_asm_operands (c_parser
*, bool);
1136 static tree
c_parser_asm_goto_operands (c_parser
*);
1137 static tree
c_parser_asm_clobbers (c_parser
*);
1138 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1139 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1141 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
1142 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1143 static struct c_expr
c_parser_unary_expression (c_parser
*);
1144 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1145 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1146 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1147 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1148 struct c_type_name
*,
1150 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1153 static struct c_expr
c_parser_expression (c_parser
*);
1154 static struct c_expr
c_parser_expression_conv (c_parser
*);
1155 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
1157 static void c_parser_omp_construct (c_parser
*);
1158 static void c_parser_omp_threadprivate (c_parser
*);
1159 static void c_parser_omp_barrier (c_parser
*);
1160 static void c_parser_omp_flush (c_parser
*);
1161 static void c_parser_omp_taskwait (c_parser
*);
1163 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1164 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1166 /* These Objective-C parser functions are only ever called when
1167 compiling Objective-C. */
1168 static void c_parser_objc_class_definition (c_parser
*, tree
);
1169 static void c_parser_objc_class_instance_variables (c_parser
*);
1170 static void c_parser_objc_class_declaration (c_parser
*);
1171 static void c_parser_objc_alias_declaration (c_parser
*);
1172 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1173 static bool c_parser_objc_method_type (c_parser
*);
1174 static void c_parser_objc_method_definition (c_parser
*);
1175 static void c_parser_objc_methodprotolist (c_parser
*);
1176 static void c_parser_objc_methodproto (c_parser
*);
1177 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1178 static tree
c_parser_objc_type_name (c_parser
*);
1179 static tree
c_parser_objc_protocol_refs (c_parser
*);
1180 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1181 static void c_parser_objc_synchronized_statement (c_parser
*);
1182 static tree
c_parser_objc_selector (c_parser
*);
1183 static tree
c_parser_objc_selector_arg (c_parser
*);
1184 static tree
c_parser_objc_receiver (c_parser
*);
1185 static tree
c_parser_objc_message_args (c_parser
*);
1186 static tree
c_parser_objc_keywordexpr (c_parser
*);
1187 static void c_parser_objc_at_property_declaration (c_parser
*);
1188 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1189 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1190 static bool c_parser_objc_diagnose_bad_element_prefix
1191 (c_parser
*, struct c_declspecs
*);
1193 /* Parse a translation unit (C90 6.7, C99 6.9).
1196 external-declarations
1198 external-declarations:
1199 external-declaration
1200 external-declarations external-declaration
1209 c_parser_translation_unit (c_parser
*parser
)
1211 if (c_parser_next_token_is (parser
, CPP_EOF
))
1213 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1214 "ISO C forbids an empty translation unit");
1218 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1219 mark_valid_location_for_stdc_pragma (false);
1223 c_parser_external_declaration (parser
);
1224 obstack_free (&parser_obstack
, obstack_position
);
1226 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1230 /* Parse an external declaration (C90 6.7, C99 6.9).
1232 external-declaration:
1238 external-declaration:
1241 __extension__ external-declaration
1245 external-declaration:
1246 objc-class-definition
1247 objc-class-declaration
1248 objc-alias-declaration
1249 objc-protocol-definition
1250 objc-method-definition
1255 c_parser_external_declaration (c_parser
*parser
)
1258 switch (c_parser_peek_token (parser
)->type
)
1261 switch (c_parser_peek_token (parser
)->keyword
)
1264 ext
= disable_extension_diagnostics ();
1265 c_parser_consume_token (parser
);
1266 c_parser_external_declaration (parser
);
1267 restore_extension_diagnostics (ext
);
1270 c_parser_asm_definition (parser
);
1272 case RID_AT_INTERFACE
:
1273 case RID_AT_IMPLEMENTATION
:
1274 gcc_assert (c_dialect_objc ());
1275 c_parser_objc_class_definition (parser
, NULL_TREE
);
1278 gcc_assert (c_dialect_objc ());
1279 c_parser_objc_class_declaration (parser
);
1282 gcc_assert (c_dialect_objc ());
1283 c_parser_objc_alias_declaration (parser
);
1285 case RID_AT_PROTOCOL
:
1286 gcc_assert (c_dialect_objc ());
1287 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1289 case RID_AT_PROPERTY
:
1290 gcc_assert (c_dialect_objc ());
1291 c_parser_objc_at_property_declaration (parser
);
1293 case RID_AT_SYNTHESIZE
:
1294 gcc_assert (c_dialect_objc ());
1295 c_parser_objc_at_synthesize_declaration (parser
);
1297 case RID_AT_DYNAMIC
:
1298 gcc_assert (c_dialect_objc ());
1299 c_parser_objc_at_dynamic_declaration (parser
);
1302 gcc_assert (c_dialect_objc ());
1303 c_parser_consume_token (parser
);
1304 objc_finish_implementation ();
1311 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1312 "ISO C does not allow extra %<;%> outside of a function");
1313 c_parser_consume_token (parser
);
1316 mark_valid_location_for_stdc_pragma (true);
1317 c_parser_pragma (parser
, pragma_external
);
1318 mark_valid_location_for_stdc_pragma (false);
1322 if (c_dialect_objc ())
1324 c_parser_objc_method_definition (parser
);
1327 /* Else fall through, and yield a syntax error trying to parse
1328 as a declaration or function definition. */
1331 /* A declaration or a function definition (or, in Objective-C,
1332 an @interface or @protocol with prefix attributes). We can
1333 only tell which after parsing the declaration specifiers, if
1334 any, and the first declarator. */
1335 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1340 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1341 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1342 accepted; otherwise (old-style parameter declarations) only other
1343 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1344 assertion is accepted; otherwise (old-style parameter declarations)
1345 it is not. If NESTED is true, we are inside a function or parsing
1346 old-style parameter declarations; any functions encountered are
1347 nested functions and declaration specifiers are required; otherwise
1348 we are at top level and functions are normal functions and
1349 declaration specifiers may be optional. If EMPTY_OK is true, empty
1350 declarations are OK (subject to all other constraints); otherwise
1351 (old-style parameter declarations) they are diagnosed. If
1352 START_ATTR_OK is true, the declaration specifiers may start with
1353 attributes; otherwise they may not.
1354 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1355 declaration when parsing an Objective-C foreach statement.
1358 declaration-specifiers init-declarator-list[opt] ;
1359 static_assert-declaration
1361 function-definition:
1362 declaration-specifiers[opt] declarator declaration-list[opt]
1367 declaration-list declaration
1369 init-declarator-list:
1371 init-declarator-list , init-declarator
1374 declarator simple-asm-expr[opt] attributes[opt]
1375 declarator simple-asm-expr[opt] attributes[opt] = initializer
1379 nested-function-definition:
1380 declaration-specifiers declarator declaration-list[opt]
1384 attributes objc-class-definition
1385 attributes objc-category-definition
1386 attributes objc-protocol-definition
1388 The simple-asm-expr and attributes are GNU extensions.
1390 This function does not handle __extension__; that is handled in its
1391 callers. ??? Following the old parser, __extension__ may start
1392 external declarations, declarations in functions and declarations
1393 at the start of "for" loops, but not old-style parameter
1396 C99 requires declaration specifiers in a function definition; the
1397 absence is diagnosed through the diagnosis of implicit int. In GNU
1398 C we also allow but diagnose declarations without declaration
1399 specifiers, but only at top level (elsewhere they conflict with
1402 In Objective-C, declarations of the looping variable in a foreach
1403 statement are exceptionally terminated by 'in' (for example, 'for
1404 (NSObject *object in array) { ... }').
1409 threadprivate-directive */
1412 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1413 bool static_assert_ok
, bool empty_ok
,
1414 bool nested
, bool start_attr_ok
,
1415 tree
*objc_foreach_object_declaration
)
1417 struct c_declspecs
*specs
;
1419 tree all_prefix_attrs
;
1420 bool diagnosed_no_specs
= false;
1421 location_t here
= c_parser_peek_token (parser
)->location
;
1423 if (static_assert_ok
1424 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1426 c_parser_static_assert_declaration (parser
);
1429 specs
= build_null_declspecs ();
1431 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1432 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1433 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1434 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1435 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1436 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1438 error_at (here
, "unknown type name %qE",
1439 c_parser_peek_token (parser
)->value
);
1441 /* Parse declspecs normally to get a correct pointer type, but avoid
1442 a further "fails to be a type name" error. Refuse nested functions
1443 since it is not how the user likely wants us to recover. */
1444 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1445 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1446 c_parser_peek_token (parser
)->value
= error_mark_node
;
1450 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1453 c_parser_skip_to_end_of_block_or_statement (parser
);
1456 if (nested
&& !specs
->declspecs_seen_p
)
1458 c_parser_error (parser
, "expected declaration specifiers");
1459 c_parser_skip_to_end_of_block_or_statement (parser
);
1462 finish_declspecs (specs
);
1463 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1469 shadow_tag_warned (specs
, 1);
1470 pedwarn (here
, 0, "empty declaration");
1472 c_parser_consume_token (parser
);
1476 /* Provide better error recovery. Note that a type name here is usually
1477 better diagnosed as a redeclaration. */
1479 && specs
->typespec_kind
== ctsk_tagdef
1480 && c_parser_next_token_starts_declspecs (parser
)
1481 && !c_parser_next_token_is (parser
, CPP_NAME
))
1483 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1484 parser
->error
= false;
1485 shadow_tag_warned (specs
, 1);
1488 else if (c_dialect_objc ())
1490 /* Prefix attributes are an error on method decls. */
1491 switch (c_parser_peek_token (parser
)->type
)
1495 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1499 warning_at (c_parser_peek_token (parser
)->location
,
1501 "prefix attributes are ignored for methods");
1502 specs
->attrs
= NULL_TREE
;
1505 c_parser_objc_method_definition (parser
);
1507 c_parser_objc_methodproto (parser
);
1513 /* This is where we parse 'attributes @interface ...',
1514 'attributes @implementation ...', 'attributes @protocol ...'
1515 (where attributes could be, for example, __attribute__
1518 switch (c_parser_peek_token (parser
)->keyword
)
1520 case RID_AT_INTERFACE
:
1522 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1524 c_parser_objc_class_definition (parser
, specs
->attrs
);
1528 case RID_AT_IMPLEMENTATION
:
1530 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1534 warning_at (c_parser_peek_token (parser
)->location
,
1536 "prefix attributes are ignored for implementations");
1537 specs
->attrs
= NULL_TREE
;
1539 c_parser_objc_class_definition (parser
, NULL_TREE
);
1543 case RID_AT_PROTOCOL
:
1545 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1547 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1554 case RID_AT_PROPERTY
:
1557 c_parser_error (parser
, "unexpected attribute");
1558 specs
->attrs
= NULL
;
1566 pending_xref_error ();
1567 prefix_attrs
= specs
->attrs
;
1568 all_prefix_attrs
= prefix_attrs
;
1569 specs
->attrs
= NULL_TREE
;
1572 struct c_declarator
*declarator
;
1576 /* Declaring either one or more declarators (in which case we
1577 should diagnose if there were no declaration specifiers) or a
1578 function definition (in which case the diagnostic for
1579 implicit int suffices). */
1580 declarator
= c_parser_declarator (parser
,
1581 specs
->typespec_kind
!= ctsk_none
,
1582 C_DTR_NORMAL
, &dummy
);
1583 if (declarator
== NULL
)
1585 c_parser_skip_to_end_of_block_or_statement (parser
);
1588 if (c_parser_next_token_is (parser
, CPP_EQ
)
1589 || c_parser_next_token_is (parser
, CPP_COMMA
)
1590 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1591 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1592 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1593 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1595 tree asm_name
= NULL_TREE
;
1596 tree postfix_attrs
= NULL_TREE
;
1597 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1599 diagnosed_no_specs
= true;
1600 pedwarn (here
, 0, "data definition has no type or storage class");
1602 /* Having seen a data definition, there cannot now be a
1603 function definition. */
1605 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1606 asm_name
= c_parser_simple_asm_expr (parser
);
1607 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1608 postfix_attrs
= c_parser_attributes (parser
);
1609 if (c_parser_next_token_is (parser
, CPP_EQ
))
1613 location_t init_loc
;
1614 c_parser_consume_token (parser
);
1615 /* The declaration of the variable is in effect while
1616 its initializer is parsed. */
1617 d
= start_decl (declarator
, specs
, true,
1618 chainon (postfix_attrs
, all_prefix_attrs
));
1620 d
= error_mark_node
;
1621 start_init (d
, asm_name
, global_bindings_p ());
1622 init_loc
= c_parser_peek_token (parser
)->location
;
1623 init
= c_parser_initializer (parser
);
1625 if (d
!= error_mark_node
)
1627 maybe_warn_string_init (TREE_TYPE (d
), init
);
1628 finish_decl (d
, init_loc
, init
.value
,
1629 init
.original_type
, asm_name
);
1634 tree d
= start_decl (declarator
, specs
, false,
1635 chainon (postfix_attrs
,
1638 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1639 NULL_TREE
, asm_name
);
1641 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1644 *objc_foreach_object_declaration
= d
;
1646 *objc_foreach_object_declaration
= error_mark_node
;
1649 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1651 c_parser_consume_token (parser
);
1652 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1653 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1656 all_prefix_attrs
= prefix_attrs
;
1659 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1661 c_parser_consume_token (parser
);
1664 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1666 /* This can only happen in Objective-C: we found the
1667 'in' that terminates the declaration inside an
1668 Objective-C foreach statement. Do not consume the
1669 token, so that the caller can use it to determine
1670 that this indeed is a foreach context. */
1675 c_parser_error (parser
, "expected %<,%> or %<;%>");
1676 c_parser_skip_to_end_of_block_or_statement (parser
);
1682 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1683 "%<asm%> or %<__attribute__%>");
1684 c_parser_skip_to_end_of_block_or_statement (parser
);
1687 /* Function definition (nested or otherwise). */
1688 timevar_push (TV_PARSE_FUNC
);
1691 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1692 c_push_function_context ();
1694 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1696 /* This can appear in many cases looking nothing like a
1697 function definition, so we don't give a more specific
1698 error suggesting there was one. */
1699 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1700 "or %<__attribute__%>");
1702 c_pop_function_context ();
1706 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1707 tv
= TV_PARSE_INLINE
;
1712 /* Parse old-style parameter declarations. ??? Attributes are
1713 not allowed to start declaration specifiers here because of a
1714 syntax conflict between a function declaration with attribute
1715 suffix and a function definition with an attribute prefix on
1716 first old-style parameter declaration. Following the old
1717 parser, they are not accepted on subsequent old-style
1718 parameter declarations either. However, there is no
1719 ambiguity after the first declaration, nor indeed on the
1720 first as long as we don't allow postfix attributes after a
1721 declarator with a nonempty identifier list in a definition;
1722 and postfix attributes have never been accepted here in
1723 function definitions either. */
1724 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1725 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1726 c_parser_declaration_or_fndef (parser
, false, false, false,
1728 store_parm_decls ();
1729 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1730 = c_parser_peek_token (parser
)->location
;
1731 fnbody
= c_parser_compound_statement (parser
);
1734 tree decl
= current_function_decl
;
1735 /* Mark nested functions as needing static-chain initially.
1736 lower_nested_functions will recompute it but the
1737 DECL_STATIC_CHAIN flag is also used before that happens,
1738 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1739 DECL_STATIC_CHAIN (decl
) = 1;
1742 c_pop_function_context ();
1743 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1756 /* Parse an asm-definition (asm() outside a function body). This is a
1764 c_parser_asm_definition (c_parser
*parser
)
1766 tree asm_str
= c_parser_simple_asm_expr (parser
);
1768 cgraph_add_asm_node (asm_str
);
1769 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1772 /* Parse a static assertion (C1X N1425 6.7.10).
1774 static_assert-declaration:
1775 static_assert-declaration-no-semi ;
1779 c_parser_static_assert_declaration (c_parser
*parser
)
1781 c_parser_static_assert_declaration_no_semi (parser
);
1783 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1784 c_parser_skip_to_end_of_block_or_statement (parser
);
1787 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1790 static_assert-declaration-no-semi:
1791 _Static_assert ( constant-expression , string-literal )
1795 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1797 location_t assert_loc
, value_loc
;
1801 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1802 assert_loc
= c_parser_peek_token (parser
)->location
;
1806 pedwarn (assert_loc
, OPT_pedantic
,
1807 "ISO C99 does not support %<_Static_assert%>");
1809 pedwarn (assert_loc
, OPT_pedantic
,
1810 "ISO C90 does not support %<_Static_assert%>");
1812 c_parser_consume_token (parser
);
1813 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1815 value_loc
= c_parser_peek_token (parser
)->location
;
1816 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1817 parser
->lex_untranslated_string
= true;
1818 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1820 parser
->lex_untranslated_string
= false;
1823 switch (c_parser_peek_token (parser
)->type
)
1829 case CPP_UTF8STRING
:
1830 string
= c_parser_peek_token (parser
)->value
;
1831 c_parser_consume_token (parser
);
1832 parser
->lex_untranslated_string
= false;
1835 c_parser_error (parser
, "expected string literal");
1836 parser
->lex_untranslated_string
= false;
1839 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1841 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1843 error_at (value_loc
, "expression in static assertion is not an integer");
1846 if (TREE_CODE (value
) != INTEGER_CST
)
1848 value
= c_fully_fold (value
, false, NULL
);
1849 if (TREE_CODE (value
) == INTEGER_CST
)
1850 pedwarn (value_loc
, OPT_pedantic
, "expression in static assertion "
1851 "is not an integer constant expression");
1853 if (TREE_CODE (value
) != INTEGER_CST
)
1855 error_at (value_loc
, "expression in static assertion is not constant");
1858 constant_expression_warning (value
);
1859 if (integer_zerop (value
))
1860 error_at (assert_loc
, "static assertion failed: %E", string
);
1863 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1864 6.7), adding them to SPECS (which may already include some).
1865 Storage class specifiers are accepted iff SCSPEC_OK; type
1866 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1867 the start iff START_ATTR_OK.
1869 declaration-specifiers:
1870 storage-class-specifier declaration-specifiers[opt]
1871 type-specifier declaration-specifiers[opt]
1872 type-qualifier declaration-specifiers[opt]
1873 function-specifier declaration-specifiers[opt]
1875 Function specifiers (inline) are from C99, and are currently
1876 handled as storage class specifiers, as is __thread.
1878 C90 6.5.1, C99 6.7.1:
1879 storage-class-specifier:
1890 C90 6.5.2, C99 6.7.2:
1903 [_Imaginary removed in C99 TC2]
1904 struct-or-union-specifier
1908 (_Bool and _Complex are new in C99.)
1910 C90 6.5.3, C99 6.7.3:
1916 address-space-qualifier
1918 (restrict is new in C99.)
1922 declaration-specifiers:
1923 attributes declaration-specifiers[opt]
1929 identifier recognized by the target
1931 storage-class-specifier:
1944 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1945 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1950 class-name objc-protocol-refs[opt]
1951 typedef-name objc-protocol-refs
1956 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1957 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1958 enum c_lookahead_kind la
)
1960 bool attrs_ok
= start_attr_ok
;
1961 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1964 gcc_assert (la
== cla_prefer_id
);
1966 while (c_parser_next_token_is (parser
, CPP_NAME
)
1967 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1968 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1970 struct c_typespec t
;
1972 location_t loc
= c_parser_peek_token (parser
)->location
;
1974 /* If we cannot accept a type, exit if the next token must start
1975 one. Also, if we already have seen a tagged definition,
1976 a typename would be an error anyway and likely the user
1977 has simply forgotten a semicolon, so we exit. */
1978 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
1979 && c_parser_next_tokens_start_typename (parser
, la
)
1980 && !c_parser_next_token_is_qualifier (parser
))
1983 if (c_parser_next_token_is (parser
, CPP_NAME
))
1985 tree value
= c_parser_peek_token (parser
)->value
;
1986 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1988 if (kind
== C_ID_ADDRSPACE
)
1991 = c_parser_peek_token (parser
)->keyword
- RID_FIRST_ADDR_SPACE
;
1992 declspecs_add_addrspace (specs
, as
);
1993 c_parser_consume_token (parser
);
1998 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2000 /* If we cannot accept a type, and the next token must start one,
2001 exit. Do the same if we already have seen a tagged definition,
2002 since it would be an error anyway and likely the user has simply
2003 forgotten a semicolon. */
2004 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2007 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2008 a C_ID_CLASSNAME. */
2009 c_parser_consume_token (parser
);
2012 if (kind
== C_ID_ID
)
2014 error ("unknown type name %qE", value
);
2015 t
.kind
= ctsk_typedef
;
2016 t
.spec
= error_mark_node
;
2018 else if (kind
== C_ID_TYPENAME
2019 && (!c_dialect_objc ()
2020 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2022 t
.kind
= ctsk_typedef
;
2023 /* For a typedef name, record the meaning, not the name.
2024 In case of 'foo foo, bar;'. */
2025 t
.spec
= lookup_name (value
);
2029 tree proto
= NULL_TREE
;
2030 gcc_assert (c_dialect_objc ());
2032 if (c_parser_next_token_is (parser
, CPP_LESS
))
2033 proto
= c_parser_objc_protocol_refs (parser
);
2034 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2037 t
.expr_const_operands
= true;
2038 declspecs_add_type (loc
, specs
, t
);
2041 if (c_parser_next_token_is (parser
, CPP_LESS
))
2043 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2044 nisse@lysator.liu.se. */
2046 gcc_assert (c_dialect_objc ());
2047 if (!typespec_ok
|| seen_type
)
2049 proto
= c_parser_objc_protocol_refs (parser
);
2051 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2053 t
.expr_const_operands
= true;
2054 declspecs_add_type (loc
, specs
, t
);
2057 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2058 switch (c_parser_peek_token (parser
)->keyword
)
2070 /* TODO: Distinguish between function specifiers (inline)
2071 and storage class specifiers, either here or in
2072 declspecs_add_scspec. */
2073 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
2074 c_parser_consume_token (parser
);
2098 if (c_dialect_objc ())
2099 parser
->objc_need_raw_identifier
= true;
2100 t
.kind
= ctsk_resword
;
2101 t
.spec
= c_parser_peek_token (parser
)->value
;
2103 t
.expr_const_operands
= true;
2104 declspecs_add_type (loc
, specs
, t
);
2105 c_parser_consume_token (parser
);
2112 t
= c_parser_enum_specifier (parser
);
2113 declspecs_add_type (loc
, specs
, t
);
2121 t
= c_parser_struct_or_union_specifier (parser
);
2122 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2123 declspecs_add_type (loc
, specs
, t
);
2126 /* ??? The old parser rejected typeof after other type
2127 specifiers, but is a syntax error the best way of
2129 if (!typespec_ok
|| seen_type
)
2133 t
= c_parser_typeof_specifier (parser
);
2134 declspecs_add_type (loc
, specs
, t
);
2140 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
2141 c_parser_consume_token (parser
);
2146 attrs
= c_parser_attributes (parser
);
2147 declspecs_add_attrs (specs
, attrs
);
2156 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2159 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2160 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2161 enum attributes[opt] identifier
2163 The form with trailing comma is new in C99. The forms with
2164 attributes are GNU extensions. In GNU C, we accept any expression
2165 without commas in the syntax (assignment expressions, not just
2166 conditional expressions); assignment expressions will be diagnosed
2171 enumerator-list , enumerator
2174 enumeration-constant
2175 enumeration-constant = constant-expression
2178 static struct c_typespec
2179 c_parser_enum_specifier (c_parser
*parser
)
2181 struct c_typespec ret
;
2183 tree ident
= NULL_TREE
;
2184 location_t enum_loc
;
2185 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2186 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2187 enum_loc
= c_parser_peek_token (parser
)->location
;
2188 c_parser_consume_token (parser
);
2189 attrs
= c_parser_attributes (parser
);
2190 enum_loc
= c_parser_peek_token (parser
)->location
;
2191 /* Set the location in case we create a decl now. */
2192 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2193 if (c_parser_next_token_is (parser
, CPP_NAME
))
2195 ident
= c_parser_peek_token (parser
)->value
;
2196 ident_loc
= c_parser_peek_token (parser
)->location
;
2197 enum_loc
= ident_loc
;
2198 c_parser_consume_token (parser
);
2200 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2202 /* Parse an enum definition. */
2203 struct c_enum_contents the_enum
;
2206 /* We chain the enumerators in reverse order, then put them in
2207 forward order at the end. */
2209 timevar_push (TV_PARSE_ENUM
);
2210 type
= start_enum (enum_loc
, &the_enum
, ident
);
2212 c_parser_consume_token (parser
);
2220 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2221 location_t decl_loc
, value_loc
;
2222 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2224 c_parser_error (parser
, "expected identifier");
2225 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2226 values
= error_mark_node
;
2229 token
= c_parser_peek_token (parser
);
2230 enum_id
= token
->value
;
2231 /* Set the location in case we create a decl now. */
2232 c_parser_set_source_position_from_token (token
);
2233 decl_loc
= value_loc
= token
->location
;
2234 c_parser_consume_token (parser
);
2235 if (c_parser_next_token_is (parser
, CPP_EQ
))
2237 c_parser_consume_token (parser
);
2238 value_loc
= c_parser_peek_token (parser
)->location
;
2239 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2242 enum_value
= NULL_TREE
;
2243 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2244 &the_enum
, enum_id
, enum_value
);
2245 TREE_CHAIN (enum_decl
) = values
;
2248 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2250 comma_loc
= c_parser_peek_token (parser
)->location
;
2252 c_parser_consume_token (parser
);
2254 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2256 if (seen_comma
&& !flag_isoc99
)
2257 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
2258 c_parser_consume_token (parser
);
2263 c_parser_error (parser
, "expected %<,%> or %<}%>");
2264 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2265 values
= error_mark_node
;
2269 postfix_attrs
= c_parser_attributes (parser
);
2270 ret
.spec
= finish_enum (type
, nreverse (values
),
2271 chainon (attrs
, postfix_attrs
));
2272 ret
.kind
= ctsk_tagdef
;
2273 ret
.expr
= NULL_TREE
;
2274 ret
.expr_const_operands
= true;
2275 timevar_pop (TV_PARSE_ENUM
);
2280 c_parser_error (parser
, "expected %<{%>");
2281 ret
.spec
= error_mark_node
;
2282 ret
.kind
= ctsk_tagref
;
2283 ret
.expr
= NULL_TREE
;
2284 ret
.expr_const_operands
= true;
2287 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2288 /* In ISO C, enumerated types can be referred to only if already
2290 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2293 pedwarn (enum_loc
, OPT_pedantic
,
2294 "ISO C forbids forward references to %<enum%> types");
2299 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2301 struct-or-union-specifier:
2302 struct-or-union attributes[opt] identifier[opt]
2303 { struct-contents } attributes[opt]
2304 struct-or-union attributes[opt] identifier
2307 struct-declaration-list
2309 struct-declaration-list:
2310 struct-declaration ;
2311 struct-declaration-list struct-declaration ;
2318 struct-declaration-list struct-declaration
2320 struct-declaration-list:
2321 struct-declaration-list ;
2324 (Note that in the syntax here, unlike that in ISO C, the semicolons
2325 are included here rather than in struct-declaration, in order to
2326 describe the syntax with extra semicolons and missing semicolon at
2331 struct-declaration-list:
2332 @defs ( class-name )
2334 (Note this does not include a trailing semicolon, but can be
2335 followed by further declarations, and gets a pedwarn-if-pedantic
2336 when followed by a semicolon.) */
2338 static struct c_typespec
2339 c_parser_struct_or_union_specifier (c_parser
*parser
)
2341 struct c_typespec ret
;
2343 tree ident
= NULL_TREE
;
2344 location_t struct_loc
;
2345 location_t ident_loc
= UNKNOWN_LOCATION
;
2346 enum tree_code code
;
2347 switch (c_parser_peek_token (parser
)->keyword
)
2358 struct_loc
= c_parser_peek_token (parser
)->location
;
2359 c_parser_consume_token (parser
);
2360 attrs
= c_parser_attributes (parser
);
2362 /* Set the location in case we create a decl now. */
2363 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2365 if (c_parser_next_token_is (parser
, CPP_NAME
))
2367 ident
= c_parser_peek_token (parser
)->value
;
2368 ident_loc
= c_parser_peek_token (parser
)->location
;
2369 struct_loc
= ident_loc
;
2370 c_parser_consume_token (parser
);
2372 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2374 /* Parse a struct or union definition. Start the scope of the
2375 tag before parsing components. */
2376 struct c_struct_parse_info
*struct_info
;
2377 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2379 /* We chain the components in reverse order, then put them in
2380 forward order at the end. Each struct-declaration may
2381 declare multiple components (comma-separated), so we must use
2382 chainon to join them, although when parsing each
2383 struct-declaration we can use TREE_CHAIN directly.
2385 The theory behind all this is that there will be more
2386 semicolon separated fields than comma separated fields, and
2387 so we'll be minimizing the number of node traversals required
2390 timevar_push (TV_PARSE_STRUCT
);
2391 contents
= NULL_TREE
;
2392 c_parser_consume_token (parser
);
2393 /* Handle the Objective-C @defs construct,
2394 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2395 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2398 gcc_assert (c_dialect_objc ());
2399 c_parser_consume_token (parser
);
2400 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2402 if (c_parser_next_token_is (parser
, CPP_NAME
)
2403 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2405 name
= c_parser_peek_token (parser
)->value
;
2406 c_parser_consume_token (parser
);
2410 c_parser_error (parser
, "expected class name");
2411 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2414 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2416 contents
= nreverse (objc_get_class_ivars (name
));
2419 /* Parse the struct-declarations and semicolons. Problems with
2420 semicolons are diagnosed here; empty structures are diagnosed
2425 /* Parse any stray semicolon. */
2426 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2428 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
2429 "extra semicolon in struct or union specified");
2430 c_parser_consume_token (parser
);
2433 /* Stop if at the end of the struct or union contents. */
2434 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2436 c_parser_consume_token (parser
);
2439 /* Accept #pragmas at struct scope. */
2440 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2442 c_parser_pragma (parser
, pragma_external
);
2445 /* Parse some comma-separated declarations, but not the
2446 trailing semicolon if any. */
2447 decls
= c_parser_struct_declaration (parser
);
2448 contents
= chainon (decls
, contents
);
2449 /* If no semicolon follows, either we have a parse error or
2450 are at the end of the struct or union and should
2452 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2453 c_parser_consume_token (parser
);
2456 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2457 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2458 "no semicolon at end of struct or union");
2459 else if (parser
->error
2460 || !c_parser_next_token_starts_declspecs (parser
))
2462 c_parser_error (parser
, "expected %<;%>");
2463 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2467 /* If we come here, we have already emitted an error
2468 for an expected `;', identifier or `(', and we also
2469 recovered already. Go on with the next field. */
2472 postfix_attrs
= c_parser_attributes (parser
);
2473 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2474 chainon (attrs
, postfix_attrs
), struct_info
);
2475 ret
.kind
= ctsk_tagdef
;
2476 ret
.expr
= NULL_TREE
;
2477 ret
.expr_const_operands
= true;
2478 timevar_pop (TV_PARSE_STRUCT
);
2483 c_parser_error (parser
, "expected %<{%>");
2484 ret
.spec
= error_mark_node
;
2485 ret
.kind
= ctsk_tagref
;
2486 ret
.expr
= NULL_TREE
;
2487 ret
.expr_const_operands
= true;
2490 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2494 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2495 the trailing semicolon.
2498 specifier-qualifier-list struct-declarator-list
2499 static_assert-declaration-no-semi
2501 specifier-qualifier-list:
2502 type-specifier specifier-qualifier-list[opt]
2503 type-qualifier specifier-qualifier-list[opt]
2504 attributes specifier-qualifier-list[opt]
2506 struct-declarator-list:
2508 struct-declarator-list , attributes[opt] struct-declarator
2511 declarator attributes[opt]
2512 declarator[opt] : constant-expression attributes[opt]
2517 __extension__ struct-declaration
2518 specifier-qualifier-list
2520 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2521 of attributes where shown is a GNU extension. In GNU C, we accept
2522 any expression without commas in the syntax (assignment
2523 expressions, not just conditional expressions); assignment
2524 expressions will be diagnosed as non-constant. */
2527 c_parser_struct_declaration (c_parser
*parser
)
2529 struct c_declspecs
*specs
;
2531 tree all_prefix_attrs
;
2533 location_t decl_loc
;
2534 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2538 ext
= disable_extension_diagnostics ();
2539 c_parser_consume_token (parser
);
2540 decl
= c_parser_struct_declaration (parser
);
2541 restore_extension_diagnostics (ext
);
2544 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2546 c_parser_static_assert_declaration_no_semi (parser
);
2549 specs
= build_null_declspecs ();
2550 decl_loc
= c_parser_peek_token (parser
)->location
;
2551 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2554 if (!specs
->declspecs_seen_p
)
2556 c_parser_error (parser
, "expected specifier-qualifier-list");
2559 finish_declspecs (specs
);
2560 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2561 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2564 if (specs
->typespec_kind
== ctsk_none
)
2566 pedwarn (decl_loc
, OPT_pedantic
,
2567 "ISO C forbids member declarations with no members");
2568 shadow_tag_warned (specs
, pedantic
);
2573 /* Support for unnamed structs or unions as members of
2574 structs or unions (which is [a] useful and [b] supports
2578 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2579 build_id_declarator (NULL_TREE
), specs
,
2582 decl_attributes (&ret
, attrs
, 0);
2587 /* Provide better error recovery. Note that a type name here is valid,
2588 and will be treated as a field name. */
2589 if (specs
->typespec_kind
== ctsk_tagdef
2590 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2591 && c_parser_next_token_starts_declspecs (parser
)
2592 && !c_parser_next_token_is (parser
, CPP_NAME
))
2594 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2595 parser
->error
= false;
2599 pending_xref_error ();
2600 prefix_attrs
= specs
->attrs
;
2601 all_prefix_attrs
= prefix_attrs
;
2602 specs
->attrs
= NULL_TREE
;
2606 /* Declaring one or more declarators or un-named bit-fields. */
2607 struct c_declarator
*declarator
;
2609 if (c_parser_next_token_is (parser
, CPP_COLON
))
2610 declarator
= build_id_declarator (NULL_TREE
);
2612 declarator
= c_parser_declarator (parser
,
2613 specs
->typespec_kind
!= ctsk_none
,
2614 C_DTR_NORMAL
, &dummy
);
2615 if (declarator
== NULL
)
2617 c_parser_skip_to_end_of_block_or_statement (parser
);
2620 if (c_parser_next_token_is (parser
, CPP_COLON
)
2621 || c_parser_next_token_is (parser
, CPP_COMMA
)
2622 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2623 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2624 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2626 tree postfix_attrs
= NULL_TREE
;
2627 tree width
= NULL_TREE
;
2629 if (c_parser_next_token_is (parser
, CPP_COLON
))
2631 c_parser_consume_token (parser
);
2632 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2634 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2635 postfix_attrs
= c_parser_attributes (parser
);
2636 d
= grokfield (c_parser_peek_token (parser
)->location
,
2637 declarator
, specs
, width
, &all_prefix_attrs
);
2638 decl_attributes (&d
, chainon (postfix_attrs
,
2639 all_prefix_attrs
), 0);
2640 DECL_CHAIN (d
) = decls
;
2642 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2643 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2646 all_prefix_attrs
= prefix_attrs
;
2647 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2648 c_parser_consume_token (parser
);
2649 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2650 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2652 /* Semicolon consumed in caller. */
2657 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2663 c_parser_error (parser
,
2664 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2665 "%<__attribute__%>");
2672 /* Parse a typeof specifier (a GNU extension).
2675 typeof ( expression )
2676 typeof ( type-name )
2679 static struct c_typespec
2680 c_parser_typeof_specifier (c_parser
*parser
)
2682 struct c_typespec ret
;
2683 ret
.kind
= ctsk_typeof
;
2684 ret
.spec
= error_mark_node
;
2685 ret
.expr
= NULL_TREE
;
2686 ret
.expr_const_operands
= true;
2687 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2688 c_parser_consume_token (parser
);
2689 c_inhibit_evaluation_warnings
++;
2691 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2693 c_inhibit_evaluation_warnings
--;
2697 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2699 struct c_type_name
*type
= c_parser_type_name (parser
);
2700 c_inhibit_evaluation_warnings
--;
2704 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2705 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2711 location_t here
= c_parser_peek_token (parser
)->location
;
2712 struct c_expr expr
= c_parser_expression (parser
);
2713 c_inhibit_evaluation_warnings
--;
2715 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2716 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2717 error_at (here
, "%<typeof%> applied to a bit-field");
2718 mark_exp_read (expr
.value
);
2719 ret
.spec
= TREE_TYPE (expr
.value
);
2720 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2721 /* This is returned with the type so that when the type is
2722 evaluated, this can be evaluated. */
2724 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2725 pop_maybe_used (was_vm
);
2727 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2731 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2732 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2733 be redeclared; otherwise it may not. KIND indicates which kind of
2734 declarator is wanted. Returns a valid declarator except in the
2735 case of a syntax error in which case NULL is returned. *SEEN_ID is
2736 set to true if an identifier being declared is seen; this is used
2737 to diagnose bad forms of abstract array declarators and to
2738 determine whether an identifier list is syntactically permitted.
2741 pointer[opt] direct-declarator
2745 ( attributes[opt] declarator )
2746 direct-declarator array-declarator
2747 direct-declarator ( parameter-type-list )
2748 direct-declarator ( identifier-list[opt] )
2751 * type-qualifier-list[opt]
2752 * type-qualifier-list[opt] pointer
2754 type-qualifier-list:
2757 type-qualifier-list type-qualifier
2758 type-qualifier-list attributes
2760 parameter-type-list:
2762 parameter-list , ...
2765 parameter-declaration
2766 parameter-list , parameter-declaration
2768 parameter-declaration:
2769 declaration-specifiers declarator attributes[opt]
2770 declaration-specifiers abstract-declarator[opt] attributes[opt]
2774 identifier-list , identifier
2776 abstract-declarator:
2778 pointer[opt] direct-abstract-declarator
2780 direct-abstract-declarator:
2781 ( attributes[opt] abstract-declarator )
2782 direct-abstract-declarator[opt] array-declarator
2783 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2788 direct-declarator ( parameter-forward-declarations
2789 parameter-type-list[opt] )
2791 direct-abstract-declarator:
2792 direct-abstract-declarator[opt] ( parameter-forward-declarations
2793 parameter-type-list[opt] )
2795 parameter-forward-declarations:
2797 parameter-forward-declarations parameter-list ;
2799 The uses of attributes shown above are GNU extensions.
2801 Some forms of array declarator are not included in C99 in the
2802 syntax for abstract declarators; these are disallowed elsewhere.
2803 This may be a defect (DR#289).
2805 This function also accepts an omitted abstract declarator as being
2806 an abstract declarator, although not part of the formal syntax. */
2808 static struct c_declarator
*
2809 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2812 /* Parse any initial pointer part. */
2813 if (c_parser_next_token_is (parser
, CPP_MULT
))
2815 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2816 struct c_declarator
*inner
;
2817 c_parser_consume_token (parser
);
2818 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2819 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2823 return make_pointer_declarator (quals_attrs
, inner
);
2825 /* Now we have a direct declarator, direct abstract declarator or
2826 nothing (which counts as a direct abstract declarator here). */
2827 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2830 /* Parse a direct declarator or direct abstract declarator; arguments
2831 as c_parser_declarator. */
2833 static struct c_declarator
*
2834 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2837 /* The direct declarator must start with an identifier (possibly
2838 omitted) or a parenthesized declarator (possibly abstract). In
2839 an ordinary declarator, initial parentheses must start a
2840 parenthesized declarator. In an abstract declarator or parameter
2841 declarator, they could start a parenthesized declarator or a
2842 parameter list. To tell which, the open parenthesis and any
2843 following attributes must be read. If a declaration specifier
2844 follows, then it is a parameter list; if the specifier is a
2845 typedef name, there might be an ambiguity about redeclaring it,
2846 which is resolved in the direction of treating it as a typedef
2847 name. If a close parenthesis follows, it is also an empty
2848 parameter list, as the syntax does not permit empty abstract
2849 declarators. Otherwise, it is a parenthesized declarator (in
2850 which case the analysis may be repeated inside it, recursively).
2852 ??? There is an ambiguity in a parameter declaration "int
2853 (__attribute__((foo)) x)", where x is not a typedef name: it
2854 could be an abstract declarator for a function, or declare x with
2855 parentheses. The proper resolution of this ambiguity needs
2856 documenting. At present we follow an accident of the old
2857 parser's implementation, whereby the first parameter must have
2858 some declaration specifiers other than just attributes. Thus as
2859 a parameter declaration it is treated as a parenthesized
2860 parameter named x, and as an abstract declarator it is
2863 ??? Also following the old parser, attributes inside an empty
2864 parameter list are ignored, making it a list not yielding a
2865 prototype, rather than giving an error or making it have one
2866 parameter with implicit type int.
2868 ??? Also following the old parser, typedef names may be
2869 redeclared in declarators, but not Objective-C class names. */
2871 if (kind
!= C_DTR_ABSTRACT
2872 && c_parser_next_token_is (parser
, CPP_NAME
)
2874 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2875 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2876 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2878 struct c_declarator
*inner
2879 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2881 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2882 c_parser_consume_token (parser
);
2883 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2886 if (kind
!= C_DTR_NORMAL
2887 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2889 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2890 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2893 /* Either we are at the end of an abstract declarator, or we have
2896 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2899 struct c_declarator
*inner
;
2900 c_parser_consume_token (parser
);
2901 attrs
= c_parser_attributes (parser
);
2902 if (kind
!= C_DTR_NORMAL
2903 && (c_parser_next_token_starts_declspecs (parser
)
2904 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2906 struct c_arg_info
*args
2907 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2914 = build_function_declarator (args
,
2915 build_id_declarator (NULL_TREE
));
2916 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2920 /* A parenthesized declarator. */
2921 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2922 if (inner
!= NULL
&& attrs
!= NULL
)
2923 inner
= build_attrs_declarator (attrs
, inner
);
2924 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2926 c_parser_consume_token (parser
);
2930 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2941 if (kind
== C_DTR_NORMAL
)
2943 c_parser_error (parser
, "expected identifier or %<(%>");
2947 return build_id_declarator (NULL_TREE
);
2951 /* Parse part of a direct declarator or direct abstract declarator,
2952 given that some (in INNER) has already been parsed; ID_PRESENT is
2953 true if an identifier is present, false for an abstract
2956 static struct c_declarator
*
2957 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2958 struct c_declarator
*inner
)
2960 /* Parse a sequence of array declarators and parameter lists. */
2961 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2963 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2964 struct c_declarator
*declarator
;
2965 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2969 c_parser_consume_token (parser
);
2970 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2971 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2973 c_parser_consume_token (parser
);
2974 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2975 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2976 if (!quals_attrs
->declspecs_seen_p
)
2978 /* If "static" is present, there must be an array dimension.
2979 Otherwise, there may be a dimension, "*", or no
2984 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2988 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2993 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2995 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2999 c_parser_consume_token (parser
);
3004 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3010 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3013 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3014 c_parser_consume_token (parser
);
3017 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3022 mark_exp_read (dimen
);
3023 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3024 static_seen
, star_seen
);
3025 if (declarator
== NULL
)
3027 inner
= set_array_declarator_inner (declarator
, inner
);
3028 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3030 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3033 struct c_arg_info
*args
;
3034 c_parser_consume_token (parser
);
3035 attrs
= c_parser_attributes (parser
);
3036 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3041 inner
= build_function_declarator (args
, inner
);
3042 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3048 /* Parse a parameter list or identifier list, including the closing
3049 parenthesis but not the opening one. ATTRS are the attributes at
3050 the start of the list. ID_LIST_OK is true if an identifier list is
3051 acceptable; such a list must not have attributes at the start. */
3053 static struct c_arg_info
*
3054 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3057 declare_parm_level ();
3058 /* If the list starts with an identifier, it is an identifier list.
3059 Otherwise, it is either a prototype list or an empty list. */
3062 && c_parser_next_token_is (parser
, CPP_NAME
)
3063 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3065 /* Look ahead to detect typos in type names. */
3066 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3067 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3068 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3069 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3071 tree list
= NULL_TREE
, *nextp
= &list
;
3072 while (c_parser_next_token_is (parser
, CPP_NAME
)
3073 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3075 *nextp
= build_tree_list (NULL_TREE
,
3076 c_parser_peek_token (parser
)->value
);
3077 nextp
= & TREE_CHAIN (*nextp
);
3078 c_parser_consume_token (parser
);
3079 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3081 c_parser_consume_token (parser
);
3082 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3084 c_parser_error (parser
, "expected identifier");
3088 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3090 struct c_arg_info
*ret
= build_arg_info ();
3092 c_parser_consume_token (parser
);
3098 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3106 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3113 /* Parse a parameter list (possibly empty), including the closing
3114 parenthesis but not the opening one. ATTRS are the attributes at
3115 the start of the list. EXPR is NULL or an expression that needs to
3116 be evaluated for the side effects of array size expressions in the
3119 static struct c_arg_info
*
3120 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3122 bool bad_parm
= false;
3124 /* ??? Following the old parser, forward parameter declarations may
3125 use abstract declarators, and if no real parameter declarations
3126 follow the forward declarations then this is not diagnosed. Also
3127 note as above that attributes are ignored as the only contents of
3128 the parentheses, or as the only contents after forward
3130 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3132 struct c_arg_info
*ret
= build_arg_info ();
3133 c_parser_consume_token (parser
);
3136 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3138 struct c_arg_info
*ret
= build_arg_info ();
3139 /* Suppress -Wold-style-definition for this case. */
3140 ret
->types
= error_mark_node
;
3141 error_at (c_parser_peek_token (parser
)->location
,
3142 "ISO C requires a named argument before %<...%>");
3143 c_parser_consume_token (parser
);
3144 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3146 c_parser_consume_token (parser
);
3151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3156 /* Nonempty list of parameters, either terminated with semicolon
3157 (forward declarations; recurse) or with close parenthesis (normal
3158 function) or with ", ... )" (variadic function). */
3161 /* Parse a parameter. */
3162 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3167 push_parm_decl (parm
, &expr
);
3168 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3171 c_parser_consume_token (parser
);
3172 mark_forward_parm_decls ();
3173 new_attrs
= c_parser_attributes (parser
);
3174 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3176 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3178 c_parser_consume_token (parser
);
3182 return get_parm_info (false, expr
);
3184 if (!c_parser_require (parser
, CPP_COMMA
,
3185 "expected %<;%>, %<,%> or %<)%>"))
3187 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3190 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3192 c_parser_consume_token (parser
);
3193 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3195 c_parser_consume_token (parser
);
3199 return get_parm_info (true, expr
);
3203 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3211 /* Parse a parameter declaration. ATTRS are the attributes at the
3212 start of the declaration if it is the first parameter. */
3214 static struct c_parm
*
3215 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3217 struct c_declspecs
*specs
;
3218 struct c_declarator
*declarator
;
3220 tree postfix_attrs
= NULL_TREE
;
3222 if (!c_parser_next_token_starts_declspecs (parser
))
3224 c_token
*token
= c_parser_peek_token (parser
);
3227 c_parser_set_source_position_from_token (token
);
3228 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3230 error ("unknown type name %qE", token
->value
);
3231 parser
->error
= true;
3233 /* ??? In some Objective-C cases '...' isn't applicable so there
3234 should be a different message. */
3236 c_parser_error (parser
,
3237 "expected declaration specifiers or %<...%>");
3238 c_parser_skip_to_end_of_parameter (parser
);
3241 specs
= build_null_declspecs ();
3244 declspecs_add_attrs (specs
, attrs
);
3247 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3248 finish_declspecs (specs
);
3249 pending_xref_error ();
3250 prefix_attrs
= specs
->attrs
;
3251 specs
->attrs
= NULL_TREE
;
3252 declarator
= c_parser_declarator (parser
,
3253 specs
->typespec_kind
!= ctsk_none
,
3254 C_DTR_PARM
, &dummy
);
3255 if (declarator
== NULL
)
3257 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3260 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3261 postfix_attrs
= c_parser_attributes (parser
);
3262 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3266 /* Parse a string literal in an asm expression. It should not be
3267 translated, and wide string literals are an error although
3268 permitted by the syntax. This is a GNU extension.
3273 ??? At present, following the old parser, the caller needs to have
3274 set lex_untranslated_string to 1. It would be better to follow the
3275 C++ parser rather than using this kludge. */
3278 c_parser_asm_string_literal (c_parser
*parser
)
3281 int save_flag
= warn_overlength_strings
;
3282 warn_overlength_strings
= 0;
3283 if (c_parser_next_token_is (parser
, CPP_STRING
))
3285 str
= c_parser_peek_token (parser
)->value
;
3286 c_parser_consume_token (parser
);
3288 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3290 error_at (c_parser_peek_token (parser
)->location
,
3291 "wide string literal in %<asm%>");
3292 str
= build_string (1, "");
3293 c_parser_consume_token (parser
);
3297 c_parser_error (parser
, "expected string literal");
3300 warn_overlength_strings
= save_flag
;
3304 /* Parse a simple asm expression. This is used in restricted
3305 contexts, where a full expression with inputs and outputs does not
3306 make sense. This is a GNU extension.
3309 asm ( asm-string-literal )
3313 c_parser_simple_asm_expr (c_parser
*parser
)
3316 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3317 /* ??? Follow the C++ parser rather than using the
3318 lex_untranslated_string kludge. */
3319 parser
->lex_untranslated_string
= true;
3320 c_parser_consume_token (parser
);
3321 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3323 parser
->lex_untranslated_string
= false;
3326 str
= c_parser_asm_string_literal (parser
);
3327 parser
->lex_untranslated_string
= false;
3328 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3330 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3336 /* Parse (possibly empty) attributes. This is a GNU extension.
3340 attributes attribute
3343 __attribute__ ( ( attribute-list ) )
3347 attribute_list , attrib
3352 any-word ( identifier )
3353 any-word ( identifier , nonempty-expr-list )
3354 any-word ( expr-list )
3356 where the "identifier" must not be declared as a type, and
3357 "any-word" may be any identifier (including one declared as a
3358 type), a reserved word storage class specifier, type specifier or
3359 type qualifier. ??? This still leaves out most reserved keywords
3360 (following the old parser), shouldn't we include them, and why not
3361 allow identifiers declared as types to start the arguments? */
3364 c_parser_attributes (c_parser
*parser
)
3366 tree attrs
= NULL_TREE
;
3367 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3369 /* ??? Follow the C++ parser rather than using the
3370 lex_untranslated_string kludge. */
3371 parser
->lex_untranslated_string
= true;
3372 c_parser_consume_token (parser
);
3373 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3375 parser
->lex_untranslated_string
= false;
3378 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3380 parser
->lex_untranslated_string
= false;
3381 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3384 /* Parse the attribute list. */
3385 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3386 || c_parser_next_token_is (parser
, CPP_NAME
)
3387 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3389 tree attr
, attr_name
, attr_args
;
3390 VEC(tree
,gc
) *expr_list
;
3391 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3393 c_parser_consume_token (parser
);
3396 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3398 /* ??? See comment above about what keywords are
3401 switch (c_parser_peek_token (parser
)->keyword
)
3439 /* Accept __attribute__((__const)) as __attribute__((const))
3442 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3445 attr_name
= c_parser_peek_token (parser
)->value
;
3446 c_parser_consume_token (parser
);
3447 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3449 attr
= build_tree_list (attr_name
, NULL_TREE
);
3450 attrs
= chainon (attrs
, attr
);
3453 c_parser_consume_token (parser
);
3454 /* Parse the attribute contents. If they start with an
3455 identifier which is followed by a comma or close
3456 parenthesis, then the arguments start with that
3457 identifier; otherwise they are an expression list.
3458 In objective-c the identifier may be a classname. */
3459 if (c_parser_next_token_is (parser
, CPP_NAME
)
3460 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3461 || (c_dialect_objc ()
3462 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3463 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3464 || (c_parser_peek_2nd_token (parser
)->type
3465 == CPP_CLOSE_PAREN
)))
3467 tree arg1
= c_parser_peek_token (parser
)->value
;
3468 c_parser_consume_token (parser
);
3469 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3470 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3474 c_parser_consume_token (parser
);
3475 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3476 tree_list
= build_tree_list_vec (expr_list
);
3477 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3478 release_tree_vector (expr_list
);
3483 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3484 attr_args
= NULL_TREE
;
3487 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3488 attr_args
= build_tree_list_vec (expr_list
);
3489 release_tree_vector (expr_list
);
3492 attr
= build_tree_list (attr_name
, attr_args
);
3493 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3494 c_parser_consume_token (parser
);
3497 parser
->lex_untranslated_string
= false;
3498 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3502 attrs
= chainon (attrs
, attr
);
3504 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3505 c_parser_consume_token (parser
);
3508 parser
->lex_untranslated_string
= false;
3509 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3513 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3514 c_parser_consume_token (parser
);
3517 parser
->lex_untranslated_string
= false;
3518 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3522 parser
->lex_untranslated_string
= false;
3527 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3530 specifier-qualifier-list abstract-declarator[opt]
3533 static struct c_type_name
*
3534 c_parser_type_name (c_parser
*parser
)
3536 struct c_declspecs
*specs
= build_null_declspecs ();
3537 struct c_declarator
*declarator
;
3538 struct c_type_name
*ret
;
3540 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3541 if (!specs
->declspecs_seen_p
)
3543 c_parser_error (parser
, "expected specifier-qualifier-list");
3546 if (specs
->type
!= error_mark_node
)
3548 pending_xref_error ();
3549 finish_declspecs (specs
);
3551 declarator
= c_parser_declarator (parser
,
3552 specs
->typespec_kind
!= ctsk_none
,
3553 C_DTR_ABSTRACT
, &dummy
);
3554 if (declarator
== NULL
)
3556 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3558 ret
->declarator
= declarator
;
3562 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3565 assignment-expression
3566 { initializer-list }
3567 { initializer-list , }
3570 designation[opt] initializer
3571 initializer-list , designation[opt] initializer
3578 designator-list designator
3585 [ constant-expression ]
3597 [ constant-expression ... constant-expression ]
3599 Any expression without commas is accepted in the syntax for the
3600 constant-expressions, with non-constant expressions rejected later.
3602 This function is only used for top-level initializers; for nested
3603 ones, see c_parser_initval. */
3605 static struct c_expr
3606 c_parser_initializer (c_parser
*parser
)
3608 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3609 return c_parser_braced_init (parser
, NULL_TREE
, false);
3613 location_t loc
= c_parser_peek_token (parser
)->location
;
3614 ret
= c_parser_expr_no_commas (parser
, NULL
);
3615 if (TREE_CODE (ret
.value
) != STRING_CST
3616 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3617 ret
= default_function_array_read_conversion (loc
, ret
);
3622 /* Parse a braced initializer list. TYPE is the type specified for a
3623 compound literal, and NULL_TREE for other initializers and for
3624 nested braced lists. NESTED_P is true for nested braced lists,
3625 false for the list of a compound literal or the list that is the
3626 top-level initializer in a declaration. */
3628 static struct c_expr
3629 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3632 struct obstack braced_init_obstack
;
3633 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3634 gcc_obstack_init (&braced_init_obstack
);
3635 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3636 c_parser_consume_token (parser
);
3638 push_init_level (0, &braced_init_obstack
);
3640 really_start_incremental_init (type
);
3641 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3643 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3647 /* Parse a non-empty initializer list, possibly with a trailing
3651 c_parser_initelt (parser
, &braced_init_obstack
);
3654 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3655 c_parser_consume_token (parser
);
3658 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3662 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3664 ret
.value
= error_mark_node
;
3665 ret
.original_code
= ERROR_MARK
;
3666 ret
.original_type
= NULL
;
3667 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3668 pop_init_level (0, &braced_init_obstack
);
3669 obstack_free (&braced_init_obstack
, NULL
);
3672 c_parser_consume_token (parser
);
3673 ret
= pop_init_level (0, &braced_init_obstack
);
3674 obstack_free (&braced_init_obstack
, NULL
);
3678 /* Parse a nested initializer, including designators. */
3681 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3683 /* Parse any designator or designator list. A single array
3684 designator may have the subsequent "=" omitted in GNU C, but a
3685 longer list or a structure member designator may not. */
3686 if (c_parser_next_token_is (parser
, CPP_NAME
)
3687 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3689 /* Old-style structure member designator. */
3690 set_init_label (c_parser_peek_token (parser
)->value
,
3691 braced_init_obstack
);
3692 /* Use the colon as the error location. */
3693 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3694 "obsolete use of designated initializer with %<:%>");
3695 c_parser_consume_token (parser
);
3696 c_parser_consume_token (parser
);
3700 /* des_seen is 0 if there have been no designators, 1 if there
3701 has been a single array designator and 2 otherwise. */
3703 /* Location of a designator. */
3704 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3705 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3706 || c_parser_next_token_is (parser
, CPP_DOT
))
3708 int des_prev
= des_seen
;
3710 des_loc
= c_parser_peek_token (parser
)->location
;
3713 if (c_parser_next_token_is (parser
, CPP_DOT
))
3716 c_parser_consume_token (parser
);
3717 if (c_parser_next_token_is (parser
, CPP_NAME
))
3719 set_init_label (c_parser_peek_token (parser
)->value
,
3720 braced_init_obstack
);
3721 c_parser_consume_token (parser
);
3726 init
.value
= error_mark_node
;
3727 init
.original_code
= ERROR_MARK
;
3728 init
.original_type
= NULL
;
3729 c_parser_error (parser
, "expected identifier");
3730 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3731 process_init_element (init
, false, braced_init_obstack
);
3738 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3739 /* ??? Following the old parser, [ objc-receiver
3740 objc-message-args ] is accepted as an initializer,
3741 being distinguished from a designator by what follows
3742 the first assignment expression inside the square
3743 brackets, but after a first array designator a
3744 subsequent square bracket is for Objective-C taken to
3745 start an expression, using the obsolete form of
3746 designated initializer without '=', rather than
3747 possibly being a second level of designation: in LALR
3748 terms, the '[' is shifted rather than reducing
3749 designator to designator-list. */
3750 if (des_prev
== 1 && c_dialect_objc ())
3752 des_seen
= des_prev
;
3755 if (des_prev
== 0 && c_dialect_objc ())
3757 /* This might be an array designator or an
3758 Objective-C message expression. If the former,
3759 continue parsing here; if the latter, parse the
3760 remainder of the initializer given the starting
3761 primary-expression. ??? It might make sense to
3762 distinguish when des_prev == 1 as well; see
3763 previous comment. */
3765 struct c_expr mexpr
;
3766 c_parser_consume_token (parser
);
3767 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3768 && ((c_parser_peek_token (parser
)->id_kind
3770 || (c_parser_peek_token (parser
)->id_kind
3771 == C_ID_CLASSNAME
)))
3773 /* Type name receiver. */
3774 tree id
= c_parser_peek_token (parser
)->value
;
3775 c_parser_consume_token (parser
);
3776 rec
= objc_get_class_reference (id
);
3777 goto parse_message_args
;
3779 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3780 mark_exp_read (first
);
3781 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3782 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3783 goto array_desig_after_first
;
3784 /* Expression receiver. So far only one part
3785 without commas has been parsed; there might be
3786 more of the expression. */
3788 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3791 location_t comma_loc
, exp_loc
;
3792 comma_loc
= c_parser_peek_token (parser
)->location
;
3793 c_parser_consume_token (parser
);
3794 exp_loc
= c_parser_peek_token (parser
)->location
;
3795 next
= c_parser_expr_no_commas (parser
, NULL
);
3796 next
= default_function_array_read_conversion (exp_loc
,
3798 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3801 /* Now parse the objc-message-args. */
3802 args
= c_parser_objc_message_args (parser
);
3803 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3806 = objc_build_message_expr (rec
, args
);
3807 mexpr
.original_code
= ERROR_MARK
;
3808 mexpr
.original_type
= NULL
;
3809 /* Now parse and process the remainder of the
3810 initializer, starting with this message
3811 expression as a primary-expression. */
3812 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3815 c_parser_consume_token (parser
);
3816 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3817 mark_exp_read (first
);
3818 array_desig_after_first
:
3819 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3821 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3822 c_parser_consume_token (parser
);
3823 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3824 mark_exp_read (second
);
3828 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3830 c_parser_consume_token (parser
);
3831 set_init_index (first
, second
, braced_init_obstack
);
3833 pedwarn (ellipsis_loc
, OPT_pedantic
,
3834 "ISO C forbids specifying range of elements to initialize");
3837 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3843 if (c_parser_next_token_is (parser
, CPP_EQ
))
3846 pedwarn (des_loc
, OPT_pedantic
,
3847 "ISO C90 forbids specifying subobject to initialize");
3848 c_parser_consume_token (parser
);
3853 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3854 "obsolete use of designated initializer without %<=%>");
3858 init
.value
= error_mark_node
;
3859 init
.original_code
= ERROR_MARK
;
3860 init
.original_type
= NULL
;
3861 c_parser_error (parser
, "expected %<=%>");
3862 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3863 process_init_element (init
, false, braced_init_obstack
);
3869 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3872 /* Parse a nested initializer; as c_parser_initializer but parses
3873 initializers within braced lists, after any designators have been
3874 applied. If AFTER is not NULL then it is an Objective-C message
3875 expression which is the primary-expression starting the
3879 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
3880 struct obstack
* braced_init_obstack
)
3883 gcc_assert (!after
|| c_dialect_objc ());
3884 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3885 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3888 location_t loc
= c_parser_peek_token (parser
)->location
;
3889 init
= c_parser_expr_no_commas (parser
, after
);
3890 if (init
.value
!= NULL_TREE
3891 && TREE_CODE (init
.value
) != STRING_CST
3892 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3893 init
= default_function_array_read_conversion (loc
, init
);
3895 process_init_element (init
, false, braced_init_obstack
);
3898 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3902 { block-item-list[opt] }
3903 { label-declarations block-item-list }
3907 block-item-list block-item
3919 { label-declarations block-item-list }
3922 __extension__ nested-declaration
3923 nested-function-definition
3927 label-declarations label-declaration
3930 __label__ identifier-list ;
3932 Allowing the mixing of declarations and code is new in C99. The
3933 GNU syntax also permits (not shown above) labels at the end of
3934 compound statements, which yield an error. We don't allow labels
3935 on declarations; this might seem like a natural extension, but
3936 there would be a conflict between attributes on the label and
3937 prefix attributes on the declaration. ??? The syntax follows the
3938 old parser in requiring something after label declarations.
3939 Although they are erroneous if the labels declared aren't defined,
3940 is it useful for the syntax to be this way?
3952 c_parser_compound_statement (c_parser
*parser
)
3955 location_t brace_loc
;
3956 brace_loc
= c_parser_peek_token (parser
)->location
;
3957 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3959 /* Ensure a scope is entered and left anyway to avoid confusion
3960 if we have just prepared to enter a function body. */
3961 stmt
= c_begin_compound_stmt (true);
3962 c_end_compound_stmt (brace_loc
, stmt
, true);
3963 return error_mark_node
;
3965 stmt
= c_begin_compound_stmt (true);
3966 c_parser_compound_statement_nostart (parser
);
3967 return c_end_compound_stmt (brace_loc
, stmt
, true);
3970 /* Parse a compound statement except for the opening brace. This is
3971 used for parsing both compound statements and statement expressions
3972 (which follow different paths to handling the opening). */
3975 c_parser_compound_statement_nostart (c_parser
*parser
)
3977 bool last_stmt
= false;
3978 bool last_label
= false;
3979 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3980 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3981 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3983 c_parser_consume_token (parser
);
3986 mark_valid_location_for_stdc_pragma (true);
3987 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3989 /* Read zero or more forward-declarations for labels that nested
3990 functions can jump to. */
3991 mark_valid_location_for_stdc_pragma (false);
3992 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3994 label_loc
= c_parser_peek_token (parser
)->location
;
3995 c_parser_consume_token (parser
);
3996 /* Any identifiers, including those declared as type names,
4001 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4003 c_parser_error (parser
, "expected identifier");
4007 = declare_label (c_parser_peek_token (parser
)->value
);
4008 C_DECLARED_LABEL_FLAG (label
) = 1;
4009 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4010 c_parser_consume_token (parser
);
4011 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4012 c_parser_consume_token (parser
);
4016 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4018 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
4020 /* We must now have at least one statement, label or declaration. */
4021 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4023 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4024 c_parser_error (parser
, "expected declaration or statement");
4025 c_parser_consume_token (parser
);
4028 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4030 location_t loc
= c_parser_peek_token (parser
)->location
;
4031 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4032 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4033 || (c_parser_next_token_is (parser
, CPP_NAME
)
4034 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4036 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4037 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4039 label_loc
= c_parser_peek_token (parser
)->location
;
4042 mark_valid_location_for_stdc_pragma (false);
4043 c_parser_label (parser
);
4045 else if (!last_label
4046 && c_parser_next_tokens_start_declaration (parser
))
4049 mark_valid_location_for_stdc_pragma (false);
4050 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4053 (pedantic
&& !flag_isoc99
)
4055 : OPT_Wdeclaration_after_statement
,
4056 "ISO C90 forbids mixed declarations and code");
4059 else if (!last_label
4060 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4062 /* __extension__ can start a declaration, but is also an
4063 unary operator that can start an expression. Consume all
4064 but the last of a possible series of __extension__ to
4066 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4067 && (c_parser_peek_2nd_token (parser
)->keyword
4069 c_parser_consume_token (parser
);
4070 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4073 ext
= disable_extension_diagnostics ();
4074 c_parser_consume_token (parser
);
4076 mark_valid_location_for_stdc_pragma (false);
4077 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4079 /* Following the old parser, __extension__ does not
4080 disable this diagnostic. */
4081 restore_extension_diagnostics (ext
);
4083 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4085 : OPT_Wdeclaration_after_statement
,
4086 "ISO C90 forbids mixed declarations and code");
4092 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4094 /* External pragmas, and some omp pragmas, are not associated
4095 with regular c code, and so are not to be considered statements
4096 syntactically. This ensures that the user doesn't put them
4097 places that would turn into syntax errors if the directive
4099 if (c_parser_pragma (parser
, pragma_compound
))
4100 last_label
= false, last_stmt
= true;
4102 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4104 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4105 c_parser_error (parser
, "expected declaration or statement");
4108 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4110 if (parser
->in_if_block
)
4112 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4113 error_at (loc
, """expected %<}%> before %<else%>");
4118 error_at (loc
, "%<else%> without a previous %<if%>");
4119 c_parser_consume_token (parser
);
4128 mark_valid_location_for_stdc_pragma (false);
4129 c_parser_statement_after_labels (parser
);
4132 parser
->error
= false;
4135 error_at (label_loc
, "label at end of compound statement");
4136 c_parser_consume_token (parser
);
4137 /* Restore the value we started with. */
4138 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4141 /* Parse a label (C90 6.6.1, C99 6.8.1).
4144 identifier : attributes[opt]
4145 case constant-expression :
4151 case constant-expression ... constant-expression :
4153 The use of attributes on labels is a GNU extension. The syntax in
4154 GNU C accepts any expressions without commas, non-constant
4155 expressions being rejected later. */
4158 c_parser_label (c_parser
*parser
)
4160 location_t loc1
= c_parser_peek_token (parser
)->location
;
4161 tree label
= NULL_TREE
;
4162 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4165 c_parser_consume_token (parser
);
4166 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4167 if (c_parser_next_token_is (parser
, CPP_COLON
))
4169 c_parser_consume_token (parser
);
4170 label
= do_case (loc1
, exp1
, NULL_TREE
);
4172 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4174 c_parser_consume_token (parser
);
4175 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4176 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4177 label
= do_case (loc1
, exp1
, exp2
);
4180 c_parser_error (parser
, "expected %<:%> or %<...%>");
4182 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4184 c_parser_consume_token (parser
);
4185 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4186 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4190 tree name
= c_parser_peek_token (parser
)->value
;
4193 location_t loc2
= c_parser_peek_token (parser
)->location
;
4194 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4195 c_parser_consume_token (parser
);
4196 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4197 c_parser_consume_token (parser
);
4198 attrs
= c_parser_attributes (parser
);
4199 tlab
= define_label (loc2
, name
);
4202 decl_attributes (&tlab
, attrs
, 0);
4203 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4208 if (c_parser_next_tokens_start_declaration (parser
))
4210 error_at (c_parser_peek_token (parser
)->location
,
4211 "a label can only be part of a statement and "
4212 "a declaration is not a statement");
4213 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4214 /*static_assert_ok*/ true,
4215 /*nested*/ true, /*empty_ok*/ false,
4216 /*start_attr_ok*/ true, NULL
);
4221 /* Parse a statement (C90 6.6, C99 6.8).
4226 expression-statement
4234 expression-statement:
4237 selection-statement:
4241 iteration-statement:
4250 return expression[opt] ;
4263 objc-throw-statement
4264 objc-try-catch-statement
4265 objc-synchronized-statement
4267 objc-throw-statement:
4281 parallel-for-construct
4282 parallel-sections-construct
4289 parallel-directive structured-block
4292 for-directive iteration-statement
4295 sections-directive section-scope
4298 single-directive structured-block
4300 parallel-for-construct:
4301 parallel-for-directive iteration-statement
4303 parallel-sections-construct:
4304 parallel-sections-directive section-scope
4307 master-directive structured-block
4310 critical-directive structured-block
4313 atomic-directive expression-statement
4316 ordered-directive structured-block */
4319 c_parser_statement (c_parser
*parser
)
4321 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4322 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4323 || (c_parser_next_token_is (parser
, CPP_NAME
)
4324 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4325 c_parser_label (parser
);
4326 c_parser_statement_after_labels (parser
);
4329 /* Parse a statement, other than a labeled statement. */
4332 c_parser_statement_after_labels (c_parser
*parser
)
4334 location_t loc
= c_parser_peek_token (parser
)->location
;
4335 tree stmt
= NULL_TREE
;
4336 bool in_if_block
= parser
->in_if_block
;
4337 parser
->in_if_block
= false;
4338 switch (c_parser_peek_token (parser
)->type
)
4340 case CPP_OPEN_BRACE
:
4341 add_stmt (c_parser_compound_statement (parser
));
4344 switch (c_parser_peek_token (parser
)->keyword
)
4347 c_parser_if_statement (parser
);
4350 c_parser_switch_statement (parser
);
4353 c_parser_while_statement (parser
);
4356 c_parser_do_statement (parser
);
4359 c_parser_for_statement (parser
);
4362 c_parser_consume_token (parser
);
4363 if (c_parser_next_token_is (parser
, CPP_NAME
))
4365 stmt
= c_finish_goto_label (loc
,
4366 c_parser_peek_token (parser
)->value
);
4367 c_parser_consume_token (parser
);
4369 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4373 c_parser_consume_token (parser
);
4374 val
= c_parser_expression (parser
).value
;
4375 mark_exp_read (val
);
4376 stmt
= c_finish_goto_ptr (loc
, val
);
4379 c_parser_error (parser
, "expected identifier or %<*%>");
4380 goto expect_semicolon
;
4382 c_parser_consume_token (parser
);
4383 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4384 goto expect_semicolon
;
4386 c_parser_consume_token (parser
);
4387 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4388 goto expect_semicolon
;
4390 c_parser_consume_token (parser
);
4391 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4393 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4394 c_parser_consume_token (parser
);
4398 struct c_expr expr
= c_parser_expression_conv (parser
);
4399 mark_exp_read (expr
.value
);
4400 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4401 goto expect_semicolon
;
4405 stmt
= c_parser_asm_statement (parser
);
4408 gcc_assert (c_dialect_objc ());
4409 c_parser_consume_token (parser
);
4410 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4412 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4413 c_parser_consume_token (parser
);
4417 tree expr
= c_parser_expression (parser
).value
;
4418 expr
= c_fully_fold (expr
, false, NULL
);
4419 stmt
= objc_build_throw_stmt (loc
, expr
);
4420 goto expect_semicolon
;
4424 gcc_assert (c_dialect_objc ());
4425 c_parser_objc_try_catch_finally_statement (parser
);
4427 case RID_AT_SYNCHRONIZED
:
4428 gcc_assert (c_dialect_objc ());
4429 c_parser_objc_synchronized_statement (parser
);
4436 c_parser_consume_token (parser
);
4438 case CPP_CLOSE_PAREN
:
4439 case CPP_CLOSE_SQUARE
:
4440 /* Avoid infinite loop in error recovery:
4441 c_parser_skip_until_found stops at a closing nesting
4442 delimiter without consuming it, but here we need to consume
4443 it to proceed further. */
4444 c_parser_error (parser
, "expected statement");
4445 c_parser_consume_token (parser
);
4448 c_parser_pragma (parser
, pragma_stmt
);
4452 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4454 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4457 /* Two cases cannot and do not have line numbers associated: If stmt
4458 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4459 cannot hold line numbers. But that's OK because the statement
4460 will either be changed to a MODIFY_EXPR during gimplification of
4461 the statement expr, or discarded. If stmt was compound, but
4462 without new variables, we will have skipped the creation of a
4463 BIND and will have a bare STATEMENT_LIST. But that's OK because
4464 (recursively) all of the component statements should already have
4465 line numbers assigned. ??? Can we discard no-op statements
4467 if (CAN_HAVE_LOCATION_P (stmt
)
4468 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4469 SET_EXPR_LOCATION (stmt
, loc
);
4471 parser
->in_if_block
= in_if_block
;
4474 /* Parse the condition from an if, do, while or for statements. */
4477 c_parser_condition (c_parser
*parser
)
4479 location_t loc
= c_parser_peek_token (parser
)->location
;
4481 cond
= c_parser_expression_conv (parser
).value
;
4482 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4483 cond
= c_fully_fold (cond
, false, NULL
);
4484 if (warn_sequence_point
)
4485 verify_sequence_points (cond
);
4489 /* Parse a parenthesized condition from an if, do or while statement.
4495 c_parser_paren_condition (c_parser
*parser
)
4498 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4499 return error_mark_node
;
4500 cond
= c_parser_condition (parser
);
4501 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4505 /* Parse a statement which is a block in C99. */
4508 c_parser_c99_block_statement (c_parser
*parser
)
4510 tree block
= c_begin_compound_stmt (flag_isoc99
);
4511 location_t loc
= c_parser_peek_token (parser
)->location
;
4512 c_parser_statement (parser
);
4513 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4516 /* Parse the body of an if statement. This is just parsing a
4517 statement but (a) it is a block in C99, (b) we track whether the
4518 body is an if statement for the sake of -Wparentheses warnings, (c)
4519 we handle an empty body specially for the sake of -Wempty-body
4520 warnings, and (d) we call parser_compound_statement directly
4521 because c_parser_statement_after_labels resets
4522 parser->in_if_block. */
4525 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4527 tree block
= c_begin_compound_stmt (flag_isoc99
);
4528 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4529 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4530 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4531 || (c_parser_next_token_is (parser
, CPP_NAME
)
4532 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4533 c_parser_label (parser
);
4534 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4535 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4537 location_t loc
= c_parser_peek_token (parser
)->location
;
4538 add_stmt (build_empty_stmt (loc
));
4539 c_parser_consume_token (parser
);
4540 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4541 warning_at (loc
, OPT_Wempty_body
,
4542 "suggest braces around empty body in an %<if%> statement");
4544 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4545 add_stmt (c_parser_compound_statement (parser
));
4547 c_parser_statement_after_labels (parser
);
4548 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4551 /* Parse the else body of an if statement. This is just parsing a
4552 statement but (a) it is a block in C99, (b) we handle an empty body
4553 specially for the sake of -Wempty-body warnings. */
4556 c_parser_else_body (c_parser
*parser
)
4558 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4559 tree block
= c_begin_compound_stmt (flag_isoc99
);
4560 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4561 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4562 || (c_parser_next_token_is (parser
, CPP_NAME
)
4563 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4564 c_parser_label (parser
);
4565 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4567 location_t loc
= c_parser_peek_token (parser
)->location
;
4570 "suggest braces around empty body in an %<else%> statement");
4571 add_stmt (build_empty_stmt (loc
));
4572 c_parser_consume_token (parser
);
4575 c_parser_statement_after_labels (parser
);
4576 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4579 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4582 if ( expression ) statement
4583 if ( expression ) statement else statement
4587 c_parser_if_statement (c_parser
*parser
)
4592 bool first_if
= false;
4593 tree first_body
, second_body
;
4596 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4597 c_parser_consume_token (parser
);
4598 block
= c_begin_compound_stmt (flag_isoc99
);
4599 loc
= c_parser_peek_token (parser
)->location
;
4600 cond
= c_parser_paren_condition (parser
);
4601 in_if_block
= parser
->in_if_block
;
4602 parser
->in_if_block
= true;
4603 first_body
= c_parser_if_body (parser
, &first_if
);
4604 parser
->in_if_block
= in_if_block
;
4605 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4607 c_parser_consume_token (parser
);
4608 second_body
= c_parser_else_body (parser
);
4611 second_body
= NULL_TREE
;
4612 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4613 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4616 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4619 switch (expression) statement
4623 c_parser_switch_statement (c_parser
*parser
)
4625 tree block
, expr
, body
, save_break
;
4626 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4627 location_t switch_cond_loc
;
4628 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4629 c_parser_consume_token (parser
);
4630 block
= c_begin_compound_stmt (flag_isoc99
);
4631 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4633 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4634 expr
= c_parser_expression (parser
).value
;
4635 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4639 switch_cond_loc
= UNKNOWN_LOCATION
;
4640 expr
= error_mark_node
;
4642 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4643 save_break
= c_break_label
;
4644 c_break_label
= NULL_TREE
;
4645 body
= c_parser_c99_block_statement (parser
);
4646 c_finish_case (body
);
4649 location_t here
= c_parser_peek_token (parser
)->location
;
4650 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4651 SET_EXPR_LOCATION (t
, here
);
4654 c_break_label
= save_break
;
4655 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4658 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4661 while (expression) statement
4665 c_parser_while_statement (c_parser
*parser
)
4667 tree block
, cond
, body
, save_break
, save_cont
;
4669 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4670 c_parser_consume_token (parser
);
4671 block
= c_begin_compound_stmt (flag_isoc99
);
4672 loc
= c_parser_peek_token (parser
)->location
;
4673 cond
= c_parser_paren_condition (parser
);
4674 save_break
= c_break_label
;
4675 c_break_label
= NULL_TREE
;
4676 save_cont
= c_cont_label
;
4677 c_cont_label
= NULL_TREE
;
4678 body
= c_parser_c99_block_statement (parser
);
4679 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4680 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4681 c_break_label
= save_break
;
4682 c_cont_label
= save_cont
;
4685 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4688 do statement while ( expression ) ;
4692 c_parser_do_statement (c_parser
*parser
)
4694 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4696 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4697 c_parser_consume_token (parser
);
4698 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4699 warning_at (c_parser_peek_token (parser
)->location
,
4701 "suggest braces around empty body in %<do%> statement");
4702 block
= c_begin_compound_stmt (flag_isoc99
);
4703 loc
= c_parser_peek_token (parser
)->location
;
4704 save_break
= c_break_label
;
4705 c_break_label
= NULL_TREE
;
4706 save_cont
= c_cont_label
;
4707 c_cont_label
= NULL_TREE
;
4708 body
= c_parser_c99_block_statement (parser
);
4709 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4710 new_break
= c_break_label
;
4711 c_break_label
= save_break
;
4712 new_cont
= c_cont_label
;
4713 c_cont_label
= save_cont
;
4714 cond
= c_parser_paren_condition (parser
);
4715 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4716 c_parser_skip_to_end_of_block_or_statement (parser
);
4717 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4718 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4721 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4724 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4725 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4727 The form with a declaration is new in C99.
4729 ??? In accordance with the old parser, the declaration may be a
4730 nested function, which is then rejected in check_for_loop_decls,
4731 but does it make any sense for this to be included in the grammar?
4732 Note in particular that the nested function does not include a
4733 trailing ';', whereas the "declaration" production includes one.
4734 Also, can we reject bad declarations earlier and cheaper than
4735 check_for_loop_decls?
4737 In Objective-C, there are two additional variants:
4740 for ( expression in expresssion ) statement
4741 for ( declaration in expression ) statement
4743 This is inconsistent with C, because the second variant is allowed
4744 even if c99 is not enabled.
4746 The rest of the comment documents these Objective-C foreach-statement.
4748 Here is the canonical example of the first variant:
4749 for (object in array) { do something with object }
4750 we call the first expression ("object") the "object_expression" and
4751 the second expression ("array") the "collection_expression".
4752 object_expression must be an lvalue of type "id" (a generic Objective-C
4753 object) because the loop works by assigning to object_expression the
4754 various objects from the collection_expression. collection_expression
4755 must evaluate to something of type "id" which responds to the method
4756 countByEnumeratingWithState:objects:count:.
4758 The canonical example of the second variant is:
4759 for (id object in array) { do something with object }
4760 which is completely equivalent to
4763 for (object in array) { do something with object }
4765 Note that initizializing 'object' in some way (eg, "for ((object =
4766 xxx) in array) { do something with object }") is possibly
4767 technically valid, but completely pointless as 'object' will be
4768 assigned to something else as soon as the loop starts. We should
4769 most likely reject it (TODO).
4771 The beginning of the Objective-C foreach-statement looks exactly
4772 like the beginning of the for-statement, and we can tell it is a
4773 foreach-statement only because the initial declaration or
4774 expression is terminated by 'in' instead of ';'.
4778 c_parser_for_statement (c_parser
*parser
)
4780 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4781 /* The following are only used when parsing an ObjC foreach statement. */
4782 tree object_expression
;
4783 /* Silence the bogus uninitialized warning. */
4784 tree collection_expression
= NULL
;
4785 location_t loc
= c_parser_peek_token (parser
)->location
;
4786 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4787 bool is_foreach_statement
= false;
4788 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4789 c_parser_consume_token (parser
);
4790 /* Open a compound statement in Objective-C as well, just in case this is
4791 as foreach expression. */
4792 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4793 cond
= error_mark_node
;
4794 incr
= error_mark_node
;
4795 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4797 /* Parse the initialization declaration or expression. */
4798 object_expression
= error_mark_node
;
4799 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4800 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4802 parser
->objc_could_be_foreach_context
= false;
4803 c_parser_consume_token (parser
);
4804 c_finish_expr_stmt (loc
, NULL_TREE
);
4806 else if (c_parser_next_tokens_start_declaration (parser
))
4808 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4809 &object_expression
);
4810 parser
->objc_could_be_foreach_context
= false;
4812 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4814 c_parser_consume_token (parser
);
4815 is_foreach_statement
= true;
4816 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4817 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4820 check_for_loop_decls (for_loc
, flag_isoc99
);
4822 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4824 /* __extension__ can start a declaration, but is also an
4825 unary operator that can start an expression. Consume all
4826 but the last of a possible series of __extension__ to
4828 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4829 && (c_parser_peek_2nd_token (parser
)->keyword
4831 c_parser_consume_token (parser
);
4832 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4835 ext
= disable_extension_diagnostics ();
4836 c_parser_consume_token (parser
);
4837 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4838 true, &object_expression
);
4839 parser
->objc_could_be_foreach_context
= false;
4841 restore_extension_diagnostics (ext
);
4842 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4844 c_parser_consume_token (parser
);
4845 is_foreach_statement
= true;
4846 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4847 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4850 check_for_loop_decls (for_loc
, flag_isoc99
);
4859 tree init_expression
;
4860 init_expression
= c_parser_expression (parser
).value
;
4861 parser
->objc_could_be_foreach_context
= false;
4862 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4864 c_parser_consume_token (parser
);
4865 is_foreach_statement
= true;
4866 if (! lvalue_p (init_expression
))
4867 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
4868 object_expression
= c_fully_fold (init_expression
, false, NULL
);
4872 c_finish_expr_stmt (loc
, init_expression
);
4873 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4877 /* Parse the loop condition. In the case of a foreach
4878 statement, there is no loop condition. */
4879 gcc_assert (!parser
->objc_could_be_foreach_context
);
4880 if (!is_foreach_statement
)
4882 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4884 c_parser_consume_token (parser
);
4889 cond
= c_parser_condition (parser
);
4890 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4893 /* Parse the increment expression (the third expression in a
4894 for-statement). In the case of a foreach-statement, this is
4895 the expression that follows the 'in'. */
4896 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4898 if (is_foreach_statement
)
4900 c_parser_error (parser
, "missing collection in fast enumeration");
4901 collection_expression
= error_mark_node
;
4904 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4908 if (is_foreach_statement
)
4909 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
4912 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4914 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4916 save_break
= c_break_label
;
4917 c_break_label
= NULL_TREE
;
4918 save_cont
= c_cont_label
;
4919 c_cont_label
= NULL_TREE
;
4920 body
= c_parser_c99_block_statement (parser
);
4921 if (is_foreach_statement
)
4922 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
4924 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4925 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
4926 c_break_label
= save_break
;
4927 c_cont_label
= save_cont
;
4930 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4931 statement with inputs, outputs, clobbers, and volatile tag
4935 asm type-qualifier[opt] ( asm-argument ) ;
4936 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4940 asm-string-literal : asm-operands[opt]
4941 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4942 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4945 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4948 Qualifiers other than volatile are accepted in the syntax but
4952 c_parser_asm_statement (c_parser
*parser
)
4954 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4955 bool simple
, is_goto
;
4956 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4957 int section
, nsections
;
4959 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4960 c_parser_consume_token (parser
);
4961 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4963 quals
= c_parser_peek_token (parser
)->value
;
4964 c_parser_consume_token (parser
);
4966 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4967 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4969 warning_at (c_parser_peek_token (parser
)->location
,
4971 "%E qualifier ignored on asm",
4972 c_parser_peek_token (parser
)->value
);
4974 c_parser_consume_token (parser
);
4980 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
4982 c_parser_consume_token (parser
);
4986 /* ??? Follow the C++ parser rather than using the
4987 lex_untranslated_string kludge. */
4988 parser
->lex_untranslated_string
= true;
4991 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4994 str
= c_parser_asm_string_literal (parser
);
4995 if (str
== NULL_TREE
)
4996 goto error_close_paren
;
4999 outputs
= NULL_TREE
;
5001 clobbers
= NULL_TREE
;
5004 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5007 /* Parse each colon-delimited section of operands. */
5008 nsections
= 3 + is_goto
;
5009 for (section
= 0; section
< nsections
; ++section
)
5011 if (!c_parser_require (parser
, CPP_COLON
,
5014 : "expected %<:%> or %<)%>"))
5015 goto error_close_paren
;
5017 /* Once past any colon, we're no longer a simple asm. */
5020 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5021 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5026 /* For asm goto, we don't allow output operands, but reserve
5027 the slot for a future extension that does allow them. */
5029 outputs
= c_parser_asm_operands (parser
, false);
5032 inputs
= c_parser_asm_operands (parser
, true);
5035 clobbers
= c_parser_asm_clobbers (parser
);
5038 labels
= c_parser_asm_goto_operands (parser
);
5044 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5049 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5051 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5055 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5056 c_parser_skip_to_end_of_block_or_statement (parser
);
5058 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5059 clobbers
, labels
, simple
));
5062 parser
->lex_untranslated_string
= false;
5066 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5070 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5071 not outputs), apply the default conversion of functions and arrays
5076 asm-operands , asm-operand
5079 asm-string-literal ( expression )
5080 [ identifier ] asm-string-literal ( expression )
5084 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
5086 tree list
= NULL_TREE
;
5092 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5094 c_parser_consume_token (parser
);
5095 if (c_parser_next_token_is (parser
, CPP_NAME
))
5097 tree id
= c_parser_peek_token (parser
)->value
;
5098 c_parser_consume_token (parser
);
5099 name
= build_string (IDENTIFIER_LENGTH (id
),
5100 IDENTIFIER_POINTER (id
));
5104 c_parser_error (parser
, "expected identifier");
5105 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5108 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5113 str
= c_parser_asm_string_literal (parser
);
5114 if (str
== NULL_TREE
)
5116 parser
->lex_untranslated_string
= false;
5117 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5119 parser
->lex_untranslated_string
= true;
5122 loc
= c_parser_peek_token (parser
)->location
;
5123 expr
= c_parser_expression (parser
);
5124 mark_exp_read (expr
.value
);
5126 expr
= default_function_array_conversion (loc
, expr
);
5127 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5128 parser
->lex_untranslated_string
= true;
5129 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5131 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5134 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5136 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5137 c_parser_consume_token (parser
);
5144 /* Parse asm clobbers, a GNU extension.
5148 asm-clobbers , asm-string-literal
5152 c_parser_asm_clobbers (c_parser
*parser
)
5154 tree list
= NULL_TREE
;
5157 tree str
= c_parser_asm_string_literal (parser
);
5159 list
= tree_cons (NULL_TREE
, str
, list
);
5162 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5163 c_parser_consume_token (parser
);
5170 /* Parse asm goto labels, a GNU extension.
5174 asm-goto-operands , identifier
5178 c_parser_asm_goto_operands (c_parser
*parser
)
5180 tree list
= NULL_TREE
;
5185 if (c_parser_next_token_is (parser
, CPP_NAME
))
5187 c_token
*tok
= c_parser_peek_token (parser
);
5189 label
= lookup_label_for_goto (tok
->location
, name
);
5190 c_parser_consume_token (parser
);
5191 TREE_USED (label
) = 1;
5195 c_parser_error (parser
, "expected identifier");
5199 name
= build_string (IDENTIFIER_LENGTH (name
),
5200 IDENTIFIER_POINTER (name
));
5201 list
= tree_cons (name
, label
, list
);
5202 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5203 c_parser_consume_token (parser
);
5205 return nreverse (list
);
5209 /* Parse an expression other than a compound expression; that is, an
5210 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5211 NULL then it is an Objective-C message expression which is the
5212 primary-expression starting the expression as an initializer.
5214 assignment-expression:
5215 conditional-expression
5216 unary-expression assignment-operator assignment-expression
5218 assignment-operator: one of
5219 = *= /= %= += -= <<= >>= &= ^= |=
5221 In GNU C we accept any conditional expression on the LHS and
5222 diagnose the invalid lvalue rather than producing a syntax
5225 static struct c_expr
5226 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5228 struct c_expr lhs
, rhs
, ret
;
5229 enum tree_code code
;
5230 location_t op_location
, exp_location
;
5231 gcc_assert (!after
|| c_dialect_objc ());
5232 lhs
= c_parser_conditional_expression (parser
, after
);
5233 op_location
= c_parser_peek_token (parser
)->location
;
5234 switch (c_parser_peek_token (parser
)->type
)
5243 code
= TRUNC_DIV_EXPR
;
5246 code
= TRUNC_MOD_EXPR
;
5261 code
= BIT_AND_EXPR
;
5264 code
= BIT_XOR_EXPR
;
5267 code
= BIT_IOR_EXPR
;
5272 c_parser_consume_token (parser
);
5273 exp_location
= c_parser_peek_token (parser
)->location
;
5274 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5275 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5276 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5277 code
, exp_location
, rhs
.value
,
5279 if (code
== NOP_EXPR
)
5280 ret
.original_code
= MODIFY_EXPR
;
5283 TREE_NO_WARNING (ret
.value
) = 1;
5284 ret
.original_code
= ERROR_MARK
;
5286 ret
.original_type
= NULL
;
5290 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5291 is not NULL then it is an Objective-C message expression which is
5292 the primary-expression starting the expression as an initializer.
5294 conditional-expression:
5295 logical-OR-expression
5296 logical-OR-expression ? expression : conditional-expression
5300 conditional-expression:
5301 logical-OR-expression ? : conditional-expression
5304 static struct c_expr
5305 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5307 struct c_expr cond
, exp1
, exp2
, ret
;
5308 location_t cond_loc
, colon_loc
, middle_loc
;
5310 gcc_assert (!after
|| c_dialect_objc ());
5312 cond
= c_parser_binary_expression (parser
, after
);
5314 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5316 cond_loc
= c_parser_peek_token (parser
)->location
;
5317 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5318 c_parser_consume_token (parser
);
5319 if (c_parser_next_token_is (parser
, CPP_COLON
))
5321 tree eptype
= NULL_TREE
;
5323 middle_loc
= c_parser_peek_token (parser
)->location
;
5324 pedwarn (middle_loc
, OPT_pedantic
,
5325 "ISO C forbids omitting the middle term of a ?: expression");
5326 warn_for_omitted_condop (middle_loc
, cond
.value
);
5327 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5329 eptype
= TREE_TYPE (cond
.value
);
5330 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5332 /* Make sure first operand is calculated only once. */
5333 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5335 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5336 exp1
.original_type
= NULL
;
5337 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5338 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5343 = c_objc_common_truthvalue_conversion
5344 (cond_loc
, default_conversion (cond
.value
));
5345 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5346 exp1
= c_parser_expression_conv (parser
);
5347 mark_exp_read (exp1
.value
);
5348 c_inhibit_evaluation_warnings
+=
5349 ((cond
.value
== truthvalue_true_node
)
5350 - (cond
.value
== truthvalue_false_node
));
5353 colon_loc
= c_parser_peek_token (parser
)->location
;
5354 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5356 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5357 ret
.value
= error_mark_node
;
5358 ret
.original_code
= ERROR_MARK
;
5359 ret
.original_type
= NULL
;
5363 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5364 exp2
= c_parser_conditional_expression (parser
, NULL
);
5365 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5367 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5368 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5369 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5370 exp1
.value
, exp1
.original_type
,
5371 exp2
.value
, exp2
.original_type
);
5372 ret
.original_code
= ERROR_MARK
;
5373 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5374 ret
.original_type
= NULL
;
5379 /* If both sides are enum type, the default conversion will have
5380 made the type of the result be an integer type. We want to
5381 remember the enum types we started with. */
5382 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5383 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5384 ret
.original_type
= ((t1
!= error_mark_node
5385 && t2
!= error_mark_node
5386 && (TYPE_MAIN_VARIANT (t1
)
5387 == TYPE_MAIN_VARIANT (t2
)))
5394 /* Parse a binary expression; that is, a logical-OR-expression (C90
5395 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5396 an Objective-C message expression which is the primary-expression
5397 starting the expression as an initializer.
5399 multiplicative-expression:
5401 multiplicative-expression * cast-expression
5402 multiplicative-expression / cast-expression
5403 multiplicative-expression % cast-expression
5405 additive-expression:
5406 multiplicative-expression
5407 additive-expression + multiplicative-expression
5408 additive-expression - multiplicative-expression
5412 shift-expression << additive-expression
5413 shift-expression >> additive-expression
5415 relational-expression:
5417 relational-expression < shift-expression
5418 relational-expression > shift-expression
5419 relational-expression <= shift-expression
5420 relational-expression >= shift-expression
5422 equality-expression:
5423 relational-expression
5424 equality-expression == relational-expression
5425 equality-expression != relational-expression
5429 AND-expression & equality-expression
5431 exclusive-OR-expression:
5433 exclusive-OR-expression ^ AND-expression
5435 inclusive-OR-expression:
5436 exclusive-OR-expression
5437 inclusive-OR-expression | exclusive-OR-expression
5439 logical-AND-expression:
5440 inclusive-OR-expression
5441 logical-AND-expression && inclusive-OR-expression
5443 logical-OR-expression:
5444 logical-AND-expression
5445 logical-OR-expression || logical-AND-expression
5448 static struct c_expr
5449 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
5451 /* A binary expression is parsed using operator-precedence parsing,
5452 with the operands being cast expressions. All the binary
5453 operators are left-associative. Thus a binary expression is of
5456 E0 op1 E1 op2 E2 ...
5458 which we represent on a stack. On the stack, the precedence
5459 levels are strictly increasing. When a new operator is
5460 encountered of higher precedence than that at the top of the
5461 stack, it is pushed; its LHS is the top expression, and its RHS
5462 is everything parsed until it is popped. When a new operator is
5463 encountered with precedence less than or equal to that at the top
5464 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5465 by the result of the operation until the operator at the top of
5466 the stack has lower precedence than the new operator or there is
5467 only one element on the stack; then the top expression is the LHS
5468 of the new operator. In the case of logical AND and OR
5469 expressions, we also need to adjust c_inhibit_evaluation_warnings
5470 as appropriate when the operators are pushed and popped. */
5472 /* The precedence levels, where 0 is a dummy lowest level used for
5473 the bottom of the stack. */
5489 /* The expression at this stack level. */
5491 /* The precedence of the operator on its left, PREC_NONE at the
5492 bottom of the stack. */
5494 /* The operation on its left. */
5496 /* The source location of this operation. */
5500 /* Location of the binary operator. */
5501 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5504 switch (stack[sp].op) \
5506 case TRUTH_ANDIF_EXPR: \
5507 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5508 == truthvalue_false_node); \
5510 case TRUTH_ORIF_EXPR: \
5511 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5512 == truthvalue_true_node); \
5517 stack[sp - 1].expr \
5518 = default_function_array_read_conversion (stack[sp - 1].loc, \
5519 stack[sp - 1].expr); \
5521 = default_function_array_read_conversion (stack[sp].loc, \
5523 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5525 stack[sp - 1].expr, \
5529 gcc_assert (!after
|| c_dialect_objc ());
5530 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5531 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5532 stack
[0].prec
= PREC_NONE
;
5537 enum tree_code ocode
;
5540 switch (c_parser_peek_token (parser
)->type
)
5548 ocode
= TRUNC_DIV_EXPR
;
5552 ocode
= TRUNC_MOD_EXPR
;
5564 ocode
= LSHIFT_EXPR
;
5568 ocode
= RSHIFT_EXPR
;
5582 case CPP_GREATER_EQ
:
5595 oprec
= PREC_BITAND
;
5596 ocode
= BIT_AND_EXPR
;
5599 oprec
= PREC_BITXOR
;
5600 ocode
= BIT_XOR_EXPR
;
5604 ocode
= BIT_IOR_EXPR
;
5607 oprec
= PREC_LOGAND
;
5608 ocode
= TRUTH_ANDIF_EXPR
;
5612 ocode
= TRUTH_ORIF_EXPR
;
5615 /* Not a binary operator, so end of the binary
5619 binary_loc
= c_parser_peek_token (parser
)->location
;
5620 c_parser_consume_token (parser
);
5621 while (oprec
<= stack
[sp
].prec
)
5625 case TRUTH_ANDIF_EXPR
:
5627 = default_function_array_read_conversion (stack
[sp
].loc
,
5629 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5630 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5631 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5632 == truthvalue_false_node
);
5634 case TRUTH_ORIF_EXPR
:
5636 = default_function_array_read_conversion (stack
[sp
].loc
,
5638 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5639 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5640 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5641 == truthvalue_true_node
);
5647 stack
[sp
].loc
= binary_loc
;
5648 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5649 stack
[sp
].prec
= oprec
;
5650 stack
[sp
].op
= ocode
;
5651 stack
[sp
].loc
= binary_loc
;
5656 return stack
[0].expr
;
5660 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5661 NULL then it is an Objective-C message expression which is the
5662 primary-expression starting the expression as an initializer.
5666 ( type-name ) unary-expression
5669 static struct c_expr
5670 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5672 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5673 gcc_assert (!after
|| c_dialect_objc ());
5675 return c_parser_postfix_expression_after_primary (parser
,
5677 /* If the expression begins with a parenthesized type name, it may
5678 be either a cast or a compound literal; we need to see whether
5679 the next character is '{' to tell the difference. If not, it is
5680 an unary expression. Full detection of unknown typenames here
5681 would require a 3-token lookahead. */
5682 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5683 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5685 struct c_type_name
*type_name
;
5688 c_parser_consume_token (parser
);
5689 type_name
= c_parser_type_name (parser
);
5690 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5691 if (type_name
== NULL
)
5693 ret
.value
= error_mark_node
;
5694 ret
.original_code
= ERROR_MARK
;
5695 ret
.original_type
= NULL
;
5699 /* Save casted types in the function's used types hash table. */
5700 used_types_insert (type_name
->specs
->type
);
5702 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5703 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5706 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5707 expr
= c_parser_cast_expression (parser
, NULL
);
5708 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5710 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5711 ret
.original_code
= ERROR_MARK
;
5712 ret
.original_type
= NULL
;
5716 return c_parser_unary_expression (parser
);
5719 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5725 unary-operator cast-expression
5726 sizeof unary-expression
5727 sizeof ( type-name )
5729 unary-operator: one of
5735 __alignof__ unary-expression
5736 __alignof__ ( type-name )
5739 unary-operator: one of
5740 __extension__ __real__ __imag__
5742 In addition, the GNU syntax treats ++ and -- as unary operators, so
5743 they may be applied to cast expressions with errors for non-lvalues
5746 static struct c_expr
5747 c_parser_unary_expression (c_parser
*parser
)
5750 struct c_expr ret
, op
;
5751 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5753 ret
.original_code
= ERROR_MARK
;
5754 ret
.original_type
= NULL
;
5755 switch (c_parser_peek_token (parser
)->type
)
5758 c_parser_consume_token (parser
);
5759 exp_loc
= c_parser_peek_token (parser
)->location
;
5760 op
= c_parser_cast_expression (parser
, NULL
);
5761 op
= default_function_array_read_conversion (exp_loc
, op
);
5762 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5763 case CPP_MINUS_MINUS
:
5764 c_parser_consume_token (parser
);
5765 exp_loc
= c_parser_peek_token (parser
)->location
;
5766 op
= c_parser_cast_expression (parser
, NULL
);
5767 op
= default_function_array_read_conversion (exp_loc
, op
);
5768 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5770 c_parser_consume_token (parser
);
5771 op
= c_parser_cast_expression (parser
, NULL
);
5772 mark_exp_read (op
.value
);
5773 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5775 c_parser_consume_token (parser
);
5776 exp_loc
= c_parser_peek_token (parser
)->location
;
5777 op
= c_parser_cast_expression (parser
, NULL
);
5778 op
= default_function_array_read_conversion (exp_loc
, op
);
5779 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5782 if (!c_dialect_objc () && !in_system_header
)
5785 "traditional C rejects the unary plus operator");
5786 c_parser_consume_token (parser
);
5787 exp_loc
= c_parser_peek_token (parser
)->location
;
5788 op
= c_parser_cast_expression (parser
, NULL
);
5789 op
= default_function_array_read_conversion (exp_loc
, op
);
5790 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5792 c_parser_consume_token (parser
);
5793 exp_loc
= c_parser_peek_token (parser
)->location
;
5794 op
= c_parser_cast_expression (parser
, NULL
);
5795 op
= default_function_array_read_conversion (exp_loc
, op
);
5796 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5798 c_parser_consume_token (parser
);
5799 exp_loc
= c_parser_peek_token (parser
)->location
;
5800 op
= c_parser_cast_expression (parser
, NULL
);
5801 op
= default_function_array_read_conversion (exp_loc
, op
);
5802 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5804 c_parser_consume_token (parser
);
5805 exp_loc
= c_parser_peek_token (parser
)->location
;
5806 op
= c_parser_cast_expression (parser
, NULL
);
5807 op
= default_function_array_read_conversion (exp_loc
, op
);
5808 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5810 /* Refer to the address of a label as a pointer. */
5811 c_parser_consume_token (parser
);
5812 if (c_parser_next_token_is (parser
, CPP_NAME
))
5814 ret
.value
= finish_label_address_expr
5815 (c_parser_peek_token (parser
)->value
, op_loc
);
5816 c_parser_consume_token (parser
);
5820 c_parser_error (parser
, "expected identifier");
5821 ret
.value
= error_mark_node
;
5825 switch (c_parser_peek_token (parser
)->keyword
)
5828 return c_parser_sizeof_expression (parser
);
5830 return c_parser_alignof_expression (parser
);
5832 c_parser_consume_token (parser
);
5833 ext
= disable_extension_diagnostics ();
5834 ret
= c_parser_cast_expression (parser
, NULL
);
5835 restore_extension_diagnostics (ext
);
5838 c_parser_consume_token (parser
);
5839 exp_loc
= c_parser_peek_token (parser
)->location
;
5840 op
= c_parser_cast_expression (parser
, NULL
);
5841 op
= default_function_array_conversion (exp_loc
, op
);
5842 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5844 c_parser_consume_token (parser
);
5845 exp_loc
= c_parser_peek_token (parser
)->location
;
5846 op
= c_parser_cast_expression (parser
, NULL
);
5847 op
= default_function_array_conversion (exp_loc
, op
);
5848 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5850 return c_parser_postfix_expression (parser
);
5853 return c_parser_postfix_expression (parser
);
5857 /* Parse a sizeof expression. */
5859 static struct c_expr
5860 c_parser_sizeof_expression (c_parser
*parser
)
5863 location_t expr_loc
;
5864 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5865 c_parser_consume_token (parser
);
5866 c_inhibit_evaluation_warnings
++;
5868 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5869 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5871 /* Either sizeof ( type-name ) or sizeof unary-expression
5872 starting with a compound literal. */
5873 struct c_type_name
*type_name
;
5874 c_parser_consume_token (parser
);
5875 expr_loc
= c_parser_peek_token (parser
)->location
;
5876 type_name
= c_parser_type_name (parser
);
5877 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5878 if (type_name
== NULL
)
5881 c_inhibit_evaluation_warnings
--;
5883 ret
.value
= error_mark_node
;
5884 ret
.original_code
= ERROR_MARK
;
5885 ret
.original_type
= NULL
;
5888 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5890 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5895 /* sizeof ( type-name ). */
5896 c_inhibit_evaluation_warnings
--;
5898 return c_expr_sizeof_type (expr_loc
, type_name
);
5902 expr_loc
= c_parser_peek_token (parser
)->location
;
5903 expr
= c_parser_unary_expression (parser
);
5905 c_inhibit_evaluation_warnings
--;
5907 mark_exp_read (expr
.value
);
5908 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5909 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5910 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5911 return c_expr_sizeof_expr (expr_loc
, expr
);
5915 /* Parse an alignof expression. */
5917 static struct c_expr
5918 c_parser_alignof_expression (c_parser
*parser
)
5921 location_t loc
= c_parser_peek_token (parser
)->location
;
5922 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5923 c_parser_consume_token (parser
);
5924 c_inhibit_evaluation_warnings
++;
5926 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5927 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5929 /* Either __alignof__ ( type-name ) or __alignof__
5930 unary-expression starting with a compound literal. */
5932 struct c_type_name
*type_name
;
5934 c_parser_consume_token (parser
);
5935 loc
= c_parser_peek_token (parser
)->location
;
5936 type_name
= c_parser_type_name (parser
);
5937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5938 if (type_name
== NULL
)
5941 c_inhibit_evaluation_warnings
--;
5943 ret
.value
= error_mark_node
;
5944 ret
.original_code
= ERROR_MARK
;
5945 ret
.original_type
= NULL
;
5948 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5950 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5955 /* alignof ( type-name ). */
5956 c_inhibit_evaluation_warnings
--;
5958 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5959 ret
.original_code
= ERROR_MARK
;
5960 ret
.original_type
= NULL
;
5966 expr
= c_parser_unary_expression (parser
);
5968 mark_exp_read (expr
.value
);
5969 c_inhibit_evaluation_warnings
--;
5971 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5972 ret
.original_code
= ERROR_MARK
;
5973 ret
.original_type
= NULL
;
5978 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5982 postfix-expression [ expression ]
5983 postfix-expression ( argument-expression-list[opt] )
5984 postfix-expression . identifier
5985 postfix-expression -> identifier
5986 postfix-expression ++
5987 postfix-expression --
5988 ( type-name ) { initializer-list }
5989 ( type-name ) { initializer-list , }
5991 argument-expression-list:
5993 argument-expression-list , argument-expression
6005 (treated as a keyword in GNU C)
6008 ( compound-statement )
6009 __builtin_va_arg ( assignment-expression , type-name )
6010 __builtin_offsetof ( type-name , offsetof-member-designator )
6011 __builtin_choose_expr ( assignment-expression ,
6012 assignment-expression ,
6013 assignment-expression )
6014 __builtin_types_compatible_p ( type-name , type-name )
6016 offsetof-member-designator:
6018 offsetof-member-designator . identifier
6019 offsetof-member-designator [ expression ]
6024 [ objc-receiver objc-message-args ]
6025 @selector ( objc-selector-arg )
6026 @protocol ( identifier )
6027 @encode ( type-name )
6029 Classname . identifier
6032 static struct c_expr
6033 c_parser_postfix_expression (c_parser
*parser
)
6035 struct c_expr expr
, e1
, e2
, e3
;
6036 struct c_type_name
*t1
, *t2
;
6037 location_t loc
= c_parser_peek_token (parser
)->location
;;
6038 expr
.original_code
= ERROR_MARK
;
6039 expr
.original_type
= NULL
;
6040 switch (c_parser_peek_token (parser
)->type
)
6043 expr
.value
= c_parser_peek_token (parser
)->value
;
6044 loc
= c_parser_peek_token (parser
)->location
;
6045 c_parser_consume_token (parser
);
6046 if (TREE_CODE (expr
.value
) == FIXED_CST
6047 && !targetm
.fixed_point_supported_p ())
6049 error_at (loc
, "fixed-point types not supported for this target");
6050 expr
.value
= error_mark_node
;
6057 expr
.value
= c_parser_peek_token (parser
)->value
;
6058 c_parser_consume_token (parser
);
6064 case CPP_UTF8STRING
:
6065 expr
.value
= c_parser_peek_token (parser
)->value
;
6066 expr
.original_code
= STRING_CST
;
6067 c_parser_consume_token (parser
);
6069 case CPP_OBJC_STRING
:
6070 gcc_assert (c_dialect_objc ());
6072 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6073 c_parser_consume_token (parser
);
6076 switch (c_parser_peek_token (parser
)->id_kind
)
6080 tree id
= c_parser_peek_token (parser
)->value
;
6081 c_parser_consume_token (parser
);
6082 expr
.value
= build_external_ref (loc
, id
,
6083 (c_parser_peek_token (parser
)->type
6085 &expr
.original_type
);
6088 case C_ID_CLASSNAME
:
6090 /* Here we parse the Objective-C 2.0 Class.name dot
6092 tree class_name
= c_parser_peek_token (parser
)->value
;
6094 c_parser_consume_token (parser
);
6095 gcc_assert (c_dialect_objc ());
6096 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6098 expr
.value
= error_mark_node
;
6101 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6103 c_parser_error (parser
, "expected identifier");
6104 expr
.value
= error_mark_node
;
6107 component
= c_parser_peek_token (parser
)->value
;
6108 c_parser_consume_token (parser
);
6109 expr
.value
= objc_build_class_component_ref (class_name
,
6114 c_parser_error (parser
, "expected expression");
6115 expr
.value
= error_mark_node
;
6119 case CPP_OPEN_PAREN
:
6120 /* A parenthesized expression, statement expression or compound
6122 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6124 /* A statement expression. */
6126 location_t brace_loc
;
6127 c_parser_consume_token (parser
);
6128 brace_loc
= c_parser_peek_token (parser
)->location
;
6129 c_parser_consume_token (parser
);
6130 if (!building_stmt_list_p ())
6132 error_at (loc
, "braced-group within expression allowed "
6133 "only inside a function");
6134 parser
->error
= true;
6135 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6136 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6137 expr
.value
= error_mark_node
;
6140 stmt
= c_begin_stmt_expr ();
6141 c_parser_compound_statement_nostart (parser
);
6142 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6144 pedwarn (loc
, OPT_pedantic
,
6145 "ISO C forbids braced-groups within expressions");
6146 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6147 mark_exp_read (expr
.value
);
6149 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6151 /* A compound literal. ??? Can we actually get here rather
6152 than going directly to
6153 c_parser_postfix_expression_after_paren_type from
6156 struct c_type_name
*type_name
;
6157 c_parser_consume_token (parser
);
6158 loc
= c_parser_peek_token (parser
)->location
;
6159 type_name
= c_parser_type_name (parser
);
6160 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6162 if (type_name
== NULL
)
6164 expr
.value
= error_mark_node
;
6167 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6173 /* A parenthesized expression. */
6174 c_parser_consume_token (parser
);
6175 expr
= c_parser_expression (parser
);
6176 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6177 TREE_NO_WARNING (expr
.value
) = 1;
6178 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6179 expr
.original_code
= ERROR_MARK
;
6180 /* Don't change EXPR.ORIGINAL_TYPE. */
6181 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6186 switch (c_parser_peek_token (parser
)->keyword
)
6188 case RID_FUNCTION_NAME
:
6189 case RID_PRETTY_FUNCTION_NAME
:
6190 case RID_C99_FUNCTION_NAME
:
6191 expr
.value
= fname_decl (loc
,
6192 c_parser_peek_token (parser
)->keyword
,
6193 c_parser_peek_token (parser
)->value
);
6194 c_parser_consume_token (parser
);
6197 c_parser_consume_token (parser
);
6198 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6200 expr
.value
= error_mark_node
;
6203 e1
= c_parser_expr_no_commas (parser
, NULL
);
6204 mark_exp_read (e1
.value
);
6205 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6206 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6208 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6209 expr
.value
= error_mark_node
;
6212 loc
= c_parser_peek_token (parser
)->location
;
6213 t1
= c_parser_type_name (parser
);
6214 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6218 expr
.value
= error_mark_node
;
6222 tree type_expr
= NULL_TREE
;
6223 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6224 groktypename (t1
, &type_expr
, NULL
));
6227 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6228 TREE_TYPE (expr
.value
), type_expr
,
6230 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6235 c_parser_consume_token (parser
);
6236 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6238 expr
.value
= error_mark_node
;
6241 t1
= c_parser_type_name (parser
);
6243 parser
->error
= true;
6244 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6245 gcc_assert (parser
->error
);
6248 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6249 expr
.value
= error_mark_node
;
6254 tree type
= groktypename (t1
, NULL
, NULL
);
6256 if (type
== error_mark_node
)
6257 offsetof_ref
= error_mark_node
;
6260 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6261 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6263 /* Parse the second argument to __builtin_offsetof. We
6264 must have one identifier, and beyond that we want to
6265 accept sub structure and sub array references. */
6266 if (c_parser_next_token_is (parser
, CPP_NAME
))
6268 offsetof_ref
= build_component_ref
6269 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6270 c_parser_consume_token (parser
);
6271 while (c_parser_next_token_is (parser
, CPP_DOT
)
6272 || c_parser_next_token_is (parser
,
6274 || c_parser_next_token_is (parser
,
6277 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6279 loc
= c_parser_peek_token (parser
)->location
;
6280 offsetof_ref
= build_array_ref (loc
,
6285 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6288 c_parser_consume_token (parser
);
6289 if (c_parser_next_token_is_not (parser
,
6292 c_parser_error (parser
, "expected identifier");
6295 offsetof_ref
= build_component_ref
6297 c_parser_peek_token (parser
)->value
);
6298 c_parser_consume_token (parser
);
6303 loc
= c_parser_peek_token (parser
)->location
;
6304 c_parser_consume_token (parser
);
6305 idx
= c_parser_expression (parser
).value
;
6306 idx
= c_fully_fold (idx
, false, NULL
);
6307 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6309 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6314 c_parser_error (parser
, "expected identifier");
6315 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6317 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
6320 case RID_CHOOSE_EXPR
:
6321 c_parser_consume_token (parser
);
6322 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6324 expr
.value
= error_mark_node
;
6327 loc
= c_parser_peek_token (parser
)->location
;
6328 e1
= c_parser_expr_no_commas (parser
, NULL
);
6329 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6331 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6332 expr
.value
= error_mark_node
;
6335 e2
= c_parser_expr_no_commas (parser
, NULL
);
6336 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6338 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6339 expr
.value
= error_mark_node
;
6342 e3
= c_parser_expr_no_commas (parser
, NULL
);
6343 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6349 mark_exp_read (e2
.value
);
6350 mark_exp_read (e3
.value
);
6351 if (TREE_CODE (c
) != INTEGER_CST
6352 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6354 "first argument to %<__builtin_choose_expr%> not"
6356 constant_expression_warning (c
);
6357 expr
= integer_zerop (c
) ? e3
: e2
;
6360 case RID_TYPES_COMPATIBLE_P
:
6361 c_parser_consume_token (parser
);
6362 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6364 expr
.value
= error_mark_node
;
6367 t1
= c_parser_type_name (parser
);
6370 expr
.value
= error_mark_node
;
6373 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6375 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6376 expr
.value
= error_mark_node
;
6379 t2
= c_parser_type_name (parser
);
6382 expr
.value
= error_mark_node
;
6385 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6390 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
6391 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
6394 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6397 case RID_AT_SELECTOR
:
6398 gcc_assert (c_dialect_objc ());
6399 c_parser_consume_token (parser
);
6400 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6402 expr
.value
= error_mark_node
;
6406 tree sel
= c_parser_objc_selector_arg (parser
);
6407 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6409 expr
.value
= objc_build_selector_expr (loc
, sel
);
6412 case RID_AT_PROTOCOL
:
6413 gcc_assert (c_dialect_objc ());
6414 c_parser_consume_token (parser
);
6415 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6417 expr
.value
= error_mark_node
;
6420 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6422 c_parser_error (parser
, "expected identifier");
6423 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6424 expr
.value
= error_mark_node
;
6428 tree id
= c_parser_peek_token (parser
)->value
;
6429 c_parser_consume_token (parser
);
6430 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6432 expr
.value
= objc_build_protocol_expr (id
);
6436 /* Extension to support C-structures in the archiver. */
6437 gcc_assert (c_dialect_objc ());
6438 c_parser_consume_token (parser
);
6439 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6441 expr
.value
= error_mark_node
;
6444 t1
= c_parser_type_name (parser
);
6447 expr
.value
= error_mark_node
;
6448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6451 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6454 tree type
= groktypename (t1
, NULL
, NULL
);
6455 expr
.value
= objc_build_encode_expr (type
);
6459 c_parser_error (parser
, "expected expression");
6460 expr
.value
= error_mark_node
;
6464 case CPP_OPEN_SQUARE
:
6465 if (c_dialect_objc ())
6467 tree receiver
, args
;
6468 c_parser_consume_token (parser
);
6469 receiver
= c_parser_objc_receiver (parser
);
6470 args
= c_parser_objc_message_args (parser
);
6471 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6473 expr
.value
= objc_build_message_expr (receiver
, args
);
6476 /* Else fall through to report error. */
6478 c_parser_error (parser
, "expected expression");
6479 expr
.value
= error_mark_node
;
6482 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6485 /* Parse a postfix expression after a parenthesized type name: the
6486 brace-enclosed initializer of a compound literal, possibly followed
6487 by some postfix operators. This is separate because it is not
6488 possible to tell until after the type name whether a cast
6489 expression has a cast or a compound literal, or whether the operand
6490 of sizeof is a parenthesized type name or starts with a compound
6491 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6492 location of the first token after the parentheses around the type
6495 static struct c_expr
6496 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6497 struct c_type_name
*type_name
,
6498 location_t type_loc
)
6504 location_t start_loc
;
6505 tree type_expr
= NULL_TREE
;
6506 bool type_expr_const
= true;
6507 check_compound_literal_type (type_loc
, type_name
);
6508 start_init (NULL_TREE
, NULL
, 0);
6509 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6510 start_loc
= c_parser_peek_token (parser
)->location
;
6511 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6513 error_at (type_loc
, "compound literal has variable size");
6514 type
= error_mark_node
;
6516 init
= c_parser_braced_init (parser
, type
, false);
6518 maybe_warn_string_init (type
, init
);
6520 if (type
!= error_mark_node
6521 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6522 && current_function_decl
)
6524 error ("compound literal qualified by address-space qualifier");
6525 type
= error_mark_node
;
6529 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
6530 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6531 ? CONSTRUCTOR_NON_CONST (init
.value
)
6532 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6533 non_const
|= !type_expr_const
;
6534 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6535 expr
.original_code
= ERROR_MARK
;
6536 expr
.original_type
= NULL
;
6539 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6541 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6542 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6546 gcc_assert (!non_const
);
6547 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6548 type_expr
, expr
.value
);
6551 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6554 /* Parse a postfix expression after the initial primary or compound
6555 literal; that is, parse a series of postfix operators.
6557 EXPR_LOC is the location of the primary expression. */
6559 static struct c_expr
6560 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6561 location_t expr_loc
,
6564 struct c_expr orig_expr
;
6566 VEC(tree
,gc
) *exprlist
;
6567 VEC(tree
,gc
) *origtypes
;
6570 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6571 switch (c_parser_peek_token (parser
)->type
)
6573 case CPP_OPEN_SQUARE
:
6574 /* Array reference. */
6575 c_parser_consume_token (parser
);
6576 idx
= c_parser_expression (parser
).value
;
6577 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6579 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6580 expr
.original_code
= ERROR_MARK
;
6581 expr
.original_type
= NULL
;
6583 case CPP_OPEN_PAREN
:
6584 /* Function call. */
6585 c_parser_consume_token (parser
);
6586 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6589 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
6590 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6593 mark_exp_read (expr
.value
);
6594 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6595 "(" after the FUNCNAME, which is what we have now. */
6596 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6598 expr
.original_code
= ERROR_MARK
;
6599 if (TREE_CODE (expr
.value
) == INTEGER_CST
6600 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6601 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6602 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6603 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6604 expr
.original_type
= NULL
;
6605 if (exprlist
!= NULL
)
6607 release_tree_vector (exprlist
);
6608 release_tree_vector (origtypes
);
6612 /* Structure element reference. */
6613 c_parser_consume_token (parser
);
6614 expr
= default_function_array_conversion (expr_loc
, expr
);
6615 if (c_parser_next_token_is (parser
, CPP_NAME
))
6616 ident
= c_parser_peek_token (parser
)->value
;
6619 c_parser_error (parser
, "expected identifier");
6620 expr
.value
= error_mark_node
;
6621 expr
.original_code
= ERROR_MARK
;
6622 expr
.original_type
= NULL
;
6625 c_parser_consume_token (parser
);
6626 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6627 expr
.original_code
= ERROR_MARK
;
6628 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6629 expr
.original_type
= NULL
;
6632 /* Remember the original type of a bitfield. */
6633 tree field
= TREE_OPERAND (expr
.value
, 1);
6634 if (TREE_CODE (field
) != FIELD_DECL
)
6635 expr
.original_type
= NULL
;
6637 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6641 /* Structure element reference. */
6642 c_parser_consume_token (parser
);
6643 expr
= default_function_array_conversion (expr_loc
, expr
);
6644 if (c_parser_next_token_is (parser
, CPP_NAME
))
6645 ident
= c_parser_peek_token (parser
)->value
;
6648 c_parser_error (parser
, "expected identifier");
6649 expr
.value
= error_mark_node
;
6650 expr
.original_code
= ERROR_MARK
;
6651 expr
.original_type
= NULL
;
6654 c_parser_consume_token (parser
);
6655 expr
.value
= build_component_ref (op_loc
,
6656 build_indirect_ref (op_loc
,
6660 expr
.original_code
= ERROR_MARK
;
6661 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6662 expr
.original_type
= NULL
;
6665 /* Remember the original type of a bitfield. */
6666 tree field
= TREE_OPERAND (expr
.value
, 1);
6667 if (TREE_CODE (field
) != FIELD_DECL
)
6668 expr
.original_type
= NULL
;
6670 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6674 /* Postincrement. */
6675 c_parser_consume_token (parser
);
6676 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6677 expr
.value
= build_unary_op (op_loc
,
6678 POSTINCREMENT_EXPR
, expr
.value
, 0);
6679 expr
.original_code
= ERROR_MARK
;
6680 expr
.original_type
= NULL
;
6682 case CPP_MINUS_MINUS
:
6683 /* Postdecrement. */
6684 c_parser_consume_token (parser
);
6685 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6686 expr
.value
= build_unary_op (op_loc
,
6687 POSTDECREMENT_EXPR
, expr
.value
, 0);
6688 expr
.original_code
= ERROR_MARK
;
6689 expr
.original_type
= NULL
;
6697 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6700 assignment-expression
6701 expression , assignment-expression
6704 static struct c_expr
6705 c_parser_expression (c_parser
*parser
)
6708 expr
= c_parser_expr_no_commas (parser
, NULL
);
6709 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6713 location_t loc
= c_parser_peek_token (parser
)->location
;
6714 location_t expr_loc
;
6715 c_parser_consume_token (parser
);
6716 expr_loc
= c_parser_peek_token (parser
)->location
;
6717 lhsval
= expr
.value
;
6718 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
6719 lhsval
= TREE_OPERAND (lhsval
, 1);
6720 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
6721 mark_exp_read (lhsval
);
6722 next
= c_parser_expr_no_commas (parser
, NULL
);
6723 next
= default_function_array_conversion (expr_loc
, next
);
6724 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
6725 expr
.original_code
= COMPOUND_EXPR
;
6726 expr
.original_type
= next
.original_type
;
6731 /* Parse an expression and convert functions or arrays to
6734 static struct c_expr
6735 c_parser_expression_conv (c_parser
*parser
)
6738 location_t loc
= c_parser_peek_token (parser
)->location
;
6739 expr
= c_parser_expression (parser
);
6740 expr
= default_function_array_conversion (loc
, expr
);
6744 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6745 functions and arrays to pointers. If FOLD_P, fold the expressions.
6748 assignment-expression
6749 nonempty-expr-list , assignment-expression
6752 static VEC(tree
,gc
) *
6753 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
6754 VEC(tree
,gc
) **p_orig_types
)
6757 VEC(tree
,gc
) *orig_types
;
6759 location_t loc
= c_parser_peek_token (parser
)->location
;
6761 ret
= make_tree_vector ();
6762 if (p_orig_types
== NULL
)
6765 orig_types
= make_tree_vector ();
6767 expr
= c_parser_expr_no_commas (parser
, NULL
);
6769 expr
= default_function_array_read_conversion (loc
, expr
);
6771 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6772 VEC_quick_push (tree
, ret
, expr
.value
);
6773 if (orig_types
!= NULL
)
6774 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6775 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6777 c_parser_consume_token (parser
);
6778 loc
= c_parser_peek_token (parser
)->location
;
6779 expr
= c_parser_expr_no_commas (parser
, NULL
);
6781 expr
= default_function_array_read_conversion (loc
, expr
);
6783 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6784 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6785 if (orig_types
!= NULL
)
6786 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6788 if (orig_types
!= NULL
)
6789 *p_orig_types
= orig_types
;
6793 /* Parse Objective-C-specific constructs. */
6795 /* Parse an objc-class-definition.
6797 objc-class-definition:
6798 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6799 objc-class-instance-variables[opt] objc-methodprotolist @end
6800 @implementation identifier objc-superclass[opt]
6801 objc-class-instance-variables[opt]
6802 @interface identifier ( identifier ) objc-protocol-refs[opt]
6803 objc-methodprotolist @end
6804 @interface identifier ( ) objc-protocol-refs[opt]
6805 objc-methodprotolist @end
6806 @implementation identifier ( identifier )
6811 "@interface identifier (" must start "@interface identifier (
6812 identifier ) ...": objc-methodprotolist in the first production may
6813 not start with a parenthesized identifier as a declarator of a data
6814 definition with no declaration specifiers if the objc-superclass,
6815 objc-protocol-refs and objc-class-instance-variables are omitted. */
6818 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
6823 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6825 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6830 c_parser_consume_token (parser
);
6831 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6833 c_parser_error (parser
, "expected identifier");
6836 id1
= c_parser_peek_token (parser
)->value
;
6837 c_parser_consume_token (parser
);
6838 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6840 /* We have a category or class extension. */
6842 tree proto
= NULL_TREE
;
6843 c_parser_consume_token (parser
);
6844 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6846 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6848 /* We have a class extension. */
6853 c_parser_error (parser
, "expected identifier or %<)%>");
6854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6860 id2
= c_parser_peek_token (parser
)->value
;
6861 c_parser_consume_token (parser
);
6863 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6866 objc_start_category_implementation (id1
, id2
);
6869 if (c_parser_next_token_is (parser
, CPP_LESS
))
6870 proto
= c_parser_objc_protocol_refs (parser
);
6871 objc_start_category_interface (id1
, id2
, proto
, attributes
);
6872 c_parser_objc_methodprotolist (parser
);
6873 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6874 objc_finish_interface ();
6877 if (c_parser_next_token_is (parser
, CPP_COLON
))
6879 c_parser_consume_token (parser
);
6880 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6882 c_parser_error (parser
, "expected identifier");
6885 superclass
= c_parser_peek_token (parser
)->value
;
6886 c_parser_consume_token (parser
);
6889 superclass
= NULL_TREE
;
6892 tree proto
= NULL_TREE
;
6893 if (c_parser_next_token_is (parser
, CPP_LESS
))
6894 proto
= c_parser_objc_protocol_refs (parser
);
6895 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
6898 objc_start_class_implementation (id1
, superclass
);
6899 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6900 c_parser_objc_class_instance_variables (parser
);
6903 objc_continue_interface ();
6904 c_parser_objc_methodprotolist (parser
);
6905 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6906 objc_finish_interface ();
6910 objc_continue_implementation ();
6915 /* Parse objc-class-instance-variables.
6917 objc-class-instance-variables:
6918 { objc-instance-variable-decl-list[opt] }
6920 objc-instance-variable-decl-list:
6921 objc-visibility-spec
6922 objc-instance-variable-decl ;
6924 objc-instance-variable-decl-list objc-visibility-spec
6925 objc-instance-variable-decl-list objc-instance-variable-decl ;
6926 objc-instance-variable-decl-list ;
6928 objc-visibility-spec:
6933 objc-instance-variable-decl:
6938 c_parser_objc_class_instance_variables (c_parser
*parser
)
6940 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6941 c_parser_consume_token (parser
);
6942 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6945 /* Parse any stray semicolon. */
6946 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6948 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6950 c_parser_consume_token (parser
);
6953 /* Stop if at the end of the instance variables. */
6954 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6956 c_parser_consume_token (parser
);
6959 /* Parse any objc-visibility-spec. */
6960 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
6962 c_parser_consume_token (parser
);
6963 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
6966 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
6968 c_parser_consume_token (parser
);
6969 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
6972 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
6974 c_parser_consume_token (parser
);
6975 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
6978 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
6980 c_parser_consume_token (parser
);
6981 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
6984 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6986 c_parser_pragma (parser
, pragma_external
);
6990 /* Parse some comma-separated declarations. */
6991 decls
= c_parser_struct_declaration (parser
);
6994 /* There is a syntax error. We want to skip the offending
6995 tokens up to the next ';' (included) or '}'
6998 /* First, skip manually a ')' or ']'. This is because they
6999 reduce the nesting level, so c_parser_skip_until_found()
7000 wouldn't be able to skip past them. */
7001 c_token
*token
= c_parser_peek_token (parser
);
7002 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7003 c_parser_consume_token (parser
);
7005 /* Then, do the standard skipping. */
7006 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7008 /* We hopefully recovered. Start normal parsing again. */
7009 parser
->error
= false;
7014 /* Comma-separated instance variables are chained together
7015 in reverse order; add them one by one. */
7016 tree ivar
= nreverse (decls
);
7017 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7018 objc_add_instance_variable (copy_node (ivar
));
7020 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7024 /* Parse an objc-class-declaration.
7026 objc-class-declaration:
7027 @class identifier-list ;
7031 c_parser_objc_class_declaration (c_parser
*parser
)
7033 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7034 c_parser_consume_token (parser
);
7035 /* Any identifiers, including those declared as type names, are OK
7040 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7042 c_parser_error (parser
, "expected identifier");
7043 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7044 parser
->error
= false;
7047 id
= c_parser_peek_token (parser
)->value
;
7048 objc_declare_class (id
);
7049 c_parser_consume_token (parser
);
7050 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7051 c_parser_consume_token (parser
);
7055 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7058 /* Parse an objc-alias-declaration.
7060 objc-alias-declaration:
7061 @compatibility_alias identifier identifier ;
7065 c_parser_objc_alias_declaration (c_parser
*parser
)
7068 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7069 c_parser_consume_token (parser
);
7070 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7072 c_parser_error (parser
, "expected identifier");
7073 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7076 id1
= c_parser_peek_token (parser
)->value
;
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 id2
= c_parser_peek_token (parser
)->value
;
7085 c_parser_consume_token (parser
);
7086 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7087 objc_declare_alias (id1
, id2
);
7090 /* Parse an objc-protocol-definition.
7092 objc-protocol-definition:
7093 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7094 @protocol identifier-list ;
7096 "@protocol identifier ;" should be resolved as "@protocol
7097 identifier-list ;": objc-methodprotolist may not start with a
7098 semicolon in the first alternative if objc-protocol-refs are
7102 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7104 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7106 c_parser_consume_token (parser
);
7107 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7109 c_parser_error (parser
, "expected identifier");
7112 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7113 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7115 /* Any identifiers, including those declared as type names, are
7120 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7122 c_parser_error (parser
, "expected identifier");
7125 id
= c_parser_peek_token (parser
)->value
;
7126 objc_declare_protocol (id
, attributes
);
7127 c_parser_consume_token (parser
);
7128 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7129 c_parser_consume_token (parser
);
7133 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7137 tree id
= c_parser_peek_token (parser
)->value
;
7138 tree proto
= NULL_TREE
;
7139 c_parser_consume_token (parser
);
7140 if (c_parser_next_token_is (parser
, CPP_LESS
))
7141 proto
= c_parser_objc_protocol_refs (parser
);
7142 parser
->objc_pq_context
= true;
7143 objc_start_protocol (id
, proto
, attributes
);
7144 c_parser_objc_methodprotolist (parser
);
7145 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7146 parser
->objc_pq_context
= false;
7147 objc_finish_interface ();
7151 /* Parse an objc-method-type.
7157 Return true if it is a class method (+) and false if it is
7158 an instance method (-).
7161 c_parser_objc_method_type (c_parser
*parser
)
7163 switch (c_parser_peek_token (parser
)->type
)
7166 c_parser_consume_token (parser
);
7169 c_parser_consume_token (parser
);
7176 /* Parse an objc-method-definition.
7178 objc-method-definition:
7179 objc-method-type objc-method-decl ;[opt] compound-statement
7183 c_parser_objc_method_definition (c_parser
*parser
)
7185 bool is_class_method
= c_parser_objc_method_type (parser
);
7186 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7187 parser
->objc_pq_context
= true;
7188 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7190 if (decl
== error_mark_node
)
7191 return; /* Bail here. */
7193 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7195 c_parser_consume_token (parser
);
7196 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7197 "extra semicolon in method definition specified");
7200 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7202 c_parser_error (parser
, "expected %<{%>");
7206 parser
->objc_pq_context
= false;
7207 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7209 add_stmt (c_parser_compound_statement (parser
));
7210 objc_finish_method_definition (current_function_decl
);
7214 /* This code is executed when we find a method definition
7215 outside of an @implementation context (or invalid for other
7216 reasons). Parse the method (to keep going) but do not emit
7219 c_parser_compound_statement (parser
);
7223 /* Parse an objc-methodprotolist.
7225 objc-methodprotolist:
7227 objc-methodprotolist objc-methodproto
7228 objc-methodprotolist declaration
7229 objc-methodprotolist ;
7233 The declaration is a data definition, which may be missing
7234 declaration specifiers under the same rules and diagnostics as
7235 other data definitions outside functions, and the stray semicolon
7236 is diagnosed the same way as a stray semicolon outside a
7240 c_parser_objc_methodprotolist (c_parser
*parser
)
7244 /* The list is terminated by @end. */
7245 switch (c_parser_peek_token (parser
)->type
)
7248 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7249 "ISO C does not allow extra %<;%> outside of a function");
7250 c_parser_consume_token (parser
);
7254 c_parser_objc_methodproto (parser
);
7257 c_parser_pragma (parser
, pragma_external
);
7262 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7264 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7265 c_parser_objc_at_property_declaration (parser
);
7266 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7268 objc_set_method_opt (true);
7269 c_parser_consume_token (parser
);
7271 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7273 objc_set_method_opt (false);
7274 c_parser_consume_token (parser
);
7277 c_parser_declaration_or_fndef (parser
, false, false, true,
7284 /* Parse an objc-methodproto.
7287 objc-method-type objc-method-decl ;
7291 c_parser_objc_methodproto (c_parser
*parser
)
7293 bool is_class_method
= c_parser_objc_method_type (parser
);
7294 tree decl
, attributes
= NULL_TREE
;
7296 /* Remember protocol qualifiers in prototypes. */
7297 parser
->objc_pq_context
= true;
7298 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7300 /* Forget protocol qualifiers now. */
7301 parser
->objc_pq_context
= false;
7303 /* Do not allow the presence of attributes to hide an erroneous
7304 method implementation in the interface section. */
7305 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7307 c_parser_error (parser
, "expected %<;%>");
7311 if (decl
!= error_mark_node
)
7312 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7314 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7317 /* If we are at a position that method attributes may be present, check that
7318 there are not any parsed already (a syntax error) and then collect any
7319 specified at the current location. Finally, if new attributes were present,
7320 check that the next token is legal ( ';' for decls and '{' for defs). */
7323 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7328 c_parser_error (parser
,
7329 "method attributes must be specified at the end only");
7330 *attributes
= NULL_TREE
;
7334 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7335 *attributes
= c_parser_attributes (parser
);
7337 /* If there were no attributes here, just report any earlier error. */
7338 if (*attributes
== NULL_TREE
|| bad
)
7341 /* If the attributes are followed by a ; or {, then just report any earlier
7343 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7344 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7347 /* We've got attributes, but not at the end. */
7348 c_parser_error (parser
,
7349 "expected %<;%> or %<{%> after method attribute definition");
7353 /* Parse an objc-method-decl.
7356 ( objc-type-name ) objc-selector
7358 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7359 objc-keyword-selector objc-optparmlist
7362 objc-keyword-selector:
7364 objc-keyword-selector objc-keyword-decl
7367 objc-selector : ( objc-type-name ) identifier
7368 objc-selector : identifier
7369 : ( objc-type-name ) identifier
7373 objc-optparms objc-optellipsis
7377 objc-opt-parms , parameter-declaration
7385 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7386 tree
*attributes
, tree
*expr
)
7388 tree type
= NULL_TREE
;
7390 tree parms
= NULL_TREE
;
7391 bool ellipsis
= false;
7392 bool attr_err
= false;
7394 *attributes
= NULL_TREE
;
7395 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7397 c_parser_consume_token (parser
);
7398 type
= c_parser_objc_type_name (parser
);
7399 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7401 sel
= c_parser_objc_selector (parser
);
7402 /* If there is no selector, or a colon follows, we have an
7403 objc-keyword-selector. If there is a selector, and a colon does
7404 not follow, that selector ends the objc-method-decl. */
7405 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7408 tree list
= NULL_TREE
;
7411 tree atype
= NULL_TREE
, id
, keyworddecl
;
7412 tree param_attr
= NULL_TREE
;
7413 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7415 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7417 c_parser_consume_token (parser
);
7418 atype
= c_parser_objc_type_name (parser
);
7419 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7422 /* New ObjC allows attributes on method parameters. */
7423 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7424 param_attr
= c_parser_attributes (parser
);
7425 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7427 c_parser_error (parser
, "expected identifier");
7428 return error_mark_node
;
7430 id
= c_parser_peek_token (parser
)->value
;
7431 c_parser_consume_token (parser
);
7432 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7433 list
= chainon (list
, keyworddecl
);
7434 tsel
= c_parser_objc_selector (parser
);
7435 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7439 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7441 /* Parse the optional parameter list. Optional Objective-C
7442 method parameters follow the C syntax, and may include '...'
7443 to denote a variable number of arguments. */
7444 parms
= make_node (TREE_LIST
);
7445 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7447 struct c_parm
*parm
;
7448 c_parser_consume_token (parser
);
7449 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7452 c_parser_consume_token (parser
);
7453 attr_err
|= c_parser_objc_maybe_method_attributes
7454 (parser
, attributes
) ;
7457 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7460 parms
= chainon (parms
,
7461 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
7466 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7470 c_parser_error (parser
, "objective-c method declaration is expected");
7471 return error_mark_node
;
7475 return error_mark_node
;
7477 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7480 /* Parse an objc-type-name.
7483 objc-type-qualifiers[opt] type-name
7484 objc-type-qualifiers[opt]
7486 objc-type-qualifiers:
7488 objc-type-qualifiers objc-type-qualifier
7490 objc-type-qualifier: one of
7491 in out inout bycopy byref oneway
7495 c_parser_objc_type_name (c_parser
*parser
)
7497 tree quals
= NULL_TREE
;
7498 struct c_type_name
*type_name
= NULL
;
7499 tree type
= NULL_TREE
;
7502 c_token
*token
= c_parser_peek_token (parser
);
7503 if (token
->type
== CPP_KEYWORD
7504 && (token
->keyword
== RID_IN
7505 || token
->keyword
== RID_OUT
7506 || token
->keyword
== RID_INOUT
7507 || token
->keyword
== RID_BYCOPY
7508 || token
->keyword
== RID_BYREF
7509 || token
->keyword
== RID_ONEWAY
))
7511 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7512 c_parser_consume_token (parser
);
7517 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7518 type_name
= c_parser_type_name (parser
);
7520 type
= groktypename (type_name
, NULL
, NULL
);
7522 /* If the type is unknown, and error has already been produced and
7523 we need to recover from the error. In that case, use NULL_TREE
7524 for the type, as if no type had been specified; this will use the
7525 default type ('id') which is good for error recovery. */
7526 if (type
== error_mark_node
)
7529 return build_tree_list (quals
, type
);
7532 /* Parse objc-protocol-refs.
7539 c_parser_objc_protocol_refs (c_parser
*parser
)
7541 tree list
= NULL_TREE
;
7542 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7543 c_parser_consume_token (parser
);
7544 /* Any identifiers, including those declared as type names, are OK
7549 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7551 c_parser_error (parser
, "expected identifier");
7554 id
= c_parser_peek_token (parser
)->value
;
7555 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7556 c_parser_consume_token (parser
);
7557 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7558 c_parser_consume_token (parser
);
7562 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7566 /* Parse an objc-try-catch-finally-statement.
7568 objc-try-catch-finally-statement:
7569 @try compound-statement objc-catch-list[opt]
7570 @try compound-statement objc-catch-list[opt] @finally compound-statement
7573 @catch ( objc-catch-parameter-declaration ) compound-statement
7574 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7576 objc-catch-parameter-declaration:
7577 parameter-declaration
7580 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7582 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7583 for C++. Keep them in sync. */
7586 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
7588 location_t location
;
7591 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7592 c_parser_consume_token (parser
);
7593 location
= c_parser_peek_token (parser
)->location
;
7594 objc_maybe_warn_exceptions (location
);
7595 stmt
= c_parser_compound_statement (parser
);
7596 objc_begin_try_stmt (location
, stmt
);
7598 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7600 struct c_parm
*parm
;
7601 tree parameter_declaration
= error_mark_node
;
7602 bool seen_open_paren
= false;
7604 c_parser_consume_token (parser
);
7605 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7606 seen_open_paren
= true;
7607 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7609 /* We have "@catch (...)" (where the '...' are literally
7610 what is in the code). Skip the '...'.
7611 parameter_declaration is set to NULL_TREE, and
7612 objc_being_catch_clauses() knows that that means
7614 c_parser_consume_token (parser
);
7615 parameter_declaration
= NULL_TREE
;
7619 /* We have "@catch (NSException *exception)" or something
7620 like that. Parse the parameter declaration. */
7621 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7623 parameter_declaration
= error_mark_node
;
7625 parameter_declaration
= grokparm (parm
, NULL
);
7627 if (seen_open_paren
)
7628 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7631 /* If there was no open parenthesis, we are recovering from
7632 an error, and we are trying to figure out what mistake
7633 the user has made. */
7635 /* If there is an immediate closing parenthesis, the user
7636 probably forgot the opening one (ie, they typed "@catch
7637 NSException *e)". Parse the closing parenthesis and keep
7639 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7640 c_parser_consume_token (parser
);
7642 /* If these is no immediate closing parenthesis, the user
7643 probably doesn't know that parenthesis are required at
7644 all (ie, they typed "@catch NSException *e"). So, just
7645 forget about the closing parenthesis and keep going. */
7647 objc_begin_catch_clause (parameter_declaration
);
7648 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7649 c_parser_compound_statement_nostart (parser
);
7650 objc_finish_catch_clause ();
7652 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
7654 c_parser_consume_token (parser
);
7655 location
= c_parser_peek_token (parser
)->location
;
7656 stmt
= c_parser_compound_statement (parser
);
7657 objc_build_finally_clause (location
, stmt
);
7659 objc_finish_try_stmt ();
7662 /* Parse an objc-synchronized-statement.
7664 objc-synchronized-statement:
7665 @synchronized ( expression ) compound-statement
7669 c_parser_objc_synchronized_statement (c_parser
*parser
)
7673 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
7674 c_parser_consume_token (parser
);
7675 loc
= c_parser_peek_token (parser
)->location
;
7676 objc_maybe_warn_exceptions (loc
);
7677 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7679 expr
= c_parser_expression (parser
).value
;
7680 expr
= c_fully_fold (expr
, false, NULL
);
7681 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7684 expr
= error_mark_node
;
7685 stmt
= c_parser_compound_statement (parser
);
7686 objc_build_synchronized (loc
, expr
, stmt
);
7689 /* Parse an objc-selector; return NULL_TREE without an error if the
7690 next token is not an objc-selector.
7695 enum struct union if else while do for switch case default
7696 break continue return goto asm sizeof typeof __alignof
7697 unsigned long const short volatile signed restrict _Complex
7698 in out inout bycopy byref oneway int char float double void _Bool
7700 ??? Why this selection of keywords but not, for example, storage
7701 class specifiers? */
7704 c_parser_objc_selector (c_parser
*parser
)
7706 c_token
*token
= c_parser_peek_token (parser
);
7707 tree value
= token
->value
;
7708 if (token
->type
== CPP_NAME
)
7710 c_parser_consume_token (parser
);
7713 if (token
->type
!= CPP_KEYWORD
)
7715 switch (token
->keyword
)
7757 c_parser_consume_token (parser
);
7764 /* Parse an objc-selector-arg.
7768 objc-keywordname-list
7770 objc-keywordname-list:
7772 objc-keywordname-list objc-keywordname
7780 c_parser_objc_selector_arg (c_parser
*parser
)
7782 tree sel
= c_parser_objc_selector (parser
);
7783 tree list
= NULL_TREE
;
7784 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7788 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7790 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
7791 sel
= c_parser_objc_selector (parser
);
7792 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7798 /* Parse an objc-receiver.
7807 c_parser_objc_receiver (c_parser
*parser
)
7809 if (c_parser_peek_token (parser
)->type
== CPP_NAME
7810 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
7811 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
7813 tree id
= c_parser_peek_token (parser
)->value
;
7814 c_parser_consume_token (parser
);
7815 return objc_get_class_reference (id
);
7817 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
7820 /* Parse objc-message-args.
7824 objc-keywordarg-list
7826 objc-keywordarg-list:
7828 objc-keywordarg-list objc-keywordarg
7831 objc-selector : objc-keywordexpr
7836 c_parser_objc_message_args (c_parser
*parser
)
7838 tree sel
= c_parser_objc_selector (parser
);
7839 tree list
= NULL_TREE
;
7840 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7845 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7846 return error_mark_node
;
7847 keywordexpr
= c_parser_objc_keywordexpr (parser
);
7848 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
7849 sel
= c_parser_objc_selector (parser
);
7850 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7856 /* Parse an objc-keywordexpr.
7863 c_parser_objc_keywordexpr (c_parser
*parser
)
7866 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
7867 if (VEC_length (tree
, expr_list
) == 1)
7869 /* Just return the expression, remove a level of
7871 ret
= VEC_index (tree
, expr_list
, 0);
7875 /* We have a comma expression, we will collapse later. */
7876 ret
= build_tree_list_vec (expr_list
);
7878 release_tree_vector (expr_list
);
7882 /* A check, needed in several places, that ObjC interface, implementation or
7883 method definitions are not prefixed by incorrect items. */
7885 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
7886 struct c_declspecs
*specs
)
7888 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
7889 || specs
->typespec_kind
!= ctsk_none
)
7891 c_parser_error (parser
,
7892 "no type or storage class may be specified here,");
7893 c_parser_skip_to_end_of_block_or_statement (parser
);
7899 /* Parse an Objective-C @property declaration. The syntax is:
7901 objc-property-declaration:
7902 '@property' objc-property-attributes[opt] struct-declaration ;
7904 objc-property-attributes:
7905 '(' objc-property-attribute-list ')'
7907 objc-property-attribute-list:
7908 objc-property-attribute
7909 objc-property-attribute-list, objc-property-attribute
7911 objc-property-attribute
7912 'getter' = identifier
7913 'setter' = identifier
7922 @property NSString *name;
7923 @property (readonly) id object;
7924 @property (retain, nonatomic, getter=getTheName) id name;
7925 @property int a, b, c;
7927 PS: This function is identical to cp_parser_objc_at_propery_declaration
7928 for C++. Keep them in sync. */
7930 c_parser_objc_at_property_declaration (c_parser
*parser
)
7932 /* The following variables hold the attributes of the properties as
7933 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7934 seen. When we see an attribute, we set them to 'true' (if they
7935 are boolean properties) or to the identifier (if they have an
7936 argument, ie, for getter and setter). Note that here we only
7937 parse the list of attributes, check the syntax and accumulate the
7938 attributes that we find. objc_add_property_declaration() will
7939 then process the information. */
7940 bool property_assign
= false;
7941 bool property_copy
= false;
7942 tree property_getter_ident
= NULL_TREE
;
7943 bool property_nonatomic
= false;
7944 bool property_readonly
= false;
7945 bool property_readwrite
= false;
7946 bool property_retain
= false;
7947 tree property_setter_ident
= NULL_TREE
;
7949 /* 'properties' is the list of properties that we read. Usually a
7950 single one, but maybe more (eg, in "@property int a, b, c;" there
7955 loc
= c_parser_peek_token (parser
)->location
;
7956 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
7958 c_parser_consume_token (parser
); /* Eat '@property'. */
7960 /* Parse the optional attribute list... */
7961 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7964 c_parser_consume_token (parser
);
7966 /* Property attribute keywords are valid now. */
7967 parser
->objc_property_attr_context
= true;
7971 bool syntax_error
= false;
7972 c_token
*token
= c_parser_peek_token (parser
);
7975 if (token
->type
!= CPP_KEYWORD
)
7977 if (token
->type
== CPP_CLOSE_PAREN
)
7978 c_parser_error (parser
, "expected identifier");
7981 c_parser_consume_token (parser
);
7982 c_parser_error (parser
, "unknown property attribute");
7986 keyword
= token
->keyword
;
7987 c_parser_consume_token (parser
);
7990 case RID_ASSIGN
: property_assign
= true; break;
7991 case RID_COPY
: property_copy
= true; break;
7992 case RID_NONATOMIC
: property_nonatomic
= true; break;
7993 case RID_READONLY
: property_readonly
= true; break;
7994 case RID_READWRITE
: property_readwrite
= true; break;
7995 case RID_RETAIN
: property_retain
= true; break;
7999 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8001 if (keyword
== RID_GETTER
)
8002 c_parser_error (parser
,
8003 "missing %<=%> (after %<getter%> attribute)");
8005 c_parser_error (parser
,
8006 "missing %<=%> (after %<setter%> attribute)");
8007 syntax_error
= true;
8010 c_parser_consume_token (parser
); /* eat the = */
8011 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8013 c_parser_error (parser
, "expected identifier");
8014 syntax_error
= true;
8017 if (keyword
== RID_SETTER
)
8019 if (property_setter_ident
!= NULL_TREE
)
8020 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8022 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8023 c_parser_consume_token (parser
);
8024 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8025 c_parser_error (parser
, "setter name must terminate with %<:%>");
8027 c_parser_consume_token (parser
);
8031 if (property_getter_ident
!= NULL_TREE
)
8032 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8034 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8035 c_parser_consume_token (parser
);
8039 c_parser_error (parser
, "unknown property attribute");
8040 syntax_error
= true;
8047 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8048 c_parser_consume_token (parser
);
8052 parser
->objc_property_attr_context
= false;
8053 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8055 /* ... and the property declaration(s). */
8056 properties
= c_parser_struct_declaration (parser
);
8058 if (properties
== error_mark_node
)
8060 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8061 parser
->error
= false;
8065 if (properties
== NULL_TREE
)
8066 c_parser_error (parser
, "expected identifier");
8069 /* Comma-separated properties are chained together in
8070 reverse order; add them one by one. */
8071 properties
= nreverse (properties
);
8073 for (; properties
; properties
= TREE_CHAIN (properties
))
8074 objc_add_property_declaration (loc
, copy_node (properties
),
8075 property_readonly
, property_readwrite
,
8076 property_assign
, property_retain
,
8077 property_copy
, property_nonatomic
,
8078 property_getter_ident
, property_setter_ident
);
8081 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8082 parser
->error
= false;
8085 /* Parse an Objective-C @synthesize declaration. The syntax is:
8087 objc-synthesize-declaration:
8088 @synthesize objc-synthesize-identifier-list ;
8090 objc-synthesize-identifier-list:
8091 objc-synthesize-identifier
8092 objc-synthesize-identifier-list, objc-synthesize-identifier
8094 objc-synthesize-identifier
8096 identifier = identifier
8099 @synthesize MyProperty;
8100 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8102 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8103 for C++. Keep them in sync.
8106 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8108 tree list
= NULL_TREE
;
8110 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8111 loc
= c_parser_peek_token (parser
)->location
;
8113 c_parser_consume_token (parser
);
8116 tree property
, ivar
;
8117 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8119 c_parser_error (parser
, "expected identifier");
8120 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8121 /* Once we find the semicolon, we can resume normal parsing.
8122 We have to reset parser->error manually because
8123 c_parser_skip_until_found() won't reset it for us if the
8124 next token is precisely a semicolon. */
8125 parser
->error
= false;
8128 property
= c_parser_peek_token (parser
)->value
;
8129 c_parser_consume_token (parser
);
8130 if (c_parser_next_token_is (parser
, CPP_EQ
))
8132 c_parser_consume_token (parser
);
8133 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8135 c_parser_error (parser
, "expected identifier");
8136 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8137 parser
->error
= false;
8140 ivar
= c_parser_peek_token (parser
)->value
;
8141 c_parser_consume_token (parser
);
8145 list
= chainon (list
, build_tree_list (ivar
, property
));
8146 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8147 c_parser_consume_token (parser
);
8151 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8152 objc_add_synthesize_declaration (loc
, list
);
8155 /* Parse an Objective-C @dynamic declaration. The syntax is:
8157 objc-dynamic-declaration:
8158 @dynamic identifier-list ;
8161 @dynamic MyProperty;
8162 @dynamic MyProperty, AnotherProperty;
8164 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8165 for C++. Keep them in sync.
8168 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8170 tree list
= NULL_TREE
;
8172 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8173 loc
= c_parser_peek_token (parser
)->location
;
8175 c_parser_consume_token (parser
);
8179 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8181 c_parser_error (parser
, "expected identifier");
8182 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8183 parser
->error
= false;
8186 property
= c_parser_peek_token (parser
)->value
;
8187 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8188 c_parser_consume_token (parser
);
8189 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8190 c_parser_consume_token (parser
);
8194 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8195 objc_add_dynamic_declaration (loc
, list
);
8199 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8200 should be considered, statements. ALLOW_STMT is true if we're within
8201 the context of a function and such pragmas are to be allowed. Returns
8202 true if we actually parsed such a pragma. */
8205 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8209 id
= c_parser_peek_token (parser
)->pragma_kind
;
8210 gcc_assert (id
!= PRAGMA_NONE
);
8214 case PRAGMA_OMP_BARRIER
:
8215 if (context
!= pragma_compound
)
8217 if (context
== pragma_stmt
)
8218 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8219 "used in compound statements");
8222 c_parser_omp_barrier (parser
);
8225 case PRAGMA_OMP_FLUSH
:
8226 if (context
!= pragma_compound
)
8228 if (context
== pragma_stmt
)
8229 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8230 "used in compound statements");
8233 c_parser_omp_flush (parser
);
8236 case PRAGMA_OMP_TASKWAIT
:
8237 if (context
!= pragma_compound
)
8239 if (context
== pragma_stmt
)
8240 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8241 "used in compound statements");
8244 c_parser_omp_taskwait (parser
);
8247 case PRAGMA_OMP_THREADPRIVATE
:
8248 c_parser_omp_threadprivate (parser
);
8251 case PRAGMA_OMP_SECTION
:
8252 error_at (c_parser_peek_token (parser
)->location
,
8253 "%<#pragma omp section%> may only be used in "
8254 "%<#pragma omp sections%> construct");
8255 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8258 case PRAGMA_GCC_PCH_PREPROCESS
:
8259 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8260 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8264 if (id
< PRAGMA_FIRST_EXTERNAL
)
8266 if (context
== pragma_external
)
8269 c_parser_error (parser
, "expected declaration specifiers");
8270 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8273 c_parser_omp_construct (parser
);
8279 c_parser_consume_pragma (parser
);
8280 c_invoke_pragma_handler (id
);
8282 /* Skip to EOL, but suppress any error message. Those will have been
8283 generated by the handler routine through calling error, as opposed
8284 to calling c_parser_error. */
8285 parser
->error
= true;
8286 c_parser_skip_to_pragma_eol (parser
);
8291 /* The interface the pragma parsers have to the lexer. */
8294 pragma_lex (tree
*value
)
8296 c_token
*tok
= c_parser_peek_token (the_parser
);
8297 enum cpp_ttype ret
= tok
->type
;
8299 *value
= tok
->value
;
8300 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8304 if (ret
== CPP_KEYWORD
)
8306 c_parser_consume_token (the_parser
);
8313 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8317 c_parser_consume_pragma (parser
);
8318 if (c_parser_next_token_is (parser
, CPP_STRING
))
8320 name
= c_parser_peek_token (parser
)->value
;
8321 c_parser_consume_token (parser
);
8324 c_parser_error (parser
, "expected string literal");
8325 c_parser_skip_to_pragma_eol (parser
);
8328 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8331 /* OpenMP 2.5 parsing routines. */
8333 /* Returns name of the next clause.
8334 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8335 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8336 returned and the token is consumed. */
8338 static pragma_omp_clause
8339 c_parser_omp_clause_name (c_parser
*parser
)
8341 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8343 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8344 result
= PRAGMA_OMP_CLAUSE_IF
;
8345 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8346 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8347 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8349 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8354 if (!strcmp ("collapse", p
))
8355 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8356 else if (!strcmp ("copyin", p
))
8357 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8358 else if (!strcmp ("copyprivate", p
))
8359 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8362 if (!strcmp ("firstprivate", p
))
8363 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8366 if (!strcmp ("lastprivate", p
))
8367 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8370 if (!strcmp ("nowait", p
))
8371 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8372 else if (!strcmp ("num_threads", p
))
8373 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8376 if (!strcmp ("ordered", p
))
8377 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8380 if (!strcmp ("private", p
))
8381 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8384 if (!strcmp ("reduction", p
))
8385 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8388 if (!strcmp ("schedule", p
))
8389 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8390 else if (!strcmp ("shared", p
))
8391 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8394 if (!strcmp ("untied", p
))
8395 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8400 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8401 c_parser_consume_token (parser
);
8406 /* Validate that a clause of the given type does not already exist. */
8409 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8414 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8415 if (OMP_CLAUSE_CODE (c
) == code
)
8417 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8418 error_at (loc
, "too many %qs clauses", name
);
8426 variable-list , identifier
8428 If KIND is nonzero, create the appropriate node and install the
8429 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8430 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8432 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8433 return the list created. */
8436 c_parser_omp_variable_list (c_parser
*parser
,
8437 location_t clause_loc
,
8438 enum omp_clause_code kind
,
8441 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8442 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8443 c_parser_error (parser
, "expected identifier");
8445 while (c_parser_next_token_is (parser
, CPP_NAME
)
8446 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8448 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8451 undeclared_variable (c_parser_peek_token (parser
)->location
,
8452 c_parser_peek_token (parser
)->value
);
8453 else if (t
== error_mark_node
)
8457 tree u
= build_omp_clause (clause_loc
, kind
);
8458 OMP_CLAUSE_DECL (u
) = t
;
8459 OMP_CLAUSE_CHAIN (u
) = list
;
8463 list
= tree_cons (t
, NULL_TREE
, list
);
8465 c_parser_consume_token (parser
);
8467 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8470 c_parser_consume_token (parser
);
8476 /* Similarly, but expect leading and trailing parenthesis. This is a very
8477 common case for omp clauses. */
8480 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8483 /* The clauses location. */
8484 location_t loc
= c_parser_peek_token (parser
)->location
;
8486 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8488 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8489 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8495 collapse ( constant-expression ) */
8498 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8500 tree c
, num
= error_mark_node
;
8504 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8506 loc
= c_parser_peek_token (parser
)->location
;
8507 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8509 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8510 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8512 if (num
== error_mark_node
)
8514 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8515 || !host_integerp (num
, 0)
8516 || (n
= tree_low_cst (num
, 0)) <= 0
8520 "collapse argument needs positive constant integer expression");
8523 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8524 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
8525 OMP_CLAUSE_CHAIN (c
) = list
;
8530 copyin ( variable-list ) */
8533 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
8535 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
8539 copyprivate ( variable-list ) */
8542 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
8544 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
8548 default ( shared | none ) */
8551 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
8553 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
8554 location_t loc
= c_parser_peek_token (parser
)->location
;
8557 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8559 if (c_parser_next_token_is (parser
, CPP_NAME
))
8561 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8566 if (strcmp ("none", p
) != 0)
8568 kind
= OMP_CLAUSE_DEFAULT_NONE
;
8572 if (strcmp ("shared", p
) != 0)
8574 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
8581 c_parser_consume_token (parser
);
8586 c_parser_error (parser
, "expected %<none%> or %<shared%>");
8588 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8590 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
8593 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
8594 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
8595 OMP_CLAUSE_CHAIN (c
) = list
;
8596 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
8602 firstprivate ( variable-list ) */
8605 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
8607 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
8611 if ( expression ) */
8614 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
8616 location_t loc
= c_parser_peek_token (parser
)->location
;
8617 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8619 tree t
= c_parser_paren_condition (parser
);
8622 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
8624 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
8625 OMP_CLAUSE_IF_EXPR (c
) = t
;
8626 OMP_CLAUSE_CHAIN (c
) = list
;
8630 c_parser_error (parser
, "expected %<(%>");
8636 lastprivate ( variable-list ) */
8639 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
8641 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
8648 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8651 location_t loc
= c_parser_peek_token (parser
)->location
;
8653 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
8655 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
8656 OMP_CLAUSE_CHAIN (c
) = list
;
8661 num_threads ( expression ) */
8664 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
8666 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
8667 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8669 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
8670 tree c
, t
= c_parser_expression (parser
).value
;
8671 t
= c_fully_fold (t
, false, NULL
);
8673 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8675 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8677 c_parser_error (parser
, "expected integer expression");
8681 /* Attempt to statically determine when the number isn't positive. */
8682 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
8683 build_int_cst (TREE_TYPE (t
), 0));
8684 if (CAN_HAVE_LOCATION_P (c
))
8685 SET_EXPR_LOCATION (c
, expr_loc
);
8686 if (c
== boolean_true_node
)
8688 warning_at (expr_loc
, 0,
8689 "%<num_threads%> value must be positive");
8690 t
= integer_one_node
;
8693 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
8695 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
8696 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
8697 OMP_CLAUSE_CHAIN (c
) = list
;
8708 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
8712 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
8714 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8715 OMP_CLAUSE_ORDERED
);
8716 OMP_CLAUSE_CHAIN (c
) = list
;
8722 private ( variable-list ) */
8725 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
8727 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
8731 reduction ( reduction-operator : variable-list )
8734 One of: + * - & ^ | && || */
8737 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
8739 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
8740 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8742 enum tree_code code
;
8744 switch (c_parser_peek_token (parser
)->type
)
8756 code
= BIT_AND_EXPR
;
8759 code
= BIT_XOR_EXPR
;
8762 code
= BIT_IOR_EXPR
;
8765 code
= TRUTH_ANDIF_EXPR
;
8768 code
= TRUTH_ORIF_EXPR
;
8771 c_parser_error (parser
,
8772 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8773 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8774 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8777 c_parser_consume_token (parser
);
8778 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8782 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
8783 OMP_CLAUSE_REDUCTION
, list
);
8784 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
8785 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
8789 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8795 schedule ( schedule-kind )
8796 schedule ( schedule-kind , expression )
8799 static | dynamic | guided | runtime | auto
8803 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
8806 location_t loc
= c_parser_peek_token (parser
)->location
;
8808 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8811 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
8813 if (c_parser_next_token_is (parser
, CPP_NAME
))
8815 tree kind
= c_parser_peek_token (parser
)->value
;
8816 const char *p
= IDENTIFIER_POINTER (kind
);
8821 if (strcmp ("dynamic", p
) != 0)
8823 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
8827 if (strcmp ("guided", p
) != 0)
8829 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
8833 if (strcmp ("runtime", p
) != 0)
8835 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
8842 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
8843 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
8844 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
8845 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
8849 c_parser_consume_token (parser
);
8850 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8853 c_parser_consume_token (parser
);
8855 here
= c_parser_peek_token (parser
)->location
;
8856 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
8857 t
= c_fully_fold (t
, false, NULL
);
8859 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
8860 error_at (here
, "schedule %<runtime%> does not take "
8861 "a %<chunk_size%> parameter");
8862 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
8864 "schedule %<auto%> does not take "
8865 "a %<chunk_size%> parameter");
8866 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
8867 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
8869 c_parser_error (parser
, "expected integer expression");
8871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8875 "expected %<,%> or %<)%>");
8877 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
8878 OMP_CLAUSE_CHAIN (c
) = list
;
8882 c_parser_error (parser
, "invalid schedule kind");
8883 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8888 shared ( variable-list ) */
8891 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
8893 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
8900 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8904 /* FIXME: Should we allow duplicates? */
8905 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
8907 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8909 OMP_CLAUSE_CHAIN (c
) = list
;
8914 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8915 is a bitmask in MASK. Return the list of clauses found; the result
8916 of clause default goes in *pdefault. */
8919 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
8922 tree clauses
= NULL
;
8925 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
8928 pragma_omp_clause c_kind
;
8930 tree prev
= clauses
;
8932 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
8933 c_parser_consume_token (parser
);
8936 here
= c_parser_peek_token (parser
)->location
;
8937 c_kind
= c_parser_omp_clause_name (parser
);
8941 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
8942 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
8943 c_name
= "collapse";
8945 case PRAGMA_OMP_CLAUSE_COPYIN
:
8946 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
8949 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
8950 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
8951 c_name
= "copyprivate";
8953 case PRAGMA_OMP_CLAUSE_DEFAULT
:
8954 clauses
= c_parser_omp_clause_default (parser
, clauses
);
8957 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
8958 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
8959 c_name
= "firstprivate";
8961 case PRAGMA_OMP_CLAUSE_IF
:
8962 clauses
= c_parser_omp_clause_if (parser
, clauses
);
8965 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
8966 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
8967 c_name
= "lastprivate";
8969 case PRAGMA_OMP_CLAUSE_NOWAIT
:
8970 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
8973 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
8974 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
8975 c_name
= "num_threads";
8977 case PRAGMA_OMP_CLAUSE_ORDERED
:
8978 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
8981 case PRAGMA_OMP_CLAUSE_PRIVATE
:
8982 clauses
= c_parser_omp_clause_private (parser
, clauses
);
8985 case PRAGMA_OMP_CLAUSE_REDUCTION
:
8986 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
8987 c_name
= "reduction";
8989 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
8990 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
8991 c_name
= "schedule";
8993 case PRAGMA_OMP_CLAUSE_SHARED
:
8994 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
8997 case PRAGMA_OMP_CLAUSE_UNTIED
:
8998 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9002 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9006 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9008 /* Remove the invalid clause(s) from the list to avoid
9009 confusing the rest of the compiler. */
9011 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9016 c_parser_skip_to_pragma_eol (parser
);
9018 return c_finish_omp_clauses (clauses
);
9025 In practice, we're also interested in adding the statement to an
9026 outer node. So it is convenient if we work around the fact that
9027 c_parser_statement calls add_stmt. */
9030 c_parser_omp_structured_block (c_parser
*parser
)
9032 tree stmt
= push_stmt_list ();
9033 c_parser_statement (parser
);
9034 return pop_stmt_list (stmt
);
9038 # pragma omp atomic new-line
9042 x binop= expr | x++ | ++x | x-- | --x
9044 +, *, -, /, &, ^, |, <<, >>
9046 where x is an lvalue expression with scalar type.
9048 LOC is the location of the #pragma token. */
9051 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9055 enum tree_code code
;
9056 struct c_expr rhs_expr
;
9058 c_parser_skip_to_pragma_eol (parser
);
9060 lhs
= c_parser_unary_expression (parser
).value
;
9061 lhs
= c_fully_fold (lhs
, false, NULL
);
9062 switch (TREE_CODE (lhs
))
9066 c_parser_skip_to_end_of_block_or_statement (parser
);
9069 case PREINCREMENT_EXPR
:
9070 case POSTINCREMENT_EXPR
:
9071 lhs
= TREE_OPERAND (lhs
, 0);
9073 rhs
= integer_one_node
;
9076 case PREDECREMENT_EXPR
:
9077 case POSTDECREMENT_EXPR
:
9078 lhs
= TREE_OPERAND (lhs
, 0);
9080 rhs
= integer_one_node
;
9084 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9085 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9086 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9087 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9088 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9089 (TREE_OPERAND (lhs
, 1), 0), 0)))
9091 /* Undo effects of boolean_increment for post {in,de}crement. */
9092 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9095 if (TREE_CODE (lhs
) == MODIFY_EXPR
9096 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9098 /* Undo effects of boolean_increment. */
9099 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9101 /* This is pre or post increment. */
9102 rhs
= TREE_OPERAND (lhs
, 1);
9103 lhs
= TREE_OPERAND (lhs
, 0);
9107 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9108 && TREE_OPERAND (lhs
, 0)
9109 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9111 /* This is pre or post decrement. */
9112 rhs
= TREE_OPERAND (lhs
, 1);
9113 lhs
= TREE_OPERAND (lhs
, 0);
9120 switch (c_parser_peek_token (parser
)->type
)
9126 code
= TRUNC_DIV_EXPR
;
9141 code
= BIT_AND_EXPR
;
9144 code
= BIT_IOR_EXPR
;
9147 code
= BIT_XOR_EXPR
;
9150 c_parser_error (parser
,
9151 "invalid operator for %<#pragma omp atomic%>");
9155 /* Arrange to pass the location of the assignment operator to
9156 c_finish_omp_atomic. */
9157 loc
= c_parser_peek_token (parser
)->location
;
9158 c_parser_consume_token (parser
);
9160 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9161 rhs_expr
= c_parser_expression (parser
);
9162 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9164 rhs
= rhs_expr
.value
;
9165 rhs
= c_fully_fold (rhs
, false, NULL
);
9168 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
9169 if (stmt
!= error_mark_node
)
9171 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9176 # pragma omp barrier new-line
9180 c_parser_omp_barrier (c_parser
*parser
)
9182 location_t loc
= c_parser_peek_token (parser
)->location
;
9183 c_parser_consume_pragma (parser
);
9184 c_parser_skip_to_pragma_eol (parser
);
9186 c_finish_omp_barrier (loc
);
9190 # pragma omp critical [(name)] new-line
9193 LOC is the location of the #pragma itself. */
9196 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9198 tree stmt
, name
= NULL
;
9200 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9202 c_parser_consume_token (parser
);
9203 if (c_parser_next_token_is (parser
, CPP_NAME
))
9205 name
= c_parser_peek_token (parser
)->value
;
9206 c_parser_consume_token (parser
);
9207 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9210 c_parser_error (parser
, "expected identifier");
9212 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9213 c_parser_error (parser
, "expected %<(%> or end of line");
9214 c_parser_skip_to_pragma_eol (parser
);
9216 stmt
= c_parser_omp_structured_block (parser
);
9217 return c_finish_omp_critical (loc
, stmt
, name
);
9221 # pragma omp flush flush-vars[opt] new-line
9224 ( variable-list ) */
9227 c_parser_omp_flush (c_parser
*parser
)
9229 location_t loc
= c_parser_peek_token (parser
)->location
;
9230 c_parser_consume_pragma (parser
);
9231 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9232 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9233 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9234 c_parser_error (parser
, "expected %<(%> or end of line");
9235 c_parser_skip_to_pragma_eol (parser
);
9237 c_finish_omp_flush (loc
);
9240 /* Parse the restricted form of the for statement allowed by OpenMP.
9241 The real trick here is to determine the loop control variable early
9242 so that we can push a new decl if necessary to make it private.
9243 LOC is the location of the OMP in "#pragma omp". */
9246 c_parser_omp_for_loop (location_t loc
,
9247 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
9249 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
9250 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
9251 bool fail
= false, open_brace_parsed
= false;
9252 int i
, collapse
= 1, nbraces
= 0;
9254 VEC(tree
,gc
) *for_block
= make_tree_vector ();
9256 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
9257 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
9258 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
9260 gcc_assert (collapse
>= 1);
9262 declv
= make_tree_vec (collapse
);
9263 initv
= make_tree_vec (collapse
);
9264 condv
= make_tree_vec (collapse
);
9265 incrv
= make_tree_vec (collapse
);
9267 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
9269 c_parser_error (parser
, "for statement expected");
9272 for_loc
= c_parser_peek_token (parser
)->location
;
9273 c_parser_consume_token (parser
);
9275 for (i
= 0; i
< collapse
; i
++)
9279 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9282 /* Parse the initialization declaration or expression. */
9283 if (c_parser_next_tokens_start_declaration (parser
))
9286 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
9287 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
9288 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
9291 if (DECL_INITIAL (decl
) == error_mark_node
)
9292 decl
= error_mark_node
;
9295 else if (c_parser_next_token_is (parser
, CPP_NAME
)
9296 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
9298 struct c_expr decl_exp
;
9299 struct c_expr init_exp
;
9300 location_t init_loc
;
9302 decl_exp
= c_parser_postfix_expression (parser
);
9303 decl
= decl_exp
.value
;
9305 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
9307 init_loc
= c_parser_peek_token (parser
)->location
;
9308 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
9309 init_exp
= default_function_array_read_conversion (init_loc
,
9311 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
9312 NOP_EXPR
, init_loc
, init_exp
.value
,
9313 init_exp
.original_type
);
9314 init
= c_process_expr_stmt (init_loc
, init
);
9316 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9321 c_parser_error (parser
,
9322 "expected iteration declaration or initialization");
9323 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9329 /* Parse the loop condition. */
9331 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
9333 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
9334 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
9336 cond
= cond_expr
.value
;
9337 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
9338 cond
= c_fully_fold (cond
, false, NULL
);
9339 switch (cond_expr
.original_code
)
9347 /* Can't be cond = error_mark_node, because we want to preserve
9348 the location until c_finish_omp_for. */
9349 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
9352 protected_set_expr_location (cond
, cond_loc
);
9354 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9356 /* Parse the increment expression. */
9358 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
9360 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
9362 incr
= c_process_expr_stmt (incr_loc
,
9363 c_parser_expression (parser
).value
);
9365 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9367 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
9371 TREE_VEC_ELT (declv
, i
) = decl
;
9372 TREE_VEC_ELT (initv
, i
) = init
;
9373 TREE_VEC_ELT (condv
, i
) = cond
;
9374 TREE_VEC_ELT (incrv
, i
) = incr
;
9378 if (i
== collapse
- 1)
9381 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9382 in between the collapsed for loops to be still considered perfectly
9383 nested. Hopefully the final version clarifies this.
9384 For now handle (multiple) {'s and empty statements. */
9387 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9389 c_parser_consume_token (parser
);
9392 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9394 c_parser_consume_token (parser
);
9398 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9399 c_parser_consume_token (parser
);
9402 c_parser_error (parser
, "not enough perfectly nested loops");
9405 open_brace_parsed
= true;
9415 nbraces
+= bracecount
;
9418 save_break
= c_break_label
;
9419 c_break_label
= size_one_node
;
9420 save_cont
= c_cont_label
;
9421 c_cont_label
= NULL_TREE
;
9422 body
= push_stmt_list ();
9424 if (open_brace_parsed
)
9426 location_t here
= c_parser_peek_token (parser
)->location
;
9427 stmt
= c_begin_compound_stmt (true);
9428 c_parser_compound_statement_nostart (parser
);
9429 add_stmt (c_end_compound_stmt (here
, stmt
, true));
9432 add_stmt (c_parser_c99_block_statement (parser
));
9435 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
9436 SET_EXPR_LOCATION (t
, loc
);
9440 body
= pop_stmt_list (body
);
9441 c_break_label
= save_break
;
9442 c_cont_label
= save_cont
;
9446 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9448 c_parser_consume_token (parser
);
9451 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9452 c_parser_consume_token (parser
);
9455 c_parser_error (parser
, "collapsed loops not perfectly nested");
9458 location_t here
= c_parser_peek_token (parser
)->location
;
9459 stmt
= c_begin_compound_stmt (true);
9461 c_parser_compound_statement_nostart (parser
);
9462 body
= c_end_compound_stmt (here
, stmt
, true);
9469 /* Only bother calling c_finish_omp_for if we haven't already generated
9470 an error from the initialization parsing. */
9473 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
9476 if (par_clauses
!= NULL
)
9479 for (c
= par_clauses
; *c
; )
9480 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
9481 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
9482 c
= &OMP_CLAUSE_CHAIN (*c
);
9485 for (i
= 0; i
< collapse
; i
++)
9486 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
9489 c
= &OMP_CLAUSE_CHAIN (*c
);
9490 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
9493 "iteration variable %qD should not be firstprivate",
9494 OMP_CLAUSE_DECL (*c
));
9495 *c
= OMP_CLAUSE_CHAIN (*c
);
9499 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9500 change it to shared (decl) in
9501 OMP_PARALLEL_CLAUSES. */
9502 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
9503 OMP_CLAUSE_LASTPRIVATE
);
9504 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
9505 OMP_CLAUSE_CHAIN (l
) = clauses
;
9507 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
9511 OMP_FOR_CLAUSES (stmt
) = clauses
;
9516 while (!VEC_empty (tree
, for_block
))
9518 /* FIXME diagnostics: LOC below should be the actual location of
9519 this particular for block. We need to build a list of
9520 locations to go along with FOR_BLOCK. */
9521 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
9524 release_tree_vector (for_block
);
9529 #pragma omp for for-clause[optseq] new-line
9532 LOC is the location of the #pragma token.
9535 #define OMP_FOR_CLAUSE_MASK \
9536 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9537 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9538 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9539 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9540 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9541 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9542 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9543 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9546 c_parser_omp_for (location_t loc
, c_parser
*parser
)
9548 tree block
, clauses
, ret
;
9550 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
9553 block
= c_begin_compound_stmt (true);
9554 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
9555 block
= c_end_compound_stmt (loc
, block
, true);
9562 # pragma omp master new-line
9565 LOC is the location of the #pragma token.
9569 c_parser_omp_master (location_t loc
, c_parser
*parser
)
9571 c_parser_skip_to_pragma_eol (parser
);
9572 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
9576 # pragma omp ordered new-line
9579 LOC is the location of the #pragma itself.
9583 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
9585 c_parser_skip_to_pragma_eol (parser
);
9586 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
9592 { section-sequence }
9595 section-directive[opt] structured-block
9596 section-sequence section-directive structured-block
9598 SECTIONS_LOC is the location of the #pragma omp sections. */
9601 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
9604 bool error_suppress
= false;
9607 loc
= c_parser_peek_token (parser
)->location
;
9608 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9610 /* Avoid skipping until the end of the block. */
9611 parser
->error
= false;
9615 stmt
= push_stmt_list ();
9617 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
9619 substmt
= push_stmt_list ();
9623 c_parser_statement (parser
);
9625 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9627 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9629 if (c_parser_next_token_is (parser
, CPP_EOF
))
9633 substmt
= pop_stmt_list (substmt
);
9634 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9635 SET_EXPR_LOCATION (substmt
, loc
);
9641 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9643 if (c_parser_next_token_is (parser
, CPP_EOF
))
9646 loc
= c_parser_peek_token (parser
)->location
;
9647 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9649 c_parser_consume_pragma (parser
);
9650 c_parser_skip_to_pragma_eol (parser
);
9651 error_suppress
= false;
9653 else if (!error_suppress
)
9655 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
9656 error_suppress
= true;
9659 substmt
= c_parser_omp_structured_block (parser
);
9660 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9661 SET_EXPR_LOCATION (substmt
, loc
);
9664 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
9665 "expected %<#pragma omp section%> or %<}%>");
9667 substmt
= pop_stmt_list (stmt
);
9669 stmt
= make_node (OMP_SECTIONS
);
9670 SET_EXPR_LOCATION (stmt
, sections_loc
);
9671 TREE_TYPE (stmt
) = void_type_node
;
9672 OMP_SECTIONS_BODY (stmt
) = substmt
;
9674 return add_stmt (stmt
);
9678 # pragma omp sections sections-clause[optseq] newline
9681 LOC is the location of the #pragma token.
9684 #define OMP_SECTIONS_CLAUSE_MASK \
9685 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9686 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9687 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9688 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9689 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9692 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
9694 tree block
, clauses
, ret
;
9696 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
9697 "#pragma omp sections");
9699 block
= c_begin_compound_stmt (true);
9700 ret
= c_parser_omp_sections_scope (loc
, parser
);
9702 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
9703 block
= c_end_compound_stmt (loc
, block
, true);
9710 # pragma parallel parallel-clause new-line
9711 # pragma parallel for parallel-for-clause new-line
9712 # pragma parallel sections parallel-sections-clause new-line
9714 LOC is the location of the #pragma token.
9717 #define OMP_PARALLEL_CLAUSE_MASK \
9718 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9719 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9720 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9721 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9722 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9723 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9724 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9725 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9728 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
9730 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
9731 const char *p_name
= "#pragma omp parallel";
9732 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
9733 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
9735 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9737 c_parser_consume_token (parser
);
9738 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
9739 p_name
= "#pragma omp parallel for";
9740 mask
|= OMP_FOR_CLAUSE_MASK
;
9741 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
9743 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9745 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9746 if (strcmp (p
, "sections") == 0)
9748 c_parser_consume_token (parser
);
9749 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
9750 p_name
= "#pragma omp parallel sections";
9751 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
9752 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
9756 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
9760 case PRAGMA_OMP_PARALLEL
:
9761 block
= c_begin_omp_parallel ();
9762 c_parser_statement (parser
);
9763 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
9766 case PRAGMA_OMP_PARALLEL_FOR
:
9767 block
= c_begin_omp_parallel ();
9768 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
9769 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
9770 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
9771 OMP_PARALLEL_COMBINED (stmt
) = 1;
9774 case PRAGMA_OMP_PARALLEL_SECTIONS
:
9775 block
= c_begin_omp_parallel ();
9776 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
9777 stmt
= c_parser_omp_sections_scope (loc
, parser
);
9779 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
9780 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
9781 OMP_PARALLEL_COMBINED (stmt
) = 1;
9792 # pragma omp single single-clause[optseq] new-line
9795 LOC is the location of the #pragma.
9798 #define OMP_SINGLE_CLAUSE_MASK \
9799 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9800 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9801 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9802 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9805 c_parser_omp_single (location_t loc
, c_parser
*parser
)
9807 tree stmt
= make_node (OMP_SINGLE
);
9808 SET_EXPR_LOCATION (stmt
, loc
);
9809 TREE_TYPE (stmt
) = void_type_node
;
9811 OMP_SINGLE_CLAUSES (stmt
)
9812 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
9813 "#pragma omp single");
9814 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
9816 return add_stmt (stmt
);
9820 # pragma omp task task-clause[optseq] new-line
9822 LOC is the location of the #pragma.
9825 #define OMP_TASK_CLAUSE_MASK \
9826 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9827 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9828 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9829 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9830 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9831 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9834 c_parser_omp_task (location_t loc
, c_parser
*parser
)
9836 tree clauses
, block
;
9838 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
9839 "#pragma omp task");
9841 block
= c_begin_omp_task ();
9842 c_parser_statement (parser
);
9843 return c_finish_omp_task (loc
, clauses
, block
);
9847 # pragma omp taskwait new-line
9851 c_parser_omp_taskwait (c_parser
*parser
)
9853 location_t loc
= c_parser_peek_token (parser
)->location
;
9854 c_parser_consume_pragma (parser
);
9855 c_parser_skip_to_pragma_eol (parser
);
9857 c_finish_omp_taskwait (loc
);
9860 /* Main entry point to parsing most OpenMP pragmas. */
9863 c_parser_omp_construct (c_parser
*parser
)
9865 enum pragma_kind p_kind
;
9869 loc
= c_parser_peek_token (parser
)->location
;
9870 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
9871 c_parser_consume_pragma (parser
);
9875 case PRAGMA_OMP_ATOMIC
:
9876 c_parser_omp_atomic (loc
, parser
);
9878 case PRAGMA_OMP_CRITICAL
:
9879 stmt
= c_parser_omp_critical (loc
, parser
);
9881 case PRAGMA_OMP_FOR
:
9882 stmt
= c_parser_omp_for (loc
, parser
);
9884 case PRAGMA_OMP_MASTER
:
9885 stmt
= c_parser_omp_master (loc
, parser
);
9887 case PRAGMA_OMP_ORDERED
:
9888 stmt
= c_parser_omp_ordered (loc
, parser
);
9890 case PRAGMA_OMP_PARALLEL
:
9891 stmt
= c_parser_omp_parallel (loc
, parser
);
9893 case PRAGMA_OMP_SECTIONS
:
9894 stmt
= c_parser_omp_sections (loc
, parser
);
9896 case PRAGMA_OMP_SINGLE
:
9897 stmt
= c_parser_omp_single (loc
, parser
);
9899 case PRAGMA_OMP_TASK
:
9900 stmt
= c_parser_omp_task (loc
, parser
);
9907 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
9912 # pragma omp threadprivate (variable-list) */
9915 c_parser_omp_threadprivate (c_parser
*parser
)
9920 c_parser_consume_pragma (parser
);
9921 loc
= c_parser_peek_token (parser
)->location
;
9922 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9924 /* Mark every variable in VARS to be assigned thread local storage. */
9925 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
9927 tree v
= TREE_PURPOSE (t
);
9929 /* FIXME diagnostics: Ideally we should keep individual
9930 locations for all the variables in the var list to make the
9931 following errors more precise. Perhaps
9932 c_parser_omp_var_list_parens() should construct a list of
9933 locations to go along with the var list. */
9935 /* If V had already been marked threadprivate, it doesn't matter
9936 whether it had been used prior to this point. */
9937 if (TREE_CODE (v
) != VAR_DECL
)
9938 error_at (loc
, "%qD is not a variable", v
);
9939 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
9940 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
9941 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
9942 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
9943 else if (TREE_TYPE (v
) == error_mark_node
)
9945 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
9946 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
9949 if (! DECL_THREAD_LOCAL_P (v
))
9951 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
9952 /* If rtl has been already set for this var, call
9953 make_decl_rtl once again, so that encode_section_info
9954 has a chance to look at the new decl flags. */
9955 if (DECL_RTL_SET_P (v
))
9958 C_DECL_THREADPRIVATE_P (v
) = 1;
9962 c_parser_skip_to_pragma_eol (parser
);
9966 /* Parse a single source file. */
9971 /* Use local storage to begin. If the first token is a pragma, parse it.
9972 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9973 which will cause garbage collection. */
9976 memset (&tparser
, 0, sizeof tparser
);
9977 the_parser
= &tparser
;
9979 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
9980 c_parser_pragma_pch_preprocess (&tparser
);
9982 the_parser
= ggc_alloc_c_parser ();
9983 *the_parser
= tparser
;
9985 /* Initialize EH, if we've been told to do so. */
9986 if (flag_exceptions
)
9987 using_eh_for_cleanups ();
9989 c_parser_translation_unit (the_parser
);
9993 #include "gt-c-parser.h"