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