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, 59 Temple Place - Suite 330, 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"
45 #include "langhooks.h"
58 /* Miscellaneous data and functions needed for the parser. */
62 /* Objective-C specific parser/lexer information. */
64 static int objc_pq_context
= 0;
66 /* The following flag is needed to contextualize Objective-C lexical
67 analysis. In some cases (e.g., 'int NSObject;'), it is undesirable
68 to bind an identifier to an Objective-C class, even if a class with
70 static int objc_need_raw_identifier
= 0;
71 #define OBJC_NEED_RAW_IDENTIFIER(VAL) \
73 if (c_dialect_objc ()) \
74 objc_need_raw_identifier = VAL; \
77 /* The reserved keyword table. */
81 ENUM_BITFIELD(rid
) rid
: 16;
82 unsigned int disable
: 16;
85 /* Disable mask. Keywords are disabled if (reswords[i].disable &
87 #define D_C89 0x01 /* not in C89 */
88 #define D_EXT 0x02 /* GCC extension */
89 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
90 #define D_OBJC 0x08 /* Objective C only */
92 static const struct resword reswords
[] =
94 { "_Bool", RID_BOOL
, 0 },
95 { "_Complex", RID_COMPLEX
, 0 },
96 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
97 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
98 { "__alignof", RID_ALIGNOF
, 0 },
99 { "__alignof__", RID_ALIGNOF
, 0 },
100 { "__asm", RID_ASM
, 0 },
101 { "__asm__", RID_ASM
, 0 },
102 { "__attribute", RID_ATTRIBUTE
, 0 },
103 { "__attribute__", RID_ATTRIBUTE
, 0 },
104 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
105 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
106 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
107 { "__builtin_va_arg", RID_VA_ARG
, 0 },
108 { "__complex", RID_COMPLEX
, 0 },
109 { "__complex__", RID_COMPLEX
, 0 },
110 { "__const", RID_CONST
, 0 },
111 { "__const__", RID_CONST
, 0 },
112 { "__extension__", RID_EXTENSION
, 0 },
113 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
114 { "__imag", RID_IMAGPART
, 0 },
115 { "__imag__", RID_IMAGPART
, 0 },
116 { "__inline", RID_INLINE
, 0 },
117 { "__inline__", RID_INLINE
, 0 },
118 { "__label__", RID_LABEL
, 0 },
119 { "__real", RID_REALPART
, 0 },
120 { "__real__", RID_REALPART
, 0 },
121 { "__restrict", RID_RESTRICT
, 0 },
122 { "__restrict__", RID_RESTRICT
, 0 },
123 { "__signed", RID_SIGNED
, 0 },
124 { "__signed__", RID_SIGNED
, 0 },
125 { "__thread", RID_THREAD
, 0 },
126 { "__typeof", RID_TYPEOF
, 0 },
127 { "__typeof__", RID_TYPEOF
, 0 },
128 { "__volatile", RID_VOLATILE
, 0 },
129 { "__volatile__", RID_VOLATILE
, 0 },
130 { "asm", RID_ASM
, D_EXT
},
131 { "auto", RID_AUTO
, 0 },
132 { "break", RID_BREAK
, 0 },
133 { "case", RID_CASE
, 0 },
134 { "char", RID_CHAR
, 0 },
135 { "const", RID_CONST
, 0 },
136 { "continue", RID_CONTINUE
, 0 },
137 { "default", RID_DEFAULT
, 0 },
139 { "double", RID_DOUBLE
, 0 },
140 { "else", RID_ELSE
, 0 },
141 { "enum", RID_ENUM
, 0 },
142 { "extern", RID_EXTERN
, 0 },
143 { "float", RID_FLOAT
, 0 },
144 { "for", RID_FOR
, 0 },
145 { "goto", RID_GOTO
, 0 },
147 { "inline", RID_INLINE
, D_EXT89
},
148 { "int", RID_INT
, 0 },
149 { "long", RID_LONG
, 0 },
150 { "register", RID_REGISTER
, 0 },
151 { "restrict", RID_RESTRICT
, D_C89
},
152 { "return", RID_RETURN
, 0 },
153 { "short", RID_SHORT
, 0 },
154 { "signed", RID_SIGNED
, 0 },
155 { "sizeof", RID_SIZEOF
, 0 },
156 { "static", RID_STATIC
, 0 },
157 { "struct", RID_STRUCT
, 0 },
158 { "switch", RID_SWITCH
, 0 },
159 { "typedef", RID_TYPEDEF
, 0 },
160 { "typeof", RID_TYPEOF
, D_EXT
},
161 { "union", RID_UNION
, 0 },
162 { "unsigned", RID_UNSIGNED
, 0 },
163 { "void", RID_VOID
, 0 },
164 { "volatile", RID_VOLATILE
, 0 },
165 { "while", RID_WHILE
, 0 },
166 /* These Objective-C keywords are recognized only immediately after
168 { "class", RID_AT_CLASS
, D_OBJC
},
169 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
170 { "defs", RID_AT_DEFS
, D_OBJC
},
171 { "encode", RID_AT_ENCODE
, D_OBJC
},
172 { "end", RID_AT_END
, D_OBJC
},
173 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
174 { "interface", RID_AT_INTERFACE
, D_OBJC
},
175 { "private", RID_AT_PRIVATE
, D_OBJC
},
176 { "protected", RID_AT_PROTECTED
, D_OBJC
},
177 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
178 { "public", RID_AT_PUBLIC
, D_OBJC
},
179 { "selector", RID_AT_SELECTOR
, D_OBJC
},
180 { "throw", RID_AT_THROW
, D_OBJC
},
181 { "try", RID_AT_TRY
, D_OBJC
},
182 { "catch", RID_AT_CATCH
, D_OBJC
},
183 { "finally", RID_AT_FINALLY
, D_OBJC
},
184 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
185 /* These are recognized only in protocol-qualifier context
187 { "bycopy", RID_BYCOPY
, D_OBJC
},
188 { "byref", RID_BYREF
, D_OBJC
},
189 { "in", RID_IN
, D_OBJC
},
190 { "inout", RID_INOUT
, D_OBJC
},
191 { "oneway", RID_ONEWAY
, D_OBJC
},
192 { "out", RID_OUT
, D_OBJC
},
194 #define N_reswords (sizeof reswords / sizeof (struct resword))
196 /* Initialization routine for this file. */
201 /* The only initialization required is of the reserved word
205 int mask
= (flag_isoc99
? 0 : D_C89
)
206 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
208 if (!c_dialect_objc ())
211 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
212 for (i
= 0; i
< N_reswords
; i
++)
214 /* If a keyword is disabled, do not enter it into the table
215 and so create a canonical spelling that isn't a keyword. */
216 if (reswords
[i
].disable
& mask
)
219 id
= get_identifier (reswords
[i
].word
);
220 C_RID_CODE (id
) = reswords
[i
].rid
;
221 C_IS_RESERVED_WORD (id
) = 1;
222 ridpointers
[(int) reswords
[i
].rid
] = id
;
226 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
227 and the C parser. Unlike the C++ lexer, the parser structure
228 stores the lexer information instead of using a separate structure.
229 Identifiers are separated into ordinary identifiers, type names,
230 keywords and some other Objective-C types of identifiers, and some
231 look-ahead is maintained.
233 ??? It might be a good idea to lex the whole file up front (as for
234 C++). It would then be possible to share more of the C and C++
235 lexer code, if desired. */
237 /* The following local token type is used. */
240 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
242 /* More information about the type of a CPP_NAME token. */
243 typedef enum c_id_kind
{
244 /* An ordinary identifier. */
246 /* An identifier declared as a typedef name. */
248 /* An identifier declared as an Objective-C class name. */
250 /* Not an identifier. */
254 /* A single C token after string literal concatenation and conversion
255 of preprocessing tokens to tokens. */
256 typedef struct c_token
GTY (())
258 /* The kind of token. */
259 ENUM_BITFIELD (cpp_ttype
) type
: 8;
260 /* If this token is a CPP_NAME, this value indicates whether also
261 declared as some kind of type. Otherwise, it is C_ID_NONE. */
262 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
263 /* If this token is a keyword, this value indicates which keyword.
264 Otherwise, this value is RID_MAX. */
265 ENUM_BITFIELD (rid
) keyword
: 8;
266 /* True if this token is from a system header. */
267 BOOL_BITFIELD in_system_header
: 1;
268 /* The value associated with this token, if any. */
270 /* The location at which this token was found. */
274 /* A parser structure recording information about the state and
275 context of parsing. Includes lexer information with up to two
276 tokens of look-ahead; more are not needed for C. */
277 typedef struct c_parser
GTY(())
279 /* The look-ahead tokens. */
281 /* How many look-ahead tokens are available (0, 1 or 2). */
283 /* True if a syntax error is being recovered from; false otherwise.
284 c_parser_error sets this flag. It should clear this flag when
285 enough tokens have been consumed to recover from the error. */
286 BOOL_BITFIELD error
: 1;
289 /* Read in and lex a single token, storing it in *TOKEN. */
292 c_lex_one_token (c_token
*token
)
294 timevar_push (TV_LEX
);
295 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
);
296 token
->in_system_header
= in_system_header
;
300 token
->id_kind
= C_ID_NONE
;
301 token
->keyword
= RID_MAX
;
305 int objc_force_identifier
= objc_need_raw_identifier
;
306 OBJC_NEED_RAW_IDENTIFIER (0);
308 if (C_IS_RESERVED_WORD (token
->value
))
310 enum rid rid_code
= C_RID_CODE (token
->value
);
312 if (c_dialect_objc ())
314 if (!OBJC_IS_AT_KEYWORD (rid_code
)
315 && (!OBJC_IS_PQ_KEYWORD (rid_code
) || objc_pq_context
))
317 /* Return the canonical spelling for this keyword. */
318 token
->value
= ridpointers
[(int) rid_code
];
319 token
->type
= CPP_KEYWORD
;
320 token
->keyword
= rid_code
;
326 /* Return the canonical spelling for this keyword. */
327 token
->value
= ridpointers
[(int) rid_code
];
328 token
->type
= CPP_KEYWORD
;
329 token
->keyword
= rid_code
;
334 decl
= lookup_name (token
->value
);
337 if (TREE_CODE (decl
) == TYPE_DECL
)
339 token
->id_kind
= C_ID_TYPENAME
;
343 else if (c_dialect_objc ())
345 tree objc_interface_decl
= objc_is_class_name (token
->value
);
346 /* Objective-C class names are in the same namespace as
347 variables and typedefs, and hence are shadowed by local
349 if (objc_interface_decl
350 && (global_bindings_p ()
351 || (!objc_force_identifier
&& !decl
)))
353 token
->value
= objc_interface_decl
;
354 token
->id_kind
= C_ID_CLASSNAME
;
359 token
->id_kind
= C_ID_ID
;
362 /* This only happens in Objective-C; it must be a keyword. */
363 token
->type
= CPP_KEYWORD
;
364 token
->id_kind
= C_ID_NONE
;
365 token
->keyword
= C_RID_CODE (token
->value
);
369 case CPP_CLOSE_PAREN
:
371 /* These tokens may affect the interpretation of any identifiers
372 following, if doing Objective-C. */
373 OBJC_NEED_RAW_IDENTIFIER (0);
374 token
->id_kind
= C_ID_NONE
;
375 token
->keyword
= RID_MAX
;
378 token
->id_kind
= C_ID_NONE
;
379 token
->keyword
= RID_MAX
;
382 timevar_pop (TV_LEX
);
385 /* Return a pointer to the next token from PARSER, reading it in if
388 static inline c_token
*
389 c_parser_peek_token (c_parser
*parser
)
391 if (parser
->tokens_avail
== 0)
393 c_lex_one_token (&parser
->tokens
[0]);
394 parser
->tokens_avail
= 1;
396 return &parser
->tokens
[0];
399 /* Return true if the next token from PARSER has the indicated
403 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
405 return c_parser_peek_token (parser
)->type
== type
;
408 /* Return true if the next token from PARSER does not have the
412 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
414 return !c_parser_next_token_is (parser
, type
);
417 /* Return true if the next token from PARSER is the indicated
421 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
425 /* Peek at the next token. */
426 token
= c_parser_peek_token (parser
);
427 /* Check to see if it is the indicated keyword. */
428 return token
->keyword
== keyword
;
431 /* Return true if TOKEN can start a type name,
434 c_token_starts_typename (c_token
*token
)
439 switch (token
->id_kind
)
446 gcc_assert (c_dialect_objc ());
452 switch (token
->keyword
)
478 if (c_dialect_objc ())
486 /* Return true if the next token from PARSER can start a type name,
489 c_parser_next_token_starts_typename (c_parser
*parser
)
491 c_token
*token
= c_parser_peek_token (parser
);
492 return c_token_starts_typename (token
);
495 /* Return true if TOKEN can start declaration specifiers, false
498 c_token_starts_declspecs (c_token
*token
)
503 switch (token
->id_kind
)
510 gcc_assert (c_dialect_objc ());
516 switch (token
->keyword
)
549 if (c_dialect_objc ())
557 /* Return true if the next token from PARSER can start declaration
558 specifiers, false otherwise. */
560 c_parser_next_token_starts_declspecs (c_parser
*parser
)
562 c_token
*token
= c_parser_peek_token (parser
);
563 return c_token_starts_declspecs (token
);
566 /* Return a pointer to the next-but-one token from PARSER, reading it
567 in if necessary. The next token is already read in. */
570 c_parser_peek_2nd_token (c_parser
*parser
)
572 if (parser
->tokens_avail
>= 2)
573 return &parser
->tokens
[1];
574 gcc_assert (parser
->tokens_avail
== 1);
575 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
576 c_lex_one_token (&parser
->tokens
[1]);
577 parser
->tokens_avail
= 2;
578 return &parser
->tokens
[1];
581 /* Consume the next token from PARSER. */
584 c_parser_consume_token (c_parser
*parser
)
586 if (parser
->tokens_avail
== 2)
587 parser
->tokens
[0] = parser
->tokens
[1];
590 gcc_assert (parser
->tokens_avail
== 1);
591 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
593 parser
->tokens_avail
--;
596 /* Update the globals input_location and in_system_header from
599 c_parser_set_source_position_from_token (c_token
*token
)
601 if (token
->type
!= CPP_EOF
)
603 input_location
= token
->location
;
604 in_system_header
= token
->in_system_header
;
608 /* Allocate a new parser. */
613 /* Use local storage to lex the first token because loading a PCH
614 file may cause garbage collection. */
617 memset (&tparser
, 0, sizeof tparser
);
618 c_lex_one_token (&tparser
.tokens
[0]);
619 tparser
.tokens_avail
= 1;
620 ret
= GGC_NEW (c_parser
);
621 memcpy (ret
, &tparser
, sizeof tparser
);
625 /* Issue a diagnostic of the form
626 FILE:LINE: MESSAGE before TOKEN
627 where TOKEN is the next token in the input stream of PARSER.
628 MESSAGE (specified by the caller) is usually of the form "expected
631 Do not issue a diagnostic if still recovering from an error.
633 ??? This is taken from the C++ parser, but building up messages in
634 this way is not i18n-friendly and some other approach should be
638 c_parser_error (c_parser
*parser
, const char *msgid
)
640 c_token
*token
= c_parser_peek_token (parser
);
643 parser
->error
= true;
646 /* This diagnostic makes more sense if it is tagged to the line of
647 the token we just peeked at. */
648 c_parser_set_source_position_from_token (token
);
649 c_parse_error (msgid
,
650 /* Because c_parse_error does not understand
651 CPP_KEYWORD, keywords are treated like
653 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
657 /* If the next token is of the indicated TYPE, consume it. Otherwise,
658 issue the error MSGID. If MSGID is NULL then a message has already
659 been produced and no message will be produced this time. Returns
660 true if found, false otherwise. */
663 c_parser_require (c_parser
*parser
,
667 if (c_parser_next_token_is (parser
, type
))
669 c_parser_consume_token (parser
);
674 c_parser_error (parser
, msgid
);
679 /* If the next token is the indicated keyword, consume it. Otherwise,
680 issue the error MSGID. Returns true if found, false otherwise. */
683 c_parser_require_keyword (c_parser
*parser
,
687 if (c_parser_next_token_is_keyword (parser
, keyword
))
689 c_parser_consume_token (parser
);
694 c_parser_error (parser
, msgid
);
699 /* Like c_parser_require, except that tokens will be skipped until the
700 desired token is found. An error message is still produced if the
701 next token is not as expected. If MSGID is NULL then a message has
702 already been produced and no message will be produced this
706 c_parser_skip_until_found (c_parser
*parser
,
710 unsigned nesting_depth
= 0;
712 if (c_parser_require (parser
, type
, msgid
))
715 /* Skip tokens until the desired token is found. */
718 /* Peek at the next token. */
719 c_token
*token
= c_parser_peek_token (parser
);
720 /* If we've reached the token we want, consume it and stop. */
721 if (token
->type
== type
&& !nesting_depth
)
723 c_parser_consume_token (parser
);
726 /* If we've run out of tokens, stop. */
727 if (token
->type
== CPP_EOF
)
729 if (token
->type
== CPP_OPEN_BRACE
730 || token
->type
== CPP_OPEN_PAREN
731 || token
->type
== CPP_OPEN_SQUARE
)
733 else if (token
->type
== CPP_CLOSE_BRACE
734 || token
->type
== CPP_CLOSE_PAREN
735 || token
->type
== CPP_CLOSE_SQUARE
)
737 if (nesting_depth
-- == 0)
740 /* Consume this token. */
741 c_parser_consume_token (parser
);
743 parser
->error
= false;
746 /* Skip tokens until the end of a parameter is found, but do not
747 consume the comma, semicolon or closing delimiter. */
750 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
752 unsigned nesting_depth
= 0;
756 c_token
*token
= c_parser_peek_token (parser
);
757 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
760 /* If we've run out of tokens, stop. */
761 if (token
->type
== CPP_EOF
)
763 if (token
->type
== CPP_OPEN_BRACE
764 || token
->type
== CPP_OPEN_PAREN
765 || token
->type
== CPP_OPEN_SQUARE
)
767 else if (token
->type
== CPP_CLOSE_BRACE
768 || token
->type
== CPP_CLOSE_PAREN
769 || token
->type
== CPP_CLOSE_SQUARE
)
771 if (nesting_depth
-- == 0)
774 /* Consume this token. */
775 c_parser_consume_token (parser
);
777 parser
->error
= false;
780 /* Skip tokens until we have consumed an entire block, or until we
781 have consumed a non-nested ';'. */
784 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
786 unsigned nesting_depth
= 0;
792 /* Peek at the next token. */
793 token
= c_parser_peek_token (parser
);
794 /* If we've run out of tokens, stop. */
795 if (token
->type
== CPP_EOF
)
797 /* If the next token is a ';', we have reached the end of the
799 if (token
->type
== CPP_SEMICOLON
&& !nesting_depth
)
801 /* Consume the ';'. */
802 c_parser_consume_token (parser
);
805 /* If the next token is a non-nested '}', then we have reached
806 the end of the current block. */
807 if (token
->type
== CPP_CLOSE_BRACE
808 && (nesting_depth
== 0 || --nesting_depth
== 0))
810 c_parser_consume_token (parser
);
813 /* If it the next token is a '{', then we are entering a new
814 block. Consume the entire block. */
815 if (token
->type
== CPP_OPEN_BRACE
)
817 c_parser_consume_token (parser
);
819 parser
->error
= false;
823 /* Save the warning flags which are controlled by __extension__. */
826 disable_extension_diagnostics (void)
829 | (warn_pointer_arith
<< 1)
830 | (warn_traditional
<< 2)
833 warn_pointer_arith
= 0;
834 warn_traditional
= 0;
839 /* Restore the warning flags which are controlled by __extension__.
840 FLAGS is the return value from disable_extension_diagnostics. */
843 restore_extension_diagnostics (int flags
)
845 pedantic
= flags
& 1;
846 warn_pointer_arith
= (flags
>> 1) & 1;
847 warn_traditional
= (flags
>> 2) & 1;
848 flag_iso
= (flags
>> 3) & 1;
851 /* Possibly kinds of declarator to parse. */
852 typedef enum c_dtr_syn
{
853 /* A normal declarator with an identifier. */
855 /* An abstract declarator (maybe empty). */
857 /* A parameter declarator: may be either, but after a type name does
858 not redeclare a typedef name as an identifier if it can
859 alternatively be interpreted as a typedef name; see DR#009,
860 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
861 following DR#249. For example, given a typedef T, "int T" and
862 "int *T" are valid parameter declarations redeclaring T, while
863 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
864 abstract declarators rather than involving redundant parentheses;
865 the same applies with attributes inside the parentheses before
870 static void c_parser_external_declaration (c_parser
*);
871 static void c_parser_asm_definition (c_parser
*);
872 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
873 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
875 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
876 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
877 static tree
c_parser_struct_declaration (c_parser
*);
878 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
879 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
881 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
883 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
885 struct c_declarator
*);
886 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
887 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
888 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
889 static tree
c_parser_simple_asm_expr (c_parser
*);
890 static tree
c_parser_attributes (c_parser
*);
891 static struct c_type_name
*c_parser_type_name (c_parser
*);
892 static struct c_expr
c_parser_initializer (c_parser
*);
893 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
894 static void c_parser_initelt (c_parser
*);
895 static void c_parser_initval (c_parser
*, struct c_expr
*);
896 static tree
c_parser_compound_statement (c_parser
*);
897 static void c_parser_compound_statement_nostart (c_parser
*);
898 static void c_parser_label (c_parser
*);
899 static void c_parser_statement (c_parser
*);
900 static void c_parser_statement_after_labels (c_parser
*);
901 static void c_parser_if_statement (c_parser
*);
902 static void c_parser_switch_statement (c_parser
*);
903 static void c_parser_while_statement (c_parser
*);
904 static void c_parser_do_statement (c_parser
*);
905 static void c_parser_for_statement (c_parser
*);
906 static tree
c_parser_asm_statement (c_parser
*);
907 static tree
c_parser_asm_operands (c_parser
*);
908 static tree
c_parser_asm_clobbers (c_parser
*);
909 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
910 static struct c_expr
c_parser_conditional_expression (c_parser
*,
912 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
913 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
914 static struct c_expr
c_parser_unary_expression (c_parser
*);
915 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
916 static struct c_expr
c_parser_alignof_expression (c_parser
*);
917 static struct c_expr
c_parser_postfix_expression (c_parser
*);
918 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
919 struct c_type_name
*);
920 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
922 static struct c_expr
c_parser_expression (c_parser
*);
923 static tree
c_parser_expr_list (c_parser
*);
925 /* These Objective-C parser functions are only ever called when
926 compiling Objective-C. */
927 static void c_parser_objc_class_definition (c_parser
*);
928 static void c_parser_objc_class_instance_variables (c_parser
*);
929 static void c_parser_objc_class_declaration (c_parser
*);
930 static void c_parser_objc_alias_declaration (c_parser
*);
931 static void c_parser_objc_protocol_definition (c_parser
*);
932 static enum tree_code
c_parser_objc_method_type (c_parser
*);
933 static void c_parser_objc_method_definition (c_parser
*);
934 static void c_parser_objc_methodprotolist (c_parser
*);
935 static void c_parser_objc_methodproto (c_parser
*);
936 static tree
c_parser_objc_method_decl (c_parser
*);
937 static tree
c_parser_objc_type_name (c_parser
*);
938 static tree
c_parser_objc_protocol_refs (c_parser
*);
939 static void c_parser_objc_try_catch_statement (c_parser
*);
940 static void c_parser_objc_synchronized_statement (c_parser
*);
941 static tree
c_parser_objc_selector (c_parser
*);
942 static tree
c_parser_objc_selector_arg (c_parser
*);
943 static tree
c_parser_objc_receiver (c_parser
*);
944 static tree
c_parser_objc_message_args (c_parser
*);
945 static tree
c_parser_objc_keywordexpr (c_parser
*);
947 /* Parse a translation unit (C90 6.7, C99 6.9).
950 external-declarations
952 external-declarations:
954 external-declarations external-declaration
963 c_parser_translation_unit (c_parser
*parser
)
965 if (c_parser_next_token_is (parser
, CPP_EOF
))
968 pedwarn ("ISO C forbids an empty source file");
972 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
976 c_parser_external_declaration (parser
);
977 obstack_free (&parser_obstack
, obstack_position
);
979 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
983 /* Parse an external declaration (C90 6.7, C99 6.9).
985 external-declaration:
991 external-declaration:
994 __extension__ external-declaration
998 external-declaration:
999 objc-class-definition
1000 objc-class-declaration
1001 objc-alias-declaration
1002 objc-protocol-definition
1003 objc-method-definition
1008 c_parser_external_declaration (c_parser
*parser
)
1011 switch (c_parser_peek_token (parser
)->type
)
1014 switch (c_parser_peek_token (parser
)->keyword
)
1017 ext
= disable_extension_diagnostics ();
1018 c_parser_consume_token (parser
);
1019 c_parser_external_declaration (parser
);
1020 restore_extension_diagnostics (ext
);
1023 c_parser_asm_definition (parser
);
1025 case RID_AT_INTERFACE
:
1026 case RID_AT_IMPLEMENTATION
:
1027 gcc_assert (c_dialect_objc ());
1028 c_parser_objc_class_definition (parser
);
1031 gcc_assert (c_dialect_objc ());
1032 c_parser_objc_class_declaration (parser
);
1035 gcc_assert (c_dialect_objc ());
1036 c_parser_objc_alias_declaration (parser
);
1038 case RID_AT_PROTOCOL
:
1039 gcc_assert (c_dialect_objc ());
1040 c_parser_objc_protocol_definition (parser
);
1043 gcc_assert (c_dialect_objc ());
1044 c_parser_consume_token (parser
);
1045 objc_finish_implementation ();
1053 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1054 c_parser_consume_token (parser
);
1058 if (c_dialect_objc ())
1060 c_parser_objc_method_definition (parser
);
1063 /* Else fall through, and yield a syntax error trying to parse
1064 as a declaration or function definition. */
1067 /* A declaration or a function definition. We can only tell
1068 which after parsing the declaration specifiers, if any, and
1069 the first declarator. */
1070 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1075 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1076 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1077 accepted; otherwise (old-style parameter declarations) only other
1078 declarations are accepted. If NESTED is true, we are inside a
1079 function or parsing old-style parameter declarations; any functions
1080 encountered are nested functions and declaration specifiers are
1081 required; otherwise we are at top level and functions are normal
1082 functions and declaration specifiers may be optional. If EMPTY_OK
1083 is true, empty declarations are OK (subject to all other
1084 constraints); otherwise (old-style parameter declarations) they are
1085 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1086 may start with attributes; otherwise they may not.
1089 declaration-specifiers init-declarator-list[opt] ;
1091 function-definition:
1092 declaration-specifiers[opt] declarator declaration-list[opt]
1097 declaration-list declaration
1099 init-declarator-list:
1101 init-declarator-list , init-declarator
1104 declarator simple-asm-expr[opt] attributes[opt]
1105 declarator simple-asm-expr[opt] attributes[opt] = initializer
1109 nested-function-definition:
1110 declaration-specifiers declarator declaration-list[opt]
1113 The simple-asm-expr and attributes are GNU extensions.
1115 This function does not handle __extension__; that is handled in its
1116 callers. ??? Following the old parser, __extension__ may start
1117 external declarations, declarations in functions and declarations
1118 at the start of "for" loops, but not old-style parameter
1121 C99 requires declaration specifiers in a function definition; the
1122 absence is diagnosed through the diagnosis of implicit int. In GNU
1123 C we also allow but diagnose declarations without declaration
1124 specifiers, but only at top level (elsewhere they conflict with
1128 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1129 bool nested
, bool start_attr_ok
)
1131 struct c_declspecs
*specs
;
1133 tree all_prefix_attrs
;
1134 bool diagnosed_no_specs
= false;
1135 specs
= build_null_declspecs ();
1136 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1139 c_parser_skip_to_end_of_block_or_statement (parser
);
1142 if (nested
&& !specs
->declspecs_seen_p
)
1144 c_parser_error (parser
, "expected declaration specifiers");
1145 c_parser_skip_to_end_of_block_or_statement (parser
);
1148 finish_declspecs (specs
);
1149 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1155 shadow_tag_warned (specs
, 1);
1156 pedwarn ("empty declaration");
1158 c_parser_consume_token (parser
);
1161 pending_xref_error ();
1162 prefix_attrs
= specs
->attrs
;
1163 all_prefix_attrs
= prefix_attrs
;
1164 specs
->attrs
= NULL_TREE
;
1167 struct c_declarator
*declarator
;
1170 /* Declaring either one or more declarators (in which case we
1171 should diagnose if there were no declaration specifiers) or a
1172 function definition (in which case the diagnostic for
1173 implicit int suffices). */
1174 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1175 C_DTR_NORMAL
, &dummy
);
1176 if (declarator
== NULL
)
1178 c_parser_skip_to_end_of_block_or_statement (parser
);
1181 if (c_parser_next_token_is (parser
, CPP_EQ
)
1182 || c_parser_next_token_is (parser
, CPP_COMMA
)
1183 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1184 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1185 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1187 tree asm_name
= NULL_TREE
;
1188 tree postfix_attrs
= NULL_TREE
;
1189 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1191 diagnosed_no_specs
= true;
1192 pedwarn ("data definition has no type or storage class");
1194 /* Having seen a data definition, there cannot now be a
1195 function definition. */
1197 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1198 asm_name
= c_parser_simple_asm_expr (parser
);
1199 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1200 postfix_attrs
= c_parser_attributes (parser
);
1201 if (c_parser_next_token_is (parser
, CPP_EQ
))
1205 c_parser_consume_token (parser
);
1206 /* The declaration of the variable is in effect while
1207 its initializer is parsed. */
1208 d
= start_decl (declarator
, specs
, true,
1209 chainon (postfix_attrs
, all_prefix_attrs
));
1211 d
= error_mark_node
;
1212 start_init (d
, asm_name
, global_bindings_p ());
1213 init
= c_parser_initializer (parser
);
1215 if (d
!= error_mark_node
)
1217 maybe_warn_string_init (TREE_TYPE (d
), init
);
1218 finish_decl (d
, init
.value
, asm_name
);
1223 tree d
= start_decl (declarator
, specs
, false,
1224 chainon (postfix_attrs
,
1227 finish_decl (d
, NULL_TREE
, asm_name
);
1229 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1231 c_parser_consume_token (parser
);
1232 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1233 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1236 all_prefix_attrs
= prefix_attrs
;
1239 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1241 c_parser_consume_token (parser
);
1246 c_parser_error (parser
, "expected %<,%> or %<;%>");
1247 c_parser_skip_to_end_of_block_or_statement (parser
);
1253 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1254 "%<asm%> or %<__attribute__%>");
1255 c_parser_skip_to_end_of_block_or_statement (parser
);
1258 /* Function definition (nested or otherwise). */
1262 pedwarn ("ISO C forbids nested functions");
1263 push_function_context ();
1265 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1267 /* This can appear in many cases looking nothing like a
1268 function definition, so we don't give a more specific
1269 error suggesting there was one. */
1270 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1271 "or %<__attribute__%>");
1273 pop_function_context ();
1276 /* Parse old-style parameter declarations. ??? Attributes are
1277 not allowed to start declaration specifiers here because of a
1278 syntax conflict between a function declaration with attribute
1279 suffix and a function definition with an attribute prefix on
1280 first old-style parameter declaration. Following the old
1281 parser, they are not accepted on subsequent old-style
1282 parameter declarations either. However, there is no
1283 ambiguity after the first declaration, nor indeed on the
1284 first as long as we don't allow postfix attributes after a
1285 declarator with a nonempty identifier list in a definition;
1286 and postfix attributes have never been accepted here in
1287 function definitions either. */
1288 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1289 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1290 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1291 DECL_SOURCE_LOCATION (current_function_decl
)
1292 = c_parser_peek_token (parser
)->location
;
1293 store_parm_decls ();
1294 fnbody
= c_parser_compound_statement (parser
);
1297 tree decl
= current_function_decl
;
1300 pop_function_context ();
1301 add_stmt (build_stmt (DECL_EXPR
, decl
));
1312 /* Parse an asm-definition (asm() outside a function body). This is a
1320 c_parser_asm_definition (c_parser
*parser
)
1322 tree asm_str
= c_parser_simple_asm_expr (parser
);
1323 /* ??? This only works sensibly in the presence of
1324 -fno-unit-at-a-time; file-scope asms really need to be passed to
1325 cgraph which needs to preserve the order of functions and
1328 assemble_asm (asm_str
);
1329 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1332 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1333 6.7), adding them to SPECS (which may already include some).
1334 Storage class specifiers are accepted iff SCSPEC_OK; type
1335 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1336 the start iff START_ATTR_OK.
1338 declaration-specifiers:
1339 storage-class-specifier declaration-specifiers[opt]
1340 type-specifier declaration-specifiers[opt]
1341 type-qualifier declaration-specifiers[opt]
1342 function-specifier declaration-specifiers[opt]
1344 Function specifiers (inline) are from C99, and are currently
1345 handled as storage class specifiers, as is __thread.
1347 C90 6.5.1, C99 6.7.1:
1348 storage-class-specifier:
1359 C90 6.5.2, C99 6.7.2:
1372 [_Imaginary removed in C99 TC2]
1373 struct-or-union-specifier
1377 (_Bool and _Complex are new in C99.)
1379 C90 6.5.3, C99 6.7.3:
1386 (restrict is new in C99.)
1390 declaration-specifiers:
1391 attributes declaration-specifiers[opt]
1393 storage-class-specifier:
1402 class-name objc-protocol-refs[opt]
1403 typedef-name objc-protocol-refs
1408 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1409 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1411 bool attrs_ok
= start_attr_ok
;
1412 bool seen_type
= specs
->type_seen_p
;
1413 while (c_parser_next_token_is (parser
, CPP_NAME
)
1414 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1415 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1417 struct c_typespec t
;
1419 if (c_parser_next_token_is (parser
, CPP_NAME
))
1421 tree value
= c_parser_peek_token (parser
)->value
;
1422 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1423 /* This finishes the specifiers unless a type name is OK, it
1424 is declared as a type name and a type name hasn't yet
1426 if (!typespec_ok
|| seen_type
1427 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1429 c_parser_consume_token (parser
);
1432 if (kind
== C_ID_TYPENAME
1433 && (!c_dialect_objc ()
1434 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1436 t
.kind
= ctsk_typedef
;
1437 /* For a typedef name, record the meaning, not the name.
1438 In case of 'foo foo, bar;'. */
1439 t
.spec
= lookup_name (value
);
1443 tree proto
= NULL_TREE
;
1444 gcc_assert (c_dialect_objc ());
1446 if (c_parser_next_token_is (parser
, CPP_LESS
))
1447 proto
= c_parser_objc_protocol_refs (parser
);
1448 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1450 declspecs_add_type (specs
, t
);
1453 if (c_parser_next_token_is (parser
, CPP_LESS
))
1455 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1456 nisse@lysator.liu.se. */
1458 gcc_assert (c_dialect_objc ());
1459 if (!typespec_ok
|| seen_type
)
1461 proto
= c_parser_objc_protocol_refs (parser
);
1463 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1464 declspecs_add_type (specs
, t
);
1467 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1468 switch (c_parser_peek_token (parser
)->keyword
)
1480 /* TODO: Distinguish between function specifiers (inline)
1481 and storage class specifiers, either here or in
1482 declspecs_add_scspec. */
1483 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1484 c_parser_consume_token (parser
);
1501 OBJC_NEED_RAW_IDENTIFIER (1);
1502 t
.kind
= ctsk_resword
;
1503 t
.spec
= c_parser_peek_token (parser
)->value
;
1504 declspecs_add_type (specs
, t
);
1505 c_parser_consume_token (parser
);
1512 t
= c_parser_enum_specifier (parser
);
1513 declspecs_add_type (specs
, t
);
1521 t
= c_parser_struct_or_union_specifier (parser
);
1522 declspecs_add_type (specs
, t
);
1525 /* ??? The old parser rejected typeof after other type
1526 specifiers, but is a syntax error the best way of
1528 if (!typespec_ok
|| seen_type
)
1532 t
= c_parser_typeof_specifier (parser
);
1533 declspecs_add_type (specs
, t
);
1539 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1540 c_parser_consume_token (parser
);
1545 attrs
= c_parser_attributes (parser
);
1546 declspecs_add_attrs (specs
, attrs
);
1555 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1558 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1559 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1560 enum attributes[opt] identifier
1562 The form with trailing comma is new in C99. The forms with
1563 attributes are GNU extensions. In GNU C, we accept any expression
1564 without commas in the syntax (assignment expressions, not just
1565 conditional expressions); assignment expressions will be diagnosed
1570 enumerator-list , enumerator
1573 enumeration-constant
1574 enumeration-constant = constant-expression
1577 static struct c_typespec
1578 c_parser_enum_specifier (c_parser
*parser
)
1580 struct c_typespec ret
;
1582 tree ident
= NULL_TREE
;
1583 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1584 c_parser_consume_token (parser
);
1585 attrs
= c_parser_attributes (parser
);
1586 if (c_parser_next_token_is (parser
, CPP_NAME
))
1588 ident
= c_parser_peek_token (parser
)->value
;
1589 c_parser_consume_token (parser
);
1591 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1593 /* Parse an enum definition. */
1594 tree type
= start_enum (ident
);
1596 /* We chain the enumerators in reverse order, then put them in
1597 forward order at the end. */
1598 tree values
= NULL_TREE
;
1599 c_parser_consume_token (parser
);
1606 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1608 c_parser_error (parser
, "expected identifier");
1609 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1610 values
= error_mark_node
;
1613 enum_id
= c_parser_peek_token (parser
)->value
;
1614 c_parser_consume_token (parser
);
1615 if (c_parser_next_token_is (parser
, CPP_EQ
))
1617 c_parser_consume_token (parser
);
1618 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1621 enum_value
= NULL_TREE
;
1622 enum_decl
= build_enumerator (enum_id
, enum_value
);
1623 TREE_CHAIN (enum_decl
) = values
;
1626 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1629 c_parser_consume_token (parser
);
1631 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1633 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1634 pedwarn ("comma at end of enumerator list");
1635 c_parser_consume_token (parser
);
1640 c_parser_error (parser
, "expected %<,%> or %<}%>");
1641 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1642 values
= error_mark_node
;
1646 postfix_attrs
= c_parser_attributes (parser
);
1647 ret
.spec
= finish_enum (type
, nreverse (values
),
1648 chainon (attrs
, postfix_attrs
));
1649 ret
.kind
= ctsk_tagdef
;
1654 c_parser_error (parser
, "expected %<{%>");
1655 ret
.spec
= error_mark_node
;
1656 ret
.kind
= ctsk_tagref
;
1659 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1660 /* In ISO C, enumerated types can be referred to only if already
1662 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1663 pedwarn ("ISO C forbids forward references to %<enum%> types");
1667 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1669 struct-or-union-specifier:
1670 struct-or-union attributes[opt] identifier[opt]
1671 { struct-contents } attributes[opt]
1672 struct-or-union attributes[opt] identifier
1675 struct-declaration-list
1677 struct-declaration-list:
1678 struct-declaration ;
1679 struct-declaration-list struct-declaration ;
1686 struct-declaration-list struct-declaration
1688 struct-declaration-list:
1689 struct-declaration-list ;
1692 (Note that in the syntax here, unlike that in ISO C, the semicolons
1693 are included here rather than in struct-declaration, in order to
1694 describe the syntax with extra semicolons and missing semicolon at
1699 struct-declaration-list:
1700 @defs ( class-name )
1702 (Note this does not include a trailing semicolon, but can be
1703 followed by further declarations, and gets a pedwarn-if-pedantic
1704 when followed by a semicolon.) */
1706 static struct c_typespec
1707 c_parser_struct_or_union_specifier (c_parser
*parser
)
1709 struct c_typespec ret
;
1711 tree ident
= NULL_TREE
;
1712 enum tree_code code
;
1713 switch (c_parser_peek_token (parser
)->keyword
)
1724 c_parser_consume_token (parser
);
1725 attrs
= c_parser_attributes (parser
);
1726 if (c_parser_next_token_is (parser
, CPP_NAME
))
1728 ident
= c_parser_peek_token (parser
)->value
;
1729 c_parser_consume_token (parser
);
1731 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1733 /* Parse a struct or union definition. Start the scope of the
1734 tag before parsing components. */
1735 tree type
= start_struct (code
, ident
);
1737 /* We chain the components in reverse order, then put them in
1738 forward order at the end. Each struct-declaration may
1739 declare multiple components (comma-separated), so we must use
1740 chainon to join them, although when parsing each
1741 struct-declaration we can use TREE_CHAIN directly.
1743 The theory behind all this is that there will be more
1744 semicolon separated fields than comma separated fields, and
1745 so we'll be minimizing the number of node traversals required
1747 tree contents
= NULL_TREE
;
1748 c_parser_consume_token (parser
);
1749 /* Handle the Objective-C @defs construct,
1750 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1751 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1754 gcc_assert (c_dialect_objc ());
1755 c_parser_consume_token (parser
);
1756 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1758 if (c_parser_next_token_is (parser
, CPP_NAME
)
1759 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1761 name
= c_parser_peek_token (parser
)->value
;
1762 c_parser_consume_token (parser
);
1766 c_parser_error (parser
, "expected class name");
1767 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1770 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1772 contents
= nreverse (objc_get_class_ivars (name
));
1775 /* Parse the struct-declarations and semicolons. Problems with
1776 semicolons are diagnosed here; empty structures are diagnosed
1781 /* Parse any stray semicolon. */
1782 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1785 pedwarn ("extra semicolon in struct or union specified");
1786 c_parser_consume_token (parser
);
1789 /* Stop if at the end of the struct or union contents. */
1790 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1792 c_parser_consume_token (parser
);
1795 /* Parse some comma-separated declarations, but not the
1796 trailing semicolon if any. */
1797 decls
= c_parser_struct_declaration (parser
);
1798 contents
= chainon (decls
, contents
);
1799 /* If no semicolon follows, either we have a parse error or
1800 are at the end of the struct or union and should
1802 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1803 c_parser_consume_token (parser
);
1806 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1807 pedwarn ("no semicolon at end of struct or union");
1810 c_parser_error (parser
, "expected %<;%>");
1811 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1816 postfix_attrs
= c_parser_attributes (parser
);
1817 ret
.spec
= finish_struct (type
, nreverse (contents
),
1818 chainon (attrs
, postfix_attrs
));
1819 ret
.kind
= ctsk_tagdef
;
1824 c_parser_error (parser
, "expected %<{%>");
1825 ret
.spec
= error_mark_node
;
1826 ret
.kind
= ctsk_tagref
;
1829 ret
= parser_xref_tag (code
, ident
);
1833 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1834 the trailing semicolon.
1837 specifier-qualifier-list struct-declarator-list
1839 specifier-qualifier-list:
1840 type-specifier specifier-qualifier-list[opt]
1841 type-qualifier specifier-qualifier-list[opt]
1842 attributes specifier-qualifier-list[opt]
1844 struct-declarator-list:
1846 struct-declarator-list , attributes[opt] struct-declarator
1849 declarator attributes[opt]
1850 declarator[opt] : constant-expression attributes[opt]
1855 __extension__ struct-declaration
1856 specifier-qualifier-list
1858 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1859 of attributes where shown is a GNU extension. In GNU C, we accept
1860 any expression without commas in the syntax (assignment
1861 expressions, not just conditional expressions); assignment
1862 expressions will be diagnosed as non-constant. */
1865 c_parser_struct_declaration (c_parser
*parser
)
1867 struct c_declspecs
*specs
;
1869 tree all_prefix_attrs
;
1871 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1875 ext
= disable_extension_diagnostics ();
1876 c_parser_consume_token (parser
);
1877 decl
= c_parser_struct_declaration (parser
);
1878 restore_extension_diagnostics (ext
);
1881 specs
= build_null_declspecs ();
1882 c_parser_declspecs (parser
, specs
, false, true, true);
1885 if (!specs
->declspecs_seen_p
)
1887 c_parser_error (parser
, "expected specifier-qualifier-list");
1890 finish_declspecs (specs
);
1891 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1894 if (!specs
->type_seen_p
)
1897 pedwarn ("ISO C forbids member declarations with no members");
1898 shadow_tag_warned (specs
, pedantic
);
1903 /* Support for unnamed structs or unions as members of
1904 structs or unions (which is [a] useful and [b] supports
1906 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
, NULL_TREE
);
1910 pending_xref_error ();
1911 prefix_attrs
= specs
->attrs
;
1912 all_prefix_attrs
= prefix_attrs
;
1913 specs
->attrs
= NULL_TREE
;
1917 /* Declaring one or more declarators or un-named bit-fields. */
1918 struct c_declarator
*declarator
;
1920 if (c_parser_next_token_is (parser
, CPP_COLON
))
1921 declarator
= build_id_declarator (NULL_TREE
);
1923 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1924 C_DTR_NORMAL
, &dummy
);
1925 if (declarator
== NULL
)
1927 c_parser_skip_to_end_of_block_or_statement (parser
);
1930 if (c_parser_next_token_is (parser
, CPP_COLON
)
1931 || c_parser_next_token_is (parser
, CPP_COMMA
)
1932 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1933 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
1934 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1936 tree postfix_attrs
= NULL_TREE
;
1937 tree width
= NULL_TREE
;
1939 if (c_parser_next_token_is (parser
, CPP_COLON
))
1941 c_parser_consume_token (parser
);
1942 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
1944 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1945 postfix_attrs
= c_parser_attributes (parser
);
1946 d
= grokfield (declarator
, specs
, width
);
1947 decl_attributes (&d
, chainon (postfix_attrs
,
1948 all_prefix_attrs
), 0);
1949 TREE_CHAIN (d
) = decls
;
1951 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1952 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1955 all_prefix_attrs
= prefix_attrs
;
1956 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1957 c_parser_consume_token (parser
);
1958 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1959 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1961 /* Semicolon consumed in caller. */
1966 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
1972 c_parser_error (parser
,
1973 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
1974 "%<__attribute__%>");
1981 /* Parse a typeof specifier (a GNU extension).
1984 typeof ( expression )
1985 typeof ( type-name )
1988 static struct c_typespec
1989 c_parser_typeof_specifier (c_parser
*parser
)
1991 struct c_typespec ret
;
1992 ret
.kind
= ctsk_typeof
;
1993 ret
.spec
= error_mark_node
;
1994 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
1995 c_parser_consume_token (parser
);
1998 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2004 if (c_parser_next_token_starts_typename (parser
))
2006 struct c_type_name
*type
= c_parser_type_name (parser
);
2011 ret
.spec
= groktypename (type
);
2012 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2017 struct c_expr expr
= c_parser_expression (parser
);
2020 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2021 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2022 error ("%<typeof%> applied to a bit-field");
2023 ret
.spec
= TREE_TYPE (expr
.value
);
2024 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2026 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2030 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2031 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2032 be redeclared; otherwise it may not. KIND indicates which kind of
2033 declarator is wanted. Returns a valid declarator except in the
2034 case of a syntax error in which case NULL is returned. *SEEN_ID is
2035 set to true if an identifier being declared is seen; this is used
2036 to diagnose bad forms of abstract array declarators and to
2037 determine whether an identifier list is syntactically permitted.
2040 pointer[opt] direct-declarator
2044 ( attributes[opt] declarator )
2045 direct-declarator array-declarator
2046 direct-declarator ( parameter-type-list )
2047 direct-declarator ( identifier-list[opt] )
2050 * type-qualifier-list[opt]
2051 * type-qualifier-list[opt] pointer
2053 type-qualifier-list:
2056 type-qualifier-list type-qualifier
2057 type-qualifier-list attributes
2059 parameter-type-list:
2061 parameter-list , ...
2064 parameter-declaration
2065 parameter-list , parameter-declaration
2067 parameter-declaration:
2068 declaration-specifiers declarator attributes[opt]
2069 declaration-specifiers abstract-declarator[opt] attributes[opt]
2073 identifier-list , identifier
2075 abstract-declarator:
2077 pointer[opt] direct-abstract-declarator
2079 direct-abstract-declarator:
2080 ( attributes[opt] abstract-declarator )
2081 direct-abstract-declarator[opt] array-declarator
2082 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2087 direct-declarator ( parameter-forward-declarations
2088 parameter-type-list[opt] )
2090 direct-abstract-declarator:
2091 direct-abstract-declarator[opt] ( parameter-forward-declarations
2092 parameter-type-list[opt] )
2094 parameter-forward-declarations:
2096 parameter-forward-declarations parameter-list ;
2098 The uses of attributes shown above are GNU extensions.
2100 Some forms of array declarator are not included in C99 in the
2101 syntax for abstract declarators; these are disallowed elsewhere.
2102 This may be a defect (DR#289).
2104 This function also accepts an omitted abstract declarator as being
2105 an abstract declarator, although not part of the formal syntax. */
2107 static struct c_declarator
*
2108 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2111 /* Parse any initial pointer part. */
2112 if (c_parser_next_token_is (parser
, CPP_MULT
))
2114 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2115 struct c_declarator
*inner
;
2116 c_parser_consume_token (parser
);
2117 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2118 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2122 return make_pointer_declarator (quals_attrs
, inner
);
2124 /* Now we have a direct declarator, direct abstract declarator or
2125 nothing (which counts as a direct abstract declarator here). */
2126 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2129 /* Parse a direct declarator or direct abstract declarator; arguments
2130 as c_parser_declarator. */
2132 static struct c_declarator
*
2133 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2136 /* The direct declarator must start with an identifier (possibly
2137 omitted) or a parenthesized declarator (possibly abstract). In
2138 an ordinary declarator, initial parentheses must start a
2139 parenthesized declarator. In an abstract declarator or parameter
2140 declarator, they could start a parenthesized declarator or a
2141 parameter list. To tell which, the open parenthesis and any
2142 following attributes must be read. If a declaration specifier
2143 follows, then it is a parameter list; if the specifier is a
2144 typedef name, there might be an ambiguity about redeclaring it,
2145 which is resolved in the direction of treating it as a typedef
2146 name. If a close parenthesis follows, it is also an empty
2147 parameter list, as the syntax does not permit empty abstract
2148 declarators. Otherwise, it is a parenthesised declarator (in
2149 which case the analysis may be repeated inside it, recursively).
2151 ??? There is an ambiguity in a parameter declaration "int
2152 (__attribute__((foo)) x)", where x is not a typedef name: it
2153 could be an abstract declarator for a function, or declare x with
2154 parentheses. The proper resolution of this ambiguity needs
2155 documenting. At present we follow an accident of the old
2156 parser's implementation, whereby the first parameter must have
2157 some declaration specifiers other than just attributes. Thus as
2158 a parameter declaration it is treated as a parenthesised
2159 parameter named x, and as an abstract declarator it is
2162 ??? Also following the old parser, attributes inside an empty
2163 parameter list are ignored, making it a list not yielding a
2164 prototype, rather than giving an error or making it have one
2165 parameter with implicit type int.
2167 ??? Also following the old parser, typedef names may be
2168 redeclared in declarators, but not Objective-C class names. */
2170 if (kind
!= C_DTR_ABSTRACT
2171 && c_parser_next_token_is (parser
, CPP_NAME
)
2173 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2174 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2176 struct c_declarator
*inner
2177 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2179 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2180 c_parser_consume_token (parser
);
2181 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2184 if (kind
!= C_DTR_NORMAL
2185 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2187 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2188 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2191 /* Either we are at the end of an abstract declarator, or we have
2194 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2197 struct c_declarator
*inner
;
2198 c_parser_consume_token (parser
);
2199 attrs
= c_parser_attributes (parser
);
2200 if (kind
!= C_DTR_NORMAL
2201 && (c_parser_next_token_starts_declspecs (parser
)
2202 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2204 struct c_arg_info
*args
2205 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2212 = build_function_declarator (args
,
2213 build_id_declarator (NULL_TREE
));
2214 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2218 /* A parenthesized declarator. */
2219 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2220 if (inner
!= NULL
&& attrs
!= NULL
)
2221 inner
= build_attrs_declarator (attrs
, inner
);
2222 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2224 c_parser_consume_token (parser
);
2228 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2232 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2239 if (kind
== C_DTR_NORMAL
)
2241 c_parser_error (parser
, "expected identifier or %<(%>");
2245 return build_id_declarator (NULL_TREE
);
2249 /* Parse part of a direct declarator or direct abstract declarator,
2250 given that some (in INNER) has already been parsed; ID_PRESENT is
2251 true if an identifier is present, false for an abstract
2254 static struct c_declarator
*
2255 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2256 struct c_declarator
*inner
)
2258 /* Parse a sequence of array declarators and parameter lists. */
2259 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2261 struct c_declarator
*declarator
;
2262 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2266 c_parser_consume_token (parser
);
2267 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2268 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2270 c_parser_consume_token (parser
);
2271 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2272 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2273 if (!quals_attrs
->declspecs_seen_p
)
2275 /* If "static" is present, there must be an array dimension.
2276 Otherwise, there may be a dimension, "*", or no
2281 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2285 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2290 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2292 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2296 c_parser_consume_token (parser
);
2301 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2307 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2310 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2311 c_parser_consume_token (parser
);
2314 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2318 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2320 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2321 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2323 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2326 struct c_arg_info
*args
;
2327 c_parser_consume_token (parser
);
2328 attrs
= c_parser_attributes (parser
);
2329 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2334 inner
= build_function_declarator (args
, inner
);
2335 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2341 /* Parse a parameter list or identifier list, including the closing
2342 parenthesis but not the opening one. ATTRS are the attributes at
2343 the start of the list. ID_LIST_OK is true if an identifier list is
2344 acceptable; such a list must not have attributes at the start. */
2346 static struct c_arg_info
*
2347 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2350 declare_parm_level ();
2351 /* If the list starts with an identifier, it is an identifier list.
2352 Otherwise, it is either a prototype list or an empty list. */
2355 && c_parser_next_token_is (parser
, CPP_NAME
)
2356 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2358 tree list
= NULL_TREE
;
2359 while (c_parser_next_token_is (parser
, CPP_NAME
)
2360 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2362 list
= chainon (list
, build_tree_list (NULL_TREE
,
2363 c_parser_peek_token (parser
)->value
));
2364 c_parser_consume_token (parser
);
2365 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2367 c_parser_consume_token (parser
);
2368 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2370 c_parser_error (parser
, "expected identifier");
2374 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2376 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2381 c_parser_consume_token (parser
);
2387 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2395 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2401 /* Parse a parameter list (possibly empty), including the closing
2402 parenthesis but not the opening one. ATTRS are the attributes at
2403 the start of the list. */
2405 static struct c_arg_info
*
2406 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2408 bool good_parm
= false;
2409 /* ??? Following the old parser, forward parameter declarations may
2410 use abstract declarators, and if no real parameter declarations
2411 follow the forward declarations then this is not diagnosed. Also
2412 note as above that attributes are ignored as the only contents of
2413 the parentheses, or as the only contents after forward
2415 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2417 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2422 c_parser_consume_token (parser
);
2425 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2427 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2431 /* Suppress -Wold-style-definition for this case. */
2432 ret
->types
= error_mark_node
;
2433 error ("ISO C requires a named argument before %<...%>");
2434 c_parser_consume_token (parser
);
2435 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2437 c_parser_consume_token (parser
);
2442 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2447 /* Nonempty list of parameters, either terminated with semicolon
2448 (forward declarations; recurse) or with close parenthesis (normal
2449 function) or with ", ... )" (variadic function). */
2452 /* Parse a parameter. */
2453 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2458 push_parm_decl (parm
);
2460 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2463 c_parser_consume_token (parser
);
2464 new_attrs
= c_parser_attributes (parser
);
2465 return c_parser_parms_list_declarator (parser
, new_attrs
);
2467 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2469 c_parser_consume_token (parser
);
2471 return get_parm_info (false);
2474 struct c_arg_info
*ret
2475 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2483 if (!c_parser_require (parser
, CPP_COMMA
,
2484 "expected %<;%>, %<,%> or %<)%>"))
2486 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2489 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2491 c_parser_consume_token (parser
);
2492 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2494 c_parser_consume_token (parser
);
2496 return get_parm_info (true);
2499 struct c_arg_info
*ret
2500 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2510 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2518 /* Parse a parameter declaration. ATTRS are the attributes at the
2519 start of the declaration if it is the first parameter. */
2521 static struct c_parm
*
2522 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2524 struct c_declspecs
*specs
;
2525 struct c_declarator
*declarator
;
2527 tree postfix_attrs
= NULL_TREE
;
2529 if (!c_parser_next_token_starts_declspecs (parser
))
2531 /* ??? In some Objective-C cases '...' isn't applicable so there
2532 should be a different message. */
2533 c_parser_error (parser
,
2534 "expected declaration specifiers or %<...%>");
2535 c_parser_skip_to_end_of_parameter (parser
);
2538 specs
= build_null_declspecs ();
2541 declspecs_add_attrs (specs
, attrs
);
2544 c_parser_declspecs (parser
, specs
, true, true, true);
2545 finish_declspecs (specs
);
2546 pending_xref_error ();
2547 prefix_attrs
= specs
->attrs
;
2548 specs
->attrs
= NULL_TREE
;
2549 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2550 C_DTR_PARM
, &dummy
);
2551 if (declarator
== NULL
)
2553 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2556 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2557 postfix_attrs
= c_parser_attributes (parser
);
2558 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2562 /* Parse a string literal in an asm expression. It should not be
2563 translated, and wide string literals are an error although
2564 permitted by the syntax. This is a GNU extension.
2569 ??? At present, following the old parser, the caller needs to have
2570 set c_lex_string_translate to 0. It would be better to follow the
2571 C++ parser rather than using the c_lex_string_translate kludge. */
2574 c_parser_asm_string_literal (c_parser
*parser
)
2577 if (c_parser_next_token_is (parser
, CPP_STRING
))
2579 str
= c_parser_peek_token (parser
)->value
;
2580 c_parser_consume_token (parser
);
2582 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2584 error ("wide string literal in %<asm%>");
2585 str
= build_string (1, "");
2586 c_parser_consume_token (parser
);
2590 c_parser_error (parser
, "expected string literal");
2596 /* Parse a simple asm expression. This is used in restricted
2597 contexts, where a full expression with inputs and outputs does not
2598 make sense. This is a GNU extension.
2601 asm ( asm-string-literal )
2605 c_parser_simple_asm_expr (c_parser
*parser
)
2608 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2609 /* ??? Follow the C++ parser rather than using the
2610 c_lex_string_translate kludge. */
2611 c_lex_string_translate
= 0;
2612 c_parser_consume_token (parser
);
2613 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2615 c_lex_string_translate
= 1;
2618 str
= c_parser_asm_string_literal (parser
);
2619 c_lex_string_translate
= 1;
2620 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2622 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2628 /* Parse (possibly empty) attributes. This is a GNU extension.
2632 attributes attribute
2635 __attribute__ ( ( attribute-list ) )
2639 attribute_list , attrib
2644 any-word ( identifier )
2645 any-word ( identifier , nonempty-expr-list )
2646 any-word ( expr-list )
2648 where the "identifier" must not be declared as a type, and
2649 "any-word" may be any identifier (including one declared as a
2650 type), a reserved word storage class specifier, type specifier or
2651 type qualifier. ??? This still leaves out most reserved keywords
2652 (following the old parser), shouldn't we include them, and why not
2653 allow identifiers declared as types to start the arguments? */
2656 c_parser_attributes (c_parser
*parser
)
2658 tree attrs
= NULL_TREE
;
2659 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2661 /* ??? Follow the C++ parser rather than using the
2662 c_lex_string_translate kludge. */
2663 c_lex_string_translate
= 0;
2664 c_parser_consume_token (parser
);
2665 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2667 c_lex_string_translate
= 1;
2670 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2672 c_lex_string_translate
= 1;
2673 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2676 /* Parse the attribute list. */
2677 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2678 || c_parser_next_token_is (parser
, CPP_NAME
)
2679 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2681 tree attr
, attr_name
, attr_args
;
2682 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2684 c_parser_consume_token (parser
);
2687 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2689 /* ??? See comment above about what keywords are
2692 switch (c_parser_peek_token (parser
)->keyword
)
2724 attr_name
= c_parser_peek_token (parser
)->value
;
2725 c_parser_consume_token (parser
);
2726 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2728 attr
= build_tree_list (attr_name
, NULL_TREE
);
2729 attrs
= chainon (attrs
, attr
);
2732 c_parser_consume_token (parser
);
2733 /* Parse the attribute contents. If they start with an
2734 identifier which is followed by a comma or close
2735 parenthesis, then the arguments start with that
2736 identifier; otherwise they are an expression list. */
2737 if (c_parser_next_token_is (parser
, CPP_NAME
)
2738 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2739 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2740 || (c_parser_peek_2nd_token (parser
)->type
2741 == CPP_CLOSE_PAREN
)))
2743 tree arg1
= c_parser_peek_token (parser
)->value
;
2744 c_parser_consume_token (parser
);
2745 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2746 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2749 c_parser_consume_token (parser
);
2750 attr_args
= tree_cons (NULL_TREE
, arg1
,
2751 c_parser_expr_list (parser
));
2756 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2757 attr_args
= NULL_TREE
;
2759 attr_args
= c_parser_expr_list (parser
);
2761 attr
= build_tree_list (attr_name
, attr_args
);
2762 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2763 c_parser_consume_token (parser
);
2766 c_lex_string_translate
= 1;
2767 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2771 attrs
= chainon (attrs
, attr
);
2773 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2774 c_parser_consume_token (parser
);
2777 c_lex_string_translate
= 1;
2778 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2782 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2783 c_parser_consume_token (parser
);
2786 c_lex_string_translate
= 1;
2787 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2791 c_lex_string_translate
= 1;
2796 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2799 specifier-qualifier-list abstract-declarator[opt]
2802 static struct c_type_name
*
2803 c_parser_type_name (c_parser
*parser
)
2805 struct c_declspecs
*specs
= build_null_declspecs ();
2806 struct c_declarator
*declarator
;
2807 struct c_type_name
*ret
;
2809 c_parser_declspecs (parser
, specs
, false, true, true);
2810 if (!specs
->declspecs_seen_p
)
2812 c_parser_error (parser
, "expected specifier-qualifier-list");
2815 pending_xref_error ();
2816 finish_declspecs (specs
);
2817 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2818 C_DTR_ABSTRACT
, &dummy
);
2819 if (declarator
== NULL
)
2821 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2823 ret
->declarator
= declarator
;
2827 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2830 assignment-expression
2831 { initializer-list }
2832 { initializer-list , }
2835 designation[opt] initializer
2836 initializer-list , designation[opt] initializer
2843 designator-list designator
2850 [ constant-expression ]
2862 [ constant-expression ... constant-expression ]
2864 Any expression without commas is accepted in the syntax for the
2865 constant-expressions, with non-constant expressions rejected later.
2867 This function is only used for top-level initializers; for nested
2868 ones, see c_parser_initval. */
2870 static struct c_expr
2871 c_parser_initializer (c_parser
*parser
)
2873 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2874 return c_parser_braced_init (parser
, NULL_TREE
, false);
2876 return c_parser_expr_no_commas (parser
, NULL
);
2879 /* Parse a braced initializer list. TYPE is the type specified for a
2880 compound literal, and NULL_TREE for other initializers and for
2881 nested braced lists. NESTED_P is true for nested braced lists,
2882 false for the list of a compound literal or the list that is the
2883 top-level initializer in a declaration. */
2885 static struct c_expr
2886 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
2888 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
2889 c_parser_consume_token (parser
);
2891 push_init_level (0);
2893 really_start_incremental_init (type
);
2894 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2897 pedwarn ("ISO C forbids empty initializer braces");
2901 /* Parse a non-empty initializer list, possibly with a trailing
2905 c_parser_initelt (parser
);
2908 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2909 c_parser_consume_token (parser
);
2912 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2916 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
2919 ret
.value
= error_mark_node
;
2920 ret
.original_code
= ERROR_MARK
;
2921 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
2924 c_parser_consume_token (parser
);
2925 return pop_init_level (0);
2928 /* Parse a nested initializer, including designators. */
2931 c_parser_initelt (c_parser
*parser
)
2933 /* Parse any designator or designator list. A single array
2934 designator may have the subsequent "=" omitted in GNU C, but a
2935 longer list or a structure member designator may not. */
2936 if (c_parser_next_token_is (parser
, CPP_NAME
)
2937 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
2939 /* Old-style structure member designator. */
2940 set_init_label (c_parser_peek_token (parser
)->value
);
2942 pedwarn ("obsolete use of designated initializer with %<:%>");
2943 c_parser_consume_token (parser
);
2944 c_parser_consume_token (parser
);
2948 /* des_seen is 0 if there have been no designators, 1 if there
2949 has been a single array designator and 2 otherwise. */
2951 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
2952 || c_parser_next_token_is (parser
, CPP_DOT
))
2954 int des_prev
= des_seen
;
2957 if (c_parser_next_token_is (parser
, CPP_DOT
))
2960 c_parser_consume_token (parser
);
2961 if (c_parser_next_token_is (parser
, CPP_NAME
))
2963 set_init_label (c_parser_peek_token (parser
)->value
);
2964 c_parser_consume_token (parser
);
2969 init
.value
= error_mark_node
;
2970 init
.original_code
= ERROR_MARK
;
2971 c_parser_error (parser
, "expected identifier");
2972 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2973 process_init_element (init
);
2980 /* ??? Following the old parser, [ objc-receiver
2981 objc-message-args ] is accepted as an initializer,
2982 being distinguished from a designator by what follows
2983 the first assignment expression inside the square
2984 brackets, but after a first array designator a
2985 subsequent square bracket is for Objective-C taken to
2986 start an expression, using the obsolete form of
2987 designated initializer without '=', rather than
2988 possibly being a second level of designation: in LALR
2989 terms, the '[' is shifted rather than reducing
2990 designator to designator-list. */
2991 if (des_prev
== 1 && c_dialect_objc ())
2993 des_seen
= des_prev
;
2996 if (des_prev
== 0 && c_dialect_objc ())
2998 /* This might be an array designator or an
2999 Objective-C message expression. If the former,
3000 continue parsing here; if the latter, parse the
3001 remainder of the initializer given the starting
3002 primary-expression. ??? It might make sense to
3003 distinguish when des_prev == 1 as well; see
3004 previous comment. */
3006 struct c_expr mexpr
;
3007 c_parser_consume_token (parser
);
3008 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3009 && ((c_parser_peek_token (parser
)->id_kind
3011 || (c_parser_peek_token (parser
)->id_kind
3012 == C_ID_CLASSNAME
)))
3014 /* Type name receiver. */
3015 tree id
= c_parser_peek_token (parser
)->value
;
3016 c_parser_consume_token (parser
);
3017 rec
= objc_get_class_reference (id
);
3018 goto parse_message_args
;
3020 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3021 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3022 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3023 goto array_desig_after_first
;
3024 /* Expression receiver. So far only one part
3025 without commas has been parsed; there might be
3026 more of the expression. */
3028 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3031 c_parser_consume_token (parser
);
3032 next
= c_parser_expr_no_commas (parser
, NULL
).value
;
3033 rec
= build_compound_expr (rec
, next
);
3036 /* Now parse the objc-message-args. */
3037 args
= c_parser_objc_message_args (parser
);
3038 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3041 = objc_build_message_expr (build_tree_list (rec
, args
));
3042 mexpr
.original_code
= ERROR_MARK
;
3043 /* Now parse and process the remainder of the
3044 initializer, starting with this message
3045 expression as a primary-expression. */
3046 c_parser_initval (parser
, &mexpr
);
3049 c_parser_consume_token (parser
);
3050 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3051 array_desig_after_first
:
3052 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3054 c_parser_consume_token (parser
);
3055 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3059 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3061 c_parser_consume_token (parser
);
3062 set_init_index (first
, second
);
3063 if (pedantic
&& second
)
3064 pedwarn ("ISO C forbids specifying range of "
3065 "elements to initialize");
3068 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3074 if (c_parser_next_token_is (parser
, CPP_EQ
))
3076 if (pedantic
&& !flag_isoc99
)
3077 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3078 c_parser_consume_token (parser
);
3085 pedwarn ("obsolete use of designated initializer "
3091 init
.value
= error_mark_node
;
3092 init
.original_code
= ERROR_MARK
;
3093 c_parser_error (parser
, "expected %<=%>");
3094 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3095 process_init_element (init
);
3101 c_parser_initval (parser
, NULL
);
3104 /* Parse a nested initializer; as c_parser_initializer but parses
3105 initializers within braced lists, after any designators have been
3106 applied. If AFTER is not NULL then it is an Objective-C message
3107 expression which is the primary-expression starting the
3111 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3114 gcc_assert (!after
|| c_dialect_objc ());
3115 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3116 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3118 init
= c_parser_expr_no_commas (parser
, after
);
3119 process_init_element (init
);
3122 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3126 { block-item-list[opt] }
3127 { label-declarations block-item-list }
3131 block-item-list block-item
3143 { label-declarations block-item-list }
3146 __extension__ nested-declaration
3147 nested-function-definition
3151 label-declarations label-declaration
3154 __label__ identifier-list ;
3156 Allowing the mixing of declarations and code is new in C99. The
3157 GNU syntax also permits (not shown above) labels at the end of
3158 compound statements, which yield an error. We don't allow labels
3159 on declarations; this might seem like a natural extension, but
3160 there would be a conflict between attributes on the label and
3161 prefix attributes on the declaration. ??? The syntax follows the
3162 old parser in requiring something after label declarations.
3163 Although they are erroneous if the labels declared aren't defined,
3164 is it useful for the syntax to be this way? */
3167 c_parser_compound_statement (c_parser
*parser
)
3170 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3171 return error_mark_node
;
3172 stmt
= c_begin_compound_stmt (true);
3173 c_parser_compound_statement_nostart (parser
);
3174 return c_end_compound_stmt (stmt
, true);
3177 /* Parse a compound statement except for the opening brace. This is
3178 used for parsing both compound statements and statement expressions
3179 (which follow different paths to handling the opening). */
3182 c_parser_compound_statement_nostart (c_parser
*parser
)
3184 bool last_stmt
= false;
3185 bool last_label
= false;
3186 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3188 c_parser_consume_token (parser
);
3191 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3193 /* Read zero or more forward-declarations for labels that nested
3194 functions can jump to. */
3195 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3197 c_parser_consume_token (parser
);
3198 /* Any identifiers, including those declared as type names,
3203 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3205 c_parser_error (parser
, "expected identifier");
3209 = declare_label (c_parser_peek_token (parser
)->value
);
3210 C_DECLARED_LABEL_FLAG (label
) = 1;
3211 add_stmt (build_stmt (DECL_EXPR
, label
));
3212 c_parser_consume_token (parser
);
3213 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3214 c_parser_consume_token (parser
);
3218 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3220 /* ??? Locating this diagnostic on the token after the
3221 declarations end follows the old parser, but it might be
3222 better to locate it where the declarations start instead. */
3224 pedwarn ("ISO C forbids label declarations");
3226 /* We must now have at least one statement, label or declaration. */
3227 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3229 c_parser_error (parser
, "expected declaration or statement");
3230 c_parser_consume_token (parser
);
3233 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3235 location_t loc
= c_parser_peek_token (parser
)->location
;
3236 if (c_parser_next_token_is (parser
, CPP_EOF
))
3238 c_parser_error (parser
, "expected declaration or statement");
3241 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3242 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3243 || (c_parser_next_token_is (parser
, CPP_NAME
)
3244 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3248 c_parser_label (parser
);
3250 else if (!last_label
3251 && c_parser_next_token_starts_declspecs (parser
))
3254 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3256 && ((pedantic
&& !flag_isoc99
)
3257 || warn_declaration_after_statement
))
3258 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3262 else if (!last_label
3263 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3265 /* __extension__ can start a declaration, but is also an
3266 unary operator that can start an expression. Consume all
3267 but the last of a possible series of __extension__ to
3269 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3270 && (c_parser_peek_2nd_token (parser
)->keyword
3272 c_parser_consume_token (parser
);
3273 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3276 ext
= disable_extension_diagnostics ();
3277 c_parser_consume_token (parser
);
3279 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3280 /* Following the old parser, __extension__ does not
3281 disable this diagnostic. */
3282 restore_extension_diagnostics (ext
);
3284 && ((pedantic
&& !flag_isoc99
)
3285 || warn_declaration_after_statement
))
3286 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3298 c_parser_statement_after_labels (parser
);
3302 error ("label at end of compound statement");
3303 c_parser_consume_token (parser
);
3306 /* Parse a label (C90 6.6.1, C99 6.8.1).
3309 identifier : attributes[opt]
3310 case constant-expression :
3316 case constant-expression ... constant-expression :
3318 The use of attributes on labels is a GNU extension. The syntax in
3319 GNU C accepts any expressions without commas, non-constant
3320 expressions being rejected later. */
3323 c_parser_label (c_parser
*parser
)
3325 location_t loc1
= c_parser_peek_token (parser
)->location
;
3326 tree label
= NULL_TREE
;
3327 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3330 c_parser_consume_token (parser
);
3331 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3332 if (c_parser_next_token_is (parser
, CPP_COLON
))
3334 c_parser_consume_token (parser
);
3335 label
= do_case (exp1
, NULL_TREE
);
3337 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3339 c_parser_consume_token (parser
);
3340 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3341 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3342 label
= do_case (exp1
, exp2
);
3345 c_parser_error (parser
, "expected %<:%> or %<...%>");
3347 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3349 c_parser_consume_token (parser
);
3350 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3351 label
= do_case (NULL_TREE
, NULL_TREE
);
3355 tree name
= c_parser_peek_token (parser
)->value
;
3359 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3360 c_parser_consume_token (parser
);
3361 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3362 loc2
= c_parser_peek_token (parser
)->location
;
3363 c_parser_consume_token (parser
);
3364 attrs
= c_parser_attributes (parser
);
3365 tlab
= define_label (loc2
, name
);
3368 decl_attributes (&tlab
, attrs
, 0);
3369 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3373 SET_EXPR_LOCATION (label
, loc1
);
3376 /* Parse a statement (C90 6.6, C99 6.8).
3381 expression-statement
3389 expression-statement:
3392 selection-statement:
3396 iteration-statement:
3405 return expression[opt] ;
3418 objc-throw-statement
3419 objc-try-catch-statement
3420 objc-synchronized-statement
3422 objc-throw-statement:
3428 c_parser_statement (c_parser
*parser
)
3430 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3431 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3432 || (c_parser_next_token_is (parser
, CPP_NAME
)
3433 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3434 c_parser_label (parser
);
3435 c_parser_statement_after_labels (parser
);
3438 /* Parse a statement, other than a labeled statement. */
3441 c_parser_statement_after_labels (c_parser
*parser
)
3443 location_t loc
= c_parser_peek_token (parser
)->location
;
3444 tree stmt
= NULL_TREE
;
3445 switch (c_parser_peek_token (parser
)->type
)
3447 case CPP_OPEN_BRACE
:
3448 add_stmt (c_parser_compound_statement (parser
));
3451 switch (c_parser_peek_token (parser
)->keyword
)
3454 c_parser_if_statement (parser
);
3457 c_parser_switch_statement (parser
);
3460 c_parser_while_statement (parser
);
3463 c_parser_do_statement (parser
);
3466 c_parser_for_statement (parser
);
3469 c_parser_consume_token (parser
);
3470 if (c_parser_next_token_is (parser
, CPP_NAME
))
3472 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3473 c_parser_consume_token (parser
);
3475 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3477 c_parser_consume_token (parser
);
3478 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3481 c_parser_error (parser
, "expected identifier or %<*%>");
3482 goto expect_semicolon
;
3484 c_parser_consume_token (parser
);
3485 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3486 goto expect_semicolon
;
3488 c_parser_consume_token (parser
);
3489 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3490 goto expect_semicolon
;
3492 c_parser_consume_token (parser
);
3493 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3495 stmt
= c_finish_return (NULL_TREE
);
3496 c_parser_consume_token (parser
);
3500 stmt
= c_finish_return (c_parser_expression (parser
).value
);
3501 goto expect_semicolon
;
3505 stmt
= c_parser_asm_statement (parser
);
3508 gcc_assert (c_dialect_objc ());
3509 c_parser_consume_token (parser
);
3510 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3512 stmt
= objc_build_throw_stmt (NULL_TREE
);
3513 c_parser_consume_token (parser
);
3518 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3519 goto expect_semicolon
;
3523 gcc_assert (c_dialect_objc ());
3524 c_parser_objc_try_catch_statement (parser
);
3526 case RID_AT_SYNCHRONIZED
:
3527 gcc_assert (c_dialect_objc ());
3528 c_parser_objc_synchronized_statement (parser
);
3535 c_parser_consume_token (parser
);
3537 case CPP_CLOSE_PAREN
:
3538 case CPP_CLOSE_SQUARE
:
3539 /* Avoid infinite loop in error recovery:
3540 c_parser_skip_until_found stops at a closing nesting
3541 delimiter without consuming it, but here we need to consume
3542 it to proceed further. */
3543 c_parser_error (parser
, "expected statement");
3544 c_parser_consume_token (parser
);
3548 stmt
= c_finish_expr_stmt (c_parser_expression (parser
).value
);
3550 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3553 /* Two cases cannot and do not have line numbers associated: If stmt
3554 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3555 cannot hold line numbers. But that's OK because the statement
3556 will either be changed to a MODIFY_EXPR during gimplification of
3557 the statement expr, or discarded. If stmt was compound, but
3558 without new variables, we will have skipped the creation of a
3559 BIND and will have a bare STATEMENT_LIST. But that's OK because
3560 (recursively) all of the component statements should already have
3561 line numbers assigned. ??? Can we discard no-op statements
3563 if (stmt
&& EXPR_P (stmt
))
3564 SET_EXPR_LOCATION (stmt
, loc
);
3567 /* Parse a parenthesized condition from an if, do or while statement.
3573 c_parser_paren_condition (c_parser
*parser
)
3577 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3578 return error_mark_node
;
3579 loc
= c_parser_peek_token (parser
)->location
;
3580 cond
= c_objc_common_truthvalue_conversion
3581 (c_parser_expression (parser
).value
);
3583 SET_EXPR_LOCATION (cond
, loc
);
3584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3588 /* Parse a statement which is a block in C99. */
3591 c_parser_c99_block_statement (c_parser
*parser
)
3593 tree block
= c_begin_compound_stmt (flag_isoc99
);
3594 c_parser_statement (parser
);
3595 return c_end_compound_stmt (block
, flag_isoc99
);
3598 /* Parse the body of an if statement or the else half thereof. This
3599 is just parsing a statement but (a) it is a block in C99, (b) we
3600 track whether the body is an if statement for the sake of
3601 -Wparentheses warnings, (c) we handle an empty body specially for
3602 the sake of -Wextra warnings. */
3605 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3607 tree block
= c_begin_compound_stmt (flag_isoc99
);
3608 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3609 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3610 || (c_parser_next_token_is (parser
, CPP_NAME
)
3611 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3612 c_parser_label (parser
);
3613 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3614 if (extra_warnings
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3615 add_stmt (build (NOP_EXPR
, NULL_TREE
, NULL_TREE
));
3616 c_parser_statement_after_labels (parser
);
3617 return c_end_compound_stmt (block
, flag_isoc99
);
3620 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3623 if ( expression ) statement
3624 if ( expression ) statement else statement
3628 c_parser_if_statement (c_parser
*parser
)
3633 bool first_if
= false, second_if
= false;
3634 tree first_body
, second_body
;
3635 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3636 c_parser_consume_token (parser
);
3637 block
= c_begin_compound_stmt (flag_isoc99
);
3638 loc
= c_parser_peek_token (parser
)->location
;
3639 cond
= c_parser_paren_condition (parser
);
3640 first_body
= c_parser_if_body (parser
, &first_if
);
3641 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3643 c_parser_consume_token (parser
);
3644 second_body
= c_parser_if_body (parser
, &second_if
);
3647 second_body
= NULL_TREE
;
3648 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3649 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3652 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3655 switch (expression) statement
3659 c_parser_switch_statement (c_parser
*parser
)
3661 tree block
, expr
, body
, save_break
;
3662 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3663 c_parser_consume_token (parser
);
3664 block
= c_begin_compound_stmt (flag_isoc99
);
3665 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3667 expr
= c_parser_expression (parser
).value
;
3668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3671 expr
= error_mark_node
;
3672 c_start_case (expr
);
3673 save_break
= c_break_label
;
3674 c_break_label
= NULL_TREE
;
3675 body
= c_parser_c99_block_statement (parser
);
3676 c_finish_case (body
);
3678 add_stmt (build (LABEL_EXPR
, void_type_node
, c_break_label
));
3679 c_break_label
= save_break
;
3680 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3683 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3686 while (expression) statement
3690 c_parser_while_statement (c_parser
*parser
)
3692 tree block
, cond
, body
, save_break
, save_cont
;
3694 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3695 c_parser_consume_token (parser
);
3696 block
= c_begin_compound_stmt (flag_isoc99
);
3697 loc
= c_parser_peek_token (parser
)->location
;
3698 cond
= c_parser_paren_condition (parser
);
3699 save_break
= c_break_label
;
3700 c_break_label
= NULL_TREE
;
3701 save_cont
= c_cont_label
;
3702 c_cont_label
= NULL_TREE
;
3703 body
= c_parser_c99_block_statement (parser
);
3704 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3705 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3706 c_break_label
= save_break
;
3707 c_cont_label
= save_cont
;
3710 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3713 do statement while ( expression ) ;
3717 c_parser_do_statement (c_parser
*parser
)
3719 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3721 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3722 c_parser_consume_token (parser
);
3723 block
= c_begin_compound_stmt (flag_isoc99
);
3724 loc
= c_parser_peek_token (parser
)->location
;
3725 save_break
= c_break_label
;
3726 c_break_label
= NULL_TREE
;
3727 save_cont
= c_cont_label
;
3728 c_cont_label
= NULL_TREE
;
3729 body
= c_parser_c99_block_statement (parser
);
3730 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3731 new_break
= c_break_label
;
3732 c_break_label
= save_break
;
3733 new_cont
= c_cont_label
;
3734 c_cont_label
= save_cont
;
3735 cond
= c_parser_paren_condition (parser
);
3736 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3737 c_parser_skip_to_end_of_block_or_statement (parser
);
3738 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3739 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3742 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3745 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3746 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3748 The form with a declaration is new in C99.
3750 ??? In accordance with the old parser, the declaration may be a
3751 nested function, which is then rejected in check_for_loop_decls,
3752 but does it make any sense for this to be included in the grammar?
3753 Note in particular that the nested function does not include a
3754 trailing ';', whereas the "declaration" production includes one.
3755 Also, can we reject bad declarations earlier and cheaper than
3756 check_for_loop_decls? */
3759 c_parser_for_statement (c_parser
*parser
)
3761 tree block
, cond
, incr
, save_break
, save_cont
, body
;
3762 location_t loc
= UNKNOWN_LOCATION
;
3763 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
3764 c_parser_consume_token (parser
);
3765 block
= c_begin_compound_stmt (flag_isoc99
);
3766 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3768 /* Parse the initialization declaration or expression. */
3769 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3771 c_parser_consume_token (parser
);
3772 c_finish_expr_stmt (NULL_TREE
);
3774 else if (c_parser_next_token_starts_declspecs (parser
))
3776 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3777 check_for_loop_decls ();
3779 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3781 /* __extension__ can start a declaration, but is also an
3782 unary operator that can start an expression. Consume all
3783 but the last of a possible series of __extension__ to
3785 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3786 && (c_parser_peek_2nd_token (parser
)->keyword
3788 c_parser_consume_token (parser
);
3789 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3792 ext
= disable_extension_diagnostics ();
3793 c_parser_consume_token (parser
);
3794 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3795 restore_extension_diagnostics (ext
);
3796 check_for_loop_decls ();
3804 c_finish_expr_stmt (c_parser_expression (parser
).value
);
3805 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3807 /* Parse the loop condition. */
3808 loc
= c_parser_peek_token (parser
)->location
;
3809 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3811 c_parser_consume_token (parser
);
3816 tree ocond
= c_parser_expression (parser
).value
;
3817 cond
= c_objc_common_truthvalue_conversion (ocond
);
3819 SET_EXPR_LOCATION (cond
, loc
);
3820 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3822 /* Parse the increment expression. */
3823 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3824 incr
= c_process_expr_stmt (NULL_TREE
);
3826 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
3827 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3831 cond
= error_mark_node
;
3832 incr
= error_mark_node
;
3834 save_break
= c_break_label
;
3835 c_break_label
= NULL_TREE
;
3836 save_cont
= c_cont_label
;
3837 c_cont_label
= NULL_TREE
;
3838 body
= c_parser_c99_block_statement (parser
);
3839 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
3840 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3841 c_break_label
= save_break
;
3842 c_cont_label
= save_cont
;
3845 /* Parse an asm statement, a GNU extension. This is a full-blown asm
3846 statement with inputs, outputs, clobbers, and volatile tag
3850 asm type-qualifier[opt] ( asm-argument ) ;
3854 asm-string-literal : asm-operands[opt]
3855 asm-string-literal : asm-operands[opt] : asm-operands[opt]
3856 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
3858 Qualifiers other than volatile are accepted in the syntax but
3862 c_parser_asm_statement (c_parser
*parser
)
3864 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
3866 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3867 c_parser_consume_token (parser
);
3868 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
3870 quals
= c_parser_peek_token (parser
)->value
;
3871 c_parser_consume_token (parser
);
3873 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
3874 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
3876 warning (0, "%E qualifier ignored on asm",
3877 c_parser_peek_token (parser
)->value
);
3879 c_parser_consume_token (parser
);
3883 /* ??? Follow the C++ parser rather than using the
3884 c_lex_string_translate kludge. */
3885 c_lex_string_translate
= 0;
3886 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3888 c_lex_string_translate
= 1;
3891 str
= c_parser_asm_string_literal (parser
);
3892 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3895 outputs
= NULL_TREE
;
3897 clobbers
= NULL_TREE
;
3900 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3902 c_lex_string_translate
= 1;
3903 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3907 /* Parse outputs. */
3908 if (c_parser_next_token_is (parser
, CPP_COLON
)
3909 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3910 outputs
= NULL_TREE
;
3912 outputs
= c_parser_asm_operands (parser
);
3913 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3916 clobbers
= NULL_TREE
;
3919 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3921 c_lex_string_translate
= 1;
3922 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3926 if (c_parser_next_token_is (parser
, CPP_COLON
)
3927 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3930 inputs
= c_parser_asm_operands (parser
);
3931 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3933 clobbers
= NULL_TREE
;
3936 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3938 c_lex_string_translate
= 1;
3939 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3942 /* Parse clobbers. */
3943 clobbers
= c_parser_asm_clobbers (parser
);
3945 c_lex_string_translate
= 1;
3946 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3948 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3951 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3952 c_parser_skip_to_end_of_block_or_statement (parser
);
3953 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
3958 /* Parse asm operands, a GNU extension.
3962 asm-operands , asm-operand
3965 asm-string-literal ( expression )
3966 [ identifier ] asm-string-literal ( expression )
3970 c_parser_asm_operands (c_parser
*parser
)
3972 tree list
= NULL_TREE
;
3975 tree name
, str
, expr
;
3976 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3978 c_parser_consume_token (parser
);
3979 if (c_parser_next_token_is (parser
, CPP_NAME
))
3981 tree id
= c_parser_peek_token (parser
)->value
;
3982 c_parser_consume_token (parser
);
3983 name
= build_string (IDENTIFIER_LENGTH (id
),
3984 IDENTIFIER_POINTER (id
));
3988 c_parser_error (parser
, "expected identifier");
3989 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3992 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3997 str
= c_parser_asm_string_literal (parser
);
3998 if (str
== NULL_TREE
)
4000 c_lex_string_translate
= 1;
4001 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4003 c_lex_string_translate
= 0;
4006 expr
= c_parser_expression (parser
).value
;
4007 c_lex_string_translate
= 0;
4008 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4010 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4013 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4015 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4016 c_parser_consume_token (parser
);
4023 /* Parse asm clobbers, a GNU extension.
4027 asm-clobbers , asm-string-literal
4031 c_parser_asm_clobbers (c_parser
*parser
)
4033 tree list
= NULL_TREE
;
4036 tree str
= c_parser_asm_string_literal (parser
);
4038 list
= tree_cons (NULL_TREE
, str
, list
);
4041 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4042 c_parser_consume_token (parser
);
4049 /* Parse an expression other than a compound expression; that is, an
4050 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4051 NULL then it is an Objective-C message expression which is the
4052 primary-expression starting the expression as an initializer.
4054 assignment-expression:
4055 conditional-expression
4056 unary-expression assignment-operator assignment-expression
4058 assignment-operator: one of
4059 = *= /= %= += -= <<= >>= &= ^= |=
4061 In GNU C we accept any conditional expression on the LHS and
4062 diagnose the invalid lvalue rather than producing a syntax
4065 static struct c_expr
4066 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4068 struct c_expr lhs
, rhs
, ret
;
4069 enum tree_code code
;
4070 gcc_assert (!after
|| c_dialect_objc ());
4071 lhs
= c_parser_conditional_expression (parser
, after
);
4072 switch (c_parser_peek_token (parser
)->type
)
4081 code
= TRUNC_DIV_EXPR
;
4084 code
= TRUNC_MOD_EXPR
;
4099 code
= BIT_AND_EXPR
;
4102 code
= BIT_XOR_EXPR
;
4105 code
= BIT_IOR_EXPR
;
4110 c_parser_consume_token (parser
);
4111 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4112 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4113 if (code
== NOP_EXPR
)
4114 ret
.original_code
= MODIFY_EXPR
;
4117 TREE_NO_WARNING (ret
.value
) = 1;
4118 ret
.original_code
= ERROR_MARK
;
4123 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4124 is not NULL then it is an Objective-C message expression which is
4125 the primary-expression starting the expression as an initializer.
4127 conditional-expression:
4128 logical-OR-expression
4129 logical-OR-expression ? expression : conditional-expression
4133 conditional-expression:
4134 logical-OR-expression ? : conditional-expression
4137 static struct c_expr
4138 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4140 struct c_expr cond
, exp1
, exp2
, ret
;
4141 gcc_assert (!after
|| c_dialect_objc ());
4142 cond
= c_parser_binary_expression (parser
, after
);
4143 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4145 c_parser_consume_token (parser
);
4146 if (c_parser_next_token_is (parser
, CPP_COLON
))
4149 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4150 /* Make sure first operand is calculated only once. */
4151 exp1
.value
= save_expr (default_conversion (cond
.value
));
4152 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4153 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4158 = c_objc_common_truthvalue_conversion
4159 (default_conversion (cond
.value
));
4160 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4161 exp1
= c_parser_expression (parser
);
4162 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4163 - (cond
.value
== truthvalue_false_node
));
4165 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4167 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4168 ret
.value
= error_mark_node
;
4169 ret
.original_code
= ERROR_MARK
;
4172 exp2
= c_parser_conditional_expression (parser
, NULL
);
4173 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4174 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4175 ret
.original_code
= ERROR_MARK
;
4179 /* Parse a binary expression; that is, a logical-OR-expression (C90
4180 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4181 an Objective-C message expression which is the primary-expression
4182 starting the expression as an initializer.
4184 multiplicative-expression:
4186 multiplicative-expression * cast-expression
4187 multiplicative-expression / cast-expression
4188 multiplicative-expression % cast-expression
4190 additive-expression:
4191 multiplicative-expression
4192 additive-expression + multiplicative-expression
4193 additive-expression - multiplicative-expression
4197 shift-expression << additive-expression
4198 shift-expression >> additive-expression
4200 relational-expression:
4202 relational-expression < shift-expression
4203 relational-expression > shift-expression
4204 relational-expression <= shift-expression
4205 relational-expression >= shift-expression
4207 equality-expression:
4208 relational-expression
4209 equality-expression == relational-expression
4210 equality-expression != relational-expression
4214 AND-expression & equality-expression
4216 exclusive-OR-expression:
4218 exclusive-OR-expression ^ AND-expression
4220 inclusive-OR-expression:
4221 exclusive-OR-expression
4222 inclusive-OR-expression | exclusive-OR-expression
4224 logical-AND-expression:
4225 inclusive-OR-expression
4226 logical-AND-expression && inclusive-OR-expression
4228 logical-OR-expression:
4229 logical-AND-expression
4230 logical-OR-expression || logical-AND-expression
4233 static struct c_expr
4234 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4236 /* A binary expression is parsed using operator-precedence parsing,
4237 with the operands being cast expressions. All the binary
4238 operators are left-associative. Thus a binary expression is of
4241 E0 op1 E1 op2 E2 ...
4243 which we represent on a stack. On the stack, the precedence
4244 levels are strictly increasing. When a new operator is
4245 encountered of higher precedence than that at the top of the
4246 stack, it is pushed; its LHS is the top expression, and its RHS
4247 is everything parsed until it is popped. When a new operator is
4248 encountered with precedence less than or equal to that at the top
4249 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4250 by the result of the operation until the operator at the top of
4251 the stack has lower precedence than the new operator or there is
4252 only one element on the stack; then the top expression is the LHS
4253 of the new operator. In the case of logical AND and OR
4254 expressions, we also need to adjust skip_evaluation as
4255 appropriate when the operators are pushed and popped. */
4257 /* The precedence levels, where 0 is a dummy lowest level used for
4258 the bottom of the stack. */
4274 /* The expression at this stack level. */
4276 /* The precedence of the operator on its left, PREC_NONE at the
4277 bottom of the stack. */
4279 /* The operation on its left. */
4285 switch (stack[sp].op) \
4287 case TRUTH_ANDIF_EXPR: \
4288 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4290 case TRUTH_ORIF_EXPR: \
4291 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4296 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4297 stack[sp - 1].expr, \
4301 gcc_assert (!after
|| c_dialect_objc ());
4302 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4303 stack
[0].prec
= PREC_NONE
;
4308 enum tree_code ocode
;
4311 switch (c_parser_peek_token (parser
)->type
)
4319 ocode
= TRUNC_DIV_EXPR
;
4323 ocode
= TRUNC_MOD_EXPR
;
4335 ocode
= LSHIFT_EXPR
;
4339 ocode
= RSHIFT_EXPR
;
4353 case CPP_GREATER_EQ
:
4366 oprec
= PREC_BITAND
;
4367 ocode
= BIT_AND_EXPR
;
4370 oprec
= PREC_BITXOR
;
4371 ocode
= BIT_XOR_EXPR
;
4375 ocode
= BIT_IOR_EXPR
;
4378 oprec
= PREC_LOGAND
;
4379 ocode
= TRUTH_ANDIF_EXPR
;
4383 ocode
= TRUTH_ORIF_EXPR
;
4386 /* Not a binary operator, so end of the binary
4390 c_parser_consume_token (parser
);
4391 while (oprec
<= stack
[sp
].prec
)
4395 case TRUTH_ANDIF_EXPR
:
4396 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4397 (default_conversion (stack
[sp
].expr
.value
));
4398 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4400 case TRUTH_ORIF_EXPR
:
4401 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4402 (default_conversion (stack
[sp
].expr
.value
));
4403 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4409 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4410 stack
[sp
].prec
= oprec
;
4411 stack
[sp
].op
= ocode
;
4416 return stack
[0].expr
;
4420 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4421 NULL then it is an Objective-C message expression which is the
4422 primary-expression starting the expression as an initializer.
4426 ( type-name ) unary-expression
4429 static struct c_expr
4430 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4432 gcc_assert (!after
|| c_dialect_objc ());
4434 return c_parser_postfix_expression_after_primary (parser
, *after
);
4435 /* If the expression begins with a parenthesized type name, it may
4436 be either a cast or a compound literal; we need to see whether
4437 the next character is '{' to tell the difference. If not, it is
4438 an unary expression. */
4439 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4440 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4442 struct c_type_name
*type_name
;
4445 c_parser_consume_token (parser
);
4446 type_name
= c_parser_type_name (parser
);
4447 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4448 if (type_name
== NULL
)
4450 ret
.value
= error_mark_node
;
4451 ret
.original_code
= ERROR_MARK
;
4454 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4455 return c_parser_postfix_expression_after_paren_type (parser
,
4457 expr
= c_parser_cast_expression (parser
, NULL
).value
;
4458 ret
.value
= c_cast_expr (type_name
, expr
);
4459 ret
.original_code
= ERROR_MARK
;
4463 return c_parser_unary_expression (parser
);
4466 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4472 unary-operator cast-expression
4473 sizeof unary-expression
4474 sizeof ( type-name )
4476 unary-operator: one of
4482 __alignof__ unary-expression
4483 __alignof__ ( type-name )
4486 unary-operator: one of
4487 __extension__ __real__ __imag__
4489 In addition, the GNU syntax treats ++ and -- as unary operators, so
4490 they may be applied to cast expressions with errors for non-lvalues
4493 static struct c_expr
4494 c_parser_unary_expression (c_parser
*parser
)
4498 switch (c_parser_peek_token (parser
)->type
)
4501 c_parser_consume_token (parser
);
4502 return parser_build_unary_op (PREINCREMENT_EXPR
,
4503 c_parser_cast_expression (parser
, NULL
));
4504 case CPP_MINUS_MINUS
:
4505 c_parser_consume_token (parser
);
4506 return parser_build_unary_op (PREDECREMENT_EXPR
,
4507 c_parser_cast_expression (parser
, NULL
));
4509 c_parser_consume_token (parser
);
4510 return parser_build_unary_op (ADDR_EXPR
,
4511 c_parser_cast_expression (parser
, NULL
));
4513 c_parser_consume_token (parser
);
4515 = build_indirect_ref (c_parser_cast_expression (parser
, NULL
).value
,
4517 ret
.original_code
= ERROR_MARK
;
4520 c_parser_consume_token (parser
);
4521 if (!c_dialect_objc () && warn_traditional
&& !in_system_header
)
4522 warning (0, "traditional C rejects the unary plus operator");
4523 return parser_build_unary_op (CONVERT_EXPR
,
4524 c_parser_cast_expression (parser
, NULL
));
4526 c_parser_consume_token (parser
);
4527 return parser_build_unary_op (NEGATE_EXPR
,
4528 c_parser_cast_expression (parser
, NULL
));
4530 c_parser_consume_token (parser
);
4531 return parser_build_unary_op (BIT_NOT_EXPR
,
4532 c_parser_cast_expression (parser
, NULL
));
4534 c_parser_consume_token (parser
);
4535 return parser_build_unary_op (TRUTH_NOT_EXPR
,
4536 c_parser_cast_expression (parser
, NULL
));
4538 /* Refer to the address of a label as a pointer. */
4539 c_parser_consume_token (parser
);
4540 if (c_parser_next_token_is (parser
, CPP_NAME
))
4542 ret
.value
= finish_label_address_expr
4543 (c_parser_peek_token (parser
)->value
);
4544 c_parser_consume_token (parser
);
4548 c_parser_error (parser
, "expected identifier");
4549 ret
.value
= error_mark_node
;
4551 ret
.original_code
= ERROR_MARK
;
4554 switch (c_parser_peek_token (parser
)->keyword
)
4557 return c_parser_sizeof_expression (parser
);
4559 return c_parser_alignof_expression (parser
);
4561 c_parser_consume_token (parser
);
4562 ext
= disable_extension_diagnostics ();
4563 ret
= c_parser_cast_expression (parser
, NULL
);
4564 restore_extension_diagnostics (ext
);
4567 c_parser_consume_token (parser
);
4568 return parser_build_unary_op (REALPART_EXPR
,
4569 c_parser_cast_expression (parser
,
4572 c_parser_consume_token (parser
);
4573 return parser_build_unary_op (IMAGPART_EXPR
,
4574 c_parser_cast_expression (parser
,
4577 return c_parser_postfix_expression (parser
);
4580 return c_parser_postfix_expression (parser
);
4584 /* Parse a sizeof expression. */
4586 static struct c_expr
4587 c_parser_sizeof_expression (c_parser
*parser
)
4590 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4591 c_parser_consume_token (parser
);
4594 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4595 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4597 /* Either sizeof ( type-name ) or sizeof unary-expression
4598 starting with a compound literal. */
4599 struct c_type_name
*type_name
;
4600 c_parser_consume_token (parser
);
4601 type_name
= c_parser_type_name (parser
);
4602 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4603 if (type_name
== NULL
)
4608 ret
.value
= error_mark_node
;
4609 ret
.original_code
= ERROR_MARK
;
4612 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4614 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4618 /* sizeof ( type-name ). */
4621 return c_expr_sizeof_type (type_name
);
4625 expr
= c_parser_unary_expression (parser
);
4629 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4630 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4631 error ("%<sizeof%> applied to a bit-field");
4632 return c_expr_sizeof_expr (expr
);
4636 /* Parse an alignof expression. */
4638 static struct c_expr
4639 c_parser_alignof_expression (c_parser
*parser
)
4642 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4643 c_parser_consume_token (parser
);
4646 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4647 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4649 /* Either __alignof__ ( type-name ) or __alignof__
4650 unary-expression starting with a compound literal. */
4651 struct c_type_name
*type_name
;
4653 c_parser_consume_token (parser
);
4654 type_name
= c_parser_type_name (parser
);
4655 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4656 if (type_name
== NULL
)
4661 ret
.value
= error_mark_node
;
4662 ret
.original_code
= ERROR_MARK
;
4665 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4667 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4671 /* alignof ( type-name ). */
4674 ret
.value
= c_alignof (groktypename (type_name
));
4675 ret
.original_code
= ERROR_MARK
;
4681 expr
= c_parser_unary_expression (parser
);
4685 ret
.value
= c_alignof_expr (expr
.value
);
4686 ret
.original_code
= ERROR_MARK
;
4691 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4695 postfix-expression [ expression ]
4696 postfix-expression ( argument-expression-list[opt] )
4697 postfix-expression . identifier
4698 postfix-expression -> identifier
4699 postfix-expression ++
4700 postfix-expression --
4701 ( type-name ) { initializer-list }
4702 ( type-name ) { initializer-list , }
4704 argument-expression-list:
4706 argument-expression-list , argument-expression
4718 (treated as a keyword in GNU C)
4721 ( compound-statement )
4722 __builtin_va_arg ( assignment-expression , type-name )
4723 __builtin_offsetof ( type-name , offsetof-member-designator )
4724 __builtin_choose_expr ( assignment-expression ,
4725 assignment-expression ,
4726 assignment-expression )
4727 __builtin_types_compatible_p ( type-name , type-name )
4729 offsetof-member-designator:
4731 offsetof-member-designator . identifier
4732 offsetof-member-designator [ expression ]
4737 [ objc-receiver objc-message-args ]
4738 @selector ( objc-selector-arg )
4739 @protocol ( identifier )
4740 @encode ( type-name )
4744 static struct c_expr
4745 c_parser_postfix_expression (c_parser
*parser
)
4747 struct c_expr expr
, e1
, e2
, e3
;
4748 struct c_type_name
*t1
, *t2
;
4749 switch (c_parser_peek_token (parser
)->type
)
4754 expr
.value
= c_parser_peek_token (parser
)->value
;
4755 expr
.original_code
= ERROR_MARK
;
4756 c_parser_consume_token (parser
);
4760 expr
.value
= c_parser_peek_token (parser
)->value
;
4761 expr
.original_code
= STRING_CST
;
4762 c_parser_consume_token (parser
);
4764 case CPP_OBJC_STRING
:
4765 gcc_assert (c_dialect_objc ());
4767 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
4768 expr
.original_code
= ERROR_MARK
;
4769 c_parser_consume_token (parser
);
4772 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
4774 c_parser_error (parser
, "expected expression");
4775 expr
.value
= error_mark_node
;
4776 expr
.original_code
= ERROR_MARK
;
4780 tree id
= c_parser_peek_token (parser
)->value
;
4781 location_t loc
= c_parser_peek_token (parser
)->location
;
4782 c_parser_consume_token (parser
);
4783 expr
.value
= build_external_ref (id
,
4784 (c_parser_peek_token (parser
)->type
4785 == CPP_OPEN_PAREN
), loc
);
4786 expr
.original_code
= ERROR_MARK
;
4789 case CPP_OPEN_PAREN
:
4790 /* A parenthesized expression, statement expression or compound
4792 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
4794 /* A statement expression. */
4796 c_parser_consume_token (parser
);
4797 c_parser_consume_token (parser
);
4798 if (cur_stmt_list
== NULL
)
4800 error ("braced-group within expression allowed "
4801 "only inside a function");
4802 parser
->error
= true;
4803 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
4804 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4805 expr
.value
= error_mark_node
;
4806 expr
.original_code
= ERROR_MARK
;
4809 stmt
= c_begin_stmt_expr ();
4810 c_parser_compound_statement_nostart (parser
);
4811 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4814 pedwarn ("ISO C forbids braced-groups within expressions");
4815 expr
.value
= c_finish_stmt_expr (stmt
);
4816 expr
.original_code
= ERROR_MARK
;
4818 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4820 /* A compound literal. ??? Can we actually get here rather
4821 than going directly to
4822 c_parser_postfix_expression_after_paren_type from
4824 struct c_type_name
*type_name
;
4825 c_parser_consume_token (parser
);
4826 type_name
= c_parser_type_name (parser
);
4827 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4829 if (type_name
== NULL
)
4831 expr
.value
= error_mark_node
;
4832 expr
.original_code
= ERROR_MARK
;
4835 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4840 /* A parenthesized expression. */
4841 c_parser_consume_token (parser
);
4842 expr
= c_parser_expression (parser
);
4843 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
4844 TREE_NO_WARNING (expr
.value
) = 1;
4845 expr
.original_code
= ERROR_MARK
;
4846 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4851 switch (c_parser_peek_token (parser
)->keyword
)
4853 case RID_FUNCTION_NAME
:
4854 case RID_PRETTY_FUNCTION_NAME
:
4855 case RID_C99_FUNCTION_NAME
:
4856 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
4857 c_parser_peek_token (parser
)->value
);
4858 expr
.original_code
= ERROR_MARK
;
4859 c_parser_consume_token (parser
);
4862 c_parser_consume_token (parser
);
4863 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4865 expr
.value
= error_mark_node
;
4866 expr
.original_code
= ERROR_MARK
;
4869 e1
= c_parser_expr_no_commas (parser
, NULL
);
4870 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4872 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4873 expr
.value
= error_mark_node
;
4874 expr
.original_code
= ERROR_MARK
;
4877 t1
= c_parser_type_name (parser
);
4878 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4882 expr
.value
= error_mark_node
;
4883 expr
.original_code
= ERROR_MARK
;
4887 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
4888 expr
.original_code
= ERROR_MARK
;
4892 c_parser_consume_token (parser
);
4893 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4895 expr
.value
= error_mark_node
;
4896 expr
.original_code
= ERROR_MARK
;
4899 t1
= c_parser_type_name (parser
);
4902 expr
.value
= error_mark_node
;
4903 expr
.original_code
= ERROR_MARK
;
4906 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4908 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4909 expr
.value
= error_mark_node
;
4910 expr
.original_code
= ERROR_MARK
;
4914 tree type
= groktypename (t1
);
4916 if (type
== error_mark_node
)
4917 offsetof_ref
= error_mark_node
;
4919 offsetof_ref
= build1 (INDIRECT_REF
, type
, NULL
);
4920 /* Parse the second argument to __builtin_offsetof. We
4921 must have one identifier, and beyond that we want to
4922 accept sub structure and sub array references. */
4923 if (c_parser_next_token_is (parser
, CPP_NAME
))
4925 offsetof_ref
= build_component_ref
4926 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
4927 c_parser_consume_token (parser
);
4928 while (c_parser_next_token_is (parser
, CPP_DOT
)
4929 || c_parser_next_token_is (parser
,
4932 if (c_parser_next_token_is (parser
, CPP_DOT
))
4934 c_parser_consume_token (parser
);
4935 if (c_parser_next_token_is_not (parser
,
4938 c_parser_error (parser
, "expected identifier");
4941 offsetof_ref
= build_component_ref
4943 c_parser_peek_token (parser
)->value
);
4944 c_parser_consume_token (parser
);
4949 c_parser_consume_token (parser
);
4950 idx
= c_parser_expression (parser
).value
;
4951 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4953 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
4958 c_parser_error (parser
, "expected identifier");
4959 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4961 expr
.value
= fold_offsetof (offsetof_ref
);
4962 expr
.original_code
= ERROR_MARK
;
4965 case RID_CHOOSE_EXPR
:
4966 c_parser_consume_token (parser
);
4967 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4969 expr
.value
= error_mark_node
;
4970 expr
.original_code
= ERROR_MARK
;
4973 e1
= c_parser_expr_no_commas (parser
, NULL
);
4974 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4976 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4977 expr
.value
= error_mark_node
;
4978 expr
.original_code
= ERROR_MARK
;
4981 e2
= c_parser_expr_no_commas (parser
, NULL
);
4982 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4984 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4985 expr
.value
= error_mark_node
;
4986 expr
.original_code
= ERROR_MARK
;
4989 e3
= c_parser_expr_no_commas (parser
, NULL
);
4990 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4995 c
= fold (e1
.value
);
4996 if (TREE_CODE (c
) != INTEGER_CST
)
4997 error ("first argument to %<__builtin_choose_expr%> not"
4999 expr
= integer_zerop (c
) ? e3
: e2
;
5002 case RID_TYPES_COMPATIBLE_P
:
5003 c_parser_consume_token (parser
);
5004 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5006 expr
.value
= error_mark_node
;
5007 expr
.original_code
= ERROR_MARK
;
5010 t1
= c_parser_type_name (parser
);
5013 expr
.value
= error_mark_node
;
5014 expr
.original_code
= ERROR_MARK
;
5017 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5019 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5020 expr
.value
= error_mark_node
;
5021 expr
.original_code
= ERROR_MARK
;
5024 t2
= c_parser_type_name (parser
);
5027 expr
.value
= error_mark_node
;
5028 expr
.original_code
= ERROR_MARK
;
5031 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5036 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5037 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5039 expr
.value
= comptypes (e1
, e2
)
5040 ? build_int_cst (NULL_TREE
, 1)
5041 : build_int_cst (NULL_TREE
, 0);
5042 expr
.original_code
= ERROR_MARK
;
5045 case RID_AT_SELECTOR
:
5046 gcc_assert (c_dialect_objc ());
5047 c_parser_consume_token (parser
);
5048 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5050 expr
.value
= error_mark_node
;
5051 expr
.original_code
= ERROR_MARK
;
5055 tree sel
= c_parser_objc_selector_arg (parser
);
5056 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5058 expr
.value
= objc_build_selector_expr (sel
);
5059 expr
.original_code
= ERROR_MARK
;
5062 case RID_AT_PROTOCOL
:
5063 gcc_assert (c_dialect_objc ());
5064 c_parser_consume_token (parser
);
5065 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5067 expr
.value
= error_mark_node
;
5068 expr
.original_code
= ERROR_MARK
;
5071 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5073 c_parser_error (parser
, "expected identifier");
5074 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5075 expr
.value
= error_mark_node
;
5076 expr
.original_code
= ERROR_MARK
;
5080 tree id
= c_parser_peek_token (parser
)->value
;
5081 c_parser_consume_token (parser
);
5082 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5084 expr
.value
= objc_build_protocol_expr (id
);
5085 expr
.original_code
= ERROR_MARK
;
5089 /* Extension to support C-structures in the archiver. */
5090 gcc_assert (c_dialect_objc ());
5091 c_parser_consume_token (parser
);
5092 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5094 expr
.value
= error_mark_node
;
5095 expr
.original_code
= ERROR_MARK
;
5098 t1
= c_parser_type_name (parser
);
5101 expr
.value
= error_mark_node
;
5102 expr
.original_code
= ERROR_MARK
;
5103 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5106 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5109 tree type
= groktypename (t1
);
5110 expr
.value
= objc_build_encode_expr (type
);
5111 expr
.original_code
= ERROR_MARK
;
5115 c_parser_error (parser
, "expected expression");
5116 expr
.value
= error_mark_node
;
5117 expr
.original_code
= ERROR_MARK
;
5121 case CPP_OPEN_SQUARE
:
5122 if (c_dialect_objc ())
5124 tree receiver
, args
;
5125 c_parser_consume_token (parser
);
5126 receiver
= c_parser_objc_receiver (parser
);
5127 args
= c_parser_objc_message_args (parser
);
5128 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5130 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5132 expr
.original_code
= ERROR_MARK
;
5135 /* Else fall through to report error. */
5137 c_parser_error (parser
, "expected expression");
5138 expr
.value
= error_mark_node
;
5139 expr
.original_code
= ERROR_MARK
;
5142 return c_parser_postfix_expression_after_primary (parser
, expr
);
5145 /* Parse a postfix expression after a parenthesized type name: the
5146 brace-enclosed initializer of a compound literal, possibly followed
5147 by some postfix operators. This is separate because it is not
5148 possible to tell until after the type name whether a cast
5149 expression has a cast or a compound literal, or whether the operand
5150 of sizeof is a parenthesized type name or starts with a compound
5153 static struct c_expr
5154 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5155 struct c_type_name
*type_name
)
5160 start_init (NULL_TREE
, NULL
, 0);
5161 type
= groktypename (type_name
);
5162 if (C_TYPE_VARIABLE_SIZE (type
))
5164 error ("compound literal has variable size");
5165 type
= error_mark_node
;
5167 init
= c_parser_braced_init (parser
, type
, false);
5169 maybe_warn_string_init (type
, init
);
5171 if (pedantic
&& !flag_isoc99
)
5172 pedwarn ("ISO C90 forbids compound literals");
5173 expr
.value
= build_compound_literal (type
, init
.value
);
5174 expr
.original_code
= ERROR_MARK
;
5175 return c_parser_postfix_expression_after_primary (parser
, expr
);
5178 /* Parse a postfix expression after the initial primary or compound
5179 literal; that is, parse a series of postfix operators. */
5181 static struct c_expr
5182 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5185 tree ident
, idx
, exprlist
;
5188 switch (c_parser_peek_token (parser
)->type
)
5190 case CPP_OPEN_SQUARE
:
5191 /* Array reference. */
5192 c_parser_consume_token (parser
);
5193 idx
= c_parser_expression (parser
).value
;
5194 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5196 expr
.value
= build_array_ref (expr
.value
, idx
);
5197 expr
.original_code
= ERROR_MARK
;
5199 case CPP_OPEN_PAREN
:
5200 /* Function call. */
5201 c_parser_consume_token (parser
);
5202 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5203 exprlist
= NULL_TREE
;
5205 exprlist
= c_parser_expr_list (parser
);
5206 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5208 expr
.value
= build_function_call (expr
.value
, exprlist
);
5209 expr
.original_code
= ERROR_MARK
;
5212 /* Structure element reference. */
5213 c_parser_consume_token (parser
);
5214 if (c_parser_next_token_is (parser
, CPP_NAME
))
5215 ident
= c_parser_peek_token (parser
)->value
;
5218 c_parser_error (parser
, "expected identifier");
5219 expr
.value
= error_mark_node
;
5220 expr
.original_code
= ERROR_MARK
;
5223 c_parser_consume_token (parser
);
5224 expr
.value
= build_component_ref (expr
.value
, ident
);
5225 expr
.original_code
= ERROR_MARK
;
5228 /* Structure element reference. */
5229 c_parser_consume_token (parser
);
5230 if (c_parser_next_token_is (parser
, CPP_NAME
))
5231 ident
= c_parser_peek_token (parser
)->value
;
5234 c_parser_error (parser
, "expected identifier");
5235 expr
.value
= error_mark_node
;
5236 expr
.original_code
= ERROR_MARK
;
5239 c_parser_consume_token (parser
);
5240 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5242 expr
.original_code
= ERROR_MARK
;
5245 /* Postincrement. */
5246 c_parser_consume_token (parser
);
5247 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5248 expr
.original_code
= ERROR_MARK
;
5250 case CPP_MINUS_MINUS
:
5251 /* Postdecrement. */
5252 c_parser_consume_token (parser
);
5253 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5254 expr
.original_code
= ERROR_MARK
;
5262 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5265 assignment-expression
5266 expression , assignment-expression
5269 static struct c_expr
5270 c_parser_expression (c_parser
*parser
)
5273 expr
= c_parser_expr_no_commas (parser
, NULL
);
5274 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5277 c_parser_consume_token (parser
);
5278 next
= c_parser_expr_no_commas (parser
, NULL
);
5279 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5280 expr
.original_code
= COMPOUND_EXPR
;
5285 /* Parse a non-empty list of expressions.
5288 assignment-expression
5289 nonempty-expr-list , assignment-expression
5293 c_parser_expr_list (c_parser
*parser
)
5297 expr
= c_parser_expr_no_commas (parser
, NULL
);
5298 ret
= build_tree_list (NULL_TREE
, expr
.value
);
5299 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5301 c_parser_consume_token (parser
);
5302 expr
= c_parser_expr_no_commas (parser
, NULL
);
5303 ret
= chainon (ret
, build_tree_list (NULL_TREE
, expr
.value
));
5309 /* Parse Objective-C-specific constructs. */
5311 /* Parse an objc-class-definition.
5313 objc-class-definition:
5314 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5315 objc-class-instance-variables[opt] objc-methodprotolist @end
5316 @implementation identifier objc-superclass[opt]
5317 objc-class-instance-variables[opt]
5318 @interface identifier ( identifier ) objc-protocol-refs[opt]
5319 objc-methodprotolist @end
5320 @implementation identifier ( identifier )
5325 "@interface identifier (" must start "@interface identifier (
5326 identifier ) ...": objc-methodprotolist in the first production may
5327 not start with a parenthesised identifier as a declarator of a data
5328 definition with no declaration specifiers if the objc-superclass,
5329 objc-protocol-refs and objc-class-instance-variables are omitted. */
5332 c_parser_objc_class_definition (c_parser
*parser
)
5337 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5339 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5343 c_parser_consume_token (parser
);
5344 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5346 c_parser_error (parser
, "expected identifier");
5349 id1
= c_parser_peek_token (parser
)->value
;
5350 c_parser_consume_token (parser
);
5351 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5354 tree proto
= NULL_TREE
;
5355 c_parser_consume_token (parser
);
5356 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5358 c_parser_error (parser
, "expected identifier");
5359 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5362 id2
= c_parser_peek_token (parser
)->value
;
5363 c_parser_consume_token (parser
);
5364 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5367 objc_start_category_implementation (id1
, id2
);
5370 if (c_parser_next_token_is (parser
, CPP_LESS
))
5371 proto
= c_parser_objc_protocol_refs (parser
);
5372 objc_start_category_interface (id1
, id2
, proto
);
5373 c_parser_objc_methodprotolist (parser
);
5374 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5375 objc_finish_interface ();
5378 if (c_parser_next_token_is (parser
, CPP_COLON
))
5380 c_parser_consume_token (parser
);
5381 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5383 c_parser_error (parser
, "expected identifier");
5386 superclass
= c_parser_peek_token (parser
)->value
;
5387 c_parser_consume_token (parser
);
5390 superclass
= NULL_TREE
;
5393 tree proto
= NULL_TREE
;
5394 if (c_parser_next_token_is (parser
, CPP_LESS
))
5395 proto
= c_parser_objc_protocol_refs (parser
);
5396 objc_start_class_interface (id1
, superclass
, proto
);
5399 objc_start_class_implementation (id1
, superclass
);
5400 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5401 c_parser_objc_class_instance_variables (parser
);
5404 objc_continue_interface ();
5405 c_parser_objc_methodprotolist (parser
);
5406 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5407 objc_finish_interface ();
5411 objc_continue_implementation ();
5416 /* Parse objc-class-instance-variables.
5418 objc-class-instance-variables:
5419 { objc-instance-variable-decl-list[opt] }
5421 objc-instance-variable-decl-list:
5422 objc-visibility-spec
5423 objc-instance-variable-decl ;
5425 objc-instance-variable-decl-list objc-visibility-spec
5426 objc-instance-variable-decl-list objc-instance-variable-decl ;
5427 objc-instance-variable-decl-list ;
5429 objc-visibility-spec:
5434 objc-instance-variable-decl:
5439 c_parser_objc_class_instance_variables (c_parser
*parser
)
5441 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5442 c_parser_consume_token (parser
);
5443 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5446 /* Parse any stray semicolon. */
5447 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5450 pedwarn ("extra semicolon in struct or union specified");
5451 c_parser_consume_token (parser
);
5454 /* Stop if at the end of the instance variables. */
5455 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5457 c_parser_consume_token (parser
);
5460 /* Parse any objc-visibility-spec. */
5461 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5463 c_parser_consume_token (parser
);
5464 objc_set_visibility (2);
5467 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5469 c_parser_consume_token (parser
);
5470 objc_set_visibility (0);
5473 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5475 c_parser_consume_token (parser
);
5476 objc_set_visibility (1);
5479 /* Parse some comma-separated declarations. */
5480 decls
= c_parser_struct_declaration (parser
);
5482 /* Comma-separated instance variables are chained together in
5483 reverse order; add them one by one. */
5484 tree ivar
= nreverse (decls
);
5485 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5486 objc_add_instance_variable (copy_node (ivar
));
5488 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5492 /* Parse an objc-class-declaration.
5494 objc-class-declaration:
5495 @class identifier-list ;
5499 c_parser_objc_class_declaration (c_parser
*parser
)
5501 tree list
= NULL_TREE
;
5502 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5503 c_parser_consume_token (parser
);
5504 /* Any identifiers, including those declared as type names, are OK
5509 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5511 c_parser_error (parser
, "expected identifier");
5514 id
= c_parser_peek_token (parser
)->value
;
5515 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5516 c_parser_consume_token (parser
);
5517 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5518 c_parser_consume_token (parser
);
5522 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5523 objc_declare_class (list
);
5526 /* Parse an objc-alias-declaration.
5528 objc-alias-declaration:
5529 @compatibility_alias identifier identifier ;
5533 c_parser_objc_alias_declaration (c_parser
*parser
)
5536 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5537 c_parser_consume_token (parser
);
5538 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5540 c_parser_error (parser
, "expected identifier");
5541 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5544 id1
= c_parser_peek_token (parser
)->value
;
5545 c_parser_consume_token (parser
);
5546 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5548 c_parser_error (parser
, "expected identifier");
5549 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5552 id2
= c_parser_peek_token (parser
)->value
;
5553 c_parser_consume_token (parser
);
5554 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5555 objc_declare_alias (id1
, id2
);
5558 /* Parse an objc-protocol-definition.
5560 objc-protocol-definition:
5561 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5562 @protocol identifier-list ;
5564 "@protocol identifier ;" should be resolved as "@protocol
5565 identifier-list ;": objc-methodprotolist may not start with a
5566 semicolon in the first alternative if objc-protocol-refs are
5570 c_parser_objc_protocol_definition (c_parser
*parser
)
5572 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5573 c_parser_consume_token (parser
);
5574 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5576 c_parser_error (parser
, "expected identifier");
5579 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5580 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5582 tree list
= NULL_TREE
;
5583 /* Any identifiers, including those declared as type names, are
5588 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5590 c_parser_error (parser
, "expected identifier");
5593 id
= c_parser_peek_token (parser
)->value
;
5594 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5595 c_parser_consume_token (parser
);
5596 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5597 c_parser_consume_token (parser
);
5601 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5602 objc_declare_protocols (list
);
5606 tree id
= c_parser_peek_token (parser
)->value
;
5607 tree proto
= NULL_TREE
;
5608 c_parser_consume_token (parser
);
5609 if (c_parser_next_token_is (parser
, CPP_LESS
))
5610 proto
= c_parser_objc_protocol_refs (parser
);
5611 objc_pq_context
= 1;
5612 objc_start_protocol (id
, proto
);
5613 c_parser_objc_methodprotolist (parser
);
5614 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5615 objc_pq_context
= 0;
5616 objc_finish_interface ();
5620 /* Parse an objc-method-type.
5627 static enum tree_code
5628 c_parser_objc_method_type (c_parser
*parser
)
5630 switch (c_parser_peek_token (parser
)->type
)
5633 c_parser_consume_token (parser
);
5636 c_parser_consume_token (parser
);
5643 /* Parse an objc-method-definition.
5645 objc-method-definition:
5646 objc-method-type objc-method-decl ;[opt] compound-statement
5650 c_parser_objc_method_definition (c_parser
*parser
)
5652 enum tree_code type
= c_parser_objc_method_type (parser
);
5654 objc_set_method_type (type
);
5655 objc_pq_context
= 1;
5656 decl
= c_parser_objc_method_decl (parser
);
5657 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5659 c_parser_consume_token (parser
);
5661 pedwarn ("extra semicolon in method definition specified");
5663 objc_pq_context
= 0;
5664 objc_start_method_definition (decl
);
5665 add_stmt (c_parser_compound_statement (parser
));
5666 objc_finish_method_definition (current_function_decl
);
5669 /* Parse an objc-methodprotolist.
5671 objc-methodprotolist:
5673 objc-methodprotolist objc-methodproto
5674 objc-methodprotolist declaration
5675 objc-methodprotolist ;
5677 The declaration is a data definition, which may be missing
5678 declaration specifiers under the same rules and diagnostics as
5679 other data definitions outside functions, and the stray semicolon
5680 is diagnosed the same way as a stray semicolon outside a
5684 c_parser_objc_methodprotolist (c_parser
*parser
)
5688 /* The list is terminated by @end. */
5689 switch (c_parser_peek_token (parser
)->type
)
5693 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5694 c_parser_consume_token (parser
);
5698 c_parser_objc_methodproto (parser
);
5703 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
5705 c_parser_declaration_or_fndef (parser
, false, true, false, true);
5711 /* Parse an objc-methodproto.
5714 objc-method-type objc-method-decl ;
5718 c_parser_objc_methodproto (c_parser
*parser
)
5720 enum tree_code type
= c_parser_objc_method_type (parser
);
5722 objc_set_method_type (type
);
5723 /* Remember protocol qualifiers in prototypes. */
5724 objc_pq_context
= 1;
5725 decl
= c_parser_objc_method_decl (parser
);
5726 /* Forget protocol qualifiers here. */
5727 objc_pq_context
= 0;
5728 objc_add_method_declaration (decl
);
5729 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5732 /* Parse an objc-method-decl.
5735 ( objc-type-name ) objc-selector
5737 ( objc-type-name ) objc-keyword-selector objc-optparmlist
5738 objc-keyword-selector objc-optparmlist
5740 objc-keyword-selector:
5742 objc-keyword-selector objc-keyword-decl
5745 objc-selector : ( objc-type-name ) identifier
5746 objc-selector : identifier
5747 : ( objc-type-name ) identifier
5751 objc-optparms objc-optellipsis
5755 objc-opt-parms , parameter-declaration
5763 c_parser_objc_method_decl (c_parser
*parser
)
5765 tree type
= NULL_TREE
;
5767 tree parms
= NULL_TREE
;
5768 bool ellipsis
= false;
5770 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5772 c_parser_consume_token (parser
);
5773 type
= c_parser_objc_type_name (parser
);
5774 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5776 sel
= c_parser_objc_selector (parser
);
5777 /* If there is no selector, or a colon follows, we have an
5778 objc-keyword-selector. If there is a selector, and a colon does
5779 not follow, that selector ends the objc-method-decl. */
5780 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
5783 tree list
= NULL_TREE
;
5786 tree atype
= NULL_TREE
, id
, keyworddecl
;
5787 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5789 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5791 c_parser_consume_token (parser
);
5792 atype
= c_parser_objc_type_name (parser
);
5793 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5796 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5798 c_parser_error (parser
, "expected identifier");
5799 return error_mark_node
;
5801 id
= c_parser_peek_token (parser
)->value
;
5802 c_parser_consume_token (parser
);
5803 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
5804 list
= chainon (list
, keyworddecl
);
5805 tsel
= c_parser_objc_selector (parser
);
5806 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
5809 /* Parse the optional parameter list. Optional Objective-C
5810 method parameters follow the C syntax, and may include '...'
5811 to denote a variable number of arguments. */
5812 parms
= make_node (TREE_LIST
);
5813 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5815 struct c_parm
*parm
;
5816 c_parser_consume_token (parser
);
5817 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5820 c_parser_consume_token (parser
);
5823 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5826 parms
= chainon (parms
,
5827 build_tree_list (NULL_TREE
, grokparm (parm
)));
5831 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
5834 /* Parse an objc-type-name.
5837 objc-type-qualifiers[opt] type-name
5838 objc-type-qualifiers[opt]
5840 objc-type-qualifiers:
5842 objc-type-qualifiers objc-type-qualifier
5844 objc-type-qualifier: one of
5845 in out inout bycopy byref oneway
5849 c_parser_objc_type_name (c_parser
*parser
)
5851 tree quals
= NULL_TREE
;
5852 struct c_type_name
*typename
= NULL
;
5853 tree type
= NULL_TREE
;
5856 c_token
*token
= c_parser_peek_token (parser
);
5857 if (token
->type
== CPP_KEYWORD
5858 && (token
->keyword
== RID_IN
5859 || token
->keyword
== RID_OUT
5860 || token
->keyword
== RID_INOUT
5861 || token
->keyword
== RID_BYCOPY
5862 || token
->keyword
== RID_BYREF
5863 || token
->keyword
== RID_ONEWAY
))
5865 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
5866 c_parser_consume_token (parser
);
5871 if (c_parser_next_token_starts_typename (parser
))
5872 typename
= c_parser_type_name (parser
);
5874 type
= groktypename (typename
);
5875 return build_tree_list (quals
, type
);
5878 /* Parse objc-protocol-refs.
5885 c_parser_objc_protocol_refs (c_parser
*parser
)
5887 tree list
= NULL_TREE
;
5888 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
5889 c_parser_consume_token (parser
);
5890 /* Any identifiers, including those declared as type names, are OK
5895 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5897 c_parser_error (parser
, "expected identifier");
5900 id
= c_parser_peek_token (parser
)->value
;
5901 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5902 c_parser_consume_token (parser
);
5903 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5904 c_parser_consume_token (parser
);
5908 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
5912 /* Parse an objc-try-catch-statement.
5914 objc-try-catch-statement:
5915 @try compound-statement objc-catch-list[opt]
5916 @try compound-statement objc-catch-list[opt] @finally compound-statement
5919 @catch ( parameter-declaration ) compound-statement
5920 objc-catch-list @catch ( parameter-declaration ) compound-statement
5924 c_parser_objc_try_catch_statement (c_parser
*parser
)
5928 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
5929 c_parser_consume_token (parser
);
5930 loc
= c_parser_peek_token (parser
)->location
;
5931 stmt
= c_parser_compound_statement (parser
);
5932 objc_begin_try_stmt (loc
, stmt
);
5933 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
5935 struct c_parm
*parm
;
5936 c_parser_consume_token (parser
);
5937 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5939 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5945 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5946 objc_begin_catch_clause (grokparm (parm
));
5947 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
5948 c_parser_compound_statement_nostart (parser
);
5949 objc_finish_catch_clause ();
5951 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
5955 c_parser_consume_token (parser
);
5956 finloc
= c_parser_peek_token (parser
)->location
;
5957 finstmt
= c_parser_compound_statement (parser
);
5958 objc_build_finally_clause (finloc
, finstmt
);
5960 objc_finish_try_stmt ();
5963 /* Parse an objc-synchronized-statement.
5965 objc-synchronized-statement:
5966 @synchronized ( expression ) compound-statement
5970 c_parser_objc_synchronized_statement (c_parser
*parser
)
5974 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
5975 c_parser_consume_token (parser
);
5976 loc
= c_parser_peek_token (parser
)->location
;
5977 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5979 expr
= c_parser_expression (parser
).value
;
5980 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5983 expr
= error_mark_node
;
5984 stmt
= c_parser_compound_statement (parser
);
5985 objc_build_synchronized (loc
, expr
, stmt
);
5988 /* Parse an objc-selector; return NULL_TREE without an error if the
5989 next token is not an objc-selector.
5994 enum struct union if else while do for switch case default
5995 break continue return goto asm sizeof typeof __alignof
5996 unsigned long const short volatile signed restrict _Complex
5997 in out inout bycopy byref oneway int char float double void _Bool
5999 ??? Why this selection of keywords but not, for example, storage
6000 class specifiers? */
6003 c_parser_objc_selector (c_parser
*parser
)
6005 c_token
*token
= c_parser_peek_token (parser
);
6006 tree value
= token
->value
;
6007 if (token
->type
== CPP_NAME
)
6009 c_parser_consume_token (parser
);
6012 if (token
->type
!= CPP_KEYWORD
)
6014 switch (token
->keyword
)
6055 c_parser_consume_token (parser
);
6062 /* Parse an objc-selector-arg.
6066 objc-keywordname-list
6068 objc-keywordname-list:
6070 objc-keywordname-list objc-keywordname
6078 c_parser_objc_selector_arg (c_parser
*parser
)
6080 tree sel
= c_parser_objc_selector (parser
);
6081 tree list
= NULL_TREE
;
6082 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6086 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6088 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6089 sel
= c_parser_objc_selector (parser
);
6090 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6096 /* Parse an objc-receiver.
6105 c_parser_objc_receiver (c_parser
*parser
)
6107 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6108 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6109 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6111 tree id
= c_parser_peek_token (parser
)->value
;
6112 c_parser_consume_token (parser
);
6113 return objc_get_class_reference (id
);
6115 return c_parser_expression (parser
).value
;
6118 /* Parse objc-message-args.
6122 objc-keywordarg-list
6124 objc-keywordarg-list:
6126 objc-keywordarg-list objc-keywordarg
6129 objc-selector : objc-keywordexpr
6134 c_parser_objc_message_args (c_parser
*parser
)
6136 tree sel
= c_parser_objc_selector (parser
);
6137 tree list
= NULL_TREE
;
6138 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6143 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6145 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6146 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6147 sel
= c_parser_objc_selector (parser
);
6148 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6154 /* Parse an objc-keywordexpr.
6161 c_parser_objc_keywordexpr (c_parser
*parser
)
6163 tree list
= c_parser_expr_list (parser
);
6164 if (TREE_CHAIN (list
) == NULL_TREE
)
6166 /* Just return the expression, remove a level of
6168 return TREE_VALUE (list
);
6172 /* We have a comma expression, we will collapse later. */
6178 /* The actual parser and external interface. ??? Does this need to be
6179 garbage-collected? */
6181 static GTY (()) c_parser
*the_parser
;
6183 /* Parse a single source file. */
6188 the_parser
= c_parser_new ();
6189 c_parser_translation_unit (the_parser
);
6193 #include "gt-c-parser.h"