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> typename absdcl absdcl1 type_quals
201 %type <ttype> xexpr parms parm identifiers
203 %type <ttype> parmlist parmlist_1 parmlist_2
204 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
205 %type <ttype> identifiers_or_typenames
207 %type <itype> setspecs
209 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
211 %type <filename> save_filename
212 %type <lineno> save_lineno
215 /* the Objective-C nonterminals */
217 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
218 %type <ttype> methoddecl unaryselector keywordselector selector
219 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
220 %type <ttype> keywordexpr keywordarglist keywordarg
221 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
222 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
223 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
225 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
229 /* Number of statements (loosely speaking) and compound statements
231 static int stmt_count;
232 static int compstmt_count;
234 /* Input file and line number of the end of the body of last simple_if;
235 used by the stmt-rule immediately after simple_if returns. */
236 static char *if_stmt_file;
237 static int if_stmt_line;
239 /* List of types and structure classes of the current declaration. */
240 static tree current_declspecs = NULL_TREE;
241 static tree prefix_attributes = NULL_TREE;
243 /* Stack of saved values of current_declspecs and prefix_attributes. */
244 static tree declspec_stack;
246 /* 1 if we explained undeclared var errors. */
247 static int undeclared_variable_notice;
250 /* Objective-C specific information */
252 tree objc_interface_context;
253 tree objc_implementation_context;
254 tree objc_method_context;
255 tree objc_ivar_chain;
256 tree objc_ivar_context;
257 enum tree_code objc_inherit_code;
258 int objc_receiver_context;
259 int objc_public_flag;
263 /* Tell yyparse how to print a token's value, if yydebug is set. */
265 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
266 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
272 pedwarn ("ANSI C forbids an empty source file");
277 /* In case there were missing closebraces,
278 get us back to the global binding level. */
279 while (! global_bindings_p ())
285 /* the reason for the strange actions in this rule
286 is so that notype_initdecls when reached via datadef
287 can find a valid list of type and sc specs in $0. */
290 {$<ttype>$ = NULL_TREE; } extdef
291 | extdefs {$<ttype>$ = NULL_TREE; } extdef
300 | ASM_KEYWORD '(' expr ')' ';'
302 if ((TREE_CODE ($3) == ADDR_EXPR
303 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
304 || TREE_CODE ($3) == STRING_CST)
307 error ("argument of `asm' is not a constant string"); }
309 { pedantic = $<itype>1; }
313 setspecs notype_initdecls ';'
315 error ("ANSI C forbids data definition with no type or storage class");
316 else if (!flag_traditional)
317 warning ("data definition has no type or storage class");
319 current_declspecs = TREE_VALUE (declspec_stack);
320 prefix_attributes = TREE_PURPOSE (declspec_stack);
321 declspec_stack = TREE_CHAIN (declspec_stack);
322 resume_momentary ($1); }
323 | declmods setspecs notype_initdecls ';'
324 { current_declspecs = TREE_VALUE (declspec_stack);
325 prefix_attributes = TREE_PURPOSE (declspec_stack);
326 declspec_stack = TREE_CHAIN (declspec_stack);
327 resume_momentary ($2); }
328 | typed_declspecs setspecs initdecls ';'
329 { current_declspecs = TREE_VALUE (declspec_stack);
330 prefix_attributes = TREE_PURPOSE (declspec_stack);
331 declspec_stack = TREE_CHAIN (declspec_stack);
332 resume_momentary ($2); }
334 { pedwarn ("empty declaration"); }
335 | typed_declspecs ';'
341 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
345 typed_declspecs setspecs declarator
346 { if (! start_function (current_declspecs, $3,
347 prefix_attributes, NULL_TREE, 0))
349 reinit_parse_for_function (); }
351 { store_parm_decls (); }
353 { finish_function (0);
354 current_declspecs = TREE_VALUE (declspec_stack);
355 prefix_attributes = TREE_PURPOSE (declspec_stack);
356 declspec_stack = TREE_CHAIN (declspec_stack);
357 resume_momentary ($2); }
358 | typed_declspecs setspecs declarator error
359 { current_declspecs = TREE_VALUE (declspec_stack);
360 prefix_attributes = TREE_PURPOSE (declspec_stack);
361 declspec_stack = TREE_CHAIN (declspec_stack);
362 resume_momentary ($2); }
363 | declmods setspecs notype_declarator
364 { if (! start_function (current_declspecs, $3,
365 prefix_attributes, NULL_TREE, 0))
367 reinit_parse_for_function (); }
369 { store_parm_decls (); }
371 { finish_function (0);
372 current_declspecs = TREE_VALUE (declspec_stack);
373 prefix_attributes = TREE_PURPOSE (declspec_stack);
374 declspec_stack = TREE_CHAIN (declspec_stack);
375 resume_momentary ($2); }
376 | declmods setspecs notype_declarator error
377 { current_declspecs = TREE_VALUE (declspec_stack);
378 prefix_attributes = TREE_PURPOSE (declspec_stack);
379 declspec_stack = TREE_CHAIN (declspec_stack);
380 resume_momentary ($2); }
381 | setspecs notype_declarator
382 { if (! start_function (NULL_TREE, $2,
383 prefix_attributes, NULL_TREE, 0))
385 reinit_parse_for_function (); }
387 { store_parm_decls (); }
389 { finish_function (0);
390 current_declspecs = TREE_VALUE (declspec_stack);
391 prefix_attributes = TREE_PURPOSE (declspec_stack);
392 declspec_stack = TREE_CHAIN (declspec_stack);
393 resume_momentary ($1); }
394 | setspecs notype_declarator error
395 { current_declspecs = TREE_VALUE (declspec_stack);
396 prefix_attributes = TREE_PURPOSE (declspec_stack);
397 declspec_stack = TREE_CHAIN (declspec_stack);
398 resume_momentary ($1); }
413 { $$ = NEGATE_EXPR; }
415 { $$ = CONVERT_EXPR; }
417 { $$ = PREINCREMENT_EXPR; }
419 { $$ = PREDECREMENT_EXPR; }
421 { $$ = BIT_NOT_EXPR; }
423 { $$ = TRUTH_NOT_EXPR; }
426 expr: nonnull_exprlist
427 { $$ = build_compound_expr ($1); }
438 { $$ = build_tree_list (NULL_TREE, $1); }
439 | nonnull_exprlist ',' expr_no_commas
440 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
445 | '*' cast_expr %prec UNARY
446 { $$ = build_indirect_ref ($2, "unary *"); }
447 /* __extension__ turns off -pedantic for following primary. */
448 | extension cast_expr %prec UNARY
450 pedantic = $<itype>1; }
451 | unop cast_expr %prec UNARY
452 { $$ = build_unary_op ($1, $2, 0);
453 overflow_warning ($$); }
454 /* Refer to the address of a label as a pointer. */
456 { tree label = lookup_label ($2);
458 pedwarn ("ANSI C forbids `&&'");
460 $$ = null_pointer_node;
463 TREE_USED (label) = 1;
464 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
465 TREE_CONSTANT ($$) = 1;
468 /* This seems to be impossible on some machines, so let's turn it off.
469 You can use __builtin_next_arg to find the anonymous stack args.
471 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
472 $$ = error_mark_node;
473 if (TREE_VALUE (tree_last (types)) == void_type_node)
474 error ("`&...' used in function with fixed number of arguments");
478 pedwarn ("ANSI C forbids `&...'");
479 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
480 $$ = build_unary_op (ADDR_EXPR, $$, 0);
483 | sizeof unary_expr %prec UNARY
485 if (TREE_CODE ($2) == COMPONENT_REF
486 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
487 error ("`sizeof' applied to a bit-field");
488 $$ = c_sizeof (TREE_TYPE ($2)); }
489 | sizeof '(' typename ')' %prec HYPERUNARY
491 $$ = c_sizeof (groktypename ($3)); }
492 | alignof unary_expr %prec UNARY
494 $$ = c_alignof_expr ($2); }
495 | alignof '(' typename ')' %prec HYPERUNARY
497 $$ = c_alignof (groktypename ($3)); }
498 | REALPART cast_expr %prec UNARY
499 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
500 | IMAGPART cast_expr %prec UNARY
501 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
505 SIZEOF { skip_evaluation++; }
509 ALIGNOF { skip_evaluation++; }
514 | '(' typename ')' cast_expr %prec UNARY
515 { tree type = groktypename ($2);
516 $$ = build_c_cast (type, $4); }
517 | '(' typename ')' '{'
518 { start_init (NULL_TREE, NULL, 0);
519 $2 = groktypename ($2);
520 really_start_incremental_init ($2); }
521 initlist_maybe_comma '}' %prec UNARY
523 tree result = pop_init_level (0);
528 pedwarn ("ANSI C forbids constructor expressions");
529 if (TYPE_NAME (type) != 0)
531 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
532 name = IDENTIFIER_POINTER (TYPE_NAME (type));
534 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
539 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
541 int failure = complete_array_type (type, $$, 1);
550 | expr_no_commas '+' expr_no_commas
551 { $$ = parser_build_binary_op ($2, $1, $3); }
552 | expr_no_commas '-' expr_no_commas
553 { $$ = parser_build_binary_op ($2, $1, $3); }
554 | expr_no_commas '*' expr_no_commas
555 { $$ = parser_build_binary_op ($2, $1, $3); }
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 LSHIFT expr_no_commas
561 { $$ = parser_build_binary_op ($2, $1, $3); }
562 | expr_no_commas RSHIFT expr_no_commas
563 { $$ = parser_build_binary_op ($2, $1, $3); }
564 | expr_no_commas ARITHCOMPARE expr_no_commas
565 { $$ = parser_build_binary_op ($2, $1, $3); }
566 | expr_no_commas EQCOMPARE expr_no_commas
567 { $$ = parser_build_binary_op ($2, $1, $3); }
568 | expr_no_commas '&' expr_no_commas
569 { $$ = parser_build_binary_op ($2, $1, $3); }
570 | expr_no_commas '|' expr_no_commas
571 { $$ = parser_build_binary_op ($2, $1, $3); }
572 | expr_no_commas '^' expr_no_commas
573 { $$ = parser_build_binary_op ($2, $1, $3); }
574 | expr_no_commas ANDAND
575 { $1 = truthvalue_conversion (default_conversion ($1));
576 skip_evaluation += $1 == boolean_false_node; }
578 { skip_evaluation -= $1 == boolean_false_node;
579 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
580 | expr_no_commas OROR
581 { $1 = truthvalue_conversion (default_conversion ($1));
582 skip_evaluation += $1 == boolean_true_node; }
584 { skip_evaluation -= $1 == boolean_true_node;
585 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
587 { $1 = truthvalue_conversion (default_conversion ($1));
588 skip_evaluation += $1 == boolean_false_node; }
590 { skip_evaluation += (($1 == boolean_true_node)
591 - ($1 == boolean_false_node)); }
593 { skip_evaluation -= $1 == boolean_true_node;
594 $$ = build_conditional_expr ($1, $4, $7); }
597 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
598 /* Make sure first operand is calculated only once. */
599 $<ttype>2 = save_expr ($1);
600 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
601 skip_evaluation += $1 == boolean_true_node; }
603 { skip_evaluation -= $1 == boolean_true_node;
604 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
605 | expr_no_commas '=' expr_no_commas
606 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
607 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
608 | expr_no_commas ASSIGN expr_no_commas
609 { $$ = build_modify_expr ($1, $2, $3);
610 /* This inhibits warnings in truthvalue_conversion. */
611 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
618 if (!$$ || $$ == error_mark_node)
620 if (yychar == YYEMPTY)
627 if (objc_receiver_context
628 && ! (objc_receiver_context
629 && strcmp (IDENTIFIER_POINTER ($1), "super")))
630 /* we have a message to super */
631 $$ = get_super_receiver ();
632 else if (objc_method_context
633 && (decl = is_ivar (objc_ivar_chain, $1)))
635 if (is_private (decl))
636 $$ = error_mark_node;
638 $$ = build_ivar_reference ($1);
643 /* Ordinary implicit function declaration. */
644 $$ = implicitly_declare ($1);
645 assemble_external ($$);
649 else if (current_function_decl == 0)
651 error ("`%s' undeclared here (not in a function)",
652 IDENTIFIER_POINTER ($1));
653 $$ = error_mark_node;
660 if (objc_receiver_context
661 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
662 /* we have a message to super */
663 $$ = get_super_receiver ();
664 else if (objc_method_context
665 && (decl = is_ivar (objc_ivar_chain, $1)))
667 if (is_private (decl))
668 $$ = error_mark_node;
670 $$ = build_ivar_reference ($1);
675 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
676 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
678 error ("`%s' undeclared (first use in this function)",
679 IDENTIFIER_POINTER ($1));
681 if (! undeclared_variable_notice)
683 error ("(Each undeclared identifier is reported only once");
684 error ("for each function it appears in.)");
685 undeclared_variable_notice = 1;
688 $$ = error_mark_node;
689 /* Prevent repeated error messages. */
690 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
691 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
695 else if (TREE_TYPE ($$) == error_mark_node)
696 $$ = error_mark_node;
697 else if (C_DECL_ANTICIPATED ($$))
699 /* The first time we see a build-in function used,
700 if it has not been declared. */
701 C_DECL_ANTICIPATED ($$) = 0;
702 if (yychar == YYEMPTY)
706 /* Omit the implicit declaration we
707 would ordinarily do, so we don't lose
708 the actual built in type.
709 But print a diagnostic for the mismatch. */
711 if (objc_method_context
712 && is_ivar (objc_ivar_chain, $1))
713 error ("Instance variable `%s' implicitly declared as function",
714 IDENTIFIER_POINTER (DECL_NAME ($$)));
717 if (TREE_CODE ($$) != FUNCTION_DECL)
718 error ("`%s' implicitly declared as function",
719 IDENTIFIER_POINTER (DECL_NAME ($$)));
720 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
721 != TYPE_MODE (integer_type_node))
722 && (TREE_TYPE (TREE_TYPE ($$))
724 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
725 IDENTIFIER_POINTER (DECL_NAME ($$)));
726 /* If it really returns void, change that to int. */
727 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
729 = build_function_type (integer_type_node,
730 TYPE_ARG_TYPES (TREE_TYPE ($$)));
733 pedwarn ("built-in function `%s' used without declaration",
734 IDENTIFIER_POINTER (DECL_NAME ($$)));
736 /* Do what we would ordinarily do when a fn is used. */
737 assemble_external ($$);
742 assemble_external ($$);
745 /* we have a definition - still check if iVariable */
747 if (!objc_receiver_context
748 || (objc_receiver_context
749 && strcmp (IDENTIFIER_POINTER ($1), "super")))
753 if (objc_method_context
754 && (decl = is_ivar (objc_ivar_chain, $1)))
756 if (IDENTIFIER_LOCAL_VALUE ($1))
757 warning ("local declaration of `%s' hides instance variable",
758 IDENTIFIER_POINTER ($1));
761 if (is_private (decl))
762 $$ = error_mark_node;
764 $$ = build_ivar_reference ($1);
768 else /* we have a message to super */
769 $$ = get_super_receiver ();
773 if (TREE_CODE ($$) == CONST_DECL)
775 $$ = DECL_INITIAL ($$);
776 /* This is to prevent an enum whose value is 0
777 from being considered a null pointer constant. */
778 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
779 TREE_CONSTANT ($$) = 1;
784 { $$ = combine_strings ($1); }
786 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
787 if (class == 'e' || class == '1'
788 || class == '2' || class == '<')
789 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
792 { $$ = error_mark_node; }
794 { if (current_function_decl == 0)
796 error ("braced-group within expression allowed only inside a function");
799 /* We must force a BLOCK for this level
800 so that, if it is not expanded later,
801 there is a way to turn off the entire subtree of blocks
802 that are contained in it. */
804 push_iterator_stack ();
806 $<ttype>$ = expand_start_stmt_expr (); }
810 pedwarn ("ANSI C forbids braced-groups within expressions");
811 pop_iterator_stack ();
813 rtl_exp = expand_end_stmt_expr ($<ttype>2);
814 /* The statements have side effects, so the group does. */
815 TREE_SIDE_EFFECTS (rtl_exp) = 1;
817 if (TREE_CODE ($3) == BLOCK)
819 /* Make a BIND_EXPR for the BLOCK already made. */
820 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
821 NULL_TREE, rtl_exp, $3);
822 /* Remove the block from the tree at this point.
823 It gets put back at the proper place
824 when the BIND_EXPR is expanded. */
830 | primary '(' exprlist ')' %prec '.'
831 { $$ = build_function_call ($1, $3); }
832 | primary '[' expr ']' %prec '.'
833 { $$ = build_array_ref ($1, $3); }
834 | primary '.' identifier
837 if (doing_objc_thang)
839 if (is_public ($1, $3))
840 $$ = build_component_ref ($1, $3);
842 $$ = error_mark_node;
846 $$ = build_component_ref ($1, $3);
848 | primary POINTSAT identifier
850 tree expr = build_indirect_ref ($1, "->");
853 if (doing_objc_thang)
855 if (is_public (expr, $3))
856 $$ = build_component_ref (expr, $3);
858 $$ = error_mark_node;
862 $$ = build_component_ref (expr, $3);
865 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
867 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
870 { $$ = build_message_expr ($1); }
872 { $$ = build_selector_expr ($1); }
874 { $$ = build_protocol_expr ($1); }
876 { $$ = build_encode_expr ($1); }
878 { $$ = build_objc_string_object ($1); }
882 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
886 { $$ = chainon ($1, $2); }
890 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
894 | objc_string OBJC_STRING
895 { $$ = chainon ($1, $2); }
899 old_style_parm_decls:
903 /* ... is used here to indicate a varargs function. */
906 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
909 /* The following are analogous to lineno_decl, decls and decl
910 except that they do not allow nested functions.
911 They are used for old-style parm decls. */
913 save_filename save_lineno datadecl
920 | datadecls lineno_datadecl
921 | lineno_datadecl errstmt
924 /* We don't allow prefix attributes here because they cause reduce/reduce
925 conflicts: we can't know whether we're parsing a function decl with
926 attribute suffix, or function defn with attribute prefix on first old
929 typed_declspecs_no_prefix_attr setspecs initdecls ';'
930 { current_declspecs = TREE_VALUE (declspec_stack);
931 prefix_attributes = TREE_PURPOSE (declspec_stack);
932 declspec_stack = TREE_CHAIN (declspec_stack);
933 resume_momentary ($2); }
934 | declmods_no_prefix_attr setspecs notype_initdecls ';'
935 { current_declspecs = TREE_VALUE (declspec_stack);
936 prefix_attributes = TREE_PURPOSE (declspec_stack);
937 declspec_stack = TREE_CHAIN (declspec_stack);
938 resume_momentary ($2); }
939 | typed_declspecs_no_prefix_attr ';'
940 { shadow_tag_warned ($1, 1);
941 pedwarn ("empty declaration"); }
942 | declmods_no_prefix_attr ';'
943 { pedwarn ("empty declaration"); }
946 /* This combination which saves a lineno before a decl
947 is the normal thing to use, rather than decl itself.
948 This is to avoid shift/reduce conflicts in contexts
949 where statement labels are allowed. */
951 save_filename save_lineno decl
959 | lineno_decl errstmt
962 /* records the type and storage class specs to use for processing
963 the declarators that follow.
964 Maintains a stack of outer-level values of current_declspecs,
965 for the sake of parm declarations nested in function declarators. */
966 setspecs: /* empty */
967 { $$ = suspend_momentary ();
968 pending_xref_error ();
969 declspec_stack = tree_cons (prefix_attributes,
972 split_specs_attrs ($<ttype>0,
973 ¤t_declspecs, &prefix_attributes); }
976 /* ??? Yuck. See after_type_declarator. */
977 setattrs: /* empty */
978 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
982 typed_declspecs setspecs initdecls ';'
983 { current_declspecs = TREE_VALUE (declspec_stack);
984 prefix_attributes = TREE_PURPOSE (declspec_stack);
985 declspec_stack = TREE_CHAIN (declspec_stack);
986 resume_momentary ($2); }
987 | declmods setspecs notype_initdecls ';'
988 { current_declspecs = TREE_VALUE (declspec_stack);
989 prefix_attributes = TREE_PURPOSE (declspec_stack);
990 declspec_stack = TREE_CHAIN (declspec_stack);
991 resume_momentary ($2); }
992 | typed_declspecs setspecs nested_function
993 { current_declspecs = TREE_VALUE (declspec_stack);
994 prefix_attributes = TREE_PURPOSE (declspec_stack);
995 declspec_stack = TREE_CHAIN (declspec_stack);
996 resume_momentary ($2); }
997 | declmods setspecs notype_nested_function
998 { current_declspecs = TREE_VALUE (declspec_stack);
999 prefix_attributes = TREE_PURPOSE (declspec_stack);
1000 declspec_stack = TREE_CHAIN (declspec_stack);
1001 resume_momentary ($2); }
1002 | typed_declspecs ';'
1003 { shadow_tag ($1); }
1005 { pedwarn ("empty declaration"); }
1007 { pedantic = $<itype>1; }
1010 /* Declspecs which contain at least one type specifier or typedef name.
1011 (Just `const' or `volatile' is not enough.)
1012 A typedef'd name following these is taken as a name to be declared.
1013 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1016 typespec reserved_declspecs
1017 { $$ = tree_cons (NULL_TREE, $1, $2); }
1018 | declmods typespec reserved_declspecs
1019 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1022 reserved_declspecs: /* empty */
1024 | reserved_declspecs typespecqual_reserved
1025 { $$ = tree_cons (NULL_TREE, $2, $1); }
1026 | reserved_declspecs SCSPEC
1027 { if (extra_warnings)
1028 warning ("`%s' is not at beginning of declaration",
1029 IDENTIFIER_POINTER ($2));
1030 $$ = tree_cons (NULL_TREE, $2, $1); }
1031 | reserved_declspecs attributes
1032 { $$ = tree_cons ($2, NULL_TREE, $1); }
1035 typed_declspecs_no_prefix_attr:
1036 typespec reserved_declspecs_no_prefix_attr
1037 { $$ = tree_cons (NULL_TREE, $1, $2); }
1038 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
1039 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1042 reserved_declspecs_no_prefix_attr:
1045 | reserved_declspecs_no_prefix_attr typespecqual_reserved
1046 { $$ = tree_cons (NULL_TREE, $2, $1); }
1047 | reserved_declspecs_no_prefix_attr SCSPEC
1048 { if (extra_warnings)
1049 warning ("`%s' is not at beginning of declaration",
1050 IDENTIFIER_POINTER ($2));
1051 $$ = tree_cons (NULL_TREE, $2, $1); }
1054 /* List of just storage classes, type modifiers, and prefix attributes.
1055 A declaration can start with just this, but then it cannot be used
1056 to redeclare a typedef-name.
1057 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1060 declmods_no_prefix_attr
1063 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
1064 | declmods declmods_no_prefix_attr
1065 { $$ = chainon ($2, $1); }
1066 | declmods attributes
1067 { $$ = tree_cons ($2, NULL_TREE, $1); }
1070 declmods_no_prefix_attr:
1072 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1073 TREE_STATIC ($$) = 1; }
1075 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1076 | declmods_no_prefix_attr TYPE_QUAL
1077 { $$ = tree_cons (NULL_TREE, $2, $1);
1078 TREE_STATIC ($$) = 1; }
1079 | declmods_no_prefix_attr SCSPEC
1080 { if (extra_warnings && TREE_STATIC ($1))
1081 warning ("`%s' is not at beginning of declaration",
1082 IDENTIFIER_POINTER ($2));
1083 $$ = tree_cons (NULL_TREE, $2, $1);
1084 TREE_STATIC ($$) = TREE_STATIC ($1); }
1088 /* Used instead of declspecs where storage classes are not allowed
1089 (that is, for typenames and structure components).
1090 Don't accept a typedef-name if anything but a modifier precedes it. */
1093 typespec reserved_typespecquals
1094 { $$ = tree_cons (NULL_TREE, $1, $2); }
1095 | nonempty_type_quals typespec reserved_typespecquals
1096 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1099 reserved_typespecquals: /* empty */
1101 | reserved_typespecquals typespecqual_reserved
1102 { $$ = tree_cons (NULL_TREE, $2, $1); }
1105 /* A typespec (but not a type qualifier).
1106 Once we have seen one of these in a declaration,
1107 if a typedef name appears then it is being redeclared. */
1112 { /* For a typedef name, record the meaning, not the name.
1113 In case of `foo foo, bar;'. */
1114 $$ = lookup_name ($1); }
1116 | CLASSNAME protocolrefs
1117 { $$ = get_static_reference ($1, $2); }
1118 | OBJECTNAME protocolrefs
1119 { $$ = get_object_reference ($2); }
1121 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1122 - nisse@lysator.liu.se */
1123 | non_empty_protocolrefs
1124 { $$ = get_object_reference ($1); }
1126 | TYPEOF '(' expr ')'
1127 { $$ = TREE_TYPE ($3); }
1128 | TYPEOF '(' typename ')'
1129 { $$ = groktypename ($3); }
1132 /* A typespec that is a reserved word, or a type qualifier. */
1134 typespecqual_reserved: TYPESPEC
1141 | initdecls ',' initdcl
1146 | notype_initdecls ',' initdcl
1152 | ASM_KEYWORD '(' string ')'
1153 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1159 declarator maybeasm maybe_attribute '='
1160 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1161 $3, prefix_attributes);
1162 start_init ($<ttype>$, $2, global_bindings_p ()); }
1164 /* Note how the declaration of the variable is in effect while its init is parsed! */
1166 finish_decl ($<ttype>5, $6, $2); }
1167 | declarator maybeasm maybe_attribute
1168 { tree d = start_decl ($1, current_declspecs, 0,
1169 $3, prefix_attributes);
1170 finish_decl (d, NULL_TREE, $2);
1175 notype_declarator maybeasm maybe_attribute '='
1176 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1177 $3, prefix_attributes);
1178 start_init ($<ttype>$, $2, global_bindings_p ()); }
1180 /* Note how the declaration of the variable is in effect while its init is parsed! */
1182 decl_attributes ($<ttype>5, $3, prefix_attributes);
1183 finish_decl ($<ttype>5, $6, $2); }
1184 | notype_declarator maybeasm maybe_attribute
1185 { tree d = start_decl ($1, current_declspecs, 0,
1186 $3, prefix_attributes);
1187 finish_decl (d, NULL_TREE, $2); }
1189 /* the * rules are dummies to accept the Apollo extended syntax
1190 so that the header files compile. */
1201 | attributes attribute
1202 { $$ = chainon ($1, $2); }
1206 ATTRIBUTE '(' '(' attribute_list ')' ')'
1213 | attribute_list ',' attrib
1214 { $$ = chainon ($1, $3); }
1221 { $$ = build_tree_list ($1, NULL_TREE); }
1222 | any_word '(' IDENTIFIER ')'
1223 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1224 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1225 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1226 | any_word '(' exprlist ')'
1227 { $$ = build_tree_list ($1, $3); }
1230 /* This still leaves out most reserved keywords,
1231 shouldn't we include them? */
1240 /* Initializers. `init' is the entry point. */
1245 { really_start_incremental_init (NULL_TREE);
1246 /* Note that the call to clear_momentary
1247 is in process_init_element. */
1248 push_momentary (); }
1249 initlist_maybe_comma '}'
1250 { $$ = pop_init_level (0);
1251 if ($$ == error_mark_node
1252 && ! (yychar == STRING || yychar == CONSTANT))
1255 pop_momentary_nofree (); }
1258 { $$ = error_mark_node; }
1261 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1262 initlist_maybe_comma:
1265 pedwarn ("ANSI C forbids empty initializer braces"); }
1266 | initlist1 maybecomma
1271 | initlist1 ',' initelt
1274 /* `initelt' is a single element of an initializer.
1275 It may use braces. */
1278 { process_init_element ($1); }
1280 { push_init_level (0); }
1281 initlist_maybe_comma '}'
1282 { process_init_element (pop_init_level (0)); }
1284 /* These are for labeled elements. The syntax for an array element
1285 initializer conflicts with the syntax for an Objective-C message,
1286 so don't include these productions in the Objective-C grammar. */
1288 | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1289 { set_init_index ($2, $4); }
1291 | '[' expr_no_commas ']' '='
1292 { set_init_index ($2, NULL_TREE); }
1294 | '[' expr_no_commas ']'
1295 { set_init_index ($2, NULL_TREE); }
1299 { set_init_label ($1); }
1301 | '.' identifier '='
1302 { set_init_label ($2); }
1308 { push_c_function_context ();
1309 if (! start_function (current_declspecs, $1,
1310 prefix_attributes, NULL_TREE, 1))
1312 pop_c_function_context ();
1315 reinit_parse_for_function (); }
1316 old_style_parm_decls
1317 { store_parm_decls (); }
1318 /* This used to use compstmt_or_error.
1319 That caused a bug with input `f(g) int g {}',
1320 where the use of YYERROR1 above caused an error
1321 which then was handled by compstmt_or_error.
1322 There followed a repeated execution of that same rule,
1323 which called YYERROR1 again, and so on. */
1325 { finish_function (1);
1326 pop_c_function_context (); }
1329 notype_nested_function:
1331 { push_c_function_context ();
1332 if (! start_function (current_declspecs, $1,
1333 prefix_attributes, NULL_TREE, 1))
1335 pop_c_function_context ();
1338 reinit_parse_for_function (); }
1339 old_style_parm_decls
1340 { store_parm_decls (); }
1341 /* This used to use compstmt_or_error.
1342 That caused a bug with input `f(g) int g {}',
1343 where the use of YYERROR1 above caused an error
1344 which then was handled by compstmt_or_error.
1345 There followed a repeated execution of that same rule,
1346 which called YYERROR1 again, and so on. */
1348 { finish_function (1);
1349 pop_c_function_context (); }
1352 /* Any kind of declarator (thus, all declarators allowed
1353 after an explicit typespec). */
1356 after_type_declarator
1360 /* A declarator that is allowed only after an explicit typespec. */
1362 after_type_declarator:
1363 '(' after_type_declarator ')'
1365 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1366 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1367 /* | after_type_declarator '(' error ')' %prec '.'
1368 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1369 poplevel (0, 0, 0); } */
1370 | after_type_declarator '[' expr ']' %prec '.'
1371 { $$ = build_nt (ARRAY_REF, $1, $3); }
1372 | after_type_declarator '[' ']' %prec '.'
1373 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1374 | '*' type_quals after_type_declarator %prec UNARY
1375 { $$ = make_pointer_declarator ($2, $3); }
1376 /* ??? Yuck. setattrs is a quick hack. We can't use
1377 prefix_attributes because $1 only applies to this
1378 declarator. We assume setspecs has already been done.
1379 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1380 attributes could be recognized here or in `attributes'). */
1381 | attributes setattrs after_type_declarator
1389 /* Kinds of declarator that can appear in a parameter list
1390 in addition to notype_declarator. This is like after_type_declarator
1391 but does not allow a typedef name in parentheses as an identifier
1392 (because it would conflict with a function with that typedef as arg). */
1395 parm_declarator '(' parmlist_or_identifiers %prec '.'
1396 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1397 /* | parm_declarator '(' error ')' %prec '.'
1398 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1399 poplevel (0, 0, 0); } */
1400 | parm_declarator '[' expr ']' %prec '.'
1401 { $$ = build_nt (ARRAY_REF, $1, $3); }
1402 | parm_declarator '[' ']' %prec '.'
1403 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1404 | '*' type_quals parm_declarator %prec UNARY
1405 { $$ = make_pointer_declarator ($2, $3); }
1406 /* ??? Yuck. setattrs is a quick hack. We can't use
1407 prefix_attributes because $1 only applies to this
1408 declarator. We assume setspecs has already been done.
1409 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1410 attributes could be recognized here or in `attributes'). */
1411 | attributes setattrs parm_declarator
1416 /* A declarator allowed whether or not there has been
1417 an explicit typespec. These cannot redeclare a typedef-name. */
1420 notype_declarator '(' parmlist_or_identifiers %prec '.'
1421 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1422 /* | notype_declarator '(' error ')' %prec '.'
1423 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1424 poplevel (0, 0, 0); } */
1425 | '(' notype_declarator ')'
1427 | '*' type_quals notype_declarator %prec UNARY
1428 { $$ = make_pointer_declarator ($2, $3); }
1429 | notype_declarator '[' expr ']' %prec '.'
1430 { $$ = build_nt (ARRAY_REF, $1, $3); }
1431 | notype_declarator '[' ']' %prec '.'
1432 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1433 /* ??? Yuck. setattrs is a quick hack. We can't use
1434 prefix_attributes because $1 only applies to this
1435 declarator. We assume setspecs has already been done.
1436 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1437 attributes could be recognized here or in `attributes'). */
1438 | attributes setattrs notype_declarator
1444 STRUCT identifier '{'
1445 { $$ = start_struct (RECORD_TYPE, $2);
1446 /* Start scope of tag before parsing components. */
1448 component_decl_list '}' maybe_attribute
1449 { $$ = finish_struct ($<ttype>4, $5, $7); }
1450 | STRUCT '{' component_decl_list '}' maybe_attribute
1451 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1455 { $$ = xref_tag (RECORD_TYPE, $2); }
1456 | UNION identifier '{'
1457 { $$ = start_struct (UNION_TYPE, $2); }
1458 component_decl_list '}' maybe_attribute
1459 { $$ = finish_struct ($<ttype>4, $5, $7); }
1460 | UNION '{' component_decl_list '}' maybe_attribute
1461 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1465 { $$ = xref_tag (UNION_TYPE, $2); }
1466 | ENUM identifier '{'
1467 { $<itype>3 = suspend_momentary ();
1468 $$ = start_enum ($2); }
1469 enumlist maybecomma_warn '}' maybe_attribute
1470 { $$ = finish_enum ($<ttype>4, nreverse ($5), $8);
1471 resume_momentary ($<itype>3); }
1473 { $<itype>2 = suspend_momentary ();
1474 $$ = start_enum (NULL_TREE); }
1475 enumlist maybecomma_warn '}' maybe_attribute
1476 { $$ = finish_enum ($<ttype>3, nreverse ($4), $7);
1477 resume_momentary ($<itype>2); }
1479 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1490 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1493 component_decl_list:
1494 component_decl_list2
1496 | component_decl_list2 component_decl
1497 { $$ = chainon ($1, $2);
1498 pedwarn ("no semicolon at end of struct or union"); }
1501 component_decl_list2: /* empty */
1503 | component_decl_list2 component_decl ';'
1504 { $$ = chainon ($1, $2); }
1505 | component_decl_list2 ';'
1507 pedwarn ("extra semicolon in struct or union specified"); }
1509 /* foo(sizeof(struct{ @defs(ClassName)})); */
1510 | DEFS '(' CLASSNAME ')'
1512 tree interface = lookup_interface ($3);
1515 $$ = get_class_ivars (interface);
1518 error ("Cannot find interface declaration for `%s'",
1519 IDENTIFIER_POINTER ($3));
1526 /* There is a shift-reduce conflict here, because `components' may
1527 start with a `typename'. It happens that shifting (the default resolution)
1528 does the right thing, because it treats the `typename' as part of
1529 a `typed_typespecs'.
1531 It is possible that this same technique would allow the distinction
1532 between `notype_initdecls' and `initdecls' to be eliminated.
1533 But I am being cautious and not trying it. */
1536 typed_typespecs setspecs components
1538 current_declspecs = TREE_VALUE (declspec_stack);
1539 prefix_attributes = TREE_PURPOSE (declspec_stack);
1540 declspec_stack = TREE_CHAIN (declspec_stack);
1541 resume_momentary ($2); }
1544 pedwarn ("ANSI C forbids member declarations with no members");
1547 | nonempty_type_quals setspecs components
1549 current_declspecs = TREE_VALUE (declspec_stack);
1550 prefix_attributes = TREE_PURPOSE (declspec_stack);
1551 declspec_stack = TREE_CHAIN (declspec_stack);
1552 resume_momentary ($2); }
1553 | nonempty_type_quals
1555 pedwarn ("ANSI C forbids member declarations with no members");
1560 | extension component_decl
1562 pedantic = $<itype>1; }
1566 component_declarator
1567 | components ',' component_declarator
1568 { $$ = chainon ($1, $3); }
1571 component_declarator:
1572 save_filename save_lineno declarator maybe_attribute
1573 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1574 decl_attributes ($$, $4, prefix_attributes); }
1575 | save_filename save_lineno
1576 declarator ':' expr_no_commas maybe_attribute
1577 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1578 decl_attributes ($$, $6, prefix_attributes); }
1579 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1580 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1581 decl_attributes ($$, $5, prefix_attributes); }
1584 /* We chain the enumerators in reverse order.
1585 They are put in forward order where enumlist is used.
1586 (The order used to be significant, but no longer is so.
1587 However, we still maintain the order, just to be clean.) */
1591 | enumlist ',' enumerator
1592 { if ($1 == error_mark_node)
1595 $$ = chainon ($3, $1); }
1597 { $$ = error_mark_node; }
1603 { $$ = build_enumerator ($1, NULL_TREE); }
1604 | identifier '=' expr_no_commas
1605 { $$ = build_enumerator ($1, $3); }
1609 typed_typespecs absdcl
1610 { $$ = build_tree_list ($1, $2); }
1611 | nonempty_type_quals absdcl
1612 { $$ = build_tree_list ($1, $2); }
1615 absdcl: /* an absolute declarator */
1621 nonempty_type_quals:
1623 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1624 | nonempty_type_quals TYPE_QUAL
1625 { $$ = tree_cons (NULL_TREE, $2, $1); }
1631 | type_quals TYPE_QUAL
1632 { $$ = tree_cons (NULL_TREE, $2, $1); }
1635 absdcl1: /* a nonempty absolute declarator */
1638 /* `(typedef)1' is `int'. */
1639 | '*' type_quals absdcl1 %prec UNARY
1640 { $$ = make_pointer_declarator ($2, $3); }
1641 | '*' type_quals %prec UNARY
1642 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1643 | absdcl1 '(' parmlist %prec '.'
1644 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1645 | absdcl1 '[' expr ']' %prec '.'
1646 { $$ = build_nt (ARRAY_REF, $1, $3); }
1647 | absdcl1 '[' ']' %prec '.'
1648 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1649 | '(' parmlist %prec '.'
1650 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1651 | '[' expr ']' %prec '.'
1652 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1654 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1655 /* ??? It appears we have to support attributes here, however
1656 using prefix_attributes is wrong. */
1659 /* at least one statement, the first of which parses without error. */
1660 /* stmts is used only after decls, so an invalid first statement
1661 is actually regarded as an invalid decl and part of the decls. */
1664 lineno_stmt_or_labels
1667 pedwarn ("ANSI C forbids label at end of compound statement");
1671 lineno_stmt_or_labels:
1672 lineno_stmt_or_label
1673 | lineno_stmt_or_labels lineno_stmt_or_label
1675 | lineno_stmt_or_labels errstmt
1687 pushlevel: /* empty */
1688 { emit_line_note (input_filename, lineno);
1692 expand_start_bindings (0);
1694 if (objc_method_context)
1700 /* Read zero or more forward-declarations for labels
1701 that nested functions can jump to. */
1706 pedwarn ("ANSI C forbids label declarations"); }
1711 | label_decls label_decl
1715 LABEL identifiers_or_typenames ';'
1717 for (link = $2; link; link = TREE_CHAIN (link))
1719 tree label = shadow_label (TREE_VALUE (link));
1720 C_DECLARED_LABEL_FLAG (label) = 1;
1721 declare_nonlocal_label (label);
1726 /* This is the body of a function definition.
1727 It causes syntax errors to ignore to the next openbrace. */
1734 compstmt_start: '{' { compstmt_count++; }
1736 compstmt: compstmt_start '}'
1737 { $$ = convert (void_type_node, integer_zero_node); }
1738 | compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1739 { emit_line_note (input_filename, lineno);
1740 expand_end_bindings (getdecls (), 1, 0);
1741 $$ = poplevel (1, 1, 0);
1742 if (yychar == CONSTANT || yychar == STRING)
1743 pop_momentary_nofree ();
1746 | compstmt_start pushlevel maybe_label_decls error '}'
1747 { emit_line_note (input_filename, lineno);
1748 expand_end_bindings (getdecls (), kept_level_p (), 0);
1749 $$ = poplevel (kept_level_p (), 0, 0);
1750 if (yychar == CONSTANT || yychar == STRING)
1751 pop_momentary_nofree ();
1754 | compstmt_start pushlevel maybe_label_decls stmts '}'
1755 { emit_line_note (input_filename, lineno);
1756 expand_end_bindings (getdecls (), kept_level_p (), 0);
1757 $$ = poplevel (kept_level_p (), 0, 0);
1758 if (yychar == CONSTANT || yychar == STRING)
1759 pop_momentary_nofree ();
1764 /* Value is number of statements counted as of the closeparen. */
1766 if_prefix lineno_labeled_stmt
1767 /* Make sure c_expand_end_cond is run once
1768 for each call to c_expand_start_cond.
1769 Otherwise a crash is likely. */
1775 { emit_line_note ($<filename>-1, $<lineno>0);
1776 c_expand_start_cond (truthvalue_conversion ($3), 0,
1778 $<itype>$ = stmt_count;
1779 if_stmt_file = $<filename>-1;
1780 if_stmt_line = $<lineno>0;
1781 position_after_white_space (); }
1784 /* This is a subroutine of stmt.
1785 It is used twice, once for valid DO statements
1786 and once for catching errors in parsing the end test. */
1791 emit_line_note ($<filename>-1, $<lineno>0);
1792 /* See comment in `while' alternative, above. */
1794 expand_start_loop_continue_elsewhere (1);
1795 position_after_white_space (); }
1796 lineno_labeled_stmt WHILE
1797 { expand_loop_continue_here (); }
1801 { $$ = input_filename; }
1808 lineno_labeled_stmt:
1809 save_filename save_lineno stmt
1811 /* | save_filename save_lineno error
1814 | save_filename save_lineno label lineno_labeled_stmt
1818 lineno_stmt_or_label:
1819 save_filename save_lineno stmt_or_label
1830 /* Parse a single real statement, not including any labels. */
1837 emit_line_note ($<filename>-1, $<lineno>0);
1838 /* It appears that this should not be done--that a non-lvalue array
1839 shouldn't get an error if the value isn't used.
1840 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1841 if it appears as a top-level expression,
1842 but says nothing about non-lvalue arrays. */
1844 /* Call default_conversion to get an error
1845 on referring to a register array if pedantic. */
1846 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1847 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1848 $1 = default_conversion ($1);
1850 iterator_expand ($1);
1851 clear_momentary (); }
1853 { c_expand_start_else ();
1854 $<itype>1 = stmt_count;
1855 position_after_white_space (); }
1857 { c_expand_end_cond ();
1858 if (extra_warnings && stmt_count == $<itype>1)
1859 warning ("empty body in an else-statement"); }
1860 | simple_if %prec IF
1861 { c_expand_end_cond ();
1862 /* This warning is here instead of in simple_if, because we
1863 do not want a warning if an empty if is followed by an
1864 else statement. Increment stmt_count so we don't
1865 give a second error if this is a nested `if'. */
1866 if (extra_warnings && stmt_count++ == $<itype>1)
1867 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1868 "empty body in an if-statement"); }
1869 /* Make sure c_expand_end_cond is run once
1870 for each call to c_expand_start_cond.
1871 Otherwise a crash is likely. */
1872 | simple_if ELSE error
1873 { c_expand_end_cond (); }
1876 emit_line_note ($<filename>-1, $<lineno>0);
1877 /* The emit_nop used to come before emit_line_note,
1878 but that made the nop seem like part of the preceding line.
1879 And that was confusing when the preceding line was
1880 inside of an if statement and was not really executed.
1881 I think it ought to work to put the nop after the line number.
1882 We will see. --rms, July 15, 1991. */
1885 { /* Don't start the loop till we have succeeded
1886 in parsing the end test. This is to make sure
1887 that we end every loop we start. */
1888 expand_start_loop (1);
1889 emit_line_note (input_filename, lineno);
1890 expand_exit_loop_if_false (NULL_PTR,
1891 truthvalue_conversion ($4));
1892 position_after_white_space (); }
1894 { expand_end_loop (); }
1897 { emit_line_note (input_filename, lineno);
1898 expand_exit_loop_if_false (NULL_PTR,
1899 truthvalue_conversion ($3));
1901 clear_momentary (); }
1902 /* This rule is needed to make sure we end every loop we start. */
1903 | do_stmt_start error
1904 { expand_end_loop ();
1905 clear_momentary (); }
1909 emit_line_note ($<filename>-1, $<lineno>0);
1910 /* See comment in `while' alternative, above. */
1912 if ($3) c_expand_expr_stmt ($3);
1913 /* Next step is to call expand_start_loop_continue_elsewhere,
1914 but wait till after we parse the entire for (...).
1915 Otherwise, invalid input might cause us to call that
1916 fn without calling expand_end_loop. */
1919 /* Can't emit now; wait till after expand_start_loop... */
1920 { $<lineno>7 = lineno;
1921 $<filename>$ = input_filename; }
1924 /* Start the loop. Doing this after parsing
1925 all the expressions ensures we will end the loop. */
1926 expand_start_loop_continue_elsewhere (1);
1927 /* Emit the end-test, with a line number. */
1928 emit_line_note ($<filename>8, $<lineno>7);
1930 expand_exit_loop_if_false (NULL_PTR,
1931 truthvalue_conversion ($6));
1932 /* Don't let the tree nodes for $9 be discarded by
1933 clear_momentary during the parsing of the next stmt. */
1935 $<lineno>7 = lineno;
1936 $<filename>8 = input_filename;
1937 position_after_white_space (); }
1939 { /* Emit the increment expression, with a line number. */
1940 emit_line_note ($<filename>8, $<lineno>7);
1941 expand_loop_continue_here ();
1943 c_expand_expr_stmt ($9);
1944 if (yychar == CONSTANT || yychar == STRING)
1945 pop_momentary_nofree ();
1948 expand_end_loop (); }
1949 | SWITCH '(' expr ')'
1951 emit_line_note ($<filename>-1, $<lineno>0);
1952 c_expand_start_case ($3);
1953 /* Don't let the tree nodes for $3 be discarded by
1954 clear_momentary during the parsing of the next stmt. */
1956 position_after_white_space (); }
1958 { expand_end_case ($3);
1959 if (yychar == CONSTANT || yychar == STRING)
1960 pop_momentary_nofree ();
1965 emit_line_note ($<filename>-1, $<lineno>0);
1966 if ( ! expand_exit_something ())
1967 error ("break statement not within loop or switch"); }
1970 emit_line_note ($<filename>-1, $<lineno>0);
1971 if (! expand_continue_loop (NULL_PTR))
1972 error ("continue statement not within a loop"); }
1975 emit_line_note ($<filename>-1, $<lineno>0);
1976 c_expand_return (NULL_TREE); }
1979 emit_line_note ($<filename>-1, $<lineno>0);
1980 c_expand_return ($2); }
1981 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1983 emit_line_note ($<filename>-1, $<lineno>0);
1985 if ((TREE_CODE ($4) == ADDR_EXPR
1986 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1987 || TREE_CODE ($4) == STRING_CST)
1990 error ("argument of `asm' is not a constant string"); }
1991 /* This is the case with just output operands. */
1992 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1994 emit_line_note ($<filename>-1, $<lineno>0);
1995 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1996 $2 == ridpointers[(int)RID_VOLATILE],
1997 input_filename, lineno); }
1998 /* This is the case with input operands as well. */
1999 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2001 emit_line_note ($<filename>-1, $<lineno>0);
2002 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2003 $2 == ridpointers[(int)RID_VOLATILE],
2004 input_filename, lineno); }
2005 /* This is the case with clobbered registers as well. */
2006 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2007 asm_operands ':' asm_clobbers ')' ';'
2009 emit_line_note ($<filename>-1, $<lineno>0);
2010 c_expand_asm_operands ($4, $6, $8, $10,
2011 $2 == ridpointers[(int)RID_VOLATILE],
2012 input_filename, lineno); }
2013 | GOTO identifier ';'
2016 emit_line_note ($<filename>-1, $<lineno>0);
2017 decl = lookup_label ($2);
2020 TREE_USED (decl) = 1;
2026 pedwarn ("ANSI C forbids `goto *expr;'");
2028 emit_line_note ($<filename>-1, $<lineno>0);
2029 expand_computed_goto (convert (ptr_type_node, $3)); }
2034 all_iter_stmt_simple
2035 /* | all_iter_stmt_with_decl */
2038 all_iter_stmt_simple:
2041 /* The value returned by this action is */
2042 /* 1 if everything is OK */
2043 /* 0 in case of error or already bound iterator */
2046 if (TREE_CODE ($3) != VAR_DECL)
2047 error ("invalid `for (ITERATOR)' syntax");
2048 else if (! ITERATOR_P ($3))
2049 error ("`%s' is not an iterator",
2050 IDENTIFIER_POINTER (DECL_NAME ($3)));
2051 else if (ITERATOR_BOUND_P ($3))
2052 error ("`for (%s)' inside expansion of same iterator",
2053 IDENTIFIER_POINTER (DECL_NAME ($3)));
2057 iterator_for_loop_start ($3);
2063 iterator_for_loop_end ($3);
2066 /* This really should allow any kind of declaration,
2067 for generality. Fix it before turning it back on.
2069 all_iter_stmt_with_decl:
2070 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2072 */ /* The value returned by this action is */
2073 /* 1 if everything is OK */
2074 /* 0 in case of error or already bound iterator */
2076 iterator_for_loop_start ($6);
2080 iterator_for_loop_end ($6);
2081 emit_line_note (input_filename, lineno);
2082 expand_end_bindings (getdecls (), 1, 0);
2083 $<ttype>$ = poplevel (1, 1, 0);
2084 if (yychar == CONSTANT || yychar == STRING)
2085 pop_momentary_nofree ();
2091 /* Any kind of label, including jump labels and case labels.
2092 ANSI C accepts labels only before statements, but we allow them
2093 also at the end of a compound statement. */
2095 label: CASE expr_no_commas ':'
2096 { register tree value = check_case_value ($2);
2098 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2102 if (value != error_mark_node)
2107 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2108 pedwarn ("label must have integral type in ANSI C");
2110 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);