1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* This file defines the grammar of C and that of Objective C.
22 ifobjc ... end ifobjc conditionals contain code for Objective C only.
23 ifc ... end ifc conditionals contain code for C only.
24 Sed commands in Makefile.in are used to convert this file into
25 c-parse.y and into objc-parse.y. */
27 /* To whomever it may concern: I have heard that such a thing was once
28 written by AT&T, but I have never seen it. */
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
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;
232 /* Objective-C specific information */
234 tree objc_interface_context;
235 tree objc_implementation_context;
236 tree objc_method_context;
237 tree objc_ivar_chain;
238 tree objc_ivar_context;
239 enum tree_code objc_inherit_code;
240 int objc_receiver_context;
241 int objc_public_flag;
245 /* Tell yyparse how to print a token's value, if yydebug is set. */
247 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
248 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
250 /* Add GC roots for variables local to this file. */
254 ggc_add_tree_root (&declspec_stack, 1);
255 ggc_add_tree_root (¤t_declspecs, 1);
256 ggc_add_tree_root (&prefix_attributes, 1);
264 pedwarn ("ANSI C forbids an empty source file");
269 /* In case there were missing closebraces,
270 get us back to the global binding level. */
271 while (! global_bindings_p ())
277 /* the reason for the strange actions in this rule
278 is so that notype_initdecls when reached via datadef
279 can find a valid list of type and sc specs in $0. */
282 {$<ttype>$ = NULL_TREE; } extdef
283 | extdefs {$<ttype>$ = NULL_TREE; } extdef
292 | ASM_KEYWORD '(' expr ')' ';'
294 if ((TREE_CODE ($3) == ADDR_EXPR
295 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
296 || TREE_CODE ($3) == STRING_CST)
299 error ("argument of `asm' is not a constant string"); }
301 { pedantic = $<itype>1; }
305 setspecs notype_initdecls ';'
307 error ("ANSI C forbids data definition with no type or storage class");
308 else if (!flag_traditional)
309 warning ("data definition has no type or storage class");
311 current_declspecs = TREE_VALUE (declspec_stack);
312 prefix_attributes = TREE_PURPOSE (declspec_stack);
313 declspec_stack = TREE_CHAIN (declspec_stack);
314 resume_momentary ($1); }
315 | declmods setspecs notype_initdecls ';'
316 { current_declspecs = TREE_VALUE (declspec_stack);
317 prefix_attributes = TREE_PURPOSE (declspec_stack);
318 declspec_stack = TREE_CHAIN (declspec_stack);
319 resume_momentary ($2); }
320 | typed_declspecs setspecs initdecls ';'
321 { current_declspecs = TREE_VALUE (declspec_stack);
322 prefix_attributes = TREE_PURPOSE (declspec_stack);
323 declspec_stack = TREE_CHAIN (declspec_stack);
324 resume_momentary ($2); }
326 { pedwarn ("empty declaration"); }
327 | typed_declspecs ';'
333 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
337 typed_declspecs setspecs declarator
338 { if (! start_function (current_declspecs, $3,
339 prefix_attributes, NULL_TREE, 0))
341 reinit_parse_for_function (); }
343 { store_parm_decls (); }
345 { finish_function (0);
346 current_declspecs = TREE_VALUE (declspec_stack);
347 prefix_attributes = TREE_PURPOSE (declspec_stack);
348 declspec_stack = TREE_CHAIN (declspec_stack);
349 resume_momentary ($2); }
350 | typed_declspecs setspecs declarator error
351 { current_declspecs = TREE_VALUE (declspec_stack);
352 prefix_attributes = TREE_PURPOSE (declspec_stack);
353 declspec_stack = TREE_CHAIN (declspec_stack);
354 resume_momentary ($2); }
355 | declmods setspecs notype_declarator
356 { if (! start_function (current_declspecs, $3,
357 prefix_attributes, NULL_TREE, 0))
359 reinit_parse_for_function (); }
361 { store_parm_decls (); }
363 { finish_function (0);
364 current_declspecs = TREE_VALUE (declspec_stack);
365 prefix_attributes = TREE_PURPOSE (declspec_stack);
366 declspec_stack = TREE_CHAIN (declspec_stack);
367 resume_momentary ($2); }
368 | declmods setspecs notype_declarator error
369 { current_declspecs = TREE_VALUE (declspec_stack);
370 prefix_attributes = TREE_PURPOSE (declspec_stack);
371 declspec_stack = TREE_CHAIN (declspec_stack);
372 resume_momentary ($2); }
373 | setspecs notype_declarator
374 { if (! start_function (NULL_TREE, $2,
375 prefix_attributes, NULL_TREE, 0))
377 reinit_parse_for_function (); }
379 { store_parm_decls (); }
381 { finish_function (0);
382 current_declspecs = TREE_VALUE (declspec_stack);
383 prefix_attributes = TREE_PURPOSE (declspec_stack);
384 declspec_stack = TREE_CHAIN (declspec_stack);
385 resume_momentary ($1); }
386 | setspecs notype_declarator error
387 { current_declspecs = TREE_VALUE (declspec_stack);
388 prefix_attributes = TREE_PURPOSE (declspec_stack);
389 declspec_stack = TREE_CHAIN (declspec_stack);
390 resume_momentary ($1); }
405 { $$ = NEGATE_EXPR; }
407 { $$ = CONVERT_EXPR; }
409 { $$ = PREINCREMENT_EXPR; }
411 { $$ = PREDECREMENT_EXPR; }
413 { $$ = BIT_NOT_EXPR; }
415 { $$ = TRUTH_NOT_EXPR; }
418 expr: nonnull_exprlist
419 { $$ = build_compound_expr ($1); }
430 { $$ = build_tree_list (NULL_TREE, $1); }
431 | nonnull_exprlist ',' expr_no_commas
432 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
437 | '*' cast_expr %prec UNARY
438 { $$ = build_indirect_ref ($2, "unary *"); }
439 /* __extension__ turns off -pedantic for following primary. */
440 | extension cast_expr %prec UNARY
442 pedantic = $<itype>1; }
443 | unop cast_expr %prec UNARY
444 { $$ = build_unary_op ($1, $2, 0);
445 overflow_warning ($$); }
446 /* Refer to the address of a label as a pointer. */
448 { tree label = lookup_label ($2);
450 pedwarn ("ANSI C forbids `&&'");
452 $$ = null_pointer_node;
455 TREE_USED (label) = 1;
456 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
457 TREE_CONSTANT ($$) = 1;
460 /* This seems to be impossible on some machines, so let's turn it off.
461 You can use __builtin_next_arg to find the anonymous stack args.
463 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
464 $$ = error_mark_node;
465 if (TREE_VALUE (tree_last (types)) == void_type_node)
466 error ("`&...' used in function with fixed number of arguments");
470 pedwarn ("ANSI C forbids `&...'");
471 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
472 $$ = build_unary_op (ADDR_EXPR, $$, 0);
475 | sizeof unary_expr %prec UNARY
477 if (TREE_CODE ($2) == COMPONENT_REF
478 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
479 error ("`sizeof' applied to a bit-field");
480 $$ = c_sizeof (TREE_TYPE ($2)); }
481 | sizeof '(' typename ')' %prec HYPERUNARY
483 $$ = c_sizeof (groktypename ($3)); }
484 | alignof unary_expr %prec UNARY
486 $$ = c_alignof_expr ($2); }
487 | alignof '(' typename ')' %prec HYPERUNARY
489 $$ = c_alignof (groktypename ($3)); }
490 | REALPART cast_expr %prec UNARY
491 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
492 | IMAGPART cast_expr %prec UNARY
493 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
494 | VA_ARG '(' expr_no_commas ',' typename ')'
495 { $$ = build_va_arg ($3, groktypename ($5)); }
499 SIZEOF { skip_evaluation++; }
503 ALIGNOF { skip_evaluation++; }
508 | '(' typename ')' cast_expr %prec UNARY
509 { tree type = groktypename ($2);
510 $$ = build_c_cast (type, $4); }
511 | '(' typename ')' '{'
512 { start_init (NULL_TREE, NULL, 0);
513 $2 = groktypename ($2);
514 really_start_incremental_init ($2); }
515 initlist_maybe_comma '}' %prec UNARY
517 tree result = pop_init_level (0);
521 if (pedantic && ! flag_isoc9x)
522 pedwarn ("ANSI C forbids constructor expressions");
523 if (TYPE_NAME (type) != 0)
525 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
526 name = IDENTIFIER_POINTER (TYPE_NAME (type));
528 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
533 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
535 int failure = complete_array_type (type, $$, 1);
544 | expr_no_commas '+' expr_no_commas
545 { $$ = parser_build_binary_op ($2, $1, $3); }
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 LSHIFT expr_no_commas
555 { $$ = parser_build_binary_op ($2, $1, $3); }
556 | expr_no_commas RSHIFT expr_no_commas
557 { $$ = parser_build_binary_op ($2, $1, $3); }
558 | expr_no_commas ARITHCOMPARE expr_no_commas
559 { $$ = parser_build_binary_op ($2, $1, $3); }
560 | expr_no_commas EQCOMPARE expr_no_commas
561 { $$ = parser_build_binary_op ($2, $1, $3); }
562 | expr_no_commas '&' 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 ANDAND
569 { $1 = truthvalue_conversion (default_conversion ($1));
570 skip_evaluation += $1 == boolean_false_node; }
572 { skip_evaluation -= $1 == boolean_false_node;
573 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
574 | expr_no_commas OROR
575 { $1 = truthvalue_conversion (default_conversion ($1));
576 skip_evaluation += $1 == boolean_true_node; }
578 { skip_evaluation -= $1 == boolean_true_node;
579 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
581 { $1 = truthvalue_conversion (default_conversion ($1));
582 skip_evaluation += $1 == boolean_false_node; }
584 { skip_evaluation += (($1 == boolean_true_node)
585 - ($1 == boolean_false_node)); }
587 { skip_evaluation -= $1 == boolean_true_node;
588 $$ = build_conditional_expr ($1, $4, $7); }
591 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
592 /* Make sure first operand is calculated only once. */
593 $<ttype>2 = save_expr ($1);
594 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
595 skip_evaluation += $1 == boolean_true_node; }
597 { skip_evaluation -= $1 == boolean_true_node;
598 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
599 | expr_no_commas '=' expr_no_commas
601 $$ = build_modify_expr ($1, NOP_EXPR, $3);
602 class = TREE_CODE_CLASS (TREE_CODE ($$));
603 if (class == 'e' || class == '1'
604 || class == '2' || class == '<')
605 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
607 | expr_no_commas ASSIGN expr_no_commas
609 $$ = build_modify_expr ($1, $2, $3);
610 /* This inhibits warnings in truthvalue_conversion. */
611 class = TREE_CODE_CLASS (TREE_CODE ($$));
612 if (class == 'e' || class == '1'
613 || class == '2' || class == '<')
614 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
622 if (!$$ || $$ == error_mark_node)
624 if (yychar == YYEMPTY)
631 if (objc_receiver_context
632 && ! (objc_receiver_context
633 && strcmp (IDENTIFIER_POINTER ($1), "super")))
634 /* we have a message to super */
635 $$ = get_super_receiver ();
636 else if (objc_method_context
637 && (decl = is_ivar (objc_ivar_chain, $1)))
639 if (is_private (decl))
640 $$ = error_mark_node;
642 $$ = build_ivar_reference ($1);
647 /* Ordinary implicit function declaration. */
648 $$ = implicitly_declare ($1);
649 assemble_external ($$);
653 else if (current_function_decl == 0)
655 error ("`%s' undeclared here (not in a function)",
656 IDENTIFIER_POINTER ($1));
657 $$ = error_mark_node;
664 if (objc_receiver_context
665 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
666 /* we have a message to super */
667 $$ = get_super_receiver ();
668 else if (objc_method_context
669 && (decl = is_ivar (objc_ivar_chain, $1)))
671 if (is_private (decl))
672 $$ = error_mark_node;
674 $$ = build_ivar_reference ($1);
679 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
680 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
682 error ("`%s' undeclared (first use in this function)",
683 IDENTIFIER_POINTER ($1));
685 if (! undeclared_variable_notice)
687 error ("(Each undeclared identifier is reported only once");
688 error ("for each function it appears in.)");
689 undeclared_variable_notice = 1;
692 $$ = error_mark_node;
693 /* Prevent repeated error messages. */
694 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
695 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
699 else if (TREE_TYPE ($$) == error_mark_node)
700 $$ = error_mark_node;
701 else if (C_DECL_ANTICIPATED ($$))
703 /* The first time we see a build-in function used,
704 if it has not been declared. */
705 C_DECL_ANTICIPATED ($$) = 0;
706 if (yychar == YYEMPTY)
710 /* Omit the implicit declaration we
711 would ordinarily do, so we don't lose
712 the actual built in type.
713 But print a diagnostic for the mismatch. */
715 if (objc_method_context
716 && is_ivar (objc_ivar_chain, $1))
717 error ("Instance variable `%s' implicitly declared as function",
718 IDENTIFIER_POINTER (DECL_NAME ($$)));
721 if (TREE_CODE ($$) != FUNCTION_DECL)
722 error ("`%s' implicitly declared as function",
723 IDENTIFIER_POINTER (DECL_NAME ($$)));
724 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
725 != TYPE_MODE (integer_type_node))
726 && (TREE_TYPE (TREE_TYPE ($$))
728 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
729 IDENTIFIER_POINTER (DECL_NAME ($$)));
730 /* If it really returns void, change that to int. */
731 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
733 = build_function_type (integer_type_node,
734 TYPE_ARG_TYPES (TREE_TYPE ($$)));
737 pedwarn ("built-in function `%s' used without declaration",
738 IDENTIFIER_POINTER (DECL_NAME ($$)));
740 /* Do what we would ordinarily do when a fn is used. */
741 assemble_external ($$);
746 assemble_external ($$);
749 /* we have a definition - still check if iVariable */
751 if (!objc_receiver_context
752 || (objc_receiver_context
753 && strcmp (IDENTIFIER_POINTER ($1), "super")))
757 if (objc_method_context
758 && (decl = is_ivar (objc_ivar_chain, $1)))
760 if (IDENTIFIER_LOCAL_VALUE ($1))
761 warning ("local declaration of `%s' hides instance variable",
762 IDENTIFIER_POINTER ($1));
765 if (is_private (decl))
766 $$ = error_mark_node;
768 $$ = build_ivar_reference ($1);
772 else /* we have a message to super */
773 $$ = get_super_receiver ();
777 if (TREE_CODE ($$) == CONST_DECL)
779 $$ = DECL_INITIAL ($$);
780 /* This is to prevent an enum whose value is 0
781 from being considered a null pointer constant. */
782 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
783 TREE_CONSTANT ($$) = 1;
788 { $$ = combine_strings ($1); }
790 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
791 if (class == 'e' || class == '1'
792 || class == '2' || class == '<')
793 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
796 { $$ = error_mark_node; }
797 | compstmt_primary_start compstmt_nostart ')'
800 pedwarn ("ANSI C forbids braced-groups within expressions");
801 pop_iterator_stack ();
803 rtl_exp = expand_end_stmt_expr ($1);
804 /* The statements have side effects, so the group does. */
805 TREE_SIDE_EFFECTS (rtl_exp) = 1;
807 if (TREE_CODE ($2) == BLOCK)
809 /* Make a BIND_EXPR for the BLOCK already made. */
810 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
811 NULL_TREE, rtl_exp, $2);
812 /* Remove the block from the tree at this point.
813 It gets put back at the proper place
814 when the BIND_EXPR is expanded. */
820 | compstmt_primary_start error ')'
822 /* Make sure we call expand_end_stmt_expr. Otherwise
823 we are likely to lose sequences and crash later. */
824 pop_iterator_stack ();
826 expand_end_stmt_expr ($1);
827 $$ = error_mark_node;
829 | primary '(' exprlist ')' %prec '.'
830 { $$ = build_function_call ($1, $3); }
831 | primary '[' expr ']' %prec '.'
832 { $$ = build_array_ref ($1, $3); }
833 | primary '.' identifier
836 if (doing_objc_thang)
838 if (is_public ($1, $3))
839 $$ = build_component_ref ($1, $3);
841 $$ = error_mark_node;
845 $$ = build_component_ref ($1, $3);
847 | primary POINTSAT identifier
849 tree expr = build_indirect_ref ($1, "->");
852 if (doing_objc_thang)
854 if (is_public (expr, $3))
855 $$ = build_component_ref (expr, $3);
857 $$ = error_mark_node;
861 $$ = build_component_ref (expr, $3);
864 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
866 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
869 { $$ = build_message_expr ($1); }
871 { $$ = build_selector_expr ($1); }
873 { $$ = build_protocol_expr ($1); }
875 { $$ = build_encode_expr ($1); }
877 { $$ = build_objc_string_object ($1); }
881 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
885 { $$ = chainon ($1, $2); }
889 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
893 | objc_string OBJC_STRING
894 { $$ = chainon ($1, $2); }
898 old_style_parm_decls:
902 /* ... is used here to indicate a varargs function. */
905 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
908 /* The following are analogous to lineno_decl, decls and decl
909 except that they do not allow nested functions.
910 They are used for old-style parm decls. */
912 save_filename save_lineno datadecl
919 | datadecls lineno_datadecl
920 | lineno_datadecl errstmt
923 /* We don't allow prefix attributes here because they cause reduce/reduce
924 conflicts: we can't know whether we're parsing a function decl with
925 attribute suffix, or function defn with attribute prefix on first old
928 typed_declspecs_no_prefix_attr setspecs initdecls ';'
929 { current_declspecs = TREE_VALUE (declspec_stack);
930 prefix_attributes = TREE_PURPOSE (declspec_stack);
931 declspec_stack = TREE_CHAIN (declspec_stack);
932 resume_momentary ($2); }
933 | declmods_no_prefix_attr setspecs notype_initdecls ';'
934 { current_declspecs = TREE_VALUE (declspec_stack);
935 prefix_attributes = TREE_PURPOSE (declspec_stack);
936 declspec_stack = TREE_CHAIN (declspec_stack);
937 resume_momentary ($2); }
938 | typed_declspecs_no_prefix_attr ';'
939 { shadow_tag_warned ($1, 1);
940 pedwarn ("empty declaration"); }
941 | declmods_no_prefix_attr ';'
942 { pedwarn ("empty declaration"); }
945 /* This combination which saves a lineno before a decl
946 is the normal thing to use, rather than decl itself.
947 This is to avoid shift/reduce conflicts in contexts
948 where statement labels are allowed. */
950 save_filename save_lineno decl
958 | lineno_decl errstmt
961 /* records the type and storage class specs to use for processing
962 the declarators that follow.
963 Maintains a stack of outer-level values of current_declspecs,
964 for the sake of parm declarations nested in function declarators. */
965 setspecs: /* empty */
966 { $$ = suspend_momentary ();
967 pending_xref_error ();
968 declspec_stack = tree_cons (prefix_attributes,
971 split_specs_attrs ($<ttype>0,
972 ¤t_declspecs, &prefix_attributes); }
975 /* ??? Yuck. See after_type_declarator. */
976 setattrs: /* empty */
977 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
981 typed_declspecs setspecs initdecls ';'
982 { current_declspecs = TREE_VALUE (declspec_stack);
983 prefix_attributes = TREE_PURPOSE (declspec_stack);
984 declspec_stack = TREE_CHAIN (declspec_stack);
985 resume_momentary ($2); }
986 | declmods setspecs notype_initdecls ';'
987 { current_declspecs = TREE_VALUE (declspec_stack);
988 prefix_attributes = TREE_PURPOSE (declspec_stack);
989 declspec_stack = TREE_CHAIN (declspec_stack);
990 resume_momentary ($2); }
991 | typed_declspecs setspecs nested_function
992 { current_declspecs = TREE_VALUE (declspec_stack);
993 prefix_attributes = TREE_PURPOSE (declspec_stack);
994 declspec_stack = TREE_CHAIN (declspec_stack);
995 resume_momentary ($2); }
996 | declmods setspecs notype_nested_function
997 { current_declspecs = TREE_VALUE (declspec_stack);
998 prefix_attributes = TREE_PURPOSE (declspec_stack);
999 declspec_stack = TREE_CHAIN (declspec_stack);
1000 resume_momentary ($2); }
1001 | typed_declspecs ';'
1002 { shadow_tag ($1); }
1004 { pedwarn ("empty declaration"); }
1006 { pedantic = $<itype>1; }
1009 /* Declspecs which contain at least one type specifier or typedef name.
1010 (Just `const' or `volatile' is not enough.)
1011 A typedef'd name following these is taken as a name to be declared.
1012 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1015 typespec reserved_declspecs
1016 { $$ = tree_cons (NULL_TREE, $1, $2); }
1017 | declmods typespec reserved_declspecs
1018 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1021 reserved_declspecs: /* empty */
1023 | reserved_declspecs typespecqual_reserved
1024 { $$ = tree_cons (NULL_TREE, $2, $1); }
1025 | reserved_declspecs SCSPEC
1026 { if (extra_warnings)
1027 warning ("`%s' is not at beginning of declaration",
1028 IDENTIFIER_POINTER ($2));
1029 $$ = tree_cons (NULL_TREE, $2, $1); }
1030 | reserved_declspecs attributes
1031 { $$ = tree_cons ($2, NULL_TREE, $1); }
1034 typed_declspecs_no_prefix_attr:
1035 typespec reserved_declspecs_no_prefix_attr
1036 { $$ = tree_cons (NULL_TREE, $1, $2); }
1037 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
1038 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1041 reserved_declspecs_no_prefix_attr:
1044 | reserved_declspecs_no_prefix_attr typespecqual_reserved
1045 { $$ = tree_cons (NULL_TREE, $2, $1); }
1046 | reserved_declspecs_no_prefix_attr SCSPEC
1047 { if (extra_warnings)
1048 warning ("`%s' is not at beginning of declaration",
1049 IDENTIFIER_POINTER ($2));
1050 $$ = tree_cons (NULL_TREE, $2, $1); }
1053 /* List of just storage classes, type modifiers, and prefix attributes.
1054 A declaration can start with just this, but then it cannot be used
1055 to redeclare a typedef-name.
1056 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
1059 declmods_no_prefix_attr
1062 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
1063 | declmods declmods_no_prefix_attr
1064 { $$ = chainon ($2, $1); }
1065 | declmods attributes
1066 { $$ = tree_cons ($2, NULL_TREE, $1); }
1069 declmods_no_prefix_attr:
1071 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
1072 TREE_STATIC ($$) = 1; }
1074 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1075 | declmods_no_prefix_attr TYPE_QUAL
1076 { $$ = tree_cons (NULL_TREE, $2, $1);
1077 TREE_STATIC ($$) = 1; }
1078 | declmods_no_prefix_attr SCSPEC
1079 { if (extra_warnings && TREE_STATIC ($1))
1080 warning ("`%s' is not at beginning of declaration",
1081 IDENTIFIER_POINTER ($2));
1082 $$ = tree_cons (NULL_TREE, $2, $1);
1083 TREE_STATIC ($$) = TREE_STATIC ($1); }
1087 /* Used instead of declspecs where storage classes are not allowed
1088 (that is, for typenames and structure components).
1089 Don't accept a typedef-name if anything but a modifier precedes it. */
1092 typespec reserved_typespecquals
1093 { $$ = tree_cons (NULL_TREE, $1, $2); }
1094 | nonempty_type_quals typespec reserved_typespecquals
1095 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
1098 reserved_typespecquals: /* empty */
1100 | reserved_typespecquals typespecqual_reserved
1101 { $$ = tree_cons (NULL_TREE, $2, $1); }
1104 /* A typespec (but not a type qualifier).
1105 Once we have seen one of these in a declaration,
1106 if a typedef name appears then it is being redeclared. */
1111 { /* For a typedef name, record the meaning, not the name.
1112 In case of `foo foo, bar;'. */
1113 $$ = lookup_name ($1); }
1115 | CLASSNAME protocolrefs
1116 { $$ = get_static_reference ($1, $2); }
1117 | OBJECTNAME protocolrefs
1118 { $$ = get_object_reference ($2); }
1120 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
1121 - nisse@lysator.liu.se */
1122 | non_empty_protocolrefs
1123 { $$ = get_object_reference ($1); }
1125 | TYPEOF '(' expr ')'
1126 { $$ = TREE_TYPE ($3); }
1127 | TYPEOF '(' typename ')'
1128 { $$ = groktypename ($3); }
1131 /* A typespec that is a reserved word, or a type qualifier. */
1133 typespecqual_reserved: TYPESPEC
1140 | initdecls ',' initdcl
1145 | notype_initdecls ',' initdcl
1151 | ASM_KEYWORD '(' string ')'
1152 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1158 declarator maybeasm maybe_attribute '='
1159 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1160 $3, prefix_attributes);
1161 start_init ($<ttype>$, $2, global_bindings_p ()); }
1163 /* Note how the declaration of the variable is in effect while its init is parsed! */
1165 finish_decl ($<ttype>5, $6, $2); }
1166 | declarator maybeasm maybe_attribute
1167 { tree d = start_decl ($1, current_declspecs, 0,
1168 $3, prefix_attributes);
1169 finish_decl (d, NULL_TREE, $2);
1174 notype_declarator maybeasm maybe_attribute '='
1175 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1176 $3, prefix_attributes);
1177 start_init ($<ttype>$, $2, global_bindings_p ()); }
1179 /* Note how the declaration of the variable is in effect while its init is parsed! */
1181 decl_attributes ($<ttype>5, $3, prefix_attributes);
1182 finish_decl ($<ttype>5, $6, $2); }
1183 | notype_declarator maybeasm maybe_attribute
1184 { tree d = start_decl ($1, current_declspecs, 0,
1185 $3, prefix_attributes);
1186 finish_decl (d, NULL_TREE, $2); }
1188 /* the * rules are dummies to accept the Apollo extended syntax
1189 so that the header files compile. */
1200 | attributes attribute
1201 { $$ = chainon ($1, $2); }
1205 ATTRIBUTE '(' '(' attribute_list ')' ')'
1212 | attribute_list ',' attrib
1213 { $$ = chainon ($1, $3); }
1220 { $$ = build_tree_list ($1, NULL_TREE); }
1221 | any_word '(' IDENTIFIER ')'
1222 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1223 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1224 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1225 | any_word '(' exprlist ')'
1226 { $$ = build_tree_list ($1, $3); }
1229 /* This still leaves out most reserved keywords,
1230 shouldn't we include them? */
1239 /* Initializers. `init' is the entry point. */
1244 { really_start_incremental_init (NULL_TREE);
1245 /* Note that the call to clear_momentary
1246 is in process_init_element. */
1247 push_momentary (); }
1248 initlist_maybe_comma '}'
1249 { $$ = pop_init_level (0);
1250 if ($$ == error_mark_node
1251 && ! (yychar == STRING || yychar == CONSTANT))
1254 pop_momentary_nofree (); }
1257 { $$ = error_mark_node; }
1260 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1261 initlist_maybe_comma:
1264 pedwarn ("ANSI C forbids empty initializer braces"); }
1265 | initlist1 maybecomma
1270 | initlist1 ',' initelt
1273 /* `initelt' is a single element of an initializer.
1274 It may use braces. */
1276 designator_list '=' initval
1277 | designator initval
1279 { set_init_label ($1); }
1286 { push_init_level (0); }
1287 initlist_maybe_comma '}'
1288 { process_init_element (pop_init_level (0)); }
1290 { process_init_element ($1); }
1296 | designator_list designator
1301 { set_init_label ($2); }
1302 /* These are for labeled elements. The syntax for an array element
1303 initializer conflicts with the syntax for an Objective-C message,
1304 so don't include these productions in the Objective-C grammar. */
1306 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1307 { set_init_index ($2, $4); }
1308 | '[' expr_no_commas ']'
1309 { set_init_index ($2, NULL_TREE); }
1316 pedwarn ("ANSI C forbids nested functions");
1318 push_function_context ();
1319 if (! start_function (current_declspecs, $1,
1320 prefix_attributes, NULL_TREE, 1))
1322 pop_function_context ();
1325 reinit_parse_for_function (); }
1326 old_style_parm_decls
1327 { store_parm_decls (); }
1328 /* This used to use compstmt_or_error.
1329 That caused a bug with input `f(g) int g {}',
1330 where the use of YYERROR1 above caused an error
1331 which then was handled by compstmt_or_error.
1332 There followed a repeated execution of that same rule,
1333 which called YYERROR1 again, and so on. */
1335 { finish_function (1);
1336 pop_function_context (); }
1339 notype_nested_function:
1342 pedwarn ("ANSI C forbids nested functions");
1344 push_function_context ();
1345 if (! start_function (current_declspecs, $1,
1346 prefix_attributes, NULL_TREE, 1))
1348 pop_function_context ();
1351 reinit_parse_for_function (); }
1352 old_style_parm_decls
1353 { store_parm_decls (); }
1354 /* This used to use compstmt_or_error.
1355 That caused a bug with input `f(g) int g {}',
1356 where the use of YYERROR1 above caused an error
1357 which then was handled by compstmt_or_error.
1358 There followed a repeated execution of that same rule,
1359 which called YYERROR1 again, and so on. */
1361 { finish_function (1);
1362 pop_function_context (); }
1365 /* Any kind of declarator (thus, all declarators allowed
1366 after an explicit typespec). */
1369 after_type_declarator
1373 /* A declarator that is allowed only after an explicit typespec. */
1375 after_type_declarator:
1376 '(' after_type_declarator ')'
1378 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1379 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1380 /* | after_type_declarator '(' error ')' %prec '.'
1381 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1382 poplevel (0, 0, 0); } */
1383 | after_type_declarator '[' expr ']' %prec '.'
1384 { $$ = build_nt (ARRAY_REF, $1, $3); }
1385 | after_type_declarator '[' ']' %prec '.'
1386 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1387 | '*' type_quals after_type_declarator %prec UNARY
1388 { $$ = make_pointer_declarator ($2, $3); }
1389 /* ??? Yuck. setattrs is a quick hack. We can't use
1390 prefix_attributes because $1 only applies to this
1391 declarator. We assume setspecs has already been done.
1392 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1393 attributes could be recognized here or in `attributes'). */
1394 | attributes setattrs after_type_declarator
1402 /* Kinds of declarator that can appear in a parameter list
1403 in addition to notype_declarator. This is like after_type_declarator
1404 but does not allow a typedef name in parentheses as an identifier
1405 (because it would conflict with a function with that typedef as arg). */
1408 parm_declarator '(' parmlist_or_identifiers %prec '.'
1409 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1410 /* | parm_declarator '(' error ')' %prec '.'
1411 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1412 poplevel (0, 0, 0); } */
1414 | parm_declarator '[' '*' ']' %prec '.'
1415 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1417 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1420 | parm_declarator '[' expr ']' %prec '.'
1421 { $$ = build_nt (ARRAY_REF, $1, $3); }
1422 | parm_declarator '[' ']' %prec '.'
1423 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1424 | '*' type_quals parm_declarator %prec UNARY
1425 { $$ = make_pointer_declarator ($2, $3); }
1426 /* ??? Yuck. setattrs is a quick hack. We can't use
1427 prefix_attributes because $1 only applies to this
1428 declarator. We assume setspecs has already been done.
1429 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1430 attributes could be recognized here or in `attributes'). */
1431 | attributes setattrs parm_declarator
1436 /* A declarator allowed whether or not there has been
1437 an explicit typespec. These cannot redeclare a typedef-name. */
1440 notype_declarator '(' parmlist_or_identifiers %prec '.'
1441 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1442 /* | notype_declarator '(' error ')' %prec '.'
1443 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1444 poplevel (0, 0, 0); } */
1445 | '(' notype_declarator ')'
1447 | '*' type_quals notype_declarator %prec UNARY
1448 { $$ = make_pointer_declarator ($2, $3); }
1450 | notype_declarator '[' '*' ']' %prec '.'
1451 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1453 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1456 | notype_declarator '[' expr ']' %prec '.'
1457 { $$ = build_nt (ARRAY_REF, $1, $3); }
1458 | notype_declarator '[' ']' %prec '.'
1459 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1460 /* ??? Yuck. setattrs is a quick hack. We can't use
1461 prefix_attributes because $1 only applies to this
1462 declarator. We assume setspecs has already been done.
1463 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1464 attributes could be recognized here or in `attributes'). */
1465 | attributes setattrs notype_declarator
1492 struct_head identifier '{'
1493 { $$ = start_struct (RECORD_TYPE, $2);
1494 /* Start scope of tag before parsing components. */
1496 component_decl_list '}' maybe_attribute
1497 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1498 | struct_head '{' component_decl_list '}' maybe_attribute
1499 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1500 $3, chainon ($1, $5));
1502 | struct_head identifier
1503 { $$ = xref_tag (RECORD_TYPE, $2); }
1504 | union_head identifier '{'
1505 { $$ = start_struct (UNION_TYPE, $2); }
1506 component_decl_list '}' maybe_attribute
1507 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1508 | union_head '{' component_decl_list '}' maybe_attribute
1509 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1510 $3, chainon ($1, $5));
1512 | union_head identifier
1513 { $$ = xref_tag (UNION_TYPE, $2); }
1514 | enum_head identifier '{'
1515 { $<itype>3 = suspend_momentary ();
1516 $$ = start_enum ($2); }
1517 enumlist maybecomma_warn '}' maybe_attribute
1518 { $$= finish_enum ($<ttype>4, nreverse ($5), chainon ($1, $8));
1519 resume_momentary ($<itype>3); }
1521 { $<itype>2 = suspend_momentary ();
1522 $$ = start_enum (NULL_TREE); }
1523 enumlist maybecomma_warn '}' maybe_attribute
1524 { $$= finish_enum ($<ttype>3, nreverse ($4), chainon ($1, $7));
1525 resume_momentary ($<itype>2); }
1526 | enum_head identifier
1527 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1538 { if (pedantic && ! flag_isoc9x)
1539 pedwarn ("comma at end of enumerator list"); }
1542 component_decl_list:
1543 component_decl_list2
1545 | component_decl_list2 component_decl
1546 { $$ = chainon ($1, $2);
1547 pedwarn ("no semicolon at end of struct or union"); }
1550 component_decl_list2: /* empty */
1552 | component_decl_list2 component_decl ';'
1553 { $$ = chainon ($1, $2); }
1554 | component_decl_list2 ';'
1556 pedwarn ("extra semicolon in struct or union specified"); }
1558 /* foo(sizeof(struct{ @defs(ClassName)})); */
1559 | DEFS '(' CLASSNAME ')'
1561 tree interface = lookup_interface ($3);
1564 $$ = get_class_ivars (interface);
1567 error ("Cannot find interface declaration for `%s'",
1568 IDENTIFIER_POINTER ($3));
1575 /* There is a shift-reduce conflict here, because `components' may
1576 start with a `typename'. It happens that shifting (the default resolution)
1577 does the right thing, because it treats the `typename' as part of
1578 a `typed_typespecs'.
1580 It is possible that this same technique would allow the distinction
1581 between `notype_initdecls' and `initdecls' to be eliminated.
1582 But I am being cautious and not trying it. */
1585 typed_typespecs setspecs components
1587 current_declspecs = TREE_VALUE (declspec_stack);
1588 prefix_attributes = TREE_PURPOSE (declspec_stack);
1589 declspec_stack = TREE_CHAIN (declspec_stack);
1590 resume_momentary ($2); }
1593 pedwarn ("ANSI C forbids member declarations with no members");
1596 | nonempty_type_quals setspecs components
1598 current_declspecs = TREE_VALUE (declspec_stack);
1599 prefix_attributes = TREE_PURPOSE (declspec_stack);
1600 declspec_stack = TREE_CHAIN (declspec_stack);
1601 resume_momentary ($2); }
1602 | nonempty_type_quals
1604 pedwarn ("ANSI C forbids member declarations with no members");
1609 | extension component_decl
1611 pedantic = $<itype>1; }
1615 component_declarator
1616 | components ',' component_declarator
1617 { $$ = chainon ($1, $3); }
1620 component_declarator:
1621 save_filename save_lineno declarator maybe_attribute
1622 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1623 decl_attributes ($$, $4, prefix_attributes); }
1624 | save_filename save_lineno
1625 declarator ':' expr_no_commas maybe_attribute
1626 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1627 decl_attributes ($$, $6, prefix_attributes); }
1628 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1629 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1630 decl_attributes ($$, $5, prefix_attributes); }
1633 /* We chain the enumerators in reverse order.
1634 They are put in forward order where enumlist is used.
1635 (The order used to be significant, but no longer is so.
1636 However, we still maintain the order, just to be clean.) */
1640 | enumlist ',' enumerator
1641 { if ($1 == error_mark_node)
1644 $$ = chainon ($3, $1); }
1646 { $$ = error_mark_node; }
1652 { $$ = build_enumerator ($1, NULL_TREE); }
1653 | identifier '=' expr_no_commas
1654 { $$ = build_enumerator ($1, $3); }
1658 typed_typespecs absdcl
1659 { $$ = build_tree_list ($1, $2); }
1660 | nonempty_type_quals absdcl
1661 { $$ = build_tree_list ($1, $2); }
1664 absdcl: /* an absolute declarator */
1670 nonempty_type_quals:
1672 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1673 | nonempty_type_quals TYPE_QUAL
1674 { $$ = tree_cons (NULL_TREE, $2, $1); }
1680 | type_quals TYPE_QUAL
1681 { $$ = tree_cons (NULL_TREE, $2, $1); }
1684 absdcl1: /* a nonempty absolute declarator */
1687 /* `(typedef)1' is `int'. */
1688 | '*' type_quals absdcl1 %prec UNARY
1689 { $$ = make_pointer_declarator ($2, $3); }
1690 | '*' type_quals %prec UNARY
1691 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1692 | absdcl1 '(' parmlist %prec '.'
1693 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1694 | absdcl1 '[' expr ']' %prec '.'
1695 { $$ = build_nt (ARRAY_REF, $1, $3); }
1696 | absdcl1 '[' ']' %prec '.'
1697 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1698 | '(' parmlist %prec '.'
1699 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1700 | '[' expr ']' %prec '.'
1701 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1703 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1704 /* ??? It appears we have to support attributes here, however
1705 using prefix_attributes is wrong. */
1706 | attributes setattrs absdcl1
1710 /* at least one statement, the first of which parses without error. */
1711 /* stmts is used only after decls, so an invalid first statement
1712 is actually regarded as an invalid decl and part of the decls. */
1715 lineno_stmt_or_labels
1718 pedwarn ("ANSI C forbids label at end of compound statement");
1722 lineno_stmt_or_labels:
1723 lineno_stmt_or_label
1724 | lineno_stmt_or_labels lineno_stmt_or_label
1726 | lineno_stmt_or_labels errstmt
1738 pushlevel: /* empty */
1739 { emit_line_note (input_filename, lineno);
1743 expand_start_bindings (0);
1745 if (objc_method_context)
1751 /* Read zero or more forward-declarations for labels
1752 that nested functions can jump to. */
1757 pedwarn ("ANSI C forbids label declarations"); }
1762 | label_decls label_decl
1766 LABEL identifiers_or_typenames ';'
1768 for (link = $2; link; link = TREE_CHAIN (link))
1770 tree label = shadow_label (TREE_VALUE (link));
1771 C_DECLARED_LABEL_FLAG (label) = 1;
1772 declare_nonlocal_label (label);
1777 /* This is the body of a function definition.
1778 It causes syntax errors to ignore to the next openbrace. */
1785 compstmt_start: '{' { compstmt_count++; }
1787 compstmt_nostart: '}'
1788 { $$ = convert (void_type_node, integer_zero_node); }
1789 | pushlevel maybe_label_decls decls xstmts '}'
1790 { emit_line_note (input_filename, lineno);
1791 expand_end_bindings (getdecls (), 1, 0);
1792 $$ = poplevel (1, 1, 0);
1793 if (yychar == CONSTANT || yychar == STRING)
1794 pop_momentary_nofree ();
1797 | pushlevel maybe_label_decls error '}'
1798 { emit_line_note (input_filename, lineno);
1799 expand_end_bindings (getdecls (), kept_level_p (), 0);
1800 $$ = poplevel (kept_level_p (), 0, 0);
1801 if (yychar == CONSTANT || yychar == STRING)
1802 pop_momentary_nofree ();
1805 | pushlevel maybe_label_decls stmts '}'
1806 { emit_line_note (input_filename, lineno);
1807 expand_end_bindings (getdecls (), kept_level_p (), 0);
1808 $$ = poplevel (kept_level_p (), 0, 0);
1809 if (yychar == CONSTANT || yychar == STRING)
1810 pop_momentary_nofree ();
1815 compstmt_primary_start:
1817 { if (current_function_decl == 0)
1819 error ("braced-group within expression allowed only inside a function");
1822 /* We must force a BLOCK for this level
1823 so that, if it is not expanded later,
1824 there is a way to turn off the entire subtree of blocks
1825 that are contained in it. */
1827 push_iterator_stack ();
1828 push_label_level ();
1829 $$ = expand_start_stmt_expr ();
1833 compstmt: compstmt_start compstmt_nostart
1837 /* Value is number of statements counted as of the closeparen. */
1839 if_prefix lineno_labeled_stmt
1840 /* Make sure c_expand_end_cond is run once
1841 for each call to c_expand_start_cond.
1842 Otherwise a crash is likely. */
1848 { emit_line_note ($<filename>-1, $<lineno>0);
1849 c_expand_start_cond (truthvalue_conversion ($3), 0,
1851 $<itype>$ = stmt_count;
1852 if_stmt_file = $<filename>-1;
1853 if_stmt_line = $<lineno>0;
1854 position_after_white_space (); }
1857 /* This is a subroutine of stmt.
1858 It is used twice, once for valid DO statements
1859 and once for catching errors in parsing the end test. */
1864 emit_line_note ($<filename>-1, $<lineno>0);
1865 /* See comment in `while' alternative, above. */
1867 expand_start_loop_continue_elsewhere (1);
1868 position_after_white_space (); }
1869 lineno_labeled_stmt WHILE
1870 { expand_loop_continue_here (); }
1874 { $$ = input_filename; }
1881 lineno_labeled_stmt:
1882 save_filename save_lineno stmt
1884 /* | save_filename save_lineno error
1887 | save_filename save_lineno label lineno_labeled_stmt
1891 lineno_stmt_or_label:
1892 save_filename save_lineno stmt_or_label
1903 /* Parse a single real statement, not including any labels. */
1910 emit_line_note ($<filename>-1, $<lineno>0);
1911 /* It appears that this should not be done--that a non-lvalue array
1912 shouldn't get an error if the value isn't used.
1913 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1914 if it appears as a top-level expression,
1915 but says nothing about non-lvalue arrays. */
1917 /* Call default_conversion to get an error
1918 on referring to a register array if pedantic. */
1919 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1920 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1921 $1 = default_conversion ($1);
1923 iterator_expand ($1);
1924 clear_momentary (); }
1926 { c_expand_start_else ();
1927 $<itype>1 = stmt_count;
1928 position_after_white_space (); }
1930 { c_expand_end_cond ();
1931 if (extra_warnings && stmt_count == $<itype>1)
1932 warning ("empty body in an else-statement"); }
1933 | simple_if %prec IF
1934 { c_expand_end_cond ();
1935 /* This warning is here instead of in simple_if, because we
1936 do not want a warning if an empty if is followed by an
1937 else statement. Increment stmt_count so we don't
1938 give a second error if this is a nested `if'. */
1939 if (extra_warnings && stmt_count++ == $<itype>1)
1940 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1941 "empty body in an if-statement"); }
1942 /* Make sure c_expand_end_cond is run once
1943 for each call to c_expand_start_cond.
1944 Otherwise a crash is likely. */
1945 | simple_if ELSE error
1946 { c_expand_end_cond (); }
1949 emit_line_note ($<filename>-1, $<lineno>0);
1950 /* The emit_nop used to come before emit_line_note,
1951 but that made the nop seem like part of the preceding line.
1952 And that was confusing when the preceding line was
1953 inside of an if statement and was not really executed.
1954 I think it ought to work to put the nop after the line number.
1955 We will see. --rms, July 15, 1991. */
1958 { /* Don't start the loop till we have succeeded
1959 in parsing the end test. This is to make sure
1960 that we end every loop we start. */
1961 expand_start_loop (1);
1962 emit_line_note (input_filename, lineno);
1963 expand_exit_loop_if_false (NULL_PTR,
1964 truthvalue_conversion ($4));
1965 position_after_white_space (); }
1967 { expand_end_loop (); }
1970 { emit_line_note (input_filename, lineno);
1971 expand_exit_loop_if_false (NULL_PTR,
1972 truthvalue_conversion ($3));
1974 clear_momentary (); }
1975 /* This rule is needed to make sure we end every loop we start. */
1976 | do_stmt_start error
1977 { expand_end_loop ();
1978 clear_momentary (); }
1982 emit_line_note ($<filename>-1, $<lineno>0);
1983 /* See comment in `while' alternative, above. */
1985 if ($3) c_expand_expr_stmt ($3);
1986 /* Next step is to call expand_start_loop_continue_elsewhere,
1987 but wait till after we parse the entire for (...).
1988 Otherwise, invalid input might cause us to call that
1989 fn without calling expand_end_loop. */
1992 /* Can't emit now; wait till after expand_start_loop... */
1993 { $<lineno>7 = lineno;
1994 $<filename>$ = input_filename; }
1997 /* Start the loop. Doing this after parsing
1998 all the expressions ensures we will end the loop. */
1999 expand_start_loop_continue_elsewhere (1);
2000 /* Emit the end-test, with a line number. */
2001 emit_line_note ($<filename>8, $<lineno>7);
2003 expand_exit_loop_if_false (NULL_PTR,
2004 truthvalue_conversion ($6));
2005 /* Don't let the tree nodes for $9 be discarded by
2006 clear_momentary during the parsing of the next stmt. */
2008 $<lineno>7 = lineno;
2009 $<filename>8 = input_filename;
2010 position_after_white_space (); }
2012 { /* Emit the increment expression, with a line number. */
2013 emit_line_note ($<filename>8, $<lineno>7);
2014 expand_loop_continue_here ();
2016 c_expand_expr_stmt ($9);
2017 if (yychar == CONSTANT || yychar == STRING)
2018 pop_momentary_nofree ();
2021 expand_end_loop (); }
2022 | SWITCH '(' expr ')'
2024 emit_line_note ($<filename>-1, $<lineno>0);
2025 c_expand_start_case ($3);
2026 /* Don't let the tree nodes for $3 be discarded by
2027 clear_momentary during the parsing of the next stmt. */
2029 position_after_white_space (); }
2031 { expand_end_case ($3);
2032 if (yychar == CONSTANT || yychar == STRING)
2033 pop_momentary_nofree ();
2038 emit_line_note ($<filename>-1, $<lineno>0);
2039 if ( ! expand_exit_something ())
2040 error ("break statement not within loop or switch"); }
2043 emit_line_note ($<filename>-1, $<lineno>0);
2044 if (! expand_continue_loop (NULL_PTR))
2045 error ("continue statement not within a loop"); }
2048 emit_line_note ($<filename>-1, $<lineno>0);
2049 c_expand_return (NULL_TREE); }
2052 emit_line_note ($<filename>-1, $<lineno>0);
2053 c_expand_return ($2); }
2054 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2056 emit_line_note ($<filename>-1, $<lineno>0);
2058 if ((TREE_CODE ($4) == ADDR_EXPR
2059 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
2060 || TREE_CODE ($4) == STRING_CST)
2063 error ("argument of `asm' is not a constant string"); }
2064 /* This is the case with just output operands. */
2065 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2067 emit_line_note ($<filename>-1, $<lineno>0);
2068 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2069 $2 == ridpointers[(int)RID_VOLATILE],
2070 input_filename, lineno); }
2071 /* This is the case with input operands as well. */
2072 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2074 emit_line_note ($<filename>-1, $<lineno>0);
2075 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2076 $2 == ridpointers[(int)RID_VOLATILE],
2077 input_filename, lineno); }
2078 /* This is the case with clobbered registers as well. */
2079 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2080 asm_operands ':' asm_clobbers ')' ';'
2082 emit_line_note ($<filename>-1, $<lineno>0);
2083 c_expand_asm_operands ($4, $6, $8, $10,
2084 $2 == ridpointers[(int)RID_VOLATILE],
2085 input_filename, lineno); }
2086 | GOTO identifier ';'
2089 emit_line_note ($<filename>-1, $<lineno>0);
2090 decl = lookup_label ($2);
2093 TREE_USED (decl) = 1;
2099 pedwarn ("ANSI C forbids `goto *expr;'");
2101 emit_line_note ($<filename>-1, $<lineno>0);
2102 expand_computed_goto (convert (ptr_type_node, $3)); }
2107 all_iter_stmt_simple
2108 /* | all_iter_stmt_with_decl */
2111 all_iter_stmt_simple:
2114 /* The value returned by this action is */
2115 /* 1 if everything is OK */
2116 /* 0 in case of error or already bound iterator */
2119 if (TREE_CODE ($3) != VAR_DECL)
2120 error ("invalid `for (ITERATOR)' syntax");
2121 else if (! ITERATOR_P ($3))
2122 error ("`%s' is not an iterator",
2123 IDENTIFIER_POINTER (DECL_NAME ($3)));
2124 else if (ITERATOR_BOUND_P ($3))
2125 error ("`for (%s)' inside expansion of same iterator",
2126 IDENTIFIER_POINTER (DECL_NAME ($3)));
2130 iterator_for_loop_start ($3);
2136 iterator_for_loop_end ($3);
2139 /* This really should allow any kind of declaration,
2140 for generality. Fix it before turning it back on.
2142 all_iter_stmt_with_decl:
2143 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2145 */ /* The value returned by this action is */
2146 /* 1 if everything is OK */
2147 /* 0 in case of error or already bound iterator */
2149 iterator_for_loop_start ($6);
2153 iterator_for_loop_end ($6);
2154 emit_line_note (input_filename, lineno);
2155 expand_end_bindings (getdecls (), 1, 0);
2156 $<ttype>$ = poplevel (1, 1, 0);
2157 if (yychar == CONSTANT || yychar == STRING)
2158 pop_momentary_nofree ();
2164 /* Any kind of label, including jump labels and case labels.
2165 ANSI C accepts labels only before statements, but we allow them
2166 also at the end of a compound statement. */
2168 label: CASE expr_no_commas ':'
2169 { register tree value = check_case_value ($2);
2171 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2175 if (value != error_mark_node)
2180 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2181 pedwarn ("label must have integral type in ANSI C");
2183 success = pushcase (value, convert_and_check,
2187 error ("case label not within a switch statement");
2188 else if (success == 2)
2190 error ("duplicate case value");
2191 error_with_decl (duplicate, "this is the first entry for that value");
2193 else if (success == 3)
2194 warning ("case value out of range");
2195 else if (success == 5)
2196 error ("case label within scope of cleanup or variable array");
2198 position_after_white_space (); }
2199 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2200 { register tree value1 = check_case_value ($2);
2201 register tree value2 = check_case_value ($4);
2203 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2206 pedwarn ("ANSI C forbids case ranges");
2209 if (value1 != error_mark_node && value2 != error_mark_node)
2212 int success = pushcase_range (value1, value2,
2213 convert_and_check, label,
2216 error ("case label not within a switch statement");
2217 else if (success == 2)
2219 error ("duplicate case value");
2220 error_with_decl (duplicate, "this is the first entry for that value");
2222 else if (success == 3)
2223 warning ("case value out of range");
2224 else if (success == 4)
2225 warning ("empty case range");
2226 else if (success == 5)
2227 error ("case label within scope of cleanup or variable array");
2229 position_after_white_space (); }
2234 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2235 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2238 error ("default label not within a switch statement");
2239 else if (success == 2)
2241 error ("multiple default labels in one switch");
2242 error_with_decl (duplicate, "this is the first default label");
2244 position_after_white_space (); }
2245 | identifier ':' maybe_attribute
2246 { tree label = define_label (input_filename, lineno, $1);
2251 expand_label (label);
2252 decl_attributes (label, $3, NULL_TREE);
2254 position_after_white_space (); }
2257 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2261 { emit_line_note (input_filename, lineno);
2264 { emit_line_note (input_filename, lineno); }
2273 /* These are the operands other than the first string and colon
2274 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2275 asm_operands: /* empty */
2277 | nonnull_asm_operands
2280 nonnull_asm_operands:
2282 | nonnull_asm_operands ',' asm_operand
2283 { $$ = chainon ($1, $3); }
2288 { $$ = build_tree_list ($1, $3); }
2293 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2294 | asm_clobbers ',' string
2295 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2298 /* This is what appears inside the parens in a function declarator.
2299 Its value is a list of ..._TYPE nodes. */
2302 clear_parm_order ();
2303 declare_parm_level (0); }
2306 parmlist_tags_warning ();
2307 poplevel (0, 0, 0); }
2315 pedwarn ("ANSI C forbids forward parameter declarations");
2316 /* Mark the forward decls as such. */
2317 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2318 TREE_ASM_WRITTEN (parm) = 1;
2319 clear_parm_order (); }
2323 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2326 /* This is what appears inside the parens in a function declarator.
2327 Is value is represented in the format that grokdeclarator expects. */
2328 parmlist_2: /* empty */
2329 { $$ = get_parm_info (0); }
2331 { $$ = get_parm_info (0);
2332 /* Gcc used to allow this as an extension. However, it does
2333 not work for all targets, and thus has been disabled.
2334 Also, since func (...) and func () are indistinguishable,
2335 it caused problems with the code in expand_builtin which
2336 tries to verify that BUILT_IN_NEXT_ARG is being used
2338 error ("ANSI C requires a named argument before `...'");
2341 { $$ = get_parm_info (1); }
2342 | parms ',' ELLIPSIS
2343 { $$ = get_parm_info (0); }
2348 { push_parm_decl ($1); }
2350 { push_parm_decl ($3); }
2353 /* A single parameter declaration or parameter type name,
2354 as found in a parmlist. */
2356 typed_declspecs setspecs parm_declarator maybe_attribute
2357 { $$ = build_tree_list (build_tree_list (current_declspecs,
2359 build_tree_list (prefix_attributes,
2361 current_declspecs = TREE_VALUE (declspec_stack);
2362 prefix_attributes = TREE_PURPOSE (declspec_stack);
2363 declspec_stack = TREE_CHAIN (declspec_stack);
2364 resume_momentary ($2); }
2365 | typed_declspecs setspecs notype_declarator maybe_attribute
2366 { $$ = build_tree_list (build_tree_list (current_declspecs,
2368 build_tree_list (prefix_attributes,
2370 current_declspecs = TREE_VALUE (declspec_stack);
2371 prefix_attributes = TREE_PURPOSE (declspec_stack);
2372 declspec_stack = TREE_CHAIN (declspec_stack);
2373 resume_momentary ($2); }
2374 | typed_declspecs setspecs absdcl maybe_attribute
2375 { $$ = build_tree_list (build_tree_list (current_declspecs,
2377 build_tree_list (prefix_attributes,
2379 current_declspecs = TREE_VALUE (declspec_stack);
2380 prefix_attributes = TREE_PURPOSE (declspec_stack);
2381 declspec_stack = TREE_CHAIN (declspec_stack);
2382 resume_momentary ($2); }
2383 | declmods setspecs notype_declarator maybe_attribute
2384 { $$ = build_tree_list (build_tree_list (current_declspecs,
2386 build_tree_list (prefix_attributes,
2388 current_declspecs = TREE_VALUE (declspec_stack);
2389 prefix_attributes = TREE_PURPOSE (declspec_stack);
2390 declspec_stack = TREE_CHAIN (declspec_stack);
2391 resume_momentary ($2); }
2393 | declmods setspecs absdcl maybe_attribute
2394 { $$ = build_tree_list (build_tree_list (current_declspecs,
2396 build_tree_list (prefix_attributes,
2398 current_declspecs = TREE_VALUE (declspec_stack);
2399 prefix_attributes = TREE_PURPOSE (declspec_stack);
2400 declspec_stack = TREE_CHAIN (declspec_stack);
2401 resume_momentary ($2); }
2404 /* This is used in a function definition
2405 where either a parmlist or an identifier list is ok.
2406 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2407 parmlist_or_identifiers:
2409 clear_parm_order ();
2410 declare_parm_level (1); }
2411 parmlist_or_identifiers_1
2413 parmlist_tags_warning ();
2414 poplevel (0, 0, 0); }
2417 parmlist_or_identifiers_1:
2421 for (t = $1; t; t = TREE_CHAIN (t))
2422 if (TREE_VALUE (t) == NULL_TREE)
2423 error ("`...' in old-style identifier list");
2424 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2427 /* A nonempty list of identifiers. */
2430 { $$ = build_tree_list (NULL_TREE, $1); }
2431 | identifiers ',' IDENTIFIER
2432 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2435 /* A nonempty list of identifiers, including typenames. */
2436 identifiers_or_typenames:
2438 { $$ = build_tree_list (NULL_TREE, $1); }
2439 | identifiers_or_typenames ',' identifier
2440 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2445 { $<itype>$ = pedantic;
2450 /* Objective-C productions. */
2460 if (objc_implementation_context)
2462 finish_class (objc_implementation_context);
2463 objc_ivar_chain = NULL_TREE;
2464 objc_implementation_context = NULL_TREE;
2467 warning ("`@end' must appear in an implementation context");
2471 /* A nonempty list of identifiers. */
2474 { $$ = build_tree_list (NULL_TREE, $1); }
2475 | identifier_list ',' identifier
2476 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2480 CLASS identifier_list ';'
2482 objc_declare_class ($2);
2486 ALIAS identifier identifier ';'
2488 objc_declare_alias ($2, $3);
2492 INTERFACE identifier protocolrefs '{'
2494 objc_interface_context = objc_ivar_context
2495 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2496 objc_public_flag = 0;
2500 continue_class (objc_interface_context);
2505 finish_class (objc_interface_context);
2506 objc_interface_context = NULL_TREE;
2509 | INTERFACE identifier protocolrefs
2511 objc_interface_context
2512 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2513 continue_class (objc_interface_context);
2518 finish_class (objc_interface_context);
2519 objc_interface_context = NULL_TREE;
2522 | INTERFACE identifier ':' identifier protocolrefs '{'
2524 objc_interface_context = objc_ivar_context
2525 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2526 objc_public_flag = 0;
2530 continue_class (objc_interface_context);
2535 finish_class (objc_interface_context);
2536 objc_interface_context = NULL_TREE;
2539 | INTERFACE identifier ':' identifier protocolrefs
2541 objc_interface_context
2542 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2543 continue_class (objc_interface_context);
2548 finish_class (objc_interface_context);
2549 objc_interface_context = NULL_TREE;
2552 | IMPLEMENTATION identifier '{'
2554 objc_implementation_context = objc_ivar_context
2555 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2556 objc_public_flag = 0;
2561 = continue_class (objc_implementation_context);
2564 | IMPLEMENTATION identifier
2566 objc_implementation_context
2567 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2569 = continue_class (objc_implementation_context);
2572 | IMPLEMENTATION identifier ':' identifier '{'
2574 objc_implementation_context = objc_ivar_context
2575 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2576 objc_public_flag = 0;
2581 = continue_class (objc_implementation_context);
2584 | IMPLEMENTATION identifier ':' identifier
2586 objc_implementation_context
2587 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2589 = continue_class (objc_implementation_context);
2592 | INTERFACE identifier '(' identifier ')' protocolrefs
2594 objc_interface_context
2595 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2596 continue_class (objc_interface_context);
2601 finish_class (objc_interface_context);
2602 objc_interface_context = NULL_TREE;
2605 | IMPLEMENTATION identifier '(' identifier ')'
2607 objc_implementation_context
2608 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2610 = continue_class (objc_implementation_context);
2615 PROTOCOL identifier protocolrefs
2617 remember_protocol_qualifiers ();
2618 objc_interface_context
2619 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2623 forget_protocol_qualifiers();
2624 finish_protocol(objc_interface_context);
2625 objc_interface_context = NULL_TREE;
2634 | non_empty_protocolrefs
2637 non_empty_protocolrefs:
2638 ARITHCOMPARE identifier_list ARITHCOMPARE
2640 if ($1 == LT_EXPR && $3 == GT_EXPR)
2648 ivar_decl_list visibility_spec ivar_decls
2653 PRIVATE { objc_public_flag = 2; }
2654 | PROTECTED { objc_public_flag = 0; }
2655 | PUBLIC { objc_public_flag = 1; }
2663 | ivar_decls ivar_decl ';'
2667 pedwarn ("extra semicolon in struct or union specified");
2672 /* There is a shift-reduce conflict here, because `components' may
2673 start with a `typename'. It happens that shifting (the default resolution)
2674 does the right thing, because it treats the `typename' as part of
2675 a `typed_typespecs'.
2677 It is possible that this same technique would allow the distinction
2678 between `notype_initdecls' and `initdecls' to be eliminated.
2679 But I am being cautious and not trying it. */
2682 typed_typespecs setspecs ivars
2684 current_declspecs = TREE_VALUE (declspec_stack);
2685 prefix_attributes = TREE_PURPOSE (declspec_stack);
2686 declspec_stack = TREE_CHAIN (declspec_stack);
2687 resume_momentary ($2); }
2688 | nonempty_type_quals setspecs ivars
2690 current_declspecs = TREE_VALUE (declspec_stack);
2691 prefix_attributes = TREE_PURPOSE (declspec_stack);
2692 declspec_stack = TREE_CHAIN (declspec_stack);
2693 resume_momentary ($2); }
2702 | ivars ',' ivar_declarator
2708 $$ = add_instance_variable (objc_ivar_context,
2710 $1, current_declspecs,
2713 | declarator ':' expr_no_commas
2715 $$ = add_instance_variable (objc_ivar_context,
2717 $1, current_declspecs, $3);
2719 | ':' expr_no_commas
2721 $$ = add_instance_variable (objc_ivar_context,
2724 current_declspecs, $2);
2731 remember_protocol_qualifiers ();
2732 if (objc_implementation_context)
2733 objc_inherit_code = CLASS_METHOD_DECL;
2735 fatal ("method definition not in class context");
2739 forget_protocol_qualifiers ();
2740 add_class_method (objc_implementation_context, $3);
2741 start_method_def ($3);
2742 objc_method_context = $3;
2746 continue_method_def ();
2750 finish_method_def ();
2751 objc_method_context = NULL_TREE;
2756 remember_protocol_qualifiers ();
2757 if (objc_implementation_context)
2758 objc_inherit_code = INSTANCE_METHOD_DECL;
2760 fatal ("method definition not in class context");
2764 forget_protocol_qualifiers ();
2765 add_instance_method (objc_implementation_context, $3);
2766 start_method_def ($3);
2767 objc_method_context = $3;
2771 continue_method_def ();
2775 finish_method_def ();
2776 objc_method_context = NULL_TREE;
2780 /* the reason for the strange actions in this rule
2781 is so that notype_initdecls when reached via datadef
2782 can find a valid list of type and sc specs in $0. */
2786 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2789 methodprotolist2: /* eliminates a shift/reduce conflict */
2792 | methodprotolist2 methodproto
2793 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2804 /* Remember protocol qualifiers in prototypes. */
2805 remember_protocol_qualifiers ();
2806 objc_inherit_code = CLASS_METHOD_DECL;
2810 /* Forget protocol qualifiers here. */
2811 forget_protocol_qualifiers ();
2812 add_class_method (objc_interface_context, $3);
2818 /* Remember protocol qualifiers in prototypes. */
2819 remember_protocol_qualifiers ();
2820 objc_inherit_code = INSTANCE_METHOD_DECL;
2824 /* Forget protocol qualifiers here. */
2825 forget_protocol_qualifiers ();
2826 add_instance_method (objc_interface_context, $3);
2832 '(' typename ')' unaryselector
2834 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2839 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2842 | '(' typename ')' keywordselector optparmlist
2844 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2847 | keywordselector optparmlist
2849 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2853 /* "optarglist" assumes that start_method_def has already been called...
2854 if it is not, the "xdecls" will not be placed in the proper scope */
2861 /* to get around the following situation: "int foo (int a) int b; {}" that
2862 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2877 typed_declspecs setspecs myparms ';'
2878 { current_declspecs = TREE_VALUE (declspec_stack);
2879 prefix_attributes = TREE_PURPOSE (declspec_stack);
2880 declspec_stack = TREE_CHAIN (declspec_stack);
2881 resume_momentary ($2); }
2882 | typed_declspecs ';'
2883 { shadow_tag ($1); }
2885 { pedwarn ("empty declaration"); }
2890 { push_parm_decl ($1); }
2891 | myparms ',' myparm
2892 { push_parm_decl ($3); }
2895 /* A single parameter declaration or parameter type name,
2896 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2899 parm_declarator maybe_attribute
2900 { $$ = build_tree_list (build_tree_list (current_declspecs,
2902 build_tree_list (prefix_attributes,
2904 | notype_declarator maybe_attribute
2905 { $$ = build_tree_list (build_tree_list (current_declspecs,
2907 build_tree_list (prefix_attributes,
2909 | absdcl maybe_attribute
2910 { $$ = build_tree_list (build_tree_list (current_declspecs,
2912 build_tree_list (prefix_attributes,
2923 /* oh what a kludge! */
2932 /* returns a tree list node generated by get_parm_info */
2945 | keywordselector keyworddecl
2947 $$ = chainon ($1, $2);
2959 ENUM { $$ = get_identifier (token_buffer); }
2960 | STRUCT { $$ = get_identifier (token_buffer); }
2961 | UNION { $$ = get_identifier (token_buffer); }
2962 | IF { $$ = get_identifier (token_buffer); }
2963 | ELSE { $$ = get_identifier (token_buffer); }
2964 | WHILE { $$ = get_identifier (token_buffer); }
2965 | DO { $$ = get_identifier (token_buffer); }
2966 | FOR { $$ = get_identifier (token_buffer); }
2967 | SWITCH { $$ = get_identifier (token_buffer); }
2968 | CASE { $$ = get_identifier (token_buffer); }
2969 | DEFAULT { $$ = get_identifier (token_buffer); }
2970 | BREAK { $$ = get_identifier (token_buffer); }
2971 | CONTINUE { $$ = get_identifier (token_buffer); }
2972 | RETURN { $$ = get_identifier (token_buffer); }
2973 | GOTO { $$ = get_identifier (token_buffer); }
2974 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2975 | SIZEOF { $$ = get_identifier (token_buffer); }
2976 | TYPEOF { $$ = get_identifier (token_buffer); }
2977 | ALIGNOF { $$ = get_identifier (token_buffer); }
2978 | TYPESPEC | TYPE_QUAL
2982 selector ':' '(' typename ')' identifier
2984 $$ = build_keyword_decl ($1, $4, $6);
2987 | selector ':' identifier
2989 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2992 | ':' '(' typename ')' identifier
2994 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2999 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
3010 | keywordarglist keywordarg
3012 $$ = chainon ($1, $2);
3020 if (TREE_CHAIN ($1) == NULL_TREE)
3021 /* just return the expr., remove a level of indirection */
3022 $$ = TREE_VALUE ($1);
3024 /* we have a comma expr., we will collapse later */
3030 selector ':' keywordexpr
3032 $$ = build_tree_list ($1, $3);
3036 $$ = build_tree_list (NULL_TREE, $2);
3044 $$ = get_class_reference ($1);
3050 { objc_receiver_context = 1; }
3052 { objc_receiver_context = 0; }
3055 $$ = build_tree_list ($3, $5);
3066 | keywordnamelist keywordname
3068 $$ = chainon ($1, $2);
3075 $$ = build_tree_list ($1, NULL_TREE);
3079 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3084 SELECTOR '(' selectorarg ')'
3091 PROTOCOL '(' identifier ')'
3097 /* extension to support C-structures in the archiver */
3100 ENCODE '(' typename ')'
3102 $$ = groktypename ($3);