Skip to content

Commit ccd8628

Browse files
Make guard_expr return a value
This avoids having an argument that is both input and output and makes using this function nicer.
1 parent 467b1c6 commit ccd8628

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

src/analyses/guard_bdd.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,22 @@ guard_bddt &guard_bddt::operator=(guard_bddt &&other)
4444
return *this;
4545
}
4646

47-
void guard_bddt::guard_expr(exprt &dest) const
47+
exprt guard_bddt::guard_expr(exprt expr) const
4848
{
4949
if(is_true())
5050
{
5151
// do nothing
52+
return expr;
5253
}
5354
else
5455
{
55-
if(dest.is_false())
56+
if(expr.is_false())
5657
{
57-
dest = boolean_negate(as_expr());
58+
return boolean_negate(as_expr());
5859
}
5960
else
6061
{
61-
implies_exprt tmp;
62-
tmp.op0() = as_expr();
63-
tmp.op1().swap(dest);
64-
dest.swap(tmp);
62+
return implies_exprt{as_expr(), expr};
6563
}
6664
}
6765
}

src/analyses/guard_bdd.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ class guard_bddt
4040
/// This can vary according to the guard implementation.
4141
static constexpr bool is_always_simplified = true;
4242

43-
/// Assign dest to `guard => dest` unless guard or dest are trivial.
44-
void guard_expr(exprt &dest) const;
43+
/// Return `guard => dest` or a simplified variant thereof if either guard or
44+
/// dest are trivial.
45+
exprt guard_expr(exprt expr) const;
4546

4647
bool is_true() const
4748
{

src/analyses/guard_expr.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/simplify_utils.h>
1919
#include <util/std_expr.h>
2020

21-
void guard_exprt::guard_expr(exprt &dest) const
21+
exprt guard_exprt::guard_expr(exprt expr) const
2222
{
2323
if(is_true())
2424
{
2525
// do nothing
26+
return expr;
2627
}
2728
else
2829
{
29-
if(dest.is_false())
30+
if(expr.is_false())
3031
{
31-
dest = boolean_negate(as_expr());
32+
return boolean_negate(as_expr());
3233
}
3334
else
3435
{
35-
implies_exprt tmp(as_expr(), dest);
36-
dest.swap(tmp);
36+
return implies_exprt{as_expr(), expr};
3737
}
3838
}
3939
}

src/analyses/guard_expr.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class guard_exprt
5555
/// This can vary according to the guard implementation.
5656
static constexpr bool is_always_simplified = false;
5757

58-
void guard_expr(exprt &dest) const;
58+
/// Return `guard => dest` or a simplified variant thereof if either guard or
59+
/// dest are trivial.
60+
exprt guard_expr(exprt expr) const;
5961

6062
bool is_true() const
6163
{

src/goto-symex/symex_main.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ void goto_symext::vcc(
116116
if(condition.is_true())
117117
return;
118118

119-
exprt guarded_condition = condition;
120-
state.guard.guard_expr(guarded_condition);
119+
const exprt guarded_condition = state.guard.guard_expr(condition);
121120

122121
state.remaining_vccs++;
123122
target.assertion(state.guard.as_expr(), guarded_condition, msg, state.source);
@@ -146,8 +145,7 @@ void goto_symext::symex_assume_l2(statet &state, const exprt &cond)
146145

147146
if(state.threads.size()==1)
148147
{
149-
exprt tmp = rewritten_cond;
150-
state.guard.guard_expr(tmp);
148+
exprt tmp = state.guard.guard_expr(rewritten_cond);
151149
target.assumption(state.guard.as_expr(), tmp, state.source);
152150
}
153151
// symex_target_equationt::convert_assertions would fail to

0 commit comments

Comments
 (0)