1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 88, 89, 92-97, 1998 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* This file defines the grammar of C and that of Objective C.
22 ifobjc ... end ifobjc conditionals contain code for Objective C only.
23 ifc ... end ifc conditionals contain code for C only.
24 Sed commands in Makefile.in are used to convert this file into
25 c-parse.y and into objc-parse.y. */
27 /* To whomever it may concern: I have heard that such a thing was once
28 written by AT&T, but I have never seen it. */
36 /* These are the 23 conflicts you should get in parse.output;
37 the state numbers may vary if minor changes in the grammar are made.
39 State 42 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
40 State 44 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 110 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
43 State 111 contains 1 shift/reduce conflict. (Two ways to recover from error.)
44 State 115 contains 1 shift/reduce conflict. (Two ways to recover from error.)
45 State 132 contains 1 shift/reduce conflict. (See comment at component_decl.)
46 State 180 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.)
47 State 194 contains 2 shift/reduce conflict. (Four ways to parse this.)
48 State 202 contains 1 shift/reduce conflict. (Two ways to recover from error.)
49 State 214 contains 1 shift/reduce conflict. (Two ways to recover from error.)
50 State 220 contains 1 shift/reduce conflict. (Two ways to recover from error.)
51 State 304 contains 2 shift/reduce conflicts. (Four ways to parse this.)
52 State 335 contains 2 shift/reduce conflicts. (Four ways to parse this.)
53 State 347 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
54 State 352 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.)
55 State 383 contains 2 shift/reduce conflicts. (Four ways to parse this.)
56 State 434 contains 2 shift/reduce conflicts. (Four ways to parse this.) */
73 #ifdef MULTIBYTE_CHARS
81 /* Since parsers are distinct for each language, put the language string
84 char *language_string = "GNU Obj-C";
87 char *language_string = "GNU C";
90 /* Like YYERROR but do call yyerror. */
91 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
93 /* Cause the `yydebug' variable to be defined. */
99 %union {long itype; tree ttype; enum tree_code code;
100 char *filename; int lineno; int ends_in_label; }
102 /* All identifiers that are not reserved words
103 and are not declared typedefs in the current block */
106 /* All identifiers that are declared typedefs in the current block.
107 In some contexts, they are treated just like IDENTIFIER,
108 but they can also serve as typespecs in declarations. */
111 /* Reserved words that specify storage class.
112 yylval contains an IDENTIFIER_NODE which indicates which one. */
115 /* Reserved words that specify type.
116 yylval contains an IDENTIFIER_NODE which indicates which one. */
119 /* Reserved words that qualify type: "const" or "volatile".
120 yylval contains an IDENTIFIER_NODE which indicates which one. */
123 /* Character or numeric constants.
124 yylval is the node for the constant. */
127 /* String constants in raw form.
128 yylval is a STRING_CST node. */
131 /* "...", used for functions with variable arglists. */
134 /* the reserved words */
135 /* SCO include files test "ASM", so use something else. */
136 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
137 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
138 %token ATTRIBUTE EXTENSION LABEL
139 %token REALPART IMAGPART
141 /* Add precedence rules to solve dangling else s/r conflict */
145 /* Define the operator tokens and their precedences.
146 The value is an integer because, if used, it is the tree code
147 to use in the expression made from the operator. */
149 %right <code> ASSIGN '='
150 %right <code> '?' ':'
156 %left <code> EQCOMPARE
157 %left <code> ARITHCOMPARE
158 %left <code> LSHIFT RSHIFT
160 %left <code> '*' '/' '%'
161 %right <code> UNARY PLUSPLUS MINUSMINUS
163 %left <code> POINTSAT '.' '(' '['
165 /* The Objective-C keywords. These are included in C and in
166 Objective C, so that the token codes are the same in both. */
167 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
168 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
170 /* Objective-C string constants in raw form.
171 yylval is an OBJC_STRING_CST node. */
177 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
178 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
179 %type <ttype> typed_declspecs reserved_declspecs
180 %type <ttype> typed_typespecs reserved_typespecquals
181 %type <ttype> declmods typespec typespecqual_reserved
182 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
183 %type <ttype> declmods_no_prefix_attr
184 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
185 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
186 %type <ttype> init maybeasm
187 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
188 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
189 %type <ttype> any_word
191 %type <ttype> compstmt
193 %type <ttype> declarator
194 %type <ttype> notype_declarator after_type_declarator
195 %type <ttype> parm_declarator
197 %type <ttype> structsp component_decl_list component_decl_list2
198 %type <ttype> component_decl components component_declarator
199 %type <ttype> enumlist enumerator
200 %type <ttype> struct_head union_head enum_head
201 %type <ttype> typename absdcl absdcl1 type_quals
202 %type <ttype> xexpr parms parm identifiers
204 %type <ttype> parmlist parmlist_1 parmlist_2
205 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
206 %type <ttype> identifiers_or_typenames
208 %type <itype> setspecs
210 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
212 %type <filename> save_filename
213 %type <lineno> save_lineno
216 /* the Objective-C nonterminals */
218 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
219 %type <ttype> methoddecl unaryselector keywordselector selector
220 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
221 %type <ttype> keywordexpr keywordarglist keywordarg
222 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
223 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
224 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
226 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
230 /* Number of statements (loosely speaking) and compound statements
232 static int stmt_count;
233 static int compstmt_count;
235 /* Input file and line number of the end of the body of last simple_if;
236 used by the stmt-rule immediately after simple_if returns. */
237 static char *if_stmt_file;
238 static int if_stmt_line;
240 /* List of types and structure classes of the current declaration. */
241 static tree current_declspecs = NULL_TREE;
242 static tree prefix_attributes = NULL_TREE;
244 /* Stack of saved values of current_declspecs and prefix_attributes. */
245 static tree declspec_stack;
247 /* 1 if we explained undeclared var errors. */
248 static int undeclared_variable_notice;
251 /* Objective-C specific information */
253 tree objc_interface_context;
254 tree objc_implementation_context;
255 tree objc_method_context;
256 tree objc_ivar_chain;
257 tree objc_ivar_context;
258 enum tree_code objc_inherit_code;
259 int objc_receiver_context;
260 int objc_public_flag;
264 /* Tell yyparse how to print a token's value, if yydebug is set. */
266 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
267 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
273 pedwarn ("ANSI C forbids an empty source file");
278 /* In case there were missing closebraces,
279 get us back to the global binding level. */
280 while (! global_bindings_p ())
286 /* the reason for the strange actions in this rule
287 is so that notype_initdecls when reached via datadef
288 can find a valid list of type and sc specs in $0. */
291 {$<ttype>$ = NULL_TREE; } extdef
292 | extdefs {$<ttype>$ = NULL_TREE; } extdef
301 | ASM_KEYWORD '(' expr ')' ';'
303 if ((TREE_CODE ($3) == ADDR_EXPR
304 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
305 || TREE_CODE ($3) == STRING_CST)
308 error ("argument of `asm' is not a constant string"); }
310 { pedantic = $<itype>1; }
314 setspecs notype_initdecls ';'
316 error ("ANSI C forbids data definition with no type or storage class");
317 else if (!flag_traditional)
318 warning ("data definition has no type or storage class");
320 current_declspecs = TREE_VALUE (declspec_stack);
321 prefix_attributes = TREE_PURPOSE (declspec_stack);
322 declspec_stack = TREE_CHAIN (declspec_stack);
323 resume_momentary ($1); }
324 | declmods setspecs notype_initdecls ';'
325 { current_declspecs = TREE_VALUE (declspec_stack);
326 prefix_attributes = TREE_PURPOSE (declspec_stack);
327 declspec_stack = TREE_CHAIN (declspec_stack);
328 resume_momentary ($2); }
329 | typed_declspecs setspecs initdecls ';'
330 { current_declspecs = TREE_VALUE (declspec_stack);
331 prefix_attributes = TREE_PURPOSE (declspec_stack);
332 declspec_stack = TREE_CHAIN (declspec_stack);
333 resume_momentary ($2); }
335 { pedwarn ("empty declaration"); }
336 | typed_declspecs ';'
342 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
346 typed_declspecs setspecs declarator
347 { if (! start_function (current_declspecs, $3,
348 prefix_attributes, NULL_TREE, 0))
350 reinit_parse_for_function (); }
352 { store_parm_decls (); }
354 { finish_function (0);
355 current_declspecs = TREE_VALUE (declspec_stack);
356 prefix_attributes = TREE_PURPOSE (declspec_stack);
357 declspec_stack = TREE_CHAIN (declspec_stack);
358 resume_momentary ($2); }
359 | typed_declspecs setspecs declarator error
360 { current_declspecs = TREE_VALUE (declspec_stack);
361 prefix_attributes = TREE_PURPOSE (declspec_stack);
362 declspec_stack = TREE_CHAIN (declspec_stack);
363 resume_momentary ($2); }
364 | declmods setspecs notype_declarator
365 { if (! start_function (current_declspecs, $3,
366 prefix_attributes, NULL_TREE, 0))
368 reinit_parse_for_function (); }
370 { store_parm_decls (); }
372 { finish_function (0);
373 current_declspecs = TREE_VALUE (declspec_stack);
374 prefix_attributes = TREE_PURPOSE (declspec_stack);
375 declspec_stack = TREE_CHAIN (declspec_stack);
376 resume_momentary ($2); }
377 | declmods setspecs notype_declarator error
378 { current_declspecs = TREE_VALUE (declspec_stack);
379 prefix_attributes = TREE_PURPOSE (declspec_stack);
380 declspec_stack = TREE_CHAIN (declspec_stack);
381 resume_momentary ($2); }
382 | setspecs notype_declarator
383 { if (! start_function (NULL_TREE, $2,
384 prefix_attributes, NULL_TREE, 0))
386 reinit_parse_for_function (); }
388 { store_parm_decls (); }
390 { finish_function (0);
391 current_declspecs = TREE_VALUE (declspec_stack);
392 prefix_attributes = TREE_PURPOSE (declspec_stack);
393 declspec_stack = TREE_CHAIN (declspec_stack);
394 resume_momentary ($1); }
395 | setspecs notype_declarator error
396 { current_declspecs = TREE_VALUE (declspec_stack);
397 prefix_attributes = TREE_PURPOSE (declspec_stack);
398 declspec_stack = TREE_CHAIN (declspec_stack);
399 resume_momentary ($1); }
414 { $$ = NEGATE_EXPR; }
416 { $$ = CONVERT_EXPR; }
418 { $$ = PREINCREMENT_EXPR; }
420 { $$ = PREDECREMENT_EXPR; }
422 { $$ = BIT_NOT_EXPR; }
424 { $$ = TRUTH_NOT_EXPR; }
427 expr: nonnull_exprlist
428 { $$ = build_compound_expr ($1); }
439 { $$ = build_tree_list (NULL_TREE, $1); }
440 | nonnull_exprlist ',' expr_no_commas
441 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
446 | '*' cast_expr %prec UNARY
447 { $$ = build_indirect_ref ($2, "unary *"); }
448 /* __extension__ turns off -pedantic for following primary. */
449 | extension cast_expr %prec UNARY
451 pedantic = $<itype>1; }
452 | unop cast_expr %prec UNARY
453 { $$ = build_unary_op ($1, $2, 0);
454 overflow_warning ($$); }
455 /* Refer to the address of a label as a pointer. */
457 { tree label = lookup_label ($2);
459 pedwarn ("ANSI C forbids `&&'");
461 $$ = null_pointer_node;
464 TREE_USED (label) = 1;
465 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
466 TREE_CONSTANT ($$) = 1;
469 /* This seems to be impossible on some machines, so let's turn it off.
470 You can use __builtin_next_arg to find the anonymous stack args.
472 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
473 $$ = error_mark_node;
474 if (TREE_VALUE (tree_last (types)) == void_type_node)
475 error ("`&...' used in function with fixed number of arguments");
479 pedwarn ("ANSI C forbids `&...'");
480 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
481 $$ = build_unary_op (ADDR_EXPR, $$, 0);
484 | sizeof unary_expr %prec UNARY
486 if (TREE_CODE ($2) == COMPONENT_REF
487 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
488 error ("`sizeof' applied to a bit-field");
489 $$ = c_sizeof (TREE_TYPE ($2)); }
490 | sizeof '(' typename ')' %prec HYPERUNARY
492 $$ = c_sizeof (groktypename ($3)); }
493 | alignof unary_expr %prec UNARY
495 $$ = c_alignof_expr ($2); }
496 | alignof '(' typename ')' %prec HYPERUNARY
498 $$ = c_alignof (groktypename ($3)); }
499 | REALPART cast_expr %prec UNARY
500 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
501 | IMAGPART cast_expr %prec UNARY
502 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
506 SIZEOF { skip_evaluation++; }
510 ALIGNOF { skip_evaluation++; }
515 | '(' typename ')' cast_expr %prec UNARY
516 { tree type = groktypename ($2);
517 $$ = build_c_cast (type, $4); }
518 | '(' typename ')' '{'
519 { start_init (NULL_TREE, NULL, 0);
520 $2 = groktypename ($2);
521 really_start_incremental_init ($2); }
522 initlist_maybe_comma '}' %prec UNARY
524 tree result = pop_init_level (0);
529 pedwarn ("ANSI C forbids constructor expressions");
530 if (TYPE_NAME (type) != 0)
532 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
533 name = IDENTIFIER_POINTER (TYPE_NAME (type));
535 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
540 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
542 int failure = complete_array_type (type, $$, 1);
551 | expr_no_commas '+' expr_no_commas
552 { $$ = parser_build_binary_op ($2, $1, $3); }
553 | expr_no_commas '-' expr_no_commas
554 { $$ = parser_build_binary_op ($2, $1, $3); }
555 | expr_no_commas '*' expr_no_commas
556 { $$ = parser_build_binary_op ($2, $1, $3); }
557 | expr_no_commas '/' expr_no_commas
558 { $$ = parser_build_binary_op ($2, $1, $3); }
559 | expr_no_commas '%' expr_no_commas
560 { $$ = parser_build_binary_op ($2, $1, $3); }
561 | expr_no_commas LSHIFT expr_no_commas
562 { $$ = parser_build_binary_op ($2, $1, $3); }
563 | expr_no_commas RSHIFT expr_no_commas
564 { $$ = parser_build_binary_op ($2, $1, $3); }
565 | expr_no_commas ARITHCOMPARE expr_no_commas
566 { $$ = parser_build_binary_op ($2, $1, $3); }
567 | expr_no_commas EQCOMPARE expr_no_commas
568 { $$ = parser_build_binary_op ($2, $1, $3); }
569 | expr_no_commas '&' expr_no_commas
570 { $$ = parser_build_binary_op ($2, $1, $3); }
571 | expr_no_commas '|' expr_no_commas
572 { $$ = parser_build_binary_op ($2, $1, $3); }
573 | expr_no_commas '^' expr_no_commas
574 { $$ = parser_build_binary_op ($2, $1, $3); }
575 | expr_no_commas ANDAND
576 { $1 = truthvalue_conversion (default_conversion ($1));
577 skip_evaluation += $1 == boolean_false_node; }
579 { skip_evaluation -= $1 == boolean_false_node;
580 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
581 | expr_no_commas OROR
582 { $1 = truthvalue_conversion (default_conversion ($1));
583 skip_evaluation += $1 == boolean_true_node; }
585 { skip_evaluation -= $1 == boolean_true_node;
586 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
588 { $1 = truthvalue_conversion (default_conversion ($1));
589 skip_evaluation += $1 == boolean_false_node; }
591 { skip_evaluation += (($1 == boolean_true_node)
592 - ($1 == boolean_false_node)); }
594 { skip_evaluation -= $1 == boolean_true_node;
595 $$ = build_conditional_expr ($1, $4, $7); }
598 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
599 /* Make sure first operand is calculated only once. */
600 $<ttype>2 = save_expr ($1);
601 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
602 skip_evaluation += $1 == boolean_true_node; }
604 { skip_evaluation -= $1 == boolean_true_node;
605 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
606 | expr_no_commas '=' expr_no_commas
607 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
608 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
609 | expr_no_commas ASSIGN expr_no_commas
610 { $$ = build_modify_expr ($1, $2, $3);
611 /* This inhibits warnings in truthvalue_conversion. */
612 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
619 if (!$$ || $$ == error_mark_node)
621 if (yychar == YYEMPTY)
628 if (objc_receiver_context
629 && ! (objc_receiver_context
630 && strcmp (IDENTIFIER_POINTER ($1), "super")))
631 /* we have a message to super */
632 $$ = get_super_receiver ();
633 else if (objc_method_context
634 && (decl = is_ivar (objc_ivar_chain, $1)))
636 if (is_private (decl))
637 $$ = error_mark_node;
639 $$ = build_ivar_reference ($1);
644 /* Ordinary implicit function declaration. */
645 $$ = implicitly_declare ($1);
646 assemble_external ($$);
650 else if (current_function_decl == 0)
652 error ("`%s' undeclared here (not in a function)",
653 IDENTIFIER_POINTER ($1));
654 $$ = error_mark_node;
661 if (objc_receiver_context
662 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
663 /* we have a message to super */
664 $$ = get_super_receiver ();
665 else if (objc_method_context
666 && (decl = is_ivar (objc_ivar_chain, $1)))
668 if (is_private (decl))
669 $$ = error_mark_node;
671 $$ = build_ivar_reference ($1);
676 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
677 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
679 error ("`%s' undeclared (first use in this function)",
680 IDENTIFIER_POINTER ($1));
682 if (! undeclared_variable_notice)
684 error ("(Each undeclared identifier is reported only once");
685 error ("for each function it appears in.)");
686 undeclared_variable_notice = 1;
689 $$ = error_mark_node;
690 /* Prevent repeated error messages. */
691 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
692 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
696 else if (TREE_TYPE ($$) == error_mark_node)
697 $$ = error_mark_node;
698 else if (C_DECL_ANTICIPATED ($$))
700 /* The first time we see a build-in function used,
701 if it has not been declared. */
702 C_DECL_ANTICIPATED ($$) = 0;
703 if (yychar == YYEMPTY)
707 /* Omit the implicit declaration we
708 would ordinarily do, so we don't lose
709 the actual built in type.
710 But print a diagnostic for the mismatch. */
712 if (objc_method_context
713 && is_ivar (objc_ivar_chain, $1))
714 error ("Instance variable `%s' implicitly declared as function",
715 IDENTIFIER_POINTER (DECL_NAME ($$)));
718 if (TREE_CODE ($$) != FUNCTION_DECL)
719 error ("`%s' implicitly declared as function",
720 IDENTIFIER_POINTER (DECL_NAME ($$)));
721 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
722 != TYPE_MODE (integer_type_node))
723 && (TREE_TYPE (TREE_TYPE ($$))
725 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
726 IDENTIFIER_POINTER (DECL_NAME ($$)));
727 /* If it really returns void, change that to int. */
728 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
730 = build_function_type (integer_type_node,
731 TYPE_ARG_TYPES (TREE_TYPE ($$)));
734 pedwarn ("built-in function `%s' used without declaration",
735 IDENTIFIER_POINTER (DECL_NAME ($$)));
737 /* Do what we would ordinarily do when a fn is used. */
738 assemble_external ($$);
743 assemble_external ($$);
746 /* we have a definition - still check if iVariable */
748 if (!objc_receiver_context
749 || (objc_receiver_context
750 && strcmp (IDENTIFIER_POINTER ($1), "super")))
754 if (objc_method_context
755 && (decl = is_ivar (objc_ivar_chain, $1)))
757 if (IDENTIFIER_LOCAL_VALUE ($1))
758 warning ("local declaration of `%s' hides instance variable",
759 IDENTIFIER_POINTER ($1));
762 if (is_private (decl))
763 $$ = error_mark_node;
765 $$ = build_ivar_reference ($1);
769 else /* we have a message to super */
770 $$ = get_super_receiver ();
774 if (TREE_CODE ($$) == CONST_DECL)
776 $$ = DECL_INITIAL ($$);
777 /* This is to prevent an enum whose value is 0
778 from being considered a null pointer constant. */
779 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
780 TREE_CONSTANT ($$) = 1;
785 { $$ = combine_strings ($1); }
787 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
788 if (class == 'e' || class == '1'
789 || class == '2' || class == '<')
790 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
793 { $$ = error_mark_node; }
795 { if (current_function_decl == 0)
797 error ("braced-group within expression allowed only inside a function");
800 /* We must force a BLOCK for this level
801 so that, if it is not expanded later,
802 there is a way to turn off the entire subtree of blocks
803 that are contained in it. */
805 push_iterator_stack ();
807 $<ttype>$ = expand_start_stmt_expr (); }
811 pedwarn ("ANSI C forbids braced-groups within expressions");
812 pop_iterator_stack ();
814 rtl_exp = expand_end_stmt_expr ($<ttype>2);
815 /* The statements have side effects, so the group does. */
816 TREE_SIDE_EFFECTS (rtl_exp) = 1;
818 if (TREE_CODE ($3) == BLOCK)
820 /* Make a BIND_EXPR for the BLOCK already made. */
821 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
822 NULL_TREE, rtl_exp, $3);
823 /* Remove the block from the tree at this point.
824 It gets put back at the proper place
825 when the BIND_EXPR is expanded. */
831 | primary '(' exprlist ')' %prec '.'
832 { $$ = build_function_call ($1, $3); }
833 | primary '[' expr ']' %prec '.'
834 { $$ = build_array_ref ($1, $3); }
835 | primary '.' identifier
838 if (doing_objc_thang)
840 if (is_public ($1, $3))
841 $$ = build_component_ref ($1, $3);
843 $$ = error_mark_node;
847 $$ = build_component_ref ($1, $3);
849 | primary POINTSAT identifier
851 tree expr = build_indirect_ref ($1, "->");
854 if (doing_objc_thang)
856 if (is_public (expr, $3))
857 $$ = build_component_ref (expr, $3);
859 $$ = error_mark_node;
863 $$ = build_component_ref (expr, $3);
866 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
868 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
871 { $$ = build_message_expr ($1); }
873 { $$ = build_selector_expr ($1); }
875 { $$ = build_protocol_expr ($1); }
877 { $$ = build_encode_expr ($1); }
879 { $$ = build_objc_string_object ($1); }
883 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
887 { $$ = chainon ($1, $2); }
891 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
895 | objc_string OBJC_STRING
896 { $$ = chainon ($1, $2); }
900 old_style_parm_decls:
904 /* ... is used here to indicate a varargs function. */
907 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
910 /* The following are analogous to lineno_decl, decls and decl
911 except that they do not allow nested functions.
912 They are used for old-style parm decls. */
914 save_filename save_lineno datadecl
921 | datadecls lineno_datadecl
922 | lineno_datadecl errstmt
925 /* We don't allow prefix attributes here because they cause reduce/reduce
926 conflicts: we can't know whether we're parsing a function decl with
927 attribute suffix, or function defn with attribute prefix on first old
930 typed_declspecs_no_prefix_attr setspecs initdecls ';'
931 { current_declspecs = TREE_VALUE (declspec_stack);
932 prefix_attributes = TREE_PURPOSE (declspec_stack);
933 declspec_stack = TREE_CHAIN (declspec_stack);
934 resume_momentary ($2); }
935 | declmods_no_prefix_attr setspecs notype_initdecls ';'
936 { current_declspecs = TREE_VALUE (declspec_stack);
937 prefix_attributes = TREE_PURPOSE (declspec_stack);
938 declspec_stack = TREE_CHAIN (declspec_stack);
939 resume_momentary ($2); }
940 | typed_declspecs_no_prefix_attr ';'
941 { shadow_tag_warned ($1, 1);
942 pedwarn ("empty declaration"); }
943 | declmods_no_prefix_attr ';'
944 { pedwarn ("empty declaration"); }
947 /* This combination which saves a lineno before a decl
948 is the normal thing to use, rather than decl itself.
949 This is to avoid shift/reduce conflicts in contexts
950 where statement labels are allowed. */
952 save_filename save_lineno decl
960 | lineno_decl errstmt
963 /* records the type and storage class specs to use for processing
964 the declarators that follow.
965 Maintains a stack of outer-level values of current_declspecs,
966 for the sake of parm declarations nested in function declarators. */
967 setspecs: /* empty */
968 { $$ = suspend_momentary ();
969 pending_xref_error ();
970 declspec_stack = tree_cons (prefix_attributes,
973 split_specs_attrs ($<ttype>0,
974 ¤t_declspecs, &prefix_attributes); }
977 /* ??? Yuck. See after_type_declarator. */
978 setattrs: /* empty */
979 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
983 typed_declspecs setspecs initdecls ';'
984 { current_declspecs = TREE_VALUE (declspec_stack);
985 prefix_attributes = TREE_PURPOSE (declspec_stack);
986 declspec_stack = TREE_CHAIN (declspec_stack);
987 resume_momentary ($2); }
988 | declmods setspecs notype_initdecls ';'
989 { current_declspecs = TREE_VALUE (declspec_stack);
990 prefix_attributes = TREE_PURPOSE (declspec_stack);
991 declspec_stack = TREE_CHAIN (declspec_stack);
992 resume_momentary ($2); }
993 | typed_declspecs setspecs nested_function
994 { current_declspecs = TREE_VALUE (declspec_stack);
995 prefix_attributes = TREE_PURPOSE (declspec_stack);
996 declspec_stack = TREE_CHAIN (declspec_stack);
997 resume_momentary ($2); }
998 | declmods setspecs notype_nested_function
999 { current_declspecs = TREE_VALUE (declspec_stack);
1000 prefix_attributes = TREE_PURPOSE (declspec_stack);
1001 declspec_stack = TREE_CHAIN (declspec_stack);
1002 resume_momentary ($2); }
1003 | typed_declspecs ';'
1004 { shadow_tag ($1); }
1006 { pedwarn ("empty declaration"); }
1008 { pedantic = $<itype>1; }
1011 /* Declspecs which contain at least one type specifier or typedef name.
1012 (Just `const' or `volatile' is not enough.)
1013 A typedef'd name following these is taken as a name to be declared.
1014 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1017 typespec reserved_declspecs
1018 { $$ = tree_cons (NULL_TREE, $1, $2); }
1019 | declmods typespec reserved_declspecs
1020 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1023 reserved_declspecs: /* empty */
1025 | reserved_declspecs typespecqual_reserved
1026 { $$ = tree_cons (NULL_TREE, $2, $1); }
1027 | reserved_declspecs SCSPEC
1028 { if (extra_warnings)
1029 warning ("`%s' is not at beginning of declaration",
1030 IDENTIFIER_POINTER ($2));
1031 $$ = tree_cons (NULL_TREE, $2, $1); }
1032 | reserved_declspecs attributes
1033 { $$ = tree_cons ($2, NULL_TREE, $1); }
1036 typed_declspecs_no_prefix_attr:
1037 typespec reserved_declspecs_no_prefix_attr
1038 { $$ = tree_cons (NULL_TREE, $1, $2); }
1039 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
1040 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1043 reserved_declspecs_no_prefix_attr:
1046 | reserved_declspecs_no_prefix_attr typespecqual_reserved
1047 { $$ = tree_cons (NULL_TREE, $2, $1); }
1048 | reserved_declspecs_no_prefix_attr SCSPEC
1049 { if (extra_warnings)
1050 warning ("`%s' is not at beginning of declaration",
1051 IDENTIFIER_POINTER ($2));
1052 $$ = tree_cons (NULL_TREE, $2, $1); }
1055 /* List of just storage classes, type modifiers, and prefix attributes.
1056 A declaration can start with just this, but then it cannot be used
1057 to redeclare a typedef-name.
1058 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1061 declmods_no_prefix_attr
1064 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
1065 | declmods declmods_no_prefix_attr
1066 { $$ = chainon ($2, $1); }
1067 | declmods attributes
1068 { $$ = tree_cons ($2, NULL_TREE, $1); }
1071 declmods_no_prefix_attr:
1073 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1074 TREE_STATIC ($$) = 1; }
1076 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1077 | declmods_no_prefix_attr TYPE_QUAL
1078 { $$ = tree_cons (NULL_TREE, $2, $1);
1079 TREE_STATIC ($$) = 1; }
1080 | declmods_no_prefix_attr SCSPEC
1081 { if (extra_warnings && TREE_STATIC ($1))
1082 warning ("`%s' is not at beginning of declaration",
1083 IDENTIFIER_POINTER ($2));
1084 $$ = tree_cons (NULL_TREE, $2, $1);
1085 TREE_STATIC ($$) = TREE_STATIC ($1); }
1089 /* Used instead of declspecs where storage classes are not allowed
1090 (that is, for typenames and structure components).
1091 Don't accept a typedef-name if anything but a modifier precedes it. */
1094 typespec reserved_typespecquals
1095 { $$ = tree_cons (NULL_TREE, $1, $2); }
1096 | nonempty_type_quals typespec reserved_typespecquals
1097 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1100 reserved_typespecquals: /* empty */
1102 | reserved_typespecquals typespecqual_reserved
1103 { $$ = tree_cons (NULL_TREE, $2, $1); }
1106 /* A typespec (but not a type qualifier).
1107 Once we have seen one of these in a declaration,
1108 if a typedef name appears then it is being redeclared. */
1113 { /* For a typedef name, record the meaning, not the name.
1114 In case of `foo foo, bar;'. */
1115 $$ = lookup_name ($1); }
1117 | CLASSNAME protocolrefs
1118 { $$ = get_static_reference ($1, $2); }
1119 | OBJECTNAME protocolrefs
1120 { $$ = get_object_reference ($2); }
1122 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1123 - nisse@lysator.liu.se */
1124 | non_empty_protocolrefs
1125 { $$ = get_object_reference ($1); }
1127 | TYPEOF '(' expr ')'
1128 { $$ = TREE_TYPE ($3); }
1129 | TYPEOF '(' typename ')'
1130 { $$ = groktypename ($3); }
1133 /* A typespec that is a reserved word, or a type qualifier. */
1135 typespecqual_reserved: TYPESPEC
1142 | initdecls ',' initdcl
1147 | notype_initdecls ',' initdcl
1153 | ASM_KEYWORD '(' string ')'
1154 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1160 declarator maybeasm maybe_attribute '='
1161 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1162 $3, prefix_attributes);
1163 start_init ($<ttype>$, $2, global_bindings_p ()); }
1165 /* Note how the declaration of the variable is in effect while its init is parsed! */
1167 finish_decl ($<ttype>5, $6, $2); }
1168 | declarator maybeasm maybe_attribute
1169 { tree d = start_decl ($1, current_declspecs, 0,
1170 $3, prefix_attributes);
1171 finish_decl (d, NULL_TREE, $2);
1176 notype_declarator maybeasm maybe_attribute '='
1177 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1178 $3, prefix_attributes);
1179 start_init ($<ttype>$, $2, global_bindings_p ()); }
1181 /* Note how the declaration of the variable is in effect while its init is parsed! */
1183 decl_attributes ($<ttype>5, $3, prefix_attributes);
1184 finish_decl ($<ttype>5, $6, $2); }
1185 | notype_declarator maybeasm maybe_attribute
1186 { tree d = start_decl ($1, current_declspecs, 0,
1187 $3, prefix_attributes);
1188 finish_decl (d, NULL_TREE, $2); }
1190 /* the * rules are dummies to accept the Apollo extended syntax
1191 so that the header files compile. */
1202 | attributes attribute
1203 { $$ = chainon ($1, $2); }
1207 ATTRIBUTE '(' '(' attribute_list ')' ')'
1214 | attribute_list ',' attrib
1215 { $$ = chainon ($1, $3); }
1222 { $$ = build_tree_list ($1, NULL_TREE); }
1223 | any_word '(' IDENTIFIER ')'
1224 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1225 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1226 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1227 | any_word '(' exprlist ')'
1228 { $$ = build_tree_list ($1, $3); }
1231 /* This still leaves out most reserved keywords,
1232 shouldn't we include them? */
1241 /* Initializers. `init' is the entry point. */
1246 { really_start_incremental_init (NULL_TREE);
1247 /* Note that the call to clear_momentary
1248 is in process_init_element. */
1249 push_momentary (); }
1250 initlist_maybe_comma '}'
1251 { $$ = pop_init_level (0);
1252 if ($$ == error_mark_node
1253 && ! (yychar == STRING || yychar == CONSTANT))
1256 pop_momentary_nofree (); }
1259 { $$ = error_mark_node; }
1262 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1263 initlist_maybe_comma:
1266 pedwarn ("ANSI C forbids empty initializer braces"); }
1267 | initlist1 maybecomma
1272 | initlist1 ',' initelt
1275 /* `initelt' is a single element of an initializer.
1276 It may use braces. */
1279 { process_init_element ($1); }
1281 { push_init_level (0); }
1282 initlist_maybe_comma '}'
1283 { process_init_element (pop_init_level (0)); }
1285 /* These are for labeled elements. The syntax for an array element
1286 initializer conflicts with the syntax for an Objective-C message,
1287 so don't include these productions in the Objective-C grammar. */
1289 | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1290 { set_init_index ($2, $4); }
1292 | '[' expr_no_commas ']' '='
1293 { set_init_index ($2, NULL_TREE); }
1295 | '[' expr_no_commas ']'
1296 { set_init_index ($2, NULL_TREE); }
1300 { set_init_label ($1); }
1302 | '.' identifier '='
1303 { set_init_label ($2); }
1309 { push_c_function_context ();
1310 if (! start_function (current_declspecs, $1,
1311 prefix_attributes, NULL_TREE, 1))
1313 pop_c_function_context ();
1316 reinit_parse_for_function (); }
1317 old_style_parm_decls
1318 { store_parm_decls (); }
1319 /* This used to use compstmt_or_error.
1320 That caused a bug with input `f(g) int g {}',
1321 where the use of YYERROR1 above caused an error
1322 which then was handled by compstmt_or_error.
1323 There followed a repeated execution of that same rule,
1324 which called YYERROR1 again, and so on. */
1326 { finish_function (1);
1327 pop_c_function_context (); }
1330 notype_nested_function:
1332 { push_c_function_context ();
1333 if (! start_function (current_declspecs, $1,
1334 prefix_attributes, NULL_TREE, 1))
1336 pop_c_function_context ();
1339 reinit_parse_for_function (); }
1340 old_style_parm_decls
1341 { store_parm_decls (); }
1342 /* This used to use compstmt_or_error.
1343 That caused a bug with input `f(g) int g {}',
1344 where the use of YYERROR1 above caused an error
1345 which then was handled by compstmt_or_error.
1346 There followed a repeated execution of that same rule,
1347 which called YYERROR1 again, and so on. */
1349 { finish_function (1);
1350 pop_c_function_context (); }
1353 /* Any kind of declarator (thus, all declarators allowed
1354 after an explicit typespec). */
1357 after_type_declarator
1361 /* A declarator that is allowed only after an explicit typespec. */
1363 after_type_declarator:
1364 '(' after_type_declarator ')'
1366 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1367 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1368 /* | after_type_declarator '(' error ')' %prec '.'
1369 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1370 poplevel (0, 0, 0); } */
1371 | after_type_declarator '[' expr ']' %prec '.'
1372 { $$ = build_nt (ARRAY_REF, $1, $3); }
1373 | after_type_declarator '[' ']' %prec '.'
1374 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1375 | '*' type_quals after_type_declarator %prec UNARY
1376 { $$ = make_pointer_declarator ($2, $3); }
1377 /* ??? Yuck. setattrs is a quick hack. We can't use
1378 prefix_attributes because $1 only applies to this
1379 declarator. We assume setspecs has already been done.
1380 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1381 attributes could be recognized here or in `attributes'). */
1382 | attributes setattrs after_type_declarator
1390 /* Kinds of declarator that can appear in a parameter list
1391 in addition to notype_declarator. This is like after_type_declarator
1392 but does not allow a typedef name in parentheses as an identifier
1393 (because it would conflict with a function with that typedef as arg). */
1396 parm_declarator '(' parmlist_or_identifiers %prec '.'
1397 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1398 /* | parm_declarator '(' error ')' %prec '.'
1399 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1400 poplevel (0, 0, 0); } */
1401 | parm_declarator '[' expr ']' %prec '.'
1402 { $$ = build_nt (ARRAY_REF, $1, $3); }
1403 | parm_declarator '[' ']' %prec '.'
1404 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1405 | '*' type_quals parm_declarator %prec UNARY
1406 { $$ = make_pointer_declarator ($2, $3); }
1407 /* ??? Yuck. setattrs is a quick hack. We can't use
1408 prefix_attributes because $1 only applies to this
1409 declarator. We assume setspecs has already been done.
1410 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1411 attributes could be recognized here or in `attributes'). */
1412 | attributes setattrs parm_declarator
1417 /* A declarator allowed whether or not there has been
1418 an explicit typespec. These cannot redeclare a typedef-name. */
1421 notype_declarator '(' parmlist_or_identifiers %prec '.'
1422 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1423 /* | notype_declarator '(' error ')' %prec '.'
1424 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1425 poplevel (0, 0, 0); } */
1426 | '(' notype_declarator ')'
1428 | '*' type_quals notype_declarator %prec UNARY
1429 { $$ = make_pointer_declarator ($2, $3); }
1430 | notype_declarator '[' expr ']' %prec '.'
1431 { $$ = build_nt (ARRAY_REF, $1, $3); }
1432 | notype_declarator '[' ']' %prec '.'
1433 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1434 /* ??? Yuck. setattrs is a quick hack. We can't use
1435 prefix_attributes because $1 only applies to this
1436 declarator. We assume setspecs has already been done.
1437 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1438 attributes could be recognized here or in `attributes'). */
1439 | attributes setattrs notype_declarator
1466 struct_head identifier '{'
1467 { $$ = start_struct (RECORD_TYPE, $2);
1468 /* Start scope of tag before parsing components. */
1470 component_decl_list '}' maybe_attribute
1471 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1472 | struct_head '{' component_decl_list '}' maybe_attribute
1473 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1474 $3, chainon ($1, $5));
1476 | struct_head identifier
1477 { $$ = xref_tag (RECORD_TYPE, $2); }
1478 | union_head identifier '{'
1479 { $$ = start_struct (UNION_TYPE, $2); }
1480 component_decl_list '}' maybe_attribute
1481 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1482 | union_head '{' component_decl_list '}' maybe_attribute
1483 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1484 $3, chainon ($1, $5));
1486 | union_head identifier
1487 { $$ = xref_tag (UNION_TYPE, $2); }
1488 | enum_head identifier '{'
1489 { $<itype>3 = suspend_momentary ();
1490 $$ = start_enum ($2); }
1491 enumlist maybecomma_warn '}' maybe_attribute
1492 { $$= finish_enum ($<ttype>4, nreverse ($5), chainon ($1, $8));
1493 resume_momentary ($<itype>3); }
1495 { $<itype>2 = suspend_momentary ();
1496 $$ = start_enum (NULL_TREE); }
1497 enumlist maybecomma_warn '}' maybe_attribute
1498 { $$= finish_enum ($<ttype>3, nreverse ($4), chainon ($1, $7));
1499 resume_momentary ($<itype>2); }
1500 | enum_head identifier
1501 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1512 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1515 component_decl_list:
1516 component_decl_list2
1518 | component_decl_list2 component_decl
1519 { $$ = chainon ($1, $2);
1520 pedwarn ("no semicolon at end of struct or union"); }
1523 component_decl_list2: /* empty */
1525 | component_decl_list2 component_decl ';'
1526 { $$ = chainon ($1, $2); }
1527 | component_decl_list2 ';'
1529 pedwarn ("extra semicolon in struct or union specified"); }
1531 /* foo(sizeof(struct{ @defs(ClassName)})); */
1532 | DEFS '(' CLASSNAME ')'
1534 tree interface = lookup_interface ($3);
1537 $$ = get_class_ivars (interface);
1540 error ("Cannot find interface declaration for `%s'",
1541 IDENTIFIER_POINTER ($3));
1548 /* There is a shift-reduce conflict here, because `components' may
1549 start with a `typename'. It happens that shifting (the default resolution)
1550 does the right thing, because it treats the `typename' as part of
1551 a `typed_typespecs'.
1553 It is possible that this same technique would allow the distinction
1554 between `notype_initdecls' and `initdecls' to be eliminated.
1555 But I am being cautious and not trying it. */
1558 typed_typespecs setspecs components
1560 current_declspecs = TREE_VALUE (declspec_stack);
1561 prefix_attributes = TREE_PURPOSE (declspec_stack);
1562 declspec_stack = TREE_CHAIN (declspec_stack);
1563 resume_momentary ($2); }
1566 pedwarn ("ANSI C forbids member declarations with no members");
1569 | nonempty_type_quals setspecs components
1571 current_declspecs = TREE_VALUE (declspec_stack);
1572 prefix_attributes = TREE_PURPOSE (declspec_stack);
1573 declspec_stack = TREE_CHAIN (declspec_stack);
1574 resume_momentary ($2); }
1575 | nonempty_type_quals
1577 pedwarn ("ANSI C forbids member declarations with no members");
1582 | extension component_decl
1584 pedantic = $<itype>1; }
1588 component_declarator
1589 | components ',' component_declarator
1590 { $$ = chainon ($1, $3); }
1593 component_declarator:
1594 save_filename save_lineno declarator maybe_attribute
1595 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1596 decl_attributes ($$, $4, prefix_attributes); }
1597 | save_filename save_lineno
1598 declarator ':' expr_no_commas maybe_attribute
1599 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1600 decl_attributes ($$, $6, prefix_attributes); }
1601 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1602 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1603 decl_attributes ($$, $5, prefix_attributes); }
1606 /* We chain the enumerators in reverse order.
1607 They are put in forward order where enumlist is used.
1608 (The order used to be significant, but no longer is so.
1609 However, we still maintain the order, just to be clean.) */
1613 | enumlist ',' enumerator
1614 { if ($1 == error_mark_node)
1617 $$ = chainon ($3, $1); }
1619 { $$ = error_mark_node; }
1625 { $$ = build_enumerator ($1, NULL_TREE); }
1626 | identifier '=' expr_no_commas
1627 { $$ = build_enumerator ($1, $3); }
1631 typed_typespecs absdcl
1632 { $$ = build_tree_list ($1, $2); }
1633 | nonempty_type_quals absdcl
1634 { $$ = build_tree_list ($1, $2); }
1637 absdcl: /* an absolute declarator */
1643 nonempty_type_quals:
1645 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1646 | nonempty_type_quals TYPE_QUAL
1647 { $$ = tree_cons (NULL_TREE, $2, $1); }
1653 | type_quals TYPE_QUAL
1654 { $$ = tree_cons (NULL_TREE, $2, $1); }
1657 absdcl1: /* a nonempty absolute declarator */
1660 /* `(typedef)1' is `int'. */
1661 | '*' type_quals absdcl1 %prec UNARY
1662 { $$ = make_pointer_declarator ($2, $3); }
1663 | '*' type_quals %prec UNARY
1664 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1665 | absdcl1 '(' parmlist %prec '.'
1666 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1667 | absdcl1 '[' expr ']' %prec '.'
1668 { $$ = build_nt (ARRAY_REF, $1, $3); }
1669 | absdcl1 '[' ']' %prec '.'
1670 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1671 | '(' parmlist %prec '.'
1672 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1673 | '[' expr ']' %prec '.'
1674 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1676 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1677 /* ??? It appears we have to support attributes here, however
1678 using prefix_attributes is wrong. */
1681 /* at least one statement, the first of which parses without error. */
1682 /* stmts is used only after decls, so an invalid first statement
1683 is actually regarded as an invalid decl and part of the decls. */
1686 lineno_stmt_or_labels
1689 pedwarn ("ANSI C forbids label at end of compound statement");
1693 lineno_stmt_or_labels:
1694 lineno_stmt_or_label
1695 | lineno_stmt_or_labels lineno_stmt_or_label
1697 | lineno_stmt_or_labels errstmt
1709 pushlevel: /* empty */
1710 { emit_line_note (input_filename, lineno);
1714 expand_start_bindings (0);
1716 if (objc_method_context)
1722 /* Read zero or more forward-declarations for labels
1723 that nested functions can jump to. */
1728 pedwarn ("ANSI C forbids label declarations"); }
1733 | label_decls label_decl
1737 LABEL identifiers_or_typenames ';'
1739 for (link = $2; link; link = TREE_CHAIN (link))
1741 tree label = shadow_label (TREE_VALUE (link));
1742 C_DECLARED_LABEL_FLAG (label) = 1;
1743 declare_nonlocal_label (label);
1748 /* This is the body of a function definition.
1749 It causes syntax errors to ignore to the next openbrace. */
1756 compstmt_start: '{' { compstmt_count++; }
1758 compstmt: compstmt_start '}'
1759 { $$ = convert (void_type_node, integer_zero_node); }
1760 | compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1761 { emit_line_note (input_filename, lineno);
1762 expand_end_bindings (getdecls (), 1, 0);
1763 $$ = poplevel (1, 1, 0);
1764 if (yychar == CONSTANT || yychar == STRING)
1765 pop_momentary_nofree ();
1768 | compstmt_start pushlevel maybe_label_decls error '}'
1769 { emit_line_note (input_filename, lineno);
1770 expand_end_bindings (getdecls (), kept_level_p (), 0);
1771 $$ = poplevel (kept_level_p (), 0, 0);
1772 if (yychar == CONSTANT || yychar == STRING)
1773 pop_momentary_nofree ();
1776 | compstmt_start pushlevel maybe_label_decls stmts '}'
1777 { emit_line_note (input_filename, lineno);
1778 expand_end_bindings (getdecls (), kept_level_p (), 0);
1779 $$ = poplevel (kept_level_p (), 0, 0);
1780 if (yychar == CONSTANT || yychar == STRING)
1781 pop_momentary_nofree ();
1786 /* Value is number of statements counted as of the closeparen. */
1788 if_prefix lineno_labeled_stmt
1789 /* Make sure c_expand_end_cond is run once
1790 for each call to c_expand_start_cond.
1791 Otherwise a crash is likely. */
1797 { emit_line_note ($<filename>-1, $<lineno>0);
1798 c_expand_start_cond (truthvalue_conversion ($3), 0,
1800 $<itype>$ = stmt_count;
1801 if_stmt_file = $<filename>-1;
1802 if_stmt_line = $<lineno>0;
1803 position_after_white_space (); }
1806 /* This is a subroutine of stmt.
1807 It is used twice, once for valid DO statements
1808 and once for catching errors in parsing the end test. */
1813 emit_line_note ($<filename>-1, $<lineno>0);
1814 /* See comment in `while' alternative, above. */
1816 expand_start_loop_continue_elsewhere (1);
1817 position_after_white_space (); }
1818 lineno_labeled_stmt WHILE
1819 { expand_loop_continue_here (); }
1823 { $$ = input_filename; }
1830 lineno_labeled_stmt:
1831 save_filename save_lineno stmt
1833 /* | save_filename save_lineno error
1836 | save_filename save_lineno label lineno_labeled_stmt
1840 lineno_stmt_or_label:
1841 save_filename save_lineno stmt_or_label
1852 /* Parse a single real statement, not including any labels. */
1859 emit_line_note ($<filename>-1, $<lineno>0);
1860 /* It appears that this should not be done--that a non-lvalue array
1861 shouldn't get an error if the value isn't used.
1862 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1863 if it appears as a top-level expression,
1864 but says nothing about non-lvalue arrays. */
1866 /* Call default_conversion to get an error
1867 on referring to a register array if pedantic. */
1868 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1869 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1870 $1 = default_conversion ($1);
1872 iterator_expand ($1);
1873 clear_momentary (); }
1875 { c_expand_start_else ();
1876 $<itype>1 = stmt_count;
1877 position_after_white_space (); }
1879 { c_expand_end_cond ();
1880 if (extra_warnings && stmt_count == $<itype>1)
1881 warning ("empty body in an else-statement"); }
1882 | simple_if %prec IF
1883 { c_expand_end_cond ();
1884 /* This warning is here instead of in simple_if, because we
1885 do not want a warning if an empty if is followed by an
1886 else statement. Increment stmt_count so we don't
1887 give a second error if this is a nested `if'. */
1888 if (extra_warnings && stmt_count++ == $<itype>1)
1889 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1890 "empty body in an if-statement"); }
1891 /* Make sure c_expand_end_cond is run once
1892 for each call to c_expand_start_cond.
1893 Otherwise a crash is likely. */
1894 | simple_if ELSE error
1895 { c_expand_end_cond (); }
1898 emit_line_note ($<filename>-1, $<lineno>0);
1899 /* The emit_nop used to come before emit_line_note,
1900 but that made the nop seem like part of the preceding line.
1901 And that was confusing when the preceding line was
1902 inside of an if statement and was not really executed.
1903 I think it ought to work to put the nop after the line number.
1904 We will see. --rms, July 15, 1991. */
1907 { /* Don't start the loop till we have succeeded
1908 in parsing the end test. This is to make sure
1909 that we end every loop we start. */
1910 expand_start_loop (1);
1911 emit_line_note (input_filename, lineno);
1912 expand_exit_loop_if_false (NULL_PTR,
1913 truthvalue_conversion ($4));
1914 position_after_white_space (); }
1916 { expand_end_loop (); }
1919 { emit_line_note (input_filename, lineno);
1920 expand_exit_loop_if_false (NULL_PTR,
1921 truthvalue_conversion ($3));
1923 clear_momentary (); }
1924 /* This rule is needed to make sure we end every loop we start. */
1925 | do_stmt_start error
1926 { expand_end_loop ();
1927 clear_momentary (); }
1931 emit_line_note ($<filename>-1, $<lineno>0);
1932 /* See comment in `while' alternative, above. */
1934 if ($3) c_expand_expr_stmt ($3);
1935 /* Next step is to call expand_start_loop_continue_elsewhere,
1936 but wait till after we parse the entire for (...).
1937 Otherwise, invalid input might cause us to call that
1938 fn without calling expand_end_loop. */
1941 /* Can't emit now; wait till after expand_start_loop... */
1942 { $<lineno>7 = lineno;
1943 $<filename>$ = input_filename; }
1946 /* Start the loop. Doing this after parsing
1947 all the expressions ensures we will end the loop. */
1948 expand_start_loop_continue_elsewhere (1);
1949 /* Emit the end-test, with a line number. */
1950 emit_line_note ($<filename>8, $<lineno>7);
1952 expand_exit_loop_if_false (NULL_PTR,
1953 truthvalue_conversion ($6));
1954 /* Don't let the tree nodes for $9 be discarded by
1955 clear_momentary during the parsing of the next stmt. */
1957 $<lineno>7 = lineno;
1958 $<filename>8 = input_filename;
1959 position_after_white_space (); }
1961 { /* Emit the increment expression, with a line number. */
1962 emit_line_note ($<filename>8, $<lineno>7);
1963 expand_loop_continue_here ();
1965 c_expand_expr_stmt ($9);
1966 if (yychar == CONSTANT || yychar == STRING)
1967 pop_momentary_nofree ();
1970 expand_end_loop (); }
1971 | SWITCH '(' expr ')'
1973 emit_line_note ($<filename>-1, $<lineno>0);
1974 c_expand_start_case ($3);
1975 /* Don't let the tree nodes for $3 be discarded by
1976 clear_momentary during the parsing of the next stmt. */
1978 position_after_white_space (); }
1980 { expand_end_case ($3);
1981 if (yychar == CONSTANT || yychar == STRING)
1982 pop_momentary_nofree ();
1987 emit_line_note ($<filename>-1, $<lineno>0);
1988 if ( ! expand_exit_something ())
1989 error ("break statement not within loop or switch"); }
1992 emit_line_note ($<filename>-1, $<lineno>0);
1993 if (! expand_continue_loop (NULL_PTR))
1994 error ("continue statement not within a loop"); }
1997 emit_line_note ($<filename>-1, $<lineno>0);
1998 c_expand_return (NULL_TREE); }
2001 emit_line_note ($<filename>-1, $<lineno>0);
2002 c_expand_return ($2); }
2003 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2005 emit_line_note ($<filename>-1, $<lineno>0);
2007 if ((TREE_CODE ($4) == ADDR_EXPR
2008 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
2009 || TREE_CODE ($4) == STRING_CST)
2012 error ("argument of `asm' is not a constant string"); }
2013 /* This is the case with just output operands. */
2014 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2016 emit_line_note ($<filename>-1, $<lineno>0);
2017 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2018 $2 == ridpointers[(int)RID_VOLATILE],
2019 input_filename, lineno); }
2020 /* This is the case with input operands as well. */
2021 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2023 emit_line_note ($<filename>-1, $<lineno>0);
2024 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2025 $2 == ridpointers[(int)RID_VOLATILE],
2026 input_filename, lineno); }
2027 /* This is the case with clobbered registers as well. */
2028 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2029 asm_operands ':' asm_clobbers ')' ';'
2031 emit_line_note ($<filename>-1, $<lineno>0);
2032 c_expand_asm_operands ($4, $6, $8, $10,
2033 $2 == ridpointers[(int)RID_VOLATILE],
2034 input_filename, lineno); }
2035 | GOTO identifier ';'
2038 emit_line_note ($<filename>-1, $<lineno>0);
2039 decl = lookup_label ($2);
2042 TREE_USED (decl) = 1;
2048 pedwarn ("ANSI C forbids `goto *expr;'");
2050 emit_line_note ($<filename>-1, $<lineno>0);
2051 expand_computed_goto (convert (ptr_type_node, $3)); }
2056 all_iter_stmt_simple
2057 /* | all_iter_stmt_with_decl */
2060 all_iter_stmt_simple:
2063 /* The value returned by this action is */
2064 /* 1 if everything is OK */
2065 /* 0 in case of error or already bound iterator */
2068 if (TREE_CODE ($3) != VAR_DECL)
2069 error ("invalid `for (ITERATOR)' syntax");
2070 else if (! ITERATOR_P ($3))
2071 error ("`%s' is not an iterator",
2072 IDENTIFIER_POINTER (DECL_NAME ($3)));
2073 else if (ITERATOR_BOUND_P ($3))
2074 error ("`for (%s)' inside expansion of same iterator",
2075 IDENTIFIER_POINTER (DECL_NAME ($3)));
2079 iterator_for_loop_start ($3);
2085 iterator_for_loop_end ($3);
2088 /* This really should allow any kind of declaration,
2089 for generality. Fix it before turning it back on.
2091 all_iter_stmt_with_decl:
2092 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2094 */ /* The value returned by this action is */
2095 /* 1 if everything is OK */
2096 /* 0 in case of error or already bound iterator */
2098 iterator_for_loop_start ($6);
2102 iterator_for_loop_end ($6);
2103 emit_line_note (input_filename, lineno);
2104 expand_end_bindings (getdecls (), 1, 0);
2105 $<ttype>$ = poplevel (1, 1, 0);
2106 if (yychar == CONSTANT || yychar == STRING)
2107 pop_momentary_nofree ();
2113 /* Any kind of label, including jump labels and case labels.
2114 ANSI C accepts labels only before statements, but we allow them
2115 also at the end of a compound statement. */
2117 label: CASE expr_no_commas ':'
2118 { register tree value = check_case_value ($2);
2120 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2124 if (value != error_mark_node)
2129 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2130 pedwarn ("label must have integral type in ANSI C");
2132 success = pushcase (value, convert_and_check,
2136 error ("case label not within a switch statement");
2137 else if (success == 2)
2139 error ("duplicate case value");
2140 error_with_decl (duplicate, "this is the first entry for that value");
2142 else if (success == 3)
2143 warning ("case value out of range");
2144 else if (success == 5)
2145 error ("case label within scope of cleanup or variable array");
2147 position_after_white_space (); }
2148 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2149 { register tree value1 = check_case_value ($2);
2150 register tree value2 = check_case_value ($4);
2152 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2155 pedwarn ("ANSI C forbids case ranges");
2158 if (value1 != error_mark_node && value2 != error_mark_node)
2161 int success = pushcase_range (value1, value2,
2162 convert_and_check, label,
2165 error ("case label not within a switch statement");
2166 else if (success == 2)
2168 error ("duplicate case value");
2169 error_with_decl (duplicate, "this is the first entry for that value");
2171 else if (success == 3)
2172 warning ("case value out of range");
2173 else if (success == 4)
2174 warning ("empty case range");
2175 else if (success == 5)
2176 error ("case label within scope of cleanup or variable array");
2178 position_after_white_space (); }
2183 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2184 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2187 error ("default label not within a switch statement");
2188 else if (success == 2)
2190 error ("multiple default labels in one switch");
2191 error_with_decl (duplicate, "this is the first default label");
2193 position_after_white_space (); }
2195 { tree label = define_label (input_filename, lineno, $1);
2199 expand_label (label);
2200 position_after_white_space (); }
2203 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2207 { emit_line_note (input_filename, lineno);
2210 { emit_line_note (input_filename, lineno); }
2219 /* These are the operands other than the first string and colon
2220 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2221 asm_operands: /* empty */
2223 | nonnull_asm_operands
2226 nonnull_asm_operands:
2228 | nonnull_asm_operands ',' asm_operand
2229 { $$ = chainon ($1, $3); }
2234 { $$ = build_tree_list ($1, $3); }
2239 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2240 | asm_clobbers ',' string
2241 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2244 /* This is what appears inside the parens in a function declarator.
2245 Its value is a list of ..._TYPE nodes. */
2248 clear_parm_order ();
2249 declare_parm_level (0); }
2252 parmlist_tags_warning ();
2253 poplevel (0, 0, 0); }
2261 pedwarn ("ANSI C forbids forward parameter declarations");
2262 /* Mark the forward decls as such. */
2263 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2264 TREE_ASM_WRITTEN (parm) = 1;
2265 clear_parm_order (); }
2269 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2272 /* This is what appears inside the parens in a function declarator.
2273 Is value is represented in the format that grokdeclarator expects. */
2274 parmlist_2: /* empty */
2275 { $$ = get_parm_info (0); }
2277 { $$ = get_parm_info (0);
2278 /* Gcc used to allow this as an extension. However, it does
2279 not work for all targets, and thus has been disabled.
2280 Also, since func (...) and func () are indistinguishable,
2281 it caused problems with the code in expand_builtin which
2282 tries to verify that BUILT_IN_NEXT_ARG is being used
2284 error ("ANSI C requires a named argument before `...'");
2287 { $$ = get_parm_info (1); }
2288 | parms ',' ELLIPSIS
2289 { $$ = get_parm_info (0); }
2294 { push_parm_decl ($1); }
2296 { push_parm_decl ($3); }
2299 /* A single parameter declaration or parameter type name,
2300 as found in a parmlist. */
2302 typed_declspecs setspecs parm_declarator maybe_attribute
2303 { $$ = build_tree_list (build_tree_list (current_declspecs,
2305 build_tree_list (prefix_attributes,
2307 current_declspecs = TREE_VALUE (declspec_stack);
2308 prefix_attributes = TREE_PURPOSE (declspec_stack);
2309 declspec_stack = TREE_CHAIN (declspec_stack);
2310 resume_momentary ($2); }
2311 | typed_declspecs setspecs notype_declarator maybe_attribute
2312 { $$ = build_tree_list (build_tree_list (current_declspecs,
2314 build_tree_list (prefix_attributes,
2316 current_declspecs = TREE_VALUE (declspec_stack);
2317 prefix_attributes = TREE_PURPOSE (declspec_stack);
2318 declspec_stack = TREE_CHAIN (declspec_stack);
2319 resume_momentary ($2); }
2320 | typed_declspecs setspecs absdcl maybe_attribute
2321 { $$ = build_tree_list (build_tree_list (current_declspecs,
2323 build_tree_list (prefix_attributes,
2325 current_declspecs = TREE_VALUE (declspec_stack);
2326 prefix_attributes = TREE_PURPOSE (declspec_stack);
2327 declspec_stack = TREE_CHAIN (declspec_stack);
2328 resume_momentary ($2); }
2329 | declmods setspecs notype_declarator maybe_attribute
2330 { $$ = build_tree_list (build_tree_list (current_declspecs,
2332 build_tree_list (prefix_attributes,
2334 current_declspecs = TREE_VALUE (declspec_stack);
2335 prefix_attributes = TREE_PURPOSE (declspec_stack);
2336 declspec_stack = TREE_CHAIN (declspec_stack);
2337 resume_momentary ($2); }
2339 | declmods setspecs absdcl maybe_attribute
2340 { $$ = build_tree_list (build_tree_list (current_declspecs,
2342 build_tree_list (prefix_attributes,
2344 current_declspecs = TREE_VALUE (declspec_stack);
2345 prefix_attributes = TREE_PURPOSE (declspec_stack);
2346 declspec_stack = TREE_CHAIN (declspec_stack);
2347 resume_momentary ($2); }
2350 /* This is used in a function definition
2351 where either a parmlist or an identifier list is ok.
2352 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2353 parmlist_or_identifiers:
2355 clear_parm_order ();
2356 declare_parm_level (1); }
2357 parmlist_or_identifiers_1
2359 parmlist_tags_warning ();
2360 poplevel (0, 0, 0); }
2363 parmlist_or_identifiers_1:
2367 for (t = $1; t; t = TREE_CHAIN (t))
2368 if (TREE_VALUE (t) == NULL_TREE)
2369 error ("`...' in old-style identifier list");
2370 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2373 /* A nonempty list of identifiers. */
2376 { $$ = build_tree_list (NULL_TREE, $1); }
2377 | identifiers ',' IDENTIFIER
2378 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2381 /* A nonempty list of identifiers, including typenames. */
2382 identifiers_or_typenames:
2384 { $$ = build_tree_list (NULL_TREE, $1); }
2385 | identifiers_or_typenames ',' identifier
2386 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2391 { $<itype>$ = pedantic;
2396 /* Objective-C productions. */
2406 if (objc_implementation_context)
2408 finish_class (objc_implementation_context);
2409 objc_ivar_chain = NULL_TREE;
2410 objc_implementation_context = NULL_TREE;
2413 warning ("`@end' must appear in an implementation context");
2417 /* A nonempty list of identifiers. */
2420 { $$ = build_tree_list (NULL_TREE, $1); }
2421 | identifier_list ',' identifier
2422 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2426 CLASS identifier_list ';'
2428 objc_declare_class ($2);
2432 ALIAS identifier identifier ';'
2434 objc_declare_alias ($2, $3);
2438 INTERFACE identifier protocolrefs '{'
2440 objc_interface_context = objc_ivar_context
2441 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2442 objc_public_flag = 0;
2446 continue_class (objc_interface_context);
2451 finish_class (objc_interface_context);
2452 objc_interface_context = NULL_TREE;
2455 | INTERFACE identifier protocolrefs
2457 objc_interface_context
2458 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2459 continue_class (objc_interface_context);
2464 finish_class (objc_interface_context);
2465 objc_interface_context = NULL_TREE;
2468 | INTERFACE identifier ':' identifier protocolrefs '{'
2470 objc_interface_context = objc_ivar_context
2471 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2472 objc_public_flag = 0;
2476 continue_class (objc_interface_context);
2481 finish_class (objc_interface_context);
2482 objc_interface_context = NULL_TREE;
2485 | INTERFACE identifier ':' identifier protocolrefs
2487 objc_interface_context
2488 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2489 continue_class (objc_interface_context);
2494 finish_class (objc_interface_context);
2495 objc_interface_context = NULL_TREE;
2498 | IMPLEMENTATION identifier '{'
2500 objc_implementation_context = objc_ivar_context
2501 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2502 objc_public_flag = 0;
2507 = continue_class (objc_implementation_context);
2510 | IMPLEMENTATION identifier
2512 objc_implementation_context
2513 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2515 = continue_class (objc_implementation_context);
2518 | IMPLEMENTATION identifier ':' identifier '{'
2520 objc_implementation_context = objc_ivar_context
2521 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2522 objc_public_flag = 0;
2527 = continue_class (objc_implementation_context);
2530 | IMPLEMENTATION identifier ':' identifier
2532 objc_implementation_context
2533 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2535 = continue_class (objc_implementation_context);
2538 | INTERFACE identifier '(' identifier ')' protocolrefs
2540 objc_interface_context
2541 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2542 continue_class (objc_interface_context);
2547 finish_class (objc_interface_context);
2548 objc_interface_context = NULL_TREE;
2551 | IMPLEMENTATION identifier '(' identifier ')'
2553 objc_implementation_context
2554 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2556 = continue_class (objc_implementation_context);
2561 PROTOCOL identifier protocolrefs
2563 remember_protocol_qualifiers ();
2564 objc_interface_context
2565 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2569 forget_protocol_qualifiers();
2570 finish_protocol(objc_interface_context);
2571 objc_interface_context = NULL_TREE;
2580 | non_empty_protocolrefs
2583 non_empty_protocolrefs:
2584 ARITHCOMPARE identifier_list ARITHCOMPARE
2586 if ($1 == LT_EXPR && $3 == GT_EXPR)
2594 ivar_decl_list visibility_spec ivar_decls
2599 PRIVATE { objc_public_flag = 2; }
2600 | PROTECTED { objc_public_flag = 0; }
2601 | PUBLIC { objc_public_flag = 1; }
2609 | ivar_decls ivar_decl ';'
2613 pedwarn ("extra semicolon in struct or union specified");
2618 /* There is a shift-reduce conflict here, because `components' may
2619 start with a `typename'. It happens that shifting (the default resolution)
2620 does the right thing, because it treats the `typename' as part of
2621 a `typed_typespecs'.
2623 It is possible that this same technique would allow the distinction
2624 between `notype_initdecls' and `initdecls' to be eliminated.
2625 But I am being cautious and not trying it. */
2628 typed_typespecs setspecs ivars
2630 current_declspecs = TREE_VALUE (declspec_stack);
2631 prefix_attributes = TREE_PURPOSE (declspec_stack);
2632 declspec_stack = TREE_CHAIN (declspec_stack);
2633 resume_momentary ($2); }
2634 | nonempty_type_quals setspecs ivars
2636 current_declspecs = TREE_VALUE (declspec_stack);
2637 prefix_attributes = TREE_PURPOSE (declspec_stack);
2638 declspec_stack = TREE_CHAIN (declspec_stack);
2639 resume_momentary ($2); }
2648 | ivars ',' ivar_declarator
2654 $$ = add_instance_variable (objc_ivar_context,
2656 $1, current_declspecs,
2659 | declarator ':' expr_no_commas
2661 $$ = add_instance_variable (objc_ivar_context,
2663 $1, current_declspecs, $3);
2665 | ':' expr_no_commas
2667 $$ = add_instance_variable (objc_ivar_context,
2670 current_declspecs, $2);
2677 remember_protocol_qualifiers ();
2678 if (objc_implementation_context)
2679 objc_inherit_code = CLASS_METHOD_DECL;
2681 fatal ("method definition not in class context");
2685 forget_protocol_qualifiers ();
2686 add_class_method (objc_implementation_context, $3);
2687 start_method_def ($3);
2688 objc_method_context = $3;
2692 continue_method_def ();
2696 finish_method_def ();
2697 objc_method_context = NULL_TREE;
2702 remember_protocol_qualifiers ();
2703 if (objc_implementation_context)
2704 objc_inherit_code = INSTANCE_METHOD_DECL;
2706 fatal ("method definition not in class context");
2710 forget_protocol_qualifiers ();
2711 add_instance_method (objc_implementation_context, $3);
2712 start_method_def ($3);
2713 objc_method_context = $3;
2717 continue_method_def ();
2721 finish_method_def ();
2722 objc_method_context = NULL_TREE;
2726 /* the reason for the strange actions in this rule
2727 is so that notype_initdecls when reached via datadef
2728 can find a valid list of type and sc specs in $0. */
2732 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2735 methodprotolist2: /* eliminates a shift/reduce conflict */
2738 | methodprotolist2 methodproto
2739 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2750 /* Remember protocol qualifiers in prototypes. */
2751 remember_protocol_qualifiers ();
2752 objc_inherit_code = CLASS_METHOD_DECL;
2756 /* Forget protocol qualifiers here. */
2757 forget_protocol_qualifiers ();
2758 add_class_method (objc_interface_context, $3);
2764 /* Remember protocol qualifiers in prototypes. */
2765 remember_protocol_qualifiers ();
2766 objc_inherit_code = INSTANCE_METHOD_DECL;
2770 /* Forget protocol qualifiers here. */
2771 forget_protocol_qualifiers ();
2772 add_instance_method (objc_interface_context, $3);
2778 '(' typename ')' unaryselector
2780 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2785 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2788 | '(' typename ')' keywordselector optparmlist
2790 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2793 | keywordselector optparmlist
2795 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2799 /* "optarglist" assumes that start_method_def has already been called...
2800 if it is not, the "xdecls" will not be placed in the proper scope */
2807 /* to get around the following situation: "int foo (int a) int b; {}" that
2808 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2823 typed_declspecs setspecs myparms ';'
2824 { current_declspecs = TREE_VALUE (declspec_stack);
2825 prefix_attributes = TREE_PURPOSE (declspec_stack);
2826 declspec_stack = TREE_CHAIN (declspec_stack);
2827 resume_momentary ($2); }
2828 | typed_declspecs ';'
2829 { shadow_tag ($1); }
2831 { pedwarn ("empty declaration"); }
2836 { push_parm_decl ($1); }
2837 | myparms ',' myparm
2838 { push_parm_decl ($3); }
2841 /* A single parameter declaration or parameter type name,
2842 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2845 parm_declarator maybe_attribute
2846 { $$ = build_tree_list (build_tree_list (current_declspecs,
2848 build_tree_list (prefix_attributes,
2850 | notype_declarator maybe_attribute
2851 { $$ = build_tree_list (build_tree_list (current_declspecs,
2853 build_tree_list (prefix_attributes,
2855 | absdcl maybe_attribute
2856 { $$ = build_tree_list (build_tree_list (current_declspecs,
2858 build_tree_list (prefix_attributes,
2869 /* oh what a kludge! */
2878 /* returns a tree list node generated by get_parm_info */
2891 | keywordselector keyworddecl
2893 $$ = chainon ($1, $2);
2905 ENUM { $$ = get_identifier (token_buffer); }
2906 | STRUCT { $$ = get_identifier (token_buffer); }
2907 | UNION { $$ = get_identifier (token_buffer); }
2908 | IF { $$ = get_identifier (token_buffer); }
2909 | ELSE { $$ = get_identifier (token_buffer); }
2910 | WHILE { $$ = get_identifier (token_buffer); }
2911 | DO { $$ = get_identifier (token_buffer); }
2912 | FOR { $$ = get_identifier (token_buffer); }
2913 | SWITCH { $$ = get_identifier (token_buffer); }
2914 | CASE { $$ = get_identifier (token_buffer); }
2915 | DEFAULT { $$ = get_identifier (token_buffer); }
2916 | BREAK { $$ = get_identifier (token_buffer); }
2917 | CONTINUE { $$ = get_identifier (token_buffer); }
2918 | RETURN { $$ = get_identifier (token_buffer); }
2919 | GOTO { $$ = get_identifier (token_buffer); }
2920 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2921 | SIZEOF { $$ = get_identifier (token_buffer); }
2922 | TYPEOF { $$ = get_identifier (token_buffer); }
2923 | ALIGNOF { $$ = get_identifier (token_buffer); }
2924 | TYPESPEC | TYPE_QUAL
2928 selector ':' '(' typename ')' identifier
2930 $$ = build_keyword_decl ($1, $4, $6);
2933 | selector ':' identifier
2935 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2938 | ':' '(' typename ')' identifier
2940 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2945 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2956 | keywordarglist keywordarg
2958 $$ = chainon ($1, $2);
2966 if (TREE_CHAIN ($1) == NULL_TREE)
2967 /* just return the expr., remove a level of indirection */
2968 $$ = TREE_VALUE ($1);
2970 /* we have a comma expr., we will collapse later */
2976 selector ':' keywordexpr
2978 $$ = build_tree_list ($1, $3);
2982 $$ = build_tree_list (NULL_TREE, $2);
2990 $$ = get_class_reference ($1);
2996 { objc_receiver_context = 1; }
2998 { objc_receiver_context = 0; }
3001 $$ = build_tree_list ($3, $5);
3012 | keywordnamelist keywordname
3014 $$ = chainon ($1, $2);
3021 $$ = build_tree_list ($1, NULL_TREE);
3025 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3030 SELECTOR '(' selectorarg ')'
3037 PROTOCOL '(' identifier ')'
3043 /* extension to support C-structures in the archiver */
3046 ENCODE '(' typename ')'
3048 $$ = groktypename ($3);