1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 Parser actions based on the old Bison parser; structure somewhat
6 influenced by and fragments based on the C++ parser.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
45 #include "langhooks.h"
58 /* Miscellaneous data and functions needed for the parser. */
62 /* Objective-C specific parser/lexer information. */
64 static int objc_pq_context
= 0;
66 /* The following flag is needed to contextualize Objective-C lexical
67 analysis. In some cases (e.g., 'int NSObject;'), it is undesirable
68 to bind an identifier to an Objective-C class, even if a class with
70 static int objc_need_raw_identifier
= 0;
71 #define OBJC_NEED_RAW_IDENTIFIER(VAL) \
73 if (c_dialect_objc ()) \
74 objc_need_raw_identifier = VAL; \
77 /* The reserved keyword table. */
81 ENUM_BITFIELD(rid
) rid
: 16;
82 unsigned int disable
: 16;
85 /* Disable mask. Keywords are disabled if (reswords[i].disable &
87 #define D_C89 0x01 /* not in C89 */
88 #define D_EXT 0x02 /* GCC extension */
89 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
90 #define D_OBJC 0x08 /* Objective C only */
92 static const struct resword reswords
[] =
94 { "_Bool", RID_BOOL
, 0 },
95 { "_Complex", RID_COMPLEX
, 0 },
96 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
97 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
98 { "__alignof", RID_ALIGNOF
, 0 },
99 { "__alignof__", RID_ALIGNOF
, 0 },
100 { "__asm", RID_ASM
, 0 },
101 { "__asm__", RID_ASM
, 0 },
102 { "__attribute", RID_ATTRIBUTE
, 0 },
103 { "__attribute__", RID_ATTRIBUTE
, 0 },
104 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
105 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
106 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
107 { "__builtin_va_arg", RID_VA_ARG
, 0 },
108 { "__complex", RID_COMPLEX
, 0 },
109 { "__complex__", RID_COMPLEX
, 0 },
110 { "__const", RID_CONST
, 0 },
111 { "__const__", RID_CONST
, 0 },
112 { "__extension__", RID_EXTENSION
, 0 },
113 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
114 { "__imag", RID_IMAGPART
, 0 },
115 { "__imag__", RID_IMAGPART
, 0 },
116 { "__inline", RID_INLINE
, 0 },
117 { "__inline__", RID_INLINE
, 0 },
118 { "__label__", RID_LABEL
, 0 },
119 { "__real", RID_REALPART
, 0 },
120 { "__real__", RID_REALPART
, 0 },
121 { "__restrict", RID_RESTRICT
, 0 },
122 { "__restrict__", RID_RESTRICT
, 0 },
123 { "__signed", RID_SIGNED
, 0 },
124 { "__signed__", RID_SIGNED
, 0 },
125 { "__thread", RID_THREAD
, 0 },
126 { "__typeof", RID_TYPEOF
, 0 },
127 { "__typeof__", RID_TYPEOF
, 0 },
128 { "__volatile", RID_VOLATILE
, 0 },
129 { "__volatile__", RID_VOLATILE
, 0 },
130 { "asm", RID_ASM
, D_EXT
},
131 { "auto", RID_AUTO
, 0 },
132 { "break", RID_BREAK
, 0 },
133 { "case", RID_CASE
, 0 },
134 { "char", RID_CHAR
, 0 },
135 { "const", RID_CONST
, 0 },
136 { "continue", RID_CONTINUE
, 0 },
137 { "default", RID_DEFAULT
, 0 },
139 { "double", RID_DOUBLE
, 0 },
140 { "else", RID_ELSE
, 0 },
141 { "enum", RID_ENUM
, 0 },
142 { "extern", RID_EXTERN
, 0 },
143 { "float", RID_FLOAT
, 0 },
144 { "for", RID_FOR
, 0 },
145 { "goto", RID_GOTO
, 0 },
147 { "inline", RID_INLINE
, D_EXT89
},
148 { "int", RID_INT
, 0 },
149 { "long", RID_LONG
, 0 },
150 { "register", RID_REGISTER
, 0 },
151 { "restrict", RID_RESTRICT
, D_C89
},
152 { "return", RID_RETURN
, 0 },
153 { "short", RID_SHORT
, 0 },
154 { "signed", RID_SIGNED
, 0 },
155 { "sizeof", RID_SIZEOF
, 0 },
156 { "static", RID_STATIC
, 0 },
157 { "struct", RID_STRUCT
, 0 },
158 { "switch", RID_SWITCH
, 0 },
159 { "typedef", RID_TYPEDEF
, 0 },
160 { "typeof", RID_TYPEOF
, D_EXT
},
161 { "union", RID_UNION
, 0 },
162 { "unsigned", RID_UNSIGNED
, 0 },
163 { "void", RID_VOID
, 0 },
164 { "volatile", RID_VOLATILE
, 0 },
165 { "while", RID_WHILE
, 0 },
166 /* These Objective-C keywords are recognized only immediately after
168 { "class", RID_AT_CLASS
, D_OBJC
},
169 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
170 { "defs", RID_AT_DEFS
, D_OBJC
},
171 { "encode", RID_AT_ENCODE
, D_OBJC
},
172 { "end", RID_AT_END
, D_OBJC
},
173 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
174 { "interface", RID_AT_INTERFACE
, D_OBJC
},
175 { "private", RID_AT_PRIVATE
, D_OBJC
},
176 { "protected", RID_AT_PROTECTED
, D_OBJC
},
177 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
178 { "public", RID_AT_PUBLIC
, D_OBJC
},
179 { "selector", RID_AT_SELECTOR
, D_OBJC
},
180 { "throw", RID_AT_THROW
, D_OBJC
},
181 { "try", RID_AT_TRY
, D_OBJC
},
182 { "catch", RID_AT_CATCH
, D_OBJC
},
183 { "finally", RID_AT_FINALLY
, D_OBJC
},
184 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
185 /* These are recognized only in protocol-qualifier context
187 { "bycopy", RID_BYCOPY
, D_OBJC
},
188 { "byref", RID_BYREF
, D_OBJC
},
189 { "in", RID_IN
, D_OBJC
},
190 { "inout", RID_INOUT
, D_OBJC
},
191 { "oneway", RID_ONEWAY
, D_OBJC
},
192 { "out", RID_OUT
, D_OBJC
},
194 #define N_reswords (sizeof reswords / sizeof (struct resword))
196 /* Initialization routine for this file. */
201 /* The only initialization required is of the reserved word
205 int mask
= (flag_isoc99
? 0 : D_C89
)
206 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
208 if (!c_dialect_objc ())
211 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
212 for (i
= 0; i
< N_reswords
; i
++)
214 /* If a keyword is disabled, do not enter it into the table
215 and so create a canonical spelling that isn't a keyword. */
216 if (reswords
[i
].disable
& mask
)
219 id
= get_identifier (reswords
[i
].word
);
220 C_RID_CODE (id
) = reswords
[i
].rid
;
221 C_IS_RESERVED_WORD (id
) = 1;
222 ridpointers
[(int) reswords
[i
].rid
] = id
;
226 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
227 and the C parser. Unlike the C++ lexer, the parser structure
228 stores the lexer information instead of using a separate structure.
229 Identifiers are separated into ordinary identifiers, type names,
230 keywords and some other Objective-C types of identifiers, and some
231 look-ahead is maintained.
233 ??? It might be a good idea to lex the whole file up front (as for
234 C++). It would then be possible to share more of the C and C++
235 lexer code, if desired. */
237 /* The following local token type is used. */
240 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
242 /* The number of token types, including C-specific ones. */
243 #define N_C_TTYPES ((int) (CPP_KEYWORD + 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
)
481 if (c_dialect_objc ())
489 /* Return true if the next token from PARSER can start a type name,
492 c_parser_next_token_starts_typename (c_parser
*parser
)
494 c_token
*token
= c_parser_peek_token (parser
);
495 return c_token_starts_typename (token
);
498 /* Return true if TOKEN can start declaration specifiers, false
501 c_token_starts_declspecs (c_token
*token
)
506 switch (token
->id_kind
)
513 gcc_assert (c_dialect_objc ());
519 switch (token
->keyword
)
552 if (c_dialect_objc ())
560 /* Return true if the next token from PARSER can start declaration
561 specifiers, false otherwise. */
563 c_parser_next_token_starts_declspecs (c_parser
*parser
)
565 c_token
*token
= c_parser_peek_token (parser
);
566 return c_token_starts_declspecs (token
);
569 /* Return a pointer to the next-but-one token from PARSER, reading it
570 in if necessary. The next token is already read in. */
573 c_parser_peek_2nd_token (c_parser
*parser
)
575 if (parser
->tokens_avail
>= 2)
576 return &parser
->tokens
[1];
577 gcc_assert (parser
->tokens_avail
== 1);
578 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
579 c_lex_one_token (&parser
->tokens
[1]);
580 parser
->tokens_avail
= 2;
581 return &parser
->tokens
[1];
584 /* Consume the next token from PARSER. */
587 c_parser_consume_token (c_parser
*parser
)
589 if (parser
->tokens_avail
== 2)
590 parser
->tokens
[0] = parser
->tokens
[1];
593 gcc_assert (parser
->tokens_avail
== 1);
594 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
596 parser
->tokens_avail
--;
599 /* Update the globals input_location and in_system_header from
602 c_parser_set_source_position_from_token (c_token
*token
)
604 if (token
->type
!= CPP_EOF
)
606 input_location
= token
->location
;
607 in_system_header
= token
->in_system_header
;
611 /* Allocate a new parser. */
616 /* Use local storage to lex the first token because loading a PCH
617 file may cause garbage collection. */
620 memset (&tparser
, 0, sizeof tparser
);
621 c_lex_one_token (&tparser
.tokens
[0]);
622 tparser
.tokens_avail
= 1;
623 ret
= GGC_NEW (c_parser
);
624 memcpy (ret
, &tparser
, sizeof tparser
);
628 /* Issue a diagnostic of the form
629 FILE:LINE: MESSAGE before TOKEN
630 where TOKEN is the next token in the input stream of PARSER.
631 MESSAGE (specified by the caller) is usually of the form "expected
634 Do not issue a diagnostic if still recovering from an error.
636 ??? This is taken from the C++ parser, but building up messages in
637 this way is not i18n-friendly and some other approach should be
641 c_parser_error (c_parser
*parser
, const char *msgid
)
643 c_token
*token
= c_parser_peek_token (parser
);
646 parser
->error
= true;
649 /* This diagnostic makes more sense if it is tagged to the line of
650 the token we just peeked at. */
651 c_parser_set_source_position_from_token (token
);
652 c_parse_error (msgid
,
653 /* Because c_parse_error does not understand
654 CPP_KEYWORD, keywords are treated like
656 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
660 /* If the next token is of the indicated TYPE, consume it. Otherwise,
661 issue the error MSGID. If MSGID is NULL then a message has already
662 been produced and no message will be produced this time. Returns
663 true if found, false otherwise. */
666 c_parser_require (c_parser
*parser
,
670 if (c_parser_next_token_is (parser
, type
))
672 c_parser_consume_token (parser
);
677 c_parser_error (parser
, msgid
);
682 /* If the next token is the indicated keyword, consume it. Otherwise,
683 issue the error MSGID. Returns true if found, false otherwise. */
686 c_parser_require_keyword (c_parser
*parser
,
690 if (c_parser_next_token_is_keyword (parser
, keyword
))
692 c_parser_consume_token (parser
);
697 c_parser_error (parser
, msgid
);
702 /* Like c_parser_require, except that tokens will be skipped until the
703 desired token is found. An error message is still produced if the
704 next token is not as expected. If MSGID is NULL then a message has
705 already been produced and no message will be produced this
709 c_parser_skip_until_found (c_parser
*parser
,
713 unsigned nesting_depth
= 0;
715 if (c_parser_require (parser
, type
, msgid
))
718 /* Skip tokens until the desired token is found. */
721 /* Peek at the next token. */
722 c_token
*token
= c_parser_peek_token (parser
);
723 /* If we've reached the token we want, consume it and stop. */
724 if (token
->type
== type
&& !nesting_depth
)
726 c_parser_consume_token (parser
);
729 /* If we've run out of tokens, stop. */
730 if (token
->type
== CPP_EOF
)
732 if (token
->type
== CPP_OPEN_BRACE
733 || token
->type
== CPP_OPEN_PAREN
734 || token
->type
== CPP_OPEN_SQUARE
)
736 else if (token
->type
== CPP_CLOSE_BRACE
737 || token
->type
== CPP_CLOSE_PAREN
738 || token
->type
== CPP_CLOSE_SQUARE
)
740 if (nesting_depth
-- == 0)
743 /* Consume this token. */
744 c_parser_consume_token (parser
);
746 parser
->error
= false;
749 /* Skip tokens until the end of a parameter is found, but do not
750 consume the comma, semicolon or closing delimiter. */
753 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
755 unsigned nesting_depth
= 0;
759 c_token
*token
= c_parser_peek_token (parser
);
760 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
763 /* If we've run out of tokens, stop. */
764 if (token
->type
== CPP_EOF
)
766 if (token
->type
== CPP_OPEN_BRACE
767 || token
->type
== CPP_OPEN_PAREN
768 || token
->type
== CPP_OPEN_SQUARE
)
770 else if (token
->type
== CPP_CLOSE_BRACE
771 || token
->type
== CPP_CLOSE_PAREN
772 || token
->type
== CPP_CLOSE_SQUARE
)
774 if (nesting_depth
-- == 0)
777 /* Consume this token. */
778 c_parser_consume_token (parser
);
780 parser
->error
= false;
783 /* Skip tokens until we have consumed an entire block, or until we
784 have consumed a non-nested ';'. */
787 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
789 unsigned nesting_depth
= 0;
795 /* Peek at the next token. */
796 token
= c_parser_peek_token (parser
);
797 /* If we've run out of tokens, stop. */
798 if (token
->type
== CPP_EOF
)
800 /* If the next token is a ';', we have reached the end of the
802 if (token
->type
== CPP_SEMICOLON
&& !nesting_depth
)
804 /* Consume the ';'. */
805 c_parser_consume_token (parser
);
808 /* If the next token is a non-nested '}', then we have reached
809 the end of the current block. */
810 if (token
->type
== CPP_CLOSE_BRACE
811 && (nesting_depth
== 0 || --nesting_depth
== 0))
813 c_parser_consume_token (parser
);
816 /* If it the next token is a '{', then we are entering a new
817 block. Consume the entire block. */
818 if (token
->type
== CPP_OPEN_BRACE
)
820 c_parser_consume_token (parser
);
822 parser
->error
= false;
826 /* Save the warning flags which are controlled by __extension__. */
829 disable_extension_diagnostics (void)
832 | (warn_pointer_arith
<< 1)
833 | (warn_traditional
<< 2)
836 warn_pointer_arith
= 0;
837 warn_traditional
= 0;
842 /* Restore the warning flags which are controlled by __extension__.
843 FLAGS is the return value from disable_extension_diagnostics. */
846 restore_extension_diagnostics (int flags
)
848 pedantic
= flags
& 1;
849 warn_pointer_arith
= (flags
>> 1) & 1;
850 warn_traditional
= (flags
>> 2) & 1;
851 flag_iso
= (flags
>> 3) & 1;
854 /* Possibly kinds of declarator to parse. */
855 typedef enum c_dtr_syn
{
856 /* A normal declarator with an identifier. */
858 /* An abstract declarator (maybe empty). */
860 /* A parameter declarator: may be either, but after a type name does
861 not redeclare a typedef name as an identifier if it can
862 alternatively be interpreted as a typedef name; see DR#009,
863 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
864 following DR#249. For example, given a typedef T, "int T" and
865 "int *T" are valid parameter declarations redeclaring T, while
866 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
867 abstract declarators rather than involving redundant parentheses;
868 the same applies with attributes inside the parentheses before
873 static void c_parser_external_declaration (c_parser
*);
874 static void c_parser_asm_definition (c_parser
*);
875 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
876 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
878 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
879 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
880 static tree
c_parser_struct_declaration (c_parser
*);
881 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
882 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
884 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
886 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
888 struct c_declarator
*);
889 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
890 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
891 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
892 static tree
c_parser_simple_asm_expr (c_parser
*);
893 static tree
c_parser_attributes (c_parser
*);
894 static struct c_type_name
*c_parser_type_name (c_parser
*);
895 static struct c_expr
c_parser_initializer (c_parser
*);
896 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
897 static void c_parser_initelt (c_parser
*);
898 static void c_parser_initval (c_parser
*, struct c_expr
*);
899 static tree
c_parser_compound_statement (c_parser
*);
900 static void c_parser_compound_statement_nostart (c_parser
*);
901 static void c_parser_label (c_parser
*);
902 static void c_parser_statement (c_parser
*);
903 static void c_parser_statement_after_labels (c_parser
*);
904 static void c_parser_if_statement (c_parser
*);
905 static void c_parser_switch_statement (c_parser
*);
906 static void c_parser_while_statement (c_parser
*);
907 static void c_parser_do_statement (c_parser
*);
908 static void c_parser_for_statement (c_parser
*);
909 static tree
c_parser_asm_statement (c_parser
*);
910 static tree
c_parser_asm_operands (c_parser
*);
911 static tree
c_parser_asm_clobbers (c_parser
*);
912 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
913 static struct c_expr
c_parser_conditional_expression (c_parser
*,
915 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
916 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
917 static struct c_expr
c_parser_unary_expression (c_parser
*);
918 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
919 static struct c_expr
c_parser_alignof_expression (c_parser
*);
920 static struct c_expr
c_parser_postfix_expression (c_parser
*);
921 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
922 struct c_type_name
*);
923 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
925 static struct c_expr
c_parser_expression (c_parser
*);
926 static tree
c_parser_expr_list (c_parser
*);
928 /* These Objective-C parser functions are only ever called when
929 compiling Objective-C. */
930 static void c_parser_objc_class_definition (c_parser
*);
931 static void c_parser_objc_class_instance_variables (c_parser
*);
932 static void c_parser_objc_class_declaration (c_parser
*);
933 static void c_parser_objc_alias_declaration (c_parser
*);
934 static void c_parser_objc_protocol_definition (c_parser
*);
935 static enum tree_code
c_parser_objc_method_type (c_parser
*);
936 static void c_parser_objc_method_definition (c_parser
*);
937 static void c_parser_objc_methodprotolist (c_parser
*);
938 static void c_parser_objc_methodproto (c_parser
*);
939 static tree
c_parser_objc_method_decl (c_parser
*);
940 static tree
c_parser_objc_type_name (c_parser
*);
941 static tree
c_parser_objc_protocol_refs (c_parser
*);
942 static void c_parser_objc_try_catch_statement (c_parser
*);
943 static void c_parser_objc_synchronized_statement (c_parser
*);
944 static tree
c_parser_objc_selector (c_parser
*);
945 static tree
c_parser_objc_selector_arg (c_parser
*);
946 static tree
c_parser_objc_receiver (c_parser
*);
947 static tree
c_parser_objc_message_args (c_parser
*);
948 static tree
c_parser_objc_keywordexpr (c_parser
*);
950 /* Parse a translation unit (C90 6.7, C99 6.9).
953 external-declarations
955 external-declarations:
957 external-declarations external-declaration
966 c_parser_translation_unit (c_parser
*parser
)
968 if (c_parser_next_token_is (parser
, CPP_EOF
))
971 pedwarn ("ISO C forbids an empty source file");
975 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
979 c_parser_external_declaration (parser
);
980 obstack_free (&parser_obstack
, obstack_position
);
982 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
986 /* Parse an external declaration (C90 6.7, C99 6.9).
988 external-declaration:
994 external-declaration:
997 __extension__ external-declaration
1001 external-declaration:
1002 objc-class-definition
1003 objc-class-declaration
1004 objc-alias-declaration
1005 objc-protocol-definition
1006 objc-method-definition
1011 c_parser_external_declaration (c_parser
*parser
)
1014 switch (c_parser_peek_token (parser
)->type
)
1017 switch (c_parser_peek_token (parser
)->keyword
)
1020 ext
= disable_extension_diagnostics ();
1021 c_parser_consume_token (parser
);
1022 c_parser_external_declaration (parser
);
1023 restore_extension_diagnostics (ext
);
1026 c_parser_asm_definition (parser
);
1028 case RID_AT_INTERFACE
:
1029 case RID_AT_IMPLEMENTATION
:
1030 gcc_assert (c_dialect_objc ());
1031 c_parser_objc_class_definition (parser
);
1034 gcc_assert (c_dialect_objc ());
1035 c_parser_objc_class_declaration (parser
);
1038 gcc_assert (c_dialect_objc ());
1039 c_parser_objc_alias_declaration (parser
);
1041 case RID_AT_PROTOCOL
:
1042 gcc_assert (c_dialect_objc ());
1043 c_parser_objc_protocol_definition (parser
);
1046 gcc_assert (c_dialect_objc ());
1047 c_parser_consume_token (parser
);
1048 objc_finish_implementation ();
1056 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1057 c_parser_consume_token (parser
);
1061 if (c_dialect_objc ())
1063 c_parser_objc_method_definition (parser
);
1066 /* Else fall through, and yield a syntax error trying to parse
1067 as a declaration or function definition. */
1070 /* A declaration or a function definition. We can only tell
1071 which after parsing the declaration specifiers, if any, and
1072 the first declarator. */
1073 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1078 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1079 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1080 accepted; otherwise (old-style parameter declarations) only other
1081 declarations are accepted. If NESTED is true, we are inside a
1082 function or parsing old-style parameter declarations; any functions
1083 encountered are nested functions and declaration specifiers are
1084 required; otherwise we are at top level and functions are normal
1085 functions and declaration specifiers may be optional. If EMPTY_OK
1086 is true, empty declarations are OK (subject to all other
1087 constraints); otherwise (old-style parameter declarations) they are
1088 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1089 may start with attributes; otherwise they may not.
1092 declaration-specifiers init-declarator-list[opt] ;
1094 function-definition:
1095 declaration-specifiers[opt] declarator declaration-list[opt]
1100 declaration-list declaration
1102 init-declarator-list:
1104 init-declarator-list , init-declarator
1107 declarator simple-asm-expr[opt] attributes[opt]
1108 declarator simple-asm-expr[opt] attributes[opt] = initializer
1112 nested-function-definition:
1113 declaration-specifiers declarator declaration-list[opt]
1116 The simple-asm-expr and attributes are GNU extensions.
1118 This function does not handle __extension__; that is handled in its
1119 callers. ??? Following the old parser, __extension__ may start
1120 external declarations, declarations in functions and declarations
1121 at the start of "for" loops, but not old-style parameter
1124 C99 requires declaration specifiers in a function definition; the
1125 absence is diagnosed through the diagnosis of implicit int. In GNU
1126 C we also allow but diagnose declarations without declaration
1127 specifiers, but only at top level (elsewhere they conflict with
1131 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1132 bool nested
, bool start_attr_ok
)
1134 struct c_declspecs
*specs
;
1136 tree all_prefix_attrs
;
1137 bool diagnosed_no_specs
= false;
1138 specs
= build_null_declspecs ();
1139 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1142 c_parser_skip_to_end_of_block_or_statement (parser
);
1145 if (nested
&& !specs
->declspecs_seen_p
)
1147 c_parser_error (parser
, "expected declaration specifiers");
1148 c_parser_skip_to_end_of_block_or_statement (parser
);
1151 finish_declspecs (specs
);
1152 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1158 shadow_tag_warned (specs
, 1);
1159 pedwarn ("empty declaration");
1161 c_parser_consume_token (parser
);
1164 pending_xref_error ();
1165 prefix_attrs
= specs
->attrs
;
1166 all_prefix_attrs
= prefix_attrs
;
1167 specs
->attrs
= NULL_TREE
;
1170 struct c_declarator
*declarator
;
1173 /* Declaring either one or more declarators (in which case we
1174 should diagnose if there were no declaration specifiers) or a
1175 function definition (in which case the diagnostic for
1176 implicit int suffices). */
1177 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1178 C_DTR_NORMAL
, &dummy
);
1179 if (declarator
== NULL
)
1181 c_parser_skip_to_end_of_block_or_statement (parser
);
1184 if (c_parser_next_token_is (parser
, CPP_EQ
)
1185 || c_parser_next_token_is (parser
, CPP_COMMA
)
1186 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1187 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1188 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1190 tree asm_name
= NULL_TREE
;
1191 tree postfix_attrs
= NULL_TREE
;
1192 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1194 diagnosed_no_specs
= true;
1195 pedwarn ("data definition has no type or storage class");
1197 /* Having seen a data definition, there cannot now be a
1198 function definition. */
1200 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1201 asm_name
= c_parser_simple_asm_expr (parser
);
1202 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1203 postfix_attrs
= c_parser_attributes (parser
);
1204 if (c_parser_next_token_is (parser
, CPP_EQ
))
1208 c_parser_consume_token (parser
);
1209 /* The declaration of the variable is in effect while
1210 its initializer is parsed. */
1211 d
= start_decl (declarator
, specs
, true,
1212 chainon (postfix_attrs
, all_prefix_attrs
));
1214 d
= error_mark_node
;
1215 start_init (d
, asm_name
, global_bindings_p ());
1216 init
= c_parser_initializer (parser
);
1218 if (d
!= error_mark_node
)
1220 maybe_warn_string_init (TREE_TYPE (d
), init
);
1221 finish_decl (d
, init
.value
, asm_name
);
1226 tree d
= start_decl (declarator
, specs
, false,
1227 chainon (postfix_attrs
,
1230 finish_decl (d
, NULL_TREE
, asm_name
);
1232 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1234 c_parser_consume_token (parser
);
1235 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1236 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1239 all_prefix_attrs
= prefix_attrs
;
1242 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1244 c_parser_consume_token (parser
);
1249 c_parser_error (parser
, "expected %<,%> or %<;%>");
1250 c_parser_skip_to_end_of_block_or_statement (parser
);
1256 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1257 "%<asm%> or %<__attribute__%>");
1258 c_parser_skip_to_end_of_block_or_statement (parser
);
1261 /* Function definition (nested or otherwise). */
1265 pedwarn ("ISO C forbids nested functions");
1266 push_function_context ();
1268 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1270 /* This can appear in many cases looking nothing like a
1271 function definition, so we don't give a more specific
1272 error suggesting there was one. */
1273 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1274 "or %<__attribute__%>");
1276 pop_function_context ();
1279 /* Parse old-style parameter declarations. ??? Attributes are
1280 not allowed to start declaration specifiers here because of a
1281 syntax conflict between a function declaration with attribute
1282 suffix and a function definition with an attribute prefix on
1283 first old-style parameter declaration. Following the old
1284 parser, they are not accepted on subsequent old-style
1285 parameter declarations either. However, there is no
1286 ambiguity after the first declaration, nor indeed on the
1287 first as long as we don't allow postfix attributes after a
1288 declarator with a nonempty identifier list in a definition;
1289 and postfix attributes have never been accepted here in
1290 function definitions either. */
1291 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1292 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1293 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1294 DECL_SOURCE_LOCATION (current_function_decl
)
1295 = c_parser_peek_token (parser
)->location
;
1296 store_parm_decls ();
1297 fnbody
= c_parser_compound_statement (parser
);
1300 tree decl
= current_function_decl
;
1303 pop_function_context ();
1304 add_stmt (build_stmt (DECL_EXPR
, decl
));
1315 /* Parse an asm-definition (asm() outside a function body). This is a
1323 c_parser_asm_definition (c_parser
*parser
)
1325 tree asm_str
= c_parser_simple_asm_expr (parser
);
1326 /* ??? This only works sensibly in the presence of
1327 -fno-unit-at-a-time; file-scope asms really need to be passed to
1328 cgraph which needs to preserve the order of functions and
1331 assemble_asm (asm_str
);
1332 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1335 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1336 6.7), adding them to SPECS (which may already include some).
1337 Storage class specifiers are accepted iff SCSPEC_OK; type
1338 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1339 the start iff START_ATTR_OK.
1341 declaration-specifiers:
1342 storage-class-specifier declaration-specifiers[opt]
1343 type-specifier declaration-specifiers[opt]
1344 type-qualifier declaration-specifiers[opt]
1345 function-specifier declaration-specifiers[opt]
1347 Function specifiers (inline) are from C99, and are currently
1348 handled as storage class specifiers, as is __thread.
1350 C90 6.5.1, C99 6.7.1:
1351 storage-class-specifier:
1362 C90 6.5.2, C99 6.7.2:
1375 [_Imaginary removed in C99 TC2]
1376 struct-or-union-specifier
1380 (_Bool and _Complex are new in C99.)
1382 C90 6.5.3, C99 6.7.3:
1389 (restrict is new in C99.)
1393 declaration-specifiers:
1394 attributes declaration-specifiers[opt]
1396 storage-class-specifier:
1405 class-name objc-protocol-refs[opt]
1406 typedef-name objc-protocol-refs
1411 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1412 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1414 bool attrs_ok
= start_attr_ok
;
1415 bool seen_type
= specs
->type_seen_p
;
1416 while (c_parser_next_token_is (parser
, CPP_NAME
)
1417 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1418 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1420 struct c_typespec t
;
1422 if (c_parser_next_token_is (parser
, CPP_NAME
))
1424 tree value
= c_parser_peek_token (parser
)->value
;
1425 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1426 /* This finishes the specifiers unless a type name is OK, it
1427 is declared as a type name and a type name hasn't yet
1429 if (!typespec_ok
|| seen_type
1430 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1432 c_parser_consume_token (parser
);
1435 if (kind
== C_ID_TYPENAME
1436 && (!c_dialect_objc ()
1437 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1439 t
.kind
= ctsk_typedef
;
1440 /* For a typedef name, record the meaning, not the name.
1441 In case of 'foo foo, bar;'. */
1442 t
.spec
= lookup_name (value
);
1446 tree proto
= NULL_TREE
;
1447 gcc_assert (c_dialect_objc ());
1449 if (c_parser_next_token_is (parser
, CPP_LESS
))
1450 proto
= c_parser_objc_protocol_refs (parser
);
1451 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1453 declspecs_add_type (specs
, t
);
1456 if (c_parser_next_token_is (parser
, CPP_LESS
))
1458 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1459 nisse@lysator.liu.se. */
1461 gcc_assert (c_dialect_objc ());
1462 if (!typespec_ok
|| seen_type
)
1464 proto
= c_parser_objc_protocol_refs (parser
);
1466 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1467 declspecs_add_type (specs
, t
);
1470 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1471 switch (c_parser_peek_token (parser
)->keyword
)
1483 /* TODO: Distinguish between function specifiers (inline)
1484 and storage class specifiers, either here or in
1485 declspecs_add_scspec. */
1486 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1487 c_parser_consume_token (parser
);
1504 OBJC_NEED_RAW_IDENTIFIER (1);
1505 t
.kind
= ctsk_resword
;
1506 t
.spec
= c_parser_peek_token (parser
)->value
;
1507 declspecs_add_type (specs
, t
);
1508 c_parser_consume_token (parser
);
1515 t
= c_parser_enum_specifier (parser
);
1516 declspecs_add_type (specs
, t
);
1524 t
= c_parser_struct_or_union_specifier (parser
);
1525 declspecs_add_type (specs
, t
);
1528 /* ??? The old parser rejected typeof after other type
1529 specifiers, but is a syntax error the best way of
1531 if (!typespec_ok
|| seen_type
)
1535 t
= c_parser_typeof_specifier (parser
);
1536 declspecs_add_type (specs
, t
);
1542 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1543 c_parser_consume_token (parser
);
1548 attrs
= c_parser_attributes (parser
);
1549 declspecs_add_attrs (specs
, attrs
);
1558 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1561 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1562 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1563 enum attributes[opt] identifier
1565 The form with trailing comma is new in C99. The forms with
1566 attributes are GNU extensions. In GNU C, we accept any expression
1567 without commas in the syntax (assignment expressions, not just
1568 conditional expressions); assignment expressions will be diagnosed
1573 enumerator-list , enumerator
1576 enumeration-constant
1577 enumeration-constant = constant-expression
1580 static struct c_typespec
1581 c_parser_enum_specifier (c_parser
*parser
)
1583 struct c_typespec ret
;
1585 tree ident
= NULL_TREE
;
1586 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1587 c_parser_consume_token (parser
);
1588 attrs
= c_parser_attributes (parser
);
1589 if (c_parser_next_token_is (parser
, CPP_NAME
))
1591 ident
= c_parser_peek_token (parser
)->value
;
1592 c_parser_consume_token (parser
);
1594 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1596 /* Parse an enum definition. */
1597 tree type
= start_enum (ident
);
1599 /* We chain the enumerators in reverse order, then put them in
1600 forward order at the end. */
1601 tree values
= NULL_TREE
;
1602 c_parser_consume_token (parser
);
1609 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1611 c_parser_error (parser
, "expected identifier");
1612 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1613 values
= error_mark_node
;
1616 enum_id
= c_parser_peek_token (parser
)->value
;
1617 c_parser_consume_token (parser
);
1618 if (c_parser_next_token_is (parser
, CPP_EQ
))
1620 c_parser_consume_token (parser
);
1621 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1624 enum_value
= NULL_TREE
;
1625 enum_decl
= build_enumerator (enum_id
, enum_value
);
1626 TREE_CHAIN (enum_decl
) = values
;
1629 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1632 c_parser_consume_token (parser
);
1634 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1636 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1637 pedwarn ("comma at end of enumerator list");
1638 c_parser_consume_token (parser
);
1643 c_parser_error (parser
, "expected %<,%> or %<}%>");
1644 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1645 values
= error_mark_node
;
1649 postfix_attrs
= c_parser_attributes (parser
);
1650 ret
.spec
= finish_enum (type
, nreverse (values
),
1651 chainon (attrs
, postfix_attrs
));
1652 ret
.kind
= ctsk_tagdef
;
1657 c_parser_error (parser
, "expected %<{%>");
1658 ret
.spec
= error_mark_node
;
1659 ret
.kind
= ctsk_tagref
;
1662 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1663 /* In ISO C, enumerated types can be referred to only if already
1665 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1666 pedwarn ("ISO C forbids forward references to %<enum%> types");
1670 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1672 struct-or-union-specifier:
1673 struct-or-union attributes[opt] identifier[opt]
1674 { struct-contents } attributes[opt]
1675 struct-or-union attributes[opt] identifier
1678 struct-declaration-list
1680 struct-declaration-list:
1681 struct-declaration ;
1682 struct-declaration-list struct-declaration ;
1689 struct-declaration-list struct-declaration
1691 struct-declaration-list:
1692 struct-declaration-list ;
1695 (Note that in the syntax here, unlike that in ISO C, the semicolons
1696 are included here rather than in struct-declaration, in order to
1697 describe the syntax with extra semicolons and missing semicolon at
1702 struct-declaration-list:
1703 @defs ( class-name )
1705 (Note this does not include a trailing semicolon, but can be
1706 followed by further declarations, and gets a pedwarn-if-pedantic
1707 when followed by a semicolon.) */
1709 static struct c_typespec
1710 c_parser_struct_or_union_specifier (c_parser
*parser
)
1712 struct c_typespec ret
;
1714 tree ident
= NULL_TREE
;
1715 enum tree_code code
;
1716 switch (c_parser_peek_token (parser
)->keyword
)
1727 c_parser_consume_token (parser
);
1728 attrs
= c_parser_attributes (parser
);
1729 if (c_parser_next_token_is (parser
, CPP_NAME
))
1731 ident
= c_parser_peek_token (parser
)->value
;
1732 c_parser_consume_token (parser
);
1734 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1736 /* Parse a struct or union definition. Start the scope of the
1737 tag before parsing components. */
1738 tree type
= start_struct (code
, ident
);
1740 /* We chain the components in reverse order, then put them in
1741 forward order at the end. Each struct-declaration may
1742 declare multiple components (comma-separated), so we must use
1743 chainon to join them, although when parsing each
1744 struct-declaration we can use TREE_CHAIN directly.
1746 The theory behind all this is that there will be more
1747 semicolon separated fields than comma separated fields, and
1748 so we'll be minimizing the number of node traversals required
1750 tree contents
= NULL_TREE
;
1751 c_parser_consume_token (parser
);
1752 /* Handle the Objective-C @defs construct,
1753 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1754 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1757 gcc_assert (c_dialect_objc ());
1758 c_parser_consume_token (parser
);
1759 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1761 if (c_parser_next_token_is (parser
, CPP_NAME
)
1762 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1764 name
= c_parser_peek_token (parser
)->value
;
1765 c_parser_consume_token (parser
);
1769 c_parser_error (parser
, "expected class name");
1770 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1773 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1775 contents
= nreverse (objc_get_class_ivars (name
));
1778 /* Parse the struct-declarations and semicolons. Problems with
1779 semicolons are diagnosed here; empty structures are diagnosed
1784 /* Parse any stray semicolon. */
1785 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1788 pedwarn ("extra semicolon in struct or union specified");
1789 c_parser_consume_token (parser
);
1792 /* Stop if at the end of the struct or union contents. */
1793 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1795 c_parser_consume_token (parser
);
1798 /* Parse some comma-separated declarations, but not the
1799 trailing semicolon if any. */
1800 decls
= c_parser_struct_declaration (parser
);
1801 contents
= chainon (decls
, contents
);
1802 /* If no semicolon follows, either we have a parse error or
1803 are at the end of the struct or union and should
1805 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1806 c_parser_consume_token (parser
);
1809 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1810 pedwarn ("no semicolon at end of struct or union");
1813 c_parser_error (parser
, "expected %<;%>");
1814 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1819 postfix_attrs
= c_parser_attributes (parser
);
1820 ret
.spec
= finish_struct (type
, nreverse (contents
),
1821 chainon (attrs
, postfix_attrs
));
1822 ret
.kind
= ctsk_tagdef
;
1827 c_parser_error (parser
, "expected %<{%>");
1828 ret
.spec
= error_mark_node
;
1829 ret
.kind
= ctsk_tagref
;
1832 ret
= parser_xref_tag (code
, ident
);
1836 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1837 the trailing semicolon.
1840 specifier-qualifier-list struct-declarator-list
1842 specifier-qualifier-list:
1843 type-specifier specifier-qualifier-list[opt]
1844 type-qualifier specifier-qualifier-list[opt]
1845 attributes specifier-qualifier-list[opt]
1847 struct-declarator-list:
1849 struct-declarator-list , attributes[opt] struct-declarator
1852 declarator attributes[opt]
1853 declarator[opt] : constant-expression attributes[opt]
1858 __extension__ struct-declaration
1859 specifier-qualifier-list
1861 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1862 of attributes where shown is a GNU extension. In GNU C, we accept
1863 any expression without commas in the syntax (assignment
1864 expressions, not just conditional expressions); assignment
1865 expressions will be diagnosed as non-constant. */
1868 c_parser_struct_declaration (c_parser
*parser
)
1870 struct c_declspecs
*specs
;
1872 tree all_prefix_attrs
;
1874 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1878 ext
= disable_extension_diagnostics ();
1879 c_parser_consume_token (parser
);
1880 decl
= c_parser_struct_declaration (parser
);
1881 restore_extension_diagnostics (ext
);
1884 specs
= build_null_declspecs ();
1885 c_parser_declspecs (parser
, specs
, false, true, true);
1888 if (!specs
->declspecs_seen_p
)
1890 c_parser_error (parser
, "expected specifier-qualifier-list");
1893 finish_declspecs (specs
);
1894 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1897 if (!specs
->type_seen_p
)
1900 pedwarn ("ISO C forbids member declarations with no members");
1901 shadow_tag_warned (specs
, pedantic
);
1906 /* Support for unnamed structs or unions as members of
1907 structs or unions (which is [a] useful and [b] supports
1909 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
, NULL_TREE
);
1913 pending_xref_error ();
1914 prefix_attrs
= specs
->attrs
;
1915 all_prefix_attrs
= prefix_attrs
;
1916 specs
->attrs
= NULL_TREE
;
1920 /* Declaring one or more declarators or un-named bit-fields. */
1921 struct c_declarator
*declarator
;
1923 if (c_parser_next_token_is (parser
, CPP_COLON
))
1924 declarator
= build_id_declarator (NULL_TREE
);
1926 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1927 C_DTR_NORMAL
, &dummy
);
1928 if (declarator
== NULL
)
1930 c_parser_skip_to_end_of_block_or_statement (parser
);
1933 if (c_parser_next_token_is (parser
, CPP_COLON
)
1934 || c_parser_next_token_is (parser
, CPP_COMMA
)
1935 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1936 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
1937 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1939 tree postfix_attrs
= NULL_TREE
;
1940 tree width
= NULL_TREE
;
1942 if (c_parser_next_token_is (parser
, CPP_COLON
))
1944 c_parser_consume_token (parser
);
1945 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
1947 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1948 postfix_attrs
= c_parser_attributes (parser
);
1949 d
= grokfield (declarator
, specs
, width
);
1950 decl_attributes (&d
, chainon (postfix_attrs
,
1951 all_prefix_attrs
), 0);
1952 TREE_CHAIN (d
) = decls
;
1954 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1955 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1958 all_prefix_attrs
= prefix_attrs
;
1959 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1960 c_parser_consume_token (parser
);
1961 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1962 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1964 /* Semicolon consumed in caller. */
1969 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
1975 c_parser_error (parser
,
1976 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
1977 "%<__attribute__%>");
1984 /* Parse a typeof specifier (a GNU extension).
1987 typeof ( expression )
1988 typeof ( type-name )
1991 static struct c_typespec
1992 c_parser_typeof_specifier (c_parser
*parser
)
1994 struct c_typespec ret
;
1995 ret
.kind
= ctsk_typeof
;
1996 ret
.spec
= error_mark_node
;
1997 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
1998 c_parser_consume_token (parser
);
2001 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2007 if (c_parser_next_token_starts_typename (parser
))
2009 struct c_type_name
*type
= c_parser_type_name (parser
);
2014 ret
.spec
= groktypename (type
);
2015 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2020 struct c_expr expr
= c_parser_expression (parser
);
2023 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2024 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2025 error ("%<typeof%> applied to a bit-field");
2026 ret
.spec
= TREE_TYPE (expr
.value
);
2027 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2033 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2034 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2035 be redeclared; otherwise it may not. KIND indicates which kind of
2036 declarator is wanted. Returns a valid declarator except in the
2037 case of a syntax error in which case NULL is returned. *SEEN_ID is
2038 set to true if an identifier being declared is seen; this is used
2039 to diagnose bad forms of abstract array declarators and to
2040 determine whether an identifier list is syntactically permitted.
2043 pointer[opt] direct-declarator
2047 ( attributes[opt] declarator )
2048 direct-declarator array-declarator
2049 direct-declarator ( parameter-type-list )
2050 direct-declarator ( identifier-list[opt] )
2053 * type-qualifier-list[opt]
2054 * type-qualifier-list[opt] pointer
2056 type-qualifier-list:
2059 type-qualifier-list type-qualifier
2060 type-qualifier-list attributes
2062 parameter-type-list:
2064 parameter-list , ...
2067 parameter-declaration
2068 parameter-list , parameter-declaration
2070 parameter-declaration:
2071 declaration-specifiers declarator attributes[opt]
2072 declaration-specifiers abstract-declarator[opt] attributes[opt]
2076 identifier-list , identifier
2078 abstract-declarator:
2080 pointer[opt] direct-abstract-declarator
2082 direct-abstract-declarator:
2083 ( attributes[opt] abstract-declarator )
2084 direct-abstract-declarator[opt] array-declarator
2085 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2090 direct-declarator ( parameter-forward-declarations
2091 parameter-type-list[opt] )
2093 direct-abstract-declarator:
2094 direct-abstract-declarator[opt] ( parameter-forward-declarations
2095 parameter-type-list[opt] )
2097 parameter-forward-declarations:
2099 parameter-forward-declarations parameter-list ;
2101 The uses of attributes shown above are GNU extensions.
2103 Some forms of array declarator are not included in C99 in the
2104 syntax for abstract declarators; these are disallowed elsewhere.
2105 This may be a defect (DR#289).
2107 This function also accepts an omitted abstract declarator as being
2108 an abstract declarator, although not part of the formal syntax. */
2110 static struct c_declarator
*
2111 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2114 /* Parse any initial pointer part. */
2115 if (c_parser_next_token_is (parser
, CPP_MULT
))
2117 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2118 struct c_declarator
*inner
;
2119 c_parser_consume_token (parser
);
2120 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2121 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2125 return make_pointer_declarator (quals_attrs
, inner
);
2127 /* Now we have a direct declarator, direct abstract declarator or
2128 nothing (which counts as a direct abstract declarator here). */
2129 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2132 /* Parse a direct declarator or direct abstract declarator; arguments
2133 as c_parser_declarator. */
2135 static struct c_declarator
*
2136 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2139 /* The direct declarator must start with an identifier (possibly
2140 omitted) or a parenthesized declarator (possibly abstract). In
2141 an ordinary declarator, initial parentheses must start a
2142 parenthesized declarator. In an abstract declarator or parameter
2143 declarator, they could start a parenthesized declarator or a
2144 parameter list. To tell which, the open parenthesis and any
2145 following attributes must be read. If a declaration specifier
2146 follows, then it is a parameter list; if the specifier is a
2147 typedef name, there might be an ambiguity about redeclaring it,
2148 which is resolved in the direction of treating it as a typedef
2149 name. If a close parenthesis follows, it is also an empty
2150 parameter list, as the syntax does not permit empty abstract
2151 declarators. Otherwise, it is a parenthesised declarator (in
2152 which case the analysis may be repeated inside it, recursively).
2154 ??? There is an ambiguity in a parameter declaration "int
2155 (__attribute__((foo)) x)", where x is not a typedef name: it
2156 could be an abstract declarator for a function, or declare x with
2157 parentheses. The proper resolution of this ambiguity needs
2158 documenting. At present we follow an accident of the old
2159 parser's implementation, whereby the first parameter must have
2160 some declaration specifiers other than just attributes. Thus as
2161 a parameter declaration it is treated as a parenthesised
2162 parameter named x, and as an abstract declarator it is
2165 ??? Also following the old parser, attributes inside an empty
2166 parameter list are ignored, making it a list not yielding a
2167 prototype, rather than giving an error or making it have one
2168 parameter with implicit type int.
2170 ??? Also following the old parser, typedef names may be
2171 redeclared in declarators, but not Objective-C class names. */
2173 if (kind
!= C_DTR_ABSTRACT
2174 && c_parser_next_token_is (parser
, CPP_NAME
)
2176 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2177 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2179 struct c_declarator
*inner
2180 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2182 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2183 c_parser_consume_token (parser
);
2184 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2187 if (kind
!= C_DTR_NORMAL
2188 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2190 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2191 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2194 /* Either we are at the end of an abstract declarator, or we have
2197 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2200 struct c_declarator
*inner
;
2201 c_parser_consume_token (parser
);
2202 attrs
= c_parser_attributes (parser
);
2203 if (kind
!= C_DTR_NORMAL
2204 && (c_parser_next_token_starts_declspecs (parser
)
2205 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2207 struct c_arg_info
*args
2208 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2215 = build_function_declarator (args
,
2216 build_id_declarator (NULL_TREE
));
2217 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2221 /* A parenthesized declarator. */
2222 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2223 if (inner
!= NULL
&& attrs
!= NULL
)
2224 inner
= build_attrs_declarator (attrs
, inner
);
2225 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2227 c_parser_consume_token (parser
);
2231 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2235 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2242 if (kind
== C_DTR_NORMAL
)
2244 c_parser_error (parser
, "expected identifier or %<(%>");
2248 return build_id_declarator (NULL_TREE
);
2252 /* Parse part of a direct declarator or direct abstract declarator,
2253 given that some (in INNER) has already been parsed; ID_PRESENT is
2254 true if an identifier is present, false for an abstract
2257 static struct c_declarator
*
2258 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2259 struct c_declarator
*inner
)
2261 /* Parse a sequence of array declarators and parameter lists. */
2262 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2264 struct c_declarator
*declarator
;
2265 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2269 c_parser_consume_token (parser
);
2270 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2271 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2273 c_parser_consume_token (parser
);
2274 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2275 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2276 if (!quals_attrs
->declspecs_seen_p
)
2278 /* If "static" is present, there must be an array dimension.
2279 Otherwise, there may be a dimension, "*", or no
2284 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2288 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2293 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2295 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2299 c_parser_consume_token (parser
);
2304 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2310 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2313 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2314 c_parser_consume_token (parser
);
2317 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2321 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2323 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2324 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2326 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2329 struct c_arg_info
*args
;
2330 c_parser_consume_token (parser
);
2331 attrs
= c_parser_attributes (parser
);
2332 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2337 inner
= build_function_declarator (args
, inner
);
2338 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2344 /* Parse a parameter list or identifier list, including the closing
2345 parenthesis but not the opening one. ATTRS are the attributes at
2346 the start of the list. ID_LIST_OK is true if an identifier list is
2347 acceptable; such a list must not have attributes at the start. */
2349 static struct c_arg_info
*
2350 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2353 declare_parm_level ();
2354 /* If the list starts with an identifier, it is an identifier list.
2355 Otherwise, it is either a prototype list or an empty list. */
2358 && c_parser_next_token_is (parser
, CPP_NAME
)
2359 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2361 tree list
= NULL_TREE
;
2362 while (c_parser_next_token_is (parser
, CPP_NAME
)
2363 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2365 list
= chainon (list
, build_tree_list (NULL_TREE
,
2366 c_parser_peek_token (parser
)->value
));
2367 c_parser_consume_token (parser
);
2368 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2370 c_parser_consume_token (parser
);
2371 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2373 c_parser_error (parser
, "expected identifier");
2377 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2379 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2384 c_parser_consume_token (parser
);
2390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2398 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2404 /* Parse a parameter list (possibly empty), including the closing
2405 parenthesis but not the opening one. ATTRS are the attributes at
2406 the start of the list. */
2408 static struct c_arg_info
*
2409 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2411 bool good_parm
= false;
2412 /* ??? Following the old parser, forward parameter declarations may
2413 use abstract declarators, and if no real parameter declarations
2414 follow the forward declarations then this is not diagnosed. Also
2415 note as above that attributes are ignored as the only contents of
2416 the parentheses, or as the only contents after forward
2418 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2420 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2425 c_parser_consume_token (parser
);
2428 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2430 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2434 /* Suppress -Wold-style-definition for this case. */
2435 ret
->types
= error_mark_node
;
2436 error ("ISO C requires a named argument before %<...%>");
2437 c_parser_consume_token (parser
);
2438 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2440 c_parser_consume_token (parser
);
2445 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2450 /* Nonempty list of parameters, either terminated with semicolon
2451 (forward declarations; recurse) or with close parenthesis (normal
2452 function) or with ", ... )" (variadic function). */
2455 /* Parse a parameter. */
2456 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2461 push_parm_decl (parm
);
2463 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2466 c_parser_consume_token (parser
);
2467 new_attrs
= c_parser_attributes (parser
);
2468 return c_parser_parms_list_declarator (parser
, new_attrs
);
2470 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2472 c_parser_consume_token (parser
);
2474 return get_parm_info (false);
2477 struct c_arg_info
*ret
2478 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2486 if (!c_parser_require (parser
, CPP_COMMA
,
2487 "expected %<;%>, %<,%> or %<)%>"))
2489 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2492 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2494 c_parser_consume_token (parser
);
2495 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2497 c_parser_consume_token (parser
);
2499 return get_parm_info (true);
2502 struct c_arg_info
*ret
2503 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2513 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2521 /* Parse a parameter declaration. ATTRS are the attributes at the
2522 start of the declaration if it is the first parameter. */
2524 static struct c_parm
*
2525 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2527 struct c_declspecs
*specs
;
2528 struct c_declarator
*declarator
;
2530 tree postfix_attrs
= NULL_TREE
;
2532 if (!c_parser_next_token_starts_declspecs (parser
))
2534 /* ??? In some Objective-C cases '...' isn't applicable so there
2535 should be a different message. */
2536 c_parser_error (parser
,
2537 "expected declaration specifiers or %<...%>");
2538 c_parser_skip_to_end_of_parameter (parser
);
2541 specs
= build_null_declspecs ();
2544 declspecs_add_attrs (specs
, attrs
);
2547 c_parser_declspecs (parser
, specs
, true, true, true);
2548 finish_declspecs (specs
);
2549 pending_xref_error ();
2550 prefix_attrs
= specs
->attrs
;
2551 specs
->attrs
= NULL_TREE
;
2552 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2553 C_DTR_PARM
, &dummy
);
2554 if (declarator
== NULL
)
2556 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2559 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2560 postfix_attrs
= c_parser_attributes (parser
);
2561 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2565 /* Parse a string literal in an asm expression. It should not be
2566 translated, and wide string literals are an error although
2567 permitted by the syntax. This is a GNU extension.
2572 ??? At present, following the old parser, the caller needs to have
2573 set c_lex_string_translate to 0. It would be better to follow the
2574 C++ parser rather than using the c_lex_string_translate kludge. */
2577 c_parser_asm_string_literal (c_parser
*parser
)
2580 if (c_parser_next_token_is (parser
, CPP_STRING
))
2582 str
= c_parser_peek_token (parser
)->value
;
2583 c_parser_consume_token (parser
);
2585 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2587 error ("wide string literal in %<asm%>");
2588 str
= build_string (1, "");
2589 c_parser_consume_token (parser
);
2593 c_parser_error (parser
, "expected string literal");
2599 /* Parse a simple asm expression. This is used in restricted
2600 contexts, where a full expression with inputs and outputs does not
2601 make sense. This is a GNU extension.
2604 asm ( asm-string-literal )
2608 c_parser_simple_asm_expr (c_parser
*parser
)
2611 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2612 /* ??? Follow the C++ parser rather than using the
2613 c_lex_string_translate kludge. */
2614 c_lex_string_translate
= 0;
2615 c_parser_consume_token (parser
);
2616 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2618 c_lex_string_translate
= 1;
2621 str
= c_parser_asm_string_literal (parser
);
2622 c_lex_string_translate
= 1;
2623 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2631 /* Parse (possibly empty) attributes. This is a GNU extension.
2635 attributes attribute
2638 __attribute__ ( ( attribute-list ) )
2642 attribute_list , attrib
2647 any-word ( identifier )
2648 any-word ( identifier , nonempty-expr-list )
2649 any-word ( expr-list )
2651 where the "identifier" must not be declared as a type, and
2652 "any-word" may be any identifier (including one declared as a
2653 type), a reserved word storage class specifier, type specifier or
2654 type qualifier. ??? This still leaves out most reserved keywords
2655 (following the old parser), shouldn't we include them, and why not
2656 allow identifiers declared as types to start the arguments? */
2659 c_parser_attributes (c_parser
*parser
)
2661 tree attrs
= NULL_TREE
;
2662 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2664 /* ??? Follow the C++ parser rather than using the
2665 c_lex_string_translate kludge. */
2666 c_lex_string_translate
= 0;
2667 c_parser_consume_token (parser
);
2668 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2670 c_lex_string_translate
= 1;
2673 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2675 c_lex_string_translate
= 1;
2676 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2679 /* Parse the attribute list. */
2680 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2681 || c_parser_next_token_is (parser
, CPP_NAME
)
2682 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2684 tree attr
, attr_name
, attr_args
;
2685 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2687 c_parser_consume_token (parser
);
2690 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2692 /* ??? See comment above about what keywords are
2695 switch (c_parser_peek_token (parser
)->keyword
)
2727 attr_name
= c_parser_peek_token (parser
)->value
;
2728 c_parser_consume_token (parser
);
2729 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2731 attr
= build_tree_list (attr_name
, NULL_TREE
);
2732 attrs
= chainon (attrs
, attr
);
2735 c_parser_consume_token (parser
);
2736 /* Parse the attribute contents. If they start with an
2737 identifier which is followed by a comma or close
2738 parenthesis, then the arguments start with that
2739 identifier; otherwise they are an expression list. */
2740 if (c_parser_next_token_is (parser
, CPP_NAME
)
2741 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2742 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2743 || (c_parser_peek_2nd_token (parser
)->type
2744 == CPP_CLOSE_PAREN
)))
2746 tree arg1
= c_parser_peek_token (parser
)->value
;
2747 c_parser_consume_token (parser
);
2748 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2749 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2752 c_parser_consume_token (parser
);
2753 attr_args
= tree_cons (NULL_TREE
, arg1
,
2754 c_parser_expr_list (parser
));
2759 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2760 attr_args
= NULL_TREE
;
2762 attr_args
= c_parser_expr_list (parser
);
2764 attr
= build_tree_list (attr_name
, attr_args
);
2765 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2766 c_parser_consume_token (parser
);
2769 c_lex_string_translate
= 1;
2770 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2774 attrs
= chainon (attrs
, attr
);
2776 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2777 c_parser_consume_token (parser
);
2780 c_lex_string_translate
= 1;
2781 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2785 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2786 c_parser_consume_token (parser
);
2789 c_lex_string_translate
= 1;
2790 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2794 c_lex_string_translate
= 1;
2799 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2802 specifier-qualifier-list abstract-declarator[opt]
2805 static struct c_type_name
*
2806 c_parser_type_name (c_parser
*parser
)
2808 struct c_declspecs
*specs
= build_null_declspecs ();
2809 struct c_declarator
*declarator
;
2810 struct c_type_name
*ret
;
2812 c_parser_declspecs (parser
, specs
, false, true, true);
2813 if (!specs
->declspecs_seen_p
)
2815 c_parser_error (parser
, "expected specifier-qualifier-list");
2818 pending_xref_error ();
2819 finish_declspecs (specs
);
2820 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2821 C_DTR_ABSTRACT
, &dummy
);
2822 if (declarator
== NULL
)
2824 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2826 ret
->declarator
= declarator
;
2830 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2833 assignment-expression
2834 { initializer-list }
2835 { initializer-list , }
2838 designation[opt] initializer
2839 initializer-list , designation[opt] initializer
2846 designator-list designator
2853 [ constant-expression ]
2865 [ constant-expression ... constant-expression ]
2867 Any expression without commas is accepted in the syntax for the
2868 constant-expressions, with non-constant expressions rejected later.
2870 This function is only used for top-level initializers; for nested
2871 ones, see c_parser_initval. */
2873 static struct c_expr
2874 c_parser_initializer (c_parser
*parser
)
2876 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2877 return c_parser_braced_init (parser
, NULL_TREE
, false);
2879 return c_parser_expr_no_commas (parser
, NULL
);
2882 /* Parse a braced initializer list. TYPE is the type specified for a
2883 compound literal, and NULL_TREE for other initializers and for
2884 nested braced lists. NESTED_P is true for nested braced lists,
2885 false for the list of a compound literal or the list that is the
2886 top-level initializer in a declaration. */
2888 static struct c_expr
2889 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
2891 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
2892 c_parser_consume_token (parser
);
2894 push_init_level (0);
2896 really_start_incremental_init (type
);
2897 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2900 pedwarn ("ISO C forbids empty initializer braces");
2904 /* Parse a non-empty initializer list, possibly with a trailing
2908 c_parser_initelt (parser
);
2911 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2912 c_parser_consume_token (parser
);
2915 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2919 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
2922 ret
.value
= error_mark_node
;
2923 ret
.original_code
= ERROR_MARK
;
2924 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
2927 c_parser_consume_token (parser
);
2928 return pop_init_level (0);
2931 /* Parse a nested initializer, including designators. */
2934 c_parser_initelt (c_parser
*parser
)
2936 /* Parse any designator or designator list. A single array
2937 designator may have the subsequent "=" omitted in GNU C, but a
2938 longer list or a structure member designator may not. */
2939 if (c_parser_next_token_is (parser
, CPP_NAME
)
2940 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
2942 /* Old-style structure member designator. */
2943 set_init_label (c_parser_peek_token (parser
)->value
);
2945 pedwarn ("obsolete use of designated initializer with %<:%>");
2946 c_parser_consume_token (parser
);
2947 c_parser_consume_token (parser
);
2951 /* des_seen is 0 if there have been no designators, 1 if there
2952 has been a single array designator and 2 otherwise. */
2954 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
2955 || c_parser_next_token_is (parser
, CPP_DOT
))
2957 int des_prev
= des_seen
;
2960 if (c_parser_next_token_is (parser
, CPP_DOT
))
2963 c_parser_consume_token (parser
);
2964 if (c_parser_next_token_is (parser
, CPP_NAME
))
2966 set_init_label (c_parser_peek_token (parser
)->value
);
2967 c_parser_consume_token (parser
);
2972 init
.value
= error_mark_node
;
2973 init
.original_code
= ERROR_MARK
;
2974 c_parser_error (parser
, "expected identifier");
2975 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2976 process_init_element (init
);
2983 /* ??? Following the old parser, [ objc-receiver
2984 objc-message-args ] is accepted as an initializer,
2985 being distinguished from a designator by what follows
2986 the first assignment expression inside the square
2987 brackets, but after a first array designator a
2988 subsequent square bracket is for Objective-C taken to
2989 start an expression, using the obsolete form of
2990 designated initializer without '=', rather than
2991 possibly being a second level of designation: in LALR
2992 terms, the '[' is shifted rather than reducing
2993 designator to designator-list. */
2994 if (des_prev
== 1 && c_dialect_objc ())
2996 des_seen
= des_prev
;
2999 if (des_prev
== 0 && c_dialect_objc ())
3001 /* This might be an array designator or an
3002 Objective-C message expression. If the former,
3003 continue parsing here; if the latter, parse the
3004 remainder of the initializer given the starting
3005 primary-expression. ??? It might make sense to
3006 distinguish when des_prev == 1 as well; see
3007 previous comment. */
3009 struct c_expr mexpr
;
3010 c_parser_consume_token (parser
);
3011 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3012 && ((c_parser_peek_token (parser
)->id_kind
3014 || (c_parser_peek_token (parser
)->id_kind
3015 == C_ID_CLASSNAME
)))
3017 /* Type name receiver. */
3018 tree id
= c_parser_peek_token (parser
)->value
;
3019 c_parser_consume_token (parser
);
3020 rec
= objc_get_class_reference (id
);
3021 goto parse_message_args
;
3023 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3024 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3025 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3026 goto array_desig_after_first
;
3027 /* Expression receiver. So far only one part
3028 without commas has been parsed; there might be
3029 more of the expression. */
3031 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3034 c_parser_consume_token (parser
);
3035 next
= c_parser_expr_no_commas (parser
, NULL
).value
;
3036 rec
= build_compound_expr (rec
, next
);
3039 /* Now parse the objc-message-args. */
3040 args
= c_parser_objc_message_args (parser
);
3041 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3044 = objc_build_message_expr (build_tree_list (rec
, args
));
3045 mexpr
.original_code
= ERROR_MARK
;
3046 /* Now parse and process the remainder of the
3047 initializer, starting with this message
3048 expression as a primary-expression. */
3049 c_parser_initval (parser
, &mexpr
);
3052 c_parser_consume_token (parser
);
3053 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3054 array_desig_after_first
:
3055 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3057 c_parser_consume_token (parser
);
3058 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3062 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3064 c_parser_consume_token (parser
);
3065 set_init_index (first
, second
);
3066 if (pedantic
&& second
)
3067 pedwarn ("ISO C forbids specifying range of "
3068 "elements to initialize");
3071 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3077 if (c_parser_next_token_is (parser
, CPP_EQ
))
3079 if (pedantic
&& !flag_isoc99
)
3080 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3081 c_parser_consume_token (parser
);
3088 pedwarn ("obsolete use of designated initializer "
3094 init
.value
= error_mark_node
;
3095 init
.original_code
= ERROR_MARK
;
3096 c_parser_error (parser
, "expected %<=%>");
3097 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3098 process_init_element (init
);
3104 c_parser_initval (parser
, NULL
);
3107 /* Parse a nested initializer; as c_parser_initializer but parses
3108 initializers within braced lists, after any designators have been
3109 applied. If AFTER is not NULL then it is an Objective-C message
3110 expression which is the primary-expression starting the
3114 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3117 gcc_assert (!after
|| c_dialect_objc ());
3118 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3119 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3121 init
= c_parser_expr_no_commas (parser
, after
);
3122 process_init_element (init
);
3125 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3129 { block-item-list[opt] }
3130 { label-declarations block-item-list }
3134 block-item-list block-item
3146 { label-declarations block-item-list }
3149 __extension__ nested-declaration
3150 nested-function-definition
3154 label-declarations label-declaration
3157 __label__ identifier-list ;
3159 Allowing the mixing of declarations and code is new in C99. The
3160 GNU syntax also permits (not shown above) labels at the end of
3161 compound statements, which yield an error. We don't allow labels
3162 on declarations; this might seem like a natural extension, but
3163 there would be a conflict between attributes on the label and
3164 prefix attributes on the declaration. ??? The syntax follows the
3165 old parser in requiring something after label declarations.
3166 Although they are erroneous if the labels declared aren't defined,
3167 is it useful for the syntax to be this way? */
3170 c_parser_compound_statement (c_parser
*parser
)
3173 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3174 return error_mark_node
;
3175 stmt
= c_begin_compound_stmt (true);
3176 c_parser_compound_statement_nostart (parser
);
3177 return c_end_compound_stmt (stmt
, true);
3180 /* Parse a compound statement except for the opening brace. This is
3181 used for parsing both compound statements and statement expressions
3182 (which follow different paths to handling the opening). */
3185 c_parser_compound_statement_nostart (c_parser
*parser
)
3187 bool last_stmt
= false;
3188 bool last_label
= false;
3189 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3191 c_parser_consume_token (parser
);
3194 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3196 /* Read zero or more forward-declarations for labels that nested
3197 functions can jump to. */
3198 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3200 c_parser_consume_token (parser
);
3201 /* Any identifiers, including those declared as type names,
3206 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3208 c_parser_error (parser
, "expected identifier");
3212 = declare_label (c_parser_peek_token (parser
)->value
);
3213 C_DECLARED_LABEL_FLAG (label
) = 1;
3214 add_stmt (build_stmt (DECL_EXPR
, label
));
3215 c_parser_consume_token (parser
);
3216 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3217 c_parser_consume_token (parser
);
3221 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3223 /* ??? Locating this diagnostic on the token after the
3224 declarations end follows the old parser, but it might be
3225 better to locate it where the declarations start instead. */
3227 pedwarn ("ISO C forbids label declarations");
3229 /* We must now have at least one statement, label or declaration. */
3230 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3232 c_parser_error (parser
, "expected declaration or statement");
3233 c_parser_consume_token (parser
);
3236 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3238 location_t loc
= c_parser_peek_token (parser
)->location
;
3239 if (c_parser_next_token_is (parser
, CPP_EOF
))
3241 c_parser_error (parser
, "expected declaration or statement");
3244 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3245 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3246 || (c_parser_next_token_is (parser
, CPP_NAME
)
3247 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3251 c_parser_label (parser
);
3253 else if (!last_label
3254 && c_parser_next_token_starts_declspecs (parser
))
3257 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3259 && ((pedantic
&& !flag_isoc99
)
3260 || warn_declaration_after_statement
))
3261 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3265 else if (!last_label
3266 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3268 /* __extension__ can start a declaration, but is also an
3269 unary operator that can start an expression. Consume all
3270 but the last of a possible series of __extension__ to
3272 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3273 && (c_parser_peek_2nd_token (parser
)->keyword
3275 c_parser_consume_token (parser
);
3276 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3279 ext
= disable_extension_diagnostics ();
3280 c_parser_consume_token (parser
);
3282 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3283 /* Following the old parser, __extension__ does not
3284 disable this diagnostic. */
3285 restore_extension_diagnostics (ext
);
3287 && ((pedantic
&& !flag_isoc99
)
3288 || warn_declaration_after_statement
))
3289 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3301 c_parser_statement_after_labels (parser
);
3305 error ("label at end of compound statement");
3306 c_parser_consume_token (parser
);
3309 /* Parse a label (C90 6.6.1, C99 6.8.1).
3312 identifier : attributes[opt]
3313 case constant-expression :
3319 case constant-expression ... constant-expression :
3321 The use of attributes on labels is a GNU extension. The syntax in
3322 GNU C accepts any expressions without commas, non-constant
3323 expressions being rejected later. */
3326 c_parser_label (c_parser
*parser
)
3328 location_t loc1
= c_parser_peek_token (parser
)->location
;
3329 tree label
= NULL_TREE
;
3330 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3333 c_parser_consume_token (parser
);
3334 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3335 if (c_parser_next_token_is (parser
, CPP_COLON
))
3337 c_parser_consume_token (parser
);
3338 label
= do_case (exp1
, NULL_TREE
);
3340 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3342 c_parser_consume_token (parser
);
3343 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3344 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3345 label
= do_case (exp1
, exp2
);
3348 c_parser_error (parser
, "expected %<:%> or %<...%>");
3350 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3352 c_parser_consume_token (parser
);
3353 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3354 label
= do_case (NULL_TREE
, NULL_TREE
);
3358 tree name
= c_parser_peek_token (parser
)->value
;
3362 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3363 c_parser_consume_token (parser
);
3364 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3365 loc2
= c_parser_peek_token (parser
)->location
;
3366 c_parser_consume_token (parser
);
3367 attrs
= c_parser_attributes (parser
);
3368 tlab
= define_label (loc2
, name
);
3371 decl_attributes (&tlab
, attrs
, 0);
3372 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3376 SET_EXPR_LOCATION (label
, loc1
);
3379 /* Parse a statement (C90 6.6, C99 6.8).
3384 expression-statement
3392 expression-statement:
3395 selection-statement:
3399 iteration-statement:
3408 return expression[opt] ;
3421 objc-throw-statement
3422 objc-try-catch-statement
3423 objc-synchronized-statement
3425 objc-throw-statement:
3431 c_parser_statement (c_parser
*parser
)
3433 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3434 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3435 || (c_parser_next_token_is (parser
, CPP_NAME
)
3436 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3437 c_parser_label (parser
);
3438 c_parser_statement_after_labels (parser
);
3441 /* Parse a statement, other than a labeled statement. */
3444 c_parser_statement_after_labels (c_parser
*parser
)
3446 location_t loc
= c_parser_peek_token (parser
)->location
;
3447 tree stmt
= NULL_TREE
;
3448 switch (c_parser_peek_token (parser
)->type
)
3450 case CPP_OPEN_BRACE
:
3451 add_stmt (c_parser_compound_statement (parser
));
3454 switch (c_parser_peek_token (parser
)->keyword
)
3457 c_parser_if_statement (parser
);
3460 c_parser_switch_statement (parser
);
3463 c_parser_while_statement (parser
);
3466 c_parser_do_statement (parser
);
3469 c_parser_for_statement (parser
);
3472 c_parser_consume_token (parser
);
3473 if (c_parser_next_token_is (parser
, CPP_NAME
))
3475 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3476 c_parser_consume_token (parser
);
3478 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3480 c_parser_consume_token (parser
);
3481 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3484 c_parser_error (parser
, "expected identifier or %<*%>");
3485 goto expect_semicolon
;
3487 c_parser_consume_token (parser
);
3488 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3489 goto expect_semicolon
;
3491 c_parser_consume_token (parser
);
3492 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3493 goto expect_semicolon
;
3495 c_parser_consume_token (parser
);
3496 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3498 stmt
= c_finish_return (NULL_TREE
);
3499 c_parser_consume_token (parser
);
3503 stmt
= c_finish_return (c_parser_expression (parser
).value
);
3504 goto expect_semicolon
;
3508 stmt
= c_parser_asm_statement (parser
);
3511 gcc_assert (c_dialect_objc ());
3512 c_parser_consume_token (parser
);
3513 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3515 stmt
= objc_build_throw_stmt (NULL_TREE
);
3516 c_parser_consume_token (parser
);
3521 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3522 goto expect_semicolon
;
3526 gcc_assert (c_dialect_objc ());
3527 c_parser_objc_try_catch_statement (parser
);
3529 case RID_AT_SYNCHRONIZED
:
3530 gcc_assert (c_dialect_objc ());
3531 c_parser_objc_synchronized_statement (parser
);
3538 c_parser_consume_token (parser
);
3540 case CPP_CLOSE_PAREN
:
3541 case CPP_CLOSE_SQUARE
:
3542 /* Avoid infinite loop in error recovery:
3543 c_parser_skip_until_found stops at a closing nesting
3544 delimiter without consuming it, but here we need to consume
3545 it to proceed further. */
3546 c_parser_error (parser
, "expected statement");
3547 c_parser_consume_token (parser
);
3551 stmt
= c_finish_expr_stmt (c_parser_expression (parser
).value
);
3553 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3556 /* Two cases cannot and do not have line numbers associated: If stmt
3557 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3558 cannot hold line numbers. But that's OK because the statement
3559 will either be changed to a MODIFY_EXPR during gimplification of
3560 the statement expr, or discarded. If stmt was compound, but
3561 without new variables, we will have skipped the creation of a
3562 BIND and will have a bare STATEMENT_LIST. But that's OK because
3563 (recursively) all of the component statements should already have
3564 line numbers assigned. ??? Can we discard no-op statements
3566 if (stmt
&& EXPR_P (stmt
))
3567 SET_EXPR_LOCATION (stmt
, loc
);
3570 /* Parse a parenthesized condition from an if, do or while statement.
3576 c_parser_paren_condition (c_parser
*parser
)
3580 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3581 return error_mark_node
;
3582 loc
= c_parser_peek_token (parser
)->location
;
3583 cond
= c_objc_common_truthvalue_conversion
3584 (c_parser_expression (parser
).value
);
3586 SET_EXPR_LOCATION (cond
, loc
);
3587 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3591 /* Parse a statement which is a block in C99. */
3594 c_parser_c99_block_statement (c_parser
*parser
)
3596 tree block
= c_begin_compound_stmt (flag_isoc99
);
3597 c_parser_statement (parser
);
3598 return c_end_compound_stmt (block
, flag_isoc99
);
3601 /* Parse the body of an if statement or the else half thereof. This
3602 is just parsing a statement but (a) it is a block in C99, (b) we
3603 track whether the body is an if statement for the sake of
3604 -Wparentheses warnings, (c) we handle an empty body specially for
3605 the sake of -Wextra warnings. */
3608 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3610 tree block
= c_begin_compound_stmt (flag_isoc99
);
3611 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3612 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3613 || (c_parser_next_token_is (parser
, CPP_NAME
)
3614 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3615 c_parser_label (parser
);
3616 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3617 if (extra_warnings
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3618 add_stmt (build (NOP_EXPR
, NULL_TREE
, NULL_TREE
));
3619 c_parser_statement_after_labels (parser
);
3620 return c_end_compound_stmt (block
, flag_isoc99
);
3623 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3626 if ( expression ) statement
3627 if ( expression ) statement else statement
3631 c_parser_if_statement (c_parser
*parser
)
3636 bool first_if
= false, second_if
= false;
3637 tree first_body
, second_body
;
3638 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3639 c_parser_consume_token (parser
);
3640 block
= c_begin_compound_stmt (flag_isoc99
);
3641 loc
= c_parser_peek_token (parser
)->location
;
3642 cond
= c_parser_paren_condition (parser
);
3643 first_body
= c_parser_if_body (parser
, &first_if
);
3644 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3646 c_parser_consume_token (parser
);
3647 second_body
= c_parser_if_body (parser
, &second_if
);
3650 second_body
= NULL_TREE
;
3651 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3652 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3655 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3658 switch (expression) statement
3662 c_parser_switch_statement (c_parser
*parser
)
3664 tree block
, expr
, body
, save_break
;
3665 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3666 c_parser_consume_token (parser
);
3667 block
= c_begin_compound_stmt (flag_isoc99
);
3668 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3670 expr
= c_parser_expression (parser
).value
;
3671 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3674 expr
= error_mark_node
;
3675 c_start_case (expr
);
3676 save_break
= c_break_label
;
3677 c_break_label
= NULL_TREE
;
3678 body
= c_parser_c99_block_statement (parser
);
3679 c_finish_case (body
);
3681 add_stmt (build (LABEL_EXPR
, void_type_node
, c_break_label
));
3682 c_break_label
= save_break
;
3683 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3686 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3689 while (expression) statement
3693 c_parser_while_statement (c_parser
*parser
)
3695 tree block
, cond
, body
, save_break
, save_cont
;
3697 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3698 c_parser_consume_token (parser
);
3699 block
= c_begin_compound_stmt (flag_isoc99
);
3700 loc
= c_parser_peek_token (parser
)->location
;
3701 cond
= c_parser_paren_condition (parser
);
3702 save_break
= c_break_label
;
3703 c_break_label
= NULL_TREE
;
3704 save_cont
= c_cont_label
;
3705 c_cont_label
= NULL_TREE
;
3706 body
= c_parser_c99_block_statement (parser
);
3707 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3708 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3709 c_break_label
= save_break
;
3710 c_cont_label
= save_cont
;
3713 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3716 do statement while ( expression ) ;
3720 c_parser_do_statement (c_parser
*parser
)
3722 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3724 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3725 c_parser_consume_token (parser
);
3726 block
= c_begin_compound_stmt (flag_isoc99
);
3727 loc
= c_parser_peek_token (parser
)->location
;
3728 save_break
= c_break_label
;
3729 c_break_label
= NULL_TREE
;
3730 save_cont
= c_cont_label
;
3731 c_cont_label
= NULL_TREE
;
3732 body
= c_parser_c99_block_statement (parser
);
3733 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3734 new_break
= c_break_label
;
3735 c_break_label
= save_break
;
3736 new_cont
= c_cont_label
;
3737 c_cont_label
= save_cont
;
3738 cond
= c_parser_paren_condition (parser
);
3739 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3740 c_parser_skip_to_end_of_block_or_statement (parser
);
3741 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3742 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3745 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3748 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3749 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3751 The form with a declaration is new in C99.
3753 ??? In accordance with the old parser, the declaration may be a
3754 nested function, which is then rejected in check_for_loop_decls,
3755 but does it make any sense for this to be included in the grammar?
3756 Note in particular that the nested function does not include a
3757 trailing ';', whereas the "declaration" production includes one.
3758 Also, can we reject bad declarations earlier and cheaper than
3759 check_for_loop_decls? */
3762 c_parser_for_statement (c_parser
*parser
)
3764 tree block
, cond
, incr
, save_break
, save_cont
, body
;
3765 location_t loc
= UNKNOWN_LOCATION
;
3766 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
3767 c_parser_consume_token (parser
);
3768 block
= c_begin_compound_stmt (flag_isoc99
);
3769 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3771 /* Parse the initialization declaration or expression. */
3772 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3774 c_parser_consume_token (parser
);
3775 c_finish_expr_stmt (NULL_TREE
);
3777 else if (c_parser_next_token_starts_declspecs (parser
))
3779 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3780 check_for_loop_decls ();
3782 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3784 /* __extension__ can start a declaration, but is also an
3785 unary operator that can start an expression. Consume all
3786 but the last of a possible series of __extension__ to
3788 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3789 && (c_parser_peek_2nd_token (parser
)->keyword
3791 c_parser_consume_token (parser
);
3792 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3795 ext
= disable_extension_diagnostics ();
3796 c_parser_consume_token (parser
);
3797 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3798 restore_extension_diagnostics (ext
);
3799 check_for_loop_decls ();
3807 c_finish_expr_stmt (c_parser_expression (parser
).value
);
3808 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3810 /* Parse the loop condition. */
3811 loc
= c_parser_peek_token (parser
)->location
;
3812 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3814 c_parser_consume_token (parser
);
3819 tree ocond
= c_parser_expression (parser
).value
;
3820 cond
= c_objc_common_truthvalue_conversion (ocond
);
3822 SET_EXPR_LOCATION (cond
, loc
);
3823 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3825 /* Parse the increment expression. */
3826 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3827 incr
= c_process_expr_stmt (NULL_TREE
);
3829 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
3830 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3834 cond
= error_mark_node
;
3835 incr
= error_mark_node
;
3837 save_break
= c_break_label
;
3838 c_break_label
= NULL_TREE
;
3839 save_cont
= c_cont_label
;
3840 c_cont_label
= NULL_TREE
;
3841 body
= c_parser_c99_block_statement (parser
);
3842 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
3843 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3844 c_break_label
= save_break
;
3845 c_cont_label
= save_cont
;
3848 /* Parse an asm statement, a GNU extension. This is a full-blown asm
3849 statement with inputs, outputs, clobbers, and volatile tag
3853 asm type-qualifier[opt] ( asm-argument ) ;
3857 asm-string-literal : asm-operands[opt]
3858 asm-string-literal : asm-operands[opt] : asm-operands[opt]
3859 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
3861 Qualifiers other than volatile are accepted in the syntax but
3865 c_parser_asm_statement (c_parser
*parser
)
3867 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
3869 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3870 c_parser_consume_token (parser
);
3871 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
3873 quals
= c_parser_peek_token (parser
)->value
;
3874 c_parser_consume_token (parser
);
3876 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
3877 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
3879 warning ("%E qualifier ignored on asm",
3880 c_parser_peek_token (parser
)->value
);
3882 c_parser_consume_token (parser
);
3886 /* ??? Follow the C++ parser rather than using the
3887 c_lex_string_translate kludge. */
3888 c_lex_string_translate
= 0;
3889 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3891 c_lex_string_translate
= 1;
3894 str
= c_parser_asm_string_literal (parser
);
3895 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3898 outputs
= NULL_TREE
;
3900 clobbers
= NULL_TREE
;
3903 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3905 c_lex_string_translate
= 1;
3906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3910 /* Parse outputs. */
3911 if (c_parser_next_token_is (parser
, CPP_COLON
)
3912 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3913 outputs
= NULL_TREE
;
3915 outputs
= c_parser_asm_operands (parser
);
3916 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3919 clobbers
= NULL_TREE
;
3922 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3924 c_lex_string_translate
= 1;
3925 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3929 if (c_parser_next_token_is (parser
, CPP_COLON
)
3930 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3933 inputs
= c_parser_asm_operands (parser
);
3934 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3936 clobbers
= NULL_TREE
;
3939 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3941 c_lex_string_translate
= 1;
3942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3945 /* Parse clobbers. */
3946 clobbers
= c_parser_asm_clobbers (parser
);
3948 c_lex_string_translate
= 1;
3949 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3954 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3955 c_parser_skip_to_end_of_block_or_statement (parser
);
3956 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
3961 /* Parse asm operands, a GNU extension.
3965 asm-operands , asm-operand
3968 asm-string-literal ( expression )
3969 [ identifier ] asm-string-literal ( expression )
3973 c_parser_asm_operands (c_parser
*parser
)
3975 tree list
= NULL_TREE
;
3978 tree name
, str
, expr
;
3979 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3981 c_parser_consume_token (parser
);
3982 if (c_parser_next_token_is (parser
, CPP_NAME
))
3984 tree id
= c_parser_peek_token (parser
)->value
;
3985 c_parser_consume_token (parser
);
3986 name
= build_string (IDENTIFIER_LENGTH (id
),
3987 IDENTIFIER_POINTER (id
));
3991 c_parser_error (parser
, "expected identifier");
3992 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3995 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4000 str
= c_parser_asm_string_literal (parser
);
4001 if (str
== NULL_TREE
)
4003 c_lex_string_translate
= 1;
4004 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4006 c_lex_string_translate
= 0;
4009 expr
= c_parser_expression (parser
).value
;
4010 c_lex_string_translate
= 0;
4011 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4013 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4016 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4018 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4019 c_parser_consume_token (parser
);
4026 /* Parse asm clobbers, a GNU extension.
4030 asm-clobbers , asm-string-literal
4034 c_parser_asm_clobbers (c_parser
*parser
)
4036 tree list
= NULL_TREE
;
4039 tree str
= c_parser_asm_string_literal (parser
);
4041 list
= tree_cons (NULL_TREE
, str
, list
);
4044 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4045 c_parser_consume_token (parser
);
4052 /* Parse an expression other than a compound expression; that is, an
4053 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4054 NULL then it is an Objective-C message expression which is the
4055 primary-expression starting the expression as an initializer.
4057 assignment-expression:
4058 conditional-expression
4059 unary-expression assignment-operator assignment-expression
4061 assignment-operator: one of
4062 = *= /= %= += -= <<= >>= &= ^= |=
4064 In GNU C we accept any conditional expression on the LHS and
4065 diagnose the invalid lvalue rather than producing a syntax
4068 static struct c_expr
4069 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4071 struct c_expr lhs
, rhs
, ret
;
4072 enum tree_code code
;
4073 gcc_assert (!after
|| c_dialect_objc ());
4074 lhs
= c_parser_conditional_expression (parser
, after
);
4075 switch (c_parser_peek_token (parser
)->type
)
4084 code
= TRUNC_DIV_EXPR
;
4087 code
= TRUNC_MOD_EXPR
;
4102 code
= BIT_AND_EXPR
;
4105 code
= BIT_XOR_EXPR
;
4108 code
= BIT_IOR_EXPR
;
4113 c_parser_consume_token (parser
);
4114 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4115 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4116 if (code
== NOP_EXPR
)
4117 ret
.original_code
= MODIFY_EXPR
;
4120 TREE_NO_WARNING (ret
.value
) = 1;
4121 ret
.original_code
= ERROR_MARK
;
4126 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4127 is not NULL then it is an Objective-C message expression which is
4128 the primary-expression starting the expression as an initializer.
4130 conditional-expression:
4131 logical-OR-expression
4132 logical-OR-expression ? expression : conditional-expression
4136 conditional-expression:
4137 logical-OR-expression ? : conditional-expression
4140 static struct c_expr
4141 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4143 struct c_expr cond
, exp1
, exp2
, ret
;
4144 gcc_assert (!after
|| c_dialect_objc ());
4145 cond
= c_parser_binary_expression (parser
, after
);
4146 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4148 c_parser_consume_token (parser
);
4149 if (c_parser_next_token_is (parser
, CPP_COLON
))
4152 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4153 /* Make sure first operand is calculated only once. */
4154 exp1
.value
= save_expr (default_conversion (cond
.value
));
4155 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4156 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4161 = c_objc_common_truthvalue_conversion
4162 (default_conversion (cond
.value
));
4163 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4164 exp1
= c_parser_expression (parser
);
4165 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4166 - (cond
.value
== truthvalue_false_node
));
4168 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4170 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4171 ret
.value
= error_mark_node
;
4172 ret
.original_code
= ERROR_MARK
;
4175 exp2
= c_parser_conditional_expression (parser
, NULL
);
4176 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4177 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4178 ret
.original_code
= ERROR_MARK
;
4182 /* Parse a binary expression; that is, a logical-OR-expression (C90
4183 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4184 an Objective-C message expression which is the primary-expression
4185 starting the expression as an initializer.
4187 multiplicative-expression:
4189 multiplicative-expression * cast-expression
4190 multiplicative-expression / cast-expression
4191 multiplicative-expression % cast-expression
4193 additive-expression:
4194 multiplicative-expression
4195 additive-expression + multiplicative-expression
4196 additive-expression - multiplicative-expression
4200 shift-expression << additive-expression
4201 shift-expression >> additive-expression
4203 relational-expression:
4205 relational-expression < shift-expression
4206 relational-expression > shift-expression
4207 relational-expression <= shift-expression
4208 relational-expression >= shift-expression
4210 equality-expression:
4211 relational-expression
4212 equality-expression == relational-expression
4213 equality-expression != relational-expression
4217 AND-expression & equality-expression
4219 exclusive-OR-expression:
4221 exclusive-OR-expression ^ AND-expression
4223 inclusive-OR-expression:
4224 exclusive-OR-expression
4225 inclusive-OR-expression | exclusive-OR-expression
4227 logical-AND-expression:
4228 inclusive-OR-expression
4229 logical-AND-expression && inclusive-OR-expression
4231 logical-OR-expression:
4232 logical-AND-expression
4233 logical-OR-expression || logical-AND-expression
4236 static struct c_expr
4237 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4239 /* A binary expression is parsed using operator-precedence parsing,
4240 with the operands being cast expressions. All the binary
4241 operators are left-associative. Thus a binary expression is of
4244 E0 op1 E1 op2 E2 ...
4246 which we represent on a stack. On the stack, the precedence
4247 levels are strictly increasing. When a new operator is
4248 encountered of higher precedence than that at the top of the
4249 stack, it is pushed; its LHS is the top expression, and its RHS
4250 is everything parsed until it is popped. When a new operator is
4251 encountered with precedence less than or equal to that at the top
4252 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4253 by the result of the operation until the operator at the top of
4254 the stack has lower precedence than the new operator or there is
4255 only one element on the stack; then the top expression is the LHS
4256 of the new operator. In the case of logical AND and OR
4257 expressions, we also need to adjust skip_evaluation as
4258 appropriate when the operators are pushed and popped. */
4260 /* The precedence levels, where 0 is a dummy lowest level used for
4261 the bottom of the stack. */
4277 /* The expression at this stack level. */
4279 /* The precedence of the operator on its left, PREC_NONE at the
4280 bottom of the stack. */
4282 /* The operation on its left. */
4288 switch (stack[sp].op) \
4290 case TRUTH_ANDIF_EXPR: \
4291 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4293 case TRUTH_ORIF_EXPR: \
4294 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4299 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4300 stack[sp - 1].expr, \
4304 gcc_assert (!after
|| c_dialect_objc ());
4305 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4306 stack
[0].prec
= PREC_NONE
;
4311 enum tree_code ocode
;
4314 switch (c_parser_peek_token (parser
)->type
)
4322 ocode
= TRUNC_DIV_EXPR
;
4326 ocode
= TRUNC_MOD_EXPR
;
4338 ocode
= LSHIFT_EXPR
;
4342 ocode
= RSHIFT_EXPR
;
4356 case CPP_GREATER_EQ
:
4369 oprec
= PREC_BITAND
;
4370 ocode
= BIT_AND_EXPR
;
4373 oprec
= PREC_BITXOR
;
4374 ocode
= BIT_XOR_EXPR
;
4378 ocode
= BIT_IOR_EXPR
;
4381 oprec
= PREC_LOGAND
;
4382 ocode
= TRUTH_ANDIF_EXPR
;
4386 ocode
= TRUTH_ORIF_EXPR
;
4389 /* Not a binary operator, so end of the binary
4393 c_parser_consume_token (parser
);
4394 while (oprec
<= stack
[sp
].prec
)
4398 case TRUTH_ANDIF_EXPR
:
4399 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4400 (default_conversion (stack
[sp
].expr
.value
));
4401 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4403 case TRUTH_ORIF_EXPR
:
4404 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4405 (default_conversion (stack
[sp
].expr
.value
));
4406 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4412 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4413 stack
[sp
].prec
= oprec
;
4414 stack
[sp
].op
= ocode
;
4419 return stack
[0].expr
;
4423 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4424 NULL then it is an Objective-C message expression which is the
4425 primary-expression starting the expression as an initializer.
4429 ( type-name ) unary-expression
4432 static struct c_expr
4433 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4435 gcc_assert (!after
|| c_dialect_objc ());
4437 return c_parser_postfix_expression_after_primary (parser
, *after
);
4438 /* If the expression begins with a parenthesized type name, it may
4439 be either a cast or a compound literal; we need to see whether
4440 the next character is '{' to tell the difference. If not, it is
4441 an unary expression. */
4442 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4443 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4445 struct c_type_name
*type_name
;
4448 c_parser_consume_token (parser
);
4449 type_name
= c_parser_type_name (parser
);
4450 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4451 if (type_name
== NULL
)
4453 ret
.value
= error_mark_node
;
4454 ret
.original_code
= ERROR_MARK
;
4457 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4458 return c_parser_postfix_expression_after_paren_type (parser
,
4460 expr
= c_parser_cast_expression (parser
, NULL
).value
;
4461 ret
.value
= c_cast_expr (type_name
, expr
);
4462 ret
.original_code
= ERROR_MARK
;
4466 return c_parser_unary_expression (parser
);
4469 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4475 unary-operator cast-expression
4476 sizeof unary-expression
4477 sizeof ( type-name )
4479 unary-operator: one of
4485 __alignof__ unary-expression
4486 __alignof__ ( type-name )
4489 unary-operator: one of
4490 __extension__ __real__ __imag__
4492 In addition, the GNU syntax treats ++ and -- as unary operators, so
4493 they may be applied to cast expressions with errors for non-lvalues
4496 static struct c_expr
4497 c_parser_unary_expression (c_parser
*parser
)
4501 ret
.original_code
= ERROR_MARK
;
4502 switch (c_parser_peek_token (parser
)->type
)
4505 c_parser_consume_token (parser
);
4507 = build_unary_op (PREINCREMENT_EXPR
,
4508 c_parser_cast_expression (parser
, NULL
).value
, 0);
4509 overflow_warning (ret
.value
);
4511 case CPP_MINUS_MINUS
:
4512 c_parser_consume_token (parser
);
4514 = build_unary_op (PREDECREMENT_EXPR
,
4515 c_parser_cast_expression (parser
, NULL
).value
, 0);
4516 overflow_warning (ret
.value
);
4519 c_parser_consume_token (parser
);
4521 = build_unary_op (ADDR_EXPR
,
4522 c_parser_cast_expression (parser
, NULL
).value
, 0);
4523 overflow_warning (ret
.value
);
4526 c_parser_consume_token (parser
);
4528 = build_indirect_ref (c_parser_cast_expression (parser
, NULL
).value
,
4532 c_parser_consume_token (parser
);
4533 if (!c_dialect_objc () && warn_traditional
&& !in_system_header
)
4534 warning ("traditional C rejects the unary plus operator");
4536 = build_unary_op (CONVERT_EXPR
,
4537 c_parser_cast_expression (parser
, NULL
).value
, 0);
4538 overflow_warning (ret
.value
);
4541 c_parser_consume_token (parser
);
4543 = build_unary_op (NEGATE_EXPR
,
4544 c_parser_cast_expression (parser
, NULL
).value
, 0);
4545 overflow_warning (ret
.value
);
4548 c_parser_consume_token (parser
);
4550 = build_unary_op (BIT_NOT_EXPR
,
4551 c_parser_cast_expression (parser
, NULL
).value
, 0);
4552 overflow_warning (ret
.value
);
4555 c_parser_consume_token (parser
);
4557 = build_unary_op (TRUTH_NOT_EXPR
,
4558 c_parser_cast_expression (parser
, NULL
).value
, 0);
4559 overflow_warning (ret
.value
);
4562 /* Refer to the address of a label as a pointer. */
4563 c_parser_consume_token (parser
);
4564 if (c_parser_next_token_is (parser
, CPP_NAME
))
4566 ret
.value
= finish_label_address_expr
4567 (c_parser_peek_token (parser
)->value
);
4568 c_parser_consume_token (parser
);
4573 c_parser_error (parser
, "expected identifier");
4574 ret
.value
= error_mark_node
;
4578 switch (c_parser_peek_token (parser
)->keyword
)
4581 return c_parser_sizeof_expression (parser
);
4583 return c_parser_alignof_expression (parser
);
4585 c_parser_consume_token (parser
);
4586 ext
= disable_extension_diagnostics ();
4587 ret
= c_parser_cast_expression (parser
, NULL
);
4588 restore_extension_diagnostics (ext
);
4591 c_parser_consume_token (parser
);
4593 = build_unary_op (REALPART_EXPR
,
4594 c_parser_cast_expression (parser
, NULL
).value
,
4598 c_parser_consume_token (parser
);
4600 = build_unary_op (IMAGPART_EXPR
,
4601 c_parser_cast_expression (parser
, NULL
).value
,
4605 return c_parser_postfix_expression (parser
);
4608 return c_parser_postfix_expression (parser
);
4612 /* Parse a sizeof expression. */
4614 static struct c_expr
4615 c_parser_sizeof_expression (c_parser
*parser
)
4618 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4619 c_parser_consume_token (parser
);
4622 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4623 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4625 /* Either sizeof ( type-name ) or sizeof unary-expression
4626 starting with a compound literal. */
4627 struct c_type_name
*type_name
;
4628 c_parser_consume_token (parser
);
4629 type_name
= c_parser_type_name (parser
);
4630 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4631 if (type_name
== NULL
)
4636 ret
.value
= error_mark_node
;
4637 ret
.original_code
= ERROR_MARK
;
4640 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4642 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4646 /* sizeof ( type-name ). */
4649 return c_expr_sizeof_type (type_name
);
4653 expr
= c_parser_unary_expression (parser
);
4657 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4658 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4659 error ("%<sizeof%> applied to a bit-field");
4660 return c_expr_sizeof_expr (expr
);
4664 /* Parse an alignof expression. */
4666 static struct c_expr
4667 c_parser_alignof_expression (c_parser
*parser
)
4670 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4671 c_parser_consume_token (parser
);
4674 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4675 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4677 /* Either __alignof__ ( type-name ) or __alignof__
4678 unary-expression starting with a compound literal. */
4679 struct c_type_name
*type_name
;
4681 c_parser_consume_token (parser
);
4682 type_name
= c_parser_type_name (parser
);
4683 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4684 if (type_name
== NULL
)
4689 ret
.value
= error_mark_node
;
4690 ret
.original_code
= ERROR_MARK
;
4693 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4695 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4699 /* alignof ( type-name ). */
4702 ret
.value
= c_alignof (groktypename (type_name
));
4703 ret
.original_code
= ERROR_MARK
;
4709 expr
= c_parser_unary_expression (parser
);
4713 ret
.value
= c_alignof_expr (expr
.value
);
4714 ret
.original_code
= ERROR_MARK
;
4719 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4723 postfix-expression [ expression ]
4724 postfix-expression ( argument-expression-list[opt] )
4725 postfix-expression . identifier
4726 postfix-expression -> identifier
4727 postfix-expression ++
4728 postfix-expression --
4729 ( type-name ) { initializer-list }
4730 ( type-name ) { initializer-list , }
4732 argument-expression-list:
4734 argument-expression-list , argument-expression
4746 (treated as a keyword in GNU C)
4749 ( compound-statement )
4750 __builtin_va_arg ( assignment-expression , type-name )
4751 __builtin_offsetof ( type-name , offsetof-member-designator )
4752 __builtin_choose_expr ( assignment-expression ,
4753 assignment-expression ,
4754 assignment-expression )
4755 __builtin_types_compatible_p ( type-name , type-name )
4757 offsetof-member-designator:
4759 offsetof-member-designator . identifier
4760 offsetof-member-designator [ expression ]
4765 [ objc-receiver objc-message-args ]
4766 @selector ( objc-selector-arg )
4767 @protocol ( identifier )
4768 @encode ( type-name )
4772 static struct c_expr
4773 c_parser_postfix_expression (c_parser
*parser
)
4775 struct c_expr expr
, e1
, e2
, e3
;
4776 struct c_type_name
*t1
, *t2
;
4777 switch (c_parser_peek_token (parser
)->type
)
4782 expr
.value
= c_parser_peek_token (parser
)->value
;
4783 expr
.original_code
= ERROR_MARK
;
4784 c_parser_consume_token (parser
);
4788 expr
.value
= c_parser_peek_token (parser
)->value
;
4789 expr
.original_code
= STRING_CST
;
4790 c_parser_consume_token (parser
);
4792 case CPP_OBJC_STRING
:
4793 gcc_assert (c_dialect_objc ());
4795 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
4796 expr
.original_code
= ERROR_MARK
;
4797 c_parser_consume_token (parser
);
4800 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
4802 c_parser_error (parser
, "expected expression");
4803 expr
.value
= error_mark_node
;
4804 expr
.original_code
= ERROR_MARK
;
4808 tree id
= c_parser_peek_token (parser
)->value
;
4809 location_t loc
= c_parser_peek_token (parser
)->location
;
4810 c_parser_consume_token (parser
);
4811 expr
.value
= build_external_ref (id
,
4812 (c_parser_peek_token (parser
)->type
4813 == CPP_OPEN_PAREN
), loc
);
4814 expr
.original_code
= ERROR_MARK
;
4817 case CPP_OPEN_PAREN
:
4818 /* A parenthesized expression, statement expression or compound
4820 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
4822 /* A statement expression. */
4824 c_parser_consume_token (parser
);
4825 c_parser_consume_token (parser
);
4826 if (cur_stmt_list
== NULL
)
4828 error ("braced-group within expression allowed "
4829 "only inside a function");
4830 parser
->error
= true;
4831 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
4832 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4833 expr
.value
= error_mark_node
;
4834 expr
.original_code
= ERROR_MARK
;
4837 stmt
= c_begin_stmt_expr ();
4838 c_parser_compound_statement_nostart (parser
);
4839 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4842 pedwarn ("ISO C forbids braced-groups within expressions");
4843 expr
.value
= c_finish_stmt_expr (stmt
);
4844 expr
.original_code
= ERROR_MARK
;
4846 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4848 /* A compound literal. ??? Can we actually get here rather
4849 than going directly to
4850 c_parser_postfix_expression_after_paren_type from
4852 struct c_type_name
*type_name
;
4853 c_parser_consume_token (parser
);
4854 type_name
= c_parser_type_name (parser
);
4855 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4857 if (type_name
== NULL
)
4859 expr
.value
= error_mark_node
;
4860 expr
.original_code
= ERROR_MARK
;
4863 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4868 /* A parenthesized expression. */
4869 c_parser_consume_token (parser
);
4870 expr
= c_parser_expression (parser
);
4871 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
4872 TREE_NO_WARNING (expr
.value
) = 1;
4873 expr
.original_code
= ERROR_MARK
;
4874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4879 switch (c_parser_peek_token (parser
)->keyword
)
4881 case RID_FUNCTION_NAME
:
4882 case RID_PRETTY_FUNCTION_NAME
:
4883 case RID_C99_FUNCTION_NAME
:
4884 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
4885 c_parser_peek_token (parser
)->value
);
4886 expr
.original_code
= ERROR_MARK
;
4887 c_parser_consume_token (parser
);
4890 c_parser_consume_token (parser
);
4891 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4893 expr
.value
= error_mark_node
;
4894 expr
.original_code
= ERROR_MARK
;
4897 e1
= c_parser_expr_no_commas (parser
, NULL
);
4898 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4900 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4901 expr
.value
= error_mark_node
;
4902 expr
.original_code
= ERROR_MARK
;
4905 t1
= c_parser_type_name (parser
);
4906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4910 expr
.value
= error_mark_node
;
4911 expr
.original_code
= ERROR_MARK
;
4915 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
4916 expr
.original_code
= ERROR_MARK
;
4920 c_parser_consume_token (parser
);
4921 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4923 expr
.value
= error_mark_node
;
4924 expr
.original_code
= ERROR_MARK
;
4927 t1
= c_parser_type_name (parser
);
4930 expr
.value
= error_mark_node
;
4931 expr
.original_code
= ERROR_MARK
;
4934 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4937 expr
.value
= error_mark_node
;
4938 expr
.original_code
= ERROR_MARK
;
4942 tree type
= groktypename (t1
);
4944 if (type
== error_mark_node
)
4945 offsetof_ref
= error_mark_node
;
4947 offsetof_ref
= build1 (INDIRECT_REF
, type
, NULL
);
4948 /* Parse the second argument to __builtin_offsetof. We
4949 must have one identifier, and beyond that we want to
4950 accept sub structure and sub array references. */
4951 if (c_parser_next_token_is (parser
, CPP_NAME
))
4953 offsetof_ref
= build_component_ref
4954 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
4955 c_parser_consume_token (parser
);
4956 while (c_parser_next_token_is (parser
, CPP_DOT
)
4957 || c_parser_next_token_is (parser
,
4960 if (c_parser_next_token_is (parser
, CPP_DOT
))
4962 c_parser_consume_token (parser
);
4963 if (c_parser_next_token_is_not (parser
,
4966 c_parser_error (parser
, "expected identifier");
4969 offsetof_ref
= build_component_ref
4971 c_parser_peek_token (parser
)->value
);
4972 c_parser_consume_token (parser
);
4977 c_parser_consume_token (parser
);
4978 idx
= c_parser_expression (parser
).value
;
4979 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4981 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
4986 c_parser_error (parser
, "expected identifier");
4987 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4989 expr
.value
= fold_offsetof (offsetof_ref
);
4990 expr
.original_code
= ERROR_MARK
;
4993 case RID_CHOOSE_EXPR
:
4994 c_parser_consume_token (parser
);
4995 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4997 expr
.value
= error_mark_node
;
4998 expr
.original_code
= ERROR_MARK
;
5001 e1
= c_parser_expr_no_commas (parser
, NULL
);
5002 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5004 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5005 expr
.value
= error_mark_node
;
5006 expr
.original_code
= ERROR_MARK
;
5009 e2
= c_parser_expr_no_commas (parser
, NULL
);
5010 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5012 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5013 expr
.value
= error_mark_node
;
5014 expr
.original_code
= ERROR_MARK
;
5017 e3
= c_parser_expr_no_commas (parser
, NULL
);
5018 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5023 c
= fold (e1
.value
);
5024 if (TREE_CODE (c
) != INTEGER_CST
)
5025 error ("first argument to %<__builtin_choose_expr%> not"
5027 expr
= integer_zerop (c
) ? e3
: e2
;
5030 case RID_TYPES_COMPATIBLE_P
:
5031 c_parser_consume_token (parser
);
5032 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5034 expr
.value
= error_mark_node
;
5035 expr
.original_code
= ERROR_MARK
;
5038 t1
= c_parser_type_name (parser
);
5041 expr
.value
= error_mark_node
;
5042 expr
.original_code
= ERROR_MARK
;
5045 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5047 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5048 expr
.value
= error_mark_node
;
5049 expr
.original_code
= ERROR_MARK
;
5052 t2
= c_parser_type_name (parser
);
5055 expr
.value
= error_mark_node
;
5056 expr
.original_code
= ERROR_MARK
;
5059 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5064 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5065 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5067 expr
.value
= comptypes (e1
, e2
)
5068 ? build_int_cst (NULL_TREE
, 1)
5069 : build_int_cst (NULL_TREE
, 0);
5070 expr
.original_code
= ERROR_MARK
;
5073 case RID_AT_SELECTOR
:
5074 gcc_assert (c_dialect_objc ());
5075 c_parser_consume_token (parser
);
5076 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5078 expr
.value
= error_mark_node
;
5079 expr
.original_code
= ERROR_MARK
;
5083 tree sel
= c_parser_objc_selector_arg (parser
);
5084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5086 expr
.value
= objc_build_selector_expr (sel
);
5087 expr
.original_code
= ERROR_MARK
;
5090 case RID_AT_PROTOCOL
:
5091 gcc_assert (c_dialect_objc ());
5092 c_parser_consume_token (parser
);
5093 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5095 expr
.value
= error_mark_node
;
5096 expr
.original_code
= ERROR_MARK
;
5099 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5101 c_parser_error (parser
, "expected identifier");
5102 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5103 expr
.value
= error_mark_node
;
5104 expr
.original_code
= ERROR_MARK
;
5108 tree id
= c_parser_peek_token (parser
)->value
;
5109 c_parser_consume_token (parser
);
5110 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5112 expr
.value
= objc_build_protocol_expr (id
);
5113 expr
.original_code
= ERROR_MARK
;
5117 /* Extension to support C-structures in the archiver. */
5118 gcc_assert (c_dialect_objc ());
5119 c_parser_consume_token (parser
);
5120 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5122 expr
.value
= error_mark_node
;
5123 expr
.original_code
= ERROR_MARK
;
5126 t1
= c_parser_type_name (parser
);
5129 expr
.value
= error_mark_node
;
5130 expr
.original_code
= ERROR_MARK
;
5131 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5134 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5137 tree type
= groktypename (t1
);
5138 expr
.value
= objc_build_encode_expr (type
);
5139 expr
.original_code
= ERROR_MARK
;
5143 c_parser_error (parser
, "expected expression");
5144 expr
.value
= error_mark_node
;
5145 expr
.original_code
= ERROR_MARK
;
5149 case CPP_OPEN_SQUARE
:
5150 if (c_dialect_objc ())
5152 tree receiver
, args
;
5153 c_parser_consume_token (parser
);
5154 receiver
= c_parser_objc_receiver (parser
);
5155 args
= c_parser_objc_message_args (parser
);
5156 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5158 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5160 expr
.original_code
= ERROR_MARK
;
5163 /* Else fall through to report error. */
5165 c_parser_error (parser
, "expected expression");
5166 expr
.value
= error_mark_node
;
5167 expr
.original_code
= ERROR_MARK
;
5170 return c_parser_postfix_expression_after_primary (parser
, expr
);
5173 /* Parse a postfix expression after a parenthesized type name: the
5174 brace-enclosed initializer of a compound literal, possibly followed
5175 by some postfix operators. This is separate because it is not
5176 possible to tell until after the type name whether a cast
5177 expression has a cast or a compound literal, or whether the operand
5178 of sizeof is a parenthesized type name or starts with a compound
5181 static struct c_expr
5182 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5183 struct c_type_name
*type_name
)
5188 start_init (NULL_TREE
, NULL
, 0);
5189 type
= groktypename (type_name
);
5190 if (C_TYPE_VARIABLE_SIZE (type
))
5192 error ("compound literal has variable size");
5193 type
= error_mark_node
;
5195 init
= c_parser_braced_init (parser
, type
, false);
5197 maybe_warn_string_init (type
, init
);
5199 if (pedantic
&& !flag_isoc99
)
5200 pedwarn ("ISO C90 forbids compound literals");
5201 expr
.value
= build_compound_literal (type
, init
.value
);
5202 expr
.original_code
= ERROR_MARK
;
5203 return c_parser_postfix_expression_after_primary (parser
, expr
);
5206 /* Parse a postfix expression after the initial primary or compound
5207 literal; that is, parse a series of postfix operators. */
5209 static struct c_expr
5210 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5213 tree ident
, idx
, exprlist
;
5216 switch (c_parser_peek_token (parser
)->type
)
5218 case CPP_OPEN_SQUARE
:
5219 /* Array reference. */
5220 c_parser_consume_token (parser
);
5221 idx
= c_parser_expression (parser
).value
;
5222 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5224 expr
.value
= build_array_ref (expr
.value
, idx
);
5225 expr
.original_code
= ERROR_MARK
;
5227 case CPP_OPEN_PAREN
:
5228 /* Function call. */
5229 c_parser_consume_token (parser
);
5230 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5231 exprlist
= NULL_TREE
;
5233 exprlist
= c_parser_expr_list (parser
);
5234 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5236 expr
.value
= build_function_call (expr
.value
, exprlist
);
5237 expr
.original_code
= ERROR_MARK
;
5240 /* Structure element reference. */
5241 c_parser_consume_token (parser
);
5242 if (c_parser_next_token_is (parser
, CPP_NAME
))
5243 ident
= c_parser_peek_token (parser
)->value
;
5246 c_parser_error (parser
, "expected identifier");
5247 expr
.value
= error_mark_node
;
5248 expr
.original_code
= ERROR_MARK
;
5251 c_parser_consume_token (parser
);
5252 expr
.value
= build_component_ref (expr
.value
, ident
);
5253 expr
.original_code
= ERROR_MARK
;
5256 /* Structure element reference. */
5257 c_parser_consume_token (parser
);
5258 if (c_parser_next_token_is (parser
, CPP_NAME
))
5259 ident
= c_parser_peek_token (parser
)->value
;
5262 c_parser_error (parser
, "expected identifier");
5263 expr
.value
= error_mark_node
;
5264 expr
.original_code
= ERROR_MARK
;
5267 c_parser_consume_token (parser
);
5268 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5270 expr
.original_code
= ERROR_MARK
;
5273 /* Postincrement. */
5274 c_parser_consume_token (parser
);
5275 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5276 expr
.original_code
= ERROR_MARK
;
5278 case CPP_MINUS_MINUS
:
5279 /* Postdecrement. */
5280 c_parser_consume_token (parser
);
5281 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5282 expr
.original_code
= ERROR_MARK
;
5290 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5293 assignment-expression
5294 expression , assignment-expression
5297 static struct c_expr
5298 c_parser_expression (c_parser
*parser
)
5301 expr
= c_parser_expr_no_commas (parser
, NULL
);
5302 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5305 c_parser_consume_token (parser
);
5306 next
= c_parser_expr_no_commas (parser
, NULL
);
5307 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5308 expr
.original_code
= COMPOUND_EXPR
;
5313 /* Parse a non-empty list of expressions.
5316 assignment-expression
5317 nonempty-expr-list , assignment-expression
5321 c_parser_expr_list (c_parser
*parser
)
5325 expr
= c_parser_expr_no_commas (parser
, NULL
);
5326 ret
= build_tree_list (NULL_TREE
, expr
.value
);
5327 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5329 c_parser_consume_token (parser
);
5330 expr
= c_parser_expr_no_commas (parser
, NULL
);
5331 ret
= chainon (ret
, build_tree_list (NULL_TREE
, expr
.value
));
5337 /* Parse Objective-C-specific constructs. */
5339 /* Parse an objc-class-definition.
5341 objc-class-definition:
5342 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5343 objc-class-instance-variables[opt] objc-methodprotolist @end
5344 @implementation identifier objc-superclass[opt]
5345 objc-class-instance-variables[opt]
5346 @interface identifier ( identifier ) objc-protocol-refs[opt]
5347 objc-methodprotolist @end
5348 @implementation identifier ( identifier )
5353 "@interface identifier (" must start "@interface identifier (
5354 identifier ) ...": objc-methodprotolist in the first production may
5355 not start with a parenthesised identifier as a declarator of a data
5356 definition with no declaration specifiers if the objc-superclass,
5357 objc-protocol-refs and objc-class-instance-variables are omitted. */
5360 c_parser_objc_class_definition (c_parser
*parser
)
5365 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5367 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5371 c_parser_consume_token (parser
);
5372 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5374 c_parser_error (parser
, "expected identifier");
5377 id1
= c_parser_peek_token (parser
)->value
;
5378 c_parser_consume_token (parser
);
5379 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5382 tree proto
= NULL_TREE
;
5383 c_parser_consume_token (parser
);
5384 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5386 c_parser_error (parser
, "expected identifier");
5387 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5390 id2
= c_parser_peek_token (parser
)->value
;
5391 c_parser_consume_token (parser
);
5392 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5395 objc_start_category_implementation (id1
, id2
);
5398 if (c_parser_next_token_is (parser
, CPP_LESS
))
5399 proto
= c_parser_objc_protocol_refs (parser
);
5400 objc_start_category_interface (id1
, id2
, proto
);
5401 c_parser_objc_methodprotolist (parser
);
5402 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5403 objc_finish_interface ();
5406 if (c_parser_next_token_is (parser
, CPP_COLON
))
5408 c_parser_consume_token (parser
);
5409 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5411 c_parser_error (parser
, "expected identifier");
5414 superclass
= c_parser_peek_token (parser
)->value
;
5415 c_parser_consume_token (parser
);
5418 superclass
= NULL_TREE
;
5421 tree proto
= NULL_TREE
;
5422 if (c_parser_next_token_is (parser
, CPP_LESS
))
5423 proto
= c_parser_objc_protocol_refs (parser
);
5424 objc_start_class_interface (id1
, superclass
, proto
);
5427 objc_start_class_implementation (id1
, superclass
);
5428 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5429 c_parser_objc_class_instance_variables (parser
);
5432 objc_continue_interface ();
5433 c_parser_objc_methodprotolist (parser
);
5434 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5435 objc_finish_interface ();
5439 objc_continue_implementation ();
5444 /* Parse objc-class-instance-variables.
5446 objc-class-instance-variables:
5447 { objc-instance-variable-decl-list[opt] }
5449 objc-instance-variable-decl-list:
5450 objc-visibility-spec
5451 objc-instance-variable-decl ;
5453 objc-instance-variable-decl-list objc-visibility-spec
5454 objc-instance-variable-decl-list objc-instance-variable-decl ;
5455 objc-instance-variable-decl-list ;
5457 objc-visibility-spec:
5462 objc-instance-variable-decl:
5467 c_parser_objc_class_instance_variables (c_parser
*parser
)
5469 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5470 c_parser_consume_token (parser
);
5471 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5474 /* Parse any stray semicolon. */
5475 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5478 pedwarn ("extra semicolon in struct or union specified");
5479 c_parser_consume_token (parser
);
5482 /* Stop if at the end of the instance variables. */
5483 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5485 c_parser_consume_token (parser
);
5488 /* Parse any objc-visibility-spec. */
5489 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5491 c_parser_consume_token (parser
);
5492 objc_set_visibility (2);
5495 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5497 c_parser_consume_token (parser
);
5498 objc_set_visibility (0);
5501 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5503 c_parser_consume_token (parser
);
5504 objc_set_visibility (1);
5507 /* Parse some comma-separated declarations. */
5508 decls
= c_parser_struct_declaration (parser
);
5510 /* Comma-separated instance variables are chained together in
5511 reverse order; add them one by one. */
5512 tree ivar
= nreverse (decls
);
5513 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5514 objc_add_instance_variable (copy_node (ivar
));
5516 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5520 /* Parse an objc-class-declaration.
5522 objc-class-declaration:
5523 @class identifier-list ;
5527 c_parser_objc_class_declaration (c_parser
*parser
)
5529 tree list
= NULL_TREE
;
5530 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5531 c_parser_consume_token (parser
);
5532 /* Any identifiers, including those declared as type names, are OK
5537 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5539 c_parser_error (parser
, "expected identifier");
5542 id
= c_parser_peek_token (parser
)->value
;
5543 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5544 c_parser_consume_token (parser
);
5545 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5546 c_parser_consume_token (parser
);
5550 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5551 objc_declare_class (list
);
5554 /* Parse an objc-alias-declaration.
5556 objc-alias-declaration:
5557 @compatibility_alias identifier identifier ;
5561 c_parser_objc_alias_declaration (c_parser
*parser
)
5564 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5565 c_parser_consume_token (parser
);
5566 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5568 c_parser_error (parser
, "expected identifier");
5569 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5572 id1
= c_parser_peek_token (parser
)->value
;
5573 c_parser_consume_token (parser
);
5574 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5576 c_parser_error (parser
, "expected identifier");
5577 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5580 id2
= c_parser_peek_token (parser
)->value
;
5581 c_parser_consume_token (parser
);
5582 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5583 objc_declare_alias (id1
, id2
);
5586 /* Parse an objc-protocol-definition.
5588 objc-protocol-definition:
5589 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5590 @protocol identifier-list ;
5592 "@protocol identifier ;" should be resolved as "@protocol
5593 identifier-list ;": objc-methodprotolist may not start with a
5594 semicolon in the first alternative if objc-protocol-refs are
5598 c_parser_objc_protocol_definition (c_parser
*parser
)
5600 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5601 c_parser_consume_token (parser
);
5602 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5604 c_parser_error (parser
, "expected identifier");
5607 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5608 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5610 tree list
= NULL_TREE
;
5611 /* Any identifiers, including those declared as type names, are
5616 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5618 c_parser_error (parser
, "expected identifier");
5621 id
= c_parser_peek_token (parser
)->value
;
5622 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5623 c_parser_consume_token (parser
);
5624 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5625 c_parser_consume_token (parser
);
5629 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5630 objc_declare_protocols (list
);
5634 tree id
= c_parser_peek_token (parser
)->value
;
5635 tree proto
= NULL_TREE
;
5636 c_parser_consume_token (parser
);
5637 if (c_parser_next_token_is (parser
, CPP_LESS
))
5638 proto
= c_parser_objc_protocol_refs (parser
);
5639 objc_pq_context
= 1;
5640 objc_start_protocol (id
, proto
);
5641 c_parser_objc_methodprotolist (parser
);
5642 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5643 objc_pq_context
= 0;
5644 objc_finish_interface ();
5648 /* Parse an objc-method-type.
5655 static enum tree_code
5656 c_parser_objc_method_type (c_parser
*parser
)
5658 switch (c_parser_peek_token (parser
)->type
)
5661 c_parser_consume_token (parser
);
5664 c_parser_consume_token (parser
);
5671 /* Parse an objc-method-definition.
5673 objc-method-definition:
5674 objc-method-type objc-method-decl ;[opt] compound-statement
5678 c_parser_objc_method_definition (c_parser
*parser
)
5680 enum tree_code type
= c_parser_objc_method_type (parser
);
5682 objc_set_method_type (type
);
5683 objc_pq_context
= 1;
5684 decl
= c_parser_objc_method_decl (parser
);
5685 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5687 c_parser_consume_token (parser
);
5689 pedwarn ("extra semicolon in method definition specified");
5691 objc_pq_context
= 0;
5692 objc_start_method_definition (decl
);
5693 add_stmt (c_parser_compound_statement (parser
));
5694 objc_finish_method_definition (current_function_decl
);
5697 /* Parse an objc-methodprotolist.
5699 objc-methodprotolist:
5701 objc-methodprotolist objc-methodproto
5702 objc-methodprotolist declaration
5703 objc-methodprotolist ;
5705 The declaration is a data definition, which may be missing
5706 declaration specifiers under the same rules and diagnostics as
5707 other data definitions outside functions, and the stray semicolon
5708 is diagnosed the same way as a stray semicolon outside a
5712 c_parser_objc_methodprotolist (c_parser
*parser
)
5716 /* The list is terminated by @end. */
5717 switch (c_parser_peek_token (parser
)->type
)
5721 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5722 c_parser_consume_token (parser
);
5726 c_parser_objc_methodproto (parser
);
5731 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
5733 c_parser_declaration_or_fndef (parser
, false, true, false, true);
5739 /* Parse an objc-methodproto.
5742 objc-method-type objc-method-decl ;
5746 c_parser_objc_methodproto (c_parser
*parser
)
5748 enum tree_code type
= c_parser_objc_method_type (parser
);
5750 objc_set_method_type (type
);
5751 /* Remember protocol qualifiers in prototypes. */
5752 objc_pq_context
= 1;
5753 decl
= c_parser_objc_method_decl (parser
);
5754 /* Forget protocol qualifiers here. */
5755 objc_pq_context
= 0;
5756 objc_add_method_declaration (decl
);
5757 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5760 /* Parse an objc-method-decl.
5763 ( objc-type-name ) objc-selector
5765 ( objc-type-name ) objc-keyword-selector objc-optparmlist
5766 objc-keyword-selector objc-optparmlist
5768 objc-keyword-selector:
5770 objc-keyword-selector objc-keyword-decl
5773 objc-selector : ( objc-type-name ) identifier
5774 objc-selector : identifier
5775 : ( objc-type-name ) identifier
5779 objc-optparms objc-optellipsis
5783 objc-opt-parms , parameter-declaration
5791 c_parser_objc_method_decl (c_parser
*parser
)
5793 tree type
= NULL_TREE
;
5795 tree parms
= NULL_TREE
;
5796 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5798 c_parser_consume_token (parser
);
5799 type
= c_parser_objc_type_name (parser
);
5800 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5802 sel
= c_parser_objc_selector (parser
);
5803 /* If there is no selector, or a colon follows, we have an
5804 objc-keyword-selector. If there is a selector, and a colon does
5805 not follow, that selector ends the objc-method-decl. */
5806 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
5809 tree list
= NULL_TREE
;
5813 tree atype
= NULL_TREE
, id
, keyworddecl
;
5814 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5816 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5818 c_parser_consume_token (parser
);
5819 atype
= c_parser_objc_type_name (parser
);
5820 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5823 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5825 c_parser_error (parser
, "expected identifier");
5826 return error_mark_node
;
5828 id
= c_parser_peek_token (parser
)->value
;
5829 c_parser_consume_token (parser
);
5830 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
5831 list
= chainon (list
, keyworddecl
);
5832 tsel
= c_parser_objc_selector (parser
);
5833 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
5836 /* Parse the optional parameter list. Optional Objective-C
5837 method parameters follow the C syntax, and may include '...'
5838 to denote a variable number of arguments. */
5839 parms
= make_node (TREE_LIST
);
5841 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5843 struct c_parm
*parm
;
5844 c_parser_consume_token (parser
);
5845 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5848 c_parser_consume_token (parser
);
5851 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5854 parms
= chainon (parms
,
5855 build_tree_list (NULL_TREE
, grokparm (parm
)));
5857 TREE_OVERFLOW (parms
) = ellipsis
;
5860 return objc_build_method_signature (type
, sel
, parms
);
5863 /* Parse an objc-type-name.
5866 objc-type-qualifiers[opt] type-name
5867 objc-type-qualifiers[opt]
5869 objc-type-qualifiers:
5871 objc-type-qualifiers objc-type-qualifier
5873 objc-type-qualifier: one of
5874 in out inout bycopy byref oneway
5878 c_parser_objc_type_name (c_parser
*parser
)
5880 tree quals
= NULL_TREE
;
5881 struct c_type_name
*typename
= NULL
;
5882 tree type
= NULL_TREE
;
5885 c_token
*token
= c_parser_peek_token (parser
);
5886 if (token
->type
== CPP_KEYWORD
5887 && (token
->keyword
== RID_IN
5888 || token
->keyword
== RID_OUT
5889 || token
->keyword
== RID_INOUT
5890 || token
->keyword
== RID_BYCOPY
5891 || token
->keyword
== RID_BYREF
5892 || token
->keyword
== RID_ONEWAY
))
5894 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
5895 c_parser_consume_token (parser
);
5900 if (c_parser_next_token_starts_typename (parser
))
5901 typename
= c_parser_type_name (parser
);
5903 type
= groktypename (typename
);
5904 return build_tree_list (quals
, type
);
5907 /* Parse objc-protocol-refs.
5914 c_parser_objc_protocol_refs (c_parser
*parser
)
5916 tree list
= NULL_TREE
;
5917 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
5918 c_parser_consume_token (parser
);
5919 /* Any identifiers, including those declared as type names, are OK
5924 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5926 c_parser_error (parser
, "expected identifier");
5929 id
= c_parser_peek_token (parser
)->value
;
5930 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5931 c_parser_consume_token (parser
);
5932 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5933 c_parser_consume_token (parser
);
5937 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
5941 /* Parse an objc-try-catch-statement.
5943 objc-try-catch-statement:
5944 @try compound-statement objc-catch-list[opt]
5945 @try compound-statement objc-catch-list[opt] @finally compound-statement
5948 @catch ( parameter-declaration ) compound-statement
5949 objc-catch-list @catch ( parameter-declaration ) compound-statement
5953 c_parser_objc_try_catch_statement (c_parser
*parser
)
5957 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
5958 c_parser_consume_token (parser
);
5959 loc
= c_parser_peek_token (parser
)->location
;
5960 stmt
= c_parser_compound_statement (parser
);
5961 objc_begin_try_stmt (loc
, stmt
);
5962 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
5964 struct c_parm
*parm
;
5965 c_parser_consume_token (parser
);
5966 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5968 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5971 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5974 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5975 objc_begin_catch_clause (grokparm (parm
));
5976 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
5977 c_parser_compound_statement_nostart (parser
);
5978 objc_finish_catch_clause ();
5980 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
5984 c_parser_consume_token (parser
);
5985 finloc
= c_parser_peek_token (parser
)->location
;
5986 finstmt
= c_parser_compound_statement (parser
);
5987 objc_build_finally_clause (finloc
, finstmt
);
5989 objc_finish_try_stmt ();
5992 /* Parse an objc-synchronized-statement.
5994 objc-synchronized-statement:
5995 @synchronized ( expression ) compound-statement
5999 c_parser_objc_synchronized_statement (c_parser
*parser
)
6003 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6004 c_parser_consume_token (parser
);
6005 loc
= c_parser_peek_token (parser
)->location
;
6006 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6008 expr
= c_parser_expression (parser
).value
;
6009 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6012 expr
= error_mark_node
;
6013 stmt
= c_parser_compound_statement (parser
);
6014 objc_build_synchronized (loc
, expr
, stmt
);
6017 /* Parse an objc-selector; return NULL_TREE without an error if the
6018 next token is not an objc-selector.
6023 enum struct union if else while do for switch case default
6024 break continue return goto asm sizeof typeof __alignof
6025 unsigned long const short volatile signed restrict _Complex
6026 in out inout bycopy byref oneway int char float double void _Bool
6028 ??? Why this selection of keywords but not, for example, storage
6029 class specifiers? */
6032 c_parser_objc_selector (c_parser
*parser
)
6034 c_token
*token
= c_parser_peek_token (parser
);
6035 tree value
= token
->value
;
6036 if (token
->type
== CPP_NAME
)
6038 c_parser_consume_token (parser
);
6041 if (token
->type
!= CPP_KEYWORD
)
6043 switch (token
->keyword
)
6084 c_parser_consume_token (parser
);
6091 /* Parse an objc-selector-arg.
6095 objc-keywordname-list
6097 objc-keywordname-list:
6099 objc-keywordname-list objc-keywordname
6107 c_parser_objc_selector_arg (c_parser
*parser
)
6109 tree sel
= c_parser_objc_selector (parser
);
6110 tree list
= NULL_TREE
;
6111 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6115 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6117 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6118 sel
= c_parser_objc_selector (parser
);
6119 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6125 /* Parse an objc-receiver.
6134 c_parser_objc_receiver (c_parser
*parser
)
6136 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6137 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6138 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6140 tree id
= c_parser_peek_token (parser
)->value
;
6141 c_parser_consume_token (parser
);
6142 return objc_get_class_reference (id
);
6144 return c_parser_expression (parser
).value
;
6147 /* Parse objc-message-args.
6151 objc-keywordarg-list
6153 objc-keywordarg-list:
6155 objc-keywordarg-list objc-keywordarg
6158 objc-selector : objc-keywordexpr
6163 c_parser_objc_message_args (c_parser
*parser
)
6165 tree sel
= c_parser_objc_selector (parser
);
6166 tree list
= NULL_TREE
;
6167 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6172 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6174 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6175 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6176 sel
= c_parser_objc_selector (parser
);
6177 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6183 /* Parse an objc-keywordexpr.
6190 c_parser_objc_keywordexpr (c_parser
*parser
)
6192 tree list
= c_parser_expr_list (parser
);
6193 if (TREE_CHAIN (list
) == NULL_TREE
)
6195 /* Just return the expression, remove a level of
6197 return TREE_VALUE (list
);
6201 /* We have a comma expression, we will collapse later. */
6207 /* The actual parser and external interface. ??? Does this need to be
6208 garbage-collected? */
6210 static GTY (()) c_parser
*the_parser
;
6212 /* Parse a single source file. */
6217 the_parser
= c_parser_new ();
6218 c_parser_translation_unit (the_parser
);
6222 #include "gt-c-parser.h"