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.) */
72 #ifdef MULTIBYTE_CHARS
80 /* Since parsers are distinct for each language, put the language string
83 char *language_string = "GNU Obj-C";
86 char *language_string = "GNU C";
89 /* Like YYERROR but do call yyerror. */
90 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
92 /* Cause the `yydebug' variable to be defined. */
98 %union {long itype; tree ttype; enum tree_code code;
99 char *filename; int lineno; int ends_in_label; }
101 /* All identifiers that are not reserved words
102 and are not declared typedefs in the current block */
105 /* All identifiers that are declared typedefs in the current block.
106 In some contexts, they are treated just like IDENTIFIER,
107 but they can also serve as typespecs in declarations. */
110 /* Reserved words that specify storage class.
111 yylval contains an IDENTIFIER_NODE which indicates which one. */
114 /* Reserved words that specify type.
115 yylval contains an IDENTIFIER_NODE which indicates which one. */
118 /* Reserved words that qualify type: "const" or "volatile".
119 yylval contains an IDENTIFIER_NODE which indicates which one. */
122 /* Character or numeric constants.
123 yylval is the node for the constant. */
126 /* String constants in raw form.
127 yylval is a STRING_CST node. */
130 /* "...", used for functions with variable arglists. */
133 /* the reserved words */
134 /* SCO include files test "ASM", so use something else. */
135 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
136 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
137 %token ATTRIBUTE EXTENSION LABEL
138 %token REALPART IMAGPART
140 /* Add precedence rules to solve dangling else s/r conflict */
144 /* Define the operator tokens and their precedences.
145 The value is an integer because, if used, it is the tree code
146 to use in the expression made from the operator. */
148 %right <code> ASSIGN '='
149 %right <code> '?' ':'
155 %left <code> EQCOMPARE
156 %left <code> ARITHCOMPARE
157 %left <code> LSHIFT RSHIFT
159 %left <code> '*' '/' '%'
160 %right <code> UNARY PLUSPLUS MINUSMINUS
162 %left <code> POINTSAT '.' '(' '['
164 /* The Objective-C keywords. These are included in C and in
165 Objective C, so that the token codes are the same in both. */
166 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
167 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
169 /* Objective-C string constants in raw form.
170 yylval is an OBJC_STRING_CST node. */
176 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
177 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
178 %type <ttype> typed_declspecs reserved_declspecs
179 %type <ttype> typed_typespecs reserved_typespecquals
180 %type <ttype> declmods typespec typespecqual_reserved
181 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
182 %type <ttype> declmods_no_prefix_attr
183 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
184 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
185 %type <ttype> init maybeasm
186 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
187 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
188 %type <ttype> any_word
190 %type <ttype> compstmt
192 %type <ttype> declarator
193 %type <ttype> notype_declarator after_type_declarator
194 %type <ttype> parm_declarator
196 %type <ttype> structsp component_decl_list component_decl_list2
197 %type <ttype> component_decl components component_declarator
198 %type <ttype> enumlist enumerator
199 %type <ttype> typename absdcl absdcl1 type_quals
200 %type <ttype> xexpr parms parm identifiers
202 %type <ttype> parmlist parmlist_1 parmlist_2
203 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
204 %type <ttype> identifiers_or_typenames
206 %type <itype> setspecs
208 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
210 %type <filename> save_filename
211 %type <lineno> save_lineno
214 /* the Objective-C nonterminals */
216 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
217 %type <ttype> methoddecl unaryselector keywordselector selector
218 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
219 %type <ttype> keywordexpr keywordarglist keywordarg
220 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
221 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
222 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
224 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
228 /* Number of statements (loosely speaking) and compound statements
230 static int stmt_count;
231 static int compstmt_count;
233 /* Input file and line number of the end of the body of last simple_if;
234 used by the stmt-rule immediately after simple_if returns. */
235 static char *if_stmt_file;
236 static int if_stmt_line;
238 /* List of types and structure classes of the current declaration. */
239 static tree current_declspecs = NULL_TREE;
240 static tree prefix_attributes = NULL_TREE;
242 /* Stack of saved values of current_declspecs and prefix_attributes. */
243 static tree declspec_stack;
245 /* 1 if we explained undeclared var errors. */
246 static int undeclared_variable_notice;
249 /* Objective-C specific information */
251 tree objc_interface_context;
252 tree objc_implementation_context;
253 tree objc_method_context;
254 tree objc_ivar_chain;
255 tree objc_ivar_context;
256 enum tree_code objc_inherit_code;
257 int objc_receiver_context;
258 int objc_public_flag;
262 /* Tell yyparse how to print a token's value, if yydebug is set. */
264 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
265 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
271 pedwarn ("ANSI C forbids an empty source file");
276 /* In case there were missing closebraces,
277 get us back to the global binding level. */
278 while (! global_bindings_p ())
284 /* the reason for the strange actions in this rule
285 is so that notype_initdecls when reached via datadef
286 can find a valid list of type and sc specs in $0. */
289 {$<ttype>$ = NULL_TREE; } extdef
290 | extdefs {$<ttype>$ = NULL_TREE; } extdef
299 | ASM_KEYWORD '(' expr ')' ';'
301 if ((TREE_CODE ($3) == ADDR_EXPR
302 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
303 || TREE_CODE ($3) == STRING_CST)
306 error ("argument of `asm' is not a constant string"); }
308 { pedantic = $<itype>1; }
312 setspecs notype_initdecls ';'
314 error ("ANSI C forbids data definition with no type or storage class");
315 else if (!flag_traditional)
316 warning ("data definition has no type or storage class");
318 current_declspecs = TREE_VALUE (declspec_stack);
319 prefix_attributes = TREE_PURPOSE (declspec_stack);
320 declspec_stack = TREE_CHAIN (declspec_stack);
321 resume_momentary ($1); }
322 | declmods setspecs notype_initdecls ';'
323 { current_declspecs = TREE_VALUE (declspec_stack);
324 prefix_attributes = TREE_PURPOSE (declspec_stack);
325 declspec_stack = TREE_CHAIN (declspec_stack);
326 resume_momentary ($2); }
327 | typed_declspecs setspecs initdecls ';'
328 { current_declspecs = TREE_VALUE (declspec_stack);
329 prefix_attributes = TREE_PURPOSE (declspec_stack);
330 declspec_stack = TREE_CHAIN (declspec_stack);
331 resume_momentary ($2); }
333 { pedwarn ("empty declaration"); }
334 | typed_declspecs ';'
340 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
344 typed_declspecs setspecs declarator
345 { if (! start_function (current_declspecs, $3,
346 prefix_attributes, NULL_TREE, 0))
348 reinit_parse_for_function (); }
350 { store_parm_decls (); }
352 { finish_function (0);
353 current_declspecs = TREE_VALUE (declspec_stack);
354 prefix_attributes = TREE_PURPOSE (declspec_stack);
355 declspec_stack = TREE_CHAIN (declspec_stack);
356 resume_momentary ($2); }
357 | typed_declspecs setspecs declarator error
358 { current_declspecs = TREE_VALUE (declspec_stack);
359 prefix_attributes = TREE_PURPOSE (declspec_stack);
360 declspec_stack = TREE_CHAIN (declspec_stack);
361 resume_momentary ($2); }
362 | declmods setspecs notype_declarator
363 { if (! start_function (current_declspecs, $3,
364 prefix_attributes, NULL_TREE, 0))
366 reinit_parse_for_function (); }
368 { store_parm_decls (); }
370 { finish_function (0);
371 current_declspecs = TREE_VALUE (declspec_stack);
372 prefix_attributes = TREE_PURPOSE (declspec_stack);
373 declspec_stack = TREE_CHAIN (declspec_stack);
374 resume_momentary ($2); }
375 | declmods setspecs notype_declarator error
376 { current_declspecs = TREE_VALUE (declspec_stack);
377 prefix_attributes = TREE_PURPOSE (declspec_stack);
378 declspec_stack = TREE_CHAIN (declspec_stack);
379 resume_momentary ($2); }
380 | setspecs notype_declarator
381 { if (! start_function (NULL_TREE, $2,
382 prefix_attributes, NULL_TREE, 0))
384 reinit_parse_for_function (); }
386 { store_parm_decls (); }
388 { finish_function (0);
389 current_declspecs = TREE_VALUE (declspec_stack);
390 prefix_attributes = TREE_PURPOSE (declspec_stack);
391 declspec_stack = TREE_CHAIN (declspec_stack);
392 resume_momentary ($1); }
393 | setspecs notype_declarator error
394 { current_declspecs = TREE_VALUE (declspec_stack);
395 prefix_attributes = TREE_PURPOSE (declspec_stack);
396 declspec_stack = TREE_CHAIN (declspec_stack);
397 resume_momentary ($1); }
412 { $$ = NEGATE_EXPR; }
414 { $$ = CONVERT_EXPR; }
416 { $$ = PREINCREMENT_EXPR; }
418 { $$ = PREDECREMENT_EXPR; }
420 { $$ = BIT_NOT_EXPR; }
422 { $$ = TRUTH_NOT_EXPR; }
425 expr: nonnull_exprlist
426 { $$ = build_compound_expr ($1); }
437 { $$ = build_tree_list (NULL_TREE, $1); }
438 | nonnull_exprlist ',' expr_no_commas
439 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
444 | '*' cast_expr %prec UNARY
445 { $$ = build_indirect_ref ($2, "unary *"); }
446 /* __extension__ turns off -pedantic for following primary. */
447 | extension cast_expr %prec UNARY
449 pedantic = $<itype>1; }
450 | unop cast_expr %prec UNARY
451 { $$ = build_unary_op ($1, $2, 0);
452 overflow_warning ($$); }
453 /* Refer to the address of a label as a pointer. */
455 { tree label = lookup_label ($2);
457 pedwarn ("ANSI C forbids `&&'");
459 $$ = null_pointer_node;
462 TREE_USED (label) = 1;
463 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
464 TREE_CONSTANT ($$) = 1;
467 /* This seems to be impossible on some machines, so let's turn it off.
468 You can use __builtin_next_arg to find the anonymous stack args.
470 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
471 $$ = error_mark_node;
472 if (TREE_VALUE (tree_last (types)) == void_type_node)
473 error ("`&...' used in function with fixed number of arguments");
477 pedwarn ("ANSI C forbids `&...'");
478 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
479 $$ = build_unary_op (ADDR_EXPR, $$, 0);
482 | sizeof unary_expr %prec UNARY
484 if (TREE_CODE ($2) == COMPONENT_REF
485 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
486 error ("`sizeof' applied to a bit-field");
487 $$ = c_sizeof (TREE_TYPE ($2)); }
488 | sizeof '(' typename ')' %prec HYPERUNARY
490 $$ = c_sizeof (groktypename ($3)); }
491 | alignof unary_expr %prec UNARY
493 $$ = c_alignof_expr ($2); }
494 | alignof '(' typename ')' %prec HYPERUNARY
496 $$ = c_alignof (groktypename ($3)); }
497 | REALPART cast_expr %prec UNARY
498 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
499 | IMAGPART cast_expr %prec UNARY
500 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
504 SIZEOF { skip_evaluation++; }
508 ALIGNOF { skip_evaluation++; }
513 | '(' typename ')' cast_expr %prec UNARY
514 { tree type = groktypename ($2);
515 $$ = build_c_cast (type, $4); }
516 | '(' typename ')' '{'
517 { start_init (NULL_TREE, NULL, 0);
518 $2 = groktypename ($2);
519 really_start_incremental_init ($2); }
520 initlist_maybe_comma '}' %prec UNARY
522 tree result = pop_init_level (0);
527 pedwarn ("ANSI C forbids constructor expressions");
528 if (TYPE_NAME (type) != 0)
530 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
531 name = IDENTIFIER_POINTER (TYPE_NAME (type));
533 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
538 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
540 int failure = complete_array_type (type, $$, 1);
549 | expr_no_commas '+' expr_no_commas
550 { $$ = parser_build_binary_op ($2, $1, $3); }
551 | expr_no_commas '-' expr_no_commas
552 { $$ = parser_build_binary_op ($2, $1, $3); }
553 | expr_no_commas '*' expr_no_commas
554 { $$ = parser_build_binary_op ($2, $1, $3); }
555 | expr_no_commas '/' expr_no_commas
556 { $$ = parser_build_binary_op ($2, $1, $3); }
557 | expr_no_commas '%' expr_no_commas
558 { $$ = parser_build_binary_op ($2, $1, $3); }
559 | expr_no_commas LSHIFT expr_no_commas
560 { $$ = parser_build_binary_op ($2, $1, $3); }
561 | expr_no_commas RSHIFT expr_no_commas
562 { $$ = parser_build_binary_op ($2, $1, $3); }
563 | expr_no_commas ARITHCOMPARE expr_no_commas
564 { $$ = parser_build_binary_op ($2, $1, $3); }
565 | expr_no_commas EQCOMPARE expr_no_commas
566 { $$ = parser_build_binary_op ($2, $1, $3); }
567 | expr_no_commas '&' expr_no_commas
568 { $$ = parser_build_binary_op ($2, $1, $3); }
569 | expr_no_commas '|' expr_no_commas
570 { $$ = parser_build_binary_op ($2, $1, $3); }
571 | expr_no_commas '^' expr_no_commas
572 { $$ = parser_build_binary_op ($2, $1, $3); }
573 | expr_no_commas ANDAND
574 { $1 = truthvalue_conversion (default_conversion ($1));
575 skip_evaluation += $1 == boolean_false_node; }
577 { skip_evaluation -= $1 == boolean_false_node;
578 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
579 | expr_no_commas OROR
580 { $1 = truthvalue_conversion (default_conversion ($1));
581 skip_evaluation += $1 == boolean_true_node; }
583 { skip_evaluation -= $1 == boolean_true_node;
584 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
586 { $1 = truthvalue_conversion (default_conversion ($1));
587 skip_evaluation += $1 == boolean_false_node; }
589 { skip_evaluation += (($1 == boolean_true_node)
590 - ($1 == boolean_false_node)); }
592 { skip_evaluation -= $1 == boolean_true_node;
593 $$ = build_conditional_expr ($1, $4, $7); }
596 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
597 /* Make sure first operand is calculated only once. */
598 $<ttype>2 = save_expr ($1);
599 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
600 skip_evaluation += $1 == boolean_true_node; }
602 { skip_evaluation -= $1 == boolean_true_node;
603 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
604 | expr_no_commas '=' expr_no_commas
605 { $$ = build_modify_expr ($1, NOP_EXPR, $3);
606 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
607 | expr_no_commas ASSIGN expr_no_commas
608 { $$ = build_modify_expr ($1, $2, $3);
609 /* This inhibits warnings in truthvalue_conversion. */
610 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
617 if (!$$ || $$ == error_mark_node)
619 if (yychar == YYEMPTY)
626 if (objc_receiver_context
627 && ! (objc_receiver_context
628 && strcmp (IDENTIFIER_POINTER ($1), "super")))
629 /* we have a message to super */
630 $$ = get_super_receiver ();
631 else if (objc_method_context
632 && (decl = is_ivar (objc_ivar_chain, $1)))
634 if (is_private (decl))
635 $$ = error_mark_node;
637 $$ = build_ivar_reference ($1);
642 /* Ordinary implicit function declaration. */
643 $$ = implicitly_declare ($1);
644 assemble_external ($$);
648 else if (current_function_decl == 0)
650 error ("`%s' undeclared here (not in a function)",
651 IDENTIFIER_POINTER ($1));
652 $$ = error_mark_node;
659 if (objc_receiver_context
660 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
661 /* we have a message to super */
662 $$ = get_super_receiver ();
663 else if (objc_method_context
664 && (decl = is_ivar (objc_ivar_chain, $1)))
666 if (is_private (decl))
667 $$ = error_mark_node;
669 $$ = build_ivar_reference ($1);
674 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
675 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
677 error ("`%s' undeclared (first use in this function)",
678 IDENTIFIER_POINTER ($1));
680 if (! undeclared_variable_notice)
682 error ("(Each undeclared identifier is reported only once");
683 error ("for each function it appears in.)");
684 undeclared_variable_notice = 1;
687 $$ = error_mark_node;
688 /* Prevent repeated error messages. */
689 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
690 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
694 else if (TREE_TYPE ($$) == error_mark_node)
695 $$ = error_mark_node;
696 else if (C_DECL_ANTICIPATED ($$))
698 /* The first time we see a build-in function used,
699 if it has not been declared. */
700 C_DECL_ANTICIPATED ($$) = 0;
701 if (yychar == YYEMPTY)
705 /* Omit the implicit declaration we
706 would ordinarily do, so we don't lose
707 the actual built in type.
708 But print a diagnostic for the mismatch. */
710 if (objc_method_context
711 && is_ivar (objc_ivar_chain, $1))
712 error ("Instance variable `%s' implicitly declared as function",
713 IDENTIFIER_POINTER (DECL_NAME ($$)));
716 if (TREE_CODE ($$) != FUNCTION_DECL)
717 error ("`%s' implicitly declared as function",
718 IDENTIFIER_POINTER (DECL_NAME ($$)));
719 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
720 != TYPE_MODE (integer_type_node))
721 && (TREE_TYPE (TREE_TYPE ($$))
723 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
724 IDENTIFIER_POINTER (DECL_NAME ($$)));
725 /* If it really returns void, change that to int. */
726 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
728 = build_function_type (integer_type_node,
729 TYPE_ARG_TYPES (TREE_TYPE ($$)));
732 pedwarn ("built-in function `%s' used without declaration",
733 IDENTIFIER_POINTER (DECL_NAME ($$)));
735 /* Do what we would ordinarily do when a fn is used. */
736 assemble_external ($$);
741 assemble_external ($$);
744 /* we have a definition - still check if iVariable */
746 if (!objc_receiver_context
747 || (objc_receiver_context
748 && strcmp (IDENTIFIER_POINTER ($1), "super")))
752 if (objc_method_context
753 && (decl = is_ivar (objc_ivar_chain, $1)))
755 if (IDENTIFIER_LOCAL_VALUE ($1))
756 warning ("local declaration of `%s' hides instance variable",
757 IDENTIFIER_POINTER ($1));
760 if (is_private (decl))
761 $$ = error_mark_node;
763 $$ = build_ivar_reference ($1);
767 else /* we have a message to super */
768 $$ = get_super_receiver ();
772 if (TREE_CODE ($$) == CONST_DECL)
774 $$ = DECL_INITIAL ($$);
775 /* This is to prevent an enum whose value is 0
776 from being considered a null pointer constant. */
777 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
778 TREE_CONSTANT ($$) = 1;
783 { $$ = combine_strings ($1); }
785 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
786 if (class == 'e' || class == '1'
787 || class == '2' || class == '<')
788 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
791 { $$ = error_mark_node; }
793 { if (current_function_decl == 0)
795 error ("braced-group within expression allowed only inside a function");
798 /* We must force a BLOCK for this level
799 so that, if it is not expanded later,
800 there is a way to turn off the entire subtree of blocks
801 that are contained in it. */
803 push_iterator_stack ();
805 $<ttype>$ = expand_start_stmt_expr (); }
809 pedwarn ("ANSI C forbids braced-groups within expressions");
810 pop_iterator_stack ();
812 rtl_exp = expand_end_stmt_expr ($<ttype>2);
813 /* The statements have side effects, so the group does. */
814 TREE_SIDE_EFFECTS (rtl_exp) = 1;
816 if (TREE_CODE ($3) == BLOCK)
818 /* Make a BIND_EXPR for the BLOCK already made. */
819 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
820 NULL_TREE, rtl_exp, $3);
821 /* Remove the block from the tree at this point.
822 It gets put back at the proper place
823 when the BIND_EXPR is expanded. */
829 | primary '(' exprlist ')' %prec '.'
830 { $$ = build_function_call ($1, $3); }
831 | primary '[' expr ']' %prec '.'
832 { $$ = build_array_ref ($1, $3); }
833 | primary '.' identifier
836 if (doing_objc_thang)
838 if (is_public ($1, $3))
839 $$ = build_component_ref ($1, $3);
841 $$ = error_mark_node;
845 $$ = build_component_ref ($1, $3);
847 | primary POINTSAT identifier
849 tree expr = build_indirect_ref ($1, "->");
852 if (doing_objc_thang)
854 if (is_public (expr, $3))
855 $$ = build_component_ref (expr, $3);
857 $$ = error_mark_node;
861 $$ = build_component_ref (expr, $3);
864 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
866 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
869 { $$ = build_message_expr ($1); }
871 { $$ = build_selector_expr ($1); }
873 { $$ = build_protocol_expr ($1); }
875 { $$ = build_encode_expr ($1); }
877 { $$ = build_objc_string_object ($1); }
881 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
885 { $$ = chainon ($1, $2); }
889 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
893 | objc_string OBJC_STRING
894 { $$ = chainon ($1, $2); }
898 old_style_parm_decls:
902 /* ... is used here to indicate a varargs function. */
905 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
908 /* The following are analogous to lineno_decl, decls and decl
909 except that they do not allow nested functions.
910 They are used for old-style parm decls. */
912 save_filename save_lineno datadecl
919 | datadecls lineno_datadecl
920 | lineno_datadecl errstmt
923 /* We don't allow prefix attributes here because they cause reduce/reduce
924 conflicts: we can't know whether we're parsing a function decl with
925 attribute suffix, or function defn with attribute prefix on first old
928 typed_declspecs_no_prefix_attr setspecs initdecls ';'
929 { current_declspecs = TREE_VALUE (declspec_stack);
930 prefix_attributes = TREE_PURPOSE (declspec_stack);
931 declspec_stack = TREE_CHAIN (declspec_stack);
932 resume_momentary ($2); }
933 | declmods_no_prefix_attr setspecs notype_initdecls ';'
934 { current_declspecs = TREE_VALUE (declspec_stack);
935 prefix_attributes = TREE_PURPOSE (declspec_stack);
936 declspec_stack = TREE_CHAIN (declspec_stack);
937 resume_momentary ($2); }
938 | typed_declspecs_no_prefix_attr ';'
939 { shadow_tag_warned ($1, 1);
940 pedwarn ("empty declaration"); }
941 | declmods_no_prefix_attr ';'
942 { pedwarn ("empty declaration"); }
945 /* This combination which saves a lineno before a decl
946 is the normal thing to use, rather than decl itself.
947 This is to avoid shift/reduce conflicts in contexts
948 where statement labels are allowed. */
950 save_filename save_lineno decl
958 | lineno_decl errstmt
961 /* records the type and storage class specs to use for processing
962 the declarators that follow.
963 Maintains a stack of outer-level values of current_declspecs,
964 for the sake of parm declarations nested in function declarators. */
965 setspecs: /* empty */
966 { $$ = suspend_momentary ();
967 pending_xref_error ();
968 declspec_stack = tree_cons (prefix_attributes,
971 split_specs_attrs ($<ttype>0,
972 ¤t_declspecs, &prefix_attributes); }
975 /* ??? Yuck. See after_type_declarator. */
976 setattrs: /* empty */
977 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
981 typed_declspecs setspecs initdecls ';'
982 { current_declspecs = TREE_VALUE (declspec_stack);
983 prefix_attributes = TREE_PURPOSE (declspec_stack);
984 declspec_stack = TREE_CHAIN (declspec_stack);
985 resume_momentary ($2); }
986 | declmods setspecs notype_initdecls ';'
987 { current_declspecs = TREE_VALUE (declspec_stack);
988 prefix_attributes = TREE_PURPOSE (declspec_stack);
989 declspec_stack = TREE_CHAIN (declspec_stack);
990 resume_momentary ($2); }
991 | typed_declspecs setspecs nested_function
992 { current_declspecs = TREE_VALUE (declspec_stack);
993 prefix_attributes = TREE_PURPOSE (declspec_stack);
994 declspec_stack = TREE_CHAIN (declspec_stack);
995 resume_momentary ($2); }
996 | declmods setspecs notype_nested_function
997 { current_declspecs = TREE_VALUE (declspec_stack);
998 prefix_attributes = TREE_PURPOSE (declspec_stack);
999 declspec_stack = TREE_CHAIN (declspec_stack);
1000 resume_momentary ($2); }
1001 | typed_declspecs ';'
1002 { shadow_tag ($1); }
1004 { pedwarn ("empty declaration"); }
1006 { pedantic = $<itype>1; }
1009 /* Declspecs which contain at least one type specifier or typedef name.
1010 (Just `const' or `volatile' is not enough.)
1011 A typedef'd name following these is taken as a name to be declared.
1012 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1015 typespec reserved_declspecs
1016 { $$ = tree_cons (NULL_TREE, $1, $2); }
1017 | declmods typespec reserved_declspecs
1018 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1021 reserved_declspecs: /* empty */
1023 | reserved_declspecs typespecqual_reserved
1024 { $$ = tree_cons (NULL_TREE, $2, $1); }
1025 | reserved_declspecs SCSPEC
1026 { if (extra_warnings)
1027 warning ("`%s' is not at beginning of declaration",
1028 IDENTIFIER_POINTER ($2));
1029 $$ = tree_cons (NULL_TREE, $2, $1); }
1030 | reserved_declspecs attributes
1031 { $$ = tree_cons ($2, NULL_TREE, $1); }
1034 typed_declspecs_no_prefix_attr:
1035 typespec reserved_declspecs_no_prefix_attr
1036 { $$ = tree_cons (NULL_TREE, $1, $2); }
1037 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
1038 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1041 reserved_declspecs_no_prefix_attr:
1044 | reserved_declspecs_no_prefix_attr typespecqual_reserved
1045 { $$ = tree_cons (NULL_TREE, $2, $1); }
1046 | reserved_declspecs_no_prefix_attr SCSPEC
1047 { if (extra_warnings)
1048 warning ("`%s' is not at beginning of declaration",
1049 IDENTIFIER_POINTER ($2));
1050 $$ = tree_cons (NULL_TREE, $2, $1); }
1053 /* List of just storage classes, type modifiers, and prefix attributes.
1054 A declaration can start with just this, but then it cannot be used
1055 to redeclare a typedef-name.
1056 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1059 declmods_no_prefix_attr
1062 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
1063 | declmods declmods_no_prefix_attr
1064 { $$ = chainon ($2, $1); }
1065 | declmods attributes
1066 { $$ = tree_cons ($2, NULL_TREE, $1); }
1069 declmods_no_prefix_attr:
1071 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1072 TREE_STATIC ($$) = 1; }
1074 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1075 | declmods_no_prefix_attr TYPE_QUAL
1076 { $$ = tree_cons (NULL_TREE, $2, $1);
1077 TREE_STATIC ($$) = 1; }
1078 | declmods_no_prefix_attr SCSPEC
1079 { if (extra_warnings && TREE_STATIC ($1))
1080 warning ("`%s' is not at beginning of declaration",
1081 IDENTIFIER_POINTER ($2));
1082 $$ = tree_cons (NULL_TREE, $2, $1);
1083 TREE_STATIC ($$) = TREE_STATIC ($1); }
1087 /* Used instead of declspecs where storage classes are not allowed
1088 (that is, for typenames and structure components).
1089 Don't accept a typedef-name if anything but a modifier precedes it. */
1092 typespec reserved_typespecquals
1093 { $$ = tree_cons (NULL_TREE, $1, $2); }
1094 | nonempty_type_quals typespec reserved_typespecquals
1095 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1098 reserved_typespecquals: /* empty */
1100 | reserved_typespecquals typespecqual_reserved
1101 { $$ = tree_cons (NULL_TREE, $2, $1); }
1104 /* A typespec (but not a type qualifier).
1105 Once we have seen one of these in a declaration,
1106 if a typedef name appears then it is being redeclared. */
1111 { /* For a typedef name, record the meaning, not the name.
1112 In case of `foo foo, bar;'. */
1113 $$ = lookup_name ($1); }
1115 | CLASSNAME protocolrefs
1116 { $$ = get_static_reference ($1, $2); }
1117 | OBJECTNAME protocolrefs
1118 { $$ = get_object_reference ($2); }
1120 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1121 - nisse@lysator.liu.se */
1122 | non_empty_protocolrefs
1123 { $$ = get_object_reference ($1); }
1125 | TYPEOF '(' expr ')'
1126 { $$ = TREE_TYPE ($3); }
1127 | TYPEOF '(' typename ')'
1128 { $$ = groktypename ($3); }
1131 /* A typespec that is a reserved word, or a type qualifier. */
1133 typespecqual_reserved: TYPESPEC
1140 | initdecls ',' initdcl
1145 | notype_initdecls ',' initdcl
1151 | ASM_KEYWORD '(' string ')'
1152 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1158 declarator maybeasm maybe_attribute '='
1159 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1160 $3, prefix_attributes);
1161 start_init ($<ttype>$, $2, global_bindings_p ()); }
1163 /* Note how the declaration of the variable is in effect while its init is parsed! */
1165 finish_decl ($<ttype>5, $6, $2); }
1166 | declarator maybeasm maybe_attribute
1167 { tree d = start_decl ($1, current_declspecs, 0,
1168 $3, prefix_attributes);
1169 finish_decl (d, NULL_TREE, $2);
1174 notype_declarator maybeasm maybe_attribute '='
1175 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1176 $3, prefix_attributes);
1177 start_init ($<ttype>$, $2, global_bindings_p ()); }
1179 /* Note how the declaration of the variable is in effect while its init is parsed! */
1181 decl_attributes ($<ttype>5, $3, prefix_attributes);
1182 finish_decl ($<ttype>5, $6, $2); }
1183 | notype_declarator maybeasm maybe_attribute
1184 { tree d = start_decl ($1, current_declspecs, 0,
1185 $3, prefix_attributes);
1186 finish_decl (d, NULL_TREE, $2); }
1188 /* the * rules are dummies to accept the Apollo extended syntax
1189 so that the header files compile. */
1200 | attributes attribute
1201 { $$ = chainon ($1, $2); }
1205 ATTRIBUTE '(' '(' attribute_list ')' ')'
1212 | attribute_list ',' attrib
1213 { $$ = chainon ($1, $3); }
1220 { $$ = build_tree_list ($1, NULL_TREE); }
1221 | any_word '(' IDENTIFIER ')'
1222 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1223 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1224 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1225 | any_word '(' exprlist ')'
1226 { $$ = build_tree_list ($1, $3); }
1229 /* This still leaves out most reserved keywords,
1230 shouldn't we include them? */
1239 /* Initializers. `init' is the entry point. */
1244 { really_start_incremental_init (NULL_TREE);
1245 /* Note that the call to clear_momentary
1246 is in process_init_element. */
1247 push_momentary (); }
1248 initlist_maybe_comma '}'
1249 { $$ = pop_init_level (0);
1250 if ($$ == error_mark_node
1251 && ! (yychar == STRING || yychar == CONSTANT))
1254 pop_momentary_nofree (); }
1257 { $$ = error_mark_node; }
1260 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1261 initlist_maybe_comma:
1264 pedwarn ("ANSI C forbids empty initializer braces"); }
1265 | initlist1 maybecomma
1270 | initlist1 ',' initelt
1273 /* `initelt' is a single element of an initializer.
1274 It may use braces. */
1277 { process_init_element ($1); }
1279 { push_init_level (0); }
1280 initlist_maybe_comma '}'
1281 { process_init_element (pop_init_level (0)); }
1283 /* These are for labeled elements. The syntax for an array element
1284 initializer conflicts with the syntax for an Objective-C message,
1285 so don't include these productions in the Objective-C grammar. */
1287 | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '='
1288 { set_init_index ($2, $4); }
1290 | '[' expr_no_commas ']' '='
1291 { set_init_index ($2, NULL_TREE); }
1293 | '[' expr_no_commas ']'
1294 { set_init_index ($2, NULL_TREE); }
1298 { set_init_label ($1); }
1300 | '.' identifier '='
1301 { set_init_label ($2); }
1307 { push_c_function_context ();
1308 if (! start_function (current_declspecs, $1,
1309 prefix_attributes, NULL_TREE, 1))
1311 pop_c_function_context ();
1314 reinit_parse_for_function (); }
1315 old_style_parm_decls
1316 { store_parm_decls (); }
1317 /* This used to use compstmt_or_error.
1318 That caused a bug with input `f(g) int g {}',
1319 where the use of YYERROR1 above caused an error
1320 which then was handled by compstmt_or_error.
1321 There followed a repeated execution of that same rule,
1322 which called YYERROR1 again, and so on. */
1324 { finish_function (1);
1325 pop_c_function_context (); }
1328 notype_nested_function:
1330 { push_c_function_context ();
1331 if (! start_function (current_declspecs, $1,
1332 prefix_attributes, NULL_TREE, 1))
1334 pop_c_function_context ();
1337 reinit_parse_for_function (); }
1338 old_style_parm_decls
1339 { store_parm_decls (); }
1340 /* This used to use compstmt_or_error.
1341 That caused a bug with input `f(g) int g {}',
1342 where the use of YYERROR1 above caused an error
1343 which then was handled by compstmt_or_error.
1344 There followed a repeated execution of that same rule,
1345 which called YYERROR1 again, and so on. */
1347 { finish_function (1);
1348 pop_c_function_context (); }
1351 /* Any kind of declarator (thus, all declarators allowed
1352 after an explicit typespec). */
1355 after_type_declarator
1359 /* A declarator that is allowed only after an explicit typespec. */
1361 after_type_declarator:
1362 '(' after_type_declarator ')'
1364 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1365 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1366 /* | after_type_declarator '(' error ')' %prec '.'
1367 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1368 poplevel (0, 0, 0); } */
1369 | after_type_declarator '[' expr ']' %prec '.'
1370 { $$ = build_nt (ARRAY_REF, $1, $3); }
1371 | after_type_declarator '[' ']' %prec '.'
1372 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1373 | '*' type_quals after_type_declarator %prec UNARY
1374 { $$ = make_pointer_declarator ($2, $3); }
1375 /* ??? Yuck. setattrs is a quick hack. We can't use
1376 prefix_attributes because $1 only applies to this
1377 declarator. We assume setspecs has already been done.
1378 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1379 attributes could be recognized here or in `attributes'). */
1380 | attributes setattrs after_type_declarator
1388 /* Kinds of declarator that can appear in a parameter list
1389 in addition to notype_declarator. This is like after_type_declarator
1390 but does not allow a typedef name in parentheses as an identifier
1391 (because it would conflict with a function with that typedef as arg). */
1394 parm_declarator '(' parmlist_or_identifiers %prec '.'
1395 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1396 /* | parm_declarator '(' error ')' %prec '.'
1397 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1398 poplevel (0, 0, 0); } */
1399 | parm_declarator '[' expr ']' %prec '.'
1400 { $$ = build_nt (ARRAY_REF, $1, $3); }
1401 | parm_declarator '[' ']' %prec '.'
1402 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1403 | '*' type_quals parm_declarator %prec UNARY
1404 { $$ = make_pointer_declarator ($2, $3); }
1405 /* ??? Yuck. setattrs is a quick hack. We can't use
1406 prefix_attributes because $1 only applies to this
1407 declarator. We assume setspecs has already been done.
1408 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1409 attributes could be recognized here or in `attributes'). */
1410 | attributes setattrs parm_declarator
1415 /* A declarator allowed whether or not there has been
1416 an explicit typespec. These cannot redeclare a typedef-name. */
1419 notype_declarator '(' parmlist_or_identifiers %prec '.'
1420 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1421 /* | notype_declarator '(' error ')' %prec '.'
1422 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1423 poplevel (0, 0, 0); } */
1424 | '(' notype_declarator ')'
1426 | '*' type_quals notype_declarator %prec UNARY
1427 { $$ = make_pointer_declarator ($2, $3); }
1428 | notype_declarator '[' expr ']' %prec '.'
1429 { $$ = build_nt (ARRAY_REF, $1, $3); }
1430 | notype_declarator '[' ']' %prec '.'
1431 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1432 /* ??? Yuck. setattrs is a quick hack. We can't use
1433 prefix_attributes because $1 only applies to this
1434 declarator. We assume setspecs has already been done.
1435 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1436 attributes could be recognized here or in `attributes'). */
1437 | attributes setattrs notype_declarator
1443 STRUCT identifier '{'
1444 { $$ = start_struct (RECORD_TYPE, $2);
1445 /* Start scope of tag before parsing components. */
1447 component_decl_list '}' maybe_attribute
1448 { $$ = finish_struct ($<ttype>4, $5, $7); }
1449 | STRUCT '{' component_decl_list '}' maybe_attribute
1450 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1454 { $$ = xref_tag (RECORD_TYPE, $2); }
1455 | UNION identifier '{'
1456 { $$ = start_struct (UNION_TYPE, $2); }
1457 component_decl_list '}' maybe_attribute
1458 { $$ = finish_struct ($<ttype>4, $5, $7); }
1459 | UNION '{' component_decl_list '}' maybe_attribute
1460 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1464 { $$ = xref_tag (UNION_TYPE, $2); }
1465 | ENUM identifier '{'
1466 { $<itype>3 = suspend_momentary ();
1467 $$ = start_enum ($2); }
1468 enumlist maybecomma_warn '}' maybe_attribute
1469 { $$ = finish_enum ($<ttype>4, nreverse ($5), $8);
1470 resume_momentary ($<itype>3); }
1472 { $<itype>2 = suspend_momentary ();
1473 $$ = start_enum (NULL_TREE); }
1474 enumlist maybecomma_warn '}' maybe_attribute
1475 { $$ = finish_enum ($<ttype>3, nreverse ($4), $7);
1476 resume_momentary ($<itype>2); }
1478 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1489 { if (pedantic) pedwarn ("comma at end of enumerator list"); }
1492 component_decl_list:
1493 component_decl_list2
1495 | component_decl_list2 component_decl
1496 { $$ = chainon ($1, $2);
1497 pedwarn ("no semicolon at end of struct or union"); }
1500 component_decl_list2: /* empty */
1502 | component_decl_list2 component_decl ';'
1503 { $$ = chainon ($1, $2); }
1504 | component_decl_list2 ';'
1506 pedwarn ("extra semicolon in struct or union specified"); }
1508 /* foo(sizeof(struct{ @defs(ClassName)})); */
1509 | DEFS '(' CLASSNAME ')'
1511 tree interface = lookup_interface ($3);
1514 $$ = get_class_ivars (interface);
1517 error ("Cannot find interface declaration for `%s'",
1518 IDENTIFIER_POINTER ($3));
1525 /* There is a shift-reduce conflict here, because `components' may
1526 start with a `typename'. It happens that shifting (the default resolution)
1527 does the right thing, because it treats the `typename' as part of
1528 a `typed_typespecs'.
1530 It is possible that this same technique would allow the distinction
1531 between `notype_initdecls' and `initdecls' to be eliminated.
1532 But I am being cautious and not trying it. */
1535 typed_typespecs setspecs components
1537 current_declspecs = TREE_VALUE (declspec_stack);
1538 prefix_attributes = TREE_PURPOSE (declspec_stack);
1539 declspec_stack = TREE_CHAIN (declspec_stack);
1540 resume_momentary ($2); }
1543 pedwarn ("ANSI C forbids member declarations with no members");
1546 | nonempty_type_quals setspecs components
1548 current_declspecs = TREE_VALUE (declspec_stack);
1549 prefix_attributes = TREE_PURPOSE (declspec_stack);
1550 declspec_stack = TREE_CHAIN (declspec_stack);
1551 resume_momentary ($2); }
1552 | nonempty_type_quals
1554 pedwarn ("ANSI C forbids member declarations with no members");
1559 | extension component_decl
1561 pedantic = $<itype>1; }
1565 component_declarator
1566 | components ',' component_declarator
1567 { $$ = chainon ($1, $3); }
1570 component_declarator:
1571 save_filename save_lineno declarator maybe_attribute
1572 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1573 decl_attributes ($$, $4, prefix_attributes); }
1574 | save_filename save_lineno
1575 declarator ':' expr_no_commas maybe_attribute
1576 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1577 decl_attributes ($$, $6, prefix_attributes); }
1578 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1579 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1580 decl_attributes ($$, $5, prefix_attributes); }
1583 /* We chain the enumerators in reverse order.
1584 They are put in forward order where enumlist is used.
1585 (The order used to be significant, but no longer is so.
1586 However, we still maintain the order, just to be clean.) */
1590 | enumlist ',' enumerator
1591 { if ($1 == error_mark_node)
1594 $$ = chainon ($3, $1); }
1596 { $$ = error_mark_node; }
1602 { $$ = build_enumerator ($1, NULL_TREE); }
1603 | identifier '=' expr_no_commas
1604 { $$ = build_enumerator ($1, $3); }
1608 typed_typespecs absdcl
1609 { $$ = build_tree_list ($1, $2); }
1610 | nonempty_type_quals absdcl
1611 { $$ = build_tree_list ($1, $2); }
1614 absdcl: /* an absolute declarator */
1620 nonempty_type_quals:
1622 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1623 | nonempty_type_quals TYPE_QUAL
1624 { $$ = tree_cons (NULL_TREE, $2, $1); }
1630 | type_quals TYPE_QUAL
1631 { $$ = tree_cons (NULL_TREE, $2, $1); }
1634 absdcl1: /* a nonempty absolute declarator */
1637 /* `(typedef)1' is `int'. */
1638 | '*' type_quals absdcl1 %prec UNARY
1639 { $$ = make_pointer_declarator ($2, $3); }
1640 | '*' type_quals %prec UNARY
1641 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1642 | absdcl1 '(' parmlist %prec '.'
1643 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1644 | absdcl1 '[' expr ']' %prec '.'
1645 { $$ = build_nt (ARRAY_REF, $1, $3); }
1646 | absdcl1 '[' ']' %prec '.'
1647 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1648 | '(' parmlist %prec '.'
1649 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1650 | '[' expr ']' %prec '.'
1651 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1653 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1654 /* ??? It appears we have to support attributes here, however
1655 using prefix_attributes is wrong. */
1658 /* at least one statement, the first of which parses without error. */
1659 /* stmts is used only after decls, so an invalid first statement
1660 is actually regarded as an invalid decl and part of the decls. */
1663 lineno_stmt_or_labels
1666 pedwarn ("ANSI C forbids label at end of compound statement");
1670 lineno_stmt_or_labels:
1671 lineno_stmt_or_label
1672 | lineno_stmt_or_labels lineno_stmt_or_label
1674 | lineno_stmt_or_labels errstmt
1686 pushlevel: /* empty */
1687 { emit_line_note (input_filename, lineno);
1691 expand_start_bindings (0);
1693 if (objc_method_context)
1699 /* Read zero or more forward-declarations for labels
1700 that nested functions can jump to. */
1705 pedwarn ("ANSI C forbids label declarations"); }
1710 | label_decls label_decl
1714 LABEL identifiers_or_typenames ';'
1716 for (link = $2; link; link = TREE_CHAIN (link))
1718 tree label = shadow_label (TREE_VALUE (link));
1719 C_DECLARED_LABEL_FLAG (label) = 1;
1720 declare_nonlocal_label (label);
1725 /* This is the body of a function definition.
1726 It causes syntax errors to ignore to the next openbrace. */
1733 compstmt_start: '{' { compstmt_count++; }
1735 compstmt: compstmt_start '}'
1736 { $$ = convert (void_type_node, integer_zero_node); }
1737 | compstmt_start pushlevel maybe_label_decls decls xstmts '}'
1738 { emit_line_note (input_filename, lineno);
1739 expand_end_bindings (getdecls (), 1, 0);
1740 $$ = poplevel (1, 1, 0);
1741 if (yychar == CONSTANT || yychar == STRING)
1742 pop_momentary_nofree ();
1745 | compstmt_start pushlevel maybe_label_decls error '}'
1746 { emit_line_note (input_filename, lineno);
1747 expand_end_bindings (getdecls (), kept_level_p (), 0);
1748 $$ = poplevel (kept_level_p (), 0, 0);
1749 if (yychar == CONSTANT || yychar == STRING)
1750 pop_momentary_nofree ();
1753 | compstmt_start pushlevel maybe_label_decls stmts '}'
1754 { emit_line_note (input_filename, lineno);
1755 expand_end_bindings (getdecls (), kept_level_p (), 0);
1756 $$ = poplevel (kept_level_p (), 0, 0);
1757 if (yychar == CONSTANT || yychar == STRING)
1758 pop_momentary_nofree ();
1763 /* Value is number of statements counted as of the closeparen. */
1765 if_prefix lineno_labeled_stmt
1766 /* Make sure c_expand_end_cond is run once
1767 for each call to c_expand_start_cond.
1768 Otherwise a crash is likely. */
1774 { emit_line_note ($<filename>-1, $<lineno>0);
1775 c_expand_start_cond (truthvalue_conversion ($3), 0,
1777 $<itype>$ = stmt_count;
1778 if_stmt_file = $<filename>-1;
1779 if_stmt_line = $<lineno>0;
1780 position_after_white_space (); }
1783 /* This is a subroutine of stmt.
1784 It is used twice, once for valid DO statements
1785 and once for catching errors in parsing the end test. */
1790 emit_line_note ($<filename>-1, $<lineno>0);
1791 /* See comment in `while' alternative, above. */
1793 expand_start_loop_continue_elsewhere (1);
1794 position_after_white_space (); }
1795 lineno_labeled_stmt WHILE
1796 { expand_loop_continue_here (); }
1800 { $$ = input_filename; }
1807 lineno_labeled_stmt:
1808 save_filename save_lineno stmt
1810 /* | save_filename save_lineno error
1813 | save_filename save_lineno label lineno_labeled_stmt
1817 lineno_stmt_or_label:
1818 save_filename save_lineno stmt_or_label
1829 /* Parse a single real statement, not including any labels. */
1836 emit_line_note ($<filename>-1, $<lineno>0);
1837 /* It appears that this should not be done--that a non-lvalue array
1838 shouldn't get an error if the value isn't used.
1839 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1840 if it appears as a top-level expression,
1841 but says nothing about non-lvalue arrays. */
1843 /* Call default_conversion to get an error
1844 on referring to a register array if pedantic. */
1845 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1846 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1847 $1 = default_conversion ($1);
1849 iterator_expand ($1);
1850 clear_momentary (); }
1852 { c_expand_start_else ();
1853 $<itype>1 = stmt_count;
1854 position_after_white_space (); }
1856 { c_expand_end_cond ();
1857 if (extra_warnings && stmt_count == $<itype>1)
1858 warning ("empty body in an else-statement"); }
1859 | simple_if %prec IF
1860 { c_expand_end_cond ();
1861 /* This warning is here instead of in simple_if, because we
1862 do not want a warning if an empty if is followed by an
1863 else statement. Increment stmt_count so we don't
1864 give a second error if this is a nested `if'. */
1865 if (extra_warnings && stmt_count++ == $<itype>1)
1866 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1867 "empty body in an if-statement"); }
1868 /* Make sure c_expand_end_cond is run once
1869 for each call to c_expand_start_cond.
1870 Otherwise a crash is likely. */
1871 | simple_if ELSE error
1872 { c_expand_end_cond (); }
1875 emit_line_note ($<filename>-1, $<lineno>0);
1876 /* The emit_nop used to come before emit_line_note,
1877 but that made the nop seem like part of the preceding line.
1878 And that was confusing when the preceding line was
1879 inside of an if statement and was not really executed.
1880 I think it ought to work to put the nop after the line number.
1881 We will see. --rms, July 15, 1991. */
1884 { /* Don't start the loop till we have succeeded
1885 in parsing the end test. This is to make sure
1886 that we end every loop we start. */
1887 expand_start_loop (1);
1888 emit_line_note (input_filename, lineno);
1889 expand_exit_loop_if_false (NULL_PTR,
1890 truthvalue_conversion ($4));
1891 position_after_white_space (); }
1893 { expand_end_loop (); }
1896 { emit_line_note (input_filename, lineno);
1897 expand_exit_loop_if_false (NULL_PTR,
1898 truthvalue_conversion ($3));
1900 clear_momentary (); }
1901 /* This rule is needed to make sure we end every loop we start. */
1902 | do_stmt_start error
1903 { expand_end_loop ();
1904 clear_momentary (); }
1908 emit_line_note ($<filename>-1, $<lineno>0);
1909 /* See comment in `while' alternative, above. */
1911 if ($3) c_expand_expr_stmt ($3);
1912 /* Next step is to call expand_start_loop_continue_elsewhere,
1913 but wait till after we parse the entire for (...).
1914 Otherwise, invalid input might cause us to call that
1915 fn without calling expand_end_loop. */
1918 /* Can't emit now; wait till after expand_start_loop... */
1919 { $<lineno>7 = lineno;
1920 $<filename>$ = input_filename; }
1923 /* Start the loop. Doing this after parsing
1924 all the expressions ensures we will end the loop. */
1925 expand_start_loop_continue_elsewhere (1);
1926 /* Emit the end-test, with a line number. */
1927 emit_line_note ($<filename>8, $<lineno>7);
1929 expand_exit_loop_if_false (NULL_PTR,
1930 truthvalue_conversion ($6));
1931 /* Don't let the tree nodes for $9 be discarded by
1932 clear_momentary during the parsing of the next stmt. */
1934 $<lineno>7 = lineno;
1935 $<filename>8 = input_filename;
1936 position_after_white_space (); }
1938 { /* Emit the increment expression, with a line number. */
1939 emit_line_note ($<filename>8, $<lineno>7);
1940 expand_loop_continue_here ();
1942 c_expand_expr_stmt ($9);
1943 if (yychar == CONSTANT || yychar == STRING)
1944 pop_momentary_nofree ();
1947 expand_end_loop (); }
1948 | SWITCH '(' expr ')'
1950 emit_line_note ($<filename>-1, $<lineno>0);
1951 c_expand_start_case ($3);
1952 /* Don't let the tree nodes for $3 be discarded by
1953 clear_momentary during the parsing of the next stmt. */
1955 position_after_white_space (); }
1957 { expand_end_case ($3);
1958 if (yychar == CONSTANT || yychar == STRING)
1959 pop_momentary_nofree ();
1964 emit_line_note ($<filename>-1, $<lineno>0);
1965 if ( ! expand_exit_something ())
1966 error ("break statement not within loop or switch"); }
1969 emit_line_note ($<filename>-1, $<lineno>0);
1970 if (! expand_continue_loop (NULL_PTR))
1971 error ("continue statement not within a loop"); }
1974 emit_line_note ($<filename>-1, $<lineno>0);
1975 c_expand_return (NULL_TREE); }
1978 emit_line_note ($<filename>-1, $<lineno>0);
1979 c_expand_return ($2); }
1980 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1982 emit_line_note ($<filename>-1, $<lineno>0);
1984 if ((TREE_CODE ($4) == ADDR_EXPR
1985 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1986 || TREE_CODE ($4) == STRING_CST)
1989 error ("argument of `asm' is not a constant string"); }
1990 /* This is the case with just output operands. */
1991 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1993 emit_line_note ($<filename>-1, $<lineno>0);
1994 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1995 $2 == ridpointers[(int)RID_VOLATILE],
1996 input_filename, lineno); }
1997 /* This is the case with input operands as well. */
1998 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2000 emit_line_note ($<filename>-1, $<lineno>0);
2001 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2002 $2 == ridpointers[(int)RID_VOLATILE],
2003 input_filename, lineno); }
2004 /* This is the case with clobbered registers as well. */
2005 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2006 asm_operands ':' asm_clobbers ')' ';'
2008 emit_line_note ($<filename>-1, $<lineno>0);
2009 c_expand_asm_operands ($4, $6, $8, $10,
2010 $2 == ridpointers[(int)RID_VOLATILE],
2011 input_filename, lineno); }
2012 | GOTO identifier ';'
2015 emit_line_note ($<filename>-1, $<lineno>0);
2016 decl = lookup_label ($2);
2019 TREE_USED (decl) = 1;
2025 pedwarn ("ANSI C forbids `goto *expr;'");
2027 emit_line_note ($<filename>-1, $<lineno>0);
2028 expand_computed_goto (convert (ptr_type_node, $3)); }
2033 all_iter_stmt_simple
2034 /* | all_iter_stmt_with_decl */
2037 all_iter_stmt_simple:
2040 /* The value returned by this action is */
2041 /* 1 if everything is OK */
2042 /* 0 in case of error or already bound iterator */
2045 if (TREE_CODE ($3) != VAR_DECL)
2046 error ("invalid `for (ITERATOR)' syntax");
2047 else if (! ITERATOR_P ($3))
2048 error ("`%s' is not an iterator",
2049 IDENTIFIER_POINTER (DECL_NAME ($3)));
2050 else if (ITERATOR_BOUND_P ($3))
2051 error ("`for (%s)' inside expansion of same iterator",
2052 IDENTIFIER_POINTER (DECL_NAME ($3)));
2056 iterator_for_loop_start ($3);
2062 iterator_for_loop_end ($3);
2065 /* This really should allow any kind of declaration,
2066 for generality. Fix it before turning it back on.
2068 all_iter_stmt_with_decl:
2069 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2071 */ /* The value returned by this action is */
2072 /* 1 if everything is OK */
2073 /* 0 in case of error or already bound iterator */
2075 iterator_for_loop_start ($6);
2079 iterator_for_loop_end ($6);
2080 emit_line_note (input_filename, lineno);
2081 expand_end_bindings (getdecls (), 1, 0);
2082 $<ttype>$ = poplevel (1, 1, 0);
2083 if (yychar == CONSTANT || yychar == STRING)
2084 pop_momentary_nofree ();
2090 /* Any kind of label, including jump labels and case labels.
2091 ANSI C accepts labels only before statements, but we allow them
2092 also at the end of a compound statement. */
2094 label: CASE expr_no_commas ':'
2095 { register tree value = check_case_value ($2);
2097 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2101 if (value != error_mark_node)
2106 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2107 pedwarn ("label must have integral type in ANSI C");
2109 success = pushcase (value, convert_and_check,
2113 error ("case label not within a switch statement");
2114 else if (success == 2)
2116 error ("duplicate case value");
2117 error_with_decl (duplicate, "this is the first entry for that value");
2119 else if (success == 3)
2120 warning ("case value out of range");
2121 else if (success == 5)
2122 error ("case label within scope of cleanup or variable array");
2124 position_after_white_space (); }
2125 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2126 { register tree value1 = check_case_value ($2);
2127 register tree value2 = check_case_value ($4);
2129 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2132 pedwarn ("ANSI C forbids case ranges");
2135 if (value1 != error_mark_node && value2 != error_mark_node)
2138 int success = pushcase_range (value1, value2,
2139 convert_and_check, label,
2142 error ("case label not within a switch statement");
2143 else if (success == 2)
2145 error ("duplicate case value");
2146 error_with_decl (duplicate, "this is the first entry for that value");
2148 else if (success == 3)
2149 warning ("case value out of range");
2150 else if (success == 4)
2151 warning ("empty case range");
2152 else if (success == 5)
2153 error ("case label within scope of cleanup or variable array");
2155 position_after_white_space (); }
2160 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2161 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2164 error ("default label not within a switch statement");
2165 else if (success == 2)
2167 error ("multiple default labels in one switch");
2168 error_with_decl (duplicate, "this is the first default label");
2170 position_after_white_space (); }
2172 { tree label = define_label (input_filename, lineno, $1);
2176 expand_label (label);
2177 position_after_white_space (); }
2180 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2184 { emit_line_note (input_filename, lineno);
2187 { emit_line_note (input_filename, lineno); }
2196 /* These are the operands other than the first string and colon
2197 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2198 asm_operands: /* empty */
2200 | nonnull_asm_operands
2203 nonnull_asm_operands:
2205 | nonnull_asm_operands ',' asm_operand
2206 { $$ = chainon ($1, $3); }
2211 { $$ = build_tree_list ($1, $3); }
2216 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2217 | asm_clobbers ',' string
2218 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2221 /* This is what appears inside the parens in a function declarator.
2222 Its value is a list of ..._TYPE nodes. */
2225 clear_parm_order ();
2226 declare_parm_level (0); }
2229 parmlist_tags_warning ();
2230 poplevel (0, 0, 0); }
2238 pedwarn ("ANSI C forbids forward parameter declarations");
2239 /* Mark the forward decls as such. */
2240 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2241 TREE_ASM_WRITTEN (parm) = 1;
2242 clear_parm_order (); }
2246 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2249 /* This is what appears inside the parens in a function declarator.
2250 Is value is represented in the format that grokdeclarator expects. */
2251 parmlist_2: /* empty */
2252 { $$ = get_parm_info (0); }
2254 { $$ = get_parm_info (0);
2255 /* Gcc used to allow this as an extension. However, it does
2256 not work for all targets, and thus has been disabled.
2257 Also, since func (...) and func () are indistinguishable,
2258 it caused problems with the code in expand_builtin which
2259 tries to verify that BUILT_IN_NEXT_ARG is being used
2261 error ("ANSI C requires a named argument before `...'");
2264 { $$ = get_parm_info (1); }
2265 | parms ',' ELLIPSIS
2266 { $$ = get_parm_info (0); }
2271 { push_parm_decl ($1); }
2273 { push_parm_decl ($3); }
2276 /* A single parameter declaration or parameter type name,
2277 as found in a parmlist. */
2279 typed_declspecs setspecs parm_declarator maybe_attribute
2280 { $$ = build_tree_list (build_tree_list (current_declspecs,
2282 build_tree_list (prefix_attributes,
2284 current_declspecs = TREE_VALUE (declspec_stack);
2285 prefix_attributes = TREE_PURPOSE (declspec_stack);
2286 declspec_stack = TREE_CHAIN (declspec_stack);
2287 resume_momentary ($2); }
2288 | typed_declspecs setspecs notype_declarator maybe_attribute
2289 { $$ = build_tree_list (build_tree_list (current_declspecs,
2291 build_tree_list (prefix_attributes,
2293 current_declspecs = TREE_VALUE (declspec_stack);
2294 prefix_attributes = TREE_PURPOSE (declspec_stack);
2295 declspec_stack = TREE_CHAIN (declspec_stack);
2296 resume_momentary ($2); }
2297 | typed_declspecs setspecs absdcl maybe_attribute
2298 { $$ = build_tree_list (build_tree_list (current_declspecs,
2300 build_tree_list (prefix_attributes,
2302 current_declspecs = TREE_VALUE (declspec_stack);
2303 prefix_attributes = TREE_PURPOSE (declspec_stack);
2304 declspec_stack = TREE_CHAIN (declspec_stack);
2305 resume_momentary ($2); }
2306 | declmods setspecs notype_declarator maybe_attribute
2307 { $$ = build_tree_list (build_tree_list (current_declspecs,
2309 build_tree_list (prefix_attributes,
2311 current_declspecs = TREE_VALUE (declspec_stack);
2312 prefix_attributes = TREE_PURPOSE (declspec_stack);
2313 declspec_stack = TREE_CHAIN (declspec_stack);
2314 resume_momentary ($2); }
2316 | declmods setspecs absdcl maybe_attribute
2317 { $$ = build_tree_list (build_tree_list (current_declspecs,
2319 build_tree_list (prefix_attributes,
2321 current_declspecs = TREE_VALUE (declspec_stack);
2322 prefix_attributes = TREE_PURPOSE (declspec_stack);
2323 declspec_stack = TREE_CHAIN (declspec_stack);
2324 resume_momentary ($2); }
2327 /* This is used in a function definition
2328 where either a parmlist or an identifier list is ok.
2329 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2330 parmlist_or_identifiers:
2332 clear_parm_order ();
2333 declare_parm_level (1); }
2334 parmlist_or_identifiers_1
2336 parmlist_tags_warning ();
2337 poplevel (0, 0, 0); }
2340 parmlist_or_identifiers_1:
2344 for (t = $1; t; t = TREE_CHAIN (t))
2345 if (TREE_VALUE (t) == NULL_TREE)
2346 error ("`...' in old-style identifier list");
2347 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2350 /* A nonempty list of identifiers. */
2353 { $$ = build_tree_list (NULL_TREE, $1); }
2354 | identifiers ',' IDENTIFIER
2355 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2358 /* A nonempty list of identifiers, including typenames. */
2359 identifiers_or_typenames:
2361 { $$ = build_tree_list (NULL_TREE, $1); }
2362 | identifiers_or_typenames ',' identifier
2363 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2368 { $<itype>$ = pedantic;
2373 /* Objective-C productions. */
2383 if (objc_implementation_context)
2385 finish_class (objc_implementation_context);
2386 objc_ivar_chain = NULL_TREE;
2387 objc_implementation_context = NULL_TREE;
2390 warning ("`@end' must appear in an implementation context");
2394 /* A nonempty list of identifiers. */
2397 { $$ = build_tree_list (NULL_TREE, $1); }
2398 | identifier_list ',' identifier
2399 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2403 CLASS identifier_list ';'
2405 objc_declare_class ($2);
2409 ALIAS identifier identifier ';'
2411 objc_declare_alias ($2, $3);
2415 INTERFACE identifier protocolrefs '{'
2417 objc_interface_context = objc_ivar_context
2418 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2419 objc_public_flag = 0;
2423 continue_class (objc_interface_context);
2428 finish_class (objc_interface_context);
2429 objc_interface_context = NULL_TREE;
2432 | INTERFACE identifier protocolrefs
2434 objc_interface_context
2435 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2436 continue_class (objc_interface_context);
2441 finish_class (objc_interface_context);
2442 objc_interface_context = NULL_TREE;
2445 | INTERFACE identifier ':' identifier protocolrefs '{'
2447 objc_interface_context = objc_ivar_context
2448 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2449 objc_public_flag = 0;
2453 continue_class (objc_interface_context);
2458 finish_class (objc_interface_context);
2459 objc_interface_context = NULL_TREE;
2462 | INTERFACE identifier ':' identifier protocolrefs
2464 objc_interface_context
2465 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2466 continue_class (objc_interface_context);
2471 finish_class (objc_interface_context);
2472 objc_interface_context = NULL_TREE;
2475 | IMPLEMENTATION identifier '{'
2477 objc_implementation_context = objc_ivar_context
2478 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2479 objc_public_flag = 0;
2484 = continue_class (objc_implementation_context);
2487 | IMPLEMENTATION identifier
2489 objc_implementation_context
2490 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2492 = continue_class (objc_implementation_context);
2495 | IMPLEMENTATION identifier ':' identifier '{'
2497 objc_implementation_context = objc_ivar_context
2498 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2499 objc_public_flag = 0;
2504 = continue_class (objc_implementation_context);
2507 | IMPLEMENTATION identifier ':' identifier
2509 objc_implementation_context
2510 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2512 = continue_class (objc_implementation_context);
2515 | INTERFACE identifier '(' identifier ')' protocolrefs
2517 objc_interface_context
2518 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2519 continue_class (objc_interface_context);
2524 finish_class (objc_interface_context);
2525 objc_interface_context = NULL_TREE;
2528 | IMPLEMENTATION identifier '(' identifier ')'
2530 objc_implementation_context
2531 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2533 = continue_class (objc_implementation_context);
2538 PROTOCOL identifier protocolrefs
2540 remember_protocol_qualifiers ();
2541 objc_interface_context
2542 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2546 forget_protocol_qualifiers();
2547 finish_protocol(objc_interface_context);
2548 objc_interface_context = NULL_TREE;
2557 | non_empty_protocolrefs
2560 non_empty_protocolrefs:
2561 ARITHCOMPARE identifier_list ARITHCOMPARE
2563 if ($1 == LT_EXPR && $3 == GT_EXPR)
2571 ivar_decl_list visibility_spec ivar_decls
2576 PRIVATE { objc_public_flag = 2; }
2577 | PROTECTED { objc_public_flag = 0; }
2578 | PUBLIC { objc_public_flag = 1; }
2586 | ivar_decls ivar_decl ';'
2590 pedwarn ("extra semicolon in struct or union specified");
2595 /* There is a shift-reduce conflict here, because `components' may
2596 start with a `typename'. It happens that shifting (the default resolution)
2597 does the right thing, because it treats the `typename' as part of
2598 a `typed_typespecs'.
2600 It is possible that this same technique would allow the distinction
2601 between `notype_initdecls' and `initdecls' to be eliminated.
2602 But I am being cautious and not trying it. */
2605 typed_typespecs setspecs ivars
2607 current_declspecs = TREE_VALUE (declspec_stack);
2608 prefix_attributes = TREE_PURPOSE (declspec_stack);
2609 declspec_stack = TREE_CHAIN (declspec_stack);
2610 resume_momentary ($2); }
2611 | nonempty_type_quals setspecs ivars
2613 current_declspecs = TREE_VALUE (declspec_stack);
2614 prefix_attributes = TREE_PURPOSE (declspec_stack);
2615 declspec_stack = TREE_CHAIN (declspec_stack);
2616 resume_momentary ($2); }
2625 | ivars ',' ivar_declarator
2631 $$ = add_instance_variable (objc_ivar_context,
2633 $1, current_declspecs,
2636 | declarator ':' expr_no_commas
2638 $$ = add_instance_variable (objc_ivar_context,
2640 $1, current_declspecs, $3);
2642 | ':' expr_no_commas
2644 $$ = add_instance_variable (objc_ivar_context,
2647 current_declspecs, $2);
2654 remember_protocol_qualifiers ();
2655 if (objc_implementation_context)
2656 objc_inherit_code = CLASS_METHOD_DECL;
2658 fatal ("method definition not in class context");
2662 forget_protocol_qualifiers ();
2663 add_class_method (objc_implementation_context, $3);
2664 start_method_def ($3);
2665 objc_method_context = $3;
2669 continue_method_def ();
2673 finish_method_def ();
2674 objc_method_context = NULL_TREE;
2679 remember_protocol_qualifiers ();
2680 if (objc_implementation_context)
2681 objc_inherit_code = INSTANCE_METHOD_DECL;
2683 fatal ("method definition not in class context");
2687 forget_protocol_qualifiers ();
2688 add_instance_method (objc_implementation_context, $3);
2689 start_method_def ($3);
2690 objc_method_context = $3;
2694 continue_method_def ();
2698 finish_method_def ();
2699 objc_method_context = NULL_TREE;
2703 /* the reason for the strange actions in this rule
2704 is so that notype_initdecls when reached via datadef
2705 can find a valid list of type and sc specs in $0. */
2709 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2712 methodprotolist2: /* eliminates a shift/reduce conflict */
2715 | methodprotolist2 methodproto
2716 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2727 /* Remember protocol qualifiers in prototypes. */
2728 remember_protocol_qualifiers ();
2729 objc_inherit_code = CLASS_METHOD_DECL;
2733 /* Forget protocol qualifiers here. */
2734 forget_protocol_qualifiers ();
2735 add_class_method (objc_interface_context, $3);
2741 /* Remember protocol qualifiers in prototypes. */
2742 remember_protocol_qualifiers ();
2743 objc_inherit_code = INSTANCE_METHOD_DECL;
2747 /* Forget protocol qualifiers here. */
2748 forget_protocol_qualifiers ();
2749 add_instance_method (objc_interface_context, $3);
2755 '(' typename ')' unaryselector
2757 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2762 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2765 | '(' typename ')' keywordselector optparmlist
2767 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2770 | keywordselector optparmlist
2772 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2776 /* "optarglist" assumes that start_method_def has already been called...
2777 if it is not, the "xdecls" will not be placed in the proper scope */
2784 /* to get around the following situation: "int foo (int a) int b; {}" that
2785 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2800 typed_declspecs setspecs myparms ';'
2801 { current_declspecs = TREE_VALUE (declspec_stack);
2802 prefix_attributes = TREE_PURPOSE (declspec_stack);
2803 declspec_stack = TREE_CHAIN (declspec_stack);
2804 resume_momentary ($2); }
2805 | typed_declspecs ';'
2806 { shadow_tag ($1); }
2808 { pedwarn ("empty declaration"); }
2813 { push_parm_decl ($1); }
2814 | myparms ',' myparm
2815 { push_parm_decl ($3); }
2818 /* A single parameter declaration or parameter type name,
2819 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2822 parm_declarator maybe_attribute
2823 { $$ = build_tree_list (build_tree_list (current_declspecs,
2825 build_tree_list (prefix_attributes,
2827 | notype_declarator maybe_attribute
2828 { $$ = build_tree_list (build_tree_list (current_declspecs,
2830 build_tree_list (prefix_attributes,
2832 | absdcl maybe_attribute
2833 { $$ = build_tree_list (build_tree_list (current_declspecs,
2835 build_tree_list (prefix_attributes,
2846 /* oh what a kludge! */
2855 /* returns a tree list node generated by get_parm_info */
2868 | keywordselector keyworddecl
2870 $$ = chainon ($1, $2);
2882 ENUM { $$ = get_identifier (token_buffer); }
2883 | STRUCT { $$ = get_identifier (token_buffer); }
2884 | UNION { $$ = get_identifier (token_buffer); }
2885 | IF { $$ = get_identifier (token_buffer); }
2886 | ELSE { $$ = get_identifier (token_buffer); }
2887 | WHILE { $$ = get_identifier (token_buffer); }
2888 | DO { $$ = get_identifier (token_buffer); }
2889 | FOR { $$ = get_identifier (token_buffer); }
2890 | SWITCH { $$ = get_identifier (token_buffer); }
2891 | CASE { $$ = get_identifier (token_buffer); }
2892 | DEFAULT { $$ = get_identifier (token_buffer); }
2893 | BREAK { $$ = get_identifier (token_buffer); }
2894 | CONTINUE { $$ = get_identifier (token_buffer); }
2895 | RETURN { $$ = get_identifier (token_buffer); }
2896 | GOTO { $$ = get_identifier (token_buffer); }
2897 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2898 | SIZEOF { $$ = get_identifier (token_buffer); }
2899 | TYPEOF { $$ = get_identifier (token_buffer); }
2900 | ALIGNOF { $$ = get_identifier (token_buffer); }
2901 | TYPESPEC | TYPE_QUAL
2905 selector ':' '(' typename ')' identifier
2907 $$ = build_keyword_decl ($1, $4, $6);
2910 | selector ':' identifier
2912 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2915 | ':' '(' typename ')' identifier
2917 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2922 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2933 | keywordarglist keywordarg
2935 $$ = chainon ($1, $2);
2943 if (TREE_CHAIN ($1) == NULL_TREE)
2944 /* just return the expr., remove a level of indirection */
2945 $$ = TREE_VALUE ($1);
2947 /* we have a comma expr., we will collapse later */
2953 selector ':' keywordexpr
2955 $$ = build_tree_list ($1, $3);
2959 $$ = build_tree_list (NULL_TREE, $2);
2967 $$ = get_class_reference ($1);
2973 { objc_receiver_context = 1; }
2975 { objc_receiver_context = 0; }
2978 $$ = build_tree_list ($3, $5);
2989 | keywordnamelist keywordname
2991 $$ = chainon ($1, $2);
2998 $$ = build_tree_list ($1, NULL_TREE);
3002 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3007 SELECTOR '(' selectorarg ')'
3014 PROTOCOL '(' identifier ')'
3020 /* extension to support C-structures in the archiver */
3023 ENCODE '(' typename ')'
3025 $$ = groktypename ($3);