1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 Parser actions based on the old Bison parser; structure somewhat
6 influenced by and fragments based on the C++ parser.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
45 #include "langhooks.h"
58 /* Miscellaneous data and functions needed for the parser. */
62 /* Objective-C specific parser/lexer information. */
64 static int objc_pq_context
= 0;
66 /* The following flag is needed to contextualize Objective-C lexical
67 analysis. In some cases (e.g., 'int NSObject;'), it is undesirable
68 to bind an identifier to an Objective-C class, even if a class with
70 static int objc_need_raw_identifier
= 0;
71 #define OBJC_NEED_RAW_IDENTIFIER(VAL) \
73 if (c_dialect_objc ()) \
74 objc_need_raw_identifier = VAL; \
77 /* The reserved keyword table. */
81 ENUM_BITFIELD(rid
) rid
: 16;
82 unsigned int disable
: 16;
85 /* Disable mask. Keywords are disabled if (reswords[i].disable &
87 #define D_C89 0x01 /* not in C89 */
88 #define D_EXT 0x02 /* GCC extension */
89 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
90 #define D_OBJC 0x08 /* Objective C only */
92 static const struct resword reswords
[] =
94 { "_Bool", RID_BOOL
, 0 },
95 { "_Complex", RID_COMPLEX
, 0 },
96 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
97 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
98 { "__alignof", RID_ALIGNOF
, 0 },
99 { "__alignof__", RID_ALIGNOF
, 0 },
100 { "__asm", RID_ASM
, 0 },
101 { "__asm__", RID_ASM
, 0 },
102 { "__attribute", RID_ATTRIBUTE
, 0 },
103 { "__attribute__", RID_ATTRIBUTE
, 0 },
104 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
105 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
106 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
107 { "__builtin_va_arg", RID_VA_ARG
, 0 },
108 { "__complex", RID_COMPLEX
, 0 },
109 { "__complex__", RID_COMPLEX
, 0 },
110 { "__const", RID_CONST
, 0 },
111 { "__const__", RID_CONST
, 0 },
112 { "__extension__", RID_EXTENSION
, 0 },
113 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
114 { "__imag", RID_IMAGPART
, 0 },
115 { "__imag__", RID_IMAGPART
, 0 },
116 { "__inline", RID_INLINE
, 0 },
117 { "__inline__", RID_INLINE
, 0 },
118 { "__label__", RID_LABEL
, 0 },
119 { "__real", RID_REALPART
, 0 },
120 { "__real__", RID_REALPART
, 0 },
121 { "__restrict", RID_RESTRICT
, 0 },
122 { "__restrict__", RID_RESTRICT
, 0 },
123 { "__signed", RID_SIGNED
, 0 },
124 { "__signed__", RID_SIGNED
, 0 },
125 { "__thread", RID_THREAD
, 0 },
126 { "__typeof", RID_TYPEOF
, 0 },
127 { "__typeof__", RID_TYPEOF
, 0 },
128 { "__volatile", RID_VOLATILE
, 0 },
129 { "__volatile__", RID_VOLATILE
, 0 },
130 { "asm", RID_ASM
, D_EXT
},
131 { "auto", RID_AUTO
, 0 },
132 { "break", RID_BREAK
, 0 },
133 { "case", RID_CASE
, 0 },
134 { "char", RID_CHAR
, 0 },
135 { "const", RID_CONST
, 0 },
136 { "continue", RID_CONTINUE
, 0 },
137 { "default", RID_DEFAULT
, 0 },
139 { "double", RID_DOUBLE
, 0 },
140 { "else", RID_ELSE
, 0 },
141 { "enum", RID_ENUM
, 0 },
142 { "extern", RID_EXTERN
, 0 },
143 { "float", RID_FLOAT
, 0 },
144 { "for", RID_FOR
, 0 },
145 { "goto", RID_GOTO
, 0 },
147 { "inline", RID_INLINE
, D_EXT89
},
148 { "int", RID_INT
, 0 },
149 { "long", RID_LONG
, 0 },
150 { "register", RID_REGISTER
, 0 },
151 { "restrict", RID_RESTRICT
, D_C89
},
152 { "return", RID_RETURN
, 0 },
153 { "short", RID_SHORT
, 0 },
154 { "signed", RID_SIGNED
, 0 },
155 { "sizeof", RID_SIZEOF
, 0 },
156 { "static", RID_STATIC
, 0 },
157 { "struct", RID_STRUCT
, 0 },
158 { "switch", RID_SWITCH
, 0 },
159 { "typedef", RID_TYPEDEF
, 0 },
160 { "typeof", RID_TYPEOF
, D_EXT
},
161 { "union", RID_UNION
, 0 },
162 { "unsigned", RID_UNSIGNED
, 0 },
163 { "void", RID_VOID
, 0 },
164 { "volatile", RID_VOLATILE
, 0 },
165 { "while", RID_WHILE
, 0 },
166 /* These Objective-C keywords are recognized only immediately after
168 { "class", RID_AT_CLASS
, D_OBJC
},
169 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
170 { "defs", RID_AT_DEFS
, D_OBJC
},
171 { "encode", RID_AT_ENCODE
, D_OBJC
},
172 { "end", RID_AT_END
, D_OBJC
},
173 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
174 { "interface", RID_AT_INTERFACE
, D_OBJC
},
175 { "private", RID_AT_PRIVATE
, D_OBJC
},
176 { "protected", RID_AT_PROTECTED
, D_OBJC
},
177 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
178 { "public", RID_AT_PUBLIC
, D_OBJC
},
179 { "selector", RID_AT_SELECTOR
, D_OBJC
},
180 { "throw", RID_AT_THROW
, D_OBJC
},
181 { "try", RID_AT_TRY
, D_OBJC
},
182 { "catch", RID_AT_CATCH
, D_OBJC
},
183 { "finally", RID_AT_FINALLY
, D_OBJC
},
184 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
185 /* These are recognized only in protocol-qualifier context
187 { "bycopy", RID_BYCOPY
, D_OBJC
},
188 { "byref", RID_BYREF
, D_OBJC
},
189 { "in", RID_IN
, D_OBJC
},
190 { "inout", RID_INOUT
, D_OBJC
},
191 { "oneway", RID_ONEWAY
, D_OBJC
},
192 { "out", RID_OUT
, D_OBJC
},
194 #define N_reswords (sizeof reswords / sizeof (struct resword))
196 /* Initialization routine for this file. */
201 /* The only initialization required is of the reserved word
205 int mask
= (flag_isoc99
? 0 : D_C89
)
206 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
208 if (!c_dialect_objc ())
211 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
212 for (i
= 0; i
< N_reswords
; i
++)
214 /* If a keyword is disabled, do not enter it into the table
215 and so create a canonical spelling that isn't a keyword. */
216 if (reswords
[i
].disable
& mask
)
219 id
= get_identifier (reswords
[i
].word
);
220 C_RID_CODE (id
) = reswords
[i
].rid
;
221 C_IS_RESERVED_WORD (id
) = 1;
222 ridpointers
[(int) reswords
[i
].rid
] = id
;
226 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
227 and the C parser. Unlike the C++ lexer, the parser structure
228 stores the lexer information instead of using a separate structure.
229 Identifiers are separated into ordinary identifiers, type names,
230 keywords and some other Objective-C types of identifiers, and some
231 look-ahead is maintained.
233 ??? It might be a good idea to lex the whole file up front (as for
234 C++). It would then be possible to share more of the C and C++
235 lexer code, if desired. */
237 /* The following local token type is used. */
240 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
242 /* More information about the type of a CPP_NAME token. */
243 typedef enum c_id_kind
{
244 /* An ordinary identifier. */
246 /* An identifier declared as a typedef name. */
248 /* An identifier declared as an Objective-C class name. */
250 /* Not an identifier. */
254 /* A single C token after string literal concatenation and conversion
255 of preprocessing tokens to tokens. */
256 typedef struct c_token
GTY (())
258 /* The kind of token. */
259 ENUM_BITFIELD (cpp_ttype
) type
: 8;
260 /* If this token is a CPP_NAME, this value indicates whether also
261 declared as some kind of type. Otherwise, it is C_ID_NONE. */
262 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
263 /* If this token is a keyword, this value indicates which keyword.
264 Otherwise, this value is RID_MAX. */
265 ENUM_BITFIELD (rid
) keyword
: 8;
266 /* True if this token is from a system header. */
267 BOOL_BITFIELD in_system_header
: 1;
268 /* The value associated with this token, if any. */
270 /* The location at which this token was found. */
274 /* A parser structure recording information about the state and
275 context of parsing. Includes lexer information with up to two
276 tokens of look-ahead; more are not needed for C. */
277 typedef struct c_parser
GTY(())
279 /* The look-ahead tokens. */
281 /* How many look-ahead tokens are available (0, 1 or 2). */
283 /* True if a syntax error is being recovered from; false otherwise.
284 c_parser_error sets this flag. It should clear this flag when
285 enough tokens have been consumed to recover from the error. */
286 BOOL_BITFIELD error
: 1;
289 /* Read in and lex a single token, storing it in *TOKEN. */
292 c_lex_one_token (c_token
*token
)
294 timevar_push (TV_LEX
);
295 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
);
296 token
->in_system_header
= in_system_header
;
300 token
->id_kind
= C_ID_NONE
;
301 token
->keyword
= RID_MAX
;
305 int objc_force_identifier
= objc_need_raw_identifier
;
306 OBJC_NEED_RAW_IDENTIFIER (0);
308 if (C_IS_RESERVED_WORD (token
->value
))
310 enum rid rid_code
= C_RID_CODE (token
->value
);
312 if (c_dialect_objc ())
314 if (!OBJC_IS_AT_KEYWORD (rid_code
)
315 && (!OBJC_IS_PQ_KEYWORD (rid_code
) || objc_pq_context
))
317 /* Return the canonical spelling for this keyword. */
318 token
->value
= ridpointers
[(int) rid_code
];
319 token
->type
= CPP_KEYWORD
;
320 token
->keyword
= rid_code
;
326 /* Return the canonical spelling for this keyword. */
327 token
->value
= ridpointers
[(int) rid_code
];
328 token
->type
= CPP_KEYWORD
;
329 token
->keyword
= rid_code
;
334 decl
= lookup_name (token
->value
);
337 if (TREE_CODE (decl
) == TYPE_DECL
)
339 token
->id_kind
= C_ID_TYPENAME
;
343 else if (c_dialect_objc ())
345 tree objc_interface_decl
= objc_is_class_name (token
->value
);
346 /* Objective-C class names are in the same namespace as
347 variables and typedefs, and hence are shadowed by local
349 if (objc_interface_decl
350 && (global_bindings_p ()
351 || (!objc_force_identifier
&& !decl
)))
353 token
->value
= objc_interface_decl
;
354 token
->id_kind
= C_ID_CLASSNAME
;
359 token
->id_kind
= C_ID_ID
;
362 /* This only happens in Objective-C; it must be a keyword. */
363 token
->type
= CPP_KEYWORD
;
364 token
->id_kind
= C_ID_NONE
;
365 token
->keyword
= C_RID_CODE (token
->value
);
369 case CPP_CLOSE_PAREN
:
371 /* These tokens may affect the interpretation of any identifiers
372 following, if doing Objective-C. */
373 OBJC_NEED_RAW_IDENTIFIER (0);
374 token
->id_kind
= C_ID_NONE
;
375 token
->keyword
= RID_MAX
;
378 token
->id_kind
= C_ID_NONE
;
379 token
->keyword
= RID_MAX
;
382 timevar_pop (TV_LEX
);
385 /* Return a pointer to the next token from PARSER, reading it in if
388 static inline c_token
*
389 c_parser_peek_token (c_parser
*parser
)
391 if (parser
->tokens_avail
== 0)
393 c_lex_one_token (&parser
->tokens
[0]);
394 parser
->tokens_avail
= 1;
396 return &parser
->tokens
[0];
399 /* Return true if the next token from PARSER has the indicated
403 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
405 return c_parser_peek_token (parser
)->type
== type
;
408 /* Return true if the next token from PARSER does not have the
412 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
414 return !c_parser_next_token_is (parser
, type
);
417 /* Return true if the next token from PARSER is the indicated
421 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
425 /* Peek at the next token. */
426 token
= c_parser_peek_token (parser
);
427 /* Check to see if it is the indicated keyword. */
428 return token
->keyword
== keyword
;
431 /* Return true if TOKEN can start a type name,
434 c_token_starts_typename (c_token
*token
)
439 switch (token
->id_kind
)
446 gcc_assert (c_dialect_objc ());
452 switch (token
->keyword
)
478 if (c_dialect_objc ())
486 /* Return true if the next token from PARSER can start a type name,
489 c_parser_next_token_starts_typename (c_parser
*parser
)
491 c_token
*token
= c_parser_peek_token (parser
);
492 return c_token_starts_typename (token
);
495 /* Return true if TOKEN can start declaration specifiers, false
498 c_token_starts_declspecs (c_token
*token
)
503 switch (token
->id_kind
)
510 gcc_assert (c_dialect_objc ());
516 switch (token
->keyword
)
549 if (c_dialect_objc ())
557 /* Return true if the next token from PARSER can start declaration
558 specifiers, false otherwise. */
560 c_parser_next_token_starts_declspecs (c_parser
*parser
)
562 c_token
*token
= c_parser_peek_token (parser
);
563 return c_token_starts_declspecs (token
);
566 /* Return a pointer to the next-but-one token from PARSER, reading it
567 in if necessary. The next token is already read in. */
570 c_parser_peek_2nd_token (c_parser
*parser
)
572 if (parser
->tokens_avail
>= 2)
573 return &parser
->tokens
[1];
574 gcc_assert (parser
->tokens_avail
== 1);
575 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
576 c_lex_one_token (&parser
->tokens
[1]);
577 parser
->tokens_avail
= 2;
578 return &parser
->tokens
[1];
581 /* Consume the next token from PARSER. */
584 c_parser_consume_token (c_parser
*parser
)
586 if (parser
->tokens_avail
== 2)
587 parser
->tokens
[0] = parser
->tokens
[1];
590 gcc_assert (parser
->tokens_avail
== 1);
591 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
593 parser
->tokens_avail
--;
596 /* Update the globals input_location and in_system_header from
599 c_parser_set_source_position_from_token (c_token
*token
)
601 if (token
->type
!= CPP_EOF
)
603 input_location
= token
->location
;
604 in_system_header
= token
->in_system_header
;
608 /* Allocate a new parser. */
613 /* Use local storage to lex the first token because loading a PCH
614 file may cause garbage collection. */
617 memset (&tparser
, 0, sizeof tparser
);
618 c_lex_one_token (&tparser
.tokens
[0]);
619 tparser
.tokens_avail
= 1;
620 ret
= GGC_NEW (c_parser
);
621 memcpy (ret
, &tparser
, sizeof tparser
);
625 /* Issue a diagnostic of the form
626 FILE:LINE: MESSAGE before TOKEN
627 where TOKEN is the next token in the input stream of PARSER.
628 MESSAGE (specified by the caller) is usually of the form "expected
631 Do not issue a diagnostic if still recovering from an error.
633 ??? This is taken from the C++ parser, but building up messages in
634 this way is not i18n-friendly and some other approach should be
638 c_parser_error (c_parser
*parser
, const char *gmsgid
)
640 c_token
*token
= c_parser_peek_token (parser
);
643 parser
->error
= true;
646 /* This diagnostic makes more sense if it is tagged to the line of
647 the token we just peeked at. */
648 c_parser_set_source_position_from_token (token
);
649 c_parse_error (gmsgid
,
650 /* Because c_parse_error does not understand
651 CPP_KEYWORD, keywords are treated like
653 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
657 /* If the next token is of the indicated TYPE, consume it. Otherwise,
658 issue the error MSGID. If MSGID is NULL then a message has already
659 been produced and no message will be produced this time. Returns
660 true if found, false otherwise. */
663 c_parser_require (c_parser
*parser
,
667 if (c_parser_next_token_is (parser
, type
))
669 c_parser_consume_token (parser
);
674 c_parser_error (parser
, msgid
);
679 /* If the next token is the indicated keyword, consume it. Otherwise,
680 issue the error MSGID. Returns true if found, false otherwise. */
683 c_parser_require_keyword (c_parser
*parser
,
687 if (c_parser_next_token_is_keyword (parser
, keyword
))
689 c_parser_consume_token (parser
);
694 c_parser_error (parser
, msgid
);
699 /* Like c_parser_require, except that tokens will be skipped until the
700 desired token is found. An error message is still produced if the
701 next token is not as expected. If MSGID is NULL then a message has
702 already been produced and no message will be produced this
706 c_parser_skip_until_found (c_parser
*parser
,
710 unsigned nesting_depth
= 0;
712 if (c_parser_require (parser
, type
, msgid
))
715 /* Skip tokens until the desired token is found. */
718 /* Peek at the next token. */
719 c_token
*token
= c_parser_peek_token (parser
);
720 /* If we've reached the token we want, consume it and stop. */
721 if (token
->type
== type
&& !nesting_depth
)
723 c_parser_consume_token (parser
);
726 /* If we've run out of tokens, stop. */
727 if (token
->type
== CPP_EOF
)
729 if (token
->type
== CPP_OPEN_BRACE
730 || token
->type
== CPP_OPEN_PAREN
731 || token
->type
== CPP_OPEN_SQUARE
)
733 else if (token
->type
== CPP_CLOSE_BRACE
734 || token
->type
== CPP_CLOSE_PAREN
735 || token
->type
== CPP_CLOSE_SQUARE
)
737 if (nesting_depth
-- == 0)
740 /* Consume this token. */
741 c_parser_consume_token (parser
);
743 parser
->error
= false;
746 /* Skip tokens until the end of a parameter is found, but do not
747 consume the comma, semicolon or closing delimiter. */
750 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
752 unsigned nesting_depth
= 0;
756 c_token
*token
= c_parser_peek_token (parser
);
757 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
760 /* If we've run out of tokens, stop. */
761 if (token
->type
== CPP_EOF
)
763 if (token
->type
== CPP_OPEN_BRACE
764 || token
->type
== CPP_OPEN_PAREN
765 || token
->type
== CPP_OPEN_SQUARE
)
767 else if (token
->type
== CPP_CLOSE_BRACE
768 || token
->type
== CPP_CLOSE_PAREN
769 || token
->type
== CPP_CLOSE_SQUARE
)
771 if (nesting_depth
-- == 0)
774 /* Consume this token. */
775 c_parser_consume_token (parser
);
777 parser
->error
= false;
780 /* Skip tokens until we have consumed an entire block, or until we
781 have consumed a non-nested ';'. */
784 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
786 unsigned nesting_depth
= 0;
792 /* Peek at the next token. */
793 token
= c_parser_peek_token (parser
);
794 /* If we've run out of tokens, stop. */
795 if (token
->type
== CPP_EOF
)
797 /* If the next token is a ';', we have reached the end of the
799 if (token
->type
== CPP_SEMICOLON
&& !nesting_depth
)
801 /* Consume the ';'. */
802 c_parser_consume_token (parser
);
805 /* If the next token is a non-nested '}', then we have reached
806 the end of the current block. */
807 if (token
->type
== CPP_CLOSE_BRACE
808 && (nesting_depth
== 0 || --nesting_depth
== 0))
810 c_parser_consume_token (parser
);
813 /* If it the next token is a '{', then we are entering a new
814 block. Consume the entire block. */
815 if (token
->type
== CPP_OPEN_BRACE
)
817 c_parser_consume_token (parser
);
819 parser
->error
= false;
823 /* Save the warning flags which are controlled by __extension__. */
826 disable_extension_diagnostics (void)
829 | (warn_pointer_arith
<< 1)
830 | (warn_traditional
<< 2)
833 warn_pointer_arith
= 0;
834 warn_traditional
= 0;
839 /* Restore the warning flags which are controlled by __extension__.
840 FLAGS is the return value from disable_extension_diagnostics. */
843 restore_extension_diagnostics (int flags
)
845 pedantic
= flags
& 1;
846 warn_pointer_arith
= (flags
>> 1) & 1;
847 warn_traditional
= (flags
>> 2) & 1;
848 flag_iso
= (flags
>> 3) & 1;
851 /* Possibly kinds of declarator to parse. */
852 typedef enum c_dtr_syn
{
853 /* A normal declarator with an identifier. */
855 /* An abstract declarator (maybe empty). */
857 /* A parameter declarator: may be either, but after a type name does
858 not redeclare a typedef name as an identifier if it can
859 alternatively be interpreted as a typedef name; see DR#009,
860 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
861 following DR#249. For example, given a typedef T, "int T" and
862 "int *T" are valid parameter declarations redeclaring T, while
863 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
864 abstract declarators rather than involving redundant parentheses;
865 the same applies with attributes inside the parentheses before
870 static void c_parser_external_declaration (c_parser
*);
871 static void c_parser_asm_definition (c_parser
*);
872 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
873 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
875 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
876 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
877 static tree
c_parser_struct_declaration (c_parser
*);
878 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
879 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
881 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
883 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
885 struct c_declarator
*);
886 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
887 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
888 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
889 static tree
c_parser_simple_asm_expr (c_parser
*);
890 static tree
c_parser_attributes (c_parser
*);
891 static struct c_type_name
*c_parser_type_name (c_parser
*);
892 static struct c_expr
c_parser_initializer (c_parser
*);
893 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
894 static void c_parser_initelt (c_parser
*);
895 static void c_parser_initval (c_parser
*, struct c_expr
*);
896 static tree
c_parser_compound_statement (c_parser
*);
897 static void c_parser_compound_statement_nostart (c_parser
*);
898 static void c_parser_label (c_parser
*);
899 static void c_parser_statement (c_parser
*);
900 static void c_parser_statement_after_labels (c_parser
*);
901 static void c_parser_if_statement (c_parser
*);
902 static void c_parser_switch_statement (c_parser
*);
903 static void c_parser_while_statement (c_parser
*);
904 static void c_parser_do_statement (c_parser
*);
905 static void c_parser_for_statement (c_parser
*);
906 static tree
c_parser_asm_statement (c_parser
*);
907 static tree
c_parser_asm_operands (c_parser
*, bool);
908 static tree
c_parser_asm_clobbers (c_parser
*);
909 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
910 static struct c_expr
c_parser_conditional_expression (c_parser
*,
912 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
913 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
914 static struct c_expr
c_parser_unary_expression (c_parser
*);
915 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
916 static struct c_expr
c_parser_alignof_expression (c_parser
*);
917 static struct c_expr
c_parser_postfix_expression (c_parser
*);
918 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
919 struct c_type_name
*);
920 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
922 static struct c_expr
c_parser_expression (c_parser
*);
923 static struct c_expr
c_parser_expression_conv (c_parser
*);
924 static tree
c_parser_expr_list (c_parser
*, bool);
926 /* These Objective-C parser functions are only ever called when
927 compiling Objective-C. */
928 static void c_parser_objc_class_definition (c_parser
*);
929 static void c_parser_objc_class_instance_variables (c_parser
*);
930 static void c_parser_objc_class_declaration (c_parser
*);
931 static void c_parser_objc_alias_declaration (c_parser
*);
932 static void c_parser_objc_protocol_definition (c_parser
*);
933 static enum tree_code
c_parser_objc_method_type (c_parser
*);
934 static void c_parser_objc_method_definition (c_parser
*);
935 static void c_parser_objc_methodprotolist (c_parser
*);
936 static void c_parser_objc_methodproto (c_parser
*);
937 static tree
c_parser_objc_method_decl (c_parser
*);
938 static tree
c_parser_objc_type_name (c_parser
*);
939 static tree
c_parser_objc_protocol_refs (c_parser
*);
940 static void c_parser_objc_try_catch_statement (c_parser
*);
941 static void c_parser_objc_synchronized_statement (c_parser
*);
942 static tree
c_parser_objc_selector (c_parser
*);
943 static tree
c_parser_objc_selector_arg (c_parser
*);
944 static tree
c_parser_objc_receiver (c_parser
*);
945 static tree
c_parser_objc_message_args (c_parser
*);
946 static tree
c_parser_objc_keywordexpr (c_parser
*);
948 /* Parse a translation unit (C90 6.7, C99 6.9).
951 external-declarations
953 external-declarations:
955 external-declarations external-declaration
964 c_parser_translation_unit (c_parser
*parser
)
966 if (c_parser_next_token_is (parser
, CPP_EOF
))
969 pedwarn ("ISO C forbids an empty source file");
973 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
977 c_parser_external_declaration (parser
);
978 obstack_free (&parser_obstack
, obstack_position
);
980 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
984 /* Parse an external declaration (C90 6.7, C99 6.9).
986 external-declaration:
992 external-declaration:
995 __extension__ external-declaration
999 external-declaration:
1000 objc-class-definition
1001 objc-class-declaration
1002 objc-alias-declaration
1003 objc-protocol-definition
1004 objc-method-definition
1009 c_parser_external_declaration (c_parser
*parser
)
1012 switch (c_parser_peek_token (parser
)->type
)
1015 switch (c_parser_peek_token (parser
)->keyword
)
1018 ext
= disable_extension_diagnostics ();
1019 c_parser_consume_token (parser
);
1020 c_parser_external_declaration (parser
);
1021 restore_extension_diagnostics (ext
);
1024 c_parser_asm_definition (parser
);
1026 case RID_AT_INTERFACE
:
1027 case RID_AT_IMPLEMENTATION
:
1028 gcc_assert (c_dialect_objc ());
1029 c_parser_objc_class_definition (parser
);
1032 gcc_assert (c_dialect_objc ());
1033 c_parser_objc_class_declaration (parser
);
1036 gcc_assert (c_dialect_objc ());
1037 c_parser_objc_alias_declaration (parser
);
1039 case RID_AT_PROTOCOL
:
1040 gcc_assert (c_dialect_objc ());
1041 c_parser_objc_protocol_definition (parser
);
1044 gcc_assert (c_dialect_objc ());
1045 c_parser_consume_token (parser
);
1046 objc_finish_implementation ();
1054 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1055 c_parser_consume_token (parser
);
1059 if (c_dialect_objc ())
1061 c_parser_objc_method_definition (parser
);
1064 /* Else fall through, and yield a syntax error trying to parse
1065 as a declaration or function definition. */
1068 /* A declaration or a function definition. We can only tell
1069 which after parsing the declaration specifiers, if any, and
1070 the first declarator. */
1071 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1076 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1077 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1078 accepted; otherwise (old-style parameter declarations) only other
1079 declarations are accepted. If NESTED is true, we are inside a
1080 function or parsing old-style parameter declarations; any functions
1081 encountered are nested functions and declaration specifiers are
1082 required; otherwise we are at top level and functions are normal
1083 functions and declaration specifiers may be optional. If EMPTY_OK
1084 is true, empty declarations are OK (subject to all other
1085 constraints); otherwise (old-style parameter declarations) they are
1086 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1087 may start with attributes; otherwise they may not.
1090 declaration-specifiers init-declarator-list[opt] ;
1092 function-definition:
1093 declaration-specifiers[opt] declarator declaration-list[opt]
1098 declaration-list declaration
1100 init-declarator-list:
1102 init-declarator-list , init-declarator
1105 declarator simple-asm-expr[opt] attributes[opt]
1106 declarator simple-asm-expr[opt] attributes[opt] = initializer
1110 nested-function-definition:
1111 declaration-specifiers declarator declaration-list[opt]
1114 The simple-asm-expr and attributes are GNU extensions.
1116 This function does not handle __extension__; that is handled in its
1117 callers. ??? Following the old parser, __extension__ may start
1118 external declarations, declarations in functions and declarations
1119 at the start of "for" loops, but not old-style parameter
1122 C99 requires declaration specifiers in a function definition; the
1123 absence is diagnosed through the diagnosis of implicit int. In GNU
1124 C we also allow but diagnose declarations without declaration
1125 specifiers, but only at top level (elsewhere they conflict with
1129 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1130 bool nested
, bool start_attr_ok
)
1132 struct c_declspecs
*specs
;
1134 tree all_prefix_attrs
;
1135 bool diagnosed_no_specs
= false;
1136 specs
= build_null_declspecs ();
1137 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1140 c_parser_skip_to_end_of_block_or_statement (parser
);
1143 if (nested
&& !specs
->declspecs_seen_p
)
1145 c_parser_error (parser
, "expected declaration specifiers");
1146 c_parser_skip_to_end_of_block_or_statement (parser
);
1149 finish_declspecs (specs
);
1150 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1156 shadow_tag_warned (specs
, 1);
1157 pedwarn ("empty declaration");
1159 c_parser_consume_token (parser
);
1162 pending_xref_error ();
1163 prefix_attrs
= specs
->attrs
;
1164 all_prefix_attrs
= prefix_attrs
;
1165 specs
->attrs
= NULL_TREE
;
1168 struct c_declarator
*declarator
;
1171 /* Declaring either one or more declarators (in which case we
1172 should diagnose if there were no declaration specifiers) or a
1173 function definition (in which case the diagnostic for
1174 implicit int suffices). */
1175 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1176 C_DTR_NORMAL
, &dummy
);
1177 if (declarator
== NULL
)
1179 c_parser_skip_to_end_of_block_or_statement (parser
);
1182 if (c_parser_next_token_is (parser
, CPP_EQ
)
1183 || c_parser_next_token_is (parser
, CPP_COMMA
)
1184 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1185 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1186 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1188 tree asm_name
= NULL_TREE
;
1189 tree postfix_attrs
= NULL_TREE
;
1190 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1192 diagnosed_no_specs
= true;
1193 pedwarn ("data definition has no type or storage class");
1195 /* Having seen a data definition, there cannot now be a
1196 function definition. */
1198 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1199 asm_name
= c_parser_simple_asm_expr (parser
);
1200 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1201 postfix_attrs
= c_parser_attributes (parser
);
1202 if (c_parser_next_token_is (parser
, CPP_EQ
))
1206 c_parser_consume_token (parser
);
1207 /* The declaration of the variable is in effect while
1208 its initializer is parsed. */
1209 d
= start_decl (declarator
, specs
, true,
1210 chainon (postfix_attrs
, all_prefix_attrs
));
1212 d
= error_mark_node
;
1213 start_init (d
, asm_name
, global_bindings_p ());
1214 init
= c_parser_initializer (parser
);
1216 if (d
!= error_mark_node
)
1218 maybe_warn_string_init (TREE_TYPE (d
), init
);
1219 finish_decl (d
, init
.value
, asm_name
);
1224 tree d
= start_decl (declarator
, specs
, false,
1225 chainon (postfix_attrs
,
1228 finish_decl (d
, NULL_TREE
, asm_name
);
1230 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1232 c_parser_consume_token (parser
);
1233 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1234 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1237 all_prefix_attrs
= prefix_attrs
;
1240 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1242 c_parser_consume_token (parser
);
1247 c_parser_error (parser
, "expected %<,%> or %<;%>");
1248 c_parser_skip_to_end_of_block_or_statement (parser
);
1254 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1255 "%<asm%> or %<__attribute__%>");
1256 c_parser_skip_to_end_of_block_or_statement (parser
);
1259 /* Function definition (nested or otherwise). */
1263 pedwarn ("ISO C forbids nested functions");
1264 push_function_context ();
1266 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1268 /* This can appear in many cases looking nothing like a
1269 function definition, so we don't give a more specific
1270 error suggesting there was one. */
1271 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1272 "or %<__attribute__%>");
1274 pop_function_context ();
1277 /* Parse old-style parameter declarations. ??? Attributes are
1278 not allowed to start declaration specifiers here because of a
1279 syntax conflict between a function declaration with attribute
1280 suffix and a function definition with an attribute prefix on
1281 first old-style parameter declaration. Following the old
1282 parser, they are not accepted on subsequent old-style
1283 parameter declarations either. However, there is no
1284 ambiguity after the first declaration, nor indeed on the
1285 first as long as we don't allow postfix attributes after a
1286 declarator with a nonempty identifier list in a definition;
1287 and postfix attributes have never been accepted here in
1288 function definitions either. */
1289 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1290 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1291 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1292 DECL_SOURCE_LOCATION (current_function_decl
)
1293 = c_parser_peek_token (parser
)->location
;
1294 store_parm_decls ();
1295 fnbody
= c_parser_compound_statement (parser
);
1298 tree decl
= current_function_decl
;
1301 pop_function_context ();
1302 add_stmt (build_stmt (DECL_EXPR
, decl
));
1313 /* Parse an asm-definition (asm() outside a function body). This is a
1321 c_parser_asm_definition (c_parser
*parser
)
1323 tree asm_str
= c_parser_simple_asm_expr (parser
);
1324 /* ??? This only works sensibly in the presence of
1325 -fno-unit-at-a-time; file-scope asms really need to be passed to
1326 cgraph which needs to preserve the order of functions and
1329 assemble_asm (asm_str
);
1330 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1333 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1334 6.7), adding them to SPECS (which may already include some).
1335 Storage class specifiers are accepted iff SCSPEC_OK; type
1336 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1337 the start iff START_ATTR_OK.
1339 declaration-specifiers:
1340 storage-class-specifier declaration-specifiers[opt]
1341 type-specifier declaration-specifiers[opt]
1342 type-qualifier declaration-specifiers[opt]
1343 function-specifier declaration-specifiers[opt]
1345 Function specifiers (inline) are from C99, and are currently
1346 handled as storage class specifiers, as is __thread.
1348 C90 6.5.1, C99 6.7.1:
1349 storage-class-specifier:
1360 C90 6.5.2, C99 6.7.2:
1373 [_Imaginary removed in C99 TC2]
1374 struct-or-union-specifier
1378 (_Bool and _Complex are new in C99.)
1380 C90 6.5.3, C99 6.7.3:
1387 (restrict is new in C99.)
1391 declaration-specifiers:
1392 attributes declaration-specifiers[opt]
1394 storage-class-specifier:
1403 class-name objc-protocol-refs[opt]
1404 typedef-name objc-protocol-refs
1409 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1410 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1412 bool attrs_ok
= start_attr_ok
;
1413 bool seen_type
= specs
->type_seen_p
;
1414 while (c_parser_next_token_is (parser
, CPP_NAME
)
1415 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1416 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1418 struct c_typespec t
;
1420 if (c_parser_next_token_is (parser
, CPP_NAME
))
1422 tree value
= c_parser_peek_token (parser
)->value
;
1423 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1424 /* This finishes the specifiers unless a type name is OK, it
1425 is declared as a type name and a type name hasn't yet
1427 if (!typespec_ok
|| seen_type
1428 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1430 c_parser_consume_token (parser
);
1433 if (kind
== C_ID_TYPENAME
1434 && (!c_dialect_objc ()
1435 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1437 t
.kind
= ctsk_typedef
;
1438 /* For a typedef name, record the meaning, not the name.
1439 In case of 'foo foo, bar;'. */
1440 t
.spec
= lookup_name (value
);
1444 tree proto
= NULL_TREE
;
1445 gcc_assert (c_dialect_objc ());
1447 if (c_parser_next_token_is (parser
, CPP_LESS
))
1448 proto
= c_parser_objc_protocol_refs (parser
);
1449 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1451 declspecs_add_type (specs
, t
);
1454 if (c_parser_next_token_is (parser
, CPP_LESS
))
1456 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1457 nisse@lysator.liu.se. */
1459 gcc_assert (c_dialect_objc ());
1460 if (!typespec_ok
|| seen_type
)
1462 proto
= c_parser_objc_protocol_refs (parser
);
1464 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1465 declspecs_add_type (specs
, t
);
1468 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1469 switch (c_parser_peek_token (parser
)->keyword
)
1481 /* TODO: Distinguish between function specifiers (inline)
1482 and storage class specifiers, either here or in
1483 declspecs_add_scspec. */
1484 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1485 c_parser_consume_token (parser
);
1502 OBJC_NEED_RAW_IDENTIFIER (1);
1503 t
.kind
= ctsk_resword
;
1504 t
.spec
= c_parser_peek_token (parser
)->value
;
1505 declspecs_add_type (specs
, t
);
1506 c_parser_consume_token (parser
);
1513 t
= c_parser_enum_specifier (parser
);
1514 declspecs_add_type (specs
, t
);
1522 t
= c_parser_struct_or_union_specifier (parser
);
1523 declspecs_add_type (specs
, t
);
1526 /* ??? The old parser rejected typeof after other type
1527 specifiers, but is a syntax error the best way of
1529 if (!typespec_ok
|| seen_type
)
1533 t
= c_parser_typeof_specifier (parser
);
1534 declspecs_add_type (specs
, t
);
1540 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1541 c_parser_consume_token (parser
);
1546 attrs
= c_parser_attributes (parser
);
1547 declspecs_add_attrs (specs
, attrs
);
1556 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1559 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1560 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1561 enum attributes[opt] identifier
1563 The form with trailing comma is new in C99. The forms with
1564 attributes are GNU extensions. In GNU C, we accept any expression
1565 without commas in the syntax (assignment expressions, not just
1566 conditional expressions); assignment expressions will be diagnosed
1571 enumerator-list , enumerator
1574 enumeration-constant
1575 enumeration-constant = constant-expression
1578 static struct c_typespec
1579 c_parser_enum_specifier (c_parser
*parser
)
1581 struct c_typespec ret
;
1583 tree ident
= NULL_TREE
;
1584 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1585 c_parser_consume_token (parser
);
1586 attrs
= c_parser_attributes (parser
);
1587 if (c_parser_next_token_is (parser
, CPP_NAME
))
1589 ident
= c_parser_peek_token (parser
)->value
;
1590 c_parser_consume_token (parser
);
1592 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1594 /* Parse an enum definition. */
1595 tree type
= start_enum (ident
);
1597 /* We chain the enumerators in reverse order, then put them in
1598 forward order at the end. */
1599 tree values
= NULL_TREE
;
1600 c_parser_consume_token (parser
);
1607 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1609 c_parser_error (parser
, "expected identifier");
1610 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1611 values
= error_mark_node
;
1614 enum_id
= c_parser_peek_token (parser
)->value
;
1615 c_parser_consume_token (parser
);
1616 if (c_parser_next_token_is (parser
, CPP_EQ
))
1618 c_parser_consume_token (parser
);
1619 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1622 enum_value
= NULL_TREE
;
1623 enum_decl
= build_enumerator (enum_id
, enum_value
);
1624 TREE_CHAIN (enum_decl
) = values
;
1627 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1630 c_parser_consume_token (parser
);
1632 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1634 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1635 pedwarn ("comma at end of enumerator list");
1636 c_parser_consume_token (parser
);
1641 c_parser_error (parser
, "expected %<,%> or %<}%>");
1642 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1643 values
= error_mark_node
;
1647 postfix_attrs
= c_parser_attributes (parser
);
1648 ret
.spec
= finish_enum (type
, nreverse (values
),
1649 chainon (attrs
, postfix_attrs
));
1650 ret
.kind
= ctsk_tagdef
;
1655 c_parser_error (parser
, "expected %<{%>");
1656 ret
.spec
= error_mark_node
;
1657 ret
.kind
= ctsk_tagref
;
1660 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1661 /* In ISO C, enumerated types can be referred to only if already
1663 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1664 pedwarn ("ISO C forbids forward references to %<enum%> types");
1668 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1670 struct-or-union-specifier:
1671 struct-or-union attributes[opt] identifier[opt]
1672 { struct-contents } attributes[opt]
1673 struct-or-union attributes[opt] identifier
1676 struct-declaration-list
1678 struct-declaration-list:
1679 struct-declaration ;
1680 struct-declaration-list struct-declaration ;
1687 struct-declaration-list struct-declaration
1689 struct-declaration-list:
1690 struct-declaration-list ;
1693 (Note that in the syntax here, unlike that in ISO C, the semicolons
1694 are included here rather than in struct-declaration, in order to
1695 describe the syntax with extra semicolons and missing semicolon at
1700 struct-declaration-list:
1701 @defs ( class-name )
1703 (Note this does not include a trailing semicolon, but can be
1704 followed by further declarations, and gets a pedwarn-if-pedantic
1705 when followed by a semicolon.) */
1707 static struct c_typespec
1708 c_parser_struct_or_union_specifier (c_parser
*parser
)
1710 struct c_typespec ret
;
1712 tree ident
= NULL_TREE
;
1713 enum tree_code code
;
1714 switch (c_parser_peek_token (parser
)->keyword
)
1725 c_parser_consume_token (parser
);
1726 attrs
= c_parser_attributes (parser
);
1727 if (c_parser_next_token_is (parser
, CPP_NAME
))
1729 ident
= c_parser_peek_token (parser
)->value
;
1730 c_parser_consume_token (parser
);
1732 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1734 /* Parse a struct or union definition. Start the scope of the
1735 tag before parsing components. */
1736 tree type
= start_struct (code
, ident
);
1738 /* We chain the components in reverse order, then put them in
1739 forward order at the end. Each struct-declaration may
1740 declare multiple components (comma-separated), so we must use
1741 chainon to join them, although when parsing each
1742 struct-declaration we can use TREE_CHAIN directly.
1744 The theory behind all this is that there will be more
1745 semicolon separated fields than comma separated fields, and
1746 so we'll be minimizing the number of node traversals required
1748 tree contents
= NULL_TREE
;
1749 c_parser_consume_token (parser
);
1750 /* Handle the Objective-C @defs construct,
1751 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1752 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1755 gcc_assert (c_dialect_objc ());
1756 c_parser_consume_token (parser
);
1757 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1759 if (c_parser_next_token_is (parser
, CPP_NAME
)
1760 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1762 name
= c_parser_peek_token (parser
)->value
;
1763 c_parser_consume_token (parser
);
1767 c_parser_error (parser
, "expected class name");
1768 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1771 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1773 contents
= nreverse (objc_get_class_ivars (name
));
1776 /* Parse the struct-declarations and semicolons. Problems with
1777 semicolons are diagnosed here; empty structures are diagnosed
1782 /* Parse any stray semicolon. */
1783 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1786 pedwarn ("extra semicolon in struct or union specified");
1787 c_parser_consume_token (parser
);
1790 /* Stop if at the end of the struct or union contents. */
1791 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1793 c_parser_consume_token (parser
);
1796 /* Parse some comma-separated declarations, but not the
1797 trailing semicolon if any. */
1798 decls
= c_parser_struct_declaration (parser
);
1799 contents
= chainon (decls
, contents
);
1800 /* If no semicolon follows, either we have a parse error or
1801 are at the end of the struct or union and should
1803 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1804 c_parser_consume_token (parser
);
1807 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1808 pedwarn ("no semicolon at end of struct or union");
1811 c_parser_error (parser
, "expected %<;%>");
1812 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1817 postfix_attrs
= c_parser_attributes (parser
);
1818 ret
.spec
= finish_struct (type
, nreverse (contents
),
1819 chainon (attrs
, postfix_attrs
));
1820 ret
.kind
= ctsk_tagdef
;
1825 c_parser_error (parser
, "expected %<{%>");
1826 ret
.spec
= error_mark_node
;
1827 ret
.kind
= ctsk_tagref
;
1830 ret
= parser_xref_tag (code
, ident
);
1834 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1835 the trailing semicolon.
1838 specifier-qualifier-list struct-declarator-list
1840 specifier-qualifier-list:
1841 type-specifier specifier-qualifier-list[opt]
1842 type-qualifier specifier-qualifier-list[opt]
1843 attributes specifier-qualifier-list[opt]
1845 struct-declarator-list:
1847 struct-declarator-list , attributes[opt] struct-declarator
1850 declarator attributes[opt]
1851 declarator[opt] : constant-expression attributes[opt]
1856 __extension__ struct-declaration
1857 specifier-qualifier-list
1859 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1860 of attributes where shown is a GNU extension. In GNU C, we accept
1861 any expression without commas in the syntax (assignment
1862 expressions, not just conditional expressions); assignment
1863 expressions will be diagnosed as non-constant. */
1866 c_parser_struct_declaration (c_parser
*parser
)
1868 struct c_declspecs
*specs
;
1870 tree all_prefix_attrs
;
1872 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1876 ext
= disable_extension_diagnostics ();
1877 c_parser_consume_token (parser
);
1878 decl
= c_parser_struct_declaration (parser
);
1879 restore_extension_diagnostics (ext
);
1882 specs
= build_null_declspecs ();
1883 c_parser_declspecs (parser
, specs
, false, true, true);
1886 if (!specs
->declspecs_seen_p
)
1888 c_parser_error (parser
, "expected specifier-qualifier-list");
1891 finish_declspecs (specs
);
1892 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1895 if (!specs
->type_seen_p
)
1898 pedwarn ("ISO C forbids member declarations with no members");
1899 shadow_tag_warned (specs
, pedantic
);
1904 /* Support for unnamed structs or unions as members of
1905 structs or unions (which is [a] useful and [b] supports
1907 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
, NULL_TREE
);
1911 pending_xref_error ();
1912 prefix_attrs
= specs
->attrs
;
1913 all_prefix_attrs
= prefix_attrs
;
1914 specs
->attrs
= NULL_TREE
;
1918 /* Declaring one or more declarators or un-named bit-fields. */
1919 struct c_declarator
*declarator
;
1921 if (c_parser_next_token_is (parser
, CPP_COLON
))
1922 declarator
= build_id_declarator (NULL_TREE
);
1924 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1925 C_DTR_NORMAL
, &dummy
);
1926 if (declarator
== NULL
)
1928 c_parser_skip_to_end_of_block_or_statement (parser
);
1931 if (c_parser_next_token_is (parser
, CPP_COLON
)
1932 || c_parser_next_token_is (parser
, CPP_COMMA
)
1933 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1934 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
1935 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1937 tree postfix_attrs
= NULL_TREE
;
1938 tree width
= NULL_TREE
;
1940 if (c_parser_next_token_is (parser
, CPP_COLON
))
1942 c_parser_consume_token (parser
);
1943 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
1945 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1946 postfix_attrs
= c_parser_attributes (parser
);
1947 d
= grokfield (declarator
, specs
, width
);
1948 decl_attributes (&d
, chainon (postfix_attrs
,
1949 all_prefix_attrs
), 0);
1950 TREE_CHAIN (d
) = decls
;
1952 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1953 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1956 all_prefix_attrs
= prefix_attrs
;
1957 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1958 c_parser_consume_token (parser
);
1959 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1960 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1962 /* Semicolon consumed in caller. */
1967 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
1973 c_parser_error (parser
,
1974 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
1975 "%<__attribute__%>");
1982 /* Parse a typeof specifier (a GNU extension).
1985 typeof ( expression )
1986 typeof ( type-name )
1989 static struct c_typespec
1990 c_parser_typeof_specifier (c_parser
*parser
)
1992 struct c_typespec ret
;
1993 ret
.kind
= ctsk_typeof
;
1994 ret
.spec
= error_mark_node
;
1995 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
1996 c_parser_consume_token (parser
);
1999 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2005 if (c_parser_next_token_starts_typename (parser
))
2007 struct c_type_name
*type
= c_parser_type_name (parser
);
2012 ret
.spec
= groktypename (type
);
2013 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2018 struct c_expr expr
= c_parser_expression (parser
);
2021 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2022 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2023 error ("%<typeof%> applied to a bit-field");
2024 ret
.spec
= TREE_TYPE (expr
.value
);
2025 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2027 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2031 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2032 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2033 be redeclared; otherwise it may not. KIND indicates which kind of
2034 declarator is wanted. Returns a valid declarator except in the
2035 case of a syntax error in which case NULL is returned. *SEEN_ID is
2036 set to true if an identifier being declared is seen; this is used
2037 to diagnose bad forms of abstract array declarators and to
2038 determine whether an identifier list is syntactically permitted.
2041 pointer[opt] direct-declarator
2045 ( attributes[opt] declarator )
2046 direct-declarator array-declarator
2047 direct-declarator ( parameter-type-list )
2048 direct-declarator ( identifier-list[opt] )
2051 * type-qualifier-list[opt]
2052 * type-qualifier-list[opt] pointer
2054 type-qualifier-list:
2057 type-qualifier-list type-qualifier
2058 type-qualifier-list attributes
2060 parameter-type-list:
2062 parameter-list , ...
2065 parameter-declaration
2066 parameter-list , parameter-declaration
2068 parameter-declaration:
2069 declaration-specifiers declarator attributes[opt]
2070 declaration-specifiers abstract-declarator[opt] attributes[opt]
2074 identifier-list , identifier
2076 abstract-declarator:
2078 pointer[opt] direct-abstract-declarator
2080 direct-abstract-declarator:
2081 ( attributes[opt] abstract-declarator )
2082 direct-abstract-declarator[opt] array-declarator
2083 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2088 direct-declarator ( parameter-forward-declarations
2089 parameter-type-list[opt] )
2091 direct-abstract-declarator:
2092 direct-abstract-declarator[opt] ( parameter-forward-declarations
2093 parameter-type-list[opt] )
2095 parameter-forward-declarations:
2097 parameter-forward-declarations parameter-list ;
2099 The uses of attributes shown above are GNU extensions.
2101 Some forms of array declarator are not included in C99 in the
2102 syntax for abstract declarators; these are disallowed elsewhere.
2103 This may be a defect (DR#289).
2105 This function also accepts an omitted abstract declarator as being
2106 an abstract declarator, although not part of the formal syntax. */
2108 static struct c_declarator
*
2109 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2112 /* Parse any initial pointer part. */
2113 if (c_parser_next_token_is (parser
, CPP_MULT
))
2115 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2116 struct c_declarator
*inner
;
2117 c_parser_consume_token (parser
);
2118 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2119 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2123 return make_pointer_declarator (quals_attrs
, inner
);
2125 /* Now we have a direct declarator, direct abstract declarator or
2126 nothing (which counts as a direct abstract declarator here). */
2127 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2130 /* Parse a direct declarator or direct abstract declarator; arguments
2131 as c_parser_declarator. */
2133 static struct c_declarator
*
2134 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2137 /* The direct declarator must start with an identifier (possibly
2138 omitted) or a parenthesized declarator (possibly abstract). In
2139 an ordinary declarator, initial parentheses must start a
2140 parenthesized declarator. In an abstract declarator or parameter
2141 declarator, they could start a parenthesized declarator or a
2142 parameter list. To tell which, the open parenthesis and any
2143 following attributes must be read. If a declaration specifier
2144 follows, then it is a parameter list; if the specifier is a
2145 typedef name, there might be an ambiguity about redeclaring it,
2146 which is resolved in the direction of treating it as a typedef
2147 name. If a close parenthesis follows, it is also an empty
2148 parameter list, as the syntax does not permit empty abstract
2149 declarators. Otherwise, it is a parenthesized declarator (in
2150 which case the analysis may be repeated inside it, recursively).
2152 ??? There is an ambiguity in a parameter declaration "int
2153 (__attribute__((foo)) x)", where x is not a typedef name: it
2154 could be an abstract declarator for a function, or declare x with
2155 parentheses. The proper resolution of this ambiguity needs
2156 documenting. At present we follow an accident of the old
2157 parser's implementation, whereby the first parameter must have
2158 some declaration specifiers other than just attributes. Thus as
2159 a parameter declaration it is treated as a parenthesized
2160 parameter named x, and as an abstract declarator it is
2163 ??? Also following the old parser, attributes inside an empty
2164 parameter list are ignored, making it a list not yielding a
2165 prototype, rather than giving an error or making it have one
2166 parameter with implicit type int.
2168 ??? Also following the old parser, typedef names may be
2169 redeclared in declarators, but not Objective-C class names. */
2171 if (kind
!= C_DTR_ABSTRACT
2172 && c_parser_next_token_is (parser
, CPP_NAME
)
2174 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2175 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2177 struct c_declarator
*inner
2178 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2180 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2181 c_parser_consume_token (parser
);
2182 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2185 if (kind
!= C_DTR_NORMAL
2186 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2188 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2189 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2192 /* Either we are at the end of an abstract declarator, or we have
2195 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2198 struct c_declarator
*inner
;
2199 c_parser_consume_token (parser
);
2200 attrs
= c_parser_attributes (parser
);
2201 if (kind
!= C_DTR_NORMAL
2202 && (c_parser_next_token_starts_declspecs (parser
)
2203 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2205 struct c_arg_info
*args
2206 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2213 = build_function_declarator (args
,
2214 build_id_declarator (NULL_TREE
));
2215 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2219 /* A parenthesized declarator. */
2220 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2221 if (inner
!= NULL
&& attrs
!= NULL
)
2222 inner
= build_attrs_declarator (attrs
, inner
);
2223 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2225 c_parser_consume_token (parser
);
2229 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2233 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2240 if (kind
== C_DTR_NORMAL
)
2242 c_parser_error (parser
, "expected identifier or %<(%>");
2246 return build_id_declarator (NULL_TREE
);
2250 /* Parse part of a direct declarator or direct abstract declarator,
2251 given that some (in INNER) has already been parsed; ID_PRESENT is
2252 true if an identifier is present, false for an abstract
2255 static struct c_declarator
*
2256 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2257 struct c_declarator
*inner
)
2259 /* Parse a sequence of array declarators and parameter lists. */
2260 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2262 struct c_declarator
*declarator
;
2263 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2267 c_parser_consume_token (parser
);
2268 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2269 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2271 c_parser_consume_token (parser
);
2272 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2273 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2274 if (!quals_attrs
->declspecs_seen_p
)
2276 /* If "static" is present, there must be an array dimension.
2277 Otherwise, there may be a dimension, "*", or no
2282 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2286 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2291 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2293 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2297 c_parser_consume_token (parser
);
2302 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2308 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2311 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2312 c_parser_consume_token (parser
);
2315 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2319 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2321 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2322 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2324 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2327 struct c_arg_info
*args
;
2328 c_parser_consume_token (parser
);
2329 attrs
= c_parser_attributes (parser
);
2330 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2335 inner
= build_function_declarator (args
, inner
);
2336 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2342 /* Parse a parameter list or identifier list, including the closing
2343 parenthesis but not the opening one. ATTRS are the attributes at
2344 the start of the list. ID_LIST_OK is true if an identifier list is
2345 acceptable; such a list must not have attributes at the start. */
2347 static struct c_arg_info
*
2348 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2351 declare_parm_level ();
2352 /* If the list starts with an identifier, it is an identifier list.
2353 Otherwise, it is either a prototype list or an empty list. */
2356 && c_parser_next_token_is (parser
, CPP_NAME
)
2357 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2359 tree list
= NULL_TREE
, *nextp
= &list
;
2360 while (c_parser_next_token_is (parser
, CPP_NAME
)
2361 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2363 *nextp
= build_tree_list (NULL_TREE
,
2364 c_parser_peek_token (parser
)->value
);
2365 nextp
= & TREE_CHAIN (*nextp
);
2366 c_parser_consume_token (parser
);
2367 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2369 c_parser_consume_token (parser
);
2370 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2372 c_parser_error (parser
, "expected identifier");
2376 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2378 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2383 c_parser_consume_token (parser
);
2389 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2397 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2403 /* Parse a parameter list (possibly empty), including the closing
2404 parenthesis but not the opening one. ATTRS are the attributes at
2405 the start of the list. */
2407 static struct c_arg_info
*
2408 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2410 bool good_parm
= false;
2411 /* ??? Following the old parser, forward parameter declarations may
2412 use abstract declarators, and if no real parameter declarations
2413 follow the forward declarations then this is not diagnosed. Also
2414 note as above that attributes are ignored as the only contents of
2415 the parentheses, or as the only contents after forward
2417 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2419 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2424 c_parser_consume_token (parser
);
2427 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2429 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2433 /* Suppress -Wold-style-definition for this case. */
2434 ret
->types
= error_mark_node
;
2435 error ("ISO C requires a named argument before %<...%>");
2436 c_parser_consume_token (parser
);
2437 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2439 c_parser_consume_token (parser
);
2444 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2449 /* Nonempty list of parameters, either terminated with semicolon
2450 (forward declarations; recurse) or with close parenthesis (normal
2451 function) or with ", ... )" (variadic function). */
2454 /* Parse a parameter. */
2455 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2460 push_parm_decl (parm
);
2462 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2465 c_parser_consume_token (parser
);
2466 mark_forward_parm_decls ();
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
, false));
2759 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2760 attr_args
= NULL_TREE
;
2762 attr_args
= c_parser_expr_list (parser
, false);
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);
2881 ret
= c_parser_expr_no_commas (parser
, NULL
);
2882 if (TREE_CODE (ret
.value
) != STRING_CST
2883 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
2884 ret
= default_function_array_conversion (ret
);
2889 /* Parse a braced initializer list. TYPE is the type specified for a
2890 compound literal, and NULL_TREE for other initializers and for
2891 nested braced lists. NESTED_P is true for nested braced lists,
2892 false for the list of a compound literal or the list that is the
2893 top-level initializer in a declaration. */
2895 static struct c_expr
2896 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
2898 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
2899 c_parser_consume_token (parser
);
2901 push_init_level (0);
2903 really_start_incremental_init (type
);
2904 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2907 pedwarn ("ISO C forbids empty initializer braces");
2911 /* Parse a non-empty initializer list, possibly with a trailing
2915 c_parser_initelt (parser
);
2918 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2919 c_parser_consume_token (parser
);
2922 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2926 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
2929 ret
.value
= error_mark_node
;
2930 ret
.original_code
= ERROR_MARK
;
2931 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
2934 c_parser_consume_token (parser
);
2935 return pop_init_level (0);
2938 /* Parse a nested initializer, including designators. */
2941 c_parser_initelt (c_parser
*parser
)
2943 /* Parse any designator or designator list. A single array
2944 designator may have the subsequent "=" omitted in GNU C, but a
2945 longer list or a structure member designator may not. */
2946 if (c_parser_next_token_is (parser
, CPP_NAME
)
2947 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
2949 /* Old-style structure member designator. */
2950 set_init_label (c_parser_peek_token (parser
)->value
);
2952 pedwarn ("obsolete use of designated initializer with %<:%>");
2953 c_parser_consume_token (parser
);
2954 c_parser_consume_token (parser
);
2958 /* des_seen is 0 if there have been no designators, 1 if there
2959 has been a single array designator and 2 otherwise. */
2961 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
2962 || c_parser_next_token_is (parser
, CPP_DOT
))
2964 int des_prev
= des_seen
;
2967 if (c_parser_next_token_is (parser
, CPP_DOT
))
2970 c_parser_consume_token (parser
);
2971 if (c_parser_next_token_is (parser
, CPP_NAME
))
2973 set_init_label (c_parser_peek_token (parser
)->value
);
2974 c_parser_consume_token (parser
);
2979 init
.value
= error_mark_node
;
2980 init
.original_code
= ERROR_MARK
;
2981 c_parser_error (parser
, "expected identifier");
2982 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2983 process_init_element (init
);
2990 /* ??? Following the old parser, [ objc-receiver
2991 objc-message-args ] is accepted as an initializer,
2992 being distinguished from a designator by what follows
2993 the first assignment expression inside the square
2994 brackets, but after a first array designator a
2995 subsequent square bracket is for Objective-C taken to
2996 start an expression, using the obsolete form of
2997 designated initializer without '=', rather than
2998 possibly being a second level of designation: in LALR
2999 terms, the '[' is shifted rather than reducing
3000 designator to designator-list. */
3001 if (des_prev
== 1 && c_dialect_objc ())
3003 des_seen
= des_prev
;
3006 if (des_prev
== 0 && c_dialect_objc ())
3008 /* This might be an array designator or an
3009 Objective-C message expression. If the former,
3010 continue parsing here; if the latter, parse the
3011 remainder of the initializer given the starting
3012 primary-expression. ??? It might make sense to
3013 distinguish when des_prev == 1 as well; see
3014 previous comment. */
3016 struct c_expr mexpr
;
3017 c_parser_consume_token (parser
);
3018 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3019 && ((c_parser_peek_token (parser
)->id_kind
3021 || (c_parser_peek_token (parser
)->id_kind
3022 == C_ID_CLASSNAME
)))
3024 /* Type name receiver. */
3025 tree id
= c_parser_peek_token (parser
)->value
;
3026 c_parser_consume_token (parser
);
3027 rec
= objc_get_class_reference (id
);
3028 goto parse_message_args
;
3030 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3031 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3032 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3033 goto array_desig_after_first
;
3034 /* Expression receiver. So far only one part
3035 without commas has been parsed; there might be
3036 more of the expression. */
3038 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3041 c_parser_consume_token (parser
);
3042 next
= c_parser_expr_no_commas (parser
, NULL
);
3043 next
= default_function_array_conversion (next
);
3044 rec
= build_compound_expr (rec
, next
.value
);
3047 /* Now parse the objc-message-args. */
3048 args
= c_parser_objc_message_args (parser
);
3049 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3052 = objc_build_message_expr (build_tree_list (rec
, args
));
3053 mexpr
.original_code
= ERROR_MARK
;
3054 /* Now parse and process the remainder of the
3055 initializer, starting with this message
3056 expression as a primary-expression. */
3057 c_parser_initval (parser
, &mexpr
);
3060 c_parser_consume_token (parser
);
3061 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3062 array_desig_after_first
:
3063 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3065 c_parser_consume_token (parser
);
3066 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3070 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3072 c_parser_consume_token (parser
);
3073 set_init_index (first
, second
);
3074 if (pedantic
&& second
)
3075 pedwarn ("ISO C forbids specifying range of "
3076 "elements to initialize");
3079 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3085 if (c_parser_next_token_is (parser
, CPP_EQ
))
3087 if (pedantic
&& !flag_isoc99
)
3088 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3089 c_parser_consume_token (parser
);
3096 pedwarn ("obsolete use of designated initializer "
3102 init
.value
= error_mark_node
;
3103 init
.original_code
= ERROR_MARK
;
3104 c_parser_error (parser
, "expected %<=%>");
3105 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3106 process_init_element (init
);
3112 c_parser_initval (parser
, NULL
);
3115 /* Parse a nested initializer; as c_parser_initializer but parses
3116 initializers within braced lists, after any designators have been
3117 applied. If AFTER is not NULL then it is an Objective-C message
3118 expression which is the primary-expression starting the
3122 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3125 gcc_assert (!after
|| c_dialect_objc ());
3126 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3127 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3130 init
= c_parser_expr_no_commas (parser
, after
);
3131 if (init
.value
!= NULL_TREE
3132 && TREE_CODE (init
.value
) != STRING_CST
3133 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3134 init
= default_function_array_conversion (init
);
3136 process_init_element (init
);
3139 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3143 { block-item-list[opt] }
3144 { label-declarations block-item-list }
3148 block-item-list block-item
3160 { label-declarations block-item-list }
3163 __extension__ nested-declaration
3164 nested-function-definition
3168 label-declarations label-declaration
3171 __label__ identifier-list ;
3173 Allowing the mixing of declarations and code is new in C99. The
3174 GNU syntax also permits (not shown above) labels at the end of
3175 compound statements, which yield an error. We don't allow labels
3176 on declarations; this might seem like a natural extension, but
3177 there would be a conflict between attributes on the label and
3178 prefix attributes on the declaration. ??? The syntax follows the
3179 old parser in requiring something after label declarations.
3180 Although they are erroneous if the labels declared aren't defined,
3181 is it useful for the syntax to be this way? */
3184 c_parser_compound_statement (c_parser
*parser
)
3187 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3188 return error_mark_node
;
3189 stmt
= c_begin_compound_stmt (true);
3190 c_parser_compound_statement_nostart (parser
);
3191 return c_end_compound_stmt (stmt
, true);
3194 /* Parse a compound statement except for the opening brace. This is
3195 used for parsing both compound statements and statement expressions
3196 (which follow different paths to handling the opening). */
3199 c_parser_compound_statement_nostart (c_parser
*parser
)
3201 bool last_stmt
= false;
3202 bool last_label
= false;
3203 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3205 c_parser_consume_token (parser
);
3208 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3210 /* Read zero or more forward-declarations for labels that nested
3211 functions can jump to. */
3212 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3214 c_parser_consume_token (parser
);
3215 /* Any identifiers, including those declared as type names,
3220 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3222 c_parser_error (parser
, "expected identifier");
3226 = declare_label (c_parser_peek_token (parser
)->value
);
3227 C_DECLARED_LABEL_FLAG (label
) = 1;
3228 add_stmt (build_stmt (DECL_EXPR
, label
));
3229 c_parser_consume_token (parser
);
3230 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3231 c_parser_consume_token (parser
);
3235 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3237 /* ??? Locating this diagnostic on the token after the
3238 declarations end follows the old parser, but it might be
3239 better to locate it where the declarations start instead. */
3241 pedwarn ("ISO C forbids label declarations");
3243 /* We must now have at least one statement, label or declaration. */
3244 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3246 c_parser_error (parser
, "expected declaration or statement");
3247 c_parser_consume_token (parser
);
3250 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3252 location_t loc
= c_parser_peek_token (parser
)->location
;
3253 if (c_parser_next_token_is (parser
, CPP_EOF
))
3255 c_parser_error (parser
, "expected declaration or statement");
3258 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3259 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3260 || (c_parser_next_token_is (parser
, CPP_NAME
)
3261 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3265 c_parser_label (parser
);
3267 else if (!last_label
3268 && c_parser_next_token_starts_declspecs (parser
))
3271 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3273 && ((pedantic
&& !flag_isoc99
)
3274 || warn_declaration_after_statement
))
3275 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3279 else if (!last_label
3280 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3282 /* __extension__ can start a declaration, but is also an
3283 unary operator that can start an expression. Consume all
3284 but the last of a possible series of __extension__ to
3286 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3287 && (c_parser_peek_2nd_token (parser
)->keyword
3289 c_parser_consume_token (parser
);
3290 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3293 ext
= disable_extension_diagnostics ();
3294 c_parser_consume_token (parser
);
3296 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3297 /* Following the old parser, __extension__ does not
3298 disable this diagnostic. */
3299 restore_extension_diagnostics (ext
);
3301 && ((pedantic
&& !flag_isoc99
)
3302 || warn_declaration_after_statement
))
3303 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3315 c_parser_statement_after_labels (parser
);
3318 parser
->error
= false;
3321 error ("label at end of compound statement");
3322 c_parser_consume_token (parser
);
3325 /* Parse a label (C90 6.6.1, C99 6.8.1).
3328 identifier : attributes[opt]
3329 case constant-expression :
3335 case constant-expression ... constant-expression :
3337 The use of attributes on labels is a GNU extension. The syntax in
3338 GNU C accepts any expressions without commas, non-constant
3339 expressions being rejected later. */
3342 c_parser_label (c_parser
*parser
)
3344 location_t loc1
= c_parser_peek_token (parser
)->location
;
3345 tree label
= NULL_TREE
;
3346 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3349 c_parser_consume_token (parser
);
3350 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3351 if (c_parser_next_token_is (parser
, CPP_COLON
))
3353 c_parser_consume_token (parser
);
3354 label
= do_case (exp1
, NULL_TREE
);
3356 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3358 c_parser_consume_token (parser
);
3359 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3360 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3361 label
= do_case (exp1
, exp2
);
3364 c_parser_error (parser
, "expected %<:%> or %<...%>");
3366 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3368 c_parser_consume_token (parser
);
3369 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3370 label
= do_case (NULL_TREE
, NULL_TREE
);
3374 tree name
= c_parser_peek_token (parser
)->value
;
3378 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3379 c_parser_consume_token (parser
);
3380 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3381 loc2
= c_parser_peek_token (parser
)->location
;
3382 c_parser_consume_token (parser
);
3383 attrs
= c_parser_attributes (parser
);
3384 tlab
= define_label (loc2
, name
);
3387 decl_attributes (&tlab
, attrs
, 0);
3388 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3392 SET_EXPR_LOCATION (label
, loc1
);
3395 /* Parse a statement (C90 6.6, C99 6.8).
3400 expression-statement
3408 expression-statement:
3411 selection-statement:
3415 iteration-statement:
3424 return expression[opt] ;
3437 objc-throw-statement
3438 objc-try-catch-statement
3439 objc-synchronized-statement
3441 objc-throw-statement:
3447 c_parser_statement (c_parser
*parser
)
3449 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3450 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3451 || (c_parser_next_token_is (parser
, CPP_NAME
)
3452 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3453 c_parser_label (parser
);
3454 c_parser_statement_after_labels (parser
);
3457 /* Parse a statement, other than a labeled statement. */
3460 c_parser_statement_after_labels (c_parser
*parser
)
3462 location_t loc
= c_parser_peek_token (parser
)->location
;
3463 tree stmt
= NULL_TREE
;
3464 switch (c_parser_peek_token (parser
)->type
)
3466 case CPP_OPEN_BRACE
:
3467 add_stmt (c_parser_compound_statement (parser
));
3470 switch (c_parser_peek_token (parser
)->keyword
)
3473 c_parser_if_statement (parser
);
3476 c_parser_switch_statement (parser
);
3479 c_parser_while_statement (parser
);
3482 c_parser_do_statement (parser
);
3485 c_parser_for_statement (parser
);
3488 c_parser_consume_token (parser
);
3489 if (c_parser_next_token_is (parser
, CPP_NAME
))
3491 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3492 c_parser_consume_token (parser
);
3494 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3496 c_parser_consume_token (parser
);
3497 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3500 c_parser_error (parser
, "expected identifier or %<*%>");
3501 goto expect_semicolon
;
3503 c_parser_consume_token (parser
);
3504 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3505 goto expect_semicolon
;
3507 c_parser_consume_token (parser
);
3508 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3509 goto expect_semicolon
;
3511 c_parser_consume_token (parser
);
3512 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3514 stmt
= c_finish_return (NULL_TREE
);
3515 c_parser_consume_token (parser
);
3519 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3520 goto expect_semicolon
;
3524 stmt
= c_parser_asm_statement (parser
);
3527 gcc_assert (c_dialect_objc ());
3528 c_parser_consume_token (parser
);
3529 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3531 stmt
= objc_build_throw_stmt (NULL_TREE
);
3532 c_parser_consume_token (parser
);
3537 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3538 goto expect_semicolon
;
3542 gcc_assert (c_dialect_objc ());
3543 c_parser_objc_try_catch_statement (parser
);
3545 case RID_AT_SYNCHRONIZED
:
3546 gcc_assert (c_dialect_objc ());
3547 c_parser_objc_synchronized_statement (parser
);
3554 c_parser_consume_token (parser
);
3556 case CPP_CLOSE_PAREN
:
3557 case CPP_CLOSE_SQUARE
:
3558 /* Avoid infinite loop in error recovery:
3559 c_parser_skip_until_found stops at a closing nesting
3560 delimiter without consuming it, but here we need to consume
3561 it to proceed further. */
3562 c_parser_error (parser
, "expected statement");
3563 c_parser_consume_token (parser
);
3567 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3569 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3572 /* Two cases cannot and do not have line numbers associated: If stmt
3573 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3574 cannot hold line numbers. But that's OK because the statement
3575 will either be changed to a MODIFY_EXPR during gimplification of
3576 the statement expr, or discarded. If stmt was compound, but
3577 without new variables, we will have skipped the creation of a
3578 BIND and will have a bare STATEMENT_LIST. But that's OK because
3579 (recursively) all of the component statements should already have
3580 line numbers assigned. ??? Can we discard no-op statements
3582 if (stmt
&& EXPR_P (stmt
))
3583 SET_EXPR_LOCATION (stmt
, loc
);
3586 /* Parse a parenthesized condition from an if, do or while statement.
3592 c_parser_paren_condition (c_parser
*parser
)
3596 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3597 return error_mark_node
;
3598 loc
= c_parser_peek_token (parser
)->location
;
3599 cond
= c_objc_common_truthvalue_conversion
3600 (c_parser_expression_conv (parser
).value
);
3602 SET_EXPR_LOCATION (cond
, loc
);
3603 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3607 /* Parse a statement which is a block in C99. */
3610 c_parser_c99_block_statement (c_parser
*parser
)
3612 tree block
= c_begin_compound_stmt (flag_isoc99
);
3613 c_parser_statement (parser
);
3614 return c_end_compound_stmt (block
, flag_isoc99
);
3617 /* Parse the body of an if statement or the else half thereof. This
3618 is just parsing a statement but (a) it is a block in C99, (b) we
3619 track whether the body is an if statement for the sake of
3620 -Wparentheses warnings, (c) we handle an empty body specially for
3621 the sake of -Wextra warnings. */
3624 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3626 tree block
= c_begin_compound_stmt (flag_isoc99
);
3627 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3628 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3629 || (c_parser_next_token_is (parser
, CPP_NAME
)
3630 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3631 c_parser_label (parser
);
3632 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3633 if (extra_warnings
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3634 add_stmt (build (NOP_EXPR
, NULL_TREE
, NULL_TREE
));
3635 c_parser_statement_after_labels (parser
);
3636 return c_end_compound_stmt (block
, flag_isoc99
);
3639 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3642 if ( expression ) statement
3643 if ( expression ) statement else statement
3647 c_parser_if_statement (c_parser
*parser
)
3652 bool first_if
= false, second_if
= false;
3653 tree first_body
, second_body
;
3654 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3655 c_parser_consume_token (parser
);
3656 block
= c_begin_compound_stmt (flag_isoc99
);
3657 loc
= c_parser_peek_token (parser
)->location
;
3658 cond
= c_parser_paren_condition (parser
);
3659 first_body
= c_parser_if_body (parser
, &first_if
);
3660 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3662 c_parser_consume_token (parser
);
3663 second_body
= c_parser_if_body (parser
, &second_if
);
3666 second_body
= NULL_TREE
;
3667 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3668 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3671 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3674 switch (expression) statement
3678 c_parser_switch_statement (c_parser
*parser
)
3680 tree block
, expr
, body
, save_break
;
3681 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3682 c_parser_consume_token (parser
);
3683 block
= c_begin_compound_stmt (flag_isoc99
);
3684 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3686 expr
= c_parser_expression (parser
).value
;
3687 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3690 expr
= error_mark_node
;
3691 c_start_case (expr
);
3692 save_break
= c_break_label
;
3693 c_break_label
= NULL_TREE
;
3694 body
= c_parser_c99_block_statement (parser
);
3695 c_finish_case (body
);
3697 add_stmt (build (LABEL_EXPR
, void_type_node
, c_break_label
));
3698 c_break_label
= save_break
;
3699 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3702 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3705 while (expression) statement
3709 c_parser_while_statement (c_parser
*parser
)
3711 tree block
, cond
, body
, save_break
, save_cont
;
3713 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3714 c_parser_consume_token (parser
);
3715 block
= c_begin_compound_stmt (flag_isoc99
);
3716 loc
= c_parser_peek_token (parser
)->location
;
3717 cond
= c_parser_paren_condition (parser
);
3718 save_break
= c_break_label
;
3719 c_break_label
= NULL_TREE
;
3720 save_cont
= c_cont_label
;
3721 c_cont_label
= NULL_TREE
;
3722 body
= c_parser_c99_block_statement (parser
);
3723 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3724 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3725 c_break_label
= save_break
;
3726 c_cont_label
= save_cont
;
3729 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3732 do statement while ( expression ) ;
3736 c_parser_do_statement (c_parser
*parser
)
3738 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3740 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3741 c_parser_consume_token (parser
);
3742 block
= c_begin_compound_stmt (flag_isoc99
);
3743 loc
= c_parser_peek_token (parser
)->location
;
3744 save_break
= c_break_label
;
3745 c_break_label
= NULL_TREE
;
3746 save_cont
= c_cont_label
;
3747 c_cont_label
= NULL_TREE
;
3748 body
= c_parser_c99_block_statement (parser
);
3749 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3750 new_break
= c_break_label
;
3751 c_break_label
= save_break
;
3752 new_cont
= c_cont_label
;
3753 c_cont_label
= save_cont
;
3754 cond
= c_parser_paren_condition (parser
);
3755 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3756 c_parser_skip_to_end_of_block_or_statement (parser
);
3757 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3758 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3761 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3764 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3765 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3767 The form with a declaration is new in C99.
3769 ??? In accordance with the old parser, the declaration may be a
3770 nested function, which is then rejected in check_for_loop_decls,
3771 but does it make any sense for this to be included in the grammar?
3772 Note in particular that the nested function does not include a
3773 trailing ';', whereas the "declaration" production includes one.
3774 Also, can we reject bad declarations earlier and cheaper than
3775 check_for_loop_decls? */
3778 c_parser_for_statement (c_parser
*parser
)
3780 tree block
, cond
, incr
, save_break
, save_cont
, body
;
3782 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
3783 loc
= c_parser_peek_token (parser
)->location
;
3784 c_parser_consume_token (parser
);
3785 block
= c_begin_compound_stmt (flag_isoc99
);
3786 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3788 /* Parse the initialization declaration or expression. */
3789 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3791 c_parser_consume_token (parser
);
3792 c_finish_expr_stmt (NULL_TREE
);
3794 else if (c_parser_next_token_starts_declspecs (parser
))
3796 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3797 check_for_loop_decls ();
3799 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3801 /* __extension__ can start a declaration, but is also an
3802 unary operator that can start an expression. Consume all
3803 but the last of a possible series of __extension__ to
3805 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3806 && (c_parser_peek_2nd_token (parser
)->keyword
3808 c_parser_consume_token (parser
);
3809 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3812 ext
= disable_extension_diagnostics ();
3813 c_parser_consume_token (parser
);
3814 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3815 restore_extension_diagnostics (ext
);
3816 check_for_loop_decls ();
3824 c_finish_expr_stmt (c_parser_expression (parser
).value
);
3825 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3827 /* Parse the loop condition. */
3828 loc
= c_parser_peek_token (parser
)->location
;
3829 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3831 c_parser_consume_token (parser
);
3836 tree ocond
= c_parser_expression_conv (parser
).value
;
3837 cond
= c_objc_common_truthvalue_conversion (ocond
);
3839 SET_EXPR_LOCATION (cond
, loc
);
3840 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3842 /* Parse the increment expression. */
3843 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3844 incr
= c_process_expr_stmt (NULL_TREE
);
3846 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
3847 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3851 cond
= error_mark_node
;
3852 incr
= error_mark_node
;
3854 save_break
= c_break_label
;
3855 c_break_label
= NULL_TREE
;
3856 save_cont
= c_cont_label
;
3857 c_cont_label
= NULL_TREE
;
3858 body
= c_parser_c99_block_statement (parser
);
3859 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
3860 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3861 c_break_label
= save_break
;
3862 c_cont_label
= save_cont
;
3865 /* Parse an asm statement, a GNU extension. This is a full-blown asm
3866 statement with inputs, outputs, clobbers, and volatile tag
3870 asm type-qualifier[opt] ( asm-argument ) ;
3874 asm-string-literal : asm-operands[opt]
3875 asm-string-literal : asm-operands[opt] : asm-operands[opt]
3876 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
3878 Qualifiers other than volatile are accepted in the syntax but
3882 c_parser_asm_statement (c_parser
*parser
)
3884 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
3886 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3887 c_parser_consume_token (parser
);
3888 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
3890 quals
= c_parser_peek_token (parser
)->value
;
3891 c_parser_consume_token (parser
);
3893 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
3894 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
3896 warning (0, "%E qualifier ignored on asm",
3897 c_parser_peek_token (parser
)->value
);
3899 c_parser_consume_token (parser
);
3903 /* ??? Follow the C++ parser rather than using the
3904 c_lex_string_translate kludge. */
3905 c_lex_string_translate
= 0;
3906 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3908 c_lex_string_translate
= 1;
3911 str
= c_parser_asm_string_literal (parser
);
3912 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3915 outputs
= NULL_TREE
;
3917 clobbers
= NULL_TREE
;
3920 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3922 c_lex_string_translate
= 1;
3923 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3927 /* Parse outputs. */
3928 if (c_parser_next_token_is (parser
, CPP_COLON
)
3929 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3930 outputs
= NULL_TREE
;
3932 outputs
= c_parser_asm_operands (parser
, false);
3933 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3936 clobbers
= NULL_TREE
;
3939 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3941 c_lex_string_translate
= 1;
3942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3946 if (c_parser_next_token_is (parser
, CPP_COLON
)
3947 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3950 inputs
= c_parser_asm_operands (parser
, true);
3951 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3953 clobbers
= NULL_TREE
;
3956 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
3958 c_lex_string_translate
= 1;
3959 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3962 /* Parse clobbers. */
3963 clobbers
= c_parser_asm_clobbers (parser
);
3965 c_lex_string_translate
= 1;
3966 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3968 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3971 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3972 c_parser_skip_to_end_of_block_or_statement (parser
);
3973 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
3978 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
3979 not outputs), apply the default conversion of functions and arrays
3984 asm-operands , asm-operand
3987 asm-string-literal ( expression )
3988 [ identifier ] asm-string-literal ( expression )
3992 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
3994 tree list
= NULL_TREE
;
3999 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4001 c_parser_consume_token (parser
);
4002 if (c_parser_next_token_is (parser
, CPP_NAME
))
4004 tree id
= c_parser_peek_token (parser
)->value
;
4005 c_parser_consume_token (parser
);
4006 name
= build_string (IDENTIFIER_LENGTH (id
),
4007 IDENTIFIER_POINTER (id
));
4011 c_parser_error (parser
, "expected identifier");
4012 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4015 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4020 str
= c_parser_asm_string_literal (parser
);
4021 if (str
== NULL_TREE
)
4023 c_lex_string_translate
= 1;
4024 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4026 c_lex_string_translate
= 0;
4029 expr
= c_parser_expression (parser
);
4031 expr
= default_function_array_conversion (expr
);
4032 c_lex_string_translate
= 0;
4033 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4035 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4038 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4040 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4041 c_parser_consume_token (parser
);
4048 /* Parse asm clobbers, a GNU extension.
4052 asm-clobbers , asm-string-literal
4056 c_parser_asm_clobbers (c_parser
*parser
)
4058 tree list
= NULL_TREE
;
4061 tree str
= c_parser_asm_string_literal (parser
);
4063 list
= tree_cons (NULL_TREE
, str
, list
);
4066 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4067 c_parser_consume_token (parser
);
4074 /* Parse an expression other than a compound expression; that is, an
4075 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4076 NULL then it is an Objective-C message expression which is the
4077 primary-expression starting the expression as an initializer.
4079 assignment-expression:
4080 conditional-expression
4081 unary-expression assignment-operator assignment-expression
4083 assignment-operator: one of
4084 = *= /= %= += -= <<= >>= &= ^= |=
4086 In GNU C we accept any conditional expression on the LHS and
4087 diagnose the invalid lvalue rather than producing a syntax
4090 static struct c_expr
4091 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4093 struct c_expr lhs
, rhs
, ret
;
4094 enum tree_code code
;
4095 gcc_assert (!after
|| c_dialect_objc ());
4096 lhs
= c_parser_conditional_expression (parser
, after
);
4097 switch (c_parser_peek_token (parser
)->type
)
4106 code
= TRUNC_DIV_EXPR
;
4109 code
= TRUNC_MOD_EXPR
;
4124 code
= BIT_AND_EXPR
;
4127 code
= BIT_XOR_EXPR
;
4130 code
= BIT_IOR_EXPR
;
4135 c_parser_consume_token (parser
);
4136 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4137 rhs
= default_function_array_conversion (rhs
);
4138 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4139 if (code
== NOP_EXPR
)
4140 ret
.original_code
= MODIFY_EXPR
;
4143 TREE_NO_WARNING (ret
.value
) = 1;
4144 ret
.original_code
= ERROR_MARK
;
4149 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4150 is not NULL then it is an Objective-C message expression which is
4151 the primary-expression starting the expression as an initializer.
4153 conditional-expression:
4154 logical-OR-expression
4155 logical-OR-expression ? expression : conditional-expression
4159 conditional-expression:
4160 logical-OR-expression ? : conditional-expression
4163 static struct c_expr
4164 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4166 struct c_expr cond
, exp1
, exp2
, ret
;
4167 gcc_assert (!after
|| c_dialect_objc ());
4168 cond
= c_parser_binary_expression (parser
, after
);
4169 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4171 cond
= default_function_array_conversion (cond
);
4172 c_parser_consume_token (parser
);
4173 if (c_parser_next_token_is (parser
, CPP_COLON
))
4176 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4177 /* Make sure first operand is calculated only once. */
4178 exp1
.value
= save_expr (default_conversion (cond
.value
));
4179 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4180 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4185 = c_objc_common_truthvalue_conversion
4186 (default_conversion (cond
.value
));
4187 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4188 exp1
= c_parser_expression_conv (parser
);
4189 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4190 - (cond
.value
== truthvalue_false_node
));
4192 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4194 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4195 ret
.value
= error_mark_node
;
4196 ret
.original_code
= ERROR_MARK
;
4199 exp2
= c_parser_conditional_expression (parser
, NULL
);
4200 exp2
= default_function_array_conversion (exp2
);
4201 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4202 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4203 ret
.original_code
= ERROR_MARK
;
4207 /* Parse a binary expression; that is, a logical-OR-expression (C90
4208 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4209 an Objective-C message expression which is the primary-expression
4210 starting the expression as an initializer.
4212 multiplicative-expression:
4214 multiplicative-expression * cast-expression
4215 multiplicative-expression / cast-expression
4216 multiplicative-expression % cast-expression
4218 additive-expression:
4219 multiplicative-expression
4220 additive-expression + multiplicative-expression
4221 additive-expression - multiplicative-expression
4225 shift-expression << additive-expression
4226 shift-expression >> additive-expression
4228 relational-expression:
4230 relational-expression < shift-expression
4231 relational-expression > shift-expression
4232 relational-expression <= shift-expression
4233 relational-expression >= shift-expression
4235 equality-expression:
4236 relational-expression
4237 equality-expression == relational-expression
4238 equality-expression != relational-expression
4242 AND-expression & equality-expression
4244 exclusive-OR-expression:
4246 exclusive-OR-expression ^ AND-expression
4248 inclusive-OR-expression:
4249 exclusive-OR-expression
4250 inclusive-OR-expression | exclusive-OR-expression
4252 logical-AND-expression:
4253 inclusive-OR-expression
4254 logical-AND-expression && inclusive-OR-expression
4256 logical-OR-expression:
4257 logical-AND-expression
4258 logical-OR-expression || logical-AND-expression
4261 static struct c_expr
4262 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4264 /* A binary expression is parsed using operator-precedence parsing,
4265 with the operands being cast expressions. All the binary
4266 operators are left-associative. Thus a binary expression is of
4269 E0 op1 E1 op2 E2 ...
4271 which we represent on a stack. On the stack, the precedence
4272 levels are strictly increasing. When a new operator is
4273 encountered of higher precedence than that at the top of the
4274 stack, it is pushed; its LHS is the top expression, and its RHS
4275 is everything parsed until it is popped. When a new operator is
4276 encountered with precedence less than or equal to that at the top
4277 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4278 by the result of the operation until the operator at the top of
4279 the stack has lower precedence than the new operator or there is
4280 only one element on the stack; then the top expression is the LHS
4281 of the new operator. In the case of logical AND and OR
4282 expressions, we also need to adjust skip_evaluation as
4283 appropriate when the operators are pushed and popped. */
4285 /* The precedence levels, where 0 is a dummy lowest level used for
4286 the bottom of the stack. */
4302 /* The expression at this stack level. */
4304 /* The precedence of the operator on its left, PREC_NONE at the
4305 bottom of the stack. */
4307 /* The operation on its left. */
4313 switch (stack[sp].op) \
4315 case TRUTH_ANDIF_EXPR: \
4316 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4318 case TRUTH_ORIF_EXPR: \
4319 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4324 stack[sp - 1].expr \
4325 = default_function_array_conversion (stack[sp - 1].expr); \
4327 = default_function_array_conversion (stack[sp].expr); \
4328 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4329 stack[sp - 1].expr, \
4333 gcc_assert (!after
|| c_dialect_objc ());
4334 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4335 stack
[0].prec
= PREC_NONE
;
4340 enum tree_code ocode
;
4343 switch (c_parser_peek_token (parser
)->type
)
4351 ocode
= TRUNC_DIV_EXPR
;
4355 ocode
= TRUNC_MOD_EXPR
;
4367 ocode
= LSHIFT_EXPR
;
4371 ocode
= RSHIFT_EXPR
;
4385 case CPP_GREATER_EQ
:
4398 oprec
= PREC_BITAND
;
4399 ocode
= BIT_AND_EXPR
;
4402 oprec
= PREC_BITXOR
;
4403 ocode
= BIT_XOR_EXPR
;
4407 ocode
= BIT_IOR_EXPR
;
4410 oprec
= PREC_LOGAND
;
4411 ocode
= TRUTH_ANDIF_EXPR
;
4415 ocode
= TRUTH_ORIF_EXPR
;
4418 /* Not a binary operator, so end of the binary
4422 c_parser_consume_token (parser
);
4423 while (oprec
<= stack
[sp
].prec
)
4427 case TRUTH_ANDIF_EXPR
:
4429 = default_function_array_conversion (stack
[sp
].expr
);
4430 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4431 (default_conversion (stack
[sp
].expr
.value
));
4432 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4434 case TRUTH_ORIF_EXPR
:
4436 = default_function_array_conversion (stack
[sp
].expr
);
4437 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4438 (default_conversion (stack
[sp
].expr
.value
));
4439 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4445 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4446 stack
[sp
].prec
= oprec
;
4447 stack
[sp
].op
= ocode
;
4452 return stack
[0].expr
;
4456 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4457 NULL then it is an Objective-C message expression which is the
4458 primary-expression starting the expression as an initializer.
4462 ( type-name ) unary-expression
4465 static struct c_expr
4466 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4468 gcc_assert (!after
|| c_dialect_objc ());
4470 return c_parser_postfix_expression_after_primary (parser
, *after
);
4471 /* If the expression begins with a parenthesized type name, it may
4472 be either a cast or a compound literal; we need to see whether
4473 the next character is '{' to tell the difference. If not, it is
4474 an unary expression. */
4475 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4476 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4478 struct c_type_name
*type_name
;
4481 c_parser_consume_token (parser
);
4482 type_name
= c_parser_type_name (parser
);
4483 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4484 if (type_name
== NULL
)
4486 ret
.value
= error_mark_node
;
4487 ret
.original_code
= ERROR_MARK
;
4490 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4491 return c_parser_postfix_expression_after_paren_type (parser
,
4493 expr
= c_parser_cast_expression (parser
, NULL
);
4494 expr
= default_function_array_conversion (expr
);
4495 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4496 ret
.original_code
= ERROR_MARK
;
4500 return c_parser_unary_expression (parser
);
4503 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4509 unary-operator cast-expression
4510 sizeof unary-expression
4511 sizeof ( type-name )
4513 unary-operator: one of
4519 __alignof__ unary-expression
4520 __alignof__ ( type-name )
4523 unary-operator: one of
4524 __extension__ __real__ __imag__
4526 In addition, the GNU syntax treats ++ and -- as unary operators, so
4527 they may be applied to cast expressions with errors for non-lvalues
4530 static struct c_expr
4531 c_parser_unary_expression (c_parser
*parser
)
4534 struct c_expr ret
, op
;
4535 switch (c_parser_peek_token (parser
)->type
)
4538 c_parser_consume_token (parser
);
4539 op
= c_parser_cast_expression (parser
, NULL
);
4540 op
= default_function_array_conversion (op
);
4541 return parser_build_unary_op (PREINCREMENT_EXPR
, op
);
4542 case CPP_MINUS_MINUS
:
4543 c_parser_consume_token (parser
);
4544 op
= c_parser_cast_expression (parser
, NULL
);
4545 op
= default_function_array_conversion (op
);
4546 return parser_build_unary_op (PREDECREMENT_EXPR
, op
);
4548 c_parser_consume_token (parser
);
4549 return parser_build_unary_op (ADDR_EXPR
,
4550 c_parser_cast_expression (parser
, NULL
));
4552 c_parser_consume_token (parser
);
4553 op
= c_parser_cast_expression (parser
, NULL
);
4554 op
= default_function_array_conversion (op
);
4555 ret
.value
= build_indirect_ref (op
.value
, "unary *");
4556 ret
.original_code
= ERROR_MARK
;
4559 c_parser_consume_token (parser
);
4560 if (!c_dialect_objc () && !in_system_header
)
4561 warning (OPT_Wtraditional
,
4562 "traditional C rejects the unary plus operator");
4563 op
= c_parser_cast_expression (parser
, NULL
);
4564 op
= default_function_array_conversion (op
);
4565 return parser_build_unary_op (CONVERT_EXPR
, op
);
4567 c_parser_consume_token (parser
);
4568 op
= c_parser_cast_expression (parser
, NULL
);
4569 op
= default_function_array_conversion (op
);
4570 return parser_build_unary_op (NEGATE_EXPR
, op
);
4572 c_parser_consume_token (parser
);
4573 op
= c_parser_cast_expression (parser
, NULL
);
4574 op
= default_function_array_conversion (op
);
4575 return parser_build_unary_op (BIT_NOT_EXPR
, op
);
4577 c_parser_consume_token (parser
);
4578 op
= c_parser_cast_expression (parser
, NULL
);
4579 op
= default_function_array_conversion (op
);
4580 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
);
4582 /* Refer to the address of a label as a pointer. */
4583 c_parser_consume_token (parser
);
4584 if (c_parser_next_token_is (parser
, CPP_NAME
))
4586 ret
.value
= finish_label_address_expr
4587 (c_parser_peek_token (parser
)->value
);
4588 c_parser_consume_token (parser
);
4592 c_parser_error (parser
, "expected identifier");
4593 ret
.value
= error_mark_node
;
4595 ret
.original_code
= ERROR_MARK
;
4598 switch (c_parser_peek_token (parser
)->keyword
)
4601 return c_parser_sizeof_expression (parser
);
4603 return c_parser_alignof_expression (parser
);
4605 c_parser_consume_token (parser
);
4606 ext
= disable_extension_diagnostics ();
4607 ret
= c_parser_cast_expression (parser
, NULL
);
4608 restore_extension_diagnostics (ext
);
4611 c_parser_consume_token (parser
);
4612 op
= c_parser_cast_expression (parser
, NULL
);
4613 op
= default_function_array_conversion (op
);
4614 return parser_build_unary_op (REALPART_EXPR
, op
);
4616 c_parser_consume_token (parser
);
4617 op
= c_parser_cast_expression (parser
, NULL
);
4618 op
= default_function_array_conversion (op
);
4619 return parser_build_unary_op (IMAGPART_EXPR
, op
);
4621 return c_parser_postfix_expression (parser
);
4624 return c_parser_postfix_expression (parser
);
4628 /* Parse a sizeof expression. */
4630 static struct c_expr
4631 c_parser_sizeof_expression (c_parser
*parser
)
4634 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4635 c_parser_consume_token (parser
);
4638 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4639 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4641 /* Either sizeof ( type-name ) or sizeof unary-expression
4642 starting with a compound literal. */
4643 struct c_type_name
*type_name
;
4644 c_parser_consume_token (parser
);
4645 type_name
= c_parser_type_name (parser
);
4646 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4647 if (type_name
== NULL
)
4652 ret
.value
= error_mark_node
;
4653 ret
.original_code
= ERROR_MARK
;
4656 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4658 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4662 /* sizeof ( type-name ). */
4665 return c_expr_sizeof_type (type_name
);
4669 expr
= c_parser_unary_expression (parser
);
4673 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4674 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4675 error ("%<sizeof%> applied to a bit-field");
4676 return c_expr_sizeof_expr (expr
);
4680 /* Parse an alignof expression. */
4682 static struct c_expr
4683 c_parser_alignof_expression (c_parser
*parser
)
4686 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4687 c_parser_consume_token (parser
);
4690 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4691 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4693 /* Either __alignof__ ( type-name ) or __alignof__
4694 unary-expression starting with a compound literal. */
4695 struct c_type_name
*type_name
;
4697 c_parser_consume_token (parser
);
4698 type_name
= c_parser_type_name (parser
);
4699 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4700 if (type_name
== NULL
)
4705 ret
.value
= error_mark_node
;
4706 ret
.original_code
= ERROR_MARK
;
4709 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4711 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4715 /* alignof ( type-name ). */
4718 ret
.value
= c_alignof (groktypename (type_name
));
4719 ret
.original_code
= ERROR_MARK
;
4725 expr
= c_parser_unary_expression (parser
);
4729 ret
.value
= c_alignof_expr (expr
.value
);
4730 ret
.original_code
= ERROR_MARK
;
4735 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4739 postfix-expression [ expression ]
4740 postfix-expression ( argument-expression-list[opt] )
4741 postfix-expression . identifier
4742 postfix-expression -> identifier
4743 postfix-expression ++
4744 postfix-expression --
4745 ( type-name ) { initializer-list }
4746 ( type-name ) { initializer-list , }
4748 argument-expression-list:
4750 argument-expression-list , argument-expression
4762 (treated as a keyword in GNU C)
4765 ( compound-statement )
4766 __builtin_va_arg ( assignment-expression , type-name )
4767 __builtin_offsetof ( type-name , offsetof-member-designator )
4768 __builtin_choose_expr ( assignment-expression ,
4769 assignment-expression ,
4770 assignment-expression )
4771 __builtin_types_compatible_p ( type-name , type-name )
4773 offsetof-member-designator:
4775 offsetof-member-designator . identifier
4776 offsetof-member-designator [ expression ]
4781 [ objc-receiver objc-message-args ]
4782 @selector ( objc-selector-arg )
4783 @protocol ( identifier )
4784 @encode ( type-name )
4788 static struct c_expr
4789 c_parser_postfix_expression (c_parser
*parser
)
4791 struct c_expr expr
, e1
, e2
, e3
;
4792 struct c_type_name
*t1
, *t2
;
4793 switch (c_parser_peek_token (parser
)->type
)
4798 expr
.value
= c_parser_peek_token (parser
)->value
;
4799 expr
.original_code
= ERROR_MARK
;
4800 c_parser_consume_token (parser
);
4804 expr
.value
= c_parser_peek_token (parser
)->value
;
4805 expr
.original_code
= STRING_CST
;
4806 c_parser_consume_token (parser
);
4808 case CPP_OBJC_STRING
:
4809 gcc_assert (c_dialect_objc ());
4811 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
4812 expr
.original_code
= ERROR_MARK
;
4813 c_parser_consume_token (parser
);
4816 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
4818 c_parser_error (parser
, "expected expression");
4819 expr
.value
= error_mark_node
;
4820 expr
.original_code
= ERROR_MARK
;
4824 tree id
= c_parser_peek_token (parser
)->value
;
4825 location_t loc
= c_parser_peek_token (parser
)->location
;
4826 c_parser_consume_token (parser
);
4827 expr
.value
= build_external_ref (id
,
4828 (c_parser_peek_token (parser
)->type
4829 == CPP_OPEN_PAREN
), loc
);
4830 expr
.original_code
= ERROR_MARK
;
4833 case CPP_OPEN_PAREN
:
4834 /* A parenthesized expression, statement expression or compound
4836 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
4838 /* A statement expression. */
4840 c_parser_consume_token (parser
);
4841 c_parser_consume_token (parser
);
4842 if (cur_stmt_list
== NULL
)
4844 error ("braced-group within expression allowed "
4845 "only inside a function");
4846 parser
->error
= true;
4847 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
4848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4849 expr
.value
= error_mark_node
;
4850 expr
.original_code
= ERROR_MARK
;
4853 stmt
= c_begin_stmt_expr ();
4854 c_parser_compound_statement_nostart (parser
);
4855 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4858 pedwarn ("ISO C forbids braced-groups within expressions");
4859 expr
.value
= c_finish_stmt_expr (stmt
);
4860 expr
.original_code
= ERROR_MARK
;
4862 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4864 /* A compound literal. ??? Can we actually get here rather
4865 than going directly to
4866 c_parser_postfix_expression_after_paren_type from
4868 struct c_type_name
*type_name
;
4869 c_parser_consume_token (parser
);
4870 type_name
= c_parser_type_name (parser
);
4871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4873 if (type_name
== NULL
)
4875 expr
.value
= error_mark_node
;
4876 expr
.original_code
= ERROR_MARK
;
4879 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4884 /* A parenthesized expression. */
4885 c_parser_consume_token (parser
);
4886 expr
= c_parser_expression (parser
);
4887 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
4888 TREE_NO_WARNING (expr
.value
) = 1;
4889 expr
.original_code
= ERROR_MARK
;
4890 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4895 switch (c_parser_peek_token (parser
)->keyword
)
4897 case RID_FUNCTION_NAME
:
4898 case RID_PRETTY_FUNCTION_NAME
:
4899 case RID_C99_FUNCTION_NAME
:
4900 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
4901 c_parser_peek_token (parser
)->value
);
4902 expr
.original_code
= ERROR_MARK
;
4903 c_parser_consume_token (parser
);
4906 c_parser_consume_token (parser
);
4907 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4909 expr
.value
= error_mark_node
;
4910 expr
.original_code
= ERROR_MARK
;
4913 e1
= c_parser_expr_no_commas (parser
, NULL
);
4914 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4916 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4917 expr
.value
= error_mark_node
;
4918 expr
.original_code
= ERROR_MARK
;
4921 t1
= c_parser_type_name (parser
);
4922 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4926 expr
.value
= error_mark_node
;
4927 expr
.original_code
= ERROR_MARK
;
4931 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
4932 expr
.original_code
= ERROR_MARK
;
4936 c_parser_consume_token (parser
);
4937 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4939 expr
.value
= error_mark_node
;
4940 expr
.original_code
= ERROR_MARK
;
4943 t1
= c_parser_type_name (parser
);
4946 expr
.value
= error_mark_node
;
4947 expr
.original_code
= ERROR_MARK
;
4950 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
4952 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4953 expr
.value
= error_mark_node
;
4954 expr
.original_code
= ERROR_MARK
;
4958 tree type
= groktypename (t1
);
4960 if (type
== error_mark_node
)
4961 offsetof_ref
= error_mark_node
;
4963 offsetof_ref
= build1 (INDIRECT_REF
, type
, NULL
);
4964 /* Parse the second argument to __builtin_offsetof. We
4965 must have one identifier, and beyond that we want to
4966 accept sub structure and sub array references. */
4967 if (c_parser_next_token_is (parser
, CPP_NAME
))
4969 offsetof_ref
= build_component_ref
4970 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
4971 c_parser_consume_token (parser
);
4972 while (c_parser_next_token_is (parser
, CPP_DOT
)
4973 || c_parser_next_token_is (parser
,
4976 if (c_parser_next_token_is (parser
, CPP_DOT
))
4978 c_parser_consume_token (parser
);
4979 if (c_parser_next_token_is_not (parser
,
4982 c_parser_error (parser
, "expected identifier");
4985 offsetof_ref
= build_component_ref
4987 c_parser_peek_token (parser
)->value
);
4988 c_parser_consume_token (parser
);
4993 c_parser_consume_token (parser
);
4994 idx
= c_parser_expression (parser
).value
;
4995 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4997 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
5002 c_parser_error (parser
, "expected identifier");
5003 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5005 expr
.value
= fold_offsetof (offsetof_ref
);
5006 expr
.original_code
= ERROR_MARK
;
5009 case RID_CHOOSE_EXPR
:
5010 c_parser_consume_token (parser
);
5011 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5013 expr
.value
= error_mark_node
;
5014 expr
.original_code
= ERROR_MARK
;
5017 e1
= c_parser_expr_no_commas (parser
, NULL
);
5018 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5020 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5021 expr
.value
= error_mark_node
;
5022 expr
.original_code
= ERROR_MARK
;
5025 e2
= c_parser_expr_no_commas (parser
, NULL
);
5026 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5028 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5029 expr
.value
= error_mark_node
;
5030 expr
.original_code
= ERROR_MARK
;
5033 e3
= c_parser_expr_no_commas (parser
, NULL
);
5034 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5039 c
= fold (e1
.value
);
5040 if (TREE_CODE (c
) != INTEGER_CST
)
5041 error ("first argument to %<__builtin_choose_expr%> not"
5043 expr
= integer_zerop (c
) ? e3
: e2
;
5046 case RID_TYPES_COMPATIBLE_P
:
5047 c_parser_consume_token (parser
);
5048 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5050 expr
.value
= error_mark_node
;
5051 expr
.original_code
= ERROR_MARK
;
5054 t1
= c_parser_type_name (parser
);
5057 expr
.value
= error_mark_node
;
5058 expr
.original_code
= ERROR_MARK
;
5061 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5063 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5064 expr
.value
= error_mark_node
;
5065 expr
.original_code
= ERROR_MARK
;
5068 t2
= c_parser_type_name (parser
);
5071 expr
.value
= error_mark_node
;
5072 expr
.original_code
= ERROR_MARK
;
5075 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5080 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5081 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5083 expr
.value
= comptypes (e1
, e2
)
5084 ? build_int_cst (NULL_TREE
, 1)
5085 : build_int_cst (NULL_TREE
, 0);
5086 expr
.original_code
= ERROR_MARK
;
5089 case RID_AT_SELECTOR
:
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
;
5099 tree sel
= c_parser_objc_selector_arg (parser
);
5100 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5102 expr
.value
= objc_build_selector_expr (sel
);
5103 expr
.original_code
= ERROR_MARK
;
5106 case RID_AT_PROTOCOL
:
5107 gcc_assert (c_dialect_objc ());
5108 c_parser_consume_token (parser
);
5109 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5111 expr
.value
= error_mark_node
;
5112 expr
.original_code
= ERROR_MARK
;
5115 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5117 c_parser_error (parser
, "expected identifier");
5118 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5119 expr
.value
= error_mark_node
;
5120 expr
.original_code
= ERROR_MARK
;
5124 tree id
= c_parser_peek_token (parser
)->value
;
5125 c_parser_consume_token (parser
);
5126 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5128 expr
.value
= objc_build_protocol_expr (id
);
5129 expr
.original_code
= ERROR_MARK
;
5133 /* Extension to support C-structures in the archiver. */
5134 gcc_assert (c_dialect_objc ());
5135 c_parser_consume_token (parser
);
5136 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5138 expr
.value
= error_mark_node
;
5139 expr
.original_code
= ERROR_MARK
;
5142 t1
= c_parser_type_name (parser
);
5145 expr
.value
= error_mark_node
;
5146 expr
.original_code
= ERROR_MARK
;
5147 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5150 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5153 tree type
= groktypename (t1
);
5154 expr
.value
= objc_build_encode_expr (type
);
5155 expr
.original_code
= ERROR_MARK
;
5159 c_parser_error (parser
, "expected expression");
5160 expr
.value
= error_mark_node
;
5161 expr
.original_code
= ERROR_MARK
;
5165 case CPP_OPEN_SQUARE
:
5166 if (c_dialect_objc ())
5168 tree receiver
, args
;
5169 c_parser_consume_token (parser
);
5170 receiver
= c_parser_objc_receiver (parser
);
5171 args
= c_parser_objc_message_args (parser
);
5172 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5174 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5176 expr
.original_code
= ERROR_MARK
;
5179 /* Else fall through to report error. */
5181 c_parser_error (parser
, "expected expression");
5182 expr
.value
= error_mark_node
;
5183 expr
.original_code
= ERROR_MARK
;
5186 return c_parser_postfix_expression_after_primary (parser
, expr
);
5189 /* Parse a postfix expression after a parenthesized type name: the
5190 brace-enclosed initializer of a compound literal, possibly followed
5191 by some postfix operators. This is separate because it is not
5192 possible to tell until after the type name whether a cast
5193 expression has a cast or a compound literal, or whether the operand
5194 of sizeof is a parenthesized type name or starts with a compound
5197 static struct c_expr
5198 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5199 struct c_type_name
*type_name
)
5204 start_init (NULL_TREE
, NULL
, 0);
5205 type
= groktypename (type_name
);
5206 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5208 error ("compound literal has variable size");
5209 type
= error_mark_node
;
5211 init
= c_parser_braced_init (parser
, type
, false);
5213 maybe_warn_string_init (type
, init
);
5215 if (pedantic
&& !flag_isoc99
)
5216 pedwarn ("ISO C90 forbids compound literals");
5217 expr
.value
= build_compound_literal (type
, init
.value
);
5218 expr
.original_code
= ERROR_MARK
;
5219 return c_parser_postfix_expression_after_primary (parser
, expr
);
5222 /* Parse a postfix expression after the initial primary or compound
5223 literal; that is, parse a series of postfix operators. */
5225 static struct c_expr
5226 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5229 tree ident
, idx
, exprlist
;
5232 switch (c_parser_peek_token (parser
)->type
)
5234 case CPP_OPEN_SQUARE
:
5235 /* Array reference. */
5236 c_parser_consume_token (parser
);
5237 idx
= c_parser_expression (parser
).value
;
5238 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5240 expr
.value
= build_array_ref (expr
.value
, idx
);
5241 expr
.original_code
= ERROR_MARK
;
5243 case CPP_OPEN_PAREN
:
5244 /* Function call. */
5245 c_parser_consume_token (parser
);
5246 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5247 exprlist
= NULL_TREE
;
5249 exprlist
= c_parser_expr_list (parser
, true);
5250 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5252 expr
.value
= build_function_call (expr
.value
, exprlist
);
5253 expr
.original_code
= ERROR_MARK
;
5256 /* Structure element reference. */
5257 c_parser_consume_token (parser
);
5258 expr
= default_function_array_conversion (expr
);
5259 if (c_parser_next_token_is (parser
, CPP_NAME
))
5260 ident
= c_parser_peek_token (parser
)->value
;
5263 c_parser_error (parser
, "expected identifier");
5264 expr
.value
= error_mark_node
;
5265 expr
.original_code
= ERROR_MARK
;
5268 c_parser_consume_token (parser
);
5269 expr
.value
= build_component_ref (expr
.value
, ident
);
5270 expr
.original_code
= ERROR_MARK
;
5273 /* Structure element reference. */
5274 c_parser_consume_token (parser
);
5275 expr
= default_function_array_conversion (expr
);
5276 if (c_parser_next_token_is (parser
, CPP_NAME
))
5277 ident
= c_parser_peek_token (parser
)->value
;
5280 c_parser_error (parser
, "expected identifier");
5281 expr
.value
= error_mark_node
;
5282 expr
.original_code
= ERROR_MARK
;
5285 c_parser_consume_token (parser
);
5286 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5288 expr
.original_code
= ERROR_MARK
;
5291 /* Postincrement. */
5292 c_parser_consume_token (parser
);
5293 expr
= default_function_array_conversion (expr
);
5294 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5295 expr
.original_code
= ERROR_MARK
;
5297 case CPP_MINUS_MINUS
:
5298 /* Postdecrement. */
5299 c_parser_consume_token (parser
);
5300 expr
= default_function_array_conversion (expr
);
5301 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5302 expr
.original_code
= ERROR_MARK
;
5310 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5313 assignment-expression
5314 expression , assignment-expression
5317 static struct c_expr
5318 c_parser_expression (c_parser
*parser
)
5321 expr
= c_parser_expr_no_commas (parser
, NULL
);
5322 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5325 c_parser_consume_token (parser
);
5326 next
= c_parser_expr_no_commas (parser
, NULL
);
5327 next
= default_function_array_conversion (next
);
5328 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5329 expr
.original_code
= COMPOUND_EXPR
;
5334 /* Parse an expression and convert functions or arrays to
5337 static struct c_expr
5338 c_parser_expression_conv (c_parser
*parser
)
5341 expr
= c_parser_expression (parser
);
5342 expr
= default_function_array_conversion (expr
);
5346 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5347 functions and arrays to pointers.
5350 assignment-expression
5351 nonempty-expr-list , assignment-expression
5355 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5359 expr
= c_parser_expr_no_commas (parser
, NULL
);
5361 expr
= default_function_array_conversion (expr
);
5362 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5363 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5365 c_parser_consume_token (parser
);
5366 expr
= c_parser_expr_no_commas (parser
, NULL
);
5368 expr
= default_function_array_conversion (expr
);
5369 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5375 /* Parse Objective-C-specific constructs. */
5377 /* Parse an objc-class-definition.
5379 objc-class-definition:
5380 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5381 objc-class-instance-variables[opt] objc-methodprotolist @end
5382 @implementation identifier objc-superclass[opt]
5383 objc-class-instance-variables[opt]
5384 @interface identifier ( identifier ) objc-protocol-refs[opt]
5385 objc-methodprotolist @end
5386 @implementation identifier ( identifier )
5391 "@interface identifier (" must start "@interface identifier (
5392 identifier ) ...": objc-methodprotolist in the first production may
5393 not start with a parenthesized identifier as a declarator of a data
5394 definition with no declaration specifiers if the objc-superclass,
5395 objc-protocol-refs and objc-class-instance-variables are omitted. */
5398 c_parser_objc_class_definition (c_parser
*parser
)
5403 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5405 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5409 c_parser_consume_token (parser
);
5410 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5412 c_parser_error (parser
, "expected identifier");
5415 id1
= c_parser_peek_token (parser
)->value
;
5416 c_parser_consume_token (parser
);
5417 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5420 tree proto
= NULL_TREE
;
5421 c_parser_consume_token (parser
);
5422 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5424 c_parser_error (parser
, "expected identifier");
5425 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5428 id2
= c_parser_peek_token (parser
)->value
;
5429 c_parser_consume_token (parser
);
5430 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5433 objc_start_category_implementation (id1
, id2
);
5436 if (c_parser_next_token_is (parser
, CPP_LESS
))
5437 proto
= c_parser_objc_protocol_refs (parser
);
5438 objc_start_category_interface (id1
, id2
, proto
);
5439 c_parser_objc_methodprotolist (parser
);
5440 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5441 objc_finish_interface ();
5444 if (c_parser_next_token_is (parser
, CPP_COLON
))
5446 c_parser_consume_token (parser
);
5447 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5449 c_parser_error (parser
, "expected identifier");
5452 superclass
= c_parser_peek_token (parser
)->value
;
5453 c_parser_consume_token (parser
);
5456 superclass
= NULL_TREE
;
5459 tree proto
= NULL_TREE
;
5460 if (c_parser_next_token_is (parser
, CPP_LESS
))
5461 proto
= c_parser_objc_protocol_refs (parser
);
5462 objc_start_class_interface (id1
, superclass
, proto
);
5465 objc_start_class_implementation (id1
, superclass
);
5466 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5467 c_parser_objc_class_instance_variables (parser
);
5470 objc_continue_interface ();
5471 c_parser_objc_methodprotolist (parser
);
5472 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5473 objc_finish_interface ();
5477 objc_continue_implementation ();
5482 /* Parse objc-class-instance-variables.
5484 objc-class-instance-variables:
5485 { objc-instance-variable-decl-list[opt] }
5487 objc-instance-variable-decl-list:
5488 objc-visibility-spec
5489 objc-instance-variable-decl ;
5491 objc-instance-variable-decl-list objc-visibility-spec
5492 objc-instance-variable-decl-list objc-instance-variable-decl ;
5493 objc-instance-variable-decl-list ;
5495 objc-visibility-spec:
5500 objc-instance-variable-decl:
5505 c_parser_objc_class_instance_variables (c_parser
*parser
)
5507 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5508 c_parser_consume_token (parser
);
5509 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5512 /* Parse any stray semicolon. */
5513 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5516 pedwarn ("extra semicolon in struct or union specified");
5517 c_parser_consume_token (parser
);
5520 /* Stop if at the end of the instance variables. */
5521 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5523 c_parser_consume_token (parser
);
5526 /* Parse any objc-visibility-spec. */
5527 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5529 c_parser_consume_token (parser
);
5530 objc_set_visibility (2);
5533 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5535 c_parser_consume_token (parser
);
5536 objc_set_visibility (0);
5539 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5541 c_parser_consume_token (parser
);
5542 objc_set_visibility (1);
5545 /* Parse some comma-separated declarations. */
5546 decls
= c_parser_struct_declaration (parser
);
5548 /* Comma-separated instance variables are chained together in
5549 reverse order; add them one by one. */
5550 tree ivar
= nreverse (decls
);
5551 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5552 objc_add_instance_variable (copy_node (ivar
));
5554 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5558 /* Parse an objc-class-declaration.
5560 objc-class-declaration:
5561 @class identifier-list ;
5565 c_parser_objc_class_declaration (c_parser
*parser
)
5567 tree list
= NULL_TREE
;
5568 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5569 c_parser_consume_token (parser
);
5570 /* Any identifiers, including those declared as type names, are OK
5575 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5577 c_parser_error (parser
, "expected identifier");
5580 id
= c_parser_peek_token (parser
)->value
;
5581 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5582 c_parser_consume_token (parser
);
5583 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5584 c_parser_consume_token (parser
);
5588 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5589 objc_declare_class (list
);
5592 /* Parse an objc-alias-declaration.
5594 objc-alias-declaration:
5595 @compatibility_alias identifier identifier ;
5599 c_parser_objc_alias_declaration (c_parser
*parser
)
5602 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5603 c_parser_consume_token (parser
);
5604 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5606 c_parser_error (parser
, "expected identifier");
5607 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5610 id1
= c_parser_peek_token (parser
)->value
;
5611 c_parser_consume_token (parser
);
5612 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5614 c_parser_error (parser
, "expected identifier");
5615 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5618 id2
= c_parser_peek_token (parser
)->value
;
5619 c_parser_consume_token (parser
);
5620 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5621 objc_declare_alias (id1
, id2
);
5624 /* Parse an objc-protocol-definition.
5626 objc-protocol-definition:
5627 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5628 @protocol identifier-list ;
5630 "@protocol identifier ;" should be resolved as "@protocol
5631 identifier-list ;": objc-methodprotolist may not start with a
5632 semicolon in the first alternative if objc-protocol-refs are
5636 c_parser_objc_protocol_definition (c_parser
*parser
)
5638 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5639 c_parser_consume_token (parser
);
5640 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5642 c_parser_error (parser
, "expected identifier");
5645 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5646 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5648 tree list
= NULL_TREE
;
5649 /* Any identifiers, including those declared as type names, are
5654 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5656 c_parser_error (parser
, "expected identifier");
5659 id
= c_parser_peek_token (parser
)->value
;
5660 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5661 c_parser_consume_token (parser
);
5662 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5663 c_parser_consume_token (parser
);
5667 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5668 objc_declare_protocols (list
);
5672 tree id
= c_parser_peek_token (parser
)->value
;
5673 tree proto
= NULL_TREE
;
5674 c_parser_consume_token (parser
);
5675 if (c_parser_next_token_is (parser
, CPP_LESS
))
5676 proto
= c_parser_objc_protocol_refs (parser
);
5677 objc_pq_context
= 1;
5678 objc_start_protocol (id
, proto
);
5679 c_parser_objc_methodprotolist (parser
);
5680 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5681 objc_pq_context
= 0;
5682 objc_finish_interface ();
5686 /* Parse an objc-method-type.
5693 static enum tree_code
5694 c_parser_objc_method_type (c_parser
*parser
)
5696 switch (c_parser_peek_token (parser
)->type
)
5699 c_parser_consume_token (parser
);
5702 c_parser_consume_token (parser
);
5709 /* Parse an objc-method-definition.
5711 objc-method-definition:
5712 objc-method-type objc-method-decl ;[opt] compound-statement
5716 c_parser_objc_method_definition (c_parser
*parser
)
5718 enum tree_code type
= c_parser_objc_method_type (parser
);
5720 objc_set_method_type (type
);
5721 objc_pq_context
= 1;
5722 decl
= c_parser_objc_method_decl (parser
);
5723 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5725 c_parser_consume_token (parser
);
5727 pedwarn ("extra semicolon in method definition specified");
5729 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5731 c_parser_error (parser
, "expected %<{%>");
5734 objc_pq_context
= 0;
5735 objc_start_method_definition (decl
);
5736 add_stmt (c_parser_compound_statement (parser
));
5737 objc_finish_method_definition (current_function_decl
);
5740 /* Parse an objc-methodprotolist.
5742 objc-methodprotolist:
5744 objc-methodprotolist objc-methodproto
5745 objc-methodprotolist declaration
5746 objc-methodprotolist ;
5748 The declaration is a data definition, which may be missing
5749 declaration specifiers under the same rules and diagnostics as
5750 other data definitions outside functions, and the stray semicolon
5751 is diagnosed the same way as a stray semicolon outside a
5755 c_parser_objc_methodprotolist (c_parser
*parser
)
5759 /* The list is terminated by @end. */
5760 switch (c_parser_peek_token (parser
)->type
)
5764 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5765 c_parser_consume_token (parser
);
5769 c_parser_objc_methodproto (parser
);
5774 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
5776 c_parser_declaration_or_fndef (parser
, false, true, false, true);
5782 /* Parse an objc-methodproto.
5785 objc-method-type objc-method-decl ;
5789 c_parser_objc_methodproto (c_parser
*parser
)
5791 enum tree_code type
= c_parser_objc_method_type (parser
);
5793 objc_set_method_type (type
);
5794 /* Remember protocol qualifiers in prototypes. */
5795 objc_pq_context
= 1;
5796 decl
= c_parser_objc_method_decl (parser
);
5797 /* Forget protocol qualifiers here. */
5798 objc_pq_context
= 0;
5799 objc_add_method_declaration (decl
);
5800 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5803 /* Parse an objc-method-decl.
5806 ( objc-type-name ) objc-selector
5808 ( objc-type-name ) objc-keyword-selector objc-optparmlist
5809 objc-keyword-selector objc-optparmlist
5811 objc-keyword-selector:
5813 objc-keyword-selector objc-keyword-decl
5816 objc-selector : ( objc-type-name ) identifier
5817 objc-selector : identifier
5818 : ( objc-type-name ) identifier
5822 objc-optparms objc-optellipsis
5826 objc-opt-parms , parameter-declaration
5834 c_parser_objc_method_decl (c_parser
*parser
)
5836 tree type
= NULL_TREE
;
5838 tree parms
= NULL_TREE
;
5839 bool ellipsis
= false;
5841 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5843 c_parser_consume_token (parser
);
5844 type
= c_parser_objc_type_name (parser
);
5845 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5847 sel
= c_parser_objc_selector (parser
);
5848 /* If there is no selector, or a colon follows, we have an
5849 objc-keyword-selector. If there is a selector, and a colon does
5850 not follow, that selector ends the objc-method-decl. */
5851 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
5854 tree list
= NULL_TREE
;
5857 tree atype
= NULL_TREE
, id
, keyworddecl
;
5858 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5860 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5862 c_parser_consume_token (parser
);
5863 atype
= c_parser_objc_type_name (parser
);
5864 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5867 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5869 c_parser_error (parser
, "expected identifier");
5870 return error_mark_node
;
5872 id
= c_parser_peek_token (parser
)->value
;
5873 c_parser_consume_token (parser
);
5874 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
5875 list
= chainon (list
, keyworddecl
);
5876 tsel
= c_parser_objc_selector (parser
);
5877 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
5880 /* Parse the optional parameter list. Optional Objective-C
5881 method parameters follow the C syntax, and may include '...'
5882 to denote a variable number of arguments. */
5883 parms
= make_node (TREE_LIST
);
5884 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5886 struct c_parm
*parm
;
5887 c_parser_consume_token (parser
);
5888 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5891 c_parser_consume_token (parser
);
5894 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
5897 parms
= chainon (parms
,
5898 build_tree_list (NULL_TREE
, grokparm (parm
)));
5902 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
5905 /* Parse an objc-type-name.
5908 objc-type-qualifiers[opt] type-name
5909 objc-type-qualifiers[opt]
5911 objc-type-qualifiers:
5913 objc-type-qualifiers objc-type-qualifier
5915 objc-type-qualifier: one of
5916 in out inout bycopy byref oneway
5920 c_parser_objc_type_name (c_parser
*parser
)
5922 tree quals
= NULL_TREE
;
5923 struct c_type_name
*typename
= NULL
;
5924 tree type
= NULL_TREE
;
5927 c_token
*token
= c_parser_peek_token (parser
);
5928 if (token
->type
== CPP_KEYWORD
5929 && (token
->keyword
== RID_IN
5930 || token
->keyword
== RID_OUT
5931 || token
->keyword
== RID_INOUT
5932 || token
->keyword
== RID_BYCOPY
5933 || token
->keyword
== RID_BYREF
5934 || token
->keyword
== RID_ONEWAY
))
5936 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
5937 c_parser_consume_token (parser
);
5942 if (c_parser_next_token_starts_typename (parser
))
5943 typename
= c_parser_type_name (parser
);
5945 type
= groktypename (typename
);
5946 return build_tree_list (quals
, type
);
5949 /* Parse objc-protocol-refs.
5956 c_parser_objc_protocol_refs (c_parser
*parser
)
5958 tree list
= NULL_TREE
;
5959 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
5960 c_parser_consume_token (parser
);
5961 /* Any identifiers, including those declared as type names, are OK
5966 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5968 c_parser_error (parser
, "expected identifier");
5971 id
= c_parser_peek_token (parser
)->value
;
5972 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5973 c_parser_consume_token (parser
);
5974 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5975 c_parser_consume_token (parser
);
5979 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
5983 /* Parse an objc-try-catch-statement.
5985 objc-try-catch-statement:
5986 @try compound-statement objc-catch-list[opt]
5987 @try compound-statement objc-catch-list[opt] @finally compound-statement
5990 @catch ( parameter-declaration ) compound-statement
5991 objc-catch-list @catch ( parameter-declaration ) compound-statement
5995 c_parser_objc_try_catch_statement (c_parser
*parser
)
5999 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
6000 c_parser_consume_token (parser
);
6001 loc
= c_parser_peek_token (parser
)->location
;
6002 stmt
= c_parser_compound_statement (parser
);
6003 objc_begin_try_stmt (loc
, stmt
);
6004 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
6006 struct c_parm
*parm
;
6007 c_parser_consume_token (parser
);
6008 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6010 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6013 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6016 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6017 objc_begin_catch_clause (grokparm (parm
));
6018 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6019 c_parser_compound_statement_nostart (parser
);
6020 objc_finish_catch_clause ();
6022 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6026 c_parser_consume_token (parser
);
6027 finloc
= c_parser_peek_token (parser
)->location
;
6028 finstmt
= c_parser_compound_statement (parser
);
6029 objc_build_finally_clause (finloc
, finstmt
);
6031 objc_finish_try_stmt ();
6034 /* Parse an objc-synchronized-statement.
6036 objc-synchronized-statement:
6037 @synchronized ( expression ) compound-statement
6041 c_parser_objc_synchronized_statement (c_parser
*parser
)
6045 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6046 c_parser_consume_token (parser
);
6047 loc
= c_parser_peek_token (parser
)->location
;
6048 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6050 expr
= c_parser_expression (parser
).value
;
6051 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6054 expr
= error_mark_node
;
6055 stmt
= c_parser_compound_statement (parser
);
6056 objc_build_synchronized (loc
, expr
, stmt
);
6059 /* Parse an objc-selector; return NULL_TREE without an error if the
6060 next token is not an objc-selector.
6065 enum struct union if else while do for switch case default
6066 break continue return goto asm sizeof typeof __alignof
6067 unsigned long const short volatile signed restrict _Complex
6068 in out inout bycopy byref oneway int char float double void _Bool
6070 ??? Why this selection of keywords but not, for example, storage
6071 class specifiers? */
6074 c_parser_objc_selector (c_parser
*parser
)
6076 c_token
*token
= c_parser_peek_token (parser
);
6077 tree value
= token
->value
;
6078 if (token
->type
== CPP_NAME
)
6080 c_parser_consume_token (parser
);
6083 if (token
->type
!= CPP_KEYWORD
)
6085 switch (token
->keyword
)
6126 c_parser_consume_token (parser
);
6133 /* Parse an objc-selector-arg.
6137 objc-keywordname-list
6139 objc-keywordname-list:
6141 objc-keywordname-list objc-keywordname
6149 c_parser_objc_selector_arg (c_parser
*parser
)
6151 tree sel
= c_parser_objc_selector (parser
);
6152 tree list
= NULL_TREE
;
6153 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6157 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6159 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6160 sel
= c_parser_objc_selector (parser
);
6161 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6167 /* Parse an objc-receiver.
6176 c_parser_objc_receiver (c_parser
*parser
)
6178 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6179 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6180 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6182 tree id
= c_parser_peek_token (parser
)->value
;
6183 c_parser_consume_token (parser
);
6184 return objc_get_class_reference (id
);
6186 return c_parser_expression (parser
).value
;
6189 /* Parse objc-message-args.
6193 objc-keywordarg-list
6195 objc-keywordarg-list:
6197 objc-keywordarg-list objc-keywordarg
6200 objc-selector : objc-keywordexpr
6205 c_parser_objc_message_args (c_parser
*parser
)
6207 tree sel
= c_parser_objc_selector (parser
);
6208 tree list
= NULL_TREE
;
6209 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6214 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6216 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6217 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6218 sel
= c_parser_objc_selector (parser
);
6219 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6225 /* Parse an objc-keywordexpr.
6232 c_parser_objc_keywordexpr (c_parser
*parser
)
6234 tree list
= c_parser_expr_list (parser
, true);
6235 if (TREE_CHAIN (list
) == NULL_TREE
)
6237 /* Just return the expression, remove a level of
6239 return TREE_VALUE (list
);
6243 /* We have a comma expression, we will collapse later. */
6249 /* The actual parser and external interface. ??? Does this need to be
6250 garbage-collected? */
6252 static GTY (()) c_parser
*the_parser
;
6254 /* Parse a single source file. */
6259 the_parser
= c_parser_new ();
6260 c_parser_translation_unit (the_parser
);
6264 #include "gt-c-parser.h"