Skip to content

Commit 8dde888

Browse files
committed
Deprecate multi-argument variants of exprt::copy_to_operands
add_to_operands or constructors with move semantics are preferable. All existing uses of the newly deprecated methods have been reworked to use non-deprecated methods. Fixes: #2809
1 parent 352be59 commit 8dde888

File tree

9 files changed

+31
-45
lines changed

9 files changed

+31
-45
lines changed

jbmc/src/java_bytecode/remove_java_new.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
280280
const auto zero_element =
281281
zero_initializer(data.type().subtype(), location, ns);
282282
CHECK_RETURN(zero_element.has_value());
283-
codet array_set(ID_array_set);
284-
array_set.copy_to_operands(new_array_data_symbol, *zero_element);
283+
codet array_set{ID_array_set, {new_array_data_symbol, *zero_element}};
285284
dest.insert_before(next, goto_programt::make_other(array_set, location));
286285
}
287286

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,8 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
10351035
// It is not obvious whether the type or 'e' should be evaluated
10361036
// first.
10371037

1038-
exprt comma_expr(ID_comma, expr.type());
1039-
comma_expr.copy_to_operands(side_effect_expr, expr);
1038+
binary_exprt comma_expr{
1039+
std::move(side_effect_expr), ID_comma, expr, expr.type()};
10401040
expr.swap(comma_expr);
10411041
}
10421042
}
@@ -1085,8 +1085,8 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr)
10851085
// It is not obvious whether the type or 'e' should be evaluated
10861086
// first.
10871087

1088-
exprt comma_expr(ID_comma, op.type());
1089-
comma_expr.copy_to_operands(side_effect_expr, op);
1088+
binary_exprt comma_expr{
1089+
std::move(side_effect_expr), ID_comma, op, op.type()};
10901090
op.swap(comma_expr);
10911091
}
10921092

src/goto-programs/builtin_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void goto_convertt::do_prob_uniform(
100100
throw 0;
101101
}
102102

103-
rhs.copy_to_operands(arguments[0], arguments[1]);
103+
rhs.add_to_operands(exprt{arguments[0]}, exprt{arguments[1]});
104104

105105
code_assignt assignment(lhs, rhs);
106106
assignment.add_source_location()=function.source_location();

src/goto-programs/goto_convert_side_effect.cpp

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,23 @@ void goto_convertt::remove_assignment(
112112
UNREACHABLE;
113113
}
114114

115-
exprt rhs;
116-
117-
const typet &op0_type = to_binary_expr(expr).op0().type();
115+
const binary_exprt &binary_expr = to_binary_expr(expr);
116+
const typet &op0_type = binary_expr.op0().type();
118117

119118
PRECONDITION(
120119
op0_type.id() != ID_c_enum_tag && op0_type.id() != ID_c_enum &&
121120
op0_type.id() != ID_c_bool && op0_type.id() != ID_bool);
122121

123-
rhs.id(new_id);
124-
rhs.copy_to_operands(
125-
to_binary_expr(expr).op0(), to_binary_expr(expr).op1());
126-
rhs.type() = to_binary_expr(expr).op0().type();
122+
exprt rhs = binary_exprt{binary_expr.op0(), new_id, binary_expr.op1()};
127123
rhs.add_source_location() = expr.source_location();
128124

129-
if(
130-
result_is_used && !address_taken &&
131-
needs_cleaning(to_binary_expr(expr).op0()))
125+
if(result_is_used && !address_taken && needs_cleaning(binary_expr.op0()))
132126
{
133127
make_temp_symbol(rhs, "assign", dest, mode);
134128
replacement_expr_opt = rhs;
135129
}
136130

137-
exprt new_lhs = skip_typecast(to_binary_expr(expr).op0());
131+
exprt new_lhs = skip_typecast(binary_expr.op0());
138132
rhs = typecast_exprt::conditional_cast(rhs, new_lhs.type());
139133
rhs.add_source_location() = expr.source_location();
140134
code_assignt assignment(new_lhs, rhs);
@@ -196,14 +190,6 @@ void goto_convertt::remove_pre(
196190
statement == ID_preincrement || statement == ID_predecrement,
197191
"expects preincrement or predecrement");
198192

199-
exprt rhs;
200-
rhs.add_source_location()=expr.source_location();
201-
202-
if(statement==ID_preincrement)
203-
rhs.id(ID_plus);
204-
else
205-
rhs.id(ID_minus);
206-
207193
const auto &op = to_unary_expr(expr).op();
208194
const typet &op_type = op.type();
209195

@@ -233,8 +219,9 @@ void goto_convertt::remove_pre(
233219
else
234220
constant = from_integer(1, constant_type);
235221

236-
rhs.add_to_operands(op, std::move(constant));
237-
rhs.type() = op.type();
222+
exprt rhs = binary_exprt{
223+
op, statement == ID_preincrement ? ID_plus : ID_minus, std::move(constant)};
224+
rhs.add_source_location() = expr.source_location();
238225

239226
const bool cannot_use_lhs =
240227
result_is_used && !address_taken && needs_cleaning(op);
@@ -282,14 +269,6 @@ void goto_convertt::remove_post(
282269
statement == ID_postincrement || statement == ID_postdecrement,
283270
"expects postincrement or postdecrement");
284271

285-
exprt rhs;
286-
rhs.add_source_location()=expr.source_location();
287-
288-
if(statement==ID_postincrement)
289-
rhs.id(ID_plus);
290-
else
291-
rhs.id(ID_minus);
292-
293272
const auto &op = to_unary_expr(expr).op();
294273
const typet &op_type = op.type();
295274

@@ -319,8 +298,11 @@ void goto_convertt::remove_post(
319298
else
320299
constant = from_integer(1, constant_type);
321300

322-
rhs.add_to_operands(op, std::move(constant));
323-
rhs.type() = op.type();
301+
binary_exprt rhs{
302+
op,
303+
statement == ID_postincrement ? ID_plus : ID_minus,
304+
std::move(constant)};
305+
rhs.add_source_location() = expr.source_location();
324306

325307
code_assignt assignment(op, rhs);
326308
assignment.add_source_location()=expr.find_source_location();

src/jsil/jsil_convert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ bool jsil_convertt::convert_code(const symbolt &symbol, codet &code)
9393
code_try_catcht t_c(std::move(t));
9494
// Adding empty symbol to catch decl
9595
code_frontend_declt d(symbol_exprt::typeless("decl_symbol"));
96-
t_c.add_catch(d, g);
96+
t_c.add_catch(std::move(d), std::move(g));
9797
t_c.add_source_location()=code.source_location();
9898

9999
code.swap(t_c);

src/solvers/flattening/boolbv_get.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ exprt boolbvt::bv_get_unbounded_array(const exprt &expr) const
356356
it++)
357357
{
358358
exprt index=from_integer(it->first, size.type());
359-
result.copy_to_operands(index, it->second);
359+
result.add_to_operands(std::move(index), exprt{it->second});
360360
}
361361
}
362362
else

src/solvers/lowering/byte_operators.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ static exprt lower_byte_update_byte_array_vector(
14081408
{
14091409
const exprt &element = value_as_byte_array.operands()[i];
14101410

1411-
const exprt where = simplify_expr(
1411+
exprt where = simplify_expr(
14121412
plus_exprt{src.offset(), from_integer(i, src.offset().type())}, ns);
14131413

14141414
// skip elements that wouldn't change (skip over typecasts as we might have
@@ -1437,9 +1437,9 @@ static exprt lower_byte_update_byte_array_vector(
14371437
update_value = typecast_exprt::conditional_cast(element, subtype);
14381438

14391439
if(result.id() != ID_with)
1440-
result = with_exprt{result, where, update_value};
1440+
result = with_exprt{result, std::move(where), std::move(update_value)};
14411441
else
1442-
result.add_to_operands(where, update_value);
1442+
result.add_to_operands(std::move(where), std::move(update_value));
14431443
}
14441444

14451445
return simplify_expr(std::move(result), ns);

src/util/expr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010
#define CPROVER_UTIL_EXPR_H
1111

1212
#include "as_const.h"
13+
#include "deprecate.h"
1314
#include "type.h"
1415
#include "validate_expressions.h"
1516
#include "validate_types.h"
@@ -148,6 +149,7 @@ class exprt:public irept
148149
/// Copy the given arguments to the end of `exprt`'s operands.
149150
/// \param e1: first `exprt` to append to the operands
150151
/// \param e2: second `exprt` to append to the operands
152+
DEPRECATED(SINCE(2022, 2, 15, "use add_to_operands(&&, &&) instead"))
151153
void copy_to_operands(const exprt &e1, const exprt &e2)
152154
{
153155
operandst &op = operands();
@@ -161,6 +163,7 @@ class exprt:public irept
161163
/// Add the given arguments to the end of `exprt`'s operands.
162164
/// \param e1: first `exprt` to append to the operands
163165
/// \param e2: second `exprt` to append to the operands
166+
DEPRECATED(SINCE(2022, 2, 15, "use add_to_operands(&&, &&) instead"))
164167
void add_to_operands(const exprt &e1, const exprt &e2)
165168
{
166169
copy_to_operands(e1, e2);
@@ -183,6 +186,7 @@ class exprt:public irept
183186
/// \param e1: first `exprt` to append to the operands
184187
/// \param e2: second `exprt` to append to the operands
185188
/// \param e3: third `exprt` to append to the operands
189+
DEPRECATED(SINCE(2022, 2, 15, "use add_to_operands(&&, &&, &&) instead"))
186190
void add_to_operands(const exprt &e1, const exprt &e2, const exprt &e3)
187191
{
188192
copy_to_operands(e1, e2, e3);
@@ -192,6 +196,7 @@ class exprt:public irept
192196
/// \param e1: first `exprt` to append to the operands
193197
/// \param e2: second `exprt` to append to the operands
194198
/// \param e3: third `exprt` to append to the operands
199+
DEPRECATED(SINCE(2022, 2, 15, "use add_to_operands(&&, &&, &&) instead"))
195200
void copy_to_operands(const exprt &e1, const exprt &e2, const exprt &e3)
196201
{
197202
operandst &op = operands();

src/util/std_code.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,9 +2025,9 @@ class code_try_catcht:public codet
20252025
return to_code(operands()[2*i+2]);
20262026
}
20272027

2028-
void add_catch(const code_frontend_declt &to_catch, const codet &code_catch)
2028+
void add_catch(code_frontend_declt &&to_catch, codet &&code_catch)
20292029
{
2030-
add_to_operands(to_catch, code_catch);
2030+
add_to_operands(std::move(to_catch), std::move(code_catch));
20312031
}
20322032

20332033
protected:

0 commit comments

Comments
 (0)