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"
61 /* Miscellaneous data and functions needed for the parser. */
65 /* Objective-C specific parser/lexer information. */
67 static int objc_pq_context
= 0;
69 /* The following flag is needed to contextualize Objective-C lexical
70 analysis. In some cases (e.g., 'int NSObject;'), it is undesirable
71 to bind an identifier to an Objective-C class, even if a class with
73 static int objc_need_raw_identifier
= 0;
74 #define OBJC_NEED_RAW_IDENTIFIER(VAL) \
76 if (c_dialect_objc ()) \
77 objc_need_raw_identifier = VAL; \
80 /* The reserved keyword table. */
84 ENUM_BITFIELD(rid
) rid
: 16;
85 unsigned int disable
: 16;
88 /* Disable mask. Keywords are disabled if (reswords[i].disable &
90 #define D_C89 0x01 /* not in C89 */
91 #define D_EXT 0x02 /* GCC extension */
92 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
93 #define D_OBJC 0x08 /* Objective C only */
95 static const struct resword reswords
[] =
97 { "_Bool", RID_BOOL
, 0 },
98 { "_Complex", RID_COMPLEX
, 0 },
99 { "_Decimal32", RID_DFLOAT32
, D_EXT
},
100 { "_Decimal64", RID_DFLOAT64
, D_EXT
},
101 { "_Decimal128", RID_DFLOAT128
, D_EXT
},
102 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
103 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
104 { "__alignof", RID_ALIGNOF
, 0 },
105 { "__alignof__", RID_ALIGNOF
, 0 },
106 { "__asm", RID_ASM
, 0 },
107 { "__asm__", RID_ASM
, 0 },
108 { "__attribute", RID_ATTRIBUTE
, 0 },
109 { "__attribute__", RID_ATTRIBUTE
, 0 },
110 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
111 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
112 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
113 { "__builtin_va_arg", RID_VA_ARG
, 0 },
114 { "__complex", RID_COMPLEX
, 0 },
115 { "__complex__", RID_COMPLEX
, 0 },
116 { "__const", RID_CONST
, 0 },
117 { "__const__", RID_CONST
, 0 },
118 { "__extension__", RID_EXTENSION
, 0 },
119 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
120 { "__imag", RID_IMAGPART
, 0 },
121 { "__imag__", RID_IMAGPART
, 0 },
122 { "__inline", RID_INLINE
, 0 },
123 { "__inline__", RID_INLINE
, 0 },
124 { "__label__", RID_LABEL
, 0 },
125 { "__real", RID_REALPART
, 0 },
126 { "__real__", RID_REALPART
, 0 },
127 { "__restrict", RID_RESTRICT
, 0 },
128 { "__restrict__", RID_RESTRICT
, 0 },
129 { "__signed", RID_SIGNED
, 0 },
130 { "__signed__", RID_SIGNED
, 0 },
131 { "__thread", RID_THREAD
, 0 },
132 { "__typeof", RID_TYPEOF
, 0 },
133 { "__typeof__", RID_TYPEOF
, 0 },
134 { "__volatile", RID_VOLATILE
, 0 },
135 { "__volatile__", RID_VOLATILE
, 0 },
136 { "asm", RID_ASM
, D_EXT
},
137 { "auto", RID_AUTO
, 0 },
138 { "break", RID_BREAK
, 0 },
139 { "case", RID_CASE
, 0 },
140 { "char", RID_CHAR
, 0 },
141 { "const", RID_CONST
, 0 },
142 { "continue", RID_CONTINUE
, 0 },
143 { "default", RID_DEFAULT
, 0 },
145 { "double", RID_DOUBLE
, 0 },
146 { "else", RID_ELSE
, 0 },
147 { "enum", RID_ENUM
, 0 },
148 { "extern", RID_EXTERN
, 0 },
149 { "float", RID_FLOAT
, 0 },
150 { "for", RID_FOR
, 0 },
151 { "goto", RID_GOTO
, 0 },
153 { "inline", RID_INLINE
, D_EXT89
},
154 { "int", RID_INT
, 0 },
155 { "long", RID_LONG
, 0 },
156 { "register", RID_REGISTER
, 0 },
157 { "restrict", RID_RESTRICT
, D_C89
},
158 { "return", RID_RETURN
, 0 },
159 { "short", RID_SHORT
, 0 },
160 { "signed", RID_SIGNED
, 0 },
161 { "sizeof", RID_SIZEOF
, 0 },
162 { "static", RID_STATIC
, 0 },
163 { "struct", RID_STRUCT
, 0 },
164 { "switch", RID_SWITCH
, 0 },
165 { "typedef", RID_TYPEDEF
, 0 },
166 { "typeof", RID_TYPEOF
, D_EXT
},
167 { "union", RID_UNION
, 0 },
168 { "unsigned", RID_UNSIGNED
, 0 },
169 { "void", RID_VOID
, 0 },
170 { "volatile", RID_VOLATILE
, 0 },
171 { "while", RID_WHILE
, 0 },
172 /* These Objective-C keywords are recognized only immediately after
174 { "class", RID_AT_CLASS
, D_OBJC
},
175 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
176 { "defs", RID_AT_DEFS
, D_OBJC
},
177 { "encode", RID_AT_ENCODE
, D_OBJC
},
178 { "end", RID_AT_END
, D_OBJC
},
179 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
180 { "interface", RID_AT_INTERFACE
, D_OBJC
},
181 { "private", RID_AT_PRIVATE
, D_OBJC
},
182 { "protected", RID_AT_PROTECTED
, D_OBJC
},
183 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
184 { "public", RID_AT_PUBLIC
, D_OBJC
},
185 { "selector", RID_AT_SELECTOR
, D_OBJC
},
186 { "throw", RID_AT_THROW
, D_OBJC
},
187 { "try", RID_AT_TRY
, D_OBJC
},
188 { "catch", RID_AT_CATCH
, D_OBJC
},
189 { "finally", RID_AT_FINALLY
, D_OBJC
},
190 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
191 /* These are recognized only in protocol-qualifier context
193 { "bycopy", RID_BYCOPY
, D_OBJC
},
194 { "byref", RID_BYREF
, D_OBJC
},
195 { "in", RID_IN
, D_OBJC
},
196 { "inout", RID_INOUT
, D_OBJC
},
197 { "oneway", RID_ONEWAY
, D_OBJC
},
198 { "out", RID_OUT
, D_OBJC
},
200 #define N_reswords (sizeof reswords / sizeof (struct resword))
202 /* Initialization routine for this file. */
207 /* The only initialization required is of the reserved word
211 int mask
= (flag_isoc99
? 0 : D_C89
)
212 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
214 if (!c_dialect_objc ())
217 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
218 for (i
= 0; i
< N_reswords
; i
++)
220 /* If a keyword is disabled, do not enter it into the table
221 and so create a canonical spelling that isn't a keyword. */
222 if (reswords
[i
].disable
& mask
)
225 id
= get_identifier (reswords
[i
].word
);
226 C_RID_CODE (id
) = reswords
[i
].rid
;
227 C_IS_RESERVED_WORD (id
) = 1;
228 ridpointers
[(int) reswords
[i
].rid
] = id
;
232 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
233 and the C parser. Unlike the C++ lexer, the parser structure
234 stores the lexer information instead of using a separate structure.
235 Identifiers are separated into ordinary identifiers, type names,
236 keywords and some other Objective-C types of identifiers, and some
237 look-ahead is maintained.
239 ??? It might be a good idea to lex the whole file up front (as for
240 C++). It would then be possible to share more of the C and C++
241 lexer code, if desired. */
243 /* The following local token type is used. */
246 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
248 /* More information about the type of a CPP_NAME token. */
249 typedef enum c_id_kind
{
250 /* An ordinary identifier. */
252 /* An identifier declared as a typedef name. */
254 /* An identifier declared as an Objective-C class name. */
256 /* Not an identifier. */
260 /* A single C token after string literal concatenation and conversion
261 of preprocessing tokens to tokens. */
262 typedef struct c_token
GTY (())
264 /* The kind of token. */
265 ENUM_BITFIELD (cpp_ttype
) type
: 8;
266 /* If this token is a CPP_NAME, this value indicates whether also
267 declared as some kind of type. Otherwise, it is C_ID_NONE. */
268 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
269 /* If this token is a keyword, this value indicates which keyword.
270 Otherwise, this value is RID_MAX. */
271 ENUM_BITFIELD (rid
) keyword
: 8;
272 /* If this token is a CPP_PRAGMA, this indicates the pragma that
273 was seen. Otherwise it is PRAGMA_NONE. */
274 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 7;
275 /* True if this token is from a system header. */
276 BOOL_BITFIELD in_system_header
: 1;
277 /* The value associated with this token, if any. */
279 /* The location at which this token was found. */
283 /* A parser structure recording information about the state and
284 context of parsing. Includes lexer information with up to two
285 tokens of look-ahead; more are not needed for C. */
286 typedef struct c_parser
GTY(())
288 /* The look-ahead tokens. */
290 /* How many look-ahead tokens are available (0, 1 or 2). */
292 /* True if a syntax error is being recovered from; false otherwise.
293 c_parser_error sets this flag. It should clear this flag when
294 enough tokens have been consumed to recover from the error. */
295 BOOL_BITFIELD error
: 1;
296 /* True if we're processing a pragma, and shouldn't automatically
297 consume CPP_PRAGMA_EOL. */
298 BOOL_BITFIELD in_pragma
: 1;
302 /* The actual parser and external interface. ??? Does this need to be
303 garbage-collected? */
305 static GTY (()) c_parser
*the_parser
;
308 /* Read in and lex a single token, storing it in *TOKEN. */
311 c_lex_one_token (c_token
*token
)
313 timevar_push (TV_LEX
);
315 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
);
316 token
->id_kind
= C_ID_NONE
;
317 token
->keyword
= RID_MAX
;
318 token
->pragma_kind
= PRAGMA_NONE
;
319 token
->in_system_header
= in_system_header
;
327 int objc_force_identifier
= objc_need_raw_identifier
;
328 OBJC_NEED_RAW_IDENTIFIER (0);
330 if (C_IS_RESERVED_WORD (token
->value
))
332 enum rid rid_code
= C_RID_CODE (token
->value
);
334 if (c_dialect_objc ())
336 if (!OBJC_IS_AT_KEYWORD (rid_code
)
337 && (!OBJC_IS_PQ_KEYWORD (rid_code
) || objc_pq_context
))
339 /* Return the canonical spelling for this keyword. */
340 token
->value
= ridpointers
[(int) rid_code
];
341 token
->type
= CPP_KEYWORD
;
342 token
->keyword
= rid_code
;
348 /* Return the canonical spelling for this keyword. */
349 token
->value
= ridpointers
[(int) rid_code
];
350 token
->type
= CPP_KEYWORD
;
351 token
->keyword
= rid_code
;
356 decl
= lookup_name (token
->value
);
359 if (TREE_CODE (decl
) == TYPE_DECL
)
361 token
->id_kind
= C_ID_TYPENAME
;
365 else if (c_dialect_objc ())
367 tree objc_interface_decl
= objc_is_class_name (token
->value
);
368 /* Objective-C class names are in the same namespace as
369 variables and typedefs, and hence are shadowed by local
371 if (objc_interface_decl
372 && (global_bindings_p ()
373 || (!objc_force_identifier
&& !decl
)))
375 token
->value
= objc_interface_decl
;
376 token
->id_kind
= C_ID_CLASSNAME
;
380 token
->id_kind
= C_ID_ID
;
384 /* This only happens in Objective-C; it must be a keyword. */
385 token
->type
= CPP_KEYWORD
;
386 token
->keyword
= C_RID_CODE (token
->value
);
390 case CPP_CLOSE_PAREN
:
392 /* These tokens may affect the interpretation of any identifiers
393 following, if doing Objective-C. */
394 OBJC_NEED_RAW_IDENTIFIER (0);
397 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
398 token
->pragma_kind
= TREE_INT_CST_LOW (token
->value
);
404 timevar_pop (TV_LEX
);
407 /* Return a pointer to the next token from PARSER, reading it in if
410 static inline c_token
*
411 c_parser_peek_token (c_parser
*parser
)
413 if (parser
->tokens_avail
== 0)
415 c_lex_one_token (&parser
->tokens
[0]);
416 parser
->tokens_avail
= 1;
418 return &parser
->tokens
[0];
421 /* Return true if the next token from PARSER has the indicated
425 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
427 return c_parser_peek_token (parser
)->type
== type
;
430 /* Return true if the next token from PARSER does not have the
434 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
436 return !c_parser_next_token_is (parser
, type
);
439 /* Return true if the next token from PARSER is the indicated
443 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
447 /* Peek at the next token. */
448 token
= c_parser_peek_token (parser
);
449 /* Check to see if it is the indicated keyword. */
450 return token
->keyword
== keyword
;
453 /* Return true if TOKEN can start a type name,
456 c_token_starts_typename (c_token
*token
)
461 switch (token
->id_kind
)
468 gcc_assert (c_dialect_objc ());
474 switch (token
->keyword
)
503 if (c_dialect_objc ())
511 /* Return true if the next token from PARSER can start a type name,
514 c_parser_next_token_starts_typename (c_parser
*parser
)
516 c_token
*token
= c_parser_peek_token (parser
);
517 return c_token_starts_typename (token
);
520 /* Return true if TOKEN can start declaration specifiers, false
523 c_token_starts_declspecs (c_token
*token
)
528 switch (token
->id_kind
)
535 gcc_assert (c_dialect_objc ());
541 switch (token
->keyword
)
577 if (c_dialect_objc ())
585 /* Return true if the next token from PARSER can start declaration
586 specifiers, false otherwise. */
588 c_parser_next_token_starts_declspecs (c_parser
*parser
)
590 c_token
*token
= c_parser_peek_token (parser
);
591 return c_token_starts_declspecs (token
);
594 /* Return a pointer to the next-but-one token from PARSER, reading it
595 in if necessary. The next token is already read in. */
598 c_parser_peek_2nd_token (c_parser
*parser
)
600 if (parser
->tokens_avail
>= 2)
601 return &parser
->tokens
[1];
602 gcc_assert (parser
->tokens_avail
== 1);
603 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
604 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
605 c_lex_one_token (&parser
->tokens
[1]);
606 parser
->tokens_avail
= 2;
607 return &parser
->tokens
[1];
610 /* Consume the next token from PARSER. */
613 c_parser_consume_token (c_parser
*parser
)
615 gcc_assert (parser
->tokens_avail
>= 1);
616 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
617 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
618 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
619 if (parser
->tokens_avail
== 2)
620 parser
->tokens
[0] = parser
->tokens
[1];
621 parser
->tokens_avail
--;
624 /* Expect the current token to be a #pragma. Consume it and remember
625 that we've begun parsing a pragma. */
628 c_parser_consume_pragma (c_parser
*parser
)
630 gcc_assert (!parser
->in_pragma
);
631 gcc_assert (parser
->tokens_avail
>= 1);
632 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
633 if (parser
->tokens_avail
== 2)
634 parser
->tokens
[0] = parser
->tokens
[1];
635 parser
->tokens_avail
--;
636 parser
->in_pragma
= true;
639 /* Update the globals input_location and in_system_header from
642 c_parser_set_source_position_from_token (c_token
*token
)
644 if (token
->type
!= CPP_EOF
)
646 input_location
= token
->location
;
647 in_system_header
= token
->in_system_header
;
651 /* Issue a diagnostic of the form
652 FILE:LINE: MESSAGE before TOKEN
653 where TOKEN is the next token in the input stream of PARSER.
654 MESSAGE (specified by the caller) is usually of the form "expected
657 Do not issue a diagnostic if still recovering from an error.
659 ??? This is taken from the C++ parser, but building up messages in
660 this way is not i18n-friendly and some other approach should be
664 c_parser_error (c_parser
*parser
, const char *gmsgid
)
666 c_token
*token
= c_parser_peek_token (parser
);
669 parser
->error
= true;
672 /* This diagnostic makes more sense if it is tagged to the line of
673 the token we just peeked at. */
674 c_parser_set_source_position_from_token (token
);
675 c_parse_error (gmsgid
,
676 /* Because c_parse_error does not understand
677 CPP_KEYWORD, keywords are treated like
679 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
683 /* If the next token is of the indicated TYPE, consume it. Otherwise,
684 issue the error MSGID. If MSGID is NULL then a message has already
685 been produced and no message will be produced this time. Returns
686 true if found, false otherwise. */
689 c_parser_require (c_parser
*parser
,
693 if (c_parser_next_token_is (parser
, type
))
695 c_parser_consume_token (parser
);
700 c_parser_error (parser
, msgid
);
705 /* If the next token is the indicated keyword, consume it. Otherwise,
706 issue the error MSGID. Returns true if found, false otherwise. */
709 c_parser_require_keyword (c_parser
*parser
,
713 if (c_parser_next_token_is_keyword (parser
, keyword
))
715 c_parser_consume_token (parser
);
720 c_parser_error (parser
, msgid
);
725 /* Like c_parser_require, except that tokens will be skipped until the
726 desired token is found. An error message is still produced if the
727 next token is not as expected. If MSGID is NULL then a message has
728 already been produced and no message will be produced this
732 c_parser_skip_until_found (c_parser
*parser
,
736 unsigned nesting_depth
= 0;
738 if (c_parser_require (parser
, type
, msgid
))
741 /* Skip tokens until the desired token is found. */
744 /* Peek at the next token. */
745 c_token
*token
= c_parser_peek_token (parser
);
746 /* If we've reached the token we want, consume it and stop. */
747 if (token
->type
== type
&& !nesting_depth
)
749 c_parser_consume_token (parser
);
753 /* If we've run out of tokens, stop. */
754 if (token
->type
== CPP_EOF
)
756 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
758 if (token
->type
== CPP_OPEN_BRACE
759 || token
->type
== CPP_OPEN_PAREN
760 || token
->type
== CPP_OPEN_SQUARE
)
762 else if (token
->type
== CPP_CLOSE_BRACE
763 || token
->type
== CPP_CLOSE_PAREN
764 || token
->type
== CPP_CLOSE_SQUARE
)
766 if (nesting_depth
-- == 0)
769 /* Consume this token. */
770 c_parser_consume_token (parser
);
772 parser
->error
= false;
775 /* Skip tokens until the end of a parameter is found, but do not
776 consume the comma, semicolon or closing delimiter. */
779 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
781 unsigned nesting_depth
= 0;
785 c_token
*token
= c_parser_peek_token (parser
);
786 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
789 /* If we've run out of tokens, stop. */
790 if (token
->type
== CPP_EOF
)
792 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
794 if (token
->type
== CPP_OPEN_BRACE
795 || token
->type
== CPP_OPEN_PAREN
796 || token
->type
== CPP_OPEN_SQUARE
)
798 else if (token
->type
== CPP_CLOSE_BRACE
799 || token
->type
== CPP_CLOSE_PAREN
800 || token
->type
== CPP_CLOSE_SQUARE
)
802 if (nesting_depth
-- == 0)
805 /* Consume this token. */
806 c_parser_consume_token (parser
);
808 parser
->error
= false;
811 /* Skip tokens until we have consumed an entire block, or until we
812 have consumed a non-nested ';'. */
815 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
817 unsigned nesting_depth
= 0;
823 /* Peek at the next token. */
824 token
= c_parser_peek_token (parser
);
825 /* If we've run out of tokens, stop. */
826 if (token
->type
== CPP_EOF
)
828 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
830 /* If the next token is a ';', we have reached the end of the
832 if (token
->type
== CPP_SEMICOLON
&& !nesting_depth
)
834 /* Consume the ';'. */
835 c_parser_consume_token (parser
);
838 /* If the next token is a non-nested '}', then we have reached
839 the end of the current block. */
840 if (token
->type
== CPP_CLOSE_BRACE
841 && (nesting_depth
== 0 || --nesting_depth
== 0))
843 c_parser_consume_token (parser
);
846 /* If it the next token is a '{', then we are entering a new
847 block. Consume the entire block. */
848 if (token
->type
== CPP_OPEN_BRACE
)
850 c_parser_consume_token (parser
);
852 parser
->error
= false;
855 /* Expect to be at the end of the pragma directive and consume an
856 end of line marker. */
859 c_parser_skip_to_pragma_eol (c_parser
*parser
)
861 gcc_assert (parser
->in_pragma
);
862 parser
->in_pragma
= false;
864 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
867 c_token
*token
= c_parser_peek_token (parser
);
868 if (token
->type
== CPP_EOF
)
870 if (token
->type
== CPP_PRAGMA_EOL
)
872 c_parser_consume_token (parser
);
875 c_parser_consume_token (parser
);
878 parser
->error
= false;
881 /* Save the warning flags which are controlled by __extension__. */
884 disable_extension_diagnostics (void)
887 | (warn_pointer_arith
<< 1)
888 | (warn_traditional
<< 2)
891 warn_pointer_arith
= 0;
892 warn_traditional
= 0;
897 /* Restore the warning flags which are controlled by __extension__.
898 FLAGS is the return value from disable_extension_diagnostics. */
901 restore_extension_diagnostics (int flags
)
903 pedantic
= flags
& 1;
904 warn_pointer_arith
= (flags
>> 1) & 1;
905 warn_traditional
= (flags
>> 2) & 1;
906 flag_iso
= (flags
>> 3) & 1;
909 /* Possibly kinds of declarator to parse. */
910 typedef enum c_dtr_syn
{
911 /* A normal declarator with an identifier. */
913 /* An abstract declarator (maybe empty). */
915 /* A parameter declarator: may be either, but after a type name does
916 not redeclare a typedef name as an identifier if it can
917 alternatively be interpreted as a typedef name; see DR#009,
918 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
919 following DR#249. For example, given a typedef T, "int T" and
920 "int *T" are valid parameter declarations redeclaring T, while
921 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
922 abstract declarators rather than involving redundant parentheses;
923 the same applies with attributes inside the parentheses before
928 static void c_parser_external_declaration (c_parser
*);
929 static void c_parser_asm_definition (c_parser
*);
930 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
931 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
933 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
934 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
935 static tree
c_parser_struct_declaration (c_parser
*);
936 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
937 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
939 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
941 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
943 struct c_declarator
*);
944 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
945 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
946 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
947 static tree
c_parser_simple_asm_expr (c_parser
*);
948 static tree
c_parser_attributes (c_parser
*);
949 static struct c_type_name
*c_parser_type_name (c_parser
*);
950 static struct c_expr
c_parser_initializer (c_parser
*);
951 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
952 static void c_parser_initelt (c_parser
*);
953 static void c_parser_initval (c_parser
*, struct c_expr
*);
954 static tree
c_parser_compound_statement (c_parser
*);
955 static void c_parser_compound_statement_nostart (c_parser
*);
956 static void c_parser_label (c_parser
*);
957 static void c_parser_statement (c_parser
*);
958 static void c_parser_statement_after_labels (c_parser
*);
959 static void c_parser_if_statement (c_parser
*);
960 static void c_parser_switch_statement (c_parser
*);
961 static void c_parser_while_statement (c_parser
*);
962 static void c_parser_do_statement (c_parser
*);
963 static void c_parser_for_statement (c_parser
*);
964 static tree
c_parser_asm_statement (c_parser
*);
965 static tree
c_parser_asm_operands (c_parser
*, bool);
966 static tree
c_parser_asm_clobbers (c_parser
*);
967 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
968 static struct c_expr
c_parser_conditional_expression (c_parser
*,
970 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
971 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
972 static struct c_expr
c_parser_unary_expression (c_parser
*);
973 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
974 static struct c_expr
c_parser_alignof_expression (c_parser
*);
975 static struct c_expr
c_parser_postfix_expression (c_parser
*);
976 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
977 struct c_type_name
*);
978 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
980 static struct c_expr
c_parser_expression (c_parser
*);
981 static struct c_expr
c_parser_expression_conv (c_parser
*);
982 static tree
c_parser_expr_list (c_parser
*, bool);
984 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
985 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
987 /* These Objective-C parser functions are only ever called when
988 compiling Objective-C. */
989 static void c_parser_objc_class_definition (c_parser
*);
990 static void c_parser_objc_class_instance_variables (c_parser
*);
991 static void c_parser_objc_class_declaration (c_parser
*);
992 static void c_parser_objc_alias_declaration (c_parser
*);
993 static void c_parser_objc_protocol_definition (c_parser
*);
994 static enum tree_code
c_parser_objc_method_type (c_parser
*);
995 static void c_parser_objc_method_definition (c_parser
*);
996 static void c_parser_objc_methodprotolist (c_parser
*);
997 static void c_parser_objc_methodproto (c_parser
*);
998 static tree
c_parser_objc_method_decl (c_parser
*);
999 static tree
c_parser_objc_type_name (c_parser
*);
1000 static tree
c_parser_objc_protocol_refs (c_parser
*);
1001 static void c_parser_objc_try_catch_statement (c_parser
*);
1002 static void c_parser_objc_synchronized_statement (c_parser
*);
1003 static tree
c_parser_objc_selector (c_parser
*);
1004 static tree
c_parser_objc_selector_arg (c_parser
*);
1005 static tree
c_parser_objc_receiver (c_parser
*);
1006 static tree
c_parser_objc_message_args (c_parser
*);
1007 static tree
c_parser_objc_keywordexpr (c_parser
*);
1009 /* Parse a translation unit (C90 6.7, C99 6.9).
1012 external-declarations
1014 external-declarations:
1015 external-declaration
1016 external-declarations external-declaration
1025 c_parser_translation_unit (c_parser
*parser
)
1027 if (c_parser_next_token_is (parser
, CPP_EOF
))
1030 pedwarn ("ISO C forbids an empty source file");
1034 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1038 c_parser_external_declaration (parser
);
1039 obstack_free (&parser_obstack
, obstack_position
);
1041 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1045 /* Parse an external declaration (C90 6.7, C99 6.9).
1047 external-declaration:
1053 external-declaration:
1056 __extension__ external-declaration
1060 external-declaration:
1061 objc-class-definition
1062 objc-class-declaration
1063 objc-alias-declaration
1064 objc-protocol-definition
1065 objc-method-definition
1070 c_parser_external_declaration (c_parser
*parser
)
1073 switch (c_parser_peek_token (parser
)->type
)
1076 switch (c_parser_peek_token (parser
)->keyword
)
1079 ext
= disable_extension_diagnostics ();
1080 c_parser_consume_token (parser
);
1081 c_parser_external_declaration (parser
);
1082 restore_extension_diagnostics (ext
);
1085 c_parser_asm_definition (parser
);
1087 case RID_AT_INTERFACE
:
1088 case RID_AT_IMPLEMENTATION
:
1089 gcc_assert (c_dialect_objc ());
1090 c_parser_objc_class_definition (parser
);
1093 gcc_assert (c_dialect_objc ());
1094 c_parser_objc_class_declaration (parser
);
1097 gcc_assert (c_dialect_objc ());
1098 c_parser_objc_alias_declaration (parser
);
1100 case RID_AT_PROTOCOL
:
1101 gcc_assert (c_dialect_objc ());
1102 c_parser_objc_protocol_definition (parser
);
1105 gcc_assert (c_dialect_objc ());
1106 c_parser_consume_token (parser
);
1107 objc_finish_implementation ();
1115 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1116 c_parser_consume_token (parser
);
1119 c_parser_pragma (parser
, pragma_external
);
1123 if (c_dialect_objc ())
1125 c_parser_objc_method_definition (parser
);
1128 /* Else fall through, and yield a syntax error trying to parse
1129 as a declaration or function definition. */
1132 /* A declaration or a function definition. We can only tell
1133 which after parsing the declaration specifiers, if any, and
1134 the first declarator. */
1135 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1141 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1142 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1143 accepted; otherwise (old-style parameter declarations) only other
1144 declarations are accepted. If NESTED is true, we are inside a
1145 function or parsing old-style parameter declarations; any functions
1146 encountered are nested functions and declaration specifiers are
1147 required; otherwise we are at top level and functions are normal
1148 functions and declaration specifiers may be optional. If EMPTY_OK
1149 is true, empty declarations are OK (subject to all other
1150 constraints); otherwise (old-style parameter declarations) they are
1151 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1152 may start with attributes; otherwise they may not.
1155 declaration-specifiers init-declarator-list[opt] ;
1157 function-definition:
1158 declaration-specifiers[opt] declarator declaration-list[opt]
1163 declaration-list declaration
1165 init-declarator-list:
1167 init-declarator-list , init-declarator
1170 declarator simple-asm-expr[opt] attributes[opt]
1171 declarator simple-asm-expr[opt] attributes[opt] = initializer
1175 nested-function-definition:
1176 declaration-specifiers declarator declaration-list[opt]
1179 The simple-asm-expr and attributes are GNU extensions.
1181 This function does not handle __extension__; that is handled in its
1182 callers. ??? Following the old parser, __extension__ may start
1183 external declarations, declarations in functions and declarations
1184 at the start of "for" loops, but not old-style parameter
1187 C99 requires declaration specifiers in a function definition; the
1188 absence is diagnosed through the diagnosis of implicit int. In GNU
1189 C we also allow but diagnose declarations without declaration
1190 specifiers, but only at top level (elsewhere they conflict with
1194 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1195 bool nested
, bool start_attr_ok
)
1197 struct c_declspecs
*specs
;
1199 tree all_prefix_attrs
;
1200 bool diagnosed_no_specs
= false;
1202 specs
= build_null_declspecs ();
1203 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1206 c_parser_skip_to_end_of_block_or_statement (parser
);
1209 if (nested
&& !specs
->declspecs_seen_p
)
1211 c_parser_error (parser
, "expected declaration specifiers");
1212 c_parser_skip_to_end_of_block_or_statement (parser
);
1215 finish_declspecs (specs
);
1216 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1222 shadow_tag_warned (specs
, 1);
1223 pedwarn ("empty declaration");
1225 c_parser_consume_token (parser
);
1228 pending_xref_error ();
1229 prefix_attrs
= specs
->attrs
;
1230 all_prefix_attrs
= prefix_attrs
;
1231 specs
->attrs
= NULL_TREE
;
1234 struct c_declarator
*declarator
;
1237 /* Declaring either one or more declarators (in which case we
1238 should diagnose if there were no declaration specifiers) or a
1239 function definition (in which case the diagnostic for
1240 implicit int suffices). */
1241 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1242 C_DTR_NORMAL
, &dummy
);
1243 if (declarator
== NULL
)
1245 c_parser_skip_to_end_of_block_or_statement (parser
);
1248 if (c_parser_next_token_is (parser
, CPP_EQ
)
1249 || c_parser_next_token_is (parser
, CPP_COMMA
)
1250 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1251 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1252 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1254 tree asm_name
= NULL_TREE
;
1255 tree postfix_attrs
= NULL_TREE
;
1256 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1258 diagnosed_no_specs
= true;
1259 pedwarn ("data definition has no type or storage class");
1261 /* Having seen a data definition, there cannot now be a
1262 function definition. */
1264 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1265 asm_name
= c_parser_simple_asm_expr (parser
);
1266 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1267 postfix_attrs
= c_parser_attributes (parser
);
1268 if (c_parser_next_token_is (parser
, CPP_EQ
))
1272 c_parser_consume_token (parser
);
1273 /* The declaration of the variable is in effect while
1274 its initializer is parsed. */
1275 d
= start_decl (declarator
, specs
, true,
1276 chainon (postfix_attrs
, all_prefix_attrs
));
1278 d
= error_mark_node
;
1279 start_init (d
, asm_name
, global_bindings_p ());
1280 init
= c_parser_initializer (parser
);
1282 if (d
!= error_mark_node
)
1284 maybe_warn_string_init (TREE_TYPE (d
), init
);
1285 finish_decl (d
, init
.value
, asm_name
);
1290 tree d
= start_decl (declarator
, specs
, false,
1291 chainon (postfix_attrs
,
1294 finish_decl (d
, NULL_TREE
, asm_name
);
1296 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1298 c_parser_consume_token (parser
);
1299 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1300 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1303 all_prefix_attrs
= prefix_attrs
;
1306 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1308 c_parser_consume_token (parser
);
1313 c_parser_error (parser
, "expected %<,%> or %<;%>");
1314 c_parser_skip_to_end_of_block_or_statement (parser
);
1320 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1321 "%<asm%> or %<__attribute__%>");
1322 c_parser_skip_to_end_of_block_or_statement (parser
);
1325 /* Function definition (nested or otherwise). */
1329 pedwarn ("ISO C forbids nested functions");
1330 push_function_context ();
1332 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1334 /* This can appear in many cases looking nothing like a
1335 function definition, so we don't give a more specific
1336 error suggesting there was one. */
1337 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1338 "or %<__attribute__%>");
1340 pop_function_context ();
1343 /* Parse old-style parameter declarations. ??? Attributes are
1344 not allowed to start declaration specifiers here because of a
1345 syntax conflict between a function declaration with attribute
1346 suffix and a function definition with an attribute prefix on
1347 first old-style parameter declaration. Following the old
1348 parser, they are not accepted on subsequent old-style
1349 parameter declarations either. However, there is no
1350 ambiguity after the first declaration, nor indeed on the
1351 first as long as we don't allow postfix attributes after a
1352 declarator with a nonempty identifier list in a definition;
1353 and postfix attributes have never been accepted here in
1354 function definitions either. */
1355 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1356 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1357 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1358 DECL_SOURCE_LOCATION (current_function_decl
)
1359 = c_parser_peek_token (parser
)->location
;
1360 store_parm_decls ();
1361 fnbody
= c_parser_compound_statement (parser
);
1364 tree decl
= current_function_decl
;
1367 pop_function_context ();
1368 add_stmt (build_stmt (DECL_EXPR
, decl
));
1379 /* Parse an asm-definition (asm() outside a function body). This is a
1387 c_parser_asm_definition (c_parser
*parser
)
1389 tree asm_str
= c_parser_simple_asm_expr (parser
);
1390 /* ??? This only works sensibly in the presence of
1391 -fno-unit-at-a-time; file-scope asms really need to be passed to
1392 cgraph which needs to preserve the order of functions and
1395 assemble_asm (asm_str
);
1396 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1399 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1400 6.7), adding them to SPECS (which may already include some).
1401 Storage class specifiers are accepted iff SCSPEC_OK; type
1402 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1403 the start iff START_ATTR_OK.
1405 declaration-specifiers:
1406 storage-class-specifier declaration-specifiers[opt]
1407 type-specifier declaration-specifiers[opt]
1408 type-qualifier declaration-specifiers[opt]
1409 function-specifier declaration-specifiers[opt]
1411 Function specifiers (inline) are from C99, and are currently
1412 handled as storage class specifiers, as is __thread.
1414 C90 6.5.1, C99 6.7.1:
1415 storage-class-specifier:
1426 C90 6.5.2, C99 6.7.2:
1439 [_Imaginary removed in C99 TC2]
1440 struct-or-union-specifier
1444 (_Bool and _Complex are new in C99.)
1446 C90 6.5.3, C99 6.7.3:
1453 (restrict is new in C99.)
1457 declaration-specifiers:
1458 attributes declaration-specifiers[opt]
1460 storage-class-specifier:
1472 class-name objc-protocol-refs[opt]
1473 typedef-name objc-protocol-refs
1478 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1479 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1481 bool attrs_ok
= start_attr_ok
;
1482 bool seen_type
= specs
->type_seen_p
;
1483 while (c_parser_next_token_is (parser
, CPP_NAME
)
1484 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1485 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1487 struct c_typespec t
;
1489 if (c_parser_next_token_is (parser
, CPP_NAME
))
1491 tree value
= c_parser_peek_token (parser
)->value
;
1492 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1493 /* This finishes the specifiers unless a type name is OK, it
1494 is declared as a type name and a type name hasn't yet
1496 if (!typespec_ok
|| seen_type
1497 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1499 c_parser_consume_token (parser
);
1502 if (kind
== C_ID_TYPENAME
1503 && (!c_dialect_objc ()
1504 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1506 t
.kind
= ctsk_typedef
;
1507 /* For a typedef name, record the meaning, not the name.
1508 In case of 'foo foo, bar;'. */
1509 t
.spec
= lookup_name (value
);
1513 tree proto
= NULL_TREE
;
1514 gcc_assert (c_dialect_objc ());
1516 if (c_parser_next_token_is (parser
, CPP_LESS
))
1517 proto
= c_parser_objc_protocol_refs (parser
);
1518 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1520 declspecs_add_type (specs
, t
);
1523 if (c_parser_next_token_is (parser
, CPP_LESS
))
1525 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1526 nisse@lysator.liu.se. */
1528 gcc_assert (c_dialect_objc ());
1529 if (!typespec_ok
|| seen_type
)
1531 proto
= c_parser_objc_protocol_refs (parser
);
1533 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1534 declspecs_add_type (specs
, t
);
1537 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1538 switch (c_parser_peek_token (parser
)->keyword
)
1550 /* TODO: Distinguish between function specifiers (inline)
1551 and storage class specifiers, either here or in
1552 declspecs_add_scspec. */
1553 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1554 c_parser_consume_token (parser
);
1574 OBJC_NEED_RAW_IDENTIFIER (1);
1575 t
.kind
= ctsk_resword
;
1576 t
.spec
= c_parser_peek_token (parser
)->value
;
1577 declspecs_add_type (specs
, t
);
1578 c_parser_consume_token (parser
);
1585 t
= c_parser_enum_specifier (parser
);
1586 declspecs_add_type (specs
, t
);
1594 t
= c_parser_struct_or_union_specifier (parser
);
1595 declspecs_add_type (specs
, t
);
1598 /* ??? The old parser rejected typeof after other type
1599 specifiers, but is a syntax error the best way of
1601 if (!typespec_ok
|| seen_type
)
1605 t
= c_parser_typeof_specifier (parser
);
1606 declspecs_add_type (specs
, t
);
1612 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1613 c_parser_consume_token (parser
);
1618 attrs
= c_parser_attributes (parser
);
1619 declspecs_add_attrs (specs
, attrs
);
1628 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1631 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1632 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1633 enum attributes[opt] identifier
1635 The form with trailing comma is new in C99. The forms with
1636 attributes are GNU extensions. In GNU C, we accept any expression
1637 without commas in the syntax (assignment expressions, not just
1638 conditional expressions); assignment expressions will be diagnosed
1643 enumerator-list , enumerator
1646 enumeration-constant
1647 enumeration-constant = constant-expression
1650 static struct c_typespec
1651 c_parser_enum_specifier (c_parser
*parser
)
1653 struct c_typespec ret
;
1655 tree ident
= NULL_TREE
;
1656 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1657 c_parser_consume_token (parser
);
1658 attrs
= c_parser_attributes (parser
);
1659 if (c_parser_next_token_is (parser
, CPP_NAME
))
1661 ident
= c_parser_peek_token (parser
)->value
;
1662 c_parser_consume_token (parser
);
1664 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1666 /* Parse an enum definition. */
1667 tree type
= start_enum (ident
);
1669 /* We chain the enumerators in reverse order, then put them in
1670 forward order at the end. */
1671 tree values
= NULL_TREE
;
1672 c_parser_consume_token (parser
);
1679 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1681 c_parser_error (parser
, "expected identifier");
1682 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1683 values
= error_mark_node
;
1686 enum_id
= c_parser_peek_token (parser
)->value
;
1687 c_parser_consume_token (parser
);
1688 if (c_parser_next_token_is (parser
, CPP_EQ
))
1690 c_parser_consume_token (parser
);
1691 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1694 enum_value
= NULL_TREE
;
1695 enum_decl
= build_enumerator (enum_id
, enum_value
);
1696 TREE_CHAIN (enum_decl
) = values
;
1699 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1702 c_parser_consume_token (parser
);
1704 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1706 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1707 pedwarn ("comma at end of enumerator list");
1708 c_parser_consume_token (parser
);
1713 c_parser_error (parser
, "expected %<,%> or %<}%>");
1714 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1715 values
= error_mark_node
;
1719 postfix_attrs
= c_parser_attributes (parser
);
1720 ret
.spec
= finish_enum (type
, nreverse (values
),
1721 chainon (attrs
, postfix_attrs
));
1722 ret
.kind
= ctsk_tagdef
;
1727 c_parser_error (parser
, "expected %<{%>");
1728 ret
.spec
= error_mark_node
;
1729 ret
.kind
= ctsk_tagref
;
1732 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1733 /* In ISO C, enumerated types can be referred to only if already
1735 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1736 pedwarn ("ISO C forbids forward references to %<enum%> types");
1740 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1742 struct-or-union-specifier:
1743 struct-or-union attributes[opt] identifier[opt]
1744 { struct-contents } attributes[opt]
1745 struct-or-union attributes[opt] identifier
1748 struct-declaration-list
1750 struct-declaration-list:
1751 struct-declaration ;
1752 struct-declaration-list struct-declaration ;
1759 struct-declaration-list struct-declaration
1761 struct-declaration-list:
1762 struct-declaration-list ;
1765 (Note that in the syntax here, unlike that in ISO C, the semicolons
1766 are included here rather than in struct-declaration, in order to
1767 describe the syntax with extra semicolons and missing semicolon at
1772 struct-declaration-list:
1773 @defs ( class-name )
1775 (Note this does not include a trailing semicolon, but can be
1776 followed by further declarations, and gets a pedwarn-if-pedantic
1777 when followed by a semicolon.) */
1779 static struct c_typespec
1780 c_parser_struct_or_union_specifier (c_parser
*parser
)
1782 struct c_typespec ret
;
1784 tree ident
= NULL_TREE
;
1785 enum tree_code code
;
1786 switch (c_parser_peek_token (parser
)->keyword
)
1797 c_parser_consume_token (parser
);
1798 attrs
= c_parser_attributes (parser
);
1799 if (c_parser_next_token_is (parser
, CPP_NAME
))
1801 ident
= c_parser_peek_token (parser
)->value
;
1802 c_parser_consume_token (parser
);
1804 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1806 /* Parse a struct or union definition. Start the scope of the
1807 tag before parsing components. */
1808 tree type
= start_struct (code
, ident
);
1810 /* We chain the components in reverse order, then put them in
1811 forward order at the end. Each struct-declaration may
1812 declare multiple components (comma-separated), so we must use
1813 chainon to join them, although when parsing each
1814 struct-declaration we can use TREE_CHAIN directly.
1816 The theory behind all this is that there will be more
1817 semicolon separated fields than comma separated fields, and
1818 so we'll be minimizing the number of node traversals required
1820 tree contents
= NULL_TREE
;
1821 c_parser_consume_token (parser
);
1822 /* Handle the Objective-C @defs construct,
1823 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1824 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1827 gcc_assert (c_dialect_objc ());
1828 c_parser_consume_token (parser
);
1829 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1831 if (c_parser_next_token_is (parser
, CPP_NAME
)
1832 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1834 name
= c_parser_peek_token (parser
)->value
;
1835 c_parser_consume_token (parser
);
1839 c_parser_error (parser
, "expected class name");
1840 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1843 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1845 contents
= nreverse (objc_get_class_ivars (name
));
1848 /* Parse the struct-declarations and semicolons. Problems with
1849 semicolons are diagnosed here; empty structures are diagnosed
1854 /* Parse any stray semicolon. */
1855 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1858 pedwarn ("extra semicolon in struct or union specified");
1859 c_parser_consume_token (parser
);
1862 /* Stop if at the end of the struct or union contents. */
1863 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1865 c_parser_consume_token (parser
);
1868 /* Accept #pragmas at struct scope. */
1869 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1871 c_parser_pragma (parser
, pragma_external
);
1874 /* Parse some comma-separated declarations, but not the
1875 trailing semicolon if any. */
1876 decls
= c_parser_struct_declaration (parser
);
1877 contents
= chainon (decls
, contents
);
1878 /* If no semicolon follows, either we have a parse error or
1879 are at the end of the struct or union and should
1881 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1882 c_parser_consume_token (parser
);
1885 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1886 pedwarn ("no semicolon at end of struct or union");
1889 c_parser_error (parser
, "expected %<;%>");
1890 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1895 postfix_attrs
= c_parser_attributes (parser
);
1896 ret
.spec
= finish_struct (type
, nreverse (contents
),
1897 chainon (attrs
, postfix_attrs
));
1898 ret
.kind
= ctsk_tagdef
;
1903 c_parser_error (parser
, "expected %<{%>");
1904 ret
.spec
= error_mark_node
;
1905 ret
.kind
= ctsk_tagref
;
1908 ret
= parser_xref_tag (code
, ident
);
1912 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1913 the trailing semicolon.
1916 specifier-qualifier-list struct-declarator-list
1918 specifier-qualifier-list:
1919 type-specifier specifier-qualifier-list[opt]
1920 type-qualifier specifier-qualifier-list[opt]
1921 attributes specifier-qualifier-list[opt]
1923 struct-declarator-list:
1925 struct-declarator-list , attributes[opt] struct-declarator
1928 declarator attributes[opt]
1929 declarator[opt] : constant-expression attributes[opt]
1934 __extension__ struct-declaration
1935 specifier-qualifier-list
1937 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1938 of attributes where shown is a GNU extension. In GNU C, we accept
1939 any expression without commas in the syntax (assignment
1940 expressions, not just conditional expressions); assignment
1941 expressions will be diagnosed as non-constant. */
1944 c_parser_struct_declaration (c_parser
*parser
)
1946 struct c_declspecs
*specs
;
1948 tree all_prefix_attrs
;
1950 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1954 ext
= disable_extension_diagnostics ();
1955 c_parser_consume_token (parser
);
1956 decl
= c_parser_struct_declaration (parser
);
1957 restore_extension_diagnostics (ext
);
1960 specs
= build_null_declspecs ();
1961 c_parser_declspecs (parser
, specs
, false, true, true);
1964 if (!specs
->declspecs_seen_p
)
1966 c_parser_error (parser
, "expected specifier-qualifier-list");
1969 finish_declspecs (specs
);
1970 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1973 if (!specs
->type_seen_p
)
1976 pedwarn ("ISO C forbids member declarations with no members");
1977 shadow_tag_warned (specs
, pedantic
);
1982 /* Support for unnamed structs or unions as members of
1983 structs or unions (which is [a] useful and [b] supports
1985 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
, NULL_TREE
);
1989 pending_xref_error ();
1990 prefix_attrs
= specs
->attrs
;
1991 all_prefix_attrs
= prefix_attrs
;
1992 specs
->attrs
= NULL_TREE
;
1996 /* Declaring one or more declarators or un-named bit-fields. */
1997 struct c_declarator
*declarator
;
1999 if (c_parser_next_token_is (parser
, CPP_COLON
))
2000 declarator
= build_id_declarator (NULL_TREE
);
2002 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2003 C_DTR_NORMAL
, &dummy
);
2004 if (declarator
== NULL
)
2006 c_parser_skip_to_end_of_block_or_statement (parser
);
2009 if (c_parser_next_token_is (parser
, CPP_COLON
)
2010 || c_parser_next_token_is (parser
, CPP_COMMA
)
2011 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2012 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2013 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2015 tree postfix_attrs
= NULL_TREE
;
2016 tree width
= NULL_TREE
;
2018 if (c_parser_next_token_is (parser
, CPP_COLON
))
2020 c_parser_consume_token (parser
);
2021 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2023 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2024 postfix_attrs
= c_parser_attributes (parser
);
2025 d
= grokfield (declarator
, specs
, width
);
2026 decl_attributes (&d
, chainon (postfix_attrs
,
2027 all_prefix_attrs
), 0);
2028 TREE_CHAIN (d
) = decls
;
2030 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2031 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2034 all_prefix_attrs
= prefix_attrs
;
2035 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2036 c_parser_consume_token (parser
);
2037 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2038 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2040 /* Semicolon consumed in caller. */
2045 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2051 c_parser_error (parser
,
2052 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2053 "%<__attribute__%>");
2060 /* Parse a typeof specifier (a GNU extension).
2063 typeof ( expression )
2064 typeof ( type-name )
2067 static struct c_typespec
2068 c_parser_typeof_specifier (c_parser
*parser
)
2070 struct c_typespec ret
;
2071 ret
.kind
= ctsk_typeof
;
2072 ret
.spec
= error_mark_node
;
2073 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2074 c_parser_consume_token (parser
);
2077 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2083 if (c_parser_next_token_starts_typename (parser
))
2085 struct c_type_name
*type
= c_parser_type_name (parser
);
2090 ret
.spec
= groktypename (type
);
2091 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2096 struct c_expr expr
= c_parser_expression (parser
);
2099 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2100 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2101 error ("%<typeof%> applied to a bit-field");
2102 ret
.spec
= TREE_TYPE (expr
.value
);
2103 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2105 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2109 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2110 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2111 be redeclared; otherwise it may not. KIND indicates which kind of
2112 declarator is wanted. Returns a valid declarator except in the
2113 case of a syntax error in which case NULL is returned. *SEEN_ID is
2114 set to true if an identifier being declared is seen; this is used
2115 to diagnose bad forms of abstract array declarators and to
2116 determine whether an identifier list is syntactically permitted.
2119 pointer[opt] direct-declarator
2123 ( attributes[opt] declarator )
2124 direct-declarator array-declarator
2125 direct-declarator ( parameter-type-list )
2126 direct-declarator ( identifier-list[opt] )
2129 * type-qualifier-list[opt]
2130 * type-qualifier-list[opt] pointer
2132 type-qualifier-list:
2135 type-qualifier-list type-qualifier
2136 type-qualifier-list attributes
2138 parameter-type-list:
2140 parameter-list , ...
2143 parameter-declaration
2144 parameter-list , parameter-declaration
2146 parameter-declaration:
2147 declaration-specifiers declarator attributes[opt]
2148 declaration-specifiers abstract-declarator[opt] attributes[opt]
2152 identifier-list , identifier
2154 abstract-declarator:
2156 pointer[opt] direct-abstract-declarator
2158 direct-abstract-declarator:
2159 ( attributes[opt] abstract-declarator )
2160 direct-abstract-declarator[opt] array-declarator
2161 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2166 direct-declarator ( parameter-forward-declarations
2167 parameter-type-list[opt] )
2169 direct-abstract-declarator:
2170 direct-abstract-declarator[opt] ( parameter-forward-declarations
2171 parameter-type-list[opt] )
2173 parameter-forward-declarations:
2175 parameter-forward-declarations parameter-list ;
2177 The uses of attributes shown above are GNU extensions.
2179 Some forms of array declarator are not included in C99 in the
2180 syntax for abstract declarators; these are disallowed elsewhere.
2181 This may be a defect (DR#289).
2183 This function also accepts an omitted abstract declarator as being
2184 an abstract declarator, although not part of the formal syntax. */
2186 static struct c_declarator
*
2187 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2190 /* Parse any initial pointer part. */
2191 if (c_parser_next_token_is (parser
, CPP_MULT
))
2193 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2194 struct c_declarator
*inner
;
2195 c_parser_consume_token (parser
);
2196 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2197 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2201 return make_pointer_declarator (quals_attrs
, inner
);
2203 /* Now we have a direct declarator, direct abstract declarator or
2204 nothing (which counts as a direct abstract declarator here). */
2205 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2208 /* Parse a direct declarator or direct abstract declarator; arguments
2209 as c_parser_declarator. */
2211 static struct c_declarator
*
2212 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2215 /* The direct declarator must start with an identifier (possibly
2216 omitted) or a parenthesized declarator (possibly abstract). In
2217 an ordinary declarator, initial parentheses must start a
2218 parenthesized declarator. In an abstract declarator or parameter
2219 declarator, they could start a parenthesized declarator or a
2220 parameter list. To tell which, the open parenthesis and any
2221 following attributes must be read. If a declaration specifier
2222 follows, then it is a parameter list; if the specifier is a
2223 typedef name, there might be an ambiguity about redeclaring it,
2224 which is resolved in the direction of treating it as a typedef
2225 name. If a close parenthesis follows, it is also an empty
2226 parameter list, as the syntax does not permit empty abstract
2227 declarators. Otherwise, it is a parenthesized declarator (in
2228 which case the analysis may be repeated inside it, recursively).
2230 ??? There is an ambiguity in a parameter declaration "int
2231 (__attribute__((foo)) x)", where x is not a typedef name: it
2232 could be an abstract declarator for a function, or declare x with
2233 parentheses. The proper resolution of this ambiguity needs
2234 documenting. At present we follow an accident of the old
2235 parser's implementation, whereby the first parameter must have
2236 some declaration specifiers other than just attributes. Thus as
2237 a parameter declaration it is treated as a parenthesized
2238 parameter named x, and as an abstract declarator it is
2241 ??? Also following the old parser, attributes inside an empty
2242 parameter list are ignored, making it a list not yielding a
2243 prototype, rather than giving an error or making it have one
2244 parameter with implicit type int.
2246 ??? Also following the old parser, typedef names may be
2247 redeclared in declarators, but not Objective-C class names. */
2249 if (kind
!= C_DTR_ABSTRACT
2250 && c_parser_next_token_is (parser
, CPP_NAME
)
2252 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2253 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2255 struct c_declarator
*inner
2256 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2258 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2259 c_parser_consume_token (parser
);
2260 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2263 if (kind
!= C_DTR_NORMAL
2264 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2266 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2267 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2270 /* Either we are at the end of an abstract declarator, or we have
2273 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2276 struct c_declarator
*inner
;
2277 c_parser_consume_token (parser
);
2278 attrs
= c_parser_attributes (parser
);
2279 if (kind
!= C_DTR_NORMAL
2280 && (c_parser_next_token_starts_declspecs (parser
)
2281 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2283 struct c_arg_info
*args
2284 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2291 = build_function_declarator (args
,
2292 build_id_declarator (NULL_TREE
));
2293 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2297 /* A parenthesized declarator. */
2298 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2299 if (inner
!= NULL
&& attrs
!= NULL
)
2300 inner
= build_attrs_declarator (attrs
, inner
);
2301 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2303 c_parser_consume_token (parser
);
2307 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2311 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2318 if (kind
== C_DTR_NORMAL
)
2320 c_parser_error (parser
, "expected identifier or %<(%>");
2324 return build_id_declarator (NULL_TREE
);
2328 /* Parse part of a direct declarator or direct abstract declarator,
2329 given that some (in INNER) has already been parsed; ID_PRESENT is
2330 true if an identifier is present, false for an abstract
2333 static struct c_declarator
*
2334 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2335 struct c_declarator
*inner
)
2337 /* Parse a sequence of array declarators and parameter lists. */
2338 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2340 struct c_declarator
*declarator
;
2341 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2345 c_parser_consume_token (parser
);
2346 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2347 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2349 c_parser_consume_token (parser
);
2350 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2351 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2352 if (!quals_attrs
->declspecs_seen_p
)
2354 /* If "static" is present, there must be an array dimension.
2355 Otherwise, there may be a dimension, "*", or no
2360 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2364 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2369 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2371 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2375 c_parser_consume_token (parser
);
2380 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2386 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2389 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2390 c_parser_consume_token (parser
);
2393 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2397 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2399 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2400 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2402 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2405 struct c_arg_info
*args
;
2406 c_parser_consume_token (parser
);
2407 attrs
= c_parser_attributes (parser
);
2408 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2413 inner
= build_function_declarator (args
, inner
);
2414 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2420 /* Parse a parameter list or identifier list, including the closing
2421 parenthesis but not the opening one. ATTRS are the attributes at
2422 the start of the list. ID_LIST_OK is true if an identifier list is
2423 acceptable; such a list must not have attributes at the start. */
2425 static struct c_arg_info
*
2426 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2429 declare_parm_level ();
2430 /* If the list starts with an identifier, it is an identifier list.
2431 Otherwise, it is either a prototype list or an empty list. */
2434 && c_parser_next_token_is (parser
, CPP_NAME
)
2435 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2437 tree list
= NULL_TREE
, *nextp
= &list
;
2438 while (c_parser_next_token_is (parser
, CPP_NAME
)
2439 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2441 *nextp
= build_tree_list (NULL_TREE
,
2442 c_parser_peek_token (parser
)->value
);
2443 nextp
= & TREE_CHAIN (*nextp
);
2444 c_parser_consume_token (parser
);
2445 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2447 c_parser_consume_token (parser
);
2448 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2450 c_parser_error (parser
, "expected identifier");
2454 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2456 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2461 c_parser_consume_token (parser
);
2467 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2475 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2481 /* Parse a parameter list (possibly empty), including the closing
2482 parenthesis but not the opening one. ATTRS are the attributes at
2483 the start of the list. */
2485 static struct c_arg_info
*
2486 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2488 bool good_parm
= false;
2489 /* ??? Following the old parser, forward parameter declarations may
2490 use abstract declarators, and if no real parameter declarations
2491 follow the forward declarations then this is not diagnosed. Also
2492 note as above that attributes are ignored as the only contents of
2493 the parentheses, or as the only contents after forward
2495 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2497 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2502 c_parser_consume_token (parser
);
2505 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2507 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2511 /* Suppress -Wold-style-definition for this case. */
2512 ret
->types
= error_mark_node
;
2513 error ("ISO C requires a named argument before %<...%>");
2514 c_parser_consume_token (parser
);
2515 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2517 c_parser_consume_token (parser
);
2522 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2527 /* Nonempty list of parameters, either terminated with semicolon
2528 (forward declarations; recurse) or with close parenthesis (normal
2529 function) or with ", ... )" (variadic function). */
2532 /* Parse a parameter. */
2533 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2538 push_parm_decl (parm
);
2540 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2543 c_parser_consume_token (parser
);
2544 mark_forward_parm_decls ();
2545 new_attrs
= c_parser_attributes (parser
);
2546 return c_parser_parms_list_declarator (parser
, new_attrs
);
2548 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2550 c_parser_consume_token (parser
);
2552 return get_parm_info (false);
2555 struct c_arg_info
*ret
2556 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2564 if (!c_parser_require (parser
, CPP_COMMA
,
2565 "expected %<;%>, %<,%> or %<)%>"))
2567 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2570 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2572 c_parser_consume_token (parser
);
2573 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2575 c_parser_consume_token (parser
);
2577 return get_parm_info (true);
2580 struct c_arg_info
*ret
2581 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2591 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2599 /* Parse a parameter declaration. ATTRS are the attributes at the
2600 start of the declaration if it is the first parameter. */
2602 static struct c_parm
*
2603 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2605 struct c_declspecs
*specs
;
2606 struct c_declarator
*declarator
;
2608 tree postfix_attrs
= NULL_TREE
;
2610 if (!c_parser_next_token_starts_declspecs (parser
))
2612 /* ??? In some Objective-C cases '...' isn't applicable so there
2613 should be a different message. */
2614 c_parser_error (parser
,
2615 "expected declaration specifiers or %<...%>");
2616 c_parser_skip_to_end_of_parameter (parser
);
2619 specs
= build_null_declspecs ();
2622 declspecs_add_attrs (specs
, attrs
);
2625 c_parser_declspecs (parser
, specs
, true, true, true);
2626 finish_declspecs (specs
);
2627 pending_xref_error ();
2628 prefix_attrs
= specs
->attrs
;
2629 specs
->attrs
= NULL_TREE
;
2630 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2631 C_DTR_PARM
, &dummy
);
2632 if (declarator
== NULL
)
2634 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2637 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2638 postfix_attrs
= c_parser_attributes (parser
);
2639 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2643 /* Parse a string literal in an asm expression. It should not be
2644 translated, and wide string literals are an error although
2645 permitted by the syntax. This is a GNU extension.
2650 ??? At present, following the old parser, the caller needs to have
2651 set c_lex_string_translate to 0. It would be better to follow the
2652 C++ parser rather than using the c_lex_string_translate kludge. */
2655 c_parser_asm_string_literal (c_parser
*parser
)
2658 if (c_parser_next_token_is (parser
, CPP_STRING
))
2660 str
= c_parser_peek_token (parser
)->value
;
2661 c_parser_consume_token (parser
);
2663 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2665 error ("wide string literal in %<asm%>");
2666 str
= build_string (1, "");
2667 c_parser_consume_token (parser
);
2671 c_parser_error (parser
, "expected string literal");
2677 /* Parse a simple asm expression. This is used in restricted
2678 contexts, where a full expression with inputs and outputs does not
2679 make sense. This is a GNU extension.
2682 asm ( asm-string-literal )
2686 c_parser_simple_asm_expr (c_parser
*parser
)
2689 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2690 /* ??? Follow the C++ parser rather than using the
2691 c_lex_string_translate kludge. */
2692 c_lex_string_translate
= 0;
2693 c_parser_consume_token (parser
);
2694 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2696 c_lex_string_translate
= 1;
2699 str
= c_parser_asm_string_literal (parser
);
2700 c_lex_string_translate
= 1;
2701 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2703 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2709 /* Parse (possibly empty) attributes. This is a GNU extension.
2713 attributes attribute
2716 __attribute__ ( ( attribute-list ) )
2720 attribute_list , attrib
2725 any-word ( identifier )
2726 any-word ( identifier , nonempty-expr-list )
2727 any-word ( expr-list )
2729 where the "identifier" must not be declared as a type, and
2730 "any-word" may be any identifier (including one declared as a
2731 type), a reserved word storage class specifier, type specifier or
2732 type qualifier. ??? This still leaves out most reserved keywords
2733 (following the old parser), shouldn't we include them, and why not
2734 allow identifiers declared as types to start the arguments? */
2737 c_parser_attributes (c_parser
*parser
)
2739 tree attrs
= NULL_TREE
;
2740 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2742 /* ??? Follow the C++ parser rather than using the
2743 c_lex_string_translate kludge. */
2744 c_lex_string_translate
= 0;
2745 c_parser_consume_token (parser
);
2746 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2748 c_lex_string_translate
= 1;
2751 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2753 c_lex_string_translate
= 1;
2754 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2757 /* Parse the attribute list. */
2758 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2759 || c_parser_next_token_is (parser
, CPP_NAME
)
2760 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2762 tree attr
, attr_name
, attr_args
;
2763 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2765 c_parser_consume_token (parser
);
2768 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2770 /* ??? See comment above about what keywords are
2773 switch (c_parser_peek_token (parser
)->keyword
)
2808 attr_name
= c_parser_peek_token (parser
)->value
;
2809 c_parser_consume_token (parser
);
2810 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2812 attr
= build_tree_list (attr_name
, NULL_TREE
);
2813 attrs
= chainon (attrs
, attr
);
2816 c_parser_consume_token (parser
);
2817 /* Parse the attribute contents. If they start with an
2818 identifier which is followed by a comma or close
2819 parenthesis, then the arguments start with that
2820 identifier; otherwise they are an expression list. */
2821 if (c_parser_next_token_is (parser
, CPP_NAME
)
2822 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2823 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2824 || (c_parser_peek_2nd_token (parser
)->type
2825 == CPP_CLOSE_PAREN
)))
2827 tree arg1
= c_parser_peek_token (parser
)->value
;
2828 c_parser_consume_token (parser
);
2829 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2830 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2833 c_parser_consume_token (parser
);
2834 attr_args
= tree_cons (NULL_TREE
, arg1
,
2835 c_parser_expr_list (parser
, false));
2840 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2841 attr_args
= NULL_TREE
;
2843 attr_args
= c_parser_expr_list (parser
, false);
2845 attr
= build_tree_list (attr_name
, attr_args
);
2846 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2847 c_parser_consume_token (parser
);
2850 c_lex_string_translate
= 1;
2851 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2855 attrs
= chainon (attrs
, attr
);
2857 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2858 c_parser_consume_token (parser
);
2861 c_lex_string_translate
= 1;
2862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2866 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2867 c_parser_consume_token (parser
);
2870 c_lex_string_translate
= 1;
2871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2875 c_lex_string_translate
= 1;
2880 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2883 specifier-qualifier-list abstract-declarator[opt]
2886 static struct c_type_name
*
2887 c_parser_type_name (c_parser
*parser
)
2889 struct c_declspecs
*specs
= build_null_declspecs ();
2890 struct c_declarator
*declarator
;
2891 struct c_type_name
*ret
;
2893 c_parser_declspecs (parser
, specs
, false, true, true);
2894 if (!specs
->declspecs_seen_p
)
2896 c_parser_error (parser
, "expected specifier-qualifier-list");
2899 pending_xref_error ();
2900 finish_declspecs (specs
);
2901 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2902 C_DTR_ABSTRACT
, &dummy
);
2903 if (declarator
== NULL
)
2905 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2907 ret
->declarator
= declarator
;
2911 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2914 assignment-expression
2915 { initializer-list }
2916 { initializer-list , }
2919 designation[opt] initializer
2920 initializer-list , designation[opt] initializer
2927 designator-list designator
2934 [ constant-expression ]
2946 [ constant-expression ... constant-expression ]
2948 Any expression without commas is accepted in the syntax for the
2949 constant-expressions, with non-constant expressions rejected later.
2951 This function is only used for top-level initializers; for nested
2952 ones, see c_parser_initval. */
2954 static struct c_expr
2955 c_parser_initializer (c_parser
*parser
)
2957 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2958 return c_parser_braced_init (parser
, NULL_TREE
, false);
2962 ret
= c_parser_expr_no_commas (parser
, NULL
);
2963 if (TREE_CODE (ret
.value
) != STRING_CST
2964 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
2965 ret
= default_function_array_conversion (ret
);
2970 /* Parse a braced initializer list. TYPE is the type specified for a
2971 compound literal, and NULL_TREE for other initializers and for
2972 nested braced lists. NESTED_P is true for nested braced lists,
2973 false for the list of a compound literal or the list that is the
2974 top-level initializer in a declaration. */
2976 static struct c_expr
2977 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
2979 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
2980 c_parser_consume_token (parser
);
2982 push_init_level (0);
2984 really_start_incremental_init (type
);
2985 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2988 pedwarn ("ISO C forbids empty initializer braces");
2992 /* Parse a non-empty initializer list, possibly with a trailing
2996 c_parser_initelt (parser
);
2999 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3000 c_parser_consume_token (parser
);
3003 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3007 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3010 ret
.value
= error_mark_node
;
3011 ret
.original_code
= ERROR_MARK
;
3012 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3015 c_parser_consume_token (parser
);
3016 return pop_init_level (0);
3019 /* Parse a nested initializer, including designators. */
3022 c_parser_initelt (c_parser
*parser
)
3024 /* Parse any designator or designator list. A single array
3025 designator may have the subsequent "=" omitted in GNU C, but a
3026 longer list or a structure member designator may not. */
3027 if (c_parser_next_token_is (parser
, CPP_NAME
)
3028 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3030 /* Old-style structure member designator. */
3031 set_init_label (c_parser_peek_token (parser
)->value
);
3033 pedwarn ("obsolete use of designated initializer with %<:%>");
3034 c_parser_consume_token (parser
);
3035 c_parser_consume_token (parser
);
3039 /* des_seen is 0 if there have been no designators, 1 if there
3040 has been a single array designator and 2 otherwise. */
3042 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3043 || c_parser_next_token_is (parser
, CPP_DOT
))
3045 int des_prev
= des_seen
;
3048 if (c_parser_next_token_is (parser
, CPP_DOT
))
3051 c_parser_consume_token (parser
);
3052 if (c_parser_next_token_is (parser
, CPP_NAME
))
3054 set_init_label (c_parser_peek_token (parser
)->value
);
3055 c_parser_consume_token (parser
);
3060 init
.value
= error_mark_node
;
3061 init
.original_code
= ERROR_MARK
;
3062 c_parser_error (parser
, "expected identifier");
3063 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3064 process_init_element (init
);
3071 /* ??? Following the old parser, [ objc-receiver
3072 objc-message-args ] is accepted as an initializer,
3073 being distinguished from a designator by what follows
3074 the first assignment expression inside the square
3075 brackets, but after a first array designator a
3076 subsequent square bracket is for Objective-C taken to
3077 start an expression, using the obsolete form of
3078 designated initializer without '=', rather than
3079 possibly being a second level of designation: in LALR
3080 terms, the '[' is shifted rather than reducing
3081 designator to designator-list. */
3082 if (des_prev
== 1 && c_dialect_objc ())
3084 des_seen
= des_prev
;
3087 if (des_prev
== 0 && c_dialect_objc ())
3089 /* This might be an array designator or an
3090 Objective-C message expression. If the former,
3091 continue parsing here; if the latter, parse the
3092 remainder of the initializer given the starting
3093 primary-expression. ??? It might make sense to
3094 distinguish when des_prev == 1 as well; see
3095 previous comment. */
3097 struct c_expr mexpr
;
3098 c_parser_consume_token (parser
);
3099 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3100 && ((c_parser_peek_token (parser
)->id_kind
3102 || (c_parser_peek_token (parser
)->id_kind
3103 == C_ID_CLASSNAME
)))
3105 /* Type name receiver. */
3106 tree id
= c_parser_peek_token (parser
)->value
;
3107 c_parser_consume_token (parser
);
3108 rec
= objc_get_class_reference (id
);
3109 goto parse_message_args
;
3111 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3112 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3113 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3114 goto array_desig_after_first
;
3115 /* Expression receiver. So far only one part
3116 without commas has been parsed; there might be
3117 more of the expression. */
3119 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3122 c_parser_consume_token (parser
);
3123 next
= c_parser_expr_no_commas (parser
, NULL
);
3124 next
= default_function_array_conversion (next
);
3125 rec
= build_compound_expr (rec
, next
.value
);
3128 /* Now parse the objc-message-args. */
3129 args
= c_parser_objc_message_args (parser
);
3130 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3133 = objc_build_message_expr (build_tree_list (rec
, args
));
3134 mexpr
.original_code
= ERROR_MARK
;
3135 /* Now parse and process the remainder of the
3136 initializer, starting with this message
3137 expression as a primary-expression. */
3138 c_parser_initval (parser
, &mexpr
);
3141 c_parser_consume_token (parser
);
3142 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3143 array_desig_after_first
:
3144 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3146 c_parser_consume_token (parser
);
3147 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3151 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3153 c_parser_consume_token (parser
);
3154 set_init_index (first
, second
);
3155 if (pedantic
&& second
)
3156 pedwarn ("ISO C forbids specifying range of "
3157 "elements to initialize");
3160 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3166 if (c_parser_next_token_is (parser
, CPP_EQ
))
3168 if (pedantic
&& !flag_isoc99
)
3169 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3170 c_parser_consume_token (parser
);
3177 pedwarn ("obsolete use of designated initializer "
3183 init
.value
= error_mark_node
;
3184 init
.original_code
= ERROR_MARK
;
3185 c_parser_error (parser
, "expected %<=%>");
3186 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3187 process_init_element (init
);
3193 c_parser_initval (parser
, NULL
);
3196 /* Parse a nested initializer; as c_parser_initializer but parses
3197 initializers within braced lists, after any designators have been
3198 applied. If AFTER is not NULL then it is an Objective-C message
3199 expression which is the primary-expression starting the
3203 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3206 gcc_assert (!after
|| c_dialect_objc ());
3207 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3208 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3211 init
= c_parser_expr_no_commas (parser
, after
);
3212 if (init
.value
!= NULL_TREE
3213 && TREE_CODE (init
.value
) != STRING_CST
3214 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3215 init
= default_function_array_conversion (init
);
3217 process_init_element (init
);
3220 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3224 { block-item-list[opt] }
3225 { label-declarations block-item-list }
3229 block-item-list block-item
3241 { label-declarations block-item-list }
3244 __extension__ nested-declaration
3245 nested-function-definition
3249 label-declarations label-declaration
3252 __label__ identifier-list ;
3254 Allowing the mixing of declarations and code is new in C99. The
3255 GNU syntax also permits (not shown above) labels at the end of
3256 compound statements, which yield an error. We don't allow labels
3257 on declarations; this might seem like a natural extension, but
3258 there would be a conflict between attributes on the label and
3259 prefix attributes on the declaration. ??? The syntax follows the
3260 old parser in requiring something after label declarations.
3261 Although they are erroneous if the labels declared aren't defined,
3262 is it useful for the syntax to be this way? */
3265 c_parser_compound_statement (c_parser
*parser
)
3268 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3269 return error_mark_node
;
3270 stmt
= c_begin_compound_stmt (true);
3271 c_parser_compound_statement_nostart (parser
);
3272 return c_end_compound_stmt (stmt
, true);
3275 /* Parse a compound statement except for the opening brace. This is
3276 used for parsing both compound statements and statement expressions
3277 (which follow different paths to handling the opening). */
3280 c_parser_compound_statement_nostart (c_parser
*parser
)
3282 bool last_stmt
= false;
3283 bool last_label
= false;
3284 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3286 c_parser_consume_token (parser
);
3289 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3291 /* Read zero or more forward-declarations for labels that nested
3292 functions can jump to. */
3293 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3295 c_parser_consume_token (parser
);
3296 /* Any identifiers, including those declared as type names,
3301 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3303 c_parser_error (parser
, "expected identifier");
3307 = declare_label (c_parser_peek_token (parser
)->value
);
3308 C_DECLARED_LABEL_FLAG (label
) = 1;
3309 add_stmt (build_stmt (DECL_EXPR
, label
));
3310 c_parser_consume_token (parser
);
3311 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3312 c_parser_consume_token (parser
);
3316 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3318 /* ??? Locating this diagnostic on the token after the
3319 declarations end follows the old parser, but it might be
3320 better to locate it where the declarations start instead. */
3322 pedwarn ("ISO C forbids label declarations");
3324 /* We must now have at least one statement, label or declaration. */
3325 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3327 c_parser_error (parser
, "expected declaration or statement");
3328 c_parser_consume_token (parser
);
3331 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3333 location_t loc
= c_parser_peek_token (parser
)->location
;
3334 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3335 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3336 || (c_parser_next_token_is (parser
, CPP_NAME
)
3337 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3341 c_parser_label (parser
);
3343 else if (!last_label
3344 && c_parser_next_token_starts_declspecs (parser
))
3347 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3349 && ((pedantic
&& !flag_isoc99
)
3350 || warn_declaration_after_statement
))
3351 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3355 else if (!last_label
3356 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3358 /* __extension__ can start a declaration, but is also an
3359 unary operator that can start an expression. Consume all
3360 but the last of a possible series of __extension__ to
3362 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3363 && (c_parser_peek_2nd_token (parser
)->keyword
3365 c_parser_consume_token (parser
);
3366 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3369 ext
= disable_extension_diagnostics ();
3370 c_parser_consume_token (parser
);
3372 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3373 /* Following the old parser, __extension__ does not
3374 disable this diagnostic. */
3375 restore_extension_diagnostics (ext
);
3377 && ((pedantic
&& !flag_isoc99
)
3378 || warn_declaration_after_statement
))
3379 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3386 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3388 /* External pragmas, and some omp pragmas, are not associated
3389 with regular c code, and so are not to be considered statements
3390 syntactically. This ensures that the user doesn't put them
3391 places that would turn into syntax errors if the directive
3393 if (c_parser_pragma (parser
, pragma_compound
))
3394 last_label
= false, last_stmt
= true;
3396 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3398 c_parser_error (parser
, "expected declaration or statement");
3406 c_parser_statement_after_labels (parser
);
3410 error ("label at end of compound statement");
3411 c_parser_consume_token (parser
);
3414 /* Parse a label (C90 6.6.1, C99 6.8.1).
3417 identifier : attributes[opt]
3418 case constant-expression :
3424 case constant-expression ... constant-expression :
3426 The use of attributes on labels is a GNU extension. The syntax in
3427 GNU C accepts any expressions without commas, non-constant
3428 expressions being rejected later. */
3431 c_parser_label (c_parser
*parser
)
3433 location_t loc1
= c_parser_peek_token (parser
)->location
;
3434 tree label
= NULL_TREE
;
3435 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3438 c_parser_consume_token (parser
);
3439 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3440 if (c_parser_next_token_is (parser
, CPP_COLON
))
3442 c_parser_consume_token (parser
);
3443 label
= do_case (exp1
, NULL_TREE
);
3445 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3447 c_parser_consume_token (parser
);
3448 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3449 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3450 label
= do_case (exp1
, exp2
);
3453 c_parser_error (parser
, "expected %<:%> or %<...%>");
3455 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3457 c_parser_consume_token (parser
);
3458 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3459 label
= do_case (NULL_TREE
, NULL_TREE
);
3463 tree name
= c_parser_peek_token (parser
)->value
;
3467 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3468 c_parser_consume_token (parser
);
3469 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3470 loc2
= c_parser_peek_token (parser
)->location
;
3471 c_parser_consume_token (parser
);
3472 attrs
= c_parser_attributes (parser
);
3473 tlab
= define_label (loc2
, name
);
3476 decl_attributes (&tlab
, attrs
, 0);
3477 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3481 SET_EXPR_LOCATION (label
, loc1
);
3484 /* Parse a statement (C90 6.6, C99 6.8).
3489 expression-statement
3497 expression-statement:
3500 selection-statement:
3504 iteration-statement:
3513 return expression[opt] ;
3526 objc-throw-statement
3527 objc-try-catch-statement
3528 objc-synchronized-statement
3530 objc-throw-statement:
3536 c_parser_statement (c_parser
*parser
)
3538 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3539 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3540 || (c_parser_next_token_is (parser
, CPP_NAME
)
3541 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3542 c_parser_label (parser
);
3543 c_parser_statement_after_labels (parser
);
3546 /* Parse a statement, other than a labeled statement. */
3549 c_parser_statement_after_labels (c_parser
*parser
)
3551 location_t loc
= c_parser_peek_token (parser
)->location
;
3552 tree stmt
= NULL_TREE
;
3553 switch (c_parser_peek_token (parser
)->type
)
3555 case CPP_OPEN_BRACE
:
3556 add_stmt (c_parser_compound_statement (parser
));
3559 switch (c_parser_peek_token (parser
)->keyword
)
3562 c_parser_if_statement (parser
);
3565 c_parser_switch_statement (parser
);
3568 c_parser_while_statement (parser
);
3571 c_parser_do_statement (parser
);
3574 c_parser_for_statement (parser
);
3577 c_parser_consume_token (parser
);
3578 if (c_parser_next_token_is (parser
, CPP_NAME
))
3580 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3581 c_parser_consume_token (parser
);
3583 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3585 c_parser_consume_token (parser
);
3586 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3589 c_parser_error (parser
, "expected identifier or %<*%>");
3590 goto expect_semicolon
;
3592 c_parser_consume_token (parser
);
3593 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3594 goto expect_semicolon
;
3596 c_parser_consume_token (parser
);
3597 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3598 goto expect_semicolon
;
3600 c_parser_consume_token (parser
);
3601 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3603 stmt
= c_finish_return (NULL_TREE
);
3604 c_parser_consume_token (parser
);
3608 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3609 goto expect_semicolon
;
3613 stmt
= c_parser_asm_statement (parser
);
3616 gcc_assert (c_dialect_objc ());
3617 c_parser_consume_token (parser
);
3618 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3620 stmt
= objc_build_throw_stmt (NULL_TREE
);
3621 c_parser_consume_token (parser
);
3626 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3627 goto expect_semicolon
;
3631 gcc_assert (c_dialect_objc ());
3632 c_parser_objc_try_catch_statement (parser
);
3634 case RID_AT_SYNCHRONIZED
:
3635 gcc_assert (c_dialect_objc ());
3636 c_parser_objc_synchronized_statement (parser
);
3643 c_parser_consume_token (parser
);
3645 case CPP_CLOSE_PAREN
:
3646 case CPP_CLOSE_SQUARE
:
3647 /* Avoid infinite loop in error recovery:
3648 c_parser_skip_until_found stops at a closing nesting
3649 delimiter without consuming it, but here we need to consume
3650 it to proceed further. */
3651 c_parser_error (parser
, "expected statement");
3652 c_parser_consume_token (parser
);
3655 c_parser_pragma (parser
, pragma_stmt
);
3659 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3661 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3664 /* Two cases cannot and do not have line numbers associated: If stmt
3665 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3666 cannot hold line numbers. But that's OK because the statement
3667 will either be changed to a MODIFY_EXPR during gimplification of
3668 the statement expr, or discarded. If stmt was compound, but
3669 without new variables, we will have skipped the creation of a
3670 BIND and will have a bare STATEMENT_LIST. But that's OK because
3671 (recursively) all of the component statements should already have
3672 line numbers assigned. ??? Can we discard no-op statements
3674 if (stmt
&& EXPR_P (stmt
))
3675 SET_EXPR_LOCATION (stmt
, loc
);
3678 /* Parse a parenthesized condition from an if, do or while statement.
3684 c_parser_paren_condition (c_parser
*parser
)
3688 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3689 return error_mark_node
;
3690 loc
= c_parser_peek_token (parser
)->location
;
3691 cond
= c_objc_common_truthvalue_conversion
3692 (c_parser_expression_conv (parser
).value
);
3694 SET_EXPR_LOCATION (cond
, loc
);
3695 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3699 /* Parse a statement which is a block in C99. */
3702 c_parser_c99_block_statement (c_parser
*parser
)
3704 tree block
= c_begin_compound_stmt (flag_isoc99
);
3705 c_parser_statement (parser
);
3706 return c_end_compound_stmt (block
, flag_isoc99
);
3709 /* Parse the body of an if statement or the else half thereof. This
3710 is just parsing a statement but (a) it is a block in C99, (b) we
3711 track whether the body is an if statement for the sake of
3712 -Wparentheses warnings, (c) we handle an empty body specially for
3713 the sake of -Wextra warnings. */
3716 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3718 tree block
= c_begin_compound_stmt (flag_isoc99
);
3719 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3720 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3721 || (c_parser_next_token_is (parser
, CPP_NAME
)
3722 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3723 c_parser_label (parser
);
3724 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3725 if (extra_warnings
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3726 add_stmt (build1 (NOP_EXPR
, NULL_TREE
, NULL_TREE
));
3727 c_parser_statement_after_labels (parser
);
3728 return c_end_compound_stmt (block
, flag_isoc99
);
3731 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3734 if ( expression ) statement
3735 if ( expression ) statement else statement
3739 c_parser_if_statement (c_parser
*parser
)
3744 bool first_if
= false, second_if
= false;
3745 tree first_body
, second_body
;
3746 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3747 c_parser_consume_token (parser
);
3748 block
= c_begin_compound_stmt (flag_isoc99
);
3749 loc
= c_parser_peek_token (parser
)->location
;
3750 cond
= c_parser_paren_condition (parser
);
3751 first_body
= c_parser_if_body (parser
, &first_if
);
3752 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3754 c_parser_consume_token (parser
);
3755 second_body
= c_parser_if_body (parser
, &second_if
);
3758 second_body
= NULL_TREE
;
3759 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3760 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3763 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3766 switch (expression) statement
3770 c_parser_switch_statement (c_parser
*parser
)
3772 tree block
, expr
, body
, save_break
;
3773 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3774 c_parser_consume_token (parser
);
3775 block
= c_begin_compound_stmt (flag_isoc99
);
3776 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3778 expr
= c_parser_expression (parser
).value
;
3779 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3782 expr
= error_mark_node
;
3783 c_start_case (expr
);
3784 save_break
= c_break_label
;
3785 c_break_label
= NULL_TREE
;
3786 body
= c_parser_c99_block_statement (parser
);
3787 c_finish_case (body
);
3789 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3790 c_break_label
= save_break
;
3791 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3794 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3797 while (expression) statement
3801 c_parser_while_statement (c_parser
*parser
)
3803 tree block
, cond
, body
, save_break
, save_cont
;
3805 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3806 c_parser_consume_token (parser
);
3807 block
= c_begin_compound_stmt (flag_isoc99
);
3808 loc
= c_parser_peek_token (parser
)->location
;
3809 cond
= c_parser_paren_condition (parser
);
3810 save_break
= c_break_label
;
3811 c_break_label
= NULL_TREE
;
3812 save_cont
= c_cont_label
;
3813 c_cont_label
= NULL_TREE
;
3814 body
= c_parser_c99_block_statement (parser
);
3815 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3816 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3817 c_break_label
= save_break
;
3818 c_cont_label
= save_cont
;
3821 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3824 do statement while ( expression ) ;
3828 c_parser_do_statement (c_parser
*parser
)
3830 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3832 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3833 c_parser_consume_token (parser
);
3834 block
= c_begin_compound_stmt (flag_isoc99
);
3835 loc
= c_parser_peek_token (parser
)->location
;
3836 save_break
= c_break_label
;
3837 c_break_label
= NULL_TREE
;
3838 save_cont
= c_cont_label
;
3839 c_cont_label
= NULL_TREE
;
3840 body
= c_parser_c99_block_statement (parser
);
3841 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3842 new_break
= c_break_label
;
3843 c_break_label
= save_break
;
3844 new_cont
= c_cont_label
;
3845 c_cont_label
= save_cont
;
3846 cond
= c_parser_paren_condition (parser
);
3847 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3848 c_parser_skip_to_end_of_block_or_statement (parser
);
3849 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3850 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3853 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3856 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3857 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3859 The form with a declaration is new in C99.
3861 ??? In accordance with the old parser, the declaration may be a
3862 nested function, which is then rejected in check_for_loop_decls,
3863 but does it make any sense for this to be included in the grammar?
3864 Note in particular that the nested function does not include a
3865 trailing ';', whereas the "declaration" production includes one.
3866 Also, can we reject bad declarations earlier and cheaper than
3867 check_for_loop_decls? */
3870 c_parser_for_statement (c_parser
*parser
)
3872 tree block
, cond
, incr
, save_break
, save_cont
, body
;
3874 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
3875 loc
= c_parser_peek_token (parser
)->location
;
3876 c_parser_consume_token (parser
);
3877 block
= c_begin_compound_stmt (flag_isoc99
);
3878 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3880 /* Parse the initialization declaration or expression. */
3881 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3883 c_parser_consume_token (parser
);
3884 c_finish_expr_stmt (NULL_TREE
);
3886 else if (c_parser_next_token_starts_declspecs (parser
))
3888 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3889 check_for_loop_decls ();
3891 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3893 /* __extension__ can start a declaration, but is also an
3894 unary operator that can start an expression. Consume all
3895 but the last of a possible series of __extension__ to
3897 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3898 && (c_parser_peek_2nd_token (parser
)->keyword
3900 c_parser_consume_token (parser
);
3901 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3904 ext
= disable_extension_diagnostics ();
3905 c_parser_consume_token (parser
);
3906 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3907 restore_extension_diagnostics (ext
);
3908 check_for_loop_decls ();
3916 c_finish_expr_stmt (c_parser_expression (parser
).value
);
3917 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3919 /* Parse the loop condition. */
3920 loc
= c_parser_peek_token (parser
)->location
;
3921 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3923 c_parser_consume_token (parser
);
3928 tree ocond
= c_parser_expression_conv (parser
).value
;
3929 cond
= c_objc_common_truthvalue_conversion (ocond
);
3931 SET_EXPR_LOCATION (cond
, loc
);
3932 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3934 /* Parse the increment expression. */
3935 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3936 incr
= c_process_expr_stmt (NULL_TREE
);
3938 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
3939 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3943 cond
= error_mark_node
;
3944 incr
= error_mark_node
;
3946 save_break
= c_break_label
;
3947 c_break_label
= NULL_TREE
;
3948 save_cont
= c_cont_label
;
3949 c_cont_label
= NULL_TREE
;
3950 body
= c_parser_c99_block_statement (parser
);
3951 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
3952 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3953 c_break_label
= save_break
;
3954 c_cont_label
= save_cont
;
3957 /* Parse an asm statement, a GNU extension. This is a full-blown asm
3958 statement with inputs, outputs, clobbers, and volatile tag
3962 asm type-qualifier[opt] ( asm-argument ) ;
3966 asm-string-literal : asm-operands[opt]
3967 asm-string-literal : asm-operands[opt] : asm-operands[opt]
3968 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
3970 Qualifiers other than volatile are accepted in the syntax but
3974 c_parser_asm_statement (c_parser
*parser
)
3976 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
3978 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3979 c_parser_consume_token (parser
);
3980 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
3982 quals
= c_parser_peek_token (parser
)->value
;
3983 c_parser_consume_token (parser
);
3985 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
3986 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
3988 warning (0, "%E qualifier ignored on asm",
3989 c_parser_peek_token (parser
)->value
);
3991 c_parser_consume_token (parser
);
3995 /* ??? Follow the C++ parser rather than using the
3996 c_lex_string_translate kludge. */
3997 c_lex_string_translate
= 0;
3998 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4000 c_lex_string_translate
= 1;
4003 str
= c_parser_asm_string_literal (parser
);
4004 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4007 outputs
= NULL_TREE
;
4009 clobbers
= NULL_TREE
;
4012 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4014 c_lex_string_translate
= 1;
4015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4019 /* Parse outputs. */
4020 if (c_parser_next_token_is (parser
, CPP_COLON
)
4021 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4022 outputs
= NULL_TREE
;
4024 outputs
= c_parser_asm_operands (parser
, false);
4025 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4028 clobbers
= NULL_TREE
;
4031 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4033 c_lex_string_translate
= 1;
4034 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4038 if (c_parser_next_token_is (parser
, CPP_COLON
)
4039 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4042 inputs
= c_parser_asm_operands (parser
, true);
4043 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4045 clobbers
= NULL_TREE
;
4048 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4050 c_lex_string_translate
= 1;
4051 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4054 /* Parse clobbers. */
4055 clobbers
= c_parser_asm_clobbers (parser
);
4057 c_lex_string_translate
= 1;
4058 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4060 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4063 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4064 c_parser_skip_to_end_of_block_or_statement (parser
);
4065 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4070 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4071 not outputs), apply the default conversion of functions and arrays
4076 asm-operands , asm-operand
4079 asm-string-literal ( expression )
4080 [ identifier ] asm-string-literal ( expression )
4084 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4086 tree list
= NULL_TREE
;
4091 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4093 c_parser_consume_token (parser
);
4094 if (c_parser_next_token_is (parser
, CPP_NAME
))
4096 tree id
= c_parser_peek_token (parser
)->value
;
4097 c_parser_consume_token (parser
);
4098 name
= build_string (IDENTIFIER_LENGTH (id
),
4099 IDENTIFIER_POINTER (id
));
4103 c_parser_error (parser
, "expected identifier");
4104 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4107 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4112 str
= c_parser_asm_string_literal (parser
);
4113 if (str
== NULL_TREE
)
4115 c_lex_string_translate
= 1;
4116 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4118 c_lex_string_translate
= 0;
4121 expr
= c_parser_expression (parser
);
4123 expr
= default_function_array_conversion (expr
);
4124 c_lex_string_translate
= 0;
4125 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4127 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4130 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4132 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4133 c_parser_consume_token (parser
);
4140 /* Parse asm clobbers, a GNU extension.
4144 asm-clobbers , asm-string-literal
4148 c_parser_asm_clobbers (c_parser
*parser
)
4150 tree list
= NULL_TREE
;
4153 tree str
= c_parser_asm_string_literal (parser
);
4155 list
= tree_cons (NULL_TREE
, str
, list
);
4158 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4159 c_parser_consume_token (parser
);
4166 /* Parse an expression other than a compound expression; that is, an
4167 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4168 NULL then it is an Objective-C message expression which is the
4169 primary-expression starting the expression as an initializer.
4171 assignment-expression:
4172 conditional-expression
4173 unary-expression assignment-operator assignment-expression
4175 assignment-operator: one of
4176 = *= /= %= += -= <<= >>= &= ^= |=
4178 In GNU C we accept any conditional expression on the LHS and
4179 diagnose the invalid lvalue rather than producing a syntax
4182 static struct c_expr
4183 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4185 struct c_expr lhs
, rhs
, ret
;
4186 enum tree_code code
;
4187 gcc_assert (!after
|| c_dialect_objc ());
4188 lhs
= c_parser_conditional_expression (parser
, after
);
4189 switch (c_parser_peek_token (parser
)->type
)
4198 code
= TRUNC_DIV_EXPR
;
4201 code
= TRUNC_MOD_EXPR
;
4216 code
= BIT_AND_EXPR
;
4219 code
= BIT_XOR_EXPR
;
4222 code
= BIT_IOR_EXPR
;
4227 c_parser_consume_token (parser
);
4228 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4229 rhs
= default_function_array_conversion (rhs
);
4230 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4231 if (code
== NOP_EXPR
)
4232 ret
.original_code
= MODIFY_EXPR
;
4235 TREE_NO_WARNING (ret
.value
) = 1;
4236 ret
.original_code
= ERROR_MARK
;
4241 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4242 is not NULL then it is an Objective-C message expression which is
4243 the primary-expression starting the expression as an initializer.
4245 conditional-expression:
4246 logical-OR-expression
4247 logical-OR-expression ? expression : conditional-expression
4251 conditional-expression:
4252 logical-OR-expression ? : conditional-expression
4255 static struct c_expr
4256 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4258 struct c_expr cond
, exp1
, exp2
, ret
;
4259 gcc_assert (!after
|| c_dialect_objc ());
4260 cond
= c_parser_binary_expression (parser
, after
);
4261 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4263 cond
= default_function_array_conversion (cond
);
4264 c_parser_consume_token (parser
);
4265 if (c_parser_next_token_is (parser
, CPP_COLON
))
4268 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4269 /* Make sure first operand is calculated only once. */
4270 exp1
.value
= save_expr (default_conversion (cond
.value
));
4271 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4272 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4277 = c_objc_common_truthvalue_conversion
4278 (default_conversion (cond
.value
));
4279 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4280 exp1
= c_parser_expression_conv (parser
);
4281 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4282 - (cond
.value
== truthvalue_false_node
));
4284 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4286 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4287 ret
.value
= error_mark_node
;
4288 ret
.original_code
= ERROR_MARK
;
4291 exp2
= c_parser_conditional_expression (parser
, NULL
);
4292 exp2
= default_function_array_conversion (exp2
);
4293 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4294 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4295 ret
.original_code
= ERROR_MARK
;
4299 /* Parse a binary expression; that is, a logical-OR-expression (C90
4300 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4301 an Objective-C message expression which is the primary-expression
4302 starting the expression as an initializer.
4304 multiplicative-expression:
4306 multiplicative-expression * cast-expression
4307 multiplicative-expression / cast-expression
4308 multiplicative-expression % cast-expression
4310 additive-expression:
4311 multiplicative-expression
4312 additive-expression + multiplicative-expression
4313 additive-expression - multiplicative-expression
4317 shift-expression << additive-expression
4318 shift-expression >> additive-expression
4320 relational-expression:
4322 relational-expression < shift-expression
4323 relational-expression > shift-expression
4324 relational-expression <= shift-expression
4325 relational-expression >= shift-expression
4327 equality-expression:
4328 relational-expression
4329 equality-expression == relational-expression
4330 equality-expression != relational-expression
4334 AND-expression & equality-expression
4336 exclusive-OR-expression:
4338 exclusive-OR-expression ^ AND-expression
4340 inclusive-OR-expression:
4341 exclusive-OR-expression
4342 inclusive-OR-expression | exclusive-OR-expression
4344 logical-AND-expression:
4345 inclusive-OR-expression
4346 logical-AND-expression && inclusive-OR-expression
4348 logical-OR-expression:
4349 logical-AND-expression
4350 logical-OR-expression || logical-AND-expression
4353 static struct c_expr
4354 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4356 /* A binary expression is parsed using operator-precedence parsing,
4357 with the operands being cast expressions. All the binary
4358 operators are left-associative. Thus a binary expression is of
4361 E0 op1 E1 op2 E2 ...
4363 which we represent on a stack. On the stack, the precedence
4364 levels are strictly increasing. When a new operator is
4365 encountered of higher precedence than that at the top of the
4366 stack, it is pushed; its LHS is the top expression, and its RHS
4367 is everything parsed until it is popped. When a new operator is
4368 encountered with precedence less than or equal to that at the top
4369 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4370 by the result of the operation until the operator at the top of
4371 the stack has lower precedence than the new operator or there is
4372 only one element on the stack; then the top expression is the LHS
4373 of the new operator. In the case of logical AND and OR
4374 expressions, we also need to adjust skip_evaluation as
4375 appropriate when the operators are pushed and popped. */
4377 /* The precedence levels, where 0 is a dummy lowest level used for
4378 the bottom of the stack. */
4394 /* The expression at this stack level. */
4396 /* The precedence of the operator on its left, PREC_NONE at the
4397 bottom of the stack. */
4399 /* The operation on its left. */
4405 switch (stack[sp].op) \
4407 case TRUTH_ANDIF_EXPR: \
4408 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4410 case TRUTH_ORIF_EXPR: \
4411 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4416 stack[sp - 1].expr \
4417 = default_function_array_conversion (stack[sp - 1].expr); \
4419 = default_function_array_conversion (stack[sp].expr); \
4420 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4421 stack[sp - 1].expr, \
4425 gcc_assert (!after
|| c_dialect_objc ());
4426 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4427 stack
[0].prec
= PREC_NONE
;
4432 enum tree_code ocode
;
4435 switch (c_parser_peek_token (parser
)->type
)
4443 ocode
= TRUNC_DIV_EXPR
;
4447 ocode
= TRUNC_MOD_EXPR
;
4459 ocode
= LSHIFT_EXPR
;
4463 ocode
= RSHIFT_EXPR
;
4477 case CPP_GREATER_EQ
:
4490 oprec
= PREC_BITAND
;
4491 ocode
= BIT_AND_EXPR
;
4494 oprec
= PREC_BITXOR
;
4495 ocode
= BIT_XOR_EXPR
;
4499 ocode
= BIT_IOR_EXPR
;
4502 oprec
= PREC_LOGAND
;
4503 ocode
= TRUTH_ANDIF_EXPR
;
4507 ocode
= TRUTH_ORIF_EXPR
;
4510 /* Not a binary operator, so end of the binary
4514 c_parser_consume_token (parser
);
4515 while (oprec
<= stack
[sp
].prec
)
4519 case TRUTH_ANDIF_EXPR
:
4521 = default_function_array_conversion (stack
[sp
].expr
);
4522 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4523 (default_conversion (stack
[sp
].expr
.value
));
4524 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4526 case TRUTH_ORIF_EXPR
:
4528 = default_function_array_conversion (stack
[sp
].expr
);
4529 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4530 (default_conversion (stack
[sp
].expr
.value
));
4531 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4537 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4538 stack
[sp
].prec
= oprec
;
4539 stack
[sp
].op
= ocode
;
4544 return stack
[0].expr
;
4548 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4549 NULL then it is an Objective-C message expression which is the
4550 primary-expression starting the expression as an initializer.
4554 ( type-name ) unary-expression
4557 static struct c_expr
4558 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4560 gcc_assert (!after
|| c_dialect_objc ());
4562 return c_parser_postfix_expression_after_primary (parser
, *after
);
4563 /* If the expression begins with a parenthesized type name, it may
4564 be either a cast or a compound literal; we need to see whether
4565 the next character is '{' to tell the difference. If not, it is
4566 an unary expression. */
4567 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4568 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4570 struct c_type_name
*type_name
;
4573 c_parser_consume_token (parser
);
4574 type_name
= c_parser_type_name (parser
);
4575 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4576 if (type_name
== NULL
)
4578 ret
.value
= error_mark_node
;
4579 ret
.original_code
= ERROR_MARK
;
4582 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4583 return c_parser_postfix_expression_after_paren_type (parser
,
4585 expr
= c_parser_cast_expression (parser
, NULL
);
4586 expr
= default_function_array_conversion (expr
);
4587 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4588 ret
.original_code
= ERROR_MARK
;
4592 return c_parser_unary_expression (parser
);
4595 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4601 unary-operator cast-expression
4602 sizeof unary-expression
4603 sizeof ( type-name )
4605 unary-operator: one of
4611 __alignof__ unary-expression
4612 __alignof__ ( type-name )
4615 unary-operator: one of
4616 __extension__ __real__ __imag__
4618 In addition, the GNU syntax treats ++ and -- as unary operators, so
4619 they may be applied to cast expressions with errors for non-lvalues
4622 static struct c_expr
4623 c_parser_unary_expression (c_parser
*parser
)
4626 struct c_expr ret
, op
;
4627 switch (c_parser_peek_token (parser
)->type
)
4630 c_parser_consume_token (parser
);
4631 op
= c_parser_cast_expression (parser
, NULL
);
4632 op
= default_function_array_conversion (op
);
4633 return parser_build_unary_op (PREINCREMENT_EXPR
, op
);
4634 case CPP_MINUS_MINUS
:
4635 c_parser_consume_token (parser
);
4636 op
= c_parser_cast_expression (parser
, NULL
);
4637 op
= default_function_array_conversion (op
);
4638 return parser_build_unary_op (PREDECREMENT_EXPR
, op
);
4640 c_parser_consume_token (parser
);
4641 return parser_build_unary_op (ADDR_EXPR
,
4642 c_parser_cast_expression (parser
, NULL
));
4644 c_parser_consume_token (parser
);
4645 op
= c_parser_cast_expression (parser
, NULL
);
4646 op
= default_function_array_conversion (op
);
4647 ret
.value
= build_indirect_ref (op
.value
, "unary *");
4648 ret
.original_code
= ERROR_MARK
;
4651 c_parser_consume_token (parser
);
4652 if (!c_dialect_objc () && !in_system_header
)
4653 warning (OPT_Wtraditional
,
4654 "traditional C rejects the unary plus operator");
4655 op
= c_parser_cast_expression (parser
, NULL
);
4656 op
= default_function_array_conversion (op
);
4657 return parser_build_unary_op (CONVERT_EXPR
, op
);
4659 c_parser_consume_token (parser
);
4660 op
= c_parser_cast_expression (parser
, NULL
);
4661 op
= default_function_array_conversion (op
);
4662 return parser_build_unary_op (NEGATE_EXPR
, op
);
4664 c_parser_consume_token (parser
);
4665 op
= c_parser_cast_expression (parser
, NULL
);
4666 op
= default_function_array_conversion (op
);
4667 return parser_build_unary_op (BIT_NOT_EXPR
, op
);
4669 c_parser_consume_token (parser
);
4670 op
= c_parser_cast_expression (parser
, NULL
);
4671 op
= default_function_array_conversion (op
);
4672 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
);
4674 /* Refer to the address of a label as a pointer. */
4675 c_parser_consume_token (parser
);
4676 if (c_parser_next_token_is (parser
, CPP_NAME
))
4678 ret
.value
= finish_label_address_expr
4679 (c_parser_peek_token (parser
)->value
);
4680 c_parser_consume_token (parser
);
4684 c_parser_error (parser
, "expected identifier");
4685 ret
.value
= error_mark_node
;
4687 ret
.original_code
= ERROR_MARK
;
4690 switch (c_parser_peek_token (parser
)->keyword
)
4693 return c_parser_sizeof_expression (parser
);
4695 return c_parser_alignof_expression (parser
);
4697 c_parser_consume_token (parser
);
4698 ext
= disable_extension_diagnostics ();
4699 ret
= c_parser_cast_expression (parser
, NULL
);
4700 restore_extension_diagnostics (ext
);
4703 c_parser_consume_token (parser
);
4704 op
= c_parser_cast_expression (parser
, NULL
);
4705 op
= default_function_array_conversion (op
);
4706 return parser_build_unary_op (REALPART_EXPR
, op
);
4708 c_parser_consume_token (parser
);
4709 op
= c_parser_cast_expression (parser
, NULL
);
4710 op
= default_function_array_conversion (op
);
4711 return parser_build_unary_op (IMAGPART_EXPR
, op
);
4713 return c_parser_postfix_expression (parser
);
4716 return c_parser_postfix_expression (parser
);
4720 /* Parse a sizeof expression. */
4722 static struct c_expr
4723 c_parser_sizeof_expression (c_parser
*parser
)
4726 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4727 c_parser_consume_token (parser
);
4730 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4731 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4733 /* Either sizeof ( type-name ) or sizeof unary-expression
4734 starting with a compound literal. */
4735 struct c_type_name
*type_name
;
4736 c_parser_consume_token (parser
);
4737 type_name
= c_parser_type_name (parser
);
4738 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4739 if (type_name
== NULL
)
4744 ret
.value
= error_mark_node
;
4745 ret
.original_code
= ERROR_MARK
;
4748 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4750 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4754 /* sizeof ( type-name ). */
4757 return c_expr_sizeof_type (type_name
);
4761 expr
= c_parser_unary_expression (parser
);
4765 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4766 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4767 error ("%<sizeof%> applied to a bit-field");
4768 return c_expr_sizeof_expr (expr
);
4772 /* Parse an alignof expression. */
4774 static struct c_expr
4775 c_parser_alignof_expression (c_parser
*parser
)
4778 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4779 c_parser_consume_token (parser
);
4782 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4783 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4785 /* Either __alignof__ ( type-name ) or __alignof__
4786 unary-expression starting with a compound literal. */
4787 struct c_type_name
*type_name
;
4789 c_parser_consume_token (parser
);
4790 type_name
= c_parser_type_name (parser
);
4791 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4792 if (type_name
== NULL
)
4797 ret
.value
= error_mark_node
;
4798 ret
.original_code
= ERROR_MARK
;
4801 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4803 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4807 /* alignof ( type-name ). */
4810 ret
.value
= c_alignof (groktypename (type_name
));
4811 ret
.original_code
= ERROR_MARK
;
4817 expr
= c_parser_unary_expression (parser
);
4821 ret
.value
= c_alignof_expr (expr
.value
);
4822 ret
.original_code
= ERROR_MARK
;
4827 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4831 postfix-expression [ expression ]
4832 postfix-expression ( argument-expression-list[opt] )
4833 postfix-expression . identifier
4834 postfix-expression -> identifier
4835 postfix-expression ++
4836 postfix-expression --
4837 ( type-name ) { initializer-list }
4838 ( type-name ) { initializer-list , }
4840 argument-expression-list:
4842 argument-expression-list , argument-expression
4854 (treated as a keyword in GNU C)
4857 ( compound-statement )
4858 __builtin_va_arg ( assignment-expression , type-name )
4859 __builtin_offsetof ( type-name , offsetof-member-designator )
4860 __builtin_choose_expr ( assignment-expression ,
4861 assignment-expression ,
4862 assignment-expression )
4863 __builtin_types_compatible_p ( type-name , type-name )
4865 offsetof-member-designator:
4867 offsetof-member-designator . identifier
4868 offsetof-member-designator [ expression ]
4873 [ objc-receiver objc-message-args ]
4874 @selector ( objc-selector-arg )
4875 @protocol ( identifier )
4876 @encode ( type-name )
4880 static struct c_expr
4881 c_parser_postfix_expression (c_parser
*parser
)
4883 struct c_expr expr
, e1
, e2
, e3
;
4884 struct c_type_name
*t1
, *t2
;
4885 switch (c_parser_peek_token (parser
)->type
)
4890 expr
.value
= c_parser_peek_token (parser
)->value
;
4891 expr
.original_code
= ERROR_MARK
;
4892 c_parser_consume_token (parser
);
4896 expr
.value
= c_parser_peek_token (parser
)->value
;
4897 expr
.original_code
= STRING_CST
;
4898 c_parser_consume_token (parser
);
4900 case CPP_OBJC_STRING
:
4901 gcc_assert (c_dialect_objc ());
4903 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
4904 expr
.original_code
= ERROR_MARK
;
4905 c_parser_consume_token (parser
);
4908 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
4910 c_parser_error (parser
, "expected expression");
4911 expr
.value
= error_mark_node
;
4912 expr
.original_code
= ERROR_MARK
;
4916 tree id
= c_parser_peek_token (parser
)->value
;
4917 location_t loc
= c_parser_peek_token (parser
)->location
;
4918 c_parser_consume_token (parser
);
4919 expr
.value
= build_external_ref (id
,
4920 (c_parser_peek_token (parser
)->type
4921 == CPP_OPEN_PAREN
), loc
);
4922 expr
.original_code
= ERROR_MARK
;
4925 case CPP_OPEN_PAREN
:
4926 /* A parenthesized expression, statement expression or compound
4928 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
4930 /* A statement expression. */
4932 c_parser_consume_token (parser
);
4933 c_parser_consume_token (parser
);
4934 if (cur_stmt_list
== NULL
)
4936 error ("braced-group within expression allowed "
4937 "only inside a function");
4938 parser
->error
= true;
4939 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
4940 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4941 expr
.value
= error_mark_node
;
4942 expr
.original_code
= ERROR_MARK
;
4945 stmt
= c_begin_stmt_expr ();
4946 c_parser_compound_statement_nostart (parser
);
4947 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4950 pedwarn ("ISO C forbids braced-groups within expressions");
4951 expr
.value
= c_finish_stmt_expr (stmt
);
4952 expr
.original_code
= ERROR_MARK
;
4954 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4956 /* A compound literal. ??? Can we actually get here rather
4957 than going directly to
4958 c_parser_postfix_expression_after_paren_type from
4960 struct c_type_name
*type_name
;
4961 c_parser_consume_token (parser
);
4962 type_name
= c_parser_type_name (parser
);
4963 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4965 if (type_name
== NULL
)
4967 expr
.value
= error_mark_node
;
4968 expr
.original_code
= ERROR_MARK
;
4971 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4976 /* A parenthesized expression. */
4977 c_parser_consume_token (parser
);
4978 expr
= c_parser_expression (parser
);
4979 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
4980 TREE_NO_WARNING (expr
.value
) = 1;
4981 expr
.original_code
= ERROR_MARK
;
4982 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4987 switch (c_parser_peek_token (parser
)->keyword
)
4989 case RID_FUNCTION_NAME
:
4990 case RID_PRETTY_FUNCTION_NAME
:
4991 case RID_C99_FUNCTION_NAME
:
4992 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
4993 c_parser_peek_token (parser
)->value
);
4994 expr
.original_code
= ERROR_MARK
;
4995 c_parser_consume_token (parser
);
4998 c_parser_consume_token (parser
);
4999 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5001 expr
.value
= error_mark_node
;
5002 expr
.original_code
= ERROR_MARK
;
5005 e1
= c_parser_expr_no_commas (parser
, NULL
);
5006 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5008 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5009 expr
.value
= error_mark_node
;
5010 expr
.original_code
= ERROR_MARK
;
5013 t1
= c_parser_type_name (parser
);
5014 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5018 expr
.value
= error_mark_node
;
5019 expr
.original_code
= ERROR_MARK
;
5023 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
5024 expr
.original_code
= ERROR_MARK
;
5028 c_parser_consume_token (parser
);
5029 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5031 expr
.value
= error_mark_node
;
5032 expr
.original_code
= ERROR_MARK
;
5035 t1
= c_parser_type_name (parser
);
5038 expr
.value
= error_mark_node
;
5039 expr
.original_code
= ERROR_MARK
;
5042 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5044 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5045 expr
.value
= error_mark_node
;
5046 expr
.original_code
= ERROR_MARK
;
5050 tree type
= groktypename (t1
);
5052 if (type
== error_mark_node
)
5053 offsetof_ref
= error_mark_node
;
5055 offsetof_ref
= build1 (INDIRECT_REF
, type
, NULL
);
5056 /* Parse the second argument to __builtin_offsetof. We
5057 must have one identifier, and beyond that we want to
5058 accept sub structure and sub array references. */
5059 if (c_parser_next_token_is (parser
, CPP_NAME
))
5061 offsetof_ref
= build_component_ref
5062 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5063 c_parser_consume_token (parser
);
5064 while (c_parser_next_token_is (parser
, CPP_DOT
)
5065 || c_parser_next_token_is (parser
,
5068 if (c_parser_next_token_is (parser
, CPP_DOT
))
5070 c_parser_consume_token (parser
);
5071 if (c_parser_next_token_is_not (parser
,
5074 c_parser_error (parser
, "expected identifier");
5077 offsetof_ref
= build_component_ref
5079 c_parser_peek_token (parser
)->value
);
5080 c_parser_consume_token (parser
);
5085 c_parser_consume_token (parser
);
5086 idx
= c_parser_expression (parser
).value
;
5087 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5089 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
5094 c_parser_error (parser
, "expected identifier");
5095 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5097 expr
.value
= fold_offsetof (offsetof_ref
);
5098 expr
.original_code
= ERROR_MARK
;
5101 case RID_CHOOSE_EXPR
:
5102 c_parser_consume_token (parser
);
5103 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5105 expr
.value
= error_mark_node
;
5106 expr
.original_code
= ERROR_MARK
;
5109 e1
= c_parser_expr_no_commas (parser
, NULL
);
5110 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5112 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5113 expr
.value
= error_mark_node
;
5114 expr
.original_code
= ERROR_MARK
;
5117 e2
= c_parser_expr_no_commas (parser
, NULL
);
5118 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5120 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5121 expr
.value
= error_mark_node
;
5122 expr
.original_code
= ERROR_MARK
;
5125 e3
= c_parser_expr_no_commas (parser
, NULL
);
5126 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5131 c
= fold (e1
.value
);
5132 if (TREE_CODE (c
) != INTEGER_CST
)
5133 error ("first argument to %<__builtin_choose_expr%> not"
5135 expr
= integer_zerop (c
) ? e3
: e2
;
5138 case RID_TYPES_COMPATIBLE_P
:
5139 c_parser_consume_token (parser
);
5140 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5142 expr
.value
= error_mark_node
;
5143 expr
.original_code
= ERROR_MARK
;
5146 t1
= c_parser_type_name (parser
);
5149 expr
.value
= error_mark_node
;
5150 expr
.original_code
= ERROR_MARK
;
5153 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5155 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5156 expr
.value
= error_mark_node
;
5157 expr
.original_code
= ERROR_MARK
;
5160 t2
= c_parser_type_name (parser
);
5163 expr
.value
= error_mark_node
;
5164 expr
.original_code
= ERROR_MARK
;
5167 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5172 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5173 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5175 expr
.value
= comptypes (e1
, e2
)
5176 ? build_int_cst (NULL_TREE
, 1)
5177 : build_int_cst (NULL_TREE
, 0);
5178 expr
.original_code
= ERROR_MARK
;
5181 case RID_AT_SELECTOR
:
5182 gcc_assert (c_dialect_objc ());
5183 c_parser_consume_token (parser
);
5184 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5186 expr
.value
= error_mark_node
;
5187 expr
.original_code
= ERROR_MARK
;
5191 tree sel
= c_parser_objc_selector_arg (parser
);
5192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5194 expr
.value
= objc_build_selector_expr (sel
);
5195 expr
.original_code
= ERROR_MARK
;
5198 case RID_AT_PROTOCOL
:
5199 gcc_assert (c_dialect_objc ());
5200 c_parser_consume_token (parser
);
5201 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5203 expr
.value
= error_mark_node
;
5204 expr
.original_code
= ERROR_MARK
;
5207 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5209 c_parser_error (parser
, "expected identifier");
5210 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5211 expr
.value
= error_mark_node
;
5212 expr
.original_code
= ERROR_MARK
;
5216 tree id
= c_parser_peek_token (parser
)->value
;
5217 c_parser_consume_token (parser
);
5218 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5220 expr
.value
= objc_build_protocol_expr (id
);
5221 expr
.original_code
= ERROR_MARK
;
5225 /* Extension to support C-structures in the archiver. */
5226 gcc_assert (c_dialect_objc ());
5227 c_parser_consume_token (parser
);
5228 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5230 expr
.value
= error_mark_node
;
5231 expr
.original_code
= ERROR_MARK
;
5234 t1
= c_parser_type_name (parser
);
5237 expr
.value
= error_mark_node
;
5238 expr
.original_code
= ERROR_MARK
;
5239 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5242 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5245 tree type
= groktypename (t1
);
5246 expr
.value
= objc_build_encode_expr (type
);
5247 expr
.original_code
= ERROR_MARK
;
5251 c_parser_error (parser
, "expected expression");
5252 expr
.value
= error_mark_node
;
5253 expr
.original_code
= ERROR_MARK
;
5257 case CPP_OPEN_SQUARE
:
5258 if (c_dialect_objc ())
5260 tree receiver
, args
;
5261 c_parser_consume_token (parser
);
5262 receiver
= c_parser_objc_receiver (parser
);
5263 args
= c_parser_objc_message_args (parser
);
5264 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5266 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5268 expr
.original_code
= ERROR_MARK
;
5271 /* Else fall through to report error. */
5273 c_parser_error (parser
, "expected expression");
5274 expr
.value
= error_mark_node
;
5275 expr
.original_code
= ERROR_MARK
;
5278 return c_parser_postfix_expression_after_primary (parser
, expr
);
5281 /* Parse a postfix expression after a parenthesized type name: the
5282 brace-enclosed initializer of a compound literal, possibly followed
5283 by some postfix operators. This is separate because it is not
5284 possible to tell until after the type name whether a cast
5285 expression has a cast or a compound literal, or whether the operand
5286 of sizeof is a parenthesized type name or starts with a compound
5289 static struct c_expr
5290 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5291 struct c_type_name
*type_name
)
5296 start_init (NULL_TREE
, NULL
, 0);
5297 type
= groktypename (type_name
);
5298 if (C_TYPE_VARIABLE_SIZE (type
))
5300 error ("compound literal has variable size");
5301 type
= error_mark_node
;
5303 init
= c_parser_braced_init (parser
, type
, false);
5305 maybe_warn_string_init (type
, init
);
5307 if (pedantic
&& !flag_isoc99
)
5308 pedwarn ("ISO C90 forbids compound literals");
5309 expr
.value
= build_compound_literal (type
, init
.value
);
5310 expr
.original_code
= ERROR_MARK
;
5311 return c_parser_postfix_expression_after_primary (parser
, expr
);
5314 /* Parse a postfix expression after the initial primary or compound
5315 literal; that is, parse a series of postfix operators. */
5317 static struct c_expr
5318 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5321 tree ident
, idx
, exprlist
;
5324 switch (c_parser_peek_token (parser
)->type
)
5326 case CPP_OPEN_SQUARE
:
5327 /* Array reference. */
5328 c_parser_consume_token (parser
);
5329 idx
= c_parser_expression (parser
).value
;
5330 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5332 expr
.value
= build_array_ref (expr
.value
, idx
);
5333 expr
.original_code
= ERROR_MARK
;
5335 case CPP_OPEN_PAREN
:
5336 /* Function call. */
5337 c_parser_consume_token (parser
);
5338 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5339 exprlist
= NULL_TREE
;
5341 exprlist
= c_parser_expr_list (parser
, true);
5342 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5344 expr
.value
= build_function_call (expr
.value
, exprlist
);
5345 expr
.original_code
= ERROR_MARK
;
5348 /* Structure element reference. */
5349 c_parser_consume_token (parser
);
5350 expr
= default_function_array_conversion (expr
);
5351 if (c_parser_next_token_is (parser
, CPP_NAME
))
5352 ident
= c_parser_peek_token (parser
)->value
;
5355 c_parser_error (parser
, "expected identifier");
5356 expr
.value
= error_mark_node
;
5357 expr
.original_code
= ERROR_MARK
;
5360 c_parser_consume_token (parser
);
5361 expr
.value
= build_component_ref (expr
.value
, ident
);
5362 expr
.original_code
= ERROR_MARK
;
5365 /* Structure element reference. */
5366 c_parser_consume_token (parser
);
5367 expr
= default_function_array_conversion (expr
);
5368 if (c_parser_next_token_is (parser
, CPP_NAME
))
5369 ident
= c_parser_peek_token (parser
)->value
;
5372 c_parser_error (parser
, "expected identifier");
5373 expr
.value
= error_mark_node
;
5374 expr
.original_code
= ERROR_MARK
;
5377 c_parser_consume_token (parser
);
5378 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5380 expr
.original_code
= ERROR_MARK
;
5383 /* Postincrement. */
5384 c_parser_consume_token (parser
);
5385 expr
= default_function_array_conversion (expr
);
5386 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5387 expr
.original_code
= ERROR_MARK
;
5389 case CPP_MINUS_MINUS
:
5390 /* Postdecrement. */
5391 c_parser_consume_token (parser
);
5392 expr
= default_function_array_conversion (expr
);
5393 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5394 expr
.original_code
= ERROR_MARK
;
5402 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5405 assignment-expression
5406 expression , assignment-expression
5409 static struct c_expr
5410 c_parser_expression (c_parser
*parser
)
5413 expr
= c_parser_expr_no_commas (parser
, NULL
);
5414 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5417 c_parser_consume_token (parser
);
5418 next
= c_parser_expr_no_commas (parser
, NULL
);
5419 next
= default_function_array_conversion (next
);
5420 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5421 expr
.original_code
= COMPOUND_EXPR
;
5426 /* Parse an expression and convert functions or arrays to
5429 static struct c_expr
5430 c_parser_expression_conv (c_parser
*parser
)
5433 expr
= c_parser_expression (parser
);
5434 expr
= default_function_array_conversion (expr
);
5438 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5439 functions and arrays to pointers.
5442 assignment-expression
5443 nonempty-expr-list , assignment-expression
5447 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5451 expr
= c_parser_expr_no_commas (parser
, NULL
);
5453 expr
= default_function_array_conversion (expr
);
5454 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5455 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5457 c_parser_consume_token (parser
);
5458 expr
= c_parser_expr_no_commas (parser
, NULL
);
5460 expr
= default_function_array_conversion (expr
);
5461 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5467 /* Parse Objective-C-specific constructs. */
5469 /* Parse an objc-class-definition.
5471 objc-class-definition:
5472 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5473 objc-class-instance-variables[opt] objc-methodprotolist @end
5474 @implementation identifier objc-superclass[opt]
5475 objc-class-instance-variables[opt]
5476 @interface identifier ( identifier ) objc-protocol-refs[opt]
5477 objc-methodprotolist @end
5478 @implementation identifier ( identifier )
5483 "@interface identifier (" must start "@interface identifier (
5484 identifier ) ...": objc-methodprotolist in the first production may
5485 not start with a parenthesized identifier as a declarator of a data
5486 definition with no declaration specifiers if the objc-superclass,
5487 objc-protocol-refs and objc-class-instance-variables are omitted. */
5490 c_parser_objc_class_definition (c_parser
*parser
)
5495 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5497 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5501 c_parser_consume_token (parser
);
5502 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5504 c_parser_error (parser
, "expected identifier");
5507 id1
= c_parser_peek_token (parser
)->value
;
5508 c_parser_consume_token (parser
);
5509 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5512 tree proto
= NULL_TREE
;
5513 c_parser_consume_token (parser
);
5514 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5516 c_parser_error (parser
, "expected identifier");
5517 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5520 id2
= c_parser_peek_token (parser
)->value
;
5521 c_parser_consume_token (parser
);
5522 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5525 objc_start_category_implementation (id1
, id2
);
5528 if (c_parser_next_token_is (parser
, CPP_LESS
))
5529 proto
= c_parser_objc_protocol_refs (parser
);
5530 objc_start_category_interface (id1
, id2
, proto
);
5531 c_parser_objc_methodprotolist (parser
);
5532 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5533 objc_finish_interface ();
5536 if (c_parser_next_token_is (parser
, CPP_COLON
))
5538 c_parser_consume_token (parser
);
5539 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5541 c_parser_error (parser
, "expected identifier");
5544 superclass
= c_parser_peek_token (parser
)->value
;
5545 c_parser_consume_token (parser
);
5548 superclass
= NULL_TREE
;
5551 tree proto
= NULL_TREE
;
5552 if (c_parser_next_token_is (parser
, CPP_LESS
))
5553 proto
= c_parser_objc_protocol_refs (parser
);
5554 objc_start_class_interface (id1
, superclass
, proto
);
5557 objc_start_class_implementation (id1
, superclass
);
5558 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5559 c_parser_objc_class_instance_variables (parser
);
5562 objc_continue_interface ();
5563 c_parser_objc_methodprotolist (parser
);
5564 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5565 objc_finish_interface ();
5569 objc_continue_implementation ();
5574 /* Parse objc-class-instance-variables.
5576 objc-class-instance-variables:
5577 { objc-instance-variable-decl-list[opt] }
5579 objc-instance-variable-decl-list:
5580 objc-visibility-spec
5581 objc-instance-variable-decl ;
5583 objc-instance-variable-decl-list objc-visibility-spec
5584 objc-instance-variable-decl-list objc-instance-variable-decl ;
5585 objc-instance-variable-decl-list ;
5587 objc-visibility-spec:
5592 objc-instance-variable-decl:
5597 c_parser_objc_class_instance_variables (c_parser
*parser
)
5599 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5600 c_parser_consume_token (parser
);
5601 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5604 /* Parse any stray semicolon. */
5605 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5608 pedwarn ("extra semicolon in struct or union specified");
5609 c_parser_consume_token (parser
);
5612 /* Stop if at the end of the instance variables. */
5613 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5615 c_parser_consume_token (parser
);
5618 /* Parse any objc-visibility-spec. */
5619 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5621 c_parser_consume_token (parser
);
5622 objc_set_visibility (2);
5625 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5627 c_parser_consume_token (parser
);
5628 objc_set_visibility (0);
5631 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5633 c_parser_consume_token (parser
);
5634 objc_set_visibility (1);
5637 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5639 c_parser_pragma (parser
, pragma_external
);
5643 /* Parse some comma-separated declarations. */
5644 decls
= c_parser_struct_declaration (parser
);
5646 /* Comma-separated instance variables are chained together in
5647 reverse order; add them one by one. */
5648 tree ivar
= nreverse (decls
);
5649 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5650 objc_add_instance_variable (copy_node (ivar
));
5652 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5656 /* Parse an objc-class-declaration.
5658 objc-class-declaration:
5659 @class identifier-list ;
5663 c_parser_objc_class_declaration (c_parser
*parser
)
5665 tree list
= NULL_TREE
;
5666 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5667 c_parser_consume_token (parser
);
5668 /* Any identifiers, including those declared as type names, are OK
5673 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5675 c_parser_error (parser
, "expected identifier");
5678 id
= c_parser_peek_token (parser
)->value
;
5679 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5680 c_parser_consume_token (parser
);
5681 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5682 c_parser_consume_token (parser
);
5686 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5687 objc_declare_class (list
);
5690 /* Parse an objc-alias-declaration.
5692 objc-alias-declaration:
5693 @compatibility_alias identifier identifier ;
5697 c_parser_objc_alias_declaration (c_parser
*parser
)
5700 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5701 c_parser_consume_token (parser
);
5702 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5704 c_parser_error (parser
, "expected identifier");
5705 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5708 id1
= c_parser_peek_token (parser
)->value
;
5709 c_parser_consume_token (parser
);
5710 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5712 c_parser_error (parser
, "expected identifier");
5713 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5716 id2
= c_parser_peek_token (parser
)->value
;
5717 c_parser_consume_token (parser
);
5718 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5719 objc_declare_alias (id1
, id2
);
5722 /* Parse an objc-protocol-definition.
5724 objc-protocol-definition:
5725 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5726 @protocol identifier-list ;
5728 "@protocol identifier ;" should be resolved as "@protocol
5729 identifier-list ;": objc-methodprotolist may not start with a
5730 semicolon in the first alternative if objc-protocol-refs are
5734 c_parser_objc_protocol_definition (c_parser
*parser
)
5736 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5737 c_parser_consume_token (parser
);
5738 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5740 c_parser_error (parser
, "expected identifier");
5743 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5744 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5746 tree list
= NULL_TREE
;
5747 /* Any identifiers, including those declared as type names, are
5752 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5754 c_parser_error (parser
, "expected identifier");
5757 id
= c_parser_peek_token (parser
)->value
;
5758 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5759 c_parser_consume_token (parser
);
5760 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5761 c_parser_consume_token (parser
);
5765 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5766 objc_declare_protocols (list
);
5770 tree id
= c_parser_peek_token (parser
)->value
;
5771 tree proto
= NULL_TREE
;
5772 c_parser_consume_token (parser
);
5773 if (c_parser_next_token_is (parser
, CPP_LESS
))
5774 proto
= c_parser_objc_protocol_refs (parser
);
5775 objc_pq_context
= 1;
5776 objc_start_protocol (id
, proto
);
5777 c_parser_objc_methodprotolist (parser
);
5778 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5779 objc_pq_context
= 0;
5780 objc_finish_interface ();
5784 /* Parse an objc-method-type.
5791 static enum tree_code
5792 c_parser_objc_method_type (c_parser
*parser
)
5794 switch (c_parser_peek_token (parser
)->type
)
5797 c_parser_consume_token (parser
);
5800 c_parser_consume_token (parser
);
5807 /* Parse an objc-method-definition.
5809 objc-method-definition:
5810 objc-method-type objc-method-decl ;[opt] compound-statement
5814 c_parser_objc_method_definition (c_parser
*parser
)
5816 enum tree_code type
= c_parser_objc_method_type (parser
);
5818 objc_set_method_type (type
);
5819 objc_pq_context
= 1;
5820 decl
= c_parser_objc_method_decl (parser
);
5821 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5823 c_parser_consume_token (parser
);
5825 pedwarn ("extra semicolon in method definition specified");
5827 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5829 c_parser_error (parser
, "expected %<{%>");
5832 objc_pq_context
= 0;
5833 objc_start_method_definition (decl
);
5834 add_stmt (c_parser_compound_statement (parser
));
5835 objc_finish_method_definition (current_function_decl
);
5838 /* Parse an objc-methodprotolist.
5840 objc-methodprotolist:
5842 objc-methodprotolist objc-methodproto
5843 objc-methodprotolist declaration
5844 objc-methodprotolist ;
5846 The declaration is a data definition, which may be missing
5847 declaration specifiers under the same rules and diagnostics as
5848 other data definitions outside functions, and the stray semicolon
5849 is diagnosed the same way as a stray semicolon outside a
5853 c_parser_objc_methodprotolist (c_parser
*parser
)
5857 /* The list is terminated by @end. */
5858 switch (c_parser_peek_token (parser
)->type
)
5862 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5863 c_parser_consume_token (parser
);
5867 c_parser_objc_methodproto (parser
);
5870 c_parser_pragma (parser
, pragma_external
);
5875 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
5877 c_parser_declaration_or_fndef (parser
, false, true, false, true);
5883 /* Parse an objc-methodproto.
5886 objc-method-type objc-method-decl ;
5890 c_parser_objc_methodproto (c_parser
*parser
)
5892 enum tree_code type
= c_parser_objc_method_type (parser
);
5894 objc_set_method_type (type
);
5895 /* Remember protocol qualifiers in prototypes. */
5896 objc_pq_context
= 1;
5897 decl
= c_parser_objc_method_decl (parser
);
5898 /* Forget protocol qualifiers here. */
5899 objc_pq_context
= 0;
5900 objc_add_method_declaration (decl
);
5901 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5904 /* Parse an objc-method-decl.
5907 ( objc-type-name ) objc-selector
5909 ( objc-type-name ) objc-keyword-selector objc-optparmlist
5910 objc-keyword-selector objc-optparmlist
5912 objc-keyword-selector:
5914 objc-keyword-selector objc-keyword-decl
5917 objc-selector : ( objc-type-name ) identifier
5918 objc-selector : identifier
5919 : ( objc-type-name ) identifier
5923 objc-optparms objc-optellipsis
5927 objc-opt-parms , parameter-declaration
5935 c_parser_objc_method_decl (c_parser
*parser
)
5937 tree type
= NULL_TREE
;
5939 tree parms
= NULL_TREE
;
5940 bool ellipsis
= false;
5942 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5944 c_parser_consume_token (parser
);
5945 type
= c_parser_objc_type_name (parser
);
5946 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5948 sel
= c_parser_objc_selector (parser
);
5949 /* If there is no selector, or a colon follows, we have an
5950 objc-keyword-selector. If there is a selector, and a colon does
5951 not follow, that selector ends the objc-method-decl. */
5952 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
5955 tree list
= NULL_TREE
;
5958 tree atype
= NULL_TREE
, id
, keyworddecl
;
5959 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5961 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5963 c_parser_consume_token (parser
);
5964 atype
= c_parser_objc_type_name (parser
);
5965 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5968 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5970 c_parser_error (parser
, "expected identifier");
5971 return error_mark_node
;
5973 id
= c_parser_peek_token (parser
)->value
;
5974 c_parser_consume_token (parser
);
5975 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
5976 list
= chainon (list
, keyworddecl
);
5977 tsel
= c_parser_objc_selector (parser
);
5978 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
5981 /* Parse the optional parameter list. Optional Objective-C
5982 method parameters follow the C syntax, and may include '...'
5983 to denote a variable number of arguments. */
5984 parms
= make_node (TREE_LIST
);
5985 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5987 struct c_parm
*parm
;
5988 c_parser_consume_token (parser
);
5989 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5992 c_parser_consume_token (parser
);
5995 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5998 parms
= chainon (parms
,
5999 build_tree_list (NULL_TREE
, grokparm (parm
)));
6003 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6006 /* Parse an objc-type-name.
6009 objc-type-qualifiers[opt] type-name
6010 objc-type-qualifiers[opt]
6012 objc-type-qualifiers:
6014 objc-type-qualifiers objc-type-qualifier
6016 objc-type-qualifier: one of
6017 in out inout bycopy byref oneway
6021 c_parser_objc_type_name (c_parser
*parser
)
6023 tree quals
= NULL_TREE
;
6024 struct c_type_name
*typename
= NULL
;
6025 tree type
= NULL_TREE
;
6028 c_token
*token
= c_parser_peek_token (parser
);
6029 if (token
->type
== CPP_KEYWORD
6030 && (token
->keyword
== RID_IN
6031 || token
->keyword
== RID_OUT
6032 || token
->keyword
== RID_INOUT
6033 || token
->keyword
== RID_BYCOPY
6034 || token
->keyword
== RID_BYREF
6035 || token
->keyword
== RID_ONEWAY
))
6037 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6038 c_parser_consume_token (parser
);
6043 if (c_parser_next_token_starts_typename (parser
))
6044 typename
= c_parser_type_name (parser
);
6046 type
= groktypename (typename
);
6047 return build_tree_list (quals
, type
);
6050 /* Parse objc-protocol-refs.
6057 c_parser_objc_protocol_refs (c_parser
*parser
)
6059 tree list
= NULL_TREE
;
6060 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6061 c_parser_consume_token (parser
);
6062 /* Any identifiers, including those declared as type names, are OK
6067 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6069 c_parser_error (parser
, "expected identifier");
6072 id
= c_parser_peek_token (parser
)->value
;
6073 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6074 c_parser_consume_token (parser
);
6075 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6076 c_parser_consume_token (parser
);
6080 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6084 /* Parse an objc-try-catch-statement.
6086 objc-try-catch-statement:
6087 @try compound-statement objc-catch-list[opt]
6088 @try compound-statement objc-catch-list[opt] @finally compound-statement
6091 @catch ( parameter-declaration ) compound-statement
6092 objc-catch-list @catch ( parameter-declaration ) compound-statement
6096 c_parser_objc_try_catch_statement (c_parser
*parser
)
6100 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
6101 c_parser_consume_token (parser
);
6102 loc
= c_parser_peek_token (parser
)->location
;
6103 stmt
= c_parser_compound_statement (parser
);
6104 objc_begin_try_stmt (loc
, stmt
);
6105 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
6107 struct c_parm
*parm
;
6108 c_parser_consume_token (parser
);
6109 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6111 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6114 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6117 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6118 objc_begin_catch_clause (grokparm (parm
));
6119 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6120 c_parser_compound_statement_nostart (parser
);
6121 objc_finish_catch_clause ();
6123 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6127 c_parser_consume_token (parser
);
6128 finloc
= c_parser_peek_token (parser
)->location
;
6129 finstmt
= c_parser_compound_statement (parser
);
6130 objc_build_finally_clause (finloc
, finstmt
);
6132 objc_finish_try_stmt ();
6135 /* Parse an objc-synchronized-statement.
6137 objc-synchronized-statement:
6138 @synchronized ( expression ) compound-statement
6142 c_parser_objc_synchronized_statement (c_parser
*parser
)
6146 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6147 c_parser_consume_token (parser
);
6148 loc
= c_parser_peek_token (parser
)->location
;
6149 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6151 expr
= c_parser_expression (parser
).value
;
6152 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6155 expr
= error_mark_node
;
6156 stmt
= c_parser_compound_statement (parser
);
6157 objc_build_synchronized (loc
, expr
, stmt
);
6160 /* Parse an objc-selector; return NULL_TREE without an error if the
6161 next token is not an objc-selector.
6166 enum struct union if else while do for switch case default
6167 break continue return goto asm sizeof typeof __alignof
6168 unsigned long const short volatile signed restrict _Complex
6169 in out inout bycopy byref oneway int char float double void _Bool
6171 ??? Why this selection of keywords but not, for example, storage
6172 class specifiers? */
6175 c_parser_objc_selector (c_parser
*parser
)
6177 c_token
*token
= c_parser_peek_token (parser
);
6178 tree value
= token
->value
;
6179 if (token
->type
== CPP_NAME
)
6181 c_parser_consume_token (parser
);
6184 if (token
->type
!= CPP_KEYWORD
)
6186 switch (token
->keyword
)
6227 c_parser_consume_token (parser
);
6234 /* Parse an objc-selector-arg.
6238 objc-keywordname-list
6240 objc-keywordname-list:
6242 objc-keywordname-list objc-keywordname
6250 c_parser_objc_selector_arg (c_parser
*parser
)
6252 tree sel
= c_parser_objc_selector (parser
);
6253 tree list
= NULL_TREE
;
6254 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6258 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6260 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6261 sel
= c_parser_objc_selector (parser
);
6262 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6268 /* Parse an objc-receiver.
6277 c_parser_objc_receiver (c_parser
*parser
)
6279 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6280 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6281 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6283 tree id
= c_parser_peek_token (parser
)->value
;
6284 c_parser_consume_token (parser
);
6285 return objc_get_class_reference (id
);
6287 return c_parser_expression (parser
).value
;
6290 /* Parse objc-message-args.
6294 objc-keywordarg-list
6296 objc-keywordarg-list:
6298 objc-keywordarg-list objc-keywordarg
6301 objc-selector : objc-keywordexpr
6306 c_parser_objc_message_args (c_parser
*parser
)
6308 tree sel
= c_parser_objc_selector (parser
);
6309 tree list
= NULL_TREE
;
6310 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6315 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6317 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6318 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6319 sel
= c_parser_objc_selector (parser
);
6320 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6326 /* Parse an objc-keywordexpr.
6333 c_parser_objc_keywordexpr (c_parser
*parser
)
6335 tree list
= c_parser_expr_list (parser
, true);
6336 if (TREE_CHAIN (list
) == NULL_TREE
)
6338 /* Just return the expression, remove a level of
6340 return TREE_VALUE (list
);
6344 /* We have a comma expression, we will collapse later. */
6350 /* Handle pragmas. ALLOW_STMT is true if we're within the context of
6351 a function and such pragmas are to be allowed. Returns true if we
6352 actually parsed such a pragma. */
6355 c_parser_pragma (c_parser
*parser
, enum pragma_context context ATTRIBUTE_UNUSED
)
6359 id
= c_parser_peek_token (parser
)->pragma_kind
;
6360 gcc_assert (id
!= PRAGMA_NONE
);
6364 case PRAGMA_GCC_PCH_PREPROCESS
:
6365 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6366 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6370 gcc_assert (id
>= PRAGMA_FIRST_EXTERNAL
);
6374 c_parser_consume_pragma (parser
);
6375 c_invoke_pragma_handler (id
);
6377 /* Skip to EOL, but suppress any error message. Those will have been
6378 generated by the handler routine through calling error, as opposed
6379 to calling c_parser_error. */
6380 parser
->error
= true;
6381 c_parser_skip_to_pragma_eol (parser
);
6386 /* The interface the pragma parsers have to the lexer. */
6389 pragma_lex (tree
*value
)
6391 c_token
*tok
= c_parser_peek_token (the_parser
);
6392 enum cpp_ttype ret
= tok
->type
;
6394 *value
= tok
->value
;
6395 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6399 if (ret
== CPP_KEYWORD
)
6401 c_parser_consume_token (the_parser
);
6408 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6412 c_parser_consume_pragma (parser
);
6413 if (c_parser_next_token_is (parser
, CPP_STRING
))
6415 name
= c_parser_peek_token (parser
)->value
;
6416 c_parser_consume_token (parser
);
6419 c_parser_error (parser
, "expected string literal");
6420 c_parser_skip_to_pragma_eol (parser
);
6423 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6426 /* Parse a single source file. */
6431 /* Use local storage to begin. If the first token is a pragma, parse it.
6432 If it is #pragma GCC pch_preprocess, then this will load a PCH file
6433 which will cause garbage collection. */
6436 memset (&tparser
, 0, sizeof tparser
);
6437 the_parser
= &tparser
;
6439 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
6440 c_parser_pragma_pch_preprocess (&tparser
);
6442 the_parser
= GGC_NEW (c_parser
);
6443 *the_parser
= tparser
;
6445 c_parser_translation_unit (the_parser
);
6449 #include "gt-c-parser.h"