1 /* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
6 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GNU CC.
12 GNU CC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
17 GNU CC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GNU CC; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
35 /* There routines provide a modular interface to perform many parsing
36 operations. They may therefore be used during actual parsing, or
37 during template instantiation, which may be regarded as a
38 degenerate form of parsing. Since the current g++ parser is
39 lacking in several respects, and will be reimplemented, we are
40 attempting to move most code that is not directly related to
41 parsing into this file; that will make implementing the new parser
42 much easier since it will be able to make use of these routines. */
44 static void do_pushlevel
PROTO((void));
45 static tree do_poplevel
PROTO((void));
46 static void finish_expr_stmt_real
PROTO((tree
, int));
47 static tree expand_cond
PROTO((tree
));
48 static tree maybe_convert_cond
PROTO((tree
));
50 /* When parsing a template, LAST_TREE contains the last statement
51 parsed. These are chained together through the TREE_CHAIN field,
52 but often need to be re-organized since the parse is performed
53 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
56 #define RECHAIN_STMTS(stmt, substmt) \
58 substmt = TREE_CHAIN (stmt); \
59 TREE_CHAIN (stmt) = NULL_TREE; \
63 /* Finish processing the COND, the SUBSTMT condition for STMT. */
65 #define FINISH_COND(cond, stmt, substmt) \
67 if (last_tree != stmt) \
69 RECHAIN_STMTS (stmt, substmt); \
70 if (!processing_template_decl) \
72 cond = build_tree_list (substmt, cond); \
80 /* T is a statement. Add it to the statement-tree. */
86 /* Add T to the statement-tree. */
87 last_tree
= TREE_CHAIN (last_tree
) = t
;
89 /* When we expand a statement-tree, we must know whether or not the
90 statements are full-expresions. We record that fact here. */
91 if (building_stmt_tree ())
92 STMT_IS_FULL_EXPR_P (last_tree
) = stmts_are_full_exprs_p
;
95 /* COND is the condition-expression for an if, while, etc.,
96 statement. Convert it to a boolean value, if appropriate. */
99 maybe_convert_cond (cond
)
102 /* Empty conditions remain empty. */
106 /* Wait until we instantiate templates before doing conversion. */
107 if (processing_template_decl
)
110 /* Do the conversion. */
111 cond
= convert_from_reference (cond
);
112 return condition_conversion (cond
);
115 /* Finish an expression-statement, whose EXPRESSION is as indicated.
116 If ASSIGNED_THIS is non-zero, then this statement just assigned to
117 the `this' pointer. */
120 finish_expr_stmt_real (expr
, assigned_this
)
124 if (expr
!= NULL_TREE
)
126 if (building_stmt_tree ())
127 add_tree (build_min_nt (EXPR_STMT
, expr
));
130 emit_line_note (input_filename
, lineno
);
131 /* Do default conversion if safe and possibly important,
132 in case within ({...}). */
133 if (!stmts_are_full_exprs_p
&&
134 ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
136 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
))
137 expr
= default_conversion (expr
);
139 if (stmts_are_full_exprs_p
)
140 expand_start_target_temps ();
142 cplus_expand_expr_stmt (expr
);
144 if (stmts_are_full_exprs_p
)
146 expand_end_target_temps ();
152 /* If this statement assigned to the `this' pointer, record that
153 fact for finish_stmt. */
155 current_function_just_assigned_this
= 1;
159 /* This was an expression-statement, so we save the type of the
161 last_expr_type
= expr
? TREE_TYPE (expr
) : NULL_TREE
;
164 /* Like finish_expr_stmt_real, but ASSIGNS_THIS is always zero. */
167 finish_expr_stmt (expr
)
170 finish_expr_stmt_real (expr
, /*assigns_this=*/0);
173 /* Begin an if-statement. Returns a newly created IF_STMT if
181 if (building_stmt_tree ())
183 r
= build_min_nt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
194 /* Process the COND of an if-statement, which may be given by
198 finish_if_stmt_cond (cond
, if_stmt
)
202 cond
= maybe_convert_cond (cond
);
204 if (building_stmt_tree ())
205 FINISH_COND (cond
, if_stmt
, IF_COND (if_stmt
));
208 emit_line_note (input_filename
, lineno
);
209 expand_start_cond (cond
, 0);
213 /* Finish the then-clause of an if-statement, which may be given by
217 finish_then_clause (if_stmt
)
220 if (building_stmt_tree ())
222 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
230 /* Begin the else-clause of an if-statement. */
235 if (!building_stmt_tree ())
236 expand_start_else ();
239 /* Finish the else-clause of an if-statement, which may be given by
243 finish_else_clause (if_stmt
)
246 if (building_stmt_tree ())
247 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
250 /* Finsh an if-statement. */
255 if (!building_stmt_tree ())
262 /* Begin a while-statement. Returns a newly created WHILE_STMT if
270 if (building_stmt_tree ())
272 r
= build_min_nt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
278 emit_line_note (input_filename
, lineno
);
279 expand_start_loop (1);
288 /* Process the COND of an if-statement, which may be given by
292 finish_while_stmt_cond (cond
, while_stmt
)
296 cond
= maybe_convert_cond (cond
);
298 if (building_stmt_tree ())
299 FINISH_COND (cond
, while_stmt
, WHILE_COND (while_stmt
));
302 emit_line_note (input_filename
, lineno
);
303 expand_exit_loop_if_false (0, cond
);
306 /* If COND wasn't a declaration, clear out the
307 block we made for it and start a new one here so the
308 optimization in expand_end_loop will work. */
309 if (getdecls () == NULL_TREE
)
316 /* Finish a while-statement, which may be given by WHILE_STMT. */
319 finish_while_stmt (while_stmt
)
324 if (building_stmt_tree ())
325 RECHAIN_STMTS (while_stmt
, WHILE_BODY (while_stmt
));
331 /* Begin a do-statement. Returns a newly created DO_STMT if
337 if (building_stmt_tree ())
339 tree r
= build_min_nt (DO_STMT
, NULL_TREE
, NULL_TREE
);
346 emit_line_note (input_filename
, lineno
);
347 expand_start_loop_continue_elsewhere (1);
352 /* Finish the body of a do-statement, which may be given by DO_STMT. */
355 finish_do_body (do_stmt
)
358 if (building_stmt_tree ())
359 RECHAIN_STMTS (do_stmt
, DO_BODY (do_stmt
));
361 expand_loop_continue_here ();
364 /* Finish a do-statement, which may be given by DO_STMT, and whose
365 COND is as indicated. */
368 finish_do_stmt (cond
, do_stmt
)
372 cond
= maybe_convert_cond (cond
);
374 if (building_stmt_tree ())
375 DO_COND (do_stmt
) = cond
;
378 emit_line_note (input_filename
, lineno
);
379 expand_exit_loop_if_false (0, cond
);
387 /* Finish a return-statement. The EXPRESSION returned, if any, is as
391 finish_return_stmt (expr
)
394 if (building_stmt_tree ())
395 add_tree (build_min_nt (RETURN_STMT
, expr
));
398 emit_line_note (input_filename
, lineno
);
399 c_expand_return (expr
);
405 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
412 if (building_stmt_tree ())
414 r
= build_min_nt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
415 NULL_TREE
, NULL_TREE
);
421 if (flag_new_for_scope
> 0)
424 note_level_for_for ();
430 /* Finish the for-init-statement of a for-statement, which may be
431 given by FOR_STMT. */
434 finish_for_init_stmt (for_stmt
)
437 if (building_stmt_tree ())
439 if (last_tree
!= for_stmt
)
440 RECHAIN_STMTS (for_stmt
, FOR_INIT_STMT (for_stmt
));
445 emit_line_note (input_filename
, lineno
);
446 expand_start_loop_continue_elsewhere (1);
452 /* Finish the COND of a for-statement, which may be given by
456 finish_for_cond (cond
, for_stmt
)
460 cond
= maybe_convert_cond (cond
);
462 if (building_stmt_tree ())
463 FINISH_COND (cond
, for_stmt
, FOR_COND (for_stmt
));
466 emit_line_note (input_filename
, lineno
);
468 expand_exit_loop_if_false (0, cond
);
471 /* If the cond wasn't a declaration, clear out the
472 block we made for it and start a new one here so the
473 optimization in expand_end_loop will work. */
474 if (getdecls () == NULL_TREE
)
481 /* Finish the increment-EXPRESSION in a for-statement, which may be
482 given by FOR_STMT. */
485 finish_for_expr (expr
, for_stmt
)
489 if (building_stmt_tree ())
490 FOR_EXPR (for_stmt
) = expr
;
492 /* Don't let the tree nodes for EXPR be discarded
493 by clear_momentary during the parsing of the next stmt. */
497 /* Finish the body of a for-statement, which may be given by
498 FOR_STMT. The increment-EXPR for the loop must be
502 finish_for_stmt (expr
, for_stmt
)
506 /* Pop the scope for the body of the loop. */
509 if (building_stmt_tree ())
510 RECHAIN_STMTS (for_stmt
, FOR_BODY (for_stmt
));
513 emit_line_note (input_filename
, lineno
);
514 expand_loop_continue_here ();
516 finish_expr_stmt (expr
);
522 if (flag_new_for_scope
> 0)
528 /* Finish a break-statement. */
533 emit_line_note (input_filename
, lineno
);
534 if (building_stmt_tree ())
535 add_tree (build_min_nt (BREAK_STMT
));
536 else if ( ! expand_exit_something ())
537 cp_error ("break statement not within loop or switch");
540 /* Finish a continue-statement. */
543 finish_continue_stmt ()
545 emit_line_note (input_filename
, lineno
);
546 if (building_stmt_tree ())
547 add_tree (build_min_nt (CONTINUE_STMT
));
548 else if (! expand_continue_loop (0))
549 cp_error ("continue statement not within a loop");
552 /* Begin a switch-statement. Returns a new SWITCH_STMT if
560 if (building_stmt_tree ())
562 r
= build_min_nt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
);
573 /* Finish the cond of a switch-statement. */
576 finish_switch_cond (cond
, switch_stmt
)
580 if (building_stmt_tree ())
581 FINISH_COND (cond
, switch_stmt
, SWITCH_COND (switch_stmt
));
582 else if (cond
!= error_mark_node
)
584 emit_line_note (input_filename
, lineno
);
585 c_expand_start_case (cond
);
588 /* The code is in error, but we don't want expand_end_case to
590 c_expand_start_case (boolean_false_node
);
594 /* Don't let the tree nodes for COND be discarded by
595 clear_momentary during the parsing of the next stmt. */
599 /* Finish the body of a switch-statement, which may be given by
600 SWITCH_STMT. The COND to switch on is indicated. */
603 finish_switch_stmt (cond
, switch_stmt
)
607 if (building_stmt_tree ())
608 RECHAIN_STMTS (switch_stmt
, SWITCH_BODY (switch_stmt
));
610 expand_end_case (cond
);
617 /* Finish a case-label. */
620 finish_case_label (low_value
, high_value
)
624 if (building_stmt_tree ())
626 add_tree (build_min_nt (CASE_LABEL
, low_value
, high_value
));
630 do_case (low_value
, high_value
);
633 /* Finish a goto-statement. */
636 finish_goto_stmt (destination
)
639 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
640 destination
= lookup_label (destination
);
642 if (building_stmt_tree ())
643 add_tree (build_min_nt (GOTO_STMT
, destination
));
646 emit_line_note (input_filename
, lineno
);
648 if (TREE_CODE (destination
) == LABEL_DECL
)
650 TREE_USED (destination
) = 1;
651 expand_goto (destination
);
654 expand_computed_goto (destination
);
658 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
664 if (building_stmt_tree ())
666 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
673 emit_line_note (input_filename
, lineno
);
674 expand_start_try_stmts ();
679 /* Likewise, for a function-try-block. */
682 begin_function_try_block ()
684 if (building_stmt_tree ())
686 tree r
= build_min_nt (TRY_BLOCK
, NULL_TREE
,
688 FN_TRY_BLOCK_P (r
) = 1;
694 if (! current_function_parms_stored
)
696 expand_start_early_try_stmts ();
701 /* Finish a try-block, which may be given by TRY_BLOCK. */
704 finish_try_block (try_block
)
707 if (building_stmt_tree ())
708 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
710 expand_start_all_catch ();
713 /* Finish the body of a cleanup try-block, which may be given by
717 finish_cleanup_try_block (try_block
)
720 if (building_stmt_tree ())
721 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
724 /* Finish an implicitly generated try-block, with a cleanup is given
728 finish_cleanup (cleanup
, try_block
)
732 if (building_stmt_tree ())
734 TRY_HANDLERS (try_block
) = cleanup
;
735 CLEANUP_P (try_block
) = 1;
738 expand_eh_region_end (protect_with_terminate (cleanup
));
741 /* Likewise, for a function-try-block. */
744 finish_function_try_block (try_block
)
747 if (building_stmt_tree ())
749 if (TREE_CHAIN (try_block
)
750 && TREE_CODE (TREE_CHAIN (try_block
)) == CTOR_INITIALIZER
)
752 /* Chain the compound statement after the CTOR_INITIALIZER. */
753 TREE_CHAIN (TREE_CHAIN (try_block
)) = last_tree
;
754 /* And make the CTOR_INITIALIZER the body of the try-block. */
755 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
758 RECHAIN_STMTS (try_block
, TRY_STMTS (try_block
));
762 end_protect_partials ();
763 expand_start_all_catch ();
764 in_function_try_handler
= 1;
768 /* Finish a handler-sequence for a try-block, which may be given by
772 finish_handler_sequence (try_block
)
775 if (building_stmt_tree ())
776 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
778 expand_end_all_catch ();
781 /* Likewise, for a function-try-block. */
784 finish_function_handler_sequence (try_block
)
787 if (building_stmt_tree ())
788 RECHAIN_STMTS (try_block
, TRY_HANDLERS (try_block
));
791 in_function_try_handler
= 0;
792 expand_end_all_catch ();
796 /* Begin a handler. Returns a HANDLER if appropriate. */
803 if (building_stmt_tree ())
805 r
= build_min_nt (HANDLER
, NULL_TREE
, NULL_TREE
);
816 /* Finish the handler-parameters for a handler, which may be given by
820 finish_handler_parms (handler
)
823 if (building_stmt_tree ())
824 RECHAIN_STMTS (handler
, HANDLER_PARMS (handler
));
827 /* Finish a handler, which may be given by HANDLER. */
830 finish_handler (handler
)
833 if (building_stmt_tree ())
834 RECHAIN_STMTS (handler
, HANDLER_BODY (handler
));
836 expand_end_catch_block ();
841 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
842 compound-statement does not define a scope. Returns a new
843 COMPOUND_STMT if appropriate. */
846 begin_compound_stmt (has_no_scope
)
851 if (building_stmt_tree ())
853 r
= build_min_nt (COMPOUND_STMT
, NULL_TREE
);
856 COMPOUND_STMT_NO_SCOPE (r
) = 1;
861 last_expr_type
= NULL_TREE
;
866 /* Normally, we try hard to keep the BLOCK for a
867 statement-expression. But, if it's a statement-expression with
868 a scopeless block, there's nothing to keep, and we don't want
869 to accidentally keep a block *inside* the scopeless block. */
876 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
877 If HAS_NO_SCOPE is non-zero, the compound statement does not define
881 finish_compound_stmt (has_no_scope
, compound_stmt
)
893 if (building_stmt_tree ())
894 RECHAIN_STMTS (compound_stmt
, COMPOUND_BODY (compound_stmt
));
896 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
897 the precise purpose of that variable is store the type of the
898 last expression statement within the last compound statement, we
899 preserve the value. */
907 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
908 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
912 finish_asm_stmt (cv_qualifier
, string
, output_operands
,
913 input_operands
, clobbers
)
916 tree output_operands
;
920 if (TREE_CHAIN (string
))
922 if (building_stmt_tree ())
923 /* We need to build the combined string on the permanent
924 obstack so that we can use it during instantiations. */
925 push_permanent_obstack ();
927 string
= combine_strings (string
);
929 if (building_stmt_tree ())
933 if (cv_qualifier
!= NULL_TREE
934 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
936 cp_warning ("%s qualifier ignored on asm",
937 IDENTIFIER_POINTER (cv_qualifier
));
938 cv_qualifier
= NULL_TREE
;
941 if (building_stmt_tree ())
943 tree r
= build_min_nt (ASM_STMT
, cv_qualifier
, string
,
944 output_operands
, input_operands
,
950 emit_line_note (input_filename
, lineno
);
951 if (output_operands
!= NULL_TREE
|| input_operands
!= NULL_TREE
952 || clobbers
!= NULL_TREE
)
956 for (t
= input_operands
; t
; t
= TREE_CHAIN (t
))
957 TREE_VALUE (t
) = decay_conversion (TREE_VALUE (t
));
959 c_expand_asm_operands (string
, output_operands
,
962 cv_qualifier
!= NULL_TREE
,
963 input_filename
, lineno
);
972 /* Finish a label with the indicated NAME. */
975 finish_label_stmt (name
)
978 tree decl
= define_label (input_filename
, lineno
, name
);
980 if (building_stmt_tree ())
981 add_tree (build_min_nt (LABEL_STMT
, decl
));
986 /* Finish a series of declarations for local labels. G++ allows users
987 to declare "local" labels, i.e., labels with scope. This extension
988 is useful when writing code involving statement-expressions. */
991 finish_label_decl (name
)
994 tree decl
= declare_local_label (name
);
995 if (building_stmt_tree ())
996 add_decl_stmt (decl
);
999 /* Create a declaration statement for the declaration given by the
1003 add_decl_stmt (decl
)
1008 /* We need the type to last until instantiation time. */
1009 decl_stmt
= build_min_nt (DECL_STMT
, decl
);
1010 add_tree (decl_stmt
);
1013 /* We're in a constructor, and have just constructed a a subobject of
1014 *THIS. CLEANUP is code to run if an exception is thrown before the
1015 end of the current function is reached. */
1018 finish_subobject (cleanup
)
1021 if (building_stmt_tree ())
1023 tree r
= build_min_nt (SUBOBJECT
, cleanup
);
1027 add_partial_entry (cleanup
);
1030 /* Bind a name and initialization to the return value of
1031 the current function. */
1034 finish_named_return_value (return_id
, init
)
1035 tree return_id
, init
;
1037 tree decl
= DECL_RESULT (current_function_decl
);
1040 /* Give this error as many times as there are occurrences,
1041 so that users can use Emacs compilation buffers to find
1042 and fix all such places. */
1043 pedwarn ("ANSI C++ does not permit named return values");
1045 if (return_id
!= NULL_TREE
)
1047 if (DECL_NAME (decl
) == NULL_TREE
)
1049 DECL_NAME (decl
) = return_id
;
1050 DECL_ASSEMBLER_NAME (decl
) = return_id
;
1054 cp_error ("return identifier `%D' already in place", return_id
);
1059 /* Can't let this happen for constructors. */
1060 if (DECL_CONSTRUCTOR_P (current_function_decl
))
1062 error ("can't redefine default return value for constructors");
1066 /* If we have a named return value, put that in our scope as well. */
1067 if (DECL_NAME (decl
) != NULL_TREE
)
1069 /* Let `cp_finish_decl' know that this initializer is ok. */
1070 DECL_INITIAL (decl
) = init
;
1073 if (building_stmt_tree ())
1074 add_tree (build_min_nt (RETURN_INIT
, return_id
, init
));
1077 cp_finish_decl (decl
, init
, NULL_TREE
, 0, 0);
1078 store_return_init (decl
);
1083 /* Cache the value of this class's main virtual function table pointer
1084 in a register variable. This will save one indirection if a
1085 more than one virtual function call is made this function. */
1090 if (base_init_expr
== 0
1091 && DECL_CONSTRUCTOR_P (current_function_decl
))
1093 if (building_stmt_tree ())
1094 add_tree (build_min_nt
1096 current_member_init_list
, current_base_init_list
));
1098 emit_base_init (current_class_type
);
1101 /* Always keep the BLOCK node associated with the outermost pair of
1102 curley braces of a function. These are needed for correct
1103 operation of dwarfout.c. */
1104 keep_next_level (1);
1107 /* Begin a new scope. */
1112 if (!building_stmt_tree ())
1114 emit_line_note (input_filename
, lineno
);
1118 if (stmts_are_full_exprs_p
)
1120 if (!building_stmt_tree () && stmts_are_full_exprs_p
)
1121 expand_start_bindings (0);
1124 /* Finish a scope. */
1131 if (!building_stmt_tree () && stmts_are_full_exprs_p
)
1132 expand_end_bindings (getdecls (), kept_level_p (), 0);
1133 if (stmts_are_full_exprs_p
)
1134 t
= poplevel (kept_level_p (), 1, 0);
1141 /* Finish a parenthesized expression EXPR. */
1144 finish_parenthesized_expr (expr
)
1147 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr
))))
1148 /* This inhibits warnings in truthvalue_conversion. */
1149 C_SET_EXP_ORIGINAL_CODE (expr
, ERROR_MARK
);
1154 /* Begin a statement-expression. The value returned must be passed to
1155 finish_stmt_expr. */
1160 keep_next_level (1);
1161 /* If we're building a statement tree, then the upcoming compound
1162 statement will be chained onto the tree structure, starting at
1163 last_tree. We return last_tree so that we can later unhook the
1164 compound statement. */
1165 return building_stmt_tree () ? last_tree
: expand_start_stmt_expr();
1168 /* Finish a statement-expression. RTL_EXPR should be the value
1169 returned by the previous begin_stmt_expr; EXPR is the
1170 statement-expression. Returns an expression representing the
1171 statement-expression. */
1174 finish_stmt_expr (rtl_expr
, expr
)
1180 if (!building_stmt_tree ())
1182 rtl_expr
= expand_end_stmt_expr (rtl_expr
);
1183 /* The statements have side effects, so the group does. */
1184 TREE_SIDE_EFFECTS (rtl_expr
) = 1;
1187 if (building_stmt_tree ())
1189 /* If the last thing in the statement-expression was not an
1190 expression-statement, then it has type `void'. */
1191 if (!last_expr_type
)
1192 last_expr_type
= void_type_node
;
1193 result
= build_min (STMT_EXPR
, last_expr_type
, last_tree
);
1194 TREE_SIDE_EFFECTS (result
) = 1;
1196 /* Remove the compound statement from the tree structure; it is
1197 now saved in the STMT_EXPR. */
1198 last_tree
= rtl_expr
;
1199 TREE_CHAIN (last_tree
) = NULL_TREE
;
1201 else if (expr
&& TREE_CODE (expr
) == BLOCK
)
1203 result
= build (BIND_EXPR
, TREE_TYPE (rtl_expr
),
1204 NULL_TREE
, rtl_expr
, expr
);
1205 delete_block (expr
);
1210 if (expr
&& TREE_CODE (expr
) == BLOCK
)
1211 /* Remove the block from the tree at this point. It gets put back
1212 at the proper place when the STMT_EXPR or BIND_EXPR is
1214 delete_block (expr
);
1219 /* Finish a call to FN with ARGS. Returns a representation of the
1223 finish_call_expr (fn
, args
, koenig
)
1232 if (TREE_CODE (fn
) == BIT_NOT_EXPR
)
1233 fn
= build_x_unary_op (BIT_NOT_EXPR
, TREE_OPERAND (fn
, 0));
1234 else if (TREE_CODE (fn
) != TEMPLATE_ID_EXPR
)
1235 fn
= do_identifier (fn
, 2, args
);
1237 result
= build_x_function_call (fn
, args
, current_class_ref
);
1239 if (TREE_CODE (result
) == CALL_EXPR
1240 && (! TREE_TYPE (result
)
1241 || TREE_CODE (TREE_TYPE (result
)) != VOID_TYPE
))
1242 result
= require_complete_type (result
);
1247 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1248 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1249 POSTDECREMENT_EXPR.) */
1252 finish_increment_expr (expr
, code
)
1254 enum tree_code code
;
1256 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1257 a COMPONENT_REF). This way if we've got, say, a reference to a
1258 static member that's being operated on, we don't end up trying to
1259 find a member operator for the class it's in. */
1261 if (TREE_CODE (expr
) == OFFSET_REF
)
1262 expr
= resolve_offset_ref (expr
);
1263 return build_x_unary_op (code
, expr
);
1266 /* Finish a use of `this'. Returns an expression for `this'. */
1273 if (current_class_ptr
)
1275 #ifdef WARNING_ABOUT_CCD
1276 TREE_USED (current_class_ptr
) = 1;
1278 result
= current_class_ptr
;
1280 else if (current_function_decl
1281 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1283 error ("`this' is unavailable for static member functions");
1284 result
= error_mark_node
;
1288 if (current_function_decl
)
1289 error ("invalid use of `this' in non-member function");
1291 error ("invalid use of `this' at top level");
1292 result
= error_mark_node
;
1298 /* Finish a member function call using OBJECT and ARGS as arguments to
1299 FN. Returns an expression for the call. */
1302 finish_object_call_expr (fn
, object
, args
)
1308 /* This is a future direction of this code, but because
1309 build_x_function_call cannot always undo what is done in
1310 build_component_ref entirely yet, we cannot do this. */
1312 tree real_fn
= build_component_ref (object
, fn
, NULL_TREE
, 1);
1313 return finish_call_expr (real_fn
, args
);
1315 if (TREE_CODE (fn
) == TYPE_DECL
)
1317 if (processing_template_decl
)
1318 /* This can happen on code like:
1321 template <class T> void f(T t) {
1325 We just grab the underlying IDENTIFIER. */
1326 fn
= DECL_NAME (fn
);
1329 cp_error ("calling type `%T' like a method", fn
);
1330 return error_mark_node
;
1334 return build_method_call (object
, fn
, args
, NULL_TREE
, LOOKUP_NORMAL
);
1338 /* Finish a qualified member function call using OBJECT and ARGS as
1339 arguments to FN. Returns an expressino for the call. */
1342 finish_qualified_object_call_expr (fn
, object
, args
)
1347 return build_scoped_method_call (object
, TREE_OPERAND (fn
, 0),
1348 TREE_OPERAND (fn
, 1), args
);
1351 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1352 being the scope, if any, of DESTRUCTOR. Returns an expression for
1356 finish_pseudo_destructor_call_expr (object
, scope
, destructor
)
1361 if (processing_template_decl
)
1362 return build_min_nt (PSEUDO_DTOR_EXPR
, object
, scope
, destructor
);
1364 if (scope
&& scope
!= destructor
)
1365 cp_error ("destructor specifier `%T::~%T()' must have matching names",
1368 if ((scope
== NULL_TREE
|| IDENTIFIER_GLOBAL_VALUE (destructor
))
1369 && (TREE_CODE (TREE_TYPE (object
)) !=
1370 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor
)))))
1371 cp_error ("`%E' is not of type `%T'", object
, destructor
);
1373 return cp_convert (void_type_node
, object
);
1376 /* Finish a call to a globally qualified member function FN using
1377 ARGS. Returns an expression for the call. */
1380 finish_qualified_call_expr (fn
, args
)
1384 if (processing_template_decl
)
1385 return build_min_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1387 return build_member_call (TREE_OPERAND (fn
, 0),
1388 TREE_OPERAND (fn
, 1),
1392 /* Finish an expression taking the address of LABEL. Returns an
1393 expression for the address. */
1396 finish_label_address_expr (label
)
1401 label
= lookup_label (label
);
1402 if (label
== NULL_TREE
)
1403 result
= null_pointer_node
;
1406 TREE_USED (label
) = 1;
1407 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
1408 TREE_CONSTANT (result
) = 1;
1414 /* Finish an expression of the form CODE EXPR. */
1417 finish_unary_op_expr (code
, expr
)
1418 enum tree_code code
;
1421 tree result
= build_x_unary_op (code
, expr
);
1422 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
)
1423 TREE_NEGATED_INT (result
) = 1;
1424 overflow_warning (result
);
1428 /* Finish an id-expression. */
1431 finish_id_expr (expr
)
1434 if (TREE_CODE (expr
) == IDENTIFIER_NODE
)
1435 expr
= do_identifier (expr
, 1, NULL_TREE
);
1440 /* Begin a new-placement. */
1443 begin_new_placement ()
1445 /* The arguments to a placement new might be passed to a
1446 deallocation function, in the event that the allocation throws an
1447 exception. Since we don't expand exception handlers until the
1448 end of a function, we must make sure the arguments stay around
1450 return suspend_momentary ();
1453 /* Finish a new-placement. The ARGS are the placement arguments. The
1454 COOKIE is the value returned by the previous call to
1455 begin_new_placement. */
1458 finish_new_placement (args
, cookie
)
1462 resume_momentary (cookie
);
1466 /* Begin a function defniition declared with DECL_SPECS and
1467 DECLARATOR. Returns non-zero if the function-declaration is
1471 begin_function_definition (decl_specs
, declarator
)
1477 split_specs_attrs (decl_specs
, &specs
, &attrs
);
1478 if (!start_function (specs
, declarator
, attrs
, SF_DEFAULT
))
1481 reinit_parse_for_function ();
1482 /* The things we're about to see are not directly qualified by any
1483 template headers we've seen thus far. */
1484 reset_specialization ();
1489 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1493 begin_constructor_declarator (scope
, name
)
1497 tree result
= build_parse_node (SCOPE_REF
, scope
, name
);
1498 enter_scope_of (result
);
1502 /* Finish an init-declarator. Returns a DECL. */
1505 finish_declarator (declarator
, declspecs
, attributes
,
1506 prefix_attributes
, initialized
)
1510 tree prefix_attributes
;
1513 return start_decl (declarator
, declspecs
, initialized
, attributes
,
1517 /* Finish a translation unit. */
1520 finish_translation_unit ()
1522 /* In case there were missing closebraces,
1523 get us back to the global binding level. */
1524 while (! toplevel_bindings_p ())
1526 while (current_namespace
!= global_namespace
)
1531 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1532 Returns the parameter. */
1535 finish_template_type_parm (aggr
, identifier
)
1539 if (aggr
!= class_type_node
)
1541 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1542 aggr
= class_type_node
;
1545 return build_tree_list (aggr
, identifier
);
1548 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1549 Returns the parameter. */
1552 finish_template_template_parm (aggr
, identifier
)
1556 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
1557 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
1558 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
1559 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
1560 SET_DECL_ARTIFICIAL (decl
);
1561 end_template_decl ();
1563 return finish_template_type_parm (aggr
, tmpl
);
1566 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1567 non-zero, the parameter list was terminated by a `...'. */
1570 finish_parmlist (parms
, ellipsis
)
1575 chainon (parms
, void_list_node
);
1576 /* We mark the PARMS as a parmlist so that declarator processing can
1577 disambiguate certain constructs. */
1578 if (parms
!= NULL_TREE
)
1579 TREE_PARMLIST (parms
) = 1;
1584 /* Begin a class definition, as indicated by T. */
1587 begin_class_definition (t
)
1590 push_permanent_obstack ();
1592 if (t
== error_mark_node
1593 || ! IS_AGGR_TYPE (t
))
1595 t
= make_lang_type (RECORD_TYPE
);
1596 pushtag (make_anon_name (), t
, 0);
1599 /* In a definition of a member class template, we will get here with an
1600 implicit typename, a TYPENAME_TYPE with a type. */
1601 if (TREE_CODE (t
) == TYPENAME_TYPE
)
1604 /* If we generated a partial instantiation of this type, but now
1605 we're seeing a real definition, we're actually looking at a
1606 partial specialization. Consider:
1608 template <class T, class U>
1614 template <class T, class U>
1617 typename X<Y<T, U> >::A a;
1620 template <class T, class U>
1625 We have to undo the effects of the previous partial
1627 if (PARTIAL_INSTANTIATION_P (t
))
1631 /* Unfortunately, when we're not in pedantic mode, we
1632 attempt to actually fill in some of the fields of the
1633 partial instantiation, in order to support the implicit
1634 typename extension. Clear those fields now, in
1635 preparation for the definition here. The fields cleared
1636 here must match those set in instantiate_class_template.
1637 Look for a comment mentioning begin_class_definition
1639 TYPE_BINFO_BASETYPES (t
) = NULL_TREE
;
1640 TYPE_FIELDS (t
) = NULL_TREE
;
1641 TYPE_METHODS (t
) = NULL_TREE
;
1642 CLASSTYPE_TAGS (t
) = NULL_TREE
;
1643 TYPE_SIZE (t
) = NULL_TREE
;
1646 /* This isn't a partial instantiation any more. */
1647 PARTIAL_INSTANTIATION_P (t
) = 0;
1649 /* If this type was already complete, and we see another definition,
1651 else if (TYPE_SIZE (t
))
1652 duplicate_tag_error (t
);
1654 /* Update the location of the decl. */
1655 DECL_SOURCE_FILE (TYPE_NAME (t
)) = input_filename
;
1656 DECL_SOURCE_LINE (TYPE_NAME (t
)) = lineno
;
1658 if (TYPE_BEING_DEFINED (t
))
1660 t
= make_lang_type (TREE_CODE (t
));
1661 pushtag (TYPE_IDENTIFIER (t
), t
, 0);
1663 maybe_process_partial_specialization (t
);
1665 TYPE_BEING_DEFINED (t
) = 1;
1666 /* Reset the interface data, at the earliest possible
1667 moment, as it might have been set via a class foo;
1670 tree name
= TYPE_IDENTIFIER (t
);
1672 if (! ANON_AGGRNAME_P (name
))
1674 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
1675 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1676 (t
, interface_unknown
);
1679 /* Only leave this bit clear if we know this
1680 class is part of an interface-only specification. */
1681 if (! CLASSTYPE_INTERFACE_KNOWN (t
)
1682 || ! CLASSTYPE_INTERFACE_ONLY (t
))
1683 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 1;
1686 tmp
= TYPE_IDENTIFIER ($
<ttype
>0);
1687 if (tmp
&& IDENTIFIER_TEMPLATE (tmp
))
1688 overload_template_name (tmp
, 1);
1690 reset_specialization();
1692 /* In case this is a local class within a template
1693 function, we save the current tree structure so
1694 that we can get it back later. */
1697 /* Make a declaration for this class in its own scope. */
1698 build_self_reference ();
1703 /* Finish the member declaration given by DECL. */
1706 finish_member_declaration (decl
)
1709 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
1712 if (decl
== void_type_node
)
1713 /* The COMPONENT was a friend, not a member, and so there's
1714 nothing for us to do. */
1717 /* We should see only one DECL at a time. */
1718 my_friendly_assert (TREE_CHAIN (decl
) == NULL_TREE
, 0);
1720 /* Set up access control for DECL. */
1722 = (current_access_specifier
== access_private_node
);
1723 TREE_PROTECTED (decl
)
1724 = (current_access_specifier
== access_protected_node
);
1725 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
1727 TREE_PRIVATE (DECL_RESULT (decl
)) = TREE_PRIVATE (decl
);
1728 TREE_PROTECTED (DECL_RESULT (decl
)) = TREE_PROTECTED (decl
);
1731 /* Mark the DECL as a member of the current class. */
1732 if (TREE_CODE (decl
) == FUNCTION_DECL
1733 || DECL_FUNCTION_TEMPLATE_P (decl
))
1734 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1735 finish_struct. Presumably it is already set as the function is
1736 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1737 DECL_CLASS_CONTEXT (decl
) = current_class_type
;
1739 DECL_CONTEXT (decl
) = current_class_type
;
1741 /* Put functions on the TYPE_METHODS list and everything else on the
1742 TYPE_FIELDS list. Note that these are built up in reverse order.
1743 We reverse them (to obtain declaration order) in finish_struct. */
1744 if (TREE_CODE (decl
) == FUNCTION_DECL
1745 || DECL_FUNCTION_TEMPLATE_P (decl
))
1747 /* We also need to add this function to the
1748 CLASSTYPE_METHOD_VEC. */
1749 add_method (current_class_type
, 0, decl
);
1751 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
1752 TYPE_METHODS (current_class_type
) = decl
;
1756 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1757 go at the beginning. The reason is that lookup_field_1
1758 searches the list in order, and we want a field name to
1759 override a type name so that the "struct stat hack" will
1760 work. In particular:
1762 struct S { enum E { }; int E } s;
1765 is legal. In addition, the FIELD_DECLs must be maintained in
1766 declaration order so that class layout works as expected.
1767 However, we don't need that order until class layout, so we
1768 save a little time by putting FIELD_DECLs on in reverse order
1769 here, and then reversing them in finish_struct_1. (We could
1770 also keep a pointer to the correct insertion points in the
1773 if (TREE_CODE (decl
) == TYPE_DECL
)
1774 TYPE_FIELDS (current_class_type
)
1775 = chainon (TYPE_FIELDS (current_class_type
), decl
);
1778 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
1779 TYPE_FIELDS (current_class_type
) = decl
;
1782 /* Enter the DECL into the scope of the class. */
1783 if (TREE_CODE (decl
) != USING_DECL
)
1784 pushdecl_class_level (decl
);
1788 /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1789 the definition is immediately followed by a semicolon. Returns the
1793 finish_class_definition (t
, attributes
, semi
, pop_scope_p
)
1799 /* finish_struct nukes this anyway; if finish_exception does too,
1802 note_got_semicolon (t
);
1804 /* If we got any attributes in class_head, xref_tag will stick them in
1805 TREE_TYPE of the type. Grab them now. */
1806 attributes
= chainon (TREE_TYPE (t
), attributes
);
1807 TREE_TYPE (t
) = NULL_TREE
;
1809 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
1813 t
= finish_struct (t
, attributes
);
1815 note_got_semicolon (t
);
1821 check_for_missing_semicolon (t
);
1823 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t
)));
1824 if (current_scope () == current_function_decl
)
1825 do_pending_defargs ();
1830 /* Finish processing the default argument expressions cached during
1831 the processing of a class definition. */
1834 begin_inline_definitions ()
1837 && current_scope () == current_function_decl
)
1838 do_pending_inlines ();
1841 /* Finish processing the inline function definitions cached during the
1842 processing of a class definition. */
1845 finish_inline_definitions ()
1847 if (current_class_type
== NULL_TREE
)
1848 clear_inline_text_obstack ();
1850 /* Undo the begin_tree in begin_class_definition. */
1854 /* Finish processing the declaration of a member class template
1855 TYPES whose template parameters are given by PARMS. */
1858 finish_member_class_template (types
)
1863 /* If there are declared, but undefined, partial specializations
1864 mixed in with the typespecs they will not yet have passed through
1865 maybe_process_partial_specialization, so we do that here. */
1866 for (t
= types
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
1867 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t
))))
1868 maybe_process_partial_specialization (TREE_VALUE (t
));
1870 note_list_got_semicolon (types
);
1871 grok_x_components (types
);
1872 if (TYPE_CONTEXT (TREE_VALUE (types
)) != current_class_type
)
1873 /* The component was in fact a friend declaration. We avoid
1874 finish_member_template_decl performing certain checks by
1878 finish_member_template_decl (types
);
1880 /* As with other component type declarations, we do
1881 not store the new DECL on the list of
1886 /* Finish processsing a complete template declaration. The PARMS are
1887 the template parameters. */
1890 finish_template_decl (parms
)
1894 end_template_decl ();
1896 end_specialization ();
1899 /* Finish processing a a template-id (which names a type) of the form
1900 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1901 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1902 the scope of template-id indicated. */
1905 finish_template_type (name
, args
, entering_scope
)
1912 decl
= lookup_template_class (name
, args
,
1913 NULL_TREE
, NULL_TREE
, entering_scope
);
1914 if (decl
!= error_mark_node
)
1915 decl
= TYPE_STUB_DECL (decl
);
1920 /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
1921 namespace scope or a class scope. */
1927 tree scope
= TREE_OPERAND (sr
, 0);
1929 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
1931 push_decl_namespace (scope
);
1932 TREE_COMPLEXITY (sr
) = -1;
1934 else if (scope
!= current_class_type
)
1936 if (TREE_CODE (scope
) == TYPENAME_TYPE
)
1938 /* In a declarator for a template class member, the scope will
1939 get here as an implicit typename, a TYPENAME_TYPE with a type. */
1940 scope
= TREE_TYPE (scope
);
1941 TREE_OPERAND (sr
, 0) = scope
;
1943 push_nested_class (scope
, 3);
1944 TREE_COMPLEXITY (sr
) = current_class_depth
;
1948 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
1949 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
1950 BASE_CLASS, or NULL_TREE if an error occurred. The
1951 ACCESSS_SPECIFIER is one of
1952 access_{default,public,protected_private}[_virtual]_node.*/
1955 finish_base_specifier (access_specifier
, base_class
)
1956 tree access_specifier
;
1962 if (base_class
== NULL_TREE
)
1964 error ("invalid base class");
1965 type
= error_mark_node
;
1968 type
= TREE_TYPE (base_class
);
1970 if (! is_aggr_type (type
, 1))
1973 result
= build_tree_list (access_specifier
, type
);
1978 /* Called when multiple declarators are processed. If that is not
1979 premitted in this context, an error is issued. */
1982 check_multiple_declarators ()
1986 In a template-declaration, explicit specialization, or explicit
1987 instantiation the init-declarator-list in the declaration shall
1988 contain at most one declarator.
1990 We don't just use PROCESSING_TEMPLATE_DECL for the first
1991 condition since that would disallow the perfectly legal code,
1992 like `template <class T> struct S { int i, j; };'. */
1993 tree scope
= current_scope ();
1995 if (scope
&& TREE_CODE (scope
) == FUNCTION_DECL
)
1996 /* It's OK to write `template <class T> void f() { int i, j;}'. */
1999 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2000 || processing_explicit_instantiation
2001 || processing_specialization
)
2002 cp_error ("multiple declarators in template declaration");
2006 finish_typeof (expr
)
2009 if (processing_template_decl
)
2013 push_permanent_obstack ();
2014 t
= make_lang_type (TYPEOF_TYPE
);
2015 TYPE_FIELDS (t
) = expr
;
2021 return TREE_TYPE (expr
);
2024 /* Create an empty statement tree for FN. */
2027 begin_stmt_tree (fn
)
2030 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2031 what follows. We remove the extraneous statement in
2032 finish_stmt_tree. */
2033 DECL_SAVED_TREE (fn
) = build_nt (EXPR_STMT
, void_zero_node
);
2034 last_tree
= DECL_SAVED_TREE (fn
);
2035 last_expr_type
= NULL_TREE
;
2038 /* Finish the statement tree for FN. */
2041 finish_stmt_tree (fn
)
2046 /* Remove the fake extra statement added in begin_stmt_tree. */
2047 stmt
= TREE_CHAIN (DECL_SAVED_TREE (fn
));
2048 DECL_SAVED_TREE (fn
) = stmt
;
2050 /* The line-number recorded in the outermost statement in a function
2051 is the line number of the end of the function. */
2052 STMT_LINENO (stmt
) = lineno
;
2053 STMT_LINENO_FOR_FN_P (stmt
) = 1;
2056 /* We're about to expand T, a statement. Set up appropriate context
2057 for the substitution. */
2063 if (!STMT_LINENO_FOR_FN_P (t
))
2064 lineno
= STMT_LINENO (t
);
2065 stmts_are_full_exprs_p
= STMT_IS_FULL_EXPR_P (t
);
2068 /* Some statements, like for-statements or if-statements, require a
2069 condition. This condition can be a declaration. If T is such a
2070 declaration it is processed, and an expression appropriate to use
2071 as the condition is returned. Otherwise, T itself is returned. */
2077 if (t
&& TREE_CODE (t
) == TREE_LIST
)
2079 expand_stmt (TREE_PURPOSE (t
));
2080 return TREE_VALUE (t
);
2086 /* Generate RTL for the statement T, and its substatements, and any
2087 other statements at its nesting level. */
2095 while (t
&& t
!= error_mark_node
)
2097 int saved_stmts_are_full_exprs_p
;
2099 /* Assume we'll have nothing to return. */
2102 /* Set up context appropriately for handling this statement. */
2103 saved_stmts_are_full_exprs_p
= stmts_are_full_exprs_p
;
2106 switch (TREE_CODE (t
))
2109 finish_return_stmt (RETURN_EXPR (t
));
2113 finish_expr_stmt_real (EXPR_STMT_EXPR (t
),
2114 EXPR_STMT_ASSIGNS_THIS (t
));
2120 int i
= suspend_momentary ();
2122 emit_line_note (input_filename
, lineno
);
2123 decl
= DECL_STMT_DECL (t
);
2124 if (TREE_CODE (decl
) == LABEL_DECL
)
2125 finish_label_decl (DECL_NAME (decl
));
2128 /* If we marked this variable as dead when we processed it
2129 before, we must undo that now. The variable has been
2131 if (TREE_CODE (decl
) == VAR_DECL
)
2132 DECL_DEAD_FOR_LOCAL (decl
) = 0;
2133 /* We need to clear DECL_CONTEXT so that maybe_push_decl
2134 will push it into the current scope. */
2135 if (DECL_CONTEXT (decl
) == current_function_decl
)
2137 DECL_CONTEXT (decl
) = NULL_TREE
;
2138 maybe_push_decl (decl
);
2140 /* If this is a declaration for an automatic local
2141 variable, initialize it. Note that we might also see a
2142 declaration for a namespace-scope object (declared with
2143 `extern') or an object with static storage duration
2144 (declared with `static'). We don't have to handle the
2145 initialization of those objects here; the former can
2146 never be a definition (only a declaration), and the
2147 latter is handled in finish_file. */
2148 if (TREE_CODE (decl
) == VAR_DECL
2149 && !TREE_STATIC (decl
)
2150 && !DECL_EXTERNAL (decl
))
2152 /* Support the old for-scope rules for backwards
2154 maybe_inject_for_scope_var (decl
);
2155 /* Let the back-end know about this variable. */
2156 initialize_local_var (decl
, DECL_INITIAL (decl
), 0);
2159 resume_momentary (i
);
2168 expand_stmt (FOR_INIT_STMT (t
));
2169 finish_for_init_stmt (NULL_TREE
);
2170 finish_for_cond (expand_cond (FOR_COND (t
)), NULL_TREE
);
2172 finish_for_expr (tmp
, NULL_TREE
);
2173 expand_stmt (FOR_BODY (t
));
2174 finish_for_stmt (tmp
, NULL_TREE
);
2180 begin_while_stmt ();
2181 finish_while_stmt_cond (expand_cond (WHILE_COND (t
)), NULL_TREE
);
2182 expand_stmt (WHILE_BODY (t
));
2183 finish_while_stmt (NULL_TREE
);
2190 expand_stmt (DO_BODY (t
));
2191 finish_do_body (NULL_TREE
);
2192 finish_do_stmt (DO_COND (t
), NULL_TREE
);
2198 finish_if_stmt_cond (expand_cond (IF_COND (t
)), NULL_TREE
);
2199 if (THEN_CLAUSE (t
))
2201 expand_stmt (THEN_CLAUSE (t
));
2202 finish_then_clause (NULL_TREE
);
2204 if (ELSE_CLAUSE (t
))
2206 begin_else_clause ();
2207 expand_stmt (ELSE_CLAUSE (t
));
2208 finish_else_clause (NULL_TREE
);
2214 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
));
2215 expand_stmt (COMPOUND_BODY (t
));
2216 rval
= finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t
),
2221 finish_break_stmt ();
2225 finish_continue_stmt ();
2232 begin_switch_stmt ();
2233 cond
= expand_cond (SWITCH_COND (t
));
2234 finish_switch_cond (cond
, NULL_TREE
);
2235 expand_stmt (SWITCH_BODY (t
));
2236 finish_switch_stmt (cond
, NULL_TREE
);
2241 finish_case_label (CASE_LOW (t
), CASE_HIGH (t
));
2245 finish_label_stmt (DECL_NAME (LABEL_STMT_LABEL (t
)));
2249 if (TREE_CODE (GOTO_DESTINATION (t
)) == LABEL_DECL
)
2250 finish_goto_stmt (DECL_NAME (GOTO_DESTINATION (t
)));
2252 finish_goto_stmt (GOTO_DESTINATION (t
));
2256 finish_asm_stmt (ASM_CV_QUAL (t
), ASM_STRING (t
), ASM_OUTPUTS
2257 (t
), ASM_INPUTS (t
), ASM_CLOBBERS (t
));
2263 expand_eh_region_start ();
2264 expand_stmt (TRY_STMTS (t
));
2265 finish_cleanup_try_block (NULL_TREE
);
2266 finish_cleanup (TRY_HANDLERS (t
), NULL_TREE
);
2271 expand_stmt (TRY_STMTS (t
));
2272 finish_try_block (NULL_TREE
);
2273 expand_stmt (TRY_HANDLERS (t
));
2274 finish_handler_sequence (NULL_TREE
);
2280 if (HANDLER_PARMS (t
))
2281 expand_start_catch_block (DECL_STMT_DECL (HANDLER_PARMS (t
)));
2283 expand_start_catch_block (NULL_TREE
);
2284 finish_handler_parms (NULL_TREE
);
2285 expand_stmt (HANDLER_BODY (t
));
2286 finish_handler (NULL_TREE
);
2290 finish_subobject (SUBOBJECT_CLEANUP (t
));
2294 my_friendly_abort (19990810);
2298 /* Restore saved state. */
2299 stmts_are_full_exprs_p
= saved_stmts_are_full_exprs_p
;
2301 /* Go on to the next statement in this scope. */
2308 /* Generate RTL for FN. */
2315 char *saved_input_filename
;
2319 /* When the parser calls us after finishing the body of a template
2320 function, we don't really want to expand the body. When we're
2321 processing an in-class definition of an inline function,
2322 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2323 to look at the function itself. */
2324 if (processing_template_decl
2325 || (DECL_LANG_SPECIFIC (fn
)
2326 && DECL_TEMPLATE_INFO (fn
)
2327 && uses_template_parms (DECL_TI_ARGS (fn
))))
2330 /* Save the current file name and line number. When we expand the
2331 body of the funciton, we'll set LINENO and INPUT_FILENAME so that
2332 error-mesages come out in the right places. */
2333 saved_lineno
= lineno
;
2334 saved_input_filename
= input_filename
;
2335 lineno
= DECL_SOURCE_LINE (fn
);
2336 input_filename
= DECL_SOURCE_FILE (fn
);
2338 start_function (NULL_TREE
, fn
, NULL_TREE
, SF_PRE_PARSED
| SF_EXPAND
);
2339 store_parm_decls ();
2341 /* There are a few things that we do not handle recursively. For
2342 example, a function try-block is handled differently from an
2343 ordinary try-block, so we must handle it here. */
2344 t
= DECL_SAVED_TREE (fn
);
2345 try_block
= NULL_TREE
;
2346 if (t
&& TREE_CODE (t
) == TRY_BLOCK
)
2349 begin_function_try_block ();
2350 t
= TRY_STMTS (try_block
);
2353 if (t
&& TREE_CODE (t
) == RETURN_INIT
)
2355 /* Clear this out so that finish_named_return_value can set it
2357 DECL_NAME (DECL_RESULT (fn
)) = NULL_TREE
;
2358 finish_named_return_value (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
2362 if (t
&& TREE_CODE (t
) == CTOR_INITIALIZER
)
2364 current_member_init_list
= TREE_OPERAND (t
, 0);
2365 current_base_init_list
= TREE_OPERAND (t
, 1);
2369 /* If this is a constructor, we need to initialize our members and
2373 /* Expand the body. */
2376 /* If there was a function try-block, expand the handlers. */
2379 finish_function_try_block (NULL_TREE
);
2380 expand_stmt (TRY_HANDLERS (try_block
));
2381 finish_function_handler_sequence (NULL_TREE
);
2384 /* Statements should always be full-expressions at the outermost set
2385 of curly braces for a function. */
2386 my_friendly_assert (stmts_are_full_exprs_p
, 19990831);
2388 /* The outermost statement for a function contains the line number
2389 recorded when we finished processing the function. */
2390 lineno
= STMT_LINENO (DECL_SAVED_TREE (fn
));
2392 /* Generate code for the function. */
2393 finish_function (lineno
, 0);
2395 /* And restore the current source position. */
2396 lineno
= saved_lineno
;
2397 input_filename
= saved_input_filename
;