Skip to content

Commit 91614ee

Browse files
Refactoring in boolbvt::convert_array
1 parent 824b51d commit 91614ee

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

src/solvers/flattening/arrays.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void arrayst::record_array_index(const index_exprt &index)
3434
// we are not allowed to put the index directly in the
3535
// entry for the root of the equivalence class
3636
// because this map is accessed during building the error trace
37-
std::size_t number=arrays.number(index.array());
37+
const std::size_t number = arrays.number(index.array());
3838
index_map[number].insert(index.index());
3939
update_indices.insert(number);
4040
}
@@ -45,14 +45,9 @@ literalt arrayst::record_array_equality(
4545
const exprt &op0=equality.op0();
4646
const exprt &op1=equality.op1();
4747

48-
// check types
49-
if(!base_type_eq(op0.type(), op1.type(), ns))
50-
{
51-
prop.error() << equality.pretty() << messaget::eom;
52-
DATA_INVARIANT(
53-
false,
54-
"record_array_equality got equality without matching types");
55-
}
48+
DATA_INVARIANT(
49+
base_type_eq(op0.type(), op1.type(), ns),
50+
"record_array_equality should get matching types");
5651

5752
DATA_INVARIANT(
5853
ns.follow(op0.type()).id()==ID_array,

src/solvers/flattening/boolbv_array.cpp

+7-16
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,30 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
109
#include "boolbv.h"
1110

1211
bvt boolbvt::convert_array(const exprt &expr)
1312
{
14-
std::size_t width=boolbv_width(expr.type());
15-
13+
const std::size_t width = boolbv_width(expr.type());
1614
if(width==0)
1715
return conversion_failed(expr);
1816

1917
if(expr.type().id()==ID_array)
2018
{
21-
assert(expr.has_operands());
19+
INVARIANT(expr.has_operands(), "array should have operands");
2220
const exprt::operandst &operands=expr.operands();
23-
assert(!operands.empty());
24-
std::size_t op_width=width/operands.size();
25-
21+
const std::size_t op_width = width / operands.size();
2622
bvt bv;
2723
bv.reserve(width);
2824

29-
forall_expr(it, operands)
25+
for(const exprt &op : operands)
3026
{
31-
const bvt &tmp=convert_bv(*it);
32-
33-
if(tmp.size()!=op_width)
34-
throw "convert_array: unexpected operand width";
35-
36-
forall_literals(it2, tmp)
37-
bv.push_back(*it2);
27+
const bvt &tmp = convert_bv(op);
28+
CHECK_RETURN(tmp.size() == op_width);
29+
bv.insert(bv.end(), tmp.begin(), tmp.end());
3830
}
3931

4032
return bv;
4133
}
42-
4334
return conversion_failed(expr);
4435
}

0 commit comments

Comments
 (0)