1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* This file defines the grammar of C and that of Objective C.
22 ifobjc ... end ifobjc conditionals contain code for Objective C only.
23 ifc ... end ifc conditionals contain code for C only.
24 Sed commands in Makefile.in are used to convert this file into
25 c-parse.y and into objc-parse.y. */
27 /* To whomever it may concern: I have heard that such a thing was once
28 written by AT&T, but I have never seen it. */
50 #ifdef MULTIBYTE_CHARS
58 /* Since parsers are distinct for each language, put the language string
61 const char * const language_string = "GNU Obj-C";
64 const char * const language_string = "GNU C";
67 /* Like YYERROR but do call yyerror. */
68 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
70 /* Cause the `yydebug' variable to be defined. */
76 %union {long itype; tree ttype; enum tree_code code;
77 char *filename; int lineno; int ends_in_label; }
79 /* All identifiers that are not reserved words
80 and are not declared typedefs in the current block */
83 /* All identifiers that are declared typedefs in the current block.
84 In some contexts, they are treated just like IDENTIFIER,
85 but they can also serve as typespecs in declarations. */
88 /* Reserved words that specify storage class.
89 yylval contains an IDENTIFIER_NODE which indicates which one. */
92 /* Reserved words that specify type.
93 yylval contains an IDENTIFIER_NODE which indicates which one. */
96 /* Reserved words that qualify type: "const", "volatile", or "restrict".
97 yylval contains an IDENTIFIER_NODE which indicates which one. */
100 /* Character or numeric constants.
101 yylval is the node for the constant. */
104 /* String constants in raw form.
105 yylval is a STRING_CST node. */
108 /* "...", used for functions with variable arglists. */
111 /* the reserved words */
112 /* SCO include files test "ASM", so use something else. */
113 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
114 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
115 %token ATTRIBUTE EXTENSION LABEL
116 %token REALPART IMAGPART VA_ARG
118 /* Used in c-lex.c for parsing pragmas. */
121 /* Add precedence rules to solve dangling else s/r conflict */
125 /* Define the operator tokens and their precedences.
126 The value is an integer because, if used, it is the tree code
127 to use in the expression made from the operator. */
129 %right <code> ASSIGN '='
130 %right <code> '?' ':'
136 %left <code> EQCOMPARE
137 %left <code> ARITHCOMPARE
138 %left <code> LSHIFT RSHIFT
140 %left <code> '*' '/' '%'
141 %right <code> UNARY PLUSPLUS MINUSMINUS
143 %left <code> POINTSAT '.' '(' '['
145 /* The Objective-C keywords. These are included in C and in
146 Objective C, so that the token codes are the same in both. */
147 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
148 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
150 /* Objective-C string constants in raw form.
151 yylval is an OBJC_STRING_CST node. */
157 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
158 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
159 %type <ttype> typed_declspecs reserved_declspecs
160 %type <ttype> typed_typespecs reserved_typespecquals
161 %type <ttype> declmods typespec typespecqual_reserved
162 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
163 %type <ttype> declmods_no_prefix_attr
164 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
165 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
166 %type <ttype> init maybeasm
167 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
168 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
169 %type <ttype> any_word
171 %type <ttype> compstmt compstmt_nostart compstmt_primary_start
173 %type <ttype> declarator
174 %type <ttype> notype_declarator after_type_declarator
175 %type <ttype> parm_declarator
177 %type <ttype> structsp component_decl_list component_decl_list2
178 %type <ttype> component_decl components component_declarator
179 %type <ttype> enumlist enumerator
180 %type <ttype> struct_head union_head enum_head
181 %type <ttype> typename absdcl absdcl1 type_quals
182 %type <ttype> xexpr parms parm identifiers
184 %type <ttype> parmlist parmlist_1 parmlist_2
185 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
186 %type <ttype> identifiers_or_typenames
188 %type <itype> setspecs
190 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
192 %type <filename> save_filename
193 %type <lineno> save_lineno
196 /* the Objective-C nonterminals */
198 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
199 %type <ttype> methoddecl unaryselector keywordselector selector
200 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
201 %type <ttype> keywordexpr keywordarglist keywordarg
202 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
203 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
204 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
206 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
210 /* Number of statements (loosely speaking) and compound statements
212 static int stmt_count;
213 static int compstmt_count;
215 /* Input file and line number of the end of the body of last simple_if;
216 used by the stmt-rule immediately after simple_if returns. */
217 static char *if_stmt_file;
218 static int if_stmt_line;
220 /* List of types and structure classes of the current declaration. */
221 static tree current_declspecs = NULL_TREE;
222 static tree prefix_attributes = NULL_TREE;
224 /* Stack of saved values of current_declspecs and prefix_attributes. */
225 static tree declspec_stack;
227 /* 1 if we explained undeclared var errors. */
228 static int undeclared_variable_notice;
231 /* Objective-C specific information */
233 tree objc_interface_context;
234 tree objc_implementation_context;
235 tree objc_method_context;
236 tree objc_ivar_chain;
237 tree objc_ivar_context;
238 enum tree_code objc_inherit_code;
239 int objc_receiver_context;
240 int objc_public_flag;
244 /* Tell yyparse how to print a token's value, if yydebug is set. */
246 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
247 extern void yyprint PROTO ((FILE *, int, YYSTYPE));
249 /* Add GC roots for variables local to this file. */
253 ggc_add_tree_root (&declspec_stack, 1);
254 ggc_add_tree_root (¤t_declspecs, 1);
255 ggc_add_tree_root (&prefix_attributes, 1);
263 pedwarn ("ANSI C forbids an empty source file");
268 /* In case there were missing closebraces,
269 get us back to the global binding level. */
270 while (! global_bindings_p ())
276 /* the reason for the strange actions in this rule
277 is so that notype_initdecls when reached via datadef
278 can find a valid list of type and sc specs in $0. */
281 {$<ttype>$ = NULL_TREE; } extdef
282 | extdefs {$<ttype>$ = NULL_TREE; } extdef
291 | ASM_KEYWORD '(' expr ')' ';'
293 if ((TREE_CODE ($3) == ADDR_EXPR
294 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
295 || TREE_CODE ($3) == STRING_CST)
298 error ("argument of `asm' is not a constant string"); }
300 { pedantic = $<itype>1; }
304 setspecs notype_initdecls ';'
306 error ("ANSI C forbids data definition with no type or storage class");
307 else if (!flag_traditional)
308 warning ("data definition has no type or storage class");
310 current_declspecs = TREE_VALUE (declspec_stack);
311 prefix_attributes = TREE_PURPOSE (declspec_stack);
312 declspec_stack = TREE_CHAIN (declspec_stack);
313 resume_momentary ($1); }
314 | declmods setspecs notype_initdecls ';'
315 { current_declspecs = TREE_VALUE (declspec_stack);
316 prefix_attributes = TREE_PURPOSE (declspec_stack);
317 declspec_stack = TREE_CHAIN (declspec_stack);
318 resume_momentary ($2); }
319 | typed_declspecs setspecs initdecls ';'
320 { current_declspecs = TREE_VALUE (declspec_stack);
321 prefix_attributes = TREE_PURPOSE (declspec_stack);
322 declspec_stack = TREE_CHAIN (declspec_stack);
323 resume_momentary ($2); }
325 { pedwarn ("empty declaration"); }
326 | typed_declspecs ';'
332 pedwarn ("ANSI C does not allow extra `;' outside of a function"); }
336 typed_declspecs setspecs declarator
337 { if (! start_function (current_declspecs, $3,
338 prefix_attributes, NULL_TREE, 0))
340 reinit_parse_for_function (); }
342 { store_parm_decls (); }
344 { finish_function (0);
345 current_declspecs = TREE_VALUE (declspec_stack);
346 prefix_attributes = TREE_PURPOSE (declspec_stack);
347 declspec_stack = TREE_CHAIN (declspec_stack);
348 resume_momentary ($2); }
349 | typed_declspecs setspecs declarator error
350 { current_declspecs = TREE_VALUE (declspec_stack);
351 prefix_attributes = TREE_PURPOSE (declspec_stack);
352 declspec_stack = TREE_CHAIN (declspec_stack);
353 resume_momentary ($2); }
354 | declmods setspecs notype_declarator
355 { if (! start_function (current_declspecs, $3,
356 prefix_attributes, NULL_TREE, 0))
358 reinit_parse_for_function (); }
360 { store_parm_decls (); }
362 { finish_function (0);
363 current_declspecs = TREE_VALUE (declspec_stack);
364 prefix_attributes = TREE_PURPOSE (declspec_stack);
365 declspec_stack = TREE_CHAIN (declspec_stack);
366 resume_momentary ($2); }
367 | declmods setspecs notype_declarator error
368 { current_declspecs = TREE_VALUE (declspec_stack);
369 prefix_attributes = TREE_PURPOSE (declspec_stack);
370 declspec_stack = TREE_CHAIN (declspec_stack);
371 resume_momentary ($2); }
372 | setspecs notype_declarator
373 { if (! start_function (NULL_TREE, $2,
374 prefix_attributes, NULL_TREE, 0))
376 reinit_parse_for_function (); }
378 { store_parm_decls (); }
380 { finish_function (0);
381 current_declspecs = TREE_VALUE (declspec_stack);
382 prefix_attributes = TREE_PURPOSE (declspec_stack);
383 declspec_stack = TREE_CHAIN (declspec_stack);
384 resume_momentary ($1); }
385 | setspecs notype_declarator error
386 { current_declspecs = TREE_VALUE (declspec_stack);
387 prefix_attributes = TREE_PURPOSE (declspec_stack);
388 declspec_stack = TREE_CHAIN (declspec_stack);
389 resume_momentary ($1); }
404 { $$ = NEGATE_EXPR; }
406 { $$ = CONVERT_EXPR; }
408 { $$ = PREINCREMENT_EXPR; }
410 { $$ = PREDECREMENT_EXPR; }
412 { $$ = BIT_NOT_EXPR; }
414 { $$ = TRUTH_NOT_EXPR; }
417 expr: nonnull_exprlist
418 { $$ = build_compound_expr ($1); }
429 { $$ = build_tree_list (NULL_TREE, $1); }
430 | nonnull_exprlist ',' expr_no_commas
431 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
436 | '*' cast_expr %prec UNARY
437 { $$ = build_indirect_ref ($2, "unary *"); }
438 /* __extension__ turns off -pedantic for following primary. */
439 | extension cast_expr %prec UNARY
441 pedantic = $<itype>1; }
442 | unop cast_expr %prec UNARY
443 { $$ = build_unary_op ($1, $2, 0);
444 overflow_warning ($$); }
445 /* Refer to the address of a label as a pointer. */
447 { tree label = lookup_label ($2);
449 pedwarn ("ANSI C forbids `&&'");
451 $$ = null_pointer_node;
454 TREE_USED (label) = 1;
455 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
456 TREE_CONSTANT ($$) = 1;
459 /* This seems to be impossible on some machines, so let's turn it off.
460 You can use __builtin_next_arg to find the anonymous stack args.
462 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
463 $$ = error_mark_node;
464 if (TREE_VALUE (tree_last (types)) == void_type_node)
465 error ("`&...' used in function with fixed number of arguments");
469 pedwarn ("ANSI C forbids `&...'");
470 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
471 $$ = build_unary_op (ADDR_EXPR, $$, 0);
474 | sizeof unary_expr %prec UNARY
476 if (TREE_CODE ($2) == COMPONENT_REF
477 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
478 error ("`sizeof' applied to a bit-field");
479 $$ = c_sizeof (TREE_TYPE ($2)); }
480 | sizeof '(' typename ')' %prec HYPERUNARY
482 $$ = c_sizeof (groktypename ($3)); }
483 | alignof unary_expr %prec UNARY
485 $$ = c_alignof_expr ($2); }
486 | alignof '(' typename ')' %prec HYPERUNARY
488 $$ = c_alignof (groktypename ($3)); }
489 | REALPART cast_expr %prec UNARY
490 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
491 | IMAGPART cast_expr %prec UNARY
492 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
493 | VA_ARG '(' expr_no_commas ',' typename ')'
494 { $$ = build_va_arg ($3, groktypename ($5)); }
498 SIZEOF { skip_evaluation++; }
502 ALIGNOF { skip_evaluation++; }
507 | '(' typename ')' cast_expr %prec UNARY
508 { tree type = groktypename ($2);
509 $$ = build_c_cast (type, $4); }
510 | '(' typename ')' '{'
511 { start_init (NULL_TREE, NULL, 0);
512 $2 = groktypename ($2);
513 really_start_incremental_init ($2); }
514 initlist_maybe_comma '}' %prec UNARY
516 tree result = pop_init_level (0);
520 if (pedantic && ! flag_isoc9x)
521 pedwarn ("ANSI C forbids constructor expressions");
522 if (TYPE_NAME (type) != 0)
524 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
525 name = IDENTIFIER_POINTER (TYPE_NAME (type));
527 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
532 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
534 int failure = complete_array_type (type, $$, 1);
543 | expr_no_commas '+' expr_no_commas
544 { $$ = parser_build_binary_op ($2, $1, $3); }
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 LSHIFT expr_no_commas
554 { $$ = parser_build_binary_op ($2, $1, $3); }
555 | expr_no_commas RSHIFT expr_no_commas
556 { $$ = parser_build_binary_op ($2, $1, $3); }
557 | expr_no_commas ARITHCOMPARE expr_no_commas
558 { $$ = parser_build_binary_op ($2, $1, $3); }
559 | expr_no_commas EQCOMPARE expr_no_commas
560 { $$ = parser_build_binary_op ($2, $1, $3); }
561 | expr_no_commas '&' 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 ANDAND
568 { $1 = truthvalue_conversion (default_conversion ($1));
569 skip_evaluation += $1 == boolean_false_node; }
571 { skip_evaluation -= $1 == boolean_false_node;
572 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
573 | expr_no_commas OROR
574 { $1 = truthvalue_conversion (default_conversion ($1));
575 skip_evaluation += $1 == boolean_true_node; }
577 { skip_evaluation -= $1 == boolean_true_node;
578 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
580 { $1 = truthvalue_conversion (default_conversion ($1));
581 skip_evaluation += $1 == boolean_false_node; }
583 { skip_evaluation += (($1 == boolean_true_node)
584 - ($1 == boolean_false_node)); }
586 { skip_evaluation -= $1 == boolean_true_node;
587 $$ = build_conditional_expr ($1, $4, $7); }
590 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
591 /* Make sure first operand is calculated only once. */
592 $<ttype>2 = save_expr ($1);
593 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
594 skip_evaluation += $1 == boolean_true_node; }
596 { skip_evaluation -= $1 == boolean_true_node;
597 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
598 | expr_no_commas '=' expr_no_commas
600 $$ = build_modify_expr ($1, NOP_EXPR, $3);
601 class = TREE_CODE_CLASS (TREE_CODE ($$));
602 if (class == 'e' || class == '1'
603 || class == '2' || class == '<')
604 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
606 | expr_no_commas ASSIGN expr_no_commas
608 $$ = build_modify_expr ($1, $2, $3);
609 /* This inhibits warnings in truthvalue_conversion. */
610 class = TREE_CODE_CLASS (TREE_CODE ($$));
611 if (class == 'e' || class == '1'
612 || class == '2' || class == '<')
613 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
621 if (!$$ || $$ == error_mark_node)
623 if (yychar == YYEMPTY)
630 if (objc_receiver_context
631 && ! (objc_receiver_context
632 && strcmp (IDENTIFIER_POINTER ($1), "super")))
633 /* we have a message to super */
634 $$ = get_super_receiver ();
635 else if (objc_method_context
636 && (decl = is_ivar (objc_ivar_chain, $1)))
638 if (is_private (decl))
639 $$ = error_mark_node;
641 $$ = build_ivar_reference ($1);
646 /* Ordinary implicit function declaration. */
647 $$ = implicitly_declare ($1);
648 assemble_external ($$);
652 else if (current_function_decl == 0)
654 error ("`%s' undeclared here (not in a function)",
655 IDENTIFIER_POINTER ($1));
656 $$ = error_mark_node;
663 if (objc_receiver_context
664 && ! strcmp (IDENTIFIER_POINTER ($1), "super"))
665 /* we have a message to super */
666 $$ = get_super_receiver ();
667 else if (objc_method_context
668 && (decl = is_ivar (objc_ivar_chain, $1)))
670 if (is_private (decl))
671 $$ = error_mark_node;
673 $$ = build_ivar_reference ($1);
678 if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
679 || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
681 error ("`%s' undeclared (first use in this function)",
682 IDENTIFIER_POINTER ($1));
684 if (! undeclared_variable_notice)
686 error ("(Each undeclared identifier is reported only once");
687 error ("for each function it appears in.)");
688 undeclared_variable_notice = 1;
691 $$ = error_mark_node;
692 /* Prevent repeated error messages. */
693 IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
694 IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
698 else if (TREE_TYPE ($$) == error_mark_node)
699 $$ = error_mark_node;
700 else if (C_DECL_ANTICIPATED ($$))
702 /* The first time we see a build-in function used,
703 if it has not been declared. */
704 C_DECL_ANTICIPATED ($$) = 0;
705 if (yychar == YYEMPTY)
709 /* Omit the implicit declaration we
710 would ordinarily do, so we don't lose
711 the actual built in type.
712 But print a diagnostic for the mismatch. */
714 if (objc_method_context
715 && is_ivar (objc_ivar_chain, $1))
716 error ("Instance variable `%s' implicitly declared as function",
717 IDENTIFIER_POINTER (DECL_NAME ($$)));
720 if (TREE_CODE ($$) != FUNCTION_DECL)
721 error ("`%s' implicitly declared as function",
722 IDENTIFIER_POINTER (DECL_NAME ($$)));
723 else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$)))
724 != TYPE_MODE (integer_type_node))
725 && (TREE_TYPE (TREE_TYPE ($$))
727 pedwarn ("type mismatch in implicit declaration for built-in function `%s'",
728 IDENTIFIER_POINTER (DECL_NAME ($$)));
729 /* If it really returns void, change that to int. */
730 if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node)
732 = build_function_type (integer_type_node,
733 TYPE_ARG_TYPES (TREE_TYPE ($$)));
736 pedwarn ("built-in function `%s' used without declaration",
737 IDENTIFIER_POINTER (DECL_NAME ($$)));
739 /* Do what we would ordinarily do when a fn is used. */
740 assemble_external ($$);
745 assemble_external ($$);
748 /* we have a definition - still check if iVariable */
750 if (!objc_receiver_context
751 || (objc_receiver_context
752 && strcmp (IDENTIFIER_POINTER ($1), "super")))
756 if (objc_method_context
757 && (decl = is_ivar (objc_ivar_chain, $1)))
759 if (IDENTIFIER_LOCAL_VALUE ($1))
760 warning ("local declaration of `%s' hides instance variable",
761 IDENTIFIER_POINTER ($1));
764 if (is_private (decl))
765 $$ = error_mark_node;
767 $$ = build_ivar_reference ($1);
771 else /* we have a message to super */
772 $$ = get_super_receiver ();
776 if (TREE_CODE ($$) == CONST_DECL)
778 $$ = DECL_INITIAL ($$);
779 /* This is to prevent an enum whose value is 0
780 from being considered a null pointer constant. */
781 $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
782 TREE_CONSTANT ($$) = 1;
787 { $$ = combine_strings ($1); }
789 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
790 if (class == 'e' || class == '1'
791 || class == '2' || class == '<')
792 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
795 { $$ = error_mark_node; }
796 | compstmt_primary_start compstmt_nostart ')'
799 pedwarn ("ANSI C forbids braced-groups within expressions");
800 pop_iterator_stack ();
802 rtl_exp = expand_end_stmt_expr ($1);
803 /* The statements have side effects, so the group does. */
804 TREE_SIDE_EFFECTS (rtl_exp) = 1;
806 if (TREE_CODE ($2) == BLOCK)
808 /* Make a BIND_EXPR for the BLOCK already made. */
809 $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
810 NULL_TREE, rtl_exp, $2);
811 /* Remove the block from the tree at this point.
812 It gets put back at the proper place
813 when the BIND_EXPR is expanded. */
819 | compstmt_primary_start error ')'
821 /* Make sure we call expand_end_stmt_expr. Otherwise
822 we are likely to lose sequences and crash later. */
823 pop_iterator_stack ();
825 expand_end_stmt_expr ($1);
826 $$ = error_mark_node;
828 | primary '(' exprlist ')' %prec '.'
829 { $$ = build_function_call ($1, $3); }
830 | primary '[' expr ']' %prec '.'
831 { $$ = build_array_ref ($1, $3); }
832 | primary '.' identifier
835 if (doing_objc_thang)
837 if (is_public ($1, $3))
838 $$ = build_component_ref ($1, $3);
840 $$ = error_mark_node;
844 $$ = build_component_ref ($1, $3);
846 | primary POINTSAT identifier
848 tree expr = build_indirect_ref ($1, "->");
851 if (doing_objc_thang)
853 if (is_public (expr, $3))
854 $$ = build_component_ref (expr, $3);
856 $$ = error_mark_node;
860 $$ = build_component_ref (expr, $3);
863 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
865 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
868 { $$ = build_message_expr ($1); }
870 { $$ = build_selector_expr ($1); }
872 { $$ = build_protocol_expr ($1); }
874 { $$ = build_encode_expr ($1); }
876 { $$ = build_objc_string_object ($1); }
880 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
884 { $$ = chainon ($1, $2); }
888 /* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
892 | objc_string OBJC_STRING
893 { $$ = chainon ($1, $2); }
897 old_style_parm_decls:
901 /* ... is used here to indicate a varargs function. */
904 pedwarn ("ANSI C does not permit use of `varargs.h'"); }
907 /* The following are analogous to lineno_decl, decls and decl
908 except that they do not allow nested functions.
909 They are used for old-style parm decls. */
911 save_filename save_lineno datadecl
918 | datadecls lineno_datadecl
919 | lineno_datadecl errstmt
922 /* We don't allow prefix attributes here because they cause reduce/reduce
923 conflicts: we can't know whether we're parsing a function decl with
924 attribute suffix, or function defn with attribute prefix on first old
927 typed_declspecs_no_prefix_attr setspecs initdecls ';'
928 { current_declspecs = TREE_VALUE (declspec_stack);
929 prefix_attributes = TREE_PURPOSE (declspec_stack);
930 declspec_stack = TREE_CHAIN (declspec_stack);
931 resume_momentary ($2); }
932 | declmods_no_prefix_attr setspecs notype_initdecls ';'
933 { current_declspecs = TREE_VALUE (declspec_stack);
934 prefix_attributes = TREE_PURPOSE (declspec_stack);
935 declspec_stack = TREE_CHAIN (declspec_stack);
936 resume_momentary ($2); }
937 | typed_declspecs_no_prefix_attr ';'
938 { shadow_tag_warned ($1, 1);
939 pedwarn ("empty declaration"); }
940 | declmods_no_prefix_attr ';'
941 { pedwarn ("empty declaration"); }
944 /* This combination which saves a lineno before a decl
945 is the normal thing to use, rather than decl itself.
946 This is to avoid shift/reduce conflicts in contexts
947 where statement labels are allowed. */
949 save_filename save_lineno decl
957 | lineno_decl errstmt
960 /* records the type and storage class specs to use for processing
961 the declarators that follow.
962 Maintains a stack of outer-level values of current_declspecs,
963 for the sake of parm declarations nested in function declarators. */
964 setspecs: /* empty */
965 { $$ = suspend_momentary ();
966 pending_xref_error ();
967 declspec_stack = tree_cons (prefix_attributes,
970 split_specs_attrs ($<ttype>0,
971 ¤t_declspecs, &prefix_attributes); }
974 /* ??? Yuck. See after_type_declarator. */
975 setattrs: /* empty */
976 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
980 typed_declspecs setspecs initdecls ';'
981 { current_declspecs = TREE_VALUE (declspec_stack);
982 prefix_attributes = TREE_PURPOSE (declspec_stack);
983 declspec_stack = TREE_CHAIN (declspec_stack);
984 resume_momentary ($2); }
985 | declmods setspecs notype_initdecls ';'
986 { current_declspecs = TREE_VALUE (declspec_stack);
987 prefix_attributes = TREE_PURPOSE (declspec_stack);
988 declspec_stack = TREE_CHAIN (declspec_stack);
989 resume_momentary ($2); }
990 | typed_declspecs setspecs nested_function
991 { current_declspecs = TREE_VALUE (declspec_stack);
992 prefix_attributes = TREE_PURPOSE (declspec_stack);
993 declspec_stack = TREE_CHAIN (declspec_stack);
994 resume_momentary ($2); }
995 | declmods setspecs notype_nested_function
996 { current_declspecs = TREE_VALUE (declspec_stack);
997 prefix_attributes = TREE_PURPOSE (declspec_stack);
998 declspec_stack = TREE_CHAIN (declspec_stack);
999 resume_momentary ($2); }
1000 | typed_declspecs ';'
1001 { shadow_tag ($1); }
1003 { pedwarn ("empty declaration"); }
1005 { pedantic = $<itype>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 /* Note that the call to clear_momentary
1245 is in process_init_element. */
1246 push_momentary (); }
1247 initlist_maybe_comma '}'
1248 { $$ = pop_init_level (0);
1249 if ($$ == error_mark_node
1250 && ! (yychar == STRING || yychar == CONSTANT))
1253 pop_momentary_nofree (); }
1256 { $$ = error_mark_node; }
1259 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1260 initlist_maybe_comma:
1263 pedwarn ("ANSI C forbids empty initializer braces"); }
1264 | initlist1 maybecomma
1269 | initlist1 ',' initelt
1272 /* `initelt' is a single element of an initializer.
1273 It may use braces. */
1275 designator_list '=' initval
1276 | designator initval
1278 { set_init_label ($1); }
1285 { push_init_level (0); }
1286 initlist_maybe_comma '}'
1287 { process_init_element (pop_init_level (0)); }
1289 { process_init_element ($1); }
1295 | designator_list designator
1300 { set_init_label ($2); }
1301 /* These are for labeled elements. The syntax for an array element
1302 initializer conflicts with the syntax for an Objective-C message,
1303 so don't include these productions in the Objective-C grammar. */
1305 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1306 { set_init_index ($2, $4); }
1307 | '[' expr_no_commas ']'
1308 { set_init_index ($2, NULL_TREE); }
1315 pedwarn ("ANSI C forbids nested functions");
1317 push_function_context ();
1318 if (! start_function (current_declspecs, $1,
1319 prefix_attributes, NULL_TREE, 1))
1321 pop_function_context ();
1324 reinit_parse_for_function (); }
1325 old_style_parm_decls
1326 { store_parm_decls (); }
1327 /* This used to use compstmt_or_error.
1328 That caused a bug with input `f(g) int g {}',
1329 where the use of YYERROR1 above caused an error
1330 which then was handled by compstmt_or_error.
1331 There followed a repeated execution of that same rule,
1332 which called YYERROR1 again, and so on. */
1334 { finish_function (1);
1335 pop_function_context (); }
1338 notype_nested_function:
1341 pedwarn ("ANSI C forbids nested functions");
1343 push_function_context ();
1344 if (! start_function (current_declspecs, $1,
1345 prefix_attributes, NULL_TREE, 1))
1347 pop_function_context ();
1350 reinit_parse_for_function (); }
1351 old_style_parm_decls
1352 { store_parm_decls (); }
1353 /* This used to use compstmt_or_error.
1354 That caused a bug with input `f(g) int g {}',
1355 where the use of YYERROR1 above caused an error
1356 which then was handled by compstmt_or_error.
1357 There followed a repeated execution of that same rule,
1358 which called YYERROR1 again, and so on. */
1360 { finish_function (1);
1361 pop_function_context (); }
1364 /* Any kind of declarator (thus, all declarators allowed
1365 after an explicit typespec). */
1368 after_type_declarator
1372 /* A declarator that is allowed only after an explicit typespec. */
1374 after_type_declarator:
1375 '(' after_type_declarator ')'
1377 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1378 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1379 /* | after_type_declarator '(' error ')' %prec '.'
1380 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1381 poplevel (0, 0, 0); } */
1382 | after_type_declarator '[' expr ']' %prec '.'
1383 { $$ = build_nt (ARRAY_REF, $1, $3); }
1384 | after_type_declarator '[' ']' %prec '.'
1385 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1386 | '*' type_quals after_type_declarator %prec UNARY
1387 { $$ = make_pointer_declarator ($2, $3); }
1388 /* ??? Yuck. setattrs is a quick hack. We can't use
1389 prefix_attributes because $1 only applies to this
1390 declarator. We assume setspecs has already been done.
1391 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1392 attributes could be recognized here or in `attributes'). */
1393 | attributes setattrs after_type_declarator
1401 /* Kinds of declarator that can appear in a parameter list
1402 in addition to notype_declarator. This is like after_type_declarator
1403 but does not allow a typedef name in parentheses as an identifier
1404 (because it would conflict with a function with that typedef as arg). */
1407 parm_declarator '(' parmlist_or_identifiers %prec '.'
1408 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1409 /* | parm_declarator '(' error ')' %prec '.'
1410 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1411 poplevel (0, 0, 0); } */
1413 | parm_declarator '[' '*' ']' %prec '.'
1414 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1416 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1419 | parm_declarator '[' expr ']' %prec '.'
1420 { $$ = build_nt (ARRAY_REF, $1, $3); }
1421 | parm_declarator '[' ']' %prec '.'
1422 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1423 | '*' type_quals parm_declarator %prec UNARY
1424 { $$ = make_pointer_declarator ($2, $3); }
1425 /* ??? Yuck. setattrs is a quick hack. We can't use
1426 prefix_attributes because $1 only applies to this
1427 declarator. We assume setspecs has already been done.
1428 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1429 attributes could be recognized here or in `attributes'). */
1430 | attributes setattrs parm_declarator
1435 /* A declarator allowed whether or not there has been
1436 an explicit typespec. These cannot redeclare a typedef-name. */
1439 notype_declarator '(' parmlist_or_identifiers %prec '.'
1440 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1441 /* | notype_declarator '(' error ')' %prec '.'
1442 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1443 poplevel (0, 0, 0); } */
1444 | '(' notype_declarator ')'
1446 | '*' type_quals notype_declarator %prec UNARY
1447 { $$ = make_pointer_declarator ($2, $3); }
1449 | notype_declarator '[' '*' ']' %prec '.'
1450 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1452 error ("`[*]' in parameter declaration only allowed in ISO C 9x");
1455 | notype_declarator '[' expr ']' %prec '.'
1456 { $$ = build_nt (ARRAY_REF, $1, $3); }
1457 | notype_declarator '[' ']' %prec '.'
1458 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1459 /* ??? Yuck. setattrs is a quick hack. We can't use
1460 prefix_attributes because $1 only applies to this
1461 declarator. We assume setspecs has already been done.
1462 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1463 attributes could be recognized here or in `attributes'). */
1464 | attributes setattrs notype_declarator
1491 struct_head identifier '{'
1492 { $$ = start_struct (RECORD_TYPE, $2);
1493 /* Start scope of tag before parsing components. */
1495 component_decl_list '}' maybe_attribute
1496 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1497 | struct_head '{' component_decl_list '}' maybe_attribute
1498 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1499 $3, chainon ($1, $5));
1501 | struct_head identifier
1502 { $$ = xref_tag (RECORD_TYPE, $2); }
1503 | union_head identifier '{'
1504 { $$ = start_struct (UNION_TYPE, $2); }
1505 component_decl_list '}' maybe_attribute
1506 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1507 | union_head '{' component_decl_list '}' maybe_attribute
1508 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1509 $3, chainon ($1, $5));
1511 | union_head identifier
1512 { $$ = xref_tag (UNION_TYPE, $2); }
1513 | enum_head identifier '{'
1514 { $<itype>3 = suspend_momentary ();
1515 $$ = start_enum ($2); }
1516 enumlist maybecomma_warn '}' maybe_attribute
1517 { $$= finish_enum ($<ttype>4, nreverse ($5), chainon ($1, $8));
1518 resume_momentary ($<itype>3); }
1520 { $<itype>2 = suspend_momentary ();
1521 $$ = start_enum (NULL_TREE); }
1522 enumlist maybecomma_warn '}' maybe_attribute
1523 { $$= finish_enum ($<ttype>3, nreverse ($4), chainon ($1, $7));
1524 resume_momentary ($<itype>2); }
1525 | enum_head identifier
1526 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1537 { if (pedantic && ! flag_isoc9x)
1538 pedwarn ("comma at end of enumerator list"); }
1541 component_decl_list:
1542 component_decl_list2
1544 | component_decl_list2 component_decl
1545 { $$ = chainon ($1, $2);
1546 pedwarn ("no semicolon at end of struct or union"); }
1549 component_decl_list2: /* empty */
1551 | component_decl_list2 component_decl ';'
1552 { $$ = chainon ($1, $2); }
1553 | component_decl_list2 ';'
1555 pedwarn ("extra semicolon in struct or union specified"); }
1557 /* foo(sizeof(struct{ @defs(ClassName)})); */
1558 | DEFS '(' CLASSNAME ')'
1560 tree interface = lookup_interface ($3);
1563 $$ = get_class_ivars (interface);
1566 error ("Cannot find interface declaration for `%s'",
1567 IDENTIFIER_POINTER ($3));
1574 /* There is a shift-reduce conflict here, because `components' may
1575 start with a `typename'. It happens that shifting (the default resolution)
1576 does the right thing, because it treats the `typename' as part of
1577 a `typed_typespecs'.
1579 It is possible that this same technique would allow the distinction
1580 between `notype_initdecls' and `initdecls' to be eliminated.
1581 But I am being cautious and not trying it. */
1584 typed_typespecs setspecs components
1586 current_declspecs = TREE_VALUE (declspec_stack);
1587 prefix_attributes = TREE_PURPOSE (declspec_stack);
1588 declspec_stack = TREE_CHAIN (declspec_stack);
1589 resume_momentary ($2); }
1592 pedwarn ("ANSI C forbids member declarations with no members");
1595 | nonempty_type_quals setspecs components
1597 current_declspecs = TREE_VALUE (declspec_stack);
1598 prefix_attributes = TREE_PURPOSE (declspec_stack);
1599 declspec_stack = TREE_CHAIN (declspec_stack);
1600 resume_momentary ($2); }
1601 | nonempty_type_quals
1603 pedwarn ("ANSI C forbids member declarations with no members");
1608 | extension component_decl
1610 pedantic = $<itype>1; }
1614 component_declarator
1615 | components ',' component_declarator
1616 { $$ = chainon ($1, $3); }
1619 component_declarator:
1620 save_filename save_lineno declarator maybe_attribute
1621 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1622 decl_attributes ($$, $4, prefix_attributes); }
1623 | save_filename save_lineno
1624 declarator ':' expr_no_commas maybe_attribute
1625 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1626 decl_attributes ($$, $6, prefix_attributes); }
1627 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1628 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1629 decl_attributes ($$, $5, prefix_attributes); }
1632 /* We chain the enumerators in reverse order.
1633 They are put in forward order where enumlist is used.
1634 (The order used to be significant, but no longer is so.
1635 However, we still maintain the order, just to be clean.) */
1639 | enumlist ',' enumerator
1640 { if ($1 == error_mark_node)
1643 $$ = chainon ($3, $1); }
1645 { $$ = error_mark_node; }
1651 { $$ = build_enumerator ($1, NULL_TREE); }
1652 | identifier '=' expr_no_commas
1653 { $$ = build_enumerator ($1, $3); }
1657 typed_typespecs absdcl
1658 { $$ = build_tree_list ($1, $2); }
1659 | nonempty_type_quals absdcl
1660 { $$ = build_tree_list ($1, $2); }
1663 absdcl: /* an absolute declarator */
1669 nonempty_type_quals:
1671 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1672 | nonempty_type_quals TYPE_QUAL
1673 { $$ = tree_cons (NULL_TREE, $2, $1); }
1679 | type_quals TYPE_QUAL
1680 { $$ = tree_cons (NULL_TREE, $2, $1); }
1683 absdcl1: /* a nonempty absolute declarator */
1686 /* `(typedef)1' is `int'. */
1687 | '*' type_quals absdcl1 %prec UNARY
1688 { $$ = make_pointer_declarator ($2, $3); }
1689 | '*' type_quals %prec UNARY
1690 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1691 | absdcl1 '(' parmlist %prec '.'
1692 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1693 | absdcl1 '[' expr ']' %prec '.'
1694 { $$ = build_nt (ARRAY_REF, $1, $3); }
1695 | absdcl1 '[' ']' %prec '.'
1696 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1697 | '(' parmlist %prec '.'
1698 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1699 | '[' expr ']' %prec '.'
1700 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1702 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1703 /* ??? It appears we have to support attributes here, however
1704 using prefix_attributes is wrong. */
1705 | attributes setattrs absdcl1
1709 /* at least one statement, the first of which parses without error. */
1710 /* stmts is used only after decls, so an invalid first statement
1711 is actually regarded as an invalid decl and part of the decls. */
1714 lineno_stmt_or_labels
1717 pedwarn ("ANSI C forbids label at end of compound statement");
1721 lineno_stmt_or_labels:
1722 lineno_stmt_or_label
1723 | lineno_stmt_or_labels lineno_stmt_or_label
1725 | lineno_stmt_or_labels errstmt
1737 pushlevel: /* empty */
1738 { emit_line_note (input_filename, lineno);
1742 expand_start_bindings (0);
1744 if (objc_method_context)
1750 /* Read zero or more forward-declarations for labels
1751 that nested functions can jump to. */
1756 pedwarn ("ANSI C forbids label declarations"); }
1761 | label_decls label_decl
1765 LABEL identifiers_or_typenames ';'
1767 for (link = $2; link; link = TREE_CHAIN (link))
1769 tree label = shadow_label (TREE_VALUE (link));
1770 C_DECLARED_LABEL_FLAG (label) = 1;
1771 declare_nonlocal_label (label);
1776 /* This is the body of a function definition.
1777 It causes syntax errors to ignore to the next openbrace. */
1784 compstmt_start: '{' { compstmt_count++; }
1786 compstmt_nostart: '}'
1787 { $$ = convert (void_type_node, integer_zero_node); }
1788 | pushlevel maybe_label_decls decls xstmts '}'
1789 { emit_line_note (input_filename, lineno);
1790 expand_end_bindings (getdecls (), 1, 0);
1791 $$ = poplevel (1, 1, 0);
1792 if (yychar == CONSTANT || yychar == STRING)
1793 pop_momentary_nofree ();
1796 | pushlevel maybe_label_decls error '}'
1797 { emit_line_note (input_filename, lineno);
1798 expand_end_bindings (getdecls (), kept_level_p (), 0);
1799 $$ = poplevel (kept_level_p (), 0, 0);
1800 if (yychar == CONSTANT || yychar == STRING)
1801 pop_momentary_nofree ();
1804 | pushlevel maybe_label_decls stmts '}'
1805 { emit_line_note (input_filename, lineno);
1806 expand_end_bindings (getdecls (), kept_level_p (), 0);
1807 $$ = poplevel (kept_level_p (), 0, 0);
1808 if (yychar == CONSTANT || yychar == STRING)
1809 pop_momentary_nofree ();
1814 compstmt_primary_start:
1816 { if (current_function_decl == 0)
1818 error ("braced-group within expression allowed only inside a function");
1821 /* We must force a BLOCK for this level
1822 so that, if it is not expanded later,
1823 there is a way to turn off the entire subtree of blocks
1824 that are contained in it. */
1826 push_iterator_stack ();
1827 push_label_level ();
1828 $$ = expand_start_stmt_expr ();
1832 compstmt: compstmt_start compstmt_nostart
1836 /* Value is number of statements counted as of the closeparen. */
1838 if_prefix lineno_labeled_stmt
1839 /* Make sure c_expand_end_cond is run once
1840 for each call to c_expand_start_cond.
1841 Otherwise a crash is likely. */
1847 { emit_line_note ($<filename>-1, $<lineno>0);
1848 c_expand_start_cond (truthvalue_conversion ($3), 0,
1850 $<itype>$ = stmt_count;
1851 if_stmt_file = $<filename>-1;
1852 if_stmt_line = $<lineno>0;
1853 position_after_white_space (); }
1856 /* This is a subroutine of stmt.
1857 It is used twice, once for valid DO statements
1858 and once for catching errors in parsing the end test. */
1863 emit_line_note ($<filename>-1, $<lineno>0);
1864 /* See comment in `while' alternative, above. */
1866 expand_start_loop_continue_elsewhere (1);
1867 position_after_white_space (); }
1868 lineno_labeled_stmt WHILE
1869 { expand_loop_continue_here (); }
1873 { $$ = input_filename; }
1880 lineno_labeled_stmt:
1881 save_filename save_lineno stmt
1883 /* | save_filename save_lineno error
1886 | save_filename save_lineno label lineno_labeled_stmt
1890 lineno_stmt_or_label:
1891 save_filename save_lineno stmt_or_label
1902 /* Parse a single real statement, not including any labels. */
1909 emit_line_note ($<filename>-1, $<lineno>0);
1910 /* It appears that this should not be done--that a non-lvalue array
1911 shouldn't get an error if the value isn't used.
1912 Section 3.2.2.1 says that an array lvalue gets converted to a pointer
1913 if it appears as a top-level expression,
1914 but says nothing about non-lvalue arrays. */
1916 /* Call default_conversion to get an error
1917 on referring to a register array if pedantic. */
1918 if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
1919 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
1920 $1 = default_conversion ($1);
1922 iterator_expand ($1);
1923 clear_momentary (); }
1925 { c_expand_start_else ();
1926 $<itype>1 = stmt_count;
1927 position_after_white_space (); }
1929 { c_expand_end_cond ();
1930 if (extra_warnings && stmt_count == $<itype>1)
1931 warning ("empty body in an else-statement"); }
1932 | simple_if %prec IF
1933 { c_expand_end_cond ();
1934 /* This warning is here instead of in simple_if, because we
1935 do not want a warning if an empty if is followed by an
1936 else statement. Increment stmt_count so we don't
1937 give a second error if this is a nested `if'. */
1938 if (extra_warnings && stmt_count++ == $<itype>1)
1939 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1940 "empty body in an if-statement"); }
1941 /* Make sure c_expand_end_cond is run once
1942 for each call to c_expand_start_cond.
1943 Otherwise a crash is likely. */
1944 | simple_if ELSE error
1945 { c_expand_end_cond (); }
1948 emit_line_note ($<filename>-1, $<lineno>0);
1949 /* The emit_nop used to come before emit_line_note,
1950 but that made the nop seem like part of the preceding line.
1951 And that was confusing when the preceding line was
1952 inside of an if statement and was not really executed.
1953 I think it ought to work to put the nop after the line number.
1954 We will see. --rms, July 15, 1991. */
1957 { /* Don't start the loop till we have succeeded
1958 in parsing the end test. This is to make sure
1959 that we end every loop we start. */
1960 expand_start_loop (1);
1961 emit_line_note (input_filename, lineno);
1962 expand_exit_loop_if_false (NULL_PTR,
1963 truthvalue_conversion ($4));
1964 position_after_white_space (); }
1966 { expand_end_loop (); }
1969 { emit_line_note (input_filename, lineno);
1970 expand_exit_loop_if_false (NULL_PTR,
1971 truthvalue_conversion ($3));
1973 clear_momentary (); }
1974 /* This rule is needed to make sure we end every loop we start. */
1975 | do_stmt_start error
1976 { expand_end_loop ();
1977 clear_momentary (); }
1981 emit_line_note ($<filename>-1, $<lineno>0);
1982 /* See comment in `while' alternative, above. */
1984 if ($3) c_expand_expr_stmt ($3);
1985 /* Next step is to call expand_start_loop_continue_elsewhere,
1986 but wait till after we parse the entire for (...).
1987 Otherwise, invalid input might cause us to call that
1988 fn without calling expand_end_loop. */
1991 /* Can't emit now; wait till after expand_start_loop... */
1992 { $<lineno>7 = lineno;
1993 $<filename>$ = input_filename; }
1996 /* Start the loop. Doing this after parsing
1997 all the expressions ensures we will end the loop. */
1998 expand_start_loop_continue_elsewhere (1);
1999 /* Emit the end-test, with a line number. */
2000 emit_line_note ($<filename>8, $<lineno>7);
2002 expand_exit_loop_if_false (NULL_PTR,
2003 truthvalue_conversion ($6));
2004 /* Don't let the tree nodes for $9 be discarded by
2005 clear_momentary during the parsing of the next stmt. */
2007 $<lineno>7 = lineno;
2008 $<filename>8 = input_filename;
2009 position_after_white_space (); }
2011 { /* Emit the increment expression, with a line number. */
2012 emit_line_note ($<filename>8, $<lineno>7);
2013 expand_loop_continue_here ();
2015 c_expand_expr_stmt ($9);
2016 if (yychar == CONSTANT || yychar == STRING)
2017 pop_momentary_nofree ();
2020 expand_end_loop (); }
2021 | SWITCH '(' expr ')'
2023 emit_line_note ($<filename>-1, $<lineno>0);
2024 c_expand_start_case ($3);
2025 /* Don't let the tree nodes for $3 be discarded by
2026 clear_momentary during the parsing of the next stmt. */
2028 position_after_white_space (); }
2030 { expand_end_case ($3);
2031 if (yychar == CONSTANT || yychar == STRING)
2032 pop_momentary_nofree ();
2037 emit_line_note ($<filename>-1, $<lineno>0);
2038 if ( ! expand_exit_something ())
2039 error ("break statement not within loop or switch"); }
2042 emit_line_note ($<filename>-1, $<lineno>0);
2043 if (! expand_continue_loop (NULL_PTR))
2044 error ("continue statement not within a loop"); }
2047 emit_line_note ($<filename>-1, $<lineno>0);
2048 c_expand_return (NULL_TREE); }
2051 emit_line_note ($<filename>-1, $<lineno>0);
2052 c_expand_return ($2); }
2053 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
2055 emit_line_note ($<filename>-1, $<lineno>0);
2057 if ((TREE_CODE ($4) == ADDR_EXPR
2058 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
2059 || TREE_CODE ($4) == STRING_CST)
2062 error ("argument of `asm' is not a constant string"); }
2063 /* This is the case with just output operands. */
2064 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
2066 emit_line_note ($<filename>-1, $<lineno>0);
2067 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2068 $2 == ridpointers[(int)RID_VOLATILE],
2069 input_filename, lineno); }
2070 /* This is the case with input operands as well. */
2071 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
2073 emit_line_note ($<filename>-1, $<lineno>0);
2074 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2075 $2 == ridpointers[(int)RID_VOLATILE],
2076 input_filename, lineno); }
2077 /* This is the case with clobbered registers as well. */
2078 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
2079 asm_operands ':' asm_clobbers ')' ';'
2081 emit_line_note ($<filename>-1, $<lineno>0);
2082 c_expand_asm_operands ($4, $6, $8, $10,
2083 $2 == ridpointers[(int)RID_VOLATILE],
2084 input_filename, lineno); }
2085 | GOTO identifier ';'
2088 emit_line_note ($<filename>-1, $<lineno>0);
2089 decl = lookup_label ($2);
2092 TREE_USED (decl) = 1;
2098 pedwarn ("ANSI C forbids `goto *expr;'");
2100 emit_line_note ($<filename>-1, $<lineno>0);
2101 expand_computed_goto (convert (ptr_type_node, $3)); }
2106 all_iter_stmt_simple
2107 /* | all_iter_stmt_with_decl */
2110 all_iter_stmt_simple:
2113 /* The value returned by this action is */
2114 /* 1 if everything is OK */
2115 /* 0 in case of error or already bound iterator */
2118 if (TREE_CODE ($3) != VAR_DECL)
2119 error ("invalid `for (ITERATOR)' syntax");
2120 else if (! ITERATOR_P ($3))
2121 error ("`%s' is not an iterator",
2122 IDENTIFIER_POINTER (DECL_NAME ($3)));
2123 else if (ITERATOR_BOUND_P ($3))
2124 error ("`for (%s)' inside expansion of same iterator",
2125 IDENTIFIER_POINTER (DECL_NAME ($3)));
2129 iterator_for_loop_start ($3);
2135 iterator_for_loop_end ($3);
2138 /* This really should allow any kind of declaration,
2139 for generality. Fix it before turning it back on.
2141 all_iter_stmt_with_decl:
2142 FOR '(' ITERATOR pushlevel setspecs iterator_spec ')'
2144 */ /* The value returned by this action is */
2145 /* 1 if everything is OK */
2146 /* 0 in case of error or already bound iterator */
2148 iterator_for_loop_start ($6);
2152 iterator_for_loop_end ($6);
2153 emit_line_note (input_filename, lineno);
2154 expand_end_bindings (getdecls (), 1, 0);
2155 $<ttype>$ = poplevel (1, 1, 0);
2156 if (yychar == CONSTANT || yychar == STRING)
2157 pop_momentary_nofree ();
2163 /* Any kind of label, including jump labels and case labels.
2164 ANSI C accepts labels only before statements, but we allow them
2165 also at the end of a compound statement. */
2167 label: CASE expr_no_commas ':'
2168 { register tree value = check_case_value ($2);
2170 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2174 if (value != error_mark_node)
2179 if (pedantic && ! INTEGRAL_TYPE_P (TREE_TYPE (value)))
2180 pedwarn ("label must have integral type in ANSI C");
2182 success = pushcase (value, convert_and_check,
2186 error ("case label not within a switch statement");
2187 else if (success == 2)
2189 error ("duplicate case value");
2190 error_with_decl (duplicate, "this is the first entry for that value");
2192 else if (success == 3)
2193 warning ("case value out of range");
2194 else if (success == 5)
2195 error ("case label within scope of cleanup or variable array");
2197 position_after_white_space (); }
2198 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
2199 { register tree value1 = check_case_value ($2);
2200 register tree value2 = check_case_value ($4);
2202 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2205 pedwarn ("ANSI C forbids case ranges");
2208 if (value1 != error_mark_node && value2 != error_mark_node)
2211 int success = pushcase_range (value1, value2,
2212 convert_and_check, label,
2215 error ("case label not within a switch statement");
2216 else if (success == 2)
2218 error ("duplicate case value");
2219 error_with_decl (duplicate, "this is the first entry for that value");
2221 else if (success == 3)
2222 warning ("case value out of range");
2223 else if (success == 4)
2224 warning ("empty case range");
2225 else if (success == 5)
2226 error ("case label within scope of cleanup or variable array");
2228 position_after_white_space (); }
2233 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2234 int success = pushcase (NULL_TREE, 0, label, &duplicate);
2237 error ("default label not within a switch statement");
2238 else if (success == 2)
2240 error ("multiple default labels in one switch");
2241 error_with_decl (duplicate, "this is the first default label");
2243 position_after_white_space (); }
2244 | identifier ':' maybe_attribute
2245 { tree label = define_label (input_filename, lineno, $1);
2250 expand_label (label);
2251 decl_attributes (label, $3, NULL_TREE);
2253 position_after_white_space (); }
2256 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2260 { emit_line_note (input_filename, lineno);
2263 { emit_line_note (input_filename, lineno); }
2272 /* These are the operands other than the first string and colon
2273 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2274 asm_operands: /* empty */
2276 | nonnull_asm_operands
2279 nonnull_asm_operands:
2281 | nonnull_asm_operands ',' asm_operand
2282 { $$ = chainon ($1, $3); }
2287 { $$ = build_tree_list ($1, $3); }
2292 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
2293 | asm_clobbers ',' string
2294 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
2297 /* This is what appears inside the parens in a function declarator.
2298 Its value is a list of ..._TYPE nodes. */
2301 clear_parm_order ();
2302 declare_parm_level (0); }
2305 parmlist_tags_warning ();
2306 poplevel (0, 0, 0); }
2314 pedwarn ("ANSI C forbids forward parameter declarations");
2315 /* Mark the forward decls as such. */
2316 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
2317 TREE_ASM_WRITTEN (parm) = 1;
2318 clear_parm_order (); }
2322 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
2325 /* This is what appears inside the parens in a function declarator.
2326 Is value is represented in the format that grokdeclarator expects. */
2327 parmlist_2: /* empty */
2328 { $$ = get_parm_info (0); }
2330 { $$ = get_parm_info (0);
2331 /* Gcc used to allow this as an extension. However, it does
2332 not work for all targets, and thus has been disabled.
2333 Also, since func (...) and func () are indistinguishable,
2334 it caused problems with the code in expand_builtin which
2335 tries to verify that BUILT_IN_NEXT_ARG is being used
2337 error ("ANSI C requires a named argument before `...'");
2340 { $$ = get_parm_info (1); }
2341 | parms ',' ELLIPSIS
2342 { $$ = get_parm_info (0); }
2347 { push_parm_decl ($1); }
2349 { push_parm_decl ($3); }
2352 /* A single parameter declaration or parameter type name,
2353 as found in a parmlist. */
2355 typed_declspecs setspecs parm_declarator maybe_attribute
2356 { $$ = build_tree_list (build_tree_list (current_declspecs,
2358 build_tree_list (prefix_attributes,
2360 current_declspecs = TREE_VALUE (declspec_stack);
2361 prefix_attributes = TREE_PURPOSE (declspec_stack);
2362 declspec_stack = TREE_CHAIN (declspec_stack);
2363 resume_momentary ($2); }
2364 | typed_declspecs setspecs notype_declarator maybe_attribute
2365 { $$ = build_tree_list (build_tree_list (current_declspecs,
2367 build_tree_list (prefix_attributes,
2369 current_declspecs = TREE_VALUE (declspec_stack);
2370 prefix_attributes = TREE_PURPOSE (declspec_stack);
2371 declspec_stack = TREE_CHAIN (declspec_stack);
2372 resume_momentary ($2); }
2373 | typed_declspecs setspecs absdcl maybe_attribute
2374 { $$ = build_tree_list (build_tree_list (current_declspecs,
2376 build_tree_list (prefix_attributes,
2378 current_declspecs = TREE_VALUE (declspec_stack);
2379 prefix_attributes = TREE_PURPOSE (declspec_stack);
2380 declspec_stack = TREE_CHAIN (declspec_stack);
2381 resume_momentary ($2); }
2382 | declmods setspecs notype_declarator maybe_attribute
2383 { $$ = build_tree_list (build_tree_list (current_declspecs,
2385 build_tree_list (prefix_attributes,
2387 current_declspecs = TREE_VALUE (declspec_stack);
2388 prefix_attributes = TREE_PURPOSE (declspec_stack);
2389 declspec_stack = TREE_CHAIN (declspec_stack);
2390 resume_momentary ($2); }
2392 | declmods setspecs absdcl maybe_attribute
2393 { $$ = build_tree_list (build_tree_list (current_declspecs,
2395 build_tree_list (prefix_attributes,
2397 current_declspecs = TREE_VALUE (declspec_stack);
2398 prefix_attributes = TREE_PURPOSE (declspec_stack);
2399 declspec_stack = TREE_CHAIN (declspec_stack);
2400 resume_momentary ($2); }
2403 /* This is used in a function definition
2404 where either a parmlist or an identifier list is ok.
2405 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2406 parmlist_or_identifiers:
2408 clear_parm_order ();
2409 declare_parm_level (1); }
2410 parmlist_or_identifiers_1
2412 parmlist_tags_warning ();
2413 poplevel (0, 0, 0); }
2416 parmlist_or_identifiers_1:
2420 for (t = $1; t; t = TREE_CHAIN (t))
2421 if (TREE_VALUE (t) == NULL_TREE)
2422 error ("`...' in old-style identifier list");
2423 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2426 /* A nonempty list of identifiers. */
2429 { $$ = build_tree_list (NULL_TREE, $1); }
2430 | identifiers ',' IDENTIFIER
2431 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2434 /* A nonempty list of identifiers, including typenames. */
2435 identifiers_or_typenames:
2437 { $$ = build_tree_list (NULL_TREE, $1); }
2438 | identifiers_or_typenames ',' identifier
2439 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2444 { $<itype>$ = pedantic;
2449 /* Objective-C productions. */
2459 if (objc_implementation_context)
2461 finish_class (objc_implementation_context);
2462 objc_ivar_chain = NULL_TREE;
2463 objc_implementation_context = NULL_TREE;
2466 warning ("`@end' must appear in an implementation context");
2470 /* A nonempty list of identifiers. */
2473 { $$ = build_tree_list (NULL_TREE, $1); }
2474 | identifier_list ',' identifier
2475 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2479 CLASS identifier_list ';'
2481 objc_declare_class ($2);
2485 ALIAS identifier identifier ';'
2487 objc_declare_alias ($2, $3);
2491 INTERFACE identifier protocolrefs '{'
2493 objc_interface_context = objc_ivar_context
2494 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2495 objc_public_flag = 0;
2499 continue_class (objc_interface_context);
2504 finish_class (objc_interface_context);
2505 objc_interface_context = NULL_TREE;
2508 | INTERFACE identifier protocolrefs
2510 objc_interface_context
2511 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2512 continue_class (objc_interface_context);
2517 finish_class (objc_interface_context);
2518 objc_interface_context = NULL_TREE;
2521 | INTERFACE identifier ':' identifier protocolrefs '{'
2523 objc_interface_context = objc_ivar_context
2524 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2525 objc_public_flag = 0;
2529 continue_class (objc_interface_context);
2534 finish_class (objc_interface_context);
2535 objc_interface_context = NULL_TREE;
2538 | INTERFACE identifier ':' identifier protocolrefs
2540 objc_interface_context
2541 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2542 continue_class (objc_interface_context);
2547 finish_class (objc_interface_context);
2548 objc_interface_context = NULL_TREE;
2551 | IMPLEMENTATION identifier '{'
2553 objc_implementation_context = objc_ivar_context
2554 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2555 objc_public_flag = 0;
2560 = continue_class (objc_implementation_context);
2563 | IMPLEMENTATION identifier
2565 objc_implementation_context
2566 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2568 = continue_class (objc_implementation_context);
2571 | IMPLEMENTATION identifier ':' identifier '{'
2573 objc_implementation_context = objc_ivar_context
2574 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2575 objc_public_flag = 0;
2580 = continue_class (objc_implementation_context);
2583 | IMPLEMENTATION identifier ':' identifier
2585 objc_implementation_context
2586 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2588 = continue_class (objc_implementation_context);
2591 | INTERFACE identifier '(' identifier ')' protocolrefs
2593 objc_interface_context
2594 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2595 continue_class (objc_interface_context);
2600 finish_class (objc_interface_context);
2601 objc_interface_context = NULL_TREE;
2604 | IMPLEMENTATION identifier '(' identifier ')'
2606 objc_implementation_context
2607 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2609 = continue_class (objc_implementation_context);
2614 PROTOCOL identifier protocolrefs
2616 remember_protocol_qualifiers ();
2617 objc_interface_context
2618 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2622 forget_protocol_qualifiers();
2623 finish_protocol(objc_interface_context);
2624 objc_interface_context = NULL_TREE;
2633 | non_empty_protocolrefs
2636 non_empty_protocolrefs:
2637 ARITHCOMPARE identifier_list ARITHCOMPARE
2639 if ($1 == LT_EXPR && $3 == GT_EXPR)
2647 ivar_decl_list visibility_spec ivar_decls
2652 PRIVATE { objc_public_flag = 2; }
2653 | PROTECTED { objc_public_flag = 0; }
2654 | PUBLIC { objc_public_flag = 1; }
2662 | ivar_decls ivar_decl ';'
2666 pedwarn ("extra semicolon in struct or union specified");
2671 /* There is a shift-reduce conflict here, because `components' may
2672 start with a `typename'. It happens that shifting (the default resolution)
2673 does the right thing, because it treats the `typename' as part of
2674 a `typed_typespecs'.
2676 It is possible that this same technique would allow the distinction
2677 between `notype_initdecls' and `initdecls' to be eliminated.
2678 But I am being cautious and not trying it. */
2681 typed_typespecs setspecs ivars
2683 current_declspecs = TREE_VALUE (declspec_stack);
2684 prefix_attributes = TREE_PURPOSE (declspec_stack);
2685 declspec_stack = TREE_CHAIN (declspec_stack);
2686 resume_momentary ($2); }
2687 | nonempty_type_quals setspecs ivars
2689 current_declspecs = TREE_VALUE (declspec_stack);
2690 prefix_attributes = TREE_PURPOSE (declspec_stack);
2691 declspec_stack = TREE_CHAIN (declspec_stack);
2692 resume_momentary ($2); }
2701 | ivars ',' ivar_declarator
2707 $$ = add_instance_variable (objc_ivar_context,
2709 $1, current_declspecs,
2712 | declarator ':' expr_no_commas
2714 $$ = add_instance_variable (objc_ivar_context,
2716 $1, current_declspecs, $3);
2718 | ':' expr_no_commas
2720 $$ = add_instance_variable (objc_ivar_context,
2723 current_declspecs, $2);
2730 remember_protocol_qualifiers ();
2731 if (objc_implementation_context)
2732 objc_inherit_code = CLASS_METHOD_DECL;
2734 fatal ("method definition not in class context");
2738 forget_protocol_qualifiers ();
2739 add_class_method (objc_implementation_context, $3);
2740 start_method_def ($3);
2741 objc_method_context = $3;
2745 continue_method_def ();
2749 finish_method_def ();
2750 objc_method_context = NULL_TREE;
2755 remember_protocol_qualifiers ();
2756 if (objc_implementation_context)
2757 objc_inherit_code = INSTANCE_METHOD_DECL;
2759 fatal ("method definition not in class context");
2763 forget_protocol_qualifiers ();
2764 add_instance_method (objc_implementation_context, $3);
2765 start_method_def ($3);
2766 objc_method_context = $3;
2770 continue_method_def ();
2774 finish_method_def ();
2775 objc_method_context = NULL_TREE;
2779 /* the reason for the strange actions in this rule
2780 is so that notype_initdecls when reached via datadef
2781 can find a valid list of type and sc specs in $0. */
2785 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2788 methodprotolist2: /* eliminates a shift/reduce conflict */
2791 | methodprotolist2 methodproto
2792 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2803 /* Remember protocol qualifiers in prototypes. */
2804 remember_protocol_qualifiers ();
2805 objc_inherit_code = CLASS_METHOD_DECL;
2809 /* Forget protocol qualifiers here. */
2810 forget_protocol_qualifiers ();
2811 add_class_method (objc_interface_context, $3);
2817 /* Remember protocol qualifiers in prototypes. */
2818 remember_protocol_qualifiers ();
2819 objc_inherit_code = INSTANCE_METHOD_DECL;
2823 /* Forget protocol qualifiers here. */
2824 forget_protocol_qualifiers ();
2825 add_instance_method (objc_interface_context, $3);
2831 '(' typename ')' unaryselector
2833 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2838 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2841 | '(' typename ')' keywordselector optparmlist
2843 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2846 | keywordselector optparmlist
2848 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2852 /* "optarglist" assumes that start_method_def has already been called...
2853 if it is not, the "xdecls" will not be placed in the proper scope */
2860 /* to get around the following situation: "int foo (int a) int b; {}" that
2861 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2876 typed_declspecs setspecs myparms ';'
2877 { current_declspecs = TREE_VALUE (declspec_stack);
2878 prefix_attributes = TREE_PURPOSE (declspec_stack);
2879 declspec_stack = TREE_CHAIN (declspec_stack);
2880 resume_momentary ($2); }
2881 | typed_declspecs ';'
2882 { shadow_tag ($1); }
2884 { pedwarn ("empty declaration"); }
2889 { push_parm_decl ($1); }
2890 | myparms ',' myparm
2891 { push_parm_decl ($3); }
2894 /* A single parameter declaration or parameter type name,
2895 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2898 parm_declarator maybe_attribute
2899 { $$ = build_tree_list (build_tree_list (current_declspecs,
2901 build_tree_list (prefix_attributes,
2903 | notype_declarator maybe_attribute
2904 { $$ = build_tree_list (build_tree_list (current_declspecs,
2906 build_tree_list (prefix_attributes,
2908 | absdcl maybe_attribute
2909 { $$ = build_tree_list (build_tree_list (current_declspecs,
2911 build_tree_list (prefix_attributes,
2922 /* oh what a kludge! */
2931 /* returns a tree list node generated by get_parm_info */
2944 | keywordselector keyworddecl
2946 $$ = chainon ($1, $2);
2958 ENUM { $$ = get_identifier (token_buffer); }
2959 | STRUCT { $$ = get_identifier (token_buffer); }
2960 | UNION { $$ = get_identifier (token_buffer); }
2961 | IF { $$ = get_identifier (token_buffer); }
2962 | ELSE { $$ = get_identifier (token_buffer); }
2963 | WHILE { $$ = get_identifier (token_buffer); }
2964 | DO { $$ = get_identifier (token_buffer); }
2965 | FOR { $$ = get_identifier (token_buffer); }
2966 | SWITCH { $$ = get_identifier (token_buffer); }
2967 | CASE { $$ = get_identifier (token_buffer); }
2968 | DEFAULT { $$ = get_identifier (token_buffer); }
2969 | BREAK { $$ = get_identifier (token_buffer); }
2970 | CONTINUE { $$ = get_identifier (token_buffer); }
2971 | RETURN { $$ = get_identifier (token_buffer); }
2972 | GOTO { $$ = get_identifier (token_buffer); }
2973 | ASM_KEYWORD { $$ = get_identifier (token_buffer); }
2974 | SIZEOF { $$ = get_identifier (token_buffer); }
2975 | TYPEOF { $$ = get_identifier (token_buffer); }
2976 | ALIGNOF { $$ = get_identifier (token_buffer); }
2977 | TYPESPEC | TYPE_QUAL
2981 selector ':' '(' typename ')' identifier
2983 $$ = build_keyword_decl ($1, $4, $6);
2986 | selector ':' identifier
2988 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2991 | ':' '(' typename ')' identifier
2993 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2998 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
3009 | keywordarglist keywordarg
3011 $$ = chainon ($1, $2);
3019 if (TREE_CHAIN ($1) == NULL_TREE)
3020 /* just return the expr., remove a level of indirection */
3021 $$ = TREE_VALUE ($1);
3023 /* we have a comma expr., we will collapse later */
3029 selector ':' keywordexpr
3031 $$ = build_tree_list ($1, $3);
3035 $$ = build_tree_list (NULL_TREE, $2);
3043 $$ = get_class_reference ($1);
3049 { objc_receiver_context = 1; }
3051 { objc_receiver_context = 0; }
3054 $$ = build_tree_list ($3, $5);
3065 | keywordnamelist keywordname
3067 $$ = chainon ($1, $2);
3074 $$ = build_tree_list ($1, NULL_TREE);
3078 $$ = build_tree_list (NULL_TREE, NULL_TREE);
3083 SELECTOR '(' selectorarg ')'
3090 PROTOCOL '(' identifier ')'
3096 /* extension to support C-structures in the archiver */
3099 ENCODE '(' typename ')'
3101 $$ = groktypename ($3);