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 parser
->error
= true;
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
= lang_hooks
.truthvalue_conversion (c_parser_expression (parser
).value
);
3585 SET_EXPR_LOCATION (cond
, loc
);
3586 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3590 /* Parse a statement which is a block in C99. */
3593 c_parser_c99_block_statement (c_parser
*parser
)
3595 tree block
= c_begin_compound_stmt (flag_isoc99
);
3596 c_parser_statement (parser
);
3597 return c_end_compound_stmt (block
, flag_isoc99
);
3600 /* Parse the body of an if statement or the else half thereof. This
3601 is just parsing a statement but (a) it is a block in C99, (b) we
3602 track whether the body is an if statement for the sake of
3603 -Wparentheses warnings, (c) we handle an empty body specially for
3604 the sake of -Wextra warnings. */
3607 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3609 tree block
= c_begin_compound_stmt (flag_isoc99
);
3610 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3611 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3612 || (c_parser_next_token_is (parser
, CPP_NAME
)
3613 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3614 c_parser_label (parser
);
3615 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3616 if (extra_warnings
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3617 add_stmt (build (NOP_EXPR
, NULL_TREE
, NULL_TREE
));
3618 c_parser_statement_after_labels (parser
);
3619 return c_end_compound_stmt (block
, flag_isoc99
);
3622 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3625 if ( expression ) statement
3626 if ( expression ) statement else statement
3630 c_parser_if_statement (c_parser
*parser
)
3635 bool first_if
= false, second_if
= false;
3636 tree first_body
, second_body
;
3637 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3638 c_parser_consume_token (parser
);
3639 block
= c_begin_compound_stmt (flag_isoc99
);
3640 loc
= c_parser_peek_token (parser
)->location
;
3641 cond
= c_parser_paren_condition (parser
);
3642 first_body
= c_parser_if_body (parser
, &first_if
);
3643 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3645 c_parser_consume_token (parser
);
3646 second_body
= c_parser_if_body (parser
, &second_if
);
3649 second_body
= NULL_TREE
;
3650 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3651 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3654 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3657 switch (expression) statement
3661 c_parser_switch_statement (c_parser
*parser
)
3663 tree block
, expr
, body
, save_break
;
3664 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3665 c_parser_consume_token (parser
);
3666 block
= c_begin_compound_stmt (flag_isoc99
);
3667 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3669 expr
= c_parser_expression (parser
).value
;
3670 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3673 expr
= error_mark_node
;
3674 c_start_case (expr
);
3675 save_break
= c_break_label
;
3676 c_break_label
= NULL_TREE
;
3677 body
= c_parser_c99_block_statement (parser
);
3678 c_finish_case (body
);
3680 add_stmt (build (LABEL_EXPR
, void_type_node
, c_break_label
));
3681 c_break_label
= save_break
;
3682 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3685 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3688 while (expression) statement
3692 c_parser_while_statement (c_parser
*parser
)
3694 tree block
, cond
, body
, save_break
, save_cont
;
3696 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3697 c_parser_consume_token (parser
);
3698 block
= c_begin_compound_stmt (flag_isoc99
);
3699 loc
= c_parser_peek_token (parser
)->location
;
3700 cond
= c_parser_paren_condition (parser
);
3701 save_break
= c_break_label
;
3702 c_break_label
= NULL_TREE
;
3703 save_cont
= c_cont_label
;
3704 c_cont_label
= NULL_TREE
;
3705 body
= c_parser_c99_block_statement (parser
);
3706 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3707 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3708 c_break_label
= save_break
;
3709 c_cont_label
= save_cont
;
3712 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3715 do statement while ( expression ) ;
3719 c_parser_do_statement (c_parser
*parser
)
3721 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3723 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3724 c_parser_consume_token (parser
);
3725 block
= c_begin_compound_stmt (flag_isoc99
);
3726 loc
= c_parser_peek_token (parser
)->location
;
3727 save_break
= c_break_label
;
3728 c_break_label
= NULL_TREE
;
3729 save_cont
= c_cont_label
;
3730 c_cont_label
= NULL_TREE
;
3731 body
= c_parser_c99_block_statement (parser
);
3732 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3733 new_break
= c_break_label
;
3734 c_break_label
= save_break
;
3735 new_cont
= c_cont_label
;
3736 c_cont_label
= save_cont
;
3737 cond
= c_parser_paren_condition (parser
);
3738 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3739 c_parser_skip_to_end_of_block_or_statement (parser
);
3740 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3741 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3744 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3747 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3748 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3750 The form with a declaration is new in C99.
3752 ??? In accordance with the old parser, the declaration may be a
3753 nested function, which is then rejected in check_for_loop_decls,
3754 but does it make any sense for this to be included in the grammar?
3755 Note in particular that the nested function does not include a
3756 trailing ';', whereas the "declaration" production includes one.
3757 Also, can we reject bad declarations earlier and cheaper than
3758 check_for_loop_decls? */
3761 c_parser_for_statement (c_parser
*parser
)
3763 tree block
, cond
, incr
, save_break
, save_cont
, body
;
3764 location_t loc
= UNKNOWN_LOCATION
;
3765 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
3766 c_parser_consume_token (parser
);
3767 block
= c_begin_compound_stmt (flag_isoc99
);
3768 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3770 /* Parse the initialization declaration or expression. */
3771 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3773 c_parser_consume_token (parser
);
3774 c_finish_expr_stmt (NULL_TREE
);
3776 else if (c_parser_next_token_starts_declspecs (parser
))
3778 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3779 check_for_loop_decls ();
3781 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3783 /* __extension__ can start a declaration, but is also an
3784 unary operator that can start an expression. Consume all
3785 but the last of a possible series of __extension__ to
3787 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3788 && (c_parser_peek_2nd_token (parser
)->keyword
3790 c_parser_consume_token (parser
);
3791 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3794 ext
= disable_extension_diagnostics ();
3795 c_parser_consume_token (parser
);
3796 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3797 restore_extension_diagnostics (ext
);
3798 check_for_loop_decls ();
3806 c_finish_expr_stmt (c_parser_expression (parser
).value
);
3807 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3809 /* Parse the loop condition. */
3810 loc
= c_parser_peek_token (parser
)->location
;
3811 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3813 c_parser_consume_token (parser
);
3818 tree ocond
= c_parser_expression (parser
).value
;
3819 cond
= lang_hooks
.truthvalue_conversion (ocond
);
3821 SET_EXPR_LOCATION (cond
, loc
);
3822 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3824 /* Parse the increment expression. */
3825 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3826 incr
= c_process_expr_stmt (NULL_TREE
);
3828 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
3829 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3833 cond
= error_mark_node
;
3834 incr
= error_mark_node
;
3836 save_break
= c_break_label
;
3837 c_break_label
= NULL_TREE
;
3838 save_cont
= c_cont_label
;
3839 c_cont_label
= NULL_TREE
;
3840 body
= c_parser_c99_block_statement (parser
);
3841 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
3842 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3843 c_break_label
= save_break
;
3844 c_cont_label
= save_cont
;
3847 /* Parse an asm statement, a GNU extension. This is a full-blown asm
3848 statement with inputs, outputs, clobbers, and volatile tag
3852 asm type-qualifier[opt] ( asm-argument ) ;
3856 asm-string-literal : asm-operands[opt]
3857 asm-string-literal : asm-operands[opt] : asm-operands[opt]
3858 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
3860 Qualifiers other than volatile are accepted in the syntax but
3864 c_parser_asm_statement (c_parser
*parser
)
3866 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
3868 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3869 c_parser_consume_token (parser
);
3870 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
3872 quals
= c_parser_peek_token (parser
)->value
;
3873 c_parser_consume_token (parser
);
3875 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
3876 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
3878 warning ("%E qualifier ignored on asm",
3879 c_parser_peek_token (parser
)->value
);
3881 c_parser_consume_token (parser
);
3885 /* ??? Follow the C++ parser rather than using the
3886 c_lex_string_translate kludge. */
3887 c_lex_string_translate
= 0;
3888 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3890 c_lex_string_translate
= 1;
3893 str
= c_parser_asm_string_literal (parser
);
3894 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3897 outputs
= NULL_TREE
;
3899 clobbers
= NULL_TREE
;
3902 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3904 c_lex_string_translate
= 1;
3905 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3909 /* Parse outputs. */
3910 if (c_parser_next_token_is (parser
, CPP_COLON
)
3911 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3912 outputs
= NULL_TREE
;
3914 outputs
= c_parser_asm_operands (parser
);
3915 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3918 clobbers
= NULL_TREE
;
3921 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3923 c_lex_string_translate
= 1;
3924 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3928 if (c_parser_next_token_is (parser
, CPP_COLON
)
3929 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3932 inputs
= c_parser_asm_operands (parser
);
3933 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3935 clobbers
= NULL_TREE
;
3938 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3940 c_lex_string_translate
= 1;
3941 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3944 /* Parse clobbers. */
3945 clobbers
= c_parser_asm_clobbers (parser
);
3947 c_lex_string_translate
= 1;
3948 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3953 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3954 c_parser_skip_to_end_of_block_or_statement (parser
);
3955 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
3960 /* Parse asm operands, a GNU extension.
3964 asm-operands , asm-operand
3967 asm-string-literal ( expression )
3968 [ identifier ] asm-string-literal ( expression )
3972 c_parser_asm_operands (c_parser
*parser
)
3974 tree list
= NULL_TREE
;
3977 tree name
, str
, expr
;
3978 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3980 c_parser_consume_token (parser
);
3981 if (c_parser_next_token_is (parser
, CPP_NAME
))
3983 tree id
= c_parser_peek_token (parser
)->value
;
3984 c_parser_consume_token (parser
);
3985 name
= build_string (IDENTIFIER_LENGTH (id
),
3986 IDENTIFIER_POINTER (id
));
3990 c_parser_error (parser
, "expected identifier");
3991 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3994 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3999 str
= c_parser_asm_string_literal (parser
);
4000 if (str
== NULL_TREE
)
4002 c_lex_string_translate
= 1;
4003 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4005 c_lex_string_translate
= 0;
4008 expr
= c_parser_expression (parser
).value
;
4009 c_lex_string_translate
= 0;
4010 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4012 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4015 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4017 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4018 c_parser_consume_token (parser
);
4025 /* Parse asm clobbers, a GNU extension.
4029 asm-clobbers , asm-string-literal
4033 c_parser_asm_clobbers (c_parser
*parser
)
4035 tree list
= NULL_TREE
;
4038 tree str
= c_parser_asm_string_literal (parser
);
4040 list
= tree_cons (NULL_TREE
, str
, list
);
4043 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4044 c_parser_consume_token (parser
);
4051 /* Parse an expression other than a compound expression; that is, an
4052 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4053 NULL then it is an Objective-C message expression which is the
4054 primary-expression starting the expression as an initializer.
4056 assignment-expression:
4057 conditional-expression
4058 unary-expression assignment-operator assignment-expression
4060 assignment-operator: one of
4061 = *= /= %= += -= <<= >>= &= ^= |=
4063 In GNU C we accept any conditional expression on the LHS and
4064 diagnose the invalid lvalue rather than producing a syntax
4067 static struct c_expr
4068 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4070 struct c_expr lhs
, rhs
, ret
;
4071 enum tree_code code
;
4072 gcc_assert (!after
|| c_dialect_objc ());
4073 lhs
= c_parser_conditional_expression (parser
, after
);
4074 switch (c_parser_peek_token (parser
)->type
)
4083 code
= TRUNC_DIV_EXPR
;
4086 code
= TRUNC_MOD_EXPR
;
4101 code
= BIT_AND_EXPR
;
4104 code
= BIT_XOR_EXPR
;
4107 code
= BIT_IOR_EXPR
;
4112 c_parser_consume_token (parser
);
4113 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4114 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4115 if (code
== NOP_EXPR
)
4116 ret
.original_code
= MODIFY_EXPR
;
4119 TREE_NO_WARNING (ret
.value
) = 1;
4120 ret
.original_code
= ERROR_MARK
;
4125 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4126 is not NULL then it is an Objective-C message expression which is
4127 the primary-expression starting the expression as an initializer.
4129 conditional-expression:
4130 logical-OR-expression
4131 logical-OR-expression ? expression : conditional-expression
4135 conditional-expression:
4136 logical-OR-expression ? : conditional-expression
4139 static struct c_expr
4140 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4142 struct c_expr cond
, exp1
, exp2
, ret
;
4143 gcc_assert (!after
|| c_dialect_objc ());
4144 cond
= c_parser_binary_expression (parser
, after
);
4145 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4147 c_parser_consume_token (parser
);
4148 if (c_parser_next_token_is (parser
, CPP_COLON
))
4151 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4152 /* Make sure first operand is calculated only once. */
4153 exp1
.value
= save_expr (default_conversion (cond
.value
));
4154 cond
.value
= lang_hooks
.truthvalue_conversion (exp1
.value
);
4155 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4160 = lang_hooks
.truthvalue_conversion (default_conversion (cond
.value
));
4161 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4162 exp1
= c_parser_expression (parser
);
4163 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4164 - (cond
.value
== truthvalue_false_node
));
4166 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4168 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4169 ret
.value
= error_mark_node
;
4170 ret
.original_code
= ERROR_MARK
;
4173 exp2
= c_parser_conditional_expression (parser
, NULL
);
4174 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4175 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4176 ret
.original_code
= ERROR_MARK
;
4180 /* Parse a binary expression; that is, a logical-OR-expression (C90
4181 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4182 an Objective-C message expression which is the primary-expression
4183 starting the expression as an initializer.
4185 multiplicative-expression:
4187 multiplicative-expression * cast-expression
4188 multiplicative-expression / cast-expression
4189 multiplicative-expression % cast-expression
4191 additive-expression:
4192 multiplicative-expression
4193 additive-expression + multiplicative-expression
4194 additive-expression - multiplicative-expression
4198 shift-expression << additive-expression
4199 shift-expression >> additive-expression
4201 relational-expression:
4203 relational-expression < shift-expression
4204 relational-expression > shift-expression
4205 relational-expression <= shift-expression
4206 relational-expression >= shift-expression
4208 equality-expression:
4209 relational-expression
4210 equality-expression == relational-expression
4211 equality-expression != relational-expression
4215 AND-expression & equality-expression
4217 exclusive-OR-expression:
4219 exclusive-OR-expression ^ AND-expression
4221 inclusive-OR-expression:
4222 exclusive-OR-expression
4223 inclusive-OR-expression | exclusive-OR-expression
4225 logical-AND-expression:
4226 inclusive-OR-expression
4227 logical-AND-expression && inclusive-OR-expression
4229 logical-OR-expression:
4230 logical-AND-expression
4231 logical-OR-expression || logical-AND-expression
4234 static struct c_expr
4235 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4237 /* A binary expression is parsed using operator-precedence parsing,
4238 with the operands being cast expressions. All the binary
4239 operators are left-associative. Thus a binary expression is of
4242 E0 op1 E1 op2 E2 ...
4244 which we represent on a stack. On the stack, the precedence
4245 levels are strictly increasing. When a new operator is
4246 encountered of higher precedence than that at the top of the
4247 stack, it is pushed; its LHS is the top expression, and its RHS
4248 is everything parsed until it is popped. When a new operator is
4249 encountered with precedence less than or equal to that at the top
4250 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4251 by the result of the operation until the operator at the top of
4252 the stack has lower precedence than the new operator or there is
4253 only one element on the stack; then the top expression is the LHS
4254 of the new operator. In the case of logical AND and OR
4255 expressions, we also need to adjust skip_evaluation as
4256 appropriate when the operators are pushed and popped. */
4258 /* The precedence levels, where 0 is a dummy lowest level used for
4259 the bottom of the stack. */
4275 /* The expression at this stack level. */
4277 /* The precedence of the operator on its left, PREC_NONE at the
4278 bottom of the stack. */
4280 /* The operation on its left. */
4286 switch (stack[sp].op) \
4288 case TRUTH_ANDIF_EXPR: \
4289 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4291 case TRUTH_ORIF_EXPR: \
4292 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4297 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4298 stack[sp - 1].expr, \
4302 gcc_assert (!after
|| c_dialect_objc ());
4303 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4304 stack
[0].prec
= PREC_NONE
;
4309 enum tree_code ocode
;
4312 switch (c_parser_peek_token (parser
)->type
)
4320 ocode
= TRUNC_DIV_EXPR
;
4324 ocode
= TRUNC_MOD_EXPR
;
4336 ocode
= LSHIFT_EXPR
;
4340 ocode
= RSHIFT_EXPR
;
4354 case CPP_GREATER_EQ
:
4367 oprec
= PREC_BITAND
;
4368 ocode
= BIT_AND_EXPR
;
4371 oprec
= PREC_BITXOR
;
4372 ocode
= BIT_XOR_EXPR
;
4376 ocode
= BIT_IOR_EXPR
;
4379 oprec
= PREC_LOGAND
;
4380 ocode
= TRUTH_ANDIF_EXPR
;
4384 ocode
= TRUTH_ORIF_EXPR
;
4387 /* Not a binary operator, so end of the binary
4391 c_parser_consume_token (parser
);
4392 while (oprec
<= stack
[sp
].prec
)
4396 case TRUTH_ANDIF_EXPR
:
4397 stack
[sp
].expr
.value
= lang_hooks
.truthvalue_conversion
4398 (default_conversion (stack
[sp
].expr
.value
));
4399 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4401 case TRUTH_ORIF_EXPR
:
4402 stack
[sp
].expr
.value
= lang_hooks
.truthvalue_conversion
4403 (default_conversion (stack
[sp
].expr
.value
));
4404 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4410 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4411 stack
[sp
].prec
= oprec
;
4412 stack
[sp
].op
= ocode
;
4417 return stack
[0].expr
;
4421 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4422 NULL then it is an Objective-C message expression which is the
4423 primary-expression starting the expression as an initializer.
4427 ( type-name ) unary-expression
4430 static struct c_expr
4431 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4433 gcc_assert (!after
|| c_dialect_objc ());
4435 return c_parser_postfix_expression_after_primary (parser
, *after
);
4436 /* If the expression begins with a parenthesized type name, it may
4437 be either a cast or a compound literal; we need to see whether
4438 the next character is '{' to tell the difference. If not, it is
4439 an unary expression. */
4440 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4441 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4443 struct c_type_name
*type_name
;
4446 c_parser_consume_token (parser
);
4447 type_name
= c_parser_type_name (parser
);
4448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4449 if (type_name
== NULL
)
4451 ret
.value
= error_mark_node
;
4452 ret
.original_code
= ERROR_MARK
;
4455 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4456 return c_parser_postfix_expression_after_paren_type (parser
,
4458 expr
= c_parser_cast_expression (parser
, NULL
).value
;
4459 ret
.value
= c_cast_expr (type_name
, expr
);
4460 ret
.original_code
= ERROR_MARK
;
4464 return c_parser_unary_expression (parser
);
4467 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4473 unary-operator cast-expression
4474 sizeof unary-expression
4475 sizeof ( type-name )
4477 unary-operator: one of
4483 __alignof__ unary-expression
4484 __alignof__ ( type-name )
4487 unary-operator: one of
4488 __extension__ __real__ __imag__
4490 In addition, the GNU syntax treats ++ and -- as unary operators, so
4491 they may be applied to cast expressions with errors for non-lvalues
4494 static struct c_expr
4495 c_parser_unary_expression (c_parser
*parser
)
4499 ret
.original_code
= ERROR_MARK
;
4500 switch (c_parser_peek_token (parser
)->type
)
4503 c_parser_consume_token (parser
);
4505 = build_unary_op (PREINCREMENT_EXPR
,
4506 c_parser_cast_expression (parser
, NULL
).value
, 0);
4507 overflow_warning (ret
.value
);
4509 case CPP_MINUS_MINUS
:
4510 c_parser_consume_token (parser
);
4512 = build_unary_op (PREDECREMENT_EXPR
,
4513 c_parser_cast_expression (parser
, NULL
).value
, 0);
4514 overflow_warning (ret
.value
);
4517 c_parser_consume_token (parser
);
4519 = build_unary_op (ADDR_EXPR
,
4520 c_parser_cast_expression (parser
, NULL
).value
, 0);
4521 overflow_warning (ret
.value
);
4524 c_parser_consume_token (parser
);
4526 = build_indirect_ref (c_parser_cast_expression (parser
, NULL
).value
,
4530 c_parser_consume_token (parser
);
4531 if (!c_dialect_objc () && warn_traditional
&& !in_system_header
)
4532 warning ("traditional C rejects the unary plus operator");
4534 = build_unary_op (CONVERT_EXPR
,
4535 c_parser_cast_expression (parser
, NULL
).value
, 0);
4536 overflow_warning (ret
.value
);
4539 c_parser_consume_token (parser
);
4541 = build_unary_op (NEGATE_EXPR
,
4542 c_parser_cast_expression (parser
, NULL
).value
, 0);
4543 overflow_warning (ret
.value
);
4546 c_parser_consume_token (parser
);
4548 = build_unary_op (BIT_NOT_EXPR
,
4549 c_parser_cast_expression (parser
, NULL
).value
, 0);
4550 overflow_warning (ret
.value
);
4553 c_parser_consume_token (parser
);
4555 = build_unary_op (TRUTH_NOT_EXPR
,
4556 c_parser_cast_expression (parser
, NULL
).value
, 0);
4557 overflow_warning (ret
.value
);
4560 /* Refer to the address of a label as a pointer. */
4561 c_parser_consume_token (parser
);
4562 if (c_parser_next_token_is (parser
, CPP_NAME
))
4564 ret
.value
= finish_label_address_expr
4565 (c_parser_peek_token (parser
)->value
);
4566 c_parser_consume_token (parser
);
4571 c_parser_error (parser
, "expected identifier");
4572 ret
.value
= error_mark_node
;
4576 switch (c_parser_peek_token (parser
)->keyword
)
4579 return c_parser_sizeof_expression (parser
);
4581 return c_parser_alignof_expression (parser
);
4583 c_parser_consume_token (parser
);
4584 ext
= disable_extension_diagnostics ();
4585 ret
= c_parser_cast_expression (parser
, NULL
);
4586 restore_extension_diagnostics (ext
);
4589 c_parser_consume_token (parser
);
4591 = build_unary_op (REALPART_EXPR
,
4592 c_parser_cast_expression (parser
, NULL
).value
,
4596 c_parser_consume_token (parser
);
4598 = build_unary_op (IMAGPART_EXPR
,
4599 c_parser_cast_expression (parser
, NULL
).value
,
4603 return c_parser_postfix_expression (parser
);
4606 return c_parser_postfix_expression (parser
);
4610 /* Parse a sizeof expression. */
4612 static struct c_expr
4613 c_parser_sizeof_expression (c_parser
*parser
)
4616 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4617 c_parser_consume_token (parser
);
4620 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4621 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4623 /* Either sizeof ( type-name ) or sizeof unary-expression
4624 starting with a compound literal. */
4625 struct c_type_name
*type_name
;
4626 c_parser_consume_token (parser
);
4627 type_name
= c_parser_type_name (parser
);
4628 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4629 if (type_name
== NULL
)
4634 ret
.value
= error_mark_node
;
4635 ret
.original_code
= ERROR_MARK
;
4638 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4640 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4644 /* sizeof ( type-name ). */
4647 return c_expr_sizeof_type (type_name
);
4651 expr
= c_parser_unary_expression (parser
);
4655 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4656 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4657 error ("%<sizeof%> applied to a bit-field");
4658 return c_expr_sizeof_expr (expr
);
4662 /* Parse an alignof expression. */
4664 static struct c_expr
4665 c_parser_alignof_expression (c_parser
*parser
)
4668 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4669 c_parser_consume_token (parser
);
4672 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4673 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4675 /* Either __alignof__ ( type-name ) or __alignof__
4676 unary-expression starting with a compound literal. */
4677 struct c_type_name
*type_name
;
4679 c_parser_consume_token (parser
);
4680 type_name
= c_parser_type_name (parser
);
4681 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4682 if (type_name
== NULL
)
4687 ret
.value
= error_mark_node
;
4688 ret
.original_code
= ERROR_MARK
;
4691 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4693 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4697 /* alignof ( type-name ). */
4700 ret
.value
= c_alignof (groktypename (type_name
));
4701 ret
.original_code
= ERROR_MARK
;
4707 expr
= c_parser_unary_expression (parser
);
4711 ret
.value
= c_alignof_expr (expr
.value
);
4712 ret
.original_code
= ERROR_MARK
;
4717 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4721 postfix-expression [ expression ]
4722 postfix-expression ( argument-expression-list[opt] )
4723 postfix-expression . identifier
4724 postfix-expression -> identifier
4725 postfix-expression ++
4726 postfix-expression --
4727 ( type-name ) { initializer-list }
4728 ( type-name ) { initializer-list , }
4730 argument-expression-list:
4732 argument-expression-list , argument-expression
4744 (treated as a keyword in GNU C)
4747 ( compound-statement )
4748 __builtin_va_arg ( assignment-expression , type-name )
4749 __builtin_offsetof ( type-name , offsetof-member-designator )
4750 __builtin_choose_expr ( assignment-expression ,
4751 assignment-expression ,
4752 assignment-expression )
4753 __builtin_types_compatible_p ( type-name , type-name )
4755 offsetof-member-designator:
4757 offsetof-member-designator . identifier
4758 offsetof-member-designator [ expression ]
4763 [ objc-receiver objc-message-args ]
4764 @selector ( objc-selector-arg )
4765 @protocol ( identifier )
4766 @encode ( type-name )
4770 static struct c_expr
4771 c_parser_postfix_expression (c_parser
*parser
)
4773 struct c_expr expr
, e1
, e2
, e3
;
4774 struct c_type_name
*t1
, *t2
;
4775 switch (c_parser_peek_token (parser
)->type
)
4780 expr
.value
= c_parser_peek_token (parser
)->value
;
4781 expr
.original_code
= ERROR_MARK
;
4782 c_parser_consume_token (parser
);
4786 expr
.value
= c_parser_peek_token (parser
)->value
;
4787 expr
.original_code
= STRING_CST
;
4788 c_parser_consume_token (parser
);
4790 case CPP_OBJC_STRING
:
4791 gcc_assert (c_dialect_objc ());
4793 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
4794 expr
.original_code
= ERROR_MARK
;
4795 c_parser_consume_token (parser
);
4798 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
4800 c_parser_error (parser
, "expected expression");
4801 expr
.value
= error_mark_node
;
4802 expr
.original_code
= ERROR_MARK
;
4806 tree id
= c_parser_peek_token (parser
)->value
;
4807 location_t loc
= c_parser_peek_token (parser
)->location
;
4808 c_parser_consume_token (parser
);
4809 expr
.value
= build_external_ref (id
,
4810 (c_parser_peek_token (parser
)->type
4811 == CPP_OPEN_PAREN
), loc
);
4812 expr
.original_code
= ERROR_MARK
;
4815 case CPP_OPEN_PAREN
:
4816 /* A parenthesized expression, statement expression or compound
4818 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
4820 /* A statement expression. */
4822 c_parser_consume_token (parser
);
4823 c_parser_consume_token (parser
);
4824 if (cur_stmt_list
== NULL
)
4826 error ("braced-group within expression allowed "
4827 "only inside a function");
4828 parser
->error
= true;
4829 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
4830 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4831 expr
.value
= error_mark_node
;
4832 expr
.original_code
= ERROR_MARK
;
4835 stmt
= c_begin_stmt_expr ();
4836 c_parser_compound_statement_nostart (parser
);
4837 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4840 pedwarn ("ISO C forbids braced-groups within expressions");
4841 expr
.value
= c_finish_stmt_expr (stmt
);
4842 expr
.original_code
= ERROR_MARK
;
4844 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4846 /* A compound literal. ??? Can we actually get here rather
4847 than going directly to
4848 c_parser_postfix_expression_after_paren_type from
4850 struct c_type_name
*type_name
;
4851 c_parser_consume_token (parser
);
4852 type_name
= c_parser_type_name (parser
);
4853 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4855 if (type_name
== NULL
)
4857 expr
.value
= error_mark_node
;
4858 expr
.original_code
= ERROR_MARK
;
4861 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4866 /* A parenthesized expression. */
4867 c_parser_consume_token (parser
);
4868 expr
= c_parser_expression (parser
);
4869 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
4870 TREE_NO_WARNING (expr
.value
) = 1;
4871 expr
.original_code
= ERROR_MARK
;
4872 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4877 switch (c_parser_peek_token (parser
)->keyword
)
4879 case RID_FUNCTION_NAME
:
4880 case RID_PRETTY_FUNCTION_NAME
:
4881 case RID_C99_FUNCTION_NAME
:
4882 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
4883 c_parser_peek_token (parser
)->value
);
4884 expr
.original_code
= ERROR_MARK
;
4885 c_parser_consume_token (parser
);
4888 c_parser_consume_token (parser
);
4889 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4891 expr
.value
= error_mark_node
;
4892 expr
.original_code
= ERROR_MARK
;
4895 e1
= c_parser_expr_no_commas (parser
, NULL
);
4896 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4898 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4899 expr
.value
= error_mark_node
;
4900 expr
.original_code
= ERROR_MARK
;
4903 t1
= c_parser_type_name (parser
);
4904 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4908 expr
.value
= error_mark_node
;
4909 expr
.original_code
= ERROR_MARK
;
4913 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
4914 expr
.original_code
= ERROR_MARK
;
4918 c_parser_consume_token (parser
);
4919 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4921 expr
.value
= error_mark_node
;
4922 expr
.original_code
= ERROR_MARK
;
4925 t1
= c_parser_type_name (parser
);
4928 expr
.value
= error_mark_node
;
4929 expr
.original_code
= ERROR_MARK
;
4932 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4935 expr
.value
= error_mark_node
;
4936 expr
.original_code
= ERROR_MARK
;
4940 tree type
= groktypename (t1
);
4942 if (type
== error_mark_node
)
4943 offsetof_ref
= error_mark_node
;
4945 offsetof_ref
= build1 (INDIRECT_REF
, type
, NULL
);
4946 /* Parse the second argument to __builtin_offsetof. We
4947 must have one identifier, and beyond that we want to
4948 accept sub structure and sub array references. */
4949 if (c_parser_next_token_is (parser
, CPP_NAME
))
4951 offsetof_ref
= build_component_ref
4952 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
4953 c_parser_consume_token (parser
);
4954 while (c_parser_next_token_is (parser
, CPP_DOT
)
4955 || c_parser_next_token_is (parser
,
4958 if (c_parser_next_token_is (parser
, CPP_DOT
))
4960 c_parser_consume_token (parser
);
4961 if (c_parser_next_token_is_not (parser
,
4964 c_parser_error (parser
, "expected identifier");
4967 offsetof_ref
= build_component_ref
4969 c_parser_peek_token (parser
)->value
);
4970 c_parser_consume_token (parser
);
4975 c_parser_consume_token (parser
);
4976 idx
= c_parser_expression (parser
).value
;
4977 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4979 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
4984 c_parser_error (parser
, "expected identifier");
4985 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4987 expr
.value
= fold_offsetof (offsetof_ref
);
4988 expr
.original_code
= ERROR_MARK
;
4991 case RID_CHOOSE_EXPR
:
4992 c_parser_consume_token (parser
);
4993 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4995 expr
.value
= error_mark_node
;
4996 expr
.original_code
= ERROR_MARK
;
4999 e1
= c_parser_expr_no_commas (parser
, NULL
);
5000 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5002 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5003 expr
.value
= error_mark_node
;
5004 expr
.original_code
= ERROR_MARK
;
5007 e2
= c_parser_expr_no_commas (parser
, NULL
);
5008 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5010 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5011 expr
.value
= error_mark_node
;
5012 expr
.original_code
= ERROR_MARK
;
5015 e3
= c_parser_expr_no_commas (parser
, NULL
);
5016 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5021 c
= fold (e1
.value
);
5023 if (TREE_CODE (c
) != INTEGER_CST
)
5024 error ("first argument to %<__builtin_choose_expr%> not"
5026 expr
= integer_zerop (c
) ? e3
: e2
;
5029 case RID_TYPES_COMPATIBLE_P
:
5030 c_parser_consume_token (parser
);
5031 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5033 expr
.value
= error_mark_node
;
5034 expr
.original_code
= ERROR_MARK
;
5037 t1
= c_parser_type_name (parser
);
5040 expr
.value
= error_mark_node
;
5041 expr
.original_code
= ERROR_MARK
;
5044 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5046 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5047 expr
.value
= error_mark_node
;
5048 expr
.original_code
= ERROR_MARK
;
5051 t2
= c_parser_type_name (parser
);
5054 expr
.value
= error_mark_node
;
5055 expr
.original_code
= ERROR_MARK
;
5058 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5063 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5064 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5066 expr
.value
= comptypes (e1
, e2
)
5067 ? build_int_cst (NULL_TREE
, 1)
5068 : build_int_cst (NULL_TREE
, 0);
5069 expr
.original_code
= ERROR_MARK
;
5072 case RID_AT_SELECTOR
:
5073 gcc_assert (c_dialect_objc ());
5074 c_parser_consume_token (parser
);
5075 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5077 expr
.value
= error_mark_node
;
5078 expr
.original_code
= ERROR_MARK
;
5082 tree sel
= c_parser_objc_selector_arg (parser
);
5083 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5085 expr
.value
= objc_build_selector_expr (sel
);
5086 expr
.original_code
= ERROR_MARK
;
5089 case RID_AT_PROTOCOL
:
5090 gcc_assert (c_dialect_objc ());
5091 c_parser_consume_token (parser
);
5092 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5094 expr
.value
= error_mark_node
;
5095 expr
.original_code
= ERROR_MARK
;
5098 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5100 c_parser_error (parser
, "expected identifier");
5101 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5102 expr
.value
= error_mark_node
;
5103 expr
.original_code
= ERROR_MARK
;
5107 tree id
= c_parser_peek_token (parser
)->value
;
5108 c_parser_consume_token (parser
);
5109 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5111 expr
.value
= objc_build_protocol_expr (id
);
5112 expr
.original_code
= ERROR_MARK
;
5116 /* Extension to support C-structures in the archiver. */
5117 gcc_assert (c_dialect_objc ());
5118 c_parser_consume_token (parser
);
5119 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5121 expr
.value
= error_mark_node
;
5122 expr
.original_code
= ERROR_MARK
;
5125 t1
= c_parser_type_name (parser
);
5128 expr
.value
= error_mark_node
;
5129 expr
.original_code
= ERROR_MARK
;
5130 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5133 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5136 tree type
= groktypename (t1
);
5137 expr
.value
= objc_build_encode_expr (type
);
5138 expr
.original_code
= ERROR_MARK
;
5142 c_parser_error (parser
, "expected expression");
5143 expr
.value
= error_mark_node
;
5144 expr
.original_code
= ERROR_MARK
;
5148 case CPP_OPEN_SQUARE
:
5149 if (c_dialect_objc ())
5151 tree receiver
, args
;
5152 c_parser_consume_token (parser
);
5153 receiver
= c_parser_objc_receiver (parser
);
5154 args
= c_parser_objc_message_args (parser
);
5155 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5157 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5159 expr
.original_code
= ERROR_MARK
;
5162 /* Else fall through to report error. */
5164 c_parser_error (parser
, "expected expression");
5165 expr
.value
= error_mark_node
;
5166 expr
.original_code
= ERROR_MARK
;
5169 return c_parser_postfix_expression_after_primary (parser
, expr
);
5172 /* Parse a postfix expression after a parenthesized type name: the
5173 brace-enclosed initializer of a compound literal, possibly followed
5174 by some postfix operators. This is separate because it is not
5175 possible to tell until after the type name whether a cast
5176 expression has a cast or a compound literal, or whether the operand
5177 of sizeof is a parenthesized type name or starts with a compound
5180 static struct c_expr
5181 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5182 struct c_type_name
*type_name
)
5187 start_init (NULL_TREE
, NULL
, 0);
5188 type
= groktypename (type_name
);
5189 if (C_TYPE_VARIABLE_SIZE (type
))
5191 error ("compound literal has variable size");
5192 type
= error_mark_node
;
5194 init
= c_parser_braced_init (parser
, type
, false);
5196 maybe_warn_string_init (type
, init
);
5198 if (pedantic
&& !flag_isoc99
)
5199 pedwarn ("ISO C90 forbids compound literals");
5200 expr
.value
= build_compound_literal (type
, init
.value
);
5201 expr
.original_code
= ERROR_MARK
;
5202 return c_parser_postfix_expression_after_primary (parser
, expr
);
5205 /* Parse a postfix expression after the initial primary or compound
5206 literal; that is, parse a series of postfix operators. */
5208 static struct c_expr
5209 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5212 tree ident
, idx
, exprlist
;
5215 switch (c_parser_peek_token (parser
)->type
)
5217 case CPP_OPEN_SQUARE
:
5218 /* Array reference. */
5219 c_parser_consume_token (parser
);
5220 idx
= c_parser_expression (parser
).value
;
5221 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5223 expr
.value
= build_array_ref (expr
.value
, idx
);
5224 expr
.original_code
= ERROR_MARK
;
5226 case CPP_OPEN_PAREN
:
5227 /* Function call. */
5228 c_parser_consume_token (parser
);
5229 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5230 exprlist
= NULL_TREE
;
5232 exprlist
= c_parser_expr_list (parser
);
5233 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5235 expr
.value
= build_function_call (expr
.value
, exprlist
);
5236 expr
.original_code
= ERROR_MARK
;
5239 /* Structure element reference. */
5240 c_parser_consume_token (parser
);
5241 if (c_parser_next_token_is (parser
, CPP_NAME
))
5242 ident
= c_parser_peek_token (parser
)->value
;
5245 c_parser_error (parser
, "expected identifier");
5246 expr
.value
= error_mark_node
;
5247 expr
.original_code
= ERROR_MARK
;
5250 c_parser_consume_token (parser
);
5251 expr
.value
= build_component_ref (expr
.value
, ident
);
5252 expr
.original_code
= ERROR_MARK
;
5255 /* Structure element reference. */
5256 c_parser_consume_token (parser
);
5257 if (c_parser_next_token_is (parser
, CPP_NAME
))
5258 ident
= c_parser_peek_token (parser
)->value
;
5261 c_parser_error (parser
, "expected identifier");
5262 expr
.value
= error_mark_node
;
5263 expr
.original_code
= ERROR_MARK
;
5266 c_parser_consume_token (parser
);
5267 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5269 expr
.original_code
= ERROR_MARK
;
5272 /* Postincrement. */
5273 c_parser_consume_token (parser
);
5274 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5275 expr
.original_code
= ERROR_MARK
;
5277 case CPP_MINUS_MINUS
:
5278 /* Postdecrement. */
5279 c_parser_consume_token (parser
);
5280 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5281 expr
.original_code
= ERROR_MARK
;
5289 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5292 assignment-expression
5293 expression , assignment-expression
5296 static struct c_expr
5297 c_parser_expression (c_parser
*parser
)
5300 expr
= c_parser_expr_no_commas (parser
, NULL
);
5301 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5304 c_parser_consume_token (parser
);
5305 next
= c_parser_expr_no_commas (parser
, NULL
);
5306 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5307 expr
.original_code
= COMPOUND_EXPR
;
5312 /* Parse a non-empty list of expressions.
5315 assignment-expression
5316 nonempty-expr-list , assignment-expression
5320 c_parser_expr_list (c_parser
*parser
)
5324 expr
= c_parser_expr_no_commas (parser
, NULL
);
5325 ret
= build_tree_list (NULL_TREE
, expr
.value
);
5326 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5328 c_parser_consume_token (parser
);
5329 expr
= c_parser_expr_no_commas (parser
, NULL
);
5330 ret
= chainon (ret
, build_tree_list (NULL_TREE
, expr
.value
));
5336 /* Parse Objective-C-specific constructs. */
5338 /* Parse an objc-class-definition.
5340 objc-class-definition:
5341 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5342 objc-class-instance-variables[opt] objc-methodprotolist @end
5343 @implementation identifier objc-superclass[opt]
5344 objc-class-instance-variables[opt]
5345 @interface identifier ( identifier ) objc-protocol-refs[opt]
5346 objc-methodprotolist @end
5347 @implementation identifier ( identifier )
5352 "@interface identifier (" must start "@interface identifier (
5353 identifier ) ...": objc-methodprotolist in the first production may
5354 not start with a parenthesised identifier as a declarator of a data
5355 definition with no declaration specifiers if the objc-superclass,
5356 objc-protocol-refs and objc-class-instance-variables are omitted. */
5359 c_parser_objc_class_definition (c_parser
*parser
)
5364 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5366 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5370 c_parser_consume_token (parser
);
5371 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5373 c_parser_error (parser
, "expected identifier");
5376 id1
= c_parser_peek_token (parser
)->value
;
5377 c_parser_consume_token (parser
);
5378 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5381 tree proto
= NULL_TREE
;
5382 c_parser_consume_token (parser
);
5383 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5385 c_parser_error (parser
, "expected identifier");
5386 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5389 id2
= c_parser_peek_token (parser
)->value
;
5390 c_parser_consume_token (parser
);
5391 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5394 objc_start_category_implementation (id1
, id2
);
5397 if (c_parser_next_token_is (parser
, CPP_LESS
))
5398 proto
= c_parser_objc_protocol_refs (parser
);
5399 objc_start_category_interface (id1
, id2
, proto
);
5400 c_parser_objc_methodprotolist (parser
);
5401 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5402 objc_finish_interface ();
5405 if (c_parser_next_token_is (parser
, CPP_COLON
))
5407 c_parser_consume_token (parser
);
5408 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5410 c_parser_error (parser
, "expected identifier");
5413 superclass
= c_parser_peek_token (parser
)->value
;
5414 c_parser_consume_token (parser
);
5417 superclass
= NULL_TREE
;
5420 tree proto
= NULL_TREE
;
5421 if (c_parser_next_token_is (parser
, CPP_LESS
))
5422 proto
= c_parser_objc_protocol_refs (parser
);
5423 objc_start_class_interface (id1
, superclass
, proto
);
5426 objc_start_class_implementation (id1
, superclass
);
5427 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5428 c_parser_objc_class_instance_variables (parser
);
5431 objc_continue_interface ();
5432 c_parser_objc_methodprotolist (parser
);
5433 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5434 objc_finish_interface ();
5438 objc_continue_implementation ();
5443 /* Parse objc-class-instance-variables.
5445 objc-class-instance-variables:
5446 { objc-instance-variable-decl-list[opt] }
5448 objc-instance-variable-decl-list:
5449 objc-visibility-spec
5450 objc-instance-variable-decl ;
5452 objc-instance-variable-decl-list objc-visibility-spec
5453 objc-instance-variable-decl-list objc-instance-variable-decl ;
5454 objc-instance-variable-decl-list ;
5456 objc-visibility-spec:
5461 objc-instance-variable-decl:
5466 c_parser_objc_class_instance_variables (c_parser
*parser
)
5468 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5469 c_parser_consume_token (parser
);
5470 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5473 /* Parse any stray semicolon. */
5474 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5477 pedwarn ("extra semicolon in struct or union specified");
5478 c_parser_consume_token (parser
);
5481 /* Stop if at the end of the instance variables. */
5482 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5484 c_parser_consume_token (parser
);
5487 /* Parse any objc-visibility-spec. */
5488 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5490 c_parser_consume_token (parser
);
5491 objc_set_visibility (2);
5494 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5496 c_parser_consume_token (parser
);
5497 objc_set_visibility (0);
5500 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5502 c_parser_consume_token (parser
);
5503 objc_set_visibility (1);
5506 /* Parse some comma-separated declarations. */
5507 decls
= c_parser_struct_declaration (parser
);
5509 /* Comma-separated instance variables are chained together in
5510 reverse order; add them one by one. */
5511 tree ivar
= nreverse (decls
);
5512 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5513 objc_add_instance_variable (copy_node (ivar
));
5515 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5519 /* Parse an objc-class-declaration.
5521 objc-class-declaration:
5522 @class identifier-list ;
5526 c_parser_objc_class_declaration (c_parser
*parser
)
5528 tree list
= NULL_TREE
;
5529 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5530 c_parser_consume_token (parser
);
5531 /* Any identifiers, including those declared as type names, are OK
5536 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5538 c_parser_error (parser
, "expected identifier");
5541 id
= c_parser_peek_token (parser
)->value
;
5542 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5543 c_parser_consume_token (parser
);
5544 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5545 c_parser_consume_token (parser
);
5549 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5550 objc_declare_class (list
);
5553 /* Parse an objc-alias-declaration.
5555 objc-alias-declaration:
5556 @compatibility_alias identifier identifier ;
5560 c_parser_objc_alias_declaration (c_parser
*parser
)
5563 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5564 c_parser_consume_token (parser
);
5565 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5567 c_parser_error (parser
, "expected identifier");
5568 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5571 id1
= c_parser_peek_token (parser
)->value
;
5572 c_parser_consume_token (parser
);
5573 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5575 c_parser_error (parser
, "expected identifier");
5576 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5579 id2
= c_parser_peek_token (parser
)->value
;
5580 c_parser_consume_token (parser
);
5581 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5582 objc_declare_alias (id1
, id2
);
5585 /* Parse an objc-protocol-definition.
5587 objc-protocol-definition:
5588 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5589 @protocol identifier-list ;
5591 "@protocol identifier ;" should be resolved as "@protocol
5592 identifier-list ;": objc-methodprotolist may not start with a
5593 semicolon in the first alternative if objc-protocol-refs are
5597 c_parser_objc_protocol_definition (c_parser
*parser
)
5599 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5600 c_parser_consume_token (parser
);
5601 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5603 c_parser_error (parser
, "expected identifier");
5606 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5607 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5609 tree list
= NULL_TREE
;
5610 /* Any identifiers, including those declared as type names, are
5615 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5617 c_parser_error (parser
, "expected identifier");
5620 id
= c_parser_peek_token (parser
)->value
;
5621 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5622 c_parser_consume_token (parser
);
5623 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5624 c_parser_consume_token (parser
);
5628 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5629 objc_declare_protocols (list
);
5633 tree id
= c_parser_peek_token (parser
)->value
;
5634 tree proto
= NULL_TREE
;
5635 c_parser_consume_token (parser
);
5636 if (c_parser_next_token_is (parser
, CPP_LESS
))
5637 proto
= c_parser_objc_protocol_refs (parser
);
5638 objc_pq_context
= 1;
5639 objc_start_protocol (id
, proto
);
5640 c_parser_objc_methodprotolist (parser
);
5641 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5642 objc_pq_context
= 0;
5643 objc_finish_interface ();
5647 /* Parse an objc-method-type.
5654 static enum tree_code
5655 c_parser_objc_method_type (c_parser
*parser
)
5657 switch (c_parser_peek_token (parser
)->type
)
5660 c_parser_consume_token (parser
);
5663 c_parser_consume_token (parser
);
5670 /* Parse an objc-method-definition.
5672 objc-method-definition:
5673 objc-method-type objc-method-decl ;[opt] compound-statement
5677 c_parser_objc_method_definition (c_parser
*parser
)
5679 enum tree_code type
= c_parser_objc_method_type (parser
);
5681 objc_set_method_type (type
);
5682 objc_pq_context
= 1;
5683 decl
= c_parser_objc_method_decl (parser
);
5684 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5686 c_parser_consume_token (parser
);
5688 pedwarn ("extra semicolon in method definition specified");
5690 objc_pq_context
= 0;
5691 objc_start_method_definition (decl
);
5692 add_stmt (c_parser_compound_statement (parser
));
5693 objc_finish_method_definition (current_function_decl
);
5696 /* Parse an objc-methodprotolist.
5698 objc-methodprotolist:
5700 objc-methodprotolist objc-methodproto
5701 objc-methodprotolist declaration
5702 objc-methodprotolist ;
5704 The declaration is a data definition, which may be missing
5705 declaration specifiers under the same rules and diagnostics as
5706 other data definitions outside functions, and the stray semicolon
5707 is diagnosed the same way as a stray semicolon outside a
5711 c_parser_objc_methodprotolist (c_parser
*parser
)
5715 /* The list is terminated by @end. */
5716 switch (c_parser_peek_token (parser
)->type
)
5720 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5721 c_parser_consume_token (parser
);
5725 c_parser_objc_methodproto (parser
);
5730 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
5732 c_parser_declaration_or_fndef (parser
, false, true, false, true);
5738 /* Parse an objc-methodproto.
5741 objc-method-type objc-method-decl ;
5745 c_parser_objc_methodproto (c_parser
*parser
)
5747 enum tree_code type
= c_parser_objc_method_type (parser
);
5749 objc_set_method_type (type
);
5750 /* Remember protocol qualifiers in prototypes. */
5751 objc_pq_context
= 1;
5752 decl
= c_parser_objc_method_decl (parser
);
5753 /* Forget protocol qualifiers here. */
5754 objc_pq_context
= 0;
5755 objc_add_method_declaration (decl
);
5756 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5759 /* Parse an objc-method-decl.
5762 ( objc-type-name ) objc-selector
5764 ( objc-type-name ) objc-keyword-selector objc-optparmlist
5765 objc-keyword-selector objc-optparmlist
5767 objc-keyword-selector:
5769 objc-keyword-selector objc-keyword-decl
5772 objc-selector : ( objc-type-name ) identifier
5773 objc-selector : identifier
5774 : ( objc-type-name ) identifier
5778 objc-optparms objc-optellipsis
5782 objc-opt-parms , parameter-declaration
5790 c_parser_objc_method_decl (c_parser
*parser
)
5792 tree type
= NULL_TREE
;
5794 tree parms
= NULL_TREE
;
5795 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5797 c_parser_consume_token (parser
);
5798 type
= c_parser_objc_type_name (parser
);
5799 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5801 sel
= c_parser_objc_selector (parser
);
5802 /* If there is no selector, or a colon follows, we have an
5803 objc-keyword-selector. If there is a selector, and a colon does
5804 not follow, that selector ends the objc-method-decl. */
5805 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
5808 tree list
= NULL_TREE
;
5812 tree atype
= NULL_TREE
, id
, keyworddecl
;
5813 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5815 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5817 c_parser_consume_token (parser
);
5818 atype
= c_parser_objc_type_name (parser
);
5819 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5822 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5824 c_parser_error (parser
, "expected identifier");
5825 return error_mark_node
;
5827 id
= c_parser_peek_token (parser
)->value
;
5828 c_parser_consume_token (parser
);
5829 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
5830 list
= chainon (list
, keyworddecl
);
5831 tsel
= c_parser_objc_selector (parser
);
5832 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
5835 /* Parse the optional parameter list. Optional Objective-C
5836 method parameters follow the C syntax, and may include '...'
5837 to denote a variable number of arguments. */
5838 parms
= make_node (TREE_LIST
);
5840 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5842 struct c_parm
*parm
;
5843 c_parser_consume_token (parser
);
5844 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5847 c_parser_consume_token (parser
);
5850 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5853 parms
= chainon (parms
,
5854 build_tree_list (NULL_TREE
, grokparm (parm
)));
5856 TREE_OVERFLOW (parms
) = ellipsis
;
5859 return objc_build_method_signature (type
, sel
, parms
);
5862 /* Parse an objc-type-name.
5865 objc-type-qualifiers[opt] type-name
5866 objc-type-qualifiers[opt]
5868 objc-type-qualifiers:
5870 objc-type-qualifiers objc-type-qualifier
5872 objc-type-qualifier: one of
5873 in out inout bycopy byref oneway
5877 c_parser_objc_type_name (c_parser
*parser
)
5879 tree quals
= NULL_TREE
;
5880 struct c_type_name
*typename
= NULL
;
5881 tree type
= NULL_TREE
;
5884 c_token
*token
= c_parser_peek_token (parser
);
5885 if (token
->type
== CPP_KEYWORD
5886 && (token
->keyword
== RID_IN
5887 || token
->keyword
== RID_OUT
5888 || token
->keyword
== RID_INOUT
5889 || token
->keyword
== RID_BYCOPY
5890 || token
->keyword
== RID_BYREF
5891 || token
->keyword
== RID_ONEWAY
))
5893 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
5894 c_parser_consume_token (parser
);
5899 if (c_parser_next_token_starts_typename (parser
))
5900 typename
= c_parser_type_name (parser
);
5902 type
= groktypename (typename
);
5903 return build_tree_list (quals
, type
);
5906 /* Parse objc-protocol-refs.
5913 c_parser_objc_protocol_refs (c_parser
*parser
)
5915 tree list
= NULL_TREE
;
5916 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
5917 c_parser_consume_token (parser
);
5918 /* Any identifiers, including those declared as type names, are OK
5923 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5925 c_parser_error (parser
, "expected identifier");
5928 id
= c_parser_peek_token (parser
)->value
;
5929 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5930 c_parser_consume_token (parser
);
5931 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5932 c_parser_consume_token (parser
);
5936 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
5940 /* Parse an objc-try-catch-statement.
5942 objc-try-catch-statement:
5943 @try compound-statement objc-catch-list[opt]
5944 @try compound-statement objc-catch-list[opt] @finally compound-statement
5947 @catch ( parameter-declaration ) compound-statement
5948 objc-catch-list @catch ( parameter-declaration ) compound-statement
5952 c_parser_objc_try_catch_statement (c_parser
*parser
)
5956 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
5957 c_parser_consume_token (parser
);
5958 loc
= c_parser_peek_token (parser
)->location
;
5959 stmt
= c_parser_compound_statement (parser
);
5960 objc_begin_try_stmt (loc
, stmt
);
5961 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
5963 struct c_parm
*parm
;
5964 c_parser_consume_token (parser
);
5965 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5967 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5970 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5973 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5974 objc_begin_catch_clause (grokparm (parm
));
5975 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
5976 c_parser_compound_statement_nostart (parser
);
5977 objc_finish_catch_clause ();
5979 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
5983 c_parser_consume_token (parser
);
5984 finloc
= c_parser_peek_token (parser
)->location
;
5985 finstmt
= c_parser_compound_statement (parser
);
5986 objc_build_finally_clause (finloc
, finstmt
);
5988 objc_finish_try_stmt ();
5991 /* Parse an objc-synchronized-statement.
5993 objc-synchronized-statement:
5994 @synchronized ( expression ) compound-statement
5998 c_parser_objc_synchronized_statement (c_parser
*parser
)
6002 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6003 c_parser_consume_token (parser
);
6004 loc
= c_parser_peek_token (parser
)->location
;
6005 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6007 expr
= c_parser_expression (parser
).value
;
6008 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6011 expr
= error_mark_node
;
6012 stmt
= c_parser_compound_statement (parser
);
6013 objc_build_synchronized (loc
, expr
, stmt
);
6016 /* Parse an objc-selector; return NULL_TREE without an error if the
6017 next token is not an objc-selector.
6022 enum struct union if else while do for switch case default
6023 break continue return goto asm sizeof typeof __alignof
6024 unsigned long const short volatile signed restrict _Complex
6025 in out inout bycopy byref oneway int char float double void _Bool
6027 ??? Why this selection of keywords but not, for example, storage
6028 class specifiers? */
6031 c_parser_objc_selector (c_parser
*parser
)
6033 c_token
*token
= c_parser_peek_token (parser
);
6034 tree value
= token
->value
;
6035 if (token
->type
== CPP_NAME
)
6037 c_parser_consume_token (parser
);
6040 if (token
->type
!= CPP_KEYWORD
)
6042 switch (token
->keyword
)
6083 c_parser_consume_token (parser
);
6090 /* Parse an objc-selector-arg.
6094 objc-keywordname-list
6096 objc-keywordname-list:
6098 objc-keywordname-list objc-keywordname
6106 c_parser_objc_selector_arg (c_parser
*parser
)
6108 tree sel
= c_parser_objc_selector (parser
);
6109 tree list
= NULL_TREE
;
6110 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6114 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6116 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6117 sel
= c_parser_objc_selector (parser
);
6118 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6124 /* Parse an objc-receiver.
6133 c_parser_objc_receiver (c_parser
*parser
)
6135 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6136 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6137 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6139 tree id
= c_parser_peek_token (parser
)->value
;
6140 c_parser_consume_token (parser
);
6141 return objc_get_class_reference (id
);
6143 return c_parser_expression (parser
).value
;
6146 /* Parse objc-message-args.
6150 objc-keywordarg-list
6152 objc-keywordarg-list:
6154 objc-keywordarg-list objc-keywordarg
6157 objc-selector : objc-keywordexpr
6162 c_parser_objc_message_args (c_parser
*parser
)
6164 tree sel
= c_parser_objc_selector (parser
);
6165 tree list
= NULL_TREE
;
6166 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6171 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6173 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6174 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6175 sel
= c_parser_objc_selector (parser
);
6176 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6182 /* Parse an objc-keywordexpr.
6189 c_parser_objc_keywordexpr (c_parser
*parser
)
6191 tree list
= c_parser_expr_list (parser
);
6192 if (TREE_CHAIN (list
) == NULL_TREE
)
6194 /* Just return the expression, remove a level of
6196 return TREE_VALUE (list
);
6200 /* We have a comma expression, we will collapse later. */
6206 /* The actual parser and external interface. ??? Does this need to be
6207 garbage-collected? */
6209 static GTY (()) c_parser
*the_parser
;
6211 /* Parse a single source file. */
6216 the_parser
= c_parser_new ();
6217 c_parser_translation_unit (the_parser
);
6221 #include "gt-c-parser.h"