Skip to content

Commit 9f9f6c0

Browse files
committed
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 8fb79d0 commit 9f9f6c0

File tree

7 files changed

+39
-27
lines changed

7 files changed

+39
-27
lines changed

regression/cbmc-cover/mcdc8/test.desc

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ main.c
33
--cover mcdc
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[main.coverage.1\] file main.c line 9 function main MC/DC independence condition 'c != FALSE && a != FALSE && !\(b != FALSE\).* SATISFIED$
7-
^\[main.coverage.2\] file main.c line 9 function main MC/DC independence condition 'c != FALSE && !\(a != FALSE\) && b != FALSE.* SATISFIED$
8-
^\[main.coverage.3\] file main.c line 9 function main MC/DC independence condition 'c != FALSE && !\(a != FALSE\) && !\(b != FALSE\).* SATISFIED$
9-
^\[main.coverage.4\] file main.c line 9 function main MC/DC independence condition '!\(c != FALSE\) && a != FALSE && !\(b != FALSE\).* SATISFIED$
6+
^\[main.coverage.1\] file main.c line 9 function main MC/DC independence condition 'a != FALSE && !\(b != FALSE\) && c != FALSE: SATISFIED$
7+
^\[main.coverage.2\] file main.c line 9 function main MC/DC independence condition 'a != FALSE && !\(b != FALSE\) && !\(c != FALSE\): SATISFIED$
8+
^\[main.coverage.3\] file main.c line 9 function main MC/DC independence condition '!\(a != FALSE\) && b != FALSE && c != FALSE: SATISFIED$
9+
^\[main.coverage.4\] file main.c line 9 function main MC/DC independence condition '!\(a != FALSE\) && !\(b != FALSE\) && c != FALSE: SATISFIED$
1010
^\*\* .* of .* covered \(100.0%\)$
1111
--
1212
^warning: ignoring

src/goto-symex/symex_assign.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Author: Daniel Kroening, [email protected]
1212
#include "symex_assign.h"
1313

1414
#include <util/byte_operators.h>
15-
#include <util/expr_util.h>
1615
#include <util/pointer_expr.h>
1716
#include <util/range.h>
1817

@@ -238,7 +237,7 @@ void symex_assignt::assign_non_struct_symbol(
238237
: assignment_type;
239238

240239
target.assignment(
241-
make_and(state.guard.as_expr(), conjunction(guard)),
240+
conjunction(state.guard.as_expr(), conjunction(guard)),
242241
l2_lhs,
243242
l2_full_lhs,
244243
get_original_name(l2_full_lhs),

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);

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)

src/util/expr_util.h

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

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

src/util/std_expr.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,37 @@ exprt disjunction(const exprt::operandst &op)
8080
}
8181
}
8282

83+
exprt conjunction(exprt a, exprt b)
84+
{
85+
PRECONDITION(a.is_boolean() && b.is_boolean());
86+
if(b.is_constant())
87+
{
88+
if(to_constant_expr(b).is_false())
89+
return false_exprt{};
90+
return a;
91+
}
92+
if(a.is_constant())
93+
{
94+
if(to_constant_expr(a).is_false())
95+
return false_exprt{};
96+
return b;
97+
}
98+
if(b.id() == ID_and)
99+
{
100+
b.add_to_operands(std::move(a));
101+
return b;
102+
}
103+
return and_exprt{std::move(a), std::move(b)};
104+
}
105+
83106
exprt conjunction(const exprt::operandst &op)
84107
{
85108
if(op.empty())
86109
return true_exprt();
87110
else if(op.size()==1)
88111
return op.front();
112+
else if(op.size() == 2)
113+
return conjunction(op[0], op[1]);
89114
else
90115
{
91116
return and_exprt(exprt::operandst(op));

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)