regmove.c (optimize_reg_copy_1): Undo Aug 18 change.
[gcc.git] / gcc / c-parse.in
1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* This file defines the grammar of C and that of Objective C.
22 ifobjc ... end ifobjc conditionals contain code for Objective C only.
23 ifc ... end ifc conditionals contain code for C only.
24 Sed commands in Makefile.in are used to convert this file into
25 c-parse.y and into objc-parse.y. */
26
27 /* To whomever it may concern: I have heard that such a thing was once
28 written by AT&T, but I have never seen it. */
29
30 ifobjc
31 %expect 66
32 end ifobjc
33 ifc
34 %expect 46
35
36 /* These are the 23 conflicts you should get in parse.output;
37 the state numbers may vary if minor changes in the grammar are made.
38
39 State 42 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
40 State 44 contains 1 shift/reduce conflict. (Two ways to recover from error.)
41 State 103 contains 1 shift/reduce conflict. (Two ways to recover from error.)
42 State 110 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
43 State 111 contains 1 shift/reduce conflict. (Two ways to recover from error.)
44 State 115 contains 1 shift/reduce conflict. (Two ways to recover from error.)
45 State 132 contains 1 shift/reduce conflict. (See comment at component_decl.)
46 State 180 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
47 State 194 contains 2 shift/reduce conflict. (Four ways to parse this.)
48 State 202 contains 1 shift/reduce conflict. (Two ways to recover from error.)
49 State 214 contains 1 shift/reduce conflict. (Two ways to recover from error.)
50 State 220 contains 1 shift/reduce conflict. (Two ways to recover from error.)
51 State 304 contains 2 shift/reduce conflicts. (Four ways to parse this.)
52 State 335 contains 2 shift/reduce conflicts. (Four ways to parse this.)
53 State 347 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
54 State 352 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
55 State 383 contains 2 shift/reduce conflicts. (Four ways to parse this.)
56 State 434 contains 2 shift/reduce conflicts. (Four ways to parse this.) */
57
58 end ifc
59
60 %{
61 #include "config.h"
62 #include "system.h"
63 #include <setjmp.h>
64
65 #include "tree.h"
66 #include "input.h"
67 #include "c-lex.h"
68 #include "c-tree.h"
69 #include "flags.h"
70 #include "output.h"
71 #include "toplev.h"
72
73 #ifdef MULTIBYTE_CHARS
74 #include <locale.h>
75 #endif
76
77 ifobjc
78 #include "objc-act.h"
79 end ifobjc
80
81 /* Since parsers are distinct for each language, put the language string
82 definition here. */
83 ifobjc
84 char *language_string = "GNU Obj-C";
85 end ifobjc
86 ifc
87 char *language_string = "GNU C";
88 end ifc
89
90 /* Like YYERROR but do call yyerror. */
91 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
92
93 /* Cause the `yydebug' variable to be defined. */
94 #define YYDEBUG 1
95 %}
96
97 %start program
98
99 %union {long itype; tree ttype; enum tree_code code;
100 char *filename; int lineno; int ends_in_label; }
101
102 /* All identifiers that are not reserved words
103 and are not declared typedefs in the current block */
104 %token IDENTIFIER
105
106 /* All identifiers that are declared typedefs in the current block.
107 In some contexts, they are treated just like IDENTIFIER,
108 but they can also serve as typespecs in declarations. */
109 %token TYPENAME
110
111 /* Reserved words that specify storage class.
112 yylval contains an IDENTIFIER_NODE which indicates which one. */
113 %token SCSPEC
114
115 /* Reserved words that specify type.
116 yylval contains an IDENTIFIER_NODE which indicates which one. */
117 %token TYPESPEC
118
119 /* Reserved words that qualify type: "const", "volatile", or "restrict".
120 yylval contains an IDENTIFIER_NODE which indicates which one. */
121 %token TYPE_QUAL
122
123 /* Character or numeric constants.
124 yylval is the node for the constant. */
125 %token CONSTANT
126
127 /* String constants in raw form.
128 yylval is a STRING_CST node. */
129 %token STRING
130
131 /* "...", used for functions with variable arglists. */
132 %token ELLIPSIS
133
134 /* the reserved words */
135 /* SCO include files test "ASM", so use something else. */
136 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
137 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
138 %token ATTRIBUTE EXTENSION LABEL
139 %token REALPART IMAGPART
140
141 /* Add precedence rules to solve dangling else s/r conflict */
142 %nonassoc IF
143 %nonassoc ELSE
144
145 /* Define the operator tokens and their precedences.
146 The value is an integer because, if used, it is the tree code
147 to use in the expression made from the operator. */
148
149 %right <code> ASSIGN '='
150 %right <code> '?' ':'
151 %left <code> OROR
152 %left <code> ANDAND
153 %left <code> '|'
154 %left <code> '^'
155 %left <code> '&'
156 %left <code> EQCOMPARE
157 %left <code> ARITHCOMPARE
158 %left <code> LSHIFT RSHIFT
159 %left <code> '+' '-'
160 %left <code> '*' '/' '%'
161 %right <code> UNARY PLUSPLUS MINUSMINUS
162 %left HYPERUNARY
163 %left <code> POINTSAT '.' '(' '['
164
165 /* The Objective-C keywords. These are included in C and in
166 Objective C, so that the token codes are the same in both. */
167 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
168 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
169
170 /* Objective-C string constants in raw form.
171 yylval is an OBJC_STRING_CST node. */
172 %token OBJC_STRING
173
174
175 %type <code> unop
176
177 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
178 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
179 %type <ttype> typed_declspecs reserved_declspecs
180 %type <ttype> typed_typespecs reserved_typespecquals
181 %type <ttype> declmods typespec typespecqual_reserved
182 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
183 %type <ttype> declmods_no_prefix_attr
184 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
185 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
186 %type <ttype> init maybeasm
187 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
188 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
189 %type <ttype> any_word
190
191 %type <ttype> compstmt
192
193 %type <ttype> declarator
194 %type <ttype> notype_declarator after_type_declarator
195 %type <ttype> parm_declarator
196
197 %type <ttype> structsp component_decl_list component_decl_list2
198 %type <ttype> component_decl components component_declarator
199 %type <ttype> enumlist enumerator
200 %type <ttype> struct_head union_head enum_head
201 %type <ttype> typename absdcl absdcl1 type_quals
202 %type <ttype> xexpr parms parm identifiers
203
204 %type <ttype> parmlist parmlist_1 parmlist_2
205 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
206 %type <ttype> identifiers_or_typenames
207
208 %type <itype> setspecs
209
210 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
211
212 %type <filename> save_filename
213 %type <lineno> save_lineno
214 \f
215 ifobjc
216 /* the Objective-C nonterminals */
217
218 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
219 %type <ttype> methoddecl unaryselector keywordselector selector
220 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
221 %type <ttype> keywordexpr keywordarglist keywordarg
222 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
223 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
224 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
225
226 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
227 end ifobjc
228 \f
229 %{
230 /* Number of statements (loosely speaking) and compound statements
231 seen so far. */
232 static int stmt_count;
233 static int compstmt_count;
234
235 /* Input file and line number of the end of the body of last simple_if;
236 used by the stmt-rule immediately after simple_if returns. */
237 static char *if_stmt_file;
238 static int if_stmt_line;
239
240 /* List of types and structure classes of the current declaration. */
241 static tree current_declspecs = NULL_TREE;
242 static tree prefix_attributes = NULL_TREE;
243
244 /* Stack of saved values of current_declspecs and prefix_attributes. */
245 static tree declspec_stack;
246
247 /* 1 if we explained undeclared var errors. */
248 static int undeclared_variable_notice;
249
250 ifobjc
251 /* Objective-C specific information */
252
253 tree objc_interface_context;
254 tree objc_implementation_context;
255 tree objc_method_context;
256 tree objc_ivar_chain;
257 tree objc_ivar_context;
258 enum tree_code objc_inherit_code;
259 int objc_receiver_context;
260 int objc_public_flag;
261
262 end ifobjc
263
264 /* Tell yyparse how to print a token's value, if yydebug is set. */
265
266 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
267 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
268 %}
269 \f
270 %%
271 program: /* empty */
272 { if (pedantic)
273 pedwarn ("ANSI C forbids an empty source file");
274 finish_file ();
275 }
276 | extdefs
277 {
278 /* In case there were missing closebraces,
279 get us back to the global binding level. */
280 while (! global_bindings_p ())
281 poplevel (0, 0, 0);
282 finish_file ();
283 }
284 ;
285
286 /* the reason for the strange actions in this rule
287 is so that notype_initdecls when reached via datadef
288 can find a valid list of type and sc specs in $0. */
289
290 extdefs:
291 {$<ttype>$ = NULL_TREE; } extdef
292 | extdefs {$<ttype>$ = NULL_TREE; } extdef
293 ;
294
295 extdef:
296 fndef
297 | datadef
298 ifobjc
299 | objcdef
300 end ifobjc
301 | ASM_KEYWORD '(' expr ')' ';'
302 { STRIP_NOPS ($3);
303 if ((TREE_CODE ($3) == ADDR_EXPR
304 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
305 || TREE_CODE ($3) == STRING_CST)
306 assemble_asm ($3);
307 else
308 error ("argument of `asm' is not a constant string"); }
309 | extension extdef
310 { pedantic = $<itype>1; }
311 ;
312
313 datadef:
314 setspecs notype_initdecls ';'
315 { if (pedantic)
316 error ("ANSI C forbids data definition with no type or storage class");
317 else if (!flag_traditional)
318 warning ("data definition has no type or storage class");
319
320 current_declspecs = TREE_VALUE (declspec_stack);
321 prefix_attributes = TREE_PURPOSE (declspec_stack);
322 declspec_stack = TREE_CHAIN (declspec_stack);
323 resume_momentary ($1); }
324 | declmods setspecs notype_initdecls ';'
325 { current_declspecs = TREE_VALUE (declspec_stack);
326 prefix_attributes = TREE_PURPOSE (declspec_stack);
327 declspec_stack = TREE_CHAIN (declspec_stack);
328 resume_momentary ($2); }
329 | typed_declspecs setspecs initdecls ';'
330 { current_declspecs = TREE_VALUE (declspec_stack);
331 prefix_attributes = TREE_PURPOSE (declspec_stack);
332 declspec_stack = TREE_CHAIN (declspec_stack);
333 resume_momentary ($2); }
334 | declmods ';'
335 { pedwarn ("empty declaration"); }
336 | typed_declspecs ';'
337 { shadow_tag ($1); }
338 | error ';'
339 | error '}'
340 | ';'
341 { if (pedantic)
342 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
343 ;
344 \f
345 fndef:
346 typed_declspecs setspecs declarator
347 { if (! start_function (current_declspecs, $3,
348 prefix_attributes, NULL_TREE, 0))
349 YYERROR1;
350 reinit_parse_for_function (); }
351 old_style_parm_decls
352 { store_parm_decls (); }
353 compstmt_or_error
354 { finish_function (0);
355 current_declspecs = TREE_VALUE (declspec_stack);
356 prefix_attributes = TREE_PURPOSE (declspec_stack);
357 declspec_stack = TREE_CHAIN (declspec_stack);
358 resume_momentary ($2); }
359 | typed_declspecs setspecs declarator error
360 { current_declspecs = TREE_VALUE (declspec_stack);
361 prefix_attributes = TREE_PURPOSE (declspec_stack);
362 declspec_stack = TREE_CHAIN (declspec_stack);
363 resume_momentary ($2); }
364 | declmods setspecs notype_declarator
365 { if (! start_function (current_declspecs, $3,
366 prefix_attributes, NULL_TREE, 0))
367 YYERROR1;
368 reinit_parse_for_function (); }
369 old_style_parm_decls
370 { store_parm_decls (); }
371 compstmt_or_error
372 { finish_function (0);
373 current_declspecs = TREE_VALUE (declspec_stack);
374 prefix_attributes = TREE_PURPOSE (declspec_stack);
375 declspec_stack = TREE_CHAIN (declspec_stack);
376 resume_momentary ($2); }
377 | declmods setspecs notype_declarator error
378 { current_declspecs = TREE_VALUE (declspec_stack);
379 prefix_attributes = TREE_PURPOSE (declspec_stack);
380 declspec_stack = TREE_CHAIN (declspec_stack);
381 resume_momentary ($2); }
382 | setspecs notype_declarator
383 { if (! start_function (NULL_TREE, $2,
384 prefix_attributes, NULL_TREE, 0))
385 YYERROR1;
386 reinit_parse_for_function (); }
387 old_style_parm_decls
388 { store_parm_decls (); }
389 compstmt_or_error
390 { finish_function (0);
391 current_declspecs = TREE_VALUE (declspec_stack);
392 prefix_attributes = TREE_PURPOSE (declspec_stack);
393 declspec_stack = TREE_CHAIN (declspec_stack);
394 resume_momentary ($1); }
395 | setspecs notype_declarator error
396 { current_declspecs = TREE_VALUE (declspec_stack);
397 prefix_attributes = TREE_PURPOSE (declspec_stack);
398 declspec_stack = TREE_CHAIN (declspec_stack);
399 resume_momentary ($1); }
400 ;
401
402 identifier:
403 IDENTIFIER
404 | TYPENAME
405 ifobjc
406 | OBJECTNAME
407 | CLASSNAME
408 end ifobjc
409 ;
410
411 unop: '&'
412 { $$ = ADDR_EXPR; }
413 | '-'
414 { $$ = NEGATE_EXPR; }
415 | '+'
416 { $$ = CONVERT_EXPR; }
417 | PLUSPLUS
418 { $$ = PREINCREMENT_EXPR; }
419 | MINUSMINUS
420 { $$ = PREDECREMENT_EXPR; }
421 | '~'
422 { $$ = BIT_NOT_EXPR; }
423 | '!'
424 { $$ = TRUTH_NOT_EXPR; }
425 ;
426
427 expr: nonnull_exprlist
428 { $$ = build_compound_expr ($1); }
429 ;
430
431 exprlist:
432 /* empty */
433 { $$ = NULL_TREE; }
434 | nonnull_exprlist
435 ;
436
437 nonnull_exprlist:
438 expr_no_commas
439 { $$ = build_tree_list (NULL_TREE, $1); }
440 | nonnull_exprlist ',' expr_no_commas
441 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
442 ;
443
444 unary_expr:
445 primary
446 | '*' cast_expr %prec UNARY
447 { $$ = build_indirect_ref ($2, "unary *"); }
448 /* __extension__ turns off -pedantic for following primary. */
449 | extension cast_expr %prec UNARY
450 { $$ = $2;
451 pedantic = $<itype>1; }
452 | unop cast_expr %prec UNARY
453 { $$ = build_unary_op ($1, $2, 0);
454 overflow_warning ($$); }
455 /* Refer to the address of a label as a pointer. */
456 | ANDAND identifier
457 { tree label = lookup_label ($2);
458 if (pedantic)
459 pedwarn ("ANSI C forbids `&&'");
460 if (label == 0)
461 $$ = null_pointer_node;
462 else
463 {
464 TREE_USED (label) = 1;
465 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
466 TREE_CONSTANT ($$) = 1;
467 }
468 }
469 /* This seems to be impossible on some machines, so let's turn it off.
470 You can use __builtin_next_arg to find the anonymous stack args.
471 | '&' ELLIPSIS
472 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
473 $$ = error_mark_node;
474 if (TREE_VALUE (tree_last (types)) == void_type_node)
475 error ("`&...' used in function with fixed number of arguments");
476 else
477 {
478 if (pedantic)
479 pedwarn ("ANSI C forbids `&...'");
480 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
481 $$ = build_unary_op (ADDR_EXPR, $$, 0);
482 } }
483 */
484 | sizeof unary_expr %prec UNARY
485 { skip_evaluation--;
486 if (TREE_CODE ($2) == COMPONENT_REF
487 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
488 error ("`sizeof' applied to a bit-field");
489 $$ = c_sizeof (TREE_TYPE ($2)); }
490 | sizeof '(' typename ')' %prec HYPERUNARY
491 { skip_evaluation--;
492 $$ = c_sizeof (groktypename ($3)); }
493 | alignof unary_expr %prec UNARY
494 { skip_evaluation--;
495 $$ = c_alignof_expr ($2); }
496 | alignof '(' typename ')' %prec HYPERUNARY
497 { skip_evaluation--;
498 $$ = c_alignof (groktypename ($3)); }
499 | REALPART cast_expr %prec UNARY
500 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
501 | IMAGPART cast_expr %prec UNARY
502 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
503 ;
504
505 sizeof:
506 SIZEOF { skip_evaluation++; }
507 ;
508
509 alignof:
510 ALIGNOF { skip_evaluation++; }
511 ;
512
513 cast_expr:
514 unary_expr
515 | '(' typename ')' cast_expr %prec UNARY
516 { tree type = groktypename ($2);
517 $$ = build_c_cast (type, $4); }
518 | '(' typename ')' '{'
519 { start_init (NULL_TREE, NULL, 0);
520 $2 = groktypename ($2);
521 really_start_incremental_init ($2); }
522 initlist_maybe_comma '}' %prec UNARY
523 { char *name;
524 tree result = pop_init_level (0);
525 tree type = $2;
526 finish_init ();
527
528 if (pedantic && ! flag_isoc9x)
529 pedwarn ("ANSI C forbids constructor expressions");
530 if (TYPE_NAME (type) != 0)
531 {
532 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
533 name = IDENTIFIER_POINTER (TYPE_NAME (type));
534 else
535 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
536 }
537 else
538 name = "";
539 $$ = result;
540 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
541 {
542 int failure = complete_array_type (type, $$, 1);
543 if (failure)
544 abort ();
545 }
546 }
547 ;
548
549 expr_no_commas:
550 cast_expr
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 '*' expr_no_commas
556 { $$ = parser_build_binary_op ($2, $1, $3); }
557 | expr_no_commas '/' expr_no_commas
558 { $$ = parser_build_binary_op ($2, $1, $3); }
559 | expr_no_commas '%' expr_no_commas
560 { $$ = parser_build_binary_op ($2, $1, $3); }
561 | expr_no_commas LSHIFT expr_no_commas
562 { $$ = parser_build_binary_op ($2, $1, $3); }
563 | expr_no_commas RSHIFT expr_no_commas
564 { $$ = parser_build_binary_op ($2, $1, $3); }
565 | expr_no_commas ARITHCOMPARE expr_no_commas
566 { $$ = parser_build_binary_op ($2, $1, $3); }
567 | expr_no_commas EQCOMPARE expr_no_commas
568 { $$ = parser_build_binary_op ($2, $1, $3); }
569 | expr_no_commas '&' expr_no_commas
570 { $$ = parser_build_binary_op ($2, $1, $3); }
571 | expr_no_commas '|' expr_no_commas
572 { $$ = parser_build_binary_op ($2, $1, $3); }
573 | expr_no_commas '^' expr_no_commas
574 { $$ = parser_build_binary_op ($2, $1, $3); }
575 | expr_no_commas ANDAND
576 { $1 = truthvalue_conversion (default_conversion ($1));
577 skip_evaluation += $1 == boolean_false_node; }
578 expr_no_commas
579 { skip_evaluation -= $1 == boolean_false_node;
580 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
581 | expr_no_commas OROR
582 { $1 = truthvalue_conversion (default_conversion ($1));
583 skip_evaluation += $1 == boolean_true_node; }
584 expr_no_commas
585 { skip_evaluation -= $1 == boolean_true_node;
586 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
587 | expr_no_commas '?'
588 { $1 = truthvalue_conversion (default_conversion ($1));
589 skip_evaluation += $1 == boolean_false_node; }
590 expr ':'
591 { skip_evaluation += (($1 == boolean_true_node)
592 - ($1 == boolean_false_node)); }
593 expr_no_commas
594 { skip_evaluation -= $1 == boolean_true_node;
595 $$ = build_conditional_expr ($1, $4, $7); }
596 | expr_no_commas '?'
597 { if (pedantic)
598 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
599 /* Make sure first operand is calculated only once. */
600 $<ttype>2 = save_expr ($1);
601 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
602 skip_evaluation += $1 == boolean_true_node; }
603 ':' expr_no_commas
604 { skip_evaluation -= $1 == boolean_true_node;
605 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
606 | expr_no_commas '=' expr_no_commas
607 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
608 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
609 | expr_no_commas ASSIGN expr_no_commas
610 { $$ = build_modify_expr ($1, $2, $3);
611 /* This inhibits warnings in truthvalue_conversion. */
612 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
613 ;
614
615 primary:
616 IDENTIFIER
617 {
618 $$ = lastiddecl;
619 if (!$$ || $$ == error_mark_node)
620 {
621 if (yychar == YYEMPTY)
622 yychar = YYLEX;
623 if (yychar == '(')
624 {
625 ifobjc
626 tree decl;
627
628 if (objc_receiver_context
629 && ! (objc_receiver_context
630 && strcmp (IDENTIFIER_POINTER ($1), "super")))
631 /* we have a message to super */
632 $$ = get_super_receiver ();
633 else if (objc_method_context
634 && (decl = is_ivar (objc_ivar_chain, $1)))
635 {
636 if (is_private (decl))
637 $$ = error_mark_node;
638 else
639 $$ = build_ivar_reference ($1);
640 }
641 else
642 end ifobjc
643 {
644 /* Ordinary implicit function declaration. */
645 $$ = implicitly_declare ($1);
646 assemble_external ($$);
647 TREE_USED ($$) = 1;
648 }
649 }
650 else if (current_function_decl == 0)
651 {
652 error ("`%s' undeclared here (not in a function)",
653 IDENTIFIER_POINTER ($1));
654 $$ = error_mark_node;
655 }
656 else
657 {
658 ifobjc
659 tree decl;
660
661 if (objc_receiver_context
662 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
663 /* we have a message to super */
664 $$ = get_super_receiver ();
665 else if (objc_method_context
666 && (decl = is_ivar (objc_ivar_chain, $1)))
667 {
668 if (is_private (decl))
669 $$ = error_mark_node;
670 else
671 $$ = build_ivar_reference ($1);
672 }
673 else
674 end ifobjc
675 {
676 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
677 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
678 {
679 error ("`%s' undeclared (first use in this function)",
680 IDENTIFIER_POINTER ($1));
681
682 if (! undeclared_variable_notice)
683 {
684 error ("(Each undeclared identifier is reported only once");
685 error ("for each function it appears in.)");
686 undeclared_variable_notice = 1;
687 }
688 }
689 $$ = error_mark_node;
690 /* Prevent repeated error messages. */
691 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
692 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
693 }
694 }
695 }
696 else if (TREE_TYPE ($$) == error_mark_node)
697 $$ = error_mark_node;
698 else if (C_DECL_ANTICIPATED ($$))
699 {
700 /* The first time we see a build-in function used,
701 if it has not been declared. */
702 C_DECL_ANTICIPATED ($$) = 0;
703 if (yychar == YYEMPTY)
704 yychar = YYLEX;
705 if (yychar == '(')
706 {
707 /* Omit the implicit declaration we
708 would ordinarily do, so we don't lose
709 the actual built in type.
710 But print a diagnostic for the mismatch. */
711 ifobjc
712 if (objc_method_context
713 && is_ivar (objc_ivar_chain, $1))
714 error ("Instance variable `%s' implicitly declared as function",
715 IDENTIFIER_POINTER (DECL_NAME ($$)));
716 else
717 end ifobjc
718 if (TREE_CODE ($$) != FUNCTION_DECL)
719 error ("`%s' implicitly declared as function",
720 IDENTIFIER_POINTER (DECL_NAME ($$)));
721 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
722 != TYPE_MODE (integer_type_node))
723 && (TREE_TYPE (TREE_TYPE ($$))
724 != void_type_node))
725 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
726 IDENTIFIER_POINTER (DECL_NAME ($$)));
727 /* If it really returns void, change that to int. */
728 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
729 TREE_TYPE ($$)
730 = build_function_type (integer_type_node,
731 TYPE_ARG_TYPES (TREE_TYPE ($$)));
732 }
733 else
734 pedwarn ("built-in function `%s' used without declaration",
735 IDENTIFIER_POINTER (DECL_NAME ($$)));
736
737 /* Do what we would ordinarily do when a fn is used. */
738 assemble_external ($$);
739 TREE_USED ($$) = 1;
740 }
741 else
742 {
743 assemble_external ($$);
744 TREE_USED ($$) = 1;
745 ifobjc
746 /* we have a definition - still check if iVariable */
747
748 if (!objc_receiver_context
749 || (objc_receiver_context
750 && strcmp (IDENTIFIER_POINTER ($1), "super")))
751 {
752 tree decl;
753
754 if (objc_method_context
755 && (decl = is_ivar (objc_ivar_chain, $1)))
756 {
757 if (IDENTIFIER_LOCAL_VALUE ($1))
758 warning ("local declaration of `%s' hides instance variable",
759 IDENTIFIER_POINTER ($1));
760 else
761 {
762 if (is_private (decl))
763 $$ = error_mark_node;
764 else
765 $$ = build_ivar_reference ($1);
766 }
767 }
768 }
769 else /* we have a message to super */
770 $$ = get_super_receiver ();
771 end ifobjc
772 }
773
774 if (TREE_CODE ($$) == CONST_DECL)
775 {
776 $$ = DECL_INITIAL ($$);
777 /* This is to prevent an enum whose value is 0
778 from being considered a null pointer constant. */
779 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
780 TREE_CONSTANT ($$) = 1;
781 }
782 }
783 | CONSTANT
784 | string
785 { $$ = combine_strings ($1); }
786 | '(' expr ')'
787 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
788 if (class == 'e' || class == '1'
789 || class == '2' || class == '<')
790 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
791 $$ = $2; }
792 | '(' error ')'
793 { $$ = error_mark_node; }
794 | '('
795 { if (current_function_decl == 0)
796 {
797 error ("braced-group within expression allowed only inside a function");
798 YYERROR;
799 }
800 /* We must force a BLOCK for this level
801 so that, if it is not expanded later,
802 there is a way to turn off the entire subtree of blocks
803 that are contained in it. */
804 keep_next_level ();
805 push_iterator_stack ();
806 push_label_level ();
807 $<ttype>$ = expand_start_stmt_expr (); }
808 compstmt ')'
809 { tree rtl_exp;
810 if (pedantic)
811 pedwarn ("ANSI C forbids braced-groups within expressions");
812 pop_iterator_stack ();
813 pop_label_level ();
814 rtl_exp = expand_end_stmt_expr ($<ttype>2);
815 /* The statements have side effects, so the group does. */
816 TREE_SIDE_EFFECTS (rtl_exp) = 1;
817
818 if (TREE_CODE ($3) == BLOCK)
819 {
820 /* Make a BIND_EXPR for the BLOCK already made. */
821 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
822 NULL_TREE, rtl_exp, $3);
823 /* Remove the block from the tree at this point.
824 It gets put back at the proper place
825 when the BIND_EXPR is expanded. */
826 delete_block ($3);
827 }
828 else
829 $$ = $3;
830 }
831 | primary '(' exprlist ')' %prec '.'
832 { $$ = build_function_call ($1, $3); }
833 | primary '[' expr ']' %prec '.'
834 { $$ = build_array_ref ($1, $3); }
835 | primary '.' identifier
836 {
837 ifobjc
838 if (doing_objc_thang)
839 {
840 if (is_public ($1, $3))
841 $$ = build_component_ref ($1, $3);
842 else
843 $$ = error_mark_node;
844 }
845 else
846 end ifobjc
847 $$ = build_component_ref ($1, $3);
848 }
849 | primary POINTSAT identifier
850 {
851 tree expr = build_indirect_ref ($1, "->");
852
853 ifobjc
854 if (doing_objc_thang)
855 {
856 if (is_public (expr, $3))
857 $$ = build_component_ref (expr, $3);
858 else
859 $$ = error_mark_node;
860 }
861 else
862 end ifobjc
863 $$ = build_component_ref (expr, $3);
864 }
865 | primary PLUSPLUS
866 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
867 | primary MINUSMINUS
868 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
869 ifobjc
870 | objcmessageexpr
871 { $$ = build_message_expr ($1); }
872 | objcselectorexpr
873 { $$ = build_selector_expr ($1); }
874 | objcprotocolexpr
875 { $$ = build_protocol_expr ($1); }
876 | objcencodeexpr
877 { $$ = build_encode_expr ($1); }
878 | objc_string
879 { $$ = build_objc_string_object ($1); }
880 end ifobjc
881 ;
882
883 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
884 string:
885 STRING
886 | string STRING
887 { $$ = chainon ($1, $2); }
888 ;
889
890 ifobjc
891 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
892 onto it. */
893 objc_string:
894 OBJC_STRING
895 | objc_string OBJC_STRING
896 { $$ = chainon ($1, $2); }
897 ;
898 end ifobjc
899
900 old_style_parm_decls:
901 /* empty */
902 | datadecls
903 | datadecls ELLIPSIS
904 /* ... is used here to indicate a varargs function. */
905 { c_mark_varargs ();
906 if (pedantic)
907 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
908 ;
909
910 /* The following are analogous to lineno_decl, decls and decl
911 except that they do not allow nested functions.
912 They are used for old-style parm decls. */
913 lineno_datadecl:
914 save_filename save_lineno datadecl
915 { }
916 ;
917
918 datadecls:
919 lineno_datadecl
920 | errstmt
921 | datadecls lineno_datadecl
922 | lineno_datadecl errstmt
923 ;
924
925 /* We don't allow prefix attributes here because they cause reduce/reduce
926 conflicts: we can't know whether we're parsing a function decl with
927 attribute suffix, or function defn with attribute prefix on first old
928 style parm. */
929 datadecl:
930 typed_declspecs_no_prefix_attr setspecs initdecls ';'
931 { current_declspecs = TREE_VALUE (declspec_stack);
932 prefix_attributes = TREE_PURPOSE (declspec_stack);
933 declspec_stack = TREE_CHAIN (declspec_stack);
934 resume_momentary ($2); }
935 | declmods_no_prefix_attr setspecs notype_initdecls ';'
936 { current_declspecs = TREE_VALUE (declspec_stack);
937 prefix_attributes = TREE_PURPOSE (declspec_stack);
938 declspec_stack = TREE_CHAIN (declspec_stack);
939 resume_momentary ($2); }
940 | typed_declspecs_no_prefix_attr ';'
941 { shadow_tag_warned ($1, 1);
942 pedwarn ("empty declaration"); }
943 | declmods_no_prefix_attr ';'
944 { pedwarn ("empty declaration"); }
945 ;
946
947 /* This combination which saves a lineno before a decl
948 is the normal thing to use, rather than decl itself.
949 This is to avoid shift/reduce conflicts in contexts
950 where statement labels are allowed. */
951 lineno_decl:
952 save_filename save_lineno decl
953 { }
954 ;
955
956 decls:
957 lineno_decl
958 | errstmt
959 | decls lineno_decl
960 | lineno_decl errstmt
961 ;
962
963 /* records the type and storage class specs to use for processing
964 the declarators that follow.
965 Maintains a stack of outer-level values of current_declspecs,
966 for the sake of parm declarations nested in function declarators. */
967 setspecs: /* empty */
968 { $$ = suspend_momentary ();
969 pending_xref_error ();
970 declspec_stack = tree_cons (prefix_attributes,
971 current_declspecs,
972 declspec_stack);
973 split_specs_attrs ($<ttype>0,
974 &current_declspecs, &prefix_attributes); }
975 ;
976
977 /* ??? Yuck. See after_type_declarator. */
978 setattrs: /* empty */
979 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
980 ;
981
982 decl:
983 typed_declspecs setspecs initdecls ';'
984 { current_declspecs = TREE_VALUE (declspec_stack);
985 prefix_attributes = TREE_PURPOSE (declspec_stack);
986 declspec_stack = TREE_CHAIN (declspec_stack);
987 resume_momentary ($2); }
988 | declmods setspecs notype_initdecls ';'
989 { current_declspecs = TREE_VALUE (declspec_stack);
990 prefix_attributes = TREE_PURPOSE (declspec_stack);
991 declspec_stack = TREE_CHAIN (declspec_stack);
992 resume_momentary ($2); }
993 | typed_declspecs setspecs nested_function
994 { current_declspecs = TREE_VALUE (declspec_stack);
995 prefix_attributes = TREE_PURPOSE (declspec_stack);
996 declspec_stack = TREE_CHAIN (declspec_stack);
997 resume_momentary ($2); }
998 | declmods setspecs notype_nested_function
999 { current_declspecs = TREE_VALUE (declspec_stack);
1000 prefix_attributes = TREE_PURPOSE (declspec_stack);
1001 declspec_stack = TREE_CHAIN (declspec_stack);
1002 resume_momentary ($2); }
1003 | typed_declspecs ';'
1004 { shadow_tag ($1); }
1005 | declmods ';'
1006 { pedwarn ("empty declaration"); }
1007 | extension decl
1008 { pedantic = $<itype>1; }
1009 ;
1010
1011 /* Declspecs which contain at least one type specifier or typedef name.
1012 (Just `const' or `volatile' is not enough.)
1013 A typedef'd name following these is taken as a name to be declared.
1014 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1015
1016 typed_declspecs:
1017 typespec reserved_declspecs
1018 { $$ = tree_cons (NULL_TREE, $1, $2); }
1019 | declmods typespec reserved_declspecs
1020 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1021 ;
1022
1023 reserved_declspecs: /* empty */
1024 { $$ = NULL_TREE; }
1025 | reserved_declspecs typespecqual_reserved
1026 { $$ = tree_cons (NULL_TREE, $2, $1); }
1027 | reserved_declspecs SCSPEC
1028 { if (extra_warnings)
1029 warning ("`%s' is not at beginning of declaration",
1030 IDENTIFIER_POINTER ($2));
1031 $$ = tree_cons (NULL_TREE, $2, $1); }
1032 | reserved_declspecs attributes
1033 { $$ = tree_cons ($2, NULL_TREE, $1); }
1034 ;
1035
1036 typed_declspecs_no_prefix_attr:
1037 typespec reserved_declspecs_no_prefix_attr
1038 { $$ = tree_cons (NULL_TREE, $1, $2); }
1039 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
1040 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1041 ;
1042
1043 reserved_declspecs_no_prefix_attr:
1044 /* empty */
1045 { $$ = NULL_TREE; }
1046 | reserved_declspecs_no_prefix_attr typespecqual_reserved
1047 { $$ = tree_cons (NULL_TREE, $2, $1); }
1048 | reserved_declspecs_no_prefix_attr SCSPEC
1049 { if (extra_warnings)
1050 warning ("`%s' is not at beginning of declaration",
1051 IDENTIFIER_POINTER ($2));
1052 $$ = tree_cons (NULL_TREE, $2, $1); }
1053 ;
1054
1055 /* List of just storage classes, type modifiers, and prefix attributes.
1056 A declaration can start with just this, but then it cannot be used
1057 to redeclare a typedef-name.
1058 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1059
1060 declmods:
1061 declmods_no_prefix_attr
1062 { $$ = $1; }
1063 | attributes
1064 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
1065 | declmods declmods_no_prefix_attr
1066 { $$ = chainon ($2, $1); }
1067 | declmods attributes
1068 { $$ = tree_cons ($2, NULL_TREE, $1); }
1069 ;
1070
1071 declmods_no_prefix_attr:
1072 TYPE_QUAL
1073 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1074 TREE_STATIC ($$) = 1; }
1075 | SCSPEC
1076 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1077 | declmods_no_prefix_attr TYPE_QUAL
1078 { $$ = tree_cons (NULL_TREE, $2, $1);
1079 TREE_STATIC ($$) = 1; }
1080 | declmods_no_prefix_attr SCSPEC
1081 { if (extra_warnings && TREE_STATIC ($1))
1082 warning ("`%s' is not at beginning of declaration",
1083 IDENTIFIER_POINTER ($2));
1084 $$ = tree_cons (NULL_TREE, $2, $1);
1085 TREE_STATIC ($$) = TREE_STATIC ($1); }
1086 ;
1087
1088
1089 /* Used instead of declspecs where storage classes are not allowed
1090 (that is, for typenames and structure components).
1091 Don't accept a typedef-name if anything but a modifier precedes it. */
1092
1093 typed_typespecs:
1094 typespec reserved_typespecquals
1095 { $$ = tree_cons (NULL_TREE, $1, $2); }
1096 | nonempty_type_quals typespec reserved_typespecquals
1097 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1098 ;
1099
1100 reserved_typespecquals: /* empty */
1101 { $$ = NULL_TREE; }
1102 | reserved_typespecquals typespecqual_reserved
1103 { $$ = tree_cons (NULL_TREE, $2, $1); }
1104 ;
1105
1106 /* A typespec (but not a type qualifier).
1107 Once we have seen one of these in a declaration,
1108 if a typedef name appears then it is being redeclared. */
1109
1110 typespec: TYPESPEC
1111 | structsp
1112 | TYPENAME
1113 { /* For a typedef name, record the meaning, not the name.
1114 In case of `foo foo, bar;'. */
1115 $$ = lookup_name ($1); }
1116 ifobjc
1117 | CLASSNAME protocolrefs
1118 { $$ = get_static_reference ($1, $2); }
1119 | OBJECTNAME protocolrefs
1120 { $$ = get_object_reference ($2); }
1121
1122 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1123 - nisse@lysator.liu.se */
1124 | non_empty_protocolrefs
1125 { $$ = get_object_reference ($1); }
1126 end ifobjc
1127 | TYPEOF '(' expr ')'
1128 { $$ = TREE_TYPE ($3); }
1129 | TYPEOF '(' typename ')'
1130 { $$ = groktypename ($3); }
1131 ;
1132
1133 /* A typespec that is a reserved word, or a type qualifier. */
1134
1135 typespecqual_reserved: TYPESPEC
1136 | TYPE_QUAL
1137 | structsp
1138 ;
1139
1140 initdecls:
1141 initdcl
1142 | initdecls ',' initdcl
1143 ;
1144
1145 notype_initdecls:
1146 notype_initdcl
1147 | notype_initdecls ',' initdcl
1148 ;
1149
1150 maybeasm:
1151 /* empty */
1152 { $$ = NULL_TREE; }
1153 | ASM_KEYWORD '(' string ')'
1154 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1155 $$ = $3;
1156 }
1157 ;
1158
1159 initdcl:
1160 declarator maybeasm maybe_attribute '='
1161 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1162 $3, prefix_attributes);
1163 start_init ($<ttype>$, $2, global_bindings_p ()); }
1164 init
1165 /* Note how the declaration of the variable is in effect while its init is parsed! */
1166 { finish_init ();
1167 finish_decl ($<ttype>5, $6, $2); }
1168 | declarator maybeasm maybe_attribute
1169 { tree d = start_decl ($1, current_declspecs, 0,
1170 $3, prefix_attributes);
1171 finish_decl (d, NULL_TREE, $2);
1172 }
1173 ;
1174
1175 notype_initdcl:
1176 notype_declarator maybeasm maybe_attribute '='
1177 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1178 $3, prefix_attributes);
1179 start_init ($<ttype>$, $2, global_bindings_p ()); }
1180 init
1181 /* Note how the declaration of the variable is in effect while its init is parsed! */
1182 { finish_init ();
1183 decl_attributes ($<ttype>5, $3, prefix_attributes);
1184 finish_decl ($<ttype>5, $6, $2); }
1185 | notype_declarator maybeasm maybe_attribute
1186 { tree d = start_decl ($1, current_declspecs, 0,
1187 $3, prefix_attributes);
1188 finish_decl (d, NULL_TREE, $2); }
1189 ;
1190 /* the * rules are dummies to accept the Apollo extended syntax
1191 so that the header files compile. */
1192 maybe_attribute:
1193 /* empty */
1194 { $$ = NULL_TREE; }
1195 | attributes
1196 { $$ = $1; }
1197 ;
1198
1199 attributes:
1200 attribute
1201 { $$ = $1; }
1202 | attributes attribute
1203 { $$ = chainon ($1, $2); }
1204 ;
1205
1206 attribute:
1207 ATTRIBUTE '(' '(' attribute_list ')' ')'
1208 { $$ = $4; }
1209 ;
1210
1211 attribute_list:
1212 attrib
1213 { $$ = $1; }
1214 | attribute_list ',' attrib
1215 { $$ = chainon ($1, $3); }
1216 ;
1217
1218 attrib:
1219 /* empty */
1220 { $$ = NULL_TREE; }
1221 | any_word
1222 { $$ = build_tree_list ($1, NULL_TREE); }
1223 | any_word '(' IDENTIFIER ')'
1224 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1225 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1226 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1227 | any_word '(' exprlist ')'
1228 { $$ = build_tree_list ($1, $3); }
1229 ;
1230
1231 /* This still leaves out most reserved keywords,
1232 shouldn't we include them? */
1233
1234 any_word:
1235 identifier
1236 | SCSPEC
1237 | TYPESPEC
1238 | TYPE_QUAL
1239 ;
1240 \f
1241 /* Initializers. `init' is the entry point. */
1242
1243 init:
1244 expr_no_commas
1245 | '{'
1246 { really_start_incremental_init (NULL_TREE);
1247 /* Note that the call to clear_momentary
1248 is in process_init_element. */
1249 push_momentary (); }
1250 initlist_maybe_comma '}'
1251 { $$ = pop_init_level (0);
1252 if ($$ == error_mark_node
1253 && ! (yychar == STRING || yychar == CONSTANT))
1254 pop_momentary ();
1255 else
1256 pop_momentary_nofree (); }
1257
1258 | error
1259 { $$ = error_mark_node; }
1260 ;
1261
1262 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1263 initlist_maybe_comma:
1264 /* empty */
1265 { if (pedantic)
1266 pedwarn ("ANSI C forbids empty initializer braces"); }
1267 | initlist1 maybecomma
1268 ;
1269
1270 initlist1:
1271 initelt
1272 | initlist1 ',' initelt
1273 ;
1274
1275 /* `initelt' is a single element of an initializer.
1276 It may use braces. */
1277 initelt:
1278 designator_list '=' initval
1279 | designator initval
1280 | identifier ':'
1281 { set_init_label ($1); }
1282 initval
1283 | initval
1284 ;
1285
1286 initval:
1287 '{'
1288 { push_init_level (0); }
1289 initlist_maybe_comma '}'
1290 { process_init_element (pop_init_level (0)); }
1291 | expr_no_commas
1292 { process_init_element ($1); }
1293 | error
1294 ;
1295
1296 designator_list:
1297 designator
1298 | designator_list designator
1299 ;
1300
1301 designator:
1302 '.' identifier
1303 { set_init_label ($2); }
1304 /* These are for labeled elements. The syntax for an array element
1305 initializer conflicts with the syntax for an Objective-C message,
1306 so don't include these productions in the Objective-C grammar. */
1307 ifc
1308 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1309 { set_init_index ($2, $4); }
1310 | '[' expr_no_commas ']'
1311 { set_init_index ($2, NULL_TREE); }
1312 end ifc
1313 ;
1314 \f
1315 nested_function:
1316 declarator
1317 { push_c_function_context ();
1318 if (! start_function (current_declspecs, $1,
1319 prefix_attributes, NULL_TREE, 1))
1320 {
1321 pop_c_function_context ();
1322 YYERROR1;
1323 }
1324 reinit_parse_for_function (); }
1325 old_style_parm_decls
1326 { store_parm_decls (); }
1327 /* This used to use compstmt_or_error.
1328 That caused a bug with input `f(g) int g {}',
1329 where the use of YYERROR1 above caused an error
1330 which then was handled by compstmt_or_error.
1331 There followed a repeated execution of that same rule,
1332 which called YYERROR1 again, and so on. */
1333 compstmt
1334 { finish_function (1);
1335 pop_c_function_context (); }
1336 ;
1337
1338 notype_nested_function:
1339 notype_declarator
1340 { push_c_function_context ();
1341 if (! start_function (current_declspecs, $1,
1342 prefix_attributes, NULL_TREE, 1))
1343 {
1344 pop_c_function_context ();
1345 YYERROR1;
1346 }
1347 reinit_parse_for_function (); }
1348 old_style_parm_decls
1349 { store_parm_decls (); }
1350 /* This used to use compstmt_or_error.
1351 That caused a bug with input `f(g) int g {}',
1352 where the use of YYERROR1 above caused an error
1353 which then was handled by compstmt_or_error.
1354 There followed a repeated execution of that same rule,
1355 which called YYERROR1 again, and so on. */
1356 compstmt
1357 { finish_function (1);
1358 pop_c_function_context (); }
1359 ;
1360
1361 /* Any kind of declarator (thus, all declarators allowed
1362 after an explicit typespec). */
1363
1364 declarator:
1365 after_type_declarator
1366 | notype_declarator
1367 ;
1368
1369 /* A declarator that is allowed only after an explicit typespec. */
1370
1371 after_type_declarator:
1372 '(' after_type_declarator ')'
1373 { $$ = $2; }
1374 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1375 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1376 /* | after_type_declarator '(' error ')' %prec '.'
1377 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1378 poplevel (0, 0, 0); } */
1379 | after_type_declarator '[' expr ']' %prec '.'
1380 { $$ = build_nt (ARRAY_REF, $1, $3); }
1381 | after_type_declarator '[' ']' %prec '.'
1382 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1383 | '*' type_quals after_type_declarator %prec UNARY
1384 { $$ = make_pointer_declarator ($2, $3); }
1385 /* ??? Yuck. setattrs is a quick hack. We can't use
1386 prefix_attributes because $1 only applies to this
1387 declarator. We assume setspecs has already been done.
1388 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1389 attributes could be recognized here or in `attributes'). */
1390 | attributes setattrs after_type_declarator
1391 { $$ = $3; }
1392 | TYPENAME
1393 ifobjc
1394 | OBJECTNAME
1395 end ifobjc
1396 ;
1397
1398 /* Kinds of declarator that can appear in a parameter list
1399 in addition to notype_declarator. This is like after_type_declarator
1400 but does not allow a typedef name in parentheses as an identifier
1401 (because it would conflict with a function with that typedef as arg). */
1402
1403 parm_declarator:
1404 parm_declarator '(' parmlist_or_identifiers %prec '.'
1405 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1406 /* | parm_declarator '(' error ')' %prec '.'
1407 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1408 poplevel (0, 0, 0); } */
1409 ifc
1410 | parm_declarator '[' '*' ']' %prec '.'
1411 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1412 if (! flag_isoc9x)
1413 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1414 }
1415 end ifc
1416 | parm_declarator '[' expr ']' %prec '.'
1417 { $$ = build_nt (ARRAY_REF, $1, $3); }
1418 | parm_declarator '[' ']' %prec '.'
1419 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1420 | '*' type_quals parm_declarator %prec UNARY
1421 { $$ = make_pointer_declarator ($2, $3); }
1422 /* ??? Yuck. setattrs is a quick hack. We can't use
1423 prefix_attributes because $1 only applies to this
1424 declarator. We assume setspecs has already been done.
1425 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1426 attributes could be recognized here or in `attributes'). */
1427 | attributes setattrs parm_declarator
1428 { $$ = $3; }
1429 | TYPENAME
1430 ;
1431
1432 /* A declarator allowed whether or not there has been
1433 an explicit typespec. These cannot redeclare a typedef-name. */
1434
1435 notype_declarator:
1436 notype_declarator '(' parmlist_or_identifiers %prec '.'
1437 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1438 /* | notype_declarator '(' error ')' %prec '.'
1439 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1440 poplevel (0, 0, 0); } */
1441 | '(' notype_declarator ')'
1442 { $$ = $2; }
1443 | '*' type_quals notype_declarator %prec UNARY
1444 { $$ = make_pointer_declarator ($2, $3); }
1445 ifc
1446 | notype_declarator '[' '*' ']' %prec '.'
1447 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1448 if (! flag_isoc9x)
1449 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1450 }
1451 end ifc
1452 | notype_declarator '[' expr ']' %prec '.'
1453 { $$ = build_nt (ARRAY_REF, $1, $3); }
1454 | notype_declarator '[' ']' %prec '.'
1455 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1456 /* ??? Yuck. setattrs is a quick hack. We can't use
1457 prefix_attributes because $1 only applies to this
1458 declarator. We assume setspecs has already been done.
1459 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1460 attributes could be recognized here or in `attributes'). */
1461 | attributes setattrs notype_declarator
1462 { $$ = $3; }
1463 | IDENTIFIER
1464 ;
1465
1466 struct_head:
1467 STRUCT
1468 { $$ = NULL_TREE; }
1469 | STRUCT attributes
1470 { $$ = $2; }
1471 ;
1472
1473 union_head:
1474 UNION
1475 { $$ = NULL_TREE; }
1476 | UNION attributes
1477 { $$ = $2; }
1478 ;
1479
1480 enum_head:
1481 ENUM
1482 { $$ = NULL_TREE; }
1483 | ENUM attributes
1484 { $$ = $2; }
1485 ;
1486
1487 structsp:
1488 struct_head identifier '{'
1489 { $$ = start_struct (RECORD_TYPE, $2);
1490 /* Start scope of tag before parsing components. */
1491 }
1492 component_decl_list '}' maybe_attribute
1493 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1494 | struct_head '{' component_decl_list '}' maybe_attribute
1495 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1496 $3, chainon ($1, $5));
1497 }
1498 | struct_head identifier
1499 { $$ = xref_tag (RECORD_TYPE, $2); }
1500 | union_head identifier '{'
1501 { $$ = start_struct (UNION_TYPE, $2); }
1502 component_decl_list '}' maybe_attribute
1503 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1504 | union_head '{' component_decl_list '}' maybe_attribute
1505 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1506 $3, chainon ($1, $5));
1507 }
1508 | union_head identifier
1509 { $$ = xref_tag (UNION_TYPE, $2); }
1510 | enum_head identifier '{'
1511 { $<itype>3 = suspend_momentary ();
1512 $$ = start_enum ($2); }
1513 enumlist maybecomma_warn '}' maybe_attribute
1514 { $$= finish_enum ($<ttype>4, nreverse ($5), chainon ($1, $8));
1515 resume_momentary ($<itype>3); }
1516 | enum_head '{'
1517 { $<itype>2 = suspend_momentary ();
1518 $$ = start_enum (NULL_TREE); }
1519 enumlist maybecomma_warn '}' maybe_attribute
1520 { $$= finish_enum ($<ttype>3, nreverse ($4), chainon ($1, $7));
1521 resume_momentary ($<itype>2); }
1522 | enum_head identifier
1523 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1524 ;
1525
1526 maybecomma:
1527 /* empty */
1528 | ','
1529 ;
1530
1531 maybecomma_warn:
1532 /* empty */
1533 | ','
1534 { if (pedantic && ! flag_isoc9x)
1535 pedwarn ("comma at end of enumerator list"); }
1536 ;
1537
1538 component_decl_list:
1539 component_decl_list2
1540 { $$ = $1; }
1541 | component_decl_list2 component_decl
1542 { $$ = chainon ($1, $2);
1543 pedwarn ("no semicolon at end of struct or union"); }
1544 ;
1545
1546 component_decl_list2: /* empty */
1547 { $$ = NULL_TREE; }
1548 | component_decl_list2 component_decl ';'
1549 { $$ = chainon ($1, $2); }
1550 | component_decl_list2 ';'
1551 { if (pedantic)
1552 pedwarn ("extra semicolon in struct or union specified"); }
1553 ifobjc
1554 /* foo(sizeof(struct{ @defs(ClassName)})); */
1555 | DEFS '(' CLASSNAME ')'
1556 {
1557 tree interface = lookup_interface ($3);
1558
1559 if (interface)
1560 $$ = get_class_ivars (interface);
1561 else
1562 {
1563 error ("Cannot find interface declaration for `%s'",
1564 IDENTIFIER_POINTER ($3));
1565 $$ = NULL_TREE;
1566 }
1567 }
1568 end ifobjc
1569 ;
1570
1571 /* There is a shift-reduce conflict here, because `components' may
1572 start with a `typename'. It happens that shifting (the default resolution)
1573 does the right thing, because it treats the `typename' as part of
1574 a `typed_typespecs'.
1575
1576 It is possible that this same technique would allow the distinction
1577 between `notype_initdecls' and `initdecls' to be eliminated.
1578 But I am being cautious and not trying it. */
1579
1580 component_decl:
1581 typed_typespecs setspecs components
1582 { $$ = $3;
1583 current_declspecs = TREE_VALUE (declspec_stack);
1584 prefix_attributes = TREE_PURPOSE (declspec_stack);
1585 declspec_stack = TREE_CHAIN (declspec_stack);
1586 resume_momentary ($2); }
1587 | typed_typespecs
1588 { if (pedantic)
1589 pedwarn ("ANSI C forbids member declarations with no members");
1590 shadow_tag($1);
1591 $$ = NULL_TREE; }
1592 | nonempty_type_quals setspecs components
1593 { $$ = $3;
1594 current_declspecs = TREE_VALUE (declspec_stack);
1595 prefix_attributes = TREE_PURPOSE (declspec_stack);
1596 declspec_stack = TREE_CHAIN (declspec_stack);
1597 resume_momentary ($2); }
1598 | nonempty_type_quals
1599 { if (pedantic)
1600 pedwarn ("ANSI C forbids member declarations with no members");
1601 shadow_tag($1);
1602 $$ = NULL_TREE; }
1603 | error
1604 { $$ = NULL_TREE; }
1605 | extension component_decl
1606 { $$ = $2;
1607 pedantic = $<itype>1; }
1608 ;
1609
1610 components:
1611 component_declarator
1612 | components ',' component_declarator
1613 { $$ = chainon ($1, $3); }
1614 ;
1615
1616 component_declarator:
1617 save_filename save_lineno declarator maybe_attribute
1618 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1619 decl_attributes ($$, $4, prefix_attributes); }
1620 | save_filename save_lineno
1621 declarator ':' expr_no_commas maybe_attribute
1622 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1623 decl_attributes ($$, $6, prefix_attributes); }
1624 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1625 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1626 decl_attributes ($$, $5, prefix_attributes); }
1627 ;
1628
1629 /* We chain the enumerators in reverse order.
1630 They are put in forward order where enumlist is used.
1631 (The order used to be significant, but no longer is so.
1632 However, we still maintain the order, just to be clean.) */
1633
1634 enumlist:
1635 enumerator
1636 | enumlist ',' enumerator
1637 { if ($1 == error_mark_node)
1638 $$ = $1;
1639 else
1640 $$ = chainon ($3, $1); }
1641 | error
1642 { $$ = error_mark_node; }
1643 ;
1644
1645
1646 enumerator:
1647 identifier
1648 { $$ = build_enumerator ($1, NULL_TREE); }
1649 | identifier '=' expr_no_commas
1650 { $$ = build_enumerator ($1, $3); }
1651 ;
1652
1653 typename:
1654 typed_typespecs absdcl
1655 { $$ = build_tree_list ($1, $2); }
1656 | nonempty_type_quals absdcl
1657 { $$ = build_tree_list ($1, $2); }
1658 ;
1659
1660 absdcl: /* an absolute declarator */
1661 /* empty */
1662 { $$ = NULL_TREE; }
1663 | absdcl1
1664 ;
1665
1666 nonempty_type_quals:
1667 TYPE_QUAL
1668 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1669 | nonempty_type_quals TYPE_QUAL
1670 { $$ = tree_cons (NULL_TREE, $2, $1); }
1671 ;
1672
1673 type_quals:
1674 /* empty */
1675 { $$ = NULL_TREE; }
1676 | type_quals TYPE_QUAL
1677 { $$ = tree_cons (NULL_TREE, $2, $1); }
1678 ;
1679
1680 absdcl1: /* a nonempty absolute declarator */
1681 '(' absdcl1 ')'
1682 { $$ = $2; }
1683 /* `(typedef)1' is `int'. */
1684 | '*' type_quals absdcl1 %prec UNARY
1685 { $$ = make_pointer_declarator ($2, $3); }
1686 | '*' type_quals %prec UNARY
1687 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1688 | absdcl1 '(' parmlist %prec '.'
1689 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1690 | absdcl1 '[' expr ']' %prec '.'
1691 { $$ = build_nt (ARRAY_REF, $1, $3); }
1692 | absdcl1 '[' ']' %prec '.'
1693 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1694 | '(' parmlist %prec '.'
1695 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1696 | '[' expr ']' %prec '.'
1697 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1698 | '[' ']' %prec '.'
1699 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1700 /* ??? It appears we have to support attributes here, however
1701 using prefix_attributes is wrong. */
1702 ;
1703
1704 /* at least one statement, the first of which parses without error. */
1705 /* stmts is used only after decls, so an invalid first statement
1706 is actually regarded as an invalid decl and part of the decls. */
1707
1708 stmts:
1709 lineno_stmt_or_labels
1710 {
1711 if (pedantic && $1)
1712 pedwarn ("ANSI C forbids label at end of compound statement");
1713 }
1714 ;
1715
1716 lineno_stmt_or_labels:
1717 lineno_stmt_or_label
1718 | lineno_stmt_or_labels lineno_stmt_or_label
1719 { $$ = $2; }
1720 | lineno_stmt_or_labels errstmt
1721 { $$ = 0; }
1722 ;
1723
1724 xstmts:
1725 /* empty */
1726 | stmts
1727 ;
1728
1729 errstmt: error ';'
1730 ;
1731
1732 pushlevel: /* empty */
1733 { emit_line_note (input_filename, lineno);
1734 pushlevel (0);
1735 clear_last_expr ();
1736 push_momentary ();
1737 expand_start_bindings (0);
1738 ifobjc
1739 if (objc_method_context)
1740 add_objc_decls ();
1741 end ifobjc
1742 }
1743 ;
1744
1745 /* Read zero or more forward-declarations for labels
1746 that nested functions can jump to. */
1747 maybe_label_decls:
1748 /* empty */
1749 | label_decls
1750 { if (pedantic)
1751 pedwarn ("ANSI C forbids label declarations"); }
1752 ;
1753
1754 label_decls:
1755 label_decl
1756 | label_decls label_decl
1757 ;
1758
1759 label_decl:
1760 LABEL identifiers_or_typenames ';'
1761 { tree link;
1762 for (link = $2; link; link = TREE_CHAIN (link))
1763 {
1764 tree label = shadow_label (TREE_VALUE (link));
1765 C_DECLARED_LABEL_FLAG (label) = 1;
1766 declare_nonlocal_label (label);
1767 }
1768 }
1769 ;
1770
1771 /* This is the body of a function definition.
1772 It causes syntax errors to ignore to the next openbrace. */
1773 compstmt_or_error:
1774 compstmt
1775 {}
1776 | error compstmt
1777 ;
1778
1779 compstmt_start: '{' { compstmt_count++; }
1780
1781 compstmt: compstmt_start '}'
1782 { $$ = convert (void_type_node, integer_zero_node); }
1783 | compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1784 { emit_line_note (input_filename, lineno);
1785 expand_end_bindings (getdecls (), 1, 0);
1786 $$ = poplevel (1, 1, 0);
1787 if (yychar == CONSTANT || yychar == STRING)
1788 pop_momentary_nofree ();
1789 else
1790 pop_momentary (); }
1791 | compstmt_start pushlevel maybe_label_decls error '}'
1792 { emit_line_note (input_filename, lineno);
1793 expand_end_bindings (getdecls (), kept_level_p (), 0);
1794 $$ = poplevel (kept_level_p (), 0, 0);
1795 if (yychar == CONSTANT || yychar == STRING)
1796 pop_momentary_nofree ();
1797 else
1798 pop_momentary (); }
1799 | compstmt_start pushlevel maybe_label_decls stmts '}'
1800 { emit_line_note (input_filename, lineno);
1801 expand_end_bindings (getdecls (), kept_level_p (), 0);
1802 $$ = poplevel (kept_level_p (), 0, 0);
1803 if (yychar == CONSTANT || yychar == STRING)
1804 pop_momentary_nofree ();
1805 else
1806 pop_momentary (); }
1807 ;
1808
1809 /* Value is number of statements counted as of the closeparen. */
1810 simple_if:
1811 if_prefix lineno_labeled_stmt
1812 /* Make sure c_expand_end_cond is run once
1813 for each call to c_expand_start_cond.
1814 Otherwise a crash is likely. */
1815 | if_prefix error
1816 ;
1817
1818 if_prefix:
1819 IF '(' expr ')'
1820 { emit_line_note ($<filename>-1, $<lineno>0);
1821 c_expand_start_cond (truthvalue_conversion ($3), 0,
1822 compstmt_count);
1823 $<itype>$ = stmt_count;
1824 if_stmt_file = $<filename>-1;
1825 if_stmt_line = $<lineno>0;
1826 position_after_white_space (); }
1827 ;
1828
1829 /* This is a subroutine of stmt.
1830 It is used twice, once for valid DO statements
1831 and once for catching errors in parsing the end test. */
1832 do_stmt_start:
1833 DO
1834 { stmt_count++;
1835 compstmt_count++;
1836 emit_line_note ($<filename>-1, $<lineno>0);
1837 /* See comment in `while' alternative, above. */
1838 emit_nop ();
1839 expand_start_loop_continue_elsewhere (1);
1840 position_after_white_space (); }
1841 lineno_labeled_stmt WHILE
1842 { expand_loop_continue_here (); }
1843 ;
1844
1845 save_filename:
1846 { $$ = input_filename; }
1847 ;
1848
1849 save_lineno:
1850 { $$ = lineno; }
1851 ;
1852
1853 lineno_labeled_stmt:
1854 save_filename save_lineno stmt
1855 { }
1856 /* | save_filename save_lineno error
1857 { }
1858 */
1859 | save_filename save_lineno label lineno_labeled_stmt
1860 { }
1861 ;
1862
1863 lineno_stmt_or_label:
1864 save_filename save_lineno stmt_or_label
1865 { $$ = $3; }
1866 ;
1867
1868 stmt_or_label:
1869 stmt
1870 { $$ = 0; }
1871 | label
1872 { $$ = 1; }
1873 ;
1874
1875 /* Parse a single real statement, not including any labels. */
1876 stmt:
1877 compstmt
1878 { stmt_count++; }
1879 | all_iter_stmt
1880 | expr ';'
1881 { stmt_count++;
1882 emit_line_note ($<filename>-1, $<lineno>0);
1883 /* It appears that this should not be done--that a non-lvalue array
1884 shouldn't get an error if the value isn't used.
1885 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1886 if it appears as a top-level expression,
1887 but says nothing about non-lvalue arrays. */
1888 #if 0
1889 /* Call default_conversion to get an error
1890 on referring to a register array if pedantic. */
1891 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1892 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1893 $1 = default_conversion ($1);
1894 #endif
1895 iterator_expand ($1);
1896 clear_momentary (); }
1897 | simple_if ELSE
1898 { c_expand_start_else ();
1899 $<itype>1 = stmt_count;
1900 position_after_white_space (); }
1901 lineno_labeled_stmt
1902 { c_expand_end_cond ();
1903 if (extra_warnings && stmt_count == $<itype>1)
1904 warning ("empty body in an else-statement"); }
1905 | simple_if %prec IF
1906 { c_expand_end_cond ();
1907 /* This warning is here instead of in simple_if, because we
1908 do not want a warning if an empty if is followed by an
1909 else statement. Increment stmt_count so we don't
1910 give a second error if this is a nested `if'. */
1911 if (extra_warnings && stmt_count++ == $<itype>1)
1912 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1913 "empty body in an if-statement"); }
1914 /* Make sure c_expand_end_cond is run once
1915 for each call to c_expand_start_cond.
1916 Otherwise a crash is likely. */
1917 | simple_if ELSE error
1918 { c_expand_end_cond (); }
1919 | WHILE
1920 { stmt_count++;
1921 emit_line_note ($<filename>-1, $<lineno>0);
1922 /* The emit_nop used to come before emit_line_note,
1923 but that made the nop seem like part of the preceding line.
1924 And that was confusing when the preceding line was
1925 inside of an if statement and was not really executed.
1926 I think it ought to work to put the nop after the line number.
1927 We will see. --rms, July 15, 1991. */
1928 emit_nop (); }
1929 '(' expr ')'
1930 { /* Don't start the loop till we have succeeded
1931 in parsing the end test. This is to make sure
1932 that we end every loop we start. */
1933 expand_start_loop (1);
1934 emit_line_note (input_filename, lineno);
1935 expand_exit_loop_if_false (NULL_PTR,
1936 truthvalue_conversion ($4));
1937 position_after_white_space (); }
1938 lineno_labeled_stmt
1939 { expand_end_loop (); }
1940 | do_stmt_start
1941 '(' expr ')' ';'
1942 { emit_line_note (input_filename, lineno);
1943 expand_exit_loop_if_false (NULL_PTR,
1944 truthvalue_conversion ($3));
1945 expand_end_loop ();
1946 clear_momentary (); }
1947 /* This rule is needed to make sure we end every loop we start. */
1948 | do_stmt_start error
1949 { expand_end_loop ();
1950 clear_momentary (); }
1951 | FOR
1952 '(' xexpr ';'
1953 { stmt_count++;
1954 emit_line_note ($<filename>-1, $<lineno>0);
1955 /* See comment in `while' alternative, above. */
1956 emit_nop ();
1957 if ($3) c_expand_expr_stmt ($3);
1958 /* Next step is to call expand_start_loop_continue_elsewhere,
1959 but wait till after we parse the entire for (...).
1960 Otherwise, invalid input might cause us to call that
1961 fn without calling expand_end_loop. */
1962 }
1963 xexpr ';'
1964 /* Can't emit now; wait till after expand_start_loop... */
1965 { $<lineno>7 = lineno;
1966 $<filename>$ = input_filename; }
1967 xexpr ')'
1968 {
1969 /* Start the loop. Doing this after parsing
1970 all the expressions ensures we will end the loop. */
1971 expand_start_loop_continue_elsewhere (1);
1972 /* Emit the end-test, with a line number. */
1973 emit_line_note ($<filename>8, $<lineno>7);
1974 if ($6)
1975 expand_exit_loop_if_false (NULL_PTR,
1976 truthvalue_conversion ($6));
1977 /* Don't let the tree nodes for $9 be discarded by
1978 clear_momentary during the parsing of the next stmt. */
1979 push_momentary ();
1980 $<lineno>7 = lineno;
1981 $<filename>8 = input_filename;
1982 position_after_white_space (); }
1983 lineno_labeled_stmt
1984 { /* Emit the increment expression, with a line number. */
1985 emit_line_note ($<filename>8, $<lineno>7);
1986 expand_loop_continue_here ();
1987 if ($9)
1988 c_expand_expr_stmt ($9);
1989 if (yychar == CONSTANT || yychar == STRING)
1990 pop_momentary_nofree ();
1991 else
1992 pop_momentary ();
1993 expand_end_loop (); }
1994 | SWITCH '(' expr ')'
1995 { stmt_count++;
1996 emit_line_note ($<filename>-1, $<lineno>0);
1997 c_expand_start_case ($3);
1998 /* Don't let the tree nodes for $3 be discarded by
1999 clear_momentary during the parsing of the next stmt. */
2000 push_momentary ();
2001 position_after_white_space (); }
2002 lineno_labeled_stmt
2003 { expand_end_case ($3);
2004 if (yychar == CONSTANT || yychar == STRING)
2005 pop_momentary_nofree ();
2006 else
2007 pop_momentary (); }
2008 | BREAK ';'
2009 { stmt_count++;
2010 emit_line_note ($<filename>-1, $<lineno>0);
2011 if ( ! expand_exit_something ())
2012 error ("break statement not within loop or switch"); }
2013 | CONTINUE ';'
2014 { stmt_count++;
2015 emit_line_note ($<filename>-1, $<lineno>0);
2016 if (! expand_continue_loop (NULL_PTR))
2017 error ("continue statement not within a loop"); }
2018 | RETURN ';'
2019 { stmt_count++;
2020 emit_line_note ($<filename>-1, $<lineno>0);
2021 c_expand_return (NULL_TREE); }
2022 | RETURN expr ';'
2023 { stmt_count++;
2024 emit_line_note ($<filename>-1, $<lineno>0);
2025 c_expand_return ($2); }
2026 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2027 { stmt_count++;
2028 emit_line_note ($<filename>-1, $<lineno>0);
2029 STRIP_NOPS ($4);
2030 if ((TREE_CODE ($4) == ADDR_EXPR
2031 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
2032 || TREE_CODE ($4) == STRING_CST)
2033 expand_asm ($4);
2034 else
2035 error ("argument of `asm' is not a constant string"); }
2036 /* This is the case with just output operands. */
2037 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2038 { stmt_count++;
2039 emit_line_note ($<filename>-1, $<lineno>0);
2040 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2041 $2 == ridpointers[(int)RID_VOLATILE],
2042 input_filename, lineno); }
2043 /* This is the case with input operands as well. */
2044 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2045 { stmt_count++;
2046 emit_line_note ($<filename>-1, $<lineno>0);
2047 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2048 $2 == ridpointers[(int)RID_VOLATILE],
2049 input_filename, lineno); }
2050 /* This is the case with clobbered registers as well. */
2051 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2052 asm_operands ':' asm_clobbers ')' ';'
2053 { stmt_count++;
2054 emit_line_note ($<filename>-1, $<lineno>0);
2055 c_expand_asm_operands ($4, $6, $8, $10,
2056 $2 == ridpointers[(int)RID_VOLATILE],
2057 input_filename, lineno); }
2058 | GOTO identifier ';'
2059 { tree decl;
2060 stmt_count++;
2061 emit_line_note ($<filename>-1, $<lineno>0);
2062 decl = lookup_label ($2);
2063 if (decl != 0)
2064 {
2065 TREE_USED (decl) = 1;
2066 expand_goto (decl);
2067 }
2068 }
2069 | GOTO '*' expr ';'
2070 { if (pedantic)
2071 pedwarn ("ANSI C forbids `goto *expr;'");
2072 stmt_count++;
2073 emit_line_note ($<filename>-1, $<lineno>0);
2074 expand_computed_goto (convert (ptr_type_node, $3)); }
2075 | ';'
2076 ;
2077
2078 all_iter_stmt:
2079 all_iter_stmt_simple
2080 /* | all_iter_stmt_with_decl */
2081 ;
2082
2083 all_iter_stmt_simple:
2084 FOR '(' primary ')'
2085 {
2086 /* The value returned by this action is */
2087 /* 1 if everything is OK */
2088 /* 0 in case of error or already bound iterator */
2089
2090 $<itype>$ = 0;
2091 if (TREE_CODE ($3) != VAR_DECL)
2092 error ("invalid `for (ITERATOR)' syntax");
2093 else if (! ITERATOR_P ($3))
2094 error ("`%s' is not an iterator",
2095 IDENTIFIER_POINTER (DECL_NAME ($3)));
2096 else if (ITERATOR_BOUND_P ($3))
2097 error ("`for (%s)' inside expansion of same iterator",
2098 IDENTIFIER_POINTER (DECL_NAME ($3)));
2099 else
2100 {
2101 $<itype>$ = 1;
2102 iterator_for_loop_start ($3);
2103 }
2104 }
2105 lineno_labeled_stmt
2106 {
2107 if ($<itype>5)
2108 iterator_for_loop_end ($3);
2109 }
2110
2111 /* This really should allow any kind of declaration,
2112 for generality. Fix it before turning it back on.
2113
2114 all_iter_stmt_with_decl:
2115 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2116 {
2117 */ /* The value returned by this action is */
2118 /* 1 if everything is OK */
2119 /* 0 in case of error or already bound iterator */
2120 /*
2121 iterator_for_loop_start ($6);
2122 }
2123 lineno_labeled_stmt
2124 {
2125 iterator_for_loop_end ($6);
2126 emit_line_note (input_filename, lineno);
2127 expand_end_bindings (getdecls (), 1, 0);
2128 $<ttype>$ = poplevel (1, 1, 0);
2129 if (yychar == CONSTANT || yychar == STRING)
2130 pop_momentary_nofree ();
2131 else
2132 pop_momentary ();
2133 }
2134 */
2135
2136 /* Any kind of label, including jump labels and case labels.
2137 ANSI C accepts labels only before statements, but we allow them
2138 also at the end of a compound statement. */
2139
2140 label: CASE expr_no_commas ':'
2141 { register tree value = check_case_value ($2);
2142 register tree label
2143 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2144
2145 stmt_count++;
2146
2147 if (value != error_mark_node)
2148 {
2149 tree duplicate;
2150 int success;
2151
2152 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2153 pedwarn ("label must have integral type in ANSI C");
2154
2155 success = pushcase (value, convert_and_check,
2156 label, &duplicate);
2157
2158 if (success == 1)
2159 error ("case label not within a switch statement");
2160 else if (success == 2)
2161 {
2162 error ("duplicate case value");
2163 error_with_decl (duplicate, "this is the first entry for that value");
2164 }
2165 else if (success == 3)
2166 warning ("case value out of range");
2167 else if (success == 5)
2168 error ("case label within scope of cleanup or variable array");
2169 }
2170 position_after_white_space (); }
2171 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2172 { register tree value1 = check_case_value ($2);
2173 register tree value2 = check_case_value ($4);
2174 register tree label
2175 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2176
2177 if (pedantic)
2178 pedwarn ("ANSI C forbids case ranges");
2179 stmt_count++;
2180
2181 if (value1 != error_mark_node && value2 != error_mark_node)
2182 {
2183 tree duplicate;
2184 int success = pushcase_range (value1, value2,
2185 convert_and_check, label,
2186 &duplicate);
2187 if (success == 1)
2188 error ("case label not within a switch statement");
2189 else if (success == 2)
2190 {
2191 error ("duplicate case value");
2192 error_with_decl (duplicate, "this is the first entry for that value");
2193 }
2194 else if (success == 3)
2195 warning ("case value out of range");
2196 else if (success == 4)
2197 warning ("empty case range");
2198 else if (success == 5)
2199 error ("case label within scope of cleanup or variable array");
2200 }
2201 position_after_white_space (); }
2202 | DEFAULT ':'
2203 {
2204 tree duplicate;
2205 register tree label
2206 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2207 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2208 stmt_count++;
2209 if (success == 1)
2210 error ("default label not within a switch statement");
2211 else if (success == 2)
2212 {
2213 error ("multiple default labels in one switch");
2214 error_with_decl (duplicate, "this is the first default label");
2215 }
2216 position_after_white_space (); }
2217 | identifier ':' maybe_attribute
2218 { tree label = define_label (input_filename, lineno, $1);
2219 stmt_count++;
2220 emit_nop ();
2221 if (label)
2222 {
2223 expand_label (label);
2224 decl_attributes (label, $3, NULL_TREE);
2225 }
2226 position_after_white_space (); }
2227 ;
2228
2229 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2230
2231 maybe_type_qual:
2232 /* empty */
2233 { emit_line_note (input_filename, lineno);
2234 $$ = NULL_TREE; }
2235 | TYPE_QUAL
2236 { emit_line_note (input_filename, lineno); }
2237 ;
2238
2239 xexpr:
2240 /* empty */
2241 { $$ = NULL_TREE; }
2242 | expr
2243 ;
2244
2245 /* These are the operands other than the first string and colon
2246 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2247 asm_operands: /* empty */
2248 { $$ = NULL_TREE; }
2249 | nonnull_asm_operands
2250 ;
2251
2252 nonnull_asm_operands:
2253 asm_operand
2254 | nonnull_asm_operands ',' asm_operand
2255 { $$ = chainon ($1, $3); }
2256 ;
2257
2258 asm_operand:
2259 STRING '(' expr ')'
2260 { $$ = build_tree_list ($1, $3); }
2261 ;
2262
2263 asm_clobbers:
2264 string
2265 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2266 | asm_clobbers ',' string
2267 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2268 ;
2269 \f
2270 /* This is what appears inside the parens in a function declarator.
2271 Its value is a list of ..._TYPE nodes. */
2272 parmlist:
2273 { pushlevel (0);
2274 clear_parm_order ();
2275 declare_parm_level (0); }
2276 parmlist_1
2277 { $$ = $2;
2278 parmlist_tags_warning ();
2279 poplevel (0, 0, 0); }
2280 ;
2281
2282 parmlist_1:
2283 parmlist_2 ')'
2284 | parms ';'
2285 { tree parm;
2286 if (pedantic)
2287 pedwarn ("ANSI C forbids forward parameter declarations");
2288 /* Mark the forward decls as such. */
2289 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2290 TREE_ASM_WRITTEN (parm) = 1;
2291 clear_parm_order (); }
2292 parmlist_1
2293 { $$ = $4; }
2294 | error ')'
2295 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2296 ;
2297
2298 /* This is what appears inside the parens in a function declarator.
2299 Is value is represented in the format that grokdeclarator expects. */
2300 parmlist_2: /* empty */
2301 { $$ = get_parm_info (0); }
2302 | ELLIPSIS
2303 { $$ = get_parm_info (0);
2304 /* Gcc used to allow this as an extension. However, it does
2305 not work for all targets, and thus has been disabled.
2306 Also, since func (...) and func () are indistinguishable,
2307 it caused problems with the code in expand_builtin which
2308 tries to verify that BUILT_IN_NEXT_ARG is being used
2309 correctly. */
2310 error ("ANSI C requires a named argument before `...'");
2311 }
2312 | parms
2313 { $$ = get_parm_info (1); }
2314 | parms ',' ELLIPSIS
2315 { $$ = get_parm_info (0); }
2316 ;
2317
2318 parms:
2319 parm
2320 { push_parm_decl ($1); }
2321 | parms ',' parm
2322 { push_parm_decl ($3); }
2323 ;
2324
2325 /* A single parameter declaration or parameter type name,
2326 as found in a parmlist. */
2327 parm:
2328 typed_declspecs setspecs parm_declarator maybe_attribute
2329 { $$ = build_tree_list (build_tree_list (current_declspecs,
2330 $3),
2331 build_tree_list (prefix_attributes,
2332 $4));
2333 current_declspecs = TREE_VALUE (declspec_stack);
2334 prefix_attributes = TREE_PURPOSE (declspec_stack);
2335 declspec_stack = TREE_CHAIN (declspec_stack);
2336 resume_momentary ($2); }
2337 | typed_declspecs setspecs notype_declarator maybe_attribute
2338 { $$ = build_tree_list (build_tree_list (current_declspecs,
2339 $3),
2340 build_tree_list (prefix_attributes,
2341 $4));
2342 current_declspecs = TREE_VALUE (declspec_stack);
2343 prefix_attributes = TREE_PURPOSE (declspec_stack);
2344 declspec_stack = TREE_CHAIN (declspec_stack);
2345 resume_momentary ($2); }
2346 | typed_declspecs setspecs absdcl maybe_attribute
2347 { $$ = build_tree_list (build_tree_list (current_declspecs,
2348 $3),
2349 build_tree_list (prefix_attributes,
2350 $4));
2351 current_declspecs = TREE_VALUE (declspec_stack);
2352 prefix_attributes = TREE_PURPOSE (declspec_stack);
2353 declspec_stack = TREE_CHAIN (declspec_stack);
2354 resume_momentary ($2); }
2355 | declmods setspecs notype_declarator maybe_attribute
2356 { $$ = build_tree_list (build_tree_list (current_declspecs,
2357 $3),
2358 build_tree_list (prefix_attributes,
2359 $4));
2360 current_declspecs = TREE_VALUE (declspec_stack);
2361 prefix_attributes = TREE_PURPOSE (declspec_stack);
2362 declspec_stack = TREE_CHAIN (declspec_stack);
2363 resume_momentary ($2); }
2364
2365 | declmods setspecs absdcl maybe_attribute
2366 { $$ = build_tree_list (build_tree_list (current_declspecs,
2367 $3),
2368 build_tree_list (prefix_attributes,
2369 $4));
2370 current_declspecs = TREE_VALUE (declspec_stack);
2371 prefix_attributes = TREE_PURPOSE (declspec_stack);
2372 declspec_stack = TREE_CHAIN (declspec_stack);
2373 resume_momentary ($2); }
2374 ;
2375
2376 /* This is used in a function definition
2377 where either a parmlist or an identifier list is ok.
2378 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2379 parmlist_or_identifiers:
2380 { pushlevel (0);
2381 clear_parm_order ();
2382 declare_parm_level (1); }
2383 parmlist_or_identifiers_1
2384 { $$ = $2;
2385 parmlist_tags_warning ();
2386 poplevel (0, 0, 0); }
2387 ;
2388
2389 parmlist_or_identifiers_1:
2390 parmlist_1
2391 | identifiers ')'
2392 { tree t;
2393 for (t = $1; t; t = TREE_CHAIN (t))
2394 if (TREE_VALUE (t) == NULL_TREE)
2395 error ("`...' in old-style identifier list");
2396 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2397 ;
2398
2399 /* A nonempty list of identifiers. */
2400 identifiers:
2401 IDENTIFIER
2402 { $$ = build_tree_list (NULL_TREE, $1); }
2403 | identifiers ',' IDENTIFIER
2404 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2405 ;
2406
2407 /* A nonempty list of identifiers, including typenames. */
2408 identifiers_or_typenames:
2409 identifier
2410 { $$ = build_tree_list (NULL_TREE, $1); }
2411 | identifiers_or_typenames ',' identifier
2412 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2413 ;
2414
2415 extension:
2416 EXTENSION
2417 { $<itype>$ = pedantic;
2418 pedantic = 0; }
2419 ;
2420 \f
2421 ifobjc
2422 /* Objective-C productions. */
2423
2424 objcdef:
2425 classdef
2426 | classdecl
2427 | aliasdecl
2428 | protocoldef
2429 | methoddef
2430 | END
2431 {
2432 if (objc_implementation_context)
2433 {
2434 finish_class (objc_implementation_context);
2435 objc_ivar_chain = NULL_TREE;
2436 objc_implementation_context = NULL_TREE;
2437 }
2438 else
2439 warning ("`@end' must appear in an implementation context");
2440 }
2441 ;
2442
2443 /* A nonempty list of identifiers. */
2444 identifier_list:
2445 identifier
2446 { $$ = build_tree_list (NULL_TREE, $1); }
2447 | identifier_list ',' identifier
2448 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2449 ;
2450
2451 classdecl:
2452 CLASS identifier_list ';'
2453 {
2454 objc_declare_class ($2);
2455 }
2456
2457 aliasdecl:
2458 ALIAS identifier identifier ';'
2459 {
2460 objc_declare_alias ($2, $3);
2461 }
2462
2463 classdef:
2464 INTERFACE identifier protocolrefs '{'
2465 {
2466 objc_interface_context = objc_ivar_context
2467 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2468 objc_public_flag = 0;
2469 }
2470 ivar_decl_list '}'
2471 {
2472 continue_class (objc_interface_context);
2473 }
2474 methodprotolist
2475 END
2476 {
2477 finish_class (objc_interface_context);
2478 objc_interface_context = NULL_TREE;
2479 }
2480
2481 | INTERFACE identifier protocolrefs
2482 {
2483 objc_interface_context
2484 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2485 continue_class (objc_interface_context);
2486 }
2487 methodprotolist
2488 END
2489 {
2490 finish_class (objc_interface_context);
2491 objc_interface_context = NULL_TREE;
2492 }
2493
2494 | INTERFACE identifier ':' identifier protocolrefs '{'
2495 {
2496 objc_interface_context = objc_ivar_context
2497 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2498 objc_public_flag = 0;
2499 }
2500 ivar_decl_list '}'
2501 {
2502 continue_class (objc_interface_context);
2503 }
2504 methodprotolist
2505 END
2506 {
2507 finish_class (objc_interface_context);
2508 objc_interface_context = NULL_TREE;
2509 }
2510
2511 | INTERFACE identifier ':' identifier protocolrefs
2512 {
2513 objc_interface_context
2514 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2515 continue_class (objc_interface_context);
2516 }
2517 methodprotolist
2518 END
2519 {
2520 finish_class (objc_interface_context);
2521 objc_interface_context = NULL_TREE;
2522 }
2523
2524 | IMPLEMENTATION identifier '{'
2525 {
2526 objc_implementation_context = objc_ivar_context
2527 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2528 objc_public_flag = 0;
2529 }
2530 ivar_decl_list '}'
2531 {
2532 objc_ivar_chain
2533 = continue_class (objc_implementation_context);
2534 }
2535
2536 | IMPLEMENTATION identifier
2537 {
2538 objc_implementation_context
2539 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2540 objc_ivar_chain
2541 = continue_class (objc_implementation_context);
2542 }
2543
2544 | IMPLEMENTATION identifier ':' identifier '{'
2545 {
2546 objc_implementation_context = objc_ivar_context
2547 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2548 objc_public_flag = 0;
2549 }
2550 ivar_decl_list '}'
2551 {
2552 objc_ivar_chain
2553 = continue_class (objc_implementation_context);
2554 }
2555
2556 | IMPLEMENTATION identifier ':' identifier
2557 {
2558 objc_implementation_context
2559 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2560 objc_ivar_chain
2561 = continue_class (objc_implementation_context);
2562 }
2563
2564 | INTERFACE identifier '(' identifier ')' protocolrefs
2565 {
2566 objc_interface_context
2567 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2568 continue_class (objc_interface_context);
2569 }
2570 methodprotolist
2571 END
2572 {
2573 finish_class (objc_interface_context);
2574 objc_interface_context = NULL_TREE;
2575 }
2576
2577 | IMPLEMENTATION identifier '(' identifier ')'
2578 {
2579 objc_implementation_context
2580 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2581 objc_ivar_chain
2582 = continue_class (objc_implementation_context);
2583 }
2584 ;
2585
2586 protocoldef:
2587 PROTOCOL identifier protocolrefs
2588 {
2589 remember_protocol_qualifiers ();
2590 objc_interface_context
2591 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2592 }
2593 methodprotolist END
2594 {
2595 forget_protocol_qualifiers();
2596 finish_protocol(objc_interface_context);
2597 objc_interface_context = NULL_TREE;
2598 }
2599 ;
2600
2601 protocolrefs:
2602 /* empty */
2603 {
2604 $$ = NULL_TREE;
2605 }
2606 | non_empty_protocolrefs
2607 ;
2608
2609 non_empty_protocolrefs:
2610 ARITHCOMPARE identifier_list ARITHCOMPARE
2611 {
2612 if ($1 == LT_EXPR && $3 == GT_EXPR)
2613 $$ = $2;
2614 else
2615 YYERROR1;
2616 }
2617 ;
2618
2619 ivar_decl_list:
2620 ivar_decl_list visibility_spec ivar_decls
2621 | ivar_decls
2622 ;
2623
2624 visibility_spec:
2625 PRIVATE { objc_public_flag = 2; }
2626 | PROTECTED { objc_public_flag = 0; }
2627 | PUBLIC { objc_public_flag = 1; }
2628 ;
2629
2630 ivar_decls:
2631 /* empty */
2632 {
2633 $$ = NULL_TREE;
2634 }
2635 | ivar_decls ivar_decl ';'
2636 | ivar_decls ';'
2637 {
2638 if (pedantic)
2639 pedwarn ("extra semicolon in struct or union specified");
2640 }
2641 ;
2642
2643
2644 /* There is a shift-reduce conflict here, because `components' may
2645 start with a `typename'. It happens that shifting (the default resolution)
2646 does the right thing, because it treats the `typename' as part of
2647 a `typed_typespecs'.
2648
2649 It is possible that this same technique would allow the distinction
2650 between `notype_initdecls' and `initdecls' to be eliminated.
2651 But I am being cautious and not trying it. */
2652
2653 ivar_decl:
2654 typed_typespecs setspecs ivars
2655 { $$ = $3;
2656 current_declspecs = TREE_VALUE (declspec_stack);
2657 prefix_attributes = TREE_PURPOSE (declspec_stack);
2658 declspec_stack = TREE_CHAIN (declspec_stack);
2659 resume_momentary ($2); }
2660 | nonempty_type_quals setspecs ivars
2661 { $$ = $3;
2662 current_declspecs = TREE_VALUE (declspec_stack);
2663 prefix_attributes = TREE_PURPOSE (declspec_stack);
2664 declspec_stack = TREE_CHAIN (declspec_stack);
2665 resume_momentary ($2); }
2666 | error
2667 { $$ = NULL_TREE; }
2668 ;
2669
2670 ivars:
2671 /* empty */
2672 { $$ = NULL_TREE; }
2673 | ivar_declarator
2674 | ivars ',' ivar_declarator
2675 ;
2676
2677 ivar_declarator:
2678 declarator
2679 {
2680 $$ = add_instance_variable (objc_ivar_context,
2681 objc_public_flag,
2682 $1, current_declspecs,
2683 NULL_TREE);
2684 }
2685 | declarator ':' expr_no_commas
2686 {
2687 $$ = add_instance_variable (objc_ivar_context,
2688 objc_public_flag,
2689 $1, current_declspecs, $3);
2690 }
2691 | ':' expr_no_commas
2692 {
2693 $$ = add_instance_variable (objc_ivar_context,
2694 objc_public_flag,
2695 NULL_TREE,
2696 current_declspecs, $2);
2697 }
2698 ;
2699
2700 methoddef:
2701 '+'
2702 {
2703 remember_protocol_qualifiers ();
2704 if (objc_implementation_context)
2705 objc_inherit_code = CLASS_METHOD_DECL;
2706 else
2707 fatal ("method definition not in class context");
2708 }
2709 methoddecl
2710 {
2711 forget_protocol_qualifiers ();
2712 add_class_method (objc_implementation_context, $3);
2713 start_method_def ($3);
2714 objc_method_context = $3;
2715 }
2716 optarglist
2717 {
2718 continue_method_def ();
2719 }
2720 compstmt_or_error
2721 {
2722 finish_method_def ();
2723 objc_method_context = NULL_TREE;
2724 }
2725
2726 | '-'
2727 {
2728 remember_protocol_qualifiers ();
2729 if (objc_implementation_context)
2730 objc_inherit_code = INSTANCE_METHOD_DECL;
2731 else
2732 fatal ("method definition not in class context");
2733 }
2734 methoddecl
2735 {
2736 forget_protocol_qualifiers ();
2737 add_instance_method (objc_implementation_context, $3);
2738 start_method_def ($3);
2739 objc_method_context = $3;
2740 }
2741 optarglist
2742 {
2743 continue_method_def ();
2744 }
2745 compstmt_or_error
2746 {
2747 finish_method_def ();
2748 objc_method_context = NULL_TREE;
2749 }
2750 ;
2751
2752 /* the reason for the strange actions in this rule
2753 is so that notype_initdecls when reached via datadef
2754 can find a valid list of type and sc specs in $0. */
2755
2756 methodprotolist:
2757 /* empty */
2758 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2759 ;
2760
2761 methodprotolist2: /* eliminates a shift/reduce conflict */
2762 methodproto
2763 | datadef
2764 | methodprotolist2 methodproto
2765 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2766 ;
2767
2768 semi_or_error:
2769 ';'
2770 | error
2771 ;
2772
2773 methodproto:
2774 '+'
2775 {
2776 /* Remember protocol qualifiers in prototypes. */
2777 remember_protocol_qualifiers ();
2778 objc_inherit_code = CLASS_METHOD_DECL;
2779 }
2780 methoddecl
2781 {
2782 /* Forget protocol qualifiers here. */
2783 forget_protocol_qualifiers ();
2784 add_class_method (objc_interface_context, $3);
2785 }
2786 semi_or_error
2787
2788 | '-'
2789 {
2790 /* Remember protocol qualifiers in prototypes. */
2791 remember_protocol_qualifiers ();
2792 objc_inherit_code = INSTANCE_METHOD_DECL;
2793 }
2794 methoddecl
2795 {
2796 /* Forget protocol qualifiers here. */
2797 forget_protocol_qualifiers ();
2798 add_instance_method (objc_interface_context, $3);
2799 }
2800 semi_or_error
2801 ;
2802
2803 methoddecl:
2804 '(' typename ')' unaryselector
2805 {
2806 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2807 }
2808
2809 | unaryselector
2810 {
2811 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2812 }
2813
2814 | '(' typename ')' keywordselector optparmlist
2815 {
2816 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2817 }
2818
2819 | keywordselector optparmlist
2820 {
2821 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2822 }
2823 ;
2824
2825 /* "optarglist" assumes that start_method_def has already been called...
2826 if it is not, the "xdecls" will not be placed in the proper scope */
2827
2828 optarglist:
2829 /* empty */
2830 | ';' myxdecls
2831 ;
2832
2833 /* to get around the following situation: "int foo (int a) int b; {}" that
2834 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2835
2836 myxdecls:
2837 /* empty */
2838 | mydecls
2839 ;
2840
2841 mydecls:
2842 mydecl
2843 | errstmt
2844 | mydecls mydecl
2845 | mydecl errstmt
2846 ;
2847
2848 mydecl:
2849 typed_declspecs setspecs myparms ';'
2850 { current_declspecs = TREE_VALUE (declspec_stack);
2851 prefix_attributes = TREE_PURPOSE (declspec_stack);
2852 declspec_stack = TREE_CHAIN (declspec_stack);
2853 resume_momentary ($2); }
2854 | typed_declspecs ';'
2855 { shadow_tag ($1); }
2856 | declmods ';'
2857 { pedwarn ("empty declaration"); }
2858 ;
2859
2860 myparms:
2861 myparm
2862 { push_parm_decl ($1); }
2863 | myparms ',' myparm
2864 { push_parm_decl ($3); }
2865 ;
2866
2867 /* A single parameter declaration or parameter type name,
2868 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2869
2870 myparm:
2871 parm_declarator maybe_attribute
2872 { $$ = build_tree_list (build_tree_list (current_declspecs,
2873 $1),
2874 build_tree_list (prefix_attributes,
2875 $2)); }
2876 | notype_declarator maybe_attribute
2877 { $$ = build_tree_list (build_tree_list (current_declspecs,
2878 $1),
2879 build_tree_list (prefix_attributes,
2880 $2)); }
2881 | absdcl maybe_attribute
2882 { $$ = build_tree_list (build_tree_list (current_declspecs,
2883 $1),
2884 build_tree_list (prefix_attributes,
2885 $2)); }
2886 ;
2887
2888 optparmlist:
2889 /* empty */
2890 {
2891 $$ = NULL_TREE;
2892 }
2893 | ',' ELLIPSIS
2894 {
2895 /* oh what a kludge! */
2896 $$ = (tree)1;
2897 }
2898 | ','
2899 {
2900 pushlevel (0);
2901 }
2902 parmlist_2
2903 {
2904 /* returns a tree list node generated by get_parm_info */
2905 $$ = $3;
2906 poplevel (0, 0, 0);
2907 }
2908 ;
2909
2910 unaryselector:
2911 selector
2912 ;
2913
2914 keywordselector:
2915 keyworddecl
2916
2917 | keywordselector keyworddecl
2918 {
2919 $$ = chainon ($1, $2);
2920 }
2921 ;
2922
2923 selector:
2924 IDENTIFIER
2925 | TYPENAME
2926 | OBJECTNAME
2927 | reservedwords
2928 ;
2929
2930 reservedwords:
2931 ENUM { $$ = get_identifier (token_buffer); }
2932 | STRUCT { $$ = get_identifier (token_buffer); }
2933 | UNION { $$ = get_identifier (token_buffer); }
2934 | IF { $$ = get_identifier (token_buffer); }
2935 | ELSE { $$ = get_identifier (token_buffer); }
2936 | WHILE { $$ = get_identifier (token_buffer); }
2937 | DO { $$ = get_identifier (token_buffer); }
2938 | FOR { $$ = get_identifier (token_buffer); }
2939 | SWITCH { $$ = get_identifier (token_buffer); }
2940 | CASE { $$ = get_identifier (token_buffer); }
2941 | DEFAULT { $$ = get_identifier (token_buffer); }
2942 | BREAK { $$ = get_identifier (token_buffer); }
2943 | CONTINUE { $$ = get_identifier (token_buffer); }
2944 | RETURN { $$ = get_identifier (token_buffer); }
2945 | GOTO { $$ = get_identifier (token_buffer); }
2946 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2947 | SIZEOF { $$ = get_identifier (token_buffer); }
2948 | TYPEOF { $$ = get_identifier (token_buffer); }
2949 | ALIGNOF { $$ = get_identifier (token_buffer); }
2950 | TYPESPEC | TYPE_QUAL
2951 ;
2952
2953 keyworddecl:
2954 selector ':' '(' typename ')' identifier
2955 {
2956 $$ = build_keyword_decl ($1, $4, $6);
2957 }
2958
2959 | selector ':' identifier
2960 {
2961 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2962 }
2963
2964 | ':' '(' typename ')' identifier
2965 {
2966 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2967 }
2968
2969 | ':' identifier
2970 {
2971 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2972 }
2973 ;
2974
2975 messageargs:
2976 selector
2977 | keywordarglist
2978 ;
2979
2980 keywordarglist:
2981 keywordarg
2982 | keywordarglist keywordarg
2983 {
2984 $$ = chainon ($1, $2);
2985 }
2986 ;
2987
2988
2989 keywordexpr:
2990 nonnull_exprlist
2991 {
2992 if (TREE_CHAIN ($1) == NULL_TREE)
2993 /* just return the expr., remove a level of indirection */
2994 $$ = TREE_VALUE ($1);
2995 else
2996 /* we have a comma expr., we will collapse later */
2997 $$ = $1;
2998 }
2999 ;
3000
3001 keywordarg:
3002 selector ':' keywordexpr
3003 {
3004 $$ = build_tree_list ($1, $3);
3005 }
3006 | ':' keywordexpr
3007 {
3008 $$ = build_tree_list (NULL_TREE, $2);
3009 }
3010 ;
3011
3012 receiver:
3013 expr
3014 | CLASSNAME
3015 {
3016 $$ = get_class_reference ($1);
3017 }
3018 ;
3019
3020 objcmessageexpr:
3021 '['
3022 { objc_receiver_context = 1; }
3023 receiver
3024 { objc_receiver_context = 0; }
3025 messageargs ']'
3026 {
3027 $$ = build_tree_list ($3, $5);
3028 }
3029 ;
3030
3031 selectorarg:
3032 selector
3033 | keywordnamelist
3034 ;
3035
3036 keywordnamelist:
3037 keywordname
3038 | keywordnamelist keywordname
3039 {
3040 $$ = chainon ($1, $2);
3041 }
3042 ;
3043
3044 keywordname:
3045 selector ':'
3046 {
3047 $$ = build_tree_list ($1, NULL_TREE);
3048 }
3049 | ':'
3050 {
3051 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3052 }
3053 ;
3054
3055 objcselectorexpr:
3056 SELECTOR '(' selectorarg ')'
3057 {
3058 $$ = $3;
3059 }
3060 ;
3061
3062 objcprotocolexpr:
3063 PROTOCOL '(' identifier ')'
3064 {
3065 $$ = $3;
3066 }
3067 ;
3068
3069 /* extension to support C-structures in the archiver */
3070
3071 objcencodeexpr:
3072 ENCODE '(' typename ')'
3073 {
3074 $$ = groktypename ($3);
3075 }
3076 ;
3077
3078 end ifobjc
3079 %%