1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 88, 89, 92-98, 1999 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. */
50 #ifdef MULTIBYTE_CHARS
58 /* Since parsers are distinct for each language, put the language string
61 const char * const language_string = "GNU Obj-C";
64 const char * const language_string = "GNU C";
67 /* Like YYERROR but do call yyerror. */
68 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
70 /* Cause the `yydebug' variable to be defined. */
76 %union {long itype; tree ttype; enum tree_code code;
77 char *filename; int lineno; int ends_in_label; }
79 /* All identifiers that are not reserved words
80 and are not declared typedefs in the current block */
83 /* All identifiers that are declared typedefs in the current block.
84 In some contexts, they are treated just like IDENTIFIER,
85 but they can also serve as typespecs in declarations. */
88 /* Reserved words that specify storage class.
89 yylval contains an IDENTIFIER_NODE which indicates which one. */
92 /* Reserved words that specify type.
93 yylval contains an IDENTIFIER_NODE which indicates which one. */
96 /* Reserved words that qualify type: "const", "volatile", or "restrict".
97 yylval contains an IDENTIFIER_NODE which indicates which one. */
100 /* Character or numeric constants.
101 yylval is the node for the constant. */
104 /* String constants in raw form.
105 yylval is a STRING_CST node. */
108 /* "...", used for functions with variable arglists. */
111 /* the reserved words */
112 /* SCO include files test "ASM", so use something else. */
113 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
114 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
115 %token ATTRIBUTE EXTENSION LABEL
116 %token REALPART IMAGPART VA_ARG
118 /* Used in c-lex.c for parsing pragmas. */
121 /* Add precedence rules to solve dangling else s/r conflict */
125 /* Define the operator tokens and their precedences.
126 The value is an integer because, if used, it is the tree code
127 to use in the expression made from the operator. */
129 %right <code> ASSIGN '='
130 %right <code> '?' ':'
136 %left <code> EQCOMPARE
137 %left <code> ARITHCOMPARE
138 %left <code> LSHIFT RSHIFT
140 %left <code> '*' '/' '%'
141 %right <code> UNARY PLUSPLUS MINUSMINUS
143 %left <code> POINTSAT '.' '(' '['
145 /* The Objective-C keywords. These are included in C and in
146 Objective C, so that the token codes are the same in both. */
147 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
148 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
150 /* Objective-C string constants in raw form.
151 yylval is an OBJC_STRING_CST node. */
157 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
158 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
159 %type <ttype> typed_declspecs reserved_declspecs
160 %type <ttype> typed_typespecs reserved_typespecquals
161 %type <ttype> declmods typespec typespecqual_reserved
162 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
163 %type <ttype> declmods_no_prefix_attr
164 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
165 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
166 %type <ttype> init maybeasm
167 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
168 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
169 %type <ttype> any_word
171 %type <ttype> compstmt compstmt_nostart compstmt_primary_start
173 %type <ttype> declarator
174 %type <ttype> notype_declarator after_type_declarator
175 %type <ttype> parm_declarator
177 %type <ttype> structsp component_decl_list component_decl_list2
178 %type <ttype> component_decl components component_declarator
179 %type <ttype> enumlist enumerator
180 %type <ttype> struct_head union_head enum_head
181 %type <ttype> typename absdcl absdcl1 type_quals
182 %type <ttype> xexpr parms parm identifiers
184 %type <ttype> parmlist parmlist_1 parmlist_2
185 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
186 %type <ttype> identifiers_or_typenames
188 %type <itype> setspecs
190 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
192 %type <filename> save_filename
193 %type <lineno> save_lineno
196 /* the Objective-C nonterminals */
198 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
199 %type <ttype> methoddecl unaryselector keywordselector selector
200 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
201 %type <ttype> keywordexpr keywordarglist keywordarg
202 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
203 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
204 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
206 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
210 /* Number of statements (loosely speaking) and compound statements
212 static int stmt_count;
213 static int compstmt_count;
215 /* Input file and line number of the end of the body of last simple_if;
216 used by the stmt-rule immediately after simple_if returns. */
217 static char *if_stmt_file;
218 static int if_stmt_line;
220 /* List of types and structure classes of the current declaration. */
221 static tree current_declspecs = NULL_TREE;
222 static tree prefix_attributes = NULL_TREE;
224 /* Stack of saved values of current_declspecs and prefix_attributes. */
225 static tree declspec_stack;
227 /* 1 if we explained undeclared var errors. */
228 static int undeclared_variable_notice;
231 /* Objective-C specific information */
233 tree objc_interface_context;
234 tree objc_implementation_context;
235 tree objc_method_context;
236 tree objc_ivar_chain;
237 tree objc_ivar_context;
238 enum tree_code objc_inherit_code;
239 int objc_receiver_context;
240 int objc_public_flag;
244 /* Tell yyparse how to print a token's value, if yydebug is set. */
246 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
247 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
253 pedwarn ("ANSI C forbids an empty source file");
258 /* In case there were missing closebraces,
259 get us back to the global binding level. */
260 while (! global_bindings_p ())
266 /* the reason for the strange actions in this rule
267 is so that notype_initdecls when reached via datadef
268 can find a valid list of type and sc specs in $0. */
271 {$<ttype>$ = NULL_TREE; } extdef
272 | extdefs {$<ttype>$ = NULL_TREE; } extdef
281 | ASM_KEYWORD '(' expr ')' ';'
283 if ((TREE_CODE ($3) == ADDR_EXPR
284 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
285 || TREE_CODE ($3) == STRING_CST)
288 error ("argument of `asm' is not a constant string"); }
290 { pedantic = $<itype>1; }
294 setspecs notype_initdecls ';'
296 error ("ANSI C forbids data definition with no type or storage class");
297 else if (!flag_traditional)
298 warning ("data definition has no type or storage class");
300 current_declspecs = TREE_VALUE (declspec_stack);
301 prefix_attributes = TREE_PURPOSE (declspec_stack);
302 declspec_stack = TREE_CHAIN (declspec_stack);
303 resume_momentary ($1); }
304 | declmods setspecs notype_initdecls ';'
305 { current_declspecs = TREE_VALUE (declspec_stack);
306 prefix_attributes = TREE_PURPOSE (declspec_stack);
307 declspec_stack = TREE_CHAIN (declspec_stack);
308 resume_momentary ($2); }
309 | typed_declspecs setspecs initdecls ';'
310 { current_declspecs = TREE_VALUE (declspec_stack);
311 prefix_attributes = TREE_PURPOSE (declspec_stack);
312 declspec_stack = TREE_CHAIN (declspec_stack);
313 resume_momentary ($2); }
315 { pedwarn ("empty declaration"); }
316 | typed_declspecs ';'
322 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
326 typed_declspecs setspecs declarator
327 { if (! start_function (current_declspecs, $3,
328 prefix_attributes, NULL_TREE, 0))
330 reinit_parse_for_function (); }
332 { store_parm_decls (); }
334 { finish_function (0);
335 current_declspecs = TREE_VALUE (declspec_stack);
336 prefix_attributes = TREE_PURPOSE (declspec_stack);
337 declspec_stack = TREE_CHAIN (declspec_stack);
338 resume_momentary ($2); }
339 | typed_declspecs setspecs declarator error
340 { current_declspecs = TREE_VALUE (declspec_stack);
341 prefix_attributes = TREE_PURPOSE (declspec_stack);
342 declspec_stack = TREE_CHAIN (declspec_stack);
343 resume_momentary ($2); }
344 | declmods setspecs notype_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 | declmods setspecs notype_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 | setspecs notype_declarator
363 { if (! start_function (NULL_TREE, $2,
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 ($1); }
375 | 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 ($1); }
394 { $$ = NEGATE_EXPR; }
396 { $$ = CONVERT_EXPR; }
398 { $$ = PREINCREMENT_EXPR; }
400 { $$ = PREDECREMENT_EXPR; }
402 { $$ = BIT_NOT_EXPR; }
404 { $$ = TRUTH_NOT_EXPR; }
407 expr: nonnull_exprlist
408 { $$ = build_compound_expr ($1); }
419 { $$ = build_tree_list (NULL_TREE, $1); }
420 | nonnull_exprlist ',' expr_no_commas
421 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
426 | '*' cast_expr %prec UNARY
427 { $$ = build_indirect_ref ($2, "unary *"); }
428 /* __extension__ turns off -pedantic for following primary. */
429 | extension cast_expr %prec UNARY
431 pedantic = $<itype>1; }
432 | unop cast_expr %prec UNARY
433 { $$ = build_unary_op ($1, $2, 0);
434 overflow_warning ($$); }
435 /* Refer to the address of a label as a pointer. */
437 { tree label = lookup_label ($2);
439 pedwarn ("ANSI C forbids `&&'");
441 $$ = null_pointer_node;
444 TREE_USED (label) = 1;
445 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
446 TREE_CONSTANT ($$) = 1;
449 /* This seems to be impossible on some machines, so let's turn it off.
450 You can use __builtin_next_arg to find the anonymous stack args.
452 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
453 $$ = error_mark_node;
454 if (TREE_VALUE (tree_last (types)) == void_type_node)
455 error ("`&...' used in function with fixed number of arguments");
459 pedwarn ("ANSI C forbids `&...'");
460 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
461 $$ = build_unary_op (ADDR_EXPR, $$, 0);
464 | sizeof unary_expr %prec UNARY
466 if (TREE_CODE ($2) == COMPONENT_REF
467 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
468 error ("`sizeof' applied to a bit-field");
469 $$ = c_sizeof (TREE_TYPE ($2)); }
470 | sizeof '(' typename ')' %prec HYPERUNARY
472 $$ = c_sizeof (groktypename ($3)); }
473 | alignof unary_expr %prec UNARY
475 $$ = c_alignof_expr ($2); }
476 | alignof '(' typename ')' %prec HYPERUNARY
478 $$ = c_alignof (groktypename ($3)); }
479 | REALPART cast_expr %prec UNARY
480 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
481 | IMAGPART cast_expr %prec UNARY
482 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
483 | VA_ARG '(' expr_no_commas ',' typename ')'
484 { $$ = build_va_arg ($3, groktypename ($5)); }
488 SIZEOF { skip_evaluation++; }
492 ALIGNOF { skip_evaluation++; }
497 | '(' typename ')' cast_expr %prec UNARY
498 { tree type = groktypename ($2);
499 $$ = build_c_cast (type, $4); }
500 | '(' typename ')' '{'
501 { start_init (NULL_TREE, NULL, 0);
502 $2 = groktypename ($2);
503 really_start_incremental_init ($2); }
504 initlist_maybe_comma '}' %prec UNARY
506 tree result = pop_init_level (0);
510 if (pedantic && ! flag_isoc9x)
511 pedwarn ("ANSI C forbids constructor expressions");
512 if (TYPE_NAME (type) != 0)
514 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
515 name = IDENTIFIER_POINTER (TYPE_NAME (type));
517 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
522 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
524 int failure = complete_array_type (type, $$, 1);
533 | expr_no_commas '+' expr_no_commas
534 { $$ = parser_build_binary_op ($2, $1, $3); }
535 | expr_no_commas '-' expr_no_commas
536 { $$ = parser_build_binary_op ($2, $1, $3); }
537 | expr_no_commas '*' expr_no_commas
538 { $$ = parser_build_binary_op ($2, $1, $3); }
539 | expr_no_commas '/' expr_no_commas
540 { $$ = parser_build_binary_op ($2, $1, $3); }
541 | expr_no_commas '%' expr_no_commas
542 { $$ = parser_build_binary_op ($2, $1, $3); }
543 | expr_no_commas LSHIFT expr_no_commas
544 { $$ = parser_build_binary_op ($2, $1, $3); }
545 | expr_no_commas RSHIFT expr_no_commas
546 { $$ = parser_build_binary_op ($2, $1, $3); }
547 | expr_no_commas ARITHCOMPARE expr_no_commas
548 { $$ = parser_build_binary_op ($2, $1, $3); }
549 | expr_no_commas EQCOMPARE 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 ANDAND
558 { $1 = truthvalue_conversion (default_conversion ($1));
559 skip_evaluation += $1 == boolean_false_node; }
561 { skip_evaluation -= $1 == boolean_false_node;
562 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
563 | expr_no_commas OROR
564 { $1 = truthvalue_conversion (default_conversion ($1));
565 skip_evaluation += $1 == boolean_true_node; }
567 { skip_evaluation -= $1 == boolean_true_node;
568 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
570 { $1 = truthvalue_conversion (default_conversion ($1));
571 skip_evaluation += $1 == boolean_false_node; }
573 { skip_evaluation += (($1 == boolean_true_node)
574 - ($1 == boolean_false_node)); }
576 { skip_evaluation -= $1 == boolean_true_node;
577 $$ = build_conditional_expr ($1, $4, $7); }
580 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
581 /* Make sure first operand is calculated only once. */
582 $<ttype>2 = save_expr ($1);
583 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
584 skip_evaluation += $1 == boolean_true_node; }
586 { skip_evaluation -= $1 == boolean_true_node;
587 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
588 | expr_no_commas '=' expr_no_commas
590 $$ = build_modify_expr ($1, NOP_EXPR, $3);
591 class = TREE_CODE_CLASS (TREE_CODE ($$));
592 if (class == 'e' || class == '1'
593 || class == '2' || class == '<')
594 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
596 | expr_no_commas ASSIGN expr_no_commas
598 $$ = build_modify_expr ($1, $2, $3);
599 /* This inhibits warnings in truthvalue_conversion. */
600 class = TREE_CODE_CLASS (TREE_CODE ($$));
601 if (class == 'e' || class == '1'
602 || class == '2' || class == '<')
603 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
611 if (!$$ || $$ == error_mark_node)
613 if (yychar == YYEMPTY)
620 if (objc_receiver_context
621 && ! (objc_receiver_context
622 && strcmp (IDENTIFIER_POINTER ($1), "super")))
623 /* we have a message to super */
624 $$ = get_super_receiver ();
625 else if (objc_method_context
626 && (decl = is_ivar (objc_ivar_chain, $1)))
628 if (is_private (decl))
629 $$ = error_mark_node;
631 $$ = build_ivar_reference ($1);
636 /* Ordinary implicit function declaration. */
637 $$ = implicitly_declare ($1);
638 assemble_external ($$);
642 else if (current_function_decl == 0)
644 error ("`%s' undeclared here (not in a function)",
645 IDENTIFIER_POINTER ($1));
646 $$ = error_mark_node;
653 if (objc_receiver_context
654 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
655 /* we have a message to super */
656 $$ = get_super_receiver ();
657 else if (objc_method_context
658 && (decl = is_ivar (objc_ivar_chain, $1)))
660 if (is_private (decl))
661 $$ = error_mark_node;
663 $$ = build_ivar_reference ($1);
668 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
669 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
671 error ("`%s' undeclared (first use in this function)",
672 IDENTIFIER_POINTER ($1));
674 if (! undeclared_variable_notice)
676 error ("(Each undeclared identifier is reported only once");
677 error ("for each function it appears in.)");
678 undeclared_variable_notice = 1;
681 $$ = error_mark_node;
682 /* Prevent repeated error messages. */
683 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
684 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
688 else if (TREE_TYPE ($$) == error_mark_node)
689 $$ = error_mark_node;
690 else if (C_DECL_ANTICIPATED ($$))
692 /* The first time we see a build-in function used,
693 if it has not been declared. */
694 C_DECL_ANTICIPATED ($$) = 0;
695 if (yychar == YYEMPTY)
699 /* Omit the implicit declaration we
700 would ordinarily do, so we don't lose
701 the actual built in type.
702 But print a diagnostic for the mismatch. */
704 if (objc_method_context
705 && is_ivar (objc_ivar_chain, $1))
706 error ("Instance variable `%s' implicitly declared as function",
707 IDENTIFIER_POINTER (DECL_NAME ($$)));
710 if (TREE_CODE ($$) != FUNCTION_DECL)
711 error ("`%s' implicitly declared as function",
712 IDENTIFIER_POINTER (DECL_NAME ($$)));
713 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
714 != TYPE_MODE (integer_type_node))
715 && (TREE_TYPE (TREE_TYPE ($$))
717 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
718 IDENTIFIER_POINTER (DECL_NAME ($$)));
719 /* If it really returns void, change that to int. */
720 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
722 = build_function_type (integer_type_node,
723 TYPE_ARG_TYPES (TREE_TYPE ($$)));
726 pedwarn ("built-in function `%s' used without declaration",
727 IDENTIFIER_POINTER (DECL_NAME ($$)));
729 /* Do what we would ordinarily do when a fn is used. */
730 assemble_external ($$);
735 assemble_external ($$);
738 /* we have a definition - still check if iVariable */
740 if (!objc_receiver_context
741 || (objc_receiver_context
742 && strcmp (IDENTIFIER_POINTER ($1), "super")))
746 if (objc_method_context
747 && (decl = is_ivar (objc_ivar_chain, $1)))
749 if (IDENTIFIER_LOCAL_VALUE ($1))
750 warning ("local declaration of `%s' hides instance variable",
751 IDENTIFIER_POINTER ($1));
754 if (is_private (decl))
755 $$ = error_mark_node;
757 $$ = build_ivar_reference ($1);
761 else /* we have a message to super */
762 $$ = get_super_receiver ();
766 if (TREE_CODE ($$) == CONST_DECL)
768 $$ = DECL_INITIAL ($$);
769 /* This is to prevent an enum whose value is 0
770 from being considered a null pointer constant. */
771 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
772 TREE_CONSTANT ($$) = 1;
777 { $$ = combine_strings ($1); }
779 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
780 if (class == 'e' || class == '1'
781 || class == '2' || class == '<')
782 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
785 { $$ = error_mark_node; }
786 | compstmt_primary_start compstmt_nostart ')'
789 pedwarn ("ANSI C forbids braced-groups within expressions");
790 pop_iterator_stack ();
792 rtl_exp = expand_end_stmt_expr ($1);
793 /* The statements have side effects, so the group does. */
794 TREE_SIDE_EFFECTS (rtl_exp) = 1;
796 if (TREE_CODE ($2) == BLOCK)
798 /* Make a BIND_EXPR for the BLOCK already made. */
799 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
800 NULL_TREE, rtl_exp, $2);
801 /* Remove the block from the tree at this point.
802 It gets put back at the proper place
803 when the BIND_EXPR is expanded. */
809 | compstmt_primary_start error ')'
811 /* Make sure we call expand_end_stmt_expr. Otherwise
812 we are likely to lose sequences and crash later. */
813 pop_iterator_stack ();
815 expand_end_stmt_expr ($1);
816 $$ = error_mark_node;
818 | primary '(' exprlist ')' %prec '.'
819 { $$ = build_function_call ($1, $3); }
820 | primary '[' expr ']' %prec '.'
821 { $$ = build_array_ref ($1, $3); }
822 | primary '.' identifier
825 if (doing_objc_thang)
827 if (is_public ($1, $3))
828 $$ = build_component_ref ($1, $3);
830 $$ = error_mark_node;
834 $$ = build_component_ref ($1, $3);
836 | primary POINTSAT identifier
838 tree expr = build_indirect_ref ($1, "->");
841 if (doing_objc_thang)
843 if (is_public (expr, $3))
844 $$ = build_component_ref (expr, $3);
846 $$ = error_mark_node;
850 $$ = build_component_ref (expr, $3);
853 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
855 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
858 { $$ = build_message_expr ($1); }
860 { $$ = build_selector_expr ($1); }
862 { $$ = build_protocol_expr ($1); }
864 { $$ = build_encode_expr ($1); }
866 { $$ = build_objc_string_object ($1); }
870 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
874 { $$ = chainon ($1, $2); }
878 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
882 | objc_string OBJC_STRING
883 { $$ = chainon ($1, $2); }
887 old_style_parm_decls:
891 /* ... is used here to indicate a varargs function. */
894 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
897 /* The following are analogous to lineno_decl, decls and decl
898 except that they do not allow nested functions.
899 They are used for old-style parm decls. */
901 save_filename save_lineno datadecl
908 | datadecls lineno_datadecl
909 | lineno_datadecl errstmt
912 /* We don't allow prefix attributes here because they cause reduce/reduce
913 conflicts: we can't know whether we're parsing a function decl with
914 attribute suffix, or function defn with attribute prefix on first old
917 typed_declspecs_no_prefix_attr setspecs initdecls ';'
918 { current_declspecs = TREE_VALUE (declspec_stack);
919 prefix_attributes = TREE_PURPOSE (declspec_stack);
920 declspec_stack = TREE_CHAIN (declspec_stack);
921 resume_momentary ($2); }
922 | declmods_no_prefix_attr setspecs notype_initdecls ';'
923 { current_declspecs = TREE_VALUE (declspec_stack);
924 prefix_attributes = TREE_PURPOSE (declspec_stack);
925 declspec_stack = TREE_CHAIN (declspec_stack);
926 resume_momentary ($2); }
927 | typed_declspecs_no_prefix_attr ';'
928 { shadow_tag_warned ($1, 1);
929 pedwarn ("empty declaration"); }
930 | declmods_no_prefix_attr ';'
931 { pedwarn ("empty declaration"); }
934 /* This combination which saves a lineno before a decl
935 is the normal thing to use, rather than decl itself.
936 This is to avoid shift/reduce conflicts in contexts
937 where statement labels are allowed. */
939 save_filename save_lineno decl
947 | lineno_decl errstmt
950 /* records the type and storage class specs to use for processing
951 the declarators that follow.
952 Maintains a stack of outer-level values of current_declspecs,
953 for the sake of parm declarations nested in function declarators. */
954 setspecs: /* empty */
955 { $$ = suspend_momentary ();
956 pending_xref_error ();
957 declspec_stack = tree_cons (prefix_attributes,
960 split_specs_attrs ($<ttype>0,
961 ¤t_declspecs, &prefix_attributes); }
964 /* ??? Yuck. See after_type_declarator. */
965 setattrs: /* empty */
966 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
970 typed_declspecs setspecs initdecls ';'
971 { current_declspecs = TREE_VALUE (declspec_stack);
972 prefix_attributes = TREE_PURPOSE (declspec_stack);
973 declspec_stack = TREE_CHAIN (declspec_stack);
974 resume_momentary ($2); }
975 | declmods setspecs notype_initdecls ';'
976 { current_declspecs = TREE_VALUE (declspec_stack);
977 prefix_attributes = TREE_PURPOSE (declspec_stack);
978 declspec_stack = TREE_CHAIN (declspec_stack);
979 resume_momentary ($2); }
980 | typed_declspecs setspecs nested_function
981 { current_declspecs = TREE_VALUE (declspec_stack);
982 prefix_attributes = TREE_PURPOSE (declspec_stack);
983 declspec_stack = TREE_CHAIN (declspec_stack);
984 resume_momentary ($2); }
985 | declmods setspecs notype_nested_function
986 { current_declspecs = TREE_VALUE (declspec_stack);
987 prefix_attributes = TREE_PURPOSE (declspec_stack);
988 declspec_stack = TREE_CHAIN (declspec_stack);
989 resume_momentary ($2); }
990 | typed_declspecs ';'
993 { pedwarn ("empty declaration"); }
995 { pedantic = $<itype>1; }
998 /* Declspecs which contain at least one type specifier or typedef name.
999 (Just `const' or `volatile' is not enough.)
1000 A typedef'd name following these is taken as a name to be declared.
1001 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1004 typespec reserved_declspecs
1005 { $$ = tree_cons (NULL_TREE, $1, $2); }
1006 | declmods typespec reserved_declspecs
1007 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1010 reserved_declspecs: /* empty */
1012 | reserved_declspecs typespecqual_reserved
1013 { $$ = tree_cons (NULL_TREE, $2, $1); }
1014 | reserved_declspecs SCSPEC
1015 { if (extra_warnings)
1016 warning ("`%s' is not at beginning of declaration",
1017 IDENTIFIER_POINTER ($2));
1018 $$ = tree_cons (NULL_TREE, $2, $1); }
1019 | reserved_declspecs attributes
1020 { $$ = tree_cons ($2, NULL_TREE, $1); }
1023 typed_declspecs_no_prefix_attr:
1024 typespec reserved_declspecs_no_prefix_attr
1025 { $$ = tree_cons (NULL_TREE, $1, $2); }
1026 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
1027 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1030 reserved_declspecs_no_prefix_attr:
1033 | reserved_declspecs_no_prefix_attr typespecqual_reserved
1034 { $$ = tree_cons (NULL_TREE, $2, $1); }
1035 | reserved_declspecs_no_prefix_attr SCSPEC
1036 { if (extra_warnings)
1037 warning ("`%s' is not at beginning of declaration",
1038 IDENTIFIER_POINTER ($2));
1039 $$ = tree_cons (NULL_TREE, $2, $1); }
1042 /* List of just storage classes, type modifiers, and prefix attributes.
1043 A declaration can start with just this, but then it cannot be used
1044 to redeclare a typedef-name.
1045 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1048 declmods_no_prefix_attr
1051 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
1052 | declmods declmods_no_prefix_attr
1053 { $$ = chainon ($2, $1); }
1054 | declmods attributes
1055 { $$ = tree_cons ($2, NULL_TREE, $1); }
1058 declmods_no_prefix_attr:
1060 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1061 TREE_STATIC ($$) = 1; }
1063 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1064 | declmods_no_prefix_attr TYPE_QUAL
1065 { $$ = tree_cons (NULL_TREE, $2, $1);
1066 TREE_STATIC ($$) = 1; }
1067 | declmods_no_prefix_attr SCSPEC
1068 { if (extra_warnings && TREE_STATIC ($1))
1069 warning ("`%s' is not at beginning of declaration",
1070 IDENTIFIER_POINTER ($2));
1071 $$ = tree_cons (NULL_TREE, $2, $1);
1072 TREE_STATIC ($$) = TREE_STATIC ($1); }
1076 /* Used instead of declspecs where storage classes are not allowed
1077 (that is, for typenames and structure components).
1078 Don't accept a typedef-name if anything but a modifier precedes it. */
1081 typespec reserved_typespecquals
1082 { $$ = tree_cons (NULL_TREE, $1, $2); }
1083 | nonempty_type_quals typespec reserved_typespecquals
1084 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1087 reserved_typespecquals: /* empty */
1089 | reserved_typespecquals typespecqual_reserved
1090 { $$ = tree_cons (NULL_TREE, $2, $1); }
1093 /* A typespec (but not a type qualifier).
1094 Once we have seen one of these in a declaration,
1095 if a typedef name appears then it is being redeclared. */
1100 { /* For a typedef name, record the meaning, not the name.
1101 In case of `foo foo, bar;'. */
1102 $$ = lookup_name ($1); }
1104 | CLASSNAME protocolrefs
1105 { $$ = get_static_reference ($1, $2); }
1106 | OBJECTNAME protocolrefs
1107 { $$ = get_object_reference ($2); }
1109 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1110 - nisse@lysator.liu.se */
1111 | non_empty_protocolrefs
1112 { $$ = get_object_reference ($1); }
1114 | TYPEOF '(' expr ')'
1115 { $$ = TREE_TYPE ($3); }
1116 | TYPEOF '(' typename ')'
1117 { $$ = groktypename ($3); }
1120 /* A typespec that is a reserved word, or a type qualifier. */
1122 typespecqual_reserved: TYPESPEC
1129 | initdecls ',' initdcl
1134 | notype_initdecls ',' initdcl
1140 | ASM_KEYWORD '(' string ')'
1141 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1147 declarator maybeasm maybe_attribute '='
1148 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1149 $3, prefix_attributes);
1150 start_init ($<ttype>$, $2, global_bindings_p ()); }
1152 /* Note how the declaration of the variable is in effect while its init is parsed! */
1154 finish_decl ($<ttype>5, $6, $2); }
1155 | declarator maybeasm maybe_attribute
1156 { tree d = start_decl ($1, current_declspecs, 0,
1157 $3, prefix_attributes);
1158 finish_decl (d, NULL_TREE, $2);
1163 notype_declarator maybeasm maybe_attribute '='
1164 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1165 $3, prefix_attributes);
1166 start_init ($<ttype>$, $2, global_bindings_p ()); }
1168 /* Note how the declaration of the variable is in effect while its init is parsed! */
1170 decl_attributes ($<ttype>5, $3, prefix_attributes);
1171 finish_decl ($<ttype>5, $6, $2); }
1172 | notype_declarator maybeasm maybe_attribute
1173 { tree d = start_decl ($1, current_declspecs, 0,
1174 $3, prefix_attributes);
1175 finish_decl (d, NULL_TREE, $2); }
1177 /* the * rules are dummies to accept the Apollo extended syntax
1178 so that the header files compile. */
1189 | attributes attribute
1190 { $$ = chainon ($1, $2); }
1194 ATTRIBUTE '(' '(' attribute_list ')' ')'
1201 | attribute_list ',' attrib
1202 { $$ = chainon ($1, $3); }
1209 { $$ = build_tree_list ($1, NULL_TREE); }
1210 | any_word '(' IDENTIFIER ')'
1211 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1212 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1213 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1214 | any_word '(' exprlist ')'
1215 { $$ = build_tree_list ($1, $3); }
1218 /* This still leaves out most reserved keywords,
1219 shouldn't we include them? */
1228 /* Initializers. `init' is the entry point. */
1233 { really_start_incremental_init (NULL_TREE);
1234 /* Note that the call to clear_momentary
1235 is in process_init_element. */
1236 push_momentary (); }
1237 initlist_maybe_comma '}'
1238 { $$ = pop_init_level (0);
1239 if ($$ == error_mark_node
1240 && ! (yychar == STRING || yychar == CONSTANT))
1243 pop_momentary_nofree (); }
1246 { $$ = error_mark_node; }
1249 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1250 initlist_maybe_comma:
1253 pedwarn ("ANSI C forbids empty initializer braces"); }
1254 | initlist1 maybecomma
1259 | initlist1 ',' initelt
1262 /* `initelt' is a single element of an initializer.
1263 It may use braces. */
1265 designator_list '=' initval
1266 | designator initval
1268 { set_init_label ($1); }
1275 { push_init_level (0); }
1276 initlist_maybe_comma '}'
1277 { process_init_element (pop_init_level (0)); }
1279 { process_init_element ($1); }
1285 | designator_list designator
1290 { set_init_label ($2); }
1291 /* These are for labeled elements. The syntax for an array element
1292 initializer conflicts with the syntax for an Objective-C message,
1293 so don't include these productions in the Objective-C grammar. */
1295 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1296 { set_init_index ($2, $4); }
1297 | '[' expr_no_commas ']'
1298 { set_init_index ($2, NULL_TREE); }
1305 pedwarn ("ANSI C forbids nested functions");
1307 push_function_context ();
1308 if (! start_function (current_declspecs, $1,
1309 prefix_attributes, NULL_TREE, 1))
1311 pop_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_function_context (); }
1328 notype_nested_function:
1331 pedwarn ("ANSI C forbids nested functions");
1333 push_function_context ();
1334 if (! start_function (current_declspecs, $1,
1335 prefix_attributes, NULL_TREE, 1))
1337 pop_function_context ();
1340 reinit_parse_for_function (); }
1341 old_style_parm_decls
1342 { store_parm_decls (); }
1343 /* This used to use compstmt_or_error.
1344 That caused a bug with input `f(g) int g {}',
1345 where the use of YYERROR1 above caused an error
1346 which then was handled by compstmt_or_error.
1347 There followed a repeated execution of that same rule,
1348 which called YYERROR1 again, and so on. */
1350 { finish_function (1);
1351 pop_function_context (); }
1354 /* Any kind of declarator (thus, all declarators allowed
1355 after an explicit typespec). */
1358 after_type_declarator
1362 /* A declarator that is allowed only after an explicit typespec. */
1364 after_type_declarator:
1365 '(' after_type_declarator ')'
1367 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1368 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1369 /* | after_type_declarator '(' error ')' %prec '.'
1370 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1371 poplevel (0, 0, 0); } */
1372 | after_type_declarator '[' expr ']' %prec '.'
1373 { $$ = build_nt (ARRAY_REF, $1, $3); }
1374 | after_type_declarator '[' ']' %prec '.'
1375 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1376 | '*' type_quals after_type_declarator %prec UNARY
1377 { $$ = make_pointer_declarator ($2, $3); }
1378 /* ??? Yuck. setattrs is a quick hack. We can't use
1379 prefix_attributes because $1 only applies to this
1380 declarator. We assume setspecs has already been done.
1381 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1382 attributes could be recognized here or in `attributes'). */
1383 | attributes setattrs after_type_declarator
1391 /* Kinds of declarator that can appear in a parameter list
1392 in addition to notype_declarator. This is like after_type_declarator
1393 but does not allow a typedef name in parentheses as an identifier
1394 (because it would conflict with a function with that typedef as arg). */
1397 parm_declarator '(' parmlist_or_identifiers %prec '.'
1398 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1399 /* | parm_declarator '(' error ')' %prec '.'
1400 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1401 poplevel (0, 0, 0); } */
1403 | parm_declarator '[' '*' ']' %prec '.'
1404 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1406 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1409 | parm_declarator '[' expr ']' %prec '.'
1410 { $$ = build_nt (ARRAY_REF, $1, $3); }
1411 | parm_declarator '[' ']' %prec '.'
1412 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1413 | '*' type_quals parm_declarator %prec UNARY
1414 { $$ = make_pointer_declarator ($2, $3); }
1415 /* ??? Yuck. setattrs is a quick hack. We can't use
1416 prefix_attributes because $1 only applies to this
1417 declarator. We assume setspecs has already been done.
1418 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1419 attributes could be recognized here or in `attributes'). */
1420 | attributes setattrs parm_declarator
1425 /* A declarator allowed whether or not there has been
1426 an explicit typespec. These cannot redeclare a typedef-name. */
1429 notype_declarator '(' parmlist_or_identifiers %prec '.'
1430 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1431 /* | notype_declarator '(' error ')' %prec '.'
1432 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1433 poplevel (0, 0, 0); } */
1434 | '(' notype_declarator ')'
1436 | '*' type_quals notype_declarator %prec UNARY
1437 { $$ = make_pointer_declarator ($2, $3); }
1439 | notype_declarator '[' '*' ']' %prec '.'
1440 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1442 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1445 | notype_declarator '[' expr ']' %prec '.'
1446 { $$ = build_nt (ARRAY_REF, $1, $3); }
1447 | notype_declarator '[' ']' %prec '.'
1448 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1449 /* ??? Yuck. setattrs is a quick hack. We can't use
1450 prefix_attributes because $1 only applies to this
1451 declarator. We assume setspecs has already been done.
1452 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1453 attributes could be recognized here or in `attributes'). */
1454 | attributes setattrs notype_declarator
1481 struct_head identifier '{'
1482 { $$ = start_struct (RECORD_TYPE, $2);
1483 /* Start scope of tag before parsing components. */
1485 component_decl_list '}' maybe_attribute
1486 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1487 | struct_head '{' component_decl_list '}' maybe_attribute
1488 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1489 $3, chainon ($1, $5));
1491 | struct_head identifier
1492 { $$ = xref_tag (RECORD_TYPE, $2); }
1493 | union_head identifier '{'
1494 { $$ = start_struct (UNION_TYPE, $2); }
1495 component_decl_list '}' maybe_attribute
1496 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1497 | union_head '{' component_decl_list '}' maybe_attribute
1498 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1499 $3, chainon ($1, $5));
1501 | union_head identifier
1502 { $$ = xref_tag (UNION_TYPE, $2); }
1503 | enum_head identifier '{'
1504 { $<itype>3 = suspend_momentary ();
1505 $$ = start_enum ($2); }
1506 enumlist maybecomma_warn '}' maybe_attribute
1507 { $$= finish_enum ($<ttype>4, nreverse ($5), chainon ($1, $8));
1508 resume_momentary ($<itype>3); }
1510 { $<itype>2 = suspend_momentary ();
1511 $$ = start_enum (NULL_TREE); }
1512 enumlist maybecomma_warn '}' maybe_attribute
1513 { $$= finish_enum ($<ttype>3, nreverse ($4), chainon ($1, $7));
1514 resume_momentary ($<itype>2); }
1515 | enum_head identifier
1516 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1527 { if (pedantic && ! flag_isoc9x)
1528 pedwarn ("comma at end of enumerator list"); }
1531 component_decl_list:
1532 component_decl_list2
1534 | component_decl_list2 component_decl
1535 { $$ = chainon ($1, $2);
1536 pedwarn ("no semicolon at end of struct or union"); }
1539 component_decl_list2: /* empty */
1541 | component_decl_list2 component_decl ';'
1542 { $$ = chainon ($1, $2); }
1543 | component_decl_list2 ';'
1545 pedwarn ("extra semicolon in struct or union specified"); }
1547 /* foo(sizeof(struct{ @defs(ClassName)})); */
1548 | DEFS '(' CLASSNAME ')'
1550 tree interface = lookup_interface ($3);
1553 $$ = get_class_ivars (interface);
1556 error ("Cannot find interface declaration for `%s'",
1557 IDENTIFIER_POINTER ($3));
1564 /* There is a shift-reduce conflict here, because `components' may
1565 start with a `typename'. It happens that shifting (the default resolution)
1566 does the right thing, because it treats the `typename' as part of
1567 a `typed_typespecs'.
1569 It is possible that this same technique would allow the distinction
1570 between `notype_initdecls' and `initdecls' to be eliminated.
1571 But I am being cautious and not trying it. */
1574 typed_typespecs setspecs components
1576 current_declspecs = TREE_VALUE (declspec_stack);
1577 prefix_attributes = TREE_PURPOSE (declspec_stack);
1578 declspec_stack = TREE_CHAIN (declspec_stack);
1579 resume_momentary ($2); }
1582 pedwarn ("ANSI C forbids member declarations with no members");
1585 | nonempty_type_quals setspecs components
1587 current_declspecs = TREE_VALUE (declspec_stack);
1588 prefix_attributes = TREE_PURPOSE (declspec_stack);
1589 declspec_stack = TREE_CHAIN (declspec_stack);
1590 resume_momentary ($2); }
1591 | nonempty_type_quals
1593 pedwarn ("ANSI C forbids member declarations with no members");
1598 | extension component_decl
1600 pedantic = $<itype>1; }
1604 component_declarator
1605 | components ',' component_declarator
1606 { $$ = chainon ($1, $3); }
1609 component_declarator:
1610 save_filename save_lineno declarator maybe_attribute
1611 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1612 decl_attributes ($$, $4, prefix_attributes); }
1613 | save_filename save_lineno
1614 declarator ':' expr_no_commas maybe_attribute
1615 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1616 decl_attributes ($$, $6, prefix_attributes); }
1617 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1618 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1619 decl_attributes ($$, $5, prefix_attributes); }
1622 /* We chain the enumerators in reverse order.
1623 They are put in forward order where enumlist is used.
1624 (The order used to be significant, but no longer is so.
1625 However, we still maintain the order, just to be clean.) */
1629 | enumlist ',' enumerator
1630 { if ($1 == error_mark_node)
1633 $$ = chainon ($3, $1); }
1635 { $$ = error_mark_node; }
1641 { $$ = build_enumerator ($1, NULL_TREE); }
1642 | identifier '=' expr_no_commas
1643 { $$ = build_enumerator ($1, $3); }
1647 typed_typespecs absdcl
1648 { $$ = build_tree_list ($1, $2); }
1649 | nonempty_type_quals absdcl
1650 { $$ = build_tree_list ($1, $2); }
1653 absdcl: /* an absolute declarator */
1659 nonempty_type_quals:
1661 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1662 | nonempty_type_quals TYPE_QUAL
1663 { $$ = tree_cons (NULL_TREE, $2, $1); }
1669 | type_quals TYPE_QUAL
1670 { $$ = tree_cons (NULL_TREE, $2, $1); }
1673 absdcl1: /* a nonempty absolute declarator */
1676 /* `(typedef)1' is `int'. */
1677 | '*' type_quals absdcl1 %prec UNARY
1678 { $$ = make_pointer_declarator ($2, $3); }
1679 | '*' type_quals %prec UNARY
1680 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1681 | absdcl1 '(' parmlist %prec '.'
1682 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1683 | absdcl1 '[' expr ']' %prec '.'
1684 { $$ = build_nt (ARRAY_REF, $1, $3); }
1685 | absdcl1 '[' ']' %prec '.'
1686 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1687 | '(' parmlist %prec '.'
1688 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1689 | '[' expr ']' %prec '.'
1690 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1692 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1693 /* ??? It appears we have to support attributes here, however
1694 using prefix_attributes is wrong. */
1695 | attributes setattrs absdcl1
1699 /* at least one statement, the first of which parses without error. */
1700 /* stmts is used only after decls, so an invalid first statement
1701 is actually regarded as an invalid decl and part of the decls. */
1704 lineno_stmt_or_labels
1707 pedwarn ("ANSI C forbids label at end of compound statement");
1711 lineno_stmt_or_labels:
1712 lineno_stmt_or_label
1713 | lineno_stmt_or_labels lineno_stmt_or_label
1715 | lineno_stmt_or_labels errstmt
1727 pushlevel: /* empty */
1728 { emit_line_note (input_filename, lineno);
1732 expand_start_bindings (0);
1734 if (objc_method_context)
1740 /* Read zero or more forward-declarations for labels
1741 that nested functions can jump to. */
1746 pedwarn ("ANSI C forbids label declarations"); }
1751 | label_decls label_decl
1755 LABEL identifiers_or_typenames ';'
1757 for (link = $2; link; link = TREE_CHAIN (link))
1759 tree label = shadow_label (TREE_VALUE (link));
1760 C_DECLARED_LABEL_FLAG (label) = 1;
1761 declare_nonlocal_label (label);
1766 /* This is the body of a function definition.
1767 It causes syntax errors to ignore to the next openbrace. */
1774 compstmt_start: '{' { compstmt_count++; }
1776 compstmt_nostart: '}'
1777 { $$ = convert (void_type_node, integer_zero_node); }
1778 | pushlevel maybe_label_decls decls xstmts '}'
1779 { emit_line_note (input_filename, lineno);
1780 expand_end_bindings (getdecls (), 1, 0);
1781 $$ = poplevel (1, 1, 0);
1782 if (yychar == CONSTANT || yychar == STRING)
1783 pop_momentary_nofree ();
1786 | pushlevel maybe_label_decls error '}'
1787 { emit_line_note (input_filename, lineno);
1788 expand_end_bindings (getdecls (), kept_level_p (), 0);
1789 $$ = poplevel (kept_level_p (), 0, 0);
1790 if (yychar == CONSTANT || yychar == STRING)
1791 pop_momentary_nofree ();
1794 | pushlevel maybe_label_decls stmts '}'
1795 { emit_line_note (input_filename, lineno);
1796 expand_end_bindings (getdecls (), kept_level_p (), 0);
1797 $$ = poplevel (kept_level_p (), 0, 0);
1798 if (yychar == CONSTANT || yychar == STRING)
1799 pop_momentary_nofree ();
1804 compstmt_primary_start:
1806 { if (current_function_decl == 0)
1808 error ("braced-group within expression allowed only inside a function");
1811 /* We must force a BLOCK for this level
1812 so that, if it is not expanded later,
1813 there is a way to turn off the entire subtree of blocks
1814 that are contained in it. */
1816 push_iterator_stack ();
1817 push_label_level ();
1818 $$ = expand_start_stmt_expr ();
1822 compstmt: compstmt_start compstmt_nostart
1826 /* Value is number of statements counted as of the closeparen. */
1828 if_prefix lineno_labeled_stmt
1829 /* Make sure c_expand_end_cond is run once
1830 for each call to c_expand_start_cond.
1831 Otherwise a crash is likely. */
1837 { emit_line_note ($<filename>-1, $<lineno>0);
1838 c_expand_start_cond (truthvalue_conversion ($3), 0,
1840 $<itype>$ = stmt_count;
1841 if_stmt_file = $<filename>-1;
1842 if_stmt_line = $<lineno>0;
1843 position_after_white_space (); }
1846 /* This is a subroutine of stmt.
1847 It is used twice, once for valid DO statements
1848 and once for catching errors in parsing the end test. */
1853 emit_line_note ($<filename>-1, $<lineno>0);
1854 /* See comment in `while' alternative, above. */
1856 expand_start_loop_continue_elsewhere (1);
1857 position_after_white_space (); }
1858 lineno_labeled_stmt WHILE
1859 { expand_loop_continue_here (); }
1863 { $$ = input_filename; }
1870 lineno_labeled_stmt:
1871 save_filename save_lineno stmt
1873 /* | save_filename save_lineno error
1876 | save_filename save_lineno label lineno_labeled_stmt
1880 lineno_stmt_or_label:
1881 save_filename save_lineno stmt_or_label
1892 /* Parse a single real statement, not including any labels. */
1899 emit_line_note ($<filename>-1, $<lineno>0);
1900 /* It appears that this should not be done--that a non-lvalue array
1901 shouldn't get an error if the value isn't used.
1902 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1903 if it appears as a top-level expression,
1904 but says nothing about non-lvalue arrays. */
1906 /* Call default_conversion to get an error
1907 on referring to a register array if pedantic. */
1908 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1909 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1910 $1 = default_conversion ($1);
1912 iterator_expand ($1);
1913 clear_momentary (); }
1915 { c_expand_start_else ();
1916 $<itype>1 = stmt_count;
1917 position_after_white_space (); }
1919 { c_expand_end_cond ();
1920 if (extra_warnings && stmt_count == $<itype>1)
1921 warning ("empty body in an else-statement"); }
1922 | simple_if %prec IF
1923 { c_expand_end_cond ();
1924 /* This warning is here instead of in simple_if, because we
1925 do not want a warning if an empty if is followed by an
1926 else statement. Increment stmt_count so we don't
1927 give a second error if this is a nested `if'. */
1928 if (extra_warnings && stmt_count++ == $<itype>1)
1929 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1930 "empty body in an if-statement"); }
1931 /* Make sure c_expand_end_cond is run once
1932 for each call to c_expand_start_cond.
1933 Otherwise a crash is likely. */
1934 | simple_if ELSE error
1935 { c_expand_end_cond (); }
1938 emit_line_note ($<filename>-1, $<lineno>0);
1939 /* The emit_nop used to come before emit_line_note,
1940 but that made the nop seem like part of the preceding line.
1941 And that was confusing when the preceding line was
1942 inside of an if statement and was not really executed.
1943 I think it ought to work to put the nop after the line number.
1944 We will see. --rms, July 15, 1991. */
1947 { /* Don't start the loop till we have succeeded
1948 in parsing the end test. This is to make sure
1949 that we end every loop we start. */
1950 expand_start_loop (1);
1951 emit_line_note (input_filename, lineno);
1952 expand_exit_loop_if_false (NULL_PTR,
1953 truthvalue_conversion ($4));
1954 position_after_white_space (); }
1956 { expand_end_loop (); }
1959 { emit_line_note (input_filename, lineno);
1960 expand_exit_loop_if_false (NULL_PTR,
1961 truthvalue_conversion ($3));
1963 clear_momentary (); }
1964 /* This rule is needed to make sure we end every loop we start. */
1965 | do_stmt_start error
1966 { expand_end_loop ();
1967 clear_momentary (); }
1971 emit_line_note ($<filename>-1, $<lineno>0);
1972 /* See comment in `while' alternative, above. */
1974 if ($3) c_expand_expr_stmt ($3);
1975 /* Next step is to call expand_start_loop_continue_elsewhere,
1976 but wait till after we parse the entire for (...).
1977 Otherwise, invalid input might cause us to call that
1978 fn without calling expand_end_loop. */
1981 /* Can't emit now; wait till after expand_start_loop... */
1982 { $<lineno>7 = lineno;
1983 $<filename>$ = input_filename; }
1986 /* Start the loop. Doing this after parsing
1987 all the expressions ensures we will end the loop. */
1988 expand_start_loop_continue_elsewhere (1);
1989 /* Emit the end-test, with a line number. */
1990 emit_line_note ($<filename>8, $<lineno>7);
1992 expand_exit_loop_if_false (NULL_PTR,
1993 truthvalue_conversion ($6));
1994 /* Don't let the tree nodes for $9 be discarded by
1995 clear_momentary during the parsing of the next stmt. */
1997 $<lineno>7 = lineno;
1998 $<filename>8 = input_filename;
1999 position_after_white_space (); }
2001 { /* Emit the increment expression, with a line number. */
2002 emit_line_note ($<filename>8, $<lineno>7);
2003 expand_loop_continue_here ();
2005 c_expand_expr_stmt ($9);
2006 if (yychar == CONSTANT || yychar == STRING)
2007 pop_momentary_nofree ();
2010 expand_end_loop (); }
2011 | SWITCH '(' expr ')'
2013 emit_line_note ($<filename>-1, $<lineno>0);
2014 c_expand_start_case ($3);
2015 /* Don't let the tree nodes for $3 be discarded by
2016 clear_momentary during the parsing of the next stmt. */
2018 position_after_white_space (); }
2020 { expand_end_case ($3);
2021 if (yychar == CONSTANT || yychar == STRING)
2022 pop_momentary_nofree ();
2027 emit_line_note ($<filename>-1, $<lineno>0);
2028 if ( ! expand_exit_something ())
2029 error ("break statement not within loop or switch"); }
2032 emit_line_note ($<filename>-1, $<lineno>0);
2033 if (! expand_continue_loop (NULL_PTR))
2034 error ("continue statement not within a loop"); }
2037 emit_line_note ($<filename>-1, $<lineno>0);
2038 c_expand_return (NULL_TREE); }
2041 emit_line_note ($<filename>-1, $<lineno>0);
2042 c_expand_return ($2); }
2043 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2045 emit_line_note ($<filename>-1, $<lineno>0);
2047 if ((TREE_CODE ($4) == ADDR_EXPR
2048 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
2049 || TREE_CODE ($4) == STRING_CST)
2052 error ("argument of `asm' is not a constant string"); }
2053 /* This is the case with just output operands. */
2054 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2056 emit_line_note ($<filename>-1, $<lineno>0);
2057 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2058 $2 == ridpointers[(int)RID_VOLATILE],
2059 input_filename, lineno); }
2060 /* This is the case with input operands as well. */
2061 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2063 emit_line_note ($<filename>-1, $<lineno>0);
2064 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2065 $2 == ridpointers[(int)RID_VOLATILE],
2066 input_filename, lineno); }
2067 /* This is the case with clobbered registers as well. */
2068 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2069 asm_operands ':' asm_clobbers ')' ';'
2071 emit_line_note ($<filename>-1, $<lineno>0);
2072 c_expand_asm_operands ($4, $6, $8, $10,
2073 $2 == ridpointers[(int)RID_VOLATILE],
2074 input_filename, lineno); }
2075 | GOTO identifier ';'
2078 emit_line_note ($<filename>-1, $<lineno>0);
2079 decl = lookup_label ($2);
2082 TREE_USED (decl) = 1;
2088 pedwarn ("ANSI C forbids `goto *expr;'");
2090 emit_line_note ($<filename>-1, $<lineno>0);
2091 expand_computed_goto (convert (ptr_type_node, $3)); }
2096 all_iter_stmt_simple
2097 /* | all_iter_stmt_with_decl */
2100 all_iter_stmt_simple:
2103 /* The value returned by this action is */
2104 /* 1 if everything is OK */
2105 /* 0 in case of error or already bound iterator */
2108 if (TREE_CODE ($3) != VAR_DECL)
2109 error ("invalid `for (ITERATOR)' syntax");
2110 else if (! ITERATOR_P ($3))
2111 error ("`%s' is not an iterator",
2112 IDENTIFIER_POINTER (DECL_NAME ($3)));
2113 else if (ITERATOR_BOUND_P ($3))
2114 error ("`for (%s)' inside expansion of same iterator",
2115 IDENTIFIER_POINTER (DECL_NAME ($3)));
2119 iterator_for_loop_start ($3);
2125 iterator_for_loop_end ($3);
2128 /* This really should allow any kind of declaration,
2129 for generality. Fix it before turning it back on.
2131 all_iter_stmt_with_decl:
2132 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2134 */ /* The value returned by this action is */
2135 /* 1 if everything is OK */
2136 /* 0 in case of error or already bound iterator */
2138 iterator_for_loop_start ($6);
2142 iterator_for_loop_end ($6);
2143 emit_line_note (input_filename, lineno);
2144 expand_end_bindings (getdecls (), 1, 0);
2145 $<ttype>$ = poplevel (1, 1, 0);
2146 if (yychar == CONSTANT || yychar == STRING)
2147 pop_momentary_nofree ();
2153 /* Any kind of label, including jump labels and case labels.
2154 ANSI C accepts labels only before statements, but we allow them
2155 also at the end of a compound statement. */
2157 label: CASE expr_no_commas ':'
2158 { register tree value = check_case_value ($2);
2160 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2164 if (value != error_mark_node)
2169 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2170 pedwarn ("label must have integral type in ANSI C");
2172 success = pushcase (value, convert_and_check,
2176 error ("case label not within a switch statement");
2177 else if (success == 2)
2179 error ("duplicate case value");
2180 error_with_decl (duplicate, "this is the first entry for that value");
2182 else if (success == 3)
2183 warning ("case value out of range");
2184 else if (success == 5)
2185 error ("case label within scope of cleanup or variable array");
2187 position_after_white_space (); }
2188 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2189 { register tree value1 = check_case_value ($2);
2190 register tree value2 = check_case_value ($4);
2192 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2195 pedwarn ("ANSI C forbids case ranges");
2198 if (value1 != error_mark_node && value2 != error_mark_node)
2201 int success = pushcase_range (value1, value2,
2202 convert_and_check, label,
2205 error ("case label not within a switch statement");
2206 else if (success == 2)
2208 error ("duplicate case value");
2209 error_with_decl (duplicate, "this is the first entry for that value");
2211 else if (success == 3)
2212 warning ("case value out of range");
2213 else if (success == 4)
2214 warning ("empty case range");
2215 else if (success == 5)
2216 error ("case label within scope of cleanup or variable array");
2218 position_after_white_space (); }
2223 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2224 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2227 error ("default label not within a switch statement");
2228 else if (success == 2)
2230 error ("multiple default labels in one switch");
2231 error_with_decl (duplicate, "this is the first default label");
2233 position_after_white_space (); }
2234 | identifier ':' maybe_attribute
2235 { tree label = define_label (input_filename, lineno, $1);
2240 expand_label (label);
2241 decl_attributes (label, $3, NULL_TREE);
2243 position_after_white_space (); }
2246 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2250 { emit_line_note (input_filename, lineno);
2253 { emit_line_note (input_filename, lineno); }
2262 /* These are the operands other than the first string and colon
2263 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2264 asm_operands: /* empty */
2266 | nonnull_asm_operands
2269 nonnull_asm_operands:
2271 | nonnull_asm_operands ',' asm_operand
2272 { $$ = chainon ($1, $3); }
2277 { $$ = build_tree_list ($1, $3); }
2282 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2283 | asm_clobbers ',' string
2284 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2287 /* This is what appears inside the parens in a function declarator.
2288 Its value is a list of ..._TYPE nodes. */
2291 clear_parm_order ();
2292 declare_parm_level (0); }
2295 parmlist_tags_warning ();
2296 poplevel (0, 0, 0); }
2304 pedwarn ("ANSI C forbids forward parameter declarations");
2305 /* Mark the forward decls as such. */
2306 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2307 TREE_ASM_WRITTEN (parm) = 1;
2308 clear_parm_order (); }
2312 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2315 /* This is what appears inside the parens in a function declarator.
2316 Is value is represented in the format that grokdeclarator expects. */
2317 parmlist_2: /* empty */
2318 { $$ = get_parm_info (0); }
2320 { $$ = get_parm_info (0);
2321 /* Gcc used to allow this as an extension. However, it does
2322 not work for all targets, and thus has been disabled.
2323 Also, since func (...) and func () are indistinguishable,
2324 it caused problems with the code in expand_builtin which
2325 tries to verify that BUILT_IN_NEXT_ARG is being used
2327 error ("ANSI C requires a named argument before `...'");
2330 { $$ = get_parm_info (1); }
2331 | parms ',' ELLIPSIS
2332 { $$ = get_parm_info (0); }
2337 { push_parm_decl ($1); }
2339 { push_parm_decl ($3); }
2342 /* A single parameter declaration or parameter type name,
2343 as found in a parmlist. */
2345 typed_declspecs setspecs parm_declarator maybe_attribute
2346 { $$ = build_tree_list (build_tree_list (current_declspecs,
2348 build_tree_list (prefix_attributes,
2350 current_declspecs = TREE_VALUE (declspec_stack);
2351 prefix_attributes = TREE_PURPOSE (declspec_stack);
2352 declspec_stack = TREE_CHAIN (declspec_stack);
2353 resume_momentary ($2); }
2354 | typed_declspecs setspecs notype_declarator maybe_attribute
2355 { $$ = build_tree_list (build_tree_list (current_declspecs,
2357 build_tree_list (prefix_attributes,
2359 current_declspecs = TREE_VALUE (declspec_stack);
2360 prefix_attributes = TREE_PURPOSE (declspec_stack);
2361 declspec_stack = TREE_CHAIN (declspec_stack);
2362 resume_momentary ($2); }
2363 | typed_declspecs setspecs absdcl maybe_attribute
2364 { $$ = build_tree_list (build_tree_list (current_declspecs,
2366 build_tree_list (prefix_attributes,
2368 current_declspecs = TREE_VALUE (declspec_stack);
2369 prefix_attributes = TREE_PURPOSE (declspec_stack);
2370 declspec_stack = TREE_CHAIN (declspec_stack);
2371 resume_momentary ($2); }
2372 | declmods setspecs notype_declarator maybe_attribute
2373 { $$ = build_tree_list (build_tree_list (current_declspecs,
2375 build_tree_list (prefix_attributes,
2377 current_declspecs = TREE_VALUE (declspec_stack);
2378 prefix_attributes = TREE_PURPOSE (declspec_stack);
2379 declspec_stack = TREE_CHAIN (declspec_stack);
2380 resume_momentary ($2); }
2382 | declmods setspecs absdcl maybe_attribute
2383 { $$ = build_tree_list (build_tree_list (current_declspecs,
2385 build_tree_list (prefix_attributes,
2387 current_declspecs = TREE_VALUE (declspec_stack);
2388 prefix_attributes = TREE_PURPOSE (declspec_stack);
2389 declspec_stack = TREE_CHAIN (declspec_stack);
2390 resume_momentary ($2); }
2393 /* This is used in a function definition
2394 where either a parmlist or an identifier list is ok.
2395 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2396 parmlist_or_identifiers:
2398 clear_parm_order ();
2399 declare_parm_level (1); }
2400 parmlist_or_identifiers_1
2402 parmlist_tags_warning ();
2403 poplevel (0, 0, 0); }
2406 parmlist_or_identifiers_1:
2410 for (t = $1; t; t = TREE_CHAIN (t))
2411 if (TREE_VALUE (t) == NULL_TREE)
2412 error ("`...' in old-style identifier list");
2413 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2416 /* A nonempty list of identifiers. */
2419 { $$ = build_tree_list (NULL_TREE, $1); }
2420 | identifiers ',' IDENTIFIER
2421 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2424 /* A nonempty list of identifiers, including typenames. */
2425 identifiers_or_typenames:
2427 { $$ = build_tree_list (NULL_TREE, $1); }
2428 | identifiers_or_typenames ',' identifier
2429 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2434 { $<itype>$ = pedantic;
2439 /* Objective-C productions. */
2449 if (objc_implementation_context)
2451 finish_class (objc_implementation_context);
2452 objc_ivar_chain = NULL_TREE;
2453 objc_implementation_context = NULL_TREE;
2456 warning ("`@end' must appear in an implementation context");
2460 /* A nonempty list of identifiers. */
2463 { $$ = build_tree_list (NULL_TREE, $1); }
2464 | identifier_list ',' identifier
2465 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2469 CLASS identifier_list ';'
2471 objc_declare_class ($2);
2475 ALIAS identifier identifier ';'
2477 objc_declare_alias ($2, $3);
2481 INTERFACE identifier protocolrefs '{'
2483 objc_interface_context = objc_ivar_context
2484 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2485 objc_public_flag = 0;
2489 continue_class (objc_interface_context);
2494 finish_class (objc_interface_context);
2495 objc_interface_context = NULL_TREE;
2498 | INTERFACE identifier protocolrefs
2500 objc_interface_context
2501 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2502 continue_class (objc_interface_context);
2507 finish_class (objc_interface_context);
2508 objc_interface_context = NULL_TREE;
2511 | INTERFACE identifier ':' identifier protocolrefs '{'
2513 objc_interface_context = objc_ivar_context
2514 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2515 objc_public_flag = 0;
2519 continue_class (objc_interface_context);
2524 finish_class (objc_interface_context);
2525 objc_interface_context = NULL_TREE;
2528 | INTERFACE identifier ':' identifier protocolrefs
2530 objc_interface_context
2531 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2532 continue_class (objc_interface_context);
2537 finish_class (objc_interface_context);
2538 objc_interface_context = NULL_TREE;
2541 | IMPLEMENTATION identifier '{'
2543 objc_implementation_context = objc_ivar_context
2544 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2545 objc_public_flag = 0;
2550 = continue_class (objc_implementation_context);
2553 | IMPLEMENTATION identifier
2555 objc_implementation_context
2556 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2558 = continue_class (objc_implementation_context);
2561 | IMPLEMENTATION identifier ':' identifier '{'
2563 objc_implementation_context = objc_ivar_context
2564 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2565 objc_public_flag = 0;
2570 = continue_class (objc_implementation_context);
2573 | IMPLEMENTATION identifier ':' identifier
2575 objc_implementation_context
2576 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2578 = continue_class (objc_implementation_context);
2581 | INTERFACE identifier '(' identifier ')' protocolrefs
2583 objc_interface_context
2584 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2585 continue_class (objc_interface_context);
2590 finish_class (objc_interface_context);
2591 objc_interface_context = NULL_TREE;
2594 | IMPLEMENTATION identifier '(' identifier ')'
2596 objc_implementation_context
2597 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2599 = continue_class (objc_implementation_context);
2604 PROTOCOL identifier protocolrefs
2606 remember_protocol_qualifiers ();
2607 objc_interface_context
2608 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2612 forget_protocol_qualifiers();
2613 finish_protocol(objc_interface_context);
2614 objc_interface_context = NULL_TREE;
2623 | non_empty_protocolrefs
2626 non_empty_protocolrefs:
2627 ARITHCOMPARE identifier_list ARITHCOMPARE
2629 if ($1 == LT_EXPR && $3 == GT_EXPR)
2637 ivar_decl_list visibility_spec ivar_decls
2642 PRIVATE { objc_public_flag = 2; }
2643 | PROTECTED { objc_public_flag = 0; }
2644 | PUBLIC { objc_public_flag = 1; }
2652 | ivar_decls ivar_decl ';'
2656 pedwarn ("extra semicolon in struct or union specified");
2661 /* There is a shift-reduce conflict here, because `components' may
2662 start with a `typename'. It happens that shifting (the default resolution)
2663 does the right thing, because it treats the `typename' as part of
2664 a `typed_typespecs'.
2666 It is possible that this same technique would allow the distinction
2667 between `notype_initdecls' and `initdecls' to be eliminated.
2668 But I am being cautious and not trying it. */
2671 typed_typespecs setspecs ivars
2673 current_declspecs = TREE_VALUE (declspec_stack);
2674 prefix_attributes = TREE_PURPOSE (declspec_stack);
2675 declspec_stack = TREE_CHAIN (declspec_stack);
2676 resume_momentary ($2); }
2677 | nonempty_type_quals setspecs ivars
2679 current_declspecs = TREE_VALUE (declspec_stack);
2680 prefix_attributes = TREE_PURPOSE (declspec_stack);
2681 declspec_stack = TREE_CHAIN (declspec_stack);
2682 resume_momentary ($2); }
2691 | ivars ',' ivar_declarator
2697 $$ = add_instance_variable (objc_ivar_context,
2699 $1, current_declspecs,
2702 | declarator ':' expr_no_commas
2704 $$ = add_instance_variable (objc_ivar_context,
2706 $1, current_declspecs, $3);
2708 | ':' expr_no_commas
2710 $$ = add_instance_variable (objc_ivar_context,
2713 current_declspecs, $2);
2720 remember_protocol_qualifiers ();
2721 if (objc_implementation_context)
2722 objc_inherit_code = CLASS_METHOD_DECL;
2724 fatal ("method definition not in class context");
2728 forget_protocol_qualifiers ();
2729 add_class_method (objc_implementation_context, $3);
2730 start_method_def ($3);
2731 objc_method_context = $3;
2735 continue_method_def ();
2739 finish_method_def ();
2740 objc_method_context = NULL_TREE;
2745 remember_protocol_qualifiers ();
2746 if (objc_implementation_context)
2747 objc_inherit_code = INSTANCE_METHOD_DECL;
2749 fatal ("method definition not in class context");
2753 forget_protocol_qualifiers ();
2754 add_instance_method (objc_implementation_context, $3);
2755 start_method_def ($3);
2756 objc_method_context = $3;
2760 continue_method_def ();
2764 finish_method_def ();
2765 objc_method_context = NULL_TREE;
2769 /* the reason for the strange actions in this rule
2770 is so that notype_initdecls when reached via datadef
2771 can find a valid list of type and sc specs in $0. */
2775 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2778 methodprotolist2: /* eliminates a shift/reduce conflict */
2781 | methodprotolist2 methodproto
2782 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2793 /* Remember protocol qualifiers in prototypes. */
2794 remember_protocol_qualifiers ();
2795 objc_inherit_code = CLASS_METHOD_DECL;
2799 /* Forget protocol qualifiers here. */
2800 forget_protocol_qualifiers ();
2801 add_class_method (objc_interface_context, $3);
2807 /* Remember protocol qualifiers in prototypes. */
2808 remember_protocol_qualifiers ();
2809 objc_inherit_code = INSTANCE_METHOD_DECL;
2813 /* Forget protocol qualifiers here. */
2814 forget_protocol_qualifiers ();
2815 add_instance_method (objc_interface_context, $3);
2821 '(' typename ')' unaryselector
2823 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2828 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2831 | '(' typename ')' keywordselector optparmlist
2833 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2836 | keywordselector optparmlist
2838 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2842 /* "optarglist" assumes that start_method_def has already been called...
2843 if it is not, the "xdecls" will not be placed in the proper scope */
2850 /* to get around the following situation: "int foo (int a) int b; {}" that
2851 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2866 typed_declspecs setspecs myparms ';'
2867 { current_declspecs = TREE_VALUE (declspec_stack);
2868 prefix_attributes = TREE_PURPOSE (declspec_stack);
2869 declspec_stack = TREE_CHAIN (declspec_stack);
2870 resume_momentary ($2); }
2871 | typed_declspecs ';'
2872 { shadow_tag ($1); }
2874 { pedwarn ("empty declaration"); }
2879 { push_parm_decl ($1); }
2880 | myparms ',' myparm
2881 { push_parm_decl ($3); }
2884 /* A single parameter declaration or parameter type name,
2885 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2888 parm_declarator maybe_attribute
2889 { $$ = build_tree_list (build_tree_list (current_declspecs,
2891 build_tree_list (prefix_attributes,
2893 | notype_declarator maybe_attribute
2894 { $$ = build_tree_list (build_tree_list (current_declspecs,
2896 build_tree_list (prefix_attributes,
2898 | absdcl maybe_attribute
2899 { $$ = build_tree_list (build_tree_list (current_declspecs,
2901 build_tree_list (prefix_attributes,
2912 /* oh what a kludge! */
2921 /* returns a tree list node generated by get_parm_info */
2934 | keywordselector keyworddecl
2936 $$ = chainon ($1, $2);
2948 ENUM { $$ = get_identifier (token_buffer); }
2949 | STRUCT { $$ = get_identifier (token_buffer); }
2950 | UNION { $$ = get_identifier (token_buffer); }
2951 | IF { $$ = get_identifier (token_buffer); }
2952 | ELSE { $$ = get_identifier (token_buffer); }
2953 | WHILE { $$ = get_identifier (token_buffer); }
2954 | DO { $$ = get_identifier (token_buffer); }
2955 | FOR { $$ = get_identifier (token_buffer); }
2956 | SWITCH { $$ = get_identifier (token_buffer); }
2957 | CASE { $$ = get_identifier (token_buffer); }
2958 | DEFAULT { $$ = get_identifier (token_buffer); }
2959 | BREAK { $$ = get_identifier (token_buffer); }
2960 | CONTINUE { $$ = get_identifier (token_buffer); }
2961 | RETURN { $$ = get_identifier (token_buffer); }
2962 | GOTO { $$ = get_identifier (token_buffer); }
2963 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2964 | SIZEOF { $$ = get_identifier (token_buffer); }
2965 | TYPEOF { $$ = get_identifier (token_buffer); }
2966 | ALIGNOF { $$ = get_identifier (token_buffer); }
2967 | TYPESPEC | TYPE_QUAL
2971 selector ':' '(' typename ')' identifier
2973 $$ = build_keyword_decl ($1, $4, $6);
2976 | selector ':' identifier
2978 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2981 | ':' '(' typename ')' identifier
2983 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2988 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2999 | keywordarglist keywordarg
3001 $$ = chainon ($1, $2);
3009 if (TREE_CHAIN ($1) == NULL_TREE)
3010 /* just return the expr., remove a level of indirection */
3011 $$ = TREE_VALUE ($1);
3013 /* we have a comma expr., we will collapse later */
3019 selector ':' keywordexpr
3021 $$ = build_tree_list ($1, $3);
3025 $$ = build_tree_list (NULL_TREE, $2);
3033 $$ = get_class_reference ($1);
3039 { objc_receiver_context = 1; }
3041 { objc_receiver_context = 0; }
3044 $$ = build_tree_list ($3, $5);
3055 | keywordnamelist keywordname
3057 $$ = chainon ($1, $2);
3064 $$ = build_tree_list ($1, NULL_TREE);
3068 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3073 SELECTOR '(' selectorarg ')'
3080 PROTOCOL '(' identifier ')'
3086 /* extension to support C-structures in the archiver */
3089 ENCODE '(' typename ')'
3091 $$ = groktypename ($3);