Skip to content

Commit a4c39a3

Browse files
committed
Use lambda_exprt
The API increases the readability of the code and also enables early checking for valid expression structure.
1 parent 3b062c6 commit a4c39a3

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

src/solvers/flattening/boolbv.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
294294
else if(expr.id()==ID_complex_imag)
295295
return convert_complex_imag(to_complex_imag_expr(expr));
296296
else if(expr.id()==ID_lambda)
297-
return convert_lambda(expr);
297+
return convert_lambda(to_lambda_expr(expr));
298298
else if(expr.id()==ID_array_of)
299299
return convert_array_of(to_array_of_expr(expr));
300300
else if(expr.id()==ID_let)
@@ -316,28 +316,21 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
316316
return conversion_failed(expr);
317317
}
318318

319-
bvt boolbvt::convert_lambda(const exprt &expr)
319+
bvt boolbvt::convert_lambda(const lambda_exprt &expr)
320320
{
321321
std::size_t width=boolbv_width(expr.type());
322322

323323
if(width==0)
324324
return conversion_failed(expr);
325325

326-
DATA_INVARIANT(
327-
expr.operands().size() == 2, "lambda expression should have two operands");
328-
329-
if(expr.type().id()!=ID_array)
330-
return conversion_failed(expr);
331-
332-
const exprt &array_size=
333-
to_array_type(expr.type()).size();
326+
const exprt &array_size = expr.type().size();
334327

335328
const auto size = numeric_cast<mp_integer>(array_size);
336329

337330
if(!size.has_value())
338331
return conversion_failed(expr);
339332

340-
typet counter_type=expr.op0().type();
333+
typet counter_type = expr.arg().type();
341334

342335
bvt bv;
343336
bv.resize(width);
@@ -346,10 +339,10 @@ bvt boolbvt::convert_lambda(const exprt &expr)
346339
{
347340
exprt counter=from_integer(i, counter_type);
348341

349-
exprt expr_op1(expr.op1());
350-
replace_expr(expr.op0(), counter, expr_op1);
342+
exprt body = expr.body();
343+
replace_expr(expr.arg(), counter, body);
351344

352-
const bvt &tmp=convert_bv(expr_op1);
345+
const bvt &tmp = convert_bv(body);
353346

354347
INVARIANT(
355348
*size * tmp.size() == width,

src/solvers/flattening/boolbv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Author: Daniel Kroening, [email protected]
2828

2929
class extractbit_exprt;
3030
class extractbits_exprt;
31+
class lambda_exprt;
3132
class member_exprt;
3233

3334
class boolbvt:public arrayst
@@ -148,7 +149,7 @@ class boolbvt:public arrayst
148149
virtual bvt convert_complex(const complex_exprt &expr);
149150
virtual bvt convert_complex_real(const complex_real_exprt &expr);
150151
virtual bvt convert_complex_imag(const complex_imag_exprt &expr);
151-
virtual bvt convert_lambda(const exprt &expr);
152+
virtual bvt convert_lambda(const lambda_exprt &expr);
152153
virtual bvt convert_let(const let_exprt &);
153154
virtual bvt convert_array_of(const array_of_exprt &expr);
154155
virtual bvt convert_union(const union_exprt &expr);

src/util/simplify_expr_array.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,12 @@ bool simplify_exprt::simplify_index(exprt &expr)
4848
{
4949
// simplify (lambda i: e)(x) to e[i/x]
5050

51-
const exprt &lambda_expr=array;
51+
const lambda_exprt &lambda_expr = to_lambda_expr(array);
5252

53-
if(lambda_expr.operands().size()!=2)
54-
return true;
55-
56-
if(expr.op1().type()==lambda_expr.op0().type())
53+
if(expr.op1().type() == lambda_expr.arg().type())
5754
{
58-
exprt tmp=lambda_expr.op1();
59-
replace_expr(lambda_expr.op0(), expr.op1(), tmp);
55+
exprt tmp = lambda_expr.body();
56+
replace_expr(lambda_expr.arg(), expr.op1(), tmp);
6057
expr.swap(tmp);
6158
return false;
6259
}

0 commit comments

Comments
 (0)