1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 1988, 1989, 1992 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 The awk script cond.awk is 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 8 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 92 contains 1 shift/reduce conflict. (Two ways to recover from error.)
40 State 99 contains 1 shift/reduce conflict. (Two ways to recover from error.)
41 State 103 contains 1 shift/reduce conflict. (Two ways to recover from error.)
42 State 119 contains 1 shift/reduce conflict. (See comment at component_decl.)
43 State 183 contains 1 shift/reduce conflict. (Two ways to recover from error.)
44 State 193 contains 1 shift/reduce conflict. (Two ways to recover from error.)
45 State 199 contains 1 shift/reduce conflict. (Two ways to recover from error.)
61 #ifdef MULTIBYTE_CHARS
70 /* Since parsers are distinct for each language, put the language string
73 char *language_string = "GNU Obj-C";
76 char *language_string = "GNU C";
85 /* Like YYERROR but do call yyerror. */
86 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
88 /* Cause the `yydebug' variable to be defined. */
94 %union {long itype; tree ttype; enum tree_code code;
95 char *filename; int lineno; }
97 /* All identifiers that are not reserved words
98 and are not declared typedefs in the current block */
101 /* All identifiers that are declared typedefs in the current block.
102 In some contexts, they are treated just like IDENTIFIER,
103 but they can also serve as typespecs in declarations. */
106 /* Reserved words that specify storage class.
107 yylval contains an IDENTIFIER_NODE which indicates which one. */
110 /* Reserved words that specify type.
111 yylval contains an IDENTIFIER_NODE which indicates which one. */
114 /* Reserved words that qualify type: "const" or "volatile".
115 yylval contains an IDENTIFIER_NODE which indicates which one. */
118 /* Character or numeric constants.
119 yylval is the node for the constant. */
122 /* String constants in raw form.
123 yylval is a STRING_CST node. */
126 /* "...", used for functions with variable arglists. */
129 /* the reserved words */
130 /* SCO include files test "ASM", so use something else. */
131 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
132 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF ALIGN
133 %token ATTRIBUTE EXTENSION LABEL
135 /* Add precedence rules to solve dangling else s/r conflict */
139 /* Define the operator tokens and their precedences.
140 The value is an integer because, if used, it is the tree code
141 to use in the expression made from the operator. */
143 %right <code> ASSIGN '='
144 %right <code> '?' ':'
150 %left <code> EQCOMPARE
151 %left <code> ARITHCOMPARE
152 %left <code> LSHIFT RSHIFT
154 %left <code> '*' '/' '%'
155 %right <code> UNARY PLUSPLUS MINUSMINUS
157 %left <code> POINTSAT '.' '(' '['
159 /* The Objective-C keywords. These are included in C and in
160 Objective C, so that the token codes are the same in both. */
161 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
162 %token CLASSNAME PUBLIC
167 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
168 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
169 %type <ttype> typed_declspecs reserved_declspecs
170 %type <ttype> typed_typespecs reserved_typespecquals
171 %type <ttype> declmods typespec typespecqual_reserved
172 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
173 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
174 %type <ttype> init initlist maybeasm
175 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
176 %type <ttype> maybe_attribute attribute_list attrib
178 %type <ttype> compstmt
180 %type <ttype> declarator
181 %type <ttype> notype_declarator after_type_declarator
182 %type <ttype> parm_declarator
184 %type <ttype> structsp component_decl_list component_decl_list2
185 %type <ttype> component_decl components component_declarator
186 %type <ttype> enumlist enumerator
187 %type <ttype> typename absdcl absdcl1 type_quals
188 %type <ttype> xexpr parms parm identifiers
190 %type <ttype> parmlist parmlist_1 parmlist_2
191 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
192 %type <ttype> identifiers_or_typenames
194 %type <itype> setspecs
196 %type <filename> save_filename
197 %type <lineno> save_lineno
200 /* the Objective-C nonterminals */
202 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
203 %type <ttype> methoddecl unaryselector keywordselector selector
204 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
205 %type <ttype> keywordexpr keywordarglist keywordarg
206 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
207 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
208 %type <ttype> CLASSNAME
212 /* Number of statements (loosely speaking) seen so far. */
213 static int stmt_count;
215 /* Input file and line number of the end of the body of last simple_if;
216 used by the stmt-rule immediately after simple_if returns. */
217 static char *if_stmt_file;
218 static int if_stmt_line;
220 /* List of types and structure classes of the current declaration. */
221 static tree current_declspecs;
223 /* Stack of saved values of current_declspecs. */
224 static tree declspec_stack;
226 /* 1 if we explained undeclared var errors. */
227 static int undeclared_variable_notice;
230 /* Objective-C specific information */
232 tree objc_interface_context;
233 tree objc_implementation_context;
234 tree objc_method_context;
235 tree objc_ivar_chain;
236 tree objc_ivar_context;
237 enum tree_code objc_inherit_code;
238 int objc_receiver_context;
239 int objc_public_flag;
243 /* Tell yyparse how to print a token's value, if yydebug is set. */
245 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
246 extern void yyprint ();
252 pedwarn ("ANSI C forbids an empty source file");
265 /* the reason for the strange actions in this rule
266 is so that notype_initdecls when reached via datadef
267 can find a valid list of type and sc specs in $0. */
270 {$<ttype>$ = NULL_TREE; } extdef
271 | extdefs {$<ttype>$ = NULL_TREE; } extdef
280 | ASM_KEYWORD '(' expr ')' ';'
282 if ((TREE_CODE ($3) == ADDR_EXPR
283 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
284 || TREE_CODE ($3) == STRING_CST)
287 error ("argument of `asm' is not a constant string"); }
291 setspecs notype_initdecls ';'
293 error ("ANSI C forbids data definition with no type or storage class");
294 else if (!flag_traditional)
295 warning ("data definition has no type or storage class"); }
296 | declmods setspecs notype_initdecls ';'
298 | typed_declspecs setspecs initdecls ';'
301 { pedwarn ("empty declaration"); }
302 | typed_declspecs ';'
308 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
312 typed_declspecs setspecs declarator
313 { if (! start_function ($1, $3, 0))
315 reinit_parse_for_function (); }
317 { store_parm_decls (); }
319 { finish_function (0); }
320 | typed_declspecs setspecs declarator error
322 | declmods setspecs notype_declarator
323 { if (! start_function ($1, $3, 0))
325 reinit_parse_for_function (); }
327 { store_parm_decls (); }
329 { finish_function (0); }
330 | declmods setspecs notype_declarator error
332 | setspecs notype_declarator
333 { if (! start_function (NULL_TREE, $2, 0))
335 reinit_parse_for_function (); }
337 { store_parm_decls (); }
339 { finish_function (0); }
340 | setspecs notype_declarator error
349 { $$ = CLASS_NAME ($1); }
356 { $$ = NEGATE_EXPR; }
358 { $$ = CONVERT_EXPR; }
360 { $$ = PREINCREMENT_EXPR; }
362 { $$ = PREDECREMENT_EXPR; }
364 { $$ = BIT_NOT_EXPR; }
366 { $$ = TRUTH_NOT_EXPR; }
369 expr: nonnull_exprlist
370 { $$ = build_compound_expr ($1); }
381 { $$ = build_tree_list (NULL_TREE, $1); }
382 | nonnull_exprlist ',' expr_no_commas
383 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
388 | '*' cast_expr %prec UNARY
389 { $$ = build_indirect_ref ($2, "unary *"); }
390 /* __extension__ turns off -pedantic for following primary. */
392 { $<itype>1 = pedantic;
394 cast_expr %prec UNARY
396 pedantic = $<itype>1; }
397 | unop cast_expr %prec UNARY
398 { $$ = build_unary_op ($1, $2, 0); }
399 /* Refer to the address of a label as a pointer. */
401 { tree label = lookup_label ($2);
403 $$ = null_pointer_node;
406 TREE_USED (label) = 1;
407 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
408 TREE_CONSTANT ($$) = 1;
411 /* This seems to be impossible on some machines, so let's turn it off.
412 You can use __builtin_next_arg to find the anonymous stack args.
414 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
415 $$ = error_mark_node;
416 if (TREE_VALUE (tree_last (types)) == void_type_node)
417 error ("`&...' used in function with fixed number of arguments");
421 pedwarn ("ANSI C forbids `&...'");
422 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
423 $$ = build_unary_op (ADDR_EXPR, $$, 0);
426 | SIZEOF unary_expr %prec UNARY
427 { if (TREE_CODE ($2) == COMPONENT_REF
428 && DECL_BIT_FIELD (TREE_OPERAND ($2, 1)))
429 error ("`sizeof' applied to a bit-field");
430 $$ = c_sizeof (TREE_TYPE ($2)); }
431 | SIZEOF '(' typename ')' %prec HYPERUNARY
432 { $$ = c_sizeof (groktypename ($3)); }
433 | ALIGNOF unary_expr %prec UNARY
434 { $$ = c_alignof_expr ($2); }
435 | ALIGNOF '(' typename ')' %prec HYPERUNARY
436 { $$ = c_alignof (groktypename ($3)); }
441 | '(' typename ')' cast_expr %prec UNARY
442 { tree type = groktypename ($2);
443 $$ = build_c_cast (type, $4); }
444 | '(' typename ')' '{' initlist maybecomma '}' %prec UNARY
445 { tree type = groktypename ($2);
448 pedwarn ("ANSI C forbids constructor expressions");
449 if (TYPE_NAME (type) != 0)
451 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
452 name = IDENTIFIER_POINTER (TYPE_NAME (type));
454 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
458 $$ = digest_init (type, build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($5)),
459 NULL_PTR, 0, 0, name);
460 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
462 int failure = complete_array_type (type, $$, 1);
471 | expr_no_commas '+' expr_no_commas
472 { $$ = parser_build_binary_op ($2, $1, $3); }
473 | expr_no_commas '-' expr_no_commas
474 { $$ = parser_build_binary_op ($2, $1, $3); }
475 | expr_no_commas '*' expr_no_commas
476 { $$ = parser_build_binary_op ($2, $1, $3); }
477 | expr_no_commas '/' expr_no_commas
478 { $$ = parser_build_binary_op ($2, $1, $3); }
479 | expr_no_commas '%' expr_no_commas
480 { $$ = parser_build_binary_op ($2, $1, $3); }
481 | expr_no_commas LSHIFT expr_no_commas
482 { $$ = parser_build_binary_op ($2, $1, $3); }
483 | expr_no_commas RSHIFT expr_no_commas
484 { $$ = parser_build_binary_op ($2, $1, $3); }
485 | expr_no_commas ARITHCOMPARE expr_no_commas
486 { $$ = parser_build_binary_op ($2, $1, $3); }
487 | expr_no_commas EQCOMPARE expr_no_commas
488 { $$ = parser_build_binary_op ($2, $1, $3); }
489 | expr_no_commas '&' expr_no_commas
490 { $$ = parser_build_binary_op ($2, $1, $3); }
491 | expr_no_commas '|' expr_no_commas
492 { $$ = parser_build_binary_op ($2, $1, $3); }
493 | expr_no_commas '^' expr_no_commas
494 { $$ = parser_build_binary_op ($2, $1, $3); }
495 | expr_no_commas ANDAND expr_no_commas
496 { $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
497 | expr_no_commas OROR expr_no_commas
498 { $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
499 | expr_no_commas '?' xexpr ':' expr_no_commas
500 { $$ = build_conditional_expr ($1, $3, $5); }
501 | expr_no_commas '=' expr_no_commas
502 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
503 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
504 | expr_no_commas ASSIGN expr_no_commas
505 { $$ = build_modify_expr ($1, $2, $3);
506 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
515 if (!$$ || $$ == error_mark_node)
517 if (yychar == YYEMPTY)
522 if (objc_receiver_context
523 && ! (objc_receiver_context
524 && strcmp (IDENTIFIER_POINTER ($1), "super")))
525 /* we have a message to super */
526 $$ = get_super_receiver ();
527 else if (objc_method_context
528 && is_ivar (objc_ivar_chain, $1))
529 $$ = build_ivar_reference ($1);
533 /* Ordinary implicit function declaration. */
534 $$ = implicitly_declare ($1);
535 assemble_external ($$);
539 else if (current_function_decl == 0)
541 error ("`%s' undeclared, outside of functions",
542 IDENTIFIER_POINTER ($1));
543 $$ = error_mark_node;
548 if (objc_receiver_context
549 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
550 /* we have a message to super */
551 $$ = get_super_receiver ();
552 else if (objc_method_context
553 && is_ivar (objc_ivar_chain, $1))
554 $$ = build_ivar_reference ($1);
558 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
559 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
561 error ("`%s' undeclared (first use this function)",
562 IDENTIFIER_POINTER ($1));
564 if (! undeclared_variable_notice)
566 error ("(Each undeclared identifier is reported only once");
567 error ("for each function it appears in.)");
568 undeclared_variable_notice = 1;
571 $$ = error_mark_node;
572 /* Prevent repeated error messages. */
573 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
574 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
578 else if (TREE_TYPE ($$) == error_mark_node)
579 $$ = error_mark_node;
580 else if (C_DECL_ANTICIPATED ($$))
582 /* The first time we see a build-in function used,
583 if it has not been declared. */
584 C_DECL_ANTICIPATED ($$) = 0;
585 if (yychar == YYEMPTY)
589 /* Omit the implicit declaration we
590 would ordinarily do, so we don't lose
591 the actual built in type.
592 But print a diagnostic for the mismatch. */
594 if (objc_method_context
595 && is_ivar (objc_ivar_chain, $1))
596 error ("Instance variable `%s' implicitly declared as function",
597 IDENTIFIER_POINTER (DECL_NAME ($$)));
600 if (TREE_CODE ($$) != FUNCTION_DECL)
601 error ("`%s' implicitly declared as function",
602 IDENTIFIER_POINTER (DECL_NAME ($$)));
603 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
604 != TYPE_MODE (integer_type_node))
605 && (TREE_TYPE (TREE_TYPE ($$))
607 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
608 IDENTIFIER_POINTER (DECL_NAME ($$)));
609 /* If it really returns void, change that to int. */
610 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
612 = build_function_type (integer_type_node,
613 TYPE_ARG_TYPES (TREE_TYPE ($$)));
616 pedwarn ("built-in function `%s' used without declaration",
617 IDENTIFIER_POINTER (DECL_NAME ($$)));
619 /* Do what we would ordinarily do when a fn is used. */
620 assemble_external ($$);
625 assemble_external ($$);
628 /* we have a definition - still check if iVariable */
630 if (!objc_receiver_context
631 || (objc_receiver_context
632 && strcmp (IDENTIFIER_POINTER ($1), "super")))
634 if (objc_method_context
635 && is_ivar (objc_ivar_chain, $1))
637 if (IDENTIFIER_LOCAL_VALUE ($1))
638 warning ("local declaration of `%s' hides instance variable",
639 IDENTIFIER_POINTER ($1));
641 $$ = build_ivar_reference ($1);
644 else /* we have a message to super */
645 $$ = get_super_receiver ();
649 if (TREE_CODE ($$) == CONST_DECL)
651 $$ = DECL_INITIAL ($$);
652 /* This is to prevent an enum whose value is 0
653 from being considered a null pointer constant. */
654 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
655 TREE_CONSTANT ($$) = 1;
660 { $$ = combine_strings ($1); }
662 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
663 if (class == 'e' || class == '1'
664 || class == '2' || class == '<')
665 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
668 { $$ = error_mark_node; }
670 { if (current_function_decl == 0)
672 error ("braced-group within expression allowed only inside a function");
675 /* We must force a BLOCK for this level
676 so that, if it is not expanded later,
677 there is a way to turn off the entire subtree of blocks
678 that are contained in it. */
681 $<ttype>$ = expand_start_stmt_expr (); }
685 pedwarn ("ANSI C forbids braced-groups within expressions");
687 rtl_exp = expand_end_stmt_expr ($<ttype>2);
688 /* The statements have side effects, so the group does. */
689 TREE_SIDE_EFFECTS (rtl_exp) = 1;
691 /* Make a BIND_EXPR for the BLOCK already made. */
692 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
693 NULL_TREE, rtl_exp, $3);
694 /* Remove the block from the tree at this point.
695 It gets put back at the proper place
696 when the BIND_EXPR is expanded. */
699 | primary '(' exprlist ')' %prec '.'
700 { $$ = build_function_call ($1, $3); }
701 | primary '[' expr ']' %prec '.'
702 { $$ = build_array_ref ($1, $3); }
703 | primary '.' identifier
706 if (doing_objc_thang)
708 if (is_public ($1, $3))
709 $$ = build_component_ref ($1, $3);
711 $$ = error_mark_node;
715 $$ = build_component_ref ($1, $3);
717 | primary POINTSAT identifier
719 tree expr = build_indirect_ref ($1, "->");
722 if (doing_objc_thang)
724 if (is_public (expr, $3))
725 $$ = build_component_ref (expr, $3);
727 $$ = error_mark_node;
731 $$ = build_component_ref (expr, $3);
734 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
736 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
739 { $$ = build_message_expr ($1); }
741 { $$ = build_selector_expr ($1); }
743 { $$ = build_encode_expr ($1); }
747 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
751 { $$ = chainon ($1, $2); }
758 /* ... is used here to indicate a varargs function. */
761 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
764 /* The following are analogous to lineno_decl, decls and decl
765 except that they do not allow nested functions.
766 They are used for old-style parm decls. */
768 save_filename save_lineno datadecl
775 | datadecls lineno_datadecl
776 | lineno_datadecl errstmt
780 typed_declspecs setspecs initdecls ';'
781 { current_declspecs = TREE_VALUE (declspec_stack);
782 declspec_stack = TREE_CHAIN (declspec_stack);
783 resume_momentary ($2); }
784 | declmods setspecs notype_initdecls ';'
785 { current_declspecs = TREE_VALUE (declspec_stack);
786 declspec_stack = TREE_CHAIN (declspec_stack);
787 resume_momentary ($2); }
788 | typed_declspecs ';'
789 { shadow_tag_warned ($1, 1);
790 pedwarn ("empty declaration"); }
792 { pedwarn ("empty declaration"); }
795 /* This combination which saves a lineno before a decl
796 is the normal thing to use, rather than decl itself.
797 This is to avoid shift/reduce conflicts in contexts
798 where statement labels are allowed. */
800 save_filename save_lineno decl
808 | lineno_decl errstmt
811 /* records the type and storage class specs to use for processing
812 the declarators that follow.
813 Maintains a stack of outer-level values of current_declspecs,
814 for the sake of parm declarations nested in function declarators. */
815 setspecs: /* empty */
816 { $$ = suspend_momentary ();
817 pending_xref_error ();
818 declspec_stack = tree_cons (NULL_TREE, current_declspecs,
820 current_declspecs = $<ttype>0; }
824 typed_declspecs setspecs initdecls ';'
825 { current_declspecs = TREE_VALUE (declspec_stack);
826 declspec_stack = TREE_CHAIN (declspec_stack);
827 resume_momentary ($2); }
828 | declmods setspecs notype_initdecls ';'
829 { current_declspecs = TREE_VALUE (declspec_stack);
830 declspec_stack = TREE_CHAIN (declspec_stack);
831 resume_momentary ($2); }
832 | typed_declspecs setspecs nested_function
833 { current_declspecs = TREE_VALUE (declspec_stack);
834 declspec_stack = TREE_CHAIN (declspec_stack);
835 resume_momentary ($2); }
836 | declmods setspecs notype_nested_function
837 { current_declspecs = TREE_VALUE (declspec_stack);
838 declspec_stack = TREE_CHAIN (declspec_stack);
839 resume_momentary ($2); }
840 | typed_declspecs ';'
843 { pedwarn ("empty declaration"); }
846 /* Declspecs which contain at least one type specifier or typedef name.
847 (Just `const' or `volatile' is not enough.)
848 A typedef'd name following these is taken as a name to be declared. */
851 typespec reserved_declspecs
852 { $$ = tree_cons (NULL_TREE, $1, $2); }
853 | declmods typespec reserved_declspecs
854 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
857 reserved_declspecs: /* empty */
859 | reserved_declspecs typespecqual_reserved
860 { $$ = tree_cons (NULL_TREE, $2, $1); }
861 | reserved_declspecs SCSPEC
862 { if (extra_warnings)
863 warning ("`%s' is not at beginning of declaration",
864 IDENTIFIER_POINTER ($2));
865 $$ = tree_cons (NULL_TREE, $2, $1); }
868 /* List of just storage classes and type modifiers.
869 A declaration can start with just this, but then it cannot be used
870 to redeclare a typedef-name. */
874 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
875 TREE_STATIC ($$) = 1; }
877 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
879 { $$ = tree_cons (NULL_TREE, $2, $1);
880 TREE_STATIC ($$) = 1; }
882 { if (extra_warnings && TREE_STATIC ($1))
883 warning ("`%s' is not at beginning of declaration",
884 IDENTIFIER_POINTER ($2));
885 $$ = tree_cons (NULL_TREE, $2, $1);
886 TREE_STATIC ($$) = TREE_STATIC ($1); }
890 /* Used instead of declspecs where storage classes are not allowed
891 (that is, for typenames and structure components).
892 Don't accept a typedef-name if anything but a modifier precedes it. */
895 typespec reserved_typespecquals
896 { $$ = tree_cons (NULL_TREE, $1, $2); }
897 | nonempty_type_quals typespec reserved_typespecquals
898 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
901 reserved_typespecquals: /* empty */
903 | reserved_typespecquals typespecqual_reserved
904 { $$ = tree_cons (NULL_TREE, $2, $1); }
907 /* A typespec (but not a type qualifier).
908 Once we have seen one of these in a declaration,
909 if a typedef name appears then it is being redeclared. */
914 { /* For a typedef name, record the meaning, not the name.
915 In case of `foo foo, bar;'. */
916 $$ = lookup_name ($1); }
919 { $$ = get_static_reference ($1); }
921 | TYPEOF '(' expr ')'
922 { $$ = TREE_TYPE ($3); }
923 | TYPEOF '(' typename ')'
924 { $$ = groktypename ($3); }
927 /* A typespec that is a reserved word, or a type qualifier. */
929 typespecqual_reserved: TYPESPEC
936 | initdecls ',' initdcl
941 | notype_initdecls ',' initdcl
947 | ASM_KEYWORD '(' string ')'
948 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
954 declarator maybeasm maybe_attribute '='
955 { $<ttype>$ = start_decl ($1, current_declspecs, 1); }
957 /* Note how the declaration of the variable is in effect while its init is parsed! */
958 { decl_attributes ($<ttype>5, $3);
959 finish_decl ($<ttype>5, $6, $2); }
960 | declarator maybeasm maybe_attribute
961 { tree d = start_decl ($1, current_declspecs, 0);
962 decl_attributes (d, $3);
963 finish_decl (d, NULL_TREE, $2); }
967 notype_declarator maybeasm maybe_attribute '='
968 { $<ttype>$ = start_decl ($1, current_declspecs, 1); }
970 /* Note how the declaration of the variable is in effect while its init is parsed! */
971 { decl_attributes ($<ttype>5, $3);
972 finish_decl ($<ttype>5, $6, $2); }
973 | notype_declarator maybeasm maybe_attribute
974 { tree d = start_decl ($1, current_declspecs, 0);
975 decl_attributes (d, $3);
976 finish_decl (d, NULL_TREE, $2); }
978 /* the * rules are dummies to accept the Apollo extended syntax
979 so that the header files compile. */
983 | ATTRIBUTE '(' '(' attribute_list ')' ')'
989 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
990 | attribute_list ',' attrib
991 { $$ = tree_cons (NULL_TREE, $3, $1); }
996 { if (strcmp (IDENTIFIER_POINTER ($1), "packed"))
997 warning ("`%s' attribute directive ignored",
998 IDENTIFIER_POINTER ($1));
1000 | IDENTIFIER '(' IDENTIFIER ')'
1001 { /* If not "mode (m)", then issue warning. */
1002 if (strcmp (IDENTIFIER_POINTER ($1), "mode") != 0)
1004 warning ("`%s' attribute directive ignored",
1005 IDENTIFIER_POINTER ($1));
1009 $$ = tree_cons ($1, $3, NULL_TREE); }
1010 | IDENTIFIER '(' CONSTANT ')'
1011 { /* if not "aligned(n)", then issue warning */
1012 if (strcmp (IDENTIFIER_POINTER ($1), "aligned") != 0
1013 || TREE_CODE ($3) != INTEGER_CST)
1015 warning ("`%s' attribute directive ignored",
1016 IDENTIFIER_POINTER ($1));
1020 $$ = tree_cons ($1, $3, NULL_TREE); }
1021 | IDENTIFIER '(' IDENTIFIER ',' CONSTANT ',' CONSTANT ')'
1022 { /* if not "format(...)", then issue warning */
1023 if (strcmp (IDENTIFIER_POINTER ($1), "format") != 0
1024 || TREE_CODE ($5) != INTEGER_CST
1025 || TREE_CODE ($7) != INTEGER_CST)
1027 warning ("`%s' attribute directive ignored",
1028 IDENTIFIER_POINTER ($1));
1034 tree_cons ($5, $7, NULL_TREE),
1042 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
1044 pedwarn ("ANSI C forbids empty initializer braces"); }
1046 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); }
1047 | '{' initlist ',' '}'
1048 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); }
1053 /* This chain is built in reverse order,
1054 and put in forward order where initlist is used. */
1057 { $$ = build_tree_list (NULL_TREE, $1); }
1059 { $$ = tree_cons (NULL_TREE, $3, $1); }
1060 /* These are for labeled elements. */
1061 | '[' expr_no_commas ELLIPSIS expr_no_commas ']' init
1062 { $$ = build_tree_list (tree_cons ($2, NULL_TREE,
1063 build_tree_list ($4, NULL_TREE)),
1065 | initlist ',' '[' expr_no_commas ELLIPSIS expr_no_commas ']' init
1066 { $$ = tree_cons (tree_cons ($4, NULL_TREE,
1067 build_tree_list ($6, NULL_TREE)),
1070 | '[' expr_no_commas ']' init
1071 { $$ = build_tree_list ($2, $4); }
1072 | initlist ',' '[' expr_no_commas ']' init
1073 { $$ = tree_cons ($4, $6, $1); }
1074 | identifier ':' init
1075 { $$ = build_tree_list ($1, $3); }
1076 | initlist ',' identifier ':' init
1077 { $$ = tree_cons ($3, $5, $1); }
1082 { push_c_function_context ();
1083 if (! start_function (current_declspecs, $1, 1))
1085 pop_c_function_context ();
1088 reinit_parse_for_function ();
1089 store_parm_decls (); }
1090 /* This used to use compstmt_or_error.
1091 That caused a bug with input `f(g) int g {}',
1092 where the use of YYERROR1 above caused an error
1093 which then was handled by compstmt_or_error.
1094 There followed a repeated execution of that same rule,
1095 which called YYERROR1 again, and so on. */
1097 { finish_function (1);
1098 pop_c_function_context (); }
1101 notype_nested_function:
1103 { push_c_function_context ();
1104 if (! start_function (current_declspecs, $1, 1))
1106 pop_c_function_context ();
1109 reinit_parse_for_function ();
1110 store_parm_decls (); }
1111 /* This used to use compstmt_or_error.
1112 That caused a bug with input `f(g) int g {}',
1113 where the use of YYERROR1 above caused an error
1114 which then was handled by compstmt_or_error.
1115 There followed a repeated execution of that same rule,
1116 which called YYERROR1 again, and so on. */
1118 { finish_function (1);
1119 pop_c_function_context (); }
1122 /* Any kind of declarator (thus, all declarators allowed
1123 after an explicit typespec). */
1126 after_type_declarator
1130 /* A declarator that is allowed only after an explicit typespec. */
1132 after_type_declarator:
1133 '(' after_type_declarator ')'
1135 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1136 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1137 /* | after_type_declarator '(' error ')' %prec '.'
1138 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1139 poplevel (0, 0, 0); } */
1140 | after_type_declarator '[' expr ']' %prec '.'
1141 { $$ = build_nt (ARRAY_REF, $1, $3); }
1142 | after_type_declarator '[' ']' %prec '.'
1143 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1144 | '*' type_quals after_type_declarator %prec UNARY
1145 { $$ = make_pointer_declarator ($2, $3); }
1149 /* Kinds of declarator that can appear in a parameter list
1150 in addition to notype_declarator. This is like after_type_declarator
1151 but does not allow a typedef name in parentheses as an identifier
1152 (because it would conflict with a function with that typedef as arg). */
1155 parm_declarator '(' parmlist_or_identifiers %prec '.'
1156 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1157 /* | parm_declarator '(' error ')' %prec '.'
1158 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1159 poplevel (0, 0, 0); } */
1160 | parm_declarator '[' expr ']' %prec '.'
1161 { $$ = build_nt (ARRAY_REF, $1, $3); }
1162 | parm_declarator '[' ']' %prec '.'
1163 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1164 | '*' type_quals parm_declarator %prec UNARY
1165 { $$ = make_pointer_declarator ($2, $3); }
1169 /* A declarator allowed whether or not there has been
1170 an explicit typespec. These cannot redeclare a typedef-name. */
1173 notype_declarator '(' parmlist_or_identifiers %prec '.'
1174 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1175 /* | notype_declarator '(' error ')' %prec '.'
1176 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1177 poplevel (0, 0, 0); } */
1178 | '(' notype_declarator ')'
1180 | '*' type_quals notype_declarator %prec UNARY
1181 { $$ = make_pointer_declarator ($2, $3); }
1182 | notype_declarator '[' expr ']' %prec '.'
1183 { $$ = build_nt (ARRAY_REF, $1, $3); }
1184 | notype_declarator '[' ']' %prec '.'
1185 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1190 STRUCT identifier '{'
1191 { $$ = start_struct (RECORD_TYPE, $2);
1192 /* Start scope of tag before parsing components. */
1194 component_decl_list '}'
1195 { $$ = finish_struct ($<ttype>4, $5);
1196 /* Really define the structure. */
1198 | STRUCT '{' component_decl_list '}'
1199 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1202 { $$ = xref_tag (RECORD_TYPE, $2); }
1203 | UNION identifier '{'
1204 { $$ = start_struct (UNION_TYPE, $2); }
1205 component_decl_list '}'
1206 { $$ = finish_struct ($<ttype>4, $5); }
1207 | UNION '{' component_decl_list '}'
1208 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1211 { $$ = xref_tag (UNION_TYPE, $2); }
1212 | ENUM identifier '{'
1213 { $<itype>3 = suspend_momentary ();
1214 $$ = start_enum ($2); }
1215 enumlist maybecomma_warn '}'
1216 { $$ = finish_enum ($<ttype>4, nreverse ($5));
1217 resume_momentary ($<itype>3); }
1219 { $<itype>2 = suspend_momentary ();
1220 $$ = start_enum (NULL_TREE); }
1221 enumlist maybecomma_warn '}'
1222 { $$ = finish_enum ($<ttype>3, nreverse ($4));
1223 resume_momentary ($<itype>2); }
1225 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1236 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1239 component_decl_list:
1240 component_decl_list2
1242 | component_decl_list2 component_decl
1243 { $$ = chainon ($1, $2);
1244 pedwarn ("no semicolon at end of struct or union"); }
1247 component_decl_list2: /* empty */
1249 | component_decl_list2 component_decl ';'
1250 { $$ = chainon ($1, $2); }
1251 | component_decl_list2 ';'
1253 pedwarn ("extra semicolon in struct or union specified"); }
1255 /* foo(sizeof(struct{ @defs(ClassName)})); */
1256 | DEFS '(' CLASSNAME ')'
1257 { $$ = get_class_ivars ($3); }
1261 /* There is a shift-reduce conflict here, because `components' may
1262 start with a `typename'. It happens that shifting (the default resolution)
1263 does the right thing, because it treats the `typename' as part of
1264 a `typed_typespecs'.
1266 It is possible that this same technique would allow the distinction
1267 between `notype_initdecls' and `initdecls' to be eliminated.
1268 But I am being cautious and not trying it. */
1271 typed_typespecs setspecs components
1273 current_declspecs = TREE_VALUE (declspec_stack);
1274 declspec_stack = TREE_CHAIN (declspec_stack);
1275 resume_momentary ($2); }
1278 pedwarn ("ANSI C forbids member declarations with no members");
1281 | nonempty_type_quals setspecs components
1283 current_declspecs = TREE_VALUE (declspec_stack);
1284 declspec_stack = TREE_CHAIN (declspec_stack);
1285 resume_momentary ($2); }
1286 | nonempty_type_quals
1288 pedwarn ("ANSI C forbids member declarations with no members");
1296 component_declarator
1297 | components ',' component_declarator
1298 { $$ = chainon ($1, $3); }
1301 component_declarator:
1302 save_filename save_lineno declarator maybe_attribute
1303 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1304 decl_attributes ($$, $4); }
1305 | save_filename save_lineno
1306 declarator ':' expr_no_commas maybe_attribute
1307 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1308 decl_attributes ($$, $6); }
1309 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1310 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1311 decl_attributes ($$, $5); }
1314 /* We chain the enumerators in reverse order.
1315 They are put in forward order where enumlist is used.
1316 (The order used to be significant, but no longer is so.
1317 However, we still maintain the order, just to be clean.) */
1321 | enumlist ',' enumerator
1322 { $$ = chainon ($3, $1); }
1328 { $$ = build_enumerator ($1, NULL_TREE); }
1329 | identifier '=' expr_no_commas
1330 { $$ = build_enumerator ($1, $3); }
1334 typed_typespecs absdcl
1335 { $$ = build_tree_list ($1, $2); }
1336 | nonempty_type_quals absdcl
1337 { $$ = build_tree_list ($1, $2); }
1340 absdcl: /* an absolute declarator */
1346 nonempty_type_quals:
1348 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1349 | nonempty_type_quals TYPE_QUAL
1350 { $$ = tree_cons (NULL_TREE, $2, $1); }
1356 | type_quals TYPE_QUAL
1357 { $$ = tree_cons (NULL_TREE, $2, $1); }
1360 absdcl1: /* a nonempty absolute declarator */
1363 /* `(typedef)1' is `int'. */
1364 | '*' type_quals absdcl1 %prec UNARY
1365 { $$ = make_pointer_declarator ($2, $3); }
1366 | '*' type_quals %prec UNARY
1367 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1368 | absdcl1 '(' parmlist %prec '.'
1369 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1370 | absdcl1 '[' expr ']' %prec '.'
1371 { $$ = build_nt (ARRAY_REF, $1, $3); }
1372 | absdcl1 '[' ']' %prec '.'
1373 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1374 | '(' parmlist %prec '.'
1375 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1376 | '[' expr ']' %prec '.'
1377 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1379 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1382 /* at least one statement, the first of which parses without error. */
1383 /* stmts is used only after decls, so an invalid first statement
1384 is actually regarded as an invalid decl and part of the decls. */
1387 lineno_stmt_or_label
1388 | stmts lineno_stmt_or_label
1400 pushlevel: /* empty */
1401 { emit_line_note (input_filename, lineno);
1405 expand_start_bindings (0);
1407 if (objc_method_context)
1413 /* Read zero or more forward-declarations for labels
1414 that nested functions can jump to. */
1419 pedwarn ("ANSI C forbids label declarations"); }
1424 | label_decls label_decl
1428 LABEL identifiers_or_typenames ';'
1430 for (link = $2; link; link = TREE_CHAIN (link))
1432 tree label = shadow_label (TREE_VALUE (link));
1433 C_DECLARED_LABEL_FLAG (label) = 1;
1434 declare_nonlocal_label (label);
1439 /* This is the body of a function definition.
1440 It causes syntax errors to ignore to the next openbrace. */
1448 { $$ = convert (void_type_node, integer_zero_node); }
1449 | '{' pushlevel maybe_label_decls decls xstmts '}'
1450 { emit_line_note (input_filename, lineno);
1451 expand_end_bindings (getdecls (), 1, 0);
1452 $$ = poplevel (1, 1, 0);
1454 | '{' pushlevel maybe_label_decls error '}'
1455 { emit_line_note (input_filename, lineno);
1456 expand_end_bindings (getdecls (), kept_level_p (), 0);
1457 $$ = poplevel (kept_level_p (), 0, 0);
1459 | '{' pushlevel maybe_label_decls stmts '}'
1460 { emit_line_note (input_filename, lineno);
1461 expand_end_bindings (getdecls (), kept_level_p (), 0);
1462 $$ = poplevel (kept_level_p (), 0, 0);
1466 /* Value is number of statements counted as of the closeparen. */
1468 if_prefix lineno_labeled_stmt
1469 /* Make sure expand_end_cond is run once
1470 for each call to expand_start_cond.
1471 Otherwise a crash is likely. */
1477 { emit_line_note ($<filename>-1, $<lineno>0);
1478 expand_start_cond (truthvalue_conversion ($3), 0);
1479 $<itype>1 = stmt_count;
1480 if_stmt_file = $<filename>-1;
1481 if_stmt_line = $<lineno>0;
1482 position_after_white_space (); }
1485 /* This is a subroutine of stmt.
1486 It is used twice, once for valid DO statements
1487 and once for catching errors in parsing the end test. */
1491 emit_line_note ($<filename>-1, $<lineno>0);
1492 /* See comment in `while' alternative, above. */
1494 expand_start_loop_continue_elsewhere (1);
1495 position_after_white_space (); }
1496 lineno_labeled_stmt WHILE
1497 { expand_loop_continue_here (); }
1501 { $$ = input_filename; }
1508 lineno_labeled_stmt:
1509 save_filename save_lineno stmt
1511 /* | save_filename save_lineno error
1514 | save_filename save_lineno label lineno_labeled_stmt
1518 lineno_stmt_or_label:
1519 save_filename save_lineno stmt_or_label
1527 position_after_white_space ();
1528 next = getc (finput);
1529 ungetc (next, finput);
1530 if (pedantic && next == '}')
1531 pedwarn ("ANSI C forbids label at end of compound statement");
1535 /* Parse a single real statement, not including any labels. */
1541 emit_line_note ($<filename>-1, $<lineno>0);
1542 c_expand_expr_stmt ($1);
1543 clear_momentary (); }
1545 { expand_start_else ();
1546 $<itype>1 = stmt_count;
1547 position_after_white_space (); }
1549 { expand_end_cond ();
1550 if (extra_warnings && stmt_count == $<itype>1)
1551 warning ("empty body in an else-statement"); }
1552 | simple_if %prec IF
1553 { expand_end_cond ();
1554 if (extra_warnings && stmt_count == $<itype>1)
1555 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1556 "empty body in an if-statement"); }
1557 /* Make sure expand_end_cond is run once
1558 for each call to expand_start_cond.
1559 Otherwise a crash is likely. */
1560 | simple_if ELSE error
1561 { expand_end_cond (); }
1564 emit_line_note ($<filename>-1, $<lineno>0);
1565 /* The emit_nop used to come before emit_line_note,
1566 but that made the nop seem like part of the preceding line.
1567 And that was confusing when the preceding line was
1568 inside of an if statement and was not really executed.
1569 I think it ought to work to put the nop after the line number.
1570 We will see. --rms, July 15, 1991. */
1573 { /* Don't start the loop till we have succeeded
1574 in parsing the end test. This is to make sure
1575 that we end every loop we start. */
1576 expand_start_loop (1);
1577 emit_line_note (input_filename, lineno);
1578 expand_exit_loop_if_false (NULL_PTR,
1579 truthvalue_conversion ($4));
1580 position_after_white_space (); }
1582 { expand_end_loop (); }
1585 { emit_line_note (input_filename, lineno);
1586 expand_exit_loop_if_false (NULL_PTR,
1587 truthvalue_conversion ($3));
1589 clear_momentary (); }
1590 /* This rule is needed to make sure we end every loop we start. */
1591 | do_stmt_start error
1592 { expand_end_loop ();
1593 clear_momentary (); }
1597 emit_line_note ($<filename>-1, $<lineno>0);
1598 /* See comment in `while' alternative, above. */
1600 if ($3) c_expand_expr_stmt ($3);
1601 /* Next step is to call expand_start_loop_continue_elsewhere,
1602 but wait till after we parse the entire for (...).
1603 Otherwise, invalid input might cause us to call that
1604 fn without calling expand_end_loop. */
1607 /* Can't emit now; wait till after expand_start_loop... */
1608 { $<lineno>7 = lineno;
1609 $<filename>$ = input_filename; }
1612 /* Start the loop. Doing this after parsing
1613 all the expressions ensures we will end the loop. */
1614 expand_start_loop_continue_elsewhere (1);
1615 /* Emit the end-test, with a line number. */
1616 emit_line_note ($<filename>8, $<lineno>7);
1618 expand_exit_loop_if_false (NULL_PTR,
1619 truthvalue_conversion ($6));
1620 /* Don't let the tree nodes for $9 be discarded by
1621 clear_momentary during the parsing of the next stmt. */
1623 $<lineno>7 = lineno;
1624 $<filename>8 = input_filename;
1625 position_after_white_space (); }
1627 { /* Emit the increment expression, with a line number. */
1628 emit_line_note ($<filename>8, $<lineno>7);
1629 expand_loop_continue_here ();
1631 c_expand_expr_stmt ($9);
1633 expand_end_loop (); }
1634 | SWITCH '(' expr ')'
1636 emit_line_note ($<filename>-1, $<lineno>0);
1637 c_expand_start_case ($3);
1638 /* Don't let the tree nodes for $3 be discarded by
1639 clear_momentary during the parsing of the next stmt. */
1641 position_after_white_space (); }
1643 { expand_end_case ($3);
1647 emit_line_note ($<filename>-1, $<lineno>0);
1648 if ( ! expand_exit_something ())
1649 error ("break statement not within loop or switch"); }
1652 emit_line_note ($<filename>-1, $<lineno>0);
1653 if (! expand_continue_loop (NULL_PTR))
1654 error ("continue statement not within a loop"); }
1657 emit_line_note ($<filename>-1, $<lineno>0);
1658 c_expand_return (NULL_TREE); }
1661 emit_line_note ($<filename>-1, $<lineno>0);
1662 c_expand_return ($2); }
1663 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1665 emit_line_note ($<filename>-1, $<lineno>0);
1667 if ((TREE_CODE ($4) == ADDR_EXPR
1668 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1669 || TREE_CODE ($4) == STRING_CST)
1672 error ("argument of `asm' is not a constant string"); }
1673 /* This is the case with just output operands. */
1674 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1676 emit_line_note ($<filename>-1, $<lineno>0);
1677 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1678 $2 == ridpointers[(int)RID_VOLATILE],
1679 input_filename, lineno); }
1680 /* This is the case with input operands as well. */
1681 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1683 emit_line_note ($<filename>-1, $<lineno>0);
1684 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1685 $2 == ridpointers[(int)RID_VOLATILE],
1686 input_filename, lineno); }
1687 /* This is the case with clobbered registers as well. */
1688 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1689 asm_operands ':' asm_clobbers ')' ';'
1691 emit_line_note ($<filename>-1, $<lineno>0);
1692 c_expand_asm_operands ($4, $6, $8, $10,
1693 $2 == ridpointers[(int)RID_VOLATILE],
1694 input_filename, lineno); }
1695 | GOTO identifier ';'
1698 emit_line_note ($<filename>-1, $<lineno>0);
1699 decl = lookup_label ($2);
1702 TREE_USED (decl) = 1;
1708 emit_line_note ($<filename>-1, $<lineno>0);
1709 expand_computed_goto (convert (ptr_type_node, $3)); }
1713 /* Any kind of label, including jump labels and case labels.
1714 ANSI C accepts labels only before statements, but we allow them
1715 also at the end of a compound statement. */
1717 label: CASE expr_no_commas ':'
1718 { register tree value = check_case_value ($2);
1720 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1724 if (value != error_mark_node)
1727 int success = pushcase (value, label, &duplicate);
1729 error ("case label not within a switch statement");
1730 else if (success == 2)
1732 error ("duplicate case value");
1733 error_with_decl (duplicate, "this is the first entry for that value");
1735 else if (success == 3)
1736 warning ("case value out of range");
1737 else if (success == 5)
1738 error ("case label within scope of cleanup or variable array");
1740 position_after_white_space (); }
1741 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1742 { register tree value1 = check_case_value ($2);
1743 register tree value2 = check_case_value ($4);
1745 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1749 if (value1 != error_mark_node && value2 != error_mark_node)
1752 int success = pushcase_range (value1, value2, label,
1755 error ("case label not within a switch statement");
1756 else if (success == 2)
1758 error ("duplicate case value");
1759 error_with_decl (duplicate, "this is the first entry for that value");
1761 else if (success == 3)
1762 warning ("case value out of range");
1763 else if (success == 4)
1764 warning ("empty case range");
1765 else if (success == 5)
1766 error ("case label within scope of cleanup or variable array");
1768 position_after_white_space (); }
1773 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1774 int success = pushcase (NULL_TREE, label, &duplicate);
1777 error ("default label not within a switch statement");
1778 else if (success == 2)
1780 error ("multiple default labels in one switch");
1781 error_with_decl (duplicate, "this is the first default label");
1783 position_after_white_space (); }
1785 { tree label = define_label (input_filename, lineno, $1);
1789 expand_label (label);
1790 position_after_white_space (); }
1793 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
1797 { emit_line_note (input_filename, lineno); }
1799 { emit_line_note (input_filename, lineno); }
1808 /* These are the operands other than the first string and colon
1809 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
1810 asm_operands: /* empty */
1812 | nonnull_asm_operands
1815 nonnull_asm_operands:
1817 | nonnull_asm_operands ',' asm_operand
1818 { $$ = chainon ($1, $3); }
1823 { $$ = build_tree_list ($1, $3); }
1828 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
1829 | asm_clobbers ',' string
1830 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
1833 /* This is what appears inside the parens in a function declarator.
1834 Its value is a list of ..._TYPE nodes. */
1837 clear_parm_order ();
1838 declare_parm_level (0); }
1841 parmlist_tags_warning ();
1842 poplevel (0, 0, 0); }
1850 pedwarn ("ANSI C forbids forward parameter declarations");
1851 /* Mark the forward decls as such. */
1852 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
1853 TREE_ASM_WRITTEN (parm) = 1;
1854 clear_parm_order (); }
1858 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
1861 /* This is what appears inside the parens in a function declarator.
1862 Is value is represented in the format that grokdeclarator expects. */
1863 parmlist_2: /* empty */
1864 { $$ = get_parm_info (0); }
1866 { $$ = get_parm_info (0);
1868 pedwarn ("ANSI C requires a named argument before `...'");
1871 { $$ = get_parm_info (1); }
1872 | parms ',' ELLIPSIS
1873 { $$ = get_parm_info (0); }
1878 { push_parm_decl ($1); }
1880 { push_parm_decl ($3); }
1883 /* A single parameter declaration or parameter type name,
1884 as found in a parmlist. */
1886 typed_declspecs parm_declarator
1887 { $$ = build_tree_list ($1, $2) ; }
1888 | typed_declspecs notype_declarator
1889 { $$ = build_tree_list ($1, $2) ; }
1890 | typed_declspecs absdcl
1891 { $$ = build_tree_list ($1, $2); }
1892 | declmods notype_declarator
1893 { $$ = build_tree_list ($1, $2) ; }
1895 { $$ = build_tree_list ($1, $2); }
1898 /* This is used in a function definition
1899 where either a parmlist or an identifier list is ok.
1900 Its value is a list of ..._TYPE nodes or a list of identifiers. */
1901 parmlist_or_identifiers:
1903 clear_parm_order ();
1904 declare_parm_level (1); }
1905 parmlist_or_identifiers_1
1907 parmlist_tags_warning ();
1908 poplevel (0, 0, 0); }
1911 parmlist_or_identifiers_1:
1915 for (t = $1; t; t = TREE_CHAIN (t))
1916 if (TREE_VALUE (t) == NULL_TREE)
1917 error ("`...' in old-style identifier list");
1918 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
1921 /* A nonempty list of identifiers. */
1924 { $$ = build_tree_list (NULL_TREE, $1); }
1925 | identifiers ',' IDENTIFIER
1926 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
1929 /* A nonempty list of identifiers, including typenames. */
1930 identifiers_or_typenames:
1932 { $$ = build_tree_list (NULL_TREE, $1); }
1933 | identifiers_or_typenames ',' identifier
1934 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
1938 /* Objective-C productions. */
1945 if (objc_implementation_context)
1947 finish_class (objc_implementation_context);
1948 objc_ivar_chain = NULL_TREE;
1949 objc_implementation_context = NULL_TREE;
1952 warning ("`@end' must appear in an implementation context");
1957 INTERFACE identifier '{'
1959 objc_interface_context = objc_ivar_context
1960 = start_class (INTERFACE_TYPE, $2, NULL_TREE);
1961 objc_public_flag = 0;
1965 continue_class (objc_interface_context);
1970 finish_class (objc_interface_context);
1971 objc_interface_context = NULL_TREE;
1974 | INTERFACE identifier
1976 objc_interface_context
1977 = start_class (INTERFACE_TYPE, $2, NULL_TREE);
1978 continue_class (objc_interface_context);
1983 finish_class (objc_interface_context);
1984 objc_interface_context = NULL_TREE;
1987 | INTERFACE identifier ':' identifier '{'
1989 objc_interface_context = objc_ivar_context
1990 = start_class (INTERFACE_TYPE, $2, $4);
1991 objc_public_flag = 0;
1995 continue_class (objc_interface_context);
2000 finish_class (objc_interface_context);
2001 objc_interface_context = NULL_TREE;
2004 | INTERFACE identifier ':' identifier
2006 objc_interface_context
2007 = start_class (INTERFACE_TYPE, $2, $4);
2008 continue_class (objc_interface_context);
2013 finish_class (objc_interface_context);
2014 objc_interface_context = NULL_TREE;
2017 | IMPLEMENTATION identifier '{'
2019 objc_implementation_context = objc_ivar_context
2020 = start_class (IMPLEMENTATION_TYPE, $2, NULL_TREE);
2021 objc_public_flag = 0;
2026 = continue_class (objc_implementation_context);
2029 | IMPLEMENTATION identifier
2031 objc_implementation_context
2032 = start_class (IMPLEMENTATION_TYPE, $2, NULL_TREE);
2034 = continue_class (objc_implementation_context);
2037 | IMPLEMENTATION identifier ':' identifier '{'
2039 objc_implementation_context = objc_ivar_context
2040 = start_class (IMPLEMENTATION_TYPE, $2, $4);
2041 objc_public_flag = 0;
2046 = continue_class (objc_implementation_context);
2049 | IMPLEMENTATION identifier ':' identifier
2051 objc_implementation_context
2052 = start_class (IMPLEMENTATION_TYPE, $2, $4);
2054 = continue_class (objc_implementation_context);
2057 | INTERFACE identifier '(' identifier ')'
2059 objc_interface_context
2060 = start_class (PROTOCOL_TYPE, $2, $4);
2061 continue_class (objc_interface_context);
2066 finish_class (objc_interface_context);
2067 objc_interface_context = NULL_TREE;
2070 | IMPLEMENTATION identifier '(' identifier ')'
2072 objc_implementation_context
2073 = start_class (CATEGORY_TYPE, $2, $4);
2075 = continue_class (objc_implementation_context);
2080 ivar_decls PUBLIC { objc_public_flag = 1; } ivar_decls
2089 | ivar_decls ivar_decl ';'
2093 warning ("extra semicolon in struct or union specified");
2098 /* There is a shift-reduce conflict here, because `components' may
2099 start with a `typename'. It happens that shifting (the default resolution)
2100 does the right thing, because it treats the `typename' as part of
2101 a `typed_typespecs'.
2103 It is possible that this same technique would allow the distinction
2104 between `notype_initdecls' and `initdecls' to be eliminated.
2105 But I am being cautious and not trying it. */
2108 typed_typespecs setspecs ivars
2111 resume_momentary ($2);
2113 | nonempty_type_quals setspecs ivars
2116 resume_momentary ($2);
2126 | ivars ',' ivar_declarator
2132 $$ = add_instance_variable (objc_ivar_context,
2134 $1, current_declspecs,
2137 | declarator ':' expr_no_commas
2139 $$ = add_instance_variable (objc_ivar_context,
2141 $1, current_declspecs, $3);
2143 | ':' expr_no_commas
2145 $$ = add_instance_variable (objc_ivar_context,
2148 current_declspecs, $2);
2155 if (objc_implementation_context)
2156 objc_inherit_code = CLASS_METHOD_DECL;
2158 fatal ("method definition not in class context");
2162 add_class_method (objc_implementation_context, $3);
2163 start_method_def ($3);
2164 objc_method_context = $3;
2168 continue_method_def ();
2172 finish_method_def ();
2173 objc_method_context = NULL_TREE;
2178 if (objc_implementation_context)
2179 objc_inherit_code = INSTANCE_METHOD_DECL;
2181 fatal ("method definition not in class context");
2185 add_instance_method (objc_implementation_context, $3);
2186 start_method_def ($3);
2187 objc_method_context = $3;
2191 continue_method_def ();
2195 finish_method_def ();
2196 objc_method_context = NULL_TREE;
2200 /* the reason for the strange actions in this rule
2201 is so that notype_initdecls when reached via datadef
2202 can find a valid list of type and sc specs in $0. */
2206 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2209 methodprotolist2: /* eliminates a shift/reduce conflict */
2212 | methodprotolist2 methodproto
2213 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2224 objc_inherit_code = CLASS_METHOD_DECL;
2228 add_class_method (objc_interface_context, $3);
2234 objc_inherit_code = INSTANCE_METHOD_DECL;
2238 add_instance_method (objc_interface_context, $3);
2244 '(' typename ')' unaryselector
2246 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2251 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2254 | '(' typename ')' keywordselector optparmlist
2256 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2259 | keywordselector optparmlist
2261 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2265 /* "optarglist" assumes that start_method_def has already been called...
2266 if it is not, the "xdecls" will not be placed in the proper scope */
2273 /* to get around the following situation: "int foo (int a) int b; {}" that
2274 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2289 typed_declspecs setspecs myparms ';'
2290 { resume_momentary ($2); }
2291 | typed_declspecs ';'
2292 { shadow_tag ($1); }
2294 { pedwarn ("empty declaration"); }
2299 { push_parm_decl ($1); }
2300 | myparms ',' myparm
2301 { push_parm_decl ($3); }
2304 /* A single parameter declaration or parameter type name,
2305 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2309 { $$ = build_tree_list (current_declspecs, $1) ; }
2311 { $$ = build_tree_list (current_declspecs, $1) ; }
2313 { $$ = build_tree_list (current_declspecs, $1) ; }
2323 /* oh what a kludge! */
2332 /* returns a tree list node generated by get_parm_info */
2345 | keywordselector keyworddecl
2347 $$ = chainon ($1, $2);
2358 ENUM { $$ = get_identifier (token_buffer); }
2359 | STRUCT { $$ = get_identifier (token_buffer); }
2360 | UNION { $$ = get_identifier (token_buffer); }
2361 | IF { $$ = get_identifier (token_buffer); }
2362 | ELSE { $$ = get_identifier (token_buffer); }
2363 | WHILE { $$ = get_identifier (token_buffer); }
2364 | DO { $$ = get_identifier (token_buffer); }
2365 | FOR { $$ = get_identifier (token_buffer); }
2366 | SWITCH { $$ = get_identifier (token_buffer); }
2367 | CASE { $$ = get_identifier (token_buffer); }
2368 | DEFAULT { $$ = get_identifier (token_buffer); }
2369 | BREAK { $$ = get_identifier (token_buffer); }
2370 | CONTINUE { $$ = get_identifier (token_buffer); }
2371 | RETURN { $$ = get_identifier (token_buffer); }
2372 | GOTO { $$ = get_identifier (token_buffer); }
2373 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2374 | SIZEOF { $$ = get_identifier (token_buffer); }
2375 | TYPEOF { $$ = get_identifier (token_buffer); }
2376 | ALIGNOF { $$ = get_identifier (token_buffer); }
2377 | TYPESPEC | TYPE_QUAL
2381 selector ':' '(' typename ')' identifier
2383 $$ = build_keyword_decl ($1, $4, $6);
2386 | selector ':' identifier
2388 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2391 | ':' '(' typename ')' identifier
2393 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2398 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2409 | keywordarglist keywordarg
2411 $$ = chainon ($1, $2);
2419 if (TREE_CHAIN ($1) == NULL_TREE)
2420 /* just return the expr., remove a level of indirection */
2421 $$ = TREE_VALUE ($1);
2423 /* we have a comma expr., we will collapse later */
2429 selector ':' keywordexpr
2431 $$ = build_tree_list ($1, $3);
2435 $$ = build_tree_list (NULL_TREE, $2);
2443 $$ = get_class_reference ($1);
2449 { objc_receiver_context = 1; }
2451 { objc_receiver_context = 0; }
2454 $$ = build_tree_list ($3, $5);
2465 | keywordnamelist keywordname
2467 $$ = chainon ($1, $2);
2474 $$ = build_tree_list ($1, NULL_TREE);
2478 $$ = build_tree_list (NULL_TREE, NULL_TREE);
2483 SELECTOR '(' selectorarg ')'
2489 /* extension to support C-structures in the archiver */
2492 ENCODE '(' typename ')'
2494 $$ = groktypename ($3);
2502 /* If STRING is the name of an Objective C @-keyword
2503 (not including the @), return the token type for that keyword.
2504 Otherwise return 0. */
2507 recognize_objc_keyword (string)
2513 if (!strcmp (string, "defs"))
2517 if (!strcmp (string, "end"))
2519 if (!strcmp (string, "encode"))
2523 if (!strcmp (string, "interface"))
2525 if (!strcmp (string, "implementation"))
2526 return IMPLEMENTATION;
2529 if (!strcmp (string, "public"))
2533 if (!strcmp (string, "selector"))