Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eb098bb

Browse files
committedSep 10, 2024·
Deprecate make_and in favour of conjunction(expr, expr)
`make_and` does not necessarily produce an `and_exprt`, so its name is misleading. We already have `conjunction(exprt::operandst)`, and will now have a variant thereof that takes exactly two operands.
1 parent 4ae54e6 commit eb098bb

File tree

6 files changed

+35
-22
lines changed

6 files changed

+35
-22
lines changed
 

Diff for: ‎src/goto-symex/symex_assign.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void symex_assignt::assign_non_struct_symbol(
238238
: assignment_type;
239239

240240
target.assignment(
241-
make_and(state.guard.as_expr(), conjunction(guard)),
241+
conjunction(state.guard.as_expr(), conjunction(guard)),
242242
l2_lhs,
243243
l2_full_lhs,
244244
get_original_name(l2_full_lhs),

Diff for: ‎src/solvers/prop/bdd_expr.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ exprt bdd_exprt::as_expr(
138138
if(r.else_branch().is_complement()) // else is false
139139
{
140140
exprt then_case = as_expr(r.then_branch(), cache);
141-
return make_and(n_expr, then_case);
141+
return conjunction(n_expr, then_case);
142142
}
143143
exprt then_case = as_expr(r.then_branch(), cache);
144144
return make_or(not_exprt(n_expr), then_case);
@@ -149,7 +149,7 @@ exprt bdd_exprt::as_expr(
149149
if(r.then_branch().is_complement()) // then is false
150150
{
151151
exprt else_case = as_expr(r.else_branch(), cache);
152-
return make_and(not_exprt(n_expr), else_case);
152+
return conjunction(not_exprt(n_expr), else_case);
153153
}
154154
exprt else_case = as_expr(r.else_branch(), cache);
155155
return make_or(n_expr, else_case);

Diff for: ‎src/util/expr_util.cpp

+1-19
Original file line numberDiff line numberDiff line change
@@ -346,25 +346,7 @@ constant_exprt make_boolean_expr(bool value)
346346

347347
exprt make_and(exprt a, exprt b)
348348
{
349-
PRECONDITION(a.is_boolean() && b.is_boolean());
350-
if(b.is_constant())
351-
{
352-
if(b.get(ID_value) == ID_false)
353-
return false_exprt{};
354-
return a;
355-
}
356-
if(a.is_constant())
357-
{
358-
if(a.get(ID_value) == ID_false)
359-
return false_exprt{};
360-
return b;
361-
}
362-
if(b.id() == ID_and)
363-
{
364-
b.add_to_operands(std::move(a));
365-
return b;
366-
}
367-
return and_exprt{std::move(a), std::move(b)};
349+
return conjunction(a, b);
368350
}
369351

370352
bool is_null_pointer(const constant_exprt &expr)

Diff for: ‎src/util/expr_util.h

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ constant_exprt make_boolean_expr(bool);
111111
/// Conjunction of two expressions. If the second is already an `and_exprt`
112112
/// add to its operands instead of creating a new expression. If one is `true`,
113113
/// return the other expression. If one is `false` returns `false`.
114+
DEPRECATED(SINCE(2024, 9, 10, "use conjunction(exprt, exprt) instead"))
114115
exprt make_and(exprt a, exprt b);
115116

116117
/// Returns true if \p expr has a pointer type and a value NULL; it also returns

Diff for: ‎src/util/std_expr.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,37 @@ exprt disjunction(const exprt::operandst &op)
6363
}
6464
}
6565

66+
exprt conjunction(exprt a, exprt b)
67+
{
68+
PRECONDITION(a.is_boolean() && b.is_boolean());
69+
if(b.is_constant())
70+
{
71+
if(to_constant_expr(b).is_false())
72+
return false_exprt{};
73+
return a;
74+
}
75+
if(a.is_constant())
76+
{
77+
if(to_constant_expr(a).is_false())
78+
return false_exprt{};
79+
return b;
80+
}
81+
if(b.id() == ID_and)
82+
{
83+
b.add_to_operands(std::move(a));
84+
return b;
85+
}
86+
return and_exprt{std::move(a), std::move(b)};
87+
}
88+
6689
exprt conjunction(const exprt::operandst &op)
6790
{
6891
if(op.empty())
6992
return true_exprt();
7093
else if(op.size()==1)
7194
return op.front();
95+
else if(op.size() == 2)
96+
return conjunction(op[0], op[1]);
7297
else
7398
{
7499
return and_exprt(exprt::operandst(op));

Diff for: ‎src/util/std_expr.h

+5
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,11 @@ class and_exprt:public multi_ary_exprt
21522152

21532153
exprt conjunction(const exprt::operandst &);
21542154

2155+
/// Conjunction of two expressions. If the second is already an `and_exprt`
2156+
/// add to its operands instead of creating a new expression. If one is `true`,
2157+
/// return the other expression. If one is `false` returns `false`.
2158+
exprt conjunction(exprt a, exprt b);
2159+
21552160
template <>
21562161
inline bool can_cast_expr<and_exprt>(const exprt &base)
21572162
{

0 commit comments

Comments
 (0)
Please sign in to comment.