13
13
14
14
bvt boolbvt::convert_array_of (const array_of_exprt &expr)
15
15
{
16
- if (expr.type ().id ()!=ID_array)
17
- throw " array_of must be array-typed" ;
18
-
19
16
const array_typet &array_type=to_array_type (expr.type ());
20
-
21
17
if (is_unbounded_array (array_type))
22
18
return conversion_failed (expr);
23
19
24
- std::size_t width=boolbv_width (array_type);
25
-
20
+ const std::size_t width = boolbv_width (array_type);
26
21
if (width==0 )
27
22
{
28
23
// A zero-length array is acceptable;
@@ -34,29 +29,25 @@ bvt boolbvt::convert_array_of(const array_of_exprt &expr)
34
29
}
35
30
36
31
const exprt &array_size=array_type.size ();
32
+ const auto size = numeric_cast<mp_integer>(array_size);
37
33
38
- mp_integer size;
39
-
40
- if (to_integer (array_size, size))
34
+ if (!size)
41
35
return conversion_failed (expr);
42
36
43
37
const bvt &tmp=convert_bv (expr.op0 ());
44
38
45
39
bvt bv;
46
40
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);
50
42
51
43
std::size_t offset=0 ;
52
-
53
44
for (mp_integer i=0 ; i<size; i=i+1 )
54
45
{
55
46
for (std::size_t j=0 ; j<tmp.size (); j++, offset++)
56
47
bv[offset]=tmp[j];
57
48
}
58
49
59
- assert (offset== bv.size ());
50
+ INVARIANT (offset == bv.size (), " final offset should correspond to size " );
60
51
61
52
return bv;
62
53
}
0 commit comments