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