Sync usage with man page.
[netbsd-mini2440.git] / gnu / usr.bin / g++ / cc1plus / cplus-parse.y
blob91d3a1b091852094ef3d55c7f4ccbdb1ac16fad0
1 /*-
2 * This code is derived from software copyrighted by the Free Software
3 * Foundation.
5 * Modified 1991 by Donn Seeley at UUNET Technologies, Inc.
6 */
8 /* YACC parser for C++ syntax.
9 Copyright (C) 1988, 1989 Free Software Foundation, Inc.
10 Hacked by Michael Tiemann (tiemann@mcc.com)
12 This file is part of GNU CC.
14 GNU CC is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 1, or (at your option)
17 any later version.
19 GNU CC is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with GNU CC; see the file COPYING. If not, write to
26 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
29 /* This grammar is based on the GNU CC grammar. */
31 /* Also note: this version contains experimental exception
32 handling features. They could break, change, disappear,
33 or otherwise exhibit volatile behavior. Don't depend on
34 me (Michael Tiemann) to protect you from any negative impact
35 this may have on your professional, personal, or spiritual life. */
38 #ifndef lint
39 static char sccsid[] = "@(#)cplus-parse.y 6.3 (Berkeley) 5/8/91";
40 #endif /* not lint */
42 #include "config.h"
43 #include "tree.h"
44 #include "input.h"
45 #include "cplus-parse.h"
46 #include "cplus-tree.h"
47 #include "assert.h"
49 /* C++ extensions */
50 extern tree ridpointers[]; /* need this up here */
51 extern tree void_list_node;
53 /* Bison compatibility */
54 #define YYEMPTY -1
55 #define YYLEX yylex()
57 #include <stdio.h>
58 #include <errno.h>
60 #ifndef errno
61 extern int errno;
62 #endif
64 extern int end_of_file;
66 void yyerror ();
68 /* Contains error message to give if user tries to declare
69 a variable where one does not belong. */
70 static char *stmt_decl_msg = 0;
72 #ifndef YYDEBUG
73 /* Cause the `yydebug' variable to be defined. */
74 int yydebug;
75 #endif
77 /* Cons up an empty parameter list. */
78 #ifdef __GNU__
79 __inline
80 #endif
81 static tree
82 empty_parms ()
84 tree parms;
86 if (strict_prototype)
87 parms = void_list_node;
88 else
89 parms = NULL_TREE;
90 return parms;
93 void yyhook ();
96 %start program
98 %union {long itype; tree ttype; enum tree_code code; }
100 /* All identifiers that are not reserved words
101 and are not declared typedefs in the current block */
102 %token IDENTIFIER
104 /* All identifiers that are declared typedefs in the current block.
105 In some contexts, they are treated just like IDENTIFIER,
106 but they can also serve as typespecs in declarations. */
107 %token TYPENAME
109 /* Reserved words that specify storage class.
110 yylval contains an IDENTIFIER_NODE which indicates which one. */
111 %token SCSPEC
113 /* Reserved words that specify type.
114 yylval contains an IDENTIFIER_NODE which indicates which one. */
115 %token TYPESPEC
117 /* Reserved words that qualify type: "const" or "volatile".
118 yylval contains an IDENTIFIER_NODE which indicates which one. */
119 %token TYPE_QUAL
121 /* Character or numeric constants.
122 yylval is the node for the constant. */
123 %token CONSTANT
125 /* String constants in raw form.
126 yylval is a STRING_CST node. */
127 %token STRING
129 /* "...", used for functions with variable arglists. */
130 %token ELLIPSIS
132 /* the reserved words */
133 %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
134 %token BREAK CONTINUE RETURN GOTO ASM TYPEOF ALIGNOF
135 %token ATTRIBUTE
137 /* the reserved words... C++ extensions */
138 %token <ttype> AGGR
139 %token DELETE NEW OVERLOAD PRIVATE PUBLIC PROTECTED THIS OPERATOR
140 %token DYNAMIC POINTSAT_LEFT_RIGHT LEFT_RIGHT
141 %token <itype> SCOPE
143 /* Define the operator tokens and their precedences.
144 The value is an integer because, if used, it is the tree code
145 to use in the expression made from the operator. */
147 %left EMPTY /* used to resolve s/r with epsilon */
149 /* Add precedence rules to solve dangling else s/r conflict */
150 %nonassoc IF
151 %nonassoc ELSE
153 %left IDENTIFIER TYPENAME TYPENAME_COLON SCSPEC TYPESPEC TYPE_QUAL ENUM AGGR
155 %left '{' ','
157 %right <code> ASSIGN '='
158 %right <code> '?' ':' RANGE
159 %left <code> OROR
160 %left <code> ANDAND
161 %left <code> '|'
162 %left <code> '^'
163 %left <code> '&'
164 %left <code> MIN_MAX
165 %left <code> EQCOMPARE
166 %left <code> ARITHCOMPARE
167 %left <code> LSHIFT RSHIFT
168 %left <code> '+' '-'
169 %left <code> '*' '/' '%'
170 %right <code> UNARY PLUSPLUS MINUSMINUS
171 %left HYPERUNARY
172 %left <ttype> PAREN_STAR_PAREN PAREN_X_SCOPE_STAR_PAREN PAREN_X_SCOPE_REF_PAREN LEFT_RIGHT
173 %left <code> POINTSAT '.' '(' '['
175 %right SCOPE /* C++ extension */
176 %nonassoc NEW DELETE RAISE RAISES RERAISE TRY EXCEPT CATCH
177 %right DYNAMIC
179 %type <code> unop
181 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist /* exprlist */
182 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
183 %type <ttype> typed_declspecs reserved_declspecs
184 %type <ttype> typed_typespecs reserved_typespecquals
185 %type <ttype> declmods typespec typespecqual_reserved
186 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
187 %type <itype> initdecls notype_initdecls initdcl /* C++ modification */
188 %type <ttype> init initlist maybeasm
189 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
190 %type <ttype> maybe_attribute attribute_list attrib
192 %type <ttype> compstmt except_stmts
194 %type <ttype> declarator notype_declarator after_type_declarator
196 %type <ttype> structsp opt.component_decl_list component_decl_list component_decl components component_declarator
197 %type <ttype> enumlist enumerator
198 %type <ttype> typename absdcl absdcl1 type_quals
199 %type <ttype> xexpr see_typename parmlist parms parm bad_parm
201 /* C++ extensions */
202 %token <ttype> TYPENAME_COLON TYPENAME_SCOPE TYPENAME_ELLIPSIS
203 %token <ttype> PRE_PARSED_FUNCTION_DECL EXTERN_LANG_STRING ALL
204 %type <ttype> fn.def2 dummy_decl x_typespec return_id
205 %type <ttype> class_head opt.init base_class_list base_class_visibility_list
206 %type <ttype> after_type_declarator_no_typename
207 %type <ttype> maybe_raises raise_identifier raise_identifiers
208 %type <ttype> component_declarator0 scoped_identifier
209 %type <ttype> forhead.1 identifier_or_opname operator_name
210 %type <ttype> new delete object primary_no_id aggr nonmomentary_expr
211 %type <itype> LC forhead.2 initdcl0 notype_initdcl0 wrapper member_init_list
212 %type <itype> .scope try
215 /* the declaration found for the last IDENTIFIER token read in.
216 yylex must look this up to detect typedefs, which get token type TYPENAME,
217 so it is left around in case the identifier is not a typedef but is
218 used in a context which makes it a reference to a variable. */
219 tree lastiddecl;
221 tree make_pointer_declarator (), make_reference_declarator ();
223 tree combine_strings ();
224 void reinit_parse_for_function ();
225 void reinit_parse_for_method ();
227 /* List of types and structure classes of the current declaration. */
228 tree current_declspecs;
230 int undeclared_variable_notice; /* 1 if we explained undeclared var errors. */
232 int yylex ();
233 extern FILE *finput;
237 program: .program /* empty */
238 | .program extdefs
239 { finish_file (); }
242 .program: /* empty */
244 if (flag_cadillac)
245 cadillac_start ();
248 /* the reason for the strange actions in this rule
249 is so that notype_initdecls when reached via datadef
250 can find a valid list of type and sc specs in $0. */
252 extdefs:
253 {$<ttype>$ = NULL_TREE; } extdef
254 | extdefs {$<ttype>$ = NULL_TREE; } extdef
257 extdef:
258 fndef
259 { if (pending_inlines) do_pending_inlines (); }
260 | datadef
261 { if (pending_inlines) do_pending_inlines (); }
262 | overloaddef
263 | ASM '(' string ')' ';'
264 { if (pedantic)
265 warning ("ANSI C forbids use of `asm' keyword");
266 if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
267 assemble_asm ($3); }
268 | extern_lang_string '{' extdefs '}'
269 { pop_lang_context (); }
270 | extern_lang_string '{' '}'
271 { pop_lang_context (); }
272 | extern_lang_string fndef
273 { if (pending_inlines) do_pending_inlines ();
274 pop_lang_context (); }
275 | extern_lang_string datadef
276 { if (pending_inlines) do_pending_inlines ();
277 pop_lang_context (); }
280 extern_lang_string:
281 EXTERN_LANG_STRING
282 { push_lang_context ($1); }
285 overloaddef:
286 OVERLOAD ov_identifiers ';'
288 ov_identifiers: IDENTIFIER
289 { declare_overloaded ($1); }
290 | ov_identifiers ',' IDENTIFIER
291 { declare_overloaded ($3); }
294 dummy_decl: /* empty */
295 { $$ = NULL_TREE; }
298 datadef:
299 dummy_decl notype_initdecls ';'
300 { if (pedantic)
301 error ("ANSI C forbids data definition lacking type or storage class");
302 else if (! flag_traditional)
303 warning ("data definition lacks type or storage class"); }
304 | declmods notype_initdecls ';'
306 /* Normal case to make fast: "int i;". */
307 | declmods declarator ';'
308 { tree d;
309 d = start_decl ($2, $1, 0, NULL_TREE);
310 finish_decl (d, NULL_TREE, NULL_TREE);
312 | typed_declspecs initdecls ';'
314 end_exception_decls ();
315 note_got_semicolon ($1);
317 /* Normal case: make this fast. */
318 | typed_declspecs declarator ';'
319 { tree d;
320 d = start_decl ($2, $1, 0, NULL_TREE);
321 finish_decl (d, NULL_TREE, NULL_TREE);
322 end_exception_decls ();
323 note_got_semicolon ($1);
325 | declmods ';'
326 { error ("empty declaration"); }
327 | typed_declspecs ';'
329 shadow_tag ($1);
330 note_got_semicolon ($1);
332 | error ';'
333 | error '}'
334 | ';'
337 fndef:
338 fn.def1 base_init compstmt_or_error
340 finish_function (lineno, 1);
341 /* finish_function performs these three statements:
343 expand_end_bindings (getdecls (), 1, 0);
344 poplevel (1, 1, 0);
346 expand_end_bindings (0, 0, 0);
347 poplevel (0, 0, 1);
350 | fn.def1 return_init base_init compstmt_or_error
352 finish_function (lineno, 1);
353 /* finish_function performs these three statements:
355 expand_end_bindings (getdecls (), 1, 0);
356 poplevel (1, 1, 0);
358 expand_end_bindings (0, 0, 0);
359 poplevel (0, 0, 1);
362 | fn.def1 nodecls compstmt_or_error
363 { finish_function (lineno, 0); }
364 | fn.def1 return_init ';' nodecls compstmt_or_error
365 { finish_function (lineno, 0); }
366 | fn.def1 return_init nodecls compstmt_or_error
367 { finish_function (lineno, 0); }
368 | typed_declspecs declarator error
370 | declmods notype_declarator error
372 | dummy_decl notype_declarator error
376 fn.def1:
377 typed_declspecs declarator maybe_raises
378 { if (! start_function ($1, $2, $3, 0))
379 YYERROR;
380 reinit_parse_for_function (); }
381 | declmods notype_declarator maybe_raises
382 { if (! start_function ($1, $2, $3, 0))
383 YYERROR;
384 reinit_parse_for_function (); }
385 | dummy_decl notype_declarator maybe_raises
386 { if (! start_function (NULL_TREE, $2, $3, 0))
387 YYERROR;
388 reinit_parse_for_function (); }
389 | dummy_decl TYPENAME '(' parmlist ')' type_quals maybe_raises
390 { if (! start_function (NULL_TREE, build_parse_node (CALL_EXPR, $2, $4, $6), $7, 0))
391 YYERROR;
392 reinit_parse_for_function (); }
393 | dummy_decl TYPENAME LEFT_RIGHT type_quals maybe_raises
394 { if (! start_function (NULL_TREE, build_parse_node (CALL_EXPR, $2, empty_parms (), $4), $5, 0))
395 YYERROR;
396 reinit_parse_for_function (); }
397 | PRE_PARSED_FUNCTION_DECL
398 { start_function (NULL_TREE, $1, NULL_TREE, 1);
399 reinit_parse_for_function (); }
402 /* more C++ complexity */
403 fn.def2:
404 typed_declspecs '(' parmlist ')' type_quals maybe_raises
406 tree decl = build_parse_node (CALL_EXPR, TREE_VALUE ($1), $3, $5);
407 $$ = start_method (TREE_CHAIN ($1), decl, $6);
408 if (! $$)
409 YYERROR;
410 if (yychar == -1)
411 yychar = yylex();
412 reinit_parse_for_method (yychar, $$); }
413 | typed_declspecs LEFT_RIGHT type_quals maybe_raises
415 tree decl = build_parse_node (CALL_EXPR, TREE_VALUE ($1), empty_parms (), $3);
416 $$ = start_method (TREE_CHAIN ($1), decl, $4);
417 if (! $$)
418 YYERROR;
419 if (yychar == YYEMPTY)
420 yychar = YYLEX;
421 reinit_parse_for_method (yychar, $$); }
422 | typed_declspecs declarator maybe_raises
423 { $$ = start_method ($1, $2, $3);
424 if (! $$)
425 YYERROR;
426 if (yychar == YYEMPTY)
427 yychar = YYLEX;
428 reinit_parse_for_method (yychar, $$); }
429 | declmods '(' parmlist ')' type_quals maybe_raises
431 tree decl = build_parse_node (CALL_EXPR, TREE_VALUE ($1), $3, $5);
432 $$ = start_method (TREE_CHAIN ($1), decl, $6);
433 if (! $$)
434 YYERROR;
435 if (yychar == YYEMPTY)
436 yychar = YYLEX;
437 reinit_parse_for_method (yychar, $$); }
438 | declmods LEFT_RIGHT type_quals maybe_raises
440 tree decl = build_parse_node (CALL_EXPR, TREE_VALUE ($1), empty_parms (), $3);
441 $$ = start_method (TREE_CHAIN ($1), decl, $4);
442 if (! $$)
443 YYERROR;
444 if (yychar == YYEMPTY)
445 yychar = YYLEX;
446 reinit_parse_for_method (yychar, $$); }
447 | declmods declarator maybe_raises
448 { $$ = start_method ($1, $2, $3);
449 if (! $$)
450 YYERROR;
451 if (yychar == YYEMPTY)
452 yychar = YYLEX;
453 reinit_parse_for_method (yychar, $$); }
454 | dummy_decl notype_declarator maybe_raises
455 { $$ = start_method (NULL_TREE, $2, $3);
456 if (! $$)
457 YYERROR;
458 if (yychar == YYEMPTY)
459 yychar = YYLEX;
460 reinit_parse_for_method (yychar, $$); }
463 return_id: RETURN IDENTIFIER
465 if (! current_function_parms_stored)
466 store_parm_decls ();
467 $$ = $2;
471 return_init: return_id opt.init
473 extern tree value_identifier;
474 tree result;
476 result = DECL_RESULT (current_function_decl);
477 if (DECL_NAME (result) == value_identifier)
478 DECL_NAME (result) = $1;
479 else
480 error ("return identifier `%s' already in place",
481 IDENTIFIER_POINTER (DECL_NAME (result)));
482 store_return_init ($2);
484 | return_id '(' nonnull_exprlist ')'
486 extern tree value_identifier;
487 tree result;
489 result = DECL_RESULT (current_function_decl);
490 if (DECL_NAME (result) == value_identifier)
491 DECL_NAME (result) = $1;
492 else
493 error ("return identifier `%s' already in place",
494 IDENTIFIER_POINTER (DECL_NAME (result)));
495 store_return_init ($3);
497 | return_id LEFT_RIGHT
499 extern tree value_identifier;
500 tree result;
502 result = DECL_RESULT (current_function_decl);
503 if (DECL_NAME (result) == value_identifier)
504 DECL_NAME (result) = $1;
505 else
506 error ("return identifier `%s' already in place",
507 IDENTIFIER_POINTER (DECL_NAME (result)));
508 store_return_init (NULL_TREE);
512 base_init:
513 ':' .set_base_init member_init_list
515 if ($3 == 0)
516 error ("no base initializers given following ':'");
517 setup_vtbl_ptr ();
521 .set_base_init:
522 /* empty */
524 int preserve = (current_class_type
525 && TYPE_USES_VIRTUAL_BASECLASSES (current_class_type));
526 preserve = 0; /* "in charge" arg means we no longer
527 need this hack. */
528 if (! current_function_parms_stored)
529 store_parm_decls ();
530 else if (preserve)
531 preserve_data ();
533 /* Flag that we are processing base and member initializers. */
534 current_vtable_decl = error_mark_node;
536 if (DECL_CONSTRUCTOR_P (current_function_decl))
538 /* Make a contour for the initializer list. */
539 pushlevel (0);
540 clear_last_expr ();
541 expand_start_bindings (0);
543 else if (current_class_type == NULL_TREE)
544 error ("base initializers not allowed for non-member functions");
545 else if (! DECL_CONSTRUCTOR_P (current_function_decl))
546 error ("only constructors take base initializers");
550 member_init_list:
551 /* empty */
552 { $$ = 0; }
553 | member_init
554 { $$ = 1; }
555 | member_init_list ',' member_init
556 | member_init_list error
561 member_init: '(' nonnull_exprlist ')'
563 if (current_class_name && pedantic)
564 warning ("old style base class initialization; use `%s (...)'",
565 IDENTIFIER_POINTER (current_class_name));
566 expand_member_init (C_C_D, NULL_TREE, $2);
568 | LEFT_RIGHT
570 if (current_class_name && pedantic)
571 warning ("old style base class initialization; use `%s (...)'",
572 IDENTIFIER_POINTER (current_class_name));
573 expand_member_init (C_C_D, NULL_TREE, void_type_node);
575 | identifier '(' nonnull_exprlist ')'
577 expand_member_init (C_C_D, $1, $3);
579 | identifier LEFT_RIGHT
580 { expand_member_init (C_C_D, $1, void_type_node); }
581 | scoped_identifier identifier '(' nonnull_exprlist ')'
583 tree base, basetype;
584 tree scopes = $1;
586 if (TREE_CODE (scopes) == SCOPE_REF)
587 /* just a pain to do this right now. */
588 abort ();
590 if (current_class_type == NULL_TREE
591 || ! is_aggr_typedef (scopes, 1))
592 break;
593 basetype = get_base_type (TREE_TYPE (TREE_TYPE (scopes)),
594 current_class_type, 1);
595 if (basetype == error_mark_node)
596 break;
597 if (basetype == 0)
599 error_not_base_type (TREE_TYPE (TREE_TYPE (scopes)), current_class_type);
600 break;
603 base = convert_pointer_to (basetype, current_class_decl);
604 expand_member_init (build_indirect_ref (base), $2, $4);
606 | scoped_identifier identifier LEFT_RIGHT
608 tree basetype, base;
609 tree scopes = $1;
610 if (TREE_CODE (scopes) == SCOPE_REF)
611 /* just a pain to do this right now. */
612 abort ();
614 if (current_class_type == NULL_TREE
615 || ! is_aggr_typedef (scopes, 1))
616 break;
617 basetype = get_base_type (TREE_TYPE (TREE_TYPE (scopes)),
618 current_class_type, 1);
619 if (basetype == error_mark_node)
620 break;
621 if (basetype == 0)
623 error_not_base_type (TREE_TYPE (TREE_TYPE (scopes)), current_class_type);
624 break;
627 base = convert_pointer_to (basetype, current_class_decl);
628 expand_member_init (build_indirect_ref (base), $2, void_type_node);
632 identifier:
633 IDENTIFIER
634 | TYPENAME
637 identifier_or_opname:
638 IDENTIFIER
639 | TYPENAME
640 | '~' identifier
641 { $$ = build_parse_node (BIT_NOT_EXPR, $2); }
642 | operator_name
643 { $$ = hack_operator ($1);
644 if ($$ == error_mark_node)
645 $$ = get_identifier ("<missing operator>"); }
646 | wrapper IDENTIFIER
647 { $$ = hack_wrapper ($1, NULL_TREE, $2); }
648 | wrapper TYPENAME
649 { $$ = hack_wrapper ($1, NULL_TREE, $2); }
650 | wrapper operator_name
651 { $$ = hack_wrapper ($1, NULL_TREE, $2); }
652 | wrapper scoped_identifier IDENTIFIER
653 { $$ = hack_wrapper ($1, $2, $3); }
654 | wrapper scoped_identifier operator_name
655 { $$ = hack_wrapper ($1, $2, $3); }
658 wrapper: LEFT_RIGHT
659 { $$ = 0; }
660 | '~' LEFT_RIGHT
661 { $$ = 1; }
662 | LEFT_RIGHT '?'
663 { $$ = 2; }
666 unop: '-'
667 { $$ = NEGATE_EXPR; }
668 | '+'
669 { $$ = CONVERT_EXPR; }
670 | PLUSPLUS
671 { $$ = PREINCREMENT_EXPR; }
672 | MINUSMINUS
673 { $$ = PREDECREMENT_EXPR; }
674 | '!'
675 { $$ = TRUTH_NOT_EXPR; }
678 expr: nonnull_exprlist
679 { $$ = build_x_compound_expr ($1); }
680 /* Ugly, but faster. */
681 | expr_no_commas
683 if (TREE_CODE ($1) == CALL_EXPR
684 && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE ($1)))
685 $$ = cleanup_after_call ($1);
689 /* Now obsolete.
690 exprlist:
691 / * empty * /
692 { $$ = NULL_TREE; }
693 | nonnull_exprlist
697 nonnull_exprlist:
698 expr_no_commas
699 { $$ = build_tree_list (NULL_TREE, $1); }
700 | nonnull_exprlist ',' expr_no_commas
701 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
702 | nonnull_exprlist ',' error
703 { chainon ($1, build_tree_list (NULL_TREE, error_mark_node)); }
706 unary_expr:
707 primary %prec UNARY
709 if (TREE_CODE ($1) == TYPE_EXPR)
710 $$ = build_component_type_expr (C_C_D, $1, NULL_TREE, 1);
711 else
712 $$ = $1;
714 | '*' cast_expr %prec UNARY
715 { $$ = build_x_indirect_ref ($2, "unary *"); }
716 | '&' cast_expr %prec UNARY
717 { $$ = build_x_unary_op (ADDR_EXPR, $2); }
718 | '~' cast_expr %prec UNARY
719 { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
720 | unop cast_expr %prec UNARY
721 { $$ = build_x_unary_op ($1, $2);
722 if ($1 == NEGATE_EXPR && TREE_CODE ($2) == INTEGER_CST)
723 TREE_NEGATED_INT ($$) = 1;
725 | SIZEOF unary_expr %prec UNARY
726 { if (TREE_CODE ($2) == COMPONENT_REF
727 && TREE_PACKED (TREE_OPERAND ($2, 1)))
728 error ("sizeof applied to a bit-field");
729 /* ANSI says arrays and functions are converted inside comma.
730 But we can't really convert them in build_compound_expr
731 because that would break commas in lvalues.
732 So do the conversion here if operand was a comma. */
733 if (TREE_CODE ($2) == COMPOUND_EXPR
734 && (TREE_CODE (TREE_TYPE ($2)) == ARRAY_TYPE
735 || TREE_CODE (TREE_TYPE ($2)) == FUNCTION_TYPE))
736 $2 = default_conversion ($2);
737 $$ = c_sizeof (TREE_TYPE ($2)); }
738 | SIZEOF '(' typename ')' %prec HYPERUNARY
739 { $$ = c_sizeof (groktypename ($3)); }
740 | ALIGNOF unary_expr %prec UNARY
741 { if (TREE_CODE ($2) == COMPONENT_REF
742 && TREE_PACKED (TREE_OPERAND ($2, 1)))
743 error ("`__alignof' applied to a bit-field");
744 if (TREE_CODE ($2) == INDIRECT_REF)
746 tree t = TREE_OPERAND ($2, 0);
747 tree best = t;
748 int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
749 while (TREE_CODE (t) == NOP_EXPR
750 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
752 int thisalign;
753 t = TREE_OPERAND (t, 0);
754 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
755 if (thisalign > bestalign)
756 best = t, bestalign = thisalign;
758 $$ = c_alignof (TREE_TYPE (TREE_TYPE (best)));
760 else
762 /* ANSI says arrays and fns are converted inside comma.
763 But we can't convert them in build_compound_expr
764 because that would break commas in lvalues.
765 So do the conversion here if operand was a comma. */
766 if (TREE_CODE ($2) == COMPOUND_EXPR
767 && (TREE_CODE (TREE_TYPE ($2)) == ARRAY_TYPE
768 || TREE_CODE (TREE_TYPE ($2)) == FUNCTION_TYPE))
769 $2 = default_conversion ($2);
770 $$ = c_alignof (TREE_TYPE ($2));
773 | ALIGNOF '(' typename ')' %prec HYPERUNARY
774 { $$ = c_alignof (groktypename ($3)); }
776 | .scope new typename %prec '='
777 { $$ = build_new ($2, $3, NULL_TREE, $1); }
778 | .scope new x_typespec '(' nonnull_exprlist ')'
779 { $$ = build_new ($2, $3, $5, $1); }
780 | .scope new x_typespec LEFT_RIGHT
781 { $$ = build_new ($2, $3, NULL_TREE, $1); }
782 | .scope new typename '=' init %prec '='
783 { $$ = build_new ($2, $3, $5, $1); }
784 | .scope new '(' typename ')'
785 { $$ = build_new ($2, $4, NULL_TREE, $1); }
786 /* Unswallow a ':' which is probably meant for ?: expression. */
787 | .scope new TYPENAME_COLON
788 { yyungetc (':', 1);
789 $$ = build_new ($2, $3, NULL_TREE, $1); }
791 | delete cast_expr %prec UNARY
792 { tree expr = stabilize_reference (convert_from_reference ($2));
793 tree type = TREE_TYPE (expr);
795 if (integer_zerop (expr))
796 $$ = build1 (NOP_EXPR, void_type_node, expr);
797 else if (TREE_CODE (type) != POINTER_TYPE)
799 error ("non-pointer type to `delete'");
800 $$ = error_mark_node;
801 break;
803 if (TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
804 $$ = build_delete (type, expr, integer_three_node,
805 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, $1);
806 else if (! TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (type)))
807 $$ = build_x_delete (type, expr, $1);
808 else
809 $$ = build_delete (type, expr, integer_three_node,
810 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 0);
812 | delete '[' expr ']' cast_expr %prec UNARY
814 tree maxindex = build_binary_op (MINUS_EXPR, $3, integer_one_node);
815 tree exp = stabilize_reference (convert_from_reference ($5));
816 tree elt_size = c_sizeof (TREE_TYPE (exp));
818 if (yychar == YYEMPTY)
819 yychar = YYLEX;
821 $$ = build_vec_delete (exp, maxindex, elt_size, NULL_TREE,
822 integer_one_node, integer_two_node);
826 cast_expr:
827 unary_expr
828 | '(' typename ')' expr_no_commas %prec UNARY
829 { tree type = groktypename ($2);
830 $$ = build_c_cast (type, $4); }
831 | '(' typename ')' '{' initlist maybecomma '}' %prec UNARY
832 { tree type = groktypename ($2);
833 tree init = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($5));
834 if (pedantic)
835 warning ("ANSI C forbids constructor-expressions");
836 /* Indicate that this was a GNU C constructor expression. */
837 TREE_HAS_CONSTRUCTOR (init) = 1;
838 $$ = digest_init (type, init, 0);
839 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
841 int failure = complete_array_type (type, $$, 1);
842 if (failure)
843 abort ();
848 expr_no_commas:
849 cast_expr
850 | expr_no_commas '+' expr_no_commas
851 { $$ = build_x_binary_op ($2, $1, $3); }
852 | expr_no_commas '-' expr_no_commas
853 { $$ = build_x_binary_op ($2, $1, $3); }
854 | expr_no_commas '*' expr_no_commas
855 { $$ = build_x_binary_op ($2, $1, $3); }
856 | expr_no_commas '/' expr_no_commas
857 { $$ = build_x_binary_op ($2, $1, $3); }
858 | expr_no_commas '%' expr_no_commas
859 { $$ = build_x_binary_op ($2, $1, $3); }
860 | expr_no_commas LSHIFT expr_no_commas
861 { $$ = build_x_binary_op ($2, $1, $3); }
862 | expr_no_commas RSHIFT expr_no_commas
863 { $$ = build_x_binary_op ($2, $1, $3); }
864 | expr_no_commas ARITHCOMPARE expr_no_commas
865 { $$ = build_x_binary_op ($2, $1, $3); }
866 | expr_no_commas EQCOMPARE expr_no_commas
867 { $$ = build_x_binary_op ($2, $1, $3); }
868 | expr_no_commas MIN_MAX expr_no_commas
869 { $$ = build_x_binary_op ($2, $1, $3); }
870 | expr_no_commas '&' expr_no_commas
871 { $$ = build_x_binary_op ($2, $1, $3); }
872 | expr_no_commas '|' expr_no_commas
873 { $$ = build_x_binary_op ($2, $1, $3); }
874 | expr_no_commas '^' expr_no_commas
875 { $$ = build_x_binary_op ($2, $1, $3); }
876 | expr_no_commas ANDAND expr_no_commas
877 { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
878 | expr_no_commas OROR expr_no_commas
879 { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
880 | expr_no_commas '?' xexpr ':' expr_no_commas
881 { $$ = build_x_conditional_expr ($1, $3, $5); }
882 | expr_no_commas '=' expr_no_commas
883 { $$ = build_modify_expr ($1, NOP_EXPR, $3); }
884 | expr_no_commas ASSIGN expr_no_commas
885 { register tree rval;
886 if (rval = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, $1, $3, $2))
887 $$ = rval;
888 else
889 $$ = build_modify_expr ($1, $2, $3); }
891 /* Handle general members. */
892 | object '*' expr_no_commas %prec UNARY
893 { $$ = build_m_component_ref ($1, build_x_indirect_ref ($3, "unary *")); }
894 | object '&' expr_no_commas %prec UNARY
895 { $$ = build_m_component_ref ($1, build_x_unary_op (ADDR_EXPR, $3)); }
896 | object unop expr_no_commas %prec UNARY
897 { $$ = build_m_component_ref ($1, build_x_unary_op ($2, $3)); }
898 | object '(' typename ')' expr_no_commas %prec UNARY
899 { tree type = groktypename ($3);
900 $$ = build_m_component_ref ($1, build_c_cast (type, $5)); }
901 | object primary_no_id %prec UNARY
902 { $$ = build_m_component_ref ($1, $2); }
905 primary:
906 IDENTIFIER
907 { $$ = do_identifier ($1); }
908 | operator_name
910 tree op = hack_operator ($1);
911 if (TREE_CODE (op) != IDENTIFIER_NODE)
912 $$ = op;
913 else
915 $$ = lookup_name (op);
916 if ($$ == NULL_TREE)
918 error ("operator %s not defined", operator_name_string (op));
919 $$ = error_mark_node;
923 | CONSTANT
924 | string
925 { $$ = combine_strings ($1); }
926 | '(' expr ')'
927 { $$ = $2; }
928 | '(' error ')'
929 { $$ = error_mark_node; }
930 | '('
931 { if (current_function_decl == 0)
933 error ("braced-group within expression allowed only inside a function");
934 YYERROR;
936 keep_next_level ();
937 $<ttype>$ = expand_start_stmt_expr (); }
938 compstmt ')'
939 { tree rtl_exp;
940 if (pedantic)
941 warning ("ANSI C forbids braced-groups within expressions");
942 rtl_exp = expand_end_stmt_expr ($<ttype>2);
943 $$ = $3;
944 TREE_USED ($$) = 0;
945 /* Since the statements have side effects,
946 consider this volatile. */
947 TREE_VOLATILE ($$) = 1;
948 TREE_TYPE ($$) = TREE_TYPE (rtl_exp);
949 STMT_BODY ($$) = rtl_exp; }
950 | primary '(' nonnull_exprlist ')'
951 { $$ = build_x_function_call ($1, $3, current_class_decl); }
952 | primary LEFT_RIGHT
953 { $$ = build_x_function_call ($1, NULL_TREE, current_class_decl); }
954 | primary '[' expr ']'
956 do_array:
958 tree type = TREE_TYPE ($1);
959 if (type == error_mark_node || $3 == error_mark_node)
960 $$ = error_mark_node;
961 else if (type == NULL_TREE)
963 /* Something has gone very wrong. Assume we
964 are mistakenly reducing an expression
965 instead of a declaration. */
966 error ("parser may be lost: is there a '{' missing somewhere?");
967 $$ = NULL_TREE;
969 else
971 if (TREE_CODE (type) == OFFSET_TYPE)
972 type = TREE_TYPE (type);
973 if (TREE_CODE (type) == REFERENCE_TYPE)
974 type = TREE_TYPE (type);
976 if (TYPE_LANG_SPECIFIC (type) &&
977 TYPE_OVERLOADS_ARRAY_REF (type))
978 $$ = build_opfncall (ARRAY_REF, LOOKUP_NORMAL, $1, $3);
979 else if (TREE_CODE (type) == POINTER_TYPE
980 || TREE_CODE (type) == ARRAY_TYPE)
981 $$ = build_array_ref ($1, $3);
982 else
983 error("[] applied to non-pointer type");
987 | object identifier_or_opname %prec UNARY
988 { $$ = build_component_ref ($1, $2, NULL_TREE, 1); }
989 | object scoped_identifier identifier_or_opname %prec UNARY
991 tree basetype = (TREE_CODE ($2) == SCOPE_REF) ? TREE_OPERAND ($2, 1) : $2;
992 if (is_aggr_typedef (basetype, 1))
994 basetype = TREE_TYPE (TREE_TYPE (basetype));
996 if ($1 == error_mark_node)
997 $$ = error_mark_node;
998 else if (basetype_or_else (basetype, TREE_TYPE ($1)))
999 $$ = build_component_ref (build_scoped_ref ($1, $2), $3, NULL_TREE, 1);
1000 else
1001 $$ = error_mark_node;
1003 else $$ = error_mark_node;
1005 | primary PLUSPLUS
1006 { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $1); }
1007 | primary MINUSMINUS
1008 { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $1); }
1010 /* C++ extensions */
1011 | THIS
1012 { if (current_class_decl)
1014 #ifdef WARNING_ABOUT_CCD
1015 TREE_USED (current_class_decl) = 1;
1016 #endif
1017 $$ = current_class_decl;
1019 else if (current_function_decl
1020 && DECL_STATIC_FUNCTION_P (current_function_decl))
1022 error ("`this' is unavailable for static member functions");
1023 $$ = error_mark_node;
1025 else
1027 if (current_function_decl)
1028 error ("invalid use of `this' in non-member function");
1029 else
1030 error ("invalid use of `this' at top level");
1031 $$ = error_mark_node;
1034 | dummy_decl TYPE_QUAL '(' nonnull_exprlist ')'
1036 tree type;
1037 tree id = $2;
1039 /* This is a C cast in C++'s `functional' notation. */
1040 if ($4 == error_mark_node)
1042 $$ = error_mark_node;
1043 break;
1045 #if 0
1046 if ($4 == NULL_TREE)
1048 error ("cannot cast null list to type `%s'",
1049 IDENTIFIER_POINTER (TYPE_NAME ($2)));
1050 $$ = error_mark_node;
1051 break;
1053 #endif
1054 if (type == error_mark_node)
1055 $$ = error_mark_node;
1056 else
1058 if (id == ridpointers[(int) RID_CONST])
1059 type = build_type_variant (integer_type_node, 1, 0);
1060 else if (id == ridpointers[(int) RID_VOLATILE])
1061 type = build_type_variant (integer_type_node, 0, 1);
1062 else if (id == ridpointers[(int) RID_FRIEND])
1064 error ("cannot cast expression to `friend' type");
1065 $$ = error_mark_node;
1066 break;
1068 else abort ();
1069 $$ = build_c_cast (type, build_compound_expr ($4));
1072 | x_typespec '(' nonnull_exprlist ')'
1073 { $$ = build_functional_cast ($1, $3); }
1074 | x_typespec LEFT_RIGHT
1075 { $$ = build_functional_cast ($1, NULL_TREE); }
1076 | SCOPE IDENTIFIER
1078 do_scoped_identifier:
1079 $$ = IDENTIFIER_GLOBAL_VALUE ($2);
1080 if (yychar == YYEMPTY)
1081 yychar = YYLEX;
1082 if (! $$)
1084 if (yychar == '(' || yychar == LEFT_RIGHT)
1086 $$ = implicitly_declare ($2);
1088 else
1090 if (IDENTIFIER_GLOBAL_VALUE ($2) != error_mark_node)
1091 error ("undeclared variable `%s' (first use here)",
1092 IDENTIFIER_POINTER ($2));
1093 $$ = error_mark_node;
1094 /* Prevent repeated error messages. */
1095 IDENTIFIER_GLOBAL_VALUE ($2) = error_mark_node;
1098 else if (TREE_CODE ($$) == CONST_DECL)
1099 $$ = DECL_INITIAL ($$);
1100 if (! TREE_USED ($$))
1102 if (TREE_EXTERNAL ($$))
1103 assemble_external ($$);
1104 TREE_USED ($$) = 1;
1107 | SCOPE operator_name
1109 $2 = hack_operator ($2);
1110 if (TREE_CODE ($2) == IDENTIFIER_NODE)
1111 goto do_scoped_identifier;
1112 do_scoped_operator:
1113 $$ = $2;
1115 | scoped_identifier identifier_or_opname %prec HYPERUNARY
1116 { $$ = build_offset_ref ($1, $2); }
1117 | scoped_identifier identifier_or_opname '(' nonnull_exprlist ')'
1118 { $$ = build_member_call ($1, $2, $4); }
1119 | scoped_identifier identifier_or_opname LEFT_RIGHT
1120 { $$ = build_member_call ($1, $2, NULL_TREE); }
1122 | object identifier_or_opname '(' nonnull_exprlist ')'
1123 { $$ = build_method_call ($1, $2, $4, NULL_TREE,
1124 (LOOKUP_NORMAL|LOOKUP_AGGR)); }
1125 | object identifier_or_opname LEFT_RIGHT
1126 { $$ = build_method_call ($1, $2, NULL_TREE, NULL_TREE,
1127 (LOOKUP_NORMAL|LOOKUP_AGGR)); }
1128 | object scoped_identifier identifier_or_opname '(' nonnull_exprlist ')'
1129 { $$ = build_scoped_method_call ($1, $2, $3, $5); }
1130 | object scoped_identifier identifier_or_opname LEFT_RIGHT
1131 { $$ = build_scoped_method_call ($1, $2, $3, NULL_TREE); }
1134 primary_no_id:
1135 '(' expr ')'
1136 { $$ = $2; }
1137 | '(' error ')'
1138 { $$ = error_mark_node; }
1139 | '('
1140 { if (current_function_decl == 0)
1142 error ("braced-group within expression allowed only inside a function");
1143 YYERROR;
1145 $<ttype>$ = expand_start_stmt_expr (); }
1146 compstmt ')'
1147 { if (pedantic)
1148 warning ("ANSI C forbids braced-groups within expressions");
1149 $$ = expand_end_stmt_expr ($<ttype>2); }
1150 | primary_no_id '(' nonnull_exprlist ')'
1151 { $$ = build_x_function_call ($1, $3, current_class_decl); }
1152 | primary_no_id LEFT_RIGHT
1153 { $$ = build_x_function_call ($1, NULL_TREE, current_class_decl); }
1154 | primary_no_id '[' expr ']'
1155 { goto do_array; }
1156 | primary_no_id PLUSPLUS
1157 { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $1); }
1158 | primary_no_id MINUSMINUS
1159 { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $1); }
1160 | SCOPE IDENTIFIER
1161 { goto do_scoped_identifier; }
1162 | SCOPE operator_name
1163 { $2 = hack_operator ($2);
1164 if (TREE_CODE ($2) == IDENTIFIER_NODE)
1165 goto do_scoped_identifier;
1166 goto do_scoped_operator;
1170 new: NEW
1171 { $$ = NULL_TREE; }
1172 | NEW '{' nonnull_exprlist '}'
1173 { $$ = $3; }
1174 | NEW DYNAMIC %prec EMPTY
1175 { $$ = void_type_node; }
1176 | NEW DYNAMIC '(' string ')'
1177 { $$ = combine_strings ($4); }
1180 .scope:
1181 /* empty */
1182 { $$ = 0; }
1183 | SCOPE
1184 { $$ = 1; }
1187 delete: DELETE
1188 { $$ = NULL_TREE; }
1189 | SCOPE delete
1190 { if ($2)
1191 error ("extra `::' before `delete' ignored");
1192 $$ = error_mark_node;
1196 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
1197 string:
1198 STRING
1199 | string STRING
1200 { $$ = chainon ($1, $2); }
1203 nodecls:
1204 /* empty */
1206 if (! current_function_parms_stored)
1207 store_parm_decls ();
1208 setup_vtbl_ptr ();
1212 object: primary '.'
1214 if ($1 == error_mark_node)
1215 $$ = error_mark_node;
1216 else
1218 tree type = TREE_TYPE ($1);
1220 if (IS_AGGR_TYPE (type)
1221 || (TREE_CODE (type) == REFERENCE_TYPE
1222 && IS_AGGR_TYPE (TREE_TYPE (type))))
1223 $$ = $1;
1224 else
1226 error ("object in '.' expression is not of aggregate type");
1227 $$ = error_mark_node;
1231 | primary POINTSAT
1233 $$ = build_x_arrow ($1);
1237 decl:
1238 typed_declspecs initdecls ';'
1240 resume_momentary ($2);
1241 note_got_semicolon ($1);
1243 /* Normal case: make this fast. */
1244 | typed_declspecs declarator ';'
1245 { tree d;
1246 int yes = suspend_momentary ();
1247 d = start_decl ($2, $1, 0, NULL_TREE);
1248 finish_decl (d, NULL_TREE, NULL_TREE);
1249 resume_momentary (yes);
1250 note_got_semicolon ($1);
1252 | declmods notype_initdecls ';'
1253 { resume_momentary ($2); }
1254 /* Normal case: make this fast. */
1255 | declmods declarator ';'
1256 { tree d;
1257 int yes = suspend_momentary ();
1258 d = start_decl ($2, $1, 0, NULL_TREE);
1259 finish_decl (d, NULL_TREE, NULL_TREE);
1260 resume_momentary (yes);
1262 | typed_declspecs ';'
1264 shadow_tag ($1);
1265 note_got_semicolon ($1);
1267 | declmods ';'
1268 { warning ("empty declaration"); }
1271 /* Any kind of declarator (thus, all declarators allowed
1272 after an explicit typespec). */
1274 declarator:
1275 after_type_declarator
1276 | notype_declarator
1279 /* Declspecs which contain at least one type specifier or typedef name.
1280 (Just `const' or `volatile' is not enough.)
1281 A typedef'd name following these is taken as a name to be declared. */
1283 typed_declspecs:
1284 x_typespec
1285 { $$ = list_hash_lookup_or_cons ($1); }
1286 | declmods typespec
1287 { $$ = hash_tree_chain ($2, $1); }
1288 | x_typespec reserved_declspecs
1289 { $$ = hash_tree_chain ($1, $2); }
1290 | declmods typespec reserved_declspecs
1291 { $$ = hash_tree_chain ($2, hash_chainon ($3, $1)); }
1294 reserved_declspecs: /* empty
1295 { $$ = NULL_TREE; } */
1296 typespecqual_reserved
1297 { $$ = build_decl_list (NULL_TREE, $1); }
1298 | SCSPEC
1299 { $$ = build_decl_list (NULL_TREE, $1); }
1300 | reserved_declspecs typespecqual_reserved
1301 { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
1302 | reserved_declspecs SCSPEC
1303 { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
1306 /* List of just storage classes and type modifiers.
1307 A declaration can start with just this, but then it cannot be used
1308 to redeclare a typedef-name. */
1310 declmods:
1311 dummy_decl TYPE_QUAL
1312 { $$ = IDENTIFIER_AS_LIST ($2); }
1313 | dummy_decl SCSPEC
1314 { $$ = IDENTIFIER_AS_LIST ($2); }
1315 | declmods TYPE_QUAL
1316 { $$ = hash_tree_chain ($2, $1); }
1317 | declmods SCSPEC
1318 { $$ = hash_tree_chain ($2, $1); }
1322 /* Used instead of declspecs where storage classes are not allowed
1323 (that is, for typenames and structure components).
1325 C++ can takes storage classes for structure components.
1326 Don't accept a typedef-name if anything but a modifier precedes it. */
1328 typed_typespecs:
1329 x_typespec %prec EMPTY
1330 { $$ = build_decl_list_1 ($1); }
1331 | nonempty_type_quals typespec
1332 { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
1333 | x_typespec reserved_typespecquals
1334 { $$ = decl_tree_cons (NULL_TREE, $1, $2); }
1335 | nonempty_type_quals typespec reserved_typespecquals
1336 { $$ = decl_tree_cons (NULL_TREE, $2, hash_chainon ($3, $1)); }
1339 reserved_typespecquals:
1340 typespecqual_reserved
1341 { $$ = build_decl_list_1 ($1); }
1342 | reserved_typespecquals typespecqual_reserved
1343 { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
1346 /* A typespec (but not a type qualifier).
1347 Once we have seen one of these in a declaration,
1348 if a typedef name appears then it is being redeclared. */
1350 typespec: TYPESPEC
1351 | structsp
1352 | TYPENAME
1353 | TYPEOF '(' expr ')'
1354 { $$ = TREE_TYPE ($3);
1355 if (pedantic)
1356 warning ("ANSI C forbids `typeof'"); }
1357 | TYPEOF '(' typename ')'
1358 { $$ = groktypename ($3);
1359 if (pedantic)
1360 warning ("ANSI C forbids `typeof'"); }
1363 /* A typespec that is a reserved word, or a type qualifier. */
1365 typespecqual_reserved: TYPESPEC
1366 | TYPE_QUAL
1367 | structsp
1370 x_typespec:
1371 dummy_decl TYPESPEC
1372 { $$ = $2; }
1373 | dummy_decl structsp
1374 { $$ = $2; }
1375 | dummy_decl TYPENAME
1376 { $$ = $2; }
1377 | dummy_decl TYPEOF '(' expr ')'
1378 { $$ = TREE_TYPE ($4);
1379 if (pedantic)
1380 warning ("ANSI C forbids `typeof'"); }
1381 | dummy_decl TYPEOF '(' typename ')'
1382 { $$ = groktypename ($4);
1383 if (pedantic)
1384 warning ("ANSI C forbids `typeof'"); }
1387 initdecls:
1388 initdcl0
1389 | initdecls ',' initdcl
1392 notype_initdecls:
1393 notype_initdcl0
1394 | notype_initdecls ',' initdcl
1397 maybeasm:
1398 /* empty */
1399 { $$ = NULL_TREE; }
1400 | ASM '(' string ')'
1401 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1402 $$ = $3;
1403 if (pedantic)
1404 warning ("ANSI C forbids use of `asm' keyword");
1408 initdcl0:
1409 declarator maybe_raises maybeasm maybe_attribute '='
1410 { current_declspecs = $<ttype>0;
1411 $<itype>5 = suspend_momentary ();
1412 $<ttype>$ = start_decl ($1, current_declspecs, 1, $2); }
1413 init
1414 /* Note how the declaration of the variable is in effect while its init is parsed! */
1415 { finish_decl ($<ttype>6, $7, $3);
1416 $$ = $<itype>5; }
1417 | declarator maybe_raises maybeasm maybe_attribute
1418 { tree d;
1419 current_declspecs = $<ttype>0;
1420 $$ = suspend_momentary ();
1421 d = start_decl ($1, current_declspecs, 0, $2);
1422 finish_decl (d, NULL_TREE, $3); }
1425 initdcl:
1426 declarator maybe_raises maybeasm maybe_attribute '='
1427 { $<ttype>$ = start_decl ($1, current_declspecs, 1, $2); }
1428 init
1429 /* Note how the declaration of the variable is in effect while its init is parsed! */
1430 { finish_decl ($<ttype>6, $7, $3); }
1431 | declarator maybe_raises maybeasm maybe_attribute
1432 { tree d = start_decl ($1, current_declspecs, 0, $2);
1433 finish_decl (d, NULL_TREE, $3); }
1436 notype_initdcl0:
1437 notype_declarator maybe_raises maybeasm maybe_attribute '='
1438 { current_declspecs = $<ttype>0;
1439 $<itype>5 = suspend_momentary ();
1440 $<ttype>$ = start_decl ($1, current_declspecs, 1, $2); }
1441 init
1442 /* Note how the declaration of the variable is in effect while its init is parsed! */
1443 { finish_decl ($<ttype>6, $7, $3);
1444 $$ = $<itype>5; }
1445 | notype_declarator maybe_raises maybeasm maybe_attribute
1446 { tree d;
1447 current_declspecs = $<ttype>0;
1448 $$ = suspend_momentary ();
1449 d = start_decl ($1, current_declspecs, 0, $2);
1450 finish_decl (d, NULL_TREE, $3); }
1453 /* the * rules are dummies to accept the Apollo extended syntax
1454 so that the header files compile. */
1455 maybe_attribute:
1456 /* empty */
1457 { $$ = NULL_TREE; }
1458 | ATTRIBUTE '(' '(' attribute_list ')' ')'
1459 { $$ = $4; }
1462 attribute_list
1463 : attrib
1464 | attribute_list ',' attrib
1467 attrib
1468 : IDENTIFIER
1469 { warning ("`%s' attribute directive ignored",
1470 IDENTIFIER_POINTER ($1));
1471 $$ = $1; }
1472 | IDENTIFIER '(' CONSTANT ')'
1473 { /* if not "aligned(1)", then issue warning */
1474 if (strcmp (IDENTIFIER_POINTER ($1), "aligned") != 0
1475 || TREE_CODE ($3) != INTEGER_CST
1476 || TREE_INT_CST_LOW ($3) != 1)
1477 warning ("`%s' attribute directive ignored",
1478 IDENTIFIER_POINTER ($1));
1479 $$ = $1; }
1480 | IDENTIFIER '(' identifiers ')'
1481 { warning ("`%s' attribute directive ignored",
1482 IDENTIFIER_POINTER ($1));
1483 $$ = $1; }
1486 identifiers:
1487 IDENTIFIER
1489 | identifiers ',' IDENTIFIER
1493 init:
1494 expr_no_commas %prec '='
1495 | '{' '}'
1496 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
1497 TREE_HAS_CONSTRUCTOR ($$) = 1;
1498 if (pedantic)
1499 warning ("ANSI C forbids empty initializer braces"); }
1500 | '{' initlist '}'
1501 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
1502 TREE_HAS_CONSTRUCTOR ($$) = 1; }
1503 | '{' initlist ',' '}'
1504 { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
1505 TREE_HAS_CONSTRUCTOR ($$) = 1; }
1506 | error
1507 { $$ = NULL_TREE; }
1510 /* This chain is built in reverse order,
1511 and put in forward order where initlist is used. */
1512 initlist:
1513 init
1514 { $$ = build_tree_list (NULL_TREE, $1); }
1515 | initlist ',' init
1516 { $$ = tree_cons (NULL_TREE, $3, $1); }
1519 structsp:
1520 ENUM identifier '{'
1521 { $<itype>3 = suspend_momentary ();
1522 $$ = start_enum ($2); }
1523 enumlist maybecomma_warn '}'
1524 { $$ = finish_enum ($<ttype>4, $5);
1525 resume_momentary ($<itype>3);
1526 check_for_missing_semicolon ($<ttype>4); }
1527 | ENUM identifier '{' '}'
1528 { $$ = finish_enum (start_enum ($2), NULL_TREE);
1529 check_for_missing_semicolon ($$); }
1530 | ENUM '{'
1531 { $<itype>2 = suspend_momentary ();
1532 $$ = start_enum (make_anon_name ()); }
1533 enumlist maybecomma_warn '}'
1534 { $$ = finish_enum ($<ttype>3, $4);
1535 resume_momentary ($<itype>1);
1536 check_for_missing_semicolon ($<ttype>3); }
1537 | ENUM '{' '}'
1538 { $$ = finish_enum (start_enum (make_anon_name()), NULL_TREE);
1539 check_for_missing_semicolon ($$); }
1540 | ENUM identifier
1541 { $$ = xref_tag (enum_type_node, $2, NULL_TREE); }
1543 /* C++ extensions, merged with C to avoid shift/reduce conflicts */
1544 | class_head LC opt.component_decl_list '}'
1546 if (TREE_CODE ($1) == ENUMERAL_TYPE)
1547 $$ = $1;
1548 else if (CLASSTYPE_DECLARED_EXCEPTION ($1))
1549 $$ = finish_exception ($1, $3);
1550 else
1551 $$ = finish_struct ($1, $3, 0, 0);
1553 if ($2 & 1)
1554 resume_temporary_allocation ();
1555 if ($2 & 2)
1556 resume_momentary (1);
1557 check_for_missing_semicolon ($$);
1559 | class_head LC opt.component_decl_list '}' ';'
1560 { if (TREE_CODE ($1) == ENUMERAL_TYPE)
1561 $$ = $1;
1562 else if (CLASSTYPE_DECLARED_EXCEPTION ($1))
1563 warning ("empty exception declaration\n");
1564 else
1565 $$ = finish_struct ($1, $3, 1, 1);
1566 if ($2 & 1)
1567 resume_temporary_allocation ();
1568 if ($2 & 2)
1569 resume_momentary (1);
1570 note_got_semicolon ($$);
1571 yyungetc (';', 0); }
1572 | class_head %prec EMPTY
1573 { $$ = $1; }
1576 maybecomma:
1577 /* empty */
1578 | ','
1581 maybecomma_warn:
1582 /* empty */
1583 | ','
1584 { if (pedantic) warning ("comma at end of enumerator list"); }
1587 aggr: AGGR
1588 { $$ = $1; }
1589 | DYNAMIC AGGR
1590 { $$ = build_tree_list (NULL_TREE, $2); }
1591 | DYNAMIC '(' string ')' AGGR
1592 { $$ = build_tree_list ($3, $5); }
1593 | aggr SCSPEC
1594 { error ("storage class specifier `%s' not allow after struct or class", IDENTIFIER_POINTER ($2));
1596 | aggr TYPESPEC
1597 { error ("type specifier `%s' not allow after struct or class", IDENTIFIER_POINTER ($2));
1599 | aggr TYPE_QUAL
1600 { error ("type qualifier `%s' not allow after struct or class", IDENTIFIER_POINTER ($2));
1602 | aggr AGGR
1603 { error ("no body nor ';' separates two class, struct or union declarations");
1606 class_head:
1607 aggr %prec EMPTY
1608 { $$ = xref_tag ($1, make_anon_name (), NULL_TREE); }
1609 | aggr identifier %prec EMPTY
1610 { $$ = xref_tag ($1, $2, NULL_TREE); }
1611 | aggr IDENTIFIER ':' base_class_list %prec EMPTY
1612 { $$ = xref_tag ($1, $2, $4); }
1613 | aggr TYPENAME_COLON %prec EMPTY
1614 { yyungetc (':', 1);
1615 $$ = xref_tag ($1, $2, NULL_TREE); }
1616 | aggr TYPENAME_COLON base_class_list %prec EMPTY
1617 { $$ = xref_tag ($1, $2, $3); }
1620 base_class_list:
1621 identifier
1622 { if (! is_aggr_typedef ($1, 1))
1623 $$ = NULL_TREE;
1624 else $$ = build_tree_list ((tree)visibility_default, $1); }
1625 | base_class_visibility_list identifier
1626 { if (! is_aggr_typedef ($2, 1))
1627 $$ = NULL_TREE;
1628 else $$ = build_tree_list ($1, $2); }
1629 | base_class_list ',' identifier
1630 { if (! is_aggr_typedef ($3, 1))
1631 $$ = NULL_TREE;
1632 else $$ = chainon ($1, build_tree_list ((tree)visibility_default, $3)); }
1633 | base_class_list ',' base_class_visibility_list identifier
1634 { if (! is_aggr_typedef ($4, 1))
1635 $$ = NULL_TREE;
1636 else $$ = chainon ($1, build_tree_list ($3, $4)); }
1639 base_class_visibility_list:
1640 PUBLIC
1641 { $$ = (tree)visibility_public; }
1642 | PRIVATE
1643 { $$ = (tree)visibility_private; }
1644 | SCSPEC
1645 { if ($1 != ridpointers[(int)RID_VIRTUAL])
1646 sorry ("non-virtual visibility");
1647 $$ = (tree)visibility_default_virtual; }
1648 | base_class_visibility_list PUBLIC
1649 { if ($1 == (tree)visibility_private)
1650 error ("base class cannot be public and private");
1651 else if ($1 == (tree)visibility_default_virtual)
1652 $$ = (tree)visibility_public_virtual; }
1653 | base_class_visibility_list PRIVATE
1654 { if ($1 == (tree)visibility_public)
1655 error ("base class cannot be private and public");
1656 else if ($1 == (tree)visibility_default_virtual)
1657 $$ = (tree)visibility_private_virtual; }
1658 | base_class_visibility_list SCSPEC
1659 { if ($2 != ridpointers[(int)RID_VIRTUAL])
1660 sorry ("non-virtual visibility");
1661 if ($1 == (tree)visibility_public)
1662 $$ = (tree)visibility_public_virtual;
1663 else if ($1 == (tree)visibility_private)
1664 $$ = (tree)visibility_private_virtual; }
1667 LC: '{'
1668 { int temp = allocation_temporary_p ();
1669 int momentary = suspend_momentary ();
1670 if (temp)
1671 end_temporary_allocation ();
1672 $$ = (momentary << 1) | temp;
1673 if (! IS_AGGR_TYPE ($<ttype>0))
1675 $<ttype>0 = make_lang_type (RECORD_TYPE);
1676 TYPE_NAME ($<ttype>0) = get_identifier ("erroneous type");
1678 pushclass ($<ttype>0, 0); }
1680 opt.component_decl_list:
1681 /* empty */
1682 { $$ = NULL_TREE; }
1683 | component_decl_list
1684 { $$ = build_tree_list ((tree)visibility_default, $1); }
1685 | opt.component_decl_list PUBLIC ':' component_decl_list
1686 { $$ = chainon ($1, build_tree_list ((tree)visibility_public, $4)); }
1687 | opt.component_decl_list PRIVATE ':' component_decl_list
1688 { $$ = chainon ($1, build_tree_list ((tree)visibility_private, $4)); }
1689 | opt.component_decl_list PROTECTED ':' component_decl_list
1690 { $$ = chainon ($1, build_tree_list ((tree)visibility_protected, $4)); }
1691 | opt.component_decl_list PUBLIC ':'
1692 | opt.component_decl_list PRIVATE ':'
1693 | opt.component_decl_list PROTECTED ':'
1696 component_decl_list:
1697 component_decl
1698 { if ($1 == void_type_node) $$ = NULL_TREE; }
1699 | component_decl_list component_decl
1700 { if ($2 != NULL_TREE && $2 != void_type_node)
1701 $$ = chainon ($1, $2); }
1702 | component_decl_list ';'
1703 { if (pedantic)
1704 warning ("extra semicolon in struct or union specified"); }
1707 component_decl:
1708 typed_declspecs components ';'
1710 do_components:
1711 if ($2 == void_type_node)
1712 /* We just got some friends.
1713 They have been recorded elsewhere. */
1714 $$ = NULL_TREE;
1715 else if ($2 == NULL_TREE)
1717 tree t = groktypename (build_decl_list ($1, NULL_TREE));
1718 if (t == NULL_TREE)
1720 error ("error in component specification");
1721 $$ = NULL_TREE;
1723 else if (TREE_CODE (t) == UNION_TYPE)
1725 /* handle anonymous unions */
1726 if (CLASSTYPE_METHOD_VEC (t))
1727 sorry ("methods in anonymous unions");
1728 $$ = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
1729 DECL_ANON_UNION_ELEM ($$) = 1;
1731 else if (TREE_CODE (t) == ENUMERAL_TYPE)
1732 $$ = grok_enum_decls (t, NULL_TREE);
1733 else if (TREE_CODE (t) == RECORD_TYPE)
1735 if (TYPE_LANG_SPECIFIC (t)
1736 && CLASSTYPE_DECLARED_EXCEPTION (t))
1737 shadow_tag ($1);
1738 $$ = NULL_TREE;
1740 else if (t != void_type_node)
1742 error ("empty component declaration");
1743 $$ = NULL_TREE;
1745 else $$ = NULL_TREE;
1747 else
1749 tree t = TREE_TYPE ($2);
1750 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL (t))
1751 $$ = grok_enum_decls (t, $2);
1752 else
1753 $$ = $2;
1755 end_exception_decls ();
1757 | typed_declspecs '(' parmlist ')' ';'
1758 { $$ = groktypefield ($1, $3); }
1759 | typed_declspecs '(' parmlist ')' '}'
1760 { error ("missing ';' before right brace");
1761 yyungetc ('}', 0);
1762 $$ = groktypefield ($1, $3); }
1763 | typed_declspecs LEFT_RIGHT ';'
1764 { $$ = groktypefield ($1, empty_parms ()); }
1765 | typed_declspecs LEFT_RIGHT '}'
1766 { error ("missing ';' before right brace");
1767 yyungetc ('}', 0);
1768 $$ = groktypefield ($1, empty_parms ()); }
1769 | declmods components ';'
1770 { goto do_components; }
1771 /* Normal case: make this fast. */
1772 | declmods declarator ';'
1773 { $$ = grokfield ($2, $1, 0, 0, 0, 0); }
1774 | declmods components '}'
1775 { error ("missing ';' before right brace");
1776 yyungetc ('}', 0);
1777 goto do_components; }
1778 | declmods '(' parmlist ')' ';'
1779 { $$ = groktypefield ($1, $3); }
1780 | declmods '(' parmlist ')' '}'
1781 { error ("missing ';' before right brace");
1782 yyungetc ('}', 0);
1783 $$ = groktypefield ($1, $3); }
1784 | declmods LEFT_RIGHT ';'
1785 { $$ = groktypefield ($1, empty_parms ()); }
1786 | declmods LEFT_RIGHT '}'
1787 { error ("missing ';' before right brace");
1788 yyungetc ('}', 0);
1789 $$ = groktypefield ($1, empty_parms ()); }
1790 | ':' expr_no_commas ';'
1791 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
1792 | ':' expr_no_commas '}'
1793 { error ("missing ';' before right brace");
1794 yyungetc ('}', 0);
1795 $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
1796 | error
1797 { $$ = NULL_TREE; }
1799 /* C++: handle constructors, destructors and inline functions */
1800 /* note that INLINE is like a TYPESPEC */
1801 | fn.def2 ':' /* base_init compstmt */
1802 { $$ = finish_method ($1); }
1803 | fn.def2 '{' /* nodecls compstmt */
1804 { $$ = finish_method ($1); }
1805 | dummy_decl notype_declarator maybe_raises ';'
1806 { $$ = grokfield ($2, NULL_TREE, $3, NULL_TREE, NULL_TREE); }
1807 | dummy_decl notype_declarator maybe_raises '}'
1808 { error ("missing ';' before right brace");
1809 yyungetc ('}', 0);
1810 $$ = grokfield ($2, NULL_TREE, $3, NULL_TREE, NULL_TREE); }
1813 components:
1814 /* empty: possibly anonymous */
1815 { $$ = NULL_TREE; }
1816 | component_declarator0
1817 | components ',' component_declarator
1819 /* In this context, void_type_node encodes
1820 friends. They have been recorded elsewhere. */
1821 if ($1 == void_type_node)
1822 $$ = $3;
1823 else
1824 $$ = chainon ($1, $3);
1828 component_declarator0:
1829 declarator maybe_raises maybeasm opt.init
1830 { current_declspecs = $<ttype>0;
1831 $$ = grokfield ($1, current_declspecs, $2, $4, $3); }
1832 | IDENTIFIER ':' expr_no_commas
1833 { current_declspecs = $<ttype>0;
1834 $$ = grokbitfield ($1, current_declspecs, $3); }
1835 | TYPENAME_COLON expr_no_commas
1836 { current_declspecs = $<ttype>0;
1837 $$ = grokbitfield ($1, current_declspecs, $2); }
1838 | ':' expr_no_commas
1839 { current_declspecs = $<ttype>0;
1840 $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
1843 component_declarator:
1844 declarator maybe_raises maybeasm opt.init
1845 { $$ = grokfield ($1, current_declspecs, $2, $4, $3); }
1846 | IDENTIFIER ':' expr_no_commas
1847 { $$ = grokbitfield ($1, current_declspecs, $3); }
1848 | TYPENAME_COLON expr_no_commas
1849 { $$ = grokbitfield ($1, current_declspecs, $2); }
1850 | ':' expr_no_commas
1851 { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
1854 /* We chain the enumerators in reverse order.
1855 Because of the way enums are built, the order is
1856 insignificant. Take advantage of this fact. */
1858 enumlist:
1859 enumerator
1860 | enumlist ',' enumerator
1861 { TREE_CHAIN ($3) = $1; $$ = $3; }
1864 enumerator:
1865 identifier
1866 { $$ = build_enumerator ($1, NULL_TREE); }
1867 | identifier '=' expr_no_commas
1868 { $$ = build_enumerator ($1, $3); }
1871 typename:
1872 typed_typespecs absdcl
1873 { $$ = build_decl_list ($1, $2); }
1874 | nonempty_type_quals absdcl
1875 { $$ = build_decl_list ($1, $2); }
1878 absdcl: /* an abstract declarator */
1879 /* empty */ %prec EMPTY
1880 { $$ = NULL_TREE; }
1881 | absdcl1 %prec EMPTY
1884 nonempty_type_quals:
1885 dummy_decl TYPE_QUAL
1886 { $$ = IDENTIFIER_AS_LIST ($2); }
1887 | nonempty_type_quals TYPE_QUAL
1888 { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
1891 type_quals:
1892 /* empty */
1893 { $$ = NULL_TREE; }
1894 | type_quals TYPE_QUAL
1895 { $$ = decl_tree_cons (NULL_TREE, $2, $1); }
1898 /* These rules must follow the rules for function declarations
1899 and component declarations. That way, longer rules are prefered. */
1901 /* An expression which will not live on the momentary obstack. */
1902 nonmomentary_expr:
1903 { $<itype>$ = suspend_momentary (); } expr
1904 { resume_momentary ($<itype>1); $$ = $2; }
1906 /* A declarator that is allowed only after an explicit typespec. */
1907 /* may all be followed by prec '.' */
1908 after_type_declarator:
1909 after_type_declarator '(' nonnull_exprlist ')' type_quals %prec '.'
1910 { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
1911 | after_type_declarator '(' parmlist ')' type_quals %prec '.'
1912 { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
1913 | after_type_declarator LEFT_RIGHT type_quals %prec '.'
1914 { $$ = build_parse_node (CALL_EXPR, $1, empty_parms (), $3); }
1915 | after_type_declarator '(' error ')' type_quals %prec '.'
1916 { $$ = build_parse_node (CALL_EXPR, $1, NULL_TREE, NULL_TREE); }
1917 | after_type_declarator '[' nonmomentary_expr ']'
1918 { $$ = build_parse_node (ARRAY_REF, $1, $3); }
1919 | after_type_declarator '[' ']'
1920 { $$ = build_parse_node (ARRAY_REF, $1, NULL_TREE); }
1921 | '(' dummy_decl after_type_declarator_no_typename ')'
1922 { $$ = $3; }
1923 | '(' '*' type_quals after_type_declarator ')'
1924 { $$ = make_pointer_declarator ($3, $4); }
1925 | PAREN_STAR_PAREN
1926 { $$ = $1;
1927 see_typename (); }
1928 | PAREN_X_SCOPE_STAR_PAREN
1929 { $$ = $1;
1930 see_typename (); }
1931 | PAREN_X_SCOPE_REF_PAREN
1932 { $$ = $1;
1933 see_typename (); }
1934 | '(' '&' type_quals after_type_declarator ')'
1935 { $$ = make_reference_declarator ($3, $4); }
1936 | '*' type_quals after_type_declarator %prec UNARY
1937 { $$ = make_pointer_declarator ($2, $3); }
1938 | '&' type_quals after_type_declarator %prec UNARY
1939 { $$ = make_reference_declarator ($2, $3); }
1940 | TYPENAME
1943 after_type_declarator_no_typename:
1944 after_type_declarator_no_typename '(' nonnull_exprlist ')' type_quals %prec '.'
1945 { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
1946 | after_type_declarator_no_typename '(' parmlist ')' type_quals %prec '.'
1947 { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
1948 | after_type_declarator_no_typename LEFT_RIGHT type_quals %prec '.'
1949 { $$ = build_parse_node (CALL_EXPR, $1, empty_parms (), $3); }
1950 | after_type_declarator_no_typename '(' error ')' type_quals %prec '.'
1951 { $$ = build_parse_node (CALL_EXPR, $1, NULL_TREE, NULL_TREE); }
1952 | after_type_declarator_no_typename '[' nonmomentary_expr ']'
1953 { $$ = build_parse_node (ARRAY_REF, $1, $3); }
1954 | after_type_declarator_no_typename '[' ']'
1955 { $$ = build_parse_node (ARRAY_REF, $1, NULL_TREE); }
1956 | '(' dummy_decl after_type_declarator_no_typename ')'
1957 { $$ = $3; }
1958 | PAREN_STAR_PAREN
1959 { $$ = $1;
1960 see_typename (); }
1961 | PAREN_X_SCOPE_STAR_PAREN
1962 { $$ = $1;
1963 see_typename (); }
1964 | PAREN_X_SCOPE_REF_PAREN
1965 { $$ = $1;
1966 see_typename (); }
1967 | '*' type_quals after_type_declarator %prec UNARY
1968 { $$ = make_pointer_declarator ($2, $3); }
1969 | '&' type_quals after_type_declarator %prec UNARY
1970 { $$ = make_reference_declarator ($2, $3); }
1973 /* A declarator allowed whether or not there has been
1974 an explicit typespec. These cannot redeclare a typedef-name. */
1976 notype_declarator:
1977 notype_declarator '(' nonnull_exprlist ')' type_quals %prec '.'
1978 { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
1979 | notype_declarator '(' parmlist ')' type_quals %prec '.'
1980 { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
1981 | notype_declarator LEFT_RIGHT type_quals %prec '.'
1982 { $$ = build_parse_node (CALL_EXPR, $1, empty_parms (), $3); }
1983 | notype_declarator '(' error ')' type_quals %prec '.'
1984 { $$ = build_parse_node (CALL_EXPR, $1, NULL_TREE, NULL_TREE); }
1985 | '(' notype_declarator ')'
1986 { $$ = $2; }
1987 | '*' type_quals notype_declarator %prec UNARY
1988 { $$ = make_pointer_declarator ($2, $3); }
1989 | '&' type_quals notype_declarator %prec UNARY
1990 { $$ = make_reference_declarator ($2, $3); }
1991 | notype_declarator '[' nonmomentary_expr ']'
1992 { $$ = build_parse_node (ARRAY_REF, $1, $3); }
1993 | notype_declarator '[' ']'
1994 { $$ = build_parse_node (ARRAY_REF, $1, NULL_TREE); }
1995 | IDENTIFIER
1996 { see_typename (); }
1998 /* C++ extensions. */
1999 | operator_name
2000 { see_typename (); }
2002 | '~' TYPENAME
2003 { see_typename ();
2004 $$ = build_parse_node (BIT_NOT_EXPR, $2); }
2005 | '~' IDENTIFIER
2006 { see_typename ();
2007 $$ = build_parse_node (BIT_NOT_EXPR, $2); }
2008 | LEFT_RIGHT identifier
2010 see_typename ();
2011 $$ = build_parse_node (WRAPPER_EXPR, $2);
2013 | LEFT_RIGHT '?' identifier
2015 see_typename ();
2016 $$ = build_parse_node (WRAPPER_EXPR,
2017 build_parse_node (COND_EXPR, $3, NULL_TREE, NULL_TREE));
2019 | '~' LEFT_RIGHT identifier
2020 { see_typename ();
2021 $$ = build_parse_node (ANTI_WRAPPER_EXPR, $3); }
2022 | TYPENAME_SCOPE type_quals notype_declarator %prec '('
2023 { see_typename ();
2024 $$ = build_parse_node (SCOPE_REF, $1, $3); }
2025 | TYPENAME_SCOPE TYPENAME %prec '('
2026 { $$ = build_parse_node (SCOPE_REF, $1, $2); }
2027 | TYPENAME_SCOPE see_typename TYPENAME '(' nonnull_exprlist ')' type_quals %prec '.'
2028 { $$ = build_parse_node (SCOPE_REF, $1,
2029 build_parse_node (CALL_EXPR, $3, $5, $7)); }
2030 | TYPENAME_SCOPE see_typename TYPENAME '(' parmlist ')' type_quals %prec '.'
2031 { $$ = build_parse_node (SCOPE_REF, $1,
2032 build_parse_node (CALL_EXPR, $3, $5, $7)); }
2033 | TYPENAME_SCOPE see_typename TYPENAME LEFT_RIGHT type_quals %prec '.'
2034 { $$ = build_parse_node (SCOPE_REF, $1,
2035 build_parse_node (CALL_EXPR, $3, empty_parms (), $5)); }
2036 | TYPENAME_SCOPE see_typename TYPENAME '(' error ')' type_quals %prec '.'
2037 { $$ = build_parse_node (SCOPE_REF, $1, build_parse_node (CALL_EXPR, $3, NULL_TREE, NULL_TREE)); }
2038 | SCOPE see_typename notype_declarator
2039 { $$ = build_parse_node (SCOPE_REF, NULL_TREE, $3); }
2042 scoped_identifier:
2043 TYPENAME_SCOPE
2044 | IDENTIFIER SCOPE
2045 | scoped_identifier TYPENAME_SCOPE
2046 { $$ = build_parse_node (SCOPE_REF, $1, $2); }
2049 absdcl1: /* a nonempty abstract declarator */
2050 '(' absdcl1 ')'
2051 { see_typename ();
2052 $$ = $2; }
2053 /* `(typedef)1' is `int'. */
2054 | '*' type_quals absdcl1 %prec EMPTY
2055 { $$ = make_pointer_declarator ($2, $3); }
2056 | '*' type_quals %prec EMPTY
2057 { $$ = make_pointer_declarator ($2, NULL_TREE); }
2058 | PAREN_STAR_PAREN
2059 { $$ = $1;
2060 see_typename (); }
2061 | PAREN_X_SCOPE_STAR_PAREN
2062 { $$ = $1;
2063 see_typename (); }
2064 | PAREN_X_SCOPE_REF_PAREN
2065 { $$ = $1;
2066 see_typename (); }
2067 | '&' type_quals absdcl1 %prec EMPTY
2068 { $$ = make_reference_declarator ($2, $3); }
2069 | '&' type_quals %prec EMPTY
2070 { $$ = make_reference_declarator ($2, NULL_TREE); }
2071 | absdcl1 '(' parmlist ')' type_quals %prec '.'
2072 { $$ = build_parse_node (CALL_EXPR, $1, $3, $5); }
2073 | absdcl1 LEFT_RIGHT type_quals %prec '.'
2074 { $$ = build_parse_node (CALL_EXPR, $1, empty_parms (), $3); }
2075 | absdcl1 '[' nonmomentary_expr ']' %prec '.'
2076 { $$ = build_parse_node (ARRAY_REF, $1, $3); }
2077 | absdcl1 '[' ']' %prec '.'
2078 { $$ = build_parse_node (ARRAY_REF, $1, NULL_TREE); }
2079 | '(' parmlist ')' type_quals %prec '.'
2080 { $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2, $4); }
2081 | LEFT_RIGHT type_quals %prec '.'
2082 { $$ = build_parse_node (CALL_EXPR, NULL_TREE, empty_parms (), $2); }
2083 | '[' nonmomentary_expr ']' %prec '.'
2084 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
2085 | '[' ']' %prec '.'
2086 { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
2087 | TYPENAME_SCOPE type_quals absdcl1 %prec EMPTY
2088 { $$ = build_parse_node (SCOPE_REF, $1, $3); }
2089 | IDENTIFIER SCOPE type_quals absdcl1 %prec EMPTY
2090 { $$ = build_parse_node (SCOPE_REF, $1, $4); }
2091 | TYPENAME_SCOPE type_quals %prec EMPTY
2092 { $$ = build_parse_node (SCOPE_REF, $1, 0); }
2093 | IDENTIFIER SCOPE type_quals %prec EMPTY
2094 { $$ = build_parse_node (SCOPE_REF, $1, 0); }
2097 /* at least one statement, the first of which parses without error. */
2098 /* stmts is used only after decls, so an invalid first statement
2099 is actually regarded as an invalid decl and part of the decls. */
2101 stmts:
2102 stmt
2103 | stmts stmt
2104 | stmts errstmt
2107 errstmt: error ';'
2110 /* build the LET_STMT node before parsing its contents,
2111 so that any LET_STMTs within the context can have their display pointers
2112 set up to point at this one. */
2114 .pushlevel: /* empty */
2116 pushlevel (0);
2117 clear_last_expr ();
2118 push_momentary ();
2119 expand_start_bindings (0);
2120 stmt_decl_msg = 0;
2124 /* This is the body of a function definition.
2125 It causes syntax errors to ignore to the next openbrace. */
2126 compstmt_or_error:
2127 compstmt
2129 | error compstmt
2132 compstmt: '{' '}'
2133 { $$ = 0; }
2134 | '{' .pushlevel stmts '}'
2135 { tree decls;
2137 pop_implicit_try_blocks (NULL_TREE);
2138 decls = getdecls ();
2139 expand_end_bindings (decls, decls != 0, 1);
2140 $$ = poplevel (decls != 0, 1, 0);
2141 pop_momentary (); }
2142 | '{' .pushlevel error '}'
2143 { pop_implicit_try_blocks (NULL_TREE);
2144 expand_end_bindings (getdecls (), 0, 1);
2145 $$ = poplevel (0, 0, 0);
2146 pop_momentary (); }
2149 simple_if:
2150 IF '(' expr ')'
2151 { emit_line_note (input_filename, lineno);
2152 expand_start_cond (truthvalue_conversion ($3), 0);
2153 stmt_decl_msg = "if"; }
2154 stmt
2155 { stmt_decl_msg = 0; }
2158 stmt:
2159 compstmt
2160 { finish_stmt (); }
2161 | decl
2162 { if (stmt_decl_msg)
2163 error ("declaration after %s invalid", stmt_decl_msg);
2164 stmt_decl_msg = 0;
2165 finish_stmt (); }
2166 | expr ';'
2167 { emit_line_note (input_filename, lineno);
2168 /* Do default conversion if safe and possibly important,
2169 in case within ({...}). */
2170 if ((TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
2171 && lvalue_p ($1))
2172 || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
2173 $1 = default_conversion ($1);
2174 cplus_expand_expr_stmt ($1);
2175 clear_momentary ();
2176 finish_stmt (); }
2177 | simple_if ELSE
2178 { expand_start_else ();
2179 stmt_decl_msg = "else"; }
2180 stmt
2181 { expand_end_else ();
2182 stmt_decl_msg = 0;
2183 finish_stmt (); }
2184 | simple_if %prec IF
2185 { expand_end_cond ();
2186 stmt_decl_msg = 0;
2187 finish_stmt (); }
2188 | WHILE
2189 { emit_nop ();
2190 emit_line_note (input_filename, lineno);
2191 expand_start_loop (1); }
2192 '(' expr ')'
2193 { expand_exit_loop_if_false (truthvalue_conversion ($4));
2194 stmt_decl_msg = "while"; }
2195 stmt
2197 expand_end_loop ();
2198 stmt_decl_msg = 0;
2199 finish_stmt (); }
2200 | DO
2201 { emit_nop ();
2202 emit_line_note (input_filename, lineno);
2203 expand_start_loop_continue_elsewhere (1);
2204 stmt_decl_msg = "do"; }
2205 stmt WHILE
2206 { stmt_decl_msg = 0;
2207 expand_loop_continue_here (); }
2208 '(' expr ')' ';'
2209 { emit_line_note (input_filename, lineno);
2210 expand_exit_loop_if_false (truthvalue_conversion ($7));
2211 expand_end_loop ();
2212 clear_momentary ();
2213 finish_stmt (); }
2214 | forhead.1
2215 { emit_nop ();
2216 emit_line_note (input_filename, lineno);
2217 if ($1) cplus_expand_expr_stmt ($1);
2218 expand_start_loop_continue_elsewhere (1); }
2219 xexpr ';'
2220 { emit_line_note (input_filename, lineno);
2221 if ($3) expand_exit_loop_if_false (truthvalue_conversion ($3)); }
2222 xexpr ')'
2223 /* Don't let the tree nodes for $6 be discarded
2224 by clear_momentary during the parsing of the next stmt. */
2225 { push_momentary ();
2226 stmt_decl_msg = "for"; }
2227 stmt
2228 { emit_line_note (input_filename, lineno);
2229 expand_loop_continue_here ();
2230 if ($6) cplus_expand_expr_stmt ($6);
2231 pop_momentary ();
2232 expand_end_loop ();
2233 stmt_decl_msg = 0;
2234 finish_stmt (); }
2235 | forhead.2
2236 { emit_nop ();
2237 emit_line_note (input_filename, lineno);
2238 expand_start_loop_continue_elsewhere (1); }
2239 xexpr ';'
2240 { emit_line_note (input_filename, lineno);
2241 if ($3) expand_exit_loop_if_false (truthvalue_conversion ($3)); }
2242 xexpr ')'
2243 /* Don't let the tree nodes for $6 be discarded
2244 by clear_momentary during the parsing of the next stmt. */
2245 { push_momentary ();
2246 stmt_decl_msg = "for";
2247 $<itype>7 = lineno; }
2248 stmt
2249 { emit_line_note (input_filename, $<itype>7);
2250 expand_loop_continue_here ();
2251 if ($6) cplus_expand_expr_stmt ($6);
2252 pop_momentary ();
2253 expand_end_loop ();
2254 pop_implicit_try_blocks (NULL_TREE);
2255 if ($1)
2257 register keep = $1 > 0;
2258 if (keep) expand_end_bindings (0, keep, 1);
2259 poplevel (keep, 1, 0);
2260 pop_momentary ();
2262 stmt_decl_msg = 0;
2263 finish_stmt ();
2265 | SWITCH '(' expr ')'
2266 { emit_line_note (input_filename, lineno);
2267 c_expand_start_case ($3);
2268 /* Don't let the tree nodes for $3 be discarded by
2269 clear_momentary during the parsing of the next stmt. */
2270 push_momentary ();
2271 stmt_decl_msg = "switch"; }
2272 stmt
2273 { expand_end_case ($3);
2274 pop_momentary ();
2275 stmt_decl_msg = 0;
2276 finish_stmt (); }
2277 | CASE expr ':'
2278 { register tree value = $2;
2279 register tree label
2280 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2282 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
2283 Strip such NOP_EXPRs. */
2284 if (TREE_CODE (value) == NOP_EXPR
2285 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
2286 value = TREE_OPERAND (value, 0);
2288 if (TREE_READONLY_DECL_P (value))
2290 value = decl_constant_value (value);
2291 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
2292 Strip such NOP_EXPRs. */
2293 if (TREE_CODE (value) == NOP_EXPR
2294 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
2295 value = TREE_OPERAND (value, 0);
2297 value = fold (value);
2299 if (TREE_CODE (value) != INTEGER_CST
2300 && value != error_mark_node)
2302 error ("case label does not reduce to an integer constant");
2303 value = error_mark_node;
2305 else
2306 /* Promote char or short to int. */
2307 value = default_conversion (value);
2308 if (value != error_mark_node)
2310 int success = pushcase (value, label);
2311 if (success == 1)
2312 error ("case label not within a switch statement");
2313 else if (success == 2)
2314 error ("duplicate case value");
2315 else if (success == 3)
2316 warning ("case value out of range");
2318 define_case_label (label);
2320 stmt
2321 | CASE expr RANGE expr ':'
2322 { register tree value1 = $2;
2323 register tree value2 = $4;
2324 register tree label
2325 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2327 if (pedantic)
2329 error ("ANSI C does not allow range expressions in switch statement");
2330 value1 = error_mark_node;
2331 value2 = error_mark_node;
2332 break;
2334 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
2335 Strip such NOP_EXPRs. */
2336 if (TREE_CODE (value1) == NOP_EXPR
2337 && TREE_TYPE (value1) == TREE_TYPE (TREE_OPERAND (value1, 0)))
2338 value1 = TREE_OPERAND (value1, 0);
2340 if (TREE_READONLY_DECL_P (value1))
2342 value1 = decl_constant_value (value1);
2343 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
2344 Strip such NOP_EXPRs. */
2345 if (TREE_CODE (value1) == NOP_EXPR
2346 && TREE_TYPE (value1) == TREE_TYPE (TREE_OPERAND (value1, 0)))
2347 value1 = TREE_OPERAND (value1, 0);
2349 value1 = fold (value1);
2351 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
2352 Strip such NOP_EXPRs. */
2353 if (TREE_CODE (value2) == NOP_EXPR
2354 && TREE_TYPE (value2) == TREE_TYPE (TREE_OPERAND (value2, 0)))
2355 value2 = TREE_OPERAND (value2, 0);
2357 if (TREE_READONLY_DECL_P (value2))
2359 value2 = decl_constant_value (value2);
2360 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
2361 Strip such NOP_EXPRs. */
2362 if (TREE_CODE (value2) == NOP_EXPR
2363 && TREE_TYPE (value2) == TREE_TYPE (TREE_OPERAND (value2, 0)))
2364 value2 = TREE_OPERAND (value2, 0);
2366 value2 = fold (value2);
2369 if (TREE_CODE (value1) != INTEGER_CST
2370 && value1 != error_mark_node)
2372 error ("case label does not reduce to an integer constant");
2373 value1 = error_mark_node;
2375 if (TREE_CODE (value2) != INTEGER_CST
2376 && value2 != error_mark_node)
2378 error ("case label does not reduce to an integer constant");
2379 value2 = error_mark_node;
2381 if (value1 != error_mark_node
2382 && value2 != error_mark_node)
2384 int success = pushcase_range (value1, value2, label);
2385 if (success == 1)
2386 error ("case label not within a switch statement");
2387 else if (success == 2)
2388 error ("duplicate (or overlapping) case value");
2389 else if (success == 3)
2390 warning ("case value out of range");
2391 else if (success == 4)
2392 warning ("empty range specified");
2394 define_case_label (label);
2396 stmt
2397 | DEFAULT ':'
2399 register tree label
2400 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2401 int success = pushcase (NULL_TREE, label);
2402 if (success == 1)
2403 error ("default label not within a switch statement");
2404 else if (success == 2)
2405 error ("multiple default labels in one switch");
2407 stmt
2408 | BREAK ';'
2409 { emit_line_note (input_filename, lineno);
2410 if ( ! expand_exit_something ())
2411 error ("break statement not within loop or switch"); }
2412 | CONTINUE ';'
2413 { emit_line_note (input_filename, lineno);
2414 if (! expand_continue_loop ())
2415 error ("continue statement not within a loop"); }
2416 | RETURN ';'
2417 { emit_line_note (input_filename, lineno);
2418 c_expand_return (NULL_TREE); }
2419 | RETURN expr ';'
2420 { emit_line_note (input_filename, lineno);
2421 c_expand_return ($2);
2422 finish_stmt ();
2424 | ASM maybe_type_qual '(' string ')' ';'
2425 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
2426 emit_line_note (input_filename, lineno);
2427 expand_asm ($4);
2428 finish_stmt ();
2430 /* This is the case with just output operands. */
2431 | ASM maybe_type_qual '(' string ':' asm_operands ')' ';'
2432 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
2433 emit_line_note (input_filename, lineno);
2434 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
2435 $2 == ridpointers[(int)RID_VOLATILE],
2436 input_filename, lineno);
2437 finish_stmt ();
2439 /* This is the case with input operands as well. */
2440 | ASM maybe_type_qual '(' string ':' asm_operands ':' asm_operands ')' ';'
2441 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
2442 emit_line_note (input_filename, lineno);
2443 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
2444 $2 == ridpointers[(int)RID_VOLATILE],
2445 input_filename, lineno);
2446 finish_stmt ();
2448 /* This is the case with clobbered registers as well. */
2449 | ASM maybe_type_qual '(' string ':' asm_operands ':'
2450 asm_operands ':' asm_clobbers ')' ';'
2451 { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
2452 emit_line_note (input_filename, lineno);
2453 c_expand_asm_operands ($4, $6, $8, $10,
2454 $2 == ridpointers[(int)RID_VOLATILE],
2455 input_filename, lineno);
2456 finish_stmt ();
2458 | GOTO identifier ';'
2459 { tree decl;
2460 emit_line_note (input_filename, lineno);
2461 decl = lookup_label ($2);
2462 TREE_USED (decl) = 1;
2463 expand_goto (decl); }
2464 | IDENTIFIER ':'
2465 { tree label = define_label (input_filename, lineno, $1);
2466 emit_nop ();
2467 if (label)
2468 expand_label (label); }
2469 stmt
2470 { finish_stmt (); }
2471 | TYPENAME_COLON
2472 { tree label = define_label (input_filename, lineno, $1);
2473 if (label)
2474 expand_label (label); }
2475 stmt
2476 { finish_stmt (); }
2477 | ';'
2478 { finish_stmt (); }
2480 /* Exception handling extentions. */
2481 | RAISE raise_identifier '(' nonnull_exprlist ')' ';'
2482 { cplus_expand_raise ($2, $4, NULL_TREE);
2483 finish_stmt (); }
2484 | RAISE raise_identifier LEFT_RIGHT ';'
2485 { cplus_expand_raise ($2, NULL_TREE, NULL_TREE);
2486 finish_stmt (); }
2487 | RAISE identifier ';'
2488 { cplus_expand_reraise ($2);
2489 finish_stmt (); }
2490 | try EXCEPT identifier '{'
2492 tree decl = cplus_expand_end_try ($1);
2493 $<ttype>2 = current_exception_type;
2494 $<ttype>4 = current_exception_decl;
2495 $<ttype>$ = current_exception_object;
2496 cplus_expand_start_except ($3, decl);
2497 pushlevel (0);
2498 clear_last_expr ();
2499 push_momentary ();
2500 expand_start_bindings (0);
2501 stmt_decl_msg = 0;
2503 except_stmts '}'
2505 tree decls = getdecls ();
2506 tree block;
2507 /* If there is a default exception to handle,
2508 handle it here. */
2509 if ($6)
2511 tree decl = build_decl (CPLUS_CATCH_DECL, NULL_TREE, 0);
2513 pushlevel (1);
2514 expand_start_bindings (0);
2515 expand_expr ($6, 0, 0, 0);
2516 expand_end_bindings (0, 1, 0);
2517 block = poplevel (1, 0, 0);
2519 /* This is a catch block. */
2520 TREE_LANG_FLAG_2 (block) = 1;
2521 STMT_VARS (block) = decl;
2524 expand_end_bindings (decls, 1, 1);
2525 block = poplevel (1, 1, 0);
2526 TREE_LANG_FLAG_3 (block) = 1;
2527 pop_momentary ();
2528 current_exception_type = $<ttype>2;
2529 current_exception_decl = $<ttype>4;
2530 current_exception_object = $<ttype>5;
2531 cplus_expand_end_except ($6);
2533 | try RERAISE raise_identifiers /* ';' checked for at bottom. */
2534 { tree name = get_identifier ("(compiler error)");
2535 tree orig_ex_type = current_exception_type;
2536 tree orig_ex_decl = current_exception_decl;
2537 tree orig_ex_obj = current_exception_object;
2538 tree decl = cplus_expand_end_try ($1), decls;
2539 tree block;
2541 /* Start hidden EXCEPT. */
2542 cplus_expand_start_except (name, decl);
2543 pushlevel (0);
2544 clear_last_expr ();
2545 push_momentary ();
2546 expand_start_bindings (0);
2547 stmt_decl_msg = 0;
2549 /* This sets up the reraise. */
2550 cplus_expand_reraise ($3);
2552 decls = getdecls ();
2553 expand_end_bindings (decls, 1, 1);
2554 block = poplevel (1, 1, 0);
2555 TREE_LANG_FLAG_3 (block) = 1;
2556 pop_momentary ();
2557 current_exception_type = orig_ex_type;
2558 current_exception_decl = orig_ex_decl;
2559 current_exception_object = orig_ex_obj;
2560 /* This will reraise for us. */
2561 cplus_expand_end_except (error_mark_node);
2562 if (yychar == YYEMPTY)
2563 yychar = YYLEX;
2564 if (yychar != ';')
2565 error ("missing ';' after reraise statement");
2567 | try %prec EMPTY
2568 { yyerror ("`except' missing after `try' statement");
2569 /* Terminate the binding contour started by special
2570 code in `.pushlevel'. Automagically pops off
2571 the conditional we started for `try' stmt. */
2572 cplus_expand_end_try ($1);
2573 expand_end_bindings (0, 0, 1);
2574 poplevel (0, 0, 0);
2575 pop_momentary ();
2576 YYERROR; }
2579 try: TRY '{' '}'
2580 { $$ = 0; }
2581 | try_head stmts '}'
2583 $$ = 1;
2584 pop_implicit_try_blocks (NULL_TREE);
2586 | try_head error '}'
2588 $$ = 0;
2589 pop_implicit_try_blocks (NULL_TREE);
2593 try_head: TRY '{' { cplus_expand_start_try (0); } .pushlevel
2595 except_stmts:
2596 /* empty */
2597 { $$ = NULL_TREE; }
2598 | except_stmts raise_identifier
2600 tree type = lookup_exception_type (current_class_type, current_class_name, $2);
2601 if (type == NULL_TREE)
2603 error ("`%s' is not an exception type",
2604 IDENTIFIER_POINTER (TREE_VALUE ($2)));
2605 current_exception_type = NULL_TREE;
2606 TREE_TYPE (current_exception_object) = error_mark_node;
2608 else
2610 current_exception_type = type;
2611 /* In-place union. */
2612 TREE_TYPE (current_exception_object) = type;
2614 $2 = cplus_expand_start_catch ($2);
2615 pushlevel (1);
2616 expand_start_bindings (0);
2618 compstmt
2620 expand_end_bindings (0, 1, 0);
2621 $4 = poplevel (1, 0, 0);
2623 cplus_expand_end_catch (0);
2625 /* Mark this as a catch block. */
2626 TREE_LANG_FLAG_2 ($4) = 1;
2627 if ($2 != error_mark_node)
2629 tree decl = build_decl (CPLUS_CATCH_DECL, DECL_NAME ($2), 0);
2630 DECL_RTL (decl) = DECL_RTL ($2);
2631 TREE_CHAIN (decl) = STMT_VARS ($4);
2632 STMT_VARS ($4) = decl;
2635 | except_stmts DEFAULT
2637 if ($1)
2638 error ("duplicate default in exception handler");
2639 current_exception_type = NULL_TREE;
2640 /* Takes it right out of scope. */
2641 TREE_TYPE (current_exception_object) = error_mark_node;
2643 if (! expand_catch_default ())
2644 compiler_error ("default catch botch");
2646 /* The default exception is handled as the
2647 last in the chain of exceptions handled. */
2648 do_pending_stack_adjust ();
2649 start_sequence ();
2650 $1 = make_node (RTL_EXPR);
2651 TREE_TYPE ($1) = void_type_node;
2653 compstmt
2655 do_pending_stack_adjust ();
2656 if (! expand_catch (NULL_TREE))
2657 compiler_error ("except nesting botch");
2658 if (! expand_end_catch ())
2659 compiler_error ("except nesting botch");
2660 RTL_EXPR_SEQUENCE ($1) = (struct rtx_def *)get_insns ();
2661 if ($4)
2663 /* Mark this block as the default catch block. */
2664 TREE_LANG_FLAG_1 ($4) = 1;
2665 TREE_LANG_FLAG_2 ($4) = 1;
2667 end_sequence ();
2671 forhead.1:
2672 FOR '(' ';'
2673 { $$ = NULL_TREE; }
2674 | FOR '(' expr ';'
2675 { $$ = $3; }
2676 | FOR '(' '{' '}'
2677 { $$ = NULL_TREE; }
2680 forhead.2:
2681 FOR '(' decl
2682 { $$ = 0; }
2683 | FOR '(' error ';'
2684 { $$ = 0; }
2685 | FOR '(' '{' .pushlevel stmts '}'
2686 { $$ = 1; }
2687 | FOR '(' '{' .pushlevel error '}'
2688 { $$ = -1; }
2691 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
2693 maybe_type_qual:
2694 /* empty */
2695 { if (pedantic)
2696 warning ("ANSI C forbids use of `asm' keyword");
2697 emit_line_note (input_filename, lineno); }
2698 | TYPE_QUAL
2699 { if (pedantic)
2700 warning ("ANSI C forbids use of `asm' keyword");
2701 emit_line_note (input_filename, lineno); }
2704 xexpr:
2705 /* empty */
2706 { $$ = NULL_TREE; }
2707 | expr
2708 | error
2709 { $$ = NULL_TREE; }
2712 /* These are the operands other than the first string and colon
2713 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
2714 asm_operands: /* empty */
2715 { $$ = NULL_TREE; }
2716 | nonnull_asm_operands
2719 nonnull_asm_operands:
2720 asm_operand
2721 | nonnull_asm_operands ',' asm_operand
2722 { $$ = chainon ($1, $3); }
2725 asm_operand:
2726 STRING '(' expr ')'
2727 { $$ = build_tree_list ($1, $3); }
2730 asm_clobbers:
2731 STRING
2732 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
2733 | asm_clobbers ',' STRING
2734 { $$ = tree_cons (NULL_TREE, $3, $1); }
2737 /* This is what appears inside the parens in a function declarator.
2738 Its value is represented in the format that grokdeclarator expects.
2740 In C++, declaring a function with no parameters
2741 means that that function takes *no* parameters. */
2742 parmlist: /* empty */
2744 if (strict_prototype)
2745 $$ = void_list_node;
2746 else
2747 $$ = NULL_TREE;
2749 | parms
2751 $$ = chainon ($1, void_list_node);
2752 TREE_PARMLIST ($$) = 1;
2754 | parms ',' ELLIPSIS
2756 $$ = $1;
2757 TREE_PARMLIST ($$) = 1;
2759 /* C++ allows an ellipsis without a separating ',' */
2760 | parms ELLIPSIS
2762 $$ = $1;
2763 TREE_PARMLIST ($$) = 1;
2765 | ELLIPSIS
2767 $$ = NULL_TREE;
2769 | TYPENAME_ELLIPSIS
2771 $$ = $1;
2772 TREE_PARMLIST ($$) = 1;
2774 | parms TYPENAME_ELLIPSIS
2776 $$ = $1;
2777 TREE_PARMLIST ($$) = 1;
2779 | parms ':'
2781 /* This helps us recover from really nasty
2782 parse errors, for example, a missing right
2783 parenthesis. */
2784 yyerror ("possibly missing ')'");
2785 $$ = chainon ($1, void_list_node);
2786 TREE_PARMLIST ($$) = 1;
2787 yyungetc (':', 0);
2788 yychar = ')';
2792 /* A nonempty list of parameter declarations or type names. */
2793 parms:
2794 parm opt.init
2795 { $$ = build_tree_list ($2, $1); }
2796 | parms ',' parm opt.init
2797 { $$ = chainon ($1, build_tree_list ($4, $3)); }
2798 | parms ',' bad_parm opt.init
2799 { $$ = chainon ($1, build_tree_list ($4, $3)); }
2802 /* A single parameter declaration or parameter type name,
2803 as found in a parmlist. */
2804 parm:
2805 typed_declspecs dont_see_typename notype_declarator
2806 { $$ = build_tree_list ($1, $3);
2807 see_typename (); }
2808 | typed_declspecs dont_see_typename absdcl
2809 { $$ = build_tree_list ($1, $3);
2810 see_typename (); }
2811 | declmods dont_see_typename notype_declarator
2812 { $$ = build_tree_list ($1, $3);
2813 see_typename (); }
2814 | declmods dont_see_typename absdcl
2815 { $$ = build_tree_list ($1, $3);
2816 see_typename (); }
2819 see_typename: type_quals
2820 { see_typename (); }
2823 dont_see_typename: /* empty */
2824 { dont_see_typename (); }
2827 bad_parm:
2828 dummy_decl notype_declarator
2830 warning ("type specifier omitted for parameter");
2831 $$ = build_tree_list (TREE_PURPOSE (TREE_VALUE ($<ttype>-1)), $2);
2833 | dummy_decl absdcl
2835 warning ("type specifier omitted for parameter");
2836 $$ = build_tree_list (TREE_PURPOSE (TREE_VALUE ($<ttype>-1)), $2);
2840 /* C++ extension: allow for initialization */
2841 opt.init:
2842 /* empty */
2843 { $$ = NULL_TREE; }
2844 | '=' init
2845 { $$ = $2; }
2848 maybe_raises:
2849 /* empty */
2850 { $$ = NULL_TREE; }
2851 | RAISES raise_identifiers %prec EMPTY
2852 { $$ = $2; }
2855 raise_identifier:
2857 { $$ = void_list_node; }
2858 | IDENTIFIER
2859 { $$ = build_decl_list (NULL_TREE, $1); }
2860 | TYPENAME
2861 { $$ = build_decl_list (NULL_TREE, $1); }
2862 | SCOPE IDENTIFIER
2863 { $$ = build_decl_list (void_type_node, $2); }
2864 | SCOPE TYPENAME
2865 { $$ = build_decl_list (void_type_node, $2); }
2866 | scoped_identifier IDENTIFIER
2867 { $$ = build_decl_list ($1, $2); }
2868 | scoped_identifier TYPENAME
2869 { $$ = build_decl_list ($1, $2); }
2871 raise_identifiers:
2872 raise_identifier
2873 | raise_identifiers ',' raise_identifier
2875 TREE_CHAIN ($3) = $1;
2876 $$ = $3;
2880 operator_name:
2881 OPERATOR '*'
2882 { $$ = build_opid (0, MULT_EXPR); }
2883 | OPERATOR '/'
2884 { $$ = build_opid (0, TRUNC_DIV_EXPR); }
2885 | OPERATOR '%'
2886 { $$ = build_opid (0, TRUNC_MOD_EXPR); }
2887 | OPERATOR '+'
2888 { $$ = build_opid (0, PLUS_EXPR); }
2889 | OPERATOR '-'
2890 { $$ = build_opid (0, MINUS_EXPR); }
2891 | OPERATOR '&'
2892 { $$ = build_opid (0, BIT_AND_EXPR); }
2893 | OPERATOR '|'
2894 { $$ = build_opid (0, BIT_IOR_EXPR); }
2895 | OPERATOR '^'
2896 { $$ = build_opid (0, BIT_XOR_EXPR); }
2897 | OPERATOR '~'
2898 { $$ = build_opid (0, BIT_NOT_EXPR); }
2899 | OPERATOR ','
2900 { $$ = build_opid (0, COMPOUND_EXPR); }
2901 | OPERATOR ARITHCOMPARE
2902 { $$ = build_opid (0, $2); }
2903 | OPERATOR EQCOMPARE
2904 { $$ = build_opid (0, $2); }
2905 | OPERATOR ASSIGN
2906 { $$ = build_opid (MODIFY_EXPR, $2); }
2907 | OPERATOR '='
2909 $$ = build_opid (MODIFY_EXPR, NOP_EXPR);
2910 if (current_class_type)
2912 TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
2913 TYPE_GETS_ASSIGNMENT (current_class_type) = 1;
2916 | OPERATOR LSHIFT
2917 { $$ = build_opid (0, $2); }
2918 | OPERATOR RSHIFT
2919 { $$ = build_opid (0, $2); }
2920 | OPERATOR PLUSPLUS
2921 { $$ = build_opid (0, POSTINCREMENT_EXPR); }
2922 | OPERATOR MINUSMINUS
2923 { $$ = build_opid (0, PREDECREMENT_EXPR); }
2924 | OPERATOR ANDAND
2925 { $$ = build_opid (0, TRUTH_ANDIF_EXPR); }
2926 | OPERATOR OROR
2927 { $$ = build_opid (0, TRUTH_ORIF_EXPR); }
2928 | OPERATOR '!'
2929 { $$ = build_opid (0, TRUTH_NOT_EXPR); }
2930 | OPERATOR '?' ':'
2931 { $$ = build_opid (0, COND_EXPR); }
2932 | OPERATOR MIN_MAX
2933 { $$ = build_opid (0, $2); }
2934 | OPERATOR POINTSAT %prec EMPTY
2935 { $$ = build_opid (0, COMPONENT_REF); }
2936 | OPERATOR POINTSAT_LEFT_RIGHT type_quals %prec '.'
2938 if (yychar == YYEMPTY)
2939 yychar = YYLEX;
2940 if (yychar == '(' || yychar == LEFT_RIGHT)
2942 $$ = build_opid (0, METHOD_CALL_EXPR);
2943 if (current_class_type)
2945 tree t = current_class_type;
2946 while (t)
2948 TYPE_OVERLOADS_METHOD_CALL_EXPR (t) = 1;
2949 t = TYPE_NEXT_VARIANT (t);
2953 else
2954 $$ = build_parse_node (CALL_EXPR, build_opid (0, COMPONENT_REF), void_list_node, $3);
2956 | OPERATOR LEFT_RIGHT
2957 { $$ = build_opid (0, CALL_EXPR);
2958 if (current_class_type)
2960 tree t = current_class_type;
2961 while (t)
2963 TYPE_OVERLOADS_CALL_EXPR (t) = 1;
2964 t = TYPE_NEXT_VARIANT (t);
2968 | OPERATOR '[' ']'
2969 { $$ = build_opid (0, ARRAY_REF);
2970 if (current_class_type)
2972 tree t = current_class_type;
2973 while (t)
2975 TYPE_OVERLOADS_ARRAY_REF (t) = 1;
2976 t = TYPE_NEXT_VARIANT (t);
2980 | OPERATOR NEW
2982 $$ = build_opid (0, NEW_EXPR);
2983 if (current_class_type)
2985 tree t = current_class_type;
2986 while (t)
2988 TREE_GETS_NEW (t) = 1;
2989 t = TYPE_NEXT_VARIANT (t);
2993 | OPERATOR DELETE
2995 $$ = build_opid (0, DELETE_EXPR);
2996 if (current_class_type)
2998 tree t = current_class_type;
2999 while (t)
3001 TREE_GETS_DELETE (t) = 1;
3002 t = TYPE_NEXT_VARIANT (t);
3007 /* These should do `groktypename' and set up TREE_HAS_X_CONVERSION
3008 here, rather than doing it in class.c . */
3009 | OPERATOR typed_typespecs absdcl
3011 $$ = build1 (TYPE_EXPR, $2, $3);
3013 | OPERATOR error
3014 { $$ = build_opid (ERROR_MARK, ERROR_MARK); }
3019 #if YYDEBUG != 0
3020 db_yyerror (s, yyps, yychar)
3021 char *s;
3022 short *yyps;
3023 int yychar;
3025 FILE *yyout;
3026 char buf[1024];
3027 int st;
3029 yyerror (s);
3030 printf ("State is %d, input token number is %d.\n", *yyps, yychar);
3032 #ifdef PARSE_OUTPUT
3033 if (*yyps < 1) fatal ("Cannot start from here");
3034 else if ((yyout = fopen (PARSE_OUTPUT, "r")) == NULL)
3035 error ("cannot open file %s", PARSE_OUTPUT);
3036 else
3038 printf ("That is to say,\n\n");
3039 while (fgets(buf, sizeof (buf)-1, yyout))
3041 if (buf[0] != 's') continue;
3042 st = atoi (buf+6);
3043 if (st != *yyps) continue;
3044 printf ("%s", buf);
3045 while (fgets (buf, sizeof (buf)-1, yyout))
3047 if (buf[0] == 's') break;
3048 printf ("%s", buf);
3050 break;
3052 printf ("With the token %s\n", yytname[YYTRANSLATE (yychar)]);
3053 fclose (yyout);
3055 #endif
3057 #endif
3059 void
3060 yyerror (string)
3061 char *string;
3063 extern FILE *finput;
3064 extern char *token_buffer;
3065 char buf[200];
3067 strcpy (buf, string);
3069 /* We can't print string and character constants well
3070 because the token_buffer contains the result of processing escapes. */
3071 if (end_of_file || feof (finput))
3072 strcat (buf, " at end of input");
3073 else if (token_buffer[0] == 0)
3074 strcat (buf, " at null character");
3075 else if (token_buffer[0] == '"')
3076 strcat (buf, " before string constant");
3077 else if (token_buffer[0] == '\'')
3078 strcat (buf, " before character constant");
3079 else
3080 strcat (buf, " before `%s'");
3082 error (buf, token_buffer);
3085 #ifndef GATHER_STATISTICS
3086 int *init_parse () { return 0; }
3087 #else
3088 static int *reduce_count;
3089 static int *token_count;
3091 #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
3092 #define TOKEN_LENGTH (256 + YYNTBASE + 1)
3094 int *
3095 init_parse ()
3097 reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1));
3098 bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1));
3099 reduce_count += 1;
3100 token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1));
3101 bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1));
3102 token_count += 1;
3103 return token_count;
3106 void
3107 yyhook (yyn)
3108 int yyn;
3110 reduce_count[yyn] += 1;
3113 static int reduce_cmp (p, q)
3114 int *p, *q;
3116 return reduce_count[*q] - reduce_count[*p];
3119 static int token_cmp (p, q)
3120 int *p, *q;
3122 return token_count[*q] - token_count[*p];
3125 void
3126 print_parse_statistics ()
3128 int i;
3129 int maxlen = REDUCE_LENGTH;
3130 unsigned *sorted;
3132 if (reduce_count[-1] == 0)
3133 return;
3135 if (TOKEN_LENGTH > REDUCE_LENGTH)
3136 maxlen = TOKEN_LENGTH;
3137 sorted = (unsigned *) alloca (sizeof (int) * maxlen);
3139 for (i = 0; i < TOKEN_LENGTH; i++)
3140 sorted[i] = i;
3141 qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
3142 for (i = 0; i < TOKEN_LENGTH; i++)
3144 int index = sorted[i];
3145 if (token_count[index] == 0)
3146 break;
3147 if (token_count[index] < token_count[-1])
3148 break;
3149 fprintf (stderr, "token %d", index);
3150 #if YYDEBUG
3151 fprintf (stderr, ", `%s'", yytname[YYTRANSLATE (index)]);
3152 #endif
3153 fprintf (stderr, ", count = %d\n", token_count[index]);
3155 fprintf (stderr, "\n");
3156 for (i = 0; i < REDUCE_LENGTH; i++)
3157 sorted[i] = i;
3158 qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
3159 for (i = 0; i < REDUCE_LENGTH; i++)
3161 int index = sorted[i];
3162 if (reduce_count[index] == 0)
3163 break;
3164 if (reduce_count[index] < reduce_count[-1])
3165 break;
3166 fprintf (stderr, "rule %d", index);
3167 #if YYDEBUG
3168 fprintf (stderr, ", line %d", yyrline[index]);
3169 #endif
3170 fprintf (stderr, ", count = %d\n", reduce_count[index]);
3172 fprintf (stderr, "\n");
3174 #endif