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 Free Software Foundation, Inc.
5 Parser actions based on the old Bison parser; structure somewhat
6 influenced by and fragments based on the C++ parser.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
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"
46 #include "langhooks.h"
62 /* Miscellaneous data and functions needed for the parser. */
66 /* Objective-C specific parser/lexer information. */
68 static int objc_pq_context
= 0;
70 /* The following flag is needed to contextualize Objective-C lexical
71 analysis. In some cases (e.g., 'int NSObject;'), it is undesirable
72 to bind an identifier to an Objective-C class, even if a class with
74 static int objc_need_raw_identifier
= 0;
75 #define OBJC_NEED_RAW_IDENTIFIER(VAL) \
77 if (c_dialect_objc ()) \
78 objc_need_raw_identifier = VAL; \
81 /* The reserved keyword table. */
85 ENUM_BITFIELD(rid
) rid
: 16;
86 unsigned int disable
: 16;
89 /* Disable mask. Keywords are disabled if (reswords[i].disable &
91 #define D_C89 0x01 /* not in C89 */
92 #define D_EXT 0x02 /* GCC extension */
93 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
94 #define D_OBJC 0x08 /* Objective C only */
96 static const struct resword reswords
[] =
98 { "_Bool", RID_BOOL
, 0 },
99 { "_Complex", RID_COMPLEX
, 0 },
100 { "_Decimal32", RID_DFLOAT32
, D_EXT
},
101 { "_Decimal64", RID_DFLOAT64
, D_EXT
},
102 { "_Decimal128", RID_DFLOAT128
, D_EXT
},
103 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
104 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
105 { "__alignof", RID_ALIGNOF
, 0 },
106 { "__alignof__", RID_ALIGNOF
, 0 },
107 { "__asm", RID_ASM
, 0 },
108 { "__asm__", RID_ASM
, 0 },
109 { "__attribute", RID_ATTRIBUTE
, 0 },
110 { "__attribute__", RID_ATTRIBUTE
, 0 },
111 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
112 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
113 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
114 { "__builtin_va_arg", RID_VA_ARG
, 0 },
115 { "__complex", RID_COMPLEX
, 0 },
116 { "__complex__", RID_COMPLEX
, 0 },
117 { "__const", RID_CONST
, 0 },
118 { "__const__", RID_CONST
, 0 },
119 { "__extension__", RID_EXTENSION
, 0 },
120 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
121 { "__imag", RID_IMAGPART
, 0 },
122 { "__imag__", RID_IMAGPART
, 0 },
123 { "__inline", RID_INLINE
, 0 },
124 { "__inline__", RID_INLINE
, 0 },
125 { "__label__", RID_LABEL
, 0 },
126 { "__real", RID_REALPART
, 0 },
127 { "__real__", RID_REALPART
, 0 },
128 { "__restrict", RID_RESTRICT
, 0 },
129 { "__restrict__", RID_RESTRICT
, 0 },
130 { "__signed", RID_SIGNED
, 0 },
131 { "__signed__", RID_SIGNED
, 0 },
132 { "__thread", RID_THREAD
, 0 },
133 { "__typeof", RID_TYPEOF
, 0 },
134 { "__typeof__", RID_TYPEOF
, 0 },
135 { "__volatile", RID_VOLATILE
, 0 },
136 { "__volatile__", RID_VOLATILE
, 0 },
137 { "asm", RID_ASM
, D_EXT
},
138 { "auto", RID_AUTO
, 0 },
139 { "break", RID_BREAK
, 0 },
140 { "case", RID_CASE
, 0 },
141 { "char", RID_CHAR
, 0 },
142 { "const", RID_CONST
, 0 },
143 { "continue", RID_CONTINUE
, 0 },
144 { "default", RID_DEFAULT
, 0 },
146 { "double", RID_DOUBLE
, 0 },
147 { "else", RID_ELSE
, 0 },
148 { "enum", RID_ENUM
, 0 },
149 { "extern", RID_EXTERN
, 0 },
150 { "float", RID_FLOAT
, 0 },
151 { "for", RID_FOR
, 0 },
152 { "goto", RID_GOTO
, 0 },
154 { "inline", RID_INLINE
, D_EXT89
},
155 { "int", RID_INT
, 0 },
156 { "long", RID_LONG
, 0 },
157 { "register", RID_REGISTER
, 0 },
158 { "restrict", RID_RESTRICT
, D_C89
},
159 { "return", RID_RETURN
, 0 },
160 { "short", RID_SHORT
, 0 },
161 { "signed", RID_SIGNED
, 0 },
162 { "sizeof", RID_SIZEOF
, 0 },
163 { "static", RID_STATIC
, 0 },
164 { "struct", RID_STRUCT
, 0 },
165 { "switch", RID_SWITCH
, 0 },
166 { "typedef", RID_TYPEDEF
, 0 },
167 { "typeof", RID_TYPEOF
, D_EXT
},
168 { "union", RID_UNION
, 0 },
169 { "unsigned", RID_UNSIGNED
, 0 },
170 { "void", RID_VOID
, 0 },
171 { "volatile", RID_VOLATILE
, 0 },
172 { "while", RID_WHILE
, 0 },
173 /* These Objective-C keywords are recognized only immediately after
175 { "class", RID_AT_CLASS
, D_OBJC
},
176 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
177 { "defs", RID_AT_DEFS
, D_OBJC
},
178 { "encode", RID_AT_ENCODE
, D_OBJC
},
179 { "end", RID_AT_END
, D_OBJC
},
180 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
181 { "interface", RID_AT_INTERFACE
, D_OBJC
},
182 { "private", RID_AT_PRIVATE
, D_OBJC
},
183 { "protected", RID_AT_PROTECTED
, D_OBJC
},
184 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
185 { "public", RID_AT_PUBLIC
, D_OBJC
},
186 { "selector", RID_AT_SELECTOR
, D_OBJC
},
187 { "throw", RID_AT_THROW
, D_OBJC
},
188 { "try", RID_AT_TRY
, D_OBJC
},
189 { "catch", RID_AT_CATCH
, D_OBJC
},
190 { "finally", RID_AT_FINALLY
, D_OBJC
},
191 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
192 /* These are recognized only in protocol-qualifier context
194 { "bycopy", RID_BYCOPY
, D_OBJC
},
195 { "byref", RID_BYREF
, D_OBJC
},
196 { "in", RID_IN
, D_OBJC
},
197 { "inout", RID_INOUT
, D_OBJC
},
198 { "oneway", RID_ONEWAY
, D_OBJC
},
199 { "out", RID_OUT
, D_OBJC
},
201 #define N_reswords (sizeof reswords / sizeof (struct resword))
203 /* Initialization routine for this file. */
208 /* The only initialization required is of the reserved word
212 int mask
= (flag_isoc99
? 0 : D_C89
)
213 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
215 if (!c_dialect_objc ())
218 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
219 for (i
= 0; i
< N_reswords
; i
++)
221 /* If a keyword is disabled, do not enter it into the table
222 and so create a canonical spelling that isn't a keyword. */
223 if (reswords
[i
].disable
& mask
)
226 id
= get_identifier (reswords
[i
].word
);
227 C_RID_CODE (id
) = reswords
[i
].rid
;
228 C_IS_RESERVED_WORD (id
) = 1;
229 ridpointers
[(int) reswords
[i
].rid
] = id
;
233 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
234 and the C parser. Unlike the C++ lexer, the parser structure
235 stores the lexer information instead of using a separate structure.
236 Identifiers are separated into ordinary identifiers, type names,
237 keywords and some other Objective-C types of identifiers, and some
238 look-ahead is maintained.
240 ??? It might be a good idea to lex the whole file up front (as for
241 C++). It would then be possible to share more of the C and C++
242 lexer code, if desired. */
244 /* The following local token type is used. */
247 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
249 /* More information about the type of a CPP_NAME token. */
250 typedef enum c_id_kind
{
251 /* An ordinary identifier. */
253 /* An identifier declared as a typedef name. */
255 /* An identifier declared as an Objective-C class name. */
257 /* Not an identifier. */
261 /* A single C token after string literal concatenation and conversion
262 of preprocessing tokens to tokens. */
263 typedef struct c_token
GTY (())
265 /* The kind of token. */
266 ENUM_BITFIELD (cpp_ttype
) type
: 8;
267 /* If this token is a CPP_NAME, this value indicates whether also
268 declared as some kind of type. Otherwise, it is C_ID_NONE. */
269 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
270 /* If this token is a keyword, this value indicates which keyword.
271 Otherwise, this value is RID_MAX. */
272 ENUM_BITFIELD (rid
) keyword
: 8;
273 /* If this token is a CPP_PRAGMA, this indicates the pragma that
274 was seen. Otherwise it is PRAGMA_NONE. */
275 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 7;
276 /* True if this token is from a system header. */
277 BOOL_BITFIELD in_system_header
: 1;
278 /* The value associated with this token, if any. */
280 /* The location at which this token was found. */
284 /* A parser structure recording information about the state and
285 context of parsing. Includes lexer information with up to two
286 tokens of look-ahead; more are not needed for C. */
287 typedef struct c_parser
GTY(())
289 /* The look-ahead tokens. */
291 /* How many look-ahead tokens are available (0, 1 or 2). */
293 /* True if a syntax error is being recovered from; false otherwise.
294 c_parser_error sets this flag. It should clear this flag when
295 enough tokens have been consumed to recover from the error. */
296 BOOL_BITFIELD error
: 1;
297 /* True if we're processing a pragma, and shouldn't automatically
298 consume CPP_PRAGMA_EOL. */
299 BOOL_BITFIELD in_pragma
: 1;
303 /* The actual parser and external interface. ??? Does this need to be
304 garbage-collected? */
306 static GTY (()) c_parser
*the_parser
;
309 /* Read in and lex a single token, storing it in *TOKEN. */
312 c_lex_one_token (c_token
*token
)
314 timevar_push (TV_LEX
);
316 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
);
317 token
->id_kind
= C_ID_NONE
;
318 token
->keyword
= RID_MAX
;
319 token
->pragma_kind
= PRAGMA_NONE
;
320 token
->in_system_header
= in_system_header
;
328 int objc_force_identifier
= objc_need_raw_identifier
;
329 OBJC_NEED_RAW_IDENTIFIER (0);
331 if (C_IS_RESERVED_WORD (token
->value
))
333 enum rid rid_code
= C_RID_CODE (token
->value
);
335 if (c_dialect_objc ())
337 if (!OBJC_IS_AT_KEYWORD (rid_code
)
338 && (!OBJC_IS_PQ_KEYWORD (rid_code
) || objc_pq_context
))
340 /* Return the canonical spelling for this keyword. */
341 token
->value
= ridpointers
[(int) rid_code
];
342 token
->type
= CPP_KEYWORD
;
343 token
->keyword
= rid_code
;
349 /* Return the canonical spelling for this keyword. */
350 token
->value
= ridpointers
[(int) rid_code
];
351 token
->type
= CPP_KEYWORD
;
352 token
->keyword
= rid_code
;
357 decl
= lookup_name (token
->value
);
360 if (TREE_CODE (decl
) == TYPE_DECL
)
362 token
->id_kind
= C_ID_TYPENAME
;
366 else if (c_dialect_objc ())
368 tree objc_interface_decl
= objc_is_class_name (token
->value
);
369 /* Objective-C class names are in the same namespace as
370 variables and typedefs, and hence are shadowed by local
372 if (objc_interface_decl
373 && (global_bindings_p ()
374 || (!objc_force_identifier
&& !decl
)))
376 token
->value
= objc_interface_decl
;
377 token
->id_kind
= C_ID_CLASSNAME
;
381 token
->id_kind
= C_ID_ID
;
385 /* This only happens in Objective-C; it must be a keyword. */
386 token
->type
= CPP_KEYWORD
;
387 token
->keyword
= C_RID_CODE (token
->value
);
391 case CPP_CLOSE_PAREN
:
393 /* These tokens may affect the interpretation of any identifiers
394 following, if doing Objective-C. */
395 OBJC_NEED_RAW_IDENTIFIER (0);
398 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
399 token
->pragma_kind
= TREE_INT_CST_LOW (token
->value
);
405 timevar_pop (TV_LEX
);
408 /* Return a pointer to the next token from PARSER, reading it in if
411 static inline c_token
*
412 c_parser_peek_token (c_parser
*parser
)
414 if (parser
->tokens_avail
== 0)
416 c_lex_one_token (&parser
->tokens
[0]);
417 parser
->tokens_avail
= 1;
419 return &parser
->tokens
[0];
422 /* Return true if the next token from PARSER has the indicated
426 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
428 return c_parser_peek_token (parser
)->type
== type
;
431 /* Return true if the next token from PARSER does not have the
435 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
437 return !c_parser_next_token_is (parser
, type
);
440 /* Return true if the next token from PARSER is the indicated
444 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
448 /* Peek at the next token. */
449 token
= c_parser_peek_token (parser
);
450 /* Check to see if it is the indicated keyword. */
451 return token
->keyword
== keyword
;
454 /* Return true if TOKEN can start a type name,
457 c_token_starts_typename (c_token
*token
)
462 switch (token
->id_kind
)
469 gcc_assert (c_dialect_objc ());
475 switch (token
->keyword
)
504 if (c_dialect_objc ())
512 /* Return true if the next token from PARSER can start a type name,
515 c_parser_next_token_starts_typename (c_parser
*parser
)
517 c_token
*token
= c_parser_peek_token (parser
);
518 return c_token_starts_typename (token
);
521 /* Return true if TOKEN can start declaration specifiers, false
524 c_token_starts_declspecs (c_token
*token
)
529 switch (token
->id_kind
)
536 gcc_assert (c_dialect_objc ());
542 switch (token
->keyword
)
578 if (c_dialect_objc ())
586 /* Return true if the next token from PARSER can start declaration
587 specifiers, false otherwise. */
589 c_parser_next_token_starts_declspecs (c_parser
*parser
)
591 c_token
*token
= c_parser_peek_token (parser
);
592 return c_token_starts_declspecs (token
);
595 /* Return a pointer to the next-but-one token from PARSER, reading it
596 in if necessary. The next token is already read in. */
599 c_parser_peek_2nd_token (c_parser
*parser
)
601 if (parser
->tokens_avail
>= 2)
602 return &parser
->tokens
[1];
603 gcc_assert (parser
->tokens_avail
== 1);
604 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
605 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
606 c_lex_one_token (&parser
->tokens
[1]);
607 parser
->tokens_avail
= 2;
608 return &parser
->tokens
[1];
611 /* Consume the next token from PARSER. */
614 c_parser_consume_token (c_parser
*parser
)
616 gcc_assert (parser
->tokens_avail
>= 1);
617 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
618 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
619 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
620 if (parser
->tokens_avail
== 2)
621 parser
->tokens
[0] = parser
->tokens
[1];
622 parser
->tokens_avail
--;
625 /* Expect the current token to be a #pragma. Consume it and remember
626 that we've begun parsing a pragma. */
629 c_parser_consume_pragma (c_parser
*parser
)
631 gcc_assert (!parser
->in_pragma
);
632 gcc_assert (parser
->tokens_avail
>= 1);
633 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
634 if (parser
->tokens_avail
== 2)
635 parser
->tokens
[0] = parser
->tokens
[1];
636 parser
->tokens_avail
--;
637 parser
->in_pragma
= true;
640 /* Update the globals input_location and in_system_header from
643 c_parser_set_source_position_from_token (c_token
*token
)
645 if (token
->type
!= CPP_EOF
)
647 input_location
= token
->location
;
648 in_system_header
= token
->in_system_header
;
652 /* Issue a diagnostic of the form
653 FILE:LINE: MESSAGE before TOKEN
654 where TOKEN is the next token in the input stream of PARSER.
655 MESSAGE (specified by the caller) is usually of the form "expected
658 Do not issue a diagnostic if still recovering from an error.
660 ??? This is taken from the C++ parser, but building up messages in
661 this way is not i18n-friendly and some other approach should be
665 c_parser_error (c_parser
*parser
, const char *gmsgid
)
667 c_token
*token
= c_parser_peek_token (parser
);
670 parser
->error
= true;
673 /* This diagnostic makes more sense if it is tagged to the line of
674 the token we just peeked at. */
675 c_parser_set_source_position_from_token (token
);
676 c_parse_error (gmsgid
,
677 /* Because c_parse_error does not understand
678 CPP_KEYWORD, keywords are treated like
680 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
684 /* If the next token is of the indicated TYPE, consume it. Otherwise,
685 issue the error MSGID. If MSGID is NULL then a message has already
686 been produced and no message will be produced this time. Returns
687 true if found, false otherwise. */
690 c_parser_require (c_parser
*parser
,
694 if (c_parser_next_token_is (parser
, type
))
696 c_parser_consume_token (parser
);
701 c_parser_error (parser
, msgid
);
706 /* If the next token is the indicated keyword, consume it. Otherwise,
707 issue the error MSGID. Returns true if found, false otherwise. */
710 c_parser_require_keyword (c_parser
*parser
,
714 if (c_parser_next_token_is_keyword (parser
, keyword
))
716 c_parser_consume_token (parser
);
721 c_parser_error (parser
, msgid
);
726 /* Like c_parser_require, except that tokens will be skipped until the
727 desired token is found. An error message is still produced if the
728 next token is not as expected. If MSGID is NULL then a message has
729 already been produced and no message will be produced this
733 c_parser_skip_until_found (c_parser
*parser
,
737 unsigned nesting_depth
= 0;
739 if (c_parser_require (parser
, type
, msgid
))
742 /* Skip tokens until the desired token is found. */
745 /* Peek at the next token. */
746 c_token
*token
= c_parser_peek_token (parser
);
747 /* If we've reached the token we want, consume it and stop. */
748 if (token
->type
== type
&& !nesting_depth
)
750 c_parser_consume_token (parser
);
754 /* If we've run out of tokens, stop. */
755 if (token
->type
== CPP_EOF
)
757 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
759 if (token
->type
== CPP_OPEN_BRACE
760 || token
->type
== CPP_OPEN_PAREN
761 || token
->type
== CPP_OPEN_SQUARE
)
763 else if (token
->type
== CPP_CLOSE_BRACE
764 || token
->type
== CPP_CLOSE_PAREN
765 || token
->type
== CPP_CLOSE_SQUARE
)
767 if (nesting_depth
-- == 0)
770 /* Consume this token. */
771 c_parser_consume_token (parser
);
773 parser
->error
= false;
776 /* Skip tokens until the end of a parameter is found, but do not
777 consume the comma, semicolon or closing delimiter. */
780 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
782 unsigned nesting_depth
= 0;
786 c_token
*token
= c_parser_peek_token (parser
);
787 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
790 /* If we've run out of tokens, stop. */
791 if (token
->type
== CPP_EOF
)
793 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
795 if (token
->type
== CPP_OPEN_BRACE
796 || token
->type
== CPP_OPEN_PAREN
797 || token
->type
== CPP_OPEN_SQUARE
)
799 else if (token
->type
== CPP_CLOSE_BRACE
800 || token
->type
== CPP_CLOSE_PAREN
801 || token
->type
== CPP_CLOSE_SQUARE
)
803 if (nesting_depth
-- == 0)
806 /* Consume this token. */
807 c_parser_consume_token (parser
);
809 parser
->error
= false;
812 /* Skip tokens until we have consumed an entire block, or until we
813 have consumed a non-nested ';'. */
816 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
818 unsigned nesting_depth
= 0;
824 /* Peek at the next token. */
825 token
= c_parser_peek_token (parser
);
826 /* If we've run out of tokens, stop. */
827 if (token
->type
== CPP_EOF
)
829 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
831 /* If the next token is a ';', we have reached the end of the
833 if (token
->type
== CPP_SEMICOLON
&& !nesting_depth
)
835 /* Consume the ';'. */
836 c_parser_consume_token (parser
);
839 /* If the next token is a non-nested '}', then we have reached
840 the end of the current block. */
841 if (token
->type
== CPP_CLOSE_BRACE
842 && (nesting_depth
== 0 || --nesting_depth
== 0))
844 c_parser_consume_token (parser
);
847 /* If it the next token is a '{', then we are entering a new
848 block. Consume the entire block. */
849 if (token
->type
== CPP_OPEN_BRACE
)
851 c_parser_consume_token (parser
);
853 parser
->error
= false;
856 /* Expect to be at the end of the pragma directive and consume an
857 end of line marker. */
860 c_parser_skip_to_pragma_eol (c_parser
*parser
)
862 gcc_assert (parser
->in_pragma
);
863 parser
->in_pragma
= false;
865 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
868 c_token
*token
= c_parser_peek_token (parser
);
869 if (token
->type
== CPP_EOF
)
871 if (token
->type
== CPP_PRAGMA_EOL
)
873 c_parser_consume_token (parser
);
876 c_parser_consume_token (parser
);
879 parser
->error
= false;
882 /* Save the warning flags which are controlled by __extension__. */
885 disable_extension_diagnostics (void)
888 | (warn_pointer_arith
<< 1)
889 | (warn_traditional
<< 2)
892 warn_pointer_arith
= 0;
893 warn_traditional
= 0;
898 /* Restore the warning flags which are controlled by __extension__.
899 FLAGS is the return value from disable_extension_diagnostics. */
902 restore_extension_diagnostics (int flags
)
904 pedantic
= flags
& 1;
905 warn_pointer_arith
= (flags
>> 1) & 1;
906 warn_traditional
= (flags
>> 2) & 1;
907 flag_iso
= (flags
>> 3) & 1;
910 /* Possibly kinds of declarator to parse. */
911 typedef enum c_dtr_syn
{
912 /* A normal declarator with an identifier. */
914 /* An abstract declarator (maybe empty). */
916 /* A parameter declarator: may be either, but after a type name does
917 not redeclare a typedef name as an identifier if it can
918 alternatively be interpreted as a typedef name; see DR#009,
919 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
920 following DR#249. For example, given a typedef T, "int T" and
921 "int *T" are valid parameter declarations redeclaring T, while
922 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
923 abstract declarators rather than involving redundant parentheses;
924 the same applies with attributes inside the parentheses before
929 static void c_parser_external_declaration (c_parser
*);
930 static void c_parser_asm_definition (c_parser
*);
931 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
932 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
934 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
935 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
936 static tree
c_parser_struct_declaration (c_parser
*);
937 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
938 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
940 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
942 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
944 struct c_declarator
*);
945 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
946 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
947 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
948 static tree
c_parser_simple_asm_expr (c_parser
*);
949 static tree
c_parser_attributes (c_parser
*);
950 static struct c_type_name
*c_parser_type_name (c_parser
*);
951 static struct c_expr
c_parser_initializer (c_parser
*);
952 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
953 static void c_parser_initelt (c_parser
*);
954 static void c_parser_initval (c_parser
*, struct c_expr
*);
955 static tree
c_parser_compound_statement (c_parser
*);
956 static void c_parser_compound_statement_nostart (c_parser
*);
957 static void c_parser_label (c_parser
*);
958 static void c_parser_statement (c_parser
*);
959 static void c_parser_statement_after_labels (c_parser
*);
960 static void c_parser_if_statement (c_parser
*);
961 static void c_parser_switch_statement (c_parser
*);
962 static void c_parser_while_statement (c_parser
*);
963 static void c_parser_do_statement (c_parser
*);
964 static void c_parser_for_statement (c_parser
*);
965 static tree
c_parser_asm_statement (c_parser
*);
966 static tree
c_parser_asm_operands (c_parser
*, bool);
967 static tree
c_parser_asm_clobbers (c_parser
*);
968 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
969 static struct c_expr
c_parser_conditional_expression (c_parser
*,
971 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
972 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
973 static struct c_expr
c_parser_unary_expression (c_parser
*);
974 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
975 static struct c_expr
c_parser_alignof_expression (c_parser
*);
976 static struct c_expr
c_parser_postfix_expression (c_parser
*);
977 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
978 struct c_type_name
*);
979 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
981 static struct c_expr
c_parser_expression (c_parser
*);
982 static struct c_expr
c_parser_expression_conv (c_parser
*);
983 static tree
c_parser_expr_list (c_parser
*, bool);
985 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
986 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
988 /* These Objective-C parser functions are only ever called when
989 compiling Objective-C. */
990 static void c_parser_objc_class_definition (c_parser
*);
991 static void c_parser_objc_class_instance_variables (c_parser
*);
992 static void c_parser_objc_class_declaration (c_parser
*);
993 static void c_parser_objc_alias_declaration (c_parser
*);
994 static void c_parser_objc_protocol_definition (c_parser
*);
995 static enum tree_code
c_parser_objc_method_type (c_parser
*);
996 static void c_parser_objc_method_definition (c_parser
*);
997 static void c_parser_objc_methodprotolist (c_parser
*);
998 static void c_parser_objc_methodproto (c_parser
*);
999 static tree
c_parser_objc_method_decl (c_parser
*);
1000 static tree
c_parser_objc_type_name (c_parser
*);
1001 static tree
c_parser_objc_protocol_refs (c_parser
*);
1002 static void c_parser_objc_try_catch_statement (c_parser
*);
1003 static void c_parser_objc_synchronized_statement (c_parser
*);
1004 static tree
c_parser_objc_selector (c_parser
*);
1005 static tree
c_parser_objc_selector_arg (c_parser
*);
1006 static tree
c_parser_objc_receiver (c_parser
*);
1007 static tree
c_parser_objc_message_args (c_parser
*);
1008 static tree
c_parser_objc_keywordexpr (c_parser
*);
1010 /* Parse a translation unit (C90 6.7, C99 6.9).
1013 external-declarations
1015 external-declarations:
1016 external-declaration
1017 external-declarations external-declaration
1026 c_parser_translation_unit (c_parser
*parser
)
1028 if (c_parser_next_token_is (parser
, CPP_EOF
))
1031 pedwarn ("ISO C forbids an empty source file");
1035 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1039 c_parser_external_declaration (parser
);
1040 obstack_free (&parser_obstack
, obstack_position
);
1042 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1046 /* Parse an external declaration (C90 6.7, C99 6.9).
1048 external-declaration:
1054 external-declaration:
1057 __extension__ external-declaration
1061 external-declaration:
1062 objc-class-definition
1063 objc-class-declaration
1064 objc-alias-declaration
1065 objc-protocol-definition
1066 objc-method-definition
1071 c_parser_external_declaration (c_parser
*parser
)
1074 switch (c_parser_peek_token (parser
)->type
)
1077 switch (c_parser_peek_token (parser
)->keyword
)
1080 ext
= disable_extension_diagnostics ();
1081 c_parser_consume_token (parser
);
1082 c_parser_external_declaration (parser
);
1083 restore_extension_diagnostics (ext
);
1086 c_parser_asm_definition (parser
);
1088 case RID_AT_INTERFACE
:
1089 case RID_AT_IMPLEMENTATION
:
1090 gcc_assert (c_dialect_objc ());
1091 c_parser_objc_class_definition (parser
);
1094 gcc_assert (c_dialect_objc ());
1095 c_parser_objc_class_declaration (parser
);
1098 gcc_assert (c_dialect_objc ());
1099 c_parser_objc_alias_declaration (parser
);
1101 case RID_AT_PROTOCOL
:
1102 gcc_assert (c_dialect_objc ());
1103 c_parser_objc_protocol_definition (parser
);
1106 gcc_assert (c_dialect_objc ());
1107 c_parser_consume_token (parser
);
1108 objc_finish_implementation ();
1116 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1117 c_parser_consume_token (parser
);
1120 c_parser_pragma (parser
, pragma_external
);
1124 if (c_dialect_objc ())
1126 c_parser_objc_method_definition (parser
);
1129 /* Else fall through, and yield a syntax error trying to parse
1130 as a declaration or function definition. */
1133 /* A declaration or a function definition. We can only tell
1134 which after parsing the declaration specifiers, if any, and
1135 the first declarator. */
1136 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1142 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1143 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1144 accepted; otherwise (old-style parameter declarations) only other
1145 declarations are accepted. If NESTED is true, we are inside a
1146 function or parsing old-style parameter declarations; any functions
1147 encountered are nested functions and declaration specifiers are
1148 required; otherwise we are at top level and functions are normal
1149 functions and declaration specifiers may be optional. If EMPTY_OK
1150 is true, empty declarations are OK (subject to all other
1151 constraints); otherwise (old-style parameter declarations) they are
1152 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1153 may start with attributes; otherwise they may not.
1156 declaration-specifiers init-declarator-list[opt] ;
1158 function-definition:
1159 declaration-specifiers[opt] declarator declaration-list[opt]
1164 declaration-list declaration
1166 init-declarator-list:
1168 init-declarator-list , init-declarator
1171 declarator simple-asm-expr[opt] attributes[opt]
1172 declarator simple-asm-expr[opt] attributes[opt] = initializer
1176 nested-function-definition:
1177 declaration-specifiers declarator declaration-list[opt]
1180 The simple-asm-expr and attributes are GNU extensions.
1182 This function does not handle __extension__; that is handled in its
1183 callers. ??? Following the old parser, __extension__ may start
1184 external declarations, declarations in functions and declarations
1185 at the start of "for" loops, but not old-style parameter
1188 C99 requires declaration specifiers in a function definition; the
1189 absence is diagnosed through the diagnosis of implicit int. In GNU
1190 C we also allow but diagnose declarations without declaration
1191 specifiers, but only at top level (elsewhere they conflict with
1195 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1196 bool nested
, bool start_attr_ok
)
1198 struct c_declspecs
*specs
;
1200 tree all_prefix_attrs
;
1201 bool diagnosed_no_specs
= false;
1203 specs
= build_null_declspecs ();
1204 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1207 c_parser_skip_to_end_of_block_or_statement (parser
);
1210 if (nested
&& !specs
->declspecs_seen_p
)
1212 c_parser_error (parser
, "expected declaration specifiers");
1213 c_parser_skip_to_end_of_block_or_statement (parser
);
1216 finish_declspecs (specs
);
1217 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1223 shadow_tag_warned (specs
, 1);
1224 pedwarn ("empty declaration");
1226 c_parser_consume_token (parser
);
1229 pending_xref_error ();
1230 prefix_attrs
= specs
->attrs
;
1231 all_prefix_attrs
= prefix_attrs
;
1232 specs
->attrs
= NULL_TREE
;
1235 struct c_declarator
*declarator
;
1238 /* Declaring either one or more declarators (in which case we
1239 should diagnose if there were no declaration specifiers) or a
1240 function definition (in which case the diagnostic for
1241 implicit int suffices). */
1242 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1243 C_DTR_NORMAL
, &dummy
);
1244 if (declarator
== NULL
)
1246 c_parser_skip_to_end_of_block_or_statement (parser
);
1249 if (c_parser_next_token_is (parser
, CPP_EQ
)
1250 || c_parser_next_token_is (parser
, CPP_COMMA
)
1251 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1252 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1253 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1255 tree asm_name
= NULL_TREE
;
1256 tree postfix_attrs
= NULL_TREE
;
1257 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1259 diagnosed_no_specs
= true;
1260 pedwarn ("data definition has no type or storage class");
1262 /* Having seen a data definition, there cannot now be a
1263 function definition. */
1265 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1266 asm_name
= c_parser_simple_asm_expr (parser
);
1267 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1268 postfix_attrs
= c_parser_attributes (parser
);
1269 if (c_parser_next_token_is (parser
, CPP_EQ
))
1273 c_parser_consume_token (parser
);
1274 /* The declaration of the variable is in effect while
1275 its initializer is parsed. */
1276 d
= start_decl (declarator
, specs
, true,
1277 chainon (postfix_attrs
, all_prefix_attrs
));
1279 d
= error_mark_node
;
1280 start_init (d
, asm_name
, global_bindings_p ());
1281 init
= c_parser_initializer (parser
);
1283 if (d
!= error_mark_node
)
1285 maybe_warn_string_init (TREE_TYPE (d
), init
);
1286 finish_decl (d
, init
.value
, asm_name
);
1291 tree d
= start_decl (declarator
, specs
, false,
1292 chainon (postfix_attrs
,
1295 finish_decl (d
, NULL_TREE
, asm_name
);
1297 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1299 c_parser_consume_token (parser
);
1300 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1301 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1304 all_prefix_attrs
= prefix_attrs
;
1307 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1309 c_parser_consume_token (parser
);
1314 c_parser_error (parser
, "expected %<,%> or %<;%>");
1315 c_parser_skip_to_end_of_block_or_statement (parser
);
1321 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1322 "%<asm%> or %<__attribute__%>");
1323 c_parser_skip_to_end_of_block_or_statement (parser
);
1326 /* Function definition (nested or otherwise). */
1330 pedwarn ("ISO C forbids nested functions");
1331 push_function_context ();
1333 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1335 /* This can appear in many cases looking nothing like a
1336 function definition, so we don't give a more specific
1337 error suggesting there was one. */
1338 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1339 "or %<__attribute__%>");
1341 pop_function_context ();
1344 /* Parse old-style parameter declarations. ??? Attributes are
1345 not allowed to start declaration specifiers here because of a
1346 syntax conflict between a function declaration with attribute
1347 suffix and a function definition with an attribute prefix on
1348 first old-style parameter declaration. Following the old
1349 parser, they are not accepted on subsequent old-style
1350 parameter declarations either. However, there is no
1351 ambiguity after the first declaration, nor indeed on the
1352 first as long as we don't allow postfix attributes after a
1353 declarator with a nonempty identifier list in a definition;
1354 and postfix attributes have never been accepted here in
1355 function definitions either. */
1356 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1357 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1358 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1359 DECL_SOURCE_LOCATION (current_function_decl
)
1360 = c_parser_peek_token (parser
)->location
;
1361 store_parm_decls ();
1362 fnbody
= c_parser_compound_statement (parser
);
1365 tree decl
= current_function_decl
;
1368 pop_function_context ();
1369 add_stmt (build_stmt (DECL_EXPR
, decl
));
1380 /* Parse an asm-definition (asm() outside a function body). This is a
1388 c_parser_asm_definition (c_parser
*parser
)
1390 tree asm_str
= c_parser_simple_asm_expr (parser
);
1392 cgraph_add_asm_node (asm_str
);
1393 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1396 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1397 6.7), adding them to SPECS (which may already include some).
1398 Storage class specifiers are accepted iff SCSPEC_OK; type
1399 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1400 the start iff START_ATTR_OK.
1402 declaration-specifiers:
1403 storage-class-specifier declaration-specifiers[opt]
1404 type-specifier declaration-specifiers[opt]
1405 type-qualifier declaration-specifiers[opt]
1406 function-specifier declaration-specifiers[opt]
1408 Function specifiers (inline) are from C99, and are currently
1409 handled as storage class specifiers, as is __thread.
1411 C90 6.5.1, C99 6.7.1:
1412 storage-class-specifier:
1423 C90 6.5.2, C99 6.7.2:
1436 [_Imaginary removed in C99 TC2]
1437 struct-or-union-specifier
1441 (_Bool and _Complex are new in C99.)
1443 C90 6.5.3, C99 6.7.3:
1450 (restrict is new in C99.)
1454 declaration-specifiers:
1455 attributes declaration-specifiers[opt]
1457 storage-class-specifier:
1469 class-name objc-protocol-refs[opt]
1470 typedef-name objc-protocol-refs
1475 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1476 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1478 bool attrs_ok
= start_attr_ok
;
1479 bool seen_type
= specs
->type_seen_p
;
1480 while (c_parser_next_token_is (parser
, CPP_NAME
)
1481 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1482 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1484 struct c_typespec t
;
1486 if (c_parser_next_token_is (parser
, CPP_NAME
))
1488 tree value
= c_parser_peek_token (parser
)->value
;
1489 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1490 /* This finishes the specifiers unless a type name is OK, it
1491 is declared as a type name and a type name hasn't yet
1493 if (!typespec_ok
|| seen_type
1494 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1496 c_parser_consume_token (parser
);
1499 if (kind
== C_ID_TYPENAME
1500 && (!c_dialect_objc ()
1501 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1503 t
.kind
= ctsk_typedef
;
1504 /* For a typedef name, record the meaning, not the name.
1505 In case of 'foo foo, bar;'. */
1506 t
.spec
= lookup_name (value
);
1510 tree proto
= NULL_TREE
;
1511 gcc_assert (c_dialect_objc ());
1513 if (c_parser_next_token_is (parser
, CPP_LESS
))
1514 proto
= c_parser_objc_protocol_refs (parser
);
1515 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1517 declspecs_add_type (specs
, t
);
1520 if (c_parser_next_token_is (parser
, CPP_LESS
))
1522 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1523 nisse@lysator.liu.se. */
1525 gcc_assert (c_dialect_objc ());
1526 if (!typespec_ok
|| seen_type
)
1528 proto
= c_parser_objc_protocol_refs (parser
);
1530 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1531 declspecs_add_type (specs
, t
);
1534 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1535 switch (c_parser_peek_token (parser
)->keyword
)
1547 /* TODO: Distinguish between function specifiers (inline)
1548 and storage class specifiers, either here or in
1549 declspecs_add_scspec. */
1550 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1551 c_parser_consume_token (parser
);
1571 OBJC_NEED_RAW_IDENTIFIER (1);
1572 t
.kind
= ctsk_resword
;
1573 t
.spec
= c_parser_peek_token (parser
)->value
;
1574 declspecs_add_type (specs
, t
);
1575 c_parser_consume_token (parser
);
1582 t
= c_parser_enum_specifier (parser
);
1583 declspecs_add_type (specs
, t
);
1591 t
= c_parser_struct_or_union_specifier (parser
);
1592 declspecs_add_type (specs
, t
);
1595 /* ??? The old parser rejected typeof after other type
1596 specifiers, but is a syntax error the best way of
1598 if (!typespec_ok
|| seen_type
)
1602 t
= c_parser_typeof_specifier (parser
);
1603 declspecs_add_type (specs
, t
);
1609 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1610 c_parser_consume_token (parser
);
1615 attrs
= c_parser_attributes (parser
);
1616 declspecs_add_attrs (specs
, attrs
);
1625 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1628 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1629 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1630 enum attributes[opt] identifier
1632 The form with trailing comma is new in C99. The forms with
1633 attributes are GNU extensions. In GNU C, we accept any expression
1634 without commas in the syntax (assignment expressions, not just
1635 conditional expressions); assignment expressions will be diagnosed
1640 enumerator-list , enumerator
1643 enumeration-constant
1644 enumeration-constant = constant-expression
1647 static struct c_typespec
1648 c_parser_enum_specifier (c_parser
*parser
)
1650 struct c_typespec ret
;
1652 tree ident
= NULL_TREE
;
1653 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1654 c_parser_consume_token (parser
);
1655 attrs
= c_parser_attributes (parser
);
1656 if (c_parser_next_token_is (parser
, CPP_NAME
))
1658 ident
= c_parser_peek_token (parser
)->value
;
1659 c_parser_consume_token (parser
);
1661 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1663 /* Parse an enum definition. */
1664 tree type
= start_enum (ident
);
1666 /* We chain the enumerators in reverse order, then put them in
1667 forward order at the end. */
1668 tree values
= NULL_TREE
;
1669 c_parser_consume_token (parser
);
1676 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1678 c_parser_error (parser
, "expected identifier");
1679 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1680 values
= error_mark_node
;
1683 enum_id
= c_parser_peek_token (parser
)->value
;
1684 c_parser_consume_token (parser
);
1685 if (c_parser_next_token_is (parser
, CPP_EQ
))
1687 c_parser_consume_token (parser
);
1688 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1691 enum_value
= NULL_TREE
;
1692 enum_decl
= build_enumerator (enum_id
, enum_value
);
1693 TREE_CHAIN (enum_decl
) = values
;
1696 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1699 c_parser_consume_token (parser
);
1701 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1703 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1704 pedwarn ("comma at end of enumerator list");
1705 c_parser_consume_token (parser
);
1710 c_parser_error (parser
, "expected %<,%> or %<}%>");
1711 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1712 values
= error_mark_node
;
1716 postfix_attrs
= c_parser_attributes (parser
);
1717 ret
.spec
= finish_enum (type
, nreverse (values
),
1718 chainon (attrs
, postfix_attrs
));
1719 ret
.kind
= ctsk_tagdef
;
1724 c_parser_error (parser
, "expected %<{%>");
1725 ret
.spec
= error_mark_node
;
1726 ret
.kind
= ctsk_tagref
;
1729 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1730 /* In ISO C, enumerated types can be referred to only if already
1732 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1733 pedwarn ("ISO C forbids forward references to %<enum%> types");
1737 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1739 struct-or-union-specifier:
1740 struct-or-union attributes[opt] identifier[opt]
1741 { struct-contents } attributes[opt]
1742 struct-or-union attributes[opt] identifier
1745 struct-declaration-list
1747 struct-declaration-list:
1748 struct-declaration ;
1749 struct-declaration-list struct-declaration ;
1756 struct-declaration-list struct-declaration
1758 struct-declaration-list:
1759 struct-declaration-list ;
1762 (Note that in the syntax here, unlike that in ISO C, the semicolons
1763 are included here rather than in struct-declaration, in order to
1764 describe the syntax with extra semicolons and missing semicolon at
1769 struct-declaration-list:
1770 @defs ( class-name )
1772 (Note this does not include a trailing semicolon, but can be
1773 followed by further declarations, and gets a pedwarn-if-pedantic
1774 when followed by a semicolon.) */
1776 static struct c_typespec
1777 c_parser_struct_or_union_specifier (c_parser
*parser
)
1779 struct c_typespec ret
;
1781 tree ident
= NULL_TREE
;
1782 enum tree_code code
;
1783 switch (c_parser_peek_token (parser
)->keyword
)
1794 c_parser_consume_token (parser
);
1795 attrs
= c_parser_attributes (parser
);
1796 if (c_parser_next_token_is (parser
, CPP_NAME
))
1798 ident
= c_parser_peek_token (parser
)->value
;
1799 c_parser_consume_token (parser
);
1801 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1803 /* Parse a struct or union definition. Start the scope of the
1804 tag before parsing components. */
1805 tree type
= start_struct (code
, ident
);
1807 /* We chain the components in reverse order, then put them in
1808 forward order at the end. Each struct-declaration may
1809 declare multiple components (comma-separated), so we must use
1810 chainon to join them, although when parsing each
1811 struct-declaration we can use TREE_CHAIN directly.
1813 The theory behind all this is that there will be more
1814 semicolon separated fields than comma separated fields, and
1815 so we'll be minimizing the number of node traversals required
1817 tree contents
= NULL_TREE
;
1818 c_parser_consume_token (parser
);
1819 /* Handle the Objective-C @defs construct,
1820 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1821 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1824 gcc_assert (c_dialect_objc ());
1825 c_parser_consume_token (parser
);
1826 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1828 if (c_parser_next_token_is (parser
, CPP_NAME
)
1829 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1831 name
= c_parser_peek_token (parser
)->value
;
1832 c_parser_consume_token (parser
);
1836 c_parser_error (parser
, "expected class name");
1837 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1840 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1842 contents
= nreverse (objc_get_class_ivars (name
));
1845 /* Parse the struct-declarations and semicolons. Problems with
1846 semicolons are diagnosed here; empty structures are diagnosed
1851 /* Parse any stray semicolon. */
1852 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1855 pedwarn ("extra semicolon in struct or union specified");
1856 c_parser_consume_token (parser
);
1859 /* Stop if at the end of the struct or union contents. */
1860 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1862 c_parser_consume_token (parser
);
1865 /* Accept #pragmas at struct scope. */
1866 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1868 c_parser_pragma (parser
, pragma_external
);
1871 /* Parse some comma-separated declarations, but not the
1872 trailing semicolon if any. */
1873 decls
= c_parser_struct_declaration (parser
);
1874 contents
= chainon (decls
, contents
);
1875 /* If no semicolon follows, either we have a parse error or
1876 are at the end of the struct or union and should
1878 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1879 c_parser_consume_token (parser
);
1882 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1883 pedwarn ("no semicolon at end of struct or union");
1886 c_parser_error (parser
, "expected %<;%>");
1887 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1892 postfix_attrs
= c_parser_attributes (parser
);
1893 ret
.spec
= finish_struct (type
, nreverse (contents
),
1894 chainon (attrs
, postfix_attrs
));
1895 ret
.kind
= ctsk_tagdef
;
1900 c_parser_error (parser
, "expected %<{%>");
1901 ret
.spec
= error_mark_node
;
1902 ret
.kind
= ctsk_tagref
;
1905 ret
= parser_xref_tag (code
, ident
);
1909 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1910 the trailing semicolon.
1913 specifier-qualifier-list struct-declarator-list
1915 specifier-qualifier-list:
1916 type-specifier specifier-qualifier-list[opt]
1917 type-qualifier specifier-qualifier-list[opt]
1918 attributes specifier-qualifier-list[opt]
1920 struct-declarator-list:
1922 struct-declarator-list , attributes[opt] struct-declarator
1925 declarator attributes[opt]
1926 declarator[opt] : constant-expression attributes[opt]
1931 __extension__ struct-declaration
1932 specifier-qualifier-list
1934 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1935 of attributes where shown is a GNU extension. In GNU C, we accept
1936 any expression without commas in the syntax (assignment
1937 expressions, not just conditional expressions); assignment
1938 expressions will be diagnosed as non-constant. */
1941 c_parser_struct_declaration (c_parser
*parser
)
1943 struct c_declspecs
*specs
;
1945 tree all_prefix_attrs
;
1947 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1951 ext
= disable_extension_diagnostics ();
1952 c_parser_consume_token (parser
);
1953 decl
= c_parser_struct_declaration (parser
);
1954 restore_extension_diagnostics (ext
);
1957 specs
= build_null_declspecs ();
1958 c_parser_declspecs (parser
, specs
, false, true, true);
1961 if (!specs
->declspecs_seen_p
)
1963 c_parser_error (parser
, "expected specifier-qualifier-list");
1966 finish_declspecs (specs
);
1967 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1970 if (!specs
->type_seen_p
)
1973 pedwarn ("ISO C forbids member declarations with no members");
1974 shadow_tag_warned (specs
, pedantic
);
1979 /* Support for unnamed structs or unions as members of
1980 structs or unions (which is [a] useful and [b] supports
1982 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
, NULL_TREE
);
1986 pending_xref_error ();
1987 prefix_attrs
= specs
->attrs
;
1988 all_prefix_attrs
= prefix_attrs
;
1989 specs
->attrs
= NULL_TREE
;
1993 /* Declaring one or more declarators or un-named bit-fields. */
1994 struct c_declarator
*declarator
;
1996 if (c_parser_next_token_is (parser
, CPP_COLON
))
1997 declarator
= build_id_declarator (NULL_TREE
);
1999 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2000 C_DTR_NORMAL
, &dummy
);
2001 if (declarator
== NULL
)
2003 c_parser_skip_to_end_of_block_or_statement (parser
);
2006 if (c_parser_next_token_is (parser
, CPP_COLON
)
2007 || c_parser_next_token_is (parser
, CPP_COMMA
)
2008 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2009 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2010 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2012 tree postfix_attrs
= NULL_TREE
;
2013 tree width
= NULL_TREE
;
2015 if (c_parser_next_token_is (parser
, CPP_COLON
))
2017 c_parser_consume_token (parser
);
2018 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2020 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2021 postfix_attrs
= c_parser_attributes (parser
);
2022 d
= grokfield (declarator
, specs
, width
);
2023 decl_attributes (&d
, chainon (postfix_attrs
,
2024 all_prefix_attrs
), 0);
2025 TREE_CHAIN (d
) = decls
;
2027 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2028 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2031 all_prefix_attrs
= prefix_attrs
;
2032 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2033 c_parser_consume_token (parser
);
2034 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2035 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2037 /* Semicolon consumed in caller. */
2042 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2048 c_parser_error (parser
,
2049 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2050 "%<__attribute__%>");
2057 /* Parse a typeof specifier (a GNU extension).
2060 typeof ( expression )
2061 typeof ( type-name )
2064 static struct c_typespec
2065 c_parser_typeof_specifier (c_parser
*parser
)
2067 struct c_typespec ret
;
2068 ret
.kind
= ctsk_typeof
;
2069 ret
.spec
= error_mark_node
;
2070 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2071 c_parser_consume_token (parser
);
2074 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2080 if (c_parser_next_token_starts_typename (parser
))
2082 struct c_type_name
*type
= c_parser_type_name (parser
);
2087 ret
.spec
= groktypename (type
);
2088 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2093 struct c_expr expr
= c_parser_expression (parser
);
2096 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2097 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2098 error ("%<typeof%> applied to a bit-field");
2099 ret
.spec
= TREE_TYPE (expr
.value
);
2100 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2102 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2106 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2107 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2108 be redeclared; otherwise it may not. KIND indicates which kind of
2109 declarator is wanted. Returns a valid declarator except in the
2110 case of a syntax error in which case NULL is returned. *SEEN_ID is
2111 set to true if an identifier being declared is seen; this is used
2112 to diagnose bad forms of abstract array declarators and to
2113 determine whether an identifier list is syntactically permitted.
2116 pointer[opt] direct-declarator
2120 ( attributes[opt] declarator )
2121 direct-declarator array-declarator
2122 direct-declarator ( parameter-type-list )
2123 direct-declarator ( identifier-list[opt] )
2126 * type-qualifier-list[opt]
2127 * type-qualifier-list[opt] pointer
2129 type-qualifier-list:
2132 type-qualifier-list type-qualifier
2133 type-qualifier-list attributes
2135 parameter-type-list:
2137 parameter-list , ...
2140 parameter-declaration
2141 parameter-list , parameter-declaration
2143 parameter-declaration:
2144 declaration-specifiers declarator attributes[opt]
2145 declaration-specifiers abstract-declarator[opt] attributes[opt]
2149 identifier-list , identifier
2151 abstract-declarator:
2153 pointer[opt] direct-abstract-declarator
2155 direct-abstract-declarator:
2156 ( attributes[opt] abstract-declarator )
2157 direct-abstract-declarator[opt] array-declarator
2158 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2163 direct-declarator ( parameter-forward-declarations
2164 parameter-type-list[opt] )
2166 direct-abstract-declarator:
2167 direct-abstract-declarator[opt] ( parameter-forward-declarations
2168 parameter-type-list[opt] )
2170 parameter-forward-declarations:
2172 parameter-forward-declarations parameter-list ;
2174 The uses of attributes shown above are GNU extensions.
2176 Some forms of array declarator are not included in C99 in the
2177 syntax for abstract declarators; these are disallowed elsewhere.
2178 This may be a defect (DR#289).
2180 This function also accepts an omitted abstract declarator as being
2181 an abstract declarator, although not part of the formal syntax. */
2183 static struct c_declarator
*
2184 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2187 /* Parse any initial pointer part. */
2188 if (c_parser_next_token_is (parser
, CPP_MULT
))
2190 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2191 struct c_declarator
*inner
;
2192 c_parser_consume_token (parser
);
2193 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2194 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2198 return make_pointer_declarator (quals_attrs
, inner
);
2200 /* Now we have a direct declarator, direct abstract declarator or
2201 nothing (which counts as a direct abstract declarator here). */
2202 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2205 /* Parse a direct declarator or direct abstract declarator; arguments
2206 as c_parser_declarator. */
2208 static struct c_declarator
*
2209 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2212 /* The direct declarator must start with an identifier (possibly
2213 omitted) or a parenthesized declarator (possibly abstract). In
2214 an ordinary declarator, initial parentheses must start a
2215 parenthesized declarator. In an abstract declarator or parameter
2216 declarator, they could start a parenthesized declarator or a
2217 parameter list. To tell which, the open parenthesis and any
2218 following attributes must be read. If a declaration specifier
2219 follows, then it is a parameter list; if the specifier is a
2220 typedef name, there might be an ambiguity about redeclaring it,
2221 which is resolved in the direction of treating it as a typedef
2222 name. If a close parenthesis follows, it is also an empty
2223 parameter list, as the syntax does not permit empty abstract
2224 declarators. Otherwise, it is a parenthesized declarator (in
2225 which case the analysis may be repeated inside it, recursively).
2227 ??? There is an ambiguity in a parameter declaration "int
2228 (__attribute__((foo)) x)", where x is not a typedef name: it
2229 could be an abstract declarator for a function, or declare x with
2230 parentheses. The proper resolution of this ambiguity needs
2231 documenting. At present we follow an accident of the old
2232 parser's implementation, whereby the first parameter must have
2233 some declaration specifiers other than just attributes. Thus as
2234 a parameter declaration it is treated as a parenthesized
2235 parameter named x, and as an abstract declarator it is
2238 ??? Also following the old parser, attributes inside an empty
2239 parameter list are ignored, making it a list not yielding a
2240 prototype, rather than giving an error or making it have one
2241 parameter with implicit type int.
2243 ??? Also following the old parser, typedef names may be
2244 redeclared in declarators, but not Objective-C class names. */
2246 if (kind
!= C_DTR_ABSTRACT
2247 && c_parser_next_token_is (parser
, CPP_NAME
)
2249 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2250 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2252 struct c_declarator
*inner
2253 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2255 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2256 c_parser_consume_token (parser
);
2257 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2260 if (kind
!= C_DTR_NORMAL
2261 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2263 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2264 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2267 /* Either we are at the end of an abstract declarator, or we have
2270 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2273 struct c_declarator
*inner
;
2274 c_parser_consume_token (parser
);
2275 attrs
= c_parser_attributes (parser
);
2276 if (kind
!= C_DTR_NORMAL
2277 && (c_parser_next_token_starts_declspecs (parser
)
2278 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2280 struct c_arg_info
*args
2281 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2288 = build_function_declarator (args
,
2289 build_id_declarator (NULL_TREE
));
2290 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2294 /* A parenthesized declarator. */
2295 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2296 if (inner
!= NULL
&& attrs
!= NULL
)
2297 inner
= build_attrs_declarator (attrs
, inner
);
2298 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2300 c_parser_consume_token (parser
);
2304 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2308 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2315 if (kind
== C_DTR_NORMAL
)
2317 c_parser_error (parser
, "expected identifier or %<(%>");
2321 return build_id_declarator (NULL_TREE
);
2325 /* Parse part of a direct declarator or direct abstract declarator,
2326 given that some (in INNER) has already been parsed; ID_PRESENT is
2327 true if an identifier is present, false for an abstract
2330 static struct c_declarator
*
2331 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2332 struct c_declarator
*inner
)
2334 /* Parse a sequence of array declarators and parameter lists. */
2335 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2337 struct c_declarator
*declarator
;
2338 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2342 c_parser_consume_token (parser
);
2343 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2344 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2346 c_parser_consume_token (parser
);
2347 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2348 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2349 if (!quals_attrs
->declspecs_seen_p
)
2351 /* If "static" is present, there must be an array dimension.
2352 Otherwise, there may be a dimension, "*", or no
2357 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2361 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2366 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2368 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2372 c_parser_consume_token (parser
);
2377 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2383 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2386 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2387 c_parser_consume_token (parser
);
2390 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2394 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2396 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2397 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2399 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2402 struct c_arg_info
*args
;
2403 c_parser_consume_token (parser
);
2404 attrs
= c_parser_attributes (parser
);
2405 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2410 inner
= build_function_declarator (args
, inner
);
2411 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2417 /* Parse a parameter list or identifier list, including the closing
2418 parenthesis but not the opening one. ATTRS are the attributes at
2419 the start of the list. ID_LIST_OK is true if an identifier list is
2420 acceptable; such a list must not have attributes at the start. */
2422 static struct c_arg_info
*
2423 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2426 declare_parm_level ();
2427 /* If the list starts with an identifier, it is an identifier list.
2428 Otherwise, it is either a prototype list or an empty list. */
2431 && c_parser_next_token_is (parser
, CPP_NAME
)
2432 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2434 tree list
= NULL_TREE
, *nextp
= &list
;
2435 while (c_parser_next_token_is (parser
, CPP_NAME
)
2436 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2438 *nextp
= build_tree_list (NULL_TREE
,
2439 c_parser_peek_token (parser
)->value
);
2440 nextp
= & TREE_CHAIN (*nextp
);
2441 c_parser_consume_token (parser
);
2442 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2444 c_parser_consume_token (parser
);
2445 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2447 c_parser_error (parser
, "expected identifier");
2451 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2453 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2458 c_parser_consume_token (parser
);
2464 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2472 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2478 /* Parse a parameter list (possibly empty), including the closing
2479 parenthesis but not the opening one. ATTRS are the attributes at
2480 the start of the list. */
2482 static struct c_arg_info
*
2483 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2485 bool good_parm
= false;
2486 /* ??? Following the old parser, forward parameter declarations may
2487 use abstract declarators, and if no real parameter declarations
2488 follow the forward declarations then this is not diagnosed. Also
2489 note as above that attributes are ignored as the only contents of
2490 the parentheses, or as the only contents after forward
2492 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2494 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2499 c_parser_consume_token (parser
);
2502 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2504 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2508 /* Suppress -Wold-style-definition for this case. */
2509 ret
->types
= error_mark_node
;
2510 error ("ISO C requires a named argument before %<...%>");
2511 c_parser_consume_token (parser
);
2512 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2514 c_parser_consume_token (parser
);
2519 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2524 /* Nonempty list of parameters, either terminated with semicolon
2525 (forward declarations; recurse) or with close parenthesis (normal
2526 function) or with ", ... )" (variadic function). */
2529 /* Parse a parameter. */
2530 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2535 push_parm_decl (parm
);
2537 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2540 c_parser_consume_token (parser
);
2541 mark_forward_parm_decls ();
2542 new_attrs
= c_parser_attributes (parser
);
2543 return c_parser_parms_list_declarator (parser
, new_attrs
);
2545 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2547 c_parser_consume_token (parser
);
2549 return get_parm_info (false);
2552 struct c_arg_info
*ret
2553 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2561 if (!c_parser_require (parser
, CPP_COMMA
,
2562 "expected %<;%>, %<,%> or %<)%>"))
2564 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2567 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2569 c_parser_consume_token (parser
);
2570 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2572 c_parser_consume_token (parser
);
2574 return get_parm_info (true);
2577 struct c_arg_info
*ret
2578 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2588 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2596 /* Parse a parameter declaration. ATTRS are the attributes at the
2597 start of the declaration if it is the first parameter. */
2599 static struct c_parm
*
2600 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2602 struct c_declspecs
*specs
;
2603 struct c_declarator
*declarator
;
2605 tree postfix_attrs
= NULL_TREE
;
2607 if (!c_parser_next_token_starts_declspecs (parser
))
2609 /* ??? In some Objective-C cases '...' isn't applicable so there
2610 should be a different message. */
2611 c_parser_error (parser
,
2612 "expected declaration specifiers or %<...%>");
2613 c_parser_skip_to_end_of_parameter (parser
);
2616 specs
= build_null_declspecs ();
2619 declspecs_add_attrs (specs
, attrs
);
2622 c_parser_declspecs (parser
, specs
, true, true, true);
2623 finish_declspecs (specs
);
2624 pending_xref_error ();
2625 prefix_attrs
= specs
->attrs
;
2626 specs
->attrs
= NULL_TREE
;
2627 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2628 C_DTR_PARM
, &dummy
);
2629 if (declarator
== NULL
)
2631 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2634 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2635 postfix_attrs
= c_parser_attributes (parser
);
2636 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2640 /* Parse a string literal in an asm expression. It should not be
2641 translated, and wide string literals are an error although
2642 permitted by the syntax. This is a GNU extension.
2647 ??? At present, following the old parser, the caller needs to have
2648 set c_lex_string_translate to 0. It would be better to follow the
2649 C++ parser rather than using the c_lex_string_translate kludge. */
2652 c_parser_asm_string_literal (c_parser
*parser
)
2655 if (c_parser_next_token_is (parser
, CPP_STRING
))
2657 str
= c_parser_peek_token (parser
)->value
;
2658 c_parser_consume_token (parser
);
2660 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2662 error ("wide string literal in %<asm%>");
2663 str
= build_string (1, "");
2664 c_parser_consume_token (parser
);
2668 c_parser_error (parser
, "expected string literal");
2674 /* Parse a simple asm expression. This is used in restricted
2675 contexts, where a full expression with inputs and outputs does not
2676 make sense. This is a GNU extension.
2679 asm ( asm-string-literal )
2683 c_parser_simple_asm_expr (c_parser
*parser
)
2686 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2687 /* ??? Follow the C++ parser rather than using the
2688 c_lex_string_translate kludge. */
2689 c_lex_string_translate
= 0;
2690 c_parser_consume_token (parser
);
2691 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2693 c_lex_string_translate
= 1;
2696 str
= c_parser_asm_string_literal (parser
);
2697 c_lex_string_translate
= 1;
2698 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2700 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2706 /* Parse (possibly empty) attributes. This is a GNU extension.
2710 attributes attribute
2713 __attribute__ ( ( attribute-list ) )
2717 attribute_list , attrib
2722 any-word ( identifier )
2723 any-word ( identifier , nonempty-expr-list )
2724 any-word ( expr-list )
2726 where the "identifier" must not be declared as a type, and
2727 "any-word" may be any identifier (including one declared as a
2728 type), a reserved word storage class specifier, type specifier or
2729 type qualifier. ??? This still leaves out most reserved keywords
2730 (following the old parser), shouldn't we include them, and why not
2731 allow identifiers declared as types to start the arguments? */
2734 c_parser_attributes (c_parser
*parser
)
2736 tree attrs
= NULL_TREE
;
2737 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2739 /* ??? Follow the C++ parser rather than using the
2740 c_lex_string_translate kludge. */
2741 c_lex_string_translate
= 0;
2742 c_parser_consume_token (parser
);
2743 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2745 c_lex_string_translate
= 1;
2748 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2750 c_lex_string_translate
= 1;
2751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2754 /* Parse the attribute list. */
2755 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2756 || c_parser_next_token_is (parser
, CPP_NAME
)
2757 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2759 tree attr
, attr_name
, attr_args
;
2760 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2762 c_parser_consume_token (parser
);
2765 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2767 /* ??? See comment above about what keywords are
2770 switch (c_parser_peek_token (parser
)->keyword
)
2805 attr_name
= c_parser_peek_token (parser
)->value
;
2806 c_parser_consume_token (parser
);
2807 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2809 attr
= build_tree_list (attr_name
, NULL_TREE
);
2810 attrs
= chainon (attrs
, attr
);
2813 c_parser_consume_token (parser
);
2814 /* Parse the attribute contents. If they start with an
2815 identifier which is followed by a comma or close
2816 parenthesis, then the arguments start with that
2817 identifier; otherwise they are an expression list. */
2818 if (c_parser_next_token_is (parser
, CPP_NAME
)
2819 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2820 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2821 || (c_parser_peek_2nd_token (parser
)->type
2822 == CPP_CLOSE_PAREN
)))
2824 tree arg1
= c_parser_peek_token (parser
)->value
;
2825 c_parser_consume_token (parser
);
2826 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2827 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2830 c_parser_consume_token (parser
);
2831 attr_args
= tree_cons (NULL_TREE
, arg1
,
2832 c_parser_expr_list (parser
, false));
2837 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2838 attr_args
= NULL_TREE
;
2840 attr_args
= c_parser_expr_list (parser
, false);
2842 attr
= build_tree_list (attr_name
, attr_args
);
2843 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2844 c_parser_consume_token (parser
);
2847 c_lex_string_translate
= 1;
2848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2852 attrs
= chainon (attrs
, attr
);
2854 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2855 c_parser_consume_token (parser
);
2858 c_lex_string_translate
= 1;
2859 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2863 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2864 c_parser_consume_token (parser
);
2867 c_lex_string_translate
= 1;
2868 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2872 c_lex_string_translate
= 1;
2877 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2880 specifier-qualifier-list abstract-declarator[opt]
2883 static struct c_type_name
*
2884 c_parser_type_name (c_parser
*parser
)
2886 struct c_declspecs
*specs
= build_null_declspecs ();
2887 struct c_declarator
*declarator
;
2888 struct c_type_name
*ret
;
2890 c_parser_declspecs (parser
, specs
, false, true, true);
2891 if (!specs
->declspecs_seen_p
)
2893 c_parser_error (parser
, "expected specifier-qualifier-list");
2896 pending_xref_error ();
2897 finish_declspecs (specs
);
2898 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2899 C_DTR_ABSTRACT
, &dummy
);
2900 if (declarator
== NULL
)
2902 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2904 ret
->declarator
= declarator
;
2908 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2911 assignment-expression
2912 { initializer-list }
2913 { initializer-list , }
2916 designation[opt] initializer
2917 initializer-list , designation[opt] initializer
2924 designator-list designator
2931 [ constant-expression ]
2943 [ constant-expression ... constant-expression ]
2945 Any expression without commas is accepted in the syntax for the
2946 constant-expressions, with non-constant expressions rejected later.
2948 This function is only used for top-level initializers; for nested
2949 ones, see c_parser_initval. */
2951 static struct c_expr
2952 c_parser_initializer (c_parser
*parser
)
2954 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2955 return c_parser_braced_init (parser
, NULL_TREE
, false);
2959 ret
= c_parser_expr_no_commas (parser
, NULL
);
2960 if (TREE_CODE (ret
.value
) != STRING_CST
2961 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
2962 ret
= default_function_array_conversion (ret
);
2967 /* Parse a braced initializer list. TYPE is the type specified for a
2968 compound literal, and NULL_TREE for other initializers and for
2969 nested braced lists. NESTED_P is true for nested braced lists,
2970 false for the list of a compound literal or the list that is the
2971 top-level initializer in a declaration. */
2973 static struct c_expr
2974 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
2976 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
2977 c_parser_consume_token (parser
);
2979 push_init_level (0);
2981 really_start_incremental_init (type
);
2982 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2985 pedwarn ("ISO C forbids empty initializer braces");
2989 /* Parse a non-empty initializer list, possibly with a trailing
2993 c_parser_initelt (parser
);
2996 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2997 c_parser_consume_token (parser
);
3000 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3004 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3007 ret
.value
= error_mark_node
;
3008 ret
.original_code
= ERROR_MARK
;
3009 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3012 c_parser_consume_token (parser
);
3013 return pop_init_level (0);
3016 /* Parse a nested initializer, including designators. */
3019 c_parser_initelt (c_parser
*parser
)
3021 /* Parse any designator or designator list. A single array
3022 designator may have the subsequent "=" omitted in GNU C, but a
3023 longer list or a structure member designator may not. */
3024 if (c_parser_next_token_is (parser
, CPP_NAME
)
3025 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3027 /* Old-style structure member designator. */
3028 set_init_label (c_parser_peek_token (parser
)->value
);
3030 pedwarn ("obsolete use of designated initializer with %<:%>");
3031 c_parser_consume_token (parser
);
3032 c_parser_consume_token (parser
);
3036 /* des_seen is 0 if there have been no designators, 1 if there
3037 has been a single array designator and 2 otherwise. */
3039 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3040 || c_parser_next_token_is (parser
, CPP_DOT
))
3042 int des_prev
= des_seen
;
3045 if (c_parser_next_token_is (parser
, CPP_DOT
))
3048 c_parser_consume_token (parser
);
3049 if (c_parser_next_token_is (parser
, CPP_NAME
))
3051 set_init_label (c_parser_peek_token (parser
)->value
);
3052 c_parser_consume_token (parser
);
3057 init
.value
= error_mark_node
;
3058 init
.original_code
= ERROR_MARK
;
3059 c_parser_error (parser
, "expected identifier");
3060 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3061 process_init_element (init
);
3068 /* ??? Following the old parser, [ objc-receiver
3069 objc-message-args ] is accepted as an initializer,
3070 being distinguished from a designator by what follows
3071 the first assignment expression inside the square
3072 brackets, but after a first array designator a
3073 subsequent square bracket is for Objective-C taken to
3074 start an expression, using the obsolete form of
3075 designated initializer without '=', rather than
3076 possibly being a second level of designation: in LALR
3077 terms, the '[' is shifted rather than reducing
3078 designator to designator-list. */
3079 if (des_prev
== 1 && c_dialect_objc ())
3081 des_seen
= des_prev
;
3084 if (des_prev
== 0 && c_dialect_objc ())
3086 /* This might be an array designator or an
3087 Objective-C message expression. If the former,
3088 continue parsing here; if the latter, parse the
3089 remainder of the initializer given the starting
3090 primary-expression. ??? It might make sense to
3091 distinguish when des_prev == 1 as well; see
3092 previous comment. */
3094 struct c_expr mexpr
;
3095 c_parser_consume_token (parser
);
3096 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3097 && ((c_parser_peek_token (parser
)->id_kind
3099 || (c_parser_peek_token (parser
)->id_kind
3100 == C_ID_CLASSNAME
)))
3102 /* Type name receiver. */
3103 tree id
= c_parser_peek_token (parser
)->value
;
3104 c_parser_consume_token (parser
);
3105 rec
= objc_get_class_reference (id
);
3106 goto parse_message_args
;
3108 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3109 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3110 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3111 goto array_desig_after_first
;
3112 /* Expression receiver. So far only one part
3113 without commas has been parsed; there might be
3114 more of the expression. */
3116 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3119 c_parser_consume_token (parser
);
3120 next
= c_parser_expr_no_commas (parser
, NULL
);
3121 next
= default_function_array_conversion (next
);
3122 rec
= build_compound_expr (rec
, next
.value
);
3125 /* Now parse the objc-message-args. */
3126 args
= c_parser_objc_message_args (parser
);
3127 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3130 = objc_build_message_expr (build_tree_list (rec
, args
));
3131 mexpr
.original_code
= ERROR_MARK
;
3132 /* Now parse and process the remainder of the
3133 initializer, starting with this message
3134 expression as a primary-expression. */
3135 c_parser_initval (parser
, &mexpr
);
3138 c_parser_consume_token (parser
);
3139 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3140 array_desig_after_first
:
3141 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3143 c_parser_consume_token (parser
);
3144 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3148 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3150 c_parser_consume_token (parser
);
3151 set_init_index (first
, second
);
3152 if (pedantic
&& second
)
3153 pedwarn ("ISO C forbids specifying range of "
3154 "elements to initialize");
3157 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3163 if (c_parser_next_token_is (parser
, CPP_EQ
))
3165 if (pedantic
&& !flag_isoc99
)
3166 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3167 c_parser_consume_token (parser
);
3174 pedwarn ("obsolete use of designated initializer "
3180 init
.value
= error_mark_node
;
3181 init
.original_code
= ERROR_MARK
;
3182 c_parser_error (parser
, "expected %<=%>");
3183 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3184 process_init_element (init
);
3190 c_parser_initval (parser
, NULL
);
3193 /* Parse a nested initializer; as c_parser_initializer but parses
3194 initializers within braced lists, after any designators have been
3195 applied. If AFTER is not NULL then it is an Objective-C message
3196 expression which is the primary-expression starting the
3200 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3203 gcc_assert (!after
|| c_dialect_objc ());
3204 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3205 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3208 init
= c_parser_expr_no_commas (parser
, after
);
3209 if (init
.value
!= NULL_TREE
3210 && TREE_CODE (init
.value
) != STRING_CST
3211 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3212 init
= default_function_array_conversion (init
);
3214 process_init_element (init
);
3217 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3221 { block-item-list[opt] }
3222 { label-declarations block-item-list }
3226 block-item-list block-item
3238 { label-declarations block-item-list }
3241 __extension__ nested-declaration
3242 nested-function-definition
3246 label-declarations label-declaration
3249 __label__ identifier-list ;
3251 Allowing the mixing of declarations and code is new in C99. The
3252 GNU syntax also permits (not shown above) labels at the end of
3253 compound statements, which yield an error. We don't allow labels
3254 on declarations; this might seem like a natural extension, but
3255 there would be a conflict between attributes on the label and
3256 prefix attributes on the declaration. ??? The syntax follows the
3257 old parser in requiring something after label declarations.
3258 Although they are erroneous if the labels declared aren't defined,
3259 is it useful for the syntax to be this way? */
3262 c_parser_compound_statement (c_parser
*parser
)
3265 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3266 return error_mark_node
;
3267 stmt
= c_begin_compound_stmt (true);
3268 c_parser_compound_statement_nostart (parser
);
3269 return c_end_compound_stmt (stmt
, true);
3272 /* Parse a compound statement except for the opening brace. This is
3273 used for parsing both compound statements and statement expressions
3274 (which follow different paths to handling the opening). */
3277 c_parser_compound_statement_nostart (c_parser
*parser
)
3279 bool last_stmt
= false;
3280 bool last_label
= false;
3281 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3283 c_parser_consume_token (parser
);
3286 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3288 /* Read zero or more forward-declarations for labels that nested
3289 functions can jump to. */
3290 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3292 c_parser_consume_token (parser
);
3293 /* Any identifiers, including those declared as type names,
3298 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3300 c_parser_error (parser
, "expected identifier");
3304 = declare_label (c_parser_peek_token (parser
)->value
);
3305 C_DECLARED_LABEL_FLAG (label
) = 1;
3306 add_stmt (build_stmt (DECL_EXPR
, label
));
3307 c_parser_consume_token (parser
);
3308 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3309 c_parser_consume_token (parser
);
3313 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3315 /* ??? Locating this diagnostic on the token after the
3316 declarations end follows the old parser, but it might be
3317 better to locate it where the declarations start instead. */
3319 pedwarn ("ISO C forbids label declarations");
3321 /* We must now have at least one statement, label or declaration. */
3322 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3324 c_parser_error (parser
, "expected declaration or statement");
3325 c_parser_consume_token (parser
);
3328 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3330 location_t loc
= c_parser_peek_token (parser
)->location
;
3331 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3332 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3333 || (c_parser_next_token_is (parser
, CPP_NAME
)
3334 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3338 c_parser_label (parser
);
3340 else if (!last_label
3341 && c_parser_next_token_starts_declspecs (parser
))
3344 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3346 && ((pedantic
&& !flag_isoc99
)
3347 || warn_declaration_after_statement
))
3348 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3352 else if (!last_label
3353 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3355 /* __extension__ can start a declaration, but is also an
3356 unary operator that can start an expression. Consume all
3357 but the last of a possible series of __extension__ to
3359 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3360 && (c_parser_peek_2nd_token (parser
)->keyword
3362 c_parser_consume_token (parser
);
3363 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3366 ext
= disable_extension_diagnostics ();
3367 c_parser_consume_token (parser
);
3369 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3370 /* Following the old parser, __extension__ does not
3371 disable this diagnostic. */
3372 restore_extension_diagnostics (ext
);
3374 && ((pedantic
&& !flag_isoc99
)
3375 || warn_declaration_after_statement
))
3376 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3383 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3385 /* External pragmas, and some omp pragmas, are not associated
3386 with regular c code, and so are not to be considered statements
3387 syntactically. This ensures that the user doesn't put them
3388 places that would turn into syntax errors if the directive
3390 if (c_parser_pragma (parser
, pragma_compound
))
3391 last_label
= false, last_stmt
= true;
3393 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3395 c_parser_error (parser
, "expected declaration or statement");
3403 c_parser_statement_after_labels (parser
);
3407 error ("label at end of compound statement");
3408 c_parser_consume_token (parser
);
3411 /* Parse a label (C90 6.6.1, C99 6.8.1).
3414 identifier : attributes[opt]
3415 case constant-expression :
3421 case constant-expression ... constant-expression :
3423 The use of attributes on labels is a GNU extension. The syntax in
3424 GNU C accepts any expressions without commas, non-constant
3425 expressions being rejected later. */
3428 c_parser_label (c_parser
*parser
)
3430 location_t loc1
= c_parser_peek_token (parser
)->location
;
3431 tree label
= NULL_TREE
;
3432 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3435 c_parser_consume_token (parser
);
3436 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3437 if (c_parser_next_token_is (parser
, CPP_COLON
))
3439 c_parser_consume_token (parser
);
3440 label
= do_case (exp1
, NULL_TREE
);
3442 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3444 c_parser_consume_token (parser
);
3445 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3446 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3447 label
= do_case (exp1
, exp2
);
3450 c_parser_error (parser
, "expected %<:%> or %<...%>");
3452 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3454 c_parser_consume_token (parser
);
3455 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3456 label
= do_case (NULL_TREE
, NULL_TREE
);
3460 tree name
= c_parser_peek_token (parser
)->value
;
3464 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3465 c_parser_consume_token (parser
);
3466 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3467 loc2
= c_parser_peek_token (parser
)->location
;
3468 c_parser_consume_token (parser
);
3469 attrs
= c_parser_attributes (parser
);
3470 tlab
= define_label (loc2
, name
);
3473 decl_attributes (&tlab
, attrs
, 0);
3474 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3478 SET_EXPR_LOCATION (label
, loc1
);
3481 /* Parse a statement (C90 6.6, C99 6.8).
3486 expression-statement
3494 expression-statement:
3497 selection-statement:
3501 iteration-statement:
3510 return expression[opt] ;
3523 objc-throw-statement
3524 objc-try-catch-statement
3525 objc-synchronized-statement
3527 objc-throw-statement:
3533 c_parser_statement (c_parser
*parser
)
3535 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3536 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3537 || (c_parser_next_token_is (parser
, CPP_NAME
)
3538 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3539 c_parser_label (parser
);
3540 c_parser_statement_after_labels (parser
);
3543 /* Parse a statement, other than a labeled statement. */
3546 c_parser_statement_after_labels (c_parser
*parser
)
3548 location_t loc
= c_parser_peek_token (parser
)->location
;
3549 tree stmt
= NULL_TREE
;
3550 switch (c_parser_peek_token (parser
)->type
)
3552 case CPP_OPEN_BRACE
:
3553 add_stmt (c_parser_compound_statement (parser
));
3556 switch (c_parser_peek_token (parser
)->keyword
)
3559 c_parser_if_statement (parser
);
3562 c_parser_switch_statement (parser
);
3565 c_parser_while_statement (parser
);
3568 c_parser_do_statement (parser
);
3571 c_parser_for_statement (parser
);
3574 c_parser_consume_token (parser
);
3575 if (c_parser_next_token_is (parser
, CPP_NAME
))
3577 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3578 c_parser_consume_token (parser
);
3580 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3582 c_parser_consume_token (parser
);
3583 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3586 c_parser_error (parser
, "expected identifier or %<*%>");
3587 goto expect_semicolon
;
3589 c_parser_consume_token (parser
);
3590 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3591 goto expect_semicolon
;
3593 c_parser_consume_token (parser
);
3594 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3595 goto expect_semicolon
;
3597 c_parser_consume_token (parser
);
3598 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3600 stmt
= c_finish_return (NULL_TREE
);
3601 c_parser_consume_token (parser
);
3605 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3606 goto expect_semicolon
;
3610 stmt
= c_parser_asm_statement (parser
);
3613 gcc_assert (c_dialect_objc ());
3614 c_parser_consume_token (parser
);
3615 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3617 stmt
= objc_build_throw_stmt (NULL_TREE
);
3618 c_parser_consume_token (parser
);
3623 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3624 goto expect_semicolon
;
3628 gcc_assert (c_dialect_objc ());
3629 c_parser_objc_try_catch_statement (parser
);
3631 case RID_AT_SYNCHRONIZED
:
3632 gcc_assert (c_dialect_objc ());
3633 c_parser_objc_synchronized_statement (parser
);
3640 c_parser_consume_token (parser
);
3642 case CPP_CLOSE_PAREN
:
3643 case CPP_CLOSE_SQUARE
:
3644 /* Avoid infinite loop in error recovery:
3645 c_parser_skip_until_found stops at a closing nesting
3646 delimiter without consuming it, but here we need to consume
3647 it to proceed further. */
3648 c_parser_error (parser
, "expected statement");
3649 c_parser_consume_token (parser
);
3652 c_parser_pragma (parser
, pragma_stmt
);
3656 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3658 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3661 /* Two cases cannot and do not have line numbers associated: If stmt
3662 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3663 cannot hold line numbers. But that's OK because the statement
3664 will either be changed to a MODIFY_EXPR during gimplification of
3665 the statement expr, or discarded. If stmt was compound, but
3666 without new variables, we will have skipped the creation of a
3667 BIND and will have a bare STATEMENT_LIST. But that's OK because
3668 (recursively) all of the component statements should already have
3669 line numbers assigned. ??? Can we discard no-op statements
3671 if (stmt
&& EXPR_P (stmt
))
3672 SET_EXPR_LOCATION (stmt
, loc
);
3675 /* Parse a parenthesized condition from an if, do or while statement.
3681 c_parser_paren_condition (c_parser
*parser
)
3685 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3686 return error_mark_node
;
3687 loc
= c_parser_peek_token (parser
)->location
;
3688 cond
= c_objc_common_truthvalue_conversion
3689 (c_parser_expression_conv (parser
).value
);
3691 SET_EXPR_LOCATION (cond
, loc
);
3692 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3696 /* Parse a statement which is a block in C99. */
3699 c_parser_c99_block_statement (c_parser
*parser
)
3701 tree block
= c_begin_compound_stmt (flag_isoc99
);
3702 c_parser_statement (parser
);
3703 return c_end_compound_stmt (block
, flag_isoc99
);
3706 /* Parse the body of an if statement or the else half thereof. This
3707 is just parsing a statement but (a) it is a block in C99, (b) we
3708 track whether the body is an if statement for the sake of
3709 -Wparentheses warnings, (c) we handle an empty body specially for
3710 the sake of -Wextra warnings. */
3713 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3715 tree block
= c_begin_compound_stmt (flag_isoc99
);
3716 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3717 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3718 || (c_parser_next_token_is (parser
, CPP_NAME
)
3719 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3720 c_parser_label (parser
);
3721 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3722 if (extra_warnings
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3723 add_stmt (build1 (NOP_EXPR
, NULL_TREE
, NULL_TREE
));
3724 c_parser_statement_after_labels (parser
);
3725 return c_end_compound_stmt (block
, flag_isoc99
);
3728 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3731 if ( expression ) statement
3732 if ( expression ) statement else statement
3736 c_parser_if_statement (c_parser
*parser
)
3741 bool first_if
= false, second_if
= false;
3742 tree first_body
, second_body
;
3743 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3744 c_parser_consume_token (parser
);
3745 block
= c_begin_compound_stmt (flag_isoc99
);
3746 loc
= c_parser_peek_token (parser
)->location
;
3747 cond
= c_parser_paren_condition (parser
);
3748 first_body
= c_parser_if_body (parser
, &first_if
);
3749 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3751 c_parser_consume_token (parser
);
3752 second_body
= c_parser_if_body (parser
, &second_if
);
3755 second_body
= NULL_TREE
;
3756 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3757 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3760 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3763 switch (expression) statement
3767 c_parser_switch_statement (c_parser
*parser
)
3769 tree block
, expr
, body
, save_break
;
3770 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3771 c_parser_consume_token (parser
);
3772 block
= c_begin_compound_stmt (flag_isoc99
);
3773 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3775 expr
= c_parser_expression (parser
).value
;
3776 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3779 expr
= error_mark_node
;
3780 c_start_case (expr
);
3781 save_break
= c_break_label
;
3782 c_break_label
= NULL_TREE
;
3783 body
= c_parser_c99_block_statement (parser
);
3784 c_finish_case (body
);
3786 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3787 c_break_label
= save_break
;
3788 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3791 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3794 while (expression) statement
3798 c_parser_while_statement (c_parser
*parser
)
3800 tree block
, cond
, body
, save_break
, save_cont
;
3802 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3803 c_parser_consume_token (parser
);
3804 block
= c_begin_compound_stmt (flag_isoc99
);
3805 loc
= c_parser_peek_token (parser
)->location
;
3806 cond
= c_parser_paren_condition (parser
);
3807 save_break
= c_break_label
;
3808 c_break_label
= NULL_TREE
;
3809 save_cont
= c_cont_label
;
3810 c_cont_label
= NULL_TREE
;
3811 body
= c_parser_c99_block_statement (parser
);
3812 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3813 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3814 c_break_label
= save_break
;
3815 c_cont_label
= save_cont
;
3818 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3821 do statement while ( expression ) ;
3825 c_parser_do_statement (c_parser
*parser
)
3827 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3829 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3830 c_parser_consume_token (parser
);
3831 block
= c_begin_compound_stmt (flag_isoc99
);
3832 loc
= c_parser_peek_token (parser
)->location
;
3833 save_break
= c_break_label
;
3834 c_break_label
= NULL_TREE
;
3835 save_cont
= c_cont_label
;
3836 c_cont_label
= NULL_TREE
;
3837 body
= c_parser_c99_block_statement (parser
);
3838 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3839 new_break
= c_break_label
;
3840 c_break_label
= save_break
;
3841 new_cont
= c_cont_label
;
3842 c_cont_label
= save_cont
;
3843 cond
= c_parser_paren_condition (parser
);
3844 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3845 c_parser_skip_to_end_of_block_or_statement (parser
);
3846 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3847 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3850 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3853 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3854 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3856 The form with a declaration is new in C99.
3858 ??? In accordance with the old parser, the declaration may be a
3859 nested function, which is then rejected in check_for_loop_decls,
3860 but does it make any sense for this to be included in the grammar?
3861 Note in particular that the nested function does not include a
3862 trailing ';', whereas the "declaration" production includes one.
3863 Also, can we reject bad declarations earlier and cheaper than
3864 check_for_loop_decls? */
3867 c_parser_for_statement (c_parser
*parser
)
3869 tree block
, cond
, incr
, save_break
, save_cont
, body
;
3871 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
3872 loc
= c_parser_peek_token (parser
)->location
;
3873 c_parser_consume_token (parser
);
3874 block
= c_begin_compound_stmt (flag_isoc99
);
3875 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3877 /* Parse the initialization declaration or expression. */
3878 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3880 c_parser_consume_token (parser
);
3881 c_finish_expr_stmt (NULL_TREE
);
3883 else if (c_parser_next_token_starts_declspecs (parser
))
3885 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3886 check_for_loop_decls ();
3888 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3890 /* __extension__ can start a declaration, but is also an
3891 unary operator that can start an expression. Consume all
3892 but the last of a possible series of __extension__ to
3894 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3895 && (c_parser_peek_2nd_token (parser
)->keyword
3897 c_parser_consume_token (parser
);
3898 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3901 ext
= disable_extension_diagnostics ();
3902 c_parser_consume_token (parser
);
3903 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3904 restore_extension_diagnostics (ext
);
3905 check_for_loop_decls ();
3913 c_finish_expr_stmt (c_parser_expression (parser
).value
);
3914 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3916 /* Parse the loop condition. */
3917 loc
= c_parser_peek_token (parser
)->location
;
3918 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3920 c_parser_consume_token (parser
);
3925 tree ocond
= c_parser_expression_conv (parser
).value
;
3926 cond
= c_objc_common_truthvalue_conversion (ocond
);
3928 SET_EXPR_LOCATION (cond
, loc
);
3929 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3931 /* Parse the increment expression. */
3932 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3933 incr
= c_process_expr_stmt (NULL_TREE
);
3935 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
3936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3940 cond
= error_mark_node
;
3941 incr
= error_mark_node
;
3943 save_break
= c_break_label
;
3944 c_break_label
= NULL_TREE
;
3945 save_cont
= c_cont_label
;
3946 c_cont_label
= NULL_TREE
;
3947 body
= c_parser_c99_block_statement (parser
);
3948 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
3949 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3950 c_break_label
= save_break
;
3951 c_cont_label
= save_cont
;
3954 /* Parse an asm statement, a GNU extension. This is a full-blown asm
3955 statement with inputs, outputs, clobbers, and volatile tag
3959 asm type-qualifier[opt] ( asm-argument ) ;
3963 asm-string-literal : asm-operands[opt]
3964 asm-string-literal : asm-operands[opt] : asm-operands[opt]
3965 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
3967 Qualifiers other than volatile are accepted in the syntax but
3971 c_parser_asm_statement (c_parser
*parser
)
3973 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
3975 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3976 c_parser_consume_token (parser
);
3977 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
3979 quals
= c_parser_peek_token (parser
)->value
;
3980 c_parser_consume_token (parser
);
3982 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
3983 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
3985 warning (0, "%E qualifier ignored on asm",
3986 c_parser_peek_token (parser
)->value
);
3988 c_parser_consume_token (parser
);
3992 /* ??? Follow the C++ parser rather than using the
3993 c_lex_string_translate kludge. */
3994 c_lex_string_translate
= 0;
3995 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3997 c_lex_string_translate
= 1;
4000 str
= c_parser_asm_string_literal (parser
);
4001 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4004 outputs
= NULL_TREE
;
4006 clobbers
= NULL_TREE
;
4009 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4011 c_lex_string_translate
= 1;
4012 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4016 /* Parse outputs. */
4017 if (c_parser_next_token_is (parser
, CPP_COLON
)
4018 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4019 outputs
= NULL_TREE
;
4021 outputs
= c_parser_asm_operands (parser
, false);
4022 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4025 clobbers
= NULL_TREE
;
4028 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4030 c_lex_string_translate
= 1;
4031 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4035 if (c_parser_next_token_is (parser
, CPP_COLON
)
4036 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4039 inputs
= c_parser_asm_operands (parser
, true);
4040 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4042 clobbers
= NULL_TREE
;
4045 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4047 c_lex_string_translate
= 1;
4048 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4051 /* Parse clobbers. */
4052 clobbers
= c_parser_asm_clobbers (parser
);
4054 c_lex_string_translate
= 1;
4055 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4057 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4060 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4061 c_parser_skip_to_end_of_block_or_statement (parser
);
4062 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4067 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4068 not outputs), apply the default conversion of functions and arrays
4073 asm-operands , asm-operand
4076 asm-string-literal ( expression )
4077 [ identifier ] asm-string-literal ( expression )
4081 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4083 tree list
= NULL_TREE
;
4088 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4090 c_parser_consume_token (parser
);
4091 if (c_parser_next_token_is (parser
, CPP_NAME
))
4093 tree id
= c_parser_peek_token (parser
)->value
;
4094 c_parser_consume_token (parser
);
4095 name
= build_string (IDENTIFIER_LENGTH (id
),
4096 IDENTIFIER_POINTER (id
));
4100 c_parser_error (parser
, "expected identifier");
4101 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4104 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4109 str
= c_parser_asm_string_literal (parser
);
4110 if (str
== NULL_TREE
)
4112 c_lex_string_translate
= 1;
4113 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4115 c_lex_string_translate
= 0;
4118 expr
= c_parser_expression (parser
);
4120 expr
= default_function_array_conversion (expr
);
4121 c_lex_string_translate
= 0;
4122 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4124 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4127 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4129 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4130 c_parser_consume_token (parser
);
4137 /* Parse asm clobbers, a GNU extension.
4141 asm-clobbers , asm-string-literal
4145 c_parser_asm_clobbers (c_parser
*parser
)
4147 tree list
= NULL_TREE
;
4150 tree str
= c_parser_asm_string_literal (parser
);
4152 list
= tree_cons (NULL_TREE
, str
, list
);
4155 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4156 c_parser_consume_token (parser
);
4163 /* Parse an expression other than a compound expression; that is, an
4164 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4165 NULL then it is an Objective-C message expression which is the
4166 primary-expression starting the expression as an initializer.
4168 assignment-expression:
4169 conditional-expression
4170 unary-expression assignment-operator assignment-expression
4172 assignment-operator: one of
4173 = *= /= %= += -= <<= >>= &= ^= |=
4175 In GNU C we accept any conditional expression on the LHS and
4176 diagnose the invalid lvalue rather than producing a syntax
4179 static struct c_expr
4180 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4182 struct c_expr lhs
, rhs
, ret
;
4183 enum tree_code code
;
4184 gcc_assert (!after
|| c_dialect_objc ());
4185 lhs
= c_parser_conditional_expression (parser
, after
);
4186 switch (c_parser_peek_token (parser
)->type
)
4195 code
= TRUNC_DIV_EXPR
;
4198 code
= TRUNC_MOD_EXPR
;
4213 code
= BIT_AND_EXPR
;
4216 code
= BIT_XOR_EXPR
;
4219 code
= BIT_IOR_EXPR
;
4224 c_parser_consume_token (parser
);
4225 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4226 rhs
= default_function_array_conversion (rhs
);
4227 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4228 if (code
== NOP_EXPR
)
4229 ret
.original_code
= MODIFY_EXPR
;
4232 TREE_NO_WARNING (ret
.value
) = 1;
4233 ret
.original_code
= ERROR_MARK
;
4238 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4239 is not NULL then it is an Objective-C message expression which is
4240 the primary-expression starting the expression as an initializer.
4242 conditional-expression:
4243 logical-OR-expression
4244 logical-OR-expression ? expression : conditional-expression
4248 conditional-expression:
4249 logical-OR-expression ? : conditional-expression
4252 static struct c_expr
4253 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4255 struct c_expr cond
, exp1
, exp2
, ret
;
4256 gcc_assert (!after
|| c_dialect_objc ());
4257 cond
= c_parser_binary_expression (parser
, after
);
4258 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4260 cond
= default_function_array_conversion (cond
);
4261 c_parser_consume_token (parser
);
4262 if (c_parser_next_token_is (parser
, CPP_COLON
))
4265 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4266 /* Make sure first operand is calculated only once. */
4267 exp1
.value
= save_expr (default_conversion (cond
.value
));
4268 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4269 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4274 = c_objc_common_truthvalue_conversion
4275 (default_conversion (cond
.value
));
4276 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4277 exp1
= c_parser_expression_conv (parser
);
4278 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4279 - (cond
.value
== truthvalue_false_node
));
4281 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4283 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4284 ret
.value
= error_mark_node
;
4285 ret
.original_code
= ERROR_MARK
;
4288 exp2
= c_parser_conditional_expression (parser
, NULL
);
4289 exp2
= default_function_array_conversion (exp2
);
4290 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4291 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4292 ret
.original_code
= ERROR_MARK
;
4296 /* Parse a binary expression; that is, a logical-OR-expression (C90
4297 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4298 an Objective-C message expression which is the primary-expression
4299 starting the expression as an initializer.
4301 multiplicative-expression:
4303 multiplicative-expression * cast-expression
4304 multiplicative-expression / cast-expression
4305 multiplicative-expression % cast-expression
4307 additive-expression:
4308 multiplicative-expression
4309 additive-expression + multiplicative-expression
4310 additive-expression - multiplicative-expression
4314 shift-expression << additive-expression
4315 shift-expression >> additive-expression
4317 relational-expression:
4319 relational-expression < shift-expression
4320 relational-expression > shift-expression
4321 relational-expression <= shift-expression
4322 relational-expression >= shift-expression
4324 equality-expression:
4325 relational-expression
4326 equality-expression == relational-expression
4327 equality-expression != relational-expression
4331 AND-expression & equality-expression
4333 exclusive-OR-expression:
4335 exclusive-OR-expression ^ AND-expression
4337 inclusive-OR-expression:
4338 exclusive-OR-expression
4339 inclusive-OR-expression | exclusive-OR-expression
4341 logical-AND-expression:
4342 inclusive-OR-expression
4343 logical-AND-expression && inclusive-OR-expression
4345 logical-OR-expression:
4346 logical-AND-expression
4347 logical-OR-expression || logical-AND-expression
4350 static struct c_expr
4351 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4353 /* A binary expression is parsed using operator-precedence parsing,
4354 with the operands being cast expressions. All the binary
4355 operators are left-associative. Thus a binary expression is of
4358 E0 op1 E1 op2 E2 ...
4360 which we represent on a stack. On the stack, the precedence
4361 levels are strictly increasing. When a new operator is
4362 encountered of higher precedence than that at the top of the
4363 stack, it is pushed; its LHS is the top expression, and its RHS
4364 is everything parsed until it is popped. When a new operator is
4365 encountered with precedence less than or equal to that at the top
4366 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4367 by the result of the operation until the operator at the top of
4368 the stack has lower precedence than the new operator or there is
4369 only one element on the stack; then the top expression is the LHS
4370 of the new operator. In the case of logical AND and OR
4371 expressions, we also need to adjust skip_evaluation as
4372 appropriate when the operators are pushed and popped. */
4374 /* The precedence levels, where 0 is a dummy lowest level used for
4375 the bottom of the stack. */
4391 /* The expression at this stack level. */
4393 /* The precedence of the operator on its left, PREC_NONE at the
4394 bottom of the stack. */
4396 /* The operation on its left. */
4402 switch (stack[sp].op) \
4404 case TRUTH_ANDIF_EXPR: \
4405 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4407 case TRUTH_ORIF_EXPR: \
4408 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4413 stack[sp - 1].expr \
4414 = default_function_array_conversion (stack[sp - 1].expr); \
4416 = default_function_array_conversion (stack[sp].expr); \
4417 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4418 stack[sp - 1].expr, \
4422 gcc_assert (!after
|| c_dialect_objc ());
4423 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4424 stack
[0].prec
= PREC_NONE
;
4429 enum tree_code ocode
;
4432 switch (c_parser_peek_token (parser
)->type
)
4440 ocode
= TRUNC_DIV_EXPR
;
4444 ocode
= TRUNC_MOD_EXPR
;
4456 ocode
= LSHIFT_EXPR
;
4460 ocode
= RSHIFT_EXPR
;
4474 case CPP_GREATER_EQ
:
4487 oprec
= PREC_BITAND
;
4488 ocode
= BIT_AND_EXPR
;
4491 oprec
= PREC_BITXOR
;
4492 ocode
= BIT_XOR_EXPR
;
4496 ocode
= BIT_IOR_EXPR
;
4499 oprec
= PREC_LOGAND
;
4500 ocode
= TRUTH_ANDIF_EXPR
;
4504 ocode
= TRUTH_ORIF_EXPR
;
4507 /* Not a binary operator, so end of the binary
4511 c_parser_consume_token (parser
);
4512 while (oprec
<= stack
[sp
].prec
)
4516 case TRUTH_ANDIF_EXPR
:
4518 = default_function_array_conversion (stack
[sp
].expr
);
4519 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4520 (default_conversion (stack
[sp
].expr
.value
));
4521 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4523 case TRUTH_ORIF_EXPR
:
4525 = default_function_array_conversion (stack
[sp
].expr
);
4526 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4527 (default_conversion (stack
[sp
].expr
.value
));
4528 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4534 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4535 stack
[sp
].prec
= oprec
;
4536 stack
[sp
].op
= ocode
;
4541 return stack
[0].expr
;
4545 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4546 NULL then it is an Objective-C message expression which is the
4547 primary-expression starting the expression as an initializer.
4551 ( type-name ) unary-expression
4554 static struct c_expr
4555 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4557 gcc_assert (!after
|| c_dialect_objc ());
4559 return c_parser_postfix_expression_after_primary (parser
, *after
);
4560 /* If the expression begins with a parenthesized type name, it may
4561 be either a cast or a compound literal; we need to see whether
4562 the next character is '{' to tell the difference. If not, it is
4563 an unary expression. */
4564 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4565 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4567 struct c_type_name
*type_name
;
4570 c_parser_consume_token (parser
);
4571 type_name
= c_parser_type_name (parser
);
4572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4573 if (type_name
== NULL
)
4575 ret
.value
= error_mark_node
;
4576 ret
.original_code
= ERROR_MARK
;
4579 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4580 return c_parser_postfix_expression_after_paren_type (parser
,
4582 expr
= c_parser_cast_expression (parser
, NULL
);
4583 expr
= default_function_array_conversion (expr
);
4584 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4585 ret
.original_code
= ERROR_MARK
;
4589 return c_parser_unary_expression (parser
);
4592 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4598 unary-operator cast-expression
4599 sizeof unary-expression
4600 sizeof ( type-name )
4602 unary-operator: one of
4608 __alignof__ unary-expression
4609 __alignof__ ( type-name )
4612 unary-operator: one of
4613 __extension__ __real__ __imag__
4615 In addition, the GNU syntax treats ++ and -- as unary operators, so
4616 they may be applied to cast expressions with errors for non-lvalues
4619 static struct c_expr
4620 c_parser_unary_expression (c_parser
*parser
)
4623 struct c_expr ret
, op
;
4624 switch (c_parser_peek_token (parser
)->type
)
4627 c_parser_consume_token (parser
);
4628 op
= c_parser_cast_expression (parser
, NULL
);
4629 op
= default_function_array_conversion (op
);
4630 return parser_build_unary_op (PREINCREMENT_EXPR
, op
);
4631 case CPP_MINUS_MINUS
:
4632 c_parser_consume_token (parser
);
4633 op
= c_parser_cast_expression (parser
, NULL
);
4634 op
= default_function_array_conversion (op
);
4635 return parser_build_unary_op (PREDECREMENT_EXPR
, op
);
4637 c_parser_consume_token (parser
);
4638 return parser_build_unary_op (ADDR_EXPR
,
4639 c_parser_cast_expression (parser
, NULL
));
4641 c_parser_consume_token (parser
);
4642 op
= c_parser_cast_expression (parser
, NULL
);
4643 op
= default_function_array_conversion (op
);
4644 ret
.value
= build_indirect_ref (op
.value
, "unary *");
4645 ret
.original_code
= ERROR_MARK
;
4648 c_parser_consume_token (parser
);
4649 if (!c_dialect_objc () && !in_system_header
)
4650 warning (OPT_Wtraditional
,
4651 "traditional C rejects the unary plus operator");
4652 op
= c_parser_cast_expression (parser
, NULL
);
4653 op
= default_function_array_conversion (op
);
4654 return parser_build_unary_op (CONVERT_EXPR
, op
);
4656 c_parser_consume_token (parser
);
4657 op
= c_parser_cast_expression (parser
, NULL
);
4658 op
= default_function_array_conversion (op
);
4659 return parser_build_unary_op (NEGATE_EXPR
, op
);
4661 c_parser_consume_token (parser
);
4662 op
= c_parser_cast_expression (parser
, NULL
);
4663 op
= default_function_array_conversion (op
);
4664 return parser_build_unary_op (BIT_NOT_EXPR
, op
);
4666 c_parser_consume_token (parser
);
4667 op
= c_parser_cast_expression (parser
, NULL
);
4668 op
= default_function_array_conversion (op
);
4669 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
);
4671 /* Refer to the address of a label as a pointer. */
4672 c_parser_consume_token (parser
);
4673 if (c_parser_next_token_is (parser
, CPP_NAME
))
4675 ret
.value
= finish_label_address_expr
4676 (c_parser_peek_token (parser
)->value
);
4677 c_parser_consume_token (parser
);
4681 c_parser_error (parser
, "expected identifier");
4682 ret
.value
= error_mark_node
;
4684 ret
.original_code
= ERROR_MARK
;
4687 switch (c_parser_peek_token (parser
)->keyword
)
4690 return c_parser_sizeof_expression (parser
);
4692 return c_parser_alignof_expression (parser
);
4694 c_parser_consume_token (parser
);
4695 ext
= disable_extension_diagnostics ();
4696 ret
= c_parser_cast_expression (parser
, NULL
);
4697 restore_extension_diagnostics (ext
);
4700 c_parser_consume_token (parser
);
4701 op
= c_parser_cast_expression (parser
, NULL
);
4702 op
= default_function_array_conversion (op
);
4703 return parser_build_unary_op (REALPART_EXPR
, op
);
4705 c_parser_consume_token (parser
);
4706 op
= c_parser_cast_expression (parser
, NULL
);
4707 op
= default_function_array_conversion (op
);
4708 return parser_build_unary_op (IMAGPART_EXPR
, op
);
4710 return c_parser_postfix_expression (parser
);
4713 return c_parser_postfix_expression (parser
);
4717 /* Parse a sizeof expression. */
4719 static struct c_expr
4720 c_parser_sizeof_expression (c_parser
*parser
)
4723 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4724 c_parser_consume_token (parser
);
4727 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4728 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4730 /* Either sizeof ( type-name ) or sizeof unary-expression
4731 starting with a compound literal. */
4732 struct c_type_name
*type_name
;
4733 c_parser_consume_token (parser
);
4734 type_name
= c_parser_type_name (parser
);
4735 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4736 if (type_name
== NULL
)
4741 ret
.value
= error_mark_node
;
4742 ret
.original_code
= ERROR_MARK
;
4745 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4747 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4751 /* sizeof ( type-name ). */
4754 return c_expr_sizeof_type (type_name
);
4758 expr
= c_parser_unary_expression (parser
);
4762 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4763 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4764 error ("%<sizeof%> applied to a bit-field");
4765 return c_expr_sizeof_expr (expr
);
4769 /* Parse an alignof expression. */
4771 static struct c_expr
4772 c_parser_alignof_expression (c_parser
*parser
)
4775 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4776 c_parser_consume_token (parser
);
4779 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4780 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4782 /* Either __alignof__ ( type-name ) or __alignof__
4783 unary-expression starting with a compound literal. */
4784 struct c_type_name
*type_name
;
4786 c_parser_consume_token (parser
);
4787 type_name
= c_parser_type_name (parser
);
4788 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4789 if (type_name
== NULL
)
4794 ret
.value
= error_mark_node
;
4795 ret
.original_code
= ERROR_MARK
;
4798 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4800 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4804 /* alignof ( type-name ). */
4807 ret
.value
= c_alignof (groktypename (type_name
));
4808 ret
.original_code
= ERROR_MARK
;
4814 expr
= c_parser_unary_expression (parser
);
4818 ret
.value
= c_alignof_expr (expr
.value
);
4819 ret
.original_code
= ERROR_MARK
;
4824 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4828 postfix-expression [ expression ]
4829 postfix-expression ( argument-expression-list[opt] )
4830 postfix-expression . identifier
4831 postfix-expression -> identifier
4832 postfix-expression ++
4833 postfix-expression --
4834 ( type-name ) { initializer-list }
4835 ( type-name ) { initializer-list , }
4837 argument-expression-list:
4839 argument-expression-list , argument-expression
4851 (treated as a keyword in GNU C)
4854 ( compound-statement )
4855 __builtin_va_arg ( assignment-expression , type-name )
4856 __builtin_offsetof ( type-name , offsetof-member-designator )
4857 __builtin_choose_expr ( assignment-expression ,
4858 assignment-expression ,
4859 assignment-expression )
4860 __builtin_types_compatible_p ( type-name , type-name )
4862 offsetof-member-designator:
4864 offsetof-member-designator . identifier
4865 offsetof-member-designator [ expression ]
4870 [ objc-receiver objc-message-args ]
4871 @selector ( objc-selector-arg )
4872 @protocol ( identifier )
4873 @encode ( type-name )
4877 static struct c_expr
4878 c_parser_postfix_expression (c_parser
*parser
)
4880 struct c_expr expr
, e1
, e2
, e3
;
4881 struct c_type_name
*t1
, *t2
;
4882 switch (c_parser_peek_token (parser
)->type
)
4887 expr
.value
= c_parser_peek_token (parser
)->value
;
4888 expr
.original_code
= ERROR_MARK
;
4889 c_parser_consume_token (parser
);
4893 expr
.value
= c_parser_peek_token (parser
)->value
;
4894 expr
.original_code
= STRING_CST
;
4895 c_parser_consume_token (parser
);
4897 case CPP_OBJC_STRING
:
4898 gcc_assert (c_dialect_objc ());
4900 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
4901 expr
.original_code
= ERROR_MARK
;
4902 c_parser_consume_token (parser
);
4905 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
4907 c_parser_error (parser
, "expected expression");
4908 expr
.value
= error_mark_node
;
4909 expr
.original_code
= ERROR_MARK
;
4913 tree id
= c_parser_peek_token (parser
)->value
;
4914 location_t loc
= c_parser_peek_token (parser
)->location
;
4915 c_parser_consume_token (parser
);
4916 expr
.value
= build_external_ref (id
,
4917 (c_parser_peek_token (parser
)->type
4918 == CPP_OPEN_PAREN
), loc
);
4919 expr
.original_code
= ERROR_MARK
;
4922 case CPP_OPEN_PAREN
:
4923 /* A parenthesized expression, statement expression or compound
4925 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
4927 /* A statement expression. */
4929 c_parser_consume_token (parser
);
4930 c_parser_consume_token (parser
);
4931 if (cur_stmt_list
== NULL
)
4933 error ("braced-group within expression allowed "
4934 "only inside a function");
4935 parser
->error
= true;
4936 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
4937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4938 expr
.value
= error_mark_node
;
4939 expr
.original_code
= ERROR_MARK
;
4942 stmt
= c_begin_stmt_expr ();
4943 c_parser_compound_statement_nostart (parser
);
4944 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4947 pedwarn ("ISO C forbids braced-groups within expressions");
4948 expr
.value
= c_finish_stmt_expr (stmt
);
4949 expr
.original_code
= ERROR_MARK
;
4951 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4953 /* A compound literal. ??? Can we actually get here rather
4954 than going directly to
4955 c_parser_postfix_expression_after_paren_type from
4957 struct c_type_name
*type_name
;
4958 c_parser_consume_token (parser
);
4959 type_name
= c_parser_type_name (parser
);
4960 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4962 if (type_name
== NULL
)
4964 expr
.value
= error_mark_node
;
4965 expr
.original_code
= ERROR_MARK
;
4968 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4973 /* A parenthesized expression. */
4974 c_parser_consume_token (parser
);
4975 expr
= c_parser_expression (parser
);
4976 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
4977 TREE_NO_WARNING (expr
.value
) = 1;
4978 expr
.original_code
= ERROR_MARK
;
4979 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4984 switch (c_parser_peek_token (parser
)->keyword
)
4986 case RID_FUNCTION_NAME
:
4987 case RID_PRETTY_FUNCTION_NAME
:
4988 case RID_C99_FUNCTION_NAME
:
4989 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
4990 c_parser_peek_token (parser
)->value
);
4991 expr
.original_code
= ERROR_MARK
;
4992 c_parser_consume_token (parser
);
4995 c_parser_consume_token (parser
);
4996 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4998 expr
.value
= error_mark_node
;
4999 expr
.original_code
= ERROR_MARK
;
5002 e1
= c_parser_expr_no_commas (parser
, NULL
);
5003 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5005 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5006 expr
.value
= error_mark_node
;
5007 expr
.original_code
= ERROR_MARK
;
5010 t1
= c_parser_type_name (parser
);
5011 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5015 expr
.value
= error_mark_node
;
5016 expr
.original_code
= ERROR_MARK
;
5020 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
5021 expr
.original_code
= ERROR_MARK
;
5025 c_parser_consume_token (parser
);
5026 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5028 expr
.value
= error_mark_node
;
5029 expr
.original_code
= ERROR_MARK
;
5032 t1
= c_parser_type_name (parser
);
5035 expr
.value
= error_mark_node
;
5036 expr
.original_code
= ERROR_MARK
;
5039 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5041 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5042 expr
.value
= error_mark_node
;
5043 expr
.original_code
= ERROR_MARK
;
5047 tree type
= groktypename (t1
);
5049 if (type
== error_mark_node
)
5050 offsetof_ref
= error_mark_node
;
5052 offsetof_ref
= build1 (INDIRECT_REF
, type
, NULL
);
5053 /* Parse the second argument to __builtin_offsetof. We
5054 must have one identifier, and beyond that we want to
5055 accept sub structure and sub array references. */
5056 if (c_parser_next_token_is (parser
, CPP_NAME
))
5058 offsetof_ref
= build_component_ref
5059 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5060 c_parser_consume_token (parser
);
5061 while (c_parser_next_token_is (parser
, CPP_DOT
)
5062 || c_parser_next_token_is (parser
,
5065 if (c_parser_next_token_is (parser
, CPP_DOT
))
5067 c_parser_consume_token (parser
);
5068 if (c_parser_next_token_is_not (parser
,
5071 c_parser_error (parser
, "expected identifier");
5074 offsetof_ref
= build_component_ref
5076 c_parser_peek_token (parser
)->value
);
5077 c_parser_consume_token (parser
);
5082 c_parser_consume_token (parser
);
5083 idx
= c_parser_expression (parser
).value
;
5084 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5086 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
5091 c_parser_error (parser
, "expected identifier");
5092 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5094 expr
.value
= fold_offsetof (offsetof_ref
);
5095 expr
.original_code
= ERROR_MARK
;
5098 case RID_CHOOSE_EXPR
:
5099 c_parser_consume_token (parser
);
5100 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5102 expr
.value
= error_mark_node
;
5103 expr
.original_code
= ERROR_MARK
;
5106 e1
= c_parser_expr_no_commas (parser
, NULL
);
5107 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5109 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5110 expr
.value
= error_mark_node
;
5111 expr
.original_code
= ERROR_MARK
;
5114 e2
= c_parser_expr_no_commas (parser
, NULL
);
5115 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5117 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5118 expr
.value
= error_mark_node
;
5119 expr
.original_code
= ERROR_MARK
;
5122 e3
= c_parser_expr_no_commas (parser
, NULL
);
5123 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5128 c
= fold (e1
.value
);
5129 if (TREE_CODE (c
) != INTEGER_CST
)
5130 error ("first argument to %<__builtin_choose_expr%> not"
5132 expr
= integer_zerop (c
) ? e3
: e2
;
5135 case RID_TYPES_COMPATIBLE_P
:
5136 c_parser_consume_token (parser
);
5137 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5139 expr
.value
= error_mark_node
;
5140 expr
.original_code
= ERROR_MARK
;
5143 t1
= c_parser_type_name (parser
);
5146 expr
.value
= error_mark_node
;
5147 expr
.original_code
= ERROR_MARK
;
5150 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5152 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5153 expr
.value
= error_mark_node
;
5154 expr
.original_code
= ERROR_MARK
;
5157 t2
= c_parser_type_name (parser
);
5160 expr
.value
= error_mark_node
;
5161 expr
.original_code
= ERROR_MARK
;
5164 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5169 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5170 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5172 expr
.value
= comptypes (e1
, e2
)
5173 ? build_int_cst (NULL_TREE
, 1)
5174 : build_int_cst (NULL_TREE
, 0);
5175 expr
.original_code
= ERROR_MARK
;
5178 case RID_AT_SELECTOR
:
5179 gcc_assert (c_dialect_objc ());
5180 c_parser_consume_token (parser
);
5181 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5183 expr
.value
= error_mark_node
;
5184 expr
.original_code
= ERROR_MARK
;
5188 tree sel
= c_parser_objc_selector_arg (parser
);
5189 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5191 expr
.value
= objc_build_selector_expr (sel
);
5192 expr
.original_code
= ERROR_MARK
;
5195 case RID_AT_PROTOCOL
:
5196 gcc_assert (c_dialect_objc ());
5197 c_parser_consume_token (parser
);
5198 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5200 expr
.value
= error_mark_node
;
5201 expr
.original_code
= ERROR_MARK
;
5204 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5206 c_parser_error (parser
, "expected identifier");
5207 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5208 expr
.value
= error_mark_node
;
5209 expr
.original_code
= ERROR_MARK
;
5213 tree id
= c_parser_peek_token (parser
)->value
;
5214 c_parser_consume_token (parser
);
5215 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5217 expr
.value
= objc_build_protocol_expr (id
);
5218 expr
.original_code
= ERROR_MARK
;
5222 /* Extension to support C-structures in the archiver. */
5223 gcc_assert (c_dialect_objc ());
5224 c_parser_consume_token (parser
);
5225 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5227 expr
.value
= error_mark_node
;
5228 expr
.original_code
= ERROR_MARK
;
5231 t1
= c_parser_type_name (parser
);
5234 expr
.value
= error_mark_node
;
5235 expr
.original_code
= ERROR_MARK
;
5236 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5239 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5242 tree type
= groktypename (t1
);
5243 expr
.value
= objc_build_encode_expr (type
);
5244 expr
.original_code
= ERROR_MARK
;
5248 c_parser_error (parser
, "expected expression");
5249 expr
.value
= error_mark_node
;
5250 expr
.original_code
= ERROR_MARK
;
5254 case CPP_OPEN_SQUARE
:
5255 if (c_dialect_objc ())
5257 tree receiver
, args
;
5258 c_parser_consume_token (parser
);
5259 receiver
= c_parser_objc_receiver (parser
);
5260 args
= c_parser_objc_message_args (parser
);
5261 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5263 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5265 expr
.original_code
= ERROR_MARK
;
5268 /* Else fall through to report error. */
5270 c_parser_error (parser
, "expected expression");
5271 expr
.value
= error_mark_node
;
5272 expr
.original_code
= ERROR_MARK
;
5275 return c_parser_postfix_expression_after_primary (parser
, expr
);
5278 /* Parse a postfix expression after a parenthesized type name: the
5279 brace-enclosed initializer of a compound literal, possibly followed
5280 by some postfix operators. This is separate because it is not
5281 possible to tell until after the type name whether a cast
5282 expression has a cast or a compound literal, or whether the operand
5283 of sizeof is a parenthesized type name or starts with a compound
5286 static struct c_expr
5287 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5288 struct c_type_name
*type_name
)
5293 start_init (NULL_TREE
, NULL
, 0);
5294 type
= groktypename (type_name
);
5295 if (C_TYPE_VARIABLE_SIZE (type
))
5297 error ("compound literal has variable size");
5298 type
= error_mark_node
;
5300 init
= c_parser_braced_init (parser
, type
, false);
5302 maybe_warn_string_init (type
, init
);
5304 if (pedantic
&& !flag_isoc99
)
5305 pedwarn ("ISO C90 forbids compound literals");
5306 expr
.value
= build_compound_literal (type
, init
.value
);
5307 expr
.original_code
= ERROR_MARK
;
5308 return c_parser_postfix_expression_after_primary (parser
, expr
);
5311 /* Parse a postfix expression after the initial primary or compound
5312 literal; that is, parse a series of postfix operators. */
5314 static struct c_expr
5315 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5318 tree ident
, idx
, exprlist
;
5321 switch (c_parser_peek_token (parser
)->type
)
5323 case CPP_OPEN_SQUARE
:
5324 /* Array reference. */
5325 c_parser_consume_token (parser
);
5326 idx
= c_parser_expression (parser
).value
;
5327 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5329 expr
.value
= build_array_ref (expr
.value
, idx
);
5330 expr
.original_code
= ERROR_MARK
;
5332 case CPP_OPEN_PAREN
:
5333 /* Function call. */
5334 c_parser_consume_token (parser
);
5335 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5336 exprlist
= NULL_TREE
;
5338 exprlist
= c_parser_expr_list (parser
, true);
5339 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5341 expr
.value
= build_function_call (expr
.value
, exprlist
);
5342 expr
.original_code
= ERROR_MARK
;
5345 /* Structure element reference. */
5346 c_parser_consume_token (parser
);
5347 expr
= default_function_array_conversion (expr
);
5348 if (c_parser_next_token_is (parser
, CPP_NAME
))
5349 ident
= c_parser_peek_token (parser
)->value
;
5352 c_parser_error (parser
, "expected identifier");
5353 expr
.value
= error_mark_node
;
5354 expr
.original_code
= ERROR_MARK
;
5357 c_parser_consume_token (parser
);
5358 expr
.value
= build_component_ref (expr
.value
, ident
);
5359 expr
.original_code
= ERROR_MARK
;
5362 /* Structure element reference. */
5363 c_parser_consume_token (parser
);
5364 expr
= default_function_array_conversion (expr
);
5365 if (c_parser_next_token_is (parser
, CPP_NAME
))
5366 ident
= c_parser_peek_token (parser
)->value
;
5369 c_parser_error (parser
, "expected identifier");
5370 expr
.value
= error_mark_node
;
5371 expr
.original_code
= ERROR_MARK
;
5374 c_parser_consume_token (parser
);
5375 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5377 expr
.original_code
= ERROR_MARK
;
5380 /* Postincrement. */
5381 c_parser_consume_token (parser
);
5382 expr
= default_function_array_conversion (expr
);
5383 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5384 expr
.original_code
= ERROR_MARK
;
5386 case CPP_MINUS_MINUS
:
5387 /* Postdecrement. */
5388 c_parser_consume_token (parser
);
5389 expr
= default_function_array_conversion (expr
);
5390 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5391 expr
.original_code
= ERROR_MARK
;
5399 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5402 assignment-expression
5403 expression , assignment-expression
5406 static struct c_expr
5407 c_parser_expression (c_parser
*parser
)
5410 expr
= c_parser_expr_no_commas (parser
, NULL
);
5411 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5414 c_parser_consume_token (parser
);
5415 next
= c_parser_expr_no_commas (parser
, NULL
);
5416 next
= default_function_array_conversion (next
);
5417 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5418 expr
.original_code
= COMPOUND_EXPR
;
5423 /* Parse an expression and convert functions or arrays to
5426 static struct c_expr
5427 c_parser_expression_conv (c_parser
*parser
)
5430 expr
= c_parser_expression (parser
);
5431 expr
= default_function_array_conversion (expr
);
5435 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5436 functions and arrays to pointers.
5439 assignment-expression
5440 nonempty-expr-list , assignment-expression
5444 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5448 expr
= c_parser_expr_no_commas (parser
, NULL
);
5450 expr
= default_function_array_conversion (expr
);
5451 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5452 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5454 c_parser_consume_token (parser
);
5455 expr
= c_parser_expr_no_commas (parser
, NULL
);
5457 expr
= default_function_array_conversion (expr
);
5458 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5464 /* Parse Objective-C-specific constructs. */
5466 /* Parse an objc-class-definition.
5468 objc-class-definition:
5469 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5470 objc-class-instance-variables[opt] objc-methodprotolist @end
5471 @implementation identifier objc-superclass[opt]
5472 objc-class-instance-variables[opt]
5473 @interface identifier ( identifier ) objc-protocol-refs[opt]
5474 objc-methodprotolist @end
5475 @implementation identifier ( identifier )
5480 "@interface identifier (" must start "@interface identifier (
5481 identifier ) ...": objc-methodprotolist in the first production may
5482 not start with a parenthesized identifier as a declarator of a data
5483 definition with no declaration specifiers if the objc-superclass,
5484 objc-protocol-refs and objc-class-instance-variables are omitted. */
5487 c_parser_objc_class_definition (c_parser
*parser
)
5492 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5494 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5498 c_parser_consume_token (parser
);
5499 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5501 c_parser_error (parser
, "expected identifier");
5504 id1
= c_parser_peek_token (parser
)->value
;
5505 c_parser_consume_token (parser
);
5506 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5509 tree proto
= NULL_TREE
;
5510 c_parser_consume_token (parser
);
5511 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5513 c_parser_error (parser
, "expected identifier");
5514 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5517 id2
= c_parser_peek_token (parser
)->value
;
5518 c_parser_consume_token (parser
);
5519 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5522 objc_start_category_implementation (id1
, id2
);
5525 if (c_parser_next_token_is (parser
, CPP_LESS
))
5526 proto
= c_parser_objc_protocol_refs (parser
);
5527 objc_start_category_interface (id1
, id2
, proto
);
5528 c_parser_objc_methodprotolist (parser
);
5529 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5530 objc_finish_interface ();
5533 if (c_parser_next_token_is (parser
, CPP_COLON
))
5535 c_parser_consume_token (parser
);
5536 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5538 c_parser_error (parser
, "expected identifier");
5541 superclass
= c_parser_peek_token (parser
)->value
;
5542 c_parser_consume_token (parser
);
5545 superclass
= NULL_TREE
;
5548 tree proto
= NULL_TREE
;
5549 if (c_parser_next_token_is (parser
, CPP_LESS
))
5550 proto
= c_parser_objc_protocol_refs (parser
);
5551 objc_start_class_interface (id1
, superclass
, proto
);
5554 objc_start_class_implementation (id1
, superclass
);
5555 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5556 c_parser_objc_class_instance_variables (parser
);
5559 objc_continue_interface ();
5560 c_parser_objc_methodprotolist (parser
);
5561 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5562 objc_finish_interface ();
5566 objc_continue_implementation ();
5571 /* Parse objc-class-instance-variables.
5573 objc-class-instance-variables:
5574 { objc-instance-variable-decl-list[opt] }
5576 objc-instance-variable-decl-list:
5577 objc-visibility-spec
5578 objc-instance-variable-decl ;
5580 objc-instance-variable-decl-list objc-visibility-spec
5581 objc-instance-variable-decl-list objc-instance-variable-decl ;
5582 objc-instance-variable-decl-list ;
5584 objc-visibility-spec:
5589 objc-instance-variable-decl:
5594 c_parser_objc_class_instance_variables (c_parser
*parser
)
5596 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5597 c_parser_consume_token (parser
);
5598 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5601 /* Parse any stray semicolon. */
5602 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5605 pedwarn ("extra semicolon in struct or union specified");
5606 c_parser_consume_token (parser
);
5609 /* Stop if at the end of the instance variables. */
5610 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5612 c_parser_consume_token (parser
);
5615 /* Parse any objc-visibility-spec. */
5616 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5618 c_parser_consume_token (parser
);
5619 objc_set_visibility (2);
5622 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5624 c_parser_consume_token (parser
);
5625 objc_set_visibility (0);
5628 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5630 c_parser_consume_token (parser
);
5631 objc_set_visibility (1);
5634 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5636 c_parser_pragma (parser
, pragma_external
);
5640 /* Parse some comma-separated declarations. */
5641 decls
= c_parser_struct_declaration (parser
);
5643 /* Comma-separated instance variables are chained together in
5644 reverse order; add them one by one. */
5645 tree ivar
= nreverse (decls
);
5646 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5647 objc_add_instance_variable (copy_node (ivar
));
5649 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5653 /* Parse an objc-class-declaration.
5655 objc-class-declaration:
5656 @class identifier-list ;
5660 c_parser_objc_class_declaration (c_parser
*parser
)
5662 tree list
= NULL_TREE
;
5663 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5664 c_parser_consume_token (parser
);
5665 /* Any identifiers, including those declared as type names, are OK
5670 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5672 c_parser_error (parser
, "expected identifier");
5675 id
= c_parser_peek_token (parser
)->value
;
5676 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5677 c_parser_consume_token (parser
);
5678 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5679 c_parser_consume_token (parser
);
5683 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5684 objc_declare_class (list
);
5687 /* Parse an objc-alias-declaration.
5689 objc-alias-declaration:
5690 @compatibility_alias identifier identifier ;
5694 c_parser_objc_alias_declaration (c_parser
*parser
)
5697 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5698 c_parser_consume_token (parser
);
5699 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5701 c_parser_error (parser
, "expected identifier");
5702 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5705 id1
= c_parser_peek_token (parser
)->value
;
5706 c_parser_consume_token (parser
);
5707 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5709 c_parser_error (parser
, "expected identifier");
5710 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5713 id2
= c_parser_peek_token (parser
)->value
;
5714 c_parser_consume_token (parser
);
5715 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5716 objc_declare_alias (id1
, id2
);
5719 /* Parse an objc-protocol-definition.
5721 objc-protocol-definition:
5722 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5723 @protocol identifier-list ;
5725 "@protocol identifier ;" should be resolved as "@protocol
5726 identifier-list ;": objc-methodprotolist may not start with a
5727 semicolon in the first alternative if objc-protocol-refs are
5731 c_parser_objc_protocol_definition (c_parser
*parser
)
5733 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5734 c_parser_consume_token (parser
);
5735 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5737 c_parser_error (parser
, "expected identifier");
5740 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5741 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5743 tree list
= NULL_TREE
;
5744 /* Any identifiers, including those declared as type names, are
5749 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5751 c_parser_error (parser
, "expected identifier");
5754 id
= c_parser_peek_token (parser
)->value
;
5755 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5756 c_parser_consume_token (parser
);
5757 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5758 c_parser_consume_token (parser
);
5762 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5763 objc_declare_protocols (list
);
5767 tree id
= c_parser_peek_token (parser
)->value
;
5768 tree proto
= NULL_TREE
;
5769 c_parser_consume_token (parser
);
5770 if (c_parser_next_token_is (parser
, CPP_LESS
))
5771 proto
= c_parser_objc_protocol_refs (parser
);
5772 objc_pq_context
= 1;
5773 objc_start_protocol (id
, proto
);
5774 c_parser_objc_methodprotolist (parser
);
5775 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5776 objc_pq_context
= 0;
5777 objc_finish_interface ();
5781 /* Parse an objc-method-type.
5788 static enum tree_code
5789 c_parser_objc_method_type (c_parser
*parser
)
5791 switch (c_parser_peek_token (parser
)->type
)
5794 c_parser_consume_token (parser
);
5797 c_parser_consume_token (parser
);
5804 /* Parse an objc-method-definition.
5806 objc-method-definition:
5807 objc-method-type objc-method-decl ;[opt] compound-statement
5811 c_parser_objc_method_definition (c_parser
*parser
)
5813 enum tree_code type
= c_parser_objc_method_type (parser
);
5815 objc_set_method_type (type
);
5816 objc_pq_context
= 1;
5817 decl
= c_parser_objc_method_decl (parser
);
5818 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5820 c_parser_consume_token (parser
);
5822 pedwarn ("extra semicolon in method definition specified");
5824 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5826 c_parser_error (parser
, "expected %<{%>");
5829 objc_pq_context
= 0;
5830 objc_start_method_definition (decl
);
5831 add_stmt (c_parser_compound_statement (parser
));
5832 objc_finish_method_definition (current_function_decl
);
5835 /* Parse an objc-methodprotolist.
5837 objc-methodprotolist:
5839 objc-methodprotolist objc-methodproto
5840 objc-methodprotolist declaration
5841 objc-methodprotolist ;
5843 The declaration is a data definition, which may be missing
5844 declaration specifiers under the same rules and diagnostics as
5845 other data definitions outside functions, and the stray semicolon
5846 is diagnosed the same way as a stray semicolon outside a
5850 c_parser_objc_methodprotolist (c_parser
*parser
)
5854 /* The list is terminated by @end. */
5855 switch (c_parser_peek_token (parser
)->type
)
5859 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5860 c_parser_consume_token (parser
);
5864 c_parser_objc_methodproto (parser
);
5867 c_parser_pragma (parser
, pragma_external
);
5872 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
5874 c_parser_declaration_or_fndef (parser
, false, true, false, true);
5880 /* Parse an objc-methodproto.
5883 objc-method-type objc-method-decl ;
5887 c_parser_objc_methodproto (c_parser
*parser
)
5889 enum tree_code type
= c_parser_objc_method_type (parser
);
5891 objc_set_method_type (type
);
5892 /* Remember protocol qualifiers in prototypes. */
5893 objc_pq_context
= 1;
5894 decl
= c_parser_objc_method_decl (parser
);
5895 /* Forget protocol qualifiers here. */
5896 objc_pq_context
= 0;
5897 objc_add_method_declaration (decl
);
5898 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5901 /* Parse an objc-method-decl.
5904 ( objc-type-name ) objc-selector
5906 ( objc-type-name ) objc-keyword-selector objc-optparmlist
5907 objc-keyword-selector objc-optparmlist
5909 objc-keyword-selector:
5911 objc-keyword-selector objc-keyword-decl
5914 objc-selector : ( objc-type-name ) identifier
5915 objc-selector : identifier
5916 : ( objc-type-name ) identifier
5920 objc-optparms objc-optellipsis
5924 objc-opt-parms , parameter-declaration
5932 c_parser_objc_method_decl (c_parser
*parser
)
5934 tree type
= NULL_TREE
;
5936 tree parms
= NULL_TREE
;
5937 bool ellipsis
= false;
5939 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5941 c_parser_consume_token (parser
);
5942 type
= c_parser_objc_type_name (parser
);
5943 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5945 sel
= c_parser_objc_selector (parser
);
5946 /* If there is no selector, or a colon follows, we have an
5947 objc-keyword-selector. If there is a selector, and a colon does
5948 not follow, that selector ends the objc-method-decl. */
5949 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
5952 tree list
= NULL_TREE
;
5955 tree atype
= NULL_TREE
, id
, keyworddecl
;
5956 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5958 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5960 c_parser_consume_token (parser
);
5961 atype
= c_parser_objc_type_name (parser
);
5962 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5965 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5967 c_parser_error (parser
, "expected identifier");
5968 return error_mark_node
;
5970 id
= c_parser_peek_token (parser
)->value
;
5971 c_parser_consume_token (parser
);
5972 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
5973 list
= chainon (list
, keyworddecl
);
5974 tsel
= c_parser_objc_selector (parser
);
5975 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
5978 /* Parse the optional parameter list. Optional Objective-C
5979 method parameters follow the C syntax, and may include '...'
5980 to denote a variable number of arguments. */
5981 parms
= make_node (TREE_LIST
);
5982 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5984 struct c_parm
*parm
;
5985 c_parser_consume_token (parser
);
5986 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5989 c_parser_consume_token (parser
);
5992 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5995 parms
= chainon (parms
,
5996 build_tree_list (NULL_TREE
, grokparm (parm
)));
6000 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6003 /* Parse an objc-type-name.
6006 objc-type-qualifiers[opt] type-name
6007 objc-type-qualifiers[opt]
6009 objc-type-qualifiers:
6011 objc-type-qualifiers objc-type-qualifier
6013 objc-type-qualifier: one of
6014 in out inout bycopy byref oneway
6018 c_parser_objc_type_name (c_parser
*parser
)
6020 tree quals
= NULL_TREE
;
6021 struct c_type_name
*typename
= NULL
;
6022 tree type
= NULL_TREE
;
6025 c_token
*token
= c_parser_peek_token (parser
);
6026 if (token
->type
== CPP_KEYWORD
6027 && (token
->keyword
== RID_IN
6028 || token
->keyword
== RID_OUT
6029 || token
->keyword
== RID_INOUT
6030 || token
->keyword
== RID_BYCOPY
6031 || token
->keyword
== RID_BYREF
6032 || token
->keyword
== RID_ONEWAY
))
6034 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6035 c_parser_consume_token (parser
);
6040 if (c_parser_next_token_starts_typename (parser
))
6041 typename
= c_parser_type_name (parser
);
6043 type
= groktypename (typename
);
6044 return build_tree_list (quals
, type
);
6047 /* Parse objc-protocol-refs.
6054 c_parser_objc_protocol_refs (c_parser
*parser
)
6056 tree list
= NULL_TREE
;
6057 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6058 c_parser_consume_token (parser
);
6059 /* Any identifiers, including those declared as type names, are OK
6064 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6066 c_parser_error (parser
, "expected identifier");
6069 id
= c_parser_peek_token (parser
)->value
;
6070 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6071 c_parser_consume_token (parser
);
6072 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6073 c_parser_consume_token (parser
);
6077 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6081 /* Parse an objc-try-catch-statement.
6083 objc-try-catch-statement:
6084 @try compound-statement objc-catch-list[opt]
6085 @try compound-statement objc-catch-list[opt] @finally compound-statement
6088 @catch ( parameter-declaration ) compound-statement
6089 objc-catch-list @catch ( parameter-declaration ) compound-statement
6093 c_parser_objc_try_catch_statement (c_parser
*parser
)
6097 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
6098 c_parser_consume_token (parser
);
6099 loc
= c_parser_peek_token (parser
)->location
;
6100 stmt
= c_parser_compound_statement (parser
);
6101 objc_begin_try_stmt (loc
, stmt
);
6102 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
6104 struct c_parm
*parm
;
6105 c_parser_consume_token (parser
);
6106 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6108 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6111 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6114 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6115 objc_begin_catch_clause (grokparm (parm
));
6116 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6117 c_parser_compound_statement_nostart (parser
);
6118 objc_finish_catch_clause ();
6120 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6124 c_parser_consume_token (parser
);
6125 finloc
= c_parser_peek_token (parser
)->location
;
6126 finstmt
= c_parser_compound_statement (parser
);
6127 objc_build_finally_clause (finloc
, finstmt
);
6129 objc_finish_try_stmt ();
6132 /* Parse an objc-synchronized-statement.
6134 objc-synchronized-statement:
6135 @synchronized ( expression ) compound-statement
6139 c_parser_objc_synchronized_statement (c_parser
*parser
)
6143 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6144 c_parser_consume_token (parser
);
6145 loc
= c_parser_peek_token (parser
)->location
;
6146 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6148 expr
= c_parser_expression (parser
).value
;
6149 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6152 expr
= error_mark_node
;
6153 stmt
= c_parser_compound_statement (parser
);
6154 objc_build_synchronized (loc
, expr
, stmt
);
6157 /* Parse an objc-selector; return NULL_TREE without an error if the
6158 next token is not an objc-selector.
6163 enum struct union if else while do for switch case default
6164 break continue return goto asm sizeof typeof __alignof
6165 unsigned long const short volatile signed restrict _Complex
6166 in out inout bycopy byref oneway int char float double void _Bool
6168 ??? Why this selection of keywords but not, for example, storage
6169 class specifiers? */
6172 c_parser_objc_selector (c_parser
*parser
)
6174 c_token
*token
= c_parser_peek_token (parser
);
6175 tree value
= token
->value
;
6176 if (token
->type
== CPP_NAME
)
6178 c_parser_consume_token (parser
);
6181 if (token
->type
!= CPP_KEYWORD
)
6183 switch (token
->keyword
)
6224 c_parser_consume_token (parser
);
6231 /* Parse an objc-selector-arg.
6235 objc-keywordname-list
6237 objc-keywordname-list:
6239 objc-keywordname-list objc-keywordname
6247 c_parser_objc_selector_arg (c_parser
*parser
)
6249 tree sel
= c_parser_objc_selector (parser
);
6250 tree list
= NULL_TREE
;
6251 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6255 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6257 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6258 sel
= c_parser_objc_selector (parser
);
6259 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6265 /* Parse an objc-receiver.
6274 c_parser_objc_receiver (c_parser
*parser
)
6276 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6277 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6278 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6280 tree id
= c_parser_peek_token (parser
)->value
;
6281 c_parser_consume_token (parser
);
6282 return objc_get_class_reference (id
);
6284 return c_parser_expression (parser
).value
;
6287 /* Parse objc-message-args.
6291 objc-keywordarg-list
6293 objc-keywordarg-list:
6295 objc-keywordarg-list objc-keywordarg
6298 objc-selector : objc-keywordexpr
6303 c_parser_objc_message_args (c_parser
*parser
)
6305 tree sel
= c_parser_objc_selector (parser
);
6306 tree list
= NULL_TREE
;
6307 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6312 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6314 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6315 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6316 sel
= c_parser_objc_selector (parser
);
6317 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6323 /* Parse an objc-keywordexpr.
6330 c_parser_objc_keywordexpr (c_parser
*parser
)
6332 tree list
= c_parser_expr_list (parser
, true);
6333 if (TREE_CHAIN (list
) == NULL_TREE
)
6335 /* Just return the expression, remove a level of
6337 return TREE_VALUE (list
);
6341 /* We have a comma expression, we will collapse later. */
6347 /* Handle pragmas. ALLOW_STMT is true if we're within the context of
6348 a function and such pragmas are to be allowed. Returns true if we
6349 actually parsed such a pragma. */
6352 c_parser_pragma (c_parser
*parser
, enum pragma_context context ATTRIBUTE_UNUSED
)
6356 id
= c_parser_peek_token (parser
)->pragma_kind
;
6357 gcc_assert (id
!= PRAGMA_NONE
);
6361 case PRAGMA_GCC_PCH_PREPROCESS
:
6362 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6363 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6367 gcc_assert (id
>= PRAGMA_FIRST_EXTERNAL
);
6371 c_parser_consume_pragma (parser
);
6372 c_invoke_pragma_handler (id
);
6374 /* Skip to EOL, but suppress any error message. Those will have been
6375 generated by the handler routine through calling error, as opposed
6376 to calling c_parser_error. */
6377 parser
->error
= true;
6378 c_parser_skip_to_pragma_eol (parser
);
6383 /* The interface the pragma parsers have to the lexer. */
6386 pragma_lex (tree
*value
)
6388 c_token
*tok
= c_parser_peek_token (the_parser
);
6389 enum cpp_ttype ret
= tok
->type
;
6391 *value
= tok
->value
;
6392 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6396 if (ret
== CPP_KEYWORD
)
6398 c_parser_consume_token (the_parser
);
6405 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6409 c_parser_consume_pragma (parser
);
6410 if (c_parser_next_token_is (parser
, CPP_STRING
))
6412 name
= c_parser_peek_token (parser
)->value
;
6413 c_parser_consume_token (parser
);
6416 c_parser_error (parser
, "expected string literal");
6417 c_parser_skip_to_pragma_eol (parser
);
6420 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6423 /* Parse a single source file. */
6428 /* Use local storage to begin. If the first token is a pragma, parse it.
6429 If it is #pragma GCC pch_preprocess, then this will load a PCH file
6430 which will cause garbage collection. */
6433 memset (&tparser
, 0, sizeof tparser
);
6434 the_parser
= &tparser
;
6436 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
6437 c_parser_pragma_pch_preprocess (&tparser
);
6439 the_parser
= GGC_NEW (c_parser
);
6440 *the_parser
= tparser
;
6442 c_parser_translation_unit (the_parser
);
6446 #include "gt-c-parser.h"