Skip to content

Commit b18109f

Browse files
Make make_(free_)bv_expr return exprt
1 parent 5724a35 commit b18109f

File tree

3 files changed

+15
-36
lines changed

3 files changed

+15
-36
lines changed

src/cbmc/bv_cbmc.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ bvt bv_cbmct::convert_waitfor(const exprt &expr)
2020
throw 0;
2121
}
2222

23-
exprt new_cycle;
2423
const exprt &old_cycle=expr.op0();
2524
const exprt &cycle_var=expr.op1();
2625
const exprt &bound=expr.op2();
2726
const exprt &predicate=expr.op3();
28-
29-
make_free_bv_expr(expr.type(), new_cycle);
27+
const exprt new_cycle = make_free_bv_expr(expr.type());
3028

3129
mp_integer bound_value;
3230
if(to_integer(bound, bound_value))
@@ -98,18 +96,9 @@ bvt bv_cbmct::convert_waitfor(const exprt &expr)
9896

9997
bvt bv_cbmct::convert_waitfor_symbol(const exprt &expr)
10098
{
101-
if(expr.operands().size()!=1)
102-
{
103-
error().source_location=expr.find_source_location();
104-
error() << "waitfor_symbol expected to have one operand" << eom;
105-
throw 0;
106-
}
107-
108-
exprt result;
99+
PRECONDITION(expr.operands().size() == 1);
109100
const exprt &bound=expr.op0();
110-
111-
make_free_bv_expr(expr.type(), result);
112-
101+
const exprt result = make_free_bv_expr(expr.type());
113102
// constraint: result<=bound
114103

115104
set_to_true(binary_relation_exprt(result, ID_le, bound));

src/solvers/flattening/boolbv.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -650,35 +650,25 @@ void boolbvt::set_to(const exprt &expr, bool value)
650650
return SUB::set_to(expr, value);
651651
}
652652

653-
void boolbvt::make_bv_expr(const typet &type, const bvt &bv, exprt &dest)
653+
exprt boolbvt::make_bv_expr(const typet &type, const bvt &bv)
654654
{
655-
dest=exprt(ID_bv_literals, type);
655+
exprt dest(ID_bv_literals, type);
656656
irept::subt &bv_sub=dest.add(ID_bv).get_sub();
657-
658657
bv_sub.resize(bv.size());
659658

660659
for(std::size_t i=0; i<bv.size(); i++)
661660
bv_sub[i].id(std::to_string(bv[i].get()));
661+
return dest;
662662
}
663663

664-
void boolbvt::make_free_bv_expr(const typet &type, exprt &dest)
664+
exprt boolbvt::make_free_bv_expr(const typet &type)
665665
{
666-
std::size_t width=boolbv_width(type);
667-
668-
if(width==0)
669-
{
670-
error() << "failed to get width of " << type.pretty() << eom;
671-
throw 0;
672-
}
673-
674-
bvt bv;
675-
bv.resize(width);
676-
677-
// make result free variables
678-
Forall_literals(it, bv)
679-
*it=prop.new_variable();
680-
681-
make_bv_expr(type, bv, dest);
666+
const std::size_t width = boolbv_width(type);
667+
PRECONDITION(width != 0);
668+
bvt bv(width);
669+
for(auto &lit : bv)
670+
lit = prop.new_variable();
671+
return make_bv_expr(type, bv);
682672
}
683673

684674
bool boolbvt::is_unbounded_array(const typet &type) const

src/solvers/flattening/boolbv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ class boolbvt:public arrayst
176176
virtual bvt convert_function_application(
177177
const function_application_exprt &expr);
178178

179-
virtual void make_bv_expr(const typet &type, const bvt &bv, exprt &dest);
180-
virtual void make_free_bv_expr(const typet &type, exprt &dest);
179+
virtual exprt make_bv_expr(const typet &type, const bvt &bv);
180+
virtual exprt make_free_bv_expr(const typet &type);
181181

182182
void convert_with(
183183
const typet &type,

0 commit comments

Comments
 (0)