2
0
mirror of git://gcc.gnu.org/git/gcc.git synced 2024-12-26 08:18:59 +08:00

cp-tree.h (build_compound_expr): Take LHS & RHS args.

* cp-tree.h (build_compound_expr): Take LHS & RHS args.
	(build_x_compound_expr_from_list): Declare.
	* typeck.c (build_x_compound_expr_from_list): New.
	(build_x_compound_expr): Adjust.
	(build_compound_expr): Remove unreachable code. Take two
	parameters, adjust.
	* decl.c (grok_reference_init): Use
	build_x_compound_expr_from_list.
	(expand_static_init): Adjust build_compound_expr call.
	(cxx_maybe_build_cleanup): Likewise.
	* init.c (perform_member_init): Use
	build_x_compound_expr_from_list.
	(build_new_1): Likewise.
	(build_vec_delete): Adjust build_compound_expr calls.
	(build_vbase_delete): Likewise.
	* typeck2.c (store_init_value): Use
	build_x_compound_expr_from_list.
	(build_functional_cast): Likewise.

From-SVN: r69794
This commit is contained in:
Nathan Sidwell 2003-07-25 16:52:47 +00:00 committed by Nathan Sidwell
parent 42eaed4985
commit c7b62f1472
6 changed files with 96 additions and 135 deletions

View File

@ -1,3 +1,24 @@
2003-07-25 Nathan Sidwell <nathan@codesourcery.com>
* cp-tree.h (build_compound_expr): Take LHS & RHS args.
(build_x_compound_expr_from_list): Declare.
* typeck.c (build_x_compound_expr_from_list): New.
(build_x_compound_expr): Adjust.
(build_compound_expr): Remove unreachable code. Take two
parameters, adjust.
* decl.c (grok_reference_init): Use
build_x_compound_expr_from_list.
(expand_static_init): Adjust build_compound_expr call.
(cxx_maybe_build_cleanup): Likewise.
* init.c (perform_member_init): Use
build_x_compound_expr_from_list.
(build_new_1): Likewise.
(build_vec_delete): Adjust build_compound_expr calls.
(build_vbase_delete): Likewise.
* typeck2.c (store_init_value): Use
build_x_compound_expr_from_list.
(build_functional_cast): Likewise.
2003-07-25 Nathan Sidwell <nathan@codesourcery.com>
* cp-tree.h (enum tsubst_flags_t): Add tf_user.

View File

@ -4299,8 +4299,9 @@ extern tree build_x_binary_op (enum tree_code, tree, tree);
extern tree build_x_unary_op (enum tree_code, tree);
extern tree unary_complex_lvalue (enum tree_code, tree);
extern tree build_x_conditional_expr (tree, tree, tree);
extern tree build_x_compound_expr_from_list (tree, const char *);
extern tree build_x_compound_expr (tree, tree);
extern tree build_compound_expr (tree);
extern tree build_compound_expr (tree, tree);
extern tree build_static_cast (tree, tree);
extern tree build_reinterpret_cast (tree, tree);
extern tree build_const_cast (tree, tree);

View File

@ -7199,7 +7199,7 @@ grok_reference_init (tree decl, tree type, tree init)
}
if (TREE_CODE (init) == TREE_LIST)
init = build_compound_expr (init);
init = build_x_compound_expr_from_list (init, "initializer");
if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
init = convert_from_reference (init);
@ -8577,12 +8577,7 @@ expand_static_init (tree decl, tree init)
run until after TEMP is set to 1. */
guard_init = set_guard (guard);
if (assignment)
{
assignment = tree_cons (NULL_TREE, assignment,
build_tree_list (NULL_TREE,
guard_init));
assignment = build_compound_expr (assignment);
}
assignment = build_compound_expr (assignment, guard_init);
else
assignment = guard_init;
finish_expr_stmt (assignment);
@ -14389,8 +14384,7 @@ cxx_maybe_build_cleanup (tree decl)
if (TYPE_USES_VIRTUAL_BASECLASSES (type)
&& ! TYPE_HAS_DESTRUCTOR (type))
rval = build_compound_expr (tree_cons (NULL_TREE, rval,
build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
rval = build_compound_expr (rval, build_vbase_delete (type, decl));
return rval;
}

View File

@ -379,17 +379,9 @@ perform_member_init (tree member, tree init)
pedwarn ("uninitialized reference member `%D'", member);
}
else if (TREE_CODE (init) == TREE_LIST)
{
/* There was an explicit member initialization. Do some
work in that case. */
if (TREE_CHAIN (init))
{
warning ("initializer list treated as compound expression");
init = build_compound_expr (init);
}
else
init = TREE_VALUE (init);
}
/* There was an explicit member initialization. Do some work
in that case. */
init = build_x_compound_expr_from_list (init, "member initializer");
if (init)
finish_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
@ -2110,12 +2102,8 @@ build_new_1 (tree exp)
means allocate an int, and initialize it with 10. */
if (TREE_CODE (init) == TREE_LIST)
{
if (TREE_CHAIN (init) != NULL_TREE)
pedwarn
("initializer list being treated as compound expression");
init = build_compound_expr (init);
}
init = build_x_compound_expr_from_list (init, "new initializer");
else if (TREE_CODE (init) == CONSTRUCTOR
&& TREE_TYPE (init) == NULL_TREE)
{
@ -2250,7 +2238,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
tree body;
/* This is the LOOP_EXPR that governs the deletion of the elements. */
tree loop;
tree loop = 0;
/* This is the thing that governs what to do after the loop has run. */
tree deallocate_expr = 0;
@ -2266,10 +2254,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
abort ();
if (! IS_AGGR_TYPE (type) || TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
{
loop = integer_zero_node;
goto no_destructor;
}
goto no_destructor;
/* The below is short by the cookie size. */
virtual_size = size_binop (MULT_EXPR, size_exp,
@ -2284,32 +2269,21 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
controller = build (BIND_EXPR, void_type_node, tbase, NULL_TREE, NULL_TREE);
TREE_SIDE_EFFECTS (controller) = 1;
body = NULL_TREE;
body = build (EXIT_EXPR, void_type_node,
build (EQ_EXPR, boolean_type_node, base, tbase));
body = build_compound_expr
(body, build_modify_expr (tbase, NOP_EXPR,
build (MINUS_EXPR, ptype, tbase, size_exp)));
body = build_compound_expr
(body, build_delete (ptype, tbase, sfk_complete_destructor,
LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1));
body = tree_cons (NULL_TREE,
build_delete (ptype, tbase, sfk_complete_destructor,
LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1),
body);
body = tree_cons (NULL_TREE,
build_modify_expr (tbase, NOP_EXPR, build (MINUS_EXPR, ptype, tbase, size_exp)),
body);
body = tree_cons (NULL_TREE,
build (EXIT_EXPR, void_type_node,
build (EQ_EXPR, boolean_type_node, base, tbase)),
body);
loop = build (LOOP_EXPR, void_type_node, build_compound_expr (body));
loop = tree_cons (NULL_TREE, tbase_init,
tree_cons (NULL_TREE, loop, NULL_TREE));
loop = build_compound_expr (loop);
loop = build (LOOP_EXPR, void_type_node, body);
loop = build_compound_expr (tbase_init, loop);
no_destructor:
/* If the delete flag is one, or anything else with the low bit set,
delete the storage. */
deallocate_expr = integer_zero_node;
if (auto_delete_vec != sfk_base_destructor)
{
tree base_tbd;
@ -2342,15 +2316,17 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
virtual_size);
}
if (loop && deallocate_expr != integer_zero_node)
{
body = tree_cons (NULL_TREE, loop,
tree_cons (NULL_TREE, deallocate_expr, NULL_TREE));
body = build_compound_expr (body);
}
body = loop;
if (!deallocate_expr)
;
else if (!body)
body = deallocate_expr;
else
body = loop;
body = build_compound_expr (body, deallocate_expr);
if (!body)
body = integer_zero_node;
/* Outermost wrapper: If pointer is null, punt. */
body = fold (build (COND_EXPR, void_type_node,
fold (build (NE_EXPR, boolean_type_node, base,
@ -3005,24 +2981,23 @@ tree
build_vbase_delete (tree type, tree decl)
{
tree vbases = CLASSTYPE_VBASECLASSES (type);
tree result = NULL_TREE;
tree result;
tree addr = build_unary_op (ADDR_EXPR, decl, 0);
my_friendly_assert (addr != error_mark_node, 222);
while (vbases)
for (result = convert_to_void (integer_zero_node, NULL);
vbases; vbases = TREE_CHAIN (vbases))
{
tree this_addr
= convert_force (build_pointer_type (BINFO_TYPE (TREE_VALUE (vbases))),
addr, 0);
result = tree_cons (NULL_TREE,
build_delete (TREE_TYPE (this_addr), this_addr,
sfk_base_destructor,
LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0),
result);
vbases = TREE_CHAIN (vbases);
tree base_addr = convert_force
(build_pointer_type (BINFO_TYPE (TREE_VALUE (vbases))), addr, 0);
tree base_delete = build_delete
(TREE_TYPE (base_addr), base_addr, sfk_base_destructor,
LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
result = build_compound_expr (result, base_delete);
}
return build_compound_expr (nreverse (result));
return result;
}
/* Build a C++ vector delete expression.

View File

@ -4264,8 +4264,26 @@ build_x_conditional_expr (tree ifexp, tree op1, tree op2)
return expr;
}
/* Handle overloading of the ',' operator when needed. Otherwise,
this function just builds an expression list. */
/* Given a list of expressions, return a compound expression
that performs them all and returns the value of the last of them. */
tree build_x_compound_expr_from_list (tree list, const char *msg)
{
tree expr = TREE_VALUE (list);
if (TREE_CHAIN (list))
{
if (msg)
pedwarn ("%s expression list treated as compound expression", msg);
for (list = TREE_CHAIN (list); list; list = TREE_CHAIN (list))
expr = build_x_compound_expr (expr, TREE_VALUE (list));
}
return expr;
}
/* Handle overloading of the ',' operator when needed. */
tree
build_x_compound_expr (tree op1, tree op2)
@ -4298,10 +4316,7 @@ build_x_compound_expr (tree op1, tree op2)
&& VOID_TYPE_P (TREE_TYPE (op1))))
warning("left-hand operand of comma expression has no effect");
}
result = build_compound_expr (tree_cons (NULL_TREE,
op1,
build_tree_list (NULL_TREE,
op2)));
result = build_compound_expr (op1, op2);
}
if (processing_template_decl && result != error_mark_node)
@ -4310,42 +4325,17 @@ build_x_compound_expr (tree op1, tree op2)
return result;
}
/* Given a list of expressions, return a compound expression
that performs them all and returns the value of the last of them. */
/* Build a compound expression. */
tree
build_compound_expr (tree list)
build_compound_expr (tree lhs, tree rhs)
{
register tree rest;
tree first;
TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
if (TREE_CHAIN (list) == 0)
{
/* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
if (TREE_CODE (list) == NOP_EXPR
&& TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
list = TREE_OPERAND (list, 0);
return TREE_VALUE (list);
}
first = TREE_VALUE (list);
first = convert_to_void (first, "left-hand operand of comma");
if (first == error_mark_node)
lhs = decl_constant_value (lhs);
lhs = convert_to_void (lhs, "left-hand operand of comma");
if (lhs == error_mark_node || rhs == error_mark_node)
return error_mark_node;
rest = build_compound_expr (TREE_CHAIN (list));
if (rest == error_mark_node)
return error_mark_node;
/* When pedantic, a compound expression cannot be a constant expression. */
if (! TREE_SIDE_EFFECTS (first) && ! pedantic)
return rest;
return build (COMPOUND_EXPR, TREE_TYPE (rest), first, rest);
return build (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
}
/* Issue an error message if casting from SRC_TYPE to DEST_TYPE casts

View File

@ -330,15 +330,8 @@ store_init_value (tree decl, tree init)
&& TREE_TYPE (init) != unknown_type_node)
{
if (TREE_CODE (decl) == RESULT_DECL)
{
if (TREE_CHAIN (init))
{
warning ("comma expression used to initialize return value");
init = build_compound_expr (init);
}
else
init = TREE_VALUE (init);
}
init = build_x_compound_expr_from_list (init,
"return value initializer");
else if (TREE_CODE (init) == TREE_LIST
&& TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
{
@ -346,17 +339,8 @@ store_init_value (tree decl, tree init)
return NULL_TREE;
}
else
{
/* We get here with code like `int a (2);' */
if (TREE_CHAIN (init) != NULL_TREE)
{
pedwarn ("initializer list being treated as compound expression");
init = build_compound_expr (init);
}
else
init = TREE_VALUE (init);
}
/* We get here with code like `int a (2);' */
init = build_x_compound_expr_from_list (init, "initializer");
}
/* End of special C++ code. */
@ -1160,11 +1144,7 @@ build_functional_cast (tree exp, tree parms)
if (parms == NULL_TREE)
parms = integer_zero_node;
else
{
if (TREE_CHAIN (parms) != NULL_TREE)
pedwarn ("initializer list being treated as compound expression");
parms = build_compound_expr (parms);
}
parms = build_x_compound_expr_from_list (parms, "functional cast");
return build_c_cast (type, parms);
}