1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This file defines the grammar of C and that of Objective C.
21 ifobjc ... end ifobjc conditionals contain code for Objective C only.
22 ifc ... end ifc conditionals contain code for C only.
23 Sed commands in Makefile.in are used to convert this file into
24 c-parse.y and into objc-parse.y. */
26 /* To whomever it may concern: I have heard that such a thing was once
27 written by AT&T, but I have never seen it. */
35 /* These are the 10 conflicts you should get in parse.output;
36 the state numbers may vary if minor changes in the grammar are made.
38 State 41 contains 1 shift/reduce conflict. (Two ways to recover from error.)
39 State 97 contains 1 shift/reduce conflict. (Two ways to recover from error.)
40 State 104 contains 1 shift/reduce conflict. (Two ways to recover from error.)
41 State 108 contains 1 shift/reduce conflict. (Two ways to recover from error.)
42 State 124 contains 1 shift/reduce conflict. (See comment at component_decl.)
43 State 191 contains 1 shift/reduce conflict. (Two ways to recover from error.)
44 State 204 contains 1 shift/reduce conflict. (Two ways to recover from error.)
45 State 210 contains 1 shift/reduce conflict. (Two ways to recover from error.)
46 State 449 contains 2 shift/reduce conflicts. (Four ways to parse this.)
62 #ifdef MULTIBYTE_CHARS
71 /* Since parsers are distinct for each language, put the language string
74 char *language_string = "GNU Obj-C";
77 char *language_string = "GNU C";
86 /* Like YYERROR but do call yyerror. */
87 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
89 /* Cause the `yydebug' variable to be defined. */
95 %union {long itype; tree ttype; enum tree_code code;
96 char *filename; int lineno; }
98 /* All identifiers that are not reserved words
99 and are not declared typedefs in the current block */
102 /* All identifiers that are declared typedefs in the current block.
103 In some contexts, they are treated just like IDENTIFIER,
104 but they can also serve as typespecs in declarations. */
107 /* Reserved words that specify storage class.
108 yylval contains an IDENTIFIER_NODE which indicates which one. */
111 /* Reserved words that specify type.
112 yylval contains an IDENTIFIER_NODE which indicates which one. */
115 /* Reserved words that qualify type: "const" or "volatile".
116 yylval contains an IDENTIFIER_NODE which indicates which one. */
119 /* Character or numeric constants.
120 yylval is the node for the constant. */
123 /* String constants in raw form.
124 yylval is a STRING_CST node. */
127 /* "...", used for functions with variable arglists. */
130 /* the reserved words */
131 /* SCO include files test "ASM", so use something else. */
132 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
133 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
134 %token ATTRIBUTE EXTENSION LABEL
135 %token REALPART IMAGPART
137 /* Add precedence rules to solve dangling else s/r conflict */
141 /* Define the operator tokens and their precedences.
142 The value is an integer because, if used, it is the tree code
143 to use in the expression made from the operator. */
145 %right <code> ASSIGN '='
146 %right <code> '?' ':'
152 %left <code> EQCOMPARE
153 %left <code> ARITHCOMPARE
154 %left <code> LSHIFT RSHIFT
156 %left <code> '*' '/' '%'
157 %right <code> UNARY PLUSPLUS MINUSMINUS
159 %left <code> POINTSAT '.' '(' '['
161 /* The Objective-C keywords. These are included in C and in
162 Objective C, so that the token codes are the same in both. */
163 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
164 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
166 /* Objective-C string constants in raw form.
167 yylval is an OBJC_STRING_CST node. */
173 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
174 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
175 %type <ttype> typed_declspecs reserved_declspecs
176 %type <ttype> typed_typespecs reserved_typespecquals
177 %type <ttype> declmods typespec typespecqual_reserved
178 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
179 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
180 %type <ttype> init maybeasm
181 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
182 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
183 %type <ttype> any_word
185 %type <ttype> compstmt
187 %type <ttype> declarator
188 %type <ttype> notype_declarator after_type_declarator
189 %type <ttype> parm_declarator
191 %type <ttype> structsp component_decl_list component_decl_list2
192 %type <ttype> component_decl components component_declarator
193 %type <ttype> enumlist enumerator
194 %type <ttype> typename absdcl absdcl1 type_quals
195 %type <ttype> xexpr parms parm identifiers
197 %type <ttype> parmlist parmlist_1 parmlist_2
198 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
199 %type <ttype> identifiers_or_typenames
201 %type <itype> setspecs
203 %type <filename> save_filename
204 %type <lineno> save_lineno
207 /* the Objective-C nonterminals */
209 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
210 %type <ttype> methoddecl unaryselector keywordselector selector
211 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
212 %type <ttype> keywordexpr keywordarglist keywordarg
213 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
214 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
215 %type <ttype> objc_string protocolrefs identifier_list objcprotocolexpr
216 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
220 /* Number of statements (loosely speaking) seen so far. */
221 static int stmt_count;
223 /* Input file and line number of the end of the body of last simple_if;
224 used by the stmt-rule immediately after simple_if returns. */
225 static char *if_stmt_file;
226 static int if_stmt_line;
228 /* List of types and structure classes of the current declaration. */
229 static tree current_declspecs;
231 /* Stack of saved values of current_declspecs. */
232 static tree declspec_stack;
234 /* 1 if we explained undeclared var errors. */
235 static int undeclared_variable_notice;
238 /* Objective-C specific information */
240 tree objc_interface_context;
241 tree objc_implementation_context;
242 tree objc_method_context;
243 tree objc_ivar_chain;
244 tree objc_ivar_context;
245 enum tree_code objc_inherit_code;
246 int objc_receiver_context;
247 int objc_public_flag;
251 /* Tell yyparse how to print a token's value, if yydebug is set. */
253 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
254 extern void yyprint ();
260 pedwarn ("ANSI C forbids an empty source file");
265 /* In case there were missing closebraces,
266 get us back to the global binding level. */
267 while (! global_bindings_p ())
273 /* the reason for the strange actions in this rule
274 is so that notype_initdecls when reached via datadef
275 can find a valid list of type and sc specs in $0. */
278 {$<ttype>$ = NULL_TREE; } extdef
279 | extdefs {$<ttype>$ = NULL_TREE; } extdef
288 | ASM_KEYWORD '(' expr ')' ';'
290 if ((TREE_CODE ($3) == ADDR_EXPR
291 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
292 || TREE_CODE ($3) == STRING_CST)
295 error ("argument of `asm' is not a constant string"); }
299 setspecs notype_initdecls ';'
301 error ("ANSI C forbids data definition with no type or storage class");
302 else if (!flag_traditional)
303 warning ("data definition has no type or storage class"); }
304 | declmods setspecs notype_initdecls ';'
306 | typed_declspecs setspecs initdecls ';'
309 { pedwarn ("empty declaration"); }
310 | typed_declspecs ';'
316 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
320 typed_declspecs setspecs declarator
321 { if (! start_function ($1, $3, 0))
323 reinit_parse_for_function (); }
325 { store_parm_decls (); }
327 { finish_function (0); }
328 | typed_declspecs setspecs declarator error
330 | declmods setspecs notype_declarator
331 { if (! start_function ($1, $3, 0))
333 reinit_parse_for_function (); }
335 { store_parm_decls (); }
337 { finish_function (0); }
338 | declmods setspecs notype_declarator error
340 | setspecs notype_declarator
341 { if (! start_function (NULL_TREE, $2, 0))
343 reinit_parse_for_function (); }
345 { store_parm_decls (); }
347 { finish_function (0); }
348 | setspecs notype_declarator error
364 { $$ = NEGATE_EXPR; }
366 { $$ = CONVERT_EXPR; }
368 { $$ = PREINCREMENT_EXPR; }
370 { $$ = PREDECREMENT_EXPR; }
372 { $$ = BIT_NOT_EXPR; }
374 { $$ = TRUTH_NOT_EXPR; }
377 expr: nonnull_exprlist
378 { $$ = build_compound_expr ($1); }
389 { $$ = build_tree_list (NULL_TREE, $1); }
390 | nonnull_exprlist ',' expr_no_commas
391 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
396 | '*' cast_expr %prec UNARY
397 { $$ = build_indirect_ref ($2, "unary *"); }
398 /* __extension__ turns off -pedantic for following primary. */
400 { $<itype>1 = pedantic;
402 cast_expr %prec UNARY
404 pedantic = $<itype>1; }
405 | unop cast_expr %prec UNARY
406 { $$ = build_unary_op ($1, $2, 0);
407 overflow_warning ($$); }
408 /* Refer to the address of a label as a pointer. */
410 { tree label = lookup_label ($2);
412 pedwarn ("ANSI C forbids `&&'");
414 $$ = null_pointer_node;
417 TREE_USED (label) = 1;
418 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
419 TREE_CONSTANT ($$) = 1;
422 /* This seems to be impossible on some machines, so let's turn it off.
423 You can use __builtin_next_arg to find the anonymous stack args.
425 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
426 $$ = error_mark_node;
427 if (TREE_VALUE (tree_last (types)) == void_type_node)
428 error ("`&...' used in function with fixed number of arguments");
432 pedwarn ("ANSI C forbids `&...'");
433 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
434 $$ = build_unary_op (ADDR_EXPR, $$, 0);
437 | SIZEOF unary_expr %prec UNARY
438 { if (TREE_CODE ($2) == COMPONENT_REF
439 && DECL_BIT_FIELD (TREE_OPERAND ($2, 1)))
440 error ("`sizeof' applied to a bit-field");
441 $$ = c_sizeof (TREE_TYPE ($2)); }
442 | SIZEOF '(' typename ')' %prec HYPERUNARY
443 { $$ = c_sizeof (groktypename ($3)); }
444 | ALIGNOF unary_expr %prec UNARY
445 { $$ = c_alignof_expr ($2); }
446 | ALIGNOF '(' typename ')' %prec HYPERUNARY
447 { $$ = c_alignof (groktypename ($3)); }
448 | REALPART cast_expr %prec UNARY
449 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
450 | IMAGPART cast_expr %prec UNARY
451 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
456 | '(' typename ')' cast_expr %prec UNARY
457 { tree type = groktypename ($2);
458 $$ = build_c_cast (type, $4); }
459 | '(' typename ')' '{'
460 { start_init (NULL_TREE, NULL, 0);
461 $2 = groktypename ($2);
462 really_start_incremental_init ($2); }
463 initlist_maybe_comma '}' %prec UNARY
465 tree result = pop_init_level (0);
470 pedwarn ("ANSI C forbids constructor expressions");
471 if (TYPE_NAME (type) != 0)
473 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
474 name = IDENTIFIER_POINTER (TYPE_NAME (type));
476 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
481 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
483 int failure = complete_array_type (type, $$, 1);
492 | expr_no_commas '+' expr_no_commas
493 { $$ = parser_build_binary_op ($2, $1, $3); }
494 | expr_no_commas '-' expr_no_commas
495 { $$ = parser_build_binary_op ($2, $1, $3); }
496 | expr_no_commas '*' expr_no_commas
497 { $$ = parser_build_binary_op ($2, $1, $3); }
498 | expr_no_commas '/' expr_no_commas
499 { $$ = parser_build_binary_op ($2, $1, $3); }
500 | expr_no_commas '%' expr_no_commas
501 { $$ = parser_build_binary_op ($2, $1, $3); }
502 | expr_no_commas LSHIFT expr_no_commas
503 { $$ = parser_build_binary_op ($2, $1, $3); }
504 | expr_no_commas RSHIFT expr_no_commas
505 { $$ = parser_build_binary_op ($2, $1, $3); }
506 | expr_no_commas ARITHCOMPARE expr_no_commas
507 { $$ = parser_build_binary_op ($2, $1, $3); }
508 | expr_no_commas EQCOMPARE expr_no_commas
509 { $$ = parser_build_binary_op ($2, $1, $3); }
510 | expr_no_commas '&' expr_no_commas
511 { $$ = parser_build_binary_op ($2, $1, $3); }
512 | expr_no_commas '|' expr_no_commas
513 { $$ = parser_build_binary_op ($2, $1, $3); }
514 | expr_no_commas '^' expr_no_commas
515 { $$ = parser_build_binary_op ($2, $1, $3); }
516 | expr_no_commas ANDAND expr_no_commas
517 { $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
518 | expr_no_commas OROR expr_no_commas
519 { $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
520 | expr_no_commas '?' xexpr ':' expr_no_commas
521 { $$ = build_conditional_expr ($1, $3, $5); }
522 | expr_no_commas '=' expr_no_commas
523 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
524 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
525 | expr_no_commas ASSIGN expr_no_commas
526 { $$ = build_modify_expr ($1, $2, $3);
527 /* This inhibits warnings in truthvalue_conversion. */
528 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
535 if (!$$ || $$ == error_mark_node)
537 if (yychar == YYEMPTY)
544 if (objc_receiver_context
545 && ! (objc_receiver_context
546 && strcmp (IDENTIFIER_POINTER ($1), "super")))
547 /* we have a message to super */
548 $$ = get_super_receiver ();
549 else if (objc_method_context
550 && (decl = is_ivar (objc_ivar_chain, $1)))
552 if (is_private (decl))
553 $$ = error_mark_node;
555 $$ = build_ivar_reference ($1);
560 /* Ordinary implicit function declaration. */
561 $$ = implicitly_declare ($1);
562 assemble_external ($$);
566 else if (current_function_decl == 0)
568 error ("`%s' undeclared here (not in a function)",
569 IDENTIFIER_POINTER ($1));
570 $$ = error_mark_node;
577 if (objc_receiver_context
578 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
579 /* we have a message to super */
580 $$ = get_super_receiver ();
581 else if (objc_method_context
582 && (decl = is_ivar (objc_ivar_chain, $1)))
584 if (is_private (decl))
585 $$ = error_mark_node;
587 $$ = build_ivar_reference ($1);
592 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
593 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
595 error ("`%s' undeclared (first use this function)",
596 IDENTIFIER_POINTER ($1));
598 if (! undeclared_variable_notice)
600 error ("(Each undeclared identifier is reported only once");
601 error ("for each function it appears in.)");
602 undeclared_variable_notice = 1;
605 $$ = error_mark_node;
606 /* Prevent repeated error messages. */
607 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
608 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
612 else if (TREE_TYPE ($$) == error_mark_node)
613 $$ = error_mark_node;
614 else if (C_DECL_ANTICIPATED ($$))
616 /* The first time we see a build-in function used,
617 if it has not been declared. */
618 C_DECL_ANTICIPATED ($$) = 0;
619 if (yychar == YYEMPTY)
623 /* Omit the implicit declaration we
624 would ordinarily do, so we don't lose
625 the actual built in type.
626 But print a diagnostic for the mismatch. */
628 if (objc_method_context
629 && is_ivar (objc_ivar_chain, $1))
630 error ("Instance variable `%s' implicitly declared as function",
631 IDENTIFIER_POINTER (DECL_NAME ($$)));
634 if (TREE_CODE ($$) != FUNCTION_DECL)
635 error ("`%s' implicitly declared as function",
636 IDENTIFIER_POINTER (DECL_NAME ($$)));
637 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
638 != TYPE_MODE (integer_type_node))
639 && (TREE_TYPE (TREE_TYPE ($$))
641 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
642 IDENTIFIER_POINTER (DECL_NAME ($$)));
643 /* If it really returns void, change that to int. */
644 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
646 = build_function_type (integer_type_node,
647 TYPE_ARG_TYPES (TREE_TYPE ($$)));
650 pedwarn ("built-in function `%s' used without declaration",
651 IDENTIFIER_POINTER (DECL_NAME ($$)));
653 /* Do what we would ordinarily do when a fn is used. */
654 assemble_external ($$);
659 assemble_external ($$);
662 /* we have a definition - still check if iVariable */
664 if (!objc_receiver_context
665 || (objc_receiver_context
666 && strcmp (IDENTIFIER_POINTER ($1), "super")))
670 if (objc_method_context
671 && (decl = is_ivar (objc_ivar_chain, $1)))
673 if (IDENTIFIER_LOCAL_VALUE ($1))
674 warning ("local declaration of `%s' hides instance variable",
675 IDENTIFIER_POINTER ($1));
678 if (is_private (decl))
679 $$ = error_mark_node;
681 $$ = build_ivar_reference ($1);
685 else /* we have a message to super */
686 $$ = get_super_receiver ();
690 if (TREE_CODE ($$) == CONST_DECL)
692 $$ = DECL_INITIAL ($$);
693 /* This is to prevent an enum whose value is 0
694 from being considered a null pointer constant. */
695 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
696 TREE_CONSTANT ($$) = 1;
701 { $$ = combine_strings ($1); }
703 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
704 if (class == 'e' || class == '1'
705 || class == '2' || class == '<')
706 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
709 { $$ = error_mark_node; }
711 { if (current_function_decl == 0)
713 error ("braced-group within expression allowed only inside a function");
716 /* We must force a BLOCK for this level
717 so that, if it is not expanded later,
718 there is a way to turn off the entire subtree of blocks
719 that are contained in it. */
721 push_iterator_stack ();
723 $<ttype>$ = expand_start_stmt_expr (); }
727 pedwarn ("ANSI C forbids braced-groups within expressions");
728 pop_iterator_stack ();
730 rtl_exp = expand_end_stmt_expr ($<ttype>2);
731 /* The statements have side effects, so the group does. */
732 TREE_SIDE_EFFECTS (rtl_exp) = 1;
734 if (TREE_CODE ($3) == BLOCK)
736 /* Make a BIND_EXPR for the BLOCK already made. */
737 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
738 NULL_TREE, rtl_exp, $3);
739 /* Remove the block from the tree at this point.
740 It gets put back at the proper place
741 when the BIND_EXPR is expanded. */
747 | primary '(' exprlist ')' %prec '.'
748 { $$ = build_function_call ($1, $3); }
749 | primary '[' expr ']' %prec '.'
750 { $$ = build_array_ref ($1, $3); }
751 | primary '.' identifier
754 if (doing_objc_thang)
756 if (is_public ($1, $3))
757 $$ = build_component_ref ($1, $3);
759 $$ = error_mark_node;
763 $$ = build_component_ref ($1, $3);
765 | primary POINTSAT identifier
767 tree expr = build_indirect_ref ($1, "->");
770 if (doing_objc_thang)
772 if (is_public (expr, $3))
773 $$ = build_component_ref (expr, $3);
775 $$ = error_mark_node;
779 $$ = build_component_ref (expr, $3);
782 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
784 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
787 { $$ = build_message_expr ($1); }
789 { $$ = build_selector_expr ($1); }
791 { $$ = build_protocol_expr ($1); }
793 { $$ = build_encode_expr ($1); }
795 { $$ = build_objc_string_object ($1); }
799 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
803 { $$ = chainon ($1, $2); }
807 /* Produces an OBJC_STRING_CST with prehaps more OBJC_STRING_CSTs chained
811 | objc_string OBJC_STRING
812 { $$ = chainon ($1, $2); }
820 /* ... is used here to indicate a varargs function. */
823 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
826 /* The following are analogous to lineno_decl, decls and decl
827 except that they do not allow nested functions.
828 They are used for old-style parm decls. */
830 save_filename save_lineno datadecl
837 | datadecls lineno_datadecl
838 | lineno_datadecl errstmt
842 typed_declspecs setspecs initdecls ';'
843 { current_declspecs = TREE_VALUE (declspec_stack);
844 declspec_stack = TREE_CHAIN (declspec_stack);
845 resume_momentary ($2); }
846 | declmods setspecs notype_initdecls ';'
847 { current_declspecs = TREE_VALUE (declspec_stack);
848 declspec_stack = TREE_CHAIN (declspec_stack);
849 resume_momentary ($2); }
850 | typed_declspecs ';'
851 { shadow_tag_warned ($1, 1);
852 pedwarn ("empty declaration"); }
854 { pedwarn ("empty declaration"); }
857 /* This combination which saves a lineno before a decl
858 is the normal thing to use, rather than decl itself.
859 This is to avoid shift/reduce conflicts in contexts
860 where statement labels are allowed. */
862 save_filename save_lineno decl
870 | lineno_decl errstmt
873 /* records the type and storage class specs to use for processing
874 the declarators that follow.
875 Maintains a stack of outer-level values of current_declspecs,
876 for the sake of parm declarations nested in function declarators. */
877 setspecs: /* empty */
878 { $$ = suspend_momentary ();
879 pending_xref_error ();
880 declspec_stack = tree_cons (NULL_TREE, current_declspecs,
882 current_declspecs = $<ttype>0; }
886 typed_declspecs setspecs initdecls ';'
887 { current_declspecs = TREE_VALUE (declspec_stack);
888 declspec_stack = TREE_CHAIN (declspec_stack);
889 resume_momentary ($2); }
890 | declmods setspecs notype_initdecls ';'
891 { current_declspecs = TREE_VALUE (declspec_stack);
892 declspec_stack = TREE_CHAIN (declspec_stack);
893 resume_momentary ($2); }
894 | typed_declspecs setspecs nested_function
895 { current_declspecs = TREE_VALUE (declspec_stack);
896 declspec_stack = TREE_CHAIN (declspec_stack);
897 resume_momentary ($2); }
898 | declmods setspecs notype_nested_function
899 { current_declspecs = TREE_VALUE (declspec_stack);
900 declspec_stack = TREE_CHAIN (declspec_stack);
901 resume_momentary ($2); }
902 | typed_declspecs ';'
905 { pedwarn ("empty declaration"); }
908 /* Declspecs which contain at least one type specifier or typedef name.
909 (Just `const' or `volatile' is not enough.)
910 A typedef'd name following these is taken as a name to be declared. */
913 typespec reserved_declspecs
914 { $$ = tree_cons (NULL_TREE, $1, $2); }
915 | declmods typespec reserved_declspecs
916 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
919 reserved_declspecs: /* empty */
921 | reserved_declspecs typespecqual_reserved
922 { $$ = tree_cons (NULL_TREE, $2, $1); }
923 | reserved_declspecs SCSPEC
924 { if (extra_warnings)
925 warning ("`%s' is not at beginning of declaration",
926 IDENTIFIER_POINTER ($2));
927 $$ = tree_cons (NULL_TREE, $2, $1); }
930 /* List of just storage classes and type modifiers.
931 A declaration can start with just this, but then it cannot be used
932 to redeclare a typedef-name. */
936 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
937 TREE_STATIC ($$) = 1; }
939 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
941 { $$ = tree_cons (NULL_TREE, $2, $1);
942 TREE_STATIC ($$) = 1; }
944 { if (extra_warnings && TREE_STATIC ($1))
945 warning ("`%s' is not at beginning of declaration",
946 IDENTIFIER_POINTER ($2));
947 $$ = tree_cons (NULL_TREE, $2, $1);
948 TREE_STATIC ($$) = TREE_STATIC ($1); }
952 /* Used instead of declspecs where storage classes are not allowed
953 (that is, for typenames and structure components).
954 Don't accept a typedef-name if anything but a modifier precedes it. */
957 typespec reserved_typespecquals
958 { $$ = tree_cons (NULL_TREE, $1, $2); }
959 | nonempty_type_quals typespec reserved_typespecquals
960 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
963 reserved_typespecquals: /* empty */
965 | reserved_typespecquals typespecqual_reserved
966 { $$ = tree_cons (NULL_TREE, $2, $1); }
969 /* A typespec (but not a type qualifier).
970 Once we have seen one of these in a declaration,
971 if a typedef name appears then it is being redeclared. */
976 { /* For a typedef name, record the meaning, not the name.
977 In case of `foo foo, bar;'. */
978 $$ = lookup_name ($1); }
980 | CLASSNAME protocolrefs
981 { $$ = get_static_reference ($1, $2); }
982 | OBJECTNAME protocolrefs
983 { $$ = get_object_reference ($2); }
985 | TYPEOF '(' expr ')'
986 { $$ = TREE_TYPE ($3); }
987 | TYPEOF '(' typename ')'
988 { $$ = groktypename ($3); }
991 /* A typespec that is a reserved word, or a type qualifier. */
993 typespecqual_reserved: TYPESPEC
1000 | initdecls ',' initdcl
1005 | notype_initdecls ',' initdcl
1011 | ASM_KEYWORD '(' string ')'
1012 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1018 declarator maybeasm maybe_attribute '='
1019 { $<ttype>$ = start_decl ($1, current_declspecs, 1);
1020 decl_attributes ($<ttype>$, $3);
1021 start_init ($<ttype>$, $2, global_bindings_p ()); }
1023 /* Note how the declaration of the variable is in effect while its init is parsed! */
1025 decl_attributes ($<ttype>5, $3);
1026 finish_decl ($<ttype>5, $6, $2); }
1027 | declarator maybeasm maybe_attribute
1028 { tree d = start_decl ($1, current_declspecs, 0);
1029 decl_attributes (d, $3);
1030 finish_decl (d, NULL_TREE, $2); }
1034 notype_declarator maybeasm maybe_attribute '='
1035 { $<ttype>$ = start_decl ($1, current_declspecs, 1);
1036 decl_attributes ($<ttype>$, $3);
1037 start_init ($<ttype>$, $2, global_bindings_p ()); }
1039 /* Note how the declaration of the variable is in effect while its init is parsed! */
1041 decl_attributes ($<ttype>5, $3);
1042 finish_decl ($<ttype>5, $6, $2); }
1043 | notype_declarator maybeasm maybe_attribute
1044 { tree d = start_decl ($1, current_declspecs, 0);
1045 decl_attributes (d, $3);
1046 finish_decl (d, NULL_TREE, $2); }
1048 /* the * rules are dummies to accept the Apollo extended syntax
1049 so that the header files compile. */
1060 | attributes attribute
1061 { $$ = chainon ($1, $2); }
1065 ATTRIBUTE '(' '(' attribute_list ')' ')'
1071 { $$ = build_tree_list (NULL_TREE, $1); }
1072 | attribute_list ',' attrib
1073 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
1081 | any_word '(' IDENTIFIER ')'
1082 { $$ = tree_cons ($1, NULL_TREE,
1083 build_tree_list (NULL_TREE, $3)); }
1084 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1085 { $$ = tree_cons ($1, NULL_TREE,
1086 tree_cons (NULL_TREE, $3, $5)); }
1087 | any_word '(' nonnull_exprlist ')'
1088 { $$ = tree_cons ($1, NULL_TREE, $3); }
1091 /* This still leaves out most reserved keywords,
1092 shouldn't we include them? */
1101 /* Initializers. `init' is the entry point. */
1106 { really_start_incremental_init (NULL_TREE);
1107 /* Note that the call to clear_momentary
1108 is in process_init_element. */
1109 push_momentary (); }
1110 initlist_maybe_comma '}'
1111 { $$ = pop_init_level (0);
1112 if ($$ == error_mark_node
1113 && ! (yychar == STRING || yychar == CONSTANT))
1116 pop_momentary_nofree (); }
1119 { $$ = error_mark_node; }
1122 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1123 initlist_maybe_comma:
1126 pedwarn ("ANSI C forbids empty initializer braces"); }
1127 | initlist1 maybecomma
1132 | initlist1 ',' initelt
1135 /* `initelt' is a single element of an initializer.
1136 It may use braces. */
1139 { process_init_element ($1); }
1141 { push_init_level (0); }
1142 initlist_maybe_comma '}'
1143 { process_init_element (pop_init_level (0)); }
1145 /* These are for labeled elements. The syntax for an array element
1146 initializer conflicts with the syntax for an Objective-C message,
1147 so don't include these productions in the Objective-C grammer. */
1149 | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1150 { set_init_index ($2, $4); }
1152 | '[' expr_no_commas ']' '='
1153 { set_init_index ($2, NULL_TREE); }
1155 | '[' expr_no_commas ']'
1156 { set_init_index ($2, NULL_TREE); }
1160 { set_init_label ($1); }
1162 | '.' identifier '='
1163 { set_init_label ($2); }
1169 { push_c_function_context ();
1170 if (! start_function (current_declspecs, $1, 1))
1172 pop_c_function_context ();
1175 reinit_parse_for_function ();
1176 store_parm_decls (); }
1177 /* This used to use compstmt_or_error.
1178 That caused a bug with input `f(g) int g {}',
1179 where the use of YYERROR1 above caused an error
1180 which then was handled by compstmt_or_error.
1181 There followed a repeated execution of that same rule,
1182 which called YYERROR1 again, and so on. */
1184 { finish_function (1);
1185 pop_c_function_context (); }
1188 notype_nested_function:
1190 { push_c_function_context ();
1191 if (! start_function (current_declspecs, $1, 1))
1193 pop_c_function_context ();
1196 reinit_parse_for_function ();
1197 store_parm_decls (); }
1198 /* This used to use compstmt_or_error.
1199 That caused a bug with input `f(g) int g {}',
1200 where the use of YYERROR1 above caused an error
1201 which then was handled by compstmt_or_error.
1202 There followed a repeated execution of that same rule,
1203 which called YYERROR1 again, and so on. */
1205 { finish_function (1);
1206 pop_c_function_context (); }
1209 /* Any kind of declarator (thus, all declarators allowed
1210 after an explicit typespec). */
1213 after_type_declarator
1217 /* A declarator that is allowed only after an explicit typespec. */
1219 after_type_declarator:
1220 '(' after_type_declarator ')'
1222 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1223 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1224 /* | after_type_declarator '(' error ')' %prec '.'
1225 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1226 poplevel (0, 0, 0); } */
1227 | after_type_declarator '[' expr ']' %prec '.'
1228 { $$ = build_nt (ARRAY_REF, $1, $3); }
1229 | after_type_declarator '[' ']' %prec '.'
1230 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1231 | '*' type_quals after_type_declarator %prec UNARY
1232 { $$ = make_pointer_declarator ($2, $3); }
1239 /* Kinds of declarator that can appear in a parameter list
1240 in addition to notype_declarator. This is like after_type_declarator
1241 but does not allow a typedef name in parentheses as an identifier
1242 (because it would conflict with a function with that typedef as arg). */
1245 parm_declarator '(' parmlist_or_identifiers %prec '.'
1246 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1247 /* | parm_declarator '(' error ')' %prec '.'
1248 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1249 poplevel (0, 0, 0); } */
1250 | parm_declarator '[' expr ']' %prec '.'
1251 { $$ = build_nt (ARRAY_REF, $1, $3); }
1252 | parm_declarator '[' ']' %prec '.'
1253 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1254 | '*' type_quals parm_declarator %prec UNARY
1255 { $$ = make_pointer_declarator ($2, $3); }
1259 /* A declarator allowed whether or not there has been
1260 an explicit typespec. These cannot redeclare a typedef-name. */
1263 notype_declarator '(' parmlist_or_identifiers %prec '.'
1264 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1265 /* | notype_declarator '(' error ')' %prec '.'
1266 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1267 poplevel (0, 0, 0); } */
1268 | '(' notype_declarator ')'
1270 | '*' type_quals notype_declarator %prec UNARY
1271 { $$ = make_pointer_declarator ($2, $3); }
1272 | notype_declarator '[' expr ']' %prec '.'
1273 { $$ = build_nt (ARRAY_REF, $1, $3); }
1274 | notype_declarator '[' ']' %prec '.'
1275 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1280 STRUCT identifier '{'
1281 { $$ = start_struct (RECORD_TYPE, $2);
1282 /* Start scope of tag before parsing components. */
1284 component_decl_list '}'
1285 { $$ = finish_struct ($<ttype>4, $5);
1286 /* Really define the structure. */
1288 | STRUCT '{' component_decl_list '}'
1289 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1292 { $$ = xref_tag (RECORD_TYPE, $2); }
1293 | UNION identifier '{'
1294 { $$ = start_struct (UNION_TYPE, $2); }
1295 component_decl_list '}'
1296 { $$ = finish_struct ($<ttype>4, $5); }
1297 | UNION '{' component_decl_list '}'
1298 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1301 { $$ = xref_tag (UNION_TYPE, $2); }
1302 | ENUM identifier '{'
1303 { $<itype>3 = suspend_momentary ();
1304 $$ = start_enum ($2); }
1305 enumlist maybecomma_warn '}'
1306 { $$ = finish_enum ($<ttype>4, nreverse ($5));
1307 resume_momentary ($<itype>3); }
1309 { $<itype>2 = suspend_momentary ();
1310 $$ = start_enum (NULL_TREE); }
1311 enumlist maybecomma_warn '}'
1312 { $$ = finish_enum ($<ttype>3, nreverse ($4));
1313 resume_momentary ($<itype>2); }
1315 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1326 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1329 component_decl_list:
1330 component_decl_list2
1332 | component_decl_list2 component_decl
1333 { $$ = chainon ($1, $2);
1334 pedwarn ("no semicolon at end of struct or union"); }
1337 component_decl_list2: /* empty */
1339 | component_decl_list2 component_decl ';'
1340 { $$ = chainon ($1, $2); }
1341 | component_decl_list2 ';'
1343 pedwarn ("extra semicolon in struct or union specified"); }
1345 /* foo(sizeof(struct{ @defs(ClassName)})); */
1346 | DEFS '(' CLASSNAME ')'
1348 tree interface = lookup_interface ($3);
1351 $$ = get_class_ivars (interface);
1354 error ("Cannot find interface declaration for `%s'",
1355 IDENTIFIER_POINTER ($3));
1362 /* There is a shift-reduce conflict here, because `components' may
1363 start with a `typename'. It happens that shifting (the default resolution)
1364 does the right thing, because it treats the `typename' as part of
1365 a `typed_typespecs'.
1367 It is possible that this same technique would allow the distinction
1368 between `notype_initdecls' and `initdecls' to be eliminated.
1369 But I am being cautious and not trying it. */
1372 typed_typespecs setspecs components
1374 current_declspecs = TREE_VALUE (declspec_stack);
1375 declspec_stack = TREE_CHAIN (declspec_stack);
1376 resume_momentary ($2); }
1379 pedwarn ("ANSI C forbids member declarations with no members");
1382 | nonempty_type_quals setspecs components
1384 current_declspecs = TREE_VALUE (declspec_stack);
1385 declspec_stack = TREE_CHAIN (declspec_stack);
1386 resume_momentary ($2); }
1387 | nonempty_type_quals
1389 pedwarn ("ANSI C forbids member declarations with no members");
1397 component_declarator
1398 | components ',' component_declarator
1399 { $$ = chainon ($1, $3); }
1402 component_declarator:
1403 save_filename save_lineno declarator maybe_attribute
1404 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1405 decl_attributes ($$, $4); }
1406 | save_filename save_lineno
1407 declarator ':' expr_no_commas maybe_attribute
1408 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1409 decl_attributes ($$, $6); }
1410 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1411 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1412 decl_attributes ($$, $5); }
1415 /* We chain the enumerators in reverse order.
1416 They are put in forward order where enumlist is used.
1417 (The order used to be significant, but no longer is so.
1418 However, we still maintain the order, just to be clean.) */
1422 | enumlist ',' enumerator
1423 { $$ = chainon ($3, $1); }
1425 { $$ = error_mark_node; }
1431 { $$ = build_enumerator ($1, NULL_TREE); }
1432 | identifier '=' expr_no_commas
1433 { $$ = build_enumerator ($1, $3); }
1437 typed_typespecs absdcl
1438 { $$ = build_tree_list ($1, $2); }
1439 | nonempty_type_quals absdcl
1440 { $$ = build_tree_list ($1, $2); }
1443 absdcl: /* an absolute declarator */
1449 nonempty_type_quals:
1451 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1452 | nonempty_type_quals TYPE_QUAL
1453 { $$ = tree_cons (NULL_TREE, $2, $1); }
1459 | type_quals TYPE_QUAL
1460 { $$ = tree_cons (NULL_TREE, $2, $1); }
1463 absdcl1: /* a nonempty absolute declarator */
1466 /* `(typedef)1' is `int'. */
1467 | '*' type_quals absdcl1 %prec UNARY
1468 { $$ = make_pointer_declarator ($2, $3); }
1469 | '*' type_quals %prec UNARY
1470 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1471 | absdcl1 '(' parmlist %prec '.'
1472 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1473 | absdcl1 '[' expr ']' %prec '.'
1474 { $$ = build_nt (ARRAY_REF, $1, $3); }
1475 | absdcl1 '[' ']' %prec '.'
1476 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1477 | '(' parmlist %prec '.'
1478 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1479 | '[' expr ']' %prec '.'
1480 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1482 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1485 /* at least one statement, the first of which parses without error. */
1486 /* stmts is used only after decls, so an invalid first statement
1487 is actually regarded as an invalid decl and part of the decls. */
1490 lineno_stmt_or_label
1491 | stmts lineno_stmt_or_label
1503 pushlevel: /* empty */
1504 { emit_line_note (input_filename, lineno);
1508 expand_start_bindings (0);
1510 if (objc_method_context)
1516 /* Read zero or more forward-declarations for labels
1517 that nested functions can jump to. */
1522 pedwarn ("ANSI C forbids label declarations"); }
1527 | label_decls label_decl
1531 LABEL identifiers_or_typenames ';'
1533 for (link = $2; link; link = TREE_CHAIN (link))
1535 tree label = shadow_label (TREE_VALUE (link));
1536 C_DECLARED_LABEL_FLAG (label) = 1;
1537 declare_nonlocal_label (label);
1542 /* This is the body of a function definition.
1543 It causes syntax errors to ignore to the next openbrace. */
1551 { $$ = convert (void_type_node, integer_zero_node); }
1552 | '{' pushlevel maybe_label_decls decls xstmts '}'
1553 { emit_line_note (input_filename, lineno);
1554 expand_end_bindings (getdecls (), 1, 0);
1555 $$ = poplevel (1, 1, 0);
1556 if (yychar == CONSTANT || yychar == STRING)
1557 pop_momentary_nofree ();
1560 | '{' pushlevel maybe_label_decls error '}'
1561 { emit_line_note (input_filename, lineno);
1562 expand_end_bindings (getdecls (), kept_level_p (), 0);
1563 $$ = poplevel (kept_level_p (), 0, 0);
1564 if (yychar == CONSTANT || yychar == STRING)
1565 pop_momentary_nofree ();
1568 | '{' pushlevel maybe_label_decls stmts '}'
1569 { emit_line_note (input_filename, lineno);
1570 expand_end_bindings (getdecls (), kept_level_p (), 0);
1571 $$ = poplevel (kept_level_p (), 0, 0);
1572 if (yychar == CONSTANT || yychar == STRING)
1573 pop_momentary_nofree ();
1578 /* Value is number of statements counted as of the closeparen. */
1580 if_prefix lineno_labeled_stmt
1581 /* Make sure expand_end_cond is run once
1582 for each call to expand_start_cond.
1583 Otherwise a crash is likely. */
1589 { emit_line_note ($<filename>-1, $<lineno>0);
1590 expand_start_cond (truthvalue_conversion ($3), 0);
1591 $<itype>$ = stmt_count;
1592 if_stmt_file = $<filename>-1;
1593 if_stmt_line = $<lineno>0;
1594 position_after_white_space (); }
1597 /* This is a subroutine of stmt.
1598 It is used twice, once for valid DO statements
1599 and once for catching errors in parsing the end test. */
1603 emit_line_note ($<filename>-1, $<lineno>0);
1604 /* See comment in `while' alternative, above. */
1606 expand_start_loop_continue_elsewhere (1);
1607 position_after_white_space (); }
1608 lineno_labeled_stmt WHILE
1609 { expand_loop_continue_here (); }
1613 { $$ = input_filename; }
1620 lineno_labeled_stmt:
1621 save_filename save_lineno stmt
1623 /* | save_filename save_lineno error
1626 | save_filename save_lineno label lineno_labeled_stmt
1630 lineno_stmt_or_label:
1631 save_filename save_lineno stmt_or_label
1639 position_after_white_space ();
1640 next = getc (finput);
1641 ungetc (next, finput);
1642 if (pedantic && next == '}')
1643 pedwarn ("ANSI C forbids label at end of compound statement");
1647 /* Parse a single real statement, not including any labels. */
1654 emit_line_note ($<filename>-1, $<lineno>0);
1655 /* It appears that this should not be done--that a non-lvalue array
1656 shouldn't get an error if the value isn't used.
1657 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1658 if it appears as a top-level expression,
1659 but says nothing about non-lvalue arrays. */
1661 /* Call default_conversion to get an error
1662 on referring to a register array if pedantic. */
1663 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1664 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1665 $1 = default_conversion ($1);
1667 iterator_expand ($1);
1668 clear_momentary (); }
1670 { expand_start_else ();
1671 $<itype>1 = stmt_count;
1672 position_after_white_space (); }
1674 { expand_end_cond ();
1675 if (extra_warnings && stmt_count == $<itype>1)
1676 warning ("empty body in an else-statement"); }
1677 | simple_if %prec IF
1678 { expand_end_cond ();
1679 /* This warning is here instead of in simple_if, because we
1680 do not want a warning if an empty if is followed by an
1681 else statement. Increment stmt_count so we don't
1682 give a second error if this is a nested `if'. */
1683 if (extra_warnings && stmt_count++ == $<itype>1)
1684 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1685 "empty body in an if-statement"); }
1686 /* Make sure expand_end_cond is run once
1687 for each call to expand_start_cond.
1688 Otherwise a crash is likely. */
1689 | simple_if ELSE error
1690 { expand_end_cond (); }
1693 emit_line_note ($<filename>-1, $<lineno>0);
1694 /* The emit_nop used to come before emit_line_note,
1695 but that made the nop seem like part of the preceding line.
1696 And that was confusing when the preceding line was
1697 inside of an if statement and was not really executed.
1698 I think it ought to work to put the nop after the line number.
1699 We will see. --rms, July 15, 1991. */
1702 { /* Don't start the loop till we have succeeded
1703 in parsing the end test. This is to make sure
1704 that we end every loop we start. */
1705 expand_start_loop (1);
1706 emit_line_note (input_filename, lineno);
1707 expand_exit_loop_if_false (NULL_PTR,
1708 truthvalue_conversion ($4));
1709 position_after_white_space (); }
1711 { expand_end_loop (); }
1714 { emit_line_note (input_filename, lineno);
1715 expand_exit_loop_if_false (NULL_PTR,
1716 truthvalue_conversion ($3));
1718 clear_momentary (); }
1719 /* This rule is needed to make sure we end every loop we start. */
1720 | do_stmt_start error
1721 { expand_end_loop ();
1722 clear_momentary (); }
1726 emit_line_note ($<filename>-1, $<lineno>0);
1727 /* See comment in `while' alternative, above. */
1729 if ($3) c_expand_expr_stmt ($3);
1730 /* Next step is to call expand_start_loop_continue_elsewhere,
1731 but wait till after we parse the entire for (...).
1732 Otherwise, invalid input might cause us to call that
1733 fn without calling expand_end_loop. */
1736 /* Can't emit now; wait till after expand_start_loop... */
1737 { $<lineno>7 = lineno;
1738 $<filename>$ = input_filename; }
1741 /* Start the loop. Doing this after parsing
1742 all the expressions ensures we will end the loop. */
1743 expand_start_loop_continue_elsewhere (1);
1744 /* Emit the end-test, with a line number. */
1745 emit_line_note ($<filename>8, $<lineno>7);
1747 expand_exit_loop_if_false (NULL_PTR,
1748 truthvalue_conversion ($6));
1749 /* Don't let the tree nodes for $9 be discarded by
1750 clear_momentary during the parsing of the next stmt. */
1752 $<lineno>7 = lineno;
1753 $<filename>8 = input_filename;
1754 position_after_white_space (); }
1756 { /* Emit the increment expression, with a line number. */
1757 emit_line_note ($<filename>8, $<lineno>7);
1758 expand_loop_continue_here ();
1760 c_expand_expr_stmt ($9);
1761 if (yychar == CONSTANT || yychar == STRING)
1762 pop_momentary_nofree ();
1765 expand_end_loop (); }
1766 | SWITCH '(' expr ')'
1768 emit_line_note ($<filename>-1, $<lineno>0);
1769 c_expand_start_case ($3);
1770 /* Don't let the tree nodes for $3 be discarded by
1771 clear_momentary during the parsing of the next stmt. */
1773 position_after_white_space (); }
1775 { expand_end_case ($3);
1776 if (yychar == CONSTANT || yychar == STRING)
1777 pop_momentary_nofree ();
1782 emit_line_note ($<filename>-1, $<lineno>0);
1783 if ( ! expand_exit_something ())
1784 error ("break statement not within loop or switch"); }
1787 emit_line_note ($<filename>-1, $<lineno>0);
1788 if (! expand_continue_loop (NULL_PTR))
1789 error ("continue statement not within a loop"); }
1792 emit_line_note ($<filename>-1, $<lineno>0);
1793 c_expand_return (NULL_TREE); }
1796 emit_line_note ($<filename>-1, $<lineno>0);
1797 c_expand_return ($2); }
1798 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1800 emit_line_note ($<filename>-1, $<lineno>0);
1802 if ((TREE_CODE ($4) == ADDR_EXPR
1803 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1804 || TREE_CODE ($4) == STRING_CST)
1807 error ("argument of `asm' is not a constant string"); }
1808 /* This is the case with just output operands. */
1809 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1811 emit_line_note ($<filename>-1, $<lineno>0);
1812 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1813 $2 == ridpointers[(int)RID_VOLATILE],
1814 input_filename, lineno); }
1815 /* This is the case with input operands as well. */
1816 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1818 emit_line_note ($<filename>-1, $<lineno>0);
1819 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1820 $2 == ridpointers[(int)RID_VOLATILE],
1821 input_filename, lineno); }
1822 /* This is the case with clobbered registers as well. */
1823 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1824 asm_operands ':' asm_clobbers ')' ';'
1826 emit_line_note ($<filename>-1, $<lineno>0);
1827 c_expand_asm_operands ($4, $6, $8, $10,
1828 $2 == ridpointers[(int)RID_VOLATILE],
1829 input_filename, lineno); }
1830 | GOTO identifier ';'
1833 emit_line_note ($<filename>-1, $<lineno>0);
1834 decl = lookup_label ($2);
1837 TREE_USED (decl) = 1;
1843 emit_line_note ($<filename>-1, $<lineno>0);
1844 expand_computed_goto (convert (ptr_type_node, $3)); }
1849 all_iter_stmt_simple
1850 /* | all_iter_stmt_with_decl */
1853 all_iter_stmt_simple:
1856 /* The value returned by this action is */
1857 /* 1 if everything is OK */
1858 /* 0 in case of error or already bound iterator */
1861 if (TREE_CODE ($3) != VAR_DECL)
1862 error ("invalid `for (ITERATOR)' syntax");
1863 else if (! ITERATOR_P ($3))
1864 error ("`%s' is not an iterator",
1865 IDENTIFIER_POINTER (DECL_NAME ($3)));
1866 else if (ITERATOR_BOUND_P ($3))
1867 error ("`for (%s)' inside expansion of same iterator",
1868 IDENTIFIER_POINTER (DECL_NAME ($3)));
1872 iterator_for_loop_start ($3);
1878 iterator_for_loop_end ($3);
1881 /* This really should allow any kind of declaration,
1882 for generality. Fix it before turning it back on.
1884 all_iter_stmt_with_decl:
1885 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
1887 */ /* The value returned by this action is */
1888 /* 1 if everything is OK */
1889 /* 0 in case of error or already bound iterator */
1891 iterator_for_loop_start ($6);
1895 iterator_for_loop_end ($6);
1896 emit_line_note (input_filename, lineno);
1897 expand_end_bindings (getdecls (), 1, 0);
1898 $<ttype>$ = poplevel (1, 1, 0);
1899 if (yychar == CONSTANT || yychar == STRING)
1900 pop_momentary_nofree ();
1906 /* Any kind of label, including jump labels and case labels.
1907 ANSI C accepts labels only before statements, but we allow them
1908 also at the end of a compound statement. */
1910 label: CASE expr_no_commas ':'
1911 { register tree value = check_case_value ($2);
1913 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1917 if (value != error_mark_node)
1920 int success = pushcase (value, convert_and_check,
1923 error ("case label not within a switch statement");
1924 else if (success == 2)
1926 error ("duplicate case value");
1927 error_with_decl (duplicate, "this is the first entry for that value");
1929 else if (success == 3)
1930 warning ("case value out of range");
1931 else if (success == 5)
1932 error ("case label within scope of cleanup or variable array");
1934 position_after_white_space (); }
1935 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1936 { register tree value1 = check_case_value ($2);
1937 register tree value2 = check_case_value ($4);
1939 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1943 if (value1 != error_mark_node && value2 != error_mark_node)
1946 int success = pushcase_range (value1, value2,
1947 convert_and_check, label,
1950 error ("case label not within a switch statement");
1951 else if (success == 2)
1953 error ("duplicate case value");
1954 error_with_decl (duplicate, "this is the first entry for that value");
1956 else if (success == 3)
1957 warning ("case value out of range");
1958 else if (success == 4)
1959 warning ("empty case range");
1960 else if (success == 5)
1961 error ("case label within scope of cleanup or variable array");
1963 position_after_white_space (); }
1968 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1969 int success = pushcase (NULL_TREE, 0, label, &duplicate);
1972 error ("default label not within a switch statement");
1973 else if (success == 2)
1975 error ("multiple default labels in one switch");
1976 error_with_decl (duplicate, "this is the first default label");
1978 position_after_white_space (); }
1980 { tree label = define_label (input_filename, lineno, $1);
1984 expand_label (label);
1985 position_after_white_space (); }
1988 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
1992 { emit_line_note (input_filename, lineno);
1995 { emit_line_note (input_filename, lineno); }
2004 /* These are the operands other than the first string and colon
2005 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2006 asm_operands: /* empty */
2008 | nonnull_asm_operands
2011 nonnull_asm_operands:
2013 | nonnull_asm_operands ',' asm_operand
2014 { $$ = chainon ($1, $3); }
2019 { $$ = build_tree_list ($1, $3); }
2024 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2025 | asm_clobbers ',' string
2026 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2029 /* This is what appears inside the parens in a function declarator.
2030 Its value is a list of ..._TYPE nodes. */
2033 clear_parm_order ();
2034 declare_parm_level (0); }
2037 parmlist_tags_warning ();
2038 poplevel (0, 0, 0); }
2046 pedwarn ("ANSI C forbids forward parameter declarations");
2047 /* Mark the forward decls as such. */
2048 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2049 TREE_ASM_WRITTEN (parm) = 1;
2050 clear_parm_order (); }
2054 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2057 /* This is what appears inside the parens in a function declarator.
2058 Is value is represented in the format that grokdeclarator expects. */
2059 parmlist_2: /* empty */
2060 { $$ = get_parm_info (0); }
2062 { $$ = get_parm_info (0);
2063 /* Gcc used to allow this as an extension. However, it does
2064 not work for all targets, and thus has been disabled.
2065 Also, since func (...) and func () are indistinguishable,
2066 it caused problems with the code in expand_builtin which
2067 tries to verify that BUILT_IN_NEXT_ARG is being used
2069 error ("ANSI C requires a named argument before `...'");
2072 { $$ = get_parm_info (1); }
2073 | parms ',' ELLIPSIS
2074 { $$ = get_parm_info (0); }
2079 { push_parm_decl ($1); }
2081 { push_parm_decl ($3); }
2084 /* A single parameter declaration or parameter type name,
2085 as found in a parmlist. */
2087 typed_declspecs parm_declarator
2088 { $$ = build_tree_list ($1, $2) ; }
2089 | typed_declspecs notype_declarator
2090 { $$ = build_tree_list ($1, $2) ; }
2091 | typed_declspecs absdcl
2092 { $$ = build_tree_list ($1, $2); }
2093 | declmods notype_declarator
2094 { $$ = build_tree_list ($1, $2) ; }
2096 { $$ = build_tree_list ($1, $2); }
2099 /* This is used in a function definition
2100 where either a parmlist or an identifier list is ok.
2101 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2102 parmlist_or_identifiers:
2104 clear_parm_order ();
2105 declare_parm_level (1); }
2106 parmlist_or_identifiers_1
2108 parmlist_tags_warning ();
2109 poplevel (0, 0, 0); }
2112 parmlist_or_identifiers_1:
2116 for (t = $1; t; t = TREE_CHAIN (t))
2117 if (TREE_VALUE (t) == NULL_TREE)
2118 error ("`...' in old-style identifier list");
2119 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2122 /* A nonempty list of identifiers. */
2125 { $$ = build_tree_list (NULL_TREE, $1); }
2126 | identifiers ',' IDENTIFIER
2127 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2130 /* A nonempty list of identifiers, including typenames. */
2131 identifiers_or_typenames:
2133 { $$ = build_tree_list (NULL_TREE, $1); }
2134 | identifiers_or_typenames ',' identifier
2135 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2139 /* Objective-C productions. */
2149 if (objc_implementation_context)
2151 finish_class (objc_implementation_context);
2152 objc_ivar_chain = NULL_TREE;
2153 objc_implementation_context = NULL_TREE;
2156 warning ("`@end' must appear in an implementation context");
2160 /* A nonempty list of identifiers. */
2163 { $$ = build_tree_list (NULL_TREE, $1); }
2164 | identifier_list ',' identifier
2165 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2169 CLASS identifier_list ';'
2171 objc_declare_class ($2);
2175 ALIAS identifier identifier ';'
2177 objc_declare_alias ($2, $3);
2181 INTERFACE identifier protocolrefs '{'
2183 objc_interface_context = objc_ivar_context
2184 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2185 objc_public_flag = 0;
2189 continue_class (objc_interface_context);
2194 finish_class (objc_interface_context);
2195 objc_interface_context = NULL_TREE;
2198 | INTERFACE identifier protocolrefs
2200 objc_interface_context
2201 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2202 continue_class (objc_interface_context);
2207 finish_class (objc_interface_context);
2208 objc_interface_context = NULL_TREE;
2211 | INTERFACE identifier ':' identifier protocolrefs '{'
2213 objc_interface_context = objc_ivar_context
2214 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2215 objc_public_flag = 0;
2219 continue_class (objc_interface_context);
2224 finish_class (objc_interface_context);
2225 objc_interface_context = NULL_TREE;
2228 | INTERFACE identifier ':' identifier protocolrefs
2230 objc_interface_context
2231 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2232 continue_class (objc_interface_context);
2237 finish_class (objc_interface_context);
2238 objc_interface_context = NULL_TREE;
2241 | IMPLEMENTATION identifier '{'
2243 objc_implementation_context = objc_ivar_context
2244 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2245 objc_public_flag = 0;
2250 = continue_class (objc_implementation_context);
2253 | IMPLEMENTATION identifier
2255 objc_implementation_context
2256 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2258 = continue_class (objc_implementation_context);
2261 | IMPLEMENTATION identifier ':' identifier '{'
2263 objc_implementation_context = objc_ivar_context
2264 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2265 objc_public_flag = 0;
2270 = continue_class (objc_implementation_context);
2273 | IMPLEMENTATION identifier ':' identifier
2275 objc_implementation_context
2276 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2278 = continue_class (objc_implementation_context);
2281 | INTERFACE identifier '(' identifier ')' protocolrefs
2283 objc_interface_context
2284 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2285 continue_class (objc_interface_context);
2290 finish_class (objc_interface_context);
2291 objc_interface_context = NULL_TREE;
2294 | IMPLEMENTATION identifier '(' identifier ')'
2296 objc_implementation_context
2297 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2299 = continue_class (objc_implementation_context);
2304 PROTOCOL identifier protocolrefs
2306 remember_protocol_qualifiers ();
2307 objc_interface_context
2308 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2312 forget_protocol_qualifiers();
2313 finish_protocol(objc_interface_context);
2314 objc_interface_context = NULL_TREE;
2323 | ARITHCOMPARE identifier_list ARITHCOMPARE
2325 if ($1 == LT_EXPR && $3 == GT_EXPR)
2333 ivar_decl_list visibility_spec ivar_decls
2338 PRIVATE { objc_public_flag = 2; }
2339 | PROTECTED { objc_public_flag = 0; }
2340 | PUBLIC { objc_public_flag = 1; }
2348 | ivar_decls ivar_decl ';'
2352 pedwarn ("extra semicolon in struct or union specified");
2357 /* There is a shift-reduce conflict here, because `components' may
2358 start with a `typename'. It happens that shifting (the default resolution)
2359 does the right thing, because it treats the `typename' as part of
2360 a `typed_typespecs'.
2362 It is possible that this same technique would allow the distinction
2363 between `notype_initdecls' and `initdecls' to be eliminated.
2364 But I am being cautious and not trying it. */
2367 typed_typespecs setspecs ivars
2370 resume_momentary ($2);
2372 | nonempty_type_quals setspecs ivars
2375 resume_momentary ($2);
2385 | ivars ',' ivar_declarator
2391 $$ = add_instance_variable (objc_ivar_context,
2393 $1, current_declspecs,
2396 | declarator ':' expr_no_commas
2398 $$ = add_instance_variable (objc_ivar_context,
2400 $1, current_declspecs, $3);
2402 | ':' expr_no_commas
2404 $$ = add_instance_variable (objc_ivar_context,
2407 current_declspecs, $2);
2414 remember_protocol_qualifiers ();
2415 if (objc_implementation_context)
2416 objc_inherit_code = CLASS_METHOD_DECL;
2418 fatal ("method definition not in class context");
2422 forget_protocol_qualifiers ();
2423 add_class_method (objc_implementation_context, $3);
2424 start_method_def ($3);
2425 objc_method_context = $3;
2429 continue_method_def ();
2433 finish_method_def ();
2434 objc_method_context = NULL_TREE;
2439 remember_protocol_qualifiers ();
2440 if (objc_implementation_context)
2441 objc_inherit_code = INSTANCE_METHOD_DECL;
2443 fatal ("method definition not in class context");
2447 forget_protocol_qualifiers ();
2448 add_instance_method (objc_implementation_context, $3);
2449 start_method_def ($3);
2450 objc_method_context = $3;
2454 continue_method_def ();
2458 finish_method_def ();
2459 objc_method_context = NULL_TREE;
2463 /* the reason for the strange actions in this rule
2464 is so that notype_initdecls when reached via datadef
2465 can find a valid list of type and sc specs in $0. */
2469 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2472 methodprotolist2: /* eliminates a shift/reduce conflict */
2475 | methodprotolist2 methodproto
2476 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2487 objc_inherit_code = CLASS_METHOD_DECL;
2491 add_class_method (objc_interface_context, $3);
2497 objc_inherit_code = INSTANCE_METHOD_DECL;
2501 add_instance_method (objc_interface_context, $3);
2507 '(' typename ')' unaryselector
2509 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2514 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2517 | '(' typename ')' keywordselector optparmlist
2519 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2522 | keywordselector optparmlist
2524 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2528 /* "optarglist" assumes that start_method_def has already been called...
2529 if it is not, the "xdecls" will not be placed in the proper scope */
2536 /* to get around the following situation: "int foo (int a) int b; {}" that
2537 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2552 typed_declspecs setspecs myparms ';'
2553 { resume_momentary ($2); }
2554 | typed_declspecs ';'
2555 { shadow_tag ($1); }
2557 { pedwarn ("empty declaration"); }
2562 { push_parm_decl ($1); }
2563 | myparms ',' myparm
2564 { push_parm_decl ($3); }
2567 /* A single parameter declaration or parameter type name,
2568 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2572 { $$ = build_tree_list (current_declspecs, $1) ; }
2574 { $$ = build_tree_list (current_declspecs, $1) ; }
2576 { $$ = build_tree_list (current_declspecs, $1) ; }
2586 /* oh what a kludge! */
2595 /* returns a tree list node generated by get_parm_info */
2608 | keywordselector keyworddecl
2610 $$ = chainon ($1, $2);
2622 ENUM { $$ = get_identifier (token_buffer); }
2623 | STRUCT { $$ = get_identifier (token_buffer); }
2624 | UNION { $$ = get_identifier (token_buffer); }
2625 | IF { $$ = get_identifier (token_buffer); }
2626 | ELSE { $$ = get_identifier (token_buffer); }
2627 | WHILE { $$ = get_identifier (token_buffer); }
2628 | DO { $$ = get_identifier (token_buffer); }
2629 | FOR { $$ = get_identifier (token_buffer); }
2630 | SWITCH { $$ = get_identifier (token_buffer); }
2631 | CASE { $$ = get_identifier (token_buffer); }
2632 | DEFAULT { $$ = get_identifier (token_buffer); }
2633 | BREAK { $$ = get_identifier (token_buffer); }
2634 | CONTINUE { $$ = get_identifier (token_buffer); }
2635 | RETURN { $$ = get_identifier (token_buffer); }
2636 | GOTO { $$ = get_identifier (token_buffer); }
2637 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2638 | SIZEOF { $$ = get_identifier (token_buffer); }
2639 | TYPEOF { $$ = get_identifier (token_buffer); }
2640 | ALIGNOF { $$ = get_identifier (token_buffer); }
2641 | TYPESPEC | TYPE_QUAL
2645 selector ':' '(' typename ')' identifier
2647 $$ = build_keyword_decl ($1, $4, $6);
2650 | selector ':' identifier
2652 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2655 | ':' '(' typename ')' identifier
2657 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2662 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2673 | keywordarglist keywordarg
2675 $$ = chainon ($1, $2);
2683 if (TREE_CHAIN ($1) == NULL_TREE)
2684 /* just return the expr., remove a level of indirection */
2685 $$ = TREE_VALUE ($1);
2687 /* we have a comma expr., we will collapse later */
2693 selector ':' keywordexpr
2695 $$ = build_tree_list ($1, $3);
2699 $$ = build_tree_list (NULL_TREE, $2);
2707 $$ = get_class_reference ($1);
2713 { objc_receiver_context = 1; }
2715 { objc_receiver_context = 0; }
2718 $$ = build_tree_list ($3, $5);
2729 | keywordnamelist keywordname
2731 $$ = chainon ($1, $2);
2738 $$ = build_tree_list ($1, NULL_TREE);
2742 $$ = build_tree_list (NULL_TREE, NULL_TREE);
2747 SELECTOR '(' selectorarg ')'
2754 PROTOCOL '(' identifier ')'
2760 /* extension to support C-structures in the archiver */
2763 ENCODE '(' typename ')'
2765 $$ = groktypename ($3);