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