]> gcc.gnu.org Git - gcc.git/blame - gcc/c-parse.in
pretty-print.c: Include tree.h.
[gcc.git] / gcc / c-parse.in
CommitLineData
66ea6f4c 1/* YACC parser for C syntax and for Objective C. -*-c-*-
f560bf91
JM
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
028299c6 4
1322177d 5This file is part of GCC.
028299c6 6
1322177d
LB
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
028299c6 11
1322177d
LB
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
028299c6
RS
16
17You should have received a copy of the GNU General Public License
1322177d
LB
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
028299c6
RS
21
22/* This file defines the grammar of C and that of Objective C.
264fa2db
ZL
23 @@ifobjc ... @@end_ifobjc conditionals contain code for Objective C only.
24 @@ifc ... @@end_ifc conditionals contain code for C only.
66b2ba11 25 Sed commands in Makefile.in are used to convert this file into
028299c6
RS
26 c-parse.y and into objc-parse.y. */
27
28/* To whomever it may concern: I have heard that such a thing was once
41ddaaa4 29 written by AT&T, but I have never seen it. */
028299c6 30
264fa2db 31@@ifc
506e2710 32%expect 13 /* shift/reduce conflicts, and no reduce/reduce conflicts. */
264fa2db 33@@end_ifc
028299c6
RS
34
35%{
818e50a5 36#include "config.h"
944fc8ab 37#include "system.h"
4977bab6
ZW
38#include "coretypes.h"
39#include "tm.h"
028299c6 40#include "tree.h"
e57e265b 41#include "langhooks.h"
028299c6 42#include "input.h"
8b97c5f8
ZW
43#include "cpplib.h"
44#include "intl.h"
45#include "timevar.h"
81a75f0f 46#include "c-pragma.h" /* For YYDEBUG definition, and parse_in. */
028299c6
RS
47#include "c-tree.h"
48#include "flags.h"
17211ab5 49#include "varray.h"
990ac8d7 50#include "output.h"
5f6da302 51#include "toplev.h"
1526a060 52#include "ggc.h"
6408ef33 53#include "c-common.h"
028299c6 54
028299c6 55#define YYERROR1 { yyerror ("syntax error"); YYERROR; }
94a50397
RH
56
57/* Like the default stack expander, except (1) use realloc when possible,
58 (2) impose no hard maxiumum on stack size, (3) REALLY do not use alloca.
59
60 Irritatingly, YYSTYPE is defined after this %{ %} block, so we cannot
61 give malloced_yyvs its proper type. This is ok since all we need from
62 it is to be able to free it. */
63
64static short *malloced_yyss;
65static void *malloced_yyvs;
66
67#define yyoverflow(MSG, SS, SSSIZE, VS, VSSIZE, YYSSZ) \
68do { \
69 size_t newsize; \
70 short *newss; \
71 YYSTYPE *newvs; \
72 newsize = *(YYSSZ) *= 2; \
73 if (malloced_yyss) \
74 { \
703ad42b
KG
75 newss = really_call_realloc (*(SS), newsize * sizeof (short)); \
76 newvs = really_call_realloc (*(VS), newsize * sizeof (YYSTYPE)); \
94a50397
RH
77 } \
78 else \
79 { \
703ad42b
KG
80 newss = really_call_malloc (newsize * sizeof (short)); \
81 newvs = really_call_malloc (newsize * sizeof (YYSTYPE)); \
94a50397
RH
82 if (newss) \
83 memcpy (newss, *(SS), (SSSIZE)); \
84 if (newvs) \
85 memcpy (newvs, *(VS), (VSSIZE)); \
86 } \
87 if (!newss || !newvs) \
88 { \
89 yyerror (MSG); \
90 return 2; \
91 } \
92 *(SS) = newss; \
93 *(VS) = newvs; \
94 malloced_yyss = newss; \
95 malloced_yyvs = (void *) newvs; \
96} while (0)
028299c6
RS
97%}
98
99%start program
100
bc4b653b 101%union {long itype; tree ttype; void *otype; struct c_expr exprtype;
f8893e47
JM
102 struct c_arg_info *arginfotype; struct c_declarator *dtrtype;
103 struct c_type_name *typenametype; struct c_parm *parmtype;
deb176fa
JM
104 struct c_declspecs *dsptype; enum tree_code code;
105 location_t location; }
028299c6
RS
106
107/* All identifiers that are not reserved words
108 and are not declared typedefs in the current block */
109%token IDENTIFIER
110
111/* All identifiers that are declared typedefs in the current block.
112 In some contexts, they are treated just like IDENTIFIER,
113 but they can also serve as typespecs in declarations. */
114%token TYPENAME
115
116/* Reserved words that specify storage class.
117 yylval contains an IDENTIFIER_NODE which indicates which one. */
f79f2651
NB
118%token SCSPEC /* Storage class other than static. */
119%token STATIC /* Static storage class. */
028299c6
RS
120
121/* Reserved words that specify type.
122 yylval contains an IDENTIFIER_NODE which indicates which one. */
123%token TYPESPEC
124
3932261a 125/* Reserved words that qualify type: "const", "volatile", or "restrict".
028299c6
RS
126 yylval contains an IDENTIFIER_NODE which indicates which one. */
127%token TYPE_QUAL
128
b77c7437
ZL
129/* Objective-C protocol qualifiers. These acquire their magic powers
130 only in certain contexts. */
131%token OBJC_TYPE_QUAL
132
028299c6
RS
133/* Character or numeric constants.
134 yylval is the node for the constant. */
135%token CONSTANT
136
a23c9413
NB
137/* String constants in raw form.
138 yylval is a STRING_CST node. */
d479d37f 139
a23c9413 140%token STRING
028299c6
RS
141
142/* "...", used for functions with variable arglists. */
143%token ELLIPSIS
144
145/* the reserved words */
146/* SCO include files test "ASM", so use something else. */
147%token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
5ed7f7b1 148%token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
028299c6 149%token ATTRIBUTE EXTENSION LABEL
ecbcf7b3 150%token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
4b4f19ec 151%token PTR_VALUE PTR_BASE PTR_EXTENT
7a3ea201 152%token FUNC_NAME OFFSETOF
0ba8a114 153
028299c6
RS
154/* Add precedence rules to solve dangling else s/r conflict */
155%nonassoc IF
156%nonassoc ELSE
157
158/* Define the operator tokens and their precedences.
159 The value is an integer because, if used, it is the tree code
160 to use in the expression made from the operator. */
161
162%right <code> ASSIGN '='
163%right <code> '?' ':'
164%left <code> OROR
165%left <code> ANDAND
166%left <code> '|'
167%left <code> '^'
168%left <code> '&'
169%left <code> EQCOMPARE
170%left <code> ARITHCOMPARE
171%left <code> LSHIFT RSHIFT
172%left <code> '+' '-'
173%left <code> '*' '/' '%'
174%right <code> UNARY PLUSPLUS MINUSMINUS
175%left HYPERUNARY
176%left <code> POINTSAT '.' '(' '['
177
178/* The Objective-C keywords. These are included in C and in
179 Objective C, so that the token codes are the same in both. */
f2b5cf97 180%token AT_INTERFACE AT_IMPLEMENTATION AT_END AT_SELECTOR AT_DEFS AT_ENCODE
6408ef33 181%token CLASSNAME AT_PUBLIC AT_PRIVATE AT_PROTECTED AT_PROTOCOL
f2b5cf97 182%token OBJECTNAME AT_CLASS AT_ALIAS
264fa2db 183%token AT_THROW AT_TRY AT_CATCH AT_FINALLY AT_SYNCHRONIZED
e6cc3a24 184%token OBJC_STRING
e31c7eec 185
028299c6 186%type <code> unop
0e5921e8
ZW
187%type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
188%type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
028299c6 189
487a92fe
JM
190%type <ttype> identifier IDENTIFIER TYPENAME CONSTANT STRING FUNC_NAME
191%type <ttype> nonnull_exprlist exprlist
192%type <exprtype> expr expr_no_commas cast_expr unary_expr primary
deb176fa
JM
193%type <dsptype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
194%type <dsptype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
195%type <dsptype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
196%type <dsptype> declspecs_nosc_ts_sa_noea declspecs_nosc_ts_sa_ea
197%type <dsptype> declspecs_sc_nots_nosa_noea declspecs_sc_nots_nosa_ea
198%type <dsptype> declspecs_sc_nots_sa_noea declspecs_sc_nots_sa_ea
199%type <dsptype> declspecs_sc_ts_nosa_noea declspecs_sc_ts_nosa_ea
200%type <dsptype> declspecs_sc_ts_sa_noea declspecs_sc_ts_sa_ea
201%type <dsptype> declspecs_ts declspecs_nots
202%type <dsptype> declspecs_ts_nosa declspecs_nots_nosa
203%type <dsptype> declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs
204%type <dsptype> maybe_type_quals_attrs
205%type <ttype> typespec_nonattr typespec_attr
25d78ace
JM
206%type <ttype> typespec_reserved_nonattr typespec_reserved_attr
207%type <ttype> typespec_nonreserved_nonattr
7a3ea201 208%type <ttype> offsetof_member_designator
25d78ace 209
9f0e2d86 210%type <ttype> scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_volatile
916c5919
JM
211%type <ttype> initdecls notype_initdecls initdcl notype_initdcl
212%type <exprtype> init
8507c40a 213%type <ttype> simple_asm_expr maybeasm asm_stmt asm_argument
028299c6 214%type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
660b43c8 215%type <ttype> maybe_attribute attributes attribute attribute_list attrib
1aaec916 216%type <ttype> any_word
028299c6 217
325c3691 218%type <ttype> compstmt compstmt_start compstmt_primary_start
506e2710 219%type <ttype> stmt label stmt_nocomp start_break start_continue
028299c6 220
325c3691 221%type <ttype> c99_block_start c99_block_lineno_labeled_stmt
506e2710 222%type <ttype> if_statement_1 if_statement_2
f8893e47
JM
223%type <dtrtype> declarator
224%type <dtrtype> notype_declarator after_type_declarator
225%type <dtrtype> parm_declarator
226%type <dtrtype> parm_declarator_starttypename parm_declarator_nostarttypename
227%type <dtrtype> array_declarator
028299c6 228
25d78ace
JM
229%type <ttype> structsp_attr structsp_nonattr
230%type <ttype> component_decl_list component_decl_list2
231%type <ttype> component_decl components components_notype component_declarator
232%type <ttype> component_notype_declarator
028299c6 233%type <ttype> enumlist enumerator
4051959b 234%type <ttype> struct_head union_head enum_head
f8893e47
JM
235%type <typenametype> typename
236%type <dtrtype> absdcl absdcl1 absdcl1_ea absdcl1_noea direct_absdcl1
237%type <parmtype> absdcl_maybe_attribute
506e2710 238%type <ttype> condition xexpr for_cond_expr for_incr_expr
f8893e47
JM
239%type <parmtype> parm firstparm
240%type <ttype> identifiers
028299c6 241
f8893e47
JM
242%type <arginfotype> parms parmlist parmlist_1 parmlist_2
243%type <arginfotype> parmlist_or_identifiers parmlist_or_identifiers_1
028299c6
RS
244%type <ttype> identifiers_or_typenames
245
1aaec916 246%type <itype> setspecs setspecs_fp extension
028299c6 247
374a4e6c 248%type <location> save_location
bc4b653b
JM
249
250%type <otype> save_obstack_position
028299c6 251\f
264fa2db 252@@ifobjc
028299c6
RS
253/* the Objective-C nonterminals */
254
028299c6 255%type <ttype> methoddecl unaryselector keywordselector selector
6408ef33 256%type <code> methodtype
028299c6
RS
257%type <ttype> keyworddecl receiver objcmessageexpr messageargs
258%type <ttype> keywordexpr keywordarglist keywordarg
6408ef33 259%type <ttype> optparmlist optparms reservedwords objcselectorexpr
028299c6 260%type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
e6cc3a24 261%type <ttype> non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
957a1c32 262
6408ef33 263%type <ttype> CLASSNAME OBJECTNAME OBJC_STRING OBJC_TYPE_QUAL
264fa2db 264
6408ef33
ZL
265%type <ttype> superclass objc_quals objc_qual objc_typename
266%type <itype> objc_try_catch_stmt optellipsis
264fa2db 267@@end_ifobjc
028299c6
RS
268\f
269%{
deb176fa
JM
270/* Declaration specifiers of the current declaration. */
271static struct c_declspecs *current_declspecs;
e2500fed 272static GTY(()) tree prefix_attributes;
028299c6 273
4b01f8d8
JM
274/* List of all the attributes applying to the identifier currently being
275 declared; includes prefix_attributes and possibly some more attributes
276 just after a comma. */
e2500fed 277static GTY(()) tree all_prefix_attributes;
4b01f8d8 278
deb176fa
JM
279/* Structure to save declaration specifiers. */
280struct c_declspec_stack {
281 /* Saved value of current_declspecs. */
282 struct c_declspecs *current_declspecs;
283 /* Saved value of prefix_attributes. */
284 tree prefix_attributes;
285 /* Saved value of all_prefix_attributes. */
286 tree all_prefix_attributes;
287 /* Next level of stack. */
288 struct c_declspec_stack *next;
289};
290
4b01f8d8
JM
291/* Stack of saved values of current_declspecs, prefix_attributes and
292 all_prefix_attributes. */
deb176fa 293static struct c_declspec_stack *declspec_stack;
028299c6 294
ee8a6a3e
RH
295/* INDIRECT_REF with a TREE_TYPE of the type being queried for offsetof. */
296static tree offsetof_base;
297
4b01f8d8
JM
298/* PUSH_DECLSPEC_STACK is called from setspecs; POP_DECLSPEC_STACK
299 should be called from the productions making use of setspecs. */
deb176fa
JM
300#define PUSH_DECLSPEC_STACK \
301 do { \
302 struct c_declspec_stack *t = XOBNEW (&parser_obstack, \
303 struct c_declspec_stack); \
304 t->current_declspecs = current_declspecs; \
305 t->prefix_attributes = prefix_attributes; \
306 t->all_prefix_attributes = all_prefix_attributes; \
307 t->next = declspec_stack; \
308 declspec_stack = t; \
4b01f8d8
JM
309 } while (0)
310
311#define POP_DECLSPEC_STACK \
312 do { \
deb176fa
JM
313 current_declspecs = declspec_stack->current_declspecs; \
314 prefix_attributes = declspec_stack->prefix_attributes; \
315 all_prefix_attributes = declspec_stack->all_prefix_attributes; \
316 declspec_stack = declspec_stack->next; \
4b01f8d8
JM
317 } while (0)
318
c3b6e114
JK
319/* For __extension__, save/restore the warning flags which are
320 controlled by __extension__. */
1aaec916
RH
321#define SAVE_EXT_FLAGS() \
322 (pedantic \
323 | (warn_pointer_arith << 1) \
324 | (warn_traditional << 2) \
325 | (flag_iso << 3))
5137bd4f 326
1aaec916 327#define RESTORE_EXT_FLAGS(val) \
5137bd4f 328 do { \
5137bd4f
RH
329 pedantic = val & 1; \
330 warn_pointer_arith = (val >> 1) & 1; \
331 warn_traditional = (val >> 2) & 1; \
750491fc 332 flag_iso = (val >> 3) & 1; \
c3b6e114
JK
333 } while (0)
334
264fa2db 335@@ifobjc
8607f1bc
ZL
336/* Objective-C specific parser/lexer information */
337
6408ef33 338static int objc_pq_context = 0;
028299c6 339
f2e6e530 340/* The following flag is needed to contextualize ObjC lexical analysis.
84d901be
AD
341 In some cases (e.g., 'int NSObject;'), it is undesirable to bind
342 an identifier to an ObjC class, even if a class with that name
f2e6e530 343 exists. */
8607f1bc 344static int objc_need_raw_identifier;
f2e6e530 345#define OBJC_NEED_RAW_IDENTIFIER(VAL) objc_need_raw_identifier = VAL
264fa2db 346@@end_ifobjc
028299c6 347
264fa2db 348@@ifc
f2e6e530 349#define OBJC_NEED_RAW_IDENTIFIER(VAL) /* nothing */
264fa2db 350@@end_ifc
f2e6e530 351
028299c6
RS
352/* Tell yyparse how to print a token's value, if yydebug is set. */
353
354#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
0e5921e8 355
f55ade6e
AJ
356static void yyprint (FILE *, int, YYSTYPE);
357static void yyerror (const char *);
358static int yylexname (void);
359static inline int _yylex (void);
360static int yylex (void);
361static void init_reswords (void);
1526a060 362
b01d837f 363 /* Initialization routine for this file. */
1526a060 364void
f55ade6e 365c_parse_init (void)
1526a060 366{
f5e99456 367 init_reswords ();
1526a060
BS
368}
369
028299c6
RS
370%}
371\f
372%%
373program: /* empty */
374 { if (pedantic)
89abf8d1 375 pedwarn ("ISO C forbids an empty source file");
028299c6
RS
376 }
377 | extdefs
028299c6
RS
378 ;
379
380/* the reason for the strange actions in this rule
381 is so that notype_initdecls when reached via datadef
deb176fa 382 can find valid declaration specifiers in $0. */
028299c6
RS
383
384extdefs:
deb176fa 385 save_obstack_position { $<dsptype>$ = NULL; } extdef
bc4b653b
JM
386 { obstack_free (&parser_obstack, $1); }
387 | extdefs save_obstack_position
3f75a254 388 { $<dsptype>$ = NULL; ggc_collect (); } extdef
bc4b653b 389 { obstack_free (&parser_obstack, $2); }
028299c6
RS
390 ;
391
392extdef:
393 fndef
394 | datadef
9f0e2d86
ZW
395 | asmdef
396 | extension extdef
397 { RESTORE_EXT_FLAGS ($1); }
264fa2db 398@@ifobjc
028299c6 399 | objcdef
264fa2db 400@@end_ifobjc
028299c6
RS
401 ;
402
bc4b653b
JM
403/* Record the current position of parser_obstack before a
404 declaration to restore it afterwards. */
405save_obstack_position:
406 { $$ = obstack_alloc (&parser_obstack, 0); }
407 ;
408
028299c6
RS
409datadef:
410 setspecs notype_initdecls ';'
411 { if (pedantic)
89abf8d1 412 error ("ISO C forbids data definition with no type or storage class");
f458d1d5 413 else
84d901be 414 warning ("data definition has no type or storage class");
962a2496 415
4b01f8d8 416 POP_DECLSPEC_STACK; }
25d78ace 417 | declspecs_nots setspecs notype_initdecls ';'
4b01f8d8 418 { POP_DECLSPEC_STACK; }
25d78ace 419 | declspecs_ts setspecs initdecls ';'
4b01f8d8 420 { POP_DECLSPEC_STACK; }
25d78ace 421 | declspecs ';'
98c3a782 422 { shadow_tag (finish_declspecs ($1)); }
028299c6
RS
423 | error ';'
424 | error '}'
425 | ';'
426 { if (pedantic)
bda67431 427 pedwarn ("ISO C does not allow extra %<;%> outside of a function"); }
028299c6
RS
428 ;
429\f
430fndef:
25d78ace 431 declspecs_ts setspecs declarator
3f75a254
JM
432 { if (!start_function (current_declspecs, $3,
433 all_prefix_attributes))
028299c6 434 YYERROR1;
0e5921e8 435 }
374a4e6c 436 old_style_parm_decls save_location
f31686a3 437 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
b190f239 438 store_parm_decls (); }
374a4e6c 439 compstmt_or_error
4a46cbfb 440 { finish_function ();
4b01f8d8 441 POP_DECLSPEC_STACK; }
25d78ace 442 | declspecs_ts setspecs declarator error
4b01f8d8 443 { POP_DECLSPEC_STACK; }
25d78ace 444 | declspecs_nots setspecs notype_declarator
3f75a254
JM
445 { if (!start_function (current_declspecs, $3,
446 all_prefix_attributes))
028299c6 447 YYERROR1;
0e5921e8 448 }
374a4e6c 449 old_style_parm_decls save_location
f31686a3 450 { DECL_SOURCE_LOCATION (current_function_decl) = $6;
b190f239
NS
451 store_parm_decls (); }
452 compstmt_or_error
4a46cbfb 453 { finish_function ();
4b01f8d8 454 POP_DECLSPEC_STACK; }
25d78ace 455 | declspecs_nots setspecs notype_declarator error
4b01f8d8 456 { POP_DECLSPEC_STACK; }
9fe9dd86 457 | setspecs notype_declarator
3f75a254
JM
458 { if (!start_function (current_declspecs, $2,
459 all_prefix_attributes))
028299c6 460 YYERROR1;
0e5921e8 461 }
374a4e6c 462 old_style_parm_decls save_location
f31686a3 463 { DECL_SOURCE_LOCATION (current_function_decl) = $5;
b190f239
NS
464 store_parm_decls (); }
465 compstmt_or_error
4a46cbfb 466 { finish_function ();
4b01f8d8 467 POP_DECLSPEC_STACK; }
028299c6 468 | setspecs notype_declarator error
4b01f8d8 469 { POP_DECLSPEC_STACK; }
028299c6
RS
470 ;
471
472identifier:
473 IDENTIFIER
474 | TYPENAME
264fa2db 475@@ifobjc
e31c7eec 476 | OBJECTNAME
f2e6e530 477 | CLASSNAME
264fa2db 478@@end_ifobjc
028299c6
RS
479 ;
480
481unop: '&'
482 { $$ = ADDR_EXPR; }
483 | '-'
484 { $$ = NEGATE_EXPR; }
485 | '+'
895ea614 486 { $$ = CONVERT_EXPR;
264fa2db 487@@ifc
aac625ac 488 if (warn_traditional && !in_system_header)
895ea614 489 warning ("traditional C rejects the unary plus operator");
264fa2db 490@@end_ifc
895ea614 491 }
028299c6
RS
492 | PLUSPLUS
493 { $$ = PREINCREMENT_EXPR; }
494 | MINUSMINUS
495 { $$ = PREDECREMENT_EXPR; }
496 | '~'
497 { $$ = BIT_NOT_EXPR; }
498 | '!'
499 { $$ = TRUTH_NOT_EXPR; }
500 ;
501
487a92fe
JM
502expr: expr_no_commas
503 | expr ',' expr_no_commas
504 { $$.value = build_compound_expr ($1.value, $3.value);
505 $$.original_code = COMPOUND_EXPR; }
028299c6
RS
506 ;
507
508exprlist:
509 /* empty */
510 { $$ = NULL_TREE; }
511 | nonnull_exprlist
512 ;
513
514nonnull_exprlist:
515 expr_no_commas
487a92fe 516 { $$ = build_tree_list (NULL_TREE, $1.value); }
028299c6 517 | nonnull_exprlist ',' expr_no_commas
487a92fe 518 { chainon ($1, build_tree_list (NULL_TREE, $3.value)); }
028299c6
RS
519 ;
520
521unary_expr:
522 primary
523 | '*' cast_expr %prec UNARY
487a92fe
JM
524 { $$.value = build_indirect_ref ($2.value, "unary *");
525 $$.original_code = ERROR_MARK; }
028299c6 526 /* __extension__ turns off -pedantic for following primary. */
72acf258
JM
527 | extension cast_expr %prec UNARY
528 { $$ = $2;
750491fc 529 RESTORE_EXT_FLAGS ($1); }
028299c6 530 | unop cast_expr %prec UNARY
487a92fe
JM
531 { $$.value = build_unary_op ($1, $2.value, 0);
532 overflow_warning ($$.value);
533 $$.original_code = ERROR_MARK; }
028299c6
RS
534 /* Refer to the address of a label as a pointer. */
535 | ANDAND identifier
487a92fe
JM
536 { $$.value = finish_label_address_expr ($2);
537 $$.original_code = ERROR_MARK; }
5f8f4a07
RK
538 | sizeof unary_expr %prec UNARY
539 { skip_evaluation--;
bc4b653b 540 in_sizeof--;
487a92fe
JM
541 if (TREE_CODE ($2.value) == COMPONENT_REF
542 && DECL_C_BIT_FIELD (TREE_OPERAND ($2.value, 1)))
bda67431 543 error ("%<sizeof%> applied to a bit-field");
bc4b653b 544 $$ = c_expr_sizeof_expr ($2); }
5f8f4a07
RK
545 | sizeof '(' typename ')' %prec HYPERUNARY
546 { skip_evaluation--;
bc4b653b
JM
547 in_sizeof--;
548 $$ = c_expr_sizeof_type ($3); }
5f8f4a07
RK
549 | alignof unary_expr %prec UNARY
550 { skip_evaluation--;
bc4b653b 551 in_alignof--;
487a92fe
JM
552 $$.value = c_alignof_expr ($2.value);
553 $$.original_code = ERROR_MARK; }
5f8f4a07
RK
554 | alignof '(' typename ')' %prec HYPERUNARY
555 { skip_evaluation--;
bc4b653b 556 in_alignof--;
487a92fe
JM
557 $$.value = c_alignof (groktypename ($3));
558 $$.original_code = ERROR_MARK; }
475e8534 559 | REALPART cast_expr %prec UNARY
487a92fe
JM
560 { $$.value = build_unary_op (REALPART_EXPR, $2.value, 0);
561 $$.original_code = ERROR_MARK; }
475e8534 562 | IMAGPART cast_expr %prec UNARY
487a92fe
JM
563 { $$.value = build_unary_op (IMAGPART_EXPR, $2.value, 0);
564 $$.original_code = ERROR_MARK; }
028299c6
RS
565 ;
566
5f8f4a07 567sizeof:
bc4b653b 568 SIZEOF { skip_evaluation++; in_sizeof++; }
5f8f4a07
RK
569 ;
570
571alignof:
bc4b653b 572 ALIGNOF { skip_evaluation++; in_alignof++; }
5f8f4a07
RK
573 ;
574
25587e40 575typeof:
bc4b653b 576 TYPEOF { skip_evaluation++; in_typeof++; }
25587e40
AO
577 ;
578
028299c6
RS
579cast_expr:
580 unary_expr
581 | '(' typename ')' cast_expr %prec UNARY
487a92fe
JM
582 { $$.value = c_cast_expr ($2, $4.value);
583 $$.original_code = ERROR_MARK; }
028299c6
RS
584 ;
585
586expr_no_commas:
587 cast_expr
588 | expr_no_commas '+' expr_no_commas
589 { $$ = parser_build_binary_op ($2, $1, $3); }
590 | expr_no_commas '-' expr_no_commas
591 { $$ = parser_build_binary_op ($2, $1, $3); }
592 | expr_no_commas '*' expr_no_commas
593 { $$ = parser_build_binary_op ($2, $1, $3); }
594 | expr_no_commas '/' expr_no_commas
595 { $$ = parser_build_binary_op ($2, $1, $3); }
596 | expr_no_commas '%' expr_no_commas
597 { $$ = parser_build_binary_op ($2, $1, $3); }
598 | expr_no_commas LSHIFT expr_no_commas
599 { $$ = parser_build_binary_op ($2, $1, $3); }
600 | expr_no_commas RSHIFT expr_no_commas
601 { $$ = parser_build_binary_op ($2, $1, $3); }
602 | expr_no_commas ARITHCOMPARE expr_no_commas
603 { $$ = parser_build_binary_op ($2, $1, $3); }
604 | expr_no_commas EQCOMPARE expr_no_commas
605 { $$ = parser_build_binary_op ($2, $1, $3); }
606 | expr_no_commas '&' expr_no_commas
607 { $$ = parser_build_binary_op ($2, $1, $3); }
608 | expr_no_commas '|' expr_no_commas
609 { $$ = parser_build_binary_op ($2, $1, $3); }
610 | expr_no_commas '^' expr_no_commas
611 { $$ = parser_build_binary_op ($2, $1, $3); }
5f8f4a07 612 | expr_no_commas ANDAND
487a92fe
JM
613 { $1.value = lang_hooks.truthvalue_conversion
614 (default_conversion ($1.value));
615 skip_evaluation += $1.value == truthvalue_false_node; }
5f8f4a07 616 expr_no_commas
487a92fe 617 { skip_evaluation -= $1.value == truthvalue_false_node;
5f8f4a07
RK
618 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
619 | expr_no_commas OROR
487a92fe
JM
620 { $1.value = lang_hooks.truthvalue_conversion
621 (default_conversion ($1.value));
622 skip_evaluation += $1.value == truthvalue_true_node; }
5f8f4a07 623 expr_no_commas
487a92fe 624 { skip_evaluation -= $1.value == truthvalue_true_node;
5f8f4a07
RK
625 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
626 | expr_no_commas '?'
487a92fe
JM
627 { $1.value = lang_hooks.truthvalue_conversion
628 (default_conversion ($1.value));
629 skip_evaluation += $1.value == truthvalue_false_node; }
5f8f4a07 630 expr ':'
487a92fe
JM
631 { skip_evaluation += (($1.value == truthvalue_true_node)
632 - ($1.value == truthvalue_false_node)); }
5f8f4a07 633 expr_no_commas
487a92fe
JM
634 { skip_evaluation -= $1.value == truthvalue_true_node;
635 $$.value = build_conditional_expr ($1.value, $4.value,
636 $7.value);
637 $$.original_code = ERROR_MARK; }
5f8f4a07
RK
638 | expr_no_commas '?'
639 { if (pedantic)
89abf8d1 640 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
5f8f4a07 641 /* Make sure first operand is calculated only once. */
487a92fe
JM
642 $<ttype>2 = save_expr (default_conversion ($1.value));
643 $1.value = lang_hooks.truthvalue_conversion ($<ttype>2);
644 skip_evaluation += $1.value == truthvalue_true_node; }
5f8f4a07 645 ':' expr_no_commas
487a92fe
JM
646 { skip_evaluation -= $1.value == truthvalue_true_node;
647 $$.value = build_conditional_expr ($1.value, $<ttype>2,
648 $5.value);
649 $$.original_code = ERROR_MARK; }
028299c6 650 | expr_no_commas '=' expr_no_commas
487a92fe
JM
651 { $$.value = build_modify_expr ($1.value, NOP_EXPR, $3.value);
652 $$.original_code = MODIFY_EXPR;
19d6ff23 653 }
028299c6 654 | expr_no_commas ASSIGN expr_no_commas
487a92fe
JM
655 { $$.value = build_modify_expr ($1.value, $2, $3.value);
656 TREE_NO_WARNING ($$.value) = 1;
657 $$.original_code = ERROR_MARK;
19d6ff23 658 }
028299c6
RS
659 ;
660
661primary:
662 IDENTIFIER
663 {
7e585d16
ZW
664 if (yychar == YYEMPTY)
665 yychar = YYLEX;
487a92fe
JM
666 $$.value = build_external_ref ($1, yychar == '(');
667 $$.original_code = ERROR_MARK;
028299c6
RS
668 }
669 | CONSTANT
487a92fe 670 { $$.value = $1; $$.original_code = ERROR_MARK; }
b84a3874 671 | STRING
916c5919 672 { $$.value = $1; $$.original_code = STRING_CST; }
e6cc3a24 673 | FUNC_NAME
487a92fe
JM
674 { $$.value = fname_decl (C_RID_CODE ($1), $1);
675 $$.original_code = ERROR_MARK; }
84d901be 676 | '(' typename ')' '{'
cedd825f 677 { start_init (NULL_TREE, NULL, 0);
f8893e47 678 $<ttype>$ = groktypename ($2);
ef787822
JM
679 if (C_TYPE_VARIABLE_SIZE ($<ttype>$))
680 {
681 error ("compound literal has variable size");
682 $<ttype>$ = error_mark_node;
683 }
f8893e47 684 really_start_incremental_init ($<ttype>$); }
cedd825f 685 initlist_maybe_comma '}' %prec UNARY
916c5919
JM
686 { struct c_expr init = pop_init_level (0);
687 tree constructor = init.value;
f8893e47 688 tree type = $<ttype>5;
cedd825f 689 finish_init ();
916c5919 690 maybe_warn_string_init (type, init);
cedd825f 691
3f75a254 692 if (pedantic && !flag_isoc99)
b46b8fb4 693 pedwarn ("ISO C90 forbids compound literals");
487a92fe
JM
694 $$.value = build_compound_literal (type, constructor);
695 $$.original_code = ERROR_MARK;
cedd825f 696 }
028299c6 697 | '(' expr ')'
487a92fe
JM
698 { $$.value = $2.value;
699 if (TREE_CODE ($$.value) == MODIFY_EXPR)
700 TREE_NO_WARNING ($$.value) = 1;
701 $$.original_code = ERROR_MARK; }
028299c6 702 | '(' error ')'
487a92fe 703 { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
d0668a73 704 | compstmt_primary_start compstmt_nostart ')'
325c3691
RH
705 { if (pedantic)
706 pedwarn ("ISO C forbids braced-groups within expressions");
487a92fe
JM
707 $$.value = c_finish_stmt_expr ($1);
708 $$.original_code = ERROR_MARK;
d0668a73
RH
709 }
710 | compstmt_primary_start error ')'
325c3691 711 { c_finish_stmt_expr ($1);
487a92fe
JM
712 $$.value = error_mark_node;
713 $$.original_code = ERROR_MARK;
028299c6
RS
714 }
715 | primary '(' exprlist ')' %prec '.'
487a92fe
JM
716 { $$.value = build_function_call ($1.value, $3);
717 $$.original_code = ERROR_MARK; }
2f401cc8 718 | VA_ARG '(' expr_no_commas ',' typename ')'
487a92fe
JM
719 { $$.value = build_va_arg ($3.value, groktypename ($5));
720 $$.original_code = ERROR_MARK; }
d3b4cd6f 721
ee8a6a3e
RH
722 | OFFSETOF '(' typename ','
723 { tree type = groktypename ($3);
724 if (type == error_mark_node)
725 offsetof_base = error_mark_node;
726 else
727 offsetof_base = build1 (INDIRECT_REF, type, NULL);
728 }
729 offsetof_member_designator ')'
730 { $$.value = fold_offsetof ($6);
487a92fe 731 $$.original_code = ERROR_MARK; }
7a3ea201 732 | OFFSETOF '(' error ')'
487a92fe 733 { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
7a3ea201
RH
734 | CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ','
735 expr_no_commas ')'
ecbcf7b3
AH
736 {
737 tree c;
738
487a92fe 739 c = fold ($3.value);
ecbcf7b3
AH
740 STRIP_NOPS (c);
741 if (TREE_CODE (c) != INTEGER_CST)
7a3ea201
RH
742 error ("first argument to __builtin_choose_expr not"
743 " a constant");
ecbcf7b3
AH
744 $$ = integer_zerop (c) ? $7 : $5;
745 }
7a3ea201 746 | CHOOSE_EXPR '(' error ')'
487a92fe 747 { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
7a3ea201 748 | TYPES_COMPATIBLE_P '(' typename ',' typename ')'
ecbcf7b3
AH
749 {
750 tree e1, e2;
751
752 e1 = TYPE_MAIN_VARIANT (groktypename ($3));
753 e2 = TYPE_MAIN_VARIANT (groktypename ($5));
754
487a92fe 755 $$.value = comptypes (e1, e2)
7d60be94
NS
756 ? build_int_cst (NULL_TREE, 1)
757 : build_int_cst (NULL_TREE, 0);
487a92fe 758 $$.original_code = ERROR_MARK;
ecbcf7b3 759 }
7a3ea201 760 | TYPES_COMPATIBLE_P '(' error ')'
487a92fe 761 { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
028299c6 762 | primary '[' expr ']' %prec '.'
487a92fe
JM
763 { $$.value = build_array_ref ($1.value, $3.value);
764 $$.original_code = ERROR_MARK; }
028299c6 765 | primary '.' identifier
487a92fe
JM
766 { $$.value = build_component_ref ($1.value, $3);
767 $$.original_code = ERROR_MARK; }
028299c6
RS
768 | primary POINTSAT identifier
769 {
487a92fe
JM
770 tree expr = build_indirect_ref ($1.value, "->");
771 $$.value = build_component_ref (expr, $3);
772 $$.original_code = ERROR_MARK;
028299c6
RS
773 }
774 | primary PLUSPLUS
487a92fe
JM
775 { $$.value = build_unary_op (POSTINCREMENT_EXPR, $1.value, 0);
776 $$.original_code = ERROR_MARK; }
028299c6 777 | primary MINUSMINUS
487a92fe
JM
778 { $$.value = build_unary_op (POSTDECREMENT_EXPR, $1.value, 0);
779 $$.original_code = ERROR_MARK; }
264fa2db 780@@ifobjc
028299c6 781 | objcmessageexpr
57a6af27 782 { $$.value = objc_build_message_expr ($1);
487a92fe 783 $$.original_code = ERROR_MARK; }
028299c6 784 | objcselectorexpr
57a6af27 785 { $$.value = objc_build_selector_expr ($1);
487a92fe 786 $$.original_code = ERROR_MARK; }
e31c7eec 787 | objcprotocolexpr
57a6af27 788 { $$.value = objc_build_protocol_expr ($1);
487a92fe 789 $$.original_code = ERROR_MARK; }
028299c6 790 | objcencodeexpr
57a6af27 791 { $$.value = objc_build_encode_expr ($1);
487a92fe 792 $$.original_code = ERROR_MARK; }
e6cc3a24 793 | OBJC_STRING
57a6af27 794 { $$.value = objc_build_string_object ($1);
487a92fe 795 $$.original_code = ERROR_MARK; }
264fa2db 796@@end_ifobjc
028299c6
RS
797 ;
798
7a3ea201
RH
799/* This is the second argument to __builtin_offsetof. We must have one
800 identifier, and beyond that we want to accept sub structure and sub
ee8a6a3e 801 array references. */
7a3ea201
RH
802
803offsetof_member_designator:
804 identifier
ee8a6a3e 805 { $$ = build_component_ref (offsetof_base, $1); }
7a3ea201 806 | offsetof_member_designator '.' identifier
ee8a6a3e 807 { $$ = build_component_ref ($1, $3); }
7a3ea201 808 | offsetof_member_designator '[' expr ']'
ee8a6a3e 809 { $$ = build_array_ref ($1, $3.value); }
7a3ea201
RH
810 ;
811
084c4c25 812old_style_parm_decls:
028299c6
RS
813 /* empty */
814 | datadecls
028299c6
RS
815 ;
816
817/* The following are analogous to lineno_decl, decls and decl
818 except that they do not allow nested functions.
819 They are used for old-style parm decls. */
820lineno_datadecl:
374a4e6c 821 save_location datadecl
028299c6
RS
822 { }
823 ;
824
825datadecls:
826 lineno_datadecl
827 | errstmt
828 | datadecls lineno_datadecl
829 | lineno_datadecl errstmt
830 ;
831
084c4c25
RK
832/* We don't allow prefix attributes here because they cause reduce/reduce
833 conflicts: we can't know whether we're parsing a function decl with
834 attribute suffix, or function defn with attribute prefix on first old
835 style parm. */
028299c6 836datadecl:
25d78ace 837 declspecs_ts_nosa setspecs initdecls ';'
4b01f8d8 838 { POP_DECLSPEC_STACK; }
25d78ace 839 | declspecs_nots_nosa setspecs notype_initdecls ';'
4b01f8d8 840 { POP_DECLSPEC_STACK; }
25d78ace 841 | declspecs_ts_nosa ';'
98c3a782 842 { shadow_tag_warned (finish_declspecs ($1), 1);
028299c6 843 pedwarn ("empty declaration"); }
25d78ace 844 | declspecs_nots_nosa ';'
028299c6
RS
845 { pedwarn ("empty declaration"); }
846 ;
847
848/* This combination which saves a lineno before a decl
849 is the normal thing to use, rather than decl itself.
850 This is to avoid shift/reduce conflicts in contexts
851 where statement labels are allowed. */
852lineno_decl:
374a4e6c 853 save_location decl
028299c6
RS
854 { }
855 ;
856
028299c6
RS
857/* records the type and storage class specs to use for processing
858 the declarators that follow.
859 Maintains a stack of outer-level values of current_declspecs,
860 for the sake of parm declarations nested in function declarators. */
861setspecs: /* empty */
4dd7201e 862 { pending_xref_error ();
4b01f8d8 863 PUSH_DECLSPEC_STACK;
deb176fa
JM
864 if ($<dsptype>0)
865 {
866 prefix_attributes = $<dsptype>0->attrs;
867 $<dsptype>0->attrs = NULL_TREE;
868 current_declspecs = $<dsptype>0;
869 }
870 else
871 {
872 prefix_attributes = NULL_TREE;
873 current_declspecs = build_null_declspecs ();
874 }
98c3a782 875 current_declspecs = finish_declspecs (current_declspecs);
4b01f8d8 876 all_prefix_attributes = prefix_attributes; }
34724814
RK
877 ;
878
4b01f8d8
JM
879/* Possibly attributes after a comma, which should reset all_prefix_attributes
880 to prefix_attributes with these ones chained on the front. */
881maybe_resetattrs:
91d231cb
JM
882 maybe_attribute
883 { all_prefix_attributes = chainon ($1, prefix_attributes); }
4b01f8d8
JM
884 ;
885
028299c6 886decl:
25d78ace 887 declspecs_ts setspecs initdecls ';'
4b01f8d8 888 { POP_DECLSPEC_STACK; }
25d78ace 889 | declspecs_nots setspecs notype_initdecls ';'
4b01f8d8 890 { POP_DECLSPEC_STACK; }
25d78ace 891 | declspecs_ts setspecs nested_function
4b01f8d8 892 { POP_DECLSPEC_STACK; }
25d78ace 893 | declspecs_nots setspecs notype_nested_function
4b01f8d8 894 { POP_DECLSPEC_STACK; }
25d78ace 895 | declspecs ';'
98c3a782 896 { shadow_tag (finish_declspecs ($1)); }
72acf258 897 | extension decl
750491fc 898 { RESTORE_EXT_FLAGS ($1); }
028299c6
RS
899 ;
900
25d78ace
JM
901/* A list of declaration specifiers. These are:
902
f79f2651 903 - Storage class specifiers (scspec), which for GCC currently includes
25d78ace
JM
904 function specifiers ("inline").
905
906 - Type specifiers (typespec_*).
907
908 - Type qualifiers (TYPE_QUAL).
909
910 - Attribute specifier lists (attributes).
911
25d78ace
JM
912 The various cases below are classified according to:
913
914 (a) Whether a storage class specifier is included or not; some
915 places in the grammar disallow storage class specifiers (_sc or _nosc).
916
917 (b) Whether a type specifier has been seen; after a type specifier,
918 a typedef name is an identifier to redeclare (_ts or _nots).
919
920 (c) Whether the list starts with an attribute; in certain places,
921 the grammar requires specifiers that don't start with an attribute
922 (_sa or _nosa).
923
924 (d) Whether the list ends with an attribute (or a specifier such that
925 any following attribute would have been parsed as part of that specifier);
926 this avoids shift-reduce conflicts in the parsing of attributes
927 (_ea or _noea).
928
929 TODO:
930
931 (i) Distinguish between function specifiers and storage class specifiers,
932 at least for the purpose of warnings about obsolescent usage.
933
934 (ii) Halve the number of productions here by eliminating the _sc/_nosc
935 distinction and instead checking where required that storage class
936 specifiers aren't present. */
937
028299c6
RS
938/* Declspecs which contain at least one type specifier or typedef name.
939 (Just `const' or `volatile' is not enough.)
deb176fa 940 A typedef'd name following these is taken as a name to be declared. */
028299c6 941
25d78ace
JM
942declspecs_nosc_nots_nosa_noea:
943 TYPE_QUAL
deb176fa 944 { $$ = declspecs_add_qual (build_null_declspecs (), $1); }
25d78ace 945 | declspecs_nosc_nots_nosa_noea TYPE_QUAL
deb176fa 946 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 947 | declspecs_nosc_nots_nosa_ea TYPE_QUAL
deb176fa 948 { $$ = declspecs_add_qual ($1, $2); }
028299c6
RS
949 ;
950
25d78ace
JM
951declspecs_nosc_nots_nosa_ea:
952 declspecs_nosc_nots_nosa_noea attributes
deb176fa 953 { $$ = declspecs_add_attrs ($1, $2); }
25d78ace
JM
954 ;
955
956declspecs_nosc_nots_sa_noea:
957 declspecs_nosc_nots_sa_noea TYPE_QUAL
deb176fa 958 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 959 | declspecs_nosc_nots_sa_ea TYPE_QUAL
deb176fa 960 { $$ = declspecs_add_qual ($1, $2); }
25d78ace
JM
961 ;
962
963declspecs_nosc_nots_sa_ea:
964 attributes
deb176fa 965 { $$ = declspecs_add_attrs (build_null_declspecs (), $1); }
25d78ace 966 | declspecs_nosc_nots_sa_noea attributes
deb176fa 967 { $$ = declspecs_add_attrs ($1, $2); }
25d78ace
JM
968 ;
969
970declspecs_nosc_ts_nosa_noea:
971 typespec_nonattr
deb176fa 972 { $$ = declspecs_add_type (build_null_declspecs (), $1); }
25d78ace 973 | declspecs_nosc_ts_nosa_noea TYPE_QUAL
deb176fa 974 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 975 | declspecs_nosc_ts_nosa_ea TYPE_QUAL
deb176fa 976 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 977 | declspecs_nosc_ts_nosa_noea typespec_reserved_nonattr
deb176fa 978 { $$ = declspecs_add_type ($1, $2); }
25d78ace 979 | declspecs_nosc_ts_nosa_ea typespec_reserved_nonattr
deb176fa 980 { $$ = declspecs_add_type ($1, $2); }
25d78ace 981 | declspecs_nosc_nots_nosa_noea typespec_nonattr
deb176fa 982 { $$ = declspecs_add_type ($1, $2); }
25d78ace 983 | declspecs_nosc_nots_nosa_ea typespec_nonattr
deb176fa 984 { $$ = declspecs_add_type ($1, $2); }
25d78ace
JM
985 ;
986
987declspecs_nosc_ts_nosa_ea:
988 typespec_attr
deb176fa 989 { $$ = declspecs_add_type (build_null_declspecs (), $1); }
25d78ace 990 | declspecs_nosc_ts_nosa_noea attributes
deb176fa 991 { $$ = declspecs_add_attrs ($1, $2); }
25d78ace 992 | declspecs_nosc_ts_nosa_noea typespec_reserved_attr
deb176fa 993 { $$ = declspecs_add_type ($1, $2); }
25d78ace 994 | declspecs_nosc_ts_nosa_ea typespec_reserved_attr
deb176fa 995 { $$ = declspecs_add_type ($1, $2); }
25d78ace 996 | declspecs_nosc_nots_nosa_noea typespec_attr
deb176fa 997 { $$ = declspecs_add_type ($1, $2); }
25d78ace 998 | declspecs_nosc_nots_nosa_ea typespec_attr
deb176fa 999 { $$ = declspecs_add_type ($1, $2); }
25d78ace
JM
1000 ;
1001
1002declspecs_nosc_ts_sa_noea:
1003 declspecs_nosc_ts_sa_noea TYPE_QUAL
deb176fa 1004 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 1005 | declspecs_nosc_ts_sa_ea TYPE_QUAL
deb176fa 1006 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 1007 | declspecs_nosc_ts_sa_noea typespec_reserved_nonattr
deb176fa 1008 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1009 | declspecs_nosc_ts_sa_ea typespec_reserved_nonattr
deb176fa 1010 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1011 | declspecs_nosc_nots_sa_noea typespec_nonattr
deb176fa 1012 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1013 | declspecs_nosc_nots_sa_ea typespec_nonattr
deb176fa 1014 { $$ = declspecs_add_type ($1, $2); }
25d78ace
JM
1015 ;
1016
1017declspecs_nosc_ts_sa_ea:
1018 declspecs_nosc_ts_sa_noea attributes
deb176fa 1019 { $$ = declspecs_add_attrs ($1, $2); }
25d78ace 1020 | declspecs_nosc_ts_sa_noea typespec_reserved_attr
deb176fa 1021 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1022 | declspecs_nosc_ts_sa_ea typespec_reserved_attr
deb176fa 1023 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1024 | declspecs_nosc_nots_sa_noea typespec_attr
deb176fa 1025 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1026 | declspecs_nosc_nots_sa_ea typespec_attr
deb176fa 1027 { $$ = declspecs_add_type ($1, $2); }
25d78ace
JM
1028 ;
1029
1030declspecs_sc_nots_nosa_noea:
f79f2651 1031 scspec
deb176fa 1032 { $$ = declspecs_add_scspec (build_null_declspecs (), $1); }
25d78ace 1033 | declspecs_sc_nots_nosa_noea TYPE_QUAL
deb176fa 1034 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 1035 | declspecs_sc_nots_nosa_ea TYPE_QUAL
deb176fa 1036 { $$ = declspecs_add_qual ($1, $2); }
f79f2651 1037 | declspecs_nosc_nots_nosa_noea scspec
deb176fa 1038 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1039 | declspecs_nosc_nots_nosa_ea scspec
deb176fa 1040 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1041 | declspecs_sc_nots_nosa_noea scspec
deb176fa 1042 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1043 | declspecs_sc_nots_nosa_ea scspec
deb176fa 1044 { $$ = declspecs_add_scspec ($1, $2); }
084c4c25
RK
1045 ;
1046
25d78ace
JM
1047declspecs_sc_nots_nosa_ea:
1048 declspecs_sc_nots_nosa_noea attributes
deb176fa 1049 { $$ = declspecs_add_attrs ($1, $2); }
084c4c25
RK
1050 ;
1051
25d78ace
JM
1052declspecs_sc_nots_sa_noea:
1053 declspecs_sc_nots_sa_noea TYPE_QUAL
deb176fa 1054 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 1055 | declspecs_sc_nots_sa_ea TYPE_QUAL
deb176fa 1056 { $$ = declspecs_add_qual ($1, $2); }
f79f2651 1057 | declspecs_nosc_nots_sa_noea scspec
deb176fa 1058 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1059 | declspecs_nosc_nots_sa_ea scspec
deb176fa 1060 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1061 | declspecs_sc_nots_sa_noea scspec
deb176fa 1062 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1063 | declspecs_sc_nots_sa_ea scspec
deb176fa 1064 { $$ = declspecs_add_scspec ($1, $2); }
028299c6
RS
1065 ;
1066
25d78ace
JM
1067declspecs_sc_nots_sa_ea:
1068 declspecs_sc_nots_sa_noea attributes
deb176fa 1069 { $$ = declspecs_add_attrs ($1, $2); }
084c4c25
RK
1070 ;
1071
25d78ace
JM
1072declspecs_sc_ts_nosa_noea:
1073 declspecs_sc_ts_nosa_noea TYPE_QUAL
deb176fa 1074 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 1075 | declspecs_sc_ts_nosa_ea TYPE_QUAL
deb176fa 1076 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 1077 | declspecs_sc_ts_nosa_noea typespec_reserved_nonattr
deb176fa 1078 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1079 | declspecs_sc_ts_nosa_ea typespec_reserved_nonattr
deb176fa 1080 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1081 | declspecs_sc_nots_nosa_noea typespec_nonattr
deb176fa 1082 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1083 | declspecs_sc_nots_nosa_ea typespec_nonattr
deb176fa 1084 { $$ = declspecs_add_type ($1, $2); }
f79f2651 1085 | declspecs_nosc_ts_nosa_noea scspec
deb176fa 1086 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1087 | declspecs_nosc_ts_nosa_ea scspec
deb176fa 1088 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1089 | declspecs_sc_ts_nosa_noea scspec
deb176fa 1090 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1091 | declspecs_sc_ts_nosa_ea scspec
deb176fa 1092 { $$ = declspecs_add_scspec ($1, $2); }
028299c6
RS
1093 ;
1094
25d78ace
JM
1095declspecs_sc_ts_nosa_ea:
1096 declspecs_sc_ts_nosa_noea attributes
deb176fa 1097 { $$ = declspecs_add_attrs ($1, $2); }
25d78ace 1098 | declspecs_sc_ts_nosa_noea typespec_reserved_attr
deb176fa 1099 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1100 | declspecs_sc_ts_nosa_ea typespec_reserved_attr
deb176fa 1101 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1102 | declspecs_sc_nots_nosa_noea typespec_attr
deb176fa 1103 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1104 | declspecs_sc_nots_nosa_ea typespec_attr
deb176fa 1105 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1106 ;
028299c6 1107
25d78ace
JM
1108declspecs_sc_ts_sa_noea:
1109 declspecs_sc_ts_sa_noea TYPE_QUAL
deb176fa 1110 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 1111 | declspecs_sc_ts_sa_ea TYPE_QUAL
deb176fa 1112 { $$ = declspecs_add_qual ($1, $2); }
25d78ace 1113 | declspecs_sc_ts_sa_noea typespec_reserved_nonattr
deb176fa 1114 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1115 | declspecs_sc_ts_sa_ea typespec_reserved_nonattr
deb176fa 1116 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1117 | declspecs_sc_nots_sa_noea typespec_nonattr
deb176fa 1118 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1119 | declspecs_sc_nots_sa_ea typespec_nonattr
deb176fa 1120 { $$ = declspecs_add_type ($1, $2); }
f79f2651 1121 | declspecs_nosc_ts_sa_noea scspec
deb176fa 1122 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1123 | declspecs_nosc_ts_sa_ea scspec
deb176fa 1124 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1125 | declspecs_sc_ts_sa_noea scspec
deb176fa 1126 { $$ = declspecs_add_scspec ($1, $2); }
f79f2651 1127 | declspecs_sc_ts_sa_ea scspec
deb176fa 1128 { $$ = declspecs_add_scspec ($1, $2); }
25d78ace 1129 ;
028299c6 1130
25d78ace
JM
1131declspecs_sc_ts_sa_ea:
1132 declspecs_sc_ts_sa_noea attributes
deb176fa 1133 { $$ = declspecs_add_attrs ($1, $2); }
25d78ace 1134 | declspecs_sc_ts_sa_noea typespec_reserved_attr
deb176fa 1135 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1136 | declspecs_sc_ts_sa_ea typespec_reserved_attr
deb176fa 1137 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1138 | declspecs_sc_nots_sa_noea typespec_attr
deb176fa 1139 { $$ = declspecs_add_type ($1, $2); }
25d78ace 1140 | declspecs_sc_nots_sa_ea typespec_attr
deb176fa 1141 { $$ = declspecs_add_type ($1, $2); }
028299c6
RS
1142 ;
1143
25d78ace
JM
1144/* Particular useful classes of declspecs. */
1145declspecs_ts:
1146 declspecs_nosc_ts_nosa_noea
1147 | declspecs_nosc_ts_nosa_ea
1148 | declspecs_nosc_ts_sa_noea
1149 | declspecs_nosc_ts_sa_ea
1150 | declspecs_sc_ts_nosa_noea
1151 | declspecs_sc_ts_nosa_ea
1152 | declspecs_sc_ts_sa_noea
1153 | declspecs_sc_ts_sa_ea
1154 ;
1155
1156declspecs_nots:
1157 declspecs_nosc_nots_nosa_noea
1158 | declspecs_nosc_nots_nosa_ea
1159 | declspecs_nosc_nots_sa_noea
1160 | declspecs_nosc_nots_sa_ea
1161 | declspecs_sc_nots_nosa_noea
1162 | declspecs_sc_nots_nosa_ea
1163 | declspecs_sc_nots_sa_noea
1164 | declspecs_sc_nots_sa_ea
1165 ;
1166
1167declspecs_ts_nosa:
1168 declspecs_nosc_ts_nosa_noea
1169 | declspecs_nosc_ts_nosa_ea
1170 | declspecs_sc_ts_nosa_noea
1171 | declspecs_sc_ts_nosa_ea
1172 ;
1173
1174declspecs_nots_nosa:
1175 declspecs_nosc_nots_nosa_noea
1176 | declspecs_nosc_nots_nosa_ea
1177 | declspecs_sc_nots_nosa_noea
1178 | declspecs_sc_nots_nosa_ea
1179 ;
1180
1181declspecs_nosc_ts:
1182 declspecs_nosc_ts_nosa_noea
1183 | declspecs_nosc_ts_nosa_ea
1184 | declspecs_nosc_ts_sa_noea
1185 | declspecs_nosc_ts_sa_ea
1186 ;
1187
1188declspecs_nosc_nots:
1189 declspecs_nosc_nots_nosa_noea
1190 | declspecs_nosc_nots_nosa_ea
1191 | declspecs_nosc_nots_sa_noea
1192 | declspecs_nosc_nots_sa_ea
1193 ;
1194
1195declspecs_nosc:
1196 declspecs_nosc_ts_nosa_noea
1197 | declspecs_nosc_ts_nosa_ea
1198 | declspecs_nosc_ts_sa_noea
1199 | declspecs_nosc_ts_sa_ea
1200 | declspecs_nosc_nots_nosa_noea
1201 | declspecs_nosc_nots_nosa_ea
1202 | declspecs_nosc_nots_sa_noea
1203 | declspecs_nosc_nots_sa_ea
1204 ;
1205
1206declspecs:
1207 declspecs_nosc_nots_nosa_noea
1208 | declspecs_nosc_nots_nosa_ea
1209 | declspecs_nosc_nots_sa_noea
1210 | declspecs_nosc_nots_sa_ea
1211 | declspecs_nosc_ts_nosa_noea
1212 | declspecs_nosc_ts_nosa_ea
1213 | declspecs_nosc_ts_sa_noea
1214 | declspecs_nosc_ts_sa_ea
1215 | declspecs_sc_nots_nosa_noea
1216 | declspecs_sc_nots_nosa_ea
1217 | declspecs_sc_nots_sa_noea
1218 | declspecs_sc_nots_sa_ea
1219 | declspecs_sc_ts_nosa_noea
1220 | declspecs_sc_ts_nosa_ea
1221 | declspecs_sc_ts_sa_noea
1222 | declspecs_sc_ts_sa_ea
1223 ;
1224
91d231cb
JM
1225/* A (possibly empty) sequence of type qualifiers and attributes. */
1226maybe_type_quals_attrs:
25d78ace 1227 /* empty */
deb176fa 1228 { $$ = NULL; }
25d78ace 1229 | declspecs_nosc_nots
91d231cb 1230 { $$ = $1; }
028299c6
RS
1231 ;
1232
25d78ace 1233/* A type specifier (but not a type qualifier).
028299c6 1234 Once we have seen one of these in a declaration,
25d78ace 1235 if a typedef name appears then it is being redeclared.
028299c6 1236
25d78ace
JM
1237 The _reserved versions start with a reserved word and may appear anywhere
1238 in the declaration specifiers; the _nonreserved versions may only
1239 appear before any other type specifiers, and after that are (if names)
1240 being redeclared.
1241
1242 FIXME: should the _nonreserved version be restricted to names being
1243 redeclared only? The other entries there relate only the GNU extensions
1244 and Objective C, and are historically parsed thus, and don't make sense
1245 after other type specifiers, but it might be cleaner to count them as
1246 _reserved.
1247
1248 _attr means: specifiers that either end with attributes,
1249 or are such that any following attributes would
1250 be parsed as part of the specifier.
1251
deb176fa 1252 _nonattr: other specifiers not ending with attributes. */
25d78ace
JM
1253
1254typespec_nonattr:
1255 typespec_reserved_nonattr
1256 | typespec_nonreserved_nonattr
1257 ;
1258
1259typespec_attr:
1260 typespec_reserved_attr
1261 ;
1262
1263typespec_reserved_nonattr:
1264 TYPESPEC
f2e6e530 1265 { OBJC_NEED_RAW_IDENTIFIER (1); }
25d78ace
JM
1266 | structsp_nonattr
1267 ;
1268
1269typespec_reserved_attr:
1270 structsp_attr
1271 ;
1272
1273typespec_nonreserved_nonattr:
1274 TYPENAME
028299c6
RS
1275 { /* For a typedef name, record the meaning, not the name.
1276 In case of `foo foo, bar;'. */
1277 $$ = lookup_name ($1); }
264fa2db 1278@@ifobjc
e31c7eec 1279 | CLASSNAME protocolrefs
6408ef33 1280 { $$ = objc_get_protocol_qualified_type ($1, $2); }
e31c7eec 1281 | OBJECTNAME protocolrefs
6408ef33 1282 { $$ = objc_get_protocol_qualified_type ($1, $2); }
957a1c32
RK
1283
1284/* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1285 - nisse@lysator.liu.se */
1286 | non_empty_protocolrefs
6408ef33 1287 { $$ = objc_get_protocol_qualified_type (NULL_TREE, $1); }
264fa2db 1288@@end_ifobjc
25587e40 1289 | typeof '(' expr ')'
65f0edec 1290 { skip_evaluation--;
bc4b653b 1291 in_typeof--;
487a92fe
JM
1292 if (TREE_CODE ($3.value) == COMPONENT_REF
1293 && DECL_C_BIT_FIELD (TREE_OPERAND ($3.value, 1)))
bda67431 1294 error ("%<typeof%> applied to a bit-field");
bc4b653b
JM
1295 $$ = TREE_TYPE ($3.value);
1296 pop_maybe_used (variably_modified_type_p ($$, NULL_TREE)); }
25587e40 1297 | typeof '(' typename ')'
bc4b653b
JM
1298 { skip_evaluation--; in_typeof--; $$ = groktypename ($3);
1299 pop_maybe_used (variably_modified_type_p ($$, NULL_TREE)); }
028299c6
RS
1300 ;
1301
25d78ace 1302/* typespec_nonreserved_attr does not exist. */
028299c6
RS
1303
1304initdecls:
1305 initdcl
4b01f8d8 1306 | initdecls ',' maybe_resetattrs initdcl
028299c6
RS
1307 ;
1308
1309notype_initdecls:
1310 notype_initdcl
4b01f8d8 1311 | notype_initdecls ',' maybe_resetattrs notype_initdcl
028299c6
RS
1312 ;
1313
028299c6
RS
1314initdcl:
1315 declarator maybeasm maybe_attribute '='
60919bce 1316 { $<ttype>$ = start_decl ($1, current_declspecs, true,
4b01f8d8 1317 chainon ($3, all_prefix_attributes));
6126f4db 1318 start_init ($<ttype>$, $2, global_bindings_p ()); }
028299c6
RS
1319 init
1320/* Note how the declaration of the variable is in effect while its init is parsed! */
42e651a6 1321 { finish_init ();
916c5919
JM
1322 maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6);
1323 finish_decl ($<ttype>5, $6.value, $2); }
028299c6 1324 | declarator maybeasm maybe_attribute
60919bce 1325 { tree d = start_decl ($1, current_declspecs, false,
4b01f8d8 1326 chainon ($3, all_prefix_attributes));
84d901be 1327 finish_decl (d, NULL_TREE, $2);
34724814 1328 }
028299c6
RS
1329 ;
1330
1331notype_initdcl:
1332 notype_declarator maybeasm maybe_attribute '='
60919bce 1333 { $<ttype>$ = start_decl ($1, current_declspecs, true,
4b01f8d8 1334 chainon ($3, all_prefix_attributes));
6126f4db 1335 start_init ($<ttype>$, $2, global_bindings_p ()); }
028299c6
RS
1336 init
1337/* Note how the declaration of the variable is in effect while its init is parsed! */
42e651a6 1338 { finish_init ();
916c5919
JM
1339 maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6);
1340 finish_decl ($<ttype>5, $6.value, $2); }
028299c6 1341 | notype_declarator maybeasm maybe_attribute
60919bce 1342 { tree d = start_decl ($1, current_declspecs, false,
4b01f8d8 1343 chainon ($3, all_prefix_attributes));
028299c6
RS
1344 finish_decl (d, NULL_TREE, $2); }
1345 ;
1346/* the * rules are dummies to accept the Apollo extended syntax
1347 so that the header files compile. */
1348maybe_attribute:
660b43c8 1349 /* empty */
c14bc6db 1350 { $$ = NULL_TREE; }
660b43c8
RK
1351 | attributes
1352 { $$ = $1; }
1353 ;
84d901be 1354
660b43c8
RK
1355attributes:
1356 attribute
1357 { $$ = $1; }
1358 | attributes attribute
1359 { $$ = chainon ($1, $2); }
1360 ;
1361
1362attribute:
21526606
EC
1363 ATTRIBUTE stop_string_translation
1364 '(' '(' attribute_list ')' ')' start_string_translation
1365 { $$ = $5; }
1366 | ATTRIBUTE error start_string_translation
110fce11 1367 { $$ = NULL_TREE; }
660b43c8
RK
1368 ;
1369
1370attribute_list:
1371 attrib
5d7a33dc 1372 { $$ = $1; }
660b43c8 1373 | attribute_list ',' attrib
5d7a33dc 1374 { $$ = chainon ($1, $3); }
660b43c8 1375 ;
84d901be 1376
660b43c8 1377attrib:
028299c6
RS
1378 /* empty */
1379 { $$ = NULL_TREE; }
660b43c8 1380 | any_word
5d7a33dc 1381 { $$ = build_tree_list ($1, NULL_TREE); }
660b43c8 1382 | any_word '(' IDENTIFIER ')'
5d7a33dc 1383 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
660b43c8 1384 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
5d7a33dc 1385 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
f365e8f6 1386 | any_word '(' exprlist ')'
5d7a33dc 1387 { $$ = build_tree_list ($1, $3); }
660b43c8
RK
1388 ;
1389
1390/* This still leaves out most reserved keywords,
1391 shouldn't we include them? */
1392
1393any_word:
1394 identifier
f79f2651 1395 | scspec
660b43c8
RK
1396 | TYPESPEC
1397 | TYPE_QUAL
1398 ;
f79f2651
NB
1399
1400scspec:
1401 STATIC
1402 | SCSPEC
1403 ;
42e651a6
RS
1404\f
1405/* Initializers. `init' is the entry point. */
028299c6
RS
1406
1407init:
1408 expr_no_commas
916c5919 1409 { $$ = $1; }
42e651a6 1410 | '{'
4dd7201e 1411 { really_start_incremental_init (NULL_TREE); }
42e651a6 1412 initlist_maybe_comma '}'
4dd7201e 1413 { $$ = pop_init_level (0); }
028299c6 1414 | error
916c5919 1415 { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
028299c6
RS
1416 ;
1417
42e651a6
RS
1418/* `initlist_maybe_comma' is the guts of an initializer in braces. */
1419initlist_maybe_comma:
1420 /* empty */
1421 { if (pedantic)
89abf8d1 1422 pedwarn ("ISO C forbids empty initializer braces"); }
42e651a6
RS
1423 | initlist1 maybecomma
1424 ;
1425
1426initlist1:
1427 initelt
1428 | initlist1 ',' initelt
1429 ;
1430
1431/* `initelt' is a single element of an initializer.
1432 It may use braces. */
1433initelt:
6f4d7222 1434 designator_list '=' initval
3f75a254 1435 { if (pedantic && !flag_isoc99)
b46b8fb4 1436 pedwarn ("ISO C90 forbids specifying subobject to initialize"); }
6f4d7222 1437 | designator initval
26d4fec7 1438 { if (pedantic)
bda67431 1439 pedwarn ("obsolete use of designated initializer without %<=%>"); }
6f4d7222 1440 | identifier ':'
26d4fec7
JM
1441 { set_init_label ($1);
1442 if (pedantic)
bda67431 1443 pedwarn ("obsolete use of designated initializer with %<:%>"); }
6f4d7222 1444 initval
84d901be 1445 {}
6f4d7222
UD
1446 | initval
1447 ;
1448
1449initval:
1450 '{'
42e651a6
RS
1451 { push_init_level (0); }
1452 initlist_maybe_comma '}'
1453 { process_init_element (pop_init_level (0)); }
6f4d7222 1454 | expr_no_commas
916c5919 1455 { process_init_element ($1); }
42e651a6 1456 | error
6f4d7222
UD
1457 ;
1458
1459designator_list:
1460 designator
1461 | designator_list designator
1462 ;
1463
1464designator:
1465 '.' identifier
1466 { set_init_label ($2); }
6f4d7222 1467 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
487a92fe 1468 { set_init_index ($2.value, $4.value);
26d4fec7
JM
1469 if (pedantic)
1470 pedwarn ("ISO C forbids specifying range of elements to initialize"); }
a78bdb8e 1471 | '[' expr_no_commas ']'
487a92fe 1472 { set_init_index ($2.value, NULL_TREE); }
028299c6 1473 ;
42e651a6 1474\f
028299c6 1475nested_function:
093c7153 1476 declarator
e2ecd91c 1477 { if (pedantic)
89abf8d1 1478 pedwarn ("ISO C forbids nested functions");
e2ecd91c
BS
1479
1480 push_function_context ();
3f75a254
JM
1481 if (!start_function (current_declspecs, $1,
1482 all_prefix_attributes))
028299c6 1483 {
e2ecd91c 1484 pop_function_context ();
028299c6
RS
1485 YYERROR1;
1486 }
0e5921e8 1487 }
093c7153 1488 old_style_parm_decls save_location
b190f239 1489 { tree decl = current_function_decl;
f31686a3 1490 DECL_SOURCE_LOCATION (decl) = $4;
b190f239 1491 store_parm_decls (); }
093c7153
RH
1492 /* This used to use compstmt_or_error. That caused a bug with
1493 input `f(g) int g {}', where the use of YYERROR1 above caused
1494 an error which then was handled by compstmt_or_error. There
1495 followed a repeated execution of that same rule, which called
1496 YYERROR1 again, and so on. */
1497 compstmt
8f17b5c5 1498 { tree decl = current_function_decl;
093c7153 1499 add_stmt ($6);
4a46cbfb 1500 finish_function ();
84d901be 1501 pop_function_context ();
350fae66 1502 add_stmt (build_stmt (DECL_EXPR, decl)); }
028299c6
RS
1503 ;
1504
1505notype_nested_function:
093c7153 1506 notype_declarator
e2ecd91c 1507 { if (pedantic)
89abf8d1 1508 pedwarn ("ISO C forbids nested functions");
e2ecd91c
BS
1509
1510 push_function_context ();
3f75a254
JM
1511 if (!start_function (current_declspecs, $1,
1512 all_prefix_attributes))
028299c6 1513 {
e2ecd91c 1514 pop_function_context ();
028299c6
RS
1515 YYERROR1;
1516 }
0e5921e8 1517 }
093c7153 1518 old_style_parm_decls save_location
b190f239 1519 { tree decl = current_function_decl;
f31686a3 1520 DECL_SOURCE_LOCATION (decl) = $4;
b190f239 1521 store_parm_decls (); }
093c7153
RH
1522 /* This used to use compstmt_or_error. That caused a bug with
1523 input `f(g) int g {}', where the use of YYERROR1 above caused
1524 an error which then was handled by compstmt_or_error. There
1525 followed a repeated execution of that same rule, which called
1526 YYERROR1 again, and so on. */
1527 compstmt
8f17b5c5 1528 { tree decl = current_function_decl;
093c7153 1529 add_stmt ($6);
4a46cbfb 1530 finish_function ();
84d901be 1531 pop_function_context ();
350fae66 1532 add_stmt (build_stmt (DECL_EXPR, decl)); }
028299c6
RS
1533 ;
1534
1535/* Any kind of declarator (thus, all declarators allowed
1536 after an explicit typespec). */
1537
1538declarator:
1539 after_type_declarator
1540 | notype_declarator
1541 ;
1542
1543/* A declarator that is allowed only after an explicit typespec. */
1544
1545after_type_declarator:
91d231cb 1546 '(' maybe_attribute after_type_declarator ')'
00325bce 1547 { $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }
028299c6 1548 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
00325bce 1549 { $$ = build_function_declarator ($3, $1); }
0e03329a 1550 | after_type_declarator array_declarator %prec '.'
00325bce 1551 { $$ = set_array_declarator_inner ($2, $1, false); }
91d231cb 1552 | '*' maybe_type_quals_attrs after_type_declarator %prec UNARY
028299c6
RS
1553 { $$ = make_pointer_declarator ($2, $3); }
1554 | TYPENAME
f8893e47 1555 { $$ = build_id_declarator ($1); }
264fa2db 1556@@ifobjc
e31c7eec 1557 | OBJECTNAME
f8893e47 1558 { $$ = build_id_declarator ($1); }
264fa2db 1559@@end_ifobjc
028299c6
RS
1560 ;
1561
1562/* Kinds of declarator that can appear in a parameter list
1563 in addition to notype_declarator. This is like after_type_declarator
1564 but does not allow a typedef name in parentheses as an identifier
1565 (because it would conflict with a function with that typedef as arg). */
028299c6 1566parm_declarator:
97d24516
JM
1567 parm_declarator_starttypename
1568 | parm_declarator_nostarttypename
1569 ;
1570
1571parm_declarator_starttypename:
1572 parm_declarator_starttypename '(' parmlist_or_identifiers %prec '.'
00325bce 1573 { $$ = build_function_declarator ($3, $1); }
0e03329a 1574 | parm_declarator_starttypename array_declarator %prec '.'
00325bce 1575 { $$ = set_array_declarator_inner ($2, $1, false); }
028299c6 1576 | TYPENAME
f8893e47 1577 { $$ = build_id_declarator ($1); }
264fa2db 1578@@ifobjc
f2e6e530 1579 | OBJECTNAME
f8893e47 1580 { $$ = build_id_declarator ($1); }
264fa2db 1581@@end_ifobjc
028299c6
RS
1582 ;
1583
97d24516
JM
1584parm_declarator_nostarttypename:
1585 parm_declarator_nostarttypename '(' parmlist_or_identifiers %prec '.'
00325bce 1586 { $$ = build_function_declarator ($3, $1); }
0e03329a 1587 | parm_declarator_nostarttypename array_declarator %prec '.'
00325bce 1588 { $$ = set_array_declarator_inner ($2, $1, false); }
91d231cb 1589 | '*' maybe_type_quals_attrs parm_declarator_starttypename %prec UNARY
97d24516 1590 { $$ = make_pointer_declarator ($2, $3); }
91d231cb 1591 | '*' maybe_type_quals_attrs parm_declarator_nostarttypename %prec UNARY
97d24516 1592 { $$ = make_pointer_declarator ($2, $3); }
91d231cb 1593 | '(' maybe_attribute parm_declarator_nostarttypename ')'
00325bce 1594 { $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }
97d24516
JM
1595 ;
1596
028299c6
RS
1597/* A declarator allowed whether or not there has been
1598 an explicit typespec. These cannot redeclare a typedef-name. */
1599
1600notype_declarator:
1601 notype_declarator '(' parmlist_or_identifiers %prec '.'
00325bce 1602 { $$ = build_function_declarator ($3, $1); }
91d231cb 1603 | '(' maybe_attribute notype_declarator ')'
00325bce 1604 { $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }
91d231cb 1605 | '*' maybe_type_quals_attrs notype_declarator %prec UNARY
028299c6 1606 { $$ = make_pointer_declarator ($2, $3); }
0e03329a 1607 | notype_declarator array_declarator %prec '.'
00325bce 1608 { $$ = set_array_declarator_inner ($2, $1, false); }
028299c6 1609 | IDENTIFIER
f8893e47 1610 { $$ = build_id_declarator ($1); }
028299c6
RS
1611 ;
1612
4051959b
JM
1613struct_head:
1614 STRUCT
1615 { $$ = NULL_TREE; }
1616 | STRUCT attributes
1617 { $$ = $2; }
1618 ;
1619
1620union_head:
1621 UNION
1622 { $$ = NULL_TREE; }
1623 | UNION attributes
1624 { $$ = $2; }
1625 ;
1626
1627enum_head:
1628 ENUM
1629 { $$ = NULL_TREE; }
1630 | ENUM attributes
1631 { $$ = $2; }
1632 ;
1633
25d78ace
JM
1634/* structsp_attr: struct/union/enum specifiers that either
1635 end with attributes, or are such that any following attributes would
1636 be parsed as part of the struct/union/enum specifier.
1637
1638 structsp_nonattr: other struct/union/enum specifiers. */
1639
1640structsp_attr:
4051959b 1641 struct_head identifier '{'
028299c6
RS
1642 { $$ = start_struct (RECORD_TYPE, $2);
1643 /* Start scope of tag before parsing components. */
1644 }
84d901be 1645 component_decl_list '}' maybe_attribute
66ea6f4c
RH
1646 { $$ = finish_struct ($<ttype>4, nreverse ($5),
1647 chainon ($1, $7)); }
4051959b 1648 | struct_head '{' component_decl_list '}' maybe_attribute
028299c6 1649 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
66ea6f4c 1650 nreverse ($3), chainon ($1, $5));
5d7a33dc 1651 }
4051959b 1652 | union_head identifier '{'
028299c6 1653 { $$ = start_struct (UNION_TYPE, $2); }
5d7a33dc 1654 component_decl_list '}' maybe_attribute
66ea6f4c
RH
1655 { $$ = finish_struct ($<ttype>4, nreverse ($5),
1656 chainon ($1, $7)); }
4051959b 1657 | union_head '{' component_decl_list '}' maybe_attribute
028299c6 1658 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
66ea6f4c 1659 nreverse ($3), chainon ($1, $5));
af6f30c4 1660 }
4051959b 1661 | enum_head identifier '{'
4dd7201e 1662 { $$ = start_enum ($2); }
41ddaaa4 1663 enumlist maybecomma_warn '}' maybe_attribute
4dd7201e
ZW
1664 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1665 chainon ($1, $8)); }
4051959b 1666 | enum_head '{'
4dd7201e 1667 { $$ = start_enum (NULL_TREE); }
41ddaaa4 1668 enumlist maybecomma_warn '}' maybe_attribute
4dd7201e
ZW
1669 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1670 chainon ($1, $7)); }
25d78ace
JM
1671 ;
1672
1673structsp_nonattr:
1674 struct_head identifier
1675 { $$ = xref_tag (RECORD_TYPE, $2); }
1676 | union_head identifier
1677 { $$ = xref_tag (UNION_TYPE, $2); }
4051959b 1678 | enum_head identifier
0aca1a4f
JM
1679 { $$ = xref_tag (ENUMERAL_TYPE, $2);
1680 /* In ISO C, enumerated types can be referred to
1681 only if already defined. */
1682 if (pedantic && !COMPLETE_TYPE_P ($$))
bda67431 1683 pedwarn ("ISO C forbids forward references to %<enum%> types"); }
028299c6
RS
1684 ;
1685
1686maybecomma:
1687 /* empty */
1688 | ','
1689 ;
1690
1691maybecomma_warn:
1692 /* empty */
1693 | ','
3f75a254 1694 { if (pedantic && !flag_isoc99)
6f4d7222 1695 pedwarn ("comma at end of enumerator list"); }
028299c6
RS
1696 ;
1697
66ea6f4c
RH
1698/* We chain the components in reverse order. They are put in forward
1699 order in structsp_attr.
1700
1701 Note that component_declarator returns single decls, so components
1702 and components_notype can use TREE_CHAIN directly, wheras components
1703 and components_notype return lists (of comma separated decls), so
1704 component_decl_list and component_decl_list2 must use chainon.
1705
1706 The theory behind all this is that there will be more semicolon
1707 separated fields than comma separated fields, and so we'll be
1708 minimizing the number of node traversals required by chainon. */
1709
028299c6
RS
1710component_decl_list:
1711 component_decl_list2
1712 { $$ = $1; }
1713 | component_decl_list2 component_decl
66ea6f4c 1714 { $$ = chainon ($2, $1);
ee759b21 1715 pedwarn ("no semicolon at end of struct or union"); }
028299c6
RS
1716 ;
1717
1718component_decl_list2: /* empty */
1719 { $$ = NULL_TREE; }
1720 | component_decl_list2 component_decl ';'
66ea6f4c 1721 { $$ = chainon ($2, $1); }
028299c6
RS
1722 | component_decl_list2 ';'
1723 { if (pedantic)
1724 pedwarn ("extra semicolon in struct or union specified"); }
264fa2db 1725@@ifobjc
028299c6 1726 /* foo(sizeof(struct{ @defs(ClassName)})); */
f2b5cf97 1727 | AT_DEFS '(' CLASSNAME ')'
57a6af27 1728 { $$ = nreverse (objc_get_class_ivars ($3)); }
264fa2db 1729@@end_ifobjc
028299c6
RS
1730 ;
1731
028299c6 1732component_decl:
25d78ace 1733 declspecs_nosc_ts setspecs components
028299c6 1734 { $$ = $3;
4b01f8d8 1735 POP_DECLSPEC_STACK; }
bc4721b8 1736 | declspecs_nosc_ts setspecs
ffc3b0f9 1737 {
84d901be
AD
1738 /* Support for unnamed structs or unions as members of
1739 structs or unions (which is [a] useful and [b] supports
ffc3b0f9
AH
1740 MS P-SDK). */
1741 if (pedantic)
89abf8d1 1742 pedwarn ("ISO C doesn't support unnamed structs/unions");
ffc3b0f9 1743
f8893e47
JM
1744 $$ = grokfield (build_id_declarator (NULL_TREE),
1745 current_declspecs, NULL_TREE);
4b01f8d8 1746 POP_DECLSPEC_STACK; }
25d78ace 1747 | declspecs_nosc_nots setspecs components_notype
028299c6 1748 { $$ = $3;
4b01f8d8 1749 POP_DECLSPEC_STACK; }
25d78ace 1750 | declspecs_nosc_nots
028299c6 1751 { if (pedantic)
89abf8d1 1752 pedwarn ("ISO C forbids member declarations with no members");
98c3a782 1753 shadow_tag_warned (finish_declspecs ($1), pedantic);
028299c6
RS
1754 $$ = NULL_TREE; }
1755 | error
1756 { $$ = NULL_TREE; }
72acf258
JM
1757 | extension component_decl
1758 { $$ = $2;
750491fc 1759 RESTORE_EXT_FLAGS ($1); }
028299c6
RS
1760 ;
1761
1762components:
1763 component_declarator
4b01f8d8 1764 | components ',' maybe_resetattrs component_declarator
66ea6f4c 1765 { TREE_CHAIN ($4) = $1; $$ = $4; }
25d78ace
JM
1766 ;
1767
1768components_notype:
1769 component_notype_declarator
4b01f8d8 1770 | components_notype ',' maybe_resetattrs component_notype_declarator
66ea6f4c 1771 { TREE_CHAIN ($4) = $1; $$ = $4; }
028299c6
RS
1772 ;
1773
1774component_declarator:
bc4721b8
NS
1775 declarator maybe_attribute
1776 { $$ = grokfield ($1, current_declspecs, NULL_TREE);
1777 decl_attributes (&$$,
1778 chainon ($2, all_prefix_attributes), 0); }
1779 | declarator ':' expr_no_commas maybe_attribute
487a92fe 1780 { $$ = grokfield ($1, current_declspecs, $3.value);
bc4721b8
NS
1781 decl_attributes (&$$,
1782 chainon ($4, all_prefix_attributes), 0); }
1783 | ':' expr_no_commas maybe_attribute
f8893e47
JM
1784 { $$ = grokfield (build_id_declarator (NULL_TREE),
1785 current_declspecs, $2.value);
bc4721b8
NS
1786 decl_attributes (&$$,
1787 chainon ($3, all_prefix_attributes), 0); }
028299c6
RS
1788 ;
1789
25d78ace 1790component_notype_declarator:
bc4721b8
NS
1791 notype_declarator maybe_attribute
1792 { $$ = grokfield ($1, current_declspecs, NULL_TREE);
1793 decl_attributes (&$$,
1794 chainon ($2, all_prefix_attributes), 0); }
1795 | notype_declarator ':' expr_no_commas maybe_attribute
487a92fe 1796 { $$ = grokfield ($1, current_declspecs, $3.value);
bc4721b8
NS
1797 decl_attributes (&$$,
1798 chainon ($4, all_prefix_attributes), 0); }
1799 | ':' expr_no_commas maybe_attribute
f8893e47
JM
1800 { $$ = grokfield (build_id_declarator (NULL_TREE),
1801 current_declspecs, $2.value);
bc4721b8
NS
1802 decl_attributes (&$$,
1803 chainon ($3, all_prefix_attributes), 0); }
25d78ace
JM
1804 ;
1805
028299c6 1806/* We chain the enumerators in reverse order.
66ea6f4c 1807 They are put in forward order in structsp_attr. */
028299c6
RS
1808
1809enumlist:
1810 enumerator
1811 | enumlist ',' enumerator
a0d074e1
RK
1812 { if ($1 == error_mark_node)
1813 $$ = $1;
1814 else
66ea6f4c 1815 TREE_CHAIN ($3) = $1, $$ = $3; }
adc3b521
RS
1816 | error
1817 { $$ = error_mark_node; }
028299c6
RS
1818 ;
1819
1820
1821enumerator:
1822 identifier
1823 { $$ = build_enumerator ($1, NULL_TREE); }
1824 | identifier '=' expr_no_commas
487a92fe 1825 { $$ = build_enumerator ($1, $3.value); }
028299c6
RS
1826 ;
1827
1828typename:
25d78ace 1829 declspecs_nosc
d3b4cd6f 1830 { pending_xref_error ();
98c3a782 1831 $<dsptype>$ = finish_declspecs ($1); }
0aca1a4f 1832 absdcl
f8893e47 1833 { $$ = XOBNEW (&parser_obstack, struct c_type_name);
deb176fa 1834 $$->specs = $<dsptype>2;
f8893e47 1835 $$->declarator = $3; }
028299c6
RS
1836 ;
1837
1838absdcl: /* an absolute declarator */
1839 /* empty */
f8893e47 1840 { $$ = build_id_declarator (NULL_TREE); }
028299c6
RS
1841 | absdcl1
1842 ;
1843
25d78ace
JM
1844absdcl_maybe_attribute: /* absdcl maybe_attribute, but not just attributes */
1845 /* empty */
00325bce 1846 { $$ = build_c_parm (current_declspecs, all_prefix_attributes,
f8893e47 1847 build_id_declarator (NULL_TREE)); }
25d78ace 1848 | absdcl1
00325bce
JM
1849 { $$ = build_c_parm (current_declspecs, all_prefix_attributes,
1850 $1); }
25d78ace 1851 | absdcl1_noea attributes
00325bce
JM
1852 { $$ = build_c_parm (current_declspecs,
1853 chainon ($2, all_prefix_attributes),
1854 $1); }
028299c6
RS
1855 ;
1856
25d78ace
JM
1857absdcl1: /* a nonempty absolute declarator */
1858 absdcl1_ea
1859 | absdcl1_noea
028299c6
RS
1860 ;
1861
25d78ace
JM
1862absdcl1_noea:
1863 direct_absdcl1
91d231cb 1864 | '*' maybe_type_quals_attrs absdcl1_noea
028299c6 1865 { $$ = make_pointer_declarator ($2, $3); }
25d78ace
JM
1866 ;
1867
1868absdcl1_ea:
91d231cb 1869 '*' maybe_type_quals_attrs
f8893e47
JM
1870 { $$ = make_pointer_declarator
1871 ($2, build_id_declarator (NULL_TREE)); }
91d231cb 1872 | '*' maybe_type_quals_attrs absdcl1_ea
25d78ace
JM
1873 { $$ = make_pointer_declarator ($2, $3); }
1874 ;
1875
1876direct_absdcl1:
91d231cb 1877 '(' maybe_attribute absdcl1 ')'
00325bce 1878 { $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }
25d78ace 1879 | direct_absdcl1 '(' parmlist
00325bce 1880 { $$ = build_function_declarator ($3, $1); }
0e03329a 1881 | direct_absdcl1 array_declarator
00325bce 1882 { $$ = set_array_declarator_inner ($2, $1, true); }
25d78ace 1883 | '(' parmlist
f8893e47
JM
1884 { $$ = build_function_declarator
1885 ($2, build_id_declarator (NULL_TREE)); }
0e03329a 1886 | array_declarator
f8893e47
JM
1887 { $$ = set_array_declarator_inner
1888 ($1, build_id_declarator (NULL_TREE), true); }
0e03329a
JM
1889 ;
1890
1891/* The [...] part of a declarator for an array type. */
1892
1893array_declarator:
88682ff6 1894 '[' maybe_type_quals_attrs expr_no_commas ']'
60919bce 1895 { $$ = build_array_declarator ($3.value, $2, false, false); }
f79f2651 1896 | '[' maybe_type_quals_attrs ']'
60919bce 1897 { $$ = build_array_declarator (NULL_TREE, $2, false, false); }
f79f2651 1898 | '[' maybe_type_quals_attrs '*' ']'
60919bce 1899 { $$ = build_array_declarator (NULL_TREE, $2, false, true); }
88682ff6 1900 | '[' STATIC maybe_type_quals_attrs expr_no_commas ']'
60919bce 1901 { $$ = build_array_declarator ($4.value, $3, true, false); }
f79f2651 1902 /* declspecs_nosc_nots is a synonym for type_quals_attrs. */
88682ff6 1903 | '[' declspecs_nosc_nots STATIC expr_no_commas ']'
60919bce 1904 { $$ = build_array_declarator ($4.value, $2, true, false); }
0e03329a 1905 ;
028299c6 1906
b7438415
JM
1907/* A nonempty series of declarations and statements (possibly followed by
1908 some labels) that can form the body of a compound statement.
1909 NOTE: we don't allow labels on declarations; this might seem like a
1910 natural extension, but there would be a conflict between attributes
1911 on the label and prefix attributes on the declaration. */
028299c6 1912
b7438415
JM
1913stmts_and_decls:
1914 lineno_stmt_decl_or_labels_ending_stmt
1915 | lineno_stmt_decl_or_labels_ending_decl
1916 | lineno_stmt_decl_or_labels_ending_label
28a19afc 1917 {
f560bf91 1918 error ("label at end of compound statement");
28a19afc 1919 }
b7438415 1920 | lineno_stmt_decl_or_labels_ending_error
28a19afc
RK
1921 ;
1922
b7438415
JM
1923lineno_stmt_decl_or_labels_ending_stmt:
1924 lineno_stmt
1925 | lineno_stmt_decl_or_labels_ending_stmt lineno_stmt
1926 | lineno_stmt_decl_or_labels_ending_decl lineno_stmt
1927 | lineno_stmt_decl_or_labels_ending_label lineno_stmt
1928 | lineno_stmt_decl_or_labels_ending_error lineno_stmt
028299c6
RS
1929 ;
1930
b7438415
JM
1931lineno_stmt_decl_or_labels_ending_decl:
1932 lineno_decl
1933 | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
85617eba
HPN
1934 {
1935 if ((pedantic && !flag_isoc99)
1936 || warn_declaration_after_statement)
1937 pedwarn_c90 ("ISO C90 forbids mixed declarations and code");
1938 }
b7438415
JM
1939 | lineno_stmt_decl_or_labels_ending_decl lineno_decl
1940 | lineno_stmt_decl_or_labels_ending_error lineno_decl
1941 ;
1942
1943lineno_stmt_decl_or_labels_ending_label:
1944 lineno_label
1945 | lineno_stmt_decl_or_labels_ending_stmt lineno_label
1946 | lineno_stmt_decl_or_labels_ending_decl lineno_label
1947 | lineno_stmt_decl_or_labels_ending_label lineno_label
1948 | lineno_stmt_decl_or_labels_ending_error lineno_label
1949 ;
1950
1951lineno_stmt_decl_or_labels_ending_error:
1952 errstmt
1953 | lineno_stmt_decl_or_labels errstmt
1954 ;
1955
1956lineno_stmt_decl_or_labels:
1957 lineno_stmt_decl_or_labels_ending_stmt
1958 | lineno_stmt_decl_or_labels_ending_decl
1959 | lineno_stmt_decl_or_labels_ending_label
1960 | lineno_stmt_decl_or_labels_ending_error
028299c6
RS
1961 ;
1962
1963errstmt: error ';'
1964 ;
1965
444ca59f
JM
1966/* Start and end blocks created for the new scopes of C99. */
1967c99_block_start: /* empty */
325c3691 1968 { $$ = c_begin_compound_stmt (flag_isoc99); }
444ca59f
JM
1969 ;
1970
028299c6
RS
1971/* Read zero or more forward-declarations for labels
1972 that nested functions can jump to. */
1973maybe_label_decls:
1974 /* empty */
1975 | label_decls
1976 { if (pedantic)
89abf8d1 1977 pedwarn ("ISO C forbids label declarations"); }
028299c6
RS
1978 ;
1979
1980label_decls:
1981 label_decl
1982 | label_decls label_decl
1983 ;
1984
1985label_decl:
1986 LABEL identifiers_or_typenames ';'
1987 { tree link;
1988 for (link = $2; link; link = TREE_CHAIN (link))
1989 {
14e33ee8 1990 tree label = declare_label (TREE_VALUE (link));
028299c6 1991 C_DECLARED_LABEL_FLAG (label) = 1;
350fae66 1992 add_stmt (build_stmt (DECL_EXPR, label));
028299c6
RS
1993 }
1994 }
1995 ;
1996
1997/* This is the body of a function definition.
1998 It causes syntax errors to ignore to the next openbrace. */
1999compstmt_or_error:
2000 compstmt
093c7153 2001 { add_stmt ($1); }
028299c6
RS
2002 | error compstmt
2003 ;
2004
506e2710 2005compstmt_start: '{' { $$ = c_begin_compound_stmt (true); }
7d6f6369 2006 ;
818e50a5 2007
d0668a73 2008compstmt_nostart: '}'
325c3691 2009 | maybe_label_decls compstmt_contents_nonempty '}'
028299c6
RS
2010 ;
2011
b7438415
JM
2012compstmt_contents_nonempty:
2013 stmts_and_decls
2014 | error
2015 ;
2016
d0668a73
RH
2017compstmt_primary_start:
2018 '(' '{'
2019 { if (current_function_decl == 0)
2020 {
325c3691
RH
2021 error ("braced-group within expression allowed "
2022 "only inside a function");
d0668a73
RH
2023 YYERROR;
2024 }
325c3691 2025 $$ = c_begin_stmt_expr ();
d0668a73 2026 }
7d6f6369 2027 ;
d0668a73
RH
2028
2029compstmt: compstmt_start compstmt_nostart
093c7153 2030 { $$ = c_end_compound_stmt ($1, true); }
d0668a73
RH
2031 ;
2032
0e5921e8
ZW
2033/* The forced readahead in here is because we might be at the end of a
2034 line, and the line and file won't be bumped until yylex absorbs the
2035 first token on the next line. */
028299c6 2036
374a4e6c 2037save_location:
0e5921e8
ZW
2038 { if (yychar == YYEMPTY)
2039 yychar = YYLEX;
374a4e6c 2040 $$ = input_location; }
028299c6
RS
2041 ;
2042
506e2710
RH
2043lineno_labels:
2044 /* empty */
2045 | lineno_labels lineno_label
028299c6
RS
2046 ;
2047
506e2710 2048/* A labeled statement. In C99 it also generates an implicit block. */
444ca59f 2049c99_block_lineno_labeled_stmt:
506e2710 2050 c99_block_start lineno_labels lineno_stmt
325c3691 2051 { $$ = c_end_compound_stmt ($1, flag_isoc99); }
444ca59f
JM
2052 ;
2053
b7438415 2054lineno_stmt:
374a4e6c 2055 save_location stmt
110fce11 2056 {
325c3691 2057 /* Two cases cannot and do not have line numbers associated:
110fce11 2058 If stmt is degenerate, such as "2;", then stmt is an
325c3691
RH
2059 INTEGER_CST, which cannot hold line numbers. But that's
2060 ok because the statement will either be changed to a
2061 MODIFY_EXPR during gimplification of the statement expr,
2062 or discarded. If stmt was compound, but without new
2063 variables, we will have skipped the creation of a BIND
2064 and will have a bare STATEMENT_LIST. But that's ok
2065 because (recursively) all of the component statments
2066 should already have line numbers assigned. */
2067 if ($2 && EXPR_P ($2))
a281759f 2068 SET_EXPR_LOCATION ($2, $1);
64094f6a 2069 }
028299c6
RS
2070 ;
2071
b7438415 2072lineno_label:
374a4e6c 2073 save_location label
a281759f 2074 { if ($2) SET_EXPR_LOCATION ($2, $1); }
028299c6
RS
2075 ;
2076
506e2710 2077condition: save_location expr
487a92fe 2078 { $$ = lang_hooks.truthvalue_conversion ($2.value);
506e2710 2079 if (EXPR_P ($$))
a281759f 2080 SET_EXPR_LOCATION ($$, $1); }
506e2710
RH
2081 ;
2082
2083/* Implement -Wparenthesis by special casing IF statement directly nested
2084 within IF statement. This requires some amount of duplication of the
2085 productions under c99_block_lineno_labeled_stmt in order to work out.
2086 But it's still likely more maintainable than lots of state outside the
2087 parser... */
2088
2089if_statement_1:
2090 c99_block_start lineno_labels if_statement
2091 { $$ = c_end_compound_stmt ($1, flag_isoc99); }
2092 ;
2093
2094if_statement_2:
2095 c99_block_start lineno_labels ';'
2096 { if (extra_warnings)
2097 add_stmt (build (NOP_EXPR, NULL_TREE, NULL_TREE));
2098 $$ = c_end_compound_stmt ($1, flag_isoc99); }
2099 | c99_block_lineno_labeled_stmt
2100 ;
2101
2102if_statement:
2103 IF c99_block_start save_location '(' condition ')'
2104 if_statement_1 ELSE if_statement_2
2105 { c_finish_if_stmt ($3, $5, $7, $9, true);
2106 add_stmt (c_end_compound_stmt ($2, flag_isoc99)); }
2107 | IF c99_block_start save_location '(' condition ')'
2108 if_statement_2 ELSE if_statement_2
2109 { c_finish_if_stmt ($3, $5, $7, $9, false);
2110 add_stmt (c_end_compound_stmt ($2, flag_isoc99)); }
2111 | IF c99_block_start save_location '(' condition ')'
2112 if_statement_1 %prec IF
2113 { c_finish_if_stmt ($3, $5, $7, NULL, true);
2114 add_stmt (c_end_compound_stmt ($2, flag_isoc99)); }
2115 | IF c99_block_start save_location '(' condition ')'
2116 if_statement_2 %prec IF
2117 { c_finish_if_stmt ($3, $5, $7, NULL, false);
2118 add_stmt (c_end_compound_stmt ($2, flag_isoc99)); }
2119 ;
2120
2121start_break: /* empty */
2122 { $$ = c_break_label; c_break_label = NULL; }
2123 ;
2124
2125start_continue: /* empty */
2126 { $$ = c_cont_label; c_cont_label = NULL; }
2127 ;
2128
2129while_statement:
2130 WHILE c99_block_start save_location '(' condition ')'
2131 start_break start_continue c99_block_lineno_labeled_stmt
2132 { c_finish_loop ($3, $5, NULL, $9, c_break_label,
2133 c_cont_label, true);
2134 add_stmt (c_end_compound_stmt ($2, flag_isoc99));
2135 c_break_label = $7; c_cont_label = $8; }
2136 ;
2137
2138do_statement:
2139 DO c99_block_start save_location start_break start_continue
2140 c99_block_lineno_labeled_stmt WHILE
2141 { $<ttype>$ = c_break_label; c_break_label = $4; }
2142 { $<ttype>$ = c_cont_label; c_cont_label = $5; }
2143 '(' condition ')' ';'
2144 { c_finish_loop ($3, $11, NULL, $6, $<ttype>8,
2145 $<ttype>9, false);
2146 add_stmt (c_end_compound_stmt ($2, flag_isoc99)); }
2147 ;
2148
2149xexpr:
2150 /* empty */
2151 { $$ = NULL_TREE; }
2152 | expr
487a92fe 2153 { $$ = $1.value; }
444ca59f
JM
2154 ;
2155
77c4d6c0
JM
2156for_init_stmt:
2157 xexpr ';'
3a5b9284 2158 { c_finish_expr_stmt ($1); }
77c4d6c0
JM
2159 | decl
2160 { check_for_loop_decls (); }
2161 ;
2162
506e2710
RH
2163for_cond_expr: save_location xexpr
2164 { if ($2)
2165 {
2166 $$ = lang_hooks.truthvalue_conversion ($2);
2167 if (EXPR_P ($$))
a281759f 2168 SET_EXPR_LOCATION ($$, $1);
506e2710
RH
2169 }
2170 else
2171 $$ = NULL;
2172 }
9f0e2d86
ZW
2173 ;
2174
506e2710
RH
2175for_incr_expr: xexpr
2176 { $$ = c_process_expr_stmt ($1); }
2177 ;
2178
2179for_statement:
2180 FOR c99_block_start '(' for_init_stmt
2181 save_location for_cond_expr ';' for_incr_expr ')'
2182 start_break start_continue c99_block_lineno_labeled_stmt
2183 { c_finish_loop ($5, $6, $8, $12, c_break_label,
2184 c_cont_label, true);
2185 add_stmt (c_end_compound_stmt ($2, flag_isoc99));
2186 c_break_label = $10; c_cont_label = $11; }
2187 ;
2188
2189switch_statement:
2190 SWITCH c99_block_start '(' expr ')'
487a92fe 2191 { $<ttype>$ = c_start_case ($4.value); }
506e2710
RH
2192 start_break c99_block_lineno_labeled_stmt
2193 { c_finish_case ($8);
2194 if (c_break_label)
2195 add_stmt (build (LABEL_EXPR, void_type_node,
2196 c_break_label));
2197 c_break_label = $7;
2198 add_stmt (c_end_compound_stmt ($2, flag_isoc99)); }
2199 ;
2200
2201/* Parse a single real statement, not including any labels or compounds. */
2202stmt_nocomp:
2203 expr ';'
487a92fe 2204 { $$ = c_finish_expr_stmt ($1.value); }
506e2710
RH
2205 | if_statement
2206 { $$ = NULL_TREE; }
2207 | while_statement
2208 { $$ = NULL_TREE; }
2209 | do_statement
2210 { $$ = NULL_TREE; }
2211 | for_statement
2212 { $$ = NULL_TREE; }
2213 | switch_statement
2214 { $$ = NULL_TREE; }
028299c6 2215 | BREAK ';'
506e2710 2216 { $$ = c_finish_bc_stmt (&c_break_label, true); }
028299c6 2217 | CONTINUE ';'
506e2710 2218 { $$ = c_finish_bc_stmt (&c_cont_label, false); }
028299c6 2219 | RETURN ';'
506e2710 2220 { $$ = c_finish_return (NULL_TREE); }
028299c6 2221 | RETURN expr ';'
487a92fe 2222 { $$ = c_finish_return ($2.value); }
9f0e2d86 2223 | asm_stmt
028299c6 2224 | GOTO identifier ';'
506e2710 2225 { $$ = c_finish_goto_label ($2); }
028299c6 2226 | GOTO '*' expr ';'
487a92fe 2227 { $$ = c_finish_goto_ptr ($3.value); }
028299c6 2228 | ';'
506e2710 2229 { $$ = NULL_TREE; }
264fa2db
ZL
2230@@ifobjc
2231 | AT_THROW expr ';'
487a92fe 2232 { $$ = objc_build_throw_stmt ($2.value); }
264fa2db 2233 | AT_THROW ';'
506e2710 2234 { $$ = objc_build_throw_stmt (NULL_TREE); }
e13e48e7 2235 | objc_try_catch_stmt
506e2710
RH
2236 { $$ = NULL_TREE; }
2237 | AT_SYNCHRONIZED save_location '(' expr ')' compstmt
487a92fe 2238 { objc_build_synchronized ($2, $4.value, $6); $$ = NULL_TREE; }
264fa2db
ZL
2239 ;
2240
093c7153
RH
2241objc_catch_prefix:
2242 AT_CATCH '(' parm ')'
6408ef33 2243 { objc_begin_catch_clause (grokparm ($3)); }
264fa2db
ZL
2244 ;
2245
093c7153
RH
2246objc_catch_clause:
2247 objc_catch_prefix '{' compstmt_nostart
2248 { objc_finish_catch_clause (); }
2249 | objc_catch_prefix '{' error '}'
2250 { objc_finish_catch_clause (); }
2251 ;
264fa2db 2252
093c7153
RH
2253objc_opt_catch_list:
2254 /* empty */
2255 | objc_opt_catch_list objc_catch_clause
264fa2db 2256 ;
e13e48e7 2257
093c7153
RH
2258objc_try_catch_clause:
2259 AT_TRY save_location compstmt
506e2710 2260 { objc_begin_try_stmt ($2, $3); }
093c7153 2261 objc_opt_catch_list
264fa2db
ZL
2262 ;
2263
093c7153
RH
2264objc_finally_clause:
2265 AT_FINALLY save_location compstmt
2266 { objc_build_finally_clause ($2, $3); }
264fa2db
ZL
2267 ;
2268
093c7153
RH
2269objc_try_catch_stmt:
2270 objc_try_catch_clause
2271 { objc_finish_try_stmt (); }
2272 | objc_try_catch_clause objc_finally_clause
2273 { objc_finish_try_stmt (); }
264fa2db 2274@@end_ifobjc
028299c6
RS
2275 ;
2276
506e2710
RH
2277/* Parse a single or compound real statement, not including any labels. */
2278stmt:
2279 compstmt
2280 { add_stmt ($1); $$ = NULL_TREE; }
2281 | stmt_nocomp
2282 ;
2283
028299c6
RS
2284/* Any kind of label, including jump labels and case labels.
2285 ANSI C accepts labels only before statements, but we allow them
2286 also at the end of a compound statement. */
2287
b00e5f0d 2288label: CASE expr_no_commas ':'
487a92fe 2289 { $$ = do_case ($2.value, NULL_TREE); }
b00e5f0d 2290 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
487a92fe 2291 { $$ = do_case ($2.value, $4.value); }
028299c6 2292 | DEFAULT ':'
506e2710 2293 { $$ = do_case (NULL_TREE, NULL_TREE); }
374a4e6c 2294 | identifier save_location ':' maybe_attribute
5b030314 2295 { tree label = define_label ($2, $1);
028299c6 2296 if (label)
736b02fd 2297 {
374a4e6c 2298 decl_attributes (&label, $4, 0);
9e14e18f 2299 $$ = add_stmt (build_stmt (LABEL_EXPR, label));
736b02fd 2300 }
64094f6a
RH
2301 else
2302 $$ = NULL_TREE;
0e5921e8 2303 }
028299c6
RS
2304 ;
2305
9f0e2d86 2306/* Asm expressions and statements */
028299c6 2307
9f0e2d86
ZW
2308/* simple_asm_expr is used in restricted contexts, where a full
2309 expression with inputs and outputs does not make sense. */
2310simple_asm_expr:
21526606
EC
2311 ASM_KEYWORD stop_string_translation
2312 '(' STRING ')' start_string_translation
2313 { $$ = $4; }
9f0e2d86
ZW
2314 ;
2315
2316/* maybeasm: used for assembly names for declarations */
2317maybeasm:
2318 /* empty */
0de456a5 2319 { $$ = NULL_TREE; }
9f0e2d86 2320 | simple_asm_expr
028299c6
RS
2321 ;
2322
9f0e2d86
ZW
2323/* asmdef: asm() outside a function body. */
2324asmdef:
2325 simple_asm_expr ';'
2326 { assemble_asm ($1); }
21526606
EC
2327 | ASM_KEYWORD error start_string_translation ';'
2328 {}
9f0e2d86
ZW
2329 ;
2330
2331/* Full-blown asm statement with inputs, outputs, clobbers, and
2332 volatile tag allowed. */
2333asm_stmt:
21526606
EC
2334 ASM_KEYWORD maybe_volatile stop_string_translation
2335 '(' asm_argument ')' start_string_translation ';'
506e2710 2336 { $$ = build_asm_stmt ($2, $5); }
9f0e2d86
ZW
2337 ;
2338
2339asm_argument:
2340 /* no operands */
2341 STRING
2342 { $$ = build_asm_expr ($1, 0, 0, 0, true); }
2343 /* output operands */
2344 | STRING ':' asm_operands
2345 { $$ = build_asm_expr ($1, $3, 0, 0, false); }
2346 /* output and input operands */
2347 | STRING ':' asm_operands ':' asm_operands
2348 { $$ = build_asm_expr ($1, $3, $5, 0, false); }
2349 /* output and input operands and clobbers */
2350 | STRING ':' asm_operands ':' asm_operands ':' asm_clobbers
2351 { $$ = build_asm_expr ($1, $3, $5, $7, false); }
2352 ;
2353
2354/* Either 'volatile' or nothing. First thing in an `asm' statement. */
2355
2356maybe_volatile:
028299c6 2357 /* empty */
9f0e2d86
ZW
2358 { $$ = 0; }
2359 | TYPE_QUAL
2360 { if ($1 != ridpointers[RID_VOLATILE])
2361 {
2362 warning ("%E qualifier ignored on asm", $1);
2363 $$ = 0;
2364 }
2365 else
2366 $$ = $1;
2367 }
028299c6
RS
2368 ;
2369
2370/* These are the operands other than the first string and colon
2371 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2372asm_operands: /* empty */
2373 { $$ = NULL_TREE; }
2374 | nonnull_asm_operands
2375 ;
2376
2377nonnull_asm_operands:
2378 asm_operand
2379 | nonnull_asm_operands ',' asm_operand
2380 { $$ = chainon ($1, $3); }
2381 ;
2382
2383asm_operand:
21526606 2384 STRING start_string_translation '(' expr ')' stop_string_translation
487a92fe
JM
2385 { $$ = build_tree_list (build_tree_list (NULL_TREE, $1),
2386 $4.value); }
21526606
EC
2387 | '[' identifier ']' STRING start_string_translation
2388 '(' expr ')' stop_string_translation
fc552851
RS
2389 { $2 = build_string (IDENTIFIER_LENGTH ($2),
2390 IDENTIFIER_POINTER ($2));
487a92fe 2391 $$ = build_tree_list (build_tree_list ($2, $4), $7.value); }
028299c6
RS
2392 ;
2393
2394asm_clobbers:
b84a3874
RH
2395 STRING
2396 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
2397 | asm_clobbers ',' STRING
2398 { $$ = tree_cons (NULL_TREE, $3, $1); }
028299c6 2399 ;
21526606
EC
2400
2401stop_string_translation:
0173bb6f 2402 { c_lex_string_translate = 0; }
21526606
EC
2403 ;
2404
2405start_string_translation:
0173bb6f 2406 { c_lex_string_translate = 1; }
21526606
EC
2407 ;
2408
028299c6
RS
2409\f
2410/* This is what appears inside the parens in a function declarator.
25d78ace
JM
2411 Its value is a list of ..._TYPE nodes. Attributes must appear here
2412 to avoid a conflict with their appearance after an open parenthesis
2413 in an abstract declarator, as in
2414 "void bar (int (__attribute__((__mode__(SI))) int foo));". */
028299c6 2415parmlist:
25d78ace 2416 maybe_attribute
f75fbaf7 2417 { push_scope ();
eb1dfbb2 2418 declare_parm_level (); }
028299c6 2419 parmlist_1
25d78ace 2420 { $$ = $3;
f75fbaf7 2421 pop_scope (); }
028299c6
RS
2422 ;
2423
2424parmlist_1:
2425 parmlist_2 ')'
2426 | parms ';'
55d54003 2427 { mark_forward_parm_decls (); }
25d78ace
JM
2428 maybe_attribute
2429 { /* Dummy action so attributes are in known place
2430 on parser stack. */ }
028299c6 2431 parmlist_1
25d78ace 2432 { $$ = $6; }
028299c6 2433 | error ')'
f8893e47
JM
2434 { $$ = XOBNEW (&parser_obstack, struct c_arg_info);
2435 $$->parms = 0;
2436 $$->tags = 0;
2437 $$->types = 0;
2438 $$->others = 0; }
028299c6
RS
2439 ;
2440
2441/* This is what appears inside the parens in a function declarator.
f8893e47 2442 Its value is represented in the format that grokdeclarator expects. */
028299c6 2443parmlist_2: /* empty */
f8893e47
JM
2444 { $$ = XOBNEW (&parser_obstack, struct c_arg_info);
2445 $$->parms = 0;
2446 $$->tags = 0;
2447 $$->types = 0;
2448 $$->others = 0; }
028299c6 2449 | ELLIPSIS
f8893e47
JM
2450 { $$ = XOBNEW (&parser_obstack, struct c_arg_info);
2451 $$->parms = 0;
2452 $$->tags = 0;
2453 $$->others = 0;
f75fbaf7 2454 /* Suppress -Wold-style-definition for this case. */
f8893e47 2455 $$->types = error_mark_node;
bda67431 2456 error ("ISO C requires a named argument before %<...%>");
028299c6
RS
2457 }
2458 | parms
f75fbaf7 2459 { $$ = get_parm_info (/*ellipsis=*/false); }
028299c6 2460 | parms ',' ELLIPSIS
f75fbaf7 2461 { $$ = get_parm_info (/*ellipsis=*/true); }
028299c6
RS
2462 ;
2463
2464parms:
25d78ace 2465 firstparm
028299c6
RS
2466 { push_parm_decl ($1); }
2467 | parms ',' parm
2468 { push_parm_decl ($3); }
2469 ;
2470
2471/* A single parameter declaration or parameter type name,
2472 as found in a parmlist. */
2473parm:
25d78ace 2474 declspecs_ts setspecs parm_declarator maybe_attribute
00325bce
JM
2475 { $$ = build_c_parm (current_declspecs,
2476 chainon ($4, all_prefix_attributes), $3);
4b01f8d8 2477 POP_DECLSPEC_STACK; }
25d78ace 2478 | declspecs_ts setspecs notype_declarator maybe_attribute
00325bce
JM
2479 { $$ = build_c_parm (current_declspecs,
2480 chainon ($4, all_prefix_attributes), $3);
4b01f8d8 2481 POP_DECLSPEC_STACK; }
25d78ace
JM
2482 | declspecs_ts setspecs absdcl_maybe_attribute
2483 { $$ = $3;
4b01f8d8 2484 POP_DECLSPEC_STACK; }
25d78ace 2485 | declspecs_nots setspecs notype_declarator maybe_attribute
00325bce
JM
2486 { $$ = build_c_parm (current_declspecs,
2487 chainon ($4, all_prefix_attributes), $3);
4b01f8d8 2488 POP_DECLSPEC_STACK; }
25d78ace
JM
2489
2490 | declspecs_nots setspecs absdcl_maybe_attribute
2491 { $$ = $3;
4b01f8d8 2492 POP_DECLSPEC_STACK; }
25d78ace
JM
2493 ;
2494
2495/* The first parm, which must suck attributes from off the top of the parser
2496 stack. */
2497firstparm:
2498 declspecs_ts_nosa setspecs_fp parm_declarator maybe_attribute
00325bce
JM
2499 { $$ = build_c_parm (current_declspecs,
2500 chainon ($4, all_prefix_attributes), $3);
4b01f8d8 2501 POP_DECLSPEC_STACK; }
25d78ace 2502 | declspecs_ts_nosa setspecs_fp notype_declarator maybe_attribute
00325bce
JM
2503 { $$ = build_c_parm (current_declspecs,
2504 chainon ($4, all_prefix_attributes), $3);
4b01f8d8 2505 POP_DECLSPEC_STACK; }
25d78ace
JM
2506 | declspecs_ts_nosa setspecs_fp absdcl_maybe_attribute
2507 { $$ = $3;
4b01f8d8 2508 POP_DECLSPEC_STACK; }
25d78ace 2509 | declspecs_nots_nosa setspecs_fp notype_declarator maybe_attribute
00325bce
JM
2510 { $$ = build_c_parm (current_declspecs,
2511 chainon ($4, all_prefix_attributes), $3);
4b01f8d8 2512 POP_DECLSPEC_STACK; }
25d78ace
JM
2513
2514 | declspecs_nots_nosa setspecs_fp absdcl_maybe_attribute
2515 { $$ = $3;
4b01f8d8 2516 POP_DECLSPEC_STACK; }
25d78ace
JM
2517 ;
2518
2519setspecs_fp:
2520 setspecs
4b01f8d8
JM
2521 { prefix_attributes = chainon (prefix_attributes, $<ttype>-2);
2522 all_prefix_attributes = prefix_attributes; }
028299c6
RS
2523 ;
2524
2525/* This is used in a function definition
2526 where either a parmlist or an identifier list is ok.
2527 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2528parmlist_or_identifiers:
709619d9 2529 maybe_attribute
f75fbaf7 2530 { push_scope ();
eb1dfbb2 2531 declare_parm_level (); }
028299c6 2532 parmlist_or_identifiers_1
709619d9 2533 { $$ = $3;
f75fbaf7 2534 pop_scope (); }
028299c6
RS
2535 ;
2536
2537parmlist_or_identifiers_1:
2538 parmlist_1
2539 | identifiers ')'
f8893e47
JM
2540 { $$ = XOBNEW (&parser_obstack, struct c_arg_info);
2541 $$->parms = 0;
2542 $$->tags = 0;
2543 $$->types = $1;
2544 $$->others = 0;
709619d9
AH
2545
2546 /* Make sure we have a parmlist after attributes. */
21611613 2547 if ($<ttype>-1 != 0)
709619d9
AH
2548 YYERROR1;
2549 }
028299c6
RS
2550 ;
2551
2552/* A nonempty list of identifiers. */
2553identifiers:
2554 IDENTIFIER
2555 { $$ = build_tree_list (NULL_TREE, $1); }
2556 | identifiers ',' IDENTIFIER
2557 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2558 ;
2559
2560/* A nonempty list of identifiers, including typenames. */
2561identifiers_or_typenames:
2562 identifier
2563 { $$ = build_tree_list (NULL_TREE, $1); }
2564 | identifiers_or_typenames ',' identifier
2565 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2566 ;
72acf258
JM
2567
2568extension:
2569 EXTENSION
3f75a254 2570 { $$ = SAVE_EXT_FLAGS ();
c3b6e114 2571 pedantic = 0;
5137bd4f 2572 warn_pointer_arith = 0;
750491fc
RH
2573 warn_traditional = 0;
2574 flag_iso = 0; }
72acf258 2575 ;
028299c6 2576\f
264fa2db 2577@@ifobjc
028299c6
RS
2578/* Objective-C productions. */
2579
2580objcdef:
2581 classdef
e31c7eec
TW
2582 | classdecl
2583 | aliasdecl
2584 | protocoldef
028299c6 2585 | methoddef
f2b5cf97 2586 | AT_END
028299c6 2587 {
6408ef33 2588 objc_finish_implementation ();
028299c6
RS
2589 }
2590 ;
2591
e31c7eec
TW
2592/* A nonempty list of identifiers. */
2593identifier_list:
2594 identifier
2595 { $$ = build_tree_list (NULL_TREE, $1); }
2596 | identifier_list ',' identifier
2597 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2598 ;
2599
2600classdecl:
f2b5cf97 2601 AT_CLASS identifier_list ';'
e31c7eec
TW
2602 {
2603 objc_declare_class ($2);
2604 }
84d901be 2605 ;
e31c7eec
TW
2606
2607aliasdecl:
f2b5cf97 2608 AT_ALIAS identifier identifier ';'
e31c7eec
TW
2609 {
2610 objc_declare_alias ($2, $3);
2611 }
84d901be 2612 ;
e31c7eec 2613
264fa2db
ZL
2614superclass:
2615 ':' identifier { $$ = $2; }
2616 | /* NULL */ %prec HYPERUNARY { $$ = NULL_TREE; }
2617 ;
028299c6 2618
264fa2db
ZL
2619class_ivars:
2620 '{' ivar_decl_list '}'
2621 | /* NULL */
2622 ;
028299c6 2623
264fa2db 2624classdef:
f2b5cf97 2625 AT_INTERFACE identifier superclass protocolrefs
028299c6 2626 {
6408ef33 2627 objc_start_class_interface ($2, $3, $4);
028299c6 2628 }
264fa2db 2629 class_ivars
028299c6 2630 {
6408ef33 2631 objc_continue_interface ();
028299c6 2632 }
f2b5cf97 2633 methodprotolist AT_END
028299c6 2634 {
6408ef33 2635 objc_finish_interface ();
028299c6
RS
2636 }
2637
f2b5cf97 2638 | AT_IMPLEMENTATION identifier superclass
028299c6 2639 {
6408ef33 2640 objc_start_class_implementation ($2, $3);
028299c6 2641 }
264fa2db 2642 class_ivars
028299c6 2643 {
6408ef33 2644 objc_continue_implementation ();
028299c6
RS
2645 }
2646
f2b5cf97 2647 | AT_INTERFACE identifier '(' identifier ')' protocolrefs
028299c6 2648 {
6408ef33 2649 objc_start_category_interface ($2, $4, $6);
028299c6 2650 }
f2b5cf97 2651 methodprotolist AT_END
028299c6 2652 {
6408ef33 2653 objc_finish_interface ();
028299c6
RS
2654 }
2655
f2b5cf97 2656 | AT_IMPLEMENTATION identifier '(' identifier ')'
028299c6 2657 {
6408ef33 2658 objc_start_category_implementation ($2, $4);
028299c6
RS
2659 }
2660 ;
2661
e31c7eec 2662protocoldef:
f2b5cf97 2663 AT_PROTOCOL identifier protocolrefs
e31c7eec 2664 {
4c521bad 2665 objc_pq_context = 1;
6408ef33 2666 objc_start_protocol ($2, $3);
e31c7eec 2667 }
f2b5cf97 2668 methodprotolist AT_END
e31c7eec 2669 {
4c521bad 2670 objc_pq_context = 0;
6408ef33 2671 objc_finish_interface ();
e31c7eec 2672 }
f2e6e530
ZL
2673 /* The @protocol forward-declaration production introduces a
2674 reduce/reduce conflict on ';', which should be resolved in
2675 favor of the production 'identifier_list -> identifier'. */
f2b5cf97 2676 | AT_PROTOCOL identifier_list ';'
f2e6e530
ZL
2677 {
2678 objc_declare_protocols ($2);
2679 }
e31c7eec
TW
2680 ;
2681
2682protocolrefs:
2683 /* empty */
2684 {
2685 $$ = NULL_TREE;
2686 }
957a1c32
RK
2687 | non_empty_protocolrefs
2688 ;
2689
2690non_empty_protocolrefs:
2691 ARITHCOMPARE identifier_list ARITHCOMPARE
e31c7eec
TW
2692 {
2693 if ($1 == LT_EXPR && $3 == GT_EXPR)
2694 $$ = $2;
2695 else
2696 YYERROR1;
2697 }
2698 ;
2699
028299c6 2700ivar_decl_list:
6408ef33
ZL
2701 /* empty */
2702 | ivar_decl_list visibility_spec ivar_decls
028299c6
RS
2703 ;
2704
e31c7eec 2705visibility_spec:
6408ef33
ZL
2706 /* empty */
2707 | AT_PRIVATE { objc_set_visibility (2); }
2708 | AT_PROTECTED { objc_set_visibility (0); }
2709 | AT_PUBLIC { objc_set_visibility (1); }
e31c7eec
TW
2710 ;
2711
028299c6 2712ivar_decls:
6408ef33 2713 /* empty */
028299c6
RS
2714 | ivar_decls ivar_decl ';'
2715 | ivar_decls ';'
2716 {
6408ef33 2717 if (pedantic)
ea3cfc81 2718 pedwarn ("extra semicolon in struct or union specified");
6408ef33 2719 }
028299c6
RS
2720 ;
2721
028299c6 2722ivar_decl:
6408ef33
ZL
2723 component_decl
2724 {
2725 /* Comma-separated ivars are chained together in
2726 reverse order; add them one by one. */
2727 tree ivar = nreverse ($1);
028299c6 2728
6408ef33
ZL
2729 for (; ivar; ivar = TREE_CHAIN (ivar))
2730 objc_add_instance_variable (copy_node (ivar));
2731 }
028299c6
RS
2732 ;
2733
6408ef33
ZL
2734opt_semi:
2735 /* NULL */
2736 | ';'
028299c6 2737 {
6408ef33
ZL
2738 if (pedantic)
2739 pedwarn ("extra semicolon in method definition specified");
2740 }
028299c6
RS
2741 ;
2742
0b1cdaf2 2743methodtype:
028299c6 2744 '+'
028299c6 2745 | '-'
0b1cdaf2
NB
2746 ;
2747
2748methoddef:
2749 methodtype
028299c6 2750 {
6408ef33 2751 objc_set_method_type ($1);
4c521bad 2752 objc_pq_context = 1;
028299c6 2753 }
6408ef33 2754 methoddecl opt_semi
028299c6 2755 {
4c521bad 2756 objc_pq_context = 0;
6408ef33 2757 objc_start_method_definition ($3);
028299c6
RS
2758 }
2759 compstmt_or_error
2760 {
6408ef33 2761 objc_finish_method_definition (current_function_decl);
028299c6
RS
2762 }
2763 ;
2764
2765/* the reason for the strange actions in this rule
2766 is so that notype_initdecls when reached via datadef
2767 can find a valid list of type and sc specs in $0. */
2768
2769methodprotolist:
2770 /* empty */
264fa2db
ZL
2771 | methodprotolist methodproto
2772 | methodprotolist { $<ttype>$ = NULL_TREE; } datadef
028299c6
RS
2773 ;
2774
2775semi_or_error:
2776 ';'
2777 | error
2778 ;
2779
2780methodproto:
0b1cdaf2 2781 methodtype
028299c6 2782 {
6408ef33 2783 objc_set_method_type ($1);
990ac8d7 2784 /* Remember protocol qualifiers in prototypes. */
4c521bad 2785 objc_pq_context = 1;
028299c6
RS
2786 }
2787 methoddecl
2788 {
990ac8d7 2789 /* Forget protocol qualifiers here. */
4c521bad 2790 objc_pq_context = 0;
6408ef33 2791 objc_add_method_declaration ($3);
028299c6
RS
2792 }
2793 semi_or_error
2794 ;
2795
2796methoddecl:
6408ef33 2797 '(' objc_typename ')' unaryselector
028299c6 2798 {
6408ef33 2799 $$ = objc_build_method_signature ($2, $4, NULL_TREE);
028299c6
RS
2800 }
2801
2802 | unaryselector
2803 {
6408ef33 2804 $$ = objc_build_method_signature (NULL_TREE, $1, NULL_TREE);
028299c6
RS
2805 }
2806
6408ef33 2807 | '(' objc_typename ')' keywordselector optparmlist
028299c6 2808 {
6408ef33 2809 $$ = objc_build_method_signature ($2, $4, $5);
028299c6
RS
2810 }
2811
2812 | keywordselector optparmlist
2813 {
6408ef33 2814 $$ = objc_build_method_signature (NULL_TREE, $1, $2);
028299c6
RS
2815 }
2816 ;
2817
6408ef33
ZL
2818/* Optional ObjC method parameters follow the C syntax, and may include '...'
2819 to denote a variable number of arguments. */
028299c6 2820
6408ef33
ZL
2821optparmlist:
2822 optparms optellipsis
2823 {
2824 TREE_OVERFLOW ($$) = $2;
2825 }
028299c6
RS
2826 ;
2827
6408ef33
ZL
2828optparms:
2829 /* NULL */
028299c6 2830 {
6408ef33 2831 $$ = make_node (TREE_LIST);
028299c6 2832 }
6408ef33 2833 | optparms ',' parm
028299c6 2834 {
6408ef33
ZL
2835 $$ = chainon ($1, build_tree_list (NULL_TREE,
2836 grokparm ($3)));
028299c6 2837 }
6408ef33 2838 ;
110fce11 2839
6408ef33
ZL
2840optellipsis:
2841 /* NULL */
028299c6 2842 {
6408ef33 2843 $$ = 0;
028299c6 2844 }
6408ef33 2845 | ',' ELLIPSIS
028299c6 2846 {
6408ef33 2847 $$ = 1;
028299c6
RS
2848 }
2849 ;
2850
2851unaryselector:
2852 selector
2853 ;
2854
2855keywordselector:
2856 keyworddecl
2857
2858 | keywordselector keyworddecl
2859 {
2860 $$ = chainon ($1, $2);
2861 }
2862 ;
2863
2864selector:
2865 IDENTIFIER
f2e6e530
ZL
2866 | TYPENAME
2867 | CLASSNAME
2868 | OBJECTNAME
028299c6
RS
2869 | reservedwords
2870 ;
2871
2872reservedwords:
6408ef33 2873 ENUM | STRUCT | UNION | IF | ELSE | WHILE | DO | FOR
0e5921e8
ZW
2874 | SWITCH | CASE | DEFAULT | BREAK | CONTINUE | RETURN
2875 | GOTO | ASM_KEYWORD | SIZEOF | TYPEOF | ALIGNOF
028299c6
RS
2876 | TYPESPEC | TYPE_QUAL
2877 ;
2878
6408ef33
ZL
2879objc_qual:
2880 OBJC_TYPE_QUAL
2881 ;
2882
2883objc_quals:
2884 objc_quals objc_qual
2885 {
2886 $$ = chainon ($1, build_tree_list (NULL_TREE, $2));
2887 }
2888 | /* NULL */
2889 {
2890 $$ = NULL_TREE;
2891 }
2892 ;
2893
2894objc_typename:
2895 objc_quals typename
2896 {
2897 $$ = build_tree_list ($1, groktypename ($2));
2898 }
2899 | objc_quals
2900 {
2901 $$ = build_tree_list ($1, NULL_TREE);
2902 }
2903 ;
2904
028299c6 2905keyworddecl:
6408ef33 2906 selector ':' '(' objc_typename ')' identifier
028299c6 2907 {
57a6af27 2908 $$ = objc_build_keyword_decl ($1, $4, $6);
028299c6
RS
2909 }
2910
2911 | selector ':' identifier
2912 {
57a6af27 2913 $$ = objc_build_keyword_decl ($1, NULL_TREE, $3);
028299c6
RS
2914 }
2915
6408ef33 2916 | ':' '(' objc_typename ')' identifier
028299c6 2917 {
57a6af27 2918 $$ = objc_build_keyword_decl (NULL_TREE, $3, $5);
028299c6
RS
2919 }
2920
2921 | ':' identifier
2922 {
57a6af27 2923 $$ = objc_build_keyword_decl (NULL_TREE, NULL_TREE, $2);
028299c6
RS
2924 }
2925 ;
2926
2927messageargs:
2928 selector
2929 | keywordarglist
2930 ;
2931
2932keywordarglist:
2933 keywordarg
2934 | keywordarglist keywordarg
2935 {
2936 $$ = chainon ($1, $2);
2937 }
2938 ;
2939
2940
2941keywordexpr:
2942 nonnull_exprlist
2943 {
2944 if (TREE_CHAIN ($1) == NULL_TREE)
2945 /* just return the expr., remove a level of indirection */
2946 $$ = TREE_VALUE ($1);
2947 else
2948 /* we have a comma expr., we will collapse later */
2949 $$ = $1;
2950 }
2951 ;
2952
2953keywordarg:
2954 selector ':' keywordexpr
2955 {
2956 $$ = build_tree_list ($1, $3);
2957 }
2958 | ':' keywordexpr
2959 {
2960 $$ = build_tree_list (NULL_TREE, $2);
2961 }
2962 ;
2963
2964receiver:
2965 expr
487a92fe 2966 { $$ = $1.value; }
028299c6
RS
2967 | CLASSNAME
2968 {
57a6af27 2969 $$ = objc_get_class_reference ($1);
028299c6 2970 }
264fa2db
ZL
2971 | TYPENAME
2972 {
57a6af27 2973 $$ = objc_get_class_reference ($1);
264fa2db 2974 }
028299c6
RS
2975 ;
2976
2977objcmessageexpr:
c1c5187c
ZL
2978 '[' receiver messageargs ']'
2979 { $$ = build_tree_list ($2, $3); }
028299c6
RS
2980 ;
2981
2982selectorarg:
2983 selector
2984 | keywordnamelist
2985 ;
2986
2987keywordnamelist:
2988 keywordname
2989 | keywordnamelist keywordname
2990 {
2991 $$ = chainon ($1, $2);
2992 }
2993 ;
2994
2995keywordname:
2996 selector ':'
2997 {
2998 $$ = build_tree_list ($1, NULL_TREE);
2999 }
3000 | ':'
3001 {
3002 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3003 }
3004 ;
3005
3006objcselectorexpr:
f2b5cf97 3007 AT_SELECTOR '(' selectorarg ')'
028299c6
RS
3008 {
3009 $$ = $3;
3010 }
3011 ;
3012
e31c7eec 3013objcprotocolexpr:
f2b5cf97 3014 AT_PROTOCOL '(' identifier ')'
e31c7eec
TW
3015 {
3016 $$ = $3;
3017 }
3018 ;
3019
028299c6
RS
3020/* extension to support C-structures in the archiver */
3021
3022objcencodeexpr:
f2b5cf97 3023 AT_ENCODE '(' typename ')'
028299c6
RS
3024 {
3025 $$ = groktypename ($3);
3026 }
3027 ;
3028
264fa2db 3029@@end_ifobjc
028299c6 3030%%
0e5921e8
ZW
3031
3032/* yylex() is a thin wrapper around c_lex(), all it does is translate
3033 cpplib.h's token codes into yacc's token codes. */
0e5921e8
ZW
3034
3035static enum cpp_ttype last_token;
0e5921e8
ZW
3036
3037/* The reserved keyword table. */
3038struct resword
3039{
3040 const char *word;
3041 ENUM_BITFIELD(rid) rid : 16;
3042 unsigned int disable : 16;
3043};
3044
3045/* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
3046 _true_. */
f458d1d5
ZW
3047#define D_C89 0x01 /* not in C89 */
3048#define D_EXT 0x02 /* GCC extension */
3049#define D_EXT89 0x04 /* GCC extension incorporated in C99 */
3050#define D_OBJC 0x08 /* Objective C only */
0e5921e8
ZW
3051
3052static const struct resword reswords[] =
3053{
19552aa5 3054 { "_Bool", RID_BOOL, 0 },
d9dbd9b1 3055 { "_Complex", RID_COMPLEX, 0 },
0ba8a114
NS
3056 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
3057 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
0e5921e8
ZW
3058 { "__alignof", RID_ALIGNOF, 0 },
3059 { "__alignof__", RID_ALIGNOF, 0 },
3060 { "__asm", RID_ASM, 0 },
3061 { "__asm__", RID_ASM, 0 },
3062 { "__attribute", RID_ATTRIBUTE, 0 },
3063 { "__attribute__", RID_ATTRIBUTE, 0 },
ecbcf7b3 3064 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
7a3ea201 3065 { "__builtin_offsetof", RID_OFFSETOF, 0 },
ecbcf7b3 3066 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
0e5921e8
ZW
3067 { "__builtin_va_arg", RID_VA_ARG, 0 },
3068 { "__complex", RID_COMPLEX, 0 },
3069 { "__complex__", RID_COMPLEX, 0 },
3070 { "__const", RID_CONST, 0 },
3071 { "__const__", RID_CONST, 0 },
3072 { "__extension__", RID_EXTENSION, 0 },
0ba8a114 3073 { "__func__", RID_C99_FUNCTION_NAME, 0 },
0e5921e8
ZW
3074 { "__imag", RID_IMAGPART, 0 },
3075 { "__imag__", RID_IMAGPART, 0 },
3076 { "__inline", RID_INLINE, 0 },
3077 { "__inline__", RID_INLINE, 0 },
3078 { "__label__", RID_LABEL, 0 },
3079 { "__ptrbase", RID_PTRBASE, 0 },
3080 { "__ptrbase__", RID_PTRBASE, 0 },
3081 { "__ptrextent", RID_PTREXTENT, 0 },
3082 { "__ptrextent__", RID_PTREXTENT, 0 },
3083 { "__ptrvalue", RID_PTRVALUE, 0 },
3084 { "__ptrvalue__", RID_PTRVALUE, 0 },
3085 { "__real", RID_REALPART, 0 },
3086 { "__real__", RID_REALPART, 0 },
3087 { "__restrict", RID_RESTRICT, 0 },
3088 { "__restrict__", RID_RESTRICT, 0 },
3089 { "__signed", RID_SIGNED, 0 },
3090 { "__signed__", RID_SIGNED, 0 },
3d78f2e9 3091 { "__thread", RID_THREAD, 0 },
0e5921e8
ZW
3092 { "__typeof", RID_TYPEOF, 0 },
3093 { "__typeof__", RID_TYPEOF, 0 },
0e5921e8
ZW
3094 { "__volatile", RID_VOLATILE, 0 },
3095 { "__volatile__", RID_VOLATILE, 0 },
3096 { "asm", RID_ASM, D_EXT },
3097 { "auto", RID_AUTO, 0 },
3098 { "break", RID_BREAK, 0 },
3099 { "case", RID_CASE, 0 },
3100 { "char", RID_CHAR, 0 },
f458d1d5 3101 { "const", RID_CONST, 0 },
0e5921e8
ZW
3102 { "continue", RID_CONTINUE, 0 },
3103 { "default", RID_DEFAULT, 0 },
3104 { "do", RID_DO, 0 },
3105 { "double", RID_DOUBLE, 0 },
3106 { "else", RID_ELSE, 0 },
3107 { "enum", RID_ENUM, 0 },
3108 { "extern", RID_EXTERN, 0 },
3109 { "float", RID_FLOAT, 0 },
3110 { "for", RID_FOR, 0 },
3111 { "goto", RID_GOTO, 0 },
3112 { "if", RID_IF, 0 },
f458d1d5 3113 { "inline", RID_INLINE, D_EXT89 },
0e5921e8
ZW
3114 { "int", RID_INT, 0 },
3115 { "long", RID_LONG, 0 },
3116 { "register", RID_REGISTER, 0 },
f458d1d5 3117 { "restrict", RID_RESTRICT, D_C89 },
0e5921e8
ZW
3118 { "return", RID_RETURN, 0 },
3119 { "short", RID_SHORT, 0 },
f458d1d5 3120 { "signed", RID_SIGNED, 0 },
0e5921e8
ZW
3121 { "sizeof", RID_SIZEOF, 0 },
3122 { "static", RID_STATIC, 0 },
3123 { "struct", RID_STRUCT, 0 },
3124 { "switch", RID_SWITCH, 0 },
3125 { "typedef", RID_TYPEDEF, 0 },
f458d1d5 3126 { "typeof", RID_TYPEOF, D_EXT },
0e5921e8
ZW
3127 { "union", RID_UNION, 0 },
3128 { "unsigned", RID_UNSIGNED, 0 },
3129 { "void", RID_VOID, 0 },
f458d1d5 3130 { "volatile", RID_VOLATILE, 0 },
0e5921e8 3131 { "while", RID_WHILE, 0 },
57a6af27 3132
264fa2db 3133@@ifobjc
0e5921e8 3134 { "id", RID_ID, D_OBJC },
b8363a24
ZW
3135
3136 /* These objc keywords are recognized only immediately after
3137 an '@'. */
3138 { "class", RID_AT_CLASS, D_OBJC },
3139 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
3140 { "defs", RID_AT_DEFS, D_OBJC },
3141 { "encode", RID_AT_ENCODE, D_OBJC },
3142 { "end", RID_AT_END, D_OBJC },
3143 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
3144 { "interface", RID_AT_INTERFACE, D_OBJC },
3145 { "private", RID_AT_PRIVATE, D_OBJC },
3146 { "protected", RID_AT_PROTECTED, D_OBJC },
3147 { "protocol", RID_AT_PROTOCOL, D_OBJC },
3148 { "public", RID_AT_PUBLIC, D_OBJC },
3149 { "selector", RID_AT_SELECTOR, D_OBJC },
264fa2db
ZL
3150 { "throw", RID_AT_THROW, D_OBJC },
3151 { "try", RID_AT_TRY, D_OBJC },
3152 { "catch", RID_AT_CATCH, D_OBJC },
3153 { "finally", RID_AT_FINALLY, D_OBJC },
3154 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
b8363a24
ZW
3155 /* These are recognized only in protocol-qualifier context
3156 (see above) */
71b7be38
ZW
3157 { "bycopy", RID_BYCOPY, D_OBJC },
3158 { "byref", RID_BYREF, D_OBJC },
3159 { "in", RID_IN, D_OBJC },
3160 { "inout", RID_INOUT, D_OBJC },
3161 { "oneway", RID_ONEWAY, D_OBJC },
3162 { "out", RID_OUT, D_OBJC },
264fa2db 3163@@end_ifobjc
0e5921e8
ZW
3164};
3165#define N_reswords (sizeof reswords / sizeof (struct resword))
3166
3167/* Table mapping from RID_* constants to yacc token numbers.
3168 Unfortunately we have to have entries for all the keywords in all
3169 three languages. */
3170static const short rid_to_yy[RID_MAX] =
3171{
f79f2651 3172 /* RID_STATIC */ STATIC,
0e5921e8
ZW
3173 /* RID_UNSIGNED */ TYPESPEC,
3174 /* RID_LONG */ TYPESPEC,
3175 /* RID_CONST */ TYPE_QUAL,
3176 /* RID_EXTERN */ SCSPEC,
3177 /* RID_REGISTER */ SCSPEC,
3178 /* RID_TYPEDEF */ SCSPEC,
3179 /* RID_SHORT */ TYPESPEC,
3180 /* RID_INLINE */ SCSPEC,
3181 /* RID_VOLATILE */ TYPE_QUAL,
3182 /* RID_SIGNED */ TYPESPEC,
3183 /* RID_AUTO */ SCSPEC,
3184 /* RID_RESTRICT */ TYPE_QUAL,
3185
3186 /* C extensions */
0e5921e8 3187 /* RID_COMPLEX */ TYPESPEC,
3d78f2e9 3188 /* RID_THREAD */ SCSPEC,
0e5921e8
ZW
3189
3190 /* C++ */
3191 /* RID_FRIEND */ 0,
3192 /* RID_VIRTUAL */ 0,
3193 /* RID_EXPLICIT */ 0,
3194 /* RID_EXPORT */ 0,
3195 /* RID_MUTABLE */ 0,
3196
3197 /* ObjC */
6408ef33
ZL
3198 /* RID_IN */ OBJC_TYPE_QUAL,
3199 /* RID_OUT */ OBJC_TYPE_QUAL,
3200 /* RID_INOUT */ OBJC_TYPE_QUAL,
3201 /* RID_BYCOPY */ OBJC_TYPE_QUAL,
3202 /* RID_BYREF */ OBJC_TYPE_QUAL,
3203 /* RID_ONEWAY */ OBJC_TYPE_QUAL,
84d901be 3204
0e5921e8
ZW
3205 /* C */
3206 /* RID_INT */ TYPESPEC,
3207 /* RID_CHAR */ TYPESPEC,
3208 /* RID_FLOAT */ TYPESPEC,
3209 /* RID_DOUBLE */ TYPESPEC,
3210 /* RID_VOID */ TYPESPEC,
3211 /* RID_ENUM */ ENUM,
3212 /* RID_STRUCT */ STRUCT,
3213 /* RID_UNION */ UNION,
3214 /* RID_IF */ IF,
3215 /* RID_ELSE */ ELSE,
3216 /* RID_WHILE */ WHILE,
3217 /* RID_DO */ DO,
3218 /* RID_FOR */ FOR,
3219 /* RID_SWITCH */ SWITCH,
3220 /* RID_CASE */ CASE,
3221 /* RID_DEFAULT */ DEFAULT,
3222 /* RID_BREAK */ BREAK,
3223 /* RID_CONTINUE */ CONTINUE,
3224 /* RID_RETURN */ RETURN,
3225 /* RID_GOTO */ GOTO,
3226 /* RID_SIZEOF */ SIZEOF,
3227
3228 /* C extensions */
3229 /* RID_ASM */ ASM_KEYWORD,
3230 /* RID_TYPEOF */ TYPEOF,
3231 /* RID_ALIGNOF */ ALIGNOF,
3232 /* RID_ATTRIBUTE */ ATTRIBUTE,
3233 /* RID_VA_ARG */ VA_ARG,
3234 /* RID_EXTENSION */ EXTENSION,
3235 /* RID_IMAGPART */ IMAGPART,
3236 /* RID_REALPART */ REALPART,
3237 /* RID_LABEL */ LABEL,
3238 /* RID_PTRBASE */ PTR_BASE,
3239 /* RID_PTREXTENT */ PTR_EXTENT,
3240 /* RID_PTRVALUE */ PTR_VALUE,
3241
ecbcf7b3
AH
3242 /* RID_CHOOSE_EXPR */ CHOOSE_EXPR,
3243 /* RID_TYPES_COMPATIBLE_P */ TYPES_COMPATIBLE_P,
3244
e6cc3a24
ZW
3245 /* RID_FUNCTION_NAME */ FUNC_NAME,
3246 /* RID_PRETTY_FUNCTION_NAME */ FUNC_NAME,
3247 /* RID_C99_FUNCTION_NAME */ FUNC_NAME,
0ba8a114 3248
0e5921e8 3249 /* C++ */
19552aa5 3250 /* RID_BOOL */ TYPESPEC,
0e5921e8
ZW
3251 /* RID_WCHAR */ 0,
3252 /* RID_CLASS */ 0,
3253 /* RID_PUBLIC */ 0,
3254 /* RID_PRIVATE */ 0,
3255 /* RID_PROTECTED */ 0,
3256 /* RID_TEMPLATE */ 0,
3257 /* RID_NULL */ 0,
3258 /* RID_CATCH */ 0,
3259 /* RID_DELETE */ 0,
3260 /* RID_FALSE */ 0,
3261 /* RID_NAMESPACE */ 0,
3262 /* RID_NEW */ 0,
7a3ea201 3263 /* RID_OFFSETOF */ OFFSETOF,
0e5921e8
ZW
3264 /* RID_OPERATOR */ 0,
3265 /* RID_THIS */ 0,
3266 /* RID_THROW */ 0,
3267 /* RID_TRUE */ 0,
3268 /* RID_TRY */ 0,
3269 /* RID_TYPENAME */ 0,
3270 /* RID_TYPEID */ 0,
3271 /* RID_USING */ 0,
3272
3273 /* casts */
3274 /* RID_CONSTCAST */ 0,
3275 /* RID_DYNCAST */ 0,
3276 /* RID_REINTCAST */ 0,
3277 /* RID_STATCAST */ 0,
3278
0e5921e8
ZW
3279 /* Objective C */
3280 /* RID_ID */ OBJECTNAME,
f2b5cf97
DA
3281 /* RID_AT_ENCODE */ AT_ENCODE,
3282 /* RID_AT_END */ AT_END,
3283 /* RID_AT_CLASS */ AT_CLASS,
3284 /* RID_AT_ALIAS */ AT_ALIAS,
3285 /* RID_AT_DEFS */ AT_DEFS,
3286 /* RID_AT_PRIVATE */ AT_PRIVATE,
3287 /* RID_AT_PROTECTED */ AT_PROTECTED,
3288 /* RID_AT_PUBLIC */ AT_PUBLIC,
3289 /* RID_AT_PROTOCOL */ AT_PROTOCOL,
3290 /* RID_AT_SELECTOR */ AT_SELECTOR,
264fa2db
ZL
3291 /* RID_AT_THROW */ AT_THROW,
3292 /* RID_AT_TRY */ AT_TRY,
3293 /* RID_AT_CATCH */ AT_CATCH,
3294 /* RID_AT_FINALLY */ AT_FINALLY,
3295 /* RID_AT_SYNCHRONIZED */ AT_SYNCHRONIZED,
f2b5cf97
DA
3296 /* RID_AT_INTERFACE */ AT_INTERFACE,
3297 /* RID_AT_IMPLEMENTATION */ AT_IMPLEMENTATION
0e5921e8
ZW
3298};
3299
3300static void
f55ade6e 3301init_reswords (void)
0e5921e8
ZW
3302{
3303 unsigned int i;
3304 tree id;
a3eaca15 3305 int mask = (flag_isoc99 ? 0 : D_C89)
a3eaca15
NB
3306 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
3307
37fa72e9 3308 if (!c_dialect_objc ())
a3eaca15 3309 mask |= D_OBJC;
0e5921e8 3310
5d038c4c 3311 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
0e5921e8
ZW
3312 for (i = 0; i < N_reswords; i++)
3313 {
aac02f4e
RH
3314 /* If a keyword is disabled, do not enter it into the table
3315 and so create a canonical spelling that isn't a keyword. */
3316 if (reswords[i].disable & mask)
3317 continue;
3318
0e5921e8
ZW
3319 id = get_identifier (reswords[i].word);
3320 C_RID_CODE (id) = reswords[i].rid;
71b7be38 3321 C_IS_RESERVED_WORD (id) = 1;
0e5921e8 3322 ridpointers [(int) reswords[i].rid] = id;
0e5921e8
ZW
3323 }
3324}
3325
0e5921e8 3326#define NAME(type) cpp_type2name (type)
0e5921e8
ZW
3327
3328static void
f55ade6e 3329yyerror (const char *msgid)
0e5921e8 3330{
4bb8ca28 3331 c_parse_error (msgid, last_token, yylval.ttype);
0e5921e8
ZW
3332}
3333
cc937581 3334static int
f55ade6e 3335yylexname (void)
cc937581
ZW
3336{
3337 tree decl;
84d901be 3338
264fa2db 3339@@ifobjc
f2e6e530
ZL
3340 int objc_force_identifier = objc_need_raw_identifier;
3341 OBJC_NEED_RAW_IDENTIFIER (0);
264fa2db 3342@@end_ifobjc
84d901be 3343
cc937581
ZW
3344 if (C_IS_RESERVED_WORD (yylval.ttype))
3345 {
3346 enum rid rid_code = C_RID_CODE (yylval.ttype);
0ba8a114 3347
264fa2db 3348@@ifobjc
f2e6e530
ZL
3349 /* Turn non-typedefed refs to "id" into plain identifiers; this
3350 allows constructs like "void foo(id id);" to work. */
3351 if (rid_code == RID_ID)
3352 {
3353 decl = lookup_name (yylval.ttype);
3354 if (decl == NULL_TREE || TREE_CODE (decl) != TYPE_DECL)
3355 return IDENTIFIER;
3356 }
3357
b8363a24
ZW
3358 if (!OBJC_IS_AT_KEYWORD (rid_code)
3359 && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
264fa2db 3360@@end_ifobjc
4c521bad 3361 {
4c521bad
NB
3362 /* Return the canonical spelling for this keyword. */
3363 yylval.ttype = ridpointers[(int) rid_code];
e6cc3a24 3364 return rid_to_yy[(int) rid_code];
4c521bad 3365 }
cc937581
ZW
3366 }
3367
3368 decl = lookup_name (yylval.ttype);
3369 if (decl)
3370 {
3371 if (TREE_CODE (decl) == TYPE_DECL)
3372 return TYPENAME;
cc937581 3373 }
264fa2db 3374@@ifobjc
a3eaca15 3375 else
cc937581 3376 {
bc095846 3377 tree objc_interface_decl = objc_is_class_name (yylval.ttype);
f2e6e530
ZL
3378 /* ObjC class names are in the same namespace as variables and
3379 typedefs, and hence are shadowed by local declarations. */
84d901be
AD
3380 if (objc_interface_decl
3381 && (global_bindings_p ()
f2e6e530 3382 || (!objc_force_identifier && !decl)))
cc937581
ZW
3383 {
3384 yylval.ttype = objc_interface_decl;
3385 return CLASSNAME;
3386 }
3387 }
264fa2db 3388@@end_ifobjc
cc937581
ZW
3389
3390 return IDENTIFIER;
3391}
3392
0e5921e8 3393static inline int
f55ade6e 3394_yylex (void)
0e5921e8 3395{
cc937581 3396 get_next:
0e5921e8 3397 last_token = c_lex (&yylval.ttype);
0e5921e8
ZW
3398 switch (last_token)
3399 {
3400 case CPP_EQ: return '=';
3401 case CPP_NOT: return '!';
3402 case CPP_GREATER: yylval.code = GT_EXPR; return ARITHCOMPARE;
3403 case CPP_LESS: yylval.code = LT_EXPR; return ARITHCOMPARE;
3404 case CPP_PLUS: yylval.code = PLUS_EXPR; return '+';
3405 case CPP_MINUS: yylval.code = MINUS_EXPR; return '-';
3406 case CPP_MULT: yylval.code = MULT_EXPR; return '*';
3407 case CPP_DIV: yylval.code = TRUNC_DIV_EXPR; return '/';
3408 case CPP_MOD: yylval.code = TRUNC_MOD_EXPR; return '%';
3409 case CPP_AND: yylval.code = BIT_AND_EXPR; return '&';
3410 case CPP_OR: yylval.code = BIT_IOR_EXPR; return '|';
3411 case CPP_XOR: yylval.code = BIT_XOR_EXPR; return '^';
3412 case CPP_RSHIFT: yylval.code = RSHIFT_EXPR; return RSHIFT;
3413 case CPP_LSHIFT: yylval.code = LSHIFT_EXPR; return LSHIFT;
3414
3415 case CPP_COMPL: return '~';
3416 case CPP_AND_AND: return ANDAND;
3417 case CPP_OR_OR: return OROR;
3418 case CPP_QUERY: return '?';
0e5921e8 3419 case CPP_OPEN_PAREN: return '(';
0e5921e8
ZW
3420 case CPP_EQ_EQ: yylval.code = EQ_EXPR; return EQCOMPARE;
3421 case CPP_NOT_EQ: yylval.code = NE_EXPR; return EQCOMPARE;
3422 case CPP_GREATER_EQ:yylval.code = GE_EXPR; return ARITHCOMPARE;
3423 case CPP_LESS_EQ: yylval.code = LE_EXPR; return ARITHCOMPARE;
3424
3425 case CPP_PLUS_EQ: yylval.code = PLUS_EXPR; return ASSIGN;
3426 case CPP_MINUS_EQ: yylval.code = MINUS_EXPR; return ASSIGN;
3427 case CPP_MULT_EQ: yylval.code = MULT_EXPR; return ASSIGN;
3428 case CPP_DIV_EQ: yylval.code = TRUNC_DIV_EXPR; return ASSIGN;
3429 case CPP_MOD_EQ: yylval.code = TRUNC_MOD_EXPR; return ASSIGN;
3430 case CPP_AND_EQ: yylval.code = BIT_AND_EXPR; return ASSIGN;
3431 case CPP_OR_EQ: yylval.code = BIT_IOR_EXPR; return ASSIGN;
3432 case CPP_XOR_EQ: yylval.code = BIT_XOR_EXPR; return ASSIGN;
3433 case CPP_RSHIFT_EQ: yylval.code = RSHIFT_EXPR; return ASSIGN;
3434 case CPP_LSHIFT_EQ: yylval.code = LSHIFT_EXPR; return ASSIGN;
3435
3436 case CPP_OPEN_SQUARE: return '[';
3437 case CPP_CLOSE_SQUARE: return ']';
3438 case CPP_OPEN_BRACE: return '{';
3439 case CPP_CLOSE_BRACE: return '}';
0e5921e8
ZW
3440 case CPP_ELLIPSIS: return ELLIPSIS;
3441
3442 case CPP_PLUS_PLUS: return PLUSPLUS;
3443 case CPP_MINUS_MINUS: return MINUSMINUS;
3444 case CPP_DEREF: return POINTSAT;
3445 case CPP_DOT: return '.';
3446
f2e6e530
ZL
3447 /* The following tokens may affect the interpretation of any
3448 identifiers following, if doing Objective-C. */
3449 case CPP_COLON: OBJC_NEED_RAW_IDENTIFIER (0); return ':';
3450 case CPP_COMMA: OBJC_NEED_RAW_IDENTIFIER (0); return ',';
3451 case CPP_CLOSE_PAREN: OBJC_NEED_RAW_IDENTIFIER (0); return ')';
3452 case CPP_SEMICOLON: OBJC_NEED_RAW_IDENTIFIER (0); return ';';
3453
0e5921e8 3454 case CPP_EOF:
ef6e958a 3455 return 0;
0e5921e8
ZW
3456
3457 case CPP_NAME:
e6cc3a24
ZW
3458 return yylexname ();
3459
3460 case CPP_AT_NAME:
3461 /* This only happens in Objective-C; it must be a keyword. */
3462 return rid_to_yy [(int) C_RID_CODE (yylval.ttype)];
0e5921e8 3463
0e5921e8
ZW
3464 case CPP_NUMBER:
3465 case CPP_CHAR:
3466 case CPP_WCHAR:
3467 return CONSTANT;
3468
3469 case CPP_STRING:
3470 case CPP_WSTRING:
e6cc3a24 3471 return STRING;
e13e48e7 3472
e6cc3a24
ZW
3473 case CPP_OBJC_STRING:
3474 return OBJC_STRING;
b8363a24 3475
0e5921e8
ZW
3476 /* These tokens are C++ specific (and will not be generated
3477 in C mode, but let's be cautious). */
3478 case CPP_SCOPE:
3479 case CPP_DEREF_STAR:
3480 case CPP_DOT_STAR:
3481 case CPP_MIN_EQ:
3482 case CPP_MAX_EQ:
3483 case CPP_MIN:
3484 case CPP_MAX:
3485 /* These tokens should not survive translation phase 4. */
3486 case CPP_HASH:
3487 case CPP_PASTE:
bda67431 3488 error ("syntax error at %qs token", NAME(last_token));
cc937581 3489 goto get_next;
0e5921e8
ZW
3490
3491 default:
3492 abort ();
3493 }
0e5921e8
ZW
3494 /* NOTREACHED */
3495}
3496
3497static int
f55ade6e 3498yylex (void)
0e5921e8
ZW
3499{
3500 int r;
3501 timevar_push (TV_LEX);
3502 r = _yylex();
3503 timevar_pop (TV_LEX);
3504 return r;
3505}
3506
0e5921e8
ZW
3507/* Function used when yydebug is set, to print a token in more detail. */
3508
3509static void
f55ade6e 3510yyprint (FILE *file, int yychar, YYSTYPE yyl)
0e5921e8
ZW
3511{
3512 tree t = yyl.ttype;
3513
3514 fprintf (file, " [%s]", NAME(last_token));
84d901be 3515
0e5921e8
ZW
3516 switch (yychar)
3517 {
3518 case IDENTIFIER:
3519 case TYPENAME:
3520 case OBJECTNAME:
3521 case TYPESPEC:
3522 case TYPE_QUAL:
3523 case SCSPEC:
f79f2651 3524 case STATIC:
0e5921e8 3525 if (IDENTIFIER_POINTER (t))
bda67431 3526 fprintf (file, " '%s'", IDENTIFIER_POINTER (t));
0e5921e8
ZW
3527 break;
3528
3529 case CONSTANT:
3530 fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
3531 if (TREE_CODE (t) == INTEGER_CST)
c14bc6db
AJ
3532 {
3533 fputs (" ", file);
3534 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3535 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
3536 }
0e5921e8
ZW
3537 break;
3538 }
3539}
3540\f
f75fbaf7
ZW
3541/* This is not the ideal place to put this, but we have to get it out
3542 of c-lex.c because cp/lex.c has its own version. */
0e5921e8 3543
d1bd0ded
GK
3544/* Parse the file. */
3545void
3546c_parse_file (void)
3547{
3548 yyparse ();
d1bd0ded 3549
94a50397
RH
3550 if (malloced_yyss)
3551 {
3552 free (malloced_yyss);
3553 free (malloced_yyvs);
d1bd0ded 3554 malloced_yyss = 0;
94a50397
RH
3555 }
3556}
e2500fed 3557
d5706a1e
ZW
3558#ifdef __XGETTEXT__
3559/* Depending on the version of Bison used to compile this grammar,
3560 it may issue generic diagnostics spelled "syntax error" or
3561 "parse error". To prevent this from changing the translation
3562 template randomly, we list all the variants of this particular
3563 diagnostic here. Translators: there is no fine distinction
3564 between diagnostics with "syntax error" in them, and diagnostics
3565 with "parse error" in them. It's okay to give them both the same
3566 translation. */
3567const char d1[] = N_("syntax error");
3568const char d2[] = N_("parse error");
3569const char d3[] = N_("syntax error; also virtual memory exhausted");
3570const char d4[] = N_("parse error; also virtual memory exhausted");
3571const char d5[] = N_("syntax error: cannot back up");
3572const char d6[] = N_("parse error: cannot back up");
3573#endif
3574
e2500fed 3575#include "gt-c-parse.h"
This page took 3.117768 seconds and 5 git commands to generate.