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