Commit 9d85d30c by Mark Mitchell Committed by Mark Mitchell

cp-tree.h (build_target_expr): New function.

	* cp-tree.h (build_target_expr): New function.
	* call.c (build_conditional_expr): Use build_target_expr.
	(convert_like): Likewise.
	(build_over_call): Likewise.
	* cvt.c (build_up_reference): Likewise.
	* decl.c (build_cleanup_on_safe_obstack): Fold into ...
	(destroy_local_var): Here.
	(build_target_expr): New function.
	* tree.c (build_cplus_new): Use it.
	(get_target_expr): Likewise.

From-SVN: r29387
parent 88731f16
1999-09-13 Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (build_target_expr): New function.
* call.c (build_conditional_expr): Use build_target_expr.
(convert_like): Likewise.
(build_over_call): Likewise.
* cvt.c (build_up_reference): Likewise.
* decl.c (build_cleanup_on_safe_obstack): Fold into ...
(destroy_local_var): Here.
(build_target_expr): New function.
* tree.c (build_cplus_new): Use it.
(get_target_expr): Likewise.
1999-09-13 Nathan Sidwell <nathan@acm.org> 1999-09-13 Nathan Sidwell <nathan@acm.org>
* typeck.c (expr_sizeof): Don't decay arrays and functions. * typeck.c (expr_sizeof): Don't decay arrays and functions.
......
...@@ -3080,8 +3080,7 @@ build_conditional_expr (arg1, arg2, arg3) ...@@ -3080,8 +3080,7 @@ build_conditional_expr (arg1, arg2, arg3)
{ {
tree slot = build (VAR_DECL, result_type); tree slot = build (VAR_DECL, result_type);
layout_decl (slot, 0); layout_decl (slot, 0);
result = build (TARGET_EXPR, result_type, result = build_target_expr (slot, result);
slot, result, NULL_TREE, NULL_TREE);
} }
/* If this expression is an rvalue, but might be mistaken for an /* If this expression is an rvalue, but might be mistaken for an
...@@ -3749,8 +3748,7 @@ convert_like (convs, expr) ...@@ -3749,8 +3748,7 @@ convert_like (convs, expr)
tree type = TREE_TYPE (TREE_OPERAND (convs, 0)); tree type = TREE_TYPE (TREE_OPERAND (convs, 0));
tree slot = build_decl (VAR_DECL, NULL_TREE, type); tree slot = build_decl (VAR_DECL, NULL_TREE, type);
DECL_ARTIFICIAL (slot) = 1; DECL_ARTIFICIAL (slot) = 1;
expr = build (TARGET_EXPR, type, slot, expr, expr = build_target_expr (slot, expr);
NULL_TREE, NULL_TREE);
TREE_SIDE_EFFECTS (expr) = 1; TREE_SIDE_EFFECTS (expr) = 1;
} }
...@@ -4039,7 +4037,7 @@ build_over_call (cand, args, flags) ...@@ -4039,7 +4037,7 @@ build_over_call (cand, args, flags)
else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn))) else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
{ {
val = build_decl (VAR_DECL, NULL_TREE, DECL_CONTEXT (fn)); val = build_decl (VAR_DECL, NULL_TREE, DECL_CONTEXT (fn));
val = build (TARGET_EXPR, DECL_CONTEXT (fn), val, arg, 0, 0); val = build_target_expr (val, arg);
TREE_SIDE_EFFECTS (val) = 1; TREE_SIDE_EFFECTS (val) = 1;
return val; return val;
} }
......
...@@ -3247,6 +3247,7 @@ extern tree cp_namespace_decls PROTO((tree)); ...@@ -3247,6 +3247,7 @@ extern tree cp_namespace_decls PROTO((tree));
extern tree create_implicit_typedef PROTO((tree, tree)); extern tree create_implicit_typedef PROTO((tree, tree));
extern tree maybe_push_decl PROTO((tree)); extern tree maybe_push_decl PROTO((tree));
extern void emit_local_var PROTO((tree)); extern void emit_local_var PROTO((tree));
extern tree build_target_expr PROTO((tree, tree));
/* in decl2.c */ /* in decl2.c */
extern void init_decl2 PROTO((void)); extern void init_decl2 PROTO((void));
......
...@@ -364,7 +364,7 @@ build_up_reference (type, arg, flags) ...@@ -364,7 +364,7 @@ build_up_reference (type, arg, flags)
{ {
tree slot = build_decl (VAR_DECL, NULL_TREE, argtype); tree slot = build_decl (VAR_DECL, NULL_TREE, argtype);
DECL_ARTIFICIAL (slot) = 1; DECL_ARTIFICIAL (slot) = 1;
arg = build (TARGET_EXPR, argtype, slot, arg, NULL_TREE, NULL_TREE); arg = build_target_expr (slot, arg);
TREE_SIDE_EFFECTS (arg) = 1; TREE_SIDE_EFFECTS (arg) = 1;
} }
......
...@@ -169,7 +169,6 @@ static void pop_labels PROTO((tree)); ...@@ -169,7 +169,6 @@ static void pop_labels PROTO((tree));
static void maybe_deduce_size_from_array_init PROTO((tree, tree)); static void maybe_deduce_size_from_array_init PROTO((tree, tree));
static tree layout_var_decl PROTO((tree, tree)); static tree layout_var_decl PROTO((tree, tree));
static void maybe_commonize_var PROTO((tree)); static void maybe_commonize_var PROTO((tree));
static tree build_cleanup_on_safe_obstack PROTO((tree));
static tree check_initializer PROTO((tree, tree)); static tree check_initializer PROTO((tree, tree));
static void make_rtl_for_nonlocal_decl PROTO((tree, tree, const char *)); static void make_rtl_for_nonlocal_decl PROTO((tree, tree, const char *));
static void push_cp_function_context PROTO((struct function *)); static void push_cp_function_context PROTO((struct function *));
...@@ -7121,47 +7120,6 @@ layout_var_decl (decl, init) ...@@ -7121,47 +7120,6 @@ layout_var_decl (decl, init)
return init; return init;
} }
/* Return a cleanup for DECL, created on whatever obstack is
appropriate. */
static tree
build_cleanup_on_safe_obstack (decl)
tree decl;
{
tree cleanup;
tree type;
int need_pop;
type = TREE_TYPE (decl);
/* Only variables get cleaned up. */
if (TREE_CODE (decl) != VAR_DECL)
return NULL_TREE;
/* And only things with destructors need cleaning up. */
if (!TYPE_NEEDS_DESTRUCTOR (type))
return NULL_TREE;
if (TREE_CODE (decl) == VAR_DECL &&
(DECL_EXTERNAL (decl) || TREE_STATIC (decl)))
/* We don't clean up things that aren't defined in this
translation unit, or that need a static cleanup. The latter
are handled by finish_file. */
return NULL_TREE;
/* Switch to an obstack that will live until the point where the
cleanup code is actually expanded. */
need_pop = suspend_momentary ();
/* Compute the cleanup. */
cleanup = maybe_build_cleanup (decl);
/* Pop back to the obstack we were on before. */
resume_momentary (need_pop);
return cleanup;
}
/* If a local static variable is declared in an inline function, or if /* If a local static variable is declared in an inline function, or if
we have a weak definition, we must endeavor to create only one we have a weak definition, we must endeavor to create only one
instance of the variable at link-time. */ instance of the variable at link-time. */
...@@ -7557,7 +7515,26 @@ void ...@@ -7557,7 +7515,26 @@ void
destroy_local_var (decl) destroy_local_var (decl)
tree decl; tree decl;
{ {
tree cleanup = build_cleanup_on_safe_obstack (decl); tree type = TREE_TYPE (decl);
tree cleanup;
/* Only variables get cleaned up. */
if (TREE_CODE (decl) != VAR_DECL)
return;
/* And only things with destructors need cleaning up. */
if (!TYPE_NEEDS_DESTRUCTOR (type))
return;
if (TREE_CODE (decl) == VAR_DECL &&
(DECL_EXTERNAL (decl) || TREE_STATIC (decl)))
/* We don't clean up things that aren't defined in this
translation unit, or that need a static cleanup. The latter
are handled by finish_file. */
return;
/* Compute the cleanup. */
cleanup = maybe_build_cleanup (decl);
/* Record the cleanup required for this declaration. */ /* Record the cleanup required for this declaration. */
if (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node if (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node
...@@ -14143,6 +14120,17 @@ maybe_build_cleanup_1 (decl, auto_delete) ...@@ -14143,6 +14120,17 @@ maybe_build_cleanup_1 (decl, auto_delete)
return 0; return 0;
} }
/* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
tree
build_target_expr (decl, value)
tree decl;
tree value;
{
return build (TARGET_EXPR, TREE_TYPE (decl), decl, value,
maybe_build_cleanup (decl), NULL_TREE);
}
/* If DECL is of a type which needs a cleanup, build that cleanup /* If DECL is of a type which needs a cleanup, build that cleanup
here. The cleanup does free the storage with a call to delete. */ here. The cleanup does free the storage with a call to delete. */
......
...@@ -251,7 +251,7 @@ build_cplus_new (type, init) ...@@ -251,7 +251,7 @@ build_cplus_new (type, init)
= (TREE_CODE (fn) == ADDR_EXPR = (TREE_CODE (fn) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
&& DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0))); && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
rval = build (TARGET_EXPR, type, slot, rval, NULL_TREE, NULL_TREE); rval = build_target_expr (slot, rval);
TREE_SIDE_EFFECTS (rval) = 1; TREE_SIDE_EFFECTS (rval) = 1;
return rval; return rval;
...@@ -269,8 +269,7 @@ get_target_expr (init) ...@@ -269,8 +269,7 @@ get_target_expr (init)
slot = build (VAR_DECL, TREE_TYPE (init)); slot = build (VAR_DECL, TREE_TYPE (init));
DECL_ARTIFICIAL (slot) = 1; DECL_ARTIFICIAL (slot) = 1;
layout_decl (slot, 0); layout_decl (slot, 0);
rval = build (TARGET_EXPR, TREE_TYPE (init), slot, init, rval = build_target_expr (slot, init);
NULL_TREE, NULL_TREE);
TREE_SIDE_EFFECTS (rval) = 1; TREE_SIDE_EFFECTS (rval) = 1;
return rval; return rval;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment