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.) */
74 #ifdef MULTIBYTE_CHARS
83 /* Since parsers are distinct for each language, put the language string
86 char *language_string = "GNU Obj-C";
89 char *language_string = "GNU C";
96 /* Like YYERROR but do call yyerror. */
97 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
99 /* Cause the `yydebug' variable to be defined. */
105 %union {long itype; tree ttype; enum tree_code code;
106 char *filename; int lineno; int ends_in_label; }
108 /* All identifiers that are not reserved words
109 and are not declared typedefs in the current block */
112 /* All identifiers that are declared typedefs in the current block.
113 In some contexts, they are treated just like IDENTIFIER,
114 but they can also serve as typespecs in declarations. */
117 /* Reserved words that specify storage class.
118 yylval contains an IDENTIFIER_NODE which indicates which one. */
121 /* Reserved words that specify type.
122 yylval contains an IDENTIFIER_NODE which indicates which one. */
125 /* Reserved words that qualify type: "const" or "volatile".
126 yylval contains an IDENTIFIER_NODE which indicates which one. */
129 /* Character or numeric constants.
130 yylval is the node for the constant. */
133 /* String constants in raw form.
134 yylval is a STRING_CST node. */
137 /* "...", used for functions with variable arglists. */
140 /* the reserved words */
141 /* SCO include files test "ASM", so use something else. */
142 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
143 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
144 %token ATTRIBUTE EXTENSION LABEL
145 %token REALPART IMAGPART
147 /* Add precedence rules to solve dangling else s/r conflict */
151 /* Define the operator tokens and their precedences.
152 The value is an integer because, if used, it is the tree code
153 to use in the expression made from the operator. */
155 %right <code> ASSIGN '='
156 %right <code> '?' ':'
162 %left <code> EQCOMPARE
163 %left <code> ARITHCOMPARE
164 %left <code> LSHIFT RSHIFT
166 %left <code> '*' '/' '%'
167 %right <code> UNARY PLUSPLUS MINUSMINUS
169 %left <code> POINTSAT '.' '(' '['
171 /* The Objective-C keywords. These are included in C and in
172 Objective C, so that the token codes are the same in both. */
173 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
174 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
176 /* Objective-C string constants in raw form.
177 yylval is an OBJC_STRING_CST node. */
183 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
184 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
185 %type <ttype> typed_declspecs reserved_declspecs
186 %type <ttype> typed_typespecs reserved_typespecquals
187 %type <ttype> declmods typespec typespecqual_reserved
188 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
189 %type <ttype> declmods_no_prefix_attr
190 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
191 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
192 %type <ttype> init maybeasm
193 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
194 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
195 %type <ttype> any_word
197 %type <ttype> compstmt
199 %type <ttype> declarator
200 %type <ttype> notype_declarator after_type_declarator
201 %type <ttype> parm_declarator
203 %type <ttype> structsp component_decl_list component_decl_list2
204 %type <ttype> component_decl components component_declarator
205 %type <ttype> enumlist enumerator
206 %type <ttype> typename absdcl absdcl1 type_quals
207 %type <ttype> xexpr parms parm identifiers
209 %type <ttype> parmlist parmlist_1 parmlist_2
210 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
211 %type <ttype> identifiers_or_typenames
213 %type <itype> setspecs
215 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
217 %type <filename> save_filename
218 %type <lineno> save_lineno
221 /* the Objective-C nonterminals */
223 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
224 %type <ttype> methoddecl unaryselector keywordselector selector
225 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
226 %type <ttype> keywordexpr keywordarglist keywordarg
227 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
228 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
229 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
231 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
235 /* Number of statements (loosely speaking) and compound statements
237 static int stmt_count;
238 static int compstmt_count;
240 /* Input file and line number of the end of the body of last simple_if;
241 used by the stmt-rule immediately after simple_if returns. */
242 static char *if_stmt_file;
243 static int if_stmt_line;
245 /* List of types and structure classes of the current declaration. */
246 static tree current_declspecs = NULL_TREE;
247 static tree prefix_attributes = NULL_TREE;
249 /* Stack of saved values of current_declspecs and prefix_attributes. */
250 static tree declspec_stack;
252 /* 1 if we explained undeclared var errors. */
253 static int undeclared_variable_notice;
256 /* Objective-C specific information */
258 tree objc_interface_context;
259 tree objc_implementation_context;
260 tree objc_method_context;
261 tree objc_ivar_chain;
262 tree objc_ivar_context;
263 enum tree_code objc_inherit_code;
264 int objc_receiver_context;
265 int objc_public_flag;
269 /* Tell yyparse how to print a token's value, if yydebug is set. */
271 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
272 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
278 pedwarn ("ANSI C forbids an empty source file");
283 /* In case there were missing closebraces,
284 get us back to the global binding level. */
285 while (! global_bindings_p ())
291 /* the reason for the strange actions in this rule
292 is so that notype_initdecls when reached via datadef
293 can find a valid list of type and sc specs in $0. */
296 {$<ttype>$ = NULL_TREE; } extdef
297 | extdefs {$<ttype>$ = NULL_TREE; } extdef
306 | ASM_KEYWORD '(' expr ')' ';'
308 if ((TREE_CODE ($3) == ADDR_EXPR
309 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
310 || TREE_CODE ($3) == STRING_CST)
313 error ("argument of `asm' is not a constant string"); }
315 { pedantic = $<itype>1; }
319 setspecs notype_initdecls ';'
321 error ("ANSI C forbids data definition with no type or storage class");
322 else if (!flag_traditional)
323 warning ("data definition has no type or storage class");
325 current_declspecs = TREE_VALUE (declspec_stack);
326 prefix_attributes = TREE_PURPOSE (declspec_stack);
327 declspec_stack = TREE_CHAIN (declspec_stack);
328 resume_momentary ($1); }
329 | declmods setspecs notype_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); }
334 | typed_declspecs setspecs initdecls ';'
335 { current_declspecs = TREE_VALUE (declspec_stack);
336 prefix_attributes = TREE_PURPOSE (declspec_stack);
337 declspec_stack = TREE_CHAIN (declspec_stack);
338 resume_momentary ($2); }
340 { pedwarn ("empty declaration"); }
341 | typed_declspecs ';'
347 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
351 typed_declspecs setspecs declarator
352 { if (! start_function (current_declspecs, $3,
353 prefix_attributes, NULL_TREE, 0))
355 reinit_parse_for_function (); }
357 { store_parm_decls (); }
359 { finish_function (0);
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 | typed_declspecs setspecs declarator error
365 { current_declspecs = TREE_VALUE (declspec_stack);
366 prefix_attributes = TREE_PURPOSE (declspec_stack);
367 declspec_stack = TREE_CHAIN (declspec_stack);
368 resume_momentary ($2); }
369 | declmods setspecs notype_declarator
370 { if (! start_function (current_declspecs, $3,
371 prefix_attributes, NULL_TREE, 0))
373 reinit_parse_for_function (); }
375 { store_parm_decls (); }
377 { finish_function (0);
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 | declmods setspecs notype_declarator error
383 { current_declspecs = TREE_VALUE (declspec_stack);
384 prefix_attributes = TREE_PURPOSE (declspec_stack);
385 declspec_stack = TREE_CHAIN (declspec_stack);
386 resume_momentary ($2); }
387 | setspecs notype_declarator
388 { if (! start_function (NULL_TREE, $2,
389 prefix_attributes, NULL_TREE, 0))
391 reinit_parse_for_function (); }
393 { store_parm_decls (); }
395 { finish_function (0);
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); }
400 | setspecs notype_declarator error
401 { current_declspecs = TREE_VALUE (declspec_stack);
402 prefix_attributes = TREE_PURPOSE (declspec_stack);
403 declspec_stack = TREE_CHAIN (declspec_stack);
404 resume_momentary ($1); }
419 { $$ = NEGATE_EXPR; }
421 { $$ = CONVERT_EXPR; }
423 { $$ = PREINCREMENT_EXPR; }
425 { $$ = PREDECREMENT_EXPR; }
427 { $$ = BIT_NOT_EXPR; }
429 { $$ = TRUTH_NOT_EXPR; }
432 expr: nonnull_exprlist
433 { $$ = build_compound_expr ($1); }
444 { $$ = build_tree_list (NULL_TREE, $1); }
445 | nonnull_exprlist ',' expr_no_commas
446 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
451 | '*' cast_expr %prec UNARY
452 { $$ = build_indirect_ref ($2, "unary *"); }
453 /* __extension__ turns off -pedantic for following primary. */
454 | extension cast_expr %prec UNARY
456 pedantic = $<itype>1; }
457 | unop cast_expr %prec UNARY
458 { $$ = build_unary_op ($1, $2, 0);
459 overflow_warning ($$); }
460 /* Refer to the address of a label as a pointer. */
462 { tree label = lookup_label ($2);
464 pedwarn ("ANSI C forbids `&&'");
466 $$ = null_pointer_node;
469 TREE_USED (label) = 1;
470 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
471 TREE_CONSTANT ($$) = 1;
474 /* This seems to be impossible on some machines, so let's turn it off.
475 You can use __builtin_next_arg to find the anonymous stack args.
477 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
478 $$ = error_mark_node;
479 if (TREE_VALUE (tree_last (types)) == void_type_node)
480 error ("`&...' used in function with fixed number of arguments");
484 pedwarn ("ANSI C forbids `&...'");
485 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
486 $$ = build_unary_op (ADDR_EXPR, $$, 0);
489 | sizeof unary_expr %prec UNARY
491 if (TREE_CODE ($2) == COMPONENT_REF
492 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
493 error ("`sizeof' applied to a bit-field");
494 $$ = c_sizeof (TREE_TYPE ($2)); }
495 | sizeof '(' typename ')' %prec HYPERUNARY
497 $$ = c_sizeof (groktypename ($3)); }
498 | alignof unary_expr %prec UNARY
500 $$ = c_alignof_expr ($2); }
501 | alignof '(' typename ')' %prec HYPERUNARY
503 $$ = c_alignof (groktypename ($3)); }
504 | REALPART cast_expr %prec UNARY
505 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
506 | IMAGPART cast_expr %prec UNARY
507 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
511 SIZEOF { skip_evaluation++; }
515 ALIGNOF { skip_evaluation++; }
520 | '(' typename ')' cast_expr %prec UNARY
521 { tree type = groktypename ($2);
522 $$ = build_c_cast (type, $4); }
523 | '(' typename ')' '{'
524 { start_init (NULL_TREE, NULL, 0);
525 $2 = groktypename ($2);
526 really_start_incremental_init ($2); }
527 initlist_maybe_comma '}' %prec UNARY
529 tree result = pop_init_level (0);
534 pedwarn ("ANSI C forbids constructor expressions");
535 if (TYPE_NAME (type) != 0)
537 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
538 name = IDENTIFIER_POINTER (TYPE_NAME (type));
540 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
545 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
547 int failure = complete_array_type (type, $$, 1);
556 | expr_no_commas '+' expr_no_commas
557 { $$ = parser_build_binary_op ($2, $1, $3); }
558 | expr_no_commas '-' expr_no_commas
559 { $$ = parser_build_binary_op ($2, $1, $3); }
560 | expr_no_commas '*' expr_no_commas
561 { $$ = parser_build_binary_op ($2, $1, $3); }
562 | expr_no_commas '/' expr_no_commas
563 { $$ = parser_build_binary_op ($2, $1, $3); }
564 | expr_no_commas '%' expr_no_commas
565 { $$ = parser_build_binary_op ($2, $1, $3); }
566 | expr_no_commas LSHIFT expr_no_commas
567 { $$ = parser_build_binary_op ($2, $1, $3); }
568 | expr_no_commas RSHIFT expr_no_commas
569 { $$ = parser_build_binary_op ($2, $1, $3); }
570 | expr_no_commas ARITHCOMPARE expr_no_commas
571 { $$ = parser_build_binary_op ($2, $1, $3); }
572 | expr_no_commas EQCOMPARE expr_no_commas
573 { $$ = parser_build_binary_op ($2, $1, $3); }
574 | expr_no_commas '&' expr_no_commas
575 { $$ = parser_build_binary_op ($2, $1, $3); }
576 | expr_no_commas '|' expr_no_commas
577 { $$ = parser_build_binary_op ($2, $1, $3); }
578 | expr_no_commas '^' expr_no_commas
579 { $$ = parser_build_binary_op ($2, $1, $3); }
580 | expr_no_commas ANDAND
581 { $1 = truthvalue_conversion (default_conversion ($1));
582 skip_evaluation += $1 == boolean_false_node; }
584 { skip_evaluation -= $1 == boolean_false_node;
585 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
586 | expr_no_commas OROR
587 { $1 = truthvalue_conversion (default_conversion ($1));
588 skip_evaluation += $1 == boolean_true_node; }
590 { skip_evaluation -= $1 == boolean_true_node;
591 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
593 { $1 = truthvalue_conversion (default_conversion ($1));
594 skip_evaluation += $1 == boolean_false_node; }
596 { skip_evaluation += (($1 == boolean_true_node)
597 - ($1 == boolean_false_node)); }
599 { skip_evaluation -= $1 == boolean_true_node;
600 $$ = build_conditional_expr ($1, $4, $7); }
603 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
604 /* Make sure first operand is calculated only once. */
605 $<ttype>2 = save_expr ($1);
606 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
607 skip_evaluation += $1 == boolean_true_node; }
609 { skip_evaluation -= $1 == boolean_true_node;
610 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
611 | expr_no_commas '=' expr_no_commas
612 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
613 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
614 | expr_no_commas ASSIGN expr_no_commas
615 { $$ = build_modify_expr ($1, $2, $3);
616 /* This inhibits warnings in truthvalue_conversion. */
617 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
624 if (!$$ || $$ == error_mark_node)
626 if (yychar == YYEMPTY)
633 if (objc_receiver_context
634 && ! (objc_receiver_context
635 && strcmp (IDENTIFIER_POINTER ($1), "super")))
636 /* we have a message to super */
637 $$ = get_super_receiver ();
638 else if (objc_method_context
639 && (decl = is_ivar (objc_ivar_chain, $1)))
641 if (is_private (decl))
642 $$ = error_mark_node;
644 $$ = build_ivar_reference ($1);
649 /* Ordinary implicit function declaration. */
650 $$ = implicitly_declare ($1);
651 assemble_external ($$);
655 else if (current_function_decl == 0)
657 error ("`%s' undeclared here (not in a function)",
658 IDENTIFIER_POINTER ($1));
659 $$ = error_mark_node;
666 if (objc_receiver_context
667 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
668 /* we have a message to super */
669 $$ = get_super_receiver ();
670 else if (objc_method_context
671 && (decl = is_ivar (objc_ivar_chain, $1)))
673 if (is_private (decl))
674 $$ = error_mark_node;
676 $$ = build_ivar_reference ($1);
681 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
682 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
684 error ("`%s' undeclared (first use in this function)",
685 IDENTIFIER_POINTER ($1));
687 if (! undeclared_variable_notice)
689 error ("(Each undeclared identifier is reported only once");
690 error ("for each function it appears in.)");
691 undeclared_variable_notice = 1;
694 $$ = error_mark_node;
695 /* Prevent repeated error messages. */
696 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
697 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
701 else if (TREE_TYPE ($$) == error_mark_node)
702 $$ = error_mark_node;
703 else if (C_DECL_ANTICIPATED ($$))
705 /* The first time we see a build-in function used,
706 if it has not been declared. */
707 C_DECL_ANTICIPATED ($$) = 0;
708 if (yychar == YYEMPTY)
712 /* Omit the implicit declaration we
713 would ordinarily do, so we don't lose
714 the actual built in type.
715 But print a diagnostic for the mismatch. */
717 if (objc_method_context
718 && is_ivar (objc_ivar_chain, $1))
719 error ("Instance variable `%s' implicitly declared as function",
720 IDENTIFIER_POINTER (DECL_NAME ($$)));
723 if (TREE_CODE ($$) != FUNCTION_DECL)
724 error ("`%s' implicitly declared as function",
725 IDENTIFIER_POINTER (DECL_NAME ($$)));
726 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
727 != TYPE_MODE (integer_type_node))
728 && (TREE_TYPE (TREE_TYPE ($$))
730 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
731 IDENTIFIER_POINTER (DECL_NAME ($$)));
732 /* If it really returns void, change that to int. */
733 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
735 = build_function_type (integer_type_node,
736 TYPE_ARG_TYPES (TREE_TYPE ($$)));
739 pedwarn ("built-in function `%s' used without declaration",
740 IDENTIFIER_POINTER (DECL_NAME ($$)));
742 /* Do what we would ordinarily do when a fn is used. */
743 assemble_external ($$);
748 assemble_external ($$);
751 /* we have a definition - still check if iVariable */
753 if (!objc_receiver_context
754 || (objc_receiver_context
755 && strcmp (IDENTIFIER_POINTER ($1), "super")))
759 if (objc_method_context
760 && (decl = is_ivar (objc_ivar_chain, $1)))
762 if (IDENTIFIER_LOCAL_VALUE ($1))
763 warning ("local declaration of `%s' hides instance variable",
764 IDENTIFIER_POINTER ($1));
767 if (is_private (decl))
768 $$ = error_mark_node;
770 $$ = build_ivar_reference ($1);
774 else /* we have a message to super */
775 $$ = get_super_receiver ();
779 if (TREE_CODE ($$) == CONST_DECL)
781 $$ = DECL_INITIAL ($$);
782 /* This is to prevent an enum whose value is 0
783 from being considered a null pointer constant. */
784 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
785 TREE_CONSTANT ($$) = 1;
790 { $$ = combine_strings ($1); }
792 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
793 if (class == 'e' || class == '1'
794 || class == '2' || class == '<')
795 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
798 { $$ = error_mark_node; }
800 { if (current_function_decl == 0)
802 error ("braced-group within expression allowed only inside a function");
805 /* We must force a BLOCK for this level
806 so that, if it is not expanded later,
807 there is a way to turn off the entire subtree of blocks
808 that are contained in it. */
810 push_iterator_stack ();
812 $<ttype>$ = expand_start_stmt_expr (); }
816 pedwarn ("ANSI C forbids braced-groups within expressions");
817 pop_iterator_stack ();
819 rtl_exp = expand_end_stmt_expr ($<ttype>2);
820 /* The statements have side effects, so the group does. */
821 TREE_SIDE_EFFECTS (rtl_exp) = 1;
823 if (TREE_CODE ($3) == BLOCK)
825 /* Make a BIND_EXPR for the BLOCK already made. */
826 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
827 NULL_TREE, rtl_exp, $3);
828 /* Remove the block from the tree at this point.
829 It gets put back at the proper place
830 when the BIND_EXPR is expanded. */
836 | primary '(' exprlist ')' %prec '.'
837 { $$ = build_function_call ($1, $3); }
838 | primary '[' expr ']' %prec '.'
839 { $$ = build_array_ref ($1, $3); }
840 | primary '.' identifier
843 if (doing_objc_thang)
845 if (is_public ($1, $3))
846 $$ = build_component_ref ($1, $3);
848 $$ = error_mark_node;
852 $$ = build_component_ref ($1, $3);
854 | primary POINTSAT identifier
856 tree expr = build_indirect_ref ($1, "->");
859 if (doing_objc_thang)
861 if (is_public (expr, $3))
862 $$ = build_component_ref (expr, $3);
864 $$ = error_mark_node;
868 $$ = build_component_ref (expr, $3);
871 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
873 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
876 { $$ = build_message_expr ($1); }
878 { $$ = build_selector_expr ($1); }
880 { $$ = build_protocol_expr ($1); }
882 { $$ = build_encode_expr ($1); }
884 { $$ = build_objc_string_object ($1); }
888 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
892 { $$ = chainon ($1, $2); }
896 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
900 | objc_string OBJC_STRING
901 { $$ = chainon ($1, $2); }
905 old_style_parm_decls:
909 /* ... is used here to indicate a varargs function. */
912 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
915 /* The following are analogous to lineno_decl, decls and decl
916 except that they do not allow nested functions.
917 They are used for old-style parm decls. */
919 save_filename save_lineno datadecl
926 | datadecls lineno_datadecl
927 | lineno_datadecl errstmt
930 /* We don't allow prefix attributes here because they cause reduce/reduce
931 conflicts: we can't know whether we're parsing a function decl with
932 attribute suffix, or function defn with attribute prefix on first old
935 typed_declspecs_no_prefix_attr setspecs 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 | declmods_no_prefix_attr setspecs notype_initdecls ';'
941 { current_declspecs = TREE_VALUE (declspec_stack);
942 prefix_attributes = TREE_PURPOSE (declspec_stack);
943 declspec_stack = TREE_CHAIN (declspec_stack);
944 resume_momentary ($2); }
945 | typed_declspecs_no_prefix_attr ';'
946 { shadow_tag_warned ($1, 1);
947 pedwarn ("empty declaration"); }
948 | declmods_no_prefix_attr ';'
949 { pedwarn ("empty declaration"); }
952 /* This combination which saves a lineno before a decl
953 is the normal thing to use, rather than decl itself.
954 This is to avoid shift/reduce conflicts in contexts
955 where statement labels are allowed. */
957 save_filename save_lineno decl
965 | lineno_decl errstmt
968 /* records the type and storage class specs to use for processing
969 the declarators that follow.
970 Maintains a stack of outer-level values of current_declspecs,
971 for the sake of parm declarations nested in function declarators. */
972 setspecs: /* empty */
973 { $$ = suspend_momentary ();
974 pending_xref_error ();
975 declspec_stack = tree_cons (prefix_attributes,
978 split_specs_attrs ($<ttype>0,
979 ¤t_declspecs, &prefix_attributes); }
982 /* ??? Yuck. See after_type_declarator. */
983 setattrs: /* empty */
984 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
988 typed_declspecs setspecs 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 | declmods setspecs notype_initdecls ';'
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 | typed_declspecs setspecs 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 | declmods setspecs notype_nested_function
1004 { current_declspecs = TREE_VALUE (declspec_stack);
1005 prefix_attributes = TREE_PURPOSE (declspec_stack);
1006 declspec_stack = TREE_CHAIN (declspec_stack);
1007 resume_momentary ($2); }
1008 | typed_declspecs ';'
1009 { shadow_tag ($1); }
1011 { pedwarn ("empty declaration"); }
1013 { pedantic = $<itype>1; }
1016 /* Declspecs which contain at least one type specifier or typedef name.
1017 (Just `const' or `volatile' is not enough.)
1018 A typedef'd name following these is taken as a name to be declared.
1019 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1022 typespec reserved_declspecs
1023 { $$ = tree_cons (NULL_TREE, $1, $2); }
1024 | declmods typespec reserved_declspecs
1025 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1028 reserved_declspecs: /* empty */
1030 | reserved_declspecs typespecqual_reserved
1031 { $$ = tree_cons (NULL_TREE, $2, $1); }
1032 | reserved_declspecs SCSPEC
1033 { if (extra_warnings)
1034 warning ("`%s' is not at beginning of declaration",
1035 IDENTIFIER_POINTER ($2));
1036 $$ = tree_cons (NULL_TREE, $2, $1); }
1037 | reserved_declspecs attributes
1038 { $$ = tree_cons ($2, NULL_TREE, $1); }
1041 typed_declspecs_no_prefix_attr:
1042 typespec reserved_declspecs_no_prefix_attr
1043 { $$ = tree_cons (NULL_TREE, $1, $2); }
1044 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
1045 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1048 reserved_declspecs_no_prefix_attr:
1051 | reserved_declspecs_no_prefix_attr typespecqual_reserved
1052 { $$ = tree_cons (NULL_TREE, $2, $1); }
1053 | reserved_declspecs_no_prefix_attr SCSPEC
1054 { if (extra_warnings)
1055 warning ("`%s' is not at beginning of declaration",
1056 IDENTIFIER_POINTER ($2));
1057 $$ = tree_cons (NULL_TREE, $2, $1); }
1060 /* List of just storage classes, type modifiers, and prefix attributes.
1061 A declaration can start with just this, but then it cannot be used
1062 to redeclare a typedef-name.
1063 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1066 declmods_no_prefix_attr
1069 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
1070 | declmods declmods_no_prefix_attr
1071 { $$ = chainon ($2, $1); }
1072 | declmods attributes
1073 { $$ = tree_cons ($2, NULL_TREE, $1); }
1076 declmods_no_prefix_attr:
1078 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1079 TREE_STATIC ($$) = 1; }
1081 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1082 | declmods_no_prefix_attr TYPE_QUAL
1083 { $$ = tree_cons (NULL_TREE, $2, $1);
1084 TREE_STATIC ($$) = 1; }
1085 | declmods_no_prefix_attr SCSPEC
1086 { if (extra_warnings && TREE_STATIC ($1))
1087 warning ("`%s' is not at beginning of declaration",
1088 IDENTIFIER_POINTER ($2));
1089 $$ = tree_cons (NULL_TREE, $2, $1);
1090 TREE_STATIC ($$) = TREE_STATIC ($1); }
1094 /* Used instead of declspecs where storage classes are not allowed
1095 (that is, for typenames and structure components).
1096 Don't accept a typedef-name if anything but a modifier precedes it. */
1099 typespec reserved_typespecquals
1100 { $$ = tree_cons (NULL_TREE, $1, $2); }
1101 | nonempty_type_quals typespec reserved_typespecquals
1102 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1105 reserved_typespecquals: /* empty */
1107 | reserved_typespecquals typespecqual_reserved
1108 { $$ = tree_cons (NULL_TREE, $2, $1); }
1111 /* A typespec (but not a type qualifier).
1112 Once we have seen one of these in a declaration,
1113 if a typedef name appears then it is being redeclared. */
1118 { /* For a typedef name, record the meaning, not the name.
1119 In case of `foo foo, bar;'. */
1120 $$ = lookup_name ($1); }
1122 | CLASSNAME protocolrefs
1123 { $$ = get_static_reference ($1, $2); }
1124 | OBJECTNAME protocolrefs
1125 { $$ = get_object_reference ($2); }
1127 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1128 - nisse@lysator.liu.se */
1129 | non_empty_protocolrefs
1130 { $$ = get_object_reference ($1); }
1132 | TYPEOF '(' expr ')'
1133 { $$ = TREE_TYPE ($3); }
1134 | TYPEOF '(' typename ')'
1135 { $$ = groktypename ($3); }
1138 /* A typespec that is a reserved word, or a type qualifier. */
1140 typespecqual_reserved: TYPESPEC
1147 | initdecls ',' initdcl
1152 | notype_initdecls ',' initdcl
1158 | ASM_KEYWORD '(' string ')'
1159 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1165 declarator maybeasm maybe_attribute '='
1166 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1167 $3, prefix_attributes);
1168 start_init ($<ttype>$, $2, global_bindings_p ()); }
1170 /* Note how the declaration of the variable is in effect while its init is parsed! */
1172 finish_decl ($<ttype>5, $6, $2); }
1173 | declarator maybeasm maybe_attribute
1174 { tree d = start_decl ($1, current_declspecs, 0,
1175 $3, prefix_attributes);
1176 finish_decl (d, NULL_TREE, $2);
1181 notype_declarator maybeasm maybe_attribute '='
1182 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1183 $3, prefix_attributes);
1184 start_init ($<ttype>$, $2, global_bindings_p ()); }
1186 /* Note how the declaration of the variable is in effect while its init is parsed! */
1188 decl_attributes ($<ttype>5, $3, prefix_attributes);
1189 finish_decl ($<ttype>5, $6, $2); }
1190 | notype_declarator maybeasm maybe_attribute
1191 { tree d = start_decl ($1, current_declspecs, 0,
1192 $3, prefix_attributes);
1193 finish_decl (d, NULL_TREE, $2); }
1195 /* the * rules are dummies to accept the Apollo extended syntax
1196 so that the header files compile. */
1207 | attributes attribute
1208 { $$ = chainon ($1, $2); }
1212 ATTRIBUTE '(' '(' attribute_list ')' ')'
1219 | attribute_list ',' attrib
1220 { $$ = chainon ($1, $3); }
1227 { $$ = build_tree_list ($1, NULL_TREE); }
1228 | any_word '(' IDENTIFIER ')'
1229 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1230 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1231 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1232 | any_word '(' exprlist ')'
1233 { $$ = build_tree_list ($1, $3); }
1236 /* This still leaves out most reserved keywords,
1237 shouldn't we include them? */
1246 /* Initializers. `init' is the entry point. */
1251 { really_start_incremental_init (NULL_TREE);
1252 /* Note that the call to clear_momentary
1253 is in process_init_element. */
1254 push_momentary (); }
1255 initlist_maybe_comma '}'
1256 { $$ = pop_init_level (0);
1257 if ($$ == error_mark_node
1258 && ! (yychar == STRING || yychar == CONSTANT))
1261 pop_momentary_nofree (); }
1264 { $$ = error_mark_node; }
1267 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1268 initlist_maybe_comma:
1271 pedwarn ("ANSI C forbids empty initializer braces"); }
1272 | initlist1 maybecomma
1277 | initlist1 ',' initelt
1280 /* `initelt' is a single element of an initializer.
1281 It may use braces. */
1284 { process_init_element ($1); }
1286 { push_init_level (0); }
1287 initlist_maybe_comma '}'
1288 { process_init_element (pop_init_level (0)); }
1290 /* These are for labeled elements. The syntax for an array element
1291 initializer conflicts with the syntax for an Objective-C message,
1292 so don't include these productions in the Objective-C grammar. */
1294 | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1295 { set_init_index ($2, $4); }
1297 | '[' expr_no_commas ']' '='
1298 { set_init_index ($2, NULL_TREE); }
1300 | '[' expr_no_commas ']'
1301 { set_init_index ($2, NULL_TREE); }
1305 { set_init_label ($1); }
1307 | '.' identifier '='
1308 { set_init_label ($2); }
1314 { push_c_function_context ();
1315 if (! start_function (current_declspecs, $1,
1316 prefix_attributes, NULL_TREE, 1))
1318 pop_c_function_context ();
1321 reinit_parse_for_function (); }
1322 old_style_parm_decls
1323 { store_parm_decls (); }
1324 /* This used to use compstmt_or_error.
1325 That caused a bug with input `f(g) int g {}',
1326 where the use of YYERROR1 above caused an error
1327 which then was handled by compstmt_or_error.
1328 There followed a repeated execution of that same rule,
1329 which called YYERROR1 again, and so on. */
1331 { finish_function (1);
1332 pop_c_function_context (); }
1335 notype_nested_function:
1337 { push_c_function_context ();
1338 if (! start_function (current_declspecs, $1,
1339 prefix_attributes, NULL_TREE, 1))
1341 pop_c_function_context ();
1344 reinit_parse_for_function (); }
1345 old_style_parm_decls
1346 { store_parm_decls (); }
1347 /* This used to use compstmt_or_error.
1348 That caused a bug with input `f(g) int g {}',
1349 where the use of YYERROR1 above caused an error
1350 which then was handled by compstmt_or_error.
1351 There followed a repeated execution of that same rule,
1352 which called YYERROR1 again, and so on. */
1354 { finish_function (1);
1355 pop_c_function_context (); }
1358 /* Any kind of declarator (thus, all declarators allowed
1359 after an explicit typespec). */
1362 after_type_declarator
1366 /* A declarator that is allowed only after an explicit typespec. */
1368 after_type_declarator:
1369 '(' after_type_declarator ')'
1371 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1372 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1373 /* | after_type_declarator '(' error ')' %prec '.'
1374 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1375 poplevel (0, 0, 0); } */
1376 | after_type_declarator '[' expr ']' %prec '.'
1377 { $$ = build_nt (ARRAY_REF, $1, $3); }
1378 | after_type_declarator '[' ']' %prec '.'
1379 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1380 | '*' type_quals after_type_declarator %prec UNARY
1381 { $$ = make_pointer_declarator ($2, $3); }
1382 /* ??? Yuck. setattrs is a quick hack. We can't use
1383 prefix_attributes because $1 only applies to this
1384 declarator. We assume setspecs has already been done.
1385 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1386 attributes could be recognized here or in `attributes'). */
1387 | attributes setattrs after_type_declarator
1395 /* Kinds of declarator that can appear in a parameter list
1396 in addition to notype_declarator. This is like after_type_declarator
1397 but does not allow a typedef name in parentheses as an identifier
1398 (because it would conflict with a function with that typedef as arg). */
1401 parm_declarator '(' parmlist_or_identifiers %prec '.'
1402 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1403 /* | parm_declarator '(' error ')' %prec '.'
1404 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1405 poplevel (0, 0, 0); } */
1406 | parm_declarator '[' expr ']' %prec '.'
1407 { $$ = build_nt (ARRAY_REF, $1, $3); }
1408 | parm_declarator '[' ']' %prec '.'
1409 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1410 | '*' type_quals parm_declarator %prec UNARY
1411 { $$ = make_pointer_declarator ($2, $3); }
1412 /* ??? Yuck. setattrs is a quick hack. We can't use
1413 prefix_attributes because $1 only applies to this
1414 declarator. We assume setspecs has already been done.
1415 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1416 attributes could be recognized here or in `attributes'). */
1417 | attributes setattrs parm_declarator
1422 /* A declarator allowed whether or not there has been
1423 an explicit typespec. These cannot redeclare a typedef-name. */
1426 notype_declarator '(' parmlist_or_identifiers %prec '.'
1427 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1428 /* | notype_declarator '(' error ')' %prec '.'
1429 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1430 poplevel (0, 0, 0); } */
1431 | '(' notype_declarator ')'
1433 | '*' type_quals notype_declarator %prec UNARY
1434 { $$ = make_pointer_declarator ($2, $3); }
1435 | notype_declarator '[' expr ']' %prec '.'
1436 { $$ = build_nt (ARRAY_REF, $1, $3); }
1437 | notype_declarator '[' ']' %prec '.'
1438 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1439 /* ??? Yuck. setattrs is a quick hack. We can't use
1440 prefix_attributes because $1 only applies to this
1441 declarator. We assume setspecs has already been done.
1442 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1443 attributes could be recognized here or in `attributes'). */
1444 | attributes setattrs notype_declarator
1450 STRUCT identifier '{'
1451 { $$ = start_struct (RECORD_TYPE, $2);
1452 /* Start scope of tag before parsing components. */
1454 component_decl_list '}' maybe_attribute
1455 { $$ = finish_struct ($<ttype>4, $5, $7); }
1456 | STRUCT '{' component_decl_list '}' maybe_attribute
1457 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1461 { $$ = xref_tag (RECORD_TYPE, $2); }
1462 | UNION identifier '{'
1463 { $$ = start_struct (UNION_TYPE, $2); }
1464 component_decl_list '}' maybe_attribute
1465 { $$ = finish_struct ($<ttype>4, $5, $7); }
1466 | UNION '{' component_decl_list '}' maybe_attribute
1467 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1471 { $$ = xref_tag (UNION_TYPE, $2); }
1472 | ENUM identifier '{'
1473 { $<itype>3 = suspend_momentary ();
1474 $$ = start_enum ($2); }
1475 enumlist maybecomma_warn '}' maybe_attribute
1476 { $$ = finish_enum ($<ttype>4, nreverse ($5), $8);
1477 resume_momentary ($<itype>3); }
1479 { $<itype>2 = suspend_momentary ();
1480 $$ = start_enum (NULL_TREE); }
1481 enumlist maybecomma_warn '}' maybe_attribute
1482 { $$ = finish_enum ($<ttype>3, nreverse ($4), $7);
1483 resume_momentary ($<itype>2); }
1485 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1496 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1499 component_decl_list:
1500 component_decl_list2
1502 | component_decl_list2 component_decl
1503 { $$ = chainon ($1, $2);
1504 pedwarn ("no semicolon at end of struct or union"); }
1507 component_decl_list2: /* empty */
1509 | component_decl_list2 component_decl ';'
1510 { $$ = chainon ($1, $2); }
1511 | component_decl_list2 ';'
1513 pedwarn ("extra semicolon in struct or union specified"); }
1515 /* foo(sizeof(struct{ @defs(ClassName)})); */
1516 | DEFS '(' CLASSNAME ')'
1518 tree interface = lookup_interface ($3);
1521 $$ = get_class_ivars (interface);
1524 error ("Cannot find interface declaration for `%s'",
1525 IDENTIFIER_POINTER ($3));
1532 /* There is a shift-reduce conflict here, because `components' may
1533 start with a `typename'. It happens that shifting (the default resolution)
1534 does the right thing, because it treats the `typename' as part of
1535 a `typed_typespecs'.
1537 It is possible that this same technique would allow the distinction
1538 between `notype_initdecls' and `initdecls' to be eliminated.
1539 But I am being cautious and not trying it. */
1542 typed_typespecs setspecs components
1544 current_declspecs = TREE_VALUE (declspec_stack);
1545 prefix_attributes = TREE_PURPOSE (declspec_stack);
1546 declspec_stack = TREE_CHAIN (declspec_stack);
1547 resume_momentary ($2); }
1550 pedwarn ("ANSI C forbids member declarations with no members");
1553 | nonempty_type_quals setspecs components
1555 current_declspecs = TREE_VALUE (declspec_stack);
1556 prefix_attributes = TREE_PURPOSE (declspec_stack);
1557 declspec_stack = TREE_CHAIN (declspec_stack);
1558 resume_momentary ($2); }
1559 | nonempty_type_quals
1561 pedwarn ("ANSI C forbids member declarations with no members");
1566 | extension component_decl
1568 pedantic = $<itype>1; }
1572 component_declarator
1573 | components ',' component_declarator
1574 { $$ = chainon ($1, $3); }
1577 component_declarator:
1578 save_filename save_lineno declarator maybe_attribute
1579 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1580 decl_attributes ($$, $4, prefix_attributes); }
1581 | save_filename save_lineno
1582 declarator ':' expr_no_commas maybe_attribute
1583 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1584 decl_attributes ($$, $6, prefix_attributes); }
1585 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1586 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1587 decl_attributes ($$, $5, prefix_attributes); }
1590 /* We chain the enumerators in reverse order.
1591 They are put in forward order where enumlist is used.
1592 (The order used to be significant, but no longer is so.
1593 However, we still maintain the order, just to be clean.) */
1597 | enumlist ',' enumerator
1598 { if ($1 == error_mark_node)
1601 $$ = chainon ($3, $1); }
1603 { $$ = error_mark_node; }
1609 { $$ = build_enumerator ($1, NULL_TREE); }
1610 | identifier '=' expr_no_commas
1611 { $$ = build_enumerator ($1, $3); }
1615 typed_typespecs absdcl
1616 { $$ = build_tree_list ($1, $2); }
1617 | nonempty_type_quals absdcl
1618 { $$ = build_tree_list ($1, $2); }
1621 absdcl: /* an absolute declarator */
1627 nonempty_type_quals:
1629 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1630 | nonempty_type_quals TYPE_QUAL
1631 { $$ = tree_cons (NULL_TREE, $2, $1); }
1637 | type_quals TYPE_QUAL
1638 { $$ = tree_cons (NULL_TREE, $2, $1); }
1641 absdcl1: /* a nonempty absolute declarator */
1644 /* `(typedef)1' is `int'. */
1645 | '*' type_quals absdcl1 %prec UNARY
1646 { $$ = make_pointer_declarator ($2, $3); }
1647 | '*' type_quals %prec UNARY
1648 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1649 | absdcl1 '(' parmlist %prec '.'
1650 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1651 | absdcl1 '[' expr ']' %prec '.'
1652 { $$ = build_nt (ARRAY_REF, $1, $3); }
1653 | absdcl1 '[' ']' %prec '.'
1654 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1655 | '(' parmlist %prec '.'
1656 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1657 | '[' expr ']' %prec '.'
1658 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1660 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1661 /* ??? It appears we have to support attributes here, however
1662 using prefix_attributes is wrong. */
1665 /* at least one statement, the first of which parses without error. */
1666 /* stmts is used only after decls, so an invalid first statement
1667 is actually regarded as an invalid decl and part of the decls. */
1670 lineno_stmt_or_labels
1673 pedwarn ("ANSI C forbids label at end of compound statement");
1677 lineno_stmt_or_labels:
1678 lineno_stmt_or_label
1679 | lineno_stmt_or_labels lineno_stmt_or_label
1681 | lineno_stmt_or_labels errstmt
1693 pushlevel: /* empty */
1694 { emit_line_note (input_filename, lineno);
1698 expand_start_bindings (0);
1700 if (objc_method_context)
1706 /* Read zero or more forward-declarations for labels
1707 that nested functions can jump to. */
1712 pedwarn ("ANSI C forbids label declarations"); }
1717 | label_decls label_decl
1721 LABEL identifiers_or_typenames ';'
1723 for (link = $2; link; link = TREE_CHAIN (link))
1725 tree label = shadow_label (TREE_VALUE (link));
1726 C_DECLARED_LABEL_FLAG (label) = 1;
1727 declare_nonlocal_label (label);
1732 /* This is the body of a function definition.
1733 It causes syntax errors to ignore to the next openbrace. */
1740 compstmt_start: '{' { compstmt_count++; }
1742 compstmt: compstmt_start '}'
1743 { $$ = convert (void_type_node, integer_zero_node); }
1744 | compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1745 { emit_line_note (input_filename, lineno);
1746 expand_end_bindings (getdecls (), 1, 0);
1747 $$ = poplevel (1, 1, 0);
1748 if (yychar == CONSTANT || yychar == STRING)
1749 pop_momentary_nofree ();
1752 | compstmt_start pushlevel maybe_label_decls error '}'
1753 { emit_line_note (input_filename, lineno);
1754 expand_end_bindings (getdecls (), kept_level_p (), 0);
1755 $$ = poplevel (kept_level_p (), 0, 0);
1756 if (yychar == CONSTANT || yychar == STRING)
1757 pop_momentary_nofree ();
1760 | compstmt_start pushlevel maybe_label_decls stmts '}'
1761 { emit_line_note (input_filename, lineno);
1762 expand_end_bindings (getdecls (), kept_level_p (), 0);
1763 $$ = poplevel (kept_level_p (), 0, 0);
1764 if (yychar == CONSTANT || yychar == STRING)
1765 pop_momentary_nofree ();
1770 /* Value is number of statements counted as of the closeparen. */
1772 if_prefix lineno_labeled_stmt
1773 /* Make sure c_expand_end_cond is run once
1774 for each call to c_expand_start_cond.
1775 Otherwise a crash is likely. */
1781 { emit_line_note ($<filename>-1, $<lineno>0);
1782 c_expand_start_cond (truthvalue_conversion ($3), 0,
1784 $<itype>$ = stmt_count;
1785 if_stmt_file = $<filename>-1;
1786 if_stmt_line = $<lineno>0;
1787 position_after_white_space (); }
1790 /* This is a subroutine of stmt.
1791 It is used twice, once for valid DO statements
1792 and once for catching errors in parsing the end test. */
1797 emit_line_note ($<filename>-1, $<lineno>0);
1798 /* See comment in `while' alternative, above. */
1800 expand_start_loop_continue_elsewhere (1);
1801 position_after_white_space (); }
1802 lineno_labeled_stmt WHILE
1803 { expand_loop_continue_here (); }
1807 { $$ = input_filename; }
1814 lineno_labeled_stmt:
1815 save_filename save_lineno stmt
1817 /* | save_filename save_lineno error
1820 | save_filename save_lineno label lineno_labeled_stmt
1824 lineno_stmt_or_label:
1825 save_filename save_lineno stmt_or_label
1836 /* Parse a single real statement, not including any labels. */
1843 emit_line_note ($<filename>-1, $<lineno>0);
1844 /* It appears that this should not be done--that a non-lvalue array
1845 shouldn't get an error if the value isn't used.
1846 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1847 if it appears as a top-level expression,
1848 but says nothing about non-lvalue arrays. */
1850 /* Call default_conversion to get an error
1851 on referring to a register array if pedantic. */
1852 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1853 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1854 $1 = default_conversion ($1);
1856 iterator_expand ($1);
1857 clear_momentary (); }
1859 { c_expand_start_else ();
1860 $<itype>1 = stmt_count;
1861 position_after_white_space (); }
1863 { c_expand_end_cond ();
1864 if (extra_warnings && stmt_count == $<itype>1)
1865 warning ("empty body in an else-statement"); }
1866 | simple_if %prec IF
1867 { c_expand_end_cond ();
1868 /* This warning is here instead of in simple_if, because we
1869 do not want a warning if an empty if is followed by an
1870 else statement. Increment stmt_count so we don't
1871 give a second error if this is a nested `if'. */
1872 if (extra_warnings && stmt_count++ == $<itype>1)
1873 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1874 "empty body in an if-statement"); }
1875 /* Make sure c_expand_end_cond is run once
1876 for each call to c_expand_start_cond.
1877 Otherwise a crash is likely. */
1878 | simple_if ELSE error
1879 { c_expand_end_cond (); }
1882 emit_line_note ($<filename>-1, $<lineno>0);
1883 /* The emit_nop used to come before emit_line_note,
1884 but that made the nop seem like part of the preceding line.
1885 And that was confusing when the preceding line was
1886 inside of an if statement and was not really executed.
1887 I think it ought to work to put the nop after the line number.
1888 We will see. --rms, July 15, 1991. */
1891 { /* Don't start the loop till we have succeeded
1892 in parsing the end test. This is to make sure
1893 that we end every loop we start. */
1894 expand_start_loop (1);
1895 emit_line_note (input_filename, lineno);
1896 expand_exit_loop_if_false (NULL_PTR,
1897 truthvalue_conversion ($4));
1898 position_after_white_space (); }
1900 { expand_end_loop (); }
1903 { emit_line_note (input_filename, lineno);
1904 expand_exit_loop_if_false (NULL_PTR,
1905 truthvalue_conversion ($3));
1907 clear_momentary (); }
1908 /* This rule is needed to make sure we end every loop we start. */
1909 | do_stmt_start error
1910 { expand_end_loop ();
1911 clear_momentary (); }
1915 emit_line_note ($<filename>-1, $<lineno>0);
1916 /* See comment in `while' alternative, above. */
1918 if ($3) c_expand_expr_stmt ($3);
1919 /* Next step is to call expand_start_loop_continue_elsewhere,
1920 but wait till after we parse the entire for (...).
1921 Otherwise, invalid input might cause us to call that
1922 fn without calling expand_end_loop. */
1925 /* Can't emit now; wait till after expand_start_loop... */
1926 { $<lineno>7 = lineno;
1927 $<filename>$ = input_filename; }
1930 /* Start the loop. Doing this after parsing
1931 all the expressions ensures we will end the loop. */
1932 expand_start_loop_continue_elsewhere (1);
1933 /* Emit the end-test, with a line number. */
1934 emit_line_note ($<filename>8, $<lineno>7);
1936 expand_exit_loop_if_false (NULL_PTR,
1937 truthvalue_conversion ($6));
1938 /* Don't let the tree nodes for $9 be discarded by
1939 clear_momentary during the parsing of the next stmt. */
1941 $<lineno>7 = lineno;
1942 $<filename>8 = input_filename;
1943 position_after_white_space (); }
1945 { /* Emit the increment expression, with a line number. */
1946 emit_line_note ($<filename>8, $<lineno>7);
1947 expand_loop_continue_here ();
1949 c_expand_expr_stmt ($9);
1950 if (yychar == CONSTANT || yychar == STRING)
1951 pop_momentary_nofree ();
1954 expand_end_loop (); }
1955 | SWITCH '(' expr ')'
1957 emit_line_note ($<filename>-1, $<lineno>0);
1958 c_expand_start_case ($3);
1959 /* Don't let the tree nodes for $3 be discarded by
1960 clear_momentary during the parsing of the next stmt. */
1962 position_after_white_space (); }
1964 { expand_end_case ($3);
1965 if (yychar == CONSTANT || yychar == STRING)
1966 pop_momentary_nofree ();
1971 emit_line_note ($<filename>-1, $<lineno>0);
1972 if ( ! expand_exit_something ())
1973 error ("break statement not within loop or switch"); }
1976 emit_line_note ($<filename>-1, $<lineno>0);
1977 if (! expand_continue_loop (NULL_PTR))
1978 error ("continue statement not within a loop"); }
1981 emit_line_note ($<filename>-1, $<lineno>0);
1982 c_expand_return (NULL_TREE); }
1985 emit_line_note ($<filename>-1, $<lineno>0);
1986 c_expand_return ($2); }
1987 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1989 emit_line_note ($<filename>-1, $<lineno>0);
1991 if ((TREE_CODE ($4) == ADDR_EXPR
1992 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1993 || TREE_CODE ($4) == STRING_CST)
1996 error ("argument of `asm' is not a constant string"); }
1997 /* This is the case with just output operands. */
1998 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2000 emit_line_note ($<filename>-1, $<lineno>0);
2001 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2002 $2 == ridpointers[(int)RID_VOLATILE],
2003 input_filename, lineno); }
2004 /* This is the case with input operands as well. */
2005 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2007 emit_line_note ($<filename>-1, $<lineno>0);
2008 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2009 $2 == ridpointers[(int)RID_VOLATILE],
2010 input_filename, lineno); }
2011 /* This is the case with clobbered registers as well. */
2012 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2013 asm_operands ':' asm_clobbers ')' ';'
2015 emit_line_note ($<filename>-1, $<lineno>0);
2016 c_expand_asm_operands ($4, $6, $8, $10,
2017 $2 == ridpointers[(int)RID_VOLATILE],
2018 input_filename, lineno); }
2019 | GOTO identifier ';'
2022 emit_line_note ($<filename>-1, $<lineno>0);
2023 decl = lookup_label ($2);
2026 TREE_USED (decl) = 1;
2032 pedwarn ("ANSI C forbids `goto *expr;'");
2034 emit_line_note ($<filename>-1, $<lineno>0);
2035 expand_computed_goto (convert (ptr_type_node, $3)); }
2040 all_iter_stmt_simple
2041 /* | all_iter_stmt_with_decl */
2044 all_iter_stmt_simple:
2047 /* The value returned by this action is */
2048 /* 1 if everything is OK */
2049 /* 0 in case of error or already bound iterator */
2052 if (TREE_CODE ($3) != VAR_DECL)
2053 error ("invalid `for (ITERATOR)' syntax");
2054 else if (! ITERATOR_P ($3))
2055 error ("`%s' is not an iterator",
2056 IDENTIFIER_POINTER (DECL_NAME ($3)));
2057 else if (ITERATOR_BOUND_P ($3))
2058 error ("`for (%s)' inside expansion of same iterator",
2059 IDENTIFIER_POINTER (DECL_NAME ($3)));
2063 iterator_for_loop_start ($3);
2069 iterator_for_loop_end ($3);
2072 /* This really should allow any kind of declaration,
2073 for generality. Fix it before turning it back on.
2075 all_iter_stmt_with_decl:
2076 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2078 */ /* The value returned by this action is */
2079 /* 1 if everything is OK */
2080 /* 0 in case of error or already bound iterator */
2082 iterator_for_loop_start ($6);
2086 iterator_for_loop_end ($6);
2087 emit_line_note (input_filename, lineno);
2088 expand_end_bindings (getdecls (), 1, 0);
2089 $<ttype>$ = poplevel (1, 1, 0);
2090 if (yychar == CONSTANT || yychar == STRING)
2091 pop_momentary_nofree ();
2097 /* Any kind of label, including jump labels and case labels.
2098 ANSI C accepts labels only before statements, but we allow them
2099 also at the end of a compound statement. */
2101 label: CASE expr_no_commas ':'
2102 { register tree value = check_case_value ($2);
2104 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2108 if (value != error_mark_node)
2111 int success = pushcase (value, convert_and_check,
2114 error ("case label not within a switch statement");
2115 else if (success == 2)
2117 error ("duplicate case value");
2118 error_with_decl (duplicate, "this is the first entry for that value");
2120 else if (success == 3)
2121 warning ("case value out of range");
2122 else if (success == 5)
2123 error ("case label within scope of cleanup or variable array");
2125 position_after_white_space (); }
2126 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2127 { register tree value1 = check_case_value ($2);
2128 register tree value2 = check_case_value ($4);
2130 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2133 pedwarn ("ANSI C forbids case ranges");
2136 if (value1 != error_mark_node && value2 != error_mark_node)
2139 int success = pushcase_range (value1, value2,
2140 convert_and_check, label,
2143 error ("case label not within a switch statement");
2144 else if (success == 2)
2146 error ("duplicate case value");
2147 error_with_decl (duplicate, "this is the first entry for that value");
2149 else if (success == 3)
2150 warning ("case value out of range");
2151 else if (success == 4)
2152 warning ("empty case range");
2153 else if (success == 5)
2154 error ("case label within scope of cleanup or variable array");
2156 position_after_white_space (); }
2161 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2162 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2165 error ("default label not within a switch statement");
2166 else if (success == 2)
2168 error ("multiple default labels in one switch");
2169 error_with_decl (duplicate, "this is the first default label");
2171 position_after_white_space (); }
2173 { tree label = define_label (input_filename, lineno, $1);
2177 expand_label (label);
2178 position_after_white_space (); }
2181 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2185 { emit_line_note (input_filename, lineno);
2188 { emit_line_note (input_filename, lineno); }
2197 /* These are the operands other than the first string and colon
2198 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2199 asm_operands: /* empty */
2201 | nonnull_asm_operands
2204 nonnull_asm_operands:
2206 | nonnull_asm_operands ',' asm_operand
2207 { $$ = chainon ($1, $3); }
2212 { $$ = build_tree_list ($1, $3); }
2217 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2218 | asm_clobbers ',' string
2219 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2222 /* This is what appears inside the parens in a function declarator.
2223 Its value is a list of ..._TYPE nodes. */
2226 clear_parm_order ();
2227 declare_parm_level (0); }
2230 parmlist_tags_warning ();
2231 poplevel (0, 0, 0); }
2239 pedwarn ("ANSI C forbids forward parameter declarations");
2240 /* Mark the forward decls as such. */
2241 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2242 TREE_ASM_WRITTEN (parm) = 1;
2243 clear_parm_order (); }
2247 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2250 /* This is what appears inside the parens in a function declarator.
2251 Is value is represented in the format that grokdeclarator expects. */
2252 parmlist_2: /* empty */
2253 { $$ = get_parm_info (0); }
2255 { $$ = get_parm_info (0);
2256 /* Gcc used to allow this as an extension. However, it does
2257 not work for all targets, and thus has been disabled.
2258 Also, since func (...) and func () are indistinguishable,
2259 it caused problems with the code in expand_builtin which
2260 tries to verify that BUILT_IN_NEXT_ARG is being used
2262 error ("ANSI C requires a named argument before `...'");
2265 { $$ = get_parm_info (1); }
2266 | parms ',' ELLIPSIS
2267 { $$ = get_parm_info (0); }
2272 { push_parm_decl ($1); }
2274 { push_parm_decl ($3); }
2277 /* A single parameter declaration or parameter type name,
2278 as found in a parmlist. */
2280 typed_declspecs setspecs parm_declarator maybe_attribute
2281 { $$ = build_tree_list (build_tree_list (current_declspecs,
2283 build_tree_list (prefix_attributes,
2285 current_declspecs = TREE_VALUE (declspec_stack);
2286 prefix_attributes = TREE_PURPOSE (declspec_stack);
2287 declspec_stack = TREE_CHAIN (declspec_stack);
2288 resume_momentary ($2); }
2289 | typed_declspecs setspecs notype_declarator maybe_attribute
2290 { $$ = build_tree_list (build_tree_list (current_declspecs,
2292 build_tree_list (prefix_attributes,
2294 current_declspecs = TREE_VALUE (declspec_stack);
2295 prefix_attributes = TREE_PURPOSE (declspec_stack);
2296 declspec_stack = TREE_CHAIN (declspec_stack);
2297 resume_momentary ($2); }
2298 | typed_declspecs setspecs absdcl maybe_attribute
2299 { $$ = build_tree_list (build_tree_list (current_declspecs,
2301 build_tree_list (prefix_attributes,
2303 current_declspecs = TREE_VALUE (declspec_stack);
2304 prefix_attributes = TREE_PURPOSE (declspec_stack);
2305 declspec_stack = TREE_CHAIN (declspec_stack);
2306 resume_momentary ($2); }
2307 | declmods setspecs notype_declarator maybe_attribute
2308 { $$ = build_tree_list (build_tree_list (current_declspecs,
2310 build_tree_list (prefix_attributes,
2312 current_declspecs = TREE_VALUE (declspec_stack);
2313 prefix_attributes = TREE_PURPOSE (declspec_stack);
2314 declspec_stack = TREE_CHAIN (declspec_stack);
2315 resume_momentary ($2); }
2317 | declmods setspecs absdcl maybe_attribute
2318 { $$ = build_tree_list (build_tree_list (current_declspecs,
2320 build_tree_list (prefix_attributes,
2322 current_declspecs = TREE_VALUE (declspec_stack);
2323 prefix_attributes = TREE_PURPOSE (declspec_stack);
2324 declspec_stack = TREE_CHAIN (declspec_stack);
2325 resume_momentary ($2); }
2328 /* This is used in a function definition
2329 where either a parmlist or an identifier list is ok.
2330 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2331 parmlist_or_identifiers:
2333 clear_parm_order ();
2334 declare_parm_level (1); }
2335 parmlist_or_identifiers_1
2337 parmlist_tags_warning ();
2338 poplevel (0, 0, 0); }
2341 parmlist_or_identifiers_1:
2345 for (t = $1; t; t = TREE_CHAIN (t))
2346 if (TREE_VALUE (t) == NULL_TREE)
2347 error ("`...' in old-style identifier list");
2348 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2351 /* A nonempty list of identifiers. */
2354 { $$ = build_tree_list (NULL_TREE, $1); }
2355 | identifiers ',' IDENTIFIER
2356 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2359 /* A nonempty list of identifiers, including typenames. */
2360 identifiers_or_typenames:
2362 { $$ = build_tree_list (NULL_TREE, $1); }
2363 | identifiers_or_typenames ',' identifier
2364 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2369 { $<itype>$ = pedantic;
2374 /* Objective-C productions. */
2384 if (objc_implementation_context)
2386 finish_class (objc_implementation_context);
2387 objc_ivar_chain = NULL_TREE;
2388 objc_implementation_context = NULL_TREE;
2391 warning ("`@end' must appear in an implementation context");
2395 /* A nonempty list of identifiers. */
2398 { $$ = build_tree_list (NULL_TREE, $1); }
2399 | identifier_list ',' identifier
2400 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2404 CLASS identifier_list ';'
2406 objc_declare_class ($2);
2410 ALIAS identifier identifier ';'
2412 objc_declare_alias ($2, $3);
2416 INTERFACE identifier protocolrefs '{'
2418 objc_interface_context = objc_ivar_context
2419 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2420 objc_public_flag = 0;
2424 continue_class (objc_interface_context);
2429 finish_class (objc_interface_context);
2430 objc_interface_context = NULL_TREE;
2433 | INTERFACE identifier protocolrefs
2435 objc_interface_context
2436 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2437 continue_class (objc_interface_context);
2442 finish_class (objc_interface_context);
2443 objc_interface_context = NULL_TREE;
2446 | INTERFACE identifier ':' identifier protocolrefs '{'
2448 objc_interface_context = objc_ivar_context
2449 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2450 objc_public_flag = 0;
2454 continue_class (objc_interface_context);
2459 finish_class (objc_interface_context);
2460 objc_interface_context = NULL_TREE;
2463 | INTERFACE identifier ':' identifier protocolrefs
2465 objc_interface_context
2466 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2467 continue_class (objc_interface_context);
2472 finish_class (objc_interface_context);
2473 objc_interface_context = NULL_TREE;
2476 | IMPLEMENTATION identifier '{'
2478 objc_implementation_context = objc_ivar_context
2479 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2480 objc_public_flag = 0;
2485 = continue_class (objc_implementation_context);
2488 | IMPLEMENTATION identifier
2490 objc_implementation_context
2491 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2493 = continue_class (objc_implementation_context);
2496 | IMPLEMENTATION identifier ':' identifier '{'
2498 objc_implementation_context = objc_ivar_context
2499 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2500 objc_public_flag = 0;
2505 = continue_class (objc_implementation_context);
2508 | IMPLEMENTATION identifier ':' identifier
2510 objc_implementation_context
2511 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2513 = continue_class (objc_implementation_context);
2516 | INTERFACE identifier '(' identifier ')' protocolrefs
2518 objc_interface_context
2519 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2520 continue_class (objc_interface_context);
2525 finish_class (objc_interface_context);
2526 objc_interface_context = NULL_TREE;
2529 | IMPLEMENTATION identifier '(' identifier ')'
2531 objc_implementation_context
2532 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2534 = continue_class (objc_implementation_context);
2539 PROTOCOL identifier protocolrefs
2541 remember_protocol_qualifiers ();
2542 objc_interface_context
2543 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2547 forget_protocol_qualifiers();
2548 finish_protocol(objc_interface_context);
2549 objc_interface_context = NULL_TREE;
2558 | non_empty_protocolrefs
2561 non_empty_protocolrefs:
2562 ARITHCOMPARE identifier_list ARITHCOMPARE
2564 if ($1 == LT_EXPR && $3 == GT_EXPR)
2572 ivar_decl_list visibility_spec ivar_decls
2577 PRIVATE { objc_public_flag = 2; }
2578 | PROTECTED { objc_public_flag = 0; }
2579 | PUBLIC { objc_public_flag = 1; }
2587 | ivar_decls ivar_decl ';'
2591 pedwarn ("extra semicolon in struct or union specified");
2596 /* There is a shift-reduce conflict here, because `components' may
2597 start with a `typename'. It happens that shifting (the default resolution)
2598 does the right thing, because it treats the `typename' as part of
2599 a `typed_typespecs'.
2601 It is possible that this same technique would allow the distinction
2602 between `notype_initdecls' and `initdecls' to be eliminated.
2603 But I am being cautious and not trying it. */
2606 typed_typespecs setspecs ivars
2608 current_declspecs = TREE_VALUE (declspec_stack);
2609 prefix_attributes = TREE_PURPOSE (declspec_stack);
2610 declspec_stack = TREE_CHAIN (declspec_stack);
2611 resume_momentary ($2); }
2612 | nonempty_type_quals setspecs ivars
2614 current_declspecs = TREE_VALUE (declspec_stack);
2615 prefix_attributes = TREE_PURPOSE (declspec_stack);
2616 declspec_stack = TREE_CHAIN (declspec_stack);
2617 resume_momentary ($2); }
2626 | ivars ',' ivar_declarator
2632 $$ = add_instance_variable (objc_ivar_context,
2634 $1, current_declspecs,
2637 | declarator ':' expr_no_commas
2639 $$ = add_instance_variable (objc_ivar_context,
2641 $1, current_declspecs, $3);
2643 | ':' expr_no_commas
2645 $$ = add_instance_variable (objc_ivar_context,
2648 current_declspecs, $2);
2655 remember_protocol_qualifiers ();
2656 if (objc_implementation_context)
2657 objc_inherit_code = CLASS_METHOD_DECL;
2659 fatal ("method definition not in class context");
2663 forget_protocol_qualifiers ();
2664 add_class_method (objc_implementation_context, $3);
2665 start_method_def ($3);
2666 objc_method_context = $3;
2670 continue_method_def ();
2674 finish_method_def ();
2675 objc_method_context = NULL_TREE;
2680 remember_protocol_qualifiers ();
2681 if (objc_implementation_context)
2682 objc_inherit_code = INSTANCE_METHOD_DECL;
2684 fatal ("method definition not in class context");
2688 forget_protocol_qualifiers ();
2689 add_instance_method (objc_implementation_context, $3);
2690 start_method_def ($3);
2691 objc_method_context = $3;
2695 continue_method_def ();
2699 finish_method_def ();
2700 objc_method_context = NULL_TREE;
2704 /* the reason for the strange actions in this rule
2705 is so that notype_initdecls when reached via datadef
2706 can find a valid list of type and sc specs in $0. */
2710 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2713 methodprotolist2: /* eliminates a shift/reduce conflict */
2716 | methodprotolist2 methodproto
2717 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2728 /* Remember protocol qualifiers in prototypes. */
2729 remember_protocol_qualifiers ();
2730 objc_inherit_code = CLASS_METHOD_DECL;
2734 /* Forget protocol qualifiers here. */
2735 forget_protocol_qualifiers ();
2736 add_class_method (objc_interface_context, $3);
2742 /* Remember protocol qualifiers in prototypes. */
2743 remember_protocol_qualifiers ();
2744 objc_inherit_code = INSTANCE_METHOD_DECL;
2748 /* Forget protocol qualifiers here. */
2749 forget_protocol_qualifiers ();
2750 add_instance_method (objc_interface_context, $3);
2756 '(' typename ')' unaryselector
2758 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2763 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2766 | '(' typename ')' keywordselector optparmlist
2768 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2771 | keywordselector optparmlist
2773 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2777 /* "optarglist" assumes that start_method_def has already been called...
2778 if it is not, the "xdecls" will not be placed in the proper scope */
2785 /* to get around the following situation: "int foo (int a) int b; {}" that
2786 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2801 typed_declspecs setspecs myparms ';'
2802 { current_declspecs = TREE_VALUE (declspec_stack);
2803 prefix_attributes = TREE_PURPOSE (declspec_stack);
2804 declspec_stack = TREE_CHAIN (declspec_stack);
2805 resume_momentary ($2); }
2806 | typed_declspecs ';'
2807 { shadow_tag ($1); }
2809 { pedwarn ("empty declaration"); }
2814 { push_parm_decl ($1); }
2815 | myparms ',' myparm
2816 { push_parm_decl ($3); }
2819 /* A single parameter declaration or parameter type name,
2820 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2823 parm_declarator maybe_attribute
2824 { $$ = build_tree_list (build_tree_list (current_declspecs,
2826 build_tree_list (prefix_attributes,
2828 | notype_declarator maybe_attribute
2829 { $$ = build_tree_list (build_tree_list (current_declspecs,
2831 build_tree_list (prefix_attributes,
2833 | absdcl maybe_attribute
2834 { $$ = build_tree_list (build_tree_list (current_declspecs,
2836 build_tree_list (prefix_attributes,
2847 /* oh what a kludge! */
2856 /* returns a tree list node generated by get_parm_info */
2869 | keywordselector keyworddecl
2871 $$ = chainon ($1, $2);
2883 ENUM { $$ = get_identifier (token_buffer); }
2884 | STRUCT { $$ = get_identifier (token_buffer); }
2885 | UNION { $$ = get_identifier (token_buffer); }
2886 | IF { $$ = get_identifier (token_buffer); }
2887 | ELSE { $$ = get_identifier (token_buffer); }
2888 | WHILE { $$ = get_identifier (token_buffer); }
2889 | DO { $$ = get_identifier (token_buffer); }
2890 | FOR { $$ = get_identifier (token_buffer); }
2891 | SWITCH { $$ = get_identifier (token_buffer); }
2892 | CASE { $$ = get_identifier (token_buffer); }
2893 | DEFAULT { $$ = get_identifier (token_buffer); }
2894 | BREAK { $$ = get_identifier (token_buffer); }
2895 | CONTINUE { $$ = get_identifier (token_buffer); }
2896 | RETURN { $$ = get_identifier (token_buffer); }
2897 | GOTO { $$ = get_identifier (token_buffer); }
2898 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2899 | SIZEOF { $$ = get_identifier (token_buffer); }
2900 | TYPEOF { $$ = get_identifier (token_buffer); }
2901 | ALIGNOF { $$ = get_identifier (token_buffer); }
2902 | TYPESPEC | TYPE_QUAL
2906 selector ':' '(' typename ')' identifier
2908 $$ = build_keyword_decl ($1, $4, $6);
2911 | selector ':' identifier
2913 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2916 | ':' '(' typename ')' identifier
2918 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2923 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2934 | keywordarglist keywordarg
2936 $$ = chainon ($1, $2);
2944 if (TREE_CHAIN ($1) == NULL_TREE)
2945 /* just return the expr., remove a level of indirection */
2946 $$ = TREE_VALUE ($1);
2948 /* we have a comma expr., we will collapse later */
2954 selector ':' keywordexpr
2956 $$ = build_tree_list ($1, $3);
2960 $$ = build_tree_list (NULL_TREE, $2);
2968 $$ = get_class_reference ($1);
2974 { objc_receiver_context = 1; }
2976 { objc_receiver_context = 0; }
2979 $$ = build_tree_list ($3, $5);
2990 | keywordnamelist keywordname
2992 $$ = chainon ($1, $2);
2999 $$ = build_tree_list ($1, NULL_TREE);
3003 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3008 SELECTOR '(' selectorarg ')'
3015 PROTOCOL '(' identifier ')'
3021 /* extension to support C-structures in the archiver */
3024 ENCODE '(' typename ')'
3026 $$ = groktypename ($3);