Skip to content

Commit c91b88b

Browse files
Replace throws and asserts with invariants in boolbv_index
1 parent 2782fc1 commit c91b88b

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/solvers/flattening/boolbv_index.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,10 @@ bvt boolbvt::convert_index(const index_exprt &expr)
117117

118118
binary_relation_exprt lower_bound(
119119
from_integer(0, index.type()), ID_le, index);
120+
CHECK_RETURN(lower_bound.lhs().is_not_nil());
120121
binary_relation_exprt upper_bound(
121122
index, ID_lt, from_integer(array_size, index.type()));
122-
123-
if(lower_bound.lhs().is_nil() ||
124-
upper_bound.rhs().is_nil())
125-
throw "number conversion failed (2)";
123+
CHECK_RETURN(upper_bound.rhs().is_not_nil());
126124

127125
and_exprt range_condition(lower_bound, upper_bound);
128126
implies_exprt implication(range_condition, value_equality);
@@ -174,11 +172,12 @@ bvt boolbvt::convert_index(const index_exprt &expr)
174172
for(mp_integer i=0; i<array_size; i=i+1)
175173
{
176174
index_equality.rhs()=from_integer(i, index_equality.lhs().type());
175+
CHECK_RETURN(index_equality.rhs().is_not_nil());
177176

178-
if(index_equality.rhs().is_nil())
179-
throw "number conversion failed (1)";
180-
181-
assert(it != array.operands().end());
177+
INVARIANT(
178+
it != array.operands().end(),
179+
"this loop iterates over the array, so `it` shouldn't be increased "
180+
"past the array's end");
182181

183182
value_equality.rhs()=*it++;
184183

@@ -201,9 +200,10 @@ bvt boolbvt::convert_index(const index_exprt &expr)
201200
// get literals for the whole array
202201

203202
const bvt &array_bv=convert_bv(array);
204-
205-
if(array_size*width!=array_bv.size())
206-
throw "unexpected array size";
203+
DATA_INVARIANT(
204+
array_size * width == array_bv.size(),
205+
"the size of an array bitvector is the size of the individual elements "
206+
"times the number of elements");
207207

208208
// TODO: maybe a shifter-like construction would be better
209209
// Would be a lot more compact but propagate worse
@@ -231,9 +231,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)
231231
for(mp_integer i=0; i<array_size; i=i+1)
232232
{
233233
index_equality.rhs()=from_integer(i, index_equality.lhs().type());
234-
235-
if(index_equality.rhs().is_nil())
236-
throw "number conversion failed (1)";
234+
CHECK_RETURN(index_equality.rhs().is_not_nil());
237235

238236
mp_integer offset=i*width;
239237

@@ -258,7 +256,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)
258256

259257
typet constant_type=index.type(); // type of index operand
260258

261-
assert(array_size>0);
259+
DATA_INVARIANT(array_size > 0, "array sizes are expected to be positive");
262260

263261
for(mp_integer i=0; i<array_size; i=i+1)
264262
{

0 commit comments

Comments
 (0)