1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 88, 89, 92, 93, 1994 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 ALIGN
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");
267 /* In case there were missing closebraces,
268 get us back to the global binding level. */
269 while (! global_bindings_p ())
277 /* the reason for the strange actions in this rule
278 is so that notype_initdecls when reached via datadef
279 can find a valid list of type and sc specs in $0. */
282 {$<ttype>$ = NULL_TREE; } extdef
283 | extdefs {$<ttype>$ = NULL_TREE; } extdef
292 | ASM_KEYWORD '(' expr ')' ';'
294 if ((TREE_CODE ($3) == ADDR_EXPR
295 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
296 || TREE_CODE ($3) == STRING_CST)
299 error ("argument of `asm' is not a constant string"); }
303 setspecs notype_initdecls ';'
305 error ("ANSI C forbids data definition with no type or storage class");
306 else if (!flag_traditional)
307 warning ("data definition has no type or storage class"); }
308 | declmods setspecs notype_initdecls ';'
310 | typed_declspecs setspecs initdecls ';'
313 { pedwarn ("empty declaration"); }
314 | typed_declspecs ';'
320 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
324 typed_declspecs setspecs declarator
325 { if (! start_function ($1, $3, 0))
327 reinit_parse_for_function (); }
329 { store_parm_decls (); }
331 { finish_function (0); }
332 | typed_declspecs setspecs declarator error
334 | declmods setspecs notype_declarator
335 { if (! start_function ($1, $3, 0))
337 reinit_parse_for_function (); }
339 { store_parm_decls (); }
341 { finish_function (0); }
342 | declmods setspecs notype_declarator error
344 | setspecs notype_declarator
345 { if (! start_function (NULL_TREE, $2, 0))
347 reinit_parse_for_function (); }
349 { store_parm_decls (); }
351 { finish_function (0); }
352 | setspecs notype_declarator error
368 { $$ = NEGATE_EXPR; }
370 { $$ = CONVERT_EXPR; }
372 { $$ = PREINCREMENT_EXPR; }
374 { $$ = PREDECREMENT_EXPR; }
376 { $$ = BIT_NOT_EXPR; }
378 { $$ = TRUTH_NOT_EXPR; }
381 expr: nonnull_exprlist
382 { $$ = build_compound_expr ($1); }
393 { $$ = build_tree_list (NULL_TREE, $1); }
394 | nonnull_exprlist ',' expr_no_commas
395 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
400 | '*' cast_expr %prec UNARY
401 { $$ = build_indirect_ref ($2, "unary *"); }
402 /* __extension__ turns off -pedantic for following primary. */
404 { $<itype>1 = pedantic;
406 cast_expr %prec UNARY
408 pedantic = $<itype>1; }
409 | unop cast_expr %prec UNARY
410 { $$ = build_unary_op ($1, $2, 0);
411 overflow_warning ($$); }
412 /* Refer to the address of a label as a pointer. */
414 { tree label = lookup_label ($2);
416 $$ = null_pointer_node;
419 TREE_USED (label) = 1;
420 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
421 TREE_CONSTANT ($$) = 1;
424 /* This seems to be impossible on some machines, so let's turn it off.
425 You can use __builtin_next_arg to find the anonymous stack args.
427 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
428 $$ = error_mark_node;
429 if (TREE_VALUE (tree_last (types)) == void_type_node)
430 error ("`&...' used in function with fixed number of arguments");
434 pedwarn ("ANSI C forbids `&...'");
435 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
436 $$ = build_unary_op (ADDR_EXPR, $$, 0);
439 | SIZEOF unary_expr %prec UNARY
440 { if (TREE_CODE ($2) == COMPONENT_REF
441 && DECL_BIT_FIELD (TREE_OPERAND ($2, 1)))
442 error ("`sizeof' applied to a bit-field");
443 $$ = c_sizeof (TREE_TYPE ($2)); }
444 | SIZEOF '(' typename ')' %prec HYPERUNARY
445 { $$ = c_sizeof (groktypename ($3)); }
446 | ALIGNOF unary_expr %prec UNARY
447 { $$ = c_alignof_expr ($2); }
448 | ALIGNOF '(' typename ')' %prec HYPERUNARY
449 { $$ = c_alignof (groktypename ($3)); }
450 | REALPART cast_expr %prec UNARY
451 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
452 | IMAGPART cast_expr %prec UNARY
453 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
458 | '(' typename ')' cast_expr %prec UNARY
459 { tree type = groktypename ($2);
460 $$ = build_c_cast (type, $4); }
461 | '(' typename ')' '{'
462 { start_init (NULL_TREE, NULL, 0);
463 $2 = groktypename ($2);
464 really_start_incremental_init ($2); }
465 initlist_maybe_comma '}' %prec UNARY
467 tree result = pop_init_level (0);
472 pedwarn ("ANSI C forbids constructor expressions");
473 if (TYPE_NAME (type) != 0)
475 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
476 name = IDENTIFIER_POINTER (TYPE_NAME (type));
478 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
483 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
485 int failure = complete_array_type (type, $$, 1);
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 '%' expr_no_commas
503 { $$ = parser_build_binary_op ($2, $1, $3); }
504 | expr_no_commas LSHIFT expr_no_commas
505 { $$ = parser_build_binary_op ($2, $1, $3); }
506 | expr_no_commas RSHIFT expr_no_commas
507 { $$ = parser_build_binary_op ($2, $1, $3); }
508 | expr_no_commas ARITHCOMPARE expr_no_commas
509 { $$ = parser_build_binary_op ($2, $1, $3); }
510 | expr_no_commas EQCOMPARE 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 '^' expr_no_commas
517 { $$ = parser_build_binary_op ($2, $1, $3); }
518 | expr_no_commas ANDAND expr_no_commas
519 { $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
520 | expr_no_commas OROR expr_no_commas
521 { $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
522 | expr_no_commas '?' xexpr ':' expr_no_commas
523 { $$ = build_conditional_expr ($1, $3, $5); }
524 | expr_no_commas '=' expr_no_commas
525 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
526 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
527 | expr_no_commas ASSIGN expr_no_commas
528 { $$ = build_modify_expr ($1, $2, $3);
529 /* This inhibits warnings in truthvalue_conversion. */
530 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
537 if (!$$ || $$ == error_mark_node)
539 if (yychar == YYEMPTY)
546 if (objc_receiver_context
547 && ! (objc_receiver_context
548 && strcmp (IDENTIFIER_POINTER ($1), "super")))
549 /* we have a message to super */
550 $$ = get_super_receiver ();
551 else if (objc_method_context
552 && (decl = is_ivar (objc_ivar_chain, $1)))
554 if (is_private (decl))
555 $$ = error_mark_node;
557 $$ = build_ivar_reference ($1);
562 /* Ordinary implicit function declaration. */
563 $$ = implicitly_declare ($1);
564 assemble_external ($$);
568 else if (current_function_decl == 0)
570 error ("`%s' undeclared here (not in a function)",
571 IDENTIFIER_POINTER ($1));
572 $$ = error_mark_node;
579 if (objc_receiver_context
580 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
581 /* we have a message to super */
582 $$ = get_super_receiver ();
583 else if (objc_method_context
584 && (decl = is_ivar (objc_ivar_chain, $1)))
586 if (is_private (decl))
587 $$ = error_mark_node;
589 $$ = build_ivar_reference ($1);
594 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
595 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
597 error ("`%s' undeclared (first use this function)",
598 IDENTIFIER_POINTER ($1));
600 if (! undeclared_variable_notice)
602 error ("(Each undeclared identifier is reported only once");
603 error ("for each function it appears in.)");
604 undeclared_variable_notice = 1;
607 $$ = error_mark_node;
608 /* Prevent repeated error messages. */
609 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
610 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
614 else if (TREE_TYPE ($$) == error_mark_node)
615 $$ = error_mark_node;
616 else if (C_DECL_ANTICIPATED ($$))
618 /* The first time we see a build-in function used,
619 if it has not been declared. */
620 C_DECL_ANTICIPATED ($$) = 0;
621 if (yychar == YYEMPTY)
625 /* Omit the implicit declaration we
626 would ordinarily do, so we don't lose
627 the actual built in type.
628 But print a diagnostic for the mismatch. */
630 if (objc_method_context
631 && is_ivar (objc_ivar_chain, $1))
632 error ("Instance variable `%s' implicitly declared as function",
633 IDENTIFIER_POINTER (DECL_NAME ($$)));
636 if (TREE_CODE ($$) != FUNCTION_DECL)
637 error ("`%s' implicitly declared as function",
638 IDENTIFIER_POINTER (DECL_NAME ($$)));
639 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
640 != TYPE_MODE (integer_type_node))
641 && (TREE_TYPE (TREE_TYPE ($$))
643 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
644 IDENTIFIER_POINTER (DECL_NAME ($$)));
645 /* If it really returns void, change that to int. */
646 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
648 = build_function_type (integer_type_node,
649 TYPE_ARG_TYPES (TREE_TYPE ($$)));
652 pedwarn ("built-in function `%s' used without declaration",
653 IDENTIFIER_POINTER (DECL_NAME ($$)));
655 /* Do what we would ordinarily do when a fn is used. */
656 assemble_external ($$);
661 assemble_external ($$);
664 /* we have a definition - still check if iVariable */
666 if (!objc_receiver_context
667 || (objc_receiver_context
668 && strcmp (IDENTIFIER_POINTER ($1), "super")))
672 if (objc_method_context
673 && (decl = is_ivar (objc_ivar_chain, $1)))
675 if (IDENTIFIER_LOCAL_VALUE ($1))
676 warning ("local declaration of `%s' hides instance variable",
677 IDENTIFIER_POINTER ($1));
680 if (is_private (decl))
681 $$ = error_mark_node;
683 $$ = build_ivar_reference ($1);
687 else /* we have a message to super */
688 $$ = get_super_receiver ();
692 if (TREE_CODE ($$) == CONST_DECL)
694 $$ = DECL_INITIAL ($$);
695 /* This is to prevent an enum whose value is 0
696 from being considered a null pointer constant. */
697 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
698 TREE_CONSTANT ($$) = 1;
703 { $$ = combine_strings ($1); }
705 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
706 if (class == 'e' || class == '1'
707 || class == '2' || class == '<')
708 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
711 { $$ = error_mark_node; }
713 { if (current_function_decl == 0)
715 error ("braced-group within expression allowed only inside a function");
718 /* We must force a BLOCK for this level
719 so that, if it is not expanded later,
720 there is a way to turn off the entire subtree of blocks
721 that are contained in it. */
723 push_iterator_stack ();
725 $<ttype>$ = expand_start_stmt_expr (); }
729 pedwarn ("ANSI C forbids braced-groups within expressions");
730 pop_iterator_stack ();
732 rtl_exp = expand_end_stmt_expr ($<ttype>2);
733 /* The statements have side effects, so the group does. */
734 TREE_SIDE_EFFECTS (rtl_exp) = 1;
736 if (TREE_CODE ($3) == BLOCK)
738 /* Make a BIND_EXPR for the BLOCK already made. */
739 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
740 NULL_TREE, rtl_exp, $3);
741 /* Remove the block from the tree at this point.
742 It gets put back at the proper place
743 when the BIND_EXPR is expanded. */
749 | primary '(' exprlist ')' %prec '.'
750 { $$ = build_function_call ($1, $3); }
751 | primary '[' expr ']' %prec '.'
752 { $$ = build_array_ref ($1, $3); }
753 | primary '.' identifier
756 if (doing_objc_thang)
758 if (is_public ($1, $3))
759 $$ = build_component_ref ($1, $3);
761 $$ = error_mark_node;
765 $$ = build_component_ref ($1, $3);
767 | primary POINTSAT identifier
769 tree expr = build_indirect_ref ($1, "->");
772 if (doing_objc_thang)
774 if (is_public (expr, $3))
775 $$ = build_component_ref (expr, $3);
777 $$ = error_mark_node;
781 $$ = build_component_ref (expr, $3);
784 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
786 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
789 { $$ = build_message_expr ($1); }
791 { $$ = build_selector_expr ($1); }
793 { $$ = build_protocol_expr ($1); }
795 { $$ = build_encode_expr ($1); }
797 { $$ = build_objc_string_object ($1); }
801 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
805 { $$ = chainon ($1, $2); }
809 /* Produces an OBJC_STRING_CST with prehaps more OBJC_STRING_CSTs chained
813 | objc_string OBJC_STRING
814 { $$ = chainon ($1, $2); }
822 /* ... is used here to indicate a varargs function. */
825 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
828 /* The following are analogous to lineno_decl, decls and decl
829 except that they do not allow nested functions.
830 They are used for old-style parm decls. */
832 save_filename save_lineno datadecl
839 | datadecls lineno_datadecl
840 | lineno_datadecl errstmt
844 typed_declspecs setspecs initdecls ';'
845 { current_declspecs = TREE_VALUE (declspec_stack);
846 declspec_stack = TREE_CHAIN (declspec_stack);
847 resume_momentary ($2); }
848 | declmods setspecs notype_initdecls ';'
849 { current_declspecs = TREE_VALUE (declspec_stack);
850 declspec_stack = TREE_CHAIN (declspec_stack);
851 resume_momentary ($2); }
852 | typed_declspecs ';'
853 { shadow_tag_warned ($1, 1);
854 pedwarn ("empty declaration"); }
856 { pedwarn ("empty declaration"); }
859 /* This combination which saves a lineno before a decl
860 is the normal thing to use, rather than decl itself.
861 This is to avoid shift/reduce conflicts in contexts
862 where statement labels are allowed. */
864 save_filename save_lineno decl
872 | lineno_decl errstmt
875 /* records the type and storage class specs to use for processing
876 the declarators that follow.
877 Maintains a stack of outer-level values of current_declspecs,
878 for the sake of parm declarations nested in function declarators. */
879 setspecs: /* empty */
880 { $$ = suspend_momentary ();
881 pending_xref_error ();
882 declspec_stack = tree_cons (NULL_TREE, current_declspecs,
884 current_declspecs = $<ttype>0; }
888 typed_declspecs setspecs initdecls ';'
889 { current_declspecs = TREE_VALUE (declspec_stack);
890 declspec_stack = TREE_CHAIN (declspec_stack);
891 resume_momentary ($2); }
892 | declmods setspecs notype_initdecls ';'
893 { current_declspecs = TREE_VALUE (declspec_stack);
894 declspec_stack = TREE_CHAIN (declspec_stack);
895 resume_momentary ($2); }
896 | typed_declspecs setspecs nested_function
897 { current_declspecs = TREE_VALUE (declspec_stack);
898 declspec_stack = TREE_CHAIN (declspec_stack);
899 resume_momentary ($2); }
900 | declmods setspecs notype_nested_function
901 { current_declspecs = TREE_VALUE (declspec_stack);
902 declspec_stack = TREE_CHAIN (declspec_stack);
903 resume_momentary ($2); }
904 | typed_declspecs ';'
907 { pedwarn ("empty declaration"); }
910 /* Declspecs which contain at least one type specifier or typedef name.
911 (Just `const' or `volatile' is not enough.)
912 A typedef'd name following these is taken as a name to be declared. */
915 typespec reserved_declspecs
916 { $$ = tree_cons (NULL_TREE, $1, $2); }
917 | declmods typespec reserved_declspecs
918 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
921 reserved_declspecs: /* empty */
923 | reserved_declspecs typespecqual_reserved
924 { $$ = tree_cons (NULL_TREE, $2, $1); }
925 | reserved_declspecs SCSPEC
926 { if (extra_warnings)
927 warning ("`%s' is not at beginning of declaration",
928 IDENTIFIER_POINTER ($2));
929 $$ = tree_cons (NULL_TREE, $2, $1); }
932 /* List of just storage classes and type modifiers.
933 A declaration can start with just this, but then it cannot be used
934 to redeclare a typedef-name. */
938 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
939 TREE_STATIC ($$) = 1; }
941 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
943 { $$ = tree_cons (NULL_TREE, $2, $1);
944 TREE_STATIC ($$) = 1; }
946 { if (extra_warnings && TREE_STATIC ($1))
947 warning ("`%s' is not at beginning of declaration",
948 IDENTIFIER_POINTER ($2));
949 $$ = tree_cons (NULL_TREE, $2, $1);
950 TREE_STATIC ($$) = TREE_STATIC ($1); }
954 /* Used instead of declspecs where storage classes are not allowed
955 (that is, for typenames and structure components).
956 Don't accept a typedef-name if anything but a modifier precedes it. */
959 typespec reserved_typespecquals
960 { $$ = tree_cons (NULL_TREE, $1, $2); }
961 | nonempty_type_quals typespec reserved_typespecquals
962 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
965 reserved_typespecquals: /* empty */
967 | reserved_typespecquals typespecqual_reserved
968 { $$ = tree_cons (NULL_TREE, $2, $1); }
971 /* A typespec (but not a type qualifier).
972 Once we have seen one of these in a declaration,
973 if a typedef name appears then it is being redeclared. */
978 { /* For a typedef name, record the meaning, not the name.
979 In case of `foo foo, bar;'. */
980 $$ = lookup_name ($1); }
982 | CLASSNAME protocolrefs
983 { $$ = get_static_reference ($1, $2); }
984 | OBJECTNAME protocolrefs
985 { $$ = get_object_reference ($2); }
987 | TYPEOF '(' expr ')'
988 { $$ = TREE_TYPE ($3); }
989 | TYPEOF '(' typename ')'
990 { $$ = groktypename ($3); }
993 /* A typespec that is a reserved word, or a type qualifier. */
995 typespecqual_reserved: TYPESPEC
1002 | initdecls ',' initdcl
1007 | notype_initdecls ',' initdcl
1013 | ASM_KEYWORD '(' string ')'
1014 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1020 declarator maybeasm maybe_attribute '='
1021 { $<ttype>$ = start_decl ($1, current_declspecs, 1);
1022 decl_attributes ($<ttype>$, $3);
1023 start_init ($<ttype>$, $2, global_bindings_p ()); }
1025 /* Note how the declaration of the variable is in effect while its init is parsed! */
1027 decl_attributes ($<ttype>5, $3);
1028 finish_decl ($<ttype>5, $6, $2); }
1029 | declarator maybeasm maybe_attribute
1030 { tree d = start_decl ($1, current_declspecs, 0);
1031 decl_attributes (d, $3);
1032 finish_decl (d, NULL_TREE, $2); }
1036 notype_declarator maybeasm maybe_attribute '='
1037 { $<ttype>$ = start_decl ($1, current_declspecs, 1);
1038 decl_attributes ($<ttype>$, $3);
1039 start_init ($<ttype>$, $2, global_bindings_p ()); }
1041 /* Note how the declaration of the variable is in effect while its init is parsed! */
1043 decl_attributes ($<ttype>5, $3);
1044 finish_decl ($<ttype>5, $6, $2); }
1045 | notype_declarator maybeasm maybe_attribute
1046 { tree d = start_decl ($1, current_declspecs, 0);
1047 decl_attributes (d, $3);
1048 finish_decl (d, NULL_TREE, $2); }
1050 /* the * rules are dummies to accept the Apollo extended syntax
1051 so that the header files compile. */
1062 | attributes attribute
1063 { $$ = chainon ($1, $2); }
1067 ATTRIBUTE '(' '(' attribute_list ')' ')'
1073 { $$ = build_tree_list (NULL_TREE, $1); }
1074 | attribute_list ',' attrib
1075 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
1083 | any_word '(' IDENTIFIER ')'
1084 { $$ = tree_cons ($1, NULL_TREE,
1085 build_tree_list (NULL_TREE, $3)); }
1086 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1087 { $$ = tree_cons ($1, NULL_TREE,
1088 tree_cons (NULL_TREE, $3, $5)); }
1089 | any_word '(' nonnull_exprlist ')'
1090 { $$ = tree_cons ($1, NULL_TREE, $3); }
1093 /* This still leaves out most reserved keywords,
1094 shouldn't we include them? */
1103 /* Initializers. `init' is the entry point. */
1108 { really_start_incremental_init (NULL_TREE);
1109 /* Note that the call to clear_momentary
1110 is in process_init_element. */
1111 push_momentary (); }
1112 initlist_maybe_comma '}'
1113 { $$ = pop_init_level (0);
1114 if ($$ == error_mark_node
1115 && ! (yychar == STRING || yychar == CONSTANT))
1118 pop_momentary_nofree (); }
1121 { $$ = error_mark_node; }
1124 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1125 initlist_maybe_comma:
1128 pedwarn ("ANSI C forbids empty initializer braces"); }
1129 | initlist1 maybecomma
1134 | initlist1 ',' initelt
1137 /* `initelt' is a single element of an initializer.
1138 It may use braces. */
1141 { process_init_element ($1); }
1143 { push_init_level (0); }
1144 initlist_maybe_comma '}'
1145 { process_init_element (pop_init_level (0)); }
1147 /* These are for labeled elements. The syntax for an array element
1148 initializer conflicts with the syntax for an Objective-C message,
1149 so don't include these productions in the Objective-C grammer. */
1151 | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1152 { set_init_index ($2, $4); }
1154 | '[' expr_no_commas ']' '='
1155 { set_init_index ($2, NULL_TREE); }
1157 | '[' expr_no_commas ']'
1158 { set_init_index ($2, NULL_TREE); }
1162 { set_init_label ($1); }
1164 | '.' identifier '='
1165 { set_init_label ($2); }
1171 { push_c_function_context ();
1172 if (! start_function (current_declspecs, $1, 1))
1174 pop_c_function_context ();
1177 reinit_parse_for_function ();
1178 store_parm_decls (); }
1179 /* This used to use compstmt_or_error.
1180 That caused a bug with input `f(g) int g {}',
1181 where the use of YYERROR1 above caused an error
1182 which then was handled by compstmt_or_error.
1183 There followed a repeated execution of that same rule,
1184 which called YYERROR1 again, and so on. */
1186 { finish_function (1);
1187 pop_c_function_context (); }
1190 notype_nested_function:
1192 { push_c_function_context ();
1193 if (! start_function (current_declspecs, $1, 1))
1195 pop_c_function_context ();
1198 reinit_parse_for_function ();
1199 store_parm_decls (); }
1200 /* This used to use compstmt_or_error.
1201 That caused a bug with input `f(g) int g {}',
1202 where the use of YYERROR1 above caused an error
1203 which then was handled by compstmt_or_error.
1204 There followed a repeated execution of that same rule,
1205 which called YYERROR1 again, and so on. */
1207 { finish_function (1);
1208 pop_c_function_context (); }
1211 /* Any kind of declarator (thus, all declarators allowed
1212 after an explicit typespec). */
1215 after_type_declarator
1219 /* A declarator that is allowed only after an explicit typespec. */
1221 after_type_declarator:
1222 '(' after_type_declarator ')'
1224 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1225 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1226 /* | after_type_declarator '(' error ')' %prec '.'
1227 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1228 poplevel (0, 0, 0); } */
1229 | after_type_declarator '[' expr ']' %prec '.'
1230 { $$ = build_nt (ARRAY_REF, $1, $3); }
1231 | after_type_declarator '[' ']' %prec '.'
1232 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1233 | '*' type_quals after_type_declarator %prec UNARY
1234 { $$ = make_pointer_declarator ($2, $3); }
1241 /* Kinds of declarator that can appear in a parameter list
1242 in addition to notype_declarator. This is like after_type_declarator
1243 but does not allow a typedef name in parentheses as an identifier
1244 (because it would conflict with a function with that typedef as arg). */
1247 parm_declarator '(' parmlist_or_identifiers %prec '.'
1248 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1249 /* | parm_declarator '(' error ')' %prec '.'
1250 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1251 poplevel (0, 0, 0); } */
1252 | parm_declarator '[' expr ']' %prec '.'
1253 { $$ = build_nt (ARRAY_REF, $1, $3); }
1254 | parm_declarator '[' ']' %prec '.'
1255 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1256 | '*' type_quals parm_declarator %prec UNARY
1257 { $$ = make_pointer_declarator ($2, $3); }
1261 /* A declarator allowed whether or not there has been
1262 an explicit typespec. These cannot redeclare a typedef-name. */
1265 notype_declarator '(' parmlist_or_identifiers %prec '.'
1266 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1267 /* | notype_declarator '(' error ')' %prec '.'
1268 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1269 poplevel (0, 0, 0); } */
1270 | '(' notype_declarator ')'
1272 | '*' type_quals notype_declarator %prec UNARY
1273 { $$ = make_pointer_declarator ($2, $3); }
1274 | notype_declarator '[' expr ']' %prec '.'
1275 { $$ = build_nt (ARRAY_REF, $1, $3); }
1276 | notype_declarator '[' ']' %prec '.'
1277 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1282 STRUCT identifier '{'
1283 { $$ = start_struct (RECORD_TYPE, $2);
1284 /* Start scope of tag before parsing components. */
1286 component_decl_list '}'
1287 { $$ = finish_struct ($<ttype>4, $5);
1288 /* Really define the structure. */
1290 | STRUCT '{' component_decl_list '}'
1291 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1294 { $$ = xref_tag (RECORD_TYPE, $2); }
1295 | UNION identifier '{'
1296 { $$ = start_struct (UNION_TYPE, $2); }
1297 component_decl_list '}'
1298 { $$ = finish_struct ($<ttype>4, $5); }
1299 | UNION '{' component_decl_list '}'
1300 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1303 { $$ = xref_tag (UNION_TYPE, $2); }
1304 | ENUM identifier '{'
1305 { $<itype>3 = suspend_momentary ();
1306 $$ = start_enum ($2); }
1307 enumlist maybecomma_warn '}'
1308 { $$ = finish_enum ($<ttype>4, nreverse ($5));
1309 resume_momentary ($<itype>3); }
1311 { $<itype>2 = suspend_momentary ();
1312 $$ = start_enum (NULL_TREE); }
1313 enumlist maybecomma_warn '}'
1314 { $$ = finish_enum ($<ttype>3, nreverse ($4));
1315 resume_momentary ($<itype>2); }
1317 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1328 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1331 component_decl_list:
1332 component_decl_list2
1334 | component_decl_list2 component_decl
1335 { $$ = chainon ($1, $2);
1336 pedwarn ("no semicolon at end of struct or union"); }
1339 component_decl_list2: /* empty */
1341 | component_decl_list2 component_decl ';'
1342 { $$ = chainon ($1, $2); }
1343 | component_decl_list2 ';'
1345 pedwarn ("extra semicolon in struct or union specified"); }
1347 /* foo(sizeof(struct{ @defs(ClassName)})); */
1348 | DEFS '(' CLASSNAME ')'
1350 tree interface = lookup_interface ($3);
1353 $$ = get_class_ivars (interface);
1356 error ("Cannot find interface declaration for `%s'",
1357 IDENTIFIER_POINTER ($3));
1364 /* There is a shift-reduce conflict here, because `components' may
1365 start with a `typename'. It happens that shifting (the default resolution)
1366 does the right thing, because it treats the `typename' as part of
1367 a `typed_typespecs'.
1369 It is possible that this same technique would allow the distinction
1370 between `notype_initdecls' and `initdecls' to be eliminated.
1371 But I am being cautious and not trying it. */
1374 typed_typespecs setspecs components
1376 current_declspecs = TREE_VALUE (declspec_stack);
1377 declspec_stack = TREE_CHAIN (declspec_stack);
1378 resume_momentary ($2); }
1381 pedwarn ("ANSI C forbids member declarations with no members");
1384 | nonempty_type_quals setspecs components
1386 current_declspecs = TREE_VALUE (declspec_stack);
1387 declspec_stack = TREE_CHAIN (declspec_stack);
1388 resume_momentary ($2); }
1389 | nonempty_type_quals
1391 pedwarn ("ANSI C forbids member declarations with no members");
1399 component_declarator
1400 | components ',' component_declarator
1401 { $$ = chainon ($1, $3); }
1404 component_declarator:
1405 save_filename save_lineno declarator maybe_attribute
1406 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1407 decl_attributes ($$, $4); }
1408 | save_filename save_lineno
1409 declarator ':' expr_no_commas maybe_attribute
1410 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1411 decl_attributes ($$, $6); }
1412 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1413 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1414 decl_attributes ($$, $5); }
1417 /* We chain the enumerators in reverse order.
1418 They are put in forward order where enumlist is used.
1419 (The order used to be significant, but no longer is so.
1420 However, we still maintain the order, just to be clean.) */
1424 | enumlist ',' enumerator
1425 { $$ = chainon ($3, $1); }
1427 { $$ = error_mark_node; }
1433 { $$ = build_enumerator ($1, NULL_TREE); }
1434 | identifier '=' expr_no_commas
1435 { $$ = build_enumerator ($1, $3); }
1439 typed_typespecs absdcl
1440 { $$ = build_tree_list ($1, $2); }
1441 | nonempty_type_quals absdcl
1442 { $$ = build_tree_list ($1, $2); }
1445 absdcl: /* an absolute declarator */
1451 nonempty_type_quals:
1453 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1454 | nonempty_type_quals TYPE_QUAL
1455 { $$ = tree_cons (NULL_TREE, $2, $1); }
1461 | type_quals TYPE_QUAL
1462 { $$ = tree_cons (NULL_TREE, $2, $1); }
1465 absdcl1: /* a nonempty absolute declarator */
1468 /* `(typedef)1' is `int'. */
1469 | '*' type_quals absdcl1 %prec UNARY
1470 { $$ = make_pointer_declarator ($2, $3); }
1471 | '*' type_quals %prec UNARY
1472 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1473 | absdcl1 '(' parmlist %prec '.'
1474 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1475 | absdcl1 '[' expr ']' %prec '.'
1476 { $$ = build_nt (ARRAY_REF, $1, $3); }
1477 | absdcl1 '[' ']' %prec '.'
1478 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1479 | '(' parmlist %prec '.'
1480 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1481 | '[' expr ']' %prec '.'
1482 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1484 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1487 /* at least one statement, the first of which parses without error. */
1488 /* stmts is used only after decls, so an invalid first statement
1489 is actually regarded as an invalid decl and part of the decls. */
1492 lineno_stmt_or_label
1493 | stmts lineno_stmt_or_label
1505 pushlevel: /* empty */
1506 { emit_line_note (input_filename, lineno);
1510 expand_start_bindings (0);
1512 if (objc_method_context)
1518 /* Read zero or more forward-declarations for labels
1519 that nested functions can jump to. */
1524 pedwarn ("ANSI C forbids label declarations"); }
1529 | label_decls label_decl
1533 LABEL identifiers_or_typenames ';'
1535 for (link = $2; link; link = TREE_CHAIN (link))
1537 tree label = shadow_label (TREE_VALUE (link));
1538 C_DECLARED_LABEL_FLAG (label) = 1;
1539 declare_nonlocal_label (label);
1544 /* This is the body of a function definition.
1545 It causes syntax errors to ignore to the next openbrace. */
1553 { $$ = convert (void_type_node, integer_zero_node); }
1554 | '{' pushlevel maybe_label_decls decls xstmts '}'
1555 { emit_line_note (input_filename, lineno);
1556 expand_end_bindings (getdecls (), 1, 0);
1557 $$ = poplevel (1, 1, 0);
1558 if (yychar == CONSTANT || yychar == STRING)
1559 pop_momentary_nofree ();
1562 | '{' pushlevel maybe_label_decls error '}'
1563 { emit_line_note (input_filename, lineno);
1564 expand_end_bindings (getdecls (), kept_level_p (), 0);
1565 $$ = poplevel (kept_level_p (), 0, 0);
1566 if (yychar == CONSTANT || yychar == STRING)
1567 pop_momentary_nofree ();
1570 | '{' pushlevel maybe_label_decls stmts '}'
1571 { emit_line_note (input_filename, lineno);
1572 expand_end_bindings (getdecls (), kept_level_p (), 0);
1573 $$ = poplevel (kept_level_p (), 0, 0);
1574 if (yychar == CONSTANT || yychar == STRING)
1575 pop_momentary_nofree ();
1580 /* Value is number of statements counted as of the closeparen. */
1582 if_prefix lineno_labeled_stmt
1583 /* Make sure expand_end_cond is run once
1584 for each call to expand_start_cond.
1585 Otherwise a crash is likely. */
1591 { emit_line_note ($<filename>-1, $<lineno>0);
1592 expand_start_cond (truthvalue_conversion ($3), 0);
1593 $<itype>$ = stmt_count;
1594 if_stmt_file = $<filename>-1;
1595 if_stmt_line = $<lineno>0;
1596 position_after_white_space (); }
1599 /* This is a subroutine of stmt.
1600 It is used twice, once for valid DO statements
1601 and once for catching errors in parsing the end test. */
1605 emit_line_note ($<filename>-1, $<lineno>0);
1606 /* See comment in `while' alternative, above. */
1608 expand_start_loop_continue_elsewhere (1);
1609 position_after_white_space (); }
1610 lineno_labeled_stmt WHILE
1611 { expand_loop_continue_here (); }
1615 { $$ = input_filename; }
1622 lineno_labeled_stmt:
1623 save_filename save_lineno stmt
1625 /* | save_filename save_lineno error
1628 | save_filename save_lineno label lineno_labeled_stmt
1632 lineno_stmt_or_label:
1633 save_filename save_lineno stmt_or_label
1641 position_after_white_space ();
1642 next = getc (finput);
1643 ungetc (next, finput);
1644 if (pedantic && next == '}')
1645 pedwarn ("ANSI C forbids label at end of compound statement");
1649 /* Parse a single real statement, not including any labels. */
1656 emit_line_note ($<filename>-1, $<lineno>0);
1657 /* It appears that this should not be done--that a non-lvalue array
1658 shouldn't get an error if the value isn't used.
1659 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1660 if it appears as a top-level expression,
1661 but says nothing about non-lvalue arrays. */
1663 /* Call default_conversion to get an error
1664 on referring to a register array if pedantic. */
1665 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1666 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1667 $1 = default_conversion ($1);
1669 iterator_expand ($1);
1670 clear_momentary (); }
1672 { expand_start_else ();
1673 $<itype>1 = stmt_count;
1674 position_after_white_space (); }
1676 { expand_end_cond ();
1677 if (extra_warnings && stmt_count == $<itype>1)
1678 warning ("empty body in an else-statement"); }
1679 | simple_if %prec IF
1680 { expand_end_cond ();
1681 /* This warning is here instead of in simple_if, because we
1682 do not want a warning if an empty if is followed by an
1684 if (extra_warnings && stmt_count == $<itype>1)
1685 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1686 "empty body in an if-statement"); }
1687 /* Make sure expand_end_cond is run once
1688 for each call to expand_start_cond.
1689 Otherwise a crash is likely. */
1690 | simple_if ELSE error
1691 { expand_end_cond (); }
1694 emit_line_note ($<filename>-1, $<lineno>0);
1695 /* The emit_nop used to come before emit_line_note,
1696 but that made the nop seem like part of the preceding line.
1697 And that was confusing when the preceding line was
1698 inside of an if statement and was not really executed.
1699 I think it ought to work to put the nop after the line number.
1700 We will see. --rms, July 15, 1991. */
1703 { /* Don't start the loop till we have succeeded
1704 in parsing the end test. This is to make sure
1705 that we end every loop we start. */
1706 expand_start_loop (1);
1707 emit_line_note (input_filename, lineno);
1708 expand_exit_loop_if_false (NULL_PTR,
1709 truthvalue_conversion ($4));
1710 position_after_white_space (); }
1712 { expand_end_loop (); }
1715 { emit_line_note (input_filename, lineno);
1716 expand_exit_loop_if_false (NULL_PTR,
1717 truthvalue_conversion ($3));
1719 clear_momentary (); }
1720 /* This rule is needed to make sure we end every loop we start. */
1721 | do_stmt_start error
1722 { expand_end_loop ();
1723 clear_momentary (); }
1727 emit_line_note ($<filename>-1, $<lineno>0);
1728 /* See comment in `while' alternative, above. */
1730 if ($3) c_expand_expr_stmt ($3);
1731 /* Next step is to call expand_start_loop_continue_elsewhere,
1732 but wait till after we parse the entire for (...).
1733 Otherwise, invalid input might cause us to call that
1734 fn without calling expand_end_loop. */
1737 /* Can't emit now; wait till after expand_start_loop... */
1738 { $<lineno>7 = lineno;
1739 $<filename>$ = input_filename; }
1742 /* Start the loop. Doing this after parsing
1743 all the expressions ensures we will end the loop. */
1744 expand_start_loop_continue_elsewhere (1);
1745 /* Emit the end-test, with a line number. */
1746 emit_line_note ($<filename>8, $<lineno>7);
1748 expand_exit_loop_if_false (NULL_PTR,
1749 truthvalue_conversion ($6));
1750 /* Don't let the tree nodes for $9 be discarded by
1751 clear_momentary during the parsing of the next stmt. */
1753 $<lineno>7 = lineno;
1754 $<filename>8 = input_filename;
1755 position_after_white_space (); }
1757 { /* Emit the increment expression, with a line number. */
1758 emit_line_note ($<filename>8, $<lineno>7);
1759 expand_loop_continue_here ();
1761 c_expand_expr_stmt ($9);
1762 if (yychar == CONSTANT || yychar == STRING)
1763 pop_momentary_nofree ();
1766 expand_end_loop (); }
1767 | SWITCH '(' expr ')'
1769 emit_line_note ($<filename>-1, $<lineno>0);
1770 c_expand_start_case ($3);
1771 /* Don't let the tree nodes for $3 be discarded by
1772 clear_momentary during the parsing of the next stmt. */
1774 position_after_white_space (); }
1776 { expand_end_case ($3);
1777 if (yychar == CONSTANT || yychar == STRING)
1778 pop_momentary_nofree ();
1783 emit_line_note ($<filename>-1, $<lineno>0);
1784 if ( ! expand_exit_something ())
1785 error ("break statement not within loop or switch"); }
1788 emit_line_note ($<filename>-1, $<lineno>0);
1789 if (! expand_continue_loop (NULL_PTR))
1790 error ("continue statement not within a loop"); }
1793 emit_line_note ($<filename>-1, $<lineno>0);
1794 c_expand_return (NULL_TREE); }
1797 emit_line_note ($<filename>-1, $<lineno>0);
1798 c_expand_return ($2); }
1799 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1801 emit_line_note ($<filename>-1, $<lineno>0);
1803 if ((TREE_CODE ($4) == ADDR_EXPR
1804 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1805 || TREE_CODE ($4) == STRING_CST)
1808 error ("argument of `asm' is not a constant string"); }
1809 /* This is the case with just output operands. */
1810 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1812 emit_line_note ($<filename>-1, $<lineno>0);
1813 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1814 $2 == ridpointers[(int)RID_VOLATILE],
1815 input_filename, lineno); }
1816 /* This is the case with input operands as well. */
1817 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1819 emit_line_note ($<filename>-1, $<lineno>0);
1820 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1821 $2 == ridpointers[(int)RID_VOLATILE],
1822 input_filename, lineno); }
1823 /* This is the case with clobbered registers as well. */
1824 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1825 asm_operands ':' asm_clobbers ')' ';'
1827 emit_line_note ($<filename>-1, $<lineno>0);
1828 c_expand_asm_operands ($4, $6, $8, $10,
1829 $2 == ridpointers[(int)RID_VOLATILE],
1830 input_filename, lineno); }
1831 | GOTO identifier ';'
1834 emit_line_note ($<filename>-1, $<lineno>0);
1835 decl = lookup_label ($2);
1838 TREE_USED (decl) = 1;
1844 emit_line_note ($<filename>-1, $<lineno>0);
1845 expand_computed_goto (convert (ptr_type_node, $3)); }
1850 all_iter_stmt_simple
1851 /* | all_iter_stmt_with_decl */
1854 all_iter_stmt_simple:
1857 /* The value returned by this action is */
1858 /* 1 if everything is OK */
1859 /* 0 in case of error or already bound iterator */
1862 if (TREE_CODE ($3) != VAR_DECL)
1863 error ("invalid `for (ITERATOR)' syntax");
1864 else if (! ITERATOR_P ($3))
1865 error ("`%s' is not an iterator",
1866 IDENTIFIER_POINTER (DECL_NAME ($3)));
1867 else if (ITERATOR_BOUND_P ($3))
1868 error ("`for (%s)' inside expansion of same iterator",
1869 IDENTIFIER_POINTER (DECL_NAME ($3)));
1873 iterator_for_loop_start ($3);
1879 iterator_for_loop_end ($3);
1882 /* This really should allow any kind of declaration,
1883 for generality. Fix it before turning it back on.
1885 all_iter_stmt_with_decl:
1886 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
1888 */ /* The value returned by this action is */
1889 /* 1 if everything is OK */
1890 /* 0 in case of error or already bound iterator */
1892 iterator_for_loop_start ($6);
1896 iterator_for_loop_end ($6);
1897 emit_line_note (input_filename, lineno);
1898 expand_end_bindings (getdecls (), 1, 0);
1899 $<ttype>$ = poplevel (1, 1, 0);
1900 if (yychar == CONSTANT || yychar == STRING)
1901 pop_momentary_nofree ();
1907 /* Any kind of label, including jump labels and case labels.
1908 ANSI C accepts labels only before statements, but we allow them
1909 also at the end of a compound statement. */
1911 label: CASE expr_no_commas ':'
1912 { register tree value = check_case_value ($2);
1914 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1918 if (value != error_mark_node)
1921 int success = pushcase (value, convert_and_check,
1924 error ("case label not within a switch statement");
1925 else if (success == 2)
1927 error ("duplicate case value");
1928 error_with_decl (duplicate, "this is the first entry for that value");
1930 else if (success == 3)
1931 warning ("case value out of range");
1932 else if (success == 5)
1933 error ("case label within scope of cleanup or variable array");
1935 position_after_white_space (); }
1936 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1937 { register tree value1 = check_case_value ($2);
1938 register tree value2 = check_case_value ($4);
1940 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1944 if (value1 != error_mark_node && value2 != error_mark_node)
1947 int success = pushcase_range (value1, value2,
1948 convert_and_check, label,
1951 error ("case label not within a switch statement");
1952 else if (success == 2)
1954 error ("duplicate case value");
1955 error_with_decl (duplicate, "this is the first entry for that value");
1957 else if (success == 3)
1958 warning ("case value out of range");
1959 else if (success == 4)
1960 warning ("empty case range");
1961 else if (success == 5)
1962 error ("case label within scope of cleanup or variable array");
1964 position_after_white_space (); }
1969 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1970 int success = pushcase (NULL_TREE, 0, label, &duplicate);
1973 error ("default label not within a switch statement");
1974 else if (success == 2)
1976 error ("multiple default labels in one switch");
1977 error_with_decl (duplicate, "this is the first default label");
1979 position_after_white_space (); }
1981 { tree label = define_label (input_filename, lineno, $1);
1985 expand_label (label);
1986 position_after_white_space (); }
1989 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
1993 { emit_line_note (input_filename, lineno);
1996 { emit_line_note (input_filename, lineno); }
2005 /* These are the operands other than the first string and colon
2006 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2007 asm_operands: /* empty */
2009 | nonnull_asm_operands
2012 nonnull_asm_operands:
2014 | nonnull_asm_operands ',' asm_operand
2015 { $$ = chainon ($1, $3); }
2020 { $$ = build_tree_list ($1, $3); }
2025 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2026 | asm_clobbers ',' string
2027 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2030 /* This is what appears inside the parens in a function declarator.
2031 Its value is a list of ..._TYPE nodes. */
2034 clear_parm_order ();
2035 declare_parm_level (0); }
2038 parmlist_tags_warning ();
2039 poplevel (0, 0, 0); }
2047 pedwarn ("ANSI C forbids forward parameter declarations");
2048 /* Mark the forward decls as such. */
2049 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2050 TREE_ASM_WRITTEN (parm) = 1;
2051 clear_parm_order (); }
2055 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2058 /* This is what appears inside the parens in a function declarator.
2059 Is value is represented in the format that grokdeclarator expects. */
2060 parmlist_2: /* empty */
2061 { $$ = get_parm_info (0); }
2063 { $$ = get_parm_info (0);
2065 pedwarn ("ANSI C requires a named argument before `...'");
2068 { $$ = get_parm_info (1); }
2069 | parms ',' ELLIPSIS
2070 { $$ = get_parm_info (0); }
2075 { push_parm_decl ($1); }
2077 { push_parm_decl ($3); }
2080 /* A single parameter declaration or parameter type name,
2081 as found in a parmlist. */
2083 typed_declspecs parm_declarator
2084 { $$ = build_tree_list ($1, $2) ; }
2085 | typed_declspecs notype_declarator
2086 { $$ = build_tree_list ($1, $2) ; }
2087 | typed_declspecs absdcl
2088 { $$ = build_tree_list ($1, $2); }
2089 | declmods notype_declarator
2090 { $$ = build_tree_list ($1, $2) ; }
2092 { $$ = build_tree_list ($1, $2); }
2095 /* This is used in a function definition
2096 where either a parmlist or an identifier list is ok.
2097 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2098 parmlist_or_identifiers:
2100 clear_parm_order ();
2101 declare_parm_level (1); }
2102 parmlist_or_identifiers_1
2104 parmlist_tags_warning ();
2105 poplevel (0, 0, 0); }
2108 parmlist_or_identifiers_1:
2112 for (t = $1; t; t = TREE_CHAIN (t))
2113 if (TREE_VALUE (t) == NULL_TREE)
2114 error ("`...' in old-style identifier list");
2115 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2118 /* A nonempty list of identifiers. */
2121 { $$ = build_tree_list (NULL_TREE, $1); }
2122 | identifiers ',' IDENTIFIER
2123 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2126 /* A nonempty list of identifiers, including typenames. */
2127 identifiers_or_typenames:
2129 { $$ = build_tree_list (NULL_TREE, $1); }
2130 | identifiers_or_typenames ',' identifier
2131 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2135 /* Objective-C productions. */
2145 if (objc_implementation_context)
2147 finish_class (objc_implementation_context);
2148 objc_ivar_chain = NULL_TREE;
2149 objc_implementation_context = NULL_TREE;
2152 warning ("`@end' must appear in an implementation context");
2156 /* A nonempty list of identifiers. */
2159 { $$ = build_tree_list (NULL_TREE, $1); }
2160 | identifier_list ',' identifier
2161 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2165 CLASS identifier_list ';'
2167 objc_declare_class ($2);
2171 ALIAS identifier identifier ';'
2173 objc_declare_alias ($2, $3);
2177 INTERFACE identifier protocolrefs '{'
2179 objc_interface_context = objc_ivar_context
2180 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2181 objc_public_flag = 0;
2185 continue_class (objc_interface_context);
2190 finish_class (objc_interface_context);
2191 objc_interface_context = NULL_TREE;
2194 | INTERFACE identifier protocolrefs
2196 objc_interface_context
2197 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2198 continue_class (objc_interface_context);
2203 finish_class (objc_interface_context);
2204 objc_interface_context = NULL_TREE;
2207 | INTERFACE identifier ':' identifier protocolrefs '{'
2209 objc_interface_context = objc_ivar_context
2210 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2211 objc_public_flag = 0;
2215 continue_class (objc_interface_context);
2220 finish_class (objc_interface_context);
2221 objc_interface_context = NULL_TREE;
2224 | INTERFACE identifier ':' identifier protocolrefs
2226 objc_interface_context
2227 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2228 continue_class (objc_interface_context);
2233 finish_class (objc_interface_context);
2234 objc_interface_context = NULL_TREE;
2237 | IMPLEMENTATION identifier '{'
2239 objc_implementation_context = objc_ivar_context
2240 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2241 objc_public_flag = 0;
2246 = continue_class (objc_implementation_context);
2249 | IMPLEMENTATION identifier
2251 objc_implementation_context
2252 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2254 = continue_class (objc_implementation_context);
2257 | IMPLEMENTATION identifier ':' identifier '{'
2259 objc_implementation_context = objc_ivar_context
2260 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2261 objc_public_flag = 0;
2266 = continue_class (objc_implementation_context);
2269 | IMPLEMENTATION identifier ':' identifier
2271 objc_implementation_context
2272 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2274 = continue_class (objc_implementation_context);
2277 | INTERFACE identifier '(' identifier ')' protocolrefs
2279 objc_interface_context
2280 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2281 continue_class (objc_interface_context);
2286 finish_class (objc_interface_context);
2287 objc_interface_context = NULL_TREE;
2290 | IMPLEMENTATION identifier '(' identifier ')'
2292 objc_implementation_context
2293 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2295 = continue_class (objc_implementation_context);
2300 PROTOCOL identifier protocolrefs
2302 remember_protocol_qualifiers ();
2303 objc_interface_context
2304 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2308 forget_protocol_qualifiers();
2309 finish_protocol(objc_interface_context);
2310 objc_interface_context = NULL_TREE;
2319 | ARITHCOMPARE identifier_list ARITHCOMPARE
2321 if ($1 == LT_EXPR && $3 == GT_EXPR)
2329 ivar_decl_list visibility_spec ivar_decls
2334 PRIVATE { objc_public_flag = 2; }
2335 | PROTECTED { objc_public_flag = 0; }
2336 | PUBLIC { objc_public_flag = 1; }
2344 | ivar_decls ivar_decl ';'
2348 pedwarn ("extra semicolon in struct or union specified");
2353 /* There is a shift-reduce conflict here, because `components' may
2354 start with a `typename'. It happens that shifting (the default resolution)
2355 does the right thing, because it treats the `typename' as part of
2356 a `typed_typespecs'.
2358 It is possible that this same technique would allow the distinction
2359 between `notype_initdecls' and `initdecls' to be eliminated.
2360 But I am being cautious and not trying it. */
2363 typed_typespecs setspecs ivars
2366 resume_momentary ($2);
2368 | nonempty_type_quals setspecs ivars
2371 resume_momentary ($2);
2381 | ivars ',' ivar_declarator
2387 $$ = add_instance_variable (objc_ivar_context,
2389 $1, current_declspecs,
2392 | declarator ':' expr_no_commas
2394 $$ = add_instance_variable (objc_ivar_context,
2396 $1, current_declspecs, $3);
2398 | ':' expr_no_commas
2400 $$ = add_instance_variable (objc_ivar_context,
2403 current_declspecs, $2);
2410 remember_protocol_qualifiers ();
2411 if (objc_implementation_context)
2412 objc_inherit_code = CLASS_METHOD_DECL;
2414 fatal ("method definition not in class context");
2418 forget_protocol_qualifiers ();
2419 add_class_method (objc_implementation_context, $3);
2420 start_method_def ($3);
2421 objc_method_context = $3;
2425 continue_method_def ();
2429 finish_method_def ();
2430 objc_method_context = NULL_TREE;
2435 remember_protocol_qualifiers ();
2436 if (objc_implementation_context)
2437 objc_inherit_code = INSTANCE_METHOD_DECL;
2439 fatal ("method definition not in class context");
2443 forget_protocol_qualifiers ();
2444 add_instance_method (objc_implementation_context, $3);
2445 start_method_def ($3);
2446 objc_method_context = $3;
2450 continue_method_def ();
2454 finish_method_def ();
2455 objc_method_context = NULL_TREE;
2459 /* the reason for the strange actions in this rule
2460 is so that notype_initdecls when reached via datadef
2461 can find a valid list of type and sc specs in $0. */
2465 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2468 methodprotolist2: /* eliminates a shift/reduce conflict */
2471 | methodprotolist2 methodproto
2472 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2483 objc_inherit_code = CLASS_METHOD_DECL;
2487 add_class_method (objc_interface_context, $3);
2493 objc_inherit_code = INSTANCE_METHOD_DECL;
2497 add_instance_method (objc_interface_context, $3);
2503 '(' typename ')' unaryselector
2505 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2510 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2513 | '(' typename ')' keywordselector optparmlist
2515 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2518 | keywordselector optparmlist
2520 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2524 /* "optarglist" assumes that start_method_def has already been called...
2525 if it is not, the "xdecls" will not be placed in the proper scope */
2532 /* to get around the following situation: "int foo (int a) int b; {}" that
2533 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2548 typed_declspecs setspecs myparms ';'
2549 { resume_momentary ($2); }
2550 | typed_declspecs ';'
2551 { shadow_tag ($1); }
2553 { pedwarn ("empty declaration"); }
2558 { push_parm_decl ($1); }
2559 | myparms ',' myparm
2560 { push_parm_decl ($3); }
2563 /* A single parameter declaration or parameter type name,
2564 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2568 { $$ = build_tree_list (current_declspecs, $1) ; }
2570 { $$ = build_tree_list (current_declspecs, $1) ; }
2572 { $$ = build_tree_list (current_declspecs, $1) ; }
2582 /* oh what a kludge! */
2591 /* returns a tree list node generated by get_parm_info */
2604 | keywordselector keyworddecl
2606 $$ = chainon ($1, $2);
2618 ENUM { $$ = get_identifier (token_buffer); }
2619 | STRUCT { $$ = get_identifier (token_buffer); }
2620 | UNION { $$ = get_identifier (token_buffer); }
2621 | IF { $$ = get_identifier (token_buffer); }
2622 | ELSE { $$ = get_identifier (token_buffer); }
2623 | WHILE { $$ = get_identifier (token_buffer); }
2624 | DO { $$ = get_identifier (token_buffer); }
2625 | FOR { $$ = get_identifier (token_buffer); }
2626 | SWITCH { $$ = get_identifier (token_buffer); }
2627 | CASE { $$ = get_identifier (token_buffer); }
2628 | DEFAULT { $$ = get_identifier (token_buffer); }
2629 | BREAK { $$ = get_identifier (token_buffer); }
2630 | CONTINUE { $$ = get_identifier (token_buffer); }
2631 | RETURN { $$ = get_identifier (token_buffer); }
2632 | GOTO { $$ = get_identifier (token_buffer); }
2633 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2634 | SIZEOF { $$ = get_identifier (token_buffer); }
2635 | TYPEOF { $$ = get_identifier (token_buffer); }
2636 | ALIGNOF { $$ = get_identifier (token_buffer); }
2637 | TYPESPEC | TYPE_QUAL
2641 selector ':' '(' typename ')' identifier
2643 $$ = build_keyword_decl ($1, $4, $6);
2646 | selector ':' identifier
2648 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2651 | ':' '(' typename ')' identifier
2653 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2658 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2669 | keywordarglist keywordarg
2671 $$ = chainon ($1, $2);
2679 if (TREE_CHAIN ($1) == NULL_TREE)
2680 /* just return the expr., remove a level of indirection */
2681 $$ = TREE_VALUE ($1);
2683 /* we have a comma expr., we will collapse later */
2689 selector ':' keywordexpr
2691 $$ = build_tree_list ($1, $3);
2695 $$ = build_tree_list (NULL_TREE, $2);
2703 $$ = get_class_reference ($1);
2709 { objc_receiver_context = 1; }
2711 { objc_receiver_context = 0; }
2714 $$ = build_tree_list ($3, $5);
2725 | keywordnamelist keywordname
2727 $$ = chainon ($1, $2);
2734 $$ = build_tree_list ($1, NULL_TREE);
2738 $$ = build_tree_list (NULL_TREE, NULL_TREE);
2743 SELECTOR '(' selectorarg ')'
2750 PROTOCOL '(' identifier ')'
2756 /* extension to support C-structures in the archiver */
2759 ENCODE '(' typename ')'
2761 $$ = groktypename ($3);