Skip to content

Commit 74ffcda

Browse files
Refactoring in boolbvt::convert_array_of
1 parent 91614ee commit 74ffcda

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/solvers/flattening/boolbv_array_of.cpp

+5-14
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ Author: Daniel Kroening, [email protected]
1313

1414
bvt boolbvt::convert_array_of(const array_of_exprt &expr)
1515
{
16-
if(expr.type().id()!=ID_array)
17-
throw "array_of must be array-typed";
18-
1916
const array_typet &array_type=to_array_type(expr.type());
20-
2117
if(is_unbounded_array(array_type))
2218
return conversion_failed(expr);
2319

24-
std::size_t width=boolbv_width(array_type);
25-
20+
const std::size_t width = boolbv_width(array_type);
2621
if(width==0)
2722
{
2823
// A zero-length array is acceptable;
@@ -34,29 +29,25 @@ bvt boolbvt::convert_array_of(const array_of_exprt &expr)
3429
}
3530

3631
const exprt &array_size=array_type.size();
32+
const auto size = numeric_cast<mp_integer>(array_size);
3733

38-
mp_integer size;
39-
40-
if(to_integer(array_size, size))
34+
if(!size)
4135
return conversion_failed(expr);
4236

4337
const bvt &tmp=convert_bv(expr.op0());
4438

4539
bvt bv;
4640
bv.resize(width);
47-
48-
if(size*tmp.size()!=width)
49-
throw "convert_array_of: unexpected operand width";
41+
CHECK_RETURN(*size * tmp.size() == width);
5042

5143
std::size_t offset=0;
52-
5344
for(mp_integer i=0; i<size; i=i+1)
5445
{
5546
for(std::size_t j=0; j<tmp.size(); j++, offset++)
5647
bv[offset]=tmp[j];
5748
}
5849

59-
assert(offset==bv.size());
50+
INVARIANT(offset == bv.size(), "final offset should correspond to size");
6051

6152
return bv;
6253
}

0 commit comments

Comments
 (0)