1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 88, 89, 92-99, 2000 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 extension
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;
230 /* For __extension__, save/restore the warning flags which are
231 controlled by __extension__. */
232 #define SAVE_WARN_FLAGS() \
233 build_int_2 (pedantic | (warn_pointer_arith << 1), 0)
234 #define RESTORE_WARN_FLAGS(tval) \
236 int val = TREE_INT_CST_LOW (tval); \
237 pedantic = val & 1; \
238 warn_pointer_arith = (val >> 1) & 1; \
242 /* Objective-C specific information */
244 tree objc_interface_context;
245 tree objc_implementation_context;
246 tree objc_method_context;
247 tree objc_ivar_chain;
248 tree objc_ivar_context;
249 enum tree_code objc_inherit_code;
250 int objc_receiver_context;
251 int objc_public_flag;
255 /* Tell yyparse how to print a token's value, if yydebug is set. */
257 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
258 extern void yyprint PARAMS ((FILE *, int, YYSTYPE));
260 /* Add GC roots for variables local to this file. */
264 ggc_add_tree_root (&declspec_stack, 1);
265 ggc_add_tree_root (¤t_declspecs, 1);
266 ggc_add_tree_root (&prefix_attributes, 1);
274 pedwarn ("ANSI C forbids an empty source file");
279 /* In case there were missing closebraces,
280 get us back to the global binding level. */
281 while (! global_bindings_p ())
287 /* the reason for the strange actions in this rule
288 is so that notype_initdecls when reached via datadef
289 can find a valid list of type and sc specs in $0. */
292 {$<ttype>$ = NULL_TREE; } extdef
293 | extdefs {$<ttype>$ = NULL_TREE; } extdef
302 | ASM_KEYWORD '(' expr ')' ';'
304 if ((TREE_CODE ($3) == ADDR_EXPR
305 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
306 || TREE_CODE ($3) == STRING_CST)
309 error ("argument of `asm' is not a constant string"); }
311 { RESTORE_WARN_FLAGS ($1); }
315 setspecs notype_initdecls ';'
317 error ("ANSI C forbids data definition with no type or storage class");
318 else if (!flag_traditional)
319 warning ("data definition has no type or storage class");
321 current_declspecs = TREE_VALUE (declspec_stack);
322 prefix_attributes = TREE_PURPOSE (declspec_stack);
323 declspec_stack = TREE_CHAIN (declspec_stack); }
324 | declmods setspecs notype_initdecls ';'
325 { current_declspecs = TREE_VALUE (declspec_stack);
326 prefix_attributes = TREE_PURPOSE (declspec_stack);
327 declspec_stack = TREE_CHAIN (declspec_stack); }
328 | typed_declspecs setspecs initdecls ';'
329 { current_declspecs = TREE_VALUE (declspec_stack);
330 prefix_attributes = TREE_PURPOSE (declspec_stack);
331 declspec_stack = TREE_CHAIN (declspec_stack); }
333 { pedwarn ("empty declaration"); }
334 | typed_declspecs ';'
340 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
344 typed_declspecs setspecs declarator
345 { if (! start_function (current_declspecs, $3,
346 prefix_attributes, NULL_TREE))
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 | typed_declspecs setspecs declarator error
357 { current_declspecs = TREE_VALUE (declspec_stack);
358 prefix_attributes = TREE_PURPOSE (declspec_stack);
359 declspec_stack = TREE_CHAIN (declspec_stack); }
360 | declmods setspecs notype_declarator
361 { if (! start_function (current_declspecs, $3,
362 prefix_attributes, NULL_TREE))
364 reinit_parse_for_function (); }
366 { store_parm_decls (); }
368 { finish_function (0);
369 current_declspecs = TREE_VALUE (declspec_stack);
370 prefix_attributes = TREE_PURPOSE (declspec_stack);
371 declspec_stack = TREE_CHAIN (declspec_stack); }
372 | declmods setspecs notype_declarator error
373 { current_declspecs = TREE_VALUE (declspec_stack);
374 prefix_attributes = TREE_PURPOSE (declspec_stack);
375 declspec_stack = TREE_CHAIN (declspec_stack); }
376 | setspecs notype_declarator
377 { if (! start_function (NULL_TREE, $2,
378 prefix_attributes, NULL_TREE))
380 reinit_parse_for_function (); }
382 { store_parm_decls (); }
384 { finish_function (0);
385 current_declspecs = TREE_VALUE (declspec_stack);
386 prefix_attributes = TREE_PURPOSE (declspec_stack);
387 declspec_stack = TREE_CHAIN (declspec_stack); }
388 | setspecs notype_declarator error
389 { current_declspecs = TREE_VALUE (declspec_stack);
390 prefix_attributes = TREE_PURPOSE (declspec_stack);
391 declspec_stack = TREE_CHAIN (declspec_stack); }
406 { $$ = NEGATE_EXPR; }
408 { $$ = CONVERT_EXPR; }
410 { $$ = PREINCREMENT_EXPR; }
412 { $$ = PREDECREMENT_EXPR; }
414 { $$ = BIT_NOT_EXPR; }
416 { $$ = TRUTH_NOT_EXPR; }
419 expr: nonnull_exprlist
420 { $$ = build_compound_expr ($1); }
431 { $$ = build_tree_list (NULL_TREE, $1); }
432 | nonnull_exprlist ',' expr_no_commas
433 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
438 | '*' cast_expr %prec UNARY
439 { $$ = build_indirect_ref ($2, "unary *"); }
440 /* __extension__ turns off -pedantic for following primary. */
441 | extension cast_expr %prec UNARY
443 RESTORE_WARN_FLAGS ($1); }
444 | unop cast_expr %prec UNARY
445 { $$ = build_unary_op ($1, $2, 0);
446 overflow_warning ($$); }
447 /* Refer to the address of a label as a pointer. */
449 { tree label = lookup_label ($2);
451 pedwarn ("ANSI C forbids `&&'");
453 $$ = null_pointer_node;
456 TREE_USED (label) = 1;
457 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
458 TREE_CONSTANT ($$) = 1;
461 /* This seems to be impossible on some machines, so let's turn it off.
462 You can use __builtin_next_arg to find the anonymous stack args.
464 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
465 $$ = error_mark_node;
466 if (TREE_VALUE (tree_last (types)) == void_type_node)
467 error ("`&...' used in function with fixed number of arguments");
471 pedwarn ("ANSI C forbids `&...'");
472 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
473 $$ = build_unary_op (ADDR_EXPR, $$, 0);
476 | sizeof unary_expr %prec UNARY
478 if (TREE_CODE ($2) == COMPONENT_REF
479 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
480 error ("`sizeof' applied to a bit-field");
481 $$ = c_sizeof (TREE_TYPE ($2)); }
482 | sizeof '(' typename ')' %prec HYPERUNARY
484 $$ = c_sizeof (groktypename ($3)); }
485 | alignof unary_expr %prec UNARY
487 $$ = c_alignof_expr ($2); }
488 | alignof '(' typename ')' %prec HYPERUNARY
490 $$ = c_alignof (groktypename ($3)); }
491 | REALPART cast_expr %prec UNARY
492 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
493 | IMAGPART cast_expr %prec UNARY
494 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
495 | VA_ARG '(' expr_no_commas ',' typename ')'
496 { $$ = build_va_arg ($3, groktypename ($5)); }
500 SIZEOF { skip_evaluation++; }
504 ALIGNOF { skip_evaluation++; }
509 | '(' typename ')' cast_expr %prec UNARY
510 { tree type = groktypename ($2);
511 $$ = build_c_cast (type, $4); }
512 | '(' typename ')' '{'
513 { start_init (NULL_TREE, NULL, 0);
514 $2 = groktypename ($2);
515 really_start_incremental_init ($2); }
516 initlist_maybe_comma '}' %prec UNARY
518 tree result = pop_init_level (0);
522 if (pedantic && ! flag_isoc9x)
523 pedwarn ("ANSI C forbids constructor expressions");
524 if (TYPE_NAME (type) != 0)
526 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
527 name = IDENTIFIER_POINTER (TYPE_NAME (type));
529 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
534 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
536 int failure = complete_array_type (type, $$, 1);
545 | expr_no_commas '+' expr_no_commas
546 { $$ = parser_build_binary_op ($2, $1, $3); }
547 | expr_no_commas '-' expr_no_commas
548 { $$ = parser_build_binary_op ($2, $1, $3); }
549 | expr_no_commas '*' expr_no_commas
550 { $$ = parser_build_binary_op ($2, $1, $3); }
551 | expr_no_commas '/' expr_no_commas
552 { $$ = parser_build_binary_op ($2, $1, $3); }
553 | expr_no_commas '%' expr_no_commas
554 { $$ = parser_build_binary_op ($2, $1, $3); }
555 | expr_no_commas LSHIFT expr_no_commas
556 { $$ = parser_build_binary_op ($2, $1, $3); }
557 | expr_no_commas RSHIFT expr_no_commas
558 { $$ = parser_build_binary_op ($2, $1, $3); }
559 | expr_no_commas ARITHCOMPARE expr_no_commas
560 { $$ = parser_build_binary_op ($2, $1, $3); }
561 | expr_no_commas EQCOMPARE expr_no_commas
562 { $$ = parser_build_binary_op ($2, $1, $3); }
563 | expr_no_commas '&' expr_no_commas
564 { $$ = parser_build_binary_op ($2, $1, $3); }
565 | expr_no_commas '|' expr_no_commas
566 { $$ = parser_build_binary_op ($2, $1, $3); }
567 | expr_no_commas '^' expr_no_commas
568 { $$ = parser_build_binary_op ($2, $1, $3); }
569 | expr_no_commas ANDAND
570 { $1 = truthvalue_conversion (default_conversion ($1));
571 skip_evaluation += $1 == boolean_false_node; }
573 { skip_evaluation -= $1 == boolean_false_node;
574 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
575 | expr_no_commas OROR
576 { $1 = truthvalue_conversion (default_conversion ($1));
577 skip_evaluation += $1 == boolean_true_node; }
579 { skip_evaluation -= $1 == boolean_true_node;
580 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
582 { $1 = truthvalue_conversion (default_conversion ($1));
583 skip_evaluation += $1 == boolean_false_node; }
585 { skip_evaluation += (($1 == boolean_true_node)
586 - ($1 == boolean_false_node)); }
588 { skip_evaluation -= $1 == boolean_true_node;
589 $$ = build_conditional_expr ($1, $4, $7); }
592 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
593 /* Make sure first operand is calculated only once. */
594 $<ttype>2 = save_expr ($1);
595 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
596 skip_evaluation += $1 == boolean_true_node; }
598 { skip_evaluation -= $1 == boolean_true_node;
599 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
600 | expr_no_commas '=' expr_no_commas
602 $$ = build_modify_expr ($1, NOP_EXPR, $3);
603 class = TREE_CODE_CLASS (TREE_CODE ($$));
604 if (class == 'e' || class == '1'
605 || class == '2' || class == '<')
606 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
608 | expr_no_commas ASSIGN expr_no_commas
610 $$ = build_modify_expr ($1, $2, $3);
611 /* This inhibits warnings in truthvalue_conversion. */
612 class = TREE_CODE_CLASS (TREE_CODE ($$));
613 if (class == 'e' || class == '1'
614 || class == '2' || class == '<')
615 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
623 if (!$$ || $$ == error_mark_node)
625 if (yychar == YYEMPTY)
632 if (objc_receiver_context
633 && ! (objc_receiver_context
634 && strcmp (IDENTIFIER_POINTER ($1), "super")))
635 /* we have a message to super */
636 $$ = get_super_receiver ();
637 else if (objc_method_context
638 && (decl = is_ivar (objc_ivar_chain, $1)))
640 if (is_private (decl))
641 $$ = error_mark_node;
643 $$ = build_ivar_reference ($1);
648 /* Ordinary implicit function declaration. */
649 $$ = implicitly_declare ($1);
650 assemble_external ($$);
654 else if (current_function_decl == 0)
656 error ("`%s' undeclared here (not in a function)",
657 IDENTIFIER_POINTER ($1));
658 $$ = error_mark_node;
665 if (objc_receiver_context
666 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
667 /* we have a message to super */
668 $$ = get_super_receiver ();
669 else if (objc_method_context
670 && (decl = is_ivar (objc_ivar_chain, $1)))
672 if (is_private (decl))
673 $$ = error_mark_node;
675 $$ = build_ivar_reference ($1);
680 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
681 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
683 error ("`%s' undeclared (first use in this function)",
684 IDENTIFIER_POINTER ($1));
686 if (! undeclared_variable_notice)
688 error ("(Each undeclared identifier is reported only once");
689 error ("for each function it appears in.)");
690 undeclared_variable_notice = 1;
693 $$ = error_mark_node;
694 /* Prevent repeated error messages. */
695 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
696 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
700 else if (TREE_TYPE ($$) == error_mark_node)
701 $$ = error_mark_node;
702 else if (C_DECL_ANTICIPATED ($$))
704 /* The first time we see a build-in function used,
705 if it has not been declared. */
706 C_DECL_ANTICIPATED ($$) = 0;
707 if (yychar == YYEMPTY)
711 /* Omit the implicit declaration we
712 would ordinarily do, so we don't lose
713 the actual built in type.
714 But print a diagnostic for the mismatch. */
716 if (objc_method_context
717 && is_ivar (objc_ivar_chain, $1))
718 error ("Instance variable `%s' implicitly declared as function",
719 IDENTIFIER_POINTER (DECL_NAME ($$)));
722 if (TREE_CODE ($$) != FUNCTION_DECL)
723 error ("`%s' implicitly declared as function",
724 IDENTIFIER_POINTER (DECL_NAME ($$)));
725 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
726 != TYPE_MODE (integer_type_node))
727 && (TREE_TYPE (TREE_TYPE ($$))
729 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
730 IDENTIFIER_POINTER (DECL_NAME ($$)));
731 /* If it really returns void, change that to int. */
732 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
734 = build_function_type (integer_type_node,
735 TYPE_ARG_TYPES (TREE_TYPE ($$)));
738 pedwarn ("built-in function `%s' used without declaration",
739 IDENTIFIER_POINTER (DECL_NAME ($$)));
741 /* Do what we would ordinarily do when a fn is used. */
742 assemble_external ($$);
747 assemble_external ($$);
750 /* we have a definition - still check if iVariable */
752 if (!objc_receiver_context
753 || (objc_receiver_context
754 && strcmp (IDENTIFIER_POINTER ($1), "super")))
758 if (objc_method_context
759 && (decl = is_ivar (objc_ivar_chain, $1)))
761 if (IDENTIFIER_LOCAL_VALUE ($1))
762 warning ("local declaration of `%s' hides instance variable",
763 IDENTIFIER_POINTER ($1));
766 if (is_private (decl))
767 $$ = error_mark_node;
769 $$ = build_ivar_reference ($1);
773 else /* we have a message to super */
774 $$ = get_super_receiver ();
778 if (TREE_CODE ($$) == CONST_DECL)
780 $$ = DECL_INITIAL ($$);
781 /* This is to prevent an enum whose value is 0
782 from being considered a null pointer constant. */
783 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
784 TREE_CONSTANT ($$) = 1;
789 { $$ = combine_strings ($1); }
791 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
792 if (class == 'e' || class == '1'
793 || class == '2' || class == '<')
794 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
797 { $$ = error_mark_node; }
798 | compstmt_primary_start compstmt_nostart ')'
801 pedwarn ("ANSI C forbids braced-groups within expressions");
802 pop_iterator_stack ();
804 rtl_exp = expand_end_stmt_expr ($1);
805 /* The statements have side effects, so the group does. */
806 TREE_SIDE_EFFECTS (rtl_exp) = 1;
808 if (TREE_CODE ($2) == BLOCK)
810 /* Make a BIND_EXPR for the BLOCK already made. */
811 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
812 NULL_TREE, rtl_exp, $2);
813 /* Remove the block from the tree at this point.
814 It gets put back at the proper place
815 when the BIND_EXPR is expanded. */
821 | compstmt_primary_start error ')'
823 /* Make sure we call expand_end_stmt_expr. Otherwise
824 we are likely to lose sequences and crash later. */
825 pop_iterator_stack ();
827 expand_end_stmt_expr ($1);
828 $$ = error_mark_node;
830 | primary '(' exprlist ')' %prec '.'
831 { $$ = build_function_call ($1, $3); }
832 | primary '[' expr ']' %prec '.'
833 { $$ = build_array_ref ($1, $3); }
834 | primary '.' identifier
837 if (doing_objc_thang)
839 if (is_public ($1, $3))
840 $$ = build_component_ref ($1, $3);
842 $$ = error_mark_node;
846 $$ = build_component_ref ($1, $3);
848 | primary POINTSAT identifier
850 tree expr = build_indirect_ref ($1, "->");
853 if (doing_objc_thang)
855 if (is_public (expr, $3))
856 $$ = build_component_ref (expr, $3);
858 $$ = error_mark_node;
862 $$ = build_component_ref (expr, $3);
865 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
867 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
870 { $$ = build_message_expr ($1); }
872 { $$ = build_selector_expr ($1); }
874 { $$ = build_protocol_expr ($1); }
876 { $$ = build_encode_expr ($1); }
878 { $$ = build_objc_string_object ($1); }
882 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
886 { $$ = chainon ($1, $2);
888 if (warn_traditional && !in_system_header)
889 warning ("Use of ANSI string concatenation");
895 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
899 | objc_string OBJC_STRING
900 { $$ = chainon ($1, $2); }
904 old_style_parm_decls:
908 /* ... is used here to indicate a varargs function. */
911 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
914 /* The following are analogous to lineno_decl, decls and decl
915 except that they do not allow nested functions.
916 They are used for old-style parm decls. */
918 save_filename save_lineno datadecl
925 | datadecls lineno_datadecl
926 | lineno_datadecl errstmt
929 /* We don't allow prefix attributes here because they cause reduce/reduce
930 conflicts: we can't know whether we're parsing a function decl with
931 attribute suffix, or function defn with attribute prefix on first old
934 typed_declspecs_no_prefix_attr setspecs initdecls ';'
935 { current_declspecs = TREE_VALUE (declspec_stack);
936 prefix_attributes = TREE_PURPOSE (declspec_stack);
937 declspec_stack = TREE_CHAIN (declspec_stack); }
938 | declmods_no_prefix_attr setspecs notype_initdecls ';'
939 { current_declspecs = TREE_VALUE (declspec_stack);
940 prefix_attributes = TREE_PURPOSE (declspec_stack);
941 declspec_stack = TREE_CHAIN (declspec_stack); }
942 | typed_declspecs_no_prefix_attr ';'
943 { shadow_tag_warned ($1, 1);
944 pedwarn ("empty declaration"); }
945 | declmods_no_prefix_attr ';'
946 { pedwarn ("empty declaration"); }
949 /* This combination which saves a lineno before a decl
950 is the normal thing to use, rather than decl itself.
951 This is to avoid shift/reduce conflicts in contexts
952 where statement labels are allowed. */
954 save_filename save_lineno decl
962 | lineno_decl errstmt
965 /* records the type and storage class specs to use for processing
966 the declarators that follow.
967 Maintains a stack of outer-level values of current_declspecs,
968 for the sake of parm declarations nested in function declarators. */
969 setspecs: /* empty */
970 { pending_xref_error ();
971 declspec_stack = tree_cons (prefix_attributes,
974 split_specs_attrs ($<ttype>0,
975 ¤t_declspecs, &prefix_attributes); }
978 /* ??? Yuck. See after_type_declarator. */
979 setattrs: /* empty */
980 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
984 typed_declspecs setspecs initdecls ';'
985 { current_declspecs = TREE_VALUE (declspec_stack);
986 prefix_attributes = TREE_PURPOSE (declspec_stack);
987 declspec_stack = TREE_CHAIN (declspec_stack); }
988 | declmods setspecs notype_initdecls ';'
989 { current_declspecs = TREE_VALUE (declspec_stack);
990 prefix_attributes = TREE_PURPOSE (declspec_stack);
991 declspec_stack = TREE_CHAIN (declspec_stack); }
992 | typed_declspecs setspecs nested_function
993 { current_declspecs = TREE_VALUE (declspec_stack);
994 prefix_attributes = TREE_PURPOSE (declspec_stack);
995 declspec_stack = TREE_CHAIN (declspec_stack); }
996 | declmods setspecs notype_nested_function
997 { current_declspecs = TREE_VALUE (declspec_stack);
998 prefix_attributes = TREE_PURPOSE (declspec_stack);
999 declspec_stack = TREE_CHAIN (declspec_stack); }
1000 | typed_declspecs ';'
1001 { shadow_tag ($1); }
1003 { pedwarn ("empty declaration"); }
1005 { RESTORE_WARN_FLAGS ($1); }
1008 /* Declspecs which contain at least one type specifier or typedef name.
1009 (Just `const' or `volatile' is not enough.)
1010 A typedef'd name following these is taken as a name to be declared.
1011 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1014 typespec reserved_declspecs
1015 { $$ = tree_cons (NULL_TREE, $1, $2); }
1016 | declmods typespec reserved_declspecs
1017 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1020 reserved_declspecs: /* empty */
1022 | reserved_declspecs typespecqual_reserved
1023 { $$ = tree_cons (NULL_TREE, $2, $1); }
1024 | reserved_declspecs SCSPEC
1025 { if (extra_warnings)
1026 warning ("`%s' is not at beginning of declaration",
1027 IDENTIFIER_POINTER ($2));
1028 $$ = tree_cons (NULL_TREE, $2, $1); }
1029 | reserved_declspecs attributes
1030 { $$ = tree_cons ($2, NULL_TREE, $1); }
1033 typed_declspecs_no_prefix_attr:
1034 typespec reserved_declspecs_no_prefix_attr
1035 { $$ = tree_cons (NULL_TREE, $1, $2); }
1036 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
1037 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1040 reserved_declspecs_no_prefix_attr:
1043 | reserved_declspecs_no_prefix_attr typespecqual_reserved
1044 { $$ = tree_cons (NULL_TREE, $2, $1); }
1045 | reserved_declspecs_no_prefix_attr SCSPEC
1046 { if (extra_warnings)
1047 warning ("`%s' is not at beginning of declaration",
1048 IDENTIFIER_POINTER ($2));
1049 $$ = tree_cons (NULL_TREE, $2, $1); }
1052 /* List of just storage classes, type modifiers, and prefix attributes.
1053 A declaration can start with just this, but then it cannot be used
1054 to redeclare a typedef-name.
1055 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1058 declmods_no_prefix_attr
1061 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
1062 | declmods declmods_no_prefix_attr
1063 { $$ = chainon ($2, $1); }
1064 | declmods attributes
1065 { $$ = tree_cons ($2, NULL_TREE, $1); }
1068 declmods_no_prefix_attr:
1070 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1071 TREE_STATIC ($$) = 1; }
1073 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1074 | declmods_no_prefix_attr TYPE_QUAL
1075 { $$ = tree_cons (NULL_TREE, $2, $1);
1076 TREE_STATIC ($$) = 1; }
1077 | declmods_no_prefix_attr SCSPEC
1078 { if (extra_warnings && TREE_STATIC ($1))
1079 warning ("`%s' is not at beginning of declaration",
1080 IDENTIFIER_POINTER ($2));
1081 $$ = tree_cons (NULL_TREE, $2, $1);
1082 TREE_STATIC ($$) = TREE_STATIC ($1); }
1086 /* Used instead of declspecs where storage classes are not allowed
1087 (that is, for typenames and structure components).
1088 Don't accept a typedef-name if anything but a modifier precedes it. */
1091 typespec reserved_typespecquals
1092 { $$ = tree_cons (NULL_TREE, $1, $2); }
1093 | nonempty_type_quals typespec reserved_typespecquals
1094 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1097 reserved_typespecquals: /* empty */
1099 | reserved_typespecquals typespecqual_reserved
1100 { $$ = tree_cons (NULL_TREE, $2, $1); }
1103 /* A typespec (but not a type qualifier).
1104 Once we have seen one of these in a declaration,
1105 if a typedef name appears then it is being redeclared. */
1110 { /* For a typedef name, record the meaning, not the name.
1111 In case of `foo foo, bar;'. */
1112 $$ = lookup_name ($1); }
1114 | CLASSNAME protocolrefs
1115 { $$ = get_static_reference ($1, $2); }
1116 | OBJECTNAME protocolrefs
1117 { $$ = get_object_reference ($2); }
1119 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1120 - nisse@lysator.liu.se */
1121 | non_empty_protocolrefs
1122 { $$ = get_object_reference ($1); }
1124 | TYPEOF '(' expr ')'
1125 { $$ = TREE_TYPE ($3); }
1126 | TYPEOF '(' typename ')'
1127 { $$ = groktypename ($3); }
1130 /* A typespec that is a reserved word, or a type qualifier. */
1132 typespecqual_reserved: TYPESPEC
1139 | initdecls ',' initdcl
1144 | notype_initdecls ',' initdcl
1150 | ASM_KEYWORD '(' string ')'
1151 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1157 declarator maybeasm maybe_attribute '='
1158 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1159 $3, prefix_attributes);
1160 start_init ($<ttype>$, $2, global_bindings_p ()); }
1162 /* Note how the declaration of the variable is in effect while its init is parsed! */
1164 finish_decl ($<ttype>5, $6, $2); }
1165 | declarator maybeasm maybe_attribute
1166 { tree d = start_decl ($1, current_declspecs, 0,
1167 $3, prefix_attributes);
1168 finish_decl (d, NULL_TREE, $2);
1173 notype_declarator maybeasm maybe_attribute '='
1174 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1175 $3, prefix_attributes);
1176 start_init ($<ttype>$, $2, global_bindings_p ()); }
1178 /* Note how the declaration of the variable is in effect while its init is parsed! */
1180 decl_attributes ($<ttype>5, $3, prefix_attributes);
1181 finish_decl ($<ttype>5, $6, $2); }
1182 | notype_declarator maybeasm maybe_attribute
1183 { tree d = start_decl ($1, current_declspecs, 0,
1184 $3, prefix_attributes);
1185 finish_decl (d, NULL_TREE, $2); }
1187 /* the * rules are dummies to accept the Apollo extended syntax
1188 so that the header files compile. */
1199 | attributes attribute
1200 { $$ = chainon ($1, $2); }
1204 ATTRIBUTE '(' '(' attribute_list ')' ')'
1211 | attribute_list ',' attrib
1212 { $$ = chainon ($1, $3); }
1219 { $$ = build_tree_list ($1, NULL_TREE); }
1220 | any_word '(' IDENTIFIER ')'
1221 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1222 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1223 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1224 | any_word '(' exprlist ')'
1225 { $$ = build_tree_list ($1, $3); }
1228 /* This still leaves out most reserved keywords,
1229 shouldn't we include them? */
1238 /* Initializers. `init' is the entry point. */
1243 { really_start_incremental_init (NULL_TREE); }
1244 initlist_maybe_comma '}'
1245 { $$ = pop_init_level (0); }
1247 { $$ = error_mark_node; }
1250 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1251 initlist_maybe_comma:
1254 pedwarn ("ANSI C forbids empty initializer braces"); }
1255 | initlist1 maybecomma
1260 | initlist1 ',' initelt
1263 /* `initelt' is a single element of an initializer.
1264 It may use braces. */
1266 designator_list '=' initval
1267 | designator initval
1269 { set_init_label ($1); }
1276 { push_init_level (0); }
1277 initlist_maybe_comma '}'
1278 { process_init_element (pop_init_level (0)); }
1280 { process_init_element ($1); }
1286 | designator_list designator
1291 { set_init_label ($2); }
1292 /* These are for labeled elements. The syntax for an array element
1293 initializer conflicts with the syntax for an Objective-C message,
1294 so don't include these productions in the Objective-C grammar. */
1296 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1297 { set_init_index ($2, $4); }
1298 | '[' expr_no_commas ']'
1299 { set_init_index ($2, NULL_TREE); }
1306 pedwarn ("ANSI C forbids nested functions");
1308 push_function_context ();
1309 if (! start_function (current_declspecs, $1,
1310 prefix_attributes, NULL_TREE))
1312 pop_function_context ();
1315 reinit_parse_for_function (); }
1316 old_style_parm_decls
1317 { store_parm_decls (); }
1318 /* This used to use compstmt_or_error.
1319 That caused a bug with input `f(g) int g {}',
1320 where the use of YYERROR1 above caused an error
1321 which then was handled by compstmt_or_error.
1322 There followed a repeated execution of that same rule,
1323 which called YYERROR1 again, and so on. */
1325 { finish_function (1);
1326 pop_function_context (); }
1329 notype_nested_function:
1332 pedwarn ("ANSI C forbids nested functions");
1334 push_function_context ();
1335 if (! start_function (current_declspecs, $1,
1336 prefix_attributes, NULL_TREE))
1338 pop_function_context ();
1341 reinit_parse_for_function (); }
1342 old_style_parm_decls
1343 { store_parm_decls (); }
1344 /* This used to use compstmt_or_error.
1345 That caused a bug with input `f(g) int g {}',
1346 where the use of YYERROR1 above caused an error
1347 which then was handled by compstmt_or_error.
1348 There followed a repeated execution of that same rule,
1349 which called YYERROR1 again, and so on. */
1351 { finish_function (1);
1352 pop_function_context (); }
1355 /* Any kind of declarator (thus, all declarators allowed
1356 after an explicit typespec). */
1359 after_type_declarator
1363 /* A declarator that is allowed only after an explicit typespec. */
1365 after_type_declarator:
1366 '(' after_type_declarator ')'
1368 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1369 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1370 /* | after_type_declarator '(' error ')' %prec '.'
1371 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1372 poplevel (0, 0, 0); } */
1373 | after_type_declarator '[' expr ']' %prec '.'
1374 { $$ = build_nt (ARRAY_REF, $1, $3); }
1375 | after_type_declarator '[' ']' %prec '.'
1376 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1377 | '*' type_quals after_type_declarator %prec UNARY
1378 { $$ = make_pointer_declarator ($2, $3); }
1379 /* ??? Yuck. setattrs is a quick hack. We can't use
1380 prefix_attributes because $1 only applies to this
1381 declarator. We assume setspecs has already been done.
1382 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1383 attributes could be recognized here or in `attributes'). */
1384 | attributes setattrs after_type_declarator
1392 /* Kinds of declarator that can appear in a parameter list
1393 in addition to notype_declarator. This is like after_type_declarator
1394 but does not allow a typedef name in parentheses as an identifier
1395 (because it would conflict with a function with that typedef as arg). */
1398 parm_declarator '(' parmlist_or_identifiers %prec '.'
1399 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1400 /* | parm_declarator '(' error ')' %prec '.'
1401 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1402 poplevel (0, 0, 0); } */
1404 | parm_declarator '[' '*' ']' %prec '.'
1405 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1407 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1410 | parm_declarator '[' expr ']' %prec '.'
1411 { $$ = build_nt (ARRAY_REF, $1, $3); }
1412 | parm_declarator '[' ']' %prec '.'
1413 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1414 | '*' type_quals parm_declarator %prec UNARY
1415 { $$ = make_pointer_declarator ($2, $3); }
1416 /* ??? Yuck. setattrs is a quick hack. We can't use
1417 prefix_attributes because $1 only applies to this
1418 declarator. We assume setspecs has already been done.
1419 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1420 attributes could be recognized here or in `attributes'). */
1421 | attributes setattrs parm_declarator
1426 /* A declarator allowed whether or not there has been
1427 an explicit typespec. These cannot redeclare a typedef-name. */
1430 notype_declarator '(' parmlist_or_identifiers %prec '.'
1431 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1432 /* | notype_declarator '(' error ')' %prec '.'
1433 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1434 poplevel (0, 0, 0); } */
1435 | '(' notype_declarator ')'
1437 | '*' type_quals notype_declarator %prec UNARY
1438 { $$ = make_pointer_declarator ($2, $3); }
1440 | notype_declarator '[' '*' ']' %prec '.'
1441 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1443 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1446 | notype_declarator '[' expr ']' %prec '.'
1447 { $$ = build_nt (ARRAY_REF, $1, $3); }
1448 | notype_declarator '[' ']' %prec '.'
1449 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1450 /* ??? Yuck. setattrs is a quick hack. We can't use
1451 prefix_attributes because $1 only applies to this
1452 declarator. We assume setspecs has already been done.
1453 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1454 attributes could be recognized here or in `attributes'). */
1455 | attributes setattrs notype_declarator
1482 struct_head identifier '{'
1483 { $$ = start_struct (RECORD_TYPE, $2);
1484 /* Start scope of tag before parsing components. */
1486 component_decl_list '}' maybe_attribute
1487 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1488 | struct_head '{' component_decl_list '}' maybe_attribute
1489 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1490 $3, chainon ($1, $5));
1492 | struct_head identifier
1493 { $$ = xref_tag (RECORD_TYPE, $2); }
1494 | union_head identifier '{'
1495 { $$ = start_struct (UNION_TYPE, $2); }
1496 component_decl_list '}' maybe_attribute
1497 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1498 | union_head '{' component_decl_list '}' maybe_attribute
1499 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1500 $3, chainon ($1, $5));
1502 | union_head identifier
1503 { $$ = xref_tag (UNION_TYPE, $2); }
1504 | enum_head identifier '{'
1505 { $$ = start_enum ($2); }
1506 enumlist maybecomma_warn '}' maybe_attribute
1507 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1508 chainon ($1, $8)); }
1510 { $$ = start_enum (NULL_TREE); }
1511 enumlist maybecomma_warn '}' maybe_attribute
1512 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1513 chainon ($1, $7)); }
1514 | enum_head identifier
1515 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1526 { if (pedantic && ! flag_isoc9x)
1527 pedwarn ("comma at end of enumerator list"); }
1530 component_decl_list:
1531 component_decl_list2
1533 | component_decl_list2 component_decl
1534 { $$ = chainon ($1, $2);
1535 pedwarn ("no semicolon at end of struct or union"); }
1538 component_decl_list2: /* empty */
1540 | component_decl_list2 component_decl ';'
1541 { $$ = chainon ($1, $2); }
1542 | component_decl_list2 ';'
1544 pedwarn ("extra semicolon in struct or union specified"); }
1546 /* foo(sizeof(struct{ @defs(ClassName)})); */
1547 | DEFS '(' CLASSNAME ')'
1549 tree interface = lookup_interface ($3);
1552 $$ = get_class_ivars (interface);
1555 error ("Cannot find interface declaration for `%s'",
1556 IDENTIFIER_POINTER ($3));
1563 /* There is a shift-reduce conflict here, because `components' may
1564 start with a `typename'. It happens that shifting (the default resolution)
1565 does the right thing, because it treats the `typename' as part of
1566 a `typed_typespecs'.
1568 It is possible that this same technique would allow the distinction
1569 between `notype_initdecls' and `initdecls' to be eliminated.
1570 But I am being cautious and not trying it. */
1573 typed_typespecs setspecs components
1575 current_declspecs = TREE_VALUE (declspec_stack);
1576 prefix_attributes = TREE_PURPOSE (declspec_stack);
1577 declspec_stack = TREE_CHAIN (declspec_stack); }
1578 | typed_typespecs setspecs save_filename save_lineno maybe_attribute
1580 /* Support for unnamed structs or unions as members of
1581 structs or unions (which is [a] useful and [b] supports
1584 pedwarn ("ANSI C doesn't support unnamed structs/unions");
1586 $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
1587 current_declspecs = TREE_VALUE (declspec_stack);
1588 prefix_attributes = TREE_PURPOSE (declspec_stack);
1589 declspec_stack = TREE_CHAIN (declspec_stack);
1591 | nonempty_type_quals setspecs components
1593 current_declspecs = TREE_VALUE (declspec_stack);
1594 prefix_attributes = TREE_PURPOSE (declspec_stack);
1595 declspec_stack = TREE_CHAIN (declspec_stack); }
1596 | nonempty_type_quals
1598 pedwarn ("ANSI C forbids member declarations with no members");
1603 | extension component_decl
1605 RESTORE_WARN_FLAGS ($1); }
1609 component_declarator
1610 | components ',' component_declarator
1611 { $$ = chainon ($1, $3); }
1614 component_declarator:
1615 save_filename save_lineno declarator maybe_attribute
1616 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1617 decl_attributes ($$, $4, prefix_attributes); }
1618 | save_filename save_lineno
1619 declarator ':' expr_no_commas maybe_attribute
1620 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1621 decl_attributes ($$, $6, prefix_attributes); }
1622 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1623 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1624 decl_attributes ($$, $5, prefix_attributes); }
1627 /* We chain the enumerators in reverse order.
1628 They are put in forward order where enumlist is used.
1629 (The order used to be significant, but no longer is so.
1630 However, we still maintain the order, just to be clean.) */
1634 | enumlist ',' enumerator
1635 { if ($1 == error_mark_node)
1638 $$ = chainon ($3, $1); }
1640 { $$ = error_mark_node; }
1646 { $$ = build_enumerator ($1, NULL_TREE); }
1647 | identifier '=' expr_no_commas
1648 { $$ = build_enumerator ($1, $3); }
1652 typed_typespecs absdcl
1653 { $$ = build_tree_list ($1, $2); }
1654 | nonempty_type_quals absdcl
1655 { $$ = build_tree_list ($1, $2); }
1658 absdcl: /* an absolute declarator */
1664 nonempty_type_quals:
1666 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1667 | nonempty_type_quals TYPE_QUAL
1668 { $$ = tree_cons (NULL_TREE, $2, $1); }
1674 | type_quals TYPE_QUAL
1675 { $$ = tree_cons (NULL_TREE, $2, $1); }
1678 absdcl1: /* a nonempty absolute declarator */
1681 /* `(typedef)1' is `int'. */
1682 | '*' type_quals absdcl1 %prec UNARY
1683 { $$ = make_pointer_declarator ($2, $3); }
1684 | '*' type_quals %prec UNARY
1685 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1686 | absdcl1 '(' parmlist %prec '.'
1687 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1688 | absdcl1 '[' expr ']' %prec '.'
1689 { $$ = build_nt (ARRAY_REF, $1, $3); }
1690 | absdcl1 '[' ']' %prec '.'
1691 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1692 | '(' parmlist %prec '.'
1693 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1694 | '[' expr ']' %prec '.'
1695 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1697 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1698 /* ??? It appears we have to support attributes here, however
1699 using prefix_attributes is wrong. */
1700 | attributes setattrs absdcl1
1704 /* at least one statement, the first of which parses without error. */
1705 /* stmts is used only after decls, so an invalid first statement
1706 is actually regarded as an invalid decl and part of the decls. */
1709 lineno_stmt_or_labels
1712 pedwarn ("ANSI C forbids label at end of compound statement");
1716 lineno_stmt_or_labels:
1717 lineno_stmt_or_label
1718 | lineno_stmt_or_labels lineno_stmt_or_label
1720 | lineno_stmt_or_labels errstmt
1732 pushlevel: /* empty */
1733 { emit_line_note (input_filename, lineno);
1736 expand_start_bindings (0);
1738 if (objc_method_context)
1744 /* Read zero or more forward-declarations for labels
1745 that nested functions can jump to. */
1750 pedwarn ("ANSI C forbids label declarations"); }
1755 | label_decls label_decl
1759 LABEL identifiers_or_typenames ';'
1761 for (link = $2; link; link = TREE_CHAIN (link))
1763 tree label = shadow_label (TREE_VALUE (link));
1764 C_DECLARED_LABEL_FLAG (label) = 1;
1765 declare_nonlocal_label (label);
1770 /* This is the body of a function definition.
1771 It causes syntax errors to ignore to the next openbrace. */
1778 compstmt_start: '{' { compstmt_count++; }
1780 compstmt_nostart: '}'
1781 { $$ = convert (void_type_node, integer_zero_node); }
1782 | pushlevel maybe_label_decls decls xstmts '}'
1783 { emit_line_note (input_filename, lineno);
1784 expand_end_bindings (getdecls (), 1, 0);
1785 $$ = poplevel (1, 1, 0); }
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 | pushlevel maybe_label_decls stmts '}'
1791 { emit_line_note (input_filename, lineno);
1792 expand_end_bindings (getdecls (), kept_level_p (), 0);
1793 $$ = poplevel (kept_level_p (), 0, 0); }
1796 compstmt_primary_start:
1798 { if (current_function_decl == 0)
1800 error ("braced-group within expression allowed only inside a function");
1803 /* We must force a BLOCK for this level
1804 so that, if it is not expanded later,
1805 there is a way to turn off the entire subtree of blocks
1806 that are contained in it. */
1808 push_iterator_stack ();
1809 push_label_level ();
1810 $$ = expand_start_stmt_expr ();
1814 compstmt: compstmt_start compstmt_nostart
1818 /* Value is number of statements counted as of the closeparen. */
1820 if_prefix lineno_labeled_stmt
1821 /* Make sure c_expand_end_cond is run once
1822 for each call to c_expand_start_cond.
1823 Otherwise a crash is likely. */
1829 { emit_line_note ($<filename>-1, $<lineno>0);
1830 c_expand_start_cond (truthvalue_conversion ($3), 0,
1832 $<itype>$ = stmt_count;
1833 if_stmt_file = $<filename>-1;
1834 if_stmt_line = $<lineno>0;
1835 position_after_white_space (); }
1838 /* This is a subroutine of stmt.
1839 It is used twice, once for valid DO statements
1840 and once for catching errors in parsing the end test. */
1845 emit_line_note ($<filename>-1, $<lineno>0);
1846 /* See comment in `while' alternative, above. */
1848 expand_start_loop_continue_elsewhere (1);
1849 position_after_white_space (); }
1850 lineno_labeled_stmt WHILE
1851 { expand_loop_continue_here (); }
1855 { $$ = input_filename; }
1862 lineno_labeled_stmt:
1863 save_filename save_lineno stmt
1865 /* | save_filename save_lineno error
1868 | save_filename save_lineno label lineno_labeled_stmt
1872 lineno_stmt_or_label:
1873 save_filename save_lineno stmt_or_label
1884 /* Parse a single real statement, not including any labels. */
1891 emit_line_note ($<filename>-1, $<lineno>0);
1892 /* It appears that this should not be done--that a non-lvalue array
1893 shouldn't get an error if the value isn't used.
1894 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1895 if it appears as a top-level expression,
1896 but says nothing about non-lvalue arrays. */
1898 /* Call default_conversion to get an error
1899 on referring to a register array if pedantic. */
1900 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1901 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1902 $1 = default_conversion ($1);
1904 iterator_expand ($1); }
1906 { c_expand_start_else ();
1907 $<itype>1 = stmt_count;
1908 position_after_white_space (); }
1910 { c_expand_end_cond ();
1911 if (extra_warnings && stmt_count == $<itype>1)
1912 warning ("empty body in an else-statement"); }
1913 | simple_if %prec IF
1914 { c_expand_end_cond ();
1915 /* This warning is here instead of in simple_if, because we
1916 do not want a warning if an empty if is followed by an
1917 else statement. Increment stmt_count so we don't
1918 give a second error if this is a nested `if'. */
1919 if (extra_warnings && stmt_count++ == $<itype>1)
1920 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1921 "empty body in an if-statement"); }
1922 /* Make sure c_expand_end_cond is run once
1923 for each call to c_expand_start_cond.
1924 Otherwise a crash is likely. */
1925 | simple_if ELSE error
1926 { c_expand_end_cond (); }
1929 emit_line_note ($<filename>-1, $<lineno>0);
1930 /* The emit_nop used to come before emit_line_note,
1931 but that made the nop seem like part of the preceding line.
1932 And that was confusing when the preceding line was
1933 inside of an if statement and was not really executed.
1934 I think it ought to work to put the nop after the line number.
1935 We will see. --rms, July 15, 1991. */
1938 { /* Don't start the loop till we have succeeded
1939 in parsing the end test. This is to make sure
1940 that we end every loop we start. */
1941 expand_start_loop (1);
1942 emit_line_note (input_filename, lineno);
1943 expand_exit_loop_if_false (NULL_PTR,
1944 truthvalue_conversion ($4));
1945 position_after_white_space (); }
1947 { expand_end_loop (); }
1950 { emit_line_note (input_filename, lineno);
1951 expand_exit_loop_if_false (NULL_PTR,
1952 truthvalue_conversion ($3));
1953 expand_end_loop (); }
1954 /* This rule is needed to make sure we end every loop we start. */
1955 | do_stmt_start error
1956 { expand_end_loop (); }
1960 emit_line_note ($<filename>-1, $<lineno>0);
1961 /* See comment in `while' alternative, above. */
1963 if ($3) c_expand_expr_stmt ($3);
1964 /* Next step is to call expand_start_loop_continue_elsewhere,
1965 but wait till after we parse the entire for (...).
1966 Otherwise, invalid input might cause us to call that
1967 fn without calling expand_end_loop. */
1970 /* Can't emit now; wait till after expand_start_loop... */
1971 { $<lineno>7 = lineno;
1972 $<filename>$ = input_filename; }
1975 /* Start the loop. Doing this after parsing
1976 all the expressions ensures we will end the loop. */
1977 expand_start_loop_continue_elsewhere (1);
1978 /* Emit the end-test, with a line number. */
1979 emit_line_note ($<filename>8, $<lineno>7);
1981 expand_exit_loop_if_false (NULL_PTR,
1982 truthvalue_conversion ($6));
1983 $<lineno>7 = lineno;
1984 $<filename>8 = input_filename;
1985 position_after_white_space (); }
1987 { /* Emit the increment expression, with a line number. */
1988 emit_line_note ($<filename>8, $<lineno>7);
1989 expand_loop_continue_here ();
1991 c_expand_expr_stmt ($9);
1992 expand_end_loop (); }
1993 | SWITCH '(' expr ')'
1995 emit_line_note ($<filename>-1, $<lineno>0);
1996 c_expand_start_case ($3);
1997 position_after_white_space (); }
1999 { expand_end_case ($3); }
2002 emit_line_note ($<filename>-1, $<lineno>0);
2003 if ( ! expand_exit_something ())
2004 error ("break statement not within loop or switch"); }
2007 emit_line_note ($<filename>-1, $<lineno>0);
2008 if (! expand_continue_loop (NULL_PTR))
2009 error ("continue statement not within a loop"); }
2012 emit_line_note ($<filename>-1, $<lineno>0);
2013 c_expand_return (NULL_TREE); }
2016 emit_line_note ($<filename>-1, $<lineno>0);
2017 c_expand_return ($2); }
2018 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2020 emit_line_note ($<filename>-1, $<lineno>0);
2022 if ((TREE_CODE ($4) == ADDR_EXPR
2023 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
2024 || TREE_CODE ($4) == STRING_CST)
2027 error ("argument of `asm' is not a constant string"); }
2028 /* This is the case with just output operands. */
2029 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2031 emit_line_note ($<filename>-1, $<lineno>0);
2032 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2033 $2 == ridpointers[(int)RID_VOLATILE],
2034 input_filename, lineno); }
2035 /* This is the case with input operands as well. */
2036 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2038 emit_line_note ($<filename>-1, $<lineno>0);
2039 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2040 $2 == ridpointers[(int)RID_VOLATILE],
2041 input_filename, lineno); }
2042 /* This is the case with clobbered registers as well. */
2043 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2044 asm_operands ':' asm_clobbers ')' ';'
2046 emit_line_note ($<filename>-1, $<lineno>0);
2047 c_expand_asm_operands ($4, $6, $8, $10,
2048 $2 == ridpointers[(int)RID_VOLATILE],
2049 input_filename, lineno); }
2050 | GOTO identifier ';'
2053 emit_line_note ($<filename>-1, $<lineno>0);
2054 decl = lookup_label ($2);
2057 TREE_USED (decl) = 1;
2063 pedwarn ("ANSI C forbids `goto *expr;'");
2065 emit_line_note ($<filename>-1, $<lineno>0);
2066 expand_computed_goto (convert (ptr_type_node, $3)); }
2071 all_iter_stmt_simple
2072 /* | all_iter_stmt_with_decl */
2075 all_iter_stmt_simple:
2078 /* The value returned by this action is */
2079 /* 1 if everything is OK */
2080 /* 0 in case of error or already bound iterator */
2083 if (TREE_CODE ($3) != VAR_DECL)
2084 error ("invalid `for (ITERATOR)' syntax");
2085 else if (! ITERATOR_P ($3))
2086 error ("`%s' is not an iterator",
2087 IDENTIFIER_POINTER (DECL_NAME ($3)));
2088 else if (ITERATOR_BOUND_P ($3))
2089 error ("`for (%s)' inside expansion of same iterator",
2090 IDENTIFIER_POINTER (DECL_NAME ($3)));
2094 iterator_for_loop_start ($3);
2100 iterator_for_loop_end ($3);
2103 /* This really should allow any kind of declaration,
2104 for generality. Fix it before turning it back on.
2106 all_iter_stmt_with_decl:
2107 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2109 */ /* The value returned by this action is */
2110 /* 1 if everything is OK */
2111 /* 0 in case of error or already bound iterator */
2113 iterator_for_loop_start ($6);
2117 iterator_for_loop_end ($6);
2118 emit_line_note (input_filename, lineno);
2119 expand_end_bindings (getdecls (), 1, 0);
2120 $<ttype>$ = poplevel (1, 1, 0);
2124 /* Any kind of label, including jump labels and case labels.
2125 ANSI C accepts labels only before statements, but we allow them
2126 also at the end of a compound statement. */
2128 label: CASE expr_no_commas ':'
2129 { register tree value = check_case_value ($2);
2131 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2135 if (value != error_mark_node)
2140 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2141 pedwarn ("label must have integral type in ANSI C");
2143 success = pushcase (value, convert_and_check,
2147 error ("case label not within a switch statement");
2148 else if (success == 2)
2150 error ("duplicate case value");
2151 error_with_decl (duplicate, "this is the first entry for that value");
2153 else if (success == 3)
2154 warning ("case value out of range");
2155 else if (success == 5)
2156 error ("case label within scope of cleanup or variable array");
2158 position_after_white_space (); }
2159 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2160 { register tree value1 = check_case_value ($2);
2161 register tree value2 = check_case_value ($4);
2163 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2166 pedwarn ("ANSI C forbids case ranges");
2169 if (value1 != error_mark_node && value2 != error_mark_node)
2172 int success = pushcase_range (value1, value2,
2173 convert_and_check, label,
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 == 4)
2185 warning ("empty case range");
2186 else if (success == 5)
2187 error ("case label within scope of cleanup or variable array");
2189 position_after_white_space (); }
2194 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2195 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2198 error ("default label not within a switch statement");
2199 else if (success == 2)
2201 error ("multiple default labels in one switch");
2202 error_with_decl (duplicate, "this is the first default label");
2204 position_after_white_space (); }
2205 | identifier ':' maybe_attribute
2206 { tree label = define_label (input_filename, lineno, $1);
2211 expand_label (label);
2212 decl_attributes (label, $3, NULL_TREE);
2214 position_after_white_space (); }
2217 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2221 { emit_line_note (input_filename, lineno);
2224 { emit_line_note (input_filename, lineno); }
2233 /* These are the operands other than the first string and colon
2234 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2235 asm_operands: /* empty */
2237 | nonnull_asm_operands
2240 nonnull_asm_operands:
2242 | nonnull_asm_operands ',' asm_operand
2243 { $$ = chainon ($1, $3); }
2248 { $$ = build_tree_list ($1, $3); }
2253 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2254 | asm_clobbers ',' string
2255 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2258 /* This is what appears inside the parens in a function declarator.
2259 Its value is a list of ..._TYPE nodes. */
2262 clear_parm_order ();
2263 declare_parm_level (0); }
2266 parmlist_tags_warning ();
2267 poplevel (0, 0, 0); }
2275 pedwarn ("ANSI C forbids forward parameter declarations");
2276 /* Mark the forward decls as such. */
2277 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2278 TREE_ASM_WRITTEN (parm) = 1;
2279 clear_parm_order (); }
2283 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2286 /* This is what appears inside the parens in a function declarator.
2287 Is value is represented in the format that grokdeclarator expects. */
2288 parmlist_2: /* empty */
2289 { $$ = get_parm_info (0); }
2291 { $$ = get_parm_info (0);
2292 /* Gcc used to allow this as an extension. However, it does
2293 not work for all targets, and thus has been disabled.
2294 Also, since func (...) and func () are indistinguishable,
2295 it caused problems with the code in expand_builtin which
2296 tries to verify that BUILT_IN_NEXT_ARG is being used
2298 error ("ANSI C requires a named argument before `...'");
2301 { $$ = get_parm_info (1); }
2302 | parms ',' ELLIPSIS
2303 { $$ = get_parm_info (0); }
2308 { push_parm_decl ($1); }
2310 { push_parm_decl ($3); }
2313 /* A single parameter declaration or parameter type name,
2314 as found in a parmlist. */
2316 typed_declspecs setspecs parm_declarator maybe_attribute
2317 { $$ = build_tree_list (build_tree_list (current_declspecs,
2319 build_tree_list (prefix_attributes,
2321 current_declspecs = TREE_VALUE (declspec_stack);
2322 prefix_attributes = TREE_PURPOSE (declspec_stack);
2323 declspec_stack = TREE_CHAIN (declspec_stack); }
2324 | typed_declspecs setspecs notype_declarator maybe_attribute
2325 { $$ = build_tree_list (build_tree_list (current_declspecs,
2327 build_tree_list (prefix_attributes,
2329 current_declspecs = TREE_VALUE (declspec_stack);
2330 prefix_attributes = TREE_PURPOSE (declspec_stack);
2331 declspec_stack = TREE_CHAIN (declspec_stack); }
2332 | typed_declspecs setspecs absdcl maybe_attribute
2333 { $$ = build_tree_list (build_tree_list (current_declspecs,
2335 build_tree_list (prefix_attributes,
2337 current_declspecs = TREE_VALUE (declspec_stack);
2338 prefix_attributes = TREE_PURPOSE (declspec_stack);
2339 declspec_stack = TREE_CHAIN (declspec_stack); }
2340 | declmods setspecs notype_declarator maybe_attribute
2341 { $$ = build_tree_list (build_tree_list (current_declspecs,
2343 build_tree_list (prefix_attributes,
2345 current_declspecs = TREE_VALUE (declspec_stack);
2346 prefix_attributes = TREE_PURPOSE (declspec_stack);
2347 declspec_stack = TREE_CHAIN (declspec_stack); }
2349 | declmods setspecs absdcl maybe_attribute
2350 { $$ = build_tree_list (build_tree_list (current_declspecs,
2352 build_tree_list (prefix_attributes,
2354 current_declspecs = TREE_VALUE (declspec_stack);
2355 prefix_attributes = TREE_PURPOSE (declspec_stack);
2356 declspec_stack = TREE_CHAIN (declspec_stack); }
2359 /* This is used in a function definition
2360 where either a parmlist or an identifier list is ok.
2361 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2362 parmlist_or_identifiers:
2364 clear_parm_order ();
2365 declare_parm_level (1); }
2366 parmlist_or_identifiers_1
2368 parmlist_tags_warning ();
2369 poplevel (0, 0, 0); }
2372 parmlist_or_identifiers_1:
2376 for (t = $1; t; t = TREE_CHAIN (t))
2377 if (TREE_VALUE (t) == NULL_TREE)
2378 error ("`...' in old-style identifier list");
2379 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2382 /* A nonempty list of identifiers. */
2385 { $$ = build_tree_list (NULL_TREE, $1); }
2386 | identifiers ',' IDENTIFIER
2387 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2390 /* A nonempty list of identifiers, including typenames. */
2391 identifiers_or_typenames:
2393 { $$ = build_tree_list (NULL_TREE, $1); }
2394 | identifiers_or_typenames ',' identifier
2395 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2400 { $$ = SAVE_WARN_FLAGS();
2402 warn_pointer_arith = 0; }
2406 /* Objective-C productions. */
2416 if (objc_implementation_context)
2418 finish_class (objc_implementation_context);
2419 objc_ivar_chain = NULL_TREE;
2420 objc_implementation_context = NULL_TREE;
2423 warning ("`@end' must appear in an implementation context");
2427 /* A nonempty list of identifiers. */
2430 { $$ = build_tree_list (NULL_TREE, $1); }
2431 | identifier_list ',' identifier
2432 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2436 CLASS identifier_list ';'
2438 objc_declare_class ($2);
2442 ALIAS identifier identifier ';'
2444 objc_declare_alias ($2, $3);
2448 INTERFACE identifier protocolrefs '{'
2450 objc_interface_context = objc_ivar_context
2451 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2452 objc_public_flag = 0;
2456 continue_class (objc_interface_context);
2461 finish_class (objc_interface_context);
2462 objc_interface_context = NULL_TREE;
2465 | INTERFACE identifier protocolrefs
2467 objc_interface_context
2468 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2469 continue_class (objc_interface_context);
2474 finish_class (objc_interface_context);
2475 objc_interface_context = NULL_TREE;
2478 | INTERFACE identifier ':' identifier protocolrefs '{'
2480 objc_interface_context = objc_ivar_context
2481 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2482 objc_public_flag = 0;
2486 continue_class (objc_interface_context);
2491 finish_class (objc_interface_context);
2492 objc_interface_context = NULL_TREE;
2495 | INTERFACE identifier ':' identifier protocolrefs
2497 objc_interface_context
2498 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2499 continue_class (objc_interface_context);
2504 finish_class (objc_interface_context);
2505 objc_interface_context = NULL_TREE;
2508 | IMPLEMENTATION identifier '{'
2510 objc_implementation_context = objc_ivar_context
2511 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2512 objc_public_flag = 0;
2517 = continue_class (objc_implementation_context);
2520 | IMPLEMENTATION identifier
2522 objc_implementation_context
2523 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2525 = continue_class (objc_implementation_context);
2528 | IMPLEMENTATION identifier ':' identifier '{'
2530 objc_implementation_context = objc_ivar_context
2531 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2532 objc_public_flag = 0;
2537 = continue_class (objc_implementation_context);
2540 | IMPLEMENTATION identifier ':' identifier
2542 objc_implementation_context
2543 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2545 = continue_class (objc_implementation_context);
2548 | INTERFACE identifier '(' identifier ')' protocolrefs
2550 objc_interface_context
2551 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2552 continue_class (objc_interface_context);
2557 finish_class (objc_interface_context);
2558 objc_interface_context = NULL_TREE;
2561 | IMPLEMENTATION identifier '(' identifier ')'
2563 objc_implementation_context
2564 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2566 = continue_class (objc_implementation_context);
2571 PROTOCOL identifier protocolrefs
2573 remember_protocol_qualifiers ();
2574 objc_interface_context
2575 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2579 forget_protocol_qualifiers();
2580 finish_protocol(objc_interface_context);
2581 objc_interface_context = NULL_TREE;
2590 | non_empty_protocolrefs
2593 non_empty_protocolrefs:
2594 ARITHCOMPARE identifier_list ARITHCOMPARE
2596 if ($1 == LT_EXPR && $3 == GT_EXPR)
2604 ivar_decl_list visibility_spec ivar_decls
2609 PRIVATE { objc_public_flag = 2; }
2610 | PROTECTED { objc_public_flag = 0; }
2611 | PUBLIC { objc_public_flag = 1; }
2619 | ivar_decls ivar_decl ';'
2623 pedwarn ("extra semicolon in struct or union specified");
2628 /* There is a shift-reduce conflict here, because `components' may
2629 start with a `typename'. It happens that shifting (the default resolution)
2630 does the right thing, because it treats the `typename' as part of
2631 a `typed_typespecs'.
2633 It is possible that this same technique would allow the distinction
2634 between `notype_initdecls' and `initdecls' to be eliminated.
2635 But I am being cautious and not trying it. */
2638 typed_typespecs setspecs ivars
2640 current_declspecs = TREE_VALUE (declspec_stack);
2641 prefix_attributes = TREE_PURPOSE (declspec_stack);
2642 declspec_stack = TREE_CHAIN (declspec_stack); }
2643 | nonempty_type_quals setspecs ivars
2645 current_declspecs = TREE_VALUE (declspec_stack);
2646 prefix_attributes = TREE_PURPOSE (declspec_stack);
2647 declspec_stack = TREE_CHAIN (declspec_stack); }
2656 | ivars ',' ivar_declarator
2662 $$ = add_instance_variable (objc_ivar_context,
2664 $1, current_declspecs,
2667 | declarator ':' expr_no_commas
2669 $$ = add_instance_variable (objc_ivar_context,
2671 $1, current_declspecs, $3);
2673 | ':' expr_no_commas
2675 $$ = add_instance_variable (objc_ivar_context,
2678 current_declspecs, $2);
2685 remember_protocol_qualifiers ();
2686 if (objc_implementation_context)
2687 objc_inherit_code = CLASS_METHOD_DECL;
2689 fatal ("method definition not in class context");
2693 forget_protocol_qualifiers ();
2694 add_class_method (objc_implementation_context, $3);
2695 start_method_def ($3);
2696 objc_method_context = $3;
2700 continue_method_def ();
2704 finish_method_def ();
2705 objc_method_context = NULL_TREE;
2710 remember_protocol_qualifiers ();
2711 if (objc_implementation_context)
2712 objc_inherit_code = INSTANCE_METHOD_DECL;
2714 fatal ("method definition not in class context");
2718 forget_protocol_qualifiers ();
2719 add_instance_method (objc_implementation_context, $3);
2720 start_method_def ($3);
2721 objc_method_context = $3;
2725 continue_method_def ();
2729 finish_method_def ();
2730 objc_method_context = NULL_TREE;
2734 /* the reason for the strange actions in this rule
2735 is so that notype_initdecls when reached via datadef
2736 can find a valid list of type and sc specs in $0. */
2740 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2743 methodprotolist2: /* eliminates a shift/reduce conflict */
2746 | methodprotolist2 methodproto
2747 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2758 /* Remember protocol qualifiers in prototypes. */
2759 remember_protocol_qualifiers ();
2760 objc_inherit_code = CLASS_METHOD_DECL;
2764 /* Forget protocol qualifiers here. */
2765 forget_protocol_qualifiers ();
2766 add_class_method (objc_interface_context, $3);
2772 /* Remember protocol qualifiers in prototypes. */
2773 remember_protocol_qualifiers ();
2774 objc_inherit_code = INSTANCE_METHOD_DECL;
2778 /* Forget protocol qualifiers here. */
2779 forget_protocol_qualifiers ();
2780 add_instance_method (objc_interface_context, $3);
2786 '(' typename ')' unaryselector
2788 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2793 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2796 | '(' typename ')' keywordselector optparmlist
2798 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2801 | keywordselector optparmlist
2803 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2807 /* "optarglist" assumes that start_method_def has already been called...
2808 if it is not, the "xdecls" will not be placed in the proper scope */
2815 /* to get around the following situation: "int foo (int a) int b; {}" that
2816 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2831 typed_declspecs setspecs myparms ';'
2832 { current_declspecs = TREE_VALUE (declspec_stack);
2833 prefix_attributes = TREE_PURPOSE (declspec_stack);
2834 declspec_stack = TREE_CHAIN (declspec_stack); }
2835 | typed_declspecs ';'
2836 { shadow_tag ($1); }
2838 { pedwarn ("empty declaration"); }
2843 { push_parm_decl ($1); }
2844 | myparms ',' myparm
2845 { push_parm_decl ($3); }
2848 /* A single parameter declaration or parameter type name,
2849 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2852 parm_declarator maybe_attribute
2853 { $$ = build_tree_list (build_tree_list (current_declspecs,
2855 build_tree_list (prefix_attributes,
2857 | notype_declarator maybe_attribute
2858 { $$ = build_tree_list (build_tree_list (current_declspecs,
2860 build_tree_list (prefix_attributes,
2862 | absdcl maybe_attribute
2863 { $$ = build_tree_list (build_tree_list (current_declspecs,
2865 build_tree_list (prefix_attributes,
2876 /* oh what a kludge! */
2885 /* returns a tree list node generated by get_parm_info */
2898 | keywordselector keyworddecl
2900 $$ = chainon ($1, $2);
2912 ENUM { $$ = get_identifier (token_buffer); }
2913 | STRUCT { $$ = get_identifier (token_buffer); }
2914 | UNION { $$ = get_identifier (token_buffer); }
2915 | IF { $$ = get_identifier (token_buffer); }
2916 | ELSE { $$ = get_identifier (token_buffer); }
2917 | WHILE { $$ = get_identifier (token_buffer); }
2918 | DO { $$ = get_identifier (token_buffer); }
2919 | FOR { $$ = get_identifier (token_buffer); }
2920 | SWITCH { $$ = get_identifier (token_buffer); }
2921 | CASE { $$ = get_identifier (token_buffer); }
2922 | DEFAULT { $$ = get_identifier (token_buffer); }
2923 | BREAK { $$ = get_identifier (token_buffer); }
2924 | CONTINUE { $$ = get_identifier (token_buffer); }
2925 | RETURN { $$ = get_identifier (token_buffer); }
2926 | GOTO { $$ = get_identifier (token_buffer); }
2927 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2928 | SIZEOF { $$ = get_identifier (token_buffer); }
2929 | TYPEOF { $$ = get_identifier (token_buffer); }
2930 | ALIGNOF { $$ = get_identifier (token_buffer); }
2931 | TYPESPEC | TYPE_QUAL
2935 selector ':' '(' typename ')' identifier
2937 $$ = build_keyword_decl ($1, $4, $6);
2940 | selector ':' identifier
2942 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2945 | ':' '(' typename ')' identifier
2947 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2952 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2963 | keywordarglist keywordarg
2965 $$ = chainon ($1, $2);
2973 if (TREE_CHAIN ($1) == NULL_TREE)
2974 /* just return the expr., remove a level of indirection */
2975 $$ = TREE_VALUE ($1);
2977 /* we have a comma expr., we will collapse later */
2983 selector ':' keywordexpr
2985 $$ = build_tree_list ($1, $3);
2989 $$ = build_tree_list (NULL_TREE, $2);
2997 $$ = get_class_reference ($1);
3003 { objc_receiver_context = 1; }
3005 { objc_receiver_context = 0; }
3008 $$ = build_tree_list ($3, $5);
3019 | keywordnamelist keywordname
3021 $$ = chainon ($1, $2);
3028 $$ = build_tree_list ($1, NULL_TREE);
3032 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3037 SELECTOR '(' selectorarg ')'
3044 PROTOCOL '(' identifier ')'
3050 /* extension to support C-structures in the archiver */
3053 ENCODE '(' typename ')'
3055 $$ = groktypename ($3);