Skip to content

Commit 5f815a7

Browse files
Make make_(free_)bv_expr return exprt
1 parent cc31a9f commit 5f815a7

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

src/cbmc/bv_cbmc.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ bvt bv_cbmct::convert_waitfor(const exprt &expr)
2525
const exprt &cycle_var=expr.op1();
2626
const exprt &bound=expr.op2();
2727
const exprt &predicate=expr.op3();
28-
29-
make_free_bv_expr(expr.type(), new_cycle);
28+
const exprt new_cycle = make_free_bv_expr(expr.type());
3029

3130
mp_integer bound_value;
3231
if(to_integer(bound, bound_value))
@@ -98,18 +97,9 @@ bvt bv_cbmct::convert_waitfor(const exprt &expr)
9897

9998
bvt bv_cbmct::convert_waitfor_symbol(const exprt &expr)
10099
{
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;
100+
PRECONDITION(expr.operands().size() == 1);
109101
const exprt &bound=expr.op0();
110-
111-
make_free_bv_expr(expr.type(), result);
112-
102+
const exprt result = make_free_bv_expr(expr.type());
113103
// constraint: result<=bound
114104

115105
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
@@ -649,35 +649,25 @@ void boolbvt::set_to(const exprt &expr, bool value)
649649
return SUB::set_to(expr, value);
650650
}
651651

652-
void boolbvt::make_bv_expr(const typet &type, const bvt &bv, exprt &dest)
652+
exprt boolbvt::make_bv_expr(const typet &type, const bvt &bv)
653653
{
654-
dest=exprt(ID_bv_literals, type);
654+
exprt dest(ID_bv_literals, type);
655655
irept::subt &bv_sub=dest.add(ID_bv).get_sub();
656-
657656
bv_sub.resize(bv.size());
658657

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

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

683673
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)