1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996,
3 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* This file defines the grammar of C and that of Objective C.
23 ifobjc ... end ifobjc conditionals contain code for Objective C only.
24 ifc ... end ifc conditionals contain code for C only.
25 Sed commands in Makefile.in are used to convert this file into
26 c-parse.y and into objc-parse.y. */
28 /* To whomever it may concern: I have heard that such a thing was once
29 written by AT&T, but I have never seen it. */
51 #ifdef MULTIBYTE_CHARS
59 /* Since parsers are distinct for each language, put the language string
62 const char * const language_string = "GNU Obj-C";
65 const char * const language_string = "GNU C";
68 /* Like YYERROR but do call yyerror. */
69 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
71 /* Cause the `yydebug' variable to be defined. */
77 %union {long itype; tree ttype; enum tree_code code;
78 char *filename; int lineno; int ends_in_label; }
80 /* All identifiers that are not reserved words
81 and are not declared typedefs in the current block */
84 /* All identifiers that are declared typedefs in the current block.
85 In some contexts, they are treated just like IDENTIFIER,
86 but they can also serve as typespecs in declarations. */
89 /* Reserved words that specify storage class.
90 yylval contains an IDENTIFIER_NODE which indicates which one. */
93 /* Reserved words that specify type.
94 yylval contains an IDENTIFIER_NODE which indicates which one. */
97 /* Reserved words that qualify type: "const", "volatile", or "restrict".
98 yylval contains an IDENTIFIER_NODE which indicates which one. */
101 /* Character or numeric constants.
102 yylval is the node for the constant. */
105 /* String constants in raw form.
106 yylval is a STRING_CST node. */
109 /* "...", used for functions with variable arglists. */
112 /* the reserved words */
113 /* SCO include files test "ASM", so use something else. */
114 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
115 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
116 %token ATTRIBUTE EXTENSION LABEL
117 %token REALPART IMAGPART VA_ARG
119 /* Used in c-lex.c for parsing pragmas. */
122 /* Add precedence rules to solve dangling else s/r conflict */
126 /* Define the operator tokens and their precedences.
127 The value is an integer because, if used, it is the tree code
128 to use in the expression made from the operator. */
130 %right <code> ASSIGN '='
131 %right <code> '?' ':'
137 %left <code> EQCOMPARE
138 %left <code> ARITHCOMPARE
139 %left <code> LSHIFT RSHIFT
141 %left <code> '*' '/' '%'
142 %right <code> UNARY PLUSPLUS MINUSMINUS
144 %left <code> POINTSAT '.' '(' '['
146 /* The Objective-C keywords. These are included in C and in
147 Objective C, so that the token codes are the same in both. */
148 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
149 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
151 /* Objective-C string constants in raw form.
152 yylval is an OBJC_STRING_CST node. */
158 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
159 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
160 %type <ttype> typed_declspecs reserved_declspecs
161 %type <ttype> typed_typespecs reserved_typespecquals
162 %type <ttype> declmods typespec typespecqual_reserved
163 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
164 %type <ttype> declmods_no_prefix_attr
165 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
166 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
167 %type <ttype> init maybeasm
168 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
169 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
170 %type <ttype> any_word extension
172 %type <ttype> compstmt compstmt_nostart compstmt_primary_start
174 %type <ttype> declarator
175 %type <ttype> notype_declarator after_type_declarator
176 %type <ttype> parm_declarator
178 %type <ttype> structsp component_decl_list component_decl_list2
179 %type <ttype> component_decl components component_declarator
180 %type <ttype> enumlist enumerator
181 %type <ttype> struct_head union_head enum_head
182 %type <ttype> typename absdcl absdcl1 type_quals
183 %type <ttype> xexpr parms parm identifiers
185 %type <ttype> parmlist parmlist_1 parmlist_2
186 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
187 %type <ttype> identifiers_or_typenames
189 %type <itype> setspecs
191 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
193 %type <filename> save_filename
194 %type <lineno> save_lineno
197 /* the Objective-C nonterminals */
199 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
200 %type <ttype> methoddecl unaryselector keywordselector selector
201 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
202 %type <ttype> keywordexpr keywordarglist keywordarg
203 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
204 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
205 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
207 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
211 /* Number of statements (loosely speaking) and compound statements
213 static int stmt_count;
214 static int compstmt_count;
216 /* Input file and line number of the end of the body of last simple_if;
217 used by the stmt-rule immediately after simple_if returns. */
218 static char *if_stmt_file;
219 static int if_stmt_line;
221 /* List of types and structure classes of the current declaration. */
222 static tree current_declspecs = NULL_TREE;
223 static tree prefix_attributes = NULL_TREE;
225 /* Stack of saved values of current_declspecs and prefix_attributes. */
226 static tree declspec_stack;
228 /* 1 if we explained undeclared var errors. */
229 static int undeclared_variable_notice;
231 /* For __extension__, save/restore the warning flags which are
232 controlled by __extension__. */
233 #define SAVE_WARN_FLAGS() \
234 build_int_2 (pedantic | (warn_pointer_arith << 1), 0)
235 #define RESTORE_WARN_FLAGS(tval) \
237 int val = TREE_INT_CST_LOW (tval); \
238 pedantic = val & 1; \
239 warn_pointer_arith = (val >> 1) & 1; \
243 /* Objective-C specific information */
245 tree objc_interface_context;
246 tree objc_implementation_context;
247 tree objc_method_context;
248 tree objc_ivar_chain;
249 tree objc_ivar_context;
250 enum tree_code objc_inherit_code;
251 int objc_receiver_context;
252 int objc_public_flag;
256 /* Tell yyparse how to print a token's value, if yydebug is set. */
258 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
259 extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
261 /* Add GC roots for variables local to this file. */
265 ggc_add_tree_root (&declspec_stack, 1);
266 ggc_add_tree_root (¤t_declspecs, 1);
267 ggc_add_tree_root (&prefix_attributes, 1);
275 pedwarn ("ANSI C forbids an empty source file");
280 /* In case there were missing closebraces,
281 get us back to the global binding level. */
282 while (! global_bindings_p ())
288 /* the reason for the strange actions in this rule
289 is so that notype_initdecls when reached via datadef
290 can find a valid list of type and sc specs in $0. */
293 {$<ttype>$ = NULL_TREE; } extdef
294 | extdefs {$<ttype>$ = NULL_TREE; } extdef
303 | ASM_KEYWORD '(' expr ')' ';'
305 if ((TREE_CODE ($3) == ADDR_EXPR
306 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
307 || TREE_CODE ($3) == STRING_CST)
310 error ("argument of `asm' is not a constant string"); }
312 { RESTORE_WARN_FLAGS ($1); }
316 setspecs notype_initdecls ';'
318 error ("ANSI C forbids data definition with no type or storage class");
319 else if (!flag_traditional)
320 warning ("data definition has no type or storage class");
322 current_declspecs = TREE_VALUE (declspec_stack);
323 prefix_attributes = TREE_PURPOSE (declspec_stack);
324 declspec_stack = TREE_CHAIN (declspec_stack); }
325 | declmods setspecs notype_initdecls ';'
326 { current_declspecs = TREE_VALUE (declspec_stack);
327 prefix_attributes = TREE_PURPOSE (declspec_stack);
328 declspec_stack = TREE_CHAIN (declspec_stack); }
329 | typed_declspecs setspecs initdecls ';'
330 { current_declspecs = TREE_VALUE (declspec_stack);
331 prefix_attributes = TREE_PURPOSE (declspec_stack);
332 declspec_stack = TREE_CHAIN (declspec_stack); }
334 { pedwarn ("empty declaration"); }
335 | typed_declspecs ';'
341 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
345 typed_declspecs setspecs declarator
346 { if (! start_function (current_declspecs, $3,
347 prefix_attributes, NULL_TREE))
349 reinit_parse_for_function (); }
351 { store_parm_decls (); }
353 { finish_function (0);
354 current_declspecs = TREE_VALUE (declspec_stack);
355 prefix_attributes = TREE_PURPOSE (declspec_stack);
356 declspec_stack = TREE_CHAIN (declspec_stack); }
357 | 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 | declmods setspecs notype_declarator
362 { if (! start_function (current_declspecs, $3,
363 prefix_attributes, NULL_TREE))
365 reinit_parse_for_function (); }
367 { store_parm_decls (); }
369 { finish_function (0);
370 current_declspecs = TREE_VALUE (declspec_stack);
371 prefix_attributes = TREE_PURPOSE (declspec_stack);
372 declspec_stack = TREE_CHAIN (declspec_stack); }
373 | declmods setspecs notype_declarator error
374 { current_declspecs = TREE_VALUE (declspec_stack);
375 prefix_attributes = TREE_PURPOSE (declspec_stack);
376 declspec_stack = TREE_CHAIN (declspec_stack); }
377 | setspecs notype_declarator
378 { if (! start_function (NULL_TREE, $2,
379 prefix_attributes, NULL_TREE))
381 reinit_parse_for_function (); }
383 { store_parm_decls (); }
385 { finish_function (0);
386 current_declspecs = TREE_VALUE (declspec_stack);
387 prefix_attributes = TREE_PURPOSE (declspec_stack);
388 declspec_stack = TREE_CHAIN (declspec_stack); }
389 | setspecs notype_declarator error
390 { current_declspecs = TREE_VALUE (declspec_stack);
391 prefix_attributes = TREE_PURPOSE (declspec_stack);
392 declspec_stack = TREE_CHAIN (declspec_stack); }
407 { $$ = NEGATE_EXPR; }
409 { $$ = CONVERT_EXPR; }
411 { $$ = PREINCREMENT_EXPR; }
413 { $$ = PREDECREMENT_EXPR; }
415 { $$ = BIT_NOT_EXPR; }
417 { $$ = TRUTH_NOT_EXPR; }
420 expr: nonnull_exprlist
421 { $$ = build_compound_expr ($1); }
432 { $$ = build_tree_list (NULL_TREE, $1); }
433 | nonnull_exprlist ',' expr_no_commas
434 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
439 | '*' cast_expr %prec UNARY
440 { $$ = build_indirect_ref ($2, "unary *"); }
441 /* __extension__ turns off -pedantic for following primary. */
442 | extension cast_expr %prec UNARY
444 RESTORE_WARN_FLAGS ($1); }
445 | unop cast_expr %prec UNARY
446 { $$ = build_unary_op ($1, $2, 0);
447 overflow_warning ($$); }
448 /* Refer to the address of a label as a pointer. */
450 { tree label = lookup_label ($2);
452 pedwarn ("ANSI C forbids `&&'");
454 $$ = null_pointer_node;
457 TREE_USED (label) = 1;
458 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
459 TREE_CONSTANT ($$) = 1;
462 /* This seems to be impossible on some machines, so let's turn it off.
463 You can use __builtin_next_arg to find the anonymous stack args.
465 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
466 $$ = error_mark_node;
467 if (TREE_VALUE (tree_last (types)) == void_type_node)
468 error ("`&...' used in function with fixed number of arguments");
472 pedwarn ("ANSI C forbids `&...'");
473 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
474 $$ = build_unary_op (ADDR_EXPR, $$, 0);
477 | sizeof unary_expr %prec UNARY
479 if (TREE_CODE ($2) == COMPONENT_REF
480 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
481 error ("`sizeof' applied to a bit-field");
482 $$ = c_sizeof (TREE_TYPE ($2)); }
483 | sizeof '(' typename ')' %prec HYPERUNARY
485 $$ = c_sizeof (groktypename ($3)); }
486 | alignof unary_expr %prec UNARY
488 $$ = c_alignof_expr ($2); }
489 | alignof '(' typename ')' %prec HYPERUNARY
491 $$ = c_alignof (groktypename ($3)); }
492 | REALPART cast_expr %prec UNARY
493 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
494 | IMAGPART cast_expr %prec UNARY
495 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
496 | VA_ARG '(' expr_no_commas ',' typename ')'
497 { $$ = build_va_arg ($3, groktypename ($5)); }
501 SIZEOF { skip_evaluation++; }
505 ALIGNOF { skip_evaluation++; }
510 | '(' typename ')' cast_expr %prec UNARY
511 { tree type = groktypename ($2);
512 $$ = build_c_cast (type, $4); }
513 | '(' typename ')' '{'
514 { start_init (NULL_TREE, NULL, 0);
515 $2 = groktypename ($2);
516 really_start_incremental_init ($2); }
517 initlist_maybe_comma '}' %prec UNARY
519 tree result = pop_init_level (0);
523 if (pedantic && ! flag_isoc99)
524 pedwarn ("ANSI C forbids constructor expressions");
525 if (TYPE_NAME (type) != 0)
527 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
528 name = IDENTIFIER_POINTER (TYPE_NAME (type));
530 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
535 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
537 int failure = complete_array_type (type, $$, 1);
546 | expr_no_commas '+' expr_no_commas
547 { $$ = parser_build_binary_op ($2, $1, $3); }
548 | expr_no_commas '-' expr_no_commas
549 { $$ = parser_build_binary_op ($2, $1, $3); }
550 | expr_no_commas '*' expr_no_commas
551 { $$ = parser_build_binary_op ($2, $1, $3); }
552 | expr_no_commas '/' expr_no_commas
553 { $$ = parser_build_binary_op ($2, $1, $3); }
554 | expr_no_commas '%' expr_no_commas
555 { $$ = parser_build_binary_op ($2, $1, $3); }
556 | expr_no_commas LSHIFT expr_no_commas
557 { $$ = parser_build_binary_op ($2, $1, $3); }
558 | expr_no_commas RSHIFT expr_no_commas
559 { $$ = parser_build_binary_op ($2, $1, $3); }
560 | expr_no_commas ARITHCOMPARE expr_no_commas
561 { $$ = parser_build_binary_op ($2, $1, $3); }
562 | expr_no_commas EQCOMPARE expr_no_commas
563 { $$ = parser_build_binary_op ($2, $1, $3); }
564 | expr_no_commas '&' expr_no_commas
565 { $$ = parser_build_binary_op ($2, $1, $3); }
566 | expr_no_commas '|' expr_no_commas
567 { $$ = parser_build_binary_op ($2, $1, $3); }
568 | expr_no_commas '^' expr_no_commas
569 { $$ = parser_build_binary_op ($2, $1, $3); }
570 | expr_no_commas ANDAND
571 { $1 = truthvalue_conversion (default_conversion ($1));
572 skip_evaluation += $1 == boolean_false_node; }
574 { skip_evaluation -= $1 == boolean_false_node;
575 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
576 | expr_no_commas OROR
577 { $1 = truthvalue_conversion (default_conversion ($1));
578 skip_evaluation += $1 == boolean_true_node; }
580 { skip_evaluation -= $1 == boolean_true_node;
581 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
583 { $1 = truthvalue_conversion (default_conversion ($1));
584 skip_evaluation += $1 == boolean_false_node; }
586 { skip_evaluation += (($1 == boolean_true_node)
587 - ($1 == boolean_false_node)); }
589 { skip_evaluation -= $1 == boolean_true_node;
590 $$ = build_conditional_expr ($1, $4, $7); }
593 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
594 /* Make sure first operand is calculated only once. */
595 $<ttype>2 = save_expr ($1);
596 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
597 skip_evaluation += $1 == boolean_true_node; }
599 { skip_evaluation -= $1 == boolean_true_node;
600 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
601 | expr_no_commas '=' expr_no_commas
603 $$ = build_modify_expr ($1, NOP_EXPR, $3);
604 class = TREE_CODE_CLASS (TREE_CODE ($$));
605 if (class == 'e' || class == '1'
606 || class == '2' || class == '<')
607 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
609 | expr_no_commas ASSIGN expr_no_commas
611 $$ = build_modify_expr ($1, $2, $3);
612 /* This inhibits warnings in truthvalue_conversion. */
613 class = TREE_CODE_CLASS (TREE_CODE ($$));
614 if (class == 'e' || class == '1'
615 || class == '2' || class == '<')
616 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
624 if (!$$ || $$ == error_mark_node)
626 if (yychar == YYEMPTY)
633 if (objc_receiver_context
634 && ! (objc_receiver_context
635 && strcmp (IDENTIFIER_POINTER ($1), "super")))
636 /* we have a message to super */
637 $$ = get_super_receiver ();
638 else if (objc_method_context
639 && (decl = is_ivar (objc_ivar_chain, $1)))
641 if (is_private (decl))
642 $$ = error_mark_node;
644 $$ = build_ivar_reference ($1);
649 /* Ordinary implicit function declaration. */
650 $$ = implicitly_declare ($1);
651 assemble_external ($$);
655 else if (current_function_decl == 0)
657 error ("`%s' undeclared here (not in a function)",
658 IDENTIFIER_POINTER ($1));
659 $$ = error_mark_node;
666 if (objc_receiver_context
667 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
668 /* we have a message to super */
669 $$ = get_super_receiver ();
670 else if (objc_method_context
671 && (decl = is_ivar (objc_ivar_chain, $1)))
673 if (is_private (decl))
674 $$ = error_mark_node;
676 $$ = build_ivar_reference ($1);
681 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
682 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
684 error ("`%s' undeclared (first use in this function)",
685 IDENTIFIER_POINTER ($1));
687 if (! undeclared_variable_notice)
689 error ("(Each undeclared identifier is reported only once");
690 error ("for each function it appears in.)");
691 undeclared_variable_notice = 1;
694 $$ = error_mark_node;
695 /* Prevent repeated error messages. */
696 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
697 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
701 else if (TREE_TYPE ($$) == error_mark_node)
702 $$ = error_mark_node;
703 else if (C_DECL_ANTICIPATED ($$))
705 /* The first time we see a build-in function used,
706 if it has not been declared. */
707 C_DECL_ANTICIPATED ($$) = 0;
708 if (yychar == YYEMPTY)
712 /* Omit the implicit declaration we
713 would ordinarily do, so we don't lose
714 the actual built in type.
715 But print a diagnostic for the mismatch. */
717 if (objc_method_context
718 && is_ivar (objc_ivar_chain, $1))
719 error ("Instance variable `%s' implicitly declared as function",
720 IDENTIFIER_POINTER (DECL_NAME ($$)));
723 if (TREE_CODE ($$) != FUNCTION_DECL)
724 error ("`%s' implicitly declared as function",
725 IDENTIFIER_POINTER (DECL_NAME ($$)));
726 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
727 != TYPE_MODE (integer_type_node))
728 && (TREE_TYPE (TREE_TYPE ($$))
730 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
731 IDENTIFIER_POINTER (DECL_NAME ($$)));
732 /* If it really returns void, change that to int. */
733 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
735 = build_function_type (integer_type_node,
736 TYPE_ARG_TYPES (TREE_TYPE ($$)));
739 pedwarn ("built-in function `%s' used without declaration",
740 IDENTIFIER_POINTER (DECL_NAME ($$)));
742 /* Do what we would ordinarily do when a fn is used. */
743 assemble_external ($$);
748 assemble_external ($$);
751 /* we have a definition - still check if iVariable */
753 if (!objc_receiver_context
754 || (objc_receiver_context
755 && strcmp (IDENTIFIER_POINTER ($1), "super")))
759 if (objc_method_context
760 && (decl = is_ivar (objc_ivar_chain, $1)))
762 if (IDENTIFIER_LOCAL_VALUE ($1))
763 warning ("local declaration of `%s' hides instance variable",
764 IDENTIFIER_POINTER ($1));
767 if (is_private (decl))
768 $$ = error_mark_node;
770 $$ = build_ivar_reference ($1);
774 else /* we have a message to super */
775 $$ = get_super_receiver ();
779 if (TREE_CODE ($$) == CONST_DECL)
781 $$ = DECL_INITIAL ($$);
782 /* This is to prevent an enum whose value is 0
783 from being considered a null pointer constant. */
784 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
785 TREE_CONSTANT ($$) = 1;
790 { $$ = combine_strings ($1); }
792 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
793 if (class == 'e' || class == '1'
794 || class == '2' || class == '<')
795 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
798 { $$ = error_mark_node; }
799 | compstmt_primary_start compstmt_nostart ')'
802 pedwarn ("ANSI C forbids braced-groups within expressions");
803 pop_iterator_stack ();
805 rtl_exp = expand_end_stmt_expr ($1);
806 /* The statements have side effects, so the group does. */
807 TREE_SIDE_EFFECTS (rtl_exp) = 1;
809 if (TREE_CODE ($2) == BLOCK)
811 /* Make a BIND_EXPR for the BLOCK already made. */
812 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
813 NULL_TREE, rtl_exp, $2);
814 /* Remove the block from the tree at this point.
815 It gets put back at the proper place
816 when the BIND_EXPR is expanded. */
822 | compstmt_primary_start error ')'
824 /* Make sure we call expand_end_stmt_expr. Otherwise
825 we are likely to lose sequences and crash later. */
826 pop_iterator_stack ();
828 expand_end_stmt_expr ($1);
829 $$ = error_mark_node;
831 | primary '(' exprlist ')' %prec '.'
832 { $$ = build_function_call ($1, $3); }
833 | primary '[' expr ']' %prec '.'
834 { $$ = build_array_ref ($1, $3); }
835 | primary '.' identifier
838 if (doing_objc_thang)
840 if (is_public ($1, $3))
841 $$ = build_component_ref ($1, $3);
843 $$ = error_mark_node;
847 $$ = build_component_ref ($1, $3);
849 | primary POINTSAT identifier
851 tree expr = build_indirect_ref ($1, "->");
854 if (doing_objc_thang)
856 if (is_public (expr, $3))
857 $$ = build_component_ref (expr, $3);
859 $$ = error_mark_node;
863 $$ = build_component_ref (expr, $3);
866 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
868 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
871 { $$ = build_message_expr ($1); }
873 { $$ = build_selector_expr ($1); }
875 { $$ = build_protocol_expr ($1); }
877 { $$ = build_encode_expr ($1); }
879 { $$ = build_objc_string_object ($1); }
883 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
887 { $$ = chainon ($1, $2);
889 if (warn_traditional && !in_system_header)
890 warning ("Use of ANSI string concatenation");
896 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
900 | objc_string OBJC_STRING
901 { $$ = chainon ($1, $2); }
905 old_style_parm_decls:
909 /* ... is used here to indicate a varargs function. */
912 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
915 /* The following are analogous to lineno_decl, decls and decl
916 except that they do not allow nested functions.
917 They are used for old-style parm decls. */
919 save_filename save_lineno datadecl
926 | datadecls lineno_datadecl
927 | lineno_datadecl errstmt
930 /* We don't allow prefix attributes here because they cause reduce/reduce
931 conflicts: we can't know whether we're parsing a function decl with
932 attribute suffix, or function defn with attribute prefix on first old
935 typed_declspecs_no_prefix_attr setspecs initdecls ';'
936 { current_declspecs = TREE_VALUE (declspec_stack);
937 prefix_attributes = TREE_PURPOSE (declspec_stack);
938 declspec_stack = TREE_CHAIN (declspec_stack); }
939 | declmods_no_prefix_attr setspecs notype_initdecls ';'
940 { current_declspecs = TREE_VALUE (declspec_stack);
941 prefix_attributes = TREE_PURPOSE (declspec_stack);
942 declspec_stack = TREE_CHAIN (declspec_stack); }
943 | typed_declspecs_no_prefix_attr ';'
944 { shadow_tag_warned ($1, 1);
945 pedwarn ("empty declaration"); }
946 | declmods_no_prefix_attr ';'
947 { pedwarn ("empty declaration"); }
950 /* This combination which saves a lineno before a decl
951 is the normal thing to use, rather than decl itself.
952 This is to avoid shift/reduce conflicts in contexts
953 where statement labels are allowed. */
955 save_filename save_lineno decl
963 | lineno_decl errstmt
966 /* records the type and storage class specs to use for processing
967 the declarators that follow.
968 Maintains a stack of outer-level values of current_declspecs,
969 for the sake of parm declarations nested in function declarators. */
970 setspecs: /* empty */
971 { pending_xref_error ();
972 declspec_stack = tree_cons (prefix_attributes,
975 split_specs_attrs ($<ttype>0,
976 ¤t_declspecs, &prefix_attributes); }
979 /* ??? Yuck. See after_type_declarator. */
980 setattrs: /* empty */
981 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
985 typed_declspecs setspecs initdecls ';'
986 { current_declspecs = TREE_VALUE (declspec_stack);
987 prefix_attributes = TREE_PURPOSE (declspec_stack);
988 declspec_stack = TREE_CHAIN (declspec_stack); }
989 | declmods setspecs notype_initdecls ';'
990 { current_declspecs = TREE_VALUE (declspec_stack);
991 prefix_attributes = TREE_PURPOSE (declspec_stack);
992 declspec_stack = TREE_CHAIN (declspec_stack); }
993 | typed_declspecs setspecs nested_function
994 { current_declspecs = TREE_VALUE (declspec_stack);
995 prefix_attributes = TREE_PURPOSE (declspec_stack);
996 declspec_stack = TREE_CHAIN (declspec_stack); }
997 | declmods setspecs notype_nested_function
998 { current_declspecs = TREE_VALUE (declspec_stack);
999 prefix_attributes = TREE_PURPOSE (declspec_stack);
1000 declspec_stack = TREE_CHAIN (declspec_stack); }
1001 | typed_declspecs ';'
1002 { shadow_tag ($1); }
1004 { pedwarn ("empty declaration"); }
1006 { RESTORE_WARN_FLAGS ($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 initlist_maybe_comma '}'
1246 { $$ = pop_init_level (0); }
1248 { $$ = error_mark_node; }
1251 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1252 initlist_maybe_comma:
1255 pedwarn ("ANSI C forbids empty initializer braces"); }
1256 | initlist1 maybecomma
1261 | initlist1 ',' initelt
1264 /* `initelt' is a single element of an initializer.
1265 It may use braces. */
1267 designator_list '=' initval
1268 | designator initval
1270 { set_init_label ($1); }
1277 { push_init_level (0); }
1278 initlist_maybe_comma '}'
1279 { process_init_element (pop_init_level (0)); }
1281 { process_init_element ($1); }
1287 | designator_list designator
1292 { set_init_label ($2); }
1293 /* These are for labeled elements. The syntax for an array element
1294 initializer conflicts with the syntax for an Objective-C message,
1295 so don't include these productions in the Objective-C grammar. */
1297 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1298 { set_init_index ($2, $4); }
1299 | '[' expr_no_commas ']'
1300 { set_init_index ($2, NULL_TREE); }
1307 pedwarn ("ANSI C forbids nested functions");
1309 push_function_context ();
1310 if (! start_function (current_declspecs, $1,
1311 prefix_attributes, NULL_TREE))
1313 pop_function_context ();
1316 reinit_parse_for_function (); }
1317 old_style_parm_decls
1318 { store_parm_decls (); }
1319 /* This used to use compstmt_or_error.
1320 That caused a bug with input `f(g) int g {}',
1321 where the use of YYERROR1 above caused an error
1322 which then was handled by compstmt_or_error.
1323 There followed a repeated execution of that same rule,
1324 which called YYERROR1 again, and so on. */
1326 { finish_function (1);
1327 pop_function_context (); }
1330 notype_nested_function:
1333 pedwarn ("ANSI C forbids nested functions");
1335 push_function_context ();
1336 if (! start_function (current_declspecs, $1,
1337 prefix_attributes, NULL_TREE))
1339 pop_function_context ();
1342 reinit_parse_for_function (); }
1343 old_style_parm_decls
1344 { store_parm_decls (); }
1345 /* This used to use compstmt_or_error.
1346 That caused a bug with input `f(g) int g {}',
1347 where the use of YYERROR1 above caused an error
1348 which then was handled by compstmt_or_error.
1349 There followed a repeated execution of that same rule,
1350 which called YYERROR1 again, and so on. */
1352 { finish_function (1);
1353 pop_function_context (); }
1356 /* Any kind of declarator (thus, all declarators allowed
1357 after an explicit typespec). */
1360 after_type_declarator
1364 /* A declarator that is allowed only after an explicit typespec. */
1366 after_type_declarator:
1367 '(' after_type_declarator ')'
1369 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1370 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1371 /* | after_type_declarator '(' error ')' %prec '.'
1372 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1373 poplevel (0, 0, 0); } */
1374 | after_type_declarator '[' expr ']' %prec '.'
1375 { $$ = build_nt (ARRAY_REF, $1, $3); }
1376 | after_type_declarator '[' ']' %prec '.'
1377 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1378 | '*' type_quals after_type_declarator %prec UNARY
1379 { $$ = make_pointer_declarator ($2, $3); }
1380 /* ??? Yuck. setattrs is a quick hack. We can't use
1381 prefix_attributes because $1 only applies to this
1382 declarator. We assume setspecs has already been done.
1383 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1384 attributes could be recognized here or in `attributes'). */
1385 | attributes setattrs after_type_declarator
1393 /* Kinds of declarator that can appear in a parameter list
1394 in addition to notype_declarator. This is like after_type_declarator
1395 but does not allow a typedef name in parentheses as an identifier
1396 (because it would conflict with a function with that typedef as arg). */
1399 parm_declarator '(' parmlist_or_identifiers %prec '.'
1400 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1401 /* | parm_declarator '(' error ')' %prec '.'
1402 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1403 poplevel (0, 0, 0); } */
1405 | parm_declarator '[' '*' ']' %prec '.'
1406 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1408 error ("`[*]' in parameter declaration only allowed in ISO C 99");
1411 | parm_declarator '[' expr ']' %prec '.'
1412 { $$ = build_nt (ARRAY_REF, $1, $3); }
1413 | parm_declarator '[' ']' %prec '.'
1414 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1415 | '*' type_quals parm_declarator %prec UNARY
1416 { $$ = make_pointer_declarator ($2, $3); }
1417 /* ??? Yuck. setattrs is a quick hack. We can't use
1418 prefix_attributes because $1 only applies to this
1419 declarator. We assume setspecs has already been done.
1420 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1421 attributes could be recognized here or in `attributes'). */
1422 | attributes setattrs parm_declarator
1427 /* A declarator allowed whether or not there has been
1428 an explicit typespec. These cannot redeclare a typedef-name. */
1431 notype_declarator '(' parmlist_or_identifiers %prec '.'
1432 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1433 /* | notype_declarator '(' error ')' %prec '.'
1434 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1435 poplevel (0, 0, 0); } */
1436 | '(' notype_declarator ')'
1438 | '*' type_quals notype_declarator %prec UNARY
1439 { $$ = make_pointer_declarator ($2, $3); }
1441 | notype_declarator '[' '*' ']' %prec '.'
1442 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1444 error ("`[*]' in parameter declaration only allowed in ISO C 99");
1447 | notype_declarator '[' expr ']' %prec '.'
1448 { $$ = build_nt (ARRAY_REF, $1, $3); }
1449 | notype_declarator '[' ']' %prec '.'
1450 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1451 /* ??? Yuck. setattrs is a quick hack. We can't use
1452 prefix_attributes because $1 only applies to this
1453 declarator. We assume setspecs has already been done.
1454 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1455 attributes could be recognized here or in `attributes'). */
1456 | attributes setattrs notype_declarator
1483 struct_head identifier '{'
1484 { $$ = start_struct (RECORD_TYPE, $2);
1485 /* Start scope of tag before parsing components. */
1487 component_decl_list '}' maybe_attribute
1488 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1489 | struct_head '{' component_decl_list '}' maybe_attribute
1490 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1491 $3, chainon ($1, $5));
1493 | struct_head identifier
1494 { $$ = xref_tag (RECORD_TYPE, $2); }
1495 | union_head identifier '{'
1496 { $$ = start_struct (UNION_TYPE, $2); }
1497 component_decl_list '}' maybe_attribute
1498 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1499 | union_head '{' component_decl_list '}' maybe_attribute
1500 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1501 $3, chainon ($1, $5));
1503 | union_head identifier
1504 { $$ = xref_tag (UNION_TYPE, $2); }
1505 | enum_head identifier '{'
1506 { $$ = start_enum ($2); }
1507 enumlist maybecomma_warn '}' maybe_attribute
1508 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1509 chainon ($1, $8)); }
1511 { $$ = start_enum (NULL_TREE); }
1512 enumlist maybecomma_warn '}' maybe_attribute
1513 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1514 chainon ($1, $7)); }
1515 | enum_head identifier
1516 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1527 { if (pedantic && ! flag_isoc99)
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 | typed_typespecs setspecs save_filename save_lineno maybe_attribute
1581 /* Support for unnamed structs or unions as members of
1582 structs or unions (which is [a] useful and [b] supports
1585 pedwarn ("ANSI C doesn't support unnamed structs/unions");
1587 $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
1588 current_declspecs = TREE_VALUE (declspec_stack);
1589 prefix_attributes = TREE_PURPOSE (declspec_stack);
1590 declspec_stack = TREE_CHAIN (declspec_stack);
1592 | nonempty_type_quals setspecs components
1594 current_declspecs = TREE_VALUE (declspec_stack);
1595 prefix_attributes = TREE_PURPOSE (declspec_stack);
1596 declspec_stack = TREE_CHAIN (declspec_stack); }
1597 | nonempty_type_quals
1599 pedwarn ("ANSI C forbids member declarations with no members");
1604 | extension component_decl
1606 RESTORE_WARN_FLAGS ($1); }
1610 component_declarator
1611 | components ',' component_declarator
1612 { $$ = chainon ($1, $3); }
1615 component_declarator:
1616 save_filename save_lineno declarator maybe_attribute
1617 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1618 decl_attributes ($$, $4, prefix_attributes); }
1619 | save_filename save_lineno
1620 declarator ':' expr_no_commas maybe_attribute
1621 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1622 decl_attributes ($$, $6, prefix_attributes); }
1623 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1624 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1625 decl_attributes ($$, $5, prefix_attributes); }
1628 /* We chain the enumerators in reverse order.
1629 They are put in forward order where enumlist is used.
1630 (The order used to be significant, but no longer is so.
1631 However, we still maintain the order, just to be clean.) */
1635 | enumlist ',' enumerator
1636 { if ($1 == error_mark_node)
1639 $$ = chainon ($3, $1); }
1641 { $$ = error_mark_node; }
1647 { $$ = build_enumerator ($1, NULL_TREE); }
1648 | identifier '=' expr_no_commas
1649 { $$ = build_enumerator ($1, $3); }
1653 typed_typespecs absdcl
1654 { $$ = build_tree_list ($1, $2); }
1655 | nonempty_type_quals absdcl
1656 { $$ = build_tree_list ($1, $2); }
1659 absdcl: /* an absolute declarator */
1665 nonempty_type_quals:
1667 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1668 | nonempty_type_quals TYPE_QUAL
1669 { $$ = tree_cons (NULL_TREE, $2, $1); }
1675 | type_quals TYPE_QUAL
1676 { $$ = tree_cons (NULL_TREE, $2, $1); }
1679 absdcl1: /* a nonempty absolute declarator */
1682 /* `(typedef)1' is `int'. */
1683 | '*' type_quals absdcl1 %prec UNARY
1684 { $$ = make_pointer_declarator ($2, $3); }
1685 | '*' type_quals %prec UNARY
1686 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1687 | absdcl1 '(' parmlist %prec '.'
1688 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1689 | absdcl1 '[' expr ']' %prec '.'
1690 { $$ = build_nt (ARRAY_REF, $1, $3); }
1691 | absdcl1 '[' ']' %prec '.'
1692 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1693 | '(' parmlist %prec '.'
1694 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1695 | '[' expr ']' %prec '.'
1696 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1698 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1699 /* ??? It appears we have to support attributes here, however
1700 using prefix_attributes is wrong. */
1701 | attributes setattrs absdcl1
1705 /* at least one statement, the first of which parses without error. */
1706 /* stmts is used only after decls, so an invalid first statement
1707 is actually regarded as an invalid decl and part of the decls. */
1710 lineno_stmt_or_labels
1713 pedwarn ("ANSI C forbids label at end of compound statement");
1717 lineno_stmt_or_labels:
1718 lineno_stmt_or_label
1719 | lineno_stmt_or_labels lineno_stmt_or_label
1721 | lineno_stmt_or_labels errstmt
1733 pushlevel: /* empty */
1734 { emit_line_note (input_filename, lineno);
1737 expand_start_bindings (0);
1739 if (objc_method_context)
1745 /* Read zero or more forward-declarations for labels
1746 that nested functions can jump to. */
1751 pedwarn ("ANSI C forbids label declarations"); }
1756 | label_decls label_decl
1760 LABEL identifiers_or_typenames ';'
1762 for (link = $2; link; link = TREE_CHAIN (link))
1764 tree label = shadow_label (TREE_VALUE (link));
1765 C_DECLARED_LABEL_FLAG (label) = 1;
1766 declare_nonlocal_label (label);
1771 /* This is the body of a function definition.
1772 It causes syntax errors to ignore to the next openbrace. */
1779 compstmt_start: '{' { compstmt_count++; }
1781 compstmt_nostart: '}'
1782 { $$ = convert (void_type_node, integer_zero_node); }
1783 | pushlevel maybe_label_decls decls xstmts '}'
1784 { emit_line_note (input_filename, lineno);
1785 expand_end_bindings (getdecls (), 1, 0);
1786 $$ = poplevel (1, 1, 0); }
1787 | pushlevel maybe_label_decls error '}'
1788 { emit_line_note (input_filename, lineno);
1789 expand_end_bindings (getdecls (), kept_level_p (), 0);
1790 $$ = poplevel (kept_level_p (), 0, 0); }
1791 | pushlevel maybe_label_decls stmts '}'
1792 { emit_line_note (input_filename, lineno);
1793 expand_end_bindings (getdecls (), kept_level_p (), 0);
1794 $$ = poplevel (kept_level_p (), 0, 0); }
1797 compstmt_primary_start:
1799 { if (current_function_decl == 0)
1801 error ("braced-group within expression allowed only inside a function");
1804 /* We must force a BLOCK for this level
1805 so that, if it is not expanded later,
1806 there is a way to turn off the entire subtree of blocks
1807 that are contained in it. */
1809 push_iterator_stack ();
1810 push_label_level ();
1811 $$ = expand_start_stmt_expr ();
1815 compstmt: compstmt_start compstmt_nostart
1819 /* Value is number of statements counted as of the closeparen. */
1821 if_prefix lineno_labeled_stmt
1822 /* Make sure c_expand_end_cond is run once
1823 for each call to c_expand_start_cond.
1824 Otherwise a crash is likely. */
1830 { emit_line_note ($<filename>-1, $<lineno>0);
1831 c_expand_start_cond (truthvalue_conversion ($3), 0,
1833 $<itype>$ = stmt_count;
1834 if_stmt_file = $<filename>-1;
1835 if_stmt_line = $<lineno>0;
1836 position_after_white_space (); }
1839 /* This is a subroutine of stmt.
1840 It is used twice, once for valid DO statements
1841 and once for catching errors in parsing the end test. */
1846 emit_line_note ($<filename>-1, $<lineno>0);
1847 /* See comment in `while' alternative, above. */
1849 expand_start_loop_continue_elsewhere (1);
1850 position_after_white_space (); }
1851 lineno_labeled_stmt WHILE
1852 { expand_loop_continue_here (); }
1856 { $$ = input_filename; }
1863 lineno_labeled_stmt:
1864 save_filename save_lineno stmt
1866 /* | save_filename save_lineno error
1869 | save_filename save_lineno label lineno_labeled_stmt
1873 lineno_stmt_or_label:
1874 save_filename save_lineno stmt_or_label
1885 /* Parse a single real statement, not including any labels. */
1892 emit_line_note ($<filename>-1, $<lineno>0);
1893 /* It appears that this should not be done--that a non-lvalue array
1894 shouldn't get an error if the value isn't used.
1895 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1896 if it appears as a top-level expression,
1897 but says nothing about non-lvalue arrays. */
1899 /* Call default_conversion to get an error
1900 on referring to a register array if pedantic. */
1901 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1902 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1903 $1 = default_conversion ($1);
1905 iterator_expand ($1); }
1907 { c_expand_start_else ();
1908 $<itype>1 = stmt_count;
1909 position_after_white_space (); }
1911 { c_expand_end_cond ();
1912 if (extra_warnings && stmt_count == $<itype>1)
1913 warning ("empty body in an else-statement"); }
1914 | simple_if %prec IF
1915 { c_expand_end_cond ();
1916 /* This warning is here instead of in simple_if, because we
1917 do not want a warning if an empty if is followed by an
1918 else statement. Increment stmt_count so we don't
1919 give a second error if this is a nested `if'. */
1920 if (extra_warnings && stmt_count++ == $<itype>1)
1921 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1922 "empty body in an if-statement"); }
1923 /* Make sure c_expand_end_cond is run once
1924 for each call to c_expand_start_cond.
1925 Otherwise a crash is likely. */
1926 | simple_if ELSE error
1927 { c_expand_end_cond (); }
1930 emit_line_note ($<filename>-1, $<lineno>0);
1931 /* The emit_nop used to come before emit_line_note,
1932 but that made the nop seem like part of the preceding line.
1933 And that was confusing when the preceding line was
1934 inside of an if statement and was not really executed.
1935 I think it ought to work to put the nop after the line number.
1936 We will see. --rms, July 15, 1991. */
1939 { /* Don't start the loop till we have succeeded
1940 in parsing the end test. This is to make sure
1941 that we end every loop we start. */
1942 expand_start_loop (1);
1943 emit_line_note (input_filename, lineno);
1944 expand_exit_loop_if_false (NULL_PTR,
1945 truthvalue_conversion ($4));
1946 position_after_white_space (); }
1948 { expand_end_loop (); }
1951 { emit_line_note (input_filename, lineno);
1952 expand_exit_loop_if_false (NULL_PTR,
1953 truthvalue_conversion ($3));
1954 expand_end_loop (); }
1955 /* This rule is needed to make sure we end every loop we start. */
1956 | do_stmt_start error
1957 { expand_end_loop (); }
1961 emit_line_note ($<filename>-1, $<lineno>0);
1962 /* See comment in `while' alternative, above. */
1964 if ($3) c_expand_expr_stmt ($3);
1965 /* Next step is to call expand_start_loop_continue_elsewhere,
1966 but wait till after we parse the entire for (...).
1967 Otherwise, invalid input might cause us to call that
1968 fn without calling expand_end_loop. */
1971 /* Can't emit now; wait till after expand_start_loop... */
1972 { $<lineno>7 = lineno;
1973 $<filename>$ = input_filename; }
1976 /* Start the loop. Doing this after parsing
1977 all the expressions ensures we will end the loop. */
1978 expand_start_loop_continue_elsewhere (1);
1979 /* Emit the end-test, with a line number. */
1980 emit_line_note ($<filename>8, $<lineno>7);
1982 expand_exit_loop_if_false (NULL_PTR,
1983 truthvalue_conversion ($6));
1984 $<lineno>7 = lineno;
1985 $<filename>8 = input_filename;
1986 position_after_white_space (); }
1988 { /* Emit the increment expression, with a line number. */
1989 emit_line_note ($<filename>8, $<lineno>7);
1990 expand_loop_continue_here ();
1992 c_expand_expr_stmt ($9);
1993 expand_end_loop (); }
1994 | SWITCH '(' expr ')'
1996 emit_line_note ($<filename>-1, $<lineno>0);
1997 c_expand_start_case ($3);
1998 position_after_white_space (); }
2000 { expand_end_case ($3); }
2003 emit_line_note ($<filename>-1, $<lineno>0);
2004 if ( ! expand_exit_something ())
2005 error ("break statement not within loop or switch"); }
2008 emit_line_note ($<filename>-1, $<lineno>0);
2009 if (! expand_continue_loop (NULL_PTR))
2010 error ("continue statement not within a loop"); }
2013 emit_line_note ($<filename>-1, $<lineno>0);
2014 c_expand_return (NULL_TREE); }
2017 emit_line_note ($<filename>-1, $<lineno>0);
2018 c_expand_return ($2); }
2019 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2021 emit_line_note ($<filename>-1, $<lineno>0);
2023 if ((TREE_CODE ($4) == ADDR_EXPR
2024 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
2025 || TREE_CODE ($4) == STRING_CST)
2028 error ("argument of `asm' is not a constant string"); }
2029 /* This is the case with just output operands. */
2030 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2032 emit_line_note ($<filename>-1, $<lineno>0);
2033 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2034 $2 == ridpointers[(int)RID_VOLATILE],
2035 input_filename, lineno); }
2036 /* This is the case with input operands as well. */
2037 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2039 emit_line_note ($<filename>-1, $<lineno>0);
2040 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2041 $2 == ridpointers[(int)RID_VOLATILE],
2042 input_filename, lineno); }
2043 /* This is the case with clobbered registers as well. */
2044 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2045 asm_operands ':' asm_clobbers ')' ';'
2047 emit_line_note ($<filename>-1, $<lineno>0);
2048 c_expand_asm_operands ($4, $6, $8, $10,
2049 $2 == ridpointers[(int)RID_VOLATILE],
2050 input_filename, lineno); }
2051 | GOTO identifier ';'
2054 emit_line_note ($<filename>-1, $<lineno>0);
2055 decl = lookup_label ($2);
2058 TREE_USED (decl) = 1;
2064 pedwarn ("ANSI C forbids `goto *expr;'");
2066 emit_line_note ($<filename>-1, $<lineno>0);
2067 expand_computed_goto (convert (ptr_type_node, $3)); }
2072 all_iter_stmt_simple
2073 /* | all_iter_stmt_with_decl */
2076 all_iter_stmt_simple:
2079 /* The value returned by this action is */
2080 /* 1 if everything is OK */
2081 /* 0 in case of error or already bound iterator */
2084 if (TREE_CODE ($3) != VAR_DECL)
2085 error ("invalid `for (ITERATOR)' syntax");
2086 else if (! ITERATOR_P ($3))
2087 error ("`%s' is not an iterator",
2088 IDENTIFIER_POINTER (DECL_NAME ($3)));
2089 else if (ITERATOR_BOUND_P ($3))
2090 error ("`for (%s)' inside expansion of same iterator",
2091 IDENTIFIER_POINTER (DECL_NAME ($3)));
2095 iterator_for_loop_start ($3);
2101 iterator_for_loop_end ($3);
2104 /* This really should allow any kind of declaration,
2105 for generality. Fix it before turning it back on.
2107 all_iter_stmt_with_decl:
2108 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2110 */ /* The value returned by this action is */
2111 /* 1 if everything is OK */
2112 /* 0 in case of error or already bound iterator */
2114 iterator_for_loop_start ($6);
2118 iterator_for_loop_end ($6);
2119 emit_line_note (input_filename, lineno);
2120 expand_end_bindings (getdecls (), 1, 0);
2121 $<ttype>$ = poplevel (1, 1, 0);
2125 /* Any kind of label, including jump labels and case labels.
2126 ANSI C accepts labels only before statements, but we allow them
2127 also at the end of a compound statement. */
2129 label: CASE expr_no_commas ':'
2130 { register tree value = check_case_value ($2);
2132 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2136 if (value != error_mark_node)
2141 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2142 pedwarn ("label must have integral type in ANSI C");
2144 success = pushcase (value, convert_and_check,
2148 error ("case label not within a switch statement");
2149 else if (success == 2)
2151 error ("duplicate case value");
2152 error_with_decl (duplicate, "this is the first entry for that value");
2154 else if (success == 3)
2155 warning ("case value out of range");
2156 else if (success == 5)
2157 error ("case label within scope of cleanup or variable array");
2159 position_after_white_space (); }
2160 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2161 { register tree value1 = check_case_value ($2);
2162 register tree value2 = check_case_value ($4);
2164 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2167 pedwarn ("ANSI C forbids case ranges");
2170 if (value1 != error_mark_node && value2 != error_mark_node)
2173 int success = pushcase_range (value1, value2,
2174 convert_and_check, label,
2177 error ("case label not within a switch statement");
2178 else if (success == 2)
2180 error ("duplicate case value");
2181 error_with_decl (duplicate, "this is the first entry for that value");
2183 else if (success == 3)
2184 warning ("case value out of range");
2185 else if (success == 4)
2186 warning ("empty case range");
2187 else if (success == 5)
2188 error ("case label within scope of cleanup or variable array");
2190 position_after_white_space (); }
2195 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2196 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2199 error ("default label not within a switch statement");
2200 else if (success == 2)
2202 error ("multiple default labels in one switch");
2203 error_with_decl (duplicate, "this is the first default label");
2205 position_after_white_space (); }
2206 | identifier ':' maybe_attribute
2207 { tree label = define_label (input_filename, lineno, $1);
2212 expand_label (label);
2213 decl_attributes (label, $3, NULL_TREE);
2215 position_after_white_space (); }
2218 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2222 { emit_line_note (input_filename, lineno);
2225 { emit_line_note (input_filename, lineno); }
2234 /* These are the operands other than the first string and colon
2235 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2236 asm_operands: /* empty */
2238 | nonnull_asm_operands
2241 nonnull_asm_operands:
2243 | nonnull_asm_operands ',' asm_operand
2244 { $$ = chainon ($1, $3); }
2249 { $$ = build_tree_list ($1, $3); }
2254 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2255 | asm_clobbers ',' string
2256 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2259 /* This is what appears inside the parens in a function declarator.
2260 Its value is a list of ..._TYPE nodes. */
2263 clear_parm_order ();
2264 declare_parm_level (0); }
2267 parmlist_tags_warning ();
2268 poplevel (0, 0, 0); }
2276 pedwarn ("ANSI C forbids forward parameter declarations");
2277 /* Mark the forward decls as such. */
2278 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2279 TREE_ASM_WRITTEN (parm) = 1;
2280 clear_parm_order (); }
2284 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2287 /* This is what appears inside the parens in a function declarator.
2288 Is value is represented in the format that grokdeclarator expects. */
2289 parmlist_2: /* empty */
2290 { $$ = get_parm_info (0); }
2292 { $$ = get_parm_info (0);
2293 /* Gcc used to allow this as an extension. However, it does
2294 not work for all targets, and thus has been disabled.
2295 Also, since func (...) and func () are indistinguishable,
2296 it caused problems with the code in expand_builtin which
2297 tries to verify that BUILT_IN_NEXT_ARG is being used
2299 error ("ANSI C requires a named argument before `...'");
2302 { $$ = get_parm_info (1); }
2303 | parms ',' ELLIPSIS
2304 { $$ = get_parm_info (0); }
2309 { push_parm_decl ($1); }
2311 { push_parm_decl ($3); }
2314 /* A single parameter declaration or parameter type name,
2315 as found in a parmlist. */
2317 typed_declspecs setspecs parm_declarator maybe_attribute
2318 { $$ = build_tree_list (build_tree_list (current_declspecs,
2320 build_tree_list (prefix_attributes,
2322 current_declspecs = TREE_VALUE (declspec_stack);
2323 prefix_attributes = TREE_PURPOSE (declspec_stack);
2324 declspec_stack = TREE_CHAIN (declspec_stack); }
2325 | typed_declspecs setspecs notype_declarator maybe_attribute
2326 { $$ = build_tree_list (build_tree_list (current_declspecs,
2328 build_tree_list (prefix_attributes,
2330 current_declspecs = TREE_VALUE (declspec_stack);
2331 prefix_attributes = TREE_PURPOSE (declspec_stack);
2332 declspec_stack = TREE_CHAIN (declspec_stack); }
2333 | typed_declspecs setspecs absdcl maybe_attribute
2334 { $$ = build_tree_list (build_tree_list (current_declspecs,
2336 build_tree_list (prefix_attributes,
2338 current_declspecs = TREE_VALUE (declspec_stack);
2339 prefix_attributes = TREE_PURPOSE (declspec_stack);
2340 declspec_stack = TREE_CHAIN (declspec_stack); }
2341 | declmods setspecs notype_declarator maybe_attribute
2342 { $$ = build_tree_list (build_tree_list (current_declspecs,
2344 build_tree_list (prefix_attributes,
2346 current_declspecs = TREE_VALUE (declspec_stack);
2347 prefix_attributes = TREE_PURPOSE (declspec_stack);
2348 declspec_stack = TREE_CHAIN (declspec_stack); }
2350 | declmods setspecs absdcl maybe_attribute
2351 { $$ = build_tree_list (build_tree_list (current_declspecs,
2353 build_tree_list (prefix_attributes,
2355 current_declspecs = TREE_VALUE (declspec_stack);
2356 prefix_attributes = TREE_PURPOSE (declspec_stack);
2357 declspec_stack = TREE_CHAIN (declspec_stack); }
2360 /* This is used in a function definition
2361 where either a parmlist or an identifier list is ok.
2362 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2363 parmlist_or_identifiers:
2365 clear_parm_order ();
2366 declare_parm_level (1); }
2367 parmlist_or_identifiers_1
2369 parmlist_tags_warning ();
2370 poplevel (0, 0, 0); }
2373 parmlist_or_identifiers_1:
2377 for (t = $1; t; t = TREE_CHAIN (t))
2378 if (TREE_VALUE (t) == NULL_TREE)
2379 error ("`...' in old-style identifier list");
2380 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2383 /* A nonempty list of identifiers. */
2386 { $$ = build_tree_list (NULL_TREE, $1); }
2387 | identifiers ',' IDENTIFIER
2388 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2391 /* A nonempty list of identifiers, including typenames. */
2392 identifiers_or_typenames:
2394 { $$ = build_tree_list (NULL_TREE, $1); }
2395 | identifiers_or_typenames ',' identifier
2396 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2401 { $$ = SAVE_WARN_FLAGS();
2403 warn_pointer_arith = 0; }
2407 /* Objective-C productions. */
2417 if (objc_implementation_context)
2419 finish_class (objc_implementation_context);
2420 objc_ivar_chain = NULL_TREE;
2421 objc_implementation_context = NULL_TREE;
2424 warning ("`@end' must appear in an implementation context");
2428 /* A nonempty list of identifiers. */
2431 { $$ = build_tree_list (NULL_TREE, $1); }
2432 | identifier_list ',' identifier
2433 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2437 CLASS identifier_list ';'
2439 objc_declare_class ($2);
2443 ALIAS identifier identifier ';'
2445 objc_declare_alias ($2, $3);
2449 INTERFACE identifier protocolrefs '{'
2451 objc_interface_context = objc_ivar_context
2452 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2453 objc_public_flag = 0;
2457 continue_class (objc_interface_context);
2462 finish_class (objc_interface_context);
2463 objc_interface_context = NULL_TREE;
2466 | INTERFACE identifier protocolrefs
2468 objc_interface_context
2469 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2470 continue_class (objc_interface_context);
2475 finish_class (objc_interface_context);
2476 objc_interface_context = NULL_TREE;
2479 | INTERFACE identifier ':' identifier protocolrefs '{'
2481 objc_interface_context = objc_ivar_context
2482 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2483 objc_public_flag = 0;
2487 continue_class (objc_interface_context);
2492 finish_class (objc_interface_context);
2493 objc_interface_context = NULL_TREE;
2496 | INTERFACE identifier ':' identifier protocolrefs
2498 objc_interface_context
2499 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2500 continue_class (objc_interface_context);
2505 finish_class (objc_interface_context);
2506 objc_interface_context = NULL_TREE;
2509 | IMPLEMENTATION identifier '{'
2511 objc_implementation_context = objc_ivar_context
2512 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2513 objc_public_flag = 0;
2518 = continue_class (objc_implementation_context);
2521 | IMPLEMENTATION identifier
2523 objc_implementation_context
2524 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2526 = continue_class (objc_implementation_context);
2529 | IMPLEMENTATION identifier ':' identifier '{'
2531 objc_implementation_context = objc_ivar_context
2532 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2533 objc_public_flag = 0;
2538 = continue_class (objc_implementation_context);
2541 | IMPLEMENTATION identifier ':' identifier
2543 objc_implementation_context
2544 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2546 = continue_class (objc_implementation_context);
2549 | INTERFACE identifier '(' identifier ')' protocolrefs
2551 objc_interface_context
2552 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2553 continue_class (objc_interface_context);
2558 finish_class (objc_interface_context);
2559 objc_interface_context = NULL_TREE;
2562 | IMPLEMENTATION identifier '(' identifier ')'
2564 objc_implementation_context
2565 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2567 = continue_class (objc_implementation_context);
2572 PROTOCOL identifier protocolrefs
2574 remember_protocol_qualifiers ();
2575 objc_interface_context
2576 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2580 forget_protocol_qualifiers();
2581 finish_protocol(objc_interface_context);
2582 objc_interface_context = NULL_TREE;
2591 | non_empty_protocolrefs
2594 non_empty_protocolrefs:
2595 ARITHCOMPARE identifier_list ARITHCOMPARE
2597 if ($1 == LT_EXPR && $3 == GT_EXPR)
2605 ivar_decl_list visibility_spec ivar_decls
2610 PRIVATE { objc_public_flag = 2; }
2611 | PROTECTED { objc_public_flag = 0; }
2612 | PUBLIC { objc_public_flag = 1; }
2620 | ivar_decls ivar_decl ';'
2624 pedwarn ("extra semicolon in struct or union specified");
2629 /* There is a shift-reduce conflict here, because `components' may
2630 start with a `typename'. It happens that shifting (the default resolution)
2631 does the right thing, because it treats the `typename' as part of
2632 a `typed_typespecs'.
2634 It is possible that this same technique would allow the distinction
2635 between `notype_initdecls' and `initdecls' to be eliminated.
2636 But I am being cautious and not trying it. */
2639 typed_typespecs setspecs ivars
2641 current_declspecs = TREE_VALUE (declspec_stack);
2642 prefix_attributes = TREE_PURPOSE (declspec_stack);
2643 declspec_stack = TREE_CHAIN (declspec_stack); }
2644 | nonempty_type_quals setspecs ivars
2646 current_declspecs = TREE_VALUE (declspec_stack);
2647 prefix_attributes = TREE_PURPOSE (declspec_stack);
2648 declspec_stack = TREE_CHAIN (declspec_stack); }
2657 | ivars ',' ivar_declarator
2663 $$ = add_instance_variable (objc_ivar_context,
2665 $1, current_declspecs,
2668 | declarator ':' expr_no_commas
2670 $$ = add_instance_variable (objc_ivar_context,
2672 $1, current_declspecs, $3);
2674 | ':' expr_no_commas
2676 $$ = add_instance_variable (objc_ivar_context,
2679 current_declspecs, $2);
2686 remember_protocol_qualifiers ();
2687 if (objc_implementation_context)
2688 objc_inherit_code = CLASS_METHOD_DECL;
2690 fatal ("method definition not in class context");
2694 forget_protocol_qualifiers ();
2695 add_class_method (objc_implementation_context, $3);
2696 start_method_def ($3);
2697 objc_method_context = $3;
2701 continue_method_def ();
2705 finish_method_def ();
2706 objc_method_context = NULL_TREE;
2711 remember_protocol_qualifiers ();
2712 if (objc_implementation_context)
2713 objc_inherit_code = INSTANCE_METHOD_DECL;
2715 fatal ("method definition not in class context");
2719 forget_protocol_qualifiers ();
2720 add_instance_method (objc_implementation_context, $3);
2721 start_method_def ($3);
2722 objc_method_context = $3;
2726 continue_method_def ();
2730 finish_method_def ();
2731 objc_method_context = NULL_TREE;
2735 /* the reason for the strange actions in this rule
2736 is so that notype_initdecls when reached via datadef
2737 can find a valid list of type and sc specs in $0. */
2741 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2744 methodprotolist2: /* eliminates a shift/reduce conflict */
2747 | methodprotolist2 methodproto
2748 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2759 /* Remember protocol qualifiers in prototypes. */
2760 remember_protocol_qualifiers ();
2761 objc_inherit_code = CLASS_METHOD_DECL;
2765 /* Forget protocol qualifiers here. */
2766 forget_protocol_qualifiers ();
2767 add_class_method (objc_interface_context, $3);
2773 /* Remember protocol qualifiers in prototypes. */
2774 remember_protocol_qualifiers ();
2775 objc_inherit_code = INSTANCE_METHOD_DECL;
2779 /* Forget protocol qualifiers here. */
2780 forget_protocol_qualifiers ();
2781 add_instance_method (objc_interface_context, $3);
2787 '(' typename ')' unaryselector
2789 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2794 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2797 | '(' typename ')' keywordselector optparmlist
2799 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2802 | keywordselector optparmlist
2804 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2808 /* "optarglist" assumes that start_method_def has already been called...
2809 if it is not, the "xdecls" will not be placed in the proper scope */
2816 /* to get around the following situation: "int foo (int a) int b; {}" that
2817 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2832 typed_declspecs setspecs myparms ';'
2833 { current_declspecs = TREE_VALUE (declspec_stack);
2834 prefix_attributes = TREE_PURPOSE (declspec_stack);
2835 declspec_stack = TREE_CHAIN (declspec_stack); }
2836 | typed_declspecs ';'
2837 { shadow_tag ($1); }
2839 { pedwarn ("empty declaration"); }
2844 { push_parm_decl ($1); }
2845 | myparms ',' myparm
2846 { push_parm_decl ($3); }
2849 /* A single parameter declaration or parameter type name,
2850 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2853 parm_declarator maybe_attribute
2854 { $$ = build_tree_list (build_tree_list (current_declspecs,
2856 build_tree_list (prefix_attributes,
2858 | notype_declarator maybe_attribute
2859 { $$ = build_tree_list (build_tree_list (current_declspecs,
2861 build_tree_list (prefix_attributes,
2863 | absdcl maybe_attribute
2864 { $$ = build_tree_list (build_tree_list (current_declspecs,
2866 build_tree_list (prefix_attributes,
2877 /* oh what a kludge! */
2886 /* returns a tree list node generated by get_parm_info */
2899 | keywordselector keyworddecl
2901 $$ = chainon ($1, $2);
2913 ENUM { $$ = get_identifier (token_buffer); }
2914 | STRUCT { $$ = get_identifier (token_buffer); }
2915 | UNION { $$ = get_identifier (token_buffer); }
2916 | IF { $$ = get_identifier (token_buffer); }
2917 | ELSE { $$ = get_identifier (token_buffer); }
2918 | WHILE { $$ = get_identifier (token_buffer); }
2919 | DO { $$ = get_identifier (token_buffer); }
2920 | FOR { $$ = get_identifier (token_buffer); }
2921 | SWITCH { $$ = get_identifier (token_buffer); }
2922 | CASE { $$ = get_identifier (token_buffer); }
2923 | DEFAULT { $$ = get_identifier (token_buffer); }
2924 | BREAK { $$ = get_identifier (token_buffer); }
2925 | CONTINUE { $$ = get_identifier (token_buffer); }
2926 | RETURN { $$ = get_identifier (token_buffer); }
2927 | GOTO { $$ = get_identifier (token_buffer); }
2928 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2929 | SIZEOF { $$ = get_identifier (token_buffer); }
2930 | TYPEOF { $$ = get_identifier (token_buffer); }
2931 | ALIGNOF { $$ = get_identifier (token_buffer); }
2932 | TYPESPEC | TYPE_QUAL
2936 selector ':' '(' typename ')' identifier
2938 $$ = build_keyword_decl ($1, $4, $6);
2941 | selector ':' identifier
2943 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2946 | ':' '(' typename ')' identifier
2948 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2953 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2964 | keywordarglist keywordarg
2966 $$ = chainon ($1, $2);
2974 if (TREE_CHAIN ($1) == NULL_TREE)
2975 /* just return the expr., remove a level of indirection */
2976 $$ = TREE_VALUE ($1);
2978 /* we have a comma expr., we will collapse later */
2984 selector ':' keywordexpr
2986 $$ = build_tree_list ($1, $3);
2990 $$ = build_tree_list (NULL_TREE, $2);
2998 $$ = get_class_reference ($1);
3004 { objc_receiver_context = 1; }
3006 { objc_receiver_context = 0; }
3009 $$ = build_tree_list ($3, $5);
3020 | keywordnamelist keywordname
3022 $$ = chainon ($1, $2);
3029 $$ = build_tree_list ($1, NULL_TREE);
3033 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3038 SELECTOR '(' selectorarg ')'
3045 PROTOCOL '(' identifier ')'
3051 /* extension to support C-structures in the archiver */
3054 ENCODE '(' typename ')'
3056 $$ = groktypename ($3);