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