Skip to content

Commit 9f06b86

Browse files
authored
Merge pull request #4683 from antlechner/antonia/rename-lambda
Rename lambda_exprt to array_comprehension_exprt
2 parents 7ededfc + cd52307 commit 9f06b86

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

src/solvers/flattening/boolbv.cpp

Lines changed: 2 additions & 2 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(to_lambda_expr(expr));
297+
return convert_lambda(to_array_comprehension_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,7 +316,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
316316
return conversion_failed(expr);
317317
}
318318

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

src/solvers/flattening/boolbv.h

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

2929
class extractbit_exprt;
3030
class extractbits_exprt;
31-
class lambda_exprt;
31+
class array_comprehension_exprt;
3232
class member_exprt;
3333

3434
class boolbvt:public arrayst
@@ -149,7 +149,7 @@ class boolbvt:public arrayst
149149
virtual bvt convert_complex(const complex_exprt &expr);
150150
virtual bvt convert_complex_real(const complex_real_exprt &expr);
151151
virtual bvt convert_complex_imag(const complex_imag_exprt &expr);
152-
virtual bvt convert_lambda(const lambda_exprt &expr);
152+
virtual bvt convert_lambda(const array_comprehension_exprt &expr);
153153
virtual bvt convert_let(const let_exprt &);
154154
virtual bvt convert_array_of(const array_of_exprt &expr);
155155
virtual bvt convert_union(const union_exprt &expr);

src/util/simplify_expr_array.cpp

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

51-
const lambda_exprt &lambda_expr = to_lambda_expr(array);
51+
const auto &comprehension = to_array_comprehension_expr(array);
5252

53-
if(expr.op1().type() == lambda_expr.arg().type())
53+
if(expr.op1().type() == comprehension.arg().type())
5454
{
55-
exprt tmp = lambda_expr.body();
56-
replace_expr(lambda_expr.arg(), expr.op1(), tmp);
55+
exprt tmp = comprehension.body();
56+
replace_expr(comprehension.arg(), expr.op1(), tmp);
5757
expr.swap(tmp);
5858
simplify_rec(expr);
5959
return false;

src/util/std_expr.h

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4462,10 +4462,21 @@ inline cond_exprt &to_cond_expr(exprt &expr)
44624462

44634463
/// \brief Expression to define a mapping from an argument (index) to elements.
44644464
/// This enables constructing an array via an anonymous function.
4465-
class lambda_exprt : public binary_exprt
4465+
/// Not all kinds of array comprehension can be expressed, only those of the
4466+
/// form `[f(x) | x in {0, 1, ... array_size-1}]`.
4467+
/// The LHS and RHS are the argument (`x`) and body (`f(x)`) of the anonymous
4468+
/// function, respectively. The range is given by the type of the expression,
4469+
/// which has to be an \ref array_typet (which includes a value for
4470+
/// `array_size`).
4471+
/// For legacy reasons, the ID of an array_comprehension_exprt is ID_lambda,
4472+
/// even though it cannot be used to represent arbitrary lambda functions.
4473+
class array_comprehension_exprt : public binary_exprt
44664474
{
44674475
public:
4468-
explicit lambda_exprt(symbol_exprt arg, exprt body, array_typet _type)
4476+
explicit array_comprehension_exprt(
4477+
symbol_exprt arg,
4478+
exprt body,
4479+
array_typet _type)
44694480
: binary_exprt(std::move(arg), ID_lambda, std::move(body), std::move(_type))
44704481
{
44714482
}
@@ -4502,35 +4513,38 @@ class lambda_exprt : public binary_exprt
45024513
};
45034514

45044515
template <>
4505-
inline bool can_cast_expr<lambda_exprt>(const exprt &base)
4516+
inline bool can_cast_expr<array_comprehension_exprt>(const exprt &base)
45064517
{
45074518
return base.id() == ID_lambda;
45084519
}
45094520

4510-
inline void validate_expr(const lambda_exprt &value)
4521+
inline void validate_expr(const array_comprehension_exprt &value)
45114522
{
4512-
validate_operands(value, 2, "'Lambda' must have two operands");
4523+
validate_operands(value, 2, "'Array comprehension' must have two operands");
45134524
}
45144525

4515-
/// \brief Cast an exprt to a \ref lambda_exprt
4526+
/// \brief Cast an exprt to a \ref array_comprehension_exprt
45164527
///
4517-
/// \a expr must be known to be \ref lambda_exprt.
4528+
/// \a expr must be known to be \ref array_comprehension_exprt.
45184529
///
45194530
/// \param expr: Source expression
4520-
/// \return Object of type \ref lambda_exprt
4521-
inline const lambda_exprt &to_lambda_expr(const exprt &expr)
4531+
/// \return Object of type \ref array_comprehension_exprt
4532+
inline const array_comprehension_exprt &
4533+
to_array_comprehension_expr(const exprt &expr)
45224534
{
45234535
PRECONDITION(expr.id() == ID_lambda);
4524-
const lambda_exprt &ret = static_cast<const lambda_exprt &>(expr);
4536+
const array_comprehension_exprt &ret =
4537+
static_cast<const array_comprehension_exprt &>(expr);
45254538
validate_expr(ret);
45264539
return ret;
45274540
}
45284541

4529-
/// \copydoc to_lambda_expr(const exprt &)
4530-
inline lambda_exprt &to_lambda_expr(exprt &expr)
4542+
/// \copydoc to_array_comprehension_expr(const exprt &)
4543+
inline array_comprehension_exprt &to_array_comprehension_expr(exprt &expr)
45314544
{
45324545
PRECONDITION(expr.id() == ID_lambda);
4533-
lambda_exprt &ret = static_cast<lambda_exprt &>(expr);
4546+
array_comprehension_exprt &ret =
4547+
static_cast<array_comprehension_exprt &>(expr);
45344548
validate_expr(ret);
45354549
return ret;
45364550
}

0 commit comments

Comments
 (0)