1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 Parser actions based on the old Bison parser; structure somewhat
6 influenced by and fragments based on the C++ parser.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
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 { "_Decimal32", RID_DFLOAT32
, D_EXT
},
97 { "_Decimal64", RID_DFLOAT64
, D_EXT
},
98 { "_Decimal128", RID_DFLOAT128
, D_EXT
},
99 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
100 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
101 { "__alignof", RID_ALIGNOF
, 0 },
102 { "__alignof__", RID_ALIGNOF
, 0 },
103 { "__asm", RID_ASM
, 0 },
104 { "__asm__", RID_ASM
, 0 },
105 { "__attribute", RID_ATTRIBUTE
, 0 },
106 { "__attribute__", RID_ATTRIBUTE
, 0 },
107 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
108 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
109 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
110 { "__builtin_va_arg", RID_VA_ARG
, 0 },
111 { "__complex", RID_COMPLEX
, 0 },
112 { "__complex__", RID_COMPLEX
, 0 },
113 { "__const", RID_CONST
, 0 },
114 { "__const__", RID_CONST
, 0 },
115 { "__extension__", RID_EXTENSION
, 0 },
116 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
117 { "__imag", RID_IMAGPART
, 0 },
118 { "__imag__", RID_IMAGPART
, 0 },
119 { "__inline", RID_INLINE
, 0 },
120 { "__inline__", RID_INLINE
, 0 },
121 { "__label__", RID_LABEL
, 0 },
122 { "__real", RID_REALPART
, 0 },
123 { "__real__", RID_REALPART
, 0 },
124 { "__restrict", RID_RESTRICT
, 0 },
125 { "__restrict__", RID_RESTRICT
, 0 },
126 { "__signed", RID_SIGNED
, 0 },
127 { "__signed__", RID_SIGNED
, 0 },
128 { "__thread", RID_THREAD
, 0 },
129 { "__typeof", RID_TYPEOF
, 0 },
130 { "__typeof__", RID_TYPEOF
, 0 },
131 { "__volatile", RID_VOLATILE
, 0 },
132 { "__volatile__", RID_VOLATILE
, 0 },
133 { "asm", RID_ASM
, D_EXT
},
134 { "auto", RID_AUTO
, 0 },
135 { "break", RID_BREAK
, 0 },
136 { "case", RID_CASE
, 0 },
137 { "char", RID_CHAR
, 0 },
138 { "const", RID_CONST
, 0 },
139 { "continue", RID_CONTINUE
, 0 },
140 { "default", RID_DEFAULT
, 0 },
142 { "double", RID_DOUBLE
, 0 },
143 { "else", RID_ELSE
, 0 },
144 { "enum", RID_ENUM
, 0 },
145 { "extern", RID_EXTERN
, 0 },
146 { "float", RID_FLOAT
, 0 },
147 { "for", RID_FOR
, 0 },
148 { "goto", RID_GOTO
, 0 },
150 { "inline", RID_INLINE
, D_EXT89
},
151 { "int", RID_INT
, 0 },
152 { "long", RID_LONG
, 0 },
153 { "register", RID_REGISTER
, 0 },
154 { "restrict", RID_RESTRICT
, D_C89
},
155 { "return", RID_RETURN
, 0 },
156 { "short", RID_SHORT
, 0 },
157 { "signed", RID_SIGNED
, 0 },
158 { "sizeof", RID_SIZEOF
, 0 },
159 { "static", RID_STATIC
, 0 },
160 { "struct", RID_STRUCT
, 0 },
161 { "switch", RID_SWITCH
, 0 },
162 { "typedef", RID_TYPEDEF
, 0 },
163 { "typeof", RID_TYPEOF
, D_EXT
},
164 { "union", RID_UNION
, 0 },
165 { "unsigned", RID_UNSIGNED
, 0 },
166 { "void", RID_VOID
, 0 },
167 { "volatile", RID_VOLATILE
, 0 },
168 { "while", RID_WHILE
, 0 },
169 /* These Objective-C keywords are recognized only immediately after
171 { "class", RID_AT_CLASS
, D_OBJC
},
172 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
173 { "defs", RID_AT_DEFS
, D_OBJC
},
174 { "encode", RID_AT_ENCODE
, D_OBJC
},
175 { "end", RID_AT_END
, D_OBJC
},
176 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
177 { "interface", RID_AT_INTERFACE
, D_OBJC
},
178 { "private", RID_AT_PRIVATE
, D_OBJC
},
179 { "protected", RID_AT_PROTECTED
, D_OBJC
},
180 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
181 { "public", RID_AT_PUBLIC
, D_OBJC
},
182 { "selector", RID_AT_SELECTOR
, D_OBJC
},
183 { "throw", RID_AT_THROW
, D_OBJC
},
184 { "try", RID_AT_TRY
, D_OBJC
},
185 { "catch", RID_AT_CATCH
, D_OBJC
},
186 { "finally", RID_AT_FINALLY
, D_OBJC
},
187 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
188 /* These are recognized only in protocol-qualifier context
190 { "bycopy", RID_BYCOPY
, D_OBJC
},
191 { "byref", RID_BYREF
, D_OBJC
},
192 { "in", RID_IN
, D_OBJC
},
193 { "inout", RID_INOUT
, D_OBJC
},
194 { "oneway", RID_ONEWAY
, D_OBJC
},
195 { "out", RID_OUT
, D_OBJC
},
197 #define N_reswords (sizeof reswords / sizeof (struct resword))
199 /* Initialization routine for this file. */
204 /* The only initialization required is of the reserved word
208 int mask
= (flag_isoc99
? 0 : D_C89
)
209 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
211 if (!c_dialect_objc ())
214 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
215 for (i
= 0; i
< N_reswords
; i
++)
217 /* If a keyword is disabled, do not enter it into the table
218 and so create a canonical spelling that isn't a keyword. */
219 if (reswords
[i
].disable
& mask
)
222 id
= get_identifier (reswords
[i
].word
);
223 C_RID_CODE (id
) = reswords
[i
].rid
;
224 C_IS_RESERVED_WORD (id
) = 1;
225 ridpointers
[(int) reswords
[i
].rid
] = id
;
229 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
230 and the C parser. Unlike the C++ lexer, the parser structure
231 stores the lexer information instead of using a separate structure.
232 Identifiers are separated into ordinary identifiers, type names,
233 keywords and some other Objective-C types of identifiers, and some
234 look-ahead is maintained.
236 ??? It might be a good idea to lex the whole file up front (as for
237 C++). It would then be possible to share more of the C and C++
238 lexer code, if desired. */
240 /* The following local token type is used. */
243 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
245 /* More information about the type of a CPP_NAME token. */
246 typedef enum c_id_kind
{
247 /* An ordinary identifier. */
249 /* An identifier declared as a typedef name. */
251 /* An identifier declared as an Objective-C class name. */
253 /* Not an identifier. */
257 /* A single C token after string literal concatenation and conversion
258 of preprocessing tokens to tokens. */
259 typedef struct c_token
GTY (())
261 /* The kind of token. */
262 ENUM_BITFIELD (cpp_ttype
) type
: 8;
263 /* If this token is a CPP_NAME, this value indicates whether also
264 declared as some kind of type. Otherwise, it is C_ID_NONE. */
265 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
266 /* If this token is a keyword, this value indicates which keyword.
267 Otherwise, this value is RID_MAX. */
268 ENUM_BITFIELD (rid
) keyword
: 8;
269 /* True if this token is from a system header. */
270 BOOL_BITFIELD in_system_header
: 1;
271 /* The value associated with this token, if any. */
273 /* The location at which this token was found. */
277 /* A parser structure recording information about the state and
278 context of parsing. Includes lexer information with up to two
279 tokens of look-ahead; more are not needed for C. */
280 typedef struct c_parser
GTY(())
282 /* The look-ahead tokens. */
284 /* How many look-ahead tokens are available (0, 1 or 2). */
286 /* True if a syntax error is being recovered from; false otherwise.
287 c_parser_error sets this flag. It should clear this flag when
288 enough tokens have been consumed to recover from the error. */
289 BOOL_BITFIELD error
: 1;
292 /* Read in and lex a single token, storing it in *TOKEN. */
295 c_lex_one_token (c_token
*token
)
297 timevar_push (TV_LEX
);
298 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
);
299 token
->in_system_header
= in_system_header
;
303 token
->id_kind
= C_ID_NONE
;
304 token
->keyword
= RID_MAX
;
308 int objc_force_identifier
= objc_need_raw_identifier
;
309 OBJC_NEED_RAW_IDENTIFIER (0);
311 if (C_IS_RESERVED_WORD (token
->value
))
313 enum rid rid_code
= C_RID_CODE (token
->value
);
315 if (c_dialect_objc ())
317 if (!OBJC_IS_AT_KEYWORD (rid_code
)
318 && (!OBJC_IS_PQ_KEYWORD (rid_code
) || objc_pq_context
))
320 /* Return the canonical spelling for this keyword. */
321 token
->value
= ridpointers
[(int) rid_code
];
322 token
->type
= CPP_KEYWORD
;
323 token
->keyword
= rid_code
;
329 /* Return the canonical spelling for this keyword. */
330 token
->value
= ridpointers
[(int) rid_code
];
331 token
->type
= CPP_KEYWORD
;
332 token
->keyword
= rid_code
;
337 decl
= lookup_name (token
->value
);
340 if (TREE_CODE (decl
) == TYPE_DECL
)
342 token
->id_kind
= C_ID_TYPENAME
;
346 else if (c_dialect_objc ())
348 tree objc_interface_decl
= objc_is_class_name (token
->value
);
349 /* Objective-C class names are in the same namespace as
350 variables and typedefs, and hence are shadowed by local
352 if (objc_interface_decl
353 && (global_bindings_p ()
354 || (!objc_force_identifier
&& !decl
)))
356 token
->value
= objc_interface_decl
;
357 token
->id_kind
= C_ID_CLASSNAME
;
362 token
->id_kind
= C_ID_ID
;
365 /* This only happens in Objective-C; it must be a keyword. */
366 token
->type
= CPP_KEYWORD
;
367 token
->id_kind
= C_ID_NONE
;
368 token
->keyword
= C_RID_CODE (token
->value
);
372 case CPP_CLOSE_PAREN
:
374 /* These tokens may affect the interpretation of any identifiers
375 following, if doing Objective-C. */
376 OBJC_NEED_RAW_IDENTIFIER (0);
377 token
->id_kind
= C_ID_NONE
;
378 token
->keyword
= RID_MAX
;
381 token
->id_kind
= C_ID_NONE
;
382 token
->keyword
= RID_MAX
;
385 timevar_pop (TV_LEX
);
388 /* Return a pointer to the next token from PARSER, reading it in if
391 static inline c_token
*
392 c_parser_peek_token (c_parser
*parser
)
394 if (parser
->tokens_avail
== 0)
396 c_lex_one_token (&parser
->tokens
[0]);
397 parser
->tokens_avail
= 1;
399 return &parser
->tokens
[0];
402 /* Return true if the next token from PARSER has the indicated
406 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
408 return c_parser_peek_token (parser
)->type
== type
;
411 /* Return true if the next token from PARSER does not have the
415 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
417 return !c_parser_next_token_is (parser
, type
);
420 /* Return true if the next token from PARSER is the indicated
424 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
428 /* Peek at the next token. */
429 token
= c_parser_peek_token (parser
);
430 /* Check to see if it is the indicated keyword. */
431 return token
->keyword
== keyword
;
434 /* Return true if TOKEN can start a type name,
437 c_token_starts_typename (c_token
*token
)
442 switch (token
->id_kind
)
449 gcc_assert (c_dialect_objc ());
455 switch (token
->keyword
)
484 if (c_dialect_objc ())
492 /* Return true if the next token from PARSER can start a type name,
495 c_parser_next_token_starts_typename (c_parser
*parser
)
497 c_token
*token
= c_parser_peek_token (parser
);
498 return c_token_starts_typename (token
);
501 /* Return true if TOKEN can start declaration specifiers, false
504 c_token_starts_declspecs (c_token
*token
)
509 switch (token
->id_kind
)
516 gcc_assert (c_dialect_objc ());
522 switch (token
->keyword
)
558 if (c_dialect_objc ())
566 /* Return true if the next token from PARSER can start declaration
567 specifiers, false otherwise. */
569 c_parser_next_token_starts_declspecs (c_parser
*parser
)
571 c_token
*token
= c_parser_peek_token (parser
);
572 return c_token_starts_declspecs (token
);
575 /* Return a pointer to the next-but-one token from PARSER, reading it
576 in if necessary. The next token is already read in. */
579 c_parser_peek_2nd_token (c_parser
*parser
)
581 if (parser
->tokens_avail
>= 2)
582 return &parser
->tokens
[1];
583 gcc_assert (parser
->tokens_avail
== 1);
584 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
585 c_lex_one_token (&parser
->tokens
[1]);
586 parser
->tokens_avail
= 2;
587 return &parser
->tokens
[1];
590 /* Consume the next token from PARSER. */
593 c_parser_consume_token (c_parser
*parser
)
595 if (parser
->tokens_avail
== 2)
596 parser
->tokens
[0] = parser
->tokens
[1];
599 gcc_assert (parser
->tokens_avail
== 1);
600 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
602 parser
->tokens_avail
--;
605 /* Update the globals input_location and in_system_header from
608 c_parser_set_source_position_from_token (c_token
*token
)
610 if (token
->type
!= CPP_EOF
)
612 input_location
= token
->location
;
613 in_system_header
= token
->in_system_header
;
617 /* Allocate a new parser. */
622 /* Use local storage to lex the first token because loading a PCH
623 file may cause garbage collection. */
626 memset (&tparser
, 0, sizeof tparser
);
627 c_lex_one_token (&tparser
.tokens
[0]);
628 tparser
.tokens_avail
= 1;
629 ret
= GGC_NEW (c_parser
);
630 memcpy (ret
, &tparser
, sizeof tparser
);
634 /* Issue a diagnostic of the form
635 FILE:LINE: MESSAGE before TOKEN
636 where TOKEN is the next token in the input stream of PARSER.
637 MESSAGE (specified by the caller) is usually of the form "expected
640 Do not issue a diagnostic if still recovering from an error.
642 ??? This is taken from the C++ parser, but building up messages in
643 this way is not i18n-friendly and some other approach should be
647 c_parser_error (c_parser
*parser
, const char *gmsgid
)
649 c_token
*token
= c_parser_peek_token (parser
);
652 parser
->error
= true;
655 /* This diagnostic makes more sense if it is tagged to the line of
656 the token we just peeked at. */
657 c_parser_set_source_position_from_token (token
);
658 c_parse_error (gmsgid
,
659 /* Because c_parse_error does not understand
660 CPP_KEYWORD, keywords are treated like
662 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
666 /* If the next token is of the indicated TYPE, consume it. Otherwise,
667 issue the error MSGID. If MSGID is NULL then a message has already
668 been produced and no message will be produced this time. Returns
669 true if found, false otherwise. */
672 c_parser_require (c_parser
*parser
,
676 if (c_parser_next_token_is (parser
, type
))
678 c_parser_consume_token (parser
);
683 c_parser_error (parser
, msgid
);
688 /* If the next token is the indicated keyword, consume it. Otherwise,
689 issue the error MSGID. Returns true if found, false otherwise. */
692 c_parser_require_keyword (c_parser
*parser
,
696 if (c_parser_next_token_is_keyword (parser
, keyword
))
698 c_parser_consume_token (parser
);
703 c_parser_error (parser
, msgid
);
708 /* Like c_parser_require, except that tokens will be skipped until the
709 desired token is found. An error message is still produced if the
710 next token is not as expected. If MSGID is NULL then a message has
711 already been produced and no message will be produced this
715 c_parser_skip_until_found (c_parser
*parser
,
719 unsigned nesting_depth
= 0;
721 if (c_parser_require (parser
, type
, msgid
))
724 /* Skip tokens until the desired token is found. */
727 /* Peek at the next token. */
728 c_token
*token
= c_parser_peek_token (parser
);
729 /* If we've reached the token we want, consume it and stop. */
730 if (token
->type
== type
&& !nesting_depth
)
732 c_parser_consume_token (parser
);
735 /* If we've run out of tokens, stop. */
736 if (token
->type
== CPP_EOF
)
738 if (token
->type
== CPP_OPEN_BRACE
739 || token
->type
== CPP_OPEN_PAREN
740 || token
->type
== CPP_OPEN_SQUARE
)
742 else if (token
->type
== CPP_CLOSE_BRACE
743 || token
->type
== CPP_CLOSE_PAREN
744 || token
->type
== CPP_CLOSE_SQUARE
)
746 if (nesting_depth
-- == 0)
749 /* Consume this token. */
750 c_parser_consume_token (parser
);
752 parser
->error
= false;
755 /* Skip tokens until the end of a parameter is found, but do not
756 consume the comma, semicolon or closing delimiter. */
759 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
761 unsigned nesting_depth
= 0;
765 c_token
*token
= c_parser_peek_token (parser
);
766 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
769 /* If we've run out of tokens, stop. */
770 if (token
->type
== CPP_EOF
)
772 if (token
->type
== CPP_OPEN_BRACE
773 || token
->type
== CPP_OPEN_PAREN
774 || token
->type
== CPP_OPEN_SQUARE
)
776 else if (token
->type
== CPP_CLOSE_BRACE
777 || token
->type
== CPP_CLOSE_PAREN
778 || token
->type
== CPP_CLOSE_SQUARE
)
780 if (nesting_depth
-- == 0)
783 /* Consume this token. */
784 c_parser_consume_token (parser
);
786 parser
->error
= false;
789 /* Skip tokens until we have consumed an entire block, or until we
790 have consumed a non-nested ';'. */
793 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
795 unsigned nesting_depth
= 0;
801 /* Peek at the next token. */
802 token
= c_parser_peek_token (parser
);
803 /* If we've run out of tokens, stop. */
804 if (token
->type
== CPP_EOF
)
806 /* If the next token is a ';', we have reached the end of the
808 if (token
->type
== CPP_SEMICOLON
&& !nesting_depth
)
810 /* Consume the ';'. */
811 c_parser_consume_token (parser
);
814 /* If the next token is a non-nested '}', then we have reached
815 the end of the current block. */
816 if (token
->type
== CPP_CLOSE_BRACE
817 && (nesting_depth
== 0 || --nesting_depth
== 0))
819 c_parser_consume_token (parser
);
822 /* If it the next token is a '{', then we are entering a new
823 block. Consume the entire block. */
824 if (token
->type
== CPP_OPEN_BRACE
)
826 c_parser_consume_token (parser
);
828 parser
->error
= false;
832 /* Save the warning flags which are controlled by __extension__. */
835 disable_extension_diagnostics (void)
838 | (warn_pointer_arith
<< 1)
839 | (warn_traditional
<< 2)
842 warn_pointer_arith
= 0;
843 warn_traditional
= 0;
848 /* Restore the warning flags which are controlled by __extension__.
849 FLAGS is the return value from disable_extension_diagnostics. */
852 restore_extension_diagnostics (int flags
)
854 pedantic
= flags
& 1;
855 warn_pointer_arith
= (flags
>> 1) & 1;
856 warn_traditional
= (flags
>> 2) & 1;
857 flag_iso
= (flags
>> 3) & 1;
860 /* Possibly kinds of declarator to parse. */
861 typedef enum c_dtr_syn
{
862 /* A normal declarator with an identifier. */
864 /* An abstract declarator (maybe empty). */
866 /* A parameter declarator: may be either, but after a type name does
867 not redeclare a typedef name as an identifier if it can
868 alternatively be interpreted as a typedef name; see DR#009,
869 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
870 following DR#249. For example, given a typedef T, "int T" and
871 "int *T" are valid parameter declarations redeclaring T, while
872 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
873 abstract declarators rather than involving redundant parentheses;
874 the same applies with attributes inside the parentheses before
879 static void c_parser_external_declaration (c_parser
*);
880 static void c_parser_asm_definition (c_parser
*);
881 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
882 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
884 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
885 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
886 static tree
c_parser_struct_declaration (c_parser
*);
887 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
888 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
890 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
892 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
894 struct c_declarator
*);
895 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
896 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
897 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
898 static tree
c_parser_simple_asm_expr (c_parser
*);
899 static tree
c_parser_attributes (c_parser
*);
900 static struct c_type_name
*c_parser_type_name (c_parser
*);
901 static struct c_expr
c_parser_initializer (c_parser
*);
902 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
903 static void c_parser_initelt (c_parser
*);
904 static void c_parser_initval (c_parser
*, struct c_expr
*);
905 static tree
c_parser_compound_statement (c_parser
*);
906 static void c_parser_compound_statement_nostart (c_parser
*);
907 static void c_parser_label (c_parser
*);
908 static void c_parser_statement (c_parser
*);
909 static void c_parser_statement_after_labels (c_parser
*);
910 static void c_parser_if_statement (c_parser
*);
911 static void c_parser_switch_statement (c_parser
*);
912 static void c_parser_while_statement (c_parser
*);
913 static void c_parser_do_statement (c_parser
*);
914 static void c_parser_for_statement (c_parser
*);
915 static tree
c_parser_asm_statement (c_parser
*);
916 static tree
c_parser_asm_operands (c_parser
*, bool);
917 static tree
c_parser_asm_clobbers (c_parser
*);
918 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
919 static struct c_expr
c_parser_conditional_expression (c_parser
*,
921 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
922 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
923 static struct c_expr
c_parser_unary_expression (c_parser
*);
924 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
925 static struct c_expr
c_parser_alignof_expression (c_parser
*);
926 static struct c_expr
c_parser_postfix_expression (c_parser
*);
927 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
928 struct c_type_name
*);
929 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
931 static struct c_expr
c_parser_expression (c_parser
*);
932 static struct c_expr
c_parser_expression_conv (c_parser
*);
933 static tree
c_parser_expr_list (c_parser
*, bool);
935 /* These Objective-C parser functions are only ever called when
936 compiling Objective-C. */
937 static void c_parser_objc_class_definition (c_parser
*);
938 static void c_parser_objc_class_instance_variables (c_parser
*);
939 static void c_parser_objc_class_declaration (c_parser
*);
940 static void c_parser_objc_alias_declaration (c_parser
*);
941 static void c_parser_objc_protocol_definition (c_parser
*);
942 static enum tree_code
c_parser_objc_method_type (c_parser
*);
943 static void c_parser_objc_method_definition (c_parser
*);
944 static void c_parser_objc_methodprotolist (c_parser
*);
945 static void c_parser_objc_methodproto (c_parser
*);
946 static tree
c_parser_objc_method_decl (c_parser
*);
947 static tree
c_parser_objc_type_name (c_parser
*);
948 static tree
c_parser_objc_protocol_refs (c_parser
*);
949 static void c_parser_objc_try_catch_statement (c_parser
*);
950 static void c_parser_objc_synchronized_statement (c_parser
*);
951 static tree
c_parser_objc_selector (c_parser
*);
952 static tree
c_parser_objc_selector_arg (c_parser
*);
953 static tree
c_parser_objc_receiver (c_parser
*);
954 static tree
c_parser_objc_message_args (c_parser
*);
955 static tree
c_parser_objc_keywordexpr (c_parser
*);
957 /* Parse a translation unit (C90 6.7, C99 6.9).
960 external-declarations
962 external-declarations:
964 external-declarations external-declaration
973 c_parser_translation_unit (c_parser
*parser
)
975 if (c_parser_next_token_is (parser
, CPP_EOF
))
978 pedwarn ("ISO C forbids an empty source file");
982 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
986 c_parser_external_declaration (parser
);
987 obstack_free (&parser_obstack
, obstack_position
);
989 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
993 /* Parse an external declaration (C90 6.7, C99 6.9).
995 external-declaration:
1001 external-declaration:
1004 __extension__ external-declaration
1008 external-declaration:
1009 objc-class-definition
1010 objc-class-declaration
1011 objc-alias-declaration
1012 objc-protocol-definition
1013 objc-method-definition
1018 c_parser_external_declaration (c_parser
*parser
)
1021 switch (c_parser_peek_token (parser
)->type
)
1024 switch (c_parser_peek_token (parser
)->keyword
)
1027 ext
= disable_extension_diagnostics ();
1028 c_parser_consume_token (parser
);
1029 c_parser_external_declaration (parser
);
1030 restore_extension_diagnostics (ext
);
1033 c_parser_asm_definition (parser
);
1035 case RID_AT_INTERFACE
:
1036 case RID_AT_IMPLEMENTATION
:
1037 gcc_assert (c_dialect_objc ());
1038 c_parser_objc_class_definition (parser
);
1041 gcc_assert (c_dialect_objc ());
1042 c_parser_objc_class_declaration (parser
);
1045 gcc_assert (c_dialect_objc ());
1046 c_parser_objc_alias_declaration (parser
);
1048 case RID_AT_PROTOCOL
:
1049 gcc_assert (c_dialect_objc ());
1050 c_parser_objc_protocol_definition (parser
);
1053 gcc_assert (c_dialect_objc ());
1054 c_parser_consume_token (parser
);
1055 objc_finish_implementation ();
1063 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1064 c_parser_consume_token (parser
);
1068 if (c_dialect_objc ())
1070 c_parser_objc_method_definition (parser
);
1073 /* Else fall through, and yield a syntax error trying to parse
1074 as a declaration or function definition. */
1077 /* A declaration or a function definition. We can only tell
1078 which after parsing the declaration specifiers, if any, and
1079 the first declarator. */
1080 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1085 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1086 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1087 accepted; otherwise (old-style parameter declarations) only other
1088 declarations are accepted. If NESTED is true, we are inside a
1089 function or parsing old-style parameter declarations; any functions
1090 encountered are nested functions and declaration specifiers are
1091 required; otherwise we are at top level and functions are normal
1092 functions and declaration specifiers may be optional. If EMPTY_OK
1093 is true, empty declarations are OK (subject to all other
1094 constraints); otherwise (old-style parameter declarations) they are
1095 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1096 may start with attributes; otherwise they may not.
1099 declaration-specifiers init-declarator-list[opt] ;
1101 function-definition:
1102 declaration-specifiers[opt] declarator declaration-list[opt]
1107 declaration-list declaration
1109 init-declarator-list:
1111 init-declarator-list , init-declarator
1114 declarator simple-asm-expr[opt] attributes[opt]
1115 declarator simple-asm-expr[opt] attributes[opt] = initializer
1119 nested-function-definition:
1120 declaration-specifiers declarator declaration-list[opt]
1123 The simple-asm-expr and attributes are GNU extensions.
1125 This function does not handle __extension__; that is handled in its
1126 callers. ??? Following the old parser, __extension__ may start
1127 external declarations, declarations in functions and declarations
1128 at the start of "for" loops, but not old-style parameter
1131 C99 requires declaration specifiers in a function definition; the
1132 absence is diagnosed through the diagnosis of implicit int. In GNU
1133 C we also allow but diagnose declarations without declaration
1134 specifiers, but only at top level (elsewhere they conflict with
1138 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1139 bool nested
, bool start_attr_ok
)
1141 struct c_declspecs
*specs
;
1143 tree all_prefix_attrs
;
1144 bool diagnosed_no_specs
= false;
1145 specs
= build_null_declspecs ();
1146 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1149 c_parser_skip_to_end_of_block_or_statement (parser
);
1152 if (nested
&& !specs
->declspecs_seen_p
)
1154 c_parser_error (parser
, "expected declaration specifiers");
1155 c_parser_skip_to_end_of_block_or_statement (parser
);
1158 finish_declspecs (specs
);
1159 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1165 shadow_tag_warned (specs
, 1);
1166 pedwarn ("empty declaration");
1168 c_parser_consume_token (parser
);
1171 pending_xref_error ();
1172 prefix_attrs
= specs
->attrs
;
1173 all_prefix_attrs
= prefix_attrs
;
1174 specs
->attrs
= NULL_TREE
;
1177 struct c_declarator
*declarator
;
1180 /* Declaring either one or more declarators (in which case we
1181 should diagnose if there were no declaration specifiers) or a
1182 function definition (in which case the diagnostic for
1183 implicit int suffices). */
1184 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1185 C_DTR_NORMAL
, &dummy
);
1186 if (declarator
== NULL
)
1188 c_parser_skip_to_end_of_block_or_statement (parser
);
1191 if (c_parser_next_token_is (parser
, CPP_EQ
)
1192 || c_parser_next_token_is (parser
, CPP_COMMA
)
1193 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1194 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1195 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1197 tree asm_name
= NULL_TREE
;
1198 tree postfix_attrs
= NULL_TREE
;
1199 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1201 diagnosed_no_specs
= true;
1202 pedwarn ("data definition has no type or storage class");
1204 /* Having seen a data definition, there cannot now be a
1205 function definition. */
1207 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1208 asm_name
= c_parser_simple_asm_expr (parser
);
1209 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1210 postfix_attrs
= c_parser_attributes (parser
);
1211 if (c_parser_next_token_is (parser
, CPP_EQ
))
1215 c_parser_consume_token (parser
);
1216 /* The declaration of the variable is in effect while
1217 its initializer is parsed. */
1218 d
= start_decl (declarator
, specs
, true,
1219 chainon (postfix_attrs
, all_prefix_attrs
));
1221 d
= error_mark_node
;
1222 start_init (d
, asm_name
, global_bindings_p ());
1223 init
= c_parser_initializer (parser
);
1225 if (d
!= error_mark_node
)
1227 maybe_warn_string_init (TREE_TYPE (d
), init
);
1228 finish_decl (d
, init
.value
, asm_name
);
1233 tree d
= start_decl (declarator
, specs
, false,
1234 chainon (postfix_attrs
,
1237 finish_decl (d
, NULL_TREE
, asm_name
);
1239 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1241 c_parser_consume_token (parser
);
1242 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1243 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1246 all_prefix_attrs
= prefix_attrs
;
1249 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1251 c_parser_consume_token (parser
);
1256 c_parser_error (parser
, "expected %<,%> or %<;%>");
1257 c_parser_skip_to_end_of_block_or_statement (parser
);
1263 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1264 "%<asm%> or %<__attribute__%>");
1265 c_parser_skip_to_end_of_block_or_statement (parser
);
1268 /* Function definition (nested or otherwise). */
1272 pedwarn ("ISO C forbids nested functions");
1273 push_function_context ();
1275 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1277 /* This can appear in many cases looking nothing like a
1278 function definition, so we don't give a more specific
1279 error suggesting there was one. */
1280 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1281 "or %<__attribute__%>");
1283 pop_function_context ();
1286 /* Parse old-style parameter declarations. ??? Attributes are
1287 not allowed to start declaration specifiers here because of a
1288 syntax conflict between a function declaration with attribute
1289 suffix and a function definition with an attribute prefix on
1290 first old-style parameter declaration. Following the old
1291 parser, they are not accepted on subsequent old-style
1292 parameter declarations either. However, there is no
1293 ambiguity after the first declaration, nor indeed on the
1294 first as long as we don't allow postfix attributes after a
1295 declarator with a nonempty identifier list in a definition;
1296 and postfix attributes have never been accepted here in
1297 function definitions either. */
1298 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1299 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1300 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1301 DECL_SOURCE_LOCATION (current_function_decl
)
1302 = c_parser_peek_token (parser
)->location
;
1303 store_parm_decls ();
1304 fnbody
= c_parser_compound_statement (parser
);
1307 tree decl
= current_function_decl
;
1310 pop_function_context ();
1311 add_stmt (build_stmt (DECL_EXPR
, decl
));
1322 /* Parse an asm-definition (asm() outside a function body). This is a
1330 c_parser_asm_definition (c_parser
*parser
)
1332 tree asm_str
= c_parser_simple_asm_expr (parser
);
1333 /* ??? This only works sensibly in the presence of
1334 -fno-unit-at-a-time; file-scope asms really need to be passed to
1335 cgraph which needs to preserve the order of functions and
1338 assemble_asm (asm_str
);
1339 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1342 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1343 6.7), adding them to SPECS (which may already include some).
1344 Storage class specifiers are accepted iff SCSPEC_OK; type
1345 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1346 the start iff START_ATTR_OK.
1348 declaration-specifiers:
1349 storage-class-specifier declaration-specifiers[opt]
1350 type-specifier declaration-specifiers[opt]
1351 type-qualifier declaration-specifiers[opt]
1352 function-specifier declaration-specifiers[opt]
1354 Function specifiers (inline) are from C99, and are currently
1355 handled as storage class specifiers, as is __thread.
1357 C90 6.5.1, C99 6.7.1:
1358 storage-class-specifier:
1369 C90 6.5.2, C99 6.7.2:
1382 [_Imaginary removed in C99 TC2]
1383 struct-or-union-specifier
1387 (_Bool and _Complex are new in C99.)
1389 C90 6.5.3, C99 6.7.3:
1396 (restrict is new in C99.)
1400 declaration-specifiers:
1401 attributes declaration-specifiers[opt]
1403 storage-class-specifier:
1415 class-name objc-protocol-refs[opt]
1416 typedef-name objc-protocol-refs
1421 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1422 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1424 bool attrs_ok
= start_attr_ok
;
1425 bool seen_type
= specs
->type_seen_p
;
1426 while (c_parser_next_token_is (parser
, CPP_NAME
)
1427 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1428 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1430 struct c_typespec t
;
1432 if (c_parser_next_token_is (parser
, CPP_NAME
))
1434 tree value
= c_parser_peek_token (parser
)->value
;
1435 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1436 /* This finishes the specifiers unless a type name is OK, it
1437 is declared as a type name and a type name hasn't yet
1439 if (!typespec_ok
|| seen_type
1440 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1442 c_parser_consume_token (parser
);
1445 if (kind
== C_ID_TYPENAME
1446 && (!c_dialect_objc ()
1447 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1449 t
.kind
= ctsk_typedef
;
1450 /* For a typedef name, record the meaning, not the name.
1451 In case of 'foo foo, bar;'. */
1452 t
.spec
= lookup_name (value
);
1456 tree proto
= NULL_TREE
;
1457 gcc_assert (c_dialect_objc ());
1459 if (c_parser_next_token_is (parser
, CPP_LESS
))
1460 proto
= c_parser_objc_protocol_refs (parser
);
1461 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1463 declspecs_add_type (specs
, t
);
1466 if (c_parser_next_token_is (parser
, CPP_LESS
))
1468 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1469 nisse@lysator.liu.se. */
1471 gcc_assert (c_dialect_objc ());
1472 if (!typespec_ok
|| seen_type
)
1474 proto
= c_parser_objc_protocol_refs (parser
);
1476 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1477 declspecs_add_type (specs
, t
);
1480 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1481 switch (c_parser_peek_token (parser
)->keyword
)
1493 /* TODO: Distinguish between function specifiers (inline)
1494 and storage class specifiers, either here or in
1495 declspecs_add_scspec. */
1496 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1497 c_parser_consume_token (parser
);
1517 OBJC_NEED_RAW_IDENTIFIER (1);
1518 t
.kind
= ctsk_resword
;
1519 t
.spec
= c_parser_peek_token (parser
)->value
;
1520 declspecs_add_type (specs
, t
);
1521 c_parser_consume_token (parser
);
1528 t
= c_parser_enum_specifier (parser
);
1529 declspecs_add_type (specs
, t
);
1537 t
= c_parser_struct_or_union_specifier (parser
);
1538 declspecs_add_type (specs
, t
);
1541 /* ??? The old parser rejected typeof after other type
1542 specifiers, but is a syntax error the best way of
1544 if (!typespec_ok
|| seen_type
)
1548 t
= c_parser_typeof_specifier (parser
);
1549 declspecs_add_type (specs
, t
);
1555 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1556 c_parser_consume_token (parser
);
1561 attrs
= c_parser_attributes (parser
);
1562 declspecs_add_attrs (specs
, attrs
);
1571 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1574 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1575 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1576 enum attributes[opt] identifier
1578 The form with trailing comma is new in C99. The forms with
1579 attributes are GNU extensions. In GNU C, we accept any expression
1580 without commas in the syntax (assignment expressions, not just
1581 conditional expressions); assignment expressions will be diagnosed
1586 enumerator-list , enumerator
1589 enumeration-constant
1590 enumeration-constant = constant-expression
1593 static struct c_typespec
1594 c_parser_enum_specifier (c_parser
*parser
)
1596 struct c_typespec ret
;
1598 tree ident
= NULL_TREE
;
1599 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1600 c_parser_consume_token (parser
);
1601 attrs
= c_parser_attributes (parser
);
1602 if (c_parser_next_token_is (parser
, CPP_NAME
))
1604 ident
= c_parser_peek_token (parser
)->value
;
1605 c_parser_consume_token (parser
);
1607 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1609 /* Parse an enum definition. */
1610 tree type
= start_enum (ident
);
1612 /* We chain the enumerators in reverse order, then put them in
1613 forward order at the end. */
1614 tree values
= NULL_TREE
;
1615 c_parser_consume_token (parser
);
1622 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1624 c_parser_error (parser
, "expected identifier");
1625 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1626 values
= error_mark_node
;
1629 enum_id
= c_parser_peek_token (parser
)->value
;
1630 c_parser_consume_token (parser
);
1631 if (c_parser_next_token_is (parser
, CPP_EQ
))
1633 c_parser_consume_token (parser
);
1634 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1637 enum_value
= NULL_TREE
;
1638 enum_decl
= build_enumerator (enum_id
, enum_value
);
1639 TREE_CHAIN (enum_decl
) = values
;
1642 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1645 c_parser_consume_token (parser
);
1647 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1649 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1650 pedwarn ("comma at end of enumerator list");
1651 c_parser_consume_token (parser
);
1656 c_parser_error (parser
, "expected %<,%> or %<}%>");
1657 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1658 values
= error_mark_node
;
1662 postfix_attrs
= c_parser_attributes (parser
);
1663 ret
.spec
= finish_enum (type
, nreverse (values
),
1664 chainon (attrs
, postfix_attrs
));
1665 ret
.kind
= ctsk_tagdef
;
1670 c_parser_error (parser
, "expected %<{%>");
1671 ret
.spec
= error_mark_node
;
1672 ret
.kind
= ctsk_tagref
;
1675 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1676 /* In ISO C, enumerated types can be referred to only if already
1678 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1679 pedwarn ("ISO C forbids forward references to %<enum%> types");
1683 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1685 struct-or-union-specifier:
1686 struct-or-union attributes[opt] identifier[opt]
1687 { struct-contents } attributes[opt]
1688 struct-or-union attributes[opt] identifier
1691 struct-declaration-list
1693 struct-declaration-list:
1694 struct-declaration ;
1695 struct-declaration-list struct-declaration ;
1702 struct-declaration-list struct-declaration
1704 struct-declaration-list:
1705 struct-declaration-list ;
1708 (Note that in the syntax here, unlike that in ISO C, the semicolons
1709 are included here rather than in struct-declaration, in order to
1710 describe the syntax with extra semicolons and missing semicolon at
1715 struct-declaration-list:
1716 @defs ( class-name )
1718 (Note this does not include a trailing semicolon, but can be
1719 followed by further declarations, and gets a pedwarn-if-pedantic
1720 when followed by a semicolon.) */
1722 static struct c_typespec
1723 c_parser_struct_or_union_specifier (c_parser
*parser
)
1725 struct c_typespec ret
;
1727 tree ident
= NULL_TREE
;
1728 enum tree_code code
;
1729 switch (c_parser_peek_token (parser
)->keyword
)
1740 c_parser_consume_token (parser
);
1741 attrs
= c_parser_attributes (parser
);
1742 if (c_parser_next_token_is (parser
, CPP_NAME
))
1744 ident
= c_parser_peek_token (parser
)->value
;
1745 c_parser_consume_token (parser
);
1747 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1749 /* Parse a struct or union definition. Start the scope of the
1750 tag before parsing components. */
1751 tree type
= start_struct (code
, ident
);
1753 /* We chain the components in reverse order, then put them in
1754 forward order at the end. Each struct-declaration may
1755 declare multiple components (comma-separated), so we must use
1756 chainon to join them, although when parsing each
1757 struct-declaration we can use TREE_CHAIN directly.
1759 The theory behind all this is that there will be more
1760 semicolon separated fields than comma separated fields, and
1761 so we'll be minimizing the number of node traversals required
1763 tree contents
= NULL_TREE
;
1764 c_parser_consume_token (parser
);
1765 /* Handle the Objective-C @defs construct,
1766 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1767 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1770 gcc_assert (c_dialect_objc ());
1771 c_parser_consume_token (parser
);
1772 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1774 if (c_parser_next_token_is (parser
, CPP_NAME
)
1775 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1777 name
= c_parser_peek_token (parser
)->value
;
1778 c_parser_consume_token (parser
);
1782 c_parser_error (parser
, "expected class name");
1783 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1786 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1788 contents
= nreverse (objc_get_class_ivars (name
));
1791 /* Parse the struct-declarations and semicolons. Problems with
1792 semicolons are diagnosed here; empty structures are diagnosed
1797 /* Parse any stray semicolon. */
1798 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1801 pedwarn ("extra semicolon in struct or union specified");
1802 c_parser_consume_token (parser
);
1805 /* Stop if at the end of the struct or union contents. */
1806 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1808 c_parser_consume_token (parser
);
1811 /* Parse some comma-separated declarations, but not the
1812 trailing semicolon if any. */
1813 decls
= c_parser_struct_declaration (parser
);
1814 contents
= chainon (decls
, contents
);
1815 /* If no semicolon follows, either we have a parse error or
1816 are at the end of the struct or union and should
1818 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1819 c_parser_consume_token (parser
);
1822 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1823 pedwarn ("no semicolon at end of struct or union");
1826 c_parser_error (parser
, "expected %<;%>");
1827 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1832 postfix_attrs
= c_parser_attributes (parser
);
1833 ret
.spec
= finish_struct (type
, nreverse (contents
),
1834 chainon (attrs
, postfix_attrs
));
1835 ret
.kind
= ctsk_tagdef
;
1840 c_parser_error (parser
, "expected %<{%>");
1841 ret
.spec
= error_mark_node
;
1842 ret
.kind
= ctsk_tagref
;
1845 ret
= parser_xref_tag (code
, ident
);
1849 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1850 the trailing semicolon.
1853 specifier-qualifier-list struct-declarator-list
1855 specifier-qualifier-list:
1856 type-specifier specifier-qualifier-list[opt]
1857 type-qualifier specifier-qualifier-list[opt]
1858 attributes specifier-qualifier-list[opt]
1860 struct-declarator-list:
1862 struct-declarator-list , attributes[opt] struct-declarator
1865 declarator attributes[opt]
1866 declarator[opt] : constant-expression attributes[opt]
1871 __extension__ struct-declaration
1872 specifier-qualifier-list
1874 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1875 of attributes where shown is a GNU extension. In GNU C, we accept
1876 any expression without commas in the syntax (assignment
1877 expressions, not just conditional expressions); assignment
1878 expressions will be diagnosed as non-constant. */
1881 c_parser_struct_declaration (c_parser
*parser
)
1883 struct c_declspecs
*specs
;
1885 tree all_prefix_attrs
;
1887 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1891 ext
= disable_extension_diagnostics ();
1892 c_parser_consume_token (parser
);
1893 decl
= c_parser_struct_declaration (parser
);
1894 restore_extension_diagnostics (ext
);
1897 specs
= build_null_declspecs ();
1898 c_parser_declspecs (parser
, specs
, false, true, true);
1901 if (!specs
->declspecs_seen_p
)
1903 c_parser_error (parser
, "expected specifier-qualifier-list");
1906 finish_declspecs (specs
);
1907 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1910 if (!specs
->type_seen_p
)
1913 pedwarn ("ISO C forbids member declarations with no members");
1914 shadow_tag_warned (specs
, pedantic
);
1919 /* Support for unnamed structs or unions as members of
1920 structs or unions (which is [a] useful and [b] supports
1922 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
, NULL_TREE
);
1926 pending_xref_error ();
1927 prefix_attrs
= specs
->attrs
;
1928 all_prefix_attrs
= prefix_attrs
;
1929 specs
->attrs
= NULL_TREE
;
1933 /* Declaring one or more declarators or un-named bit-fields. */
1934 struct c_declarator
*declarator
;
1936 if (c_parser_next_token_is (parser
, CPP_COLON
))
1937 declarator
= build_id_declarator (NULL_TREE
);
1939 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1940 C_DTR_NORMAL
, &dummy
);
1941 if (declarator
== NULL
)
1943 c_parser_skip_to_end_of_block_or_statement (parser
);
1946 if (c_parser_next_token_is (parser
, CPP_COLON
)
1947 || c_parser_next_token_is (parser
, CPP_COMMA
)
1948 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1949 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
1950 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1952 tree postfix_attrs
= NULL_TREE
;
1953 tree width
= NULL_TREE
;
1955 if (c_parser_next_token_is (parser
, CPP_COLON
))
1957 c_parser_consume_token (parser
);
1958 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
1960 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1961 postfix_attrs
= c_parser_attributes (parser
);
1962 d
= grokfield (declarator
, specs
, width
);
1963 decl_attributes (&d
, chainon (postfix_attrs
,
1964 all_prefix_attrs
), 0);
1965 TREE_CHAIN (d
) = decls
;
1967 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1968 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1971 all_prefix_attrs
= prefix_attrs
;
1972 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1973 c_parser_consume_token (parser
);
1974 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1975 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1977 /* Semicolon consumed in caller. */
1982 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
1988 c_parser_error (parser
,
1989 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
1990 "%<__attribute__%>");
1997 /* Parse a typeof specifier (a GNU extension).
2000 typeof ( expression )
2001 typeof ( type-name )
2004 static struct c_typespec
2005 c_parser_typeof_specifier (c_parser
*parser
)
2007 struct c_typespec ret
;
2008 ret
.kind
= ctsk_typeof
;
2009 ret
.spec
= error_mark_node
;
2010 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2011 c_parser_consume_token (parser
);
2014 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2020 if (c_parser_next_token_starts_typename (parser
))
2022 struct c_type_name
*type
= c_parser_type_name (parser
);
2027 ret
.spec
= groktypename (type
);
2028 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2033 struct c_expr expr
= c_parser_expression (parser
);
2036 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2037 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2038 error ("%<typeof%> applied to a bit-field");
2039 ret
.spec
= TREE_TYPE (expr
.value
);
2040 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2042 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2046 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2047 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2048 be redeclared; otherwise it may not. KIND indicates which kind of
2049 declarator is wanted. Returns a valid declarator except in the
2050 case of a syntax error in which case NULL is returned. *SEEN_ID is
2051 set to true if an identifier being declared is seen; this is used
2052 to diagnose bad forms of abstract array declarators and to
2053 determine whether an identifier list is syntactically permitted.
2056 pointer[opt] direct-declarator
2060 ( attributes[opt] declarator )
2061 direct-declarator array-declarator
2062 direct-declarator ( parameter-type-list )
2063 direct-declarator ( identifier-list[opt] )
2066 * type-qualifier-list[opt]
2067 * type-qualifier-list[opt] pointer
2069 type-qualifier-list:
2072 type-qualifier-list type-qualifier
2073 type-qualifier-list attributes
2075 parameter-type-list:
2077 parameter-list , ...
2080 parameter-declaration
2081 parameter-list , parameter-declaration
2083 parameter-declaration:
2084 declaration-specifiers declarator attributes[opt]
2085 declaration-specifiers abstract-declarator[opt] attributes[opt]
2089 identifier-list , identifier
2091 abstract-declarator:
2093 pointer[opt] direct-abstract-declarator
2095 direct-abstract-declarator:
2096 ( attributes[opt] abstract-declarator )
2097 direct-abstract-declarator[opt] array-declarator
2098 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2103 direct-declarator ( parameter-forward-declarations
2104 parameter-type-list[opt] )
2106 direct-abstract-declarator:
2107 direct-abstract-declarator[opt] ( parameter-forward-declarations
2108 parameter-type-list[opt] )
2110 parameter-forward-declarations:
2112 parameter-forward-declarations parameter-list ;
2114 The uses of attributes shown above are GNU extensions.
2116 Some forms of array declarator are not included in C99 in the
2117 syntax for abstract declarators; these are disallowed elsewhere.
2118 This may be a defect (DR#289).
2120 This function also accepts an omitted abstract declarator as being
2121 an abstract declarator, although not part of the formal syntax. */
2123 static struct c_declarator
*
2124 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2127 /* Parse any initial pointer part. */
2128 if (c_parser_next_token_is (parser
, CPP_MULT
))
2130 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2131 struct c_declarator
*inner
;
2132 c_parser_consume_token (parser
);
2133 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2134 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2138 return make_pointer_declarator (quals_attrs
, inner
);
2140 /* Now we have a direct declarator, direct abstract declarator or
2141 nothing (which counts as a direct abstract declarator here). */
2142 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2145 /* Parse a direct declarator or direct abstract declarator; arguments
2146 as c_parser_declarator. */
2148 static struct c_declarator
*
2149 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2152 /* The direct declarator must start with an identifier (possibly
2153 omitted) or a parenthesized declarator (possibly abstract). In
2154 an ordinary declarator, initial parentheses must start a
2155 parenthesized declarator. In an abstract declarator or parameter
2156 declarator, they could start a parenthesized declarator or a
2157 parameter list. To tell which, the open parenthesis and any
2158 following attributes must be read. If a declaration specifier
2159 follows, then it is a parameter list; if the specifier is a
2160 typedef name, there might be an ambiguity about redeclaring it,
2161 which is resolved in the direction of treating it as a typedef
2162 name. If a close parenthesis follows, it is also an empty
2163 parameter list, as the syntax does not permit empty abstract
2164 declarators. Otherwise, it is a parenthesized declarator (in
2165 which case the analysis may be repeated inside it, recursively).
2167 ??? There is an ambiguity in a parameter declaration "int
2168 (__attribute__((foo)) x)", where x is not a typedef name: it
2169 could be an abstract declarator for a function, or declare x with
2170 parentheses. The proper resolution of this ambiguity needs
2171 documenting. At present we follow an accident of the old
2172 parser's implementation, whereby the first parameter must have
2173 some declaration specifiers other than just attributes. Thus as
2174 a parameter declaration it is treated as a parenthesized
2175 parameter named x, and as an abstract declarator it is
2178 ??? Also following the old parser, attributes inside an empty
2179 parameter list are ignored, making it a list not yielding a
2180 prototype, rather than giving an error or making it have one
2181 parameter with implicit type int.
2183 ??? Also following the old parser, typedef names may be
2184 redeclared in declarators, but not Objective-C class names. */
2186 if (kind
!= C_DTR_ABSTRACT
2187 && c_parser_next_token_is (parser
, CPP_NAME
)
2189 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2190 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2192 struct c_declarator
*inner
2193 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2195 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2196 c_parser_consume_token (parser
);
2197 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2200 if (kind
!= C_DTR_NORMAL
2201 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2203 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2204 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2207 /* Either we are at the end of an abstract declarator, or we have
2210 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2213 struct c_declarator
*inner
;
2214 c_parser_consume_token (parser
);
2215 attrs
= c_parser_attributes (parser
);
2216 if (kind
!= C_DTR_NORMAL
2217 && (c_parser_next_token_starts_declspecs (parser
)
2218 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2220 struct c_arg_info
*args
2221 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2228 = build_function_declarator (args
,
2229 build_id_declarator (NULL_TREE
));
2230 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2234 /* A parenthesized declarator. */
2235 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2236 if (inner
!= NULL
&& attrs
!= NULL
)
2237 inner
= build_attrs_declarator (attrs
, inner
);
2238 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2240 c_parser_consume_token (parser
);
2244 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2248 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2255 if (kind
== C_DTR_NORMAL
)
2257 c_parser_error (parser
, "expected identifier or %<(%>");
2261 return build_id_declarator (NULL_TREE
);
2265 /* Parse part of a direct declarator or direct abstract declarator,
2266 given that some (in INNER) has already been parsed; ID_PRESENT is
2267 true if an identifier is present, false for an abstract
2270 static struct c_declarator
*
2271 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2272 struct c_declarator
*inner
)
2274 /* Parse a sequence of array declarators and parameter lists. */
2275 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2277 struct c_declarator
*declarator
;
2278 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2282 c_parser_consume_token (parser
);
2283 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2284 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2286 c_parser_consume_token (parser
);
2287 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2288 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2289 if (!quals_attrs
->declspecs_seen_p
)
2291 /* If "static" is present, there must be an array dimension.
2292 Otherwise, there may be a dimension, "*", or no
2297 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2301 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2306 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2308 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2312 c_parser_consume_token (parser
);
2317 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2323 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2326 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2327 c_parser_consume_token (parser
);
2330 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2334 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2336 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2337 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2339 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2342 struct c_arg_info
*args
;
2343 c_parser_consume_token (parser
);
2344 attrs
= c_parser_attributes (parser
);
2345 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2350 inner
= build_function_declarator (args
, inner
);
2351 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2357 /* Parse a parameter list or identifier list, including the closing
2358 parenthesis but not the opening one. ATTRS are the attributes at
2359 the start of the list. ID_LIST_OK is true if an identifier list is
2360 acceptable; such a list must not have attributes at the start. */
2362 static struct c_arg_info
*
2363 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2366 declare_parm_level ();
2367 /* If the list starts with an identifier, it is an identifier list.
2368 Otherwise, it is either a prototype list or an empty list. */
2371 && c_parser_next_token_is (parser
, CPP_NAME
)
2372 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2374 tree list
= NULL_TREE
, *nextp
= &list
;
2375 while (c_parser_next_token_is (parser
, CPP_NAME
)
2376 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2378 *nextp
= build_tree_list (NULL_TREE
,
2379 c_parser_peek_token (parser
)->value
);
2380 nextp
= & TREE_CHAIN (*nextp
);
2381 c_parser_consume_token (parser
);
2382 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2384 c_parser_consume_token (parser
);
2385 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2387 c_parser_error (parser
, "expected identifier");
2391 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2393 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2398 c_parser_consume_token (parser
);
2404 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2412 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2418 /* Parse a parameter list (possibly empty), including the closing
2419 parenthesis but not the opening one. ATTRS are the attributes at
2420 the start of the list. */
2422 static struct c_arg_info
*
2423 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2425 bool good_parm
= false;
2426 /* ??? Following the old parser, forward parameter declarations may
2427 use abstract declarators, and if no real parameter declarations
2428 follow the forward declarations then this is not diagnosed. Also
2429 note as above that attributes are ignored as the only contents of
2430 the parentheses, or as the only contents after forward
2432 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2434 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2439 c_parser_consume_token (parser
);
2442 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2444 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2448 /* Suppress -Wold-style-definition for this case. */
2449 ret
->types
= error_mark_node
;
2450 error ("ISO C requires a named argument before %<...%>");
2451 c_parser_consume_token (parser
);
2452 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2454 c_parser_consume_token (parser
);
2459 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2464 /* Nonempty list of parameters, either terminated with semicolon
2465 (forward declarations; recurse) or with close parenthesis (normal
2466 function) or with ", ... )" (variadic function). */
2469 /* Parse a parameter. */
2470 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2475 push_parm_decl (parm
);
2477 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2480 c_parser_consume_token (parser
);
2481 mark_forward_parm_decls ();
2482 new_attrs
= c_parser_attributes (parser
);
2483 return c_parser_parms_list_declarator (parser
, new_attrs
);
2485 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2487 c_parser_consume_token (parser
);
2489 return get_parm_info (false);
2492 struct c_arg_info
*ret
2493 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2501 if (!c_parser_require (parser
, CPP_COMMA
,
2502 "expected %<;%>, %<,%> or %<)%>"))
2504 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2507 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2509 c_parser_consume_token (parser
);
2510 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2512 c_parser_consume_token (parser
);
2514 return get_parm_info (true);
2517 struct c_arg_info
*ret
2518 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2528 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2536 /* Parse a parameter declaration. ATTRS are the attributes at the
2537 start of the declaration if it is the first parameter. */
2539 static struct c_parm
*
2540 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2542 struct c_declspecs
*specs
;
2543 struct c_declarator
*declarator
;
2545 tree postfix_attrs
= NULL_TREE
;
2547 if (!c_parser_next_token_starts_declspecs (parser
))
2549 /* ??? In some Objective-C cases '...' isn't applicable so there
2550 should be a different message. */
2551 c_parser_error (parser
,
2552 "expected declaration specifiers or %<...%>");
2553 c_parser_skip_to_end_of_parameter (parser
);
2556 specs
= build_null_declspecs ();
2559 declspecs_add_attrs (specs
, attrs
);
2562 c_parser_declspecs (parser
, specs
, true, true, true);
2563 finish_declspecs (specs
);
2564 pending_xref_error ();
2565 prefix_attrs
= specs
->attrs
;
2566 specs
->attrs
= NULL_TREE
;
2567 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2568 C_DTR_PARM
, &dummy
);
2569 if (declarator
== NULL
)
2571 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2574 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2575 postfix_attrs
= c_parser_attributes (parser
);
2576 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2580 /* Parse a string literal in an asm expression. It should not be
2581 translated, and wide string literals are an error although
2582 permitted by the syntax. This is a GNU extension.
2587 ??? At present, following the old parser, the caller needs to have
2588 set c_lex_string_translate to 0. It would be better to follow the
2589 C++ parser rather than using the c_lex_string_translate kludge. */
2592 c_parser_asm_string_literal (c_parser
*parser
)
2595 if (c_parser_next_token_is (parser
, CPP_STRING
))
2597 str
= c_parser_peek_token (parser
)->value
;
2598 c_parser_consume_token (parser
);
2600 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2602 error ("wide string literal in %<asm%>");
2603 str
= build_string (1, "");
2604 c_parser_consume_token (parser
);
2608 c_parser_error (parser
, "expected string literal");
2614 /* Parse a simple asm expression. This is used in restricted
2615 contexts, where a full expression with inputs and outputs does not
2616 make sense. This is a GNU extension.
2619 asm ( asm-string-literal )
2623 c_parser_simple_asm_expr (c_parser
*parser
)
2626 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2627 /* ??? Follow the C++ parser rather than using the
2628 c_lex_string_translate kludge. */
2629 c_lex_string_translate
= 0;
2630 c_parser_consume_token (parser
);
2631 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2633 c_lex_string_translate
= 1;
2636 str
= c_parser_asm_string_literal (parser
);
2637 c_lex_string_translate
= 1;
2638 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2640 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2646 /* Parse (possibly empty) attributes. This is a GNU extension.
2650 attributes attribute
2653 __attribute__ ( ( attribute-list ) )
2657 attribute_list , attrib
2662 any-word ( identifier )
2663 any-word ( identifier , nonempty-expr-list )
2664 any-word ( expr-list )
2666 where the "identifier" must not be declared as a type, and
2667 "any-word" may be any identifier (including one declared as a
2668 type), a reserved word storage class specifier, type specifier or
2669 type qualifier. ??? This still leaves out most reserved keywords
2670 (following the old parser), shouldn't we include them, and why not
2671 allow identifiers declared as types to start the arguments? */
2674 c_parser_attributes (c_parser
*parser
)
2676 tree attrs
= NULL_TREE
;
2677 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2679 /* ??? Follow the C++ parser rather than using the
2680 c_lex_string_translate kludge. */
2681 c_lex_string_translate
= 0;
2682 c_parser_consume_token (parser
);
2683 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2685 c_lex_string_translate
= 1;
2688 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2690 c_lex_string_translate
= 1;
2691 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2694 /* Parse the attribute list. */
2695 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2696 || c_parser_next_token_is (parser
, CPP_NAME
)
2697 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2699 tree attr
, attr_name
, attr_args
;
2700 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2702 c_parser_consume_token (parser
);
2705 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2707 /* ??? See comment above about what keywords are
2710 switch (c_parser_peek_token (parser
)->keyword
)
2745 attr_name
= c_parser_peek_token (parser
)->value
;
2746 c_parser_consume_token (parser
);
2747 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2749 attr
= build_tree_list (attr_name
, NULL_TREE
);
2750 attrs
= chainon (attrs
, attr
);
2753 c_parser_consume_token (parser
);
2754 /* Parse the attribute contents. If they start with an
2755 identifier which is followed by a comma or close
2756 parenthesis, then the arguments start with that
2757 identifier; otherwise they are an expression list. */
2758 if (c_parser_next_token_is (parser
, CPP_NAME
)
2759 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2760 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2761 || (c_parser_peek_2nd_token (parser
)->type
2762 == CPP_CLOSE_PAREN
)))
2764 tree arg1
= c_parser_peek_token (parser
)->value
;
2765 c_parser_consume_token (parser
);
2766 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2767 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2770 c_parser_consume_token (parser
);
2771 attr_args
= tree_cons (NULL_TREE
, arg1
,
2772 c_parser_expr_list (parser
, false));
2777 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2778 attr_args
= NULL_TREE
;
2780 attr_args
= c_parser_expr_list (parser
, false);
2782 attr
= build_tree_list (attr_name
, attr_args
);
2783 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2784 c_parser_consume_token (parser
);
2787 c_lex_string_translate
= 1;
2788 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2792 attrs
= chainon (attrs
, attr
);
2794 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2795 c_parser_consume_token (parser
);
2798 c_lex_string_translate
= 1;
2799 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2803 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2804 c_parser_consume_token (parser
);
2807 c_lex_string_translate
= 1;
2808 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2812 c_lex_string_translate
= 1;
2817 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2820 specifier-qualifier-list abstract-declarator[opt]
2823 static struct c_type_name
*
2824 c_parser_type_name (c_parser
*parser
)
2826 struct c_declspecs
*specs
= build_null_declspecs ();
2827 struct c_declarator
*declarator
;
2828 struct c_type_name
*ret
;
2830 c_parser_declspecs (parser
, specs
, false, true, true);
2831 if (!specs
->declspecs_seen_p
)
2833 c_parser_error (parser
, "expected specifier-qualifier-list");
2836 pending_xref_error ();
2837 finish_declspecs (specs
);
2838 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2839 C_DTR_ABSTRACT
, &dummy
);
2840 if (declarator
== NULL
)
2842 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2844 ret
->declarator
= declarator
;
2848 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2851 assignment-expression
2852 { initializer-list }
2853 { initializer-list , }
2856 designation[opt] initializer
2857 initializer-list , designation[opt] initializer
2864 designator-list designator
2871 [ constant-expression ]
2883 [ constant-expression ... constant-expression ]
2885 Any expression without commas is accepted in the syntax for the
2886 constant-expressions, with non-constant expressions rejected later.
2888 This function is only used for top-level initializers; for nested
2889 ones, see c_parser_initval. */
2891 static struct c_expr
2892 c_parser_initializer (c_parser
*parser
)
2894 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2895 return c_parser_braced_init (parser
, NULL_TREE
, false);
2899 ret
= c_parser_expr_no_commas (parser
, NULL
);
2900 if (TREE_CODE (ret
.value
) != STRING_CST
2901 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
2902 ret
= default_function_array_conversion (ret
);
2907 /* Parse a braced initializer list. TYPE is the type specified for a
2908 compound literal, and NULL_TREE for other initializers and for
2909 nested braced lists. NESTED_P is true for nested braced lists,
2910 false for the list of a compound literal or the list that is the
2911 top-level initializer in a declaration. */
2913 static struct c_expr
2914 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
2916 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
2917 c_parser_consume_token (parser
);
2919 push_init_level (0);
2921 really_start_incremental_init (type
);
2922 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2925 pedwarn ("ISO C forbids empty initializer braces");
2929 /* Parse a non-empty initializer list, possibly with a trailing
2933 c_parser_initelt (parser
);
2936 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2937 c_parser_consume_token (parser
);
2940 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2944 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
2947 ret
.value
= error_mark_node
;
2948 ret
.original_code
= ERROR_MARK
;
2949 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
2952 c_parser_consume_token (parser
);
2953 return pop_init_level (0);
2956 /* Parse a nested initializer, including designators. */
2959 c_parser_initelt (c_parser
*parser
)
2961 /* Parse any designator or designator list. A single array
2962 designator may have the subsequent "=" omitted in GNU C, but a
2963 longer list or a structure member designator may not. */
2964 if (c_parser_next_token_is (parser
, CPP_NAME
)
2965 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
2967 /* Old-style structure member designator. */
2968 set_init_label (c_parser_peek_token (parser
)->value
);
2970 pedwarn ("obsolete use of designated initializer with %<:%>");
2971 c_parser_consume_token (parser
);
2972 c_parser_consume_token (parser
);
2976 /* des_seen is 0 if there have been no designators, 1 if there
2977 has been a single array designator and 2 otherwise. */
2979 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
2980 || c_parser_next_token_is (parser
, CPP_DOT
))
2982 int des_prev
= des_seen
;
2985 if (c_parser_next_token_is (parser
, CPP_DOT
))
2988 c_parser_consume_token (parser
);
2989 if (c_parser_next_token_is (parser
, CPP_NAME
))
2991 set_init_label (c_parser_peek_token (parser
)->value
);
2992 c_parser_consume_token (parser
);
2997 init
.value
= error_mark_node
;
2998 init
.original_code
= ERROR_MARK
;
2999 c_parser_error (parser
, "expected identifier");
3000 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3001 process_init_element (init
);
3008 /* ??? Following the old parser, [ objc-receiver
3009 objc-message-args ] is accepted as an initializer,
3010 being distinguished from a designator by what follows
3011 the first assignment expression inside the square
3012 brackets, but after a first array designator a
3013 subsequent square bracket is for Objective-C taken to
3014 start an expression, using the obsolete form of
3015 designated initializer without '=', rather than
3016 possibly being a second level of designation: in LALR
3017 terms, the '[' is shifted rather than reducing
3018 designator to designator-list. */
3019 if (des_prev
== 1 && c_dialect_objc ())
3021 des_seen
= des_prev
;
3024 if (des_prev
== 0 && c_dialect_objc ())
3026 /* This might be an array designator or an
3027 Objective-C message expression. If the former,
3028 continue parsing here; if the latter, parse the
3029 remainder of the initializer given the starting
3030 primary-expression. ??? It might make sense to
3031 distinguish when des_prev == 1 as well; see
3032 previous comment. */
3034 struct c_expr mexpr
;
3035 c_parser_consume_token (parser
);
3036 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3037 && ((c_parser_peek_token (parser
)->id_kind
3039 || (c_parser_peek_token (parser
)->id_kind
3040 == C_ID_CLASSNAME
)))
3042 /* Type name receiver. */
3043 tree id
= c_parser_peek_token (parser
)->value
;
3044 c_parser_consume_token (parser
);
3045 rec
= objc_get_class_reference (id
);
3046 goto parse_message_args
;
3048 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3049 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3050 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3051 goto array_desig_after_first
;
3052 /* Expression receiver. So far only one part
3053 without commas has been parsed; there might be
3054 more of the expression. */
3056 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3059 c_parser_consume_token (parser
);
3060 next
= c_parser_expr_no_commas (parser
, NULL
);
3061 next
= default_function_array_conversion (next
);
3062 rec
= build_compound_expr (rec
, next
.value
);
3065 /* Now parse the objc-message-args. */
3066 args
= c_parser_objc_message_args (parser
);
3067 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3070 = objc_build_message_expr (build_tree_list (rec
, args
));
3071 mexpr
.original_code
= ERROR_MARK
;
3072 /* Now parse and process the remainder of the
3073 initializer, starting with this message
3074 expression as a primary-expression. */
3075 c_parser_initval (parser
, &mexpr
);
3078 c_parser_consume_token (parser
);
3079 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3080 array_desig_after_first
:
3081 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3083 c_parser_consume_token (parser
);
3084 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3088 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3090 c_parser_consume_token (parser
);
3091 set_init_index (first
, second
);
3092 if (pedantic
&& second
)
3093 pedwarn ("ISO C forbids specifying range of "
3094 "elements to initialize");
3097 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3103 if (c_parser_next_token_is (parser
, CPP_EQ
))
3105 if (pedantic
&& !flag_isoc99
)
3106 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3107 c_parser_consume_token (parser
);
3114 pedwarn ("obsolete use of designated initializer "
3120 init
.value
= error_mark_node
;
3121 init
.original_code
= ERROR_MARK
;
3122 c_parser_error (parser
, "expected %<=%>");
3123 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3124 process_init_element (init
);
3130 c_parser_initval (parser
, NULL
);
3133 /* Parse a nested initializer; as c_parser_initializer but parses
3134 initializers within braced lists, after any designators have been
3135 applied. If AFTER is not NULL then it is an Objective-C message
3136 expression which is the primary-expression starting the
3140 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3143 gcc_assert (!after
|| c_dialect_objc ());
3144 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3145 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3148 init
= c_parser_expr_no_commas (parser
, after
);
3149 if (init
.value
!= NULL_TREE
3150 && TREE_CODE (init
.value
) != STRING_CST
3151 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3152 init
= default_function_array_conversion (init
);
3154 process_init_element (init
);
3157 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3161 { block-item-list[opt] }
3162 { label-declarations block-item-list }
3166 block-item-list block-item
3178 { label-declarations block-item-list }
3181 __extension__ nested-declaration
3182 nested-function-definition
3186 label-declarations label-declaration
3189 __label__ identifier-list ;
3191 Allowing the mixing of declarations and code is new in C99. The
3192 GNU syntax also permits (not shown above) labels at the end of
3193 compound statements, which yield an error. We don't allow labels
3194 on declarations; this might seem like a natural extension, but
3195 there would be a conflict between attributes on the label and
3196 prefix attributes on the declaration. ??? The syntax follows the
3197 old parser in requiring something after label declarations.
3198 Although they are erroneous if the labels declared aren't defined,
3199 is it useful for the syntax to be this way? */
3202 c_parser_compound_statement (c_parser
*parser
)
3205 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3206 return error_mark_node
;
3207 stmt
= c_begin_compound_stmt (true);
3208 c_parser_compound_statement_nostart (parser
);
3209 return c_end_compound_stmt (stmt
, true);
3212 /* Parse a compound statement except for the opening brace. This is
3213 used for parsing both compound statements and statement expressions
3214 (which follow different paths to handling the opening). */
3217 c_parser_compound_statement_nostart (c_parser
*parser
)
3219 bool last_stmt
= false;
3220 bool last_label
= false;
3221 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3223 c_parser_consume_token (parser
);
3226 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3228 /* Read zero or more forward-declarations for labels that nested
3229 functions can jump to. */
3230 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3232 c_parser_consume_token (parser
);
3233 /* Any identifiers, including those declared as type names,
3238 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3240 c_parser_error (parser
, "expected identifier");
3244 = declare_label (c_parser_peek_token (parser
)->value
);
3245 C_DECLARED_LABEL_FLAG (label
) = 1;
3246 add_stmt (build_stmt (DECL_EXPR
, label
));
3247 c_parser_consume_token (parser
);
3248 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3249 c_parser_consume_token (parser
);
3253 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3255 /* ??? Locating this diagnostic on the token after the
3256 declarations end follows the old parser, but it might be
3257 better to locate it where the declarations start instead. */
3259 pedwarn ("ISO C forbids label declarations");
3261 /* We must now have at least one statement, label or declaration. */
3262 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3264 c_parser_error (parser
, "expected declaration or statement");
3265 c_parser_consume_token (parser
);
3268 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3270 location_t loc
= c_parser_peek_token (parser
)->location
;
3271 if (c_parser_next_token_is (parser
, CPP_EOF
))
3273 c_parser_error (parser
, "expected declaration or statement");
3276 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3277 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3278 || (c_parser_next_token_is (parser
, CPP_NAME
)
3279 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3283 c_parser_label (parser
);
3285 else if (!last_label
3286 && c_parser_next_token_starts_declspecs (parser
))
3289 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3291 && ((pedantic
&& !flag_isoc99
)
3292 || warn_declaration_after_statement
))
3293 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3297 else if (!last_label
3298 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3300 /* __extension__ can start a declaration, but is also an
3301 unary operator that can start an expression. Consume all
3302 but the last of a possible series of __extension__ to
3304 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3305 && (c_parser_peek_2nd_token (parser
)->keyword
3307 c_parser_consume_token (parser
);
3308 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3311 ext
= disable_extension_diagnostics ();
3312 c_parser_consume_token (parser
);
3314 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3315 /* Following the old parser, __extension__ does not
3316 disable this diagnostic. */
3317 restore_extension_diagnostics (ext
);
3319 && ((pedantic
&& !flag_isoc99
)
3320 || warn_declaration_after_statement
))
3321 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3333 c_parser_statement_after_labels (parser
);
3337 error ("label at end of compound statement");
3338 c_parser_consume_token (parser
);
3341 /* Parse a label (C90 6.6.1, C99 6.8.1).
3344 identifier : attributes[opt]
3345 case constant-expression :
3351 case constant-expression ... constant-expression :
3353 The use of attributes on labels is a GNU extension. The syntax in
3354 GNU C accepts any expressions without commas, non-constant
3355 expressions being rejected later. */
3358 c_parser_label (c_parser
*parser
)
3360 location_t loc1
= c_parser_peek_token (parser
)->location
;
3361 tree label
= NULL_TREE
;
3362 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3365 c_parser_consume_token (parser
);
3366 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3367 if (c_parser_next_token_is (parser
, CPP_COLON
))
3369 c_parser_consume_token (parser
);
3370 label
= do_case (exp1
, NULL_TREE
);
3372 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3374 c_parser_consume_token (parser
);
3375 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3376 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3377 label
= do_case (exp1
, exp2
);
3380 c_parser_error (parser
, "expected %<:%> or %<...%>");
3382 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3384 c_parser_consume_token (parser
);
3385 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3386 label
= do_case (NULL_TREE
, NULL_TREE
);
3390 tree name
= c_parser_peek_token (parser
)->value
;
3394 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3395 c_parser_consume_token (parser
);
3396 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3397 loc2
= c_parser_peek_token (parser
)->location
;
3398 c_parser_consume_token (parser
);
3399 attrs
= c_parser_attributes (parser
);
3400 tlab
= define_label (loc2
, name
);
3403 decl_attributes (&tlab
, attrs
, 0);
3404 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3408 SET_EXPR_LOCATION (label
, loc1
);
3411 /* Parse a statement (C90 6.6, C99 6.8).
3416 expression-statement
3424 expression-statement:
3427 selection-statement:
3431 iteration-statement:
3440 return expression[opt] ;
3453 objc-throw-statement
3454 objc-try-catch-statement
3455 objc-synchronized-statement
3457 objc-throw-statement:
3463 c_parser_statement (c_parser
*parser
)
3465 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3466 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3467 || (c_parser_next_token_is (parser
, CPP_NAME
)
3468 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3469 c_parser_label (parser
);
3470 c_parser_statement_after_labels (parser
);
3473 /* Parse a statement, other than a labeled statement. */
3476 c_parser_statement_after_labels (c_parser
*parser
)
3478 location_t loc
= c_parser_peek_token (parser
)->location
;
3479 tree stmt
= NULL_TREE
;
3480 switch (c_parser_peek_token (parser
)->type
)
3482 case CPP_OPEN_BRACE
:
3483 add_stmt (c_parser_compound_statement (parser
));
3486 switch (c_parser_peek_token (parser
)->keyword
)
3489 c_parser_if_statement (parser
);
3492 c_parser_switch_statement (parser
);
3495 c_parser_while_statement (parser
);
3498 c_parser_do_statement (parser
);
3501 c_parser_for_statement (parser
);
3504 c_parser_consume_token (parser
);
3505 if (c_parser_next_token_is (parser
, CPP_NAME
))
3507 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3508 c_parser_consume_token (parser
);
3510 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3512 c_parser_consume_token (parser
);
3513 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3516 c_parser_error (parser
, "expected identifier or %<*%>");
3517 goto expect_semicolon
;
3519 c_parser_consume_token (parser
);
3520 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3521 goto expect_semicolon
;
3523 c_parser_consume_token (parser
);
3524 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3525 goto expect_semicolon
;
3527 c_parser_consume_token (parser
);
3528 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3530 stmt
= c_finish_return (NULL_TREE
);
3531 c_parser_consume_token (parser
);
3535 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3536 goto expect_semicolon
;
3540 stmt
= c_parser_asm_statement (parser
);
3543 gcc_assert (c_dialect_objc ());
3544 c_parser_consume_token (parser
);
3545 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3547 stmt
= objc_build_throw_stmt (NULL_TREE
);
3548 c_parser_consume_token (parser
);
3553 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3554 goto expect_semicolon
;
3558 gcc_assert (c_dialect_objc ());
3559 c_parser_objc_try_catch_statement (parser
);
3561 case RID_AT_SYNCHRONIZED
:
3562 gcc_assert (c_dialect_objc ());
3563 c_parser_objc_synchronized_statement (parser
);
3570 c_parser_consume_token (parser
);
3572 case CPP_CLOSE_PAREN
:
3573 case CPP_CLOSE_SQUARE
:
3574 /* Avoid infinite loop in error recovery:
3575 c_parser_skip_until_found stops at a closing nesting
3576 delimiter without consuming it, but here we need to consume
3577 it to proceed further. */
3578 c_parser_error (parser
, "expected statement");
3579 c_parser_consume_token (parser
);
3583 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3585 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3588 /* Two cases cannot and do not have line numbers associated: If stmt
3589 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3590 cannot hold line numbers. But that's OK because the statement
3591 will either be changed to a MODIFY_EXPR during gimplification of
3592 the statement expr, or discarded. If stmt was compound, but
3593 without new variables, we will have skipped the creation of a
3594 BIND and will have a bare STATEMENT_LIST. But that's OK because
3595 (recursively) all of the component statements should already have
3596 line numbers assigned. ??? Can we discard no-op statements
3598 if (stmt
&& EXPR_P (stmt
))
3599 SET_EXPR_LOCATION (stmt
, loc
);
3602 /* Parse a parenthesized condition from an if, do or while statement.
3608 c_parser_paren_condition (c_parser
*parser
)
3612 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3613 return error_mark_node
;
3614 loc
= c_parser_peek_token (parser
)->location
;
3615 cond
= c_objc_common_truthvalue_conversion
3616 (c_parser_expression_conv (parser
).value
);
3618 SET_EXPR_LOCATION (cond
, loc
);
3619 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3623 /* Parse a statement which is a block in C99. */
3626 c_parser_c99_block_statement (c_parser
*parser
)
3628 tree block
= c_begin_compound_stmt (flag_isoc99
);
3629 c_parser_statement (parser
);
3630 return c_end_compound_stmt (block
, flag_isoc99
);
3633 /* Parse the body of an if statement or the else half thereof. This
3634 is just parsing a statement but (a) it is a block in C99, (b) we
3635 track whether the body is an if statement for the sake of
3636 -Wparentheses warnings, (c) we handle an empty body specially for
3637 the sake of -Wextra warnings. */
3640 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3642 tree block
= c_begin_compound_stmt (flag_isoc99
);
3643 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3644 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3645 || (c_parser_next_token_is (parser
, CPP_NAME
)
3646 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3647 c_parser_label (parser
);
3648 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3649 if (extra_warnings
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3650 add_stmt (build1 (NOP_EXPR
, NULL_TREE
, NULL_TREE
));
3651 c_parser_statement_after_labels (parser
);
3652 return c_end_compound_stmt (block
, flag_isoc99
);
3655 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3658 if ( expression ) statement
3659 if ( expression ) statement else statement
3663 c_parser_if_statement (c_parser
*parser
)
3668 bool first_if
= false, second_if
= false;
3669 tree first_body
, second_body
;
3670 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3671 c_parser_consume_token (parser
);
3672 block
= c_begin_compound_stmt (flag_isoc99
);
3673 loc
= c_parser_peek_token (parser
)->location
;
3674 cond
= c_parser_paren_condition (parser
);
3675 first_body
= c_parser_if_body (parser
, &first_if
);
3676 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3678 c_parser_consume_token (parser
);
3679 second_body
= c_parser_if_body (parser
, &second_if
);
3682 second_body
= NULL_TREE
;
3683 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3684 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3687 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3690 switch (expression) statement
3694 c_parser_switch_statement (c_parser
*parser
)
3696 tree block
, expr
, body
, save_break
;
3697 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3698 c_parser_consume_token (parser
);
3699 block
= c_begin_compound_stmt (flag_isoc99
);
3700 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3702 expr
= c_parser_expression (parser
).value
;
3703 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3706 expr
= error_mark_node
;
3707 c_start_case (expr
);
3708 save_break
= c_break_label
;
3709 c_break_label
= NULL_TREE
;
3710 body
= c_parser_c99_block_statement (parser
);
3711 c_finish_case (body
);
3713 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3714 c_break_label
= save_break
;
3715 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3718 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3721 while (expression) statement
3725 c_parser_while_statement (c_parser
*parser
)
3727 tree block
, cond
, body
, save_break
, save_cont
;
3729 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3730 c_parser_consume_token (parser
);
3731 block
= c_begin_compound_stmt (flag_isoc99
);
3732 loc
= c_parser_peek_token (parser
)->location
;
3733 cond
= c_parser_paren_condition (parser
);
3734 save_break
= c_break_label
;
3735 c_break_label
= NULL_TREE
;
3736 save_cont
= c_cont_label
;
3737 c_cont_label
= NULL_TREE
;
3738 body
= c_parser_c99_block_statement (parser
);
3739 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3740 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3741 c_break_label
= save_break
;
3742 c_cont_label
= save_cont
;
3745 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3748 do statement while ( expression ) ;
3752 c_parser_do_statement (c_parser
*parser
)
3754 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3756 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3757 c_parser_consume_token (parser
);
3758 block
= c_begin_compound_stmt (flag_isoc99
);
3759 loc
= c_parser_peek_token (parser
)->location
;
3760 save_break
= c_break_label
;
3761 c_break_label
= NULL_TREE
;
3762 save_cont
= c_cont_label
;
3763 c_cont_label
= NULL_TREE
;
3764 body
= c_parser_c99_block_statement (parser
);
3765 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3766 new_break
= c_break_label
;
3767 c_break_label
= save_break
;
3768 new_cont
= c_cont_label
;
3769 c_cont_label
= save_cont
;
3770 cond
= c_parser_paren_condition (parser
);
3771 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3772 c_parser_skip_to_end_of_block_or_statement (parser
);
3773 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3774 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3777 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3780 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3781 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3783 The form with a declaration is new in C99.
3785 ??? In accordance with the old parser, the declaration may be a
3786 nested function, which is then rejected in check_for_loop_decls,
3787 but does it make any sense for this to be included in the grammar?
3788 Note in particular that the nested function does not include a
3789 trailing ';', whereas the "declaration" production includes one.
3790 Also, can we reject bad declarations earlier and cheaper than
3791 check_for_loop_decls? */
3794 c_parser_for_statement (c_parser
*parser
)
3796 tree block
, cond
, incr
, save_break
, save_cont
, body
;
3798 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
3799 loc
= c_parser_peek_token (parser
)->location
;
3800 c_parser_consume_token (parser
);
3801 block
= c_begin_compound_stmt (flag_isoc99
);
3802 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3804 /* Parse the initialization declaration or expression. */
3805 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3807 c_parser_consume_token (parser
);
3808 c_finish_expr_stmt (NULL_TREE
);
3810 else if (c_parser_next_token_starts_declspecs (parser
))
3812 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3813 check_for_loop_decls ();
3815 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3817 /* __extension__ can start a declaration, but is also an
3818 unary operator that can start an expression. Consume all
3819 but the last of a possible series of __extension__ to
3821 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3822 && (c_parser_peek_2nd_token (parser
)->keyword
3824 c_parser_consume_token (parser
);
3825 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3828 ext
= disable_extension_diagnostics ();
3829 c_parser_consume_token (parser
);
3830 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3831 restore_extension_diagnostics (ext
);
3832 check_for_loop_decls ();
3840 c_finish_expr_stmt (c_parser_expression (parser
).value
);
3841 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3843 /* Parse the loop condition. */
3844 loc
= c_parser_peek_token (parser
)->location
;
3845 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3847 c_parser_consume_token (parser
);
3852 tree ocond
= c_parser_expression_conv (parser
).value
;
3853 cond
= c_objc_common_truthvalue_conversion (ocond
);
3855 SET_EXPR_LOCATION (cond
, loc
);
3856 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3858 /* Parse the increment expression. */
3859 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3860 incr
= c_process_expr_stmt (NULL_TREE
);
3862 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
3863 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3867 cond
= error_mark_node
;
3868 incr
= error_mark_node
;
3870 save_break
= c_break_label
;
3871 c_break_label
= NULL_TREE
;
3872 save_cont
= c_cont_label
;
3873 c_cont_label
= NULL_TREE
;
3874 body
= c_parser_c99_block_statement (parser
);
3875 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
3876 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3877 c_break_label
= save_break
;
3878 c_cont_label
= save_cont
;
3881 /* Parse an asm statement, a GNU extension. This is a full-blown asm
3882 statement with inputs, outputs, clobbers, and volatile tag
3886 asm type-qualifier[opt] ( asm-argument ) ;
3890 asm-string-literal : asm-operands[opt]
3891 asm-string-literal : asm-operands[opt] : asm-operands[opt]
3892 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
3894 Qualifiers other than volatile are accepted in the syntax but
3898 c_parser_asm_statement (c_parser
*parser
)
3900 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
3902 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3903 c_parser_consume_token (parser
);
3904 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
3906 quals
= c_parser_peek_token (parser
)->value
;
3907 c_parser_consume_token (parser
);
3909 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
3910 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
3912 warning (0, "%E qualifier ignored on asm",
3913 c_parser_peek_token (parser
)->value
);
3915 c_parser_consume_token (parser
);
3919 /* ??? Follow the C++ parser rather than using the
3920 c_lex_string_translate kludge. */
3921 c_lex_string_translate
= 0;
3922 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3924 c_lex_string_translate
= 1;
3927 str
= c_parser_asm_string_literal (parser
);
3928 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3931 outputs
= NULL_TREE
;
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
);
3943 /* Parse outputs. */
3944 if (c_parser_next_token_is (parser
, CPP_COLON
)
3945 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3946 outputs
= NULL_TREE
;
3948 outputs
= c_parser_asm_operands (parser
, false);
3949 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3952 clobbers
= NULL_TREE
;
3955 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3957 c_lex_string_translate
= 1;
3958 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3962 if (c_parser_next_token_is (parser
, CPP_COLON
)
3963 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3966 inputs
= c_parser_asm_operands (parser
, true);
3967 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3969 clobbers
= NULL_TREE
;
3972 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3974 c_lex_string_translate
= 1;
3975 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3978 /* Parse clobbers. */
3979 clobbers
= c_parser_asm_clobbers (parser
);
3981 c_lex_string_translate
= 1;
3982 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3984 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3987 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3988 c_parser_skip_to_end_of_block_or_statement (parser
);
3989 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
3994 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
3995 not outputs), apply the default conversion of functions and arrays
4000 asm-operands , asm-operand
4003 asm-string-literal ( expression )
4004 [ identifier ] asm-string-literal ( expression )
4008 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4010 tree list
= NULL_TREE
;
4015 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4017 c_parser_consume_token (parser
);
4018 if (c_parser_next_token_is (parser
, CPP_NAME
))
4020 tree id
= c_parser_peek_token (parser
)->value
;
4021 c_parser_consume_token (parser
);
4022 name
= build_string (IDENTIFIER_LENGTH (id
),
4023 IDENTIFIER_POINTER (id
));
4027 c_parser_error (parser
, "expected identifier");
4028 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4031 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4036 str
= c_parser_asm_string_literal (parser
);
4037 if (str
== NULL_TREE
)
4039 c_lex_string_translate
= 1;
4040 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4042 c_lex_string_translate
= 0;
4045 expr
= c_parser_expression (parser
);
4047 expr
= default_function_array_conversion (expr
);
4048 c_lex_string_translate
= 0;
4049 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4051 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4054 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4056 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4057 c_parser_consume_token (parser
);
4064 /* Parse asm clobbers, a GNU extension.
4068 asm-clobbers , asm-string-literal
4072 c_parser_asm_clobbers (c_parser
*parser
)
4074 tree list
= NULL_TREE
;
4077 tree str
= c_parser_asm_string_literal (parser
);
4079 list
= tree_cons (NULL_TREE
, str
, list
);
4082 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4083 c_parser_consume_token (parser
);
4090 /* Parse an expression other than a compound expression; that is, an
4091 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4092 NULL then it is an Objective-C message expression which is the
4093 primary-expression starting the expression as an initializer.
4095 assignment-expression:
4096 conditional-expression
4097 unary-expression assignment-operator assignment-expression
4099 assignment-operator: one of
4100 = *= /= %= += -= <<= >>= &= ^= |=
4102 In GNU C we accept any conditional expression on the LHS and
4103 diagnose the invalid lvalue rather than producing a syntax
4106 static struct c_expr
4107 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4109 struct c_expr lhs
, rhs
, ret
;
4110 enum tree_code code
;
4111 gcc_assert (!after
|| c_dialect_objc ());
4112 lhs
= c_parser_conditional_expression (parser
, after
);
4113 switch (c_parser_peek_token (parser
)->type
)
4122 code
= TRUNC_DIV_EXPR
;
4125 code
= TRUNC_MOD_EXPR
;
4140 code
= BIT_AND_EXPR
;
4143 code
= BIT_XOR_EXPR
;
4146 code
= BIT_IOR_EXPR
;
4151 c_parser_consume_token (parser
);
4152 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4153 rhs
= default_function_array_conversion (rhs
);
4154 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4155 if (code
== NOP_EXPR
)
4156 ret
.original_code
= MODIFY_EXPR
;
4159 TREE_NO_WARNING (ret
.value
) = 1;
4160 ret
.original_code
= ERROR_MARK
;
4165 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4166 is not NULL then it is an Objective-C message expression which is
4167 the primary-expression starting the expression as an initializer.
4169 conditional-expression:
4170 logical-OR-expression
4171 logical-OR-expression ? expression : conditional-expression
4175 conditional-expression:
4176 logical-OR-expression ? : conditional-expression
4179 static struct c_expr
4180 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4182 struct c_expr cond
, exp1
, exp2
, ret
;
4183 gcc_assert (!after
|| c_dialect_objc ());
4184 cond
= c_parser_binary_expression (parser
, after
);
4185 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4187 cond
= default_function_array_conversion (cond
);
4188 c_parser_consume_token (parser
);
4189 if (c_parser_next_token_is (parser
, CPP_COLON
))
4192 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4193 /* Make sure first operand is calculated only once. */
4194 exp1
.value
= save_expr (default_conversion (cond
.value
));
4195 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4196 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4201 = c_objc_common_truthvalue_conversion
4202 (default_conversion (cond
.value
));
4203 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4204 exp1
= c_parser_expression_conv (parser
);
4205 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4206 - (cond
.value
== truthvalue_false_node
));
4208 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4210 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4211 ret
.value
= error_mark_node
;
4212 ret
.original_code
= ERROR_MARK
;
4215 exp2
= c_parser_conditional_expression (parser
, NULL
);
4216 exp2
= default_function_array_conversion (exp2
);
4217 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4218 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4219 ret
.original_code
= ERROR_MARK
;
4223 /* Parse a binary expression; that is, a logical-OR-expression (C90
4224 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4225 an Objective-C message expression which is the primary-expression
4226 starting the expression as an initializer.
4228 multiplicative-expression:
4230 multiplicative-expression * cast-expression
4231 multiplicative-expression / cast-expression
4232 multiplicative-expression % cast-expression
4234 additive-expression:
4235 multiplicative-expression
4236 additive-expression + multiplicative-expression
4237 additive-expression - multiplicative-expression
4241 shift-expression << additive-expression
4242 shift-expression >> additive-expression
4244 relational-expression:
4246 relational-expression < shift-expression
4247 relational-expression > shift-expression
4248 relational-expression <= shift-expression
4249 relational-expression >= shift-expression
4251 equality-expression:
4252 relational-expression
4253 equality-expression == relational-expression
4254 equality-expression != relational-expression
4258 AND-expression & equality-expression
4260 exclusive-OR-expression:
4262 exclusive-OR-expression ^ AND-expression
4264 inclusive-OR-expression:
4265 exclusive-OR-expression
4266 inclusive-OR-expression | exclusive-OR-expression
4268 logical-AND-expression:
4269 inclusive-OR-expression
4270 logical-AND-expression && inclusive-OR-expression
4272 logical-OR-expression:
4273 logical-AND-expression
4274 logical-OR-expression || logical-AND-expression
4277 static struct c_expr
4278 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4280 /* A binary expression is parsed using operator-precedence parsing,
4281 with the operands being cast expressions. All the binary
4282 operators are left-associative. Thus a binary expression is of
4285 E0 op1 E1 op2 E2 ...
4287 which we represent on a stack. On the stack, the precedence
4288 levels are strictly increasing. When a new operator is
4289 encountered of higher precedence than that at the top of the
4290 stack, it is pushed; its LHS is the top expression, and its RHS
4291 is everything parsed until it is popped. When a new operator is
4292 encountered with precedence less than or equal to that at the top
4293 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4294 by the result of the operation until the operator at the top of
4295 the stack has lower precedence than the new operator or there is
4296 only one element on the stack; then the top expression is the LHS
4297 of the new operator. In the case of logical AND and OR
4298 expressions, we also need to adjust skip_evaluation as
4299 appropriate when the operators are pushed and popped. */
4301 /* The precedence levels, where 0 is a dummy lowest level used for
4302 the bottom of the stack. */
4318 /* The expression at this stack level. */
4320 /* The precedence of the operator on its left, PREC_NONE at the
4321 bottom of the stack. */
4323 /* The operation on its left. */
4329 switch (stack[sp].op) \
4331 case TRUTH_ANDIF_EXPR: \
4332 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4334 case TRUTH_ORIF_EXPR: \
4335 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4340 stack[sp - 1].expr \
4341 = default_function_array_conversion (stack[sp - 1].expr); \
4343 = default_function_array_conversion (stack[sp].expr); \
4344 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4345 stack[sp - 1].expr, \
4349 gcc_assert (!after
|| c_dialect_objc ());
4350 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4351 stack
[0].prec
= PREC_NONE
;
4356 enum tree_code ocode
;
4359 switch (c_parser_peek_token (parser
)->type
)
4367 ocode
= TRUNC_DIV_EXPR
;
4371 ocode
= TRUNC_MOD_EXPR
;
4383 ocode
= LSHIFT_EXPR
;
4387 ocode
= RSHIFT_EXPR
;
4401 case CPP_GREATER_EQ
:
4414 oprec
= PREC_BITAND
;
4415 ocode
= BIT_AND_EXPR
;
4418 oprec
= PREC_BITXOR
;
4419 ocode
= BIT_XOR_EXPR
;
4423 ocode
= BIT_IOR_EXPR
;
4426 oprec
= PREC_LOGAND
;
4427 ocode
= TRUTH_ANDIF_EXPR
;
4431 ocode
= TRUTH_ORIF_EXPR
;
4434 /* Not a binary operator, so end of the binary
4438 c_parser_consume_token (parser
);
4439 while (oprec
<= stack
[sp
].prec
)
4443 case TRUTH_ANDIF_EXPR
:
4445 = default_function_array_conversion (stack
[sp
].expr
);
4446 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4447 (default_conversion (stack
[sp
].expr
.value
));
4448 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4450 case TRUTH_ORIF_EXPR
:
4452 = default_function_array_conversion (stack
[sp
].expr
);
4453 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4454 (default_conversion (stack
[sp
].expr
.value
));
4455 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4461 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4462 stack
[sp
].prec
= oprec
;
4463 stack
[sp
].op
= ocode
;
4468 return stack
[0].expr
;
4472 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4473 NULL then it is an Objective-C message expression which is the
4474 primary-expression starting the expression as an initializer.
4478 ( type-name ) unary-expression
4481 static struct c_expr
4482 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4484 gcc_assert (!after
|| c_dialect_objc ());
4486 return c_parser_postfix_expression_after_primary (parser
, *after
);
4487 /* If the expression begins with a parenthesized type name, it may
4488 be either a cast or a compound literal; we need to see whether
4489 the next character is '{' to tell the difference. If not, it is
4490 an unary expression. */
4491 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4492 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4494 struct c_type_name
*type_name
;
4497 c_parser_consume_token (parser
);
4498 type_name
= c_parser_type_name (parser
);
4499 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4500 if (type_name
== NULL
)
4502 ret
.value
= error_mark_node
;
4503 ret
.original_code
= ERROR_MARK
;
4506 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4507 return c_parser_postfix_expression_after_paren_type (parser
,
4509 expr
= c_parser_cast_expression (parser
, NULL
);
4510 expr
= default_function_array_conversion (expr
);
4511 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4512 ret
.original_code
= ERROR_MARK
;
4516 return c_parser_unary_expression (parser
);
4519 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4525 unary-operator cast-expression
4526 sizeof unary-expression
4527 sizeof ( type-name )
4529 unary-operator: one of
4535 __alignof__ unary-expression
4536 __alignof__ ( type-name )
4539 unary-operator: one of
4540 __extension__ __real__ __imag__
4542 In addition, the GNU syntax treats ++ and -- as unary operators, so
4543 they may be applied to cast expressions with errors for non-lvalues
4546 static struct c_expr
4547 c_parser_unary_expression (c_parser
*parser
)
4550 struct c_expr ret
, op
;
4551 switch (c_parser_peek_token (parser
)->type
)
4554 c_parser_consume_token (parser
);
4555 op
= c_parser_cast_expression (parser
, NULL
);
4556 op
= default_function_array_conversion (op
);
4557 return parser_build_unary_op (PREINCREMENT_EXPR
, op
);
4558 case CPP_MINUS_MINUS
:
4559 c_parser_consume_token (parser
);
4560 op
= c_parser_cast_expression (parser
, NULL
);
4561 op
= default_function_array_conversion (op
);
4562 return parser_build_unary_op (PREDECREMENT_EXPR
, op
);
4564 c_parser_consume_token (parser
);
4565 return parser_build_unary_op (ADDR_EXPR
,
4566 c_parser_cast_expression (parser
, NULL
));
4568 c_parser_consume_token (parser
);
4569 op
= c_parser_cast_expression (parser
, NULL
);
4570 op
= default_function_array_conversion (op
);
4571 ret
.value
= build_indirect_ref (op
.value
, "unary *");
4572 ret
.original_code
= ERROR_MARK
;
4575 c_parser_consume_token (parser
);
4576 if (!c_dialect_objc () && !in_system_header
)
4577 warning (OPT_Wtraditional
,
4578 "traditional C rejects the unary plus operator");
4579 op
= c_parser_cast_expression (parser
, NULL
);
4580 op
= default_function_array_conversion (op
);
4581 return parser_build_unary_op (CONVERT_EXPR
, op
);
4583 c_parser_consume_token (parser
);
4584 op
= c_parser_cast_expression (parser
, NULL
);
4585 op
= default_function_array_conversion (op
);
4586 return parser_build_unary_op (NEGATE_EXPR
, op
);
4588 c_parser_consume_token (parser
);
4589 op
= c_parser_cast_expression (parser
, NULL
);
4590 op
= default_function_array_conversion (op
);
4591 return parser_build_unary_op (BIT_NOT_EXPR
, op
);
4593 c_parser_consume_token (parser
);
4594 op
= c_parser_cast_expression (parser
, NULL
);
4595 op
= default_function_array_conversion (op
);
4596 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
);
4598 /* Refer to the address of a label as a pointer. */
4599 c_parser_consume_token (parser
);
4600 if (c_parser_next_token_is (parser
, CPP_NAME
))
4602 ret
.value
= finish_label_address_expr
4603 (c_parser_peek_token (parser
)->value
);
4604 c_parser_consume_token (parser
);
4608 c_parser_error (parser
, "expected identifier");
4609 ret
.value
= error_mark_node
;
4611 ret
.original_code
= ERROR_MARK
;
4614 switch (c_parser_peek_token (parser
)->keyword
)
4617 return c_parser_sizeof_expression (parser
);
4619 return c_parser_alignof_expression (parser
);
4621 c_parser_consume_token (parser
);
4622 ext
= disable_extension_diagnostics ();
4623 ret
= c_parser_cast_expression (parser
, NULL
);
4624 restore_extension_diagnostics (ext
);
4627 c_parser_consume_token (parser
);
4628 op
= c_parser_cast_expression (parser
, NULL
);
4629 op
= default_function_array_conversion (op
);
4630 return parser_build_unary_op (REALPART_EXPR
, op
);
4632 c_parser_consume_token (parser
);
4633 op
= c_parser_cast_expression (parser
, NULL
);
4634 op
= default_function_array_conversion (op
);
4635 return parser_build_unary_op (IMAGPART_EXPR
, op
);
4637 return c_parser_postfix_expression (parser
);
4640 return c_parser_postfix_expression (parser
);
4644 /* Parse a sizeof expression. */
4646 static struct c_expr
4647 c_parser_sizeof_expression (c_parser
*parser
)
4650 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4651 c_parser_consume_token (parser
);
4654 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4655 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4657 /* Either sizeof ( type-name ) or sizeof unary-expression
4658 starting with a compound literal. */
4659 struct c_type_name
*type_name
;
4660 c_parser_consume_token (parser
);
4661 type_name
= c_parser_type_name (parser
);
4662 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4663 if (type_name
== NULL
)
4668 ret
.value
= error_mark_node
;
4669 ret
.original_code
= ERROR_MARK
;
4672 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4674 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4678 /* sizeof ( type-name ). */
4681 return c_expr_sizeof_type (type_name
);
4685 expr
= c_parser_unary_expression (parser
);
4689 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4690 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4691 error ("%<sizeof%> applied to a bit-field");
4692 return c_expr_sizeof_expr (expr
);
4696 /* Parse an alignof expression. */
4698 static struct c_expr
4699 c_parser_alignof_expression (c_parser
*parser
)
4702 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4703 c_parser_consume_token (parser
);
4706 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4707 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4709 /* Either __alignof__ ( type-name ) or __alignof__
4710 unary-expression starting with a compound literal. */
4711 struct c_type_name
*type_name
;
4713 c_parser_consume_token (parser
);
4714 type_name
= c_parser_type_name (parser
);
4715 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4716 if (type_name
== NULL
)
4721 ret
.value
= error_mark_node
;
4722 ret
.original_code
= ERROR_MARK
;
4725 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4727 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4731 /* alignof ( type-name ). */
4734 ret
.value
= c_alignof (groktypename (type_name
));
4735 ret
.original_code
= ERROR_MARK
;
4741 expr
= c_parser_unary_expression (parser
);
4745 ret
.value
= c_alignof_expr (expr
.value
);
4746 ret
.original_code
= ERROR_MARK
;
4751 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4755 postfix-expression [ expression ]
4756 postfix-expression ( argument-expression-list[opt] )
4757 postfix-expression . identifier
4758 postfix-expression -> identifier
4759 postfix-expression ++
4760 postfix-expression --
4761 ( type-name ) { initializer-list }
4762 ( type-name ) { initializer-list , }
4764 argument-expression-list:
4766 argument-expression-list , argument-expression
4778 (treated as a keyword in GNU C)
4781 ( compound-statement )
4782 __builtin_va_arg ( assignment-expression , type-name )
4783 __builtin_offsetof ( type-name , offsetof-member-designator )
4784 __builtin_choose_expr ( assignment-expression ,
4785 assignment-expression ,
4786 assignment-expression )
4787 __builtin_types_compatible_p ( type-name , type-name )
4789 offsetof-member-designator:
4791 offsetof-member-designator . identifier
4792 offsetof-member-designator [ expression ]
4797 [ objc-receiver objc-message-args ]
4798 @selector ( objc-selector-arg )
4799 @protocol ( identifier )
4800 @encode ( type-name )
4804 static struct c_expr
4805 c_parser_postfix_expression (c_parser
*parser
)
4807 struct c_expr expr
, e1
, e2
, e3
;
4808 struct c_type_name
*t1
, *t2
;
4809 switch (c_parser_peek_token (parser
)->type
)
4814 expr
.value
= c_parser_peek_token (parser
)->value
;
4815 expr
.original_code
= ERROR_MARK
;
4816 c_parser_consume_token (parser
);
4820 expr
.value
= c_parser_peek_token (parser
)->value
;
4821 expr
.original_code
= STRING_CST
;
4822 c_parser_consume_token (parser
);
4824 case CPP_OBJC_STRING
:
4825 gcc_assert (c_dialect_objc ());
4827 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
4828 expr
.original_code
= ERROR_MARK
;
4829 c_parser_consume_token (parser
);
4832 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
4834 c_parser_error (parser
, "expected expression");
4835 expr
.value
= error_mark_node
;
4836 expr
.original_code
= ERROR_MARK
;
4840 tree id
= c_parser_peek_token (parser
)->value
;
4841 location_t loc
= c_parser_peek_token (parser
)->location
;
4842 c_parser_consume_token (parser
);
4843 expr
.value
= build_external_ref (id
,
4844 (c_parser_peek_token (parser
)->type
4845 == CPP_OPEN_PAREN
), loc
);
4846 expr
.original_code
= ERROR_MARK
;
4849 case CPP_OPEN_PAREN
:
4850 /* A parenthesized expression, statement expression or compound
4852 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
4854 /* A statement expression. */
4856 c_parser_consume_token (parser
);
4857 c_parser_consume_token (parser
);
4858 if (cur_stmt_list
== NULL
)
4860 error ("braced-group within expression allowed "
4861 "only inside a function");
4862 parser
->error
= true;
4863 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
4864 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4865 expr
.value
= error_mark_node
;
4866 expr
.original_code
= ERROR_MARK
;
4869 stmt
= c_begin_stmt_expr ();
4870 c_parser_compound_statement_nostart (parser
);
4871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4874 pedwarn ("ISO C forbids braced-groups within expressions");
4875 expr
.value
= c_finish_stmt_expr (stmt
);
4876 expr
.original_code
= ERROR_MARK
;
4878 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4880 /* A compound literal. ??? Can we actually get here rather
4881 than going directly to
4882 c_parser_postfix_expression_after_paren_type from
4884 struct c_type_name
*type_name
;
4885 c_parser_consume_token (parser
);
4886 type_name
= c_parser_type_name (parser
);
4887 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4889 if (type_name
== NULL
)
4891 expr
.value
= error_mark_node
;
4892 expr
.original_code
= ERROR_MARK
;
4895 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4900 /* A parenthesized expression. */
4901 c_parser_consume_token (parser
);
4902 expr
= c_parser_expression (parser
);
4903 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
4904 TREE_NO_WARNING (expr
.value
) = 1;
4905 expr
.original_code
= ERROR_MARK
;
4906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4911 switch (c_parser_peek_token (parser
)->keyword
)
4913 case RID_FUNCTION_NAME
:
4914 case RID_PRETTY_FUNCTION_NAME
:
4915 case RID_C99_FUNCTION_NAME
:
4916 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
4917 c_parser_peek_token (parser
)->value
);
4918 expr
.original_code
= ERROR_MARK
;
4919 c_parser_consume_token (parser
);
4922 c_parser_consume_token (parser
);
4923 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4925 expr
.value
= error_mark_node
;
4926 expr
.original_code
= ERROR_MARK
;
4929 e1
= c_parser_expr_no_commas (parser
, NULL
);
4930 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4932 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4933 expr
.value
= error_mark_node
;
4934 expr
.original_code
= ERROR_MARK
;
4937 t1
= c_parser_type_name (parser
);
4938 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4942 expr
.value
= error_mark_node
;
4943 expr
.original_code
= ERROR_MARK
;
4947 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
4948 expr
.original_code
= ERROR_MARK
;
4952 c_parser_consume_token (parser
);
4953 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4955 expr
.value
= error_mark_node
;
4956 expr
.original_code
= ERROR_MARK
;
4959 t1
= c_parser_type_name (parser
);
4962 expr
.value
= error_mark_node
;
4963 expr
.original_code
= ERROR_MARK
;
4966 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4968 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4969 expr
.value
= error_mark_node
;
4970 expr
.original_code
= ERROR_MARK
;
4974 tree type
= groktypename (t1
);
4976 if (type
== error_mark_node
)
4977 offsetof_ref
= error_mark_node
;
4979 offsetof_ref
= build1 (INDIRECT_REF
, type
, NULL
);
4980 /* Parse the second argument to __builtin_offsetof. We
4981 must have one identifier, and beyond that we want to
4982 accept sub structure and sub array references. */
4983 if (c_parser_next_token_is (parser
, CPP_NAME
))
4985 offsetof_ref
= build_component_ref
4986 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
4987 c_parser_consume_token (parser
);
4988 while (c_parser_next_token_is (parser
, CPP_DOT
)
4989 || c_parser_next_token_is (parser
,
4992 if (c_parser_next_token_is (parser
, CPP_DOT
))
4994 c_parser_consume_token (parser
);
4995 if (c_parser_next_token_is_not (parser
,
4998 c_parser_error (parser
, "expected identifier");
5001 offsetof_ref
= build_component_ref
5003 c_parser_peek_token (parser
)->value
);
5004 c_parser_consume_token (parser
);
5009 c_parser_consume_token (parser
);
5010 idx
= c_parser_expression (parser
).value
;
5011 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5013 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
5018 c_parser_error (parser
, "expected identifier");
5019 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5021 expr
.value
= fold_offsetof (offsetof_ref
);
5022 expr
.original_code
= ERROR_MARK
;
5025 case RID_CHOOSE_EXPR
:
5026 c_parser_consume_token (parser
);
5027 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5029 expr
.value
= error_mark_node
;
5030 expr
.original_code
= ERROR_MARK
;
5033 e1
= c_parser_expr_no_commas (parser
, NULL
);
5034 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5036 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5037 expr
.value
= error_mark_node
;
5038 expr
.original_code
= ERROR_MARK
;
5041 e2
= c_parser_expr_no_commas (parser
, NULL
);
5042 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5044 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5045 expr
.value
= error_mark_node
;
5046 expr
.original_code
= ERROR_MARK
;
5049 e3
= c_parser_expr_no_commas (parser
, NULL
);
5050 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5055 c
= fold (e1
.value
);
5056 if (TREE_CODE (c
) != INTEGER_CST
)
5057 error ("first argument to %<__builtin_choose_expr%> not"
5059 expr
= integer_zerop (c
) ? e3
: e2
;
5062 case RID_TYPES_COMPATIBLE_P
:
5063 c_parser_consume_token (parser
);
5064 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5066 expr
.value
= error_mark_node
;
5067 expr
.original_code
= ERROR_MARK
;
5070 t1
= c_parser_type_name (parser
);
5073 expr
.value
= error_mark_node
;
5074 expr
.original_code
= ERROR_MARK
;
5077 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5079 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5080 expr
.value
= error_mark_node
;
5081 expr
.original_code
= ERROR_MARK
;
5084 t2
= c_parser_type_name (parser
);
5087 expr
.value
= error_mark_node
;
5088 expr
.original_code
= ERROR_MARK
;
5091 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5096 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5097 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5099 expr
.value
= comptypes (e1
, e2
)
5100 ? build_int_cst (NULL_TREE
, 1)
5101 : build_int_cst (NULL_TREE
, 0);
5102 expr
.original_code
= ERROR_MARK
;
5105 case RID_AT_SELECTOR
:
5106 gcc_assert (c_dialect_objc ());
5107 c_parser_consume_token (parser
);
5108 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5110 expr
.value
= error_mark_node
;
5111 expr
.original_code
= ERROR_MARK
;
5115 tree sel
= c_parser_objc_selector_arg (parser
);
5116 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5118 expr
.value
= objc_build_selector_expr (sel
);
5119 expr
.original_code
= ERROR_MARK
;
5122 case RID_AT_PROTOCOL
:
5123 gcc_assert (c_dialect_objc ());
5124 c_parser_consume_token (parser
);
5125 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5127 expr
.value
= error_mark_node
;
5128 expr
.original_code
= ERROR_MARK
;
5131 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5133 c_parser_error (parser
, "expected identifier");
5134 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5135 expr
.value
= error_mark_node
;
5136 expr
.original_code
= ERROR_MARK
;
5140 tree id
= c_parser_peek_token (parser
)->value
;
5141 c_parser_consume_token (parser
);
5142 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5144 expr
.value
= objc_build_protocol_expr (id
);
5145 expr
.original_code
= ERROR_MARK
;
5149 /* Extension to support C-structures in the archiver. */
5150 gcc_assert (c_dialect_objc ());
5151 c_parser_consume_token (parser
);
5152 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5154 expr
.value
= error_mark_node
;
5155 expr
.original_code
= ERROR_MARK
;
5158 t1
= c_parser_type_name (parser
);
5161 expr
.value
= error_mark_node
;
5162 expr
.original_code
= ERROR_MARK
;
5163 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5166 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5169 tree type
= groktypename (t1
);
5170 expr
.value
= objc_build_encode_expr (type
);
5171 expr
.original_code
= ERROR_MARK
;
5175 c_parser_error (parser
, "expected expression");
5176 expr
.value
= error_mark_node
;
5177 expr
.original_code
= ERROR_MARK
;
5181 case CPP_OPEN_SQUARE
:
5182 if (c_dialect_objc ())
5184 tree receiver
, args
;
5185 c_parser_consume_token (parser
);
5186 receiver
= c_parser_objc_receiver (parser
);
5187 args
= c_parser_objc_message_args (parser
);
5188 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5190 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5192 expr
.original_code
= ERROR_MARK
;
5195 /* Else fall through to report error. */
5197 c_parser_error (parser
, "expected expression");
5198 expr
.value
= error_mark_node
;
5199 expr
.original_code
= ERROR_MARK
;
5202 return c_parser_postfix_expression_after_primary (parser
, expr
);
5205 /* Parse a postfix expression after a parenthesized type name: the
5206 brace-enclosed initializer of a compound literal, possibly followed
5207 by some postfix operators. This is separate because it is not
5208 possible to tell until after the type name whether a cast
5209 expression has a cast or a compound literal, or whether the operand
5210 of sizeof is a parenthesized type name or starts with a compound
5213 static struct c_expr
5214 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5215 struct c_type_name
*type_name
)
5220 start_init (NULL_TREE
, NULL
, 0);
5221 type
= groktypename (type_name
);
5222 if (C_TYPE_VARIABLE_SIZE (type
))
5224 error ("compound literal has variable size");
5225 type
= error_mark_node
;
5227 init
= c_parser_braced_init (parser
, type
, false);
5229 maybe_warn_string_init (type
, init
);
5231 if (pedantic
&& !flag_isoc99
)
5232 pedwarn ("ISO C90 forbids compound literals");
5233 expr
.value
= build_compound_literal (type
, init
.value
);
5234 expr
.original_code
= ERROR_MARK
;
5235 return c_parser_postfix_expression_after_primary (parser
, expr
);
5238 /* Parse a postfix expression after the initial primary or compound
5239 literal; that is, parse a series of postfix operators. */
5241 static struct c_expr
5242 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5245 tree ident
, idx
, exprlist
;
5248 switch (c_parser_peek_token (parser
)->type
)
5250 case CPP_OPEN_SQUARE
:
5251 /* Array reference. */
5252 c_parser_consume_token (parser
);
5253 idx
= c_parser_expression (parser
).value
;
5254 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5256 expr
.value
= build_array_ref (expr
.value
, idx
);
5257 expr
.original_code
= ERROR_MARK
;
5259 case CPP_OPEN_PAREN
:
5260 /* Function call. */
5261 c_parser_consume_token (parser
);
5262 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5263 exprlist
= NULL_TREE
;
5265 exprlist
= c_parser_expr_list (parser
, true);
5266 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5268 expr
.value
= build_function_call (expr
.value
, exprlist
);
5269 expr
.original_code
= ERROR_MARK
;
5272 /* Structure element reference. */
5273 c_parser_consume_token (parser
);
5274 expr
= default_function_array_conversion (expr
);
5275 if (c_parser_next_token_is (parser
, CPP_NAME
))
5276 ident
= c_parser_peek_token (parser
)->value
;
5279 c_parser_error (parser
, "expected identifier");
5280 expr
.value
= error_mark_node
;
5281 expr
.original_code
= ERROR_MARK
;
5284 c_parser_consume_token (parser
);
5285 expr
.value
= build_component_ref (expr
.value
, ident
);
5286 expr
.original_code
= ERROR_MARK
;
5289 /* Structure element reference. */
5290 c_parser_consume_token (parser
);
5291 expr
= default_function_array_conversion (expr
);
5292 if (c_parser_next_token_is (parser
, CPP_NAME
))
5293 ident
= c_parser_peek_token (parser
)->value
;
5296 c_parser_error (parser
, "expected identifier");
5297 expr
.value
= error_mark_node
;
5298 expr
.original_code
= ERROR_MARK
;
5301 c_parser_consume_token (parser
);
5302 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5304 expr
.original_code
= ERROR_MARK
;
5307 /* Postincrement. */
5308 c_parser_consume_token (parser
);
5309 expr
= default_function_array_conversion (expr
);
5310 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5311 expr
.original_code
= ERROR_MARK
;
5313 case CPP_MINUS_MINUS
:
5314 /* Postdecrement. */
5315 c_parser_consume_token (parser
);
5316 expr
= default_function_array_conversion (expr
);
5317 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5318 expr
.original_code
= ERROR_MARK
;
5326 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5329 assignment-expression
5330 expression , assignment-expression
5333 static struct c_expr
5334 c_parser_expression (c_parser
*parser
)
5337 expr
= c_parser_expr_no_commas (parser
, NULL
);
5338 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5341 c_parser_consume_token (parser
);
5342 next
= c_parser_expr_no_commas (parser
, NULL
);
5343 next
= default_function_array_conversion (next
);
5344 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5345 expr
.original_code
= COMPOUND_EXPR
;
5350 /* Parse an expression and convert functions or arrays to
5353 static struct c_expr
5354 c_parser_expression_conv (c_parser
*parser
)
5357 expr
= c_parser_expression (parser
);
5358 expr
= default_function_array_conversion (expr
);
5362 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5363 functions and arrays to pointers.
5366 assignment-expression
5367 nonempty-expr-list , assignment-expression
5371 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5375 expr
= c_parser_expr_no_commas (parser
, NULL
);
5377 expr
= default_function_array_conversion (expr
);
5378 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5379 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5381 c_parser_consume_token (parser
);
5382 expr
= c_parser_expr_no_commas (parser
, NULL
);
5384 expr
= default_function_array_conversion (expr
);
5385 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5391 /* Parse Objective-C-specific constructs. */
5393 /* Parse an objc-class-definition.
5395 objc-class-definition:
5396 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5397 objc-class-instance-variables[opt] objc-methodprotolist @end
5398 @implementation identifier objc-superclass[opt]
5399 objc-class-instance-variables[opt]
5400 @interface identifier ( identifier ) objc-protocol-refs[opt]
5401 objc-methodprotolist @end
5402 @implementation identifier ( identifier )
5407 "@interface identifier (" must start "@interface identifier (
5408 identifier ) ...": objc-methodprotolist in the first production may
5409 not start with a parenthesized identifier as a declarator of a data
5410 definition with no declaration specifiers if the objc-superclass,
5411 objc-protocol-refs and objc-class-instance-variables are omitted. */
5414 c_parser_objc_class_definition (c_parser
*parser
)
5419 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5421 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5425 c_parser_consume_token (parser
);
5426 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5428 c_parser_error (parser
, "expected identifier");
5431 id1
= c_parser_peek_token (parser
)->value
;
5432 c_parser_consume_token (parser
);
5433 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5436 tree proto
= NULL_TREE
;
5437 c_parser_consume_token (parser
);
5438 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5440 c_parser_error (parser
, "expected identifier");
5441 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5444 id2
= c_parser_peek_token (parser
)->value
;
5445 c_parser_consume_token (parser
);
5446 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5449 objc_start_category_implementation (id1
, id2
);
5452 if (c_parser_next_token_is (parser
, CPP_LESS
))
5453 proto
= c_parser_objc_protocol_refs (parser
);
5454 objc_start_category_interface (id1
, id2
, proto
);
5455 c_parser_objc_methodprotolist (parser
);
5456 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5457 objc_finish_interface ();
5460 if (c_parser_next_token_is (parser
, CPP_COLON
))
5462 c_parser_consume_token (parser
);
5463 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5465 c_parser_error (parser
, "expected identifier");
5468 superclass
= c_parser_peek_token (parser
)->value
;
5469 c_parser_consume_token (parser
);
5472 superclass
= NULL_TREE
;
5475 tree proto
= NULL_TREE
;
5476 if (c_parser_next_token_is (parser
, CPP_LESS
))
5477 proto
= c_parser_objc_protocol_refs (parser
);
5478 objc_start_class_interface (id1
, superclass
, proto
);
5481 objc_start_class_implementation (id1
, superclass
);
5482 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5483 c_parser_objc_class_instance_variables (parser
);
5486 objc_continue_interface ();
5487 c_parser_objc_methodprotolist (parser
);
5488 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5489 objc_finish_interface ();
5493 objc_continue_implementation ();
5498 /* Parse objc-class-instance-variables.
5500 objc-class-instance-variables:
5501 { objc-instance-variable-decl-list[opt] }
5503 objc-instance-variable-decl-list:
5504 objc-visibility-spec
5505 objc-instance-variable-decl ;
5507 objc-instance-variable-decl-list objc-visibility-spec
5508 objc-instance-variable-decl-list objc-instance-variable-decl ;
5509 objc-instance-variable-decl-list ;
5511 objc-visibility-spec:
5516 objc-instance-variable-decl:
5521 c_parser_objc_class_instance_variables (c_parser
*parser
)
5523 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5524 c_parser_consume_token (parser
);
5525 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5528 /* Parse any stray semicolon. */
5529 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5532 pedwarn ("extra semicolon in struct or union specified");
5533 c_parser_consume_token (parser
);
5536 /* Stop if at the end of the instance variables. */
5537 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5539 c_parser_consume_token (parser
);
5542 /* Parse any objc-visibility-spec. */
5543 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5545 c_parser_consume_token (parser
);
5546 objc_set_visibility (2);
5549 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5551 c_parser_consume_token (parser
);
5552 objc_set_visibility (0);
5555 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5557 c_parser_consume_token (parser
);
5558 objc_set_visibility (1);
5561 /* Parse some comma-separated declarations. */
5562 decls
= c_parser_struct_declaration (parser
);
5564 /* Comma-separated instance variables are chained together in
5565 reverse order; add them one by one. */
5566 tree ivar
= nreverse (decls
);
5567 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5568 objc_add_instance_variable (copy_node (ivar
));
5570 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5574 /* Parse an objc-class-declaration.
5576 objc-class-declaration:
5577 @class identifier-list ;
5581 c_parser_objc_class_declaration (c_parser
*parser
)
5583 tree list
= NULL_TREE
;
5584 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5585 c_parser_consume_token (parser
);
5586 /* Any identifiers, including those declared as type names, are OK
5591 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5593 c_parser_error (parser
, "expected identifier");
5596 id
= c_parser_peek_token (parser
)->value
;
5597 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5598 c_parser_consume_token (parser
);
5599 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5600 c_parser_consume_token (parser
);
5604 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5605 objc_declare_class (list
);
5608 /* Parse an objc-alias-declaration.
5610 objc-alias-declaration:
5611 @compatibility_alias identifier identifier ;
5615 c_parser_objc_alias_declaration (c_parser
*parser
)
5618 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5619 c_parser_consume_token (parser
);
5620 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5622 c_parser_error (parser
, "expected identifier");
5623 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5626 id1
= c_parser_peek_token (parser
)->value
;
5627 c_parser_consume_token (parser
);
5628 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5630 c_parser_error (parser
, "expected identifier");
5631 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5634 id2
= c_parser_peek_token (parser
)->value
;
5635 c_parser_consume_token (parser
);
5636 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5637 objc_declare_alias (id1
, id2
);
5640 /* Parse an objc-protocol-definition.
5642 objc-protocol-definition:
5643 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5644 @protocol identifier-list ;
5646 "@protocol identifier ;" should be resolved as "@protocol
5647 identifier-list ;": objc-methodprotolist may not start with a
5648 semicolon in the first alternative if objc-protocol-refs are
5652 c_parser_objc_protocol_definition (c_parser
*parser
)
5654 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5655 c_parser_consume_token (parser
);
5656 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5658 c_parser_error (parser
, "expected identifier");
5661 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5662 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5664 tree list
= NULL_TREE
;
5665 /* Any identifiers, including those declared as type names, are
5670 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5672 c_parser_error (parser
, "expected identifier");
5675 id
= c_parser_peek_token (parser
)->value
;
5676 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5677 c_parser_consume_token (parser
);
5678 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5679 c_parser_consume_token (parser
);
5683 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5684 objc_declare_protocols (list
);
5688 tree id
= c_parser_peek_token (parser
)->value
;
5689 tree proto
= NULL_TREE
;
5690 c_parser_consume_token (parser
);
5691 if (c_parser_next_token_is (parser
, CPP_LESS
))
5692 proto
= c_parser_objc_protocol_refs (parser
);
5693 objc_pq_context
= 1;
5694 objc_start_protocol (id
, proto
);
5695 c_parser_objc_methodprotolist (parser
);
5696 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5697 objc_pq_context
= 0;
5698 objc_finish_interface ();
5702 /* Parse an objc-method-type.
5709 static enum tree_code
5710 c_parser_objc_method_type (c_parser
*parser
)
5712 switch (c_parser_peek_token (parser
)->type
)
5715 c_parser_consume_token (parser
);
5718 c_parser_consume_token (parser
);
5725 /* Parse an objc-method-definition.
5727 objc-method-definition:
5728 objc-method-type objc-method-decl ;[opt] compound-statement
5732 c_parser_objc_method_definition (c_parser
*parser
)
5734 enum tree_code type
= c_parser_objc_method_type (parser
);
5736 objc_set_method_type (type
);
5737 objc_pq_context
= 1;
5738 decl
= c_parser_objc_method_decl (parser
);
5739 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5741 c_parser_consume_token (parser
);
5743 pedwarn ("extra semicolon in method definition specified");
5745 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5747 c_parser_error (parser
, "expected %<{%>");
5750 objc_pq_context
= 0;
5751 objc_start_method_definition (decl
);
5752 add_stmt (c_parser_compound_statement (parser
));
5753 objc_finish_method_definition (current_function_decl
);
5756 /* Parse an objc-methodprotolist.
5758 objc-methodprotolist:
5760 objc-methodprotolist objc-methodproto
5761 objc-methodprotolist declaration
5762 objc-methodprotolist ;
5764 The declaration is a data definition, which may be missing
5765 declaration specifiers under the same rules and diagnostics as
5766 other data definitions outside functions, and the stray semicolon
5767 is diagnosed the same way as a stray semicolon outside a
5771 c_parser_objc_methodprotolist (c_parser
*parser
)
5775 /* The list is terminated by @end. */
5776 switch (c_parser_peek_token (parser
)->type
)
5780 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5781 c_parser_consume_token (parser
);
5785 c_parser_objc_methodproto (parser
);
5790 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
5792 c_parser_declaration_or_fndef (parser
, false, true, false, true);
5798 /* Parse an objc-methodproto.
5801 objc-method-type objc-method-decl ;
5805 c_parser_objc_methodproto (c_parser
*parser
)
5807 enum tree_code type
= c_parser_objc_method_type (parser
);
5809 objc_set_method_type (type
);
5810 /* Remember protocol qualifiers in prototypes. */
5811 objc_pq_context
= 1;
5812 decl
= c_parser_objc_method_decl (parser
);
5813 /* Forget protocol qualifiers here. */
5814 objc_pq_context
= 0;
5815 objc_add_method_declaration (decl
);
5816 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5819 /* Parse an objc-method-decl.
5822 ( objc-type-name ) objc-selector
5824 ( objc-type-name ) objc-keyword-selector objc-optparmlist
5825 objc-keyword-selector objc-optparmlist
5827 objc-keyword-selector:
5829 objc-keyword-selector objc-keyword-decl
5832 objc-selector : ( objc-type-name ) identifier
5833 objc-selector : identifier
5834 : ( objc-type-name ) identifier
5838 objc-optparms objc-optellipsis
5842 objc-opt-parms , parameter-declaration
5850 c_parser_objc_method_decl (c_parser
*parser
)
5852 tree type
= NULL_TREE
;
5854 tree parms
= NULL_TREE
;
5855 bool ellipsis
= false;
5857 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5859 c_parser_consume_token (parser
);
5860 type
= c_parser_objc_type_name (parser
);
5861 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5863 sel
= c_parser_objc_selector (parser
);
5864 /* If there is no selector, or a colon follows, we have an
5865 objc-keyword-selector. If there is a selector, and a colon does
5866 not follow, that selector ends the objc-method-decl. */
5867 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
5870 tree list
= NULL_TREE
;
5873 tree atype
= NULL_TREE
, id
, keyworddecl
;
5874 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5876 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5878 c_parser_consume_token (parser
);
5879 atype
= c_parser_objc_type_name (parser
);
5880 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5883 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5885 c_parser_error (parser
, "expected identifier");
5886 return error_mark_node
;
5888 id
= c_parser_peek_token (parser
)->value
;
5889 c_parser_consume_token (parser
);
5890 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
5891 list
= chainon (list
, keyworddecl
);
5892 tsel
= c_parser_objc_selector (parser
);
5893 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
5896 /* Parse the optional parameter list. Optional Objective-C
5897 method parameters follow the C syntax, and may include '...'
5898 to denote a variable number of arguments. */
5899 parms
= make_node (TREE_LIST
);
5900 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5902 struct c_parm
*parm
;
5903 c_parser_consume_token (parser
);
5904 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5907 c_parser_consume_token (parser
);
5910 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5913 parms
= chainon (parms
,
5914 build_tree_list (NULL_TREE
, grokparm (parm
)));
5918 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
5921 /* Parse an objc-type-name.
5924 objc-type-qualifiers[opt] type-name
5925 objc-type-qualifiers[opt]
5927 objc-type-qualifiers:
5929 objc-type-qualifiers objc-type-qualifier
5931 objc-type-qualifier: one of
5932 in out inout bycopy byref oneway
5936 c_parser_objc_type_name (c_parser
*parser
)
5938 tree quals
= NULL_TREE
;
5939 struct c_type_name
*typename
= NULL
;
5940 tree type
= NULL_TREE
;
5943 c_token
*token
= c_parser_peek_token (parser
);
5944 if (token
->type
== CPP_KEYWORD
5945 && (token
->keyword
== RID_IN
5946 || token
->keyword
== RID_OUT
5947 || token
->keyword
== RID_INOUT
5948 || token
->keyword
== RID_BYCOPY
5949 || token
->keyword
== RID_BYREF
5950 || token
->keyword
== RID_ONEWAY
))
5952 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
5953 c_parser_consume_token (parser
);
5958 if (c_parser_next_token_starts_typename (parser
))
5959 typename
= c_parser_type_name (parser
);
5961 type
= groktypename (typename
);
5962 return build_tree_list (quals
, type
);
5965 /* Parse objc-protocol-refs.
5972 c_parser_objc_protocol_refs (c_parser
*parser
)
5974 tree list
= NULL_TREE
;
5975 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
5976 c_parser_consume_token (parser
);
5977 /* Any identifiers, including those declared as type names, are OK
5982 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5984 c_parser_error (parser
, "expected identifier");
5987 id
= c_parser_peek_token (parser
)->value
;
5988 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5989 c_parser_consume_token (parser
);
5990 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5991 c_parser_consume_token (parser
);
5995 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
5999 /* Parse an objc-try-catch-statement.
6001 objc-try-catch-statement:
6002 @try compound-statement objc-catch-list[opt]
6003 @try compound-statement objc-catch-list[opt] @finally compound-statement
6006 @catch ( parameter-declaration ) compound-statement
6007 objc-catch-list @catch ( parameter-declaration ) compound-statement
6011 c_parser_objc_try_catch_statement (c_parser
*parser
)
6015 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
6016 c_parser_consume_token (parser
);
6017 loc
= c_parser_peek_token (parser
)->location
;
6018 stmt
= c_parser_compound_statement (parser
);
6019 objc_begin_try_stmt (loc
, stmt
);
6020 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
6022 struct c_parm
*parm
;
6023 c_parser_consume_token (parser
);
6024 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6026 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6032 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6033 objc_begin_catch_clause (grokparm (parm
));
6034 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6035 c_parser_compound_statement_nostart (parser
);
6036 objc_finish_catch_clause ();
6038 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6042 c_parser_consume_token (parser
);
6043 finloc
= c_parser_peek_token (parser
)->location
;
6044 finstmt
= c_parser_compound_statement (parser
);
6045 objc_build_finally_clause (finloc
, finstmt
);
6047 objc_finish_try_stmt ();
6050 /* Parse an objc-synchronized-statement.
6052 objc-synchronized-statement:
6053 @synchronized ( expression ) compound-statement
6057 c_parser_objc_synchronized_statement (c_parser
*parser
)
6061 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6062 c_parser_consume_token (parser
);
6063 loc
= c_parser_peek_token (parser
)->location
;
6064 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6066 expr
= c_parser_expression (parser
).value
;
6067 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6070 expr
= error_mark_node
;
6071 stmt
= c_parser_compound_statement (parser
);
6072 objc_build_synchronized (loc
, expr
, stmt
);
6075 /* Parse an objc-selector; return NULL_TREE without an error if the
6076 next token is not an objc-selector.
6081 enum struct union if else while do for switch case default
6082 break continue return goto asm sizeof typeof __alignof
6083 unsigned long const short volatile signed restrict _Complex
6084 in out inout bycopy byref oneway int char float double void _Bool
6086 ??? Why this selection of keywords but not, for example, storage
6087 class specifiers? */
6090 c_parser_objc_selector (c_parser
*parser
)
6092 c_token
*token
= c_parser_peek_token (parser
);
6093 tree value
= token
->value
;
6094 if (token
->type
== CPP_NAME
)
6096 c_parser_consume_token (parser
);
6099 if (token
->type
!= CPP_KEYWORD
)
6101 switch (token
->keyword
)
6142 c_parser_consume_token (parser
);
6149 /* Parse an objc-selector-arg.
6153 objc-keywordname-list
6155 objc-keywordname-list:
6157 objc-keywordname-list objc-keywordname
6165 c_parser_objc_selector_arg (c_parser
*parser
)
6167 tree sel
= c_parser_objc_selector (parser
);
6168 tree list
= NULL_TREE
;
6169 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6173 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6175 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6176 sel
= c_parser_objc_selector (parser
);
6177 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6183 /* Parse an objc-receiver.
6192 c_parser_objc_receiver (c_parser
*parser
)
6194 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6195 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6196 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6198 tree id
= c_parser_peek_token (parser
)->value
;
6199 c_parser_consume_token (parser
);
6200 return objc_get_class_reference (id
);
6202 return c_parser_expression (parser
).value
;
6205 /* Parse objc-message-args.
6209 objc-keywordarg-list
6211 objc-keywordarg-list:
6213 objc-keywordarg-list objc-keywordarg
6216 objc-selector : objc-keywordexpr
6221 c_parser_objc_message_args (c_parser
*parser
)
6223 tree sel
= c_parser_objc_selector (parser
);
6224 tree list
= NULL_TREE
;
6225 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6230 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6232 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6233 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6234 sel
= c_parser_objc_selector (parser
);
6235 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6241 /* Parse an objc-keywordexpr.
6248 c_parser_objc_keywordexpr (c_parser
*parser
)
6250 tree list
= c_parser_expr_list (parser
, true);
6251 if (TREE_CHAIN (list
) == NULL_TREE
)
6253 /* Just return the expression, remove a level of
6255 return TREE_VALUE (list
);
6259 /* We have a comma expression, we will collapse later. */
6265 /* The actual parser and external interface. ??? Does this need to be
6266 garbage-collected? */
6268 static GTY (()) c_parser
*the_parser
;
6270 /* Parse a single source file. */
6275 the_parser
= c_parser_new ();
6276 c_parser_translation_unit (the_parser
);
6280 #include "gt-c-parser.h"